DBA Data[Home] [Help]

PACKAGE BODY: APPS.WMS_TASK_MGMT_PUB

Source


1 PACKAGE BODY WMS_TASK_MGMT_PUB AS
2 /*$Header: WMSTKMPB.pls 120.14.12020000.4 2013/04/15 06:52:35 raminoch ship $ */
3 ------------------------------------------------------------------------------------------------------
4         g_pkg_name VARCHAR2(30) := 'WMS_TASK_MGMT_PUB';
5         g_debug    NUMBER       := nvl(fnd_profile.VALUE('INV_DEBUG_TRACE'),0);
6 ------------------------------------------------------------------------------------------------------
7 -- START OF QUERY TASKS
8 PROCEDURE initialize_main_table
9 IS
10 BEGIN
11         ---initialize the main table
12         ---this table will have all the parameters with default values that
13         ---need to be passed to wms_waveplan_tasks_pvt.query_tasks procedure
14         g_main_tab(1).field_name   := 'ACTIVE';
15         g_main_tab(1).field_value  := NULL;
16         g_main_tab(2).field_name   := 'ASSEMBLY_ID';
17         g_main_tab(2).field_value  := NULL;
18         g_main_tab(3).field_name   := 'CARRIER_ID';
19         g_main_tab(3).field_value  := NULL;
20         g_main_tab(4).field_name   := 'CATEGORY_SET_ID';
21         g_main_tab(4).field_value  := NULL;
22         g_main_tab(5).field_name   := 'COMPLETED';
23         g_main_tab(5).field_value  := FND_API.G_FALSE;
24         g_main_tab(6).field_name   := 'CUSTOMER_CATEGORY';
25         g_main_tab(6).field_value  := NULL;
26         g_main_tab(7).field_name   := 'CUSTOMER_ID';
27         g_main_tab(7).field_value  := NULL;
28         g_main_tab(8).field_name   := 'CYCLE_COUNT_NAME';
29         g_main_tab(8).field_value  := NULL;
30         g_main_tab(9).field_name   := 'CYCLE_COUNT_TASKS';
31         g_main_tab(9).field_value  := FND_API.G_TRUE;
32         g_main_tab(10).field_name  := 'DELIVERY_ID';
33         g_main_tab(10).field_value := NULL;
34         g_main_tab(11).field_name  := 'DEPARTMENT_ID';
35         g_main_tab(11).field_value := NULL;
36         g_main_tab(12).field_name  := 'DISPATCHED';
37         g_main_tab(12).field_value := FND_API.G_FALSE;
38         g_main_tab(13).field_name  := 'EMPLOYEE_ID';
39         g_main_tab(13).field_value := NULL;
40         ---add equipment
41         g_main_tab(14).field_name  := 'EQUIPMENT';
42         g_main_tab(14).field_value := NULL;
43         g_main_tab(15).field_name  := 'EQUIPMENT_TYPE_ID'; --14
44         g_main_tab(15).field_value := NULL;
45         g_main_tab(16).field_name  := 'FROM_CREATION_DATE'; -- 15
46         g_main_tab(16).field_value := NULL;
47         g_main_tab(17).field_name  := 'FROM_JOB'; --16
48         g_main_tab(17).field_value := NULL;
49         g_main_tab(18).field_name  := 'FROM_LINE'; --17
50         g_main_tab(18).field_value := NULL;
51         g_main_tab(19).field_name  := 'FROM_LINES_IN_SALES_ORDER'; --18
52         g_main_tab(19).field_value := NULL;
53         g_main_tab(20).field_name  := 'FROM_PICK_SLIP'; --19
54         g_main_tab(20).field_value := NULL;
55         g_main_tab(21).field_name  := 'FROM_PO_HEADER_ID'; --20
56         g_main_tab(21).field_value := NULL;
57         g_main_tab(22).field_name  := 'FROM_PURCHASE_ORDER'; --21
58         g_main_tab(22).field_value := NULL;
59         g_main_tab(23).field_name  := 'FROM_REPLENSIHMENT_MO'; --22
60         g_main_tab(23).field_value := NULL;
61         g_main_tab(24).field_name  := 'FROM_REQUISITION'; --23
62         g_main_tab(24).field_value := NULL;
63         g_main_tab(25).field_name  := 'FROM_REQUISITION_HEADER_ID'; --24
64         g_main_tab(25).field_value := NULL;
65         g_main_tab(26).field_name  := 'FROM_RMA'; --25
66         g_main_tab(26).field_value := NULL;
67         g_main_tab(27).field_name  := 'FROM_RMA_HEADER_ID'; --26
68         g_main_tab(27).field_value := NULL;
69         g_main_tab(28).field_name  := 'FROM_SALES_ORDER_ID'; --27
70         g_main_tab(28).field_value := NULL;
71         g_main_tab(29).field_name  := 'FROM_SHIPMENT'; --28
72         g_main_tab(29).field_value := NULL;
73         g_main_tab(30).field_name  := 'FROM_SHIPMENT_DATE'; --29
74         g_main_tab(30).field_value := NULL;
75         g_main_tab(31).field_name  := 'FROM_START_DATE'; --30
76         g_main_tab(31).field_value := NULL;
77         g_main_tab(32).field_name  := 'FROM_TASK_PRIORITY'; --31
78         g_main_tab(32).field_value := NULL;
79         g_main_tab(33).field_name  := 'FROM_TASK_QUANTITY'; --32
80         g_main_tab(33).field_value := NULL;
81         g_main_tab(34).field_name  := 'FROM_TRANSFER_ISSUE_MO'; --33
82         g_main_tab(34).field_value := NULL;
83         g_main_tab(35).field_name  := 'INBOUND'; --34
84         g_main_tab(35).field_value := FND_API.G_FALSE;
85         g_main_tab(36).field_name  := 'INDEPENDENT_TASKS'; --35
86         g_main_tab(36).field_value := FND_API.G_TRUE;
87         g_main_tab(37).field_name  := 'INVENTORY_ITEM_ID'; --36
88         g_main_tab(37).field_value := NULL;
89         g_main_tab(38).field_name  := 'ITEM_CATEGORY_ID'; --37
90         g_main_tab(38).field_value := NULL;
91         g_main_tab(39).field_name  := 'LOADED'; --38
92         g_main_tab(39).field_value := FND_API.G_FALSE;
93         g_main_tab(40).field_name  := 'LOCATOR_ID'; --39
94         g_main_tab(40).field_value := NULL;
95         g_main_tab(41).field_name  := 'LPN_PUTAWAY_TASKS'; --40
96         g_main_tab(41).field_value := FND_API.G_TRUE;
97         g_main_tab(42).field_name  := 'MANUFACTURING'; --41
98         g_main_tab(42).field_value := FND_API.G_FALSE;
99         g_main_tab(43).field_name  := 'MANUFACTURING_TYPE'; --42
100         g_main_tab(43).field_value := NULL;
101         g_main_tab(44).field_name  := 'MO_ISSUE_TASKS'; --43
102         g_main_tab(44).field_value := FND_API.G_TRUE;
103         g_main_tab(45).field_name  := 'MO_TRANSFER_TASKS'; --44
104         g_main_tab(45).field_value := FND_API.G_TRUE;
105         g_main_tab(46).field_name  := 'OP_PLAN_ACTIVITY_ID'; --45
106         g_main_tab(46).field_value := NULL;
107         g_main_tab(47).field_name  := 'OP_PLAN_ID'; --46
108         g_main_tab(47).field_value := NULL;
109         g_main_tab(48).field_name  := 'OP_PLAN_TYPE_ID'; --47
110         g_main_tab(48).field_value := NULL;
111         ---add ORDER_TYPE
112         g_main_tab(49).field_name  := 'ORDER_TYPE';
113         g_main_tab(49).field_value := NULL;
114         g_main_tab(50).field_name  := 'OUTBOUND';  ---48
115         g_main_tab(50).field_value := FND_API.G_FALSE;
116         g_main_tab(51).field_name  := 'PENDING'; --49
117         g_main_tab(51).field_value := FND_API.G_FALSE;
118         g_main_tab(52).field_name  := 'PERSON_RESOURCE_ID'; --50
119         g_main_tab(52).field_value := NULL;
120         g_main_tab(53).field_name  := 'PLAN_ABORTED'; --51
121         g_main_tab(53).field_value := FND_API.G_FALSE;
122         g_main_tab(54).field_name  := 'PLAN_CANCELLED'; --52
123         g_main_tab(54).field_value := FND_API.G_FALSE;
124         g_main_tab(55).field_name  := 'PLAN_COMPLETED'; --53
125         g_main_tab(55).field_value := FND_API.G_FALSE;
126         g_main_tab(56).field_name  := 'PLAN_IN_PROGRESS'; --54
127         g_main_tab(56).field_value := FND_API.G_FALSE;
128         g_main_tab(57).field_name  := 'PLAN_PENDING'; --55
129         g_main_tab(57).field_value := FND_API.G_FALSE;
130         g_main_tab(58).field_name  := 'PLANNED_TASKS'; --56
131         g_main_tab(58).field_value := FND_API.G_TRUE;
132         g_main_tab(59).field_name  := 'QUEUED'; --57
133         g_main_tab(59).field_value := FND_API.G_FALSE;
134         g_main_tab(60).field_name  := 'REPLENISHMENT_TASKS'; --58
135         g_main_tab(60).field_value := FND_API.G_TRUE;
136         g_main_tab(61).field_name  := 'SHIP_METHOD_CODE'; --59
137         g_main_tab(61).field_value := NULL;
138         g_main_tab(62).field_name  := 'SHIP_TO_COUNTRY'; --60
139         g_main_tab(62).field_value := NULL;
140         g_main_tab(63).field_name  := 'SHIP_TO_POSTAL_CODE'; --61
141         g_main_tab(63).field_value := NULL;
142         g_main_tab(64).field_name  := 'SHIP_TO_STATE'; --62
143         g_main_tab(64).field_value := NULL;
144         g_main_tab(65).field_name  := 'SHIPMENT_PRIORITY'; --63
145         g_main_tab(65).field_value := NULL;
146         g_main_tab(66).field_name  := 'STAGING_MOVE'; --64
147         g_main_tab(66).field_value := FND_API.G_FALSE;
148         g_main_tab(67).field_name  := 'SUBINVENTORY'; --65
149         g_main_tab(67).field_value := NULL;
150         g_main_tab(68).field_name  := 'TO_CREATION_DATE'; --66
151         g_main_tab(68).field_value := NULL;
152         g_main_tab(69).field_name  := 'TO_JOB'; --67
153         g_main_tab(69).field_value := NULL;
154         g_main_tab(70).field_name  := 'TO_LINE'; --68
155         g_main_tab(70).field_value := NULL;
156         g_main_tab(71).field_name  := 'TO_LINES_IN_SALES_ORDER'; --69
157         g_main_tab(71).field_value := NULL;
158         g_main_tab(72).field_name  := 'TO_LOCATOR_ID'; --70
159         g_main_tab(72).field_value := NULL;
160         g_main_tab(73).field_name  := 'TO_PICK_SLIP'; --71
161         g_main_tab(73).field_value := NULL;
162         g_main_tab(74).field_name  := 'TO_PO_HEADER_ID'; --72
163         g_main_tab(74).field_value := NULL;
164         g_main_tab(75).field_name  := 'TO_PURCHASE_ORDER'; --73
165         g_main_tab(75).field_value := NULL;
166         g_main_tab(76).field_name  := 'TO_REPLENSIHMENT_MO'; --74
167         g_main_tab(76).field_value := NULL;
168         g_main_tab(77).field_name  := 'TO_REQUISITION'; --75
169         g_main_tab(77).field_value := NULL;
170         g_main_tab(78).field_name  := 'TO_REQUISITION_HEADER_ID';--76
171         g_main_tab(78).field_value := NULL;
172         g_main_tab(79).field_name  := 'TO_RMA'; --77
173         g_main_tab(79).field_value := NULL;
174         g_main_tab(80).field_name  := 'TO_RMA_HEADER_ID'; --78
175         g_main_tab(80).field_value := NULL;
176         g_main_tab(81).field_name  := 'TO_SALES_ORDER_ID'; --79
177         g_main_tab(81).field_value := NULL;
178         g_main_tab(82).field_name  := 'TO_SHIPMENT'; --80
179         g_main_tab(82).field_value := NULL;
180         g_main_tab(83).field_name  := 'TO_SHIPMENT_DATE'; --81
181         g_main_tab(83).field_value := NULL;
182         g_main_tab(84).field_name  := 'TO_START_DATE'; --82
183         g_main_tab(84).field_value := NULL;
184         g_main_tab(85).field_name  := 'TO_SUBINVENTORY'; --83
185         g_main_tab(85).field_value := NULL;
186         g_main_tab(86).field_name  := 'TO_TASK_PRIORITY'; --84
187         g_main_tab(86).field_value := NULL;
188         g_main_tab(87).field_name  := 'TO_TASK_QUANTITY'; --85
189         g_main_tab(87).field_value := NULL;
190         g_main_tab(88).field_name  := 'TO_TRANSFER_ISSUE_MO'; --86
191         g_main_tab(88).field_value := NULL;
192         g_main_tab(89).field_name  := 'TRIP_ID'; --87
193         g_main_tab(89).field_value := NULL;
194         g_main_tab(90).field_name  := 'UNRELEASED'; --88
195         g_main_tab(90).field_value := FND_API.G_FALSE;
196         g_main_tab(91).field_name  := 'USER_TASK_TYPE_ID'; --89
197         g_main_tab(91).field_value := NULL;
198         g_main_tab(92).field_name  := 'WAREHOUSING'; --90
199         g_main_tab(92).field_value := FND_API.G_FALSE;
200 	g_main_tab(93).field_name  := 'CROSSDOCK'; --91--Munish added column for crossdock
201         g_main_tab(93).field_value := FND_API.G_FALSE; --Munish initialized column value for crossdock
202 END initialize_main_table;
203 
204 -------------------------------------------------------------------------------------------------------------------
205 /*Procedure to log error message to the x_updated_tasks rec*/
206 -------------------------------------------------------------------------------------------------------------------
207 
208 PROCEDURE log_error(p_transaction_number IN NUMBER DEFAULT NULL ,
209 		    p_task_table IN WMS_TASK_MGMT_PUB.task_tab_type ,
210 		    p_error_msg IN VARCHAR2 ,
211 		    x_updated_tasks OUT NOCOPY WMS_TASK_MGMT_PUB.task_tab_type) IS
212 
213 BEGIN
214         IF p_transaction_number is NOT NULL THEN
215                 x_updated_tasks(1).RESULT := 'E';
216                 x_updated_tasks(1).ERROR  := p_error_msg;
217         ELSIF p_task_table.COUNT           > 0 THEN
218                 FOR i                     in 1..p_task_table.COUNT
219                 LOOP
220                         x_updated_tasks(i).RESULT := 'E';
221                         x_updated_tasks(i).ERROR  := p_error_msg;
222                 END LOOP;
223         END IF;
224 END log_error;
225 --------------------------------------------------------------------------------------------------------
226 /* Check Cartonization API checks if the cartonization_id can be stamped on the
227    set of input tasks.
228    Even if any one of the task fail validation, the API returns error.
229 */
230 --------------------------------------------------------------------------------------------------------
231 PROCEDURE check_cartonization ( p_task_table IN WMS_TASK_MGMT_PUB.task_tab_type ,
232 				p_new_carton_lpn_id IN NUMBER DEFAULT NULL ,
233 				x_error_msg OUT NOCOPY VARCHAR2 ,
234 				x_return_status OUT NOCOPY VARCHAR2 )
235 IS
236         CURSOR carton_lpn_csr(c_lpn_id NUMBER)
237         IS
238                 SELECT  lpn_context,
239                         organization_id,
240 			inventory_item_id
241                 FROM    wms_license_plate_numbers wlpn
242                 WHERE   wlpn.lpn_id=c_lpn_id;
243 
244         CURSOR carton_lpn_del_det (c_lpn_id NUMBER)
245         IS
246                 SELECT  wdd.delivery_detail_id,
247                         wdd.move_order_line_id
248                 FROM    wsh_delivery_details wdd,
249                         mtl_material_transactions_temp mmtt
250                 WHERE   wdd.move_order_line_id=mmtt.move_order_line_id
251                     AND wdd.organization_id   =mmtt.organization_id
252                     AND (mmtt.transfer_lpn_id  =c_lpn_id
253 		         OR mmtt.cartonization_id = c_lpn_id);
254 
255 --                  AND ROWNUM                < 2;
256 /*        CURSOR carton_lpn_del_det1 (c_lpn_id NUMBER)
257         IS
258                 SELECT  wdd.delivery_detail_id,
259                         wdd.move_order_line_id
260                 FROM    wsh_delivery_details wdd,
261                         mtl_material_transactions_temp mmtt
262                 WHERE   wdd.move_order_line_id=mmtt.move_order_line_id
263                     AND wdd.organization_id   =mmtt.organization_id
264                     AND mmtt.cartonization_id = c_lpn_id
265                     AND ROWNUM                = 1;*/
266         CURSOR c_get_delivery_id(p_delivery_detail_id NUMBER)
267         IS
268                 SELECT  delivery_id
269                 FROM    wsh_delivery_assignments
270                 WHERE   delivery_detail_id = p_delivery_detail_id;
271         CURSOR c_bulk_task(p_transaction_number NUMBER)
272         IS
273                 SELECT '1'
274                 FROM    mtl_material_transactions_temp
275                 WHERE   parent_line_id = p_transaction_number
276                 AND rownum         = 1;
277 
278         l_carton_lpn_ctx            NUMBER;
279         l_carton_lpn_org            NUMBER;
280         l_carton_del_det_id         NUMBER;
281         l_carton_del_id             NUMBER;
282         l_carton_move_order_line_id NUMBER;
283         l_temp_carton_grp_id        NUMBER;
284         l_carton_grp_id_tab WSH_UTIL_CORE.id_tab_type;
285         l_del_det_id_tab WSH_UTIL_CORE.id_tab_type;
286 	l_del_det_id_no_del_tab WSH_UTIL_CORE.id_tab_type;
287         l_del_id_tab WSH_UTIL_CORE.id_tab_type;
288         l_move_order_line_id_tab WSH_UTIL_CORE.id_tab_type;
289         l_bulk_task          VARCHAR2(2);
290         l_temp_del_detail_id NUMBER;
291         l_move_order_line_id NUMBER;
292         l_temp_del_id        NUMBER;
293         l_debug              NUMBER         := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
294         l_api_name           VARCHAR2(1000) := 'CHECK_CARTONIZATION';
295         l_error_msg          VARCHAR2(2000);
296         l_msg_count          NUMBER;
297 	p_action_prms       WSH_GLBL_VAR_STRCT_GRP.dd_action_parameters_rec_type;
298 	l_validation_level          NUMBER;
299 	l_grouping_rows            WSH_UTIL_CORE.id_tab_type;
300 	l_del_id_tab_new WSH_UTIL_CORE.id_tab_type;
301 	l_return_status    VARCHAR2(10);
302 	l_msg_data         varchar2(1000);
303 	l_delivery_name   VARCHAR2(30) := NULL;
304 	l_delivery_id     NUMBER;
305 	l_carton_lpn_itm_id   NUMBER;
306 
307 BEGIN
308         x_return_status := fnd_api.g_ret_sts_success;
309         OPEN carton_lpn_csr(p_new_carton_lpn_id);
310         FETCH carton_lpn_csr INTO l_carton_lpn_ctx,l_carton_lpn_org,l_carton_lpn_itm_id;
311         CLOSE carton_lpn_csr;
312         --if carton lpn is passed and is not valid then no need to proceed further
313         IF(l_carton_lpn_ctx NOT IN (5,8)) THEN
314                 x_return_status := fnd_api.g_ret_sts_error;
315                 fnd_message.set_name('WMS', 'WMS_CARTON_LPN_CTX_ERR');
316                 fnd_msg_pub.ADD;
317                 fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE, p_count => l_msg_count, p_data => x_error_msg );
318                 l_error_msg                      :='Invalid context for Carton LPN:'||p_new_carton_lpn_id;
319                 IF(l_debug                        = 1) THEN
320                         inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
321                 END IF;
322                 RETURN;
323 	ELSIF (l_carton_lpn_itm_id is NULL) THEN
324                 x_return_status := fnd_api.g_ret_sts_error;
325 		fnd_message.set_name('WMS', 'WMS_CARTONIZATION_ERR');
326 		fnd_msg_pub.ADD;
327 		fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE, p_count => l_msg_count, p_data => x_error_msg );
328                 l_error_msg                      :='Inventory item id is not present in carton LPN';
329                 IF(l_debug                        = 1) THEN
330                         inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
331                 END IF;
332                 RETURN;
333         END IF;
334 
335 /*        IF (l_carton_lpn_ctx = 5 ) THEN
336                 OPEN carton_lpn_del_det1(p_new_carton_lpn_id);
337                 FETCH   carton_lpn_del_det1
338                 INTO    l_carton_del_det_id,
339                         l_carton_move_order_line_id;
340                 CLOSE carton_lpn_del_det1;
341                 IF (l_carton_del_det_id is NOT NULL and l_carton_move_order_line_id is NOT NULL) THEN
342                         l_del_det_id_tab(l_del_det_id_tab.count                +1) := l_carton_del_det_id;
343                         l_move_order_line_id_tab(l_move_order_line_id_tab.count+1) := l_carton_move_order_line_id;
344                 END IF;
345         END IF;*/
346         IF (l_carton_lpn_ctx in (5,8) ) THEN
347                 --get carton del_det_id and mover_oder_line_id
348                 OPEN carton_lpn_del_det(p_new_carton_lpn_id);
349 		LOOP
350                 FETCH carton_lpn_del_det
351 		INTO l_carton_del_det_id,
352 		     l_carton_move_order_line_id;
353 
354 		l_del_det_id_tab(l_del_det_id_tab.count                +1) := l_carton_del_det_id;
355                 l_move_order_line_id_tab(l_move_order_line_id_tab.count+1) := l_carton_move_order_line_id;
356 		EXIT WHEN carton_lpn_del_det%NOTFOUND;
357 		END LOOP;
358 
359                 CLOSE carton_lpn_del_det;
360 
361         END IF;
362         FOR i IN 1..p_task_table.count
363         LOOP
364                 IF (p_task_table(i).organization_id <> l_carton_lpn_org) THEN
365                         x_return_status             := fnd_api.g_ret_sts_error;
366                         fnd_message.set_name('WMS', 'WMS_CARTON_LPN_ORG_ERR');
367                         fnd_msg_pub.ADD;
368                         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE, p_count => l_msg_count, p_data => x_error_msg );
369                         l_error_msg                      :='Organization is not same for Carton LPN and Task';
370                         IF(l_debug                        = 1) THEN
371                                 inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
372                         END IF;
373                         RETURN;
374                 END IF;
375                 --Bulk tasks cannot be cartonized
376                 OPEN c_bulk_task(p_task_table(i).transaction_number);
377                 FETCH c_bulk_task INTO l_bulk_task;
378                 IF c_bulk_task%NOTFOUND THEN
379                         CLOSE c_bulk_task;
380                 ELSE
381                         x_return_status := fnd_api.g_ret_sts_error;
382                         fnd_message.set_name('WMS', 'WMS_CARTON_BULK_ERR');
383                         fnd_msg_pub.ADD;
384                         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE, p_count => l_msg_count, p_data => x_error_msg );
385                         l_error_msg                      :='Bulk Tasks cannot be cartonized';
386                         IF(l_debug                        = 1) THEN
387                                 inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
388                         END IF;
389                         CLOSE c_bulk_task;
390                         RETURN;
391                 END IF;
392         END LOOP;
393         --Fetch the delivery_detail_id's and move order line id's associated with the input task/tasks.
394         FOR i IN 1..p_task_table.count
395         LOOP
396                 BEGIN
397                         SELECT  wdd.delivery_detail_id,
398                                 wdd.move_order_line_id
399                         INTO    l_temp_del_detail_id,
400                                 l_move_order_line_id
401                         FROM    wsh_delivery_details wdd,
402                                 mtl_material_transactions_temp mmtt
403                         WHERE   wdd.move_order_line_id   = mmtt.move_order_line_id
404                             AND mmtt.transaction_temp_id = p_task_table(i).transaction_number;
405                 EXCEPTION
406                 WHEN OTHERS THEN
407                         l_temp_del_detail_id := NULL;
408                 END;
409                 IF (l_temp_del_detail_id IS NULL) THEN
410                         x_return_status := fnd_api.g_ret_sts_error;
411                         fnd_message.set_name('WMS', 'WMS_CARTONIZATION_ERR');
412                         fnd_msg_pub.ADD;
413                         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => x_error_msg );
414                         l_error_msg                      :='Data not present in WDD for the corresponding task :'||p_task_table(i).transaction_number;
415                         IF(l_debug                        = 1) THEN
416                                 inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
417                         END IF;
418                         RETURN;
419                 ELSE
420                         l_del_det_id_tab(l_del_det_id_tab.count                +1) := l_temp_del_detail_id;
421                         l_move_order_line_id_tab(l_move_order_line_id_tab.count+1) := l_move_order_line_id;
422                 END IF;
423         END LOOP;
424         --Fetch the delivery_id associated with the tasks.
425         FOR i IN 1..l_del_det_id_tab.COUNT
426         LOOP
427                 BEGIN
428                         SELECT  delivery_id
429                         INTO    l_temp_del_id
430                         FROM    wsh_delivery_assignments
431                         WHERE   delivery_detail_id = l_del_det_id_tab(i);
432                 EXCEPTION
433                 WHEN OTHERS THEN
434                         l_temp_del_id := NULL;
435 			--fetch the dd id's with null delivery_id into l_del_det_id_no_del_tab.
436 			l_del_det_id_no_del_tab(l_del_det_id_no_del_tab.count+1) := l_del_det_id_tab(i);
437                 END;
438                 l_del_id_tab(l_del_id_tab.count +1) := l_temp_del_id;
439         END LOOP;
440         --Need to check if all the deliveries are same or not.
441         --This needs to be done only if count of delivery_detail_id is >1.
442         IF l_del_det_id_tab.COUNT > 1 THEN
443                 FOR i            IN 1..l_del_id_tab.COUNT
444                 LOOP
445 			IF (l_del_id_tab(i) is NOT NULL) THEN
446 			     --copy the value to a new structure
447 			     l_del_id_tab_new(l_del_id_tab_new.count +1) := l_del_id_tab(i);
448 			END IF;
449 		END LOOP;
450 
451 	        IF (l_del_id_tab_new.COUNT = 0) THEN
452 		   --all the delivery_id's are null,
453 		   --Call delivery_grouping API.
454 
455 		   WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping( p_line_rows     => l_del_det_id_tab,
456                                     x_grouping_rows => l_grouping_rows,
457                                     x_return_status => l_return_status);
458 
459 	          IF l_return_status = 'S' then
460 		    -- check if all the values in l_grouping_rows are same.
461 		     FOR i in 1..l_grouping_rows.COUNT LOOP
462 			   IF (l_grouping_rows(1) <> l_grouping_rows(i)) THEN
463                                 x_return_status      := fnd_api.g_ret_sts_error;
464                                 fnd_message.set_name('WMS', 'WMS_CARTON_DEL_GP_ERR');
465                                 fnd_msg_pub.ADD;
466                                 fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => x_error_msg );
467                                 l_error_msg                      :='Delivery grouping mismatch,cartonization cannot be done';
468                                 IF(l_debug                        = 1) THEN
469                                         inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
470                                 END IF;
471                                 RETURN;
472 		            END IF;
473 		   END LOOP;
474 
475 		  END IF;
476 
477 		ELSE --l_del_id_Tab_new.count > 0
478 		   --check if the delivery_id's that are present in l_del_id_tab_new are all same.
479                    FOR i in 1..l_del_id_tab_new.COUNT LOOP
480 			   IF (l_del_id_tab_new(1) <> l_del_id_tab_new(i)) THEN
481                                 x_return_status      := fnd_api.g_ret_sts_error;
482                                 fnd_message.set_name('WMS', 'WMS_CARTON_DEL_ERR');
483                                 fnd_msg_pub.ADD;
484                                 fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => x_error_msg );
485                                 l_error_msg                      :='Delivery mismatch,cartonization cannot be done';
486                                 IF(l_debug                        = 1) THEN
487                                         inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
488                                 END IF;
489                                 RETURN;
490 		            END IF;
491 		   END LOOP;
492 		   --del_id's present are all same.
493 		   --call WSH API by passing deliery_id from l_del_id_tab_new and l_del_det_id_no_del_tab
494 		   --and see if the same delivery_id can be stamped on the null delivery records.
495 		   --This needs to be done only if there are some delivery_detail_ids for which there is
496 		   --no delivery association.
497 		   IF (l_del_det_id_no_del_tab.COUNT > 0 ) THEN
498 
499 			l_delivery_id := l_del_id_tab_new(1);
500 
501 			wsh_delivery_details_grp.detail_to_delivery(
502 				p_api_version        =>    1.0,
503 				p_init_msg_list      =>    FND_API.G_FALSE,
504 				p_commit             =>    FND_API.G_FALSE,
505 				p_validation_level   =>    l_validation_level,
506 				x_return_status      =>    l_return_status,
507 				x_msg_count          =>    l_msg_count,
508 				x_msg_data           =>    l_msg_data,
509 				p_TabOfDelDets       =>    l_del_det_id_no_del_tab,
510 				p_action             =>    'ASSIGN',
511 				p_delivery_id        =>    l_delivery_id,
512 				p_delivery_name      =>    l_delivery_name,
513 				p_action_prms        =>    p_action_prms);
514 
515 		        IF l_return_status <> 'S' THEN
516 				fnd_message.set_name('WMS', 'WMS_CARTONIZATION_ERR');
517                                 fnd_msg_pub.ADD;
518                                 fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => x_error_msg );
519                                 l_error_msg                      :='Error returned from WSH API';
520                                 IF(l_debug                        = 1) THEN
521                                         inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
522                                 END IF;
523 				RETURN;
524 		        END IF;
525 		   END IF;
526                 END IF;
527         END IF;
528 
529 END check_cartonization;
530 -------------------------------------------------------------------------------------------------------------------
531 /*This procedure checks if the various attributes that are passed can be updated
532 on the provided task*/
533 -------------------------------------------------------------------------------------------------------------------
534 
535 PROCEDURE modify_single_task( p_task_rec IN WMS_TASK_MGMT_PUB.task_output_rectype,
536         P_new_task_status                IN NUMBER DEFAULT NULL,
537         P_new_task_priority              IN NUMBER DEFAULT NULL,
538         P_new_task_type                  IN VARCHAR2 DEFAULT NULL,
539         P_new_carton_lpn_id              IN NUMBER DEFAULT NULL,
540         p_new_operation_plan_id          IN NUMBER DEFAULT NULL,
541         p_output_task_rec OUT NOCOPY WMS_TASK_MGMT_PUB.task_output_rectype,
542         p_op_plan_rec IN WMS_TASK_MGMT_PUB.op_plan_rec)
543 IS
544         l_lpn              VARCHAR2(30);
545         l_return_status    VARCHAR2(10);
546         l_count NUMBER DEFAULT 0;
547         l_operation_plan_type_id NUMBER;
548         l_msg_data         fnd_new_messages.MESSAGE_TEXT%TYPE;
549         l_msg_count        NUMBER;
550         l_error_code       NUMBER;
551         l_std_task_type    NUMBER;
552         l_usr_task_type_id NUMBER;
553         l_err_msg          VARCHAR2(240);
554         l_debug            NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
555         l_api_name VARCHAR2(1000) := 'MODIFY_SINGLE_TASK';
556         l_msg      VARCHAR2(2000);
557 
558 	Cursor c_usr_task_type(p_std_task_type NUMBER,
559                 p_operation_code               VARCHAR2,
560 		p_org_id                       NUMBER) IS
561 		SELECT  standard_operation_id
562                 FROM    BOM_STANDARD_OPERATIONS_V
563                 WHERE   wms_task_type  = p_std_task_type
564                 AND operation_code = p_operation_code
565 		AND organization_id    = p_org_id    ;
566 
567     --operation plan code changes start 6888354
568 
569     CURSOR c_plan_detail(v_operation_plan_id NUMBER) IS
570      SELECT  operation_plan_detail_id
571            , operation_sequence
572            , is_in_inventory
573            , operation_type
574      FROM WMS_OP_PLAN_DETAILS
575      WHERE operation_plan_id  = v_operation_plan_id
576      AND   operation_sequence = (SELECT MIN(operation_sequence)
577                                        FROM WMS_OP_PLAN_DETAILS
578                                       WHERE operation_plan_id=v_operation_plan_id);
579 
580     CURSOR C_OP_PLANS_B(v_operation_plan_id NUMBER) IS
581      SELECT  OPERATION_PLAN_ID,
582              SYSTEM_TASK_TYPE,
583              ACTIVITY_TYPE_ID,
584              PLAN_TYPE_ID
585      FROM WMS_OP_PLANS_B
586      WHERE operation_plan_id=v_operation_plan_id;
587 
588      CURSOR C_OP_OPERATIONS_STATUS(v_source_task_id NUMBER) IS
589 	    SELECT STATUS   FROM    wms_op_plan_instances
590 	    WHERE   ((
591 		      source_task_id in
592 		    (SELECT parent_line_id
593 		    FROM    mtl_material_transactions_temp
594 		    WHERE   transaction_temp_id =v_source_task_id
595 		      )) OR (source_task_id =v_source_task_id )); ---contains parent only
596 
597     l_op_plan_b_rec                 C_OP_PLANS_B%ROWTYPE;
598     l_operation_plan_detail_rec     c_plan_detail%ROWTYPE;
599     l_op_operation_status_rec       C_OP_OPERATIONS_STATUS%ROWTYPE;
600     l_src_tran_id    NUMBER;
601     l_src_parent_id    NUMBER;
602 
603     --operation plan code changes end  6888354
604 
605 
606 BEGIN
607 --6888354 START
608 IF (p_task_rec.status_id = 9 ) THEN
609         /*If the original task status is Active, check if the user whom the tasks
610         assigned is logged on to the system. If the user is logged on, updating the same is not allowed. */
611         BEGIN
612                 SELECT  COUNT(*)
613                 INTO    l_count
614                 FROM    WMS_DISPATCHED_TASKS wdt1
615                 WHERE   wdt1.status              = 9
616                     AND wdt1.TRANSACTION_TEMP_ID =p_task_rec.TRANSACTION_NUMBER
617                     AND EXISTS
618                         (SELECT 1
619                         FROM    MTL_MOBILE_LOGIN_HIST MMLH,
620                                 WMS_DISPATCHED_TASKS wdt
621                         WHERE   wdt1.TRANSACTION_TEMP_ID = wdt.TRANSACTION_TEMP_ID
622                             AND MMLH.USER_ID             = wdt1.LAST_UPDATED_BY
623                             AND MMLH.LOGOFF_DATE        IS NULL
624                             AND MMLH.EVENT_MESSAGE      IS NULL
625                         );
626         EXCEPTION
627         WHEN OTHERS THEN
628                 NULL;
629                 l_msg     := 'Error in querying Active tasks';
630                 IF(l_debug = 1) THEN
631                         inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
632                 END IF;
633                 p_output_task_rec.RESULT := 'E';
634                 p_output_task_rec.ERROR  := l_err_msg;
635                 RETURN;
636         END;
637         IF l_count > 0 THEN
638                 fnd_message.set_name('WMS', 'WMS_ATF_INVALID_TASK_STATUS');--new message  WMS_ATF_ACTIVE_TASK_EXP
639                 fnd_msg_pub.ADD;
640                 fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
641                 l_msg                              := 'Active task can be updated if tasks assigned to user is logged off the system';
642                 IF(l_debug                          = 1) THEN
643                         inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
644                 END IF;
645                 p_output_task_rec.RESULT := 'E';
646                 p_output_task_rec.ERROR  := l_err_msg;
647                 RETURN;
648         END IF;
649 ELSIF (p_task_rec.status_id      = 3 ) THEN
650 		/*A task can be in dispatched status when a group of tasks are dispatched to a mobile user
651 		and one of the tasks in the group is in ACTIVE status and the rest in DISPATCHED status.
652 		Updating such dispatched tasks to pending/unreleased status SHOULD NOT be allowed. */
653 		BEGIN
654 				SELECT  COUNT(*)
655 				INTO    l_count
656 				FROM    mtl_material_transactions_temp mmtt,
657 						WMS_DISPATCHED_TASKS wdt
658 				WHERE   mmtt.transaction_temp_id = wdt.transaction_temp_id
659 				AND wdt.transaction_temp_id  =p_task_rec.TRANSACTION_NUMBER
660 				AND wdt.status               = 3
661 				AND EXISTS
662 					(SELECT 1
663 					FROM    WMS_DISPATCHED_TASKS wdt2
664 					WHERE   wdt2.person_id            = p_task_rec.PERSON_ID
665 						AND wdt2.status               = 9
666 						AND wdt2.task_method         IS NOT NULL
667 						AND wdt2.transaction_temp_id IN
668 						(SELECT transaction_temp_id
669 						FROM    mtl_material_transactions_temp mmtt1
670 						WHERE
671 						DECODE(wdt.TASK_METHOD, 'CARTON', mmtt1.cartonization_id, 'PICK_SLIP', mmtt1.pick_slip_number, 'DISCRETE', mmtt1.pick_slip_number, mmtt1.transaction_source_id) =
672 						DECODE(wdt.TASK_METHOD, 'CARTON', mmtt.cartonization_id, 'PICK_SLIP', mmtt.pick_slip_number, 'DISCRETE', mmtt.pick_slip_number, mmtt.transaction_source_id)
673 						)
674 					);
675 		EXCEPTION
676 		WHEN OTHERS THEN
677 				NULL;
678 				l_msg     := 'Error in querying Dispatched tasks';
679 				IF(l_debug = 1) THEN
680 						inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
681 				END IF;
682 				p_output_task_rec.RESULT := 'E';
683 				p_output_task_rec.ERROR  := l_err_msg;
684 				RETURN;
685 		END;
686 		IF (l_count > 0 ) THEN                                             --ANY OF GROUP TASK IS active
687 				fnd_message.set_name('WMS', 'WMS_ATF_INVALID_TASK_STATUS');--new message    WMS_ATF_DISPATCH_TASK_EXP
688 				fnd_msg_pub.ADD;
689 				fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
690 				l_msg                              := 'Dispatcher task can be updated only if any of the task in group is not in Active status';
691 				IF(l_debug                          = 1) THEN
692 						inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
693 				END IF;
694 				p_output_task_rec.RESULT := 'E';
695 				p_output_task_rec.ERROR  := l_err_msg;
696 				RETURN;
697 		END IF;
698 END IF;
699 
700         IF (p_new_task_status IS NOT NULL) THEN
701                 --check the current task status and then only do the updated.
702                 --status_id = 1==>Pending,2==>Qued,8==>Unreleased,9==>Active.
703                  IF (p_task_rec.status_id = 9 ) THEN
704                       IF p_new_task_status  in (1,8) THEN
705                            p_output_task_rec.status_id := p_new_task_status;
706                       ELSE
707                           fnd_message.set_name('WMS', 'WMS_ATF_INVALID_TASK_STATUS');
708                           fnd_msg_pub.ADD;
709                           fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
710                           l_msg                            := 'Active task can be moved only to Pending or Unreleased state';
711                           IF(l_debug                        = 1) THEN
712                                   inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
713                           END IF;
714                           p_output_task_rec.RESULT := 'E';
715                           p_output_task_rec.ERROR  := l_err_msg;
716                           RETURN;
717                       END IF;
718 	                 ELSIF (p_task_rec.status_id = 3 ) THEN
719                       IF p_new_task_status  in (1,8) THEN
720                          p_output_task_rec.status_id := p_new_task_status;
721                       ELSE
722                           fnd_message.set_name('WMS', 'WMS_ATF_INVALID_TASK_STATUS');
723                           fnd_msg_pub.ADD;
724                           fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
725                           l_msg                            := 'Dispatcher task can be moved only to Pending or Unreleased state';
726                           IF(l_debug                        = 1) THEN
727                                   inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
728                           END IF;
729                           p_output_task_rec.RESULT := 'E';
730                           p_output_task_rec.ERROR  := l_err_msg;
731                           RETURN;
732                       END IF; --6888354 END
733                  ELSIF (p_task_rec.status_id = 8 ) THEN
734                       IF (p_new_task_status =1 OR (p_new_task_status = 2 AND p_task_rec.task_type_id <> 2 ))THEN
735                           p_output_task_rec.status_id := p_new_task_status;
736                       ELSE
737                           fnd_message.set_name('WMS', 'WMS_ATF_INVALID_TASK_STATUS');
738                           fnd_msg_pub.ADD;
739                           fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
740                           l_msg                            := 'Unreleased task can be moved only to Pending or Queued state';
741                           IF(l_debug                        = 1) THEN
742                                   inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
743                           END IF;
744                           p_output_task_rec.RESULT := 'E';
745                           p_output_task_rec.ERROR  := l_err_msg;
746                           RETURN;
747                       END IF;
748                  ELSIF (p_task_rec.status_id = 1 ) THEN
749                       IF ( p_new_task_status = 2 AND p_task_rec.task_type_id <> 2 )THEN
750                           p_output_task_rec.status_id := p_new_task_status;
751                       ELSE
752                           fnd_message.set_name('WMS', 'WMS_ATF_INVALID_TASK_STATUS');
753                           fnd_msg_pub.ADD;
754                           fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
755                           l_msg                            := 'Pending task can be moved only to Queued state';
756                           IF(l_debug                        = 1) THEN
757                                   inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
758                           END IF;
759                           p_output_task_rec.RESULT := 'E';
760                           p_output_task_rec.ERROR  := l_err_msg;
761                           RETURN;
762                       END IF;
763  	         ELSE
764                           fnd_message.set_name('WMS', 'WMS_ATF_INVALID_TASK_STATUS');
765                           fnd_msg_pub.ADD;
766                           fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
767                           l_msg                            := 'Invalid task status';
768                           IF(l_debug                        = 1) THEN
769                                   inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
770                           END IF;
771                           p_output_task_rec.RESULT := 'E';
772                           p_output_task_rec.ERROR  := l_err_msg;
773                           RETURN;
774                  END IF;
775 
776         END IF;
777 
778 	IF (P_new_task_priority IS NOT NULL) THEN
779 		IF (p_task_rec.task_type_id <> 2) THEN
780 		        p_output_task_rec.priority := p_new_task_priority;
781 		ELSE
782 			fnd_message.set_name('WMS', 'WMS_INVALID_TASK');
783 			fnd_msg_pub.ADD;
784 			fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
785 			l_msg                            := 'Inbound task priority cannot be updated';
786 			IF(l_debug                        = 1) THEN
787 				inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
788 			END IF;
789 			p_output_task_rec.RESULT := 'E';
790 			p_output_task_rec.ERROR  := l_err_msg;
791 			RETURN;
792 		END IF;
793         END IF;
794 
795         IF (P_new_carton_lpn_id IS NOT NULL) THEN
796                 SELECT  license_plate_number
797                 INTO    l_lpn
798                 FROM    wms_license_plate_numbers
799                 WHERE   lpn_id                       =P_new_carton_lpn_id;
800                 p_output_task_rec.cartonization_lpn := l_lpn;
801                 p_output_task_rec.cartonization_id  := P_new_carton_lpn_id;
802         END IF;
803         IF (P_new_task_type IS NOT NULL) THEN
804                 OPEN c_usr_task_type(p_task_rec.task_type_id,p_new_task_type,p_task_rec.organization_id);
805                 FETCH c_usr_task_type INTO l_usr_task_type_id;
806                 IF c_usr_task_type%NOTFOUND THEN
807                         fnd_message.set_name('WMS', 'WMS_INVALID_USER_TASK');--new message
808                         fnd_msg_pub.ADD;
809                         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
810                         l_msg                            := 'Standard task type associated with the user task is different from the current standard task type';
811                         IF(l_debug                        = 1) THEN
812                                 inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
813                         END IF;
814                         p_output_task_rec.RESULT := 'E';
815                         p_output_task_rec.ERROR  := l_err_msg;
816                         RETURN;
817                 ELSE
818                         p_output_task_rec.user_task_type_id := l_usr_task_type_id;
819                 END IF;
820                 CLOSE c_usr_task_type;
821         END IF;
822         IF (p_new_operation_plan_id IS NOT NULL) THEN
823             IF (p_op_plan_rec.organization_id IS NOT NULL) THEN
824                 IF (p_task_rec.organization_id             <> p_op_plan_rec.organization_id) THEN
825                         IF(p_op_plan_rec.common_to_all_org <> 'Y') THEN
826                                 fnd_message.set_name('WMS', 'WMS_OPER_PLAN_ORG_INVALID');--new message
827                                 fnd_msg_pub.ADD;
828                                 fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
829                                 p_output_task_rec.RESULT         := 'E';
830                                 p_output_task_rec.ERROR          := l_err_msg;
831                                 l_msg                            := 'Organization associated with the operation plan is different from that of the task';
832                                 IF(l_debug                        = 1) THEN
833                                         inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
834                                 END IF;
835                                 RETURN;
836                         END IF;
837                 END IF;
838             END IF;
839 
840 	    IF (p_task_rec.OPERATION_PLAN_ID IS NOT NULL  AND  p_op_plan_rec.plan_type_id IS NOT NULL) THEN
841 		    SELECT PLAN_TYPE_ID
842 		    INTO l_operation_plan_type_id
843 		    FROM wms_op_plans_b
844 		    WHERE OPERATION_PLAN_ID=p_task_rec.OPERATION_PLAN_ID;
845 
846 		    IF (l_operation_plan_type_id IS NOT NULL ) THEN
847 			/*	An inspection operation plan can be replaced with another inspection operation plan and
848 			  like wise a standard operation plan can be replaced only with another Standard operation plan.   */
849 			/*only in case of cross dock tasks, a cross dock operation can be replaced with another cross dock operation plan or
850 			  it can also be replaced with a non-cross dock Operation plan    */
851 			  IF ( l_operation_plan_type_id   = 3  OR
852 			     ( p_op_plan_rec.plan_type_id = 1 AND l_operation_plan_type_id = 1) OR
853 			     ( p_op_plan_rec.plan_type_id = 2  AND  l_operation_plan_type_id = 2 )) THEN
854 				p_output_task_rec.operation_plan_id := p_new_operation_plan_id;
855 			  ELSE
856 			      fnd_message.set_name('WMS', 'WMS_OPERTN_PLAN_ID_INVALID');--new message
857 			      fnd_msg_pub.ADD;
858 			      fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
859 			      p_output_task_rec.RESULT         := 'E';
860 			      p_output_task_rec.ERROR          := l_err_msg;
861 			      l_msg                            := 'Inspection/Standard operation plan can only be replaced with another Inspection/Standard operation plan
862 								   and cross dock operation can be replaced with another cross dock operation plan or non-cross dock Operation plan ';
863 			      IF(l_debug                        = 1) THEN
864 				      inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
865 			      END IF;
866 			      RETURN;
867 			  END IF;
868 		    ELSE
869 			fnd_message.set_name('WMS', 'WMS_OPERTN_PLAN_ID_INVALID');--new message
870 			fnd_msg_pub.ADD;
871 			fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
872 			p_output_task_rec.RESULT         := 'E';
873 			p_output_task_rec.ERROR          := l_err_msg;
874 			l_msg                            := 'Current or new operation plan type is NULL';
875 			IF(l_debug                        = 1) THEN
876 				inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
877 			END IF;
878 			  RETURN;
879 		    END IF;
880 	    END IF;
881 
882 
883             IF ( p_op_plan_rec.activity_type_id = 1) THEN                   --INBOUND CASE
884                         IF(p_task_rec.task_type_id <> 2) THEN                   --putaway
885                                 fnd_message.set_name('WMS', 'WMS_INVALID_OP_PLAN_ACTIVITY');--new message
886                                 fnd_msg_pub.ADD;
887                                 fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
888                                 p_output_task_rec.ERROR          := l_err_msg;
889                                 p_output_task_rec.RESULT         := 'E';
890                                 l_msg                            := 'Mismatch in the operation plan activity type and task type';
891                                 IF(l_debug                        = 1) THEN
892                                         inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
893                                 END IF;
894                                 RETURN;
895                         ELSE
896                            --operation plan  code changes start 6888354
897                            BEGIN
898                                    SAVEPOINT inb_op_sp;
899                                    OPEN C_OP_OPERATIONS_STATUS(p_task_rec.transaction_number);
900                                    FETCH   C_OP_OPERATIONS_STATUS
901                                    INTO    l_op_operation_status_rec;
902                                    IF (l_op_operation_status_rec.STATUS=1) THEN
903                                            OPEN C_OP_PLANS_B(p_new_operation_plan_id);
904                                            FETCH   C_OP_PLANS_B
905                                            INTO    l_op_plan_b_rec;
906                                            IF (C_OP_PLANS_B%NOTFOUND) THEN
907                                                    IF (l_debug=1) THEN
908                                                            inv_trx_util_pub.trace('Records not found in WMS_OP_PLANS_B for given p_new_operation_plan_id');
909                                                            fnd_message.set_name('WMS', ' WMS_INVALID_TASK');--new message
910                                                            fnd_msg_pub.ADD;
911                                                            fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
912                                                            l_msg                              := 'No of Records found in WMS_OP_PLANS_B for given operation plan id';
913                                                            IF(l_debug                          = 1) THEN
914                                                                    inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
915                                                            END IF;
916                                                            p_output_task_rec.RESULT := 'E';
917                                                            p_output_task_rec.ERROR  := l_err_msg;
918                                                            RETURN;
919                                                    END IF;
920                                                    CLOSE C_OP_PLANS_B;
921                                            ELSE
922                                                    inv_trx_util_pub.trace('updating wms_op_plan_instances.........');
923                                                    UPDATE wms_op_plan_instances
924                                                    SET     OPERATION_PLAN_ID=l_op_plan_b_rec.OPERATION_PLAN_ID,
925                                                            -- SYSTEM_TASK_TYPE =l_op_plan_b_rec.SYSTEM_TASK_TYPE , Bug#8978253
926                                                            ACTIVITY_TYPE_ID =l_op_plan_b_rec.ACTIVITY_TYPE_ID ,
927                                                            PLAN_TYPE_ID     =l_op_plan_b_rec.PLAN_TYPE_ID
928                                                    WHERE ((source_task_id  IN
929                                                            (SELECT parent_line_id
930                                                            FROM    mtl_material_transactions_temp
931                                                            WHERE   transaction_temp_id=p_task_rec.transaction_number
932                                                            ))
933                                                         OR (source_task_id = p_task_rec.transaction_number)); --update parent records only
934                                                    OPEN c_plan_detail(p_new_operation_plan_id);
935                                                    FETCH   c_plan_detail
936                                                    INTO    l_operation_plan_detail_rec;
937                                                    IF (c_plan_detail%NOTFOUND) THEN
938                                                            IF (l_debug=1) THEN
939                                                                    inv_trx_util_pub.trace('Records not found in WMS_OP_PLAN_DETAILS for given operation plan id');
940                                                                    fnd_message.set_name('WMS', ' WMS_INVALID_TASK');--new message
941                                                                    fnd_msg_pub.ADD;
942                                                                    fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
943                                                                    l_msg                              := 'No of Records found in WMS_OP_PLAN_DETAILS for given operation plan id';
944                                                                    IF(l_debug                          = 1) THEN
945                                                                            inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
946                                                                    END IF;
947                                                                    p_output_task_rec.RESULT := 'E';
948                                                                    p_output_task_rec.ERROR  := l_err_msg;
949                                                                    RETURN;
950                                                            END IF;
951                                                            CLOSE c_plan_detail;
952                                                    ELSE
953                                                            inv_trx_util_pub.trace('updating wms_op_operation_instances.........');
954                                                            UPDATE wms_op_operation_instances
955                                                            --SET     OPERATION_TYPE          =l_operation_plan_detail_rec.OPERATION_TYPE           , Bug#8978253
956                                                            SET     OPERATION_PLAN_DETAIL_ID=l_operation_plan_detail_rec.OPERATION_PLAN_DETAIL_ID ,
957                                                                    OPERATION_SEQUENCE      =l_operation_plan_detail_rec.OPERATION_SEQUENCE       ,
958                                                                    --ACTIVITY_TYPE=l_operation_plan_detail_rec.ACTIVITY_TYPE ,
959                                                                    IS_IN_INVENTORY =l_operation_plan_detail_rec.IS_IN_INVENTORY
960                                                            WHERE ((source_task_id IN
961                                                                    (SELECT TRANSACTION_TEMP_ID
962                                                                    FROM    mtl_material_transactions_temp
963                                                                    WHERE   parent_line_id=p_task_rec.transaction_number
964                                                                    ))
965                                                                 OR ( source_task_id =p_task_rec.transaction_number));--update all the children records only
966                                                    END IF;
967                                            END IF;
968 
969                                    ELSE
970                                            fnd_message.set_name('WMS', ' WMS_INVALID_TASK');--new message
971                                            fnd_msg_pub.ADD;
972                                            fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
973                                            l_msg                              := 'STATUS in wms_op_plan_instances is not pending';
974                                            IF(l_debug                          = 1) THEN
975                                                    inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
976                                            END IF;
977                                            p_output_task_rec.RESULT := 'E';
978                                            p_output_task_rec.ERROR  := l_err_msg;
979                                            RETURN;
980                                    END IF; --  l_op_operation_status_rec.STATUS end
981 
982                                    SELECT  parent_line_id
983                                    INTO    l_src_parent_id
984                                    FROM    mtl_material_transactions_temp
985                                    WHERE   TRANSACTION_TEMP_ID=p_task_rec.transaction_number;
986                                    IF (l_src_parent_id       IS NULL) THEN
987                                            l_src_tran_id     :=p_task_rec.transaction_number;
988                                            UPDATE mtl_material_transactions_temp mmtt
989                                            SET     mmtt.OPERATION_PLAN_ID=p_new_operation_plan_id
990                                            WHERE   mmtt.PARENT_LINE_ID   = l_src_tran_id;--update child record
991                                    ELSE
992                                            l_src_tran_id:=l_src_parent_id;
993                                            UPDATE mtl_material_transactions_temp mmtt
994                                            SET     mmtt.OPERATION_PLAN_ID   =p_new_operation_plan_id
995                                            WHERE   mmtt.TRANSACTION_TEMP_ID = l_src_tran_id;--update parent record
996                                    END IF;                                                  --parent if end
997                                    p_output_task_rec.operation_plan_id := p_new_operation_plan_id;
998 
999                            EXCEPTION
1000                            WHEN OTHERS THEN
1001                                    ROLLBACK TO inb_op_sp;
1002                                    p_output_task_rec.RESULT := 'E';
1003                                    inv_trx_util_pub.trace('Exception Occured while updating operation plan');
1004                                    RETURN;
1005                            END;
1006                         --operation plan  code changes end 6888354
1007 
1008                         END IF;
1009             ELSE --outbound case
1010                         --for outbound case wopi , wooi is not impacted as I could observe by creating records.
1011                         --just updating the plan id should be enough.needs to be  investigated further
1012                         IF (p_task_rec.task_type_id <> 1) THEN                  --if not a pick task then error out
1013                                 fnd_message.set_name('WMS', 'WMS_INVALID_OP_PLAN_ACTIVITY');--new message
1014                                 fnd_msg_pub.ADD;
1015                                 fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_err_msg );
1016                                 l_msg                            := 'Mismatch in the operation plan activity type and task type';
1017                                 IF(l_debug                        = 1) THEN
1018                                         inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
1019                                 END IF;
1020                                 p_output_task_rec.RESULT := 'E';
1021                                 p_output_task_rec.ERROR  := l_err_msg;
1022                                 RETURN;
1023                         ELSE --update the mmtt with new plan
1024                                 /*UPDATE mtl_material_transactions_temp
1025                                         SET operation_plan_id        = p_new_operation_plan_id
1026                                 WHERE   transaction_temp_id          = p_task_rec.transaction_number;*/
1027                                 p_output_task_rec.operation_plan_id := p_new_operation_plan_id;
1028                         END IF;
1029             END IF;
1030         END IF;
1031 EXCEPTION
1032 WHEN OTHERS THEN
1033         NULL;
1034 END modify_single_task;
1035 
1036 -------------------------------------------------------------------------------------------------------------------
1037 /*This procedure is to create a dummy task table with only the task_idThis will be used if user gives the task_id as input.*/
1038 PROCEDURE Create_Task_Table ( p_transaction_number IN NUMBER DEFAULT NULL ,
1039 			      x_task_table OUT NOCOPY WMS_TASK_MGMT_PUB.task_tab_type )IS
1040 
1041         l_task_table WMS_TASK_MGMT_PUB.task_tab_type ;
1042         l_task_rec WMS_TASK_MGMT_PUB.task_output_rectype;
1043 BEGIN
1044         l_task_rec.TRANSACTION_NUMBER := p_transaction_number;
1045         l_task_table(1)               := l_task_rec ;
1046         x_task_table                  := l_task_table;
1047 END Create_Task_Table ;
1048 -------------------------------------------------------------------------------------------------------------------
1049 
1050 /*This procedure will validate one task at a a time.*/
1051 PROCEDURE validate_task_id ( p_init_msg_list IN VARCHAR2 DEFAULT 'Y' ,
1052 			     p_transaction_number IN NUMBER DEFAULT NULL ,
1053 			     p_action IN VARCHAR2 DEFAULT NULL,       --6850212
1054 			     x_validation_status OUT NOCOPY VARCHAR2 ,
1055 			     x_error_msg OUT NOCOPY VARCHAR2 ,
1056 			     x_return_status OUT NOCOPY VARCHAR2 )IS
1057 
1058         l_wdt_status     NUMBER := 0 ;
1059         l_task_exists    NUMBER := 0;
1060         l_msg_count      NUMBER ;
1061         l_task_type      NUMBER ;
1062         l_parent_line_id NUMBER := 0 ;
1063 BEGIN
1064         --initialize output variables.
1065         x_validation_status := 'S';
1066         x_return_status     := 'S';
1067         x_error_msg         := NULL;
1068         --Initialize message pub
1069         IF p_init_msg_list ='Y' THEN
1070                 fnd_msg_pub.initialize;
1071         END IF;
1072         BEGIN
1073                 --Make sure there is a task with this Id
1074                 SELECT  1                  ,
1075                         mmtt.wms_task_type ,
1076                         parent_line_id
1077                 INTO    l_task_exists ,
1078                         l_task_type   ,
1079                         l_parent_line_id
1080                 FROM    MTL_MATERIAL_TRANSACTIONS_TEMP mmtt
1081                 WHERE   mmtt.transaction_temp_id=p_transaction_number;
1082         EXCEPTION
1083         WHEN NO_DATA_FOUND THEN
1084                 null;
1085         WHEN OTHERS THEN
1086                 x_return_status := 'E';
1087         END ;
1088         IF (l_task_exists = 0 ) THEN
1089                 --Checkif it is a cycle count task
1090                 SELECT  count(1)
1091                 INTO    l_task_exists
1092                 FROM    Mtl_Cycle_Count_Entries mcce
1093                 WHERE   mcce.cycle_count_entry_id = p_transaction_number
1094                     AND mcce.entry_status_code   IN( 1 , 3) ;
1095                 l_task_type                      := 3 ; --cycle count.
1096         END IF ;
1097         IF (l_task_exists = 0 ) THEN
1098                 --Still no task, this is invalid id.
1099                 fnd_message.set_name('WMS', 'INVALID_TASK');
1100                 fnd_msg_pub.ADD;
1101                 x_validation_status:= 'E';
1102         END IF;
1103         --Need to check status in WDT .
1104         BEGIN
1105                 SELECT  wdt.status
1106                 INTO    l_wdt_status
1107                 FROM    Wms_Dispatched_Tasks wdt
1108                 WHERE   wdt.transaction_temp_id = p_transaction_number ;
1109         EXCEPTION
1110         WHEN NO_DATA_FOUND THEN
1111                 --No WDT, so task must bein status pending/unreleased.
1112                 l_wdt_status := 0 ;
1113         WHEN OTHERS THEN
1114                 x_return_status := 'E';
1115         END;
1116         IF (l_wdt_status = 0 AND l_task_type= 2 ) THEN  --Only for putaway tasks.
1117                 SELECT  MAX(wdt.status )
1118                 INTO    l_wdt_status
1119                 FROM    Wms_Dispatched_Tasks wdt
1120                 WHERE   wdt.transaction_temp_id in
1121                         (SELECT transaction_temp_id      --To check the child tasks
1122                         FROM    MTL_MATERIAL_TRANSACTIONS_TEMP mmtt
1123                         WHERE   mmtt.parent_line_id = p_transaction_number
1124                 UNION SELECT  mmtt2.transaction_temp_id    --To check the siblings
1125                 FROM    MTL_MATERIAL_TRANSACTIONS_TEMP mmtt1 ,
1126                         MTL_MATERIAL_TRANSACTIONS_TEMP mmtt2
1127                 WHERE   mmtt1.transaction_temp_id = p_transaction_number
1128                     AND mmtt2.parent_line_id      = mmtt1.parent_line_id
1129         UNION SELECT  mmtt2.transaction_temp_id     ---To check the parent task.
1130         FROM    MTL_MATERIAL_TRANSACTIONS_TEMP mmtt1 ,
1131                 MTL_MATERIAL_TRANSACTIONS_TEMP mmtt2
1132         WHERE   mmtt1.transaction_temp_id = p_transaction_number
1133             AND mmtt2.transaction_temp_id = mmtt1.parent_line_id
1134                         ) ;
1135         END IF;
1136         IF ( l_parent_line_id         > 0 AND l_task_type = 1 ) THEN --This is nbulk pick
1137                 IF (l_parent_line_id <> p_transaction_number ) THEN
1138                         --The input is a child of bulk task.Fail validation.
1139                         fnd_message.set_name('WMS', 'INVALID_TASK');
1140                         fnd_msg_pub.ADD;
1141                         x_validation_status:= 'E';
1142                 END IF;
1143         END IF;
1144         --	6850212 Start
1145 	IF p_action = 'MODIFY' THEN
1146 		IF (l_wdt_status NOT IN (0,2,3,9)) THEN
1147 			--fnd_message.set_name('WMS', 'WMS_ATF_INVALID_TASK_STATUS');
1148 			--fnd_msg_pub.ADD;
1149 			x_validation_status:= 'E';
1150 		END IF;
1151 	ELSE
1152 		IF( l_wdt_status NOT  IN (0,2) ) THEN
1153 			--fnd_message.set_name('WMS', 'WMS_ATF_INVALID_TASK_STATUS');
1154 			--fnd_msg_pub.ADD;
1155 			x_validation_status:= 'E';
1156 		 END IF;
1157 	END IF;
1158 	--	6850212 End
1159   fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => x_error_msg );
1160 EXCEPTION
1161 WHEN OTHERS THEN
1162         x_return_status := 'E';
1163 END validate_task_id ;
1164 -------------------------------------------------------------------------------------------------------------------
1165 
1166 /*Main procedure for task validation. */
1167 PROCEDURE validate_tasks ( p_init_msg_list IN VARCHAR2 DEFAULT 'Y' ,
1168 			   p_transaction_number IN NUMBER DEFAULT NULL ,
1169 			   p_task_table IN WMS_TASK_MGMT_PUB.task_tab_type ,
1170 			   p_action IN VARCHAR2 DEFAULT NULL,       --6850212
1171 			   x_wms_task OUT NOCOPY WMS_TASK_MGMT_PUB.task_tab_type ,
1172 			   x_return_status OUT NOCOPY VARCHAR2 ) IS
1173 
1174         l_validate_task_ret VARCHAR2(1) ;
1175         l_error_msg         VARCHAR2(240);
1176         l_task_table WMS_TASK_MGMT_PUB.task_tab_type ;
1177 BEGIN
1178         x_return_status := 'S';
1179         IF ( p_transaction_number IS NOT NULL ) THEN
1180                 Create_Task_Table (p_transaction_number => p_transaction_number,  --create a dummy table
1181                 x_task_table                            => l_task_table );
1182         ELSE
1183                 l_task_table := p_task_table ;
1184         END IF;
1185         FOR i IN 1..l_task_table.count
1186         LOOP --Validate each task record individually.
1187                 validate_task_id ( p_transaction_number => l_task_table(i).TRANSACTION_NUMBER,
1188 		                   x_validation_status => l_validate_task_ret ,
1189 				   p_action=>p_action,--6850212
1190                                    x_error_msg => l_error_msg ,
1191 				   x_return_status => x_return_status );
1192                 IF (l_validate_task_ret                 ='E' ) THEN
1193                         l_task_table(i).result         := 'E';
1194                         l_task_table(i).error          := l_error_msg;
1195                 END IF;
1196         END LOOP;
1197         x_wms_task := l_task_table;
1198 EXCEPTION
1199 WHEN OTHERS THEN
1200         x_return_status := 'E';
1201 END validate_tasks ;
1202 ---------------------------------------------------------------------------------------------------------
1203 
1204 /*This procedure checks if cartonization can be done on the taks.
1205 If the API returns success, then carton_lpn_id can be stamped on the tasks*/
1206 /*PROCEDURE check_cartonization ( p_task_table IN WMS_TASK_MGMT_PUB.task_tab_type ,
1207 				p_new_carton_lpn_id IN NUMBER DEFAULT NULL ,
1208 				x_error_msg OUT NOCOPY VARCHAR2 ,
1209 				x_return_status OUT NOCOPY VARCHAR2 ) IS
1210 
1211         CURSOR carton_lpn_csr(c_lpn_id NUMBER)
1212         IS
1213                 SELECT  lpn_context,
1214                         organization_id
1215                 FROM    wms_license_plate_numbers wlpn
1216                 WHERE   wlpn.lpn_id=c_lpn_id;
1217         CURSOR carton_lpn_del_det (c_lpn_id NUMBER)
1218         IS
1219                 SELECT  wdd.delivery_detail_id,
1220                         wdd.move_order_line_id
1221                 FROM    wsh_delivery_details wdd,
1222                         mtl_material_transactions_temp mmtt
1223                 WHERE   wdd.move_order_line_id=mmtt.move_order_line_id
1224                     AND wdd.organization_id   =mmtt.organization_id
1225                     AND mmtt.transfer_lpn_id  =c_lpn_id
1226                     AND ROWNUM                < 2;
1227         CURSOR carton_lpn_del_det1 (c_lpn_id NUMBER)
1228         IS
1229                 SELECT  wdd.delivery_detail_id,
1230                         wdd.move_order_line_id
1231                 FROM    wsh_delivery_details wdd,
1232                         mtl_material_transactions_temp mmtt
1233                 WHERE   wdd.move_order_line_id=mmtt.move_order_line_id
1234                     AND wdd.organization_id   =mmtt.organization_id
1235                     AND mmtt.cartonization_id = c_lpn_id
1236                     AND ROWNUM                = 1;
1237         CURSOR c_get_delivery_id(p_delivery_detail_id NUMBER)
1238         IS
1239                 SELECT  delivery_id
1240                 FROM    wsh_delivery_assignments
1241                 WHERE   delivery_detail_id = p_delivery_detail_id;
1242         CURSOR c_bulk_task(p_transaction_number NUMBER)
1243         IS
1244                 SELECT '1'
1245                 FROM    mtl_material_transactions_temp
1246                 WHERE   parent_line_id = p_transaction_number
1247                     AND rownum         = 1;
1248         l_carton_lpn_ctx            NUMBER;
1249         l_carton_lpn_org            NUMBER;
1250         l_carton_del_det_id         NUMBER;
1251         l_carton_del_id             NUMBER;
1252         l_carton_move_order_line_id NUMBER;
1253         l_temp_carton_grp_id        NUMBER;
1254         l_carton_grp_id_tab WSH_UTIL_CORE.id_tab_type;
1255         l_del_det_id_tab WSH_UTIL_CORE.id_tab_type;
1256         l_del_id_tab WSH_UTIL_CORE.id_tab_type;
1257         l_move_order_line_id_tab WSH_UTIL_CORE.id_tab_type;
1258         l_bulk_task          VARCHAR2(2);
1259         l_temp_del_detail_id NUMBER;
1260         l_move_order_line_id NUMBER;
1261         l_temp_del_id        NUMBER;
1262         l_debug              NUMBER         := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1263         l_api_name           VARCHAR2(1000) := 'CHECK_CARTONIZATION';
1264         l_error_msg          VARCHAR2(2000);
1265         l_msg_count          NUMBER;
1266 BEGIN
1267         x_return_status := fnd_api.g_ret_sts_success;
1268         OPEN carton_lpn_csr(p_new_carton_lpn_id);
1269         FETCH carton_lpn_csr INTO l_carton_lpn_ctx,l_carton_lpn_org;
1270         CLOSE carton_lpn_csr;
1271         --if carton lpn is passed and is not valid then no need to proceed further
1272         IF(l_carton_lpn_ctx NOT IN (5,8)) THEN
1273                 x_return_status := fnd_api.g_ret_sts_error;
1274                 fnd_message.set_name('WMS', 'WMS_CARTONIZATION_ERR');
1275                 fnd_msg_pub.ADD;
1276                 fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => x_error_msg );
1277                 l_error_msg                      :='Invalid context for Carton LPN:'||p_new_carton_lpn_id;
1278                 IF(l_debug                        = 1) THEN
1279                         inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
1280                 END IF;
1281                 RETURN;
1282         END IF;
1283         IF (l_carton_lpn_ctx = 5 ) THEN
1284                 OPEN carton_lpn_del_det1(p_new_carton_lpn_id);
1285                 FETCH   carton_lpn_del_det1
1286                 INTO    l_carton_del_det_id,
1287                         l_carton_move_order_line_id;
1288                 CLOSE carton_lpn_del_det1;
1289                 IF (l_carton_del_det_id is NOT NULL and l_carton_move_order_line_id is NOT NULL) THEN
1290                         l_del_det_id_tab(l_del_det_id_tab.count                +1) := l_carton_del_det_id;
1291                         l_move_order_line_id_tab(l_move_order_line_id_tab.count+1) := l_carton_move_order_line_id;
1292                 END IF;
1293         END IF;
1294         IF (l_carton_lpn_ctx = 8 ) THEN
1295                 --get carton del_det_id and mover_oder_line_id
1296                 OPEN carton_lpn_del_det(p_new_carton_lpn_id);
1297                 FETCH carton_lpn_del_det INTO l_carton_del_det_id,l_carton_move_order_line_id;
1298                 CLOSE carton_lpn_del_det;
1299                 l_del_det_id_tab(l_del_det_id_tab.count                +1) := l_carton_del_det_id;
1300                 l_move_order_line_id_tab(l_move_order_line_id_tab.count+1) := l_carton_move_order_line_id;
1301         END IF;
1302         FOR i IN 1..p_task_table.count
1303         LOOP
1304                 IF (p_task_table(i).organization_id <> l_carton_lpn_org) THEN
1305                         x_return_status             := fnd_api.g_ret_sts_error;
1306                         fnd_message.set_name('WMS', 'WMS_CARTONIZATION_ERR');
1307                         fnd_msg_pub.ADD;
1308                         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => x_error_msg );
1309                         l_error_msg                      :='Organization is not same for Carton LPN and Task';
1310                         IF(l_debug                        = 1) THEN
1311                                 inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
1312                         END IF;
1313                         RETURN;
1314                 END IF;
1315                 --Bulk tasks cannot be cartonized
1316                 OPEN c_bulk_task(p_task_table(i).transaction_number);
1317                 FETCH c_bulk_task INTO l_bulk_task;
1318                 IF c_bulk_task%NOTFOUND THEN
1319                         CLOSE c_bulk_task;
1320                 ELSE
1321                         x_return_status := fnd_api.g_ret_sts_error;
1322                         fnd_message.set_name('WMS', 'WMS_CARTONIZATION_ERR');
1323                         fnd_msg_pub.ADD;
1324                         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => x_error_msg );
1325                         l_error_msg                      :='Bulk Tasks cannot be cartonized';
1326                         IF(l_debug                        = 1) THEN
1327                                 inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
1328                         END IF;
1329                         CLOSE c_bulk_task;
1330                         RETURN;
1331                 END IF;
1332         END LOOP;
1333         --Fetch the delivery_detail_id's and move order line id's associated with the input task/tasks.
1334         FOR i IN 1..p_task_table.count
1335         LOOP
1336                 BEGIN
1337                         SELECT  wdd.delivery_detail_id,
1338                                 wdd.move_order_line_id
1339                         INTO    l_temp_del_detail_id,
1340                                 l_move_order_line_id
1341                         FROM    wsh_delivery_details wdd,
1342                                 mtl_material_transactions_temp mmtt
1343                         WHERE   wdd.move_order_line_id   = mmtt.move_order_line_id
1344                             AND mmtt.transaction_temp_id = p_task_table(i).transaction_number;
1345                 EXCEPTION
1346                 WHEN OTHERS THEN
1347                         l_temp_del_detail_id := NULL;
1348                 END;
1349                 IF (l_temp_del_detail_id IS NULL) THEN
1350                         x_return_status := fnd_api.g_ret_sts_error;
1351                         fnd_message.set_name('WMS', 'WMS_CARTONIZATION_ERR');
1352                         fnd_msg_pub.ADD;
1353                         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => x_error_msg );
1354                         l_error_msg                      :='Data not present in WDD for the corresponding task :'||p_task_table(i).transaction_number;
1355                         IF(l_debug                        = 1) THEN
1356                                 inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
1357                         END IF;
1358                         RETURN;
1359                 ELSE
1360                         l_del_det_id_tab(l_del_det_id_tab.count                +1) := l_temp_del_detail_id;
1361                         l_move_order_line_id_tab(l_move_order_line_id_tab.count+1) := l_move_order_line_id;
1362                 END IF;
1363         END LOOP;
1364         --Fetch the delivery_id associated with the tasks.
1365         FOR i IN 1..l_del_det_id_tab.COUNT
1366         LOOP
1367                 BEGIN
1368                         SELECT  delivery_id
1369                         INTO    l_temp_del_id
1370                         FROM    wsh_delivery_assignments
1371                         WHERE   delivery_detail_id = l_del_det_id_tab(i);
1372                 EXCEPTION
1373                 WHEN OTHERS THEN
1374                         l_temp_del_id := NULL;
1375                 END;
1376                 l_del_id_tab(l_del_id_tab.count +1) := l_temp_del_id;
1377         END LOOP;
1378         --Need to check if all the deliveries are same or not.
1379         --This needs to be done only if count of delivery_detail_id is >1.
1380         IF l_del_det_id_tab.COUNT > 1 THEN
1381                 FOR i            IN 1..l_del_id_tab.COUNT
1382                 LOOP
1383                         IF nvl(l_del_id_tab(1),-999) <> nvl(l_del_id_tab(i),-999) THEN
1384                                 x_return_status      := fnd_api.g_ret_sts_error;
1385                                 fnd_message.set_name('WMS', 'WMS_CARTONIZATION_ERR');
1386                                 fnd_msg_pub.ADD;
1387                                 fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => x_error_msg );
1388                                 l_error_msg                      :='Delivery mismatch,cartonization cannot be done';
1389                                 IF(l_debug                        = 1) THEN
1390                                         inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
1391                                 END IF;
1392                                 RETURN;
1393                         END IF;
1394                 END LOOP;
1395         END IF;
1396         --If delivery_id is null, then check for the carton_group_id
1397         --See if the delivery_id is null on the first record
1398         --If it is null, then it will be null on all the rest as per the above validation.
1399         IF ((l_del_id_tab(1) is NULL) AND (l_del_det_id_tab.COUNT > 1))THEN
1400                 FOR i                                            IN 1..l_move_order_line_id_tab.COUNT
1401                 LOOP
1402                         BEGIN
1403                                 SELECT  mtrl.carton_grouping_id
1404                                 INTO    l_temp_carton_grp_id
1405                                 FROM    mtl_txn_request_lines mtrl
1406                                 WHERE   line_id = l_move_order_line_id_tab(i);
1407                         EXCEPTION
1408                         WHEN OTHERS THEN
1409                                 l_temp_carton_grp_id := NULL;
1410                         END;
1411                         l_carton_grp_id_tab(l_carton_grp_id_tab.count+1) := l_temp_carton_grp_id;
1412                 END LOOP;
1413                 FOR i IN 1..l_carton_grp_id_tab.COUNT
1414                 LOOP
1415                         IF nvl(l_carton_grp_id_tab(1),-999) <> nvl(l_carton_grp_id_tab(i),-999) THEN
1416                                 x_return_status             := fnd_api.g_ret_sts_error;
1417                                 fnd_message.set_name('WMS', 'WMS_CARTONIZATION_ERR');
1418                                 fnd_msg_pub.ADD;
1419                                 fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => x_error_msg );
1420                                 l_error_msg                      :='Carton group mismatch,cartonization cannot be done';
1421                                 IF(l_debug                        = 1) THEN
1422                                         inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
1423                                 END IF;
1424                                 RETURN;
1425                         END IF;
1426                 END LOOP;
1427         END IF;
1428 END check_cartonization;*/
1429 
1430 -------------------------------------------------------------------------------------------------------------------
1431 
1432 --START OF SPLIT TASK
1433 PROCEDURE print_msg(p_procedure IN VARCHAR2 ,
1434 		    p_msg IN VARCHAR2) IS
1435 
1436 BEGIN
1437         inv_log_util.trace(p_msg ,g_pkg_name || '.' || p_procedure ||  ': ' ,9);
1438         --    dbms_output.put_line(p_procedure||' : ' || p_msg);
1439 END print_msg;
1440 
1441 -------------------------------------------------------------------------------------------------------------------
1442 /*PROCEDURE validate_quantities()
1443 This procedure performs all quantity and UOM validations based on the inputs in form of tasks and
1444 split quantity table passed
1445 */
1446 -------------------------------------------------------------------------------------------------------------------
1447 PROCEDURE validate_quantities( p_transaction_temp_id IN NUMBER ,
1448 			       p_split_quantities IN task_qty_tbl_type ,
1449 			       x_lot_control_code OUT NOCOPY NUMBER ,
1450 			       x_serial_control_code OUT NOCOPY NUMBER ,
1451 			       x_split_uom_quantities OUT NOCOPY qty_changed_tbl_type ,
1452 			       x_return_status OUT NOCOPY VARCHAR2 ,
1453 			       x_msg_data OUT NOCOPY VARCHAR2 ,
1454 			       x_msg_count OUT NOCOPY VARCHAR2 ) IS
1455 
1456         l_mmtt_inventory_item_id     NUMBER;
1457         l_mmtt_primary_quantity      NUMBER;
1458         l_mmtt_transaction_quantity  NUMBER;
1459         l_mmtt_transaction_uom_code  NUMBER;
1460         l_mmtt_organization_id       NUMBER;
1461         l_mmtt_transaction_uom       VARCHAR2(3);
1462         l_mmtt_item_primary_uom_code VARCHAR2(3);
1463         l_lot_control_code           NUMBER;
1464         l_serial_control_code        NUMBER;
1465         l_decimal_precision          CONSTANT NUMBER := 5;
1466         l_mtlt_transaction_qty       NUMBER          := 0;
1467         l_msnt_transaction_qty       NUMBER          := 0;
1468         l_task_tbl_transaction_qty   NUMBER          := 0;
1469         l_procedure_name             VARCHAR2(20)    := 'VALIDATE_QUANTITIES';
1470         l_task_tbl_primary_qty       NUMBER          := 0;
1471         l_sum_tbl_transaction_qty    NUMBER          := 0;
1472 		l_sum_tbl_secondary_qty      NUMBER          := 0; -- Added for Bug 16099247
1473         l_sum_tbl_primary_qty        NUMBER          := 0;
1474         l_remaining_primary_qty      NUMBER          := 0;
1475         l_remaining_transaction_qty  NUMBER          := 0;
1476         l_mmtt_secondary_uom         VARCHAR2(3);  -- Added for Bug 16099247
1477         l_mmtt_sec_transaction_qty   NUMBER;       -- Added for Bug 16099247
1478         l_tracking_quantity_ind      VARCHAR2(3);  -- Added for Bug 16099247
1479 BEGIN
1480         x_return_status := 'E';
1481         IF g_debug       = 1 THEN
1482                 print_msg(l_procedure_name, 'Entered');
1483         END IF;
1484         IF p_split_quantities.COUNT = 0 THEN
1485                 x_return_status    := 'E';
1486                 IF g_debug          = 1 THEN
1487                         print_msg(l_procedure_name, 'Quantities table is empty, exiting');
1488                 END IF;
1489                 RETURN;
1490         END IF;
1491         SELECT  transaction_uom       ,
1492                 inventory_item_id     ,
1493                 primary_quantity      ,
1494                 transaction_quantity  ,
1495                 item_primary_uom_code ,
1496                 transaction_uom       ,
1497                 organization_id       ,
1498                 secondary_uom_code    ,        -- Added for Bug 16099247
1499                 secondary_transaction_quantity -- Added for Bug 16099247
1500         INTO    l_mmtt_transaction_uom       ,
1501                 l_mmtt_inventory_item_id     ,
1502                 l_mmtt_primary_quantity      ,
1503                 l_mmtt_transaction_quantity  ,
1504                 l_mmtt_item_primary_uom_code ,
1505                 l_mmtt_transaction_uom       ,
1506                 l_mmtt_organization_id       ,
1507 				l_mmtt_secondary_uom         , -- Added for Bug 16099247
1508                 l_mmtt_sec_transaction_qty     -- Added for Bug 16099247
1509         FROM    mtl_material_transactions_temp
1510         WHERE   transaction_temp_id = p_transaction_temp_id;
1511         SELECT  lot_control_code ,
1512                 serial_number_control_code,
1513 				tracking_quantity_ind -- Added for Bug 16099247
1514         INTO    l_lot_control_code ,
1515                 l_serial_control_code,
1516 				l_tracking_quantity_ind -- Added for Bug 16099247
1517         FROM    mtl_system_items_b
1518         WHERE   inventory_item_id = l_mmtt_inventory_item_id
1519             AND organization_id   = l_mmtt_organization_id;
1520         x_lot_control_code       := l_lot_control_code;
1521         x_serial_control_code    := l_serial_control_code;
1522         IF g_debug                = 1 THEN
1523                 FOR i            IN p_split_quantities.FIRST .. p_split_quantities.LAST
1524                 LOOP
1525                         print_msg(l_procedure_name ,  ' Inside For loop i = ' || i ||
1526 			' Task :' || p_transaction_temp_id ||
1527 			' Quantity : ' ||p_split_quantities(i).quantity ||
1528 			' Suggested UOM :' ||p_split_quantities(i).uom ||
1529 			' MMTT transaction UOM :' ||l_mmtt_transaction_uom||
1530       ' MMTT secondary UOM :'||l_mmtt_secondary_uom||
1531       'MMTT secondary qty:'||l_mmtt_sec_transaction_qty); -- Added for Bug 16099247
1532                 END LOOP;
1533         END IF;
1534         FOR i IN p_split_quantities.FIRST .. p_split_quantities.LAST
1535         LOOP
1536                 IF p_split_quantities(i).uom IS NULL THEN
1537                         IF g_debug = 1 THEN
1538                                 print_msg(l_procedure_name , 'UOM cannot be passed as NULL');
1539                         END IF;
1540                         x_return_status := 'E';
1541                         RETURN;
1542                 END IF;
1543                 IF RTRIM(LTRIM(p_split_quantities(i).uom)) NOT IN (l_mmtt_item_primary_uom_code,l_mmtt_transaction_uom) THEN
1544                         x_return_status                        := 'E';
1545                         IF g_debug                              = 1 THEN
1546                                 print_msg(l_procedure_name , 'UOM validation failed, only primary or transaction UOM allowed :');
1547                         END IF;
1548                         RETURN;
1549                 END IF;
1550                 -- All UOMs are same
1551                 IF l_mmtt_transaction_uom                               = l_mmtt_item_primary_uom_code THEN
1552                         x_split_uom_quantities(i).primary_quantity     := p_split_quantities(i).quantity;
1553                         x_split_uom_quantities(i).transaction_quantity := p_split_quantities(i).quantity;
1554 						-- Added for Bug 16099247
1555                         IF (l_tracking_quantity_ind='PS' AND p_split_quantities(i).secondary_qty is NULL) THEN
1556                           x_split_uom_quantities(i).secondary_quantity :=  inv_convert.inv_um_convert(item_id => l_mmtt_inventory_item_id ,
1557 											                                                                                PRECISION => l_decimal_precision ,
1558 											                                                                                from_quantity => p_split_quantities(i).quantity ,
1559 											                                                                                from_unit => l_mmtt_item_primary_uom_code ,
1560 											                                                                                to_unit => l_mmtt_secondary_uom ,
1561 											                                                                                from_name => NULL ,
1562 											                                                                                to_name => NULL);
1563                         ELSE
1564                            x_split_uom_quantities(i).secondary_quantity := p_split_quantities(i).secondary_qty;
1565                         END IF;
1566                 ELSE
1567                         IF l_mmtt_transaction_uom = p_split_quantities(i).uom THEN
1568                                 IF g_debug        = 1 THEN
1569                                         print_msg(l_procedure_name , ' mmtt transaction UOM is same as UOM in quantity table');
1570                                 END IF;
1571                                 l_task_tbl_transaction_qty                     := p_split_quantities(i).quantity;
1572                                 x_split_uom_quantities(i).transaction_quantity := p_split_quantities(i).quantity;
1573 								-- Added for Bug 16099247
1574                                 IF (l_tracking_quantity_ind='PS' AND p_split_quantities(i).secondary_qty is NULL) THEN
1575                                   x_split_uom_quantities(i).secondary_quantity :=  inv_convert.inv_um_convert(item_id => l_mmtt_inventory_item_id ,
1576 											                                                                                        PRECISION => l_decimal_precision ,
1577 											                                                                                        from_quantity => p_split_quantities(i).quantity ,
1578 											                                                                                        from_unit => l_mmtt_transaction_uom ,
1579 											                                                                                        to_unit => l_mmtt_secondary_uom ,
1580 											                                                                                        from_name => NULL ,
1581 											                                                                                        to_name => NULL);
1582 								ELSE
1583 								  x_split_uom_quantities(i).secondary_quantity := p_split_quantities(i).secondary_qty;
1584 								END IF;
1585                         ELSE
1586                                 IF g_debug = 1 THEN
1587                                         print_msg(l_procedure_name , ' mmtt transaction UOM quantity table UOM are not same, calling inv_convert.inv_um_convert with :');
1588                                         print_msg(l_procedure_name,  ' item_id  : '||l_mmtt_inventory_item_id);
1589                                         print_msg(l_procedure_name,  ' PRECISION : '|| l_decimal_precision);
1590                                         print_msg(l_procedure_name, ' from_quantity :'|| p_split_quantities(i).quantity);
1591                                         print_msg(l_procedure_name, ' from_unit :'||p_split_quantities(i).uom);
1592                                         print_msg(l_procedure_name, ' to_unit :'||l_mmtt_transaction_uom);
1593                                 END IF;
1594                                 l_task_tbl_transaction_qty   := inv_convert.inv_um_convert( item_id => l_mmtt_inventory_item_id ,
1595 											    PRECISION => l_decimal_precision ,
1596 											    from_quantity => p_split_quantities(i).quantity ,
1597 											    from_unit => p_split_quantities(i).uom ,
1598 											    to_unit => l_mmtt_transaction_uom ,
1599 											    from_name => NULL ,
1600 											    to_name => NULL );
1601 								-- Added for Bug 16099247
1602 								IF (l_tracking_quantity_ind='PS' AND p_split_quantities(i).secondary_qty is NULL) THEN
1603 												x_split_uom_quantities(i).secondary_quantity :=  inv_convert.inv_um_convert(item_id => l_mmtt_inventory_item_id ,
1604 											                                                                                PRECISION => l_decimal_precision ,
1605 											                                                                                from_quantity => p_split_quantities(i).quantity ,
1606 											                                                                                from_unit => p_split_quantities(i).uom ,
1607 											                                                                                to_unit => l_mmtt_secondary_uom ,
1608 											                                                                                from_name => NULL ,
1609 											                                                                                to_name => NULL);
1610 								ELSE
1611 												x_split_uom_quantities(i).secondary_quantity := p_split_quantities(i).secondary_qty;
1612 								END IF;
1613                                 IF l_task_tbl_transaction_qty = -9999 THEN
1614                                         IF g_debug            = 1 THEN
1615                                                 print_msg(l_procedure_name, ' No conversion defined from :'||p_split_quantities(i).uom|| ' to :'|| l_mmtt_transaction_uom || ' , or UOM does not exist.');
1616                                         END IF;
1617                                         x_return_status := 'E';
1618                                         RETURN;
1619                                 END IF;
1620                                 x_split_uom_quantities(i).transaction_quantity := l_task_tbl_transaction_qty;
1621                         END IF;
1622                         IF l_mmtt_item_primary_uom_code = p_split_quantities(i).uom THEN
1623                                 IF g_debug              = 1 THEN
1624                                         print_msg(l_procedure_name , ' primary UOM is same as UOM in quantity table');
1625                                 END IF;
1626                                 l_task_tbl_primary_qty                     := p_split_quantities(i).quantity;
1627                                 x_split_uom_quantities(i).primary_quantity := p_split_quantities(i).quantity;
1628 								-- Added for Bug 16099247
1629 								IF (l_tracking_quantity_ind='PS' AND p_split_quantities(i).secondary_qty is NULL) THEN
1630 												x_split_uom_quantities(i).secondary_quantity :=  inv_convert.inv_um_convert(item_id => l_mmtt_inventory_item_id ,
1631 											                                                                                PRECISION => l_decimal_precision ,
1632 											                                                                                from_quantity => p_split_quantities(i).quantity ,
1633 											                                                                                from_unit => p_split_quantities(i).uom ,
1634 											                                                                                to_unit => l_mmtt_secondary_uom ,
1635 											                                                                                from_name => NULL ,
1636 											                                                                                to_name => NULL);
1637 								ELSE
1638 												x_split_uom_quantities(i).secondary_quantity := p_split_quantities(i).secondary_qty;
1639 								END IF;
1640                         ELSE
1641                                 IF g_debug = 1 THEN
1642                                         print_msg(l_procedure_name , ' primary UOM not same as UOM in quantity table');
1643                                         print_msg(l_procedure_name,  ' For primary quantity ');
1644                                         print_msg(l_procedure_name,  ' item_id  : '||l_mmtt_inventory_item_id);
1645                                         print_msg(l_procedure_name,  ' PRECISION : '|| l_decimal_precision);
1646                                         print_msg(l_procedure_name, ' from_quantity :'|| p_split_quantities(i).quantity);
1647                                         print_msg(l_procedure_name, ' from_unit :'||p_split_quantities(i).uom);
1648                                         print_msg(l_procedure_name, ' to_unit :'||l_mmtt_transaction_uom);
1649                                 END IF;
1650                                 l_task_tbl_primary_qty       := inv_convert.inv_um_convert(item_id => l_mmtt_inventory_item_id ,
1651 											   PRECISION => l_decimal_precision ,
1652 											   from_quantity => p_split_quantities(i).quantity ,
1653 											   from_unit => p_split_quantities(i).uom ,
1654 											   to_unit => l_mmtt_item_primary_uom_code ,
1655 											   from_name => NULL ,
1656 											   to_name => NULL);
1657 								-- Added for Bug 16099247
1658 								IF (l_tracking_quantity_ind='PS' AND p_split_quantities(i).secondary_qty is NULL) THEN
1659 												x_split_uom_quantities(i).secondary_quantity :=  inv_convert.inv_um_convert(item_id => l_mmtt_inventory_item_id ,
1660 											                                                                                PRECISION => l_decimal_precision ,
1661 											                                                                                from_quantity => p_split_quantities(i).quantity ,
1662 											                                                                                from_unit => p_split_quantities(i).uom ,
1663 											                                                                                to_unit => l_mmtt_secondary_uom ,
1664 											                                                                                from_name => NULL ,
1665 											                                                                                to_name => NULL);
1666 								ELSE
1667 												x_split_uom_quantities(i).secondary_quantity := p_split_quantities(i).secondary_qty;
1668 								END IF;
1669                                 IF l_task_tbl_transaction_qty = -9999 THEN
1670                                         IF g_debug            = 1 THEN
1671                                                 print_msg(l_procedure_name, ' No conversion defined from :'||
1672 						p_split_quantities(i).uom|| ' to :'||
1673 						l_mmtt_transaction_uom || ' , or UOM does not exist.');
1674                                         END IF;
1675                                         x_return_status := 'E';
1676                                         RETURN;
1677                                 END IF;
1678                                 x_split_uom_quantities(i).primary_quantity := l_task_tbl_primary_qty;
1679                         END IF;
1680                 END IF;
1681                 IF x_split_uom_quantities(i).transaction_quantity <= 0 OR x_split_uom_quantities(i).primary_quantity <= 0 THEN
1682                         IF g_debug                                 = 1 THEN
1683                                 print_msg(l_procedure_name ,'Negative and zero quantities are not allowed in quantities table, exiting.');
1684                         END IF;
1685                         x_return_status := 'E';
1686                         RETURN;
1687                 END IF;
1688                 l_sum_tbl_transaction_qty := l_sum_tbl_transaction_qty + x_split_uom_quantities(i).transaction_quantity;
1689                 l_sum_tbl_primary_qty     := l_sum_tbl_primary_qty     + x_split_uom_quantities(i).primary_quantity;
1690 				l_sum_tbl_secondary_qty     := l_sum_tbl_secondary_qty     + x_split_uom_quantities(i).secondary_quantity; -- Added for Bug 16099247
1691         END LOOP;
1692         IF g_debug = 1 THEN
1693                 print_msg(l_procedure_name , 'l_sum_tbl_transaction_qty : '||l_sum_tbl_transaction_qty);
1694                 print_msg(l_procedure_name , 'l_sum_tbl_primary_qty : '||l_sum_tbl_primary_qty);
1695         END IF;
1696         IF l_sum_tbl_transaction_qty >= l_mmtt_transaction_quantity THEN
1697                 IF g_debug            = 1 THEN
1698                         print_msg(l_procedure_name ,'Sum of qty table :'|| l_sum_tbl_transaction_qty || 'should be less than the mmtt line quantity:'||l_mmtt_transaction_quantity );
1699                 END IF;
1700                 x_return_status := 'E';
1701                 RETURN;
1702         END IF;
1703         --Validate lot/serial quantity
1704         IF g_debug = 1 THEN
1705                 print_msg(l_procedure_name ,'Validating lot/serial if allocations are present');
1706                 print_msg(l_procedure_name , 'lot_control_code : '|| l_lot_control_code);
1707                 print_msg(l_procedure_name , 'serial_control_code : '|| l_serial_control_code);
1708         END IF;
1709         IF l_lot_control_code = 2 AND l_serial_control_code IN (2,5) THEN
1710                 BEGIN
1711                         --Lot quantity
1712                         SELECT  sum(transaction_quantity)
1713                         INTO    l_mtlt_transaction_qty
1714                         FROM    mtl_transaction_lots_temp
1715                         WHERE   transaction_temp_id = p_transaction_temp_id;
1716                         IF g_debug                  = 1 THEN
1717                                 print_msg(l_procedure_name , 'l_mtlt_transaction_qty : '||l_mtlt_transaction_qty|| ' l_mmtt_transaction_quantity : '||l_mmtt_transaction_quantity);
1718                         END IF;
1719                         IF l_mtlt_transaction_qty <> l_mmtt_transaction_quantity THEN
1720                                 x_return_status   := 'E';
1721                                 IF g_debug         = 1 THEN
1722                                         print_msg(l_procedure_name ,'Mismatch in MMTT and MTLT quantity');
1723                                 END IF;
1724                                 RETURN;
1725                         END IF;
1726                 EXCEPTION
1727                 WHEN NO_DATA_FOUND THEN
1728                         x_return_status := 'E';
1729                         IF g_debug       = 1 THEN
1730                                 print_msg(l_procedure_name ,'No Data Found : Mismatch in MMTT and MTLT quantity');
1731                         END IF;
1732                         RETURN;
1733                 END;
1734                 BEGIN
1735                         --serial quantity
1736                         SELECT  sum(1)
1737                         INTO    l_msnt_transaction_qty
1738                         FROM    mtl_serial_numbers_temp
1739                         WHERE   transaction_temp_id IN
1740                                 (SELECT serial_transaction_temp_id
1741                                 FROM    mtl_transaction_lots_temp
1742                                 WHERE   transaction_temp_id = p_transaction_temp_id
1743                                 );
1744                         IF l_msnt_transaction_qty <> l_mmtt_transaction_quantity THEN
1745                                 x_return_status   := 'E';
1746                                 IF g_debug         = 1 THEN
1747                                         print_msg(l_procedure_name ,'Mismatch in MMTT and MSNT quantity');
1748                                 END IF;
1749                                 RETURN;
1750                         END IF;
1751                 EXCEPTION
1752                 WHEN NO_DATA_FOUND THEN
1753                         x_return_status := 'E';
1754                         IF g_debug       = 1 THEN
1755                                 print_msg(l_procedure_name ,'No Data Found :Mismatch in MMTT and MSNT quantity');
1756                         END IF;
1757                         RETURN;
1758                 END;
1759         ELSIF l_lot_control_code = 2 AND l_serial_control_code NOT IN (2,5) THEN
1760                 BEGIN
1761                         --Lot quantity
1762                         SELECT  sum(transaction_quantity)
1763                         INTO    l_mtlt_transaction_qty
1764                         FROM    mtl_transaction_lots_temp
1765                         WHERE   transaction_temp_id = p_transaction_temp_id;
1766                         IF l_mtlt_transaction_qty  <> l_mmtt_transaction_quantity THEN
1767                                 x_return_status    := 'E';
1768                                 IF g_debug          = 1 THEN
1769                                         print_msg(l_procedure_name ,'Mismatch in MMTT and MTLT quantity');
1770                                 END IF;
1771                                 RETURN;
1772                         END IF;
1773                 EXCEPTION
1774                 WHEN NO_DATA_FOUND THEN
1775                         x_return_status := 'E';
1776                         IF g_debug       = 1 THEN
1777                                 print_msg(l_procedure_name ,'No Data Found :Mismatch in MMTT and MTLT quantity');
1778                         END IF;
1779                         RETURN;
1780                 END;
1781         ELSIF l_lot_control_code = 1 AND l_serial_control_code IN (2,5) THEN
1782                 BEGIN
1783                         IF g_debug = 1 THEN
1784                                 print_msg(l_procedure_name ,'Checking for MMTT and MSNT quantity');
1785                         END IF;
1786                         --Serial quantity
1787                         SELECT  sum(1)
1788                         INTO    l_msnt_transaction_qty
1789                         FROM    mtl_serial_numbers_temp
1790                         WHERE   transaction_temp_id = p_transaction_temp_id;
1791                         IF l_msnt_transaction_qty  <> l_mmtt_transaction_quantity THEN
1792                                 x_return_status    := 'E';
1793                                 IF g_debug          = 1 THEN
1794                                         print_msg(l_procedure_name ,'Mismatch in MMTT and MSNT quantity');
1795                                 END IF;
1796                                 RETURN;
1797                         END IF;
1798                 EXCEPTION
1799                 WHEN NO_DATA_FOUND THEN
1800                         x_return_status := 'E';
1801                         IF g_debug       = 1 THEN
1802                                 print_msg(l_procedure_name ,'No Data Found :Mismatch in MMTT and MSNT quantity');
1803                         END IF;
1804                         RETURN;
1805                 END;
1806         END IF;
1807         IF g_debug = 1 THEN
1808                 print_msg(l_procedure_name , 'l_mmtt_primary_quantity  -  l_sum_tbl_primary_qty '||l_mmtt_primary_quantity ||  ' - '||l_sum_tbl_transaction_qty);
1809         END IF;
1810         x_return_status := 'S';
1811 EXCEPTION
1812 WHEN OTHERS THEN
1813         x_return_status := 'E';
1814 END validate_quantities;
1815 
1816 -------------------------------------------------------------------------------------------------------------------
1817 /*PROCEDURE validate_task()
1818 This is the main procedure for all validations for the outbound task except quantity validations.
1819 It internally calls generic procedure validate_task_id.
1820 */
1821 -------------------------------------------------------------------------------------------------------------------
1822 
1823 PROCEDURE validate_task( p_transaction_temp_id IN NUMBER ,
1824 			 x_return_status OUT NOCOPY VARCHAR2 ,
1825 			 x_error_msg OUT NOCOPY VARCHAR2 ,
1826 			 x_msg_data OUT NOCOPY VARCHAR2 ,
1827 			 x_msg_count OUT NOCOPY VARCHAR2 ) IS
1828 
1829         l_mmtt_id                    NUMBER;
1830         l_mmtt_inventory_item_id     NUMBER;
1831         l_mmtt_task_status           NUMBER;
1832         l_mmtt_allocated_lpn_id      NUMBER;
1833         l_mmtt_primary_quantity      NUMBER;
1834         l_mmtt_transaction_quantity  NUMBER;
1835 		l_mmtt_sec_transaction_qty   NUMBER; -- Added for Byg 16099247
1836         l_mmtt_transaction_uom_code  NUMBER;
1837         l_orig_mol_id                NUMBER;
1838         l_mmtt_mol_header_id         NUMBER;
1839         l_mmtt_organization_id       NUMBER;
1840         l_mmtt_transaction_uom       VARCHAR2(3);
1841         l_mmtt_item_primary_uom_code VARCHAR2(3);
1842         l_task_type                  NUMBER;
1843         l_parent_line_id             NUMBER := 0;
1844         l_validation_status          VARCHAR2(10);
1845         l_error_msg                  VARCHAR2(1000);
1846         l_task_return_status         VARCHAR2(10);
1847         l_procedure_name             VARCHAR2(20) := 'VALIDATE_TASK';
1848         l_task_exists                NUMBER;
1849 BEGIN
1850         x_return_status := 'S'; --6870528/6851036
1851         validate_task_id ( p_init_msg_list  => 'Y' ,p_transaction_number=>  p_transaction_temp_id ,x_validation_status => l_validation_status ,x_error_msg => l_error_msg , x_return_status =>x_return_status );  --6850212
1852         IF g_debug = 1 THEN
1853                 print_msg(l_procedure_name , 'Task :' || p_transaction_temp_id || ' not valid.');
1854         END IF;
1855         IF NVL(l_validation_status,'E') <> 'S' OR NVL(x_return_status,'E') <> 'S' THEN
1856                 IF g_debug               = 1 THEN
1857                         print_msg(l_procedure_name , 'Task :' || p_transaction_temp_id || ' not valid.');
1858                 END IF;
1859                 x_return_status := 'E';
1860                 RETURN;
1861         END IF;
1862         IF p_transaction_temp_id IS NULL THEN
1863                 x_return_status := 'E';
1864                 IF g_debug       = 1 THEN
1865                         print_msg(l_procedure_name, 'No transaction_temp_id passed');
1866                 END IF;
1867                 RETURN;
1868         END IF;
1869         BEGIN
1870                 -- Taking locks on the task
1871                 SELECT  transaction_temp_id   ,
1872                         wms_task_status       ,
1873                         allocated_lpn_id      ,
1874                         transaction_uom       ,
1875                         inventory_item_id     ,
1876                         primary_quantity      ,
1877                         transaction_quantity  ,
1878                         move_order_line_id    ,
1879                         move_order_header_id  ,
1880                         item_primary_uom_code ,
1881                         transaction_uom       ,
1882                         organization_id       ,
1883                         wms_task_type         ,
1884                         parent_line_id        ,
1885 						secondary_transaction_quantity -- Added for Bug 16099247
1886                 INTO    l_mmtt_id                    ,
1887                         l_mmtt_task_status           ,
1888                         l_mmtt_allocated_lpn_id      ,
1889                         l_mmtt_transaction_uom       ,
1890                         l_mmtt_inventory_item_id     ,
1891                         l_mmtt_primary_quantity      ,
1892                         l_mmtt_transaction_quantity  ,
1893                         l_orig_mol_id                ,
1894                         l_mmtt_mol_header_id         ,
1895                         l_mmtt_item_primary_uom_code ,
1896                         l_mmtt_transaction_uom       ,
1897                         l_mmtt_organization_id       ,
1898                         l_task_type                  ,
1899                         l_parent_line_id             ,
1900 						l_mmtt_sec_transaction_qty    -- Added for Bug 16099247
1901                 FROM    mtl_material_transactions_temp
1902                 WHERE   transaction_temp_id = p_transaction_temp_id FOR UPDATE NOWAIT;
1903                 IF l_mmtt_allocated_lpn_id IS NOT NULL THEN
1904                         x_return_status := 'E';
1905                         IF g_debug       = 1 THEN
1906                                 print_msg(l_procedure_name ,'Task :' || l_mmtt_id || ' has an allocated LPN. Split not allowed');
1907                         END IF;
1908                         RETURN;
1909                 END IF;
1910                 IF ( l_parent_line_id    > 0 AND l_task_type = 1 AND l_parent_line_id = p_transaction_temp_id ) THEN -- This is bulk pick
1911                         x_return_status := 'E';
1912                         IF g_debug       = 1 THEN
1913                                 print_msg(l_procedure_name ,'Task :' || l_mmtt_id || ' is a Bulk Pick task. Split not allowed');
1914                         END IF;
1915                         RETURN ;
1916                 END IF;
1917                 IF l_task_type          <> 1 THEN
1918                         x_return_status := 'E';
1919                         IF g_debug       = 1 THEN
1920                                 print_msg(l_procedure_name ,'Task :' || l_mmtt_id || ' is not an outbound task. Split not allowed');
1921                         END IF;
1922                         RETURN ;
1923                 END IF;
1924                 IF g_debug = 1 THEN
1925                         print_msg(l_procedure_name , 'Calling validate_task_id for Task :' || p_transaction_temp_id);
1926                 END IF;
1927                -- x_return_status := 'S';  --6870528/6851036
1928         EXCEPTION
1929         WHEN NO_DATA_FOUND THEN
1930                 SELECT  count(1)
1931                 INTO    l_task_exists
1932                 FROM    mtl_cycle_count_entries mcce
1933                 WHERE   mcce.cycle_count_entry_id = p_transaction_temp_id
1934                     AND mcce.entry_status_code   IN( 1 , 3) ;
1935                 IF g_debug                        = 1 THEN
1936                         IF l_task_exists          > 0 THEN
1937                                 print_msg(l_procedure_name , 'Task :' || p_transaction_temp_id || ' is a cycle count task, split not allowed.');
1938                         ELSE
1939                                 print_msg(l_procedure_name , 'Task :' || p_transaction_temp_id || ' does not exist.');
1940                         END IF;
1941                 END IF;
1942                 x_return_status := 'E';
1943         WHEN OTHERS THEN
1944                 x_return_status := 'E';
1945                 IF g_debug       = 1 THEN
1946                         print_msg(l_procedure_name , 'Resource busy, was not able to acquire lock  on mmtt:' || p_transaction_temp_id);
1947                 END IF;
1948         END;
1949      --   x_return_status := 'S';    --6870528/6851036
1950 END validate_task;
1951 
1952 -------------------------------------------------------------------------------------------------------------------
1953 /*PROCEDURE split_mtlt()
1954 This helper procedure performs the splitting for the lot records contained in mtl_transaction_lots_temp table
1955 */
1956 -------------------------------------------------------------------------------------------------------------------
1957 PROCEDURE split_mtlt ( p_new_transaction_temp_id IN NUMBER ,
1958 		       p_transaction_qty_to_split IN NUMBER ,
1959 		       p_primary_qty_to_split IN NUMBER ,
1960 			   p_secondary_qty_to_split NUMBER, -- Added for Bug 16099247
1961 		       p_row_id IN ROWID ,
1962 		       x_return_status OUT NOCOPY VARCHAR2 ,
1963 		       x_msg_data OUT NOCOPY VARCHAR2 ,
1964 		       x_msg_count OUT NOCOPY VARCHAR2 ) IS
1965 
1966 BEGIN
1967         x_return_status := 'E';
1968         INSERT
1969         INTO    mtl_transaction_lots_temp
1970                 (
1971                         TRANSACTION_TEMP_ID        ,
1972                         LAST_UPDATE_DATE           ,
1973                         LAST_UPDATED_BY            ,
1974                         CREATION_DATE              ,
1975                         CREATED_BY                 ,
1976                         LAST_UPDATE_LOGIN          ,
1977                         REQUEST_ID                 ,
1978                         PROGRAM_APPLICATION_ID     ,
1979                         PROGRAM_ID                 ,
1980                         PROGRAM_UPDATE_DATE        ,
1981                         TRANSACTION_QUANTITY       ,
1982                         PRIMARY_QUANTITY           ,
1983                         LOT_NUMBER                 ,
1984                         LOT_EXPIRATION_DATE        ,
1985                         ERROR_CODE                 ,
1986                         SERIAL_TRANSACTION_TEMP_ID ,
1987                         GROUP_HEADER_ID            ,
1988                         PUT_AWAY_RULE_ID           ,
1989                         PICK_RULE_ID               ,
1990                         DESCRIPTION                ,
1991                         VENDOR_NAME                ,
1992                         SUPPLIER_LOT_NUMBER        ,
1993                         ORIGINATION_DATE           ,
1994                         DATE_CODE                  ,
1995                         GRADE_CODE                 ,
1996                         CHANGE_DATE                ,
1997                         MATURITY_DATE              ,
1998                         STATUS_ID                  ,
1999                         RETEST_DATE                ,
2000                         AGE                        ,
2001                         ITEM_SIZE                  ,
2002                         COLOR                      ,
2003                         VOLUME                     ,
2004                         VOLUME_UOM                 ,
2005                         PLACE_OF_ORIGIN            ,
2006                         BEST_BY_DATE               ,
2007                         LENGTH                     ,
2008                         LENGTH_UOM                 ,
2009                         RECYCLED_CONTENT           ,
2010                         THICKNESS                  ,
2011                         THICKNESS_UOM              ,
2012                         WIDTH                      ,
2013                         WIDTH_UOM                  ,
2014                         CURL_WRINKLE_FOLD          ,
2015                         LOT_ATTRIBUTE_CATEGORY     ,
2016                         C_ATTRIBUTE1               ,
2017                         C_ATTRIBUTE2               ,
2018                         C_ATTRIBUTE3               ,
2019                         C_ATTRIBUTE4               ,
2020                         C_ATTRIBUTE5               ,
2021                         C_ATTRIBUTE6               ,
2022                         C_ATTRIBUTE7               ,
2023                         C_ATTRIBUTE8               ,
2024                         C_ATTRIBUTE9               ,
2025                         C_ATTRIBUTE10              ,
2026                         C_ATTRIBUTE11              ,
2027                         C_ATTRIBUTE12              ,
2028                         C_ATTRIBUTE13              ,
2029                         C_ATTRIBUTE14              ,
2030                         C_ATTRIBUTE15              ,
2031                         C_ATTRIBUTE16              ,
2032                         C_ATTRIBUTE17              ,
2033                         C_ATTRIBUTE18              ,
2034                         C_ATTRIBUTE19              ,
2035                         C_ATTRIBUTE20              ,
2036                         D_ATTRIBUTE1               ,
2037                         D_ATTRIBUTE2               ,
2038                         D_ATTRIBUTE3               ,
2039                         D_ATTRIBUTE4               ,
2040                         D_ATTRIBUTE5               ,
2041                         D_ATTRIBUTE6               ,
2042                         D_ATTRIBUTE7               ,
2043                         D_ATTRIBUTE8               ,
2044                         D_ATTRIBUTE9               ,
2045                         D_ATTRIBUTE10              ,
2046                         N_ATTRIBUTE1               ,
2047                         N_ATTRIBUTE2               ,
2048                         N_ATTRIBUTE3               ,
2049                         N_ATTRIBUTE4               ,
2050                         N_ATTRIBUTE5               ,
2051                         N_ATTRIBUTE6               ,
2052                         N_ATTRIBUTE7               ,
2053                         N_ATTRIBUTE8               ,
2054                         N_ATTRIBUTE9               ,
2055                         N_ATTRIBUTE10              ,
2056                         VENDOR_ID                  ,
2057                         TERRITORY_CODE             ,
2058                         SUBLOT_NUM                 ,
2059                         SECONDARY_QUANTITY         ,
2060                         SECONDARY_UNIT_OF_MEASURE  ,
2061                         QC_GRADE                   ,
2062                         REASON_CODE                ,
2063                         PRODUCT_CODE               ,
2064                         PRODUCT_TRANSACTION_ID     ,
2065                         ATTRIBUTE_CATEGORY         ,
2066                         ATTRIBUTE1                 ,
2067                         ATTRIBUTE2                 ,
2068                         ATTRIBUTE3                 ,
2069                         ATTRIBUTE4                 ,
2070                         ATTRIBUTE5                 ,
2071                         ATTRIBUTE6                 ,
2072                         ATTRIBUTE7                 ,
2073                         ATTRIBUTE8                 ,
2074                         ATTRIBUTE9                 ,
2075                         ATTRIBUTE10                ,
2076                         ATTRIBUTE11                ,
2077                         ATTRIBUTE12                ,
2078                         ATTRIBUTE13                ,
2079                         ATTRIBUTE14                ,
2080                         ATTRIBUTE15
2081                 )
2082         SELECT  p_new_transaction_temp_id --TRANSACTION_TEMP_ID
2083                 ,
2084                 sysdate --LAST_UPDATE_DATE
2085                 ,
2086                 FND_GLOBAL.USER_ID ,
2087                 sysdate --CREATION_DATE
2088                 ,
2089                 FND_GLOBAL.USER_ID     ,
2090                 LAST_UPDATE_LOGIN      ,
2091                 REQUEST_ID             ,
2092                 PROGRAM_APPLICATION_ID ,
2093                 PROGRAM_ID             ,
2094                 PROGRAM_UPDATE_DATE    ,
2095                 p_transaction_qty_to_split --TRANSACTION_QUANTITY
2096                 ,
2097                 p_primary_qty_to_split --PRIMARY_QUANTITY
2098                 ,
2099                 LOT_NUMBER                 ,
2100                 LOT_EXPIRATION_DATE        ,
2101                 ERROR_CODE                 ,
2102                 SERIAL_TRANSACTION_TEMP_ID ,
2103                 GROUP_HEADER_ID            ,
2104                 PUT_AWAY_RULE_ID           ,
2105                 PICK_RULE_ID               ,
2106                 DESCRIPTION                ,
2107                 VENDOR_NAME                ,
2108                 SUPPLIER_LOT_NUMBER        ,
2109                 ORIGINATION_DATE           ,
2110                 DATE_CODE                  ,
2111                 GRADE_CODE                 ,
2112                 CHANGE_DATE                ,
2113                 MATURITY_DATE              ,
2114                 STATUS_ID                  ,
2115                 RETEST_DATE                ,
2116                 AGE                        ,
2117                 ITEM_SIZE                  ,
2118                 COLOR                      ,
2119                 VOLUME                     ,
2120                 VOLUME_UOM                 ,
2121                 PLACE_OF_ORIGIN            ,
2122                 BEST_BY_DATE               ,
2123                 LENGTH                     ,
2124                 LENGTH_UOM                 ,
2125                 RECYCLED_CONTENT           ,
2126                 THICKNESS                  ,
2127                 THICKNESS_UOM              ,
2128                 WIDTH                      ,
2129                 WIDTH_UOM                  ,
2130                 CURL_WRINKLE_FOLD          ,
2131                 LOT_ATTRIBUTE_CATEGORY     ,
2132                 C_ATTRIBUTE1               ,
2133                 C_ATTRIBUTE2               ,
2134                 C_ATTRIBUTE3               ,
2135                 C_ATTRIBUTE4               ,
2136                 C_ATTRIBUTE5               ,
2137                 C_ATTRIBUTE6               ,
2138                 C_ATTRIBUTE7               ,
2139                 C_ATTRIBUTE8               ,
2140                 C_ATTRIBUTE9               ,
2141                 C_ATTRIBUTE10              ,
2142                 C_ATTRIBUTE11              ,
2143                 C_ATTRIBUTE12              ,
2144                 C_ATTRIBUTE13              ,
2145                 C_ATTRIBUTE14              ,
2146                 C_ATTRIBUTE15              ,
2147                 C_ATTRIBUTE16              ,
2148                 C_ATTRIBUTE17              ,
2149                 C_ATTRIBUTE18              ,
2150                 C_ATTRIBUTE19              ,
2151                 C_ATTRIBUTE20              ,
2152                 D_ATTRIBUTE1               ,
2153                 D_ATTRIBUTE2               ,
2154                 D_ATTRIBUTE3               ,
2155                 D_ATTRIBUTE4               ,
2156                 D_ATTRIBUTE5               ,
2157                 D_ATTRIBUTE6               ,
2158                 D_ATTRIBUTE7               ,
2159                 D_ATTRIBUTE8               ,
2160                 D_ATTRIBUTE9               ,
2161                 D_ATTRIBUTE10              ,
2162                 N_ATTRIBUTE1               ,
2163                 N_ATTRIBUTE2               ,
2164                 N_ATTRIBUTE3               ,
2165                 N_ATTRIBUTE4               ,
2166                 N_ATTRIBUTE5               ,
2167                 N_ATTRIBUTE6               ,
2168                 N_ATTRIBUTE7               ,
2169                 N_ATTRIBUTE8               ,
2170                 N_ATTRIBUTE9               ,
2171                 N_ATTRIBUTE10              ,
2172                 VENDOR_ID                  ,
2173                 TERRITORY_CODE             ,
2174                 SUBLOT_NUM                 ,
2175                 p_secondary_qty_to_split   , -- Changed for Bug 16099247
2176                 SECONDARY_UNIT_OF_MEASURE  ,
2177                 QC_GRADE                   ,
2178                 REASON_CODE                ,
2179                 PRODUCT_CODE               ,
2180                 PRODUCT_TRANSACTION_ID     ,
2181                 ATTRIBUTE_CATEGORY         ,
2182                 ATTRIBUTE1                 ,
2183                 ATTRIBUTE2                 ,
2184                 ATTRIBUTE3                 ,
2185                 ATTRIBUTE4                 ,
2186                 ATTRIBUTE5                 ,
2187                 ATTRIBUTE6                 ,
2188                 ATTRIBUTE7                 ,
2189                 ATTRIBUTE8                 ,
2190                 ATTRIBUTE9                 ,
2191                 ATTRIBUTE10                ,
2192                 ATTRIBUTE11                ,
2193                 ATTRIBUTE12                ,
2194                 ATTRIBUTE13                ,
2195                 ATTRIBUTE14                ,
2196                 ATTRIBUTE15
2197         FROM    mtl_transaction_lots_temp
2198         WHERE   rowid    = p_row_id;
2199         x_return_status := 'S';
2200 EXCEPTION
2201 WHEN OTHERS THEN
2202         x_return_status := 'E';
2203         RETURN;
2204 END split_mtlt;
2205 
2206 -------------------------------------------------------------------------------------------------------------------
2207 /*Procedure split_serial()
2208 This helper procedure performs the splitting for the serial records contained in mtl_serial_numbers_temp table
2209 */
2210 -------------------------------------------------------------------------------------------------------------------
2211 
2212 PROCEDURE split_serial( p_orig_transaction_temp_id IN NUMBER ,
2213 			p_new_transaction_temp_id IN NUMBER ,
2214 			p_transaction_qty_to_split IN NUMBER ,
2215 			p_primary_qty_to_split IN NUMBER ,
2216 			p_inventory_item_id IN NUMBER ,
2217 			p_organization_id IN NUMBER ,
2218 			x_return_status OUT NOCOPY VARCHAR2 ,
2219 			x_msg_data OUT NOCOPY VARCHAR2 ,
2220 			x_msg_count OUT NOCOPY VARCHAR2 ) IS
2221 
2222         CURSOR C_MSNT
2223         IS
2224                 SELECT  rowid,
2225                         msnt.*
2226                 FROM    mtl_serial_numbers_temp msnt
2227                 WHERE   transaction_temp_id = p_orig_transaction_temp_id
2228                 ORDER BY fm_serial_number;
2229         l_procedure_name            VARCHAR2(20) := 'SPLIT_SERIAL';
2230         l_transaction_remaining_qty NUMBER;
2231         l_primary_remaining_qty     NUMBER;
2232 BEGIN
2233         x_return_status             := 'E';
2234         l_transaction_remaining_qty := p_transaction_qty_to_split;
2235         l_primary_remaining_qty     := p_primary_qty_to_split;
2236         IF g_debug                   = 1 THEN
2237         print_msg(l_procedure_name,  'In for loop(cursor msnt) for transaction_temp_id : '||p_orig_transaction_temp_id ||  'l_transaction_remaining_qty : '||l_transaction_remaining_qty||  'l_primary_remaining_qty : '||l_primary_remaining_qty);
2238         END IF;
2239         FOR msnt IN C_MSNT
2240         LOOP
2241                 l_transaction_remaining_qty := l_transaction_remaining_qty - 1;
2242                 UPDATE mtl_serial_numbers_temp
2243                         SET transaction_temp_id = p_new_transaction_temp_id ,
2244                         last_updated_by         = FND_GLOBAL.USER_ID
2245                 WHERE   rowid                   = msnt.rowid;
2246                 UPDATE mtl_serial_numbers msn
2247                         SET msn.group_mark_id   = p_new_transaction_temp_id ,
2248                         last_updated_by         = FND_GLOBAL.USER_ID
2249                 WHERE   msn.inventory_item_id   = p_inventory_item_id
2250                     AND serial_number           = msnt.fm_serial_number
2251                     AND current_organization_id = p_organization_id;
2252                 IF l_transaction_remaining_qty  = 0 THEN
2253                         print_msg(l_procedure_name,'All the quantity has been consumed, going back');
2254                         EXIT;
2255                 END IF;
2256         END LOOP;
2257         x_return_status := 'S';
2258 EXCEPTION
2259 WHEN OTHERS THEN
2260         x_return_status := 'E';
2261         RETURN;
2262 END split_serial;
2263 
2264 -------------------------------------------------------------------------------------------------------------------
2265 /*PROCEDURE split_lot_serial()
2266 This is the procedure called for splitting in case an Item is either only Lot Controlled or both Lot and
2267 Serial Controlled. It internally calls procedures split_mtlt and split_serial.
2268 */
2269 -------------------------------------------------------------------------------------------------------------------
2270 PROCEDURE split_lot_serial( p_orig_transaction_temp_id IN NUMBER ,
2271 			    p_new_transaction_temp_id IN NUMBER ,
2272 			    p_transaction_qty_to_split IN NUMBER ,
2273 			    p_primary_qty_to_split IN NUMBER ,
2274 				p_secondary_qty_to_split IN NUMBER , -- Added for Bug 16099247
2275 			    p_inventory_item_id IN NUMBER ,
2276 			    p_organization_id IN NUMBER ,
2277 			    x_return_status OUT NOCOPY VARCHAR2 ,
2278 			    x_msg_data OUT NOCOPY VARCHAR2 ,
2279 			    x_msg_count OUT NOCOPY VARCHAR2 ) IS
2280 
2281         CURSOR C_MTLT
2282         IS
2283                 SELECT  rowid,
2284                         mtlt.*
2285                 FROM    mtl_transaction_lots_temp mtlt
2286                 WHERE   transaction_temp_id = p_orig_transaction_temp_id
2287                 ORDER BY lot_number;
2288 
2289         l_transaction_remaining_qty NUMBER;
2290         l_primary_remaining_qty     NUMBER;
2291 		l_secondary_remaining_qty   NUMBER; -- Added for Bug 16099247
2292         l_txn_remaining_qty_mtlt    NUMBER;
2293         l_prim_remaining_qty_mtlt   NUMBER;
2294 		l_sec_remaining_qty_mtlt    NUMBER; -- Added for Bug 16099247
2295         l_procedure_name            VARCHAR2(30) := 'SPLIT_LOT_SERIAL';
2296         l_lot_control_code          NUMBER;
2297         l_serial_control_code       NUMBER;
2298         l_new_serial_txn_temp_id    NUMBER;
2299         l_lot_control_code          NUMBER;
2300         l_serial_control_code       NUMBER;
2301 	x_lot_return_status         VARCHAR2(1);
2302 BEGIN
2303         x_return_status := 'E';
2304         IF g_debug       = 1 THEN
2305                 print_msg(l_procedure_name, 'Entered.');
2306         END IF;
2307         l_transaction_remaining_qty := p_transaction_qty_to_split;
2308         l_primary_remaining_qty     := p_primary_qty_to_split;
2309 		l_secondary_remaining_qty     := p_secondary_qty_to_split; -- Added for Bug 16099247
2310 
2311         FOR mtlt                    IN C_MTLT
2312         LOOP
2313                 IF g_debug = 1 THEN
2314                         print_msg(l_procedure_name,  'In for loop(cursor mtlt) for transaction_temp_id : '||
2315 			p_orig_transaction_temp_id ||  'l_transaction_remaining_qty : '||
2316 			l_transaction_remaining_qty||  'l_primary_remaining_qty : '||
2317 			l_primary_remaining_qty);
2318                 END IF;
2319                 IF l_transaction_remaining_qty >= mtlt.transaction_quantity THEN
2320                         -- Then this whole row can be consumed there is not need to split.
2321                         -- Update the row with the new ttemp_id and transaction_quantity.
2322                         -- Calculate remaining quantity.
2323                         -- Update mtl_lot_number
2324                         l_transaction_remaining_qty := l_transaction_remaining_qty - mtlt.transaction_quantity;
2325                         l_primary_remaining_qty     := l_primary_remaining_qty     - mtlt.primary_quantity;
2326 						l_secondary_remaining_qty   := l_secondary_remaining_qty - mtlt.secondary_quantity; -- Added for Bug 16099247
2327                         UPDATE mtl_transaction_lots_temp
2328                                 SET transaction_temp_id = p_new_transaction_temp_id ,
2329                                 last_updated_by         = FND_GLOBAL.USER_ID
2330                         WHERE   rowid                   = mtlt.rowid;
2331                         IF l_transaction_remaining_qty  = 0 THEN
2332                                 EXIT;
2333                         END IF;
2334                 ELSE
2335                         -- Oops the mtlt quantity is bigger gotta split the row.
2336                         -- Insert a new row with the transaction_quantity.
2337                         -- Update the old row with the remaining quantity.
2338                         -- Update mtl_lot_number
2339                         split_mtlt ( p_new_transaction_temp_id ,
2340 				     l_transaction_remaining_qty ,
2341 				     l_primary_remaining_qty ,
2342 					 l_secondary_remaining_qty, -- Added for Bug 16099247
2343 					 mtlt.rowid ,
2344 				     x_lot_return_status ,
2345 				     x_msg_data ,
2346 				     x_msg_count );
2347 
2348                         IF mtlt.serial_transaction_temp_id IS NOT NULL THEN
2349                                 SELECT  mtl_material_transactions_s.NEXTVAL
2350                                 INTO    l_new_serial_txn_temp_id
2351                                 FROM    dual;
2352                                 UPDATE mtl_transaction_lots_temp
2353                                         SET serial_transaction_temp_id   = l_new_serial_txn_temp_id ,
2354                                         last_updated_by                  = FND_GLOBAL.USER_ID
2355                                 WHERE   transaction_temp_id              = p_new_transaction_temp_id
2356                                     AND lot_number                       = mtlt.lot_number;
2357                                 split_serial( p_orig_transaction_temp_id => mtlt.serial_transaction_temp_id ,
2358 				              p_new_transaction_temp_id => l_new_serial_txn_temp_id ,
2359 					      p_transaction_qty_to_split => l_transaction_remaining_qty ,
2360 					      p_primary_qty_to_split => l_primary_remaining_qty ,
2361 					      p_inventory_item_id => p_inventory_item_id ,
2362 					      p_organization_id => p_organization_id ,
2363 					      x_return_status => x_return_status ,
2364 					      x_msg_data => x_msg_data ,
2365 					      x_msg_count => x_msg_count );
2366                         END IF;
2367                         l_txn_remaining_qty_mtlt  := mtlt.transaction_quantity - l_transaction_remaining_qty;
2368                         l_prim_remaining_qty_mtlt := mtlt.primary_quantity     - l_primary_remaining_qty;
2369 						l_sec_remaining_qty_mtlt := mtlt.secondary_quantity     - l_secondary_remaining_qty; -- Added for Bug 16099247
2370                         -- Update the remaining qty in the mtlt after insert.
2371                         UPDATE mtl_transaction_lots_temp
2372                                 SET transaction_quantity = l_txn_remaining_qty_mtlt  ,
2373                                 primary_quantity         = l_prim_remaining_qty_mtlt ,
2374 								secondary_quantity       = l_sec_remaining_qty_mtlt , -- Added for Bug 16099247
2375                                 last_updated_by          = FND_GLOBAL.USER_ID
2376                         WHERE   rowid                    = mtlt.rowid;
2377                         -- As the remaining quantity is already consumed we can safely exit
2378                         EXIT ;
2379                 END IF;
2380         END LOOP;
2381         x_return_status := 'S';
2382 EXCEPTION
2383 WHEN OTHERS THEN
2384         IF g_debug = 1 THEN
2385                 print_msg(l_procedure_name,  'Error occurred : '|| SQLERRM);
2386         END IF;
2387         x_return_status := 'E';
2388         RETURN;
2389 END split_lot_serial;
2390 
2391 -------------------------------------------------------------------------------------------------------------------
2392 /*PROCEDURE split_wdt()
2393 This procedure is called to accordingly split the task record contained in wms_dispatched_tasks table
2394 */
2395 -------------------------------------------------------------------------------------------------------------------
2396 PROCEDURE split_wdt( p_new_task_id IN NUMBER ,
2397 		     p_new_transaction_temp_id IN NUMBER ,
2398 		     p_new_mol_id IN NUMBER ,
2399 		     p_orig_transaction_temp_id IN NUMBER ,
2400 		     x_return_status OUT NOCOPY VARCHAR2 ,
2401 		     x_msg_data OUT NOCOPY VARCHAR2 ,
2402 		     x_msg_count OUT NOCOPY VARCHAR2 ) IS
2403 
2404         l_proceudre_name VARCHAR2(30) := 'SPLIT_WDT';
2405         l_sysdate DATE                := SYSDATE;
2406 BEGIN
2407         x_return_status := 'E';
2408         IF g_debug       = 1 THEN
2409                 print_msg(l_proceudre_name,  ' Entered ');
2410         END IF;
2411         INSERT
2412         INTO    wms_dispatched_tasks
2413                 (
2414                         op_plan_instance_id         ,
2415                         task_method                 ,
2416                         task_id                     ,
2417                         transaction_temp_id         ,
2418                         organization_id             ,
2419                         user_task_type              ,
2420                         person_id                   ,
2421                         effective_start_date        ,
2422                         effective_end_date          ,
2423                         equipment_id                ,
2424                         equipment_instance          ,
2425                         person_resource_id          ,
2426                         machine_resource_id         ,
2427                         status                      ,
2428                         dispatched_time             ,
2429                         loaded_time                 ,
2430                         drop_off_time               ,
2431                         last_update_date            ,
2432                         last_updated_by             ,
2433                         creation_date               ,
2434                         created_by                  ,
2435                         last_update_login           ,
2436                         attribute_category          ,
2437                         attribute1                  ,
2438                         attribute2                  ,
2439                         attribute3                  ,
2440                         attribute4                  ,
2441                         attribute5                  ,
2442                         attribute6                  ,
2443                         attribute7                  ,
2444                         attribute8                  ,
2445                         attribute9                  ,
2446                         attribute10                 ,
2447                         attribute11                 ,
2448                         attribute12                 ,
2449                         attribute13                 ,
2450                         attribute14                 ,
2451                         attribute15                 ,
2452                         task_type                   ,
2453                         priority                    ,
2454                         task_group_id               ,
2455                         device_id                   ,
2456                         device_invoked              ,
2457                         device_request_id           ,
2458                         suggested_dest_subinventory ,
2459                         suggested_dest_locator_id   ,
2460                         operation_plan_id           ,
2461                         move_order_line_id          ,
2462                         transfer_lpn_id
2463                 )
2464         SELECT  op_plan_instance_id ,
2465                 task_method         ,
2466                 p_new_task_id --task_id
2467                 ,
2468                 p_new_transaction_temp_id --transaction_temp_id
2469                 ,
2470                 organization_id      ,
2471                 user_task_type       ,
2472                 person_id            ,
2473                 effective_start_date ,
2474                 effective_end_date   ,
2475                 equipment_id         ,
2476                 equipment_instance   ,
2477                 person_resource_id   ,
2478                 machine_resource_id  ,
2479                 status               ,
2480                 dispatched_time      ,
2481                 loaded_time          ,
2482                 drop_off_time        ,
2483                 l_sysdate --last_update_date
2484                 ,
2485                 FND_GLOBAL.USER_ID ,
2486                 l_sysdate --creation_date
2487                 ,
2488                 FND_GLOBAL.USER_ID          ,
2489                 last_update_login           ,
2490                 attribute_category          ,
2491                 attribute1                  ,
2492                 attribute2                  ,
2493                 attribute3                  ,
2494                 attribute4                  ,
2495                 attribute5                  ,
2496                 attribute6                  ,
2497                 attribute7                  ,
2498                 attribute8                  ,
2499                 attribute9                  ,
2500                 attribute10                 ,
2501                 attribute11                 ,
2502                 attribute12                 ,
2503                 attribute13                 ,
2504                 attribute14                 ,
2505                 attribute15                 ,
2506                 task_type                   ,
2507                 priority                    ,
2508                 task_group_id               ,
2509                 device_id                   ,
2510                 device_invoked              ,
2511                 device_request_id           ,
2512                 suggested_dest_subinventory ,
2513                 suggested_dest_locator_id   ,
2514                 operation_plan_id           ,
2515                 p_new_mol_id                ,
2516                 transfer_lpn_id
2517         FROM    wms_dispatched_tasks
2518         WHERE   transaction_temp_id = p_orig_transaction_temp_id;
2519         x_return_status            := 'S';
2520 EXCEPTION
2521 WHEN OTHERS THEN
2522         x_return_status := 'E';
2523         IF g_debug       = 1 THEN
2524                 print_msg(l_proceudre_name,  ' Error Code : '|| SQLCODE || ' Error Message :'||SQLERRM);
2525         END IF;
2526         RETURN;
2527 END split_wdt;
2528 
2529 -------------------------------------------------------------------------------------------------------------------
2530 /*PROCEDURE split_mmtt()
2531 This procedure performs the split for the Pending task record in mtl_material_transactions_temp table
2532 */
2533 -------------------------------------------------------------------------------------------------------------------
2534 PROCEDURE split_mmtt( p_orig_transaction_temp_id IN NUMBER ,
2535 		      p_new_transaction_temp_id IN NUMBER ,
2536 		      p_new_transaction_header_id IN NUMBER ,
2537 		      p_new_mol_id IN NUMBER ,
2538 		      p_transaction_qty_to_split IN NUMBER ,
2539 		      p_primary_qty_to_split IN NUMBER ,
2540 			  p_secondary_qty_to_split in NUMBER, -- Added for Bug 16099247
2541 		      x_return_status OUT NOCOPY VARCHAR2 ,
2542 		      x_msg_data OUT NOCOPY VARCHAR2 ,
2543 		      x_msg_count OUT NOCOPY VARCHAR2 ) IS
2544 
2545         l_procedure_name VARCHAR2(30) := 'WMS_TASK_SPLIT_API.SPLIT_MMTT';
2546         l_sysdate DATE                := SYSDATE;
2547 BEGIN
2548         x_return_status := 'E';
2549         IF g_debug       = 1 THEN
2550                 print_msg(l_procedure_name,  ' Entered ');
2551         END IF;
2552         INSERT
2553         INTO    mtl_material_transactions_temp
2554                 (
2555                         currency_conversion_date       ,
2556                         shipment_number                ,
2557                         org_cost_group_id              ,
2558                         cost_type_id                   ,
2559                         transaction_status             ,
2560                         standard_operation_id          ,
2561                         task_priority                  ,
2562                         wms_task_type                  ,
2563                         parent_line_id                 ,
2564                         source_lot_number              ,
2565                         transfer_cost_group_id         ,
2566                         lpn_id                         ,
2567                         transfer_lpn_id                ,
2568                         wms_task_status                ,
2569                         content_lpn_id                 ,
2570                         container_item_id              ,
2571                         cartonization_id               ,
2572                         pick_slip_date                 ,
2573                         rebuild_item_id                ,
2574                         rebuild_serial_number          ,
2575                         rebuild_activity_id            ,
2576                         rebuild_job_name               ,
2577                         organization_type              ,
2578                         transfer_organization_type     ,
2579                         owning_organization_id         ,
2580                         owning_tp_type                 ,
2581                         xfr_owning_organization_id     ,
2582                         transfer_owning_tp_type        ,
2583                         planning_organization_id       ,
2584                         planning_tp_type               ,
2585                         xfr_planning_organization_id   ,
2586                         transfer_planning_tp_type      ,
2587                         secondary_uom_code             ,
2588                         secondary_transaction_quantity ,
2589                         allocated_lpn_id               ,
2590                         schedule_number                ,
2591                         scheduled_flag                 ,
2592                         class_code                     ,
2593                         schedule_group                 ,
2594                         build_sequence                 ,
2595                         bom_revision                   ,
2596                         routing_revision               ,
2597                         bom_revision_date              ,
2598                         routing_revision_date          ,
2599                         alternate_bom_designator       ,
2600                         alternate_routing_designator   ,
2601                         transaction_batch_id           ,
2602                         transaction_batch_seq          ,
2603                         operation_plan_id              ,
2604                         intransit_account              ,
2605                         fob_point                      ,
2606                         transaction_header_id          ,
2607                         transaction_temp_id            ,
2608                         source_code                    ,
2609                         source_line_id                 ,
2610                         transaction_mode               ,
2611                         lock_flag                      ,
2612                         last_update_date               ,
2613                         last_updated_by                ,
2614                         creation_date                  ,
2615                         created_by                     ,
2616                         last_update_login              ,
2617                         request_id                     ,
2618                         program_application_id         ,
2619                         program_id                     ,
2620                         program_update_date            ,
2621                         inventory_item_id              ,
2622                         revision                       ,
2623                         organization_id                ,
2624                         subinventory_code              ,
2625                         locator_id                     ,
2626                         transaction_quantity           ,
2627                         primary_quantity               ,
2628                         transaction_uom                ,
2629                         transaction_cost               ,
2630                         transaction_type_id            ,
2631                         transaction_action_id          ,
2632                         transaction_source_type_id     ,
2633                         transaction_source_id          ,
2634                         transaction_source_name        ,
2635                         transaction_date               ,
2636                         acct_period_id                 ,
2637                         distribution_account_id        ,
2638                         transaction_reference          ,
2639                         requisition_line_id            ,
2640                         requisition_distribution_id    ,
2641                         reason_id                      ,
2642                         lot_number                     ,
2643                         lot_expiration_date            ,
2644                         serial_number                  ,
2645                         receiving_document             ,
2646                         demand_id                      ,
2647                         rcv_transaction_id             ,
2648                         move_transaction_id            ,
2649                         completion_transaction_id      ,
2650                         wip_entity_type                ,
2651                         schedule_id                    ,
2652                         repetitive_line_id             ,
2653                         employee_code                  ,
2654                         primary_switch                 ,
2655                         schedule_update_code           ,
2656                         setup_teardown_code            ,
2657                         item_ordering                  ,
2658                         negative_req_flag              ,
2659                         operation_seq_num              ,
2660                         picking_line_id                ,
2661                         trx_source_line_id             ,
2662                         trx_source_delivery_id         ,
2663                         physical_adjustment_id         ,
2664                         cycle_count_id                 ,
2665                         rma_line_id                    ,
2666                         customer_ship_id               ,
2667                         currency_code                  ,
2668                         currency_conversion_rate       ,
2669                         currency_conversion_type       ,
2670                         ship_to_location               ,
2671                         move_order_header_id           ,
2672                         serial_allocated_flag          ,
2673                         trx_flow_header_id             ,
2674                         logical_trx_type_code          ,
2675                         original_transaction_temp_id   ,
2676                         vendor_lot_number              ,
2677                         encumbrance_account            ,
2678                         encumbrance_amount             ,
2679                         transfer_cost                  ,
2680                         transportation_cost            ,
2681                         transportation_account         ,
2682                         freight_code                   ,
2683                         containers                     ,
2684                         waybill_airbill                ,
2685                         expected_arrival_date          ,
2686                         transfer_subinventory          ,
2687                         transfer_organization          ,
2688                         transfer_to_location           ,
2689                         new_average_cost               ,
2690                         value_change                   ,
2691                         percentage_change              ,
2692                         material_allocation_temp_id    ,
2693                         demand_source_header_id        ,
2694                         demand_source_line             ,
2695                         demand_source_delivery         ,
2696                         item_segments                  ,
2697                         item_description               ,
2698                         item_trx_enabled_flag          ,
2699                         item_location_control_code     ,
2700                         item_restrict_subinv_code      ,
2701                         item_restrict_locators_code    ,
2702                         item_revision_qty_control_code ,
2703                         item_primary_uom_code          ,
2704                         item_uom_class                 ,
2705                         item_shelf_life_code           ,
2706                         item_shelf_life_days           ,
2707                         item_lot_control_code          ,
2708                         item_serial_control_code       ,
2709                         item_inventory_asset_flag      ,
2710                         allowed_units_lookup_code      ,
2711                         department_id                  ,
2712                         department_code                ,
2713                         wip_supply_type                ,
2714                         supply_subinventory            ,
2715                         supply_locator_id              ,
2716                         valid_subinventory_flag        ,
2717                         valid_locator_flag             ,
2718                         locator_segments               ,
2719                         current_locator_control_code   ,
2720                         number_of_lots_entered         ,
2721                         wip_commit_flag                ,
2722                         next_lot_number                ,
2723                         lot_alpha_prefix               ,
2724                         next_serial_number             ,
2725                         serial_alpha_prefix            ,
2726                         shippable_flag                 ,
2727                         posting_flag                   ,
2728                         required_flag                  ,
2729                         process_flag                   ,
2730                         ERROR_CODE                     ,
2731                         error_explanation              ,
2732                         attribute_category             ,
2733                         attribute1                     ,
2734                         attribute2                     ,
2735                         attribute3                     ,
2736                         attribute4                     ,
2737                         attribute5                     ,
2738                         attribute6                     ,
2739                         attribute7                     ,
2740                         attribute8                     ,
2741                         attribute9                     ,
2742                         attribute10                    ,
2743                         attribute11                    ,
2744                         attribute12                    ,
2745                         attribute13                    ,
2746                         attribute14                    ,
2747                         attribute15                    ,
2748                         movement_id                    ,
2749                         reservation_quantity           ,
2750                         shipped_quantity               ,
2751                         transaction_line_number        ,
2752                         task_id                        ,
2753                         to_task_id                     ,
2754                         source_task_id                 ,
2755                         project_id                     ,
2756                         source_project_id              ,
2757                         pa_expenditure_org_id          ,
2758                         to_project_id                  ,
2759                         expenditure_type               ,
2760                         final_completion_flag          ,
2761                         transfer_percentage            ,
2762                         transaction_sequence_id        ,
2763                         material_account               ,
2764                         material_overhead_account      ,
2765                         resource_account               ,
2766                         outside_processing_account     ,
2767                         overhead_account               ,
2768                         flow_schedule                  ,
2769                         cost_group_id                  ,
2770                         demand_class                   ,
2771                         qa_collection_id               ,
2772                         kanban_card_id                 ,
2773                         overcompletion_transaction_qty ,
2774                         overcompletion_primary_qty     ,
2775                         overcompletion_transaction_id  ,
2776                         end_item_unit_number           ,
2777                         scheduled_payback_date         ,
2778                         line_type_code                 ,
2779                         parent_transaction_temp_id     ,
2780                         put_away_strategy_id           ,
2781                         put_away_rule_id               ,
2782                         pick_strategy_id               ,
2783                         pick_rule_id                   ,
2784                         move_order_line_id             ,
2785                         task_group_id                  ,
2786                         pick_slip_number               ,
2787                         reservation_id                 ,
2788                         common_bom_seq_id              ,
2789                         common_routing_seq_id          ,
2790                         ussgl_transaction_code         ,
2791                         fulfillment_base               --16662319
2792                 )
2793         SELECT  currency_conversion_date       ,
2794                 shipment_number                ,
2795                 org_cost_group_id              ,
2796                 cost_type_id                   ,
2797                 transaction_status             ,
2798                 standard_operation_id          ,
2799                 task_priority                  ,
2800                 wms_task_type                  ,
2801                 parent_line_id                 ,
2802                 source_lot_number              ,
2803                 transfer_cost_group_id         ,
2804                 lpn_id                         ,
2805                 transfer_lpn_id                ,
2806                 wms_task_status                ,
2807                 content_lpn_id                 ,
2808                 container_item_id              ,
2809                 cartonization_id               ,
2810                 pick_slip_date                 ,
2811                 rebuild_item_id                ,
2812                 rebuild_serial_number          ,
2813                 rebuild_activity_id            ,
2814                 rebuild_job_name               ,
2815                 organization_type              ,
2816                 transfer_organization_type     ,
2817                 owning_organization_id         ,
2818                 owning_tp_type                 ,
2819                 xfr_owning_organization_id     ,
2820                 transfer_owning_tp_type        ,
2821                 planning_organization_id       ,
2822                 planning_tp_type               ,
2823                 xfr_planning_organization_id   ,
2824                 transfer_planning_tp_type      ,
2825                 secondary_uom_code             ,
2826                 p_secondary_qty_to_split	   , -- Added for Bug 16099247
2827                 allocated_lpn_id               ,
2828                 schedule_number                ,
2829                 scheduled_flag                 ,
2830                 class_code                     ,
2831                 schedule_group                 ,
2832                 build_sequence                 ,
2833                 bom_revision                   ,
2834                 routing_revision               ,
2835                 bom_revision_date              ,
2836                 routing_revision_date          ,
2837                 alternate_bom_designator       ,
2838                 alternate_routing_designator   ,
2839                 transaction_batch_id           ,
2840                 transaction_batch_seq          ,
2841                 operation_plan_id              ,
2842                 intransit_account              ,
2843                 fob_point                      ,
2844                 p_new_transaction_header_id --TRANSACTION_HEADER_ID
2845                 ,
2846                 p_new_transaction_temp_id --TRANSACTION_TEMP_ID
2847                 ,
2848                 source_code      ,
2849                 source_line_id   ,
2850                 transaction_mode ,
2851                 lock_flag        ,
2852                 l_sysdate --LAST_UPDATE_DATE
2853                 ,
2854                 FND_GLOBAL.USER_ID ,
2855                 l_sysdate --CREATION_DATE
2856                 ,
2857                 FND_GLOBAL.USER_ID     ,
2858                 last_update_login      ,
2859                 request_id             ,
2860                 program_application_id ,
2861                 program_id             ,
2862                 program_update_date    ,
2863                 inventory_item_id      ,
2864                 revision               ,
2865                 organization_id        ,
2866                 subinventory_code      ,
2867                 locator_id             ,
2868                 p_transaction_qty_to_split --TRANSACTION_QUANTITY
2869                 ,
2870                 p_primary_qty_to_split --PRIMARY_QUANTITY
2871                 ,
2872                 transaction_uom                ,
2873                 transaction_cost               ,
2874                 transaction_type_id            ,
2875                 transaction_action_id          ,
2876                 transaction_source_type_id     ,
2877                 transaction_source_id          ,
2878                 transaction_source_name        ,
2879                 transaction_date               ,
2880                 acct_period_id                 ,
2881                 distribution_account_id        ,
2882                 transaction_reference          ,
2883                 requisition_line_id            ,
2884                 requisition_distribution_id    ,
2885                 reason_id                      ,
2886                 lot_number                     ,
2887                 lot_expiration_date            ,
2888                 serial_number                  ,
2889                 receiving_document             ,
2890                 demand_id                      ,
2891                 rcv_transaction_id             ,
2892                 move_transaction_id            ,
2893                 completion_transaction_id      ,
2894                 wip_entity_type                ,
2895                 schedule_id                    ,
2896                 repetitive_line_id             ,
2897                 employee_code                  ,
2898                 primary_switch                 ,
2899                 schedule_update_code           ,
2900                 setup_teardown_code            ,
2901                 item_ordering                  ,
2902                 negative_req_flag              ,
2903                 operation_seq_num              ,
2904                 picking_line_id                ,
2905                 trx_source_line_id             ,
2906                 trx_source_delivery_id         ,
2907                 physical_adjustment_id         ,
2908                 cycle_count_id                 ,
2909                 rma_line_id                    ,
2910                 customer_ship_id               ,
2911                 currency_code                  ,
2912                 currency_conversion_rate       ,
2913                 currency_conversion_type       ,
2914                 ship_to_location               ,
2915                 move_order_header_id           ,
2916                 serial_allocated_flag          ,
2917                 trx_flow_header_id             ,
2918                 logical_trx_type_code          ,
2919                 original_transaction_temp_id   ,
2920                 vendor_lot_number              ,
2921                 encumbrance_account            ,
2922                 encumbrance_amount             ,
2923                 transfer_cost                  ,
2924                 transportation_cost            ,
2925                 transportation_account         ,
2926                 freight_code                   ,
2927                 containers                     ,
2928                 waybill_airbill                ,
2929                 expected_arrival_date          ,
2930                 transfer_subinventory          ,
2931                 transfer_organization          ,
2932                 transfer_to_location           ,
2933                 new_average_cost               ,
2934                 value_change                   ,
2935                 percentage_change              ,
2936                 material_allocation_temp_id    ,
2937                 demand_source_header_id        ,
2938                 demand_source_line             ,
2939                 demand_source_delivery         ,
2940                 item_segments                  ,
2941                 item_description               ,
2942                 item_trx_enabled_flag          ,
2943                 item_location_control_code     ,
2944                 item_restrict_subinv_code      ,
2945                 item_restrict_locators_code    ,
2946                 item_revision_qty_control_code ,
2947                 item_primary_uom_code          ,
2948                 item_uom_class                 ,
2949                 item_shelf_life_code           ,
2950                 item_shelf_life_days           ,
2951                 item_lot_control_code          ,
2952                 item_serial_control_code       ,
2953                 item_inventory_asset_flag      ,
2954                 allowed_units_lookup_code      ,
2955                 department_id                  ,
2956                 department_code                ,
2957                 wip_supply_type                ,
2958                 supply_subinventory            ,
2959                 supply_locator_id              ,
2960                 valid_subinventory_flag        ,
2961                 valid_locator_flag             ,
2962                 locator_segments               ,
2963                 current_locator_control_code   ,
2964                 number_of_lots_entered         ,
2965                 wip_commit_flag                ,
2966                 next_lot_number                ,
2967                 lot_alpha_prefix               ,
2968                 next_serial_number             ,
2969                 serial_alpha_prefix            ,
2970                 shippable_flag                 ,
2971                 posting_flag                   ,
2972                 required_flag                  ,
2973                 process_flag                   ,
2974                 ERROR_CODE                     ,
2975                 error_explanation              ,
2976                 attribute_category             ,
2977                 attribute1                     ,
2978                 attribute2                     ,
2979                 attribute3                     ,
2980                 attribute4                     ,
2981                 attribute5                     ,
2982                 attribute6                     ,
2983                 attribute7                     ,
2984                 attribute8                     ,
2985                 attribute9                     ,
2986                 attribute10                    ,
2987                 attribute11                    ,
2988                 attribute12                    ,
2989                 attribute13                    ,
2990                 attribute14                    ,
2991                 attribute15                    ,
2992                 movement_id                    ,
2993                 reservation_quantity           ,
2994                 shipped_quantity               ,
2995                 transaction_line_number        ,
2996                 task_id                        ,
2997                 to_task_id                     ,
2998                 source_task_id                 ,
2999                 project_id                     ,
3000                 source_project_id              ,
3001                 pa_expenditure_org_id          ,
3002                 to_project_id                  ,
3003                 expenditure_type               ,
3004                 final_completion_flag          ,
3005                 transfer_percentage            ,
3006                 transaction_sequence_id        ,
3007                 material_account               ,
3008                 material_overhead_account      ,
3009                 resource_account               ,
3010                 outside_processing_account     ,
3011                 overhead_account               ,
3012                 flow_schedule                  ,
3013                 cost_group_id                  ,
3014                 demand_class                   ,
3015                 qa_collection_id               ,
3016                 kanban_card_id                 ,
3017                 overcompletion_transaction_qty ,
3018                 overcompletion_primary_qty     ,
3019                 overcompletion_transaction_id  ,
3020                 end_item_unit_number           ,
3021                 scheduled_payback_date         ,
3022                 line_type_code                 ,
3023                 parent_transaction_temp_id     ,
3024                 put_away_strategy_id           ,
3025                 put_away_rule_id               ,
3026                 pick_strategy_id               ,
3027                 pick_rule_id                   ,
3028                 move_order_line_id             ,
3029                 task_group_id                  ,
3030                 pick_slip_number               ,
3031                 reservation_id                 ,
3032                 common_bom_seq_id              ,
3033                 common_routing_seq_id          ,
3034                 ussgl_transaction_code         ,
3035                 fulfillment_base               --16662319
3036         FROM    mtl_material_transactions_temp
3037         WHERE   transaction_temp_id = p_orig_transaction_temp_id;
3038         x_return_status            := 'S';
3039 EXCEPTION
3040 WHEN OTHERS THEN
3041         x_return_status := 'E';
3042         IF g_debug       = 1 THEN
3043                 print_msg(l_procedure_name,  ' Error Code : '|| SQLCODE || ' Error Message :'||SQLERRM);
3044         END IF;
3045         RETURN;
3046 END split_mmtt;
3047 
3048 -------------------------------------------------------------------------------------------------------------------
3049 --START OF DELETE TASK Process
3050 
3051 PROCEDURE debug_print (p_message IN VARCHAR2 ) IS
3052         l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'), 0);
3053 BEGIN
3054         IF (l_debug                                             = 1) THEN
3055                 inv_mobile_helper_functions.tracelog (p_err_msg => p_message,
3056 						      p_module => 'wms_delete_tasks',
3057 						      p_level => 11);
3058         END IF;
3059 END debug_print;
3060 -------------------------------------------------------------------------------------------------------------------
3061 /*FUNCTION query_rows()
3062 This function gets the move order record for the move order line passed.
3063 */
3064 -------------------------------------------------------------------------------------------------------------------
3065 FUNCTION query_rows(p_line_id IN NUMBER := fnd_api.g_miss_num)
3066 RETURN inv_move_order_pub.trolin_tbl_type IS
3067 
3068         l_trolin_rec inv_move_order_pub.trolin_rec_type;
3069         l_trolin_tbl inv_move_order_pub.trolin_tbl_type;
3070         CURSOR l_trolin_csr
3071         IS
3072                 SELECT  attribute1                 ,
3073                         attribute10                ,
3074                         attribute11                ,
3075                         attribute12                ,
3076                         attribute13                ,
3077                         attribute14                ,
3078                         attribute15                ,
3079                         attribute2                 ,
3080                         attribute3                 ,
3081                         attribute4                 ,
3082                         attribute5                 ,
3083                         attribute6                 ,
3084                         attribute7                 ,
3085                         attribute8                 ,
3086                         attribute9                 ,
3087                         attribute_category         ,
3088                         created_by                 ,
3089                         creation_date              ,
3090                         date_required              ,
3091                         from_locator_id            ,
3092                         from_subinventory_code     ,
3093                         from_subinventory_id       ,
3094                         header_id                  ,
3095                         inventory_item_id          ,
3096                         last_updated_by            ,
3097                         last_update_date           ,
3098                         last_update_login          ,
3099                         line_id                    ,
3100                         line_number                ,
3101                         line_status                ,
3102                         lot_number                 ,
3103                         organization_id            ,
3104                         program_application_id     ,
3105                         program_id                 ,
3106                         program_update_date        ,
3107                         project_id                 ,
3108                         quantity                   ,
3109                         quantity_delivered         ,
3110                         quantity_detailed          ,
3111                         reason_id                  ,
3112                         REFERENCE                  ,
3113                         reference_id               ,
3114                         reference_type_code        ,
3115                         request_id                 ,
3116                         revision                   ,
3117                         serial_number_end          ,
3118                         serial_number_start        ,
3119                         status_date                ,
3120                         task_id                    ,
3121                         to_account_id              ,
3122                         to_locator_id              ,
3123                         to_subinventory_code       ,
3124                         to_subinventory_id         ,
3125                         transaction_header_id      ,
3126                         uom_code                   ,
3127                         transaction_type_id        ,
3128                         transaction_source_type_id ,
3129                         txn_source_id              ,
3130                         txn_source_line_id         ,
3131                         txn_source_line_detail_id  ,
3132                         to_organization_id         ,
3133                         primary_quantity           ,
3134                         pick_strategy_id           ,
3135                         put_away_strategy_id       ,
3136                         unit_number                ,
3137                         ship_to_location_id        ,
3138                         from_cost_group_id         ,
3139                         to_cost_group_id           ,
3140                         lpn_id                     ,
3141                         to_lpn_id                  ,
3142                         inspection_status          ,
3143                         pick_methodology_id        ,
3144                         container_item_id          ,
3145                         carton_grouping_id         ,
3146                         wms_process_flag           ,
3147                         pick_slip_number           ,
3148                         pick_slip_date             ,
3149                         ship_set_id                ,
3150                         ship_model_id              ,
3151                         model_quantity             ,
3152                         required_quantity
3153                 FROM    mtl_txn_request_lines
3154                 WHERE   line_id = p_line_id;
3155 BEGIN
3156         debug_print(  'p_line_id ' || p_line_id);
3157         IF (p_line_id IS NOT NULL AND p_line_id <> fnd_api.g_miss_num ) THEN
3158                 --  Loop over fetched records
3159                 FOR l_implicit_rec IN l_trolin_csr
3160                 LOOP
3161                         l_trolin_rec.attribute1                 := l_implicit_rec.attribute1;
3162                         l_trolin_rec.attribute10                := l_implicit_rec.attribute10;
3163                         l_trolin_rec.attribute11                := l_implicit_rec.attribute11;
3164                         l_trolin_rec.attribute12                := l_implicit_rec.attribute12;
3165                         l_trolin_rec.attribute13                := l_implicit_rec.attribute13;
3166                         l_trolin_rec.attribute14                := l_implicit_rec.attribute14;
3167                         l_trolin_rec.attribute15                := l_implicit_rec.attribute15;
3168                         l_trolin_rec.attribute2                 := l_implicit_rec.attribute2;
3169                         l_trolin_rec.attribute3                 := l_implicit_rec.attribute3;
3170                         l_trolin_rec.attribute4                 := l_implicit_rec.attribute4;
3171                         l_trolin_rec.attribute5                 := l_implicit_rec.attribute5;
3172                         l_trolin_rec.attribute6                 := l_implicit_rec.attribute6;
3173                         l_trolin_rec.attribute7                 := l_implicit_rec.attribute7;
3174                         l_trolin_rec.attribute8                 := l_implicit_rec.attribute8;
3175                         l_trolin_rec.attribute9                 := l_implicit_rec.attribute9;
3176                         l_trolin_rec.attribute_category         := l_implicit_rec.attribute_category;
3177                         l_trolin_rec.created_by                 := l_implicit_rec.created_by;
3178                         l_trolin_rec.creation_date              := l_implicit_rec.creation_date;
3179                         l_trolin_rec.date_required              := l_implicit_rec.date_required;
3180                         l_trolin_rec.from_locator_id            := l_implicit_rec.from_locator_id;
3181                         l_trolin_rec.from_subinventory_code     := l_implicit_rec.from_subinventory_code;
3182                         l_trolin_rec.from_subinventory_id       := l_implicit_rec.from_subinventory_id;
3183                         l_trolin_rec.header_id                  := l_implicit_rec.header_id;
3184                         l_trolin_rec.inventory_item_id          := l_implicit_rec.inventory_item_id;
3185                         l_trolin_rec.last_updated_by            := l_implicit_rec.last_updated_by;
3186                         l_trolin_rec.last_update_date           := l_implicit_rec.last_update_date;
3187                         l_trolin_rec.last_update_login          := l_implicit_rec.last_update_login;
3188                         l_trolin_rec.line_id                    := l_implicit_rec.line_id;
3189                         l_trolin_rec.line_number                := l_implicit_rec.line_number;
3190                         l_trolin_rec.line_status                := l_implicit_rec.line_status;
3191                         l_trolin_rec.lot_number                 := l_implicit_rec.lot_number;
3192                         l_trolin_rec.organization_id            := l_implicit_rec.organization_id;
3193                         l_trolin_rec.program_application_id     := l_implicit_rec.program_application_id;
3194                         l_trolin_rec.program_id                 := l_implicit_rec.program_id;
3195                         l_trolin_rec.program_update_date        := l_implicit_rec.program_update_date;
3196                         l_trolin_rec.project_id                 := l_implicit_rec.project_id;
3197                         l_trolin_rec.quantity                   := l_implicit_rec.quantity;
3198                         l_trolin_rec.quantity_delivered         := l_implicit_rec.quantity_delivered;
3199                         l_trolin_rec.quantity_detailed          := l_implicit_rec.quantity_detailed;
3200                         l_trolin_rec.reason_id                  := l_implicit_rec.reason_id;
3201                         l_trolin_rec.REFERENCE                  := l_implicit_rec.REFERENCE;
3202                         l_trolin_rec.reference_id               := l_implicit_rec.reference_id;
3203                         l_trolin_rec.reference_type_code        := l_implicit_rec.reference_type_code;
3204                         l_trolin_rec.request_id                 := l_implicit_rec.request_id;
3205                         l_trolin_rec.revision                   := l_implicit_rec.revision;
3206                         l_trolin_rec.serial_number_end          := l_implicit_rec.serial_number_end;
3207                         l_trolin_rec.serial_number_start        := l_implicit_rec.serial_number_start;
3208                         l_trolin_rec.status_date                := l_implicit_rec.status_date;
3209                         l_trolin_rec.task_id                    := l_implicit_rec.task_id;
3210                         l_trolin_rec.to_account_id              := l_implicit_rec.to_account_id;
3211                         l_trolin_rec.to_locator_id              := l_implicit_rec.to_locator_id;
3212                         l_trolin_rec.to_subinventory_code       := l_implicit_rec.to_subinventory_code;
3213                         l_trolin_rec.to_subinventory_id         := l_implicit_rec.to_subinventory_id;
3214                         l_trolin_rec.transaction_header_id      := l_implicit_rec.transaction_header_id;
3215                         l_trolin_rec.uom_code                   := l_implicit_rec.uom_code;
3216                         l_trolin_rec.transaction_type_id        := l_implicit_rec.transaction_type_id;
3217                         l_trolin_rec.transaction_source_type_id := l_implicit_rec.transaction_source_type_id;
3218                         l_trolin_rec.txn_source_id              := l_implicit_rec.txn_source_id;
3219                         l_trolin_rec.txn_source_line_id         := l_implicit_rec.txn_source_line_id;
3220                         l_trolin_rec.txn_source_line_detail_id  := l_implicit_rec.txn_source_line_detail_id;
3221                         l_trolin_rec.to_organization_id         := l_implicit_rec.to_organization_id;
3222                         l_trolin_rec.primary_quantity           := l_implicit_rec.primary_quantity;
3223                         l_trolin_rec.pick_strategy_id           := l_implicit_rec.pick_strategy_id;
3224                         l_trolin_rec.put_away_strategy_id       := l_implicit_rec.put_away_strategy_id;
3225                         l_trolin_rec.unit_number                := l_implicit_rec.unit_number;
3226                         l_trolin_rec.ship_to_location_id        := l_implicit_rec.ship_to_location_id;
3227                         l_trolin_rec.from_cost_group_id         := l_implicit_rec.from_cost_group_id;
3228                         l_trolin_rec.to_cost_group_id           := l_implicit_rec.to_cost_group_id;
3229                         l_trolin_rec.lpn_id                     := l_implicit_rec.lpn_id;
3230                         l_trolin_rec.to_lpn_id                  := l_implicit_rec.to_lpn_id;
3231                         l_trolin_rec.inspection_status          := l_implicit_rec.inspection_status;
3232                         l_trolin_rec.pick_methodology_id        := l_implicit_rec.pick_methodology_id;
3233                         l_trolin_rec.container_item_id          := l_implicit_rec.container_item_id;
3234                         l_trolin_rec.carton_grouping_id         := l_implicit_rec.carton_grouping_id;
3235                         l_trolin_rec.wms_process_flag           := l_implicit_rec.wms_process_flag;
3236                         l_trolin_rec.pick_slip_number           := l_implicit_rec.pick_slip_number;
3237                         l_trolin_rec.pick_slip_date             := l_implicit_rec.pick_slip_date;
3238                         l_trolin_rec.ship_set_id                := l_implicit_rec.ship_set_id;
3239                         l_trolin_rec.ship_model_id              := l_implicit_rec.ship_model_id;
3240                         l_trolin_rec.model_quantity             := l_implicit_rec.model_quantity;
3241                         l_trolin_rec.required_quantity          := l_implicit_rec.required_quantity;
3242                         l_trolin_tbl(l_trolin_tbl.COUNT + 1)    := l_trolin_rec;
3243                 END LOOP;
3244         END IF;
3245         IF (p_line_id IS NOT NULL AND p_line_id <> fnd_api.g_miss_num ) AND (l_trolin_tbl.COUNT = 0) THEN
3246                 debug_print('no data found');
3247                 RAISE NO_DATA_FOUND;
3248         END IF;
3249         --  Return fetched table
3250         RETURN l_trolin_tbl;
3251 EXCEPTION
3252 WHEN fnd_api.g_exc_unexpected_error THEN
3253         RAISE fnd_api.g_exc_unexpected_error;
3254 WHEN OTHERS THEN
3255         RAISE fnd_api.g_exc_unexpected_error;
3256 END query_rows;
3257 
3258 -------------------------------------------------------------------------------------------------------------------
3259 /*PROCEDURE delete_transaction()
3260 This procedure checks for lot/serial control-deletes MTLT, MSNT,
3261 Unmarks the serials, checks if a task record exists in wms_dispatched_tasks and deletes it.
3262 */
3263 -------------------------------------------------------------------------------------------------------------------
3264 PROCEDURE delete_transaction( x_return_status OUT NOCOPY VARCHAR2 ,
3265 			      x_msg_data OUT NOCOPY VARCHAR2 ,
3266 			      x_msg_count OUT NOCOPY NUMBER ,
3267 			      p_transaction_temp_id NUMBER ,
3268 			      p_update_parent BOOLEAN ) IS
3269 
3270         l_inventory_item_id   NUMBER;
3271         l_lot_control_code    NUMBER;
3272         l_serial_control_code NUMBER;
3273         l_fm_serial_number    VARCHAR2(30);
3274         l_to_serial_number    VARCHAR2(30);
3275         l_unmarked_count      NUMBER := 0;
3276         l_parent_line_id      NUMBER;
3277         l_child_txn_qty       NUMBER;
3278         l_child_pri_qty       NUMBER;
3279         l_child_uom           VARCHAR2(3);
3280         exc_not_deleted       EXCEPTION;
3281         l_msnt_count          NUMBER;
3282         l_wdt_count           NUMBER;
3283         l_msn_count           NUMBER;
3284         l_debug               NUMBER;
3285         CURSOR c_item_info
3286         IS
3287                 SELECT  msi.inventory_item_id         ,
3288                         msi.lot_control_code          ,
3289                         msi.serial_number_control_code,
3290                         mmtt.parent_line_id
3291                 FROM    mtl_system_items msi,
3292                         mtl_material_transactions_temp mmtt
3293                 WHERE   mmtt.transaction_temp_id = p_transaction_temp_id
3294                     AND msi.inventory_item_id    = mmtt.inventory_item_id
3295                     AND msi.organization_id      = mmtt.organization_id;
3296 BEGIN
3297         l_debug         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3298         x_return_status := fnd_api.g_ret_sts_success;
3299         SAVEPOINT deltxn;
3300         IF l_debug = 1 THEN
3301                 debug_print(  'Cleaning up MMTT, MTLT and MSNT for Txn Temp ID = ' || p_transaction_temp_id);
3302         END IF;
3303         OPEN c_item_info;
3304         FETCH   c_item_info
3305         INTO    l_inventory_item_id  ,
3306                 l_lot_control_code   ,
3307                 l_serial_control_code,
3308                 l_parent_line_id;
3309         CLOSE c_item_info;
3310         IF l_debug = 1 THEN
3311                 debug_print(  'Item ID        = ' || l_inventory_item_id);
3312                 debug_print(  'Lot Control    = ' || l_lot_control_code);
3313                 debug_print(  'Serial Control = ' || l_serial_control_code);
3314                 debug_print(  'Parent Line ID = ' || l_parent_line_id);
3315         END IF;
3316         IF l_parent_line_id IS NOT NULL AND p_update_parent THEN
3317                 IF l_debug = 1 THEN
3318                         debug_print(  'Child Record... Updating the Parent: TxnTempID = ' || l_parent_line_id);
3319                 END IF;
3320                 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3321                         IF l_debug  = 1 THEN
3322                                 debug_print('Error occurred while updating parent line in MMTT');
3323                         END IF;
3324                         ROLLBACK TO deltxn;
3325                         RAISE exc_not_deleted;
3326                 END IF;
3327         END IF;
3328         -- Unmarking and Deleting all the Serials associated with the Transaction
3329         IF l_serial_control_code     IN(2, 5) THEN --If serial controlled
3330                 IF l_lot_control_code = 2 THEN     -- If lot controlled also
3331                         SELECT  count (*)
3332                         INTO    l_msn_count
3333                         FROM    mtl_serial_numbers
3334                         WHERE   group_mark_id IN
3335                                 (SELECT serial_transaction_temp_id
3336                                 FROM    mtl_transaction_lots_temp
3337                                 WHERE   transaction_temp_id = p_transaction_temp_id
3338                                 );
3339                         IF l_msn_count > 0 THEN
3340                                 UPDATE mtl_serial_numbers
3341                                         SET group_mark_id = NULL,
3342                                         line_mark_id      = NULL,
3343                                         lot_line_mark_id  = NULL
3344                                 WHERE   group_mark_id    IN
3345                                         (SELECT serial_transaction_temp_id
3346                                         FROM    mtl_transaction_lots_temp
3347                                         WHERE   transaction_temp_id = p_transaction_temp_id
3348                                         );
3349                                 l_unmarked_count  := SQL%ROWCOUNT;
3350                                 IF SQL%ROWCOUNT    = 0 THEN
3351                                         IF l_debug = 1 THEN
3352                                                 debug_print (   'Error updating MSN  ');
3353                                         END IF;
3354                                         ROLLBACK TO deltxn;
3355                                         RAISE exc_not_deleted;
3356                                 END IF;
3357                         END IF;
3358                         SELECT  count(*)
3359                         INTO    l_msnt_count
3360                         FROM    mtl_serial_numbers_temp
3361                         WHERE   transaction_temp_id IN
3362                                 (SELECT serial_transaction_temp_id
3363                                 FROM    mtl_transaction_lots_temp
3364                                 WHERE   transaction_temp_id = p_transaction_temp_id
3365                                 );
3366                         IF l_msnt_count > 0 THEN
3367                                 DELETE mtl_serial_numbers_temp
3368                                 WHERE   transaction_temp_id IN
3369                                         (SELECT serial_transaction_temp_id
3370                                         FROM    mtl_transaction_lots_temp
3371                                         WHERE   transaction_temp_id = p_transaction_temp_id
3372                                         );
3373                                 IF SQL%ROWCOUNT    = 0 THEN
3374                                         IF l_debug = 1 THEN
3375                                                 debug_print (   'Error deleting MSNT  ');
3376                                         END IF;
3377                                         ROLLBACK TO deltxn;
3378                                         RAISE exc_not_deleted;
3379                                 END IF;
3380                         END IF;
3381                 ELSE -- only serial controlled but not lot controlled.
3382                         SELECT  count(*)
3383                         INTO    l_msn_count
3384                         FROM    mtl_serial_numbers
3385                         WHERE   group_mark_id = p_transaction_temp_id ;
3386                         IF l_msn_count        > 0 THEN
3387                                 UPDATE mtl_serial_numbers
3388                                         SET group_mark_id = NULL,
3389                                         line_mark_id      = NULL,
3390                                         lot_line_mark_id  = NULL
3391                                 WHERE   group_mark_id     = p_transaction_temp_id ;
3392                                 l_unmarked_count         := SQL%ROWCOUNT;
3393                                 IF SQL%ROWCOUNT           = 0 THEN
3394                                         IF l_debug        = 1 THEN
3395                                                 debug_print (   'Error updating MSN  ');
3396                                         END IF;
3397                                         ROLLBACK TO deltxn;
3398                                         RAISE exc_not_deleted;
3399                                 END IF;
3400                         END IF;
3401                         SELECT  count (*)
3402                         INTO    l_msnt_count
3403                         FROM    mtl_serial_numbers_temp
3404                         WHERE   transaction_temp_id = p_transaction_temp_id;
3405                         IF l_msnt_count             > 0 THEN
3406                                 DELETE mtl_serial_numbers_temp
3407                                 WHERE   transaction_temp_id = p_transaction_temp_id;
3408                                 IF SQL%ROWCOUNT             = 0 THEN
3409                                         IF l_debug          = 1 THEN
3410                                                 debug_print (  'Error deleting  MSNT ');
3411                                         END IF;
3412                                         ROLLBACK TO deltxn;
3413                                         RAISE exc_not_deleted;
3414                                 END IF;
3415                         END IF;
3416                 END IF;
3417                 IF l_debug = 1 THEN
3418                         debug_print(  'Serials unmarked in MSN = ' || l_unmarked_count);
3419                         debug_print(  'Records deleted in MSNT = ' || SQL%ROWCOUNT);
3420                 END IF;
3421         END IF;
3422         -- Deleting all the Lots associated with the Transaction
3423         IF l_lot_control_code = 2 THEN
3424                 DELETE mtl_transaction_lots_temp
3425                 WHERE   transaction_temp_id = p_transaction_temp_id;
3426                 IF SQL%ROWCOUNT             = 0 THEN
3427                         IF l_debug          = 1 THEN
3428                                 debug_print (   'Error deleting MTLT  ');
3429                         END IF;
3430                         ROLLBACK TO deltxn;
3431                         RAISE exc_not_deleted;
3432                 END IF;
3433                 IF l_debug = 1 THEN
3434                         debug_print(  'Records deleted in MTLT = ' || SQL%ROWCOUNT);
3435                 END IF;
3436         END IF;
3437         SELECT  count (*)
3438         INTO    l_wdt_count
3439         FROM    wms_dispatched_tasks
3440         WHERE   transaction_temp_id = p_transaction_temp_id;
3441         IF l_wdt_count              >0 THEN
3442                 -- Deleting the Task
3443                 DELETE wms_dispatched_tasks WHERE transaction_temp_id = p_transaction_temp_id;
3444                 IF l_debug = 1 THEN
3445                         debug_print(  'Records deleted in WDT = ' || SQL%ROWCOUNT);
3446                 END IF;
3447                 IF SQL%ROWCOUNT = 0 THEN
3448                         debug_print (   'Error deleting WDT  ');
3449                         ROLLBACK TO deltxn;
3450                         RAISE exc_not_deleted;
3451                 END IF;
3452         END IF;
3453         -- Deleting the Transaction
3454         DELETE mtl_material_transactions_temp
3455         WHERE   transaction_temp_id = p_transaction_temp_id;
3456         IF SQL%ROWCOUNT             = 0 THEN
3457                 IF l_debug          = 1 THEN
3458                         debug_print (   'Error deleting MMTT  ');
3459                 END IF;
3460                 ROLLBACK TO deltxn;
3461                 RAISE exc_not_deleted;
3462         END IF;
3463         IF l_debug = 1 THEN
3464                 debug_print(  'Records deleted in MMTT = ' || SQL%ROWCOUNT);
3465         END IF;
3466 EXCEPTION
3467 WHEN exc_not_deleted THEN
3468         IF l_debug =1 THEN
3469                 debug_print('In the exception for could not delete a record. Returning staus as E');
3470         END IF;
3471         x_return_status := 'E';
3472 WHEN OTHERS THEN
3473         x_return_status := fnd_api.g_ret_sts_unexp_error;
3474         IF l_debug       = 1 THEN
3475                 debug_print(  'Exception Occurred = ' || SQLERRM);
3476         END IF;
3477         ROLLBACK TO deltxn;
3478 END delete_transaction;
3479 
3480 -------------------------------------------------------------------------------------------------------------------
3481 /*PROCEDURE delete_details()
3482 This procedure calls inv_reservation_pub.update_reservation() to udpate/delete reservation and subsequently
3483 calls delete_transactions.
3484 */
3485 -------------------------------------------------------------------------------------------------------------------
3486 PROCEDURE delete_details( p_transaction_temp_id IN NUMBER ,
3487 			  p_move_order_line_id IN NUMBER ,
3488 			  p_reservation_id IN NUMBER ,
3489 			  p_transaction_quantity IN NUMBER ,
3490 			  p_primary_trx_qty IN NUMBER ,
3491 			  x_return_status OUT NOCOPY VARCHAR2 ,
3492 			  x_msg_count OUT NOCOPY NUMBER ,
3493 			  x_msg_data OUT NOCOPY VARCHAR2 ) IS
3494 
3495         l_mtl_reservation_tbl inv_reservation_global.mtl_reservation_tbl_type;
3496         l_mtl_reservation_rec inv_reservation_global.mtl_reservation_rec_type;
3497         l_mtl_reservation_tbl_count NUMBER;
3498         l_original_serial_number inv_reservation_global.serial_number_tbl_type;
3499         l_to_serial_number inv_reservation_global.serial_number_tbl_type;
3500         l_error_code               NUMBER;
3501         l_count                    NUMBER;
3502         l_success                  BOOLEAN;
3503         l_umconvert_trans_quantity NUMBER := 0;
3504         l_mmtt_rec inv_mo_line_detail_util.g_mmtt_rec;
3505         l_primary_uom             VARCHAR2(10);
3506         l_ato_item                NUMBER := 0;
3507         l_debug                   NUMBER;
3508         l_rsv_detailed_qty        NUMBER;
3509         l_rsv_reservation_qty     NUMBER;
3510         l_rsv_pri_reservation_qty NUMBER;
3511         g_retain_ato_profile      VARCHAR2(1) := fnd_profile.VALUE('WSH_RETAIN_ATO_RESERVATIONS');
3512         exc_not_deleted           EXCEPTION;
3513 BEGIN
3514         l_debug         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3515         x_return_status := fnd_api.g_ret_sts_success;
3516         SAVEPOINT delete_details;
3517         IF (l_debug = 1) THEN
3518                 debug_print(  'Transaction Temp ID = ' || p_transaction_temp_id);
3519                 debug_print(  'Move Order Line ID  = ' || p_move_order_line_id);
3520                 debug_print(  'Transaction Qty     = ' || p_transaction_quantity);
3521                 debug_print(  'Reservation ID      = ' || p_reservation_id);
3522         END IF;
3523         IF p_reservation_id IS NOT NULL THEN
3524                 l_mtl_reservation_rec.reservation_id                       := p_reservation_id;
3525                 inv_reservation_pub.query_reservation( p_api_version_number => 1.0 ,
3526 						       x_return_status => x_return_status ,
3527 						       x_msg_count => x_msg_count ,
3528 						       x_msg_data => x_msg_data ,
3529 						       p_query_input => l_mtl_reservation_rec ,
3530 						       x_mtl_reservation_tbl => l_mtl_reservation_tbl ,
3531 						       x_mtl_reservation_tbl_count => l_mtl_reservation_tbl_count ,
3532 						       x_error_code => l_error_code );
3533 
3534                 IF l_debug                                                  = 1 THEN
3535                         debug_print(  'x_return_status = ' || x_return_status);
3536                         debug_print(  'l_error_code = ' || l_error_code);
3537                         debug_print(  'l_mtl_reservation_tbl_count = ' || l_mtl_reservation_tbl_count);
3538                 END IF;
3539                 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3540                         IF l_debug  = 1 THEN
3541                                 debug_print('delete_mo: Error occurred while deleting MMTT');
3542                         END IF;
3543                         ROLLBACK TO delete_details;
3544                         RAISE exc_not_deleted ;
3545                 END IF;
3546                 IF l_mtl_reservation_tbl_count > 0 THEN
3547                         -- If reservations exist, check if the item is an ATO Item
3548                         --   only if the profile WSH_RETAIN_ATO_RESERVATIONS = 'Y'
3549                         IF g_retain_ato_profile = 'Y' THEN
3550                                 IF l_debug      = 1 THEN
3551                                         debug_print('g_retain_ato_profile = Y');
3552                                 END IF;
3553                                 BEGIN
3554                                         SELECT  1,
3555                                                 primary_uom_code
3556                                         INTO    l_ato_item,
3557                                                 l_primary_uom
3558                                         FROM    mtl_system_items
3559                                         WHERE   replenish_to_order_flag = 'Y'
3560                                             AND bom_item_type           = 4
3561                                             AND inventory_item_id       = l_mtl_reservation_tbl(1).inventory_item_id
3562                                             AND organization_id         = l_mtl_reservation_tbl(1).organization_id;
3563                                 EXCEPTION
3564                                 WHEN OTHERS THEN
3565                                         l_ato_item := 0;
3566                                 END;
3567                         END IF;
3568                         IF l_debug = 1 THEN
3569                                 debug_print(  'l_ato_item = ' || l_ato_item);
3570                         END IF;
3571                         l_rsv_detailed_qty        := NVL(l_mtl_reservation_tbl(1).detailed_quantity,0);
3572                         l_rsv_reservation_qty     := NVL(l_mtl_reservation_tbl(1).reservation_quantity,0);
3573                         l_rsv_pri_reservation_qty := NVL(l_mtl_reservation_tbl(1).primary_reservation_quantity,0);
3574                         IF l_ato_item              = 1 THEN
3575                                 IF l_debug         = 1 THEN
3576                                         debug_print('l_ato_item = 1');
3577                                 END IF;
3578                                 -- If item is ato item, reduce the detailed quantity by the transaction
3579                                 -- quantity and retain the reservation. Convert to primary uom before
3580                                 -- reducing detailed quantity.
3581                                 l_mmtt_rec                := inv_mo_line_detail_util.query_row(p_transaction_temp_id);
3582                                 l_umconvert_trans_quantity:= p_transaction_quantity;
3583                                 IF l_mmtt_rec.inventory_item_id IS NOT NULL AND l_mmtt_rec.transaction_uom IS NOT NULL THEN
3584                                         IF l_debug = 1 THEN
3585                                                 debug_print(  'UOM Convert = ');
3586                                         END IF;
3587                                         l_umconvert_trans_quantity := inv_convert.inv_um_convert( item_id => l_mmtt_rec.inventory_item_id ,
3588 												  PRECISION => NULL ,
3589 												  from_quantity => p_transaction_quantity ,
3590 												  from_unit => l_mmtt_rec.transaction_uom ,
3591 												  to_unit => l_primary_uom ,
3592 												  from_name => NULL ,
3593 												  to_name => NULL);
3594                                 END IF;
3595                                 l_mtl_reservation_rec                              := l_mtl_reservation_tbl(1);
3596                                 IF(l_rsv_detailed_qty                               > ABS(l_umconvert_trans_quantity)) THEN
3597                                         l_mtl_reservation_tbl(1).detailed_quantity := l_rsv_detailed_qty - ABS(l_umconvert_trans_quantity);
3598                                 ELSE
3599                                         l_mtl_reservation_tbl(1).detailed_quantity := 0;
3600                                 END IF;
3601                                 IF l_debug = 1 THEN
3602                                         debug_print(  'call inv_reservation_pub.update_reservation = ');
3603                                 END IF;
3604                                 inv_reservation_pub.update_reservation( p_api_version_number => 1.0 ,
3605 									x_return_status => x_return_status ,
3606 									x_msg_count => x_msg_count ,
3607 									x_msg_data => x_msg_data ,
3608 									p_original_rsv_rec => l_mtl_reservation_rec ,
3609 									p_to_rsv_rec => l_mtl_reservation_tbl(1) ,
3610 									p_original_serial_number => l_original_serial_number ,
3611 									p_to_serial_number => l_to_serial_number);
3612                                 IF l_debug                                                   = 1 THEN
3613                                         debug_print('x_return_status' || x_return_status);
3614                                 END IF;
3615                                 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3616                                         IF l_debug  = 1 THEN
3617                                                 debug_print('delete_mo: Error occurred while updating reservations');
3618                                         END IF;
3619                                         ROLLBACK TO delete_details;
3620                                         RAISE exc_not_deleted ;
3621                                 END IF;
3622                         ELSE
3623                                 l_mtl_reservation_rec := l_mtl_reservation_tbl(1);
3624                                 l_mmtt_rec            := inv_mo_line_detail_util.query_row(p_transaction_temp_id);
3625                                 IF l_debug             = 1 THEN
3626                                         debug_print(  'Allocation UOM  = ' || l_mmtt_rec.transaction_uom);
3627                                         debug_print(  'Reservation UOM = ' || l_mtl_reservation_rec.reservation_uom_code);
3628                                 END IF;
3629                                 IF l_mmtt_rec.transaction_uom      <> l_mtl_reservation_rec.reservation_uom_code THEN
3630                                         l_umconvert_trans_quantity := inv_convert.inv_um_convert( item_id => l_mmtt_rec.inventory_item_id ,
3631 												  PRECISION => NULL ,
3632 												  from_quantity => ABS(p_transaction_quantity) ,
3633 												  from_unit => l_mmtt_rec.transaction_uom ,
3634 												  to_unit => l_mtl_reservation_rec.reservation_uom_code ,
3635 												  from_name => NULL ,
3636 												  to_name => NULL);
3637                                 ELSE
3638                                         l_umconvert_trans_quantity := ABS(p_transaction_quantity);
3639                                 END IF;
3640                                 IF l_debug = 1 THEN
3641                                         debug_print(  'After UOM Conversion TxnQty = ' || l_umconvert_trans_quantity);
3642                                 END IF;
3643                                 IF(l_rsv_detailed_qty                               > ABS(p_transaction_quantity)) THEN
3644                                         l_mtl_reservation_tbl(1).detailed_quantity := l_rsv_detailed_qty - ABS(p_transaction_quantity);
3645                                 ELSE
3646                                         l_mtl_reservation_tbl(1).detailed_quantity := 0;
3647                                 END IF;
3648                                 IF(l_rsv_reservation_qty                               > ABS(l_umconvert_trans_quantity)) THEN
3649                                         l_mtl_reservation_tbl(1).reservation_quantity := l_rsv_reservation_qty - ABS(l_umconvert_trans_quantity);
3650                                 ELSE
3651                                         l_mtl_reservation_tbl(1).reservation_quantity := 0;
3652                                 END IF;
3653                                 IF(l_rsv_pri_reservation_qty                                   > ABS(p_primary_trx_qty)) THEN
3654                                         l_mtl_reservation_tbl(1).primary_reservation_quantity := l_rsv_pri_reservation_qty - ABS(p_primary_trx_qty);
3655                                 ELSE
3656                                         l_mtl_reservation_tbl(1).primary_reservation_quantity := 0;
3657                                 END IF;
3658                                 inv_reservation_pub.update_reservation( p_api_version_number => 1.0 ,
3659 									x_return_status => x_return_status ,
3660 									x_msg_count => x_msg_count ,
3661 									x_msg_data => x_msg_data ,
3662 									p_original_rsv_rec => l_mtl_reservation_rec ,
3663 									p_to_rsv_rec => l_mtl_reservation_tbl(1) ,
3664 									p_original_serial_number => l_original_serial_number ,
3665 									p_to_serial_number => l_to_serial_number);
3666 
3667                                 IF l_debug                                                   = 1 THEN
3668                                         debug_print(  'x_return_status from inv_reservation_pub.update_reservation ' || x_return_status);
3669                                 END IF;
3670                                 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3671                                         IF l_debug  = 1 THEN
3672                                                 debug_print('delete_mo: Error occurred while updating reservations');
3673                                         END IF;
3674                                         ROLLBACK TO delete_details;
3675                                         RAISE exc_not_deleted ;
3676                                 END IF;
3677                         END IF; -- reservation count > 0
3678                 END IF;         -- ato item check
3679         END IF;
3680         IF l_debug = 1 THEN
3681                 debug_print(  'call delete_transaction ' );
3682         END IF;
3683         delete_transaction( x_return_status => x_return_status ,
3684 			    x_msg_data => x_msg_data ,
3685 			    x_msg_count => x_msg_count ,
3686 			    p_transaction_temp_id => p_transaction_temp_id ,
3687 			    p_update_parent => FALSE);
3688         IF l_debug                          = 1 THEN
3689                 debug_print(  'x_return_status ' || x_return_status);
3690         END IF;
3691         IF x_return_status = fnd_api.g_ret_sts_error THEN
3692                 IF l_debug = 1 THEN
3693                         debug_print('delete_mo: Error occurred while deleting MMTT');
3694                 END IF;
3695                 ROLLBACK TO delete_details;
3696                 RAISE exc_not_deleted ;
3697         ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
3698                 IF l_debug    = 1 THEN
3699                         debug_print('delete_mo: Error occurred while deleting MMTT');
3700                 END IF;
3701                 ROLLBACK TO delete_details;
3702         END IF;
3703 EXCEPTION
3704 WHEN exc_not_deleted THEN
3705         IF l_debug =1 THEN
3706                 debug_print('In the exception for could not delete a record. Returning staus as E');
3707         END IF;
3708         x_return_status := 'E';
3709 WHEN OTHERS THEN
3710         x_return_status := fnd_api.g_ret_sts_unexp_error;
3711         ROLLBACK TO delete_details;
3712 END delete_details;
3713 
3714 -------------------------------------------------------------------------------------------------------------------
3715 
3716 PROCEDURE backorder_source( x_return_status OUT NOCOPY VARCHAR2 ,
3717 			    x_msg_count OUT NOCOPY NUMBER ,
3718 			    x_msg_data OUT NOCOPY VARCHAR2 ,
3719 			    p_move_order_type NUMBER ,
3720 			    p_mo_line_rec inv_move_order_pub.trolin_rec_type ,
3721 			    p_qty_to_backorder NUMBER ) IS
3722 
3723         l_shipping_attr wsh_interface.changedattributetabtype;
3724         l_released_status    VARCHAR2(1);
3725         l_delivery_detail_id NUMBER;
3726         l_source_header_id   NUMBER;
3727         l_source_line_id     NUMBER;
3728         l_qty_to_backorder   NUMBER := 0;
3729         l_debug              NUMBER;
3730         exc_not_deleted      EXCEPTION;
3731         CURSOR c_wsh_info
3732         IS
3733                 SELECT  delivery_detail_id,
3734                         oe_header_id      ,
3735                         oe_line_id        ,
3736                         released_status
3737                 FROM    wsh_inv_delivery_details_v
3738                 WHERE   move_order_line_id = p_mo_line_rec.line_id
3739                     AND move_order_line_id IS NOT NULL
3740                     AND released_status = 'S';
3741 BEGIN
3742         SAVEPOINT backorder_source;
3743         x_return_status            := fnd_api.g_ret_sts_success;
3744         l_debug                    := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3745         l_qty_to_backorder         := p_qty_to_backorder;
3746         IF l_qty_to_backorder       < 0 THEN
3747                 l_qty_to_backorder := 0;
3748         END IF;
3749         IF l_debug = 1 THEN
3750                 debug_print('l_qty_to_backorder' || l_qty_to_backorder);
3751         END IF;
3752         IF p_move_order_type = inv_globals.g_move_order_pick_wave THEN
3753                 IF l_debug   = 1 THEN
3754                         debug_print('in mo type pick wave' );
3755                 END IF;
3756                 OPEN c_wsh_info;
3757                 FETCH   c_wsh_info
3758                 INTO    l_delivery_detail_id,
3759                         l_source_header_id  ,
3760                         l_source_line_id    ,
3761                         l_released_status;
3762                 IF c_wsh_info%NOTFOUND THEN
3763                         CLOSE c_wsh_info;
3764                         IF l_debug = 1 THEN
3765                                 debug_print('NOTFOUND c_wsh_info' );
3766                         END IF;
3767                         RAISE fnd_api.g_exc_error;
3768                 END IF;
3769                 CLOSE c_wsh_info;
3770                 IF l_debug = 1 THEN
3771                         debug_print('finished fetching' );
3772                 END IF;
3773                 --Call Update_Shipping_Attributes to backorder detail line
3774                 l_shipping_attr(1).source_header_id     := l_source_header_id;
3775                 l_shipping_attr(1).source_line_id       := l_source_line_id;
3776                 l_shipping_attr(1).ship_from_org_id     := p_mo_line_rec.organization_id;
3777                 l_shipping_attr(1).released_status      := l_released_status;
3778                 l_shipping_attr(1).delivery_detail_id   := l_delivery_detail_id;
3779                 l_shipping_attr(1).action_flag          := 'B';
3780                 l_shipping_attr(1).cycle_count_quantity := l_qty_to_backorder;
3781                 l_shipping_attr(1).subinventory         := p_mo_line_rec.from_subinventory_code;
3782                 l_shipping_attr(1).locator_id           := p_mo_line_rec.from_locator_id;
3783                 IF (l_debug                              = 1) THEN
3784                         debug_print('Calling Update Shipping Attributes');
3785                         debug_print(  '  Source Header ID   = ' || l_shipping_attr(1).source_header_id);
3786                         debug_print(  '  Source Line ID     = ' || l_shipping_attr(1).source_line_id);
3787                         debug_print(  '  Ship From Org ID   = ' || l_shipping_attr(1).ship_from_org_id);
3788                         debug_print(  '  Released Status    = ' || l_shipping_attr(1).released_status);
3789                         debug_print(  '  Delivery Detail ID = ' || l_shipping_attr(1).delivery_detail_id);
3790                         debug_print(  '  Action Flag        = ' || l_shipping_attr(1).action_flag);
3791                         debug_print(  '  Cycle Count Qty    = ' || l_shipping_attr(1).cycle_count_quantity);
3792                         debug_print(  '  Subinventory       = ' || l_shipping_attr(1).subinventory);
3793                         debug_print(  '  Locator ID         = ' || l_shipping_attr(1).locator_id);
3794                 END IF;
3795                 wsh_interface.update_shipping_attributes( p_source_code => 'INV' ,
3796 							  p_changed_attributes => l_shipping_attr ,
3797 							  x_return_status => x_return_status );
3798                 IF (l_debug                                             = 1) THEN
3799                         debug_print(  'Updated Shipping Attributes - Return Status = ' || x_return_status);
3800                 END IF;
3801                 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3802                         ROLLBACK TO backorder_source;
3803                         RAISE exc_not_deleted ;
3804                 END IF;
3805         ELSIF p_move_order_type = inv_globals.g_move_order_mfg_pick THEN
3806                 IF l_debug      = 1 THEN
3807                         debug_print('Calling Unallocate WIP Material');
3808                         debug_print(  '  WIP Entity ID     = ' || p_mo_line_rec.txn_source_id);
3809                         debug_print(  '  Operation Seq Num = ' || p_mo_line_rec.txn_source_line_id);
3810                         debug_print(  '  Inventory Item ID = ' || p_mo_line_rec.inventory_item_id);
3811                         debug_print(  '  Repetitive Sch ID = ' || p_mo_line_rec.reference_id);
3812                         debug_print(  '  Primary Qty       = ' || l_qty_to_backorder);
3813                 END IF;
3814                 wip_picking_pub.unallocate_material( x_return_status => x_return_status ,
3815 						     x_msg_data => x_msg_data ,
3816 						     p_wip_entity_id => p_mo_line_rec.txn_source_id ,
3817 						     p_operation_seq_num => p_mo_line_rec.txn_source_line_id ,
3818 						     p_inventory_item_id => p_mo_line_rec.inventory_item_id ,
3819 						     p_repetitive_schedule_id => p_mo_line_rec.reference_id ,
3820 						     p_primary_quantity => l_qty_to_backorder );
3821 
3822                 IF (l_debug                                          = 1) THEN
3823                         debug_print(  'Unallocated WIP Material  - Return Status = ' || x_return_status);
3824                 END IF;
3825                 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3826                         ROLLBACK TO backorder_source;
3827                         RAISE exc_not_deleted ;
3828                 END IF;
3829         END IF;
3830 EXCEPTION
3831 WHEN exc_not_deleted THEN
3832         IF l_debug =1 THEN
3833                 debug_print('In the exception for could not delete a record. Returning staus as E');
3834         END IF;
3835         x_return_status := 'E';
3836 WHEN OTHERS THEN
3837         x_return_status := fnd_api.g_ret_sts_unexp_error;
3838         ROLLBACK TO backorder_source;
3839 END backorder_source;
3840 
3841 -------------------------------------------------------------------------------------------------------------------
3842 /*PROCEDURE backorder()
3843 This procedure calls wsh_interface.update_shipping_attributes() for MO of type pick wave, else calls
3844 wip_picking_pub.unallocate_material for MO of type WIP
3845 */
3846 -------------------------------------------------------------------------------------------------------------------
3847 PROCEDURE backorder( p_line_id IN NUMBER ,
3848 		     p_transaction_temp_id IN NUMBER ,
3849 		     x_return_status OUT NOCOPY VARCHAR2 ,
3850 		     x_msg_count OUT NOCOPY NUMBER ,
3851 		     x_msg_data OUT NOCOPY VARCHAR2 ) IS
3852 
3853         l_mo_line_rec inv_move_order_pub.trolin_rec_type;
3854         l_mold_tbl inv_mo_line_detail_util.g_mmtt_tbl_type;
3855         l_mo_type              NUMBER;
3856         l_allow_backordering   VARCHAR2(1) := 'Y';
3857         l_debug                NUMBER;
3858         l_transaction_quantity NUMBER;
3859         exc_not_deleted        EXCEPTION;
3860         CURSOR c_allow_backordering
3861         IS
3862                 SELECT 'N'
3863                 FROM    DUAL
3864                 WHERE   EXISTS
3865                         (SELECT 1
3866                         FROM    wms_dispatched_tasks wdt,
3867                                 mtl_material_transactions_temp mmtt
3868                         WHERE   mmtt.move_order_line_id = l_mo_line_rec.line_id
3869                             AND wdt.transaction_temp_id = nvl(mmtt.parent_line_id, mmtt.transaction_temp_id)
3870                             AND wdt.status             IN (4,9)
3871                         );
3872         CURSOR c_mo_type
3873         IS
3874                 SELECT  mtrh.move_order_type
3875                 FROM    mtl_txn_request_headers mtrh,
3876                         mtl_txn_request_lines mtrl
3877                 WHERE   mtrl.line_id   = l_mo_line_rec.line_id
3878                     AND mtrh.header_id = mtrl.header_id;
3879         CURSOR c_mmtt_info
3880         IS
3881                 SELECT  mmtt.transaction_temp_id                            ,
3882                         ABS(mmtt.primary_quantity) primary_quantity         ,
3883                         ABS(mmtt.transaction_quantity) transaction_quantity ,
3884                         mmtt.reservation_id
3885                 FROM    mtl_material_transactions_temp mmtt
3886                 WHERE   mmtt.move_order_line_id = p_line_id
3887                     AND NOT EXISTS
3888                         (SELECT 1
3889                         FROM    mtl_material_transactions_temp t
3890                         WHERE   t.parent_line_id = mmtt.transaction_temp_id
3891                         )
3892                         FOR UPDATE NOWAIT;
3893 BEGIN
3894         x_return_status := fnd_api.g_ret_sts_success;
3895         l_debug         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3896         -- Set savepoint
3897         SAVEPOINT backorder;
3898         IF (l_debug = 1) THEN
3899                 debug_print(  'Backordering for MO Line ID = ' || p_line_id);
3900         END IF;
3901         l_mo_line_rec := query_rows(p_line_id)(1);
3902         -- Querying the Move Order Type of the Line.
3903         OPEN c_mo_type;
3904         FETCH c_mo_type INTO l_mo_type;
3905         CLOSE c_mo_type;
3906         IF l_debug = 1 THEN
3907                 debug_print(  'l_mo_type = ' || l_mo_type);
3908         END IF;
3909         IF (inv_install.adv_inv_installed(l_mo_line_rec.organization_id)) THEN
3910                 OPEN c_allow_backordering;
3911                 FETCH c_allow_backordering INTO l_allow_backordering;
3912                 CLOSE c_allow_backordering;
3913         END IF;
3914         IF (l_debug = 1) THEN
3915                 debug_print(  'Allow BackOrdering = ' || l_allow_backordering);
3916                 debug_print('p_transaction_temp_id' || p_transaction_temp_id);
3917         END IF;
3918         SELECT  transaction_quantity
3919         INTO    l_transaction_quantity
3920         FROM    mtl_material_transactions_temp
3921         WHERE   transaction_temp_id = p_transaction_temp_id;
3922         IF l_debug                  = 1 THEN
3923                 debug_print('l_transaction_quantity' || l_transaction_quantity);
3924         END IF;
3925         IF (l_allow_backordering                                                                      = 'Y') THEN
3926                 IF NVL(l_mo_line_rec.quantity_detailed, 0) - NVL(l_mo_line_rec.quantity_delivered, 0) > 0 THEN
3927                         IF l_debug                                                                    = 1 THEN
3928                                 debug_print(  'Before for loop.. l_mmtt_info ' );
3929                         END IF;
3930                         FOR l_mmtt_info IN c_mmtt_info
3931                         LOOP
3932                                 IF l_debug = 1 THEN
3933                                         debug_print(  'In for loop.. l_mmtt_info ' );
3934                                         debug_print(  'l_mmtt_info.transaction_temp_id.. ' || l_mmtt_info.transaction_temp_id );
3935                                         debug_print(  'p_line_id.. ' || p_line_id);
3936                                         debug_print(  'l_mmtt_info.reservation_id.. ' || l_mmtt_info.reservation_id);
3937                                         debug_print(  'l_mmtt_info.transaction_quantity.. ' || l_mmtt_info.transaction_quantity);
3938                                         debug_print(  'l_mmtt_info.primary_quantity.. ' || l_mmtt_info.primary_quantity);
3939                                 END IF;
3940                                 delete_details( x_return_status => x_return_status ,
3941 						x_msg_data => x_msg_data ,
3942 						x_msg_count => x_msg_count ,
3943 						p_transaction_temp_id => l_mmtt_info.transaction_temp_id ,
3944 						p_move_order_line_id => p_line_id ,
3945 						p_reservation_id => l_mmtt_info.reservation_id ,
3946 						p_transaction_quantity => l_mmtt_info.transaction_quantity ,
3947 						p_primary_trx_qty => l_mmtt_info.primary_quantity );
3948 
3949                                 IF l_debug                      = 1 THEN
3950                                         debug_print(  'x_return_status ' || x_return_status);
3951                                 END IF;
3952                                 IF x_return_status = fnd_api.g_ret_sts_error THEN
3953                                         IF l_debug = 1 THEN
3954                                                 debug_print('Error occurred while back ordering');
3955                                         END IF;
3956                                         ROLLBACK TO backorder;
3957                                         RAISE exc_not_deleted ;
3958                                 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
3959                                         IF l_debug    = 1 THEN
3960                                                 debug_print('Unexpected error occurred while back ordering');
3961                                         END IF;
3962                                         ROLLBACK TO backorder;
3963                                 END IF;
3964                         END LOOP;
3965                 END IF;
3966                 IF l_debug = 1 THEN
3967                         debug_print(  'Before calling backorder_source ');
3968                         debug_print('l_mo_type' || l_mo_type);
3969                 END IF;
3970                 backorder_source( x_return_status => x_return_status ,
3971 				  x_msg_data => x_msg_data ,
3972 				  x_msg_count => x_msg_count ,
3973 				  p_move_order_type => l_mo_type ,
3974 				  p_mo_line_rec => l_mo_line_rec ,
3975 				  p_qty_to_backorder => l_transaction_quantity );
3976 
3977                 IF l_debug                        = 1 THEN
3978                         debug_print(  'x_return_status ' || x_return_status);
3979                 END IF;
3980                 IF x_return_status = fnd_api.g_ret_sts_error THEN
3981                         IF l_debug = 1 THEN
3982                                 debug_print('Error occurred while back ordering');
3983                         END IF;
3984                         ROLLBACK TO backorder;
3985                         RAISE exc_not_deleted ;
3986                 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
3987                         IF l_debug    = 1 THEN
3988                                 debug_print('Unexpected Error occurred while back ordering');
3989                         END IF;
3990                         ROLLBACK TO backorder;
3991                 END IF;
3992                 IF l_debug = 1 THEN
3993                         debug_print(  'Updating Move Order Line to set Status = 5 and Qty Detailed = '
3994 				      || l_mo_line_rec.quantity_delivered);
3995                         debug_print(  'Updating Move Order Line Quantity = ' || l_mo_line_rec.quantity_delivered);
3996                 END IF;
3997                 UPDATE mtl_txn_request_lines
3998                 SET     line_status       = 5                         ,
3999                         quantity_detailed = NVL(quantity_delivered,0) ,
4000                         quantity          = NVL(quantity_delivered,0)
4001                 WHERE   line_id           = p_line_id;
4002                 IF SQL%ROWCOUNT           = 0 THEN
4003                         IF l_debug        = 1 THEN
4004                                 debug_print (  'Error updating MTRL::: ');
4005                         END IF;
4006                         ROLLBACK TO backorder;
4007                         RAISE exc_not_deleted ;
4008                 END IF;
4009         END IF;
4010         IF l_debug = 1 THEN
4011                 debug_print(  'check MO type ' || l_mo_type);
4012         END IF;
4013         IF l_mo_type       = inv_globals.g_move_order_pick_wave THEN
4014                 IF l_debug = 1 THEN
4015                         debug_print(  'before calling inv_transfer_order_pvt.clean_reservations ' || l_mo_line_rec.txn_source_line_id);
4016                 END IF;
4017                 inv_transfer_order_pvt.clean_reservations( p_source_line_id => l_mo_line_rec.txn_source_line_id ,
4018 							   x_return_status => x_return_status ,
4019 							   x_msg_count => x_msg_count ,
4020 							   x_msg_data => x_msg_data );
4021 
4022                 IF l_debug                                                  = 1 THEN
4023                         debug_print(  'x_return_status ' || x_return_status);
4024                 END IF;
4025                 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4026                         IF l_debug  = 1 THEN
4027                                 debug_print(  'Error occurred while cleaning reservation ');
4028                         END IF;
4029                         ROLLBACK TO backorder;
4030                         RAISE exc_not_deleted ;
4031                 END IF;
4032         END IF;
4033 EXCEPTION
4034 WHEN exc_not_deleted THEN
4035         IF l_debug =1 THEN
4036                 debug_print('In the exception for could not delete a record. Returning staus as E');
4037         END IF;
4038         x_return_status := 'E';
4039 WHEN OTHERS THEN
4040         x_return_status := fnd_api.g_ret_sts_unexp_error;
4041         ROLLBACK TO backorder;
4042 END backorder;
4043 
4044 -------------------------------------------------------------------------------------------------------------------
4045 /*PROCEDURE DELETE_OUTBOUND_TASKS()
4046 This is the proceudre called from the DELETE_TASKS API when the task is an Outbound task.
4047 Deletes Sales Orders, Internal Orders and WIP Pick tasks.
4048 */
4049 -------------------------------------------------------------------------------------------------------------------
4050 PROCEDURE DELETE_OUTBOUND_TASKS (p_task_rec IN task_record_type,
4051 				 x_task_rec OUT NOCOPY task_record_type,
4052 				 x_return_status OUT NOCOPY VARCHAR2) IS
4053 
4054         l_transaction_number    NUMBER ;
4055         l_other_mmtt_count      NUMBER;
4056         l_progress              VARCHAR2(30) := '100';
4057         l_update_parent         BOOLEAN      := FALSE ;  -- No need to call update_parent_mmtt
4058         x_msg_count             NUMBER;
4059         x_msg_data              VARCHAR2(50);
4060         l_g_ret_sts_error       CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_error;
4061         l_g_ret_sts_unexp_error CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_unexp_error;
4062         l_g_ret_sts_success     CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_success;
4063         l_reservation_id        NUMBER;
4064         l_pri_rsv_qty           NUMBER;
4065         l_rsv_qty               NUMBER;
4066         l_pri_rsv_uom           VARCHAR2(3);
4067         l_rsv_uom               VARCHAR2(3);
4068         l_old_upd_resv_rec inv_reservation_global.mtl_reservation_rec_type;
4069         l_new_upd_resv_rec inv_reservation_global.mtl_reservation_rec_type;
4070         l_upd_dummy_sn inv_reservation_global.serial_number_tbl_type;
4071         l_task_table WMS_TASK_MGMT_PUB.task_tab_type ;
4072         l_task_rec WMS_TASK_MGMT_PUB.task_output_rectype;
4073         l_transaction_record mtl_material_transactions_temp%rowtype ; --MMTT rec
4074         l_move_order_rec mtl_txn_request_lines%rowtype ;              --MTRL rec
4075         l_mo_line_rec inv_move_order_pub.trolin_rec_type;
4076         l_mo_type       NUMBER;
4077         l_wdt_count     NUMBER;
4078         l_debug         NUMBER;
4079         exc_not_deleted EXCEPTION;
4080         CURSOR c_mmtt_info
4081         IS
4082                 SELECT  mmtt.transaction_temp_id ,
4083                         mmtt.parent_line_id    --For checking bulk task
4084                         ,
4085                         mmtt.inventory_item_id    ,
4086                         mmtt.move_order_line_id   ,
4087                         mmtt.transaction_uom      ,
4088                         mmtt.primary_quantity     ,
4089                         mmtt.transaction_quantity ,
4090                         mmtt.wms_task_type
4091                 FROM    mtl_material_transactions_temp mmtt
4092                 WHERE   mmtt.transaction_temp_id = l_transaction_number
4093                     AND NOT EXISTS
4094                         (SELECT 1
4095                         FROM    mtl_material_transactions_temp t1
4096                         WHERE   t1.parent_line_id = mmtt.transaction_temp_id
4097                         )
4098         UNION ALL
4099         SELECT  mmtt.transaction_temp_id ,
4100                 mmtt.parent_line_id            --For checking bulk task
4101                 ,
4102                 mmtt.inventory_item_id    ,
4103                 mmtt.move_order_line_id   ,
4104                 mmtt.transaction_uom      ,
4105                 mmtt.primary_quantity     ,
4106                 mmtt.transaction_quantity ,
4107                 mmtt.wms_task_type
4108         FROM    mtl_material_transactions_temp mmtt
4109         WHERE   mmtt.parent_line_id  = l_transaction_number
4110             AND mmtt.parent_line_id <> mmtt.transaction_temp_id;
4111 -- This union by will end up getting all PARENTS too *****
4112 CURSOR c_mo_line_info
4113 IS
4114         SELECT  mtrl.uom_code                   ,
4115                 mtrl.transaction_source_type_id ,
4116                 mtrl.transaction_type_id
4117         FROM    mtl_txn_request_lines mtrl
4118         WHERE   mtrl.line_id = l_transaction_record.move_order_line_id;
4119 CURSOR c_get_other_mmtt
4120 IS
4121         SELECT  COUNT(*)
4122         FROM    mtl_material_transactions_temp mmtt
4123         WHERE   mmtt.move_order_line_id   = l_transaction_record.move_order_line_id
4124             AND mmtt.transaction_temp_id <> l_transaction_record.transaction_temp_id
4125             AND NOT EXISTS
4126                 (SELECT 1
4127                 FROM    mtl_material_transactions_temp t1
4128                 WHERE   t1.parent_line_id = mmtt.transaction_temp_id
4129                 );
4130 CURSOR c_mo_type
4131 IS
4132         SELECT  mtrh.move_order_type
4133         FROM    mtl_txn_request_headers mtrh,
4134                 mtl_txn_request_lines mtrl
4135         WHERE   mtrl.line_id   = l_transaction_record.move_order_line_id
4136             AND mtrh.header_id = mtrl.header_id;
4137 BEGIN
4138         x_return_status := fnd_api.g_ret_sts_success;
4139         l_progress      := '110';
4140         l_debug         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
4141         IF (l_debug      = 1) THEN
4142                 debug_print('IN DELETE_OUTBOUND_TASKS');
4143                 debug_print (  'l_progress: ' || l_progress );
4144         END IF;
4145         SAVEPOINT delso;
4146         l_transaction_number := p_task_rec.transaction_number;
4147         IF l_debug            = 1 THEN
4148                 debug_print (  'l_transaction_number ' || l_transaction_number );
4149         END IF;
4150         OPEN c_mmtt_info;
4151         LOOP
4152                 FETCH   c_mmtt_info
4153                 INTO    l_transaction_record.transaction_temp_id  ,
4154                         l_transaction_record.parent_line_id       ,
4155                         l_transaction_record.inventory_item_id    ,
4156                         l_transaction_record.move_order_line_id   ,
4157                         l_transaction_record.transaction_uom      ,
4158                         l_transaction_record.primary_quantity     ,
4159                         l_transaction_record.transaction_quantity ,
4160                         l_transaction_record.wms_task_type;
4161                 EXIT
4162         WHEN c_mmtt_info%NOTFOUND;
4163                 l_progress := '120';
4164                 IF (l_debug = 1) THEN
4165                         debug_print (  'delete_so: l_progress: ' || l_progress );
4166                         debug_print (  'delete_so: l_transaction_record.transaction_temp_id ' || l_transaction_record.transaction_temp_id );
4167                         debug_print (  'delete_so: l_transaction_record.parent_line_id ' || l_transaction_record.parent_line_id );
4168                         debug_print (  'delete_so: l_transaction_record.inventory_item_id ' || l_transaction_record.inventory_item_id );
4169                         debug_print (  'delete_so: l_transaction_record.move_order_line_id ' || l_transaction_record.move_order_line_id );
4170                         debug_print (  'delete_so: l_transaction_record.transaction_uom ' || l_transaction_record.transaction_uom );
4171                         debug_print (  'delete_so: l_transaction_record.primary_quantity ' || l_transaction_record.primary_quantity );
4172                         debug_print (  'delete_so: l_transaction_record.transaction_quantity ' || l_transaction_record.transaction_quantity );
4173                         debug_print (  'delete_so: l_transaction_record.wms_task_type ' || l_transaction_record.wms_task_type );
4174                 END IF;
4175                 OPEN c_mo_line_info;
4176                 FETCH   c_mo_line_info
4177                 INTO    l_move_order_rec.uom_code                  ,
4178                         l_move_order_rec.transaction_source_type_id,
4179                         l_move_order_rec.transaction_type_id;
4180                 CLOSE c_mo_line_info;
4181                 l_progress := '125';
4182                 IF (l_debug = 1) THEN
4183                         debug_print (  'delete_so: l_progress: ' || l_progress );
4184                         debug_print('delete_so: l_move_order_rec.uom_code :'|| l_move_order_rec.uom_code);
4185                         debug_print('delete_so: l_move_order_rec.transaction_source_type_id :'|| l_move_order_rec.transaction_source_type_id);
4186                         debug_print('delete_so: l_move_order_rec.transaction_type_id :'|| l_move_order_rec.transaction_type_id);
4187                 END IF;
4188                 l_progress := '135';
4189                 OPEN c_get_other_mmtt;
4190                 FETCH c_get_other_mmtt INTO l_other_mmtt_count;
4191                 CLOSE c_get_other_mmtt;
4192                 IF (l_debug = 1) THEN
4193                         debug_print (  'delete_so: l_progress: ' || l_progress );
4194                         debug_print(  'delete_so: Number of MMTTs other than this MMTT : ' || l_other_mmtt_count);
4195                 END IF;
4196                 IF l_other_mmtt_count > 0 THEN
4197                         IF (l_debug   = 1) THEN
4198                                 debug_print('delete_so: Other MMTT lines exist too. So cant close MO Line');
4199                         END IF;
4200                         l_progress := '140';
4201                         BEGIN
4202                                 IF (l_debug = 1) THEN
4203                                         debug_print (  'delete_so: l_progress: ' || l_progress );
4204                                         debug_print(  'delete_so: Before we update MO and delete MMTT, we need to update reservation ');
4205                                 END IF;
4206                                 SELECT  nvl(mmtt.reservation_id,-1)     ,
4207                                         mr.primary_reservation_quantity ,
4208                                         mr.reservation_quantity         ,
4209                                         mr.primary_uom_code             ,
4210                                         mr.reservation_uom_code
4211                                 INTO    l_reservation_id ,
4212                                         l_pri_rsv_qty    ,
4213                                         l_rsv_qty        ,
4214                                         l_pri_rsv_uom    ,
4215                                         l_rsv_uom
4216                                 FROM    mtl_material_transactions_temp mmtt ,
4217                                         mtl_reservations mr
4218                                 WHERE   mmtt.transaction_temp_id = l_transaction_record.transaction_temp_id
4219                                     AND mr.reservation_id        = mmtt.reservation_id ;
4220                                 IF (l_debug                      = 1) THEN
4221                                         debug_print('delete_so: l_reservation_id:'||l_reservation_id || ' ,l_pri_rsv_qty :' ||l_pri_rsv_qty||',l_rsv_qty :'||l_rsv_qty );
4222                                         debug_print('delete_so: MMTT.pri_qty:'||l_transaction_record.primary_quantity ||' ,l_pri_rsv_uom :'||l_pri_rsv_uom||',l_rsv_uom :'||l_rsv_uom );
4223                                 END IF;
4224                                 IF (l_rsv_qty                                            > l_transaction_record.primary_quantity ) THEN
4225                                         l_old_upd_resv_rec.reservation_id               := l_reservation_id ;
4226                                         l_new_upd_resv_rec.primary_reservation_quantity := l_pri_rsv_qty - l_transaction_record.primary_quantity ;
4227                                         IF (l_pri_rsv_uom                               <> l_rsv_uom ) THEN
4228                                                 l_new_upd_resv_rec.reservation_quantity := l_rsv_qty - INV_Convert.inv_um_convert ( item_id => l_transaction_record.inventory_item_id,
4229 													precision => null,
4230 													from_quantity => l_transaction_record.primary_quantity ,
4231 													from_unit => l_pri_rsv_uom,
4232 													to_unit => l_rsv_uom,
4233 													from_name => null,
4234 													to_name => null );
4235                                         ELSE
4236                                                 l_new_upd_resv_rec.reservation_quantity := l_rsv_qty - l_transaction_record.primary_quantity ;
4237                                         END IF;
4238                                         IF (l_debug = 1) THEN
4239                                                 debug_print(  'delete_so: Calling update_reservation api : ' );
4240                                         END IF;
4241                                         inv_reservation_pub.update_reservation( p_api_version_number => 1.0 ,
4242 										p_init_msg_lst => fnd_api.g_false ,
4243 										x_return_status => x_return_status ,
4244 										x_msg_count => x_msg_count ,
4245 										x_msg_data => x_msg_data ,
4246 										p_original_rsv_rec => l_old_upd_resv_rec ,
4247 										p_to_rsv_rec => l_new_upd_resv_rec ,
4248 										p_original_serial_number => l_upd_dummy_sn ,
4249 										p_to_serial_number => l_upd_dummy_sn ,
4250 										p_validation_flag => fnd_api.g_true );
4251 
4252                                         IF (l_debug                                                  = 1) THEN
4253                                                 debug_print(  'delete_so: return of update_reservation api : ' || x_return_status);
4254                                         END IF;
4255                                         IF x_return_status <> fnd_api.g_ret_sts_success THEN
4256                                                 x_task_rec := p_task_rec;
4257                                                 IF (l_debug = 1) THEN
4258                                                         debug_print(  'delete_so: Error updating reservation ' );
4259                                                 END IF;
4260                                                 ROLLBACK TO delso;
4261                                                 RAISE exc_not_deleted ;
4262                                         END IF;
4263                                 END IF;
4264                         EXCEPTION
4265                         WHEN NO_DATA_FOUND THEN
4266                                 IF (l_debug = 1) THEN
4267                                         debug_print(   'delete_so: There is no reservation for this MMTT  ' );
4268                                 END IF;
4269                         WHEN OTHERS THEN
4270                                 IF (l_debug = 1) THEN
4271                                         debug_print(  'delete_so: OTHERS EXCEPTION !!!! while Updating reservation ' );
4272                                 END IF;
4273                                 x_return_status:= fnd_api.g_ret_sts_unexp_error ;
4274                                 ROLLBACK TO delso;
4275                         END;
4276                         l_progress                         := '145';
4277                         delete_transaction( x_return_status => x_return_status ,
4278 					    x_msg_data => x_msg_data ,
4279 					    x_msg_count => x_msg_count ,
4280 					    p_transaction_temp_id => l_transaction_record.transaction_temp_id ,
4281 					    p_update_parent => l_update_parent );
4282 
4283                         IF l_debug                          = 1 THEN
4284                                 debug_print(  'x_return_status ' || x_return_status);
4285                         END IF;
4286                         IF x_return_status = fnd_api.g_ret_sts_error THEN
4287                                 IF l_debug = 1 THEN
4288                                         debug_print (  'delete_so: l_progress: ' || l_progress );
4289                                         debug_print('delete_so: Error occurred while deleting MMTT');
4290                                 END IF;
4291                                 x_task_rec := p_task_rec;
4292                                 ROLLBACK TO delso;
4293                                 RAISE exc_not_deleted ;
4294                         ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4295                                 IF l_debug    = 1 THEN
4296                                         debug_print('delete_mo: Error occurred while deleting MMTT');
4297                                 END IF;
4298                                 ROLLBACK TO delso;
4299                         END IF;
4300                         IF l_debug = 1 THEN
4301                                 debug_print (  'l_transaction_record.transaction_quantity ' || l_transaction_record.transaction_quantity);
4302                                 debug_print (  'l_transaction_record.move_order_line_id ' || l_transaction_record.move_order_line_id);
4303                         END IF;
4304                         UPDATE mtl_txn_request_lines
4305                         SET     quantity_detailed = quantity_detailed - l_transaction_record.transaction_quantity
4306                         WHERE   line_id           = l_transaction_record.move_order_line_id;
4307                         IF SQL%ROWCOUNT           = 0 THEN
4308                                 IF l_debug        = 1 THEN
4309                                         debug_print (  'delete_so: error updateing  MTRL::: ');
4310                                 END IF;
4311                                 ROLLBACK TO delso;
4312                                 RAISE exc_not_deleted ;
4313                         END IF;
4314                         -- Querying the Move Order Type of the Line.
4315                         OPEN c_mo_type;
4316                         FETCH c_mo_type INTO l_mo_type;
4317                         CLOSE c_mo_type;
4318                         IF l_debug = 1 THEN
4319                                 debug_print (  'delete_so: l_mo_type::: ' || l_mo_type);
4320                         END IF;
4321                         l_mo_line_rec                   := inv_trolin_util.query_row(l_transaction_record.move_order_line_id);
4322                         backorder_source(x_return_status => x_return_status ,
4323 					 x_msg_data => x_msg_data ,
4324 					 x_msg_count => x_msg_count ,
4325 					 p_move_order_type => l_mo_type ,
4326 					 p_mo_line_rec => l_mo_line_rec ,
4327 					 p_qty_to_backorder => l_transaction_record.primary_quantity);
4328 
4329                         IF x_return_status               = fnd_api.g_ret_sts_error THEN
4330                                 IF l_debug               = 1 THEN
4331                                         debug_print('delete_so: Error occurred while backordering WDD');
4332                                 END IF;
4333                                 x_task_rec := p_task_rec;
4334                                 ROLLBACK TO delso;
4335                                 RAISE exc_not_deleted ;
4336                         ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4337                                 IF l_debug    = 1 THEN
4338                                         debug_print('Unexpected Error occurred while backordering WDD');
4339                                 END IF;
4340                                 ROLLBACK TO delso;
4341                         END IF;
4342                 ELSE --IF l_other_mmtt_count > 0
4343                         l_progress := '150';
4344                         if (l_debug = 1) THEN
4345                                 debug_print (  'delete_so: l_progress: ' || l_progress );
4346                                 debug_print('delete_so: Just one MMTT line exists. Close MO');
4347                         END IF;
4348                         l_progress := '155';
4349                         SELECT  count(*)
4350                         INTO    l_wdt_count
4351                         FROM    wms_dispatched_tasks
4352                         WHERE   transaction_temp_id = l_transaction_number;
4353                         IF l_wdt_count              > 0 THEN
4354                                 DELETE
4355                                 FROM    wms_dispatched_tasks
4356                                 WHERE   transaction_temp_id = l_transaction_number;
4357                                 IF SQL%ROWCOUNT             = 0 THEN
4358                                         IF l_debug          = 1 THEN
4359                                                 debug_print (  'delete_so: l_progress: ' || l_progress );
4360                                                 debug_print (  'delete_so: error deleting WDT::: ');
4361                                         END IF;
4362                                         x_task_rec := p_task_rec;
4363                                         ROLLBACK TO delso;
4364                                         RAISE exc_not_deleted ;
4365                                 END IF;
4366                         END IF;
4367                         backorder( p_line_id => l_transaction_record.move_order_line_id ,p_transaction_temp_id => l_transaction_record.transaction_temp_id , x_return_status => x_return_status , x_msg_count => x_msg_count , x_msg_data => x_msg_data );
4368                         IF l_debug           = 1 THEN
4369                                 debug_print(  'x_return_status ' || x_return_status);
4370                         END IF;
4371                         IF x_return_status = fnd_api.g_ret_sts_error THEN
4372                                 IF l_debug = 1 THEN
4373                                         debug_print('delete_so: Unexpected error occurrend while calling BackOrder API');
4374                                 END IF;
4375                                 x_task_rec := p_task_rec;
4376                                 ROLLBACK TO delso;
4377                                 RAISE exc_not_deleted ;
4378                         ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4379                                 IF l_debug    = 1 THEN
4380                                         debug_print('delete_so: Unexpected error occurred  while calling BackOrder API');
4381                                 END IF;
4382                                 ROLLBACK TO delso;
4383                         END IF;
4384                 END IF;
4385         END LOOP;
4386         l_progress := '160';
4387         -- For checking Bulk task.Check if l_transaction_number passed is also
4388         --parent line id.If it's bulk task then call delete transaction.
4389         IF l_transaction_record.parent_line_id = l_transaction_number THEN
4390                 IF l_debug                     = 1 THEN
4391                         debug_print('delete_so: Now calling delete transaction for parent line');
4392                 END IF;
4393                 delete_transaction( x_return_status => x_return_status ,
4394 				    x_msg_data => x_msg_data ,
4395 				    x_msg_count => x_msg_count ,
4396 				    p_transaction_temp_id => l_transaction_record.parent_line_id ,
4397 				    p_update_parent => l_update_parent );
4398 
4399                 IF l_debug                          = 1 THEN
4400                         debug_print(  'x_return_status ' || x_return_status);
4401                 END IF;
4402                 IF x_return_status = fnd_api.g_ret_sts_error THEN
4403                         IF l_debug = 1 THEN
4404                                 debug_print('delete_so: Error occurred while deleting parent line in MMTT');
4405                         END IF;
4406                         x_task_rec := p_task_rec;
4407                         ROLLBACK TO delso;
4408                         RAISE exc_not_deleted ;
4409                 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4410                         IF l_debug    = 1 THEN
4411                                 debug_print('delete_so: Error occurred while deleting MMTT');
4412                         END IF;
4413                         ROLLBACK TO delso;
4414                 END IF;
4415         END IF; --for parent line IF
4416         CLOSE c_mmtt_info;
4417 EXCEPTION
4418 WHEN exc_not_deleted THEN
4419         IF l_debug =1 THEN
4420                 debug_print('In the exception, could not delete a record. Returning staus as E');
4421         END IF;
4422         x_task_rec.status :='E';
4423         x_task_rec.ERROR  := 'Error while deleting Outbound Task';
4424         x_return_status   := 'E';
4425 WHEN OTHERS THEN
4426         IF l_debug = 1 THEN
4427                 debug_print('delete_so: In the When Others Exception, Rolling back.');
4428         END IF;
4429         x_task_rec        := p_task_rec;
4430         x_task_rec.ERROR  := 'Unexpected Error Occurred';
4431         x_task_rec.status :='E';
4432         x_return_status   := l_g_ret_sts_unexp_error;
4433         ROLLBACK TO delso;
4434 END DELETE_OUTBOUND_TASKS;
4435 
4436 -------------------------------------------------------------------------------------------------------------------
4437 /*PROCEDURE DELETE_MO_TASKS()
4438 This is the proceudre called from the DELETE_TASKS API when the task is a Move Order.
4439 Deletes Replenishment, MO Xfer, MO Issue tasks
4440 */
4441 -------------------------------------------------------------------------------------------------------------------
4442 PROCEDURE DELETE_MO_TASKS (p_task_rec IN task_record_type,
4443 			   x_task_rec OUT NOCOPY task_record_type,
4444 			   x_return_status OUT NOCOPY VARCHAR2) IS
4445 
4446         l_transaction_number    NUMBER ;
4447         l_other_mmtt_count      NUMBER;
4448         l_progress              VARCHAR2(30) := '200';
4449         l_update_parent         BOOLEAN      := FALSE ;  -- No need to call update_parent_mmtt
4450         x_msg_count             NUMBER;
4451         x_msg_data              VARCHAR2(50);
4452         l_g_ret_sts_error       CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_error;
4453         l_g_ret_sts_unexp_error CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_unexp_error;
4454         l_g_ret_sts_success     CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_success;
4455         l_reservation_id        NUMBER;
4456         l_pri_rsv_qty           NUMBER;
4457         l_rsv_qty               NUMBER;
4458         l_pri_rsv_uom           VARCHAR2(3);
4459         l_rsv_uom               VARCHAR2(3);
4460         l_old_upd_resv_rec inv_reservation_global.mtl_reservation_rec_type;
4461         l_new_upd_resv_rec inv_reservation_global.mtl_reservation_rec_type;
4462         l_upd_dummy_sn inv_reservation_global.serial_number_tbl_type;
4463         l_task_table WMS_TASK_MGMT_PUB.task_tab_type ;
4464         l_task_rec WMS_TASK_MGMT_PUB.task_output_rectype;
4465         l_transaction_record mtl_material_transactions_temp%rowtype ; --MMTT rec
4466         l_move_order_rec mtl_txn_request_lines%rowtype ;              --MTRL rec
4467         l_debug         NUMBER;
4468         exc_not_deleted EXCEPTION;
4469         CURSOR c_mmtt_info
4470         IS
4471                 SELECT  mmtt.transaction_temp_id ,
4472                         mmtt.parent_line_id    --For checking bulk task
4473                         ,
4474                         mmtt.inventory_item_id  ,
4475                         mmtt.move_order_line_id ,
4476                         mmtt.transaction_uom    ,
4477                         mmtt.primary_quantity   ,
4478                         mmtt.wms_task_type
4479                 FROM    mtl_material_transactions_temp mmtt
4480                 WHERE   mmtt.transaction_temp_id = l_transaction_number
4481                     AND NOT EXISTS
4482                         (SELECT 1
4483                         FROM    mtl_material_transactions_temp t1
4484                         WHERE   t1.parent_line_id = mmtt.transaction_temp_id
4485                         )
4486         UNION ALL
4487         SELECT  mmtt.transaction_temp_id ,
4488                 mmtt.parent_line_id            --For checking bulk task
4489                 ,
4490                 mmtt.inventory_item_id  ,
4491                 mmtt.move_order_line_id ,
4492                 mmtt.transaction_uom    ,
4493                 mmtt.primary_quantity   ,
4494                 mmtt.wms_task_type
4495         FROM    mtl_material_transactions_temp mmtt
4496         WHERE   mmtt.parent_line_id  = l_transaction_number
4497             AND mmtt.parent_line_id <> mmtt.transaction_temp_id;
4498 -- This union by will end up getting all PARENTS too *****
4499 CURSOR c_mo_line_info
4500 IS
4501         SELECT  mtrl.uom_code                   ,
4502                 mtrl.transaction_source_type_id ,
4503                 mtrl.transaction_type_id
4504         FROM    mtl_txn_request_lines mtrl
4505         WHERE   mtrl.line_id = l_transaction_record.move_order_line_id;
4506 CURSOR c_get_other_mmtt
4507 IS
4508         SELECT  COUNT(*)
4509         FROM    mtl_material_transactions_temp mmtt
4510         WHERE   mmtt.move_order_line_id   = l_transaction_record.move_order_line_id
4511             AND mmtt.transaction_temp_id <> l_transaction_record.transaction_temp_id
4512             AND NOT EXISTS
4513                 (SELECT 1
4514                 FROM    mtl_material_transactions_temp t1
4515                 WHERE   t1.parent_line_id = mmtt.transaction_temp_id
4516                 );
4517 BEGIN
4518         x_return_status := fnd_api.g_ret_sts_success;
4519         l_progress      := '210';
4520         l_debug         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
4521         IF (l_debug      = 1) THEN
4522                 debug_print('IN DELETE_MO_TASKS');
4523                 debug_print (  'delete_mo: l_progress: ' || l_progress );
4524         END IF;
4525         SAVEPOINT delmo;
4526         l_transaction_number := p_task_rec.transaction_number;
4527         IF l_debug            = 1 THEN
4528                 debug_print (  'l_transaction_number ' || l_transaction_number );
4529         END IF;
4530         OPEN c_mmtt_info;
4531         LOOP
4532                 FETCH   c_mmtt_info
4533                 INTO    l_transaction_record.transaction_temp_id ,
4534                         l_transaction_record.parent_line_id      ,
4535                         l_transaction_record.inventory_item_id   ,
4536                         l_transaction_record.move_order_line_id  ,
4537                         l_transaction_record.transaction_uom     ,
4538                         l_transaction_record.primary_quantity    ,
4539                         l_transaction_record.wms_task_type;
4540                 EXIT
4541         WHEN c_mmtt_info%NOTFOUND;
4542                 l_progress := '220';
4543                 IF (l_debug = 1) THEN
4544                         debug_print (  'delete_mo: l_progress: ' || l_progress );
4545                         debug_print (  'delete_mo: l_transaction_record.transaction_temp_id ' || l_transaction_record.transaction_temp_id );
4546                         debug_print (  'delete_mo: l_transaction_record.parent_line_id ' || l_transaction_record.parent_line_id );
4547                         debug_print (  'delete_mo: l_transaction_record.inventory_item_id ' || l_transaction_record.inventory_item_id );
4548                         debug_print (  'delete_mo: l_transaction_record.move_order_line_id ' || l_transaction_record.move_order_line_id );
4549                         debug_print (  'delete_mo: l_transaction_record.transaction_uom ' || l_transaction_record.transaction_uom );
4550                         debug_print (  'delete_mo: l_transaction_record.primary_quantity ' || l_transaction_record.primary_quantity );
4551                         debug_print (  'delete_mo: l_transaction_record.wms_task_type ' || l_transaction_record.wms_task_type );
4552                 END IF;
4553                 OPEN c_mo_line_info;
4554                 FETCH   c_mo_line_info
4555                 INTO    l_move_order_rec.uom_code                  ,
4556                         l_move_order_rec.transaction_source_type_id,
4557                         l_move_order_rec.transaction_type_id;
4558                 CLOSE c_mo_line_info;
4559                 l_progress := '230';
4560                 IF (l_debug = 1) THEN
4561                         debug_print (  'delete_mo: l_progress: ' || l_progress );
4562                         debug_print('delete_mo: l_move_order_rec.uom_code :'|| l_move_order_rec.uom_code);
4563                         debug_print('delete_mo: l_move_order_rec.transaction_source_type_id :'|| l_move_order_rec.transaction_source_type_id);
4564                         debug_print('delete_mo: l_move_order_rec.transaction_type_id :'|| l_move_order_rec.transaction_type_id);
4565                 END IF;
4566                 l_progress := '250';
4567                 OPEN c_get_other_mmtt;
4568                 FETCH c_get_other_mmtt INTO l_other_mmtt_count;
4569                 CLOSE c_get_other_mmtt;
4570                 IF (l_debug = 1) THEN
4571                         debug_print (  'delete_mo: l_progress: ' || l_progress );
4572                         debug_print(  'delete_mo: Number of MMTTs other than this MMTT : ' || l_other_mmtt_count);
4573                 END IF;
4574                 IF l_other_mmtt_count > 0 THEN
4575                         IF (l_debug   = 1) THEN
4576                                 debug_print('delete_mo: Other MMTT lines exist too. So cant close MO Line');
4577                         END IF;
4578                         l_progress                         := '260';
4579                         delete_transaction( x_return_status => x_return_status ,
4580 					    x_msg_data => x_msg_data ,
4581 					    x_msg_count => x_msg_count ,
4582 					    p_transaction_temp_id => l_transaction_record.transaction_temp_id ,
4583 					    p_update_parent => l_update_parent );
4584 
4585                         IF l_debug                          = 1 THEN
4586                                 debug_print(  'x_return_status ' || x_return_status);
4587                         END IF;
4588                         IF x_return_status = fnd_api.g_ret_sts_error THEN
4589                                 IF l_debug = 1 THEN
4590                                         debug_print (  'delete_mo: l_progress: ' || l_progress );
4591                                         debug_print('delete_mo: Error occurred while deleting MMTT');
4592                                 END IF;
4593                                 x_task_rec := p_task_rec;
4594                                 ROLLBACK TO delmo;
4595                                 RAISE exc_not_deleted ;
4596                         ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4597                                 IF l_debug    = 1 THEN
4598                                         debug_print('delete_mo: Error occurred while deleting MMTT');
4599                                 END IF;
4600                                 ROLLBACK TO delmo;
4601                         END IF;
4602                 ELSE --IF l_other_mmtt_count > 0
4603                         l_progress := '280';
4604                         IF (l_debug = 1) THEN
4605                                 debug_print (  'delete_mo: l_progress: ' || l_progress );
4606                                 debug_print ('delete_mo: l_transaction_record.move_order_line_id' || l_transaction_record.move_order_line_id );
4607                         END IF;
4608                         UPDATE mtl_txn_request_lines
4609                         SET     quantity_detailed = nvl(quantity_delivered,0),
4610                                 line_status       = 5                        ,
4611                                 last_update_date  = SYSDATE
4612                         WHERE   line_id           = l_transaction_record.move_order_line_id;
4613                         IF SQL%ROWCOUNT           = 0 THEN
4614                                 IF l_debug        = 1 THEN
4615                                         debug_print (  'delete_mo: error updating MTRL::: ');
4616                                 END IF;
4617                                 x_task_rec := p_task_rec;
4618                                 ROLLBACK TO delmo;
4619                                 RAISE exc_not_deleted ;
4620                         END IF;
4621                         IF l_debug = 1 THEN
4622                                 debug_print (  'delete_mo: before calling delete transaction::: ');
4623                         END IF;
4624                         delete_transaction( x_return_status => x_return_status ,
4625 					    x_msg_data => x_msg_data ,
4626 					    x_msg_count => x_msg_count ,
4627 					    p_transaction_temp_id => l_transaction_record.transaction_temp_id ,
4628 					    p_update_parent => l_update_parent );
4629 
4630                         IF l_debug                          = 1 THEN
4631                                 debug_print(  'x_return_status ' || x_return_status);
4632                         END IF;
4633                         IF x_return_status = fnd_api.g_ret_sts_error THEN
4634                                 IF l_debug = 1 THEN
4635                                         debug_print('delete_mo: Error occurred while deleting MMTT');
4636                                 END IF;
4637                                 x_task_rec := p_task_rec;
4638                                 ROLLBACK TO delmo;
4639                                 RAISE exc_not_deleted ;
4640                         ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4641                                 IF l_debug    = 1 THEN
4642                                         debug_print('delete_mo: Error occurred while deleting MMTT');
4643                                 END IF;
4644                                 ROLLBACK TO delmo;
4645                         END IF;
4646                         l_progress := '290';
4647                         IF (l_debug = 1) THEN
4648                                 debug_print (  'delete_mo: l_progress: ' || l_progress );
4649                         END IF;
4650                 END IF;
4651         END LOOP;
4652         CLOSE c_mmtt_info;
4653 EXCEPTION
4654 WHEN exc_not_deleted THEN
4655         IF l_debug =1 THEN
4656                 debug_print('In the exception for could not delete a record. Returning staus as E');
4657         END IF;
4658         x_task_rec.status :='E';
4659         x_task_rec.ERROR  := 'Error deleting Move order tasks';
4660         x_return_status   := 'E';
4661 WHEN OTHERS THEN
4662         IF l_debug = 1 THEN
4663                 debug_print('delete_mo: In the When Others Exception, Rolling back.');
4664         END IF;
4665         x_task_rec        := p_task_rec;
4666         x_task_rec.ERROR  := 'Unexpected Error Occurred';
4667         x_task_rec.status :='E';
4668         x_return_status   := l_g_ret_sts_unexp_error;
4669         ROLLBACK TO delmo;
4670 END DELETE_MO_TASKS;
4671 
4672 -------------------------------------------------------------------------------------------------------------------
4673 /*PROCEDURE DELETE_INBOUND_TASKS
4674 This is the proceudre called from the DELETE_TASKS API when the task is a Putaway Task.
4675 */
4676 -------------------------------------------------------------------------------------------------------------------
4677 PROCEDURE DELETE_INBOUND_TASKS ( p_task_rec IN task_record_type,
4678 				 x_task_rec OUT NOCOPY task_record_type,
4679 				 x_return_status OUT NOCOPY VARCHAR2) IS
4680 
4681         l_other_mmtt_count   NUMBER;
4682         l_debug              NUMBER;
4683         l_progress           VARCHAR2(30);
4684         l_update_parent      BOOLEAN := FALSE ;  -- No need to call update_parent_mmtt
4685         x_msg_count          NUMBER;
4686         x_msg_data           VARCHAR2(50);
4687         l_return_status      VARCHAR2(1);
4688         l_transaction_number NUMBER ;
4689         l_transaction_record mtl_material_transactions_temp%rowtype ; --MMTT rec
4690         l_move_order_rec mtl_txn_request_lines%rowtype ;              --MTRL rec
4691         l_op_plan_rec wms_op_plan_instances%rowtype ;                 --WOPI rec
4692         exc_not_deleted         EXCEPTION;
4693         l_op_plan_status        NUMBER ;
4694         l_g_ret_sts_error       CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_error;
4695         l_g_ret_sts_unexp_error CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_unexp_error;
4696         l_g_ret_sts_success     CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_success;
4697         CURSOR c_mmtt_info
4698         IS
4699                 SELECT  mmtt.transaction_temp_id ,
4700                         mmtt.parent_line_id      ,
4701                         mmtt.organization_id     ,
4702                         mmtt.inventory_item_id   ,
4703                         mmtt.move_order_line_id  ,
4704                         mmtt.transaction_uom     ,
4705                         mmtt.primary_quantity    ,
4706                         mmtt.transaction_quantity
4707                 FROM    mtl_material_transactions_temp mmtt
4708                 WHERE   mmtt.transaction_temp_id = l_transaction_number
4709                     AND NOT EXISTS
4710                         (SELECT 1
4711                         FROM    mtl_material_transactions_temp t1
4712                         WHERE   t1.parent_line_id = mmtt.transaction_temp_id
4713                         )
4714         UNION ALL
4715         SELECT  mmtt.transaction_temp_id ,
4716                 mmtt.parent_line_id      ,
4717                 mmtt.organization_id     ,
4718                 mmtt.inventory_item_id   ,
4719                 mmtt.move_order_line_id  ,
4720                 mmtt.transaction_uom     ,
4721                 mmtt.primary_quantity    ,
4722                 mmtt.transaction_quantity
4723         FROM    mtl_material_transactions_temp mmtt
4724         WHERE   mmtt.parent_line_id  = l_transaction_number
4725             AND mmtt.parent_line_id <> mmtt.transaction_temp_id;
4726 CURSOR c_mo_line_info
4727 IS
4728         SELECT  mtrl.uom_code                   ,
4729                 mtrl.transaction_source_type_id ,
4730                 mtrl.transaction_type_id        ,
4731                 backorder_delivery_detail_id
4732         FROM    mtl_txn_request_lines mtrl
4733         WHERE   mtrl.line_id = l_transaction_record.move_order_line_id;
4734 CURSOR c_get_other_mmtt
4735 IS
4736         SELECT  COUNT(*)
4737         FROM    mtl_material_transactions_temp mmtt
4738         WHERE   mmtt.move_order_line_id   = l_transaction_record.move_order_line_id
4739             AND mmtt.transaction_temp_id <> l_transaction_record.transaction_temp_id
4740             AND NOT EXISTS
4741                 (SELECT 1
4742                 FROM    mtl_material_transactions_temp t1
4743                 WHERE   t1.parent_line_id = mmtt.transaction_temp_id
4744                 );
4745 CURSOR c_plan_instance
4746 IS
4747         SELECT  status             ,
4748                 orig_dest_sub_code ,
4749                 orig_dest_loc_id
4750         FROM    WMS_OP_PLAN_INSTANCES
4751         WHERE   source_task_id = l_transaction_record.parent_line_id;
4752 BEGIN
4753         l_debug         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
4754         x_return_status := fnd_api.g_ret_sts_success;
4755         l_progress      := '300';
4756         IF (l_debug      = 1) THEN
4757                 debug_print('IN DELETE_INBOUND_TASKS');
4758                 debug_print(  'l_progress: ' || l_progress );
4759         END IF;
4760         SAVEPOINT delinb;
4761         l_transaction_number := p_task_rec.transaction_number;
4762         IF (l_debug           = 1) THEN
4763                 debug_print(  'l_transaction_number ' || l_transaction_number );
4764         END IF;
4765         OPEN c_mmtt_info;
4766         LOOP
4767                 FETCH   c_mmtt_info
4768                 INTO    l_transaction_record.transaction_temp_id ,
4769                         l_transaction_record.parent_line_id      ,
4770                         l_transaction_record.organization_id     ,
4771                         l_transaction_record.inventory_item_id   ,
4772                         l_transaction_record.move_order_line_id  ,
4773                         l_transaction_record.transaction_uom     ,
4774                         l_transaction_record.primary_quantity    ,
4775                         l_transaction_record.transaction_quantity;
4776                 EXIT
4777         WHEN c_mmtt_info%NOTFOUND;
4778                 l_progress := '310';
4779                 IF (l_debug = 1) THEN
4780                         debug_print (  'delete_inbound_tasks: l_progress: ' || l_progress );
4781                         debug_print (  'delete_inbound_tasks: l_transaction_record.transaction_temp_id ' || l_transaction_record.transaction_temp_id );
4782                         debug_print (  'delete_inbound_tasks: l_transaction_record.parent_line_id ' || l_transaction_record.parent_line_id );
4783                         debug_print (  'delete_inbound_tasks: l_transaction_record.inventory_item_id ' || l_transaction_record.inventory_item_id );
4784                         debug_print (  'delete_inbound_tasks: l_transaction_record.move_order_line_id ' || l_transaction_record.move_order_line_id );
4785                         debug_print (  'delete_inbound_tasks: l_transaction_record.transaction_uom ' || l_transaction_record.transaction_uom );
4786                         debug_print (  'delete_inbound_tasks: l_transaction_record.primary_quantity ' || l_transaction_record.primary_quantity );
4787                         debug_print (  'delete_inbound_tasks: l_transaction_record.transaction_quantity ' || l_transaction_record.transaction_quantity );
4788                 END IF;
4789                 --Checking for the status of the Task(as per the operation plan, if Pending or In Progress)
4790                 l_progress := '320';
4791                 OPEN c_plan_instance;
4792                 FETCH   c_plan_instance
4793                 INTO    l_op_plan_rec.status            ,
4794                         l_op_plan_rec.orig_dest_sub_code,
4795                         l_op_plan_rec.orig_dest_loc_id;
4796                 CLOSE c_plan_instance;
4797                 IF l_op_plan_rec.status IS NULL THEN
4798                         IF l_debug =1 THEN
4799                                 debug_print('No Plan Instance record exists');
4800                         END IF;
4801                         x_task_rec := p_task_rec;
4802                         ROLLBACK to delinb ;
4803                         RAISE exc_not_deleted ;
4804                 END IF;
4805                 l_progress             := '330';
4806                 IF l_op_plan_rec.status = 1 THEN
4807                         IF l_debug      =1 THEN
4808                                 debug_print (  'delete_inbound_tasks: l_progress: ' || l_progress );
4809                         END IF;
4810                         OPEN c_mo_line_info;
4811                         FETCH   c_mo_line_info
4812                         INTO    l_move_order_rec.uom_code                  ,
4813                                 l_move_order_rec.transaction_source_type_id,
4814                                 l_move_order_rec.transaction_type_id       ,
4815                                 l_move_order_rec.backorder_delivery_detail_id;
4816                         CLOSE c_mo_line_info;
4817                         l_progress := '340';
4818                         IF (l_debug = 1) THEN
4819                                 debug_print (  'delete_inbound_tasks: l_progress: ' || l_progress );
4820                                 debug_print('delete_inbound_tasks: l_move_order_rec.uom_code :'|| l_move_order_rec.uom_code);
4821                                 debug_print('delete_inbound_tasks: l_move_order_rec.transaction_source_type_id :'|| l_move_order_rec.transaction_source_type_id);
4822                                 debug_print('delete_inbound_tasks: l_move_order_rec.transaction_type_id :'|| l_move_order_rec.transaction_type_id);
4823                                 debug_print('delete_inbound_tasks: l_move_order_rec.backorder_delivery_detail_id :'|| l_move_order_rec.backorder_delivery_detail_id);
4824                         END IF;
4825                         IF l_move_order_rec.backorder_delivery_detail_id IS NULL THEN
4826                                 l_progress := '350';
4827                                 --delete operation plan tables (wopi and wooi)
4828                                 DELETE
4829                                 FROM    wms_op_plan_instances
4830                                 WHERE   source_task_id = l_transaction_record.parent_line_id;
4831                                 IF SQL%ROWCOUNT        =0 THEN
4832                                         IF l_debug     =1 THEN
4833                                                 debug_print('Count not delete the Plan Instance of this task');
4834                                         END IF;
4835                                         x_task_rec := p_task_rec;
4836                                         ROLLBACK to delinb ;
4837                                         RAISE exc_not_deleted ;
4838                                 END IF;
4839                                 DELETE
4840                                 FROM    wms_op_operation_instances
4841                                 WHERE   source_task_id = l_transaction_record.transaction_temp_id;
4842                                 IF SQL%ROWCOUNT        =0 THEN
4843                                         IF l_debug     =1 THEN
4844                                                 debug_print('Count not update the operation instance of this task');
4845                                         END IF;
4846                                         x_task_rec := p_task_rec;
4847                                         ROLLBACK to delinb ;
4848                                         RAISE exc_not_deleted ;
4849                                 END IF;
4850                                 l_progress := '360';
4851                                 --call delete_transaction (deletes mmtt, mtlt, msnt and wdt)
4852                                 delete_transaction( x_return_status => l_return_status ,
4853 						    x_msg_data => x_msg_data ,
4854 						    x_msg_count => x_msg_count ,
4855 						    p_transaction_temp_id => l_transaction_record.transaction_temp_id ,p_update_parent => l_update_parent );
4856                                 IF l_debug                          = 1 THEN
4857                                         debug_print(  'x_return_status ' || x_return_status);
4858                                 END IF;
4859                                 IF x_return_status = fnd_api.g_ret_sts_error THEN
4860                                         IF l_debug = 1 THEN
4861                                                 debug_print('delete_inbound_tasks: Error while deleting MMTT/MTLT/MSNT/WDT');
4862                                         END IF;
4863                                         x_task_rec := p_task_rec;
4864                                         ROLLBACK TO delinb;
4865                                         RAISE exc_not_deleted ;
4866                                 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4867                                         IF l_debug    = 1 THEN
4868                                                 debug_print('delete_inbound_tasks: Error occurred while deleting MMTT');
4869                                         END IF;
4870                                         ROLLBACK TO delinb;
4871                                 END IF;
4872                                 l_progress := '370';
4873                                 --delete the parent mmtt
4874                                 DELETE
4875                                 FROM    MTL_MATERIAL_TRANSACTIONS_TEMP
4876                                 WHERE   transaction_temp_id = l_transaction_record.parent_line_id ;
4877                                 IF SQL%ROWCOUNT             =0 THEN
4878                                         IF l_debug          =1 THEN
4879                                                 debug_print('Count not delete the parent mmtt');
4880                                         END IF;
4881                                         x_task_rec := p_task_rec;
4882                                         ROLLBACK to delinb ;
4883                                         RAISE exc_not_deleted ;
4884                                 END IF;
4885                                 --call update locator capacity
4886                                 inv_loc_wms_utils.revert_loc_suggested_cap_nauto ( x_return_status => l_return_status ,
4887 										   x_msg_count => x_msg_count ,
4888 										   x_msg_data => x_msg_data ,
4889 										   p_organization_id => l_transaction_record.organization_id ,
4890 										   p_inventory_location_id => l_op_plan_rec.orig_dest_loc_id ,
4891 										   p_inventory_item_id => l_transaction_record.inventory_item_id ,
4892 										   p_primary_uom_flag => 'Y' ,
4893 										   p_transaction_uom_code => NULL ,
4894 										   p_quantity => l_transaction_record.primary_quantity );
4895                                 IF l_debug                                                         = 1 THEN
4896                                         debug_print(  'Return status from revert_loc_suggested_capacity ' || x_return_status);
4897                                 END IF;
4898                                 IF l_return_status <> fnd_api.g_ret_sts_success THEN
4899                                         IF l_debug  = 1 THEN
4900                                                 debug_print('delete_inbound_tasks: Error while reverting locator capacity');
4901                                         END IF;
4902                                         x_task_rec := p_task_rec;
4903                                         ROLLBACK TO delinb;
4904                                         RAISE exc_not_deleted ;
4905                                 END IF;
4906                                 l_progress := '380';
4907                                 OPEN c_get_other_mmtt;
4908                                 FETCH c_get_other_mmtt INTO l_other_mmtt_count;
4909                                 CLOSE c_get_other_mmtt;
4910                                 IF (l_debug = 1) THEN
4911                                         debug_print(  'delete_inbound_tasks: Number of MMTTs other than this MMTT : ' || l_other_mmtt_count);
4912                                 END IF;
4913                                 IF l_other_mmtt_count > 0 THEN
4914                                         UPDATE mtl_txn_request_lines
4915                                                 SET quantity_detailed = quantity_detailed - l_transaction_record.primary_quantity
4916                                         WHERE   line_id               = l_transaction_record.move_order_line_id;
4917                                 ELSE --IF l_other_mmtt_count > 0
4918                                         UPDATE mtl_txn_request_lines
4919                                                 SET quantity_detailed = null
4920                                         WHERE   line_id               = l_transaction_record.move_order_line_id;
4921                                 END IF;
4922                                 IF SQL%ROWCOUNT    =0 THEN
4923                                         IF l_debug =1 THEN
4924                                                 debug_print('Could not update the move order line.');
4925                                         END IF;
4926                                         x_task_rec := p_task_rec;
4927                                         ROLLBACK to delinb ;
4928                                         RAISE exc_not_deleted ;
4929                                 END IF;
4930                         ELSE
4931                                 x_task_rec      := p_task_rec;
4932                                 x_task_rec.ERROR:= 'This is a crossdock task, not deleting';
4933                                 x_return_status := 'E';
4934 				--anjana
4935 			        IF l_debug =1 THEN
4936 					debug_print('This is a crossdock task, not deleting');
4937 			        END IF;
4938                         END IF ;
4939                 ELSE
4940                         x_task_rec      := p_task_rec;
4941                         x_task_rec.ERROR:= 'Invalid status of Operation Plan';
4942                         x_return_status := 'E';
4943 			--anjana
4944 		        IF l_debug =1 THEN
4945 				debug_print('Invalid status of Operation Plan');
4946 		        END IF;
4947                 END IF;
4948         END LOOP;
4949 EXCEPTION
4950 WHEN exc_not_deleted THEN
4951         IF l_debug =1 THEN
4952                 debug_print('In the exception for could not delete a record. Returning staus as E');
4953         END IF;
4954         x_task_rec.status :='E';
4955         x_task_rec.ERROR  := 'Error deleting Inbound Tasks';
4956         x_return_status   := 'E';
4957 WHEN OTHERS THEN
4958         IF l_debug = 1 THEN
4959                 debug_print('delete_inbound_tasks:In the When Others Exception, Rolling back.' );
4960         END IF;
4961         x_task_rec        := p_task_rec;
4962         x_task_rec.ERROR  := 'Unexpected Error Occurred';
4963         x_task_rec.status :='E';
4964         x_return_status   := l_g_ret_sts_unexp_error;
4965         ROLLBACK TO delinb;
4966 END DELETE_INBOUND_TASKS;
4967 
4968 -------------------------------------------------------------------------------------------------------------------
4969 /*PROCEDURE DELETE_CC_TASKS
4970 This is the proceudre called from the DELETE_TASKS API when the task is a Cycle Count Entry.
4971 This update the entry to a Rejected Status and deletes the corresponding task record if it exists.
4972 */
4973 -------------------------------------------------------------------------------------------------------------------
4974 PROCEDURE DELETE_CC_TASKS ( p_task_rec IN task_record_type,
4975 			    x_task_rec OUT NOCOPY task_record_type,
4976 			    x_return_status OUT NOCOPY VARCHAR2) IS
4977 
4978         l_cc_entry_id           NUMBER ;
4979         l_cyc_header_id         NUMBER;
4980         l_cyc_count_name        mtl_cycle_count_headers.cycle_count_header_name%TYPE ;
4981         l_update_cyc            NUMBER;
4982         l_cyc_task              NUMBER;
4983         l_debug                 NUMBER;
4984         exc_not_deleted         EXCEPTION;
4985         l_g_ret_sts_error       CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_error;
4986         l_g_ret_sts_unexp_error CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_unexp_error;
4987         l_g_ret_sts_success     CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_success;
4988 BEGIN
4989 	x_return_status := fnd_api.g_ret_sts_success;
4990         l_debug       := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
4991         l_cc_entry_id := p_task_rec.transaction_number ;
4992         SAVEPOINT delcyc;
4993         SELECT  cycle_count_header_id
4994         INTO    l_cyc_header_id
4995         FROM    mtl_cycle_count_entries
4996         WHERE   cycle_count_entry_id = l_cc_entry_id ;
4997         UPDATE mtl_cycle_count_entries
4998                 SET entry_status_code = 4
4999         WHERE   cycle_count_entry_id  = l_cc_entry_id ;
5000         IF l_debug                    =1 THEN
5001                 debug_print('delete_cc_tasks: In Delete Cycle Count Tasks');
5002                 debug_print('delete_cc_tasks: Value of cycle count header:'||l_cyc_header_id);
5003                 debug_print('delete_cc_tasks: Value of cycle count entry:'||l_cc_entry_id);
5004         END IF;
5005         IF SQL%ROWCOUNT    =0 THEN
5006                 IF l_debug =1 THEN
5007                         debug_print('delete_cc_tasks: Could not update the cycle count entry.');
5008                 END IF;
5009                 x_task_rec := p_task_rec;
5010                 ROLLBACK to delcyc ;
5011                 RAISE exc_not_deleted ;
5012         END IF;
5013         SELECT  count(task_id)
5014         INTO    l_cyc_task
5015         FROM    wms_dispatched_tasks
5016         WHERE   transaction_temp_id = l_cc_entry_id
5017             AND task_type           = 3;
5018         IF l_cyc_task              <> 0 THEN
5019                 DELETE
5020                 FROM    wms_dispatched_tasks
5021                 WHERE   transaction_temp_id = l_cc_entry_id
5022                     AND task_type           = 3;
5023                 IF SQL%ROWCOUNT             =0 THEN
5024                         IF l_debug          =1 THEN
5025                                 debug_print('delete_cc_tasks: Could not delete the cycle count task.');
5026                         END IF;
5027                         x_task_rec := p_task_rec;
5028                         ROLLBACK to delcyc ;
5029                         RAISE exc_not_deleted;
5030                 END IF; --Rowcount for wdt delete
5031         END IF;         --Exists cycle count tasks in wdt
5032 EXCEPTION
5033 WHEN exc_not_deleted THEN
5034         IF l_debug =1 THEN
5035                 debug_print('delete_cc_tasks: In the exception for could not delete a record. Returning staus as E');
5036         END IF;
5037         x_task_rec.status :='E';
5038         x_task_rec.ERROR  := 'Could not delete the cycle count task.';
5039         x_return_status   := 'E';
5040 WHEN OTHERS THEN
5041         IF l_debug = 1 THEN
5042                 debug_print('delete_cc_tasks: In the When Others Exception, Rolling back.' );
5043         END IF;
5044         x_task_rec        := p_task_rec;
5045         x_task_rec.status :='E';
5046         x_task_rec.ERROR  := 'Unexpected Error Occurred';
5047         x_return_status   := l_g_ret_sts_unexp_error;
5048         ROLLBACK TO delcyc;
5049 END DELETE_CC_TASKS;
5050 
5051 -------------------------------------------------------------------------------------------------------------------
5052 --DELETE TASK
5053 /*This Public API takes care of deleting a single task or a table of tasks as is passed to the API.
5054   The types of tasks that this API handles include Inbound, Outbound, Warehouse and Manufacturing Tasks.
5055 
5056 PROCEDURE delete_tasks ( p_transaction_number IN NUMBER DEFAULT NULL ,
5057 			 p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE ,
5058 			 p_wms_task IN WMS_TASK_MGMT_PUB.task_tab_type ,
5059 			 x_undeleted_tasks OUT NOCOPY WMS_TASK_MGMT_PUB.task_tab_type ,
5060 			 x_return_status OUT NOCOPY VARCHAR2 ,
5061 			 x_msg_count OUT NOCOPY NUMBER ,
5062 			 x_msg_data OUT NOCOPY VARCHAR2 )
5063 
5064 Parameter		Description
5065 
5066 p_transaction_number	This corrsponds to the task_id that user is trying to delete.
5067 P_wms_task		This correspinds to the set of tasks that user is trying to delete.
5068 P_Commit		This parameter decides whether to commit the changes or not.
5069 X_undeleted_tasks	This parameter contains the set of undeleted tasks.
5070 X_return_status		This parameter gives the return status of delete_task API.
5071 			'S' = Success, 'U' = Unexpected Error, 'E' = Error.
5072 X_msg_count		This gives the count of messages logged during the task deletion process.
5073 X_msg_data		This gives the descrption of the messages that got logged during the task deletion process.
5074 -------------------------------------------------------------------------------------------------------------------*/
5075 
5076 PROCEDURE delete_tasks ( p_transaction_number IN NUMBER DEFAULT NULL ,
5077 			 p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE ,
5078 			 p_wms_task IN WMS_TASK_MGMT_PUB.task_tab_type ,
5079 			 x_undeleted_tasks OUT NOCOPY WMS_TASK_MGMT_PUB.task_tab_type ,
5080 			 x_return_status OUT NOCOPY VARCHAR2 ,
5081 			 x_msg_count OUT NOCOPY NUMBER ,
5082 			 x_msg_data OUT NOCOPY VARCHAR2 ) IS
5083 
5084         l_task_table WMS_TASK_MGMT_PUB.task_tab_type ;
5085         l_task_rec task_record_type ;
5086         x_task_rec task_record_type ;
5087         l_transaction_number NUMBER;
5088         l_transaction_record mtl_material_transactions_temp%rowtype ;
5089         /*Local variable for the validate_task API*/
5090         l_ret_task_table WMS_TASK_MGMT_PUB.task_tab_type ;
5091         l_val_ret_status        VARCHAR2(30);
5092         l_task_type             NUMBER ;
5093         l_task_exists           NUMBER                :=0 ;
5094         l_g_ret_sts_error       CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_error;
5095         l_g_ret_sts_unexp_error CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_unexp_error;
5096         l_g_ret_sts_success     CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_success;
5097         exec_unexp              EXCEPTION;
5098         l_lock_cyc_rec          NUMBER;
5099         l_debug                 NUMBER;
5100         undel_task              NUMBER;
5101 	l_msg			VARCHAR2(2000);--anjana
5102 BEGIN
5103         x_return_status     := fnd_api.g_ret_sts_success;
5104 	--anjana
5105 	x_msg_count := 0;
5106         l_debug             := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
5107         l_val_ret_status    :='S' ;
5108         l_transaction_number:= p_transaction_number ;
5109         l_task_table        := p_wms_task;
5110         IF l_debug           = 1 THEN
5111                 debug_print('IN DELETE_TASKS' );
5112         END IF;
5113         IF l_debug = 1 THEN
5114                 debug_print('Values passed to delete_tasks p_transaction_number:'|| p_transaction_number );
5115         END IF ;
5116         WMS_TASK_MGMT_PUB.validate_tasks( p_init_msg_list =>'Y' ,
5117 					  p_transaction_number => l_transaction_number ,
5118 					  p_task_table => l_task_table ,
5119 					  x_wms_task => l_ret_task_table ,
5120 					  x_return_status => l_val_ret_status );
5121         SAVEPOINT deltask ;
5122         IF l_val_ret_status ='S' THEN
5123                 undel_task :=1;
5124                 FOR i      IN 1..l_ret_task_table.count
5125                 LOOP
5126                         IF (nvl(l_ret_task_table(i).result,'@@@') <> 'E') THEN
5127                                 BEGIN
5128                                         BEGIN
5129 						l_task_exists:=0;
5130                                                 --Intitalizin the record
5131                                                 l_task_rec.transaction_number:= l_ret_task_table(i).transaction_number ;
5132                                                 SELECT  1,
5133                                                         wms_task_type
5134                                                 INTO    l_task_exists,
5135                                                         l_task_type
5136                                                 FROM    mtl_material_transactions_temp
5137                                                 WHERE   transaction_temp_id = l_ret_task_table(i).transaction_number FOR UPDATE NOWAIT;
5138                                         EXCEPTION
5139                                         WHEN NO_DATA_FOUND THEN
5140                                                 null;
5141                                         END;
5142                                         IF l_debug = 1 THEN
5143                                                 debug_print('l_task_exists'|| l_task_exists );
5144                                                 debug_print('l_task_type:'|| l_task_type );
5145                                         END IF;
5146                                         IF (l_task_exists = 0 ) THEN
5147                                                 SELECT  count(cycle_count_entry_id)
5148                                                 INTO    l_task_exists
5149                                                 FROM    mtl_cycle_count_entries
5150                                                 WHERE   cycle_count_entry_id = l_ret_task_table(i).transaction_number ;
5151                                                 SELECT  1
5152                                                 INTO    l_lock_cyc_rec
5153                                                 FROM    mtl_cycle_count_entries
5154                                                 WHERE   cycle_count_entry_id = l_ret_task_table(i).transaction_number FOR UPDATE NOWAIT;
5155                                                 l_task_type                 := 3;
5156                                                 IF l_task_exists             = 1 THEN
5157                                                         IF l_debug           = 1 THEN
5158                                                                 debug_print('Cycle Count Task');
5159                                                         END IF ;
5160                                                         DELETE_CC_TASKS(p_task_rec => l_task_rec, x_task_rec => x_task_rec, x_return_status => x_return_status);
5161                                                 END IF;
5162                                         END IF;
5163                                         IF l_task_type     = 1 THEN --SO, WIP
5164                                                 IF l_debug = 1 THEN
5165                                                         debug_print('SO/WIP');
5166                                                 END IF ;
5167                                                 DELETE_OUTBOUND_TASKS(p_task_rec => l_task_rec, x_task_rec => x_task_rec, x_return_status => x_return_status);
5168                                         ELSIF l_task_type                        = 2 THEN --Inbound
5169                                                 IF l_debug                       = 1 THEN
5170                                                         debug_print('Inbound Task');
5171                                                 END IF ;
5172                                                 DELETE_INBOUND_TASKS(p_task_rec => l_task_rec, x_task_rec => x_task_rec, x_return_status => x_return_status);
5173                                         ELSIF l_task_type                      IN (4, 5, 6) THEN --Replenishment, MO Xfer, MO Issue)
5174                                                 IF l_debug                      = 1 THEN
5175                                                         debug_print('MO Tasks');
5176                                                 END IF ;
5177                                                 DELETE_MO_TASKS(p_task_rec => l_task_rec, x_task_rec => x_task_rec, x_return_status => x_return_status);
5178                                         END IF;
5179                                 EXCEPTION
5180                                 WHEN OTHERS THEN
5181                                         x_return_status := l_g_ret_sts_unexp_error;
5182                                         IF l_debug       = 1 THEN
5183                                                 debug_print('In the When Others Exception in the Loop, Rolling back.' );
5184                                         END IF;
5185                                         ROLLBACK TO deltask;
5186                                 END;
5187                                 IF x_return_status = 'E' THEN
5188                                         IF l_debug = 1 THEN
5189                                                 debug_print('The called program returned error' );
5190                                         END IF;
5191 					--anjana
5192                                         FND_MESSAGE.SET_NAME('WMS', 'WMS_TASK_DELETE_ERROR');
5193 					l_msg := fnd_message.get;
5194 					x_msg_count := x_msg_count + 1;
5195 					x_msg_data := x_msg_data || l_msg;
5196 
5197                                         x_undeleted_tasks(undel_task).transaction_number:= x_task_rec.transaction_number;
5198                                         x_undeleted_tasks(undel_task).RESULT            := x_task_rec.status;
5199                                         x_undeleted_tasks(undel_task).error             := l_msg;
5200                                         undel_task                                      :=undel_task+1;
5201 --                                      FND_MSG_PUB.ADD;
5202 --                                      fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
5203                                 END IF;
5204                                 IF x_return_status ='U' THEN
5205                                         IF l_debug = 1 THEN
5206                                                 debug_print('The called program returned unexpected error status' );
5207                                         END IF;
5208                                         RAISE exec_unexp;
5209                                 END IF;
5210                         ELSE
5211                                 IF l_debug = 1 THEN
5212                                         debug_print('Validate_task returned error for this record' );
5213                                 END IF;
5214                                 FND_MESSAGE.SET_NAME('WMS', 'WMS_INVALID_TASK');
5215 				--anjana
5216 				l_msg := fnd_message.get;
5217 				x_msg_count := x_msg_count + 1;
5218 				x_msg_data := x_msg_data || l_msg;
5219 --                              FND_MSG_PUB.ADD;
5220 --                              fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
5221 
5222 				x_undeleted_tasks(undel_task).transaction_number:= l_ret_task_table(i).transaction_number ;  --6888354 Bug
5223                                 x_undeleted_tasks(undel_task).RESULT   := l_ret_task_table(i).RESULT;
5224                                 x_undeleted_tasks(undel_task).error    := l_msg;
5225                                 undel_task                             :=undel_task+1;
5226                         END IF ;
5227                 END LOOP; --Loop for task table
5228         ELSE
5229                 IF l_debug = 1 THEN
5230                         debug_print('Invalid status returned from Validate_Task' );
5231                 END IF;
5232                 RAISE exec_unexp;
5233         END IF; --End of Validation Status 'S'.
5234         IF p_commit = FND_API.G_TRUE THEN
5235                 COMMIT;
5236         END IF ;
5237 EXCEPTION
5238 WHEN exec_unexp THEN
5239         IF l_debug = 1 THEN
5240                 debug_print('In the Unexpected Error of Delete_Tasks, Rolling back.' );
5241         END IF;
5242         x_return_status := l_g_ret_sts_unexp_error;
5243         FND_MESSAGE.SET_NAME('WMS', 'WMS_UNEXPECTED_ERROR');
5244         FND_MSG_PUB.ADD;
5245         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
5246         ROLLBACK TO deltask;
5247 WHEN OTHERS THEN
5248         IF l_debug = 1 THEN
5249                 debug_print('In the When Others Exception of Delete_Tasks, Rolling back.' );
5250         END IF;
5251         x_return_status := l_g_ret_sts_unexp_error;
5252         FND_MESSAGE.SET_NAME('WMS', 'WMS_UNEXPECTED_ERROR');
5253         FND_MSG_PUB.ADD;
5254         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
5255         ROLLBACK TO deltask;
5256 END DELETE_TASKS;
5257 
5258 -------------------------------------------------------------------------------------------------------------------
5259 --QUERY_TASK
5260 /*
5261 This public API is used to query task based on the query_name or the transaction_number
5262 provided by the user.
5263 
5264 PROCEDURE query_task (
5265       p_transaction_number    IN                NUMBER DEFAULT NULL
5266     , p_query_name            IN                WMS_SAVED_QUERIES.QUERY_NAME%TYPE
5267     , x_task_tab              OUT NOCOPY   	WMS_TASKS_PUB.TASK_TABLE
5268     , x_return_status         OUT NOCOPY   	VARCHAR2
5269     , x_msg_count             OUT NOCOPY  	NUMBER
5270     , x_msg_data              OUT NOCOPY  	VARCHAR2 );
5271 
5272 
5273 Parameter		Description
5274 
5275 p_transaction_number	This corrsponds to the task_id that user is trying to update
5276 P_query_name		This correspinds to name of any saved query from the WMS  control board.
5277 			This is used for querying multiple tasks
5278 P_Commit		This parameter decides whether to commit the changes or not.
5279 X_task_tab		PL/SQL table which contains the task/tasks queried by the user.
5280 X_return_status		This parameter gives the return status of query_task API.
5281 			'S' = Success, 'U' = Unexpected Error, 'E' = Error.
5282 X_msg_count		This gives the count of messages logged during the query task process.
5283 X_msg_data		This gives the descrption of the messages that got logged during the query task process.
5284 */
5285 -------------------------------------------------------------------------------------------------------------------
5286   PROCEDURE query_task( p_transaction_number IN          NUMBER    DEFAULT NULL
5287                        ,p_query_name         IN          VARCHAR2
5288                        ,x_task_tab           OUT NOCOPY  task_tab_type
5289                        ,x_return_status      OUT NOCOPY  VARCHAR2
5290                        ,x_msg_count          OUT NOCOPY  NUMBER
5291                        ,x_msg_data           OUT NOCOPY  VARCHAR2
5292                       )
5293   IS
5294 
5295   l_mmtt_rec                                 mtl_material_transactions_temp%ROWTYPE;
5296   l_mcce_rec                                 mtl_cycle_count_entries%ROWTYPE;
5297   l_query_tab                                query_tab_type;
5298 
5299 
5300   l_organization_id                          NUMBER := NULL;
5301   l_record_count                             NUMBER := 0;
5302 
5303   l_order_type                               VARCHAR2(10):= NULL;
5304   l_err_msg                                  VARCHAR2(2000);
5305 
5306   l_include_sales_orders                     BOOLEAN := FALSE;
5307   l_include_internal_orders                  BOOLEAN := FALSE;
5308   l_execute_qry                              BOOLEAN := TRUE;
5309 
5310   l_invalid_org                              EXCEPTION;
5311   l_qry_fail                                 EXCEPTION;
5312 
5313   l_debug                                    NUMBER         := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5314   l_api_name                                 VARCHAR2(1000) := 'QUERY_TASK';
5315 
5316   v_cycle_count_name                         varchar2(30) := NULL;
5317 
5318   c_cd_exist  number;
5319 
5320   CURSOR c_cd_task (p_transaction_number IN NUMBER) IS
5321   SELECT 1  FROM mtl_material_transactions_temp mmtt,mtl_txn_request_lines mtrl
5322   WHERE mtrl.backorder_delivery_detail_id IS NOT NULL
5323   AND mtrl.line_id = mmtt.move_order_line_id
5324   AND transaction_temp_id = p_transaction_number;
5325 --added for completed tasks under bug 6854145
5326 --start changes 6854145
5327   l_mmt_rec             mtl_material_transactions%ROWTYPE;
5328   l_wdth_rec            wms_dispatched_tasks_history%ROWTYPE;
5329   CURSOR c_cd_task1 (p_transaction_number IN NUMBER) IS
5330   SELECT 1  FROM wms_dispatched_tasks_history wdth,mtl_txn_request_lines mtrl
5331   WHERE mtrl.backorder_delivery_detail_id IS NOT NULL
5332   AND mtrl.line_id = wdth.move_order_line_id
5333   AND transaction_id = p_transaction_number;
5334   --end changes 6854145
5335   BEGIN
5336 
5337   IF(p_transaction_number IS NOT NULL) THEN
5338     BEGIN
5339       SELECT *
5340       INTO   l_mmtt_rec
5341       FROM   mtl_material_transactions_temp
5342       WHERE  transaction_temp_id = p_transaction_number;
5343 
5344       IF(l_debug = 1) THEN
5345         l_err_msg := 'Calling API wms_waveplan_tasks_pvt.query_tasks for task: '||p_transaction_number;
5346         inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
5347       END IF;
5348 
5349       --Munish
5350       OPEN c_cd_task (p_transaction_number);
5351       FETCH c_cd_task into c_cd_exist;
5352       CLOSE c_cd_task;
5353 
5354       If (c_cd_exist = 1)  THEN
5355       --CALLL wms_waveplan_tasks_pvt.query_tasks API WITH
5356       --p_crossdock_include=true and p_outbound_include=false and p_inbound_include=false
5357 	      wms_waveplan_tasks_pvt.query_tasks(
5358 	       p_add                          => FALSE
5359 	      ,p_organization_id              => l_mmtt_rec.organization_id
5360 	      ,p_subinventory_code            => l_mmtt_rec.subinventory_code
5361 	      ,p_locator_id                   => l_mmtt_rec.locator_id
5362 	      ,p_to_subinventory_code         => l_mmtt_rec.transfer_subinventory
5363 	      ,p_to_locator_id                => l_mmtt_rec.transfer_to_location
5364 	      ,p_inventory_item_id            => l_mmtt_rec.inventory_item_id
5365 	      ,p_from_task_priority           => l_mmtt_rec.task_priority
5366 	      ,p_to_task_priority             => l_mmtt_rec.task_priority
5367 	      ,p_from_creation_date           => l_mmtt_rec.creation_date
5368 	      ,p_to_creation_date             => l_mmtt_rec.creation_date
5369 	      ,p_is_unreleased                => TRUE
5370 	      ,p_is_pending                   => TRUE
5371 	      ,p_is_queued                    => TRUE
5372 	      ,p_is_dispatched                => TRUE
5373 	      ,p_is_active                    => TRUE
5374 	      ,p_is_loaded                    => TRUE
5375 	      ,p_is_completed                 => TRUE
5376 	      ,p_include_inbound              => FALSE
5377 	      ,p_include_outbound             => FALSE
5378 	      ,p_include_crossdock            => TRUE
5379 	      ,p_include_manufacturing        => TRUE
5380 	      ,p_include_warehousing          => TRUE
5381 	      ,p_from_shipment_number         => l_mmtt_rec.shipment_number
5382 	      ,p_to_shipment_number           => l_mmtt_rec.shipment_number
5383 	      ,p_from_pick_slip_number        => l_mmtt_rec.pick_slip_number
5384 	      ,p_to_pick_slip_number          => l_mmtt_rec.pick_slip_number
5385 	      ,p_delivery_id                  => l_mmtt_rec.trx_source_delivery_id
5386 	      ,p_manufacturing_type           => 1
5387 	      ,p_include_staging_move         => TRUE
5388 	      ,x_return_status                => x_return_status
5389 	      ,x_msg_data                     => x_msg_data
5390 	      ,x_msg_count                    => x_msg_count
5391 	      ,x_record_count                 => l_record_count
5392 	      ,p_is_pending_plan              => FALSE
5393 	      ,p_is_inprogress_plan           => FALSE
5394 	      ,p_is_completed_plan            => FALSE
5395 	      ,p_is_cancelled_plan            => FALSE
5396 	      ,p_is_aborted_plan              => FALSE
5397 		  ,p_is_api_call                  => TRUE --Bug 13594691
5398 	      );
5399     ELSE
5400     --CALLL wms_waveplan_tasks_pvt.query_tasks API WITH p_crossdock_include=false and
5401     --p_outbound_include=true and p_inbound_include=true
5402     --MKGUPTA2      6868286 Start
5403          IF   l_mmtt_rec.parent_line_id IS NOT NULL THEN
5404               l_mmtt_rec.pick_slip_number:=NULL;
5405          ELSE
5406               l_mmtt_rec.subinventory_code:=NULL;
5407               l_mmtt_rec.locator_id:=NULL;
5408          END IF;
5409 	 --  6868286 End
5410               wms_waveplan_tasks_pvt.query_tasks(
5411 	       p_add                          => FALSE
5412 	      ,p_organization_id              => l_mmtt_rec.organization_id
5413 	      ,p_subinventory_code            => l_mmtt_rec.subinventory_code
5414 	      ,p_locator_id                   => l_mmtt_rec.locator_id
5415 	      ,p_to_subinventory_code         => l_mmtt_rec.transfer_subinventory
5416 	      ,p_to_locator_id                => l_mmtt_rec.transfer_to_location
5417 	      ,p_inventory_item_id            => l_mmtt_rec.inventory_item_id
5418 	      ,p_from_task_priority           => l_mmtt_rec.task_priority
5419 	      ,p_to_task_priority             => l_mmtt_rec.task_priority
5420 	      ,p_from_creation_date           => Trunc(l_mmtt_rec.creation_date)  --  6868286
5421 	      ,p_to_creation_date             => Trunc(l_mmtt_rec.creation_date)  --  6868286
5422 	      ,p_is_unreleased                => TRUE
5423 	      ,p_is_pending                   => TRUE
5424 	      ,p_is_queued                    => TRUE
5425 	      ,p_is_dispatched                => TRUE
5426 	      ,p_is_active                    => TRUE
5427 	      ,p_is_loaded                    => TRUE
5428 	      ,p_is_completed                 => FALSE
5429 	      ,p_include_inbound              => TRUE
5430 	      ,p_include_outbound             => TRUE
5431 	      ,p_include_crossdock            => FALSE
5432 	      ,p_include_manufacturing        => TRUE
5433 	      ,p_include_warehousing          => TRUE
5434 	      ,p_from_shipment_number         => l_mmtt_rec.shipment_number
5435 	      ,p_to_shipment_number           => l_mmtt_rec.shipment_number
5436 	      ,p_from_pick_slip_number        => l_mmtt_rec.pick_slip_number
5437 	      ,p_to_pick_slip_number          => l_mmtt_rec.pick_slip_number
5438 	      ,p_delivery_id                  => l_mmtt_rec.trx_source_delivery_id
5439 	      ,p_manufacturing_type           => 1
5440 	      ,p_include_staging_move         => TRUE
5441 	      ,x_return_status                => x_return_status
5442 	      ,x_msg_data                     => x_msg_data
5443 	      ,x_msg_count                    => x_msg_count
5444 	      ,x_record_count                 => l_record_count
5445 	      ,p_is_pending_plan              =>TRUE
5446 	      ,p_is_inprogress_plan           =>TRUE
5447 	      ,p_is_completed_plan            =>TRUE
5448 	      ,p_is_cancelled_plan            =>TRUE
5449 	      ,p_is_aborted_plan              =>TRUE
5450 		  ,p_is_api_call                  => TRUE --Bug 13594691
5451 	      );
5452       END IF;
5453 
5454       IF(l_debug = 1) THEN
5455         l_err_msg := 'Status returned by API wms_waveplan_tasks_pvt.query_tasks: '||x_return_status;
5456         inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
5457       END IF;
5458 
5459       IF (x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5460 /*      SELECT * BULK COLLECT
5461         INTO   x_task_tab
5462         FROM   wms_waveplan_tasks_temp
5463         WHERE  transaction_temp_id = p_transaction_number;*/
5464 
5465 	--Replacing the above by selecting columns from the table.
5466 	SELECT
5467 	 TASK_ID,
5468 	 TRANSACTION_TEMP_ID,
5469 	 PARENT_LINE_ID,
5470 	 INVENTORY_ITEM_ID,
5471 	 ITEM,
5472 	 ITEM_DESCRIPTION,
5473 	 UNIT_WEIGHT,
5474 	 WEIGHT_UOM_CODE,
5475 	 DISPLAY_WEIGHT,
5476 	 UNIT_VOLUME,
5477 	 VOLUME_UOM_CODE,
5478 	 DISPLAY_VOLUME,
5479 	 TIME_ESTIMATE,
5480 	 ORGANIZATION_ID,
5481 	 ORGANIZATION_CODE,
5482 	 REVISION,
5483 	 SUBINVENTORY,
5484 	 LOCATOR_ID,
5485 	 LOCATOR,
5486 	 TRANSACTION_TYPE_ID,
5487 	 TRANSACTION_ACTION_ID,
5488 	 TRANSACTION_SOURCE_TYPE_ID,
5489 	 TRANSACTION_SOURCE_TYPE,
5490 	 TRANSACTION_SOURCE_ID,
5491 	 TRANSACTION_SOURCE_LINE_ID,
5492 	 TO_ORGANIZATION_ID,
5493 	 TO_ORGANIZATION_CODE,
5494 	 TO_SUBINVENTORY,
5495 	 TO_LOCATOR_ID,
5496 	 TO_LOCATOR,
5497 	 TRANSACTION_UOM,
5498 	 TRANSACTION_QUANTITY,
5499 	 USER_TASK_TYPE_ID,
5500 	 USER_TASK_TYPE,
5501 	 PERSON_ID,
5502 	 PERSON_ID_ORIGINAL,
5503 	 PERSON,
5504 	 EFFECTIVE_START_DATE,
5505 	 EFFECTIVE_END_DATE,
5506 	 PERSON_RESOURCE_ID,
5507 	 PERSON_RESOURCE_CODE,
5508 	 MACHINE_RESOURCE_ID,
5509 	 MACHINE_RESOURCE_CODE,
5510 	 EQUIPMENT_INSTANCE,
5511 	 STATUS_ID,
5512 	 STATUS_ID_ORIGINAL,
5513 	 STATUS,
5514 	 CREATION_TIME,
5515 	 DISPATCHED_TIME,
5516 	 LOADED_TIME,
5517 	 DROP_OFF_TIME,
5518 	 MMTT_LAST_UPDATE_DATE,
5519 	 MMTT_LAST_UPDATED_BY,
5520 	 WDT_LAST_UPDATE_DATE,
5521 	 WDT_LAST_UPDATED_BY,
5522 	 PRIORITY,
5523 	 PRIORITY_ORIGINAL,
5524 	 TASK_TYPE_ID,
5525 	 TASK_TYPE,
5526 	 MOVE_ORDER_LINE_ID,
5527 	 PICK_SLIP_NUMBER,
5528 	 CARTONIZATION_ID,
5529 	 ALLOCATED_LPN_ID,
5530 	 CONTAINER_ITEM_ID,
5531 	 CONTENT_LPN_ID,
5532 	 TO_LPN_ID,
5533 	 CONTAINER_ITEM ,
5534 	 CARTONIZATION_LPN,
5535 	 ALLOCATED_LPN ,
5536 	 CONTENT_LPN,
5537 	 TO_LPN,
5538 	 REFERENCE ,
5539 	 REFERENCE_ID,
5540 	 CUSTOMER_ID,
5541 	 CUSTOMER ,
5542 	 SHIP_TO_LOCATION_ID ,
5543 	 SHIP_TO_STATE ,
5544 	 SHIP_TO_COUNTRY,
5545 	 SHIP_TO_POSTAL_CODE,
5546 	 DELIVERY_ID ,
5547 	 DELIVERY ,
5548 	 SHIP_METHOD ,
5549 	 CARRIER_ID ,
5550 	 CARRIER ,
5551 	 SHIPMENT_DATE ,
5552 	 SHIPMENT_PRIORITY,
5553 	 WIP_ENTITY_TYPE,
5554 	 WIP_ENTITY_ID,
5555 	 ASSEMBLY_ID,
5556 	 ASSEMBLY ,
5557 	 LINE_ID,
5558 	 LINE,
5559 	 DEPARTMENT_ID,
5560 	 DEPARTMENT,
5561 	 SOURCE_HEADER,
5562 	 LINE_NUMBER,
5563 	 OPERATION_PLAN_ID,
5564 	 OPERATION_PLAN ,
5565 	 RESULT ,
5566 	 ERROR ,
5567 	 IS_MODIFIED ,
5568 	 EXPANSION_CODE ,
5569 	 FROM_LPN ,
5570 	 FROM_LPN_ID,
5571 	 NUM_OF_CHILD_TASKS,
5572 	 OPERATION_SEQUENCE,
5573 	 OP_PLAN_INSTANCE_ID,
5574 	 PLANS_TASKS ,
5575 	 TRANSACTION_SET_ID,
5576 	 PICKED_LPN_ID,
5577 	 PICKED_LPN,
5578 	 LOADED_LPN,
5579 	 LOADED_LPN_ID,
5580 	 DROP_LPN ,
5581 	 SECONDARY_TRANSACTION_QUANTITY,
5582 	 SECONDARY_TRANSACTION_UOM ,
5583 	 PRIMARY_PRODUCT,
5584 	 LOAD_SEQ_NUMBER
5585 	BULK COLLECT
5586 	INTO   x_task_tab
5587 	FROM   wms_waveplan_tasks_temp
5588 	WHERE  transaction_temp_id = p_transaction_number;
5589 
5590    END IF;
5591 
5592     EXCEPTION
5593       WHEN NO_DATA_FOUND THEN
5594         BEGIN
5595           SELECT *
5596           INTO   l_mcce_rec
5597           FROM   mtl_cycle_count_entries
5598           WHERE  cycle_count_entry_id = p_transaction_number;
5599 
5600           BEGIN
5601           SELECT cycle_count_header_name
5602             INTO v_cycle_count_name
5603             FROM mtl_cycle_count_headers
5604            WHERE cycle_count_header_id = l_mcce_rec.cycle_count_header_id;
5605           EXCEPTION
5606             WHEN NO_DATA_FOUND THEN
5607               v_cycle_count_name   := NULL;
5608           END;
5609 
5610           IF(l_debug = 1) THEN
5611             l_err_msg := 'Calling API wms_waveplan_tasks_pvt.query_tasks for cycle count task: '||p_transaction_number;
5612             inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
5613             inv_trx_util_pub.trace('Cycle Count Name '||v_cycle_count_name);
5614           END IF;
5615 
5616           wms_waveplan_tasks_pvt.query_tasks(
5617            p_add                          => FALSE
5618           ,p_organization_id              => l_mcce_rec.organization_id
5619           ,p_subinventory_code            => l_mcce_rec.subinventory
5620           ,p_locator_id                   => l_mcce_rec.locator_id
5621           ,p_inventory_item_id            => l_mcce_rec.inventory_item_id
5622           ,p_from_creation_date           => l_mcce_rec.creation_date
5623           ,p_to_creation_date             => l_mcce_rec.creation_date
5624           ,p_is_unreleased                => TRUE
5625           ,p_is_pending                   => TRUE
5626           ,p_is_queued                    => TRUE
5627           ,p_is_dispatched                => TRUE
5628           ,p_is_active                    => TRUE
5629           ,p_is_loaded                    => TRUE
5630           ,p_is_completed                 => TRUE
5631           ,p_include_inbound              => FALSE
5632           ,p_include_outbound             => FALSE
5633           ,p_include_manufacturing        => FALSE
5634           ,p_include_warehousing          => TRUE
5635           ,p_manufacturing_type           => 1
5636           ,p_include_replenishment        => FALSE
5637           ,p_include_mo_transfer          => FALSE
5638           ,p_include_mo_issue             => FALSE
5639           ,p_include_lpn_putaway          => FALSE
5640           ,p_include_staging_move         => FALSE
5641           ,p_include_cycle_count          => TRUE
5642           ,p_cycle_count_name             => v_cycle_count_name
5643           ,x_return_status                => x_return_status
5644           ,x_msg_data                     => x_msg_data
5645           ,x_msg_count                    => x_msg_count
5646           ,x_record_count                 => l_record_count
5647           ,p_is_pending_plan              => FALSE
5648           ,p_is_inprogress_plan           => FALSE
5649           ,p_is_completed_plan            => FALSE
5650           ,p_is_cancelled_plan            => FALSE
5651           ,p_is_aborted_plan              => FALSE
5652 		  ,p_is_api_call                  => TRUE --Bug 13594691
5653           );
5654 
5655 
5656           IF(l_debug = 1) THEN
5657             l_err_msg := 'Status returned by API wms_waveplan_tasks_pvt.query_tasks for cycle count task: '||x_return_status;
5658             inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
5659           END IF;
5660 
5661           IF (x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5662 /*          SELECT * BULK COLLECT
5663             INTO   x_task_tab
5664             FROM   wms_waveplan_tasks_temp
5665             WHERE  transaction_temp_id = p_transaction_number;*/
5666 
5667 	    --Replacing the above by selecting columns from the table.
5668 	    SELECT
5669 		 TASK_ID,
5670 		 TRANSACTION_TEMP_ID,
5671 		 PARENT_LINE_ID,
5672 		 INVENTORY_ITEM_ID,
5673 		 ITEM,
5674 		 ITEM_DESCRIPTION,
5675 		 UNIT_WEIGHT,
5676 		 WEIGHT_UOM_CODE,
5677 		 DISPLAY_WEIGHT,
5678 		 UNIT_VOLUME,
5679 		 VOLUME_UOM_CODE,
5680 		 DISPLAY_VOLUME,
5681 		 TIME_ESTIMATE,
5682 		 ORGANIZATION_ID,
5683 		 ORGANIZATION_CODE,
5684 		 REVISION,
5685 		 SUBINVENTORY,
5686 		 LOCATOR_ID,
5687 		 LOCATOR,
5688 		 TRANSACTION_TYPE_ID,
5689 		 TRANSACTION_ACTION_ID,
5690 		 TRANSACTION_SOURCE_TYPE_ID,
5691 		 TRANSACTION_SOURCE_TYPE,
5692 		 TRANSACTION_SOURCE_ID,
5693 		 TRANSACTION_SOURCE_LINE_ID,
5694 		 TO_ORGANIZATION_ID,
5695 		 TO_ORGANIZATION_CODE,
5696 		 TO_SUBINVENTORY,
5697 		 TO_LOCATOR_ID,
5698 		 TO_LOCATOR,
5699 		 TRANSACTION_UOM,
5700 		 TRANSACTION_QUANTITY,
5701 		 USER_TASK_TYPE_ID,
5702 		 USER_TASK_TYPE,
5703 		 PERSON_ID,
5704 		 PERSON_ID_ORIGINAL,
5705 		 PERSON,
5706 		 EFFECTIVE_START_DATE,
5707 		 EFFECTIVE_END_DATE,
5708 		 PERSON_RESOURCE_ID,
5709 		 PERSON_RESOURCE_CODE,
5710 		 MACHINE_RESOURCE_ID,
5711 		 MACHINE_RESOURCE_CODE,
5712 		 EQUIPMENT_INSTANCE,
5713 		 STATUS_ID,
5714 		 STATUS_ID_ORIGINAL,
5715 		 STATUS,
5716 		 CREATION_TIME,
5717 		 DISPATCHED_TIME,
5718 		 LOADED_TIME,
5719 		 DROP_OFF_TIME,
5720 		 MMTT_LAST_UPDATE_DATE,
5721 		 MMTT_LAST_UPDATED_BY,
5722 		 WDT_LAST_UPDATE_DATE,
5723 		 WDT_LAST_UPDATED_BY,
5724 		 PRIORITY,
5725 		 PRIORITY_ORIGINAL,
5726 		 TASK_TYPE_ID,
5727 		 TASK_TYPE,
5728 		 MOVE_ORDER_LINE_ID,
5729 		 PICK_SLIP_NUMBER,
5730 		 CARTONIZATION_ID,
5731 		 ALLOCATED_LPN_ID,
5732 		 CONTAINER_ITEM_ID,
5733 		 CONTENT_LPN_ID,
5734 		 TO_LPN_ID,
5735 		 CONTAINER_ITEM ,
5736 		 CARTONIZATION_LPN,
5737 		 ALLOCATED_LPN ,
5738 		 CONTENT_LPN,
5739 		 TO_LPN,
5740 		 REFERENCE ,
5741 		 REFERENCE_ID,
5742 		 CUSTOMER_ID,
5743 		 CUSTOMER ,
5744 		 SHIP_TO_LOCATION_ID ,
5745 		 SHIP_TO_STATE ,
5746 		 SHIP_TO_COUNTRY,
5747 		 SHIP_TO_POSTAL_CODE,
5748 		 DELIVERY_ID ,
5749 		 DELIVERY ,
5750 		 SHIP_METHOD ,
5751 		 CARRIER_ID ,
5752 		 CARRIER ,
5753 		 SHIPMENT_DATE ,
5754 		 SHIPMENT_PRIORITY,
5755 		 WIP_ENTITY_TYPE,
5756 		 WIP_ENTITY_ID,
5757 		 ASSEMBLY_ID,
5758 		 ASSEMBLY ,
5759 		 LINE_ID,
5760 		 LINE,
5761 		 DEPARTMENT_ID,
5762 		 DEPARTMENT,
5763 		 SOURCE_HEADER,
5764 		 LINE_NUMBER,
5765 		 OPERATION_PLAN_ID,
5766 		 OPERATION_PLAN ,
5767 		 RESULT ,
5768 		 ERROR ,
5769 		 IS_MODIFIED ,
5770 		 EXPANSION_CODE ,
5771 		 FROM_LPN ,
5772 		 FROM_LPN_ID,
5773 		 NUM_OF_CHILD_TASKS,
5774 		 OPERATION_SEQUENCE,
5775 		 OP_PLAN_INSTANCE_ID,
5776 		 PLANS_TASKS ,
5777 		 TRANSACTION_SET_ID,
5778 		 PICKED_LPN_ID,
5779 		 PICKED_LPN,
5780 		 LOADED_LPN,
5781 		 LOADED_LPN_ID,
5782 		 DROP_LPN ,
5783 		 SECONDARY_TRANSACTION_QUANTITY,
5784 		 SECONDARY_TRANSACTION_UOM ,
5785 		 PRIMARY_PRODUCT,
5786 		 LOAD_SEQ_NUMBER
5787 	    BULK COLLECT
5788 	    INTO   x_task_tab
5789 	    FROM   wms_waveplan_tasks_temp
5790 	    WHERE  transaction_temp_id = p_transaction_number;
5791 
5792           END IF;
5793 
5794    EXCEPTION
5795     WHEN NO_DATA_FOUND THEN
5796 	  --start changes for completed tasks
5797       BEGIN
5798       inv_trx_util_pub.trace('checking in wdth for completed inbound or crossdock tasks');
5799       SELECT *
5800       INTO   l_wdth_rec
5801       FROM   wms_dispatched_tasks_history
5802       WHERE  transaction_id = p_transaction_number;
5803 
5804       IF(l_debug = 1) THEN
5805         l_err_msg := 'Calling API wms_waveplan_tasks_pvt.query_tasks for task: '||p_transaction_number;
5806         inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
5807       END IF;
5808 
5809       --Munish  checking completed crossdock task
5810       OPEN c_cd_task1 (p_transaction_number);
5811       FETCH c_cd_task1 into c_cd_exist;
5812       CLOSE c_cd_task1;
5813 
5814       If (c_cd_exist = 1)  THEN
5815       inv_trx_util_pub.trace('calling API wms_waveplan_tasks_pvt.query_tasks for completed crossdock task');
5816       --CALLL wms_waveplan_tasks_pvt.query_tasks API WITH
5817       --p_crossdock_include=true and p_outbound_include=false and p_inbound_include=false
5818 	      wms_waveplan_tasks_pvt.query_tasks(
5819 	       p_add                          => FALSE
5820 	      ,p_organization_id              => l_wdth_rec.organization_id
5821 	      ,p_subinventory_code            => l_wdth_rec.source_subinventory_code
5822 	      ,p_locator_id                   => l_wdth_rec.source_locator_id
5823 	      ,p_to_subinventory_code         => l_wdth_rec.dest_subinventory_code
5824 	      ,p_to_locator_id                => l_wdth_rec.dest_locator_id
5825 	      ,p_inventory_item_id            => l_wdth_rec.inventory_item_id
5826 	      ,p_from_task_priority           => l_wdth_rec.priority
5827 	      ,p_to_task_priority             => l_wdth_rec.priority
5828 	      ,p_from_creation_date           => TRUNC(l_wdth_rec.creation_date)
5829 	      ,p_to_creation_date             => TRUNC(l_wdth_rec.creation_date)
5830 	      ,p_is_unreleased                => FALSE
5831 	      ,p_is_pending                   => FALSE
5832 	      ,p_is_queued                    => FALSE
5833 	      ,p_is_dispatched                => FALSE
5834 	      ,p_is_active                    => FALSE
5835 	      ,p_is_loaded                    => FALSE
5836 	      ,p_is_completed                 => TRUE
5837 	      ,p_include_inbound              => FALSE
5838 	      ,p_include_outbound             => FALSE
5839 	      ,p_include_crossdock            => TRUE
5840 	      ,p_include_manufacturing        => FALSE
5841 	      ,p_include_warehousing          => FALSE
5842 	      ,p_from_shipment_number         => NULL
5843 	      ,p_to_shipment_number           => NULL
5844 	      ,p_from_pick_slip_number        => NULL
5845 	      ,p_to_pick_slip_number          => NULL
5846 	      ,p_delivery_id                  => NULL
5847 	      ,p_manufacturing_type           => 1
5848 	      ,p_include_staging_move         => FALSE
5849 	      ,x_return_status                => x_return_status
5850 	      ,x_msg_data                     => x_msg_data
5851 	      ,x_msg_count                    => x_msg_count
5852 	      ,x_record_count                 => l_record_count
5853 	      ,p_is_pending_plan              => FALSE
5854 	      ,p_is_inprogress_plan           => FALSE
5855 	      ,p_is_completed_plan            => FALSE
5856 	      ,p_is_cancelled_plan            => FALSE
5857 	      ,p_is_aborted_plan              => FALSE
5858 		  ,p_is_api_call                  => TRUE --Bug 13594691
5859 	      );
5860     ELSE
5861     --CALLL wms_waveplan_tasks_pvt.query_tasks API WITH p_crossdock_include=false and
5862     --p_outbound_include=true and p_inbound_include=true
5863     inv_trx_util_pub.trace('calling completed inbound task');--mkgupta2
5864     IF   l_wdth_rec.is_parent ='Y' THEN
5865     inv_trx_util_pub.trace('checking if its a parent task completed inbound task');
5866 	 l_wdth_rec.source_subinventory_code:=NULL;
5867          l_wdth_rec.source_locator_id:=NULL;
5868     END IF;
5869     	       wms_waveplan_tasks_pvt.query_tasks(
5870 	       p_add                          => FALSE
5871 	      ,p_organization_id              => l_wdth_rec.organization_id
5872 	      ,p_subinventory_code            => l_wdth_rec.source_subinventory_code
5873 	      ,p_locator_id                   => l_wdth_rec.source_locator_id
5874 	      ,p_to_subinventory_code         => l_wdth_rec.dest_subinventory_code
5875 	      ,p_to_locator_id                => l_wdth_rec.dest_locator_id
5876 	      ,p_inventory_item_id            => l_wdth_rec.inventory_item_id
5877 	      ,p_from_task_priority           => NULL
5878 	      ,p_to_task_priority             => NULL
5879 	      ,p_from_creation_date           => TRUNC(l_wdth_rec.creation_date)
5880 	      ,p_to_creation_date             => TRUNC(l_wdth_rec.creation_date)
5881 	      ,p_is_unreleased                => FALSE
5882 	      ,p_is_pending                   => FALSE
5883 	      ,p_is_queued                    => FALSE
5884 	      ,p_is_dispatched                => FALSE
5885 	      ,p_is_active                    => FALSE
5886 	      ,p_is_loaded                    => FALSE
5887 	      ,p_is_completed                 => TRUE
5888 	      ,p_include_inbound              => TRUE
5889 	      ,p_include_outbound             => FALSE
5890 	      ,p_include_crossdock            => FALSE
5891 	      ,p_include_manufacturing        => FALSE
5892 	      ,p_include_warehousing          => FALSE
5893 	      ,p_from_shipment_number         => NULL
5894 	      ,p_to_shipment_number           => NULL
5895 	      ,p_from_pick_slip_number        => NULL
5896 	      ,p_to_pick_slip_number          => NULL
5897 	      ,p_delivery_id                  => NULL
5898 	      ,p_manufacturing_type           => 1
5899 	      ,p_include_staging_move         => FALSE
5900 	      ,x_return_status                => x_return_status
5901 	      ,x_msg_data                     => x_msg_data
5902 	      ,x_msg_count                    => x_msg_count
5903 	      ,x_record_count                 => l_record_count
5904 	      ,p_is_pending_plan              =>TRUE
5905 	      ,p_is_inprogress_plan           =>TRUE
5906 	      ,p_is_completed_plan            =>TRUE
5907 	      ,p_is_cancelled_plan            =>TRUE
5908 	      ,p_is_aborted_plan              =>TRUE
5909 		  ,p_is_api_call                  => TRUE --Bug 13594691
5910 	      );
5911       END IF;
5912 
5913       IF(l_debug = 1) THEN
5914         l_err_msg := 'Status returned by API wms_waveplan_tasks_pvt.query_tasks: '||x_return_status;
5915         inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
5916       END IF;
5917 
5918       IF (x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5919      	SELECT
5920 	 TASK_ID,
5921 	 TRANSACTION_TEMP_ID,
5922 	 PARENT_LINE_ID,
5923 	 INVENTORY_ITEM_ID,
5924 	 ITEM,
5925 	 ITEM_DESCRIPTION,
5926 	 UNIT_WEIGHT,
5927 	 WEIGHT_UOM_CODE,
5928 	 DISPLAY_WEIGHT,
5929 	 UNIT_VOLUME,
5930 	 VOLUME_UOM_CODE,
5931 	 DISPLAY_VOLUME,
5932 	 TIME_ESTIMATE,
5933 	 ORGANIZATION_ID,
5934 	 ORGANIZATION_CODE,
5935 	 REVISION,
5936 	 SUBINVENTORY,
5937 	 LOCATOR_ID,
5938 	 LOCATOR,
5939 	 TRANSACTION_TYPE_ID,
5940 	 TRANSACTION_ACTION_ID,
5941 	 TRANSACTION_SOURCE_TYPE_ID,
5942 	 TRANSACTION_SOURCE_TYPE,
5943 	 TRANSACTION_SOURCE_ID,
5944 	 TRANSACTION_SOURCE_LINE_ID,
5945 	 TO_ORGANIZATION_ID,
5946 	 TO_ORGANIZATION_CODE,
5947 	 TO_SUBINVENTORY,
5948 	 TO_LOCATOR_ID,
5949 	 TO_LOCATOR,
5950 	 TRANSACTION_UOM,
5951 	 TRANSACTION_QUANTITY,
5952 	 USER_TASK_TYPE_ID,
5953 	 USER_TASK_TYPE,
5954 	 PERSON_ID,
5955 	 PERSON_ID_ORIGINAL,
5956 	 PERSON,
5957 	 EFFECTIVE_START_DATE,
5958 	 EFFECTIVE_END_DATE,
5959 	 PERSON_RESOURCE_ID,
5960 	 PERSON_RESOURCE_CODE,
5961 	 MACHINE_RESOURCE_ID,
5962 	 MACHINE_RESOURCE_CODE,
5963 	 EQUIPMENT_INSTANCE,
5964 	 STATUS_ID,
5965 	 STATUS_ID_ORIGINAL,
5966 	 STATUS,
5967 	 CREATION_TIME,
5968 	 DISPATCHED_TIME,
5969 	 LOADED_TIME,
5970 	 DROP_OFF_TIME,
5971 	 MMTT_LAST_UPDATE_DATE,
5972 	 MMTT_LAST_UPDATED_BY,
5973 	 WDT_LAST_UPDATE_DATE,
5974 	 WDT_LAST_UPDATED_BY,
5975 	 PRIORITY,
5976 	 PRIORITY_ORIGINAL,
5977 	 TASK_TYPE_ID,
5978 	 TASK_TYPE,
5979 	 MOVE_ORDER_LINE_ID,
5980 	 PICK_SLIP_NUMBER,
5981 	 CARTONIZATION_ID,
5982 	 ALLOCATED_LPN_ID,
5983 	 CONTAINER_ITEM_ID,
5984 	 CONTENT_LPN_ID,
5985 	 TO_LPN_ID,
5986 	 CONTAINER_ITEM ,
5987 	 CARTONIZATION_LPN,
5988 	 ALLOCATED_LPN ,
5989 	 CONTENT_LPN,
5990 	 TO_LPN,
5991 	 REFERENCE ,
5992 	 REFERENCE_ID,
5993 	 CUSTOMER_ID,
5994 	 CUSTOMER ,
5995 	 SHIP_TO_LOCATION_ID ,
5996 	 SHIP_TO_STATE ,
5997 	 SHIP_TO_COUNTRY,
5998 	 SHIP_TO_POSTAL_CODE,
5999 	 DELIVERY_ID ,
6000 	 DELIVERY ,
6001 	 SHIP_METHOD ,
6002 	 CARRIER_ID ,
6003 	 CARRIER ,
6004 	 SHIPMENT_DATE ,
6005 	 SHIPMENT_PRIORITY,
6006 	 WIP_ENTITY_TYPE,
6007 	 WIP_ENTITY_ID,
6008 	 ASSEMBLY_ID,
6009 	 ASSEMBLY ,
6010 	 LINE_ID,
6011 	 LINE,
6012 	 DEPARTMENT_ID,
6013 	 DEPARTMENT,
6014 	 SOURCE_HEADER,
6015 	 LINE_NUMBER,
6016 	 OPERATION_PLAN_ID,
6017 	 OPERATION_PLAN ,
6018 	 RESULT ,
6019 	 ERROR ,
6020 	 IS_MODIFIED ,
6021 	 EXPANSION_CODE ,
6022 	 FROM_LPN ,
6023 	 FROM_LPN_ID,
6024 	 NUM_OF_CHILD_TASKS,
6025 	 OPERATION_SEQUENCE,
6026 	 OP_PLAN_INSTANCE_ID,
6027 	 PLANS_TASKS ,
6028 	 TRANSACTION_SET_ID,
6029 	 PICKED_LPN_ID,
6030 	 PICKED_LPN,
6031 	 LOADED_LPN,
6032 	 LOADED_LPN_ID,
6033 	 DROP_LPN ,
6034 	 SECONDARY_TRANSACTION_QUANTITY,
6035 	 SECONDARY_TRANSACTION_UOM ,
6036 	 PRIMARY_PRODUCT,
6037 	 LOAD_SEQ_NUMBER
6038 	BULK COLLECT
6039 	INTO   x_task_tab
6040 	FROM   wms_waveplan_tasks_temp
6041 	WHERE  transaction_temp_id = p_transaction_number;
6042         END IF;
6043       EXCEPTION
6044           WHEN NO_DATA_FOUND THEN
6045                 inv_trx_util_pub.trace('in the NO_DATA_FOUND exception block of inbound/crossdock completed task');
6046              BEGIN
6047                 inv_trx_util_pub.trace('checking in mmt for outbound/warehouse/manufacturing completed task');
6048                SELECT *
6049                INTO   l_mmt_rec
6050                FROM   mtl_material_transactions
6051                WHERE  transaction_id = p_transaction_number;
6052                inv_trx_util_pub.trace('task existing in mmt');
6053 
6054 	       IF(l_debug = 1) THEN
6055                l_err_msg := 'Calling API wms_waveplan_tasks_pvt.query_tasks for task: '||p_transaction_number;
6056                inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
6057                END IF;
6058 
6059 	       inv_trx_util_pub.trace('checking for bulk task');
6060               IF   l_mmt_rec.parent_transaction_id IS NOT NULL THEN
6061                    l_mmt_rec.pick_slip_number:=NULL;
6062               END IF;
6063               wms_waveplan_tasks_pvt.query_tasks(
6064 	       p_add                          => FALSE
6065 	      ,p_organization_id              => l_mmt_rec.organization_id
6066 	      ,p_subinventory_code            => l_mmt_rec.subinventory_code
6067 	      ,p_locator_id                   => l_mmt_rec.locator_id
6068 	      ,p_to_subinventory_code         => l_mmt_rec.transfer_subinventory
6069 	      ,p_to_locator_id                => l_mmt_rec.transfer_locator_id
6070 	      ,p_inventory_item_id            => l_mmt_rec.inventory_item_id
6071 	      ,p_from_task_priority           => NULL
6072 	      ,p_to_task_priority             => NULL
6073 	      ,p_from_creation_date           => TRUNC(l_mmt_rec.creation_date)
6074 	      ,p_to_creation_date             => TRUNC(l_mmt_rec.creation_date)
6075 	      ,p_is_unreleased                => FALSE
6076 	      ,p_is_pending                   => FALSE
6077 	      ,p_is_queued                    => FALSE
6078 	      ,p_is_dispatched                => FALSE
6079 	      ,p_is_active                    => FALSE
6080 	      ,p_is_loaded                    => FALSE
6081 	      ,p_is_completed                 => TRUE
6082 	      ,p_include_inbound              => FALSE
6083 	      ,p_include_outbound             => TRUE
6084 	      ,p_include_crossdock            => FALSE
6085 	      ,p_include_manufacturing        => TRUE
6086 	      ,p_include_warehousing          => TRUE
6087 	      ,p_from_shipment_number         => l_mmt_rec.shipment_number
6088 	      ,p_to_shipment_number           => l_mmt_rec.shipment_number
6089 	      ,p_from_pick_slip_number        => l_mmt_rec.pick_slip_number
6090 	      ,p_to_pick_slip_number          => l_mmt_rec.pick_slip_number
6091 	      ,p_delivery_id                  => l_mmt_rec.trx_source_delivery_id
6092 	      ,p_manufacturing_type           => 1
6093 	      ,p_include_staging_move         => TRUE
6094 	      ,x_return_status                => x_return_status
6095 	      ,x_msg_data                     => x_msg_data
6096 	      ,x_msg_count                    => x_msg_count
6097 	      ,x_record_count                 => l_record_count
6098 	      ,p_is_pending_plan              =>FALSE
6099 	      ,p_is_inprogress_plan           =>FALSE
6100 	      ,p_is_completed_plan            =>FALSE
6101 	      ,p_is_cancelled_plan            =>FALSE
6102 	      ,p_is_aborted_plan              =>FALSE
6103 		  ,p_is_api_call                  => TRUE --Bug 13594691
6104 	      );
6105 
6106             IF(l_debug = 1) THEN
6107              l_err_msg := 'Status returned by API wms_waveplan_tasks_pvt.query_tasks: '||x_return_status;
6108              inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
6109             END IF;
6110 
6111            IF (x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
6112          SELECT
6113 	 TASK_ID,
6114 	 TRANSACTION_TEMP_ID,
6115 	 PARENT_LINE_ID,
6116 	 INVENTORY_ITEM_ID,
6117 	 ITEM,
6118 	 ITEM_DESCRIPTION,
6119 	 UNIT_WEIGHT,
6120 	 WEIGHT_UOM_CODE,
6121 	 DISPLAY_WEIGHT,
6122 	 UNIT_VOLUME,
6123 	 VOLUME_UOM_CODE,
6124 	 DISPLAY_VOLUME,
6125 	 TIME_ESTIMATE,
6126 	 ORGANIZATION_ID,
6127 	 ORGANIZATION_CODE,
6128 	 REVISION,
6129 	 SUBINVENTORY,
6130 	 LOCATOR_ID,
6131 	 LOCATOR,
6132 	 TRANSACTION_TYPE_ID,
6133 	 TRANSACTION_ACTION_ID,
6134 	 TRANSACTION_SOURCE_TYPE_ID,
6135 	 TRANSACTION_SOURCE_TYPE,
6136 	 TRANSACTION_SOURCE_ID,
6137 	 TRANSACTION_SOURCE_LINE_ID,
6138 	 TO_ORGANIZATION_ID,
6139 	 TO_ORGANIZATION_CODE,
6140 	 TO_SUBINVENTORY,
6141 	 TO_LOCATOR_ID,
6142 	 TO_LOCATOR,
6143 	 TRANSACTION_UOM,
6144 	 TRANSACTION_QUANTITY,
6145 	 USER_TASK_TYPE_ID,
6146 	 USER_TASK_TYPE,
6147 	 PERSON_ID,
6148 	 PERSON_ID_ORIGINAL,
6149 	 PERSON,
6150 	 EFFECTIVE_START_DATE,
6151 	 EFFECTIVE_END_DATE,
6152 	 PERSON_RESOURCE_ID,
6153 	 PERSON_RESOURCE_CODE,
6154 	 MACHINE_RESOURCE_ID,
6155 	 MACHINE_RESOURCE_CODE,
6156 	 EQUIPMENT_INSTANCE,
6157 	 STATUS_ID,
6158 	 STATUS_ID_ORIGINAL,
6159 	 STATUS,
6160 	 CREATION_TIME,
6161 	 DISPATCHED_TIME,
6162 	 LOADED_TIME,
6163 	 DROP_OFF_TIME,
6164 	 MMTT_LAST_UPDATE_DATE,
6165 	 MMTT_LAST_UPDATED_BY,
6166 	 WDT_LAST_UPDATE_DATE,
6167 	 WDT_LAST_UPDATED_BY,
6168 	 PRIORITY,
6169 	 PRIORITY_ORIGINAL,
6170 	 TASK_TYPE_ID,
6171 	 TASK_TYPE,
6172 	 MOVE_ORDER_LINE_ID,
6173 	 PICK_SLIP_NUMBER,
6174 	 CARTONIZATION_ID,
6175 	 ALLOCATED_LPN_ID,
6176 	 CONTAINER_ITEM_ID,
6177 	 CONTENT_LPN_ID,
6178 	 TO_LPN_ID,
6179 	 CONTAINER_ITEM ,
6180 	 CARTONIZATION_LPN,
6181 	 ALLOCATED_LPN ,
6182 	 CONTENT_LPN,
6183 	 TO_LPN,
6184 	 REFERENCE ,
6185 	 REFERENCE_ID,
6186 	 CUSTOMER_ID,
6187 	 CUSTOMER ,
6188 	 SHIP_TO_LOCATION_ID ,
6189 	 SHIP_TO_STATE ,
6190 	 SHIP_TO_COUNTRY,
6191 	 SHIP_TO_POSTAL_CODE,
6192 	 DELIVERY_ID ,
6193 	 DELIVERY ,
6194 	 SHIP_METHOD ,
6195 	 CARRIER_ID ,
6196 	 CARRIER ,
6197 	 SHIPMENT_DATE ,
6198 	 SHIPMENT_PRIORITY,
6199 	 WIP_ENTITY_TYPE,
6200 	 WIP_ENTITY_ID,
6201 	 ASSEMBLY_ID,
6202 	 ASSEMBLY ,
6203 	 LINE_ID,
6204 	 LINE,
6205 	 DEPARTMENT_ID,
6206 	 DEPARTMENT,
6207 	 SOURCE_HEADER,
6208 	 LINE_NUMBER,
6209 	 OPERATION_PLAN_ID,
6210 	 OPERATION_PLAN ,
6211 	 RESULT ,
6212 	 ERROR ,
6213 	 IS_MODIFIED ,
6214 	 EXPANSION_CODE ,
6215 	 FROM_LPN ,
6216 	 FROM_LPN_ID,
6217 	 NUM_OF_CHILD_TASKS,
6218 	 OPERATION_SEQUENCE,
6219 	 OP_PLAN_INSTANCE_ID,
6220 	 PLANS_TASKS ,
6221 	 TRANSACTION_SET_ID,
6222 	 PICKED_LPN_ID,
6223 	 PICKED_LPN,
6224 	 LOADED_LPN,
6225 	 LOADED_LPN_ID,
6226 	 DROP_LPN ,
6227 	 SECONDARY_TRANSACTION_QUANTITY,
6228 	 SECONDARY_TRANSACTION_UOM ,
6229 	 PRIMARY_PRODUCT,
6230 	 LOAD_SEQ_NUMBER
6231 	BULK COLLECT
6232 	INTO   x_task_tab
6233 	FROM   wms_waveplan_tasks_temp
6234 	WHERE  transaction_temp_id = p_transaction_number;
6235 
6236          END IF;
6237         EXCEPTION
6238             WHEN NO_DATA_FOUND THEN
6239              inv_trx_util_pub.trace('in the exception block of outbond/manufacturing/warehousing complete tasks');
6240              fnd_message.set_name('WMS', 'WMS_INVALID_TASK');
6241              fnd_msg_pub.ADD;
6242              x_return_status := fnd_api.g_ret_sts_unexp_error;
6243              fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
6244              l_err_msg := 'Failed to fetch data from MMTT,MCCE,MMT or WDTH tables for transaction number '||p_transaction_number;
6245              IF(l_debug = 1) THEN
6246               inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
6247              END IF;
6248          END;
6249           --end the begin block for outbond/manufacturing/warehousing complete tasks
6250        END;
6251           --end the begin block for inbound/crossdock complete tasks
6252       END;
6253           --end the begin block for cycle count tasks
6254       WHEN OTHERS THEN
6255         x_return_status := fnd_api.g_ret_sts_unexp_error;
6256         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
6257         l_err_msg := substr(SQLERRM,1,1000);
6258         IF(l_debug = 1) THEN
6259           inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
6260         END IF;
6261     END;
6262          --end the begin block for uncompleted tasks
6263 
6264   ELSIF (p_query_name IS NOT NULL) THEN
6265   ---initialize the main table
6266   initialize_main_table();
6267 
6268   ---populate the l_query_tab table with cursor output
6269   BEGIN
6270     SELECT REPLACE(field_name,'FIND_TASKS.','') field_name,
6271            decode(field_value,'Y','T','N','F',field_value) field_value
6272            BULK COLLECT
6273     INTO   l_query_tab
6274     FROM   wms_saved_queries
6275     WHERE  query_name = p_query_name
6276     ORDER BY 1;
6277   EXCEPTION
6278     WHEN OTHERS THEN
6279       fnd_message.set_name('WMS', 'WMS_INVALID_VALUE');
6280       fnd_msg_pub.ADD;
6281       l_err_msg := substr(SQLERRM,1,1000);
6282       RAISE l_qry_fail;
6283   END;
6284 
6285   IF (l_query_tab.COUNT > 0) THEN
6286     ---pass the field_values from l_query_tab table
6287     ---to the field_values in g_main_tab table for
6288     ---matching field_names
6289     FOR i IN l_query_tab.FIRST..l_query_tab.LAST
6290       LOOP
6291         FOR j IN g_main_tab.FIRST..g_main_tab.LAST
6292           LOOP
6293             IF (g_main_tab(j).field_name = l_query_tab(i).field_name) THEN
6294               g_main_tab(j).field_value := l_query_tab(i).field_value;
6295               EXIT; -- exit the inner loop
6296             END IF;
6297           END LOOP; --- loop for j
6298       END LOOP; --- loop for i
6299   END IF; ----l_query_tab.COUNT > 0
6300 
6301 --- check the credentials of the query_name passed as input
6302 
6303 ---if 'inbound' task is queried then
6304 --Munish is adding (g_main_tab(93).field_value = FND_API.G_TRUE) to check crossdock task
6305   IF(g_main_tab(35).field_value = FND_API.G_TRUE) OR (g_main_tab(93).field_value = FND_API.G_TRUE)  THEN
6306 --  IF(g_main_tab(35).field_value = FND_API.G_TRUE) THEN
6307     ---if its planned or independent task
6308     IF ((g_main_tab(36).field_value = FND_API.G_TRUE)
6309     OR  (g_main_tab(58).field_value = FND_API.G_TRUE))
6310     THEN
6311       ---the status has to be either one of the following:
6312       ---unreleased, pending, queued, dispatched,active, loaded, completed
6313       IF((g_main_tab(1).field_value = FND_API.G_TRUE)
6314       OR (g_main_tab(5).field_value = FND_API.G_TRUE)
6315       OR (g_main_tab(12).field_value = FND_API.G_TRUE)
6316       OR (g_main_tab(39).field_value = FND_API.G_TRUE)
6317       OR (g_main_tab(51).field_value = FND_API.G_TRUE)
6318       OR (g_main_tab(59).field_value = FND_API.G_TRUE)
6319       OR (g_main_tab(90).field_value = FND_API.G_TRUE))
6320       THEN
6321         l_execute_qry := TRUE;
6322       END IF;
6323     --else if it's not planned or independent task then
6324     --it has to be either one of plan_pending, plan_in_progress, plan_completed
6325     --plan_cancelled or plan_aborted
6326     ELSIF((g_main_tab(53).field_value = FND_API.G_TRUE)
6327        OR (g_main_tab(54).field_value = FND_API.G_TRUE)
6328        OR (g_main_tab(55).field_value = FND_API.G_TRUE)
6329        OR (g_main_tab(56).field_value = FND_API.G_TRUE)
6330        OR (g_main_tab(57).field_value = FND_API.G_TRUE))
6331     THEN
6332       l_execute_qry := TRUE;
6333     ELSE
6334       l_execute_qry := FALSE;
6335       l_err_msg := 'Invalid query criteria';
6336       fnd_message.set_name('WMS', 'WMS_NO_SOURCE_ENTERED');
6337       fnd_msg_pub.ADD;
6338       RAISE l_qry_fail;
6339     END IF;
6340   END IF;
6341 
6342   --If its either outbound, manufacturing or warehousing tasks
6343   IF ((g_main_tab(50).field_value = FND_API.G_TRUE)
6344     OR(g_main_tab(42).field_value = FND_API.G_TRUE)
6345     OR(g_main_tab(92).field_value = FND_API.G_TRUE))
6346   THEN
6347       ---the status has to be either one of the following:
6348       ---unreleased, pending, queued, dispatched,active, loaded, completed
6349       IF((g_main_tab(1).field_value = FND_API.G_TRUE)
6350       OR (g_main_tab(5).field_value = FND_API.G_TRUE)
6351       OR (g_main_tab(12).field_value = FND_API.G_TRUE)
6352       OR (g_main_tab(39).field_value = FND_API.G_TRUE)
6353       OR (g_main_tab(51).field_value = FND_API.G_TRUE)
6354       OR (g_main_tab(59).field_value = FND_API.G_TRUE)
6355       OR (g_main_tab(90).field_value = FND_API.G_TRUE))
6356       THEN
6357         l_execute_qry := TRUE;
6358       END IF;
6359   ---else if its neither one of the following tasks then generate error message
6360   ---outbound, inbound, manufacturing, warehousing
6361   ELSIF ((g_main_tab(50).field_value = FND_API.G_FALSE)
6362       AND(g_main_tab(42).field_value = FND_API.G_FALSE)
6363       AND(g_main_tab(92).field_value = FND_API.G_FALSE)
6364       AND(g_main_tab(35).field_value = FND_API.G_FALSE)
6365       AND (g_main_tab(93).field_value = FND_API.G_FALSE))
6366   THEN
6367     l_execute_qry := FALSE;
6368     l_err_msg := 'Invalid query criteria';
6369     fnd_message.set_name('WMS', 'WMS_NO_SOURCE_ENTERED');
6370     fnd_msg_pub.ADD;
6371     RAISE l_qry_fail;
6372   END IF;
6373 
6374 --- Derive organization_id
6375   BEGIN
6376     SELECT DISTINCT organization_id
6377     INTO   l_organization_id
6378     FROM   wms_saved_queries
6379     WHERE  query_name = p_query_name;
6380   EXCEPTION
6381     WHEN OTHERS THEN
6382     fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ORG');
6383     fnd_msg_pub.ADD;
6384     l_err_msg := concat('Invalid Org: ',substr(SQLERRM,1,1000));
6385     RAISE l_invalid_org;
6386     NULL;
6387   END;
6388 
6389 ---logic to initialize variables
6390 ---v_include_sales_orders, v_include_internal_orders
6391   l_order_type := g_main_tab(49).field_value;
6392 
6393   IF (upper(l_order_type) = 'B') THEN
6394     l_include_sales_orders    := TRUE;
6395     l_include_internal_orders := TRUE;
6396   ELSIF (upper(l_order_type) = 'S') THEN
6397     l_include_sales_orders    := TRUE;
6398   ELSIF (upper(l_order_type) = 'I') THEN
6399     l_include_internal_orders    := TRUE;
6400   END IF;
6401 ---end logic to initialize variables
6402 ---v_include_sales_orders , v_include_internal_orders
6403 
6404 ---call the main API to find the queried tasks
6405   IF (l_execute_qry) THEN
6406 
6407     IF(l_debug = 1) THEN
6408       l_err_msg := 'Calling API wms_waveplan_tasks_pvt.query_tasks for Query: '||p_query_name;
6409       inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
6410     END IF;
6411 
6412       wms_waveplan_tasks_pvt.query_tasks (
6413       FALSE,                          ---p_add                   BOOLEAN DEFAULT FALSE,
6414       l_organization_id,              ---p_organization_id       NUMBER DEFAULT NULL,
6415       g_main_tab(67).field_value,     ---p_subinventory_code     VARCHAR2 DEFAULT NULL,
6416       g_main_tab(40).field_value,     ---p_locator_id            NUMBER DEFAULT NULL,
6417       g_main_tab(85).field_value,     ---p_to_subinventory_code  VARCHAR2 DEFAULT NULL,
6418       g_main_tab(72).field_value,     ---p_to_locator_id         NUMBER DEFAULT NULL,
6419       g_main_tab(37).field_value,     ---p_inventory_item_id     NUMBER DEFAULT NULL,
6420       g_main_tab(4).field_value,      ---p_category_set_id       NUMBER DEFAULT NULL,
6421       g_main_tab(38).field_value,     ---p_item_category_id      NUMBER DEFAULT NULL,
6422       g_main_tab(13).field_value,     ---p_person_id             NUMBER DEFAULT NULL,
6423       g_main_tab(52).field_value,     ---p_person_resource_id    NUMBER DEFAULT NULL,
6424       g_main_tab(15).field_value,     ---p_equipment_type_id     NUMBER DEFAULT NULL,
6425       NULL,                           ---p_machine_resource_id   NUMBER DEFAULT NULL,
6426       g_main_tab(14).field_value,     ---p_machine_instance      VARCHAR2 DEFAULT NULL,
6427       g_main_tab(91).field_value,     ---p_user_task_type_id     NUMBER DEFAULT NULL,
6428       g_main_tab(33).field_value,     ---p_from_task_quantity    NUMBER DEFAULT NULL,
6429       g_main_tab(87).field_value,     ---p_to_task_quantity      NUMBER DEFAULT NULL,
6430       g_main_tab(32).field_value,     ---p_from_task_priority    NUMBER DEFAULT NULL,
6431       g_main_tab(86).field_value,     ---p_to_task_priority      NUMBER DEFAULT NULL,
6432       g_main_tab(16).field_value,     ---p_from_creation_date    DATE DEFAULT NULL,
6433       g_main_tab(68).field_value,     ---p_to_creation_date      DATE DEFAULT NULL,
6434       fnd_api.to_boolean(g_main_tab(90).field_value),     ---p_is_unreleased         BOOLEAN DEFAULT FALSE,
6435       fnd_api.to_boolean(g_main_tab(51).field_value),     ---p_is_pending            BOOLEAN DEFAULT FALSE,
6436       fnd_api.to_boolean(g_main_tab(59).field_value),     ---p_is_queued             BOOLEAN DEFAULT FALSE,
6437       fnd_api.to_boolean(g_main_tab(12).field_value),     ---p_is_dispatched         BOOLEAN DEFAULT FALSE,
6438       fnd_api.to_boolean(g_main_tab(1).field_value),      ---p_is_active             BOOLEAN DEFAULT FALSE,
6439       fnd_api.to_boolean(g_main_tab(39).field_value),     ---p_is_loaded             BOOLEAN DEFAULT FALSE,
6440       fnd_api.to_boolean(g_main_tab(5).field_value),      ---p_is_completed          BOOLEAN DEFAULT FALSE,
6441       fnd_api.to_boolean(g_main_tab(35).field_value),     ---p_include_inbound       BOOLEAN DEFAULT FALSE,
6442       fnd_api.to_boolean(g_main_tab(50).field_value),     ---p_include_outbound      BOOLEAN DEFAULT FALSE,
6443       fnd_api.to_boolean(g_main_tab(93).field_value),                      ---p_include_crossdock
6444       fnd_api.to_boolean(g_main_tab(42).field_value),     ---p_include_manufacturing BOOLEAN DEFAULT FALSE,
6445       fnd_api.to_boolean(g_main_tab(92).field_value),     ---p_include_warehousing   BOOLEAN DEFAULT FALSE,
6446       g_main_tab(21).field_value,     ---p_from_po_header_id     NUMBER DEFAULT NULL,
6447       g_main_tab(74).field_value,     ---p_to_po_header_id       NUMBER DEFAULT NULL,
6448       g_main_tab(22).field_value,     ---p_from_purchase_order   VARCHAR2 DEFAULT NULL,
6449       g_main_tab(75).field_value,     ---p_to_purchase_order     VARCHAR2 DEFAULT NULL,
6450       g_main_tab(27).field_value,     ---p_from_rma_header_id    NUMBER DEFAULT NULL,
6451       g_main_tab(80).field_value,     ---p_to_rma_header_id      NUMBER DEFAULT NULL,
6452       g_main_tab(26).field_value,     ---p_from_rma              VARCHAR2 DEFAULT NULL,
6453       g_main_tab(79).field_value,     ---p_to_rma                VARCHAR2 DEFAULT NULL,
6454       g_main_tab(25).field_value,     ---p_from_requisition_header_id  NUMBER DEFAULT NULL,
6455       g_main_tab(78).field_value,     ---p_to_requisition_header_id    NUMBER DEFAULT NULL,
6456       g_main_tab(24).field_value,     ---p_from_requisition      VARCHAR2 DEFAULT NULL,
6457       g_main_tab(77).field_value,     ---p_to_requisition        VARCHAR2 DEFAULT NULL,
6458       g_main_tab(29).field_value,     ---p_from_shipment_number  VARCHAR2 DEFAULT NULL,
6459       g_main_tab(82).field_value,     ---p_to_shipment_number    VARCHAR2 DEFAULT NULL,
6460       l_include_sales_orders,         ---p_include_sales_orders  BOOLEAN DEFAULT TRUE,
6461       l_include_internal_orders,      ---p_include_internal_orders BOOLEAN DEFAULT TRUE,
6462       g_main_tab(28).field_value,     ---p_from_sales_order_id   NUMBER DEFAULT NULL,
6463       g_main_tab(81).field_value,     ---p_to_sales_order_id     NUMBER DEFAULT NULL,
6464       g_main_tab(20).field_value,     ---p_from_pick_slip_number NUMBER DEFAULT NULL,
6465       g_main_tab(73).field_value,     ---p_to_pick_slip_number   NUMBER DEFAULT NULL,
6466       g_main_tab(7).field_value,      ---p_customer_id           NUMBER DEFAULT NULL,
6467       g_main_tab(6).field_value,      ---p_customer_category     VARCHAR2 DEFAULT NULL,
6468       g_main_tab(10).field_value,     ---p_delivery_id           NUMBER DEFAULT NULL,
6469       g_main_tab(3).field_value,      ---p_carrier_id            NUMBER DEFAULT NULL,
6470       g_main_tab(61).field_value,     ---p_ship_method           VARCHAR2 DEFAULT NULL,
6471       g_main_tab(65).field_value,     ---p_shipment_priority     VARCHAR2 DEFAULT NULL,
6472       g_main_tab(89).field_value,     ---p_trip_id               NUMBER DEFAULT NULL,
6473       g_main_tab(30).field_value,     ---p_from_shipment_date    DATE DEFAULT NULL,
6474       g_main_tab(83).field_value,     ---p_to_shipment_date      DATE DEFAULT NULL,
6475       g_main_tab(64).field_value,     ---p_ship_to_state         VARCHAR2 DEFAULT NULL,
6476       g_main_tab(62).field_value,     ---p_ship_to_country       VARCHAR2 DEFAULT NULL,
6477       g_main_tab(63).field_value,     ---p_ship_to_postal_code   VARCHAR2 DEFAULT NULL,
6478       g_main_tab(19).field_value,     ---p_from_number_of_order_lines NUMBER DEFAULT NULL,
6479       g_main_tab(71).field_value,     ---p_to_number_of_order_lines   NUMBER DEFAULT NULL,
6480       g_main_tab(43).field_value,     ---p_manufacturing_type   VARCHAR2 DEFAULT NULL,
6481       g_main_tab(17).field_value,     ---p_from_job             VARCHAR2 DEFAULT NULL,
6482       g_main_tab(69).field_value,     ---p_to_job               VARCHAR2 DEFAULT NULL,
6483       g_main_tab(2).field_value,      ---p_assembly_id          NUMBER DEFAULT NULL,
6484       g_main_tab(31).field_value,     ---p_from_start_date      DATE DEFAULT NULL,
6485       g_main_tab(84).field_value,     ---p_to_start_date        DATE DEFAULT NULL,
6486       g_main_tab(18).field_value,     ---p_from_line            VARCHAR2 DEFAULT NULL,
6487       g_main_tab(70).field_value,     ---p_to_line              VARCHAR2 DEFAULT NULL,
6488       g_main_tab(11).field_value,     ---p_department_id        NUMBER DEFAULT NULL,
6489       fnd_api.to_boolean(g_main_tab(60).field_value),     ---p_include_replenishment  BOOLEAN DEFAULT TRUE,
6490       g_main_tab(23).field_value,     ---p_from_replenishment_mo  VARCHAR2 DEFAULT NULL,
6491       g_main_tab(76).field_value,     ---p_to_replenishment_mo  VARCHAR2 DEFAULT NULL,
6492       fnd_api.to_boolean(g_main_tab(45).field_value),     ---p_include_mo_transfer  BOOLEAN DEFAULT TRUE,
6493       fnd_api.to_boolean(g_main_tab(44).field_value),     ---p_include_mo_issue     BOOLEAN DEFAULT TRUE,
6494       g_main_tab(34).field_value,                 ---p_from_transfer_issue_mo VARCHAR2 DEFAULT NULL,
6495       g_main_tab(88).field_value,                 ---p_to_transfer_issue_mo VARCHAR2 DEFAULT NULL,
6496       fnd_api.to_boolean(g_main_tab(41).field_value),     ---p_include_lpn_putaway  BOOLEAN DEFAULT TRUE,
6497       fnd_api.to_boolean(g_main_tab(66).field_value),     ---p_include_staging_move BOOLEAN DEFAULT FALSE,
6498       fnd_api.to_boolean(g_main_tab(9).field_value),      ---p_include_cycle_count  BOOLEAN DEFAULT TRUE,
6499       g_main_tab(8).field_value,                  ---p_cycle_count_name     VARCHAR2 DEFAULT NULL,
6500       l_record_count,                             ---OUT NOCOPY   NUMBER,
6501       x_return_status,                            ---OUT NOCOPY   VARCHAR2,
6502       x_msg_data,                                 ---OUT NOCOPY   VARCHAR2,
6503       x_msg_count,                                ---OUT NOCOPY   NUMBER,
6504       fnd_api.to_boolean(g_main_tab(36).field_value),     ---p_query_independent_tasks   BOOLEAN DEFAULT TRUE,
6505       fnd_api.to_boolean(g_main_tab(58).field_value),     ---p_query_planned_tasks       BOOLEAN DEFAULT TRUE,
6506       fnd_api.to_boolean(g_main_tab(57).field_value),     ---p_is_pending_plan           BOOLEAN DEFAULT FALSE,
6507       fnd_api.to_boolean(g_main_tab(56).field_value),     ---p_is_inprogress_plan        BOOLEAN DEFAULT FALSE,
6508       fnd_api.to_boolean(g_main_tab(55).field_value),     ---p_is_completed_plan         BOOLEAN DEFAULT FALSE,
6509       fnd_api.to_boolean(g_main_tab(54).field_value),     ---p_is_cancelled_plan         BOOLEAN DEFAULT FALSE,
6510       fnd_api.to_boolean(g_main_tab(53).field_value),     ---p_is_aborted_plan           BOOLEAN DEFAULT FALSE,
6511       g_main_tab(46).field_value,                 ---p_activity_id   NUMBER DEFAULT NULL,
6512       g_main_tab(48).field_value,                 ---p_plan_type_id  NUMBER DEFAULT NULL,
6513       g_main_tab(47).field_value                  ---p_op_plan_id    NUMBER DEFAULT NULL
6514    );
6515 
6516     IF(l_debug = 1) THEN
6517       l_err_msg := 'Status returned by API wms_waveplan_tasks_pvt.query_tasks: '||x_return_status;
6518       inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
6519     END IF;
6520 
6521     IF(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
6522 /*    SELECT * BULK COLLECT
6523       INTO   x_task_tab
6524       FROM   wms_waveplan_tasks_temp;*/
6525       --Replacing the above by selecting columns from the table.
6526       SELECT
6527 	 TASK_ID,
6528 	 TRANSACTION_TEMP_ID,
6529 	 PARENT_LINE_ID,
6530 	 INVENTORY_ITEM_ID,
6531 	 ITEM,
6532 	 ITEM_DESCRIPTION,
6533 	 UNIT_WEIGHT,
6534 	 WEIGHT_UOM_CODE,
6535 	 DISPLAY_WEIGHT,
6536 	 UNIT_VOLUME,
6537 	 VOLUME_UOM_CODE,
6538 	 DISPLAY_VOLUME,
6539 	 TIME_ESTIMATE,
6540 	 ORGANIZATION_ID,
6541 	 ORGANIZATION_CODE,
6542 	 REVISION,
6543 	 SUBINVENTORY,
6544 	 LOCATOR_ID,
6545 	 LOCATOR,
6546 	 TRANSACTION_TYPE_ID,
6547 	 TRANSACTION_ACTION_ID,
6548 	 TRANSACTION_SOURCE_TYPE_ID,
6549 	 TRANSACTION_SOURCE_TYPE,
6550 	 TRANSACTION_SOURCE_ID,
6551 	 TRANSACTION_SOURCE_LINE_ID,
6552 	 TO_ORGANIZATION_ID,
6553 	 TO_ORGANIZATION_CODE,
6554 	 TO_SUBINVENTORY,
6555 	 TO_LOCATOR_ID,
6556 	 TO_LOCATOR,
6557 	 TRANSACTION_UOM,
6558 	 TRANSACTION_QUANTITY,
6559 	 USER_TASK_TYPE_ID,
6560 	 USER_TASK_TYPE,
6561 	 PERSON_ID,
6562 	 PERSON_ID_ORIGINAL,
6563 	 PERSON,
6564 	 EFFECTIVE_START_DATE,
6565 	 EFFECTIVE_END_DATE,
6566 	 PERSON_RESOURCE_ID,
6567 	 PERSON_RESOURCE_CODE,
6568 	 MACHINE_RESOURCE_ID,
6569 	 MACHINE_RESOURCE_CODE,
6570 	 EQUIPMENT_INSTANCE,
6571 	 STATUS_ID,
6572 	 STATUS_ID_ORIGINAL,
6573 	 STATUS,
6574 	 CREATION_TIME,
6575 	 DISPATCHED_TIME,
6576 	 LOADED_TIME,
6577 	 DROP_OFF_TIME,
6578 	 MMTT_LAST_UPDATE_DATE,
6579 	 MMTT_LAST_UPDATED_BY,
6580 	 WDT_LAST_UPDATE_DATE,
6581 	 WDT_LAST_UPDATED_BY,
6582 	 PRIORITY,
6583 	 PRIORITY_ORIGINAL,
6584 	 TASK_TYPE_ID,
6585 	 TASK_TYPE,
6586 	 MOVE_ORDER_LINE_ID,
6587 	 PICK_SLIP_NUMBER,
6588 	 CARTONIZATION_ID,
6589 	 ALLOCATED_LPN_ID,
6590 	 CONTAINER_ITEM_ID,
6591 	 CONTENT_LPN_ID,
6592 	 TO_LPN_ID,
6593 	 CONTAINER_ITEM ,
6594 	 CARTONIZATION_LPN,
6595 	 ALLOCATED_LPN ,
6596 	 CONTENT_LPN,
6597 	 TO_LPN,
6598 	 REFERENCE ,
6599 	 REFERENCE_ID,
6600 	 CUSTOMER_ID,
6601 	 CUSTOMER ,
6602 	 SHIP_TO_LOCATION_ID ,
6603 	 SHIP_TO_STATE ,
6604 	 SHIP_TO_COUNTRY,
6605 	 SHIP_TO_POSTAL_CODE,
6606 	 DELIVERY_ID ,
6607 	 DELIVERY ,
6608 	 SHIP_METHOD ,
6609 	 CARRIER_ID ,
6610 	 CARRIER ,
6611 	 SHIPMENT_DATE ,
6612 	 SHIPMENT_PRIORITY,
6613 	 WIP_ENTITY_TYPE,
6614 	 WIP_ENTITY_ID,
6615 	 ASSEMBLY_ID,
6616 	 ASSEMBLY ,
6617 	 LINE_ID,
6618 	 LINE,
6619 	 DEPARTMENT_ID,
6620 	 DEPARTMENT,
6621 	 SOURCE_HEADER,
6622 	 LINE_NUMBER,
6623 	 OPERATION_PLAN_ID,
6624 	 OPERATION_PLAN ,
6625 	 RESULT ,
6626 	 ERROR ,
6627 	 IS_MODIFIED ,
6628 	 EXPANSION_CODE,
6629 	 FROM_LPN ,
6630 	 FROM_LPN_ID,
6631 	 NUM_OF_CHILD_TASKS,
6632 	 OPERATION_SEQUENCE,
6633 	 OP_PLAN_INSTANCE_ID,
6634 	 PLANS_TASKS ,
6635 	 TRANSACTION_SET_ID,
6636 	 PICKED_LPN_ID,
6637 	 PICKED_LPN,
6638 	 LOADED_LPN,
6639 	 LOADED_LPN_ID,
6640 	 DROP_LPN ,
6641 	 SECONDARY_TRANSACTION_QUANTITY,
6642 	 SECONDARY_TRANSACTION_UOM ,
6643 	 PRIMARY_PRODUCT,
6644 	 LOAD_SEQ_NUMBER
6645       BULK COLLECT
6646       INTO   x_task_tab
6647       FROM   wms_waveplan_tasks_temp;
6648     END IF;
6649 
6650   END IF; --- if l_execute_qry then
6651 
6652   ELSE
6653     x_return_status := fnd_api.g_ret_sts_unexp_error;
6654     fnd_message.set_name('WMS', 'WMS_INVALID_VALUE');
6655     fnd_msg_pub.ADD;
6656     fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
6657     inv_trx_util_pub.trace(l_api_name||': '||'Invalid Parameters Passed');
6658   END IF; ----if p_transaction_number is not null
6659 
6660   EXCEPTION
6661     WHEN l_invalid_org THEN
6662       x_return_status := fnd_api.g_ret_sts_unexp_error;
6663       fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
6664       IF(l_debug = 1) THEN
6665         inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
6666       END IF;
6667       NULL;
6668 
6669     WHEN l_qry_fail THEN
6670       x_return_status := fnd_api.g_ret_sts_unexp_error;
6671       fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
6672       IF(l_debug = 1) THEN
6673         inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
6674       END IF;
6675       NULL;
6676 
6677     WHEN OTHERS THEN
6678       x_return_status := fnd_api.g_ret_sts_unexp_error;
6679       fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
6680       l_err_msg := substr(SQLERRM,1,1000);
6681       IF(l_debug = 1) THEN
6682         inv_trx_util_pub.trace(l_api_name||': '||l_err_msg);
6683       END IF;
6684       NULL;
6685 
6686   END query_task;
6687 -------------------------------------------------------------------------------------------------------------------
6688 --SPLIT TASK
6689 /*This Public API will take care of splitting the task(only outboung)provided by the user.
6690   The criterion to split is only based on the quantity.
6691 
6692 PROCEDURE split task (p_source_transaction_number IN           NUMBER DEFAULT NULL,
6693 		        p_split_quantities          IN  	 WMS_TASKS_PUB.TASK_QUANTITY_TABLE,
6694 		        p_commit                    IN           VARCHAR2  DEFAULT  G_FALSE,
6695 		        x_resultant_tasks           OUT NOCOPY   WMS_TASKS_PUB.TASK_TABLE,
6696 		        x_resultant_task_details    OUT NOCOPY   WMS_TASKS_PUB.TASK_DETAILS_TABLE,
6697 		        x_return_status             OUT NOCOPY   VARCHAR2,
6698 		        x_msg_count                 OUT NOCOPY   NUMBER,
6699 		        x_msg_data                  OUT NOCOPY   VARCHAR2  );
6700 
6701 
6702 Parameter			Description
6703 p_transaction_number		This corrsponds to the task_id that user is trying to split.
6704 P_split_quantities		This correspinds to the The PL/SQL table of quantities to be 	           splitted. This table will contain one or more entries with quantities to be splitted from the task.
6705 P_Commit			This parameter decides whether to commit the changes or not.
6706 X_resultant_tasks		PL/SQL table contains information about lot/serial allocation of the resultant tasks.
6707 X_Resultant_task_details	PL/SQL table of type wms_query_tasks_pub.task_tab_type contains the details of the resultant tasks after the split.
6708 X_return_status			This parameter gives the return status of split_task API. 	'S' = Success, 'U' = Unexpected Error, 'E' = Error.
6709 X_msg_count			This gives the count of messages logged during the split task process.
6710 X_msg_data			This gives the descrption of the messages that got logged during the split task process.
6711 */
6712 -------------------------------------------------------------------------------------------------------------------
6713 PROCEDURE split_task( p_source_transaction_number IN NUMBER DEFAULT NULL ,
6714 		      p_split_quantities IN task_qty_tbl_type ,
6715 		      p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE ,
6716 		      x_resultant_tasks OUT NOCOPY WMS_TASK_MGMT_PUB.task_tab_type ,
6717 		      x_resultant_task_details OUT NOCOPY task_detail_tbl_type ,
6718 		      x_return_status OUT NOCOPY VARCHAR2 ,
6719 		      x_msg_count OUT NOCOPY NUMBER ,
6720 		      x_msg_data OUT NOCOPY VARCHAR2 ) IS
6721 
6722         CURSOR mtlt_changed (p_ttemp_id IN NUMBER)
6723         IS
6724                 SELECT  *
6725                 FROM    mtl_transaction_lots_temp
6726                 WHERE   transaction_temp_id = p_ttemp_id
6727                 ORDER BY lot_number;
6728 
6729 	--Bug 6766048
6730 	CURSOR C_MMTT_ORG_ITM (p_txn_temp_id NUMBER)
6731 	IS
6732 		select inventory_item_id, organization_id
6733 		from mtl_material_transactions_temp
6734 		where transaction_temp_id = p_txn_temp_id;
6735 
6736 	CURSOR C_LOT_DIVISIBLE (p_item_id NUMBER,p_organization_id NUMBER )
6737 	IS
6738 		select lot_divisible_flag
6739 		from mtl_system_items
6740 		where inventory_item_id = p_item_id
6741 		and organization_id = p_organization_id;
6742 
6743 	l_mtlt_row MTL_TRANSACTION_LOTS_TEMP%ROWTYPE;
6744         --      l_split_uom_quantities               qty_changed_tbl_type;
6745         l_procedure_name            VARCHAR2(30)    := 'SPLIT_TASK';
6746         l_task_tbl_qty_count        NUMBER          := p_split_quantities.COUNT;
6747         g_debug                     NUMBER          := nvl(fnd_profile.VALUE('INV_DEBUG_TRACE'),0);
6748         l_decimal_precision         CONSTANT NUMBER := 5;
6749         l_task_tbl_primary_qty      NUMBER;
6750         l_task_tbl_transaction_qty  NUMBER;
6751         l_sum_tbl_transaction_qty   NUMBER := 0;
6752         l_sum_tbl_primary_qty       NUMBER := 0;
6753         l_new_mol_id                NUMBER;
6754         l_orig_mol_id               NUMBER;
6755         l_new_transaction_temp_id   NUMBER;
6756         l_new_transaction_header_id NUMBER;
6757         l_new_task_id               NUMBER;
6758         l_remaining_primary_qty     NUMBER := 0;
6759         l_remaining_transaction_qty NUMBER := 0;
6760         l_mol_num                   NUMBER;
6761         l_serial_control_code       NUMBER;
6762         l_lot_control_code          NUMBER;
6763         l_index                     NUMBER;
6764         l_new_tasks_output WMS_TASK_MGMT_PUB.task_tab_type;
6765         l_new_tasks_tbl WMS_TASK_MGMT_PUB.task_tab_type;
6766         x_task_table WMS_TASK_MGMT_PUB.task_tab_type;
6767         l_return_status          VARCHAR2(10);
6768         l_msg_count              NUMBER;
6769         l_msg_data               VARCHAR(200);
6770         l_validation_status      VARCHAR2(10);
6771         l_error_msg              VARCHAR2(1000);
6772         l_task_return_status     VARCHAR2(10);
6773         l_mmtt_return_status     VARCHAR2(1);
6774         l_wdt_return_status      VARCHAR2(1);
6775         l_lot_ser_return_status  VARCHAR2(1);
6776         l_serial_return_status   VARCHAR2(1);
6777         l_mtlt_transaction_qty   NUMBER;
6778         l_msnt_transaction_qty   NUMBER;
6779         l_val_task_ret_status    VARCHAR2(1);
6780         l_mmtt_inventory_item_id NUMBER;
6781         l_mmtt_task_status       NUMBER;
6782         l_mmtt_organization_id   NUMBER;
6783         l_split_uom_quantities QTY_CHANGED_TBL_TYPE;
6784         l_val_qty_ret_status   VARCHAR2(1);
6785         l_invalid_task         EXCEPTION;
6786         l_invalid_quantities   EXCEPTION;
6787         l_unexpected_error     EXCEPTION;
6788         l_query_task_exception EXCEPTION;
6789 	l_invalid_lot	       EXCEPTION;
6790 	--Bug 6766048
6791 	l_lot_divisible		    VARCHAR2(1);
6792 	l_mmtt_itm_id		    NUMBER;
6793 	l_mmtt_org_id		    NUMBER;
6794 
6795 BEGIN
6796         g_debug   := 1;
6797         IF g_debug = 1 THEN
6798                 print_msg(l_procedure_name,  'In Split Task ');
6799         END IF;
6800         x_return_status := 'S';
6801         new_task_table.delete;
6802         validate_task( p_transaction_temp_id => p_source_transaction_number ,
6803 		       x_return_status => x_return_status ,
6804 		       x_error_msg => l_error_msg ,
6805 		       x_msg_data => x_msg_data ,
6806 		       x_msg_count => x_msg_count );
6807         IF g_debug                           = 1 THEN
6808                 print_msg(l_procedure_name,  ' Validate task return status : '|| x_return_status);
6809         END IF;
6810         IF NVL(x_return_status,'E') <> 'S' THEN
6811                 RAISE l_invalid_task;
6812         END IF;
6813         validate_quantities( p_transaction_temp_id => p_source_transaction_number ,
6814 			     p_split_quantities => p_split_quantities ,
6815 			     x_lot_control_code => l_lot_control_code ,
6816 			     x_serial_control_code => l_serial_control_code ,
6817 			     x_split_uom_quantities => l_split_uom_quantities ,
6818 			     x_return_status => x_return_status ,
6819 			     x_msg_data => x_msg_data ,
6820 			     x_msg_count => x_msg_count );
6821 
6822         IF NVL(x_return_status,'E')               <> 'S' THEN
6823                 RAISE l_invalid_quantities;
6824         END IF;
6825 	--Bug 6766048:Check if the lot item is divisble or not.If not, log error and exit.
6826 	IF (l_lot_control_code = 2) THEN
6827 		OPEN C_MMTT_ORG_ITM(p_source_transaction_number);
6828 		FETCH C_MMTT_ORG_ITM into l_mmtt_itm_id,l_mmtt_org_id;
6829 		CLOSE C_MMTT_ORG_ITM;
6830 
6831 		OPEN C_LOT_DIVISIBLE(l_mmtt_itm_id,l_mmtt_org_id);
6832 		FETCH C_LOT_DIVISIBLE into l_lot_divisible;
6833 		CLOSE C_LOT_DIVISIBLE;
6834 
6835 		IF (l_lot_divisible =  'N') THEN
6836 			RAISE l_invalid_lot;
6837 		END IF;
6838 	END IF;
6839 
6840         IF g_debug     = 1 THEN
6841                 FOR i in l_split_uom_quantities.FIRST .. l_split_uom_quantities.LAST
6842                 LOOP
6843                         print_msg(l_procedure_name, ' l_split_uom_quantities('||i|| ').primary_quantity: '||l_split_uom_quantities(i).primary_quantity);
6844                         print_msg(l_procedure_name, ' l_split_uom_quantities('||i|| ').transaction_quantity: '||l_split_uom_quantities(i).transaction_quantity);
6845                 END LOOP;
6846         END IF;
6847         SAVEPOINT wms_split_task;
6848         IF g_debug = 1 THEN
6849                 print_msg(l_procedure_name, ' SAVEPOINT wms_split_task established');
6850         END IF;
6851         FOR i IN l_split_uom_quantities.FIRST .. l_split_uom_quantities.LAST
6852         LOOP
6853                 SELECT  mtl_material_transactions_s.NEXTVAL
6854                 INTO    l_new_transaction_header_id
6855                 FROM    dual;
6856                 SELECT  mtl_material_transactions_s.NEXTVAL
6857                 INTO    l_new_transaction_temp_id
6858                 FROM    dual;
6859                 SELECT wms_dispatched_tasks_s.NEXTVAL INTO l_new_task_id FROM dual;
6860                 IF g_debug = 1 THEN
6861                         print_msg(l_procedure_name,  ' Calling split_mmtt for Txn. temp id : '||p_source_transaction_number);
6862                 END IF;
6863                 split_mmtt( p_orig_transaction_temp_id => p_source_transaction_number ,
6864 			    p_new_transaction_temp_id => l_new_transaction_temp_id ,
6865 			    p_new_transaction_header_id => l_new_transaction_header_id ,
6866 			    p_new_mol_id => l_orig_mol_id ,
6867 			    p_transaction_qty_to_split => l_split_uom_quantities(i).transaction_quantity ,
6868 			    p_primary_qty_to_split => l_split_uom_quantities(i).primary_quantity ,
6869 				p_secondary_qty_to_split => l_split_uom_quantities(i).secondary_quantity ,  -- Added for Bug 16099247
6870 			    x_return_status => x_return_status ,
6871 			    x_msg_data => x_msg_data ,
6872 			    x_msg_count => x_msg_count );
6873 
6874                 IF g_debug                             = 1 THEN
6875                         print_msg(l_procedure_name,  ' x_return_status : ' || x_return_status);
6876                 END IF;
6877                 IF NVL(x_return_status, 'E') <> 'S' THEN
6878                         IF g_debug            = 1 THEN
6879                                 print_msg(l_procedure_name, ' Unable to split MMTT, unexpected error has occurred');
6880                         END IF;
6881                         RAISE l_unexpected_error;
6882                 END IF;
6883                 BEGIN
6884                         SELECT  status
6885                         INTO    l_mmtt_task_status
6886                         FROM    wms_dispatched_tasks
6887                         WHERE   transaction_temp_id = p_source_transaction_number;
6888                 EXCEPTION
6889                 WHEN NO_DATA_FOUND THEN
6890                         l_mmtt_task_status := -9999;
6891                         NULL;
6892                 END;
6893                 IF g_debug = 1 THEN
6894                         print_msg(l_procedure_name,   'l_mmtt_task_status :  '|| l_mmtt_task_status);
6895                 END IF;
6896                 IF l_mmtt_task_status            = 2 THEN
6897                         split_wdt( p_new_task_id => l_new_task_id ,
6898 			p_new_transaction_temp_id => l_new_transaction_temp_id ,
6899 			p_new_mol_id => l_orig_mol_id ,
6900 			p_orig_transaction_temp_id => p_source_transaction_number ,
6901 			x_return_status => x_return_status ,
6902 			x_msg_data => x_msg_data ,
6903 			x_msg_count => x_msg_count );
6904 
6905                         IF g_debug               = 1 THEN
6906                                 print_msg(l_procedure_name,  ' x_return_status : '||x_return_status);
6907                         END IF;
6908                         IF NVL(x_return_status, 'E') <> 'S' THEN
6909                                 IF g_debug            = 1 THEN
6910                                         print_msg(l_procedure_name, ' Unable to split WDT, unexpected error has occurred');
6911                                 END IF;
6912                                 RAISE l_unexpected_error;
6913                         END IF;
6914                 END IF;
6915                 IF (l_lot_control_code = 2 AND l_serial_control_code IN (2,5)) OR (l_lot_control_code = 2 AND l_serial_control_code NOT IN (2,5)) THEN
6916                         split_lot_serial( p_source_transaction_number ,
6917 					  l_new_transaction_temp_id ,
6918 					  l_split_uom_quantities(i).transaction_quantity ,
6919 					  l_split_uom_quantities(i).primary_quantity ,
6920 					  l_split_uom_quantities(i).secondary_quantity ,-- Added for Bug 16099247
6921 					  l_mmtt_inventory_item_id ,
6922 					  l_mmtt_organization_id ,
6923 					  x_return_status ,
6924 					  x_msg_data ,
6925 					  x_msg_count );
6926 
6927                         IF g_debug = 1 THEN
6928                                 print_msg(l_procedure_name,  ' x_return_status : ' || x_return_status);
6929                         END IF;
6930                         IF NVL(x_return_status, 'E') <> 'S' THEN
6931                                 IF g_debug            = 1 THEN
6932                                         print_msg(l_procedure_name, ' Was not able to split lot serial');
6933                                 END IF;
6934                                 RAISE l_unexpected_error;
6935                         END IF;
6936                 ELSIF l_lot_control_code                         = 1 AND l_serial_control_code IN (2,5) THEN
6937                         split_serial( p_orig_transaction_temp_id => p_source_transaction_number ,
6938 				      p_new_transaction_temp_id => l_new_transaction_temp_id ,
6939 				      p_transaction_qty_to_split => l_split_uom_quantities(i).transaction_quantity ,
6940 				      p_primary_qty_to_split => l_split_uom_quantities(i).primary_quantity ,
6941 				      p_inventory_item_id => l_mmtt_inventory_item_id ,
6942 				      p_organization_id => l_mmtt_organization_id ,
6943 				      x_return_status => x_return_status ,
6944 				      x_msg_data => x_msg_data ,
6945 				      x_msg_count => x_msg_count );
6946                         IF g_debug                               = 1 THEN
6947                                 print_msg(l_procedure_name,  ' x_return_status : '||x_return_status);
6948                         END IF;
6949                         IF NVL(x_return_status, 'E') <> 'S' THEN
6950                                 IF g_debug            = 1 THEN
6951                                         print_msg(l_procedure_name, ' Was not able to split serials');
6952                                 END IF;
6953                                 RAISE l_unexpected_error;
6954                         END IF;
6955                 END IF;
6956                 -- Update the original row
6957                 BEGIN
6958                         UPDATE mtl_material_transactions_temp
6959                         SET     primary_quantity     = primary_quantity     - l_split_uom_quantities(i).primary_quantity     ,
6960                                 transaction_quantity = transaction_quantity - l_split_uom_quantities(i).transaction_quantity ,
6961 								secondary_transaction_quantity = secondary_transaction_quantity - l_split_uom_quantities(i).secondary_quantity , -- Added for Bug 16099247
6962                                 last_updated_by      = FND_GLOBAL.USER_ID
6963                         WHERE   transaction_temp_id  = p_source_transaction_number;
6964                 EXCEPTION
6965                 WHEN OTHERS THEN
6966                         IF g_debug = 1 THEN
6967                                 print_msg(l_procedure_name,  ' Error Code : '|| SQLCODE || ' Error Message :'||SUBSTR(SQLERRM,1,100));
6968                         END IF;
6969                         RAISE l_unexpected_error;
6970                 END;
6971                 IF g_debug = 1 THEN
6972                         print_msg(l_procedure_name, ' Updated original txn. temp id :'||p_source_transaction_number);
6973                 END IF;
6974                 l_index                                     := new_task_table.count + 1;
6975                 new_task_table(l_index).transaction_temp_id := l_new_transaction_temp_id;
6976         END LOOP;
6977         l_index                                     := new_task_table.count + 1;
6978         new_task_table(l_index).transaction_temp_id := p_source_transaction_number;
6979         IF g_debug                                   = 1 THEN
6980                 print_msg(l_procedure_name, ' Split done sucessfully for txn. temp id :'||p_source_transaction_number);
6981         END IF;
6982         IF g_debug = 1 THEN
6983                 print_msg(l_procedure_name, ' lot control code :'||l_lot_control_code ||  ' serial control code : '|| l_serial_control_code);
6984         END IF;
6985         IF g_debug = 1 THEN
6986                 print_msg(l_procedure_name, '***********New Task Table***********');
6987                 print_msg(l_procedure_name, '*** Transaction temp id ***');
6988                 FOR i IN new_task_table.FIRST .. new_task_table.LAST
6989                 LOOP
6990                         print_msg(l_procedure_name,   '   '|| new_task_table(i).transaction_temp_id);
6991                 END LOOP;
6992         END IF;
6993         IF g_debug = 1 THEN
6994                 print_msg(l_procedure_name, 'Inserting Lot/Serial details of the new tasks in X_RESULTANT_TASK_DETAILS');
6995         END IF;
6996         IF l_lot_control_code = 2 THEN
6997                 FOR i        IN new_task_table.FIRST .. new_task_table.LAST
6998                 LOOP
6999                         OPEN mtlt_changed(new_task_table(i).transaction_temp_id);
7000                         LOOP
7001                                 FETCH mtlt_changed INTO l_mtlt_row;
7002                                 EXIT
7003                         WHEN mtlt_changed%NOTFOUND;
7004                                 l_index                                                    := x_resultant_task_details.count + 1;
7005                                 x_resultant_task_details(l_index).parent_task_id           := l_mtlt_row.transaction_temp_id;
7006                                 x_resultant_task_details(l_index).lot_number               := l_mtlt_row.lot_number;
7007                                 x_resultant_task_details(l_index).lot_expiration_date      := l_mtlt_row.lot_expiration_date;
7008                                 x_resultant_task_details(l_index).lot_primary_quantity     := l_mtlt_row.primary_quantity;
7009                                 x_resultant_task_details(l_index).lot_transaction_quantity := l_mtlt_row.transaction_quantity;
7010 								x_resultant_task_details(l_index).lot_secondary_quantity := l_mtlt_row.secondary_quantity; -- Added for Bug 16099247
7011                                 IF l_mtlt_row.serial_transaction_temp_id IS NOT NULL THEN
7012                                         x_resultant_task_details(l_index).number_of_serials := l_mtlt_row.primary_quantity;
7013                                         SELECT  MIN(FM_SERIAL_NUMBER) ,
7014                                                 MAX(FM_SERIAL_NUMBER) ,
7015                                                 MAX(status_id)
7016                                         INTO    x_resultant_task_details(l_index).from_serial_number ,
7017                                                 x_resultant_task_details(l_index).to_serial_number   ,
7018                                                 x_resultant_task_details(l_index).serial_status_id
7019                                         FROM    mtl_serial_numbers_temp
7020                                         WHERE   transaction_temp_id = l_mtlt_row.serial_transaction_temp_id;
7021                                 END IF;
7022                         END LOOP;
7023                         CLOSE mtlt_changed;
7024                 END LOOP;
7025         ELSIF l_serial_control_code IN (2,5) THEN
7026                 FOR i               IN new_task_table.FIRST .. new_task_table.LAST
7027                 LOOP
7028                         l_index                                          := x_resultant_task_details.count + 1;
7029                         x_resultant_task_details(l_index).parent_task_id := new_task_table(i).transaction_temp_id;
7030                         SELECT  MIN(FM_SERIAL_NUMBER) ,
7031                                 MAX(FM_SERIAL_NUMBER) ,
7032                                 MAX(status_id)        ,
7033                                 COUNT(*)
7034                         INTO    x_resultant_task_details(l_index).from_serial_number ,
7035                                 x_resultant_task_details(l_index).to_serial_number   ,
7036                                 x_resultant_task_details(l_index).serial_status_id   ,
7037                                 x_resultant_task_details(l_index).number_of_serials
7038                         FROM    mtl_serial_numbers_temp
7039                         WHERE   transaction_temp_id = new_task_table(i).transaction_temp_id;
7040                 END LOOP;
7041         END IF;
7042         IF g_debug                                = 1 THEN
7043                 IF x_resultant_task_details.COUNT > 0 THEN
7044                         print_msg(l_procedure_name, 'Task Id    Lot    quantity  fm_serial   to_serial   num_of_serials');
7045                         FOR i IN x_resultant_task_details.FIRST .. x_resultant_task_details.LAST
7046                         LOOP
7047                                 print_msg(l_procedure_name,
7048 					  x_resultant_task_details(i).parent_task_id ||
7049 					  '      '||
7050 					  x_resultant_task_details(i).lot_number ||
7051 					  '      '||
7052 					  x_resultant_task_details(i).lot_primary_quantity||
7053 					  '      '||
7054 					  x_resultant_task_details(i).from_serial_number||
7055 					  '      '||
7056 					  x_resultant_task_details(i).to_serial_number||
7057 					  '      '||
7058 					  x_resultant_task_details(i).number_of_serials);
7059                         END LOOP;
7060                 ELSE
7061                         print_msg(l_procedure_name,'Table x_resultant_task_details is empty, item is not serial or lot controlled');
7062                 END IF;
7063         END IF;
7064         FOR i IN new_task_table.FIRST .. new_task_table.LAST
7065         LOOP
7066                 IF g_debug = 1 THEN
7067                         print_msg(l_procedure_name, 'Before calling WMS_TASK_MGMT_PUB.query_task');
7068                         WMS_TASK_MGMT_PUB.query_task ( new_task_table(i).transaction_temp_id ,
7069 						       NULL ,
7070 						       l_new_tasks_tbl ,
7071 						       l_return_status ,
7072 						       l_msg_count ,
7073 						       l_msg_data );
7074 
7075                         IF NVL(l_return_status,'N') = 'S' OR l_new_tasks_tbl.COUNT > 0 THEN
7076                                 IF g_debug          = 1 THEN
7077                                         print_msg(l_procedure_name,  'WMS_TASK_MGMT_PUB.query_task returned success for task : ' || new_task_table(i).transaction_temp_id);
7078                                 END IF;
7079                                 IF l_new_tasks_tbl.COUNT      > 0 THEN
7080                                         x_resultant_tasks(i) := l_new_tasks_tbl(1);
7081                                 END IF;
7082                         ELSE
7083                                 IF g_debug = 1 THEN
7084                                         print_msg(l_procedure_name, 'WMS_TASK_MGMT_PUB.query_task returned error');
7085                                 END IF;
7086 --                               x_return_status := 'E';
7087                                 RAISE l_query_task_exception;
7088                         END IF;
7089                 END IF;
7090         END LOOP;
7091         IF g_debug                         = 1 THEN
7092                 IF x_resultant_tasks.COUNT > 0 THEN
7093                         print_msg(l_procedure_name, 'Task Id   item_id  sub   locator   Qty');
7094                         FOR i IN x_resultant_tasks.FIRST .. x_resultant_tasks.LAST
7095                         LOOP
7096                                 print_msg(l_procedure_name,
7097 					  x_resultant_tasks(i).task_id ||
7098 					  '     '||
7099 					  x_resultant_tasks(i).inventory_item_id||
7100 					  '     '||
7101 					  x_resultant_tasks(i).subinventory||
7102 					  '     '||
7103 					  x_resultant_tasks(i).locator||
7104 					  '     '||
7105 					  x_resultant_tasks(i).transaction_quantity);
7106                         END LOOP;
7107                 ELSE
7108                         print_msg(l_procedure_name, 'Table x_resultant_tasks is empty');
7109                 END IF;
7110         END IF;
7111         IF p_commit        = FND_API.G_TRUE THEN
7112                 IF g_debug = 1 THEN
7113                         print_msg(l_procedure_name, ' p_commit is TRUE, so COMMITING the transactions.');
7114                 END IF;
7115                 COMMIT;
7116         ELSE
7117                 IF g_debug = 1 THEN
7118                         print_msg(l_procedure_name, ' p_commit is FALSE, so not COMMITING the transactions.');
7119                 END IF;
7120         END IF;
7121         x_return_status := 'S';
7122 EXCEPTION
7123 WHEN L_INVALID_TASK THEN
7124         IF g_debug = 1 THEN
7125                 print_msg(l_procedure_name,'EXCEPTION BLOCK  : Validate task returned error');
7126         END IF;
7127         x_return_status := 'S';
7128         WMS_TASK_MGMT_PUB.query_task ( p_source_transaction_number ,
7129 				       NULL ,
7130 				       l_new_tasks_tbl ,
7131 				       l_return_status ,
7132 				       l_msg_count ,
7133 				       l_msg_data );
7134         fnd_message.set_name('WMS', 'WMS_INVALID_TASK');
7135         fnd_msg_pub.ADD;
7136         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
7137 
7138         IF l_new_tasks_tbl.COUNT      > 0 THEN
7139                 x_resultant_tasks(1)        := l_new_tasks_tbl(1);
7140                 x_resultant_tasks(1).RESULT := 'E';
7141 --              x_resultant_tasks(1).ERROR  := 'Invalid Task';
7142 --		anjana
7143                 x_resultant_tasks(1).ERROR  := x_msg_data;
7144 
7145         END IF;
7146 --Bug 6766048
7147 WHEN L_INVALID_LOT THEN
7148         IF g_debug = 1 THEN
7149                 print_msg(l_procedure_name,'EXCEPTION BLOCK  : Lot split error');
7150         END IF;
7151         x_return_status := 'S';
7152         WMS_TASK_MGMT_PUB.query_task ( p_source_transaction_number ,
7153 				       NULL ,
7154 				       l_new_tasks_tbl ,
7155 				       l_return_status ,
7156 				       l_msg_count ,
7157 				       l_msg_data );
7158         fnd_message.set_name('INV', 'INV_LOT_INDIVISIBLE');
7159         fnd_msg_pub.ADD;
7160         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
7161 
7162         IF l_new_tasks_tbl.COUNT      > 0 THEN
7163                 x_resultant_tasks(1)        := l_new_tasks_tbl(1);
7164                 x_resultant_tasks(1).RESULT := 'E';
7165 	        x_resultant_tasks(1).ERROR  := x_msg_data;
7166         END IF;
7167 
7168 WHEN L_INVALID_QUANTITIES THEN
7169         IF g_debug = 1 THEN
7170                 print_msg(l_procedure_name,'EXCEPTION BLOCK  : Validate quantities returned error');
7171         END IF;
7172         x_return_status := 'S';
7173         WMS_TASK_MGMT_PUB.query_task ( p_source_transaction_number ,
7174 				       NULL ,
7175 				       l_new_tasks_tbl ,
7176 				       l_return_status ,
7177 				       l_msg_count ,
7178 				       l_msg_data );
7179         fnd_message.set_name('WMS', 'WMS_INVALID_SPLIT_QUANTITY');
7180         fnd_msg_pub.ADD;
7181         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
7182 
7183         IF l_new_tasks_tbl.COUNT      > 0 THEN
7184                 x_resultant_tasks(1)        := l_new_tasks_tbl(1);
7185                 x_resultant_tasks(1).RESULT := 'E';
7186 --              x_resultant_tasks(1).ERROR  := 'Invalid Quantities';
7187 --		anjana
7188                 x_resultant_tasks(1).ERROR  := x_msg_data;
7189         END IF;
7190 
7191 WHEN L_QUERY_TASK_EXCEPTION THEN
7192         IF g_debug = 1 THEN
7193                 print_msg(l_procedure_name,'EXCEPTION BLOCK  : Query task returned error, ROLLING BACK THE TRANSACTIONS');
7194         END IF;
7195         x_return_status := 'S';
7196         ROLLBACK TO wms_split_task;
7197         WMS_TASK_MGMT_PUB.query_task ( p_source_transaction_number ,
7198 	                               NULL ,
7199 				       l_new_tasks_tbl ,
7200 				       l_return_status ,
7201 				       l_msg_count ,
7202 				       l_msg_data );
7203         fnd_message.set_name('WMS', 'WMS_QUERY_ELIG_MATRL');
7204         fnd_msg_pub.ADD;
7205         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
7206 
7207         IF l_new_tasks_tbl.COUNT      > 0 THEN
7208                 x_resultant_tasks(1)        := l_new_tasks_tbl(1);
7209                 x_resultant_tasks(1).RESULT := 'E';
7210 --              x_resultant_tasks(1).ERROR  := 'Query Task returned error or no rows';
7211 --		anjana
7212                 x_resultant_tasks(1).ERROR  := x_msg_data;
7213         END IF;
7214 
7215 WHEN L_UNEXPECTED_ERROR THEN
7216         IF g_debug = 1 THEN
7217                 print_msg(l_procedure_name,'EXCEPTION BLOCK  : Unexpected error has occured, ROLLING BACK THE TRANSACTIONS');
7218         END IF;
7219         x_return_status := 'E';
7220         ROLLBACK TO wms_split_task;
7221         fnd_message.set_name('WMS', 'WMS_UNEXPECTED_ERROR');
7222         fnd_msg_pub.ADD;
7223         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
7224 WHEN OTHERS THEN
7225         IF g_debug = 1 THEN
7226                 print_msg(l_procedure_name,'EXCEPTION BLOCK  : Unexpected error has occured, ROLLING BACK THE TRANSACTIONS');
7227         END IF;
7228         x_return_status := 'E';
7229         ROLLBACK TO wms_split_task;
7230         fnd_message.set_name('WMS', 'WMS_UNEXPECTED_ERROR');
7231         fnd_msg_pub.ADD;
7232         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
7233         x_return_status                  := 'E';
7234         IF g_debug                        = 1 THEN
7235                 print_msg(l_procedure_name,  'EXCEPTION BLOCK  :  Error Code : '|| SQLCODE || 'EXCEPTION BLOCK  :  Error Message :'||SQLERRM);
7236         END IF;
7237 END split_task;
7238 
7239 -------------------------------------------------------------------------------------------------------------------
7240 --MODIFY TASK
7241 /*This Public API takes care of modifying the following attributes of a task or set of tasks:
7242 1.Task Status
7243 2.Task Priority
7244 3.Operation Plan
7245 4.Cartonization LPN
7246 5.Task Type
7247 
7248 PROCEDURE modify_task (p_transaction_number     IN              NUMBER DEFAULT NULL
7249 		  , p_task_table                IN              WMS_TASKS_PUB.TASK_TABLE
7250 		  , p_new_task_status     	IN              NUMBER DEFAULT NULL
7251 		  , p_new_task_priority   	IN              NUMBER DEFAULT NULL
7252 		  , p_new_task_type         	IN              VARCHAR2 DEFAULT NULL
7253 		  , p_new_carton_lpn_id   	IN              NUMBER DEFAULT NULL
7254 		  , p_new_operation_plan_id   	IN              NUMBER DEFAILUT NULL
7255 		  , p_person_id			IN		NUMBER DEFAULT  NULL
7256 		  , p_commit                    IN              VARCHAR2  DEFAULT  G_FALSE
7257 		  , x_updated_tasks         	OUT 	NOCOPY  WMS_TASKS_PUB.TASK_TABLE
7258 		  , x_return_status           	OUT 	NOCOPY  VARCHAR2
7259 		  , x_msg_count              	OUT 	NOCOPY  NUMBER
7260 		  , x_msg_data                 	OUT 	NOCOPY  VARCHAR2 );
7261 
7262 Parameter		Description
7263 
7264 p_transaction_number	This corresponds to the task_id that user is trying to update
7265 P_task_table		This corresponds to the set of tasks that user is trying to update
7266 P_new_task_status	This corresponds to the new status to which user wants to update the task/set of tasks
7267 P_new_task_priority	This corresponds to new task priority which user wants to assign to the tasks/set of tasks.
7268 P_new_task_tyoe		This corresponds to the new task type which user wants to update on the task/set of tasks.
7269 P_new_carton_lpn_id	This is the carton_lpn_id which user wants to update on task/set of tasks.
7270 P_new_operation_plan_id	This is the new operation plan id which user wants to update on task/set of tasks.
7271 P_person_id		This the user to which task will be queued, if the task status is getting changed to 'Queued' state.
7272 P_Commit		This parameter decides whether to commit the changes or not.
7273 X_updated_tasks		This is a table of records, which contain the updated tasks. If the tasks could not be updated, the Result column in the table is updated with 'E' and the Error column is updated with the error message
7274 X_return_status		This parameter gives the return status of Modify_task API.	'S' = Success, 'U' = Unexpected Error, 'E' = Error.
7275 X_msg_count		This gives the count of messages logged during the task updation process.
7276 X_msg_data		This gives the description of the messages that got logged during the task updation process.
7277 
7278 */
7279 -------------------------------------------------------------------------------------------------------------------
7280 PROCEDURE modify_task ( p_transaction_number IN NUMBER DEFAULT NULL ,
7281 			p_task_table IN WMS_TASK_MGMT_PUB.task_tab_type ,
7282 			p_new_task_status IN NUMBER DEFAULT NULL ,
7283 			p_new_task_priority IN NUMBER DEFAULT NULL ,
7284 			p_new_task_type IN VARCHAR2 DEFAULT NULL ,
7285 			p_new_carton_lpn_id IN NUMBER DEFAULT NULL ,
7286 			p_new_operation_plan_id IN NUMBER DEFAULT NULL ,
7287 			p_person_id IN NUMBER DEFAULT NULL ,
7288 			p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE ,
7289 			x_updated_tasks OUT NOCOPY WMS_TASK_MGMT_PUB.task_tab_type ,
7290 			x_return_status OUT NOCOPY VARCHAR2 ,
7291 			x_msg_count OUT NOCOPY NUMBER ,
7292 			x_msg_data OUT NOCOPY VARCHAR2 ) IS
7293 
7294         temp_task_tab WMS_TASK_MGMT_PUB.task_tab_type;
7295         CURSOR op_plan_cur(c_op_plan_id NUMBER)
7296         IS
7297                 SELECT  system_task_type ,
7298                         organization_id  ,
7299                         enabled_flag     ,
7300                         activity_type_id ,
7301                         common_to_all_org,
7302                         plan_type_id
7303                 FROM    wms_op_plans_b
7304                 WHERE   operation_plan_id=c_op_plan_id;
7305         --Cursor to lock the mmtt record before updation.
7306         Cursor c_lock_mmtt (p_transaction_number NUMBER)
7307         IS
7308                 SELECT '1'
7309                 FROM    mtl_material_transactions_temp
7310                 WHERE   transaction_temp_id = p_transaction_number FOR UPDATE NOWAIT;
7311         --Cursor to lock the mcce record before updation.
7312         Cursor c_lock_mcce (p_transaction_number NUMBER)
7313         IS
7314                 SELECT '1'
7315                 FROM    mtl_cycle_count_entries
7316                 WHERE   cycle_count_entry_id = p_transaction_number FOR UPDATE NOWAIT;
7317         p_return_sts         VARCHAR2(30);
7318         P_msg_count          NUMBER;
7319         l_msg_count          NUMBER;
7320         P_msg_data           VARCHAR2(30);
7321         l_valid_task_counter NUMBER;
7322         p_temp_task_rec WMS_TASK_MGMT_PUB.task_output_rectype;
7323         l_op_plan_rec WMS_TASK_MGMT_PUB.op_plan_rec;
7324         l_debug     NUMBER         := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7325         l_api_name  VARCHAR2(1000) := 'MODIFY_TASK';
7326         l_msg       VARCHAR2(2000);
7327         l_err_msg   VARCHAR2(2000);
7328         l_error_msg VARCHAR2(2000);
7329         l_lock      VARCHAR2(2);
7330         l_updated_tasks WMS_TASK_MGMT_PUB.task_tab_type;
7331 
7332 
7333 	TYPE TransactionNumber IS TABLE OF NUMBER
7334         INDEX BY BINARY_INTEGER;
7335 	TYPE OrganizationId IS TABLE OF NUMBER
7336         INDEX BY BINARY_INTEGER;
7337 	TYPE  UserTaskTypeId IS TABLE OF NUMBER
7338         INDEX BY BINARY_INTEGER;
7339 	TYPE PersonId IS TABLE OF NUMBER
7340         INDEX BY BINARY_INTEGER;
7341 	TYPE PersonResourceId IS TABLE OF NUMBER
7342         INDEX BY BINARY_INTEGER;
7343 	TYPE MachineResourceId IS TABLE OF NUMBER
7344         INDEX BY BINARY_INTEGER;
7345 	TYPE StatusId IS TABLE OF NUMBER
7346         INDEX BY BINARY_INTEGER;
7347 	TYPE Priority IS TABLE OF NUMBER
7348         INDEX BY BINARY_INTEGER;
7349 	TYPE TaskTypeId IS TABLE OF NUMBER
7350         INDEX BY BINARY_INTEGER;
7351 	TYPE MoveOrderLineId IS TABLE OF NUMBER
7352         INDEX BY BINARY_INTEGER;
7353 	TYPE ToLpnId IS TABLE OF NUMBER
7354         INDEX BY BINARY_INTEGER;
7355 	TYPE OperationPlanId IS TABLE OF NUMBER
7356         INDEX BY BINARY_INTEGER;
7357 	TYPE CartonizationId IS TABLE OF NUMBER
7358         INDEX BY BINARY_INTEGER;
7359 	TYPE DispatchedTime is TABLE OF DATE;
7360 
7361 	l_transaction_num_table TransactionNumber;
7362 	l_organization_id_table OrganizationId;
7363 	l_usertask_type_id_table UserTaskTypeId;
7364 	l_person_id_tabke PersonId;
7365 	l_person_resource_id_tabe PersonResourceId;
7366 	l_machine_resource_id_table MachineResourceId;
7367 	l_status_id_table  StatusId;
7368 	l_priority_table Priority;
7369 	l_task_type_id_table TaskTypeId;
7370 	l_move_order_line_id_table MoveOrderLineId;
7371 	l_to_lpn_id_table ToLpnId;
7372 	l_operation_plan_id_table OperationPlanId;
7373 	l_dispatched_time_table DispatchedTime;
7374 
7375 	l_mmtt_cartonization_id_table CartonizationId;
7376 	l_mmtt_transaction_num_table TransactionNumber;
7377 	l_mmtt_usertask_type_id_table UserTaskTypeId;
7378 	l_mmtt_status_id_table  StatusId;
7379 	l_mmtt_priority_table Priority;
7380 	l_mmtt_operation_plan_id_table OperationPlanId;
7381 
7382 	l_mcce_transaction_num_table TransactionNumber;
7383 	l_mcce_usertask_type_id_table UserTaskTypeId;
7384 	l_mcce_priority_table Priority;
7385 
7386 	l_wdt_transaction_num_table TransactionNumber;
7387 	l_wdt_usertask_type_id_table UserTaskTypeId;
7388 	l_wdt_status_id_table  StatusId;
7389 	l_wdt_priority_table Priority;
7390 	l_wdt_operation_plan_id_table OperationPlanId;
7391 
7392 	l_wdt_del_trns_num_table TransactionNumber;
7393 	l_action VARCHAR2(20) := 'MODIFY'; --	6850212
7394 
7395 
7396 BEGIN
7397         x_return_status := fnd_api.g_ret_sts_success;
7398 	--anjana
7399 	x_msg_count := 0;
7400         --1.Tasks status can be updated only to to Pending or queued or unreleased state.
7401         IF (p_new_task_status IS NOT NULL) THEN
7402                 IF(p_new_task_status NOT IN (1,2,8)) THEN
7403                         --6850212:Return status should not be set to error.
7404                         --x_return_status  := fnd_api.g_ret_sts_error;
7405                         fnd_message.set_name('WMS', 'WMS_INVALID_TASK_STATUS');--new message
7406                         fnd_msg_pub.ADD;
7407                         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_msg );
7408 			x_msg_data := l_msg;
7409 			x_msg_count := l_msg_count;
7410                         l_err_msg                        :='New task status not in Pending or Queued state or Unreleased state';
7411                         IF(l_debug                        = 1) THEN
7412                                 inv_trx_util_pub.trace(l_api_name|| ': '||l_err_msg);
7413                         END IF;
7414                         log_error(p_transaction_number => p_transaction_number, p_task_table => p_task_table, p_error_msg => l_msg, x_updated_tasks => x_updated_tasks);
7415                         RETURN;
7416                 END IF;
7417         END IF;
7418         --2.If operation Plan is send, then check if it is enabled in the org or not.
7419         IF (p_new_operation_plan_id IS NOT NULL) THEN
7420                 OPEN op_plan_cur(p_new_operation_plan_id);
7421                 FETCH   op_plan_cur
7422                 INTO    l_op_plan_rec.system_task_type ,
7423                         l_op_plan_rec.organization_id  ,
7424                         l_op_plan_rec.eabled_flag      ,
7425                         l_op_plan_rec.activity_type_id ,
7426                         l_op_plan_rec.common_to_all_org,
7427                         l_op_plan_rec.plan_type_id;
7428                 IF (l_op_plan_rec.eabled_flag <> 'Y') THEN--op_plan passed is not enabled
7429                         --6850212:Return status should not be set to error.
7430                         --x_return_status       := fnd_api.g_ret_sts_error;
7431                         fnd_message.set_name('WMS', 'WMS_OPERTN_PLAN_ID_INVALID');--new message
7432                         fnd_msg_pub.ADD;
7433                         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_msg );
7434 			x_msg_data := l_msg;
7435 			x_msg_count := l_msg_count;
7436                         l_err_msg                        :='Operation Plan is not enabled';
7437                         IF(l_debug                        = 1) THEN
7438                                 inv_trx_util_pub.trace(l_api_name|| ': '||l_err_msg);
7439                         END IF;
7440                         log_error(p_transaction_number => p_transaction_number,
7441 				  p_task_table => p_task_table,
7442 				  p_error_msg => l_msg,
7443 				  x_updated_tasks => x_updated_tasks);
7444                         RETURN;
7445                 END IF;
7446                 CLOSE op_plan_cur;
7447         END IF;
7448         --3.Perform Validation,Query,Check cartonization on taks/tasks.
7449         --  If transaction_number and task_table are both passed, honour transaction_number.
7450         --Call Validate task API
7451 	validate_tasks(p_transaction_number => p_transaction_number,
7452 		       p_task_table => p_task_table,
7453 			p_action     => l_action,  --6850212
7454 		       x_wms_task => l_updated_tasks,
7455 		       x_return_status => p_return_sts);
7456 
7457 	IF (p_return_sts                    = fnd_api.g_ret_sts_success) THEN
7458 		l_valid_task_counter       := l_updated_tasks.count;
7459 		FOR i                      IN 1..l_updated_tasks.count
7460 		LOOP--Loop starts
7461 			IF (nvl(l_updated_tasks(i).RESULT,'X')<> 'E') THEN
7462 				temp_task_tab.delete;-- := NULL; --flush the temporary table
7463 				WMS_TASK_MGMT_PUB.query_task( p_transaction_number => l_updated_tasks(i).transaction_number,
7464 							      p_query_name => NULL,
7465 							      x_task_tab => temp_task_tab,
7466 							      x_return_status => p_return_sts,
7467 							      x_msg_count => p_msg_count,
7468 							      x_msg_data => p_msg_data);
7469 
7470 				--if quey was not successfull then populate output table with passed values with error
7471 				IF ((p_return_sts <> fnd_api.g_ret_sts_success) OR ( temp_task_tab.count = 0)) THEN
7472 					fnd_message.set_name('WMS', 'WMS_QUERY_ELIG_MATRL');--new message
7473 --					fnd_msg_pub.ADD;
7474 --					fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_msg);
7475 					--anjana
7476 					l_msg := fnd_message.get;
7477 					x_msg_data := x_msg_data || l_msg;
7478 					x_msg_count := x_msg_count + 1;
7479 
7480 					l_err_msg                        :='Error in querying task from Query_task API for transaction_number :'||p_task_table(i).transaction_number ||'This task will be skipped';
7481 					IF(l_debug                        = 1) THEN
7482 						inv_trx_util_pub.trace(l_api_name|| ': '||l_err_msg);
7483 					END IF;
7484 					x_updated_tasks(i)        := l_updated_tasks(i);
7485 					x_updated_tasks(i).RESULT := 'E';
7486 					x_updated_tasks(i).ERROR  := l_msg;
7487 					l_valid_task_counter      := l_valid_task_counter - 1;
7488 				ELSE                                           --if query success
7489 					x_updated_tasks(i) := temp_task_tab(1);--assigning the queried results to output table
7490 				END IF;
7491 			ELSE
7492 				fnd_message.set_name('WMS', 'WMS_INVALID_TASK');
7493 --				fnd_msg_pub.ADD;
7494 --				fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_msg );
7495 				--anjana
7496 				l_msg := fnd_message.get;
7497 				x_msg_data := x_msg_data || l_msg;
7498 				x_msg_count := x_msg_count + 1;
7499 
7500 				x_updated_tasks(i)               := l_updated_tasks(i);
7501 				x_updated_tasks(i).RESULT        := 'E';
7502 				x_updated_tasks(i).ERROR         := l_msg;
7503 				l_valid_task_counter             := l_valid_task_counter - 1;
7504 			END IF;
7505 		END LOOP;--Loop ends
7506 	ELSE
7507 		x_return_status := fnd_api.g_ret_sts_unexp_error;
7508 		fnd_message.set_name('WMS', 'WMS_UNEXPECTED_ERROR');
7509 		fnd_msg_pub.ADD;
7510 		fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_msg );
7511 		x_msg_data := l_msg;
7512 		x_msg_count := l_msg_count;
7513 		--      l_err_msg :='Task Validation Failed';
7514 		IF(l_debug = 1) THEN
7515 			inv_trx_util_pub.trace(l_api_name|| ': '||l_msg);
7516 		END IF;
7517 		RETURN;
7518 	END IF;
7519 	IF (l_valid_task_counter <=0 ) THEN
7520 		--all the tasks are invalid.Dont proceed
7521 		--6850212:Return status should not be set to error.
7522 		--x_return_status := fnd_api.g_ret_sts_error;
7523 		RETURN;
7524 	END IF;
7525 	--Cartonization needs to be done only if all the tasks passed are valid and the task is an outboud task(SO/WIP)
7526 	IF (p_new_carton_lpn_id IS NOT NULL) THEN
7527 		IF (l_updated_tasks.count = l_valid_task_counter)THEN
7528 			FOR i         in 1..l_updated_tasks.count
7529 			LOOP
7530 				IF ((l_updated_tasks(1).task_type_id <> 1) OR (l_updated_tasks(i).task_type_id <> l_updated_tasks(1).task_type_id )) THEN
7531 					fnd_message.set_name('WMS', 'WMS_CARTONIZATION_ERROR');--new message
7532 					fnd_msg_pub.ADD;
7533 					fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => l_msg_count, p_data => l_msg );
7534 					l_err_msg                        :='Cartonization can be done only on Outbound tasks(Sales order/WIP)';
7535 					x_msg_data := l_msg;
7536 					x_msg_count := l_msg_count;
7537 					log_error(p_transaction_number    => p_transaction_number,
7538 						  p_task_table => l_updated_tasks,
7539 						  p_error_msg => l_msg,
7540 						  x_updated_tasks => x_updated_tasks);
7541 					RETURN;
7542 				END IF;
7543 			END LOOP;
7544 			check_cartonization(p_task_table => l_updated_tasks,
7545 					    p_new_carton_lpn_id => p_new_carton_lpn_id,
7546 					    x_error_msg => l_error_msg,
7547 					    x_return_status => p_return_sts);
7548 
7549 			IF (p_return_sts                <> fnd_api.g_ret_sts_success) THEN
7550 				x_return_status         := fnd_api.g_ret_sts_error;
7551 				fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data );
7552 				FOR i                   IN 1..l_updated_tasks.count
7553 				LOOP
7554 					x_updated_tasks(i).RESULT := 'E';
7555 					x_updated_tasks(i).ERROR  := l_error_msg;
7556 				END LOOP;
7557 				IF(l_debug = 1) THEN
7558 					inv_trx_util_pub.trace(l_api_name|| ': '||l_error_msg);
7559 				END IF;
7560 				RETURN;
7561 			END IF;
7562 		ELSE
7563 			x_return_status := fnd_api.g_ret_sts_error;
7564 			fnd_message.set_name('WMS', 'WMS_CARTONIZATION_ERROR');--new message
7565 			fnd_msg_pub.ADD;
7566 			fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data );
7567 			l_err_msg                        := 'Some tasks have failed validation,cartonization cannot be done';
7568 			IF(l_debug                        = 1) THEN
7569 				inv_trx_util_pub.trace(l_api_name|| ': '||l_err_msg);
7570 			END IF;
7571 			RETURN;
7572 		END IF;
7573 	END IF;
7574 	FOR i in 1..x_updated_tasks.count
7575 	LOOP
7576 		IF (nvl(x_updated_tasks(i).RESULT,'X')<> 'E') THEN
7577 			--Lock the mmtt/mcee record
7578 			BEGIN
7579 				IF (x_updated_tasks(i).task_type_id <> 3) THEN
7580 					OPEN c_lock_mmtt(x_updated_tasks(i).transaction_number);
7581 					FETCH c_lock_mmtt INTO l_lock;
7582 					CLOSE c_lock_mmtt;
7583 				ELSE
7584 					OPEN c_lock_mcce(x_updated_tasks(i).transaction_number);
7585 					FETCH c_lock_mcce INTO l_lock;
7586 					CLOSE c_lock_mcce;
7587 				END IF;
7588 			EXCEPTION
7589 			WHEN OTHERS THEN
7590 				l_err_msg                 := substr(SQLERRM,1,1000);
7591 				x_updated_tasks(i).RESULT := 'E';
7592 				x_updated_tasks(i).ERROR  := l_err_msg;
7593 				IF(l_debug                 = 1) THEN
7594 					inv_trx_util_pub.trace(l_api_name|| ': '||l_err_msg);
7595 				END IF;
7596 			END;
7597 			p_temp_task_rec              := x_updated_tasks(i);
7598 
7599 			modify_single_task(p_task_rec => p_temp_task_rec,
7600 					   p_new_task_status => p_new_task_status,
7601 					   P_new_task_priority => P_new_task_priority,
7602 					   P_new_task_type => P_new_task_type,
7603 					   P_new_carton_lpn_id => P_new_carton_lpn_id,
7604 					   p_new_operation_plan_id => p_new_operation_plan_id,
7605 					   p_output_task_rec => l_updated_tasks(i),
7606 					   p_op_plan_rec => l_op_plan_rec);
7607 
7608 			--Copy values from l_updated_tasks to x_updated_tasks
7609 			x_updated_tasks(i).RESULT            := nvl(l_updated_tasks(i).RESULT,x_updated_tasks(i).RESULT);
7610 			x_updated_tasks(i).ERROR             := nvl(l_updated_tasks(i).ERROR,x_updated_tasks(i).ERROR);
7611 			x_updated_tasks(i).status_id         := nvl(l_updated_tasks(i).status_id,x_updated_tasks(i).status_id);
7612 			x_updated_tasks(i).operation_plan_id := nvl(l_updated_tasks(i).operation_plan_id,x_updated_tasks(i).operation_plan_id);
7613 			x_updated_tasks(i).cartonization_id  := nvl(l_updated_tasks(i).cartonization_id,x_updated_tasks(i).cartonization_id);
7614 			x_updated_tasks(i).priority          := nvl(l_updated_tasks(i).priority,x_updated_tasks(i).priority);
7615 			x_updated_tasks(i).user_task_type_id := nvl(l_updated_tasks(i).user_task_type_id,x_updated_tasks(i).user_task_type_id);
7616 			--anjana
7617 			IF (nvl(x_updated_tasks(i).RESULT,'X') = 'E') THEN
7618 			  x_msg_count:= x_msg_count + 1;
7619 			  x_msg_data := x_msg_data || x_updated_tasks(i).ERROR ;
7620 			END IF;
7621 		END IF;
7622 	END LOOP;
7623 
7624 
7625 	FOR i IN 1..x_updated_tasks.count
7626         LOOP
7627               IF (nvl(x_updated_tasks(i).RESULT,'X')<> 'E') THEN
7628 		IF p_new_task_status = 2 THEN
7629 		  l_transaction_num_table(l_transaction_num_table.COUNT+1)		:= x_updated_tasks(i).transaction_number;
7630 		  l_organization_id_table(l_organization_id_table.COUNT+1)		:= x_updated_tasks(i).organization_id;
7631 		  l_usertask_type_id_table(l_usertask_type_id_table.COUNt+1)		:= x_updated_tasks(i).user_task_type_id;
7632 		  l_person_resource_id_tabe(l_person_resource_id_tabe.COUNt+1)		:= x_updated_tasks(i).person_resource_id;
7633 		  l_machine_resource_id_table(l_machine_resource_id_table.COUNT+1)	:= x_updated_tasks(i).machine_resource_id;
7634 		  l_status_id_table(l_status_id_table.COUNT+1)				:= x_updated_tasks(i).status_id;
7635 		  l_priority_table(l_priority_table.COUNT+1)				:= x_updated_tasks(i).priority;
7636 		  l_task_type_id_table(l_task_type_id_table.COUNT+1)			:= x_updated_tasks(i).task_type_id;
7637 		  l_move_order_line_id_table(l_move_order_line_id_table.COUNt+1)	:= x_updated_tasks(i).move_order_line_id;
7638 		  l_to_lpn_id_table(l_to_lpn_id_table.COUNT+1)				:= x_updated_tasks(i).to_lpn_id;
7639 		  l_operation_plan_id_table(l_operation_plan_id_table.COUNT+1)		:= x_updated_tasks(i).operation_plan_id;
7640 	--	  l_dispatched_time_table(l_dispatched_time_table.COUNt+1)		:= x_updated_tasks(i).dispatched_time;
7641 		END IF;
7642 		IF x_updated_tasks(i).task_type_id <> 3 then
7643                 --for inbound and outbound tasks,update mmtt
7644 		  l_mmtt_cartonization_id_table(l_mmtt_cartonization_id_table.COUNt+1)	:= x_updated_tasks(i).cartonization_id;
7645 		  l_mmtt_transaction_num_table(l_mmtt_transaction_num_table.COUNT+1)	:= x_updated_tasks(i).transaction_number;
7646 		  l_mmtt_usertask_type_id_table(l_mmtt_usertask_type_id_table.COUNt+1)	:= x_updated_tasks(i).user_task_type_id;
7647 		  l_mmtt_status_id_table(l_mmtt_status_id_table.COUNT+1)		:= x_updated_tasks(i).status_id;
7648 		  l_mmtt_priority_table(l_mmtt_priority_table.COUNT+1)			:= x_updated_tasks(i).priority;
7649 		  l_mmtt_operation_plan_id_table(l_mmtt_operation_plan_id_table.COUNT+1):= x_updated_tasks(i).operation_plan_id;
7650 		ELSE
7651  		  l_mcce_transaction_num_table(l_mcce_transaction_num_table.COUNT+1)	:= x_updated_tasks(i).transaction_number;
7652 		  l_mcce_usertask_type_id_table(l_mcce_usertask_type_id_table.COUNt+1)	:= x_updated_tasks(i).user_task_type_id;
7653 		  l_mcce_priority_table(l_mcce_priority_table.COUNT+1)			:= x_updated_tasks(i).priority;
7654 		END IF;
7655 
7656 		--If the x_updated_tasks(i).status_id is 2 ,then update wdt also.
7657                 --wdt does not have cartonization_id.
7658                 --Also this needs to be done only if wdt was existing before.
7659                 IF (x_updated_tasks(i).status_id = 2 AND (nvl(p_new_task_status,-99) <> 2) )THEN
7660 		  l_wdt_transaction_num_table(l_wdt_transaction_num_table.COUNT+1)	:= x_updated_tasks(i).transaction_number;
7661 		  l_wdt_usertask_type_id_table(l_wdt_usertask_type_id_table.COUNt+1)	:= x_updated_tasks(i).user_task_type_id;
7662 		  l_wdt_status_id_table(l_wdt_status_id_table.COUNT+1)			:= x_updated_tasks(i).status_id;
7663 		  l_wdt_priority_table(l_wdt_priority_table.COUNT+1)			:= x_updated_tasks(i).priority;
7664 		  l_wdt_operation_plan_id_table(l_wdt_operation_plan_id_table.COUNT+1)	:= x_updated_tasks(i).operation_plan_id;
7665 		END IF;
7666 
7667 		IF (nvl(p_new_task_status,-99) in (1,8)) THEN
7668 		  l_wdt_del_trns_num_table(l_wdt_del_trns_num_table.COUNT+1)	:= x_updated_tasks(i).transaction_number;
7669 		END IF;
7670 
7671 	      END IF;
7672 	END LOOP;
7673 
7674         --Do BULK INSERT,UPDATE
7675 	IF (l_transaction_num_table.COUNT > 0) THEN
7676 	  FORALL i in 1..l_transaction_num_table.COUNT
7677 	  INSERT
7678 	  INTO    wms_dispatched_tasks
7679 	  (
7680 		task_id             ,
7681 		transaction_temp_id ,
7682 		organization_id     ,
7683 		user_task_type      ,
7684 		person_id           ,
7685 		effective_start_date,
7686 		effective_end_date  ,
7687 		person_resource_id  ,
7688 		machine_resource_id ,
7689 		status              ,
7690 		dispatched_time     ,
7691 		last_update_date    ,
7692 		last_updated_by     ,
7693 		creation_date       ,
7694 		created_by          ,
7695 		task_type           ,
7696 		priority            ,
7697 		move_order_line_id  ,
7698 		operation_plan_id   ,
7699 		transfer_lpn_id
7700 	  )
7701 	  VALUES
7702 	  (
7703 		wms_dispatched_tasks_s.NEXTVAL		,
7704 		l_transaction_num_table(i)		,
7705 		l_organization_id_table(i)		,
7706 		l_usertask_type_id_table(i)		,
7707 		p_person_id				,
7708 		sysdate					,
7709 		sysdate					,
7710 		l_person_resource_id_tabe(i)		,
7711 		l_machine_resource_id_table(i)		,
7712 		l_status_id_table(i)			,
7713 		sysdate					,
7714 		sysdate					,
7715 		FND_GLOBAL.USER_ID			,
7716 		sysdate					,
7717 		FND_GLOBAL.USER_ID			,
7718 		l_task_type_id_table(i)			,
7719 		l_priority_table(i)			,
7720 		l_move_order_line_id_table(i)		,
7721 		l_operation_plan_id_table(i)		,
7722 		l_to_lpn_id_table(i)			);
7723 	END IF;
7724 
7725 	IF (l_mmtt_transaction_num_table.COUNT > 0) THEN
7726   	  FORALL i in 1..l_mmtt_transaction_num_table.COUNT
7727 	  UPDATE mtl_material_transactions_temp
7728 	  SET    wms_task_status       = l_mmtt_status_id_table(i)       ,
7729 	  	 operation_plan_id     = l_mmtt_operation_plan_id_table(i),
7730 		 cartonization_id      = l_mmtt_cartonization_id_table(i) ,
7731 		 task_priority         = l_mmtt_priority_table(i)         ,
7732 		 standard_operation_id = l_mmtt_usertask_type_id_table(i)
7733 	  WHERE  transaction_temp_id   = l_mmtt_transaction_num_table(i);
7734 	END IF;
7735 
7736 	IF (l_mcce_transaction_num_table.COUNT > 0) THEN
7737 	  FORALL i in 1..l_mcce_transaction_num_table.COUNT
7738 	   UPDATE mtl_cycle_count_entries
7739 	   SET    task_priority         = l_mcce_priority_table(i)         ,
7740 		  standard_operation_id = l_mcce_usertask_type_id_table(i)
7741 	   WHERE  cycle_count_entry_id  = l_mcce_transaction_num_table(i);
7742 	END IF;
7743 
7744 	IF (l_wdt_transaction_num_table.COUNT > 0) THEN
7745 	  FORALL i in 1..l_wdt_transaction_num_table.COUNT
7746 	  UPDATE wms_dispatched_tasks
7747 	  SET    status		       = l_wdt_status_id_table(i)       ,
7748 		 operation_plan_id     = l_wdt_operation_plan_id_table(i),
7749 		 priority	       = l_wdt_priority_table(i)         ,
7750 		 user_task_type        = l_wdt_usertask_type_id_table(i)
7751 	  WHERE  transaction_temp_id   = l_wdt_transaction_num_table(i);
7752 	END IF;
7753 
7754 	IF (l_wdt_del_trns_num_table.COUNT > 0) THEN
7755 	  FORALL i in 1..l_wdt_del_trns_num_table.COUNT
7756 	  DELETE from wms_dispatched_tasks
7757 	  WHERE  transaction_temp_id   = l_wdt_del_trns_num_table(i);
7758 	END IF;
7759 
7760         IF (p_commit = FND_API.G_TRUE) THEN
7761                 COMMIT;
7762         END IF;
7763 EXCEPTION
7764 WHEN OTHERS THEN
7765         x_return_status                  := fnd_api.g_ret_sts_unexp_error;
7766         fnd_msg_pub.count_and_get(p_encoded => FND_API.G_FALSE,p_count => x_msg_count, p_data => x_msg_data);
7767         l_err_msg                        := substr(SQLERRM,1,1000);
7768         IF(l_debug                        = 1) THEN
7769                 inv_trx_util_pub.trace(l_api_name|| ': '||l_err_msg);
7770         END IF;
7771 
7772 END modify_task;
7773 
7774 -------------------------------------------------------------------------------------------------------------
7775 
7776 /*This Public API takes care of cancelling a single or a set of crossdock tasks.
7777 
7778 PROCEDURE cancel_task (p_transaction_number     IN                         	NUMBER DEFAULT  NULL
7779 		   , p_task_table           	IN                         	WMS_TASKS_PUB.TASK_TABLE
7780 		   , p_commit               	IN                         	VARCHAR2  DEFAULT  G_FALSE
7781 		   , x_undeleted_tasks  	OUT 	NOCOPY   	WMS_TASKS_PUB.TASK_TABLE
7782 		   , x_unprocessed_crossdock_tasks
7783 						OUT 	NOCOPY   	WMS_TASKS_PUB.TASK_TABLE
7784 		   , x_return_status       	OUT 	NOCOPY   	VARCHAR2
7785 		   , x_msg_count          	OUT 	NOCOPY   	NUMBER
7786 		   , x_msg_data            	OUT 	NOCOPY  	VARCHAR2  );
7787 
7788 
7789 Parameter		Description
7790 
7791 p_transaction_number	This corrsponds to the task_id that user is trying to cancel
7792 P_task_table		This correspinds to the set of tasks that user is trying to cancel
7793 P_Commit		This parameter decides whether to commit the changes or not.
7794 X_unprocessed_crossdockdeleted_tasks
7795 			This parameter contains the set of tasks that could not be cancelled.
7796 X_return_status		This parameter gives the return status of cancel_task API. 	'S' = Success, 'U' = Unexpected Error, 'E' = Error.
7797 X_msg_count		This gives the count of messages logged during the task deletion process.
7798 X_msg_data		This gives the descrption of the messages that got logged during the task deletion process.
7799 */
7800 -------------------------------------------------------------------------------------------------------------
7801 
7802 PROCEDURE cancel_task(
7803    p_transaction_number            IN              NUMBER DEFAULT NULL,
7804    p_commit                        IN              VARCHAR2 DEFAULT fnd_api.g_false,
7805    p_wms_task                      IN              WMS_TASK_MGMT_PUB.task_tab_type,
7806    x_unprocessed_crossdock_tasks   OUT NOCOPY      WMS_TASK_MGMT_PUB.task_tab_type,
7807    x_return_status                 OUT NOCOPY      VARCHAR2,
7808    x_msg_count                     OUT NOCOPY      NUMBER,
7809    x_msg_data                      OUT NOCOPY      VARCHAR2
7810 )
7811 IS
7812 
7813    l_val_ret_status    VARCHAR2(10) ;
7814    l_task_table WMS_TASK_MGMT_PUB.task_tab_type ;
7815    l_transaction_number NUMBER ;
7816    l_ret_task_table  WMS_TASK_MGMT_PUB.task_tab_type;
7817    l_debug     NUMBER         := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7818    l_unprocessed_crossdock_count     NUMBER         := 1;
7819    l_msg		VARCHAR2(2000);
7820 
7821 BEGIN
7822 
7823    x_return_status := fnd_api.g_ret_sts_success;
7824    --anjana
7825    x_msg_count := 0;
7826    l_transaction_number:= p_transaction_number ;
7827    l_task_table        := p_wms_task;
7828 
7829 
7830    IF l_debug = 1 THEN
7831       inv_trx_util_pub.trace('CANCEL_TASK: Enter...');
7832    END IF;
7833 
7834    WMS_TASK_MGMT_PUB.validate_tasks( p_transaction_number => l_transaction_number ,
7835 				     p_task_table => l_task_table ,
7836 				     x_wms_task => l_ret_task_table ,
7837 				     x_return_status => l_val_ret_status );
7838    IF l_debug = 1 THEN
7839     inv_trx_util_pub.trace('cancel_task l_val_ret_status is : '||l_val_ret_status);
7840    END IF;
7841 
7842    IF (l_val_ret_status = fnd_api.g_ret_sts_success) THEN
7843       IF l_debug = 1 THEN
7844 	      inv_trx_util_pub.trace('l_ret_task_table.count :   '||l_ret_task_table.count);
7845       END IF;
7846 
7847       FOR i in 1..l_ret_task_table.count LOOP
7848          IF l_debug = 1 THEN
7849 	         inv_trx_util_pub.trace('cancel_task l_ret_task_table(i).RESULT    '||l_ret_task_table(i).RESULT);
7850          END IF;
7851          IF ( nvl(l_ret_task_table(i).RESULT,'X')<> FND_API.G_RET_STS_ERROR)THEN
7852             IF l_debug = 1 THEN
7853 		    inv_trx_util_pub.trace('cancel_task transaction_number    '||l_ret_task_table(i).transaction_number);
7854 	    END IF;
7855             SAVEPOINT SAVEPOINT1;
7856             WMS_CROSS_DOCK_PVT.cancel_crossdock_task(p_transaction_temp_id => l_ret_task_table(i).transaction_number
7857          				            ,x_return_status => x_return_status
7858 				                    ,x_msg_data => x_msg_data
7859 				                    ,x_msg_count => x_msg_count);
7860             IF l_debug = 1 THEN
7861 		    inv_trx_util_pub.trace('cancel_task CANCEL_TASK: x_return_status: ' || x_return_status);
7862 	    END IF;
7863 
7864 	    IF (x_return_status<>FND_API.G_RET_STS_SUCCESS) THEN
7865     		FND_MESSAGE.SET_NAME('WMS', 'WMS_CANCEL_FAILED');
7866 		l_msg := fnd_message.get;
7867 		x_msg_count := x_msg_count + 1;
7868 		x_msg_data := x_msg_data || l_msg;
7869 
7870 		x_unprocessed_crossdock_tasks(l_unprocessed_crossdock_count).transaction_number := l_transaction_number;
7871 	        x_unprocessed_crossdock_tasks(l_unprocessed_crossdock_count).result             := x_return_status;
7872  	        x_unprocessed_crossdock_tasks(l_unprocessed_crossdock_count).error              := l_msg;
7873                 l_unprocessed_crossdock_count							:=l_unprocessed_crossdock_count+1;
7874 	        ROLLBACK TO SAVEPOINT1;
7875             END IF;
7876          ELSE
7877 	    FND_MESSAGE.SET_NAME('WMS', 'WMS_INVALID_TASK');
7878 	    l_msg := fnd_message.get;
7879 	    x_msg_count := x_msg_count + 1;
7880 	    x_msg_data := x_msg_data || l_msg;
7881             IF l_debug = 1 THEN
7882 		    inv_trx_util_pub.trace('Validate_task returned error for this record');
7883 	    END IF;
7884             x_unprocessed_crossdock_tasks(l_unprocessed_crossdock_count).transaction_number := l_transaction_number;
7885 	    x_unprocessed_crossdock_tasks(l_unprocessed_crossdock_count).result             := l_ret_task_table(i).RESULT;
7886  	    x_unprocessed_crossdock_tasks(l_unprocessed_crossdock_count).error              := l_msg;
7887             l_unprocessed_crossdock_count						    := l_unprocessed_crossdock_count+1;
7888 	 END IF;
7889       END LOOP;
7890       IF l_debug = 1 THEN
7891 	inv_trx_util_pub.trace('CANCEL_TASK: x_unprocessed_crossdock_tasks: ' || x_unprocessed_crossdock_tasks.count);
7892 	inv_trx_util_pub.trace('CANCEL_TASK: Exiting...');
7893       END IF;
7894     ELSE
7895       IF l_debug = 1 THEN
7896         inv_trx_util_pub.trace('CANCEL_TASK: Error occured while validating the transaction_number or table of transaction_number...');
7897       END IF;
7898       x_return_status:=FND_API.G_RET_STS_UNEXP_ERROR;
7899       RETURN;
7900     END IF;
7901 
7902     IF (p_commit= FND_API.G_TRUE ) THEN
7903        COMMIT;
7904     END IF;
7905 EXCEPTION
7906   WHEN fnd_api.g_exc_error  THEN
7907       IF l_debug = 1 THEN
7908         inv_trx_util_pub.trace('CANCEL_TASK: Expected Error occurred while performing cancel cross dock task:'|| SQLCODE);
7909       END IF;
7910       x_return_status:=FND_API.G_RET_STS_ERROR;
7911       ROLLBACK TO SAVEPOINT1;
7912       RETURN;
7913   WHEN OTHERS  THEN
7914       IF l_debug = 1 THEN
7915         inv_trx_util_pub.trace('CANCEL_TASK: Unknown Error occurred while performing cancel cross dock task:'|| SQLCODE);
7916       END IF;
7917       x_return_status:=FND_API.G_RET_STS_UNEXP_ERROR;
7918       ROLLBACK TO SAVEPOINT1;
7919       RETURN;
7920 END cancel_task;
7921 
7922 END WMS_TASK_MGMT_PUB;