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