[Home] [Help]
PACKAGE BODY: APPS.WMS_POSTALLOC_PVT
Source
1 PACKAGE BODY wms_postalloc_pvt AS
2 /* $Header: WMSVPRPB.pls 120.10.12020000.4 2013/02/26 21:05:36 sahmahes ship $*/
3
4 g_pkg_body_ver CONSTANT VARCHAR2(100) := '$Header $';
5 g_newline CONSTANT VARCHAR2(10) := fnd_global.newline;
6 g_bulk_fetch_limit CONSTANT NUMBER := 1000;
7 g_debug NUMBER := NVL(fnd_profile.value('INV_DEBUG_TRACE'),0);
8 g_user_id CONSTANT NUMBER := fnd_global.user_id;
9 g_hash_base NUMBER := 1;
10 g_hash_size NUMBER := POWER(2, 25);
11
12
13 TYPE tbl_num IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
14 TYPE tbl_varchar1 IS TABLE OF VARCHAR2(1) INDEX BY PLS_INTEGER;
15 TYPE tbl_varchar3 IS TABLE OF VARCHAR2(3) INDEX BY PLS_INTEGER;
16 TYPE tbl_varchar10 IS TABLE OF VARCHAR2(10) INDEX BY PLS_INTEGER;
17 TYPE tbl_varchar50 IS TABLE OF VARCHAR2(50) INDEX BY PLS_INTEGER;
18 TYPE tbl_date IS TABLE OF DATE INDEX BY PLS_INTEGER;
19
20
21 -- Op plan, task type assignment
22 g_opa_org_id NUMBER := -1;
23 g_opa_rule_exists BOOLEAN := TRUE;
24 g_tta_org_id NUMBER := -1;
25 g_tta_rule_exists BOOLEAN := TRUE;
26
27 TYPE t_rule_id IS TABLE OF wms_rules.rule_id%TYPE;
28 TYPE t_type_hdr_id IS TABLE OF wms_rules.type_hdr_id%TYPE;
29 g_t_opa_rule_id t_rule_id;
30 g_t_opa_type_hdr_id t_type_hdr_id;
31 g_t_tta_rule_id t_rule_id;
32 g_t_tta_type_hdr_id t_type_hdr_id;
33
34
35 -- Pick slip numbering
36 TYPE grprectyp IS RECORD(
37 grouping_rule_id NUMBER
38 , use_order_ps VARCHAR2(1) := 'N'
39 , use_customer_ps VARCHAR2(1) := 'N'
40 , use_ship_to_ps VARCHAR2(1) := 'N'
41 , use_carrier_ps VARCHAR2(1) := 'N'
42 , use_ship_priority_ps VARCHAR2(1) := 'N'
43 , use_trip_stop_ps VARCHAR2(1) := 'N'
44 , use_delivery_ps VARCHAR2(1) := 'N'
45 , use_src_sub_ps VARCHAR2(1) := 'N'
46 , use_src_locator_ps VARCHAR2(1) := 'N'
47 , use_item_ps VARCHAR2(1) := 'N'
48 , use_revision_ps VARCHAR2(1) := 'N'
49 , use_lot_ps VARCHAR2(1) := 'N'
50 , use_jobsch_ps VARCHAR2(1) := 'N'
51 , use_oper_seq_ps VARCHAR2(1) := 'N'
52 , use_dept_ps VARCHAR2(1) := 'N'
53 , use_supply_type_ps VARCHAR2(1) := 'N'
54 , use_supply_sub_ps VARCHAR2(1) := 'N'
55 , use_supply_loc_ps VARCHAR2(1) := 'N'
56 , use_project_ps VARCHAR2(1) := 'N'
57 , use_task_ps VARCHAR2(1) := 'N'
58 , pick_method VARCHAR2(30) := '-99');
59
60 g_ps_rule_rec grprectyp;
61
62 g_cluster_pick_method CONSTANT VARCHAR2(1) := '3';
63
64
65 -- Device integration
66 g_device_level_none CONSTANT NUMBER := 0;
67 g_device_level_org CONSTANT NUMBER := 100;
68 g_device_level_sub CONSTANT NUMBER := 200;
69 g_device_level_locator CONSTANT NUMBER := 300;
70 g_device_level_user CONSTANT NUMBER := 400;
71 g_wms_be_pick_release CONSTANT NUMBER := 11;
72
73 g_dev_tbl tbl_num;
74 g_org_tbl tbl_num;
75 g_sub_tbl tbl_varchar10;
76 g_loc_tbl tbl_num;
77 g_user_tbl tbl_num;
78
79
80 -- Task splitting
81 g_from_uom_code_tbl tbl_varchar3;
82 g_to_uom_code_tbl tbl_varchar3;
83 g_from_to_uom_ratio_tbl tbl_num;
84 g_item_tbl tbl_num;
85
86 g_hash_split_org_tbl tbl_num;
87 g_hash_split_inv_item_id_tbl tbl_num;
88 g_hash_split_std_op_id_tbl tbl_num;
89 g_hash_split_fac_tbl tbl_num;
90
91 g_eqp_org_id NUMBER := -1;
92 g_eqp_vol_uom tbl_varchar3;
93 g_eqp_wt_uom tbl_varchar3;
94 g_eqp_weight tbl_num;
95 g_eqp_volume tbl_num;
96
97
98
99 PROCEDURE print_debug
100 ( p_msg IN VARCHAR2
101 , p_api_name IN VARCHAR2
102 ) IS
103 BEGIN
104 inv_log_util.trace
105 ( p_message => p_msg
106 , p_module => g_pkg_name || '.' || p_api_name
107 , p_level => 9
108 );
109 END print_debug;
110
111
112
113 PROCEDURE print_version_info
114 IS
115 BEGIN
116 print_debug ('Spec:: ' || g_pkg_spec_ver, 'print_version_info');
117 print_debug ('Body:: ' || g_pkg_body_ver, 'print_version_info');
118 END print_version_info;
119
120
121
122 -- Fetches and locks the next record in wms_pr_workers table
123 -- for a given batch and worker type
124 PROCEDURE fetch_next_wpr_rec
125 ( p_batch_id IN NUMBER
126 , p_mode IN VARCHAR2
127 , x_wpr_rec OUT NOCOPY wms_pr_workers%ROWTYPE
128 , x_return_status OUT NOCOPY VARCHAR2
129 ) IS
130
131 l_api_name VARCHAR2(30) := 'fetch_next_wpr_rec';
132 l_msg_count NUMBER;
133 l_msg_data VARCHAR2(2000);
134
135 l_wpr_rec wms_pr_workers%ROWTYPE;
136 l_return_status VARCHAR2(1);
137 l_row_id ROWID;
138 done BOOLEAN := FALSE;
139
140 record_locked_exc EXCEPTION;
141 PRAGMA EXCEPTION_INIT (record_locked_exc, -54);
142
143 BEGIN
144 x_return_status := fnd_api.g_ret_sts_success;
145
146 SAVEPOINT fetch_wpr_sp;
147
148 IF g_debug = 1 THEN
149 print_debug( 'Entered with parameters: ' || g_newline ||
150 'p_batch_id => ' || TO_CHAR(p_batch_id) || g_newline ||
151 'p_mode => ' || p_mode
152 , l_api_name);
153 END IF;
154
155 LOOP --{
156 EXIT WHEN done;
157 BEGIN
158 -- If a record is locked successfully, or if no data found,
159 -- or if an unknown exception occurs, then exit the loop.
160 -- If unable to lock one record, try another (continue looping).
161 SELECT rowid INTO l_row_id
162 FROM wms_pr_workers
163 WHERE batch_id = p_batch_id
164 AND worker_mode = p_mode
165 AND processed_flag = 'N'
166 AND rownum < 2
167 FOR UPDATE NOWAIT;
168
169 done := TRUE;
170
171 UPDATE wms_pr_workers
172 SET processed_flag = 'Y'
173 WHERE rowid = l_row_id
174 RETURNING batch_id
175 , worker_mode
176 , processed_flag
177 , organization_id
178 , mo_header_id
179 , transaction_batch_id
180 , cartonization_id
181 , detailed_count
182 INTO l_wpr_rec;
183
184 COMMIT;
185
186 IF g_debug = 1 THEN
187 print_debug
188 ( 'Successfully locked a WPR row: ' || g_newline ||
189 ' Org ID: ' || TO_CHAR(l_wpr_rec.organization_id) || g_newline ||
190 ' MO Header ID: ' || TO_CHAR(l_wpr_rec.mo_header_id) || g_newline ||
191 ' Txn batch ID: ' || TO_CHAR(l_wpr_rec.transaction_batch_id) || g_newline ||
192 ' Cartonization ID: ' || TO_CHAR(l_wpr_rec.cartonization_id) || g_newline ||
193 ' Detailed count: ' || TO_CHAR(l_wpr_rec.detailed_count)
194 , l_api_name
195 );
196 END IF;
197
198 EXCEPTION
199 WHEN record_locked_exc THEN
200 IF g_debug = 1 THEN
201 print_debug ('Record locked', l_api_name);
202 END IF;
203 done := FALSE;
204 WHEN NO_DATA_FOUND THEN
205 IF g_debug = 1 THEN
206 print_debug ('No more records', l_api_name);
207 END IF;
208 x_return_status := 'N';
209 done := TRUE;
210 WHEN OTHERS THEN
211 IF g_debug = 1 THEN
212 print_debug ('Other error: ' || SQLERRM, l_api_name);
213 END IF;
214 done := TRUE;
215 RAISE fnd_api.g_exc_unexpected_error;
216 END;
217
218 END LOOP; --}
219
220 IF x_return_status = fnd_api.g_ret_sts_success THEN
221 x_wpr_rec := l_wpr_rec;
222 END IF;
223
224 EXCEPTION
225 WHEN fnd_api.g_exc_error THEN
226 ROLLBACK TO fetch_wpr_sp;
227 x_return_status := fnd_api.g_ret_sts_error;
228 fnd_msg_pub.count_and_get
229 ( p_count => l_msg_count
230 , p_data => l_msg_data
231 , p_encoded => fnd_api.g_false
232 );
233 IF g_debug = 1 THEN
234 print_debug (l_msg_data, l_api_name);
235 END IF;
236
237 WHEN OTHERS THEN
238 ROLLBACK TO fetch_wpr_sp;
239 x_return_status := fnd_api.g_ret_sts_unexp_error;
240 IF g_debug = 1 THEN
241 print_debug ('Other error: ' || SQLERRM, l_api_name);
242 END IF;
243
244 END fetch_next_wpr_rec;
245
246
247
248 PROCEDURE assign_op_plan
249 ( p_transaction_batch_id IN NUMBER
250 , p_organization_id IN NUMBER
251 , x_return_status OUT NOCOPY VARCHAR2
252 ) IS
253
254 l_api_name VARCHAR2(30) := 'assign_op_plan';
255 l_msg_count NUMBER;
256 l_msg_data VARCHAR2(2000);
257
258 l_return_status NUMBER;
259 l_op_plan_id NUMBER;
260 l_rule_applied BOOLEAN;
261
262 l_mmtt_temp_id tbl_num;
263 l_mmtt_hid tbl_num;
264
265 CURSOR c_mmtt_cursor (p_txn_batch_id NUMBER) IS
266 SELECT transaction_temp_id
267 FROM mtl_material_transactions_temp
268 WHERE transaction_batch_id = p_txn_batch_id;
269
270 BEGIN
271 -- Initialize API return status to success
272 x_return_status := fnd_api.g_ret_sts_success;
273
274 IF g_debug = 1 THEN
275 print_debug( 'Entered with parameters: ' || g_newline ||
276 'p_transaction_batch_id => ' || p_transaction_batch_id || g_newline ||
277 'p_organization_id => ' || p_organization_id || g_newline
278 , l_api_name);
279 END IF;
280
281 -- Bulk fetch applicable rule IDs (only if first time or org changed)
282 IF g_opa_org_id <> p_organization_id THEN
283 g_opa_org_id := p_organization_id;
284 BEGIN
285 SELECT rules.rule_id, rules.type_hdr_id BULK COLLECT
286 INTO g_t_opa_rule_id, g_t_opa_type_hdr_id
287 FROM wms_rules rules
288 , wms_op_plans_b wop
289 WHERE rules.organization_id IN (g_opa_org_id,-1)
290 AND rules.type_code = 7
291 AND rules.enabled_flag = 'Y'
292 AND rules.type_hdr_id = wop.operation_plan_id
293 AND wop.activity_type_id = 2 -- Outbound
294 AND wop.enabled_flag = 'Y'
295 ORDER BY rules.rule_weight DESC, rules.creation_date;
296
297 g_opa_rule_exists := TRUE;
298 EXCEPTION
299 WHEN NO_DATA_FOUND THEN
300 g_opa_rule_exists := FALSE;
301 END ;
302 END IF;
303
304 -- If there is at least one operation plan selection rule enabled
305 IF g_opa_rule_exists THEN --{
306 OPEN c_mmtt_cursor(p_transaction_batch_id);
307
308 LOOP --{
309 FETCH c_mmtt_cursor BULK COLLECT
310 INTO l_mmtt_temp_id LIMIT g_bulk_fetch_limit;
311 EXIT WHEN l_mmtt_temp_id.COUNT = 0;
312
313 FOR ii IN l_mmtt_temp_id.FIRST .. l_mmtt_temp_id.LAST LOOP --{
314 l_rule_applied := FALSE;
315
316 FOR jj IN g_t_opa_rule_id.FIRST .. g_t_opa_rule_id.LAST LOOP --{
317 wms_rule_pvt.execute_op_rule( g_t_opa_rule_id(jj), l_mmtt_temp_id(ii), l_return_status);
318
319 IF l_return_status > 0 THEN
320 l_mmtt_hid(ii) := g_t_opa_type_hdr_id(jj);
321 l_rule_applied := TRUE;
322 EXIT;
323 END IF;
324 END LOOP; --}
325
326 -- If no Operation Plan rule gets applied,
327 -- stamp the org default outbound operation plan
328 IF ( l_rule_applied <> TRUE ) THEN
329 IF ( inv_cache.set_org_rec( p_organization_id ) ) THEN
330 l_mmtt_hid(ii) := NVL(inv_cache.org_rec.default_pick_op_plan_id,1);
331 ELSE
332 IF g_debug = 1 THEN
333 print_debug ( 'Error setting cache for organization', l_api_name );
334 END IF;
335 RAISE fnd_api.g_exc_unexpected_error;
336 END IF;
337 END IF ;
338
339 IF g_debug = 1 THEN
340 print_debug ('Temp ID: ' || l_mmtt_temp_id(ii) || ', op plan assigned: '
341 || l_mmtt_hid(ii), l_api_name);
342 END IF;
343 END LOOP; --}
344
345 -- Bulk update operation_plan_id in all the MMTTs with cached values
346 FORALL kk IN l_mmtt_temp_id.FIRST .. l_mmtt_temp_id.LAST
347 UPDATE mtl_material_transactions_temp
348 SET operation_plan_id = l_mmtt_hid(kk)
349 WHERE transaction_temp_id = l_mmtt_temp_id(kk);
350
351 END LOOP; --}
352
353 IF c_mmtt_cursor%ISOPEN THEN
354 CLOSE c_mmtt_cursor;
355 END IF;
356 --}
357 ELSE --{
358 -- If there is no operation plan selection rule enabled,
359 -- stamp the org default outbound operation plan
360 IF (inv_cache.set_org_rec(p_organization_id) ) THEN
361 l_op_plan_id := NVL(inv_cache.org_rec.default_pick_op_plan_id,1);
362 ELSE
363 IF g_debug = 1 THEN
364 print_debug('Error setting cache for organization', l_api_name);
365 END IF;
366 RAISE fnd_api.g_exc_unexpected_error;
367 END IF;
368
369 IF g_debug = 1 THEN
370 print_debug ('No operation plan rules defined', l_api_name);
371 print_debug ('l_op_plan_id value: ' || l_op_plan_id, l_api_name);
372 END IF;
373
374 UPDATE mtl_material_transactions_temp
375 SET operation_plan_id = l_op_plan_id
376 WHERE transaction_batch_id = p_transaction_batch_id;
377 END IF; --}
378
379 UPDATE wms_pr_workers
380 SET worker_mode = 'TTA', processed_flag = 'N'
381 WHERE transaction_batch_id = p_transaction_batch_id;
382
383 COMMIT;
384
385 EXCEPTION
386 WHEN fnd_api.g_exc_error THEN
387 x_return_status := fnd_api.g_ret_sts_error;
388 fnd_msg_pub.count_and_get
389 ( p_count => l_msg_count
390 , p_data => l_msg_data
391 , p_encoded => fnd_api.g_false
392 );
393 IF g_debug = 1 THEN
394 print_debug (l_msg_data, l_api_name);
395 END IF;
396
397 IF c_mmtt_cursor%ISOPEN THEN
398 CLOSE c_mmtt_cursor;
399 END IF;
400
401 WHEN OTHERS THEN
402 x_return_status := fnd_api.g_ret_sts_unexp_error;
403 IF g_debug = 1 THEN
404 print_debug ('Other error: ' || SQLERRM, l_api_name);
405 END IF;
406
407 IF c_mmtt_cursor%ISOPEN THEN
408 CLOSE c_mmtt_cursor;
409 END IF;
410 END assign_op_plan;
411
412
413
414 PROCEDURE assign_operation_plans
415 ( p_batch_id IN NUMBER
416 , x_return_status OUT NOCOPY VARCHAR2
417 ) IS
418 l_api_name VARCHAR2(30) := 'assign_operation_plans';
419 l_msg_count NUMBER;
420 l_msg_data VARCHAR2(2000);
421
422 l_wpr_rec wms_pr_workers%ROWTYPE;
423 l_api_return_status VARCHAR2(1);
424
425 BEGIN
426 x_return_status := fnd_api.g_ret_sts_success;
427
428 IF g_debug = 1 THEN
429 print_debug( 'Entered with parameters: ' || g_newline ||
430 'p_batch_id => ' || TO_CHAR(p_batch_id)
431 , l_api_name);
432 END IF;
433
434 LOOP --{
435 l_api_return_status := fnd_api.g_ret_sts_success;
436 fetch_next_wpr_rec
437 ( p_batch_id => p_batch_id
438 , p_mode => 'OPA'
439 , x_wpr_rec => l_wpr_rec
440 , x_return_status => l_api_return_status
441 );
442
443 IF l_api_return_status = 'N' THEN
444 IF g_debug = 1 THEN
445 print_debug ( 'No more records in WPR', l_api_name );
446 END IF;
447 EXIT;
448 ELSIF l_api_return_status <> fnd_api.g_ret_sts_success THEN
449 IF g_debug = 1 THEN
450 print_debug('Error status from fetch_next_wpr_rec: '
451 || l_api_return_status, l_api_name);
452 END IF;
453 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
454 RAISE fnd_api.g_exc_error;
455 ELSE
456 RAISE fnd_api.g_exc_unexpected_error;
457 END IF;
458 END IF;
459
460 l_api_return_status := fnd_api.g_ret_sts_success;
461 assign_op_plan
462 ( p_transaction_batch_id => l_wpr_rec.transaction_batch_id
463 , p_organization_id => l_wpr_rec.organization_id
464 , x_return_status => l_api_return_status
465 );
466
467 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
468 IF g_debug = 1 THEN
469 print_debug('Error status from assign_op_plan: '
470 || l_api_return_status, l_api_name);
471 END IF;
472 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
473 RAISE fnd_api.g_exc_error;
474 ELSE
475 RAISE fnd_api.g_exc_unexpected_error;
476 END IF;
477 END IF;
478 END LOOP;
479
480 EXCEPTION
481 WHEN fnd_api.g_exc_error THEN
482 x_return_status := fnd_api.g_ret_sts_error;
483 fnd_msg_pub.count_and_get
484 ( p_count => l_msg_count
485 , p_data => l_msg_data
486 , p_encoded => fnd_api.g_false
487 );
488 IF g_debug = 1 THEN
489 print_debug (l_msg_data, l_api_name);
490 END IF;
491
492 WHEN OTHERS THEN
493 x_return_status := fnd_api.g_ret_sts_unexp_error;
494 IF g_debug = 1 THEN
495 print_debug ('Other error: ' || SQLERRM, l_api_name);
496 END IF;
497
498 END assign_operation_plans;
499
500
501
502 -- Insert all the mmtt records for a move order header id
503 -- into wms_cartonization_temp
504 PROCEDURE create_wct
505 ( p_move_order_header_id IN NUMBER
506 , x_return_status OUT NOCOPY VARCHAR2
507 ) IS
508
509 l_api_name VARCHAR2(30) := 'create_wct';
510 l_msg_count NUMBER;
511 l_msg_data VARCHAR2(2000);
512
513 BEGIN
514 x_return_status := fnd_api.g_ret_sts_success;
515
516 SAVEPOINT create_wct_sp;
517
518 IF g_debug = 1 THEN
519 print_debug( 'Entered with parameters: ' || g_newline ||
520 'p_move_order_header_id => ' || p_move_order_header_id
521 , l_api_name);
522 END IF;
523
524 -- Checking if the caller is 'TRP' (i.e) from Task Release then
525 -- cartonization_id can be null as well so removing the condition
526
527 IF g_caller = 'TRP' THEN --{
528 INSERT INTO wms_cartonization_temp(
529 transaction_header_id
530 , transaction_temp_id
531 , source_code
532 , source_line_id
533 , transaction_mode
534 , lock_flag
535 , last_update_date
536 , last_updated_by
537 , creation_date
538 , created_by
539 , last_update_login
540 , request_id
541 , program_application_id
542 , program_id
543 , program_update_date
544 , inventory_item_id
545 , revision
546 , organization_id
547 , subinventory_code
548 , locator_id
549 , transaction_quantity
550 , primary_quantity
551 , transaction_uom
552 , transaction_cost
553 , transaction_type_id
554 , transaction_action_id
555 , transaction_source_type_id
556 , transaction_source_id
557 , transaction_source_name
558 , transaction_date
559 , acct_period_id
560 , distribution_account_id
561 , transaction_reference
562 , requisition_line_id
563 , requisition_distribution_id
564 , reason_id
565 , lot_number
566 , lot_expiration_date
567 , serial_number
568 , receiving_document
569 , demand_id
570 , rcv_transaction_id
571 , move_transaction_id
572 , completion_transaction_id
573 , wip_entity_type
574 , schedule_id
575 , repetitive_line_id
576 , employee_code
577 , primary_switch
578 , schedule_update_code
579 , setup_teardown_code
580 , item_ordering
581 , negative_req_flag
582 , operation_seq_num
583 , picking_line_id
584 , trx_source_line_id
585 , trx_source_delivery_id
586 , physical_adjustment_id
587 , cycle_count_id
588 , rma_line_id
589 , customer_ship_id
590 , currency_code
591 , currency_conversion_rate
592 , currency_conversion_type
593 , currency_conversion_date
594 , ussgl_transaction_code
595 , vendor_lot_number
596 , encumbrance_account
597 , encumbrance_amount
598 , ship_to_location
599 , shipment_number
600 , transfer_cost
601 , transportation_cost
602 , transportation_account
603 , freight_code
604 , containers
605 , waybill_airbill
606 , expected_arrival_date
607 , transfer_subinventory
608 , transfer_organization
609 , transfer_to_location
610 , new_average_cost
611 , value_change
612 , percentage_change
613 , material_allocation_temp_id
614 , demand_source_header_id
615 , demand_source_line
616 , demand_source_delivery
617 , item_segments
618 , item_description
619 , item_trx_enabled_flag
620 , item_location_control_code
621 , item_restrict_subinv_code
622 , item_restrict_locators_code
623 , item_revision_qty_control_code
624 , item_primary_uom_code
625 , item_uom_class
626 , item_shelf_life_code
627 , item_shelf_life_days
628 , item_lot_control_code
629 , item_serial_control_code
630 , item_inventory_asset_flag
631 , allowed_units_lookup_code
632 , department_id
633 , department_code
634 , wip_supply_type
635 , supply_subinventory
636 , supply_locator_id
637 , valid_subinventory_flag
638 , valid_locator_flag
639 , locator_segments
640 , current_locator_control_code
641 , number_of_lots_entered
642 , wip_commit_flag
643 , next_lot_number
644 , lot_alpha_prefix
645 , next_serial_number
646 , serial_alpha_prefix
647 , shippable_flag
648 , posting_flag
649 , required_flag
650 , process_flag
651 , error_code
652 , error_explanation
653 , attribute_category
654 , attribute1
655 , attribute2
656 , attribute3
657 , attribute4
658 , attribute5
659 , attribute6
660 , attribute7
661 , attribute8
662 , attribute9
663 , attribute10
664 , attribute11
665 , attribute12
666 , attribute13
667 , attribute14
668 , attribute15
669 , movement_id
670 , reservation_quantity
671 , shipped_quantity
672 , transaction_line_number
673 , task_id
674 , to_task_id
675 , source_task_id
676 , project_id
677 , source_project_id
678 , pa_expenditure_org_id
679 , to_project_id
680 , expenditure_type
681 , final_completion_flag
682 , transfer_percentage
683 , transaction_sequence_id
684 , material_account
685 , material_overhead_account
686 , resource_account
687 , outside_processing_account
688 , overhead_account
689 , flow_schedule
690 , cost_group_id
691 , demand_class
692 , qa_collection_id
693 , kanban_card_id
694 , overcompletion_txn_qty
695 , overcompletion_primary_qty
696 , overcompletion_transaction_id
697 , end_item_unit_number
698 , scheduled_payback_date
699 , line_type_code
700 , parent_transaction_temp_id
701 , put_away_strategy_id
702 , put_away_rule_id
703 , pick_strategy_id
704 , pick_rule_id
705 , move_order_line_id
706 , task_group_id
707 , pick_slip_number
708 , reservation_id
709 , common_bom_seq_id
710 , common_routing_seq_id
711 , org_cost_group_id
712 , cost_type_id
713 , transaction_status
714 , standard_operation_id
715 , task_priority
716 , wms_task_type
717 , parent_line_id
718 , source_lot_number
719 , transfer_cost_group_id
720 , lpn_id
721 , transfer_lpn_id
722 , wms_task_status
723 , content_lpn_id
724 , container_item_id
725 , cartonization_id
726 , pick_slip_date
727 , rebuild_item_id
728 , rebuild_serial_number
729 , rebuild_activity_id
730 , rebuild_job_name
731 , organization_type
732 , transfer_organization_type
733 , owning_organization_id
734 , owning_tp_type
735 , xfr_owning_organization_id
736 , transfer_owning_tp_type
737 , planning_organization_id
738 , planning_tp_type
739 , xfr_planning_organization_id
740 , transfer_planning_tp_type
741 , secondary_uom_code
742 , secondary_transaction_quantity
743 , allocated_lpn_id
744 , schedule_number
745 , scheduled_flag
746 , class_code
747 , schedule_group
748 , build_sequence
749 , bom_revision
750 , routing_revision
751 , bom_revision_date
752 , routing_revision_date
753 , alternate_bom_designator
754 , alternate_routing_designator
755 , transaction_batch_id
756 , transaction_batch_seq
757 , operation_plan_id
758 , intransit_account
759 , fob_point
760 , logical_trx_type_code
761 , move_order_header_id
762 , original_transaction_temp_id
763 , serial_allocated_flag
764 , trx_flow_header_id
765 , fulfillment_base
766 )
767 SELECT mmtt.transaction_header_id
768 , mmtt.transaction_temp_id
769 , mmtt.source_code
770 , mmtt.source_line_id
771 , mmtt.transaction_mode
772 , mmtt.lock_flag
773 , mmtt.last_update_date
774 , mmtt.last_updated_by
775 , mmtt.creation_date
776 , mmtt.created_by
777 , mmtt.last_update_login
778 , mmtt.request_id
779 , mmtt.program_application_id
780 , mmtt.program_id
781 , mmtt.program_update_date
782 , mmtt.inventory_item_id
783 , mmtt.revision
784 , mmtt.organization_id
785 , mmtt.subinventory_code
786 , mmtt.locator_id
787 , mmtt.transaction_quantity
788 , mmtt.primary_quantity
789 , mmtt.transaction_uom
790 , mmtt.transaction_cost
791 , mmtt.transaction_type_id
792 , mmtt.transaction_action_id
793 , mmtt.transaction_source_type_id
794 , mmtt.transaction_source_id
795 , mmtt.transaction_source_name
796 , mmtt.transaction_date
797 , mmtt.acct_period_id
798 , mmtt.distribution_account_id
799 , mmtt.transaction_reference
800 , mmtt.requisition_line_id
801 , mmtt.requisition_distribution_id
802 , mmtt.reason_id
803 , mmtt.lot_number
804 , mmtt.lot_expiration_date
805 , mmtt.serial_number
806 , mmtt.receiving_document
807 , mmtt.demand_id
808 , mmtt.rcv_transaction_id
809 , mmtt.move_transaction_id
810 , mmtt.completion_transaction_id
811 , mmtt.wip_entity_type
812 , mmtt.schedule_id
813 , mmtt.repetitive_line_id
814 , mmtt.employee_code
815 , mmtt.primary_switch
816 , mmtt.schedule_update_code
817 , mmtt.setup_teardown_code
818 , mmtt.item_ordering
819 , mmtt.negative_req_flag
820 , mmtt.operation_seq_num
821 , mmtt.picking_line_id
822 , mmtt.trx_source_line_id
823 , mmtt.trx_source_delivery_id
824 , mmtt.physical_adjustment_id
825 , mmtt.cycle_count_id
826 , mmtt.rma_line_id
827 , mmtt.customer_ship_id
828 , mmtt.currency_code
829 , mmtt.currency_conversion_rate
830 , mmtt.currency_conversion_type
831 , mmtt.currency_conversion_date
832 , mmtt.ussgl_transaction_code
833 , mmtt.vendor_lot_number
834 , mmtt.encumbrance_account
835 , mmtt.encumbrance_amount
836 , mmtt.ship_to_location
837 , mmtt.shipment_number
838 , mmtt.transfer_cost
839 , mmtt.transportation_cost
840 , mmtt.transportation_account
841 , mmtt.freight_code
842 , mmtt.containers
843 , mmtt.waybill_airbill
844 , mmtt.expected_arrival_date
845 , mmtt.transfer_subinventory
846 , mmtt.transfer_organization
847 , mmtt.transfer_to_location
848 , mmtt.new_average_cost
849 , mmtt.value_change
850 , mmtt.percentage_change
851 , mmtt.material_allocation_temp_id
852 , mmtt.demand_source_header_id
853 , mmtt.demand_source_line
854 , mmtt.demand_source_delivery
855 , mmtt.item_segments
856 , mmtt.item_description
857 , mmtt.item_trx_enabled_flag
858 , mmtt.item_location_control_code
859 , mmtt.item_restrict_subinv_code
860 , mmtt.item_restrict_locators_code
861 , mmtt.item_revision_qty_control_code
862 , mmtt.item_primary_uom_code
863 , mmtt.item_uom_class
864 , mmtt.item_shelf_life_code
865 , mmtt.item_shelf_life_days
866 , mmtt.item_lot_control_code
867 , mmtt.item_serial_control_code
868 , mmtt.item_inventory_asset_flag
869 , mmtt.allowed_units_lookup_code
870 , mmtt.department_id
871 , mmtt.department_code
872 , mmtt.wip_supply_type
873 , mmtt.supply_subinventory
874 , mmtt.supply_locator_id
875 , mmtt.valid_subinventory_flag
876 , mmtt.valid_locator_flag
877 , mmtt.locator_segments
878 , mmtt.current_locator_control_code
879 , mmtt.number_of_lots_entered
880 , mmtt.wip_commit_flag
881 , mmtt.next_lot_number
882 , mmtt.lot_alpha_prefix
883 , mmtt.next_serial_number
884 , mmtt.serial_alpha_prefix
885 , mmtt.shippable_flag
886 , mmtt.posting_flag
887 , mmtt.required_flag
888 , mmtt.process_flag
889 , mmtt.error_code
890 , mmtt.error_explanation
891 , mmtt.attribute_category
892 , mmtt.attribute1
893 , mmtt.attribute2
894 , mmtt.attribute3
895 , mmtt.attribute4
896 , mmtt.attribute5
897 , mmtt.attribute6
898 , mmtt.attribute7
899 , mmtt.attribute8
900 , mmtt.attribute9
901 , mmtt.attribute10
902 , mmtt.attribute11
903 , mmtt.attribute12
904 , mmtt.attribute13
905 , mmtt.attribute14
906 , mmtt.attribute15
907 , mmtt.movement_id
908 , mmtt.reservation_quantity
909 , mmtt.shipped_quantity
910 , mmtt.transaction_line_number
911 , mmtt.task_id
912 , mmtt.to_task_id
913 , mmtt.source_task_id
914 , mmtt.project_id
915 , mmtt.source_project_id
916 , mmtt.pa_expenditure_org_id
917 , mmtt.to_project_id
918 , mmtt.expenditure_type
919 , mmtt.final_completion_flag
920 , mmtt.transfer_percentage
921 , mmtt.transaction_sequence_id
922 , mmtt.material_account
923 , mmtt.material_overhead_account
924 , mmtt.resource_account
925 , mmtt.outside_processing_account
926 , mmtt.overhead_account
927 , mmtt.flow_schedule
928 , mmtt.cost_group_id
929 , mmtt.demand_class
930 , mmtt.qa_collection_id
931 , mmtt.kanban_card_id
932 , mmtt.overcompletion_transaction_qty
933 , mmtt.overcompletion_primary_qty
934 , mmtt.overcompletion_transaction_id
935 , mmtt.end_item_unit_number
936 , mmtt.scheduled_payback_date
937 , mmtt.line_type_code
938 , mmtt.parent_transaction_temp_id
939 , mmtt.put_away_strategy_id
940 , mmtt.put_away_rule_id
941 , mmtt.pick_strategy_id
942 , mmtt.pick_rule_id
943 , mmtt.move_order_line_id
944 , mmtt.task_group_id
945 , mmtt.pick_slip_number
946 , mmtt.reservation_id
947 , mmtt.common_bom_seq_id
948 , mmtt.common_routing_seq_id
949 , mmtt.org_cost_group_id
950 , mmtt.cost_type_id
951 , mmtt.transaction_status
952 , mmtt.standard_operation_id
953 , mmtt.task_priority
954 , mmtt.wms_task_type
955 , mmtt.parent_line_id
956 , mmtt.source_lot_number
957 , mmtt.transfer_cost_group_id
958 , mmtt.lpn_id
959 , mmtt.transfer_lpn_id
960 , mmtt.wms_task_status
961 , mmtt.content_lpn_id
962 , decode( g_pick_group_rule,'Y',decode(mmtt.container_item_id,-1,null,mmtt.container_item_id),mmtt.container_item_id)
963 , mmtt.cartonization_id
964 , mmtt.pick_slip_date
965 , mmtt.rebuild_item_id
966 , mmtt.rebuild_serial_number
967 , mmtt.rebuild_activity_id
968 , mmtt.rebuild_job_name
969 , mmtt.organization_type
970 , mmtt.transfer_organization_type
971 , mmtt.owning_organization_id
972 , mmtt.owning_tp_type
973 , mmtt.xfr_owning_organization_id
974 , mmtt.transfer_owning_tp_type
975 , mmtt.planning_organization_id
976 , mmtt.planning_tp_type
977 , mmtt.xfr_planning_organization_id
978 , mmtt.transfer_planning_tp_type
979 , mmtt.secondary_uom_code
980 , mmtt.secondary_transaction_quantity
981 , mmtt.allocated_lpn_id
982 , mmtt.schedule_number
983 , mmtt.scheduled_flag
984 , mmtt.class_code
985 , mmtt.schedule_group
986 , mmtt.build_sequence
987 , mmtt.bom_revision
988 , mmtt.routing_revision
989 , mmtt.bom_revision_date
990 , mmtt.routing_revision_date
991 , mmtt.alternate_bom_designator
992 , mmtt.alternate_routing_designator
993 , mmtt.transaction_batch_id
994 , mmtt.transaction_batch_seq
995 , mmtt.operation_plan_id
996 , mmtt.intransit_account
997 , mmtt.fob_point
998 , mmtt.logical_trx_type_code
999 , mmtt.move_order_header_id
1000 , mmtt.original_transaction_temp_id
1001 , mmtt.serial_allocated_flag
1002 , mmtt.trx_flow_header_id
1003 , mmtt.fulfillment_base
1004 FROM mtl_material_transactions_temp mmtt
1005 WHERE mmtt.move_order_header_id = p_move_order_header_id;
1006 -- AND mmtt.container_item_id IS NULL;
1007 --}
1008 ELSE
1009 --{
1010 INSERT INTO wms_cartonization_temp(
1011 transaction_header_id
1012 , transaction_temp_id
1013 , source_code
1014 , source_line_id
1015 , transaction_mode
1016 , lock_flag
1017 , last_update_date
1018 , last_updated_by
1019 , creation_date
1020 , created_by
1021 , last_update_login
1022 , request_id
1023 , program_application_id
1024 , program_id
1025 , program_update_date
1026 , inventory_item_id
1027 , revision
1028 , organization_id
1029 , subinventory_code
1030 , locator_id
1031 , transaction_quantity
1032 , primary_quantity
1033 , transaction_uom
1034 , transaction_cost
1035 , transaction_type_id
1036 , transaction_action_id
1037 , transaction_source_type_id
1038 , transaction_source_id
1039 , transaction_source_name
1040 , transaction_date
1041 , acct_period_id
1042 , distribution_account_id
1043 , transaction_reference
1044 , requisition_line_id
1045 , requisition_distribution_id
1046 , reason_id
1047 , lot_number
1048 , lot_expiration_date
1049 , serial_number
1050 , receiving_document
1051 , demand_id
1052 , rcv_transaction_id
1053 , move_transaction_id
1054 , completion_transaction_id
1055 , wip_entity_type
1056 , schedule_id
1057 , repetitive_line_id
1058 , employee_code
1059 , primary_switch
1060 , schedule_update_code
1061 , setup_teardown_code
1062 , item_ordering
1063 , negative_req_flag
1064 , operation_seq_num
1065 , picking_line_id
1066 , trx_source_line_id
1067 , trx_source_delivery_id
1068 , physical_adjustment_id
1069 , cycle_count_id
1070 , rma_line_id
1071 , customer_ship_id
1072 , currency_code
1073 , currency_conversion_rate
1074 , currency_conversion_type
1075 , currency_conversion_date
1076 , ussgl_transaction_code
1077 , vendor_lot_number
1078 , encumbrance_account
1079 , encumbrance_amount
1080 , ship_to_location
1081 , shipment_number
1082 , transfer_cost
1083 , transportation_cost
1084 , transportation_account
1085 , freight_code
1086 , containers
1087 , waybill_airbill
1088 , expected_arrival_date
1089 , transfer_subinventory
1090 , transfer_organization
1091 , transfer_to_location
1092 , new_average_cost
1093 , value_change
1094 , percentage_change
1095 , material_allocation_temp_id
1096 , demand_source_header_id
1097 , demand_source_line
1098 , demand_source_delivery
1099 , item_segments
1100 , item_description
1101 , item_trx_enabled_flag
1102 , item_location_control_code
1103 , item_restrict_subinv_code
1104 , item_restrict_locators_code
1105 , item_revision_qty_control_code
1106 , item_primary_uom_code
1107 , item_uom_class
1108 , item_shelf_life_code
1109 , item_shelf_life_days
1110 , item_lot_control_code
1111 , item_serial_control_code
1112 , item_inventory_asset_flag
1113 , allowed_units_lookup_code
1114 , department_id
1115 , department_code
1116 , wip_supply_type
1117 , supply_subinventory
1118 , supply_locator_id
1119 , valid_subinventory_flag
1120 , valid_locator_flag
1121 , locator_segments
1122 , current_locator_control_code
1123 , number_of_lots_entered
1124 , wip_commit_flag
1125 , next_lot_number
1126 , lot_alpha_prefix
1127 , next_serial_number
1128 , serial_alpha_prefix
1129 , shippable_flag
1130 , posting_flag
1131 , required_flag
1132 , process_flag
1133 , error_code
1134 , error_explanation
1135 , attribute_category
1136 , attribute1
1137 , attribute2
1138 , attribute3
1139 , attribute4
1140 , attribute5
1141 , attribute6
1142 , attribute7
1143 , attribute8
1144 , attribute9
1145 , attribute10
1146 , attribute11
1147 , attribute12
1148 , attribute13
1149 , attribute14
1150 , attribute15
1151 , movement_id
1152 , reservation_quantity
1153 , shipped_quantity
1154 , transaction_line_number
1155 , task_id
1156 , to_task_id
1157 , source_task_id
1158 , project_id
1159 , source_project_id
1160 , pa_expenditure_org_id
1161 , to_project_id
1162 , expenditure_type
1163 , final_completion_flag
1164 , transfer_percentage
1165 , transaction_sequence_id
1166 , material_account
1167 , material_overhead_account
1168 , resource_account
1169 , outside_processing_account
1170 , overhead_account
1171 , flow_schedule
1172 , cost_group_id
1173 , demand_class
1174 , qa_collection_id
1175 , kanban_card_id
1176 , overcompletion_txn_qty
1177 , overcompletion_primary_qty
1178 , overcompletion_transaction_id
1179 , end_item_unit_number
1180 , scheduled_payback_date
1181 , line_type_code
1182 , parent_transaction_temp_id
1183 , put_away_strategy_id
1184 , put_away_rule_id
1185 , pick_strategy_id
1186 , pick_rule_id
1187 , move_order_line_id
1188 , task_group_id
1189 , pick_slip_number
1190 , reservation_id
1191 , common_bom_seq_id
1192 , common_routing_seq_id
1193 , org_cost_group_id
1194 , cost_type_id
1195 , transaction_status
1196 , standard_operation_id
1197 , task_priority
1198 , wms_task_type
1199 , parent_line_id
1200 , source_lot_number
1201 , transfer_cost_group_id
1202 , lpn_id
1203 , transfer_lpn_id
1204 , wms_task_status
1205 , content_lpn_id
1206 , container_item_id
1207 , cartonization_id
1208 , pick_slip_date
1209 , rebuild_item_id
1210 , rebuild_serial_number
1211 , rebuild_activity_id
1212 , rebuild_job_name
1213 , organization_type
1214 , transfer_organization_type
1215 , owning_organization_id
1216 , owning_tp_type
1217 , xfr_owning_organization_id
1218 , transfer_owning_tp_type
1219 , planning_organization_id
1220 , planning_tp_type
1221 , xfr_planning_organization_id
1222 , transfer_planning_tp_type
1223 , secondary_uom_code
1224 , secondary_transaction_quantity
1225 , allocated_lpn_id
1226 , schedule_number
1227 , scheduled_flag
1228 , class_code
1229 , schedule_group
1230 , build_sequence
1231 , bom_revision
1232 , routing_revision
1233 , bom_revision_date
1234 , routing_revision_date
1235 , alternate_bom_designator
1236 , alternate_routing_designator
1237 , transaction_batch_id
1238 , transaction_batch_seq
1239 , operation_plan_id
1240 , intransit_account
1241 , fob_point
1242 , logical_trx_type_code
1243 , move_order_header_id
1244 , original_transaction_temp_id
1245 , serial_allocated_flag
1246 , trx_flow_header_id
1247 , fulfillment_base
1248 )
1249 SELECT mmtt.transaction_header_id
1250 , mmtt.transaction_temp_id
1251 , mmtt.source_code
1252 , mmtt.source_line_id
1253 , mmtt.transaction_mode
1254 , mmtt.lock_flag
1255 , mmtt.last_update_date
1256 , mmtt.last_updated_by
1257 , mmtt.creation_date
1258 , mmtt.created_by
1259 , mmtt.last_update_login
1260 , mmtt.request_id
1261 , mmtt.program_application_id
1262 , mmtt.program_id
1263 , mmtt.program_update_date
1264 , mmtt.inventory_item_id
1265 , mmtt.revision
1266 , mmtt.organization_id
1267 , mmtt.subinventory_code
1268 , mmtt.locator_id
1269 , mmtt.transaction_quantity
1270 , mmtt.primary_quantity
1271 , mmtt.transaction_uom
1272 , mmtt.transaction_cost
1273 , mmtt.transaction_type_id
1274 , mmtt.transaction_action_id
1275 , mmtt.transaction_source_type_id
1276 , mmtt.transaction_source_id
1277 , mmtt.transaction_source_name
1278 , mmtt.transaction_date
1279 , mmtt.acct_period_id
1280 , mmtt.distribution_account_id
1281 , mmtt.transaction_reference
1282 , mmtt.requisition_line_id
1283 , mmtt.requisition_distribution_id
1284 , mmtt.reason_id
1285 , mmtt.lot_number
1286 , mmtt.lot_expiration_date
1287 , mmtt.serial_number
1288 , mmtt.receiving_document
1289 , mmtt.demand_id
1290 , mmtt.rcv_transaction_id
1291 , mmtt.move_transaction_id
1292 , mmtt.completion_transaction_id
1293 , mmtt.wip_entity_type
1294 , mmtt.schedule_id
1295 , mmtt.repetitive_line_id
1296 , mmtt.employee_code
1297 , mmtt.primary_switch
1298 , mmtt.schedule_update_code
1299 , mmtt.setup_teardown_code
1300 , mmtt.item_ordering
1301 , mmtt.negative_req_flag
1302 , mmtt.operation_seq_num
1303 , mmtt.picking_line_id
1304 , mmtt.trx_source_line_id
1305 , mmtt.trx_source_delivery_id
1306 , mmtt.physical_adjustment_id
1307 , mmtt.cycle_count_id
1308 , mmtt.rma_line_id
1309 , mmtt.customer_ship_id
1310 , mmtt.currency_code
1311 , mmtt.currency_conversion_rate
1312 , mmtt.currency_conversion_type
1313 , mmtt.currency_conversion_date
1314 , mmtt.ussgl_transaction_code
1315 , mmtt.vendor_lot_number
1316 , mmtt.encumbrance_account
1317 , mmtt.encumbrance_amount
1318 , mmtt.ship_to_location
1319 , mmtt.shipment_number
1320 , mmtt.transfer_cost
1321 , mmtt.transportation_cost
1322 , mmtt.transportation_account
1323 , mmtt.freight_code
1324 , mmtt.containers
1325 , mmtt.waybill_airbill
1326 , mmtt.expected_arrival_date
1327 , mmtt.transfer_subinventory
1328 , mmtt.transfer_organization
1329 , mmtt.transfer_to_location
1330 , mmtt.new_average_cost
1331 , mmtt.value_change
1332 , mmtt.percentage_change
1333 , mmtt.material_allocation_temp_id
1334 , mmtt.demand_source_header_id
1335 , mmtt.demand_source_line
1336 , mmtt.demand_source_delivery
1337 , mmtt.item_segments
1338 , mmtt.item_description
1339 , mmtt.item_trx_enabled_flag
1340 , mmtt.item_location_control_code
1341 , mmtt.item_restrict_subinv_code
1342 , mmtt.item_restrict_locators_code
1343 , mmtt.item_revision_qty_control_code
1344 , mmtt.item_primary_uom_code
1345 , mmtt.item_uom_class
1346 , mmtt.item_shelf_life_code
1347 , mmtt.item_shelf_life_days
1348 , mmtt.item_lot_control_code
1349 , mmtt.item_serial_control_code
1350 , mmtt.item_inventory_asset_flag
1351 , mmtt.allowed_units_lookup_code
1352 , mmtt.department_id
1353 , mmtt.department_code
1354 , mmtt.wip_supply_type
1355 , mmtt.supply_subinventory
1356 , mmtt.supply_locator_id
1357 , mmtt.valid_subinventory_flag
1358 , mmtt.valid_locator_flag
1359 , mmtt.locator_segments
1360 , mmtt.current_locator_control_code
1361 , mmtt.number_of_lots_entered
1362 , mmtt.wip_commit_flag
1363 , mmtt.next_lot_number
1364 , mmtt.lot_alpha_prefix
1365 , mmtt.next_serial_number
1366 , mmtt.serial_alpha_prefix
1367 , mmtt.shippable_flag
1368 , mmtt.posting_flag
1369 , mmtt.required_flag
1370 , mmtt.process_flag
1371 , mmtt.error_code
1372 , mmtt.error_explanation
1373 , mmtt.attribute_category
1374 , mmtt.attribute1
1375 , mmtt.attribute2
1376 , mmtt.attribute3
1377 , mmtt.attribute4
1378 , mmtt.attribute5
1379 , mmtt.attribute6
1380 , mmtt.attribute7
1381 , mmtt.attribute8
1382 , mmtt.attribute9
1383 , mmtt.attribute10
1384 , mmtt.attribute11
1385 , mmtt.attribute12
1386 , mmtt.attribute13
1387 , mmtt.attribute14
1388 , mmtt.attribute15
1389 , mmtt.movement_id
1390 , mmtt.reservation_quantity
1391 , mmtt.shipped_quantity
1392 , mmtt.transaction_line_number
1393 , mmtt.task_id
1394 , mmtt.to_task_id
1395 , mmtt.source_task_id
1396 , mmtt.project_id
1397 , mmtt.source_project_id
1398 , mmtt.pa_expenditure_org_id
1399 , mmtt.to_project_id
1400 , mmtt.expenditure_type
1401 , mmtt.final_completion_flag
1402 , mmtt.transfer_percentage
1403 , mmtt.transaction_sequence_id
1404 , mmtt.material_account
1405 , mmtt.material_overhead_account
1406 , mmtt.resource_account
1407 , mmtt.outside_processing_account
1408 , mmtt.overhead_account
1409 , mmtt.flow_schedule
1410 , mmtt.cost_group_id
1411 , mmtt.demand_class
1412 , mmtt.qa_collection_id
1413 , mmtt.kanban_card_id
1414 , mmtt.overcompletion_transaction_qty
1415 , mmtt.overcompletion_primary_qty
1416 , mmtt.overcompletion_transaction_id
1417 , mmtt.end_item_unit_number
1418 , mmtt.scheduled_payback_date
1419 , mmtt.line_type_code
1420 , mmtt.parent_transaction_temp_id
1421 , mmtt.put_away_strategy_id
1422 , mmtt.put_away_rule_id
1423 , mmtt.pick_strategy_id
1424 , mmtt.pick_rule_id
1425 , mmtt.move_order_line_id
1426 , mmtt.task_group_id
1427 , mmtt.pick_slip_number
1428 , mmtt.reservation_id
1429 , mmtt.common_bom_seq_id
1430 , mmtt.common_routing_seq_id
1431 , mmtt.org_cost_group_id
1432 , mmtt.cost_type_id
1433 , mmtt.transaction_status
1434 , mmtt.standard_operation_id
1435 , mmtt.task_priority
1436 , mmtt.wms_task_type
1437 , mmtt.parent_line_id
1438 , mmtt.source_lot_number
1439 , mmtt.transfer_cost_group_id
1440 , mmtt.lpn_id
1441 , mmtt.transfer_lpn_id
1442 , mmtt.wms_task_status
1443 , mmtt.content_lpn_id
1444 , mmtt.container_item_id
1445 , mmtt.cartonization_id
1446 , mmtt.pick_slip_date
1447 , mmtt.rebuild_item_id
1448 , mmtt.rebuild_serial_number
1449 , mmtt.rebuild_activity_id
1450 , mmtt.rebuild_job_name
1451 , mmtt.organization_type
1452 , mmtt.transfer_organization_type
1453 , mmtt.owning_organization_id
1454 , mmtt.owning_tp_type
1455 , mmtt.xfr_owning_organization_id
1456 , mmtt.transfer_owning_tp_type
1457 , mmtt.planning_organization_id
1458 , mmtt.planning_tp_type
1459 , mmtt.xfr_planning_organization_id
1460 , mmtt.transfer_planning_tp_type
1461 , mmtt.secondary_uom_code
1462 , mmtt.secondary_transaction_quantity
1463 , mmtt.allocated_lpn_id
1464 , mmtt.schedule_number
1465 , mmtt.scheduled_flag
1466 , mmtt.class_code
1467 , mmtt.schedule_group
1468 , mmtt.build_sequence
1469 , mmtt.bom_revision
1470 , mmtt.routing_revision
1471 , mmtt.bom_revision_date
1472 , mmtt.routing_revision_date
1473 , mmtt.alternate_bom_designator
1474 , mmtt.alternate_routing_designator
1475 , mmtt.transaction_batch_id
1476 , mmtt.transaction_batch_seq
1477 , mmtt.operation_plan_id
1478 , mmtt.intransit_account
1479 , mmtt.fob_point
1480 , mmtt.logical_trx_type_code
1481 , mmtt.move_order_header_id
1482 , mmtt.original_transaction_temp_id
1483 , mmtt.serial_allocated_flag
1484 , mmtt.trx_flow_header_id
1485 , mmtt.fulfillment_base
1486 FROM mtl_material_transactions_temp mmtt
1487 WHERE mmtt.move_order_header_id = p_move_order_header_id
1488 AND mmtt.container_item_id IS NULL;
1489 --}
1490 END IF;
1491
1492 IF g_debug = 1 THEN
1493 print_debug ('Number of rows inserted into WCT: ' || SQL%ROWCOUNT, l_api_name);
1494 END IF;
1495
1496 EXCEPTION
1497 WHEN fnd_api.g_exc_error THEN
1498 x_return_status := fnd_api.g_ret_sts_error;
1499 ROLLBACK TO create_wct_sp;
1500 fnd_msg_pub.count_and_get
1501 ( p_count => l_msg_count
1502 , p_data => l_msg_data
1503 , p_encoded => fnd_api.g_false
1504 );
1505 IF g_debug = 1 THEN
1506 print_debug (l_msg_data, l_api_name);
1507 END IF;
1508
1509 WHEN OTHERS THEN
1510 x_return_status := fnd_api.g_ret_sts_unexp_error;
1511 ROLLBACK TO create_wct_sp;
1512 IF g_debug = 1 THEN
1513 print_debug ('Other error: ' || SQLERRM, l_api_name);
1514 END IF;
1515
1516 END create_wct;
1517
1518
1519
1520 PROCEDURE merge_wct_to_mmtt
1521 ( x_return_status OUT NOCOPY VARCHAR2
1522 ) IS
1523 l_api_name VARCHAR2(30) := 'merge_wct_to_mmtt';
1524 l_msg_count NUMBER;
1525 l_msg_data VARCHAR2(2000);
1526 BEGIN
1527 x_return_status := fnd_api.g_ret_sts_success;
1528
1529 SAVEPOINT merge_wct_sp;
1530
1531 MERGE INTO mtl_material_transactions_temp mmtt
1532 USING ( SELECT * FROM wms_cartonization_temp ) wct
1533 ON ( mmtt.transaction_temp_id = wct.transaction_temp_id )
1534 WHEN MATCHED THEN
1535 UPDATE SET
1536 mmtt.primary_quantity = wct.primary_quantity
1537 , mmtt.transaction_quantity = wct.transaction_quantity
1538 , mmtt.secondary_transaction_quantity = wct.secondary_transaction_quantity
1539 , mmtt.cartonization_id = wct.cartonization_id
1540 , mmtt.container_item_id = NVL(wct.container_item_id,-1)
1541 , mmtt.transaction_batch_id = wct.transaction_batch_id
1542 , mmtt.last_update_date = SYSDATE
1543 , mmtt.last_updated_by = g_user_id
1544 WHEN NOT MATCHED THEN
1545 INSERT ( mmtt.transaction_header_id
1546 , mmtt.transaction_temp_id
1547 , mmtt.source_code
1548 , mmtt.source_line_id
1549 , mmtt.transaction_mode
1550 , mmtt.lock_flag
1551 , mmtt.last_update_date
1552 , mmtt.last_updated_by
1553 , mmtt.creation_date
1554 , mmtt.created_by
1555 , mmtt.last_update_login
1556 , mmtt.request_id
1557 , mmtt.program_application_id
1558 , mmtt.program_id
1559 , mmtt.program_update_date
1560 , mmtt.inventory_item_id
1561 , mmtt.revision
1562 , mmtt.organization_id
1563 , mmtt.subinventory_code
1564 , mmtt.locator_id
1565 , mmtt.transaction_quantity
1566 , mmtt.primary_quantity
1567 , mmtt.transaction_uom
1568 , mmtt.transaction_cost
1569 , mmtt.transaction_type_id
1570 , mmtt.transaction_action_id
1571 , mmtt.transaction_source_type_id
1572 , mmtt.transaction_source_id
1573 , mmtt.transaction_source_name
1574 , mmtt.transaction_date
1575 , mmtt.acct_period_id
1576 , mmtt.distribution_account_id
1577 , mmtt.transaction_reference
1578 , mmtt.requisition_line_id
1579 , mmtt.requisition_distribution_id
1580 , mmtt.reason_id
1581 , mmtt.lot_number
1582 , mmtt.lot_expiration_date
1583 , mmtt.serial_number
1584 , mmtt.receiving_document
1585 , mmtt.demand_id
1586 , mmtt.rcv_transaction_id
1587 , mmtt.move_transaction_id
1588 , mmtt.completion_transaction_id
1589 , mmtt.wip_entity_type
1590 , mmtt.schedule_id
1591 , mmtt.repetitive_line_id
1592 , mmtt.employee_code
1593 , mmtt.primary_switch
1594 , mmtt.schedule_update_code
1595 , mmtt.setup_teardown_code
1596 , mmtt.item_ordering
1597 , mmtt.negative_req_flag
1598 , mmtt.operation_seq_num
1599 , mmtt.picking_line_id
1600 , mmtt.trx_source_line_id
1601 , mmtt.trx_source_delivery_id
1602 , mmtt.physical_adjustment_id
1603 , mmtt.cycle_count_id
1604 , mmtt.rma_line_id
1605 , mmtt.customer_ship_id
1606 , mmtt.currency_code
1607 , mmtt.currency_conversion_rate
1608 , mmtt.currency_conversion_type
1609 , mmtt.currency_conversion_date
1610 , mmtt.ussgl_transaction_code
1611 , mmtt.vendor_lot_number
1612 , mmtt.encumbrance_account
1613 , mmtt.encumbrance_amount
1614 , mmtt.ship_to_location
1615 , mmtt.shipment_number
1616 , mmtt.transfer_cost
1617 , mmtt.transportation_cost
1618 , mmtt.transportation_account
1619 , mmtt.freight_code
1620 , mmtt.containers
1621 , mmtt.waybill_airbill
1622 , mmtt.expected_arrival_date
1623 , mmtt.transfer_subinventory
1624 , mmtt.transfer_organization
1625 , mmtt.transfer_to_location
1626 , mmtt.new_average_cost
1627 , mmtt.value_change
1628 , mmtt.percentage_change
1629 , mmtt.material_allocation_temp_id
1630 , mmtt.demand_source_header_id
1631 , mmtt.demand_source_line
1632 , mmtt.demand_source_delivery
1633 , mmtt.item_segments
1634 , mmtt.item_description
1635 , mmtt.item_trx_enabled_flag
1636 , mmtt.item_location_control_code
1637 , mmtt.item_restrict_subinv_code
1638 , mmtt.item_restrict_locators_code
1639 , mmtt.item_revision_qty_control_code
1640 , mmtt.item_primary_uom_code
1641 , mmtt.item_uom_class
1642 , mmtt.item_shelf_life_code
1643 , mmtt.item_shelf_life_days
1644 , mmtt.item_lot_control_code
1645 , mmtt.item_serial_control_code
1646 , mmtt.item_inventory_asset_flag
1647 , mmtt.allowed_units_lookup_code
1648 , mmtt.department_id
1649 , mmtt.department_code
1650 , mmtt.wip_supply_type
1651 , mmtt.supply_subinventory
1652 , mmtt.supply_locator_id
1653 , mmtt.valid_subinventory_flag
1654 , mmtt.valid_locator_flag
1655 , mmtt.locator_segments
1656 , mmtt.current_locator_control_code
1657 , mmtt.number_of_lots_entered
1658 , mmtt.wip_commit_flag
1659 , mmtt.next_lot_number
1660 , mmtt.lot_alpha_prefix
1661 , mmtt.next_serial_number
1662 , mmtt.serial_alpha_prefix
1663 , mmtt.shippable_flag
1664 , mmtt.posting_flag
1665 , mmtt.required_flag
1666 , mmtt.process_flag
1667 , mmtt.error_code
1668 , mmtt.error_explanation
1669 , mmtt.attribute_category
1670 , mmtt.attribute1
1671 , mmtt.attribute2
1672 , mmtt.attribute3
1673 , mmtt.attribute4
1674 , mmtt.attribute5
1675 , mmtt.attribute6
1676 , mmtt.attribute7
1677 , mmtt.attribute8
1678 , mmtt.attribute9
1679 , mmtt.attribute10
1680 , mmtt.attribute11
1681 , mmtt.attribute12
1682 , mmtt.attribute13
1683 , mmtt.attribute14
1684 , mmtt.attribute15
1685 , mmtt.movement_id
1686 , mmtt.reservation_quantity
1687 , mmtt.shipped_quantity
1688 , mmtt.transaction_line_number
1689 , mmtt.task_id
1690 , mmtt.to_task_id
1691 , mmtt.source_task_id
1692 , mmtt.project_id
1693 , mmtt.source_project_id
1694 , mmtt.pa_expenditure_org_id
1695 , mmtt.to_project_id
1696 , mmtt.expenditure_type
1697 , mmtt.final_completion_flag
1698 , mmtt.transfer_percentage
1699 , mmtt.transaction_sequence_id
1700 , mmtt.material_account
1701 , mmtt.material_overhead_account
1702 , mmtt.resource_account
1703 , mmtt.outside_processing_account
1704 , mmtt.overhead_account
1705 , mmtt.flow_schedule
1706 , mmtt.cost_group_id
1707 , mmtt.transfer_cost_group_id
1708 , mmtt.demand_class
1709 , mmtt.qa_collection_id
1710 , mmtt.kanban_card_id
1711 , mmtt.overcompletion_transaction_qty
1712 , mmtt.overcompletion_primary_qty
1713 , mmtt.overcompletion_transaction_id
1714 , mmtt.end_item_unit_number
1715 , mmtt.scheduled_payback_date
1716 , mmtt.line_type_code
1717 , mmtt.parent_transaction_temp_id
1718 , mmtt.put_away_strategy_id
1719 , mmtt.put_away_rule_id
1720 , mmtt.pick_strategy_id
1721 , mmtt.pick_rule_id
1722 , mmtt.move_order_line_id
1723 , mmtt.task_group_id
1724 , mmtt.pick_slip_number
1725 , mmtt.reservation_id
1726 , mmtt.common_bom_seq_id
1727 , mmtt.common_routing_seq_id
1728 , mmtt.org_cost_group_id
1729 , mmtt.cost_type_id
1730 , mmtt.transaction_status
1731 , mmtt.standard_operation_id
1732 , mmtt.task_priority
1733 , mmtt.wms_task_type
1734 , mmtt.parent_line_id
1735 , mmtt.source_lot_number
1736 , mmtt.lpn_id
1737 , mmtt.transfer_lpn_id
1738 , mmtt.wms_task_status
1739 , mmtt.content_lpn_id
1740 , mmtt.container_item_id
1741 , mmtt.cartonization_id
1742 , mmtt.pick_slip_date
1743 , mmtt.rebuild_item_id
1744 , mmtt.rebuild_serial_number
1745 , mmtt.rebuild_activity_id
1746 , mmtt.rebuild_job_name
1747 , mmtt.organization_type
1748 , mmtt.transfer_organization_type
1749 , mmtt.owning_organization_id
1750 , mmtt.owning_tp_type
1751 , mmtt.xfr_owning_organization_id
1752 , mmtt.transfer_owning_tp_type
1753 , mmtt.planning_organization_id
1754 , mmtt.planning_tp_type
1755 , mmtt.xfr_planning_organization_id
1756 , mmtt.transfer_planning_tp_type
1757 , mmtt.secondary_uom_code
1758 , mmtt.secondary_transaction_quantity
1759 , mmtt.transaction_batch_id
1760 , mmtt.transaction_batch_seq
1761 , mmtt.allocated_lpn_id
1762 , mmtt.schedule_number
1763 , mmtt.scheduled_flag
1764 , mmtt.class_code
1765 , mmtt.schedule_group
1766 , mmtt.build_sequence
1767 , mmtt.bom_revision
1768 , mmtt.routing_revision
1769 , mmtt.bom_revision_date
1770 , mmtt.routing_revision_date
1771 , mmtt.alternate_bom_designator
1772 , mmtt.alternate_routing_designator
1773 , mmtt.operation_plan_id
1774 , mmtt.intransit_account
1775 , mmtt.fob_point
1776 , mmtt.logical_trx_type_code
1777 , mmtt.original_transaction_temp_id
1778 , mmtt.trx_flow_header_id
1779 , mmtt.serial_allocated_flag
1780 , mmtt.move_order_header_id
1781 , mmtt.fulfillment_base
1782 )
1783 VALUES ( wct.transaction_header_id
1784 , wct.transaction_temp_id
1785 , wct.source_code
1786 , wct.source_line_id
1787 , wct.transaction_mode
1788 , wct.lock_flag
1789 , SYSDATE
1790 , g_user_id
1791 , SYSDATE
1792 , g_user_id
1793 , wct.last_update_login
1794 , wct.request_id
1795 , wct.program_application_id
1796 , wct.program_id
1797 , wct.program_update_date
1798 , wct.inventory_item_id
1799 , wct.revision
1800 , wct.organization_id
1801 , wct.subinventory_code
1802 , wct.locator_id
1803 , wct.transaction_quantity
1804 , wct.primary_quantity
1805 , wct.transaction_uom
1806 , wct.transaction_cost
1807 , wct.transaction_type_id
1808 , wct.transaction_action_id
1809 , wct.transaction_source_type_id
1810 , wct.transaction_source_id
1811 , wct.transaction_source_name
1812 , wct.transaction_date
1813 , wct.acct_period_id
1814 , wct.distribution_account_id
1815 , wct.transaction_reference
1816 , wct.requisition_line_id
1817 , wct.requisition_distribution_id
1818 , wct.reason_id
1819 , wct.lot_number
1820 , wct.lot_expiration_date
1821 , wct.serial_number
1822 , wct.receiving_document
1823 , wct.demand_id
1824 , wct.rcv_transaction_id
1825 , wct.move_transaction_id
1826 , wct.completion_transaction_id
1827 , wct.wip_entity_type
1828 , wct.schedule_id
1829 , wct.repetitive_line_id
1830 , wct.employee_code
1831 , wct.primary_switch
1832 , wct.schedule_update_code
1833 , wct.setup_teardown_code
1834 , wct.item_ordering
1835 , wct.negative_req_flag
1836 , wct.operation_seq_num
1837 , wct.picking_line_id
1838 , wct.trx_source_line_id
1839 , wct.trx_source_delivery_id
1840 , wct.physical_adjustment_id
1841 , wct.cycle_count_id
1842 , wct.rma_line_id
1843 , wct.customer_ship_id
1844 , wct.currency_code
1845 , wct.currency_conversion_rate
1846 , wct.currency_conversion_type
1847 , wct.currency_conversion_date
1848 , wct.ussgl_transaction_code
1849 , wct.vendor_lot_number
1850 , wct.encumbrance_account
1851 , wct.encumbrance_amount
1852 , wct.ship_to_location
1853 , wct.shipment_number
1854 , wct.transfer_cost
1855 , wct.transportation_cost
1856 , wct.transportation_account
1857 , wct.freight_code
1858 , wct.containers
1859 , wct.waybill_airbill
1860 , wct.expected_arrival_date
1861 , wct.transfer_subinventory
1862 , wct.transfer_organization
1863 , wct.transfer_to_location
1864 , wct.new_average_cost
1865 , wct.value_change
1866 , wct.percentage_change
1867 , wct.material_allocation_temp_id
1868 , wct.demand_source_header_id
1869 , wct.demand_source_line
1870 , wct.demand_source_delivery
1871 , wct.item_segments
1872 , wct.item_description
1873 , wct.item_trx_enabled_flag
1874 , wct.item_location_control_code
1875 , wct.item_restrict_subinv_code
1876 , wct.item_restrict_locators_code
1877 , wct.item_revision_qty_control_code
1878 , wct.item_primary_uom_code
1879 , wct.item_uom_class
1880 , wct.item_shelf_life_code
1881 , wct.item_shelf_life_days
1882 , wct.item_lot_control_code
1883 , wct.item_serial_control_code
1884 , wct.item_inventory_asset_flag
1885 , wct.allowed_units_lookup_code
1886 , wct.department_id
1887 , wct.department_code
1888 , wct.wip_supply_type
1889 , wct.supply_subinventory
1890 , wct.supply_locator_id
1891 , wct.valid_subinventory_flag
1892 , wct.valid_locator_flag
1893 , wct.locator_segments
1894 , wct.current_locator_control_code
1895 , wct.number_of_lots_entered
1896 , wct.wip_commit_flag
1897 , wct.next_lot_number
1898 , wct.lot_alpha_prefix
1899 , wct.next_serial_number
1900 , wct.serial_alpha_prefix
1901 , wct.shippable_flag
1902 , wct.posting_flag
1903 , wct.required_flag
1904 , wct.process_flag
1905 , wct.error_code
1906 , wct.error_explanation
1907 , wct.attribute_category
1908 , wct.attribute1
1909 , wct.attribute2
1910 , wct.attribute3
1911 , wct.attribute4
1912 , wct.attribute5
1913 , wct.attribute6
1914 , wct.attribute7
1915 , wct.attribute8
1916 , wct.attribute9
1917 , wct.attribute10
1918 , wct.attribute11
1919 , wct.attribute12
1920 , wct.attribute13
1921 , wct.attribute14
1922 , wct.attribute15
1923 , wct.movement_id
1924 , wct.reservation_quantity
1925 , wct.shipped_quantity
1926 , wct.transaction_line_number
1927 , wct.task_id
1928 , wct.to_task_id
1929 , wct.source_task_id
1930 , wct.project_id
1931 , wct.source_project_id
1932 , wct.pa_expenditure_org_id
1933 , wct.to_project_id
1934 , wct.expenditure_type
1935 , wct.final_completion_flag
1936 , wct.transfer_percentage
1937 , wct.transaction_sequence_id
1938 , wct.material_account
1939 , wct.material_overhead_account
1940 , wct.resource_account
1941 , wct.outside_processing_account
1942 , wct.overhead_account
1943 , wct.flow_schedule
1944 , wct.cost_group_id
1945 , wct.transfer_cost_group_id
1946 , wct.demand_class
1947 , wct.qa_collection_id
1948 , wct.kanban_card_id
1949 , wct.overcompletion_txn_qty
1950 , wct.overcompletion_primary_qty
1951 , wct.overcompletion_transaction_id
1952 , wct.end_item_unit_number
1953 , wct.scheduled_payback_date
1954 , wct.line_type_code
1955 , wct.parent_transaction_temp_id
1956 , wct.put_away_strategy_id
1957 , wct.put_away_rule_id
1958 , wct.pick_strategy_id
1959 , wct.pick_rule_id
1960 , wct.move_order_line_id
1961 , wct.task_group_id
1962 , wct.pick_slip_number
1963 , wct.reservation_id
1964 , wct.common_bom_seq_id
1965 , wct.common_routing_seq_id
1966 , wct.org_cost_group_id
1967 , wct.cost_type_id
1968 , wct.transaction_status
1969 , wct.standard_operation_id
1970 , wct.task_priority
1971 , wct.wms_task_type
1972 , wct.parent_line_id
1973 , wct.source_lot_number
1974 , wct.lpn_id
1975 , wct.transfer_lpn_id
1976 , wct.wms_task_status
1977 , wct.content_lpn_id
1978 , NVL(wct.container_item_id,-1)
1979 , wct.cartonization_id
1980 , wct.pick_slip_date
1981 , wct.rebuild_item_id
1982 , wct.rebuild_serial_number
1983 , wct.rebuild_activity_id
1984 , wct.rebuild_job_name
1985 , wct.organization_type
1986 , wct.transfer_organization_type
1987 , wct.owning_organization_id
1988 , wct.owning_tp_type
1989 , wct.xfr_owning_organization_id
1990 , wct.transfer_owning_tp_type
1991 , wct.planning_organization_id
1992 , wct.planning_tp_type
1993 , wct.xfr_planning_organization_id
1994 , wct.transfer_planning_tp_type
1995 , wct.secondary_uom_code
1996 , wct.secondary_transaction_quantity
1997 , wct.transaction_batch_id
1998 , wct.transaction_batch_seq
1999 , wct.allocated_lpn_id
2000 , wct.schedule_number
2001 , wct.scheduled_flag
2002 , wct.class_code
2003 , wct.schedule_group
2004 , wct.build_sequence
2005 , wct.bom_revision
2006 , wct.routing_revision
2007 , wct.bom_revision_date
2008 , wct.routing_revision_date
2009 , wct.alternate_bom_designator
2010 , wct.alternate_routing_designator
2011 , wct.operation_plan_id
2012 , wct.intransit_account
2013 , wct.fob_point
2014 , wct.logical_trx_type_code
2015 , wct.original_transaction_temp_id
2016 , wct.trx_flow_header_id
2017 , wct.serial_allocated_flag
2018 , wct.move_order_header_id
2019 , wct.fulfillment_base
2020 );
2021
2022 IF g_debug = 1 AND SQL%ROWCOUNT > 0 THEN
2023 print_debug(TO_CHAR(SQL%ROWCOUNT) || ' rows merged.', l_api_name);
2024 END IF;
2025
2026 EXCEPTION
2027 WHEN fnd_api.g_exc_error THEN
2028 x_return_status := fnd_api.g_ret_sts_error;
2029 ROLLBACK TO merge_wct_sp;
2030 fnd_msg_pub.count_and_get
2031 ( p_count => l_msg_count
2032 , p_data => l_msg_data
2033 , p_encoded => fnd_api.g_false
2034 );
2035 IF g_debug = 1 THEN
2036 print_debug (l_msg_data, l_api_name);
2037 END IF;
2038
2039 WHEN OTHERS THEN
2040 x_return_status := fnd_api.g_ret_sts_unexp_error;
2041 ROLLBACK TO merge_wct_sp;
2042 IF g_debug = 1 THEN
2043 print_debug ('Other error: ' || SQLERRM, l_api_name);
2044 END IF;
2045
2046 END merge_wct_to_mmtt;
2047
2048 --
2049 -- If any cartonization rules setup exists in the organization this method
2050 -- gets invoked from the cartonize procedure. It populates cartonization_id,
2051 -- container_item_id of MMTT rows belonging to a particular Move Order
2052 -- Header ID
2053 --
2054 PROCEDURE rulebased_cartonization
2055 ( x_return_status OUT NOCOPY VARCHAR2
2056 , p_org_id IN NUMBER
2057 , p_move_order_header_id IN NUMBER
2058 ) IS
2059 l_api_name VARCHAR2(30) := 'rulebased_cartonization';
2060 l_msg_count NUMBER;
2061 l_msg_data VARCHAR2(2000);
2062
2063 l_api_return_status VARCHAR2(1);
2064 l_move_order_type NUMBER;
2065
2066 TYPE rules_table_type IS TABLE OF wms_selection_criteria_txn%ROWTYPE;
2067 rules_table rules_table_type;
2068 rules_table1 rules_table_type;
2069
2070 l_count NUMBER;
2071
2072 BEGIN
2073 x_return_status := fnd_api.g_ret_sts_success;
2074
2075 SAVEPOINT rb_carton_sp;
2076
2077 IF g_debug = 1 THEN
2078 print_debug( 'Entered with parameters: ' || g_newline ||
2079 'p_org_id => ' || p_org_id ||
2080 'p_move_order_header_id =>' || p_move_order_header_id
2081 , l_api_name);
2082 END IF;
2083
2084 l_api_return_status := fnd_api.g_ret_sts_success;
2085 assign_pick_slip_numbers
2086 ( p_organization_id => p_org_id
2087 , p_mo_header_id => p_move_order_header_id
2088 , p_grouping_rule_id => NULL
2089 , x_return_status => l_api_return_status
2090 );
2091
2092 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
2093 IF g_debug = 1 THEN
2094 print_debug('Error status from assign_pick_slip_number: '
2095 || l_api_return_status, l_api_name);
2096 END IF;
2097 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
2098 RAISE fnd_api.g_exc_error;
2099 ELSE
2100 RAISE fnd_api.g_exc_unexpected_error;
2101 END IF;
2102 END IF;
2103
2104 l_api_return_status := fnd_api.g_ret_sts_success;
2105
2106
2107
2108 IF g_debug = 1 THEN
2109 print_debug('Fetching cartonization rules.. for checking if it is a pick slip group rule', l_api_name);
2110 END IF;
2111
2112 SELECT * BULK COLLECT
2113 INTO rules_table1
2114 FROM wms_selection_criteria_txn
2115 WHERE rule_type_code = 12
2116 AND from_organization_id = p_org_id
2117 AND enabled_flag = 1
2118 ORDER BY sequence_number;
2119
2120 l_api_return_status := fnd_api.g_ret_sts_success;
2121 FOR iii IN rules_table1.FIRST .. rules_table1.LAST LOOP --{
2122
2123 print_debug('Rules return type id is '||rules_table1(iii).return_type_id, l_api_name);
2124
2125 -- If pick slip grouping rule then set the global variable as 'Y'
2126 IF rules_table1(iii).return_type_id = 3 THEN
2127
2128 g_pick_group_rule := 'Y';
2129
2130 end if;
2131
2132
2133 end loop;
2134
2135 create_wct
2136 ( p_move_order_header_id => p_move_order_header_id
2137 , x_return_status => l_api_return_status
2138 );
2139
2140
2141
2142 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
2143 IF g_debug = 1 THEN
2144 print_debug('Error status from create_wct: '
2145 || l_api_return_status, l_api_name);
2146 END IF;
2147 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
2148 RAISE fnd_api.g_exc_error;
2149 ELSE
2150 RAISE fnd_api.g_exc_unexpected_error;
2151 END IF;
2152 END IF;
2153
2154 IF g_debug = 1 THEN
2155 print_debug('Fetching cartonization rules..', l_api_name);
2156 END IF;
2157
2158 SELECT * BULK COLLECT
2159 INTO rules_table
2160 FROM wms_selection_criteria_txn
2161 WHERE rule_type_code = 12
2162 AND from_organization_id = p_org_id
2163 AND enabled_flag = 1
2164 ORDER BY sequence_number;
2165
2166 l_api_return_status := fnd_api.g_ret_sts_success;
2167 FOR ii IN rules_table.FIRST .. rules_table.LAST LOOP --{
2168 IF rules_table(ii).return_type_id = 1 THEN
2169 WMS_CARTNZN_PUB.cartonize_single_item
2170 ( x_return_status => l_api_return_status
2171 , x_msg_count => l_msg_count
2172 , x_msg_data => l_msg_data
2173 , p_out_bound => 'Y'
2174 , p_org_id => rules_table(ii).from_organization_id
2175 , p_move_order_header_id => p_move_order_header_id
2176 , p_subinventory_name => rules_table(ii).from_subinventory_name
2177 );
2178 ELSIF rules_table(ii).return_type_id = 2 THEN
2179 WMS_CARTNZN_PUB.cartonize_mixed_item
2180 ( x_return_status => l_api_return_status
2181 , x_msg_count => l_msg_count
2182 , x_msg_data => l_msg_data
2183 , p_out_bound => 'Y'
2184 , p_org_id => rules_table(ii).from_organization_id
2185 , p_move_order_header_id => p_move_order_header_id
2186 , p_transaction_header_id => NULL
2187 , p_subinventory_name => rules_table(ii).from_subinventory_name
2188 , p_pack_level => 0
2189 , p_stop_level => 0
2190 );
2191 WMS_CARTNZN_PUB.pack_level := 0;
2192 ELSIF rules_table(ii).return_type_id = 3 THEN
2193 WMS_CARTNZN_PUB.g_cartonize_pick_slip := 'Y';
2194 WMS_CARTNZN_PUB.cartonize_pick_slip
2195 ( p_org_id => rules_table(ii).from_organization_id
2196 , p_move_order_header_id => p_move_order_header_id
2197 , p_subinventory_name => rules_table(ii).from_subinventory_name
2198 , x_return_status => l_api_return_status
2199 );
2200 ELSIF rules_table(ii).return_type_id = 4 THEN
2201 WMS_CARTNZN_PUB.cartonize_customer_logic
2202 ( p_org_id => rules_table(ii).from_organization_id
2203 , p_move_order_header_id => p_move_order_header_id
2204 , p_subinventory_name => rules_table(ii).from_subinventory_name
2205 , x_return_status => l_api_return_status
2206 );
2207 END IF;
2208
2209 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
2210 IF g_debug = 1 THEN
2211 print_debug('Error status from WMS_CARTNZN_PUB APIs: '
2212 || l_api_return_status, l_api_name);
2213 END IF;
2214 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
2215 RAISE fnd_api.g_exc_error;
2216 ELSE
2217 RAISE fnd_api.g_exc_unexpected_error;
2218 END IF;
2219 END IF;
2220
2221 SELECT count(1) INTO l_count
2222 FROM wms_cartonization_temp
2223 WHERE cartonization_id IS NULL
2224 AND transaction_header_id >= 0;
2225
2226 IF l_count = 0 THEN
2227 EXIT;
2228 END IF;
2229
2230 END LOOP; --}
2231
2232 -- If there are any more rows left for cartonization for first level,
2233 -- cartonize through default logic
2234 IF l_count > 0 THEN
2235 l_api_return_status := fnd_api.g_ret_sts_success;
2236 WMS_CARTNZN_PUB.cartonize_default_logic
2237 ( p_org_id => p_org_id
2238 , p_move_order_header_id => p_move_order_header_id
2239 , p_out_bound => 'Y'
2240 , x_return_status => l_api_return_status
2241 , x_msg_count => l_msg_count
2242 , x_msg_data => l_msg_data
2243 );
2244 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
2245 IF g_debug = 1 THEN
2246 print_debug('Error status from cartonize_default_logic: '
2247 || l_api_return_status, l_api_name);
2248 END IF;
2249 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
2250 RAISE fnd_api.g_exc_error;
2251 ELSE
2252 RAISE fnd_api.g_exc_unexpected_error;
2253 END IF;
2254 END IF;
2255 END IF;
2256
2257 IF g_debug = 1 THEN
2258 print_debug( 'Done with FIRST LEVEL OF CARTONIZATION, inserting packaging history'
2259 , l_api_name);
2260 END IF;
2261
2262 WMS_CARTNZN_PUB.pack_level := 0;
2263
2264 l_api_return_status := fnd_api.g_ret_sts_success;
2265 WMS_CARTNZN_PUB.insert_ph
2266 ( p_move_order_header_id => p_move_order_header_id
2267 , p_current_header_id => p_move_order_header_id
2268 , x_return_status => l_api_return_status
2269 );
2270 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
2271 IF g_debug = 1 THEN
2272 print_debug('Error status from cartonize_default_logic: '
2273 || l_api_return_status, l_api_name);
2274 END IF;
2275 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
2276 RAISE fnd_api.g_exc_error;
2277 ELSE
2278 RAISE fnd_api.g_exc_unexpected_error;
2279 END IF;
2280 END IF;
2281
2282 IF g_debug = 1 THEN
2283 print_debug( 'Done with WMS_CARTNZN_PUB.insert_ph', l_api_name);
2284 print_debug( 'Calling CARTONIZE_MIXED_ITEM for doing MULTI-LEVEL CARTONIZATION'
2285 , l_api_name);
2286 END IF;
2287
2288 l_api_return_status := fnd_api.g_ret_sts_success;
2289 WMS_CARTNZN_PUB.cartonize_mixed_item
2290 ( x_return_status => l_api_return_status
2291 , x_msg_count => l_msg_count
2292 , x_msg_data => l_msg_data
2293 , p_out_bound => 'Y'
2294 , p_org_id => p_org_id
2295 , p_move_order_header_id => p_move_order_header_id
2296 , p_transaction_header_id => NULL
2297 , p_pack_level => 1
2298 );
2299 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
2300 IF g_debug = 1 THEN
2301 print_debug('Error status from cartonize_mixed_item: '
2302 || l_api_return_status, l_api_name);
2303 END IF;
2304 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
2305 RAISE fnd_api.g_exc_error;
2306 ELSE
2307 RAISE fnd_api.g_exc_unexpected_error;
2308 END IF;
2309 END IF;
2310
2311 IF g_debug = 1 THEN
2312 print_debug('Calling Generate_LPNs', l_api_name);
2313 END IF;
2314
2315 BEGIN
2316 WMS_CARTNZN_PUB.generate_lpns
2317 ( p_header_id => p_move_order_header_id
2318 , p_organization_id => p_org_id
2319 );
2320 EXCEPTION
2321 WHEN OTHERS THEN
2322 IF (g_debug = 1) THEN
2323 print_debug( 'Not erroring out since the mode is Pick release'
2324 , l_api_name);
2325 END IF;
2326 RAISE fnd_api.g_exc_unexpected_error;
2327 END;
2328
2329 DELETE wms_cartonization_temp
2330 WHERE transaction_header_id < 0;
2331
2332 l_api_return_status := fnd_api.g_ret_sts_success;
2333 merge_wct_to_mmtt(l_api_return_status);
2334 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
2335 IF g_debug = 1 THEN
2336 print_debug('Error status from merge_wct_to_mmtt: '
2337 || l_api_return_status, l_api_name);
2338 END IF;
2339 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
2340 RAISE fnd_api.g_exc_error;
2341 ELSE
2342 RAISE fnd_api.g_exc_unexpected_error;
2343 END IF;
2344 END IF;
2345
2346 COMMIT;
2347
2348 EXCEPTION
2349 WHEN OTHERS THEN
2350 x_return_status := fnd_api.g_ret_sts_unexp_error;
2351 ROLLBACK TO rb_carton_sp;
2352 IF g_debug = 1 THEN
2353 print_debug('Error in rulebased_cartonization: ' || SQLERRM, l_api_name);
2354 END IF;
2355
2356 END rulebased_cartonization;
2357
2358
2359
2360 -- Populates the cartonization_id, container_item_id columns
2361 -- on MMTT rows for a particular Move Order Header ID
2362 PROCEDURE cartonize
2363 ( p_org_id IN NUMBER
2364 , p_move_order_header_id IN NUMBER
2365 , p_caller IN VARCHAR2 DEFAULT 'N'
2366 , x_return_status OUT NOCOPY VARCHAR2
2367 ) IS
2368
2369 l_api_name CONSTANT VARCHAR2(30) := 'cartonize';
2370 v1 wms_cartnzn_pub.wct_row_type;
2371 cartonization_profile VARCHAR2(1) := 'Y';
2372 v_cart_value NUMBER;
2373 v_container_item_id NUMBER := NULL;
2374 v_qty NUMBER := -1;
2375 v_qty_per_cont NUMBER := -1;
2376 v_tr_qty_per_cont NUMBER := -1;
2377 v_sec_tr_qty_per_cont NUMBER := -1;
2378 v_primary_uom_code VARCHAR2(3);
2379 v_loop NUMBER := 0;
2380 v_lpn_id NUMBER := 0;
2381 ret_value NUMBER := 29;
2382 v_return_status VARCHAR2(1);
2383 v_left_prim_quant NUMBER;
2384 v_left_tr_quant NUMBER;
2385 v_sec_left_tr_quant NUMBER;
2386 v_sublvlctrl VARCHAR2(1) := '2';
2387 l_api_return_status VARCHAR2(1);
2388 l_msg_count NUMBER;
2389 l_msg_data VARCHAR2(2000);
2390 v_prev_move_order_line_id NUMBER := 0;
2391 space_avail_for NUMBER := 0;
2392 tr_space_avail_for NUMBER := 0;
2393 sec_tr_space_avail_for NUMBER := 0;
2394 v_serial_control_code NUMBER := NULL;
2395 l_current_header_id NUMBER := NULL;
2396 l_stop_level NUMBER := -1;
2397 v_prev_item_id NUMBER := NULL;
2398 l_prev_package_id NUMBER := NULL;
2399 l_temp_id NUMBER := NULL;
2400 l_item_id NUMBER := NULL;
2401 l_qty NUMBER := NULL;
2402 l_tr_qty NUMBER := NULL;
2403 l_sec_tr_qty NUMBER := NULL;
2404 l_clpn_id NUMBER := NULL;
2405 l_citem_id NUMBER := NULL;
2406 l_package_id NUMBER := NULL;
2407 l_upd_qty_flag VARCHAR2(1) := NULL;
2408 l_prev_header_id NUMBER := NULL;
2409 l_header_id NUMBER := NULL;
2410 l_no_pkgs_gen VARCHAR2(1);
2411 l_prev_condition VARCHAR2(1);
2412 l_revision_code VARCHAR2(1);
2413 l_lot_code VARCHAR2(1);
2414 l_serial_code VARCHAR2(1);
2415 l_is_revision_control BOOLEAN;
2416 l_is_lot_control BOOLEAN;
2417 l_is_serial_control BOOLEAN;
2418 packaging_mode NUMBER := wms_cartnzn_pub.pr_pkg_mode;
2419 l_qoh NUMBER;
2420 l_lpn_fully_allocated VARCHAR2(1) :='N';
2421 percent_fill_basis VARCHAR2(1) :='W';
2422 l_valid_container VARCHAR2(1) := 'Y';
2423 l_cartonize_sales_orders VARCHAR2(1) :=NULL;
2424 l_rulebased_setup_exists NUMBER := 0;
2425 error_code VARCHAR2(30);
2426 error_msg VARCHAR2(30);
2427
2428 CURSOR wct_rows IS
2429 SELECT wct.*
2430 FROM wms_cartonization_temp wct
2431 , mtl_txn_request_lines mtrl
2432 , mtl_secondary_inventories sub
2433 , mtl_parameters mtlp
2434 WHERE wct.move_order_line_id = mtrl.line_id
2435 AND mtrl.header_id = p_move_order_header_id
2436 AND wct.cartonization_id IS NULL
2437 AND mtlp.organization_id = wct.organization_id
2438 AND sub.organization_id = wct.organization_id
2439 AND wct.transfer_lpn_id IS NULL
2440 AND sub.secondary_inventory_name = wct.subinventory_code
2441 AND ((Nvl(mtlp.cartonization_flag,-1) = 1)
2442 OR (Nvl(mtlp.cartonization_flag,-1) = 3 AND sub.cartonization_flag = 1)
2443 OR (NVL(mtlp.cartonization_flag,-1) = 4)
2444 OR (NVL(mtlp.cartonization_flag,-1) = 5 AND sub.cartonization_flag = 1)
2445 )
2446 ORDER BY wct.move_order_line_id
2447 , wct.inventory_item_id
2448 , ABS(wct.transaction_temp_id);
2449
2450 CURSOR bpack_rows (p_hdr_id NUMBER) IS
2451 SELECT *
2452 FROM wms_cartonization_temp
2453 WHERE transaction_header_id = p_hdr_id
2454 AND cartonization_id IS NULL
2455 AND transfer_lpn_id IS NULL
2456 ORDER BY move_order_line_id
2457 , DECODE( content_lpn_id
2458 , NULL, inventory_item_id
2459 , DECODE( SIGN(p_hdr_id)
2460 , -1, inventory_item_id
2461 , wms_cartnzn_pub.get_lpn_itemid (content_lpn_id)
2462 )
2463 )
2464 , ABS(transaction_temp_id);
2465
2466 CURSOR packages(p_hdr_id NUMBER) IS
2467 SELECT transaction_temp_id
2468 , inventory_item_id
2469 , primary_quantity
2470 , transaction_quantity
2471 , secondary_transaction_quantity
2472 , content_lpn_id
2473 , container_item_id
2474 , cartonization_id
2475 FROM wms_cartonization_temp
2476 WHERE transaction_header_id = p_hdr_id
2477 ORDER BY cartonization_id;
2478
2479 CURSOR opackages(p_hdr_id NUMBER) IS
2480 SELECT wct.transaction_temp_id
2481 , wct.inventory_item_id
2482 , wct.primary_quantity
2483 , wct.transaction_quantity
2484 , wct.secondary_transaction_quantity
2485 , wct.content_lpn_id
2486 , wct.container_item_id
2487 , wct.cartonization_id
2488 FROM wms_cartonization_temp wct
2489 , mtl_txn_request_lines mtrl
2490 WHERE wct.move_order_line_id = mtrl.line_id
2491 AND mtrl.header_id = p_hdr_id
2492 ORDER BY wct.cartonization_id;
2493
2494 BEGIN
2495 x_return_status := fnd_api.g_ret_sts_success;
2496 error_code := 'CARTONIZE 10';
2497 SAVEPOINT cartonization_sp;
2498
2499 IF g_debug = 1 THEN
2500 print_debug( 'Entered with parameters: ' || g_newline ||
2501 'p_org_id => ' || p_org_id ||
2502 'p_move_order_header_id =>' || p_move_order_header_id
2503 , l_api_name);
2504 END IF;
2505
2506 WMS_CARTNZN_PUB.outbound := 'Y';
2507
2508 --making sure that we are starting with an empty table
2509 DELETE wms_cartonization_temp;
2510
2511 WMS_CARTNZN_PUB.pkg_attr_table.DELETE;
2512 WMS_CARTNZN_PUB.lpn_attr_table.DELETE;
2513 WMS_CARTNZN_PUB.lpns_generated_tb.DELETE;
2514
2515 --get the values related to cartonization from org parameters
2516 BEGIN
2517 SELECT NVL(cartonization_flag,-1)
2518 , NVL(cartonize_sales_orders,'Y')
2519 , NVL(allocate_serial_flag,'N')
2520 INTO v_cart_value
2521 , l_cartonize_sales_orders
2522 , WMS_CARTNZN_PUB.g_allocate_serial_flag
2523 FROM mtl_parameters
2524 WHERE organization_id = p_org_id;
2525 EXCEPTION
2526 WHEN OTHERS THEN
2527 v_cart_value := NULL;
2528 END;
2529
2530 g_caller := p_caller; --- Assigning global variable for p_caller
2531
2532 -- Changes done for Task Release as a part of Wave Planning project
2533 IF p_caller = 'TRP' THEN ---Calling Cartonization from Task release
2534 IF v_cart_value = 4 THEN -- Always Cartonize for Task Release process
2535 v_cart_value := 1;
2536 ELSIF v_cart_value = 5 THEN -- Cartonize for Task Release at subinventory level
2537 v_cart_value := 3;
2538 END IF;
2539 END IF;
2540
2541 --check whether the cartonization is at subinv level or at org level
2542 IF v_cart_value = 1 AND l_cartonize_sales_orders ='Y' THEN
2543 v_sublvlctrl := '1'; -- Cartonization is enabled for the whole organization
2544 cartonization_profile := 'Y';
2545 ELSIF v_cart_value = 3 AND l_cartonize_sales_orders ='Y' THEN
2546 v_sublvlctrl := '3'; --cartonization is controlled at the subinventory level
2547 cartonization_profile := 'Y';
2548 ELSE
2549 cartonization_profile := 'N';
2550 END IF;
2551
2552 IF cartonization_profile = 'N' THEN
2553 IF g_debug = 1 THEN
2554 print_debug ('Cartonization is disabled, so returning.', l_api_name);
2555 END IF;
2556 RETURN;
2557 END IF;
2558
2559 WMS_CARTNZN_PUB.g_sublvlctrl := v_sublvlctrl; -- used when calling cartonize_mixed_item
2560 -- from rule based cartonization
2561 IF g_debug = 1 THEN
2562 print_debug( 'WMS_CARTNZN_PUB.g_sublvlctrl: '||WMS_CARTNZN_PUB.g_sublvlctrl
2563 , l_api_name);
2564 END IF;
2565
2566 BEGIN
2567 SELECT percent_fill_basis_flag
2568 INTO percent_fill_basis
2569 FROM wsh_shipping_parameters
2570 WHERE organization_id = p_org_id AND
2571 ROWNUM < 2;
2572 EXCEPTION
2573 WHEN OTHERS THEN
2574 percent_fill_basis := 'W';
2575 END;
2576
2577 -- Rule Based Cartonization
2578 SELECT count(1)
2579 INTO l_rulebased_setup_exists
2580 FROM wms_selection_criteria_txn_v
2581 WHERE rule_type_code = 12
2582 AND enabled_flag = 1
2583 AND from_organization_id = p_org_id
2584 AND ROWNUM = 1;
2585
2586 IF l_rulebased_setup_exists > 0 THEN
2587 WMS_CARTNZN_PUB.table_name := 'wms_cartonization_temp';
2588 IF v_cart_value = 1 or v_cart_value = 3 THEN
2589 l_api_return_status := fnd_api.g_ret_sts_success;
2590 rulebased_cartonization
2591 ( x_return_status => l_api_return_status
2592 , p_org_id => p_org_id
2593 , p_move_order_header_id => p_move_order_header_id
2594 );
2595
2596 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
2597 IF g_debug = 1 THEN
2598 print_debug('Error status from rulebased_cartonization: '
2599 || l_api_return_status, l_api_name);
2600 END IF;
2601 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
2602 RAISE fnd_api.g_exc_error;
2603 ELSE
2604 RAISE fnd_api.g_exc_unexpected_error;
2605 END IF;
2606 END IF;
2607
2608 RETURN;
2609 END IF;
2610 ELSE
2611 IF g_debug = 1 THEN
2612 print_debug( 'Rulebased setup does not exist, going to default cartonization logic'
2613 , l_api_name);
2614 END IF;
2615 END IF;
2616 -- End of Rule Based Cartonization
2617
2618 IF g_debug = 1 THEN
2619 print_debug('Cartonization profile is ' || cartonization_profile ||
2620 ', outbound is ' || WMS_CARTNZN_PUB.outbound ||
2621 ', controlled at sub level is ' || v_sublvlctrl
2622 , l_api_name);
2623 print_debug(' Percent fill basis ' || percent_fill_basis, l_api_name);
2624 END IF;
2625
2626 WMS_CARTNZN_PUB.table_name := 'wms_cartonization_temp';
2627
2628 IF g_debug = 1 THEN
2629 print_debug('Inserting mmtt rows of this header into wms_cartonization_temp '
2630 || p_move_order_header_id , l_api_name);
2631 END IF;
2632
2633 error_code := 'CARTONIZE 50';
2634
2635 l_api_return_status := fnd_api.g_ret_sts_success;
2636 create_wct
2637 ( p_move_order_header_id => p_move_order_header_id
2638 , x_return_status => l_api_return_status
2639 );
2640
2641 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
2642 IF g_debug = 1 THEN
2643 print_debug('Error status from create_wct: '
2644 || l_api_return_status, l_api_name);
2645 END IF;
2646 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
2647 RAISE fnd_api.g_exc_error;
2648 ELSE
2649 RAISE fnd_api.g_exc_unexpected_error;
2650 END IF;
2651 END IF;
2652
2653 l_stop_level := -1;
2654 WMS_CARTNZN_PUB.pack_level := 0;
2655 l_current_header_id := p_move_order_header_id;
2656
2657 IF cartonization_profile = 'Y' THEN --{
2658 --- This is the Multi level Cartonization loop
2659 LOOP --{
2660 IF g_debug = 1 THEN
2661 print_debug( 'cur lev ' || WMS_CARTNZN_PUB.pack_level ||
2662 ', stop lev ' || l_stop_level
2663 , l_api_name);
2664 END IF;
2665
2666 EXIT WHEN ((WMS_CARTNZN_PUB.pack_level >= l_stop_level) AND (l_stop_level <> -1));
2667
2668 v_prev_item_id := -1;
2669 v_prev_move_order_line_id := -1;
2670
2671 IF g_debug = 1 THEN
2672 print_debug( 'Opening cusror hdr id: ' || l_current_header_id
2673 , l_api_name);
2674 END IF;
2675
2676 IF ((WMS_CARTNZN_PUB.outbound = 'Y') AND (WMS_CARTNZN_PUB.pack_level = 0)) THEN
2677 error_code := 'CARTONIZE 70';
2678 IF g_debug = 1 THEN
2679 print_debug('Opening wct_rows', l_api_name);
2680 END IF;
2681 OPEN wct_rows;
2682 IF g_debug = 1 THEN
2683 print_debug('Opened wct_rows', l_api_name);
2684 END IF;
2685 ELSE
2686 error_code := 'CARTONIZE 90';
2687 IF g_debug = 1 THEN
2688 print_debug('Opening bpack_rows', l_api_name);
2689 END IF;
2690 OPEN bpack_rows(l_current_header_id);
2691 IF g_debug = 1 THEN
2692 print_debug('Opened bpack rows', l_api_name);
2693 END IF;
2694 END IF;
2695
2696 error_code := 'CARTONIZE 100';
2697
2698 LOOP --{
2699 IF g_debug = 1 THEN
2700 print_debug(' Fetching rows::pack_level: ' || WMS_CARTNZN_PUB.pack_level ||
2701 ', outbound: ' || WMS_CARTNZN_PUB.outbound
2702 , l_api_name);
2703 END IF;
2704
2705 IF ((WMS_CARTNZN_PUB.outbound = 'Y') AND (WMS_CARTNZN_PUB.pack_level = 0)) THEN --{
2706 error_code := 'CARTONIZE 110';
2707 FETCH wct_rows INTO v1;
2708 EXIT WHEN wct_rows%notfound;
2709
2710 SELECT revision_qty_control_code
2711 , lot_control_code
2712 , serial_number_control_code
2713 INTO l_revision_code
2714 , l_lot_code
2715 , l_serial_code
2716 FROM mtl_system_items
2717 WHERE organization_id = v1.organization_id
2718 AND inventory_item_id = v1.inventory_item_id;
2719
2720 IF l_revision_code > 1 THEN
2721 l_is_revision_control := TRUE;
2722 ELSE
2723 l_is_revision_control := FALSE;
2724 END IF;
2725
2726 IF l_lot_code > 1 THEN
2727 l_is_lot_control := TRUE;
2728 ELSE
2729 l_is_lot_control := FALSE;
2730 END IF;
2731
2732 IF (l_serial_code > 1 AND l_serial_code <> 6) THEN
2733 l_is_serial_control := TRUE;
2734 ELSE
2735 l_is_serial_control := FALSE;
2736 END IF;
2737
2738 IF (v1.allocated_lpn_id IS NOT NULL ) THEN --{
2739 error_code := 'CARTONIZE 120';
2740
2741 SELECT NVL(SUM(primary_transaction_quantity),0)
2742 INTO l_qoh FROM mtl_onhand_quantities_detail
2743 WHERE organization_id = v1.organization_id
2744 AND subinventory_code = v1.subinventory_code
2745 AND locator_id = v1.locator_id
2746 AND lpn_id = v1.allocated_lpn_id;
2747
2748 IF g_debug = 1 THEN
2749 print_debug('lpn_id: ' || v1.allocated_lpn_id, l_api_name);
2750 print_debug('l_qoh: ' || l_qoh, l_api_name);
2751 print_debug('PrimaryQty: '|| v1.primary_quantity, l_api_name);
2752 END IF;
2753
2754 IF l_qoh = v1.primary_quantity THEN
2755 l_lpn_fully_allocated := 'Y';
2756 SELECT v1.transaction_temp_id, 'Y'
2757 INTO WMS_CARTNZN_PUB.t_lpn_alloc_flag_table(v1.transaction_temp_id)
2758 FROM DUAL;
2759 ELSE
2760 l_lpn_fully_allocated := 'N';
2761 SELECT v1.transaction_temp_id, 'N'
2762 INTO WMS_CARTNZN_PUB.t_lpn_alloc_flag_table(v1.transaction_temp_id)
2763 FROM DUAL;
2764 END IF;
2765 --}
2766 ELSE
2767 l_lpn_fully_allocated := 'Y';
2768 SELECT v1.transaction_temp_id, 'Y'
2769 INTO WMS_CARTNZN_PUB.t_lpn_alloc_flag_table(v1.transaction_temp_id)
2770 FROM DUAL;
2771 END IF ;
2772 --}
2773 ELSE
2774 error_code := 'CARTONIZE 130';
2775 FETCH bpack_rows INTO v1;
2776
2777 EXIT WHEN bpack_rows%notfound;
2778
2779 l_lpn_fully_allocated := 'N';
2780 END IF;
2781
2782 IF g_debug = 1 THEN
2783 print_debug('Fetch succeeded', l_api_name);
2784 print_debug('lpn_fully_allocated: ' || l_lpn_fully_allocated, l_api_name);
2785 print_debug('lpn_id after if: ' || v1.allocated_lpn_id, l_api_name);
2786 END IF;
2787
2788 IF v1.allocated_lpn_id IS NOT NULL AND
2789 l_lpn_fully_allocated = 'Y' THEN
2790 NULL;
2791 ELSE --{
2792 --populate lpn_alloc_flag with null for loose item
2793 SELECT v1.transaction_temp_id, NULL
2794 INTO WMS_CARTNZN_PUB.t_lpn_alloc_flag_table(v1.transaction_temp_id)
2795 FROM DUAL;
2796
2797 -- If the content_lpn_id is populated on the mmtt record
2798 -- could be two cases. Either we are trying to pack an LPN
2799 -- or a package. We will have packages poulated in this
2800 -- column only by multi level cartonization and when it
2801 -- does that, the row is inserted with negative header id
2802 -- Basing on this we either get the item associated with
2803 -- the lpn, or item associated with the package
2804
2805 error_code := 'CARTONIZE 140';
2806
2807 IF v1.content_lpn_id IS NOT NULL THEN
2808 IF g_debug = 1 THEN
2809 print_debug('Content_lpn_id IS NOT NULL', l_api_name);
2810 END IF;
2811
2812 IF v1.transaction_header_id < 0 THEN
2813 error_code := 'CARTONIZE 150';
2814 ELSE
2815 error_code := 'CARTONIZE 160';
2816 v1.inventory_item_id := WMS_CARTNZN_PUB.get_lpn_itemid(v1.content_lpn_id);
2817 END IF;
2818
2819 -- When we are packaing an lpn or a package the qty is
2820 -- always 1
2821 v1.primary_quantity := 1;
2822 v1.transaction_quantity := 1;
2823 END IF;
2824
2825 error_code := 'CARTONIZE 170';
2826 SELECT primary_uom_code
2827 INTO v_primary_uom_code
2828 FROM mtl_system_items
2829 WHERE inventory_item_id = v1.inventory_item_id
2830 AND organization_id = v1.ORGANIZATION_ID;
2831
2832 IF v1.content_lpn_id IS NOT NULL THEN
2833 -- We want to set the transaction uom same as primary uom
2834 v1.transaction_uom := v_primary_uom_code;
2835 END IF;
2836
2837 IF g_debug = 1 THEN
2838 print_debug('inventory_item_id: ' || v1.inventory_item_id, l_api_name);
2839 print_debug('primary_quantity: ' || v1.primary_quantity, l_api_name);
2840 print_debug('primary_uom_code: ' ||v_primary_uom_code, l_api_name);
2841 print_debug('transaction_quantity: ' ||v1.transaction_quantity, l_api_name);
2842 print_debug('transaction_uom: ' ||v1.transaction_uom, l_api_name);
2843 print_debug('secondary_transaction_quantity: '||v1.secondary_transaction_quantity, l_api_name);
2844 print_debug('secondary_uom_code: ' ||v1.secondary_uom_code, l_api_name);
2845 END IF;
2846
2847 IF (WMS_CARTNZN_PUB.outbound = 'Y') AND (WMS_CARTNZN_PUB.pack_level = 0) AND
2848 (v_prev_move_order_line_id <> v1.move_order_line_id) THEN
2849 l_prev_condition := 'Y';
2850 ELSIF (WMS_CARTNZN_PUB.outbound = 'Y') AND (WMS_CARTNZN_PUB.pack_level <> 0) AND
2851 ((v_prev_move_order_line_id <> v1.move_order_line_id) OR
2852 (v1.inventory_item_id <> v_prev_item_id)) THEN
2853 l_prev_condition := 'Y';
2854 ELSIF (WMS_CARTNZN_PUB.outbound = 'N') AND
2855 (v1.inventory_item_id <> v_prev_item_id) THEN
2856 l_prev_condition := 'Y';
2857 ELSE
2858 l_prev_condition := 'N';
2859 END IF;
2860
2861 -- The below condition is used when to make a
2862 -- call to the an api that returns conatiner item relation
2863 -- ship if present
2864 -- In outbound mode
2865 -- you have to call this when previous move order line id
2866 -- is different from the current one
2867 -- In the inbound mode
2868 -- We need to call if the previous item is different form
2869 -- the current item
2870
2871 IF l_prev_condition = 'Y' THEN --{
2872 IF g_debug = 1 THEN
2873 print_debug('Call wms_container_pub.container_required_qty api for item id '
2874 || v1.inventory_item_id, l_api_name);
2875 END IF;
2876
2877 v_prev_item_id := v1.inventory_item_id;
2878 v_prev_move_order_line_id := v1.move_order_line_id;
2879 v_container_item_id := NULL;
2880 v_qty_per_cont := -1;
2881 v_qty := -1;
2882 space_avail_for := 0;
2883 l_valid_container := 'Y';
2884
2885 IF (WMS_CARTNZN_PUB.outbound = 'Y') AND (WMS_CARTNZN_PUB.pack_level = 0) --{
2886 AND (packaging_mode = wms_cartnzn_pub.pr_pkg_mode) THEN
2887 error_code := 'CARTONIZE 180';
2888 wsh_interface.Get_Max_Load_Qty
2889 ( p_move_order_line_id => v1.move_order_line_id
2890 , x_max_load_quantity => v_qty_per_cont
2891 , x_container_item_id => v_container_item_id
2892 , x_return_status => v_return_status
2893 );
2894
2895 l_valid_container := 'Y';
2896
2897 IF((v_return_status = fnd_api.g_ret_sts_success) AND
2898 (v_qty_per_cont > 0) AND
2899 (v_container_item_id IS NOT NULL) AND
2900 (v_container_item_id > 0) ) THEN
2901
2902 v_qty := ceil(v1.primary_quantity/v_qty_per_cont);
2903 -- This quantity needs to be recalculated. This is
2904 -- poulated to pass the check marked by '#chk1'
2905 END IF;
2906
2907 IF (g_debug = 1) THEN
2908 print_debug('wsh_interface.Get_Max_Load_Qty return status: '
2909 || v_return_status, l_api_name);
2910 print_debug('Container: ' || v_container_item_id, l_api_name);
2911 print_debug('Number of dum containers: ' || v_qty, l_api_name);
2912 END IF;
2913
2914 v_prev_move_order_line_id := v1.move_order_line_id;
2915 --}
2916 ELSE --{
2917 error_code := 'CARTONIZE 190';
2918 wms_container_pub.Container_Required_Qty
2919 ( p_api_version => 1.0
2920 , x_return_status => v_return_status
2921 , x_msg_count => l_msg_count
2922 , x_msg_data => l_msg_data
2923 , p_source_item_id => v1.inventory_item_id
2924 , p_source_qty => v1.primary_quantity
2925 , p_source_qty_uom => v_primary_uom_code
2926 , p_organization_id => v1.organization_id
2927 , p_dest_cont_item_id => v_container_item_id
2928 , p_qty_required => v_qty
2929 );
2930
2931 IF g_debug = 1 THEN
2932 print_debug('Container_required_quantity return status: '
2933 || v_return_status, l_api_name);
2934 print_debug('Container: ' || v_container_item_id, l_api_name);
2935 print_debug('Number of conatiners: ' || v_qty, l_api_name);
2936 END IF;
2937
2938 v_prev_item_id := v1.inventory_item_id;
2939
2940 IF ((v_return_status = fnd_api.g_ret_sts_success ) AND
2941 (v_qty IS NOT NULL) AND
2942 (v_qty > 0) AND
2943 (v_container_item_id IS NOT NULL) AND
2944 (v_container_item_id > 0) ) THEN
2945
2946 error_code := 'CARTONIZE 200';
2947
2948 SELECT max_load_quantity
2949 INTO v_qty_per_cont
2950 FROM wsh_container_items
2951 WHERE load_item_id = v1.inventory_item_id
2952 AND master_organization_id = v1.organization_id
2953 AND container_item_id = v_container_item_id;
2954 END IF;
2955 --}
2956 END IF;
2957
2958 IF g_debug = 1 THEN
2959 print_debug('Qty per container is: ' || v_qty_per_cont, l_api_name);
2960 END IF;
2961
2962 --#chk1
2963
2964 IF ((v_return_status <> fnd_api.g_ret_sts_success ) OR
2965 (v_qty_per_cont IS NULL) OR
2966 (v_qty IS NULL) OR
2967 (v_container_item_id IS NULL) OR
2968 (v_qty <= 0) OR
2969 (v_container_item_id <= 0) OR
2970 (v_qty_per_cont <= 0) OR
2971 l_valid_container = 'N'
2972 ) THEN
2973 IF g_debug = 1 THEN
2974 print_debug('Improper values returned by container_required_qty', l_api_name);
2975 END IF;
2976 ELSE --{
2977 SELECT msi.serial_number_control_code
2978 INTO v_serial_control_code
2979 FROM mtl_system_items msi
2980 WHERE msi.inventory_item_id = v1.inventory_item_id
2981 AND msi.organization_id = v1.organization_id;
2982
2983 IF ((v_serial_control_code NOT IN (1,6))
2984 AND (Ceil(v_qty_per_cont) > v_qty_per_cont )) THEN
2985 IF g_debug = 1 THEN
2986 print_debug('cannot split serial controlled items to fractions', l_api_name);
2987 print_debug('Please check the container item relationships', l_api_name);
2988 END IF;
2989
2990 v_qty_per_cont := 0;
2991 v_serial_control_code := NULL;
2992 END IF;
2993
2994 v_serial_control_code := NULL;
2995
2996 v_tr_qty_per_cont := inv_convert.inv_um_convert
2997 ( v1.inventory_item_id
2998 , 5
2999 , v_qty_per_cont
3000 , v_primary_uom_code
3001 , v1.transaction_uom
3002 , NULL
3003 , NULL
3004 );
3005
3006 IF v1.secondary_uom_code IS NOT NULL THEN
3007 v_sec_tr_qty_per_cont := inv_convert.inv_um_convert
3008 ( v1.inventory_item_id
3009 , 5
3010 , v_qty_per_cont
3011 , v_primary_uom_code
3012 , v1.secondary_uom_code
3013 , NULL
3014 , NULL
3015 );
3016 END IF;
3017 IF g_debug = 1 THEN
3018 print_debug('Transaction qty per conatiner is: '
3019 || v_tr_qty_per_cont, l_api_name);
3020 END IF;
3021 IF g_debug = 1 THEN
3022 print_debug('Secondary Transaction qty per conatiner is: '
3023 ||v_sec_tr_qty_per_cont, l_api_name);
3024 END IF;
3025 --}
3026 END IF;
3027 --}
3028 ELSE --{
3029 IF (space_avail_for > 0) THEN --{
3030 IF g_debug = 1 THEN
3031 print_debug('Space available for: ' || space_avail_for, l_api_name);
3032 END IF;
3033
3034 IF (v1.primary_quantity <= space_avail_for) THEN --{
3035 IF g_debug = 1 THEN
3036 print_debug( 'Prim qty: ' || v1.primary_quantity
3037 || ' <= ' || space_avail_for
3038 , l_api_name);
3039 END IF;
3040
3041 space_avail_for := space_avail_for - v1.primary_quantity;
3042
3043 IF v1.content_lpn_id IS NULL THEN
3044 l_upd_qty_flag := 'Y';
3045 ELSE
3046 l_upd_qty_flag := 'N';
3047 END IF;
3048
3049 WMS_CARTNZN_PUB.update_mmtt
3050 ( p_transaction_temp_id => v1.transaction_temp_id
3051 , p_primary_quantity => v1.primary_quantity
3052 , p_transaction_quantity => v1.transaction_quantity
3053 , p_secondary_quantity => v1.secondary_transaction_quantity
3054 , p_lpn_id => v_lpn_id
3055 , p_container_item_id => v_container_item_id
3056 , p_parent_line_id => NULL
3057 , p_upd_qty_flag => l_upd_qty_flag
3058 , x_return_status => l_api_return_status
3059 , x_msg_count => l_msg_count
3060 , x_msg_data => l_msg_data
3061 );
3062
3063 v1.primary_quantity := 0;
3064 --}
3065 ELSE --{
3066 IF g_debug = 1 THEN
3067 print_debug( 'Prim qty: ' || v1.primary_quantity
3068 || ' > ' || space_avail_for
3069 , l_api_name);
3070 END IF;
3071
3072 tr_space_avail_for := inv_convert.inv_um_convert
3073 ( v1.inventory_item_id
3074 , 5
3075 , space_avail_for
3076 , v_primary_uom_code
3077 , v1.transaction_uom
3078 , NULL
3079 , NULL
3080 );
3081
3082 sec_tr_space_avail_for := NULL;
3083 IF v1.secondary_uom_code IS NOT NULL THEN
3084 sec_tr_space_avail_for := inv_convert.inv_um_convert
3085 ( v1.inventory_item_id
3086 , 5
3087 , space_avail_for
3088 , v_primary_uom_code
3089 , v1.secondary_uom_code
3090 , NULL
3091 , NULL
3092 );
3093 END IF;
3094 IF g_debug = 1 THEN
3095 print_debug( 'Tr space avail for: ' || tr_space_avail_for
3096 , l_api_name);
3097 END IF;
3098
3099 WMS_CARTNZN_PUB.insert_mmtt
3100 ( p_transaction_temp_id => v1.transaction_temp_id
3101 , p_primary_quantity => space_avail_for
3102 , p_transaction_quantity => tr_space_avail_for
3103 , p_secondary_quantity => sec_tr_space_avail_for
3104 , p_lpn_id => v_lpn_id
3105 , p_container_item_id => v_container_item_id
3106 , x_return_status => l_api_return_status
3107 , x_msg_count => l_msg_count
3108 , x_msg_data => l_msg_data
3109 );
3110
3111 v1.primary_quantity := v1.primary_quantity - space_avail_for;
3112 v1.transaction_quantity := inv_convert.inv_um_convert
3113 ( v1.inventory_item_id
3114 , 5
3115 , v1.primary_quantity
3116 , v_primary_uom_code
3117 , v1.transaction_uom
3118 , NULL
3119 , NULL
3120 );
3121
3122 IF v1.secondary_uom_code IS NOT NULL THEN
3123 v1.secondary_transaction_quantity
3124 := inv_convert.inv_um_convert
3125 ( v1.inventory_item_id
3126 , 5
3127 , v1.primary_quantity
3128 , v_primary_uom_code
3129 , v1.secondary_uom_code
3130 , NULL
3131 , NULL
3132 );
3133 END IF;
3134
3135 space_avail_for := 0;
3136
3137 IF g_debug = 1 THEN
3138 print_debug('Prim qty: ' || v1.primary_quantity, l_api_name);
3139 print_debug('Tr qty: ' ||v1.transaction_quantity, l_api_name);
3140 print_debug('Sec Tr qty: ' || v1.secondary_transaction_quantity, l_api_name);
3141 print_debug('Space Avail for: ' || space_avail_for, l_api_name);
3142 END IF;
3143 --}
3144 END IF;
3145 --}
3146 END IF;
3147 --}
3148 END IF;
3149
3150 /* Condition #3 */
3151 IF ( v_return_status <> FND_API.g_ret_sts_success OR
3152 v_qty_per_cont IS NULL OR
3153 v_qty_per_cont <= 0 OR
3154 v_container_item_id IS NULL OR
3155 v_tr_qty_per_cont IS NULL OR
3156 v_tr_qty_per_cont <= 0 OR
3157 v1.primary_quantity <= 0 ) THEN
3158
3159 IF g_debug = 1 THEN
3160 print_debug('Container_Required_Qty - inc values', l_api_name);
3161 END IF;
3162 /* Condition #3a */
3163 NULL;
3164 ELSE --{
3165 /* Condition #3b */
3166 IF v1.content_lpn_id IS NULL THEN
3167 l_upd_qty_flag := 'Y';
3168 ELSE
3169 l_upd_qty_flag := 'N';
3170 END IF;
3171
3172 v_qty := CEIL(v1.primary_quantity/v_qty_per_cont);
3173
3174 IF (MOD(v1.primary_quantity,v_qty_per_cont) = 0) THEN
3175 space_avail_for := 0;
3176 ELSE
3177 space_avail_for := v_qty_per_cont - MOD(v1.primary_quantity,v_qty_per_cont);
3178 END IF;
3179
3180 IF g_debug = 1 THEN
3181 print_debug('space avail for: ' || space_avail_for, l_api_name);
3182 END IF;
3183
3184 /* Condition #4 */
3185 IF ((v1.primary_quantity <= v_qty_per_cont) OR ( v_qty = 1)) THEN --{
3186 IF g_debug = 1 THEN
3187 print_debug('primary_quantity <= qty per conatiner or ' ||
3188 'NUMBER OF cont = 1', l_api_name);
3189 END IF;
3190
3191 v_lpn_id := WMS_CARTNZN_PUB.get_next_package_id;
3192
3193 IF g_debug = 1 THEN
3194 print_debug('Generated label Id '||v_lpn_id, l_api_name);
3195 END IF;
3196
3197 WMS_CARTNZN_PUB.update_mmtt
3198 ( p_transaction_temp_id => v1.transaction_temp_id
3199 , p_primary_quantity => v1.primary_quantity
3200 , p_transaction_quantity => v1.transaction_quantity
3201 , p_secondary_quantity => v1.secondary_transaction_quantity
3202 , p_lpn_id => v_lpn_id
3203 , p_container_item_id => v_container_item_id
3204 , p_parent_line_id => NULL
3205 , p_upd_qty_flag => l_upd_qty_flag
3206 , x_return_status => l_api_return_status
3207 , x_msg_count => l_msg_count
3208 , x_msg_data => l_msg_data
3209 );
3210 --}
3211 ELSE --{
3212 /* Condition #4b */
3213 v_loop := v_qty;
3214
3215 IF g_debug = 1 THEN
3216 print_debug('NUMBER OF cont: ' || v_qty, l_api_name);
3217 END IF;
3218
3219 v_lpn_id := WMS_CARTNZN_PUB.get_next_package_id;
3220 IF g_debug = 1 THEN
3221 print_debug('Generated label ID: ' || v_lpn_id, l_api_name);
3222 print_debug('Calling update_mmtt', l_api_name);
3223 END IF;
3224
3225 WMS_CARTNZN_PUB.update_mmtt
3226 ( p_transaction_temp_id => v1.transaction_temp_id
3227 , p_primary_quantity => v_qty_per_cont
3228 , p_transaction_quantity => v_tr_qty_per_cont
3229 , p_secondary_quantity => v_sec_tr_qty_per_cont
3230 , p_lpn_id => v_lpn_id
3231 , p_container_item_id => v_container_item_id
3232 , p_parent_line_id => NULL
3233 , p_upd_qty_flag => l_upd_qty_flag
3234 , x_return_status => l_api_return_status
3235 , x_msg_count => l_msg_count
3236 , x_msg_data => l_msg_data
3237 );
3238
3239 v_loop := v_loop - 1;
3240
3241 LOOP --{
3242 EXIT WHEN v_loop < 2;
3243
3244 v_lpn_id := WMS_CARTNZN_PUB.get_next_package_id;
3245 IF g_debug = 1 THEN
3246 print_debug('Generated label ID: ' || v_lpn_id, l_api_name);
3247 print_debug('Calling insert mmtt', l_api_name);
3248 END IF;
3249 WMS_CARTNZN_PUB.insert_mmtt
3250 ( p_transaction_temp_id => v1.transaction_temp_id
3251 , p_primary_quantity => v_qty_per_cont
3252 , p_transaction_quantity => v_tr_qty_per_cont
3253 , p_secondary_quantity => v_sec_tr_qty_per_cont
3254 , p_lpn_id => v_lpn_id
3255 , p_container_item_id => v_container_item_id
3256 , x_return_status => l_api_return_status
3257 , x_msg_count => l_msg_count
3258 , x_msg_data => l_msg_data
3259 );
3260
3261 IF g_debug = 1 THEN
3262 print_debug('called insert mmtt', l_api_name);
3263 END IF;
3264 v_loop := v_loop - 1;
3265 END LOOP; --}
3266
3267 v_lpn_id := WMS_CARTNZN_PUB.get_next_package_id;
3268 IF g_debug = 1 THEN
3269 print_debug('Generated label ID: ' || v_lpn_id, l_api_name);
3270 END IF;
3271
3272 v_left_prim_quant := MOD(v1.primary_quantity,v_qty_per_cont);
3273 v_left_tr_quant := MOD(v1.transaction_quantity,v_tr_qty_per_cont);
3274
3275 IF v1.secondary_uom_code IS NOT NULL THEN
3276 v_sec_left_tr_quant :=
3277 MOD(v1.secondary_transaction_quantity,v_sec_tr_qty_per_cont);
3278 END IF;
3279
3280 IF (v_left_prim_quant = 0 OR v_left_tr_quant =0) THEN
3281 v_left_prim_quant := v_qty_per_cont;
3282 v_left_tr_quant := v_tr_qty_per_cont;
3283 IF v1.secondary_uom_code IS NOT NULL THEN
3284 v_sec_left_tr_quant := v_sec_tr_qty_per_cont;
3285 END IF;
3286 END IF;
3287
3288 IF g_debug = 1 THEN
3289 print_debug('calling insert mmtt', l_api_name);
3290 END IF;
3291 WMS_CARTNZN_PUB.insert_mmtt
3292 ( p_transaction_temp_id => v1.transaction_temp_id
3293 , p_primary_quantity => v_left_prim_quant
3294 , p_transaction_quantity => v_left_tr_quant
3295 , p_secondary_quantity => v_sec_left_tr_quant
3296 , p_lpn_id => v_lpn_id
3297 , p_container_item_id => v_container_item_id
3298 , x_return_status => l_api_return_status
3299 , x_msg_count => l_msg_count
3300 , x_msg_data => l_msg_data
3301 );
3302
3303 NULL;
3304 -- Shipping API
3305 END IF; --} /* Close Condition #4 */
3306 END IF; --} /* Close Condition #3 */
3307 END IF; --} /* for v1.allocated_lpn_id is not null */
3308 END LOOP; --}
3309
3310 IF g_debug = 1 THEN
3311 print_debug( 'End working with wms_container_pub.container_required_qty api'
3312 , l_api_name);
3313 END IF;
3314
3315 error_code := 'CARTONIZE 220';
3316
3317 IF g_debug = 1 THEN
3318 print_debug('Calling item-category cartonization', l_api_name);
3319 END IF;
3320
3321 IF ((WMS_CARTNZN_PUB.outbound = 'Y') AND (WMS_CARTNZN_PUB.pack_level = 0)) THEN --{
3322 print_debug('p_move_order_header_id: ' || p_move_order_header_id ||
3323 ', outbound: ' || WMS_CARTNZN_PUB.outbound ||
3324 ', v_sublvlctrl: ' || v_sublvlctrl ||
3325 ', percent_fill_basis: ' || percent_fill_basis
3326 , l_api_name);
3327
3328 ret_value := WMS_CARTNZN_PUB.do_cartonization
3329 ( p_move_order_header_id
3330 , 0
3331 , WMS_CARTNZN_PUB.outbound
3332 , v_sublvlctrl
3333 , percent_fill_basis
3334 );
3335 --}
3336 ELSE --{
3337 IF g_debug = 1 THEN
3338 print_debug('In else for cartonization', l_api_name);
3339 print_debug('Passing header id: ' || l_current_header_id, l_api_name);
3340 print_debug('Passing outbound: ' || WMS_CARTNZN_PUB.outbound, l_api_name);
3341 print_debug('Passing Sub level Control: ' || v_sublvlctrl, l_api_name);
3342 END IF;
3343
3344 ret_value := WMS_CARTNZN_PUB.do_cartonization
3345 ( 0
3346 , l_current_header_id
3347 , WMS_CARTNZN_PUB.outbound
3348 , v_sublvlctrl
3349 , percent_fill_basis
3350 );
3351 --}
3352 END IF;
3353
3354 IF g_debug = 1 THEN
3355 print_debug('Cartonization returned: ' || ret_value, l_api_name);
3356 print_debug('Calling split_lot_serials', l_api_name);
3357 END IF;
3358
3359 WMS_CARTNZN_PUB.split_lot_serials (p_org_id);
3360
3361 IF g_debug = 1 THEN
3362 print_debug('Populating Packaging History Table', l_api_name);
3363 END IF;
3364
3365 l_prev_package_id := -1;
3366 l_prev_header_id := l_current_header_id;
3367
3368 IF g_debug = 1 THEN
3369 print_debug('Prev header ID: ' || l_prev_header_id, l_api_name);
3370 END IF;
3371
3372 l_current_header_id := WMS_CARTNZN_PUB.get_next_header_id;
3373
3374 IF g_debug = 1 THEN
3375 print_debug('Current_header_id: ' || l_current_header_id, l_api_name);
3376 END IF;
3377
3378 error_code := 'CARTONIZE 225';
3379 WMS_CARTNZN_PUB.t_lpn_alloc_flag_table.DELETE;
3380 error_code := 'CARTONIZE 226';
3381 IF ((WMS_CARTNZN_PUB.outbound = 'Y') AND (WMS_CARTNZN_PUB.pack_level = 0) ) THEN
3382 error_code := 'CARTONIZE 227';
3383 OPEN opackages(l_prev_header_id);
3384 ELSE
3385 error_code := 'CARTONIZE 228';
3386 OPEN packages(l_prev_header_id);
3387 END IF;
3388
3389 l_no_pkgs_gen := 'Y';
3390
3391 error_code := 'CARTONIZE 230';
3392
3393 LOOP --{
3394 IF g_debug = 1 THEN
3395 print_debug('Fetching Packages cursor', l_api_name);
3396 END IF;
3397
3398 error_code := 'CARTONIZE 240';
3399
3400 IF ((WMS_CARTNZN_PUB.outbound = 'Y') AND (WMS_CARTNZN_PUB.pack_level = 0) ) THEN
3401 FETCH opackages
3402 INTO l_temp_id
3403 , l_item_id
3404 , l_qty
3405 , l_tr_qty
3406 , l_sec_tr_qty
3407 , l_clpn_id
3408 , l_citem_id
3409 , l_package_id;
3410 EXIT WHEN opackages%notfound;
3411 ELSE
3412 FETCH packages
3413 INTO l_temp_id
3414 , l_item_id
3415 , l_qty
3416 , l_tr_qty
3417 , l_sec_tr_qty
3418 , l_clpn_id
3419 , l_citem_id
3420 , l_package_id;
3421 EXIT WHEN packages%notfound;
3422 END IF;
3423
3424 IF g_debug = 1 THEN
3425 print_debug('temp_id '||l_temp_id , l_api_name);
3426 print_debug('item_id '||l_item_id , l_api_name);
3427 print_debug('qty '||l_qty , l_api_name);
3428 print_debug('tr_qty '||l_tr_qty, l_api_name);
3429 print_debug('sec_tr_qty '||l_sec_tr_qty, l_api_name);
3430 print_debug('clpn_id '||l_clpn_id, l_api_name);
3431 print_debug('citem_id '||l_citem_id, l_api_name);
3432 print_debug('package_id '||l_package_id, l_api_name);
3433 END IF;
3434
3435 IF l_package_id IS NOT NULL THEN --{
3436 l_no_pkgs_gen := 'N';
3437
3438 IF l_package_id <> l_prev_package_id THEN --{
3439 l_prev_package_id := l_package_id;
3440
3441 IF g_debug = 1 THEN
3442 print_debug( 'Inserting a new row for package ' || l_package_id
3443 , l_api_name);
3444 END IF;
3445
3446 WMS_CARTNZN_PUB.insert_mmtt
3447 ( p_transaction_temp_id => l_temp_id
3448 , p_primary_quantity => l_qty
3449 , p_transaction_quantity => l_tr_qty
3450 , p_secondary_quantity => l_sec_tr_qty
3451 , p_new_txn_hdr_id => l_current_header_id
3452 , p_new_txn_tmp_id => WMS_CARTNZN_PUB.get_next_temp_id
3453 , p_clpn_id => l_package_id
3454 , p_item_id => l_citem_id
3455 , x_return_status => l_api_return_status
3456 , x_msg_count => l_msg_count
3457 , x_msg_data => l_msg_data
3458 );
3459 --}
3460 END IF;
3461
3462 IF g_debug = 1 THEN
3463 print_debug('Calling InsertPH for temp_id ' || l_temp_id, l_api_name);
3464 END IF;
3465
3466 IF WMS_CARTNZN_PUB.outbound = 'Y' THEN
3467 WMS_CARTNZN_PUB.insert_ph (p_move_order_header_id, l_temp_id);
3468 -- Insert_PH is overloaded in WMSCRTNS.pls. careful
3469 END IF;
3470 --}
3471 END IF;
3472 END LOOP; --}
3473
3474 IF ((WMS_CARTNZN_PUB.outbound = 'Y') AND (WMS_CARTNZN_PUB.pack_level = 0) ) THEN
3475 IF opackages%ISOPEN THEN
3476 CLOSE opackages;
3477 END IF;
3478 ELSE
3479 IF packages%ISOPEN THEN
3480 CLOSE packages;
3481 END IF;
3482 END IF;
3483
3484 IF l_no_pkgs_gen = 'Y' THEN
3485 IF g_debug = 1 THEN
3486 print_debug('No labels generated in the previous level-EXITING', l_api_name);
3487 END IF;
3488
3489 IF ((WMS_CARTNZN_PUB.outbound = 'Y') AND (WMS_CARTNZN_PUB.pack_level = 0)) THEN
3490 IF wct_rows%ISOPEN then
3491 CLOSE wct_rows;
3492 END IF;
3493 ELSE
3494 IF bpack_rows%ISOPEN THEN
3495 CLOSE bpack_rows;
3496 END IF;
3497 END IF;
3498
3499 EXIT;
3500 END IF;
3501
3502 IF ((WMS_CARTNZN_PUB.outbound = 'Y') AND (WMS_CARTNZN_PUB.pack_level = 0)) THEN
3503 IF wct_rows%ISOPEN THEN
3504 CLOSE wct_rows;
3505 END IF;
3506 ELSE
3507 IF bpack_rows%iSOPEN THEN
3508 CLOSE bpack_rows;
3509 END IF;
3510 END IF;
3511
3512 WMS_CARTNZN_PUB.pack_level := WMS_CARTNZN_PUB.pack_level + 1;
3513 IF g_debug = 1 THEN
3514 print_debug('Incremented the current level', l_api_name);
3515 print_debug('going back to the multi-cart loop', l_api_name);
3516 END IF;
3517
3518 END LOOP; --}
3519 -- Ends the loop for Multi level Cartonization loop
3520
3521 l_header_id := p_move_order_header_id;
3522
3523 -- We have to update the end labels to LPNS and update the
3524 -- packaging history and mmtt correspondingly
3525
3526 IF g_debug = 1 THEN
3527 print_debug('Calling Generate_LPNs for header id ' || l_header_id, l_api_name);
3528 END IF;
3529
3530 BEGIN
3531 error_code := 'CARTONIZE 250';
3532
3533 WMS_CARTNZN_PUB.generate_lpns
3534 ( p_header_id => l_header_id
3535 , p_organization_id => p_org_id
3536 );
3537 EXCEPTION
3538 WHEN OTHERS THEN
3539 IF g_debug = 1 THEN
3540 print_debug('Other error (Pick release mode): ' || SQLERRM, l_api_name);
3541 END IF;
3542 RAISE fnd_api.g_exc_unexpected_error;
3543 END;
3544
3545 DELETE wms_cartonization_temp
3546 WHERE transaction_header_id < 0;
3547
3548 l_api_return_status := fnd_api.g_ret_sts_success;
3549 merge_wct_to_mmtt(l_api_return_status);
3550 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
3551 IF g_debug = 1 THEN
3552 print_debug('Error status from merge_wct_to_mmtt: '
3553 || l_api_return_status, l_api_name);
3554 END IF;
3555 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
3556 RAISE fnd_api.g_exc_error;
3557 ELSE
3558 RAISE fnd_api.g_exc_unexpected_error;
3559 END IF;
3560 END IF;
3561 END IF; --} /* Cartonization profile = 'Y' */
3562
3563 IF wct_rows%ISOPEN THEN
3564 CLOSE wct_rows;
3565 END IF;
3566
3567 COMMIT;
3568
3569 EXCEPTION
3570 WHEN fnd_api.g_exc_error THEN
3571 ROLLBACK TO cartonization_sp;
3572 x_return_status := fnd_api.g_ret_sts_error;
3573
3574 FND_MESSAGE.SET_NAME('WMS', 'WMS_CARTONIZATION_ERROR');
3575 FND_MESSAGE.SET_TOKEN('ERROR_CODE', ERROR_CODE);
3576 FND_MSG_PUB.ADD;
3577
3578 IF g_debug = 1 THEN
3579 print_debug('EXCEPTION occurred from ERROR_CODE: ' || error_code, l_api_name);
3580 END IF;
3581
3582 fnd_msg_pub.count_and_get
3583 ( p_count => l_msg_count
3584 , p_data => l_msg_data
3585 );
3586
3587 IF wct_rows%ISOPEN THEN
3588 CLOSE wct_rows;
3589 END IF;
3590 IF opackages%ISOPEN THEN
3591 CLOSE opackages;
3592 END IF;
3593 IF packages%ISOPEN THEN
3594 CLOSE packages;
3595 END IF;
3596 IF bpack_rows%ISOPEN THEN
3597 CLOSE bpack_rows;
3598 END IF;
3599
3600 WHEN OTHERS THEN
3601 ROLLBACK TO cartonization_sp;
3602 x_return_status := fnd_api.g_ret_sts_unexp_error;
3603
3604 ERROR_MSG := SQLERRM;
3605
3606 IF g_debug = 1 THEN
3607 print_debug('Exception occurred from ERROR_CODE: ' || error_code, l_api_name);
3608 END IF;
3609
3610 IF wct_rows%ISOPEN THEN
3611 CLOSE wct_rows;
3612 END IF;
3613 IF opackages%ISOPEN THEN
3614 CLOSE opackages;
3615 END IF;
3616 IF packages%ISOPEN THEN
3617 CLOSE packages;
3618 END IF;
3619 IF bpack_rows%ISOPEN THEN
3620 CLOSE bpack_rows;
3621 END IF;
3622
3623 END cartonize;
3624
3625
3626
3627 PROCEDURE consolidate_tasks
3628 ( p_mo_header_id IN NUMBER
3629 , x_return_status OUT NOCOPY VARCHAR2
3630 ) IS
3631 l_api_name VARCHAR2(30) := 'consolidate_tasks';
3632 l_msg_count NUMBER;
3633 l_msg_data VARCHAR2(2000);
3634
3635 l_delivery_flag VARCHAR2(1);
3636 l_bulk_pick_control NUMBER;
3637 l_move_order_type NUMBER;
3638 l_dummy VARCHAR2(1);
3639
3640 l_last_update_date tbl_date;
3641 l_last_updated_by tbl_num;
3642 l_creation_date tbl_date;
3643 l_created_by tbl_num;
3644 l_inventory_item_id tbl_num;
3645 l_revision tbl_varchar3;
3646 l_organization_id tbl_num;
3647 l_subinventory_code tbl_varchar10;
3648 l_locator_id tbl_num;
3649 l_transaction_quantity tbl_num;
3650 l_primary_quantity tbl_num;
3651 l_transaction_uom tbl_varchar3;
3652 l_transaction_type_id tbl_num;
3653 l_transaction_action_id tbl_num;
3654 l_transaction_source_type_id tbl_num;
3655 l_transaction_date tbl_date;
3656 l_acct_period_id tbl_num;
3657 l_to_org_id tbl_num;
3658 l_wms_task_type tbl_num;
3659 l_task_priority tbl_num;
3660 l_cost_group_id tbl_num;
3661 l_transaction_header_id tbl_num;
3662 l_container_item_id tbl_num;
3663 l_operation_plan_id tbl_num;
3664 l_wms_task_status tbl_num;
3665 l_carton_grouping_id tbl_num;
3666 l_primary_uom_code tbl_varchar3;
3667 l_lot_control_code tbl_num;
3668 l_serial_control_code tbl_num;
3669 l_serial_allocated_flag tbl_varchar1;
3670 l_transaction_batch_id tbl_num;
3671 l_child_task_id tbl_num;
3672 l_parent_task_id tbl_num;
3673
3674 tbl_transaction_temp_id tbl_num;
3675
3676 -- Cursor task_list is for the tasks within the delivery and
3677 -- and cursor task_list_cross_delivery is for tasks across deliveries
3678 CURSOR task_list (p_move_order_header_id NUMBER) IS
3679 SELECT SYSDATE last_update_date
3680 , g_user_id last_updated_by
3681 , SYSDATE creation_date
3682 , g_user_id created_by
3683 , mmtt.inventory_item_id
3684 , mmtt.revision
3685 , mmtt.organization_id
3686 , mmtt.subinventory_code
3687 , mmtt.locator_id
3688 , SUM(mmtt.transaction_quantity) transaction_quantity
3689 , SUM(mmtt.primary_quantity) primary_quantity
3690 , mmtt.transaction_uom
3691 , mmtt.transaction_type_id
3692 , mmtt.transaction_action_id
3693 , mmtt.transaction_source_type_id
3694 , MAX(mmtt.transaction_date) transaction_date
3695 , MAX(mmtt.acct_period_id) acct_period_id
3696 , mmtt.transfer_organization
3697 , mmtt.wms_task_type
3698 , MAX(mmtt.task_priority) task_priority
3699 , mmtt.cost_group_id
3700 , MAX(mmtt.transaction_header_id) transaction_header_id
3701 , mmtt.container_item_id
3702 , mmtt.operation_plan_id
3703 , mmtt.wms_task_status -- carry forward task status also for unreleased/pending statuses
3704 , NVL(wda.delivery_id, mol.carton_grouping_id) carton_grouping_id
3705 , mmtt.item_primary_uom_code
3706 , mmtt.item_lot_control_code
3707 , mmtt.item_serial_control_code
3708 , mmtt.serial_allocated_flag
3709 , mmtt.transaction_batch_id
3710 FROM mtl_material_transactions_temp mmtt, mtl_txn_request_lines mol
3711 , wsh_delivery_details_ob_grp_v wdd, wsh_delivery_assignments_v wda
3712 WHERE mmtt.move_order_line_id = mol.line_id
3713 AND mol.header_id = p_move_order_header_id
3714 AND mol.line_id = wdd.move_order_line_id
3715 AND wdd.delivery_detail_id = wda.delivery_detail_id
3716 AND mmtt.wms_task_type NOT IN(5, 6)
3717 AND mmtt.allocated_lpn_id IS NULL -- if lpn allocated, no need to do consolidation
3718 AND mmtt.cartonization_id IS NULL -- only bulk non_cartonized lines
3719 AND ( mmtt.serial_allocated_flag = 'N' -- do not bulk serial allocated lines
3720 OR mmtt.serial_allocated_flag IS NULL )
3721 AND NVL(mmtt.fulfillment_base,'P') = 'P'
3722 AND ( l_bulk_pick_control = WMS_GLOBALS.BULK_PICK_ENTIRE_WAVE
3723 -- If bulk picking is not disabled and not pick entire wave only the honor sub/item is left,
3724 -- so no need to check l_bulk_pick_control, only need to check the sub/item flag
3725 OR EXISTS( SELECT 1 -- sub is bulk picking enabled
3726 FROM mtl_secondary_inventories msi
3727 WHERE msi.secondary_inventory_name = mmtt.subinventory_code
3728 AND msi.organization_id = mmtt.organization_id
3729 AND msi.enable_bulk_pick= 'Y' )
3730 OR EXISTS( SELECT 1 -- item is bulk picking enabled
3731 FROM mtl_system_items msi
3732 WHERE msi.inventory_item_id = mmtt.inventory_item_id
3733 AND msi.organization_id = mmtt.organization_id
3734 AND msi.bulk_picked_flag = 'Y' )
3735 )
3736 GROUP BY mmtt.inventory_item_id
3737 , mmtt.revision
3738 , mmtt.organization_id
3739 , mmtt.subinventory_code
3740 , mmtt.locator_id
3741 , mmtt.transaction_uom
3742 , mmtt.transaction_type_id
3743 , mmtt.transaction_action_id
3744 , mmtt.transaction_source_type_id
3745 , mmtt.transfer_organization
3746 , mmtt.wms_task_type
3747 , mmtt.cost_group_id
3748 , mmtt.container_item_id
3749 , mmtt.operation_plan_id
3750 , NVL(wda.delivery_id, mol.carton_grouping_id) -- only consolidate tasks with the same carton_grouping_id
3751 -- (hense delivery) if the delivery is checked in the rule
3752 , mmtt.wms_task_status
3753 , mmtt.item_primary_uom_code
3754 , mmtt.item_lot_control_code
3755 , mmtt.item_serial_control_code
3756 , mmtt.serial_allocated_flag
3757 , mmtt.transaction_batch_id
3758 HAVING SUM(mmtt.transaction_quantity) <> MIN(mmtt.transaction_quantity); -- make sure one line will not get consolidated
3759
3760 CURSOR task_list_cross_delivery (p_move_order_header_id NUMBER) IS
3761 SELECT SYSDATE last_update_date
3762 , g_user_id last_updated_by
3763 , SYSDATE creation_date
3764 , g_user_id created_by
3765 , mmtt.inventory_item_id
3766 , mmtt.revision
3767 , mmtt.organization_id
3768 , mmtt.subinventory_code
3769 , mmtt.locator_id
3770 , SUM(mmtt.transaction_quantity) transaction_quantity
3771 , SUM(mmtt.primary_quantity) primary_quantity
3772 , mmtt.transaction_uom
3773 , mmtt.transaction_type_id
3774 , mmtt.transaction_action_id
3775 , mmtt.transaction_source_type_id
3776 , MAX(mmtt.transaction_date) transaction_date
3777 , MAX(mmtt.acct_period_id) acct_period_id
3778 , mmtt.transfer_organization
3779 , mmtt.wms_task_type
3780 , MAX(mmtt.task_priority) task_priority
3781 , mmtt.cost_group_id
3782 , MAX(mmtt.transaction_header_id) transaction_header_id
3783 , mmtt.container_item_id
3784 , mmtt.operation_plan_id
3785 , mmtt.wms_task_status -- carry forward task status also for unreleased/pending statuses
3786 , mmtt.item_primary_uom_code
3787 , mmtt.item_lot_control_code
3788 , mmtt.item_serial_control_code
3789 , mmtt.serial_allocated_flag
3790 , mmtt.transaction_batch_id
3791 FROM mtl_material_transactions_temp mmtt
3792 WHERE mmtt.wms_task_type NOT IN(5, 6)
3793 AND mmtt.allocated_lpn_id IS NULL -- if lpn allocated, no need to do consolidation
3794 AND mmtt.cartonization_id IS NULL -- only bulk non_cartonized lines
3795 AND mmtt.move_order_header_id = p_move_order_header_id
3796 AND ( mmtt.serial_allocated_flag = 'N' -- do not bulk serial allocated lines
3797 or mmtt.serial_allocated_flag IS NULL )
3798 AND NVL(mmtt.fulfillment_base,'P') = 'P'
3799 AND ( l_bulk_pick_control = WMS_GLOBALS.BULK_PICK_ENTIRE_WAVE
3800 -- if bulk picking is not disabled and not pick entire wave only the honor sub/item is left,
3801 -- so no need to check l_bulk_pick_control, only need to check the sub/item flag
3802 OR EXISTS( SELECT 1 -- sub is bulk picking enabled
3803 FROM mtl_secondary_inventories msi
3804 WHERE msi.secondary_inventory_name = mmtt.subinventory_code
3805 AND msi.organization_id = mmtt.organization_id
3806 AND msi.enable_bulk_pick= 'Y' )
3807 OR EXISTS( SELECT 1 -- item is bulk picking enabled
3808 FROM mtl_system_items msi
3809 WHERE msi.inventory_item_id = mmtt.inventory_item_id
3810 AND msi.organization_id = mmtt.organization_id
3811 AND msi.bulk_picked_flag = 'Y' )
3812 )
3813 GROUP BY mmtt.inventory_item_id
3814 , mmtt.revision
3815 , mmtt.organization_id
3816 , mmtt.subinventory_code
3817 , mmtt.locator_id
3818 , mmtt.transaction_uom
3819 , mmtt.transaction_type_id
3820 , mmtt.transaction_action_id
3821 , mmtt.transaction_source_type_id
3822 , mmtt.transfer_organization
3823 , mmtt.wms_task_type
3824 , mmtt.cost_group_id
3825 , mmtt.container_item_id
3826 , mmtt.operation_plan_id
3827 , mmtt.wms_task_status
3828 , mmtt.item_primary_uom_code
3829 , mmtt.item_lot_control_code
3830 , mmtt.item_serial_control_code
3831 , mmtt.serial_allocated_flag
3832 , mmtt.transaction_batch_id
3833 HAVING SUM(mmtt.transaction_quantity) <> MIN(mmtt.transaction_quantity); -- make sure one line will not get consolidated
3834
3835 BEGIN
3836
3837 -- Initialize API return status to success
3838 x_return_status := fnd_api.g_ret_sts_success;
3839
3840 SAVEPOINT task_consolidation_sp;
3841
3842 IF g_debug = 1 THEN
3843 print_debug( 'Entered with parameters: ' || g_newline ||
3844 'p_mo_header_id => ' || p_mo_header_id
3845 , l_api_name);
3846 END IF;
3847
3848 -- Cache the move order header info
3849 IF NOT INV_CACHE.set_mtrh_rec(p_mo_header_id) THEN
3850 IF g_debug = 1 THEN
3851 print_debug( 'Error from INV_CACHE.set_mtrh_rec', l_api_name);
3852 END IF;
3853 RAISE fnd_api.g_exc_unexpected_error;
3854 END IF;
3855
3856 SELECT spg.bulk_pick_control
3857 INTO l_bulk_pick_control
3858 FROM wsh_pick_grouping_rules spg
3859 WHERE spg.pick_grouping_rule_id = INV_CACHE.mtrh_rec.grouping_rule_id;
3860
3861 -- If bulk picking is not enabled then RETURN
3862 IF l_bulk_pick_control IS NULL THEN
3863 l_bulk_pick_control := WMS_GLOBALS.BULK_PICK_SUB_ITEM;
3864 ELSE
3865 IF (l_bulk_pick_control = WMS_GLOBALS.BULK_PICK_DISABLED) THEN
3866 IF (g_debug = 1) THEN
3867 print_debug( 'Bulk picking is not enabled', l_api_name );
3868 END IF;
3869 RETURN;
3870 END IF;
3871 END IF;
3872
3873 l_move_order_type := INV_CACHE.mtrh_rec.move_order_type;
3874
3875 IF l_move_order_type <> inv_globals.g_move_order_pick_wave THEN
3876 IF (g_debug = 1) THEN
3877 print_debug('Move Order is a not pick wave move order', l_api_name );
3878 END IF;
3879 RAISE fnd_api.g_exc_unexpected_error;
3880 END IF;
3881
3882 SELECT DELIVERY_FLAG
3883 INTO l_delivery_flag
3884 FROM WSH_PICK_GROUPING_RULES
3885 WHERE pick_method=WMS_GLOBALS.PICK_METHOD_BULK
3886 AND user_defined_flag = 'N' -- bulk picking default rule
3887 AND ROWNUM < 2; -- In case of pseudo translation, multiple records are inserted for the seeded rule
3888
3889 IF g_debug = 1 THEN
3890 print_debug('Group-by-delivery flag: ' || l_delivery_flag, l_api_name);
3891 END IF;
3892
3893 IF l_delivery_flag = 'Y' THEN
3894 OPEN task_list( p_mo_header_id );
3895 ELSE
3896 OPEN task_list_cross_delivery( p_mo_header_id );
3897 END IF;
3898
3899 LOOP --{
3900 IF l_delivery_flag = 'Y' THEN
3901 FETCH task_list BULK COLLECT
3902 INTO l_last_update_date
3903 , l_last_updated_by
3904 , l_creation_date
3905 , l_created_by
3906 , l_inventory_item_id
3907 , l_revision
3908 , l_organization_id
3909 , l_subinventory_code
3910 , l_locator_id
3911 , l_transaction_quantity
3912 , l_primary_quantity
3913 , l_transaction_uom
3914 , l_transaction_type_id
3915 , l_transaction_action_id
3916 , l_transaction_source_type_id
3917 , l_transaction_date
3918 , l_acct_period_id
3919 , l_to_org_id
3920 , l_wms_task_type
3921 , l_task_priority
3922 , l_cost_group_id
3923 , l_transaction_header_id
3924 , l_container_item_id
3925 , l_operation_plan_id
3926 , l_wms_task_status
3927 , l_carton_grouping_id
3928 , l_primary_uom_code
3929 , l_lot_control_code
3930 , l_serial_control_code
3931 , l_serial_allocated_flag
3932 , l_transaction_batch_id LIMIT g_bulk_fetch_limit;
3933
3934 EXIT WHEN l_transaction_header_id.COUNT = 0;
3935 ELSE
3936 FETCH task_list_cross_delivery BULK COLLECT
3937 INTO l_last_update_date
3938 , l_last_updated_by
3939 , l_creation_date
3940 , l_created_by
3941 , l_inventory_item_id
3942 , l_revision
3943 , l_organization_id
3944 , l_subinventory_code
3945 , l_locator_id
3946 , l_transaction_quantity
3947 , l_primary_quantity
3948 , l_transaction_uom
3949 , l_transaction_type_id
3950 , l_transaction_action_id
3951 , l_transaction_source_type_id
3952 , l_transaction_date
3953 , l_acct_period_id
3954 , l_to_org_id
3955 , l_wms_task_type
3956 , l_task_priority
3957 , l_cost_group_id
3958 , l_transaction_header_id
3959 , l_container_item_id
3960 , l_operation_plan_id
3961 , l_wms_task_status
3962 , l_primary_uom_code
3963 , l_lot_control_code
3964 , l_serial_control_code
3965 , l_serial_allocated_flag
3966 , l_transaction_batch_id LIMIT g_bulk_fetch_limit;
3967
3968 EXIT WHEN l_transaction_header_id.COUNT = 0;
3969 END IF;
3970
3971 -- Bulk insert parent rows directly into MMTT
3972 FORALL jj IN l_transaction_header_id.FIRST .. l_transaction_header_id.LAST
3973 INSERT INTO mtl_material_transactions_temp
3974 ( transaction_header_id
3975 , transaction_temp_id
3976 , posting_flag
3977 , transaction_status
3978 , last_update_date
3979 , last_updated_by
3980 , creation_date
3981 , created_by
3982 , transaction_type_id
3983 , transaction_action_id
3984 , transaction_source_type_id
3985 , organization_id
3986 , inventory_item_id
3987 , revision
3988 , subinventory_code
3989 , locator_id
3990 , transfer_organization
3991 , transaction_quantity
3992 , primary_quantity
3993 , transaction_uom
3994 , transaction_date
3995 , acct_period_id
3996 , cost_group_id
3997 , wms_task_type
3998 , task_priority
3999 , container_item_id
4000 , operation_plan_id
4001 , wms_task_status
4002 , parent_line_id
4003 , item_primary_uom_code
4004 , item_lot_control_code
4005 , item_serial_control_code
4006 , serial_allocated_flag
4007 , transaction_batch_id
4008 , pick_slip_number
4009 , lock_flag ) --bug 9130704
4010 VALUES ( l_transaction_header_id(jj)
4011 , mtl_material_transactions_s.NEXTVAL
4012 , 'N'
4013 , 2
4014 , l_last_update_date(jj)
4015 , l_last_updated_by(jj)
4016 , l_creation_date(jj)
4017 , l_created_by(jj)
4018 , l_transaction_type_id(jj)
4019 , l_transaction_action_id(jj)
4020 , l_transaction_source_type_id(jj)
4021 , l_organization_id(jj)
4022 , l_inventory_item_id(jj)
4023 , l_revision(jj)
4024 , l_subinventory_code(jj)
4025 , l_locator_id(jj)
4026 , l_to_org_id(jj)
4027 , l_transaction_quantity(jj)
4028 , l_primary_quantity(jj)
4029 , l_transaction_uom(jj)
4030 , l_transaction_date(jj)
4031 , l_acct_period_id(jj)
4032 , l_cost_group_id(jj)
4033 , l_wms_task_type(jj)
4034 , l_task_priority(jj)
4035 , l_container_item_id(jj)
4036 , l_operation_plan_id(jj)
4037 , l_wms_task_status(jj)
4038 , mtl_material_transactions_s.CURRVAL
4039 , l_primary_uom_code(jj)
4040 , l_lot_control_code(jj)
4041 , l_serial_control_code(jj)
4042 , l_serial_allocated_flag(jj)
4043 , l_transaction_batch_id(jj)
4044 , wsh_pick_slip_numbers_s.NEXTVAL
4045 , 'Y')
4046 RETURNING transaction_temp_id BULK COLLECT INTO tbl_transaction_temp_id;
4047
4048 IF g_debug = 1 AND SQL%ROWCOUNT > 0 THEN
4049 print_debug( 'Inserted ' || l_transaction_header_id.COUNT || ' parent MMTTs'
4050 , l_api_name);
4051 END IF;
4052
4053 -- Bulk update the child MMTTs for setting parent_line_id
4054 -- and nulling out transaction_batch_id and pick_slip_number
4055 IF l_delivery_flag = 'Y' THEN
4056 FORALL kk IN tbl_transaction_temp_id.FIRST .. tbl_transaction_temp_id.LAST
4057 UPDATE mtl_material_transactions_temp mmtt
4058 SET parent_line_id = tbl_transaction_temp_id(kk)
4059 , transaction_batch_id = NULL
4060 , pick_slip_number = NULL
4061 WHERE transaction_temp_id <> tbl_transaction_temp_id(kk)
4062 AND move_order_header_id = p_mo_header_id
4063 AND inventory_item_id = l_inventory_item_id(kk)
4064 AND NVL(revision, '#$%') = NVL(l_revision(kk), NVL(revision, '#$%'))
4065 AND organization_id = l_organization_id(kk)
4066 AND subinventory_code = l_subinventory_code(kk)
4067 AND transaction_uom = l_transaction_uom(kk)
4068 AND NVL(cost_group_id, -1) = NVL(l_cost_group_id(kk), NVL(cost_group_id, -1))
4069 AND NVL(locator_id, -1) = NVL(l_locator_id(kk), NVL(locator_id, -1))
4070 AND NVL(transfer_organization, -1) = NVL(l_to_org_id(kk), NVL(transfer_organization, -1))
4071 AND NVL(transaction_type_id, -1) = NVL(l_transaction_type_id(kk), NVL(transaction_type_id, -1))
4072 AND NVL(transaction_action_id, -1) = NVL(l_transaction_action_id(kk), NVL(transaction_action_id, -1))
4073 AND NVL(transaction_source_type_id, -1) = NVL(l_transaction_source_type_id(kk), NVL(transaction_source_type_id, -1))
4074 AND EXISTS( SELECT 1
4075 FROM mtl_txn_request_lines mol,wsh_delivery_details_ob_grp_v wdd,wsh_delivery_assignments_v wda
4076 WHERE mol.line_id = mmtt.move_order_line_id
4077 AND mol.line_id = wdd.move_order_line_id
4078 AND wdd.delivery_detail_id = wda.delivery_detail_id
4079 AND NVL(wda.delivery_id,mol.carton_grouping_id) = l_carton_grouping_id(kk) )
4080 AND allocated_lpn_id IS NULL -- Bug: 9309619 Added below condition
4081 AND cartonization_id is NULL;--added for bug 9446937
4082 ELSE
4083 FORALL kk IN tbl_transaction_temp_id.FIRST .. tbl_transaction_temp_id.LAST
4084 UPDATE mtl_material_transactions_temp
4085 SET parent_line_id = tbl_transaction_temp_id(kk)
4086 , transaction_batch_id = NULL
4087 , pick_slip_number = NULL --newly added
4088 WHERE transaction_temp_id <> tbl_transaction_temp_id(kk)
4089 AND move_order_header_id = p_mo_header_id
4090 AND inventory_item_id = l_inventory_item_id(kk)
4091 AND NVL(revision, '#$%') = NVL(l_revision(kk), NVL(revision, '#$%'))
4092 AND organization_id = l_organization_id(kk)
4093 AND subinventory_code = l_subinventory_code(kk)
4094 AND transaction_uom = l_transaction_uom(kk)
4095 AND NVL(locator_id, -1) = NVL(l_locator_id(kk), NVL(locator_id, -1))
4096 AND NVL(cost_group_id, -1) = NVL(l_cost_group_id(kk), NVL(cost_group_id, -1))
4097 AND NVL(transfer_organization, -1) = NVL(l_to_org_id(kk), NVL(transfer_organization, -1))
4098 AND NVL(transaction_type_id, -1) = NVL(l_transaction_type_id(kk), NVL(transaction_type_id, -1))
4099 AND NVL(transaction_action_id, -1) = NVL(l_transaction_action_id(kk), NVL(transaction_action_id, -1))
4100 AND NVL(transaction_source_type_id, -1) = NVL(l_transaction_source_type_id(kk), NVL(transaction_source_type_id, -1))
4101 AND allocated_lpn_id IS NULL -- Bug: 9309619 Added below condition
4102 AND cartonization_id is NULL;--added for bug 9446937
4103 END IF;
4104
4105 IF g_debug = 1 AND SQL%ROWCOUNT > 0 THEN
4106 print_debug('Updated child MMTTs', l_api_name);
4107 END IF;
4108
4109 -- Bulk insert MTLT records for the parent tasks
4110 FORALL ii IN tbl_transaction_temp_id.FIRST .. tbl_transaction_temp_id.LAST
4111 INSERT INTO mtl_transaction_lots_temp
4112 ( transaction_temp_id
4113 , lot_number
4114 , transaction_quantity
4115 , primary_quantity
4116 , lot_expiration_date
4117 , last_update_date
4118 , last_updated_by
4119 , creation_date
4120 , created_by
4121 , serial_transaction_temp_id) -- always set to null since we don't bulk
4122 -- lines with allocated serial numbers
4123
4124 ( SELECT tbl_transaction_temp_id(ii) -- transaction_temp_id of parent line
4125 , mtlt.lot_number
4126 , SUM(mtlt.transaction_quantity) transaction_quantity
4127 , SUM(mtlt.primary_quantity) primary_quantity
4128 , mtlt.lot_expiration_date
4129 , SYSDATE
4130 , g_user_id
4131 , SYSDATE
4132 , g_user_id
4133 , NULL
4134 FROM mtl_transaction_lots_temp mtlt, mtl_material_transactions_temp mmtt
4135 WHERE mtlt.transaction_temp_id = mmtt.transaction_temp_id
4136 AND mmtt.parent_line_id = tbl_transaction_temp_id(ii) -- child task
4137 AND mmtt.transaction_temp_id <> tbl_transaction_temp_id(ii) -- not parent task
4138 AND l_lot_control_code(ii) = 2
4139 GROUP BY mtlt.lot_number,mtlt.lot_expiration_date );
4140
4141 IF g_debug = 1 AND SQL%ROWCOUNT > 0 THEN
4142 print_debug('Inserted parent MTLT records', l_api_name);
4143 END IF;
4144
4145 END LOOP; --}
4146
4147 IF task_list%ISOPEN THEN
4148 CLOSE task_list;
4149 END IF;
4150
4151 IF task_list%ISOPEN THEN
4152 CLOSe task_list_cross_delivery;
4153 END IF;
4154
4155 COMMIT;
4156
4157 EXCEPTION
4158 WHEN fnd_api.g_exc_error THEN
4159 ROLLBACK TO task_consolidation_sp;
4160 x_return_status := fnd_api.g_ret_sts_error;
4161 fnd_msg_pub.count_and_get
4162 ( p_count => l_msg_count
4163 , p_data => l_msg_data
4164 , p_encoded => fnd_api.g_false
4165 );
4166 IF g_debug = 1 THEN
4167 print_debug (l_msg_data, l_api_name);
4168 END IF;
4169 IF task_list%ISOPEN THEN
4170 CLOSE task_list;
4171 END IF;
4172 IF task_list_cross_delivery%ISOPEN THEN
4173 CLOSE task_list_cross_delivery;
4174 END IF;
4175
4176 WHEN OTHERS THEN
4177 ROLLBACK TO task_consolidation_sp;
4178 x_return_status := fnd_api.g_ret_sts_unexp_error;
4179 IF g_debug = 1 THEN
4180 print_debug('Other error: ' || SQLERRM, l_api_name);
4181 END IF;
4182 IF task_list%ISOPEN THEN
4183 CLOSE task_list;
4184 END IF;
4185 IF task_list_cross_delivery%ISOPEN THEN
4186 CLOSE task_list_cross_delivery;
4187 END IF;
4188
4189 END consolidate_tasks;
4190
4191
4192
4193 PROCEDURE split_one_task
4194 ( p_mmtt_temp_id IN NUMBER
4195 , x_return_status OUT NOCOPY VARCHAR2
4196 ) IS
4197
4198 l_api_name VARCHAR2(30) := 'split_one_task';
4199 l_msg_count NUMBER;
4200 l_msg_data VARCHAR2(2000);
4201 l_api_return_status VARCHAR2(1);
4202 l_split_executed BOOLEAN;
4203 l_savepoint_exists BOOLEAN := FALSE;
4204
4205 l_hash_split_fac_value NUMBER;
4206 l_hash_split_fac_string VARCHAR2(2000) := NULL;
4207
4208 l_task_new_rec mtl_material_transactions_temp%ROWTYPE;
4209 l_child_new_rec mtl_material_transactions_temp%ROWTYPE;
4210 l_lot_split_rec inv_rcv_common_apis.trans_rec_tb_tp;
4211
4212 l_organization_id NUMBER;
4213 l_parent_line_id NUMBER;
4214 l_std_op_id NUMBER; --task type
4215 l_split_factor NUMBER; --tasks would be split to this size
4216 l_item_vol NUMBER; --item unit volume
4217 l_item_weight NUMBER; --item unit weight
4218 l_item_v_uom VARCHAR2(3); --item unit volume UOM
4219 l_item_w_uom VARCHAR2(3); --item unit weight UOM
4220 l_equip_v_uom VARCHAR2(3); -- equipment volume UOM
4221 l_equip_w_uom VARCHAR2(3); -- equipment weight UOM
4222 l_equip_vol NUMBER; --equipment volume capacity
4223 l_equip_weight NUMBER; --equipment weight capacity
4224 l_eqp_id NUMBER;
4225 l_eq_it_v_uom_ratio NUMBER := 1; --conversion ratio between equipment volume capacity and item unit volume UOM
4226 l_eq_it_w_uom_ratio NUMBER := 1; --conversion ratio between equipment weight capacity and item unit weight UOM
4227
4228 l_loc_txn_uom_ratio NUMBER; --conversion rate between locator uom and transaction uom
4229 l_txn_pri_uom_ratio NUMBER; --conversion rate between transaction uom and item primary UOM
4230 l_txn_sec_uom_ratio NUMBER; --conversion rate between transaction uom and secondary UOM
4231 l_loc_uom_code VARCHAR2(3); --locator uom_code
4232 l_txn_uom_code VARCHAR2(3); --transaction uom_code
4233 l_sec_uom_code VARCHAR2(3); --secondary uom_code
4234 l_item_id NUMBER;
4235 l_init_qty NUMBER;
4236 l_sec_txn_qty NUMBER; --secondary transaction quantity
4237 l_item_prim_uom_code VARCHAR2(3); --primary uom_code
4238 l_min_cap NUMBER; --minimum equipment capacity for a task
4239 l_min_cap_temp NUMBER;
4240 l_new_qty NUMBER;
4241 l_lot_control_code NUMBER;
4242 l_serial_number_control_code NUMBER;
4243 l_sfactor_flag NUMBER;
4244
4245 l_child_remaining_qty NUMBER := 0;
4246 l_child_temp_id NUMBER := 0;
4247 l_child_total_qty NUMBER := 0;
4248 l_new_child_temp_id NUMBER;
4249 l_new_child_qty NUMBER;
4250 l_new_temp_id NUMBER;
4251
4252 l_hash_value_w NUMBER;
4253 l_hash_string_w VARCHAR2(2000) := NULL;
4254 l_hash_value_loctxnuom NUMBER;
4255 l_hash_string_loctxnuom VARCHAR2(2000) := NULL;
4256 l_hash_value_tpuom NUMBER;
4257 l_hash_string_tpuom VARCHAR2(2000) := NULL;
4258 l_hash_value_tsecuom NUMBER;
4259 l_hash_string_tsecuom VARCHAR2(2000) := NULL;
4260 l_hash_value_v NUMBER;
4261 l_hash_string_v VARCHAR2(2000) := NULL;
4262
4263
4264 CURSOR c_child_tasks(p_parent_line_id NUMBER) IS
4265 SELECT mmtt.transaction_temp_id
4266 , mmtt.transaction_quantity
4267 FROM mtl_material_transactions_temp mmtt
4268 , mtl_txn_request_lines mol
4269 , wsh_delivery_details_ob_grp_v wdd
4270 , wsh_delivery_assignments_v wda
4271 WHERE mmtt.parent_line_id = p_parent_line_id
4272 AND mol.line_id = mmtt.move_order_line_id
4273 AND mol.line_id = wdd.move_order_line_id
4274 AND wdd.delivery_detail_id = wda.delivery_detail_id
4275 AND mmtt.transaction_temp_id <> p_parent_line_id
4276 ORDER BY nvl(wda.delivery_id,mol.carton_grouping_id)
4277 , mmtt.transaction_quantity DESC;
4278
4279 CURSOR c_eqp_capacity(p_task_id NUMBER) IS
4280 SELECT res_equip.inventory_item_id
4281 FROM mtl_material_transactions_temp mmtt
4282 , bom_std_op_resources tt_x_res
4283 , bom_resources res
4284 , bom_resource_equipments res_equip
4285 WHERE mmtt.transaction_temp_id = p_task_id
4286 AND mmtt.standard_operation_id = tt_x_res.standard_operation_id
4287 AND tt_x_res.resource_id = res.resource_id
4288 AND res.organization_id = mmtt.organization_id
4289 AND res.resource_type = 1
4290 AND res_equip.resource_id = res.resource_id
4291 AND res_equip.organization_id = res.organization_id;
4292
4293 l_child_rec c_child_tasks%ROWTYPE;
4294
4295 BEGIN
4296 x_return_status := fnd_api.g_ret_sts_success;
4297
4298 IF g_debug = 1 THEN
4299 print_debug( 'Entered with parameters: ' || g_newline ||
4300 'p_mmtt_temp_id => ' || p_mmtt_temp_id
4301 , l_api_name );
4302 END IF;
4303
4304 l_split_factor := -9999;
4305 l_min_cap := -9999;
4306 l_split_executed := FALSE;
4307
4308 SELECT NVL(mil.pick_uom_code, msi.pick_uom_code)
4309 , mmtt.organization_id
4310 , mmtt.parent_line_id
4311 , mmtt.inventory_item_id
4312 , mmtt.standard_operation_id
4313 , mmtt.transaction_quantity
4314 , mmtt.transaction_uom
4315 , mmtt.secondary_transaction_quantity
4316 , mmtt.secondary_uom_code
4317 , item.primary_uom_code
4318 , item.lot_control_code
4319 , item.serial_number_control_code
4320 INTO l_loc_uom_code
4321 , l_organization_id
4322 , l_parent_line_id
4323 , l_item_id
4324 , l_std_op_id
4325 , l_init_qty
4326 , l_txn_uom_code
4327 , l_sec_txn_qty
4328 , l_sec_uom_code
4329 , l_item_prim_uom_code
4330 , l_lot_control_code
4331 , l_serial_number_control_code
4332 FROM mtl_material_transactions_temp mmtt
4333 , mtl_item_locations mil
4334 , mtl_secondary_inventories msi
4335 , mtl_system_items item
4336 WHERE mmtt.transaction_temp_id = p_mmtt_temp_id
4337 AND mmtt.locator_id = mil.inventory_location_id(+)
4338 AND mmtt.organization_id = mil.organization_id(+)
4339 AND mmtt.subinventory_code = msi.secondary_inventory_name
4340 AND mmtt.organization_id = msi.organization_id
4341 AND mmtt.inventory_item_id = item.inventory_item_id
4342 AND mmtt.organization_id = item.organization_id;
4343
4344 IF l_txn_uom_code IS NULL
4345 OR l_item_id IS NULL
4346 OR l_init_qty IS NULL
4347 OR l_item_prim_uom_code IS NULL
4348 THEN
4349 IF g_debug = 1 THEN
4350 print_debug('Necessary UOM information is missing for task: ' || p_mmtt_temp_id, l_api_name);
4351 END IF;
4352 RETURN;
4353 END IF;
4354
4355 IF l_loc_uom_code IS NULL THEN
4356 IF g_debug = 1 THEN
4357 print_debug('l_loc_uom_code is NULL, initializing l_loc_txn_uom_ratio to 1', l_api_name);
4358 END IF;
4359 l_loc_txn_uom_ratio := 1;
4360 ELSE --{
4361 IF l_loc_uom_code = l_txn_uom_code THEN
4362 l_loc_txn_uom_ratio := 1;
4363 ELSE --{
4364 l_hash_string_loctxnuom := l_loc_uom_code || '-' || l_txn_uom_code || '-' || l_item_id; --newly added
4365 l_hash_value_loctxnuom := DBMS_UTILITY.get_hash_value
4366 ( name => l_hash_string_loctxnuom
4367 , base => g_hash_base
4368 , hash_size => g_hash_size
4369 );
4370
4371 IF g_from_to_uom_ratio_tbl.EXISTS(l_hash_value_loctxnuom)
4372 AND g_from_uom_code_tbl(l_hash_value_loctxnuom) = l_loc_uom_code
4373 AND g_to_uom_code_tbl(l_hash_value_loctxnuom) = l_txn_uom_code
4374 AND g_item_tbl(l_hash_value_loctxnuom) = l_item_id --newly added
4375 THEN
4376 l_loc_txn_uom_ratio := g_from_to_uom_ratio_tbl(l_hash_value_loctxnuom);
4377 ELSE --{
4378 -- Compute conversion ratio between transaction UOM and item primary UOM
4379 inv_convert.inv_um_conversion( from_unit => l_loc_uom_code
4380 , to_unit => l_txn_uom_code
4381 , item_id => l_item_id
4382 , uom_rate => l_loc_txn_uom_ratio
4383 );
4384 g_from_uom_code_tbl(l_hash_value_loctxnuom) := l_loc_uom_code;
4385 g_to_uom_code_tbl(l_hash_value_loctxnuom) := l_txn_uom_code;
4386 g_from_to_uom_ratio_tbl(l_hash_value_loctxnuom) := l_loc_txn_uom_ratio;
4387 g_item_tbl(l_hash_value_loctxnuom) := l_item_id; --newly added
4388 END IF; --}
4389 END IF; --}
4390 END IF; --}
4391
4392 IF l_loc_txn_uom_ratio = -99999 THEN -- UOM conversion failure
4393 IF g_debug = 1 THEN
4394 print_debug('Loc/txn UOM ratio calculation failed', l_api_name);
4395 END IF;
4396 RETURN;
4397 END IF;
4398
4399 IF l_txn_uom_code = l_item_prim_uom_code THEN
4400 l_txn_pri_uom_ratio := 1;
4401 ELSE --{
4402 l_hash_string_tpuom := l_txn_uom_code || '-' || l_item_prim_uom_code || '-' || l_item_id; --newly added
4403 l_hash_value_tpuom := DBMS_UTILITY.get_hash_value
4404 ( name => l_hash_string_tpuom
4405 , base => g_hash_base
4406 , hash_size => g_hash_size
4407 );
4408
4409 IF g_from_to_uom_ratio_tbl.EXISTS(l_hash_value_tpuom)
4410 AND g_from_uom_code_tbl(l_hash_value_tpuom) = l_txn_uom_code
4411 AND g_to_uom_code_tbl(l_hash_value_tpuom) = l_item_prim_uom_code
4412 AND g_item_tbl(l_hash_value_tpuom) = l_item_id --newly added
4413 THEN
4414 l_txn_pri_uom_ratio := g_from_to_uom_ratio_tbl(l_hash_value_tpuom);
4415 ELSE --{
4416 -- Compute conversion ratio between transaction UOM and item primary UOM
4417 inv_convert.inv_um_conversion( from_unit => l_txn_uom_code
4418 , to_unit => l_item_prim_uom_code
4419 , item_id => l_item_id
4420 , uom_rate => l_txn_pri_uom_ratio
4421 );
4422 g_from_uom_code_tbl(l_hash_value_tpuom) := l_txn_uom_code;
4423 g_to_uom_code_tbl(l_hash_value_tpuom) := l_item_prim_uom_code;
4424 g_from_to_uom_ratio_tbl(l_hash_value_tpuom) := l_txn_pri_uom_ratio;
4425 g_item_tbl(l_hash_value_tpuom) := l_item_id; --newly added
4426 END IF; --}
4427 END IF; --}
4428
4429 IF l_txn_pri_uom_ratio = -99999 THEN -- UOM conversion failure
4430 IF g_debug = 1 THEN
4431 print_debug('Txn/primary UOM ratio calculation failed', l_api_name);
4432 END IF;
4433 RETURN;
4434 END IF;
4435
4436 IF l_sec_uom_code IS NOT NULL THEN --{
4437 IF l_txn_uom_code = l_sec_uom_code THEN
4438 l_txn_sec_uom_ratio := 1;
4439 ELSE --{
4440 l_hash_string_tsecuom := l_txn_uom_code || '-' || l_sec_uom_code || '-' || l_item_id; --newly added
4441 l_hash_value_tsecuom := DBMS_UTILITY.get_hash_value
4442 ( name => l_hash_string_tsecuom
4443 , base => g_hash_base
4444 , hash_size => g_hash_size
4445 );
4446
4447 IF g_from_to_uom_ratio_tbl.EXISTS(l_hash_value_tsecuom)
4448 AND g_from_uom_code_tbl(l_hash_value_tsecuom) = l_txn_uom_code
4449 AND g_to_uom_code_tbl(l_hash_value_tsecuom) = l_sec_uom_code
4450 AND g_item_tbl(l_hash_value_tsecuom) = l_item_id --newly added
4451 THEN
4452 l_txn_sec_uom_ratio := g_from_to_uom_ratio_tbl(l_hash_value_tsecuom);
4453 ELSE --{
4454 -- Compute conversion ratio between transaction UOM and item primary UOM
4455 inv_convert.inv_um_conversion( from_unit => l_txn_uom_code
4456 , to_unit => l_sec_uom_code
4457 , item_id => l_item_id
4458 , uom_rate => l_txn_sec_uom_ratio
4459 );
4460 g_from_uom_code_tbl(l_hash_value_tsecuom) := l_txn_uom_code;
4461 g_to_uom_code_tbl(l_hash_value_tsecuom) := l_sec_uom_code;
4462 g_from_to_uom_ratio_tbl(l_hash_value_tsecuom) := l_txn_sec_uom_ratio;
4463 g_item_tbl(l_hash_value_tsecuom) := l_item_id; --newly added
4464 END IF; --}
4465 END IF; --}
4466
4467 IF l_txn_sec_uom_ratio = -99999 THEN -- UOM conversion failure
4468 IF g_debug = 1 THEN
4469 print_debug('Txn/secondary UOM ratio calculation failed', l_api_name);
4470 END IF;
4471 RETURN;
4472 END IF;
4473 END IF; --}
4474
4475 IF g_debug = 1 THEN
4476 print_debug('l_loc_txn_uom_ratio => ' || l_loc_txn_uom_ratio, l_api_name);
4477 print_debug('l_txn_pri_uom_ratio => ' || l_txn_pri_uom_ratio, l_api_name);
4478 END IF;
4479
4480 l_sfactor_flag := 0;
4481 l_hash_split_fac_string := TO_CHAR(l_organization_id) || '-' ||
4482 TO_CHAR(l_item_id) || '-' ||
4483 TO_CHAR(l_std_op_id);
4484 l_hash_split_fac_value := DBMS_UTILITY.get_hash_value
4485 ( name => l_hash_split_fac_string
4486 , base => g_hash_base
4487 , hash_size => g_hash_size
4488 );
4489
4490 IF g_hash_split_fac_tbl.EXISTS(l_hash_split_fac_value)
4491 AND g_hash_split_org_tbl(l_hash_split_fac_value) = l_organization_id
4492 AND g_hash_split_inv_item_id_tbl(l_hash_split_fac_value) = l_item_id
4493 AND g_hash_split_std_op_id_tbl(l_hash_split_fac_value) = l_std_op_id
4494 THEN
4495 l_min_cap := g_hash_split_fac_tbl(l_hash_split_fac_value);
4496 l_sfactor_flag := 1;
4497 END IF;
4498
4499 IF l_sfactor_flag = 0 THEN --{
4500 -- Add -9999 to the cache so that the split_factor calculation
4501 -- is only attempted once
4502 g_hash_split_org_tbl(l_hash_split_fac_value) := l_organization_id;
4503 g_hash_split_inv_item_id_tbl(l_hash_split_fac_value) := l_item_id;
4504 g_hash_split_std_op_id_tbl(l_hash_split_fac_value) := l_std_op_id;
4505 g_hash_split_fac_tbl(l_hash_split_fac_value) := -9999;
4506
4507 IF inv_cache.set_item_rec(l_organization_id, l_item_id) THEN
4508 l_item_v_uom := inv_cache.item_rec.volume_uom_code;
4509 l_item_w_uom := inv_cache.item_rec.weight_uom_code;
4510 l_item_weight := inv_cache.item_rec.unit_weight;
4511 l_item_vol := inv_cache.item_rec.unit_volume;
4512 END IF ;
4513
4514 IF (( l_item_v_uom IS NOT NULL AND l_item_vol IS NOT NULL )
4515 OR ( l_item_w_uom IS NOT NULL AND l_item_weight IS NOT NULL ))
4516 THEN --{
4517 OPEN c_eqp_capacity(p_mmtt_temp_id);
4518 -- Loop through equipment items
4519 LOOP --{
4520 FETCH c_eqp_capacity INTO l_eqp_id;
4521 EXIT WHEN c_eqp_capacity%NOTFOUND;
4522
4523 IF g_eqp_org_id = l_organization_id
4524 AND g_eqp_vol_uom.EXISTS(l_eqp_id)
4525 THEN
4526 l_equip_v_uom := g_eqp_vol_uom(l_eqp_id);
4527 l_equip_w_uom := g_eqp_wt_uom(l_eqp_id);
4528 l_equip_weight := g_eqp_weight(l_eqp_id);
4529 l_equip_vol := g_eqp_volume(l_eqp_id);
4530 ELSE --{
4531 BEGIN
4532 SELECT msi.volume_uom_code
4533 , msi.weight_uom_code
4534 , msi.maximum_load_weight
4535 , msi.internal_volume
4536 INTO l_equip_v_uom
4537 , l_equip_w_uom
4538 , l_equip_weight
4539 , l_equip_vol
4540 FROM mtl_system_items msi
4541 WHERE msi.organization_id = l_organization_id
4542 AND msi.inventory_item_id = l_eqp_id;
4543
4544 -- Cache equipment attributes
4545 g_eqp_org_id := l_organization_id;
4546 g_eqp_vol_uom(l_eqp_id) := l_equip_v_uom;
4547 g_eqp_wt_uom(l_eqp_id) := l_equip_w_uom;
4548 g_eqp_weight(l_eqp_id) := l_equip_weight;
4549 g_eqp_volume(l_eqp_id) := l_equip_vol;
4550
4551 EXCEPTION
4552 WHEN OTHERS THEN
4553 IF g_debug = 1 THEN
4554 print_debug ('Error fetching equipment attributes'
4555 || SQLERRM, l_api_name);
4556 END IF;
4557 RAISE fnd_api.g_exc_unexpected_error;
4558 END;
4559 END IF; --}
4560
4561 IF ((l_equip_vol IS NOT NULL AND l_item_vol IS NOT NULL)
4562 OR (l_equip_weight IS NOT NULL AND l_item_weight IS NOT NULL))
4563 THEN --{
4564 l_eq_it_v_uom_ratio := -9999;
4565 l_eq_it_w_uom_ratio := -9999;
4566 l_min_cap_temp := -9999;
4567
4568 -- Derive item-to-equip weight UOM conversion
4569 IF l_item_w_uom IS NOT NULL AND l_equip_w_uom IS NOT NULL THEN --{
4570 IF l_equip_w_uom = l_item_w_uom THEN
4571 l_eq_it_w_uom_ratio := 1;
4572 ELSE --{
4573 l_hash_string_w := l_equip_w_uom || '-' || l_item_w_uom || '-' || '0'; --newly added
4574 l_hash_value_w := DBMS_UTILITY.get_hash_value
4575 ( name => l_hash_string_w
4576 , base => g_hash_base
4577 , hash_size => g_hash_size
4578 );
4579
4580 IF g_from_to_uom_ratio_tbl.EXISTS(l_hash_value_w)
4581 AND g_from_uom_code_tbl(l_hash_value_w) = l_equip_w_uom
4582 AND g_to_uom_code_tbl(l_hash_value_w) = l_item_w_uom
4583 AND g_item_tbl(l_hash_value_w) = 0 --newly added
4584 THEN
4585 l_eq_it_w_uom_ratio := g_from_to_uom_ratio_tbl(l_hash_value_w);
4586 ELSE --{
4587 inv_convert.inv_um_conversion( from_unit => l_equip_w_uom
4588 , to_unit => l_item_w_uom
4589 , item_id => 0
4590 , uom_rate => l_eq_it_w_uom_ratio
4591 );
4592 g_from_uom_code_tbl(l_hash_value_w) := l_equip_w_uom;
4593 g_to_uom_code_tbl(l_hash_value_w) := l_item_w_uom;
4594 g_from_to_uom_ratio_tbl(l_hash_value_w) := l_eq_it_w_uom_ratio;
4595 g_item_tbl(l_hash_value_w) := 0; --newly added
4596 END IF; --}
4597 END IF; --}
4598 END IF; --}
4599
4600 -- Derive item-to-equip volume UOM conversion
4601 IF l_item_v_uom IS NOT NULL AND l_equip_v_uom IS NOT NULL THEN --{
4602 IF l_equip_v_uom = l_item_v_uom THEN
4603 l_eq_it_v_uom_ratio := 1;
4604 ELSE --{
4605 l_hash_string_v := l_equip_v_uom || '-' || l_item_v_uom || '-' || '0'; --newly added
4606 l_hash_value_v := DBMS_UTILITY.get_hash_value
4607 ( name => l_hash_string_v
4608 , base => g_hash_base
4609 , hash_size => g_hash_size
4610 );
4611
4612 IF g_from_to_uom_ratio_tbl.EXISTS(l_hash_value_v)
4613 AND g_from_uom_code_tbl(l_hash_value_v) = l_equip_v_uom
4614 AND g_to_uom_code_tbl(l_hash_value_v) = l_item_v_uom
4615 AND g_item_tbl(l_hash_value_v) = 0 --newly added
4616 THEN
4617 l_eq_it_v_uom_ratio := g_from_to_uom_ratio_tbl(l_hash_value_v);
4618 ELSE --{
4619 inv_convert.inv_um_conversion( from_unit => l_equip_v_uom
4620 , to_unit => l_item_v_uom
4621 , item_id => 0
4622 , uom_rate => l_eq_it_v_uom_ratio
4623 );
4624 g_from_uom_code_tbl(l_hash_value_v) := l_equip_v_uom;
4625 g_to_uom_code_tbl(l_hash_value_v) := l_item_v_uom;
4626 g_from_to_uom_ratio_tbl(l_hash_value_v) := l_eq_it_v_uom_ratio;
4627 g_item_tbl(l_hash_value_v) := 0; --newly added
4628 END IF; --}
4629 END IF; --}
4630 END IF; --}
4631
4632 IF g_debug = 1 THEN
4633 print_debug('l_equip_vol = ' || l_equip_vol, l_api_name);
4634 print_debug('l_item_vol = ' || l_item_vol, l_api_name);
4635 print_debug('l_eq_it_v_uom_ratio = ' || l_eq_it_v_uom_ratio, l_api_name);
4636 print_debug('l_equip_weight = ' || l_equip_weight, l_api_name);
4637 print_debug('l_item_weight = ' || l_item_weight, l_api_name);
4638 print_debug('l_eq_it_w_uom_ratio = ' || l_eq_it_w_uom_ratio, l_api_name);
4639 END IF;
4640
4641 IF l_eq_it_w_uom_ratio <> -9999 AND
4642 l_eq_it_v_uom_ratio <> -9999 AND
4643 l_equip_weight IS NOT NULL AND
4644 l_equip_vol IS NOT NULL
4645 THEN
4646 l_min_cap_temp := TRUNC(LEAST( ((l_equip_vol * l_eq_it_v_uom_ratio) / l_item_vol)
4647 , ((l_equip_weight * l_eq_it_w_uom_ratio) / l_item_weight)
4648 )
4649 );
4650 IF l_min_cap_temp = 0 THEN
4651 l_min_cap_temp := LEAST( ((l_equip_vol * l_eq_it_v_uom_ratio) / l_item_vol)
4652 , ((l_equip_weight * l_eq_it_w_uom_ratio) / l_item_weight)
4653 );
4654 END IF;
4655 ELSIF l_eq_it_w_uom_ratio <> -9999 AND l_equip_weight IS NOT NULL THEN
4656 l_min_cap_temp := TRUNC((l_equip_weight * l_eq_it_w_uom_ratio) / l_item_weight);
4657 IF l_min_cap_temp = 0 THEN
4658 l_min_cap_temp := (l_equip_weight * l_eq_it_w_uom_ratio) / l_item_weight;
4659 END IF;
4660 ELSIF l_eq_it_v_uom_ratio <> -9999 AND l_equip_vol IS NOT NULL THEN
4661 l_min_cap_temp := TRUNC((l_equip_vol * l_eq_it_v_uom_ratio) / l_item_vol);
4662 IF l_min_cap_temp = 0 THEN
4663 l_min_cap_temp := (l_equip_vol * l_eq_it_v_uom_ratio) / l_item_vol;
4664 END IF;
4665 ELSE
4666 IF g_debug = 1 THEN
4667 print_debug( 'Both eqp/item volume and eqp/item weight UOM ratio calculation failed'
4668 , l_api_name);
4669 END IF;
4670 END IF;
4671
4672 IF (l_min_cap_temp <> -9999 AND l_min_cap_temp < l_min_cap)
4673 OR l_min_cap = -9999
4674 THEN
4675 l_min_cap := l_min_cap_temp;
4676 END IF;
4677 --}
4678 ELSE
4679 IF g_debug = 1 THEN
4680 print_debug( 'Both eqp/it weight or eqp/it vol is not defined'
4681 , l_api_name);
4682 END IF;
4683 IF c_eqp_capacity%ISOPEN THEN
4684 CLOSE c_eqp_capacity;
4685 END IF;
4686 RETURN;
4687 END IF;
4688 END LOOP; --}
4689 IF c_eqp_capacity%ISOPEN THEN
4690 CLOSE c_eqp_capacity;
4691 END IF;
4692
4693 g_hash_split_org_tbl(l_hash_split_fac_value) := l_organization_id;
4694 g_hash_split_inv_item_id_tbl(l_hash_split_fac_value) := l_item_id;
4695 g_hash_split_std_op_id_tbl(l_hash_split_fac_value) := l_std_op_id;
4696 g_hash_split_fac_tbl(l_hash_split_fac_value) := l_min_cap;
4697 END IF; --}
4698 END IF; --}
4699
4700 IF l_min_cap = -9999 THEN
4701 IF g_debug = 1 THEN
4702 print_debug('Invalid equipment capacity', l_api_name);
4703 END IF;
4704 RETURN;
4705 END IF;
4706
4707 l_split_factor := l_min_cap / l_txn_pri_uom_ratio;
4708
4709 IF l_split_factor >= l_loc_txn_uom_ratio THEN
4710 l_split_factor := TRUNC( l_split_factor / l_loc_txn_uom_ratio ) * l_loc_txn_uom_ratio;
4711 END IF;
4712
4713 IF l_split_factor <= 0 THEN
4714 IF g_debug = 1 THEN
4715 print_debug('Minimum capacity is 0', l_api_name);
4716 END IF;
4717 RETURN;
4718 END IF;
4719
4720 IF g_debug = 1 THEN
4721 print_debug('l_split_factor = ' || l_split_factor, l_api_name);
4722 END IF;
4723
4724 -- Splitting logic starts
4725 IF l_init_qty > l_split_factor AND l_split_factor > 0 THEN
4726 SAVEPOINT split_task_sp;
4727 l_savepoint_exists := TRUE;
4728 IF p_mmtt_temp_id = l_parent_line_id THEN
4729 OPEN c_child_tasks(p_mmtt_temp_id);
4730 END IF;
4731 END IF;
4732
4733 WHILE (l_init_qty > l_split_factor AND l_split_factor > 0)
4734 LOOP --{
4735 IF g_debug = 1 THEN
4736 print_debug('l_init_qty: ' || l_init_qty, l_api_name);
4737 END IF;
4738
4739 l_split_executed := TRUE;
4740 l_init_qty := l_init_qty - l_split_factor;
4741
4742 IF l_init_qty >= 0 THEN
4743 l_new_qty := l_split_factor;
4744 ELSE
4745 l_new_qty := l_init_qty + l_split_factor;
4746 END IF;
4747
4748 BEGIN
4749 SELECT *
4750 INTO l_task_new_rec
4751 FROM mtl_material_transactions_temp
4752 WHERE transaction_temp_id = p_mmtt_temp_id;
4753 EXCEPTION
4754 WHEN OTHERS THEN
4755 IF g_debug = 1 THEN
4756 print_debug ('Error fetching MMTT record: ' || SQLERRM, l_api_name);
4757 END IF;
4758 RAISE fnd_api.g_exc_unexpected_error;
4759 END;
4760
4761 SELECT mtl_material_transactions_s.NEXTVAL
4762 INTO l_new_temp_id
4763 FROM DUAL;
4764
4765 l_task_new_rec.transaction_temp_id := l_new_temp_id;
4766 l_task_new_rec.transaction_quantity := l_new_qty;
4767 l_task_new_rec.primary_quantity := l_new_qty * l_txn_pri_uom_ratio;
4768 IF l_task_new_rec.secondary_uom_code IS NOT NULL THEN
4769 l_task_new_rec.secondary_transaction_quantity := l_new_qty * l_txn_sec_uom_ratio;
4770 END IF;
4771 IF p_mmtt_temp_id = l_parent_line_id THEN
4772 l_task_new_rec.parent_line_id := l_new_temp_id;
4773 END IF;
4774
4775 wms_task_dispatch_engine.insert_mmtt(l_task_new_rec);
4776
4777 IF p_mmtt_temp_id = l_parent_line_id THEN --{
4778 -- Delete MTLT records created in task consolidation
4779 DELETE FROM mtl_transaction_lots_temp
4780 WHERE transaction_temp_id = p_mmtt_temp_id;
4781
4782 l_child_total_qty := 0;
4783 LOOP --{
4784 IF l_child_remaining_qty = 0 THEN
4785 FETCH c_child_tasks INTO l_child_rec;
4786 EXIT WHEN c_child_tasks%NOTFOUND;
4787
4788 l_child_remaining_qty := l_child_rec.transaction_quantity;
4789 l_child_temp_id := l_child_rec.transaction_temp_id;
4790 l_child_total_qty := l_child_total_qty + l_child_rec.transaction_quantity;
4791 ELSE
4792 l_child_rec.transaction_quantity := l_child_remaining_qty;
4793 l_child_total_qty := l_child_remaining_qty;
4794 END IF;
4795
4796 IF l_child_total_qty <= l_new_qty THEN
4797 -- Update the child records with the new parent line id
4798 UPDATE mtl_material_transactions_temp
4799 SET parent_line_id = l_new_temp_id
4800 WHERE transaction_temp_id = l_child_rec.transaction_temp_id;
4801
4802 l_child_remaining_qty := 0;
4803 IF l_child_total_qty = l_new_qty THEN
4804 EXIT;
4805 END IF;
4806 ELSE --{
4807 l_child_remaining_qty := l_child_total_qty - l_new_qty;
4808 l_new_child_qty := l_child_rec.transaction_quantity - l_child_remaining_qty;
4809
4810 -- Update the child line with the remaining qty
4811 UPDATE mtl_material_transactions_temp
4812 SET transaction_quantity = l_child_remaining_qty
4813 , primary_quantity = l_child_remaining_qty * l_txn_pri_uom_ratio
4814 , secondary_transaction_quantity
4815 = DECODE( secondary_uom_code
4816 , NULL, NULL
4817 , l_child_remaining_qty * l_txn_sec_uom_ratio
4818 )
4819 WHERE transaction_temp_id = l_child_rec.transaction_temp_id;
4820
4821 SELECT mtl_material_transactions_s.NEXTVAL
4822 INTO l_new_child_temp_id
4823 FROM DUAL;
4824
4825 SELECT *
4826 INTO l_child_new_rec
4827 FROM mtl_material_transactions_temp
4828 WHERE transaction_temp_id = l_child_rec.transaction_temp_id;
4829
4830 l_child_new_rec.transaction_temp_id := l_new_child_temp_id;
4831 l_child_new_rec.transaction_quantity := l_new_child_qty;
4832 l_child_new_rec.primary_quantity := l_new_child_qty * l_txn_pri_uom_ratio;
4833 IF l_child_new_rec.secondary_uom_code IS NOT NULL THEN
4834 l_child_new_rec.secondary_transaction_quantity := l_new_child_qty * l_txn_sec_uom_ratio;
4835 END IF;
4836 l_child_new_rec.parent_line_id := l_new_temp_id;
4837
4838 wms_task_dispatch_engine.insert_mmtt(l_child_new_rec);
4839
4840 -- Split lot/serial temp table
4841 l_lot_split_rec(1).transaction_id := l_new_child_temp_id;
4842 l_lot_split_rec(1).primary_quantity := l_child_new_rec.primary_quantity;
4843
4844 inv_rcv_common_apis.BREAK( p_original_tid => l_child_rec.transaction_temp_id
4845 , p_new_transactions_tb => l_lot_split_rec
4846 , p_lot_control_code => l_lot_control_code
4847 , p_serial_control_code => l_serial_number_control_code
4848 );
4849 EXIT;
4850 END IF; --}
4851 END LOOP; --}
4852
4853 -- Copy the lot and serial to the parents
4854 l_api_return_status := fnd_api.g_ret_sts_success;
4855 wms_task_dispatch_engine.duplicate_lot_serial_in_parent
4856 ( p_parent_transaction_temp_id => l_new_temp_id
4857 , x_return_status => l_api_return_status
4858 , x_msg_count => l_msg_count
4859 , x_msg_data => l_msg_data
4860 );
4861 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
4862 IF g_debug = 1 THEN
4863 print_debug('Error status from duplicate_lot_serial_in_parent: '
4864 || l_api_return_status, l_api_name);
4865 END IF;
4866 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
4867 RAISE fnd_api.g_exc_error;
4868 ELSE
4869 RAISE fnd_api.g_exc_unexpected_error;
4870 END IF;
4871 END IF;
4872 END IF; --}
4873
4874 -- Split lot/serial temp table
4875 IF l_parent_line_id IS NULL THEN
4876 l_lot_split_rec(1).transaction_id := l_new_temp_id;
4877 l_lot_split_rec(1).primary_quantity := l_task_new_rec.primary_quantity;
4878
4879 inv_rcv_common_apis.BREAK( p_original_tid => p_mmtt_temp_id
4880 , p_new_transactions_tb => l_lot_split_rec
4881 , p_lot_control_code => l_lot_control_code
4882 , p_serial_control_code => l_serial_number_control_code
4883 );
4884 END IF;
4885 END LOOP; --}
4886
4887 IF l_init_qty <= l_split_factor AND l_split_executed THEN --{
4888 IF g_debug = 1 THEN
4889 print_debug('Update original MMTT row with remaining qty: '
4890 || l_init_qty, l_api_name);
4891 END IF;
4892
4893 UPDATE mtl_material_transactions_temp
4894 SET transaction_quantity = l_init_qty
4895 , primary_quantity = l_init_qty * l_txn_pri_uom_ratio
4896 , secondary_transaction_quantity
4897 = DECODE( secondary_uom_code
4898 , NULL, NULL
4899 , l_init_qty * l_txn_sec_uom_ratio
4900 )
4901 WHERE transaction_temp_id = p_mmtt_temp_id;
4902
4903 IF p_mmtt_temp_id = l_parent_line_id THEN --{
4904 -- Copy the lot and serial to the parents
4905 l_api_return_status := fnd_api.g_ret_sts_success;
4906 wms_task_dispatch_engine.duplicate_lot_serial_in_parent
4907 ( p_parent_transaction_temp_id => p_mmtt_temp_id
4908 , x_return_status => x_return_status
4909 , x_msg_count => l_msg_count
4910 , x_msg_data => l_msg_data
4911 );
4912 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
4913 IF g_debug = 1 THEN
4914 print_debug('Error status from duplicate_lot_serial_in_parent: '
4915 || l_api_return_status, l_api_name);
4916 END IF;
4917 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
4918 RAISE fnd_api.g_exc_error;
4919 ELSE
4920 RAISE fnd_api.g_exc_unexpected_error;
4921 END IF;
4922 END IF;
4923 END IF; --}
4924 END IF; --}
4925
4926 IF c_eqp_capacity%ISOPEN THEN
4927 CLOSE c_eqp_capacity;
4928 END IF;
4929
4930 IF c_child_tasks%ISOPEN THEN
4931 CLOSE c_child_tasks;
4932 END IF;
4933
4934 COMMIT;
4935
4936 EXCEPTION
4937 WHEN fnd_api.g_exc_error THEN
4938 x_return_status := fnd_api.g_ret_sts_error;
4939 IF l_savepoint_exists THEN
4940 ROLLBACK TO split_task_sp;
4941 END IF;
4942 fnd_msg_pub.count_and_get
4943 ( p_count => l_msg_count
4944 , p_data => l_msg_data
4945 , p_encoded => fnd_api.g_false
4946 );
4947 IF g_debug = 1 THEN
4948 print_debug (l_msg_data, l_api_name);
4949 END IF;
4950 IF c_eqp_capacity%ISOPEN THEN
4951 CLOSE c_eqp_capacity;
4952 END IF;
4953
4954 IF c_child_tasks%ISOPEN THEN
4955 CLOSE c_child_tasks;
4956 END IF;
4957
4958 WHEN OTHERS THEN
4959 x_return_status := fnd_api.g_ret_sts_unexp_error;
4960 IF l_savepoint_exists THEN
4961 ROLLBACK TO split_task_sp;
4962 END IF;
4963 IF g_debug = 1 THEN
4964 print_debug ('Other error: ' || SQLERRM, l_api_name);
4965 END IF;
4966 IF c_eqp_capacity%ISOPEN THEN
4967 CLOSE c_eqp_capacity;
4968 END IF;
4969
4970 IF c_child_tasks%ISOPEN THEN
4971 CLOSE c_child_tasks;
4972 END IF;
4973
4974 END split_one_task;
4975
4976
4977
4978 PROCEDURE split_tasks
4979 ( p_batch_id IN NUMBER
4980 , x_return_status OUT NOCOPY VARCHAR2
4981 ) IS
4982
4983 l_api_name VARCHAR2(30) := 'split_tasks';
4984 l_msg_count NUMBER;
4985 l_msg_data VARCHAR2(2000);
4986
4987 l_mmtt_temp_id tbl_num;
4988 l_api_return_status VARCHAR2(1);
4989 l_wpr_rec wms_pr_workers%ROWTYPE;
4990
4991 CURSOR c_split_tasks (p_txn_batch_id NUMBER) IS
4992 SELECT transaction_temp_id
4993 FROM mtl_material_transactions_temp
4994 WHERE transaction_batch_id = p_txn_batch_id
4995 AND standard_operation_id IS NOT NULL; -- skip rows without task types
4996
4997 BEGIN
4998 x_return_status := fnd_api.g_ret_sts_success;
4999
5000 IF g_debug = 1 THEN
5001 print_debug( 'Entered with parameters: ' || g_newline ||
5002 'p_batch_id => ' || p_batch_id
5003 , l_api_name);
5004 END IF;
5005
5006 LOOP --{
5007 l_api_return_status := fnd_api.g_ret_sts_success;
5008 fetch_next_wpr_rec
5009 ( p_batch_id => p_batch_id
5010 , p_mode => 'TSPLIT'
5011 , x_wpr_rec => l_wpr_rec
5012 , x_return_status => l_api_return_status
5013 );
5014
5015 IF l_api_return_status = 'N' THEN
5016 IF g_debug = 1 THEN
5017 print_debug('No more records in WPR', l_api_name);
5018 END IF;
5019 EXIT;
5020 ELSIF l_api_return_status <> fnd_api.g_ret_sts_success THEN
5021 IF g_debug = 1 THEN
5022 print_debug('Error status from fetch_next_wpr_rec: '
5023 || l_api_return_status, l_api_name);
5024 END IF;
5025 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
5026 RAISE fnd_api.g_exc_error;
5027 ELSE
5028 RAISE fnd_api.g_exc_unexpected_error;
5029 END IF;
5030 END IF;
5031
5032 OPEN c_split_tasks (l_wpr_rec.transaction_batch_id);
5033 LOOP --{
5034 FETCH c_split_tasks BULK COLLECT
5035 INTO l_mmtt_temp_id LIMIT g_bulk_fetch_limit;
5036
5037 EXIT WHEN l_mmtt_temp_id.COUNT = 0;
5038
5039 FOR ii IN l_mmtt_temp_id.FIRST .. l_mmtt_temp_id.LAST
5040 LOOP --{
5041 l_api_return_status := fnd_api.g_ret_sts_success;
5042 WMS_POSTALLOC_PVT.split_one_task
5043 ( p_mmtt_temp_id => l_mmtt_temp_id(ii)
5044 , x_return_status => l_api_return_status
5045 );
5046
5047 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
5048 IF g_debug = 1 THEN
5049 print_debug('Error status from split_one_task: '
5050 || l_api_return_status, l_api_name);
5051 END IF;
5052 -- Ignore errors, continue to next task
5053 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
5054 NULL;
5055 -- RAISE fnd_api.g_exc_error;
5056 ELSE
5057 NULL;
5058 -- RAISE fnd_api.g_exc_unexpected_error;
5059 END IF;
5060 END IF;
5061
5062 END LOOP; --}
5063 END LOOP; --}
5064
5065 IF c_split_tasks%ISOPEN THEN --{
5066 CLOSE c_split_tasks;
5067 END IF; --}
5068
5069 END LOOP; --}
5070
5071 EXCEPTION
5072 WHEN fnd_api.g_exc_error THEN
5073 x_return_status := fnd_api.g_ret_sts_error;
5074 fnd_msg_pub.count_and_get
5075 ( p_count => l_msg_count
5076 , p_data => l_msg_data
5077 , p_encoded => fnd_api.g_false
5078 );
5079 IF g_debug = 1 THEN
5080 print_debug (l_msg_data, l_api_name);
5081 END IF;
5082 IF c_split_tasks%ISOPEN THEN
5083 CLOSE c_split_tasks;
5084 END IF;
5085
5086 WHEN OTHERS THEN
5087 x_return_status := fnd_api.g_ret_sts_unexp_error;
5088 IF g_debug = 1 THEN
5089 print_debug ('Other error: ' || sqlerrm, l_api_name);
5090 END IF;
5091 IF c_split_tasks%ISOPEN THEN
5092 CLOSE c_split_tasks;
5093 END IF;
5094
5095 END split_tasks;
5096
5097
5098
5099 PROCEDURE assign_ttype
5100 ( p_transaction_batch_id IN NUMBER
5101 , p_organization_id IN NUMBER
5102 , x_return_status OUT NOCOPY VARCHAR2
5103 ) IS
5104
5105 l_api_name VARCHAR2(30) := 'assign_ttype';
5106 l_msg_count NUMBER;
5107 l_msg_data VARCHAR2(2000);
5108
5109 l_api_return_status VARCHAR2(1);
5110 l_return_status NUMBER;
5111 l_task_type_id NUMBER;
5112 l_rule_applied BOOLEAN;
5113
5114 l_mmtt_temp_id tbl_num;
5115 l_mmtt_hid tbl_num;
5116
5117 CURSOR c_mmtt_cursor (p_batch_id NUMBER) IS
5118 SELECT transaction_temp_id
5119 FROM mtl_material_transactions_temp
5120 WHERE transaction_batch_id = p_batch_id;
5121
5122 BEGIN
5123 -- Initialize API return status to success
5124 x_return_status := fnd_api.g_ret_sts_success;
5125
5126 IF g_debug = 1 THEN
5127 print_debug( 'Entered with parameters: ' || g_newline ||
5128 'p_transaction_batch_id => ' || p_transaction_batch_id || g_newline ||
5129 'p_organization_id => ' || p_organization_id || g_newline
5130 , l_api_name);
5131 END IF;
5132
5133 -- Bulk fetch applicable rule IDs (only if first time or org changed)
5134 IF g_tta_org_id <> p_organization_id THEN
5135 g_tta_org_id := p_organization_id;
5136 BEGIN
5137 SELECT rules.rule_id, rules.type_hdr_id BULK COLLECT
5138 INTO g_t_tta_rule_id, g_t_tta_type_hdr_id
5139 FROM wms_rules_b rules
5140 , bom_standard_operations bso
5141 WHERE rules.organization_id IN (g_tta_org_id,-1)
5142 AND rules.type_code = 3
5143 AND rules.enabled_flag = 'Y'
5144 AND rules.type_hdr_id = bso.standard_operation_id
5145 AND bso.organization_id = g_tta_org_id
5146 AND bso.wms_task_type = 1
5147 ORDER BY rules.rule_weight DESC, rules.creation_date;
5148
5149 g_tta_rule_exists := TRUE;
5150 EXCEPTION
5151 WHEN NO_DATA_FOUND THEN
5152 g_tta_rule_exists := FALSE;
5153 END ;
5154 END IF;
5155
5156 -- If there is at least one task type rule enabled
5157 IF g_tta_rule_exists THEN --{
5158 OPEN c_mmtt_cursor(p_transaction_batch_id);
5159
5160 LOOP --{
5161 FETCH c_mmtt_cursor BULK COLLECT
5162 INTO l_mmtt_temp_id LIMIT g_bulk_fetch_limit;
5163 EXIT WHEN l_mmtt_temp_id.COUNT = 0;
5164
5165 FOR ii IN l_mmtt_temp_id.FIRST .. l_mmtt_temp_id.LAST LOOP --{
5166 l_rule_applied := FALSE;
5167
5168 FOR jj IN g_t_tta_rule_id.FIRST .. g_t_tta_rule_id.LAST LOOP --{
5169 wms_rule_pvt.execute_task_rule( g_t_tta_rule_id(jj), l_mmtt_temp_id(ii), l_return_status);
5170
5171 IF l_return_status > 0 THEN
5172 l_mmtt_hid(ii) := g_t_tta_type_hdr_id(jj);
5173 l_rule_applied := TRUE;
5174 EXIT;
5175 END IF;
5176 END LOOP; --}
5177
5178 -- If no Task type rule gets applied,
5179 -- stamp the org default task type
5180 IF ( l_rule_applied <> TRUE ) THEN
5181 IF ( inv_cache.set_org_rec( p_organization_id ) ) THEN
5182 l_mmtt_hid(ii) := inv_cache.org_rec.default_pick_task_type_id;
5183 ELSE
5184 IF g_debug = 1 THEN
5185 print_debug ( 'Error setting cache for organization', l_api_name );
5186 END IF;
5187 RAISE fnd_api.g_exc_unexpected_error;
5188 END IF;
5189 END IF ;
5190
5191 IF g_debug = 1 THEN
5192 print_debug('Temp ID: ' || l_mmtt_temp_id(ii) || ', task type assigned: '
5193 || l_mmtt_hid(ii), l_api_name);
5194 END IF;
5195 END LOOP; --}
5196
5197 -- Bulk update task_type_id in all the MMTTs with cached values
5198 FORALL kk IN l_mmtt_temp_id.FIRST .. l_mmtt_temp_id.LAST
5199 UPDATE mtl_material_transactions_temp
5200 SET standard_operation_id = l_mmtt_hid(kk)
5201 WHERE transaction_temp_id = l_mmtt_temp_id(kk);
5202 END LOOP; --}
5203
5204 IF c_mmtt_cursor%ISOPEN THEN
5205 CLOSE c_mmtt_cursor;
5206 END IF;
5207 --}
5208 ELSE --{
5209 -- If there is no task type rule enabled,
5210 -- stamp the org default task type
5211 IF (inv_cache.set_org_rec(p_organization_id) ) THEN
5212 l_task_type_id := inv_cache.org_rec.default_pick_task_type_id;
5213 ELSE
5214 IF g_debug = 1 THEN
5215 print_debug('Error setting cache for organization', l_api_name);
5216 END IF;
5217 RAISE fnd_api.g_exc_unexpected_error;
5218 END IF;
5219
5220 IF g_debug = 1 THEN
5221 print_debug('l_task_type_id value: ' || l_task_type_id, l_api_name);
5222 END IF;
5223
5224 UPDATE mtl_material_transactions_temp
5225 SET standard_operation_id = l_task_type_id
5226 WHERE transaction_batch_id = p_transaction_batch_id;
5227 END IF; --}
5228
5229 UPDATE wms_pr_workers
5230 SET worker_mode = 'TSPLIT', processed_flag = 'N'
5231 WHERE transaction_batch_id = p_transaction_batch_id;
5232
5233 COMMIT;
5234
5235 EXCEPTION
5236 WHEN fnd_api.g_exc_error THEN
5237 x_return_status := fnd_api.g_ret_sts_error;
5238 fnd_msg_pub.count_and_get
5239 ( p_count => l_msg_count
5240 , p_data => l_msg_data
5241 , p_encoded => fnd_api.g_false
5242 );
5243 IF g_debug = 1 THEN
5244 print_debug (l_msg_data, l_api_name);
5245 END IF;
5246 IF c_mmtt_cursor%ISOPEN THEN
5247 CLOSE c_mmtt_cursor;
5248 END IF;
5249
5250 WHEN OTHERS THEN
5251 x_return_status := fnd_api.g_ret_sts_unexp_error;
5252 IF g_debug = 1 THEN
5253 print_debug ('Other error: ' || SQLERRM, l_api_name);
5254 END IF;
5255 IF c_mmtt_cursor%ISOPEN THEN
5256 CLOSE c_mmtt_cursor;
5257 END IF;
5258
5259 END assign_ttype;
5260
5261
5262
5263 PROCEDURE assign_task_types
5264 ( p_batch_id IN NUMBER
5265 , x_return_status OUT NOCOPY VARCHAR2
5266 ) IS
5267 l_api_name VARCHAR2(30) := 'assign_task_types';
5268 l_msg_count NUMBER;
5269 l_msg_data VARCHAR2(2000);
5270
5271 l_api_return_status VARCHAR2(1);
5272 l_wpr_rec wms_pr_workers%ROWTYPE;
5273 l_tta_done BOOLEAN;
5274
5275 BEGIN
5276 x_return_status := fnd_api.g_ret_sts_success;
5277
5278 IF g_debug = 1 THEN
5279 print_debug( 'Entered with parameters: ' || g_newline ||
5280 'p_batch_id => ' || p_batch_id
5281 , l_api_name);
5282 END IF;
5283
5284 l_tta_done := FALSE;
5285 LOOP --{
5286 l_api_return_status := fnd_api.g_ret_sts_success;
5287 fetch_next_wpr_rec
5288 ( p_batch_id => p_batch_id
5289 , p_mode => 'TTA'
5290 , x_wpr_rec => l_wpr_rec
5291 , x_return_status => l_api_return_status
5292 );
5293
5294 IF l_api_return_status = 'N' THEN
5295 IF g_debug = 1 THEN
5296 print_debug('No more records in WPR', l_api_name);
5297 END IF;
5298 l_tta_done := TRUE;
5299 EXIT;
5300 ELSIF l_api_return_status <> fnd_api.g_ret_sts_success THEN
5301 IF g_debug = 1 THEN
5302 print_debug('Error status from fetch_next_wpr_rec: '
5303 || l_api_return_status, l_api_name);
5304 END IF;
5305 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
5306 RAISE fnd_api.g_exc_error;
5307 ELSE
5308 RAISE fnd_api.g_exc_unexpected_error;
5309 END IF;
5310 END IF;
5311
5312 l_api_return_status := fnd_api.g_ret_sts_success;
5313 assign_ttype
5314 ( p_transaction_batch_id => l_wpr_rec.transaction_batch_id
5315 , p_organization_id => l_wpr_rec.organization_id
5316 , x_return_status => l_api_return_status
5317 );
5318
5319 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
5320 IF g_debug = 1 THEN
5321 print_debug('Error status from assign_ttype: '
5322 || l_api_return_status, l_api_name);
5323 END IF;
5324 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
5325 RAISE fnd_api.g_exc_error;
5326 ELSE
5327 RAISE fnd_api.g_exc_unexpected_error;
5328 END IF;
5329 END IF;
5330 END LOOP; --}
5331
5332 IF l_tta_done THEN --{
5333 l_api_return_status := fnd_api.g_ret_sts_success;
5334 split_tasks
5335 ( p_batch_id => p_batch_id
5336 , x_return_status => l_api_return_status
5337 );
5338 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
5339 IF g_debug = 1 THEN
5340 print_debug('Error status from split_tasks: '
5341 || l_api_return_status, l_api_name);
5342 END IF;
5343 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
5344 RAISE fnd_api.g_exc_error;
5345 ELSE
5346 RAISE fnd_api.g_exc_unexpected_error;
5347 END IF;
5348 END IF;
5349 END IF; --}
5350
5351 EXCEPTION
5352 WHEN fnd_api.g_exc_error THEN
5353 x_return_status := fnd_api.g_ret_sts_error;
5354 fnd_msg_pub.count_and_get
5355 ( p_count => l_msg_count
5356 , p_data => l_msg_data
5357 , p_encoded => fnd_api.g_false
5358 );
5359 IF g_debug = 1 THEN
5360 print_debug (l_msg_data, l_api_name);
5361 END IF;
5362
5363 WHEN OTHERS THEN
5364 x_return_status := fnd_api.g_ret_sts_unexp_error;
5365 IF g_debug = 1 THEN
5366 print_debug ('Other error: ' || SQLERRM, l_api_name);
5367 END IF;
5368
5369 END assign_task_types;
5370
5371
5372
5373 FUNCTION get_device_id( p_organization_id IN NUMBER
5374 , p_subinventory_code IN VARCHAR2
5375 , p_locator_id IN NUMBER
5376 ) RETURN NUMBER IS
5377
5378 l_api_name VARCHAR2(30) := 'get_device_id';
5379 l_hash_value NUMBER;
5380 l_hash_string VARCHAR2(2000) := NULL;
5381 l_force_sign_on_flag VARCHAR2(1);
5382 l_ret_dev_id NUMBER;
5383 l_temp_dev_id NUMBER;
5384
5385 BEGIN
5386
5387 -- Concatenate the subinventory, locator, organization and user id string
5388 l_hash_string := TO_CHAR(p_organization_id) || '-'
5389 || p_subinventory_code || '-'
5390 || TO_CHAR(p_locator_id) || '-'
5391 || TO_CHAR(g_user_id);
5392
5393 -- Generate hash value with the concatenated string
5394 l_hash_value := DBMS_UTILITY.get_hash_value
5395 ( name => l_hash_string
5396 , base => g_hash_base
5397 , hash_size => g_hash_size
5398 );
5399 IF g_debug = 1 THEN
5400 print_debug ('Hash string: ' || l_hash_string, l_api_name);
5401 print_debug ('Hash value generated: ' || l_hash_value, l_api_name);
5402 END IF;
5403
5404 -- If the hash value returned exists then take the device_id from the cache
5405 IF g_dev_tbl.EXISTS(l_hash_value) AND
5406 g_org_tbl(l_hash_value) = p_organization_id AND
5407 g_sub_tbl(l_hash_value) = p_subinventory_code AND
5408 g_loc_tbl(l_hash_value) = p_locator_id AND
5409 g_user_tbl(l_hash_value) = g_user_id
5410 THEN
5411 l_ret_dev_id := g_dev_tbl(l_hash_value);
5412 ELSE --{
5413 SELECT device_id
5414 INTO l_ret_dev_id
5415 FROM ( SELECT wbed.device_id
5416 FROM wms_bus_event_devices wbed
5417 , wms_devices_b wd
5418 WHERE wd.device_id = wbed.device_id
5419 AND wbed.organization_id = wd.organization_id
5420 AND wd.ENABLED_FLAG = 'Y'
5421 AND wbed.ENABLED_FLAG = 'Y'
5422 AND DECODE( level_type
5423 , g_device_level_sub, p_subinventory_code
5424 , level_value) = DECODE( level_type
5425 , g_device_level_sub, p_subinventory_code
5426 , g_device_level_org, p_organization_id
5427 , g_device_level_locator, p_locator_id
5428 , g_device_level_user, g_user_id
5429 , level_value
5430 )
5431 AND NVL(wbed.organization_id,-1)
5432 = NVL(p_organization_id,NVL(wbed.organization_id,-1))
5433 AND wbed.auto_enabled_flag = 'Y'
5434 AND wbed.business_event_id = g_wms_be_pick_release
5435 ORDER BY level_type DESC )
5436 WHERE ROWNUM < 2;
5437
5438 --
5439 -- In WMSDEVPB (select_device API), the device ID is set to zero
5440 -- instead of NULL. However, if the devive ID is 0, it does not
5441 -- update the WDR records inserted by WMSCRTNB (insert_device_request_rec
5442 -- API) - instead leaves it as NULL. It also skips inserting of
5443 -- lot/serial records for device ID=0. This behavior is preserved
5444 -- in the new code.
5445 --
5446 IF l_ret_dev_id IS NOT NULL THEN --{
5447 BEGIN
5448 SELECT force_sign_on_flag
5449 INTO l_force_sign_on_flag
5450 FROM wms_devices_b
5451 WHERE device_id = l_ret_dev_id;
5452
5453 IF l_force_sign_on_flag = 'Y' THEN
5454 BEGIN
5455 SELECT device_id
5456 INTO l_temp_dev_id
5457 FROM wms_device_assignment_temp
5458 WHERE device_id = l_ret_dev_id
5459 AND created_by = g_user_id;
5460 EXCEPTION
5461 WHEN NO_DATA_FOUND THEN
5462 l_ret_dev_id := NULL;
5463 END;
5464 END IF;
5465 EXCEPTION
5466 WHEN OTHERS THEN
5467 l_ret_dev_id := NULL;
5468 END;
5469 END IF; --}
5470
5471 -- Cache the device_id
5472 g_org_tbl(l_hash_value) := p_organization_id;
5473 g_sub_tbl(l_hash_value) := p_subinventory_code;
5474 g_loc_tbl(l_hash_value) := p_locator_id;
5475 g_user_tbl(l_hash_value) := g_user_id;
5476 g_dev_tbl(l_hash_value) := l_ret_dev_id;
5477
5478 END IF; --}
5479
5480 IF g_debug = 1 THEN
5481 print_debug ('Returning device ID ' || l_ret_dev_id, l_api_name);
5482 END IF;
5483
5484 RETURN l_ret_dev_id;
5485
5486 EXCEPTION
5487 WHEN OTHERS THEN
5488 IF g_debug = 1 THEN
5489 print_debug ('Other error: ' || SQLERRM, l_api_name);
5490 END IF;
5491 RETURN NULL;
5492 END get_device_id;
5493
5494
5495
5496 PROCEDURE insert_device_requests
5497 ( p_organization_id IN NUMBER
5498 , p_mo_header_id IN NUMBER
5499 , x_return_status OUT NOCOPY VARCHAR2
5500 ) IS
5501 l_api_name VARCHAR2(30) := 'insert_device_requests';
5502 l_msg_count NUMBER;
5503 l_msg_data VARCHAR2(2000);
5504
5505 l_api_return_status VARCHAR2(240);
5506 l_bus_event_id NUMBER;
5507 l_req_msg VARCHAR2(255);
5508
5509 t_transaction_temp_id tbl_num;
5510 t_organization_id tbl_num;
5511 t_subinventory_code tbl_varchar10;
5512 t_locator_id tbl_num;
5513 t_transfer_organization tbl_num;
5514 t_inventory_item_id tbl_num;
5515 t_revision tbl_varchar3;
5516 t_transaction_uom tbl_varchar3;
5517 t_allocated_lpn_id tbl_num;
5518 t_cartonization_id tbl_num;
5519 t_transaction_quantity tbl_num;
5520 t_dev_id tbl_num;
5521 t_lot_serial_capable_flag tbl_varchar1;
5522 t_transfer_subinventory tbl_varchar10;
5523 t_transfer_to_location tbl_num;
5524 t_last_update_date tbl_date;
5525 t_last_updated_by tbl_num;
5526 t_last_update_login tbl_num;
5527
5528 -- Cursor for non-bulk task records
5529 CURSOR c_non_bulk_tasks (p_mo_hdr_id IN NUMBER) IS
5530 SELECT x.transaction_temp_id
5531 , x.organization_id
5532 , x.subinventory_code
5533 , x.locator_id
5534 , x.transfer_organization
5535 , x.inventory_item_id
5536 , x.revision
5537 , x.transaction_uom
5538 , x.allocated_lpn_id
5539 , x.cartonization_id
5540 , x.transaction_quantity
5541 , x.transfer_subinventory
5542 , x.transfer_to_location
5543 , x.last_update_date
5544 , x.last_updated_by
5545 , x.last_update_login
5546 , x.dev_id
5547 , NVL(dev.lot_serial_capable,'N') lot_serial_capable_flag
5548 FROM ( SELECT mmtt.transaction_temp_id
5549 , mmtt.organization_id
5550 , mmtt.subinventory_code
5551 , mmtt.locator_id
5552 , mmtt.transfer_organization
5553 , mmtt.inventory_item_id
5554 , mmtt.revision
5555 , mmtt.transaction_uom
5556 , mmtt.allocated_lpn_id
5557 , mmtt.cartonization_id
5558 , mmtt.transaction_quantity
5559 , mmtt.transfer_subinventory
5560 , mmtt.transfer_to_location
5561 , mmtt.last_update_date
5562 , mmtt.last_updated_by
5563 , mmtt.last_update_login
5564 , get_device_id( mmtt.organization_id
5565 , mmtt.subinventory_code
5566 , mmtt.locator_id
5567 ) dev_id
5568 FROM mtl_material_transactions_temp mmtt
5569 WHERE mmtt.move_order_header_id = p_mo_hdr_id
5570 AND mmtt.parent_line_id IS NULL
5571 ) x
5572 , wms_devices_b dev
5573 WHERE x.dev_id = dev.device_id(+);
5574
5575 -- Cursor for child task records
5576 CURSOR c_child_tasks (p_mo_hdr_id IN NUMBER) IS
5577 SELECT transaction_temp_id
5578 , organization_id
5579 , subinventory_code
5580 , locator_id
5581 , transfer_organization
5582 , inventory_item_id
5583 , revision
5584 , transaction_uom
5585 , allocated_lpn_id
5586 , cartonization_id
5587 , transaction_quantity
5588 , transfer_subinventory
5589 , transfer_to_location
5590 , last_update_date
5591 , last_updated_by
5592 , last_update_login
5593 , get_device_id( mmtt.organization_id
5594 , mmtt.subinventory_code
5595 , mmtt.locator_id
5596 ) dev_id
5597 FROM mtl_material_transactions_temp mmtt
5598 WHERE mmtt.move_order_header_id = p_mo_hdr_id
5599 AND mmtt.parent_line_id IS NOT NULL;
5600
5601 -- Cursor for parent task records
5602 CURSOR c_parent_tasks (p_mo_hdr_id IN NUMBER) IS
5603 SELECT x.transaction_temp_id
5604 , x.organization_id
5605 , x.subinventory_code
5606 , x.locator_id
5607 , x.transfer_organization
5608 , x.inventory_item_id
5609 , x.revision
5610 , x.transaction_uom
5611 , x.allocated_lpn_id
5612 , x.cartonization_id
5613 , x.transaction_quantity
5614 , x.transfer_subinventory
5615 , x.transfer_to_location
5616 , x.last_update_date
5617 , x.last_updated_by
5618 , x.last_update_login
5619 , x.dev_id
5620 , NVL(dev.lot_serial_capable,'N') lot_serial_capable_flag
5621 FROM ( SELECT mmtt.transaction_temp_id
5622 , mmtt.organization_id
5623 , mmtt.subinventory_code
5624 , mmtt.locator_id
5625 , mmtt.transfer_organization
5626 , mmtt.inventory_item_id
5627 , mmtt.revision
5628 , mmtt.transaction_uom
5629 , mmtt.allocated_lpn_id
5630 , mmtt.cartonization_id
5631 , mmtt.transaction_quantity
5632 , mmtt.transfer_subinventory
5633 , mmtt.transfer_to_location
5634 , mmtt.last_update_date
5635 , mmtt.last_updated_by
5636 , mmtt.last_update_login
5637 , get_device_id( mmtt.organization_id
5638 , mmtt.subinventory_code
5639 , mmtt.locator_id
5640 ) dev_id
5641 FROM mtl_material_transactions_temp mmtt
5642 WHERE mmtt.transaction_temp_id IN
5643 ( SELECT DISTINCT parent_line_id
5644 FROM mtl_material_transactions_temp mmtt1
5645 WHERE mmtt1.move_order_header_id = p_mo_hdr_id
5646 AND mmtt1.parent_line_id IS NOT NULL
5647 )
5648 ) x,
5649 wms_devices_b dev
5650 WHERE x.dev_id = dev.device_id(+);
5651
5652 BEGIN
5653 x_return_status := fnd_api.g_ret_sts_success;
5654
5655 IF g_debug = 1 THEN
5656 print_debug( 'Entered with parameters: ' || g_newline ||
5657 'p_organization_id => ' || TO_CHAR(p_organization_id) || g_newline ||
5658 'p_mo_header_id => ' || TO_CHAR(p_mo_header_id)
5659 , l_api_name);
5660 END IF;
5661
5662 l_api_return_status := fnd_api.g_ret_sts_success;
5663 wms_device_integration_pvt.is_device_set_up
5664 ( p_org_id => p_organization_id
5665 , p_bus_event_id => 11
5666 , x_return_status => l_api_return_status
5667 );
5668 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
5669 IF g_debug = 1 THEN
5670 print_debug('Error status from is_device_set_up API: '
5671 || l_api_return_status, l_api_name);
5672 END IF;
5673 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
5674 RAISE fnd_api.g_exc_error;
5675 ELSE
5676 RAISE fnd_api.g_exc_unexpected_error;
5677 END IF;
5678 END IF;
5679
5680 IF g_debug = 1 THEN
5681 print_debug( 'Value of wms_call_device_request: '
5682 || wms_device_integration_pvt.wms_call_device_request
5683 , l_api_name);
5684 END IF;
5685
5686 IF wms_device_integration_pvt.wms_call_device_request = 1 THEN
5687 l_bus_event_id := wms_device_integration_pvt.wms_be_pick_release;
5688 ELSE
5689 RETURN;
5690 END IF;
5691
5692 -- BULK fetch the MMTT records for non-bulk tasks
5693 OPEN c_non_bulk_tasks( p_mo_header_id );
5694
5695 LOOP --{
5696 FETCH c_non_bulk_tasks BULK COLLECT INTO t_transaction_temp_id
5697 , t_organization_id
5698 , t_subinventory_code
5699 , t_locator_id
5700 , t_transfer_organization
5701 , t_inventory_item_id
5702 , t_revision
5703 , t_transaction_uom
5704 , t_allocated_lpn_id
5705 , t_cartonization_id
5706 , t_transaction_quantity
5707 , t_transfer_subinventory
5708 , t_transfer_to_location
5709 , t_last_update_date
5710 , t_last_updated_by
5711 , t_last_update_login
5712 , t_dev_id
5713 , t_lot_serial_capable_flag LIMIT g_bulk_fetch_limit;
5714 EXIT WHEN t_transaction_temp_id.COUNT = 0;
5715
5716 -- BULK INSERT the records in WDR (for LOAD)
5717 FORALL ii IN t_transaction_temp_id.FIRST .. t_transaction_temp_id.LAST
5718 INSERT INTO wms_device_requests( request_id
5719 , task_id
5720 , task_summary
5721 , task_type_id
5722 , business_event_id
5723 , organization_id
5724 , subinventory_code
5725 , locator_id
5726 , transfer_org_id
5727 , transfer_sub_code
5728 , transfer_loc_id
5729 , inventory_item_id
5730 , revision
5731 , uom
5732 , lpn_id
5733 , xfer_lpn_id
5734 , transaction_quantity
5735 , last_update_date
5736 , last_updated_by
5737 , device_id )
5738 VALUES( wms_device_integration_pvt.wms_pkRel_dev_req_id --global var same for all pick release lines
5739 , t_transaction_temp_id(ii)
5740 , 'Y'
5741 , 1 --"LOAD"
5742 , l_bus_event_id
5743 , t_organization_id(ii)
5744 , t_subinventory_code(ii)
5745 , t_locator_id(ii)
5746 , t_transfer_organization(ii)
5747 , NULL
5748 , NULL
5749 , t_inventory_item_id(ii)
5750 , t_revision(ii)
5751 , t_transaction_uom(ii)
5752 , t_allocated_lpn_id(ii)
5753 , t_cartonization_id(ii)
5754 , t_transaction_quantity(ii)
5755 , SYSDATE
5756 , g_user_id
5757 , t_dev_id(ii) );
5758
5759 -- BULK INSERT the records in WDR (for DROP)
5760 FORALL jj IN t_transaction_temp_id.FIRST .. t_transaction_temp_id.LAST
5761 INSERT INTO wms_device_requests( request_id
5762 , task_id
5763 , task_summary
5764 , task_type_id
5765 , business_event_id
5766 , organization_id
5767 , subinventory_code
5768 , locator_id
5769 , transfer_org_id
5770 , transfer_sub_code
5771 , transfer_loc_id
5772 , inventory_item_id
5773 , revision
5774 , uom
5775 , lpn_id
5776 , xfer_lpn_id
5777 , transaction_quantity
5778 , last_update_date
5779 , last_updated_by
5780 , device_id )
5781 VALUES( wms_device_integration_pvt.wms_pkRel_dev_req_id
5782 , t_transaction_temp_id(jj)
5783 , 'Y'
5784 , 2 --"DROP"
5785 , l_bus_event_id
5786 , t_organization_id(jj)
5787 , NULL
5788 , NULL
5789 , t_transfer_organization(jj)
5790 , t_transfer_subinventory(jj)
5791 , t_transfer_to_location(jj)
5792 , t_inventory_item_id(jj)
5793 , t_revision(jj)
5794 , t_transaction_uom(jj)
5795 , t_allocated_lpn_id(jj)
5796 , t_cartonization_id(jj)
5797 , t_transaction_quantity(jj)
5798 , SYSDATE
5799 , g_user_id
5800 , t_dev_id(jj) );
5801
5802 --BULK INSERT lot/serial WDR record
5803 FORALL kk IN t_transaction_temp_id.FIRST .. t_transaction_temp_id.LAST
5804 INSERT INTO wms_device_requests( request_id
5805 , task_id
5806 , relation_id
5807 , sequence_id
5808 , task_summary
5809 , task_type_id
5810 , business_event_id
5811 , organization_id
5812 , subinventory_code
5813 , locator_id
5814 , transfer_org_id
5815 , transfer_sub_code
5816 , transfer_loc_id
5817 , inventory_item_id
5818 , revision
5819 , uom
5820 , lot_number
5821 , lot_qty
5822 , serial_number
5823 , lpn_id
5824 , xfer_lpn_id
5825 , transaction_quantity
5826 , device_id
5827 , status_code
5828 , last_update_date
5829 , last_updated_by
5830 , last_update_login )
5831 ( SELECT wms_device_integration_pvt.wms_pkRel_dev_req_id
5832 , t_transaction_temp_id(kk)
5833 , NULL
5834 , NULL
5835 , 'N'
5836 , NULL
5837 , l_bus_event_id
5838 , t_organization_id(kk)
5839 , t_subinventory_code(kk)
5840 , t_locator_id(kk)
5841 , t_transfer_organization(kk)
5842 , t_transfer_subinventory(kk)
5843 , t_transfer_to_location(kk)
5844 , t_inventory_item_id(kk)
5845 , t_revision(kk)
5846 , t_transaction_uom(kk)
5847 , mtlt.lot_number
5848 , mtlt.transaction_quantity
5849 , NULL
5850 , t_allocated_lpn_id(kk)
5851 , t_cartonization_id(kk)
5852 , mtlt.transaction_quantity
5853 , t_dev_id(kk)
5854 , 'S'
5855 , t_last_update_date(kk)
5856 , t_last_updated_by(kk)
5857 , t_last_update_login(kk)
5858 FROM mtl_transaction_lots_temp mtlt
5859 WHERE mtlt.transaction_temp_id = t_transaction_temp_id(kk)
5860 AND t_dev_id(kk) IS NOT NULL
5861 AND t_lot_serial_capable_flag(kk) <> 'N'
5862 AND mtlt.serial_transaction_temp_id IS NULL
5863 UNION ALL
5864 SELECT wms_device_integration_pvt.wms_pkRel_dev_req_id
5865 , t_transaction_temp_id(kk)
5866 , NULL
5867 , NULL
5868 , 'N'
5869 , NULL
5870 , l_bus_event_id
5871 , t_organization_id(kk)
5872 , t_subinventory_code(kk)
5873 , t_locator_id(kk)
5874 , t_transfer_organization(kk)
5875 , t_transfer_subinventory(kk)
5876 , t_transfer_to_location(kk)
5877 , t_inventory_item_id(kk)
5878 , t_revision(kk)
5879 , t_transaction_uom(kk)
5880 , NULL
5881 , NULL
5882 , msnt.fm_serial_number
5883 , t_allocated_lpn_id(kk)
5884 , t_cartonization_id(kk)
5885 , 1
5886 , t_dev_id(kk)
5887 , 'S'
5888 , t_last_update_date(kk)
5889 , t_last_updated_by(kk)
5890 , t_last_update_login(kk)
5891 FROM mtl_serial_numbers_temp msnt
5892 WHERE msnt.transaction_temp_id = t_transaction_temp_id(kk)
5893 AND t_dev_id(kk) IS NOT NULL
5894 AND t_lot_serial_capable_flag(kk) <> 'N'
5895 UNION ALL
5896 SELECT wms_device_integration_pvt.wms_pkRel_dev_req_id
5897 , t_transaction_temp_id(kk)
5898 , NULL
5899 , NULL
5900 , 'N'
5901 , NULL
5902 , l_bus_event_id
5903 , t_organization_id(kk)
5904 , t_subinventory_code(kk)
5905 , t_locator_id(kk)
5906 , t_transfer_organization(kk)
5907 , t_transfer_subinventory(kk)
5908 , t_transfer_to_location(kk)
5909 , t_inventory_item_id(kk)
5910 , t_revision(kk)
5911 , t_transaction_uom(kk)
5912 , mtlt.lot_number
5913 , mtlt.transaction_quantity
5914 , msnt.fm_serial_number
5915 , t_allocated_lpn_id(kk)
5916 , t_cartonization_id(kk)
5917 , 1
5918 , t_dev_id(kk)
5919 , 'S'
5920 , t_last_update_date(kk)
5921 , t_last_updated_by(kk)
5922 , t_last_update_login(kk)
5923 FROM mtl_transaction_lots_temp mtlt, mtl_serial_numbers_temp msnt
5924 WHERE mtlt.transaction_temp_id = t_transaction_temp_id(kk)
5925 AND mtlt.serial_transaction_temp_id = msnt.transaction_temp_id
5926 AND t_dev_id(kk) IS NOT NULL
5927 AND t_lot_serial_capable_flag(kk) <> 'N' );
5928 END LOOP; --}
5929
5930 IF c_non_bulk_tasks%ISOPEN THEN
5931 CLOSE c_non_bulk_tasks;
5932 END IF;
5933
5934 IF g_debug = 1 THEN
5935 print_debug ('Done processing non-bulk tasks.', l_api_name);
5936 END IF;
5937
5938 COMMIT;
5939
5940 -- Delete the temp tables
5941 t_transaction_temp_id.DELETE;
5942 t_organization_id.DELETE;
5943 t_subinventory_code.DELETE;
5944 t_locator_id.DELETE;
5945 t_transfer_organization.DELETE;
5946 t_inventory_item_id.DELETE;
5947 t_revision.DELETE;
5948 t_transaction_uom.DELETE;
5949 t_allocated_lpn_id.DELETE;
5950 t_cartonization_id.DELETE;
5951 t_transaction_quantity.DELETE;
5952 t_dev_id.DELETE;
5953 t_lot_serial_capable_flag.DELETE;
5954 t_transfer_subinventory.DELETE;
5955 t_transfer_to_location.DELETE;
5956 t_last_update_date.DELETE;
5957 t_last_updated_by.DELETE;
5958 t_last_update_login.DELETE;
5959
5960 -- BULK fetch the MMTT records for child tasks
5961 OPEN c_child_tasks( p_mo_header_id );
5962
5963 LOOP --{
5964 FETCH c_child_tasks BULK COLLECT INTO t_transaction_temp_id
5965 , t_organization_id
5966 , t_subinventory_code
5967 , t_locator_id
5968 , t_transfer_organization
5969 , t_inventory_item_id
5970 , t_revision
5971 , t_transaction_uom
5972 , t_allocated_lpn_id
5973 , t_cartonization_id
5974 , t_transaction_quantity
5975 , t_transfer_subinventory
5976 , t_transfer_to_location
5977 , t_last_update_date
5978 , t_last_updated_by
5979 , t_last_update_login
5980 , t_dev_id LIMIT g_bulk_fetch_limit;
5981 EXIT WHEN t_transaction_temp_id.COUNT = 0;
5982
5983 -- BULK INSERT the WDR DROP record for child MMTT records
5984 FORALL ll IN t_transaction_temp_id.FIRST .. t_transaction_temp_id.LAST
5985 INSERT INTO wms_device_requests( request_id
5986 , task_id
5987 , task_summary
5988 , task_type_id
5989 , business_event_id
5990 , organization_id
5991 , subinventory_code
5992 , locator_id
5993 , transfer_org_id
5994 , transfer_sub_code
5995 , transfer_loc_id
5996 , inventory_item_id
5997 , revision
5998 , uom
5999 , lpn_id
6000 , xfer_lpn_id
6001 , transaction_quantity
6002 , last_update_date
6003 , last_updated_by
6004 , device_id )
6005 VALUES( wms_device_integration_pvt.wms_pkRel_dev_req_id
6006 , t_transaction_temp_id(ll)
6007 , 'Y'
6008 , 2 --"DROP"
6009 , l_bus_event_id
6010 , t_organization_id(ll)
6011 , NULL
6012 , NULL
6013 , t_transfer_organization(ll)
6014 , t_transfer_subinventory(ll)
6015 , t_transfer_to_location(ll)
6016 , t_inventory_item_id(ll)
6017 , t_revision(ll)
6018 , t_transaction_uom(ll)
6019 , t_allocated_lpn_id(ll)
6020 , t_cartonization_id(ll)
6021 , t_transaction_quantity(ll)
6022 , SYSDATE
6023 , g_user_id
6024 , t_dev_id(ll) );
6025 END LOOP; --}
6026
6027 IF c_child_tasks%ISOPEN THEN
6028 CLOSE c_child_tasks;
6029 END IF;
6030
6031 IF g_debug = 1 THEN
6032 print_debug ('Done processing bulk-pick child tasks.', l_api_name);
6033 END IF;
6034
6035 COMMIT;
6036
6037 -- Delete the temp tables
6038 t_transaction_temp_id.DELETE;
6039 t_organization_id.DELETE;
6040 t_subinventory_code.DELETE;
6041 t_locator_id.DELETE;
6042 t_transfer_organization.DELETE;
6043 t_inventory_item_id.DELETE;
6044 t_revision.DELETE;
6045 t_transaction_uom.DELETE;
6046 t_allocated_lpn_id.DELETE;
6047 t_cartonization_id.DELETE;
6048 t_transaction_quantity.DELETE;
6049 t_dev_id.DELETE;
6050 t_lot_serial_capable_flag.DELETE;
6051 t_transfer_subinventory.DELETE;
6052 t_transfer_to_location.DELETE;
6053 t_last_update_date.DELETE;
6054 t_last_updated_by.DELETE;
6055 t_last_update_login.DELETE;
6056
6057 -- BULK fetch the MMTT records for parent tasks
6058 OPEN c_parent_tasks( p_mo_header_id );
6059
6060 LOOP --{
6061 FETCH c_parent_tasks BULK COLLECT INTO t_transaction_temp_id
6062 , t_organization_id
6063 , t_subinventory_code
6064 , t_locator_id
6065 , t_transfer_organization
6066 , t_inventory_item_id
6067 , t_revision
6068 , t_transaction_uom
6069 , t_allocated_lpn_id
6070 , t_cartonization_id
6071 , t_transaction_quantity
6072 , t_transfer_subinventory
6073 , t_transfer_to_location
6074 , t_last_update_date
6075 , t_last_updated_by
6076 , t_last_update_login
6077 , t_dev_id
6078 , t_lot_serial_capable_flag LIMIT g_bulk_fetch_limit;
6079 EXIT WHEN t_transaction_temp_id.COUNT = 0;
6080
6081 IF g_debug = 1 THEN
6082 print_debug ('Fetched ' || t_transaction_temp_id.COUNT || ' parent tasks', l_api_name);
6083 END IF;
6084
6085 --BULK INSERT the LOAD records for parent MMTT records
6086 FORALL mm IN t_transaction_temp_id.FIRST .. t_transaction_temp_id.LAST
6087 INSERT INTO wms_device_requests( request_id
6088 , task_id
6089 , task_summary
6090 , task_type_id
6091 , business_event_id
6092 , organization_id
6093 , subinventory_code
6094 , locator_id
6095 , transfer_org_id
6096 , transfer_sub_code
6097 , transfer_loc_id
6098 , inventory_item_id
6099 , revision
6100 , uom
6101 , lpn_id
6102 , xfer_lpn_id
6103 , transaction_quantity
6104 , last_update_date
6105 , last_updated_by
6106 , device_id )
6107 VALUES( wms_device_integration_pvt.wms_pkRel_dev_req_id
6108 , t_transaction_temp_id(mm)
6109 , 'Y'
6110 , 1 --"LOAD"
6111 , l_bus_event_id
6112 , t_organization_id(mm)
6113 , t_subinventory_code(mm)
6114 , t_locator_id(mm)
6115 , t_transfer_organization(mm)
6116 , NULL
6117 , NULL
6118 , t_inventory_item_id(mm)
6119 , t_revision(mm)
6120 , t_transaction_uom(mm)
6121 , t_allocated_lpn_id(mm)
6122 , t_cartonization_id(mm)
6123 , t_transaction_quantity(mm)
6124 , SYSDATE
6125 , g_user_id
6126 , t_dev_id(mm) );
6127
6128 IF g_debug = 1 THEN
6129 print_debug ('Done inserting LOAD records for parent tasks', l_api_name);
6130 END IF;
6131
6132 -- BULK INSERT the lot/serial record for parent MMTT records
6133 FORALL nn IN t_transaction_temp_id.FIRST .. t_transaction_temp_id.LAST
6134 INSERT INTO wms_device_requests( request_id
6135 , task_id
6136 , relation_id
6137 , sequence_id
6138 , task_summary
6139 , task_type_id
6140 , business_event_id
6141 , organization_id
6142 , subinventory_code
6143 , locator_id
6144 , transfer_org_id
6145 , transfer_sub_code
6146 , transfer_loc_id
6147 , inventory_item_id
6148 , revision
6149 , uom
6150 , lot_number
6151 , lot_qty
6152 , serial_number
6153 , lpn_id
6154 , xfer_lpn_id
6155 , transaction_quantity
6156 , device_id
6157 , status_code
6158 , last_update_date
6159 , last_updated_by
6160 , last_update_login )
6161 ( SELECT wms_device_integration_pvt.wms_pkRel_dev_req_id
6162 , t_transaction_temp_id(nn)
6163 , NULL
6164 , NULL
6165 , 'N'
6166 , NULL
6167 , l_bus_event_id
6168 , t_organization_id(nn)
6169 , t_subinventory_code(nn)
6170 , t_locator_id(nn)
6171 , t_transfer_organization(nn)
6172 , t_transfer_subinventory(nn)
6173 , t_transfer_to_location(nn)
6174 , t_inventory_item_id(nn)
6175 , t_revision(nn)
6176 , t_transaction_uom(nn)
6177 , mtlt.lot_number
6178 , mtlt.transaction_quantity
6179 , NULL
6180 , t_allocated_lpn_id(nn)
6181 , t_cartonization_id(nn)
6182 , mtlt.transaction_quantity
6183 , t_dev_id(nn)
6184 , 'S'
6185 , t_last_update_date(nn)
6186 , t_last_updated_by(nn)
6187 , t_last_update_login(nn)
6188 FROM mtl_transaction_lots_temp mtlt
6189 WHERE mtlt.transaction_temp_id = t_transaction_temp_id(nn)
6190 AND t_dev_id(nn) IS NOT NULL
6191 AND t_lot_serial_capable_flag(nn) <> 'N'
6192 AND mtlt.serial_transaction_temp_id IS NULL
6193 UNION ALL
6194 SELECT wms_device_integration_pvt.wms_pkRel_dev_req_id
6195 , t_transaction_temp_id(nn)
6196 , NULL
6197 , NULL
6198 , 'N'
6199 , NULL
6200 , l_bus_event_id
6201 , t_organization_id(nn)
6202 , t_subinventory_code(nn)
6203 , t_locator_id(nn)
6204 , t_transfer_organization(nn)
6205 , t_transfer_subinventory(nn)
6206 , t_transfer_to_location(nn)
6207 , t_inventory_item_id(nn)
6208 , t_revision(nn)
6209 , t_transaction_uom(nn)
6210 , NULL
6211 , NULL
6212 , msnt.fm_serial_number
6213 , t_allocated_lpn_id(nn)
6214 , t_cartonization_id(nn)
6215 , 1
6216 , t_dev_id(nn)
6217 , 'S'
6218 , t_last_update_date(nn)
6219 , t_last_updated_by(nn)
6220 , t_last_update_login(nn)
6221 FROM mtl_serial_numbers_temp msnt
6222 WHERE msnt.transaction_temp_id = t_transaction_temp_id(nn)
6223 AND t_dev_id(nn) IS NOT NULL
6224 AND t_lot_serial_capable_flag(nn) <> 'N'
6225 UNION ALL
6226 SELECT wms_device_integration_pvt.wms_pkRel_dev_req_id
6227 , t_transaction_temp_id(nn)
6228 , NULL
6229 , NULL
6230 , 'N'
6231 , NULL
6232 , l_bus_event_id
6233 , t_organization_id(nn)
6234 , t_subinventory_code(nn)
6235 , t_locator_id(nn)
6236 , t_transfer_organization(nn)
6237 , t_transfer_subinventory(nn)
6238 , t_transfer_to_location(nn)
6239 , t_inventory_item_id(nn)
6240 , t_revision(nn)
6241 , t_transaction_uom(nn)
6242 , mtlt.lot_number
6243 , mtlt.transaction_quantity
6244 , msnt.fm_serial_number
6245 , t_allocated_lpn_id(nn)
6246 , t_cartonization_id(nn)
6247 , 1
6248 , t_dev_id(nn)
6249 , 'S'
6250 , t_last_update_date(nn)
6251 , t_last_updated_by(nn)
6252 , t_last_update_login(nn)
6253 FROM mtl_transaction_lots_temp mtlt, mtl_serial_numbers_temp msnt
6254 WHERE mtlt.transaction_temp_id = t_transaction_temp_id(nn)
6255 AND mtlt.serial_transaction_temp_id = msnt.transaction_temp_id
6256 AND t_dev_id(nn) IS NOT NULL
6257 AND t_lot_serial_capable_flag(nn) <> 'N' );
6258 END LOOP; --}
6259
6260 IF c_parent_tasks%ISOPEN THEN
6261 CLOSE c_parent_tasks;
6262 END IF;
6263
6264 IF g_debug = 1 THEN
6265 print_debug ('Done processing bulk-pick parent tasks.', l_api_name);
6266 END IF;
6267
6268 COMMIT;
6269
6270 l_api_return_status := fnd_api.g_ret_sts_success;
6271 wms_device_integration_pvt.device_request
6272 ( p_bus_event => wms_device_integration_pvt.wms_be_pick_release
6273 , p_call_ctx => wms_device_integration_pvt.dev_req_auto
6274 , p_task_trx_id => p_mo_header_id -- p_organization_id;bug 9130704
6275 , p_org_id => p_organization_id -- p_mo_header_id;bug 9130704
6276 , x_request_msg => l_req_msg
6277 , x_return_status => l_api_return_status
6278 , x_msg_count => l_msg_count
6279 , x_msg_data => l_msg_data
6280 );
6281 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
6282 IF g_debug = 1 THEN
6283 print_debug('Error status from device_request API: '
6284 || l_api_return_status, l_api_name);
6285 END IF;
6286 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
6287 RAISE fnd_api.g_exc_error;
6288 ELSE
6289 RAISE fnd_api.g_exc_unexpected_error;
6290 END IF;
6291 END IF;
6292
6293 IF g_debug = 1 THEN
6294 print_debug('Device request message: '|| l_req_msg, l_api_name);
6295 END IF;
6296
6297 COMMIT;
6298
6299 EXCEPTION
6300 WHEN fnd_api.g_exc_error THEN
6301 x_return_status := fnd_api.g_ret_sts_error;
6302 fnd_msg_pub.count_and_get
6303 ( p_count => l_msg_count
6304 , p_data => l_msg_data
6305 , p_encoded => fnd_api.g_false
6306 );
6307 IF g_debug = 1 THEN
6308 print_debug (l_msg_data, l_api_name);
6309 END IF;
6310
6311 DELETE FROM wms_device_requests
6312 WHERE request_id = wms_device_integration_pvt.wms_pkRel_dev_req_id;
6313
6314 COMMIT;
6315
6316 IF c_non_bulk_tasks%ISOPEN THEN
6317 CLOSE c_non_bulk_tasks;
6318 END IF;
6319 IF c_child_tasks%ISOPEN THEN
6320 CLOSE c_child_tasks;
6321 END IF;
6322 IF c_parent_tasks%ISOPEN THEN
6323 CLOSE c_parent_tasks;
6324 END IF;
6325
6326 WHEN OTHERS THEN
6327 x_return_status := fnd_api.g_ret_sts_unexp_error;
6328 IF g_debug = 1 THEN
6329 print_debug ('Other error: ' || SQLERRM, l_api_name);
6330 END IF;
6331
6332 DELETE FROM wms_device_requests
6333 WHERE request_id = wms_device_integration_pvt.wms_pkRel_dev_req_id;
6334
6335 COMMIT;
6336
6337 IF c_non_bulk_tasks%ISOPEN THEN
6338 CLOSE c_non_bulk_tasks;
6339 END IF;
6340 IF c_child_tasks%ISOPEN THEN
6341 CLOSE c_child_tasks;
6342 END IF;
6343 IF c_parent_tasks%ISOPEN THEN
6344 CLOSE c_parent_tasks;
6345 END IF;
6346
6347 END insert_device_requests;
6348
6349
6350
6351 PROCEDURE CreateDynSelSQL
6352 ( x_pick_slip_sql OUT NOCOPY VARCHAR2
6353 , x_mmtt_sql OUT NOCOPY VARCHAR2
6354 , x_num_criteria OUT NOCOPY NUMBER
6355 , x_return_status OUT NOCOPY VARCHAR2
6356 ) IS
6357
6358 l_api_name VARCHAR2(30) := 'CreateDynSelSQL';
6359 l_count NUMBER := 0;
6360 l_pick_slip_sql VARCHAR2(2000) := 'SELECT ';
6361 l_pickslip_base VARCHAR2(2000) := ' FROM mtl_material_transactions_temp mmtt'
6362 || ' , mtl_txn_request_lines mtrl'
6363 || ' , wsh_inv_delivery_details_v wdd'
6364 || ' WHERE mtrl.header_id = :mo_header_id'
6365 || ' AND mmtt.move_order_line_id = mtrl.line_id'
6366 || ' AND wdd.move_order_line_id = mtrl.line_id';
6367 l_ps_group_by VARCHAR2(2000) := ' GROUP BY ';
6368
6369 l_mmtt_sql_where VARCHAR2(2000) := '';
6370 l_mmtt_sql_base VARCHAR2(2000) := 'SELECT mmtt.transaction_temp_id'
6371 || ' , inv_salesorder.get_salesorder_for_oeheader(wdd.oe_header_id)'
6372 || ' , wdd.oe_line_id'
6373 || ' FROM mtl_material_transactions_temp mmtt'
6374 || ' , mtl_txn_request_lines mtrl'
6375 || ' , wsh_inv_delivery_details_v wdd '
6376 || ' WHERE mtrl.header_id = :mo_header_id'
6377 || ' AND mmtt.move_order_line_id = mtrl.line_id'
6378 || ' AND wdd.move_order_line_id = mtrl.line_id'
6379 || ' AND mmtt.parent_line_id IS NULL'; -- non-bulk tasks
6380
6381 BEGIN
6382 x_return_status := fnd_api.g_ret_sts_success;
6383
6384 IF g_debug = 1 THEN
6385 print_debug('Entered ' || l_api_name, l_api_name);
6386 END IF;
6387
6388 --
6389 -- For each grouping attribute that is checked and set to 'Y',
6390 -- append a column to the SELECT and GROUP BY clauses of Grouping Rule query
6391 -- Also, append an AND condition to MMTT query
6392 --
6393 -- For some columns we can safely avoid using NVL:
6394 -- Order Number (Always populated on WDD for pick released lines)
6395 -- From Subinventory (Always populated on MMTT for pick suggestions)
6396 -- From Locator (Always populated on MMTT for pick suggestions)
6397 -- Item Number (NOT NULL column on MMTT)
6398 --
6399 IF g_ps_rule_rec.use_order_ps = 'Y' THEN
6400 l_count := l_count + 1;
6401 l_pick_slip_sql := l_pick_slip_sql || ' wdd.oe_header_id ';
6402 l_ps_group_by := l_ps_group_by || ' wdd.oe_header_id ';
6403
6404 l_mmtt_sql_where := l_mmtt_sql_where || ' AND wdd.oe_header_id = TO_NUMBER(:var' || l_count || ')';
6405 END IF;
6406
6407 IF g_ps_rule_rec.use_customer_ps = 'Y' THEN
6408 l_count := l_count + 1;
6409
6410 IF l_count > 1 THEN
6411 l_pick_slip_sql := l_pick_slip_sql || ',';
6412 l_ps_group_by := l_ps_group_by || ',';
6413 END IF;
6414 l_pick_slip_sql := l_pick_slip_sql || ' wdd.customer_id ';
6415 l_ps_group_by := l_ps_group_by || ' wdd.customer_id ';
6416
6417 l_mmtt_sql_where := l_mmtt_sql_where || ' AND NVL(wdd.customer_id,-1) = TO_NUMBER(:var' || l_count || ')';
6418 END IF;
6419
6420 IF g_ps_rule_rec.use_carrier_ps = 'Y' THEN
6421 l_count := l_count + 1;
6422
6423 IF l_count > 1 THEN
6424 l_pick_slip_sql := l_pick_slip_sql || ',';
6425 l_ps_group_by := l_ps_group_by || ',';
6426 END IF;
6427 l_pick_slip_sql := l_pick_slip_sql || ' wdd.freight_code ';
6428 l_ps_group_by := l_ps_group_by || ' wdd.freight_code ';
6429
6430 l_mmtt_sql_where := l_mmtt_sql_where || ' AND NVL(wdd.freight_code,''-1'') = :var' || l_count;
6431 END IF;
6432
6433 IF g_ps_rule_rec.use_ship_to_ps = 'Y' THEN
6434 l_count := l_count + 1;
6435
6436 IF l_count > 1 THEN
6437 l_pick_slip_sql := l_pick_slip_sql || ',';
6438 l_ps_group_by := l_ps_group_by || ',';
6439 END IF;
6440 l_pick_slip_sql := l_pick_slip_sql || ' wdd.ship_to_location ';
6441 l_ps_group_by := l_ps_group_by || ' wdd.ship_to_location ';
6442
6443 l_mmtt_sql_where := l_mmtt_sql_where || ' AND NVL(wdd.ship_to_location,-1) = TO_NUMBER(:var' || l_count || ')';
6444 END IF;
6445
6446 IF g_ps_rule_rec.use_ship_priority_ps = 'Y' THEN
6447 l_count := l_count + 1;
6448
6449 IF l_count > 1 THEN
6450 l_pick_slip_sql := l_pick_slip_sql || ',';
6451 l_ps_group_by := l_ps_group_by || ',';
6452 END IF;
6453 l_pick_slip_sql := l_pick_slip_sql || ' wdd.shipment_priority_code ';
6454 l_ps_group_by := l_ps_group_by || ' wdd.shipment_priority_code ';
6455
6456 l_mmtt_sql_where := l_mmtt_sql_where || ' AND NVL(wdd.shipment_priority_code,''-1'') = :var' || l_count;
6457 END IF;
6458
6459 IF g_ps_rule_rec.use_trip_stop_ps = 'Y' THEN
6460 l_count := l_count + 1;
6461
6462 IF l_count > 1 THEN
6463 l_pick_slip_sql := l_pick_slip_sql || ',';
6464 l_ps_group_by := l_ps_group_by || ',';
6465 END IF;
6466 l_pick_slip_sql := l_pick_slip_sql || ' wdd.trip_stop_id ';
6467 l_ps_group_by := l_ps_group_by || ' wdd.trip_stop_id ';
6468
6469 l_mmtt_sql_where := l_mmtt_sql_where || ' AND NVL(wdd.trip_stop_id,-1) = TO_NUMBER(:var' || l_count || ')';
6470 END IF;
6471
6472 IF g_ps_rule_rec.use_delivery_ps = 'Y' THEN
6473 l_count := l_count + 1;
6474
6475 IF l_count > 1 THEN
6476 l_pick_slip_sql := l_pick_slip_sql || ',';
6477 l_ps_group_by := l_ps_group_by || ',';
6478 END IF;
6479 l_pick_slip_sql := l_pick_slip_sql || ' wdd.shipping_delivery_id ';
6480 l_ps_group_by := l_ps_group_by || ' wdd.shipping_delivery_id ';
6481
6482 l_mmtt_sql_where := l_mmtt_sql_where || ' AND NVL(wdd.shipping_delivery_id,-1) = TO_NUMBER(:var' || l_count || ')';
6483 END IF;
6484
6485 IF g_ps_rule_rec.use_src_sub_ps = 'Y' THEN
6486 l_count := l_count + 1;
6487
6488 IF l_count > 1 THEN
6489 l_pick_slip_sql := l_pick_slip_sql || ',';
6490 l_ps_group_by := l_ps_group_by || ',';
6491 END IF;
6492 l_pick_slip_sql := l_pick_slip_sql || ' mmtt.subinventory_code ';
6493 l_ps_group_by := l_ps_group_by || ' mmtt.subinventory_code ';
6494
6495 l_mmtt_sql_where := l_mmtt_sql_where || ' AND mmtt.subinventory_code = :var' || l_count;
6496 END IF;
6497
6498 IF g_ps_rule_rec.use_src_locator_ps = 'Y' THEN
6499 l_count := l_count + 1;
6500
6501 IF l_count > 1 THEN
6502 l_pick_slip_sql := l_pick_slip_sql || ',';
6503 l_ps_group_by := l_ps_group_by || ',';
6504 END IF;
6505 l_pick_slip_sql := l_pick_slip_sql || ' mmtt.locator_id ';
6506 l_ps_group_by := l_ps_group_by || ' mmtt.locator_id ';
6507
6508 l_mmtt_sql_where := l_mmtt_sql_where || ' AND mmtt.locator_id = TO_NUMBER(:var' || l_count || ')';
6509 END IF;
6510
6511 IF g_ps_rule_rec.use_item_ps = 'Y' THEN
6512 l_count := l_count + 1;
6513
6514 IF l_count > 1 THEN
6515 l_pick_slip_sql := l_pick_slip_sql || ',';
6516 l_ps_group_by := l_ps_group_by || ',';
6517 END IF;
6518 l_pick_slip_sql := l_pick_slip_sql || ' mmtt.inventory_item_id ';
6519 l_ps_group_by := l_ps_group_by || ' mmtt.inventory_item_id ';
6520
6521 l_mmtt_sql_where := l_mmtt_sql_where || ' AND mmtt.inventory_item_id = TO_NUMBER(:var' || l_count || ')';
6522 END IF;
6523
6524 IF g_ps_rule_rec.use_revision_ps = 'Y' THEN
6525 l_count := l_count + 1;
6526
6527 IF l_count > 1 THEN
6528 l_pick_slip_sql := l_pick_slip_sql || ',';
6529 l_ps_group_by := l_ps_group_by || ',';
6530 END IF;
6531 l_pick_slip_sql := l_pick_slip_sql || ' mmtt.revision ';
6532 l_ps_group_by := l_ps_group_by || ' mmtt.revision ';
6533
6534 l_mmtt_sql_where := l_mmtt_sql_where || ' AND NVL(mmtt.revision,''-1'') = :var' || l_count;
6535 END IF;
6536
6537 IF g_ps_rule_rec.use_supply_sub_ps = 'Y' THEN
6538 l_count := l_count + 1;
6539
6540 IF l_count > 1 THEN
6541 l_pick_slip_sql := l_pick_slip_sql || ',';
6542 l_ps_group_by := l_ps_group_by || ',';
6543 END IF;
6544 l_pick_slip_sql := l_pick_slip_sql || ' mmtt.transfer_subinventory ';
6545 l_ps_group_by := l_ps_group_by || ' mmtt.transfer_subinventory ';
6546
6547 l_mmtt_sql_where := l_mmtt_sql_where || ' AND NVL(mmtt.transfer_subinventory,''-1'') = :var' || l_count;
6548 END IF;
6549
6550 IF g_ps_rule_rec.use_supply_loc_ps = 'Y' THEN
6551 l_count := l_count + 1;
6552
6553 IF l_count > 1 THEN
6554 l_pick_slip_sql := l_pick_slip_sql || ',';
6555 l_ps_group_by := l_ps_group_by || ',';
6556 END IF;
6557 l_pick_slip_sql := l_pick_slip_sql || ' mmtt.transfer_to_location ';
6558 l_ps_group_by := l_ps_group_by || ' mmtt.transfer_to_location ';
6559
6560 l_mmtt_sql_where := l_mmtt_sql_where || ' AND NVL(mmtt.transfer_to_location,-1) = TO_NUMBER(:var' || l_count || ')';
6561 END IF;
6562
6563 IF g_ps_rule_rec.use_project_ps = 'Y' THEN
6564 l_count := l_count + 1;
6565
6566 IF l_count > 1 THEN
6567 l_pick_slip_sql := l_pick_slip_sql || ',';
6568 l_ps_group_by := l_ps_group_by || ',';
6569 END IF;
6570 l_pick_slip_sql := l_pick_slip_sql || ' mmtt.project_id ';
6571 l_ps_group_by := l_ps_group_by || ' mmtt.project_id ';
6572
6573 l_mmtt_sql_where := l_mmtt_sql_where || ' AND NVL(mmtt.project_id,-1) = TO_NUMBER(:var' || l_count || ')';
6574 END IF;
6575
6576 IF g_ps_rule_rec.use_task_ps = 'Y' THEN
6577 l_count := l_count + 1;
6578
6579 IF l_count > 1 THEN
6580 l_pick_slip_sql := l_pick_slip_sql || ',';
6581 l_ps_group_by := l_ps_group_by || ',';
6582 END IF;
6583 l_pick_slip_sql := l_pick_slip_sql || ' mmtt.task_id ';
6584 l_ps_group_by := l_ps_group_by || ' mmtt.task_id ';
6585
6586 l_mmtt_sql_where := l_mmtt_sql_where || ' AND NVL(mmtt.task_id,-1) = TO_NUMBER(:var' || l_count || ')';
6587 END IF;
6588
6589 -- Concatenate the clauses to form the final two queries
6590 x_pick_slip_sql := l_pick_slip_sql || l_pickslip_base || l_ps_group_by;
6591 x_mmtt_sql := l_mmtt_sql_base || l_mmtt_sql_where;
6592 x_num_criteria := l_count;
6593
6594 EXCEPTION
6595 WHEN OTHERS THEN
6596
6597 x_return_status := fnd_api.g_ret_sts_unexp_error;
6598
6599 IF g_debug = 1 THEN
6600 print_debug ('Other error: ' || SQLERRM, l_api_name);
6601 END IF;
6602 END CreateDynSelSQL;
6603
6604
6605
6606 PROCEDURE assign_pick_slip_numbers
6607 ( p_organization_id IN NUMBER
6608 , p_mo_header_id IN NUMBER
6609 , p_grouping_rule_id IN NUMBER
6610 , x_return_status OUT NOCOPY VARCHAR2
6611 ) IS
6612
6613 l_api_name VARCHAR2(30) := 'assign_pick_slip_numbers';
6614 l_grouping_rule_id NUMBER;
6615 l_organization_id NUMBER;
6616 l_pick_slip_sql VARCHAR2(2000);
6617 l_mmtt_sql VARCHAR2(2000);
6618 l_num_criteria NUMBER;
6619 l_pick_slip_number NUMBER;
6620 l_msg_count NUMBER;
6621 l_msg_data VARCHAR2(2000);
6622 l_api_return_status VARCHAR2(1);
6623 l_dummy VARCHAR2(1);
6624
6625 t_grp_crit1 tbl_varchar50;
6626 t_grp_crit2 tbl_varchar50;
6627 t_grp_crit3 tbl_varchar50;
6628 t_grp_crit4 tbl_varchar50;
6629 t_grp_crit5 tbl_varchar50;
6630 t_grp_crit6 tbl_varchar50;
6631 t_grp_crit7 tbl_varchar50;
6632 t_grp_crit8 tbl_varchar50;
6633 t_grp_crit9 tbl_varchar50;
6634 t_grp_crit10 tbl_varchar50;
6635 t_grp_crit11 tbl_varchar50;
6636 t_grp_crit12 tbl_varchar50;
6637 t_grp_crit13 tbl_varchar50;
6638 t_grp_crit14 tbl_varchar50;
6639 t_grp_crit15 tbl_varchar50;
6640
6641 tbl_transaction_temp_id tbl_num;
6642 tbl_sales_order_id tbl_num;
6643 tbl_oe_line_id tbl_num;
6644 tbl_parent_temp_id tbl_num;
6645
6646 TYPE l_ref_cur IS REF CURSOR;
6647 l_pick_slip_cur l_ref_cur;
6648 l_mmtt_cur l_ref_cur;
6649
6650 CURSOR c_ps_rule (p_pgr_id IN NUMBER) IS
6651 SELECT NVL(order_number_flag, 'N')
6652 , NVL(customer_flag, 'N')
6653 , NVL(ship_to_flag, 'N')
6654 , NVL(carrier_flag, 'N')
6655 , NVL(shipment_priority_flag, 'N')
6656 , NVL(trip_stop_flag, 'N')
6657 , NVL(delivery_flag, 'N')
6658 , NVL(subinventory_flag, 'N')
6659 , NVL(locator_flag, 'N')
6660 , NVL(dest_sub_flag, 'N')
6661 , NVL(dest_loc_flag, 'N')
6662 , NVL(project_flag, 'N')
6663 , NVL(task_flag, 'N')
6664 , NVL(item_flag, 'N')
6665 , NVL(revision_flag, 'N')
6666 , NVL(lot_flag, 'N')
6667 , NVL(pick_method, '-99')
6668 FROM wsh_pick_grouping_rules
6669 WHERE pick_grouping_rule_id = p_pgr_id;
6670
6671 CURSOR c_mold IS
6672 SELECT mmtt.transaction_temp_id
6673 , inv_salesorder.get_salesorder_for_oeheader(wdd.oe_header_id)
6674 , wdd.oe_line_id
6675 FROM mtl_material_transactions_temp mmtt
6676 , mtl_txn_request_lines mol
6677 , wsh_inv_delivery_details_v wdd
6678 WHERE mmtt.move_order_line_id = mol.line_id
6679 AND mol.header_id = p_mo_header_id
6680 AND wdd.move_order_line_id = mol.line_id
6681 AND mmtt.parent_line_id IS NULL; -- exclude bulk pick child tasks
6682
6683 BEGIN
6684 x_return_status := fnd_api.g_ret_sts_success;
6685
6686 SAVEPOINT pick_slip_sp;
6687
6688 IF g_debug = 1 THEN
6689 print_debug( 'Entered with parameters: ' || g_newline ||
6690 'p_organization_id => ' || p_organization_id || g_newline ||
6691 'p_mo_header_id => ' || p_mo_header_id || g_newline ||
6692 'p_grouping_rule_id => ' || p_grouping_rule_id || g_newline
6693 , l_api_name );
6694 END IF;
6695
6696 -- Need to handle the case where pick slip numbering
6697 -- was already done for rulebased cartonization
6698 BEGIN
6699 SELECT 'x' INTO l_dummy
6700 FROM dual
6701 WHERE EXISTS
6702 ( SELECT 'x'
6703 FROM mtl_material_transactions_temp mmtt1
6704 WHERE mmtt1.move_order_header_id = p_mo_header_id
6705 AND mmtt1.parent_line_id IS NULL
6706 AND mmtt1.pick_slip_number IS NULL
6707 );
6708
6709 IF g_debug = 1 THEN
6710 print_debug( 'MMTTs exist which require pick slip numbering.'
6711 , l_api_name);
6712 END IF;
6713
6714 EXCEPTION
6715 WHEN NO_DATA_FOUND THEN
6716 IF g_debug = 1 THEN
6717 print_debug( 'Pick slip numbering not required, exiting.'
6718 , l_api_name);
6719 END IF;
6720 RETURN;
6721 WHEN OTHERS THEN
6722 IF g_debug = 1 THEN
6723 print_debug( 'Error checking pick slip numbering status: '
6724 || SQLERRM, l_api_name);
6725 END IF;
6726 RAISE fnd_api.g_exc_unexpected_error;
6727 END;
6728
6729 -- Setting the Grouping rule id. If PickSlip grouping rule Id is not passed,
6730 -- then fetch from mtl_txn_request_headers
6731 IF p_grouping_rule_id IS NOT NULL THEN
6732 l_grouping_rule_id := p_grouping_rule_id;
6733 ELSE
6734 BEGIN
6735 SELECT grouping_rule_id, organization_id
6736 INTO l_grouping_rule_id, l_organization_id
6737 FROM mtl_txn_request_headers
6738 WHERE header_id = p_mo_header_id;
6739 EXCEPTION
6740 WHEN OTHERS THEN
6741 IF g_debug = 1 THEN
6742 print_debug ('Error querying grouping rule from MO header: '
6743 || SQLERRM, l_api_name);
6744 END IF;
6745 RAISE fnd_api.g_exc_unexpected_error;
6746 END;
6747 END IF;
6748
6749 -- If Grouping rule id is still null, fetch it from wsh_parameters
6750 -- (the organization-level default)
6751 IF l_grouping_rule_id IS NULL THEN
6752 BEGIN
6753 SELECT pick_grouping_rule_id
6754 INTO l_grouping_rule_id
6755 FROM wsh_shipping_parameters
6756 WHERE organization_id = p_organization_id;
6757 EXCEPTION
6758 WHEN OTHERS THEN
6759 IF g_debug = 1 THEN
6760 print_debug ('Error querying grouping rule from Shipping parameters: '
6761 || SQLERRM, l_api_name);
6762 END IF;
6763 RAISE fnd_api.g_exc_unexpected_error;
6764 END;
6765 END IF;
6766
6767 -- Fetch the attributes for the Pick Slip Grouping Rule
6768 OPEN c_ps_rule(l_grouping_rule_id);
6769 FETCH c_ps_rule INTO g_ps_rule_rec.use_order_ps
6770 , g_ps_rule_rec.use_customer_ps
6771 , g_ps_rule_rec.use_ship_to_ps
6772 , g_ps_rule_rec.use_carrier_ps
6773 , g_ps_rule_rec.use_ship_priority_ps
6774 , g_ps_rule_rec.use_trip_stop_ps
6775 , g_ps_rule_rec.use_delivery_ps
6776 , g_ps_rule_rec.use_src_sub_ps
6777 , g_ps_rule_rec.use_src_locator_ps
6778 , g_ps_rule_rec.use_supply_sub_ps
6779 , g_ps_rule_rec.use_supply_loc_ps
6780 , g_ps_rule_rec.use_project_ps
6781 , g_ps_rule_rec.use_task_ps
6782 , g_ps_rule_rec.use_item_ps
6783 , g_ps_rule_rec.use_revision_ps
6784 , g_ps_rule_rec.use_lot_ps
6785 , g_ps_rule_rec.pick_method;
6786 CLOSE c_ps_rule;
6787
6788 g_ps_rule_rec.grouping_rule_id := l_grouping_rule_id;
6789 IF g_debug = 1 THEN
6790 print_debug( 'Pick method : ' || g_ps_rule_rec.pick_method
6791 , l_api_name);
6792 END IF;
6793
6794 -- If Pick method is not Cluster Pick
6795 IF (g_ps_rule_rec.pick_method <> g_cluster_pick_method) THEN --{
6796
6797 -- Call CreateDynSelSQL API which constructs and returns the two dynamic queries,
6798 -- l_pick_slip_sql gives the grouping criteria and l_mmtt_sql dynamically gives the
6799 -- records in MMTT to be stamped with Pick Slip Number based on each record
6800 -- returned by l_pick_slip_sql
6801 l_api_return_status := fnd_api.g_ret_sts_success;
6802 CreateDynSelSQL(
6803 x_pick_slip_sql => l_pick_slip_sql
6804 , x_mmtt_sql => l_mmtt_sql
6805 , x_num_criteria => l_num_criteria
6806 , x_return_status => l_api_return_status);
6807
6808 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
6809 IF g_debug = 1 THEN
6810 print_debug('Error status from CreateDynSelSQL: '
6811 || l_api_return_status, l_api_name);
6812 END IF;
6813 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
6814 RAISE fnd_api.g_exc_error;
6815 ELSE
6816 RAISE fnd_api.g_exc_unexpected_error;
6817 END IF;
6818 END IF;
6819
6820 IF g_debug = 1 THEN
6821 print_debug( 'Number of grouping criteria returned : ' || l_num_criteria, l_api_name );
6822 print_debug( 'Pick Slip grouping criteria dynamic query : ' || l_pick_slip_sql, l_api_name );
6823 print_debug( 'Dynamic query for matching MMTT rows: ' || l_mmtt_sql, l_api_name );
6824 END IF;
6825
6826 -- If no grouping criteria returned
6827 IF l_num_criteria < 1 THEN
6828 IF g_debug = 1 THEN
6829 print_debug( 'No Grouping criteria found', l_api_name );
6830 END IF;
6831 RAISE fnd_api.G_EXC_UNEXPECTED_ERROR;
6832 END IF;
6833
6834 -- Open grouping criteria cursor. Each row in this cursor represents a pick slip
6835 OPEN l_pick_slip_cur FOR l_pick_slip_sql USING p_mo_header_id;
6836
6837 LOOP --{
6838 -- Bulk fetch the grouping criteria based on number of
6839 -- grouping attributes returned(l_num_criteria)
6840 IF l_num_criteria = 1 THEN
6841 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1 LIMIT g_bulk_fetch_limit;
6842 ELSIF l_num_criteria = 2 THEN
6843 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1
6844 , t_grp_crit2 LIMIT g_bulk_fetch_limit;
6845 ELSIF l_num_criteria = 3 THEN
6846 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1
6847 , t_grp_crit2
6848 , t_grp_crit3 LIMIT g_bulk_fetch_limit;
6849 ELSIF l_num_criteria = 4 THEN
6850 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1
6851 , t_grp_crit2
6852 , t_grp_crit3
6853 , t_grp_crit4 LIMIT g_bulk_fetch_limit;
6854 ELSIF l_num_criteria = 5 THEN
6855 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1
6856 , t_grp_crit2
6857 , t_grp_crit3
6858 , t_grp_crit4
6859 , t_grp_crit5 LIMIT g_bulk_fetch_limit;
6860 ELSIF l_num_criteria = 6 THEN
6861 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1
6862 , t_grp_crit2
6863 , t_grp_crit3
6864 , t_grp_crit4
6865 , t_grp_crit5
6866 , t_grp_crit6 LIMIT g_bulk_fetch_limit;
6867 ELSIF l_num_criteria = 7 THEN
6868 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1
6869 , t_grp_crit2
6870 , t_grp_crit3
6871 , t_grp_crit4
6872 , t_grp_crit5
6873 , t_grp_crit6
6874 , t_grp_crit7 LIMIT g_bulk_fetch_limit;
6875 ELSIF l_num_criteria = 8 THEN
6876 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1
6877 , t_grp_crit2
6878 , t_grp_crit3
6879 , t_grp_crit4
6880 , t_grp_crit5
6881 , t_grp_crit6
6882 , t_grp_crit7
6883 , t_grp_crit8 LIMIT g_bulk_fetch_limit;
6884 ELSIF l_num_criteria = 9 THEN
6885 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1
6886 , t_grp_crit2
6887 , t_grp_crit3
6888 , t_grp_crit4
6889 , t_grp_crit5
6890 , t_grp_crit6
6891 , t_grp_crit7
6892 , t_grp_crit8
6893 , t_grp_crit9 LIMIT g_bulk_fetch_limit;
6894 ELSIF l_num_criteria = 10 THEN
6895 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1
6896 , t_grp_crit2
6897 , t_grp_crit3
6898 , t_grp_crit4
6899 , t_grp_crit5
6900 , t_grp_crit6
6901 , t_grp_crit7
6902 , t_grp_crit8
6903 , t_grp_crit9
6904 , t_grp_crit10 LIMIT g_bulk_fetch_limit;
6905 ELSIF l_num_criteria = 11 THEN
6906 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1
6907 , t_grp_crit2
6908 , t_grp_crit3
6909 , t_grp_crit4
6910 , t_grp_crit5
6911 , t_grp_crit6
6912 , t_grp_crit7
6913 , t_grp_crit8
6914 , t_grp_crit9
6915 , t_grp_crit10
6916 , t_grp_crit11 LIMIT g_bulk_fetch_limit;
6917 ELSIF l_num_criteria = 12 THEN
6918 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1
6919 , t_grp_crit2
6920 , t_grp_crit3
6921 , t_grp_crit4
6922 , t_grp_crit5
6923 , t_grp_crit6
6924 , t_grp_crit7
6925 , t_grp_crit8
6926 , t_grp_crit9
6927 , t_grp_crit10
6928 , t_grp_crit11
6929 , t_grp_crit12 LIMIT g_bulk_fetch_limit;
6930 ELSIF l_num_criteria = 13 THEN
6931 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1
6932 , t_grp_crit2
6933 , t_grp_crit3
6934 , t_grp_crit4
6935 , t_grp_crit5
6936 , t_grp_crit6
6937 , t_grp_crit7
6938 , t_grp_crit8
6939 , t_grp_crit9
6940 , t_grp_crit10
6941 , t_grp_crit11
6942 , t_grp_crit12
6943 , t_grp_crit13 LIMIT g_bulk_fetch_limit;
6944 ELSIF l_num_criteria = 14 THEN
6945 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1
6946 , t_grp_crit2
6947 , t_grp_crit3
6948 , t_grp_crit4
6949 , t_grp_crit5
6950 , t_grp_crit6
6951 , t_grp_crit7
6952 , t_grp_crit8
6953 , t_grp_crit9
6954 , t_grp_crit10
6955 , t_grp_crit11
6956 , t_grp_crit12
6957 , t_grp_crit13
6958 , t_grp_crit14 LIMIT g_bulk_fetch_limit;
6959 ELSIF l_num_criteria = 15 THEN
6960 FETCH l_pick_slip_cur BULK COLLECT INTO t_grp_crit1
6961 , t_grp_crit2
6962 , t_grp_crit3
6963 , t_grp_crit4
6964 , t_grp_crit5
6965 , t_grp_crit6
6966 , t_grp_crit7
6967 , t_grp_crit8
6968 , t_grp_crit9
6969 , t_grp_crit10
6970 , t_grp_crit11
6971 , t_grp_crit12
6972 , t_grp_crit13
6973 , t_grp_crit14
6974 , t_grp_crit15 LIMIT g_bulk_fetch_limit;
6975 END IF;
6976
6977 EXIT WHEN t_grp_crit1.COUNT = 0;
6978
6979 FOR ii IN t_grp_crit1.FIRST .. t_grp_crit1.LAST LOOP --{
6980
6981 -- Get the next pick slip number using the sequence
6982 SELECT wsh_pick_slip_numbers_s.NEXTVAL
6983 INTO l_pick_slip_number
6984 FROM DUAL;
6985
6986 -- Open cursor to fetch matching MMTT rows based on number of Grouping attributes returned
6987 IF l_num_criteria = 1 THEN
6988 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
6989 , NVL(t_grp_crit1(ii),'-1');
6990 ELSIF l_num_criteria = 2 THEN
6991 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
6992 , NVL(t_grp_crit1(ii),'-1')
6993 , NVL(t_grp_crit2(ii),'-1');
6994 ELSIF l_num_criteria = 3 THEN
6995 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
6996 , NVL(t_grp_crit1(ii),'-1')
6997 , NVL(t_grp_crit2(ii),'-1')
6998 , NVL(t_grp_crit3(ii),'-1');
6999 ELSIF l_num_criteria = 4 THEN
7000 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
7001 , NVL(t_grp_crit1(ii),'-1')
7002 , NVL(t_grp_crit2(ii),'-1')
7003 , NVL(t_grp_crit3(ii),'-1')
7004 , NVL(t_grp_crit4(ii),'-1');
7005 ELSIF l_num_criteria = 5 THEN
7006 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
7007 , NVL(t_grp_crit1(ii),'-1')
7008 , NVL(t_grp_crit2(ii),'-1')
7009 , NVL(t_grp_crit3(ii),'-1')
7010 , NVL(t_grp_crit4(ii),'-1')
7011 , NVL(t_grp_crit5(ii),'-1');
7012 ELSIF l_num_criteria = 6 THEN
7013 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
7014 , NVL(t_grp_crit1(ii),'-1')
7015 , NVL(t_grp_crit2(ii),'-1')
7016 , NVL(t_grp_crit3(ii),'-1')
7017 , NVL(t_grp_crit4(ii),'-1')
7018 , NVL(t_grp_crit5(ii),'-1')
7019 , NVL(t_grp_crit6(ii),'-1');
7020 ELSIF l_num_criteria = 7 THEN
7021 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
7022 , NVL(t_grp_crit1(ii),'-1')
7023 , NVL(t_grp_crit2(ii),'-1')
7024 , NVL(t_grp_crit3(ii),'-1')
7025 , NVL(t_grp_crit4(ii),'-1')
7026 , NVL(t_grp_crit5(ii),'-1')
7027 , NVL(t_grp_crit6(ii),'-1')
7028 , NVL(t_grp_crit7(ii),'-1');
7029 ELSIF l_num_criteria = 8 THEN
7030 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
7031 , NVL(t_grp_crit1(ii),'-1')
7032 , NVL(t_grp_crit2(ii),'-1')
7033 , NVL(t_grp_crit3(ii),'-1')
7034 , NVL(t_grp_crit4(ii),'-1')
7035 , NVL(t_grp_crit5(ii),'-1')
7036 , NVL(t_grp_crit6(ii),'-1')
7037 , NVL(t_grp_crit7(ii),'-1')
7038 , NVL(t_grp_crit8(ii),'-1');
7039 ELSIF l_num_criteria = 9 THEN
7040 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
7041 , NVL(t_grp_crit1(ii),'-1')
7042 , NVL(t_grp_crit2(ii),'-1')
7043 , NVL(t_grp_crit3(ii),'-1')
7044 , NVL(t_grp_crit4(ii),'-1')
7045 , NVL(t_grp_crit5(ii),'-1')
7046 , NVL(t_grp_crit6(ii),'-1')
7047 , NVL(t_grp_crit7(ii),'-1')
7048 , NVL(t_grp_crit8(ii),'-1')
7049 , NVL(t_grp_crit9(ii),'-1');
7050 ELSIF l_num_criteria = 10 THEN
7051 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
7052 , NVL(t_grp_crit1(ii),'-1')
7053 , NVL(t_grp_crit2(ii),'-1')
7054 , NVL(t_grp_crit3(ii),'-1')
7055 , NVL(t_grp_crit4(ii),'-1')
7056 , NVL(t_grp_crit5(ii),'-1')
7057 , NVL(t_grp_crit6(ii),'-1')
7058 , NVL(t_grp_crit7(ii),'-1')
7059 , NVL(t_grp_crit8(ii),'-1')
7060 , NVL(t_grp_crit9(ii),'-1')
7061 , NVL(t_grp_crit10(ii),'-1');
7062 ELSIF l_num_criteria = 11 THEN
7063 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
7064 , NVL(t_grp_crit1(ii),'-1')
7065 , NVL(t_grp_crit2(ii),'-1')
7066 , NVL(t_grp_crit3(ii),'-1')
7067 , NVL(t_grp_crit4(ii),'-1')
7068 , NVL(t_grp_crit5(ii),'-1')
7069 , NVL(t_grp_crit6(ii),'-1')
7070 , NVL(t_grp_crit7(ii),'-1')
7071 , NVL(t_grp_crit8(ii),'-1')
7072 , NVL(t_grp_crit9(ii),'-1')
7073 , NVL(t_grp_crit10(ii),'-1')
7074 , NVL(t_grp_crit11(ii),'-1');
7075 ELSIF l_num_criteria = 12 THEN
7076 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
7077 , NVL(t_grp_crit1(ii),'-1')
7078 , NVL(t_grp_crit2(ii),'-1')
7079 , NVL(t_grp_crit3(ii),'-1')
7080 , NVL(t_grp_crit4(ii),'-1')
7081 , NVL(t_grp_crit5(ii),'-1')
7082 , NVL(t_grp_crit6(ii),'-1')
7083 , NVL(t_grp_crit7(ii),'-1')
7084 , NVL(t_grp_crit8(ii),'-1')
7085 , NVL(t_grp_crit9(ii),'-1')
7086 , NVL(t_grp_crit10(ii),'-1')
7087 , NVL(t_grp_crit11(ii),'-1')
7088 , NVL(t_grp_crit12(ii),'-1');
7089 ELSIF l_num_criteria = 13 THEN
7090 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
7091 , NVL(t_grp_crit1(ii),'-1')
7092 , NVL(t_grp_crit2(ii),'-1')
7093 , NVL(t_grp_crit3(ii),'-1')
7094 , NVL(t_grp_crit4(ii),'-1')
7095 , NVL(t_grp_crit5(ii),'-1')
7096 , NVL(t_grp_crit6(ii),'-1')
7097 , NVL(t_grp_crit7(ii),'-1')
7098 , NVL(t_grp_crit8(ii),'-1')
7099 , NVL(t_grp_crit9(ii),'-1')
7100 , NVL(t_grp_crit10(ii),'-1')
7101 , NVL(t_grp_crit11(ii),'-1')
7102 , NVL(t_grp_crit12(ii),'-1')
7103 , NVL(t_grp_crit13(ii),'-1');
7104 ELSIF l_num_criteria = 14 THEN
7105 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
7106 , NVL(t_grp_crit1(ii),'-1')
7107 , NVL(t_grp_crit2(ii),'-1')
7108 , NVL(t_grp_crit3(ii),'-1')
7109 , NVL(t_grp_crit4(ii),'-1')
7110 , NVL(t_grp_crit5(ii),'-1')
7111 , NVL(t_grp_crit6(ii),'-1')
7112 , NVL(t_grp_crit7(ii),'-1')
7113 , NVL(t_grp_crit8(ii),'-1')
7114 , NVL(t_grp_crit9(ii),'-1')
7115 , NVL(t_grp_crit10(ii),'-1')
7116 , NVL(t_grp_crit11(ii),'-1')
7117 , NVL(t_grp_crit12(ii),'-1')
7118 , NVL(t_grp_crit13(ii),'-1')
7119 , NVL(t_grp_crit14(ii),'-1');
7120 ELSIF l_num_criteria = 15 THEN
7121 OPEN l_mmtt_cur FOR l_mmtt_sql USING p_mo_header_id
7122 , NVL(t_grp_crit1(ii),'-1')
7123 , NVL(t_grp_crit2(ii),'-1')
7124 , NVL(t_grp_crit3(ii),'-1')
7125 , NVL(t_grp_crit4(ii),'-1')
7126 , NVL(t_grp_crit5(ii),'-1')
7127 , NVL(t_grp_crit6(ii),'-1')
7128 , NVL(t_grp_crit7(ii),'-1')
7129 , NVL(t_grp_crit8(ii),'-1')
7130 , NVL(t_grp_crit9(ii),'-1')
7131 , NVL(t_grp_crit10(ii),'-1')
7132 , NVL(t_grp_crit11(ii),'-1')
7133 , NVL(t_grp_crit12(ii),'-1')
7134 , NVL(t_grp_crit13(ii),'-1')
7135 , NVL(t_grp_crit14(ii),'-1')
7136 , NVL(t_grp_crit15(ii),'-1');
7137 END IF;
7138
7139 LOOP --{
7140 -- BULK FETCH set of matching MMTTs
7141 FETCH l_mmtt_cur BULK COLLECT
7142 INTO tbl_transaction_temp_id
7143 , tbl_sales_order_id
7144 , tbl_oe_line_id LIMIT g_bulk_fetch_limit;
7145 EXIT WHEN tbl_transaction_temp_id.COUNT = 0;
7146
7147 -- Assign the pick slip number to the records in MTL_MATERIAL_TRANSACTIONS_TEMP
7148 FORALL jj IN tbl_transaction_temp_id.FIRST .. tbl_transaction_temp_id.LAST
7149 UPDATE mtl_material_transactions_temp
7150 SET pick_slip_number = l_pick_slip_number
7151 , transaction_source_id = tbl_sales_order_id(jj)
7152 , trx_source_line_id = tbl_oe_line_id(jj)
7153 , demand_source_header_id = tbl_sales_order_id(jj)
7154 , demand_source_line = tbl_oe_line_id(jj)
7155 WHERE transaction_temp_id = tbl_transaction_temp_id(jj);
7156 END LOOP; --}
7157
7158 IF l_mmtt_cur%ISOPEN THEN
7159 CLOSE l_mmtt_cur;
7160 END IF;
7161 END LOOP; --}
7162 END LOOP; --}
7163
7164 IF l_pick_slip_cur%ISOPEN THEN
7165 CLOSE l_pick_slip_cur;
7166 END IF;
7167 --}
7168 ELSIF (g_ps_rule_rec.pick_method = g_cluster_pick_method) THEN
7169 OPEN c_mold;
7170 LOOP --{
7171 FETCH c_mold BULK COLLECT
7172 INTO tbl_transaction_temp_id
7173 , tbl_sales_order_id
7174 , tbl_oe_line_id LIMIT g_bulk_fetch_limit;
7175 EXIT WHEN tbl_transaction_temp_id.COUNT = 0;
7176
7177 FORALL jj IN tbl_transaction_temp_id.FIRST .. tbl_transaction_temp_id.LAST
7178 UPDATE mtl_material_transactions_temp
7179 SET pick_slip_number = wsh_pick_slip_numbers_s.NEXTVAL
7180 , transaction_source_id = tbl_sales_order_id(jj)
7181 , trx_source_line_id = tbl_oe_line_id(jj)
7182 , demand_source_header_id = tbl_sales_order_id(jj)
7183 , demand_source_line = tbl_oe_line_id(jj)
7184 WHERE transaction_temp_id = tbl_transaction_temp_id(jj);
7185 END LOOP; --}
7186 IF c_mold%ISOPEN THEN
7187 CLOSE c_mold;
7188 END IF;
7189 END IF;
7190
7191 COMMIT;
7192
7193 EXCEPTION
7194 WHEN fnd_api.g_exc_error THEN
7195 ROLLBACK TO pick_slip_sp;
7196 x_return_status := fnd_api.g_ret_sts_error;
7197 fnd_msg_pub.count_and_get
7198 ( p_count => l_msg_count
7199 , p_data => l_msg_data
7200 , p_encoded => fnd_api.g_false
7201 );
7202 IF g_debug = 1 THEN
7203 print_debug (l_msg_data, l_api_name);
7204 END IF;
7205 IF c_ps_rule%ISOPEN THEN
7206 CLOSE c_ps_rule;
7207 END IF;
7208 IF c_mold%ISOPEN THEN
7209 CLOSE c_mold;
7210 END IF;
7211
7212 WHEN OTHERS THEN
7213 ROLLBACK TO pick_slip_sp;
7214 x_return_status := fnd_api.g_ret_sts_unexp_error;
7215 IF g_debug = 1 THEN
7216 print_debug ('Other error: ' || SQLERRM, l_api_name);
7217 END IF;
7218 IF c_ps_rule%ISOPEN THEN
7219 CLOSE c_ps_rule;
7220 END IF;
7221 IF c_mold%ISOPEN THEN
7222 CLOSE c_mold;
7223 END IF;
7224
7225 END assign_pick_slip_numbers;
7226
7227
7228
7229 PROCEDURE print_labels
7230 ( p_batch_id IN NUMBER
7231 , x_return_status OUT NOCOPY VARCHAR2
7232 ) IS
7233
7234 l_api_name VARCHAR2(30) := 'print_labels';
7235 l_msg_count NUMBER;
7236 l_msg_data VARCHAR2(2000);
7237
7238 l_api_return_status VARCHAR2(1);
7239 l_lbl_api_status VARCHAR2(1);
7240 l_label_status VARCHAR2(500);
7241 l_wpr_rec wms_pr_workers%ROWTYPE;
7242 t_carton_id inv_label.transaction_id_rec_type;
7243 t_cspk_temp_id inv_label.transaction_id_rec_type;
7244 l_wpr_counter NUMBER;
7245 l_txn_batch_ctr NUMBER;
7246 t_txn_batch_id tbl_num;
7247
7248 CURSOR c_lblprnt (p_batch_id NUMBER) IS
7249 SELECT transaction_temp_id
7250 FROM mtl_material_transactions_temp
7251 WHERE transaction_batch_id = p_batch_id;
7252
7253 BEGIN
7254 x_return_status := fnd_api.g_ret_sts_success;
7255
7256 IF g_debug = 1 THEN
7257 print_debug( 'Entered with parameters: ' || g_newline ||
7258 'p_batch_id => ' || p_batch_id
7259 , l_api_name);
7260 END IF;
7261
7262 l_wpr_counter := 0;
7263 LOOP --{
7264 l_api_return_status := fnd_api.g_ret_sts_success;
7265 fetch_next_wpr_rec
7266 ( p_batch_id => p_batch_id
7267 , p_mode => 'CRTN_LBL'
7268 , x_wpr_rec => l_wpr_rec
7269 , x_return_status => l_api_return_status
7270 );
7271
7272 IF l_api_return_status = 'N' THEN --{
7273 IF l_wpr_counter > 0 THEN
7274 IF g_debug = 1 THEN
7275 print_debug ('No more CRTN_LBL records in WPR, print remaining', l_api_name);
7276 END IF;
7277 l_lbl_api_status := fnd_api.g_ret_sts_success;
7278 inv_label.print_label
7279 ( x_return_status => l_lbl_api_status
7280 , x_msg_count => l_msg_count
7281 , x_msg_data => l_msg_data
7282 , x_label_status => l_label_status
7283 , p_api_version => 1.0
7284 , p_print_mode => 1
7285 , p_business_flow_code => 22
7286 , p_transaction_id => t_carton_id
7287 );
7288
7289 FORALL ii IN t_carton_id.FIRST .. t_carton_id.LAST
7290 DELETE wms_pr_workers
7291 WHERE cartonization_id = t_carton_id(ii);
7292
7293 IF l_lbl_api_status <> fnd_api.g_ret_sts_success THEN
7294 FND_MESSAGE.SET_NAME('INV', 'INV_RCV_CRT_PRINT_LAB_FAIL');
7295 FND_MSG_PUB.ADD;
7296 RAISE fnd_api.g_exc_error;
7297 END IF;
7298 l_wpr_counter := 0;
7299 t_carton_id.DELETE;
7300 EXIT;
7301 ELSE
7302 IF g_debug = 1 THEN
7303 print_debug ('No more CRTN_LBL records in WPR', l_api_name);
7304 END IF;
7305 EXIT;
7306 END IF;
7307 --}
7308 ELSIF l_api_return_status <> fnd_api.g_ret_sts_success THEN
7309 IF g_debug = 1 THEN
7310 print_debug('Error status from fetch_next_wpr_rec: '
7311 || l_api_return_status, l_api_name);
7312 END IF;
7313 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
7314 RAISE fnd_api.g_exc_error;
7315 ELSE
7316 RAISE fnd_api.g_exc_unexpected_error;
7317 END IF;
7318 END IF;
7319
7320 l_wpr_counter := l_wpr_counter + 1;
7321 t_carton_id (l_wpr_counter) := l_wpr_rec.cartonization_id;
7322 IF g_debug = 1 THEN
7323 print_debug( 'No. of cartonization IDs fetched so far: ' || l_wpr_counter
7324 , l_api_name);
7325 END IF;
7326
7327 IF l_wpr_counter >= 100 THEN
7328 l_lbl_api_status := fnd_api.g_ret_sts_success;
7329 inv_label.print_label
7330 ( x_return_status => l_lbl_api_status
7331 , x_msg_count => l_msg_count
7332 , x_msg_data => l_msg_data
7333 , x_label_status => l_label_status
7334 , p_api_version => 1.0
7335 , p_print_mode => 1
7336 , p_business_flow_code => 22
7337 , p_transaction_id => t_carton_id
7338 );
7339
7340 FORALL jj IN t_carton_id.FIRST .. t_carton_id.LAST
7341 DELETE wms_pr_workers
7342 WHERE cartonization_id = t_carton_id(jj);
7343
7344 IF l_lbl_api_status <> fnd_api.g_ret_sts_success THEN
7345 FND_MESSAGE.SET_NAME('INV', 'INV_RCV_CRT_PRINT_LAB_FAIL');
7346 FND_MSG_PUB.ADD;
7347 RAISE fnd_api.g_exc_error;
7348 END IF;
7349 l_wpr_counter := 0;
7350 t_carton_id.DELETE;
7351 END IF;
7352 END LOOP; --}
7353
7354 l_txn_batch_ctr := 0;
7355 LOOP --{
7356 l_api_return_status := fnd_api.g_ret_sts_success;
7357 fetch_next_wpr_rec
7358 ( p_batch_id => p_batch_id
7359 , p_mode => 'CSPK_LBL'
7360 , x_wpr_rec => l_wpr_rec
7361 , x_return_status => l_api_return_status
7362 );
7363
7364 IF l_api_return_status = 'N' THEN
7365 IF g_debug = 1 THEN
7366 print_debug ( 'No more records in WPR', l_api_name );
7367 END IF;
7368 EXIT;
7369 ELSIF l_api_return_status <> fnd_api.g_ret_sts_success THEN
7370 IF g_debug = 1 THEN
7371 print_debug('Error status from fetch_next_wpr_rec: '
7372 || l_api_return_status, l_api_name);
7373 END IF;
7374 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
7375 RAISE fnd_api.g_exc_error;
7376 ELSE
7377 RAISE fnd_api.g_exc_unexpected_error;
7378 END IF;
7379 END IF;
7380
7381 l_txn_batch_ctr := l_txn_batch_ctr + 1;
7382 t_txn_batch_id(l_txn_batch_ctr) := l_wpr_rec.transaction_batch_id;
7383
7384 OPEN c_lblprnt (l_wpr_rec.transaction_batch_id);
7385 FETCH c_lblprnt BULK COLLECT INTO t_cspk_temp_id;
7386 CLOSE c_lblprnt;
7387
7388 l_api_return_status := fnd_api.g_ret_sts_success;
7389 inv_label.print_label
7390 ( x_return_status => l_api_return_status
7391 , x_msg_count => l_msg_count
7392 , x_msg_data => l_msg_data
7393 , x_label_status => l_label_status
7394 , p_api_version => 1.0
7395 , p_print_mode => 1
7396 , p_business_flow_code => 42
7397 , p_transaction_id => t_cspk_temp_id
7398 );
7399
7400 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
7401 FND_MESSAGE.SET_NAME('WMS', 'WMS_PR_LABEL_FAIL'); -- TBD
7402 FND_MSG_PUB.ADD;
7403 RAISE fnd_api.g_exc_error;
7404 END IF;
7405 t_cspk_temp_id.DELETE;
7406
7407 END LOOP; --}
7408
7409 IF t_txn_batch_id.COUNT > 0 THEN
7410 FORALL kk IN t_txn_batch_id.FIRST .. t_txn_batch_id.LAST
7411 UPDATE mtl_material_transactions_temp
7412 SET transaction_batch_id = NULL
7413 WHERE transaction_batch_id = t_txn_batch_id(kk);
7414
7415 FORALL mm IN t_txn_batch_id.FIRST .. t_txn_batch_id.LAST
7416 DELETE FROM wms_pr_workers
7417 WHERE transaction_batch_id = t_txn_batch_id(mm);
7418 END IF;
7419
7420 COMMIT;
7421
7422 EXCEPTION
7423 WHEN fnd_api.g_exc_error THEN
7424 x_return_status := fnd_api.g_ret_sts_error;
7425 fnd_msg_pub.count_and_get
7426 ( p_count => l_msg_count
7427 , p_data => l_msg_data
7428 , p_encoded => fnd_api.g_false
7429 );
7430 IF g_debug = 1 THEN
7431 print_debug (l_msg_data, l_api_name);
7432 END IF;
7433 IF c_lblprnt%ISOPEN THEN
7434 CLOSE c_lblprnt;
7435 END IF;
7436 IF t_carton_id.COUNT > 0 THEN
7437 FORALL jj IN t_carton_id.FIRST .. t_carton_id.LAST
7438 DELETE wms_pr_workers
7439 WHERE cartonization_id = t_carton_id(jj);
7440 COMMIT;
7441 END IF;
7442 IF t_txn_batch_id.COUNT > 0 THEN
7443 FORALL kk IN t_txn_batch_id.FIRST .. t_txn_batch_id.LAST
7444 UPDATE mtl_material_transactions_temp
7445 SET transaction_batch_id = NULL
7446 WHERE transaction_batch_id = t_txn_batch_id(kk);
7447 FORALL mm IN t_txn_batch_id.FIRST .. t_txn_batch_id.LAST
7448 DELETE FROM wms_pr_workers
7449 WHERE transaction_batch_id = t_txn_batch_id(mm);
7450 COMMIT;
7451 END IF;
7452
7453 WHEN OTHERS THEN
7454 x_return_status := fnd_api.g_ret_sts_unexp_error;
7455 IF g_debug = 1 THEN
7456 print_debug ('Other error: ' || SQLERRM, l_api_name);
7457 END IF;
7458 IF c_lblprnt%ISOPEN THEN
7459 CLOSE c_lblprnt;
7460 END IF;
7461 IF t_carton_id.COUNT > 0 THEN
7462 FORALL jj IN t_carton_id.FIRST .. t_carton_id.LAST
7463 DELETE wms_pr_workers
7464 WHERE cartonization_id = t_carton_id(jj);
7465 COMMIT;
7466 END IF;
7467 IF t_txn_batch_id.COUNT > 0 THEN
7468 FORALL kk IN t_txn_batch_id.FIRST .. t_txn_batch_id.LAST
7469 UPDATE mtl_material_transactions_temp
7470 SET transaction_batch_id = NULL
7471 WHERE transaction_batch_id = t_txn_batch_id(kk);
7472 FORALL mm IN t_txn_batch_id.FIRST .. t_txn_batch_id.LAST
7473 DELETE FROM wms_pr_workers
7474 WHERE transaction_batch_id = t_txn_batch_id(mm);
7475 COMMIT;
7476 END IF;
7477
7478 END print_labels;
7479
7480
7481
7482 END wms_postalloc_pvt;