DBA Data[Home] [Help]

PACKAGE BODY: APPS.WSH_SHIP_CONFIRM_ACTIONS

Source


1 PACKAGE BODY WSH_SHIP_CONFIRM_ACTIONS as
2 /* $Header: WSHDDSHB.pls 120.35.12020000.7 2013/05/21 13:07:46 sunilku ship $ */
3 
4 c_inv_int_partial CONSTANT VARCHAR2(1) := 'P';
5 c_inv_int_full   CONSTANT VARCHAR2(1) := 'Y';
6 
7 --Global Variables added for bug 4538005
8    g_prv_from_location      NUMBER;
9    g_prv_customer_site_id   NUMBER;
10    g_intransit_time         NUMBER;
11    g_prv_ship_method_code   VARCHAR2(30);
12 --
13 
14 G_PKG_NAME CONSTANT VARCHAR2(50) := 'WSH_SHIP_CONFIRM_ACTIONS';
15 --
16 
17 -- Bug 3628620
18 -- Old Procedure transfer_serial_numbers is modified to be a wrapper
19 -- on top of transfer_serial_numbers_pvt
20 
21 --========================================================================
22 -- PROCEDURE : transfer_serial_numbers_pvt
23 --             Transfers Serial Numbers from mtl_serial_numbers_temp to
24 --             wsh_serial_numbers and this will be used to display the
25 --             Serial Numbers shipped from the Shipping Transactions Form
26 --
27 -- PARAMETERS: p_transfer_param        Input Parameter for this API
28 --                                     Values can be WDD or MSNT
29 --             p_batch_id              The batch id of trip stops being
30 --                                     interfaced.
31 --             p_interfacing           if this procedure is called during OM
32 --                                     interface value 'OM' is passed, otherwise
33 --                                     value 'INV' is passed.
34 --             x_return_status         return status of the API.
35 
36 -- COMMENT   : This procedure is used to transfer the serial number information
37 --             from mtl_serial_numbers_temp to the wsh_serial_numbers table.
38 --             It then deletes these entries from mtl_serial_numbers_temp.
39 --             IF this procedure is called during the INV interface then only
40 --             the lines that have been interfaced to OM are processed, else
41 --             the non-oe lines are processed as well.
42 --========================================================================
43 
44 PROCEDURE transfer_serial_numbers_pvt (
45             p_transfer_param   IN VARCHAR2,
46             p_batch_id       IN  NUMBER,
47             p_interfacing    IN VARCHAR2,
48             x_return_status OUT NOCOPY VARCHAR2) IS
49 
50   CURSOR dd_msnt_rec  IS
51   select dd.delivery_detail_id, dd.transaction_temp_id,
52          to_number(msnt.serial_prefix) "quantity",
53          msnt.fm_serial_number, msnt.to_serial_number,
54          msnt.attribute_category, -- Bug 3628620
55          msnt.attribute1,
56          msnt.attribute2,
57          msnt.attribute3,
58          msnt.attribute4,
59          msnt.attribute5,
60          msnt.attribute6,
61          msnt.attribute7,
62          msnt.attribute8,
63          msnt.attribute9,
64          msnt.attribute10,
65          msnt.attribute11,
66          msnt.attribute12,
67          msnt.attribute13,
68          msnt.attribute14,
69          msnt.attribute15,   -- End of Bug 3628620
70          dd.inventory_item_id, -- 3704188
71          --Bug 8467875
72          msnt.cycles_since_mark,
73          msnt.cycles_since_new,
74          msnt.cycles_since_overhaul,
75          msnt.cycles_since_repair,
76          msnt.cycles_since_visit,
77          msnt.c_attribute1,
78          msnt.c_attribute10,
79          msnt.c_attribute11,
80          msnt.c_attribute12,
81          msnt.c_attribute13,
82          msnt.c_attribute14,
83          msnt.c_attribute15,
84          msnt.c_attribute16,
85          msnt.c_attribute17,
86          msnt.c_attribute18,
87          msnt.c_attribute19,
88          msnt.c_attribute2,
89          msnt.c_attribute20,
90          msnt.c_attribute3,
91          msnt.c_attribute4,
92          msnt.c_attribute5,
93          msnt.c_attribute6,
94          msnt.c_attribute7,
95          msnt.c_attribute8,
96          msnt.c_attribute9,
97          msnt.d_attribute1,
98          msnt.d_attribute10,
99          msnt.d_attribute2,
100          msnt.d_attribute3,
101          msnt.d_attribute4,
102          msnt.d_attribute5,
103          msnt.d_attribute6,
104          msnt.d_attribute7,
105          msnt.d_attribute8,
106          msnt.d_attribute9,
107          msnt.number_of_repairs,
108          msnt.n_attribute1,
109          msnt.n_attribute10,
110          msnt.n_attribute2,
111          msnt.n_attribute3,
112          msnt.n_attribute4,
113          msnt.n_attribute5,
114          msnt.n_attribute6,
115          msnt.n_attribute7,
116          msnt.n_attribute8,
117          msnt.n_attribute9,
118          msnt.territory_code,
119          msnt.time_since_mark,
120          msnt.time_since_new,
121          msnt.time_since_overhaul,
122          msnt.time_since_repair,
123          msnt.time_since_visit,
124          msnt.serial_attribute_category
125          --Bug 8467875
126   from   wsh_delivery_details dd,
127          wsh_delivery_assignments_v da,
128          wsh_delivery_legs dg,
129          wsh_new_deliveries dl,
130          wsh_trip_stops st,
131          mtl_serial_numbers_temp msnt
132   where  st.batch_id = p_batch_id
133   and    st.stop_location_id = dl.initial_pickup_location_id
134   and    dg.delivery_id = dl.delivery_id
135   and    da.delivery_id = dl.delivery_id
136   and    dd.delivery_detail_id = da.delivery_detail_id
137   -- bug 2787888 : removed oe_interfaced_flag and source_code comparison for OKE lines
138   and    st.stop_id = dg.pick_up_stop_id
139   and    dd.released_status = 'C'
140   and    dd.container_flag='N'
141   and    dd.transaction_temp_id = msnt.transaction_temp_id
142 --  and    msnt.fm_serial_number <> nvl(msnt.to_serial_number, msnt.fm_serial_number)
143   and    nvl(dl.shipment_direction , 'O') IN ('O', 'IO');   -- J Inbound Logistics jckwok
144 
145   CURSOR dd_msnt_rec_om  IS
146   select dd.delivery_detail_id, dd.transaction_temp_id,
147          to_number(msnt.serial_prefix) "quantity",
148          msnt.fm_serial_number, msnt.to_serial_number,
149          msnt.attribute_category, -- Bug 3628620
150          msnt.attribute1,
151          msnt.attribute2,
152          msnt.attribute3,
153          msnt.attribute4,
154          msnt.attribute5,
155          msnt.attribute6,
156          msnt.attribute7,
157          msnt.attribute8,
158          msnt.attribute9,
159          msnt.attribute10,
160          msnt.attribute11,
161          msnt.attribute12,
162          msnt.attribute13,
163          msnt.attribute14,
164          msnt.attribute15,   -- End of Bug 3628620
165          dd.inventory_item_id,-- 3704188
166          --Bug 8467875
167          msnt.cycles_since_mark,
168          msnt.cycles_since_new,
169          msnt.cycles_since_overhaul,
170          msnt.cycles_since_repair,
171          msnt.cycles_since_visit,
172          msnt.c_attribute1,
173          msnt.c_attribute10,
174          msnt.c_attribute11,
175          msnt.c_attribute12,
176          msnt.c_attribute13,
177          msnt.c_attribute14,
178          msnt.c_attribute15,
179          msnt.c_attribute16,
180          msnt.c_attribute17,
181          msnt.c_attribute18,
182          msnt.c_attribute19,
183          msnt.c_attribute2,
184          msnt.c_attribute20,
185          msnt.c_attribute3,
186          msnt.c_attribute4,
187          msnt.c_attribute5,
188          msnt.c_attribute6,
189          msnt.c_attribute7,
190          msnt.c_attribute8,
191          msnt.c_attribute9,
192          msnt.d_attribute1,
193          msnt.d_attribute10,
194          msnt.d_attribute2,
195          msnt.d_attribute3,
196          msnt.d_attribute4,
197          msnt.d_attribute5,
198          msnt.d_attribute6,
199          msnt.d_attribute7,
200          msnt.d_attribute8,
201          msnt.d_attribute9,
202          msnt.number_of_repairs,
203          msnt.n_attribute1,
204          msnt.n_attribute10,
205          msnt.n_attribute2,
206          msnt.n_attribute3,
207          msnt.n_attribute4,
208          msnt.n_attribute5,
209          msnt.n_attribute6,
210          msnt.n_attribute7,
211          msnt.n_attribute8,
212          msnt.n_attribute9,
213          msnt.territory_code,
214          msnt.time_since_mark,
215          msnt.time_since_new,
216          msnt.time_since_overhaul,
217          msnt.time_since_repair,
218          msnt.time_since_visit,
219          msnt.serial_attribute_category
220          --Bug 8467875
221   from   wsh_delivery_details dd,
222          wsh_delivery_assignments_v da,
223          wsh_delivery_legs dg,
224          wsh_new_deliveries dl,
225          wsh_trip_stops st,
226          mtl_serial_numbers_temp msnt
227   where  st.batch_id = p_batch_id
228   and    st.stop_location_id = dl.initial_pickup_location_id
229   and    dg.delivery_id = dl.delivery_id
230   and    da.delivery_id = dl.delivery_id
231   and    dd.delivery_detail_id = da.delivery_detail_id
232   and    st.stop_id = dg.pick_up_stop_id
233   and    dd.released_status = 'C'
234   and    dd.container_flag='N'
235   and    NVL(dd.oe_interfaced_flag , 'N') = 'Y'
236   and    dd.transaction_temp_id = msnt.transaction_temp_id
237 --  and    msnt.fm_serial_number <> nvl(msnt.to_serial_number, msnt.fm_serial_number)
238   and    nvl(dl.shipment_direction , 'O') IN ('O', 'IO');
239 
240   CURSOR dd_wdd_rec  IS
241   select dd.delivery_detail_id, msn.group_mark_id,
242          dd.shipped_quantity "quantity",
243          dd.serial_number, dd.serial_number "to_serial_number",
244          msn.attribute_category, -- Bug 3628620
245          msn.attribute1,
246          msn.attribute2,
247          msn.attribute3,
248          msn.attribute4,
249          msn.attribute5,
250          msn.attribute6,
251          msn.attribute7,
252          msn.attribute8,
253          msn.attribute9,
254          msn.attribute10,
255          msn.attribute11,
256          msn.attribute12,
257          msn.attribute13,
258          msn.attribute14,
259          msn.attribute15,   -- End of Bug 3628620
260          dd.inventory_item_id, -- 3704188
261          --Bug 8467875
262          msn.cycles_since_mark,
263          msn.cycles_since_new,
264          msn.cycles_since_overhaul,
265          msn.cycles_since_repair,
266          msn.cycles_since_visit,
267          msn.c_attribute1,
268          msn.c_attribute10,
269          msn.c_attribute11,
270          msn.c_attribute12,
271          msn.c_attribute13,
272          msn.c_attribute14,
273          msn.c_attribute15,
274          msn.c_attribute16,
275          msn.c_attribute17,
276          msn.c_attribute18,
277          msn.c_attribute19,
278          msn.c_attribute2,
279          msn.c_attribute20,
280          msn.c_attribute3,
281          msn.c_attribute4,
282          msn.c_attribute5,
283          msn.c_attribute6,
284          msn.c_attribute7,
285          msn.c_attribute8,
286          msn.c_attribute9,
287          msn.d_attribute1,
288          msn.d_attribute10,
289          msn.d_attribute2,
290          msn.d_attribute3,
291          msn.d_attribute4,
292          msn.d_attribute5,
293          msn.d_attribute6,
294          msn.d_attribute7,
295          msn.d_attribute8,
296          msn.d_attribute9,
297          msn.number_of_repairs,
298          msn.n_attribute1,
299          msn.n_attribute10,
300          msn.n_attribute2,
301          msn.n_attribute3,
302          msn.n_attribute4,
303          msn.n_attribute5,
304          msn.n_attribute6,
305          msn.n_attribute7,
306          msn.n_attribute8,
307          msn.n_attribute9,
308          msn.territory_code,
309          msn.time_since_mark,
310          msn.time_since_new,
311          msn.time_since_overhaul,
312          msn.time_since_repair,
313          msn.time_since_visit,
314          msn.serial_attribute_category
315          --Bug 8467875
316   from   wsh_delivery_details dd,
317          wsh_delivery_assignments_v da,
318          wsh_delivery_legs dg,
319          wsh_new_deliveries dl,
320          wsh_trip_stops st,
321          mtl_serial_numbers msn
322   where  st.batch_id = p_batch_id
323   and    st.stop_location_id = dl.initial_pickup_location_id
324   and    dg.delivery_id = dl.delivery_id
325   and    da.delivery_id = dl.delivery_id
326   and    dd.delivery_detail_id = da.delivery_detail_id
327   -- bug 2787888 : removed oe_interfaced_flag and source_code comparison for OKE lines
328   and    st.stop_id = dg.pick_up_stop_id
329   and    dd.released_status = 'C'
330   and    dd.container_flag='N'
331   and    dd.serial_number = msn.serial_number
332   and    dd.inventory_item_id = msn.inventory_item_id -- bug 3704188: part of mtl_serial_numbers_u1
333   and    nvl(dl.shipment_direction , 'O') IN ('O', 'IO');   -- J Inbound Logistics jckwok
334 
335   CURSOR dd_wdd_rec_om  IS
336   select dd.delivery_detail_id, msn.group_mark_id,
337          dd.shipped_quantity "quantity",
338          dd.serial_number, dd.serial_number "to_serial_number",
339          msn.attribute_category, -- Bug 3628620
340          msn.attribute1,
341          msn.attribute2,
342          msn.attribute3,
343          msn.attribute4,
344          msn.attribute5,
345          msn.attribute6,
346          msn.attribute7,
347          msn.attribute8,
348          msn.attribute9,
349          msn.attribute10,
350          msn.attribute11,
351          msn.attribute12,
352          msn.attribute13,
353          msn.attribute14,
354          msn.attribute15,   -- End of Bug 3628620
355          dd.inventory_item_id, -- 3704188
356          --Bug 8467875
357          msn.cycles_since_mark,
358          msn.cycles_since_new,
359          msn.cycles_since_overhaul,
360          msn.cycles_since_repair,
361          msn.cycles_since_visit,
362          msn.c_attribute1,
363          msn.c_attribute10,
364          msn.c_attribute11,
365          msn.c_attribute12,
366          msn.c_attribute13,
367          msn.c_attribute14,
368          msn.c_attribute15,
369          msn.c_attribute16,
370          msn.c_attribute17,
371          msn.c_attribute18,
372          msn.c_attribute19,
373          msn.c_attribute2,
374          msn.c_attribute20,
375          msn.c_attribute3,
376          msn.c_attribute4,
377          msn.c_attribute5,
378          msn.c_attribute6,
379          msn.c_attribute7,
380          msn.c_attribute8,
381          msn.c_attribute9,
382          msn.d_attribute1,
383          msn.d_attribute10,
384          msn.d_attribute2,
385          msn.d_attribute3,
386          msn.d_attribute4,
387          msn.d_attribute5,
388          msn.d_attribute6,
389          msn.d_attribute7,
390          msn.d_attribute8,
391          msn.d_attribute9,
392          msn.number_of_repairs,
393          msn.n_attribute1,
394          msn.n_attribute10,
395          msn.n_attribute2,
396          msn.n_attribute3,
397          msn.n_attribute4,
398          msn.n_attribute5,
399          msn.n_attribute6,
400          msn.n_attribute7,
401          msn.n_attribute8,
402          msn.n_attribute9,
403          msn.territory_code,
404          msn.time_since_mark,
405          msn.time_since_new,
406          msn.time_since_overhaul,
407          msn.time_since_repair,
408          msn.time_since_visit,
409          msn.serial_attribute_category
410          --Bug 8467875
411   from   wsh_delivery_details dd,
412          wsh_delivery_assignments_v da,
413          wsh_delivery_legs dg,
414          wsh_new_deliveries dl,
415          wsh_trip_stops st,
416          mtl_serial_numbers msn
417   where  st.batch_id = p_batch_id
418   and    st.stop_location_id = dl.initial_pickup_location_id
419   and    dg.delivery_id = dl.delivery_id
420   and    da.delivery_id = dl.delivery_id
421   and    dd.delivery_detail_id = da.delivery_detail_id
422   and    st.stop_id = dg.pick_up_stop_id
423   and    dd.released_status = 'C'
424   and    dd.container_flag='N'
425   and    NVL(dd.oe_interfaced_flag , 'N') = 'Y'
426   and    dd.serial_number = msn.serial_number
427   and    dd.inventory_item_id = msn.inventory_item_id -- bug 3704188: part of mtl_serial_numbers_u1
428   and    nvl(dl.shipment_direction , 'O') IN ('O', 'IO');
429 
430   CURSOR c_get_attr_msn (x_serial_number VARCHAR2,
431                          x_inventory_item_id NUMBER) IS
432   select msn.attribute1,
433          msn.attribute2,
434          msn.attribute3,
435          msn.attribute4,
436          msn.attribute5,
437          msn.attribute6,
438          msn.attribute7,
439          msn.attribute8,
440          msn.attribute9,
441          msn.attribute10,
442          msn.attribute11,
443          msn.attribute12,
444          msn.attribute13,
445          msn.attribute14,
446          msn.attribute15
447   from   mtl_serial_numbers msn
448   where  msn.serial_number = x_serial_number
449   and    msn.inventory_item_id = x_inventory_item_id -- bug 3704188: part of mtl_serial_numbers_u1
450   ;
451 
452   TYPE t_delivery_detail_id  IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
453   TYPE t_transaction_temp_id IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
454   TYPE t_quantity            IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
455   TYPE t_inv_item_id         IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
456   TYPE t_fm_serial_number    IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
457   TYPE t_to_serial_number    IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
458   -- Bug 3628620
459   TYPE t_attribute_category  IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
460   TYPE t_attribute1          IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
461   TYPE t_attribute2          IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
462   TYPE t_attribute3          IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
463   TYPE t_attribute4          IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
464   TYPE t_attribute5          IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
465   TYPE t_attribute6          IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
466   TYPE t_attribute7          IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
467   TYPE t_attribute8          IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
468   TYPE t_attribute9          IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
469   TYPE t_attribute10         IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
470   TYPE t_attribute11         IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
471   TYPE t_attribute12         IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
472   TYPE t_attribute13         IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
473   TYPE t_attribute14         IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
474   TYPE t_attribute15         IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
475   -- End of Bug 3628620
476   -- Bug 8467875
477   TYPE t_attribute16         IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
478   TYPE t_attribute17         IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
479   TYPE t_attribute18         IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
480   TYPE t_attribute19         IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
481   TYPE t_attribute20         IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
482   TYPE t_territory_code      IS TABLE OF VARCHAR2(30)  INDEX BY BINARY_INTEGER;
483   TYPE t_serial_attribute_category IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
484   TYPE t_cycles_since_mark 	IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
485   TYPE t_cycles_since_new 		IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
486   TYPE t_cycles_since_overhaul IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
487   TYPE t_cycles_since_repair 	IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
488   TYPE t_cycles_since_visit 	IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
489   TYPE t_number_of_repairs 	IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
490   TYPE t_n_attribute1 			IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
491   TYPE t_n_attribute10 			IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
492   TYPE t_n_attribute2 			IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
493   TYPE t_n_attribute3 			IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
494   TYPE t_n_attribute4 			IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
495   TYPE t_n_attribute5 			IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
496   TYPE t_n_attribute6 			IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
497   TYPE t_n_attribute7 			IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
498   TYPE t_n_attribute8 			IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
499   TYPE t_n_attribute9 			IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
500   TYPE t_time_since_mark 		IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
501   TYPE t_time_since_new 		IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
502   TYPE t_time_since_overhaul 	IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
503   TYPE t_time_since_repair 	IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
504   TYPE t_time_since_visit 		IS TABLE OF NUMBER       INDEX BY BINARY_INTEGER;
505   TYPE t_d_attribute1  		 	IS TABLE OF DATE         INDEX BY BINARY_INTEGER;
506   TYPE t_d_attribute10 		 	IS TABLE OF DATE         INDEX BY BINARY_INTEGER;
507   TYPE t_d_attribute2 	 		IS TABLE OF DATE         INDEX BY BINARY_INTEGER;
508   TYPE t_d_attribute3 	 		IS TABLE OF DATE         INDEX BY BINARY_INTEGER;
509   TYPE t_d_attribute4 	 		IS TABLE OF DATE         INDEX BY BINARY_INTEGER;
510   TYPE t_d_attribute5 	 		IS TABLE OF DATE         INDEX BY BINARY_INTEGER;
511   TYPE t_d_attribute6 	 		IS TABLE OF DATE         INDEX BY BINARY_INTEGER;
512   TYPE t_d_attribute7 	 		IS TABLE OF DATE         INDEX BY BINARY_INTEGER;
513   TYPE t_d_attribute8 	 		IS TABLE OF DATE         INDEX BY BINARY_INTEGER;
514   TYPE t_d_attribute9 	 		IS TABLE OF DATE         INDEX BY BINARY_INTEGER;
515   -- Bug 8467875
516   -- Bug 8467875
517   l_serial_attribute_category   t_serial_attribute_category ;
518   l_c_attribute1           t_attribute1;
519   l_c_attribute2           t_attribute2;
520   l_c_attribute3           t_attribute3;
521   l_c_attribute4           t_attribute4;
522   l_c_attribute5           t_attribute5;
523   l_c_attribute6           t_attribute6;
524   l_c_attribute7           t_attribute7;
525   l_c_attribute8           t_attribute8;
526   l_c_attribute9           t_attribute9;
527   l_c_attribute10          t_attribute10;
528   l_c_attribute11          t_attribute11;
529   l_c_attribute12          t_attribute12;
530   l_c_attribute13          t_attribute13;
531   l_c_attribute14          t_attribute14;
532   l_c_attribute15          t_attribute15;
533   l_c_attribute16          t_attribute16;
534   l_c_attribute17          t_attribute17;
535   l_c_attribute18          t_attribute18;
536   l_c_attribute19          t_attribute19;
537   l_c_attribute20          t_attribute20;
538   l_cycles_since_mark	   t_cycles_since_mark;
539   l_cycles_since_new 	   t_cycles_since_new;
540   l_cycles_since_overhaul  t_cycles_since_overhaul;
541   l_cycles_since_repair 	t_cycles_since_repair;
542   l_cycles_since_visit 	   t_cycles_since_visit;
543   l_number_of_repairs 	   t_number_of_repairs;
544   l_n_attribute1 		      t_n_attribute1;
545   l_n_attribute10 	      t_n_attribute10;
546   l_n_attribute2 		      t_n_attribute2;
547   l_n_attribute3 		      t_n_attribute3;
548   l_n_attribute4 		      t_n_attribute4;
549   l_n_attribute5 		      t_n_attribute5;
550   l_n_attribute6 		      t_n_attribute6;
551   l_n_attribute7 		      t_n_attribute7;
552   l_n_attribute8 		      t_n_attribute8;
553   l_n_attribute9 		      t_n_attribute9;
554   l_time_since_mark 	      t_time_since_mark;
555   l_time_since_new 	      t_time_since_new;
556   l_time_since_overhaul 	t_time_since_overhaul;
557   l_time_since_repair 	   t_time_since_repair;
558   l_time_since_visit	      t_time_since_visit;
559   l_d_attribute1           t_d_attribute1;
560   l_d_attribute10           t_d_attribute10;
561   l_d_attribute2           t_d_attribute2;
562   l_d_attribute3           t_d_attribute3;
563   l_d_attribute4           t_d_attribute4;
564   l_d_attribute5           t_d_attribute5;
565   l_d_attribute6           t_d_attribute6;
566   l_d_attribute7           t_d_attribute7;
567   l_d_attribute8           t_d_attribute8;
568   l_d_attribute9           t_d_attribute9;
569   l_territory_code         t_territory_code;
570   -- Bug 8467875
571 
572   l_delivery_detail_id   t_delivery_detail_id;
573   l_transaction_temp_id  t_transaction_temp_id;
574   l_quantity             t_quantity ;
575   l_inv_item_id          t_inv_item_id ;
576   l_fm_serial_number     t_fm_serial_number ;
577   l_to_serial_number     t_to_serial_number ;
578 
579   -- Bug 3628620
580   l_attribute_category   t_attribute_category ;
581   l_attribute1           t_attribute1 ;
582   l_attribute2           t_attribute2 ;
583   l_attribute3           t_attribute3 ;
584   l_attribute4           t_attribute4 ;
585   l_attribute5           t_attribute5 ;
586   l_attribute6           t_attribute6 ;
587   l_attribute7           t_attribute7 ;
588   l_attribute8           t_attribute8 ;
589   l_attribute9           t_attribute9 ;
590   l_attribute10          t_attribute10 ;
591   l_attribute11          t_attribute11 ;
592   l_attribute12          t_attribute12 ;
593   l_attribute13          t_attribute13 ;
594   l_attribute14          t_attribute14 ;
595   l_attribute15          t_attribute15 ;
596   -- End of Bug 3628620
597 
598   cur_fetch  NUMBER := 0;
599   tot_fetch  NUMBER := 0;
600   pre_fetch  NUMBER := 0;
601   l_batch_size  NUMBER := 1000;
602   ins_rows   NUMBER := 0;
603   del_rows   NUMBER := 0;
604   upd_rows   NUMBER := 0;
605 --
606 l_debug_on CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
607 --
608 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'TRANSFER_SERIAL_NUMBERS_PVT';
609 --
610 
611 BEGIN
612    --
613    IF l_debug_on THEN
614        WSH_DEBUG_SV.push(l_module_name);
615        --
616        WSH_DEBUG_SV.log(l_module_name,'p_transfer_param',p_transfer_param);
617        WSH_DEBUG_SV.log(l_module_name,'p_batch_id',p_batch_id);
618        WSH_DEBUG_SV.log(l_module_name,'p_interfacing',p_interfacing);
619    END IF;
620    --
621 
622   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
623 
624   IF p_interfacing = 'OM' THEN
625      IF p_transfer_param = 'MSNT' THEN
626         OPEN dd_msnt_rec_om;
627      ELSIF p_transfer_param = 'WDD' THEN
628         OPEN dd_wdd_rec_om;
629      END IF;
630   ELSE
631      IF p_transfer_param = 'MSNT' THEN
632         OPEN dd_msnt_rec;
633      ELSIF p_transfer_param = 'WDD' THEN
634         OPEN dd_wdd_rec;
635      END IF;
636   END IF;
637 
638   tot_fetch := 0;
639   LOOP
640     pre_fetch := tot_fetch;
641 
642     IF p_interfacing = 'OM' THEN
643      IF p_transfer_param = 'MSNT' THEN
644        FETCH dd_msnt_rec_om BULK COLLECT
645        INTO  l_delivery_detail_id, l_transaction_temp_id,
646              l_quantity, l_fm_serial_number, l_to_serial_number,
647              l_attribute_category, l_attribute1, l_attribute2,
648              l_attribute3,  l_attribute4,  l_attribute5,  l_attribute6,
649              l_attribute7,  l_attribute8,  l_attribute9,  l_attribute10,
650              l_attribute11, l_attribute12, l_attribute13, l_attribute14,
651              l_attribute15,
652              l_inv_item_id, -- bug 3704188
653              -- Bug 8467875
654              l_cycles_since_mark,
655              l_cycles_since_new,l_cycles_since_overhaul,
656              l_cycles_since_repair,l_cycles_since_visit,
657              l_c_attribute1,l_c_attribute10,l_c_attribute11,
658              l_c_attribute12,l_c_attribute13,l_c_attribute14,
659              l_c_attribute15,l_c_attribute16,l_c_attribute17,
660              l_c_attribute18,l_c_attribute19,l_c_attribute2,
661              l_c_attribute20,l_c_attribute3,l_c_attribute4,
662              l_c_attribute5,l_c_attribute6,l_c_attribute7,
663              l_c_attribute8,l_c_attribute9,l_d_attribute1,
664              l_d_attribute10,l_d_attribute2,l_d_attribute3,
665              l_d_attribute4,l_d_attribute5,l_d_attribute6,
666              l_d_attribute7,l_d_attribute8,l_d_attribute9,
667              l_number_of_repairs,l_n_attribute1,l_n_attribute10,
668              l_n_attribute2,l_n_attribute3,l_n_attribute4,l_n_attribute5,
669              l_n_attribute6,l_n_attribute7,l_n_attribute8,
670              l_n_attribute9, l_territory_code,l_time_since_mark,l_time_since_new,
671              l_time_since_overhaul,l_time_since_repair,l_time_since_visit,
672              l_serial_attribute_category
673              -- Bug 8467875
674        LIMIT l_batch_size ;
675        tot_fetch := dd_msnt_rec_om%ROWCOUNT;
676      ELSIF p_transfer_param = 'WDD' THEN
677        FETCH dd_wdd_rec_om BULK COLLECT
678        INTO  l_delivery_detail_id, l_transaction_temp_id,
679              l_quantity, l_fm_serial_number, l_to_serial_number,
680              l_attribute_category, l_attribute1, l_attribute2,
681              l_attribute3,  l_attribute4,  l_attribute5,  l_attribute6,
682              l_attribute7,  l_attribute8,  l_attribute9,  l_attribute10,
683              l_attribute11, l_attribute12, l_attribute13, l_attribute14,
684              l_attribute15,
685              l_inv_item_id, -- bug 3704188
686              -- Bug 8467875
687              l_cycles_since_mark,
688              l_cycles_since_new,l_cycles_since_overhaul,
689              l_cycles_since_repair,l_cycles_since_visit,
690              l_c_attribute1,l_c_attribute10,l_c_attribute11,
691              l_c_attribute12,l_c_attribute13,l_c_attribute14,
692              l_c_attribute15,l_c_attribute16,l_c_attribute17,
693              l_c_attribute18,l_c_attribute19,l_c_attribute2,
694              l_c_attribute20,l_c_attribute3,l_c_attribute4,
695              l_c_attribute5,l_c_attribute6,l_c_attribute7,
696              l_c_attribute8,l_c_attribute9,l_d_attribute1,
697              l_d_attribute10,l_d_attribute2,l_d_attribute3,
698              l_d_attribute4,l_d_attribute5,l_d_attribute6,
699              l_d_attribute7,l_d_attribute8,l_d_attribute9,
700              l_number_of_repairs,l_n_attribute1,l_n_attribute10,
701              l_n_attribute2,l_n_attribute3,l_n_attribute4,l_n_attribute5,
702              l_n_attribute6,l_n_attribute7,l_n_attribute8,
703              l_n_attribute9, l_territory_code,l_time_since_mark,l_time_since_new,
704              l_time_since_overhaul,l_time_since_repair,l_time_since_visit,
705              l_serial_attribute_category
706              -- Bug 8467875
707        LIMIT l_batch_size ;
708        tot_fetch := dd_wdd_rec_om%ROWCOUNT;
709      END IF;
710     ELSE
711      IF p_transfer_param = 'MSNT' THEN
712        FETCH dd_msnt_rec BULK COLLECT
713        INTO  l_delivery_detail_id, l_transaction_temp_id,
714              l_quantity, l_fm_serial_number, l_to_serial_number,
715              l_attribute_category, l_attribute1, l_attribute2,
716              l_attribute3,  l_attribute4,  l_attribute5,  l_attribute6,
717              l_attribute7,  l_attribute8,  l_attribute9,  l_attribute10,
718              l_attribute11, l_attribute12, l_attribute13, l_attribute14,
719              l_attribute15,
720              l_inv_item_id, -- bug 3704188
721              -- Bug 8467875
722              l_cycles_since_mark,
723              l_cycles_since_new,l_cycles_since_overhaul,
724              l_cycles_since_repair,l_cycles_since_visit,
725              l_c_attribute1,l_c_attribute10,l_c_attribute11,
726              l_c_attribute12,l_c_attribute13,l_c_attribute14,
727              l_c_attribute15,l_c_attribute16,l_c_attribute17,
728              l_c_attribute18,l_c_attribute19,l_c_attribute2,
729              l_c_attribute20,l_c_attribute3,l_c_attribute4,
730              l_c_attribute5,l_c_attribute6,l_c_attribute7,
731              l_c_attribute8,l_c_attribute9,l_d_attribute1,
732              l_d_attribute10,l_d_attribute2,l_d_attribute3,
733              l_d_attribute4,l_d_attribute5,l_d_attribute6,
734              l_d_attribute7,l_d_attribute8,l_d_attribute9,
735              l_number_of_repairs,l_n_attribute1,l_n_attribute10,
736              l_n_attribute2,l_n_attribute3,l_n_attribute4,l_n_attribute5,
737              l_n_attribute6,l_n_attribute7,l_n_attribute8,
738              l_n_attribute9,l_territory_code,l_time_since_mark,l_time_since_new,
739              l_time_since_overhaul,l_time_since_repair,l_time_since_visit,
740              l_serial_attribute_category
741              -- Bug 8467875
742        LIMIT l_batch_size ;
743        tot_fetch := dd_msnt_rec%ROWCOUNT;
744      ELSIF p_transfer_param = 'WDD' THEN
745        FETCH dd_wdd_rec BULK COLLECT
746        INTO  l_delivery_detail_id, l_transaction_temp_id,
747              l_quantity, l_fm_serial_number, l_to_serial_number,
748              l_attribute_category, l_attribute1, l_attribute2,
749              l_attribute3,  l_attribute4,  l_attribute5,  l_attribute6,
750              l_attribute7,  l_attribute8,  l_attribute9,  l_attribute10,
751              l_attribute11, l_attribute12, l_attribute13, l_attribute14,
752              l_attribute15,
753              l_inv_item_id, -- bug 3704188
754              -- Bug 8467875
755              l_cycles_since_mark,
756              l_cycles_since_new,l_cycles_since_overhaul,
757              l_cycles_since_repair,l_cycles_since_visit,
758              l_c_attribute1,l_c_attribute10,l_c_attribute11,
759              l_c_attribute12,l_c_attribute13,l_c_attribute14,
760              l_c_attribute15,l_c_attribute16,l_c_attribute17,
761              l_c_attribute18,l_c_attribute19,l_c_attribute2,
762              l_c_attribute20,l_c_attribute3,l_c_attribute4,
763              l_c_attribute5,l_c_attribute6,l_c_attribute7,
764              l_c_attribute8,l_c_attribute9,l_d_attribute1,
765              l_d_attribute10,l_d_attribute2,l_d_attribute3,
766              l_d_attribute4,l_d_attribute5,l_d_attribute6,
767              l_d_attribute7,l_d_attribute8,l_d_attribute9,
768              l_number_of_repairs,l_n_attribute1,l_n_attribute10,
769              l_n_attribute2,l_n_attribute3,l_n_attribute4,l_n_attribute5,
770              l_n_attribute6,l_n_attribute7,l_n_attribute8,
771              l_n_attribute9, l_territory_code,l_time_since_mark,l_time_since_new,
772              l_time_since_overhaul,l_time_since_repair,l_time_since_visit,
773              l_serial_attribute_category
774              -- Bug 8467875
775        LIMIT l_batch_size ;
776        tot_fetch := dd_wdd_rec%ROWCOUNT;
777      END IF;
778     END IF;
779 
780     cur_fetch := tot_fetch - pre_fetch;
781     EXIT WHEN ( cur_fetch <= 0);
782 
783     FORALL i IN 1 .. cur_fetch
784       INSERT INTO wsh_serial_numbers
785                          ( delivery_detail_id,
786                            quantity,
787                            fm_serial_number,
788                            to_serial_number,
789                            creation_date,
790                            created_by,
791                            last_update_date,
792                            last_updated_by,
793                            attribute_category, -- Bug 3628620
794                            attribute1, attribute2, attribute3,
795                            attribute4,  attribute5, attribute6,
796                            attribute7,  attribute8, attribute9,
797                            attribute10, attribute11,attribute12,
798                            attribute13, attribute14,attribute15, -- End of Bug 3628620
799                            -- Bug 8467875
800                            serial_attribute_category,c_attribute1,c_attribute2,
801                            c_attribute3,c_attribute4,c_attribute5,
802                            c_attribute6,c_attribute7,c_attribute8,
803                            c_attribute9,c_attribute10,c_attribute11,
804                            c_attribute12,c_attribute13,c_attribute14,
805                            c_attribute15,c_attribute16,c_attribute17,
806                            c_attribute18,c_attribute19,c_attribute20,
807                            cycles_since_mark,cycles_since_new,cycles_since_overhaul,
808                            cycles_since_repair,cycles_since_visit,number_of_repairs,
809                            n_attribute1,n_attribute10,n_attribute2,
810                            n_attribute3,n_attribute4,n_attribute5,
811                            n_attribute6,n_attribute7,n_attribute8,
812                            n_attribute9,time_since_mark,time_since_new,
813                            time_since_overhaul,time_since_repair,time_since_visit,
814                            d_attribute1,d_attribute10,d_attribute2,
815                            d_attribute3,d_attribute4,d_attribute5,
816                            d_attribute6,d_attribute7,d_attribute8,
817                            d_attribute9,territory_code
818                            -- Bug 8467875
819                           )
820                       VALUES
821                          ( l_delivery_detail_id(i),
822                            l_quantity(i),
823                            l_fm_serial_number(i),
824                            l_to_serial_number(i),
825                            sysdate,
826                            FND_GLOBAL.USER_ID,
827                            sysdate,
828                            FND_GLOBAL.USER_ID,
829                            l_attribute_category(i), -- Bug 3628620
830                            l_attribute1(i), l_attribute2(i), l_attribute3(i),
831                            l_attribute4(i),  l_attribute5(i),  l_attribute6(i),
832                            l_attribute7(i),  l_attribute8(i),  l_attribute9(i),
833                            l_attribute10(i), l_attribute11(i), l_attribute12(i),
834                            l_attribute13(i), l_attribute14(i), l_attribute15(i),
835                            -- End of Bug 3628620
836                            -- Bug 8467875
837                            l_serial_attribute_category(i),l_c_attribute1(i),l_c_attribute2(i),
838                            l_c_attribute3(i),l_c_attribute4(i),l_c_attribute5(i),
839                            l_c_attribute6(i),l_c_attribute7(i),l_c_attribute8(i),
840                            l_c_attribute9(i),l_c_attribute10(i),l_c_attribute11(i),
841                            l_c_attribute12(i),l_c_attribute13(i),l_c_attribute14(i),
842                            l_c_attribute15(i),l_c_attribute16(i),l_c_attribute17(i),
843                            l_c_attribute18(i),l_c_attribute19(i),l_c_attribute20(i),
844                            l_cycles_since_mark(i),l_cycles_since_new(i),l_cycles_since_overhaul(i),
845                            l_cycles_since_repair(i),l_cycles_since_visit(i),l_number_of_repairs(i),
846                            l_n_attribute1(i),l_n_attribute10(i),l_n_attribute2(i),
847                            l_n_attribute3(i),l_n_attribute4(i),l_n_attribute5(i),
848                            l_n_attribute6(i),l_n_attribute7(i),l_n_attribute8(i),
849                            l_n_attribute9(i),l_time_since_mark(i),l_time_since_new(i),
850                            l_time_since_overhaul(i),l_time_since_repair(i),l_time_since_visit(i),
851                            l_d_attribute1(i),l_d_attribute10(i),l_d_attribute2(i),
852                            l_d_attribute3(i),l_d_attribute4(i),l_d_attribute5(i),
853                            l_d_attribute6(i),l_d_attribute7(i),l_d_attribute8(i),
854                            l_d_attribute9(i),l_territory_code(i)
855                            -- Bug 8467875
856                           );
857 
858 
859     ins_rows := ins_rows + sql%rowcount;
860     -- Bug 6625172: Removing Delete of msnt for each transaction_temp_id from here
861     -- and updating wsh_delivery_details only when p_transfer_param is 'WDD'
862     IF p_transfer_param = 'WDD' THEN
863       /* FORALL i IN 1 .. cur_fetch
864          DELETE FROM mtl_serial_numbers_temp
865          WHERE  transaction_temp_id = l_transaction_temp_id(i)
866          AND    fm_serial_number = l_fm_serial_number(i);
867 
868        del_rows := del_rows + sql%rowcount;
869     ELSE*/
870        FORALL i IN 1 .. cur_fetch
871          UPDATE wsh_delivery_details
872          SET    serial_number = NULL,
873 	        --Added as part of bug 7645262
874                 last_update_date    = sysdate,
875                 request_id          = fnd_global.conc_request_id,
876                 last_updated_by     = fnd_global.user_id,
877                 transaction_temp_id = l_transaction_temp_id(i)
878          WHERE  delivery_detail_id = l_delivery_detail_id(i);
879 
880        upd_rows := upd_rows + sql%rowcount;
881     END IF;
882 
883   END LOOP;
884 
885   IF p_interfacing = 'OM' THEN
886      IF p_transfer_param = 'MSNT' THEN
887       --{
888         CLOSE dd_msnt_rec_om;
889 	-- bug 6625172: Deleting the msnt records for all the selected transaction_temp_id's for OM records
890 	IF (ins_rows > 0) THEN
891         --{
892            DELETE mtl_serial_numbers_temp
893            WHERE  transaction_temp_id IN
894               (   SELECT DISTINCT dd.transaction_temp_id
895                   from  wsh_delivery_details dd,
896                   wsh_delivery_assignments da,
897                   wsh_delivery_legs dg,
898                   wsh_new_deliveries dl,
899                   wsh_trip_stops st,
900                   mtl_serial_numbers_temp msnt
901                   where  st.batch_id = p_batch_id
902                   and    st.stop_location_id = dl.initial_pickup_location_id
903                   and    dg.delivery_id = dl.delivery_id
904                   and    da.delivery_id = dl.delivery_id
905                   and    dd.delivery_detail_id = da.delivery_detail_id
906                   and    st.stop_id = dg.pick_up_stop_id
907                   and    dd.released_status = 'C'
908                   and    dd.container_flag='N'
909                   and    NVL(dd.oe_interfaced_flag , 'N') = 'Y'
910                   and    dd.transaction_temp_id = msnt.transaction_temp_id
911                   and    nvl(dl.shipment_direction , 'O') IN ('O', 'IO'));
912         --}
913         END IF;
914       --}
915      ELSIF p_transfer_param = 'WDD' THEN
916         CLOSE dd_wdd_rec_om;
917      END IF;
918   ELSE
919      IF p_transfer_param = 'MSNT' THEN
920      --{
921         CLOSE dd_msnt_rec;
922 	-- bug 6625172: Deleting the msnt records for all the selected transaction_temp_id's for non-OM records
923         IF (ins_rows > 0) THEN
924         --{
925             DELETE mtl_serial_numbers_temp
926             WHERE  transaction_temp_id IN
927             ( SELECT DISTINCT dd.transaction_temp_id
928                   from   wsh_delivery_details dd,
929                   wsh_delivery_assignments da,
930                  wsh_delivery_legs dg,
931                  wsh_new_deliveries dl,
932                  wsh_trip_stops st,
933                  mtl_serial_numbers_temp msnt
934                  where  st.batch_id = p_batch_id
935                  and    st.stop_location_id = dl.initial_pickup_location_id
936                  and    dg.delivery_id = dl.delivery_id
937                  and    da.delivery_id = dl.delivery_id
938                  and    dd.delivery_detail_id = da.delivery_detail_id
939                  and    st.stop_id = dg.pick_up_stop_id
940                  and    dd.released_status = 'C'
941                  and    dd.container_flag='N'
942                  and    dd.transaction_temp_id = msnt.transaction_temp_id
943                  and    nvl(dl.shipment_direction , 'O') IN ('O', 'IO'));
944          --}
945        END IF;
946        --}
947      ELSIF p_transfer_param = 'WDD' THEN
948         CLOSE dd_wdd_rec;
949      END IF;
950   END IF;
951 
952   IF l_debug_on THEN
953       WSH_DEBUG_SV.log(l_module_name,'Numbers of rows inserted into wsh_serial_numbers: '|| to_char(ins_rows) ||
954                                      ', Number of rows deleted from mtl_serial_numbers_temp: '|| to_char(del_rows) ||
955                                      ', Number of rows updated in wsh_delivery_details: '|| to_char(upd_rows) );
956       WSH_DEBUG_SV.pop(l_module_name);
957   END IF;
958 
959 EXCEPTION
960   WHEN OTHERS THEN
961     IF dd_msnt_rec%ISOPEN THEN
962       CLOSE dd_msnt_rec;
963     END IF;
964     IF dd_msnt_rec_om%ISOPEN THEN
965       CLOSE dd_msnt_rec_om;
966     END IF;
967     IF dd_wdd_rec%ISOPEN THEN
968       CLOSE dd_wdd_rec;
969     END IF;
970     IF dd_wdd_rec_om%ISOPEN THEN
971       CLOSE dd_wdd_rec_om;
972     END IF;
973     IF c_get_attr_msn%ISOPEN THEN
974       CLOSE c_get_attr_msn;
975     END IF;
976     IF l_debug_on THEN
977          WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| substr(SQLERRM,1,200),WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
978            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
979     END IF;
980     wsh_util_core.default_handler('WSH_SHIP_CONFIRM_ACTIONS.TRANSFER_SERIAL_NUMBERS_PVT');
981     x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
982 
983 END transfer_serial_numbers_pvt;
984 
985 --========================================================================
986 -- PROCEDURE : transfer_serial_numbers
987 --             Wrapper API for Transfer_Serial_Numbers_pvt
988 --
989 -- PARAMETERS: p_batch_id              The batch id of trip stops being
990 --                                     interfaced.
991 --             p_interfacing           if this procedure is called during OM
992 --                                     interface value 'OM' is passed, otherwise
993 --                                     value 'INV' is passed.
994 --             x_return_status         return status of the API.
995 --
996 -- COMMENT   : This procedure is used to transfer the serial number information
997 --             from mtl_serial_numbers_temp to the wsh_serial_numbers table.
998 --             It then deletes these entries from mtl_serial_numbers_temp.
999 --             IF this procedure is called during the INV interface then only
1000 --             the lines that have been interfaced to OM are processed, else
1001 --             the non-oe lines are processed as well.
1002 --========================================================================
1003 PROCEDURE transfer_serial_numbers (
1004             p_batch_id       IN  NUMBER,
1005             p_interfacing    IN VARCHAR2,
1006             x_return_status OUT NOCOPY VARCHAR2) IS
1007 
1008 --
1009 l_debug_on CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
1010 --
1011 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'TRANSFER_SERIAL_NUMBERS';
1012 --
1013 
1014 BEGIN
1015    --
1016    IF l_debug_on THEN
1017        WSH_DEBUG_SV.push(l_module_name);
1018        --
1019        WSH_DEBUG_SV.log(l_module_name,'p_batch_id',p_batch_id);
1020        WSH_DEBUG_SV.log(l_module_name,'p_interfacing',p_interfacing);
1021    END IF;
1022    --
1023 
1024   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1025 
1026   -- Call transfer_serial_numbers_pvt
1027 
1028   -- Case I : Serial Records where 'From Serial Number' <> 'To Serial Number'
1029   --          and records exist in MSNT
1030   -- Case II : Serial Records where 'From Serial Number' = 'To Serial Number'
1031   --            or 'To Serial Number' is Null and records exist in MSNT
1032   -- Combined, since records exist in MSNT
1033   transfer_serial_numbers_pvt(
1034                                p_transfer_param  => 'MSNT',
1035                                p_batch_id        => p_batch_id,
1036                                p_interfacing     => p_interfacing,
1037                                x_return_status   => x_return_status );
1038 
1039   -- Case III : 'Serial Number' is present in wsh_delivery_details
1040   transfer_serial_numbers_pvt(
1041                                p_transfer_param  => 'WDD',
1042                                p_batch_id        => p_batch_id,
1043                                p_interfacing     => p_interfacing,
1044                                x_return_status   => x_return_status );
1045 
1046    IF l_debug_on THEN
1047       WSH_DEBUG_SV.pop(l_module_name);
1048    END IF;
1049 
1050 EXCEPTION
1051   WHEN OTHERS THEN
1052     IF l_debug_on THEN
1053          WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| substr(SQLERRM,1,200),WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1054            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
1055     END IF;
1056     wsh_util_core.default_handler('WSH_SHIP_CONFIRM_ACTIONS.TRANSFER_SERIAL_NUMBERS');
1057     x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1058 
1059 END transfer_serial_numbers;
1060 
1061 -- End of Changes for creating wrapper and new API transfer_serial_numbers_pvt
1062 
1063 --
1064 --Procedure:     Ship_Confirm_A_Trip_Stop
1065 --Parameters:    p_stop_id,
1066 --        x_return_status
1067 --Description:  This procedure will ship confirm the whole trip stop.
1068 --       It submits the inventory interface program -- inv_interface
1069 
1070 PROCEDURE Ship_Confirm_A_Trip_Stop(p_stop_id number,
1071                  x_return_status out NOCOPY  varchar2) is
1072 l_status1 varchar2(30);
1073 l_status2 varchar2(30);
1074 inv_inter_req_submission exception;
1075 request_id number;
1076 msg varchar2(2000);
1077 --
1078 l_debug_on BOOLEAN;
1079 --
1080 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'SHIP_CONFIRM_A_TRIP_STOP';
1081 --
1082 l_log_level	NUMBER :=0;
1083 begin
1084    --
1085    --
1086    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
1087    --
1088    IF l_debug_on IS NULL
1089    THEN
1090        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
1091    END IF;
1092    --
1093    IF l_debug_on THEN
1094        WSH_DEBUG_SV.push(l_module_name);
1095        --
1096        WSH_DEBUG_SV.log(l_module_name,'P_STOP_ID',P_STOP_ID);
1097        WSH_DEBUG_SV.log(l_module_name,'Submitting the request');
1098        l_log_level := 1;
1099    END IF;
1100    --
1101    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1102    -- bug 2308504: make sure to pass all parameters expected,
1103    --    so that code output will go into the log file.
1104    request_id := FND_REQUEST.submit_Request('WSH', 'WSHINTERFACE', '', '', FALSE,
1105                   'ALL',      -- mode
1106                                                 p_stop_id,  -- stop
1107                                                 '',         -- delivery
1108                                                 l_log_level);       -- log level
1109    IF l_debug_on THEN
1110       WSH_DEBUG_SV.log(l_module_name,'request_id',request_id);
1111    END IF;
1112    if  (request_id = 0) THEN
1113      raise inv_inter_req_submission;
1114    else
1115      FND_MESSAGE.SET_NAME('WSH', 'WSH_DET_INV_INT_SUBMITTED');
1116      FND_MESSAGE.SET_TOKEN('REQ_ID', to_char(request_id));
1117      WSH_UTIL_CORE.ADD_MESSAGE(x_return_status,l_module_name);
1118    END if;
1119 
1120    IF l_debug_on THEN
1121        WSH_DEBUG_SV.pop(l_module_name);
1122    END IF;
1123    --
1124    exception
1125      WHEN inv_inter_req_submission THEN
1126        x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1127        fnd_message.set_name('WSH', 'WSH_DET_INV_INT_REQ_SUBMISSION');
1128        WSH_UTIL_CORE.ADD_MESSAGE(x_return_status,l_module_name);
1129        IF l_debug_on THEN
1130           WSH_DEBUG_SV.logmsg(l_module_name,'INV_INTER_REQ_SUBMISSION exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
1131           WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:INV_INTER_REQ_SUBMISSION');
1132       END IF;
1133       --
1134       WHEN others THEN
1135        wsh_util_core.default_handler('WSH_SHIP_CONFRIM_ACTIONS.SHIP_CONFIRM_A_TRIP_STOP',l_module_name);
1136        x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1137        IF l_debug_on THEN
1138            WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1139            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
1140        END IF;
1141        --
1142 END Ship_Confirm_A_Trip_Stop;
1143 
1144 
1145 -- start bug 1578251: internal procedure to manage completion_status
1146 --========================================================================
1147 -- PROCEDURE : Update_Completion_Status
1148 --                  Internal procedure to manage completion_status for ITS
1149 --
1150 -- PARAMETERS: p_num_stops             Number of the stops which are processed
1151 --                                     by the calling API
1152 --             p_batch_id              The batch id of trip stops being
1153 --                                     interfaced.
1154 --             x_master_status         The ITS status for current run
1155 --             p_api_status            The status of the calling API
1156 --             x_normal_count          Number of stops interfaced with NORMAL
1157 --             x_warning_count         Number of stops interfaced with WARNING
1158 --             x_interfaced_count      Number of stops interfaced with
1159 --                                     INTERFACED status.
1160 --             x_return_status         return status of the API.
1161 
1162 -- COMMENT   : This procedure is called after each interface (OM,DSNO,INV)
1163 --             It sets an overall return status for the ITS current run and also
1164 --             keeps track of the completion status and number of stops
1165 --             processed for each interface.
1166 --             The possible values for the status processed by this API are:
1167 --             NORMAL :     the interface completed normal
1168 --             INTERFACED : the interface completed in INTERFACED status
1169 --             WARNING :    There are some problems, but the ITS will not stop
1170 --             ERROR:       There are problems preventing the ITS to complete.
1171 --========================================================================
1172 
1173 procedure Update_Completion_Status(p_num_stops IN NUMBER,
1174                            p_batch_id  IN NUMBER,
1175                            x_master_status IN OUT NOCOPY  VARCHAR2,
1176                            p_api_status      IN OUT NOCOPY  VARCHAR2,
1177                            x_normal_count  IN OUT NOCOPY  NUMBER,
1178                            x_warning_count   IN OUT NOCOPY  NUMBER,
1179                            x_interfaced_count IN OUT NOCOPY  NUMBER
1180                ) IS
1181                --
1182 l_debug_on BOOLEAN;
1183                --
1184                l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'UPDATE_COMPLETION_STATUS';
1185 
1186                l_stops_in_batch      NUMBER;
1187                --
1188                CURSOR c_get_num_stops(p_batch_id NUMBER) IS
1189                SELECT count(*)
1190                FROM wsh_trip_stops
1191                WHERE batch_id = p_batch_id;
1192                --
1193 BEGIN
1194      --
1195      l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
1196      --
1197      IF l_debug_on IS NULL
1198      THEN
1199          l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
1200      END IF;
1201      --
1202      IF l_debug_on THEN
1203          WSH_DEBUG_SV.push(l_module_name);
1204          --
1205          WSH_DEBUG_SV.log(l_module_name,'p_num_stops',p_num_stops);
1206          WSH_DEBUG_SV.log(l_module_name,'p_batch_id',p_batch_id);
1207          WSH_DEBUG_SV.log(l_module_name,'X_MASTER_STATUS',X_MASTER_STATUS);
1208          WSH_DEBUG_SV.log(l_module_name,'P_API_STATUS',P_API_STATUS);
1209          WSH_DEBUG_SV.log(l_module_name,'X_NORMAL_COUNT',X_NORMAL_COUNT);
1210          WSH_DEBUG_SV.log(l_module_name,'X_WARNING_COUNT',X_WARNING_COUNT);
1211          WSH_DEBUG_SV.log(l_module_name,'X_INTERFACED_COUNT',X_INTERFACED_COUNT);
1212      END IF;
1213      --
1214      IF p_num_stops IS NOT NULL THEN
1215         l_stops_in_batch := p_num_stops;
1216      ELSE
1217         OPEN c_get_num_stops(p_batch_id);
1218         FETCH c_get_num_stops INTO l_stops_in_batch;
1219         CLOSE c_get_num_stops;
1220         IF l_debug_on THEN
1221             WSH_DEBUG_SV.log(l_module_name,'l_stops_in_batch',l_stops_in_batch);
1222         END IF;
1223      END IF;
1224 
1225      IF  p_api_status = 'NORMAL'  THEN
1226       x_normal_count := x_normal_count + l_stops_in_batch;
1227      ELSIF p_api_status = 'INTERFACED' THEN
1228       x_interfaced_count := x_interfaced_count + l_stops_in_batch;
1229      ELSIF p_api_status = 'WARNING' THEN
1230       x_warning_count := x_warning_count + l_stops_in_batch;
1231       IF x_master_status = 'NORMAL' THEN
1232         x_master_status := p_api_status;
1233       END IF;
1234      ELSIF p_api_status = 'ERROR' THEN
1235       IF x_master_status IN ('NORMAL', 'WARNING' ) THEN
1236         x_master_status := p_api_status;
1237       END IF;
1238      ELSE
1239         -- unknown status...
1240         WSH_UTIL_CORE.PrintMsg('ERROR: unknown status = '''
1241                          || p_api_status || '''');
1242         x_master_status := 'ERROR';
1243      END IF;
1244      --
1245      IF l_debug_on THEN
1246          WSH_DEBUG_SV.log(l_module_name,'X_MASTER_STATUS',X_MASTER_STATUS);
1247          WSH_DEBUG_SV.log(l_module_name,'P_API_STATUS',P_API_STATUS);
1248          WSH_DEBUG_SV.log(l_module_name,'X_NORMAL_COUNT',X_NORMAL_COUNT);
1249          WSH_DEBUG_SV.log(l_module_name,'X_WARNING_COUNT',X_WARNING_COUNT);
1250          WSH_DEBUG_SV.log(l_module_name,'X_INTERFACED_COUNT',X_INTERFACED_COUNT);
1251          WSH_DEBUG_SV.pop(l_module_name);
1252      END IF;
1253      --
1254 END Update_Completion_Status;
1255 -- end bug 1578251: internal procedure to manage completion_status
1256 
1257 
1258 
1259 
1260 --========================================================================
1261 -- PROCEDURE : handle_stop_lvl_splits
1262 --                  This procedure determines if all the trip stops within a
1263 --                  batch can be processed together, if not, it removes the
1264 --                  violating trip stops from the batch
1265 --
1266 -- PARAMETERS: x_split_stops           trip stops that are removed from the
1267 --                                     batch
1268 --             p_batch_id              The batch id of trip stops being
1269 --                                     interfaced.
1270 --             x_stop_tab              The trip stops associated with the batch
1271 --             x_return_status         return status of the API.
1272 
1273 -- COMMENT   : If two delivery details have the same SOURCE_LINE_ID and are
1274 --             associated with 2 different pick up trip stops, then these 2
1275 --             trip stops cannot be processed in the same batch (problem in
1276 --             OM interface).  The first trip stop will be removed from
1277 --             the batch and will be put in x_split_stops.
1278 --             This is the flow for this API :
1279 --             If table x_split_stops has some rows from earlier run, this
1280 --             means that some stops were extracted from previous batch, so
1281 --             the API will mark these stops with the current batch. then it
1282 --             determines if there are stops in the new batch that cannot be
1283 --             processed together.  If, for example, there are 3 stops that
1284 --             cannot be processed together then stop 1 and 2 will be removed
1285 --             from the batch.  Table x_split_stops will contain stop 1 and 2
1286 --             table x_stop_tab will contain stop 3 and any other remaining
1287 --             stop left in the batch.
1288 --
1289 --========================================================================
1290 
1291 PROCEDURE handle_stop_lvl_splits(
1292                         x_split_stops IN OUT NOCOPY wsh_util_core.id_tab_type,
1293                         p_batch_id    IN NUMBER,
1294                         x_stop_tab    IN OUT NOCOPY wsh_util_core.id_tab_type,
1295                         x_return_status OUT NOCOPY VARCHAR2)
1296 IS
1297    --
1298    l_debug_on BOOLEAN;
1299    l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' ||
1300     'handle_stop_lvl_splits';
1301 
1302    x  NUMBER;
1303    j  NUMBER;
1304    i  NUMBER;
1305    l_last NUMBER;
1306    z  NUMBER := 1;
1307    l_found BOOLEAN;
1308 
1309    l_new_split_stops       wsh_util_core.id_tab_type;
1310    l_stop_tab              wsh_util_core.id_tab_type;
1311 
1312 
1313    CURSOR get_stops(p_batch_id NUMBER) is
1314    SELECT DISTINCT wts.stop_id
1315    FROM wsh_trip_stops wts,
1316    wsh_trip_stops wts2,
1317    wsh_delivery_legs wdl,
1318    wsh_delivery_legs wdl2,
1319    wsh_delivery_assignments_v wda,
1320    wsh_delivery_assignments_v wda2,
1321    wsh_delivery_details wdd,
1322    wsh_delivery_details wdd2
1323    WHERE wts.batch_id = p_batch_id
1324    AND wts.stop_id = wdl.pick_up_stop_id
1325    AND wda.delivery_id = wdl.delivery_id
1326    AND wda.delivery_detail_id = wdd.delivery_detail_id
1327    AND wdd.source_code = 'OE'
1328    AND nvl(wdd.oe_interfaced_flag,'N') <> 'Y'
1329    AND wdd.released_status <> 'D'
1330    AND wts2.batch_id = p_batch_id
1331    AND wts2.stop_id = wdl2.pick_up_stop_id
1332    AND wda2.delivery_id = wdl2.delivery_id
1333    AND wda2.delivery_detail_id = wdd2.delivery_detail_id
1334    AND wdd2.source_line_id = wdd.source_line_id
1335    AND wdd2.source_code = 'OE'
1336    AND nvl(wdd2.oe_interfaced_flag,'N') <> 'Y'
1337    AND wdd2.released_status <> 'D'
1338    AND wts2.stop_id <> wts.stop_id;
1339 
1340 
1341 BEGIN
1342 
1343    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
1344    --
1345    IF l_debug_on IS NULL
1346    THEN
1347        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
1348    END IF;
1349    --
1350    IF l_debug_on THEN
1351        WSH_DEBUG_SV.push(l_module_name);
1352        --
1353        WSH_DEBUG_SV.log(l_module_name,'x_split_stops.count',
1354                                                           x_split_stops.COUNT);
1355        WSH_DEBUG_SV.log(l_module_name,'x_stop_tab.count', x_stop_tab.COUNT);
1356        WSH_DEBUG_SV.log(l_module_name,'p_batch_id',p_batch_id);
1357    END IF;
1358 
1359    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1360 
1361    l_stop_tab := x_stop_tab;
1362    x_stop_tab.DELETE;
1363 
1364    x := x_split_stops.FIRST;
1365    WHILE x IS NOT NULL LOOP --{
1366       --
1367       -- if there are some stops removed from previous batch then add them to
1368       -- the current batch also add these stops to the x_stop_tab( first add
1369       -- them to l_stop_tab)
1370       --
1371       UPDATE wsh_trip_stops
1372       SET batch_id  = p_batch_id
1373       WHERE stop_id = x_split_stops(x);
1374 
1375       IF l_debug_on THEN
1376          WSH_DEBUG_SV.log(l_module_name,'Adding stop',x_split_stops(x));
1377       END IF;
1378 
1379       -- add the left over stops from previuos batch to current stops
1380       l_stop_tab(l_stop_tab.COUNT + 1) := x_split_stops(x);
1381       x:= x_split_stops.NEXT(x);
1382    END LOOP; --}
1383 
1384    x_split_stops.DELETE;
1385 
1386    -- get all the stops that cannot be processed in one batch
1387    OPEN get_stops(p_batch_id);
1388    FETCH get_stops BULK COLLECT INTO x_split_stops ;
1389    CLOSE get_stops;
1390 
1391    IF x_split_stops.COUNT > 1 THEN --{
1392 
1393       x := l_stop_tab.FIRST;
1394       --
1395       -- Remove all the stops in x_split_stops (except the last row) from
1396       -- the batch and put the remaining stops in x_stop_tab.  Remove the
1397       -- last row of x_split_stops, this stop will be processed with the batch
1398       --
1399       l_last := x_split_stops.count - 1;
1400 
1401       WHILE x IS NOT NULL LOOP --{
1402 
1403          l_found := FALSE;
1404          FOR i IN 1..l_last LOOP --{
1405 
1406             IF l_stop_tab(x) = x_split_stops(i) THEN --{
1407                l_found := TRUE;
1408                EXIT;
1409             END IF ; --}
1410          END LOOP; --}
1411 
1412          IF l_found THEN --{
1413                UPDATE wsh_trip_stops
1414                SET batch_id = NULL
1415                WHERE stop_id =  l_stop_tab(x)
1416                AND batch_id = p_batch_id;
1417 
1418                IF l_debug_on THEN
1419                   WSH_DEBUG_SV.log(l_module_name,'removing  stop',
1420                                                               l_stop_tab(x));
1421                END IF;
1422 
1423          ELSE --}{
1424                x_stop_tab(z) := l_stop_tab(x);
1425                z := z + 1;
1426          END IF; --}
1427          x := l_stop_tab.NEXT(x);
1428       END LOOP; --}
1429       -- do not remove the last stop
1430       x_split_stops.DELETE(x_split_stops.LAST);
1431    ELSE --}{
1432       x_stop_tab := l_stop_tab;
1433    END IF;--}
1434 
1435 
1436    IF l_debug_on THEN
1437          WSH_DEBUG_SV.log(l_module_name,'x_split_stops.count',
1438                                                         x_split_stops.COUNT);
1439          WSH_DEBUG_SV.log(l_module_name,'x_stop_tab.count',x_stop_tab.COUNT);
1440          WSH_DEBUG_SV.pop(l_module_name);
1441    END IF;
1442 
1443 EXCEPTION
1444    WHEN OTHERS THEN
1445         x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
1446 
1447         IF l_debug_on THEN
1448             WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1449             WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
1450         END IF;
1451 
1452 END handle_stop_lvl_splits;
1453 
1454 
1455 
1456 -- start bug 1578251: Interface_ALL to batch process the stops
1457 --========================================================================
1458 -- PROCEDURE : interface_ALL
1459 --                  This procedure is used to interface trip stops for the mode
1460 --                  selected by parameter p_mode.  This procedure is called from
1461 --                  the wrapper of concurrent program "Interface Trip Stops SRS"
1462 --                  (interface_all_wrp) to perform the single thread
1463 --                  interfacing.
1464 --
1465 -- PARAMETERS: errbuf                  Used by the concurrent program for error
1466 --                                     messages.
1467 --             retcode                 Used by the concurrent program for return
1468 --                                     code.
1469 --             p_stop_id               Stop id to be interfaced.
1470 --             p_delivery_id           Delivery id to be interfaced.
1471 --             p_log_level             value 1 turns on the debug.
1472 --             p_batch_id              ship confirm batch used by concurrent
1473 --                                     program "Ship Confirm Deliveries SRS"
1474 --             p_trip_type             Used by concurrent program "Ship Confirm
1475 --                                     Deliveries SRS".
1476 --             p_organization_id       If p_stop_id and p_delivery_id are left
1477 --                                     blank use this parameter to interface all
1478 --                                     the stops within this organization.
1479 --             p_stops_per_batch       Indicates the number of stops that can be
1480 --                                     marked by a batch and processed together.
1481 
1482 -- COMMENT   : This API is called from the ITS wrapper (interface_all_wrp) to
1483 --             perform a single thread interface of trip stops to OM, DSNO and
1484 --             INV (depending on the value given by p_mode.)  It loops through
1485 --             all eligible trip stops, marks as many as it is indicated by
1486 --             parameter p_stops_per_batch with a batch_id and performs the 3
1487 --             interfaces.
1488 --             First, it interfaces all the trip stops within the batch to OM.
1489 --             If some stops fails to interface to OM, filter these stops out.]
1490 --             Run the DSNO interface for the remaining stops.  If some stops
1491 --             fail in DSNO interface, remove them from the batch.  Run the
1492 --             inventory interface for the remaining stops.
1493 --             Note that if all stops failed during an interface, it does not
1494 --             make sense to remove all of them from the batch.  The API, simply
1495 --             will not perform the remaining interfaces.
1496 --             If the overal API status is not ERROR, then start with the next
1497 --             batch and processed the 3 interfaces.
1498 --
1499 --========================================================================
1500 
1501 procedure interface_ALL(errbuf      OUT NOCOPY  VARCHAR2,
1502                   retcode     OUT NOCOPY  VARCHAR2,
1503                   p_mode      IN  VARCHAR2,
1504                   p_stop_id    IN  NUMBER,
1505                   p_delivery_id IN  NUMBER,
1506                   p_log_level   IN  NUMBER,
1507                   p_batch_id NUMBER DEFAULT NULL,
1508                   p_trip_type IN VARCHAR2 DEFAULT NULL,
1509                   p_organization_id IN NUMBER DEFAULT NULL,
1510                   p_stops_per_batch IN NUMBER DEFAULT NULL) IS
1511 
1512   c_stop_separator     CONSTANT VARCHAR2(100) :=
1513   '========================================================================';
1514   c_interface_separator CONSTANT VARCHAR2(100) :=
1515   '------------------------------------------------------------------------';
1516 
1517   l_stop_id          NUMBER;
1518   l_found            BOOLEAN := FALSE;
1519   l_errors           NUMBER;
1520   l_warn             NUMBER;
1521 
1522   l_interface_mode       VARCHAR2(80);
1523   l_completion_status     VARCHAR2(30);
1524   l_api_completion_status  VARCHAR2(30);
1525 
1526   request_id           NUMBER;
1527   l_error_code       NUMBER;
1528   l_error_text       VARCHAR2(2000);
1529   l_temp            BOOLEAN;
1530   l_stops_count         NUMBER := 0;
1531   l_interface_names     WSH_UTIL_CORE.Column_Tab_Type;
1532   l_stops_normal       WSH_UTIL_CORE.Id_Tab_Type;
1533   l_stops_warning     WSH_UTIL_CORE.Id_Tab_Type;
1534   l_stops_interfaced   WSH_UTIL_CORE.Id_Tab_Type;
1535   l_err_stops         WSH_UTIL_CORE.Id_Tab_Type;
1536 
1537   l_inv_interface   NUMBER := 0;
1538   l_om_interface    NUMBER := 0;
1539   l_dsno_interface     NUMBER := 0;
1540   i                  NUMBER;
1541 
1542   l_previous_interface  BOOLEAN;
1543   l_run_dsno            BOOLEAN;
1544   l_oke_count           NUMBER := 0;
1545   l_stops_per_batch     NUMBER;
1546   l_stop_per_batch_counter NUMBER := 1;
1547   l_batch_ready         BOOLEAN := FALSE;
1548   l_stop_batch_id       NUMBER;
1549    -- Stops that will be used for DSNO interface are put in  l_dsno_stop_tab.
1550   l_dsno_stop_tab       wsh_util_core.id_Tab_type;
1551    -- The stops being processed for OM interface are stored in l_stop_tab
1552   l_stop_tab            wsh_util_core.id_Tab_type;
1553   l_tab_count           NUMBER;
1554   l_err_stops_count     NUMBER;
1555   l_completion_status_bkp VARCHAR2(30);
1556   l_stop_count          NUMBER := 0;
1557   l_api_completion_status_bkp VARCHAR2(30);
1558   l_return_status       VARCHAR2(10);
1559   l_inv_batch_table     WSH_UTIL_CORE.Id_Tab_Type;
1560   l_index               number;
1561   x                     NUMBER;
1562   l_num_warnings        NUMBER := 0;
1563   l_num_errors          NUMBER := 0;
1564   l_invoicing_method    VARCHAR2(100);
1565   -- stops that are processed for INV interface are put in l_inv_stops.
1566   l_inv_stops           wsh_util_core.id_tab_type;
1567   l_split_stops         wsh_util_core.id_tab_type;
1568 
1569   -- bug 2657859 frontport bug 2630535: avoid deadlocks
1570   CURSOR lock_row ( p_stop_id in  NUMBER, p_flag in VARCHAR2 ) IS
1571   SELECT stop_id
1572   FROM wsh_trip_stops
1573   WHERE stop_id = p_stop_id
1574   AND   pending_interface_flag = p_flag
1575   FOR UPDATE NOWAIT;
1576 
1577   CURSOR lock_batch ( p_batch_id in  NUMBER, p_flag in VARCHAR2 ) IS
1578   SELECT stop_id
1579   FROM wsh_trip_stops
1580   WHERE batch_id = p_batch_id
1581   AND   pending_interface_flag = p_flag
1582   FOR UPDATE NOWAIT;
1583 
1584   l_recinfo lock_row%ROWTYPE;
1585   l_batchinfo lock_batch%ROWTYPE;
1586 
1587   trip_stop_locked exception  ;
1588   PRAGMA EXCEPTION_INIT(trip_stop_locked, -54);
1589 
1590 
1591   -- Lookup stop for this delivery
1592   CURSOR c_delivery_stop(p_delivery_id NUMBER) IS
1593    SELECT wts.stop_id
1594    FROM   wsh_trip_stops    wts,
1595          wsh_delivery_legs  wdl,
1596          wsh_new_deliveries wnd
1597    WHERE  wnd.delivery_id    = p_delivery_id
1598    AND   wdl.delivery_id     = wnd.delivery_id
1599    AND   wts.stop_id      = wdl.pick_up_stop_id
1600    AND   wts.stop_location_id = wnd.initial_pickup_location_id;
1601 
1602   -- bug 3642085
1603   -- Find closed stops that have pick up deliveries with lines to interface
1604   CURSOR c_stop_to_interface(p_trip_stop_id NUMBER) IS
1605    SELECT wts.stop_id
1606    FROM   wsh_trip_stops wts
1607    WHERE  wts.stop_id = p_trip_stop_id
1608    AND   wts.pending_interface_flag = 'Y'
1609    AND   nvl(wts.SHIPMENTS_TYPE_FLAG, 'O') IN  ('O', 'M');
1610 
1611   -- Find closed stops that have pick up deliveries with lines to interface
1612   CURSOR c_all_elig_stops_to_interface IS
1613    SELECT wts.stop_id
1614    FROM   wsh_trip_stops wts
1615    WHERE  wts.pending_interface_flag = 'Y'
1616    AND    nvl(wts.SHIPMENTS_TYPE_FLAG, 'O') IN  ('O', 'M')  -- J Inbound Logistics jckwok
1617    ORDER BY DECODE(wts.lock_stop_id, wts.stop_id, 1, NULL, 2, 3);
1618   -- bug 3642085
1619 
1620   -- Find closed stops that have pick up deliveries with lines to interface
1621   -- for a given organization
1622   CURSOR c_stops_org(p_organization_id NUMBER) IS
1623    SELECT DISTINCT wts.stop_id
1624    FROM   wsh_trip_stops wts,
1625           wsh_new_deliveries wnd,
1626           wsh_delivery_legs wdl
1627    WHERE   wts.pending_interface_flag = 'Y'
1628    AND   wdl.pick_up_stop_id = wts.stop_id
1629    AND   wnd.initial_pickup_location_id = wts.stop_location_id
1630    AND   wdl.delivery_id     = wnd.delivery_id
1631    AND   nvl(wts.SHIPMENTS_TYPE_FLAG, 'O') IN  ('O', 'M')
1632    AND   wnd.organization_id = p_organization_id
1633    ORDER BY  wts.stop_id;
1634 
1635 
1636   CURSOR c_batch_stop(p_batch_id NUMBER, p_trip_type VARCHAR2)IS
1637     SELECT wts.stop_id
1638     FROM   wsh_trip_stops    wts,
1639           wsh_delivery_legs  wdl,
1640           wsh_new_deliveries wnd,
1641           wsh_picking_batches wpb
1642     WHERE p_batch_id IS NOT NULL
1643     AND   wnd.batch_id    = p_batch_id
1644     AND   wdl.delivery_id     = wnd.delivery_id
1645     AND   wts.stop_id      = wdl.pick_up_stop_id
1646     AND   wts.stop_location_id = wnd.initial_pickup_location_id
1647     AND   wpb.batch_id = wnd.batch_id
1648     AND   (p_trip_type IS NULL OR
1649           (p_trip_type = 'AC' AND wpb.creation_date <= wts.creation_date) OR
1650           (p_trip_type = 'MC' AND wpb.creation_date > wts.creation_date))
1651     AND   nvl(wnd.SHIPMENT_DIRECTION , 'O') IN ('O', 'IO')   -- J Inbound Logistics jckwok
1652     ORDER BY DECODE(wts.lock_stop_id, wts.stop_id,1,
1653                 NULL,2,3);
1654 
1655 CURSOR pickup_oke_headers (p_stop_id in number) IS
1656 SELECT 1
1657 FROM   wsh_delivery_legs dg,
1658       wsh_new_deliveries dl,
1659       wsh_trip_stops st
1660 WHERE  st.stop_id = dg.pick_up_stop_id AND
1661        nvl(dl.SHIPMENT_DIRECTION , 'O') IN ('O', 'IO') AND  -- J Inbound Logistics jckwok
1662       st.stop_id = p_stop_id AND
1663       st.stop_location_id = dl.initial_pickup_location_id AND
1664       dg.delivery_id = dl.delivery_id  AND
1665 	   dl.asn_seq_number is not null
1666 	   and rownum=1;
1667 
1668 
1669 CURSOR c_get_batch IS
1670 SELECT WSH_STOP_BATCH_S.NEXTVAL
1671 FROM sys.dual;
1672 
1673 --/== Workflow Changes
1674 CURSOR  c_stop_to_del_cur_wf( p_stop_id IN NUMBER ) IS
1675 SELECT  wnd.delivery_id,
1676 	wnd.organization_id,
1677 	wnd.initial_pickup_location_id,
1678 	wnd.delivery_scpod_wf_process,
1679 	wnd.del_wf_interface_attr
1680 FROM    wsh_new_deliveries wnd,
1681 	wsh_delivery_legs wdl,
1682 	wsh_trip_stops wts
1683 WHERE   wnd.delivery_id = wdl.delivery_id
1684 AND     wdl.pick_up_stop_id = p_stop_id
1685 AND     wts.stop_id      = wdl.pick_up_stop_id
1686 AND     wts.stop_location_id = wnd.initial_pickup_location_id;
1687 
1688 l_del_entity_ids WSH_UTIL_CORE.column_tab_type;
1689 l_wf_rs        VARCHAR2(1);
1690 l_override_wf  VARCHAR2(1);
1691 l_purged_count NUMBER;
1692 e_trip_stop_wf_inprogress EXCEPTION;
1693 -- Workflow Changes ==/
1694 
1695 l_standalone VARCHAR2(1); --Standalone WMS project changes
1696 
1697 e_continue  EXCEPTION;
1698 --bsadri
1699 
1700 
1701 --
1702 l_debug_on BOOLEAN;
1703 --
1704 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'INTERFACE_ALL';
1705 --
1706 BEGIN
1707   --
1708   WSH_UTIL_CORE.Enable_Concurrent_Log_Print;
1709   WSH_UTIL_CORE.Set_Log_Level(p_log_level);
1710   --
1711   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
1712   --
1713   IF l_debug_on IS NULL
1714   THEN
1715       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
1716   END IF;
1717   --
1718   IF l_debug_on THEN
1719       WSH_DEBUG_SV.push(l_module_name);
1720       --
1721       WSH_DEBUG_SV.log(l_module_name,'P_MODE',P_MODE);
1722       WSH_DEBUG_SV.log(l_module_name,'P_STOP_ID',P_STOP_ID);
1723       WSH_DEBUG_SV.log(l_module_name,'P_DELIVERY_ID',P_DELIVERY_ID);
1724       WSH_DEBUG_SV.log(l_module_name,'P_LOG_LEVEL',P_LOG_LEVEL);
1725       WSH_DEBUG_SV.log(l_module_name,'p_organization_id',p_organization_id);
1726       WSH_DEBUG_SV.log(l_module_name,'p_stops_per_batch',p_stops_per_batch);
1727   END IF;
1728 
1729   --
1730   l_completion_status := 'NORMAL';
1731 
1732   -- If stop_id is given use this to query the stop, else if delivery_id is
1733   -- given use the delivery_id to query the stop.
1734 
1735   IF p_stops_per_batch IS NULL or p_stops_per_batch = 0 THEN
1736      l_stops_per_batch := 1;
1737   ELSIF p_stops_per_batch < 0 THEN
1738      IF l_debug_on THEN
1739          WSH_DEBUG_SV.log(l_module_name,'Error negative p_stops_per_batch',
1740                                                           p_stops_per_batch );
1741      END IF;
1742      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1743   ELSE
1744      l_stops_per_batch := p_stops_per_batch;
1745   END IF;
1746 
1747 
1748   IF l_stops_per_batch > 1 THEN --{
1749      FND_PROFILE.Get('WSH_INVOICE_NUMBERING_METHOD',l_invoicing_method);
1750 
1751      IF l_debug_on THEN
1752          WSH_DEBUG_SV.log(l_module_name,'l_invoicing_method',
1753                                                         l_invoicing_method );
1754      END IF;
1755 
1756      IF l_invoicing_method = 'D' THEN
1757         l_stops_per_batch := 1;
1758      END IF;
1759 
1760   END IF; --}
1761 
1762   --Standalone WMS project changes
1763   IF WMS_DEPLOY.WMS_DEPLOYMENT_MODE = 'D' THEN
1764     l_standalone := 'Y';
1765   ELSE
1766     l_standalone := 'N';
1767   END IF;
1768 
1769   IF l_debug_on THEN
1770       WSH_DEBUG_SV.log(l_module_name,'l_standalone',l_standalone );
1771   END IF;
1772 
1773   IF p_mode <> 'ALL' THEN
1774    l_interface_mode := p_mode;
1775   ELSE
1776    l_interface_mode := 'INV OM DSNO';
1777   END IF;
1778 
1779   IF l_standalone = 'Y' THEN  --Standalone WMS project changes
1780     l_interface_mode := 'INV DSNO';
1781     IF l_debug_on THEN
1782        WSH_DEBUG_SV.logmsg(l_module_name,  'Standalone is enabled only INV and DSNO will be run');
1783     END IF;
1784   END IF;
1785 
1786 
1787 
1788   IF p_delivery_id IS NULL THEN
1789    l_stop_id := p_stop_id;
1790   ELSE
1791    --
1792    IF l_debug_on THEN
1793        WSH_DEBUG_SV.logmsg(l_module_name,  'INTERFACETRIPSTOP: FINDING STOP FOR DELIVERY_ID ' || P_DELIVERY_ID  );
1794    END IF;
1795    --
1796    OPEN  c_delivery_stop(p_delivery_id);
1797    FETCH c_delivery_stop INTO l_stop_id;
1798    IF c_delivery_stop%NOTFOUND THEN
1799      l_stop_id := NULL;
1800    END IF;
1801    CLOSE c_delivery_stop;
1802    IF l_debug_on THEN
1803       WSH_DEBUG_SV.log(l_module_name,'l_stop_id',l_stop_id);
1804    END IF;
1805    IF l_stop_id IS NULL THEN
1806      WSH_UTIL_CORE.PrintMsg('InterfaceTripStop: cannot find stop.  Exiting.');
1807      l_completion_status := 'WARNING';
1808      goto interface_end;
1809    END IF;
1810   END IF;
1811 
1812 
1813   IF l_stop_id IS NULL THEN
1814    WSH_UTIL_CORE.PrintMsg('InterfaceTripStop: processing all eligible stops for '
1815                     || l_interface_mode);
1816   ELSE
1817    WSH_UTIL_CORE.PrintMsg('InterfaceTripStop: processing stop_id '
1818                     || TO_CHAR(l_stop_id)
1819                     || ' for ' || l_interface_mode);
1820   END IF;
1821 
1822   -- Interface Flip: do OM/DSNO before INV
1823 
1824   l_interface_names(1) := 'ORDER MANAGEMENT';
1825   l_interface_names(2) := 'DSNO';
1826   l_interface_names(3) := 'INVENTORY';
1827   FOR i IN 1..l_interface_names.COUNT LOOP
1828    l_stops_normal(i)  := 0;
1829    l_stops_warning(i)   := 0;
1830    l_stops_interfaced(i) := 0;
1831   END LOOP;
1832 
1833 
1834   IF INSTR(l_interface_mode, 'INV') > 0 THEN
1835    l_inv_interface := 1;
1836   END IF;
1837 
1838   IF INSTR(l_interface_mode, 'OM') > 0 THEN
1839    l_om_interface := 1;
1840   END IF;
1841 
1842   IF INSTR(l_interface_mode, 'DSNO') > 0 THEN
1843    l_dsno_interface := 1;
1844   END IF;
1845 
1846   IF l_debug_on THEN
1847      WSH_DEBUG_SV.log(l_module_name,'l_inv_interface',l_inv_interface);
1848      WSH_DEBUG_SV.log(l_module_name,'l_om_interface',l_om_interface);
1849      WSH_DEBUG_SV.log(l_module_name,'l_dsno_interface',l_dsno_interface);
1850      WSH_DEBUG_SV.log(l_module_name,'l_interface_mode',l_interface_mode);
1851      WSH_DEBUG_SV.log(l_module_name,'l_stop_id',l_stop_id);
1852   END IF;
1853 
1854   -- Based on input criteria open one of these cursors to query for the
1855   -- eligible trip stops.
1856   --
1857 
1858   IF p_batch_id is not null then
1859      open c_batch_stop(p_batch_id, p_trip_type);
1860   ELSIF (l_stop_id IS NULL) AND (p_organization_id is not null) THEN
1861      OPEN c_stops_org(p_organization_id);
1862   -- bug 3642085
1863   ELSIF l_stop_id is not null then
1864      open c_stop_to_interface(l_stop_id);
1865   ELSE
1866      open c_all_elig_stops_to_interface;
1867   -- bug 3642085
1868   END IF;
1869 
1870   LOOP --{
1871   BEGIN
1872 
1873     IF c_batch_stop%isopen THEN --{
1874       FETCH c_batch_stop into l_stop_id;
1875       IF c_batch_stop%NOTFOUND  THEN
1876          IF l_stop_per_batch_counter = 1 AND l_split_stops.COUNT = 0 THEN
1877             EXIT;
1878          ELSE
1879             l_batch_ready := TRUE;
1880             -- This is the case, where there are no more stops to be processed,
1881             --  but the the number of stops per batch is not satisfied.
1882             -- We mark the batch as ready, to process the remaining stops.
1883          END IF;
1884       END IF;
1885     -- bug 3642085
1886     ELSIF c_stop_to_interface%isopen THEN --}{
1887       FETCH c_stop_to_interface into l_stop_id;
1888       IF c_stop_to_interface%NOTFOUND  THEN
1889          IF l_stop_per_batch_counter = 1 AND l_split_stops.COUNT = 0 THEN
1890             EXIT;
1891          ELSE
1892             l_batch_ready := TRUE;
1893             -- This is the case, where there are no more stops to be processed,
1894             --  but the the number of stops per batch is not satisfied.
1895             -- We mark the batch as ready, to process the remaining stops.
1896          END IF;
1897        END IF;
1898     ELSIF c_all_elig_stops_to_interface%isopen THEN --}{
1899       FETCH c_all_elig_stops_to_interface into l_stop_id;
1900       IF c_all_elig_stops_to_interface%NOTFOUND  THEN
1901          IF l_stop_per_batch_counter = 1 AND l_split_stops.COUNT = 0 THEN
1902             EXIT;
1903          ELSE
1904             l_batch_ready := TRUE;
1905             -- This is the case, where there are no more stops to be processed,
1906             --  but the the number of stops per batch is not satisfied.
1907             -- We mark the batch as ready, to process the remaining stops.
1908          END IF;
1909        END IF;
1910     -- bug 3642085
1911     ELSIF c_stops_org%isopen THEN --}{
1912       FETCH c_stops_org into l_stop_id;
1913       IF c_stops_org%NOTFOUND  THEN
1914          IF l_stop_per_batch_counter = 1 AND l_split_stops.COUNT = 0 THEN
1915             EXIT;
1916          ELSE
1917             l_batch_ready := TRUE;
1918             -- This is the case, where there are no more stops to be processed,
1919             --  but the the number of stops per batch is not satisfied.
1920             -- We mark the batch as ready, to process the remaining stops.
1921          END IF;
1922        END IF; --}
1923     END IF;
1924 
1925     --/== Workflow Changes
1926     l_override_wf:= fnd_profile.value('WSH_OVERRIDE_SCPOD_WF');
1927     IF l_debug_on THEN
1928        WSH_DEBUG_SV.log(l_module_name,'l_override_wf',l_override_wf);
1929     END IF;
1930 
1931     IF (nvl(l_override_wf,'N') = 'N') THEN
1932         FOR cur_rec IN c_stop_to_del_cur_wf(l_stop_id) LOOP
1933 	    IF (cur_rec.delivery_scpod_wf_process is not null and
1934 			cur_rec.del_wf_interface_attr  = 'I') THEN
1935                 l_completion_status := 'WARNING';
1936 		RAISE e_trip_stop_wf_inprogress;
1937 	    END IF;
1938 	END LOOP;
1939     ELSE
1940     -- Override the Ship to Deliver Workflow
1941         FOR cur_rec IN c_stop_to_del_cur_wf(l_stop_id) LOOP
1942 	    IF (WSH_WF_STD.Wf_Exists('DELIVERY_C',cur_rec.delivery_id)) THEN
1943 		l_del_entity_ids(l_del_entity_ids.count +1) := cur_rec.delivery_id;
1944 		IF l_debug_on THEN
1945 		    WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WF_STD.Log_Wf_Exception', WSH_DEBUG_SV.C_PROC_LEVEL);
1946 		END IF;
1947 		WSH_WF_STD.Log_Wf_Exception(p_entity_type => 'DELIVERY',
1948 				p_entity_id             => cur_rec.delivery_id,
1949 				p_ship_from_location_id => cur_rec.initial_pickup_location_id,
1950 				p_logging_entity        => 'SHIPPER',
1951 				p_exception_name        => 'WSH_DEL_SCPOD_PURGED',
1952 				x_return_status         => l_wf_rs);
1953 		IF l_debug_on THEN
1954 		WSH_DEBUG_SV.log(l_module_name,'Return status after calling WSH_WF_STD.Log_Wf_Exception',l_wf_rs);
1955 		END IF;
1956 	    END IF;
1957 	END LOOP;
1958     END IF;
1959 
1960     -- Purging Overridden Workflows after the loop
1961     IF (l_del_entity_ids.count > 0) THEN
1962         IF l_debug_on THEN
1963             WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WF_STD.PURGE_ENTITY',WSH_DEBUG_SV.C_PROC_LEVEL);
1964         END IF;
1965         WSH_WF_STD.Purge_Entity(
1966 		p_entity_type => 'DELIVERY',
1967 		p_entity_ids  => l_del_entity_ids,
1968 		x_success_count  => l_purged_count,
1969 		x_return_status => l_wf_rs);
1970         IF l_debug_on THEN
1971             WSH_DEBUG_SV.log(l_module_name,'L_PURGED_COUNT',l_purged_count);
1972 	    WSH_DEBUG_SV.log(l_module_name,'L_WF_RS',l_wf_rs);
1973         END IF;
1974     END IF;
1975     -- Workflow Changes ==/
1976 
1977     -- Get the new batch_id for the stops (wsh_trip_stops.batch_id)
1978     IF l_stop_per_batch_counter = 1 THEN
1979        l_dsno_stop_tab.DELETE;
1980        l_stop_tab.DELETE;
1981        OPEN c_get_batch;
1982        FETCH c_get_batch INTO l_stop_batch_id;
1983        CLOSE c_get_batch;
1984     END IF;
1985 
1986    -- bug 2657859 frontport bug 2630535
1987    -- avoid deadlocks by marking stop as being processed:
1988    -- skip stops if their interface_flag is NULL or 'P'.
1989    DECLARE
1990       l_notfound BOOLEAN;
1991       l_action   VARCHAR2(100);
1992    BEGIN
1993       IF l_debug_on THEN
1994         WSH_DEBUG_SV.log(l_module_name,
1995                     'setting savepoint before_flag_change');
1996       END IF;
1997 
1998       SAVEPOINT before_flag_change;
1999 
2000       IF NOT l_batch_ready THEN --{
2001          IF l_debug_on THEN
2002            WSH_DEBUG_SV.log(l_module_name,
2003                        'locking row for ' || l_stop_id);
2004          END IF;
2005 
2006          l_action := 'locking';
2007          OPEN   lock_row(l_stop_id, 'Y');
2008          FETCH  lock_row into l_recinfo;
2009          l_notfound := lock_row%NOTFOUND;
2010          CLOSE  lock_row;
2011 
2012          l_action := 'examining';
2013 
2014          IF l_notfound THEN
2015            -- probably taken care of by another request
2016            --COMMIT;
2017            GOTO next_stop;
2018          END IF;
2019 
2020 
2021          l_action := 'updating';
2022 
2023          IF l_debug_on THEN
2024            WSH_DEBUG_SV.log(l_module_name,
2025              'updating pending_interface_flag to P for batch', l_stop_batch_id);
2026          END IF;
2027 
2028 
2029          -- mark stop as being processed; refresh its LAST_UPDATED info.
2030          UPDATE wsh_trip_stops
2031          SET    pending_interface_flag = 'P',
2032              request_id             = fnd_global.conc_request_id,
2033              last_updated_by        = fnd_global.user_id,
2034              last_update_date       = sysdate,
2035              batch_id               = l_stop_batch_id
2036          WHERE  stop_id = l_stop_id;
2037 
2038          l_stop_tab(l_stop_tab.COUNT+1) := l_stop_id;
2039 
2040          l_stops_count        := l_stops_count + 1;
2041 
2042 
2043          -- If the batch is not full, then get another stop.
2044 
2045          IF l_stop_per_batch_counter < l_stops_per_batch THEN
2046             l_stop_per_batch_counter := l_stop_per_batch_counter + 1;
2047             RAISE e_continue;
2048          END IF;
2049 
2050       END IF; --}
2051 
2052       IF (l_stops_per_batch > 1  )
2053           AND (l_stop_tab.COUNT > 1 OR l_split_stops.COUNT > 0) THEN   --{
2054          -- If some stops within this batch have lines split in WSH and
2055          -- these lines are in multiple stops, do not process these stops
2056          -- together
2057          handle_stop_lvl_splits(x_split_stops => l_split_stops,
2058                                 p_batch_id    => l_stop_batch_id,
2059                                 x_stop_tab    => l_stop_tab,
2060                                 x_return_status => l_return_status);
2061 
2062           wsh_util_core.api_post_call(
2063             p_return_status    => l_return_status,
2064             x_num_warnings     => l_num_warnings,
2065             x_num_errors       => l_num_errors);
2066 
2067       END IF; --}
2068 
2069       COMMIT;
2070       l_stop_per_batch_counter := 1; --initialize for the next batch
2071 
2072    EXCEPTION
2073     WHEN trip_stop_locked THEN
2074        -- stop is locked; probably used by another process
2075        IF l_debug_on THEN
2076          WSH_DEBUG_SV.log(l_module_name,
2077                     'stop is locked');
2078        END IF;
2079        WSH_UTIL_CORE.Println('Interface_All: skipping locked stop_id ' || l_stop_id || ' is locked.');
2080        IF lock_row%ISOPEN THEN
2081          CLOSE lock_row;
2082        END IF;
2083        --IF l_debug_on THEN
2084          --WSH_DEBUG_SV.log(l_module_name,
2085                     --'rollback to before_flag_change');
2086        --END IF;
2087        -- rollback to before_flag_change;
2088        -- why do we need rollback? nothing is updated
2089        --GOTO next_stop;
2090        RAISE e_continue;
2091 
2092     WHEN e_continue THEN
2093        RAISE e_continue;
2094 
2095     WHEN OTHERS THEN
2096        IF l_debug_on THEN
2097          WSH_DEBUG_SV.log(l_module_name,
2098                     'unhandled exception for action ' || l_action);
2099        END IF;
2100 
2101        l_completion_status := 'ERROR';
2102        l_error_code     := SQLCODE;
2103        l_error_text     := SQLERRM;
2104        WSH_UTIL_CORE.PrintMsg('Interface_ALL failed with unexpected error in ' || l_action || ' ' || l_stop_id);
2105        WSH_UTIL_CORE.PrintMsg('The unexpected error is ' || l_error_text);
2106        l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS(l_completion_status,'');
2107        errbuf := 'Interface trip stop failed with unexpected error';
2108        retcode := '2';
2109        IF lock_row%ISOPEN THEN
2110          CLOSE lock_row;
2111        END IF;
2112        rollback to before_flag_change;
2113        IF l_debug_on THEN
2114            WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2115            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
2116        END IF;
2117        RETURN;
2118    END;
2119 
2120 
2121    l_api_completion_status := 'NORMAL';
2122    l_previous_interface  := FALSE;
2123 
2124    IF l_debug_on THEN
2125        WSH_DEBUG_SV.logmsg(l_module_name,  C_STOP_SEPARATOR  );
2126    END IF;
2127    --
2128 
2129    -- The stops being processed for OM interface are stored in l_stop_tab
2130    -- the stops that are successfully processed will be stoped in
2131    -- l_dsno_stop_tab.  The stops that will be processed for inventory interface
2132    -- will be put in l_inv_stops.  Stops that cannot be processed in the current
2133    -- batch are put in l_split_stops.
2134 
2135    -- OM Interface
2136    IF   l_om_interface = 1
2137       AND l_api_completion_status = 'NORMAL' THEN --{
2138 
2139      IF l_previous_interface THEN
2140       --
2141       IF l_debug_on THEN
2142           WSH_DEBUG_SV.logmsg(l_module_name,  C_INTERFACE_SEPARATOR  );
2143       END IF;
2144       --
2145      END IF;
2146      l_previous_interface := TRUE;
2147 
2148 
2149      l_err_stops_count := 0;
2150      oe_interface_trip_stop(p_batch_id => l_stop_batch_id,
2151                             p_stop_tab => l_stop_tab,
2152                             x_stop_tab => l_dsno_stop_tab,
2153                             x_num_stops_removed => l_err_stops_count,
2154                             x_completion_status =>l_api_completion_status);
2155 
2156      --
2157      IF l_debug_on THEN
2158           WSH_DEBUG_SV.logmsg(l_module_name,  'INTERFACETRIPSTOP: RESULT OF OM INTERFACING BATCH_ID ' || TO_CHAR ( l_stop_batch_id ) || ' = ' || L_API_COMPLETION_STATUS  );
2159      END IF;
2160      --
2161 
2162      IF NVL(l_err_stops_count,0) = 0   THEN --{
2163         l_dsno_stop_tab := l_stop_tab;
2164      END IF; --}
2165 
2166       IF (l_err_stops_count > 0 )  THEN --{
2167         l_api_completion_status_bkp := 'WARNING';
2168         Update_Completion_Status(l_err_stops_count,
2169                            NULL,
2170                            l_completion_status,
2171                            l_api_completion_status_bkp,
2172                            l_stops_normal(1),
2173                            l_stops_warning(1),
2174                            l_stops_interfaced(1));
2175      END IF; --}
2176 
2177      IF (l_err_stops_count = l_dsno_stop_tab.COUNT)
2178        AND (l_err_stops_count =  l_stop_tab.COUNT) THEN
2179        -- this is the case that all the lines have failed interface to OM
2180        -- we have already called the Update_Completion_Status for this case
2181        l_stop_count := 0;
2182      ELSE
2183        l_stop_count := l_dsno_stop_tab.COUNT;
2184      END IF;
2185 
2186      Update_Completion_Status(l_stop_count ,
2187                         NULL,
2188                         l_completion_status,
2189                         l_api_completion_status,
2190                         l_stops_normal(1),
2191                         l_stops_warning(1),
2192                         l_stops_interfaced(1));
2193    ELSE --}{
2194 
2195       l_dsno_stop_tab := l_stop_tab;
2196 
2197    END IF; --}
2198    -- Start of changes for bug 114730024
2199    --Added by Xin for WSH trigger elimination #14040855 Begin
2200    IF OM_INTERFACED(p_batch_id) THEN
2201     FOR cur_rec IN c_stop_to_del_cur_wf(l_stop_id) LOOP
2202 
2203      IF l_debug_on THEN
2204        WSH_DEBUG_SV.logmsg(l_module_name,
2205        'Calling program unit WSH_WF_STD.RAISE_EVENT',
2206        WSH_DEBUG_SV.C_PROC_LEVEL);
2207      END IF;
2208 
2209      WSH_WF_STD.RAISE_EVENT(p_entity_type   =>  'DELIVERY',
2210                p_entity_id =>  cur_rec.delivery_id,
2211                p_event     => 'oracle.apps.wsh.delivery.oe.interfaced',
2212                p_organization_id =>  cur_rec.organization_id,
2213                x_return_status   =>  l_wf_rs);
2214      IF l_debug_on THEN
2215 
2216        WSH_DEBUG_SV.log(l_module_name,'Return status after
2217        calling WSH_WF_STD.RAISE_EVENT => ',l_wf_rs);
2218 
2219      END IF;
2220 
2221     END LOOP;
2222    END IF;
2223    --Added by Xin for WSH trigger elimination #14040855 End.
2224    -- End of changes for bug 14730024
2225    -- DSNO submission
2226    -- Interface only if NORMAL (avoid re-submission)
2227 
2228    l_inv_stops.DELETE;
2229    l_stop_tab.DELETE;
2230 
2231    l_tab_count := l_dsno_stop_tab.COUNT;
2232 
2233    IF l_debug_on THEN
2234       WSH_DEBUG_SV.log(l_module_name,'l_api_completion_status',
2235                                                      l_api_completion_status);
2236       WSH_DEBUG_SV.log(l_module_name,'l_previous_interface',
2237                                                      l_previous_interface);
2238       WSH_DEBUG_SV.log(l_module_name,'l_dsno_stop_tab.COUNT',
2239                                                      l_tab_count);
2240    END IF;
2241 
2242 
2243    l_api_completion_status_bkp := l_api_completion_status;
2244    l_err_stops.DELETE;
2245 
2246    IF   l_dsno_interface = 1 AND l_tab_count > 0
2247    THEN --{
2248 
2249       -- save the OM completion status
2250 
2251 
2252       x := l_dsno_stop_tab.FIRST;
2253       l_index := 1;
2254 
2255       WHILE ( x IS NOT NULL) LOOP --{
2256       --fix for 2781235.
2257       -- if there are OKE lines, then run dsno
2258       -- even if om interface was not run
2259       -- for oke line, om interface is not applicable.
2260       -- so run dsno if inv.interface is pending for oke
2261       -- lines
2262       --
2263          l_run_dsno := FALSE;
2264          --
2265          IF l_api_completion_status_bkp = 'NORMAL'
2266          THEN
2267 	     l_run_dsno := TRUE;
2268          ELSIF l_api_completion_status_bkp = 'INTERFACED'
2269          THEN
2270          --{
2271 	      l_oke_count := 0;
2272 	      --
2273               -- Only run DSNO interface if the DSNO has not been successfully
2274               -- interfaced before.
2275 
2276 	      FOR pickup_oke_headers_rec IN pickup_oke_headers(l_dsno_stop_tab(x))
2277 	      LOOP
2278 	          l_oke_count := 1;
2279 	      END LOOP;
2280 	      --
2281 	      IF l_oke_count = 0
2282 	      THEN
2283 	          l_run_dsno := TRUE;
2284 	      END IF;
2285          --}
2286          END IF;
2287          --
2288          IF l_run_dsno
2289          THEN
2290          --{
2291 
2292            IF l_previous_interface THEN
2293             --
2294             IF l_debug_on THEN
2295                 WSH_DEBUG_SV.logmsg(l_module_name,  C_INTERFACE_SEPARATOR  );
2296             END IF;
2297             --
2298            END IF;
2299            l_previous_interface := TRUE;
2300 
2301            --
2302            IF l_debug_on THEN
2303                WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DSNO.SUBMIT_TRIP_STOP',WSH_DEBUG_SV.C_PROC_LEVEL);
2304            END IF;
2305            --
2306            WSH_DSNO.Submit_Trip_Stop(l_dsno_stop_tab(x), l_api_completion_status);
2307            --
2308            IF l_debug_on THEN
2309                WSH_DEBUG_SV.logmsg(l_module_name,  'INTERFACETRIPSTOP: RESULT OF DSNO SUBMISSION FOR STOP_ID ' || TO_CHAR ( l_dsno_stop_tab(x) ) || ' = ' || L_API_COMPLETION_STATUS  );
2310            END IF;
2311            --
2312            Update_Completion_Status(1,
2313                               NULL,
2314                               l_completion_status,
2315                               l_api_completion_status,
2316                               l_stops_normal(2),
2317                               l_stops_warning(2),
2318                               l_stops_interfaced(2));
2319 
2320             IF l_api_completion_status <> 'NORMAL' THEN --{
2321                l_err_stops(l_err_stops.COUNT + 1 ) := l_dsno_stop_tab(x);
2322             ELSE
2323                l_inv_stops(l_index) := l_dsno_stop_tab(x);
2324                l_index := l_index + 1;
2325             END IF; --}
2326             --}
2327          END IF;
2328          COMMIT;
2329          x := l_dsno_stop_tab.NEXT(x);
2330       END LOOP ; --}
2331    END IF; --}
2332 
2333    IF l_err_stops.COUNT = l_dsno_stop_tab.COUNT THEN --{
2334 
2335       -- if all DSNOs failed, then set the status to ERROR for the whole batch
2336 
2337       l_api_completion_status := 'ERROR';
2338    ELSE --}{
2339       l_api_completion_status := l_api_completion_status_bkp ;
2340 
2341       IF l_err_stops.COUNT > 0 THEN --{
2342 
2343          -- set the api status to normal for the success DSNOs and filter
2344          -- out the failed ones from the batch.
2345 
2346          l_api_completion_status := 'NORMAL';
2347 
2348          --print the stops being deleted from the batch
2349 
2350          IF l_debug_on THEN
2351              x := l_err_stops.FIRST;
2352              WHILE x IS NOT NULL LOOP
2353                 WSH_DEBUG_SV.log(l_module_name,'Following stop failed DSNO and '
2354                     || ' is being removed from the batch',l_err_stops(x));
2355                 x := l_err_stops.NEXT(x);
2356             END LOOP;
2357          END IF;
2358 
2359          -- Filter out the failed stops from the batch.
2360          FORALL x IN l_err_stops.FIRST..l_err_stops.LAST
2361          UPDATE wsh_trip_stops
2362          SET pending_interface_flag = 'Y',
2363            batch_id = NULL
2364          WHERE stop_id = l_err_stops(x);
2365 
2366          COMMIT;
2367 
2368       END IF; --}
2369    END IF; --}
2370 
2371    IF l_inv_stops.COUNT = 0 THEN
2372       l_inv_stops := l_dsno_stop_tab;
2373    END IF;
2374 
2375    l_err_stops.DELETE;
2376    l_dsno_stop_tab.DELETE;
2377 
2378 
2379    -- Inventory Interface
2380    --   OK to interface if stop is already interfaced to OM
2381    IF l_debug_on THEN
2382       WSH_DEBUG_SV.log(l_module_name,'l_api_completion_status',
2383                                                      l_api_completion_status);
2384       WSH_DEBUG_SV.log(l_module_name,'l_previous_interface',
2385                                                      l_previous_interface);
2386    END IF;
2387 
2388    IF   l_inv_interface = 1
2389       AND l_api_completion_status IN ('NORMAL', 'INTERFACED') THEN
2390 
2391      IF l_previous_interface THEN
2392       --
2393       IF l_debug_on THEN
2394           WSH_DEBUG_SV.logmsg(l_module_name,  C_INTERFACE_SEPARATOR  );
2395       END IF;
2396       --
2397      END IF;
2398      l_previous_interface := TRUE;
2399 
2400      Inv_Interface_Trip_Stop(l_stop_batch_id, l_api_completion_status);
2401      --
2402      IF l_debug_on THEN
2403         WSH_DEBUG_SV.logmsg(l_module_name,  'INTERFACETRIPSTOP: RESULT OF INVENTORY INTERFACING BATCH_ID ' || TO_CHAR ( l_stop_batch_id ) || ' = ' || L_API_COMPLETION_STATUS  );
2404      END IF;
2405      --
2406      Update_Completion_Status(NULL,
2407                            l_stop_batch_id,
2408                            l_completion_status,
2409                            l_api_completion_status,
2410                            l_stops_normal(3),
2411                            l_stops_warning(3),
2412                            l_stops_interfaced(3));
2413 
2414 
2415    END IF;
2416 
2417    l_dsno_stop_tab.DELETE;
2418    l_inv_batch_table.DELETE;
2419 
2420 
2421 
2422    -- bug 2657859 frontport bug 2630535
2423    -- re-lock stop before updating its flag to 'Y' or NULL.
2424    DECLARE
2425       l_found BOOLEAN;
2426       l_action   VARCHAR2(100);
2427       l_new_flag VARCHAR2(1);
2428    BEGIN
2429       IF l_debug_on THEN
2430         WSH_DEBUG_SV.log(l_module_name,
2431                     're-lock stop to set pending_interface_flag to Y or NULL');
2432       END IF;
2433 
2434 
2435       savepoint before_flag_reset;
2436 
2437 
2438       l_action := 'checking';
2439       IF ALL_INTERFACED(l_stop_batch_id) THEN
2440         l_new_flag := NULL;  -- interfaced
2441       ELSE
2442         l_new_flag := 'Y';   -- pending further interface
2443       END IF;
2444 
2445       l_action := 'locking';
2446       OPEN   lock_batch(l_stop_batch_id, 'P');
2447       FETCH  lock_batch into l_batchinfo;
2448       l_found := lock_batch%FOUND;
2449       CLOSE  lock_batch;
2450 
2451       -- set the pending_interface_flag to 'Y' or NULL based on the out come
2452       -- of the ITS.
2453 
2454       IF l_found THEN
2455         l_action := 'updating';
2456         UPDATE wsh_trip_stops
2457         SET    pending_interface_flag = l_new_flag,
2458                   last_updated_by          = fnd_global.user_id,
2459                   last_update_date         = sysdate
2460         WHERE  batch_id = l_stop_batch_id;
2461       END IF;
2462 
2463       --/== Workflow Changes
2464       IF l_new_flag is null then
2465           FOR cur_rec IN c_stop_to_del_cur_wf(l_stop_id) LOOP
2466 	      IF l_debug_on THEN
2467 	          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WF_STD.RAISE_EVENT',WSH_DEBUG_SV.C_PROC_LEVEL);
2468 	      END IF;
2469 
2470 	      WSH_WF_STD.RAISE_EVENT(p_entity_type   =>  'DELIVERY',
2471 			       p_entity_id       =>  cur_rec.delivery_id,
2472 			       p_event           =>  'oracle.apps.wsh.delivery.gen.interfaced',
2473 			       p_organization_id =>  cur_rec.organization_id,
2474 			       x_return_status   =>  l_wf_rs);
2475 
2476 	      IF l_debug_on THEN
2477 	          WSH_DEBUG_SV.log(l_module_name,'Return status after calling WSH_WF_STD.RAISE_EVENT => ',l_wf_rs);
2478 	      END IF;
2479 	  END LOOP;
2480       END IF;
2481       -- Workflow Changes ==/
2482 
2483       COMMIT;
2484 
2485 
2486    EXCEPTION
2487      WHEN trip_stop_locked THEN
2488        -- stop is locked; probably used by another process
2489        WSH_UTIL_CORE.PrintMsg('Locking issue:  batch '|| l_stop_batch_id  || ' needs pending_interface_flag updated to ' || l_new_flag);
2490        IF lock_row%ISOPEN THEN
2491          CLOSE lock_row;
2492        END IF;
2493        IF lock_batch%ISOPEN THEN
2494          CLOSE lock_batch;
2495        END IF;
2496        rollback to before_flag_reset;
2497 
2498     WHEN OTHERS THEN
2499        IF l_debug_on THEN
2500          WSH_DEBUG_SV.log(l_module_name,
2501                        'unhandled exception for action ' || l_action);
2502        END IF;
2503        l_completion_status := 'ERROR';
2504        l_error_code     := SQLCODE;
2505        l_error_text     := SQLERRM;
2506        WSH_UTIL_CORE.PrintMsg('Interface_ALL failed with unexpected error in ' || l_action || ' ' || l_stop_batch_id);
2507        WSH_UTIL_CORE.PrintMsg('The unexpected error is ' || l_error_text);
2508        l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS(l_completion_status,'');
2509        errbuf := 'Interface trip stop failed with unexpected error';
2510        retcode := '2';
2511        IF lock_row%ISOPEN THEN
2512          CLOSE lock_row;
2513        END IF;
2514        IF lock_batch%ISOPEN THEN
2515          CLOSE lock_batch;
2516        END IF;
2517        rollback to before_flag_reset;
2518        IF l_debug_on THEN
2519            WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2520            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
2521        END IF;
2522        RETURN;
2523    END;
2524 
2525 
2526 <<next_stop>>
2527    IF l_completion_status = 'ERROR' THEN
2528      WSH_UTIL_CORE.PrintMsg('InterfaceTripStop: Stopping because of ERROR.');
2529      IF l_debug_on THEN
2530         WSH_DEBUG_SV.log(l_module_name,
2531                               'InterfaceTripStop: Stopping because of ERROR.');
2532      END IF;
2533      EXIT;
2534    END IF;
2535   EXCEPTION
2536     WHEN e_trip_stop_wf_inprogress THEN           --/== Workflow Changes
2537        -- Deliveries starting or ending at this stop are being controlled by Ship to Deliver Workflow
2538        IF l_debug_on THEN
2539          WSH_DEBUG_SV.log(l_module_name,
2540         'Ship to Deliver Workflow is enabled for one or more deliveries related to this Stop');
2541        END IF;
2542        WSH_UTIL_CORE.Println('Ship to Deliver Workflow is enabled for one or more deliveries related to this Stop');
2543        WSH_UTIL_CORE.Println('Interface_All: skipping stop_id ' || l_stop_id );
2544        --==/
2545 
2546     WHEN e_continue THEN
2547       NULL;
2548       -- continue with the next stop, this stop is locked by another process.
2549   END ;
2550   END LOOP; -- c_stops_to_interface}
2551 
2552    IF c_batch_stop%isopen THEN
2553        CLOSE c_batch_stop;
2554    -- bug 3642085
2555    ELSIF c_stop_to_interface%isopen THEN
2556        CLOSE c_stop_to_interface;
2557    ELSIF c_all_elig_stops_to_interface%isopen THEN
2558        CLOSE c_all_elig_stops_to_interface;
2559    -- bug 3642085
2560    ELSIF c_stops_org%isopen THEN
2561        CLOSE c_stops_org;
2562    END IF;
2563 
2564    --
2565    IF l_debug_on THEN
2566        WSH_DEBUG_SV.logmsg(l_module_name,  C_STOP_SEPARATOR  );
2567        WSH_DEBUG_SV.log(l_module_name,'l_stops_count',l_stops_count);
2568    END IF;
2569    --
2570 
2571   IF l_stops_count = 0 THEN
2572    WSH_UTIL_CORE.PrintMsg('InterfaceTripStop: no stop is processed because no lines are eligble for interfacing.');
2573   ELSE
2574    WSH_UTIL_CORE.PrintMsg('InterfaceTripStop: total stops processed: '
2575                     || l_stops_count);
2576 
2577    FOR i IN 1..l_interface_names.COUNT LOOP
2578      IF  l_stops_normal(i) > 0
2579        OR l_stops_warning(i) > 0
2580        OR l_stops_interfaced(i) > 0 THEN
2581        WSH_UTIL_CORE.PrintMsg('Stops processed for '
2582                         || l_interface_names(i)
2583                         || ' with status NORMAL: '
2584                         || l_stops_normal(i));
2585        WSH_UTIL_CORE.PrintMsg('Stops processed for '
2586                         || l_interface_names(i)
2587                         || ' with status WARNING: '
2588                         || l_stops_warning(i));
2589        WSH_UTIL_CORE.PrintMsg('Stops interfaced for '
2590                         || l_interface_names(i)
2591                         || ': '
2592                         || l_stops_interfaced(i));
2593        IF l_debug_on THEN
2594           WSH_DEBUG_SV.log(l_module_name,'Stops processed for '
2595                         || l_interface_names(i)
2596                         || ' with status NORMAL: '
2597                         || l_stops_normal(i));
2598           WSH_DEBUG_SV.log(l_module_name,'Stops processed for '
2599                         || l_interface_names(i)
2600                         || ' with status WARNING: '
2601                         || l_stops_warning(i));
2602           WSH_DEBUG_SV.log(l_module_name,'Stops interfaced for '
2603                         || l_interface_names(i)
2604                         || ': '
2605                         || l_stops_interfaced(i));
2606        END IF;
2607 
2608      END IF;
2609    END LOOP;
2610 
2611   END IF;
2612 
2613   <<interface_end>>
2614   l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS(l_completion_status,'');
2615   IF l_completion_status = 'NORMAL' THEN
2616     errbuf := 'Interface trip stop is completed successfully';
2617     retcode := '0';
2618   ELSIF l_completion_status = 'WARNING' THEN
2619     errbuf := 'Interface trip stop is  completed with warning';
2620     retcode := '1';
2621   ELSE
2622     errbuf := 'Interface trip stop  is completed with error';
2623     retcode := '2';
2624   END IF;
2625   --
2626   IF l_debug_on THEN
2627       WSH_DEBUG_SV.log(l_module_name,'errbuf',errbuf);
2628       WSH_DEBUG_SV.log(l_module_name,'retcode',retcode);
2629       WSH_DEBUG_SV.log(l_module_name,'l_completion_status',l_completion_status);
2630       WSH_DEBUG_SV.pop(l_module_name);
2631   END IF;
2632   --
2633   -- bug 2657859 frontport bug 2630535
2634   -- automatic cleanup of stuck stops where requests completed
2635   DECLARE
2636     l_recs  NUMBER;
2637   BEGIN
2638        IF l_debug_on THEN
2639           WSH_DEBUG_SV.log(l_module_name,
2640                     'Automatic clean up');
2641        END IF;
2642 
2643     UPDATE wsh_trip_stops wts
2644     SET    wts.pending_interface_flag = 'Y',
2645            wts.last_updated_by       = fnd_global.user_id,
2646            wts.last_update_date      = sysdate
2647     WHERE  wts.pending_interface_flag = 'P'
2648     AND    EXISTS (SELECT 'request completed'
2649                    FROM fnd_concurrent_requests fcr
2650                    WHERE  fcr.request_id = wts.request_id
2651                    AND    fcr.phase_code = 'C');
2652     l_recs := sql%rowcount;
2653 
2654        IF l_debug_on THEN
2655           WSH_DEBUG_SV.log(l_module_name,
2656                     'l_recs = ' || l_recs);
2657        END IF;
2658 
2659     COMMIT;
2660 
2661     IF l_recs > 0 THEN
2662       WSH_UTIL_CORE.PrintMsg('Cleaned up ' || to_char(l_recs) || ' stuck stops.');
2663        IF l_debug_on THEN
2664           WSH_DEBUG_SV.log(l_module_name,
2665                     'Cleaned up ' || to_char(l_recs) || ' stuck stops.');
2666        END IF;
2667 
2668     END IF;
2669 
2670   EXCEPTION
2671      WHEN OTHERS THEN
2672        NULL;  -- ignore errors from clean-up here.
2673   END;
2674 
2675   EXCEPTION
2676     WHEN OTHERS THEN
2677        l_completion_status := 'ERROR';
2678        l_error_code     := SQLCODE;
2679        l_error_text     := SQLERRM;
2680        WSH_UTIL_CORE.PrintMsg('Interface_ALL failed with unexpected error.');
2681        WSH_UTIL_CORE.PrintMsg('The unexpected error is ' || l_error_text);
2682        l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS(l_completion_status,'');
2683        errbuf := 'Interface trip stop failed with unexpected error';
2684        retcode := '2';
2685        --
2686        IF l_debug_on THEN
2687            WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2688            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
2689        END IF;
2690        --
2691 END interface_ALL;
2692 
2693 --========================================================================
2694 -- PROCEDURE : inv_interface
2695 --                  This procedure is a wrapper for Interface_AL (bug 1578251)
2696 --                  This procedure is maintained for backward compatibility
2697 --
2698 -- PARAMETERS: errbuf                  Used by the concurrent program for error
2699 --                                     messages.
2700 --             retcode                 Used by the concurrent program for return
2701 --                                     code.
2702 --             p_stop_id               Stop id to be interfaced.
2703 
2704 -- COMMENT   : This API will is a wrapper on Interface_AL to perform the INV
2705 --             interface only.
2706 --
2707 --========================================================================
2708 
2709 PROCEDURE inv_interface(errbuf out NOCOPY  varchar2,
2710                   retcode out NOCOPY  varchar2,
2711                   p_stop_id in number) is
2712                   --
2713 l_debug_on BOOLEAN;
2714                   --
2715                   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'INV_INTERFACE';
2716 
2717 l_log_level	NUMBER:=0;
2718                   --
2719 BEGIN
2720  --
2721  --
2722  l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
2723  --
2724  IF l_debug_on IS NULL
2725  THEN
2726      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
2727  END IF;
2728  --
2729  IF l_debug_on THEN
2730      WSH_DEBUG_SV.push(l_module_name);
2731      --
2732      WSH_DEBUG_SV.log(l_module_name,'P_STOP_ID',P_STOP_ID);
2733 
2734      l_log_level := 1;
2735  END IF;
2736 
2737  --
2738  Interface_All(errbuf    => errbuf,
2739             retcode  => retcode,
2740             p_mode    => 'INV',
2741             p_stop_id  => p_stop_id,
2742             p_log_level => l_log_level);
2743  IF retcode = '0' THEN
2744    errbuf := 'Inventory interface is completed successfully';
2745  ELSIF retcode = '1' THEN
2746    errbuf := 'Inventory interface is completed with warning';
2747  ELSE
2748    errbuf := 'Inventory interface is completed with error';
2749  END IF;
2750  --
2751  IF l_debug_on THEN
2752      WSH_DEBUG_SV.log(l_module_name,'errbuf',errbuf);
2753      WSH_DEBUG_SV.log(l_module_name,'retcode',retcode);
2754      WSH_DEBUG_SV.pop(l_module_name);
2755  END IF;
2756  --
2757 END inv_interface;
2758 
2759 --========================================================================
2760 -- PROCEDURE : Insert_inv_records
2761 --                  This procedure inserts records into INV tables:
2762 --                  mtl_transactions_interface ,mtl_serial_numbers_interface and
2763 --                  mtl_transaction_lots_interface
2764 --
2765 -- PARAMETERS: p_start_index           This is the start index of table
2766 --                                     p_mtl_txn_if_rec that should be used for
2767 --                                     bulk insert operations.
2768 --             p_end_index             This is the end index of table
2769 --                                     p_mtl_txn_if_rec that should be used for
2770 --                                     bulk insert operations.
2771 --             p_mtl_txn_if_rec        PLSQL table to be inserted into
2772 --                                     mtl_transactions_interface.
2773 --             p_mtl_ser_txn_if_rec    PLSQL table to be inserted into
2774 --                                     mtl_serial_numbers_interface.
2775 --             p_mtl_lot_txn_if_rec    PLSQL table to be inserted into
2776 --                                     mtl_transaction_lots_interface.
2777 --             p_def_inv_online        'Y' will defer the inventories process
2778 --                                     online API.
2779 --             x_return_status         Return status of the API.
2780 
2781 -- COMMENT   : This API is called from Interface_Detail_To_Inv and will bulk
2782 --             insert the inventory information into inventories interface
2783 --             tables.  In order to perform the bulk insert operation, within
2784 --             the rollback segment of the database, the start index and end
2785 --             index of PLSQL table p_mtl_txn_if_rec is passed.  These
2786 --             parameters identify the range within this table that needs to
2787 --             be bulk inserted.
2788 --
2789 --========================================================================
2790 
2791 PROCEDURE Insert_inv_records(
2792 	p_start_index		IN number,
2793 	p_end_index		IN number,
2794 	p_mtl_txn_if_rec      	IN WSH_SHIP_CONFIRM_ACTIONS.Mtl_txn_if_rec_type,
2795        	p_mtl_ser_txn_if_rec  	IN OUT NOCOPY Mtl_ser_txn_if_rec_type,
2796        	p_mtl_lot_txn_if_rec  	IN OUT NOCOPY Mtl_lot_txn_if_rec_type,
2797         p_def_inv_online        IN VARCHAR2,
2798 	x_return_status		OUT NOCOPY 	VARCHAR2) IS
2799 
2800 l_debug_on BOOLEAN;
2801 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'Insert_inv_records';
2802 
2803 l_return_status	varchar2(1);
2804 BEGIN
2805  l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
2806  IF l_debug_on IS NULL THEN
2807     l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
2808  END IF;
2809 
2810  IF l_debug_on THEN
2811     WSH_DEBUG_SV.push(l_module_name);
2812     WSH_DEBUG_SV.log(l_module_name,'p_start_index',p_start_index);
2813     WSH_DEBUG_SV.log(l_module_name,'p_end_index',p_end_index);
2814     WSH_DEBUG_SV.log(l_module_name,'p_mtl_txn_if_rec.count',p_mtl_txn_if_rec.source_line_id.count);
2815     WSH_DEBUG_SV.log(l_module_name,'p_mtl_ser_txn_if_rec.count',p_mtl_ser_txn_if_rec.source_line_id.count);
2816     WSH_DEBUG_SV.log(l_module_name,'p_mtl_lot_txn_if_rec.count',p_mtl_lot_txn_if_rec.source_line_id.count);
2817     WSH_DEBUG_SV.log(l_module_name,'p_def_inv_online',p_def_inv_online);
2818  END IF;
2819 
2820  x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
2821 
2822 
2823  SAVEPOINT sp_insert_inv_records;
2824 
2825  -- Bulk insert the INV information into mtl_transactions_interface
2826  IF (p_mtl_txn_if_rec.source_line_id.count > 0 ) THEN
2827     WSH_TRX_HANDLER.INSERT_ROW_BULK (
2828 	p_start_index		=>p_start_index,
2829 	p_end_index		=>p_end_index,
2830 	p_mtl_txn_if_rec 	=>p_mtl_txn_if_rec,
2831         x_return_status  	=> l_return_status);
2832 
2833      IF l_debug_on THEN
2834         WSH_DEBUG_SV.log(l_module_name,'WSH_TRX_HANDLER.INSERT_ROW_BULK l_return_status',l_return_status);
2835      END IF;
2836 
2837      IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) then
2838         raise fnd_api.g_exc_error;
2839      END IF;
2840  END IF;
2841 
2842 
2843  -- Bulk insert the serial number information into mtl_serial_numbers_interface
2844  IF (p_mtl_ser_txn_if_rec.source_line_id.count > 0 ) THEN
2845     WSH_TRXSN_HANDLER.INSERT_ROW_BULK
2846 		(p_mtl_ser_txn_if_rec => p_mtl_ser_txn_if_rec,
2847                  x_return_status  => l_return_status);
2848 
2849     IF l_debug_on THEN
2850        WSH_DEBUG_SV.log(l_module_name,'WSH_TRXSN_HANDLER.INSERT_ROW_BULK l_return_status',l_return_status);
2851     END IF;
2852 
2853     IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) then
2854         raise fnd_api.g_exc_error;
2855     END IF;
2856 
2857     p_mtl_ser_txn_if_rec.source_code.delete;
2858     p_mtl_ser_txn_if_rec.source_line_id.delete;
2859     p_mtl_ser_txn_if_rec.fm_serial_number.delete;
2860     p_mtl_ser_txn_if_rec.to_serial_number.delete;
2861     p_mtl_ser_txn_if_rec.transaction_interface_id.delete;
2862 
2863 
2864  END IF;
2865 
2866 
2867  -- Bulk insert the lot number information into mtl_transaction_lots_interface
2868  IF (p_mtl_lot_txn_if_rec.source_line_id.count > 0 ) THEN
2869     WSH_TRXLOTS_HANDLER.insert_ROW_bulk
2870 		(p_mtl_lot_txn_if_rec => p_mtl_lot_txn_if_rec,
2871                  x_return_status  => l_return_status);
2872 
2873     IF l_debug_on THEN
2874         WSH_DEBUG_SV.log(l_module_name,'WSH_TRXLOT_HANDLER.INSERT_ROW_BULK l_return_status',l_return_status);
2875     END IF;
2876 
2877     IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) then
2878         raise fnd_api.g_exc_error;
2879     END IF;
2880 
2881     p_mtl_lot_txn_if_rec.source_code.delete;
2882     p_mtl_lot_txn_if_rec.source_line_id.delete;
2883     p_mtl_lot_txn_if_rec.lot_number.delete;
2884     p_mtl_lot_txn_if_rec.trx_quantity.delete;
2885     p_mtl_lot_txn_if_rec.serial_transaction_temp_id.delete;
2886     p_mtl_lot_txn_if_rec.transaction_interface_id.delete;
2887 -- HW OPMCONV. Need to delete grade and secondary qty
2888     p_mtl_lot_txn_if_rec.grade_code.delete;
2889     p_mtl_lot_txn_if_rec.secondary_trx_quantity.delete;
2890 
2891  END IF;
2892 
2893  IF p_def_inv_online = 'Y' THEN
2894    COMMIT;
2895  END IF;
2896 
2897  IF l_debug_on THEN
2898     WSH_DEBUG_SV.pop(l_module_name);
2899  END IF;
2900 
2901 EXCEPTION
2902  WHEN FND_API.G_EXC_ERROR THEN
2903      x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR ;
2904 
2905      IF l_debug_on THEN
2906       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
2907       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_ERROR');
2908      END IF;
2909 
2910      ROLLBACK TO SAVEPOINT sp_insert_inv_records;
2911 
2912  WHEN OTHERS THEN
2913     x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2914 
2915     IF l_debug_on THEN
2916        WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is
2917  '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2918        WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
2919     END IF;
2920 
2921      ROLLBACK TO SAVEPOINT sp_insert_inv_records;
2922 END  Insert_inv_records;
2923 
2924 
2925 --========================================================================
2926 -- PROCEDURE : Interface_Detail_To_Inv
2927 --                  This procedure gathers all the information that Inventory
2928 --                  needs from Shipping system and does some additional
2929 --                  validations, then it callls Insert_inv_records to insert
2930 --                  the records into the inventories interface tables.
2931 --
2932 -- PARAMETERS: p_batch_id              The ITS batch_id for all the trip stops
2933 --                                     being processed in this batch.
2934 --             P_transaction_header_id The new trx_header_id for mtl interface
2935 --                                     table.
2936 --             x_opm_org_exist         This parameter tells the calling API if
2937 --                                     the lines being processed have OPM items
2938 --             x_non_opm_org_exist     This parameter tells the calling API if
2939 --                                     the lines being processed have non-OPM
2940 --                                     items
2941 --             x_return_status         Return status of the API
2942 
2943 -- COMMENT   : First all the information needed from shipping tables are
2944 --             bulk fetched into PLSQL table.  If there are no eligible
2945 --             lines, then return success.
2946 --             loop through the lines fetched and derive additional information
2947 --             and perform additional validations.  Mark the lines with zero
2948 --             shipped_qty as interfaced to INV.  If ship qty > 0 and the item
2949 --             is an OPM item, update the inventory with additional information
2950 --             and set these lines as interfaced to INV, otherwise if the item
2951 --             is an non-OPM item then calculate some additional info based on
2952 --             the source_code.
2953 --             populate the out parameters x_opm_org_exist, and
2954 --             x_non_opm_org_exist, to signal the calling API, whether INV API
2955 --             for non-opm items should be called or GMI API for OPM item should
2956 --             be called.
2957 --             Call Insert_inv_records to insert the records in the bulk size
2958 --             Chunks specified by profile option WSH_BULK_BATCH_SIZE.
2959 --
2960 --========================================================================
2961 
2962 -- HW OPMCONV. Removed the parameter x_opm_org_exist
2963 PROCEDURE Interface_Detail_To_Inv(
2964 	p_batch_id		IN 		NUMBER,
2965 	P_transaction_header_id	IN 		NUMBER,
2966         x_non_opm_org_exist     OUT NOCOPY      BOOLEAN,
2967 	x_return_status		OUT NOCOPY 	VARCHAR2) IS
2968 
2969 
2970 CURSOR c_order_line_info(c_order_line_id number) is
2971 SELECT source_document_type_id, source_document_id, source_document_line_id
2972 FROM   oe_order_lines_all
2973 WHERE  line_id = c_order_line_id;
2974 l_order_line_info c_order_line_info%ROWTYPE;
2975 
2976 /* Bug 1248431 added po_req_distributions.distribution_id */
2977 /* 2231732  encumbrance related stuff added */
2978 CURSOR c_po_info(c_po_line_id number, c_source_document_id number) is
2979 SELECT   destination_type_code,
2980      destination_subinventory,
2981      source_organization_id,
2982      destination_organization_id,
2983      deliver_to_location_id,
2984      pl.requisition_line_id,
2985      pd.distribution_id,
2986      pl.unit_price,
2987      nvl(pd.budget_account_id,-1)  budget_account_id,
2988      decode(nvl(pd.prevent_encumbrance_flag,'N'),'N',nvl(pd.encumbered_flag,'N'),'N') encumbered_flag
2989 FROM    po_requisition_lines_all pl,
2990      po_req_distributions_all pd
2991 WHERE pl.requisition_line_id = c_po_line_id
2992 AND     pl.requisition_header_id = c_source_document_id
2993 AND     pl.requisition_line_id = pd.requisition_line_id;
2994 l_po_info c_po_info%ROWTYPE;
2995 
2996 
2997 /* Bug 2137423: checking MTL_INTERORG_PARAMETERS to internal transaction type */
2998 CURSOR c_mtl_interorg_parameters (c_from_organization_id NUMBER , c_to_organization_id NUMBER) IS
2999    SELECT intransit_type
3000    FROM   mtl_interorg_parameters
3001    WHERE  from_organization_id = c_from_organization_id AND
3002           to_organization_id = c_to_organization_id;
3003 l_intransit_type NUMBER;
3004 
3005 -- Bug 2657652 : Added cursor c_serial_numbers
3006 -- Need to add Attributes for Bug 3628620 and then pass to INV table for insertion
3007 -- Calls Insert_Inv_Records which calls WSH_TRX_HANDLER.INSERT_ROW_BULK
3008 -- CHECK WITH INV for record structure which needs to be passed while Inserting INV records???
3009 CURSOR c_serial_numbers (c_delivery_detail_id NUMBER) IS
3010 SELECT fm_serial_number,
3011        to_serial_number,
3012        rownum, --haperf
3013        mtl_material_transactions_s.nextval seq_num,
3014        attribute_category,
3015        attribute1,
3016        attribute2,
3017        attribute3,
3018        attribute4,
3019        attribute5,
3020        attribute6,
3021        attribute7,
3022        attribute8,
3023        attribute9,
3024        attribute10,
3025        attribute11,
3026        attribute12,
3027        attribute13,
3028        attribute14,
3029        attribute15,
3030        --Bug 8467875
3031        cycles_since_mark,
3032        cycles_since_new,
3033        cycles_since_overhaul,
3034        cycles_since_repair,
3035        cycles_since_visit,
3036        c_attribute1,
3037        c_attribute10,
3038        c_attribute11,
3039        c_attribute12,
3040        c_attribute13,
3041        c_attribute14,
3042        c_attribute15,
3043        c_attribute16,
3044        c_attribute17,
3045        c_attribute18,
3046        c_attribute19,
3047        c_attribute2,
3048        c_attribute20,
3049        c_attribute3,
3050        c_attribute4,
3051        c_attribute5,
3052        c_attribute6,
3053        c_attribute7,
3054        c_attribute8,
3055        c_attribute9,
3056        d_attribute1,
3057        d_attribute10,
3058        d_attribute2,
3059        d_attribute3,
3060        d_attribute4,
3061        d_attribute5,
3062        d_attribute6,
3063        d_attribute7,
3064        d_attribute8,
3065        d_attribute9,
3066        number_of_repairs,
3067        n_attribute1,
3068        n_attribute10,
3069        n_attribute2,
3070        n_attribute3,
3071        n_attribute4,
3072        n_attribute5,
3073        n_attribute6,
3074        n_attribute7,
3075        n_attribute8,
3076        n_attribute9,
3077        territory_code,
3078        time_since_mark,
3079        time_since_new,
3080        time_since_overhaul,
3081        time_since_repair,
3082        time_since_visit,
3083        serial_attribute_category
3084        --Bug 8467875
3085 from   wsh_serial_numbers
3086 where  delivery_detail_id = c_delivery_detail_id;
3087 
3088 --Bug 13529169 added cursor to fetch the lot attribute values
3089 
3090 CURSOR c_lot_attr(c_inv_item_id NUMBER,c_organization_id NUMBER,c_lot_name VARCHAR2) IS
3091 SELECT attribute_category,
3092        attribute1,
3093        attribute2,
3094        attribute3,
3095        attribute4,
3096        attribute5,
3097        attribute6,
3098        attribute7,
3099        attribute8,
3100        attribute9,
3101        attribute10,
3102        attribute11,
3103        attribute12,
3104        attribute13,
3105        attribute14,
3106        attribute15,
3107        c_attribute1,
3108        c_attribute10,
3109        c_attribute11,
3110        c_attribute12,
3111        c_attribute13,
3112        c_attribute14,
3113        c_attribute15,
3114        c_attribute16,
3115        c_attribute17,
3116        c_attribute18,
3117        c_attribute19,
3118        c_attribute2,
3119        c_attribute20,
3120        c_attribute3,
3121        c_attribute4,
3122        c_attribute5,
3123        c_attribute6,
3124        c_attribute7,
3125        c_attribute8,
3126        c_attribute9,
3127        d_attribute1,
3128        d_attribute10,
3129        d_attribute2,
3130        d_attribute3,
3131        d_attribute4,
3132        d_attribute5,
3133        d_attribute6,
3134        d_attribute7,
3135        d_attribute8,
3136        d_attribute9,
3137        n_attribute1,
3138        n_attribute10,
3139        n_attribute2,
3140        n_attribute3,
3141        n_attribute4,
3142        n_attribute5,
3143        n_attribute6,
3144        n_attribute7,
3145        n_attribute8,
3146        n_attribute9,
3147        lot_attribute_category
3148 FROM   mtl_lot_numbers
3149 WHERE  inventory_item_id = c_inv_item_id
3150 AND    organization_id   = c_organization_id
3151 AND    lot_number        = c_lot_name;
3152 
3153 l_trx_source_type_id number := NULL;
3154 l_trx_action_id number := NULL;
3155 l_trx_type_code number := NULL;
3156 l_error_code number := NULL;
3157 l_error_text varchar2(2000) := NULL;
3158 l_req_distribution_id NUMBER := NULL;
3159 l_transfer_subinventory   VARCHAR2(10) := NULL;
3160 l_transfer_organization   NUMBER := NULL;
3161 l_ship_to_location_id   NUMBER := NULL;
3162 l_requisition_line_id    NUMBER :=NULL;
3163 l_dummy_ser_trx_interface_id number := NULL;
3164 l_trx_source_id NUMBER := NULL;
3165 l_account             NUMBER := NULL;
3166 l_account_return_status   VARCHAR2(30) := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
3167 -- HW OPMCONV. Removed OPM local variables
3168 
3169 l_return_status   varchar2(30);
3170 l_message_count       NUMBER;
3171 l_message_data      VARCHAR2(3000);
3172 
3173 -- Bug 3628620
3174 l_attribute_category VARCHAR2(30);
3175 l_attribute1         VARCHAR2(150);
3176 l_attribute2         VARCHAR2(150);
3177 l_attribute3         VARCHAR2(150);
3178 l_attribute4         VARCHAR2(150);
3179 l_attribute5         VARCHAR2(150);
3180 l_attribute6         VARCHAR2(150);
3181 l_attribute7         VARCHAR2(150);
3182 l_attribute8         VARCHAR2(150);
3183 l_attribute9         VARCHAR2(150);
3184 l_attribute10        VARCHAR2(150);
3185 l_attribute11        VARCHAR2(150);
3186 l_attribute12        VARCHAR2(150);
3187 l_attribute13        VARCHAR2(150);
3188 l_attribute14        VARCHAR2(150);
3189 l_attribute15        VARCHAR2(150);
3190 
3191 -- End of Bug 3628620
3192 
3193 -- bug 1651076
3194 l_source_code  varchar2(40) := NULL;
3195 
3196 /* H Integration: 940/945 cogs wrudge */
3197 l_ship_params                      WSH_SHIPPING_PARAMS_PVT.Parameter_Rec_Typ;
3198 l_sp_ret_status                    VARCHAR2(1);
3199 
3200 
3201 -- Bug 2231732 encumbrance enhancement
3202 l_encumbrance_account  number := NULL;
3203 l_encumbrance_amount  number := NULL;
3204 
3205 -- Bug 4538005
3206   l_intransit_time         NUMBER;
3207   l_session_id          NUMBER;
3208 
3209 l_serial_count NUMBER;
3210 
3211 l_debug_on BOOLEAN;
3212 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'INTERFACE_DETAIL_TO_INV';
3213 
3214 CURSOR c_convert_locId (v_location_id NUMBER) IS
3215 SELECT source_location_id
3216 FROM   wsh_locations
3217 WHERE  wsh_location_id = v_location_id;
3218 
3219 --HVOP heali
3220 l_mtl_txn_if_rec	 	Mtl_txn_if_rec_type;
3221 l_mtl_ser_txn_if_rec  	Mtl_ser_txn_if_rec_type;
3222 l_mtl_lot_txn_if_rec  	Mtl_lot_txn_if_rec_type;
3223 
3224 
3225 --haperf
3226 CURSOR c_details_for_interface(p_batch_id number) IS
3227 SELECT source_code,
3228        source_header_id,
3229        source_line_id,
3230        inventory_item_id,
3231        subinventory,
3232        trx_quantity,
3233        trx_date,
3234        organization_id,
3235        trx_source_id,
3236        trx_source_type_id,
3237        trx_action_id,
3238        trx_type_id,
3239        distribution_account_id,
3240        trx_reference,
3241        trx_header_id,
3242        trx_source_line_id,
3243        trx_source_delivery_id,
3244        revision,
3245        locator_id,
3246        picking_line_id,
3247        transfer_subinventory,
3248        transfer_organization,
3249        ship_to_location_id,
3250        requisition_line_id,
3251        requisition_distribution_id,
3252        trx_uom,
3253        mtl_material_transactions_s.nextval trx_interface_id,
3254        shipment_number,
3255        expected_arrival_date,
3256        encumbrance_account,
3257        encumbrance_amount,
3258        movement_id,
3259        freight_code,
3260        waybill_airbill,
3261        content_lpn_id,
3262        requested_quantity,
3263        inv_interfaced_flag,
3264        ship_method_code,
3265        cycle_count_quantity,
3266        src_requested_quantity_uom,
3267        transaction_temp_id,
3268        lot_number,
3269        serial_number,
3270        to_serial_number,
3271        trip_id,
3272 -- HW OPMCONV. No need for sublot anymore
3273 --     sublot_number,
3274        ship_tolerance_above,
3275        ship_tolerance_below,
3276        src_requested_quantity,
3277        org_id,
3278        trx_quantity2,
3279        error_flag,
3280 -- HW OPMCONV. Retrieve grade and uom2
3281        preferred_grade,
3282        requested_quantity_uom2,
3283 --added for BUG 4538005
3284        ship_from_location_id,
3285        ship_to_site_use_id
3286 --
3287 FROM (SELECT dd.source_code,
3288        dd.source_header_id,
3289        dd.source_line_id,
3290        dd.inventory_item_id,
3291        dd.subinventory,
3292        dd.shipped_quantity 	trx_quantity,
3293        st.actual_departure_date trx_date,
3294        dd.organization_id,
3295        NULL			trx_source_id,
3296        NULL			trx_source_type_id,
3297        NULL			trx_action_id,
3298        NULL			trx_type_id,
3299        NULL			distribution_account_id,
3300        dd.source_header_id	trx_reference,
3301        NULL			trx_header_id,
3302        dd.source_line_id	trx_source_line_id,
3303        dl.delivery_id 		trx_source_delivery_id,
3304        dd.revision,
3305        dd.locator_id,
3306        dd.delivery_detail_id	picking_line_id,
3307        NULL			transfer_subinventory,
3308        NULL			transfer_organization,
3309        dd.ship_to_location_id	ship_to_location_id,
3310        NULL			requisition_line_id,
3311        NULL			requisition_distribution_id,
3312        dd.requested_quantity_uom trx_uom,
3313        --haperf NULL			trx_interface_id,
3314        dl.name			shipment_number,
3315        dl.ultimate_dropoff_date expected_arrival_date,
3316        NULL			encumbrance_account,
3317        NULL			encumbrance_amount,
3318        dd.movement_id,
3319        wcv.freight_code		freight_code,
3320        dl.waybill		waybill_airbill,
3321        dd1.lpn_id		content_lpn_id,
3322        ---
3323        dd.requested_quantity,
3324        dd.inv_interfaced_flag,
3325        tr.ship_method_code,
3326        dd.cycle_count_quantity,
3327        dd.src_requested_quantity_uom,
3328        dd.transaction_temp_id,
3329        dd.lot_number,
3330        dd.serial_number,
3331        dd.to_serial_number,
3332        st.trip_id,
3333 -- HW OPMCONV. No need for sublot anymore
3334 --     dd.sublot_number,
3335        dd.ship_tolerance_above,
3336        dd.ship_tolerance_below,
3337        dd.src_requested_quantity,
3338        dd.org_id,
3339 -- HW OPM 3064890 added trx_quantity2
3340        dd.shipped_quantity2     trx_quantity2,
3341        'N' error_flag,
3342 -- HW OPMCONV. Retrieve grade and uom2
3343        dd.preferred_grade,
3344        dd.requested_quantity_uom2,
3345 --added for BUG 4538005
3346        dd.ship_from_location_id  ship_from_location_id,
3347        dd.ship_to_site_use_id   ship_to_site_use_id
3348 --
3349 FROM    wsh_delivery_details dd,
3350         wsh_delivery_assignments_v da,
3351 	wsh_delivery_legs dg,
3352         wsh_new_deliveries dl,
3353         wsh_trip_stops st,
3354 	wsh_trips tr,
3355         wsh_carriers wcv,
3356         wsh_delivery_details dd1,
3357         wsh_delivery_assignments_v da1
3358 WHERE   st.stop_id = dg.pick_up_stop_id
3359 AND     st.batch_id = p_batch_id
3360 AND     st.stop_location_id = dl.initial_pickup_location_id
3361 AND     dg.delivery_id = dl.delivery_id
3362 AND     da.delivery_id = dl.delivery_id
3363 AND     dd.delivery_detail_id = da.delivery_detail_id
3364 AND     st.trip_id = tr.trip_id
3365 AND     dd.container_flag = 'N'
3366 AND     dd.source_code <> 'RTV'    -- RTV changes
3367 AND     dd.inv_interfaced_flag = 'N'
3368 AND     dd.released_status <> 'D'
3369 AND     nvl(dd.line_direction,'O') in ('O','IO')
3370 AND     tr.carrier_id = wcv.carrier_id (+)
3371 AND     dd.delivery_detail_id=da1.delivery_detail_id
3372 AND     da1.parent_delivery_detail_id = dd1.delivery_detail_id(+)
3373 ORDER BY dd.organization_id,
3374 	 dd.source_header_id,
3375 	 dd.ship_to_location_id);
3376 --haperf
3377 
3378 --added for 4538005
3379  CURSOR get_session_id IS
3380   SELECT mrp_atp_schedule_temp_s.nextVal
3381   FROM dual;
3382 
3383 
3384 
3385 CURSOR get_interface_id IS
3386  SELECT mtl_material_transactions_s.nextval
3387  FROM sys.dual;
3388 
3389 
3390 -- FP bug 4166635: cursor to look up trip's freight carrier
3391 --              for frontporting bug 4145337 / 3901066.
3392 CURSOR c_freight_code(p_ship_method_code varchar2,
3393                       p_organization_id number) is
3394 SELECT wcv.freight_code freight_code
3395 FROM wsh_carrier_services wcs,
3396      wsh_org_carrier_services wocs,
3397      wsh_carriers_v wcv
3398 WHERE wcs.carrier_service_id = wocs.carrier_service_id AND
3399       wcs.carrier_id = wcv.carrier_id AND
3400       wcs.ship_method_code = p_ship_method_code AND
3401       wocs.organization_id = p_organization_id;
3402 
3403 -- FP bug 4166635: cursor to look up delivery's freight carrier
3404 CURSOR c_freight_code_del(p_delivery_id  number) is
3405 SELECT wc.freight_code
3406  FROM  wsh_new_deliveries wnd,
3407        wsh_carriers wc
3408  WHERE wnd.delivery_id = p_delivery_id AND
3409        wc.carrier_id = wnd.carrier_id;
3410 
3411 -- FP bug 4166635: cache single records for the default freight code
3412 l_cache_trip_sm     WSH_TRIPS.SHIP_METHOD_CODE%TYPE;
3413 l_cache_trip_org_id NUMBER;
3414 l_cache_trip_fc     WSH_CARRIERS.FREIGHT_CODE%TYPE;
3415 l_cache_del_id      NUMBER;
3416 l_cache_del_fc      WSH_CARRIERS.FREIGHT_CODE%TYPE;
3417 
3418 
3419 
3420 -- Define this recode type to pass to GMI_Shipping_Util.GMI_UPDATE_SHIPMENT_TXN api.
3421 -- HW OPMCONV. Removed all OPM local variables
3422 l_delivery_detail_tbl		WSH_BULK_TYPES_GRP.tbl_num;
3423 
3424 e_line_error			EXCEPTION;
3425 e_line_warning			EXCEPTION;
3426 l_row_count			NUMBER:=0;
3427 l_ser_count			NUMBER:=0;
3428 l_lot_count			NUMBER:=0;
3429 l_index				NUMBER;
3430 l_error_count			NUMBER:=0;
3431 l_warning_count			NUMBER:=0;
3432 l_prev_source_header_id		NUMBER;
3433 l_prev_ship_to_location_id	NUMBER;
3434 l_prev_organization_id		NUMBER;
3435 l_org_type			VARCHAR2(30);
3436 l_interface_serial		boolean :=false;
3437 l_interface_lot			boolean :=false;
3438 l_bulk_count 			number := 0;
3439 l_bulk_batch_size 		number;
3440 l_start_index			number:=0;
3441 l_insert_inv_calls		number:=0;
3442 l_insert_inv_not_success		number:=0;
3443 --HVOP heali
3444 l_def_inv_online                VARCHAR2(10);
3445 
3446 
3447 BEGIN
3448  l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
3449 
3450  IF l_debug_on IS NULL THEN
3451        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
3452  END IF;
3453 
3454  IF l_debug_on THEN
3455        WSH_DEBUG_SV.push(l_module_name);
3456        WSH_DEBUG_SV.log(l_module_name,'batch_id',p_batch_id);
3457        WSH_DEBUG_SV.log(l_module_name,'P_TRANSACTION_HEADER_ID',P_TRANSACTION_HEADER_ID);
3458  END IF;
3459 
3460  x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
3461  -- HW OPMCONV. Removed OPM variables
3462 
3463 
3464  --Bulk fetch c_details_for_interface INTO l_mtl_txn_if_rec;
3465  OPEN c_details_for_interface(p_batch_id);
3466  FETCH c_details_for_interface BULK COLLECT
3467        INTO -- l_mtl_txn_if_rec.;  -- replaced due to 8.1.7.4 pl/sql bug 3286811
3468          l_mtl_txn_if_rec.source_code		,
3469          l_mtl_txn_if_rec.source_header_id       ,
3470          l_mtl_txn_if_rec.source_line_id		,
3471          l_mtl_txn_if_rec.inventory_item_id      ,
3472          l_mtl_txn_if_rec.subinventory           ,
3473          l_mtl_txn_if_rec.trx_quantity           ,
3474          l_mtl_txn_if_rec.trx_date               ,
3475          l_mtl_txn_if_rec.organization_id        ,
3476          l_mtl_txn_if_rec.trx_source_id          ,
3477          l_mtl_txn_if_rec.trx_source_type_id     ,
3478          l_mtl_txn_if_rec.trx_action_id          ,
3479          l_mtl_txn_if_rec.trx_type_id            ,
3480          l_mtl_txn_if_rec.distribution_account_id,
3481          l_mtl_txn_if_rec.trx_reference          ,
3482          l_mtl_txn_if_rec.trx_header_id          ,
3483          l_mtl_txn_if_rec.trx_source_line_id     ,
3484          l_mtl_txn_if_rec.trx_source_delivery_id ,
3485          l_mtl_txn_if_rec.revision              	,
3486          l_mtl_txn_if_rec.locator_id             ,
3487          l_mtl_txn_if_rec.picking_line_id        ,
3488          l_mtl_txn_if_rec.transfer_subinventory  ,
3489          l_mtl_txn_if_rec.transfer_organization  ,
3490          l_mtl_txn_if_rec.ship_to_location_id    ,
3491          l_mtl_txn_if_rec.requisition_line_id    ,
3492          l_mtl_txn_if_rec.requisition_distribution_id,
3493          l_mtl_txn_if_rec.trx_uom              	,
3494          l_mtl_txn_if_rec.trx_interface_id       ,
3495          l_mtl_txn_if_rec.shipment_number        ,
3496          l_mtl_txn_if_rec.expected_arrival_date  ,
3497          l_mtl_txn_if_rec.encumbrance_account    ,
3498          l_mtl_txn_if_rec.encumbrance_amount     ,
3499          l_mtl_txn_if_rec.movement_id            ,
3500          l_mtl_txn_if_rec.freight_code           ,
3501          l_mtl_txn_if_rec.waybill_airbill        ,
3502 	 l_mtl_txn_if_rec.content_lpn_id		,
3503          l_mtl_txn_if_rec.requested_quantity	,
3504          l_mtl_txn_if_rec.inv_interfaced_flag	,
3505          l_mtl_txn_if_rec.ship_method_code	,
3506          l_mtl_txn_if_rec.cycle_count_quantity	,
3507          l_mtl_txn_if_rec.src_requested_quantity_uom,
3508          l_mtl_txn_if_rec.transaction_temp_id	,
3509          l_mtl_txn_if_rec.lot_number		,
3510          l_mtl_txn_if_rec.serial_number		,
3511          l_mtl_txn_if_rec.to_serial_number	,
3512          l_mtl_txn_if_rec.trip_id		,
3513 -- HW OPMCONV. No need for sublot anymore
3514 --       l_mtl_txn_if_rec.sublot_number		,
3515          l_mtl_txn_if_rec.ship_tolerance_above	,
3516          l_mtl_txn_if_rec.ship_tolerance_below	,
3517          l_mtl_txn_if_rec.src_requested_quantity	,
3518          l_mtl_txn_if_rec.org_id			,
3519          l_mtl_txn_if_rec.trx_quantity2          ,
3520          l_mtl_txn_if_rec.error_flag		,
3521 -- HW OPMCONV - Added grade and UOM2
3522          l_mtl_txn_if_rec.GRADE_CODE          ,
3523          l_mtl_txn_if_rec.SECONDARY_TRX_UOM,
3524 --Added for Bug 4538005
3525 	 l_mtl_txn_if_rec.ship_from_location_id,
3526 	 l_mtl_txn_if_rec.ship_to_site_use_id
3527 --
3528 	 ;
3529 
3530  l_row_count := c_details_for_interface%ROWCOUNT;
3531  CLOSE c_details_for_interface;
3532 
3533 
3534  FND_PROFILE.Get('WSH_BULK_BATCH_SIZE',l_bulk_batch_size);
3535  FND_PROFILE.Get('WSH_DEFER_INV_PR_ONLINE',l_def_inv_online);
3536 
3537  IF l_debug_on THEN
3538        WSH_DEBUG_SV.log(l_module_name,'No of record fetch',l_row_count);
3539        WSH_DEBUG_SV.log(l_module_name,'l_bulk_batch_size',l_bulk_batch_size);
3540        WSH_DEBUG_SV.log(l_module_name,'l_def_inv_online',l_def_inv_online);
3541  END IF;
3542 
3543  l_index := l_mtl_txn_if_rec.picking_line_id.FIRST;
3544  IF nvl(l_index,0) = 0 THEN
3545      -- perhaps the inventory transaction manager is processing this
3546      x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
3547      IF l_debug_on THEN
3548          WSH_DEBUG_SV.log(l_module_name,'No Delivery Detail Found',l_index);
3549          WSH_DEBUG_SV.pop(l_module_name);
3550      END IF;
3551      RETURN;
3552  END IF;
3553 
3554  l_start_index := l_index;
3555 
3556  -- FP bug 4166635: reset the cache for default freight code
3557  l_cache_trip_sm     := FND_API.G_MISS_CHAR;
3558  l_cache_trip_org_id := FND_API.G_MISS_NUM;
3559  l_cache_trip_fc     := NULL;
3560  l_cache_del_id      := FND_API.G_MISS_NUM;
3561  l_cache_del_fc      := NULL;
3562 
3563 
3564  WHILE l_index is not null LOOP  -- {
3565  BEGIN
3566   IF l_debug_on THEN
3567      WSH_DEBUG_SV.log(l_module_name,'delivery_detail_id',l_mtl_txn_if_rec.picking_line_id(l_index));
3568      WSH_DEBUG_SV.log(l_module_name,'trx_interface_id',l_mtl_txn_if_rec.trx_interface_id(l_index));
3569      WSH_DEBUG_SV.log(l_module_name,'freight_code',l_mtl_txn_if_rec.freight_code(l_index));
3570      WSH_DEBUG_SV.log(l_module_name,'content_lpn_id',l_mtl_txn_if_rec.content_lpn_id(l_index));
3571   END IF;
3572 
3573   IF l_mtl_txn_if_rec.content_lpn_id(l_index) IS NULL then
3574      IF l_debug_on THEN
3575         WSH_DEBUG_SV.logmsg(l_module_name,'LPN ID IS NULL FOR THE PARENT CONTAINER OF LINE '
3576                   ||l_mtl_txn_if_rec.picking_line_id(l_index));
3577      END IF;
3578   END IF;
3579   --- 1:
3580 
3581   ---2:
3582   -- check for Actual Departure Date
3583   IF l_mtl_txn_if_rec.trx_date(l_index) IS NULL THEN
3584      WSH_UTIL_CORE.PrintMsg('Actual Departure Date of Trip Stop in batch '|| p_batch_id ||' is NULL');
3585      IF l_debug_on THEN
3586         WSH_DEBUG_SV.log(l_module_name, 'Actual Departure Date of Trip Stop is NULL in batch ',p_batch_id);
3587      END IF;
3588 
3589      raise e_line_error;
3590   END IF;
3591   ---2:
3592     --Bug 9611416 check for Actual Departure Date > sysdate
3593   IF l_mtl_txn_if_rec.trx_date(l_index) > sysdate THEN
3594      WSH_UTIL_CORE.PrintMsg('Actual Departure Date of Trip Stop in batch '|| p_batch_id ||' is a future date');
3595      IF l_debug_on THEN
3596         WSH_DEBUG_SV.log(l_module_name, 'Actual Departure Date of Trip Stop is a future date',l_mtl_txn_if_rec.trx_date(l_index));
3597         WSH_DEBUG_SV.log(l_module_name, 'Delivery Detail id ',l_mtl_txn_if_rec.picking_line_id(l_index));
3598      END IF;
3599 
3600      raise e_line_warning;
3601   END IF;
3602 
3603   ---3:
3604   -- Set the lines with  shipped_qty=0, as interfaced to INV
3605   IF l_debug_on THEN
3606      WSH_DEBUG_SV.log(l_module_name,'Shipped_qty',l_mtl_txn_if_rec.trx_quantity(l_index));
3607      WSH_DEBUG_SV.log(l_module_name,'Shipped_qty',l_mtl_txn_if_rec.inv_interfaced_flag(l_index));
3608   END IF;
3609   IF NVL(l_mtl_txn_if_rec.trx_quantity(l_index), 0) = 0 THEN
3610      IF NVL(l_mtl_txn_if_rec.inv_interfaced_flag(l_index), 'N') <> 'Y' THEN
3611 
3612         l_delivery_detail_tbl(l_delivery_detail_tbl.count + 1) := l_mtl_txn_if_rec.picking_line_id(l_index);
3613         IF l_debug_on THEN
3614                WSH_DEBUG_SV.logmsg(l_module_name, 'HAVE SET THE INV_INTERFACED_FLAG TO '|| C_INV_INT_FULL ||
3615                     ' FOR DELIVERY DETAIL ' ||l_mtl_txn_if_rec.picking_line_id(l_index));
3616         END IF;
3617      END IF;
3618   END IF;
3619   ---3:
3620 
3621 
3622   ---4:
3623   IF (NVL(l_mtl_txn_if_rec.trx_quantity(l_index),0) > 0 ) AND    --{
3624         ( UPPER(NVL(l_mtl_txn_if_rec.inv_interfaced_flag(l_index),'N')) <> c_inv_int_full) THEN
3625 
3626 
3627 -- HW BUG#:3999479   - Always make it TRUE
3628      x_non_opm_org_exist := TRUE;
3629 
3630 
3631      -- FP bug 4166635:
3632      -- Freight code is being passed to inventory using the following logic :
3633      --        If freight_code populated at the  trip, then pass it
3634      --        else if Ship_method populated at trip, then get the freight code
3635      --        else if freght_method populated at delivery , use it
3636      --         (Generally Ship method or carrier_id will not null at trip )
3637      IF l_mtl_txn_if_rec.freight_code(l_index) IS NULL THEN  --{
3638 
3639        IF l_mtl_txn_if_rec.ship_method_code(l_index) IS NOT NULL THEN
3640 
3641          IF    l_mtl_txn_if_rec.ship_method_code(l_index) <> l_cache_trip_sm
3642             OR l_mtl_txn_if_rec.organization_id(l_index)  <> l_cache_trip_org_id THEN
3643            l_cache_trip_sm     := l_mtl_txn_if_rec.ship_method_code(l_index);
3644            l_cache_trip_org_id := l_mtl_txn_if_rec.organization_id(l_index);
3645            IF l_debug_on THEN
3646             WSH_DEBUG_SV.log(l_module_name, 'looking up freight carrier for trip ship method', l_cache_trip_sm);
3647             WSH_DEBUG_SV.log(l_module_name, 'and organization_id', l_cache_trip_org_id);
3648            END IF;
3649            OPEN c_freight_code(l_mtl_txn_if_rec.ship_method_code(l_index),
3650                                l_mtl_txn_if_rec.organization_id(l_index));
3651            FETCH c_freight_code into l_cache_trip_fc;
3652            IF c_freight_code%NOTFOUND THEN
3653              IF l_debug_on THEN
3654               WSH_DEBUG_SV.logmsg(l_module_name, 'c_freight_code record not found');
3655              END IF;
3656              l_cache_trip_fc := NULL;
3657            END IF;
3658            CLOSE c_freight_code;
3659          END IF;
3660 
3661          IF l_debug_on THEN
3662            WSH_DEBUG_SV.log(l_module_name, 'defaulting freight_code with l_cache_trip_fc', l_cache_trip_fc);
3663          END IF;
3664          l_mtl_txn_if_rec.freight_code(l_index) := l_cache_trip_fc;
3665 
3666        ELSE
3667 
3668          IF l_mtl_txn_if_rec.trx_source_delivery_id(l_index) <> l_cache_del_id THEN
3669            l_cache_del_id := l_mtl_txn_if_rec.trx_source_delivery_id(l_index);
3670            IF l_debug_on THEN
3671              WSH_DEBUG_SV.log(l_module_name, 'looking up freight carrier for delivery', l_cache_del_id);
3672            END IF;
3673            OPEN c_freight_code_del(l_mtl_txn_if_rec.trx_source_delivery_id(l_index) ) ;
3674            FETCH c_freight_code_del into l_cache_del_fc;
3675            IF c_freight_code_del%NOTFOUND THEN
3676              IF l_debug_on THEN
3677                WSH_DEBUG_SV.logmsg(l_module_name, 'c_freight_code_del record not found');
3678              END IF;
3679              l_cache_del_fc := NULL;
3680            END IF;
3681            CLOSE c_freight_code_del;
3682          END IF;
3683 
3684          IF l_debug_on THEN
3685            WSH_DEBUG_SV.log(l_module_name, 'defaulting freight_code with l_cache_del_fc', l_cache_del_fc);
3686          END IF;
3687          l_mtl_txn_if_rec.freight_code(l_index) := l_cache_del_fc;
3688 
3689        END IF;
3690      END IF ; --} l_mtl_txn_if_rec.freight_code(l_index) IS NULL
3691 
3692         -- fabdi end : SHIPPING PIECE 12/09/2000
3693        /* getting the source_document_type id to see if it is an internal order or not */
3694        /* get order line info to decide if this is part of an internal order */
3695        IF l_debug_on THEN
3696           WSH_DEBUG_SV.log(l_module_name,'source_code',l_mtl_txn_if_rec.source_code(l_index));
3697           WSH_DEBUG_SV.log(l_module_name,'ont_source_code', WSH_SHIP_CONFIRM_ACTIONS.ont_source_code);
3698        END IF;
3699 
3700        -- for non-opm items derive additional information, based on the
3701        -- source_code
3702 
3703        IF ( l_mtl_txn_if_rec.source_code(l_index) = 'OE' ) THEN --{
3704 
3705          IF (WSH_SHIP_CONFIRM_ACTIONS.ont_source_code is NULL) THEN
3706             WSH_SHIP_CONFIRM_ACTIONS.ont_source_code := FND_PROFILE.VALUE('ONT_SOURCE_CODE');
3707          END IF;
3708 
3709          l_source_code := WSH_SHIP_CONFIRM_ACTIONS.ont_source_code;
3710          --
3711          IF l_debug_on THEN
3712              WSH_DEBUG_SV.log(l_module_name,'l_source_code',l_source_code);
3713              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit INV_SALESORDER.GET_SALESORDER_FOR_OEHEADER',
3714                                                                              WSH_DEBUG_SV.C_PROC_LEVEL);
3715          END IF;
3716          --
3717          IF (nvl(l_prev_source_header_id,-99) <> l_mtl_txn_if_rec.source_header_id(l_index)) THEN
3718             l_trx_source_id := INV_SALESORDER.GET_SALESORDER_FOR_OEHEADER
3719 					( l_mtl_txn_if_rec.source_header_id(l_index));
3720          END IF;
3721          l_prev_source_header_id:=  l_mtl_txn_if_rec.source_header_id(l_index);
3722          --
3723          IF l_debug_on THEN
3724              WSH_DEBUG_SV.logmsg(l_module_name,  'FOUND MTL ORDER LINE: ' ||L_TRX_SOURCE_ID  );
3725          END IF;
3726          --
3727          OPEN c_order_line_info(l_mtl_txn_if_rec.source_line_id(l_index));
3728          FETCH c_order_line_info into l_order_line_info;
3729          IF (c_order_line_info%NOTFOUND) THEN
3730             CLOSE c_order_line_info;
3731             WSH_UTIL_CORE.PrintMsg('Sales order not valid');
3732             IF l_debug_on THEN
3733                 WSH_DEBUG_SV.log(l_module_name,'Sales order not valid');
3734             END IF;
3735             raise e_line_error;
3736          END if;
3737          CLOSE c_order_line_info;
3738 
3739          -- bug 1656291
3740          IF l_debug_on THEN
3741             WSH_DEBUG_SV.log(l_module_name,'source_document_type_id',l_order_line_info.source_document_type_id);
3742             WSH_DEBUG_SV.log(l_module_name,'source_document_id',l_order_line_info.source_document_id);
3743             WSH_DEBUG_SV.log(l_module_name,'source_document_line_id',l_order_line_info.source_document_line_id);
3744          END IF;
3745 
3746          IF (l_order_line_info.source_document_type_id = 10) THEN
3747             IF l_debug_on THEN
3748                 WSH_DEBUG_SV.logmsg(l_module_name, 'THIS LINE IS PART OF AN INTERNAL ORDER' );
3749             END IF;
3750 
3751             OPEN c_po_info(l_order_line_info.source_document_line_id, l_order_line_info.source_document_id);
3752             FETCH c_po_info into l_po_info;
3753             IF c_po_info%NOTFOUND THEN
3754               CLOSE c_po_info;
3755               WSH_UTIL_CORE.PrintMsg('Requisition line not found');
3756               IF l_debug_on THEN
3757                   WSH_DEBUG_SV.log(l_module_name,'Requisition line not found');
3758               END IF;
3759               raise e_line_error;
3760             END IF;
3761             CLOSE c_po_info;
3762 
3763             IF l_debug_on THEN
3764                 WSH_DEBUG_SV.logmsg(l_module_name,'REQUISITION LINE ID:'||L_ORDER_LINE_INFO.SOURCE_DOCUMENT_LINE_ID);
3765                 WSH_DEBUG_SV.log(l_module_name, 'encumbered_flag', l_po_info.encumbered_flag );
3766                 WSH_DEBUG_SV.log(l_module_name, 'budget_account_id', l_po_info.budget_account_id);
3767                 WSH_DEBUG_SV.log(l_module_name, 'unit_price', l_po_info.unit_price);
3768             END IF;
3769 
3770             ---  2231732  encumbrance enhancement
3771             If l_po_info.encumbered_flag = 'Y' then
3772                l_encumbrance_account := l_po_info.budget_account_id;
3773                ---- Bug #2813401 : Converting  the shipped qty to ordered  qty UOM
3774                l_encumbrance_amount := (wsh_wv_utils.convert_uom( l_mtl_txn_if_rec.trx_uom(l_index),
3775                                           l_mtl_txn_if_rec.src_requested_quantity_uom(l_index),
3776                                           l_mtl_txn_if_rec.trx_quantity(l_index),
3777                                           l_mtl_txn_if_rec.inventory_item_id(l_index))* l_po_info.unit_price);
3778             end if;
3779             --
3780             IF l_debug_on THEN
3781                    WSH_DEBUG_SV.logmsg(l_module_name,
3782          		'DEST_TYPE_CODE:' ||
3783 			L_PO_INFO.DESTINATION_TYPE_CODE ||
3784 			' SOURCE ORG ID:' ||
3785 			L_PO_INFO.SOURCE_ORGANIZATION_ID ||
3786 			' DEST ORG ID:' ||
3787 			L_PO_INFO.DESTINATION_ORGANIZATION_ID ||
3788 			' ENCUMBRANCE UNIT PRICE:' ||
3789 			TO_CHAR ( L_PO_INFO.UNIT_PRICE ) ||
3790 			' ENCUMBRANCE ACCOUNT:'
3791 			||TO_CHAR ( L_PO_INFO.BUDGET_ACCOUNT_ID )
3792 			|| ' ENCUMBERED FLAG: '
3793 			|| L_PO_INFO.ENCUMBERED_FLAG
3794 			|| ' ENCUMBRANCE ACCOUNT : '
3795 			||TO_CHAR ( L_ENCUMBRANCE_ACCOUNT )
3796 			|| ' ENCUMBRANCE AMOUNT : '
3797 			||TO_CHAR ( L_ENCUMBRANCE_AMOUNT )  );
3798             END IF;
3799 
3800             ---  2231732 encumbrance enhancement
3801             l_transfer_subinventory := l_po_info.destination_subinventory;
3802             l_transfer_organization := l_po_info.destination_organization_id;
3803             l_requisition_line_id := l_po_info.requisition_line_id;
3804             l_ship_to_location_id := l_po_info.deliver_to_location_id;
3805             l_req_distribution_id := l_po_info.distribution_id;
3806 
3807             IF (l_po_info.destination_type_code = 'EXPENSE') THEN
3808              l_trx_source_type_id := 8;
3809              l_trx_action_id := 1;
3810              l_trx_type_code := 34 /* Store_issue */;
3811             ELSIF (l_po_info.destination_type_code = 'INVENTORY') AND
3812                 (l_po_info.source_organization_id = l_po_info.destination_organization_id) THEN
3813              l_trx_source_type_id := 8;
3814              l_trx_action_id := 2;
3815              l_trx_type_code := 50 /* Subinv_xfer */;
3816             ELSIF (l_po_info.destination_organization_id <> l_po_info.source_organization_id) THEN
3817                   /* Bug 2137423, check mtl_interorg_parameters to decide transaction codes */
3818                   OPEN c_mtl_interorg_parameters( l_po_info.source_organization_id,
3819                                                   l_po_info.destination_organization_id);
3820                   FETCH c_mtl_interorg_parameters INTO l_intransit_type;
3821                   IF c_mtl_interorg_parameters%NOTFOUND THEN
3822                   /* default to intransit */
3823                      l_trx_source_type_id := 8;
3824                      l_trx_action_id := 21;
3825                      l_trx_type_code := 62; /* intransit_shpmnt */
3826                   ELSE
3827                      IF l_intransit_type = 1 THEN
3828                         l_trx_source_type_id := 8;
3829                         l_trx_action_id := 3;
3830                         l_trx_type_code := 54; /* direct shipment */
3831                      ELSE
3832                         l_trx_source_type_id := 8;
3833                         l_trx_action_id := 21;
3834                         l_trx_type_code := 62; /* intransit_shpmnt */
3835                      END IF;
3836                   END IF;
3837                   CLOSE c_mtl_interorg_parameters;
3838                   IF l_debug_on THEN
3839                      WSH_DEBUG_SV.log(l_module_name,'l_intransit_type', l_intransit_type);
3840                      WSH_DEBUG_SV.log(l_module_name,'l_trx_source_type_id', l_trx_source_type_id);
3841                      WSH_DEBUG_SV.log(l_module_name,'l_trx_action_id', l_trx_action_id);
3842                      WSH_DEBUG_SV.log(l_module_name,'l_trx_type_code', l_trx_type_code);
3843                   END IF;
3844             END IF;
3845 
3846 
3847             IF (l_po_info.destination_type_code <> 'INVENTORY') THEN
3848 
3849                --Bug 3391494:Onward 11.5.10 for Internal Order Expenses need to pass the
3850                --Shipping Goods Dispatched Account instead of Charge account from PO to Inventor for Interface.
3851 
3852                IF (WSH_CODE_CONTROL.Get_Code_Release_Level >= '110510') THEN
3853                   IF l_debug_on THEN
3854                    WSH_DEBUG_SV.logmsg(l_module_name,'Onward 11.5.10 not requried to get the PO account',
3855                                                                                     WSH_DEBUG_SV.C_PROC_LEVEL);
3856                   END IF;
3857                   l_account := NULL;
3858                ELSE
3859                   IF l_debug_on THEN
3860                    WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit PO_REQ_DIST_SV1.GET_DIST_ACCOUNT',
3861                                                                                     WSH_DEBUG_SV.C_PROC_LEVEL);
3862                   END IF;
3863 
3864                   l_account := PO_REQ_DIST_SV1.get_dist_account( l_requisition_line_id  ) ;  -- Bug 1610178
3865                END IF;
3866 
3867                IF l_debug_on THEN
3868                   WSH_DEBUG_SV.log(l_module_name,'l_account',l_account);
3869                END IF;
3870 
3871                IF ( l_account = -11 ) OR l_account IS NULL THEN
3872                    IF l_account = -11 THEN
3873                       WSH_UTIL_CORE.PRINTMsg ( 'Error: More than one Distribution accounts ' || l_account );
3874                    ELSE
3875                       WSH_UTIL_CORE.PRINTMsg ( 'No Distribution account ' || l_account );
3876                    END IF;
3877                    WSH_UTIL_CORE.PRINTMsg ('Use default distribution account defined for the organization');
3878                    wsh_shipping_params_pvt.get(
3879                            p_organization_id => l_mtl_txn_if_rec.organization_id(l_index),
3880                            x_param_info      => l_ship_params,
3881                            x_return_status   => l_sp_ret_status);
3882 
3883                    IF l_debug_on THEN
3884                        WSH_DEBUG_SV.log(l_module_name,'wsh_shipping_params_pvt.get l_sp_ret_status',l_sp_ret_status);
3885                    END IF;
3886                    IF l_sp_ret_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3887                       wsh_util_core.printmsg('Unable to get shipping parameters for org '
3888                                                   || l_mtl_txn_if_rec.organization_id(l_index));
3889 
3890                       IF l_debug_on THEN
3891                           WSH_DEBUG_SV.log(l_module_name,'Unable to get shipping parameters for org ',
3892                                           l_mtl_txn_if_rec.organization_id(l_index));
3893                       END IF;
3894                       raise e_line_warning;
3895                    END IF;
3896 
3897 
3898                    l_account := l_ship_params.goods_dispatched_account;
3899                    IF l_debug_on THEN
3900                        WSH_DEBUG_SV.logmsg(l_module_name, ' ACCOUNT_ID:' || L_ACCOUNT );
3901                    END IF;
3902 
3903                    IF ( l_account IS NULL ) THEN
3904                      WSH_UTIL_CORE.PrintMsg('There is no default goods dispatched account for org ' ||
3905                                                          l_mtl_txn_if_rec.organization_id(l_index));
3906                       raise e_line_warning;
3907                    END IF;
3908 
3909                END IF;
3910             END IF;
3911             --
3912             IF l_debug_on THEN
3913                 WSH_DEBUG_SV.logmsg(l_module_name,  'DISTRIBUTION ACCOUNT IS ' || L_ACCOUNT  );
3914             END IF;
3915             --
3916 
3917 	    -- Added for bug 4538005
3918             IF ( nvl(g_prv_from_location, -99)      = l_mtl_txn_if_rec.ship_from_location_id(l_index) AND
3919                  nvl(g_prv_customer_site_id, -99)   = l_mtl_txn_if_rec.ship_to_site_use_id(l_index) AND
3920                  nvl(g_prv_ship_method_code, '-99') = nvl(l_mtl_txn_if_rec.ship_method_code(l_index), '-11' ) )
3921             THEN
3922                l_intransit_time := g_intransit_time;
3923             -- If previous record details are different from current record details and
3924             -- ship method is not null
3925             ELSIF ( l_mtl_txn_if_rec.ship_method_code(l_index) IS NOT NULL )
3926             THEN
3927 
3928                IF l_debug_on THEN
3929                    WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program WSH_LOCATIONS_PKG.Get_Intransit_Time');
3930                END IF;
3931 
3932 	       OPEN get_session_id;
3933                FETCH get_session_id INTO l_session_id;
3934                CLOSE get_session_id;
3935 
3936 	       MSC_ATP_PROC.ATP_Shipping_Lead_Time (
3937 			p_from_loc_id =>  l_mtl_txn_if_rec.ship_from_location_id(l_index),        -- From Location ID
3938 			p_to_customer_site_id =>  l_mtl_txn_if_rec.ship_to_site_use_id(l_index),        -- To Customer Site ID
3939 			p_session_id =>  l_session_id,        -- A Unique Session ID
3940 		        x_ship_method =>  l_mtl_txn_if_rec.ship_method_code(l_index),  -- Ship Method to Use
3941 			x_intransit_time  =>  l_intransit_time,       -- The calculated in-transit Lead time
3942 		        x_return_status => l_return_status       -- A return status variable
3943                                         --  FND_API.G_RET_STS_SUCCESS - on success
3944                                         --  FND_API.G_RET_STS_ERROR - on expected error
3945                                         --  FND_API.G_RET_STS_UNEXP_ERROR - on unexpected error
3946 	       );
3947 
3948 	       IF ( l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS ) THEN
3949                   --Handle Return Status
3950                   x_return_status := l_return_status;
3951 
3952                   IF l_debug_on THEN
3953                       WSH_DEBUG_SV.log(l_module_name, 'x_return_status', x_return_status);
3954                       WSH_DEBUG_SV.logmsg(l_module_name, 'Error returned from WSH_LOCATIONS_PKG.Get_Intransit_Time');
3955                       WSH_DEBUG_SV.pop(l_module_name);
3956                   END IF;
3957 
3958                   RETURN;
3959                END IF;
3960 
3961                g_prv_from_location    := l_mtl_txn_if_rec.ship_from_location_id(l_index);
3962                g_prv_customer_site_id := l_mtl_txn_if_rec.ship_to_site_use_id(l_index);
3963                g_prv_ship_method_code := l_mtl_txn_if_rec.ship_method_code(l_index);
3964                g_intransit_time       := l_intransit_time;
3965             ELSE
3966                l_intransit_time := 0;
3967             END IF;
3968 
3969             IF l_debug_on THEN
3970                WSH_DEBUG_SV.log(l_module_name, 'Intransit Time', l_intransit_time);
3971             END IF;
3972 
3973 
3974 
3975 	     l_mtl_txn_if_rec.expected_arrival_date(l_index) :=  l_mtl_txn_if_rec.trx_date(l_index)+ nvl(l_intransit_time, 0);
3976 
3977 
3978 	 ------------------------------------
3979          ELSE /* not internal order */
3980             --
3981             IF l_debug_on THEN
3982                 WSH_DEBUG_SV.logmsg(l_module_name,  'NOT AN INTERNAL ORDER'  );
3983                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_TPA_DELIVERY_DETAILS_PKG.GET_ACCOUNT',
3984                                                       WSH_DEBUG_SV.C_PROC_LEVEL);
3985             END IF;
3986 
3987             /* get cogs account */
3988             l_account := WSH_TPA_DELIVERY_DETAILS_PKG.Get_Account(
3989 					p_delivery_detail_id  => l_mtl_txn_if_rec.picking_line_id(l_index),
3990                                         x_return_status     => l_account_return_status);
3991 
3992             IF l_debug_on THEN
3993                 WSH_DEBUG_SV.logmsg(l_module_name, 'RET_STATUS:'|| L_ACCOUNT_RETURN_STATUS ||
3994                                                                        ' ACCOUNT_ID:' || L_ACCOUNT );
3995 	    END IF;
3996 
3997             IF ( l_account_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS ) THEN
3998                WSH_UTIL_CORE.PrintMsg('Unable to get account for delivery detail id ' ||
3999                                                                  l_mtl_txn_if_rec.picking_line_id(l_index));
4000                raise e_line_warning;
4001             END IF ;
4002 
4003             l_transfer_subinventory := NULL;
4004             l_transfer_organization := NULL;
4005 
4006             IF (nvl(l_prev_ship_to_location_id,-99) <> l_mtl_txn_if_rec.ship_to_location_id(l_index)) THEN
4007                OPEN c_convert_locId(l_mtl_txn_if_rec.ship_to_location_id(l_index));
4008                FETCH c_convert_locId INTO l_ship_to_location_id;
4009                IF c_convert_locId%NOTFOUND THEN
4010                   FND_MESSAGE.SET_NAME('WSH','WSH_XC_INVALID_LOCATION');
4011                   wsh_util_core.add_message(WSH_UTIL_CORE.G_RET_STS_ERROR, l_module_name);
4012                   CLOSE c_convert_locId;
4013                   IF l_debug_on THEN
4014                     WSH_DEBUG_SV.log(l_module_name, 'c_convert_locId%NOTFOUND',
4015                                               l_mtl_txn_if_rec.ship_to_location_id(l_index));
4016                   END IF;
4017                   raise e_line_error;
4018                END IF;
4019                CLOSE c_convert_locId;
4020             END IF;
4021 
4022             l_prev_ship_to_location_id:=l_mtl_txn_if_rec.ship_to_location_id(l_index);
4023 
4024             l_requisition_line_id := NULL;
4025             l_trx_source_type_id := 2;
4026             l_trx_action_id := 1;
4027             l_trx_type_code := 33;
4028          END IF;
4029 
4030        ELSIF ( l_mtl_txn_if_rec.source_code(l_index) = 'OKE' ) THEN --} {
4031          l_source_code := 'OKE';
4032          l_trx_source_type_id := 16;
4033          l_trx_action_id := 1;
4034          l_trx_type_code := 77;
4035          l_trx_source_id := l_mtl_txn_if_rec.source_header_id(l_index);
4036          --
4037          IF l_debug_on THEN
4038              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit OKE_SHIPPING_EXT.COST_OF_SALES_ACCOUNT',
4039                                                                   WSH_DEBUG_SV.C_PROC_LEVEL);
4040          END IF;
4041          --
4042          l_account := OKE_SHIPPING_EXT.COST_OF_SALES_ACCOUNT(
4043                                               X_Delivery_Detail_ID => l_mtl_txn_if_rec.picking_line_id(l_index));
4044          IF l_debug_on THEN
4045             WSH_DEBUG_SV.log(l_module_name,'l_account',l_account);
4046          END IF;
4047 
4048          IF l_account IS NULL THEN
4049             WSH_UTIL_CORE.PrintMsg('OKE_SHIPPING_EXT.Cost_Of_Sales_Account returns NULL value');
4050             WSH_UTIL_CORE.PRINTMsg ('Use default distribution account defined for the organization');
4051             wsh_shipping_params_pvt.get(
4052                      p_organization_id => l_mtl_txn_if_rec.organization_id(l_index),
4053                      x_param_info      => l_ship_params,
4054                      x_return_status   => l_sp_ret_status);
4055             IF l_sp_ret_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4056                wsh_util_core.printmsg('Unable to get shipping parameters for org ' ||
4057                                                      l_mtl_txn_if_rec.organization_id(l_index));
4058                IF l_debug_on THEN
4059                    WSH_DEBUG_SV.log(l_module_name,
4060                         'Unable to get shipping parameters for org', l_mtl_txn_if_rec.organization_id(l_index));
4061                END IF;
4062                raise e_line_warning;
4063             END IF;
4064 
4065             l_account := l_ship_params.goods_dispatched_account;
4066             IF l_debug_on THEN
4067                 WSH_DEBUG_SV.logmsg(l_module_name, ' ACCOUNT_ID:' || L_ACCOUNT );
4068             END IF;
4069             --
4070             IF  l_account IS NULL  THEN
4071                WSH_UTIL_CORE.PrintMsg('There is no default goods dispatched account for org ' ||
4072                                                               l_mtl_txn_if_rec.organization_id(l_index));
4073                x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING ;
4074                --
4075                IF l_debug_on THEN
4076                    WSH_DEBUG_SV.log(l_module_name, 'There is no default goods dispatched account for org'
4077                            ,l_mtl_txn_if_rec.organization_id(l_index));
4078                END IF;
4079                raise e_line_warning;
4080             END IF;
4081          END IF;
4082        ELSE   -- source_code is not OE or OKE } {
4083          /* H Integration: 940/945 interface other source_code lines like 'WSH' to inventory */
4084          l_source_code := l_mtl_txn_if_rec.source_code(l_index);
4085          l_trx_source_type_id := 13; -- Inventory
4086          l_trx_action_id      := 1;
4087          l_trx_type_code      := 32; -- miscellaneous issue
4088          l_trx_source_id      := l_mtl_txn_if_rec.source_header_id(l_index);
4089 
4090          IF l_debug_on THEN
4091              WSH_DEBUG_SV.log(l_module_name,'l_source_code',l_source_code);
4092              WSH_DEBUG_SV.log(l_module_name,'l_trx_source_id',l_trx_source_id);
4093          END IF;
4094 
4095          wsh_shipping_params_pvt.get(
4096                    p_organization_id => l_mtl_txn_if_rec.organization_id(l_index),
4097                    x_param_info      => l_ship_params,
4098                    x_return_status   => l_sp_ret_status);
4099          IF l_sp_ret_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4100             wsh_util_core.printmsg('Unable to get shipping parameters for org ' ||
4101                                                          l_mtl_txn_if_rec.organization_id(l_index));
4102             x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
4103             --
4104             IF l_debug_on THEN
4105                 WSH_DEBUG_SV.log(l_module_name, 'Unable to get shipping parameters for org',
4106                                                 l_mtl_txn_if_rec.organization_id(l_index));
4107             END IF;
4108             raise e_line_warning;
4109          END IF;
4110 
4111          l_account := l_ship_params.goods_dispatched_account;
4112          IF l_debug_on THEN
4113              WSH_DEBUG_SV.logmsg(l_module_name, ' ACCOUNT_ID:' || L_ACCOUNT );
4114          END IF;
4115 
4116          IF ( l_account IS NULL ) THEN
4117             WSH_UTIL_CORE.PrintMsg('There is no default goods dispatched account for org ' ||
4118                                                              l_mtl_txn_if_rec.organization_id(l_index));
4119             x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING ;
4120             --
4121             IF l_debug_on THEN
4122                 WSH_DEBUG_SV.log(l_module_name, 'There is no default goods dispatched account for org',
4123                      l_mtl_txn_if_rec.organization_id(l_index));
4124             END IF;
4125             raise e_line_warning;
4126          END IF;
4127        END IF; --}
4128 
4129 
4130        IF (nvl(l_prev_organization_id,-99) <> l_mtl_txn_if_rec.organization_id(l_index)) THEN
4131           l_org_type := WSH_EXTERNAL_INTERFACE_SV.Get_Warehouse_Type(
4132                          p_organization_id => l_mtl_txn_if_rec.organization_id(l_index),
4133                          x_return_status   => x_return_status);
4134        END IF;
4135 
4136        IF l_debug_on THEN
4137         WSH_DEBUG_SV.log(l_module_name,'l_org_type',l_org_type);
4138         WSH_DEBUG_SV.log(l_module_name,'l_source_code',l_source_code);
4139        END IF;
4140 
4141        l_prev_organization_id := l_mtl_txn_if_rec.organization_id(l_index);
4142 
4143        -- TPW - Distributed changes
4144        IF l_org_type in ('TPW','TW2') and  l_source_code = 'OE' THEN
4145           l_mtl_txn_if_rec.subinventory(l_index) := NULL;
4146        END IF;
4147        --
4148 
4149        l_bulk_count := l_bulk_count + 1;
4150        l_mtl_txn_if_rec.source_code(l_index):= l_source_code;
4151        l_mtl_txn_if_rec.source_header_id(l_index):=NVL(l_mtl_txn_if_rec.source_header_id(l_index),111);
4152        l_mtl_txn_if_rec.trx_quantity(l_index):= - l_mtl_txn_if_rec.trx_quantity(l_index);
4153 -- HW OPMCONV - Added Qty2
4154        l_mtl_txn_if_rec.trx_quantity2(l_index):= - l_mtl_txn_if_rec.trx_quantity2(l_index);
4155        l_mtl_txn_if_rec.trx_source_id(l_index):= l_trx_source_id;
4156        l_mtl_txn_if_rec.trx_source_type_id(l_index):= l_trx_source_type_id;
4157        l_mtl_txn_if_rec.trx_action_id(l_index):= l_trx_action_id;
4158        l_mtl_txn_if_rec.trx_type_id(l_index):= l_trx_type_code;
4159        l_mtl_txn_if_rec.distribution_account_id(l_index):= l_account;
4160        l_mtl_txn_if_rec.transfer_subinventory(l_index):=l_transfer_subinventory ;
4161        l_mtl_txn_if_rec.transfer_organization(l_index):= l_transfer_organization;
4162        l_mtl_txn_if_rec.ship_to_location_id(l_index):= l_ship_to_location_id;
4163        l_mtl_txn_if_rec.requisition_line_iD(L_INDEX):=l_requisition_line_id ;
4164        l_mtl_txn_if_rec.requisition_distribution_id(l_index):= l_req_distribution_id;
4165        l_mtl_txn_if_rec.encumbrance_account(l_index):=l_encumbrance_account ;
4166        l_mtl_txn_if_rec.encumbrance_amount(l_index):= l_encumbrance_amount;
4167        l_mtl_txn_if_rec.trx_header_id(l_index):= p_transaction_header_id;
4168 
4169        --haperf
4170        l_dummy_ser_trx_interface_id := null;
4171        --haperf
4172 
4173        IF (l_mtl_txn_if_rec.serial_number(l_index) is not NULL
4174                OR l_mtl_txn_if_rec.transaction_temp_id(l_index) is not NULL)
4175            AND (l_mtl_txn_if_rec.lot_number(l_index) is not NULL) THEN
4176          l_interface_serial := true;
4177          l_interface_lot := true;
4178 
4179        ELSIF (l_mtl_txn_if_rec.transaction_temp_id(l_index) IS NOT NULL
4180               OR l_mtl_txn_if_rec.serial_number(l_index) IS NOT NULL) THEN
4181          l_interface_serial := true;
4182          --haperf
4183          l_dummy_ser_trx_interface_id := l_mtl_txn_if_rec.trx_interface_id(l_index);
4184 
4185        ELSIF (l_mtl_txn_if_rec.lot_number(l_index) is not NULL) THEN
4186          l_interface_lot := true;
4187          l_dummy_ser_trx_interface_id := null;
4188        END IF;
4189 
4190        IF l_debug_on THEN
4191           WSH_DEBUG_SV.log(l_module_name,'l_interface_serial',l_interface_serial);
4192           WSH_DEBUG_SV.log(l_module_name,'l_mtl_txn_if_rec.transaction_temp_id(l_index) ',l_mtl_txn_if_rec.transaction_temp_id(l_index));
4193        END IF;
4194 
4195        -- gather the serial number information.
4196        IF (l_interface_serial) THEN
4197          l_interface_serial := false;
4198 
4199          IF (l_mtl_txn_if_rec.transaction_temp_id(l_index) is NULL) THEN
4200 
4201            --haperf
4202            IF (l_interface_lot) THEN
4203              OPEN get_interface_id;
4204              FETCH get_interface_id INTO l_dummy_ser_trx_interface_id;
4205              CLOSE get_interface_id;
4206            END IF;
4207            --haperf
4208 
4209            l_bulk_count := l_bulk_count + 1;
4210            l_ser_count:= l_mtl_ser_txn_if_rec.source_line_id.count + 1;
4211            l_mtl_ser_txn_if_rec.source_code(l_ser_count):= l_source_code;
4212            l_mtl_ser_txn_if_rec.source_line_id(l_ser_count):= l_mtl_txn_if_rec.source_line_id(l_index);
4213            l_mtl_ser_txn_if_rec.fm_serial_number(l_ser_count):=l_mtl_txn_if_rec.serial_number(l_index);
4214            l_mtl_ser_txn_if_rec.to_serial_number(l_ser_count):= NVL(l_mtl_txn_if_rec.to_serial_number(l_index),
4215                                                                     l_mtl_txn_if_rec.serial_number(l_index));
4216            l_mtl_ser_txn_if_rec.transaction_interface_id(l_ser_count):=l_dummy_ser_trx_interface_id;
4217 
4218            -- Bug 36328620, do we need to look at INV MSN, MSNT tables for these attributes?
4219            l_mtl_ser_txn_if_rec.attribute_category(l_ser_count):=null;
4220            l_mtl_ser_txn_if_rec.attribute1(l_ser_count):=null;
4221            l_mtl_ser_txn_if_rec.attribute2(l_ser_count):=null;
4222            l_mtl_ser_txn_if_rec.attribute3(l_ser_count):=null;
4223            l_mtl_ser_txn_if_rec.attribute4(l_ser_count):=null;
4224            l_mtl_ser_txn_if_rec.attribute5(l_ser_count):=null;
4225            l_mtl_ser_txn_if_rec.attribute6(l_ser_count):=null;
4226            l_mtl_ser_txn_if_rec.attribute7(l_ser_count):=null;
4227            l_mtl_ser_txn_if_rec.attribute8(l_ser_count):=null;
4228            l_mtl_ser_txn_if_rec.attribute9(l_ser_count):=null;
4229            l_mtl_ser_txn_if_rec.attribute10(l_ser_count):=null;
4230            l_mtl_ser_txn_if_rec.attribute11(l_ser_count):=null;
4231            l_mtl_ser_txn_if_rec.attribute12(l_ser_count):=null;
4232            l_mtl_ser_txn_if_rec.attribute13(l_ser_count):=null;
4233            l_mtl_ser_txn_if_rec.attribute14(l_ser_count):=null;
4234            l_mtl_ser_txn_if_rec.attribute15(l_ser_count):=null;
4235            -- End of Bug 3628620
4236 
4237 --Bug 10337581
4238           l_mtl_ser_txn_if_rec.cycles_since_mark(l_ser_count):=NULL;
4239            l_mtl_ser_txn_if_rec.cycles_since_new(l_ser_count):=NULL;
4240            l_mtl_ser_txn_if_rec.cycles_since_overhaul(l_ser_count):=NULL;
4241            l_mtl_ser_txn_if_rec.cycles_since_repair(l_ser_count):=NULL;
4242            l_mtl_ser_txn_if_rec.cycles_since_visit(l_ser_count):=NULL;
4243            l_mtl_ser_txn_if_rec.c_attribute1(l_ser_count):=NULL;
4244            l_mtl_ser_txn_if_rec.c_attribute10(l_ser_count):=NULL;
4245            l_mtl_ser_txn_if_rec.c_attribute11(l_ser_count):=NULL;
4246            l_mtl_ser_txn_if_rec.c_attribute12(l_ser_count):=NULL;
4247            l_mtl_ser_txn_if_rec.c_attribute13(l_ser_count):=NULL;
4248            l_mtl_ser_txn_if_rec.c_attribute14(l_ser_count):=NULL;
4249            l_mtl_ser_txn_if_rec.c_attribute15(l_ser_count):=NULL;
4250            l_mtl_ser_txn_if_rec.c_attribute16(l_ser_count):=NULL;
4251            l_mtl_ser_txn_if_rec.c_attribute17(l_ser_count):=NULL;
4252            l_mtl_ser_txn_if_rec.c_attribute18(l_ser_count):=NULL;
4253            l_mtl_ser_txn_if_rec.c_attribute19(l_ser_count):=NULL;
4254            l_mtl_ser_txn_if_rec.c_attribute2(l_ser_count):=NULL;
4255            l_mtl_ser_txn_if_rec.c_attribute20(l_ser_count):=NULL;
4256            l_mtl_ser_txn_if_rec.c_attribute3(l_ser_count):=NULL;
4257            l_mtl_ser_txn_if_rec.c_attribute4(l_ser_count):=NULL;
4258            l_mtl_ser_txn_if_rec.c_attribute5(l_ser_count):=NULL;
4259            l_mtl_ser_txn_if_rec.c_attribute6(l_ser_count):=NULL;
4260            l_mtl_ser_txn_if_rec.c_attribute7(l_ser_count):=NULL;
4261            l_mtl_ser_txn_if_rec.c_attribute8(l_ser_count):=NULL;
4262            l_mtl_ser_txn_if_rec.c_attribute9(l_ser_count):=NULL;
4263            l_mtl_ser_txn_if_rec.d_attribute1(l_ser_count):=NULL;
4264            l_mtl_ser_txn_if_rec.d_attribute10(l_ser_count):=NULL;
4265            l_mtl_ser_txn_if_rec.d_attribute2(l_ser_count):=NULL;
4266            l_mtl_ser_txn_if_rec.d_attribute3(l_ser_count):=NULL;
4267            l_mtl_ser_txn_if_rec.d_attribute4(l_ser_count):=NULL;
4268            l_mtl_ser_txn_if_rec.d_attribute5(l_ser_count):=NULL;
4269            l_mtl_ser_txn_if_rec.d_attribute6(l_ser_count):=NULL;
4270            l_mtl_ser_txn_if_rec.d_attribute7(l_ser_count):=NULL;
4271            l_mtl_ser_txn_if_rec.d_attribute8(l_ser_count):=NULL;
4272            l_mtl_ser_txn_if_rec.d_attribute9(l_ser_count):=NULL;
4273            l_mtl_ser_txn_if_rec.number_of_repairs(l_ser_count):=NULL;
4274            l_mtl_ser_txn_if_rec.n_attribute1(l_ser_count):=NULL;
4275            l_mtl_ser_txn_if_rec.n_attribute10(l_ser_count):=NULL;
4276            l_mtl_ser_txn_if_rec.n_attribute2(l_ser_count):=NULL;
4277            l_mtl_ser_txn_if_rec.n_attribute3(l_ser_count):=NULL;
4278            l_mtl_ser_txn_if_rec.n_attribute4(l_ser_count):=NULL;
4279            l_mtl_ser_txn_if_rec.n_attribute5(l_ser_count):=NULL;
4280            l_mtl_ser_txn_if_rec.n_attribute6(l_ser_count):=NULL;
4281            l_mtl_ser_txn_if_rec.n_attribute7(l_ser_count):=NULL;
4282            l_mtl_ser_txn_if_rec.n_attribute8(l_ser_count):=NULL;
4283            l_mtl_ser_txn_if_rec.n_attribute9(l_ser_count):=NULL;
4284            l_mtl_ser_txn_if_rec.territory_code(l_ser_count):=NULL;
4285            l_mtl_ser_txn_if_rec.time_since_mark(l_ser_count):=NULL;
4286            l_mtl_ser_txn_if_rec.time_since_new(l_ser_count):=NULL;
4287            l_mtl_ser_txn_if_rec.time_since_overhaul(l_ser_count):=NULL;
4288            l_mtl_ser_txn_if_rec.time_since_repair(l_ser_count):=NULL;
4289            l_mtl_ser_txn_if_rec.time_since_visit(l_ser_count):=NULL;
4290            l_mtl_ser_txn_if_rec.serial_attribute_category(l_ser_count):=NULL;
4291 --end of Bug 10337581
4292 
4293            IF l_debug_on THEN
4294              WSH_DEBUG_SV.logmsg(l_module_name, 'ITEM BEING ADD TO SERIAL RECORD l_mtl_ser_txn_if_rec');
4295              WSH_DEBUG_SV.log(l_module_name,'source_code',l_mtl_ser_txn_if_rec.source_code(l_ser_count));
4296              WSH_DEBUG_SV.log(l_module_name,'source_line_id',l_mtl_ser_txn_if_rec.source_line_id(l_ser_count));
4297              WSH_DEBUG_SV.log(l_module_name,'fm_serial_number',l_mtl_ser_txn_if_rec.fm_serial_number(l_ser_count));
4298              WSH_DEBUG_SV.log(l_module_name,'to_serial_number',l_mtl_ser_txn_if_rec.to_serial_number(l_ser_count));
4299              WSH_DEBUG_SV.log(l_module_name,'transaction_interface_id',
4300                                                       l_mtl_ser_txn_if_rec.transaction_interface_id(l_ser_count));
4301              WSH_DEBUG_SV.log(l_module_name,'Attribute Category',l_mtl_ser_txn_if_rec.attribute_category(l_ser_count));
4302              WSH_DEBUG_SV.log(l_module_name,'Attribute1',l_mtl_ser_txn_if_rec.attribute1(l_ser_count));
4303              WSH_DEBUG_SV.log(l_module_name,'Attribute2',l_mtl_ser_txn_if_rec.attribute2(l_ser_count));
4304              WSH_DEBUG_SV.log(l_module_name,'Attribute3',l_mtl_ser_txn_if_rec.attribute3(l_ser_count));
4305              WSH_DEBUG_SV.log(l_module_name,'Attribute4',l_mtl_ser_txn_if_rec.attribute4(l_ser_count));
4306              WSH_DEBUG_SV.log(l_module_name,'Attribute5',l_mtl_ser_txn_if_rec.attribute5(l_ser_count));
4307              WSH_DEBUG_SV.log(l_module_name,'Attribute6',l_mtl_ser_txn_if_rec.attribute6(l_ser_count));
4308              WSH_DEBUG_SV.log(l_module_name,'Attribute7',l_mtl_ser_txn_if_rec.attribute7(l_ser_count));
4309              WSH_DEBUG_SV.log(l_module_name,'Attribute8',l_mtl_ser_txn_if_rec.attribute8(l_ser_count));
4310              WSH_DEBUG_SV.log(l_module_name,'Attribute9',l_mtl_ser_txn_if_rec.attribute9(l_ser_count));
4311              WSH_DEBUG_SV.log(l_module_name,'Attribute10',l_mtl_ser_txn_if_rec.attribute10(l_ser_count));
4312              WSH_DEBUG_SV.log(l_module_name,'Attribute11',l_mtl_ser_txn_if_rec.attribute11(l_ser_count));
4313              WSH_DEBUG_SV.log(l_module_name,'Attribute12',l_mtl_ser_txn_if_rec.attribute12(l_ser_count));
4314              WSH_DEBUG_SV.log(l_module_name,'Attribute13',l_mtl_ser_txn_if_rec.attribute13(l_ser_count));
4315              WSH_DEBUG_SV.log(l_module_name,'Attribute14',l_mtl_ser_txn_if_rec.attribute14(l_ser_count));
4316              WSH_DEBUG_SV.log(l_module_name,'Attribute15',l_mtl_ser_txn_if_rec.attribute15(l_ser_count));
4317            END IF;
4318 
4319          ELSE
4320             l_serial_count := 0;
4321             FOR ser_rec in c_serial_numbers(l_mtl_txn_if_rec.picking_line_id(l_index)) LOOP
4322 
4323               --haperf
4324               IF (l_interface_lot) THEN
4325                 IF (ser_rec.rownum = 1 ) THEN
4326                    l_dummy_ser_trx_interface_id := ser_rec.seq_num;
4327                 END IF;
4328               END IF;
4329               --haperf
4330 
4331               l_bulk_count := l_bulk_count + 1;
4332               l_ser_count:= l_mtl_ser_txn_if_rec.source_line_id.count + 1;
4333               l_mtl_ser_txn_if_rec.source_code(l_ser_count):= l_source_code;
4334               l_mtl_ser_txn_if_rec.source_line_id(l_ser_count):= l_mtl_txn_if_rec.source_line_id(l_index);
4335               l_mtl_ser_txn_if_rec.fm_serial_number(l_ser_count):=ser_rec.fm_serial_number;
4336               l_mtl_ser_txn_if_rec.to_serial_number(l_ser_count):=NVL(ser_rec.to_serial_number,
4337                                                                                 ser_rec.fm_serial_number);
4338               l_mtl_ser_txn_if_rec.transaction_interface_id(l_ser_count):=l_dummy_ser_trx_interface_id;
4339 
4340               -- Bug 36328620,
4341               l_mtl_ser_txn_if_rec.attribute_category(l_ser_count):=ser_rec.attribute_category;
4342               l_mtl_ser_txn_if_rec.attribute1(l_ser_count):=ser_rec.attribute1;
4343               l_mtl_ser_txn_if_rec.attribute2(l_ser_count):=ser_rec.attribute2;
4344               l_mtl_ser_txn_if_rec.attribute3(l_ser_count):=ser_rec.attribute3;
4345               l_mtl_ser_txn_if_rec.attribute4(l_ser_count):=ser_rec.attribute4;
4346               l_mtl_ser_txn_if_rec.attribute5(l_ser_count):=ser_rec.attribute5;
4347               l_mtl_ser_txn_if_rec.attribute6(l_ser_count):=ser_rec.attribute6;
4348               l_mtl_ser_txn_if_rec.attribute7(l_ser_count):=ser_rec.attribute7;
4349               l_mtl_ser_txn_if_rec.attribute8(l_ser_count):=ser_rec.attribute8;
4350               l_mtl_ser_txn_if_rec.attribute9(l_ser_count):=ser_rec.attribute9;
4351               l_mtl_ser_txn_if_rec.attribute10(l_ser_count):=ser_rec.attribute10;
4352               l_mtl_ser_txn_if_rec.attribute11(l_ser_count):=ser_rec.attribute11;
4353               l_mtl_ser_txn_if_rec.attribute12(l_ser_count):=ser_rec.attribute12;
4354               l_mtl_ser_txn_if_rec.attribute13(l_ser_count):=ser_rec.attribute13;
4355               l_mtl_ser_txn_if_rec.attribute14(l_ser_count):=ser_rec.attribute14;
4356               l_mtl_ser_txn_if_rec.attribute15(l_ser_count):=ser_rec.attribute15;
4357               -- End of Bug 3628620
4358               --Bug 8467875
4359                l_mtl_ser_txn_if_rec.cycles_since_mark(l_ser_count):=ser_rec.cycles_since_mark;
4360                l_mtl_ser_txn_if_rec.cycles_since_new(l_ser_count):=ser_rec.cycles_since_new;
4361                l_mtl_ser_txn_if_rec.cycles_since_overhaul(l_ser_count):=ser_rec.cycles_since_overhaul;
4362                l_mtl_ser_txn_if_rec.cycles_since_repair(l_ser_count):=ser_rec.cycles_since_repair;
4363                l_mtl_ser_txn_if_rec.cycles_since_visit(l_ser_count):=ser_rec.cycles_since_visit;
4364                l_mtl_ser_txn_if_rec.c_attribute1(l_ser_count):=ser_rec.c_attribute1;
4365                l_mtl_ser_txn_if_rec.c_attribute10(l_ser_count):=ser_rec.c_attribute10;
4366                l_mtl_ser_txn_if_rec.c_attribute11(l_ser_count):=ser_rec.c_attribute11;
4367                l_mtl_ser_txn_if_rec.c_attribute12(l_ser_count):=ser_rec.c_attribute12;
4368                l_mtl_ser_txn_if_rec.c_attribute13(l_ser_count):=ser_rec.c_attribute13;
4369                l_mtl_ser_txn_if_rec.c_attribute14(l_ser_count):=ser_rec.c_attribute14;
4370                l_mtl_ser_txn_if_rec.c_attribute15(l_ser_count):=ser_rec.c_attribute15;
4371                l_mtl_ser_txn_if_rec.c_attribute16(l_ser_count):=ser_rec.c_attribute16;
4372                l_mtl_ser_txn_if_rec.c_attribute17(l_ser_count):=ser_rec.c_attribute17;
4373                l_mtl_ser_txn_if_rec.c_attribute18(l_ser_count):=ser_rec.c_attribute18;
4374                l_mtl_ser_txn_if_rec.c_attribute19(l_ser_count):=ser_rec.c_attribute19;
4375                l_mtl_ser_txn_if_rec.c_attribute2(l_ser_count):=ser_rec.c_attribute2;
4376                l_mtl_ser_txn_if_rec.c_attribute20(l_ser_count):=ser_rec.c_attribute20;
4377                l_mtl_ser_txn_if_rec.c_attribute3(l_ser_count):=ser_rec.c_attribute3;
4378                l_mtl_ser_txn_if_rec.c_attribute4(l_ser_count):=ser_rec.c_attribute4;
4379                l_mtl_ser_txn_if_rec.c_attribute5(l_ser_count):=ser_rec.c_attribute5;
4380                l_mtl_ser_txn_if_rec.c_attribute6(l_ser_count):=ser_rec.c_attribute6;
4381                l_mtl_ser_txn_if_rec.c_attribute7(l_ser_count):=ser_rec.c_attribute7;
4382                l_mtl_ser_txn_if_rec.c_attribute8(l_ser_count):=ser_rec.c_attribute8;
4383                l_mtl_ser_txn_if_rec.c_attribute9(l_ser_count):=ser_rec.c_attribute9;
4384                l_mtl_ser_txn_if_rec.d_attribute1(l_ser_count):=ser_rec.d_attribute1;
4385                l_mtl_ser_txn_if_rec.d_attribute10(l_ser_count):=ser_rec.d_attribute10;
4386                l_mtl_ser_txn_if_rec.d_attribute2(l_ser_count):=ser_rec.d_attribute2;
4387                l_mtl_ser_txn_if_rec.d_attribute3(l_ser_count):=ser_rec.d_attribute3;
4388                l_mtl_ser_txn_if_rec.d_attribute4(l_ser_count):=ser_rec.d_attribute4;
4389                l_mtl_ser_txn_if_rec.d_attribute5(l_ser_count):=ser_rec.d_attribute5;
4390                l_mtl_ser_txn_if_rec.d_attribute6(l_ser_count):=ser_rec.d_attribute6;
4391                l_mtl_ser_txn_if_rec.d_attribute7(l_ser_count):=ser_rec.d_attribute7;
4392                l_mtl_ser_txn_if_rec.d_attribute8(l_ser_count):=ser_rec.d_attribute8;
4393                l_mtl_ser_txn_if_rec.d_attribute9(l_ser_count):=ser_rec.d_attribute9;
4394                l_mtl_ser_txn_if_rec.number_of_repairs(l_ser_count):=ser_rec.number_of_repairs;
4395                l_mtl_ser_txn_if_rec.n_attribute1(l_ser_count):=ser_rec.n_attribute1;
4396                l_mtl_ser_txn_if_rec.n_attribute10(l_ser_count):=ser_rec.n_attribute10;
4397                l_mtl_ser_txn_if_rec.n_attribute2(l_ser_count):=ser_rec.n_attribute2;
4398                l_mtl_ser_txn_if_rec.n_attribute3(l_ser_count):=ser_rec.n_attribute3;
4399                l_mtl_ser_txn_if_rec.n_attribute4(l_ser_count):=ser_rec.n_attribute4;
4400                l_mtl_ser_txn_if_rec.n_attribute5(l_ser_count):=ser_rec.n_attribute5;
4401                l_mtl_ser_txn_if_rec.n_attribute6(l_ser_count):=ser_rec.n_attribute6;
4402                l_mtl_ser_txn_if_rec.n_attribute7(l_ser_count):=ser_rec.n_attribute7;
4403                l_mtl_ser_txn_if_rec.n_attribute8(l_ser_count):=ser_rec.n_attribute8;
4404                l_mtl_ser_txn_if_rec.n_attribute9(l_ser_count):=ser_rec.n_attribute9;
4405                l_mtl_ser_txn_if_rec.territory_code(l_ser_count):=ser_rec.territory_code;
4406                l_mtl_ser_txn_if_rec.time_since_mark(l_ser_count):=ser_rec.time_since_mark;
4407                l_mtl_ser_txn_if_rec.time_since_new(l_ser_count):=ser_rec.time_since_new;
4408                l_mtl_ser_txn_if_rec.time_since_overhaul(l_ser_count):=ser_rec.time_since_overhaul;
4409                l_mtl_ser_txn_if_rec.time_since_repair(l_ser_count):=ser_rec.time_since_repair;
4410                l_mtl_ser_txn_if_rec.time_since_visit(l_ser_count):=ser_rec.time_since_visit;
4411                l_mtl_ser_txn_if_rec.serial_attribute_category(l_ser_count):=ser_rec.serial_attribute_category;
4412                --Bug 8467875
4413 
4414               IF l_debug_on THEN
4415                WSH_DEBUG_SV.logmsg(l_module_name, 'ITEM BEING ADD TO SERIAL RECORD l_mtl_ser_txn_if_rec');
4416                WSH_DEBUG_SV.log(l_module_name,'source_code',l_mtl_ser_txn_if_rec.source_code(l_ser_count));
4417                WSH_DEBUG_SV.log(l_module_name,'source_line_id',l_mtl_ser_txn_if_rec.source_line_id(l_ser_count));
4418                WSH_DEBUG_SV.log(l_module_name,'fm_serial_number',l_mtl_ser_txn_if_rec.fm_serial_number(l_ser_count));
4419                WSH_DEBUG_SV.log(l_module_name,'to_serial_number',l_mtl_ser_txn_if_rec.to_serial_number(l_ser_count));
4420                WSH_DEBUG_SV.log(l_module_name,'transaction_interface_id',
4421                                                       l_mtl_ser_txn_if_rec.transaction_interface_id(l_ser_count));
4422                WSH_DEBUG_SV.log(l_module_name,'Attribute Category',l_mtl_ser_txn_if_rec.attribute_category(l_ser_count));
4423                WSH_DEBUG_SV.log(l_module_name,'Attribute1',l_mtl_ser_txn_if_rec.attribute1(l_ser_count));
4424                WSH_DEBUG_SV.log(l_module_name,'Attribute2',l_mtl_ser_txn_if_rec.attribute2(l_ser_count));
4425                WSH_DEBUG_SV.log(l_module_name,'Attribute3',l_mtl_ser_txn_if_rec.attribute3(l_ser_count));
4426                WSH_DEBUG_SV.log(l_module_name,'Attribute4',l_mtl_ser_txn_if_rec.attribute4(l_ser_count));
4427                WSH_DEBUG_SV.log(l_module_name,'Attribute5',l_mtl_ser_txn_if_rec.attribute5(l_ser_count));
4428                WSH_DEBUG_SV.log(l_module_name,'Attribute6',l_mtl_ser_txn_if_rec.attribute6(l_ser_count));
4429                WSH_DEBUG_SV.log(l_module_name,'Attribute7',l_mtl_ser_txn_if_rec.attribute7(l_ser_count));
4430                WSH_DEBUG_SV.log(l_module_name,'Attribute8',l_mtl_ser_txn_if_rec.attribute8(l_ser_count));
4431                WSH_DEBUG_SV.log(l_module_name,'Attribute9',l_mtl_ser_txn_if_rec.attribute9(l_ser_count));
4432                WSH_DEBUG_SV.log(l_module_name,'Attribute10',l_mtl_ser_txn_if_rec.attribute10(l_ser_count));
4433                WSH_DEBUG_SV.log(l_module_name,'Attribute11',l_mtl_ser_txn_if_rec.attribute11(l_ser_count));
4434                WSH_DEBUG_SV.log(l_module_name,'Attribute12',l_mtl_ser_txn_if_rec.attribute12(l_ser_count));
4435                WSH_DEBUG_SV.log(l_module_name,'Attribute13',l_mtl_ser_txn_if_rec.attribute13(l_ser_count));
4436                WSH_DEBUG_SV.log(l_module_name,'Attribute14',l_mtl_ser_txn_if_rec.attribute14(l_ser_count));
4437                WSH_DEBUG_SV.log(l_module_name,'Attribute15',l_mtl_ser_txn_if_rec.attribute15(l_ser_count));
4438               END IF;
4439 
4440               l_serial_count := l_serial_count + 1;
4441             END LOOP;
4442 
4443             IF (l_serial_count = 0) THEN
4444               IF l_debug_on THEN
4445                   WSH_DEBUG_SV.logmsg(l_module_name, 'ERROR: NO SERIAL RECORDS FOUND FOR TRANSACTION_TEMP_ID '||
4446                                                                   l_mtl_txn_if_rec.transaction_temp_id(l_index));
4447               END IF;
4448               raise e_line_error;
4449             ELSE
4450               IF l_debug_on THEN
4451                   WSH_DEBUG_SV.logmsg(l_module_name, 'INSERTED '||l_serial_count||' SERIAL RECORDS ');
4452               END IF;
4453             END IF;
4454          END IF;
4455        END IF;
4456 
4457        -- Gather the lot information
4458        IF (l_interface_lot) THEN
4459          IF l_debug_on THEN
4460              WSH_DEBUG_SV.logmsg(l_module_name, 'ITEM IS UNDER SRL CTRL .'||
4461                            'INSERTING SRL NUMBER ' || l_mtl_txn_if_rec.SERIAL_NUMBER(l_index) || 'INTO MSNI.');
4462          END IF;
4463            l_interface_lot := false;
4464            l_bulk_count := l_bulk_count + 1;
4465 
4466            l_lot_count:= l_mtl_lot_txn_if_rec.source_line_id.count + 1;
4467            l_mtl_lot_txn_if_rec.transaction_interface_id(l_lot_count):=l_mtl_txn_if_rec.trx_interface_id(l_index); --haperf
4468            l_mtl_lot_txn_if_rec.source_code(l_lot_count):= l_source_code;
4469            l_mtl_lot_txn_if_rec.source_line_id(l_lot_count):= l_mtl_txn_if_rec.source_line_id(l_index);
4470            l_mtl_lot_txn_if_rec.lot_number(l_lot_count):= l_mtl_txn_if_rec.lot_number(l_index);
4471            l_mtl_lot_txn_if_rec.trx_quantity(l_lot_count):= l_mtl_txn_if_rec.trx_quantity(l_index);
4472            l_mtl_lot_txn_if_rec.serial_transaction_temp_id(l_lot_count):=l_dummy_ser_trx_interface_id;
4473 -- HW OPMCONV. Populate grade and qty2
4474            l_mtl_lot_txn_if_rec.grade_code(l_lot_count):= l_mtl_txn_if_rec.grade_code(l_index);
4475            l_mtl_lot_txn_if_rec.secondary_trx_quantity(l_lot_count):= l_mtl_txn_if_rec.trx_quantity2 (l_index);
4476 
4477            --Bug 13529169, populate lot attibutes only in case of internal sales orders
4478             IF (l_order_line_info.source_document_type_id = 10) THEN
4479                IF l_debug_on THEN
4480                   WSH_DEBUG_SV.logmsg(l_module_name, 'Order Type is Internal, populating Lot attribute values');
4481                END IF;
4482                OPEN c_lot_attr(l_mtl_txn_if_rec.inventory_item_id(l_index),l_mtl_txn_if_rec.organization_id(l_index),l_mtl_txn_if_rec.lot_number(l_index));
4483                FETCH c_lot_attr INTO   l_mtl_lot_txn_if_rec.attribute_category(l_lot_count),
4484                                        l_mtl_lot_txn_if_rec.attribute1(l_lot_count),
4485                                        l_mtl_lot_txn_if_rec.attribute2(l_lot_count),
4486                                        l_mtl_lot_txn_if_rec.attribute3(l_lot_count),
4487                                        l_mtl_lot_txn_if_rec.attribute4(l_lot_count),
4488                                        l_mtl_lot_txn_if_rec.attribute5(l_lot_count),
4489                                        l_mtl_lot_txn_if_rec.attribute6(l_lot_count),
4490                                        l_mtl_lot_txn_if_rec.attribute7(l_lot_count),
4491                                        l_mtl_lot_txn_if_rec.attribute8(l_lot_count),
4492                                        l_mtl_lot_txn_if_rec.attribute9(l_lot_count),
4493                                        l_mtl_lot_txn_if_rec.attribute10(l_lot_count),
4494                                        l_mtl_lot_txn_if_rec.attribute11(l_lot_count),
4495                                        l_mtl_lot_txn_if_rec.attribute12(l_lot_count),
4496                                        l_mtl_lot_txn_if_rec.attribute13(l_lot_count),
4497                                        l_mtl_lot_txn_if_rec.attribute14(l_lot_count),
4498                                        l_mtl_lot_txn_if_rec.attribute15(l_lot_count),
4499                                        l_mtl_lot_txn_if_rec.c_attribute1(l_lot_count),
4500                                        l_mtl_lot_txn_if_rec.c_attribute10(l_lot_count),
4501                                        l_mtl_lot_txn_if_rec.c_attribute11(l_lot_count),
4502                                        l_mtl_lot_txn_if_rec.c_attribute12(l_lot_count),
4503                                        l_mtl_lot_txn_if_rec.c_attribute13(l_lot_count),
4504                                        l_mtl_lot_txn_if_rec.c_attribute14(l_lot_count),
4505                                        l_mtl_lot_txn_if_rec.c_attribute15(l_lot_count),
4506                                        l_mtl_lot_txn_if_rec.c_attribute16(l_lot_count),
4507                                        l_mtl_lot_txn_if_rec.c_attribute17(l_lot_count),
4508                                        l_mtl_lot_txn_if_rec.c_attribute18(l_lot_count),
4509                                        l_mtl_lot_txn_if_rec.c_attribute19(l_lot_count),
4510                                        l_mtl_lot_txn_if_rec.c_attribute2(l_lot_count),
4511                                        l_mtl_lot_txn_if_rec.c_attribute20(l_lot_count),
4512                                        l_mtl_lot_txn_if_rec.c_attribute3(l_lot_count),
4513                                        l_mtl_lot_txn_if_rec.c_attribute4(l_lot_count),
4514                                        l_mtl_lot_txn_if_rec.c_attribute5(l_lot_count),
4515                                        l_mtl_lot_txn_if_rec.c_attribute6(l_lot_count),
4516                                        l_mtl_lot_txn_if_rec.c_attribute7(l_lot_count),
4517                                        l_mtl_lot_txn_if_rec.c_attribute8(l_lot_count),
4518                                        l_mtl_lot_txn_if_rec.c_attribute9(l_lot_count),
4519                                        l_mtl_lot_txn_if_rec.d_attribute1(l_lot_count),
4520                                        l_mtl_lot_txn_if_rec.d_attribute10(l_lot_count),
4521                                        l_mtl_lot_txn_if_rec.d_attribute2(l_lot_count),
4522                                        l_mtl_lot_txn_if_rec.d_attribute3(l_lot_count),
4523                                        l_mtl_lot_txn_if_rec.d_attribute4(l_lot_count),
4524                                        l_mtl_lot_txn_if_rec.d_attribute5(l_lot_count),
4525                                        l_mtl_lot_txn_if_rec.d_attribute6(l_lot_count),
4526                                        l_mtl_lot_txn_if_rec.d_attribute7(l_lot_count),
4527                                        l_mtl_lot_txn_if_rec.d_attribute8(l_lot_count),
4528                                        l_mtl_lot_txn_if_rec.d_attribute9(l_lot_count),
4529                                        l_mtl_lot_txn_if_rec.n_attribute1(l_lot_count),
4530                                        l_mtl_lot_txn_if_rec.n_attribute10(l_lot_count),
4531                                        l_mtl_lot_txn_if_rec.n_attribute2(l_lot_count),
4532                                        l_mtl_lot_txn_if_rec.n_attribute3(l_lot_count),
4533                                        l_mtl_lot_txn_if_rec.n_attribute4(l_lot_count),
4534                                        l_mtl_lot_txn_if_rec.n_attribute5(l_lot_count),
4535                                        l_mtl_lot_txn_if_rec.n_attribute6(l_lot_count),
4536                                        l_mtl_lot_txn_if_rec.n_attribute7(l_lot_count),
4537                                        l_mtl_lot_txn_if_rec.n_attribute8(l_lot_count),
4538                                        l_mtl_lot_txn_if_rec.n_attribute9(l_lot_count),
4539                                        l_mtl_lot_txn_if_rec.lot_attribute_category(l_lot_count);
4540                   IF c_lot_attr%NOTFOUND THEN
4541                      CLOSE c_lot_attr;
4542                      IF l_debug_on THEN
4543                         WSH_DEBUG_SV.logmsg(l_module_name, 'ERROR: NO RECORDS FOUND FOR LOT '||l_mtl_txn_if_rec.lot_number(l_index));
4544                      END IF;
4545                      raise e_line_error;
4546                   END IF;
4547                   CLOSE c_lot_attr;
4548 
4549                 IF l_debug_on THEN
4550                  WSH_DEBUG_SV.log(l_module_name,'Attribute Category',l_mtl_lot_txn_if_rec.attribute_category(l_lot_count));
4551                  WSH_DEBUG_SV.log(l_module_name,'Attribute1',l_mtl_lot_txn_if_rec.attribute1(l_lot_count));
4552                  WSH_DEBUG_SV.log(l_module_name,'Attribute2',l_mtl_lot_txn_if_rec.attribute2(l_lot_count));
4553                  WSH_DEBUG_SV.log(l_module_name,'Attribute3',l_mtl_lot_txn_if_rec.attribute3(l_lot_count));
4554                  WSH_DEBUG_SV.log(l_module_name,'Attribute4',l_mtl_lot_txn_if_rec.attribute4(l_lot_count));
4555                  WSH_DEBUG_SV.log(l_module_name,'Attribute5',l_mtl_lot_txn_if_rec.attribute5(l_lot_count));
4556                  WSH_DEBUG_SV.log(l_module_name,'Attribute6',l_mtl_lot_txn_if_rec.attribute6(l_lot_count));
4557                  WSH_DEBUG_SV.log(l_module_name,'Attribute7',l_mtl_lot_txn_if_rec.attribute7(l_lot_count));
4558                  WSH_DEBUG_SV.log(l_module_name,'Attribute8',l_mtl_lot_txn_if_rec.attribute8(l_lot_count));
4559                  WSH_DEBUG_SV.log(l_module_name,'Attribute9',l_mtl_lot_txn_if_rec.attribute9(l_lot_count));
4560                  WSH_DEBUG_SV.log(l_module_name,'Attribute10',l_mtl_lot_txn_if_rec.attribute10(l_lot_count));
4561                  WSH_DEBUG_SV.log(l_module_name,'Attribute11',l_mtl_lot_txn_if_rec.attribute11(l_lot_count));
4562                  WSH_DEBUG_SV.log(l_module_name,'Attribute12',l_mtl_lot_txn_if_rec.attribute12(l_lot_count));
4563                  WSH_DEBUG_SV.log(l_module_name,'Attribute13',l_mtl_lot_txn_if_rec.attribute13(l_lot_count));
4564                  WSH_DEBUG_SV.log(l_module_name,'Attribute14',l_mtl_lot_txn_if_rec.attribute14(l_lot_count));
4565                  WSH_DEBUG_SV.log(l_module_name,'Attribute15',l_mtl_lot_txn_if_rec.attribute15(l_lot_count));
4566                  WSH_DEBUG_SV.log(l_module_name,'Lot Attribute Category',l_mtl_lot_txn_if_rec.lot_attribute_category(l_lot_count));
4567                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute1',l_mtl_lot_txn_if_rec.c_attribute1(l_lot_count));
4568                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute2',l_mtl_lot_txn_if_rec.c_attribute2(l_lot_count));
4569                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute3',l_mtl_lot_txn_if_rec.c_attribute3(l_lot_count));
4570                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute4',l_mtl_lot_txn_if_rec.c_attribute4(l_lot_count));
4571                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute5',l_mtl_lot_txn_if_rec.c_attribute5(l_lot_count));
4572                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute6',l_mtl_lot_txn_if_rec.c_attribute6(l_lot_count));
4573                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute7',l_mtl_lot_txn_if_rec.c_attribute7(l_lot_count));
4574                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute8',l_mtl_lot_txn_if_rec.c_attribute8(l_lot_count));
4575                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute9',l_mtl_lot_txn_if_rec.c_attribute9(l_lot_count));
4576                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute10',l_mtl_lot_txn_if_rec.c_attribute10(l_lot_count));
4577                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute11',l_mtl_lot_txn_if_rec.c_attribute11(l_lot_count));
4578                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute12',l_mtl_lot_txn_if_rec.c_attribute12(l_lot_count));
4579                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute13',l_mtl_lot_txn_if_rec.c_attribute13(l_lot_count));
4580                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute14',l_mtl_lot_txn_if_rec.c_attribute14(l_lot_count));
4581                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute15',l_mtl_lot_txn_if_rec.c_attribute15(l_lot_count));
4582                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute16',l_mtl_lot_txn_if_rec.c_attribute16(l_lot_count));
4583                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute17',l_mtl_lot_txn_if_rec.c_attribute17(l_lot_count));
4584                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute18',l_mtl_lot_txn_if_rec.c_attribute18(l_lot_count));
4585                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute19',l_mtl_lot_txn_if_rec.c_attribute19(l_lot_count));
4586                  WSH_DEBUG_SV.log(l_module_name,'C_Attribute20',l_mtl_lot_txn_if_rec.c_attribute20(l_lot_count));
4587                 END IF;
4588             ELSE
4589                 l_mtl_lot_txn_if_rec.attribute_category(l_lot_count):= NULL;
4590                 l_mtl_lot_txn_if_rec.attribute1(l_lot_count):= NULL;
4591                 l_mtl_lot_txn_if_rec.attribute2(l_lot_count):= NULL;
4592                 l_mtl_lot_txn_if_rec.attribute3(l_lot_count):= NULL;
4593                 l_mtl_lot_txn_if_rec.attribute4(l_lot_count):= NULL;
4594                 l_mtl_lot_txn_if_rec.attribute5(l_lot_count):= NULL;
4595                 l_mtl_lot_txn_if_rec.attribute6(l_lot_count):= NULL;
4596                 l_mtl_lot_txn_if_rec.attribute7(l_lot_count):= NULL;
4597                 l_mtl_lot_txn_if_rec.attribute8(l_lot_count):= NULL;
4598                 l_mtl_lot_txn_if_rec.attribute9(l_lot_count):= NULL;
4599                 l_mtl_lot_txn_if_rec.attribute10(l_lot_count):= NULL;
4600                 l_mtl_lot_txn_if_rec.attribute11(l_lot_count):= NULL;
4601                 l_mtl_lot_txn_if_rec.attribute12(l_lot_count):= NULL;
4602                 l_mtl_lot_txn_if_rec.attribute13(l_lot_count):= NULL;
4603                 l_mtl_lot_txn_if_rec.attribute14(l_lot_count):= NULL;
4604                 l_mtl_lot_txn_if_rec.attribute15(l_lot_count):= NULL;
4605                 l_mtl_lot_txn_if_rec.c_attribute1(l_lot_count):= NULL;
4606                 l_mtl_lot_txn_if_rec.c_attribute10(l_lot_count):= NULL;
4607                 l_mtl_lot_txn_if_rec.c_attribute11(l_lot_count):= NULL;
4608                 l_mtl_lot_txn_if_rec.c_attribute12(l_lot_count):= NULL;
4609                 l_mtl_lot_txn_if_rec.c_attribute13(l_lot_count):= NULL;
4610                 l_mtl_lot_txn_if_rec.c_attribute14(l_lot_count):= NULL;
4611                 l_mtl_lot_txn_if_rec.c_attribute15(l_lot_count):= NULL;
4612                 l_mtl_lot_txn_if_rec.c_attribute16(l_lot_count):= NULL;
4613                 l_mtl_lot_txn_if_rec.c_attribute17(l_lot_count):= NULL;
4614                 l_mtl_lot_txn_if_rec.c_attribute18(l_lot_count):= NULL;
4615                 l_mtl_lot_txn_if_rec.c_attribute19(l_lot_count):= NULL;
4616                 l_mtl_lot_txn_if_rec.c_attribute2(l_lot_count):= NULL;
4617                 l_mtl_lot_txn_if_rec.c_attribute20(l_lot_count):= NULL;
4618                 l_mtl_lot_txn_if_rec.c_attribute3(l_lot_count):= NULL;
4619                 l_mtl_lot_txn_if_rec.c_attribute4(l_lot_count):= NULL;
4620                 l_mtl_lot_txn_if_rec.c_attribute5(l_lot_count):= NULL;
4621                 l_mtl_lot_txn_if_rec.c_attribute6(l_lot_count):= NULL;
4622                 l_mtl_lot_txn_if_rec.c_attribute7(l_lot_count):= NULL;
4623                 l_mtl_lot_txn_if_rec.c_attribute8(l_lot_count):= NULL;
4624                 l_mtl_lot_txn_if_rec.c_attribute9(l_lot_count):= NULL;
4625                 l_mtl_lot_txn_if_rec.d_attribute1(l_lot_count):= NULL;
4626                 l_mtl_lot_txn_if_rec.d_attribute10(l_lot_count):= NULL;
4627                 l_mtl_lot_txn_if_rec.d_attribute2(l_lot_count):= NULL;
4628                 l_mtl_lot_txn_if_rec.d_attribute3(l_lot_count):= NULL;
4629                 l_mtl_lot_txn_if_rec.d_attribute4(l_lot_count):= NULL;
4630                 l_mtl_lot_txn_if_rec.d_attribute5(l_lot_count):= NULL;
4631                 l_mtl_lot_txn_if_rec.d_attribute6(l_lot_count):= NULL;
4632                 l_mtl_lot_txn_if_rec.d_attribute7(l_lot_count):= NULL;
4633                 l_mtl_lot_txn_if_rec.d_attribute8(l_lot_count):= NULL;
4634                 l_mtl_lot_txn_if_rec.d_attribute9(l_lot_count):= NULL;
4635                 l_mtl_lot_txn_if_rec.n_attribute1(l_lot_count):= NULL;
4636                 l_mtl_lot_txn_if_rec.n_attribute10(l_lot_count):= NULL;
4637                 l_mtl_lot_txn_if_rec.n_attribute2(l_lot_count):= NULL;
4638                 l_mtl_lot_txn_if_rec.n_attribute3(l_lot_count):= NULL;
4639                 l_mtl_lot_txn_if_rec.n_attribute4(l_lot_count):= NULL;
4640                 l_mtl_lot_txn_if_rec.n_attribute5(l_lot_count):= NULL;
4641                 l_mtl_lot_txn_if_rec.n_attribute6(l_lot_count):= NULL;
4642                 l_mtl_lot_txn_if_rec.n_attribute7(l_lot_count):= NULL;
4643                 l_mtl_lot_txn_if_rec.n_attribute8(l_lot_count):= NULL;
4644                 l_mtl_lot_txn_if_rec.n_attribute9(l_lot_count):= NULL;
4645                 l_mtl_lot_txn_if_rec.lot_attribute_category(l_lot_count):= NULL;
4646             End if;
4647             -- Bug 13529169 ends here
4648 
4649            IF l_debug_on THEN
4650              WSH_DEBUG_SV.logmsg(l_module_name, 'ITEM BEING ADD TO LOT RECORD l_mtl_lot_txn_if_rec');
4651              WSH_DEBUG_SV.log(l_module_name,'transaction_interface_id',
4652                                                       l_mtl_lot_txn_if_rec.transaction_interface_id(l_lot_count));
4653              WSH_DEBUG_SV.log(l_module_name,'source_code',l_mtl_lot_txn_if_rec.source_code(l_lot_count));
4654              WSH_DEBUG_SV.log(l_module_name,'source_line_id',l_mtl_lot_txn_if_rec.source_line_id(l_lot_count));
4655              WSH_DEBUG_SV.log(l_module_name,'lot_number',l_mtl_lot_txn_if_rec.lot_number(l_lot_count));
4656              WSH_DEBUG_SV.log(l_module_name,'trx_quantity',l_mtl_lot_txn_if_rec.trx_quantity(l_lot_count));
4657 -- HW OPMCONV - Added Qty2
4658              WSH_DEBUG_SV.log(l_module_name,'trx_quantity2',l_mtl_lot_txn_if_rec.secondary_trx_quantity(l_lot_count));
4659              WSH_DEBUG_SV.log(l_module_name,'serial_transaction_temp_id',
4660                                                   l_mtl_lot_txn_if_rec.serial_transaction_temp_id(l_lot_count));
4661            END IF;
4662        END IF;
4663 
4664   --haperf
4665   ELSE
4666      l_mtl_txn_if_rec.freight_code(l_index):=null;
4667   --haperf
4668   END IF;  -- } if trx_quantity > 0
4669   ---4:
4670 
4671  IF l_debug_on THEN
4672     WSH_DEBUG_SV.log(l_module_name, 'l_index',l_index);
4673     WSH_DEBUG_SV.log(l_module_name, 'l_bulk_count',l_bulk_count);
4674     WSH_DEBUG_SV.log(l_module_name, 'l_mtl_txn_if_rec.picking_line_id.last',l_mtl_txn_if_rec.picking_line_id.last);
4675  END IF;
4676 
4677 
4678  -- IF the profile option WSH_BULK_BATCH_SIZE is specified, then insert the
4679  -- data into mtl tables, based on the chunk size specified by this profile
4680  -- option.
4681 
4682  IF ((l_bulk_batch_size is not NULL and l_bulk_count >= l_bulk_batch_size)
4683       or l_index = l_mtl_txn_if_rec.picking_line_id.last) THEN
4684     l_insert_inv_calls := l_insert_inv_calls + 1;
4685 
4686     Insert_inv_records(
4687 	p_start_index	=> l_start_index,
4688 	p_end_index	=> l_index,
4689 	p_mtl_txn_if_rec => l_mtl_txn_if_rec,
4690 	p_mtl_ser_txn_if_rec => l_mtl_ser_txn_if_rec,
4691 	p_mtl_lot_txn_if_rec => l_mtl_lot_txn_if_rec,
4692         p_def_inv_online   => l_def_inv_online,
4693 	x_return_status	 => l_return_status);
4694 
4695    IF l_debug_on THEN
4696       WSH_DEBUG_SV.log(l_module_name,'Insert_inv_records l_return_status',l_return_status);
4697    END IF;
4698    IF ( l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS ) THEN
4699        l_insert_inv_not_success := l_insert_inv_not_success + 1;
4700    END IF;
4701 
4702    IF l_debug_on THEN
4703       WSH_DEBUG_SV.log(l_module_name,'l_insert_inv_calls',l_insert_inv_calls);
4704       WSH_DEBUG_SV.log(l_module_name,'l_insert_inv_not_success',l_insert_inv_not_success);
4705    END IF;
4706 
4707    l_bulk_count := 0;
4708    l_start_index := l_index + 1;
4709  END IF;
4710 
4711 
4712  EXCEPTION
4713     WHEN e_line_error THEN
4714          IF l_debug_on THEN
4715             WSH_DEBUG_SV.log(l_module_name,'Error at line', l_mtl_txn_if_rec.picking_line_id(l_index));
4716          END IF;
4717          l_mtl_txn_if_rec.error_flag(l_index):='Y';
4718 	 -- Bug 4615610 : Assigned some dummy value to trx_type_id to avoid SQL error while
4719           --inserting into MTI
4720          l_mtl_txn_if_rec.trx_type_id(l_index):= -1;
4721          l_error_count := l_error_count + 1;
4722 
4723          --Bug#5084133: Needs to call Insert_inv_records even when it errors out for the last record.
4724          IF ( l_index = l_mtl_txn_if_rec.picking_line_id.last ) THEN
4725          --{
4726              l_insert_inv_calls := l_insert_inv_calls + 1;
4727              Insert_inv_records(
4728                 p_start_index   => l_start_index,
4729                 p_end_index     => l_index,
4730                 p_mtl_txn_if_rec => l_mtl_txn_if_rec,
4731                 p_mtl_ser_txn_if_rec => l_mtl_ser_txn_if_rec,
4732                 p_mtl_lot_txn_if_rec => l_mtl_lot_txn_if_rec,
4733                 p_def_inv_online   => l_def_inv_online,
4734                 x_return_status  => l_return_status);
4735 
4736              IF l_debug_on THEN
4737                  WSH_DEBUG_SV.log(l_module_name,'Insert_inv_records l_return_status',l_return_status);
4738              END IF;
4739              IF ( l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS ) THEN
4740                       l_insert_inv_not_success := l_insert_inv_not_success + 1;
4741              END IF;
4742              IF l_debug_on THEN
4743                   WSH_DEBUG_SV.log(l_module_name,'l_insert_inv_calls',l_insert_inv_calls);
4744                   WSH_DEBUG_SV.log(l_module_name,'l_insert_inv_not_success',l_insert_inv_not_success);
4745              END IF;
4746              l_bulk_count := 0;
4747          --}
4748          END IF;
4749 
4750     WHEN e_line_warning THEN
4751          IF l_debug_on THEN
4752             WSH_DEBUG_SV.log(l_module_name,'Warning at line', l_mtl_txn_if_rec.picking_line_id(l_index));
4753          END IF;
4754          l_mtl_txn_if_rec.error_flag(l_index):='Y';
4755 	 -- Bug 4615610 : Assigned some dummy value to trx_type_id to avoid SQL error while
4756           --inserting into MTI
4757          l_mtl_txn_if_rec.trx_type_id(l_index):= -1;
4758          l_warning_count := l_warning_count + 1;
4759 
4760          --Bug#5084133: Needs to call Insert_inv_records even when it errors out for the last record.
4761          IF ( l_index = l_mtl_txn_if_rec.picking_line_id.last ) THEN
4762          --{
4763              l_insert_inv_calls := l_insert_inv_calls + 1;
4764              Insert_inv_records(
4765                 p_start_index   => l_start_index,
4766                 p_end_index     => l_index,
4767                 p_mtl_txn_if_rec => l_mtl_txn_if_rec,
4768                 p_mtl_ser_txn_if_rec => l_mtl_ser_txn_if_rec,
4769                 p_mtl_lot_txn_if_rec => l_mtl_lot_txn_if_rec,
4770                 p_def_inv_online   => l_def_inv_online,
4771                 x_return_status  => l_return_status);
4772 
4773              IF l_debug_on THEN
4774                  WSH_DEBUG_SV.log(l_module_name,'Insert_inv_records l_return_status',l_return_status);
4775              END IF;
4776              IF ( l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS ) THEN
4777                       l_insert_inv_not_success := l_insert_inv_not_success + 1;
4778              END IF;
4779              IF l_debug_on THEN
4780                   WSH_DEBUG_SV.log(l_module_name,'l_insert_inv_calls',l_insert_inv_calls);
4781                   WSH_DEBUG_SV.log(l_module_name,'l_insert_inv_not_success',l_insert_inv_not_success);
4782              END IF;
4783              l_bulk_count := 0;
4784          --}
4785          END IF;
4786 
4787  END;
4788 
4789  l_index := l_mtl_txn_if_rec.picking_line_id.NEXT(l_index);
4790  END LOOP; --}
4791 
4792 
4793  --3: For Shipped_qty=0
4794  IF l_debug_on THEN
4795     WSH_DEBUG_SV.log(l_module_name,'l_delivery_detail_tbl.count',l_delivery_detail_tbl.count);
4796  END IF;
4797 
4798  IF (l_delivery_detail_tbl.count > 0) THEN
4799     FORALL i IN l_delivery_detail_tbl.first..l_delivery_detail_tbl.last
4800     UPDATE wsh_delivery_details
4801     SET inv_interfaced_flag = c_inv_int_full ,
4802         --Added as part of bug 7645262
4803         last_update_date    = sysdate,
4804         request_id          = fnd_global.conc_request_id,
4805         last_updated_by     = fnd_global.user_id
4806 
4807     WHERE delivery_detail_id = l_delivery_detail_tbl(i)
4808     AND container_flag = 'N';
4809  END IF;
4810 
4811  --For OPM Lines
4812  -- HW OPMCONV. Removed OPM sepecific code
4813 
4814  IF (l_insert_inv_not_success >= l_insert_inv_calls) THEN
4815     raise fnd_api.g_exc_error;
4816  ELSIF (l_insert_inv_not_success > 0 and l_insert_inv_not_success < l_insert_inv_calls) THEN
4817      RAISE wsh_util_core.g_exc_warning;
4818  END IF;
4819 
4820 
4821 
4822  IF (l_error_count >= l_mtl_txn_if_rec.picking_line_id.count) THEN
4823     raise fnd_api.g_exc_error;
4824  ELSIF ((l_error_count > 0 and l_error_count<l_mtl_txn_if_rec.picking_line_id.count)
4825          OR l_warning_count > 0) THEN
4826      RAISE wsh_util_core.g_exc_warning;
4827  END IF;
4828 
4829  IF l_debug_on THEN
4830        WSH_DEBUG_SV.log(l_module_name, 'x_return_status',x_return_status);
4831        WSH_DEBUG_SV.log(l_module_name, 'l_mtl_txn_if_rec.count',l_mtl_txn_if_rec.picking_line_id.count);
4832        WSH_DEBUG_SV.log(l_module_name, 'l_mtl_ser_txn_if_rec.count',l_mtl_ser_txn_if_rec.source_line_id.count);
4833        WSH_DEBUG_SV.log(l_module_name, 'l_mtl_lot_txn_if_rec.count',l_mtl_lot_txn_if_rec.source_line_id.count);
4834        WSH_DEBUG_SV.pop(l_module_name);
4835  END IF;
4836 
4837 EXCEPTION
4838  WHEN wsh_util_core.g_exc_warning THEN
4839     x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
4840 
4841     IF l_debug_on THEN
4842        wsh_debug_sv.logmsg(l_module_name, 'wsh_util_core.g_exc_warning exception has occured.', wsh_debug_sv.c_excep_level);
4843        wsh_debug_sv.pop(l_module_name, 'EXCEPTION:FND_API.G_EXC_ERROR');
4844     END IF;
4845 
4846  WHEN fnd_api.g_exc_error THEN
4847     x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4848 
4849     IF l_debug_on THEN
4850        wsh_debug_sv.logmsg(l_module_name, 'FND_API.G_EXC_ERROR exception has occured.', wsh_debug_sv.c_excep_level);
4851        wsh_debug_sv.pop(l_module_name, 'EXCEPTION:FND_API.G_EXC_ERROR');
4852     END IF;
4853 
4854 
4855  WHEN others THEN
4856     x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
4857     l_error_code := SQLCODE;
4858     l_error_text := SQLERRM;
4859     WSH_UTIL_CORE.PrintMsg(l_mtl_txn_if_rec.picking_line_id(l_index) ||': Interface detail to inventory failed with unexpected error');
4860     WSH_UTIL_CORE.PrintMsg('The unexpected error is ' || l_error_text);
4861 
4862     IF c_freight_code%ISOPEN THEN
4863        CLOSE c_freight_code;
4864     END IF;
4865     IF c_freight_code_del%ISOPEN THEN
4866        CLOSE c_freight_code_del;
4867     END IF;
4868 
4869     IF l_debug_on THEN
4870        WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
4871        WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
4872     END IF;
4873        --
4874 END Interface_Detail_To_Inv;
4875 
4876 
4877 
4878 --========================================================================
4879 -- PROCEDURE : inv_interface_trip_stop
4880 --                  This procedure interfaces the trip stops within the
4881 --                  current batch to the inventory.
4882 --
4883 -- PARAMETERS: p_batch_id              The ITS current batch_id
4884 --             x_completion_status     Return status of the API.
4885 
4886 -- COMMENT   : First this API checks to see if all the lines within the
4887 --             batch is fully interfaced to OM (if not return warning).  It
4888 --             Calls the transfer_serial_numbers, to populate the serial number
4889 --             information from MTL tables into Shipping tables.  This is done
4890 --             for non-OM lines.  Then it calls Update_Interfaced_Details to
4891 --             set the inv_interfaced_flag for the records that have been
4892 --             already processed by the inventory transaction manager.  If the
4893 --             on-line processing is not deferred, then mark the records in mtl
4894 --             interface tables, which has been failed in previous runs, with
4895 --             the current transaction header_id.  Call Interface_Detail_To_Inv
4896 --             to insert the records into MTL interface tables.  If the batch
4897 --             contains lines with OPM items then call
4898 --             GMI_UPDATE_ORDER.process_order, otherwise if there are some
4899 --             non-opm lines and on-line processing is not deferred, then call
4900 --             process_inv_online, to process the inventory on-line.
4901 --
4902 --========================================================================
4903 
4904 procedure inv_interface_trip_stop(p_batch_id        IN  NUMBER,
4905                           x_completion_status OUT NOCOPY  VARCHAR2) IS
4906 l_completion_status   VARCHAR2(30) := 'NORMAL';
4907 l_inv_inter_status varchar2(30);
4908 om_inter_req_submission   exception;
4909 l_lock_desc            VARCHAR2(92) ;
4910 l_temp                  BOOLEAN    ;
4911 
4912 l_delivery_id number;
4913 request_id number;
4914 l_error_code number;
4915 l_error_text varchar2(2000);
4916 -- HW OPMCONV. Removed OPM variables
4917 
4918 l_non_opm_org_exist BOOLEAN DEFAULT FALSE;
4919 l_transaction_header_id number ;
4920 l_return_status varchar2(30);
4921 l_get_lock_status varchar2(30);
4922 
4923 l_org_id   NUMBER;
4924 l_count    NUMBER := 0;
4925 
4926 CURSOR lock_row ( p_batch_id in  NUMBER ) IS
4927 SELECT stop_id
4928 FROM wsh_trip_stops
4929 WHERE batch_id = p_batch_id
4930 FOR UPDATE NOWAIT;
4931 Recinfo lock_row%ROWTYPE;
4932 
4933 l_stop_tab     wsh_util_core.id_tab_type;
4934 
4935 -- bug 5736840
4936 
4937 CURSOR  get_details (p_batch_id IN NUMBER) IS
4938 SELECT  da.delivery_detail_id
4939 FROM    wsh_delivery_assignments da , wsh_delivery_legs dg, wsh_new_deliveries dl, wsh_trip_stops st
4940 where   dl.delivery_id = da.delivery_id
4941 AND     da.delivery_id IS NOT NULL
4942 AND     st.stop_id = dg.pick_up_stop_id
4943 AND     st.batch_id = p_batch_id
4944 AND     st.stop_location_id = dl.initial_pickup_location_id
4945 AND     dg.delivery_id = dl.delivery_id;
4946 
4947 l_detail_ids_tbl WSH_BULK_TYPES_GRP.tbl_num;
4948 l_detail_ids_count        NUMBER;
4949 
4950 --
4951 
4952 -- bug 3588371
4953 -- This cursor fetches the records in mti that are not being processed
4954 -- by other transaction.  This can contain records that have errored in
4955 -- in the previous run
4956 CURSOR l_get_picking_ln_id_csr (p_batch_id IN NUMBER) IS
4957 SELECT mti.picking_line_id
4958 FROM   mtl_transactions_interface mti,
4959        wsh_delivery_assignments_v da ,
4960        wsh_delivery_legs dg,
4961        wsh_new_deliveries dl,
4962        wsh_delivery_details wdd,
4963        wsh_trip_stops st
4964 WHERE  mti.picking_line_id  = da.delivery_detail_id
4965 AND    wdd.delivery_detail_id = da.delivery_detail_id
4966 AND    wdd.source_code  <>  'RTV'                           -- RTV changes
4967 AND    dl.delivery_id = da.delivery_id
4968 AND    st.stop_id = dg.pick_up_stop_id
4969 AND    st.batch_id = p_batch_id
4970 AND    st.stop_location_id = dl.initial_pickup_location_id
4971 AND    dg.delivery_id = dl.delivery_id
4972 AND    nvl(mti.lock_flag,2) = 2;
4973 
4974 --RTV changes
4975 CURSOR c_get_rtv_deliveries (p_batch_id  IN  NUMBER) IS
4976 SELECT DISTINCT wnd.delivery_id
4977 from   wsh_delivery_details wdd,
4978        wsh_delivery_assignments_v wda,
4979        wsh_new_deliveries wnd,
4980        wsh_delivery_legs wdl,
4981        wsh_trip_stops wts
4982 where  wdd.source_code        = 'RTV'
4983 and    nvl(wdd.inv_interfaced_flag, 'N') = 'N'
4984 AND    wdd.container_flag = 'N'
4985 AND    wdd.released_status <> 'D'
4986 AND    nvl(wdd.line_direction,'O') in ('O','IO')
4987 and    wdd.delivery_detail_id = wda.delivery_detail_id
4988 and    wda.delivery_id        = wnd.delivery_id
4989 and    wda.delivery_id is not null
4990 and    wnd.delivery_id        = wdl.delivery_id
4991 and    wdl.pick_up_stop_id    = wts.stop_id
4992 and    wdd.ship_from_location_id = wts.stop_location_id
4993 and    wts.batch_id               = p_batch_id;
4994 
4995 l_picking_line_id_tbl        WSH_BULK_TYPES_GRP.tbl_num;
4996 
4997 l_picking_lines_count        NUMBER;
4998 l_num_warnings        NUMBER := 0;
4999 -- bug 3588371
5000 
5001 trip_stop_locked exception  ;
5002 PRAGMA EXCEPTION_INIT(trip_stop_locked, -54);
5003 
5004 l_debug_on BOOLEAN;
5005 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'INV_INTERFACE_TRIP_STOP';
5006 
5007 --HVOP heali
5008 l_def_inv_online		VARCHAR2(10);
5009 --HVOP heali
5010 -- RTV changes:
5011 l_rtv_delivery_id       NUMBER;
5012 l_rcv_interf_status     varchar2(30);
5013 l_rcv_completion_status     varchar2(30);
5014 -- RTV changes
5015 BEGIN
5016    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
5017    IF l_debug_on IS NULL THEN
5018        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
5019    END IF;
5020 
5021    IF l_debug_on THEN
5022        WSH_DEBUG_SV.push(l_module_name);
5023        WSH_DEBUG_SV.log(l_module_name,'p_batch_id',p_batch_id);
5024    END IF;
5025    --
5026    WSH_SHIP_CONFIRM_ACTIONS.ont_source_code := NULL;
5027 
5028 
5029    -- the batch should be fully interfaced to OM first.
5030 
5031    IF NOT  OM_INTERFACED(p_batch_id) THEN
5032     wsh_util_core.printmsg('Batch ' || p_batch_id || ' is not yet fully interfaced to OM.');
5033     x_completion_status := 'WARNING';
5034 
5035     IF l_debug_on THEN
5036         WSH_DEBUG_SV.log(l_module_name,'x_completion_status',x_completion_status);
5037         WSH_DEBUG_SV.log(l_module_name,'Batch ' || p_batch_id || ' is not yet fully interfaced to OM.');
5038         WSH_DEBUG_SV.pop(l_module_name);
5039     END IF;
5040     --
5041     return;
5042    END IF;
5043 
5044    -- lock the stops in the batch
5045    OPEN  lock_row ( p_batch_id ) ;
5046    FETCH lock_row INTO Recinfo;
5047    IF lock_row%NOTFOUND  THEN
5048     CLOSE lock_row;
5049 
5050     IF l_debug_on THEN
5051         WSH_DEBUG_SV.logmsg(l_module_name,  'INV INTERFACE CANNOT FIND Stops for batch ' || P_Batch_id  );
5052     END IF;
5053 
5054     x_completion_status := 'ERROR';
5055    --
5056     IF l_debug_on THEN
5057         WSH_DEBUG_SV.log(l_module_name,'x_completion_status', x_completion_status);
5058         WSH_DEBUG_SV.pop(l_module_name);
5059     END IF;
5060     --
5061     return;
5062    END IF;
5063 
5064    --  bug 2787888 : Added call to transfer serial records from mtl_serial_numbers_temp to wsh_serial_numbers
5065    IF l_debug_on THEN
5066        WSH_DEBUG_SV.logmsg(l_module_name, 'Calling TRANSFER_SERIAL_NUMBERS FOR BATCH ' || TO_CHAR ( P_batch_id ) );
5067    END IF;
5068 
5069    -- transfer the serial number information for non-om lines.
5070    transfer_serial_numbers (  p_batch_id => p_batch_id ,
5071                               p_interfacing => 'INV',
5072                               x_return_status =>  l_return_status );
5073 
5074    if (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
5075       IF l_debug_on THEN
5076           WSH_DEBUG_SV.logmsg(l_module_name, 'Error encountered in call to TRANSFER_SERIAL_NUMBERS FOR BATCH' || TO_CHAR ( P_BATCH_ID ) );
5077           WSH_DEBUG_SV.log(l_module_name,'x_completion_status', x_completion_status);
5078           WSH_DEBUG_SV.pop(l_module_name);
5079       END IF;
5080       x_completion_status := 'ERROR';
5081       return;
5082    end if;
5083    --  bug 2787888
5084 
5085    -- set the inv-interfaced_flag for to 'Y' for all the records that have been
5086    -- already successfully processed by the inventory transaction manager.
5087 
5088    Update_Interfaced_Details ( p_batch_id ,  l_return_status ) ;
5089 
5090    if (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) then
5091     WSH_UTIL_CORE.PrintMsg('inv_interface_trip_stop failed for batch '||p_batch_id ||':txn '||l_transaction_header_id);
5092         If (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
5093          l_completion_status := 'ERROR';
5094         ELSE
5095          l_completion_status := 'WARNING';
5096         END IF;
5097         IF l_debug_on THEN
5098            WSH_DEBUG_SV.log(l_module_name,'inv_interface_trip_stop failed for Batch '|| p_batch_id
5099                                                                        ||': txn ' || l_transaction_header_id  );
5100            WSH_DEBUG_SV.log(l_module_name,'l_completion_status', l_completion_status);
5101         END IF;
5102    end if;
5103    -- RTV changes
5104    l_rcv_interf_status     := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
5105    l_rcv_completion_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
5106 
5107    OPEN c_get_rtv_deliveries (p_batch_id);
5108    LOOP --{
5109         FETCH c_get_rtv_deliveries into l_rtv_delivery_id;
5110         EXIT WHEN c_get_rtv_deliveries%NOTFOUND;
5111 
5112         IF l_debug_on THEN
5113             WSH_DEBUG_SV.logmsg(l_module_name, 'RCV Delivery_id '|| l_rtv_delivery_id);
5114             WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit RCV_WSH_INTERFACE_PKG.interface_to_rcv',WSH_DEBUG_SV.C_PROC_LEVEL);
5115         END IF;
5116 
5117         l_rcv_interf_status   := WSH_UTIL_CORE.G_RET_STS_ERROR;
5118 
5119         RCV_WSH_INTERFACE_PKG.interface_to_rcv( p_delivery_id   => l_rtv_delivery_id,
5120                                                 p_return_status => l_rcv_interf_status);
5121 
5122         IF l_debug_on THEN
5123            WSH_DEBUG_SV.log(l_module_name,'Return status after calling RCV API ',l_rcv_interf_status);
5124         END IF;
5125 
5126         IF (l_rcv_interf_status = WSH_UTIL_CORE.G_RET_STS_ERROR OR
5127             l_rcv_interf_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) then
5128           l_rcv_completion_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
5129         END IF;
5130 
5131     END LOOP;  --}
5132     CLOSE c_get_rtv_deliveries;
5133 
5134     --
5135 
5136 
5137    -- If all the lines are interfaced to inventory, then return success.
5138 
5139    if ( inv_interfaced ( p_batch_id  ))  then
5140        IF l_debug_on THEN
5141            WSH_DEBUG_SV.logmsg(l_module_name,  'BATCH '|| P_batch_id || ' HAS BEEN SUCCESSFULLY INTERFACED'  );
5142        END IF;
5143 
5144        x_completion_status := 'INTERFACED';
5145        IF lock_row%ISOPEN THEN
5146          CLOSE lock_row;
5147        END IF;
5148 
5149        IF l_debug_on THEN
5150            WSH_DEBUG_SV.log(l_module_name,'x_completion_status', x_completion_status);
5151            WSH_DEBUG_SV.pop(l_module_name);
5152        END IF;
5153 
5154        return ;
5155    end if  ;
5156 
5157      -- update inv_interfaced_flag = 'N' where 'P' (for stop) and not in mti
5158     -- The ones that got sent to MMT have been updated to 'Y' earlier by Update_Interfaced_Details.
5159     -- So , this statement will update the ones still in 'P' and are  neither in MMT nor in MTI
5160 
5161     -- sql repository performance bug 4891985 (>1M sharable memory)
5162     -- changed wsh_delivery_assignments_v to wsh_delivery_assignments
5163 
5164     -- bug 5736840
5165      open  get_details(p_batch_id);
5166      fetch get_details bulk collect into l_detail_ids_tbl;
5167      close get_details;
5168 
5169      l_detail_ids_count := l_detail_ids_tbl.COUNT;
5170 
5171       IF l_debug_on THEN
5172         WSH_DEBUG_SV.log(l_module_name,'Number of records fetched by get_details is ', l_detail_ids_count);
5173       END IF;
5174 
5175     -- Bug#7271241 :removed source_code from where clause as DDs can be
5176     --               associated to OKE system.
5177      IF (nvl(l_detail_ids_count,0) > 0) THEN
5178       FORALL i in l_detail_ids_tbl.FIRST..l_detail_ids_tbl.LAST
5179        update wsh_delivery_details dd
5180        set    inv_interfaced_flag = 'N' ,
5181               --Added as part of bug 7645262
5182               last_update_date    = sysdate,
5183               request_id          = fnd_global.conc_request_id,
5184               last_updated_by     = fnd_global.user_id
5185        where  inv_interfaced_flag = 'P'
5186        and    not exists (
5187                           select picking_line_id
5188                           from   mtl_transactions_interface mti
5189                           where  source_line_id = mti.trx_source_line_id
5190                           and    mti.picking_line_id   =  dd.delivery_detail_id)
5191        and delivery_detail_id  = l_detail_ids_tbl(i)
5192        and container_flag = 'N'
5193        and released_status <> 'D'; /* H integration: wrudge */
5194 
5195      END IF;
5196     -- bug 5736840
5197 
5198       SELECT mtl_material_transactions_s.nextval
5199       INTO l_transaction_header_id
5200       FROM sys.dual;
5201       --
5202       IF l_debug_on THEN
5203           WSH_DEBUG_SV.logmsg(l_module_name,  'NEW TRANSACTION_HEADER : ' || TO_CHAR ( L_TRANSACTION_HEADER_ID )  );
5204       END IF;
5205       --
5206 
5207 
5208      -- update the lines in mti with the new transaction_header_id  so that these are picked up
5209      -- by our call to process_online.
5210 
5211      FND_PROFILE.Get('WSH_DEFER_INV_PR_ONLINE',l_def_inv_online);
5212 
5213      IF (nvl(l_def_inv_online,'N') <> 'Y') THEN --{
5214         -- bug 3588371
5215         open  l_get_picking_ln_id_csr(p_batch_id);
5216         fetch l_get_picking_ln_id_csr bulk collect into l_picking_line_id_tbl;
5217         close l_get_picking_ln_id_csr;
5218 
5219         l_picking_lines_count := l_picking_line_id_tbl.COUNT;
5220 
5221         IF l_debug_on THEN
5222           WSH_DEBUG_SV.log(l_module_name,'Number of records fetched by l_get_picking_ln_id_csr is ', l_picking_lines_count);
5223         END IF;
5224 
5225         IF (nvl(l_picking_lines_count,0) > 0) THEN
5226         --{
5227           --
5228           --
5229           FORALL i IN l_picking_line_id_tbl.first..l_picking_line_id_tbl.last
5230           update mtl_transactions_interface
5231           set    transaction_header_id = l_transaction_header_id
5232           where  picking_line_id    = l_picking_line_id_tbl(i)
5233           and    nvl(process_flag,1) <> 3
5234           and    nvl(lock_flag,2) = 2;
5235                 -- Bug 3259613:: Process should not pick record which is being
5236                 -- updated by another process;
5237 
5238           l_count := SQL%ROWCOUNT;
5239           IF l_debug_on THEN
5240             WSH_DEBUG_SV.log(l_module_name,'No. existing record updated in MTI', l_count);
5241           END IF;
5242           --
5243           --
5244           -- bug 3588371
5245         --}
5246         END IF;
5247 
5248       END IF; --}
5249 
5250    -- check if all are 'Y' then update to -1 * transation_header_id
5251    -- Call Interface_Detail_To_Inv to populate the MTL interface tables.
5252 
5253 --HVOP heali
5254 -- HW OPMCONV - No need to pass l_opm_org_exist
5255   Interface_Detail_To_Inv(
5256         p_batch_id               => p_batch_id,
5257         P_transaction_header_id => l_transaction_header_id,
5258         x_non_opm_org_exist     => l_non_opm_org_exist,
5259         x_return_status         => l_inv_inter_status);
5260 
5261    IF l_debug_on THEN
5262        WSH_DEBUG_SV.log(l_module_name,'Interface_Detail_To_Inv l_inv_inter_status',l_inv_inter_status);
5263    END IF;
5264 
5265  -- HW OPMCONV. Removed checking for non_opm lines
5266 
5267    IF l_count > 0 THEN
5268        -- if l_count > 0 means that there are mti reords updated with our
5269        -- transactio id
5270        l_non_opm_org_exist := TRUE;
5271    END IF;
5272 
5273    -- bug 3588371
5274    IF nvl(l_picking_lines_count,0) > 0
5275    AND nvl(l_count,0) < l_picking_lines_count
5276    THEN
5277    --{
5278      fnd_message.set_name('WSH', 'WSH_INV_INTF_ERROR_LINES');
5279      l_num_warnings := nvl(l_num_warnings,0) + 1;
5280      WSH_UTIL_CORE.ADD_MESSAGE(wsh_util_core.g_ret_sts_warning,l_module_name);
5281    --}
5282 -- HW OPMCONV - No need to check for l_opm_org_exist
5283    ELSIF (nvl(l_picking_lines_count,0) = 0
5284           and not(l_non_opm_org_exist)
5285           and nvl(l_def_inv_online,'N') <> 'Y') THEN
5286    --{
5287      fnd_message.set_name('WSH', 'WSH_INV_INTF_LINES_LOCKED');
5288      l_num_warnings := nvl(l_num_warnings,0) + 1;
5289      WSH_UTIL_CORE.ADD_MESSAGE(wsh_util_core.g_ret_sts_warning,l_module_name);
5290    --}
5291    END IF;
5292    -- bug 3588371
5293 
5294    -- Bug#4736038: If return value is WSH_UTIL_CORE.G_RET_STS_ERROR,
5295    --             i) It is treated as warning so that other batches can be processed.
5296    --            ii) No need to call process_inv_online as it represents all DD's in a batch are failed.
5297   IF (l_inv_inter_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
5298      IF (l_inv_inter_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ) THEN
5299 
5300          IF lock_row%ISOPEN THEN
5301            CLOSE lock_row;
5302          END IF;
5303          x_completion_status := 'ERROR';
5304 
5305          IF l_debug_on THEN
5306           WSH_DEBUG_SV.log(l_module_name,'Batch_id '||p_batch_id||' pass Inventory interface with unexpected errors');
5307           WSH_DEBUG_SV.pop(l_module_name);
5308          END IF;
5309          return;
5310       ELSIF ( l_inv_inter_status = WSH_UTIL_CORE.G_RET_STS_ERROR ) THEN
5311 
5312          IF lock_row%ISOPEN THEN
5313            CLOSE lock_row;
5314          END IF;
5315          x_completion_status := 'WARNING';
5316          IF l_debug_on THEN
5317           WSH_DEBUG_SV.log(l_module_name,'Batch_id '||p_batch_id||' pass Inventory interface with expected errors');
5318           WSH_DEBUG_SV.pop(l_module_name);
5319          END IF;
5320          return;
5321      ELSE
5322           l_completion_status := 'WARNING';
5323       END IF;
5324   END IF;
5325 --HVOP heali
5326    -- mark all 'N' as 'P'
5327    -- process online
5328 
5329    -- update to 'Y' where where inv_interfaced_flag = 'P' and dd_id in mmt and trx_hdr matches and mtl.delivery_id matches (procedure A)
5330 
5331    -- commit; /* Commented out for bug 1777401 */
5332 
5333      IF (nvl(l_def_inv_online,'N') <> 'Y'  and l_completion_status <> 'ERROR') THEN
5334         process_inv_online ( p_batch_id , l_transaction_header_id , l_return_status );
5335 
5336         if (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) then
5337           IF l_debug_on THEN
5338               WSH_DEBUG_SV.logmsg(l_module_name,'Batch '|| p_batch_id ||': TXN ' ||
5339                                                    L_TRANSACTION_HEADER_ID || ' : PROCESS ONLINE FAILED AGAIN'  );
5340           END IF;
5341           IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
5342             l_completion_status := 'ERROR';
5343           ELSE
5344             l_completion_status := 'WARNING';
5345           END IF;
5346         end if;
5347      END IF;
5348        --HVOP heali
5349 
5350    IF lock_row%ISOPEN THEN
5351      close lock_row;
5352    END IF;
5353 
5354    -- RTV changes
5355    if ( l_rcv_completion_status = WSH_UTIL_CORE.G_RET_STS_ERROR) then
5356       x_completion_status := 'ERROR';
5357    else
5358       x_completion_status := l_completion_status;
5359    end if;
5360    -- RTV changes
5361 
5362 
5363    -- bug 3588371
5364    IF (nvl(l_num_warnings,0) > 0 AND l_completion_status <> 'ERROR') THEN
5365      x_completion_status := 'WARNING';
5366      l_num_warnings := 0;
5367    END IF;
5368    -- bug 3588371
5369 
5370    --
5371    IF l_debug_on THEN
5372        WSH_DEBUG_SV.log(l_module_name,'l_completion_status',l_completion_status);
5373        WSH_DEBUG_SV.pop(l_module_name);
5374 
5375    END IF;
5376    --
5377    EXCEPTION
5378      when trip_stop_locked  Then
5379        IF lock_row%ISOPEN THEN
5380          CLOSE lock_row;
5381        END IF;
5382        IF get_details%ISOPEN THEN
5383          CLOSE get_details;
5384        END IF;
5385        WSH_UTIL_CORE.PrintMsg('This Trip Stop is locked by some other process');
5386          x_completion_status := 'WARNING';  -- continue processing other stops
5387        --
5388        IF l_debug_on THEN
5389            WSH_DEBUG_SV.logmsg(l_module_name,'TRIP_STOP_LOCKED exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
5390            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:TRIP_STOP_LOCKED');
5391        END IF;
5392        --
5393      WHEN others THEN
5394        IF get_details%ISOPEN THEN
5395          CLOSE get_details;
5396        END IF;
5397        l_completion_status := 'ERROR';
5398        l_error_code := SQLCODE;
5399        l_error_text := SQLERRM;
5400        WSH_UTIL_CORE.PrintMsg('Interface trip_stop to inventory failed with unexpected error');
5401        WSH_UTIL_CORE.PrintMsg('The unexpected error is ' || l_error_text);
5402        x_completion_status := l_completion_status;
5403        --
5404        IF l_debug_on THEN
5405            WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
5406            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
5407        END IF;
5408        --
5409 END inv_interface_Trip_Stop;
5410 
5411 --
5412 --Function:     More_Shipment_Exist
5413 --Parameters:      p_delivery_id,
5414 --            p_source_line_id
5415 --Description:      This function returns a boolean value to indicate
5416 --            if more shipments exist for the source line
5417 --          that is being shipped within the delivery
5418 
5419 FUNCTION More_Shipment_Exist(p_delivery_id number, p_source_code varchar2, p_source_line_id number) RETURN BOOLEAN is
5420 cursor assigned_line_total is
5421    SELECT count(*)  total
5422    from wsh_delivery_details dd,
5423          wsh_delivery_assignments_v da,
5424          wsh_new_deliveries ds
5425      where dd.delivery_detail_id = da.delivery_detail_id
5426      and  da.delivery_id = ds.delivery_id
5427      and  ds.status_code NOT IN ('CL','IT','CO', 'SR', 'SC') /* Closed, In  Transit, Confirmed */
5428      and  da.delivery_id <> p_delivery_id
5429      and  da.delivery_id IS NOT NULL
5430      and  dd.source_line_id = p_source_line_id
5431      and  dd.source_code = p_source_code
5432      and  dd.container_flag = 'N'
5433           and    dd.released_status <> 'D' ;  /* H integration: wrudge */
5434 l_assigned_total assigned_line_total%ROWTYPE;
5435 cursor unassigned_line_total is
5436    SELECT count(*) total
5437    from wsh_delivery_details dd,
5438          wsh_delivery_assignments_v da
5439      where   dd.delivery_detail_id = da.delivery_detail_id
5440      and da.delivery_id is NULL
5441      and dd.source_line_id = p_source_line_id
5442      and  dd.source_code = p_source_code
5443      and dd.container_flag = 'N'
5444           and   dd.released_status <> 'D' ;  /* H integration: wrudge */
5445 l_unassigned_total unassigned_line_total%ROWTYPE;
5446 --
5447 l_debug_on BOOLEAN;
5448 --
5449 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'MORE_SHIPMENT_EXIST';
5450 --
5451 BEGIN
5452    --
5453    --
5454    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
5455    --
5456    IF l_debug_on IS NULL
5457    THEN
5458        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
5459    END IF;
5460    --
5461    IF l_debug_on THEN
5462        WSH_DEBUG_SV.push(l_module_name);
5463        --
5464        WSH_DEBUG_SV.log(l_module_name,'P_DELIVERY_ID',P_DELIVERY_ID);
5465        WSH_DEBUG_SV.log(l_module_name,'P_SOURCE_CODE',P_SOURCE_CODE);
5466        WSH_DEBUG_SV.log(l_module_name,'P_SOURCE_LINE_ID',P_SOURCE_LINE_ID);
5467    END IF;
5468    --
5469    OPEN assigned_line_total;
5470    FETCH assigned_line_total into l_assigned_total;
5471    OPEN unassigned_line_total;
5472    FETCH unassigned_line_total into l_unassigned_total;
5473    IF l_debug_on THEN
5474       WSH_DEBUG_SV.log(l_module_name,'l_assigned_total',l_assigned_total.total);
5475       WSH_DEBUG_SV.log(l_module_name,'l_unassigned_total',l_unassigned_total.total);
5476    END IF;
5477    if ((l_assigned_total.total > 0) or (l_unassigned_total.total > 0) ) THEN
5478      --
5479      IF l_debug_on THEN
5480          WSH_DEBUG_SV.pop(l_module_name);
5481      END IF;
5482      --
5483      return TRUE;
5484    else
5485      --
5486      IF l_debug_on THEN
5487          WSH_DEBUG_SV.pop(l_module_name);
5488      END IF;
5489      --
5490      return FALSE;
5491    END if;
5492 END More_Shipment_Exist;
5493 
5494 --========================================================================
5495 -- FUNCTION  : Get_Line_Expected_Qty
5496 --                  This function returns the sum of expected quantity for
5497 --                  a source_line_id, where these lines are not being processed
5498 --                  by the current batch.
5499 --
5500 -- PARAMETERS: p_source_line_id        The source line id (order line id)
5501 --             p_batch_id              The ITS current batch_id
5502 --             p_fulfill_base          The fulfillment base of p_source_line_id
5503 
5504 --Description: This function returns expected shipped quantity (or secondary shipped quantity)
5505 --             for a source line besides the shipped quantity(or secondary shipped quantity) in
5506 --             the current stop depending on whether fulfillment base is primary or secondary
5507 --
5508 --========================================================================
5509 
5510 -- muom
5511 FUNCTION Get_Line_Expected_Qty(p_source_line_id in number, p_batch_id in number, p_fulfill_base in varchar2 ) RETURN NUMBER is
5512 total_expt_qty number ;
5513 l_planned_qty number :=0;
5514 
5515 /* H integration: 940/945 bug 2312168 wrudge
5516 **   we also expect shipped quantities from outbound deliveries.
5517 */
5518 
5519 -- cursor other_batch_delivery_details calculates the sum of picked_quantity or
5520 -- requested quantity for the lines, which have certain source_line_id
5521 -- and they do not belong to the current batch and have the following release
5522 -- status: Staged/Pick Confirmed ,or shipped but not interfaced to inv or the
5523 -- line belong to 3'd party warehouse and the delivery is in status
5524 -- Shipment Cancellation Request or Shipment Requested
5525 
5526 cursor other_batch_delivery_details is
5527 -- muom
5528 select sum(decode(p_fulfill_base,'S',nvl(wdd.picked_quantity2, wdd.requested_quantity2),nvl(wdd.picked_quantity, wdd.requested_quantity)))
5529 from wsh_delivery_details wdd,
5530 wsh_delivery_assignments_v da,
5531 wsh_new_deliveries wnd
5532 where wdd.source_line_id=p_source_line_id and
5533 wdd.source_code = 'OE' and
5534 wdd.delivery_detail_id=da.delivery_detail_id and
5535 not exists (select 1 from wsh_delivery_legs lg, wsh_trip_stops st
5536 where st.batch_id= p_batch_id and
5537 st.stop_id = lg.pick_up_stop_id and
5538 nvl(da.delivery_id,0)= lg.delivery_id)
5539 and wnd.delivery_id(+) = da.delivery_id
5540 and (   (wdd.released_status = 'Y')
5541      OR (wdd.released_status = 'C' AND wdd.oe_interfaced_flag <> 'Y')
5542      OR (wnd.status_code IN ('SR', 'SC'))
5543     );
5544 
5545 --
5546 l_debug_on BOOLEAN;
5547 --
5548 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'GET_LINE_EXPECTED_QTY';
5549 --
5550 BEGIN
5551 
5552    --
5553    --
5554    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
5555    --
5556    IF l_debug_on IS NULL
5557    THEN
5558        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
5559    END IF;
5560    --
5561    IF l_debug_on THEN
5562        WSH_DEBUG_SV.push(l_module_name);
5563        --
5564        WSH_DEBUG_SV.log(l_module_name,'P_SOURCE_LINE_ID',P_SOURCE_LINE_ID);
5565        WSH_DEBUG_SV.log(l_module_name,'P_batch_id',P_batch_id);
5566    END IF;
5567    --
5568    OPEN   other_batch_delivery_details;
5569    FETCH  other_batch_delivery_details INTO l_planned_qty;
5570    IF other_batch_delivery_details%NOTFOUND THEN
5571      l_planned_qty := 0;
5572    END IF;
5573    CLOSE  other_batch_delivery_details;
5574 
5575    --
5576    IF l_debug_on THEN
5577        WSH_DEBUG_SV.logmsg(l_module_name, 'PLANNED QUANTITY: '|| L_PLANNED_QTY );
5578        WSH_DEBUG_SV.pop(l_module_name);
5579    END IF;
5580    --
5581    return l_planned_qty;
5582 
5583 end Get_Line_Expected_Qty ;
5584 
5585 
5586 --R12:MOAC this API now calls WSH, instead of OM
5587 --         renamed Get_New_Tolerance to Check_Tolerance
5588 --         changed Function to Procedure as the old result is not needed.
5589 --========================================================================
5590 -- PROCEDURE  : Check_Tolerance
5591 --                  This function is a wrapper around
5592 --                  WSH_DETAILS_VALIDATIONS.get_min_max_tolerance_quantity
5593 --
5594 -- PARAMETERS: p_stop_id               This parameter is not being used.
5595 --             p_source_line_id        The source line id for which the
5596 --                                     tolerance is being calculated.
5597 --             p_shipping_uom          is shipping's requested_quantity_uom
5598 --             p_tot_shp_qty           Sum of shipped_quantity for the source
5599 --                                     line id (not interfaced to OM)
5600 --             p_tot_shp_qty2          Sum of shipped_quantity2 for the source
5601 --                                     line id (not interfaced to OM)
5602 --             x_ship_beyond_flag      Shipped beyond the tolerance
5603 --             x_fulfilled_flag        Value 'T' means the line is fulfilled.
5604 -- COMMENT   : This function calls get_min_max_tolerance_quantity
5605 --             to determine if the order line is fulfilled,
5606 --             returning the minimum quantity remaining to ship.
5607 --
5608 --========================================================================
5609 
5610 PROCEDURE Check_Tolerance(
5611            p_stop_id  number ,
5612            p_source_line_id number,
5613            p_shipping_uom varchar2,
5614            p_tot_shp_qty  number ,
5615            p_tot_shp_qty2  number ,
5616            x_ship_beyond_flag out NOCOPY  varchar2,
5617            x_fulfilled_flag out NOCOPY  varchar2,
5618 	   x_return_status  out NOCOPY VARCHAR2) IS
5619 
5620 l_msg_count number;
5621 l_msg_data varchar2(3000);
5622 l_return_status VARCHAR2(1);
5623 GET_TOLERANCE_FAILED exception;
5624 
5625 l_debug_on BOOLEAN;
5626 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CHECK_TOLERANCE';
5627 
5628   l_minmaxinrec          WSH_DETAILS_VALIDATIONS.MinMaxInRecType;
5629   l_minmaxinoutrec       WSH_DETAILS_VALIDATIONS.MinMaxInOutRecType;
5630   l_minmaxoutrec         WSH_DETAILS_VALIDATIONS.MinMaxOutRecType;
5631 
5632   -- OM call to compare
5633    --Bug#9437761
5634   CURSOR c_order_line_details(c_source_line_id NUMBER) IS
5635 Select order_quantity_uom,
5636 ordered_quantity_uom2
5637 from oe_order_Lines_all
5638 where line_id = c_source_line_id ;
5639 
5640 l_order_quantity_uom VARCHAR2(3) ;
5641 l_ordered_quantity_uom2 VARCHAR2(3) ;
5642 
5643 
5644 begin
5645 
5646    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
5647    IF l_debug_on IS NULL
5648    THEN
5649        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
5650    END IF;
5651    IF l_debug_on THEN
5652        WSH_DEBUG_SV.push(l_module_name);
5653        WSH_DEBUG_SV.log(l_module_name,'P_STOP_ID',P_STOP_ID);
5654        WSH_DEBUG_SV.log(l_module_name,'P_SOURCE_LINE_ID',P_SOURCE_LINE_ID);
5655        WSH_DEBUG_SV.log(l_module_name,'P_SHIPPING_UOM',P_SHIPPING_UOM);
5656        WSH_DEBUG_SV.log(l_module_name,'P_TOT_SHP_QTY',P_TOT_SHP_QTY);
5657        WSH_DEBUG_SV.log(l_module_name,'P_TOT_SHP_QTY2',P_TOT_SHP_QTY2);
5658    END IF;
5659 
5660   l_minmaxinrec.source_code := 'OE';
5661   l_minmaxinrec.line_id :=  p_source_line_id;
5662   l_minmaxinrec.action_flag := 'I';
5663 
5664    IF l_debug_on THEN
5665        WSH_DEBUG_SV.logmsg(l_module_name, 'THE TOTAL SHIPPED QUANTITY FOR ORDER LINE ' || P_SOURCE_LINE_ID || ' IS ' || P_TOT_SHP_QTY );
5666    END IF;
5667 
5668 
5669   WSH_DETAILS_VALIDATIONS.get_min_max_tolerance_quantity
5670 		(p_in_attributes    => l_minmaxinrec,
5671 		 x_out_attributes   => l_minmaxoutrec,
5672 		 p_inout_attributes => l_minmaxinoutrec,
5673 		 x_return_status    => l_return_status,
5674 		 x_msg_count        => l_msg_count,
5675 		 x_msg_data         => l_msg_data
5676 		 );
5677 
5678    IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,
5679                            WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
5680      raise GET_TOLERANCE_FAILED;
5681    END if;
5682 
5683     -- muom
5684     -- If Fulfillment Base is Secondary, then derive fulfilled_flag/ship_beyond_flag from get_min_max_tolerance_quantity api.
5685     -- If Fulfillment Base is Primary, then continue to do as before
5686     IF WSH_UTIL_CORE.Get_Line_Fulfillment_Base('OE', p_source_line_id) = 'S' THEN
5687 
5688       IF l_minmaxoutrec.min_remaining_quantity2 <= 0 THEN
5689         x_fulfilled_flag := 'T';
5690       ELSE
5691         x_fulfilled_flag := 'F';
5692       END IF;
5693       IF l_minmaxoutrec.max_remaining_quantity2 < 0 THEN
5694         x_ship_beyond_flag := 'T';
5695       ELSE
5696         x_ship_beyond_flag := 'F';
5697       END IF;
5698     ELSE
5699       IF l_minmaxoutrec.min_remaining_quantity <= 0 THEN
5700         x_fulfilled_flag := 'T';
5701       ELSE
5702         x_fulfilled_flag := 'F';
5703       END IF;
5704 
5705       --Bug#9437761
5706       Open c_order_line_details(p_source_line_id) ;
5707       Fetch c_order_line_details into l_order_quantity_uom,
5708                                     l_ordered_quantity_uom2 ;
5709       Close c_order_line_details;
5710 
5711       IF l_debug_on THEN
5712          WSH_DEBUG_SV.logmsg(l_module_name, 'L_ORDER_QTY_UOM   IS ' || l_order_quantity_uom );
5713          WSH_DEBUG_SV.logmsg(l_module_name, 'L_ORDER_QTY_UOM2 IS ' || l_ordered_quantity_uom2 );
5714       END IF;
5715       -- when the ordered uom is in secondary uom, the fulfillment check would
5716       -- be against the min_remaining_quantity2
5717       IF l_ordered_quantity_uom2 IS NOT NULL AND
5718          l_order_quantity_uom = l_ordered_quantity_uom2  AND l_minmaxoutrec.min_remaining_quantity2 <= 0 THEN
5719 
5720          x_fulfilled_flag := 'T';
5721       END IF ;
5722 
5723       IF l_minmaxoutrec.max_remaining_quantity < 0 THEN
5724         x_ship_beyond_flag := 'T';
5725       ELSE
5726         x_ship_beyond_flag := 'F';
5727       END IF;
5728     END IF;
5729 
5730    x_return_status   := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
5731 
5732    IF l_debug_on THEN
5733       WSH_DEBUG_SV.log(l_module_name, 'SHIP_BEYOND_FLAG', X_SHIP_BEYOND_FLAG);
5734       WSH_DEBUG_SV.log(l_module_name, 'FULFILLED_FLAG', X_FULFILLED_FLAG);
5735       WSH_DEBUG_SV.pop(l_module_name);
5736    END IF;
5737 
5738 EXCEPTION
5739      WHEN GET_TOLERANCE_FAILED THEN
5740        IF l_debug_on THEN
5741            WSH_DEBUG_SV.logmsg(l_module_name,  'WSH get_min_max_tolerance_quantity FAILED'  );
5742            WSH_DEBUG_SV.log(l_module_name, 'l_return_status', l_return_status);
5743            WSH_DEBUG_SV.logmsg(l_module_name,'GET_TOLERANCE_FAILED exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
5744            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:GET_TOLERANCE_FAILED');
5745        END IF;
5746        x_return_status  := l_return_status;
5747        x_fulfilled_flag := NULL;
5748 
5749 END Check_Tolerance;
5750 
5751 --Standalone WMS Project changes ,moved common code inside this API to be used by existing code
5752 --as well as Standalone code
5753 --========================================================================
5754 -- PROCEDURE : Handle_Tolerances
5755 --                  Procedure to check tolarance and cancel remaining wdd if any.
5756 --
5757 -- PARAMETERS: p_batch_id            --batch_id when called from Interface_Stop_To_OM
5758 --                                   --NULL when called from Process_Delivery_To_OM
5759 --             p_oe_interface_rec    line details records
5760 --             x_fulfilled_flag      Y if line is completely shipped or shipped within tolerance
5761 --             x_over_reason         '0' in case of overshipment
5762 --             x_return_status
5763 --
5764 -- COMMENT   : This API check tolerance of the line and accordingly cancel the remaing
5765 --             wdd.Created to be used by Standalone API Process_Delivery_To_OM.
5766 --             As well as existing API Interface_stop_to_OM
5767 --========================================================================
5768 PROCEDURE Handle_Tolerances(
5769           p_batch_id IN NUMBER,
5770           p_oe_interface_rec IN WSH_SHIP_CONFIRM_ACTIONS.oe_interface_rec,
5771           x_fulfilled_flag OUT NOCOPY VARCHAR2,
5772           x_over_reason OUT NOCOPY VARCHAR2,
5773           x_return_status   OUT NOCOPY  VARCHAR2 ) IS
5774   l_debug_on    BOOLEAN;
5775   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.'|| G_PKG_NAME || '.'|| 'Handle_Tolerances';
5776   l_tot_dd_req_qty NUMBER;
5777   l_tot_dd_shp_qty NUMBER;
5778   l_tot_ord_qty NUMBER;
5779   l_ship_beyond_flag     VARCHAR2(1);
5780   l_fulfilled_flag       VARCHAR2(1);
5781   l_process_flag         VARCHAR2(1);
5782   l_return_status       VARCHAR2(10);
5783   l_delete_detail_id NUMBER;
5784   l_remain_detail_index NUMBER;
5785   l_num_warnings NUMBER;
5786   l_num_errors    NUMBER;
5787   l_prev_line_set_id     NUMBER:= -99;
5788   l_cancel_unpicked_details VARCHAR(1);
5789   l_remain_details_id WSH_UTIL_CORE.Id_Tab_Type;
5790   l_line_id NUMBER;
5791   l_dummy VARCHAR2(1);
5792   l_summary  VARCHAR2(2000) :=NULL;
5793   l_error_Code NUMBER ;
5794   l_error_text varchar2(2000);
5795   l_details  VARCHAR2(4000) :=NULL;
5796   l_get_msg_count          number;
5797   l_client_id              NUMBER;
5798 
5799   CURSOR c_remain_detail_id(c_source_line_id NUMBER) IS
5800   SELECT delivery_detail_id
5801   FROM   wsh_delivery_details dd
5802   WHERE  source_line_id   = c_source_line_id
5803     AND source_code      = 'OE'
5804     AND released_status IN ('R', 'B','N','S','X')
5805     AND NVL(container_flag, 'N') = 'N';
5806 
5807   CURSOR c_remain_lines(c_source_line_set_id NUMBER, c_source_header_id NUMBER, p_batch_id NUMBER)  IS
5808   SELECT DISTINCT wdd.source_line_id
5809   FROM   wsh_delivery_details wdd
5810   WHERE  wdd.source_header_id   = c_source_header_id
5811      AND wdd.source_code        = 'OE'
5812      AND wdd.source_line_set_id = c_source_line_set_id
5813      AND NOT EXISTS
5814          ( SELECT 'x'
5815            FROM    wsh_delivery_assignments_v wda,
5816                    wsh_new_deliveries wnd        ,
5817                    wsh_delivery_legs wdl         ,
5818                    wsh_trip_stops wts
5819            WHERE   wdd.delivery_detail_id = wda.delivery_detail_id
5820                AND wda.delivery_id        = wnd.delivery_id
5821                AND wda.delivery_id IS NOT NULL
5822                AND wnd.delivery_id           = wdl.delivery_id
5823                AND wdl.pick_up_stop_id       = wts.stop_id
5824                AND wdd.ship_from_location_id = wts.stop_location_id
5825                AND wts.batch_id              = p_batch_id);
5826 
5827   CURSOR c_picked_dd(c_source_line_id NUMBER, c_source_header_id NUMBER) IS
5828   SELECT 'x'
5829   FROM   wsh_delivery_details wdd      ,
5830          wsh_delivery_assignments_v wda,
5831          wsh_new_deliveries wnd
5832   WHERE  wdd.source_line_id     = c_source_line_id
5833      AND wdd.source_code        = 'OE'
5834      AND wdd.source_header_id   = c_source_header_id
5835      AND wdd.delivery_detail_id = wda.delivery_detail_id
5836      AND wnd.delivery_id(+)     = wda.delivery_id
5837      AND ( ( wdd.released_status = 'Y' ) OR
5838            ( wdd.released_status = 'C' AND wdd.oe_interfaced_flag <> 'Y' ) OR
5839            ( wnd.status_code IN ('SR','SC')));
5840 
5841 --9437761
5842 l_uom2_order_fulfilled VARCHAR2(1) :=FND_API.G_FALSE;
5843 -- muom
5844 l_fulfill_base varchar2(1);
5845 l_tot_dd_req_qty2 number;
5846 l_tot_dd_shp_qty2 number;
5847 l_tot_ord_qty2 number;
5848 
5849 
5850 BEGIN
5851 
5852     l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
5853     IF l_debug_on IS NULL THEN
5854             l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
5855     END IF;
5856 
5857     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
5858 
5859     IF l_debug_on THEN
5860         WSH_DEBUG_SV.push(l_module_name);
5861     END IF;
5862 
5863     IF NOT INV_GMI_RSV_BRANCH.Process_Branch(p_organization_id => p_oe_interface_rec.organization_id) THEN
5864        l_process_flag := FND_API.G_FALSE;
5865     ELSE
5866        l_process_flag := FND_API.G_TRUE;
5867     END IF;
5868 
5869     -- muom
5870     l_fulfill_base := WSH_UTIL_CORE.Get_Line_Fulfillment_Base('OE', p_oe_interface_rec.source_line_id);
5871 
5872     IF l_debug_on THEN
5873          WSH_DEBUG_SV.logmsg(l_module_name,'l_process_flag '  || l_process_flag);
5874     END IF;
5875   --9437761
5876            /* when the ordered uom is in secondary uom check_tolernace should be
5877  *                called FP of bug,4760099 */
5878 	 IF p_oe_interface_rec.ordered_quantity_uom2 IS NOT NULL AND
5879            p_oe_interface_rec.order_quantity_uom = p_oe_interface_rec.ordered_quantity_uom2 AND
5880            p_oe_interface_rec.total_shipped_quantity2 >= p_oe_interface_rec.ordered_quantity2 AND
5881            -- muom
5882            l_fulfill_base = 'P' THEN
5883            l_uom2_order_fulfilled  := FND_API.G_TRUE ;
5884          END IF ;
5885 
5886 
5887       IF ((nvl(p_oe_interface_rec.ship_tolerance_above,0) > 0) OR    -- {
5888                (nvl(p_oe_interface_rec.ship_tolerance_below,0) > 0))
5889 	       OR (l_uom2_order_fulfilled = FND_API.G_TRUE ) THEN
5890 
5891    -- IF ((NVL(p_oe_interface_rec.ship_tolerance_above,0) > 0) OR (NVL(p_oe_interface_rec.ship_tolerance_below,0) > 0))THEN
5892 
5893         IF (p_oe_interface_rec.source_line_set_id IS NOT NULL) THEN
5894         --{
5895             SELECT SUM(dd.requested_quantity),
5896                   SUM( NVL(dd.shipped_quantity, 0 )),
5897                   -- muom
5898                   SUM(dd.requested_quantity2),
5899                   SUM( NVL(dd.shipped_quantity2, 0 )),
5900                   max(nvl(dd.client_id,0)) -- LSP PROJECT : needs to check clientId on WDD records.
5901             INTO  l_tot_dd_req_qty,
5902                   l_tot_dd_shp_qty,
5903                   -- muom
5904                   l_tot_dd_req_qty2,
5905                   l_tot_dd_shp_qty2,
5906                   l_client_id             -- LSP PROJECT
5907             FROM  wsh_delivery_Details dd       ,
5908                   wsh_delivery_assignments_v da ,
5909                   wsh_delivery_legs dg          ,
5910                   wsh_new_deliveries dl         ,
5911                   wsh_trip_stops st
5912             WHERE st.stop_id          = dg.pick_up_stop_id
5913               AND st.batch_id         = P_batch_id
5914               AND st.stop_location_id = dl.initial_pickup_location_id
5915               AND dg.delivery_id      = dl.delivery_id
5916               AND dl.delivery_id      = da.delivery_id
5917               AND da.delivery_id IS NOT NULL
5918               AND da.delivery_detail_id = dd.delivery_detail_id
5919               AND NVL ( dd.oe_interfaced_flag , 'N' ) <> 'Y'
5920               AND dd.source_code = 'OE'
5921               AND dd.source_header_id = p_oe_interface_rec.source_header_id
5922               AND dd.source_line_set_id = p_oe_interface_rec.source_line_set_id
5923               AND dd.released_status <> 'D';
5924 
5925             SELECT SUM(WSH_WV_UTILS.CONVERT_UOM(ol.order_quantity_uom, p_oe_interface_rec.requested_quantity_uom, ol.ordered_quantity, ol.inventory_item_id)) order_line_quantity,
5926             -- muom
5927             SUM(ol.ordered_quantity2) order_line_quantity2
5928             INTO  l_tot_ord_qty, l_tot_ord_qty2
5929             FROM  oe_order_lines_all ol
5930             WHERE ol.header_id   = p_oe_interface_rec.source_header_id
5931               AND ol.line_set_id = p_oe_interface_rec.source_line_set_id;
5932 
5933             IF l_debug_on THEN
5934                 WSH_DEBUG_SV.logmsg(l_module_name, 'l_tot_ord_qty '||l_tot_ord_qty||' l_tot_dd_req_qty '|| l_tot_dd_req_qty||' l_tot_dd_shp_qty '||l_tot_dd_shp_qty);
5935             END IF;
5936          --Bug 12823498: If its LSP mode then check whether client_id is populated
5937          ELSIF ( WMS_DEPLOY.WMS_DEPLOYMENT_MODE = 'L' ) THEN
5938             SELECT DISTINCT client_id
5939             INTO   l_client_id
5940             FROM   wsh_delivery_details
5941             WHERE  source_code = 'OE'
5942             AND    source_line_id = p_oe_interface_rec.source_line_id;
5943          --}
5944          END IF;
5945 
5946          -- OM bug 2022029: compare total requested quantity instead of total shipped quantity
5947          -- muom
5948          IF (((p_oe_interface_rec.source_line_set_id IS NULL) AND
5949              ((l_fulfill_base = 'P' and p_oe_interface_rec.total_requested_quantity < p_oe_interface_rec.order_line_quantity) OR
5950               (l_fulfill_base = 'S' and p_oe_interface_rec.total_requested_quantity2 < p_oe_interface_rec.order_line_quantity2))) OR
5951              ((p_oe_interface_rec.source_line_set_id IS NOT NULL) AND
5952               ((l_fulfill_base = 'P' and l_tot_dd_req_qty < l_tot_ord_qty) OR
5953                (l_fulfill_base = 'S' and l_tot_dd_req_qty2 < l_tot_ord_qty2)))) THEN
5954          --{
5955                  IF l_debug_on THEN
5956                      IF (p_oe_interface_rec.source_line_set_id IS NOT NULL) THEN
5957                          WSH_DEBUG_SV.logmsg(l_module_name,  'Shipping partial quantity for the line set ' || p_oe_interface_rec.source_line_set_id);
5958                      ELSE
5959                          WSH_DEBUG_SV.logmsg(l_module_name, 'Shipping partial quantity for the order line '|| p_oe_interface_rec.source_line_id);
5960                      END IF;
5961                  END IF;
5962                  --haperf
5963                  IF l_debug_on THEN
5964                      WSH_DEBUG_SV.logmsg(l_module_name, '===============');
5965                      WSH_DEBUG_SV.logmsg(l_module_name, 'Tolerance Check');
5966                      WSH_DEBUG_SV.logmsg(l_module_name, '===============');
5967                  END IF;
5968 
5969                  Check_Tolerance( p_stop_id => NULL ,
5970                                   p_source_line_id => p_oe_interface_rec.source_line_id ,
5971                                   p_shipping_uom => p_oe_interface_rec.requested_quantity_uom,
5972                                   p_tot_shp_qty => p_oe_interface_rec.total_shipped_quantity ,
5973                                   p_tot_shp_qty2 => p_oe_interface_rec.total_shipped_quantity2,
5974                                   x_ship_beyond_flag => l_ship_beyond_flag,
5975                                   x_fulfilled_flag => l_fulfilled_flag,
5976                                   x_return_status => l_return_status);
5977                  --haperf
5978                  WSH_UTIL_CORE.api_post_call( p_return_status => l_return_status,
5979                                               x_num_warnings =>l_num_warnings,
5980                                               x_num_errors =>l_num_errors);
5981 
5982                  IF l_debug_on THEN
5983                      WSH_DEBUG_SV.logmsg(l_module_name, 'fullfilled flag = '||l_fulfilled_flag);
5984                  END IF;
5985 
5986                  IF (NVL(l_fulfilled_flag, 'F') = 'T') THEN
5987                  --{
5988                        l_remain_detail_index := 0;
5989                        IF l_debug_on THEN
5990                                WSH_DEBUG_SV.logmsg(l_module_name, 'Ship within tolerance');
5991                        END IF;
5992                        -- LSP PROJECT : should set value when DeploymentMode is Integrated
5993                        --          or DeploymentMode is LSP but clientId is NULL (normal orders)
5994                        -- muom
5995                        IF ((Get_Line_Expected_Qty(p_oe_interface_rec.source_line_id, p_batch_id, l_fulfill_base)) > 0 and
5996                            (WMS_DEPLOY.WMS_DEPLOYMENT_MODE = 'I' OR (WMS_DEPLOY.WMS_DEPLOYMENT_MODE = 'L' and l_client_id IS NULL)) ) THEN
5997                        --{
5998                            IF l_debug_on THEN
5999                                    WSH_DEBUG_SV.logmsg(l_module_name, 'change fulfilled_flag to P because planned_quantity > 0 for the current line');
6000                            END IF;
6001                            l_fulfilled_flag := 'P';
6002                        --}
6003                        ELSE
6004                        --{
6005                            IF l_debug_on THEN
6006                                WSH_DEBUG_SV.logmsg(l_module_name, 'l_fullfilled_flag is True, need to call cancel_details for source_line = '||p_oe_interface_rec.source_line_id);
6007                            END IF;
6008                            -- Handle pending delivery details for current line
6009                            OPEN c_remain_detail_id(p_oe_interface_rec.source_line_id);
6010                            LOOP
6011                                FETCH c_remain_detail_id
6012                                INTO  l_delete_detail_id;
6013                                EXIT WHEN c_remain_detail_id %NOTFOUND;
6014                                l_remain_detail_index                      := l_remain_detail_index + 1;
6015                                l_remain_details_id(l_remain_detail_index) := l_delete_detail_id;
6016                                IF l_debug_on THEN
6017                                    WSH_DEBUG_SV.logmsg(l_module_name, 'l_remain_detail_index =  '||l_remain_detail_index||' detail_id = '||l_delete_detail_id);
6018                                END IF;
6019                            END LOOP;
6020                            CLOSE c_remain_detail_id;
6021                        --}
6022                        END IF;
6023                        -- Handle all lines in the line set which are not there in the current stop, if not processed before
6024                        -- Need to cancel the delivery details for each line depending on pending quantity
6025                        IF l_debug_on THEN
6026                            WSH_DEBUG_SV.logmsg(l_module_name, 'oe_interace_rec.source_line_set ='|| p_oe_interface_rec.source_line_set_id);
6027                        END IF;
6028                        IF ((p_oe_interface_rec.source_line_set_id IS NOT NULL) AND
6029                            (p_oe_interface_rec.source_line_set_id <> l_prev_line_set_id))THEN
6030                        --{
6031                             l_prev_line_set_id := p_oe_interface_rec.source_line_set_id;
6032                              -- Get all lines in the line set which are not there in the specified stop
6033                              OPEN c_remain_lines(p_oe_interface_rec.source_line_set_id, p_oe_interface_rec.source_header_id, p_batch_id);
6034                              LOOP
6035                              --{
6036                                  FETCH c_remain_lines
6037                                  INTO  l_line_id;
6038                                  EXIT WHEN c_remain_lines%NOTFOUND;
6039                                  -- see if the line has staged/shipped delivery details
6040                                  OPEN c_picked_dd(l_line_id, p_oe_interface_rec.source_header_id);
6041                                  FETCH c_picked_dd
6042                                  INTO  l_dummy;
6043 
6044                                  IF (c_picked_dd%NOTFOUND) THEN
6045                                  --{
6046                                      -- Cancel the pending delivery details
6047                                      OPEN c_remain_detail_id(l_line_id);
6048                                      LOOP
6049                                      --{
6050                                          FETCH c_remain_detail_id
6051                                          INTO  l_delete_detail_id;
6052                                          EXIT WHEN c_remain_detail_id %NOTFOUND;
6053                                          l_remain_detail_index                      := l_remain_detail_index + 1;
6054                                          l_remain_details_id(l_remain_detail_index) := l_delete_detail_id;
6055                                          IF l_debug_on THEN
6056                                              WSH_DEBUG_SV.logmsg(l_module_name, 'l_remain_detail_index =  '||l_remain_detail_index||' detail_id = '||l_delete_detail_id);
6057                                          END IF;
6058                                      --}
6059                                      END LOOP;
6060                                      CLOSE c_remain_detail_id;
6061                                  --}
6062                                  END IF;
6063                                    CLOSE c_picked_dd;
6064                              --}
6065                              END LOOP;
6066                              CLOSE c_remain_lines;
6067                        --}
6068                        END IF;
6069                        --Bug 7131800 : Default Return from the Cancel_Unpicked_Details_At_ITS function is Yes (Y) --Old Behaviour
6070                        --
6071                        l_cancel_unpicked_details := NULL;
6072                        --
6073                        IF (l_process_flag = FND_API.G_FALSE ) THEN
6074                        --{
6075                              IF l_debug_on THEN
6076                                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_CUSTOM_PUB.Cancel_Unpicked_Details_At_ITS', WSH_DEBUG_SV.C_PROC_LEVEL);
6077                              END IF;
6078                              l_cancel_unpicked_details := WSH_CUSTOM_PUB.Cancel_Unpicked_Details_At_ITS(  p_source_header_id => p_oe_interface_rec.source_header_id,
6079                                                                                                           p_source_line_id => p_oe_interface_rec.source_line_id,
6080                                                                                                           p_source_line_set_id => p_oe_interface_rec.source_line_set_id,
6081                                                                                                           p_remain_details_id => l_remain_details_id);
6082                              IF l_debug_on THEN
6083                                  WSH_DEBUG_SV.logmsg(l_module_name, 'l_cancel_upicked_details '|| l_cancel_unpicked_details);
6084                              END IF;
6085                              IF ( l_cancel_unpicked_details NOT IN ('Y','N') ) THEN
6086                                  IF l_debug_on THEN
6087                                          WSH_DEBUG_SV.logmsg(l_module_name, ' Error in Routine wsh_custom_pub.Cancel_Unpicked_Details_At_ITS ');
6088                                  END IF;
6089                                  RAISE FND_API.G_EXC_ERROR;
6090                              END IF;
6091                        --}
6092                        ELSE -- If it is an OPM Org, which is the current/default behaviour
6093                             l_cancel_unpicked_details := 'Y';
6094                        END IF;
6095                        --
6096                        IF (l_remain_detail_index > 0 AND l_cancel_unpicked_details = 'Y') THEN
6097                        --{
6098                            WSH_INTERFACE.Cancel_Details( p_details_id => l_remain_details_id,
6099                                                          x_return_status => l_return_status);
6100                            IF l_debug_on THEN
6101                                    WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
6102                            END IF;
6103                            WSH_UTIL_CORE.api_post_call( p_return_status => l_return_status,
6104                                                         x_num_warnings =>l_num_warnings,
6105                                                         x_num_errors =>l_num_errors);
6106                        --}
6107                        END IF;
6108                  --}
6109                  END IF; -- if l_fullfilled_flag = 'T';
6110                  --haperf
6111                  -- OM bug 2022029: this case should never happen.
6112                  -- still in the big loop which is looping through all the source
6113                  -- lines in the delivery
6114                  -- OVERSHIPMENT
6115          --}
6116          -- muom
6117          ELSIF (((p_oe_interface_rec.source_line_set_id IS NULL)  AND
6118                 ((l_fulfill_base = 'P' and p_oe_interface_rec.total_shipped_quantity > p_oe_interface_rec.order_line_quantity) or
6119                  (l_fulfill_base = 'S' and p_oe_interface_rec.total_shipped_quantity2 > p_oe_interface_rec.order_line_quantity2))) OR
6120                 ((p_oe_interface_rec.source_line_set_id IS NOT NULL)  AND
6121                  (l_fulfill_base = 'P' and l_tot_dd_shp_qty > l_tot_ord_qty) or
6122                  (l_fulfill_base = 'S' and l_tot_dd_shp_qty2 > l_tot_ord_qty2))) THEN
6123          --{
6124              IF l_debug_on THEN
6125                  WSH_DEBUG_SV.logmsg(l_module_name,'Over Shipment for order line '|| p_oe_interface_rec.source_line_id);
6126              END IF;
6127              IF (p_oe_interface_rec.top_model_line_id IS NULL) THEN
6128              --{
6129                  -- This part actually is not being used since UI doesn't allow
6130                  -- over shipment beyong tolerance
6131                  --haperf
6132                  IF l_debug_on THEN
6133                      WSH_DEBUG_SV.logmsg(l_module_name, '===============');
6134                      WSH_DEBUG_SV.logmsg(l_module_name, 'Tolerance Check');
6135                      WSH_DEBUG_SV.logmsg(l_module_name, '===============');
6136                  END IF;
6137 
6138                  Check_Tolerance( p_stop_id => NULL ,
6139                                   p_source_line_id => p_oe_interface_rec.source_line_id ,
6140                                   p_shipping_uom => p_oe_interface_rec.requested_quantity_uom,
6141                                   p_tot_shp_qty => p_oe_interface_rec.total_shipped_quantity ,
6142                                   p_tot_shp_qty2 => p_oe_interface_rec.total_shipped_quantity2 ,
6143                                   x_ship_beyond_flag => l_ship_beyond_flag,
6144                                   x_fulfilled_flag => l_fulfilled_flag,
6145                                   x_return_status => l_return_status);
6146                  --haperf
6147                  WSH_UTIL_CORE.api_post_call( p_return_status => l_return_status,
6148                                               x_num_warnings =>l_num_warnings,
6149                                               x_num_errors =>l_num_errors);
6150 
6151                  IF (l_ship_beyond_flag = 'T') THEN
6152                      /* if ship beyond tolerance, we need to warn the user */
6153                      fnd_message.set_name('WSH', 'WSH_DET_SHIP_BEYOND_TOLERANCE');
6154                      x_over_reason := 'O';
6155                  END IF;
6156              --}
6157              END IF;
6158          --}     --haperf
6159          ELSE
6160              l_fulfilled_flag:='T';
6161          END IF;
6162     --}
6163     ELSE           --tolerance is not specified
6164     --{
6165          --haperf
6166          -- muom
6167          IF (l_fulfill_base = 'P' and p_oe_interface_rec.total_requested_quantity <> p_oe_interface_rec.order_line_quantity) OR
6168             (l_fulfill_base = 'S' and p_oe_interface_rec.total_requested_quantity2 <> p_oe_interface_rec.order_line_quantity2) THEN
6169                  l_fulfilled_flag :='F';
6170          ELSE
6171                  l_fulfilled_flag:='T';
6172          END IF;
6173     --}
6174     END IF;      --End if of tolerance check
6175 
6176     x_fulfilled_flag := l_fulfilled_flag ;
6177 
6178     IF ( l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS ) THEN
6179         x_return_status := l_return_status;
6180     END IF;
6181 
6182     IF l_debug_on THEN
6183         WSH_DEBUG_SV.log(l_module_name,'x_return_status',x_return_status);
6184         WSH_DEBUG_SV.pop(l_module_name);
6185     END IF;
6186 
6187 EXCEPTION
6188 
6189   WHEN fnd_api.g_exc_error THEN
6190        x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
6191        WSH_UTIL_CORE.Get_Messages('N',l_summary, l_details, l_get_msg_count);
6192 
6193         IF c_remain_detail_id%ISOPEN THEN
6194           close c_remain_detail_id;
6195         END IF;
6196 
6197         IF c_remain_lines%ISOPEN THEN
6198           close c_remain_lines;
6199         END IF;
6200 
6201         IF c_picked_dd%ISOPEN THEN
6202           close c_picked_dd;
6203         END IF;
6204 
6205         IF l_debug_on THEN
6206             WSH_DEBUG_SV.logmsg(l_module_name, 'ERROR IN Handle_Tolerances ' );
6207             WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:fnd_api.g_exc_error');
6208         END IF;
6209 
6210 
6211   WHEN others THEN
6212         x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
6213         l_error_code := SQLCODE;
6214         l_error_text := SQLERRM;
6215 
6216         IF c_remain_detail_id%ISOPEN THEN
6217           close c_remain_detail_id;
6218         END IF;
6219 
6220         IF c_remain_lines%ISOPEN THEN
6221           close c_remain_lines;
6222         END IF;
6223 
6224         IF c_picked_dd%ISOPEN THEN
6225           close c_picked_dd;
6226         END IF;
6227 
6228         wsh_util_core.printMsg('API Handle_Tolerances failed with an unexpected error');
6229         WSH_UTIL_CORE.PrintMsg('The unexpected error is ' || l_error_text);
6230         --
6231         IF l_debug_on THEN
6232             WSH_DEBUG_SV.logmsg(l_module_name, 'UNEXPECTED ERROR IN Handle_Tolerances ' );
6233             WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
6234             WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
6235         END IF;
6236 
6237  END Handle_Tolerances;
6238 
6239 --
6240 --Function:       Part_of_PTO
6241 --Parameters:      p_source_line_id
6242 --Description:     This function returns a boolean value to
6243 --          indicate if the order line is part of a PTO
6244 
6245 
6246 FUNCTION Part_Of_PTO(p_source_code varchar2,p_source_line_id number) RETURN BOOLEAN is
6247 l_count number;
6248 --
6249 l_debug_on BOOLEAN;
6250 --
6251 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'PART_OF_PTO';
6252 --
6253 BEGIN
6254    --
6255    --
6256    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
6257    --
6258    IF l_debug_on IS NULL
6259    THEN
6260        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
6261    END IF;
6262    --
6263    IF l_debug_on THEN
6264        WSH_DEBUG_SV.push(l_module_name);
6265        --
6266        WSH_DEBUG_SV.log(l_module_name,'P_SOURCE_CODE',P_SOURCE_CODE);
6267        WSH_DEBUG_SV.log(l_module_name,'P_SOURCE_LINE_ID',P_SOURCE_LINE_ID);
6268    END IF;
6269    --
6270    SELECT count(*) into l_count
6271    from wsh_delivery_details
6272    where top_model_line_id is not null
6273    and source_line_id = p_source_line_id
6274    and source_code = p_source_code
6275    and   container_flag = 'N'
6276    and released_status <> 'D' ;  /* H integration: wrudge */
6277 
6278    IF l_debug_on THEN
6279       WSH_DEBUG_SV.log(l_module_name,'l_count',l_count);
6280    END IF;
6281    if (l_count > 0 ) THEN
6282      --
6283      IF l_debug_on THEN
6284          WSH_DEBUG_SV.pop(l_module_name);
6285      END IF;
6286      --
6287      return TRUE;
6288    --
6289    IF l_debug_on THEN
6290        WSH_DEBUG_SV.pop(l_module_name);
6291    END IF;
6292    --
6293    else return FALSE;
6294    END if;
6295 END Part_Of_PTO;
6296 
6297 FUNCTION Top_Of_Model(p_source_code varchar2,p_source_line_id number) RETURN number is
6298 l_top_id number;
6299 --
6300 l_debug_on BOOLEAN;
6301 --
6302 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'TOP_OF_MODEL';
6303 --
6304 BEGIN
6305    --
6306    --
6307    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
6308    --
6309    IF l_debug_on IS NULL
6310    THEN
6311        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
6312    END IF;
6313    --
6314    IF l_debug_on THEN
6315        WSH_DEBUG_SV.push(l_module_name);
6316        --
6317        WSH_DEBUG_SV.log(l_module_name,'P_SOURCE_CODE',P_SOURCE_CODE);
6318        WSH_DEBUG_SV.log(l_module_name,'P_SOURCE_LINE_ID',P_SOURCE_LINE_ID);
6319    END IF;
6320    --
6321    if (part_of_pto(p_source_code,p_source_line_id) = TRUE) THEN
6322      SELECT distinct top_model_line_id  into l_top_id
6323      from wsh_delivery_details
6324      where source_line_id = p_source_line_id
6325      and source_code = p_source_code
6326      and container_flag = 'N'
6327           and released_status <> 'D' ;  /* H integration: wrudge */
6328      IF l_debug_on THEN
6329          WSH_DEBUG_SV.log(l_module_name,'l_top_id',l_top_id);
6330          WSH_DEBUG_SV.pop(l_module_name);
6331      END IF;
6332      --
6333      return l_top_id;
6334    else
6335      NULL;
6336    END if;
6337    IF l_debug_on THEN
6338       WSH_DEBUG_SV.pop(l_module_name);
6339    END IF;
6340 
6341 END Top_Of_Model;
6342 
6343 --========================================================================
6344 -- PROCEDURE : update_interfaced_details
6345 --                  This procedure updates the delivery details as interfaced
6346 --                  to INV, if the lines are successfully processed by the
6347 --                  inventory transaction manager.
6348 --
6349 -- PARAMETERS: p_batch_id              The ITS batch ID
6350 --             x_return_status         The return status of the API.
6351 
6352 -- COMMENT   : This procedure updates the delivery details as interfaced to INV
6353 --             if they have been already processed by inventory system
6354 --             and the record has been entered into the table
6355 --             mtl_material_transactions.
6356 --
6357 --========================================================================
6358 
6359 procedure update_interfaced_details ( p_batch_id number  ,  x_return_status out NOCOPY  varchar2 ) is
6360 --
6361 l_debug_on BOOLEAN;
6362 --
6363 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'UPDATE_INTERFACED_DETAILS';
6364 --
6365 begin
6366 /* H integration: include transaction_source_type_id 13    wrudge */
6367 /*    transaction_source_type_id 2 and 8 are for OE */
6368 /*    transaction_source_type_id 16 is for OKE      */
6369     --
6370     --
6371     l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
6372     --
6373     IF l_debug_on IS NULL
6374     THEN
6375         l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
6376     END IF;
6377     --
6378     IF l_debug_on THEN
6379         WSH_DEBUG_SV.push(l_module_name);
6380         --
6381         WSH_DEBUG_SV.log(l_module_name,'p_batch_id',p_batch_id);
6382     END IF;
6383     --
6384     update wsh_delivery_details  dd
6385     set inv_interfaced_flag   =   c_inv_int_full ,
6386         --Added as part of bug 7645262
6387         last_update_date    = sysdate,
6388         request_id          = fnd_global.conc_request_id,
6389         last_updated_by     = fnd_global.user_id
6390 
6391     where (exists (
6392                 SELECT mmt.picking_line_id
6393                    FROM  mtl_material_transactions mmt
6394                    WHERE mmt.picking_line_id  =  dd.delivery_detail_id
6395                and transaction_source_type_id in ( 2,8,13,16 )
6396                and trx_source_line_id = dd.source_line_id
6397                    )
6398                )
6399     and container_flag = 'N'
6400     and nvl(inv_interfaced_flag , 'N')  <> c_inv_int_full
6401    and nvl(inv_interfaced_flag , 'N')  <> 'X'
6402     and dd.delivery_Detail_id in  (
6403                SELECT  da.delivery_detail_id
6404                FROM   wsh_delivery_assignments_v da ,
6405                        wsh_delivery_legs dg,
6406                        wsh_new_deliveries dl,
6407                        wsh_trip_stops st
6408                where   dl.delivery_id = da.delivery_id  AND
6409                      da.delivery_id  IS NOT NULL AND
6410                      st.stop_id = dg.pick_up_stop_id AND
6411                      st.batch_id = p_batch_id AND
6412                      st.stop_location_id = dl.initial_pickup_location_id AND
6413                      dg.delivery_id = dl.delivery_id AND
6414                      nvl(dl.SHIPMENT_DIRECTION , 'O') IN ('O', 'IO')   -- J Inbound Logistics jckwok
6415                 )
6416          and dd.source_code <> 'RTV'     -- RTV changes
6417          and dd.released_status <> 'D';   /* H integration: wrudge */
6418     --
6419     IF l_debug_on THEN
6420         WSH_DEBUG_SV.logmsg(l_module_name,  'NUMBER OF ROWS UPDATED AS INTERFACED TO INVENTORY = ' || SQL%ROWCOUNT  );
6421         WSH_DEBUG_SV.pop(l_module_name);
6422     END IF;
6423     --
6424     exception
6425        WHEN others THEN
6426         x_return_status :=  WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
6427          WSH_UTIL_CORE.PrintMsg('UPDATE_INTERFACED_DETAILS : unexpected error ');
6428          WSH_UTIL_CORE.PrintMsg( SQLCODE || ' : ' || SQLERRM );
6429 
6430          IF l_debug_on THEN
6431              WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
6432              WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
6433          END IF;
6434          --
6435 end update_interfaced_details ;
6436 
6437 
6438 /* OE_interface can be called from the ship confirm program or
6439    it can be called from a concurrent program by user in the case of
6440    oe interface failed and it needs to be re-run manually by user */
6441 --
6442 --Procedure:     oe_interface
6443 --             errbuf
6444 --             retcode
6445 --            p_stop_id
6446 --Description:   wrapper for Interface_ALL (bug 1578251)
6447 PROCEDURE oe_interface(
6448   errbuf out NOCOPY  VARCHAR2,
6449   retcode out NOCOPY  VARCHAR2,
6450   p_stop_id in number)
6451 IS
6452 --
6453 l_debug_on BOOLEAN;
6454 --
6455 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'OE_INTERFACE';
6456 --
6457 l_log_level	NUMBER:=0;
6458 BEGIN
6459  --
6460  --
6461  l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
6462  --
6463  IF l_debug_on IS NULL
6464  THEN
6465      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
6466  END IF;
6467  --
6468  IF l_debug_on THEN
6469      WSH_DEBUG_SV.push(l_module_name);
6470      --
6471      WSH_DEBUG_SV.log(l_module_name,'P_STOP_ID',P_STOP_ID);
6472 
6473      l_log_level :=1;
6474  END IF;
6475  --
6476 
6477  Interface_All(errbuf    => errbuf,
6478             retcode  => retcode,
6479             p_mode    => 'OM DSNO',
6480             p_stop_id  => p_stop_id,
6481 	    p_log_level => l_log_level);
6482  IF retcode = '0' THEN
6483    errbuf := 'OM interface is completed successfully';
6484  ELSIF retcode = '1' THEN
6485    errbuf := 'OM interface is completed with warning';
6486  ELSE
6487    errbuf := 'OM interface is completed with error';
6488  END IF;
6489  --
6490  IF l_debug_on THEN
6491      WSH_DEBUG_SV.log(l_module_name,'retcode',retcode);
6492      WSH_DEBUG_SV.pop(l_module_name);
6493  END IF;
6494  --
6495 END oe_interface;
6496 
6497 
6498 
6499 
6500 --========================================================================
6501 -- PROCEDURE : Filter_Stops_From_Batch
6502 --                  If some of stops being processed contain delivery details
6503 --                  ,which have failed to interface to OM, then this procedure
6504 --                  will remove these lines from the batch.
6505 --
6506 -- PARAMETERS: p_batch_id              The ITS batch ID
6507 --             p_stop_tab              Table of trip stop IDs in belong to the
6508 --                                     current batch.
6509 --             x_num_stops_removed     Number of stops removed from the batch.
6510 --             x_stop_tab              stop IDs left in the batch.
6511 --             x_return_status         The return status of the API.
6512 
6513 -- COMMENT   : If some of the trip stops being processed have delivery lines,
6514 --             which have failed to interface to OM, this procedure, will
6515 --             remove these stops from the batch.  The trip stops left in the
6516 --             batch will be cached in x_stop_tab and the number of the trip
6517 --             stops removed will be stored in x_num_stops_removed.  If all the
6518 --             stops in the batch have failed lines then no stop is removed from
6519 --             the batch.  x_num_stops_removed will be set to the count of all
6520 --             the stops in the batch.  This indicates to the calling program
6521 --             that all the stops in the batch have failed.
6522 --
6523 --========================================================================
6524 
6525 PROCEDURE Filter_Stops_From_Batch (p_batch_id IN NUMBER,
6526                       p_stop_tab IN wsh_util_core.id_tab_type,
6527                       x_num_stops_removed OUT NOCOPY NUMBER,
6528                       x_stop_tab OUT NOCOPY wsh_util_core.id_tab_type,
6529                       x_return_status OUT NOCOPY VARCHAR2)
6530 IS
6531 
6532    l_debug_on BOOLEAN;
6533    l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' ||
6534            'FILTER_STOPS_FROM_BATCH';
6535 
6536    l_count          NUMBER;
6537    l_start          NUMBER;
6538    i                NUMBER;
6539    j                NUMBER;
6540    l_all_stops_count NUMBER;
6541 
6542    l_found           BOOLEAN;
6543    l_err_stops       wsh_util_core.id_tab_type;
6544    l_dummy           NUMBER;
6545 
6546    CURSOR c_lock_batch (p_batch_id NUMBER) IS
6547    SELECT batch_id
6548    FROM wsh_trip_stops
6549    WHERE batch_id = p_batch_id
6550    FOR UPDATE NOWAIT;
6551 
6552 
6553    -- Cursor c_failed_stops contains stops, which have delivery details that
6554    -- have failed interface to OM.
6555 
6556    CURSOR c_failed_stops (p_batch_id NUMBER) IS
6557    SELECT DISTINCT stop_id
6558    FROM   wsh_delivery_Details dd,
6559       wsh_delivery_assignments_v da ,
6560       wsh_delivery_legs dg,
6561       wsh_new_deliveries dl,
6562       wsh_trip_stops st
6563    WHERE st.stop_id = dg.pick_up_stop_id
6564       AND st.batch_id = p_batch_id
6565       AND st.stop_location_id = dl.initial_pickup_location_id
6566       AND dg.delivery_id = dl.delivery_id
6567       AND dl.delivery_id = da.delivery_id
6568       AND da.delivery_id IS NOT NULL
6569       AND da.delivery_detail_id = dd.delivery_detail_id
6570       AND dd.oe_interfaced_flag =  'N'
6571       AND dd.source_code = 'OE'
6572       AND dd.released_status <> 'D'
6573       AND    nvl(dd.line_direction,'O') IN ('O','IO');
6574 
6575 BEGIN
6576 
6577    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
6578    --
6579    IF l_debug_on IS NULL
6580    THEN
6581        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
6582    END IF;
6583    --
6584    IF l_debug_on THEN
6585        WSH_DEBUG_SV.push(l_module_name);
6586        WSH_DEBUG_SV.log(l_module_name,'p_batch_id',p_batch_id);
6587    END IF;
6588    --
6589    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
6590    x_num_stops_removed := 0;
6591 
6592    SAVEPOINT  s_Filter_Stops_From_Batch;
6593 
6594    l_all_stops_count := p_stop_tab.COUNT;
6595 
6596    IF l_all_stops_count = 0 THEN
6597       IF l_debug_on THEN
6598           WSH_DEBUG_SV.log(l_module_name,'l_all_stops_count',l_all_stops_count);
6599           WSH_DEBUG_SV.pop(l_module_name);
6600       END IF;
6601       RETURN;
6602    END IF;
6603 
6604    --get the stops that have at least one failed lines
6605 
6606    OPEN c_failed_stops(p_batch_id);
6607    FETCH c_failed_stops BULK COLLECT INTO
6608       l_err_stops;
6609    CLOSE c_failed_stops;
6610 
6611 
6612    l_count := l_err_stops.COUNT;
6613 
6614 
6615    IF l_count = l_all_stops_count THEN --{
6616       --if all the stops failed then populate the number of stops that is
6617       -- filtered  out.
6618       --However, do not remove the batch_id from the stops, in the wrapper
6619       -- we need the batch to contain some stops to set the pending flag
6620       x_num_stops_removed := l_all_stops_count;
6621       x_stop_tab := p_stop_tab;
6622    ELSIF l_count = 0 THEN --}{
6623       --If there are not failed stops then all the stops are good
6624       x_stop_tab := p_stop_tab;
6625       x_num_stops_removed := 0;
6626    ELSIF l_all_stops_count > l_count THEN  --}{
6627 
6628       --This means there are some stops that could be processed as interfaced
6629 
6630       x_num_stops_removed := l_count;
6631       -- filter out the failed stops
6632 
6633       OPEN c_lock_batch(p_batch_id);
6634       FETCH c_lock_batch INTO l_dummy;
6635       CLOSE c_lock_batch;
6636 
6637       l_start := l_err_stops.FIRST;
6638       FORALL i IN l_start..l_count
6639       UPDATE wsh_trip_stops
6640       SET batch_id = NULL,
6641       pending_interface_flag = 'Y'
6642       WHERE stop_id = l_err_stops(i);
6643 
6644       COMMIT;
6645 
6646       i := p_stop_tab.FIRST;
6647       WHILE i IS NOT NULL LOOP --{
6648          l_found := FALSE;
6649          j := l_err_stops.FIRST;
6650          WHILE j IS NOT NULL LOOP --{
6651             IF l_err_stops(j) = p_stop_tab(i) THEN
6652                l_found := TRUE;
6653                EXIT;
6654             END IF;
6655             j := l_err_stops.NEXT(j);
6656          END LOOP; --}
6657          --
6658          IF NOT l_found THEN
6659             -- if non of the lines in the stop has failed in OM then
6660             -- it can be processed further to DSNO and INV, put this in
6661             -- x_stop_tab
6662             x_stop_tab(x_stop_tab.COUNT + 1) := p_stop_tab(i);
6663          END IF;
6664          i := p_stop_tab.NEXT(i);
6665       END LOOP; --}
6666 
6667    END IF; --}
6668 
6669    IF l_debug_on THEN --{
6670       i := l_err_stops.FIRST;
6671       WHILE i IS NOT NULL LOOP
6672          WSH_DEBUG_SV.log(l_module_name,'Failed to interface stop to OM',
6673             l_err_stops(i));
6674          i := l_err_stops.NEXT(i);
6675       END LOOP;
6676    END IF; --}
6677 
6678 
6679    IF l_debug_on THEN
6680        WSH_DEBUG_SV.log(l_module_name,'x_return_status',x_return_status   );
6681        WSH_DEBUG_SV.log(l_module_name,'l_err_stops.count',l_err_stops.COUNT );
6682        WSH_DEBUG_SV.log(l_module_name,'x_stop_tab.count',x_stop_tab.COUNT );
6683        WSH_DEBUG_SV.log(l_module_name,'l_all_stops_count',l_all_stops_count   );
6684        WSH_DEBUG_SV.log(l_module_name,'x_num_stops_removed',x_num_stops_removed   );
6685        WSH_DEBUG_SV.pop(l_module_name);
6686    END IF;
6687 
6688    EXCEPTION
6689 
6690       WHEN OTHERS THEN
6691          ROLLBACK TO s_Filter_Stops_From_Batch;
6692          x_return_status := wsh_util_core.g_ret_sts_unexp_error;
6693          wsh_util_core.default_handler('WSH_SHIP_CONFIRM_ACTIONS.Filter_Stops_From_Batch');
6694 
6695          IF l_debug_on THEN
6696             wsh_debug_sv.logmsg(l_module_name, 'Unexpected error has occured. Oracle error message is ' || SQLERRM, wsh_debug_sv.c_unexpec_err_level);
6697             wsh_debug_sv.pop(l_module_name, 'EXCEPTION:OTHERS');
6698          END IF;
6699 
6700 
6701 END Filter_Stops_From_Batch;
6702 
6703 
6704 -- start bug 1578251: move oe_interface logic to oe_interface_trip_stop and set completion_status
6705 --
6706 --========================================================================
6707 -- PROCEDURE : oe_interface_trip_stop
6708 --                  This API interfaces the trip stops being processed to the
6709 --                  Order Management.
6710 --
6711 -- PARAMETERS: p_batch_id              The ITS batch ID
6712 --             p_stop_tab              Table of trip stop IDs in belong to the
6713 --                                     current batch.
6714 --             x_num_stops_removed     Number of stops removed from the batch.
6715 --                                     If this parameter is the same as
6716 --                                     x_stop_tab.count then all the stops have
6717 --                                     failed (but they have not been removed
6718 --                                     from the batch)
6719 --             x_stop_tab              stop IDs left in the batch.
6720 --             x_completion_status     The return status of the API.
6721 --
6722 -- COMMENT   : This API first calls Interface_Stop_To_OM to interface the
6723 --             trip stops within the batch to the OM.  Interface_Stop_To_OM
6724 --             results in error or warning, then it calls
6725 --             Filter_Stops_From_Batch to filter out the failed trip stops.
6726 --             Then it calls transfer_serial_numbers for the successful stops
6727 --             to transfer the serial number information from the inventory
6728 --             tables into the shipping tables.  It populates the table
6729 --             x_stop_tab with the stops left in the batch and populates
6730 --             x_num_stops_removed with the number of the stops removed from the
6731 --             batch.  If x_num_stops_removed equals the rowcount of table
6732 --             x_stop_tab, this means that all the stops in the batch have
6733 --             failed, but they have not been removed from the batch.
6734 --
6735 --========================================================================
6736 
6737 PROCEDURE oe_interface_trip_stop(p_batch_id IN NUMBER,
6738                          p_stop_tab IN wsh_util_core.id_tab_type,
6739                          x_stop_tab OUT NOCOPY wsh_util_core.id_tab_type,
6740                          x_num_stops_removed OUT NOCOPY NUMBER,
6741                          x_completion_status OUT NOCOPY  VARCHAR2) IS
6742 
6743 l_return_status varchar2(30);
6744 l_prev_return_status varchar2(30);
6745 l_completion_status      VARCHAR2(30) := 'NORMAL';
6746 l_dummy    VARCHAR2(10);
6747 l_num_warnings NUMBER := 0;
6748 l_num_errors   NUMBER := 0;
6749 
6750 CURSOR lock_row ( p_batch_id in  NUMBER ) IS
6751 SELECT stop_id
6752 FROM wsh_trip_stops
6753 WHERE batch_id = p_batch_id
6754 FOR UPDATE NOWAIT;
6755 Recinfo lock_row%ROWTYPE;
6756 
6757 trip_stop_locked exception  ;
6758 e_Interface_Stop_to_om exception;
6759 PRAGMA EXCEPTION_INIT(trip_stop_locked, -54);
6760 
6761 l_debug_on BOOLEAN;
6762 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'OE_INTERFACE_TRIP_STOP';
6763 BEGIN
6764   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
6765   --
6766   IF l_debug_on IS NULL
6767   THEN
6768       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
6769   END IF;
6770   --
6771   IF l_debug_on THEN
6772       WSH_DEBUG_SV.push(l_module_name);
6773       WSH_DEBUG_SV.log(l_module_name,'p_batch_id',p_batch_id);
6774   END IF;
6775   --
6776 
6777   x_num_stops_removed := 0;
6778 
6779   OPEN  lock_row ( p_batch_id ) ;
6780   FETCH lock_row INTO Recinfo;
6781   IF lock_row%NOTFOUND  THEN
6782    CLOSE lock_row;
6783    x_completion_status := 'ERROR';
6784    --
6785    IF l_debug_on THEN
6786        WSH_DEBUG_SV.logmsg(l_module_name,  'OM INTERFACE CANNOT FIND BATCH ID ' || p_batch_id  );
6787        WSH_DEBUG_SV.log(l_module_name,'x_completion_status',x_completion_status);
6788        WSH_DEBUG_SV.pop(l_module_name);
6789    END IF;
6790    --
6791    return;
6792   END IF;
6793 
6794    --
6795    IF l_debug_on THEN
6796        WSH_DEBUG_SV.logmsg(l_module_name,  'OM INTERFACING BATCH ' || TO_CHAR ( p_batch_id )  );
6797    END IF;
6798    --
6799 
6800    WSH_SHIP_CONFIRM_ACTIONS.l_currentDate := SYSDATE;
6801 
6802    --HVOP heali
6803    Interface_Stop_To_OM(
6804 		p_batch_id        => p_batch_id ,
6805                 x_return_status   => l_return_status);
6806 
6807    IF l_debug_on THEN
6808        WSH_DEBUG_SV.log(l_module_name,'Interface_Stop_To_OM l_return_status',l_return_status);
6809    END IF;
6810 
6811 
6812    l_prev_return_status := l_return_status;
6813    IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN --{
6814       IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN --{
6815          raise e_Interface_Stop_to_om;
6816       END IF; --}
6817    ELSE --}{
6818       l_completion_status := 'INTERFACED' ;
6819    END if; --}
6820    --HVOP heali
6821    -- Bug 2657652 : Added call to transfer serial records from mtl_serial_numbers_temp to wsh_serial_numbers
6822    IF l_debug_on THEN
6823        WSH_DEBUG_SV.logmsg(l_module_name, 'Calling TRANSFER_SERIAL_NUMBERS FOR ' || TO_CHAR ( p_batch_id ) );
6824    END IF;
6825 
6826    IF l_prev_return_status  <> WSH_UTIL_CORE.G_RET_STS_ERROR THEN
6827       transfer_serial_numbers (  p_batch_id => p_batch_id ,
6828                                  p_interfacing => 'OM',
6829                                  x_return_status =>  l_return_status );
6830 
6831       if (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
6832          raise e_Interface_Stop_To_OM;
6833       end if;
6834    END IF;
6835 
6836    IF l_prev_return_status IN ( WSH_UTIL_CORE.G_RET_STS_WARNING,
6837                                WSH_UTIL_CORE.G_RET_STS_ERROR ) THEN --{
6838 
6839       -- filter out the failed stops from the batch.
6840 
6841       Filter_Stops_From_Batch (p_batch_id => p_batch_id,
6842                                p_stop_tab => p_stop_tab,
6843                                x_num_stops_removed => x_num_stops_removed,
6844                                x_stop_tab          => x_stop_tab,
6845                                x_return_status => l_dummy);
6846 
6847       WSH_UTIL_CORE.api_post_call(p_return_status    =>l_dummy,
6848                                 x_num_warnings     =>l_num_warnings,
6849                                 x_num_errors       =>l_num_errors);
6850 
6851       -- if x_stop_tab contains less rows than p_stop_tab then this shows
6852       -- there are some stops are removed from the batch and the rest of
6853       -- the stops can be processed as interfaced.
6854 
6855       IF x_stop_tab.COUNT < p_stop_tab.COUNT   THEN
6856          l_completion_status := 'INTERFACED';
6857       ELSE
6858          raise e_Interface_Stop_to_om;
6859       END IF;
6860 
6861    END IF; --}
6862 
6863    IF lock_row%ISOPEN THEN
6864      CLOSE lock_row;
6865    END IF;
6866 
6867    x_completion_status := l_completion_status;
6868    --
6869    IF l_debug_on THEN
6870        WSH_DEBUG_SV.log(l_module_name,'x_completion_status',x_completion_status);
6871        WSH_DEBUG_SV.pop(l_module_name);
6872    END IF;
6873 EXCEPTION
6874    when trip_stop_locked  Then
6875      IF lock_row%ISOPEN THEN
6876        CLOSE lock_row;
6877      END IF;
6878      WSH_UTIL_CORE.PrintMsg('This Trip Stop is locked by some other process');
6879      x_completion_status := 'WARNING';  -- continue processing other stops
6880      --
6881      IF l_debug_on THEN
6882          WSH_DEBUG_SV.logmsg(l_module_name,'TRIP_STOP_LOCKED exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
6883          WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:TRIP_STOP_LOCKED');
6884      END IF;
6885      --
6886 
6887    WHEN e_Interface_Stop_To_OM then
6888        WSH_UTIL_CORE.PrintMsg('Failed to interface Batch  '  ||  p_batch_id
6889             ||  '  to Order Management because API interface_header_to_OM failed');
6890        IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
6891          x_completion_status := 'ERROR';
6892        ELSE
6893          x_completion_status := 'WARNING';
6894        END IF;
6895        IF lock_row%ISOPEN THEN  -- bug 2598688: avoid invalid cursor
6896          CLOSE lock_row;
6897        END IF;
6898        --
6899        IF l_debug_on THEN
6900            WSH_DEBUG_SV.logmsg(l_module_name,'e_Interface_Stop_To_OM exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
6901            WSH_DEBUG_SV.log(l_module_name,'x_completion_status',x_completion_status);
6902            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:e_Interface_Stop_To_OM');
6903        END IF;
6904        --
6905 
6906    WHEN others then
6907 
6908 --  todo: Use wsh_util_core.default_handler and then get_message and println
6909        WSH_UTIL_CORE.PrintMsg('The unexpected error is ' || SQLERRM || to_char(SQLCODE));
6910        x_completion_status := 'ERROR';
6911        IF lock_row%ISOPEN THEN  -- bug 2598688: avoid invalid cursor
6912          CLOSE lock_row;
6913        END IF;
6914        --
6915        IF l_debug_on THEN
6916            WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
6917            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
6918        END IF;
6919        --
6920 END oe_interface_trip_stop;
6921 
6922 
6923 --========================================================================
6924 -- FUNCTION : Is_OM_Bulk_Enable
6925 --                  This API determines if the specic line is bulk enabled.
6926 --
6927 -- PARAMETERS: p_batch_id              The ITS batch ID
6928 --             p_requested_quantity    requested Quantity
6929 --             p_shipped_quantity      Shipped quantity.
6930 --             p_requested_quantity2   secondary requested quantity
6931 --             p_shipped_quantity2     secondary shipped quantity
6932 --             p_top_model_line_id     The top model line id
6933 --             p_ship_set_id           The ship set id
6934 --             p_source_line_id        Source line id
6935 --             p_source_header_id      Source header id
6936 --
6937 -- COMMENT   : This API determines if a line is bulk enabled.  A line is
6938 --             considered to be bulk enabled if it meets the following
6939 --             conditions:
6940 --             1. Order lines should be shipped completely.
6941 --                  bug 5688051: secondary shipped quantity should
6942 --                               match secondary requested quantity
6943 --                               if not null; this is to take care
6944 --                               of lot-specific quantity conversion.
6945 --             2. All the models belong to same TOP_MODEL_LINE should be
6946 --                present in the batch being processed.
6947 --             3. Lines being processed are not split in OM before.
6948 --             4. All the lines belonging to the same ship set must be present
6949 --                in the batch being processed.
6950 --             5. For standard items, check if the source line is being shipped
6951 --                completely and that there are no delivery details associated
6952 --                with the same source line but not associated to the trip stop.
6953 --
6954 --========================================================================
6955 
6956 FUNCTION Is_OM_Bulk_Enable(
6957       p_batch_id		IN	NUMBER,
6958       p_requested_quantity	IN	NUMBER,
6959       p_shipped_quantity	IN	NUMBER,
6960       p_requested_quantity2	IN	NUMBER,
6961       p_shipped_quantity2	IN	NUMBER,
6962       p_setsmc_input_rec	IN	OE_Shipping_Integration_PUB.Setsmc_Input_Rec_Type,
6963       p_source_line_id		IN	NUMBER,
6964       p_source_header_id        IN      NUMBER) RETURN boolean IS -- bug 3642085
6965 
6966 l_debug_on BOOLEAN;
6967 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'Is_OM_Bulk_Enable';
6968 
6969 
6970 CURSOR top_model_line_csr(p_batch_id NUMBER, p_top_model_line_id NUMBER, p_source_header_id NUMBER) IS
6971 SELECT  delivery_detail_id
6972 FROM 	wsh_delivery_details wdd
6973 WHERE   wdd.top_model_line_id = p_top_model_line_id
6974 AND     wdd.source_header_id = p_source_header_id -- bug 3642085
6975 AND     wdd.source_code = 'OE'                    -- bug 3642085
6976 MINUS
6977 SELECT  wdd.delivery_detail_id
6978   from wsh_delivery_details wdd,
6979        wsh_delivery_assignments_v wda,
6980        wsh_delivery_legs wdl,
6981        wsh_trip_stops wts
6982   where wts.batch_id = p_batch_id
6983   and   wdl.pick_up_stop_id = wts.stop_id
6984   and   wda.delivery_id = wdl.delivery_id
6985   and   wdd.delivery_detail_id = wda.delivery_detail_id
6986   and   wdd.container_flag = 'N'
6987   and   wdd.source_code = 'OE'
6988   AND     wdd.source_line_set_id IS NULL
6989   AND   wdd.source_header_id = p_source_header_id -- frontport of bug 4324971
6990   and   wdd.top_model_line_id = p_top_model_line_id;
6991 
6992 CURSOR ship_set_line_csr(p_batch_id NUMBER, p_ship_set_id NUMBER, p_source_header_id NUMBER) IS
6993 Select  delivery_detail_id
6994 from 	wsh_delivery_details wdd
6995 WHERE   wdd.ship_set_id = p_ship_set_id
6996 AND     wdd.source_header_id = p_source_header_id -- bug 3642085
6997 AND     wdd.source_code = 'OE'                    -- bug 3642085
6998 MINUS
6999 select wdd.delivery_detail_id
7000 from wsh_delivery_details wdd,
7001        wsh_delivery_assignments_v wda,
7002        wsh_delivery_legs wdl,
7003        wsh_trip_stops wts
7004   where wts.batch_id = p_batch_id
7005   and   wdl.pick_up_stop_id = wts.stop_id
7006   and   wda.delivery_id = wdl.delivery_id
7007   and   wdd.delivery_detail_id = wda.delivery_detail_id
7008   and   wdd.container_flag = 'N'
7009   and   wdd.source_code = 'OE'
7010   AND     wdd.source_line_set_id IS NULL
7011   and   wdd.ship_set_id = p_ship_set_id;
7012 
7013 CURSOR std_item_line_csr (p_batch_id NUMBER, p_source_line_id NUMBER) IS
7014 SELECT   delivery_detail_id
7015 from wsh_delivery_details wdd
7016 WHERE   wdd.source_line_id = p_source_line_id
7017 AND     wdd.source_code = 'OE'                    -- bug 3642085
7018 MINUS
7019 SELECT  wdd.delivery_detail_id
7020   from wsh_delivery_details wdd,
7021        wsh_delivery_assignments_v wda,
7022        wsh_delivery_legs wdl,
7023        wsh_trip_stops wts
7024   where wts.batch_id = p_batch_id
7025   and   wdl.pick_up_stop_id = wts.stop_id
7026   and   wda.delivery_id = wdl.delivery_id
7027   and   wdd.delivery_detail_id = wda.delivery_detail_id
7028   and   wdd.container_flag = 'N'
7029   and   wdd.source_code = 'OE'
7030   AND     wdd.source_line_set_id IS NULL
7031   and   wdd.source_line_id = p_source_line_id;
7032 
7033 l_return_status			varchar2(1);
7034 l_temp				NUMBER;
7035 l_bulk				boolean ;
7036 l_model_cache_tbl 		WSH_UTIL_CORE.boolean_tab_type;
7037 l_model_cache_ext_tbl 		WSH_UTIL_CORE.boolean_tab_type;
7038 l_ship_cache_tbl 		WSH_UTIL_CORE.boolean_tab_type;
7039 l_ship_cache_ext_tbl 		WSH_UTIL_CORE.boolean_tab_type;
7040 l_std_cache_tbl 		WSH_UTIL_CORE.boolean_tab_type;
7041 l_std_cache_ext_tbl 		WSH_UTIL_CORE.boolean_tab_type;
7042 l_setsmc_output_rec             OE_Shipping_Integration_PUB.Setsmc_Output_Rec_Type;
7043 e_raise_others                  EXCEPTION;
7044 
7045 BEGIN
7046    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
7047    IF l_debug_on IS NULL THEN
7048        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
7049    END IF;
7050 
7051    IF l_debug_on THEN
7052        WSH_DEBUG_SV.push(l_module_name);
7053        WSH_DEBUG_SV.log(l_module_name,'P_batch_id',P_batch_id);
7054        WSH_DEBUG_SV.log(l_module_name,'p_requested_quantity',p_requested_quantity);
7055        WSH_DEBUG_SV.log(l_module_name,'p_shipped_quantity',p_shipped_quantity);
7056        WSH_DEBUG_SV.log(l_module_name,'p_requested_quantity2',p_requested_quantity2);
7057        WSH_DEBUG_SV.log(l_module_name,'p_shipped_quantity2',p_shipped_quantity2);
7058        WSH_DEBUG_SV.log(l_module_name,'top_model_line_id',p_setsmc_input_rec.top_model_line_id);
7059        WSH_DEBUG_SV.log(l_module_name,'ship_set_id',p_setsmc_input_rec.ship_set_id);
7060        WSH_DEBUG_SV.log(l_module_name,'p_source_line_id',p_source_line_id);
7061        WSH_DEBUG_SV.log(l_module_name,'p_source_header_id',p_source_header_id);
7062    END IF;
7063 
7064 
7065    IF     (p_requested_quantity =p_shipped_quantity)
7066       AND (nvl(p_requested_quantity2,0) = nvl(p_shipped_quantity2,0))
7067          THEN -- {
7068          IF l_debug_on THEN
7069             WSH_DEBUG_SV.logmsg(l_module_name, 'Request qty and  Shipped qty are equal.');
7070          END IF;
7071 
7072          -- Processing Model Line
7073          IF (p_setsmc_input_rec.top_model_line_id is NOT NULL) THEN
7074               IF l_debug_on THEN
7075                  WSH_DEBUG_SV.logmsg(l_module_name, ' Processing Model Line');
7076               END IF;
7077 
7078             --Check if bulk status is found for current top model line in cache
7079              WSH_UTIL_CORE.get_cached_value(
7080                              p_cache_tbl 	=> l_model_cache_tbl,
7081                              p_cache_ext_tbl 	=> l_model_cache_ext_tbl,
7082                              p_value 		=> l_bulk,
7083                              p_key 		=> p_setsmc_input_rec.top_model_line_id,
7084                              p_action 		=> 'GET',
7085                              x_return_status 	=> l_return_status) ;
7086 
7087             --IF (not found in cache) THEN
7088             IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING) THEN --{
7089                IF l_debug_on THEN
7090                   WSH_DEBUG_SV.logmsg(l_module_name,
7091                     ' Calling OE_Shipping_Integration_PUB.Get_SetSMC_Interface_Status');
7092                END IF;
7093                OE_Shipping_Integration_PUB.Get_SetSMC_Interface_Status(
7094                    p_setsmc_input_rec    => p_setsmc_input_rec,
7095                    p_setsmc_output_rec   => l_setsmc_output_rec,
7096                    x_return_status       => l_return_status);
7097 
7098                IF l_debug_on THEN
7099                    WSH_DEBUG_SV.log(l_module_name,'l_return_status',
7100                                                              l_return_status);
7101                    WSH_DEBUG_SV.log(l_module_name,'x_interface_status',
7102                                     l_setsmc_output_rec.x_interface_status);
7103                END IF;
7104                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7105                   raise  FND_API.G_EXC_ERROR;
7106                END IF;
7107 
7108                IF l_setsmc_output_rec.x_interface_status = 'Y' THEN --{
7109 
7110                   OPEN  top_model_line_csr(p_batch_id,p_setsmc_input_rec.top_model_line_id, p_source_header_id);
7111                   FETCH top_model_line_csr INTO l_temp;
7112 
7113                   IF (top_model_line_csr%NOTFOUND) THEN
7114                    l_bulk:=true;
7115                   ELSE
7116                    l_bulk:=false;
7117                   END IF;
7118 
7119                   CLOSE top_model_line_csr;
7120                ELSE --}{
7121                   l_bulk:=false;
7122                END IF; --}
7123 
7124                --Cache top_model_id and bulk status.
7125                WSH_UTIL_CORE.get_cached_value(
7126                              p_cache_tbl 	=> l_model_cache_tbl,
7127                              p_cache_ext_tbl 	=> l_model_cache_ext_tbl,
7128                              p_value 		=> l_bulk,
7129                              p_key 		=> p_setsmc_input_rec.top_model_line_id,
7130                              p_action 		=> 'PUT',
7131                              x_return_status 	=> l_return_status) ;
7132 
7133                IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
7134                   raise  FND_API.G_EXC_ERROR;
7135                END IF;
7136 
7137             ELSIF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN --}{
7138                raise  FND_API.G_EXC_ERROR;
7139             END IF; --}
7140          END IF;
7141          -- Processing Model Line
7142 
7143 
7144          -- Processing Ship Set Line
7145          IF (p_setsmc_input_rec.ship_set_id is NOT NULL)
7146               AND (NVL(l_bulk,TRUE) ) then
7147               IF l_debug_on THEN
7148                  WSH_DEBUG_SV.logmsg(l_module_name, ' Processing Ship Set Line');
7149               END IF;
7150 
7151             --Check if bulk status is found for current ship_set line in cache
7152              WSH_UTIL_CORE.get_cached_value(
7153                              p_cache_tbl 	=> l_ship_cache_tbl,
7154                              p_cache_ext_tbl 	=> l_ship_cache_ext_tbl,
7155                              p_value 		=> l_bulk,
7156                              p_key 		=> p_setsmc_input_rec.ship_set_id,
7157                              p_action 		=> 'GET',
7158                              x_return_status 	=> l_return_status) ;
7159 
7160             --IF (not found in cache) THEN
7161             IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING) THEN
7162                IF l_debug_on THEN
7163                   WSH_DEBUG_SV.logmsg(l_module_name,
7164                     ' Calling OE_Shipping_Integration_PUB.Get_SetSMC_Interface_Status');
7165                END IF;
7166                OE_Shipping_Integration_PUB.Get_SetSMC_Interface_Status(
7167                    p_setsmc_input_rec    => p_setsmc_input_rec,
7168                    p_setsmc_output_rec   => l_setsmc_output_rec,
7169                    x_return_status       => l_return_status);
7170 
7171                IF l_debug_on THEN
7172                    WSH_DEBUG_SV.log(l_module_name,'l_return_status',
7173                                                              l_return_status);
7174                    WSH_DEBUG_SV.log(l_module_name,'x_interface_status',
7175                                     l_setsmc_output_rec.x_interface_status);
7176                END IF;
7177 
7178                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7179                   raise  FND_API.G_EXC_ERROR;
7180                END IF;
7181                IF l_setsmc_output_rec.x_interface_status = 'Y' THEN --{
7182                   OPEN  ship_set_line_csr(p_batch_id,p_setsmc_input_rec.ship_set_id, p_source_header_id);
7183                   FETCH ship_set_line_csr INTO l_temp;
7184 
7185                   IF (ship_set_line_csr%NOTFOUND) THEN
7186                    l_bulk:=true;
7187                   ELSE
7188                    l_bulk:=false;
7189                   END IF;
7190 
7191                   CLOSE ship_set_line_csr;
7192                ELSE --}{
7193                    l_bulk:=false;
7194                END IF; --}
7195                --Cache top_model_id and bulk status.
7196                WSH_UTIL_CORE.get_cached_value(
7197                              p_cache_tbl 	=> l_ship_cache_tbl,
7198                              p_cache_ext_tbl 	=> l_ship_cache_ext_tbl,
7199                              p_value 		=> l_bulk,
7200                              p_key 		=> p_setsmc_input_rec.ship_set_id,
7201                              p_action 		=> 'PUT',
7202                              x_return_status 	=> l_return_status) ;
7203 
7204                IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
7205                   raise  FND_API.G_EXC_ERROR;
7206                END IF;
7207             ELSIF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
7208                raise  FND_API.G_EXC_ERROR;
7209             END IF;
7210          END IF;
7211          -- Processing Ship Set Line
7212 
7213 
7214          --Standard item
7215          IF (p_setsmc_input_rec.ship_set_id is NULL
7216             And p_setsmc_input_rec.top_model_line_id IS NULL) then
7217               IF l_debug_on THEN
7218                  WSH_DEBUG_SV.logmsg(l_module_name, ' Processing Standard Line');
7219               END IF;
7220 
7221             --Check if bulk status is found for current ato_line in cache
7222              WSH_UTIL_CORE.get_cached_value(
7223                              p_cache_tbl 	=> l_std_cache_tbl,
7224                              p_cache_ext_tbl 	=> l_std_cache_ext_tbl,
7225                              p_value 		=> l_bulk,
7226                              p_key 		=> p_source_line_id,
7227                              p_action 		=> 'GET',
7228                              x_return_status 	=> l_return_status) ;
7229 
7230             --IF (not found in cache) THEN
7231             IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING) THEN
7232                OPEN  std_item_line_csr(p_batch_id,p_source_line_id);
7233                FETCH std_item_line_csr INTO l_temp;
7234 
7235                IF (std_item_line_csr%NOTFOUND) THEN
7236                 l_bulk:=true;
7237                ELSE
7238                 l_bulk:=false;
7239                END IF;
7240                CLOSE std_item_line_csr;
7241 
7242                --Cache top_model_id and bulk status.
7243                WSH_UTIL_CORE.get_cached_value(
7244                              p_cache_tbl 	=> l_std_cache_tbl,
7245                              p_cache_ext_tbl 	=> l_std_cache_ext_tbl,
7246                              p_value 		=> l_bulk,
7247                              p_key 		=> p_source_line_id,
7248                              p_action 		=> 'PUT',
7249                              x_return_status 	=> l_return_status) ;
7250 
7251                IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
7252                   raise  FND_API.G_EXC_ERROR;
7253                END IF;
7254             ELSIF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
7255                raise  FND_API.G_EXC_ERROR;
7256             END IF;
7257          END IF;
7258          --Standard item
7259 
7260    ELSE -- }{
7261          -- Request qty and  Shipped qty are not equal.
7262          l_bulk:=FALSE;
7263          IF l_debug_on THEN
7264             WSH_DEBUG_SV.logmsg(l_module_name, 'Request qty and  Shipped qty are not equal. l_bulk is FALSE');
7265          END IF;
7266    END IF; -- }
7267 
7268 
7269    IF l_debug_on THEN
7270      WSH_DEBUG_SV.pop(l_module_name);
7271    END IF;
7272 
7273    RETURN NVL(l_bulk, FALSE);
7274 EXCEPTION
7275  WHEN others THEN
7276    IF l_debug_on THEN
7277      WSH_DEBUG_SV.logmsg(l_module_name, 'UNEXPECTED ERROR IN Is_OM_Bulk_Enable' );
7278      WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,
7279                                                                   WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
7280      WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
7281    END IF;
7282    raise e_raise_others;
7283 END Is_OM_Bulk_Enable;
7284 
7285 
7286 --========================================================================
7287 -- PROCEDURE : print_ship_line
7288 --                  This API prints debug information for the PLSQL table, which
7289 --                  is being passed to OM to be interfaced.
7290 --
7291 -- PARAMETERS: p_bulk_mode             Bulk mode for OM interface
7292 --             p_ship_line             Record of tables to be printed
7293 --             p_start_index           Start index for p_ship_line.
7294 --             p_end_index             End index for p_end_index.
7295 --
7296 -- COMMENT   : If p_start_index and p_end_index is passed then prints the
7297 --             information for the rows (table p_ship_line) between these 2
7298 --             indexes, else if print the whole table.
7299 --
7300 --========================================================================
7301 
7302 PROCEDURE print_ship_line (p_bulk_mode		IN	varchar2,
7303 			   p_ship_line	        IN OE_Ship_Confirmation_Pub.Ship_Line_Rec_Type,
7304 			   p_start_index	IN number default null,
7305 			   p_end_index		IN number default null) IS
7306 
7307 l_debug_on BOOLEAN;
7308 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'print_ship_line';
7309 
7310 l_start_index	number;
7311 l_end_index	number;
7312 
7313 BEGIN
7314    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
7315    IF l_debug_on IS NULL THEN
7316        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
7317    END IF;
7318 
7319    IF l_debug_on THEN
7320        WSH_DEBUG_SV.push(l_module_name);
7321        WSH_DEBUG_SV.log(l_module_name,'p_start_index',p_start_index);
7322        WSH_DEBUG_SV.log(l_module_name,'p_end_index',p_end_index);
7323    END IF;
7324  IF (p_start_index is null or p_end_index is null) THEN
7325   l_start_index := p_ship_line.fulfilled_flag.first;
7326   l_end_index := p_ship_line.fulfilled_flag.last;
7327  ELSE
7328   l_start_index := p_start_index;
7329   l_end_index := p_end_index;
7330  END IF;
7331 
7332 
7333    IF l_debug_on THEN
7334 
7335  IF (p_bulk_mode='N') THEN
7336  FOR i IN l_start_index..l_end_index LOOP
7337 
7338  WSH_DEBUG_SV.logmsg(l_module_name,'#########NON BULK##############');
7339  WSH_DEBUG_SV.log(l_module_name,'Index',i);
7340  WSH_DEBUG_SV.log(l_module_name,'fulfilled_flag',p_ship_line.fulfilled_flag(i));
7341  WSH_DEBUG_SV.log(l_module_name,'actual_shipment_date',p_ship_line.actual_shipment_date(i));
7342  WSH_DEBUG_SV.log(l_module_name,'shipping_quantity2',p_ship_line.shipping_quantity2(i));
7343  WSH_DEBUG_SV.log(l_module_name,'shipping_quantity',p_ship_line.shipping_quantity(i));
7344  WSH_DEBUG_SV.log(l_module_name,'shipping_quantity_uom2',p_ship_line.shipping_quantity_uom2(i));
7345  WSH_DEBUG_SV.log(l_module_name,'shipping_quantity_uom',p_ship_line.shipping_quantity_uom(i));
7346  -- muom
7347  WSH_DEBUG_SV.log(l_module_name,'shipped_quantity',p_ship_line.shipped_quantity(i));
7348  WSH_DEBUG_SV.log(l_module_name,'line_id',p_ship_line.line_id(i));
7349  WSH_DEBUG_SV.log(l_module_name,'header_id',p_ship_line.header_id(i));
7350  WSH_DEBUG_SV.log(l_module_name,'top_model_line_id',p_ship_line.top_model_line_id(i));
7351  WSH_DEBUG_SV.log(l_module_name,'ato_line_id',p_ship_line.ato_line_id(i));
7352  WSH_DEBUG_SV.log(l_module_name,'ship_set_id',p_ship_line.ship_set_id(i));
7353  WSH_DEBUG_SV.log(l_module_name,'arrival_set_id',p_ship_line.arrival_set_id(i));
7354  WSH_DEBUG_SV.log(l_module_name,'inventory_item_id',p_ship_line.inventory_item_id(i));
7355  WSH_DEBUG_SV.log(l_module_name,'ship_from_org_id',p_ship_line.ship_from_org_id(i));
7356  WSH_DEBUG_SV.log(l_module_name,'line_set_id',p_ship_line.line_set_id(i));
7357  WSH_DEBUG_SV.log(l_module_name,'smc_flag',p_ship_line.smc_flag(i));
7358  WSH_DEBUG_SV.log(l_module_name,'over_ship_reason_code',p_ship_line.over_ship_reason_code(i));
7359  WSH_DEBUG_SV.log(l_module_name,'requested_quantity',p_ship_line.requested_quantity(i));
7360  WSH_DEBUG_SV.log(l_module_name,'requested_quantity2',p_ship_line.requested_quantity2(i));
7361  WSH_DEBUG_SV.log(l_module_name,'pending_quantity',p_ship_line.pending_quantity(i));
7362  WSH_DEBUG_SV.log(l_module_name,'pending_quantity2',p_ship_line.pending_quantity2(i));
7363  WSH_DEBUG_SV.log(l_module_name,'pending_requested_flag',p_ship_line.pending_requested_flag(i));
7364  WSH_DEBUG_SV.log(l_module_name,'order_quantity_uom',p_ship_line.order_quantity_uom(i));
7365  WSH_DEBUG_SV.log(l_module_name,'order_quantity_uom2',p_ship_line.order_quantity_uom2(i));
7366  WSH_DEBUG_SV.log(l_module_name,'model_remnant_flag',p_ship_line.model_remnant_flag(i));
7367  WSH_DEBUG_SV.log(l_module_name,'ordered_quantity',p_ship_line.ordered_quantity(i));
7368  WSH_DEBUG_SV.log(l_module_name,'ordered_quantity2',p_ship_line.ordered_quantity2(i));
7369  WSH_DEBUG_SV.log(l_module_name,'item_type_code',p_ship_line.item_type_code(i));
7370  WSH_DEBUG_SV.log(l_module_name,'calculate_price_flag',p_ship_line.calculate_price_flag(i));
7371 
7372  END LOOP;
7373 
7374  ELSE
7375  FOR i IN l_start_index..l_end_index LOOP
7376 
7377  WSH_DEBUG_SV.logmsg(l_module_name,'#########BULK##############');
7378  WSH_DEBUG_SV.log(l_module_name,'Index',i);
7379  WSH_DEBUG_SV.log(l_module_name,'header_id',p_ship_line.header_id(i));
7380  WSH_DEBUG_SV.log(l_module_name,'line_id',p_ship_line.line_id(i));
7381  WSH_DEBUG_SV.log(l_module_name,'top Model line_id',p_ship_line.top_model_line_id(i));
7382  WSH_DEBUG_SV.log(l_module_name,'ship set line_id',p_ship_line.ship_set_id(i));
7383  WSH_DEBUG_SV.log(l_module_name,'arrival_set_id',p_ship_line.arrival_set_id(i));
7384  WSH_DEBUG_SV.log(l_module_name,'actual_shipment_date',p_ship_line.actual_shipment_date(i));
7385  WSH_DEBUG_SV.log(l_module_name,'shipping_quantity',p_ship_line.shipping_quantity(i));
7386  WSH_DEBUG_SV.log(l_module_name,'shipping_quantity_uom',p_ship_line.shipping_quantity_uom(i));
7387  -- muom
7388  WSH_DEBUG_SV.log(l_module_name,'shipped_quantity',p_ship_line.shipped_quantity(i));
7389  WSH_DEBUG_SV.log(l_module_name,'shipping_quantity2',p_ship_line.shipping_quantity2(i));
7390  WSH_DEBUG_SV.log(l_module_name,'shipping_quantity_uom2',p_ship_line.shipping_quantity_uom2(i));
7391  WSH_DEBUG_SV.log(l_module_name,'flow_status_code',p_ship_line.flow_status_code(i));
7392  WSH_DEBUG_SV.log(l_module_name,'ordered_quantity',p_ship_line.ordered_quantity(i));
7393  WSH_DEBUG_SV.log(l_module_name,'ordered_quantity2',p_ship_line.ordered_quantity2(i));
7394  END LOOP;
7395  END IF;
7396 
7397       WSH_DEBUG_SV.pop(l_module_name);
7398    END IF;
7399 
7400 EXCEPTION
7401     WHEN others THEN
7402 
7403       IF l_debug_on THEN
7404           WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
7405          WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
7406       END IF;
7407 END print_ship_line;
7408 
7409 
7410 --========================================================================
7411 -- PROCEDURE : Process_Stop_To_OM
7412 --                  This API is called from Interface_Stop_To_OM to interface
7413 --                  the lines to the OM.
7414 --
7415 -- PARAMETERS: p_batch_id              ITS batch id.
7416 --             p_bulk_ship_line        Record of tables containing order line
7417 --                                     information.
7418 --             p_bulk_req_line         Record of tables containing additional
7419 --                                     information for non-bulk enabled lines.
7420 --             p_bulk_mode             Bulk mode for OM API
7421 --             p_org_id                org_id for non-bulk lines.
7422 --             x_freight_costs         PLSQL table containing the freight cost
7423 --                                     for all the lines within the batch.
7424 --             x_charges_are_calculated Boolean, indicates if the charges have
7425 --                                     been calculated.
7426 --             x_return_status         The return status of the API.
7427 --
7428 -- COMMENT   : For non bulk mode (p_bulk_mode = 'N') all the lines in tables
7429 --             p_bulk_ship_line and p_bulk_req_line are passed to the OM
7430 --             API for processing.  If profile option WSH_BULK_BATCH_SIZE
7431 --             contains a batch size and the processing mode is Bulk mode then
7432 --             the lines in table p_bulk_ship_line are passed to OM API in
7433 --             bulk size chunks.  Also if table p_bulk_ship_line contains lines
7434 --             with different org_id, then OM API is called once per org_id.
7435 --             The freight charge for each order line is calculated and passed
7436 --             to OM API.  The first time Process_Stop_To_OM is called, all the
7437 --             freight charges for all the lines within the batch is calculated
7438 --             and put in table x_freight_costs.  Then for all the lines being
7439 --             passed to OM API, the corresponding freight charges will be
7440 --             retrieved from table x_freight_costs and passed to the OM API.
7441 --
7442 --========================================================================
7443 
7444 PROCEDURE Process_Stop_To_OM (
7445         p_batch_id         IN    	NUMBER,
7446         p_bulk_ship_line  IN OUT NOCOPY OE_Ship_Confirmation_Pub.Ship_Line_Rec_Type,
7447         p_bulk_req_line   IN OUT NOCOPY OE_Ship_Confirmation_Pub.Ship_Line_Rec_Type,
7448         p_bulk_mode       IN    	varchar2,
7449         p_org_id       	  IN    	NUMBER DEFAULT NULL,
7450         x_freight_costs   IN OUT NOCOPY OE_Ship_Confirmation_Pub.Ship_Adj_Rec_Type,
7451         x_charges_are_calculated IN OUT NOCOPY BOOLEAN ,
7452         x_return_status   IN OUT NOCOPY varchar2) IS
7453 
7454 l_debug_on BOOLEAN;
7455 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'Process_Stop_To_OM';
7456 
7457 process_freight_costs_failed 	EXCEPTION;
7458 
7459 l_return_status		varchar2(1);
7460 l_summary               VARCHAR2(3000);
7461 x_msg_count		number;
7462 x_msg_data		VARCHAR2(3000);
7463 
7464 l_freight_costs_all     WSH_FC_INTERFACE_PKG.OMInterfaceCostTabType;
7465 l_ship_adj_line_all	OE_Ship_Confirmation_Pub.Ship_Adj_Rec_Type;
7466 l_ship_adj_line		OE_Ship_Confirmation_Pub.Ship_Adj_Rec_Type;
7467 
7468 l_total_count		NUMBER:=0;
7469 l_start_index		NUMBER;
7470 l_end_index		NUMBER;
7471 l_dummy                 NUMBER;
7472 l_error_count		NUMBER:=0;
7473 l_warn_count		NUMBER:=0;
7474 l_loop_count		NUMBER:=0;
7475 l_count			NUMBER:=0;
7476 l_row_count			NUMBER:=0;
7477 l_bulk_count		NUMBER := 0;
7478 l_line_idx              NUMBER;
7479 l_charge_idx            NUMBER;
7480 l_counter               NUMBER;
7481 l_lines_tab             OE_WSH_BULK_GRP.T_NUM := OE_WSH_BULK_GRP.T_NUM();
7482 l_stop_id               NUMBER;
7483 l_bulk_batch_size       NUMBER;
7484 l_index                 NUMBER;
7485 x                       number;
7486 l_prev_org_id           NUMBER ;
7487 l_org_change            BOOLEAN ;
7488 l_header_id		NUMBER;
7489 
7490 CURSOR c_get_batch_stops (p_batch_id NUMBER) IS
7491 SELECT stop_id
7492 FROM wsh_trip_stops
7493 WHERE batch_id = p_batch_id
7494 ORDER BY stop_id ;
7495 
7496 CURSOR c_get_stop_lines (p_stop_id NUMBER) IS
7497 SELECT  wdd.source_line_id
7498 FROM wsh_delivery_details wdd,
7499      wsh_trip_stops wts,
7500      wsh_delivery_legs wdl,
7501      wsh_delivery_assignments_v wda
7502 WHERE wts.stop_id = p_stop_id
7503 AND   wdl.pick_up_stop_id = wts.stop_id
7504 AND   wdl.delivery_id = wda.delivery_id
7505 AND   wdd.delivery_detail_id = wda.delivery_detail_id
7506 AND   nvl(wdd.LINE_DIRECTION , 'O') IN ('O', 'IO')
7507 AND   wdd.released_status = 'C'
7508 AND   wdd.container_flag='N'
7509 AND   wdd.oe_interfaced_flag <> 'Y'
7510 AND   wdd.source_code = 'OE'
7511 ORDER BY wdd.source_line_id;
7512 
7513 e_next_record   EXCEPTION;
7514 
7515 --hadcp
7516 l_dcp_profile	NUMBER;
7517 l_oe_interfaced_flag VARCHAR2(1);
7518 l_container_flag VARCHAR2(1);
7519 l_source_code VARCHAR2(2);
7520 l_released_status VARCHAR2(2);
7521 --hadcp
7522 BEGIN
7523    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
7524    IF l_debug_on IS NULL THEN
7525        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
7526    END IF;
7527 
7528    IF l_debug_on THEN
7529        WSH_DEBUG_SV.push(l_module_name);
7530        WSH_DEBUG_SV.log(l_module_name,'p_batch_id',p_batch_id);
7531        WSH_DEBUG_SV.log(l_module_name,'p_bulk_mode',p_bulk_mode);
7532        WSH_DEBUG_SV.log(l_module_name,'p_org_id',p_org_id);
7533        WSH_DEBUG_SV.log(l_module_name,'p_bulk_ship_line.count',p_bulk_ship_line.line_id.count);
7534        WSH_DEBUG_SV.log(l_module_name,'p_bulk_req_line.count',p_bulk_req_line.line_id.count);
7535        WSH_DEBUG_SV.log(l_module_name,'x_charges_are_calculated',x_charges_are_calculated);
7536    END IF;
7537 
7538    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
7539 
7540 
7541 
7542    IF (p_bulk_mode='N') THEN
7543 
7544       l_header_id := p_bulk_ship_line.header_id(p_bulk_ship_line.header_id.FIRST);
7545       IF l_debug_on THEN
7546         WSH_DEBUG_SV.log(l_module_name,'l_header_id',l_header_id);
7547       END IF;
7548 
7549 --R12:MOAC replace call, updated comment
7550       --Set the Policy Context for non bulk
7551       MO_GLOBAL.set_policy_context('S', p_org_id);
7552    END IF;
7553 
7554 
7555    FND_PROFILE.Get('WSH_BULK_BATCH_SIZE',l_bulk_batch_size);
7556 
7557    --hadcp
7558    WSH_DCP_PVT.G_CALL_DCP_CHECK := 'N';
7559    l_dcp_profile := WSH_DCP_PVT.G_CHECK_DCP;
7560 
7561    IF l_dcp_profile IS NULL THEN
7562        l_dcp_profile := wsh_dcp_pvt.is_dcp_enabled;
7563    END IF;
7564 
7565    --hadcp
7566 
7567    IF l_debug_on THEN
7568        WSH_DEBUG_SV.log(l_module_name,'l_bulk_batch_size',l_bulk_batch_size);
7569        WSH_DEBUG_SV.log(l_module_name,'l_dcp_profile',l_dcp_profile);
7570    END IF;
7571 
7572 
7573    -- Calculate the charges for all the stops in the batch and save it into
7574    -- the table x_freight_costs.  If this calculation has been done once, skip
7575    -- this step.
7576 
7577    --IF x_freight_costs.line_id.COUNT = 0 THEN
7578    IF NOT x_charges_are_calculated THEN --{
7579 
7580       -- get all the stops with this batch_id
7581 
7582       OPEN c_get_batch_stops (p_batch_id);
7583       LOOP --{
7584          FETCH c_get_batch_stops INTO l_stop_id;
7585          EXIT WHEN c_get_batch_stops%NOTFOUND;
7586 
7587          l_lines_tab.DELETE;
7588 
7589          -- get all the source_lines for the stop
7590 
7591          OPEN c_get_stop_lines(l_stop_id);
7592          FETCH c_get_stop_lines BULK COLLECT INTO
7593             l_lines_tab;
7594          CLOSE c_get_stop_lines;
7595 
7596          l_start_index := l_lines_tab.FIRST;
7597 
7598          -- calculate the charges for each stop
7599 
7600 
7601          WSH_FC_INTERFACE_PKG.Process_Freight_Costs(
7602               p_stop_id           => l_stop_id,
7603               p_start_index	    => l_start_index,
7604               p_line_id_tbl       => l_lines_tab,
7605               x_freight_costs_all => l_freight_costs_all,
7606               x_freight_costs     => l_ship_adj_line_all,
7607               x_end_index	    => l_dummy,
7608               x_return_status     => l_return_status);
7609 
7610 
7611          IF l_debug_on THEN
7612           WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
7613           WSH_DEBUG_SV.log(l_module_name,'stop id',l_stop_id);
7614           WSH_DEBUG_SV.log(l_module_name,'l_lines_tab.count',
7615                                                         l_lines_tab.COUNT);
7616           WSH_DEBUG_SV.log(l_module_name,'l_ship_adj_line_all.line_id.count',l_ship_adj_line_all.line_id.count);
7617          END IF;
7618 
7619 
7620          IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
7621             RAISE process_freight_costs_failed;
7622          END IF;
7623 
7624          l_freight_costs_all.DELETE;
7625 
7626       END LOOP; --}
7627 
7628       x_freight_costs := l_ship_adj_line_all;
7629       x_charges_are_calculated := TRUE;
7630    END IF; --}
7631 
7632 
7633    l_row_count := p_bulk_ship_line.line_id.count;
7634    l_end_index := l_row_count;
7635    l_start_index := p_bulk_ship_line.line_id.first;
7636 
7637    IF (p_bulk_mode) = 'Y' AND (l_start_index IS NOT NULL) THEN
7638       l_prev_org_id := p_bulk_ship_line.org_id(l_start_index);
7639 --R12:MOAC replace call
7640       MO_GLOBAL.set_policy_context('S', l_prev_org_id);
7641       IF l_debug_on THEN
7642          WSH_DEBUG_SV.log(l_module_name,'setting the org',l_prev_org_id);
7643       END IF;
7644    END IF;
7645 
7646    --hadcp
7647    IF (l_dcp_profile IN (1,2) ) THEN
7648       WSH_DCP_PVT.G_INIT_MSG_COUNT := fnd_msg_pub.count_msg;
7649    END IF;
7650    IF l_debug_on THEN
7651       WSH_DEBUG_SV.log(l_module_name,'Outside Loop WSH_DCP_PVT.G_INIT_MSG_COUNT',WSH_DCP_PVT.G_INIT_MSG_COUNT);
7652    END IF;
7653    --hadcp
7654 
7655    l_line_idx := l_start_index;
7656    l_counter := 1;
7657 
7658    WHILE (l_line_idx IS NOT NULL) LOOP --{
7659     BEGIN --{ DCP Block
7660 
7661       BEGIN --{
7662 
7663          l_org_change := FALSE;
7664 
7665          IF p_bulk_mode = 'Y' THEN --{
7666             IF l_prev_org_id <> p_bulk_ship_line.org_id(l_line_idx) THEN
7667                l_prev_org_id := p_bulk_ship_line.org_id(l_line_idx);
7668                IF l_debug_on THEN
7669                   WSH_DEBUG_SV.log(l_module_name,'l_prev_org_id', l_prev_org_id);
7670                   WSH_DEBUG_SV.log(l_module_name,'l_line_idx', l_line_idx);
7671                   WSH_DEBUG_SV.log(l_module_name,'l_bulk_count', l_bulk_count);
7672                END IF;
7673                IF l_bulk_count > 0 THEN
7674                   l_org_change := TRUE;
7675                   l_line_idx := p_bulk_ship_line.line_id.PRIOR(l_line_idx);
7676                END IF;
7677             END IF;
7678          END IF; --}
7679          IF NOT l_org_change THEN --{
7680             l_bulk_count := l_bulk_count + 1;
7681             --bsadri from table x_freight_costs  select only the charges needed
7682             --for p_bulk_ship_line.line_id table
7683             -- put this charges in table l_ship_adj_line
7684 
7685             l_charge_idx := x_freight_costs.line_id.FIRST;
7686             WHILE l_charge_idx IS NOT NULL LOOP --{
7687                IF p_bulk_ship_line.line_id(l_line_idx) =
7688                                      x_freight_costs.line_id(l_charge_idx)
7689                THEN --{
7690                   l_ship_adj_line.cost_id.extend;
7691                   l_ship_adj_line.automatic_flag.extend;
7692                   l_ship_adj_line.list_line_type_code.extend;
7693                   l_ship_adj_line.charge_type_code.extend;
7694                   l_ship_adj_line.header_id.extend;
7695                   l_ship_adj_line.line_id.extend;
7696                   l_ship_adj_line.adjusted_amount.extend;
7697                   l_ship_adj_line.arithmetic_operator.extend;
7698                   l_ship_adj_line.operation.extend;
7699 
7700                   IF l_debug_on THEN
7701                      WSH_DEBUG_SV.log(l_module_name,'charge matched', p_bulk_ship_line.line_id(l_line_idx));
7702                   END IF;
7703 
7704                   l_ship_adj_line.cost_id(l_counter) :=
7705                              x_freight_costs.cost_id(l_charge_idx);
7706                   l_ship_adj_line.automatic_flag(l_counter) :=
7707                              x_freight_costs.automatic_flag(l_charge_idx);
7708                   l_ship_adj_line.list_line_type_code(l_counter) :=
7709                              x_freight_costs.list_line_type_code(l_charge_idx);
7710                   l_ship_adj_line.charge_type_code(l_counter) :=
7711                              x_freight_costs.charge_type_code(l_charge_idx);
7712                   l_ship_adj_line.header_id(l_counter) :=
7713                              x_freight_costs.header_id(l_charge_idx);
7714                   l_ship_adj_line.line_id(l_counter) :=
7715                              x_freight_costs.line_id(l_charge_idx);
7716                   l_ship_adj_line.adjusted_amount(l_counter) :=
7717                              x_freight_costs.adjusted_amount(l_charge_idx);
7718                   l_ship_adj_line.arithmetic_operator(l_counter) :=
7719                              x_freight_costs.arithmetic_operator(l_charge_idx);
7720                   l_ship_adj_line.operation(l_counter) :=
7721                              x_freight_costs.operation(l_charge_idx);
7722                   l_counter := l_counter + 1;
7723                   l_bulk_count := l_bulk_count + 1;
7724 
7725                END IF ;--}
7726 
7727                l_charge_idx := x_freight_costs.line_id.NEXT(l_charge_idx);
7728 
7729             END LOOP ; --}
7730          END IF; --}
7731 
7732          --bsadri Find out if the BULK limit is reached or the loop is
7733          -- exhouseted
7734 
7735          IF l_debug_on THEN
7736             WSH_DEBUG_SV.logmsg(l_module_name,'After while Loop');
7737          END IF;
7738          IF l_org_change THEN  --{
7739             l_end_index := l_line_idx;
7740          ELSE --}{
7741             IF l_line_idx < l_row_count THEN --{
7742                IF (l_bulk_batch_size IS NOT NULL)
7743                 AND (p_bulk_mode = 'Y' )THEN --{
7744                   IF l_bulk_count >= l_bulk_batch_size THEN --{
7745                      l_end_index := l_line_idx;
7746                   ELSE --}{
7747                      raise e_next_record;
7748                   END IF ; --}
7749                ELSE --}{
7750                   raise e_next_record;
7751                END IF; --}
7752             ELSE --}{
7753                l_end_index := l_line_idx;
7754             END IF; --}
7755          END IF; --}
7756 
7757          l_loop_count := l_loop_count + 1;
7758          l_counter := 1;
7759 
7760          IF l_debug_on THEN
7761             WSH_DEBUG_SV.logmsg(l_module_name,'Establishing save point l_interface_om');
7762          END IF;
7763          Savepoint l_interface_om;
7764 
7765           l_oe_interfaced_flag := 'P';
7766           l_container_flag := 'N';
7767           l_source_code := 'OE';
7768           l_released_status := 'D';
7769           -- bug 3761090
7770           FORALL i IN l_start_index..l_end_index
7771           UPDATE wsh_delivery_details dd
7772           SET    oe_interfaced_flag = l_oe_interfaced_flag ,
7773                  --Added as part of bug 7645262
7774                  last_update_date    = sysdate,
7775                  request_id          = fnd_global.conc_request_id,
7776                  last_updated_by     = fnd_global.user_id
7777           WHERE  source_line_id = p_bulk_ship_line.line_id(i)
7778           and container_flag = l_container_flag
7779           and source_code = l_source_code
7780           and released_status <> l_released_status
7781           and dd.delivery_detail_id in  (
7782             SELECT  /*+ no_unnest */ da.delivery_detail_id
7783             FROM wsh_delivery_assignments_v da ,
7784                   wsh_delivery_legs dg,
7785                   wsh_new_deliveries dl,
7786                   wsh_trip_stops st
7787             where   da.delivery_detail_id = dd.delivery_detail_id  AND
7788                   dl.delivery_id = da.delivery_id  AND
7789                   da.delivery_id  IS NOT NULL AND
7790                   st.stop_id = dg.pick_up_stop_id AND
7791                   st.batch_id = p_batch_id AND
7792                   st.stop_location_id = dl.initial_pickup_location_id AND
7793                   dg.delivery_id = dl.delivery_id
7794              );
7795 
7796 
7797          IF l_debug_on THEN
7798             WSH_DEBUG_SV.logmsg(l_module_name,'After Forall Update');
7799             WSH_DEBUG_SV.logmsg(l_module_name,'Printing P_ship_line_rec');
7800             print_ship_line(p_bulk_mode,p_bulk_ship_line,l_start_index,l_end_index);
7801             WSH_DEBUG_SV.log(l_module_name,'Calling OE_Ship_Confirmation_Pub.Ship_Confirm_New TIME:',SYSDATE);
7802          END IF;
7803          OE_Ship_Confirmation_Pub.Ship_Confirm_New(
7804            P_ship_line_rec         => p_bulk_ship_line,
7805            P_requested_line_rec    => p_bulk_req_line,
7806            P_line_adj_rec          => l_ship_adj_line,
7807            P_bulk_mode             => p_bulk_mode,
7808            P_start_index		=> l_start_index,
7809            P_end_index		=> l_end_index,
7810            x_msg_count             => x_msg_count,
7811            x_msg_data              => x_msg_data,
7812            x_return_status         => l_return_status);
7813 
7814          IF l_debug_on THEN
7815             WSH_DEBUG_SV.log(l_module_name,'After OE_Shipping_Integration_PUB.Ship_Confirm_New TIME:',SYSDATE);
7816             WSH_DEBUG_SV.log(l_module_name,'l_return_status ',l_return_status);
7817             WSH_DEBUG_SV.logmsg(l_module_name, 'NO. OF OE MESSAGES :'||X_MSG_COUNT  );
7818          END IF;
7819 
7820          FOR k IN 1 .. nvl(x_msg_count,0)
7821          LOOP
7822             --
7823             IF l_debug_on THEN
7824                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit OE_MSG_PUB.GET',WSH_DEBUG_SV.C_PROC_LEVEL);
7825             END IF;
7826             --
7827             x_msg_data := oe_msg_pub.get( p_msg_index => k,
7828             p_encoded => 'F'
7829             );
7830             --
7831             IF l_debug_on THEN
7832                 WSH_DEBUG_SV.logmsg(l_module_name, SUBSTR ( X_MSG_DATA , 1 , 255 ) );
7833             END IF;
7834             --
7835             WSH_UTIL_CORE.printmsg('Error msg: '||substr(x_msg_data,1,2000));
7836          END LOOP;
7837 
7838          IF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING
7839            AND p_bulk_mode='N' THEN
7840 
7841               -- for non-bulk mode handle warnings as error;
7842 
7843               l_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
7844 
7845          END IF;
7846 
7847 
7848          IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
7849             IF l_debug_on THEN
7850               WSH_DEBUG_SV.logmsg(l_module_name,'SUCCESS');
7851             END IF;
7852 
7853          --Bug 3482227
7854          IF (p_bulk_mode='N') THEN
7855             --Bug 3761090
7856             l_oe_interfaced_flag := 'Y';
7857             l_container_flag := 'N';
7858             l_source_code := 'OE';
7859             l_released_status := 'D';
7860 
7861             UPDATE wsh_delivery_details dd
7862             set   oe_interfaced_flag = l_oe_interfaced_flag ,
7863                   --Added as part of bug 7645262
7864                   last_update_date    = sysdate,
7865                   request_id          = fnd_global.conc_request_id,
7866                   last_updated_by     = fnd_global.user_id
7867             where  delivery_detail_id in  (
7868                    SELECT da.delivery_detail_id
7869                    FROM wsh_delivery_assignments_v da ,
7870                          wsh_delivery_legs dg,
7871                          wsh_new_deliveries dl,
7872                          wsh_trip_stops st,
7873                          oe_order_lines_all ol
7874                    where   da.delivery_detail_id = dd.delivery_detail_id  AND
7875                          dl.delivery_id = da.delivery_id  AND
7876                          da.delivery_id  IS NOT NULL AND
7877                          st.stop_id = dg.pick_up_stop_id AND
7878                          st.batch_id = p_batch_id AND
7879                          st.stop_location_id = dl.initial_pickup_location_id AND
7880                          dg.delivery_id = dl.delivery_id  AND
7881                          ol.line_id = dd.source_line_id AND
7882                          ol.shipped_quantity > 0
7883                     )
7884             and dd.source_header_id = l_header_id
7885             and container_flag = l_container_flag
7886             and source_code = l_source_code
7887             and released_status <> l_released_status;
7888           ELSE
7889             --Bug 3761090
7890             l_oe_interfaced_flag := 'Y';
7891             l_container_flag := 'N';
7892             l_source_code := 'OE';
7893             l_released_status := 'D';
7894 
7895             FORALL i IN l_start_index..l_end_index
7896             UPDATE wsh_delivery_details dd
7897             SET    oe_interfaced_flag = l_oe_interfaced_flag ,
7898                    --Added as part of bug 7645262
7899                    last_update_date    = sysdate,
7900                    request_id          = fnd_global.conc_request_id,
7901                    last_updated_by     = fnd_global.user_id
7902 
7903             WHERE  source_line_id = p_bulk_ship_line.line_id(i)
7904             and container_flag = l_container_flag
7905             and source_code = l_source_code
7906             and released_status <> l_released_status
7907             and dd.delivery_detail_id in  (
7908               SELECT  /*+ no_unnest */ da.delivery_detail_id
7909               FROM wsh_delivery_assignments_v da ,
7910                     wsh_delivery_legs dg,
7911                     wsh_new_deliveries dl,
7912                     wsh_trip_stops st
7913               where   da.delivery_detail_id = dd.delivery_detail_id  AND
7914                     dl.delivery_id = da.delivery_id  AND
7915                     da.delivery_id  IS NOT NULL AND
7916                     st.stop_id = dg.pick_up_stop_id AND
7917                     st.batch_id = p_batch_id AND
7918                     st.stop_location_id = dl.initial_pickup_location_id AND
7919                     dg.delivery_id = dl.delivery_id
7920                );
7921 
7922            END IF;
7923 
7924             l_count := SQL%ROWCOUNT;
7925             IF l_debug_on THEN
7926              WSH_DEBUG_SV.log(l_module_name,'No. Success Rec. Update to Y', l_count);
7927             END IF;
7928 
7929             --hadcp
7930             IF (l_dcp_profile IN (1,2)  ) THEN
7931                WSH_DCP_PVT.Check_ITS(
7932            		P_bulk_mode     => p_bulk_mode,
7933            		P_start_index	=> l_start_index,
7934            		P_end_index	=> l_end_index,
7935                         P_its_rec 	=> p_bulk_ship_line);
7936             END IF;
7937             IF l_debug_on THEN
7938              WSH_DEBUG_SV.logmsg(l_module_name,'No DCP Error');
7939             END IF;
7940 
7941             IF (l_dcp_profile IN (1,2) ) THEN
7942                WSH_DCP_PVT.G_INIT_MSG_COUNT := fnd_msg_pub.count_msg;
7943             END IF;
7944             IF l_debug_on THEN
7945                WSH_DEBUG_SV.log(l_module_name,'Inside Loop WSH_DCP_PVT.G_INIT_MSG_COUNT',WSH_DCP_PVT.G_INIT_MSG_COUNT);
7946             END IF;
7947             --hadcp
7948 
7949             commit;
7950          ELSIF (l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING) THEN
7951             IF l_debug_on THEN
7952               WSH_DEBUG_SV.logmsg(l_module_name,'WARNING');
7953             END IF;
7954             l_warn_count := l_warn_count + 1;
7955             --Bug 3761090
7956             l_container_flag := 'N';
7957             l_source_code := 'OE';
7958             l_released_status := 'D';
7959             FORALL i IN l_start_index..l_end_index
7960              UPDATE wsh_delivery_details dd
7961              SET oe_interfaced_flag = Decode(p_bulk_ship_line.error_flag(i),'Y','N','Y') ,
7962                  --Added as part of bug 7645262
7963                  last_update_date    = sysdate,
7964                  request_id          = fnd_global.conc_request_id,
7965                  last_updated_by     = fnd_global.user_id
7966              WHERE  source_line_id = p_bulk_ship_line.line_id(i)
7967              and container_flag = l_container_flag
7968              and source_code = l_source_code
7969              and released_status <> l_released_status
7970              and dd.delivery_detail_id in  (
7971                SELECT /*+ no_unnest */ da.delivery_detail_id
7972                FROM wsh_delivery_assignments_v da ,
7973                      wsh_delivery_legs dg,
7974                      wsh_new_deliveries dl,
7975                      wsh_trip_stops st
7976                where   da.delivery_detail_id = dd.delivery_detail_id  AND
7977                      dl.delivery_id = da.delivery_id  AND
7978                      da.delivery_id  IS NOT NULL AND
7979                      st.stop_id = dg.pick_up_stop_id AND
7980                      st.batch_id = p_batch_id AND
7981                      st.stop_location_id = dl.initial_pickup_location_id AND
7982                      dg.delivery_id = dl.delivery_id
7983                 );
7984 
7985 
7986              l_count := SQL%ROWCOUNT;
7987              IF l_debug_on THEN
7988               WSH_DEBUG_SV.log(l_module_name,'No. Warning Rec. Update',l_count);
7989              END IF;
7990 
7991             --hadcp
7992             IF (l_dcp_profile IN (1,2)  ) THEN
7993                WSH_DCP_PVT.Check_ITS(
7994            		P_bulk_mode     => p_bulk_mode,
7995            		P_start_index	=> l_start_index,
7996            		P_end_index	=> l_end_index,
7997                         P_its_rec 	=> p_bulk_ship_line);
7998             END IF;
7999             IF l_debug_on THEN
8000              WSH_DEBUG_SV.logmsg(l_module_name,'No DCP Error');
8001             END IF;
8002 
8003             IF (l_dcp_profile IN (1,2) ) THEN
8004                WSH_DCP_PVT.G_INIT_MSG_COUNT := fnd_msg_pub.count_msg;
8005             END IF;
8006             IF l_debug_on THEN
8007                WSH_DEBUG_SV.log(l_module_name,'Inside Loop WSH_DCP_PVT.G_INIT_MSG_COUNT',WSH_DCP_PVT.G_INIT_MSG_COUNT);
8008             END IF;
8009             --hadcp
8010 
8011             commit;
8012          ELSE
8013             IF l_debug_on THEN
8014               WSH_DEBUG_SV.logmsg(l_module_name,'ERROR');
8015             END IF;
8016              l_error_count := l_error_count + 1;
8017 
8018             --hadcp
8019              --Rollback to savepoint l_interface_om;
8020 
8021              IF (p_bulk_mode='Y') THEN
8022                IF l_debug_on THEN
8023                  WSH_DEBUG_SV.logmsg(l_module_name,'Rollback to savepoint l_interface_om');
8024                END IF;
8025                ROLLBACK TO l_interface_om;
8026              ELSE
8027                IF l_debug_on THEN
8028                  WSH_DEBUG_SV.logmsg(l_module_name,'Rollback to savepoint its_process_order_non_bulk');
8029                END IF;
8030                ROLLBACK TO its_process_order_non_bulk;
8031              END IF;
8032 
8033             IF (l_dcp_profile IN (1,2)  ) THEN
8034                WSH_DCP_PVT.Check_ITS(
8035            		P_bulk_mode       => p_bulk_mode,
8036            		P_start_index	  => l_start_index,
8037            		P_end_index	  => l_end_index,
8038                         P_its_rec 	  => p_bulk_ship_line,
8039                         p_raise_exception => 'N');
8040 
8041             END IF;
8042             IF l_debug_on THEN
8043              WSH_DEBUG_SV.logmsg(l_module_name,'No DCP Error');
8044             END IF;
8045 
8046             IF (l_dcp_profile IN (1,2) ) THEN
8047                WSH_DCP_PVT.G_INIT_MSG_COUNT := fnd_msg_pub.count_msg;
8048             END IF;
8049             IF l_debug_on THEN
8050                WSH_DEBUG_SV.log(l_module_name,'Inside Loop WSH_DCP_PVT.G_INIT_MSG_COUNT',WSH_DCP_PVT.G_INIT_MSG_COUNT);
8051             END IF;
8052             --hadcp
8053          END IF;
8054          l_start_index := l_end_index + 1;
8055 
8056          IF l_debug_on THEN
8057                      WSH_DEBUG_SV.log(l_module_name,'before deleting tables', l_start_index);
8058          END IF;
8059          l_bulk_count := 0;
8060          l_ship_adj_line.cost_id.DELETE;
8061          l_ship_adj_line.automatic_flag.DELETE;
8062          l_ship_adj_line.list_line_type_code.DELETE;
8063          l_ship_adj_line.charge_type_code.DELETE;
8064          l_ship_adj_line.header_id.DELETE;
8065          l_ship_adj_line.line_id.DELETE;
8066          l_ship_adj_line.adjusted_amount.DELETE;
8067          l_ship_adj_line.arithmetic_operator.DELETE;
8068          l_ship_adj_line.operation.DELETE;
8069 
8070 
8071       EXCEPTION
8072          WHEN e_next_record THEN
8073             IF l_debug_on THEN
8074                WSH_DEBUG_SV.logmsg(l_module_name,'Exception e_next_record');
8075             END IF;
8076 
8077             NULL;
8078       END ; --}
8079 
8080       IF l_debug_on THEN
8081          WSH_DEBUG_SV.log(l_module_name,'current index',l_line_idx);
8082       END IF;
8083 
8084       l_line_idx := p_bulk_ship_line.line_id.NEXT(l_line_idx);
8085 
8086       IF l_debug_on THEN
8087          WSH_DEBUG_SV.log(l_module_name,'next index',l_line_idx);
8088       END IF;
8089 
8090       IF l_org_change THEN --{
8091 --R12:MOAC replace call
8092          MO_GLOBAL.set_policy_context('S', l_prev_org_id);
8093          IF l_debug_on THEN
8094             WSH_DEBUG_SV.log(l_module_name,'setting the org', l_prev_org_id);
8095             WSH_DEBUG_SV.log(l_module_name,'l_line_idx', l_line_idx);
8096             WSH_DEBUG_SV.log(l_module_name,'l_bulk_count', l_bulk_count);
8097          END IF;
8098       END IF; --}
8099 
8100     --hadcp
8101     EXCEPTION
8102        WHEN WSH_DCP_PVT.data_inconsistency_exception THEN
8103          IF NOT l_debug_on OR  l_debug_on is null THEN
8104            l_debug_on := wsh_debug_sv.is_debug_enabled;
8105          END IF;
8106 
8107          IF l_debug_on THEN
8108             WSH_DEBUG_SV.logmsg(l_module_name,'DCP Exception');
8109          END IF;
8110 
8111          IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_WARNING, WSH_UTIL_CORE.G_RET_STS_SUCCESS)) THEN
8112             IF l_debug_on THEN
8113                WSH_DEBUG_SV.logmsg(l_module_name,'DCP Rollback');
8114             END IF;
8115 
8116                IF l_debug_on THEN
8117                  WSH_DEBUG_SV.logmsg(l_module_name,'Rollback to savepoint l_interface_om');
8118                END IF;
8119                ROLLBACK TO l_interface_om;
8120 
8121          END IF;
8122 
8123          l_line_idx := l_start_index;
8124 
8125          IF l_debug_on THEN
8126             WSH_DEBUG_SV.log(l_module_name,'DCP before deleting tables', l_start_index);
8127          END IF;
8128          l_bulk_count := 0;
8129          l_ship_adj_line.cost_id.DELETE;
8130          l_ship_adj_line.automatic_flag.DELETE;
8131          l_ship_adj_line.list_line_type_code.DELETE;
8132          l_ship_adj_line.charge_type_code.DELETE;
8133          l_ship_adj_line.header_id.DELETE;
8134          l_ship_adj_line.line_id.DELETE;
8135          l_ship_adj_line.adjusted_amount.DELETE;
8136          l_ship_adj_line.arithmetic_operator.DELETE;
8137          l_ship_adj_line.operation.DELETE;
8138 
8139          l_loop_count := l_loop_count - 1;
8140     END; --} DCP Block
8141     --hadcp
8142    END LOOP; --}
8143 
8144 
8145    IF l_debug_on THEN
8146        WSH_DEBUG_SV.log(l_module_name,'l_loop_count',l_loop_count);
8147        WSH_DEBUG_SV.log(l_module_name,'l_error_count',l_error_count);
8148        WSH_DEBUG_SV.log(l_module_name,'l_warn_count',l_warn_count);
8149    END IF;
8150 
8151    IF (l_error_count = l_loop_count ) THEN
8152       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
8153       IF l_debug_on THEN
8154          WSH_DEBUG_SV.logmsg(l_module_name,'Process Order Error', WSH_DEBUG_SV.C_EXCEP_LEVEL);
8155       END IF;
8156 
8157       --hadcp
8158       IF (p_bulk_mode='N') THEN
8159          IF l_debug_on THEN
8160             WSH_DEBUG_SV.logmsg(l_module_name,'Rollback to savepoint its_process_order_non_bulk');
8161          END IF;
8162          ROLLBACK TO its_process_order_non_bulk;
8163       END IF;
8164       --hadcp
8165 
8166    ELSIF (l_warn_count > 0 OR (l_error_count > 0 and l_error_count < l_loop_count) ) THEN
8167       x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
8168       IF l_debug_on THEN
8169          WSH_DEBUG_SV.logmsg(l_module_name,'Process Order Warning'||WSH_DEBUG_SV.C_EXCEP_LEVEL);
8170       END IF;
8171    END IF;
8172 
8173    IF l_debug_on THEN
8174       WSH_DEBUG_SV.pop(l_module_name);
8175    END IF;
8176 
8177 EXCEPTION
8178    WHEN process_freight_costs_failed THEN
8179       WSH_UTIL_CORE.PrintMsg('process_freight_costs_failed');
8180       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
8181 
8182       IF l_debug_on THEN
8183           WSH_DEBUG_SV.logmsg(l_module_name,'PROCESS_FREIGHT_COSTS_FAILED exception has occured.',
8184                                                                          WSH_DEBUG_SV.C_EXCEP_LEVEL);
8185           WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:PROCESS_FREIGHT_COSTS_FAILED');
8186       END IF;
8187 
8188       --Rollback to savepoint l_interface_om;
8189 
8190       --hadcp
8191       IF (p_bulk_mode='N') THEN
8192          IF l_debug_on THEN
8193             WSH_DEBUG_SV.logmsg(l_module_name,'Rollback to savepoint its_process_order_non_bulk');
8194          END IF;
8195          ROLLBACK TO its_process_order_non_bulk;
8196       END IF;
8197       --hadcp
8198 
8199 
8200    WHEN others THEN
8201       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
8202       wsh_util_core.printMsg('API Process_Stop_To_OM failed with an unexpected error');
8203       WSH_UTIL_CORE.PrintMsg('The unexpected error is ' || sqlerrm);
8204 
8205       IF l_debug_on THEN
8206          WSH_DEBUG_SV.logmsg(l_module_name, 'UNEXPECTED ERROR IN Process_Stop_To_OM' );
8207          WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
8208          WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
8209       END IF;
8210 
8211       --hadcp
8212       IF (p_bulk_mode='Y') THEN
8213          IF l_debug_on THEN
8214             WSH_DEBUG_SV.logmsg(l_module_name,'Rollback to savepoint l_interface_om');
8215          END IF;
8216          Rollback to savepoint l_interface_om;
8217       ELSE
8218          IF l_debug_on THEN
8219             WSH_DEBUG_SV.logmsg(l_module_name,'Rollback to savepoint its_process_order_non_bulk');
8220          END IF;
8221          ROLLBACK TO its_process_order_non_bulk;
8222       END IF;
8223       --hadcp
8224 
8225 END Process_Stop_To_OM;
8226 
8227 
8228 --========================================================================
8229 -- PROCEDURE : extend_om_ship_line
8230 --                  This API extend the tables need to be passed to OM API.
8231 --
8232 -- PARAMETERS: p_ship_line             Record of the table
8233 --             x_return_status         The return status of the API.
8234 --
8235 -- COMMENT   :
8236 --
8237 --========================================================================
8238 
8239 PROCEDURE extend_om_ship_line (
8240 	p_ship_line		IN OUT NOCOPY OE_Ship_Confirmation_Pub.Ship_Line_Rec_Type,
8241 	x_return_status	OUT NOCOPY VARCHAR2) IS
8242 
8243 l_debug_on BOOLEAN;
8244 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'extend_om_ship_line';
8245 
8246 BEGIN
8247    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
8248    IF l_debug_on IS NULL THEN
8249        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
8250    END IF;
8251 
8252    IF l_debug_on THEN
8253        WSH_DEBUG_SV.push(l_module_name);
8254        WSH_DEBUG_SV.log(l_module_name,'p_ship_line.fulfilled_flag.count', p_ship_line.fulfilled_flag.count);
8255    END IF;
8256 
8257    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
8258 
8259 
8260  p_ship_line.fulfilled_flag.extend;
8261  p_ship_line.actual_shipment_date.extend;
8262  p_ship_line.shipping_quantity2.extend;
8263  p_ship_line.shipping_quantity.extend;
8264  p_ship_line.shipped_quantity.extend; -- muom
8265  p_ship_line.shipping_quantity_uom2.extend;
8266  p_ship_line.shipping_quantity_uom.extend;
8267  p_ship_line.line_id.extend;
8268  p_ship_line.header_id.extend;
8269  p_ship_line.top_model_line_id.extend;
8270  p_ship_line.ato_line_id.extend;
8271  p_ship_line.ship_set_id.extend;
8272  p_ship_line.arrival_set_id.extend;
8273  p_ship_line.inventory_item_id.extend;
8274  p_ship_line.ship_from_org_id.extend;
8275  p_ship_line.line_set_id.extend;
8276  p_ship_line.smc_flag.extend;
8277  p_ship_line.over_ship_reason_code.extend;
8278  p_ship_line.requested_quantity.extend;
8279  p_ship_line.requested_quantity2.extend;
8280  p_ship_line.pending_quantity.extend;
8281  p_ship_line.pending_quantity2.extend;
8282  p_ship_line.pending_requested_flag.extend;
8283  p_ship_line.order_quantity_uom.extend;
8284  p_ship_line.order_quantity_uom2.extend;
8285 
8286  p_ship_line.model_remnant_flag.extend;
8287  p_ship_line.ordered_quantity.extend;
8288  p_ship_line.ordered_quantity2.extend;
8289  p_ship_line.item_type_code.extend;
8290  p_ship_line.calculate_price_flag.extend;
8291 
8292 
8293    IF l_debug_on THEN
8294       WSH_DEBUG_SV.pop(l_module_name);
8295    END IF;
8296 
8297 EXCEPTION
8298     WHEN others THEN
8299       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
8300 
8301       IF l_debug_on THEN
8302           WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
8303          WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
8304       END IF;
8305 END extend_om_ship_line;
8306 
8307 
8308 
8309 --========================================================================
8310 -- PROCEDURE : Interface_Stop_To_OM
8311 --                  This API is called from oe_interface_trip_stop to interface
8312 --                  all the lines in the batch to the OM.
8313 --
8314 -- PARAMETERS: p_batch_id              ITS batch id.
8315 --             x_return_status         The return status of the API.
8316 --
8317 -- COMMENT   : If all the lines in the batch are bulk enabled then they will
8318 --             be bulk collected into a record of the tables and be passed to
8319 --             procedure process_stop_to_om.  If not all the lines are bulk
8320 --             enabled then loop through all the lines.  If a line is bulk
8321 --             enabled, store it to a record of table, if the line is not bulk
8322 --             enabled then store it in a different record of tables.  For
8323 --             bulk enabled lines call process_stop_to_om once, for non-bulk
8324 --             enabled lines call process_stop_to_om once per sale order.
8325 --
8326 --             For non-bulk enabled lines call Check_Tolerance to find out if
8327 --             the line is fulfilled in OM.  If tolerance is specified for the
8328 --             line, for a case of under shipment, call Get_Line_Expected_Qty
8329 --             to see if lines have planned quantity.  If the line has planned
8330 --             quantity then set the fulfilled flag as N. Then cancel the
8331 --             pending delivery details.
8332 --             If a shipment is beyond the tolerance limit then give warning to
8333 --             the user.
8334 --
8335 --========================================================================
8336 
8337 PROCEDURE Interface_Stop_To_OM(
8338           p_batch_id        IN  NUMBER,
8339           x_return_status   out NOCOPY  varchar2 )
8340 IS
8341 --wrudge
8342 -- OM bug 2022029: added ato_line_id, sum(dd.requested_quantity2)
8343 --           and requested_quantity2
8344 
8345 --Bug 2177678 ,removed the use of oe_order_lines_all
8346 --Now OM locks oe_order_lines_all table for the associated lines
8347 CURSOR lock_delivery_line(p_batch_id NUMBER,c_source_header_id NUMBER,c_source_line_id NUMBER) IS
8348 SELECT dd.source_line_id
8349 FROM   wsh_delivery_Details dd,
8350    wsh_delivery_assignments_v da ,
8351    wsh_delivery_legs dg,
8352    wsh_new_deliveries dl,
8353    wsh_trip_stops st
8354 WHERE st.stop_id = dg.pick_up_stop_id AND
8355    st.batch_id = p_batch_id AND
8356    st.stop_location_id = dl.initial_pickup_location_id AND
8357    dg.delivery_id = dl.delivery_id  AND
8358    dl.delivery_id = da.delivery_id  AND
8359    da.delivery_id IS NOT NULL AND
8360    da.delivery_detail_id = dd.delivery_detail_id
8361    and nvl ( dd.oe_interfaced_flag , 'N' )  <> 'Y'
8362    and dd.source_code = 'OE'
8363    and dd.source_header_id = c_source_header_id
8364    and dd.source_line_id = c_source_line_id
8365    and dd.released_status <> 'D'  /* H integration: wrudge */
8366 for update nowait;
8367 
8368 CURSOR lock_dds_line_set(c_source_header_id NUMBER,
8369                          c_source_line_set_id NUMBER,
8370                          c_batch_id NUMBER) IS
8371 SELECT wdd.delivery_detail_id
8372 FROM   wsh_delivery_details wdd
8373 WHERE  wdd.source_code = 'OE'
8374 AND    wdd.source_header_id = c_source_header_id
8375 AND    wdd.source_line_set_id = c_source_line_set_id
8376 AND    wdd.released_status <> 'D'
8377 AND EXISTS (
8378             SELECT 'X'
8379             FROM wsh_trip_stops wts,
8380             wsh_delivery_legs wdl,
8381             wsh_delivery_assignments_v wda
8382             WHERE wdd.delivery_detail_id = wda.delivery_detail_id
8383             AND wts.batch_id = c_batch_id
8384             AND wts.stop_id = wdl.pick_up_stop_id
8385             AND wdl.delivery_id = wda.delivery_id
8386            )
8387 FOR UPDATE NOWAIT;
8388 --Above cursor query modified for perf bug fix 9803324
8389 
8390 CURSOR lock_dds_line(c_source_header_id NUMBER, c_source_line_id NUMBER,
8391                      c_batch_id NUMBER) IS
8392 SELECT wdd.delivery_detail_id
8393 FROM   wsh_delivery_details wdd
8394 WHERE  wdd.source_code = 'OE'
8395 AND    wdd.source_header_id = c_source_header_id
8396 AND    wdd.source_line_id = c_source_line_id
8397 AND    wdd.released_status <> 'D'
8398 AND EXISTS (
8399             SELECT 'X'
8400             FROM wsh_trip_stops wts,
8401             wsh_delivery_legs wdl,
8402             wsh_delivery_assignments_v wda
8403             WHERE wdd.delivery_detail_id = wda.delivery_detail_id
8404             AND wts.batch_id = c_batch_id
8405             AND wts.stop_id = wdl.pick_up_stop_id
8406             AND wdl.delivery_id = wda.delivery_id
8407            )
8408 FOR UPDATE NOWAIT;
8409 --Above cursor query modified for perf bug fix 9803324
8410 
8411 
8412 CURSOR c_remain_detail_id(c_source_line_id NUMBER) IS
8413 SELECT delivery_detail_id
8414 FROM wsh_delivery_details dd
8415 WHERE source_line_id = c_source_line_id AND
8416      source_code = 'OE' AND
8417      released_status IN ('R', 'B', 'N', 'S', 'X') AND
8418      NVL(container_flag, 'N') = 'N';
8419 
8420 CURSOR c_remain_lines(c_source_line_set_id NUMBER,
8421                       c_source_header_id NUMBER,
8422                       p_batch_id NUMBER) IS
8423 SELECT DISTINCT wdd.source_line_id
8424 from   wsh_delivery_details wdd
8425 where  wdd.source_header_id   = c_source_header_id
8426 and    wdd.source_code        = 'OE'
8427 and    wdd.source_line_set_id = c_source_line_set_id
8428 and    not exists (
8429          select 'x'
8430          from   wsh_delivery_assignments_v wda,
8431                 wsh_new_deliveries wnd,
8432                 wsh_delivery_legs wdl,
8433                 wsh_trip_stops wts
8434          where  wdd.delivery_detail_id = wda.delivery_detail_id
8435          and    wda.delivery_id        = wnd.delivery_id
8436          and    wda.delivery_id is not null
8437          and    wnd.delivery_id        = wdl.delivery_id
8438          and    wdl.pick_up_stop_id    = wts.stop_id
8439          and    wdd.ship_from_location_id = wts.stop_location_id
8440          and    wts.batch_id               = p_batch_id);
8441 
8442 CURSOR c_picked_dd(c_source_line_id NUMBER,
8443                    c_source_header_id NUMBER) IS
8444 select 'x'
8445 from   wsh_delivery_details wdd,
8446        wsh_delivery_assignments_v wda,
8447        wsh_new_deliveries wnd
8448 where  wdd.source_line_id     = c_source_line_id
8449 and    wdd.source_code        = 'OE'
8450 and    wdd.source_header_id   = c_source_header_id
8451 and    wdd.delivery_detail_id = wda.delivery_detail_id
8452 and    wnd.delivery_id(+)     = wda.delivery_id
8453 and    ( (wdd.released_status = 'Y') OR
8454          (wdd.released_status = 'C' AND wdd.oe_interfaced_flag <> 'Y') OR
8455          (wnd.status_code IN ('SR', 'SC'))
8456        );
8457 
8458 l_prev_line_set_id NUMBER:= -99;
8459 l_dummy            VARCHAR2(1);
8460 l_line_id          NUMBER;
8461 l_tot_ord_qty      NUMBER;
8462 l_tot_dd_req_qty   NUMBER;
8463 l_tot_dd_shp_qty   NUMBER;
8464 WSH_CANCEL_DETAIL_FAILED EXCEPTION;
8465 
8466 --After Merge
8467 
8468 -- HW OPMCONV. Removed local variables
8469 --bug 7131800
8470 l_process_flag      VARCHAR2(1) :=FND_API.G_FALSE;
8471 l_tot_shp_qty           number;
8472 l_tot_shp_qty2         number;  -- OPM KYH 12/SEP/00
8473 -- muom
8474 l_tot_om_shp_qty       number;
8475 x_msg_data             varchar2(2000);
8476 x_msg_count           number;
8477 l_counter               number;
8478 
8479 l_return_status          varchar2(30);
8480 l_new_tolerance_below      number;
8481 l_old_tolerance_below      number;
8482 l_over_reason           VARCHAR2(1);
8483 l_ship_beyond_flag     VARCHAR2(1);
8484 l_fulfilled_flag       VARCHAR2(1);
8485 l_summary               VARCHAR2(2000) :=NULL;
8486 l_details               VARCHAR2(4000) :=NULL;
8487 l_get_msg_count          number;
8488 l_error_Code            number;
8489 l_error_text            varchar2(2000);
8490 l_remain_details_id     WSH_UTIL_CORE.Id_Tab_Type;
8491 l_remain_detail_index      NUMBER;
8492 
8493 
8494 l_delete_detail_id NUMBER;
8495 
8496 --bug 2080335
8497 t_source_line_id     NUMBER;
8498 line_locked     EXCEPTION;
8499 PRAGMA EXCEPTION_INIT(line_locked, -54);
8500 
8501 
8502 -- OM bug 2022029
8503 l_line_qtys        OE_SHIP_CONFIRMATION_PUB.Req_Quantity_Tbl_Type;
8504 
8505 -- anxsharm for Load Tender
8506  l_trip_id_tab wsh_util_core.id_tab_type;
8507 
8508 -- sql repository performance bug 4891985 (>1M sharable memory)
8509 -- 1) changed wsh_delivery_assignments_v to wsh_delivery_assignments
8510 -- 2) restructured the query
8511 -- 3) added the missing condition wdd2.released_status <> 'D' not to handled the cancelled delivery lines
8512 
8513 --HVOP heali
8514 /*
8515 CURSOR check_bulk_csr (cp_batch_id NUMBER) IS
8516 select 'X'
8517 from wsh_delivery_details
8518 where source_line_id in (select source_line_id
8519                          from wsh_delivery_details wdd,
8520                               wsh_delivery_assignments_v wda,
8521                               wsh_delivery_legs wdl,
8522                               wsh_trip_stops wts
8523                          where wts.batch_id = cp_batch_id
8524                          and   wdl.pick_up_stop_id = wts.stop_id
8525                          and   wda.delivery_id = wdl.delivery_id
8526                          and   wdd.delivery_detail_id = wda.delivery_detail_id
8527                          and   wdd.container_flag = 'N'
8528                          and   wdd.source_code = 'OE'
8529                         )
8530   and   (delivery_detail_id not in
8531             (select wdd.delivery_detail_id
8532              from wsh_delivery_details wdd,
8533                   wsh_delivery_assignments_v wda,
8534                   wsh_delivery_legs wdl,
8535                   wsh_trip_stops wts
8536              where wts.batch_id = cp_batch_id
8537              and   wdl.pick_up_stop_id = wts.stop_id
8538              and   wda.delivery_id = wdl.delivery_id
8539              and   wdd.delivery_detail_id = wda.delivery_detail_id
8540              and   wdd.container_flag = 'N'
8541              and   wdd.source_code = 'OE'
8542             )
8543          or    top_model_line_id is not null
8544          or    ship_set_id is not null
8545          or    nvl(ship_model_complete_flag,'N')  = 'Y'
8546          or    requested_quantity <> nvl(shipped_quantity,-99)
8547          or    source_line_set_id IS NOT NULL
8548         )
8549   and   source_code = 'OE'
8550 and   container_flag = 'N';
8551 */
8552 
8553 CURSOR check_bulk_csr (cp_batch_id NUMBER) IS
8554 select 'X'
8555   from wsh_trip_stops wts,
8556        wsh_delivery_legs wdl,
8557        wsh_delivery_assignments wda ,
8558        wsh_delivery_details wdd
8559  where wts.batch_id = cp_batch_id
8560    and wdl.pick_up_stop_id = wts.stop_id
8561    and wda.delivery_id = wdl.delivery_id
8562    and wdd.delivery_detail_id = wda.delivery_detail_id
8563    and wdd.container_flag = 'N'
8564    and wdd.source_code = 'OE'
8565    and (EXISTS (select 'any non-cancelled line outside batch'
8566                   from wsh_delivery_details wdd2
8567                  where wdd2.source_line_id = wdd.source_line_id
8568                    and wdd2.source_code = 'OE'
8569                    and wdd2.container_flag = 'N'
8570                    and wdd2.released_status <> 'D'
8571                    and wdd2.delivery_detail_id NOT IN
8572                        (select wda3.delivery_detail_id
8573                           from wsh_delivery_assignments wda3 ,
8574                                wsh_delivery_legs wdl3,
8575                                wsh_trip_stops wts3,
8576                                wsh_delivery_details wdd3
8577                          where wts3.batch_id = cp_batch_id
8578                            and wdl3.pick_up_stop_id = wts3.stop_id
8579                            and wda3.delivery_id = wdl3.delivery_id
8580                            and wdd3.delivery_detail_id = wda3.delivery_detail_id
8581                            and wdd3.source_line_id = wdd.source_line_id
8582                            and wdd3.source_code = 'OE'
8583                            and wdd3.container_flag = 'N'))
8584         or    wdd.top_model_line_id is not null
8585         or    wdd.ship_set_id is not null
8586         or    nvl(wdd.ship_model_complete_flag,'N')  = 'Y'
8587         or    wdd.requested_quantity <> nvl(wdd.shipped_quantity,-99)
8588               -- bug 5688051
8589         or    nvl(requested_quantity2, -99) <> nvl(shipped_quantity2, -99)
8590         or    wdd.source_line_set_id IS NOT NULL )
8591    and rownum = 1;
8592 
8593 
8594 CURSOR c_oe_interface_bulk(cp_batch_id NUMBER) IS
8595  SELECT	dd.source_header_id		        header_id,
8596 	dd.source_line_id			line_id,
8597         dd.top_model_line_id 			top_model_line_id,
8598         dd.ship_set_id				ship_set_id,
8599         dd.arrival_set_id			arrival_set_id,
8600 	NVL(dl.initial_pickup_date,sysdate) 	actual_shipment_date,
8601 	dd.requested_quantity_uom		shipping_quantity_uom,
8602 	dd.requested_quantity_uom2 		shipping_quantity_uom2,
8603         ol.flow_status_code			flow_status_code,
8604         ol.ordered_quantity			ordered_quantity,
8605         ol.ordered_quantity2			ordered_quantity2,
8606         ol.org_id                               org_id,
8607 	sum( nvl(dd.shipped_quantity,0) )	shipping_quantity,
8608 	sum( nvl(dd.shipped_quantity2, 0 )) 	shipping_quantity2,
8609         -- muom
8610         -- Derive shipped_quantity (to pass to OM) only when Fufillment Base is Secondary
8611         sum( decode(dd.requested_quantity_uom2, null, null,
8612                       decode(WSH_UTIL_CORE.Get_Line_Fulfillment_Base(dd.source_code, dd.source_line_id),
8613                                         'S', WSH_WV_UTILS.CONVERT_UOM(from_uom => dd.requested_quantity_uom2,
8614                                                                       to_uom   => ol.order_quantity_uom,
8615                                                                       quantity => nvl(dd.shipped_quantity2,0),
8616                                                                       item_id  => dd.inventory_item_id)))) shipped_quantity
8617 FROM   wsh_delivery_Details dd,
8618    wsh_delivery_assignments_v da ,
8619    wsh_delivery_legs dg,
8620    wsh_new_deliveries dl,
8621    wsh_trip_stops st,
8622    oe_order_lines_all ol
8623 WHERE st.stop_id = dg.pick_up_stop_id AND
8624    st.batch_id = cp_batch_id AND
8625    st.stop_location_id = dl.initial_pickup_location_id AND
8626    dg.delivery_id = dl.delivery_id  AND
8627    dl.delivery_id = da.delivery_id  AND
8628    da.delivery_detail_id = dd.delivery_detail_id
8629    and nvl ( dd.oe_interfaced_flag , 'N' )  <> 'Y'
8630    and dd.source_code = 'OE'
8631    and dd.released_status <> 'D'
8632    and ol.line_id = dd.source_line_id
8633    and dd.client_id IS NULL -- LSP PROJECT : Should not perform OM interface for LSP orders
8634 GROUP BY
8635    dd.source_header_id ,
8636    dd.source_line_id,
8637    dd.top_model_line_id,
8638    dd.ship_set_id,
8639    dd.arrival_set_id,
8640    dl.initial_pickup_date,
8641    dd.requested_quantity_uom,
8642    dd.requested_quantity_uom2,
8643    ol.flow_status_code,
8644    ol.ordered_quantity,
8645    ol.ordered_quantity2,
8646    ol.order_quantity_uom, -- muom
8647    ol.org_id
8648 ORDER BY --Bugfix 14127623
8649    dd.source_header_id,
8650    dd.source_line_id;
8651 
8652 CURSOR c_oe_interface(cp_batch_id NUMBER) IS
8653    SELECT dd.source_header_id ,
8654    dd.source_header_number ,
8655    dd.source_line_set_id,
8656    dd.source_line_id ,
8657    WSH_WV_UTILS.CONVERT_UOM(ol.order_quantity_uom,
8658                      dd.requested_quantity_uom,
8659                      ol.ordered_quantity,
8660                      dd.inventory_item_id) order_line_quantity,
8661    -- muom
8662    ol.ordered_quantity2 order_line_quantity2,
8663    dd.requested_quantity_uom  ,
8664    dd.requested_quantity_uom2 ,
8665    ol.ordered_quantity,
8666    ol.order_quantity_uom,
8667    ol.ordered_quantity2,
8668    ol.ordered_quantity_uom2,
8669    ol.model_remnant_flag,
8670    ol.item_type_code,
8671    ol.calculate_price_flag,
8672    dd.ship_tolerance_below  ,
8673    dd.ship_tolerance_above,
8674    ol.org_id org_id ,
8675    dd.organization_id organization_id ,
8676    NVL(dd.oe_interfaced_flag, 'N') oe_interfaced_flag,
8677    dl.initial_pickup_date,
8678    dd.top_model_line_id ,
8679    dd.ato_line_id,
8680    dd.ship_set_id,
8681    dd.ship_model_complete_flag,
8682    dd.arrival_set_id,
8683    dd.inventory_item_id,
8684    ol.flow_status_code,
8685    sum( dd.requested_quantity )     total_requested_quantity,
8686    sum( dd.requested_quantity2 )   total_requested_quantity2,
8687    sum( nvl(dd.shipped_quantity, 0 )) total_shipped_quantity ,
8688    sum( nvl(dd.shipped_quantity2, 0 )) total_shipped_quantity2,
8689    -- muom
8690    -- Derive shipped_quantity (to pass to OM) only when Fufillment Base is Secondary
8691    sum( decode(dd.requested_quantity_uom2, null, null,
8692          decode(WSH_UTIL_CORE.Get_Line_Fulfillment_Base(dd.source_code, dd.source_line_id),
8693           'S',WSH_WV_UTILS.CONVERT_UOM(
8694                              from_uom   => ol.ordered_quantity_uom2,
8695                              to_uom     => ol.order_quantity_uom,
8696                              quantity   => nvl(dd.shipped_quantity2, 0 ),
8697                              item_id    => dd.inventory_item_id)))) total_om_shipped_quantity
8698 FROM   wsh_delivery_Details dd,
8699    wsh_delivery_assignments_v da ,
8700    wsh_delivery_legs dg,
8701    wsh_new_deliveries dl,
8702    wsh_trip_stops st,
8703    oe_order_lines_all ol
8704 WHERE st.stop_id = dg.pick_up_stop_id AND
8705    st.batch_id = cp_batch_id AND
8706    st.stop_location_id = dl.initial_pickup_location_id AND
8707    dg.delivery_id = dl.delivery_id  AND
8708    dl.delivery_id = da.delivery_id  AND
8709    da.delivery_id IS NOT NULL AND
8710    da.delivery_detail_id = dd.delivery_detail_id
8711    and nvl ( dd.oe_interfaced_flag , 'N' )  <> 'Y'
8712    and dd.source_code = 'OE'
8713    and ol.line_id = dd.source_line_id
8714    and dd.released_status <> 'D'
8715    and dd.client_id IS NULL  -- LSP PROJECT : Should not perform OM interface for LSP orders
8716 group by ol.org_id ,
8717    dd.source_header_id ,
8718    dd.source_header_number ,
8719    dd.source_line_set_id,
8720    dd.source_line_id,
8721    dd.top_model_line_id,
8722    dd.ship_set_id,
8723    dd.ato_line_id,
8724    dd.ship_set_id,
8725    dd.arrival_set_id,
8726    dd.inventory_item_id,
8727    dd.ship_model_complete_flag,
8728    WSH_WV_UTILS.CONVERT_UOM(ol.order_quantity_uom,
8729                      dd.requested_quantity_uom,
8730                      ol.ordered_quantity,
8731                      dd.inventory_item_id) ,
8732    dd.requested_quantity_uom,
8733    dd.requested_quantity_uom2,
8734    ol.ordered_quantity,
8735    ol.order_quantity_uom,
8736    ol.ordered_quantity2,
8737    ol.ordered_quantity_uom2,
8738    ol.model_remnant_flag,
8739    ol.item_type_code,
8740    ol.calculate_price_flag,
8741    dd.ship_tolerance_below ,
8742    dd.ship_tolerance_above ,
8743    dd.organization_id ,
8744    NVL(dd.oe_interfaced_flag, 'N') ,
8745    dl.initial_pickup_date,
8746    ol.flow_status_code
8747 ORDER BY  ol.org_id,
8748         dd.source_header_id,
8749         dd.source_header_number,
8750         --bug fix 3286811 : replaced total_shipped_quantity -total_requested_quantity in order by for 8.1.7.4 compatibility
8751         (sum( nvl(dd.shipped_quantity, 0 )) - sum( dd.requested_quantity )),
8752         dd.source_line_set_id,
8753         dd.source_line_id,
8754         dd.top_model_line_id,
8755         dd.ato_line_id,
8756         dd.ship_set_id,
8757         dd.arrival_set_id,
8758         dd.inventory_item_id,
8759         dd.ship_model_complete_flag,
8760         WSH_WV_UTILS.CONVERT_UOM(ol.order_quantity_uom,
8761                                  dd.requested_quantity_uom,
8762                                  ol.ordered_quantity,
8763                                  dd.inventory_item_id) ,
8764         dd.requested_quantity_uom,
8765         dd.requested_quantity_uom2,
8766         ol.ordered_quantity,
8767         ol.order_quantity_uom,
8768         ol.ordered_quantity2,
8769         ol.ordered_quantity_uom2,
8770         ol.model_remnant_flag,
8771         ol.item_type_code,
8772         ol.calculate_price_flag,
8773         dd.ship_tolerance_below,
8774         dd.ship_tolerance_above ,
8775         dd.organization_id,
8776         NVL(dd.oe_interfaced_flag, 'N') ,
8777         dl.initial_pickup_date ;
8778 
8779 l_bulk_ship_line        OE_Ship_Confirmation_Pub.Ship_Line_Rec_Type;
8780 l_bulk_req_line        	OE_Ship_Confirmation_Pub.Ship_Line_Rec_Type;
8781 l_non_bulk_ship_line    OE_Ship_Confirmation_Pub.Ship_Line_Rec_Type;
8782 l_non_bulk_req_line     OE_Ship_Confirmation_Pub.Ship_Line_Rec_Type;
8783 
8784 l_check_bulk			VARCHAR2(1);
8785 l_prev_source_header_number 	VARCHAR2(150);
8786 l_bulk_count			NUMBER:=0;
8787 l_non_bulk_count		NUMBER:=0;
8788 l_non_bulk_ship_count		NUMBER:=0;
8789 l_non_bulk_req_count		NUMBER:=0;
8790 
8791 
8792 l_num_errors            	NUMBER :=0;
8793 l_num_warnings          	NUMBER :=0;
8794 
8795 l_num_om_errors                 NUMBER :=0;
8796 l_num_om_warnings               NUMBER :=0;
8797 l_num_om_api_call               NUMBER :=0;
8798 
8799 l_org_id			number;
8800 l_prev_org_id			number;
8801 --HVOP heali
8802 l_freight_costs                 OE_Ship_Confirmation_Pub.Ship_Adj_Rec_Type;
8803 l_charges_are_calculated        BOOLEAN DEFAULT FALSE;
8804 l_setsmc_input_rec              OE_Shipping_Integration_PUB.Setsmc_Input_Rec_Type;
8805 
8806 oe_interface_rec c_oe_interface%ROWTYPE ;
8807 -- Bug 7131800
8808 l_cancel_unpicked_details       VARCHAR2(1);
8809 
8810 -- muom
8811 l_fulfill_base varchar2(1);
8812 
8813 l_debug_on BOOLEAN;
8814 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'INTERFACE_STOP_TO_OM';
8815 
8816 BEGIN
8817  l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
8818   --
8819  IF l_debug_on IS NULL THEN
8820        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
8821  END IF;
8822   --
8823  IF l_debug_on THEN
8824        WSH_DEBUG_SV.push(l_module_name);
8825        WSH_DEBUG_SV.log(l_module_name,'p_batch_id',p_batch_id);
8826  END IF;
8827 
8828  x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
8829 
8830 
8831 
8832  l_counter := 0;
8833 
8834 
8835  -- HVOP heali
8836  OPEN check_bulk_csr(p_batch_id);
8837  FETCH check_bulk_csr INTO l_check_bulk;
8838  CLOSE check_bulk_csr;
8839 
8840  IF l_debug_on THEN
8841     WSH_DEBUG_SV.log(l_module_name,'l_check_bulk',l_check_bulk);
8842  END IF;
8843 
8844 
8845  IF (nvl(l_check_bulk,'%%') <> 'X' ) THEN --{
8846      IF l_debug_on THEN
8847         WSH_DEBUG_SV.logmsg(l_module_name,'All lines are bulk enabled');
8848      END IF;
8849 
8850       OPEN c_oe_interface_bulk(p_batch_id);
8851       FETCH c_oe_interface_bulk BULK COLLECT
8852 	INTO l_bulk_ship_line.header_id,
8853 	     l_bulk_ship_line.line_id,
8854 	     l_bulk_ship_line.top_model_line_id,
8855 	     l_bulk_ship_line.ship_set_id,
8856              l_bulk_ship_line.arrival_set_id,
8857 	     l_bulk_ship_line.actual_shipment_date,
8858 	     l_bulk_ship_line.shipping_quantity_uom,
8859 	     l_bulk_ship_line.shipping_quantity_uom2,
8860 	     l_bulk_ship_line.flow_status_code,
8861              l_bulk_ship_line.ordered_quantity,
8862              l_bulk_ship_line.ordered_quantity2,
8863 	     l_bulk_ship_line.org_id,
8864 	     l_bulk_ship_line.shipping_quantity,
8865 	     l_bulk_ship_line.shipping_quantity2,
8866              -- muom
8867              l_bulk_ship_line.shipped_quantity;
8868 
8869 
8870       l_bulk_count := c_oe_interface_bulk%ROWCOUNT;
8871       CLOSE c_oe_interface_bulk;
8872       IF l_debug_on THEN
8873        WSH_DEBUG_SV.log(l_module_name,'Rows insert into l_bulk_ship_line',l_bulk_count);
8874       END IF;
8875 
8876  ELSE --} {
8877    IF l_debug_on THEN
8878       WSH_DEBUG_SV.logmsg(l_module_name,'All lines are NOT bulk enable');
8879    END IF;
8880 
8881    OPEN c_oe_interface(p_batch_id);
8882    LOOP
8883    BEGIN --{
8884      -- Need to split Bulk and Non-Bulk enable lines.
8885 
8886      FETCH c_oe_interface INTO oe_interface_rec;
8887      EXIT WHEN c_oe_interface%NOTFOUND;
8888 
8889   -- Commenting out the following code for the bug 5961591
8890   /*
8891      l_non_bulk_count:=l_non_bulk_count + 1;
8892 
8893      IF (l_non_bulk_count = 1) THEN
8894         l_prev_source_header_number:=oe_interface_rec.source_header_number;
8895      END IF;
8896   */
8897   -- End of comment for bug 5961591
8898      IF l_debug_on THEN
8899       WSH_DEBUG_SV.logmsg(l_module_name,  'INTERFACE SOURCE_LINE_ID= '||OE_INTERFACE_REC.SOURCE_LINE_ID);
8900      END IF;
8901 
8902 
8903      IF ((nvl(oe_interface_rec.ship_tolerance_above,0) > 0) OR    -- {
8904                (nvl(oe_interface_rec.ship_tolerance_below,0) > 0)) THEN
8905 
8906         IF (oe_interface_rec.source_line_set_id is not null) THEN --{
8907            IF l_debug_on THEN
8908                 WSH_DEBUG_SV.logmsg(l_module_name,  'Checking for Lock on dds in line set '||
8909                                                                        oe_interface_rec.source_line_set_id);
8910            END IF;
8911 
8912            OPEN lock_dds_line_set(oe_interface_rec.source_header_id,oe_interface_rec.source_line_set_id, p_batch_id);
8913            FETCH lock_dds_line_set INTO t_source_line_id;
8914            IF lock_dds_line_set%NOTFOUND THEN
8915               IF l_debug_on THEN
8916                  WSH_DEBUG_SV.logmsg(l_module_name,  'Some or all delivery details for Line Set '||
8917                                     oe_interface_rec.source_line_set_id||' are already locked by another process');
8918               END IF;
8919               CLOSE lock_dds_line_set;
8920            END IF;
8921            CLOSE lock_dds_line_set;
8922 
8923         ELSE --}{
8924            IF l_debug_on THEN
8925                 WSH_DEBUG_SV.logmsg(l_module_name,'Checking for Lock on dds in line '||
8926                                                                      oe_interface_rec.source_line_id);
8927            END IF;
8928 
8929            OPEN lock_dds_line(oe_interface_rec.source_header_id,oe_interface_rec.source_line_id, p_batch_id);
8930            FETCH lock_dds_line INTO t_source_line_id;
8931            if lock_dds_line%NOTFOUND then
8932               IF l_debug_on THEN
8933                   WSH_DEBUG_SV.logmsg(l_module_name,  'Some or all delivery details for Line '||
8934                                        oe_interface_rec.source_line_id||' are already lock by another process');
8935               END IF;
8936               CLOSE lock_dds_line;
8937            end if;
8938            CLOSE lock_dds_line;
8939         END IF; --}
8940 
8941      ELSE --}{
8942         -- bug2080335
8943         IF l_debug_on THEN
8944          WSH_DEBUG_SV.log(l_module_name, 'Checking for Lock on line '||oe_interface_rec.source_line_id);
8945         END IF;
8946         OPEN lock_delivery_line(p_batch_id,oe_interface_rec.source_header_id,oe_interface_rec.source_line_id);
8947         FETCH lock_delivery_line INTO t_source_line_id;
8948         IF lock_delivery_line%NOTFOUND then
8949          IF l_debug_on THEN
8950              WSH_DEBUG_SV.logmsg(l_module_name,  'LINE '||OE_INTERFACE_REC.SOURCE_LINE_ID||'
8951                                                                          IS ALREADY LOCK BY ANOTHER PROCESS'  );
8952          END IF;
8953          CLOSE lock_delivery_line;
8954         END IF;
8955         CLOSE lock_delivery_line;
8956      END IF; --}
8957 -- Moved the commented out code after IF condition for bug 5961591.
8958      -- Issue with existing code:
8959      -- ===========================
8960      -- If above IF condition fails to obtain the lock for the processing line
8961      -- then it goes to LINE_LOCKED Exception however variable l_non_bulk_count is
8962      -- incremented before the IF condition. Based on l_non_bulk_count variable
8963      -- value, SAVEPOINT its_process_order_non_bulk is set
8964      -- If savepoint ITS_PROCESS_ORDER_NON_BULK is NOT set then ITS fails with
8965      -- following error
8966      -- ORA-01086: savepoint 'ITS_PROCESS_ORDER_NON_BULK' never established
8967      -- Due to above error delivery detail is stuck with OE_INTERFACED_FLAG value 'P'
8968      -- and this delivery detail will still be assigned to CLOSED order line.
8969      -- Fix done for bug 5946787 :
8970      -- ===========================
8971      -- So,  variable l_non_bulk_count should be incremented only after acquiring lock on
8972      -- the line being processed during ITS.
8973      -- Start of fix for bug the 5961591
8974 
8975       l_non_bulk_count:=l_non_bulk_count + 1;
8976 
8977      IF (l_non_bulk_count = 1) THEN
8978         l_prev_source_header_number:=oe_interface_rec.source_header_number;
8979      END IF;
8980      --End of fix for the bug 5961591
8981 
8982      IF l_debug_on THEN
8983          WSH_DEBUG_SV.log(l_module_name,'t_source_line_id',t_source_line_id);
8984          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit INV_GMI_RSV_BRANCH.PROCESS_BRANCH',WSH_DEBUG_SV.C_PROC_LEVEL);
8985      END IF;
8986      -- bug 7131800
8987      IF NOT INV_GMI_RSV_BRANCH.Process_Branch(p_organization_id => oe_interface_rec.organization_id) THEN
8988        l_process_flag := FND_API.G_FALSE;
8989      ELSE
8990        l_process_flag := FND_API.G_TRUE;
8991      END IF;
8992      --
8993 -- HW OPMCONV. Removed checking for OPM orgs
8994 
8995      l_tot_shp_qty := oe_interface_rec.total_shipped_quantity ;
8996      l_tot_shp_qty2 := oe_interface_rec.total_shipped_quantity2 ;
8997      -- muom
8998      l_tot_om_shp_qty := oe_interface_rec.total_om_shipped_quantity;
8999 
9000      l_old_tolerance_below := oe_interface_rec.ship_tolerance_below;
9001      l_org_id := oe_interface_rec.org_id;
9002 
9003      IF l_debug_on THEN
9004         WSH_DEBUG_SV.log(l_module_name,'source_header_number',oe_interface_rec.source_header_number);
9005 	WSH_DEBUG_SV.log(l_module_name,'l_process_flag',l_process_flag);
9006         WSH_DEBUG_SV.log(l_module_name,'l_prev_source_header_number',l_prev_source_header_number);
9007         WSH_DEBUG_SV.log(l_module_name,'l_non_bulk_ship_line.line_id.count',l_non_bulk_ship_line.line_id.count);
9008      END IF;
9009      IF (oe_interface_rec.source_header_number <> nvl(l_prev_source_header_number,'#')         -- {
9010              AND (l_non_bulk_ship_line.line_id.count > 0 OR l_non_bulk_req_line.line_id.count > 0)
9011             ) THEN
9012 
9013             l_num_om_api_call := l_num_om_api_call + 1;
9014             Process_Stop_To_OM(
9015                 p_batch_id	     => p_batch_id,
9016                 p_bulk_ship_line     => l_non_bulk_ship_line,
9017                 p_bulk_req_line      => l_non_bulk_req_line,
9018                 P_bulk_mode	     => 'N',
9019                 p_org_id	     => l_prev_org_id,
9020                 x_freight_costs      => l_freight_costs,
9021                 x_charges_are_calculated => l_charges_are_calculated,
9022                 x_return_status      => l_return_status);
9023 
9024             IF l_debug_on THEN
9025                WSH_DEBUG_SV.log(l_module_name, 'NON BULK Process_Stop_To_OM l_return_status',l_return_status);
9026             END IF;
9027 
9028             IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
9029               IF l_debug_on THEN
9030                 WSH_DEBUG_SV.logmsg(l_module_name, 'Rolling back to the savepoint its_process_order_non_bulk as ITS for the order completed with an error');
9031               END IF;
9032               --ROLLBACK TO its_process_order_non_bulk;
9033 
9034             END IF;
9035 
9036             --Initialize l_non_bulk_ship_line and l_non_bulk_req_line
9037             l_non_bulk_ship_count:=0;
9038 
9039             l_non_bulk_ship_line.line_id.delete;
9040             l_non_bulk_ship_line.requested_quantity.delete;
9041             l_non_bulk_ship_line.requested_quantity2.delete;
9042             l_non_bulk_ship_line.shipping_quantity2.delete;
9043             l_non_bulk_ship_line.shipping_quantity.delete;
9044             l_non_bulk_ship_line.shipped_quantity.delete; -- muom
9045             l_non_bulk_ship_line.shipping_quantity_uom2.delete;
9046             l_non_bulk_ship_line.shipping_quantity_uom.delete;
9047 
9048             l_non_bulk_ship_line.order_quantity_uom.delete;
9049             l_non_bulk_ship_line.order_quantity_uom2.delete;
9050             l_non_bulk_ship_line.ordered_quantity.delete;
9051             l_non_bulk_ship_line.ordered_quantity2.delete;
9052             l_non_bulk_ship_line.fulfilled_flag.delete;
9053             l_non_bulk_ship_line.actual_shipment_date.delete;
9054 	    l_non_bulk_ship_line.header_id.delete;
9055 	    l_non_bulk_ship_line.top_model_line_id.delete;
9056 	    l_non_bulk_ship_line.ato_line_id.delete;
9057 	    l_non_bulk_ship_line.ship_set_id.delete;
9058 	    l_non_bulk_ship_line.arrival_set_id.delete;
9059 	    l_non_bulk_ship_line.inventory_item_id.delete;
9060 	    l_non_bulk_ship_line.ship_from_org_id.delete;
9061 	    l_non_bulk_ship_line.line_set_id.delete;
9062             l_non_bulk_ship_line.smc_flag.delete;
9063             l_non_bulk_ship_line.over_ship_reason_code.delete;
9064             l_non_bulk_ship_line.pending_quantity.delete;
9065             l_non_bulk_ship_line.pending_quantity2.delete;
9066             l_non_bulk_ship_line.pending_requested_flag.delete;
9067             l_non_bulk_ship_line.item_type_code.delete;
9068             l_non_bulk_ship_line.calculate_price_flag.delete;
9069 
9070 
9071             l_non_bulk_req_count:=0;
9072             l_non_bulk_req_line.line_id.delete;
9073             l_non_bulk_req_line.requested_quantity.delete;
9074             l_non_bulk_req_line.requested_quantity2.delete;
9075             l_non_bulk_req_line.shipping_quantity2.delete;
9076             l_non_bulk_req_line.shipping_quantity.delete;
9077             l_non_bulk_req_line.shipped_quantity.delete; -- muom
9078             l_non_bulk_req_line.shipping_quantity_uom2.delete;
9079             l_non_bulk_req_line.shipping_quantity_uom.delete;
9080             l_non_bulk_req_line.order_quantity_uom.delete;
9081             l_non_bulk_req_line.order_quantity_uom2.delete;
9082             l_non_bulk_req_line.ordered_quantity.delete;
9083             l_non_bulk_req_line.ordered_quantity2.delete;
9084 	    l_non_bulk_req_line.line_set_id.delete;
9085             l_non_bulk_req_line.item_type_code.delete;
9086 
9087 	    l_non_bulk_req_line.ato_line_id.delete;
9088 	    l_non_bulk_req_line.top_model_line_id.delete;
9089 	    l_non_bulk_req_line.inventory_item_id.delete;
9090 	    l_non_bulk_req_line.ship_from_org_id.delete;
9091 
9092             WSH_UTIL_CORE.api_post_call(p_return_status    =>l_return_status,
9093                                    x_num_warnings     =>l_num_om_warnings,
9094                                    x_num_errors       =>l_num_om_errors,
9095                                    p_raise_error_flag =>false);
9096 
9097        IF l_debug_on THEN
9098          WSH_DEBUG_SV.logmsg(l_module_name, 'Setting the savepoint its_process_order_non_bulk for the next order');
9099        END IF;
9100        SAVEPOINT its_process_order_non_bulk;
9101      ELSIF (l_non_bulk_count = 1) THEN
9102      --{
9103        IF l_debug_on THEN
9104          WSH_DEBUG_SV.logmsg(l_module_name, 'Setting the savepoint its_process_order_non_bulk for the first order');
9105        END IF;
9106        SAVEPOINT its_process_order_non_bulk;
9107      --}
9108      END IF; --}
9109 
9110      -- Cache the Source header Number
9111      IF l_debug_on THEN
9112 -- HW OPMCONV. Comment printing value of process flag
9113         WSH_DEBUG_SV.logmsg(l_module_name, 'L_PROCESS_FLAG IS ' || L_PROCESS_FLAG );
9114         WSH_DEBUG_SV.logmsg(l_module_name,  'L_TOT_SHP_QTY = '||L_TOT_SHP_QTY  );
9115      END IF;
9116 
9117      l_setsmc_input_rec.top_model_line_id := oe_interface_rec.top_model_line_id;
9118      l_setsmc_input_rec.ship_set_id := oe_interface_rec.ship_set_id;
9119      l_setsmc_input_rec.header_id := oe_interface_rec.source_header_id;
9120 
9121      --Assign record to bulk and non bulk record of table for passing to OM
9122      IF (Is_OM_Bulk_Enable(p_batch_id,
9123                            oe_interface_rec.total_requested_quantity,
9124                            oe_interface_rec.total_shipped_quantity,
9125                            -- bug 5688051
9126                            oe_interface_rec.total_requested_quantity2,
9127                            oe_interface_rec.total_shipped_quantity2,
9128                            l_setsmc_input_rec,
9129                            oe_interface_rec.source_line_id,
9130                            oe_interface_rec.source_header_id)
9131         ) THEN -- {
9132          l_bulk_count := l_bulk_count + 1;
9133 
9134 	 l_bulk_ship_line.header_id.extend;
9135 	 l_bulk_ship_line.header_id(l_bulk_count):= oe_interface_rec.source_header_id;
9136 	 l_bulk_ship_line.line_id.extend;
9137 	 l_bulk_ship_line.line_id(l_bulk_count):= oe_interface_rec.source_line_id;
9138 	 l_bulk_ship_line.top_model_line_id.extend;
9139 	 l_bulk_ship_line.top_model_line_id(l_bulk_count):= oe_interface_rec.top_model_line_id;
9140 	 l_bulk_ship_line.ship_set_id.extend;
9141 	 l_bulk_ship_line.ship_set_id(l_bulk_count):= oe_interface_rec.ship_set_id;
9142 	 l_bulk_ship_line.arrival_set_id.extend;
9143 	 l_bulk_ship_line.arrival_set_id(l_bulk_count):= oe_interface_rec.arrival_set_id;
9144 	 l_bulk_ship_line.actual_shipment_date.extend;
9145 	 l_bulk_ship_line.actual_shipment_date(l_bulk_count):=NVL(oe_interface_rec.initial_pickup_date,sysdate);
9146 	 l_bulk_ship_line.shipping_quantity_uom.extend;
9147 	 l_bulk_ship_line.shipping_quantity_uom(l_bulk_count):= oe_interface_rec.requested_quantity_uom;
9148 	 l_bulk_ship_line.shipping_quantity_uom2.extend;
9149 	 l_bulk_ship_line.shipping_quantity_uom2(l_bulk_count):=oe_interface_rec.requested_quantity_uom2;
9150 	 l_bulk_ship_line.shipping_quantity.extend;
9151 	 l_bulk_ship_line.shipping_quantity(l_bulk_count):= l_tot_shp_qty;
9152          -- muom
9153 	 l_bulk_ship_line.shipped_quantity.extend;
9154 	 l_bulk_ship_line.shipped_quantity(l_bulk_count):= l_tot_om_shp_qty;
9155 	 l_bulk_ship_line.shipping_quantity2.extend;
9156 	 l_bulk_ship_line.shipping_quantity2(l_bulk_count):= l_tot_shp_qty2;
9157 	 l_bulk_ship_line.flow_status_code.extend;
9158 	 l_bulk_ship_line.flow_status_code(l_bulk_count):= oe_interface_rec.flow_status_code;
9159 	 l_bulk_ship_line.ordered_quantity.extend;
9160 	 l_bulk_ship_line.ordered_quantity(l_bulk_count):= oe_interface_rec.ordered_quantity;
9161 
9162 	 l_bulk_ship_line.org_id.extend;
9163 	 l_bulk_ship_line.org_id(l_bulk_count):= oe_interface_rec.org_id;
9164 
9165 	 l_bulk_ship_line.ordered_quantity2.extend;
9166 	 l_bulk_ship_line.ordered_quantity2(l_bulk_count):= oe_interface_rec.ordered_quantity2;
9167      ELSE -- } {
9168 
9169          IF l_debug_on THEN
9170             WSH_DEBUG_SV.logmsg(l_module_name, 'Interface the Non-Bulk record for Source Header');
9171             WSH_DEBUG_SV.log(l_module_name,'ship_tolerance_above',oe_interface_rec.ship_tolerance_above);
9172             WSH_DEBUG_SV.log(l_module_name,'ship_tolerance_below',oe_interface_rec.ship_tolerance_below);
9173             WSH_DEBUG_SV.log(l_module_name,'total_requested_quantity',oe_interface_rec.total_requested_quantity);
9174             WSH_DEBUG_SV.log(l_module_name,'order_line_quantity',oe_interface_rec.order_line_quantity);
9175             WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_SHIP_CONFRIM_ACTIONS.Handle_Tolerances',WSH_DEBUG_SV.C_PROC_LEVEL);
9176          END IF;
9177 
9178          -- muom
9179          l_fulfill_base := WSH_UTIL_CORE.Get_Line_Fulfillment_Base('OE', oe_interface_rec.source_line_id);
9180 
9181          --Standllone created new API ,Moved common code inside Handle_Tolerances API
9182          --    to be used by existing code as well as Standalone code
9183          Handle_Tolerances ( p_batch_id => p_batch_id,
9184                              p_oe_interface_rec => oe_interface_rec,
9185                              x_fulfilled_flag => l_fulfilled_flag,
9186                              x_over_reason => l_over_reason,
9187                              x_return_status => l_return_status);
9188 
9189          IF l_debug_on THEN
9190             WSH_DEBUG_SV.log(l_module_name,'Return status after calling WSH_SHIP_CONFRIM_ACTIONS.Handle_Tolerances ',l_return_status);
9191          END IF;
9192 
9193          WSH_UTIL_CORE.api_post_call( p_return_status => l_return_status,
9194                                                     x_num_warnings =>l_num_warnings,
9195                                                     x_num_errors =>l_num_errors);
9196 
9197          -- muom
9198          IF l_debug_on THEN
9199             WSH_DEBUG_SV.logmsg(l_module_name,'l_tot_shp_qty '||l_tot_shp_qty||' l_tot_shp_qty2 '||l_tot_shp_qty2);
9200          END IF;
9201 
9202          IF ( l_fulfill_base = 'P' and l_tot_shp_qty > 0 ) OR ( l_fulfill_base = 'S' and l_tot_shp_qty2 > 0 ) THEN  --{
9203               --wrudge
9204               -- OM bug 2022029: populate  l_line_qtys only if requested_quantity differs,
9205               -- and it's not PTO,
9206               -- and the order line is not fulfilled in this session (flag is false or pending.)
9207               --
9208               IF l_debug_on THEN
9209                    WSH_DEBUG_SV.log(l_module_name, 'l_fulfilled_flag ',l_fulfilled_flag);
9210                    WSH_DEBUG_SV.log(l_module_name,'total_requested_quantity',oe_interface_rec.total_requested_quantity);
9211                    -- muom
9212                    WSH_DEBUG_SV.log(l_module_name,'total_requested_quantity2',oe_interface_rec.total_requested_quantity2);
9213                    WSH_DEBUG_SV.log(l_module_name,'top_model_line_id', oe_interface_rec.top_model_line_id);
9214                    WSH_DEBUG_SV.log(l_module_name,'ato_line_id',oe_interface_rec.ato_line_id);
9215               END IF;
9216               --Bug 8975388: initialize the value of variable l_cancel_unpicked_details.
9217               --
9218               l_cancel_unpicked_details := NULL;
9219               --
9220               IF (l_process_flag = FND_API.G_FALSE ) THEN
9221               --{
9222                     IF l_debug_on THEN
9223                             WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_CUSTOM_PUB.Cancel_Unpicked_Details_At_ITS', WSH_DEBUG_SV.C_PROC_LEVEL);
9224                     END IF;
9225                     l_cancel_unpicked_details := WSH_CUSTOM_PUB.Cancel_Unpicked_Details_At_ITS(  p_source_header_id => oe_interface_rec.source_header_id,
9226                                                                                                  p_source_line_id => oe_interface_rec.source_line_id,
9227                                                                                                  p_source_line_set_id => oe_interface_rec.source_line_set_id,
9228                                                                                                  p_remain_details_id => l_remain_details_id);
9229                     IF l_debug_on THEN
9230                         WSH_DEBUG_SV.logmsg(l_module_name, 'l_cancel_upicked_details '|| l_cancel_unpicked_details);
9231                     END IF;
9232                     IF ( l_cancel_unpicked_details NOT IN ('Y','N') ) THEN
9233                         IF l_debug_on THEN
9234                                 WSH_DEBUG_SV.logmsg(l_module_name, ' Error in Routine wsh_custom_pub.Cancel_Unpicked_Details_At_ITS ');
9235                         END IF;
9236                         RAISE FND_API.G_EXC_ERROR;
9237                     END IF;
9238               --}
9239               ELSE -- If it is an OPM Org, which is the current/default behaviour
9240                    l_cancel_unpicked_details := 'Y';
9241               END IF;
9242               --
9243               -- End Bug 8975388
9244 
9245               -- muom
9246               IF    (  (( l_fulfill_base = 'P' and l_tot_shp_qty <> oe_interface_rec.total_requested_quantity) OR
9247                         (l_fulfill_base = 'S' and l_tot_shp_qty2 <> oe_interface_rec.total_requested_quantity2))
9248                       AND (   oe_interface_rec.top_model_line_id IS NULL
9249                           OR NVL(oe_interface_rec.ato_line_id,-1) = oe_interface_rec.top_model_line_id  )
9250                       AND (NVL(l_fulfilled_flag, 'F') <> 'T'))
9251                  OR (l_fulfilled_flag = 'P')
9252                  -- Bug 7131800: if the Remaining Delivery Details were not Cancelled Earlier, then they would need to be split into another Line
9253                  OR ( l_cancel_unpicked_details = 'N'
9254                       --Bug 13062521: Only for Standard Items and ATO Items
9255                       AND (  oe_interface_rec.top_model_line_id IS NULL
9256                              OR NVL(oe_interface_rec.ato_line_id,-1) = oe_interface_rec.top_model_line_id  ) )
9257               THEN
9258                 l_non_bulk_req_count := l_non_bulk_req_count + 1;
9259 
9260                 l_non_bulk_req_line.line_id.extend;
9261                 l_non_bulk_req_line.requested_quantity.extend;
9262                 l_non_bulk_req_line.requested_quantity2.extend;
9263                 l_non_bulk_req_line.shipping_quantity2.extend;
9264                 l_non_bulk_req_line.shipping_quantity.extend;
9265                 l_non_bulk_req_line.shipped_quantity.extend; -- muom
9266                 l_non_bulk_req_line.shipping_quantity_uom2.extend;
9267                 l_non_bulk_req_line.shipping_quantity_uom.extend;
9268                 l_non_bulk_req_line.order_quantity_uom.extend;
9269                 l_non_bulk_req_line.order_quantity_uom2.extend;
9270                 l_non_bulk_req_line.ordered_quantity.extend;
9271                 l_non_bulk_req_line.ordered_quantity2.extend;
9272                 l_non_bulk_req_line.line_set_id.extend;
9273                 l_non_bulk_req_line.item_type_code.extend;
9274                 l_non_bulk_req_line.ato_line_id.extend;
9275                 l_non_bulk_req_line.top_model_line_id.extend;
9276                 l_non_bulk_req_line.inventory_item_id.extend;
9277                 l_non_bulk_req_line.ship_from_org_id.extend;
9278 
9279 
9280                 l_non_bulk_req_line.line_id(l_non_bulk_req_count):= oe_interface_rec.source_line_id;
9281                 l_non_bulk_req_line.requested_quantity(l_non_bulk_req_count):=
9282                                                                     oe_interface_rec.total_requested_quantity;
9283                 l_non_bulk_req_line.requested_quantity2(l_non_bulk_req_count):=
9284                                                                     oe_interface_rec.total_requested_quantity2;
9285                 l_non_bulk_req_line.shipping_quantity2(l_non_bulk_req_count):= l_tot_shp_qty2;
9286                 l_non_bulk_req_line.shipping_quantity(l_non_bulk_req_count):= l_tot_shp_qty;
9287                 -- muom
9288                 l_non_bulk_req_line.shipped_quantity(l_non_bulk_req_count):= l_tot_om_shp_qty;
9289                 l_non_bulk_req_line.shipping_quantity_uom2(l_non_bulk_req_count):=
9290                                                                        oe_interface_rec.requested_quantity_uom2;
9291                 l_non_bulk_req_line.shipping_quantity_uom(l_non_bulk_req_count):=
9292                                                                           oe_interface_rec.requested_quantity_uom;
9293                 l_non_bulk_req_line.order_quantity_uom(l_non_bulk_req_count):=oe_interface_rec.order_quantity_uom;
9294                 l_non_bulk_req_line.order_quantity_uom2(l_non_bulk_req_count):=
9295                                                                          oe_interface_rec.ordered_quantity_uom2;
9296                 l_non_bulk_req_line.ordered_quantity(l_non_bulk_req_count):= oe_interface_rec.ordered_quantity;
9297                 l_non_bulk_req_line.ordered_quantity2(l_non_bulk_req_count):= oe_interface_rec.ordered_quantity2;
9298 
9299                 l_non_bulk_req_line.line_set_id(l_non_bulk_req_count):= oe_interface_rec.source_line_set_id;
9300                 l_non_bulk_req_line.item_type_code(l_non_bulk_req_count):= oe_interface_rec.item_type_code;
9301 
9302                 l_non_bulk_req_line.ato_line_id(l_non_bulk_req_count):= oe_interface_rec.ato_line_id;
9303                 l_non_bulk_req_line.top_model_line_id(l_non_bulk_req_count):= oe_interface_rec.top_model_line_id;
9304                 l_non_bulk_req_line.inventory_item_id(l_non_bulk_req_count):= oe_interface_rec.inventory_item_id;
9305                 l_non_bulk_req_line.ship_from_org_id(l_non_bulk_req_count):= oe_interface_rec.organization_id;
9306 
9307 
9308                 IF l_debug_on THEN
9309                    WSH_DEBUG_SV.logmsg(l_module_name, 'Lines in l_non_bulk_req_line');
9310                    WSH_DEBUG_SV.log(l_module_name,'line_id',l_non_bulk_req_line.line_id(l_non_bulk_req_count));
9311                    WSH_DEBUG_SV.log(l_module_name,'requested_quantity',l_non_bulk_req_line.requested_quantity(l_non_bulk_req_count));
9312                    WSH_DEBUG_SV.log(l_module_name,'requested_quantity2',l_non_bulk_req_line.requested_quantity2(l_non_bulk_req_count));
9313                    WSH_DEBUG_SV.log(l_module_name,'shipping_quantity',l_non_bulk_req_line.shipping_quantity(l_non_bulk_req_count));
9314                    WSH_DEBUG_SV.log(l_module_name,'shipping_quantity_uom',l_non_bulk_req_line.shipping_quantity_uom(l_non_bulk_req_count));
9315                    WSH_DEBUG_SV.log(l_module_name,'shipping_quantity2',l_non_bulk_req_line.shipping_quantity2(l_non_bulk_req_count));
9316                    WSH_DEBUG_SV.log(l_module_name,'shipping_quantity_uom2',l_non_bulk_req_line.shipping_quantity_uom2(l_non_bulk_req_count));
9317                    -- muom
9318                    WSH_DEBUG_SV.log(l_module_name,'shipped_quantity',l_non_bulk_req_line.shipped_quantity(l_non_bulk_req_count));
9319                    WSH_DEBUG_SV.log(l_module_name,'ordered_quantity',l_non_bulk_req_line.ordered_quantity(l_non_bulk_req_count));
9320                    WSH_DEBUG_SV.log(l_module_name,'order_quantity_uom',l_non_bulk_req_line.order_quantity_uom(l_non_bulk_req_count));
9321                    WSH_DEBUG_SV.log(l_module_name,'ordered_quantity2',l_non_bulk_req_line.ordered_quantity2(l_non_bulk_req_count));
9322                    WSH_DEBUG_SV.log(l_module_name,'order_quantity_uom2',l_non_bulk_req_line.order_quantity_uom2(l_non_bulk_req_count));
9323                    WSH_DEBUG_SV.log(l_module_name,'line_set_id',l_non_bulk_req_line.line_set_id(l_non_bulk_req_count));
9324                    WSH_DEBUG_SV.log(l_module_name,'item_type_code',l_non_bulk_req_line.ato_line_id(l_non_bulk_req_count));
9325                    WSH_DEBUG_SV.log(l_module_name,'top_model_line_id',l_non_bulk_req_line.top_model_line_id(l_non_bulk_req_count));
9326                    WSH_DEBUG_SV.log(l_module_name,'inventory_item_id',l_non_bulk_req_line.inventory_item_id(l_non_bulk_req_count));
9327                    WSH_DEBUG_SV.log(l_module_name,'ship_from_org_id',l_non_bulk_req_line.ship_from_org_id(l_non_bulk_req_count));
9328                 END IF;
9329 
9330 
9331               END IF;
9332 
9333               --HVOP heali
9334               l_non_bulk_ship_count := l_non_bulk_ship_count + 1;
9335 
9336               extend_om_ship_line(l_non_bulk_ship_line
9337                                 , l_return_status);
9338 
9339               IF l_debug_on THEN
9340                  WSH_DEBUG_SV.log(l_module_name, 'Non Bulk Ship l_non_bulk_ship_count',l_non_bulk_ship_count);
9341                  WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
9342               END IF;
9343 
9344               WSH_UTIL_CORE.api_post_call
9345                           ( p_return_status    =>l_return_status
9346                           , x_num_warnings     =>l_num_warnings
9347                           , x_num_errors       =>l_num_errors);
9348 
9349 
9350               IF (NVL(l_fulfilled_flag, 'F') = 'T') THEN
9351                  l_non_bulk_ship_line.fulfilled_flag(l_non_bulk_ship_count):= 'Y';
9352               ELSE
9353                  l_non_bulk_ship_line.fulfilled_flag(l_non_bulk_ship_count):= 'N';
9354               END IF;
9355               l_non_bulk_ship_line.actual_shipment_date(l_non_bulk_ship_count):=
9356                                                               NVL(oe_interface_rec.initial_pickup_date, sysdate);
9357               l_non_bulk_ship_line.shipping_quantity2(l_non_bulk_ship_count):= l_tot_shp_qty2;
9358               l_non_bulk_ship_line.shipping_quantity(l_non_bulk_ship_count):= l_tot_shp_qty;
9359               -- muom
9360               l_non_bulk_ship_line.shipped_quantity(l_non_bulk_ship_count):= l_tot_om_shp_qty;
9361               l_non_bulk_ship_line.shipping_quantity_uom2(l_non_bulk_ship_count):=
9362                                                                oe_interface_rec.requested_quantity_uom2;
9363               l_non_bulk_ship_line.shipping_quantity_uom(l_non_bulk_ship_count):=
9364                                                                oe_interface_rec.requested_quantity_uom;
9365               l_non_bulk_ship_line.line_id(l_non_bulk_ship_count):= oe_interface_rec.source_line_id;
9366               l_non_bulk_ship_line.header_id(l_non_bulk_ship_count):= oe_interface_rec.source_header_id;
9367               l_non_bulk_ship_line.top_model_line_id(l_non_bulk_ship_count):= oe_interface_rec.top_model_line_id;
9368               l_non_bulk_ship_line.ato_line_id(l_non_bulk_ship_count):= oe_interface_rec.ato_line_id;
9369               l_non_bulk_ship_line.ship_set_id(l_non_bulk_ship_count):= oe_interface_rec.ship_set_id;
9370               l_non_bulk_ship_line.arrival_set_id(l_non_bulk_ship_count):= oe_interface_rec.arrival_set_id;
9371               l_non_bulk_ship_line.inventory_item_id(l_non_bulk_ship_count):= oe_interface_rec.inventory_item_id;
9372               l_non_bulk_ship_line.ship_from_org_id(l_non_bulk_ship_count):= oe_interface_rec.organization_id;
9373               l_non_bulk_ship_line.line_set_id(l_non_bulk_ship_count):= oe_interface_rec.source_line_set_id;
9374               l_non_bulk_ship_line.smc_flag(l_non_bulk_ship_count):= oe_interface_rec.ship_model_complete_flag;
9375               l_non_bulk_ship_line.over_ship_reason_code(l_non_bulk_ship_count):= l_over_reason;
9376               l_non_bulk_ship_line.requested_quantity(l_non_bulk_ship_count):=
9377                                                                    oe_interface_rec.total_requested_quantity;
9378               l_non_bulk_ship_line.requested_quantity2(l_non_bulk_ship_count):=
9379                                                                    oe_interface_rec.total_requested_quantity2;
9380 
9381               l_non_bulk_ship_line.pending_quantity(l_non_bulk_ship_count):= NULL;
9382               l_non_bulk_ship_line.pending_quantity2(l_non_bulk_ship_count):= NULL;
9383               l_non_bulk_ship_line.pending_requested_flag(l_non_bulk_ship_count):= NULL;
9384 
9385               l_non_bulk_ship_line.order_quantity_uom(l_non_bulk_ship_count):=oe_interface_rec.order_quantity_uom;
9386               l_non_bulk_ship_line.order_quantity_uom2(l_non_bulk_ship_count):= oe_interface_rec.ordered_quantity_uom2;
9387               l_non_bulk_ship_line.model_remnant_flag(l_non_bulk_ship_count):= oe_interface_rec.model_remnant_flag;
9388               l_non_bulk_ship_line.ordered_quantity(l_non_bulk_ship_count):= oe_interface_rec.ordered_quantity;
9389               l_non_bulk_ship_line.ordered_quantity2(l_non_bulk_ship_count):= oe_interface_rec.ordered_quantity2;
9390               l_non_bulk_ship_line.item_type_code(l_non_bulk_ship_count):= oe_interface_rec.item_type_code;
9391               l_non_bulk_ship_line.calculate_price_flag(l_non_bulk_ship_count):= oe_interface_rec.calculate_price_flag;
9392               --HVOP heali
9393 
9394          END IF; -- }
9395 
9396      END IF; -- }
9397 
9398 
9399     EXCEPTION
9400        WHEN fnd_api.g_exc_error THEN
9401           IF l_debug_on THEN
9402              WSH_DEBUG_SV.log(l_module_name, 'fnd_api.g_exc_error at source_line_id',
9403                                                                    oe_interface_rec.source_line_id);
9404           END IF;
9405 
9406        WHEN fnd_api.g_exc_unexpected_error THEN
9407           IF l_debug_on THEN
9408              WSH_DEBUG_SV.log(l_module_name, 'fnd_api.g_exc_unexpected_error at source_line_id', oe_interface_rec.source_line_id);
9409           END IF;
9410 
9411 
9412        WHEN line_locked  THEN
9413           l_num_errors:=l_num_errors + 1;
9414           IF l_debug_on THEN
9415              WSH_DEBUG_SV.log(l_module_name, 'Failure to Accrue the Lock for source_line_id: ',
9416                                                                    oe_interface_rec.source_line_id);
9417           END IF;
9418 
9419        WHEN others THEN
9420           IF l_debug_on THEN
9421              WSH_DEBUG_SV.log(l_module_name, 'Errmsg: ',sqlerrm);
9422           END IF;
9423           raise FND_API.G_EXC_UNEXPECTED_ERROR;
9424    END; --}
9425 
9426 
9427      -- Cache the Source header Number
9428      l_prev_source_header_number:=oe_interface_rec.source_header_number;
9429      l_prev_org_id := l_org_id;
9430    END LOOP;  /* big loop , finished loop through the line*/
9431    CLOSE c_oe_interface;
9432 
9433  END IF; --}
9434  --HVOP heali
9435 
9436 
9437  IF l_debug_on THEN
9438     WSH_DEBUG_SV.log(l_module_name, 'l_non_bulk_ship_line.line_id.count',l_non_bulk_ship_line.line_id.count);
9439     WSH_DEBUG_SV.log(l_module_name, 'l_non_bulk_req_line.line_id.count',l_non_bulk_req_line.line_id.count);
9440  END IF;
9441 
9442  IF (l_non_bulk_ship_line.line_id.count > 0 ) THEN
9443             l_num_om_api_call := l_num_om_api_call + 1;
9444             Process_Stop_To_OM(
9445                 p_batch_id	     => p_batch_id,
9446                 p_bulk_ship_line     => l_non_bulk_ship_line,
9447                 p_bulk_req_line      => l_non_bulk_req_line,
9448                 P_bulk_mode	     => 'N',
9449                 p_org_id	     => l_org_id,
9450                 x_freight_costs      => l_freight_costs,
9451                 x_charges_are_calculated => l_charges_are_calculated,
9452                 x_return_status      => l_return_status);
9453 
9454 
9455     IF l_debug_on THEN
9456        WSH_DEBUG_SV.log(l_module_name, 'Process_Stop_To_OM l_return_status',l_return_status);
9457     END IF;
9458 
9459     IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
9460       IF l_debug_on THEN
9461         WSH_DEBUG_SV.logmsg(l_module_name, 'Rolling back to the savepoint its_process_order_non_bulk as ITS for the order completed with an error 2');
9462       END IF;
9463       --ROLLBACK TO its_process_order_non_bulk;
9464 
9465     END IF;
9466 
9467     IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) then
9468        raise fnd_api.g_exc_error;
9469     END IF;
9470 
9471 
9472     WSH_UTIL_CORE.api_post_call(p_return_status    =>l_return_status,
9473                                    x_num_warnings     =>l_num_om_warnings,
9474                                    x_num_errors       =>l_num_om_errors,
9475                                    p_raise_error_flag =>false);
9476  END IF;
9477 
9478 
9479  IF l_debug_on THEN
9480     WSH_DEBUG_SV.log(l_module_name, 'l_bulk_ship_line.line_id.count',l_bulk_ship_line.line_id.count);
9481     WSH_DEBUG_SV.log(l_module_name, 'l_bulk_req_line.line_id.count',l_bulk_req_line.line_id.count);
9482  END IF;
9483  IF (l_bulk_ship_line.line_id.count > 0 ) THEN
9484     l_num_om_api_call := l_num_om_api_call + 1;
9485     Process_Stop_To_OM(
9486                 p_batch_id            => p_batch_id,
9487                 p_bulk_ship_line     => l_bulk_ship_line,
9488                 p_bulk_req_line      => l_bulk_req_line,
9489                 P_bulk_mode          => 'Y',
9490                 x_freight_costs      => l_freight_costs,
9491                 x_charges_are_calculated => l_charges_are_calculated,
9492                 x_return_status      => l_return_status);
9493 
9494     IF l_debug_on THEN
9495        WSH_DEBUG_SV.log(l_module_name, 'Process_Stop_To_OM l_return_status',l_return_status);
9496     END IF;
9497     IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) then
9498        raise fnd_api.g_exc_error;
9499     END IF;
9500 
9501     WSH_UTIL_CORE.api_post_call(p_return_status    =>l_return_status,
9502                                    x_num_warnings     =>l_num_om_warnings,
9503                                    x_num_errors       =>l_num_om_errors,
9504                                    p_raise_error_flag =>false);
9505  END IF;
9506 
9507 
9508  IF l_debug_on THEN
9509    WSH_DEBUG_SV.log(l_module_name, 'l_num_om_api_call',l_num_om_api_call);
9510    WSH_DEBUG_SV.log(l_module_name, 'l_num_om_errors',l_num_om_errors);
9511    WSH_DEBUG_SV.log(l_module_name, 'l_num_om_warnings',l_num_om_warnings);
9512    WSH_DEBUG_SV.log(l_module_name, 'l_non_bulk_count',l_non_bulk_count);
9513    WSH_DEBUG_SV.log(l_module_name, 'l_num_errors',l_num_errors);
9514    WSH_DEBUG_SV.log(l_module_name, 'l_num_warnings',l_num_warnings);
9515  END IF;
9516 
9517   IF ( (l_num_errors >= l_non_bulk_count and l_non_bulk_count > 0 ) OR (l_num_om_errors >= l_num_om_api_call and l_num_om_api_call > 0) ) THEN
9518     raise fnd_api.g_exc_error;
9519   ELSIF ( (l_num_errors > 0 )  OR (l_num_om_errors > 0  and l_num_om_api_call > 0) ) THEN
9520     raise wsh_util_core.g_exc_warning;
9521   ELSIF ( (l_num_warnings > 0 ) OR (l_num_om_warnings > 0 and l_num_om_api_call > 0) ) THEN
9522     raise wsh_util_core.g_exc_warning;
9523   ELSE
9524     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
9525   END IF;
9526 
9527 
9528  IF l_debug_on THEN
9529       WSH_DEBUG_SV.log(l_module_name,'x_return_status',x_return_status);
9530        WSH_DEBUG_SV.pop(l_module_name);
9531  END IF;
9532 
9533 EXCEPTION
9534 
9535   WHEN fnd_api.g_exc_error THEN
9536        x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
9537        WSH_UTIL_CORE.Get_Messages('N',l_summary, l_details, l_get_msg_count);
9538         IF c_oe_interface%ISOPEN THEN
9539           close c_oe_interface;
9540         END IF;
9541         IF lock_delivery_line%ISOPEN THEN
9542           close lock_delivery_line;
9543         END IF;
9544         IF lock_dds_line%ISOPEN THEN
9545           close lock_dds_line;
9546         END IF;
9547         IF lock_dds_line_set%ISOPEN THEN
9548           close lock_dds_line_set;
9549         END IF;
9550         IF c_remain_detail_id%ISOPEN THEN
9551           close c_remain_detail_id;
9552         END IF;
9553         IF c_remain_lines%ISOPEN THEN
9554           close c_remain_lines;
9555         END IF;
9556         IF c_picked_dd%ISOPEN THEN
9557           close c_picked_dd;
9558         END IF;
9559 
9560        IF l_debug_on THEN
9561           WSH_DEBUG_SV.logmsg(l_module_name,'fnd_api.g_exc_error exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
9562           WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:fnd_api.g_exc_error');
9563        END IF;
9564        --
9565 
9566   WHEN wsh_util_core.g_exc_warning THEN
9567        x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
9568        WSH_UTIL_CORE.Get_Messages('N',l_summary, l_details, l_get_msg_count);
9569         IF c_oe_interface%ISOPEN THEN
9570           close c_oe_interface;
9571         END IF;
9572         IF lock_delivery_line%ISOPEN THEN
9573           close lock_delivery_line;
9574         END IF;
9575         IF lock_dds_line%ISOPEN THEN
9576           close lock_dds_line;
9577         END IF;
9578         IF lock_dds_line_set%ISOPEN THEN
9579           close lock_dds_line_set;
9580         END IF;
9581         IF c_remain_detail_id%ISOPEN THEN
9582           close c_remain_detail_id;
9583         END IF;
9584         IF c_remain_lines%ISOPEN THEN
9585           close c_remain_lines;
9586         END IF;
9587         IF c_picked_dd%ISOPEN THEN
9588           close c_picked_dd;
9589         END IF;
9590 
9591        IF l_debug_on THEN
9592           WSH_DEBUG_SV.logmsg(l_module_name,'wsh_util_core.g_exc_warning exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
9593           WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:wsh_util_core.g_exc_warning');
9594        END IF;
9595 
9596   WHEN fnd_api.g_exc_unexpected_error THEN
9597        x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
9598        WSH_UTIL_CORE.Get_Messages('N',l_summary, l_details, l_get_msg_count);
9599         IF c_oe_interface%ISOPEN THEN
9600           close c_oe_interface;
9601         END IF;
9602         IF lock_delivery_line%ISOPEN THEN
9603           close lock_delivery_line;
9604         END IF;
9605         IF lock_dds_line%ISOPEN THEN
9606           close lock_dds_line;
9607         END IF;
9608         IF lock_dds_line_set%ISOPEN THEN
9609           close lock_dds_line_set;
9610         END IF;
9611         IF c_remain_detail_id%ISOPEN THEN
9612           close c_remain_detail_id;
9613         END IF;
9614         IF c_remain_lines%ISOPEN THEN
9615           close c_remain_lines;
9616         END IF;
9617         IF c_picked_dd%ISOPEN THEN
9618           close c_picked_dd;
9619         END IF;
9620 
9621        IF l_debug_on THEN
9622           WSH_DEBUG_SV.logmsg(l_module_name,'fnd_api.g_exc_unexpected exception has occured: '||SQLERRM,WSH_DEBUG_SV.C_EXCEP_LEVEL);
9623           WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:wsh_util_core.g_exc_warning');
9624        END IF;
9625 
9626 
9627   WHEN line_locked  THEN
9628         wsh_util_core.printMsg('Error: Failure to Accrue the Lock for above line,Please try after sometime');
9629         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
9630         IF c_oe_interface%ISOPEN THEN
9631           close c_oe_interface;
9632         END IF;
9633         IF lock_delivery_line%ISOPEN THEN
9634           close lock_delivery_line;
9635         END IF;
9636         IF lock_dds_line%ISOPEN THEN
9637           close lock_dds_line;
9638         END IF;
9639         IF lock_dds_line_set%ISOPEN THEN
9640           close lock_dds_line_set;
9641         END IF;
9642         IF c_remain_detail_id%ISOPEN THEN
9643           close c_remain_detail_id;
9644         END IF;
9645         IF c_remain_lines%ISOPEN THEN
9646           close c_remain_lines;
9647         END IF;
9648         IF c_picked_dd%ISOPEN THEN
9649           close c_picked_dd;
9650         END IF;
9651 
9652         IF l_debug_on THEN
9653             WSH_DEBUG_SV.logmsg(l_module_name,'LINE_LOCKED exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
9654             WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:LINE_LOCKED');
9655         END IF;
9656         --
9657 
9658   WHEN others THEN
9659         x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
9660         l_error_code := SQLCODE;
9661         l_error_text := SQLERRM;
9662         -- bug 2657859 frontport bug 2685584: close open cursors
9663         IF c_oe_interface%ISOPEN THEN
9664           close c_oe_interface;
9665         END IF;
9666         IF lock_delivery_line%ISOPEN THEN
9667           close lock_delivery_line;
9668         END IF;
9669         IF lock_dds_line%ISOPEN THEN
9670           close lock_dds_line;
9671         END IF;
9672         IF lock_dds_line_set%ISOPEN THEN
9673           close lock_dds_line_set;
9674         END IF;
9675         IF c_remain_detail_id%ISOPEN THEN
9676           close c_remain_detail_id;
9677         END IF;
9678         IF c_remain_lines%ISOPEN THEN
9679           close c_remain_lines;
9680         END IF;
9681         IF c_picked_dd%ISOPEN THEN
9682           close c_picked_dd;
9683         END IF;
9684         wsh_util_core.printMsg('API interface_line_to_OM failed with an unexpected error');
9685         WSH_UTIL_CORE.PrintMsg('The unexpected error is ' || l_error_text);
9686         --
9687         IF l_debug_on THEN
9688             WSH_DEBUG_SV.logmsg(l_module_name, 'UNEXPECTED ERROR IN INTERFACE_HEADER_TO_OM ' );
9689             WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM
9690 ,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
9691             WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
9692         END IF;
9693         --
9694 END interface_stop_to_OM;
9695 
9696 
9697 --========================================================================
9698 -- PROCEDURE : process_inv_online
9699 --                  This API is a wrapper for
9700 --                  mtl_online_transaction_pub.process_online, to interface all
9701 --                  the lines inserted into MTL interface tables to inventory.
9702 --
9703 -- PARAMETERS: p_batch_id              ITS batch id.
9704 --             p_transaction_header_id The transaction header id for
9705 --                                     mtl_transactions_interface
9706 --             x_return_status         The return status of the API.
9707 --
9708 -- COMMENT   : Sets the inv_interfaced_flag for all the lines in the batch to
9709 --             'P' then calls the inventories process_online.  Then it calls
9710 --             Update_Interfaced_Details to update the inv_interfaced_flag
9711 --             accordingly.
9712 --
9713 --========================================================================
9714 
9715 procedure process_inv_online  ( p_batch_id in number ,
9716             p_transaction_header_id  in number  ,
9717                x_return_status       out NOCOPY  varchar2  ) is
9718 l_outcome BOOLEAN := TRUE;
9719 x_error_code VARCHAR2(240) := NULL;
9720 x_error_explanation VARCHAR2(240) := NULL;
9721 c_time_out   CONSTANT NUMBER := 1200;
9722 l_time_out NUMBER :=1200;
9723 l_profile_time_out NUMBER;--Bugfix#2346011.
9724 l_process_online_msg_count NUMBER := 0;
9725 l_process_online_message varchar2(4000) := NULL;
9726 l_error_Code            number;
9727 l_error_text            varchar2(2000);
9728 l_return_status             varchar2(30);
9729 
9730 --
9731 l_debug_on BOOLEAN;
9732 --
9733 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'PROCESS_INV_ONLINE';
9734 --
9735 begin
9736    --
9737    --
9738    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
9739    --
9740    IF l_debug_on IS NULL
9741    THEN
9742        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
9743    END IF;
9744    --
9745    IF l_debug_on THEN
9746        WSH_DEBUG_SV.push(l_module_name);
9747        --
9748        WSH_DEBUG_SV.log(l_module_name,'p_batch_id',p_batch_id);
9749        WSH_DEBUG_SV.log(l_module_name,'P_TRANSACTION_HEADER_ID',P_TRANSACTION_HEADER_ID);
9750    END IF;
9751    --
9752    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
9753    -- mark all 'N' as 'P'
9754 
9755    /* record is already processed by inventory */
9756    update wsh_delivery_details
9757    set inv_interfaced_flag = 'P' ,
9758        --Added as part of bug 7645262
9759        last_update_date    = sysdate,
9760        request_id          = fnd_global.conc_request_id,
9761        last_updated_by     = fnd_global.user_id
9762 
9763    where delivery_detail_id in  (
9764                SELECT  da.delivery_detail_id
9765                FROM   wsh_delivery_assignments_v da ,
9766                   wsh_delivery_legs dg,
9767                   wsh_new_deliveries dl,
9768                   wsh_trip_stops st
9769                where dl.delivery_id = da.delivery_id  AND
9770                    da.delivery_id  IS NOT NULL AND
9771                    st.stop_id = dg.pick_up_stop_id AND
9772                    st.batch_id   = p_batch_id   AND
9773                    st.stop_location_id = dl.initial_pickup_location_id AND
9774                    dg.delivery_id = dl.delivery_id AND
9775                    nvl(dl.SHIPMENT_DIRECTION , 'O') IN ('O', 'IO')   -- J Inbound Logistics jckwok
9776                )
9777    --RTV changes
9778    and source_code <> 'RTV'
9779    and inv_interfaced_flag = 'N'
9780    and container_flag = 'N'
9781    and released_status <> 'D' ; /* H integration: wrudge */
9782 --   and source_code = 'OE' ;
9783 
9784    -- process online
9785    --
9786    IF l_debug_on THEN
9787        WSH_DEBUG_SV.log(l_module_name,'Number of rows updated',SQL%ROWCOUNT);
9788        WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
9789        WSH_DEBUG_SV.logmsg(l_module_name,  'RIGHT BEFORE CALLING MTL_ONLINE_TRANSACTION_PUB.PROCESS_ONLINE'  );
9790    END IF;
9791    --
9792 --Bugfix#2346011.
9793    l_profile_time_out := TO_NUMBER(FND_PROFILE.VALUE('INV_RPC_TIMEOUT'));
9794 
9795    IF l_profile_time_out > 1200 THEN
9796      l_time_out := l_profile_time_out;
9797    END IF;
9798 
9799    --
9800    IF l_debug_on THEN
9801        WSH_DEBUG_SV.logmsg(l_module_name,  'TIMEOUT VALUE: '||L_TIME_OUT  );
9802        WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit MTL_ONLINE_TRANSACTION_PUB.PROCESS_ONLINE',WSH_DEBUG_SV.C_PROC_LEVEL);
9803    END IF;
9804    --
9805 --Bugfix#2346011.
9806    l_outcome := mtl_online_transaction_pub.process_online(
9807                 p_transaction_header_id,
9808                 l_time_out,
9809                 x_error_code,
9810                 x_error_explanation
9811                 );
9812    --
9813    IF l_debug_on THEN
9814        WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
9815        WSH_DEBUG_SV.log(l_module_name,'l_outcome',l_outcome);
9816    END IF;
9817    --
9818    /* what should we do if the online processer is hanging
9819      because manager is not aviable. User needs to be informed */
9820 
9821    if (l_outcome <> TRUE )   THEN
9822       WSH_UTIL_CORE.printMsg('MTL_ONLINE_TRANSACTION_PUB.process_online returns false');
9823       WSH_UTIL_CORE.printMsg('Error Code:' || x_error_code);
9824       WSH_UTIL_CORE.printMsg('Error Explanation:' || x_error_explanation);
9825       WSH_UTIL_CORE.printMsg('Retrieving messages from the stack');
9826       IF l_debug_on THEN
9827          WSH_DEBUG_SV.log(l_module_name,'Error Code:',x_error_code);
9828          WSH_DEBUG_SV.log(l_module_name,'Error Explanation::',
9829                                                   x_error_explanation);
9830       END IF;
9831       l_process_online_msg_count := fnd_msg_pub.count_msg;
9832       if l_process_online_msg_count > 0 then
9833          FOR i in 1 .. l_process_online_msg_count
9834          LOOP
9835             l_process_online_message := fnd_msg_pub.get(i,'T');
9836             l_process_online_message := replace(l_process_online_message,fnd_global.local_chr(0), ' ');
9837             WSH_UTIL_CORE.PrintMsg(l_process_online_message);
9838             IF l_debug_on THEN
9839                WSH_DEBUG_SV.log(l_module_name,'Error txt:',
9840                                      SUBSTR(l_process_online_message,1,200));
9841             END IF;
9842          END LOOP;
9843       end if;
9844 
9845       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
9846       --
9847       IF l_debug_on THEN
9848           WSH_DEBUG_SV.log(l_module_name,'x_return_status',x_return_status);
9849           WSH_DEBUG_SV.pop(l_module_name);
9850       END IF;
9851       --
9852       return ;
9853    end if  ;
9854 
9855    -- update to 'Y' where where inv_interfaced_flag = 'P' and dd_id in mmt and trx_hdr matches and mtl.delivery_id matches
9856 
9857    Update_Interfaced_Details ( p_batch_id , l_return_status ) ;
9858 
9859      if (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) then
9860       x_return_status := l_return_status ;
9861         WSH_UTIL_CORE.PrintMsg('process_inv_online  failed for batch '|| p_batch_id ||': txn '
9862                      || p_transaction_header_id  );
9863       --
9864       IF l_debug_on THEN
9865           WSH_DEBUG_SV.log(l_module_name,'process_inv_online  failed for Batch '
9866               || p_batch_id|| ': txn '|| p_transaction_header_id );
9867           WSH_DEBUG_SV.pop(l_module_name);
9868       END IF;
9869       --
9870       return ;
9871      end if;
9872      --
9873      IF l_debug_on THEN
9874          WSH_DEBUG_SV.log(l_module_name,'x_return_status',x_return_status);
9875          WSH_DEBUG_SV.pop(l_module_name);
9876      END IF;
9877      --
9878    EXCEPTION
9879      WHEN others THEN
9880        x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
9881        l_error_code := SQLCODE;
9882        l_error_text := SQLERRM;
9883        WSH_UTIL_CORE.PrintMsg(p_transaction_header_id  ||': process_inv_online failed ');
9884        WSH_UTIL_CORE.PrintMsg('The unexpected error is ' || l_error_text);
9885        --
9886        IF l_debug_on THEN
9887            WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
9888            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
9889        END IF;
9890        --
9891 end process_inv_online ;
9892 
9893 --========================================================================
9894 -- FUNCTION  : Get_Account
9895 --                  Purpose of the function is to get the COGS account
9896 --                  information
9897 --
9898 -- PARAMETERS: p_delivery_detail_id    The delivery detail id
9899 --             x_return_status         The return status of the API.
9900 --
9901 -- COMMENT   : Called from Interface_Detail_To_Inv.
9902 --
9903 --========================================================================
9904 
9905 FUNCTION Get_Account(
9906   p_delivery_detail_id      IN   NUMBER
9907 , x_return_status          OUT NOCOPY  VARCHAR2
9908 ) RETURN NUMBER
9909 IS
9910 
9911 -- CSUN 01/19/2000 need to modify this cursor once we want to include containers
9912 CURSOR C_Details(p_del_detail_id number)  is
9913 SELECT source_line_id, organization_id, org_id from wsh_delivery_details
9914 where delivery_detail_id = p_del_detail_id
9915 and container_flag = 'N'
9916 and released_status <> 'D' ; /* H integration: wrudge */
9917 l_detail_rec c_details%ROWTYPE;
9918 
9919 CURSOR c_dispatch_account(p_organization_id number)
9920 IS
9921 SELECT goods_dispatched_account
9922 FROM   wsh_shipping_parameters
9923 WHERE  organization_id = p_organization_id;
9924 
9925 l_dispatch_account c_dispatch_account%ROWTYPE;
9926 l_cogs_return_ccid number := NULL;
9927 l_cogs_concat_segs varchar2(1000) := NULL;
9928 l_cogs_concat_ids varchar2(1000) := NULL;
9929 l_cogs_concat_descrs varchar2(1000) := NULL;
9930 l_cogs_msg_count number := NULL;
9931 l_cogs_msg_data varchar2(4000) := NULL;
9932 l_account            NUMBER := NULL;
9933 l_cogs_return_status   VARCHAR2(30);
9934 
9935 -- bug 2657859 frontport bug 2685584: to handle other exceptions
9936 l_error_Code            number;
9937 l_error_text            varchar2(2000);
9938 
9939 NO_DEF_GOODS_DISPATCHED_ACCT exception;
9940 --
9941 l_debug_on BOOLEAN;
9942 --
9943 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'GET_ACCOUNT';
9944 --
9945 BEGIN
9946    --
9947    --
9948    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
9949    --
9950    IF l_debug_on IS NULL
9951    THEN
9952        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
9953    END IF;
9954    --
9955    IF l_debug_on THEN
9956        WSH_DEBUG_SV.push(l_module_name);
9957        --
9958        WSH_DEBUG_SV.log(l_module_name,'P_DELIVERY_DETAIL_ID',P_DELIVERY_DETAIL_ID);
9959    END IF;
9960    --
9961    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
9962    OPEN c_details(p_delivery_detail_id);
9963    FETCH c_details INTO l_detail_rec;
9964    CLOSE c_details;
9965 
9966    IF l_debug_on THEN
9967       WSH_DEBUG_SV.log(l_module_name,'source_line_id',l_detail_rec.source_line_id);
9968       WSH_DEBUG_SV.log(l_module_name,'organization_id',l_detail_rec.organization_id);
9969       WSH_DEBUG_SV.log(l_module_name,'org_id',l_detail_rec.org_id);
9970    END IF;
9971 
9972    IF l_detail_rec.org_id IS NULL THEN
9973      SELECT ORG_ID
9974      INTO l_detail_rec.org_id
9975      FROM OE_ORDER_LINES_ALL
9976      WHERE LINE_ID = l_detail_rec.SOURCE_LINE_ID;
9977      IF l_debug_on THEN
9978        WSH_DEBUG_SV.log(l_module_name,'derived org_id', l_detail_rec.org_id);
9979      END IF;
9980    END IF;
9981 
9982    OPEN c_dispatch_account(l_detail_rec.organization_id);
9983    FETCH c_dispatch_account into l_dispatch_account;
9984    if (c_dispatch_account%NOTFOUND) then
9985      RAISE NO_DEF_GOODS_DISPATCHED_ACCT;
9986    END if;
9987    CLOSE c_dispatch_account;
9988 
9989    MO_GLOBAL.set_policy_context('S', l_detail_rec.org_id);
9990    --
9991    -- bug 2756842 - to reset message stack
9992    oe_msg_pub.initialize();
9993    --
9994    IF l_debug_on THEN
9995        WSH_DEBUG_SV.log(l_module_name,'l_dispatch_account',
9996                                   l_dispatch_account.goods_dispatched_account);
9997        WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit OE_FLEX_COGS_PUB.START_PROCESS',WSH_DEBUG_SV.C_PROC_LEVEL);
9998    END IF;
9999    --
10000    l_cogs_return_status := OE_FLEX_COGS_PUB.Start_Process(
10001      1.0,
10002      l_detail_rec.source_line_id,
10003      l_cogs_return_ccid,
10004      l_cogs_concat_segs,
10005      l_cogs_concat_ids,
10006      l_cogs_concat_descrs,
10007      l_cogs_msg_count,
10008      l_cogs_msg_data);
10009    --
10010    IF l_debug_on THEN
10011        WSH_DEBUG_SV.logmsg(l_module_name,  'NO. OF OE MESSAGES :'||L_COGS_MSG_COUNT  );
10012        WSH_DEBUG_SV.logmsg(l_module_name,  'RETURN STATUS FROM OE_FLEX_COGS_PUB.START_PROCESS IS ' || L_COGS_RETURN_STATUS  );
10013        WSH_DEBUG_SV.logmsg(l_module_name,  'CONCAT_SEGS IS ' || L_COGS_CONCAT_SEGS  );
10014        WSH_DEBUG_SV.logmsg(l_module_name,  'CONCAT_IDS IS ' || L_COGS_CONCAT_IDS  );
10015        WSH_DEBUG_SV.logmsg(l_module_name,  'CONCAT_DESCRS IS ' || L_COGS_CONCAT_DESCRS  );
10016        WSH_DEBUG_SV.logmsg(l_module_name,  'L_CONGS_RETURN_CCID IS ' || L_COGS_RETURN_CCID  );
10017    END IF;
10018    --
10019 
10020    IF   l_cogs_msg_count is not null then
10021      for k in 1 .. l_cogs_msg_count LOOP
10022        --
10023        l_cogs_msg_data := oe_msg_pub.get(
10024          p_msg_index => k,
10025          p_encoded => 'F'
10026        );
10027        --
10028        IF l_debug_on THEN
10029            WSH_DEBUG_SV.logmsg(l_module_name, SUBSTR ( L_COGS_MSG_DATA , 1 , 255 ) );
10030        END IF;
10031        --
10032      END LOOP;
10033 
10034    END IF;
10035    l_account := l_cogs_return_ccid;
10036    IF l_account IS NULL THEN
10037       l_account :=  l_dispatch_account.goods_dispatched_account;
10038       -- IF l_account IS NULL THEN
10039         -- x_return_status := l_cogs_return_status;
10040       -- END IF;
10041    END IF;
10042  ---  Bug 2791295 return status should be passed irrespective of l_account value
10043     x_return_status := l_cogs_return_status;
10044 
10045    --
10046    IF l_debug_on THEN
10047        WSH_DEBUG_SV.log(l_module_name,'l_account',l_account);
10048        WSH_DEBUG_SV.pop(l_module_name);
10049    END IF;
10050    --
10051    RETURN(l_account);
10052 
10053    EXCEPTION
10054      WHEN NO_DEF_GOODS_DISPATCHED_ACCT THEN
10055         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
10056        WSH_UTIL_CORE.PrintMsg('There is no default goods dispatched account');
10057         -- bug 2657859 frontport bug 2685584: close open cursors
10058         IF c_details%ISOPEN THEN
10059           close c_details;
10060         END IF;
10061         IF c_dispatch_account%ISOPEN THEN
10062           close c_dispatch_account;
10063         END IF;
10064        x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
10065        --
10066        IF l_debug_on THEN
10067            WSH_DEBUG_SV.logmsg(l_module_name,'NO_DEF_GOODS_DISPATCHED_ACCT exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
10068            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:NO_DEF_GOODS_DISPATCHED_ACCT');
10069        END IF;
10070        --
10071        RETURN NULL;
10072 
10073      -- bug 2657859 frontport bug 2685584: catch other exceptions
10074      WHEN others THEN
10075        x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
10076        l_error_code := SQLCODE;
10077        l_error_text := SQLERRM;
10078        WSH_UTIL_CORE.PrintMsg(p_delivery_detail_id  ||': get_account failed ');
10079        WSH_UTIL_CORE.PrintMsg('The unexpected error code is ' || l_error_code);
10080        WSH_UTIL_CORE.PrintMsg('The unexpected error is ' || l_error_text);
10081         IF c_details%ISOPEN THEN
10082           close c_details;
10083         END IF;
10084         IF c_dispatch_account%ISOPEN THEN
10085           close c_dispatch_account;
10086         END IF;
10087        x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
10088        IF l_debug_on THEN
10089            WSH_DEBUG_SV.logmsg(l_module_name,'Unhandled exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
10090            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
10091        END IF;
10092        RETURN NULL;
10093 --
10094 END Get_Account;
10095 
10096 
10097 --========================================================================
10098 -- FUNCTION  : ALL_INTERFACED
10099 --                  If there are any lines in the batch that have either not
10100 --                  interfaced to OM, or not interfaced to INV, then return
10101 --                  FALSE.
10102 --
10103 -- PARAMETERS: p_batch_id              ITS batch id.
10104 --
10105 -- COMMENT   :
10106 --
10107 --========================================================================
10108 
10109 FUNCTION ALL_INTERFACED ( p_batch_id in number ) RETURN BOOLEAN  is
10110 --
10111 l_debug_on BOOLEAN;
10112 --
10113 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'ALL_INTERFACED';
10114 --
10115 BEGIN
10116      --
10117      --
10118      l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
10119      --
10120      IF l_debug_on IS NULL
10121      THEN
10122          l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
10123      END IF;
10124      --
10125      IF l_debug_on THEN
10126          WSH_DEBUG_SV.push(l_module_name);
10127          --
10128          WSH_DEBUG_SV.log(l_module_name,'p_batch_id',p_batch_id);
10129      END IF;
10130      --
10131      IF INV_INTERFACED(p_batch_id) THEN
10132       --
10133       IF l_debug_on THEN
10134           WSH_DEBUG_SV.log(l_module_name,'Returning OM_INTERFACED');
10135           WSH_DEBUG_SV.pop(l_module_name);
10136       END IF;
10137       --
10138       RETURN OM_INTERFACED(p_batch_id);
10139      END IF;
10140      --
10141      IF l_debug_on THEN
10142         WSH_DEBUG_SV.log(l_module_name,'Return False');
10143         WSH_DEBUG_SV.pop(l_module_name);
10144      END IF;
10145      RETURN FALSE;
10146    END ALL_INTERFACED;
10147 
10148 
10149 --========================================================================
10150 -- FUNCTION  : INV_INTERFACED
10151 --                  If there are any lines in the batch that have not interfaced
10152 --                  to INV, return FALSE.
10153 --
10154 -- PARAMETERS: p_batch_id              ITS batch id.
10155 --
10156 -- COMMENT   :
10157 --
10158 --========================================================================
10159 
10160    FUNCTION INV_INTERFACED ( p_batch_id in number ) RETURN BOOLEAN  is
10161   -- bug 1714402: make sure lines aren't checked if they don't need interface.
10162   -- inv_interfaced_flag = 'X' means no need to get inv interfaced
10163 /* H integration: added 'WSH' to validate for inventory interface wrudge */
10164   CURSOR c_lines_not_interfaced(p_batch_id NUMBER) IS
10165    SELECT wdd.delivery_detail_id
10166    FROM   wsh_trip_stops wts,
10167          wsh_delivery_legs wdl,
10168          wsh_delivery_assignments_v wda,
10169          wsh_delivery_details wdd
10170    WHERE  wdd.inv_interfaced_flag IN ('N', 'P')
10171    AND   wts.batch_id = p_batch_id
10172    AND   wts.stop_location_id = wdd.ship_from_location_id
10173    AND   wts.stop_id = wdl.pick_up_stop_id
10174    AND   wdl.delivery_id = wda.delivery_id
10175    AND   wda.delivery_id IS NOT NULL
10176    AND   wda.delivery_detail_id = wdd.delivery_detail_id
10177    AND   wdd.source_code in ('OE','OKE', 'WSH','RTV')   -- RTV changes
10178         AND     wdd.released_status <> 'D'  /* H integration: wrudge */
10179    AND   nvl(wdd.LINE_DIRECTION , 'O') IN ('O', 'IO')   -- J Inbound Logistics jckwok
10180    AND   rownum = 1;
10181 
10182   l_temp NUMBER;
10183   flag   BOOLEAN;
10184 
10185 --
10186 l_debug_on BOOLEAN;
10187 --
10188 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'INV_INTERFACED';
10189 --
10190 BEGIN
10191   --
10192   --
10193   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
10194   --
10195   IF l_debug_on IS NULL
10196   THEN
10197       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
10198   END IF;
10199   --
10200   IF l_debug_on THEN
10201       WSH_DEBUG_SV.push(l_module_name);
10202       --
10203       WSH_DEBUG_SV.log(l_module_name,'p_batch_id',p_batch_id);
10204   END IF;
10205   --
10206   OPEN  c_lines_not_interfaced(P_batch_id);
10207   FETCH c_lines_not_interfaced INTO l_temp;
10208   flag  := c_lines_not_interfaced%NOTFOUND;
10209   CLOSE c_lines_not_interfaced;
10210   --
10211   IF l_debug_on THEN
10212       WSH_DEBUG_SV.log(l_module_name,' flag', flag);
10213       WSH_DEBUG_SV.pop(l_module_name);
10214   END IF;
10215   --
10216   RETURN flag;
10217 END  INV_INTERFACED ;
10218 
10219 
10220 --========================================================================
10221 -- FUNCTION  : OM_INTERFACED
10222 --                  If there are any lines in the batch that have not interfaced
10223 --                  to OM, return FALSE.
10224 --
10225 -- PARAMETERS: p_batch_id              ITS batch id.
10226 --
10227 -- COMMENT   :
10228 --
10229 --========================================================================
10230 
10231 FUNCTION OM_INTERFACED ( p_batch_id in number ) RETURN BOOLEAN  is
10232   CURSOR c_lines_not_interfaced(p_batch_id NUMBER) IS
10233    SELECT wdd.delivery_detail_id
10234    FROM   wsh_trip_stops wts,
10235          wsh_delivery_legs wdl,
10236          wsh_delivery_assignments_v wda,
10237          wsh_delivery_details wdd
10238    WHERE -- wdd.oe_interfaced_flag <> 'Y'
10239          wdd.oe_interfaced_flag NOT IN ( 'Y' ,'X')  --Standalone WMS project changes
10240    AND   wts.batch_id = p_batch_id
10241    AND   wts.stop_location_id = wdd.ship_from_location_id
10242    AND   wts.stop_id = wdl.pick_up_stop_id
10243    AND   wdl.delivery_id = wda.delivery_id
10244    AND   wda.delivery_id IS NOT NULL
10245    AND   wda.delivery_detail_id = wdd.delivery_detail_id
10246    AND   wdd.source_code = 'OE'
10247         AND     wdd.released_status <> 'D'  /* H integration: wrudge */
10248    AND   rownum = 1;
10249 
10250   l_temp NUMBER;
10251   flag   BOOLEAN;
10252 
10253 --
10254 l_debug_on BOOLEAN;
10255 --
10256 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'OM_INTERFACED';
10257 --
10258 BEGIN
10259   --
10260   --
10261   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
10262   --
10263   IF l_debug_on IS NULL
10264   THEN
10265       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
10266   END IF;
10267   --
10268   IF l_debug_on THEN
10269       WSH_DEBUG_SV.push(l_module_name);
10270       --
10271       WSH_DEBUG_SV.log(l_module_name,'p_batch_id',p_batch_id);
10272   END IF;
10273   --
10274   OPEN  c_lines_not_interfaced(p_batch_id);
10275   FETCH c_lines_not_interfaced INTO l_temp;
10276   flag  := c_lines_not_interfaced%NOTFOUND;
10277   CLOSE c_lines_not_interfaced;
10278   --
10279   IF l_debug_on THEN
10280       WSH_DEBUG_SV.log(l_module_name,'flag',flag);
10281       WSH_DEBUG_SV.pop(l_module_name);
10282   END IF;
10283   --
10284   RETURN flag;
10285 END  OM_INTERFACED ;
10286 
10287 
10288 --========================================================================
10289 -- PROCEDURE : Interface_ALL_wrp
10290 --                  This is the main wrapper for the concurrent program
10291 --                  interface trip stop SRS.
10292 --
10293 -- PARAMETERS: errbuf                  Used by the concurrent program for error
10294 --                                     messages.
10295 --             retcode                 Used by the concurrent program for return
10296 --                                     code.
10297 --             p_stop_id               Stop id to be interfaced.
10298 --             p_delivery_id           Delivery id to be interfaced.
10299 --             p_log_level             value 1 turns on the debug.
10300 --             p_batch_id              ship confirm batch used by concurrent
10301 --                                     program "Ship Confirm Deliveries SRS"
10302 --             p_trip_type             Used by concurrent program "Ship Confirm
10303 --                                     Deliveries SRS".
10304 --             p_organization_id       If p_stop_id and p_delivery_id are left
10305 --                                     blank use this parameter to interface all
10306 --                                     the stops within this organization.
10307 --             p_num_requests          Indicates the number of child requests
10308 --                                     that would run in parallel.
10309 --             p_stops_per_batch       Indicates the number of stops that can be
10310 --                                     marked by a batch and processed together.
10311 --
10312 -- COMMENT   : If p_num_requests is one ( cannot be smaller than one), then
10313 --             procedure interface_all is called to process the ITS.
10314 --             If p_num_requests is grater than one, then this API will create
10315 --             as many child processes as it is indicated by this parameter, and
10316 --             waits in the pause mode for all the children to be finished.
10317 --             Each child is spawned with p_num_requests set to one.
10318 --             If multiple child processes are run then the parent program will
10319 --             have a output file giving the summary of the results for each
10320 --             child.  If all children process successfully then the return
10321 --             status is success, else if all children errored out then return
10322 --             status is set as error, else set the return status as warning.
10323 --
10324 --========================================================================
10325 
10326 procedure interface_ALL_wrp(errbuf        OUT NOCOPY  VARCHAR2,
10327                         retcode       OUT NOCOPY  VARCHAR2,
10328                         p_mode        IN  VARCHAR2 DEFAULT 'ALL',
10329                         p_stop_id     IN  NUMBER   DEFAULT NULL,
10330                         p_delivery_id IN  NUMBER   DEFAULT NULL,
10331                         p_log_level   IN  NUMBER   DEFAULT 0,
10332                         p_batch_id IN NUMBER DEFAULT NULL,
10333                         p_trip_type IN VARCHAR2 DEFAULT NULL,
10334                         p_organization_id IN NUMBER DEFAULT NULL,
10335                         p_num_requests IN NUMBER DEFAULT NULL,
10336                         p_stops_per_batch IN NUMBER DEFAULT NULL) IS
10337 
10338    --
10339    l_debug_on BOOLEAN;
10340    --
10341    l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.'
10342                                                        || 'INTERFACE_ALL_WRP';
10343    --
10344    l_req_data               VARCHAR2(100);
10345    l_num_requests           NUMBER;
10346    l_child_req_ids          wsh_util_core.id_tab_type;
10347    l_request_id             NUMBER;
10348    l_this_request           NUMBER;
10349    j                        NUMBER;
10350    l_dummy                  BOOLEAN;
10351    l_errors                 NUMBER := 0;
10352    l_warnings               NUMBER := 0;
10353    l_completion_status      VARCHAR2(30);
10354    l_phase                  VARCHAR2(100);
10355    l_status                 VARCHAR2(100);
10356    l_dev_phase              VARCHAR2(100);
10357    l_dev_status             VARCHAR2(100);
10358    l_message                VARCHAR2(500);
10359    l_error_code number := NULL;
10360    l_error_text varchar2(2000) := NULL;
10361 
10362 
10363    CURSOR c_requests (p_parent_request_id NUMBER) IS
10364    SELECT request_id
10365    FROM FND_CONCURRENT_REQUESTS
10366    WHERE parent_request_id = p_parent_request_id;
10367    e_invalid_number   EXCEPTION;
10368 
10369 BEGIN
10370   --
10371   WSH_UTIL_CORE.Enable_Concurrent_Log_Print;
10372   WSH_UTIL_CORE.Set_Log_Level(p_log_level);
10373   --
10374   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
10375   --
10376   IF l_debug_on IS NULL
10377   THEN
10378       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
10379   END IF;
10380   --
10381   IF l_debug_on THEN
10382       WSH_DEBUG_SV.push(l_module_name);
10383       --
10384       WSH_DEBUG_SV.log(l_module_name,'P_MODE',P_MODE);
10385       WSH_DEBUG_SV.log(l_module_name,'P_STOP_ID',P_STOP_ID);
10386       WSH_DEBUG_SV.log(l_module_name,'P_DELIVERY_ID',P_DELIVERY_ID);
10387       WSH_DEBUG_SV.log(l_module_name,'P_LOG_LEVEL',P_LOG_LEVEL);
10388       WSH_DEBUG_SV.log(l_module_name,'p_organization_id',p_organization_id);
10389       WSH_DEBUG_SV.log(l_module_name,'p_num_requests',p_num_requests);
10390       WSH_DEBUG_SV.log(l_module_name,'p_stops_per_batch',p_stops_per_batch);
10391   END IF;
10392   --
10393   l_completion_status := 'NORMAL';
10394 
10395   l_num_requests := NVL(p_num_requests,1);
10396   IF l_num_requests = 0 THEN
10397      l_num_requests := 1;
10398   ELSIF l_num_requests < 0 THEN
10399      IF l_debug_on THEN
10400          WSH_DEBUG_SV.log(l_module_name,'Number of requests cannot be negative'
10401                                                               ,l_num_requests);
10402      END IF;
10403      RAISE e_invalid_number;
10404   END IF;
10405 
10406   l_req_data := FND_CONC_GLOBAL.request_data ;
10407   IF l_debug_on THEN
10408       WSH_DEBUG_SV.log(l_module_name,'l_req_data',l_req_data);
10409   END IF;
10410 
10411   IF (l_req_data IS NULL) THEN
10412      IF (l_num_requests > 1)THEN --{
10413        FOR i IN 1..l_num_requests LOOP
10414         l_request_id := FND_REQUEST.submit_Request(
10415                                       application => 'WSH',
10416                                       program => 'WSHINTERFACES',
10417                                       sub_request => TRUE,
10418                                       argument1 =>p_mode,
10419                                       argument2 =>p_stop_id,
10420                                       argument3 =>p_delivery_id,
10421                                       argument4 =>p_log_level,
10422                                       argument5 =>p_batch_id,
10423                                       argument6 =>p_trip_type,
10424                                       argument7 =>p_organization_id,
10425                                       argument8 =>1 ,-- l_num_requests
10426                                       argument9 => p_stops_per_batch
10427         );
10428 
10429         IF l_debug_on THEN
10430             WSH_DEBUG_SV.log(l_module_name,'child request',l_request_id);
10431         END IF;
10432 
10433        END LOOP;
10434        fnd_conc_global.set_req_globals(conc_status  => 'PAUSED',
10435                                  request_data => to_char(l_num_requests));
10436     ELSE --}{
10437      interface_ALL(
10438                    errbuf => errbuf,
10439                    retcode => retcode,
10440                    p_mode  => p_mode,
10441                    p_stop_id => p_stop_id,
10442                    p_delivery_id => p_delivery_id,
10443                    p_log_level => p_log_level,
10444                    p_batch_id => p_batch_id,
10445                    p_trip_type => p_trip_type,
10446                    p_organization_id => p_organization_id,
10447                    p_stops_per_batch => p_stops_per_batch);
10448     END IF; --}
10449   END IF;
10450 
10451   IF (l_req_data IS NOT NULL) AND (l_num_requests > 1)THEN --{
10452      --set the l_completion_status based on the other programs
10453      FND_PROFILE.Get('CONC_REQUEST_ID', l_this_request);
10454      OPEN c_requests(l_this_request);
10455      FETCH c_requests BULK COLLECT INTO l_child_req_ids;
10456      CLOSE c_requests;
10457 
10458      j := l_child_req_ids.FIRST;
10459      WHILE j IS NOT NULL LOOP
10460         l_dev_status := NULL;
10461         l_dummy := FND_CONCURRENT.get_request_status(
10462                                      request_id => l_child_req_ids(j),                                               phase      => l_phase,
10463                                      status     => l_status,
10464                                      dev_phase  => l_dev_phase,
10465                                      dev_status => l_dev_status,
10466                                      message    => l_message);
10467 
10468         IF l_dev_status = 'WARNING' THEN
10469            l_warnings:= l_warnings + 1;
10470         ELSIF l_dev_status <> 'NORMAL' THEN
10471            l_errors := l_errors + 1;
10472         END IF;
10473         IF l_debug_on THEN
10474              WSH_DEBUG_SV.log(l_module_name,'l_dev_status',l_dev_status);
10475              WSH_DEBUG_SV.log(l_module_name,'l_child_req_id'
10476                                                         ,l_child_req_ids(j));
10477         END IF;
10478 
10479         FND_MESSAGE.SET_NAME('WSH','WSH_CHILD_REQ_STATUS');
10480         FND_MESSAGE.SET_TOKEN('REQ_ID', to_char(l_child_req_ids(j)));
10481         FND_MESSAGE.SET_TOKEN('STATUS', l_status);
10482         FND_FILE.put_line(FND_FILE.output,FND_MESSAGE.GET);
10483 
10484         j := l_child_req_ids.NEXT(j);
10485      END LOOP;
10486 
10487      IF l_errors = 0  AND l_warnings = 0 THEN
10488         l_completion_status := 'NORMAL';
10489      ELSIF (l_errors > 0 ) AND (l_errors  = l_child_req_ids.count )  THEN
10490         l_completion_status := 'ERROR';
10491      ELSE
10492         l_completion_status := 'WARNING';
10493      END IF;
10494 
10495      l_dummy := FND_CONCURRENT.SET_COMPLETION_STATUS(l_completion_status,'');
10496 
10497      IF l_completion_status = 'NORMAL' THEN
10498        errbuf := 'Interface trip stop is completed successfully';
10499        retcode := '0';
10500      ELSIF l_completion_status = 'WARNING' THEN
10501        errbuf := 'Interface trip stop is  completed with warning';
10502        retcode := '1';
10503      ELSE
10504        errbuf := 'Interface trip stop  is completed with error';
10505        retcode := '2';
10506      END IF;
10507      --
10508   END IF; --}
10509 
10510   IF l_debug_on THEN
10511       WSH_DEBUG_SV.log(l_module_name,'errbuf',errbuf);
10512       WSH_DEBUG_SV.log(l_module_name,'retcode',retcode);
10513       WSH_DEBUG_SV.log(l_module_name,'l_completion_status',l_completion_status);
10514       WSH_DEBUG_SV.pop(l_module_name);
10515   END IF;
10516   --
10517 
10518   EXCEPTION
10519     WHEN e_invalid_number THEN
10520        l_completion_status := 'ERROR';
10521        l_error_code     := SQLCODE;
10522        l_error_text     := SQLERRM;
10523        l_dummy := FND_CONCURRENT.SET_COMPLETION_STATUS(l_completion_status,'');
10524        errbuf := 'Interface trip stop failed with unexpected error';
10525        retcode := '2';
10526        --
10527        IF l_debug_on THEN
10528            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:e_invalid_number');
10529        END IF;
10530        --
10531     WHEN OTHERS THEN
10532        l_completion_status := 'ERROR';
10533        l_error_code     := SQLCODE;
10534        l_error_text     := SQLERRM;
10535        WSH_UTIL_CORE.PrintMsg('Interface_ALL_wrp failed with unexpected error.');
10536        WSH_UTIL_CORE.PrintMsg('The unexpected error is ' || l_error_text);
10537        l_dummy := FND_CONCURRENT.SET_COMPLETION_STATUS(l_completion_status,'');
10538        errbuf := 'Interface trip stop failed with unexpected error';
10539        retcode := '2';
10540        --
10541        IF l_debug_on THEN
10542            WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
10543            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
10544        END IF;
10545        --
10546 END interface_ALL_wrp;
10547 
10548 --Standalone WMS project New API
10549 --========================================================================
10550 -- PROCEDURE : Process_Delivery_To_OM
10551 --                  Procedure to interface delvieries to OM
10552 --
10553 -- PARAMETERS: delivery_id             Delivery_id need to be interfaced
10554 --             x_return_status         return status of the API.
10555 --
10556 -- COMMENT   : This API is created to be used only by Standalone code.
10557 --             API will interfaces the delivery passed to OM only if
10558 --             the delivery is completely shipped or shipped within tolerances.
10559 --             For tolerance case remaining delivery details will be cancelled
10560 --========================================================================
10561 PROCEDURE Process_Delivery_To_OM ( p_delivery_id  IN NUMBER,
10562                                    x_return_status OUT NOCOPY VARCHAR2)IS
10563 
10564   l_debug_on    BOOLEAN;
10565   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.'|| G_PKG_NAME || '.'|| 'Process_Delivery_To_OM';
10566   l_return_status       VARCHAR2(1);
10567   l_summary             VARCHAR2(3000);
10568   l_num_warnings        VARCHAR2(3000);
10569   l_num_errors          VARCHAR2(3000);
10570   l_ship_beyond_flag    VARCHAR2(1);
10571   l_fulfilled_flag      VARCHAR2(1);
10572   l_remain_detail_index NUMBER;
10573   l_remain_details_id WSH_UTIL_CORE.Id_Tab_Type ;
10574 
10575   --This cursor should fetch only one records per order line
10576   --Get total_requested_quantity and total_shipped_quantity for the order line
10577   --This cursor type should match with WSH_SHIP_CONFIRM_ACTIONS.oe_interface_rec
10578 
10579   /*Get all the details at order line level of the delivery passed which are shipped and not interfaced to OM */
10580   CURSOR c_get_oe_interface_line_detail(c_delivery_id NUMBER)  IS
10581    SELECT dd.source_header_id ,
10582          dd.source_header_number,
10583          NULL source_line_set_id,
10584          dd.source_line_id,
10585          WSH_WV_UTILS.CONVERT_UOM(ol.order_quantity_uom,
10586                      dd.requested_quantity_uom,
10587                      ol.ordered_quantity,
10588                      dd.inventory_item_id) order_line_quantity,
10589          -- muom
10590          ol.ordered_quantity2 order_line_quantity2,
10591          dd.requested_quantity_uom,
10592          NULL requested_quantity_uom2,
10593          ol.ordered_quantity,
10594          ol.order_quantity_uom,
10595          NULL ordered_quantity2,
10596          NULL ordered_quantity_uom2,
10597          NULL model_remnant_flag,
10598          ol.item_type_code,
10599          ol.calculate_price_flag,
10600          dd.ship_tolerance_below,
10601          dd.ship_tolerance_above,
10602          NULL org_id,
10603          dd.organization_id,
10604          NVL(dd.oe_interfaced_flag,'X') oe_interfaced_flag,
10605          NULL initial_pickup_date ,
10606          NULL top_model_line_id,
10607          NULL ato_line_id ,
10608          NULL ship_set_id ,
10609          NULL ship_model_complete_flag  ,
10610          NULL arrival_set_id,
10611          dd.inventory_item_id,
10612          ol.flow_status_code,
10613          SUM( dd.requested_quantity ) total_requested_quantity ,
10614          NULL total_requested_quantity2,
10615          SUM( NVL(dd.shipped_quantity, 0 )) total_shipped_quantity,
10616          NULL total_shipped_quantity2,
10617          -- muom
10618          NULL total_om_shipped_quantity
10619   FROM   wsh_delivery_Details dd ,
10620          oe_order_lines_all ol
10621   WHERE  dd.source_line_id = ol.line_id
10622     AND  dd.released_status = 'C'
10623     AND  dd.source_code = 'OE'
10624     AND  ol.shipped_quantity IS NULL
10625     AND  dd.source_line_id IN
10626          ( SELECT DISTINCT dd1.source_line_id
10627            FROM   wsh_delivery_details dd1      ,
10628                   wsh_delivery_assignments_v da
10629            WHERE  da.delivery_id = c_delivery_id
10630              AND  da.delivery_detail_id  = dd1.delivery_detail_id
10631              AND  NVL(dd1.oe_interfaced_flag,'X') = 'X'
10632              AND  dd1.source_code = 'OE'
10633              AND  dd1.released_status = 'C')
10634   GROUP BY  dd.source_header_id,
10635             dd.source_header_number,
10636             dd.source_line_id,
10637             ol.ordered_quantity,
10638             dd.requested_quantity_uom,
10639             ol.ordered_quantity,
10640             ol.order_quantity_uom,
10641             dd.inventory_item_id,
10642             ol.item_type_code,
10643             ol.calculate_price_flag,
10644             dd.ship_tolerance_below,
10645             dd.ship_tolerance_above,
10646             dd.organization_id,
10647             NVL(dd.oe_interfaced_flag, 'X') ,
10648             ol.flow_status_code
10649   ORDER BY  dd.organization_id ,
10650             dd.source_line_id ;
10651 
10652   line_rec wsh_ship_confirm_actions.oe_interface_rec;
10653   l_over_reason varchar2(1);
10654   l_delete_detail_id NUMBER;
10655   line_id_tab wsh_util_core.id_tab_type;
10656   i NUMBER :=0;
10657   line_locked     EXCEPTION;
10658   PRAGMA EXCEPTION_INIT(line_locked, -54);
10659 
10660 BEGIN
10661 
10662     l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
10663     IF l_debug_on IS NULL THEN
10664         l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
10665     END IF;
10666 
10667     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
10668 
10669     IF l_debug_on THEN
10670         WSH_DEBUG_SV.push(l_module_name);
10671         WSH_DEBUG_SV.log(l_module_name,'delivery_id ',p_delivery_id);
10672         WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DELIVERY_DETAILS_PKG.Lock_Detail_No_Compare',WSH_DEBUG_SV.C_PROC_LEVEL);
10673     END IF;
10674 
10675     SAVEPOINT l_cancel_wdd;
10676 
10677     --This API will lock the associated delivery details
10678     wsh_delivery_details_pkg.lock_detail_no_compare(p_delivery_id =>  p_delivery_id);
10679 
10680     /*Get all the details at order line level of the delivery passed which are shipped and not interfaced to OM */
10681     OPEN c_get_oe_interface_line_detail(p_delivery_id);
10682     LOOP
10683     --{
10684         FETCH c_get_oe_interface_line_detail into line_rec;
10685         EXIT WHEN c_get_oe_interface_line_detail%NOTFOUND;
10686 
10687         IF l_debug_on THEN
10688             WSH_DEBUG_SV.logmsg(l_module_name, 'Inside line rec loop : line_id '|| line_rec.source_line_id);
10689         END IF;
10690 
10691         i := i + 1;
10692         line_id_tab(i) := line_rec.source_line_id ;
10693 
10694         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_SHIP_CONFRIM_ACTIONS.Handle_Tolerances',WSH_DEBUG_SV.C_PROC_LEVEL);
10695 
10696         /*Check the tolerances and cancel the delivery details ,if tolerances are met*/
10697         Handle_Tolerances ( p_batch_id => NULL,
10698                             p_oe_interface_rec => line_rec,
10699                             x_fulfilled_flag => l_fulfilled_flag,
10700                             x_over_reason => l_over_reason,
10701                             x_return_status => l_return_status);
10702 
10703         IF l_debug_on THEN
10704            WSH_DEBUG_SV.log(l_module_name,'Return status after calling WSH_SHIP_CONFRIM_ACTIONS.Handle_Tolerances ',l_return_status);
10705         END IF;
10706 
10707         WSH_UTIL_CORE.api_post_call(  p_return_status => l_return_status,
10708                                       x_num_warnings =>l_num_warnings,
10709                                       x_num_errors =>l_num_errors);
10710     --}
10711     END LOOP;
10712     CLOSE c_get_oe_interface_line_detail;
10713 
10714     --Interfaces lines to OM
10715     IF (line_id_tab.count > 0 ) THEN
10716     --{
10717          IF l_debug_on THEN
10718            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_SHIP_CONFIRM_ACTIONS.Process_lines_To_OM', WSH_DEBUG_SV.C_PROC_LEVEL);
10719          END IF;
10720 
10721          /*Interface the delivery details to OM*/
10722          Process_lines_To_OM(p_line_id_tab =>line_id_tab,
10723                                 x_return_status => l_return_status);
10724 
10725          IF l_debug_on THEN
10726             WSH_DEBUG_SV.logmsg(l_module_name, 'After program unit Process_lines_To_OM l_return_status ' || l_return_status );
10727          END IF;
10728 
10729          WSH_UTIL_CORE.api_post_call(p_return_status => l_return_status, x_num_warnings =>l_num_warnings, x_num_errors =>l_num_errors);
10730     --}
10731     ELSE
10732     --{
10733          IF l_debug_on THEN
10734              WSH_DEBUG_SV.logmsg(l_module_name, '*****No eligible lines found in the delivery to interface******');
10735          END IF;
10736     --}
10737     END IF;
10738 
10739     IF ( l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS ) THEN
10740         x_return_status := l_return_status;
10741     END IF;
10742 
10743     IF l_debug_on THEN
10744       WSH_DEBUG_SV.pop(l_module_name);
10745     END IF;
10746 
10747 EXCEPTION
10748    WHEN line_locked  THEN
10749         wsh_util_core.printMsg('Error: Failure to Accrue the Lock ,Please try after sometime');
10750         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
10751 
10752         IF c_get_oe_interface_line_detail%ISOPEN THEN
10753            close c_get_oe_interface_line_detail;
10754         END IF;
10755 
10756         ROLLBACK TO SAVEPOINT l_cancel_wdd;
10757         IF l_debug_on THEN
10758            WSH_DEBUG_SV.logmsg(l_module_name,'Rollback to savepoint l_cancel_wdd');
10759            WSH_DEBUG_SV.logmsg(l_module_name,'LINE_LOCKED exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
10760            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:LINE_LOCKED');
10761         END IF;
10762 
10763    WHEN OTHERS THEN
10764         x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
10765         wsh_util_core.printMsg('API Process_Delivery_To_OM failed with an unexpected error');
10766         WSH_UTIL_CORE.PrintMsg('The unexpected error is '|| sqlerrm);
10767 
10768         IF c_get_oe_interface_line_detail%ISOPEN THEN
10769           close c_get_oe_interface_line_detail;
10770         END IF;
10771 
10772         ROLLBACK TO SAVEPOINT l_cancel_wdd;
10773         IF l_debug_on THEN
10774            WSH_DEBUG_SV.logmsg(l_module_name,'Rollback to savepoint l_cancel_wdd');
10775            WSH_DEBUG_SV.logmsg(l_module_name, 'UNEXPECTED ERROR IN WSH_Process_Stop_To_OM' );
10776            WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
10777            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
10778          END IF;
10779 
10780 END Process_delivery_To_OM;
10781 
10782 --Standalone WMS project New API
10783 --========================================================================
10784 -- PROCEDURE : Process_lines_to_om
10785 --                  Procedure to interface completely shipped lines to OM
10786 --
10787 -- PARAMETERS: line_id_tab             table of line_ids need to be interfaced
10788 --             x_return_status         return status of the API.
10789 --
10790 -- COMMENT   : This API is created to be called only from Standalone code
10791 --             API interfaces the lines passed to OM only if there are no
10792 --             unshipped wdd remaining for the order line.
10793 --               -If complete quantity is shipped then BUlk mode variable are popualted
10794 --                AND/OR
10795 --               -If line is shipped within tolerances then Non BUlk mode variable are
10796 --                   popualted
10797 --             Based on Bulk and Non bulk varaiables OM API will be called in Bulk and
10798 --	           Non Bulk mode.
10799 ----========================================================================
10800 PROCEDURE Process_Lines_To_OM (p_line_id_tab     IN wsh_util_core.id_tab_type ,
10801                                   x_return_status OUT NOCOPY VARCHAR2)IS
10802   l_debug_on    BOOLEAN;
10803   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.'|| G_PKG_NAME || '.'|| 'Process_lines_To_OM';
10804   l_return_status       VARCHAR2(1);
10805   x_msg_count           NUMBER;
10806   x_msg_data            VARCHAR2(3000);
10807   l_error_count         NUMBER:=0;
10808   l_end_index           NUMBER;
10809   l_start_index         NUMBER;
10810   l_row_count           NUMBER;
10811   l_end_index_nonbulk   NUMBER;
10812   l_start_index_nonbulk NUMBER;
10813   l_row_count_nonbulk   NUMBER;
10814   l_bulk_ship_line OE_Ship_Confirmation_Pub.Ship_Line_Rec_Type;
10815   l_non_bulk_ship_line OE_Ship_Confirmation_Pub.Ship_Line_Rec_Type;
10816   p_bulk_req_line OE_Ship_Confirmation_Pub.Ship_Line_Rec_Type;
10817   l_ship_adj_line OE_Ship_Confirmation_Pub.Ship_Adj_Rec_Type;
10818   i NUMBER:=0;
10819 
10820   /* Cursor should fetch the order lines which have ONLY shipped delivery details */
10821   CURSOR c_get_line_detail_to_interface(c_line_id NUMBER)  IS
10822   SELECT dd.source_header_id,
10823          dd.source_header_number  ,
10824          dd.source_line_id ,
10825          ol.ordered_quantity ,
10826          dd.requested_quantity_uom,
10827          ol.order_quantity_uom ,
10828          dd.inventory_item_id,
10829          ol.item_type_code  ,
10830          ol.org_id  ,
10831          ol.calculate_price_flag ,
10832          dd.ship_tolerance_below,
10833          dd.ship_tolerance_above   ,
10834          dd.organization_id  ,
10835          NVL(dd.oe_interfaced_flag, 'X') oe_interfaced_flag  ,
10836          ol.flow_status_code  ,
10837          SUM( dd.requested_quantity ) total_requested_quantity ,
10838          SUM( NVL(dd.shipped_quantity, 0 )) total_shipped_quantity
10839   FROM   wsh_delivery_Details dd ,
10840          oe_order_lines_all ol
10841   WHERE  dd.source_line_id  = ol.line_id
10842      AND dd.released_status = 'C'
10843      AND dd.source_line_id  = c_line_id
10844      AND dd.source_code = 'OE'
10845      and ol.shipped_quantity is NULL
10846      AND NOT EXISTS
10847          ( SELECT 'X'
10848            FROM   wsh_delivery_details wdd2
10849            WHERE  wdd2.source_line_id   = dd.source_line_id
10850              AND  wdd2.source_code = 'OE'
10851              AND  wdd2.released_status IN ( 'R','B','S','Y','X'))
10852   GROUP BY dd.source_header_id ,
10853          dd.source_header_number ,
10854          dd.source_line_id ,
10855          ol.ordered_quantity ,
10856          dd.requested_quantity_uom ,
10857          ol.ordered_quantity ,
10858          ol.order_quantity_uom ,
10859          dd.inventory_item_id ,
10860          ol.item_type_code ,
10861          ol.org_id ,
10862          ol.calculate_price_flag ,
10863          dd.ship_tolerance_below ,
10864          dd.ship_tolerance_above ,
10865          dd.organization_id ,
10866          NVL(dd.oe_interfaced_flag, 'X') ,
10867          ol.flow_status_code
10868    ORDER BY dd.organization_id ,
10869             dd.source_line_id ;
10870 
10871   line_rec c_get_line_detail_to_interface%ROWTYPE;
10872   l_over_reason VARCHAR2(1);
10873   j NUMBER :=0;
10874   k NUMBER :=0;
10875   l_pick_up_date DATE;
10876   l_loop_count NUMBER;
10877 
10878 BEGIN
10879     l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
10880     IF l_debug_on IS NULL THEN
10881             l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
10882     END IF;
10883 
10884     IF l_debug_on THEN
10885         WSH_DEBUG_SV.push(l_module_name);
10886         WSH_DEBUG_SV.log(l_module_name,'line_id_tab.count',P_line_id_tab.count);
10887         WSH_DEBUG_SV.logmsg(l_module_name, 'Get lines to interface - Start loop');
10888     END IF;
10889 
10890     l_bulk_ship_line.line_id.DELETE;
10891     l_non_bulk_ship_line.line_id.DELETE;
10892     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
10893 
10894     --If tolerances are met remaining quantity should have been cancelled till this point
10895 
10896     /*Process Order lines one by one*/
10897     FOR k IN 1..P_line_id_tab.count
10898     LOOP
10899     --{
10900         IF l_debug_on THEN
10901            WSH_DEBUG_SV.logmsg(l_module_name, '=======================');
10902            WSH_DEBUG_SV.logmsg(l_module_name, 'Before line rec line_id' || P_line_id_tab(k));
10903         END IF;
10904 
10905         /*Get the order lines which have only shipped delivery details*/
10906         OPEN c_get_line_detail_to_interface(P_line_id_tab(k));
10907         FETCH c_get_line_detail_to_interface
10908         INTO  line_rec;
10909 
10910         IF c_get_line_detail_to_interface%NOTFOUND THEN
10911             IF l_debug_on THEN
10912                 WSH_DEBUG_SV.logmsg(l_module_name, 'Line not eligible to interface');
10913             END IF;
10914             GOTO loop_end;
10915         END IF;
10916 
10917         IF l_debug_on THEN
10918             WSH_DEBUG_SV.logmsg(l_module_name, 'After line rec line_id ' || line_rec.source_line_id);
10919         END IF;
10920 
10921         --Get initial pick up date for the line.
10922         BEGIN
10923         --{
10924             SELECT initial_pickup_date
10925             INTO  l_pick_up_date
10926             FROM  wsh_delivery_details wdd    ,
10927                   wsh_delivery_assignments wda,
10928                   wsh_new_deliveries wnd
10929             WHERE wdd.source_line_id     = line_rec.source_line_id
10930               AND wda.delivery_detail_id = wdd.delivery_detail_id
10931               AND wnd.delivery_id        = wda.delivery_id
10932               AND ROWNUM =1;
10933 
10934             IF l_debug_on THEN
10935                 WSH_DEBUG_SV.log(l_module_name,'l_pick_up_date',l_pick_up_date);
10936             END IF;
10937         --}
10938         END;
10939 
10940         --for full quantity shipped ,popualate bulk mode variable
10941         IF ( WSH_WV_UTILS.CONVERT_UOM( line_rec.order_quantity_uom, line_rec.requested_quantity_uom, line_rec.ordered_quantity, line_rec.inventory_item_id) = line_rec.total_shipped_quantity ) THEN
10942         --{
10943             IF l_debug_on THEN
10944                 WSH_DEBUG_SV.logmsg(l_module_name, 'Total quantity shipped interface to OM');
10945                 WSH_DEBUG_SV.log(l_module_name,'line_rec.total_ordered_quantity',line_rec.ordered_quantity);
10946                 WSH_DEBUG_SV.log(l_module_name,'line_rec.total_requested_quantity',line_rec.total_requested_quantity);
10947                 WSH_DEBUG_SV.log(l_module_name,'line_rec.total_shipped_quantity',line_rec.total_shipped_quantity);
10948                 WSH_DEBUG_SV.logmsg(l_module_name, 'Populate bulk varaible');
10949                 WSH_DEBUG_SV.log(l_module_name,'source_header_id',line_rec.source_header_id);
10950                 WSH_DEBUG_SV.log(l_module_name,'source_line_id',line_rec.source_line_id);
10951                 WSH_DEBUG_SV.log(l_module_name,'initial_pickup_date',l_pick_up_date);
10952                 WSH_DEBUG_SV.log(l_module_name,'initial_pickup_date',line_rec.flow_status_code);
10953                 WSH_DEBUG_SV.log(l_module_name,'requested_quantity_uom',line_rec.requested_quantity_uom);
10954                 WSH_DEBUG_SV.log(l_module_name,'ordered_quantity',line_rec.ordered_quantity);
10955                 WSH_DEBUG_SV.log(l_module_name,'total_shipped_quantity',line_rec.total_shipped_quantity);
10956                 WSH_DEBUG_SV.log(l_module_name,'org_id',line_rec.org_id);
10957             END IF;
10958             i := i+1;
10959             l_bulk_ship_line.header_id.extend;
10960             l_bulk_ship_line.header_id(i):= line_rec.source_header_id;
10961             l_bulk_ship_line.line_id.extend;
10962             l_bulk_ship_line.line_id(i):= line_rec.source_line_id;
10963             l_bulk_ship_line.top_model_line_id.extend;
10964             l_bulk_ship_line.top_model_line_id(i):= NULL;
10965             l_bulk_ship_line.ship_set_id.extend;
10966             l_bulk_ship_line.ship_set_id(i):= NULL;
10967             l_bulk_ship_line.arrival_set_id.extend;
10968             l_bulk_ship_line.arrival_set_id(i):= NULL;
10969             l_bulk_ship_line.actual_shipment_date.extend;
10970             l_bulk_ship_line.actual_shipment_date(i):=NVL(l_pick_up_date,sysdate);
10971             l_bulk_ship_line.shipping_quantity_uom.extend;
10972             l_bulk_ship_line.shipping_quantity_uom(i):= line_rec.requested_quantity_uom;
10973             l_bulk_ship_line.shipping_quantity_uom2.extend;
10974             l_bulk_ship_line.shipping_quantity_uom2(i):=NULL;
10975             l_bulk_ship_line.flow_status_code.extend;
10976             l_bulk_ship_line.flow_status_code(i):= line_rec.flow_status_code;
10977             l_bulk_ship_line.ordered_quantity.extend;
10978             l_bulk_ship_line.ordered_quantity(i):= line_rec.ordered_quantity;
10979             l_bulk_ship_line.shipping_quantity.extend;
10980             l_bulk_ship_line.shipping_quantity(i):= line_rec.total_shipped_quantity;
10981             l_bulk_ship_line.shipping_quantity2.extend;
10982             l_bulk_ship_line.shipping_quantity2(i):= NULL ;
10983             l_bulk_ship_line.org_id.extend;
10984             l_bulk_ship_line.org_id(i):= line_rec.org_id;
10985             l_bulk_ship_line.ordered_quantity2.extend;
10986             l_bulk_ship_line.ordered_quantity2(i):= NULL;
10987         --}
10988         --line is shipped within tolerances ,popualate non bulk mode variable
10989         ELSIF ((NVL(line_rec.ship_tolerance_above,0) > 0) OR
10990                 (NVL(line_rec.ship_tolerance_below,0) > 0))THEN
10991         --{
10992             IF l_debug_on THEN
10993                 WSH_DEBUG_SV.logmsg(l_module_name, 'Tolearance case');
10994                 WSH_DEBUG_SV.log(l_module_name,'total shipped quantity',line_rec.total_shipped_quantity);
10995                 WSH_DEBUG_SV.log(l_module_name,'ordered_quantity',line_rec.ordered_quantity);
10996                 WSH_DEBUG_SV.log(l_module_name,'line_rec.ship_tolerance_below',line_rec.ship_tolerance_below);
10997                 WSH_DEBUG_SV.log(l_module_name,'line_rec.ship_tolerance_above',line_rec.ship_tolerance_above);
10998                 WSH_DEBUG_SV.logmsg(l_module_name, 'Populate non bulk varaible');
10999                 WSH_DEBUG_SV.log(l_module_name,'source_header_id',line_rec.source_header_id);
11000                 WSH_DEBUG_SV.log(l_module_name,'source_line_id',line_rec.source_line_id);
11001                 WSH_DEBUG_SV.log(l_module_name,'initial_pickup_date',l_pick_up_date);
11002                 WSH_DEBUG_SV.log(l_module_name,'requested_quantity_uom',line_rec.requested_quantity_uom);
11003                 WSH_DEBUG_SV.log(l_module_name,'inventory_item_id',line_rec.inventory_item_id );
11004                 WSH_DEBUG_SV.log(l_module_name,'flow_status_code',line_rec.flow_status_code);
11005                 WSH_DEBUG_SV.log(l_module_name,'ordered_quantity',line_rec.ordered_quantity);
11006                 WSH_DEBUG_SV.log(l_module_name,'total_shipped_quantity',line_rec.total_shipped_quantity);
11007                 WSH_DEBUG_SV.log(l_module_name,'organization_id',line_rec.organization_id);
11008                 WSH_DEBUG_SV.log(l_module_name,'org_id',line_rec.org_id);
11009                 WSH_DEBUG_SV.log(l_module_name,'item_type_code',line_rec.item_type_code);
11010                 WSH_DEBUG_SV.log(l_module_name,'item_type_code',line_rec.calculate_price_flag);
11011             END IF;
11012 
11013             j := j+1;
11014             l_non_bulk_ship_line.header_id.extend;
11015             l_non_bulk_ship_line.header_id(j):= line_rec.source_header_id;
11016             l_non_bulk_ship_line.line_id.extend;
11017             l_non_bulk_ship_line.line_id(j):= line_rec.source_line_id;
11018             l_non_bulk_ship_line.top_model_line_id.extend;
11019             l_non_bulk_ship_line.top_model_line_id(j):= NULL;
11020             l_non_bulk_ship_line.ato_line_id.extend;
11021             l_non_bulk_ship_line.ato_line_id(j):= NULL;
11022             l_non_bulk_ship_line.item_type_code.extend;
11023             l_non_bulk_ship_line.item_type_code(j):= line_rec.item_type_code;
11024             l_non_bulk_ship_line.ship_set_id.extend;
11025             l_non_bulk_ship_line.ship_set_id(j):= NULL;
11026             l_non_bulk_ship_line.arrival_set_id.extend;
11027             l_non_bulk_ship_line.arrival_set_id(j):= NULL;
11028             l_non_bulk_ship_line.line_set_id.extend;
11029             l_non_bulk_ship_line.line_set_id(j):= NULL;
11030             l_non_bulk_ship_line.smc_flag.extend;
11031             l_non_bulk_ship_line.smc_flag(j):= NULL;
11032             l_non_bulk_ship_line.over_ship_reason_code.extend;
11033             l_non_bulk_ship_line.over_ship_reason_code(j):= NULL;
11034             l_non_bulk_ship_line.pending_quantity.extend;
11035             l_non_bulk_ship_line.pending_quantity(j):= NULL;
11036             l_non_bulk_ship_line.pending_quantity2.extend;
11037             l_non_bulk_ship_line.pending_quantity2(j):= NULL;
11038             l_non_bulk_ship_line.pending_requested_flag.extend;
11039             l_non_bulk_ship_line.pending_requested_flag(j):= NULL;
11040             l_non_bulk_ship_line.actual_shipment_date.extend;
11041             l_non_bulk_ship_line.actual_shipment_date(j):=NVL(l_pick_up_date,sysdate);
11042             l_non_bulk_ship_line.shipping_quantity_uom.extend;
11043             l_non_bulk_ship_line.shipping_quantity_uom(j):= line_rec.requested_quantity_uom;
11044             l_non_bulk_ship_line.shipping_quantity_uom2.extend;
11045             l_non_bulk_ship_line.shipping_quantity_uom2(j):=NULL;
11046             l_non_bulk_ship_line.inventory_item_id.extend;
11047             l_non_bulk_ship_line.inventory_item_id(j):=NULL;
11048             l_non_bulk_ship_line.flow_status_code.extend;
11049             l_non_bulk_ship_line.flow_status_code(j):= line_rec.flow_status_code;
11050             l_non_bulk_ship_line.ordered_quantity.extend;
11051             l_non_bulk_ship_line.ordered_quantity(j):= line_rec.ordered_quantity;
11052             l_non_bulk_ship_line.shipping_quantity.extend;
11053             l_non_bulk_ship_line.shipping_quantity(j):= line_rec.total_shipped_quantity;
11054             l_non_bulk_ship_line.shipping_quantity2.extend;
11055             l_non_bulk_ship_line.shipping_quantity2(j):= NULL ;
11056             l_non_bulk_ship_line.ship_from_org_id.extend;
11057             l_non_bulk_ship_line.ship_from_org_id(j):= line_rec.organization_id;
11058             l_non_bulk_ship_line.org_id.extend;
11059             l_non_bulk_ship_line.org_id(j):= line_rec.org_id;
11060             l_non_bulk_ship_line.ordered_quantity2.extend;
11061             l_non_bulk_ship_line.ordered_quantity2(j):= NULL;
11062             l_non_bulk_ship_line.order_quantity_uom.extend;
11063             l_non_bulk_ship_line.order_quantity_uom(j):= line_rec.order_quantity_uom;
11064             l_non_bulk_ship_line.order_quantity_uom2.extend;
11065             l_non_bulk_ship_line.order_quantity_uom2(j):= NULL;
11066             l_non_bulk_ship_line.model_remnant_flag.extend;
11067             l_non_bulk_ship_line.model_remnant_flag(j):= NULL;
11068             l_non_bulk_ship_line.item_type_code.extend;
11069             l_non_bulk_ship_line.item_type_code(j):= NULL;
11070             l_non_bulk_ship_line.calculate_price_flag.extend;
11071             l_non_bulk_ship_line.calculate_price_flag(j):= NULL;
11072             l_non_bulk_ship_line.fulfilled_flag.extend;
11073             l_non_bulk_ship_line.fulfilled_flag(j):= 'Y'; --Should always be Y as we don't want order line to split
11074         --}
11075         END IF;
11076         <<loop_end>>
11077         CLOSE c_get_line_detail_to_interface;
11078     --}
11079     END LOOP; --  FOR i IN 1..line_id_tab.count LOOP
11080 
11081     IF l_debug_on THEN
11082         WSH_DEBUG_SV.logmsg(l_module_name,'Loop End');
11083     END IF;
11084 
11085     --If No STA STB case populate BULK variables
11086     l_row_count   := l_bulk_ship_line.line_id.count;
11087     l_end_index   := l_row_count;
11088     l_start_index := l_bulk_ship_line.line_id.first;
11089 
11090     --If STA or STB case populate NON BULK variables
11091     l_row_count_nonbulk   := l_non_bulk_ship_line.line_id.count;
11092     l_end_index_nonbulk   := l_row_count_nonbulk;
11093     l_start_index_nonbulk := l_non_bulk_ship_line.line_id.first;
11094 
11095     SAVEPOINT l_interface_om;
11096 
11097     --If No STA STB , call OM API in bulk mode
11098     IF l_row_count > 0 THEN
11099     --{
11100         IF l_debug_on THEN
11101            WSH_DEBUG_SV.log(l_module_name,'Total bulk rows',l_row_count);
11102            WSH_DEBUG_SV.logmsg(l_module_name,'Establishing save point l_interface_om_bulk');
11103         END IF;
11104 
11105         SAVEPOINT l_interface_om_bulk;
11106         IF l_debug_on THEN
11107             WSH_DEBUG_SV.log(l_module_name,'Calling OE_Ship_Confirmation_Pub.Ship_Confirm_New TIME:',SYSDATE);
11108         END IF;
11109 
11110         MO_GLOBAL.set_policy_context('S', l_bulk_ship_line.org_id(l_start_index));
11111         IF l_debug_on THEN
11112             WSH_DEBUG_SV.log(l_module_name,'Setting the org',l_bulk_ship_line.org_id(l_start_index));
11113         END IF;
11114         l_loop_count := l_loop_count +1;
11115 
11116         /*Call OM API in bulk mode to interface wdd to OM*/
11117         OE_Ship_Confirmation_Pub.Ship_Confirm_New(P_ship_line_rec => l_bulk_ship_line,
11118                                                   P_requested_line_rec => p_bulk_req_line,
11119                                                   P_line_adj_rec => l_ship_adj_line,
11120                                                   P_bulk_mode => 'Y',
11121                                                   P_start_index => l_start_index,
11122                                                   P_end_index => l_end_index,
11123                                                   x_msg_count => x_msg_count,
11124                                                   x_msg_data => x_msg_data,
11125                                                   x_return_status => l_return_status);
11126 
11127         IF l_debug_on THEN
11128             WSH_DEBUG_SV.log(l_module_name,'After OE_Shipping_Integration_PUB.Ship_Confirm_New TIME:',SYSDATE);
11129             WSH_DEBUG_SV.log(l_module_name,'l_return_status ',l_return_status);
11130             WSH_DEBUG_SV.logmsg(l_module_name, 'NO. OF OE MESSAGES :'||X_MSG_COUNT );
11131         END IF;
11132 
11133         FOR k IN 1 .. NVL(x_msg_count,0)
11134         LOOP
11135         --{
11136               --
11137               IF l_debug_on THEN
11138                       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit OE_MSG_PUB.GET',WSH_DEBUG_SV.C_PROC_LEVEL);
11139               END IF;
11140               --
11141               x_msg_data := oe_msg_pub.get( p_msg_index => k, p_encoded => 'F' );
11142               --
11143               IF l_debug_on THEN
11144                       WSH_DEBUG_SV.logmsg(l_module_name, SUBSTR ( X_MSG_DATA , 1 , 255 ) );
11145               END IF;
11146               --
11147               WSH_UTIL_CORE.printmsg('Error msg: '||SUBSTR(x_msg_data,1,2000));
11148         --}
11149         END LOOP;
11150 
11151         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11152         --{
11153             IF l_debug_on THEN
11154                     WSH_DEBUG_SV.logmsg(l_module_name,'ERROR');
11155             END IF;
11156             l_error_count := l_error_count + 1;
11157             IF l_debug_on THEN
11158                     WSH_DEBUG_SV.logmsg(l_module_name,'Rollback to savepoint l_interface_om_bulk');
11159             END IF;
11160             ROLLBACK TO l_interface_om_bulk;
11161         --}
11162         END IF;
11163     --}
11164     END IF;
11165 
11166     --If STA or STB ,call OM API in non bulk mode
11167     IF l_row_count_nonbulk > 0 THEN
11168     --{
11169           IF l_debug_on THEN
11170               WSH_DEBUG_SV.log(l_module_name,'Total Non bulk rows',l_row_count_nonbulk);
11171           END IF;
11172           IF l_debug_on THEN
11173               WSH_DEBUG_SV.logmsg(l_module_name,'Establishing save point l_interface_om_non_bulk');
11174           END IF;
11175           SAVEPOINT l_interface_om_non_bulk;
11176           IF l_debug_on THEN
11177               WSH_DEBUG_SV.log(l_module_name,'Calling OE_Ship_Confirmation_Pub.Ship_Confirm_New TIME:',SYSDATE);
11178           END IF;
11179 
11180           MO_GLOBAL.set_policy_context('S', l_non_bulk_ship_line.org_id(l_start_index_nonbulk));
11181 
11182           IF l_debug_on THEN
11183               WSH_DEBUG_SV.log(l_module_name,'setting the org',l_non_bulk_ship_line.org_id(l_start_index_nonbulk));
11184           END IF;
11185 
11186           l_loop_count := l_loop_count + 1;
11187 
11188           /*Call OM API in non bulk mode to interface WDD to OM*/
11189           OE_Ship_Confirmation_Pub.Ship_Confirm_New(P_ship_line_rec => l_non_bulk_ship_line,
11190                                                     P_requested_line_rec => p_bulk_req_line,
11191                                                     P_line_adj_rec => l_ship_adj_line,
11192                                                     P_bulk_mode => 'N',
11193                                                     P_start_index => l_start_index_nonbulk,
11194                                                     P_end_index => l_end_index_nonbulk,
11195                                                     x_msg_count => x_msg_count,
11196                                                     x_msg_data => x_msg_data,
11197                                                     x_return_status => l_return_status);
11198           IF l_debug_on THEN
11199                   WSH_DEBUG_SV.log(l_module_name,'After OE_Shipping_Integration_PUB.Ship_Confirm_New TIME:',SYSDATE);
11200                   WSH_DEBUG_SV.log(l_module_name,'l_return_status ',l_return_status);
11201                   WSH_DEBUG_SV.logmsg(l_module_name, 'NO. OF OE MESSAGES :'
11202                   ||X_MSG_COUNT );
11203           END IF;
11204 
11205           FOR k IN 1 .. NVL(x_msg_count,0)
11206           LOOP
11207                   --
11208                   IF l_debug_on THEN
11209                           WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit OE_MSG_PUB.GET',WSH_DEBUG_SV.C_PROC_LEVEL);
11210                   END IF;
11211                   --
11212                   x_msg_data := oe_msg_pub.get( p_msg_index => k, p_encoded => 'F' );
11213                   --
11214                   IF l_debug_on THEN
11215                           WSH_DEBUG_SV.logmsg(l_module_name, SUBSTR ( X_MSG_DATA , 1 , 255 ) );
11216                   END IF;
11217                   --
11218                   WSH_UTIL_CORE.printmsg('Error msg: '||SUBSTR(x_msg_data,1,2000));
11219           END LOOP;
11220 
11221           IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11222           --{
11223                 IF l_debug_on THEN
11224                         WSH_DEBUG_SV.logmsg(l_module_name,'ERROR');
11225                 END IF;
11226                 l_error_count := l_error_count + 1;
11227                 IF l_debug_on THEN
11228                         WSH_DEBUG_SV.logmsg(l_module_name,'Rollback to savepoint l_interface_om_non_bulk');
11229                 END IF;
11230                 ROLLBACK TO l_interface_om_non_bulk;
11231           --}
11232           END IF;
11233     --}
11234     END IF;
11235 
11236     IF l_row_count = 0 AND l_row_count_nonbulk = 0 THEN
11237       IF l_debug_on THEN
11238           WSH_DEBUG_SV.logmsg(l_module_name,'*******No eligible lines found*********');
11239       END IF;
11240     END IF;
11241 
11242     IF ( l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS ) THEN
11243         x_return_status := l_return_status;
11244     END IF;
11245 
11246     IF l_debug_on THEN
11247        WSH_DEBUG_SV.pop(l_module_name);
11248     END IF;
11249 
11250 EXCEPTION
11251    WHEN OTHERS THEN
11252         x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
11253         wsh_util_core.printMsg('API Process_lines_To_OM failed with an unexpected error');
11254         WSH_UTIL_CORE.PrintMsg('The unexpected error is '|| sqlerrm);
11255 
11256         IF c_get_line_detail_to_interface%ISOPEN THEN
11257            close c_get_line_detail_to_interface;
11258         END IF;
11259 
11260         IF l_debug_on THEN
11261             WSH_DEBUG_SV.logmsg(l_module_name,'Rollback to savepoint l_interface_om');
11262         END IF;
11263         ROLLBACK TO SAVEPOINT l_interface_om;
11264 
11265         IF l_debug_on THEN
11266             WSH_DEBUG_SV.logmsg(l_module_name, 'UNEXPECTED ERROR IN Process_lines_To_OM' );
11267             WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
11268             WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
11269         END IF;
11270 
11271 END Process_lines_To_OM;
11272 
11273 END WSH_SHIP_CONFIRM_ACTIONS;