DBA Data[Home] [Help]

PACKAGE BODY: APPS.WSH_DELIVERY_DETAILS_GRP

Source


1 PACKAGE BODY WSH_DELIVERY_DETAILS_GRP as
2 /* $Header: WSHDDGPB.pls 120.37.12020000.2 2012/11/21 12:32:20 ravmamid ship $ */
3 
4   -- standard global constants
5   G_PKG_NAME CONSTANT VARCHAR2(30)    := 'WSH_DELIVERY_DETAILS_GRP';
6   p_message_type  CONSTANT VARCHAR2(1)  := 'E';
7   c_wms_code_present VARCHAR2(1) := 'Y';
8 
9 -- anxsharm for Load Tender
10 -- add delivery id and parent_delivery_detail_id
11 CURSOR c_original_detail_cur(p_detail_id  NUMBER) IS
12      SELECT wdd.source_line_id,
13            wdd.organization_id,
14            wdd.inventory_item_id,
15            wdd.serial_number,
16            wdd.to_serial_number, -- Bug fix 2652300
17            wdd.top_model_line_id, -- Bug fix 2652300
18            wdd.transaction_temp_id,
19            wdd.locator_id,
20            wdd.revision,
21            wdd.subinventory,
22            wdd.lot_number,
23            wdd.released_status,
24            wdd.requested_quantity_uom,
25            wdd.gross_weight,
26            wdd.net_weight,
27            wdd.weight_uom_code,
28            wdd.volume,
29            wdd.volume_uom_code,
30            wdd.container_name,
31            wdd.container_flag,
32            wdd.master_serial_number,
33            wdd.inspection_flag,
34            wdd.cycle_count_quantity,
35            wdd.shipped_quantity,
36            wdd.requested_quantity,
37            wdd.picked_quantity,
38 -- PK added for Bug 3055126 qty2's
39            wdd.cycle_count_quantity2,
40            wdd.shipped_quantity2,
41            wdd.requested_quantity2,
42            wdd.picked_quantity2,
43            wdd.pickable_flag,
44            wda.delivery_id,
45            wda.parent_delivery_detail_id,
46 		   --Added for bug 12850936
47            wv_frozen_flag,
48            wdd.inv_interfaced_flag
49            -- Added for bug 13574503
50      FROM wsh_delivery_details wdd,
51           wsh_delivery_assignments_v wda
52      WHERE wdd.delivery_detail_id = p_detail_id
53        AND wdd.delivery_detail_id = wda.delivery_detail_id;
54 
55 
56 -- Forward Declarations for local procedures
57 PROCEDURE  Create_Delivery_Detail(
58                 p_detail_info_tab      IN   WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type,
59                 p_detail_IN_rec        IN   WSH_GLBL_VAR_STRCT_GRP.detailInRecType,
60                 p_valid_index_tab      IN   wsh_util_core.id_tab_type,
61                 x_detail_OUT_rec       OUT NOCOPY WSH_GLBL_VAR_STRCT_GRP.detailOutRecType,
62                 x_return_status        OUT NOCOPY VARCHAR2,
63                 x_msg_count            OUT NOCOPY     NUMBER,
64                 x_msg_data             OUT NOCOPY     VARCHAR2
65                 );
66 
67 PROCEDURE  Validate_Delivery_Detail(
68                 x_detail_info_tab  IN  OUT NOCOPY WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type,
69                 p_in_detail_tab    IN   WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type,
70                 p_action           IN  VARCHAR2,
71                 p_validation_tab   IN  wsh_util_core.Id_Tab_Type,
72                 p_caller           IN  varchar2,
73                 x_valid_index_tab  OUT NOCOPY WSH_UTIL_CORE.Id_Tab_Type,
74                 x_details_marked   OUT NOCOPY WSH_UTIL_CORE.Id_Tab_Type,
75                 x_detail_tender_tab  OUT NOCOPY WSH_UTIL_CORE.Id_Tab_Type,
76                 x_return_status    OUT NOCOPY VARCHAR2,
77                 x_msg_count        OUT NOCOPY     NUMBER,
78                 x_msg_data         OUT NOCOPY     VARCHAR2,
79                 p_in_rec           IN  WSH_GLBL_VAR_STRCT_GRP.detailInRecType,
80                 p_serial_range_tab IN  WSH_GLBL_VAR_STRCT_GRP.ddSerialRangeTabType
81             );
82 
83 PROCEDURE  Update_Delivery_Detail(
84                 p_detail_info_tab     IN        WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type ,
85                 p_valid_index_tab     IN  wsh_util_core.id_tab_type,
86                 x_return_status       OUT NOCOPY  varchar2,
87                 x_msg_count            OUT NOCOPY     NUMBER,
88                 x_msg_data             OUT NOCOPY     VARCHAR2,
89                 p_caller               IN             VARCHAR2 DEFAULT NULL
90                 );
91 
92     -- ---------------------------------------------------------------------
93     -- Procedure: Cancel_Delivery_Detail
94     --
95     -- Parameters:
96     --
97     -- Description:  This local procedure is the new API for wrapping the logic of CANCEL of delivery details
98     -- Created:   Harmonization Project. Patchset I
99     -- -----------------------------------------------------------------------
100 
101 PROCEDURE  Cancel_Delivery_Detail(
102                 p_detail_info_tab     IN  WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type ,
103                 x_return_status       OUT NOCOPY      VARCHAR2,
104                 x_msg_count           OUT NOCOPY      NUMBER,
105                 x_msg_data            OUT NOCOPY      VARCHAR2,
106                 p_caller              IN              VARCHAR2 DEFAULT NULL
107     );
108 
109 
110 
111 PROCEDURE Validate_Detail_Line(
112                 x_detail_rec          IN OUT NOCOPY WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Rec_Type,
113                 p_in_detail_rec    IN   WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Rec_Type,
114                 p_original_rec        IN   c_original_detail_cur%ROWTYPE,
115                 p_validation_tab      IN   WSH_UTIL_CORE.id_tab_type,
116                 x_mark_reprice_flag   OUT NOCOPY VARCHAR2,
117                 x_return_status       OUT NOCOPY VARCHAR2,
118                 x_msg_count           OUT NOCOPY NUMBER,
119                 x_msg_data            OUT NOCOPY VARCHAR2,
120                 p_in_rec              IN  WSH_GLBL_VAR_STRCT_GRP.detailInRecType,
121                 p_serial_range_tab    IN  WSH_GLBL_VAR_STRCT_GRP.ddSerialRangeTabType
122                 );
123 
124 PROCEDURE Validate_Detail_Container(
125                 x_detail_rec          IN OUT NOCOPY  WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Rec_Type,
126                 p_original_rec        IN   c_original_detail_cur%ROWTYPE,
127                 p_validation_tab      IN   WSH_UTIL_CORE.id_tab_type,
128                 x_mark_reprice_flag   OUT  NOCOPY VARCHAR2,
129                 x_return_status       OUT  NOCOPY VARCHAR2,
130                 x_msg_count           OUT  NOCOPY NUMBER,
131                 x_msg_data            OUT  NOCOPY VARCHAR2
132                 );
133 
134 PROCEDURE Validate_Detail_Common(
135                 x_detail_rec          IN OUT NOCOPY WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Rec_Type,
136                 p_original_rec        IN   c_original_detail_cur%ROWTYPE,
137                 p_validation_tab      IN   wsh_util_core.id_tab_type,
138                 x_mark_reprice_flag   OUT  NOCOPY VARCHAR2,
139                 x_return_status       OUT  NOCOPY VARCHAR2,
140                 x_msg_count           OUT  NOCOPY NUMBER,
141                 x_msg_data            OUT  NOCOPY VARCHAR2
142                 );
143 
144 PROCEDURE get_serial_quantity(
145           p_transaction_temp_id  IN  NUMBER,
146           p_serial_number        IN  VARCHAR2,
147           p_to_serial_number     IN  VARCHAR2,
148           p_shipped_quantity     IN  VARCHAR2,
149           x_serial_qty           OUT NOCOPY NUMBER,
150           x_return_status        OUT NOCOPY VARCHAR2);
151 
152 -- -----------------------------------------------------------------------
153 -- Procedure: detail_to_delivery
154 --
155 -- Parameters:    1) table of delivery_detail_ids
156 --            2) action: assign/unassign
157 --            3) delivery_id: need to specify delivery id or delivery name
158 --              if the action is 'ASSIGN'
159 --            4) delivery_name: need to specify delivery id or delivery
160 --              name if the action is 'ASSIGN'
161 --            5) other standard parameters
162 --
163 --
164 -- Description:  This procedure assign/unassign delivery_details to
165 --            a delivery.
166 -- Parameters: p_TabOfDelDets: required
167 --          p_action: required
168 --          p_delivery_id: required if action='ASSIGN'
169 -- -----------------------------------------------------------------------
170 PROCEDURE detail_to_delivery(
171    -- Standard parameters
172    p_api_version        IN              NUMBER,
173    p_init_msg_list      IN              VARCHAR2,
174    p_commit             IN              VARCHAR2,
175    p_validation_level   IN              NUMBER,
176    x_return_status      OUT NOCOPY      VARCHAR2,
177    x_msg_count          OUT NOCOPY      NUMBER,
178    x_msg_data           OUT NOCOPY      VARCHAR2,
179    -- procedure specific parameters
180    p_tabofdeldets       IN              WSH_UTIL_CORE.id_tab_type,
181    p_action             IN              VARCHAR2,
182    p_delivery_id        IN              NUMBER,
183    p_delivery_name      IN              VARCHAR2,
184    p_action_prms  IN WSH_GLBL_VAR_STRCT_GRP.dd_action_parameters_rec_type   -- J-IB-NPARIKH
185 ) IS
186 -- Standard call to check for call compatibility
187    l_api_version        CONSTANT NUMBER := 1.0;
188    l_api_name           CONSTANT VARCHAR2(30) := 'delivery_detail_to_delivery';
189    l_return_status               VARCHAR2(30) := NULL;
190    l_delivery_id                 NUMBER := NULL;
191    l_cont_ins_id                 NUMBER := NULL;
192    l_tabofdeldets                wsh_util_core.id_tab_type;
193    l_msg_summary                 VARCHAR2(2000) := NULL;
194    l_msg_details                 VARCHAR2(4000) := NULL;
195    l_del_params                  wsh_delivery_autocreate.grp_attr_tab_type;
196    wsh_no_del_det_tbl            EXCEPTION;
197    wsh_no_delivery_id            EXCEPTION;
198    wsh_no_delivery               EXCEPTION; /*2777869*/
199    wsh_invalid_delivery_id       EXCEPTION; /*2777869*/
200    wsh_invalid_action            EXCEPTION;
201 
202    CURSOR c_delivery_record IS
203       SELECT delivery_id
204         FROM wsh_new_deliveries
205        WHERE NAME = p_delivery_name;
206 
207 /*2777869*/
208     CURSOR c_delivery_id is
209       SELECT delivery_id
210       FROM  wsh_new_deliveries
211       WHERE delivery_id = p_delivery_id;
212 
213    -- deliveryMerge
214    CURSOR c_get_assigned_delivery (c_delivery_detail_id NUMBER) IS
215       SELECT wda.delivery_id
216       FROM   wsh_delivery_assignments_v wda,
217              wsh_delivery_details wdd
218       WHERE  wda.delivery_detail_id = c_delivery_detail_id
219       AND    wda.delivery_detail_id = wdd.delivery_detail_id
220       AND    wdd.container_flag = 'N'
221       AND    NVL(wdd.line_direction,'O') in ('O','IO');
222    --
223    l_debug_on                    BOOLEAN;
224    --
225    l_module_name        CONSTANT VARCHAR2(100) := 'wsh.plsql.' || g_pkg_name || '.' || 'DETAIL_TO_DELIVERY';
226 
227    -- Patchset I: Harmonization Project
228    l_pack_status_dummy           VARCHAR2(100);
229    l_msg_data                    VARCHAR2(32767);
230 
231 -- anxsharm for Load Tender
232    l_trip_id_tab                 wsh_util_core.id_tab_type;
233    l_det_tab                     wsh_util_core.id_tab_type;
234    l_number_of_errors            NUMBER := 0;
235    l_number_of_warnings          NUMBER := 0;
236    --
237    l_cnt                         NUMBER;
238    i                             number;
239 
240    -- deliveryMerge
241    l_adjust_planned_del_tab      wsh_util_core.id_tab_type;
242    l_delivery_already_included   boolean;
243    --LPN Convergence
244    e_invalid_quantity EXCEPTION;
245 
246 BEGIN
247    --
248    l_debug_on := wsh_debug_interface.g_debug;
249 
250    --
251    IF l_debug_on IS NULL THEN
252       l_debug_on := wsh_debug_sv.is_debug_enabled;
253    END IF;
254 
255    --
256    SAVEPOINT detail_to_delivery_grp;
257 
258     -- Standard begin of API savepoint
259    --
260    -- Debug Statements
261    --
262    IF l_debug_on THEN
263       wsh_debug_sv.push(l_module_name);
264       --
265       wsh_debug_sv.LOG(l_module_name, 'P_API_VERSION', p_api_version);
266       wsh_debug_sv.LOG(l_module_name, 'P_INIT_MSG_LIST', p_init_msg_list);
267       wsh_debug_sv.LOG(l_module_name, 'P_COMMIT', p_commit);
268       wsh_debug_sv.LOG(l_module_name, 'P_VALIDATION_LEVEL', p_validation_level);
269       wsh_debug_sv.LOG(l_module_name, 'P_ACTION', p_action);
270       wsh_debug_sv.LOG(l_module_name, 'P_DELIVERY_ID', p_delivery_id);
271       wsh_debug_sv.LOG(l_module_name, 'P_DELIVERY_NAME', p_delivery_name);
272       wsh_debug_sv.LOG(l_module_name, 'P_TABOFDELDETS.COUNT', p_tabofdeldets.COUNT);
273    END IF;
274 
275    --
276    l_adjust_planned_del_tab.delete;
277 
278    IF NOT fnd_api.compatible_api_call(
279             l_api_version,
280             p_api_version,
281             l_api_name,
282             g_pkg_name
283          ) THEN
284       RAISE fnd_api.g_exc_unexpected_error;
285    END IF;
286 
287    -- Check p_init_msg_list
288    IF fnd_api.to_boolean(p_init_msg_list) THEN
289       fnd_msg_pub.initialize;
290    END IF;
291 
292    x_return_status := wsh_util_core.g_ret_sts_success;
293 
294    IF (p_tabofdeldets.COUNT = 0) THEN
295       RAISE wsh_no_del_det_tbl;
296    END IF;
297 
298    /* check action */
299    IF UPPER(NVL(p_action, 'N')) NOT IN('ASSIGN', 'UNASSIGN') THEN
300       RAISE wsh_invalid_action;
301    END IF;
302 
303    i := p_tabofdeldets.FIRST;
304    l_cnt := 0;
305    --
306    WHILE i IS NOT NULL
307    LOOP
308     l_cnt := l_cnt + 1;
309     --
310     l_tabofdeldets(l_cnt) := p_tabofdeldets(i);
311     --
312     i := p_tabofdeldets.NEXT(i);
313     --
314    END LOOP;
315 
316 
317    IF UPPER(NVL(p_action, 'N')) = 'ASSIGN' THEN
318       IF (
319                  (p_delivery_id IS NOT NULL)
320              AND (p_delivery_id <> fnd_api.g_miss_num)
321           OR     (p_delivery_name IS NOT NULL)
322              AND (p_delivery_name <> fnd_api.g_miss_char)
323          ) THEN
324          IF (p_delivery_id IS NULL OR p_delivery_id = fnd_api.g_miss_num) THEN
325             /* convert delivery_name to delivery_id */
326             OPEN c_delivery_record;
327             FETCH c_delivery_record INTO l_delivery_id;
328 
329             IF c_delivery_record%NOTFOUND THEN
330                CLOSE c_delivery_record;
331             -- RAISE wsh_no_delivery_id;  /*2777869*/
332                RAISE wsh_no_delivery;
333             END IF;
334 
335             CLOSE c_delivery_record;
336          ELSE
337             OPEN c_delivery_id;     /*2777869*/
338             FETCH c_delivery_id into l_delivery_id;
339             IF c_delivery_id%NOTFOUND THEN
340                CLOSE c_delivery_id;
341                RAISE wsh_invalid_delivery_id;
342             END IF;
343          -- l_delivery_id := p_delivery_id;
344          END IF;
345 
346          IF l_debug_on THEN
347             wsh_debug_sv.logmsg(l_module_name, 'Calling program unit WSH_DLVB_COMMON_ACTIONS.ASSIGN_DETAILS', wsh_debug_sv.c_proc_level);
348          END IF;
349 
350          --
351 
352          /* Patchset I : Harmonization Project Begin
353                Instead of the old call to Assign_Multiple_Details
354          We now have call to wsh_dlvb_common_actions.assign_details */
355  IF l_debug_on THEN
356          wsh_debug_sv.logmsg(l_module_name, '  befor assign_details');
357       END IF;
358          wsh_dlvb_common_actions.assign_details(
359             p_detail_tab            => l_tabofdeldets,
360             p_parent_detail_id      => NULL,
361             p_delivery_id           => p_delivery_id,
362             x_pack_status           => l_pack_status_dummy,
363             x_return_status         => l_return_status
364          );
365          wsh_util_core.api_post_call(
366             p_return_status => l_return_status,
367             x_num_warnings       => l_number_of_warnings,
368             x_num_errors         => l_number_of_errors);
369          /* Patchset I : Harmonization Project End */
370          l_det_tab(1) := p_delivery_id;
371          wsh_tp_release.calculate_cont_del_tpdates(
372             p_entity => 'DLVY',
373             p_entity_ids =>l_det_tab,
374             x_return_status => x_return_status);
375 
376          wsh_util_core.api_post_call(
377               p_return_status => l_return_status,
378               x_num_warnings       => l_number_of_warnings,
379               x_num_errors         => l_number_of_errors);
380 
381          -- deliveryMerge, collect the delivery ids for adjust_planned_flag call
382 
383          l_adjust_planned_del_tab(l_adjust_planned_del_tab.count+1) := p_delivery_id;
384       IF l_debug_on THEN
385          wsh_debug_sv.logmsg(l_module_name, ' added delivery '||p_delivery_id ||' for adjustment');
386       END IF;
387 
388       ELSE
389          /* no delivery id is passed for action assign */
390          RAISE wsh_no_delivery_id;
391       END IF;
392    ELSE
393       /*  unassign */
394       IF l_debug_on THEN
395          wsh_debug_sv.logmsg(l_module_name, 'Calling program unit WSH_DETAILS_VALIDATIONS.CHECK_UNASSIGN_FROM_DELIVERY', wsh_debug_sv.c_proc_level);
396       END IF;
397 
398       wsh_details_validations.check_unassign_from_delivery(
399          p_detail_rows => l_tabofdeldets,
400          x_return_status      => l_return_status);
401 
402       wsh_util_core.api_post_call(
403          p_return_status => l_return_status,
404          x_num_warnings       => l_number_of_warnings,
405          x_num_errors         => l_number_of_errors);
406 
407       IF l_debug_on THEN
408          wsh_debug_sv.logmsg(l_module_name, 'Calling program unit WSH_DLVB_COMMON_ACTIONS.UNASSIGN_DETAILS', wsh_debug_sv.c_proc_level);
409       END IF;
410 
411       /* Patchset I : Harmonization Project Begin
412       Instead of the old call to WSH_DELIVERY_DETAILS_ACTIONS.Unassign_Multiple_Details We now have call to wsh_dlvb_common_actions.unassign_details */
413       -- deliveryMerge
414 
415       i := l_tabofdeldets.FIRST;
416       WHILE i is not NULL LOOP
417          OPEN c_get_assigned_delivery(l_tabofdeldets(i));
418          FETCH c_get_assigned_delivery INTO l_delivery_id;
419          IF c_get_assigned_delivery%NOTFOUND THEN
420            goto end_of_loop;
421          ELSE
422          --
423            l_delivery_already_included := false;
424 
425            IF l_adjust_planned_del_tab.count > 0 THEN
426               FOR i in l_adjust_planned_del_tab.FIRST .. l_adjust_planned_del_tab.LAST LOOP
427                  IF l_adjust_planned_del_tab(i) = l_delivery_id THEN
428                     l_delivery_already_included := true;
429                  END IF;
430               END LOOP;
431            END IF;
432 
433            IF NOT l_delivery_already_included THEN
434               l_adjust_planned_del_tab(l_adjust_planned_del_tab.count+1) := l_delivery_id;
435            END IF;
436 
437          --
438          END IF;
439          <<end_of_loop>>
440          CLOSE c_get_assigned_delivery;
441       i := l_tabofdeldets.next(i);
442       END LOOP;
443 
444       wsh_dlvb_common_actions.unassign_details(
445          p_detail_tab              => l_tabofdeldets,
446          p_parent_detail_flag      => 'N',
447          p_delivery_flag           => 'Y',
448          x_return_status           => l_return_status,
449          p_action_prms             => p_action_prms
450       );
451       wsh_util_core.api_post_call(
452          p_return_status => l_return_status,
453          x_num_warnings       => l_number_of_warnings,
454          x_num_errors         => l_number_of_errors);
455       /* Patchset I : Harmonization Project End */
456    END IF;
457    -- deliveryMerge
458    IF l_adjust_planned_del_tab.count > 0 and WSH_PICK_LIST.G_BATCH_ID is NULL THEN
459       WSH_NEW_DELIVERY_ACTIONS.Adjust_Planned_Flag(
460          p_delivery_ids          => l_adjust_planned_del_tab,
461          p_caller                => 'WSH_DLMG',
462          p_force_appending_limit => 'N',
463          p_call_lcss             => 'Y',
464          x_return_status         => l_return_status);
465 
466       IF l_debug_on THEN
467          WSH_DEBUG_SV.log(l_module_name,'Adjust_Planned_Flag returns ',l_return_status);
468       END IF;
469 
470       wsh_util_core.api_post_call(
471          p_return_status => l_return_status,
472          x_num_warnings       => l_number_of_warnings,
473          x_num_errors         => l_number_of_errors);
474 
475    END IF;
476 
477    IF l_number_of_warnings > 0 THEN
478       IF l_debug_on THEN
479          wsh_debug_sv.log(l_module_name, 'Number of warnings', l_number_of_warnings);
480       END IF;
481 
482       RAISE wsh_util_core.g_exc_warning;
483    END IF;
484 
485    fnd_msg_pub.count_and_get(
486       p_count => x_msg_count,
487       p_data => x_msg_data,
488       p_encoded      => fnd_api.g_false);
489 
490    IF fnd_api.to_boolean(p_commit) THEN
491       -- dbms_output.put_line('commit');
492       COMMIT WORK;
493    END IF;
494 
495    IF l_debug_on THEN
496       wsh_debug_sv.pop(l_module_name);
497    END IF;
498 --
499 EXCEPTION
500    WHEN fnd_api.g_exc_error THEN
501       ROLLBACK TO detail_to_delivery_grp;
502       x_return_status := fnd_api.g_ret_sts_error;
503       fnd_msg_pub.count_and_get(
504          p_count => x_msg_count,
505          p_data => x_msg_data,
506          p_encoded      => fnd_api.g_false);
507 
508       --
509       IF l_debug_on THEN
510          wsh_debug_sv.logmsg(l_module_name, 'FND_API.G_EXC_ERROR exception has occured.', wsh_debug_sv.c_excep_level);
511          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:FND_API.G_EXC_ERROR');
512       END IF;
513    --
514    WHEN fnd_api.g_exc_unexpected_error THEN
515       ROLLBACK TO detail_to_delivery_grp;
516       x_return_status := fnd_api.g_ret_sts_unexp_error;
517       fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data,
518          p_encoded      => fnd_api.g_false);
519 
520       --
521       IF l_debug_on THEN
522          wsh_debug_sv.logmsg(l_module_name, 'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.', wsh_debug_sv.c_excep_level);
523          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
524       END IF;
525    --
526    WHEN wsh_util_core.g_exc_warning THEN
527       x_return_status := wsh_util_core.g_ret_sts_warning;
528       fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data,
529          p_encoded      => fnd_api.g_false);
530 
531       --
532       IF l_debug_on THEN
533          wsh_debug_sv.logmsg(l_module_name, 'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ', wsh_debug_sv.c_excep_level);
534          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
535       END IF;
536 
537    WHEN wsh_invalid_action THEN
538       ROLLBACK TO detail_to_delivery_grp;
539       x_return_status := wsh_util_core.g_ret_sts_error;
540       fnd_message.set_name('WSH', 'WSH_PUB_INVALID_ACTION');
541       wsh_util_core.add_message(x_return_status);
542       fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data,
543          p_encoded      => fnd_api.g_false);
544 
545       IF l_debug_on THEN
546          wsh_debug_sv.logmsg(l_module_name, 'WSH_INVALID_ACTION exception has occured.', wsh_debug_sv.c_excep_level);
547          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:WSH_INVALID_ACTION');
548       END IF;
549 
550    WHEN wsh_no_del_det_tbl THEN
551       ROLLBACK TO detail_to_delivery_grp;
552       x_return_status := wsh_util_core.g_ret_sts_error;
553       fnd_message.set_name('WSH', 'WSH_PUB_NO_DEL_DET_TBL');
554       wsh_util_core.add_message(x_return_status);
555       fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data,
556          p_encoded      => fnd_api.g_false);
557 
558       IF l_debug_on THEN
559          wsh_debug_sv.logmsg(l_module_name, 'WSH_NO_DEL_DET_TBL exception has occured.', wsh_debug_sv.c_excep_level);
560          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:WSH_NO_DEL_DET_TBL');
561       END IF;
562    --
563    WHEN wsh_no_delivery_id THEN
564       ROLLBACK TO detail_to_delivery_grp;
565       x_return_status := wsh_util_core.g_ret_sts_error;
566       fnd_message.set_name('WSH', 'WSH_PUB_NO_DELIVERY');
567       wsh_util_core.add_message(x_return_status);
568       fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data,
569          p_encoded      => fnd_api.g_false);
570 
571       IF l_debug_on THEN
572          wsh_debug_sv.logmsg(l_module_name, 'WSH_NO_DELIVERY_ID exception has occured.', wsh_debug_sv.c_excep_level);
573          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:WSH_NO_DELIVERY_ID');
574       END IF;
575 --
576 
577 /*Start of 2777869*/
578 
579    WHEN wsh_no_delivery THEN
580       ROLLBACK TO detail_to_delivery_grp;
581       x_return_status := wsh_util_core.g_ret_sts_error;
582       fnd_message.set_name('WSH', 'WSH_DELIVERY_NOT_EXIST');
583       fnd_message.set_token('DELIVERY_NAME', p_delivery_name);
584       wsh_util_core.add_message(x_return_status);
585       fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data,
586          p_encoded      => fnd_api.g_false);
587 
588       IF l_debug_on THEN
589          wsh_debug_sv.logmsg(l_module_name, 'WSH_NO_DELIVERY exception has occured.', wsh_debug_sv.c_excep_level);
590          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:WSH_NO_DELIVERY');
591       END IF;
592 --
593    WHEN wsh_invalid_delivery_id THEN
594       ROLLBACK TO detail_to_delivery_grp;
595       x_return_status := wsh_util_core.g_ret_sts_error;
596       fnd_message.set_name('WSH', 'WSH_INVALID_DELIVERY');
597       fnd_message.set_token('DELIVERY', p_delivery_id);
598       wsh_util_core.add_message(x_return_status);
599       fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data,
600          p_encoded      => fnd_api.g_false);
601 
602       IF l_debug_on THEN
603          wsh_debug_sv.logmsg(l_module_name, 'WSH_INVALID_DELIVERY_ID exception has occured.', wsh_debug_sv.c_excep_level);
604          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:WSH_INVALID_DELIVERY_ID');
605       END IF;
606 
607 /* End of 2777869*/
608 --
609 
610    WHEN OTHERS THEN
611       ROLLBACK TO detail_to_delivery_grp;
612       x_return_status := wsh_util_core.g_ret_sts_unexp_error;
613       wsh_util_core.default_handler('WSH_DELIVERY_DETAILS_GRP.DETAIL_TO_DELIVERY');
614       fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data,
615          p_encoded      => fnd_api.g_false);
616 
617       IF l_debug_on THEN
618          wsh_debug_sv.logmsg(l_module_name, 'Unexpected error has occured. Oracle error message is ' || SQLERRM, wsh_debug_sv.c_unexpec_err_level);
619          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:OTHERS');
620       END IF;
621 --
622 END detail_to_delivery;
623 
624 
625 --This procedure is for backward compatibility only. Do not use this.
626 PROCEDURE detail_to_delivery(
627    -- Standard parameters
628    p_api_version        IN              NUMBER,
629    p_init_msg_list      IN              VARCHAR2,
630    p_commit             IN              VARCHAR2,
631    p_validation_level   IN              NUMBER,
632    x_return_status      OUT NOCOPY      VARCHAR2,
633    x_msg_count          OUT NOCOPY      NUMBER,
634    x_msg_data           OUT NOCOPY      VARCHAR2,
635    -- procedure specific parameters
636    p_tabofdeldets       IN              WSH_UTIL_CORE.id_tab_type,
637    p_action             IN              VARCHAR2,
638    p_delivery_id        IN              NUMBER,
639    p_delivery_name      IN              VARCHAR2
640 ) IS
641 
642    --
643    l_debug_on                    BOOLEAN;
644    --
645    l_module_name        CONSTANT VARCHAR2(100) := 'wsh.plsql.' || g_pkg_name || '.' || 'DETAIL_TO_DELIVERY';
646    --
647    l_action_prms   WSH_GLBL_VAR_STRCT_GRP.dd_action_parameters_rec_type;  -- J-IB-NPARIKH
648 BEGIN
649    --
650    l_debug_on := wsh_debug_interface.g_debug;
651 
652    --
653    IF l_debug_on IS NULL THEN
654       l_debug_on := wsh_debug_sv.is_debug_enabled;
655    END IF;
656 
657 
658    -- Debug Statements
659    --
660    IF l_debug_on THEN
661       wsh_debug_sv.push(l_module_name);
662       --
663       wsh_debug_sv.LOG(l_module_name, 'P_API_VERSION', p_api_version);
664       wsh_debug_sv.LOG(l_module_name, 'P_INIT_MSG_LIST', p_init_msg_list);
665       wsh_debug_sv.LOG(l_module_name, 'P_COMMIT', p_commit);
666       wsh_debug_sv.LOG(l_module_name, 'P_VALIDATION_LEVEL', p_validation_level);
667       wsh_debug_sv.LOG(l_module_name, 'P_ACTION', p_action);
668       wsh_debug_sv.LOG(l_module_name, 'P_DELIVERY_ID', p_delivery_id);
669       wsh_debug_sv.LOG(l_module_name, 'P_DELIVERY_NAME', p_delivery_name);
670       wsh_debug_sv.LOG(l_module_name, 'P_TABOFDELDETS.COUNT', p_tabofdeldets.COUNT);
671    END IF;
672 
673 
674       IF l_debug_on THEN
675          wsh_debug_sv.logmsg(l_module_name, 'Calling program unit WSH_DELIVERY_DETAILS_GRP.DETAIL_TO_DELIVERY', wsh_debug_sv.c_proc_level);
676       END IF;
677 
678       DETAIL_TO_DELIVERY
679         (
680            p_api_version ,
681            p_init_msg_list ,
682            p_commit    ,
683            p_validation_level,
684            x_return_status ,
685            x_msg_count   ,
686            x_msg_data   ,
687            p_tabofdeldets,
688            p_action      ,
689            p_delivery_id  ,
690            p_delivery_name  ,
691            l_action_prms
692         );
693    IF l_debug_on THEN
694       wsh_debug_sv.pop(l_module_name);
695    END IF;
696 --
697 EXCEPTION
698 
699    WHEN OTHERS THEN
700       x_return_status := wsh_util_core.g_ret_sts_unexp_error;
701       wsh_util_core.default_handler('WSH_DELIVERY_DETAILS_GRP.DETAIL_TO_DELIVERY');
702       fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data,
703          p_encoded      => fnd_api.g_false);
704 
705       IF l_debug_on THEN
706          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:OTHERS');
707       END IF;
708 --
709 END detail_to_delivery;
710 
711 -- ----------------------------------------------------------------------
712 -- Procedure:   split_line
713 -- Parameters:     p_from_detail_id: The delivery detail ID to be split
714 --            x_new_detail_id:  The new delivery detail ID
715 --            p_source_quantity:
716 --            split_quantity:
717 --
718 -- Description:   This procedure split a delivery_deatil line
719 --          03/19/01 OPM changes. Added split_quantity2
720 --  ----------------------------------------------------------------------
721 PROCEDURE split_line(
722    -- Standard parameters
723    p_api_version        IN              NUMBER,
724    p_init_msg_list      IN              VARCHAR2,
725    p_commit             IN              VARCHAR2,
726    p_validation_level   IN              NUMBER,
727    x_return_status      OUT NOCOPY      VARCHAR2,
728    x_msg_count          OUT NOCOPY      NUMBER,
729    x_msg_data           OUT NOCOPY      VARCHAR2,
730    -- Procedure specific parameters
731    p_from_detail_id     IN              NUMBER,
732    x_new_detail_id      OUT NOCOPY      NUMBER,
733    x_split_quantity     IN OUT NOCOPY   NUMBER,
734    x_split_quantity2    IN OUT NOCOPY   NUMBER,
735    p_manual_split       IN              VARCHAR2 DEFAULT NULL,
736    p_converted_flag     IN              VARCHAR2 DEFAULT NULL
737 ) IS
738    l_msg_summary                 VARCHAR2(2000);
739    l_msg_details                 VARCHAR2(4000);
740    l_requested_quantity          NUMBER := NULL;
741    l_requested_quantity2         NUMBER := NULL;/* OPM changes  NC 03/19/01 */
742    l_received_quantity           NUMBER := NULL;
743    l_received_quantity2          NUMBER := NULL;
744    l_line_direction              VARCHAR2(30);
745 -- Standard call to check for call compatibility.
746    l_api_version        CONSTANT NUMBER := 1.0;
747    l_api_name           CONSTANT VARCHAR2(30) := 'Split_Line';
748 
749 /* OPM changes NC . Added requsted_quantity2 in the select */
750    CURSOR c_find_delivery_detail(c_delivery_detail_id NUMBER) IS
751       SELECT NVL(LINE_DIRECTION,'O'),
752              NVL(received_quantity, shipped_quantity),
753              NVL(received_quantity2, shipped_quantity2),
754              NVL(picked_quantity, requested_quantity),
755              NVL(picked_quantity2, requested_quantity2)
756         FROM wsh_delivery_details
757        WHERE delivery_detail_id = c_delivery_detail_id;
758 
759    wsh_invalid_split_qty         EXCEPTION;
760    wsh_invalid_split_qty2        EXCEPTION; /* Added for OPM. NC - 03/19/01 */
761    wsh_inalid_detail_id          EXCEPTION;
762    --
763    l_debug_on                    BOOLEAN;
764    --
765    l_module_name        CONSTANT VARCHAR2(100) := 'wsh.plsql.' || g_pkg_name || '.' || 'SPLIT_LINE';
766    --
767       -- Patchset I : Harmonization Project
768       --
769    l_number_of_errors            NUMBER := 0;
770    l_number_of_warnings          NUMBER := 0;
771    l_msg_data                    VARCHAR2(32767);
772    l_inv_item_id                 NUMBER;
773    l_organization_id             NUMBER;
774    l_requested_quantity_uom      VARCHAR2(32767);
775    l_return_status               VARCHAR2(32767);
776    l_output_quantity             NUMBER;
777    l_validation_level_tab        wsh_util_core.id_tab_type;
778 
779    -- bug 3524851
780    l_top_model_line_id           NUMBER;
781 
782    --
783    CURSOR det_cur(p_del_det_id NUMBER) IS
784       SELECT inventory_item_id, organization_id, requested_quantity_uom, top_model_line_id
785         FROM wsh_delivery_details
786        WHERE delivery_detail_id = p_del_det_id;
787 BEGIN
788    --
789    l_debug_on := wsh_debug_interface.g_debug;
790 
791    --
792    IF l_debug_on IS NULL THEN
793       l_debug_on := wsh_debug_sv.is_debug_enabled;
794    END IF;
795 
796    --
797    SAVEPOINT split_line_grp;
798 
799    -- Standard begin of API savepoint
800    IF l_debug_on THEN
801       wsh_debug_sv.push(l_module_name);
802       --
803       wsh_debug_sv.LOG(l_module_name, 'P_API_VERSION', p_api_version);
804       wsh_debug_sv.LOG(l_module_name, 'P_INIT_MSG_LIST', p_init_msg_list);
805       wsh_debug_sv.LOG(l_module_name, 'P_COMMIT', p_commit);
806       wsh_debug_sv.LOG(l_module_name, 'P_VALIDATION_LEVEL', p_validation_level);
807       wsh_debug_sv.LOG(l_module_name, 'P_FROM_DETAIL_ID', p_from_detail_id);
808       wsh_debug_sv.LOG(l_module_name, 'X_SPLIT_QUANTITY', x_split_quantity);
809       wsh_debug_sv.LOG(l_module_name, 'X_SPLIT_QUANTITY2', x_split_quantity2);
810    END IF;
811 
812    --
813 
814    IF NOT fnd_api.compatible_api_call(
815             l_api_version,
816             p_api_version,
817             l_api_name,
818             g_pkg_name
819          ) THEN
820       RAISE fnd_api.g_exc_unexpected_error;
821    END IF;
822 
823    -- Check p_init_msg_list
824    IF fnd_api.to_boolean(p_init_msg_list) THEN
825       fnd_msg_pub.initialize;
826    END IF;
827 
828    x_return_status := wsh_util_core.g_ret_sts_success;
829    --
830    /* Patchset I : Harmonization Project */
831    l_validation_level_tab := wsh_actions_levels.g_validation_level_tab;
832    /* OPM changes  NC - added l_requested_quantity2 */
833    OPEN c_find_delivery_detail(p_from_detail_id);
834    FETCH c_find_delivery_detail INTO l_line_direction, l_received_quantity,
835     l_received_quantity2, l_requested_quantity,
836     l_requested_quantity2;
837 
838    IF c_find_delivery_detail%NOTFOUND THEN
839       RAISE wsh_inalid_detail_id;
840    END IF;
841 
842    CLOSE c_find_delivery_detail;
843 
844    -- J-IB-NPARIKH-{
845    IF l_line_direction NOT IN ('O','IO')
846    THEN
847    --{
848         --
849         -- For inbound/drop-ship lines,
850         -- qty. to be split cannot be greater than
851         -- NVL(RCV,SHP,PICK,REQ).
852         -- Hence, setting variables l_requested_quantity(2) to
853         -- NVL(RCV,SHP,PICK,REQ).
854         --
855         l_requested_quantity  := NVL(l_received_quantity,l_requested_quantity);
856         l_requested_quantity2 := NVL(l_received_quantity2,l_requested_quantity2);
857    --}
858    END IF;
859    -- J-IB-NPARIKH-}
860 
861 
862 
863    IF l_requested_quantity < x_split_quantity THEN
864       RAISE wsh_invalid_split_qty;
865    END IF;
866 
867    /* OPM changes  NC - added */
868    IF l_requested_quantity2 < x_split_quantity2 THEN
869       RAISE wsh_invalid_split_qty2;
870    END IF;
871 
872    /* PATCHSET I: Harmonization Project. validate decimal quantity */
873 
874    IF (l_validation_level_tab(wsh_actions_levels.c_decimal_quantity_lvl) = 1) THEN
875       OPEN det_cur(p_from_detail_id);
876       FETCH det_cur INTO l_inv_item_id, l_organization_id,
877        l_requested_quantity_uom, l_top_model_line_id;
878       CLOSE det_cur;
879 
880 -- HW Harmonization project. Added p_organization_id
881 -- HW OPMCONV - Removed branching
882 
883          IF l_debug_on THEN
884             wsh_debug_sv.LOG(l_module_name, 'Inv item id', l_inv_item_id);
885             wsh_debug_sv.LOG(l_module_name, 'Org id', l_organization_id);
886             wsh_debug_sv.LOG(l_module_name, 'Req qty uom', l_requested_quantity_uom);
887             wsh_debug_sv.logmsg(l_module_name, 'Calling program unit WSH_DETAILS_VALIDATIONS.CHECK_DECIMAL_QUANTITY', wsh_debug_sv.c_proc_level);
888          END IF;
889 
890          wsh_details_validations.check_decimal_quantity(
891             p_item_id              => l_inv_item_id,
892             p_organization_id      => l_organization_id,
893             p_input_quantity       => x_split_quantity,
894             p_uom_code             => l_requested_quantity_uom, -- :split_line.quantity_UOM,
895             x_output_quantity      => l_output_quantity,
896             x_return_status        => l_return_status,
897             p_top_model_line_id    => l_top_model_line_id -- bug 3524851
898          );
899 
900          IF l_debug_on THEN
901             wsh_debug_sv.LOG(l_module_name, 'Return Status after check decimal', l_return_status);
902             wsh_debug_sv.LOG(l_module_name, 'Output qty after check decimal', l_output_quantity);
903          END IF;
904 
905          -- UT Bug fix 2650839
906          --IF l_return_status <> wsh_util_core.g_ret_sts_success THEN
907          --   RAISE fnd_api.g_exc_error;
908          --END IF;
909          -- Reverting the fix made in 2650839 as we need to return warning instead of
910          -- error to public API users.
911          wsh_util_core.api_post_call(
912             p_return_status => l_return_status,
913             x_num_warnings       => l_number_of_warnings,
914             x_num_errors         => l_number_of_errors);
915 
916    END IF;
917 
918    IF l_debug_on THEN
919       wsh_debug_sv.logmsg(l_module_name, 'Calling program unit WSH_DELIVERY_DETAILS_ACTIONS.SPLIT_DELIVERY_DETAILS', wsh_debug_sv.c_proc_level);
920    END IF;
921 
922   --
923 -- HW added p_converted_flag
924    wsh_delivery_details_actions.split_delivery_details(
925       p_from_detail_id      => p_from_detail_id,
926       p_req_quantity        => x_split_quantity,
927       p_req_quantity2       => x_split_quantity2,
928       p_manual_split        => p_manual_split,
929       p_converted_flag      => p_converted_flag,
930       x_new_detail_id       => x_new_detail_id,
931       x_return_status       => l_return_status
932    );
933    wsh_util_core.api_post_call(
934       p_return_status => l_return_status,
935       x_num_warnings       => l_number_of_warnings,
936       x_num_errors         => l_number_of_errors);
937 
938    IF l_number_of_warnings > 0 THEN
939       IF l_debug_on THEN
940          wsh_debug_sv.log(l_module_name, 'Number of warnings', l_number_of_warnings);
941       END IF;
942 
943       RAISE wsh_util_core.g_exc_warning;
944    END IF;
945 
946    fnd_msg_pub.count_and_get(
947       p_count => x_msg_count,
948       p_data => x_msg_data,
949       p_encoded      => fnd_api.g_false);
950 
951    IF l_debug_on THEN
952       wsh_debug_sv.LOG(l_module_name, 'X_NEW_DETAIL_ID', x_new_detail_id);
953       wsh_debug_sv.LOG(l_module_name, 'X_SPLIT_QUANTITY', x_split_quantity);
954       wsh_debug_sv.pop(l_module_name);
955    END IF;
956 --
957 EXCEPTION
958    WHEN fnd_api.g_exc_error THEN
959       ROLLBACK TO split_line_grp;
960       x_return_status := fnd_api.g_ret_sts_error;
961       fnd_msg_pub.count_and_get(
962          p_count => x_msg_count,
963          p_data => x_msg_data,
964          p_encoded      => fnd_api.g_false);
965 
966       --
967       IF l_debug_on THEN
968          wsh_debug_sv.logmsg(l_module_name, 'FND_API.G_EXC_ERROR exception has occured.', wsh_debug_sv.c_excep_level);
969          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:FND_API.G_EXC_ERROR');
970       END IF;
971    --
972    WHEN fnd_api.g_exc_unexpected_error THEN
973       ROLLBACK TO split_line_grp;
974       x_return_status := fnd_api.g_ret_sts_unexp_error;
975       fnd_msg_pub.count_and_get(
976          p_count => x_msg_count,
977          p_data => x_msg_data,
978          p_encoded      => fnd_api.g_false);
979 
980       --
981       IF l_debug_on THEN
982          wsh_debug_sv.logmsg(l_module_name, 'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.', wsh_debug_sv.c_excep_level);
983          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
984       END IF;
985    --
986    WHEN wsh_util_core.g_exc_warning THEN
987       x_return_status := wsh_util_core.g_ret_sts_warning;
988       fnd_msg_pub.count_and_get(
989          p_count => x_msg_count,
990          p_data => x_msg_data,
991          p_encoded      => fnd_api.g_false);
992 
993       --
994       IF l_debug_on THEN
995          wsh_debug_sv.logmsg(l_module_name, 'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ', wsh_debug_sv.c_excep_level);
996          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
997       END IF;
998    WHEN wsh_inalid_detail_id THEN
999       ROLLBACK TO split_line_grp;
1000       x_return_status := wsh_util_core.g_ret_sts_error;
1001 
1002 /* Bug 2777869 : Instead of message "WSH_PUB_INALID_DETAIL_ID",now we are using
1003 "WSH_DET_INVALID_DETAIL".*/
1004 
1005       fnd_message.set_name('WSH', 'WSH_DET_INVALID_DETAIL');
1006       fnd_message.set_token('DETAIL_ID',p_from_detail_id);
1007       wsh_util_core.add_message(x_return_status);
1008 
1009       fnd_msg_pub.count_and_get(
1010          p_count => x_msg_count,
1011          p_data => x_msg_data,
1012          p_encoded      => fnd_api.g_false);
1013 
1014       IF l_debug_on THEN
1015          wsh_debug_sv.logmsg(l_module_name, 'WSH_INALID_DETAIL_ID exception has occured.', wsh_debug_sv.c_excep_level);
1016          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:WSH_INALID_DETAIL_ID');
1017       END IF;
1018 --
1019    WHEN wsh_invalid_split_qty THEN
1020       ROLLBACK TO split_line_grp;
1021       x_return_status := wsh_util_core.g_ret_sts_error;
1022       fnd_message.set_name('WSH', 'WSH_DET_SPLIT_EXCEED');
1023       wsh_util_core.add_message(x_return_status);
1024 
1025       fnd_msg_pub.count_and_get(
1026          p_count => x_msg_count,
1027          p_data => x_msg_data,
1028          p_encoded      => fnd_api.g_false);
1029 
1030       IF l_debug_on THEN
1031          wsh_debug_sv.logmsg(l_module_name, 'WSH_INVALID_SPLIT_QTY exception has occured.', wsh_debug_sv.c_excep_level);
1032          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:WSH_INVALID_SPLIT_QTY');
1033       END IF;
1034 --
1035    WHEN wsh_invalid_split_qty2 THEN               /* OPM changes. NC - Added */
1036       ROLLBACK TO split_line_grp;
1037       x_return_status := wsh_util_core.g_ret_sts_error;
1038       fnd_message.set_name('WSH', 'WSH_PUB_INVALID_SPLIT_QTY');
1039       wsh_util_core.add_message(x_return_status);
1040 
1041       fnd_msg_pub.count_and_get(
1042          p_count => x_msg_count,
1043          p_data => x_msg_data,
1044          p_encoded      => fnd_api.g_false);
1045 
1046       IF l_debug_on THEN
1047          wsh_debug_sv.logmsg(l_module_name, 'WSH_INVALID_SPLIT_QTY2 exception has occured.', wsh_debug_sv.c_excep_level);
1048          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:WSH_INVALID_SPLIT_QTY2');
1049       END IF;
1050 --
1051    WHEN OTHERS THEN
1052       ROLLBACK TO split_line_grp;
1053       x_return_status := fnd_api.g_ret_sts_unexp_error;
1054       wsh_util_core.add_message(x_return_status, l_module_name);
1055       wsh_util_core.default_handler('WSH_DELIVERY_DETAILS_GRP.Split_Line');
1056 
1057       fnd_msg_pub.count_and_get(
1058          p_count => x_msg_count,
1059          p_data => x_msg_data,
1060          p_encoded      => fnd_api.g_false);
1061       --
1062       IF l_debug_on THEN
1063          wsh_debug_sv.logmsg(l_module_name, 'Unexpected error has occured. Oracle error message is ' || SQLERRM, wsh_debug_sv.c_unexpec_err_level);
1064          wsh_debug_sv.pop(l_module_name, 'EXCEPTION:OTHERS');
1065       END IF;
1066 --
1067 END split_line;
1068 
1069 
1070 
1071 
1072 
1073 --===================
1074 -- PROCEDURES
1075 --===================
1076 
1077 
1078 
1079 
1080 
1081 
1082 
1083 --========================================================================
1084 -- PROCEDURE : Update_Shipping_Attributes
1085 --
1086 -- PARAMETERS: p_api_version_number    known api versionerror buffer
1087 --             p_init_msg_list         initialize message stack
1088 --             x_return_status         return status
1089 --             x_msg_count             number of messages in the list
1090 --             x_msg_data              text of messages
1091 --            p_changed_attributes    changed attributes for delivery details
1092 --             p_source_code           source system
1093 --
1094 --
1095 -- COMMENT   : Validates Organization_id and Organization_code against view
1096 --             org_organization_definitions. If both values are
1097 --             specified then only Org_Id is used
1098 --========================================================================
1099 
1100 PROCEDURE Update_Shipping_Attributes (
1101   -- Standard parameters
1102   p_api_version_number     IN     NUMBER
1103 , p_init_msg_list          IN     VARCHAR2
1104 , p_commit                 IN     VARCHAR2
1105 , x_return_status             OUT NOCOPY  VARCHAR2
1106 , x_msg_count                 OUT NOCOPY  NUMBER
1107 , x_msg_data                  OUT NOCOPY  VARCHAR2
1108 
1109   -- Procedure specific parameters
1110 , p_changed_attributes     IN OUT NOCOPY   WSH_INTERFACE.ChangedAttributeTabType
1111 , p_source_code            IN     VARCHAR2
1112 , p_container_flag         IN     VARCHAR2 DEFAULT NULL
1113 )
1114 IS
1115 
1116   --
1117   l_number_of_errors    NUMBER := 0;
1118   l_number_of_warnings  NUMBER := 0;
1119         l_return_status     VARCHAR2(30);
1120         l_counter   NUMBER;
1121         l_index             NUMBER;
1122         l_api_version_number  NUMBER := 1.0;
1123         l_api_name          VARCHAR2(30) := 'Update_Shipping_Attributes';
1124 
1125         l_msg_count             NUMBER;
1126         l_msg_data              VARCHAR2(32767);
1127         l_detail_info_tab       WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type;
1128         l_detail_in_rec         WSH_GLBL_VAR_STRCT_GRP.detailInRecType;
1129         l_detail_out_rec        WSH_GLBL_VAR_STRCT_GRP.detailOutRecType;
1130         l_dummy_ids             wsh_util_core.id_Tab_type;
1131         invalid_source_code     exception;
1132         mark_reprice_error      exception;
1133         update_failed           exception;
1134 detail_no_found         EXCEPTION;
1135 invalid_released_status EXCEPTION; -- Bug fix  2154620
1136 l_error_detail_id NUMBER;
1137 l_error_attribute VARCHAR2(240);
1138 l_error_attribute_value VARCHAR2(360);
1139 
1140 l_org         NUMBER;
1141 
1142 cursor get_org (p_detail_id in number)is
1143 select organization_id
1144 from wsh_delivery_details
1145 where delivery_detail_id = p_detail_id;
1146 --
1147 l_debug_on BOOLEAN;
1148 --
1149 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'UPDATE_SHIPPING_ATTRIBUTES';
1150 --
1151 BEGIN
1152   --
1153   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
1154   --
1155   IF l_debug_on IS NULL
1156   THEN
1157       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
1158   END IF;
1159   --
1160   SAVEPOINT UPDATE_SHIPPING_ATTR_GRP;
1161   --
1162   -- Debug Statements
1163   --
1164   IF l_debug_on THEN
1165           WSH_DEBUG_SV.push(l_module_name);
1166       --
1167     WSH_DEBUG_SV.log(l_module_name,'P_API_VERSION_NUMBER',P_API_VERSION_NUMBER);
1168     WSH_DEBUG_SV.log(l_module_name,'P_INIT_MSG_LIST',P_INIT_MSG_LIST);
1169     WSH_DEBUG_SV.log(l_module_name,'P_COMMIT',P_COMMIT);
1170     WSH_DEBUG_SV.log(l_module_name,'P_SOURCE_CODE',P_SOURCE_CODE);
1171     WSH_DEBUG_SV.log(l_module_name,'P_CONTAINER_FLAG',P_CONTAINER_FLAG);
1172           WSH_DEBUG_SV.log(l_module_name,'Table Count',p_changed_attributes.COUNT);
1173 
1174   END IF;
1175   --
1176   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1177 
1178   --  Standard call to check for call compatibility
1179     IF NOT FND_API.Compatible_API_Call(
1180     l_api_version_number,
1181     p_api_version_number,
1182     l_api_name,
1183     G_PKG_NAME) THEN
1184     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1185   END IF;
1186 
1187     --  Initialize message stack if required
1188     IF FND_API.to_Boolean(p_init_msg_list) THEN
1189       FND_MSG_PUB.initialize;
1190     END IF;
1191 
1192         -- sperera source_code has to be 'OE' or 'WSH'
1193   IF (NVL(p_source_code, FND_API.G_MISS_CHAR)) NOT IN ('WSH', 'OE') THEN
1194     RAISE invalid_source_code;
1195   END IF;
1196 
1197        -- Patchset I : Harmonization Project.
1198              l_detail_in_rec.action_code := 'UPDATE';
1199 
1200       l_index := p_changed_attributes.FIRST;
1201       WHILE l_index IS NOT NULL LOOP
1202 
1203         OPEN get_org (p_changed_attributes(l_index).delivery_detail_id);
1204         FETCH get_org into l_org;
1205         IF get_org%notfound THEN
1206            CLOSE get_org;
1207            RAISE update_failed;
1208         END IF;
1209         CLOSE get_org;
1210 
1211              IF (wsh_util_validate.Check_Wms_Org(l_org)='Y') THEN
1212                l_detail_in_rec.caller := 'WMS';
1213              ELSE
1214                l_detail_in_rec.caller := 'WSH_GRP';
1215              END IF;
1216 
1217         l_detail_info_tab(l_index).arrival_set_id      :=   p_changed_attributes(l_index).arrival_set_id;
1218         l_detail_info_tab(l_index).ato_line_id      :=   p_changed_attributes(l_index).ato_line_id;
1219         l_detail_info_tab(l_index).attribute_category      :=   p_changed_attributes(l_index).attribute_category;
1220         l_detail_info_tab(l_index).attribute1      :=   p_changed_attributes(l_index).attribute1;
1221         l_detail_info_tab(l_index).attribute10      :=   p_changed_attributes(l_index).attribute10;
1222         l_detail_info_tab(l_index).attribute11      :=   p_changed_attributes(l_index).attribute11;
1223         l_detail_info_tab(l_index).attribute12      :=   p_changed_attributes(l_index).attribute12;
1224         l_detail_info_tab(l_index).attribute13      :=   p_changed_attributes(l_index).attribute13;
1225         l_detail_info_tab(l_index).attribute14      :=   p_changed_attributes(l_index).attribute14;
1226         l_detail_info_tab(l_index).attribute15      :=   p_changed_attributes(l_index).attribute15;
1227         l_detail_info_tab(l_index).attribute2      :=   p_changed_attributes(l_index).attribute2;
1228         l_detail_info_tab(l_index).attribute3      :=   p_changed_attributes(l_index).attribute3;
1229         l_detail_info_tab(l_index).attribute4      :=   p_changed_attributes(l_index).attribute4;
1230         l_detail_info_tab(l_index).attribute5      :=   p_changed_attributes(l_index).attribute5;
1231         l_detail_info_tab(l_index).attribute6      :=   p_changed_attributes(l_index).attribute6;
1232         l_detail_info_tab(l_index).attribute7      :=   p_changed_attributes(l_index).attribute7;
1233         l_detail_info_tab(l_index).attribute8      :=   p_changed_attributes(l_index).attribute8;
1234         l_detail_info_tab(l_index).attribute9      :=   p_changed_attributes(l_index).attribute9;
1235         l_detail_info_tab(l_index).cancelled_quantity      :=   p_changed_attributes(l_index).cancelled_quantity;
1236         l_detail_info_tab(l_index).cancelled_quantity2       :=   p_changed_attributes(l_index).cancelled_quantity2;
1237         l_detail_info_tab(l_index).carrier_id      :=   p_changed_attributes(l_index).carrier_id;
1238         l_detail_info_tab(l_index).classification      :=   p_changed_attributes(l_index).classification    ;
1239         l_detail_info_tab(l_index).commodity_code_cat_id       :=   p_changed_attributes(l_index).commodity_code_cat_id ;
1240         l_detail_info_tab(l_index).container_flag      :=   p_changed_attributes(l_index).container_flag   ;
1241         l_detail_info_tab(l_index).container_name      :=   p_changed_attributes(l_index).container_name   ;
1242         l_detail_info_tab(l_index).container_type_code       :=   p_changed_attributes(l_index).container_type_code   ;
1243         l_detail_info_tab(l_index).country_of_origin      :=   p_changed_attributes(l_index).country_of_origin ;
1244         l_detail_info_tab(l_index).currency_code      :=   p_changed_attributes(l_index).currency_code      ;
1245         l_detail_info_tab(l_index).cust_model_serial_number       :=   p_changed_attributes(l_index).cust_model_serial_number;
1246         l_detail_info_tab(l_index).cust_po_number      :=   p_changed_attributes(l_index).cust_po_number;
1247         l_detail_info_tab(l_index).customer_dock_code      :=   p_changed_attributes(l_index).customer_dock_code;
1248         l_detail_info_tab(l_index).customer_id      :=   p_changed_attributes(l_index).customer_id       ;
1249         l_detail_info_tab(l_index).customer_item_id      :=   p_changed_attributes(l_index).customer_item_id  ;
1250         l_detail_info_tab(l_index).customer_job        :=   p_changed_attributes(l_index).customer_job      ;
1251         l_detail_info_tab(l_index).customer_prod_seq      :=   p_changed_attributes(l_index).customer_prod_seq;
1252         l_detail_info_tab(l_index).customer_production_line       :=   p_changed_attributes(l_index).customer_production_line;
1253         l_detail_info_tab(l_index).customer_requested_lot_flag    :=   p_changed_attributes(l_index).customer_requested_lot_flag;
1254         l_detail_info_tab(l_index).cycle_count_quantity      :=   p_changed_attributes(l_index).cycle_count_quantity ;
1255         l_detail_info_tab(l_index).cycle_count_quantity2       :=   p_changed_attributes(l_index).cycle_count_quantity2   ;
1256         l_detail_info_tab(l_index).date_requested      :=   p_changed_attributes(l_index).date_requested;
1257         l_detail_info_tab(l_index).date_scheduled      :=   p_changed_attributes(l_index).date_scheduled;
1258         l_detail_info_tab(l_index).deliver_to_contact_id      :=   p_changed_attributes(l_index).deliver_to_contact_id;
1259         l_detail_info_tab(l_index).delivered_quantity      :=   p_changed_attributes(l_index).delivered_quantity;
1260         l_detail_info_tab(l_index).delivered_quantity2      :=   p_changed_attributes(l_index).delivered_quantity2   ;
1261         l_detail_info_tab(l_index).delivery_detail_id      :=   p_changed_attributes(l_index).delivery_detail_id;
1262         l_detail_info_tab(l_index).dep_plan_required_flag      :=   p_changed_attributes(l_index).dep_plan_required_flag;
1263         l_detail_info_tab(l_index).detail_container_item_id      :=   p_changed_attributes(l_index).detail_container_item_id;
1264         l_detail_info_tab(l_index).fill_percent      :=   p_changed_attributes(l_index).fill_percent;
1265         l_detail_info_tab(l_index).fob_code      :=   p_changed_attributes(l_index).fob_code;
1266         l_detail_info_tab(l_index).freight_class_cat_id      :=   p_changed_attributes(l_index).freight_class_cat_id;
1267         l_detail_info_tab(l_index).freight_terms_code      :=   p_changed_attributes(l_index).freight_terms_code;
1268         l_detail_info_tab(l_index).gross_weight      :=   p_changed_attributes(l_index).gross_weight;
1269         l_detail_info_tab(l_index).hazard_class_id      :=   p_changed_attributes(l_index).hazard_class_id;
1270         l_detail_info_tab(l_index).hold_code      :=   p_changed_attributes(l_index).hold_code;
1271         l_detail_info_tab(l_index).inspection_flag      :=   p_changed_attributes(l_index).inspection_flag    ;
1272         l_detail_info_tab(l_index).intmed_ship_to_contact_id      :=   p_changed_attributes(l_index).intmed_ship_to_contact_id;
1273         l_detail_info_tab(l_index).inv_interfaced_flag      :=   p_changed_attributes(l_index).inv_interfaced_flag   ;
1274         l_detail_info_tab(l_index).inventory_item_id      :=   p_changed_attributes(l_index).inventory_item_id ;
1275         l_detail_info_tab(l_index).item_description      :=   p_changed_attributes(l_index).item_description  ;
1276         l_detail_info_tab(l_index).load_seq_number      :=   p_changed_attributes(l_index).load_seq_number   ;
1277         l_detail_info_tab(l_index).lot_number      :=   p_changed_attributes(l_index).lot_number;
1278         l_detail_info_tab(l_index).lpn_id      :=   p_changed_attributes(l_index).lpn_id   ;
1279         l_detail_info_tab(l_index).master_container_item_id      :=   p_changed_attributes(l_index).master_container_item_id;
1280         l_detail_info_tab(l_index).master_serial_number      :=   p_changed_attributes(l_index).master_serial_number  ;
1281         l_detail_info_tab(l_index).maximum_load_weight      :=   p_changed_attributes(l_index).maximum_load_weight   ;
1282         l_detail_info_tab(l_index).maximum_volume      :=   p_changed_attributes(l_index).maximum_volume    ;
1283         l_detail_info_tab(l_index).minimum_fill_percent      :=   p_changed_attributes(l_index).minimum_fill_percent  ;
1284         l_detail_info_tab(l_index).move_order_line_id      :=   p_changed_attributes(l_index).move_order_line_id;
1285         l_detail_info_tab(l_index).movement_id      :=   p_changed_attributes(l_index).movement_id ;
1286         l_detail_info_tab(l_index).mvt_stat_status      :=   p_changed_attributes(l_index).mvt_stat_status   ;
1287         l_detail_info_tab(l_index).net_weight      :=   p_changed_attributes(l_index).net_weight;
1288         l_detail_info_tab(l_index).oe_interfaced_flag      :=   p_changed_attributes(l_index).oe_interfaced_flag;
1289         l_detail_info_tab(l_index).org_id      :=   p_changed_attributes(l_index).org_id   ;
1290         l_detail_info_tab(l_index).organization_id      :=   p_changed_attributes(l_index).organization_id   ;
1291         l_detail_info_tab(l_index).original_subinventory      :=   p_changed_attributes(l_index).original_subinventory    ;
1292         l_detail_info_tab(l_index).packing_instructions      :=   p_changed_attributes(l_index).packing_instructions;
1293         l_detail_info_tab(l_index).pickable_flag      :=   p_changed_attributes(l_index).pickable_flag ;
1294         l_detail_info_tab(l_index).picked_quantity      :=   p_changed_attributes(l_index).picked_quantity;
1295         l_detail_info_tab(l_index).picked_quantity2      :=   p_changed_attributes(l_index).picked_quantity2;
1296         l_detail_info_tab(l_index).preferred_grade      :=   p_changed_attributes(l_index).preferred_grade;
1297         l_detail_info_tab(l_index).project_id      :=   p_changed_attributes(l_index).project_id;
1298         l_detail_info_tab(l_index).quality_control_quantity      :=   p_changed_attributes(l_index).quality_control_quantity;
1299         l_detail_info_tab(l_index).quality_control_quantity2      :=   p_changed_attributes(l_index).quality_control_quantity2;
1300         l_detail_info_tab(l_index).received_quantity      :=   p_changed_attributes(l_index).received_quantity;
1301         l_detail_info_tab(l_index).received_quantity2      :=   p_changed_attributes(l_index).received_quantity2;
1302         l_detail_info_tab(l_index).released_status      :=   p_changed_attributes(l_index).released_status;
1303         l_detail_info_tab(l_index).request_id      :=   p_changed_attributes(l_index).request_id;
1304         l_detail_info_tab(l_index).revision      :=   p_changed_attributes(l_index).revision;
1305         l_detail_info_tab(l_index).seal_code      :=   p_changed_attributes(l_index).seal_code;
1306 
1307         l_detail_info_tab(l_index).ship_method_code      :=   p_changed_attributes(l_index).shipping_method_code;
1308         l_detail_info_tab(l_index).ship_model_complete_flag       :=   p_changed_attributes(l_index).ship_model_complete_flag;
1309         l_detail_info_tab(l_index).ship_set_id      :=   p_changed_attributes(l_index).ship_set_id;
1310         l_detail_info_tab(l_index).ship_to_contact_id      :=   p_changed_attributes(l_index).ship_to_contact_id;
1311         l_detail_info_tab(l_index).ship_to_site_use_id      :=   p_changed_attributes(l_index).ship_to_site_use_id   ;
1312         l_detail_info_tab(l_index).ship_tolerance_above      :=   p_changed_attributes(l_index).ship_tolerance_above;
1313         l_detail_info_tab(l_index).ship_tolerance_below      :=   p_changed_attributes(l_index).ship_tolerance_below;
1314         l_detail_info_tab(l_index).shipment_priority_code      :=   p_changed_attributes(l_index).shipment_priority_code;
1315         l_detail_info_tab(l_index).shipped_quantity      :=   p_changed_attributes(l_index).shipped_quantity ;
1316         l_detail_info_tab(l_index).shipped_quantity2      :=   p_changed_attributes(l_index).shipped_quantity2  ;
1317         l_detail_info_tab(l_index).shipping_instructions      :=   p_changed_attributes(l_index).shipping_instructions;
1318         l_detail_info_tab(l_index).sold_to_contact_id      :=   p_changed_attributes(l_index).sold_to_contact_id;
1319         l_detail_info_tab(l_index).source_code      :=   p_changed_attributes(l_index).source_code;
1320         l_detail_info_tab(l_index).source_header_id      :=   p_changed_attributes(l_index).source_header_id;
1321         l_detail_info_tab(l_index).source_header_number      :=   p_changed_attributes(l_index).source_header_number ;
1322         l_detail_info_tab(l_index).source_header_type_id      :=   p_changed_attributes(l_index).source_header_type_id  ;
1323         l_detail_info_tab(l_index).source_header_type_name      :=   p_changed_attributes(l_index).source_header_type_name   ;
1324         l_detail_info_tab(l_index).source_line_id      :=   p_changed_attributes(l_index).source_line_id;
1325         l_detail_info_tab(l_index).source_line_set_id      :=   p_changed_attributes(l_index).source_line_set_id;
1326         l_detail_info_tab(l_index).split_from_detail_id      :=   p_changed_attributes(l_index).split_from_delivery_detail_id ;
1327         l_detail_info_tab(l_index).src_requested_quantity      :=   p_changed_attributes(l_index).src_requested_quantity ;
1328         l_detail_info_tab(l_index).src_requested_quantity_uom      :=   p_changed_attributes(l_index).src_requested_quantity_uom;
1329         l_detail_info_tab(l_index).src_requested_quantity_uom2    :=   p_changed_attributes(l_index).src_requested_quantity_uom2 ;
1330         l_detail_info_tab(l_index).src_requested_quantity2       :=   p_changed_attributes(l_index).src_requested_quantity2 ;
1331         l_detail_info_tab(l_index).subinventory      :=   p_changed_attributes(l_index).subinventory;
1332 -- HW OPMCONV - No need for sublot_number
1333 --      l_detail_info_tab(l_index).sublot_number       :=   p_changed_attributes(l_index).sublot_number  ;
1334         l_detail_info_tab(l_index).task_id      :=   p_changed_attributes(l_index).task_id  ;
1335         l_detail_info_tab(l_index).to_serial_number      :=   p_changed_attributes(l_index).to_serial_number  ;
1336         l_detail_info_tab(l_index).top_model_line_id      :=   p_changed_attributes(l_index).top_model_line_id;
1337         l_detail_info_tab(l_index).tp_attribute_category      :=   p_changed_attributes(l_index).tp_attribute_category      ;
1338         l_detail_info_tab(l_index).tp_attribute1      :=   p_changed_attributes(l_index).tp_attribute1 ;
1339         l_detail_info_tab(l_index).tp_attribute10      :=   p_changed_attributes(l_index).tp_attribute10 ;
1340         l_detail_info_tab(l_index).tp_attribute11      :=   p_changed_attributes(l_index).tp_attribute11  ;
1341         l_detail_info_tab(l_index).tp_attribute12      :=   p_changed_attributes(l_index).tp_attribute12  ;
1342         l_detail_info_tab(l_index).tp_attribute13      :=   p_changed_attributes(l_index).tp_attribute13;
1343         l_detail_info_tab(l_index).tp_attribute14      :=   p_changed_attributes(l_index).tp_attribute14;
1344         l_detail_info_tab(l_index).tp_attribute15      :=   p_changed_attributes(l_index).tp_attribute15 ;
1345         l_detail_info_tab(l_index).tp_attribute2      :=   p_changed_attributes(l_index).tp_attribute2 ;
1346         l_detail_info_tab(l_index).tp_attribute3      :=   p_changed_attributes(l_index).tp_attribute3;
1347         l_detail_info_tab(l_index).tp_attribute4      :=   p_changed_attributes(l_index).tp_attribute4;
1348         l_detail_info_tab(l_index).tp_attribute5      :=   p_changed_attributes(l_index).tp_attribute5;
1349         l_detail_info_tab(l_index).tp_attribute6      :=   p_changed_attributes(l_index).tp_attribute6;
1350         l_detail_info_tab(l_index).tp_attribute7      :=   p_changed_attributes(l_index).tp_attribute7;
1351         l_detail_info_tab(l_index).tp_attribute8      :=   p_changed_attributes(l_index).tp_attribute8;
1352         l_detail_info_tab(l_index).tp_attribute9      :=   p_changed_attributes(l_index).tp_attribute9;
1353         l_detail_info_tab(l_index).tracking_number    :=   p_changed_attributes(l_index).tracking_number;
1354 
1355 -- jckwok Bug 3579965: must check whether transaction_temp_id <> FND_API.G_MISS_NUM also
1356         if (p_changed_attributes(l_index).transaction_temp_id is not null
1357                AND p_changed_attributes(l_index).transaction_temp_id <> FND_API.G_MISS_NUM)  then
1358            l_detail_info_tab(l_index).transaction_temp_id      :=   p_changed_attributes(l_index).transaction_temp_id;
1359         else
1360            l_detail_info_tab(l_index).serial_number      :=   p_changed_attributes(l_index).serial_number;
1361         end if;
1362 
1363         l_detail_info_tab(l_index).unit_price      :=   p_changed_attributes(l_index).unit_price;
1364         l_detail_info_tab(l_index).volume      :=   p_changed_attributes(l_index).volume;
1365         l_detail_info_tab(l_index).volume_uom_code      :=   p_changed_attributes(l_index).volume_uom_code;
1366         l_detail_info_tab(l_index).weight_uom_code      :=   p_changed_attributes(l_index).weight_uom_code;
1367 
1368 
1369           l_index := p_changed_attributes.NEXT(l_index);
1370       END LOOP;
1371 
1372              IF l_debug_on THEN
1373                  WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_INTERFACE_GRP.CREATE_UPDATE_DELIVERY_DETAIL',WSH_DEBUG_SV.C_PROC_LEVEL);
1374              END IF;
1375 
1376        wsh_interface_grp.Create_Update_Delivery_Detail
1377        (
1378           p_api_version_number  => l_api_version_number,
1379           p_init_msg_list          => FND_API.G_FALSE,
1380           p_commit                => FND_API.G_FALSE,
1381           x_return_status         => l_return_status,
1382           x_msg_count             => l_msg_count,
1383           x_msg_data              => l_msg_data,
1384           p_detail_info_tab       => l_detail_info_tab,
1385           p_IN_rec                => l_detail_in_rec,
1386           x_OUT_rec               => l_detail_out_rec
1387        );
1388 
1389                   IF l_debug_on THEN
1390                       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.API_POST_CALL',WSH_DEBUG_SV.C_PROC_LEVEL);
1391                   END IF;
1392                   --
1393                   wsh_util_core.api_post_call(
1394                       p_return_status => l_return_status,
1395                       x_num_warnings  => l_number_of_warnings,
1396                       x_num_errors    => l_number_of_errors,
1397                       p_msg_data      => l_msg_data
1398                       );
1399 
1400 
1401     -- report success
1402   IF FND_API.TO_BOOLEAN(p_commit) THEN
1403     COMMIT WORK;
1404   END IF;
1405 
1406   x_return_status := FND_API.G_RET_STS_SUCCESS;
1407   FND_MSG_PUB.Count_And_Get
1408        ( p_count => x_msg_count,
1409          p_data  => x_msg_data,
1410                p_encoded => FND_API.G_FALSE
1411        );
1412        --
1413        -- Debug Statements
1414        --
1415        IF l_debug_on THEN
1416            WSH_DEBUG_SV.pop(l_module_name);
1417        END IF;
1418        --
1419   EXCEPTION
1420     WHEN mark_reprice_error then
1421                         ROLLBACK TO UPDATE_SHIPPING_ATTR_GRP;
1422       FND_MESSAGE.Set_Name('WSH', 'WSH_REPRICE_REQUIRED_ERR');
1423       x_return_status := l_return_status;
1424     WSH_UTIL_CORE.add_message (x_return_status);
1425     FND_MSG_PUB.Count_And_Get
1426          ( p_count => x_msg_count,
1427            p_data  => x_msg_data,
1428                        p_encoded => FND_API.G_FALSE
1429          );
1430          --
1431          -- Debug Statements
1432          --
1433          IF l_debug_on THEN
1434              WSH_DEBUG_SV.logmsg(l_module_name,'MARK_REPRICE_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
1435              WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:MARK_REPRICE_ERROR');
1436          END IF;
1437          --
1438     WHEN invalid_source_code THEN
1439                         ROLLBACK TO UPDATE_SHIPPING_ATTR_GRP;
1440       x_return_status := FND_API.G_RET_STS_ERROR;
1441                         FND_MESSAGE.Set_Name('WSH', 'WSH_INVALID_SOURCE_CODE');
1442                         WSH_UTIL_CORE.Add_Message(x_return_status);
1443       FND_MSG_PUB.Count_And_Get
1444            ( p_count => x_msg_count,
1445              p_data  => x_msg_data,
1446                                p_encoded => FND_API.G_FALSE
1447            );
1448            --
1449            -- Debug Statements
1450            --
1451            IF l_debug_on THEN
1452                WSH_DEBUG_SV.logmsg(l_module_name,'INVALID_SOURCE_CODE exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
1453                WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:INVALID_SOURCE_CODE');
1454            END IF;
1455            --
1456     WHEN update_failed THEN
1457                         ROLLBACK TO UPDATE_SHIPPING_ATTR_GRP;
1458       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1459       FND_MESSAGE.SET_NAME('WSH', 'WSH_DETAIL_VALIDATION_FAILED');
1460       FND_MESSAGE.SET_TOKEN('ATTRIBUTE', l_error_attribute);
1461       FND_MESSAGE.SET_TOKEN('ATTRB_VALUE', l_error_attribute_value);
1462       FND_MESSAGE.SET_TOKEN('DELIVERY_DETAIL', l_error_detail_id);
1463       WSH_UTIL_CORE.ADD_MESSAGE(x_return_status);
1464       FND_MSG_PUB.Count_And_Get
1465            ( p_count => x_msg_count,
1466              p_data  => x_msg_data,
1467                                p_encoded => FND_API.G_FALSE
1468            );
1469 
1470     -- Bug fix  2154602
1471     IF l_debug_on THEN
1472         WSH_DEBUG_SV.logmsg(l_module_name,'UPDATE_FAILED exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
1473         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:UPDATE_FAILED');
1474     END IF;
1475     --
1476     WHEN invalid_released_status THEN
1477                         ROLLBACK TO UPDATE_SHIPPING_ATTR_GRP;
1478       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1479       WSH_UTIL_CORE.ADD_MESSAGE(x_return_status);
1480       FND_MSG_PUB.Count_And_Get
1481            ( p_count => x_msg_count,
1482              p_data  => x_msg_data,
1483                                p_encoded => FND_API.G_FALSE
1484            );
1485     -- End of Bug fix  2154602
1486 
1487                   IF l_debug_on THEN
1488                      WSH_DEBUG_SV.logmsg(l_module_name,'INVALID_RELEASED_STATUS exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
1489                      WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:INVALID_RELEASED_STATUS');
1490                   END IF;
1491 --
1492                WHEN Others THEN
1493                IF get_org%isopen THEN
1494                   close get_org;
1495                END IF;
1496                         ROLLBACK TO UPDATE_SHIPPING_ATTR_GRP;
1497                x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1498                WSH_UTIL_CORE.add_message (x_return_status);
1499                WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Update_Shipping_Attributes');
1500     FND_MSG_PUB.Count_And_Get
1501            ( p_count => x_msg_count,
1502              p_data  => x_msg_data,
1503                                p_encoded => FND_API.G_FALSE
1504            );
1505                 IF l_debug_on THEN
1506                    WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1507                    WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
1508                 END IF;
1509 --
1510 END Update_Shipping_Attributes;
1511 
1512 PROCEDURE Get_Detail_Status(
1513   p_delivery_detail_id  IN NUMBER
1514 , x_line_status         OUT NOCOPY  VARCHAR2
1515 , x_return_status       OUT NOCOPY  VARCHAR2
1516 )
1517 IS
1518 CURSOR del_assign IS
1519 SELECT delivery_id, parent_delivery_detail_id
1520 FROM wsh_delivery_assignments_v
1521 WHERE delivery_detail_id = p_delivery_detail_id;
1522 l_assign_rec del_assign%ROWTYPE;
1523 
1524 CURSOR del_status(c_del_id NUMBER) IS
1525 SELECT status_code
1526 FROM wsh_new_deliveries
1527 WHERE delivery_id = c_del_id;
1528 
1529 l_del_status  VARCHAR2(100) := NULL;
1530 l_msg_summary VARCHAR2(3000);
1531 x_msg_count   NUMBER;
1532 --
1533 l_debug_on BOOLEAN;
1534 --
1535 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'GET_DETAIL_STATUS';
1536 --
1537 BEGIN
1538   --
1539   -- Debug Statements
1540   --
1541   --
1542   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
1543   --
1544   IF l_debug_on IS NULL
1545   THEN
1546       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
1547   END IF;
1548   --
1549   IF l_debug_on THEN
1550       WSH_DEBUG_SV.push(l_module_name);
1551       --
1552       WSH_DEBUG_SV.log(l_module_name,'P_DELIVERY_DETAIL_ID',P_DELIVERY_DETAIL_ID);
1553   END IF;
1554   --
1555   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1556 
1557   -- get line status for delivery detail
1558   OPEN del_assign;
1559   FETCH del_assign INTO l_assign_rec;
1560   IF (l_assign_rec.delivery_id IS NOT NULL) THEN
1561     OPEN del_status(l_assign_rec.delivery_id);
1562     FETCH del_status INTO l_del_status;
1563     CLOSE del_status;
1564   END IF;
1565   CLOSE del_assign;
1566 
1567   IF (l_del_status IN ('CO', 'IT', 'CL')) THEN
1568     x_line_status := 'SIC';
1569   ELSIF (l_assign_rec.parent_delivery_detail_id IS NOT NULL) THEN
1570     x_line_status := 'PK';
1571   ELSIF( l_assign_rec.parent_delivery_detail_id IS NULL) THEN
1572     x_line_status := 'OK';
1573   ELSE
1574     NULL;
1575   END IF;
1576 
1577 /*
1578   EXCEPTION
1579   WHEN others then
1580     wsh_util_core.default_handler('WSH_DELIVERY_DETAILS_GRP.Get_Detail_Status');
1581     x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1582     WSH_UTIL_CORE.get_messages('Y', l_msg_summary, l_msg_details, x_msg_count);
1583     if x_msg_count > 1 then
1584       x_msg_data := l_msg_summary || l_msg_details;
1585     else
1586       x_msg_data := l_msg_summary;
1587     end if;
1588     */
1589     IF l_debug_on THEN
1590             WSH_DEBUG_SV.log(l_module_name,'X_LINE_STATUS',x_line_status);
1591       WSH_DEBUG_SV.pop(l_module_name);
1592     END IF;
1593     --
1594 END get_detail_status;
1595 
1596 -- ---------------------------------------------------------------------
1597 -- Procedure: Autocreate_Deliveries
1598 --
1599 -- change on 8/24/2005 : p_caller is added
1600 --                       refer to bug 4467032 (R12 Routing Guide)
1601 -- -----------------------------------------------------------------------
1602 PROCEDURE Autocreate_Deliveries(
1603   -- Standard parameters
1604   p_api_version_number     IN     NUMBER
1605 , p_init_msg_list          IN     VARCHAR2
1606 , p_commit                 IN     VARCHAR2
1607 , p_caller                 IN     VARCHAR2 DEFAULT NULL
1608 , x_return_status             OUT NOCOPY  VARCHAR2
1609 , x_msg_count                 OUT NOCOPY  NUMBER
1610 , x_msg_data                  OUT NOCOPY  VARCHAR2
1611 , p_line_rows              IN     WSH_UTIL_CORE.id_tab_type
1612 , p_group_by_header_flag        IN     VARCHAR2
1613 , x_del_rows                  OUT NOCOPY  wsh_util_core.id_tab_type
1614 )
1615 IS
1616 l_dummy_rows               WSH_UTIL_CORE.id_tab_type;
1617 l_api_version_number    NUMBER := 1.0;
1618 l_api_name    CONSTANT  VARCHAR2(30):= 'Autocreate_Deliveries';
1619 l_return_status            VARCHAR2(30);
1620 autocreate_delivery_failed  EXCEPTION;
1621 l_msg_summary varchar2(2000)  := NULL;
1622 l_msg_details varchar2(4000)  := NULL;
1623 --
1624   l_number_of_errors    NUMBER := 0;
1625   l_number_of_warnings  NUMBER := 0;
1626   l_msg_data                  VARCHAR2(32767);
1627 l_debug_on BOOLEAN;
1628 --
1629 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'AUTOCREATE_DELIVERIES';
1630 --
1631 
1632   --
1633   -- Following 4 variables are added for bugfix #4070732
1634   l_api_session_name CONSTANT VARCHAR2(150) := G_PKG_NAME ||'.' || l_module_name;
1635   l_reset_flags BOOLEAN;
1636   --
1637 BEGIN
1638 	-- Bugfix 4070732
1639 	IF WSH_UTIL_CORE.G_START_OF_SESSION_API is null
1640 	THEN
1641 		WSH_UTIL_CORE.G_START_OF_SESSION_API     := l_api_session_name;
1642 		WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API := FALSE;
1643 	END IF;
1644 	-- End of Code Bugfix 4070732
1645   --
1646   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
1647   --
1648   IF l_debug_on IS NULL
1649   THEN
1650       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
1651   END IF;
1652   --
1653   SAVEPOINT  AUTOCREATE_DEL_GRP;
1654 
1655     -- Standard begin of API savepoint
1656   IF l_debug_on THEN
1657       WSH_DEBUG_SV.push(l_module_name);
1658       --
1659       WSH_DEBUG_SV.log(l_module_name,'P_API_VERSION_NUMBER',P_API_VERSION_NUMBER);
1660       WSH_DEBUG_SV.log(l_module_name,'P_INIT_MSG_LIST',P_INIT_MSG_LIST);
1661       WSH_DEBUG_SV.log(l_module_name,'P_COMMIT',P_COMMIT);
1662       WSH_DEBUG_SV.log(l_module_name,'P_LINE_ROWS.COUNT',P_LINE_ROWS.COUNT);
1663   END IF;
1664   --
1665 
1666   IF NOT FND_API.compatible_api_call(
1667     l_api_version_number,
1668     p_api_version_number,
1669     l_api_name,
1670     G_PKG_NAME) THEN
1671     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1672   END IF;
1673 
1674   -- Check p_init_msg_list
1675   IF FND_API.to_boolean(p_init_msg_list)  THEN
1676     FND_MSG_PUB.initialize;
1677   END IF;
1678   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1679 
1680   IF l_debug_on THEN
1681       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_AUTOCREATE.AUTOCREATE_DEL_ACROSS_ORGS',WSH_DEBUG_SV.C_PROC_LEVEL);
1682   END IF;
1683   --
1684   wsh_delivery_autocreate.autocreate_del_across_orgs(
1685     p_line_rows         => p_line_rows,
1686     p_org_rows     => l_dummy_rows, -- bug 1668578
1687     p_container_flag     => 'N',
1688     p_check_flag         => 'N',
1689     p_caller             => p_caller,
1690     p_max_detail_commit  => NULL,
1691     p_group_by_header_flag   => p_group_by_header_flag,
1692     x_del_rows           => x_del_rows,
1693     x_grouping_rows      => l_dummy_rows,
1694     x_return_status      => l_return_status);
1695 
1696   wsh_util_core.api_post_call(
1697      p_return_status => l_return_status,
1698      x_num_warnings  => l_number_of_warnings,
1699      x_num_errors    => l_number_of_errors,
1700      p_msg_data      => l_msg_data
1701      );
1702 
1703   IF l_number_of_warnings > 0 THEN
1704     IF l_debug_on THEN
1705               wsh_debug_sv.log(l_module_name,'Number of warnings', l_number_of_warnings);
1706     END IF;
1707     RAISE WSH_UTIL_CORE.G_EXC_WARNING;
1708   END IF;
1709 
1710 
1711   IF FND_API.TO_BOOLEAN(p_commit) THEN
1712     --
1713     -- Start code for Bugfix 4070732
1714     --
1715 	IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
1716 	   IF l_debug_on THEN
1717 		 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Process_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
1718 	   END IF;
1719            l_reset_flags := FALSE;
1720 
1721 	   WSH_UTIL_CORE.Process_stops_for_load_tender(p_reset_flags   => l_reset_flags,
1722 						       x_return_status => l_return_status);
1723 
1724 	   IF l_debug_on THEN
1725 		WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
1726 	   END IF;
1727 
1728            IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
1729               RAISE FND_API.G_EXC_ERROR;
1730            ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
1731               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1732            ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
1733               RAISE WSH_UTIL_CORE.G_EXC_WARNING;
1734            END IF;
1735 
1736 	END IF;
1737     --
1738     -- End of code for Bugfix 4070732
1739     --
1740     COMMIT WORK;
1741   END IF;
1742 
1743 
1744     --bug 4070732
1745     --End of the API handling of calls to process_stops_for_load_tender
1746     IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name) THEN
1747     --{
1748         IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
1749         --{
1750 
1751            IF FND_API.TO_BOOLEAN(p_commit) THEN
1752 
1753             IF l_debug_on THEN
1754               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
1755             END IF;
1756 
1757             WSH_UTIL_CORE.reset_stops_for_load_tender(p_reset_flags   => TRUE,
1758                                                         x_return_status => l_return_status);
1759 
1760            ELSE
1761 
1762             IF l_debug_on THEN
1763               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Process_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
1764             END IF;
1765 
1766             WSH_UTIL_CORE.Process_stops_for_load_tender(p_reset_flags   => TRUE,
1767                                                         x_return_status => l_return_status);
1768            END IF;
1769 
1770             IF l_debug_on THEN
1771               WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
1772             END IF;
1773 
1774              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
1775                 x_return_status := l_return_status;
1776 
1777               IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,
1778                                    WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1779                 IF NOT(FND_API.TO_BOOLEAN(p_commit)) THEN
1780                  ROLLBACK TO AUTOCREATE_DEL_GRP;
1781 	        end if;
1782               END IF;
1783             END IF;
1784         --}
1785         END IF;
1786     --}
1787     END IF;
1788 
1789     --bug 4070732
1790     --
1791   FND_MSG_PUB.Count_And_Get
1792   (
1793     p_count  => x_msg_count,
1794     p_data  =>  x_msg_data,
1795     p_encoded => FND_API.G_FALSE
1796   );
1797 
1798 
1799        IF l_debug_on THEN
1800           WSH_DEBUG_SV.log(l_module_name,'X_DEL_ROWS.COUNT',x_del_rows.count);
1801           WSH_DEBUG_SV.pop(l_module_name);
1802        END IF;
1803 --
1804   EXCEPTION
1805     WHEN FND_API.G_EXC_ERROR THEN
1806                 ROLLBACK TO AUTOCREATE_DEL_GRP;
1807                 x_return_status := FND_API.G_RET_STS_ERROR ;
1808              --
1809              -- Start code for Bugfix 4070732
1810              --
1811              IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name)
1812              THEN
1813              --{
1814                 IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
1815                 --{
1816                   IF l_debug_on THEN
1817                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
1818                   END IF;
1819 
1820                   WSH_UTIL_CORE.Reset_stops_for_load_tender(p_reset_flags   => TRUE,
1821                      x_return_status => l_return_status);
1822 
1823                   IF l_debug_on THEN
1824                      WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
1825                   END IF;
1826 
1827                   IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1828                      x_return_status := l_return_status;
1829                   END IF;
1830                 --}
1831                 END IF;
1832               --}
1833              END IF;
1834              --
1835              -- End of Code Bugfix 4070732
1836              --
1837                 FND_MSG_PUB.Count_And_Get
1838                   (
1839                      p_count  => x_msg_count,
1840                      p_data  =>  x_msg_data,
1841                p_encoded => FND_API.G_FALSE
1842                   );
1843 
1844 
1845                   IF l_debug_on THEN
1846                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
1847                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_ERROR');
1848                   END IF;
1849                   --
1850 
1851     WHEN autocreate_delivery_failed THEN
1852                 ROLLBACK TO AUTOCREATE_DEL_GRP;
1853                 x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1854                         wsh_util_core.add_message(x_return_status, l_module_name);
1855              --
1856              -- Start code for Bugfix 4070732
1857              --
1858              IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name)
1859              THEN
1860              --{
1861                 IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
1862                 --{
1863                   IF l_debug_on THEN
1864                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
1865                   END IF;
1866 
1867                   WSH_UTIL_CORE.Reset_stops_for_load_tender(p_reset_flags   => TRUE,
1868                      x_return_status => l_return_status);
1869 
1870                   IF l_debug_on THEN
1871                      WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
1872                   END IF;
1873 
1874                   IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1875                      x_return_status := l_return_status;
1876                   END IF;
1877                 --}
1878                 END IF;
1879               --}
1880              END IF;
1881              --
1882              -- End of Code Bugfix 4070732
1883              --
1884 
1885                 FND_MSG_PUB.Count_And_Get
1886                   (
1887                      p_count  => x_msg_count,
1888                      p_data  =>  x_msg_data,
1889                p_encoded => FND_API.G_FALSE
1890                   );
1891 
1892 
1893                 IF l_debug_on THEN
1894                    WSH_DEBUG_SV.logmsg(l_module_name,'AUTOCREATE_DELIVERY_FAILED exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
1895                    WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:AUTOCREATE_DELIVERY_FAILED');
1896                 END IF;
1897 
1898         WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
1899              x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
1900       --
1901       -- Start code for Bugfix 4070732
1902       --
1903        IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name)
1904        THEN
1905        --{
1906           IF NOT (WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API)
1907           THEN
1908           --{
1909 
1910              WSH_UTIL_CORE.Process_stops_for_load_tender(p_reset_flags   => TRUE,
1911                                                          x_return_status => l_return_status);
1912 
1913              IF l_debug_on THEN
1914                   WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
1915              END IF;
1916 
1917              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
1918                 x_return_status := l_return_status;
1919 
1920               IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,
1921                                    WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1922                  ROLLBACK TO AUTOCREATE_DEL_GRP;
1923               END IF;
1924              END IF;
1925           --}
1926           END IF;
1927       ---}
1928       END IF;
1929      --
1930      -- End of Code Bugfix 4070732
1931      --
1932 
1933             FND_MSG_PUB.Count_And_Get
1934              (
1935                p_count  => x_msg_count,
1936                p_data  =>  x_msg_data,
1937                p_encoded => FND_API.G_FALSE
1938              );
1939 
1940 
1941            IF l_debug_on THEN
1942               WSH_DEBUG_SV.logmsg(l_module_name,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ',WSH_DEBUG_SV.C_EXCEP_LEVEL);
1943               WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
1944            END IF;
1945       --
1946         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1947                 ROLLBACK TO AUTOCREATE_DEL_GRP;
1948                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1949 		--
1950 		-- Start of code for Bugfix 4070732
1951 		--
1952 		   IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name) THEN
1953 		      IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
1954 			 IF l_debug_on THEN
1955 			       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
1956 			 END IF;
1957 
1958 			 WSH_UTIL_CORE.Reset_stops_for_load_tender(p_reset_flags   => TRUE,
1959 								   x_return_status => l_return_status);
1960 
1961 
1962 			 IF l_debug_on THEN
1963 			      WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
1964 			 END IF;
1965 
1966 		      END IF;
1967 		   END IF;
1968 		--
1969 		-- End of code for Bugfix 4070732
1970 		--
1971                 FND_MSG_PUB.Count_And_Get
1972                   (
1973                      p_count  => x_msg_count,
1974                      p_data  =>  x_msg_data,
1975                p_encoded => FND_API.G_FALSE
1976                   );
1977                   --
1978            IF l_debug_on THEN
1979                 WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
1980                 WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
1981            END IF;
1982       --
1983         WHEN OTHERS THEN
1984                 ROLLBACK TO AUTOCREATE_DEL_GRP;
1985                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1986                wsh_util_core.add_message(x_return_status, l_module_name);
1987                WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Autocreate_Deliveries');
1988 		--
1989 		-- Start of code for Bugfix 4070732
1990 		--
1991 		   IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name) THEN
1992 		      IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
1993 			 IF l_debug_on THEN
1994 			       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
1995 			 END IF;
1996 
1997 			 WSH_UTIL_CORE.Reset_stops_for_load_tender(p_reset_flags   => TRUE,
1998 								   x_return_status => l_return_status);
1999 
2000 
2001 			 IF l_debug_on THEN
2002 			      WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
2003 			 END IF;
2004 
2005 		      END IF;
2006 		   END IF;
2007 		--
2008 		-- End of code for Bugfix 4070732
2009 		--
2010                 FND_MSG_PUB.Count_And_Get
2011                   (
2012                      p_count  => x_msg_count,
2013                      p_data  =>  x_msg_data,
2014                p_encoded => FND_API.G_FALSE
2015                   );
2016     --
2017             IF l_debug_on THEN
2018                 WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2019                 WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
2020             END IF;
2021    --
2022 END Autocreate_Deliveries;
2023 
2024 PROCEDURE Autocreate_del_trip(
2025   -- Standard parameters
2026   p_api_version_number     IN     NUMBER
2027 , p_init_msg_list          IN     VARCHAR2
2028 , p_commit                 IN     VARCHAR2
2029 , x_return_status             OUT NOCOPY  VARCHAR2
2030 , x_msg_count                 OUT NOCOPY  NUMBER
2031 , x_msg_data                  OUT NOCOPY  VARCHAR2
2032 , p_line_rows              IN     WSH_UTIL_CORE.id_tab_type
2033 , x_del_rows                  OUT NOCOPY  WSH_UTIL_CORE.id_tab_type
2034 , x_trip_rows                   OUT NOCOPY WSH_UTIL_CORE.id_tab_type
2035 )
2036 IS
2037 l_api_name    CONSTANT  VARCHAR2(30):= 'Autocreate_del_trip';
2038 l_api_version_number CONSTANT NUMBER := 1.0;
2039 l_return_status VARCHAR2(30);
2040 autocreate_trip_failed EXCEPTION;
2041 l_msg_summary varchar2(2000)  := NULL;
2042 l_msg_details varchar2(4000)  := NULL;
2043 l_org_rows    wsh_util_core.id_tab_type; -- bug 1668578
2044   l_number_of_errors    NUMBER := 0;
2045   l_number_of_warnings  NUMBER := 0;
2046   l_msg_data                  VARCHAR2(32767);
2047 --
2048 l_debug_on BOOLEAN;
2049 --
2050 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'AUTOCREATE_DEL_TRIP';
2051 --
2052 BEGIN
2053   --
2054   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
2055   --
2056   IF l_debug_on IS NULL
2057   THEN
2058       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
2059   END IF;
2060   --
2061   SAVEPOINT AUTOCREATE_TRIP_GRP;
2062     -- Standard begin of API savepoint
2063 
2064   IF l_debug_on THEN
2065       WSH_DEBUG_SV.push(l_module_name);
2066       --
2067       WSH_DEBUG_SV.log(l_module_name,'P_API_VERSION_NUMBER',P_API_VERSION_NUMBER);
2068       WSH_DEBUG_SV.log(l_module_name,'P_INIT_MSG_LIST',P_INIT_MSG_LIST);
2069       WSH_DEBUG_SV.log(l_module_name,'P_COMMIT',P_COMMIT);
2070       WSH_DEBUG_SV.log(l_module_name,'P_LINE_ROWS.COUNT',P_LINE_ROWS.COUNT);
2071   END IF;
2072   --
2073 
2074   IF NOT FND_API.compatible_api_call(
2075     l_api_version_number,
2076     p_api_version_number,
2077     l_api_name,
2078     G_PKG_NAME) THEN
2079     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2080   END IF;
2081 
2082   -- Check p_init_msg_list
2083   IF FND_API.to_boolean(p_init_msg_list)  THEN
2084     FND_MSG_PUB.initialize;
2085   END IF;
2086   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
2087 
2088   IF l_debug_on THEN
2089       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_TRIPS_ACTIONS.AUTOCREATE_DEL_TRIP',WSH_DEBUG_SV.C_PROC_LEVEL);
2090   END IF;
2091   --
2092   WSH_TRIPS_ACTIONS.autocreate_del_trip(
2093     p_line_rows     => p_line_rows,
2094     p_org_rows    => l_org_rows,  -- bug 1668578
2095     x_del_rows    => x_del_rows,
2096     x_trip_rows   => x_trip_rows,
2097     x_return_status   => l_return_status);
2098 
2099             wsh_util_core.api_post_call(
2100                p_return_status => l_return_status,
2101                x_num_warnings  => l_number_of_warnings,
2102                x_num_errors    => l_number_of_errors,
2103                p_msg_data      => l_msg_data
2104                );
2105 
2106 
2107         IF l_number_of_warnings > 0 THEN
2108            IF l_debug_on THEN
2109               wsh_debug_sv.log(l_module_name,'Number of warnings', l_number_of_warnings);
2110            END IF;
2111            RAISE WSH_UTIL_CORE.G_EXC_WARNING;
2112         END IF;
2113 
2114 
2115                 FND_MSG_PUB.Count_And_Get
2116                   (
2117                      p_count  => x_msg_count,
2118                      p_data  =>  x_msg_data,
2119                      p_encoded => FND_API.G_FALSE
2120                   );
2121 
2122        IF FND_API.TO_BOOLEAN(p_commit) THEN
2123          COMMIT WORK;
2124        END IF;
2125 
2126         IF l_debug_on THEN
2127             WSH_DEBUG_SV.log(l_module_name,'X_DEL_ROWS.COUNT',x_del_rows.count);
2128             WSH_DEBUG_SV.log(l_module_name, 'X trip rows.count', x_trip_rows.count);
2129             WSH_DEBUG_SV.pop(l_module_name);
2130         END IF;
2131 --
2132   EXCEPTION
2133     WHEN FND_API.G_EXC_ERROR THEN
2134                 ROLLBACK TO AUTOCREATE_TRIP_GRP;
2135                 x_return_status := FND_API.G_RET_STS_ERROR ;
2136                 FND_MSG_PUB.Count_And_Get
2137                   (
2138                      p_count  => x_msg_count,
2139                      p_data  =>  x_msg_data,
2140                p_encoded => FND_API.G_FALSE
2141                   );
2142 
2143                   IF l_debug_on THEN
2144                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
2145                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_ERROR');
2146                   END IF;
2147                   --
2148     WHEN autocreate_trip_failed THEN
2149                 ROLLBACK TO AUTOCREATE_TRIP_GRP;
2150                 x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2151                         wsh_util_core.add_message(x_return_status);
2152                 FND_MSG_PUB.Count_And_Get
2153                   (
2154                      p_count  => x_msg_count,
2155                      p_data  =>  x_msg_data,
2156                p_encoded => FND_API.G_FALSE
2157                   );
2158                     IF l_debug_on THEN
2159                       WSH_DEBUG_SV.logmsg(l_module_name,'AUTOCREATE_TRIP_FAILED exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
2160                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:AUTOCREATE_TRIP_FAILED');
2161                   END IF;
2162         --
2163         WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
2164              x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
2165             FND_MSG_PUB.Count_And_Get
2166              (
2167                p_count  => x_msg_count,
2168                p_data  =>  x_msg_data,
2169                p_encoded => FND_API.G_FALSE
2170              );
2171             --
2172            IF l_debug_on THEN
2173               WSH_DEBUG_SV.logmsg(l_module_name,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ',WSH_DEBUG_SV.C_EXCEP_LEVEL);
2174               WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
2175            END IF;
2176       --
2177         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2178                 ROLLBACK TO AUTOCREATE_TRIP_GRP;
2179                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2180                 FND_MSG_PUB.Count_And_Get
2181                   (
2182                      p_count  => x_msg_count,
2183                      p_data  =>  x_msg_data,
2184                p_encoded => FND_API.G_FALSE
2185                   );
2186                   --
2187 
2188            IF l_debug_on THEN
2189                 WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
2190                 WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
2191            END IF;
2192       --
2193         WHEN OTHERS THEN
2194                 ROLLBACK TO AUTOCREATE_TRIP_GRP;
2195                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2196                wsh_util_core.add_message(x_return_status, l_module_name);
2197                WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Autocreate_Del_Trip');
2198                 FND_MSG_PUB.Count_And_Get
2199                   (
2200                      p_count  => x_msg_count,
2201                      p_data  =>  x_msg_data,
2202                p_encoded => FND_API.G_FALSE
2203                   );
2204     --
2205             IF l_debug_on THEN
2206                 WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2207                 WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
2208             END IF;
2209 
2210   --
2211 END Autocreate_del_trip;
2212 
2213 
2214     -- ---------------------------------------------------------------------
2215     -- Procedure: Delivery_Detail_Action
2216     --
2217     -- Parameters:
2218     --
2219     -- Description:  This procedure is the core group API for the
2220     --               delivery_detail_action. This is for called by STF directly.
2221     --         Public API and other product APIs call the wrapper version.
2222     --               The wrapper version, in turn, calls this procedure.
2223     -- Created:   Harmonization Project. Patchset I
2224     -- -----------------------------------------------------------------------
2225     PROCEDURE Delivery_Detail_Action(
2226     -- Standard Parameters
2227        p_api_version_number        IN       NUMBER,
2228        p_init_msg_list             IN       VARCHAR2,
2229        p_commit                    IN       VARCHAR2,
2230        x_return_status             OUT  NOCOPY    VARCHAR2,
2231        x_msg_count                 OUT  NOCOPY    NUMBER,
2232        x_msg_data                  OUT  NOCOPY    VARCHAR2,
2233 
2234     -- Procedure specific Parameters
2235        p_rec_attr_tab              IN     WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type,
2236        p_action_prms               IN     WSH_GLBL_VAR_STRCT_GRP.dd_action_parameters_rec_type,
2237        x_defaults                  OUT  NOCOPY    WSH_GLBL_VAR_STRCT_GRP.dd_default_parameters_rec_type,  -- defaults
2238        x_action_out_rec            OUT  NOCOPY    WSH_GLBL_VAR_STRCT_GRP.dd_action_out_rec_type
2239        ) IS
2240 
2241         l_api_name              CONSTANT VARCHAR2(30)   := 'delivery_detail_action';
2242         l_api_version           CONSTANT NUMBER         := 1.0;
2243         --
2244   --
2245   l_return_status             VARCHAR2(32767);
2246   l1_return_status             VARCHAR2(32767);
2247   l_msg_count                 NUMBER;
2248   l_msg_data                  VARCHAR2(32767);
2249   l_program_name              VARCHAR2(32767);
2250         l_validation_level          NUMBER;
2251         --
2252         --
2253   --
2254   l_number_of_errors    NUMBER := 0;
2255   l_number_of_warnings  NUMBER := 0;
2256         l_counter             NUMBER := 0;
2257         l_index               NUMBER;
2258         check_status          NUMBER;
2259 
2260         -- Variables for pack, unpack, auto-pack
2261         l_group_id_tab     WSH_UTIL_CORE.ID_TAB_TYPE;
2262         l_entity_type      VARCHAR2(32767);
2263         l_cont_flag        VARCHAR2(32767);
2264         l_container_name   VARCHAR2(32767);
2265         l_delivery_flag    VARCHAR2(32767);
2266         l_cont_instance_id NUMBER;
2267 
2268 
2269   -- Variables for cycle_count
2270         l_bo_rows          WSH_UTIL_CORE.Id_Tab_Type;
2271         l_bo_qtys          WSH_UTIL_CORE.Id_Tab_Type;
2272         l_req_qtys         WSH_UTIL_CORE.Id_Tab_Type;
2273         l_bo_qtys2         WSH_UTIL_CORE.Id_Tab_Type;
2274         l_overpick_qtys    WSH_UTIL_CORE.Id_Tab_Type;
2275         l_overpick_qtys2   WSH_UTIL_CORE.Id_Tab_Type;
2276         l_sources          WSH_UTIL_CORE.Column_Tab_Type; -- RTV BO Cons Changes
2277 
2278         --
2279         l_released_status     VARCHAR2(32767);
2280         l_line_direction      VARCHAR2(32767);
2281         l_inventory_item_id   NUMBER;
2282         l_requested_quantity  NUMBER;
2283         l_requested_quantity2 NUMBER;
2284         l_picked_quantity     NUMBER;
2285         l_picked_quantity2    NUMBER;
2286         l_shipped_quantity    NUMBER;
2287         l_shipped_quantity2   NUMBER;
2288         l_inv_item_id         NUMBER;
2289         l_source_code         VARCHAR2(30); -- RTV BO Cons Changes
2290         l_organization_id     NUMBER;
2291         l_requested_quantity_uom            VARCHAR2(32767);
2292 -- HW OPMCONV - Added variable uom2
2293         l_requested_quantity_uom2           VARCHAR2(32767);
2294         l_output_quantity     NUMBER;
2295         l_split_quantity      NUMBER;
2296         l_split_quantity2     NUMBER;
2297         l_manual_split        VARCHAR2(1);
2298         l_converted_flag  VARCHAR2(1); -- HW OPM
2299 
2300         --
2301         l_validation_level_tab WSH_UTIL_CORE.Id_Tab_Type;
2302         l_id_tab               WSH_UTIL_CORE.Id_Tab_Type;
2303         l_dummy_ids            WSH_UTIL_CORE.Id_Tab_Type;
2304         l_request_ids          WSH_UTIL_CORE.Id_Tab_Type;
2305         l_valid_ids            WSH_UTIL_CORE.Id_Tab_Type;
2306         l_error_ids            WSH_UTIL_CORE.Id_Tab_Type;
2307         l_valid_index_tab      WSH_UTIL_CORE.Id_Tab_Type;
2308         l_valid_ids_tab        WSH_UTIL_CORE.Id_Tab_Type;
2309         --
2310         --anxsharm for load tender
2311         l_trip_id_tab          WSH_UTIL_CORE.Id_Tab_Type;
2312 
2313         l_dlvy_organization_id  NUMBER;
2314         l_dlvy_status_code          VARCHAR2(32767);
2315         l_dlvy_planned_flag         VARCHAR2(32767);
2316         l_dlvy_shipment_direction   VARCHAR2(30);
2317         --
2318         l_detail_rec_tab       WSH_DETAILS_VALIDATIONS.detail_rec_tab_type;
2319         l_dlvy_rec_tab         WSH_DELIVERY_VALIDATIONS.dlvy_rec_tab_type;
2320         l_det_id_tab           WSH_UTIL_CORE.ID_TAB_TYPE;
2321         l_detail_group_params  wsh_delivery_autocreate.grp_attr_rec_type;
2322 
2323         l_attr_tab  wsh_delivery_autocreate.grp_attr_tab_type;
2324         l_group_info  wsh_delivery_autocreate.grp_attr_tab_type;
2325         l_action_rec wsh_delivery_autocreate.action_rec_type;
2326         l_target_rec wsh_delivery_autocreate.grp_attr_rec_type;
2327         l_matched_entities wsh_util_core.id_tab_type;
2328         l_out_rec wsh_delivery_autocreate.out_rec_type;
2329 
2330 	-- Consolidation of BO Delivery details project
2331 	l_line_ids	   WSH_UTIL_CORE.Id_Tab_Type;
2332 	l_cons_flags        WSH_UTIL_CORE.Column_Tab_Type;
2333 	l_global_param_rec  WSH_SHIPPING_PARAMS_PVT.Global_Parameters_Rec_Typ;
2334 
2335         CURSOR det_cur(p_del_det_id NUMBER) IS
2336           SELECT inventory_item_id
2337                , organization_id
2338                , requested_quantity_uom
2339                , nvl(line_direction,'O') line_direction -- J-IB-NPARIKH
2340                , released_status
2341           FROM wsh_delivery_details
2342           WHERE delivery_detail_id = p_del_det_id;
2343 
2344 -- HW Harmonization project for OPM. Need to get organization_id
2345 -- HW OPMCONV  - 1) Added retrieval of UOM2 -
2346 --             - 2) Changed name to det_line
2347         CURSOR det_line(l_del_det_id NUMBER) IS
2348           SELECT nvl(line_direction,'O') line_direction, requested_quantity_uom2
2349           FROM wsh_delivery_details
2350           WHERE delivery_detail_id = l_del_det_id;
2351 -- HW OPM end
2352 
2353   --
2354         CURSOR cycle_count_cur(p_del_det_id NUMBER) IS
2355           SELECT released_status, requested_quantity,  requested_quantity2,
2356                  picked_quantity,  picked_quantity2 , shipped_quantity , shipped_quantity2,
2357                  organization_id, inventory_item_id , source_code -- RTV BO Cons Changes
2358           FROM wsh_delivery_details
2359           WHERE delivery_detail_id = p_del_det_id;
2360 
2361         --
2362         CURSOR del_cur(p_dlvy_id NUMBER) IS
2363           SELECT organization_id,
2364                  status_code,
2365                  planned_flag,
2366                  nvl(shipment_direction, 'O'),  -- shipment_direction jckwok
2367                  nvl(ignore_for_planning, 'N'), -- OTM R12 : WSHDEVLS record
2368                  nvl(tms_interface_flag, WSH_NEW_DELIVERIES_PVT.C_TMS_NOT_TO_BE_SENT)                                           -- OTM R12 : WSHDEVLS record
2369           FROM wsh_new_deliveries
2370           WHERE delivery_id = p_dlvy_id;
2371 
2372         --
2373         -- deliveryMerge
2374 
2375         CURSOR get_delivery(p_del_det_id NUMBER) IS
2376           SELECT wda.delivery_id
2377           FROM wsh_delivery_assignments_v wda, wsh_delivery_details wdd
2378           WHERE wdd.delivery_detail_id = p_del_det_id
2379                 AND wdd.delivery_detail_id = wda.delivery_detail_id
2380                 AND wdd.container_flag = 'N'
2381                 AND wdd.source_code = 'OE'
2382                 AND NVL(wdd.line_direction, 'O') in ('O', 'IO');
2383 
2384 l_debug_on BOOLEAN;
2385        --
2386        l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'DELIVERY_DETAIL_ACTION';
2387 
2388 
2389 --Compatibility Changes
2390     l_cc_validate_result    VARCHAR2(1);
2391     l_cc_failed_records     WSH_FTE_COMP_CONSTRAINT_PKG.failed_line_tab_type;
2392     l_cc_line_groups      WSH_FTE_COMP_CONSTRAINT_PKG.line_group_tab_type;
2393     l_cc_group_info     WSH_FTE_COMP_CONSTRAINT_PKG.cc_group_tab_type;
2394 
2395 
2396     b_cc_linefailed     boolean;
2397     b_cc_groupidexists      boolean;
2398     l_id_tab_temp     wsh_util_core.id_tab_type;
2399     l_id_tab_t        wsh_util_core.id_tab_type;
2400     l_cc_count_success      NUMBER;
2401     l_cc_count_group_ids    NUMBER;
2402     l_cc_count_rec      NUMBER;
2403     l_cc_group_ids      wsh_util_core.id_tab_type;
2404 
2405     l_cc_upd_dlvy_intmed_ship_to  VARCHAR2(1);
2406     l_cc_upd_dlvy_ship_method   VARCHAR2(1);
2407     l_cc_dlvy_intmed_ship_to    NUMBER;
2408     l_cc_dlvy_ship_method   VARCHAR2(30);
2409 
2410     l_cc_count_del_rows     NUMBER;
2411     l_num_errors      NUMBER;
2412     l_cc_del_rows     wsh_util_core.id_tab_type;
2413     l_cc_grouping_rows      wsh_util_core.id_tab_type;
2414     l_cc_return_status      VARCHAR2(1);
2415     l_trip_id       NUMBER;
2416 
2417     --dummy tables for calling validate_constraint_mainper
2418     l_cc_del_attr_tab         WSH_NEW_DELIVERIES_PVT.Delivery_Attr_Tbl_Type;
2419     l_cc_det_attr_tab         WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type;
2420     l_cc_trip_attr_tab          WSH_TRIPS_PVT.Trip_Attr_Tbl_Type;
2421     l_cc_stop_attr_tab          WSH_TRIP_STOPS_PVT.Stop_Attr_Tbl_Type;
2422     l_cc_in_ids           wsh_util_core.id_tab_type;
2423     l_cc_fail_ids   wsh_util_core.id_tab_type;
2424 
2425     l_delivery_detail_id  NUMBER;
2426 
2427     CURSOR c_delcur(p_dlvy_id NUMBER) IS
2428     SELECT SHIP_METHOD_CODE, INTMED_SHIP_TO_LOCATION_ID
2429     FROM wsh_new_deliveries
2430     WHERE delivery_id = p_dlvy_id;
2431 
2432 --Compatibility Changes
2433 
2434     l_action_code VARCHAR2(32767);
2435 --
2436     -- deliveryMerge
2437     l_delivery_ids   wsh_util_core.id_tab_type;
2438     l_delivery_id    NUMBER;
2439     l_delivery_already_included boolean;
2440     --
2441     --
2442     l_cnt            NUMBER;
2443     l_action_prms    WSH_GLBL_VAR_STRCT_GRP.dd_action_parameters_rec_type;
2444     --
2445 
2446     l_dummy_line_ids    WSH_UTIL_CORE.Id_Tab_Type;
2447 
2448     e_end_of_api     EXCEPTION;
2449     --dcp
2450     l_check_dcp NUMBER;
2451 --Bugfix 4070732
2452     l_api_session_name CONSTANT VARCHAR2(150) := G_PKG_NAME ||'.' || l_module_name;
2453     l_reset_flags BOOLEAN;
2454 
2455     -- K LPN CONV. rv
2456     l_lpn_in_sync_comm_rec WSH_GLBL_VAR_STRCT_GRP.lpn_sync_comm_in_rec_type;
2457     l_lpn_out_sync_comm_rec WSH_GLBL_VAR_STRCT_GRP.lpn_sync_comm_out_rec_type;
2458     -- K LPN CONV. rv
2459     --
2460 
2461     -- OTM R12 : due to record changes in WSHDEVLS
2462     l_dlvy_ignore         WSH_NEW_DELIVERIES.IGNORE_FOR_PLANNING%TYPE;
2463     l_tms_interface_flag  WSH_NEW_DELIVERIES.TMS_INTERFACE_FLAG%TYPE;
2464     -- End of OTM R12 : due to record changes in WSHDEVLS
2465 
2466     -- OTM R12 : packing ECO
2467     l_gc3_is_installed    VARCHAR2(1);
2468     -- End of OTM R12 : packing ECO
2469 
2470 
2471   BEGIN
2472        --dcp
2473        <<api_start>>
2474 
2475 	-- Bugfix 4070732
2476 	IF WSH_UTIL_CORE.G_START_OF_SESSION_API is null
2477 	THEN
2478 		WSH_UTIL_CORE.G_START_OF_SESSION_API     := l_api_session_name;
2479 		WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API := FALSE;
2480 	END IF;
2481 	-- End of Code Bugfix 4070732
2482 
2483         -- Standard Start of API savepoint
2484         --
2485         l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
2486         --
2487         IF l_debug_on IS NULL
2488         THEN
2489             l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
2490         END IF;
2491         --
2492         SAVEPOINT   DELIVERY_DETAIL_ACTION_GRP;
2493 
2494        l_check_dcp := WSH_DCP_PVT.G_CHECK_DCP;
2495 
2496        if l_check_dcp is null then
2497           l_check_dcp := wsh_dcp_pvt.is_dcp_enabled;
2498        end if;
2499 
2500         --
2501         -- Debug Statements
2502         --
2503         IF l_debug_on THEN
2504             WSH_DEBUG_SV.push(l_module_name);
2505             --
2506             WSH_DEBUG_SV.log(l_module_name,'P_API_VERSION_NUMBER',P_API_VERSION_NUMBER);
2507             WSH_DEBUG_SV.log(l_module_name,'P_INIT_MSG_LIST',P_INIT_MSG_LIST);
2508             WSH_DEBUG_SV.log(l_module_name,'P_COMMIT',P_COMMIT);
2509             WSH_DEBUG_SV.log(l_module_name, 'Caller', p_action_prms.caller);
2510             WSH_DEBUG_SV.log(l_module_name, 'Phase', p_action_prms.phase);
2511             WSH_DEBUG_SV.log(l_module_name, 'Action Code', p_action_prms.action_code);
2512             WSH_DEBUG_SV.log(l_module_name, 'Input Table count', p_rec_attr_tab.count);
2513         END IF;
2514         --
2515         -- Initialize message list if p_init_msg_list is set to TRUE.
2516   --
2517         IF FND_API.to_Boolean( p_init_msg_list )
2518   THEN
2519                 FND_MSG_PUB.initialize;
2520         ELSE
2521            IF nvl(l_check_dcp, -99) IN (1,2) THEN
2522                 WSH_DCP_PVT.G_INIT_MSG_COUNT := fnd_msg_pub.count_msg;
2523            END IF;
2524         END IF;
2525   --
2526         --  Initialize API return status to success
2527   x_return_status       := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
2528   l_number_of_errors := 0;
2529   l_number_of_warnings := 0;
2530 
2531        -- deliveryMerge
2532        l_delivery_ids.delete;
2533 
2534         -- Mandatory parameters check
2535         IF( p_action_prms.caller IS NULL) THEN
2536             FND_MESSAGE.SET_NAME('WSH', 'WSH_REQUIRED_FIELD_NULL');
2537             FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'CALLER');
2538             wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
2539            IF l_debug_on THEN
2540               wsh_debug_sv.logmsg(l_module_name,'Null Caller');
2541            END IF;
2542            RAISE FND_API.G_EXC_ERROR;
2543         ELSIF(p_action_prms.action_code IS NULL) THEN
2544            FND_MESSAGE.SET_NAME('WSH', 'WSH_REQUIRED_FIELD_NULL');
2545            FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'ACTION_CODE');
2546             wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
2547            IF l_debug_on THEN
2548               wsh_debug_sv.logmsg(l_module_name,'WSH_INVALID_ACTION_CODE');
2549            END IF;
2550            RAISE FND_API.G_EXC_ERROR;
2551         END IF;
2552 
2553         IF(p_rec_attr_tab.count = 0) THEN
2554            IF l_debug_on THEN
2555               wsh_debug_sv.logmsg(l_module_name,'Table count zero');
2556            END IF;
2557            RAISE FND_API.G_EXC_ERROR;
2558         END IF;
2559         --
2560         -- bug 2788946
2561         -- This condition is added so that we treat these actions
2562         -- as equivalent to "PICK-RELEASE" ONLY during
2563         -- setting the levels and validating the eligibility of the action
2564         IF p_action_prms.action_code IN ('PICK-SHIP', 'PICK-PACK-SHIP') THEN
2565             l_action_code := 'PICK-RELEASE';
2566         ELSE
2567             l_action_code := p_action_prms.action_code;
2568         END IF;
2569         --
2570         --
2571         -- J-IB-NPARIKH-{
2572         --
2573         IF l_action_code = 'SPLIT_DELIVERY'
2574         THEN
2575         --{
2576             l_action_prms := p_action_prms;
2577             --
2578             l_action_prms.caller       := p_action_prms.caller || WSH_UTIL_CORE.C_SPLIT_DLVY_SUFFIX;
2579             l_action_prms.action_code  := 'UNASSIGN';
2580             --
2581             Delivery_Detail_Action
2582                 (
2583                    p_api_version_number     => p_api_version_number,
2584                    p_init_msg_list          => FND_API.G_FALSE,
2585                    p_commit                 => FND_API.G_FALSE,
2586                    x_return_status          => l_return_status,
2587                    x_msg_count              => l_msg_count,
2588                    x_msg_data               => l_msg_data,
2589                    p_rec_attr_tab           => p_rec_attr_tab,
2590                    p_action_prms            => l_action_prms,
2591                    x_defaults               => x_defaults,
2592                    x_action_out_rec         => x_action_out_rec
2593                 );
2594             --
2595             --
2596             wsh_util_core.api_post_call
2597               (
2598                 p_return_status => l_return_status,
2599                 x_num_warnings  => l_number_of_warnings,
2600                 x_num_errors    => l_number_of_errors,
2601                 p_msg_data      => l_msg_data
2602               );
2603             --
2604             --
2605             l_action_prms.caller       := p_action_prms.caller || WSH_UTIL_CORE.C_SPLIT_DLVY_SUFFIX;
2606             --
2607             --
2608             IF  p_action_prms.delivery_id IS NULL
2609             AND p_action_prms.delivery_name IS NULL
2610             THEN
2611                 l_action_prms.action_code  := 'AUTOCREATE-DEL';
2612             ELSE
2613                 l_action_prms.action_code  := 'ASSIGN';
2614             END IF;
2615             --
2616             Delivery_Detail_Action
2617                 (
2618                    p_api_version_number     => p_api_version_number,
2619                    p_init_msg_list          => FND_API.G_FALSE,
2620                    p_commit                 => FND_API.G_FALSE,
2621                    x_return_status          => l_return_status,
2622                    x_msg_count              => l_msg_count,
2623                    x_msg_data               => l_msg_data,
2624                    p_rec_attr_tab           => p_rec_attr_tab,
2625                    p_action_prms            => l_action_prms,
2626                    x_defaults               => x_defaults,
2627                    x_action_out_rec         => x_action_out_rec
2628                 );
2629             --
2630             --
2631             wsh_util_core.api_post_call
2632               (
2633                 p_return_status => l_return_status,
2634                 x_num_warnings  => l_number_of_warnings,
2635                 x_num_errors    => l_number_of_errors,
2636                 p_msg_data      => l_msg_data
2637               );
2638             --
2639             RAISE e_end_of_api;
2640         --}
2641         END IF;
2642         --
2643         -- J-IB-NPARIKH-}
2644         --
2645         --
2646         --
2647         -- Set validation level
2648         IF l_debug_on THEN
2649             WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_ACTIONS_LEVELS.SET_VALIDATION_LEVEL',WSH_DEBUG_SV.C_PROC_LEVEL);
2650             WSH_DEBUG_SV.log(l_module_name,'l_action_code',l_action_code);
2651         END IF;
2652         --
2653         wsh_actions_levels.set_validation_level(
2654             p_entity           => 'DLVB',
2655             p_caller           => p_action_prms.caller,
2656             p_phase            => nvl(p_action_prms.phase,1),
2657             p_action           => l_action_code,
2658             x_return_status    => l_return_status
2659         );
2660 
2661             --
2662             IF l_debug_on THEN
2663                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.API_POST_CALL',WSH_DEBUG_SV.C_PROC_LEVEL);
2664             END IF;
2665             --
2666             wsh_util_core.api_post_call(
2667                p_return_status => l_return_status,
2668                x_num_warnings  => l_number_of_warnings,
2669                x_num_errors    => l_number_of_errors,
2670                p_msg_data      => l_msg_data
2671                );
2672 
2673         l_validation_level_tab := wsh_actions_levels.g_validation_level_tab;
2674 
2675         -- Need to create l_detail_rec_tab to call Is_Action_Enabled
2676 
2677         l_index := p_rec_attr_tab.FIRST;
2678         while l_index is not null
2679         loop
2680 
2681             IF NVL(p_action_prms.phase,1) = 1 THEN
2682                   l_detail_rec_tab(l_index).delivery_detail_id := p_rec_attr_tab(l_index).delivery_detail_id;
2683                   l_detail_rec_tab(l_index).organization_id    := p_rec_attr_tab(l_index).organization_id;
2684                   l_detail_rec_tab(l_index).released_status    := p_rec_attr_tab(l_index).released_status;
2685                   l_detail_rec_tab(l_index).container_flag     := p_rec_attr_tab(l_index).container_flag;
2686                   l_detail_rec_tab(l_index).source_code        := p_rec_attr_tab(l_index).source_code;
2687                   l_detail_rec_tab(l_index).lpn_id             := p_rec_attr_tab(l_index).lpn_id;
2688                   -- J Inbound Logistics: need to populate line_direction,sf_locn_id before calling Is_Action_Enabled
2689                   l_detail_rec_tab(l_index).line_direction     := p_rec_attr_tab(l_index).line_direction;
2690                   -- J-IB-NPARIKH
2691                   --
2692                   -- Populate ship from location from database
2693                   -- so that it can be utlized to validate if actions
2694                   -- are enabled/disabled.
2695                   --
2696                   l_detail_rec_tab(l_index).ship_from_location_id := p_rec_attr_tab(l_index).ship_from_location_id;
2697 
2698                   -- R12, X-dock
2699                   l_detail_rec_tab(l_index).move_order_line_id := p_rec_attr_tab(l_index).move_order_line_id;
2700 
2701             END IF;
2702             l_id_tab(l_index) := p_rec_attr_tab(l_index).delivery_detail_id;
2703             l_index := p_rec_attr_tab.NEXT(l_index);
2704         END LOOP;
2705 
2706 
2707         -- Call Is_Action_Enabled API depending on validation level
2708         IF l_validation_level_tab(wsh_actions_levels.C_ACTION_ENABLED_LVL) = 1  THEN
2709             --
2710             IF l_debug_on THEN
2711                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DETAILS_VALIDATIONS.IS_ACTION_ENABLED',WSH_DEBUG_SV.C_PROC_LEVEL);
2712             END IF;
2713             --
2714             WSH_DETAILS_VALIDATIONS.Is_Action_Enabled(
2715                 p_del_detail_rec_tab    => l_detail_rec_tab,
2716                 p_action                => l_action_code,
2717                 p_caller                => p_action_prms.caller,
2718                 p_deliveryid            => p_action_prms.delivery_id,
2719                 x_return_status         => l_return_status,
2720                 x_valid_ids             => l_valid_ids,
2721                 x_error_ids             => l_error_ids,
2722                 x_valid_index_tab       => l_valid_index_tab
2723                );
2724 
2725                IF l_debug_on THEN
2726                   wsh_debug_sv.log(l_module_name,'Is_Action_Enabled returns',
2727                                                          l_return_status);
2728                END IF;
2729             --
2730             wsh_util_core.api_post_call(
2731                p_return_status => l_return_status,
2732                x_num_warnings  => l_number_of_warnings,
2733                x_num_errors    => l_number_of_errors,
2734                p_msg_data      => l_msg_data,
2735                p_raise_error_flag => FALSE
2736                );
2737         END IF;
2738 
2739         IF(l_number_of_errors >0 ) THEN
2740          --{
2741          IF p_action_prms.caller = 'WSH_FSTRX' THEN
2742             FND_MESSAGE.SET_NAME('WSH', 'WSH_DISABLE_ACTION');
2743             wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
2744          END IF;
2745          --
2746          IF l_debug_on THEN
2747              wsh_debug_sv.logmsg(l_module_name, 'WSH_DISABLE_ACTION');
2748          END IF;
2749          --
2750          raise FND_API.G_EXC_ERROR;
2751          --}
2752         END IF;
2753 
2754         IF( l_validation_level_tab(wsh_actions_levels.C_DLVY_ACTION_ENABLED_LVL) = 1) THEN
2755 
2756       --
2757             IF(p_action_prms.delivery_id IS NOT NULL) THEN
2758 
2759                OPEN del_cur(p_action_prms.delivery_id);
2760                FETCH del_cur INTO l_dlvy_organization_id, l_dlvy_status_code,
2761                                   l_dlvy_planned_flag,
2762                                   l_dlvy_shipment_direction,
2763                                   l_dlvy_ignore,        -- OTM R12 : WSHDEVLS
2764                                   l_tms_interface_flag; -- OTM R12 : WSHDEVLS
2765 
2766                IF del_cur%NOTFOUND THEN
2767                   CLOSE del_cur;
2768                   FND_MESSAGE.SET_NAME('WSH', 'WSH_INVALID_DELIVERY');
2769                   FND_MESSAGE.SET_TOKEN('DELIVERY', p_action_prms.delivery_id);
2770                  wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
2771                   IF l_debug_on THEN
2772                      wsh_debug_sv.logmsg(l_module_name, 'Delivery does not exist');
2773                   END IF;
2774                   RAISE FND_API.G_EXC_ERROR;
2775                END IF;
2776                CLOSE del_cur;
2777             ELSE
2778                FND_MESSAGE.SET_NAME('WSH', 'WSH_REQUIRED_FIELD_NULL');
2779                FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'DELIVERY_ID');
2780             wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
2781                IF l_debug_on THEN
2782                   wsh_debug_sv.logmsg(l_module_name, 'Null Delivery Id');
2783                END IF;
2784                RAISE FND_API.G_EXC_ERROR;
2785             END IF;
2786 
2787             l_dlvy_rec_tab(1).delivery_id     :=  p_action_prms.delivery_id;
2788             l_dlvy_rec_tab(1).organization_id :=  l_dlvy_organization_id;
2789             l_dlvy_rec_tab(1).status_code     :=  l_dlvy_status_code;
2790             l_dlvy_rec_tab(1).planned_flag    :=  l_dlvy_planned_flag;
2791             -- J Inbound jckwok
2792             l_dlvy_rec_tab(1).shipment_direction  := l_dlvy_shipment_direction;
2793             -- call dlvy's action enabled.
2794 
2795             -- OTM R12 : due to record changes in WSHDEVLS
2796             l_dlvy_rec_tab(1).ignore_for_planning :=  l_dlvy_ignore;
2797             l_dlvy_rec_tab(1).tms_interface_flag  :=  l_tms_interface_flag;
2798             -- End of OTM R12 : due to record changes in WSHDEVLS
2799 
2800                --
2801 
2802                IF l_debug_on THEN
2803                    WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_VALIDATIONS.IS_ACTION_ENABLED',WSH_DEBUG_SV.C_PROC_LEVEL);
2804                END IF;
2805                --
2806                wsh_delivery_validations.Is_Action_Enabled(
2807                 p_dlvy_rec_tab          => l_dlvy_rec_tab,
2808                 p_action                => p_action_prms.action_code,
2809                 p_caller                => p_action_prms.caller,
2810                 x_return_status         => l_return_status,
2811                 x_valid_ids             => l_valid_ids,
2812                 x_error_ids             => l_error_ids,
2813                 x_valid_index_tab       => l_valid_index_tab
2814                );
2815                --
2816             wsh_util_core.api_post_call(
2817                p_return_status => l_return_status,
2818                x_num_warnings  => l_number_of_warnings,
2819                x_num_errors    => l_number_of_errors,
2820                p_msg_data      => l_msg_data,
2821                p_raise_error_flag => FALSE
2822                );
2823 
2824             IF p_action_prms.caller = 'WSH_FSTRX' THEN
2825                  x_action_out_rec.valid_id_tab := l_valid_index_tab;
2826             ELSE
2827                  x_action_out_rec.valid_id_tab := l_valid_ids;
2828             END IF;
2829             --
2830         END IF;
2831 
2832         -- Lock records
2833         IF  l_validation_level_tab(wsh_actions_levels.C_LOCK_RECORDS_LVL) = 1 THEN
2834 
2835             -- we need to send only the valid records to lock procedure
2836             -- Build the table using the valid index output from Is_Action_Enabled
2837             IF l_debug_on THEN
2838                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_PKG.LOCK_DELIVERY_DETAILS',WSH_DEBUG_SV.C_PROC_LEVEL);
2839             END IF;
2840 	 IF  NOT (    p_action_prms.caller = 'WSH_FSTRX'
2841                   AND p_action_prms.action_code =  'DELETE'
2842                   ) THEN  --BUG 4354579
2843             wsh_delivery_details_pkg.Lock_Delivery_Details(
2844                p_rec_attr_tab          => p_rec_attr_tab,
2845                p_caller                => p_action_prms.caller,
2846                p_valid_index_tab       => l_valid_index_tab,
2847                x_valid_ids_tab         => l_valid_ids_tab,
2848                x_return_status         => l_return_status
2849                );
2850 
2851               x_action_out_rec.valid_id_tab := l_valid_ids_tab;
2852 
2853             --
2854             wsh_util_core.api_post_call(
2855                p_return_status => l_return_status,
2856                x_num_warnings  => l_number_of_warnings,
2857                x_num_errors    => l_number_of_errors,
2858                p_msg_data      => l_msg_data,
2859                p_raise_error_flag => FALSE
2860                );
2861 	 END IF;
2862         END IF;
2863 
2864         --
2865        IF(l_number_of_errors >0 ) THEN
2866            FND_MESSAGE.SET_NAME('WSH', 'WSH_DISABLE_ACTION');
2867             wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
2868            IF l_debug_on THEN
2869                wsh_debug_sv.logmsg(l_module_name, 'WSH_DISABLE_ACTION');
2870            END IF;
2871            RAISE FND_API.G_EXC_ERROR;
2872        END IF;
2873          --
2874          IF l_number_of_warnings > 0 THEN
2875 
2876            FND_MESSAGE.SET_NAME('WSH', 'WSH_DISABLE_ACTION_WARN');
2877             wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
2878            IF l_debug_on THEN
2879                wsh_debug_sv.logmsg(l_module_name, 'WSH_DISABLE_ACTION_WARN');
2880             END IF;
2881 
2882             IF(p_action_prms.caller = 'WSH_FSTRX') THEN
2883                  x_action_out_rec.selection_issue_flag := 'Y';
2884                  RAISE WSH_UTIL_CORE.G_EXC_WARNING;
2885             ELSE
2886                IF l_debug_on THEN
2887                   wsh_debug_sv.log(l_module_name,'Number of warnings', l_number_of_warnings);
2888                END IF;
2889                  RAISE FND_API.G_EXC_ERROR;
2890             END IF;
2891          END IF;
2892 
2893 
2894     IF l_validation_level_tab(wsh_actions_levels.C_VALIDATE_CONSTRAINTS_LVL) = 1
2895     THEN --{
2896 
2897    --Compatibility Changes
2898     -- Autocreate trip calls autocreate del and then autocreate trip so the constraint validation
2899     -- will be done at that point (in private API)
2900     -- actions PACK, AUTO-PACK, AUTO-PACK-MASTER only post-I (constraints for these have not been implemented yet)
2901 
2902        IF wsh_util_core.fte_is_installed = 'Y' THEN
2903 
2904           WSH_FTE_COMP_CONSTRAINT_PKG.validate_constraint_main(
2905           p_api_version_number =>  1.0,
2906           p_init_msg_list      =>  FND_API.G_FALSE,
2907           p_entity_type        =>  'L',
2908           p_target_id          =>  p_action_prms.DELIVERY_ID,
2909           p_action_code        =>  p_action_prms.action_code,
2910           p_del_attr_tab       =>  l_cc_del_attr_tab,
2911           p_det_attr_tab       =>  p_rec_attr_tab,
2912           p_trip_attr_tab      =>  l_cc_trip_attr_tab,
2913           p_stop_attr_tab      =>  l_cc_stop_attr_tab,
2914           p_in_ids             =>  l_cc_in_ids,
2915           x_fail_ids           =>  l_cc_fail_ids,
2916           x_validate_result          =>  l_cc_validate_result,
2917           x_failed_lines             =>  l_cc_failed_records,
2918           x_line_groups              =>  l_cc_line_groups,
2919           x_group_info               =>  l_cc_group_info,
2920           x_msg_count                =>  l_msg_count,
2921           x_msg_data                 =>  l_msg_data,
2922           x_return_status            =>  l_return_status);
2923 
2924          IF l_debug_on THEN
2925            wsh_debug_sv.log(l_module_name,'Return Status After Calling validate_constraint_main',l_return_status);
2926            wsh_debug_sv.log(l_module_name,'validate_result After Calling validate_constraint_main',l_cc_validate_result);
2927            wsh_debug_sv.log(l_module_name,'msg_count After Calling validate_constraint_main',l_msg_count);
2928            wsh_debug_sv.log(l_module_name,'msg_data After Calling validate_constraint_main',l_msg_data);
2929            wsh_debug_sv.log(l_module_name,'fail_ids count After Calling validate_constraint_main',l_cc_failed_records.COUNT);
2930            wsh_debug_sv.log(l_module_name,'l_cc_line_groups.count count After Calling validate_constraint_main',l_cc_line_groups.COUNT);
2931            wsh_debug_sv.log(l_module_name,'group_info count After Calling validate_constraint_main',l_cc_group_info.COUNT);
2932          END IF;
2933          --
2934 
2935         IF l_return_status=wsh_util_core.g_ret_sts_error  THEN
2936            --fix p_rec_attr_tab to have only successful records
2937            l_cc_count_success:=1;
2938 
2939            IF l_debug_on THEN
2940                wsh_debug_sv.log(l_module_name,'p_rec_attr_tab count before removing failed lines',p_rec_attr_tab.COUNT);
2941            END IF;
2942 
2943            IF l_cc_failed_records.COUNT>0 AND p_rec_attr_tab.COUNT>0 THEN
2944 
2945              --set return_status as warning
2946              IF l_cc_failed_records.COUNT<>p_rec_attr_tab.COUNT THEN
2947                 l_return_status:=wsh_util_core.g_ret_sts_warning;
2948              END IF;
2949 
2950              FOR i in p_rec_attr_tab.FIRST..p_rec_attr_tab.LAST LOOP
2951                b_cc_linefailed:=FALSE;
2952                FOR j in l_cc_failed_records.FIRST..l_cc_failed_records.LAST LOOP
2953                    IF (p_rec_attr_tab(i).delivery_detail_id=l_cc_failed_records(j).entity_line_id) THEN
2954                      b_cc_linefailed:=TRUE;
2955                      FND_MESSAGE.SET_NAME('WSH','WSH_DELDET_COMP_FAILED');
2956                      FND_MESSAGE.SET_TOKEN('DELDET_ID',l_cc_failed_records(j).entity_line_id);
2957                      wsh_util_core.add_message(l_return_status);
2958                    END IF;
2959                END LOOP;
2960                IF (NOT(b_cc_linefailed)) THEN
2961                  l_id_tab_t(l_cc_count_success):=p_rec_attr_tab(i).delivery_detail_id;
2962                  l_cc_count_success:=l_cc_count_success+1;
2963                END IF;
2964              END LOOP;
2965 
2966              --bsadri for assign, if one line fails, then fail all lines {
2967              IF l_action_code = 'ASSIGN'
2968                 AND l_cc_failed_records.COUNT > 0 THEN
2969                 l_id_tab_t.DELETE;
2970                 l_return_status := wsh_util_core.g_ret_sts_error;
2971              END IF;
2972              --}
2973 
2974              IF l_id_tab_t.COUNT>0 THEN
2975                 l_id_tab:=l_id_tab_t;
2976              ELSE
2977                 IF l_debug_on THEN
2978                   wsh_debug_sv.logmsg(l_module_name,'all lines errored in compatibility check');
2979                 END IF;
2980                 wsh_util_core.api_post_call(
2981                     p_return_status    => l_return_status,
2982                     x_num_warnings     => l_number_of_warnings,
2983                     x_num_errors       => l_num_errors,
2984                     p_msg_data         => l_msg_data);
2985              END IF;
2986 
2987              IF l_debug_on THEN
2988                 wsh_debug_sv.log(l_module_name,'l_id_tab count after removing failed lines',l_id_tab.COUNT);
2989              END IF;
2990 
2991            END IF;
2992 
2993         ELSIF l_return_status=wsh_util_core.g_ret_sts_unexp_error THEN
2994            wsh_util_core.api_post_call(
2995               p_return_status    => l_return_status,
2996               x_num_warnings     => l_number_of_warnings,
2997               x_num_errors       => l_num_errors,
2998               p_msg_data         => l_msg_data);
2999         END IF;
3000 
3001          wsh_util_core.api_post_call(
3002            p_return_status    => l_return_status,
3003            x_num_warnings     => l_number_of_warnings,
3004            x_num_errors       => l_num_errors,
3005            p_msg_data         => l_msg_data,
3006            p_raise_error_flag => FALSE);
3007 
3008        END IF;
3009        --Compatibility Changes
3010     END IF; --}
3011 
3012 
3013 
3014 
3015 -- HW OPM BUG#:2677054
3016 -- Need this part to be used by form and public API
3017        IF ( nvl(p_action_prms.phase,1) = 1 ) AND  (p_action_prms.action_code ='SPLIT-LINE' ) THEN
3018 
3019            OPEN  det_cur(l_id_tab(l_id_tab.first));
3020            FETCH det_cur
3021            INTO l_inv_item_id
3022            , l_organization_id
3023            , l_requested_quantity_uom
3024            , l_line_direction
3025            , l_released_status
3026            ;
3027            CLOSE det_cur;
3028 
3029 -- Check for if line belongs to OPM
3030 -- HW OPMCONV - Removed checking for process
3031              IF (l_line_direction IN ('O','IO') -- J-IB-NPARIKH
3032                ) THEN
3033 -- Check if line is allocated , check is required only for outbound lines
3034 -- HW OPMCONV - Removed call to old OPM API is_line_allocated
3035 -- and replaced it with is_split_allowed
3036 
3037 -- Check if split is allowed
3038 -- HW OPMCONV - New WSH API to check if split is allowed
3039                 l_delivery_detail_id := l_id_tab(l_id_tab.first);
3040               IF l_inv_item_id IS NOT NULL THEN -- Added for bug 15885718
3041                 IF (NOT WSH_DETAILS_VALIDATIONS.is_split_allowed
3042                       ( p_delivery_detail_id  => l_delivery_detail_id,
3043                         p_organization_id     => l_organization_id,
3044                         p_inventory_item_id   => l_inv_item_id,
3045                         p_released_status     => l_released_status)
3046                         ) THEN
3047                   FND_MESSAGE.SET_NAME('WSH', 'WSH_OPM_LOT_INDIVISIBLE');
3048                   IF p_action_prms.caller = 'WSH_FSTRX' THEN
3049                     wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
3050                   END IF;
3051                   RAISE FND_API.G_EXC_ERROR;
3052                 END IF;
3053              END IF; -- Added for bug 15885718
3054            END IF;
3055 
3056 -- If caller is form, return. We are done
3057            IF(p_action_prms.caller = 'WSH_FSTRX') THEN
3058              --Change made during Bugfix 4070732
3059              --Raise end of api so that handling of return status, reset flags are done there
3060              RAISE e_end_of_api;
3061            END IF;
3062 
3063         END IF;
3064 
3065 
3066        IF(p_action_prms.caller = 'WSH_FSTRX' AND nvl(p_action_prms.phase,1) = 1 )AND
3067             (p_action_prms.action_code ='PACK') THEN
3068             --Change made during Bugfix 4070732
3069              --Raise end of api so that handling of return status, reset flags are done there
3070              RAISE e_end_of_api;
3071         END IF;
3072 -- HW end of BUG#:2677054
3073 
3074         IF p_action_prms.action_code IN('SPLIT-LINE', 'CYCLE-COUNT', 'PICK-RELEASE-UI', 'RESOLVE-EXCEPTIONS-UI') THEN
3075            IF(p_rec_attr_tab.count > 1) THEN
3076               FND_MESSAGE.SET_NAME('WSH','WSH_UI_MULTI_SELECTION');
3077             wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
3078               IF l_debug_on THEN
3079                 wsh_debug_sv.logmsg(l_module_name,'WSH_UI_MULTI_SELECTION');
3080               END IF;
3081               RAISE FND_API.G_EXC_ERROR;
3082            END IF;
3083         END IF;
3084 
3085         IF  l_debug_on THEN
3086            wsh_debug_sv.log(l_module_name, 'Id Tab Count', l_id_tab.count);
3087         END IF;
3088 
3089         IF p_action_prms.action_code IN('ASSIGN', 'UNASSIGN') THEN
3090 
3091            IF(p_action_prms.action_code = 'ASSIGN' AND nvl(p_action_prms.phase,1) = 1) THEN
3092              IF l_debug_on THEN
3093                 WSH_DEBUG_SV.log(l_module_name, 'Delivery Id', p_action_prms.delivery_id);
3094                 WSH_DEBUG_SV.log(l_module_name, 'Delivery Name', p_action_prms.delivery_name);
3095                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DETAILS_VALIDATIONS.CHECK_ASSIGN_DEL_MULTI',WSH_DEBUG_SV.C_PROC_LEVEL);
3096             END IF;
3097 
3098                wsh_details_validations.check_assign_del_multi(
3099       p_detail_rows   => l_id_tab,
3100       x_del_params    => l_detail_group_params,
3101       x_return_status   => l_return_status);
3102 
3103              IF l_debug_on THEN
3104                 WSH_DEBUG_SV.log(l_module_name, 'return status after calling check_assign_del_multi', l_return_status);
3105                 WSH_DEBUG_SV.log(l_module_name, 'group id', l_detail_group_params.group_id);
3106             END IF;
3107                wsh_util_core.api_post_call(
3108                    p_return_status => l_return_status,
3109                    x_num_warnings  => l_number_of_warnings,
3110                    x_num_errors    => l_number_of_errors,
3111                    p_msg_data      => l_msg_data
3112                    );
3113 
3114                IF p_action_prms.caller = 'WSH_FSTRX' THEN
3115                   x_defaults.detail_group_params := l_detail_group_params;
3116                        l_attr_tab(1) := l_detail_group_params;
3117                        l_attr_tab(1).entity_type := 'DELIVERY_DETAIL';
3118 
3119                        l_target_rec.entity_type := 'DELIVERY';
3120                        l_action_rec.output_format_type := 'TEMP_TAB';
3121                        l_action_rec.action := 'MATCH_GROUPS';
3122 
3123 
3124                         wsh_delivery_autocreate.Find_Matching_Groups(
3125                         p_attr_tab => l_attr_tab,
3126                         p_action_rec => l_action_rec,
3127                         p_target_rec => l_target_rec,
3128                         p_group_tab  => l_group_info,
3129                         x_matched_entities => l_matched_entities,
3130                         x_out_rec => l_out_rec,
3131                         x_return_status => l_return_status);
3132 
3133                         wsh_util_core.api_post_call(
3134                             p_return_status => l_return_status,
3135                             x_num_warnings  => l_number_of_warnings,
3136                             x_num_errors    => l_number_of_errors,
3137                             p_msg_data      => l_msg_data
3138                             );
3139 
3140                    --Change made during Bugfix 4070732
3141                    --Raise end of api so that handling of return status, reset flags are done there
3142                    RAISE e_end_of_api;
3143                END IF;
3144             END IF; -- if check for phase
3145 
3146            /*Since the existing procedure Detail_To_Delivery has its own id_tab_type, need to map the id tab */
3147            l_index := l_id_tab.FIRST;
3148            WHILE l_index IS NOT NULL LOOP
3149               l_det_id_tab(l_index) := l_id_tab(l_index);
3150               l_index := l_id_tab.NEXT(l_index);
3151            END LOOP;
3152             --
3153             IF l_debug_on THEN
3154                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_GRP.DETAIL_TO_DELIVERY',WSH_DEBUG_SV.C_PROC_LEVEL);
3155             END IF;
3156             --
3157             WSH_DELIVERY_DETAILS_GRP.detail_to_delivery(
3158                 p_api_version        =>    l_api_version,
3159                 p_init_msg_list      =>    FND_API.G_FALSE,
3160                 p_commit             =>    FND_API.G_FALSE,
3161                 p_validation_level   =>    l_validation_level,
3162                 x_return_status      =>    l_return_status,
3163                 x_msg_count          =>    l_msg_count,
3164                 x_msg_data           =>    l_msg_data,
3165                 p_TabOfDelDets       =>    l_det_id_tab,
3166                 p_action             =>    p_action_prms.action_code,
3167                 p_delivery_id        =>    p_action_prms.delivery_id,
3168                 p_delivery_name      =>    p_action_prms.delivery_name,
3169                 p_action_prms        =>    p_action_prms);
3170 
3171 
3172             --
3173             wsh_util_core.api_post_call(
3174                p_return_status => l_return_status,
3175                x_num_warnings  => l_number_of_warnings,
3176                x_num_errors    => l_number_of_errors,
3177                p_msg_data      => l_msg_data
3178                );
3179 
3180              IF (l_return_status in (WSH_UTIL_CORE.G_RET_STS_SUCCESS, WSH_UTIL_CORE.G_RET_STS_WARNING)
3181                  AND p_action_prms.action_code = 'ASSIGN' ) THEN
3182                   IF l_debug_on THEN
3183                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_NEW_DELIVERY_ACTIONS.ASSIGN_DELIVERY_UPDATE',WSH_DEBUG_SV.C_PROC_LEVEL);
3184                   END IF;
3185 
3186                 wsh_new_delivery_actions.assign_delivery_update(
3187         p_delivery_id  => p_action_prms.delivery_id,
3188         p_del_params   => l_detail_group_params,
3189         x_return_status => l_return_status);
3190 
3191                     wsh_util_core.api_post_call(
3192                        p_return_status => l_return_status,
3193                        x_num_warnings  => l_number_of_warnings,
3194                        x_num_errors    => l_number_of_errors,
3195                        p_msg_data      => l_msg_data
3196                        );
3197 
3198                     -- deliveryMerge
3199                     -- populate x_action_out_rec.result_id_tab with
3200                     -- assigned delivery details
3201                     x_action_out_rec.result_id_tab := l_det_id_tab ;
3202              END IF;
3203 
3204         --
3205         ELSIF p_action_prms.action_code = 'SPLIT-LINE' THEN
3206             --
3207             --
3208            IF(nvl(p_action_prms.split_quantity,0) =0) THEN
3209               FND_MESSAGE.SET_NAME('WSH', 'WSH_NO_ZERO_NUM');
3210             wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
3211               IF l_debug_on THEN
3212                 wsh_debug_sv.logmsg(l_module_name,'Zero or Null split quantity');
3213               END IF;
3214               RAISE FND_API.G_EXC_ERROR;
3215            END IF;
3216 
3217             --
3218             IF l_debug_on THEN
3219                wsh_debug_sv.log(l_module_name, 'Split Quantity', p_action_prms.split_quantity);
3220             END IF;
3221 
3222             l_split_quantity := p_action_prms.split_quantity;
3223             l_split_quantity2 := p_action_prms.split_quantity2;
3224             --
3225             --
3226 -- HW Harmonization project for OPM .Need to add converted_flag for OPM
3227 -- Need to check if caller is from STF or not. If call from STF, make l_converted_quantity ='Y'
3228 
3229 -- HW OPMCONV - 1) Changed name of cursor
3230 --            - 2) Fetch requested_uom2
3231             OPEN  det_line(l_id_tab(l_id_tab.first));
3232             FETCH det_line INTO l_line_direction,l_requested_quantity_uom2;
3233             CLOSE det_line;
3234 
3235 -- HW OPMCONV - 1) No need to check for process_org
3236 --            - 2) check for value of UOM2 before calling the validation
3237            IF  ( l_requested_quantity_uom2 IS NOT NULL
3238                 AND l_requested_quantity_uom2 <> FND_API.G_MISS_CHAR) THEN
3239 
3240             --{
3241                 IF l_debug_on THEN
3242                     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DETAILS_VALIDATIONS.validate_secondary_quantity',WSH_DEBUG_SV.C_PROC_LEVEL);
3243                 END IF;
3244                 --
3245                 -- J-IB-NPARIKH-{
3246 															--
3247 -- HW OPMCONV - Added p_caller to validate_secondary_quantity
3248 -- Check that secondary quantity is within tolerance of primary quantity
3249 															--
3250                IF  l_inventory_item_id is not null
3251                AND ( p_action_prms.caller like 'FTE%' or l_line_direction not in ('IO','O') )
3252                THEN
3253                --{
3254                    WSH_DETAILS_VALIDATIONS.validate_secondary_quantity
3255                         (
3256                             p_delivery_detail_id =>    l_id_tab(l_id_tab.first),
3257                             x_quantity           =>    l_split_quantity,
3258                             x_quantity2          =>    l_split_quantity2,
3259                             p_caller             =>    p_action_prms.caller,
3260                             x_return_status      =>    l_return_status,
3261                             x_msg_count          =>    l_msg_count,
3262                             x_msg_data           =>    l_msg_data
3263                         );
3264                    --
3265                     wsh_util_core.api_post_call(
3266                        p_return_status => l_return_status,
3267                        x_num_warnings  => l_number_of_warnings,
3268                        x_num_errors    => l_number_of_errors,
3269                        p_msg_data      => l_msg_data
3270                        );
3271                    --
3272                    l_converted_flag := 'Y';
3273                --}
3274                -- J-IB-NPARIKH-}
3275                ELSIF(p_action_prms.caller = 'WSH_FSTRX' AND p_action_prms.phase = 2 )
3276                THEN
3277                     l_converted_flag := 'Y';
3278                ELSE
3279                     l_converted_flag := NULL;
3280                END IF;
3281             --}
3282 
3283           END IF;  -- of UOM2
3284 
3285 -- HW Harmonization project forOPM. Added p_manual_split parameter
3286 -- HW added p_converted_flag
3287             IF l_debug_on THEN
3288                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_GRP.SPLIT_LINE',WSH_DEBUG_SV.C_PROC_LEVEL);
3289             END IF;
3290             WSH_DELIVERY_DETAILS_GRP.split_line(
3291                 p_api_version        =>    l_api_version,
3292                 p_init_msg_list      =>    FND_API.G_FALSE,
3293                 p_commit             =>    FND_API.G_FALSE,
3294                 p_validation_level   =>    l_validation_level,
3295                 x_return_status      =>    l_return_status,
3296                 x_msg_count          =>    l_msg_count,
3297                 x_msg_data           =>    l_msg_data,
3298                 p_from_detail_id     =>    l_id_tab(l_id_tab.first),
3299                 x_new_detail_id      =>    x_action_out_rec.result_id_tab(1),
3300                 x_split_quantity     =>    l_split_quantity,
3301                 x_split_quantity2    =>    l_split_quantity2,
3302                 p_manual_split       =>    l_manual_split,
3303                 p_converted_flag     =>    l_converted_flag);
3304 
3305              x_action_out_rec.split_quantity := l_split_quantity;
3306              x_action_out_rec.split_quantity2 := l_split_quantity2;
3307 
3308             --
3309             wsh_util_core.api_post_call(
3310                p_return_status => l_return_status,
3311                x_num_warnings  => l_number_of_warnings,
3312                x_num_errors    => l_number_of_errors,
3313                p_msg_data      => l_msg_data
3314                );
3315 
3316         --
3317         ELSIF p_action_prms.action_code = 'AUTOCREATE-DEL' THEN
3318             --
3319             IF l_debug_on THEN
3320                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_GRP.AUTOCREATE_DELIVERIES',WSH_DEBUG_SV.C_PROC_LEVEL);
3321             END IF;
3322             --
3323             --Compatibility Changes
3324             IF wsh_util_core.fte_is_installed = 'Y' AND l_cc_line_groups.COUNT>0 THEN
3325 
3326               --1. get the group ids by which the constraints API has grouped the lines
3327               l_cc_count_group_ids:=1;
3328               FOR i in l_cc_line_groups.FIRST..l_cc_line_groups.LAST LOOP
3329                 b_cc_groupidexists:=FALSE;
3330 
3331                 IF l_cc_group_ids.COUNT>0 THEN
3332                  FOR j in l_cc_group_ids.FIRST..l_cc_group_ids.LAST LOOP
3333                   IF (l_cc_line_groups(i).line_group_id=l_cc_group_ids(j)) THEN
3334                     b_cc_groupidexists:=TRUE;
3335                   END IF;
3336                  END LOOP;
3337                 END IF;
3338                 IF (NOT(b_cc_groupidexists)) THEN
3339                   l_cc_group_ids(l_cc_count_group_ids):=l_cc_line_groups(i).line_group_id;
3340                   l_cc_count_group_ids:=l_cc_count_group_ids+1;
3341                 END IF;
3342               END LOOP;
3343 
3344               --2. from the group id table above, loop thru lines table to get the lines which belong
3345               --to each group and call autocreate_del for each group
3346               FOR i in l_cc_group_ids.FIRST..l_cc_group_ids.LAST LOOP
3347                 l_cc_count_rec:=1;
3348                 FOR j in l_cc_line_groups.FIRST..l_cc_line_groups.LAST LOOP
3349                   IF l_cc_line_groups(j).line_group_id=l_cc_group_ids(i) THEN
3350                     l_id_tab_temp(l_cc_count_rec):=l_cc_line_groups(j).entity_line_id;
3351                     l_cc_count_rec:=l_cc_count_rec+1;
3352                   END IF;
3353                 END LOOP;
3354 
3355                 IF l_debug_on THEN
3356                   wsh_debug_sv.log(l_module_name,'id_tab_temp count ',l_id_tab_temp.COUNT);
3357                 END IF;
3358 
3359                 WSH_DELIVERY_DETAILS_GRP.Autocreate_Deliveries(
3360                         p_api_version_number  =>  l_api_version,
3361                         p_init_msg_list       =>  FND_API.G_FALSE,
3362                         p_commit              =>  FND_API.G_FALSE,
3363                         p_caller              =>  p_action_prms.caller,
3364                         x_return_status       =>  l_return_status ,
3365                         x_msg_count           =>  l_msg_count,
3366                         x_msg_data            =>  l_msg_data,
3367                         p_line_rows           =>  l_id_tab_temp,
3368                         p_group_by_header_flag => p_action_prms.group_by_header_flag,
3369                         x_del_rows            =>  x_action_out_rec.delivery_id_tab);
3370 
3371 
3372                 --set the intermediate ship to, ship method to null if group rec from constraint validation has these as 'N'
3373                 l_cc_upd_dlvy_intmed_ship_to:='Y';
3374                 l_cc_upd_dlvy_ship_method:='Y';
3375                 IF l_cc_group_info.COUNT>0 THEN
3376                  FOR j in l_cc_group_info.FIRST..l_cc_group_info.LAST LOOP
3377                   IF l_cc_group_info(j).line_group_id=l_cc_group_ids(i) THEN
3378                   l_cc_upd_dlvy_intmed_ship_to:=l_cc_group_info(j).upd_dlvy_intmed_ship_to;
3379                   l_cc_upd_dlvy_ship_method:=l_cc_group_info(j).upd_dlvy_ship_method;
3380                   END IF;
3381                  END LOOP;
3382                 END IF;
3383 
3384                 IF l_debug_on THEN
3385                   wsh_debug_sv.log(l_module_name,'l_cc_upd_dlvy_intmed_ship_to ',l_cc_upd_dlvy_intmed_ship_to);
3386                   wsh_debug_sv.log(l_module_name,'l_cc_upd_dlvy_ship_method ',l_cc_upd_dlvy_ship_method);
3387                   wsh_debug_sv.log(l_module_name,'x_action_out_rec.delivery_id_tab.COUNT ',x_action_out_rec.delivery_id_tab.COUNT);
3388                   wsh_debug_sv.log(l_module_name,'l_return_status after calling autocreate_del in comp ',l_return_status);
3389                 END IF;
3390 
3391                 IF l_cc_upd_dlvy_intmed_ship_to='N' OR l_cc_upd_dlvy_ship_method='N' THEN
3392                  IF x_action_out_rec.delivery_id_tab.COUNT>0 THEN
3393 
3394                    FOR i in x_action_out_rec.delivery_id_tab.FIRST..x_action_out_rec.delivery_id_tab.LAST LOOP
3395                     FOR delcurtemp in c_delcur(x_action_out_rec.delivery_id_tab(i)) LOOP
3396                       l_cc_dlvy_intmed_ship_to:=delcurtemp.INTMED_SHIP_TO_LOCATION_ID;
3397                       l_cc_dlvy_ship_method:=delcurtemp.SHIP_METHOD_CODE;
3398                       IF l_cc_upd_dlvy_intmed_ship_to='N' and l_cc_dlvy_intmed_ship_to IS NOT NULL THEN
3399                         update wsh_new_deliveries set INTMED_SHIP_TO_LOCATION_ID=null
3400                         where delivery_id=x_action_out_rec.delivery_id_tab(i);
3401                       END IF;
3402                       --IF l_cc_upd_dlvy_ship_method='N' and l_cc_dlvy_ship_method IS NOT NULL THEN
3403                       IF l_cc_upd_dlvy_ship_method='N' THEN
3404 
3405                         -- OTM R12 : update delivery
3406                         -- no code changes are needed for the following update
3407                         -- since it reaches here only when FTE is installed
3408 
3409                         update wsh_new_deliveries
3410                         set SHIP_METHOD_CODE=null,
3411                                 CARRIER_ID = null,
3412                                 MODE_OF_TRANSPORT = null,
3413                                 SERVICE_LEVEL = null
3414                         where delivery_id=x_action_out_rec.delivery_id_tab(i);
3415                       END IF;
3416                     END LOOP;
3417                    END LOOP;
3418                  END IF;
3419                 END IF;
3420                   --set the intermediate ship to, ship method to null if group rec from constraint validation has these as 'N'
3421                 IF l_cc_del_rows.COUNT=0 THEN
3422                   l_cc_del_rows:=x_action_out_rec.delivery_id_tab;
3423                 ELSE
3424                   l_cc_count_del_rows:=l_cc_del_rows.COUNT;
3425                   IF x_action_out_rec.delivery_id_tab.COUNT>0 THEN
3426                     FOR i in x_action_out_rec.delivery_id_tab.FIRST..x_action_out_rec.delivery_id_tab.LAST LOOP
3427                       l_cc_del_rows(l_cc_count_del_rows+i):=x_action_out_rec.delivery_id_tab(i);
3428                     END LOOP;
3429                   END IF;
3430                 END IF;
3431 
3432                 IF (l_cc_return_status is not null AND l_cc_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
3433                   l_return_status:=l_cc_return_status;
3434                 ELSIF (l_cc_return_status is not null AND l_cc_return_status=WSH_UTIL_CORE.G_RET_STS_WARNING AND l_return_status=WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
3435                   l_return_status:=l_cc_return_status;
3436                 ELSE
3437                   l_cc_return_status:=l_return_status;
3438                 END IF;
3439 
3440               END LOOP;
3441               l_return_status:=l_cc_return_status;
3442               x_action_out_rec.delivery_id_tab:=l_cc_del_rows;
3443 
3444               IF l_debug_on THEN
3445                 wsh_debug_sv.log(l_module_name,'x_action_out_rec.delivery_id_tab.COUNT after loop ',x_action_out_rec.delivery_id_tab.COUNT);
3446               END IF;
3447 
3448             ELSE
3449 
3450               WSH_DELIVERY_DETAILS_GRP.Autocreate_Deliveries(
3451                   p_api_version_number  =>  l_api_version,
3452                   p_init_msg_list       =>  FND_API.G_FALSE,
3453                   p_commit              =>  FND_API.G_FALSE,
3454                   p_caller              =>  p_action_prms.caller,
3455                   x_return_status       =>  l_return_status ,
3456                   x_msg_count           =>  l_msg_count,
3457                   x_msg_data            =>  l_msg_data,
3458                   p_line_rows           =>  l_id_tab,
3459                   p_group_by_header_flag => p_action_prms.group_by_header_flag,
3460                   x_del_rows            =>  x_action_out_rec.delivery_id_tab);
3461 
3462             END IF;
3463             --Compatibility Changes
3464 
3465             --
3466             IF l_debug_on THEN
3467                 wsh_debug_sv.log(l_module_name,'Return Status After Calling Autocreate_Deliveries',l_return_status);
3468             END IF;
3469 
3470             --
3471             wsh_util_core.api_post_call(
3472                p_return_status => l_return_status,
3473                x_num_warnings  => l_number_of_warnings,
3474                x_num_errors    => l_number_of_errors,
3475                p_msg_data      => l_msg_data
3476                );
3477 
3478             -- deliveryMerge
3479             wsh_new_delivery_actions.Adjust_Planned_Flag(
3480                p_delivery_ids           => x_action_out_rec.delivery_id_tab,
3481                p_caller                 => 'WSH_DLMG',
3482                p_force_appending_limit  => 'N',
3483                p_call_lcss              => 'Y',
3484                x_return_status          => l_return_status);
3485 
3486             wsh_util_core.api_post_call(
3487                p_return_status => l_return_status,
3488                x_num_warnings  => l_number_of_warnings,
3489                x_num_errors    => l_number_of_errors,
3490                p_msg_data      => l_msg_data
3491                );
3492         --
3493         ELSIF p_action_prms.action_code = 'AUTOCREATE-TRIP' THEN
3494             --
3495             IF l_debug_on THEN
3496                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_GRP.AUTOCREATE_DEL_TRIP',WSH_DEBUG_SV.C_PROC_LEVEL);
3497             END IF;
3498             --
3499             WSH_DELIVERY_DETAILS_GRP.Autocreate_del_trip(
3500                 p_api_version_number  =>  l_api_version,
3501                 p_init_msg_list       => FND_API.G_FALSE,
3502                 p_commit              => FND_API.G_FALSE,
3503                 x_return_status       => l_return_status,
3504                 x_msg_count           => l_msg_count,
3505                 x_msg_data            => l_msg_data,
3506                 p_line_rows           => l_id_tab,
3507                 x_del_rows            => x_action_out_rec.delivery_id_tab,
3508                 x_trip_rows           => x_action_out_rec.result_id_tab);
3509 
3510             --
3511             wsh_util_core.api_post_call(
3512                p_return_status => l_return_status,
3513                x_num_warnings  => l_number_of_warnings,
3514                x_num_errors    => l_number_of_errors,
3515                p_msg_data      => l_msg_data
3516                );
3517         --
3518         ELSIF p_action_prms.action_code in ('IGNORE_PLAN', 'INCLUDE_PLAN') then
3519            Wsh_tp_release.change_ignoreplan_status
3520                    (p_entity        =>'DLVB',
3521                     p_in_ids        => l_id_tab,
3522                     p_action_code   => p_action_prms.action_code,
3523                     x_return_status => l_return_status);
3524            --
3525            IF l_debug_on THEN
3526                wsh_debug_sv.log(l_module_name,'Return Status After Calling change_ignoreplan_status ',l_return_status);
3527            END IF;
3528            --
3529            wsh_util_core.api_post_call(
3530               p_return_status    => l_return_status,
3531               x_num_warnings     => l_number_of_warnings,
3532               x_num_errors       => l_number_of_errors);
3533          --
3534 
3535         ELSIF p_action_prms.action_code = 'PICK-RELEASE' THEN
3536             --
3537         IF  l_debug_on THEN
3538            wsh_debug_sv.log(l_module_name, 'Id Tab Count', l_id_tab.count);
3539         END IF;
3540 
3541       IF l_debug_on THEN
3542           WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PICK_LIST.LAUNCH_PICK_RELEASE',WSH_DEBUG_SV.C_PROC_LEVEL);
3543       END IF;
3544       --
3545 
3546       wsh_pick_list.launch_pick_release(
3547                 p_trip_ids           => l_dummy_ids,
3548                 p_stop_ids           => l_dummy_ids,
3549                 p_delivery_ids       => l_dummy_ids,
3550                 p_detail_ids         => l_id_tab,
3551 		p_batch_id           => p_action_prms.batch_id, -- bug# 6719369 (replenishment project)
3552                 x_request_ids        => l_request_ids,
3553                 x_return_status      => l_return_status);
3554 
3555             --
3556             wsh_util_core.api_post_call(
3557                p_return_status => l_return_status,
3558                x_num_warnings  => l_number_of_warnings,
3559                x_num_errors    => l_number_of_errors,
3560                p_msg_data      => l_msg_data
3561                );
3562         --
3563         ELSIF p_action_prms.action_code = 'PICK-PACK-SHIP' THEN
3564             --
3565         IF  l_debug_on THEN
3566            wsh_debug_sv.log(l_module_name, 'Id Tab Count', l_id_tab.count);
3567         END IF;
3568 
3569       IF l_debug_on THEN
3570           WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PICK_LIST.LAUNCH_PICK_RELEASE',WSH_DEBUG_SV.C_PROC_LEVEL);
3571       END IF;
3572       --
3573       wsh_pick_list.launch_pick_release(
3574                 p_trip_ids           => l_dummy_ids,
3575                 p_stop_ids           => l_dummy_ids,
3576                 p_delivery_ids       => l_dummy_ids,
3577                 p_detail_ids         => l_id_tab,
3578                 x_request_ids      => l_request_ids,
3579                 x_return_status      => l_return_status,
3580                 p_auto_pack_ship     => 'PS');
3581 
3582             --
3583             wsh_util_core.api_post_call(
3584                p_return_status => l_return_status,
3585                x_num_warnings  => l_number_of_warnings,
3586                x_num_errors    => l_number_of_errors,
3587                p_msg_data      => l_msg_data
3588                );
3589         --
3590         ELSIF p_action_prms.action_code = 'PICK-SHIP' THEN
3591             --
3592         IF  l_debug_on THEN
3593            wsh_debug_sv.log(l_module_name, 'Id Tab Count', l_id_tab.count);
3594         END IF;
3595 
3596       IF l_debug_on THEN
3597           WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PICK_LIST.LAUNCH_PICK_RELEASE',WSH_DEBUG_SV.C_PROC_LEVEL);
3598       END IF;
3599       --
3600       wsh_pick_list.launch_pick_release(
3601                 p_trip_ids           => l_dummy_ids,
3602                 p_stop_ids           => l_dummy_ids,
3603                 p_delivery_ids       => l_dummy_ids,
3604                 p_detail_ids         => l_id_tab,
3605                 x_request_ids      => l_request_ids,
3606                 x_return_status      => l_return_status,
3607                 p_auto_pack_ship     => 'SC');
3608 
3609             --
3610             wsh_util_core.api_post_call(
3611                p_return_status => l_return_status,
3612                x_num_warnings  => l_number_of_warnings,
3613                x_num_errors    => l_number_of_errors,
3614                p_msg_data      => l_msg_data
3615                );
3616         --
3617         ELSIF p_action_prms.action_code = 'WT-VOL' THEN
3618             --
3619 
3620             -- OTM R12 : packing ECO
3621             -- This change was introduced to mark the G_RESET_WV flag
3622             -- before calling detail_weight_volume so the procedure will know
3623             -- to invoke update tms_interface_flag process.
3624 
3625             l_gc3_is_installed := WSH_UTIL_CORE.G_GC3_IS_INSTALLED;
3626             IF l_gc3_is_installed IS NULL THEN
3627               l_gc3_is_installed := WSH_UTIL_CORE.GC3_IS_INSTALLED;
3628             END IF;
3629 
3630             IF l_gc3_is_installed = 'Y' THEN
3631               WSH_WV_UTILS.G_RESET_WV := 'Y'; -- set to Y to enable the update
3632             END IF;
3633             -- End of OTM R12 : packing ECO
3634 
3635             IF l_debug_on THEN
3636               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.DETAIL_WEIGHT_VOLUME',WSH_DEBUG_SV.C_PROC_LEVEL);
3637             END IF;
3638             --
3639             wsh_wv_utils.detail_weight_volume (
3640                 p_detail_rows       => l_id_tab ,
3641                 p_override_flag     => 'Y', -- Need to see if we can Use p_action_prms.wv_override_flag
3642                 x_return_status     => l_return_status);
3643 
3644             --
3645             wsh_util_core.api_post_call(
3646                p_return_status => l_return_status,
3647                x_num_warnings  => l_number_of_warnings,
3648                x_num_errors    => l_number_of_errors,
3649                p_msg_data      => l_msg_data
3650                );
3651 
3652             -- OTM R12 : packing ECO
3653             IF l_gc3_is_installed = 'Y' THEN
3654               WSH_WV_UTILS.G_RESET_WV := 'N'; -- after call, set it back to 'N'
3655             END IF;
3656             -- End of OTM R12 : packing ECO
3657 
3658         --
3659         ELSIF p_action_prms.action_code  = 'PACK' THEN
3660             --
3661             -- we just have to call the container group api here
3662             l_cont_flag :=  'N';
3663             l_delivery_flag := 'N';
3664 
3665             --
3666             IF l_debug_on THEN
3667                 WSH_DEBUG_SV.log(l_module_name, 'Container Name', p_action_prms.container_name);
3668                 WSH_DEBUG_SV.log(l_module_name, 'Container Instance Id', p_action_prms.container_instance_id);
3669                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_CONTAINER_GRP.CONTAINER_ACTIONS',WSH_DEBUG_SV.C_PROC_LEVEL);
3670             END IF;
3671 
3672             wsh_container_grp.Container_Actions(
3673                 p_api_version    => l_api_version,
3674                 p_init_msg_list    => FND_API.G_FALSE,
3675                 p_commit           => FND_API.G_FALSE,
3676                 p_validation_level => wsh_container_grp.C_DELIVERY_DETAIL_CALL,
3677                 x_return_status    => l_return_status,
3678                 x_msg_count        => l_msg_count,
3679                 x_msg_data         => l_msg_data,
3680                 p_detail_tab       => l_id_tab,
3681                 p_container_name   => p_action_prms.container_name,
3682                 p_cont_instance_id => p_action_prms.container_instance_id,
3683                 p_container_flag   => l_cont_flag,
3684                 p_delivery_flag    => l_delivery_flag,
3685                 p_action_code      => 'PACK',
3686                 p_caller           => p_action_prms.caller);
3687 
3688             --
3689             wsh_util_core.api_post_call(
3690                p_return_status => l_return_status,
3691                x_num_warnings  => l_number_of_warnings,
3692                x_num_errors    => l_number_of_errors,
3693                p_msg_data      => l_msg_data
3694                );
3695             --
3696 
3697             -- deliveryMerge add the call to Adjust_Planned_Flag with delivery detail ids
3698 
3699             FOR i in l_id_tab.FIRST .. l_id_tab.LAST LOOP
3700               OPEN get_delivery(l_id_tab(i));
3701               FETCH get_delivery into l_delivery_id;
3702               IF get_delivery%NOTFOUND THEN
3703                  CLOSE get_delivery;
3704                  goto end_of_detail_loop_1;
3705               END IF;
3706               CLOSE get_delivery;
3707 
3708               l_delivery_already_included := false;
3709               IF l_delivery_ids.count > 0 THEN
3710                  FOR j in l_delivery_ids.FIRST .. l_delivery_ids.LAST LOOP
3711                     IF l_delivery_ids(j) = l_delivery_id THEN
3712                        l_delivery_already_included := true;
3713                     END IF;
3714                  END LOOP;
3715               END IF;
3716 
3717               IF NOT l_delivery_already_included THEN
3718                  l_delivery_ids(l_delivery_ids.count+1) := l_delivery_id;
3719               END IF;
3720               <<end_of_detail_loop_1>>
3721               null;
3722             END LOOP;
3723 
3724             IF l_delivery_ids.count > 0 THEN
3725               WSH_NEW_DELIVERY_ACTIONS.Adjust_Planned_Flag(
3726                   p_delivery_ids          => l_delivery_ids,
3727                   p_caller                => 'WSH_DLMG',
3728                   p_force_appending_limit => 'N',
3729                   p_call_lcss             => 'Y',
3730                   x_return_status         => l_return_status);
3731 
3732                IF l_debug_on THEN
3733                   WSH_DEBUG_SV.log(l_module_name,'Adjust_Planned_Flag returns ',l_return_status);
3734                END IF;
3735             END IF;
3736 
3737             wsh_util_core.api_post_call(
3738                p_return_status => l_return_status,
3739                x_num_warnings  => l_number_of_warnings,
3740                x_num_errors    => l_number_of_errors,
3741                p_msg_data      => l_msg_data
3742                );
3743 
3744         ELSIF p_action_prms.action_code = 'AUTO-PACK' THEN
3745             --
3746             -- we just have to call the container group api here
3747       l_entity_type := 'L';
3748 
3749             --
3750             IF l_debug_on THEN
3751                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_CONTAINER_GRP.AUTO_PACK',WSH_DEBUG_SV.C_PROC_LEVEL);
3752             END IF;
3753             wsh_container_grp.Auto_Pack (
3754                 p_api_version    => l_api_version,
3755                 p_init_msg_list    => FND_API.G_FALSE,
3756                 p_commit           => FND_API.G_FALSE,
3757                 p_validation_level => l_validation_level,
3758                 x_return_status    => l_return_status,
3759                 x_msg_count        => l_msg_count,
3760                 x_msg_data         => l_msg_data,
3761                 p_entity_tab     =>  l_id_tab,
3762                 p_entity_type    =>  l_entity_type,
3763                 p_group_id_tab     => l_group_id_tab,
3764                 p_pack_cont_flag   => 'N' ,
3765                 x_cont_inst_tab    => x_action_out_rec.result_id_tab);
3766 
3767             --
3768             wsh_util_core.api_post_call(
3769                p_return_status => l_return_status,
3770                x_num_warnings  => l_number_of_warnings,
3771                x_num_errors    => l_number_of_errors,
3772                p_msg_data      => l_msg_data
3773                );
3774 
3775         --
3776         ELSIF p_action_prms.action_code = 'AUTO-PACK-MASTER' THEN
3777             --
3778       -- we just have to call the container group api here
3779       -- set the flag p_pack_cont_flagto Y to do auto-pack-master.
3780       l_entity_type := 'L';
3781 
3782             --
3783             IF l_debug_on THEN
3784                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_CONTAINER_GRP.AUTO_PACK',WSH_DEBUG_SV.C_PROC_LEVEL);
3785             END IF;
3786            wsh_container_grp.Auto_Pack (
3787          p_api_version    => p_api_version_number,
3788                p_init_msg_list    => FND_API.G_FALSE,
3789                p_commit           => FND_API.G_FALSE,
3790                p_validation_level => l_validation_level,
3791                x_return_status    => l_return_status,
3792                x_msg_count        => l_msg_count,
3793                x_msg_data         => l_msg_data ,
3794                p_entity_tab       => l_id_tab,
3795                p_entity_type      => l_entity_type,
3796                p_group_id_tab     => l_group_id_tab,
3797                p_pack_cont_flag   => 'Y',
3798                x_cont_inst_tab    => x_action_out_rec.result_id_tab);
3799 
3800             -- Handle return status
3801             --
3802             wsh_util_core.api_post_call(
3803                p_return_status => l_return_status,
3804                x_num_warnings  => l_number_of_warnings,
3805                x_num_errors    => l_number_of_errors,
3806                p_msg_data      => l_msg_data
3807                );
3808         --
3809 
3810         ELSIF p_action_prms.action_code = 'UNPACK'  THEN
3811             --
3812             -- we just have to call the container group api here
3813             l_cont_flag := 'Y'; -- need to set this to Y if action is Unpack
3814 
3815             -- deliveryMerge
3816             -- get the delivery associated with the delivery details
3817             FOR i in l_id_tab.FIRST .. l_id_tab.LAST LOOP
3818               OPEN get_delivery(l_id_tab(i));
3819               FETCH get_delivery into l_delivery_id;
3820               IF l_delivery_id is NULL OR get_delivery%NOTFOUND THEN
3821                  CLOSE get_delivery;
3822                  goto end_of_detail_loop_2;
3823               END IF;
3824               CLOSE get_delivery;
3825 
3826               l_delivery_already_included := false;
3827 
3828               IF l_delivery_ids.count > 0 THEN
3829                  FOR j in l_delivery_ids.FIRST .. l_delivery_ids.LAST LOOP
3830                    IF l_delivery_ids(j) = l_delivery_id THEN
3831                       l_delivery_already_included := true;
3832                    END IF;
3833                  END LOOP;
3834               END IF;
3835 
3836               IF NOT l_delivery_already_included THEN
3837                  l_delivery_ids(l_delivery_ids.count+1) := l_delivery_id;
3838               END IF;
3839               <<end_of_detail_loop_2>>
3840               null;
3841             END LOOP;
3842 
3843 
3844             IF l_debug_on THEN
3845                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_CONTAINER_GRP.CONTAINER_ACTIONS',WSH_DEBUG_SV.C_PROC_LEVEL);
3846             END IF;
3847            wsh_container_grp.Container_Actions(
3848                p_api_version    => l_api_version,
3849                p_init_msg_list    => FND_API.G_FALSE,
3850                p_commit           => FND_API.G_FALSE,
3851                p_validation_level => wsh_container_grp.C_DELIVERY_DETAIL_CALL,
3852                x_return_status    => l_return_status,
3853                x_msg_count        => l_msg_count,
3854                x_msg_data         => l_msg_data ,
3855                p_detail_tab       => l_id_tab,
3856                p_container_name   => p_action_prms.container_name,
3857                p_cont_instance_id => p_action_prms.container_instance_id,
3858                p_container_flag   => l_cont_flag,
3859                p_delivery_flag    => l_delivery_flag,
3860                p_action_code      => 'UNPACK',
3861                p_caller           => p_action_prms.caller);
3862 
3863             --
3864             wsh_util_core.api_post_call(
3865                p_return_status => l_return_status,
3866                x_num_warnings  => l_number_of_warnings,
3867                x_num_errors    => l_number_of_errors,
3868                p_msg_data      => l_msg_data
3869                );
3870 
3871             -- deliveryMerge
3872             IF l_delivery_ids.count > 0 THEN
3873                WSH_NEW_DELIVERY_ACTIONS.Adjust_Planned_Flag(
3874                   p_delivery_ids          => l_delivery_ids,
3875                   p_caller                => 'WSH_DLMG',
3876                   p_force_appending_limit => 'N',
3877                   p_call_lcss             => 'Y',
3878                   x_return_status         => l_return_status);
3879 
3880                IF l_debug_on THEN
3881                   WSH_DEBUG_SV.log(l_module_name,'Adjust_Planned_Flag returns ',l_return_status);
3882                END IF;
3883             END IF;
3884 
3885             wsh_util_core.api_post_call(
3886                p_return_status => l_return_status,
3887                x_num_warnings  => l_number_of_warnings,
3888                x_num_errors    => l_number_of_errors,
3889                p_msg_data      => l_msg_data);
3890 
3891         --
3892         ELSIF p_action_prms.action_code = 'CYCLE-COUNT' THEN
3893 
3894             --
3895             -- Note: This action is only for one record. It is enforced by STF.
3896             --
3897             OPEN  cycle_count_cur(l_id_tab(l_id_tab.first));
3898             FETCH cycle_count_cur
3899             INTO l_released_status
3900                , l_requested_quantity
3901                , l_requested_quantity2
3902                , l_picked_quantity
3903                , l_picked_quantity2
3904                , l_shipped_quantity
3905                , l_shipped_quantity2
3906                , l_organization_id
3907                , l_inv_item_id
3908                , l_source_code -- RTV BO Cons Changes
3909                ;
3910 
3911             IF cycle_count_cur%NOTFOUND THEN
3912                 CLOSE cycle_count_cur;
3913                 IF l_debug_on THEN
3914                    wsh_debug_sv.logmsg(l_module_name,'Detail not found');
3915                 END IF;
3916                 RAISE FND_API.G_EXC_ERROR;
3917             END IF;
3918 
3919             CLOSE cycle_count_cur;
3920             --
3921             --
3922             IF l_released_status = 'Y' AND NVL(l_picked_quantity, l_requested_quantity) > NVL(l_shipped_quantity, 0) THEN
3923                NULL;
3924             ELSE
3925                 IF l_debug_on THEN
3926                    wsh_debug_sv.logmsg(l_module_name,'Incorrect Released status or incorrect quantities');
3927                 END IF;
3928                fnd_message.set_name('WSH', 'WSH_CC_RSV_INSUFF');
3929             wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
3930                raise FND_API.G_EXC_ERROR;
3931             END IF;
3932             --
3933             --
3934 
3935 
3936 -- HW OPM BUG#:2677054
3937 -- HW OPMCONV - 1) No need to branch code
3938 --            - 2) Relace call is_line_allocated with new WSH API
3939 -- HW OPMCONV - New WSH API to check if split is allowed
3940 
3941                l_delivery_detail_id := l_id_tab(l_id_tab.first);
3942 
3943                 IF (NOT WSH_DETAILS_VALIDATIONS.is_cycle_count_allowed
3944                       ( p_delivery_detail_id  => l_delivery_detail_id,
3945                         p_organization_id     => l_organization_id,
3946                         p_inventory_item_id   => l_inv_item_id,
3947                         p_released_status     => l_released_status,
3948                         p_picked_qty          => l_picked_quantity,
3949                         p_cycle_qty           => p_action_prms.quantity_to_split)
3950                         ) THEN
3951                   FND_MESSAGE.SET_NAME('WSH', 'WSH_NO_PARTIAL_CYCLE_COUNT');
3952 
3953                   IF p_action_prms.caller = 'WSH_FSTRX'  THEN
3954                      wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
3955                   END IF;
3956                   RAISE FND_API.G_EXC_ERROR;
3957                 END IF;
3958 
3959 -- HW end of 2677054
3960 
3961 
3962             IF p_action_prms.caller = 'WSH_FSTRX' AND p_action_prms.phase = 1 THEN
3963                -- return to Form so that the Cycle Count Dialog is shown to enter quantities
3964                --
3965                x_defaults.quantity_to_cc :=  nvl(l_picked_quantity, l_requested_quantity) - nvl(l_shipped_quantity,0);
3966                x_defaults.quantity2_to_cc := nvl(l_picked_quantity2, l_requested_quantity2) - nvl(l_shipped_quantity2,0);
3967 
3968                IF l_debug_on THEN
3969                    wsh_debug_sv.log(l_module_name, 'Default cc qty', x_defaults.quantity_to_cc);
3970                END IF;
3971                --
3972                    --Change made during Bugfix 4070732
3973                    --Raise end of api so that handling of return status, reset flags are done there
3974                    RAISE e_end_of_api;
3975 
3976             END IF;
3977             --
3978             -- Check if  cycle-count quantity is less than (picked or requested qty) - shipped qty
3979             -- Check if cycle_count quantity is greater than zero
3980             --Bug 2650617, nvl(l_shipped_quantity,0)
3981             IF (( p_action_prms.quantity_to_split > (NVL(l_picked_quantity, l_requested_quantity) - nvl(l_shipped_quantity,0)))
3982                   OR p_action_prms.quantity_to_split <= 0) THEN
3983 
3984                 IF l_debug_on THEN
3985                    wsh_debug_sv.logmsg(l_module_name,'Incorrect quantities');
3986                 END IF;
3987                 FND_MESSAGE.SET_NAME('WSH', 'WSH_DET_SPLIT_EXCEED');
3988             wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
3989                raise FND_API.G_EXC_ERROR;
3990 
3991             END IF;
3992 
3993             -- Calculate the quantities to be passed to backorder API
3994             --
3995             l_req_qtys(1) :=  l_requested_quantity;
3996             l_overpick_qtys(1) :=    LEAST(p_action_prms.quantity_to_split,
3997                                           NVL(l_picked_quantity,  l_requested_quantity) - l_requested_quantity);
3998 
3999             l_overpick_qtys2(1) :=  LEAST(p_action_prms.quantity2_to_split,
4000                                          NVL(l_picked_quantity2,  l_requested_quantity2) - l_requested_quantity2);
4001 
4002             l_bo_qtys(1)  := p_action_prms.quantity_to_split - l_overpick_qtys(1);
4003             l_bo_qtys2(1) := p_action_prms.quantity2_to_split - l_overpick_qtys2(1);
4004             l_sources(1)   := l_source_code; --RTV BO Cons Changes
4005 
4006           IF l_debug_on THEN
4007             wsh_debug_sv.log(l_module_name, 'Overpick Qty' , l_overpick_qtys(1));
4008             wsh_debug_sv.log(l_module_name, 'BO qty', l_bo_qtys(1));
4009           END IF;
4010 
4011 
4012             IF l_validation_level_tab(wsh_actions_levels.C_DECIMAL_QUANTITY_LVL)= 1 THEN
4013                --
4014                --
4015                OPEN  det_cur(l_id_tab(l_id_tab.first));
4016                FETCH det_cur
4017                INTO l_inv_item_id
4018                   , l_organization_id
4019                   , l_requested_quantity_uom
4020                   , l_line_direction
4021                   , l_released_status;
4022                CLOSE det_cur;
4023 
4024 -- HW Harmonization project for OPM. Added p_organization_id
4025 -- HW OPMCONV - Removed branching
4026 
4027          -- this needs to be called only for Discrete Org
4028                   --
4029                   IF l_debug_on THEN
4030                       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DETAILS_VALIDATIONS.CHECK_DECIMAL_QUANTITY',WSH_DEBUG_SV.C_PROC_LEVEL);
4031                   END IF;
4032                   --
4033                   WSH_DETAILS_VALIDATIONS.check_decimal_quantity(
4034                       p_item_id         => l_inv_item_id,
4035                       p_organization_id => l_organization_id,
4036                       p_input_quantity  => p_action_prms.quantity_to_split,
4037                       p_uom_code        => l_requested_quantity_uom,
4038                       x_output_quantity => l_output_quantity,
4039                       x_return_status   => l_return_status);
4040 
4041                   IF l_debug_on THEN
4042                       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.API_POST_CALL',WSH_DEBUG_SV.C_PROC_LEVEL);
4043                   END IF;
4044                   --
4045 
4046                 IF l_return_status <> wsh_util_core.g_ret_sts_success THEN
4047                    raise FND_API.G_EXC_ERROR;
4048                 END IF;
4049 
4050             --
4051             END IF;
4052 
4053 
4054             IF l_debug_on THEN
4055                 wsh_debug_sv.log(l_module_name, 'BO rows count', l_id_tab.count);
4056                 wsh_debug_sv.log(l_module_name, 'BO qtys count', l_bo_qtys.count);
4057                 wsh_debug_sv.log(l_module_name, 'Req qtys count', l_req_qtys.count);
4058                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_SHIP_CONFIRM_ACTIONS2.BACKORDER',WSH_DEBUG_SV.C_PROC_LEVEL);
4059             END IF;
4060             --
4061             wsh_ship_confirm_actions2.Backorder(
4062                 p_detail_ids     => l_id_tab,
4063                 p_line_ids       => l_line_ids,         -- Consolidation of BO Delivery details project
4064                 p_bo_qtys        => l_bo_qtys ,
4065                 p_req_qtys       => l_req_qtys ,
4066                 p_bo_qtys2       => l_bo_qtys2 ,
4067                 p_overpick_qtys  => l_overpick_qtys ,
4068                 p_overpick_qtys2 => l_overpick_qtys2 ,
4069                 p_sources        => l_sources, -- RTV BO Cons Changes
4070                 p_bo_mode        => 'CYCLE_COUNT' ,
4071                 x_out_rows       => x_action_out_rec.result_id_tab ,
4072                 x_cons_flags     => l_cons_flags,       -- Consolidation of BO Delivery details project
4073                 x_return_status  => l_return_status);
4074 
4075             -- Handle return status
4076             -- set message if necessary
4077             wsh_util_core.api_post_call(
4078                p_return_status => l_return_status,
4079                x_num_warnings  => l_number_of_warnings,
4080                x_num_errors    => l_number_of_errors,
4081                p_msg_data      => l_msg_data
4082                );
4083 
4084          IF l_debug_on THEN
4085             WSH_DEBUG_SV.log(l_module_name, 'Backorder Result tab count', x_action_out_rec.result_id_tab.count);
4086          END IF;
4087 
4088 	 --
4089 	 -- Consolidation of BO Delivery details project
4090   	 --
4091   	 -- Debug Statements
4092   	 --
4093   	 IF l_debug_on THEN
4094        	   WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_SHIPPING_PARAMS_PVT.Get_Global_Parameters',WSH_DEBUG_SV.C_PROC_LEVEL);
4095   	 END IF;
4096   	 --
4097 	 WSH_SHIPPING_PARAMS_PVT.Get_Global_Parameters(l_global_param_rec, l_return_status);
4098 
4099 	 -- Handle return status
4100          -- set message if necessary
4101          wsh_util_core.api_post_call(
4102                p_return_status => l_return_status,
4103                x_num_warnings  => l_number_of_warnings,
4104                x_num_errors    => l_number_of_errors,
4105                p_msg_data      => l_msg_data
4106                );
4107 
4108 	 -- x_action_out_rec.result_id_tab contains the original delivery_detail_id, for complete cycle-count.
4109 	 -- x_action_out_rec.result_id_tab contains the newly created delivery_detail_id, for
4110 	 -- partial cycle-count(split happens in this case).
4111 	 --
4112 	 -- Pass back the original delivery_detail_id, if it was merged into some other delivery detail
4113     	 IF (l_global_param_rec.consolidate_bo_lines = 'Y' AND l_cons_flags(1) = 'Y') THEN
4114             x_action_out_rec.result_id_tab(1) := l_id_tab(1);
4115   	 END IF;
4116 	 --
4117 
4118         --
4119         ELSIF p_action_prms.action_code IN ('PACKING-WORKBENCH',  'PICK-RELEASE-UI', 'RESOLVE-EXCEPTIONS-UI', 'FREIGHT-COSTS-UI') AND p_action_prms.caller = 'WSH_FSTRX' THEN
4120             -- do nothing. return
4121             -- These actions are supported only for UI(STF).
4122             -- Not applicable for other callers
4123 
4124             --Change made during Bugfix 4070732
4125             --Raise end of api so that handling of return status, reset flags are done there
4126             RAISE e_end_of_api;
4127 
4128         --
4129 	--Bug 3326794: Added code for the DELETE action.
4130 	ELSIF  p_action_prms.action_code = 'DELETE' THEN
4131 	--{
4132             IF l_debug_on THEN
4133 	    --{
4134                WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Delete',WSH_DEBUG_SV.C_PROC_LEVEL);
4135             --}
4136 	    END IF;
4137             --
4138             WSH_UTIL_CORE.Delete(
4139                    p_type          => 'DLVB',
4140                    p_rows          => l_id_tab,
4141                    x_return_status => l_return_status);
4142             --
4143             IF l_debug_on THEN
4144 	    --{
4145                wsh_debug_sv.log(l_module_name,'Return Status After Calling Delete',l_return_status);
4146             --}
4147 	    END IF;
4148             --
4149             wsh_util_core.api_post_call(
4150              p_return_status    => l_return_status,
4151              x_num_warnings     => l_number_of_warnings,
4152              x_num_errors       => l_number_of_errors);
4153 
4154         --}  -- End  Bug 3326794
4155 
4156         ELSE
4157             --
4158            FND_MESSAGE.SET_NAME('WSH','WSH_INVALID_ACTION_CODE');
4159            FND_MESSAGE.SET_TOKEN('ACT_CODE',p_action_prms.action_code );
4160             wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
4161            IF l_debug_on THEN
4162               wsh_debug_sv.logmsg(l_module_name,'WSH_INVALID_ACTION_CODE');
4163            END IF;
4164            RAISE FND_API.G_EXC_ERROR;
4165         --
4166         END IF;
4167         --
4168         --
4169         --Call to DCP
4170         --If profile is turned on.
4171      BEGIN
4172      --{
4173        --
4174        IF l_debug_on THEN
4175           wsh_debug_sv.log(l_module_name, 'l_check_dcp', l_check_dcp);
4176           wsh_debug_sv.log(l_module_name, 'g_call_dcp_check', WSH_DCP_PVT.G_CALL_DCP_CHECK);
4177        END IF;
4178        --
4179        IF NVL(l_check_dcp, -99) IN (1,2)
4180           AND NVL(WSH_DCP_PVT.G_CALL_DCP_CHECK, 'Y') = 'Y'
4181        THEN
4182        --{
4183         IF p_action_prms.action_code IN ('SPLIT-LINE', 'CYCLE-COUNT', 'PACK', 'AUTO-PACK')
4184         THEN
4185         --{
4186            IF l_debug_on THEN
4187               WSH_DEBUG_SV.LOGMSG(L_MODULE_NAME, 'CALLING DCP ');
4188            END IF;
4189 
4190            wsh_dcp_pvt.check_detail(
4191                      p_action_code => p_action_prms.action_code,
4192                      p_dtl_table => p_rec_attr_tab);
4193          --}
4194          END IF;
4195        --}
4196        END IF;
4197       EXCEPTION
4198       WHEN wsh_dcp_pvt.data_inconsistency_exception THEN
4199         if NOT l_debug_on OR l_debug_on is null then
4200            l_debug_on := wsh_debug_sv.is_debug_enabled;
4201         end if;
4202         IF l_debug_on THEN
4203           WSH_DEBUG_SV.logmsg(l_module_name,'data_inconsistency_exception');
4204         END IF;
4205         ROLLBACK TO DELIVERY_DETAIL_ACTION_GRP;
4206         GOTO api_start;
4207       WHEN OTHERS THEN
4208         IF l_debug_on THEN
4209           WSH_DEBUG_SV.logmsg(l_module_name,'When Others');
4210         END IF;
4211         null;
4212       --}
4213       END;
4214       --
4215         RAISE e_end_of_api;   -- J-IB-NPARIKH
4216 
4217 
4218   EXCEPTION
4219         WHEN e_end_of_api THEN
4220 
4221             IF del_cur%ISOPEN THEN
4222               CLOSE del_cur;
4223             END IF;
4224 
4225             --
4226             -- K LPN CONV. rv
4227             --
4228             IF WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y'
4229             THEN
4230             --{
4231                 IF l_debug_on THEN
4232                   WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',WSH_DEBUG_SV.C_PROC_LEVEL);
4233                 END IF;
4234 
4235                 WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS
4236                   (
4237                     p_in_rec             => l_lpn_in_sync_comm_rec,
4238                     x_return_status      => l_return_status,
4239                     x_out_rec            => l_lpn_out_sync_comm_rec
4240                   );
4241                 --
4242                 --
4243                 IF l_debug_on THEN
4244                   WSH_DEBUG_SV.log(l_module_name,'Return status after calling WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',l_return_status);
4245                 END IF;
4246                 --
4247                 --
4248                 WSH_UTIL_CORE.API_POST_CALL
4249                   (
4250                     p_return_status    => l_return_status,
4251                     x_num_warnings     => l_number_of_warnings,
4252                     x_num_errors       => l_number_of_errors,
4253                     p_raise_error_flag => false
4254                   );
4255             --}
4256             END IF;
4257             --
4258             -- K LPN CONV. rv
4259             --
4260 
4261             IF l_number_of_warnings > 0 THEN
4262                IF l_debug_on THEN
4263                   wsh_debug_sv.log (l_module_name,'Number of warnings', l_number_of_warnings);
4264                END IF;
4265                -- RAISE WSH_UTIL_CORE.G_EXC_WARNING;
4266                 l1_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
4267             ELSE
4268                 l1_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
4269             END IF;
4270             --
4271            -- Standard check of p_commit.
4272            IF FND_API.To_Boolean( p_commit ) THEN
4273               IF(l_debug_on) THEN
4274                  wsh_debug_sv.logmsg(l_module_name, 'Commit Work');
4275               END IF;
4276                --
4277                -- Start code for Bugfix 4070732
4278                --
4279               IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
4280                  IF l_debug_on THEN
4281                     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Process_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
4282                  END IF;
4283 
4284                  l_reset_flags := FALSE;
4285                  WSH_UTIL_CORE.Process_stops_for_load_tender(p_reset_flags   => l_reset_flags,
4286 						       x_return_status => l_return_status);
4287 
4288                  IF l_debug_on THEN
4289                     WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
4290                  END IF;
4291 
4292                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4293                     l1_return_status := l_return_status;
4294                  END IF;
4295 
4296               END IF;
4297              --
4298              -- End of code for Bugfix 4070732
4299              --
4300 
4301               COMMIT WORK;
4302            END IF;
4303 
4304            --bug 4070732
4305            --End of the API handling of calls to process_stops_for_load_tender
4306           IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name) THEN
4307           --{
4308              IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
4309              --{
4310 
4311                IF FND_API.To_Boolean( p_commit ) THEN
4312                  IF l_debug_on THEN
4313                     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
4314                  END IF;
4315 
4316                  WSH_UTIL_CORE.reset_stops_for_load_tender(p_reset_flags   => TRUE,
4317                                                         x_return_status => l_return_status);
4318 
4319                ELSE
4320                  IF l_debug_on THEN
4321                     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Process_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
4322                  END IF;
4323 
4324                  WSH_UTIL_CORE.Process_stops_for_load_tender(p_reset_flags   => TRUE,
4325                                                         x_return_status => l_return_status);
4326 
4327                END IF;
4328 
4329                  IF l_debug_on THEN
4330                     WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
4331                  END IF;
4332 
4333                  IF l1_return_status <> WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
4334                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4335                       IF l1_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
4336                         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4337                           l1_return_status := l_return_status;
4338 			END IF;
4339 		      ELSE
4340                          l1_return_status := l_return_status;
4341 		      END IF;
4342                    END IF;
4343                  END IF;
4344                --}
4345               END IF;
4346            --}
4347           END IF;
4348 
4349           x_return_status := l1_return_status;
4350     --bug 4070732
4351 
4352             FND_MSG_PUB.Count_And_Get
4353                (
4354                 p_count  => x_msg_count,
4355                 p_data  =>  x_msg_data,
4356                 p_encoded => FND_API.G_FALSE
4357                );
4358 
4359 
4360             IF l_debug_on THEN
4361                 WSH_DEBUG_SV.pop(l_module_name);
4362             END IF;
4363             --
4364         WHEN FND_API.G_EXC_ERROR THEN
4365                 -- ROLLBACK TO DELIVERY_DETAIL_ACTION_GRP;
4366                 x_return_status := FND_API.G_RET_STS_ERROR ;
4367                 --
4368                 IF del_cur%ISOPEN THEN
4369                   CLOSE del_cur;
4370                 END IF;
4371                 -- K LPN CONV. rv
4372                 --
4373                 IF WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y'
4374                 THEN
4375                 --{
4376                     IF l_debug_on THEN
4377                       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',WSH_DEBUG_SV.C_PROC_LEVEL);
4378                     END IF;
4379 
4380                     WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS
4381                       (
4382                         p_in_rec             => l_lpn_in_sync_comm_rec,
4383                         x_return_status      => l_return_status,
4384                         x_out_rec            => l_lpn_out_sync_comm_rec
4385                       );
4386                     --
4387                     --
4388                     IF l_debug_on THEN
4389                       WSH_DEBUG_SV.log(l_module_name,'Return status after calling WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',l_return_status);
4390                     END IF;
4391                     --
4392                     --
4393                     IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
4394                       x_return_status := l_return_status;
4395                     END IF;
4396                     --
4397                 --}
4398                 END IF;
4399                 --
4400                 -- K LPN CONV. rv
4401                 --
4402              --
4403              -- Start code for Bugfix 4070732
4404              --
4405              IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name)
4406              THEN
4407              --{
4408                 IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
4409                 --{
4410                   IF l_debug_on THEN
4411                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
4412                   END IF;
4413 
4414                   WSH_UTIL_CORE.Reset_stops_for_load_tender(p_reset_flags   => TRUE,
4415                      x_return_status => l_return_status);
4416 
4417                   IF l_debug_on THEN
4418                      WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
4419                   END IF;
4420 
4421                   IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
4422                      x_return_status := l_return_status;
4423                   END IF;
4424                 --}
4425                 END IF;
4426               --}
4427              END IF;
4428              --
4429              -- End of Code Bugfix 4070732
4430              --
4431                 FND_MSG_PUB.Count_And_Get
4432                   (
4433                      p_count  => x_msg_count,
4434                      p_data  =>  x_msg_data,
4435                p_encoded => FND_API.G_FALSE
4436                   );
4437 
4438 
4439                   IF l_debug_on THEN
4440                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
4441                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_ERROR');
4442                   END IF;
4443                   --
4444         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4445                 -- ROLLBACK TO DELIVERY_DETAIL_ACTION_GRP;
4446                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4447 
4448                 IF del_cur%ISOPEN THEN
4449                   CLOSE del_cur;
4450                 END IF;
4451 
4452                 --
4453                 -- K LPN CONV. rv
4454                 --
4455                 IF WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y'
4456                 THEN
4457                 --{
4458                     IF l_debug_on THEN
4459                       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',WSH_DEBUG_SV.C_PROC_LEVEL);
4460                     END IF;
4461 
4462                     WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS
4463                       (
4464                         p_in_rec             => l_lpn_in_sync_comm_rec,
4465                         x_return_status      => l_return_status,
4466                         x_out_rec            => l_lpn_out_sync_comm_rec
4467                       );
4468                     --
4469                     --
4470                     IF l_debug_on THEN
4471                       WSH_DEBUG_SV.log(l_module_name,'Return status after calling WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',l_return_status);
4472                     END IF;
4473                     --
4474                     --
4475                 --}
4476                 END IF;
4477                 --
4478                 -- K LPN CONV. rv
4479                 --
4480              --
4481              -- Start code for Bugfix 4070732
4482              --
4483              IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name)
4484              THEN
4485              --{
4486                 IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
4487                 --{
4488                   IF l_debug_on THEN
4489                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
4490                   END IF;
4491 
4492                   WSH_UTIL_CORE.Reset_stops_for_load_tender(p_reset_flags   => TRUE,
4493                      x_return_status => l_return_status);
4494 
4495                   IF l_debug_on THEN
4496                      WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
4497                   END IF;
4498                 --}
4499                 END IF;
4500               --}
4501              END IF;
4502              --
4503              -- End of Code Bugfix 4070732
4504              --
4505                 FND_MSG_PUB.Count_And_Get
4506                   (
4507                      p_count  => x_msg_count,
4508                      p_data  =>  x_msg_data,
4509                p_encoded => FND_API.G_FALSE
4510                   );
4511 
4512 
4513                   IF l_debug_on THEN
4514                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
4515                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
4516                   END IF;
4517                   --
4518     WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
4519       x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
4520           IF del_cur%ISOPEN THEN
4521             CLOSE del_cur;
4522           END IF;
4523 
4524           --
4525           -- K LPN CONV. rv
4526           --
4527           IF WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y'
4528           THEN
4529           --{
4530               IF l_debug_on THEN
4531                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',WSH_DEBUG_SV.C_PROC_LEVEL);
4532               END IF;
4533 
4534               WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS
4535                 (
4536                   p_in_rec             => l_lpn_in_sync_comm_rec,
4537                   x_return_status      => l_return_status,
4538                   x_out_rec            => l_lpn_out_sync_comm_rec
4539                 );
4540               --
4541               --
4542               IF l_debug_on THEN
4543                 WSH_DEBUG_SV.log(l_module_name,'Return status after calling WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',l_return_status);
4544               END IF;
4545               --
4546               --
4547               IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR, WSH_UTIL_CORE.G_RET_STS_ERROR) and x_return_status <> WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
4548                 x_return_status := l_return_status;
4549               END IF;
4550               --
4551           --}
4552           END IF;
4553           --
4554           -- K LPN CONV. rv
4555           --
4556       --
4557       -- Start code for Bugfix 4070732
4558       --
4559        IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name)
4560        THEN
4561        --{
4562           IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API)
4563           THEN
4564           --{
4565              IF l_debug_on THEN
4566                    WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Process_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
4567              END IF;
4568 
4569              WSH_UTIL_CORE.Process_stops_for_load_tender(p_reset_flags   => TRUE,
4570                                                          x_return_status => l_return_status);
4571 
4572              IF l_debug_on THEN
4573                   WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
4574              END IF;
4575 
4576              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4577                 x_return_status := l_return_status;
4578              END IF;
4579           --}
4580           END IF;
4581       ---}
4582       END IF;
4583      --
4584      -- End of Code Bugfix 4070732
4585      --
4586       FND_MSG_PUB.Count_And_Get
4587         (
4588          p_count  => x_msg_count,
4589          p_data  =>  x_msg_data,
4590          p_encoded => FND_API.G_FALSE
4591         );
4592 
4593       IF l_debug_on THEN
4594         WSH_DEBUG_SV.logmsg(l_module_name,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ',WSH_DEBUG_SV.C_EXCEP_LEVEL);
4595         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
4596       END IF;
4597       --
4598         WHEN OTHERS THEN
4599                 IF del_cur%ISOPEN THEN
4600                   CLOSE del_cur;
4601                 END IF;
4602 
4603                 -- ROLLBACK TO DELIVERY_DETAIL_ACTION_GRP;
4604                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4605                 IF cycle_count_cur%ISOPEN THEN
4606                    Close cycle_count_cur;
4607                 END IF;
4608               wsh_util_core.add_message(x_return_status, l_module_name);
4609                WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Delivery_Detail_Action');
4610                 --
4611                 -- K LPN CONV. rv
4612                 --
4613                 IF WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y'
4614                 THEN
4615                 --{
4616                     IF l_debug_on THEN
4617                       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',WSH_DEBUG_SV.C_PROC_LEVEL);
4618                     END IF;
4619 
4620                     WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS
4621                       (
4622                         p_in_rec             => l_lpn_in_sync_comm_rec,
4623                         x_return_status      => l_return_status,
4624                         x_out_rec            => l_lpn_out_sync_comm_rec
4625                       );
4626                     --
4627                     --
4628                     IF l_debug_on THEN
4629                       WSH_DEBUG_SV.log(l_module_name,'Return status after calling WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',l_return_status);
4630                     END IF;
4631                     --
4632                     --
4633                 --}
4634                 END IF;
4635                 --
4636                 -- K LPN CONV. rv
4637                 --
4638              --
4639              -- Start code for Bugfix 4070732
4640              --
4641              IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name)
4642              THEN
4643              --{
4644                 IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
4645                 --{
4646                   IF l_debug_on THEN
4647                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
4648                   END IF;
4649 
4650                   WSH_UTIL_CORE.Reset_stops_for_load_tender(p_reset_flags   => TRUE,
4651                      x_return_status => l_return_status);
4652 
4653                   IF l_debug_on THEN
4654                      WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
4655                   END IF;
4656                 --}
4657                 END IF;
4658               --}
4659              END IF;
4660              --
4661              -- End of Code Bugfix 4070732
4662              --
4663                 FND_MSG_PUB.Count_And_Get
4664                   (
4665                      p_count  => x_msg_count,
4666                      p_data  =>  x_msg_data,
4667                p_encoded => FND_API.G_FALSE
4668                   );
4669     --
4670 
4671                  IF l_debug_on THEN
4672                      WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
4673                      WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
4674                  END IF;
4675                  --
4676     END Delivery_Detail_Action;
4677 
4678 
4679     -- ---------------------------------------------------------------------
4680     -- Procedure: Create_Update_Delivery_Detail
4681     --
4682     -- Parameters:        --
4683     -- Description:  This procedure is the new API for wrapping the logic of CREATE/UPDATE of delivery details
4684     -- Created:   Harmonization Project. Patchset I
4685     -- -----------------------------------------------------------------------
4686 
4687     PROCEDURE Create_Update_Delivery_Detail
4688     (
4689        -- Standard Parameters
4690        p_api_version_number  IN  NUMBER,
4691        p_init_msg_list           IN    VARCHAR2,
4692        p_commit                  IN    VARCHAR2,
4693        x_return_status           OUT NOCOPY  VARCHAR2,
4694        x_msg_count               OUT NOCOPY  NUMBER,
4695        x_msg_data                OUT NOCOPY  VARCHAR2,
4696 
4697        -- Procedure Specific Parameters
4698        p_detail_info_tab         IN WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type,
4699        p_IN_rec                  IN   WSH_GLBL_VAR_STRCT_GRP.detailInRecType,
4700        x_OUT_rec                 OUT NOCOPY   WSH_GLBL_VAR_STRCT_GRP.detailOutRecType
4701     ) IS
4702 
4703         l_api_name              CONSTANT VARCHAR2(30)   := 'Create_Update_Delivery_Detail';
4704         l_api_version           CONSTANT NUMBER         := 1.0;
4705         --
4706   --
4707   l_return_status             VARCHAR2(32767);
4708   l_msg_count                 NUMBER;
4709   l_msg_data                  VARCHAR2(32767);
4710   l_program_name              VARCHAR2(32767);
4711         --
4712   l_number_of_errors    NUMBER := 0;
4713   l_number_of_warnings  NUMBER := 0;
4714   --
4715         l_loop_num_error      NUMBER := 0;
4716         l_loop_num_warn       NUMBER := 0;
4717         --
4718         l_counter             NUMBER := 0;
4719         l_index               NUMBER;
4720 
4721         l_detail_info_tab     WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type;
4722         l_valid_index_tab     wsh_util_core.id_tab_type;
4723         l_delivery_id         NUMBER;
4724         l_delivery_detail_rec WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Rec_Type;
4725         l_validation_tab      wsh_util_core.id_tab_type;
4726   --
4727         l_details_marked        WSH_UTIL_CORE.Id_Tab_Type;
4728         l_dummy_ser_range_tab   WSH_GLBL_VAR_STRCT_GRP.ddSerialRangeTabType;
4729         mark_reprice_error      EXCEPTION;
4730 
4731         --
4732         CURSOR det_to_del_cur(p_detail_id NUMBER) IS
4733            SELECT wda.delivery_id
4734            FROM wsh_delivery_assignments_v wda
4735            WHERE wda.delivery_detail_id = p_detail_id;
4736 
4737 -- anxsharm for Load Tender
4738         l_detail_tender_tab wsh_util_core.id_tab_type;
4739         l_trip_id_tab wsh_util_core.id_tab_type;
4740 
4741         --
4742 l_debug_on BOOLEAN;
4743   --
4744   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CREATE_UPDATE_DELIVERY_DETAIL';
4745   --
4746 
4747   BEGIN
4748 
4749         -- Standard Start of API savepoint
4750         --
4751         l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
4752         --
4753         IF l_debug_on IS NULL
4754         THEN
4755             l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
4756         END IF;
4757         --
4758         SAVEPOINT   CREATE_UPDATE_DEL_DETAIL_GRP;
4759         --
4760         -- Debug Statements
4761         --
4762         IF l_debug_on THEN
4763             WSH_DEBUG_SV.push(l_module_name);
4764             --
4765             WSH_DEBUG_SV.log(l_module_name,'P_API_VERSION_NUMBER',P_API_VERSION_NUMBER);
4766             WSH_DEBUG_SV.log(l_module_name,'P_INIT_MSG_LIST',P_INIT_MSG_LIST);
4767             WSH_DEBUG_SV.log(l_module_name,'P_COMMIT',P_COMMIT);
4768             WSH_DEBUG_SV.log(l_module_name, 'Caller', p_In_rec.caller);
4769             WSH_DEBUG_SV.log(l_module_name, 'Action Code', p_In_rec.action_code);
4770             WSH_DEBUG_SV.log(l_module_name,'Input Table count', p_detail_info_tab.count);
4771         END IF;
4772         --
4773 
4774         -- Initialize message list if p_init_msg_list is set to TRUE.
4775         IF FND_API.to_Boolean( p_init_msg_list )
4776         THEN
4777                 FND_MSG_PUB.initialize;
4778         END IF;
4779 
4780         --  Initialize API return status to success
4781         x_return_status       := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
4782         l_number_of_errors    := 0;
4783         l_number_of_warnings := 0;
4784 
4785       /* Call the New Overloaded API */
4786 
4787         create_update_delivery_detail(
4788             p_api_version_number      =>  p_api_version_number,
4789             p_init_msg_list           =>  FND_API.G_FALSE,
4790             p_commit                  =>  FND_API.G_FALSE,
4791             x_return_status           =>  l_return_status,
4792             x_msg_count               =>  l_msg_count,
4793             x_msg_data                =>  l_msg_data,
4794             p_detail_info_tab         =>  p_detail_info_tab,
4795             p_IN_rec                  =>  p_in_rec,
4796             x_OUT_rec                 =>  x_out_rec,
4797             p_serial_range_tab        =>  l_dummy_ser_range_tab
4798             );
4799 
4800               wsh_util_core.api_post_call(
4801                             p_return_status  =>l_return_status,
4802                             x_num_warnings     =>l_number_of_warnings,
4803                             x_num_errors       =>l_number_of_errors);
4804 
4805     IF l_number_of_warnings > 0 THEN
4806        IF l_debug_on THEN
4807         wsh_debug_sv.log(l_module_name,'Number of warnings', l_number_of_warnings);
4808        END IF;
4809        RAISE WSH_UTIL_CORE.G_EXC_WARNING;
4810     END IF;
4811 
4812 
4813        -- Standard check of p_commit.
4814        IF FND_API.To_Boolean( p_commit ) THEN
4815           IF(l_debug_on) THEN
4816              wsh_debug_sv.logmsg(l_module_name, 'Commit Work');
4817           END IF;
4818           COMMIT WORK;
4819        END IF;
4820 
4821        FND_MSG_PUB.Count_And_Get
4822          (
4823           p_count  => x_msg_count,
4824           p_data  =>  x_msg_data,
4825           p_encoded => FND_API.G_FALSE
4826          );
4827 
4828       IF l_debug_on THEN
4829          WSH_DEBUG_SV.pop(l_module_name);
4830       END IF;
4831 --
4832   EXCEPTION
4833         WHEN FND_API.G_EXC_ERROR THEN
4834                 ROLLBACK TO CREATE_UPDATE_DEL_DETAIL_GRP;
4835                 x_return_status := FND_API.G_RET_STS_ERROR ;
4836                 FND_MSG_PUB.Count_And_Get
4837                   (
4838                      p_count  => x_msg_count,
4839                      p_data  =>  x_msg_data,
4840                p_encoded => FND_API.G_FALSE
4841                   );
4842                   --
4843                   IF l_debug_on THEN
4844                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
4845                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_ERROR');
4846                   END IF;
4847                   --
4848         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4849                 ROLLBACK TO CREATE_UPDATE_DEL_DETAIL_GRP;
4850                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4851                 FND_MSG_PUB.Count_And_Get
4852                   (
4853                      p_count  => x_msg_count,
4854                      p_data  =>  x_msg_data,
4855                p_encoded => FND_API.G_FALSE
4856                   );
4857 
4858                   --
4859                   IF l_debug_on THEN
4860                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
4861                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
4862                   END IF;
4863                   --
4864         WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
4865              x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
4866              FND_MSG_PUB.Count_And_Get
4867               (
4868                 p_count  => x_msg_count,
4869                 p_data  =>  x_msg_data,
4870                 p_encoded => FND_API.G_FALSE
4871               );
4872         --
4873         IF l_debug_on THEN
4874             WSH_DEBUG_SV.logmsg(l_module_name,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ',WSH_DEBUG_SV.C_EXCEP_LEVEL);
4875            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
4876        END IF;
4877 --
4878         WHEN mark_reprice_error then
4879                 FND_MESSAGE.Set_Name('WSH', 'WSH_REPRICE_REQUIRED_ERR');
4880                 wsh_util_core.add_message(x_return_status, l_module_name);
4881                 x_return_status := l_return_status;
4882                  FND_MSG_PUB.Count_And_Get
4883                   (
4884                      p_count  => x_msg_count,
4885                      p_data  =>  x_msg_data,
4886                p_encoded => FND_API.G_FALSE
4887                   );
4888     --
4889 
4890                 --
4891                 IF l_debug_on THEN
4892                     WSH_DEBUG_SV.logmsg(l_module_name,'MARK_REPRICE_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
4893                     WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:MARK_REPRICE_ERROR');
4894                 END IF;
4895                 --
4896         WHEN OTHERS THEN
4897                 ROLLBACK TO CREATE_UPDATE_DEL_DETAIL_GRP;
4898                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4899                wsh_util_core.add_message(x_return_status, l_module_name);
4900                WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Create_Update_Delivery_Detail');
4901                 FND_MSG_PUB.Count_And_Get
4902                   (
4903                      p_count  => x_msg_count,
4904                      p_data  =>  x_msg_data,
4905                p_encoded => FND_API.G_FALSE
4906                   );
4907     --
4908 
4909           IF l_debug_on THEN
4910                WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
4911                WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
4912          END IF;
4913 --
4914   END Create_Update_Delivery_Detail;
4915 
4916 
4917 /* ----------------------------------------------------
4918   PROCEDURE  Create_containers
4919   ----------------------------------------------------*/
4920     -- lpn conv
4921     PROCEDURE  Create_containers(
4922                 p_detail_info_tab     IN WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type ,
4923                 p_detail_IN_rec       IN  WSH_GLBL_VAR_STRCT_GRP.detailInRecType,
4924                 x_container_ids   OUT NOCOPY  WSH_UTIL_CORE.ID_TAB_TYPE,
4925                 x_return_status       OUT NOCOPY  varchar2
4926                 )
4927       IS
4928       l_debug_on BOOLEAN;
4929       --
4930       l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME ||
4931                                               '.' || 'CREATE_CONTAINERS';
4932       l_generate boolean := FALSE;
4933       l_create_for_wms boolean := FALSE;
4934       l_create_one_record boolean := FALSE;
4935       l_lpn_out_tab           WMS_Data_Type_Definitions_pub.LPNTableType;
4936       l_gen_lpn_rec           WMS_Data_Type_Definitions_pub.AutoCreateLPNRecordType;
4937       l_verify_org_level     NUMBER;
4938       l_verify_cont_item     NUMBER;
4939       l_organization_id NUMBER    := NULL;
4940       l_organization_code VARCHAR2(240) := NULL;
4941       l_cont_item_id    NUMBER    := NULL;
4942       l_cont_item_seg   FND_FLEX_EXT.SegmentArray;
4943       l_cont_item_name  VARCHAR2(30)  := NULL;
4944       l_wms_return_status       VARCHAR2(10);
4945       l_wms_msg_count           NUMBER;
4946       l_wms_msg_data            VARCHAR2(2000);
4947       l_wms_organization_id     NUMBER;
4948       l_total_length            NUMBER;
4949       l_name_prefix             VARCHAR2(30);
4950       l_name_suffix             VARCHAR2(30);
4951       l_base_number             NUMBER;
4952       l_base_number_dummy       NUMBER;
4953       l_container_names         WSH_GLBL_VAR_STRCT_GRP.v50_Tbl_Type;
4954       l_lpn_ids                 wsh_util_core.id_tab_type;
4955       i                         NUMBER;
4956       j                         NUMBER;
4957       l_orig_value              varchar2(2);
4958       l_update_container_orig   VARCHAR2(2) := WSH_WMS_LPN_GRP.g_update_to_container;
4959 -- bmso
4960       l_lpn_table             WMS_Data_Type_Definitions_pub.LPNTableType;
4961       l_container_info_rec        WSH_GLBL_VAR_STRCT_GRP.ContInfoRectype;
4962       l_container_rec       WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Rec_Type;
4963       l_cont_dummy_tab  WSH_UTIL_CORE.id_tab_type;
4964       l_del_assg_rec        WSH_DELIVERY_DETAILS_PKG.Delivery_Assignments_Rec_Type;
4965       l_assignment_dummy_tab  WSH_UTIL_CORE.id_tab_type;
4966       l_wms_enabled             BOOLEAN;
4967       l_return_status           VARCHAR2(2);
4968       l_number_of_warnings      NUMBER := 0;
4969       l_number_of_errors        NUMBER := 0;
4970       l_suffix_length           NUMBER;
4971       l_additional_cont_attr    wsh_glbl_var_strct_grp.LPNRecordType;
4972 
4973       l_new_session BOOLEAN := TRUE;
4974 
4975       CURSOR c_get_default_parameters (v_organization_id NUMBER) IS
4976       SELECT LPN_STARTING_NUMBER
4977       FROM mtl_parameters
4978       WHERE ORGANIZATION_ID = v_organization_id;
4979 
4980       CURSOR c_get_wms_next_seq IS
4981       SELECT  WMS_LICENSE_PLATE_NUMBERS_S2.nextval
4982       FROM DUAL;
4983       CURSOR c_get_wms_curr_seq IS
4984       SELECT  WMS_LICENSE_PLATE_NUMBERS_S2.currval
4985       FROM DUAL;
4986 
4987       l_lpn_starting_num NUMBER;
4988       l_wms_sequence  NUMBER;
4989 
4990       e_lpn_count_invalid           EXCEPTION;
4991       e_NO_INV_ITEM           EXCEPTION;
4992 
4993 
4994 
4995     BEGIN
4996         --
4997         l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
4998         --
4999         IF l_debug_on IS NULL
5000         THEN
5001             l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
5002         END IF;
5003         --
5004         IF l_debug_on THEN
5005             WSH_DEBUG_SV.push(l_module_name);
5006             WSH_DEBUG_SV.log(l_module_name, 'p_detail_info_tab.count',
5007                                                    p_detail_info_tab.count);
5008         END IF;
5009 
5010         SAVEPOINT   s_create_containers_DDGPB;
5011 
5012         l_orig_value := WSH_WMS_LPN_GRP.g_call_group_api;
5013 
5014         IF p_detail_info_tab.COUNT > 0 THEN
5015            l_create_for_wms := TRUE;
5016         ELSIF p_detail_IN_rec.quantity = 1
5017           AND ( p_detail_IN_rec.container_name IS NOT NULL) THEN
5018            l_create_one_record := TRUE;
5019         ELSIF NVL(p_detail_IN_rec.quantity,0) <=0 THEN
5020            IF l_debug_on THEN
5021               WSH_DEBUG_SV.log(l_module_name,
5022                                'Invalid quantity', p_detail_IN_rec.quantity);
5023            END IF;
5024            raise fnd_api.g_exc_error;
5025         ELSE
5026            l_generate := TRUE;
5027         END IF;
5028 
5029         IF l_generate OR l_create_one_record THEN --{
5030 
5031            -- This portion creates or generates containers for non-wms callers
5032 
5033            --validate the container item, and org bmso
5034 
5035            l_verify_org_level := WSH_ACTIONS_LEVELS.g_validation_level_tab(WSH_ACTIONS_LEVELS.C_CONTAINER_ORG_LVL);
5036 
5037            l_verify_cont_item := WSH_ACTIONS_LEVELS.g_validation_level_tab(WSH_ACTIONS_LEVELS.C_CONT_ITEM_LVL);
5038 
5039              l_organization_id := p_detail_IN_rec.organization_id;
5040              l_organization_code := p_detail_IN_rec.organization_code;
5041              --
5042              IF l_verify_org_level = 1 THEN --{
5043                 --
5044                 WSH_UTIL_VALIDATE.Validate_Org (l_organization_id,
5045                            l_organization_code,
5046                            l_return_status);
5047                 IF l_return_status NOT IN ( wsh_util_core.g_ret_sts_success ,WSH_UTIL_CORE.G_RET_STS_WARNING)
5048                 THEN
5049                    fnd_message.set_name('WSH', 'WSH_OI_INVALID_ORG');
5050                    wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5051                 END IF;
5052 
5053                 wsh_util_core.api_post_call(
5054                     p_return_status => l_return_status,
5055                     x_num_warnings  => l_number_of_warnings,
5056                     x_num_errors    => l_number_of_errors
5057                 );
5058 
5059              END IF; --}
5060              --
5061              -- validate item
5062              l_cont_item_id := p_detail_IN_rec.container_item_id;
5063              l_cont_item_seg := p_detail_IN_rec.container_item_seg;
5064              l_cont_item_name := p_detail_IN_rec.container_item_name;
5065              --
5066              IF l_verify_cont_item = 1 THEN --{
5067                 -- wms change:  Validate Item check is to be skipped if the
5068                 -- Org. is WMS enabled
5069 
5070                 IF l_debug_on THEN
5071                    WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WMS_INSTALL.CHECK_INSTALL',WSH_DEBUG_SV.C_PROC_LEVEL);
5072                 END IF;
5073 
5074                 l_wms_enabled := WMS_INSTALL.check_install(
5075                                     l_wms_return_status,
5076                                     l_wms_msg_count,
5077                                     l_wms_msg_data,
5078                                     l_organization_id);
5079 
5080                 wsh_util_core.api_post_call(
5081                              p_return_status => l_wms_return_status,
5082                              x_num_warnings  => l_number_of_warnings,
5083                              x_num_errors    => l_number_of_errors
5084                 );
5085 
5086                 IF l_debug_on THEN
5087                    wsh_debug_sv.log(l_module_name, 'wms enabled',
5088                                                             l_wms_enabled);
5089                 END IF;
5090                 IF (l_wms_enabled = FALSE) THEN --{
5091                    IF (l_cont_item_id IS NULL
5092                      AND l_cont_item_name IS NULL
5093                      AND l_cont_item_seg.count = 0) then --{
5094                       fnd_message.set_name('WSH', 'WSH_CONT_INVALID_ITEM');
5095                       WSH_UTIL_CORE.ADD_MESSAGE(wsh_util_core.g_ret_sts_error, l_module_name);
5096                       RAISE e_NO_INV_ITEM;
5097                    ELSE --}{
5098                       --
5099                       WSH_UTIL_VALIDATE.Validate_Item
5100                          (p_inventory_item_id => l_cont_item_id,
5101                           p_inventory_item   => l_cont_item_name,
5102                           p_organization_id   => l_organization_id,
5103                           p_seg_array      => l_cont_item_seg,
5104                           x_return_status     => l_return_status,
5105                           p_item_type      => 'CONT_ITEM');
5106                       IF l_return_status NOT IN ( WSH_UTIL_CORE.G_RET_STS_SUCCESS, WSH_UTIL_CORE.G_RET_STS_WARNING)
5107                       THEN
5108                          fnd_message.set_name('WSH', 'WSH_CONT_INVALID_ITEM');
5109                          WSH_UTIL_CORE.ADD_MESSAGE(wsh_util_core.g_ret_sts_error, l_module_name);
5110                          wsh_util_core.api_post_call(
5111                              p_return_status => l_return_status,
5112                              x_num_warnings  => l_number_of_warnings,
5113                              x_num_errors    => l_number_of_errors
5114                          );
5115                       END IF;
5116                   END IF; --}
5117                ELSE --}{
5118                   fnd_message.set_name('WSH', 'WSH_INCORRECT_ORG');
5119                   fnd_message.set_token('ORG_CODE', l_organization_code);
5120                   wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5121                   RAISE FND_API.G_EXC_ERROR;
5122                END IF;  -- wms_enabled }
5123             END IF; -- verify item}
5124             --
5125 
5126            IF l_generate  THEN --{
5127              IF c_wms_code_present = 'Y' THEN --{
5128 
5129              -- calculating the parameter needed to generate container name
5130 
5131              IF (p_detail_IN_rec.name_suffix IS NOT NULL)
5132                AND (NVL(p_detail_IN_rec.ucc_128_suffix_flag,2) = 1)
5133              THEN
5134                 IF l_debug_on THEN
5135                    wsh_debug_sv.log(l_module_name, 'Error ucc_128_suffix_flag is set to 1 and name_suffix is set to ',p_detail_IN_rec.name_suffix);
5136                 END IF;
5137                 FND_MESSAGE.SET_NAME('WSH', 'WSH_UCC128_ERROR'); --bmso new
5138                 wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5139                 RAISE FND_API.G_EXC_ERROR;
5140              END IF;
5141 
5142              IF p_detail_IN_rec.ucc_128_suffix_flag = 1 THEN
5143                 l_suffix_length := 1;
5144                 -- Also the prefix should be integer
5145                 BEGIN
5146                    IF TRUNC(NVL(p_detail_IN_rec.name_prefix,0))
5147                         <> NVL(p_detail_IN_rec.name_prefix,0)
5148                       OR TRUNC(NVL(p_detail_IN_rec.name_prefix,0)) < 0
5149                    THEN
5150                       FND_MESSAGE.SET_NAME('WSH', 'WSH_UCC128_PREFIX_ERR'); --bmso new
5151                       wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5152 
5153                    END IF;
5154                 EXCEPTION
5155                    WHEN OTHERS THEN
5156                       FND_MESSAGE.SET_NAME('WSH', 'WSH_UCC128_PREFIX_ERR'); --bmso new
5157                       wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5158                 END;
5159              ELSE
5160                 l_suffix_length := NVL(LENGTH(p_detail_IN_rec.name_suffix),0);
5161              END IF;
5162 
5163              OPEN c_get_default_parameters(l_organization_id);
5164              FETCH c_get_default_parameters INTO l_lpn_starting_num;
5165              CLOSE c_get_default_parameters;
5166 
5167              l_base_number_dummy := NVL(p_detail_IN_rec.base_number,
5168                                                    l_lpn_starting_num);
5169              l_new_session := TRUE;
5170              IF l_base_number_dummy IS NULL THEN --{
5171                 BEGIN
5172                    OPEN c_get_wms_curr_seq ;
5173                    fetch c_get_wms_curr_seq INTO l_wms_sequence;
5174                    CLOSE c_get_wms_curr_seq;
5175                    l_base_number_dummy := l_wms_sequence + 1;
5176                 EXCEPTION
5177                    WHEN OTHERS THEN
5178                       l_new_session := FALSE;
5179                       OPEN c_get_wms_next_seq ;
5180                       fetch c_get_wms_next_seq INTO l_wms_sequence;
5181                       CLOSE c_get_wms_next_seq;
5182                       l_base_number_dummy := l_wms_sequence;
5183                 END ;
5184              END IF; --}
5185 
5186              IF l_new_session THEN
5187                 l_base_number_dummy := l_base_number_dummy + p_detail_IN_rec.quantity - 1;
5188              ELSE
5189                 l_base_number_dummy := l_base_number_dummy + p_detail_IN_rec.quantity ;
5190              END IF;
5191 
5192 
5193              IF l_debug_on THEN
5194                 wsh_debug_sv.log(l_module_name, 'l_lpn_starting_num',l_lpn_starting_num);
5195                 wsh_debug_sv.log(l_module_name, 'l_wms_sequence',l_wms_sequence);
5196                 wsh_debug_sv.log(l_module_name, 'l_base_number_dummy',l_base_number_dummy);
5197              END IF;
5198 
5199              IF p_detail_IN_rec.num_digits IS NOT NULL THEN
5200                 l_total_length := NVL(length(p_detail_IN_rec.name_prefix),0)
5201                     + l_suffix_length
5202                     + GREATEST(p_detail_IN_rec.num_digits,NVL(LENGTH(l_base_number_dummy),0));
5203              END IF;
5204 
5205 
5206              l_total_length := NVL(l_total_length,FND_API.G_MISS_NUM);
5207              l_name_prefix := NVL(p_detail_IN_rec.name_prefix,FND_API.G_MISS_CHAR);
5208              l_name_suffix := NVL(p_detail_IN_rec.name_suffix,FND_API.G_MISS_CHAR);
5209 
5210              l_gen_lpn_rec.container_item_id := l_cont_item_id;
5211              l_gen_lpn_rec.organization_id :=  l_organization_id;
5212              l_gen_lpn_rec.lpn_prefix:=  l_name_prefix;
5213              l_gen_lpn_rec.lpn_suffix := l_name_suffix;
5214              l_gen_lpn_rec.starting_num :=  p_detail_IN_rec.base_number;
5215              IF p_detail_IN_rec.base_number IS NOT NULL THEN --{
5216                 IF p_detail_IN_rec.base_number <> FND_API.G_MISS_NUM THEN
5217                    IF l_lpn_starting_num = p_detail_IN_rec.base_number THEN
5218                       l_gen_lpn_rec.starting_num := NULL;
5219                    END IF;
5220                 END IF;
5221              END IF ; --}
5222              l_gen_lpn_rec.total_lpn_length :=  l_total_length;
5223              l_gen_lpn_rec.quantity:= p_detail_IN_rec.quantity;
5224              --l_gen_lpn_rec.caller :=  p_detail_IN_rec.caller;
5225              l_gen_lpn_rec.ucc_128_suffix_flag :=  p_detail_IN_rec.ucc_128_suffix_flag;
5226 
5227              WSH_WMS_LPN_GRP.g_call_group_api := 'N';
5228              WSH_WMS_LPN_GRP.g_update_to_container := 'N';
5229 
5230              IF l_debug_on THEN
5231                 wsh_debug_sv.logmsg(l_module_name, 'Calling wms_container_grp.Auto_Create_LPNs');
5232              END IF;
5233              wms_container_grp.Auto_Create_LPNs (
5234                 p_api_version         => 1.0
5235                , p_init_msg_list      => fnd_api.g_false
5236                , p_commit             => fnd_api.g_false
5237                , x_return_status      => l_return_status
5238                , x_msg_count          => l_wms_msg_count
5239                , x_msg_data           => l_wms_msg_data
5240                , p_caller               => 'WSH_GENERATE'
5241                , p_gen_lpn_rec        => l_gen_lpn_rec
5242                , p_lpn_table          => l_lpn_out_tab
5243              );
5244 
5245              WSH_WMS_LPN_GRP.g_call_group_api := l_orig_value;
5246              WSH_WMS_LPN_GRP.g_update_to_container := l_update_container_orig;
5247 
5248              wsh_util_core.api_post_call(
5249                  p_return_status => l_return_status,
5250                  x_num_warnings  => l_number_of_warnings,
5251                  x_num_errors    => l_number_of_errors,
5252                  p_msg_data      => l_wms_msg_data
5253              );
5254              --bms get the names
5255              i := l_lpn_out_tab.FIRST;
5256              --if i null then error out bmso
5257              j := 1;
5258              IF l_debug_on THEN
5259                 wsh_debug_sv.log(l_module_name, 'l_lpn_out_tab.count',l_lpn_out_tab.count);
5260              END IF;
5261              WHILE i IS NOT NULL LOOP --{
5262                 l_container_info_rec.lpn_ids(j) := l_lpn_out_tab(i).lpn_id;
5263                 l_container_info_rec.container_names(j) :=
5264                                        l_lpn_out_tab(i).license_plate_number;
5265                 IF l_debug_on THEN
5266                    wsh_debug_sv.log(l_module_name, 'name',
5267                                       l_container_info_rec.container_names(j));
5268                    wsh_debug_sv.log(l_module_name, 'lpn_id',
5269                                               l_container_info_rec.lpn_ids(j));
5270                 END IF;
5271 
5272                 IF l_container_info_rec.lpn_ids(j) IS NULL THEN
5273                    FND_MESSAGE.SET_NAME('WSH', 'WSH_REQUIRED_FIELD_NULL');
5274                    FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'LPN_ID');
5275                    wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5276                    RAISE FND_API.G_EXC_ERROR;
5277 
5278                 ELSIF l_container_info_rec.container_names(j) IS NULL THEN
5279                    FND_MESSAGE.SET_NAME('WSH', 'WSH_REQUIRED_FIELD_NULL');
5280                    FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'CONTAINER_NAME');
5281                    wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5282                    RAISE FND_API.G_EXC_ERROR;
5283 
5284                 END IF;
5285 
5286                 i := l_lpn_out_tab.NEXT(i);
5287                 j := j + 1;
5288 
5289              END LOOP; --}
5290 
5291              l_container_rec.weight_uom_code :=
5292                                      l_lpn_out_tab(1).GROSS_WEIGHT_UOM_CODE;
5293              l_container_rec.gross_weight :=
5294                                        l_lpn_out_tab(1).GROSS_WEIGHT;
5295              l_additional_cont_attr.tare_weight :=
5296                                        l_lpn_out_tab(1).TARE_WEIGHT;
5297              l_additional_cont_attr.tare_weight_uom_code :=
5298                                        l_lpn_out_tab(1).TARE_WEIGHT_UOM_CODE;
5299              l_container_rec.volume_uom_code :=
5300                        l_lpn_out_tab(1).CONTAINER_VOLUME_UOM;
5301              l_container_rec.volume := l_lpn_out_tab(1).CONTAINER_VOLUME;
5302              l_additional_cont_attr.filled_volume_uom_code :=
5303                        l_lpn_out_tab(1).CONTENT_VOLUME_UOM_CODE;
5304              l_container_rec.filled_volume := l_lpn_out_tab(1).CONTENT_VOLUME;
5305              l_container_rec.locator_id := l_lpn_out_tab(1).locator_id;
5306              l_container_rec.subinventory := l_lpn_out_tab(1).SUBINVENTORY_CODE;
5307              l_container_rec.inventory_item_id := l_cont_item_id;
5308              l_container_rec.organization_id := l_organization_id;
5309 
5310              -- uncomment when the column is there
5311              --l_container_rec.volume := l_lpn_out_tab(1).CONTAINER_VOLUME;
5312              ELSE --}{
5313              /* bmso comment out this protion when WMS code is there */
5314              wsh_container_actions.Create_Multiple_Cont_name (
5315                   p_cont_name     => p_detail_IN_rec.container_name,
5316                   p_cont_name_pre => p_detail_IN_rec.name_prefix,
5317                   p_cont_name_suf => p_detail_IN_rec.name_suffix,
5318                   p_cont_name_num => p_detail_IN_rec.base_number,
5319                   p_cont_name_dig => p_detail_IN_rec.num_digits,
5320                   p_quantity      => p_detail_IN_rec.quantity,
5321                   x_cont_names    => l_container_info_rec.container_names,
5322                   x_return_status => l_return_status
5323              );
5324              wsh_util_core.api_post_call(
5325                  p_return_status => l_return_status,
5326                  x_num_warnings  => l_number_of_warnings,
5327                  x_num_errors    => l_number_of_errors
5328              );
5329              i := l_container_info_rec.container_names.FIRST;
5330              WHILE i IS NOT NULL LOOP --{
5331                 l_container_info_rec.lpn_ids(i) := NULL;
5332                 i := l_container_info_rec.container_names.NEXT(i);
5333              END LOOP; --} comment out till here
5334              l_container_rec.inventory_item_id := l_cont_item_id;
5335              l_container_rec.organization_id := l_organization_id;
5336              END IF; --}
5337              IF l_container_info_rec.lpn_ids.COUNT <> p_detail_IN_rec.quantity
5338              THEN
5339                 RAISE e_lpn_count_invalid;
5340              END IF;
5341 
5342            ELSIF  l_create_one_record THEN --}{
5343              --bmso
5344              IF c_wms_code_present = 'Y' THEN --{
5345              IF l_debug_on THEN
5346                 wsh_debug_sv.logmsg(l_module_name, 'Calling wms_container_grp.create_lpns');
5347              END IF;
5348              l_lpn_table(1).license_plate_number :=
5349                                                p_detail_IN_rec.container_name;
5350              l_lpn_table(1).inventory_item_id := l_cont_item_id;
5351              l_lpn_table(1).organization_id := l_organization_id;
5352              --l_lpn_table(1).ucc_128_suffix_flag :=
5353                                         --p_detail_IN_rec.ucc_128_suffix_flag;
5354 
5355              WSH_WMS_LPN_GRP.g_call_group_api := 'N';
5356              WSH_WMS_LPN_GRP.g_update_to_container := 'N';
5357 
5358              wms_container_grp.create_lpns(
5359                    p_api_version           => 1.0,
5360                    p_init_msg_list         => fnd_api.g_false,
5361                    p_commit                => fnd_api.g_false,
5362                    x_return_status         => l_return_status,
5363                    x_msg_count             => l_wms_msg_count,
5364                    x_msg_data              => l_wms_msg_data,
5365                    p_caller                => 'WSH_CREATE',
5366                    p_lpn_table             => l_lpn_table
5367              );
5368              WSH_WMS_LPN_GRP.g_call_group_api := l_orig_value;
5369              WSH_WMS_LPN_GRP.g_update_to_container := l_update_container_orig;
5370 
5371              wsh_util_core.api_post_call(
5372                  p_return_status => l_return_status,
5373                  x_num_warnings  => l_number_of_warnings,
5374                  x_num_errors    => l_number_of_errors,
5375                  p_msg_data      => l_wms_msg_data
5376              );
5377              l_container_info_rec.container_names(1) := l_lpn_table(1).license_plate_number;
5378              l_container_info_rec.lpn_ids(1) := l_lpn_table(1).lpn_id;
5379 
5380              IF l_container_info_rec.lpn_ids(1) IS NULL THEN
5381                 FND_MESSAGE.SET_NAME('WSH', 'WSH_REQUIRED_FIELD_NULL');
5382                 FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'LPN_ID');
5383                 wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5384                 RAISE FND_API.G_EXC_ERROR;
5385 
5386              ELSIF l_container_info_rec.container_names(1) IS NULL THEN
5387                 FND_MESSAGE.SET_NAME('WSH', 'WSH_REQUIRED_FIELD_NULL');
5388                 FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'CONTAINER_NAME');
5389                 wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5390                 RAISE FND_API.G_EXC_ERROR;
5391 
5392              END IF;
5393 
5394              l_container_rec.weight_uom_code :=
5395                                        l_lpn_table(1).GROSS_WEIGHT_UOM_CODE;
5396              l_container_rec.gross_weight :=
5397                                        l_lpn_table(1).GROSS_WEIGHT;
5398              l_additional_cont_attr.tare_weight :=
5399                                        l_lpn_table(1).TARE_WEIGHT;
5400              l_additional_cont_attr.tare_weight_uom_code :=
5401                                        l_lpn_table(1).TARE_WEIGHT_UOM_CODE;
5402 
5403              l_container_rec.locator_id := l_lpn_table(1).locator_id;
5404              l_container_rec.subinventory := l_lpn_table(1).SUBINVENTORY_CODE;
5405              l_container_rec.volume_uom_code :=
5406                        l_lpn_table(1).CONTAINER_VOLUME_UOM;
5407              l_additional_cont_attr.filled_volume_uom_code :=
5408                        l_lpn_table(1).CONTENT_VOLUME_UOM_CODE;
5409              l_container_rec.filled_volume := l_lpn_table(1).CONTENT_VOLUME;
5410              l_container_rec.volume := l_lpn_table(1).CONTAINER_VOLUME;
5411              l_container_rec.inventory_item_id := l_cont_item_id;
5412              l_container_rec.organization_id := l_organization_id;
5413 
5414              ELSE --}{
5415              /* COMMENT THIS PART ONCE WMS CODE IS AVAILABLE */
5416              wsh_container_actions.Create_Multiple_Cont_name (
5417                   p_cont_name     => p_detail_IN_rec.container_name,
5418                   p_cont_name_pre => NULL,
5419                   p_cont_name_suf => NULL,
5420                   p_cont_name_num => NULL,
5421                   p_cont_name_dig => NULL,
5422                   p_quantity      => p_detail_IN_rec.quantity,
5423                   x_cont_names    => l_container_info_rec.container_names,
5424                   x_return_status => l_return_status
5425              );
5426              wsh_util_core.api_post_call(
5427                  p_return_status => l_return_status,
5428                  x_num_warnings  => l_number_of_warnings,
5429                  x_num_errors    => l_number_of_errors
5430              );
5431              l_container_info_rec.lpn_ids(1) := NULL;
5432              l_container_rec.inventory_item_id := l_cont_item_id;
5433              l_container_rec.organization_id := l_organization_id;
5434              END IF; --}
5435            END IF; --}
5436            wsh_container_actions.default_container_attr(l_container_rec,
5437                                                         l_additional_cont_attr,
5438                                                         p_detail_IN_rec.caller,
5439                                                         l_return_status);
5440            wsh_util_core.api_post_call(
5441                  p_return_status => l_return_status,
5442                  x_num_warnings  => l_number_of_warnings,
5443                  x_num_errors    => l_number_of_errors
5444            );
5445            WSH_DELIVERY_DETAILS_PKG.create_delivery_details_bulk
5446            ( p_delivery_details_info    => l_container_rec,
5447                 p_num_of_rec            => p_detail_IN_rec.quantity,
5448                 p_container_info_rec    => l_container_info_rec,
5449                 x_return_status         => l_return_status,
5450                 x_dd_id_tab             => l_cont_dummy_tab
5451            );
5452 
5453            IF l_return_status IN
5454               (WSH_UTIL_CORE.G_RET_STS_ERROR,
5455                WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR  ) THEN
5456               --
5457               IF l_debug_on THEN
5458                  WSH_DEBUG_SV.logmsg(l_module_name, 'ERROR CREATING CONTAINER');
5459               END IF;
5460               --
5461               FND_MESSAGE.SET_NAME('WSH','WSH_CONT_CREATE_ERROR');
5462               WSH_UTIL_CORE.Add_Message(l_return_status,l_module_name);
5463               RAISE FND_API.G_EXC_ERROR;
5464            END IF;
5465 
5466            IF l_debug_on THEN
5467               WSH_DEBUG_SV.log(l_module_name,'COUNT OF WDD RECORDS',
5468                                                       l_cont_dummy_tab.count);
5469            END IF;
5470 
5471            wsh_util_core.api_post_call(
5472                  p_return_status => l_return_status,
5473                  x_num_warnings  => l_number_of_warnings,
5474                  x_num_errors    => l_number_of_errors
5475            );
5476 
5477            WSH_DELIVERY_DETAILS_PKG.create_deliv_assignment_bulk
5478                ( p_delivery_assignments_info => l_del_assg_rec,
5479                  p_num_of_rec => p_detail_IN_rec.quantity,
5480                  p_dd_id_tab  =>  l_cont_dummy_tab,
5481                  x_da_id_tab => l_assignment_dummy_tab,
5482                  x_return_status => l_return_status
5483            );
5484 
5485            IF l_debug_on THEN
5486               WSH_DEBUG_SV.log(l_module_name,'COUNT OF WDA RECORDS',
5487                                                l_assignment_dummy_tab.count);
5488               WSH_DEBUG_SV.log(l_module_name,'Return Status',l_return_status);
5489            END IF;
5490 
5491            IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,
5492                              WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
5493                 FND_MESSAGE.SET_NAME('WSH','WSH_CONT_CREATE_ERROR');
5494                 WSH_UTIL_CORE.Add_Message(l_return_status,l_module_name);
5495                 RAISE FND_API.G_EXC_ERROR;
5496            END IF;
5497 
5498 
5499            wsh_util_core.api_post_call(
5500                     p_return_status => l_return_status,
5501                     x_num_warnings  => l_number_of_warnings,
5502                     x_num_errors    => l_number_of_errors
5503                 );
5504 
5505         ELSIF l_create_for_wms THEN --}{
5506            -- Create container for WMS callers
5507            i := p_detail_info_tab.FIRST;
5508            WHILE i IS NOT NULL LOOP --{
5509               IF p_detail_info_tab(i).organization_id IS NULL THEN --{
5510                  FND_MESSAGE.SET_NAME('WSH', 'WSH_REQUIRED_FIELD_NULL');
5511                  FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'ORGANIZATION_ID');
5512                  wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5513                  IF l_debug_on THEN
5514                    wsh_debug_sv.log(l_module_name,'ERROR organization id is null for', p_detail_info_tab(i).lpn_id);
5515                  END IF;
5516 
5517                  raise FND_API.G_EXC_ERROR;
5518 
5519               END IF; --}
5520               IF p_detail_info_tab(i).lpn_id IS NULL THEN
5521                  FND_MESSAGE.SET_NAME('WSH', 'WSH_REQUIRED_FIELD_NULL');
5522                  FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'LPN_ID');
5523                  wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5524                  RAISE FND_API.G_EXC_ERROR;
5525 
5526               ELSIF p_detail_info_tab(i).container_name IS NULL THEN
5527                  FND_MESSAGE.SET_NAME('WSH', 'WSH_REQUIRED_FIELD_NULL');
5528                  FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'CONTAINER_NAME');
5529                  wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5530                  RAISE FND_API.G_EXC_ERROR;
5531 
5532               END IF;
5533 
5534               l_container_info_rec.lpn_ids(1) := p_detail_info_tab(i).lpn_id;
5535               l_container_info_rec.container_names(1) := p_detail_info_tab(i).container_name;
5536               l_container_rec := p_detail_info_tab(i);
5537               l_additional_cont_attr.filled_volume_uom_code := p_detail_info_tab(i).volume_uom_code;
5538 
5539               /*IF l_container_rec.organization_id IS NULL THEN
5540 
5541                  IF l_debug_on THEN
5542                     WSH_DEBUG_SV.logmsg(l_module_name,
5543                                           'organization is not passed');
5544                  END IF;
5545                  RAISE FND_API.G_EXC_ERROR;
5546               END IF; */
5547 
5548               wsh_container_actions.default_container_attr(l_container_rec,
5549                                                       l_additional_cont_attr,
5550                                                       p_detail_IN_rec.caller,
5551                                                       l_return_status);
5552               wsh_util_core.api_post_call(
5553                     p_return_status => l_return_status,
5554                     x_num_warnings  => l_number_of_warnings,
5555                     x_num_errors    => l_number_of_errors
5556               );
5557               WSH_DELIVERY_DETAILS_PKG.create_delivery_details_bulk
5558               ( p_delivery_details_info    => l_container_rec,
5559                    p_num_of_rec            => 1,
5560                    p_container_info_rec    => l_container_info_rec,
5561                    x_return_status         => l_return_status,
5562                    x_dd_id_tab             => l_cont_dummy_tab
5563               );
5564 
5565               IF l_return_status IN
5566                  (WSH_UTIL_CORE.G_RET_STS_ERROR,
5567                   WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR  ) THEN
5568                  --
5569                  IF l_debug_on THEN
5570                     WSH_DEBUG_SV.logmsg(l_module_name, 'ERROR CREATING CONTAINER');
5571                  END IF;
5572                  --
5573                  FND_MESSAGE.SET_NAME('WSH','WSH_CONT_CREATE_ERROR');
5574                  WSH_UTIL_CORE.Add_Message(l_return_status,l_module_name);
5575                  RAISE FND_API.G_EXC_ERROR;
5576               END IF;
5577 
5578               IF l_debug_on THEN
5579                  WSH_DEBUG_SV.log(l_module_name,'COUNT OF WDD RECORDS',
5580                                                       l_cont_dummy_tab.count);
5581               END IF;
5582 
5583               wsh_util_core.api_post_call(
5584                     p_return_status => l_return_status,
5585                     x_num_warnings  => l_number_of_warnings,
5586                     x_num_errors    => l_number_of_errors
5587               );
5588 
5589               WSH_DELIVERY_DETAILS_PKG.create_deliv_assignment_bulk
5590                   ( p_delivery_assignments_info => l_del_assg_rec,
5591                     p_num_of_rec => 1,
5592                     p_dd_id_tab  =>  l_cont_dummy_tab,
5593                     x_da_id_tab => l_assignment_dummy_tab,
5594                     x_return_status => l_return_status
5595               );
5596 
5597               IF l_debug_on THEN
5598                  WSH_DEBUG_SV.log(l_module_name,'COUNT OF WDA RECORDS',
5599                                                   l_assignment_dummy_tab.count);
5600                  WSH_DEBUG_SV.log(l_module_name,'Return Status',l_return_status);
5601               END IF;
5602 
5603               IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,
5604                              WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
5605                    FND_MESSAGE.SET_NAME('WSH','WSH_CONT_CREATE_ERROR');
5606                    WSH_UTIL_CORE.Add_Message(l_return_status,l_module_name);
5607                    RAISE FND_API.G_EXC_ERROR;
5608               END IF;
5609               --
5610               wsh_util_core.api_post_call(
5611                     p_return_status => l_return_status,
5612                     x_num_warnings  => l_number_of_warnings,
5613                     x_num_errors    => l_number_of_errors
5614               );
5615 
5616               i:= p_detail_info_tab.NEXT(i);
5617 
5618            END LOOP; --}
5619         END IF; --}
5620 
5621 
5622         x_container_ids       := l_cont_dummy_tab;
5623 
5624         IF l_number_of_errors > 0
5625         THEN
5626             x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
5627         ELSIF l_number_of_warnings > 0
5628         THEN
5629             x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
5630         ELSE
5631             x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
5632         END IF;
5633 
5634         IF l_debug_on THEN
5635             WSH_DEBUG_SV.pop(l_module_name);
5636         END IF;
5637 
5638     EXCEPTION
5639         WHEN e_NO_INV_ITEM then
5640            WSH_WMS_LPN_GRP.g_call_group_api := l_orig_value;
5641            WSH_WMS_LPN_GRP.g_update_to_container := l_update_container_orig;
5642 
5643            rollback to s_create_containers_DDGPB;
5644            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
5645            IF l_debug_on THEN
5646               WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:e_NO_INV_ITEM');
5647            END IF;
5648         WHEN e_lpn_count_invalid then
5649            WSH_WMS_LPN_GRP.g_call_group_api := l_orig_value;
5650            WSH_WMS_LPN_GRP.g_update_to_container := l_update_container_orig;
5651 
5652            rollback to s_create_containers_DDGPB;
5653            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
5654            fnd_message.set_name('WSH', 'WSH_LPN_COUNT_INVALID');
5655            WSH_UTIL_CORE.ADD_MESSAGE(x_return_status);
5656            IF l_debug_on THEN
5657                WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:e_lpn_count_invalid');
5658            END IF;
5659            --
5660 
5661         WHEN FND_API.G_EXC_ERROR THEN
5662                 WSH_WMS_LPN_GRP.g_call_group_api := l_orig_value;
5663                 WSH_WMS_LPN_GRP.g_update_to_container := l_update_container_orig;
5664 
5665                 rollback to s_create_containers_DDGPB;
5666                 x_return_status := FND_API.G_RET_STS_ERROR ;
5667                 IF l_debug_on THEN
5668                    WSH_DEBUG_SV.logmsg(l_module_name,
5669                     'FND_API.G_EXC_ERROR exception has occured.',
5670                      WSH_DEBUG_SV.C_EXCEP_LEVEL);
5671                      WSH_DEBUG_SV.pop(l_module_name,
5672                                      'EXCEPTION:FND_API.G_EXC_ERROR');
5673                 END IF;
5674                 --
5675         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5676                 WSH_WMS_LPN_GRP.g_call_group_api := l_orig_value;
5677                 rollback to s_create_containers_DDGPB;
5678                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
5679 
5680                 IF l_debug_on THEN
5681                     WSH_DEBUG_SV.logmsg(l_module_name
5682                       ,'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.'
5683                       ,WSH_DEBUG_SV.C_EXCEP_LEVEL);
5684                     WSH_DEBUG_SV.pop(l_module_name
5685                        ,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
5686                 END IF;
5687                   --
5688         WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
5689                 WSH_WMS_LPN_GRP.g_call_group_api := l_orig_value;
5690                 WSH_WMS_LPN_GRP.g_update_to_container := l_update_container_orig;
5691 
5692              x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
5693              IF l_debug_on THEN
5694                  WSH_DEBUG_SV.logmsg(l_module_name
5695                    ,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured '
5696                    ,WSH_DEBUG_SV.C_EXCEP_LEVEL);
5697                 WSH_DEBUG_SV.pop(l_module_name
5698                    ,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
5699             END IF;
5700         WHEN OTHERS THEN
5701             WSH_WMS_LPN_GRP.g_call_group_api := l_orig_value;
5702             rollback to s_create_containers_DDGPB;
5703             x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
5704             wsh_util_core.add_message(x_return_status, l_module_name);
5705             WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Create_containers');
5706             IF l_debug_on THEN
5707               WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
5708               WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
5709             END IF;
5710 
5711     END Create_containers;
5712 
5713     -- ---------------------------------------------------------------------
5714     -- Procedure: Create_Delivery_Detail
5715     --
5716     -- Parameters:
5717     --
5718     -- Description:  This local procedure is the new API for wrapping the logic of CREATE of delivery details
5719     -- Created:   Harmonization Project. Patchset I
5720     -- -----------------------------------------------------------------------
5721 
5722     PROCEDURE  Create_Delivery_Detail(
5723                 p_detail_info_tab     IN WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type ,
5724                 p_detail_IN_rec       IN  WSH_GLBL_VAR_STRCT_GRP.detailInRecType,
5725                 p_valid_index_tab     IN  wsh_util_core.id_tab_type,
5726                 x_detail_OUT_rec      OUT NOCOPY WSH_GLBL_VAR_STRCT_GRP.detailOutRecType,
5727                 x_return_status       OUT NOCOPY  varchar2,
5728                 x_msg_count           OUT NOCOPY      NUMBER,
5729                 x_msg_data            OUT NOCOPY      VARCHAR2)
5730   IS
5731 
5732   l_api_name              	CONSTANT VARCHAR2(30)   := 'Create_Delivery_Detail';
5733   l_api_version           	CONSTANT NUMBER         := 1.0;
5734   l_init_msg_list         	VARCHAR2(100);
5735   l_commit                	VARCHAR2(100);
5736 
5737   --
5738   l_return_status             	VARCHAR2(32767);
5739   l_msg_count                 	NUMBER;
5740   l_msg_data                  	VARCHAR2(32767);
5741   l_program_name              	VARCHAR2(32767);
5742 
5743   l_number_of_errors    	NUMBER := 0;
5744   l_number_of_warnings  	NUMBER := 0;
5745   --
5746   l_index                  	NUMBER;
5747   l_new_detail_id          	NUMBER;
5748   l_dummy_rowid            	VARCHAR2(32767);
5749   l_dummy_assgn_rowid      	VARCHAR2(32767);
5750   l_delivery_assignment_id 	NUMBER;
5751   l_delivery_assignments_info   WSH_DELIVERY_DETAILS_PKG.Delivery_Assignments_Rec_Type;
5752   l_item_type              	VARCHAR2(30);
5753 
5754   l_validation_level       	NUMBER;
5755 
5756   --OTM R12
5757   l_delivery_detail_tab		WSH_ENTITY_INFO_TAB;
5758   l_delivery_detail_rec		WSH_ENTITY_INFO_REC;
5759   l_item_quantity_uom_tab	WSH_UTIL_CORE.COLUMN_TAB_TYPE;
5760   l_gc3_is_installed            VARCHAR2(1);
5761   l_counter                     NUMBER;
5762   --
5763 
5764   --
5765   l_debug_on BOOLEAN;
5766   --
5767   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CREATE_DELIVERY_DETAIL';
5768 
5769     --
5770     BEGIN
5771         --
5772         l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
5773         --
5774         IF l_debug_on IS NULL
5775         THEN
5776             l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
5777         END IF;
5778         --
5779         SAVEPOINT CREATE_DEL_DETAIL_GRP;
5780 
5781         IF l_debug_on THEN
5782             WSH_DEBUG_SV.push(l_module_name);
5783             WSH_DEBUG_SV.log(l_module_name, 'container_item_id',p_detail_IN_rec.container_item_id);
5784             WSH_DEBUG_SV.log(l_module_name, 'container_item_name',p_detail_IN_rec.container_item_name);
5785             WSH_DEBUG_SV.log(l_module_name, 'organization_id', p_detail_IN_rec.organization_id);
5786             WSH_DEBUG_SV.log(l_module_name, 'organization_code',p_detail_IN_rec.organization_code);
5787             WSH_DEBUG_SV.log(l_module_name, 'name_prefix', p_detail_IN_rec.name_prefix);
5788             WSH_DEBUG_SV.log(l_module_name, 'name_suffix', p_detail_IN_rec.name_suffix);
5789             WSH_DEBUG_SV.log(l_module_name, 'base number', p_detail_IN_rec.base_number);
5790             WSH_DEBUG_SV.log(l_module_name, 'Num Digits', p_detail_IN_rec.num_digits);
5791             WSH_DEBUG_SV.log(l_module_name, 'Quantity', p_detail_IN_rec.quantity);
5792             WSH_DEBUG_SV.log(l_module_name, 'Container Name', p_detail_IN_rec.container_name);
5793             WSH_DEBUG_SV.log(l_module_name, 'Lpn Ids Count', p_detail_In_rec.lpn_ids.count);
5794             WSH_DEBUG_SV.log(l_module_name, 'Caller', p_detail_in_rec.caller);
5795         END IF;
5796         --
5797 
5798         --  Initialize API return status to success
5799         x_return_status       := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
5800         l_number_of_errors := 0;
5801         l_number_of_warnings := 0;
5802 
5803 	--OTM R12 initialize
5804         l_gc3_is_installed := WSH_UTIL_CORE.G_GC3_IS_INSTALLED;
5805 
5806         IF (l_gc3_is_installed IS NULL) THEN
5807           l_gc3_is_installed := WSH_UTIL_CORE.GC3_IS_INSTALLED;
5808         END IF;
5809 
5810         IF (l_gc3_is_installed = 'Y') THEN
5811           l_delivery_detail_tab := WSH_ENTITY_INFO_TAB();
5812         END IF;
5813         l_counter := 1;
5814 	--
5815 
5816          l_index := p_valid_index_tab.FIRST;
5817 
5818          IF(l_index IS NULL) OR nvl(WSH_WMS_LPN_GRP.g_caller,'WSH') like 'WMS%' THEN --{
5819 
5820             -- logic for creating containers
5821              IF nvl(WSH_WMS_LPN_GRP.g_caller,'WSH') NOT LIKE 'WMS%' THEN --{
5822                 IF( p_detail_IN_rec.organization_id IS NULL and p_detail_IN_rec.organization_code IS NULL) THEN
5823                     FND_MESSAGE.SET_NAME('WSH', 'WSH_CONT_ORG_NULL');
5824                     wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5825                     IF l_debug_on THEN
5826                        wsh_debug_sv.logmsg(l_module_name,'Null Organization');
5827                     END IF;
5828                     raise FND_API.G_EXC_ERROR;
5829                 ELSIF(p_detail_IN_rec.container_item_id IS NULL
5830                    AND p_detail_IN_rec.container_item_name IS NULL
5831                    AND p_detail_IN_rec.container_item_seg.count = 0) THEN
5832                    FND_MESSAGE.SET_NAME('WSH', 'WSH_REQUIRED_FIELD_NULL');
5833                    FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'CONTAINER_ITEM');
5834                    wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5835                      IF l_debug_on THEN
5836                        wsh_debug_sv.logmsg(l_module_name,'Null Container item');
5837                      END IF;
5838 
5839                      raise FND_API.G_EXC_ERROR;
5840 
5841                 END IF;
5842              END IF; --}
5843 
5844             Create_containers(
5845                 p_detail_info_tab  => p_detail_info_tab,
5846                 p_detail_IN_rec  => p_detail_IN_rec,
5847                 x_container_ids  => x_detail_out_rec.detail_ids,
5848                 x_return_status => l_return_status
5849             );
5850             wsh_util_core.api_post_call(
5851                       p_return_status => l_return_status,
5852                       x_num_warnings  => l_number_of_warnings,
5853                       x_num_errors    => l_number_of_errors
5854             );
5855          ELSE --}{
5856             WHILE  l_index IS NOT NULL
5857             LOOP --{
5858                --
5859                IF(p_detail_info_tab(l_index).container_flag in ('Y', 'C')) THEN
5860                   IF l_debug_on THEN
5861                      wsh_debug_sv.logmsg(l_module_name,'Container Flag Yes ');
5862                   END IF;
5863                   RAISE FND_API.G_EXC_ERROR;
5864                END IF;
5865 
5866                IF  p_detail_info_tab(l_index).inventory_item_id  IS NOT NULL THEN --{
5867                    -- Validate Item and see if this is container item
5868                     -- Error out if this is a container item
5869 
5870                   IF l_debug_on THEN
5871                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_VALIDATE.FIND_ITEM_TYPE',WSH_DEBUG_SV.C_PROC_LEVEL);
5872                   END IF;
5873 
5874                   WSH_UTIL_VALIDATE.Find_Item_Type
5875                    (
5876                      p_inventory_item_id => p_detail_info_tab(l_index).inventory_item_id,
5877                      p_organization_id   => p_detail_info_tab(l_index).organization_id,
5878                      x_item_type         => l_item_type,
5879                      x_return_status     => l_return_status
5880                    );
5881 
5882                   IF l_debug_on THEN
5883                      wsh_debug_sv.log(l_module_name, 'Item Type', l_item_type);
5884                   END IF;
5885                   --
5886                   wsh_util_core.api_post_call(
5887                          p_return_status => l_return_status,
5888                          x_num_warnings  => l_number_of_warnings,
5889                          x_num_errors    => l_number_of_errors,
5890                          p_msg_data      => l_msg_data
5891                          );
5892 
5893                   IF(nvl(l_item_type, 'FND_API.G_MISS_CHAR') = 'CONT_ITEM') THEN
5894                       IF l_debug_on THEN
5895                          wsh_debug_sv.logmsg(l_module_name,'Container Item');
5896                       END IF;
5897                      RAISE FND_API.G_EXC_ERROR;
5898                    END IF;
5899                 END IF; --}
5900 
5901 
5902                 IF l_debug_on THEN
5903                    WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_PKG.CREATE_DELIVERY_DETAILS',WSH_DEBUG_SV.C_PROC_LEVEL);
5904                 END IF;
5905                 --
5906                 WSH_DELIVERY_DETAILS_PKG.create_delivery_details(
5907                  p_delivery_details_info  =>   p_detail_info_tab(l_index),
5908                  x_rowid                =>   l_dummy_rowid,
5909                  x_delivery_detail_id     =>   l_new_detail_id,
5910                  x_return_status          =>   l_return_status);
5911 
5912                 IF l_debug_on THEN
5913                    wsh_debug_sv.log(l_module_name, 'New Detail Created', l_new_detail_id);
5914                 END IF;
5915 
5916                 --
5917                 wsh_util_core.api_post_call(
5918                       p_return_status => l_return_status,
5919                       x_num_warnings  => l_number_of_warnings,
5920                       x_num_errors    => l_number_of_errors,
5921                       p_msg_data      => l_msg_data,
5922                       p_raise_error_flag  => FALSE
5923                       );
5924                 --
5925                 IF l_return_status <> wsh_util_core.g_ret_sts_success THEN
5926                    FND_MESSAGE.SET_NAME('WSH', 'WSH_DET_CREATE_DET_FAILED');
5927                    wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5928                    RAISE FND_API.G_EXC_ERROR;
5929                 END IF;
5930                 l_delivery_assignments_info.delivery_id               := NULL;
5931                 l_delivery_assignments_info.parent_delivery_id        := NULL;
5932                 l_delivery_assignments_info.delivery_detail_id        := l_new_detail_id;
5933                 l_delivery_assignments_info.parent_delivery_detail_id := NULL;
5934 
5935 
5936                 IF l_debug_on THEN
5937                     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_PKG.CREATE_DELIVERY_ASSIGNMENTS',WSH_DEBUG_SV.C_PROC_LEVEL);
5938                 END IF;
5939                 --
5940                 WSH_DELIVERY_DETAILS_PKG.Create_Delivery_Assignments(
5941                   p_delivery_assignments_info    =>   l_delivery_assignments_info,
5942                   x_rowid                        =>   l_dummy_assgn_rowid,
5943                   x_delivery_assignment_id       =>   l_delivery_assignment_id,
5944                   x_return_status                =>   l_return_status);
5945 
5946                   x_detail_out_Rec.detail_ids(l_index) := l_new_detail_id;
5947 
5948                 wsh_util_core.api_post_call(
5949                       p_return_status => l_return_status,
5950                       x_num_warnings  => l_number_of_warnings,
5951                       x_num_errors    => l_number_of_errors,
5952                       p_msg_data      => l_msg_data,
5953                       p_raise_error_flag  => FALSE
5954                       );
5955 
5956                 IF l_return_status <> wsh_util_core.g_ret_sts_success THEN
5957                    FND_MESSAGE.SET_NAME('WSH', 'WSH_DET_CREATE_AS_FAILED');
5958                    wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
5959                    RAISE FND_API.G_EXC_ERROR;
5960                 END IF;
5961 
5962 		--OTM R12, calling delivery detail splitter
5963 		IF (l_gc3_is_installed = 'Y') THEN
5964 
5965                   IF l_debug_on THEN
5966                     WSH_DEBUG_SV.log(l_module_name,'Delivery detail number',l_index);
5967                     WSH_DEBUG_SV.log(l_module_name,'Delivery detail count',l_counter);
5968                     WSH_DEBUG_SV.log(l_module_name,'delivery detail id',l_new_detail_id);
5969                     WSH_DEBUG_SV.log(l_module_name,'inventory item id',p_detail_info_tab(l_index).inventory_item_id);
5970                     WSH_DEBUG_SV.log(l_module_name,'net weight',p_detail_info_tab(l_index).net_weight);
5971                     WSH_DEBUG_SV.log(l_module_name,'organization id',p_detail_info_tab(l_index).organization_id);
5972                     WSH_DEBUG_SV.log(l_module_name,'weight uom code',p_detail_info_tab(l_index).weight_uom_code);
5973                     WSH_DEBUG_SV.log(l_module_name,'requested quantity',p_detail_info_tab(l_index).requested_quantity);
5974                     WSH_DEBUG_SV.log(l_module_name,'ship from location id',p_detail_info_tab(l_index).ship_from_location_id);
5975                     WSH_DEBUG_SV.log(l_module_name,'requested quantity uom',p_detail_info_tab(l_index).requested_quantity_uom);
5976                   END IF;
5977 
5978                   --prepare table of delivery detail information to call splitter
5979 		  l_delivery_detail_tab.EXTEND;
5980 		  l_delivery_detail_tab(l_counter) := WSH_ENTITY_INFO_REC(l_new_detail_id,
5981 					NULL,
5982 				     	p_detail_info_tab(l_index).inventory_item_id,
5983 				     	p_detail_info_tab(l_index).net_weight,
5984 					0,
5985 					p_detail_info_tab(l_index).organization_id,
5986 					p_detail_info_tab(l_index).weight_uom_code,
5987 					p_detail_info_tab(l_index).requested_quantity,
5988 					p_detail_info_tab(l_index).ship_from_location_id,
5989 					NULL);
5990 	          l_item_quantity_uom_tab(l_counter)   := p_detail_info_tab(l_index).requested_quantity_uom;
5991                   l_counter := l_counter + 1;
5992 		END IF;
5993 		--END OTM R12
5994 
5995                 l_index := p_valid_index_tab.NEXT(l_index);
5996                 --
5997              END LOOP; -- while l_index is not null }
5998 
5999              --OTM R12, after loop call split with all the data
6000              IF (l_counter > 1) THEN
6001 
6002                IF l_debug_on THEN
6003                  WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_SPLITTER.tms_delivery_detail_split',WSH_DEBUG_SV.C_PROC_LEVEL);
6004                END IF;
6005 
6006                WSH_DELIVERY_DETAILS_SPLITTER.tms_delivery_detail_split(
6007                  p_detail_tab => l_delivery_detail_tab,
6008                  p_item_quantity_uom_tab => l_item_quantity_uom_tab,
6009                  x_return_status => l_return_status);
6010 
6011                IF l_debug_on THEN
6012                  WSH_DEBUG_SV.logmsg(l_module_name, 'return status from WSH_DELIVERY_DETAILS_SPLITTER.tms_delivery_detail_split: ' || l_return_status);
6013                END IF;
6014 
6015                -- we will not fail based on l_return_status here because
6016                -- we do not want to stop the flow
6017                -- if the detail doesn't split, it will be caught later in
6018                -- delivery splitting and will have exception on the detail
6019                IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
6020                  IF l_debug_on THEN
6021                    WSH_DEBUG_SV.logmsg(l_module_name, 'Delivery detail split failed for ' || l_new_detail_id );
6022                  END IF;
6023                END IF;
6024              END IF;
6025              --END OTM R12
6026           END IF; --}
6027        FND_MSG_PUB.Count_And_Get
6028          (
6029           p_count  => x_msg_count,
6030           p_data  =>  x_msg_data,
6031           p_encoded => FND_API.G_FALSE
6032          );
6033 
6034     -- Debug Statements
6035     --
6036     IF l_debug_on THEN
6037         WSH_DEBUG_SV.pop(l_module_name);
6038     END IF;
6039     --
6040     EXCEPTION
6041         WHEN FND_API.G_EXC_ERROR THEN
6042                 ROLLBACK to CREATE_DEL_DETAIL_GRP;
6043                 x_return_status := FND_API.G_RET_STS_ERROR ;
6044                 FND_MSG_PUB.Count_And_Get
6045                   (
6046                      p_count  => x_msg_count,
6047                      p_data  =>  x_msg_data,
6048                p_encoded => FND_API.G_FALSE
6049                   );
6050 
6051                   IF l_debug_on THEN
6052                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
6053                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_ERROR');
6054                   END IF;
6055                   --
6056         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6057                 ROLLBACK to CREATE_DEL_DETAIL_GRP;
6058                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6059                 FND_MSG_PUB.Count_And_Get
6060                   (
6061                      p_count  => x_msg_count,
6062                      p_data  =>  x_msg_data,
6063                p_encoded => FND_API.G_FALSE
6064                   );
6065 
6066                   IF l_debug_on THEN
6067                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
6068                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
6069                   END IF;
6070                   --
6071         WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
6072              x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
6073              FND_MSG_PUB.Count_And_Get
6074               (
6075                 p_count  => x_msg_count,
6076                 p_data  =>  x_msg_data,
6077                 p_encoded => FND_API.G_FALSE
6078               );
6079         --
6080         IF l_debug_on THEN
6081             WSH_DEBUG_SV.logmsg(l_module_name,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ',WSH_DEBUG_SV.C_EXCEP_LEVEL);
6082            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
6083        END IF;
6084 --
6085         WHEN OTHERS THEN
6086 
6087                 ROLLBACK to CREATE_DEL_DETAIL_GRP;
6088                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6089                wsh_util_core.add_message(x_return_status, l_module_name);
6090                WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Create_Delivery_Detail');
6091                 FND_MSG_PUB.Count_And_Get
6092                   (
6093                      p_count  => x_msg_count,
6094                      p_data  =>  x_msg_data,
6095                p_encoded => FND_API.G_FALSE
6096                   );
6097 
6098               IF l_debug_on THEN
6099                   WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
6100                   WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
6101               END IF;
6102 --
6103     END Create_Delivery_Detail;
6104 
6105 -- anxsharm for Load Tender
6106 -- added a new out parameter x_detail_tender_tab
6107 -- This table of id will have the delivery detail ids
6108 -- for which the weight or volume or delivery or parent_detail
6109 -- or picked/shipped quantity have changed.
6110     -- ---------------------------------------------------------------------
6111     -- Procedure: Validate_Delivery_Detail
6112     --
6113     -- Parameters:
6114     --
6115     -- Description:  This local procedure is the new API for wrapping the logic of VALIDATE of delivery details
6116     -- Created:   Harmonization Project. Patchset I
6117     -- -----------------------------------------------------------------------
6118 
6119     -- frontport bug 5055682
6120     -- ---------------------------------------------------------------------
6121     -- Behavior for Serial Numbers :
6122     -- 1) If single serial number is passed as part of p_in_detail_rec, then
6123     --    serial number will be stamped on wdd table.
6124     -- 2) If single/multiple serial number(s) is passed as p_serial_range_tab,
6125     --    then serial number(s) will be inserted into msnt table and
6126     --    transaction_temp_id will be stamped on wdd table.
6127     -- 3) If multiple serial numbers are passed as part of p_in_detail_rec,
6128     --    then serial numbers will be inserted into msnt table and
6129     --    transaction_temp_id will be stamped on wdd table.
6130     -- -----------------------------------------------------------------------
6131 
6132     PROCEDURE  Validate_Delivery_Detail(
6133                 x_detail_info_tab  IN  OUT NOCOPY  WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type,
6134                 p_in_detail_tab    IN   WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type,
6135                 p_action           IN  VARCHAR2,
6136                 p_validation_tab   IN  wsh_util_core.id_tab_type,
6137                 p_caller           IN  VARCHAR2,
6138                 x_valid_index_tab  OUT  NOCOPY WSH_UTIL_CORE.Id_Tab_Type,
6139                 x_details_marked   OUT NOCOPY WSH_UTIL_CORE.Id_Tab_Type,
6140                 x_detail_tender_tab OUT NOCOPY wsh_util_core.id_tab_type,
6141                 x_return_status    OUT NOCOPY VARCHAR2,
6142                 x_msg_count        OUT NOCOPY      NUMBER,
6143                 x_msg_data         OUT NOCOPY      VARCHAR2,
6144                 p_in_rec           IN  WSH_GLBL_VAR_STRCT_GRP.detailInRecType,
6145                 p_serial_range_tab IN  WSH_GLBL_VAR_STRCT_GRP.ddSerialRangeTabType
6146                ) IS
6147 
6148 
6149         l_api_name              CONSTANT VARCHAR2(30)   := 'Validate_Delivery_Detail';
6150         l_api_version           CONSTANT NUMBER         := 1.0;
6151         l_init_msg_list         VARCHAR2(32767);
6152         l_commit                VARCHAR2(32767);
6153         --
6154   --
6155   l_return_status             VARCHAR2(32767);
6156   l_msg_count                 NUMBER;
6157   l_msg_data                  VARCHAR2(32767);
6158   l_program_name              VARCHAR2(32767);
6159         --
6160   l_number_of_errors    NUMBER := 0;
6161   l_number_of_warnings  NUMBER := 0;
6162   --
6163 
6164         l_index                  NUMBER;
6165         l_new_detail_id          NUMBER;
6166         l_dummy_rowid            NUMBER;
6167         l_dummy_assgn_rowid      NUMBER;
6168         l_delivery_assignment_id NUMBER;
6169         l_delivery_assignments_info     WSH_DELIVERY_DETAILS_PKG.Delivery_Assignments_Rec_Type;
6170         l_required_field        VARCHAR2(32767);
6171 
6172         l_validation_level       NUMBER;
6173         l_org_id               NUMBER;
6174         l_isWshLocation         BOOLEAN DEFAULT FALSE;
6175 
6176         /* H projects: pricing integration csun */
6177         l_mark_reprice_flag            VARCHAR2(1) := 'N';
6178         m NUMBER := 0;
6179         l_details_marked        WSH_UTIL_CORE.Id_Tab_Type;
6180         mark_reprice_error  EXCEPTION;
6181 
6182         l_original_detail_rec c_original_detail_cur%ROWTYPE;
6183   --
6184 l_debug_on BOOLEAN;
6185   --
6186   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'VALIDATE_DELIVERY_DETAIL';
6187   -- OPM Bug 3055126
6188   l_check_status         NUMBER;
6189   --
6190 
6191     --
6192     uom_conversion_failed       EXCEPTION;
6193     e_required_field_null       EXCEPTION;
6194     e_ib_create_error           EXCEPTION;
6195     -- PK Bug 3055126 OPM Exceptions
6196 -- HW OPMCONV - Removed OPM variables
6197 
6198 -- anxsharm for Load Tender
6199 -- remove this cursor not being used
6200 
6201     CURSOR c_original_line(p_counter NUMBER)
6202     IS
6203     SELECT source_line_id,
6204            organization_id,
6205            inventory_item_id,
6206            serial_number,
6207            transaction_temp_id,
6208            locator_id,
6209            revision,
6210            subinventory,
6211            lot_number,
6212            released_status,
6213            requested_quantity_uom
6214     FROM wsh_delivery_details
6215     WHERE delivery_detail_id = x_detail_info_tab(p_counter).delivery_detail_id;
6216     -- AND source_code = p_source_code;
6217 
6218     l_old_delivery_detail_rec c_original_line%ROWTYPE;
6219 
6220     CURSOR c_inventory_item_info(p_inventory_item_id number, p_organization_id number) is
6221     SELECT  primary_uom_code,
6222     description,
6223     hazard_class_id,
6224     weight_uom_code,
6225     unit_weight,
6226     volume_uom_code,
6227     unit_volume
6228      FROM mtl_system_items
6229      WHERE inventory_item_id = p_inventory_item_id
6230      AND   organization_id  = p_organization_id;
6231 
6232      l_inventory_item_info c_inventory_item_info%ROWTYPE;
6233 
6234 	 --Bug 12850936: Cursor to determine weight/volume in case
6235      --where shipped quantity is zero
6236      CURSOR Item_Net_Wt_Vol(c_delivery_detail_id NUMBER,
6237                             c_shipped_quantity   NUMBER) IS
6238      SELECT wsh_wv_utils.convert_uom (msi.weight_uom_code,
6239                          wdd.weight_uom_code,
6240                         (NVL(wdd.unit_weight, msi.unit_weight) *
6241                            wsh_wv_utils.convert_uom (wdd.requested_quantity_uom,
6242                                         msi.primary_uom_code,
6243                                         nvl(c_shipped_quantity,
6244                                           NVL(wdd.picked_quantity,
6245                                             wdd.requested_quantity)),
6246                                         wdd.inventory_item_id) ),
6247                          wdd.inventory_item_id ) weight,
6248             wsh_wv_utils.convert_uom (msi.volume_uom_code,
6249                          wdd.volume_uom_code,
6250                         (NVL(wdd.unit_volume, msi.unit_volume) *
6251                            wsh_wv_utils.convert_uom (wdd.requested_quantity_uom,
6252                                         msi.primary_uom_code,
6253                                         nvl(c_shipped_quantity,
6254                                           NVL(wdd.picked_quantity,
6255                                             wdd.requested_quantity)),
6256                                         wdd.inventory_item_id) ),
6257                          wdd.inventory_item_id ) volume
6258      FROM   wsh_delivery_details wdd,
6259             mtl_system_items     msi
6260      WHERE  wdd.delivery_detail_id = c_delivery_detail_id
6261      AND    msi.inventory_item_id  = wdd.inventory_item_id
6262      AND    msi.organization_id    = wdd.organization_id;
6263 
6264 -- anxsharm for Load tender
6265      l_old_table wsh_interface.deliverydetailtab;
6266      l_new_table wsh_interface.deliverydetailtab;
6267      l_count_old NUMBER;
6268      l_count_new NUMBER;
6269      l_fte_installed VARCHAR2(1);
6270 
6271     BEGIN
6272         --
6273         l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
6274         --
6275         IF l_debug_on IS NULL
6276         THEN
6277             l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
6278         END IF;
6279         --
6280         SAVEPOINT VALIDATE_DEL_DETAIL_GRP;
6281 
6282         IF l_debug_on THEN
6283             WSH_DEBUG_SV.push(l_module_name);
6284             --
6285             WSH_DEBUG_SV.log(l_module_name,'P_ACTION',P_ACTION);
6286             WSH_DEBUG_SV.log(l_module_name,'p_caller',p_caller);
6287         END IF;
6288         --
6289         --  Initialize API return status to success
6290   x_return_status       := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
6291   l_number_of_errors := 0;
6292   l_number_of_warnings := 0;
6293 
6294         IF p_caller IN ( 'WSH_FSTRX' , 'WSH_TPW_INBOUND')
6295           OR p_caller LIKE 'FTE%' THEN
6296             l_isWshLocation := TRUE;
6297         END IF;
6298 
6299         l_index := x_detail_info_tab.FIRST;
6300 
6301         IF wsh_util_core.fte_is_installed = 'Y' THEN
6302           l_fte_installed := 'Y';
6303         END IF;
6304 
6305         --
6306         WHILE l_index IS NOT NULL
6307         LOOP
6308            --
6309            BEGIN
6310              SAVEPOINT validate_det_loop_grp;
6311              --
6312              IF l_debug_on THEN
6313                 wsh_debug_sv.log(l_module_name, 'Index', l_index);
6314              END IF;
6315              IF(p_action = 'CREATE') THEN
6316                       --
6317                       -- J-IB-NPARIKH-{
6318                       --
6319                       IF NVL(x_detail_info_tab(l_index).line_direction,'O') NOT IN ('O','IO')
6320                       THEN
6321                         --
6322                         -- Cannot create inbound lines through group APIs
6323                         --
6324                         RAISE e_ib_create_error;
6325                       END IF;
6326                       --
6327                       -- J-IB-NPARIKH-}
6328                       --
6329                       IF (x_detail_info_tab(l_index).source_code is NULL) THEN
6330                           l_required_field := 'SOURCE_CODE';
6331                     RAISE e_required_field_null;
6332                       ELSIF (x_detail_info_tab(l_index).source_header_id is NULL) THEN
6333                           l_required_field := 'SOURCE_HEADER_ID';
6334                     RAISE e_required_field_null;
6335                       ELSIF (x_detail_info_tab(l_index).source_line_id is NULL) THEN
6336                           l_required_field := 'SOURCE_LINE_ID';
6337                     RAISE e_required_field_null;
6338                       ELSIF (x_detail_info_tab(l_index).src_requested_quantity is NULL) THEN
6339                           l_required_field := 'SRC_REQ_QTY';
6340                     RAISE e_required_field_null;
6341                       ELSIF (x_detail_info_tab(l_index).src_requested_quantity_uom is NULL) THEN
6342                           l_required_field := 'SRC_REQ_QTY_UOM';
6343                     RAISE e_required_field_null;
6344 
6345                      /* if item is not setup in the inventory system yet.
6346                     The required fields
6347                           Item_Description,
6348                            Weight_UOM_Code,
6349                            Volume_UOM_Code,
6350                           Net_Weight,
6351                            Volume */
6352                       --
6353                       ELSIF (x_detail_info_tab(l_index).inventory_item_id is NULL) THEN
6354 
6355                           if (x_detail_info_tab(l_index).item_description is NULL) THEN
6356                             l_required_field := 'ITEM';
6357                             raise e_required_field_null;
6358                     end if;
6359 
6360               /* you need to either have inventory_item_id or item_description */
6361                   if (x_detail_info_tab(l_index).item_description is not NULL) then
6362 
6363             -- bug 2398865
6364                     IF ( nvl(x_detail_info_tab(l_index).requested_quantity,fnd_api.g_miss_num) = fnd_api.g_miss_num ) THEN
6365                    x_detail_info_tab(l_index).requested_quantity_uom := x_detail_info_tab(l_index).src_requested_quantity_uom;
6366                  x_detail_info_tab(l_index).requested_quantity := x_detail_info_tab(l_index).src_requested_quantity;
6367                 END IF;
6368             -- bug 2398865
6369                if (x_detail_info_tab(l_index).weight_uom_code is NULL) THEN
6370                                      l_required_field := 'WEIGHT_UOM';
6371              raise e_required_field_null;
6372                     end if;
6373 
6374               if (x_detail_info_tab(l_index).volume_uom_code is NULL) THEN
6375                                      l_required_field := 'VOLUME_UOM';
6376              raise e_required_field_null;
6377                   end if;
6378 
6379               if (x_detail_info_tab(l_index).net_weight is NULL) THEN
6380                                         l_required_field := 'NET_WEIGHT';
6381                 raise e_required_field_null;
6382                     end if;
6383 
6384               if (x_detail_info_tab(l_index).volume is NULL) THEN
6385                                         l_required_field := 'VOLUME';
6386                 raise e_required_field_null;
6387               end if;
6388 
6389               end if; -- if item_description is not null
6390 
6391                          /* Bug 2177410, skip inventory interface for non-item */
6392                          x_detail_info_tab(l_index).inv_interfaced_flag := 'X';
6393                       --
6394                      ELSIF (x_detail_info_tab(l_index).organization_id is NULL) THEN
6395                         l_required_field := 'ORGANIZATION_ID';
6396             raise e_required_field_null;
6397                      ELSIF (x_detail_info_tab(l_index).source_header_number is NULL) THEN
6398                         l_required_field := 'SOURCE_HEADER_NUMBER';
6399             raise e_required_field_null;
6400                      ELSIF (x_detail_info_tab(l_index).org_id is NULL) THEN
6401                         l_required_field := 'ORG_ID';
6402             raise e_required_field_null;
6403                      ELSIF (x_detail_info_tab(l_index).source_line_number is NULL) THEN
6404                         l_required_field := 'SOURCE_LINE_NUMBER';
6405             raise e_required_field_null;
6406                      END IF;
6407 
6408                      IF x_detail_info_tab(l_index).ship_from_location_id is NULL THEN
6409                           l_required_field := 'SHIP_FROM_LOCATION_ID';
6410                           raise e_required_field_null;
6411                      ELSE
6412                            IF l_debug_on THEN
6413                               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_LOCATION',WSH_DEBUG_SV.C_PROC_LEVEL);
6414                            END IF;
6415                           wsh_util_validate.validate_location(
6416                               p_location_id   => x_detail_info_tab(l_index).ship_from_location_id,
6417                               x_return_status => l_return_status,
6418                               p_isWshLocation => l_isWshLocation);
6419 
6420                        wsh_util_core.api_post_call(
6421                            p_return_status => l_return_status,
6422                            x_num_warnings  => l_number_of_warnings,
6423                            x_num_errors    => l_number_of_errors,
6424                            p_msg_data      => l_msg_data
6425                            );
6426                      END IF;
6427 
6428                      IF x_detail_info_tab(l_index).ship_to_location_id is NULL THEN
6429                             l_required_field := 'SHIP_TO_LOCATION_ID';
6430                             raise e_required_field_null;
6431                      ELSE
6432                            IF l_debug_on THEN
6433                               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_LOCATION',WSH_DEBUG_SV.C_PROC_LEVEL);
6434                            END IF;
6435                           wsh_util_validate.validate_location(
6436                               p_location_id   => x_detail_info_tab(l_index).ship_to_location_id,
6437                               x_return_status => l_return_status,
6438                               p_isWshLocation => l_isWshLocation);
6439 
6440                        wsh_util_core.api_post_call(
6441                            p_return_status => l_return_status,
6442                            x_num_warnings  => l_number_of_warnings,
6443                            x_num_errors    => l_number_of_errors,
6444                            p_msg_data      => l_msg_data
6445                            );
6446                      END IF;
6447 
6448                       --
6449                      IF (x_detail_info_tab(l_index).inventory_item_id is not null) THEN
6450                         --
6451               open c_inventory_item_info(x_detail_info_tab(l_index).inventory_item_id, x_detail_info_tab(l_index).organization_id);
6452             fetch c_inventory_item_info into l_inventory_item_info;
6453             close c_inventory_item_info;
6454 
6455             x_detail_info_tab(l_index).item_description := l_inventory_item_info.description;
6456             x_detail_info_tab(l_index).requested_quantity_uom := l_inventory_item_info.primary_uom_code;
6457 
6458                         --
6459             if (x_detail_info_tab(l_index).requested_quantity_uom is NULL) THEN
6460                             l_required_field := 'PRIMARY_UOM';
6461           raise e_required_field_null;
6462             end if;
6463 
6464             -- bug 2398865
6465                         --
6466             IF ( nvl(x_detail_info_tab(l_index).requested_quantity,fnd_api.g_miss_num) = fnd_api.g_miss_num ) THEN
6467 
6468                IF l_debug_on THEN
6469                   WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM',WSH_DEBUG_SV.C_PROC_LEVEL);
6470                END IF;
6471 
6472                  x_detail_info_tab(l_index).requested_quantity := wsh_wv_utils.convert_uom(
6473          x_detail_info_tab(l_index).src_requested_quantity_uom,
6474          l_inventory_item_info.primary_uom_code,
6475          x_detail_info_tab(l_index).src_requested_quantity,
6476          x_detail_info_tab(l_index).inventory_item_id);
6477 
6478                        wsh_util_core.api_post_call(
6479                            p_return_status => l_return_status,
6480                            x_num_warnings  => l_number_of_warnings,
6481                            x_num_errors    => l_number_of_errors,
6482                            p_msg_data      => l_msg_data
6483                            );
6484                         --
6485            END IF;
6486            -- bug 2398865
6487                         --
6488                   if (x_detail_info_tab(l_index).requested_quantity is NULL) THEN
6489                 raise UOM_CONVERSION_FAILED;
6490             end if;
6491                         --
6492             x_detail_info_tab(l_index).weight_uom_code := l_inventory_item_info.weight_uom_code;
6493             x_detail_info_tab(l_index).volume_uom_code := l_inventory_item_info.volume_uom_code;
6494 
6495                      END IF;
6496 
6497                         --
6498                         /* make it not applicable for pick release */
6499                         IF (x_detail_info_tab(l_index).source_code = 'OKE' ) THEN
6500                 x_detail_info_tab(l_index).released_status := 'X';
6501                         END IF;
6502                         --
6503                        IF (x_detail_info_tab(l_index).container_flag is NULL) THEN
6504                  x_detail_info_tab(l_index).container_flag := 'N';
6505                        END IF;
6506 
6507                         --
6508                         /* Bug 2212025 default date_requested to date_scheduled */
6509                         x_detail_info_tab(l_index).date_requested := NVL(x_detail_info_tab(l_index).date_requested, x_detail_info_tab(l_index).date_scheduled);
6510 
6511              --
6512              ELSIF p_action = 'UPDATE' THEN
6513 
6514                OPEN c_original_detail_cur(x_detail_info_tab(l_index).delivery_detail_id);
6515                FETCH c_original_detail_cur INTO l_original_detail_rec;
6516 
6517                IF c_original_detail_cur%NOTFOUND THEN
6518                      CLOSE c_original_detail_cur;
6519                      IF l_debug_on THEN
6520                        wsh_debug_sv.logmsg(l_module_name,'No Original Detail Record ');
6521                      END IF;
6522                      l_number_of_errors := l_number_of_errors + 1;
6523                      FND_MESSAGE.SET_NAME('WSH', 'WSH_DET_INVALID_DETAIL');
6524                      FND_MESSAGE.SET_TOKEN('DETAIL_ID', x_detail_info_tab(l_index).delivery_detail_id);
6525                      wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
6526                      RAISE FND_API.G_EXC_ERROR;
6527                END IF;
6528 
6529                CLOSE c_original_detail_cur;
6530 
6531                -- Bug 3382932: If caller is WMS, default the shipped_quantity2 to be the picked_quantity2.
6532 
6533                IF p_caller like 'WMS%' THEN
6534 
6535                   x_detail_info_tab(l_index).shipped_quantity2 :=  x_detail_info_tab(l_index).picked_quantity2;
6536 
6537                END IF;
6538 
6539 
6540                Validate_Detail_Common(
6541                     x_detail_rec        => x_detail_info_tab(l_index),
6542                     p_original_rec           => l_original_detail_rec,
6543                     p_validation_tab    => p_validation_tab,
6544                     x_mark_reprice_flag => l_mark_reprice_flag,
6545                     x_return_status     => l_return_status,
6546                     x_msg_count         => l_msg_count,
6547                     x_msg_data          => l_msg_data
6548                     );
6549 
6550                   IF l_debug_on THEN
6551                       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.API_POST_CALL',WSH_DEBUG_SV.C_PROC_LEVEL);
6552                   END IF;
6553                   --
6554                   wsh_util_core.api_post_call(
6555                       p_return_status => l_return_status,
6556                       x_num_warnings  => l_number_of_warnings,
6557                       x_num_errors    => l_number_of_errors,
6558                       p_msg_data      => l_msg_data
6559                       );
6560 
6561                  IF(l_original_detail_rec.container_flag in ('Y', 'C')) THEN
6562 
6563                   Validate_Detail_Container(
6564                     x_detail_rec        => x_detail_info_tab(l_index),
6565                     p_original_rec           => l_original_detail_rec,
6566                     p_validation_tab    => p_validation_tab,
6567                     x_mark_reprice_flag => l_mark_reprice_flag,
6568                     x_return_status     => l_return_status,
6569                     x_msg_count         => l_msg_count,
6570                     x_msg_data          => l_msg_data
6571                     );
6572 
6573                   IF l_debug_on THEN
6574                       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.API_POST_CALL',WSH_DEBUG_SV.C_PROC_LEVEL);
6575                   END IF;
6576                   --
6577                   wsh_util_core.api_post_call(
6578                       p_return_status => l_return_status,
6579                       x_num_warnings  => l_number_of_warnings,
6580                       x_num_errors    => l_number_of_errors,
6581                       p_msg_data      => l_msg_data
6582                       );
6583 
6584                 ELSIF(l_original_detail_rec.container_flag = 'N') THEN
6585 
6586                  Validate_Detail_Line(
6587                     x_detail_rec        => x_detail_info_tab(l_index),
6588                     p_in_detail_rec     => p_in_detail_tab(l_index),
6589                     p_original_rec      => l_original_detail_rec,
6590                     p_validation_tab    => p_validation_tab,
6591                     x_mark_reprice_flag => l_mark_reprice_flag,
6592                     x_return_status     => l_return_status,
6593                     x_msg_count         => l_msg_count,
6594                     x_msg_data          => l_msg_data,
6595                     p_in_rec            => p_in_rec,
6596                     p_serial_range_tab  => p_serial_range_tab
6597                     );
6598 
6599                   IF l_debug_on THEN
6600                       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.API_POST_CALL',WSH_DEBUG_SV.C_PROC_LEVEL);
6601                   END IF;
6602                   --
6603                   wsh_util_core.api_post_call(
6604                       p_return_status => l_return_status,
6605                       x_num_warnings  => l_number_of_warnings,
6606                       x_num_errors    => l_number_of_errors,
6607                       p_msg_data      => l_msg_data
6608                       );
6609 
6610 				  --Bug 12850936: When shipped_quantity is updated using Update_Shipping_Attributes Public API
6611                   --Weight/Volume needs to be re-calculated as its done from STF UI
6612                   --This piece of code is similar to DLVB.SHIPPED_QUANTITY Program Unit in WSHSTREF.fmb
6613                   IF ( p_caller = 'WSH_PUB' AND
6614                        NVL(l_original_detail_rec.shipped_quantity, -1) <> NVL(x_detail_info_tab(l_index).shipped_quantity, -1) )
6615                   THEN
6616                      -- Update w/v only when wv_frozen_flag is 'N'
6617                      IF l_original_detail_rec.wv_frozen_flag = 'N'
6618                      THEN
6619                         --
6620                         IF l_debug_on THEN
6621                             WSH_DEBUG_SV.logmsg(l_module_name,'Resetting Weight/Volume based on shipped quantity => ' || x_detail_info_tab(l_index).shipped_quantity ||
6622                                                               ', original shipped quantity => ' || l_original_detail_rec.shipped_quantity );
6623                         END IF;
6624                         --
6625                         IF l_original_detail_rec.shipped_quantity = 0
6626                         THEN
6627                            OPEN Item_Net_Wt_Vol(x_detail_info_tab(l_index).delivery_detail_id,
6628                                                 x_detail_info_tab(l_index).shipped_quantity);
6629                            FETCH Item_Net_Wt_Vol INTO x_detail_info_tab(l_index).net_weight,
6630                                                       x_detail_info_tab(l_index).volume;
6631                            CLOSE Item_Net_Wt_Vol;
6632                            x_detail_info_tab(l_index).gross_weight := x_detail_info_tab(l_index).net_weight;
6633                         ELSE
6634                            IF x_detail_info_tab(l_index).shipped_quantity IS NOT NULL
6635                            THEN
6636                               x_detail_info_tab(l_index).gross_weight := round((l_original_detail_rec.gross_weight * x_detail_info_tab(l_index).shipped_quantity) /
6637                                                 nvl(l_original_detail_rec.shipped_quantity,nvl(l_original_detail_rec.picked_quantity,l_original_detail_rec.requested_quantity)), 5);
6638                               x_detail_info_tab(l_index).net_weight := round((l_original_detail_rec.net_weight*x_detail_info_tab(l_index).shipped_quantity) /
6639                                                 nvl(l_original_detail_rec.shipped_quantity,nvl(l_original_detail_rec.picked_quantity,l_original_detail_rec.requested_quantity)), 5);
6640                               x_detail_info_tab(l_index).volume := round((l_original_detail_rec.volume*x_detail_info_tab(l_index).shipped_quantity) /
6641                                                 nvl(l_original_detail_rec.shipped_quantity,nvl(l_original_detail_rec.picked_quantity,l_original_detail_rec.requested_quantity)), 5);
6642                            ELSE
6643                               x_detail_info_tab(l_index).gross_weight := round((l_original_detail_rec.gross_weight * NVL(l_original_detail_rec.picked_quantity, l_original_detail_rec.requested_quantity)) /
6644                                                 nvl(l_original_detail_rec.shipped_quantity,nvl(l_original_detail_rec.picked_quantity,l_original_detail_rec.requested_quantity)), 5);
6645                               x_detail_info_tab(l_index).net_weight := round((l_original_detail_rec.net_weight * NVL(l_original_detail_rec.picked_quantity, l_original_detail_rec.requested_quantity)) /
6646                                                 nvl(l_original_detail_rec.shipped_quantity,nvl(l_original_detail_rec.picked_quantity,l_original_detail_rec.requested_quantity)), 5);
6647                               x_detail_info_tab(l_index).volume := round((l_original_detail_rec.volume * NVL(l_original_detail_rec.picked_quantity, l_original_detail_rec.requested_quantity)) /
6648                                                 nvl(l_original_detail_rec.shipped_quantity,nvl(l_original_detail_rec.picked_quantity,l_original_detail_rec.requested_quantity)), 5);
6649                            END IF;
6650                         END IF;
6651                      END IF;
6652                   END IF;
6653                   --Bug 12850936: End
6654 
6655               END IF; -- if check for container_flag
6656 
6657                IF(l_mark_reprice_flag = 'Y' ) THEN
6658                   x_details_marked(x_details_marked.count+1) := x_detail_info_tab(l_index).delivery_detail_id;
6659                END IF;
6660 
6661 
6662 -- anxsharm for Load Tender
6663                IF l_fte_installed = 'Y' THEN
6664 
6665 -- this is for action code of UPDATE only
6666 -- track changes to quantity or weight or volume
6667 -- do not pass delivery id and parent_delivery_detail_id from here
6668 
6669 -- number of records already populated in table
6670                l_count_old := l_old_table.count + 1;
6671                l_count_new := l_new_table.count + 1;
6672 
6673 --
6674 -- Current Values in Database
6675 --
6676                l_old_table(l_count_old).requested_quantity := l_original_detail_rec.requested_quantity;
6677                l_old_table(l_count_old).picked_quantity := l_original_detail_rec.picked_quantity;
6678                l_old_table(l_count_old).shipped_quantity := l_original_detail_rec.shipped_quantity;
6679                l_old_table(l_count_old).gross_weight := l_original_detail_rec.gross_weight;
6680                l_old_table(l_count_old).net_weight := l_original_detail_rec.net_weight;
6681                l_old_table(l_count_old).weight_uom_code := l_original_detail_rec.weight_uom_code;
6682                l_old_table(l_count_old).volume := l_original_detail_rec.volume;
6683                l_old_table(l_count_old).volume_uom_code := l_original_detail_rec.volume_uom_code;
6684 -- Old record must have delivery detail id, which is same
6685 -- as the new record
6686                l_old_table(l_count_old).delivery_detail_id := x_detail_info_tab(l_index).delivery_detail_id;
6687 
6688 --
6689 -- New Record
6690 --
6691                l_new_table(l_count_new).requested_quantity := x_detail_info_tab(l_index).requested_quantity;
6692                l_new_table(l_count_new).picked_quantity := x_detail_info_tab(l_index).picked_quantity;
6693                l_new_table(l_count_new).shipped_quantity := x_detail_info_tab(l_index).shipped_quantity;
6694                l_new_table(l_count_new).gross_weight := x_detail_info_tab(l_index).gross_weight;
6695                l_new_table(l_count_new).net_weight := x_detail_info_tab(l_index).net_weight;
6696                l_new_table(l_count_new).weight_uom_code := x_detail_info_tab(l_index).weight_uom_code;
6697                l_new_table(l_count_new).volume := x_detail_info_tab(l_index).volume;
6698                l_new_table(l_count_new).volume_uom_code := x_detail_info_tab(l_index).volume_uom_code;
6699 
6700                END IF; -- fte is installed
6701 -- anxsharm , end of code for Load Tender
6702              --  moved code for vlaidating secondary quantity inside the ELSIF p_action = 'UPDATE' block
6703              -- PK Bug 3055126 Begin OPM Changes for validation of quantities
6704              IF  ( p_caller = 'WSH_PUB') THEN
6705                IF (nvl(x_detail_info_tab(l_index).shipped_quantity,fnd_api.g_miss_num) <> fnd_api.g_miss_num OR
6706                    nvl(x_detail_info_tab(l_index).shipped_quantity2,fnd_api.g_miss_num) <> fnd_api.g_miss_num) THEN
6707 
6708 -- HW OPMCONV - Use this API instead of GMI_RESERVATION_UTIL.validate_opm_quantities
6709 
6710                   WSH_DETAILS_VALIDATIONS.validate_secondary_quantity
6711                   (
6712                   p_delivery_detail_id => x_detail_info_tab(l_index).delivery_detail_id,
6713                   x_quantity          => x_detail_info_tab(l_index).shipped_quantity,
6714                   x_quantity2         => x_detail_info_tab(l_index).shipped_quantity2,
6715                   p_caller             =>    p_caller,
6716                   x_return_status      => l_return_status,
6717                   x_msg_count          =>    l_msg_count,
6718                   x_msg_data           =>    l_msg_data
6719                   );
6720                    --
6721                    wsh_util_core.api_post_call(
6722                        p_return_status => l_return_status,
6723                        x_num_warnings  => l_number_of_warnings,
6724                        x_num_errors    => l_number_of_errors,
6725                        p_msg_data      => l_msg_data
6726                        );
6727 
6728 
6729                END IF;
6730 
6731 -- HW OPMCONV - Needed to add check for "0". Some cases cycle_count values
6732 -- had values of zeroes due to initialization issues
6733              IF ( ( nvl(x_detail_info_tab(l_index).cycle_count_quantity,fnd_api.g_miss_num) <> fnd_api.g_miss_num
6734                OR  nvl(x_detail_info_tab(l_index).cycle_count_quantity2,fnd_api.g_miss_num) <> fnd_api.g_miss_num )
6735                AND ( x_detail_info_tab(l_index).cycle_count_quantity <> 0
6736                 OR   x_detail_info_tab(l_index).cycle_count_quantity2 <> 0) )
6737                     THEN
6738 
6739                     IF l_debug_on THEN
6740                         wsh_debug_sv.push(l_module_name);
6741                         wsh_debug_sv.LOG(l_module_name, 'x_detail_info_tab(l_index).cycle_count_quantity', x_detail_info_tab(l_index).cycle_count_quantity);
6742                         wsh_debug_sv.LOG(l_module_name, 'x_detail_info_tab(l_index).cycle_count_quantity2', x_detail_info_tab(l_index).cycle_count_quantity2);
6743 
6744                     END IF;
6745 
6746                  WSH_DETAILS_VALIDATIONS.validate_secondary_quantity
6747                   (
6748                   p_delivery_detail_id => x_detail_info_tab(l_index).delivery_detail_id,
6749                   x_quantity           => x_detail_info_tab(l_index).cycle_count_quantity,
6750                   x_quantity2          => x_detail_info_tab(l_index).cycle_count_quantity2,
6751                   p_caller             => p_caller,
6752                   x_return_status      => l_return_status,
6753                   x_msg_count          => l_msg_count,
6754                   x_msg_data           => l_msg_data
6755                   );
6756 
6757 
6758                   wsh_util_core.api_post_call(
6759                        p_return_status => l_return_status,
6760                        x_num_warnings  => l_number_of_warnings,
6761                        x_num_errors    => l_number_of_errors,
6762                        p_msg_data      => l_msg_data
6763                        );
6764 
6765               END IF;
6766 
6767            END IF;
6768              -- PK Bug 3055126 End OPM Changes
6769 
6770              END IF; -- if p_action = create
6771 
6772 -- HW OPMCONV - Removed checking for process
6773 
6774              -- Added for bug 4399278, 4418754
6775              x_valid_index_tab(l_index) := l_index;
6776 
6777            --
6778            EXCEPTION -- for the local begin
6779               WHEN FND_API.G_EXC_ERROR THEN
6780                 ROLLBACK TO validate_det_loop_grp;
6781                 IF l_debug_on THEN
6782                    wsh_debug_sv.log(l_module_name, 'Validation failure for detail', x_detail_info_tab(l_index).delivery_detail_id);
6783                 END IF;
6784 
6785               WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6786                 ROLLBACK TO validate_det_loop_grp;
6787                 IF l_debug_on THEN
6788                    wsh_debug_sv.logmsg(l_module_name, 'Unexpected error within loop');
6789                 END IF;
6790              WHEN e_required_field_null THEN
6791                 ROLLBACK TO validate_det_loop_grp;
6792                 l_number_of_errors := l_number_of_errors + 1;
6793                 FND_MESSAGE.SET_NAME('WSH', 'WSH_REQUIRED_FIELD_NULL');
6794                 FND_MESSAGE.SET_TOKEN('FIELD_NAME', l_required_field);
6795                 WSH_UTIL_CORE.ADD_MESSAGE(wsh_util_core.g_ret_sts_error, l_module_name);
6796                 IF l_debug_on THEN
6797                       WSH_DEBUG_SV.logmsg(l_module_name,'E_REQUIRED_FIELD_NULL  exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
6798                END IF;
6799                -- J-IB-NPARIKH-{
6800              WHEN e_ib_create_error THEN
6801                 ROLLBACK TO validate_det_loop_grp;
6802                 l_number_of_errors := l_number_of_errors + 1;
6803                 FND_MESSAGE.SET_NAME('WSH', 'WSH_IB_CREATE_LINE_ERROR');
6804                 WSH_UTIL_CORE.ADD_MESSAGE(wsh_util_core.g_ret_sts_error, l_module_name);
6805                 IF l_debug_on THEN
6806                       WSH_DEBUG_SV.logmsg(l_module_name,'e_ib_create_error  exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
6807                END IF;
6808                -- J-IB-NPARIKH-}
6809 
6810              when uom_conversion_failed then
6811                 FND_MESSAGE.SEt_NAME('WSH','UOM_CONVERSION_FAILED');
6812                 WSH_UTIL_CORE.ADD_MESSAGE(wsh_util_core.g_ret_sts_error, l_module_name);
6813 
6814                   IF l_debug_on THEN
6815                       WSH_DEBUG_SV.logmsg(l_module_name,'UOM_CONVERSION_FAILED exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
6816                END IF;
6817 
6818               WHEN OTHERS THEN
6819                 ROLLBACK TO validate_det_loop_grp;
6820                 IF l_debug_on THEN
6821                    wsh_debug_sv.logmsg(l_module_name, 'Others exception  within loop');
6822                 END IF;
6823                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6824            END; -- for the local begin
6825 
6826              -- Commented for bug 4399278, 4418754
6827              --x_valid_index_tab(l_index) := l_index;
6828              --
6829              l_index := x_detail_info_tab.NEXT(l_index);
6830         --
6831         END LOOP; -- while l_index is not null
6832 
6833 -- anxsharm for Load Tender
6834 -- new API added for comparison of attributes
6835 -- but has different record structure.
6836 -- Use Compare_detail_attributes API
6837         IF l_fte_installed = 'Y' THEN
6838           WSH_DETAILS_VALIDATIONS.compare_detail_attributes
6839                  (p_old_table     => l_old_table,
6840                   p_new_table     => l_new_table,
6841                   p_action_code   => p_action,
6842                   p_phase         => 1,
6843                   p_caller        => 'WSH',
6844                   x_changed_id_tab => x_detail_tender_tab,
6845                   x_return_status => l_return_status
6846                  );
6847           wsh_util_core.api_post_call(
6848                       p_return_status => l_return_status,
6849                       x_num_warnings  => l_number_of_warnings,
6850                       x_num_errors    => l_number_of_errors,
6851                       p_msg_data      => l_msg_data
6852                       );
6853         END IF; --l_fte_installed = 'Y'
6854 -- anxsharm end for Load Tender
6855 
6856 
6857       IF l_debug_on THEN
6858          wsh_debug_sv.log(l_module_name, 'Number of errors', l_number_of_errors);
6859          wsh_debug_sv.log(l_module_name, 'Number of warnings', l_number_of_warnings);
6860       END IF;
6861 
6862       IF x_detail_info_tab.count > 0 THEN
6863         IF l_number_of_errors >= x_detail_info_tab.count THEN
6864            RAISE FND_API.G_EXC_ERROR;
6865         ELSIF l_number_of_errors >0 THEN
6866            RAISE WSH_UTIL_CORE.G_EXC_WARNING;
6867         ELSIF l_number_of_warnings > 0 THEN
6868            RAISE WSH_UTIL_CORE.G_EXC_WARNING;
6869         END IF;
6870       END IF;
6871 
6872        FND_MSG_PUB.Count_And_Get
6873          (
6874           p_count  => x_msg_count,
6875           p_data  =>  x_msg_data,
6876           p_encoded => FND_API.G_FALSE
6877          );
6878 
6879     IF l_debug_on THEN
6880         WSH_DEBUG_SV.pop(l_module_name);
6881     END IF;
6882     --
6883     EXCEPTION
6884         WHEN FND_API.G_EXC_ERROR THEN
6885                 ROLLBACK to VALIDATE_DEL_DETAIL_GRP;
6886                 x_return_status := FND_API.G_RET_STS_ERROR ;
6887                 FND_MSG_PUB.Count_And_Get
6888                   (
6889                      p_count  => x_msg_count,
6890                      p_data  =>  x_msg_data,
6891                p_encoded => FND_API.G_FALSE
6892                   );
6893                   --
6894                   IF l_debug_on THEN
6895                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
6896                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_ERROR');
6897                   END IF;
6898                   --
6899         --
6900         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6901                 ROLLBACK to VALIDATE_DEL_DETAIL_GRP;
6902                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6903                 FND_MSG_PUB.Count_And_Get
6904                   (
6905                      p_count  => x_msg_count,
6906                      p_data  =>  x_msg_data,
6907                p_encoded => FND_API.G_FALSE
6908                   );
6909                   --
6910                   IF l_debug_on THEN
6911                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
6912                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
6913                   END IF;
6914                   --
6915         --
6916         WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
6917              x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
6918              FND_MSG_PUB.Count_And_Get
6919               (
6920                 p_count  => x_msg_count,
6921                 p_data  =>  x_msg_data,
6922                 p_encoded => FND_API.G_FALSE
6923               );
6924         --
6925            IF l_debug_on THEN
6926               WSH_DEBUG_SV.logmsg(l_module_name,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ',WSH_DEBUG_SV.C_EXCEP_LEVEL);
6927               WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
6928            END IF;
6929  --
6930 
6931 
6932         WHEN OTHERS THEN
6933 
6934                 ROLLBACK to VALIDATE_DEL_DETAIL_GRP;
6935                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6936                wsh_util_core.add_message(x_return_status, l_module_name);
6937                WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Validate_Delivery_Detail');
6938 
6939                 FND_MSG_PUB.Count_And_Get
6940                   (
6941                      p_count  => x_msg_count,
6942                      p_data  =>  x_msg_data,
6943                p_encoded => FND_API.G_FALSE
6944                   );
6945     --
6946                       IF l_debug_on THEN
6947                     WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
6948                     WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
6949                 END IF;
6950     --
6951     END Validate_Delivery_Detail;
6952 
6953     -- ---------------------------------------------------------------------
6954     -- Procedure: Update_Delivery_Detail
6955     --
6956     -- Parameters:
6957     --
6958     -- Description:  This local procedure is the new API for wrapping the logic of UPDATE of delivery details
6959     -- Created:   Harmonization Project. Patchset I
6960     -- -----------------------------------------------------------------------
6961 
6962     PROCEDURE  Update_Delivery_Detail(
6963                 p_detail_info_tab     IN        WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type ,
6964                 p_valid_index_tab     IN  wsh_util_core.id_tab_type,
6965                 x_return_status       OUT NOCOPY  VARCHAR2,
6966                 x_msg_count           OUT NOCOPY      NUMBER,
6967                 x_msg_data            OUT NOCOPY      VARCHAR2,
6968                 p_caller              IN              VARCHAR2 DEFAULT NULL)
6969       IS
6970 
6971         cursor lock_delivery_details(p_del_det IN NUMBER) is
6972         select delivery_detail_id
6973         from wsh_delivery_details
6974         where delivery_detail_id = p_del_det
6975         for update nowait;
6976 
6977 
6978         l_api_name              CONSTANT VARCHAR2(30)   := 'Update_Delivery_Detail';
6979         l_api_version           CONSTANT NUMBER         := 1.0;
6980         --
6981   --
6982   l_return_status             VARCHAR2(32767);
6983   l_msg_count                 NUMBER;
6984   l_msg_data                  VARCHAR2(32767);
6985   l_program_name              VARCHAR2(32767);
6986         --
6987   l_number_of_errors    NUMBER := 0;
6988   l_number_of_warnings  NUMBER := 0;
6989   --
6990         l_index                  NUMBER;
6991         l_delivery_detail        NUMBER;
6992   --lpn conv
6993   l_in_rec             WSH_GLBL_VAR_STRCT_GRP.lpn_sync_comm_in_rec_type;
6994   l_out_rec            WSH_GLBL_VAR_STRCT_GRP.lpn_sync_comm_out_rec_type;
6995 
6996   --
6997 l_debug_on BOOLEAN;
6998   --
6999   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'UPDATE_DELIVERY_DETAIL';
7000         delivery_detail_locked EXCEPTION;
7001         PRAGMA EXCEPTION_INIT(delivery_detail_locked, -00054);
7002 
7003 
7004 
7005     BEGIN
7006     --
7007         --
7008         l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
7009         --
7010         IF l_debug_on IS NULL
7011         THEN
7012             l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
7013         END IF;
7014         --
7015         SAVEPOINT UPDATE_DEL_DETAIL_GRP;
7016         IF l_debug_on THEN
7017             WSH_DEBUG_SV.push(l_module_name);
7018             WSH_DEBUG_SV.log(l_module_name,'count of p_valid_index_tab is', p_valid_index_tab.count);
7019             WSH_DEBUG_SV.log(l_module_name,'count of p_detail_info_tab is', p_detail_info_tab.count);
7020         END IF;
7021         --
7022 
7023         --  Initialize API return status to success
7024   x_return_status       := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
7025   l_number_of_errors := 0;
7026   l_number_of_warnings := 0;
7027 
7028         l_index := p_valid_index_tab.FIRST;
7029 
7030         IF l_debug_on THEN
7031             WSH_DEBUG_SV.log(l_module_name,'first index of p_detail_info_tab is', l_index);
7032         END IF;
7033 
7034         WHILE l_index IS NOT NULL
7035         LOOP
7036             IF (p_caller like 'WMS%') OR (p_caller = 'WSH_USA') THEN
7037             -- Bug 3292364
7038             -- Lock the container being updated during OM changes.
7039                IF l_debug_on THEN
7040                    WSH_DEBUG_SV.log(l_module_name, 'lock delivery detail '||p_detail_info_tab(l_index).delivery_detail_id);
7041                END IF;
7042 
7043                OPEN lock_delivery_details(p_detail_info_tab(l_index).delivery_detail_id);
7044                FETCH lock_delivery_details into l_delivery_detail;
7045 
7046             END IF;
7047 
7048 
7049             IF l_debug_on THEN
7050                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_PKG.UPDATE_DELIVERY_DETAILS',WSH_DEBUG_SV.C_PROC_LEVEL);
7051             END IF;
7052             --
7053             wsh_delivery_details_pkg.Update_Delivery_Details(
7054                 p_rowid                   => p_detail_info_tab(l_index).rowid,
7055                 p_delivery_details_info   => p_detail_info_tab(l_index),
7056                 x_return_status           =>  l_return_status);
7057 
7058                   --
7059                   IF l_debug_on THEN
7060                       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.API_POST_CALL',WSH_DEBUG_SV.C_PROC_LEVEL);
7061                   END IF;
7062                   --
7063                   wsh_util_core.api_post_call(
7064                       p_return_status => l_return_status,
7065                       x_num_warnings  => l_number_of_warnings,
7066                       x_num_errors    => l_number_of_errors,
7067                       p_msg_data      => l_msg_data
7068                       );
7069 
7070               IF lock_delivery_details%isopen THEN
7071                  CLOSE lock_delivery_details;
7072               END IF;
7073 
7074 
7075            l_index := p_valid_index_tab.NEXT(l_index);
7076 
7077        END LOOP; -- while l_index is not null
7078 
7079        --{ lpn conv
7080        IF WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y' THEN
7081           WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED := 'N';
7082 
7083           WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS( --bmso dependency
7084                      p_in_rec        => l_in_rec,
7085                      x_return_status => l_return_status,
7086                      x_out_rec       => l_out_rec
7087           );
7088 
7089           wsh_util_core.api_post_call(
7090                       p_return_status => l_return_status,
7091                       x_num_warnings  => l_number_of_warnings,
7092                       x_num_errors    => l_number_of_errors
7093           );
7094 
7095           WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED := 'Y';
7096           WSH_WMS_LPN_GRP.g_update_to_container := 'N';
7097 
7098        END IF;
7099        --} lpn conv
7100 
7101        FND_MSG_PUB.Count_And_Get
7102          (
7103           p_count  => x_msg_count,
7104           p_data  =>  x_msg_data,
7105           p_encoded => FND_API.G_FALSE
7106          );
7107 
7108     --
7109     IF l_debug_on THEN
7110         WSH_DEBUG_SV.pop(l_module_name);
7111     END IF;
7112     --
7113     EXCEPTION
7114         WHEN FND_API.G_EXC_ERROR THEN
7115                 ROLLBACK to UPDATE_DEL_DETAIL_GRP;
7116                 x_return_status := FND_API.G_RET_STS_ERROR ;
7117                 WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED := 'Y';
7118                 WSH_WMS_LPN_GRP.g_update_to_container := 'N';
7119                 FND_MSG_PUB.Count_And_Get
7120                   (
7121                      p_count  => x_msg_count,
7122                      p_data  =>  x_msg_data,
7123                p_encoded => FND_API.G_FALSE
7124                   );
7125                   --
7126 
7127                   IF l_debug_on THEN
7128                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
7129                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_ERROR');
7130                   END IF;
7131                   --
7132         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7133               IF lock_delivery_details%isopen THEN
7134                  CLOSE lock_delivery_details;
7135               END IF;
7136                 ROLLBACK to UPDATE_DEL_DETAIL_GRP;
7137                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7138                 WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED := 'Y';
7139                 WSH_WMS_LPN_GRP.g_update_to_container := 'N';
7140                 FND_MSG_PUB.Count_And_Get
7141                   (
7142                      p_count  => x_msg_count,
7143                      p_data  =>  x_msg_data,
7144                p_encoded => FND_API.G_FALSE
7145                   );
7146                   --
7147                   --
7148                   IF l_debug_on THEN
7149                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
7150                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
7151                   END IF;
7152                   --
7153         WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
7154               IF lock_delivery_details%isopen THEN
7155                  CLOSE lock_delivery_details;
7156               END IF;
7157              x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
7158              --
7159              -- K LPN CONV. rv
7160              --
7161              IF WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y'
7162              THEN
7163              --{
7164                  IF l_debug_on THEN
7165                    WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',WSH_DEBUG_SV.C_PROC_LEVEL);
7166                  END IF;
7167 
7168                  WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS
7169                    (
7170                      p_in_rec             => l_in_rec,
7171                      x_return_status      => l_return_status,
7172                      x_out_rec            => l_out_rec
7173                    );
7174                  --
7175                  --
7176                  IF l_debug_on THEN
7177                    WSH_DEBUG_SV.log(l_module_name,'Return status after calling WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',l_return_status);
7178                  END IF;
7179                  --
7180                  --
7181                  IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR, WSH_UTIL_CORE.G_RET_STS_ERROR) and x_return_status <> WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
7182                    x_return_status := l_return_status;
7183                  END IF;
7184                  --
7185              --}
7186              END IF;
7187              --
7188              -- K LPN CONV. rv
7189              --
7190                 WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED := 'Y';
7191                 WSH_WMS_LPN_GRP.g_update_to_container := 'N';
7192              FND_MSG_PUB.Count_And_Get
7193               (
7194                 p_count  => x_msg_count,
7195                 p_data  =>  x_msg_data,
7196                 p_encoded => FND_API.G_FALSE
7197               );
7198         --
7199         IF l_debug_on THEN
7200             WSH_DEBUG_SV.logmsg(l_module_name,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ',WSH_DEBUG_SV.C_EXCEP_LEVEL);
7201            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
7202        END IF;
7203 --
7204         WHEN delivery_detail_locked THEN
7205               IF lock_delivery_details%isopen THEN
7206                  CLOSE lock_delivery_details;
7207               END IF;
7208               --
7209               -- K LPN CONV. rv
7210               --
7211               IF WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y'
7212               THEN
7213               --{
7214                   IF l_debug_on THEN
7215                     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',WSH_DEBUG_SV.C_PROC_LEVEL);
7216                   END IF;
7217 
7218                   WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS
7219                     (
7220                       p_in_rec             => l_in_rec,
7221                       x_return_status      => l_return_status,
7222                       x_out_rec            => l_out_rec
7223                     );
7224                   --
7225                   --
7226                   IF l_debug_on THEN
7227                     WSH_DEBUG_SV.log(l_module_name,'Return status after calling WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',l_return_status);
7228                   END IF;
7229                   --
7230                   --
7231                   IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR, WSH_UTIL_CORE.G_RET_STS_ERROR) and x_return_status <> WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
7232                     x_return_status := l_return_status;
7233                   END IF;
7234                   --
7235               --}
7236               END IF;
7237               --
7238               -- K LPN CONV. rv
7239               --
7240                 WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED := 'Y';
7241                 WSH_WMS_LPN_GRP.g_update_to_container := 'N';
7242               l_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
7243               FND_MESSAGE.Set_Name('WSH', 'WSH_NO_LOCK');
7244               wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
7245              IF l_debug_on THEN
7246               WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:delivery_detail_locked');
7247              END IF;
7248 
7249         WHEN OTHERS THEN
7250               IF lock_delivery_details%isopen THEN
7251                  CLOSE lock_delivery_details;
7252               END IF;
7253 
7254                 ROLLBACK to UPDATE_DEL_DETAIL_GRP;
7255                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7256                 WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED := 'Y';
7257                 WSH_WMS_LPN_GRP.g_update_to_container := 'N';
7258                wsh_util_core.add_message(x_return_status, l_module_name);
7259                WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Update_Delivery_Detail');
7260 
7261                 FND_MSG_PUB.Count_And_Get
7262                   (
7263                      p_count  => x_msg_count,
7264                      p_data  =>  x_msg_data,
7265                p_encoded => FND_API.G_FALSE
7266                   );
7267 
7268              IF l_debug_on THEN
7269                 WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
7270                 WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
7271             END IF;
7272 --
7273     END Update_Delivery_Detail;
7274 
7275 
7276 
7277 
7278     -- ---------------------------------------------------------------------
7279     -- Procedure: Cancel_Delivery_Detail
7280     --
7281     -- Parameters:
7282     --
7283     -- Description:  This local procedure is the new API for wrapping the logic of CANCEL of delivery details
7284     -- Created:   Harmonization Project. Patchset I
7285     -- -----------------------------------------------------------------------
7286 
7287     PROCEDURE  Cancel_Delivery_Detail(
7288                 p_detail_info_tab     IN  WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type ,
7289                 x_return_status       OUT NOCOPY      VARCHAR2,
7290                 x_msg_count           OUT NOCOPY      NUMBER,
7291                 x_msg_data            OUT NOCOPY      VARCHAR2,
7292                 p_caller              IN              VARCHAR2 DEFAULT NULL)
7293       IS
7294 
7295         l_api_name              CONSTANT VARCHAR2(30)   := 'Cancel_Delivery_Detail';
7296         l_api_version           CONSTANT NUMBER         := 1.0;
7297         --
7298   --
7299   l_return_status             VARCHAR2(32767);
7300   l_msg_count                 NUMBER;
7301   l_msg_data                  VARCHAR2(32767);
7302   l_program_name              VARCHAR2(32767);
7303         --
7304   l_number_of_errors    NUMBER := 0;
7305   l_number_of_warnings  NUMBER := 0;
7306   --
7307         l_index                  NUMBER;
7308 
7309   --jckwok
7310   l_changed_attr_tab      wsh_interface.ChangedAttributeTabType;
7311 
7312   --
7313   l_debug_on BOOLEAN;
7314   --
7315     l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CANCEL_DELIVERY_DETAIL';
7316 
7317 
7318 
7319     BEGIN
7320     --
7321         --
7322         l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
7323         --
7324         IF l_debug_on IS NULL
7325         THEN
7326             l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
7327         END IF;
7328         --
7329         SAVEPOINT CANCEL_DEL_DETAIL_GRP;
7330         IF l_debug_on THEN
7331             WSH_DEBUG_SV.push(l_module_name);
7332         END IF;
7333         --
7334 
7335   --  Initialize API return status to success
7336   x_return_status       := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
7337   l_number_of_errors := 0;
7338   l_number_of_warnings := 0;
7339 
7340 
7341       l_index := p_detail_info_tab.FIRST;
7342       WHILE l_index IS NOT NULL
7343   LOOP
7344    l_changed_attr_tab(l_index).action_flag         :=  'U';
7345    l_changed_attr_tab(l_index).source_code         :=  p_detail_info_tab(l_index).source_code;
7346          l_changed_attr_tab(l_index).container_flag                        :=  p_detail_info_tab(l_index).container_flag;
7347    l_changed_attr_tab(l_index).delivery_detail_id                    :=   p_detail_info_tab(l_index).delivery_detail_id;
7348    l_changed_attr_tab(l_index).ordered_quantity                      :=   0 ;
7349    l_changed_attr_tab(l_index).order_quantity_uom                  :=   p_detail_info_tab(l_index).requested_quantity_uom;
7350          l_changed_attr_tab(l_index).source_line_id                        :=   p_detail_info_tab(l_index).source_line_id;
7351    l_index := p_detail_info_tab.NEXT(l_index);
7352   END LOOP;
7353 
7354 
7355        --
7356        IF l_debug_on THEN
7357                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_INTERFACE.Update_Shipping_Attributes',WSH_DEBUG_SV.C_PROC_LEVEL);
7358                 WSH_DEBUG_SV.log(l_module_name, 'l_changed_attr_tab.count', l_changed_attr_tab.count);
7359                 WSH_DEBUG_SV.log(l_module_name, 'Delivery Detail Id', l_changed_attr_tab(1).delivery_detail_id);
7360 
7361                 WSH_DEBUG_SV.log(l_module_name, 'Ordered Quantity ', l_changed_attr_tab(1).ordered_quantity);
7362                 WSH_DEBUG_SV.log(l_module_name, 'Ord qty uom ', l_changed_attr_tab(1).order_quantity_uom);
7363                 WSH_DEBUG_SV.log(l_module_name, 'Source Line Id', l_changed_attr_tab(1).Source_Line_id);
7364                 wsh_debug_sv.log(l_module_name, 'Source_Code', p_detail_info_tab(1).source_code);
7365        END IF;
7366        --
7367 
7368 
7369 
7370        WSH_INTERFACE.Update_Shipping_Attributes(
7371     p_source_code            =>  'WSH',
7372                 p_changed_attributes  => l_changed_attr_tab,
7373     x_return_status          => l_return_status
7374        );
7375 
7376                   --
7377                   IF l_debug_on THEN
7378                       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.API_POST_CALL',WSH_DEBUG_SV.C_PROC_LEVEL);
7379                   END IF;
7380                   --
7381       --
7382                   wsh_util_core.api_post_call(
7383                       p_return_status => l_return_status,
7384                       x_num_warnings  => l_number_of_warnings,
7385                       x_num_errors    => l_number_of_errors,
7386                       p_msg_data      => l_msg_data
7387                       );
7388 
7389       --
7390 
7391                   IF l_number_of_warnings > 0 THEN
7392                         IF l_debug_on THEN
7393                                wsh_debug_sv.log(l_module_name, 'Number of warnings', l_number_of_warnings);
7394                         END IF;
7395 
7396                         RAISE wsh_util_core.g_exc_warning;
7397                   END IF;
7398 
7399 
7400 
7401        FND_MSG_PUB.Count_And_Get
7402          (
7403           p_count  => x_msg_count,
7404           p_data  =>  x_msg_data,
7405           p_encoded => FND_API.G_FALSE
7406          );
7407 
7408     --
7409     IF l_debug_on THEN
7410         WSH_DEBUG_SV.pop(l_module_name);
7411     END IF;
7412     --
7413 
7414 
7415 
7416 --
7417     EXCEPTION
7418         WHEN FND_API.G_EXC_ERROR THEN
7419                 ROLLBACK to CANCEL_DEL_DETAIL_GRP;
7420                 x_return_status := FND_API.G_RET_STS_ERROR ;
7421                 FND_MSG_PUB.Count_And_Get
7422                   (
7423                      p_count  => x_msg_count,
7424                      p_data  =>  x_msg_data,
7425                      p_encoded => FND_API.G_FALSE
7426                   );
7427 
7428                   IF l_debug_on THEN
7429                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
7430                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_ERROR');
7431                   END IF;
7432                   --
7433         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7434                 ROLLBACK to CANCEL_DEL_DETAIL_GRP;
7435                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7436                 FND_MSG_PUB.Count_And_Get
7437                   (
7438                      p_count  => x_msg_count,
7439                      p_data  =>  x_msg_data,
7440                      p_encoded => FND_API.G_FALSE
7441                   );
7442 
7443                   IF l_debug_on THEN
7444                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
7445                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
7446                   END IF;
7447                   --
7448         WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
7449              x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
7450              FND_MSG_PUB.Count_And_Get
7451               (
7452                 p_count  => x_msg_count,
7453                 p_data  =>  x_msg_data,
7454                 p_encoded => FND_API.G_FALSE
7455               );
7456         --
7457         IF l_debug_on THEN
7458             WSH_DEBUG_SV.logmsg(l_module_name,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ',WSH_DEBUG_SV.C_EXCEP_LEVEL);
7459             WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
7460         END IF;
7461 --
7462         WHEN OTHERS THEN
7463 
7464                 ROLLBACK to CANCEL_DEL_DETAIL_GRP;
7465                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7466                 wsh_util_core.add_message(x_return_status, l_module_name);
7467                 WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Delete_Delivery_Detail');
7468                 FND_MSG_PUB.Count_And_Get
7469                   (
7470                      p_count  => x_msg_count,
7471                      p_data  =>  x_msg_data,
7472                      p_encoded => FND_API.G_FALSE
7473                   );
7474 
7475               IF l_debug_on THEN
7476                   WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
7477                   WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
7478               END IF;
7479 --
7480 
7481 
7482 
7483 
7484 
7485 
7486 END Cancel_Delivery_Detail;
7487 
7488 
7489 
7490 
7491 
7492     -- ---------------------------------------------------------------------
7493     -- Procedure: Validate_Detail_Line
7494     --
7495     -- Parameters:
7496     --
7497     -- Description:  This local procedure is the new API for wrapping the logic of VALIDATE of Non Containers
7498     -- Created:   Harmonization Project. Patchset I
7499     -- -----------------------------------------------------------------------
7500 /*
7501    PLEASE READ BEFORE CHANGING THIS PROCEDURE
7502    For inbound lines, this procedure returns back to caller, right at the beginning.
7503    If you are adding any validation, which may be applicable for inbound line as well, please
7504    evaluate against that.
7505 */
7506 PROCEDURE validate_detail_line(
7507    x_detail_rec          IN OUT NOCOPY   WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Rec_Type,
7508    p_in_detail_rec       IN              WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Rec_Type,
7509    p_original_rec        IN              c_original_detail_cur%ROWTYPE,
7510    p_validation_tab      IN              wsh_util_core.id_tab_type,
7511    x_mark_reprice_flag   OUT NOCOPY      VARCHAR2,
7512    x_return_status       OUT NOCOPY      VARCHAR2,
7513    x_msg_count           OUT NOCOPY      NUMBER,
7514    x_msg_data            OUT NOCOPY      VARCHAR2,
7515    p_in_rec              IN              WSH_GLBL_VAR_STRCT_GRP.detailInRecType,
7516    p_serial_range_tab    IN              WSH_GLBL_VAR_STRCT_GRP.ddSerialRangeTabType
7517 ) IS
7518    l_api_name           CONSTANT VARCHAR2(30) := 'Validate_Detail_Line';
7519    l_api_version        CONSTANT NUMBER := 1.0;
7520    --
7521    l_return_status               VARCHAR2(32767);
7522    l_msg_count                   NUMBER;
7523    l_msg_data                    VARCHAR2(32767);
7524    l_program_name                VARCHAR2(32767);
7525    --
7526    l_number_of_errors            NUMBER := 0;
7527    l_number_of_warnings          NUMBER := 0;
7528    --
7529    l_org_id                      NUMBER;                     /***Bug 1813496*/
7530    l_subinventory                VARCHAR2(30);               /***Bug 1813496*/
7531    l_locator                     NUMBER;                     /***Bug 1813496*/
7532    l_revision                    VARCHAR2(30);
7533               /***Bug 1813496*/
7534 -- HW OPMCONV - Increased length to 80
7535    l_lot                         VARCHAR2(80);
7536    l_result                      BOOLEAN;
7537    l_quantity                    NUMBER;
7538    l_inv_controls                wsh_delivery_details_inv.inv_control_flag_rec;
7539    l_ship_method_name            VARCHAR2(32767);
7540 -- HW Harmonization project for OPM. Added l_process flag variable
7541 -- HW OPMCONV - Removed OPM variables
7542 
7543 -- added variables for bug 12597783
7544    l_lpn_id                  NUMBER;
7545    l_wms_installed           VARCHAR2(10);
7546 
7547 
7548    l_det_qty_rec                 wsh_details_validations.validatequantityattrrectype;
7549    -- Bug fix  1578114
7550    l_transaction_id              NUMBER;
7551    l_prefix                      VARCHAR2(240);
7552    v1                            NUMBER;
7553    v2                            DATE;
7554    v3                            NUMBER;
7555    v4                            DATE;
7556    v5                            NUMBER;
7557    v6                            NUMBER;
7558    v7                            NUMBER;
7559    v8                            NUMBER;
7560    v9                            NUMBER;
7561    v10                           DATE;
7562    v11                           VARCHAR2(30);
7563 -- HW OPMCONV - Increased to 80 to hold lot_number
7564    v12                           VARCHAR2(80);
7565    v13                           VARCHAR2(30);
7566    v14                           VARCHAR2(30);
7567    v15                           VARCHAR2(30);
7568    v16                           VARCHAR2(30);
7569    v17                           NUMBER;
7570    v18                           VARCHAR2(30);
7571    v19                           VARCHAR2(30);
7572    v20                           VARCHAR2(150);
7573    v21                           VARCHAR2(150);
7574    v22                           VARCHAR2(150);
7575    v23                           VARCHAR2(150);
7576    v24                           VARCHAR2(150);
7577    v25                           VARCHAR2(150);
7578    v26                           VARCHAR2(150);
7579    v27                           VARCHAR2(150);
7580    v28                           VARCHAR2(150);
7581    v29                           VARCHAR2(150);
7582    v30                           VARCHAR2(150);
7583    v31                           VARCHAR2(150);
7584    v32                           VARCHAR2(150);
7585    v33                           VARCHAR2(150);
7586    v34                           VARCHAR2(150);
7587    v35                           VARCHAR2(3);
7588    l_index                       NUMBER;
7589    l_det_index                   NUMBER;
7590    l_detail_ser_count            NUMBER;
7591    l_detail_ser_qty              NUMBER;
7592    l_det_ser_range_tab           WSH_GLBL_VAR_STRCT_GRP.ddSerialRangeTabType;
7593    l_update_attributes           BOOLEAN;
7594    l_stamp_ser_wdd               BOOLEAN; -- frontport bug 5055682
7595 
7596    -- bug 4766908
7597    l_reservable_flag        VARCHAR2(1);
7598    -- end bug 4766908
7599    l_trx_type_id                 NUMBER;
7600    CURSOR get_group_mark_id (v_serial_number IN VARCHAR2, v_item_id IN NUMBER) IS
7601    SELECT group_mark_id
7602    FROM mtl_serial_numbers
7603    WHERE serial_number = v_serial_number
7604    AND inventory_item_id = v_item_id;
7605    --
7606    l_debug_on                    BOOLEAN;
7607    --
7608    l_module_name        CONSTANT VARCHAR2(100)
7609                := 'wsh.plsql.' || g_pkg_name || '.' || 'VALIDATE_DETAIL_LINE';
7610 
7611  --added cursor to fetch lpn_id for bug 12597783.
7612 
7613  CURSOR get_lpn_id IS
7614     SELECT  wdd.lpn_id
7615 	FROM    wsh_delivery_details wdd
7616 		   ,wsh_delivery_assignments wda
7617 	WHERE   wdd.delivery_detail_id = wda.parent_delivery_detail_id
7618 	AND     wda.delivery_detail_id = x_detail_rec.delivery_detail_id
7619 	AND     wdd.container_flag = 'Y';
7620 
7621 --
7622 BEGIN
7623    --
7624    l_debug_on := wsh_debug_interface.g_debug;
7625 
7626    --
7627    IF l_debug_on IS NULL THEN
7628       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
7629    END IF;
7630 
7631    --
7632    SAVEPOINT validate_det_line_grp;
7633 
7634    --bug 12597783
7635 
7636      l_wms_installed := wsh_util_validate.Check_Wms_Org(x_detail_rec.organization_id);
7637 
7638      IF (l_wms_installed = 'Y') THEN
7639          OPEN get_lpn_id;
7640          FETCH get_lpn_id INTO l_lpn_id;
7641          CLOSE get_lpn_id;
7642      END IF;
7643 
7644    --bug 12597783
7645 
7646    IF l_debug_on THEN
7647       WSH_DEBUG_SV.push(l_module_name);
7648 	  WSH_DEBUG_SV.LOG(l_module_name, 'l_wms_installed', l_wms_installed);
7649 	  WSH_DEBUG_SV.LOG(l_module_name, 'l_lpn_id', l_lpn_id);
7650       WSH_DEBUG_SV.LOG(l_module_name, 'Delivery Detail Id', x_detail_rec.delivery_detail_id);
7651       WSH_DEBUG_SV.LOG(l_module_name, 'Serial table count', p_serial_range_tab.COUNT);
7652       WSH_DEBUG_SV.LOG(l_module_name, 'SQ', x_detail_rec.shipped_quantity);
7653    END IF;
7654 
7655    --  Initialize API return status to success --
7656    x_return_status := wsh_util_core.g_ret_sts_success;
7657    l_number_of_errors := 0;
7658    l_number_of_warnings := 0;
7659 
7660    --
7661    -- J-IB-NPARIKH-{
7662    IF NVL(x_detail_rec.line_direction,'O') NOT IN ('O','IO')
7663    THEN
7664    --{
7665         --
7666         -- None of the validations are applicable for inbound lines. So, return
7667         --
7668         IF l_debug_on
7669         THEN
7670             wsh_debug_sv.pop(l_module_name);
7671         END IF;
7672         --
7673         RETURN;
7674    --}
7675    END IF;
7676    -- J-IB-NPARIKH-}
7677    --
7678 
7679 -- HW Harmonization project for OPM. Need to check if org is discrete or process
7680 -- HW OPMCONV - Removed checking for process org
7681 
7682    IF (p_validation_tab(wsh_actions_levels.c_tol_above_lvl) = 1) THEN
7683       IF l_debug_on THEN
7684          WSH_DEBUG_SV.log(l_module_name, 'Ship Tolerance Above', x_detail_rec.ship_tolerance_above);
7685          WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_NEGATIVE',
7686             WSH_DEBUG_SV.c_proc_level);
7687       END IF;
7688 
7689   --Bug # 3266333
7690       wsh_util_validate.validate_negative(
7691          p_value          =>  x_detail_rec.ship_tolerance_above,
7692 	 p_field_name     => 'ship_tolerance_above',
7693 	 x_return_status  => l_return_status );
7694   --
7695 
7696       wsh_util_core.api_post_call(
7697          p_return_status      => l_return_status,
7698          x_num_warnings       => l_number_of_warnings,
7699          x_num_errors         => l_number_of_errors,
7700          p_msg_data           => l_msg_data
7701       );
7702    END IF;
7703 
7704    IF (p_validation_tab(wsh_actions_levels.c_tol_below_lvl) = 1) THEN
7705       IF l_debug_on THEN
7706          WSH_DEBUG_SV.log(l_module_name, 'Ship Tolerance Below', x_detail_rec.ship_tolerance_below);
7707          WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_NEGATIVE',WSH_DEBUG_SV.c_proc_level);
7708       END IF;
7709 
7710   --Bug # 3266333
7711       wsh_util_validate.validate_negative(
7712          p_value          =>  x_detail_rec.ship_tolerance_below,
7713 	 p_field_name     => 'ship_tolerance_below',
7714 	 x_return_status  => l_return_status );
7715   --
7716 
7717       wsh_util_core.api_post_call(
7718          p_return_status      => l_return_status,
7719          x_num_warnings       => l_number_of_warnings,
7720          x_num_errors         => l_number_of_errors,
7721          p_msg_data           => l_msg_data
7722       );
7723    END IF;
7724 
7725    IF l_debug_on THEN
7726       WSH_DEBUG_SV.log(l_module_name, 'x_detail_rec.org_id', x_detail_rec.org_id);
7727       WSH_DEBUG_SV.log(l_module_name, 'x_detail_rec.locator_id', x_detail_rec.locator_id);
7728       WSH_DEBUG_SV.log(l_module_name, 'x_detail_rec.revision', x_detail_rec.revision);
7729       WSH_DEBUG_SV.log(l_module_name, 'x_detail_rec.subinventory', x_detail_rec.subinventory);
7730       WSH_DEBUG_SV.log(l_module_name, 'x_detail_rec.lot_number', x_detail_rec.lot_number);
7731    END IF;
7732 
7733    l_org_id := p_original_rec.organization_id;
7734 
7735    /***************Material Status Impact***********/
7736    WSH_DELIVERY_DETAILS_INV.get_trx_type_id(
7737      p_source_line_id => x_detail_rec.source_line_id, --RTV changes
7738      p_source_code    => x_detail_rec.source_code,    --RTV changes
7739      x_transaction_type_id    => l_trx_type_id,
7740      x_return_status  => l_return_status);
7741    --
7742    wsh_util_core.api_post_call(
7743      p_return_status      => l_return_status,
7744      x_num_warnings       => l_number_of_warnings,
7745      x_num_errors         => l_number_of_errors,
7746      p_msg_data           => l_msg_data);
7747    /***************Material Status Impact***********/
7748 
7749    IF x_detail_rec.locator_id <> fnd_api.g_miss_num THEN
7750       l_locator := x_detail_rec.locator_id;
7751    -- Modified Else condition for bug 4399278, 4418754
7752    ELSIF ( x_detail_rec.subinventory = p_original_rec.subinventory ) THEN
7753       l_locator := p_original_rec.locator_id;
7754    END IF;
7755 
7756    IF x_detail_rec.revision <> fnd_api.g_miss_char THEN
7757       l_revision := x_detail_rec.revision;
7758    ELSE
7759       l_revision := p_original_rec.revision;
7760    END IF;
7761 
7762    IF x_detail_rec.subinventory <> fnd_api.g_miss_char THEN
7763       l_subinventory := x_detail_rec.subinventory;
7764    ELSE
7765       l_subinventory := p_original_rec.subinventory;
7766    END IF;
7767 
7768    IF x_detail_rec.lot_number <> fnd_api.g_miss_char THEN
7769       l_lot := x_detail_rec.lot_number;
7770    ELSE
7771       l_lot := p_original_rec.lot_number;
7772    END IF;
7773 
7774    IF l_debug_on THEN
7775       WSH_DEBUG_SV.log(l_module_name, 'l_org_id', l_org_id);
7776       WSH_DEBUG_SV.log(l_module_name, 'l_locator', l_locator);
7777       WSH_DEBUG_SV.log(l_module_name, 'l_revision', l_revision);
7778       WSH_DEBUG_SV.log(l_module_name, 'l_subinventory', l_subinventory);
7779       WSH_DEBUG_SV.log(l_module_name, 'l_lot_number', l_lot);
7780    END IF;
7781 
7782    -- UT bug fix 2657367
7783    IF    p_validation_tab(wsh_actions_levels.c_ship_qty_lvl) = 1
7784       OR p_validation_tab(wsh_actions_levels.c_revision_lvl) = 1
7785       OR p_validation_tab(wsh_actions_levels.c_locator_lvl) = 1
7786       OR p_validation_tab(wsh_actions_levels.c_lot_number_lvl) = 1
7787       OR p_validation_tab(wsh_actions_levels.c_serial_num_lvl) = 1
7788    THEN
7789    --(
7790       IF l_debug_on THEN
7791          WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DELIVERY_DETAILS_INV.FETCH_INV_CONTROLS', WSH_DEBUG_SV.c_proc_level);
7792       END IF;
7793 
7794       wsh_delivery_details_inv.fetch_inv_controls(
7795          p_delivery_detail_id      => x_detail_rec.delivery_detail_id,
7796          p_inventory_item_id       => p_original_rec.inventory_item_id,
7797          p_organization_id         => l_org_id,
7798          p_subinventory            => l_subinventory,
7799          x_inv_controls_rec        => l_inv_controls,
7800          x_return_status           => l_return_status
7801       );
7802 
7803       IF l_debug_on THEN
7804          WSH_DEBUG_SV.log(l_module_name, 'Return Status', l_return_status);
7805          WSH_DEBUG_SV.log(l_module_name, 'Lot Flag', l_inv_controls.lot_flag);
7806          WSH_DEBUG_SV.log(l_module_name, 'Revision Flag', l_inv_controls.rev_flag);
7807          WSH_DEBUG_SV.log(l_module_name, 'Locator Flag', l_inv_controls.loc_flag);
7808          WSH_DEBUG_SV.log(l_module_name, 'Serial Control Code', l_inv_controls.serial_code);
7809       END IF;
7810 
7811       wsh_util_core.api_post_call(
7812          p_return_status      => l_return_status,
7813          x_num_warnings       => l_number_of_warnings,
7814          x_num_errors         => l_number_of_errors,
7815          p_msg_data           => l_msg_data
7816       );
7817    --)
7818    END IF;
7819 
7820    -- UT bug fix 2657367
7821 
7822    IF (p_validation_tab(wsh_actions_levels.c_ship_qty_lvl) = 1) THEN
7823       IF l_debug_on THEN
7824          WSH_DEBUG_SV.log(l_module_name, 'Shipped Qty', x_detail_rec.shipped_quantity);
7825          WSH_DEBUG_SV.log(l_module_name, 'Existing Shipped Qty', p_original_rec.shipped_quantity);
7826       END IF;
7827       -- BugFix 4519867: Validate shipped qty only when it's not equal to fnd_api.g_miss_num.
7828       IF ((p_in_detail_rec.shipped_quantity IS NULL )
7829           OR (p_in_detail_rec.shipped_quantity <> fnd_api.g_miss_num))
7830       THEN
7831               l_det_qty_rec.delivery_detail_id := x_detail_rec.delivery_detail_id;
7832               l_det_qty_rec.requested_quantity := x_detail_rec.requested_quantity;
7833               l_det_qty_rec.requested_quantity2 := x_detail_rec.requested_quantity2;
7834               l_det_qty_rec.picked_quantity := x_detail_rec.picked_quantity;
7835               l_det_qty_rec.picked_quantity2 := x_detail_rec.picked_quantity2;
7836               l_det_qty_rec.shipped_quantity := x_detail_rec.shipped_quantity;
7837               l_det_qty_rec.shipped_quantity2 := x_detail_rec.shipped_quantity2;
7838               l_det_qty_rec.cycle_count_quantity := x_detail_rec.cycle_count_quantity;
7839               l_det_qty_rec.cycle_count_quantity2 :=
7840                                                     x_detail_rec.cycle_count_quantity2;
7841               l_det_qty_rec.requested_quantity_uom :=
7842                                                    x_detail_rec.requested_quantity_uom;
7843               l_det_qty_rec.requested_quantity_uom2 :=
7844                                                   x_detail_rec.requested_quantity_uom2;
7845               l_det_qty_rec.ship_tolerance_above := x_detail_rec.ship_tolerance_above;
7846               l_det_qty_rec.inventory_item_id := x_detail_rec.inventory_item_id;
7847               l_det_qty_rec.organization_id := x_detail_rec.organization_id;
7848               l_det_qty_rec.serial_number := p_original_rec.serial_number;
7849               l_det_qty_rec.transaction_temp_id := p_original_rec.transaction_temp_id; -- Bug fix 2652300
7850               l_det_qty_rec.top_model_line_id := p_original_rec.top_model_line_id; -- Bug fix 2652300
7851               l_det_qty_rec.inv_ser_control_code := l_inv_controls.serial_code;               -- Bug fix 2652300
7852         -- HW Harmonization for OPM. Use l_process_flag
7853         -- HW OPMCONV - Removed checking for process org and population of
7854         -- process org variable
7855 
7856                 get_serial_quantity(
7857                  p_transaction_temp_id      => p_original_rec.transaction_temp_id,
7858                  p_serial_number            => p_original_rec.serial_number,
7859                  p_to_serial_number         => p_original_rec.to_serial_number,
7860                  p_shipped_quantity         => x_detail_rec.shipped_quantity,
7861                  x_serial_qty               => l_det_qty_rec.serial_quantity,
7862                  x_return_status            => l_return_status
7863                  );
7864 
7865                 IF l_debug_on THEN
7866                    WSH_DEBUG_SV.log(l_module_name, 'get serial qty status', l_return_status);
7867                    WSH_DEBUG_SV.log(l_module_name, 'Serial qty', l_det_qty_rec.serial_quantity);
7868                    WSH_DEBUG_SV.log(l_module_name, 'Serial Number', l_det_qty_rec.serial_number);
7869                    WSH_DEBUG_SV.log(l_module_name, 'Trans temp id', l_det_qty_rec.transaction_temp_id);
7870                    WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DETAILS_VALIDATIONS.VALIDATE_SHIPPED_CC_QUANTITY', WSH_DEBUG_SV.c_proc_level);
7871                 END IF;
7872 
7873               --
7874               wsh_details_validations.validate_shipped_cc_quantity(
7875                  p_flag               => 'SQ',
7876                  x_det_rec            => l_det_qty_rec,
7877                  x_return_status      => l_return_status,
7878                  x_msg_count          => l_msg_count,
7879                  x_msg_data           => l_msg_data
7880               );
7881               x_detail_rec.shipped_quantity := l_det_qty_rec.shipped_quantity;
7882               -- x_detail_rec.cycle_count_quantity := l_det_qty_rec.cycle_count_quantity;
7883 
7884               -- Bug 5466481: First consider the passed cycle count qty,
7885               -- If it is not passed then take the system calculated value.
7886               IF (p_in_detail_rec.cycle_count_quantity = fnd_api.g_miss_num) THEN
7887               --{
7888                 x_detail_rec.cycle_count_quantity := l_det_qty_rec.cycle_count_quantity;
7889               ELSE
7890                 x_detail_rec.cycle_count_quantity := p_in_detail_rec.cycle_count_quantity;
7891               --}
7892               END IF;
7893 
7894               --
7895               wsh_util_core.api_post_call(
7896                  p_return_status      => l_return_status,
7897                  x_num_warnings       => l_number_of_warnings,
7898                  x_num_errors         => l_number_of_errors,
7899                  p_msg_data           => l_msg_data
7900               );
7901       END IF; -- End of code BugFix 4519867
7902    END IF;
7903 
7904 -- HW Harmonization project for OPM.
7905 -- HW OPMCONV - Removed checking for process_flag
7906 
7907       IF (p_validation_tab(wsh_actions_levels.c_ship_qty2_lvl) = 1) THEN
7908          IF (x_detail_rec.shipped_quantity2 <> fnd_api.g_miss_num) THEN
7909             l_det_qty_rec.delivery_detail_id :=
7910                                               x_detail_rec.delivery_detail_id;
7911             l_det_qty_rec.requested_quantity :=
7912                                               x_detail_rec.requested_quantity;
7913             l_det_qty_rec.requested_quantity2 :=
7914                                              x_detail_rec.requested_quantity2;
7915             l_det_qty_rec.picked_quantity := x_detail_rec.picked_quantity;
7916             l_det_qty_rec.picked_quantity2 := x_detail_rec.picked_quantity2;
7917             l_det_qty_rec.shipped_quantity := x_detail_rec.shipped_quantity;
7918             l_det_qty_rec.shipped_quantity2 := x_detail_rec.shipped_quantity2;
7919             l_det_qty_rec.cycle_count_quantity :=
7920                                             x_detail_rec.cycle_count_quantity;
7921             l_det_qty_rec.cycle_count_quantity2 :=
7922                                            x_detail_rec.cycle_count_quantity2;
7923             l_det_qty_rec.requested_quantity_uom :=
7924                                           x_detail_rec.requested_quantity_uom;
7925             l_det_qty_rec.requested_quantity_uom2 :=
7926                                          x_detail_rec.requested_quantity_uom2;
7927             l_det_qty_rec.ship_tolerance_above :=
7928                                             x_detail_rec.ship_tolerance_above;
7929             l_det_qty_rec.inventory_item_id := x_detail_rec.inventory_item_id;
7930             l_det_qty_rec.organization_id := x_detail_rec.organization_id;
7931             l_det_qty_rec.serial_number := x_detail_rec.serial_number;
7932             l_det_qty_rec.transaction_temp_id :=
7933                                              x_detail_rec.transaction_temp_id;
7934             l_det_qty_rec.top_model_line_id := x_detail_rec.top_model_line_id;
7935 -- HW use l_process_flag
7936 -- HW OPMCONV - Removed population of  process_flag
7937 
7938             IF l_debug_on THEN
7939                WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DETAILS_VALIDATIONS.VALIDATE_SHIPPED_CC_QUANTITY2', WSH_DEBUG_SV.c_proc_level);
7940             END IF;
7941 
7942             --
7943 
7944             wsh_details_validations.validate_shipped_cc_quantity2(
7945                p_flag               => 'SQ',
7946                x_det_rec            => l_det_qty_rec,
7947                x_return_status      => l_return_status,
7948                x_msg_count          => l_msg_count,
7949                x_msg_data           => l_msg_data
7950             );
7951             x_detail_rec.shipped_quantity2 := l_det_qty_rec.shipped_quantity2;
7952             --PK added for Bug 3055126 Next line.
7953             x_detail_rec.cycle_count_quantity2 := l_det_qty_rec.cycle_count_quantity2;
7954             --
7955             wsh_util_core.api_post_call(
7956                p_return_status      => l_return_status,
7957                x_num_warnings       => l_number_of_warnings,
7958                x_num_errors         => l_number_of_errors,
7959                p_msg_data           => l_msg_data
7960             );
7961          END IF; -- of shipped_quantity2
7962       END IF; -- of C_SHIP_QTY2_LVL
7963 
7964 -- HW OPM end of changes
7965 
7966    IF (p_validation_tab(wsh_actions_levels.c_cc_qty_lvl) = 1) THEN
7967       IF l_debug_on THEN
7968          WSH_DEBUG_SV.log(l_module_name, 'Cycle_Count Qty', x_detail_rec.cycle_count_quantity);
7969          WSH_DEBUG_SV.log(l_module_name, 'Existing Cycle_Count Qty', p_original_rec.cycle_count_quantity);
7970       END IF;
7971       -- BugFix 4519867: Validate cycle count qty only when it's not equal to fnd_api.g_miss_num.
7972       IF ( (p_in_detail_rec.cycle_count_quantity IS NULL)
7973          OR (p_in_detail_rec.cycle_count_quantity <> fnd_api.g_miss_num))
7974       THEN
7975               l_det_qty_rec.delivery_detail_id := x_detail_rec.delivery_detail_id;
7976               l_det_qty_rec.requested_quantity := x_detail_rec.requested_quantity;
7977               l_det_qty_rec.requested_quantity2 := x_detail_rec.requested_quantity2;
7978               l_det_qty_rec.picked_quantity := x_detail_rec.picked_quantity;
7979               l_det_qty_rec.picked_quantity2 := x_detail_rec.picked_quantity2;
7980               l_det_qty_rec.shipped_quantity := x_detail_rec.shipped_quantity;
7981               l_det_qty_rec.shipped_quantity2 := x_detail_rec.shipped_quantity2;
7982               l_det_qty_rec.cycle_count_quantity := x_detail_rec.cycle_count_quantity;
7983               l_det_qty_rec.cycle_count_quantity2 :=
7984                                                     x_detail_rec.cycle_count_quantity2;
7985               l_det_qty_rec.requested_quantity_uom :=
7986                                                    x_detail_rec.requested_quantity_uom;
7987               l_det_qty_rec.requested_quantity_uom2 :=
7988                                                   x_detail_rec.requested_quantity_uom2;
7989               l_det_qty_rec.ship_tolerance_above := x_detail_rec.ship_tolerance_above;
7990               l_det_qty_rec.inventory_item_id := x_detail_rec.inventory_item_id;
7991               l_det_qty_rec.organization_id := x_detail_rec.organization_id;
7992               l_det_qty_rec.serial_number := x_detail_rec.serial_number;
7993               l_det_qty_rec.transaction_temp_id := x_detail_rec.transaction_temp_id;
7994               l_det_qty_rec.top_model_line_id := x_detail_rec.top_model_line_id;
7995         -- HW Harmonization project for OPM.Use l_process_flag
7996         -- HW OPMCONV - Removed populatation of process_flag
7997 
7998               --
7999               IF l_debug_on THEN
8000                  WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DETAILS_VALIDATIONS.VALIDATE_SHIPPED_CC_QUANTITY', WSH_DEBUG_SV.c_proc_level);
8001               END IF;
8002 
8003               --
8004               wsh_details_validations.validate_shipped_cc_quantity(
8005                  p_flag               => 'CCQ',
8006                  x_det_rec            => l_det_qty_rec,
8007                  x_return_status      => l_return_status,
8008                  x_msg_count          => l_msg_count,
8009                  x_msg_data           => l_msg_data
8010               );
8011               x_detail_rec.cycle_count_quantity := l_det_qty_rec.cycle_count_quantity;
8012 
8013               --
8014               wsh_util_core.api_post_call(
8015                  p_return_status      => l_return_status,
8016                  x_num_warnings       => l_number_of_warnings,
8017                  x_num_errors         => l_number_of_errors,
8018                  p_msg_data           => l_msg_data
8019               );
8020       END IF; -- BugFix 4519867
8021    END IF;
8022 
8023 -- HW Harmonization project for OPM. Added cycle_count_qty2
8024 -- HW OPMCONV - Removed checking for process_flag
8025 
8026       IF (p_validation_tab(wsh_actions_levels.c_cc_qty2_lvl) = 1) THEN
8027          IF (x_detail_rec.cycle_count_quantity2 <> fnd_api.g_miss_num) THEN
8028             l_det_qty_rec.delivery_detail_id :=
8029                                               x_detail_rec.delivery_detail_id;
8030             l_det_qty_rec.requested_quantity :=
8031                                               x_detail_rec.requested_quantity;
8032             l_det_qty_rec.requested_quantity2 :=
8033                                              x_detail_rec.requested_quantity2;
8034             l_det_qty_rec.picked_quantity := x_detail_rec.picked_quantity;
8035             l_det_qty_rec.picked_quantity2 := x_detail_rec.picked_quantity2;
8036             l_det_qty_rec.shipped_quantity := x_detail_rec.shipped_quantity;
8037             l_det_qty_rec.shipped_quantity2 := x_detail_rec.shipped_quantity2;
8038             l_det_qty_rec.cycle_count_quantity :=
8039                                             x_detail_rec.cycle_count_quantity;
8040             l_det_qty_rec.cycle_count_quantity2 :=
8041                                            x_detail_rec.cycle_count_quantity2;
8042             l_det_qty_rec.requested_quantity_uom :=
8043                                           x_detail_rec.requested_quantity_uom;
8044             l_det_qty_rec.requested_quantity_uom2 :=
8045                                          x_detail_rec.requested_quantity_uom2;
8046             l_det_qty_rec.ship_tolerance_above :=
8047                                             x_detail_rec.ship_tolerance_above;
8048             l_det_qty_rec.inventory_item_id := x_detail_rec.inventory_item_id;
8049             l_det_qty_rec.organization_id := x_detail_rec.organization_id;
8050             l_det_qty_rec.serial_number := x_detail_rec.serial_number;
8051             l_det_qty_rec.transaction_temp_id :=
8052                                              x_detail_rec.transaction_temp_id;
8053             l_det_qty_rec.top_model_line_id := x_detail_rec.top_model_line_id;
8054 -- HW Harmonization project for OPM. Use l_process_flag
8055 -- HW OPMCONV - Removed population of process_flag
8056 
8057             IF l_debug_on THEN
8058                WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DETAILS_VALIDATIONS.VALIDATE_SHIPPED_CC_QUANTITY2', WSH_DEBUG_SV.c_proc_level);
8059             END IF;
8060 
8061             --
8062             wsh_details_validations.validate_shipped_cc_quantity2(
8063                p_flag               => 'CCQ',
8064                x_det_rec            => l_det_qty_rec,
8065                x_return_status      => l_return_status,
8066                x_msg_count          => l_msg_count,
8067                x_msg_data           => l_msg_data
8068             );
8069             x_detail_rec.cycle_count_quantity2 :=
8070                                            l_det_qty_rec.cycle_count_quantity2;
8071             --
8072             wsh_util_core.api_post_call(
8073                p_return_status      => l_return_status,
8074                x_num_warnings       => l_number_of_warnings,
8075                x_num_errors         => l_number_of_errors,
8076                p_msg_data           => l_msg_data
8077             );
8078          END IF; -- of cycle_count_quantity2
8079       END IF; -- of C_CC_QTY2_LVL
8080 
8081 -- HW OPM end of changes
8082 
8083    IF (p_validation_tab(wsh_actions_levels.c_smc_lvl) = 1) THEN
8084       IF (x_detail_rec.ship_method_code <> fnd_api.g_miss_char) THEN
8085          IF l_debug_on THEN
8086             WSH_DEBUG_SV.log(l_module_name, 'Ship Method', x_detail_rec.ship_method_code);
8087             WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_SHIP_METHOD', WSH_DEBUG_SV.c_proc_level);
8088          END IF;
8089 
8090          --
8091          wsh_util_validate.validate_ship_method(
8092             p_ship_method_code => x_detail_rec.ship_method_code,
8093             p_ship_method_name      => l_ship_method_name,
8094             x_return_status         => l_return_status);
8095          --
8096          wsh_util_core.api_post_call(
8097             p_return_status      => l_return_status,
8098             x_num_warnings       => l_number_of_warnings,
8099             x_num_errors         => l_number_of_errors,
8100             p_msg_data           => l_msg_data
8101          );
8102       END IF;
8103    END IF;
8104 
8105    IF (p_validation_tab(wsh_actions_levels.c_dep_plan_lvl) = 1) THEN
8106       IF (x_detail_rec.dep_plan_required_flag <> fnd_api.g_miss_char) THEN
8107          IF l_debug_on THEN
8108             WSH_DEBUG_SV.log(l_module_name, 'Departure Plan Flag', x_detail_rec.dep_plan_required_flag);
8109             WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_BOOLEAN', WSH_DEBUG_SV.c_proc_level);
8110          END IF;
8111 
8112          --
8113          wsh_util_validate.validate_boolean(
8114             p_flag => x_detail_rec.dep_plan_required_flag,
8115             x_return_status      => l_return_status);
8116          --
8117          wsh_util_core.api_post_call(
8118             p_return_status      => l_return_status,
8119             x_num_warnings       => l_number_of_warnings,
8120             x_num_errors         => l_number_of_errors,
8121             p_msg_data           => l_msg_data
8122          );
8123       END IF;
8124    END IF;
8125 
8126    IF (p_validation_tab(wsh_actions_levels.c_ship_mod_comp_lvl) = 1) THEN
8127       IF (x_detail_rec.ship_model_complete_flag <> fnd_api.g_miss_char) THEN
8128          IF l_debug_on THEN
8129             WSH_DEBUG_SV.log(l_module_name, 'Ship Model Complete Flag', x_detail_rec.ship_model_complete_flag);
8130             WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_BOOLEAN', WSH_DEBUG_SV.c_proc_level);
8131          END IF;
8132 
8133          --
8134          wsh_util_validate.validate_boolean(
8135             p_flag => x_detail_rec.ship_model_complete_flag,
8136             x_return_status      => l_return_status);
8137          --
8138          wsh_util_core.api_post_call(
8139             p_return_status      => l_return_status,
8140             x_num_warnings       => l_number_of_warnings,
8141             x_num_errors         => l_number_of_errors,
8142             p_msg_data           => l_msg_data
8143          );
8144       END IF;
8145    END IF;
8146 
8147    IF (p_validation_tab(wsh_actions_levels.c_sub_inv_lvl) = 1) THEN
8148       IF (x_detail_rec.subinventory <> fnd_api.g_miss_char) THEN
8149          IF l_debug_on THEN
8150             WSH_DEBUG_SV.log(l_module_name, 'Subinventory', x_detail_rec.subinventory);
8151             WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DELIVERY_DETAILS_INV.VALIDATE_SUBINVENTORY', WSH_DEBUG_SV.c_proc_level);
8152          END IF;
8153 
8154          --
8155          wsh_delivery_details_inv.validate_subinventory(
8156             p_subinventory           => x_detail_rec.subinventory,
8157             p_organization_id        => l_org_id,
8158             p_inventory_item_id      => p_original_rec.inventory_item_id,
8159 	    p_transaction_type_id    => l_trx_type_id,
8160 	    p_object_type            => 'A',
8161 	    x_return_status          => l_return_status,
8162             x_result                 => l_result
8163          );
8164          --
8165          IF l_debug_on THEN
8166             WSH_DEBUG_SV.log(l_module_name, 'Result after validate subinventory', l_result);
8167             WSH_DEBUG_SV.log(l_module_name, 'Return status after validate subinventory', l_return_status);
8168          END IF;
8169 
8170          IF NOT l_result THEN
8171             IF l_debug_on THEN
8172                WSH_DEBUG_SV.logmsg(l_module_name, 'Invalid subinventory');
8173             END IF;
8174 
8175             l_return_status := wsh_util_core.g_ret_sts_error;
8176          END IF;
8177 
8178          wsh_util_core.api_post_call(
8179             p_return_status      => l_return_status,
8180             x_num_warnings       => l_number_of_warnings,
8181             x_num_errors         => l_number_of_errors,
8182             p_msg_data           => l_msg_data
8183          );
8184          x_mark_reprice_flag := 'Y';
8185       END IF;
8186    END IF;
8187 
8188    IF (p_validation_tab(wsh_actions_levels.c_revision_lvl) = 1)
8189    THEN
8190    -- {
8191       IF (x_detail_rec.revision <> fnd_api.g_miss_char)
8192       THEN
8193       -- {
8194          -- UT bug fix 2657367
8195          IF l_debug_on THEN
8196             wsh_debug_sv.log(l_module_name, 'Pickable Flag', p_original_rec.pickable_flag);
8197             wsh_debug_sv.log(l_module_name, 'Rev Flag', l_inv_controls.rev_flag);
8198          END IF;
8199          --
8200          IF p_original_rec.pickable_flag = 'N'
8201          THEN
8202          -- {
8203              IF l_inv_controls.rev_flag = 'N'
8204                 AND x_detail_rec.revision IS NOT NULL
8205              THEN
8206                l_number_of_errors := l_number_of_errors + 1;
8207                RAISE FND_API.G_EXC_ERROR;
8208              END IF;
8209          ELSE
8210              IF l_debug_on THEN
8211                WSH_DEBUG_SV.log(l_module_name, 'Revision', x_detail_rec.revision);
8212                WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DELIVERY_DETAILS_INV.VALIDATE_REVISION', WSH_DEBUG_SV.c_proc_level);
8213              END IF;
8214 
8215              wsh_delivery_details_inv.validate_revision(
8216                p_revision               => x_detail_rec.revision,
8217                p_organization_id        => l_org_id,
8218                p_inventory_item_id      => p_original_rec.inventory_item_id,
8219                x_return_status          => l_return_status,
8220                x_result                 => l_result
8221                );
8222 
8223          -- Bug fix   2657367. Need to check l_result
8224          IF l_debug_on THEN
8225             WSH_DEBUG_SV.log(l_module_name, 'Result after validate revision', l_result);
8226             WSH_DEBUG_SV.log(l_module_name, 'Return status after validate revision', l_return_status);
8227          END IF;
8228 
8229          IF NOT l_result THEN
8230             IF l_debug_on THEN
8231                WSH_DEBUG_SV.logmsg(l_module_name, 'Invalid Revision');
8232             END IF;
8233 
8234             RAISE fnd_api.g_exc_error;
8235          END IF;
8236 
8237          wsh_util_core.api_post_call(
8238             p_return_status      => l_return_status,
8239             x_num_warnings       => l_number_of_warnings,
8240             x_num_errors         => l_number_of_errors,
8241             p_msg_data           => l_msg_data
8242          );
8243          -- }
8244          END IF;
8245       -- }
8246       END IF;
8247    -- }
8248    END IF;
8249 
8250    IF (p_validation_tab(wsh_actions_levels.c_locator_lvl) = 1) THEN
8251       IF (x_detail_rec.locator_id <> fnd_api.g_miss_num)
8252       THEN
8253       -- {
8254           -- UT bug fix 2657367
8255          IF l_debug_on THEN
8256             wsh_debug_sv.log(l_module_name, 'Pickable Flag', p_original_rec.pickable_flag);
8257             wsh_debug_sv.log(l_module_name, 'Locator Flag', l_inv_controls.loc_flag);
8258          END IF;
8259          --
8260           IF  p_original_rec.pickable_flag  = 'N'
8261           THEN
8262           -- {
8263              IF l_inv_controls.loc_flag = 'N'
8264                 AND x_detail_rec.locator_id IS NOT NULL
8265              THEN
8266                 l_number_of_errors := l_number_of_errors + 1;
8267                 RAISE FND_API.G_EXC_ERROR;
8268              END IF;
8269           ELSE
8270 
8271              IF l_debug_on THEN
8272                 WSH_DEBUG_SV.log(l_module_name, 'Locator Id', x_detail_rec.locator_id);
8273                 WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DELIVERY_DETAILS_INV.VALIDATE_LOCATOR', WSH_DEBUG_SV.c_proc_level);
8274             END IF;
8275             wsh_delivery_details_inv.validate_locator(
8276                p_locator_id             => x_detail_rec.locator_id,
8277                p_organization_id        => l_org_id,
8278                p_inventory_item_id      => p_original_rec.inventory_item_id,
8279                p_subinventory           => l_subinventory,
8280 	       p_transaction_type_id    => l_trx_type_id,
8281 	       p_object_type            => 'A',
8282                x_return_status          => l_return_status,
8283                x_result                 => l_result
8284                );
8285 
8286             -- Bug fix   2657367. Need to check l_result
8287             IF l_debug_on THEN
8288                WSH_DEBUG_SV.log(l_module_name, 'Result after validate locator', l_result);
8289                WSH_DEBUG_SV.log(l_module_name, 'Return status after validate locator', l_return_status);
8290             END IF;
8291 
8292             IF NOT l_result THEN
8293               IF l_debug_on THEN
8294                  WSH_DEBUG_SV.logmsg(l_module_name, 'Invalid Locator');
8295               END IF;
8296 
8297               RAISE fnd_api.g_exc_error;
8298             END IF;
8299 
8300             --
8301             wsh_util_core.api_post_call(
8302                p_return_status      => l_return_status,
8303                x_num_warnings       => l_number_of_warnings,
8304                x_num_errors         => l_number_of_errors,
8305                p_msg_data           => l_msg_data
8306                );
8307           -- }
8308           END IF;
8309       -- }
8310       END IF;
8311     END IF;
8312 
8313    IF (p_validation_tab(wsh_actions_levels.c_lot_number_lvl) = 1) AND
8314        p_original_rec.inv_interfaced_flag NOT IN ('Y','X')   THEN -- Added for bug 13574503
8315       IF (x_detail_rec.lot_number <> fnd_api.g_miss_char) THEN
8316 -- HW Harmonization project for OPM. Need to branch
8317 -- HW OPMCONV - Removed branching
8318 
8319             -- UT bug fix 2657367
8320                  IF l_debug_on THEN
8321                     WSH_DEBUG_SV.log(l_module_name, 'Lot Number', x_detail_rec.lot_number);
8322                     wsh_debug_sv.log(l_module_name, 'Pickable Flag', p_original_rec.pickable_flag);
8323                     wsh_debug_sv.log(l_module_name, 'Lot Flag', l_inv_controls.lot_flag);
8324                  END IF;
8325                   --
8326                   IF nvl(p_original_rec.pickable_flag, 'N') = 'N'
8327                   THEN
8328                   -- {
8329                       IF l_inv_controls.lot_flag = 'N'
8330                          AND x_detail_rec.lot_number IS NOT NULL
8331                       THEN
8332                          -- For non-transactable items, lot number cannot be updated if item is not under lot control
8333                           l_number_of_errors := l_number_of_errors + 1;
8334                           RAISE FND_API.G_EXC_ERROR;
8335                      END IF;
8336                   ELSE
8337                     -- bug 4766908 get the reservable_flag
8338                     IF p_original_rec.released_status = 'Y' THEN
8339                       l_reservable_flag := WSH_DELIVERY_DETAILS_INV.get_reservable_flag(
8340                                                x_item_id         => p_original_rec.inventory_item_id,
8341                                                x_organization_id => p_original_rec.organization_id,
8342                                                x_pickable_flag   => p_original_rec.pickable_flag);
8343                     END IF;
8344                     IF (nvl(l_reservable_flag, 'Y') = 'Y') THEN
8345                       IF l_debug_on THEN
8346                          WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DELIVERY_DETAILS_INV.VALIDATE_LOT_NUMBER', WSH_DEBUG_SV.c_proc_level);
8347                       END IF;
8348 
8349                       wsh_delivery_details_inv.validate_lot_number(
8350                           p_lot_number             => x_detail_rec.lot_number,
8351                           p_organization_id        => l_org_id,
8352                           p_inventory_item_id      => p_original_rec.inventory_item_id,
8353                           p_revision               => l_revision,
8354                           p_subinventory           => l_subinventory,
8355                           p_locator_id             => l_locator,
8356 	  	          p_transaction_type_id    => l_trx_type_id,
8357 	                  p_object_type            => 'A',
8358                       p_lpn_id                 => l_lpn_id,                  --bug 12597783
8359                           x_return_status          => l_return_status,
8360                           x_result                 => l_result
8361                            );
8362 
8363                        -- Bug fix   2657367. Need to check l_result
8364                       IF l_debug_on THEN
8365                           WSH_DEBUG_SV.log(l_module_name, 'Result after validate lot', l_result);
8366                           WSH_DEBUG_SV.log(l_module_name, 'Return status after validate lot', l_return_status);
8367                       END IF;
8368 
8369                       IF NOT l_result THEN
8370                          IF l_debug_on THEN
8371                             WSH_DEBUG_SV.logmsg(l_module_name, 'Invalid Lot Number');
8372                          END IF;
8373 
8374                          RAISE fnd_api.g_exc_error;
8375                       END IF;
8376                     END IF;
8377                   -- }
8378                   END IF;
8379 -- HW OPMCONV - Removed branching
8380 
8381 -- HW OPM end of changes
8382 
8383          --
8384          wsh_util_core.api_post_call(
8385             p_return_status      => l_return_status,
8386             x_num_warnings       => l_number_of_warnings,
8387             x_num_errors         => l_number_of_errors,
8388             p_msg_data           => l_msg_data
8389          );
8390       END IF;
8391    END IF;
8392 
8393 /* Since we are updating by delivery_detail, make sure source_line_id is populated */
8394    x_detail_rec.source_line_id := p_original_rec.source_line_id;
8395 
8396    IF (p_validation_tab(wsh_actions_levels.c_sold_contact_lvl) = 1) THEN
8397       IF (x_detail_rec.sold_to_contact_id <> fnd_api.g_miss_num) THEN
8398          IF l_debug_on THEN
8399             WSH_DEBUG_SV.log(l_module_name, 'Sold to Contact', x_detail_rec.sold_to_contact_id);
8400             WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_CONTACT', WSH_DEBUG_SV.c_proc_level);
8401          END IF;
8402 
8403          --
8404          wsh_util_validate.validate_contact(
8405             p_contact_id => x_detail_rec.sold_to_contact_id,
8406             x_return_status      => l_return_status);
8407          wsh_util_core.api_post_call(
8408             p_return_status      => l_return_status,
8409             x_num_warnings       => l_number_of_warnings,
8410             x_num_errors         => l_number_of_errors,
8411             p_msg_data           => l_msg_data
8412          );
8413       END IF;
8414    END IF;
8415 
8416    IF (p_validation_tab(wsh_actions_levels.c_ship_contact_lvl) = 1) THEN
8417       IF (x_detail_rec.ship_to_contact_id <> fnd_api.g_miss_num) THEN
8418          IF l_debug_on THEN
8419             WSH_DEBUG_SV.log(l_module_name, 'Ship to Contact Id', x_detail_rec.ship_to_contact_id);
8420             WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_CONTACT', WSH_DEBUG_SV.c_proc_level);
8421          END IF;
8422 
8423          --
8424          wsh_util_validate.validate_contact(
8425             p_contact_id => x_detail_rec.ship_to_contact_id,
8426             x_return_status      => l_return_status);
8427          --
8428          wsh_util_core.api_post_call(
8429             p_return_status      => l_return_status,
8430             x_num_warnings       => l_number_of_warnings,
8431             x_num_errors         => l_number_of_errors,
8432             p_msg_data           => l_msg_data
8433          );
8434       END IF;
8435    END IF;
8436 
8437    IF (p_validation_tab(wsh_actions_levels.c_deliver_contact_lvl) = 1) THEN
8438       IF (x_detail_rec.deliver_to_contact_id <> fnd_api.g_miss_num) THEN
8439          IF l_debug_on THEN
8440             WSH_DEBUG_SV.log(l_module_name, 'Deliver To Contact', x_detail_rec.deliver_to_contact_id);
8441             WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_CONTACT', WSH_DEBUG_SV.c_proc_level);
8442          END IF;
8443 
8444          --
8445          wsh_util_validate.validate_contact(
8446             p_contact_id => x_detail_rec.deliver_to_contact_id,
8447             x_return_status      => l_return_status);
8448          --
8449          wsh_util_core.api_post_call(
8450             p_return_status      => l_return_status,
8451             x_num_warnings       => l_number_of_warnings,
8452             x_num_errors         => l_number_of_errors,
8453             p_msg_data           => l_msg_data
8454          );
8455       END IF;
8456    END IF;
8457 
8458    IF (p_validation_tab(wsh_actions_levels.c_intmed_ship_contact_lvl) = 1) THEN
8459       IF (x_detail_rec.intmed_ship_to_contact_id <> fnd_api.g_miss_num) THEN
8460          IF l_debug_on THEN
8461             WSH_DEBUG_SV.log(l_module_name, 'Intmed Ship To Contact', x_detail_rec.intmed_ship_to_contact_id);
8462             WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_CONTACT', WSH_DEBUG_SV.c_proc_level);
8463          END IF;
8464 
8465          --
8466          wsh_util_validate.validate_contact(
8467             p_contact_id => x_detail_rec.intmed_ship_to_contact_id,
8468             x_return_status      => l_return_status);
8469          --
8470          wsh_util_core.api_post_call(
8471             p_return_status      => l_return_status,
8472             x_num_warnings       => l_number_of_warnings,
8473             x_num_errors         => l_number_of_errors,
8474             p_msg_data           => l_msg_data
8475          );
8476       END IF;
8477    END IF;
8478 
8479 -- HW Harmonization project for OPM. This is applicable for discrete only
8480 -- added a check for l_process_flag
8481    IF (p_validation_tab(wsh_actions_levels.c_serial_num_lvl) = 1) THEN
8482       l_detail_ser_count := 0;
8483       l_detail_ser_qty := 0;
8484       l_index := p_serial_range_tab.FIRST;
8485       l_det_index := 1;
8486       l_update_attributes := FALSE;
8487       l_stamp_ser_wdd     := FALSE;
8488       WHILE l_index IS NOT NULL LOOP
8489          IF p_serial_range_tab(l_index).delivery_detail_id =
8490                                               x_detail_rec.delivery_detail_id THEN
8491 
8492 
8493             l_det_ser_range_tab(l_det_index).delivery_detail_id := p_serial_range_tab(l_index).delivery_detail_id;
8494             l_det_ser_range_tab(l_det_index).from_serial_number := p_serial_range_tab(l_index).from_serial_number;
8495 
8496             -- If to_serial_number is null or is g_miss_char,
8497             -- then default it to from_serial_number
8498             IF ( p_serial_range_tab(l_index).to_serial_number IS NULL ) OR
8499                ( p_serial_range_tab(l_index).to_serial_number =
8500                                   fnd_api.g_miss_char ) THEN
8501                  l_det_ser_range_tab(l_det_index).to_serial_number
8502                            := p_serial_range_tab(l_index).from_serial_number;
8503             ELSE
8504                  l_det_ser_range_tab(l_det_index).to_serial_number
8505                            := p_serial_range_tab(l_index).to_serial_number;
8506             END IF;
8507 
8508             l_det_ser_range_tab(l_det_index).quantity           := p_serial_range_tab(l_index).quantity;
8509 
8510             l_detail_ser_qty := l_detail_ser_qty + p_serial_range_tab(l_index).quantity;
8511             -- Bug 3628620, populate msnt flexfield attributes if the from/to serial numbers
8512             -- are the same.
8513             IF NVL(l_det_ser_range_tab(l_det_index).to_serial_number, l_det_ser_range_tab(l_det_index).from_serial_number)  =
8514                l_det_ser_range_tab(l_det_index).from_serial_number
8515             THEN
8516                l_det_ser_range_tab(l_det_index).attribute_category := p_serial_range_tab(l_index).attribute_category;
8517                l_det_ser_range_tab(l_det_index).attribute1 := p_serial_range_tab(l_index).attribute1;
8518                l_det_ser_range_tab(l_det_index).attribute2 := p_serial_range_tab(l_index).attribute2;
8519                l_det_ser_range_tab(l_det_index).attribute3 := p_serial_range_tab(l_index).attribute3;
8520                l_det_ser_range_tab(l_det_index).attribute4 := p_serial_range_tab(l_index).attribute4;
8521                l_det_ser_range_tab(l_det_index).attribute5 := p_serial_range_tab(l_index).attribute5;
8522                l_det_ser_range_tab(l_det_index).attribute6 := p_serial_range_tab(l_index).attribute6;
8523                l_det_ser_range_tab(l_det_index).attribute7 := p_serial_range_tab(l_index).attribute7;
8524                l_det_ser_range_tab(l_det_index).attribute8 := p_serial_range_tab(l_index).attribute8;
8525                l_det_ser_range_tab(l_det_index).attribute9 := p_serial_range_tab(l_index).attribute9;
8526                l_det_ser_range_tab(l_det_index).attribute10 := p_serial_range_tab(l_index).attribute10;
8527                l_det_ser_range_tab(l_det_index).attribute11 := p_serial_range_tab(l_index).attribute11;
8528                l_det_ser_range_tab(l_det_index).attribute12 := p_serial_range_tab(l_index).attribute12;
8529                l_det_ser_range_tab(l_det_index).attribute13 := p_serial_range_tab(l_index).attribute13;
8530                l_det_ser_range_tab(l_det_index).attribute14 := p_serial_range_tab(l_index).attribute14;
8531                l_det_ser_range_tab(l_det_index).attribute15 := p_serial_range_tab(l_index).attribute15;
8532             END IF;
8533             l_det_index := l_det_index +1;
8534          END IF;
8535 
8536          l_index := p_serial_range_tab.NEXT(l_index);
8537       END LOOP;
8538 
8539       l_detail_ser_count := l_det_ser_range_tab.count;
8540 
8541       IF l_debug_on THEN
8542          WSH_DEBUG_SV.log(l_module_name, 'Current detail count', l_detail_ser_count);
8543          WSH_DEBUG_SV.log(l_module_name, 'Total serial qty in table', l_detail_ser_qty);
8544       END IF;
8545 
8546       IF l_detail_ser_count >= 1
8547       THEN
8548       -- (
8549          IF l_debug_on THEN
8550             WSH_DEBUG_SV.log(l_module_name, 'input from serial number', p_in_detail_rec.serial_number);
8551             WSH_DEBUG_SV.log(l_module_name, 'input to_serial_number', p_in_detail_rec.to_serial_number);
8552          END IF;
8553 
8554          IF    (
8555                     p_in_detail_rec.serial_number IS NOT NULL
8556                 AND p_in_detail_rec.serial_number <> fnd_api.g_miss_char
8557                )
8558             OR (
8559                     p_in_detail_rec.to_serial_number IS NOT NULL
8560                 AND p_in_detail_rec.to_serial_number <> fnd_api.g_miss_char
8561                )
8562          THEN
8563          -- (
8564             -- Error case. Inputs should be mutually exclusive
8565             IF l_debug_on THEN
8566                WSH_DEBUG_SV.logmsg(l_module_name, 'Serial number input not mutually exclusive');
8567             END IF;
8568 
8569             RAISE fnd_api.g_exc_error;
8570          -- )
8571          END IF;
8572       ELSIF l_detail_ser_count = 0
8573       THEN
8574          IF     p_in_detail_rec.serial_number IS NOT NULL
8575             AND p_in_detail_rec.serial_number <> fnd_api.g_miss_char
8576          THEN
8577          -- (
8578             l_det_ser_range_tab(1).delivery_detail_id := x_detail_rec.delivery_detail_id;
8579             l_det_ser_range_tab(1).from_serial_number := p_in_detail_rec.serial_number;
8580 
8581             IF p_in_detail_rec.to_serial_number <> fnd_api.g_miss_char
8582             THEN
8583             -- (
8584                l_det_ser_range_tab(1).to_serial_number := p_in_detail_rec.to_serial_number;
8585             -- )
8586             END IF;
8587 
8588             l_det_ser_range_tab(1).quantity := x_detail_rec.shipped_quantity;
8589             l_detail_ser_count := l_detail_ser_count + 1;
8590             l_detail_ser_qty := l_detail_ser_qty + x_detail_rec.shipped_quantity;
8591 
8592             -- If From and To Serial Number is same,
8593             -- then stamp serial number on wdd and do not
8594             -- generate transaction_temp_id
8595             IF l_det_ser_range_tab(1).from_serial_number
8596                       = NVL(l_det_ser_range_tab(1).to_serial_number,
8597                             l_det_ser_range_tab(1).from_serial_number) THEN
8598              IF l_debug_on THEN
8599               WSH_DEBUG_SV.logmsg(l_module_name, 'Stamp serial number on wdd');
8600              END IF;
8601              l_stamp_ser_wdd := TRUE;
8602             END IF;
8603 
8604          ELSE
8605             IF     p_in_detail_rec.to_serial_number IS NOT NULL
8606                AND p_in_detail_rec.to_serial_number <> fnd_api.g_miss_char
8607             THEN
8608             -- (
8609                -- To serial number cannot exist with a from serial number
8610                IF l_debug_on THEN
8611                   WSH_DEBUG_SV.logmsg(l_module_name, 'From serial number is null');
8612                END IF;
8613 
8614                RAISE fnd_api.g_exc_error;
8615             -- )
8616             END IF;
8617          -- )
8618          END IF;
8619       -- )
8620       END IF;
8621 
8622 
8623       IF l_detail_ser_count >= 1
8624       THEN
8625       -- (
8626           --bug 4365589
8627           IF p_in_rec.caller = 'WSH_PUB'
8628              AND l_inv_controls.serial_code IN (2,5)
8629           THEN --{
8630              IF (wsh_util_validate.Check_Wms_Org(l_org_id)='Y') THEN --{
8631                  IF l_debug_on THEN
8632                     WSH_DEBUG_SV.logmsg(l_module_name, 'Cannot modify the serial numbers for WMS organizationx ');
8633                  END IF;
8634 
8635                  RAISE fnd_api.g_exc_error;
8636              END IF; --}
8637           END IF;--}
8638 
8639             -- Check 1: When serial number is input, Released Status should be Y or X
8640             IF p_original_rec.released_status NOT IN('Y', 'X')
8641             THEN
8642             -- (
8643                IF l_debug_on THEN
8644                   WSH_DEBUG_SV.logmsg(l_module_name, 'Released Status Not in X,Y');
8645                END IF;
8646 
8647                RAISE fnd_api.g_exc_error;
8648             -- )
8649             END IF;
8650 
8651           -- Check 2: When serial number is input, Shipped Qty should not be null or Zero. Bug 2652300
8652           IF nvl(x_detail_rec.shipped_quantity, nvl(p_original_rec.shipped_quantity,0)) = 0
8653           THEN
8654           -- (
8655               -- Bug 2652300. Cannot update serial number if shipped qty is null or zero
8656                  IF l_debug_on THEN
8657                     WSH_DEBUG_SV.logmsg(l_module_name, 'Shipped qty zero or null. Not null serial number');
8658                  END IF;
8659                  raise FND_API.G_EXC_ERROR;
8660           ELSIF  nvl(x_detail_rec.shipped_quantity, nvl(p_original_rec.shipped_quantity,0)) > 1
8661           THEN
8662             -- Check 3: If shipped qty is greater than one,
8663             --          if table count is one, then to_serial_number should exist. Bug 2652319
8664               IF l_detail_ser_count = 1
8665                      AND l_det_ser_range_tab(l_det_ser_range_tab.first).to_serial_number IS NULL
8666               THEN
8667               -- (
8668                  IF l_debug_on THEN
8669                     WSH_DEBUG_SV.logmsg(l_module_name, 'Shipped qty greater than one. No to_serial_number');
8670                  END IF;
8671                  raise FND_API.G_EXC_ERROR;
8672               -- )
8673               END IF;
8674           -- )
8675           END IF;
8676 
8677          -- Check 3: Sum of Serial number qty should not be greater than shipped qty
8678          IF l_detail_ser_qty > x_detail_rec.shipped_quantity
8679          THEN
8680          -- (
8681             -- Total quantity in serial table should not be greater than shipped qty
8682             -- Error case.
8683             IF l_debug_on THEN
8684                WSH_DEBUG_SV.logmsg(l_module_name, 'Serial table qty greater than shipped qty');
8685             END IF;
8686             RAISE fnd_api.g_exc_error;
8687          ELSIF l_detail_ser_qty = 1
8688          THEN
8689             IF l_debug_on THEN
8690                WSH_DEBUG_SV.log(l_module_name, 'table from serial num', l_det_ser_range_tab(1).from_serial_number);
8691                WSH_DEBUG_SV.log(l_module_name, 'table to seral num', l_det_ser_range_tab(1).to_serial_number);
8692             END IF;
8693 
8694             IF l_det_ser_range_tab(1).from_serial_number IS NOT NULL
8695             THEN
8696             -- (
8697                   x_detail_rec.serial_number := l_det_ser_range_tab(1).from_serial_number;
8698             ELSE
8699                -- Record cannot exist without a from serial number
8700                IF l_debug_on THEN
8701                   WSH_DEBUG_SV.logmsg(l_module_name, 'From serial number is null');
8702                END IF;
8703 
8704                RAISE fnd_api.g_exc_error;
8705             -- )
8706             END IF;
8707          ELSIF l_detail_ser_qty > 1
8708          THEN
8709             SELECT mtl_material_transactions_s.NEXTVAL
8710             INTO l_transaction_id
8711             FROM DUAL;
8712          END IF;
8713 
8714          -- Bug 3628620. We allow update of serial number attributes only if the
8715          -- serial number exists (implies shipped qty = 1) in wdd and the user is
8716          -- not attempting to change the serial number.
8717          -- If the transaction temp id exists in wdd, then the record exists in
8718          -- msnt, and the user can update msnt using the INV API.
8719 
8720          l_index := l_det_ser_range_tab.first;
8721          IF     l_det_ser_range_tab.count = 1
8722             AND l_det_ser_range_tab(l_index).quantity = 1 THEN
8723           --{
8724              IF l_det_ser_range_tab(l_index).from_serial_number =
8725                 NVL(l_det_ser_range_tab(l_index).to_serial_number,
8726                     l_det_ser_range_tab(l_index).from_serial_number)
8727              AND (l_det_ser_range_tab(l_index).from_serial_number =
8728                     p_original_rec.serial_number) AND (NOT l_stamp_ser_wdd) THEN  --Bug 8858812
8729                --{
8730                -- We are not changing the serial number, we are only updating
8731                -- the serial number attributes.
8732                -- create new record in msnt using the group_mark_id from msn.
8733                -- Bug 4016863 : We generate a new transaction_temp_id and call
8734                -- Update_Marked_serial API later
8735                --
8736                IF l_debug_on THEN
8737                 WSH_DEBUG_SV.logmsg(l_module_name,
8738                          'Generating txn temp ID for existing serial number');
8739                END IF;
8740                --
8741                SELECT mtl_material_transactions_s.NEXTVAL
8742                INTO l_transaction_id
8743                FROM DUAL;
8744                --
8745                l_update_attributes := TRUE;
8746                --}
8747 	     ELSE
8748                --{
8749                IF NOT l_stamp_ser_wdd THEN
8750                  IF l_debug_on THEN
8751                     WSH_DEBUG_SV.logmsg(l_module_name,
8752                                         'generate transaction temp id');
8753                  END IF;
8754                  SELECT mtl_material_transactions_s.NEXTVAL
8755                  INTO l_transaction_id
8756                  FROM DUAL;
8757                END IF;
8758                --}
8759              END IF;
8760           --}
8761          END IF;
8762 
8763      -- )
8764      END IF; -- if l_detail_ser_count >=1
8765 
8766          IF l_debug_on THEN
8767             WSH_DEBUG_SV.log(l_module_name, 'Transaction id created', l_transaction_id);
8768          END IF;
8769 
8770 -- HW OPMCONV - Removed checking for l_process_flag
8771       IF (
8772               (
8773                   (x_detail_rec.serial_number <> fnd_api.g_miss_char)
8774                OR x_detail_rec.serial_number IS NULL
8775                OR l_detail_ser_count > 0
8776               )
8777 --          AND l_process_flag = '0'
8778          )
8779       THEN
8780       -- (
8781 
8782          IF l_debug_on THEN
8783             WSH_DEBUG_SV.log(l_module_name, 'Serial Number', x_detail_rec.serial_number);
8784             WSH_DEBUG_SV.log(l_module_name, 'To Serial Number', x_detail_rec.to_serial_number);
8785          END IF;
8786 
8787          --
8788          IF l_debug_on THEN
8789             WSH_DEBUG_SV.log(l_module_name, 'inv control ser flag', l_inv_controls.ser_flag);
8790          END IF;
8791 
8792          -- Fix added to check the serial number before setting the message.
8793          -- If Serial Flag is N, need to set the message only if serial numbers are populated
8794          IF    x_detail_rec.serial_number IS NOT NULL
8795             OR x_detail_rec.to_serial_number IS NOT NULL
8796             OR l_detail_ser_count > 0
8797          THEN
8798          -- (
8799              IF l_inv_controls.ser_flag = 'N'
8800              THEN
8801              -- (
8802                  l_return_status := wsh_util_core.g_ret_sts_error;
8803                  fnd_message.set_name('WSH', 'WSH_INV_INVALID');
8804                  fnd_message.set_token('INV_ATTRIBUTE', 'Serial Number Code');
8805                  wsh_util_core.add_message(l_return_status);
8806                  RAISE fnd_api.g_exc_error;
8807              -- )
8808              END IF;
8809          -- )
8810          END IF;
8811 
8812          /* Bug fix: 2652300. Removed the code to call unmark serial numbers.
8813             Unmarking of serial numbers is now done in the api
8814             wsh_details_validations.validate_shipped_cc_qty , based on the shipped quantity and the serial quantity.
8815             It is no longer done here in the group API.*/
8816 
8817          -- Bug 3628620
8818          -- Handle Unmark Serial Number for Public API
8819          IF p_in_rec.caller = 'WSH_PUB' THEN
8820 
8821            -- Serial Number is being modified from Not null to Null/Not Null value,
8822            -- Unmark using serial number
8823            IF p_original_rec.serial_number IS NOT NULL AND
8824               l_detail_ser_qty = 1 AND l_update_attributes = FALSE AND
8825               x_detail_rec.serial_number <> fnd_api.g_miss_char
8826               -- AND (x_detail_rec.serial_number IS NULL OR
8827               -- x_detail_rec.serial_number <> p_original_rec.serial_number)
8828              THEN
8829 
8830              IF l_debug_on THEN
8831                WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_INV.UNMARK_SERIAL_NUMBER',WSH_DEBUG_SV.C_PROC_LEVEL);
8832                WSH_DEBUG_SV.log(l_module_name,'Case1',p_original_rec.serial_number);
8833              END IF;
8834              wsh_delivery_details_inv.unmark_serial_number(
8835                p_delivery_detail_id  => p_in_detail_rec.delivery_detail_id,
8836                p_serial_number_code  => l_inv_controls.serial_code,
8837                p_serial_number          => p_original_rec.serial_number,
8838                p_transaction_temp_id => NULL,
8839                x_return_status          => l_return_status,
8840                p_inventory_item_id   => p_original_rec.inventory_item_id);
8841 
8842              IF l_debug_on THEN
8843                wsh_debug_sv.log(l_module_name, 'Return status after Unmark ', l_return_status);
8844              END IF;
8845 
8846              IF l_return_status <> wsh_util_core.g_ret_sts_success THEN
8847                RAISE fnd_api.g_exc_error;
8848              END IF;
8849 
8850            -- Transaction temp id exists in WDD,now 1 serial number is being
8851            -- specified, unmark using transaction temp id
8852            ELSIF (p_original_rec.transaction_temp_id IS NOT NULL AND
8853                   x_detail_rec.serial_number <> fnd_api.g_miss_char AND
8854                   l_detail_ser_qty = 1 AND l_update_attributes = FALSE)
8855                  OR
8856                  (p_original_rec.transaction_temp_id IS NOT NULL AND
8857                   l_det_ser_range_tab.count > 0 AND
8858                   l_detail_ser_qty > 1)
8859            THEN
8860              -- derive serial number from MSNT for this transaction temp id
8861              -- compare with x_detail_rec.serial_number
8862 
8863              IF l_debug_on THEN
8864                WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_INV.UNMARK_SERIAL_NUMBER',WSH_DEBUG_SV.C_PROC_LEVEL);
8865                WSH_DEBUG_SV.log(l_module_name,'Case2',p_original_rec.transaction_temp_id);
8866              END IF;
8867              wsh_delivery_details_inv.unmark_serial_number(
8868                p_delivery_detail_id  => p_in_detail_rec.delivery_detail_id,
8869                p_serial_number_code  => l_inv_controls.serial_code,
8870                p_serial_number          => NULL,
8871                p_transaction_temp_id => p_original_rec.transaction_temp_id,
8872                x_return_status          => l_return_status,
8873                p_inventory_item_id   => p_original_rec.inventory_item_id);
8874 
8875              IF l_debug_on THEN
8876                wsh_debug_sv.log(l_module_name, 'Return status after Unmark ', l_return_status);
8877              END IF;
8878 
8879              IF l_return_status <> wsh_util_core.g_ret_sts_success THEN
8880                RAISE fnd_api.g_exc_error;
8881              END IF;
8882 
8883            END IF;
8884          END IF;
8885          -- End of Bug 3628620
8886 
8887          l_det_index := l_det_ser_range_tab.FIRST;
8888 
8889          WHILE l_det_index IS NOT NULL
8890          LOOP
8891          -- (
8892             --
8893                IF l_det_ser_range_tab(l_det_index).from_serial_number IS NOT NULL THEN
8894                   -- Bug 3628620. Skip validation if we are only updating the serial number flexfield attributes.
8895                   IF NOT l_update_attributes THEN
8896                     IF l_inv_controls.ser_flag = 'Y' THEN
8897                        IF l_det_ser_range_tab(l_det_index).to_serial_number IS NOT NULL THEN -- bug 1578114 condition added
8898                           IF l_debug_on THEN
8899                              WSH_DEBUG_SV.log(l_module_name, 'To Serial Number', l_det_ser_range_tab(l_det_index).to_serial_number);
8900                              WSH_DEBUG_SV.log(l_module_name, 'Transaction Id', l_transaction_id);
8901                              WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DELIVERY_DETAILS_INV.VALIDATE_SERIAL_RANGE', WSH_DEBUG_SV.c_proc_level);
8902                           END IF;
8903 
8904                           --
8905                           -- Validates the Range of Serial Number
8906                           wsh_delivery_details_inv.validate_serial_range(
8907                              p_from_serial_number      => l_det_ser_range_tab(l_det_index).from_serial_number,
8908                              p_to_serial_number        => l_det_ser_range_tab(l_det_index).to_serial_number,
8909                              p_lot_number              => l_lot,
8910                              p_organization_id         => l_org_id,
8911                              p_inventory_item_id       => p_original_rec.inventory_item_id,
8912                              p_subinventory            => l_subinventory,
8913                              p_revision                => l_revision,
8914                              p_locator_id              => l_locator,
8915                              p_quantity                => l_det_ser_range_tab(l_det_index).quantity,
8916      	                     p_transaction_type_id    => l_trx_type_id,
8917 	                     p_object_type            => 'A',
8918 			     x_prefix                  => l_prefix,
8919                              x_return_status           => l_return_status,
8920                              x_result                  => l_result
8921                           );
8922 
8923                           --
8924                           IF l_debug_on THEN
8925                              WSH_DEBUG_SV.log(l_module_name, 'Prefix',l_prefix);
8926                              WSH_DEBUG_SV.log(l_module_name, 'Result',l_result);
8927                              WSH_DEBUG_SV.log(l_module_name, 'Return Status',l_return_status);
8928                           END IF;
8929 
8930                           IF NOT l_result THEN
8931                              l_return_status := wsh_util_core.g_ret_sts_error;
8932                           END IF;
8933 
8934                           wsh_util_core.api_post_call(
8935                            p_return_status      => l_return_status,
8936                            x_num_warnings       => l_number_of_warnings,
8937                            x_num_errors         => l_number_of_errors,
8938                            p_msg_data           => l_msg_data
8939                           );
8940                        ELSE
8941                           IF l_debug_on THEN
8942                              WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DELIVERY_DETAILS_INV.VALIDATE_SERIAL', WSH_DEBUG_SV.c_proc_level);
8943                           END IF;
8944 
8945                           --
8946                           wsh_delivery_details_inv.validate_serial(
8947                            p_serial_number          => l_det_ser_range_tab(l_det_index).from_serial_number,
8948                            p_lot_number             => l_lot,
8949                            p_organization_id        => l_org_id,
8950                            p_inventory_item_id      => p_original_rec.inventory_item_id,
8951                            p_subinventory           => l_subinventory,
8952                            p_revision               => l_revision,
8953                            p_locator_id             => l_locator,
8954   	                   p_transaction_type_id    => l_trx_type_id,
8955 	                   p_object_type            => 'A',
8956                            x_return_status          => l_return_status,
8957                            x_result                 => l_result
8958                           );
8959                           --
8960                           IF l_debug_on THEN
8961                              WSH_DEBUG_SV.log(l_module_name, 'Result',l_result);
8962                              WSH_DEBUG_SV.log(l_module_name, 'Return Status',l_return_status);
8963                           END IF;
8964                           --
8965                           IF NOT l_result THEN
8966                              l_return_status := wsh_util_core.g_ret_sts_error;
8967                           END IF;
8968                           --
8969                           wsh_util_core.api_post_call(
8970                              p_return_status      => l_return_status,
8971                              x_num_warnings       => l_number_of_warnings,
8972                              x_num_errors         => l_number_of_errors,
8973                              p_msg_data           => l_msg_data
8974                           );
8975                        END IF; -- if to_serial_number is not null
8976 
8977 
8978                     ELSIF l_inv_controls.ser_flag = 'D' THEN
8979                        IF l_debug_on THEN
8980                         WSH_DEBUG_SV.log(l_module_name, 'to serial number', l_det_ser_range_tab(l_det_index).to_serial_number);
8981                        END IF;
8982 
8983                        IF     (
8984                              l_det_ser_range_tab(l_det_index).to_serial_number <>
8985                                                            fnd_api.g_miss_char
8986                             )
8987                           AND l_det_ser_range_tab(l_det_index).to_serial_number IS NOT NULL THEN -- bug 1578114 condition added
8988                           IF l_debug_on THEN
8989                              WSH_DEBUG_SV.log(l_module_name, 'Transaction id created', l_transaction_id);
8990                              WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DELIVERY_DETAILS_INV.CREATE_DYNAMIC_SERIAL_RANGE', WSH_DEBUG_SV.c_proc_level);
8991                           END IF;
8992 
8993                           --
8994                           -- Creates/Validates the Range of Serial Number
8995                           wsh_delivery_details_inv.create_dynamic_serial_range(
8996                            p_from_number             => l_det_ser_range_tab(l_det_index).from_serial_number,
8997                            p_to_number               => l_det_ser_range_tab(l_det_index).to_serial_number,
8998 --  Earlier l_transaction_id was being passed to p_delivery_detail below (frontport from 1159) -  jckwok
8999                            p_delivery_detail_id      => x_detail_rec.delivery_detail_id,
9000                            p_source_line_id          => p_original_rec.source_line_id,
9001                            p_lot_number              => l_lot,
9002                            p_organization_id         => l_org_id,
9003                            p_inventory_item_id       => p_original_rec.inventory_item_id,
9004                            p_subinventory            => l_subinventory,
9005                            p_revision                => l_revision,
9006                            p_locator_id              => l_locator,
9007                            p_quantity                => l_det_ser_range_tab(l_det_index).quantity,
9008                            x_prefix                  => l_prefix,
9009                            x_return_status           => l_return_status
9010                           );
9011                           --
9012                           wsh_util_core.api_post_call(
9013                            p_return_status      => l_return_status,
9014                            x_num_warnings       => l_number_of_warnings,
9015                            x_num_errors         => l_number_of_errors,
9016                            p_msg_data           => l_msg_data
9017                           );
9018                        ELSE
9019                           IF l_debug_on THEN
9020                            WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DELIVERY_DETAILS_INV.CREATE_DYNAMIC_SERIAL', WSH_DEBUG_SV.c_proc_level);
9021                           END IF;
9022 
9023                           --
9024                           wsh_delivery_details_inv.create_dynamic_serial(
9025                            p_from_number             => l_det_ser_range_tab(l_det_index).from_serial_number,
9026                            p_to_number               => l_det_ser_range_tab(l_det_index).from_serial_number,
9027                            p_delivery_detail_id      => x_detail_rec.delivery_detail_id,
9028                            p_source_line_id          => p_original_rec.source_line_id,
9029                            p_lot_number              => l_lot,
9030                            p_organization_id         => l_org_id,
9031                            p_inventory_item_id       => p_original_rec.inventory_item_id,
9032                            p_subinventory            => l_subinventory,
9033                            p_revision                => l_revision,
9034                            p_locator_id              => l_locator,
9035                            x_return_status           => l_return_status
9036                           );
9037                           --
9038                           wsh_util_core.api_post_call(
9039                              p_return_status      => l_return_status,
9040                              x_num_warnings       => l_number_of_warnings,
9041                              x_num_errors         => l_number_of_errors,
9042                              p_msg_data           => l_msg_data
9043                           );
9044                        END IF; -- if to_serial_number is not null
9045                     END IF; -- IF l_controls.ser_flag = 'D'/'Y'
9046 
9047                   END IF; -- IF NOT l_update_attributes THEN
9048 
9049 
9050                   IF     l_transaction_id IS NOT NULL
9051                      AND l_det_ser_range_tab(l_det_index).to_serial_number IS NOT NULL THEN --bug 1578114 condition added
9052                      v1 := l_transaction_id;
9053                      v2 := SYSDATE;
9054                      v3 := fnd_global.user_id;
9055                      v4 := SYSDATE;
9056                      v5 := fnd_global.user_id;
9057                      v6 := fnd_global.login_id;
9058                      v7 := NULL;
9059                      v8 := NULL;
9060                      v9 := NULL;
9061                      v10 := SYSDATE;
9062                      v11 := NULL;
9063                      v12 := l_lot;
9064                      v13 :=
9065                            l_det_ser_range_tab(l_det_index).from_serial_number;
9066                      v14 := l_det_ser_range_tab(l_det_index).to_serial_number;
9067                      v15 := l_det_ser_range_tab(l_det_index).quantity;
9068                      v16 := NULL;
9069                      v17 := l_transaction_id;
9070                      v18 := NULL;
9071                      v19 := l_det_ser_range_tab(l_det_index).attribute_category;
9072                      v20 := l_det_ser_range_tab(l_det_index).attribute1;
9073                      v21 := l_det_ser_range_tab(l_det_index).attribute2;
9074                      v22 := l_det_ser_range_tab(l_det_index).attribute3;
9075                      v23 := l_det_ser_range_tab(l_det_index).attribute4;
9076                      v24 := l_det_ser_range_tab(l_det_index).attribute5;
9077                      v25 := l_det_ser_range_tab(l_det_index).attribute6;
9078                      v26 := l_det_ser_range_tab(l_det_index).attribute7;
9079                      v27 := l_det_ser_range_tab(l_det_index).attribute8;
9080                      v28 := l_det_ser_range_tab(l_det_index).attribute9;
9081                      v29 := l_det_ser_range_tab(l_det_index).attribute10;
9082                      v30 := l_det_ser_range_tab(l_det_index).attribute11;
9083                      v31 := l_det_ser_range_tab(l_det_index).attribute12;
9084                      v32 := l_det_ser_range_tab(l_det_index).attribute13;
9085                      v33 := l_det_ser_range_tab(l_det_index).attribute14;
9086                      v34 := l_det_ser_range_tab(l_det_index).attribute15;
9087                      -- Bug 3628620: INV wants DFF_UPDATED_FLAG to be populated
9088                      -- to 'Y' if there are dff attributes in msnt
9089                      IF v20 IS NOT NULL OR
9090                         v21 IS NOT NULL OR
9091                         v22 IS NOT NULL OR
9092                         v23 IS NOT NULL OR
9093                         v24 IS NOT NULL OR
9094                         v25 IS NOT NULL OR
9095                         v26 IS NOT NULL OR
9096                         v27 IS NOT NULL OR
9097                         v28 IS NOT NULL OR
9098                         v29 IS NOT NULL OR
9099                         v30 IS NOT NULL OR
9100                         v31 IS NOT NULL OR
9101                         v32 IS NOT NULL OR
9102                         v33 IS NOT NULL OR
9103                         v34 IS NOT NULL
9104                      THEN
9105                         v35 := 'Y';
9106                      ELSE
9107                         v35 := 'N';
9108                      END IF;
9109 
9110                      IF l_debug_on THEN
9111                         WSH_DEBUG_SV.logmsg(l_module_name, 'Inserting record into msnt');
9112                      END IF;
9113 
9114                      INSERT INTO mtl_serial_numbers_temp
9115                                  (
9116                                   transaction_temp_id, last_update_date,
9117                                   last_updated_by, creation_date,
9118                                   created_by, last_update_login, request_id,
9119                                   program_application_id, program_id,
9120                                   program_update_date, vendor_serial_number,
9121                                   vendor_lot_number, fm_serial_number,
9122                                   to_serial_number, serial_prefix,
9123                                   ERROR_CODE, group_header_id,
9124                                   parent_serial_number,
9125                                   attribute_category,
9126                                   attribute1,
9127                                   attribute2,
9128                                   attribute3,
9129                                   attribute4,
9130                                   attribute5,
9131                                   attribute6,
9132                                   attribute7,
9133                                   attribute8,
9134                                   attribute9,
9135                                   attribute10,
9136                                   attribute11,
9137                                   attribute12,
9138                                   attribute13,
9139                                   attribute14,
9140                                   attribute15,
9141                                   dff_updated_flag
9142                                  )
9143                           VALUES (
9144                                   v1, v2,
9145                                   v3, v4,
9146                                   v5, v6, v7,
9147                                   v8, v9,
9148                                   v10, v11,
9149                                   v12, v13,
9150                                   v14, v15,
9151                                   v16, v17,
9152                                   v18,
9153                                   v19,
9154                                   v20,
9155                                   v21,
9156                                   v22,
9157                                   v23,
9158                                   v24,
9159                                   v25,
9160                                   v26,
9161                                   v27,
9162                                   v28,
9163                                   v29,
9164                                   v30,
9165                                   v31,
9166                                   v32,
9167                                   v33,
9168                                   v34,
9169                                   v35
9170                                  );
9171                   END IF; -- if l_transaction_id is not null
9172                END IF; -- If new serial number is not null
9173 
9174             l_det_index := l_det_ser_range_tab.NEXT(l_det_index);
9175          -- )
9176          END LOOP; -- while l_det_index of serial_range_tab is not null
9177 
9178          IF l_debug_on THEN
9179            WSH_DEBUG_SV.log(l_module_name, 'Transaction Id', l_transaction_id);
9180          END IF;
9181 
9182          IF NOT l_update_attributes THEN
9183           --{
9184             IF l_transaction_id IS NOT NULL
9185             THEN
9186             -- (
9187                wsh_delivery_details_inv.mark_serial_number(
9188                   p_delivery_detail_id       => x_detail_rec.delivery_detail_id,
9189                   p_serial_number            => NULL,
9190                   p_transaction_temp_id      => l_transaction_id,
9191                   x_return_status            => l_return_status
9192                );
9193                wsh_util_core.api_post_call(
9194                   p_return_status      => l_return_status,
9195                   x_num_warnings       => l_number_of_warnings,
9196                   x_num_errors         => l_number_of_errors,
9197                   p_msg_data           => l_msg_data
9198                );
9199             ELSIF p_in_detail_rec.serial_number IS NOT NULL
9200                   AND p_in_detail_rec.serial_number <> FND_API.G_MISS_CHAR
9201             THEN
9202                --
9203                IF l_debug_on THEN
9204                   WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_DELIVERY_DETAILS_INV.MARK_SERIAL_NUMBER', WSH_DEBUG_SV.c_proc_level);
9205                END IF;
9206 
9207                --
9208                wsh_delivery_details_inv.mark_serial_number(
9209                   p_delivery_detail_id       => x_detail_rec.delivery_detail_id,
9210                   p_serial_number            => p_in_detail_rec.serial_number,
9211                   p_transaction_temp_id      => l_transaction_id,
9212                   x_return_status            => l_return_status
9213                );
9214                wsh_util_core.api_post_call(
9215                   p_return_status      => l_return_status,
9216                   x_num_warnings       => l_number_of_warnings,
9217                   x_num_errors         => l_number_of_errors,
9218                   p_msg_data           => l_msg_data
9219                );
9220                -- Since only single serial number exists, transaction_temp_id if exists, should be nulled
9221                x_detail_rec.transaction_temp_id := NULL;
9222             --)
9223             END IF;
9224           --}
9225          ELSE
9226           --{
9227           -- Bug 4016863 : Need to mark existing serial number with
9228           -- newly generated transaction_temp_id in the scenario where
9229           -- only the serial attributes are updated and not the serial #
9230           --
9231           IF l_debug_on THEN
9232              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_INV.UPDATE_MARKED_SERIAL',WSH_DEBUG_SV.C_PROC_LEVEL);
9233           END IF;
9234           --
9235           WSH_DELIVERY_DETAILS_INV.Update_Marked_Serial(
9236              p_from_serial_number  => p_original_rec.serial_number,
9237              p_to_serial_number    => NULL, -- always pass NULL for single serial number
9238              p_inventory_item_id   => p_original_rec.inventory_item_id,
9239              p_organization_id     => l_org_id,
9240              p_transaction_temp_id => l_transaction_id,
9241              p_delivery_detail_id  => x_detail_rec.delivery_detail_id, --RTV changes
9242              x_return_status       => l_return_status);
9243           --
9244           IF l_debug_on THEN
9245             wsh_debug_sv.log(l_module_name, 'Return status after Update_Marked_Serial ', l_return_status);
9246           END IF;
9247           --
9248           IF l_return_status <> wsh_util_core.g_ret_sts_success THEN
9249             RAISE fnd_api.g_exc_error;
9250           END IF;
9251           --}
9252          END IF; -- l_update_attributes;
9253        -- )
9254       END IF; -- serial number g_miss_num
9255 
9256       IF l_transaction_id IS NOT NULL THEN
9257          x_detail_rec.transaction_temp_id := l_transaction_id;
9258          x_detail_rec.serial_number := NULL;
9259          x_detail_rec.to_serial_number := NULL;
9260       END IF;
9261 
9262       IF NVL(x_detail_rec.shipped_quantity, 0) = 0 THEN
9263          IF l_debug_on THEN
9264             WSH_DEBUG_SV.logmsg(l_module_name, 'Zero or Null shipped qty');
9265          END IF;
9266 
9267          x_detail_rec.serial_number := NULL;
9268          x_detail_rec.to_serial_number := NULL;
9269          x_detail_rec.transaction_temp_id := NULL;
9270       END IF;
9271 
9272       -- If from serial number = to serial number, only from serial number should be populated
9273       IF x_detail_rec.serial_number = x_detail_rec.to_serial_number THEN
9274          x_detail_rec.to_serial_number := NULL;
9275       END IF;
9276 
9277       IF l_debug_on THEN
9278          WSH_DEBUG_SV.log(l_module_name, 'transaction temp id', x_detail_rec.transaction_temp_id);
9279          WSH_DEBUG_SV.log(l_module_name, 'serial number', x_detail_rec.serial_number);
9280          WSH_DEBUG_SV.log(l_module_name, 'to_serial_number', x_detail_rec.to_serial_number);
9281       END IF;
9282    END IF; -- if check for validation level
9283 
9284    fnd_msg_pub.count_and_get(
9285       p_count => x_msg_count,
9286       p_data => x_msg_data,
9287       p_encoded      => fnd_api.g_false);
9288 
9289    IF l_debug_on THEN
9290       WSH_DEBUG_SV.pop(l_module_name);
9291    END IF;
9292 --
9293 EXCEPTION
9294    WHEN fnd_api.g_exc_error THEN
9295       ROLLBACK TO validate_det_line_grp;
9296       x_return_status := fnd_api.g_ret_sts_error;
9297       fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data,
9298          p_encoded      => fnd_api.g_false);
9299 
9300       --
9301       IF l_debug_on THEN
9302          WSH_DEBUG_SV.logmsg(l_module_name, 'FND_API.G_EXC_ERROR exception has occured.', WSH_DEBUG_SV.c_excep_level);
9303          WSH_DEBUG_SV.pop(l_module_name, 'EXCEPTION:FND_API.G_EXC_ERROR');
9304       END IF;
9305 --
9306    WHEN fnd_api.g_exc_unexpected_error THEN
9307       ROLLBACK TO validate_det_line_grp;
9308       x_return_status := fnd_api.g_ret_sts_unexp_error;
9309       fnd_msg_pub.count_and_get(
9310          p_count => x_msg_count,
9311          p_data => x_msg_data,
9312          p_encoded      => fnd_api.g_false);
9313 
9314       --
9315       IF l_debug_on THEN
9316          WSH_DEBUG_SV.logmsg(l_module_name, 'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.', WSH_DEBUG_SV.c_excep_level);
9317          WSH_DEBUG_SV.pop(l_module_name,
9318             'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
9319       END IF;
9320 --
9321    WHEN wsh_util_core.g_exc_warning THEN
9322       x_return_status := wsh_util_core.g_ret_sts_warning;
9323       fnd_msg_pub.count_and_get(
9324          p_count => x_msg_count,
9325          p_data => x_msg_data,
9326          p_encoded      => fnd_api.g_false);
9327 
9328       --
9329       IF l_debug_on THEN
9330          WSH_DEBUG_SV.logmsg(l_module_name,
9331             'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ',
9332             WSH_DEBUG_SV.c_excep_level);
9333          WSH_DEBUG_SV.pop(l_module_name,
9334             'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
9335       END IF;
9336 --
9337    WHEN OTHERS THEN
9338       ROLLBACK TO validate_det_line_grp;
9339       x_return_status := fnd_api.g_ret_sts_unexp_error;
9340       wsh_util_core.add_message(x_return_status, l_module_name);
9341       wsh_util_core.default_handler('WSH_DELIVERY_DETAILS_GRP.Validate_Detail_Line');
9342       fnd_msg_pub.count_and_get(
9343          p_count => x_msg_count,
9344          p_data => x_msg_data,
9345          p_encoded      => fnd_api.g_false);
9346 
9347       --
9348 
9349       IF l_debug_on THEN
9350          WSH_DEBUG_SV.logmsg(l_module_name,
9351                'Unexpected error has occured. Oracle error message is '
9352             || SQLERRM,
9353             WSH_DEBUG_SV.c_unexpec_err_level);
9354          WSH_DEBUG_SV.pop(l_module_name, 'EXCEPTION:OTHERS');
9355       END IF;
9356 --
9357 END validate_detail_line;
9358 
9359 
9360     -- ---------------------------------------------------------------------
9361     -- Procedure: Validate_Detail_Container
9362     --
9363     -- Parameters:
9364     --
9365     -- Description:  This local procedure is the new API for wrapping the logic of VALIDATE of Containers
9366     -- Created:   Harmonization Project. Patchset I
9367     -- -----------------------------------------------------------------------
9368     PROCEDURE Validate_Detail_Container(
9369                 x_detail_rec          IN OUT NOCOPY WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Rec_Type,
9370                 p_original_rec        IN   c_original_detail_cur%ROWTYPE,
9371                 p_validation_tab      IN   wsh_util_core.id_tab_type,
9372                 x_mark_reprice_flag   OUT  NOCOPY VARCHAR2,
9373                 x_return_status       OUT  NOCOPY VARCHAR2,
9374                 x_msg_count           OUT  NOCOPY NUMBER,
9375                 x_msg_data            OUT  NOCOPY VARCHAR2
9376                 ) IS
9377 
9378         l_api_name              CONSTANT VARCHAR2(30)   := 'Validate_Detail_Container';
9379         l_api_version           CONSTANT NUMBER         := 1.0;
9380 
9381   --
9382   l_return_status             VARCHAR2(32767);
9383   l_msg_count                 NUMBER;
9384   l_msg_data                  VARCHAR2(32767);
9385   l_program_name              VARCHAR2(32767);
9386         --
9387   l_number_of_errors    NUMBER := 0;
9388   l_number_of_warnings  NUMBER := 0;
9389   --
9390         l_cont_item_seg         FND_FLEX_EXT.SegmentArray;
9391         l_cont_item_name        VARCHAR2(30)    := NULL;
9392 
9393         --
9394 l_debug_on BOOLEAN;
9395         --
9396         l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'VALIDATE_DETAIL_CONTAINER';
9397         --
9398 e_invalid_delivered_qty EXCEPTION; --lpn SyNCH uP samanna
9399         --
9400     BEGIN
9401         --
9402         l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
9403         --
9404         IF l_debug_on IS NULL
9405         THEN
9406             l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
9407         END IF;
9408         --
9409         SAVEPOINT  VALIDATE_DET_CONTAINER_GRP;
9410         --
9411         IF l_debug_on THEN
9412             WSH_DEBUG_SV.push(l_module_name);
9413             WSH_DEBUG_SV.log(l_module_name, 'Delivery Detail Id', x_detail_rec.delivery_detail_id);
9414         END IF;
9415         --  Initialize API return status to success
9416   x_return_status       := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
9417   l_number_of_errors := 0;
9418   l_number_of_warnings := 0;
9419 
9420         IF(p_validation_tab(WSH_ACTIONS_LEVELS.C_CONT_ITEM_LVL) = 1 ) THEN
9421            IF (x_detail_rec.inventory_item_id <> FND_API.G_MISS_NUM) THEN
9422                 --
9423                 IF l_debug_on THEN
9424                     WSH_DEBUG_SV.log(l_module_name, 'Inventory Item Id', x_detail_rec.inventory_item_id);
9425                     WSH_DEBUG_SV.log(l_module_name, 'Organization Id', x_detail_rec.organization_id);
9426                     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_ITEM',WSH_DEBUG_SV.C_PROC_LEVEL);
9427                 END IF;
9428                 --
9429                 WSH_UTIL_VALIDATE.Validate_Item(
9430                      p_inventory_item_id => x_detail_rec.inventory_item_id,
9431                      p_inventory_item    => l_cont_item_name,
9432                      p_organization_id   => p_original_rec.organization_id,
9433                      p_seg_array         => l_cont_item_seg,
9434                      p_item_type         => 'CONT_ITEM',
9435                      x_return_status     => l_return_status);
9436 
9437                   --
9438                   wsh_util_core.api_post_call(
9439                       p_return_status => l_return_status,
9440                       x_num_warnings  => l_number_of_warnings,
9441                       x_num_errors    => l_number_of_errors,
9442                       p_msg_data      => l_msg_data
9443                       );
9444 
9445            END IF;
9446         END IF;
9447 	--
9448 	--lpn CONV.. samanna
9449 	IF (x_detail_rec.delivered_quantity <> FND_API.G_MISS_NUM) THEN
9450 	   IF p_original_rec.shipped_quantity IS NOT NULL THEN
9451 	      IF x_detail_rec.delivered_quantity > p_original_rec.shipped_quantity THEN
9452 	         RAISE e_invalid_delivered_qty;
9453 	      END IF;
9454 	   ELSE
9455 	      IF p_original_rec.picked_quantity IS NOT NULL THEN
9456 	         IF x_detail_rec.delivered_quantity > p_original_rec.picked_quantity THEN
9457 		    RAISE e_invalid_delivered_qty;
9458 		 END IF;
9459 	      ELSE
9460 	         IF p_original_rec.requested_quantity IS NOT NULL THEN
9461 		    IF x_detail_rec.delivered_quantity > p_original_rec.requested_quantity THEN
9462 		       RAISE e_invalid_delivered_qty;
9463 		    END IF;
9464 		 END IF;
9465 	      END IF;
9466 	   END IF;
9467 	END IF;
9468       --
9469     FND_MSG_PUB.Count_And_Get
9470       (
9471         p_count  => x_msg_count,
9472         p_data  =>  x_msg_data,
9473         p_encoded => FND_API.G_FALSE
9474       );
9475 
9476         IF l_debug_on THEN
9477                 WSH_DEBUG_SV.pop(l_module_name);
9478         END IF;
9479 
9480     EXCEPTION
9481 	  WHEN e_invalid_delivered_qty THEN
9482                 ROLLBACK TO VALIDATE_DET_CONTAINER_GRP;
9483                 x_return_status := FND_API.G_RET_STS_ERROR ;
9484                 FND_MESSAGE.SET_NAME('WSH', 'WSH_INVALID_DELIVERED_QTY');
9485                 WSH_UTIL_CORE.ADD_MESSAGE(wsh_util_core.g_ret_sts_error, l_module_name);
9486                 FND_MSG_PUB.Count_And_Get
9487                   (
9488                      p_count  => x_msg_count,
9489                      p_data  =>  x_msg_data,
9490                      p_encoded => FND_API.G_FALSE
9491                   );
9492                 IF l_debug_on THEN
9493 		   WSH_DEBUG_SV.logmsg(l_module_name,'E_INVALID_DELIVERED_QTY exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
9494                    WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION: E_INVALID_DELIVERED_QTY');
9495                 END IF;
9496 
9497 
9498         WHEN FND_API.G_EXC_ERROR THEN
9499                  ROLLBACK TO VALIDATE_DET_CONTAINER_GRP;
9500                 x_return_status := FND_API.G_RET_STS_ERROR ;
9501                 FND_MSG_PUB.Count_And_Get
9502                   (
9503                      p_count  => x_msg_count,
9504                      p_data  =>  x_msg_data,
9505                p_encoded => FND_API.G_FALSE
9506                   );
9507                   --
9508 
9509             IF l_debug_on THEN
9510                 WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
9511                 WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_ERROR');
9512             END IF;
9513 
9514         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9515                  ROLLBACK TO VALIDATE_DET_CONTAINER_GRP;
9516                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
9517                 FND_MSG_PUB.Count_And_Get
9518                   (
9519                      p_count  => x_msg_count,
9520                      p_data  =>  x_msg_data,
9521                p_encoded => FND_API.G_FALSE
9522                   );
9523                   --
9524 
9525              IF l_debug_on THEN
9526                 WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
9527                 WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
9528             END IF;
9529 --
9530         WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
9531              x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
9532              FND_MSG_PUB.Count_And_Get
9533               (
9534                 p_count  => x_msg_count,
9535                 p_data  =>  x_msg_data,
9536                 p_encoded => FND_API.G_FALSE
9537               );
9538         --
9539         IF l_debug_on THEN
9540             WSH_DEBUG_SV.logmsg(l_module_name,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ',WSH_DEBUG_SV.C_EXCEP_LEVEL);
9541            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
9542        END IF;
9543 --
9544         WHEN OTHERS THEN
9545                  ROLLBACK TO VALIDATE_DET_CONTAINER_GRP;
9546                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
9547                wsh_util_core.add_message(x_return_status, l_module_name);
9548                WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Validate_Detail_Container');
9549                 FND_MSG_PUB.Count_And_Get
9550                   (
9551                      p_count  => x_msg_count,
9552                      p_data  =>  x_msg_data,
9553                p_encoded => FND_API.G_FALSE
9554                   );
9555 
9556             IF l_debug_on THEN
9557                 WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
9558                 WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
9559             END IF;
9560 --
9561     END Validate_Detail_Container;
9562 
9563 
9564     -- ---------------------------------------------------------------------
9565     -- Procedure: Validate_Detail_Common
9566     --
9567     -- Parameters:
9568     --
9569     -- Description:  This local procedure is the new API for wrapping the logic of VALIDATE of both
9570     --                 Containers and Non Containers(Lines)
9571     -- Created:   Harmonization Project. Patchset I
9572     -- -----------------------------------------------------------------------
9573 
9574     PROCEDURE Validate_Detail_Common(
9575                 x_detail_rec          IN OUT NOCOPY WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Rec_Type,
9576                 p_original_rec        IN   c_original_detail_cur%ROWTYPE,
9577                 p_validation_tab      IN   wsh_util_core.id_tab_type,
9578                 x_mark_reprice_flag   OUT  NOCOPY VARCHAR2,
9579                 x_return_status       OUT  NOCOPY VARCHAR2,
9580                 x_msg_count           OUT  NOCOPY NUMBER,
9581                 x_msg_data            OUT  NOCOPY VARCHAR2
9582                 ) IS
9583 
9584         l_api_name              CONSTANT VARCHAR2(30)   := 'Validate_Detail_Common';
9585         l_api_version           CONSTANT NUMBER         := 1.0;
9586   --
9587   l_return_status             VARCHAR2(32767);
9588   l_msg_count                 NUMBER;
9589   l_msg_data                  VARCHAR2(32767);
9590   l_program_name              VARCHAR2(32767);
9591         --
9592   l_number_of_errors    NUMBER := 0;
9593   l_number_of_warnings  NUMBER := 0;
9594   --
9595         l_parent_detail_id    NUMBER;
9596         l_cont_item_seg         FND_FLEX_EXT.SegmentArray;
9597         l_cont_item_name        VARCHAR2(30)    := NULL;
9598   --
9599 
9600         CURSOR parent_detail_cur(p_detail_id NUMBER) IS
9601            SELECT parent_delivery_detail_id
9602            FROM wsh_delivery_assignments_v
9603            WHERE delivery_detail_id = p_detail_id;
9604            --
9605 -- HW OPMCONV - Removed OPM variables
9606 
9607 l_debug_on BOOLEAN;
9608            --
9609            l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'VALIDATE_DETAIL_COMMON';
9610            --
9611     BEGIN
9612         --
9613         l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
9614         --
9615         IF l_debug_on IS NULL
9616         THEN
9617             l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
9618         END IF;
9619         --
9620         SAVEPOINT VALIDATE_DET_COMMON_GRP;
9621 
9622         IF l_debug_on THEN
9623             WSH_DEBUG_SV.push(l_module_name);
9624             WSH_DEBUG_SV.log(l_module_name, 'Delivery Detail Id', x_detail_rec.delivery_detail_id);
9625         END IF;
9626         --
9627 
9628         --  Initialize API return status to success
9629   x_return_status       := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
9630   l_number_of_errors := 0;
9631   l_number_of_warnings := 0;
9632 
9633 --HW OPMCONV - Removed checking for process org
9634 
9635         IF(p_validation_tab(WSH_ACTIONS_LEVELS.C_GROSS_WEIGHT_LVL) = 1 ) THEN
9636                IF l_debug_on THEN
9637                   WSH_DEBUG_SV.log(l_module_name, 'Gross Weight', x_detail_rec.gross_weight);
9638                   WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_NEGATIVE',WSH_DEBUG_SV.C_PROC_LEVEL);
9639                END IF;
9640 	  --Bug # 3266333
9641 	       wsh_util_validate.validate_negative(
9642 		    p_value          =>  x_detail_rec.gross_weight,
9643 	  	    p_field_name     => 'gross_weight',
9644 		    x_return_status  => l_return_status );
9645           --
9646                   wsh_util_core.api_post_call(
9647                       p_return_status => l_return_status,
9648                       x_num_warnings  => l_number_of_warnings,
9649                       x_num_errors    => l_number_of_errors,
9650                       p_msg_data      => l_msg_data
9651                       );
9652 
9653                 x_mark_reprice_flag := 'Y';
9654         END IF;
9655 
9656         IF(p_validation_tab(WSH_ACTIONS_LEVELS.C_NET_WEIGHT_LVL) = 1 ) THEN
9657               --
9658               IF l_debug_on THEN
9659                   WSH_DEBUG_SV.log(l_module_name, 'Net Weight', x_detail_rec.net_weight);
9660                   WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_NEGATIVE',WSH_DEBUG_SV.C_PROC_LEVEL);
9661               END IF;
9662 	  --Bug # 3266333
9663 	       wsh_util_validate.validate_negative(
9664 		    p_value          =>  x_detail_rec.net_weight,
9665 	  	    p_field_name     => 'net_weight',
9666 		    x_return_status  => l_return_status );
9667           --
9668                wsh_util_core.api_post_call(
9669                     p_return_status => l_return_status,
9670                     x_num_warnings  => l_number_of_warnings,
9671                     x_num_errors    => l_number_of_errors,
9672                     p_msg_data      => l_msg_data
9673                      );
9674 
9675                   x_mark_reprice_flag := 'Y';
9676         END IF;
9677 
9678 
9679         IF(p_validation_tab(WSH_ACTIONS_LEVELS.C_VOLUME_LVL) = 1 ) THEN
9680                --
9681                IF l_debug_on THEN
9682                    WSH_DEBUG_SV.log(l_module_name, 'Volume', x_detail_rec.volume);
9683                    WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_NEGATIVE',WSH_DEBUG_SV.C_PROC_LEVEL);
9684                END IF;
9685 	     --Bug # 3266333
9686 	       wsh_util_validate.validate_negative(
9687 		    p_value          =>  x_detail_rec.volume,
9688 	  	    p_field_name     => 'volume',
9689 		    x_return_status  => l_return_status );
9690               --
9691                   wsh_util_core.api_post_call(
9692                       p_return_status => l_return_status,
9693                       x_num_warnings  => l_number_of_warnings,
9694                       x_num_errors    => l_number_of_errors,
9695                       p_msg_data      => l_msg_data
9696                       );
9697 
9698                x_mark_reprice_flag := 'Y';
9699         END IF;
9700 
9701      IF(p_validation_tab(WSH_ACTIONS_LEVELS.C_MASTER_SER_NUM_LVL) = 1 ) THEN
9702         IF(x_detail_rec.master_serial_number IS NOT NULL) THEN
9703                IF l_debug_on THEN
9704                    WSH_DEBUG_SV.log(l_module_name, 'Original container Flag', p_original_rec.container_flag);
9705                    WSH_DEBUG_SV.log(l_module_name, 'Master Serial Number', x_detail_rec.master_serial_number);
9706                END IF;
9707 
9708             -- Update of master serial number is allowed only if detail is a container
9709             -- And if the container is the top most container
9710 
9711 	    -- R12 MDC: For container_flag 'C' does not need additional logic because
9712 	    -- it is always topmost container. Only replaced ELSE condition with ELSIF
9713 	    -- to skip check for container flag 'C'
9714 
9715             IF(p_original_rec.container_flag = 'Y') THEN
9716 	       -- Verify if this is the top most container
9717                OPEN parent_detail_cur(x_detail_rec.delivery_detail_id);
9718                FETCH parent_detail_cur INTO l_parent_detail_id;
9719                CLOSE parent_detail_cur;
9720 
9721                IF(l_parent_detail_id IS NOT NULL) THEN
9722                   x_detail_rec.master_serial_number := p_original_rec.master_serial_number;
9723                   FND_MESSAGE.SET_NAME('WSH', 'WSH_UPDATE_MASTER_SERIAL');
9724                   wsh_util_core.add_message(wsh_util_core.g_ret_sts_warning, l_module_name);
9725                   RAISE WSH_UTIL_CORE.G_EXC_WARNING;
9726                END IF;
9727             ELSIF (p_original_rec.container_flag = 'N') THEN -- R12 MDC
9728                x_detail_rec.master_serial_number := p_original_rec.master_serial_number;
9729                FND_MESSAGE.SET_NAME('WSH', 'WSH_UPDATE_MASTER_SERIAL');
9730                wsh_util_core.add_message(wsh_util_core.g_ret_sts_warning, l_module_name);
9731                RAISE WSH_UTIL_CORE.G_EXC_WARNING;
9732             END IF;
9733         END IF;
9734 
9735      END IF;
9736 
9737      IF(p_validation_tab(WSH_ACTIONS_LEVELS.C_DET_INSPECT_FLAG_LVL) = 1 ) THEN
9738          -- Cannot set the inspection_Flag to N if it is already I or R
9739 
9740          IF x_detail_rec.inspection_flag IS NOT NULL THEN
9741             IF l_debug_on THEN
9742                WSH_DEBUG_SV.log(l_module_name, 'Original Inspec Flag', p_original_rec.inspection_flag);
9743                WSH_DEBUG_SV.log(l_module_name, 'Inspection Flag', x_detail_rec.inspection_flag);
9744             END IF;
9745 
9746             IF(x_detail_rec.inspection_flag = 'N' AND p_original_rec.inspection_flag IN ('I', 'R')) THEN
9747               x_detail_rec.inspection_flag := p_original_rec.inspection_flag;
9748               FND_MESSAGE.SET_NAME('WSH', 'WSH_UPDATE_INSPECT_FLAG');
9749             wsh_util_core.add_message(wsh_util_core.g_ret_sts_warning, l_module_name);
9750               RAISE WSH_UTIL_CORE.G_EXC_WARNING;
9751             END IF;
9752 
9753          END IF;
9754 
9755      END IF;
9756 
9757      IF(p_validation_tab(WSH_ACTIONS_LEVELS.C_MASTER_LPN_ITEM_LVL) = 1) THEN
9758         IF x_detail_rec.master_container_item_id IS NOT NULL THEN
9759 
9760                IF l_debug_on THEN
9761                    WSH_DEBUG_SV.log(l_module_name, 'Master cont item id', x_detail_rec.master_container_item_id);
9762                    WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_ITEM',WSH_DEBUG_SV.C_PROC_LEVEL);
9763                END IF;
9764 
9765            WSH_UTIL_VALIDATE.Validate_Item(
9766                      p_inventory_item_id => x_detail_rec.master_container_item_id,
9767                      p_inventory_item    => l_cont_item_name,
9768                      p_organization_id   => p_original_rec.organization_id,
9769                      p_seg_array         => l_cont_item_seg,
9770                      p_item_type         => 'CONT_ITEM',
9771                      x_return_status     => l_return_status);
9772 
9773                   --
9774                   wsh_util_core.api_post_call(
9775                       p_return_status => l_return_status,
9776                       x_num_warnings  => l_number_of_warnings,
9777                       x_num_errors    => l_number_of_errors,
9778                       p_msg_data      => l_msg_data
9779                       );
9780         END IF;
9781      END IF;
9782 
9783      IF(p_validation_tab(WSH_ACTIONS_LEVELS.C_DETAIL_LPN_ITEM_LVL) = 1) THEN
9784         IF x_detail_rec.detail_container_item_id IS NOT NULL THEN
9785 
9786                IF l_debug_on THEN
9787                    WSH_DEBUG_SV.log(l_module_name, 'Detail cont item id', x_detail_rec.Detail_container_item_id);
9788                    WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_VALIDATE.VALIDATE_ITEM',WSH_DEBUG_SV.C_PROC_LEVEL);
9789                END IF;
9790 
9791            WSH_UTIL_VALIDATE.Validate_Item(
9792                      p_inventory_item_id => x_detail_rec.detail_container_item_id,
9793                      p_inventory_item    => l_cont_item_name,
9794                      p_organization_id   => p_original_rec.organization_id,
9795                      p_seg_array         => l_cont_item_seg,
9796                      p_item_type         => 'CONT_ITEM',
9797                      x_return_status     => l_return_status);
9798 
9799                   --
9800                   wsh_util_core.api_post_call(
9801                       p_return_status => l_return_status,
9802                       x_num_warnings  => l_number_of_warnings,
9803                       x_num_errors    => l_number_of_errors,
9804                       p_msg_data      => l_msg_data
9805                       );
9806         END IF;
9807      END IF;
9808      IF l_debug_on THEN
9809        WSH_DEBUG_SV.log(l_module_name, 'x_detail_rec.delivered_quantity',x_detail_rec.delivered_quantity);
9810      END IF;
9811 -- HW OPMCONV - Removed branching
9812 
9813      --{
9814        IF (nvl(x_detail_rec.delivered_quantity, FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM) THEN
9815        --{
9816          x_detail_rec.delivered_quantity := round(x_detail_rec.delivered_quantity,wsh_util_core.c_max_decimal_digits_inv);
9817        --}
9818        END IF;
9819      --}
9820 
9821 
9822 
9823     FND_MSG_PUB.Count_And_Get
9824       (
9825         p_count  => x_msg_count,
9826         p_data  =>  x_msg_data,
9827         p_encoded => FND_API.G_FALSE
9828       );
9829 
9830       IF l_debug_on THEN
9831                 WSH_DEBUG_SV.pop(l_module_name);
9832       END IF;
9833 
9834     EXCEPTION
9835         WHEN FND_API.G_EXC_ERROR THEN
9836                 ROLLBACK TO VALIDATE_DET_COMMON_GRP;
9837                 x_return_status := FND_API.G_RET_STS_ERROR ;
9838                 FND_MSG_PUB.Count_And_Get
9839                   (
9840                      p_count  => x_msg_count,
9841                      p_data  =>  x_msg_data,
9842                p_encoded => FND_API.G_FALSE
9843                   );
9844                   --
9845               IF l_debug_on THEN
9846                 WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
9847                 WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_ERROR');
9848               END IF;
9849 
9850         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9851                 ROLLBACK TO VALIDATE_DET_COMMON_GRP;
9852                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
9853                 FND_MSG_PUB.Count_And_Get
9854                   (
9855                      p_count  => x_msg_count,
9856                      p_data  =>  x_msg_data,
9857                p_encoded => FND_API.G_FALSE
9858                   );
9859                   --
9860 
9861            IF l_debug_on THEN
9862                 WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
9863                 WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
9864            END IF;
9865 
9866         WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
9867              x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
9868              FND_MSG_PUB.Count_And_Get
9869               (
9870                 p_count  => x_msg_count,
9871                 p_data  =>  x_msg_data,
9872                 p_encoded => FND_API.G_FALSE
9873               );
9874         --
9875         IF l_debug_on THEN
9876             WSH_DEBUG_SV.logmsg(l_module_name,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ',WSH_DEBUG_SV.C_EXCEP_LEVEL);
9877            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
9878        END IF;
9879 
9880         WHEN OTHERS THEN
9881                 ROLLBACK TO VALIDATE_DET_COMMON_GRP;
9882                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9883                wsh_util_core.add_message(x_return_status, l_module_name);
9884                WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Validate_Detail_Common');
9885                 FND_MSG_PUB.Count_And_Get
9886                   (
9887                      p_count  => x_msg_count,
9888                      p_data  =>  x_msg_data,
9889                p_encoded => FND_API.G_FALSE
9890                   );
9891     --
9892 
9893             IF l_debug_on THEN
9894                 WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
9895                 WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
9896             END IF;
9897 
9898     END Validate_Detail_Common;
9899 
9900 /* ---------------------------------------------------------------------
9901    Procedure: Get_Serial_Quantity
9902 
9903    Parameters:
9904 
9905    Description:  This procedure is used to derive the serial quantity.
9906                  Procedure is created based on the function get_serial_qty
9907                  in WSHFSTRX.
9908    Created:   Harmonization Project. Patchset I. Bug fix 2652300
9909    ----------------------------------------------------------------------- */
9910 
9911 PROCEDURE get_serial_quantity(
9912           p_transaction_temp_id  IN  NUMBER,
9913           p_serial_number        IN  VARCHAR2,
9914           p_to_serial_number     IN  VARCHAR2,
9915           p_shipped_quantity     IN  VARCHAR2,
9916           x_serial_qty           OUT NOCOPY NUMBER,
9917           x_return_status        OUT NOCOPY VARCHAR2)
9918 IS
9919 
9920   cursor c_serial_qty(p_transaction_temp_id number) is
9921   SELECT   sum(nvl(msnt.serial_prefix, 0)) serial_qty
9922   FROM     mtl_serial_numbers_temp msnt
9923   WHERE    msnt.transaction_temp_id = p_transaction_temp_id
9924   GROUP BY msnt.transaction_temp_id;
9925 
9926   l_serial_qty c_serial_qty%ROWTYPE;
9927 
9928   l_debug_on Boolean;
9929 
9930   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'GET_SERIAL_QUANTITY';
9931 
9932 begin
9933 
9934       l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
9935       --
9936       IF l_debug_on IS NULL THEN
9937           l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
9938       END IF;
9939       --
9940         IF l_debug_on THEN
9941             WSH_DEBUG_SV.push(l_module_name);
9942             WSH_DEBUG_SV.log(l_module_name, 'Transaction Temp Id', p_transaction_temp_id);
9943             WSH_DEBUG_SV.log(l_module_name, 'Serial Number', p_serial_number);
9944             WSH_DEBUG_SV.log(l_module_name, 'To Serial Number', p_to_serial_number);
9945             WSH_DEBUG_SV.log(l_module_name, 'Shipped Qty', p_shipped_quantity);
9946         END IF;
9947         --
9948 
9949   x_return_status       := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
9950 
9951   if p_transaction_temp_id is not null then
9952 
9953     open c_serial_qty(p_transaction_temp_id);
9954     fetch c_serial_qty into l_serial_qty;
9955     if c_serial_qty%NOTFOUND then
9956        l_serial_qty.serial_qty := 0;
9957     end if;
9958     close c_serial_qty;
9959   elsif p_serial_number IS NOT NULL AND p_to_serial_number IS NOT NULL THEN
9960     l_serial_qty.serial_qty := p_shipped_quantity;
9961   elsif p_serial_number IS NOT NULL THEN
9962     l_serial_qty.serial_qty := 1;
9963   else
9964     l_serial_qty.serial_qty := 0;
9965   end if;
9966 
9967   x_serial_qty := NVL(l_serial_qty.serial_qty, 0);
9968 
9969       IF l_debug_on THEN
9970          wsh_debug_sv.log(l_module_name, 'Serial Qty', x_serial_qty);
9971          WSH_DEBUG_SV.pop(l_module_name);
9972       END IF;
9973 
9974 
9975 EXCEPTION
9976         WHEN FND_API.G_EXC_ERROR THEN
9977                 x_return_status := FND_API.G_RET_STS_ERROR ;
9978               IF l_debug_on THEN
9979                 WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
9980                 WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_ERROR');
9981               END IF;
9982 
9983         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9984                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
9985            IF l_debug_on THEN
9986                 WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
9987                 WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
9988            END IF;
9989 
9990         WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
9991              x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
9992         IF l_debug_on THEN
9993             WSH_DEBUG_SV.logmsg(l_module_name,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ',WSH_DEBUG_SV.C_EXCEP_LEVEL);
9994            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
9995        END IF;
9996 
9997         WHEN OTHERS THEN
9998                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9999                wsh_util_core.add_message(x_return_status, l_module_name);
10000                WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Get_Serial_Quantity');
10001     --
10002 
10003             IF l_debug_on THEN
10004                 WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
10005                 WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
10006             END IF;
10007 
10008 END get_serial_quantity;
10009 
10010 /*    ---------------------------------------------------------------------
10011     Procedure: Create_Update_Delivery_Detail (OVERLOADED)
10012 
10013     Parameters:
10014 
10015     Description:  This procedure is the new API for wrapping the logic of CREATE/UPDATE of delivery details
10016                      This OVERLOADED procedure has the additional parameter 'p_serial_range_tab'
10017     Created :   Patchset I
10018     ----------------------------------------------------------------------- */
10019 
10020     PROCEDURE Create_Update_Delivery_Detail
10021     (
10022        -- Standard Parameters
10023        p_api_version_number  IN  NUMBER,
10024        p_init_msg_list           IN    VARCHAR2,
10025        p_commit                  IN    VARCHAR2,
10026        x_return_status           OUT     NOCOPY  VARCHAR2,
10027        x_msg_count               OUT   NOCOPY  NUMBER,
10028        x_msg_data                OUT   NOCOPY  VARCHAR2,
10029 
10030        -- Procedure Specific Parameters
10031        p_detail_info_tab         IN   WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type,
10032        p_IN_rec                  IN   WSH_GLBL_VAR_STRCT_GRP.detailInRecType,
10033        x_OUT_rec                 OUT NOCOPY WSH_GLBL_VAR_STRCT_GRP.detailOutRecType,
10034        p_serial_range_tab        IN  WSH_GLBL_VAR_STRCT_GRP.ddSerialRangeTabType
10035     ) IS
10036 
10037         l_api_name              CONSTANT VARCHAR2(30)   := 'Create_Update_Delivery_Detail2';
10038         l_api_version           CONSTANT NUMBER         := 1.0;
10039         --
10040   --
10041   --
10042   l_return_status             VARCHAR2(32767);
10043   l1_return_status             VARCHAR2(32767);
10044   l_msg_count                 NUMBER;
10045   l_msg_data                  VARCHAR2(32767);
10046   l_program_name              VARCHAR2(32767);
10047         --
10048   l_number_of_errors    NUMBER := 0;
10049   l_number_of_warnings  NUMBER := 0;
10050   --
10051         l_loop_num_error      NUMBER := 0;
10052         l_loop_num_warn       NUMBER := 0;
10053         --
10054         l_counter             NUMBER := 0;
10055         l_index               NUMBER;
10056 
10057         l_detail_info_tab     WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type;
10058         l_valid_index_tab     wsh_util_core.id_tab_type;
10059         l_delivery_id         NUMBER;
10060         l_delivery_detail_rec WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Rec_Type;
10061         l_validation_tab      wsh_util_core.id_tab_type;
10062   --
10063         l_details_marked        WSH_UTIL_CORE.Id_Tab_Type;
10064         mark_reprice_error      EXCEPTION;
10065 
10066         --
10067         CURSOR det_to_del_cur(p_detail_id NUMBER) IS
10068            SELECT wda.delivery_id
10069            FROM wsh_delivery_assignments_v wda
10070            WHERE wda.delivery_detail_id = p_detail_id;
10071 
10072 -- anxsharm for Load Tender
10073         l_detail_tender_tab wsh_util_core.id_tab_type;
10074         l_trip_id_tab wsh_util_core.id_tab_type;
10075 
10076         --
10077         l_weight_uom_code     VARCHAR2(10);
10078         l_volume_uom_code     VARCHAR2(10);
10079 l_debug_on BOOLEAN;
10080   --
10081   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CREATE_UPDATE_DELIVERY_DETAIL2';
10082   --
10083   -- Following 4 variables are added for bugfix #4070732
10084   l_api_session_name CONSTANT VARCHAR2(150) := G_PKG_NAME ||'.' || l_module_name;
10085   l_reset_flags BOOLEAN;
10086   --
10087   BEGIN
10088 	-- Bugfix 4070732
10089 	IF WSH_UTIL_CORE.G_START_OF_SESSION_API is null
10090 	THEN
10091 		WSH_UTIL_CORE.G_START_OF_SESSION_API     := l_api_session_name;
10092 		WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API := FALSE;
10093 	END IF;
10094 	-- End of Code Bugfix 4070732
10095 
10096         -- Standard Start of API savepoint
10097         SAVEPOINT   CREATE_UPDATE_DEL_DETAIL_GRP2;
10098         --
10099         l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
10100         --
10101         IF l_debug_on IS NULL
10102         THEN
10103             l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
10104         END IF;
10105         --
10106 
10107         --
10108         -- Debug Statements
10109         --
10110         IF l_debug_on THEN
10111             WSH_DEBUG_SV.push(l_module_name);
10112             --
10113             WSH_DEBUG_SV.log(l_module_name,'P_API_VERSION_NUMBER',P_API_VERSION_NUMBER);
10114             WSH_DEBUG_SV.log(l_module_name,'P_INIT_MSG_LIST',P_INIT_MSG_LIST);
10115             WSH_DEBUG_SV.log(l_module_name,'P_COMMIT',P_COMMIT);
10116             WSH_DEBUG_SV.log(l_module_name, 'Caller', p_In_rec.caller);
10117             WSH_DEBUG_SV.log(l_module_name, 'Action Code', p_In_rec.action_code);
10118             WSH_DEBUG_SV.log(l_module_name,'Input Table count', p_detail_info_tab.count);
10119         END IF;
10120         --
10121 
10122         -- Initialize message list if p_init_msg_list is set to TRUE.
10123   --
10124   --
10125         IF FND_API.to_Boolean( p_init_msg_list )
10126   THEN
10127                 FND_MSG_PUB.initialize;
10128         END IF;
10129   --
10130   --
10131         --  Initialize API return status to success
10132   x_return_status       := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
10133   l_number_of_errors := 0;
10134   l_number_of_warnings := 0;
10135 
10136         -- Check for generic mandatory parameters
10137         IF p_In_rec.caller IS NULL THEN
10138             FND_MESSAGE.SET_NAME('WSH', 'WSH_REQUIRED_FIELD_NULL');
10139             FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'CALLER');
10140             wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
10141            IF l_debug_on THEN
10142               wsh_debug_sv.logmsg(l_module_name,'Null Caller');
10143            END IF;
10144             RAISE FND_API.G_EXC_ERROR;
10145         END IF;
10146 
10147         IF p_In_rec.action_code IS NULL THEN
10148             FND_MESSAGE.SET_NAME('WSH', 'WSH_REQUIRED_FIELD_NULL');
10149             FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'ACTION_CODE');
10150             wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
10151            IF l_debug_on THEN
10152               wsh_debug_sv.logmsg(l_module_name,'Null Action Code');
10153            END IF;
10154             RAISE FND_API.G_EXC_ERROR;
10155         ELSIF(p_In_rec.action_code NOT IN('CREATE', 'UPDATE', 'CANCEL')
10156               OR (p_In_rec.action_code = 'CANCEL' AND p_In_rec.caller <> 'WSH_INBOUND')) THEN
10157            FND_MESSAGE.SET_NAME('WSH','WSH_INVALID_ACTION_CODE');
10158            FND_MESSAGE.SET_TOKEN('ACT_CODE',p_In_rec.action_code );
10159             wsh_util_core.add_message(wsh_util_core.g_ret_sts_error, l_module_name);
10160            IF l_debug_on THEN
10161               wsh_debug_sv.logmsg(l_module_name,'WSH_INVALID_ACTION_CODE');
10162            END IF;
10163             RAISE FND_API.G_EXC_ERROR;
10164         END IF;
10165 
10166         -- Set Validation Level
10167 
10168         IF l_debug_on THEN
10169             WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_ACTIONS_LEVELS.SET_VALIDATION_LEVEL',WSH_DEBUG_SV.C_PROC_LEVEL);
10170         END IF;
10171         --
10172         wsh_actions_levels.set_validation_level(
10173             p_entity           => 'DLVB',
10174             p_caller           => p_In_rec.caller,
10175             p_phase            => p_In_rec.phase,
10176             p_action           => p_In_rec.action_code,
10177             x_return_status    => l_return_status
10178         );
10179 
10180                   --
10181                   wsh_util_core.api_post_call(
10182                       p_return_status => l_return_status,
10183                       x_num_warnings  => l_number_of_warnings,
10184                       x_num_errors    => l_number_of_errors,
10185                       p_msg_data      => l_msg_data
10186                       );
10187                --
10188         l_validation_tab := WSH_ACTIONS_LEVELS.G_VALIDATION_LEVEL_TAB;
10189 
10190         -- Get Disabled List
10191         --
10192       IF(l_validation_tab(WSH_ACTIONS_LEVELS.C_DISABLED_LIST_LVL) = 1) THEN
10193         l_index := p_detail_info_tab.FIRST;
10194         WHILE l_index IS NOT NULL
10195         LOOP
10196             --
10197           BEGIN
10198             SAVEPOINT before_det_disabled_grp;
10199 
10200             OPEN det_to_del_cur(p_detail_info_tab(l_index).delivery_detail_id);
10201             FETCH det_to_del_Cur INTO l_delivery_id;
10202             CLOSE det_to_del_Cur;
10203 
10204             IF l_debug_on THEN
10205                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DETAILS_VALIDATIONS.GET_DISABLED_LIST',WSH_DEBUG_SV.C_PROC_LEVEL);
10206             END IF;
10207             --
10208 
10209             IF p_In_rec.caller LIKE 'WMS%' AND p_in_rec.action_code ='UPDATE'
10210             THEN
10211                l_weight_uom_code := p_detail_info_tab(l_index).weight_uom_code;
10212                l_volume_uom_code := p_detail_info_tab(l_index).volume_uom_code;
10213                IF l_debug_on THEN
10214                   WSH_DEBUG_SV.log(l_module_name,'l_weight_uom_code',
10215                                                             l_weight_uom_code);
10216                   WSH_DEBUG_SV.log(l_module_name,'l_volume_uom_code',
10217                                                             l_volume_uom_code);
10218                END IF;
10219 
10220             END IF;
10221 
10222             wsh_details_validations.get_disabled_list(
10223                 --
10224                 p_delivery_detail_rec   =>   p_detail_info_tab(l_index),
10225                 p_delivery_id           =>   l_delivery_id,
10226                 p_in_rec                =>   p_In_rec,
10227                 x_return_status         =>   l_return_status,
10228                 x_msg_count             =>   l_msg_count,
10229                 x_msg_data              =>   l_msg_data,
10230                 x_delivery_detail_rec   =>   l_delivery_detail_rec
10231                  );
10232 
10233 
10234                   --
10235                   wsh_util_core.api_post_call(
10236                       p_return_status => l_return_status,
10237                       x_num_warnings  => l_loop_num_warn,
10238                       x_num_errors    => l_loop_num_error,
10239                       p_msg_data      => l_msg_data
10240                       );
10241 
10242                 -- lpn conv
10243                 -- IF WMS passes different UOM then convert
10244                 IF p_In_rec.caller LIKE 'WMS%'
10245                   AND p_in_rec.action_code ='UPDATE'
10246                   AND l_delivery_detail_rec.container_flag in ('Y', 'C')
10247                 THEN
10248                    IF l_weight_uom_code <>
10249                                    l_delivery_detail_rec.weight_uom_code
10250                      AND l_weight_uom_code <> FND_API.G_MISS_CHAR
10251                    THEN
10252                       l_delivery_detail_rec.gross_weight :=
10253                               WSH_WV_UTILS.Convert_Uom_core (
10254                                      from_uom => l_weight_uom_code,
10255                                      to_uom => l_delivery_detail_rec.weight_uom_code,
10256                                      quantity => l_delivery_detail_rec.gross_weight,
10257                                      item_id => l_delivery_detail_rec.inventory_item_id,
10258                                      x_return_status => l_return_status );
10259 
10260                       wsh_util_core.api_post_call(
10261                          p_return_status => l_return_status,
10262                          x_num_warnings  => l_loop_num_warn,
10263                          x_num_errors    => l_loop_num_error
10264                          );
10265 
10266                       l_delivery_detail_rec.net_weight :=
10267                               WSH_WV_UTILS.Convert_Uom_core (
10268                                      from_uom => l_weight_uom_code,
10269                                      to_uom => l_delivery_detail_rec.weight_uom_code,
10270                                      quantity => l_delivery_detail_rec.net_weight,
10271                                      item_id => l_delivery_detail_rec.inventory_item_id,
10272                                      x_return_status => l_return_status);
10273 
10274                               wsh_util_core.api_post_call(
10275                                  p_return_status => l_return_status,
10276                                  x_num_warnings  => l_loop_num_warn,
10277                                  x_num_errors    => l_loop_num_error
10278                                  );
10279                       IF l_debug_on THEN
10280                          WSH_DEBUG_SV.log(l_module_name,'net_weight',
10281                                          l_delivery_detail_rec.net_weight);
10282                          WSH_DEBUG_SV.log(l_module_name,'gross_weight',
10283                                       l_delivery_detail_rec.gross_weight);
10284                          WSH_DEBUG_SV.log(l_module_name,'database uom',
10285                                    l_delivery_detail_rec.weight_uom_code);
10286                          WSH_DEBUG_SV.log(l_module_name,'item_id',
10287                                  l_delivery_detail_rec.inventory_item_id);
10288                       END IF;
10289 
10290                    END IF;
10291                    IF l_volume_uom_code <>
10292                                     l_delivery_detail_rec.volume_uom_code
10293                      AND l_volume_uom_code <> FND_API.G_MISS_CHAR
10294                    THEN
10295 
10296                       l_delivery_detail_rec.volume :=
10297                               WSH_WV_UTILS.Convert_Uom_core (
10298                                      from_uom => l_volume_uom_code,
10299                                      to_uom => l_delivery_detail_rec.volume_uom_code,
10300                                      quantity => l_delivery_detail_rec.volume,
10301                                      item_id => l_delivery_detail_rec.inventory_item_id,
10302                                      x_return_status => l_return_status);
10303 
10304                       wsh_util_core.api_post_call(
10305                                  p_return_status => l_return_status,
10306                                  x_num_warnings  => l_loop_num_warn,
10307                                  x_num_errors    => l_loop_num_error
10308                                  );
10309 
10310                       l_delivery_detail_rec.filled_volume :=
10311                            WSH_WV_UTILS.Convert_Uom_core (
10312                                   from_uom => l_volume_uom_code,
10313                                   to_uom => l_delivery_detail_rec.volume_uom_code,
10314                                   quantity => l_delivery_detail_rec.filled_volume,
10315                                   item_id => l_delivery_detail_rec.inventory_item_id,
10316                                   x_return_status => l_return_status);
10317                       wsh_util_core.api_post_call(
10318                                  p_return_status => l_return_status,
10319                                  x_num_warnings  => l_loop_num_warn,
10320                                  x_num_errors    => l_loop_num_error
10321                                  );
10322                       IF l_debug_on THEN
10323                          WSH_DEBUG_SV.log(l_module_name,'volume',
10324                                             l_delivery_detail_rec.volume);
10325                          WSH_DEBUG_SV.log(l_module_name,'filled_volume',
10326                                       l_delivery_detail_rec.filled_volume);
10327                          WSH_DEBUG_SV.log(l_module_name,'database uom',
10328                                    l_delivery_detail_rec.volume_uom_code);
10329                          WSH_DEBUG_SV.log(l_module_name,'item_id',
10330                                  l_delivery_detail_rec.inventory_item_id);
10331                       END IF;
10332                    END IF;
10333 
10334                 END IF;
10335                 l_detail_info_tab(l_index) := l_delivery_detail_rec;
10336           EXCEPTION
10337              WHEN FND_API.G_EXC_ERROR THEN
10338                  ROLLBACK TO  before_det_disabled_grp;
10339                  IF l_debug_on THEN
10340                     wsh_debug_sv.logmsg(l_module_name, 'g exc error');
10341                  END IF;
10342              WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
10343                  ROLLBACK TO before_det_disabled_grp;
10344                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10345              WHEN OTHERS THEN
10346                  ROLLBACK TO before_det_disabled_grp;
10347                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10348 
10349           END;
10350           l_weight_uom_code := NULL;
10351           l_volume_uom_code := NULL;
10352           l_index := p_detail_info_tab.NEXT(l_index);
10353         END LOOP;
10354 
10355           IF l_debug_on THEN
10356              wsh_debug_sv.log(l_module_name, 'Number of errors after loop', l_loop_num_error);
10357              wsh_debug_sv.log(l_module_name, 'New table count', l_detail_info_tab.count);
10358           END IF;
10359 
10360        -- For create container, the table count will be zero
10361        -- Should not set error for that container case
10362 --bmso check the case where container is created and the detail_info_tab > 0
10363         IF p_detail_info_tab.count > 0 THEN
10364           IF l_loop_num_error = p_detail_info_tab.count THEN
10365              IF l_debug_on THEN
10366                     wsh_debug_sv.logmsg(l_module_name, 'get disabled list fail all records');
10367              END IF;
10368              RAISE FND_API.G_EXC_ERROR;
10369           ELSE
10370              l_number_of_warnings := l_loop_num_error;
10371           END IF;
10372         END IF;
10373 
10374        ELSE
10375            -- if the validation level for disabled list is turned off
10376            -- then we initialize the local table using the input table directly
10377            -- this will be applicable when caller is WSHFSTRX.
10378            IF l_debug_on THEN
10379               wsh_debug_sv.logmsg(l_module_name, 'Get Disabled turned off');
10380            END IF;
10381            l_detail_info_tab := p_detail_info_tab;
10382        --
10383        END IF; -- if check for C_DISABLED_LIST_LVL
10384 
10385        IF(p_in_rec.action_code ='UPDATE' AND l_detail_info_tab.count < 1) THEN
10386            -- Should not proceed further
10387            IF l_debug_on THEN
10388               wsh_debug_sv.logmsg(l_module_name,'Table Count Zero');
10389            END IF;
10390            RAISE FND_API.G_EXC_ERROR;
10391        END IF;
10392 
10393 -- anxsharm for Load Tender
10394           IF(l_validation_tab(WSH_ACTIONS_LEVELS.C_WMS_CONTAINERS_LVL) = 1) THEN--{ lpn conv
10395              Validate_Delivery_Detail(
10396                 x_detail_info_tab  => l_detail_info_tab,
10397                 p_in_detail_tab    =>  p_detail_info_tab,
10398                 p_action           => p_In_rec.action_code,
10399                 p_validation_tab   => l_validation_tab,
10400                 p_caller           => p_In_rec.caller,
10401                 x_valid_index_tab  => l_valid_index_tab,
10402                 x_details_marked   => l_details_marked,
10403                 x_detail_tender_tab =>l_detail_tender_tab,
10404                 x_return_status    => l_return_status,
10405                 x_msg_count        =>  l_msg_count,
10406                 x_msg_data         => l_msg_data,
10407                 p_in_rec           => p_in_rec,
10408                 p_serial_range_tab => p_serial_range_tab);
10409 
10410                   --
10411                   wsh_util_core.api_post_call(
10412                       p_return_status => l_return_status,
10413                       x_num_warnings  => l_number_of_warnings,
10414                       x_num_errors    => l_number_of_errors,
10415                       p_msg_data      => l_msg_data
10416                       );
10417        END IF; --} lpn conv
10418        IF(p_In_rec.action_code = 'CREATE') THEN
10419             --
10420             Create_Delivery_Detail(
10421                 p_detail_info_tab => l_detail_info_tab,
10422                 p_detail_IN_rec   => p_in_rec ,
10423                 p_valid_index_tab => l_valid_index_tab,
10424                 x_detail_OUT_rec        => x_out_rec,
10425                 x_return_status   => l_return_status,
10426                 x_msg_count            =>  l_msg_count,
10427                 x_msg_data             => l_msg_data);
10428 
10429                   --
10430                   wsh_util_core.api_post_call(
10431                       p_return_status => l_return_status,
10432                       x_num_warnings  => l_number_of_warnings,
10433                       x_num_errors    => l_number_of_errors,
10434                       p_msg_data      => l_msg_data
10435                       );
10436 
10437 
10438        ELSIF(p_In_rec.action_code = 'UPDATE') THEN
10439 
10440              IF( WSH_UTIL_CORE.FTE_Is_Installed = 'Y') THEN
10441     IF l_details_marked.count > 0 THEN
10442       --
10443       IF l_debug_on THEN
10444           WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_LEGS_ACTIONS.MARK_REPRICE_REQUIRED',WSH_DEBUG_SV.C_PROC_LEVEL);
10445       END IF;
10446       --
10447       WSH_DELIVERY_LEGS_ACTIONS.Mark_Reprice_Required(
10448          p_entity_type => 'DELIVERY_DETAIL',
10449          p_entity_ids   => l_details_marked,
10450          x_return_status => l_return_status);
10451 
10452                   --
10453                   wsh_util_core.api_post_call(
10454                       p_return_status => l_return_status,
10455                       x_num_warnings  => l_number_of_warnings,
10456                       x_num_errors    => l_number_of_errors,
10457                       p_msg_data      => l_msg_data
10458                       );
10459 
10460       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10461          raise mark_reprice_error;
10462       END IF;
10463     END IF;
10464               END IF;
10465 
10466             IF nvl(WSH_WMS_LPN_GRP.g_caller,'WSH') like 'WMS%' THEN --{
10467                --
10468                IF l_valid_index_tab.COUNT <> l_detail_info_tab.COUNT THEN
10469                   --
10470                   IF l_debug_on THEN
10471                       --
10472                       WSH_DEBUG_SV.logmsg(l_module_name,'ERROR not all line are validated successfully',WSH_DEBUG_SV.C_PROC_LEVEL);
10473                       WSH_DEBUG_SV.log(l_module_name,'valid count',l_valid_index_tab.COUNT);
10474                       WSH_DEBUG_SV.log(l_module_name,'total count',l_detail_info_tab.COUNT);
10475                       --
10476                   END IF;
10477                   --
10478                   RAISE FND_API.G_EXC_ERROR;
10479                   --
10480                END IF;
10481                --
10482             END IF; --}
10483 
10484             Update_Delivery_Detail(
10485                 p_detail_info_tab      => l_detail_info_tab,
10486                 p_valid_index_tab      => l_valid_index_tab,
10487                 x_return_status        => l_return_status,
10488                 x_msg_count            => l_msg_count,
10489                 x_msg_data             => l_msg_data,
10490                 p_caller               => p_in_rec.caller);
10491 
10492                   --
10493                   wsh_util_core.api_post_call(
10494                       p_return_status => l_return_status,
10495                       x_num_warnings  => l_number_of_warnings,
10496                       x_num_errors    => l_number_of_errors,
10497                       p_msg_data      => l_msg_data
10498                       );
10499 
10500 -- jckwok: code for action_code = 'CANCEL'
10501   ELSIF (p_in_rec.action_code = 'CANCEL') THEN
10502 
10503       Cancel_Delivery_Detail(
10504                 p_detail_info_tab     =>  l_detail_info_tab,
10505                 x_return_status       =>  l_return_status,
10506                 x_msg_count           =>  l_msg_count,
10507                 x_msg_data            =>  l_msg_data,
10508                 p_caller              =>  p_in_rec.caller);
10509 
10510             wsh_util_core.api_post_call(p_return_status  =>l_return_status,
10511                                   x_num_warnings     =>l_number_of_warnings,
10512                                   x_num_errors       =>l_number_of_errors);
10513 
10514 -- jckwok
10515 
10516        END IF;
10517 
10518        IF l_number_of_warnings > 0 THEN
10519          IF l_debug_on THEN
10520             wsh_debug_sv.log(l_module_name, 'Number of warnings', l_number_of_warnings);
10521          END IF;
10522 
10523          RAISE wsh_util_core.g_exc_warning;
10524       END IF;
10525 
10526        -- Standard check of p_commit.
10527        IF FND_API.To_Boolean( p_commit ) THEN
10528           IF(l_debug_on) THEN
10529              wsh_debug_sv.logmsg(l_module_name, 'Commit Work');
10530           END IF;
10531                --
10532                -- Start code for Bugfix 4070732
10533                --
10534               IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
10535                  IF l_debug_on THEN
10536                     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Process_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
10537                  END IF;
10538 
10539                  l_reset_flags := FALSE;
10540 
10541                  WSH_UTIL_CORE.Process_stops_for_load_tender(p_reset_flags   => l_reset_flags,
10542 						       x_return_status => l_return_status);
10543 
10544                  IF l_debug_on THEN
10545                     WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
10546                  END IF;
10547 
10548                  IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
10549                     RAISE FND_API.G_EXC_ERROR;
10550                  ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
10551                     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10552                  ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10553                     RAISE WSH_UTIL_CORE.G_EXC_WARNING;
10554                  END IF;
10555 
10556               END IF;
10557              --
10558              -- End of code for Bugfix 4070732
10559              --
10560           COMMIT WORK;
10561        END IF;
10562 
10563            --bug 4070732
10564            --End of the API handling of calls to process_stops_for_load_tender
10565           IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name) THEN
10566           --{
10567              IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
10568              --{
10569 
10570                 IF FND_API.TO_BOOLEAN(p_commit) THEN
10571 
10572                  IF l_debug_on THEN
10573                     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
10574                  END IF;
10575 
10576                  WSH_UTIL_CORE.reset_stops_for_load_tender(p_reset_flags   => TRUE,
10577                                                         x_return_status => l_return_status);
10578 		ELSE
10579 
10580                  IF l_debug_on THEN
10581                     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Process_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
10582                  END IF;
10583 
10584                  WSH_UTIL_CORE.Process_stops_for_load_tender(p_reset_flags   => TRUE,
10585                                                         x_return_status => l_return_status);
10586 		END IF;
10587 
10588                  IF l_debug_on THEN
10589                     WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
10590                  END IF;
10591 
10592 
10593                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10594                     x_return_status := l_return_status;
10595 
10596                     IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,
10597                                    WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
10598                     THEN
10599                        IF NOT(FND_API.TO_BOOLEAN(p_commit)) THEN
10600                         ROLLBACK TO CREATE_UPDATE_DEL_DETAIL_GRP2;
10601 		       END IF;
10602                     END IF;
10603                  END IF;
10604                --}
10605               END IF;
10606            --}
10607           END IF;
10608 
10609     --bug 4070732
10610        FND_MSG_PUB.Count_And_Get
10611          (
10612           p_count  => x_msg_count,
10613           p_data  =>  x_msg_data,
10614           p_encoded => FND_API.G_FALSE
10615          );
10616 
10617 
10618       IF l_debug_on THEN
10619          WSH_DEBUG_SV.pop(l_module_name);
10620       END IF;
10621 --
10622   EXCEPTION
10623         WHEN FND_API.G_EXC_ERROR THEN
10624                 ROLLBACK TO CREATE_UPDATE_DEL_DETAIL_GRP2;
10625                 x_return_status := FND_API.G_RET_STS_ERROR ;
10626              --
10627              -- Start code for Bugfix 4070732
10628              --
10629              IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name)
10630              THEN
10631              --{
10632                 IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
10633                 --{
10634                   IF l_debug_on THEN
10635                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
10636                   END IF;
10637 
10638                   WSH_UTIL_CORE.Reset_stops_for_load_tender(p_reset_flags   => TRUE,
10639                      x_return_status => l_return_status);
10640 
10641                   IF l_debug_on THEN
10642                      WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
10643                   END IF;
10644 
10645                   IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
10646                      x_return_status := l_return_status;
10647                   END IF;
10648                 --}
10649                 END IF;
10650               --}
10651              END IF;
10652              --
10653              -- End of Code Bugfix 4070732
10654              --
10655                 FND_MSG_PUB.Count_And_Get
10656                   (
10657                      p_count  => x_msg_count,
10658                      p_data  =>  x_msg_data,
10659                p_encoded => FND_API.G_FALSE
10660                   );
10661 
10662 
10663 
10664                   --
10665                   IF l_debug_on THEN
10666                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
10667                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_ERROR');
10668                   END IF;
10669                   --
10670         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
10671                 ROLLBACK TO CREATE_UPDATE_DEL_DETAIL_GRP2;
10672                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
10673              --
10674              -- Start code for Bugfix 4070732
10675              --
10676              IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name)
10677              THEN
10678              --{
10679                 IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
10680                 --{
10681                   IF l_debug_on THEN
10682                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
10683                   END IF;
10684 
10685                   WSH_UTIL_CORE.Reset_stops_for_load_tender(p_reset_flags   => TRUE,
10686                      x_return_status => l_return_status);
10687 
10688                   IF l_debug_on THEN
10689                      WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
10690                   END IF;
10691                 --}
10692                 END IF;
10693               --}
10694              END IF;
10695              --
10696              -- End of Code Bugfix 4070732
10697              --
10698                 FND_MSG_PUB.Count_And_Get
10699                   (
10700                      p_count  => x_msg_count,
10701                      p_data  =>  x_msg_data,
10702                p_encoded => FND_API.G_FALSE
10703                   );
10704 
10705 
10706 
10707                   --
10708                   IF l_debug_on THEN
10709                       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
10710                       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
10711                   END IF;
10712                   --
10713         WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
10714              x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
10715              --
10716              -- Start code for Bugfix 4070732
10717              --
10718             IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name) THEN
10719               IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
10720                 IF l_debug_on THEN
10721                    WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Process_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
10722                  END IF;
10723 
10724                   WSH_UTIL_CORE.Process_stops_for_load_tender(p_reset_flags   => TRUE,
10725                                                          x_return_status => l_return_status);
10726 
10727                   IF l_debug_on THEN
10728                      WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
10729                   END IF;
10730 
10731                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10732                       x_return_status := l_return_status;
10733 
10734                     IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,
10735                                    WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
10736                     THEN
10737                         ROLLBACK TO CREATE_UPDATE_DEL_DETAIL_GRP2;
10738                     END IF;
10739                   END IF;
10740 
10741                END IF;
10742             END IF;
10743             --
10744             -- End of Code Bugfix 4070732
10745             --
10746              FND_MSG_PUB.Count_And_Get
10747               (
10748                 p_count  => x_msg_count,
10749                 p_data  =>  x_msg_data,
10750                 p_encoded => FND_API.G_FALSE
10751               );
10752 
10753 
10754 
10755         --
10756         IF l_debug_on THEN
10757             WSH_DEBUG_SV.logmsg(l_module_name,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ',WSH_DEBUG_SV.C_EXCEP_LEVEL);
10758            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
10759        END IF;
10760 --
10761         WHEN mark_reprice_error then
10762                 FND_MESSAGE.Set_Name('WSH', 'WSH_REPRICE_REQUIRED_ERR');
10763                 wsh_util_core.add_message(x_return_status, l_module_name);
10764                 x_return_status := l_return_status;
10765              --
10766              -- Start code for Bugfix 4070732
10767              --
10768             IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name) THEN
10769               IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
10770                 IF l_debug_on THEN
10771                    WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Process_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
10772                  END IF;
10773 
10774                   WSH_UTIL_CORE.Process_stops_for_load_tender(p_reset_flags   => TRUE,
10775                                                          x_return_status => l1_return_status);
10776 
10777                   IF l_debug_on THEN
10778                      WSH_DEBUG_SV.log(l_module_name,'l1_return_status',l1_return_status);
10779                   END IF;
10780 
10781                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
10782                    IF l1_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10783                       IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
10784                         IF l1_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10785                           l_return_status := l1_return_status;
10786 			END IF;
10787 		      ELSE
10788                          l_return_status := l1_return_status;
10789 		      END IF;
10790                    END IF;
10791                  END IF;
10792 
10793                  x_return_status := l_return_status;
10794                     IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,
10795                                    WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
10796                     THEN
10797                         ROLLBACK TO CREATE_UPDATE_DEL_DETAIL_GRP2;
10798                     END IF;
10799 
10800                END IF;
10801             END IF;
10802             --
10803             -- End of Code Bugfix 4070732
10804             --
10805                  FND_MSG_PUB.Count_And_Get
10806                   (
10807                      p_count  => x_msg_count,
10808                      p_data  =>  x_msg_data,
10809                p_encoded => FND_API.G_FALSE
10810                   );
10811     --
10812 
10813                 --
10814                 IF l_debug_on THEN
10815                     WSH_DEBUG_SV.logmsg(l_module_name,'MARK_REPRICE_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
10816                     WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:MARK_REPRICE_ERROR');
10817                 END IF;
10818                 --
10819         WHEN OTHERS THEN
10820                 ROLLBACK TO CREATE_UPDATE_DEL_DETAIL_GRP2;
10821                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
10822                wsh_util_core.add_message(x_return_status, l_module_name);
10823                WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Create_Update_Delivery_Detail');
10824              --
10825              -- Start code for Bugfix 4070732
10826              --
10827              IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name)
10828              THEN
10829              --{
10830                 IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
10831                 --{
10832                   IF l_debug_on THEN
10833                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
10834                   END IF;
10835 
10836                   WSH_UTIL_CORE.Reset_stops_for_load_tender(p_reset_flags   => TRUE,
10837                      x_return_status => l_return_status);
10838 
10839                   IF l_debug_on THEN
10840                      WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
10841                   END IF;
10842                 --}
10843                 END IF;
10844               --}
10845              END IF;
10846              --
10847              -- End of Code Bugfix 4070732
10848              --
10849                 FND_MSG_PUB.Count_And_Get
10850                   (
10851                      p_count  => x_msg_count,
10852                      p_data  =>  x_msg_data,
10853                p_encoded => FND_API.G_FALSE
10854                   );
10855     --
10856 
10857 
10858           IF l_debug_on THEN
10859                WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
10860                WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
10861          END IF;
10862 --
10863   END Create_Update_Delivery_Detail;
10864 
10865 -- ---------------------------------------------------------------------
10866 -- Procedure: Get_Carton_Grouping
10867 --
10868 -- Parameters:
10869 --
10870 -- Description:  This procedure is the new API for wrapping the logic of autcreate_deliveries.
10871 -- Usage: Called by WMS code to return carton grouping table.
10872 -- Bug 6790938 :
10873 -- Calling Find_Matching_Groups api instead of calling Autocreate_deliveries
10874 -- -----------------------------------------------------------------------
10875 -- Added for Bug 4295161
10876 PROCEDURE Get_Carton_Grouping (p_line_rows             IN          WSH_UTIL_CORE.id_tab_type,
10877                                x_grouping_rows         OUT NOCOPY  WSH_UTIL_CORE.id_tab_type,
10878                                x_return_status         OUT NOCOPY  VARCHAR2) IS
10879 
10880   l_attr_tab          wsh_delivery_autocreate.grp_attr_tab_type;
10881   l_group_tab         wsh_delivery_autocreate.grp_attr_tab_type;
10882   l_action_rec        wsh_delivery_autocreate.action_rec_type;
10883   l_target_rec        wsh_delivery_autocreate.grp_attr_rec_type;
10884   l_matched_entities  wsh_util_core.id_tab_type;
10885   l_out_rec           wsh_delivery_autocreate.out_rec_type;
10886 
10887   l_debug_on Boolean;
10888 
10889   --bug 7171766
10890   l_match_found BOOLEAN;
10891   l_group_match_seq_tbl    WSH_PICK_LIST.group_match_seq_tab_type;
10892   K NUMBER ;
10893 
10894   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'GET_CARTON_GROUPING';
10895 
10896 BEGIN
10897 
10898   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
10899   --
10900   IF l_debug_on IS NULL THEN
10901     l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
10902   END IF;
10903   --
10904   IF l_debug_on THEN
10905     WSH_DEBUG_SV.push(l_module_name);
10906     WSH_DEBUG_SV.LOG(l_module_name, 'Count of p_line_rows-', p_line_rows.count);
10907   END IF;
10908   --
10909   x_return_status :=  FND_API.G_RET_STS_SUCCESS;
10910 
10911   FOR i in 1..p_line_rows.count
10912   LOOP
10913      l_attr_tab(i).entity_id   := p_line_rows(i);
10914      l_attr_tab(i).entity_type := 'DELIVERY_DETAIL';
10915   END LOOP;
10916   l_action_rec.action := 'MATCH_GROUPS';
10917 
10918   IF l_debug_on THEN
10919     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_AUTOCREATE.Find_Matching_Groups', WSH_DEBUG_SV.C_PROC_LEVEL);
10920   END IF;
10921   WSH_DELIVERY_AUTOCREATE.Find_Matching_Groups (
10922                p_attr_tab          =>  l_attr_tab,
10923                p_action_rec        =>  l_action_rec,
10924                p_target_rec        =>  l_target_rec,
10925                p_group_tab         =>  l_group_tab,
10926                x_matched_entities  =>  l_matched_entities,
10927                x_out_rec           =>  l_out_rec,
10928                x_return_status     =>  x_return_status );
10929 
10930  --bug 7171766
10931   l_group_match_seq_tbl.delete;
10932 
10933   FOR i in 1.. l_attr_tab.count LOOP
10934   --{
10935       l_match_found :=FALSE;
10936       IF l_group_match_seq_tbl.count > 0 THEN
10937       --{
10938           FOR k in l_group_match_seq_tbl.FIRST..l_group_match_seq_tbl.LAST LOOP
10939           --{
10940 	      IF l_attr_tab(i).group_id = l_group_match_seq_tbl(k).match_group_id THEN
10941 	      --{
10942 	          l_group_match_seq_tbl(i).delivery_group_id := l_group_match_seq_tbl(k).delivery_group_id ;
10943 	          l_match_found := TRUE;
10944 	          EXIT;
10945               --}
10946               End IF;
10947           --}
10948          END LOOP;
10949      --}
10950      END IF ;
10951 
10952      IF NOT l_match_found THEN
10953      --{
10954          l_group_match_seq_tbl(i).match_group_id :=l_attr_tab(i).group_id;
10955          select WSH_DELIVERY_GROUP_S.nextval into l_group_match_seq_tbl(i).delivery_group_id  from dual;
10956      --}
10957      End IF;
10958 
10959      x_grouping_rows(i) := l_group_match_seq_tbl(i).delivery_group_id;
10960   --}
10961   END LOOP;
10962   --bug 7171766 till here
10963 
10964   IF l_debug_on THEN
10965     WSH_DEBUG_SV.LOG(l_module_name, 'Count of x_grouping_rows -', x_grouping_rows.count);
10966     WSH_DEBUG_SV.LOG(l_module_name, 'x_return_status', x_return_status);
10967     WSH_DEBUG_SV.pop(l_module_name);
10968   END IF;
10969 
10970 EXCEPTION
10971   WHEN FND_API.G_EXC_ERROR THEN
10972     x_return_status := FND_API.G_RET_STS_ERROR ;
10973     IF l_debug_on THEN
10974       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
10975       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_ERROR');
10976     END IF;
10977 
10978   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
10979     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
10980     IF l_debug_on THEN
10981       WSH_DEBUG_SV.logmsg(l_module_name,'FND_API.G_EXC_UNEXPECTED_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
10982       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
10983     END IF;
10984 
10985   WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
10986     x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
10987     IF l_debug_on THEN
10988       WSH_DEBUG_SV.logmsg(l_module_name,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured',WSH_DEBUG_SV.C_EXCEP_LEVEL);
10989       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
10990     END IF;
10991 
10992   WHEN OTHERS THEN
10993     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10994     wsh_util_core.add_message(x_return_status, l_module_name);
10995     WSH_UTIL_CORE.default_handler('WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping');
10996     --
10997     IF l_debug_on THEN
10998       WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
10999       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
11000     END IF;
11001 END Get_Carton_Grouping;
11002 
11003 END WSH_DELIVERY_DETAILS_GRP;