DBA Data[Home] [Help]

PACKAGE BODY: APPS.WSH_PICK_LIST

Source


1 PACKAGE BODY WSH_PICK_LIST AS
2 /* $Header: WSHPGSLB.pls 120.64.12020000.6 2013/04/16 13:22:32 sunilku ship $ */
3 
4 
5 g_hash_base NUMBER := 1;
6 g_hash_size NUMBER := power(2, 25);
7 
8 
9 --
10 -- Package
11 --  WSH_PICK_LIST
12 --
13 -- Purpose
14 --   This package does the following:
15 --   - Generate selection list
16 --   - Call Move Order APIs to create reservations and to print Pick Slips
17 --
18 
19    --Recode attributes of Demand Table
20 -- HW OPMCONV - Added qty2
21    TYPE demRecTyp IS RECORD (
22           demand_source_header_id NUMBER,
23           demand_source_line_id   NUMBER,
24           subinventory_code VARCHAR2(10),
25           locator_id  NUMBER,
26           reserved_quantity NUMBER,
27           reserved_quantity2 NUMBER);
28 
29    TYPE demRecTabTyp IS TABLE OF demRecTyp INDEX BY BINARY_INTEGER;
30 
31    --
32    --  VARIABLES
33 
34    -- Description: Constant to distinguish CONCURRENT request from
35    -- ONLINE request
36    G_CONC_REQ VARCHAR2(1) := FND_API.G_TRUE;
37 
38 
39    -- Following globals are needed by online_release API to pass back to the Pick Release Form
40    G_ONLINE_PICK_RELEASE_PHASE  VARCHAR2(30) := null;
41    -- Possible values are - START, MOVE_ORDER_LINES,SUCCESS
42    -- MOVE_ORDER_LINES is used by Form to give a different message if Process
43    -- fails after successfull call to Inv_Move_Order_Pub.Create_Move_Order_Lines
44 
45    G_ONLINE_PICK_RELEASE_RESULT  VARCHAR2(1) := 'F';
46    -- Possible values are S(Success) and F(failure)
47 
48    G_ONLINE_PICK_RELEASE_SKIP VARCHAR2(1) := 'N';
49    --
50 
51    G_PKG_NAME CONSTANT VARCHAR2(50) := 'WSH_PICK_LIST';
52 
53    g_demand_table demRecTabTyp;
54 
55    -- Global Variables
56    g_trolin_tbl              INV_MOVE_ORDER_PUB.Trolin_Tbl_Type;
57    g_trolin_delivery_ids     WSH_UTIL_CORE.Id_Tab_Type;
58    g_order_number            NUMBER;
59    g_del_detail_ids          WSH_PICK_LIST.DelDetTabTyp;
60    g_exp_pick_release_stat   Inv_Express_Pick_Pub.P_Pick_Release_Status_Tbl;
61 
62    -- X-dock, declare package level global variables
63    g_allocation_method       WSH_PICKING_BATCHES.ALLOCATION_METHOD%TYPE;
64    g_xdock_delivery_ids      WSH_UTIL_CORE.Id_Tab_Type; -- used for X-dock only
65    g_xdock_detail_ids        WSH_PICK_LIST.DelDetTabTyp; -- used for X-dock only
66 
67 /**************************
68 -- X-dock
69 -- Description: This function is called from create_move_order_lines and
70 --              Release_Batch API.
71 --              Create_move_order_lines is called from Release_Batch_Sub
72 --              which in turn is called from Release_Batch API, but could
73 --              also be called from SRS program.
74 --              This function will replace the multiple calls made in the
75 --              code to check for g_allocation_method being not 'Crossdock'
76 --              and provides a single point of maintenance
77 --
78 --FUNCTION check_allocation_method RETURN VARCHAR2; -- Spec not required
79 g_valid_allocation  VARCHAR2(1);
80 -- Need to be nullified for each organization
81 FUNCTION check_allocation_method RETURN VARCHAR2 IS
82 
83 BEGIN
84   IF g_valid_allocation IS NULL THEN
85     IF g_allocation_method IN (WSH_PICK_LIST.C_INVENTORY_ONLY,
86                                WSH_PICK_LIST.C_PRIORITIZE_CROSSDOCK,
87                                WSH_PICK_LIST.C_PRIORITIZE_INVENTORY) THEN
88       g_valid_allocation := 'Y';
89     ELSE
90       g_valid_allocation := 'N';
91     END IF;
92   END IF;
93   RETURN g_valid_allocation;
94 
95 END;
96 ****************************/
97 
98 -- Start of comments
99 -- API name : Init_Pick_Release
100 -- Type     : Private
101 -- Pre-reqs : None.
102 -- Procedure: This API calls WSH_PR_CRITERIA.Init API to initialize global variables
103 -- Parameters :
104 -- IN:
105 --      p_batch_id            IN  Batch Id.
106 --      p_worker_id           IN  Worker Id.
107 -- OUT:
108 --      x_return_status       OUT NOCOPY  Return Status.
109 -- End of comments
110 PROCEDURE Init_Pick_Release(
111       p_batch_id                        IN      NUMBER,
112       p_worker_id                       IN      NUMBER,
113       x_return_status                   OUT NOCOPY VARCHAR2)
114 IS
115   --
116   l_debug_on BOOLEAN;
117   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'INIT_PICK_RELEASE';
118   --
119 BEGIN
120 
121   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
122 
123   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
124   IF l_debug_on IS NULL THEN
125      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
126   END IF;
127 
128   IF l_debug_on THEN
129      WSH_DEBUG_SV.push(l_module_name);
130      WSH_DEBUG_SV.log(l_module_name,'P_BATCH_ID ',P_BATCH_ID);
131      WSH_DEBUG_SV.log(l_module_name,'P_WORKER_ID ',P_WORKER_ID);
132      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PR_CRITERIA.INIT',WSH_DEBUG_SV.C_PROC_LEVEL);
133   END IF;
134 
135   WSH_PR_CRITERIA.Init( p_batch_id   => p_batch_id,
136                         p_worker_id  => p_worker_id,
137                         x_api_status => x_return_status);
138 
139   IF (x_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
140      --
141      IF l_debug_on THEN
142         WSH_DEBUG_SV.logmsg(l_module_name,  'INITIALIZATION SUCCESSFUL ');
143      END IF;
144      --
145   ELSIF (x_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) OR (x_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
146      WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_PR_CRITERIA.Init');
147      --
148      IF l_debug_on THEN
149         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:INIT');
150      END IF;
151      --
152      RETURN; -- back to calling API
153   END IF;
154 
155   WSH_PICK_LIST.G_BATCH_ID := p_batch_id;
156 
157   BEGIN --{
158    --Get the seeded document set id
159    SELECT WRS.REPORT_SET_ID
160    INTO   WSH_PICK_LIST.G_SEED_DOC_SET
161    FROM   WSH_REPORT_SET_LINES WRSL,
162           WSH_REPORT_SETS WRS
163    WHERE  WRS.NAME = 'Pick Slip Report'
164    AND    WRS.REPORT_SET_ID = WRSL.REPORT_SET_ID ;
165    --
166    IF l_debug_on THEN
167        WSH_DEBUG_SV.logmsg(l_module_name,  'SEEDED PICK RELEASE DOCUMENT SET IS '||WSH_PICK_LIST.G_SEED_DOC_SET  );
168    END IF;
169    --
170    EXCEPTION
171      --
172      WHEN NO_DATA_FOUND THEN
173        --
174        WSH_PICK_LIST.G_SEED_DOC_SET := NULL;
175        --
176        IF l_debug_on THEN
177          WSH_DEBUG_SV.logmsg(l_module_name,  'SEEDED PICK RELEASE DOCUMENT SET NOT FOUND');
178        END IF;
179        --
180      WHEN TOO_MANY_ROWS THEN
181        --
182        WSH_PICK_LIST.G_SEED_DOC_SET := NULL;
183        --
184        IF l_debug_on THEN
185          WSH_DEBUG_SV.logmsg(l_module_name, 'SEEDED PICK RELEASE DOCUMENT SET HAS > 1 REPORT. IGNORING...');
186        END IF;
187   END; --}
188 
189   -- X-dock, populate the package globals
190   g_allocation_method := WSH_PR_CRITERIA.g_allocation_method;
191 
192   IF l_debug_on THEN
193      WSH_DEBUG_SV.pop(l_module_name);
194   END IF;
195 
196 EXCEPTION
197       --
198       WHEN OTHERS THEN
199          x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
200          IF l_debug_on THEN
201             WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '
202                                 || SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
203             WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
204          END IF;
205          --
206 END Init_Pick_Release;
207 
208 
209 -- Start of comments
210 -- API name : Get_Org_Params
211 -- Type     : Private
212 -- Pre-reqs : None.
213 -- Procedure: This API gets all Organization related parameters
214 -- Parameters :
215 -- IN:
216 --      p_organization_id     IN  Organization Id.
217 -- OUT:
218 --      x_org_info            OUT NOCOPY  Organization Info.
219 --      x_return_status       OUT NOCOPY  Return Status.
220 -- End of comments
221 PROCEDURE Get_Org_Params(
222       p_organization_id                IN      NUMBER,
223       x_org_info                       OUT NOCOPY WSH_PICK_LIST.Org_Params_Rec,
224       x_return_status                  OUT NOCOPY VARCHAR2)
225 IS
226 
227   --Cursor to get inventory pick confirmed required flag.
228   CURSOR get_default_confirm(c_org_id IN NUMBER) IS
229   SELECT DECODE(MO_PICK_CONFIRM_REQUIRED, 2, 'Y', 'N')
230   FROM   MTL_PARAMETERS
231   WHERE  ORGANIZATION_ID = c_org_id;
232 
233   l_default_pickconfirm  VARCHAR2(1);
234   l_init_rules           VARCHAR2(1) := FND_API.G_FALSE;
235   l_param_info           WSH_SHIPPING_PARAMS_PVT.Parameter_Rec_Typ;
236   l_express_pick_profile VARCHAR2(1);
237 
238   l_debug_on BOOLEAN;
239   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'GET_ORG_PARAMS';
240 
241 BEGIN
242 
243   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
244 
245   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
246   IF l_debug_on IS NULL THEN
247      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
248   END IF;
249 
250   IF l_debug_on THEN
251      WSH_DEBUG_SV.push(l_module_name);
252      WSH_DEBUG_SV.log(l_module_name,'P_ORGANIZATION_ID ',P_ORGANIZATION_ID);
253      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_SHIPPING_PARAMS_PVT.Get',WSH_DEBUG_SV.C_PROC_LEVEL);
254   END IF;
255 
256   -- 10. Getting Organization Parameters
257   WSH_SHIPPING_PARAMS_PVT.Get(
258             p_organization_id => p_organization_id,
259             x_param_info      => l_param_info,
260             x_return_status   => x_return_status);
261 
262   IF l_debug_on THEN
263      WSH_DEBUG_SV.log(l_module_name,'Return Status After Calling WSH_SHIPPING_PARAMS_PVT.Get',x_return_status);
264   END IF;
265 
266   -- 20. Using NVL function for possible null values
267   l_param_info.PRINT_PICK_SLIP_MODE          := NVL(l_param_info.PRINT_PICK_SLIP_MODE, 'E');
268   l_param_info.AUTOCREATE_DELIVERIES_FLAG    := NVL(l_param_info.AUTOCREATE_DELIVERIES_FLAG, 'N');
269   l_param_info.ENFORCE_SHIP_SET_AND_SMC      := NVL(l_param_info.ENFORCE_SHIP_SET_AND_SMC, 'N');
270   l_param_info.APPENDING_LIMIT               := NVL(l_param_info.APPENDING_LIMIT, 'N');
271 
272   IF l_param_info.APPENDING_LIMIT <> 'N' THEN
273      l_param_info.APPENDING_LIMIT := 'Y';
274   END IF;
275 
276   OPEN  get_default_confirm(p_organization_id);
277   FETCH get_default_confirm INTO l_default_pickconfirm;
278   CLOSE get_default_confirm;
279 
280   IF l_debug_on THEN
281      WSH_DEBUG_SV.log(l_module_name,  'DEFAULTS FOR ORGANIZATION', P_ORGANIZATION_ID);
282      WSH_DEBUG_SV.log(l_module_name,  ' PICK SLIP MODE', L_PARAM_INFO.PRINT_PICK_SLIP_MODE);
283      WSH_DEBUG_SV.log(l_module_name,  ' AUTO DETAIL', L_PARAM_INFO.AUTODETAIL_PR_FLAG);
284      WSH_DEBUG_SV.log(l_module_name,  ' AUTO PICK CONFIRM', L_DEFAULT_PICKCONFIRM);
285      WSH_DEBUG_SV.log(l_module_name,  ' AUTOCREATE DEL', L_PARAM_INFO.AUTOCREATE_DELIVERIES_FLAG);
286      WSH_DEBUG_SV.log(l_module_name,  ' STAGING SUBINVENTORY', L_PARAM_INFO.DEFAULT_STAGE_SUBINVENTORY);
287      WSH_DEBUG_SV.log(l_module_name,  ' STAGING LOCATOR ID', L_PARAM_INFO.DEFAULT_STAGE_LOCATOR_ID);
288      WSH_DEBUG_SV.log(l_module_name,  ' PICK SEQ RULE ID', L_PARAM_INFO.PICK_SEQUENCE_RULE_ID);
289      WSH_DEBUG_SV.log(l_module_name,  ' PICK GROUPING RULE ID', L_PARAM_INFO.PICK_GROUPING_RULE_ID);
290      WSH_DEBUG_SV.log(l_module_name,  ' ENFORCE SHIP SET AND SMC', L_PARAM_INFO.ENFORCE_SHIP_SET_AND_SMC);
291      WSH_DEBUG_SV.log(l_module_name,  ' PICK RELEASE DOCUMENT SET ID', L_PARAM_INFO.PICK_RELEASE_REPORT_SET_ID);
292      WSH_DEBUG_SV.log(l_module_name,  ' TASK PLANNING FLAG', L_PARAM_INFO.TASK_PLANNING_FLAG);
293      WSH_DEBUG_SV.log(l_module_name,  ' Use Header Flag', L_PARAM_INFO.AUTOCREATE_DEL_ORDERS_FLAG);
294      WSH_DEBUG_SV.log(l_module_name,  ' Ship Confirm Rule ID', L_PARAM_INFO.SHIP_CONFIRM_RULE_ID);
295      WSH_DEBUG_SV.log(l_module_name,  ' Append Flag', L_PARAM_INFO.APPENDING_LIMIT);
296      WSH_DEBUG_SV.log(l_module_name,  ' Auto Pack Level ', L_PARAM_INFO.AUTOPACK_LEVEL);
297      WSH_DEBUG_SV.log(l_module_name,  ' Auto Apply Routing Rules ', L_PARAM_INFO.AUTO_APPLY_ROUTING_RULES);
298      WSH_DEBUG_SV.log(l_module_name,  ' Auto Calculate Freight Rates after Delivery Creation '
299                                    , L_PARAM_INFO.AUTO_CALC_FGT_RATE_CR_DEL);
300      --bug# 6689448 (replenishment project)
301      WSH_DEBUG_SV.log(l_module_name,  'dynamic replenishment flag', L_PARAM_INFO.DYNAMIC_REPLENISHMENT_FLAG);
302   END IF;
303 
304   -- 30. Deriving Actual Values
305   x_org_info.autodetail_flag       := NVL(WSH_PR_CRITERIA.g_autodetail_flag, l_param_info.autodetail_pr_flag);
306   x_org_info.auto_pick_confirm     := NVL(WSH_PR_CRITERIA.g_auto_pick_confirm_flag, l_default_pickconfirm);
307   x_org_info.autocreate_deliveries := NVL(WSH_PR_CRITERIA.g_autocreate_deliveries,
308                                                               l_param_info.autocreate_deliveries_flag); --bug 4556414
309   x_org_info.pick_seq_rule_id      := NVL(WSH_PR_CRITERIA.g_pick_seq_rule_id, l_param_info.pick_sequence_rule_id);
310   x_org_info.pick_grouping_rule_id := NVL(WSH_PR_CRITERIA.g_pick_grouping_rule_id, l_param_info.pick_grouping_rule_id);
311   x_org_info.autopack_level        := NVL(WSH_PR_CRITERIA.g_autopack_level, l_param_info.autopack_level);
312   -- rlanka : Pack J Enhancement
313   --
314   -- LSP PROJECT : Use_header_flag value defaulting (from org/client defaults) has been moved to the calling API
315   --          WSH_DELIVERY_AUTOCREATE.Find_Matching_Groups/Create_Hash and hence just passing
316   --          the original value to the calling API.
317   --x_org_info.use_header_flag       := NVL(WSH_PR_CRITERIA.g_acDelivCriteria, l_param_info.autocreate_del_orders_flag); --bug 4556414
318   x_org_info.use_header_flag       := WSH_PR_CRITERIA.g_acDelivCriteria;
319   -- LSP PROJECT : end
320   x_org_info.append_flag           := l_param_info.appending_limit;
321   x_org_info.print_pick_slip_mode  := l_param_info.print_pick_slip_mode;
322   x_org_info.enforce_ship_set_and_smc  := l_param_info.enforce_ship_set_and_smc;
323 
324   x_org_info.auto_apply_routing_rules   := l_param_info.auto_apply_routing_rules;
325   x_org_info.auto_calc_fgt_rate_cr_del  := l_param_info.auto_calc_fgt_rate_cr_del;
326 
327   IF l_debug_on THEN
328      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_VALIDATE.CHECK_WMS_ORG',WSH_DEBUG_SV.C_PROC_LEVEL);
329   END IF;
330 
331   x_org_info.wms_org := WSH_UTIL_VALIDATE.CHECK_WMS_ORG(p_organization_id);
332   IF (x_org_info.wms_org = 'Y') THEN
333 
334      IF l_debug_on THEN
335         WSH_DEBUG_SV.logmsg(l_module_name,  P_ORGANIZATION_ID || ' IS WMS ENABLED ORGANIZATION'  );
336      END IF;
337 
338      --task_planning_flag is default of Release criteria or organization default.
339      x_org_info.task_planning_flag := NVL(WSH_PR_CRITERIA.g_task_planning_flag, NVL(l_param_info.task_planning_flag, 'N'));
340      IF x_org_info.task_planning_flag = 'Y' THEN
341         x_org_info.auto_pick_confirm := 'N';
342      END IF;
343 
344      --bug# 6689448 (replenishment project):
345      x_org_info.dynamic_replenishment_flag := NVL(WSH_PR_CRITERIA.g_dynamic_replenishment_flag, NVL(l_param_info.dynamic_replenishment_flag, 'N'));
346   ELSE
347      x_org_info.task_planning_flag := 'N';
348      x_org_info.dynamic_replenishment_flag := 'N';
349   END IF;
350 
351   -- Bug 3316645: For only Non-WMS orgs, default the Subinventory and Locator from either
352   -- Pick Release Criteria or the Shipping Parameters defaults
353   -- For WMS, the default will be from the Pick Release Criteria entered only
354   IF (x_org_info.wms_org = 'N') THEN
355     x_org_info.to_subinventory := NVL(WSH_PR_CRITERIA.g_to_subinventory, l_param_info.default_stage_subinventory);
356 
357     -- Following IF condition added for Bug 4199614,(FP Bug-4225169)
358     -- Default locator in Org. Shipping Parameters will be assigned to To_Locator
359     -- only if default subinventory in Org. Shipping Parameters and subinventory
360     -- entered in Pick Release form are same.
361     -- Modified IF condition for bug 4363740.
362     -- If Subinventory entered in Pick Release form is NULL, then copy Subinventory
363     -- and Locator from Org. Shipping Parameters.
364     IF  (l_param_info.default_stage_subinventory = x_org_info.to_subinventory) THEN
365       x_org_info.to_locator         := NVL(WSH_PR_CRITERIA.g_to_locator, l_param_info.default_stage_locator_id);
366     ELSE
367       x_org_info.to_locator         := WSH_PR_CRITERIA.g_to_locator;
368     END IF;
369 
370   ELSE
371      x_org_info.to_subinventory    := WSH_PR_CRITERIA.g_to_subinventory;
372      x_org_info.to_locator         := WSH_PR_CRITERIA.g_to_locator;
373   END IF;
374 
375   IF ( NVL(WSH_PR_CRITERIA.g_doc_set_id,-1) <> -1 ) THEN
376      x_org_info.doc_set_id := WSH_PR_CRITERIA.g_doc_set_id;
377   ELSE
378      x_org_info.doc_set_id := l_param_info.pick_release_report_set_id;
379   END IF;
380 
381   IF x_org_info.append_flag = 'N' or x_org_info.auto_pick_confirm = 'Y' THEN
382      x_org_info.append_flag := 'N';
383   ELSE
384      x_org_info.append_flag := NVL(WSH_PR_CRITERIA.g_append_flag, x_org_info.append_flag);
385   END IF;
386 
387   IF l_debug_on THEN
388      WSH_DEBUG_SV.log(l_module_name,  'ACTUAL PARAMETERS THAT WILL BE USED');
389      WSH_DEBUG_SV.log(l_module_name,  ' AUTO DETAIL', X_ORG_INFO.AUTODETAIL_FLAG);
390      WSH_DEBUG_SV.log(l_module_name,  ' AUTO PICK CONFIRM', X_ORG_INFO.AUTO_PICK_CONFIRM);
391      WSH_DEBUG_SV.log(l_module_name,  ' AUTOCREATE DELIVERIES', X_ORG_INFO.AUTOCREATE_DELIVERIES);
392      WSH_DEBUG_SV.log(l_module_name,  ' STAGING SUBINVENTORY', X_ORG_INFO.TO_SUBINVENTORY);
393      WSH_DEBUG_SV.log(l_module_name,  ' STAGING LOCATOR ID', X_ORG_INFO.TO_LOCATOR);
394      WSH_DEBUG_SV.log(l_module_name,  ' PICK SEQ RULE ID', X_ORG_INFO.PICK_SEQ_RULE_ID);
395      WSH_DEBUG_SV.log(l_module_name,  ' PICK GROUPING RULE ID', X_ORG_INFO.PICK_GROUPING_RULE_ID);
396      WSH_DEBUG_SV.log(l_module_name,  ' ENFORCE SHIP SET AND SMC', X_ORG_INFO.ENFORCE_SHIP_SET_AND_SMC);
397      WSH_DEBUG_SV.log(l_module_name,  ' PICK RELEASE DOCUMENT SET ID', X_ORG_INFO.DOC_SET_ID);
398      WSH_DEBUG_SV.log(l_module_name,  ' TASK PLANNING FLAG', X_ORG_INFO.TASK_PLANNING_FLAG);
399      WSH_DEBUG_SV.log(l_module_name,  ' USE HEADER FLAG', X_ORG_INFO.USE_HEADER_FLAG);
400      WSH_DEBUG_SV.log(l_module_name,  ' APPEND FLAG', X_ORG_INFO.APPEND_FLAG);
401      WSH_DEBUG_SV.log(l_module_name,  ' AUTO PACK LEVEL ', X_ORG_INFO.AUTOPACK_LEVEL);
402      --bug# 6689448 (replenishment project)
403      WSH_DEBUG_SV.log(l_module_name,  ' DYNAMIC REPLENISHMENT FLAG ', X_ORG_INFO.DYNAMIC_REPLENISHMENT_FLAG);
404   END IF;
405 
406   x_org_info.express_pick_flag := 'N';
407 
408   l_express_pick_profile := NVL(FND_PROFILE.VALUE('WSH_EXPRESS_PICK'), 'N');
409   IF l_debug_on THEN
410      WSH_DEBUG_SV.logmsg(l_module_name,'Profile WSH_EXPRESS_PICK value '||l_express_pick_profile);
411   END IF;
412 
413   -- 40. Express Pickup only if Profile is yes AND Have prior reservation AND Ato Pick Confirm select as Yes.
414   IF l_express_pick_profile = 'Y' THEN
415      IF x_org_info.wms_org = 'N' AND WSH_PR_CRITERIA.g_existing_rsvs_only_flag = 'Y'
416      AND x_org_info.auto_pick_confirm = 'Y' THEN
417         x_org_info.express_pick_flag := 'Y';
418         IF l_debug_on THEN
419            WSH_DEBUG_SV.logmsg(l_module_name,'*** Enabling Express Pick. SMCs will not be picked ***');
420         END IF;
421      ELSE
422         IF l_debug_on THEN
423            WSH_DEBUG_SV.logmsg(l_module_name,'*** Disabling Express Pick ***');
424         END IF;
425      END IF;
426    -- Bug 4775539
427            WSH_PR_CRITERIA.g_honor_pick_from := 'Y';
428 	  --Get the honor pick from profile value default is Y.
429              WSH_PR_CRITERIA.g_honor_pick_from := NVL(FND_PROFILE.VALUE('WSH_HONOR_PICK_FROM'), 'Y');
430       END IF;
431 
432   -- 50. Check to see if rules need to be initialized for organization
433   IF (l_init_rules = FND_API.G_FALSE OR WSH_PR_CRITERIA.g_pick_grouping_rule_id IS NULL
434   OR WSH_PR_CRITERIA.g_pick_seq_rule_id IS NULL) THEN --{
435       IF l_debug_on THEN
436          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PR_CRITERIA.Init_Rules',WSH_DEBUG_SV.C_PROC_LEVEL);
437       END IF;
438 
439       WSH_PR_CRITERIA.Init_Rules(x_org_info.pick_seq_rule_id, x_org_info.pick_grouping_rule_id, x_return_status);
440       IF (x_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
441 
442          IF l_debug_on THEN
443             WSH_DEBUG_SV.logmsg(l_module_name,  'INITIALIZATION OF RULES SUCESSFUL');
444          END IF;
445 
446       ELSIF (x_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) OR (x_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
447          WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_PR_CRITERIA.Init_Rules');
448 
449          IF l_debug_on THEN
450            WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:INIT_RULES');
451            RETURN; -- back to calling API
452          END IF;
453       END IF;
454 
455   END IF; --}
456 
457   IF l_debug_on THEN
458      WSH_DEBUG_SV.pop(l_module_name);
459   END IF;
460 
461 
462 EXCEPTION
463       --
464       WHEN OTHERS THEN
465          IF get_default_confirm%ISOPEN THEN
466             CLOSE get_default_confirm;
467          END IF;
468          x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
469          IF l_debug_on THEN
470             WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '
471                                 || SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
472             WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
473          END IF;
474 
475 END Get_Org_Params;
476 
477 -- Start of comments
478 -- API name : Spawn_Workers
479 -- Type     : Private
480 -- Pre-reqs : None.
481 -- Procedure: This API spawns child requests based on input parameters.
482 -- Parameters :
483 -- IN:
484 --      p_batch_id            IN  Batch Id.
485 --      p_num_requests        IN  Number of child requests.
486 --      p_mode                IN  Mode.
487 --      p_req_status          IN  Current Request Status (0 - Success, 1 - Warning).
488 --      p_log_level           IN  Set the debug log level.
489 -- OUT:
490 --      x_return_status       OUT NOCOPY  Return Status.
491 -- End of comments
492 PROCEDURE Spawn_Workers(
493       p_batch_id                        IN      NUMBER,
494       p_num_requests                    IN      NUMBER,
495       p_mode                            IN      VARCHAR2,
496       p_req_status                      IN      VARCHAR2,
497       p_log_level                       IN      NUMBER,
498       x_return_status                   OUT NOCOPY VARCHAR2)
499 IS
500 
501   l_debug_on BOOLEAN;
502   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'SPAWN_WORKERS';
503 
504   l_request_id NUMBER;
505 
506 BEGIN
507 
508   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
509 
510   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
511   IF l_debug_on IS NULL THEN
512      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
513   END IF;
514 
515   IF l_debug_on THEN
516      WSH_DEBUG_SV.push(l_module_name);
517      WSH_DEBUG_SV.log(l_module_name,'P_BATCH_ID ',P_BATCH_ID);
518      WSH_DEBUG_SV.log(l_module_name,'P_NUM_REQUESTS ',P_NUM_REQUESTS);
519      WSH_DEBUG_SV.log(l_module_name,'P_MODE ',P_MODE);
520      WSH_DEBUG_SV.log(l_module_name,'P_REQ_STATUS ',P_REQ_STATUS);
521      WSH_DEBUG_SV.log(l_module_name,'P_LOG_LEVEL',P_LOG_LEVEL);
522   END IF;
523 
524   IF p_mode IN ('PICK','PICK-SS','PS') THEN
525   --{
526      FOR i IN 1..p_num_requests LOOP
527          IF l_debug_on THEN
528             WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit FND_REQUEST.Submit_Request',WSH_DEBUG_SV.C_PROC_LEVEL);
529             WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
530          END IF;
531          l_request_id := FND_REQUEST.Submit_Request(
532                                                       application => 'WSH',
533                                                       program     => 'WSHPSGL_SUB',
534                                                       description => '',
535                                                       start_time  => '',
536                                                       sub_request => TRUE,       -- Child Request
537                                                       argument1   => p_batch_id,
538                                                       argument2   => i,          -- Worker ID
539                                                       argument3   => p_mode,
540                                                       argument4   => p_log_level
541                                                    );
542          IF l_request_id = 0 THEN
543             -- If request submission failed, exit with error.
544             IF l_debug_on THEN
545                WSH_DEBUG_SV.logmsg(l_module_name,'Request submission failed for Worker '||i);
546                WSH_DEBUG_SV.pop(l_module_name);
547             END IF;
548             x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
549             RETURN;
550          ELSE
551             IF l_debug_on THEN
552                WSH_DEBUG_SV.logmsg(l_module_name,'Request '||l_request_id||' submitted successfully');
553             END IF;
554          END IF;
555      END LOOP;
556   --}
557   END IF;
558 
559   IF l_debug_on THEN
560      WSH_DEBUG_SV.logmsg(l_module_name,'Setting Parent Request to pause');
561   END IF;
562   FND_CONC_GLOBAL.Set_Req_Globals ( Conc_Status => 'PAUSED', Request_Data => p_batch_id ||':'|| p_req_status
563                                                                              ||':'|| p_mode );
564 
565   IF l_debug_on THEN
566      WSH_DEBUG_SV.pop(l_module_name);
567   END IF;
568 
569 EXCEPTION
570       --
571       WHEN OTHERS THEN
572          x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
573          IF l_debug_on THEN
574             WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '
575                                 || SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
576             WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
577          END IF;
578 
579 END Spawn_Workers;
580 
581 
582 -- Start of comments
583 -- API name : Print_Docs
584 -- Type     : Private
585 -- Pre-reqs : None.
586 -- Procedure: This API will print all Documents that are part of Pick Release Document Set
587 --            and the Pick Slip Report.
588 -- Parameters :
589 -- IN:
590 --      p_batch_id                  IN  Pick Release Batch Id.
591 --      p_organization_id           IN  Organization Id.
592 --      p_print_ps                  IN  Print Pick Slip Report.
593 --      p_ps_mode                   IN  Pick Slip Printing Mode , Valid Values I/E.
594 --      p_doc_set_id                IN  Pick Release Document Set.
595 --      p_batch_name                IN  Batch Name.
596 --      p_order_number              IN  Order Number.
597 -- OUT:
598 --      x_return_status             OUT NOCOPY  Return Status.
599 -- End of comments
600 PROCEDURE Print_docs(
601      p_batch_id         IN  NUMBER,
602      p_organization_id  IN  NUMBER,
603      p_print_ps         IN  VARCHAR2,
604      p_ps_mode          IN  VARCHAR2,
605      p_doc_set_id       IN  NUMBER,
606      p_batch_name       IN  VARCHAR2,
607      p_order_number     IN  NUMBER,
608      x_return_status    OUT NOCOPY VARCHAR2
609 ) IS
610 
611   CURSOR c_get_printers IS
612   SELECT distinct printer_name,conc_program_name
613   FROM   wsh_pr_workers
614   WHERE  batch_id = p_batch_id
615   AND    organization_id = p_organization_id
616   AND    type = 'PRINTER';
617 
618   CURSOR c_order_number(l_header_id NUMBER) IS
619   SELECT source_header_number
620   FROM   wsh_delivery_details
621   WHERE  source_header_id = l_header_id
622   AND    rownum = 1;
623 
624   l_debug_on    BOOLEAN;
625   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'Print_Docs';
626 
627   l_document_info WSH_DOCUMENT_SETS.document_set_tab_type;
628   l_null_ids      WSH_UTIL_CORE.Id_Tab_Type;
629   l_return_status VARCHAR2(1);
630   l_message       VARCHAR2(2000);
631   l_order_number  VARCHAR2(30);
632 
633 BEGIN
634   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
635   IF l_debug_on IS NULL THEN
636      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
637   END IF;
638 
639   IF l_debug_on THEN
640      WSH_DEBUG_SV.push(l_module_name);
641      WSH_DEBUG_SV.log(l_module_name,'P_BATCH_ID',P_BATCH_ID);
642      WSH_DEBUG_SV.log(l_module_name,'P_ORGANIZATION_ID',P_ORGANIZATION_ID);
643      WSH_DEBUG_SV.log(l_module_name,'P_PRINT_PS',P_PRINT_PS);
644      WSH_DEBUG_SV.log(l_module_name,'P_PS_MODE',P_PS_MODE);
645      WSH_DEBUG_SV.log(l_module_name,'P_DOC_SET_ID',P_DOC_SET_ID);
646      WSH_DEBUG_SV.log(l_module_name,'P_BATCH_NAME',P_BATCH_NAME);
647      WSH_DEBUG_SV.log(l_module_name,'P_ORDER_NUMBER',P_ORDER_NUMBER);
648   END IF;
649   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
650 
651   WSH_INV_INTEGRATION_GRP.G_PRINTERTAB.delete;
652 
653   FOR crec in c_get_printers LOOP
654       WSH_INV_INTEGRATION_GRP.G_PRINTERTAB(WSH_INV_INTEGRATION_GRP.G_PRINTERTAB.COUNT+1).printer_name := crec.printer_name;
655       WSH_INV_INTEGRATION_GRP.G_PRINTERTAB(WSH_INV_INTEGRATION_GRP.G_PRINTERTAB.COUNT).conc_program_name := crec.conc_program_name;
656     --
657     IF l_debug_on THEN
658        WSH_DEBUG_SV.logmsg(l_module_name,  'Calling Print_Document_sets for crec.printer_name  ' || crec.printer_name );
659         WSH_DEBUG_SV.logmsg(l_module_name,  'Calling Print_Document_sets for crec.conc_program_name  ' || crec.conc_program_name );
660    END IF ;
661    --
662   END LOOP;
663 
664   IF p_print_ps = 'Y' THEN
665   --{
666      IF l_debug_on THEN
667         WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
668         WSH_DEBUG_SV.logmsg(l_module_name,  'PRINT PICK SLIP REPORT'  );
669         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PR_PICK_SLIP_NUMBER.PRINT_PICK_SLIP'
670                                          ,WSH_DEBUG_SV.C_PROC_LEVEL);
671      END IF;
672      WSH_PR_PICK_SLIP_NUMBER.Print_Pick_Slip (
673                                                p_report_set_id   => WSH_PICK_LIST.G_SEED_DOC_SET,
674                                                p_organization_id => p_organization_id,
675                                                p_order_header_id => WSH_PR_CRITERIA.g_order_header_id,
676                                                p_ps_mode         => p_ps_mode,
677                                                p_batch_id        => p_batch_id,
678                                                x_api_status      => l_return_status,
679                                                x_error_message   => l_message );
680      IF l_debug_on THEN
681        WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
682      END IF;
683      IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
684      OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
685          WSH_UTIL_CORE.PrintMsg('Warning: Cannot Print Report(s)');
686          WSH_UTIL_CORE.PrintMsg(l_message);
687          x_return_status := l_return_status;
688      ELSE
689          IF l_debug_on THEN
690             WSH_DEBUG_SV.logmsg(l_module_name,  'PRINT PICK SLIP SUCCESSFUL'  );
691          END IF;
692       END IF;
693   --}
694   END IF;
695 
696   -- Bug 7347232 Deleting the Printer (set at Subinv or Org level) which was selected by INV for Seeded Pick Slip Report
697   -- Printer selected by INV should not be used for Document set other than Seeded Pick Slip Report
698  -- bugfix 13384185
699   --WSH_INV_INTEGRATION_GRP.G_PRINTERTAB.delete;
700 
701   IF (p_doc_set_id <> -1 ) THEN
702   --{
703       IF l_debug_on THEN
704          WSH_DEBUG_SV.logmsg(l_module_name,  '* PRINT DOCUMENT SET AFTER FINISHING PRINTING PICK SLIP REPORTS'  );
705       END IF;
706       l_document_info(1).p_report_set_id := p_doc_set_id;
707       l_document_info(1).p_request_id    := FND_GLOBAL.CONC_REQUEST_ID;
708       -- bug 2367043: p_move_order range should use l_batch_name, not id.
709       l_document_info(1).p_move_order_h  := p_batch_name;
710       l_document_info(1).p_move_order_l  := p_batch_name;
711       IF (NVL(WSH_PR_CRITERIA.g_trip_id,0) > 0) THEN
712           l_document_info(1).p_trip_id      := WSH_PR_CRITERIA.g_trip_id;
713           l_document_info(1).p_trip_id_high := WSH_PR_CRITERIA.g_trip_id;
714           l_document_info(1).p_trip_id_low  := WSH_PR_CRITERIA.g_trip_id;
715       ELSIF (NVL(WSH_PR_CRITERIA.g_trip_stop_id,0) > 0) THEN
716           l_document_info(1).p_trip_stop_id := WSH_PR_CRITERIA.g_trip_stop_id;
717       ELSIF (NVL(WSH_PR_CRITERIA.g_delivery_id,0) > 0) THEN
718           l_document_info(1).p_delivery_id := WSH_PR_CRITERIA.g_delivery_id;
719           l_document_info(1).p_delivery_id_high := WSH_PR_CRITERIA.g_delivery_id;
720           l_document_info(1).p_delivery_id_low  := WSH_PR_CRITERIA.g_delivery_id;
721       ELSIF (NVL(WSH_PR_CRITERIA.g_order_header_id,0) > 0) THEN
722           OPEN  c_order_number(WSH_PR_CRITERIA.g_order_header_id);
723           FETCH c_order_number INTO l_order_number;
724           CLOSE c_order_number;
725           l_document_info(1).p_order_num_high := l_order_number;
726           l_document_info(1).p_order_num_low  := l_order_number;
727           --Bugfix 3604021 added code to pass the order type id
728           l_document_info(1).p_order_type_id := WSH_PR_CRITERIA.g_order_type_id;
729           l_document_info(1).p_transaction_type_id := WSH_PR_CRITERIA.g_order_type_id;
730       END IF;
731 
732       IF l_debug_on THEN
733          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DOCUMENT_SETS.PRINT_DOCUMENT_SETS'
734                                            ,WSH_DEBUG_SV.C_PROC_LEVEL);
735       END IF;
736       ---------------------------------------------------------
737       --  For printing the Document Sets for Pick Release ,
738       --  only l_document_info should be passed to the
739       --  Print_Document_Sets API
740       --  l_document_info contains the parameters used for
741       --  launching Pick Release (Refer bug 2565768)
742       ---------------------------------------------------------
743       l_null_ids.delete; -- ensure that the table is empty since no ids should be passed
744 
745       WSH_DOCUMENT_SETS.Print_Document_Sets (
746                                               p_report_set_id       => p_doc_set_id,
747                                               p_organization_id     => p_organization_id,
748                                               p_trip_ids            => l_null_ids,
749                                               p_stop_ids            => l_null_ids,
750                                               p_delivery_ids        => l_null_ids,
751                                               p_document_param_info => l_document_info,
752                                               x_return_status       => l_return_status );
753       IF l_debug_on THEN
754          WSH_DEBUG_SV.logmsg(l_module_name,  '* END PRINT DOCUMENT SET '  );
755       END IF;
756       IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
757       OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
758           WSH_UTIL_CORE.PrintMsg('Warning: Cannot Print Document Set, when count=0 ');
759           WSH_UTIL_CORE.PrintMsg(l_message);
760           x_return_status := l_return_status;
761       ELSE
762           IF l_debug_on THEN
763              WSH_DEBUG_SV.logmsg(l_module_name,  'PRINT DOCUMENT SET SUCCESSFUL '  );
764           END IF;
765       END IF;
766   --}
767   END IF;
768 
769   fnd_msg_pub.delete_msg(); -- Clear Msg Buffer
770 
771   IF l_debug_on THEN
772      WSH_DEBUG_SV.logmsg(l_module_name,'x_return_status '||x_return_status);
773      WSH_DEBUG_SV.pop(l_module_name);
774   END IF;
775 
776 EXCEPTION
777   WHEN OTHERS THEN
778        x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
779        IF l_debug_on THEN
780           WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '
781                               || SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
782           WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
783        END IF;
784 END Print_docs;
785 
786 -- Start of comments
787 -- API name : Create_Move_Order_Lines
788 -- Type     : Private
789 -- Pre-reqs : None.
790 -- Procedure: This API will initialize Move Order Line table and then
791 --            call Inventory's Move Order Line API. In case of
792 --            Express Pick, it will call Inventory's Express Pick API
793 -- Parameters :
794 -- IN:
795 --      p_batch_id                  IN  Batch Id.
796 --      p_worker_id                 IN  Worker Id.
797 --      p_organization_id           IN  Organization Id.
798 --      p_mo_header_id              IN  Move Order Header Id.
799 --      p_wms_flag                  IN  Org is WMS Enabled or not, Valid Values Y/N.
800 --      p_auto_pick_confirm         IN  Auto Pick Confirm Flag, Valid Values Y/N.
801 --      p_express_pick_flag         IN  Express Pick Enabled or not, Valid Values Y/N.
802 --      p_pick_slip_grouping_rule   IN  Pick Slip Grouping Rule Id.
803 --      p_to_subinventory           IN  Staging Subinventory
804 --      p_to_locator                IN  Staging Locator
805 -- IN OUT:
806 --      x_curr_count                IN OUT NOCOPY  Counter for Move Order Line Number
807 -- OUT:
808 --      x_return_status             OUT NOCOPY  Return Status.
809 -- End of comments
810 PROCEDURE Create_Move_Order_Lines(
811       p_batch_id                     IN      NUMBER,
812       p_worker_id                    IN      NUMBER,
813       p_organization_id              IN      NUMBER,
814       p_mo_header_id                 IN      NUMBER,
815       p_wms_flag                     IN      VARCHAR2,
816       p_auto_pick_confirm            IN      VARCHAR2,
817       p_express_pick_flag            IN      VARCHAR2,
818       p_pick_slip_grouping_rule      IN      NUMBER,
819       p_to_subinventory              IN      VARCHAR2,
820       p_to_locator                   IN      VARCHAR2,
821       p_use_header_flag              IN      WSH_SHIPPING_PARAMETERS.AUTOCREATE_DEL_ORDERS_PR_FLAG%TYPE, -- bug 8623544
822       x_curr_count                   IN OUT NOCOPY   NUMBER,
823       x_return_status                OUT NOCOPY VARCHAR2)
824 IS
825 
826   --Cursor to get the Trip stop id associated with the PickUp Stop of delivery detail line.
827   CURSOR get_dd_pup_trip_stop(v_org_id IN NUMBER, v_dd_id NUMBER) IS
828   SELECT wts.STOP_ID
829   FROM   wsh_trips wt, wsh_trip_stops wts, wsh_delivery_assignments_v wda,
830          wsh_delivery_legs wdl, wsh_delivery_details wdd
831   WHERE  wdd.delivery_detail_id = v_dd_id
832   AND    wdd.organization_id    = v_org_id
833   AND    wda.delivery_detail_id = wdd.delivery_detail_id
834   AND    wdl.delivery_id        = wda.delivery_id
835   AND    wts.stop_id            = wdl.pick_up_stop_id
836   AND    wts.trip_id            = wt.trip_id;
837 
838   -- Workflow Change
839   CURSOR c_get_picked_lines_count (c_delivery_detail_id NUMBER) IS
840   SELECT count (wdd.delivery_detail_id), delivery_id
841   FROM   wsh_delivery_details wdd, wsh_delivery_assignments_v wda
842   WHERE  wdd.delivery_detail_id = wda.delivery_detail_id
843   AND    wda.delivery_id = (  SELECT delivery_id
844                               FROM wsh_delivery_assignments_v
845                               WHERE delivery_detail_id = c_delivery_detail_id )
846   AND    wdd.released_status NOT IN ('R', 'X', 'N')
847   AND    wdd.pickable_flag = 'Y'
848   AND    wdd.container_flag = 'N'
849   GROUP  BY delivery_id;
850   -- Workflow Change
851 
852 
853   TYPE Stops_Ids_Rec IS RECORD ( Staging_Subinventory    VARCHAR2(10),
854                                  Staging_Lane_Id         NUMBER        );
855 
856   TYPE Stops_Ids_Tbl IS TABLE OF Stops_Ids_Rec INDEX BY BINARY_INTEGER;
857 
858   l_Stops_Ids_Tbl		 Stops_Ids_Tbl;
859 
860   l_debug_on BOOLEAN;
861   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CREATE_MOVE_ORDER_LINES';
862 
863   i                              NUMBER;
864   l_count                        NUMBER;
865   l_count_x_relstatus_details    NUMBER;
866   l_temp_trolin_rec              INV_MOVE_ORDER_PUB.Trolin_Rec_Type;
867   l_trolin_tbl                   INV_MOVE_ORDER_PUB.Trolin_Tbl_Type;
868   l_trolin_val_tbl               INV_MOVE_ORDER_PUB.Trolin_Val_Tbl_Type;
869   l_rel_delivery_detail_id 	 WSH_UTIL_CORE.Id_Tab_Type;
870   l_dummy_rsv_tbl                INV_RESERVATION_GLOBAL.Mtl_Reservation_Tbl_Type;
871 
872   -- WMS
873   l_attr_tab                      WSH_DELIVERY_AUTOCREATE.Grp_attr_tab_type;
874   l_group_tab                     WSH_DELIVERY_AUTOCREATE.Grp_attr_tab_type;
875   l_action_rec                    WSH_DELIVERY_AUTOCREATE.Action_rec_type;
876   l_target_rec                    WSH_DELIVERY_AUTOCREATE.Grp_attr_rec_type;
877   l_matched_entities              WSH_UTIL_CORE.id_tab_type;
878   l_out_rec                       WSH_DELIVERY_AUTOCREATE.Out_rec_type;
879   l_dd_pup_stop_id               NUMBER;
880   x_wms_return_status            VARCHAR2(1);
881   x_wms_msg_count                NUMBER;
882   x_wms_msg_data                 VARCHAR2(2000);
883   x_wms_stg_ln_id                NUMBER;
884   x_wms_sub_code                 VARCHAR2(10);
885 
886   l_user_id                      NUMBER;
887   l_login_id                     NUMBER;
888   l_date                         DATE;
889   l_api_version_number           NUMBER := 1.0;
890   l_msg_count                    NUMBER;
891   l_msg_data                     VARCHAR2(2000);
892   l_commit                       VARCHAR2(1) := FND_API.G_FALSE;
893   l_return_status                VARCHAR2(1);
894   l_request_id                   NUMBER;
895   l_item_name                    VARCHAR2(2000);
896   l_message                      VARCHAR2(2000);
897   l_message1                     VARCHAR2(2000);
898   l_exception_name           WSH_EXCEPTION_DEFINITIONS_TL.EXCEPTION_NAME%TYPE;
899   l_exception_return_status      VARCHAR2(30);
900   l_exception_msg_count          NUMBER;
901   l_exception_msg_data           VARCHAR2(4000) := NULL;
902   l_dummy_exception_id           NUMBER;
903 
904   -- DBI Project
905   l_detail_tab                   WSH_UTIL_CORE.Id_Tab_Type;
906   l_dbi_rs                       VARCHAR2(1);               -- DBI Project
907   l_dd_txn_id                    NUMBER;            -- DBI Project
908   l_txn_return_status            VARCHAR2(1);       -- DBI Project
909 
910   -- Workflow Change
911   l_count_picked_lines NUMBER;
912   l_delv_id NUMBER;
913   l_wf_rs VARCHAR2(1); --Pick to POD WF Project
914 
915   l_del_detail_id   WSH_PICK_LIST.DelDetTabTyp;
916   j NUMBER;
917 
918    --bug  7171766
919    l_match_found BOOLEAN;
920    l_group_match_seq_tbl    WSH_PICK_LIST.group_match_seq_tab_type;
921    K NUMBER ;
922    --Added for Standalone project Changes
923    l_standalone_mode                VARCHAR2(1);
924 
925 BEGIN
926 
927   x_return_status     := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
928 
929   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
930   IF l_debug_on IS NULL THEN
931      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
932   END IF;
933 
934   l_standalone_mode := WMS_DEPLOY.wms_deployment_mode; -- Standalone project Changes Start
935 
936   IF l_debug_on THEN
937      WSH_DEBUG_SV.push(l_module_name);
938      WSH_DEBUG_SV.log(l_module_name,'P_BATCH_ID',P_BATCH_ID);
939      WSH_DEBUG_SV.log(l_module_name,'P_WORKER_ID',P_WORKER_ID);
940      WSH_DEBUG_SV.log(l_module_name,'P_ORGANIZATION_ID',P_ORGANIZATION_ID);
941      WSH_DEBUG_SV.log(l_module_name,'P_MO_HEADER_ID',P_MO_HEADER_ID);
942      WSH_DEBUG_SV.log(l_module_name,'P_WMS_FLAG',P_WMS_FLAG);
943      WSH_DEBUG_SV.log(l_module_name,'P_AUTO_PICK_CONFIRM',P_AUTO_PICK_CONFIRM);
944      WSH_DEBUG_SV.log(l_module_name,'P_EXPRESS_PICK_FLAG',P_EXPRESS_PICK_FLAG);
945      WSH_DEBUG_SV.log(l_module_name,'P_PICK_SLIP_GROUPING_RULE',P_PICK_SLIP_GROUPING_RULE);
946      WSH_DEBUG_SV.log(l_module_name,'P_TO_SUBINVENTORY',P_TO_SUBINVENTORY);
947      WSH_DEBUG_SV.log(l_module_name,'P_TO_LOCATOR',P_TO_LOCATOR);
948      WSH_DEBUG_SV.log(l_module_name,'l_standalone_mode',l_standalone_mode);
949   END IF;
950 
951   -- Clear move order lines tables
952   g_trolin_tbl.delete;
953   l_trolin_val_tbl.delete;
954   g_trolin_delivery_ids.delete;
955   g_del_detail_ids.delete;
956   l_rel_delivery_detail_id.delete;
957   l_count := 0;
958   l_count_x_relstatus_details := 0;
959 
960   g_xdock_delivery_ids.delete;
961   g_xdock_detail_ids.delete;
962 
963   l_user_id  := WSH_PR_CRITERIA.g_user_id;
964   l_login_id := WSH_PR_CRITERIA.g_login_id;
965   l_date     := SYSDATE;
966 
967   -- X-dock
968   -- Call to WMS API to process lines for X-dock
969   IF g_allocation_method IN (WSH_PICK_LIST.C_CROSSDOCK_ONLY, WSH_PICK_LIST.C_PRIORITIZE_CROSSDOCK) THEN --{
970     IF l_debug_on THEN
971       WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
972       WSH_DEBUG_SV.log(l_module_name,'Release Table Count',wsh_pr_criteria.release_table.count);
973       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit '||'WMS_XDOCK_PEGGING_PUB.PLANNED_CROSS_DOCK',WSH_DEBUG_SV.C_PROC_LEVEL);
974     END IF;
975 
976     -- Parameters description :
977     -- P_DEL_DETAIL_ID (g_xdock_detail_ids) :contains the list of delivery details which have been
978     --                    successfully planned for X-dock
979     -- P_TROLIN_DELIVERY_IDS (g_xdock_delivery_ids) : Matches index with p_del_detail_id and stores
980     --                    delivery ids for the delivery details(derived from release_table)
981     -- P_WSH_RELEASE_TABLE(wsh_pr_criteria.release_table) : IN/OUT variable, in case of splitting
982     --                    of delivery details new records will be added to p_wsh_release_table
983     --
984     WMS_Xdock_Pegging_Pub.Planned_Cross_Dock
985       (p_api_version         => l_api_version_number,
986        p_init_msg_list       => fnd_api.g_false,
987        p_commit              => l_commit,
988        p_batch_id            => p_batch_id,
989        p_wsh_release_table   => wsh_pr_criteria.release_table,
990        p_trolin_delivery_ids => g_xdock_delivery_ids,
991        p_del_detail_id       => g_xdock_detail_ids,
992        x_return_status       => l_return_status,
993        x_msg_count           => l_msg_count,
994        x_msg_data            => l_msg_data
995       );
996     IF l_debug_on THEN
997       WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
998       WSH_DEBUG_SV.log(l_module_name,'After Calling WMS API-Planned_Cross_Dock',l_return_status);
999       WSH_DEBUG_SV.log(l_module_name,'Release Table Count',wsh_pr_criteria.release_table.count);
1000       WSH_DEBUG_SV.log(l_module_name,'G_XDOCK_DELIVERY_IDS Table Count',g_xdock_delivery_ids.count);
1001       WSH_DEBUG_SV.log(l_module_name,'G_XDOCK_DETAIL_IDS Table Count',g_xdock_detail_ids.count);
1002     END IF;
1003 
1004     IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
1005         OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN--{
1006       x_return_status := l_return_status;
1007       WSH_UTIL_CORE.PrintMsg('Error occurred in WMS API Planned_Cross_Dock');
1008       IF l_debug_on THEN
1009         WSH_DEBUG_SV.pop(l_module_name);
1010       END IF;
1011       -- the parent API handles the errors raised from create_move_order_lines
1012       RETURN;
1013     ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
1014       x_return_status := l_return_status;
1015       WSH_UTIL_CORE.PrintMsg('Warning returned from WMS API Planned_Cross_Dock');
1016       IF g_xdock_detail_ids.count <> wsh_pr_criteria.release_table.count THEN --{
1017         --there is atleast one delivery detail which was not crossdocked
1018         --Need to log exception for that delivery detail
1019         --WMS Crossdock API will set the released_status to 'S' for lines which are
1020         --crossdocked
1021         FOR i in WSH_PR_CRITERIA.release_table.FIRST..WSH_PR_CRITERIA.release_table.LAST
1022         LOOP
1023         IF WSH_PR_CRITERIA.release_table(i).released_status IN ('R','B','X') THEN --{
1024 
1025           IF WSH_PR_CRITERIA.release_table(i).non_reservable_flag = 'Y' THEN
1026             l_exception_name := 'WSH_PICK_XDOCK_NR';  -- ECO 5220234
1027           ELSE
1028             l_exception_name := 'WSH_PICK_XDOCK';
1029           END IF;
1030 
1031           FND_MESSAGE.SET_NAME('WSH', l_exception_name);
1032           l_message := FND_MESSAGE.GET;
1033           l_exception_return_status := NULL;
1034           l_exception_msg_count := NULL;
1035           l_exception_msg_data := NULL;
1036           l_dummy_exception_id := NULL;
1037           IF l_debug_on THEN
1038             WSH_DEBUG_SV.logmsg(l_module_name,
1039                         'Log exception for Detail, id- '
1040                         ||WSH_PR_CRITERIA.release_table(i).delivery_detail_id
1041                         || ', ' || l_exception_name);
1042           END IF;
1043 
1044           wsh_xc_util.log_exception(
1045             p_api_version            => 1.0,
1046             p_logging_entity         => 'SHIPPER',
1047             p_logging_entity_id      => FND_GLOBAL.USER_ID,
1048             p_exception_name         => l_exception_name,
1049             p_message                => l_message,
1050             p_inventory_item_id      => WSH_PR_CRITERIA.release_table(i).inventory_item_id,
1051             p_logged_at_location_id  => WSH_PR_CRITERIA.release_table(i).ship_from_location_id,
1052             p_exception_location_id  => WSH_PR_CRITERIA.release_table(i).ship_from_location_id,
1053             p_request_id             => l_request_id,
1054             p_batch_id               => WSH_PICK_LIST.g_batch_id,
1055             p_delivery_detail_id     => WSH_PR_CRITERIA.release_table(i).delivery_detail_id,
1056             x_return_status          => l_exception_return_status,
1057             x_msg_count              => l_exception_msg_count,
1058             x_msg_data               => l_exception_msg_data,
1059             x_exception_id           => l_dummy_exception_id);
1060 
1061           IF l_debug_on THEN
1062             WSH_DEBUG_SV.logmsg(l_module_name,  'LOGGED EXCEPTION '||L_DUMMY_EXCEPTION_ID  );
1063           END IF;
1064         END IF; --}
1065         END LOOP;
1066       END IF; --}
1067     END IF;--}
1068 
1069   END IF; --}
1070   --  end of X-dock related call
1071 
1072   -- If p_num_workers in Release_Batch api is 1 and WMS Org, then Generate Grouping Ids for the lines
1073   -- X-dock,cartonization is not applicable for X-dock only mode
1074   IF p_worker_id IS NULL AND WSH_PICK_LIST.G_NUM_WORKERS = 1 AND p_wms_flag = 'Y'
1075   AND WSH_PR_CRITERIA.release_table.count > 0
1076   AND g_allocation_method IN (WSH_PICK_LIST.C_INVENTORY_ONLY,
1077                               WSH_PICK_LIST.C_PRIORITIZE_CROSSDOCK,
1078                               WSH_PICK_LIST.C_PRIORITIZE_INVENTORY)
1079   THEN --{
1080      IF l_debug_on THEN
1081         WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
1082      END IF;
1083      l_attr_tab.delete;
1084      FOR i in 1.. WSH_PR_CRITERIA.release_table.count LOOP
1085          l_attr_tab(i).entity_id := WSH_PR_CRITERIA.release_table(i).delivery_detail_id;
1086          l_attr_tab(i).entity_type := 'DELIVERY_DETAIL';
1087        IF WSH_PR_CRITERIA.release_table(i).released_status = 'S' THEN
1088          -- delivery detail is X-docked, pass flag to ignore this line for grouping
1089          IF l_debug_on THEN
1090            WSH_DEBUG_SV.log(l_module_name,'X-docked Detail id-', WSH_PR_CRITERIA.release_table(i).delivery_detail_id);
1091          END IF;
1092          l_attr_tab(i).is_xdocked_flag := 'Y';
1093        END IF;
1094      END LOOP;
1095      -- LSP PROJECT : Use_header_flag value defaulting (from org/client defaults) has been moved to the calling API
1096      --          WSH_DELIVERY_AUTOCREATE.Find_Matching_Groups/Create_Hash and to recognize the change
1097      --          passing action code as 'MATCH_GROUPS_AT_PICK' instead of 'MATCH_GROUPS'.
1098      l_action_rec.action := 'MATCH_GROUPS_AT_PICK';
1099      -- LSP PROJECT : end
1100      l_action_rec.group_by_header_flag := p_use_header_flag ; --bug 8623544
1101 
1102      WSH_DELIVERY_AUTOCREATE.Find_Matching_Groups(
1103                                                    p_attr_tab => l_attr_tab,
1104                                                    p_action_rec => l_action_rec,
1105                                                    p_target_rec => l_target_rec,
1106                                                    p_group_tab => l_group_tab,
1107                                                    x_matched_entities => l_matched_entities,
1108                                                    x_out_rec => l_out_rec,
1109                                                    x_return_status => l_return_status);
1110 
1111      IF l_debug_on THEN
1112         WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
1113         WSH_DEBUG_SV.log(l_module_name,'WSH_DELIVERY_AUTOCREATE.Find_Matching_Groups l_return_status',l_return_status);
1114      END IF;
1115      IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
1116      OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
1117          x_return_status := l_return_status;
1118          WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_DELIVERY_AUTOCREATE.Find_Matching_Groups');
1119          IF l_debug_on THEN
1120             WSH_DEBUG_SV.pop(l_module_name);
1121          END IF;
1122          RETURN;
1123      END IF;
1124   END IF; --}
1125 
1126   -- X-dock
1127   -- Populate trolin_tbl only for these allocation methods, this call is not
1128   -- required for X-dock only
1129   IF g_allocation_method IN (WSH_PICK_LIST.C_INVENTORY_ONLY,
1130                               WSH_PICK_LIST.C_PRIORITIZE_CROSSDOCK,
1131                               WSH_PICK_LIST.C_PRIORITIZE_INVENTORY) THEN
1132   --{
1133 
1134     -- Print before the loop
1135     IF l_debug_on THEN
1136       WSH_DEBUG_SV.log(l_module_name, 'ALLOCATION METHOD', g_allocation_method);
1137     END IF;
1138 
1139   --bug 7171766
1140   l_group_match_seq_tbl.delete;
1141 
1142   -- Looping through Release Table
1143   FOR i in 1..WSH_PR_CRITERIA.release_table.count LOOP
1144   --{
1145       IF l_debug_on THEN
1146          WSH_DEBUG_SV.log(l_module_name, 'PROCESSING DELIVERY DETAIL', WSH_PR_CRITERIA.RELEASE_TABLE(I).DELIVERY_DETAIL_ID);
1147       END IF;
1148       IF (nvl(g_order_number, 0) <> WSH_PR_CRITERIA.release_table(i).source_header_number) THEN
1149           g_order_number := WSH_PR_CRITERIA.release_table(i).source_header_number;
1150       END IF;
1151       IF l_debug_on THEN
1152         WSH_DEBUG_SV.log(l_module_name, 'Released Status of Detail', WSH_PR_CRITERIA.RELEASE_TABLE(I).RELEASED_STATUS);
1153       END IF;
1154       IF (WSH_PR_CRITERIA.release_table(i).released_status = 'X') THEN
1155       --{
1156          IF l_debug_on THEN
1157             WSH_DEBUG_SV.logmsg(l_module_name,'IGNORING NON-TRANSACTABLE LINE FOR MOVE ORDER LINE CREATION');
1158          END IF;
1159          l_count_x_relstatus_details := l_count_x_relstatus_details + 1;
1160          l_rel_delivery_detail_id(l_count_x_relstatus_details):= WSH_PR_CRITERIA.release_table(i).delivery_detail_id;
1161       --}
1162       -- X-dock, X-dock lines which have been processed above
1163       -- will have released status of S
1164       ELSIF (WSH_PR_CRITERIA.release_table(i).released_status = WSH_DELIVERY_DETAILS_PKG.C_RELEASED_TO_WAREHOUSE) THEN --{
1165          IF l_debug_on THEN
1166             WSH_DEBUG_SV.logmsg(l_module_name,'IGNORING PLANNED X-DOCK LINE FOR MOVE ORDER LINE CREATION');
1167          END IF;
1168       --}
1169       ELSE
1170       --{
1171       --
1172          l_count := l_count + 1;
1173          g_del_detail_ids(l_count)       := WSH_PR_CRITERIA.release_table(i).delivery_detail_id;
1174          g_trolin_delivery_ids(l_count) := WSH_PR_CRITERIA.release_table(i).delivery_id;
1175          g_trolin_tbl(l_count).line_number := WSH_PR_CRITERIA.release_table(i).line_number;
1176          g_trolin_tbl(l_count).txn_source_line_detail_id := WSH_PR_CRITERIA.release_table(i).delivery_detail_id;
1177          g_trolin_tbl(l_count).created_by         := l_user_id;
1178          g_trolin_tbl(l_count).creation_date      := l_date;
1179          g_trolin_tbl(l_count).last_updated_by    := l_user_id;
1180          g_trolin_tbl(l_count).last_update_date   := l_date;
1181          g_trolin_tbl(l_count).last_update_login  := l_login_id;
1182          g_trolin_tbl(l_count).header_id          := p_mo_header_id;
1183          --Bug8683087 passing mtl_sales_order header_id
1184  	 g_trolin_tbl(l_count).txn_source_id      := WSH_PR_CRITERIA.release_table(i).demand_source_header_id;
1185          g_trolin_tbl(l_count).txn_source_line_id := WSH_PR_CRITERIA.release_table(i).source_line_id;
1186          g_trolin_tbl(l_count).organization_id    := p_organization_id;
1187          g_trolin_tbl(l_count).date_required      := WSH_PR_CRITERIA.release_table(i).date_scheduled;
1188          IF ((WSH_PR_CRITERIA.release_table(i).from_sub is NOT NULL) AND (WSH_PR_CRITERIA.g_from_subinventory IS NULL)) THEN
1189               g_trolin_tbl(l_count).from_subinventory_code := WSH_PR_CRITERIA.release_table(i).from_sub;
1190               -- Standalone project Changes : Begin
1191               -- LSP PROJECT : consider LSP mode also.
1192               IF (l_standalone_mode = 'D' OR (l_standalone_mode = 'L' AND WSH_PR_CRITERIA.release_table(i).client_id IS NOT NULL)) THEN
1193                  g_trolin_tbl(l_count).from_locator_id        := WSH_PR_CRITERIA.release_table(i).from_locator;
1194               END IF;
1195          ELSE
1196               g_trolin_tbl(l_count).from_subinventory_code := WSH_PR_CRITERIA.g_from_subinventory;
1197               -- Standalone project Changes
1198               -- wdd's loc id should be considered when released with pick from sub and no pick from loc
1199               --
1200               -- LSP PROJECT : consider LSP mode also.
1201               IF ((l_standalone_mode = 'D' OR (l_standalone_mode = 'L' AND WSH_PR_CRITERIA.release_table(i).client_id IS NOT NULL)) AND WSH_PR_CRITERIA.g_from_locator IS NULL) THEN
1202                  IF (g_trolin_tbl(l_count).from_subinventory_code = WSH_PR_CRITERIA.g_from_subinventory) THEN
1203                      g_trolin_tbl(l_count).from_locator_id        := WSH_PR_CRITERIA.release_table(i).from_locator;
1204                  ELSE
1205                      g_trolin_tbl(l_count).from_locator_id        := NULL;
1206                  END IF;
1207               ELSE
1208                  g_trolin_tbl(l_count).from_locator_id        := WSH_PR_CRITERIA.g_from_locator;
1209               END IF;
1210          END IF;
1211          -- Standalone project Changes
1212          -- LSP PROJECT : consider LSP mode also.
1213          IF (l_standalone_mode = 'D' OR (l_standalone_mode = 'L' AND WSH_PR_CRITERIA.release_table(i).client_id IS NOT NULL)) THEN
1214             g_trolin_tbl(l_count).revision   := WSH_PR_CRITERIA.release_table(i).revision;
1215             g_trolin_tbl(l_count).lot_number := WSH_PR_CRITERIA.release_table(i).lot_number;
1216          END IF;
1217          g_trolin_tbl(l_count).to_subinventory_code := p_to_subinventory;
1218          g_trolin_tbl(l_count).to_locator_id        := p_to_locator;
1219          --
1220          IF l_debug_on THEN
1221              WSH_DEBUG_SV.logmsg(l_module_name,  'DD id : '||g_del_detail_ids(l_count) );
1222              WSH_DEBUG_SV.logmsg(l_module_name,  'from sub : '||g_trolin_tbl(l_count).from_subinventory_code );
1223              WSH_DEBUG_SV.logmsg(l_module_name,  'from loc : '||g_trolin_tbl(l_count).from_locator_id );
1224              WSH_DEBUG_SV.logmsg(l_module_name,  'rev : '||g_trolin_tbl(l_count).revision );
1225              WSH_DEBUG_SV.logmsg(l_module_name,  'lot : '||g_trolin_tbl(l_count).lot_number );
1226          END IF;
1227          --- Standalone project Changes: end
1228 
1229          -- If p_num_workers in Release_Batch api is 1 and WMS Org, then populate Carton Grouping Ids for the lines
1230          IF p_worker_id IS NULL AND WSH_PICK_LIST.G_NUM_WORKERS = 1 AND p_wms_flag = 'Y' THEN
1231 	 --{
1232 	      --bug 7171766
1233               l_match_found :=FALSE;
1234 
1235 	      IF l_group_match_seq_tbl.count > 0 THEN
1236 	      --{
1237 		k:= l_group_match_seq_tbl.FIRST;  --Bugfix 10236089
1238 		   WHILE k IS NOT NULL LOOP  --Bugfix 10236089
1239 		   --{
1240 		       IF l_attr_tab(i).group_id = l_group_match_seq_tbl(k).match_group_id THEN
1241 		       --{
1242 			   l_group_match_seq_tbl(i).delivery_group_id := l_group_match_seq_tbl(k).delivery_group_id ;
1243 			   l_match_found := TRUE;
1244 			   EXIT;
1245 		       --}
1246 		       End IF;
1247 		   k:=l_group_match_seq_tbl.NEXT(k);  --Bugfix 10236089
1248 		   --}
1249 		   END LOOP;
1250 	      --}
1251 	      END IF ;
1252 
1253 	      IF NOT l_match_found THEN
1254 	      --{
1255 		  l_group_match_seq_tbl(i).match_group_id :=l_attr_tab(i).group_id;
1256 		  select WSH_DELIVERY_GROUP_S.nextval into l_group_match_seq_tbl(i).delivery_group_id from dual;
1257 	      --}
1258 	      End IF;
1259 
1260             IF l_debug_on THEN
1261                WSH_DEBUG_SV.logmsg(l_module_name,  'CARTON GROUPING ID : '||l_group_match_seq_tbl(i).delivery_group_id );
1262             END IF;
1263 
1264             g_trolin_tbl(l_count).carton_grouping_id := l_group_match_seq_tbl(i).delivery_group_id ;
1265 
1266          --}
1267          END IF;
1268 
1269          -- Get Staging Subinventory and Staging Lane for WMS Organization
1270          IF (p_wms_flag = 'Y') AND (WSH_PR_CRITERIA.release_table(i).delivery_detail_id IS NOT NULL) THEN
1271          --{
1272             OPEN get_dd_pup_trip_stop ( p_organization_id, WSH_PR_CRITERIA.release_table(i).delivery_detail_id );
1273             FETCH get_dd_pup_trip_stop INTO l_dd_pup_stop_id;
1274             IF get_dd_pup_trip_stop%NOTFOUND THEN
1275                IF l_debug_on THEN
1276                   WSH_DEBUG_SV.logmsg(l_module_name, 'DELIVERY DETAIL '||
1277                                     WSH_PR_CRITERIA.RELEASE_TABLE(I).DELIVERY_DETAIL_ID|| ' NOT ASSOCIATED TO ANY TRIP'  );
1278                END IF;
1279             ELSE
1280             --{
1281                -- If Stop_id already exists in Staging Table, use table values
1282                IF l_Stops_Ids_Tbl.EXISTS(l_dd_pup_stop_id) THEN
1283                   g_trolin_tbl(l_count).to_subinventory_code := l_Stops_Ids_Tbl(l_dd_pup_stop_id).Staging_Subinventory;
1284                   g_trolin_tbl(l_count).to_locator_id        := l_Stops_Ids_Tbl(l_dd_pup_stop_id).Staging_Lane_Id;
1285                ELSE
1286                --{
1287                   IF l_debug_on THEN
1288                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit '||
1289                                      'WMS_TRIPSTOPS_STAGELANES_PUB.GET_STGLN_FOR_TRIPSTOP',WSH_DEBUG_SV.C_PROC_LEVEL);
1290                   END IF;
1291                   x_wms_return_status := NULL;
1292                   WMS_TRIPSTOPS_STAGELANES_PUB.get_stgln_for_tripstop (
1293                                                                         p_org_id        => p_organization_id,
1294                                                                         p_trip_stop     => l_dd_pup_stop_id,
1295                                                                         x_stg_ln_id     => x_wms_stg_ln_id,
1296                                                                         x_sub_code      => x_wms_sub_code,
1297                                                                         x_return_status => x_wms_return_status,
1298                                                                         x_msg_count     => x_wms_msg_count,
1299                                                                         x_msg_data      => x_wms_msg_data);
1300                   IF l_debug_on THEN
1301                      WSH_DEBUG_SV.logmsg(l_module_name, 'WMS - RELATED VARIABLES ');
1302                      WSH_DEBUG_SV.logmsg(l_module_name, 'WMS - DD ID :'||WSH_PR_CRITERIA.RELEASE_TABLE(I).DELIVERY_DETAIL_ID);
1303                      WSH_DEBUG_SV.logmsg(l_module_name, 'WMS - PUP-STOPID :' || L_DD_PUP_STOP_ID);
1304                      WSH_DEBUG_SV.logmsg(l_module_name, 'WMS - RETN. STATUS :' || X_WMS_RETURN_STATUS);
1305                      WSH_DEBUG_SV.logmsg(l_module_name, 'WMS - STG. LN ID :' || X_WMS_STG_LN_ID);
1306                      WSH_DEBUG_SV.logmsg(l_module_name, 'WMS - STG. SUB :' || X_WMS_SUB_CODE);
1307                   END IF;
1308                   IF ( x_wms_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS ) THEN
1309                              --  AND x_wms_sub_code IS NOT NULL) THEN
1310                        g_trolin_tbl(l_count).to_subinventory_code           := x_wms_sub_code;
1311                        g_trolin_tbl(l_count).to_locator_id                  := x_wms_stg_ln_id;
1312                        l_Stops_Ids_Tbl(l_dd_pup_stop_id).Staging_Subinventory := x_wms_sub_code;
1313                        l_Stops_Ids_Tbl(l_dd_pup_stop_id).Staging_Lane_Id      := x_wms_stg_ln_id;
1314                   END IF;
1315                --}
1316                END IF;
1317             --}
1318             END IF;
1319             CLOSE get_dd_pup_trip_stop;
1320          --}
1321          END IF;
1322 
1323          g_trolin_tbl(l_count).project_id         := WSH_PR_CRITERIA.release_table(i).project_id;
1324          g_trolin_tbl(l_count).task_id            := WSH_PR_CRITERIA.release_table(i).task_id;
1325          g_trolin_tbl(l_count).inventory_item_id  := WSH_PR_CRITERIA.release_table(i).inventory_item_id;
1326          g_trolin_tbl(l_count).ship_set_id        := WSH_PR_CRITERIA.release_table(i).ship_set_id;
1327          g_trolin_tbl(l_count).ship_model_id      := WSH_PR_CRITERIA.release_table(i).top_model_line_id;
1328          g_trolin_tbl(l_count).model_quantity     := WSH_PR_CRITERIA.release_table(i).top_model_quantity;
1329          IF l_debug_on THEN
1330             WSH_DEBUG_SV.logmsg(l_module_name, 'Line Number '||G_TROLIN_TBL(L_COUNT).LINE_NUMBER||
1331                                                ' MOVE ORDER SHIP SET '||G_TROLIN_TBL(L_COUNT).SHIP_SET_ID ||
1332                                                ' MODEL ID '||G_TROLIN_TBL( L_COUNT).SHIP_MODEL_ID || ' MODEL QTY '
1333                                                ||G_TROLIN_TBL(L_COUNT).MODEL_QUANTITY  );
1334          END IF;
1335          g_trolin_tbl(l_count).quantity           := WSH_PR_CRITERIA.release_table(i).requested_quantity;
1336          g_trolin_tbl(l_count).secondary_quantity := TO_NUMBER(WSH_PR_CRITERIA.release_table(i).requested_quantity2);
1337          g_trolin_tbl(l_count).uom_code           := WSH_PR_CRITERIA.release_table(i).requested_quantity_uom;
1338          g_trolin_tbl(l_count).secondary_uom      := WSH_PR_CRITERIA.release_table(i).requested_quantity_UOM2;
1339          g_trolin_tbl(l_count).grade_code         := WSH_PR_CRITERIA.release_table(i).preferred_grade;
1340          g_trolin_tbl(l_count).line_status        := INV_Globals.G_TO_STATUS_PREAPPROVED;
1341          g_trolin_tbl(l_count).unit_number        := WSH_PR_CRITERIA.release_table(i).unit_number;
1342          -- Transaction type is different for internal orders
1343          IF (WSH_PR_CRITERIA.release_table(i).source_doc_type = 10) THEN
1344              g_trolin_tbl(l_count).transaction_type_id := INV_GLOBALS.G_TYPE_INTERNAL_ORDER_STGXFR;
1345          ELSE
1346              g_trolin_tbl(l_count).transaction_type_id := INV_GLOBALS.G_TYPE_TRANSFER_ORDER_STGXFR;
1347          END IF;
1348 
1349          -- No need to create move order line for backordered line
1350          IF (WSH_PR_CRITERIA.release_table(i).move_order_line_id IS NOT NULL) THEN
1351              g_trolin_tbl(l_count).line_id := WSH_PR_CRITERIA.release_table(i).move_order_line_id;
1352              -- The quantity for the Backordered line should be the same as the original quantity
1353              IF l_debug_on THEN
1354                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit INV_TROLIN_UTIL.QUERY_ROW',WSH_DEBUG_SV.C_PROC_LEVEL);
1355              END IF;
1356              l_temp_trolin_rec := INV_Trolin_Util.Query_Row( p_line_id => g_trolin_tbl(l_count).line_id );
1357              g_trolin_tbl(l_count).quantity := l_temp_trolin_rec.quantity;
1358              g_trolin_tbl(l_count).operation := INV_GLOBALS.G_OPR_UPDATE;
1359          ELSE
1360              g_trolin_tbl(l_count).operation := INV_GLOBALS.G_OPR_CREATE;
1361          END IF;
1362       --}
1363       END IF; -- released_status X
1364   --}
1365   END LOOP;
1366 
1367   END IF; --}
1368 
1369   --{
1370   -- Bulk Update all Non-Transactable lines as Staged
1371   IF (l_count_x_relstatus_details > 0) THEN
1372       FOR i IN 1..l_count_x_relstatus_details LOOP
1373          UPDATE wsh_delivery_details
1374          SET    released_status   = 'Y',
1375                 batch_id          = p_batch_id,
1376                 last_updated_by   = l_user_id,
1377                 last_update_date  = l_date,
1378                 last_update_login = l_login_id
1379          WHERE  delivery_detail_id = l_rel_delivery_detail_id(i);
1380 
1381          --Raise Event : Pick To Pod Workflow
1382          WSH_WF_STD.Raise_Event(
1383                                  p_entity_type => 'LINE',
1384                                  p_entity_id => l_rel_delivery_detail_id(i) ,
1385                                  p_event => 'oracle.apps.wsh.line.gen.staged' ,
1386                                  --p_parameters IN wf_parameter_list_t DEFAULT NULL,
1387                                  p_organization_id => p_organization_id,
1388                                  x_return_status => l_wf_rs ) ;
1389 
1390           IF l_debug_on THEN
1391              WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
1392              wsh_debug_sv.log(l_module_name,'Return Status After Calling WSH_WF_STD.Raise_Event',l_wf_rs);
1393           END IF;
1394           --Done Raise Event: Pick To Pod Workflow
1395       END LOOP;
1396 
1397       -- Update of wsh_delivery_details where released_status is changed, call DBI API after the update.
1398       IF l_debug_on THEN
1399          WSH_DEBUG_SV.log(l_module_name,'Calling DBI API.Detail Count-',l_rel_delivery_detail_id.count);
1400       END IF;
1401       WSH_INTEGRATION.DBI_Update_Detail_Log (
1402                                                  p_delivery_detail_id_tab => l_rel_delivery_detail_id,
1403                                                  p_dml_type               => 'UPDATE',
1404                                                  x_return_status          => l_dbi_rs );
1405       IF l_debug_on THEN
1406          WSH_DEBUG_SV.log(l_module_name,'Return Status after DBI Call-',l_dbi_rs);
1407       END IF;
1408       IF l_dbi_rs = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
1409          WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_INTEGRATION.DBI_Update_Detail_Log');
1410          x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1411          IF l_debug_on THEN
1412             WSH_DEBUG_SV.pop(l_module_name);
1413          END IF;
1414          RETURN;
1415       END IF;
1416       IF l_debug_on THEN
1417          WSH_DEBUG_SV.log(l_module_name,'l_count_x_relstatus_details updated ',l_count_x_relstatus_details);
1418       END IF;
1419   END IF;
1420   --}
1421 
1422   -- Move Order Lines Creation
1423   IF (g_trolin_tbl.count > 0)  THEN
1424   --{
1425      IF p_express_pick_flag = 'N' THEN
1426      --{
1427         IF l_debug_on THEN
1428            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit INV_MOVE_ORDER_PUB.CREATE_MOVE_ORDER_LINES',
1429                                               WSH_DEBUG_SV.C_PROC_LEVEL);
1430            WSH_DEBUG_SV.log(l_module_name, 'G_TROLIN_TBL.COUNT',G_TROLIN_TBL.COUNT);
1431            WSH_DEBUG_SV.log(l_module_name, 'Current Time is ',SYSDATE);
1432         END IF;
1433         Inv_Move_Order_Pub.Create_Move_Order_Lines
1434                     (
1435                        p_api_version_number  => l_api_version_number,
1436                        p_init_msg_list       => FND_API.G_FALSE,
1437                        p_return_values       => FND_API.G_TRUE,
1438                        p_commit              => l_commit,
1439                        p_trolin_tbl          => g_trolin_tbl,
1440                        p_trolin_val_tbl      => l_trolin_val_tbl,
1441                        p_validation_flag     => 'N', -- Inventory will skip most validations and assume Shipping validates them
1442                        x_trolin_tbl          => g_trolin_tbl,
1443                        x_trolin_val_tbl      => l_trolin_val_tbl,
1444                        x_return_status       => l_return_status,
1445                        x_msg_count           => l_msg_count,
1446                        x_msg_data            => l_msg_data
1447                       );
1448         IF l_debug_on THEN
1449            WSH_DEBUG_SV.log(l_module_name, 'Current Time is ',SYSDATE);
1450            WSH_DEBUG_SV.log(l_module_name, 'Return status from INV API', l_return_status);
1451            WSH_DEBUG_SV.log(l_module_name, 'l_msg_count', l_msg_count);
1452            WSH_DEBUG_SV.log(l_module_name, 'l_msg_data', l_msg_data);
1453         END IF;
1454         IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
1455         --{
1456            WSH_UTIL_CORE.PrintMsg('Error occurred in Inv_Move_Order_Pub.Create_Move_Order_Lines');
1457            FOR i in 1..l_msg_count LOOP
1458                l_message := fnd_msg_pub.get(i,'F');
1459                l_message := replace(l_message,chr(0),' ');
1460                WSH_UTIL_CORE.PrintMsg(l_message);
1461            END LOOP;
1462            fnd_msg_pub.delete_msg();
1463            IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1464            --{
1465               WSH_UTIL_CORE.PrintMsg('Unexpected error from Inv_Move_Order_Pub.Create_Move_Order_Lines. Exiting');
1466               x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1467               IF l_debug_on THEN
1468                  WSH_DEBUG_SV.pop(l_module_name);
1469               END IF;
1470               RETURN;
1471            --}
1472            ELSE
1473            --{
1474               WSH_UTIL_CORE.PrintMsg('Create Move Order Lines Partially Successful');
1475               x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
1476   	      IF l_debug_on THEN
1477   	         WSH_DEBUG_SV.logmsg(l_module_name, 'Create Move Order Lines Partially Successful');
1478   	         WSH_DEBUG_SV.logmsg(l_module_name, 'Remove lines that errored out in INV');
1479   	      END IF;
1480               -- Bug 2522935 : Error in MO line creation for Ship Sets causes Released to Warehouse lines
1481               -- Delete all the Lines which had the return status as error from Inventory's Move Order Line API
1482               FOR i in 1..g_trolin_tbl.count LOOP
1483                   IF g_trolin_tbl(i).return_status = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
1484                      WSH_UTIL_CORE.PrintMsg('Delete Line '||g_trolin_tbl(i).line_id);
1485   	             IF l_debug_on THEN
1486   	        	WSH_DEBUG_SV.log(l_module_name, 'Deleting line', g_trolin_tbl(i).line_id);
1487                      END IF;
1488                      g_trolin_tbl.delete(i);
1489                      l_trolin_val_tbl.delete(i);
1490                      g_del_detail_ids.delete(i);
1491                      g_trolin_delivery_ids.delete(i);
1492                   END IF;
1493               END LOOP;
1494               WSH_UTIL_CORE.PrintMsg('After deleting lines, Trolin Table count '||g_del_detail_ids.count);
1495               IF l_debug_on THEN
1496   	         WSH_DEBUG_SV.log(l_module_name, 'g_del_detail_ids.count', g_del_detail_ids.count);
1497               END IF;
1498            --}
1499            END IF;
1500         --}
1501         ELSIF (l_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
1502         --{
1503            G_ONLINE_PICK_RELEASE_PHASE := 'MOVE_ORDER_LINES';
1504            IF l_debug_on THEN
1505               WSH_DEBUG_SV.logmsg(l_module_name,  'CREATED MO LINES SUCESSFULLY');
1506   	      WSH_DEBUG_SV.log(l_module_name, 'g_del_detail_ids.count', g_del_detail_ids.count);
1507            END IF;
1508         --}
1509         END IF;
1510      --}
1511      ELSE -- l_express_pick_flag =
1512      --{
1513         IF l_debug_on THEN
1514            WSH_DEBUG_SV.logmsg(l_module_name,'============');
1515            WSH_DEBUG_SV.logmsg(l_module_name,'Express Pick');
1516            WSH_DEBUG_SV.logmsg(l_module_name,'============');
1517            WSH_DEBUG_SV.logmsg(l_module_name,'Calling Inv_Express_Pick_Pub.Pick_Release with COUNT:'||G_TROLIN_TBL.COUNT  );
1518            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Inv_Express_Pick_Pub.Pick_Release',WSH_DEBUG_SV.C_PROC_LEVEL);
1519         END IF;
1520         WSH_PICK_LIST.G_AUTO_PICK_CONFIRM := 'Y';
1521         Inv_Express_Pick_Pub.Pick_Release (
1522                     p_api_version            => l_api_version_number,
1523                     p_init_msg_list          => FND_API.G_TRUE,
1524                     p_commit                 => l_commit,
1525                     p_mo_line_tbl            => g_trolin_tbl,
1526                     p_grouping_rule_id       => p_pick_slip_grouping_rule,
1527                     p_reservations_tbl       => l_dummy_rsv_tbl,
1528                     p_allow_partial_pick     => FND_API.G_TRUE,
1529                     p_pick_release_status_tbl=> g_exp_pick_release_stat,
1530                     x_return_status          => l_return_status,
1531                     x_msg_count              => l_msg_count,
1532                     x_msg_data               => l_msg_data);
1533         IF l_debug_on THEN
1534            WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
1535            WSH_DEBUG_SV.log(l_module_name,'Inv_Express_Pick_Pub.Pick_Release l_return_status',l_return_status);
1536         END IF;
1537         IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
1538         --{
1539            WSH_UTIL_CORE.PrintMsg('Error occurred in Inv_Express_Pick_Pub.Pick_Release');
1540            FOR i in 1..l_msg_count LOOP
1541                l_message := fnd_msg_pub.get(i,'F');
1542                l_message := replace(l_message,chr(0),' ');
1543                WSH_UTIL_CORE.PrintMsg(l_message);
1544                IF (i = 1) THEN
1545                    l_message1 := l_message;
1546                END IF;
1547            END LOOP;
1548            fnd_msg_pub.delete_msg();
1549            IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1550            --{
1551               WSH_UTIL_CORE.PrintMsg('Unexpected error from Inv_Express_Pick_Pub.Pick_Release. Exiting');
1552               x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1553               IF l_debug_on THEN
1554                  WSH_DEBUG_SV.pop(l_module_name);
1555               END IF;
1556               RETURN;
1557            --}
1558            ELSE
1559            --{
1560               ROLLBACK TO BEF_MOVE_ORDER_LINE_CREATE;
1561               WSH_UTIL_CORE.PrintMsg('Express Pick Release Returned Expected Error');
1562               x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
1563               l_request_id := fnd_global.conc_request_id;
1564               IF (l_request_id <> -1 OR G_BATCH_ID IS NOT NULL ) THEN
1565               --{
1566                  FOR i in 1 .. WSH_PR_CRITERIA.release_table.count LOOP
1567                      IF l_debug_on THEN
1568                         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.GET_ITEM_NAME',WSH_DEBUG_SV.C_PROC_LEVEL);
1569                      END IF;
1570                      l_item_name := WSH_UTIL_CORE.Get_Item_Name(WSH_PR_CRITERIA.release_table(i).inventory_item_id,
1571                                                                 WSH_PR_CRITERIA.release_table(i).organization_id);
1572                      FND_MESSAGE.SET_NAME('WSH','WSH_INV_EXPECTED_ERROR');
1573                      FND_MESSAGE.SET_TOKEN('ITEM',l_item_name);
1574                      FND_MESSAGE.SET_TOKEN('ORDER',WSH_PR_CRITERIA.release_table(i).source_header_number);
1575                      FND_MESSAGE.SET_TOKEN('INVMESSAGE',l_message1);
1576                      l_message := FND_MESSAGE.GET;
1577                      l_exception_return_status := NULL;
1578                      l_exception_msg_count := NULL;
1579                      l_exception_msg_data := NULL;
1580                      l_dummy_exception_id := NULL;
1581                      IF l_debug_on THEN
1582                         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_XC_UTIL.LOG_EXCEPTION',WSH_DEBUG_SV.C_PROC_LEVEL);
1583                      END IF;
1584                      WSH_XC_UTIL.Log_Exception(
1585                               p_api_version             => 1.0,
1586                               p_logging_entity          => 'SHIPPER',
1587                               p_logging_entity_id       => FND_GLOBAL.USER_ID,
1588                               p_exception_name          => 'WSH_INV_EXPECTED_ERROR',
1589                               p_message                 => l_message,
1590                               p_inventory_item_id       => WSH_PR_CRITERIA.release_table(i).inventory_item_id,
1591                               p_logged_at_location_id   => WSH_PR_CRITERIA.release_table(i).ship_from_location_id,
1592                               p_exception_location_id   => WSH_PR_CRITERIA.release_table(i).ship_from_location_id,
1593                               p_request_id              => l_request_id,
1594                               p_batch_id                => WSH_PICK_LIST.g_batch_id,
1595                               x_return_status           => l_exception_return_status,
1596                               x_msg_count               => l_exception_msg_count,
1597                               x_msg_data                => l_exception_msg_data,
1598                               x_exception_id            => l_dummy_exception_id);
1599                      IF l_debug_on THEN
1600                         WSH_DEBUG_SV.logmsg(l_module_name,  'LOGGED EXCEPTION '||L_DUMMY_EXCEPTION_ID  );
1601                      END IF;
1602                  END LOOP;
1603               --}
1604               END IF;
1605            --}
1606            END IF;
1607         --}
1608         END IF;
1609 
1610         IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
1611         --{
1612             /* INV will always pass 'delivery_detail_id' in the record structure and this will be in the same
1613                order as passed by shipping.
1614                1. If a dd is completely picked and the dd is Staged using only 1 reservation
1615                   then INV should pass pick_status 'S' and split_delivery_id null
1616                2. If a dd is completely picked and the dd is Staged using more than 1 reservation
1617                   then INV should pass pick_status 'S' and split_delivery_id for all split details. Also
1618                   INV should pass another record with pick_status 'S'.
1619                3. If a dd is partially picked and the dd is Staged using only 1 reservation
1620                   then INV should pass pick_status 'S' and split_delivery_id for split detail. Also
1621                   INV should pass another record with pick_status 'P' with split_delivery_id null.
1622                4. If a dd is partially picked and the dd is Staged using more than 1 reservation
1623                   then INV should pass pick_status 'S' and split_delivery_id for all split details. Also
1624                   INV should pass another record with pick_status 'P' with split_delivery_id null
1625                5. If a dd is completely ignored(say it has only org level reservation or it has partial detail
1626                   reservation and is in ship set)
1627                   then INV will pass pick_status 'F' and split_delivery_id  null.
1628                6. If a dd is completely ignored because other line in ship set couldn't be fulfilled
1629                   then INV will pass pick_status 'I' and split_delivery_id  null.
1630             */
1631             IF l_debug_on THEN
1632                FOR i IN g_exp_pick_release_stat.FIRST..g_exp_pick_release_stat.LAST LOOP
1633                    WSH_DEBUG_SV.logmsg(l_module_name,i||' '||g_exp_pick_release_stat(i).delivery_detail_id||
1634                                          ' '||g_exp_pick_release_stat(i).pick_status||
1635                                          ' '||g_exp_pick_release_stat(i).split_delivery_id);
1636                END LOOP;
1637             END IF;
1638         --}
1639         END IF;
1640      --}
1641      END IF;
1642   --}
1643   END IF; -- g_trolin_tbl.count > 0
1644 
1645   x_curr_count := x_curr_count + WSH_PR_CRITERIA.release_table.count ;
1646 
1647   -- Save Move Order Line IDs into Delivery Details table
1648   IF p_express_pick_flag = 'N' THEN
1649   --{
1650      -- Bug 2522935 : Error in MO line creation for Ship Sets causes Released to Warehouse lines
1651      i :=  g_trolin_tbl.FIRST;
1652      l_detail_tab.delete; -- DBI Project
1653      WHILE i IS NOT NULL LOOP
1654      --{
1655         --Bug 5645615: Since we are deleting lines with error status, get the next index before we might delete the line.
1656         j := g_trolin_tbl.NEXT(i);
1657         BEGIN
1658           IF (g_trolin_tbl(i).return_status =  WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
1659               IF l_debug_on THEN
1660                  WSH_DEBUG_SV.logmsg(l_module_name,  'UPDATE WITH TROLIN.LINE_ID ' || G_TROLIN_TBL(I).LINE_ID  );
1661               END IF;
1662               UPDATE wsh_delivery_details
1663               SET    move_order_line_id = g_trolin_tbl(i).line_id,
1664                      released_status = WSH_DELIVERY_DETAILS_PKG.C_RELEASED_TO_WAREHOUSE,
1665                      batch_id   = p_batch_id,
1666                      last_updated_by = l_user_id,
1667                      last_update_date   = l_date,
1668                      last_update_login  = l_login_id,
1669                      replenishment_status = NULL    -- bug# 6719369 (replenishment project)
1670               WHERE  delivery_detail_id = g_del_detail_ids(i);
1671 
1672 	      l_detail_tab(l_detail_tab.count+1) := g_del_detail_ids(i); -- DBI Project
1673               --DBI
1674               WSH_DD_TXNS_PVT.create_dd_txn_from_dd  (
1675                                                        p_delivery_detail_id => g_del_detail_ids(i),
1676                                                        x_dd_txn_id => l_dd_txn_id,
1677                                                        x_return_status =>l_txn_return_status);
1678               IF (l_txn_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
1679                   x_return_status := l_txn_return_status;
1680                   WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_DD_TXNS_PVT.create_dd_txn_from_dd');
1681                   IF l_debug_on THEN
1682                      WSH_DEBUG_SV.pop(l_module_name);
1683                   END IF;
1684                   RETURN;
1685               END IF;
1686               --DBI
1687 
1688               --Raise Event : Pick To Pod Workflow
1689               WSH_WF_STD.Raise_Event(
1690                                       p_entity_type => 'LINE',
1691                                       p_entity_id => g_del_detail_ids(i) ,
1692                                       p_event => 'oracle.apps.wsh.line.gen.releasedtowarehouse' ,
1693                                       --p_parameters IN wf_parameter_list_t DEFAULT NULL,
1694                                       p_organization_id => p_organization_id,
1695                                       x_return_status => l_wf_rs ) ;
1696               IF l_debug_on THEN
1697                  WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
1698                  wsh_debug_sv.log(l_module_name,'Return Status After Calling WSH_WF_STD.Raise_Event',l_wf_rs);
1699               END IF;
1700 
1701               OPEN c_get_picked_lines_count( g_del_detail_ids(i) );
1702               FETCH c_get_picked_lines_count INTO l_count_picked_lines, l_delv_id ;
1703               IF (c_get_picked_lines_count%FOUND) THEN
1704                   IF ( l_count_picked_lines=1) THEN --If it is the first line in a delivery to be released
1705                        WSH_WF_STD.Raise_Event(
1706                                                p_entity_type => 'DELIVERY',
1707                                                p_entity_id => l_delv_id ,
1708                                                p_event => 'oracle.apps.wsh.delivery.pik.pickinitiated' ,
1709                                                p_organization_id => p_organization_id,
1710                                                x_return_status => l_wf_rs ) ;
1711                        IF l_debug_on THEN
1712                           WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
1713                           wsh_debug_sv.log(l_module_name,'Return Status After Calling WSH_WF_STD.Raise_Event',l_wf_rs);
1714                        END IF;
1715                   END IF;
1716               END IF;
1717               CLOSE c_get_picked_lines_count;
1718               --Done Raise Event : Pick To Pod Workflow
1719 
1720           ELSE
1721               WSH_UTIL_CORE.PrintMsg('Could not Create Move Order Line for Delivery Detail '||g_del_detail_ids(i));
1722               -- Bug 5645615: Delete all the lines with return status error.
1723               IF g_trolin_tbl(i).return_status = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
1724                  WSH_UTIL_CORE.PrintMsg('Delete Line '||g_trolin_tbl(i).line_id);
1725                  IF l_debug_on THEN
1726                     WSH_DEBUG_SV.log(l_module_name, 'Deleting trolin line', g_trolin_tbl(i).line_id);
1727                     WSH_DEBUG_SV.log(l_module_name, 'Deleting detail line', g_del_detail_ids(i));
1728                  END IF;
1729                  g_trolin_tbl.delete(i);
1730                  l_trolin_val_tbl.delete(i);
1731                  g_del_detail_ids.delete(i);
1732                  g_trolin_delivery_ids.delete(i);
1733               END IF;
1734 
1735           END IF;
1736         EXCEPTION
1737           WHEN no_data_found THEN
1738                WSH_UTIL_CORE.PrintMsg('Delivery detail line not found: '|| WSH_PR_CRITERIA.release_table(i).delivery_detail_id);
1739                x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1740                IF l_debug_on THEN
1741                   WSH_DEBUG_SV.pop(l_module_name);
1742                END IF;
1743                RETURN;
1744           WHEN others THEN
1745                WSH_UTIL_CORE.PrintMsg('Cannot update delivery detail: ' || WSH_PR_CRITERIA.release_table(i).delivery_detail_id);
1746                x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1747                IF l_debug_on THEN
1748                   WSH_DEBUG_SV.pop(l_module_name);
1749                END IF;
1750                RETURN;
1751         END;
1752         i := j;
1753      --}
1754      END LOOP;
1755      IF l_debug_on THEN
1756         WSH_DEBUG_SV.log(l_module_name, 'g_trolin_tbl.count', g_trolin_tbl.count);
1757         WSH_DEBUG_SV.log(l_module_name, 'g_del_detail_ids.count', g_del_detail_ids.count);
1758      END IF;
1759 
1760      -- Update of wsh_delivery_details where released_status is changed, call DBI API after the update.
1761      IF l_debug_on THEN
1762         WSH_DEBUG_SV.log(l_module_name,'Calling DBI API.Detail count',l_detail_tab.count);
1763      END IF;
1764      WSH_INTEGRATION.DBI_Update_Detail_Log (
1765                                              p_delivery_detail_id_tab => l_detail_tab,
1766                                              p_dml_type               => 'UPDATE',
1767                                              x_return_status          => l_dbi_rs );
1768      IF l_debug_on THEN
1769         WSH_DEBUG_SV.log(l_module_name,'Return Status after DBI Call-',l_dbi_rs);
1770      END IF;
1771      IF l_dbi_rs = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
1772         x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1773         WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_INTEGRATION.DBI_Update_Detail_Log');
1774 	IF l_debug_on THEN
1775            WSH_DEBUG_SV.pop(l_module_name);
1776         END IF;
1777 	RETURN;
1778      END IF;
1779   --}
1780   END IF;
1781 
1782   IF l_debug_on THEN
1783      WSH_DEBUG_SV.pop(l_module_name);
1784   END IF;
1785 
1786 EXCEPTION
1787       WHEN OTHERS THEN
1788          IF get_dd_pup_trip_stop%ISOPEN THEN
1789             CLOSE get_dd_pup_trip_stop;
1790          END IF;
1791          x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1792          IF l_debug_on THEN
1793             WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '
1794                                 || SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1795             WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
1796          END IF;
1797 
1798 END Create_Move_Order_Lines;
1799 
1800 
1801 -- Start of comments
1802 -- API name : Autocreate_Deliveries
1803 -- Type     : Private
1804 -- Pre-reqs : None.
1805 -- Procedure: This API will append deliveries and call Autocreate_Deliveries to
1806 --            create deliveries
1807 -- Parameters :
1808 -- IN:
1809 --      p_append_flag               IN  Append Flag, Valid Values Y/N.
1810 --      p_use_header_flag           IN  Deliveries should be unique for each order, Valid Values Y/N.
1811 --      p_del_details_tbl           IN  Table of Delivery Details for Delivery creation.
1812 -- OUT:
1813 --      x_return_status             OUT NOCOPY  Return Status.
1814 -- End of comments
1815 PROCEDURE Autocreate_Deliveries(
1816       p_append_flag                  IN      VARCHAR2,
1817       p_use_header_flag              IN      VARCHAR2,
1818       p_del_details_tbl              IN      WSH_UTIL_CORE.Id_Tab_Type,
1819       x_return_status                OUT NOCOPY VARCHAR2)
1820 IS
1821 
1822   CURSOR del_cur(c_dlvy_id NUMBER) IS
1823   SELECT ship_method_code, intmed_ship_to_location_id
1824   FROM   wsh_new_deliveries
1825   WHERE  delivery_id = c_dlvy_id;
1826 
1827   l_del_details_tbl   WSH_UTIL_CORE.Id_Tab_Type;
1828   l_grouping_tbl      WSH_UTIL_CORE.Id_Tab_Type;
1829   l_delivery_ids_tbl  WSH_UTIL_CORE.Id_Tab_Type;
1830   i                   NUMBER;
1831   j                   NUMBER;
1832   l_msg_count         NUMBER;
1833   l_msg_data          VARCHAR2(2000);
1834   l_return_status     VARCHAR2(1);
1835 
1836   --Compatibility Changes
1837   l_cc_validate_result          VARCHAR2(1);
1838   l_cc_failed_records           WSH_FTE_COMP_CONSTRAINT_PKG.failed_line_tab_type;
1839   l_cc_line_groups              WSH_FTE_COMP_CONSTRAINT_PKG.line_group_tab_type;
1840   l_cc_group_info               WSH_FTE_COMP_CONSTRAINT_PKG.cc_group_tab_type;
1841   b_cc_linefailed               BOOLEAN;
1842   b_cc_groupidexists            BOOLEAN;
1843   l_id_tab_temp                 WSH_UTIL_CORE.Id_Tab_Type;
1844   l_del_details_tbl_temp        WSH_UTIL_CORE.Id_Tab_Type;
1845   l_cc_count_success            NUMBER;
1846   l_cc_count_group_ids          NUMBER;
1847   l_cc_count_rec                NUMBER;
1848   l_cc_group_ids                WSH_UTIL_CORE.Id_Tab_Type;
1849   l_cc_upd_dlvy_intmed_ship_to  VARCHAR2(1);
1850   l_cc_upd_dlvy_ship_method     VARCHAR2(1);
1851   l_cc_dlvy_intmed_ship_to      NUMBER;
1852   l_cc_dlvy_ship_method         VARCHAR2(30);
1853   l_num_errors                  NUMBER;
1854   l_num_warnings                NUMBER;
1855   l_cc_del_rows                 WSH_UTIL_CORE.Id_Tab_Type;
1856   l_cc_grouping_rows            WSH_UTIL_CORE.Id_Tab_Type;
1857   l_cc_return_status            VARCHAR2(1);
1858   l_cc_count_del_rows           NUMBER;
1859   l_cc_count_grouping_rows      NUMBER;
1860   --dummy tables for calling validate_constraint_main
1861   l_cc_del_attr_tab             WSH_NEW_DELIVERIES_PVT.Delivery_Attr_Tbl_Type;
1862   l_cc_det_attr_tab             WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type;
1863   l_cc_trip_attr_tab            WSH_TRIPS_PVT.Trip_Attr_Tbl_Type;
1864   l_cc_stop_attr_tab            WSH_TRIP_STOPS_PVT.Stop_Attr_Tbl_Type;
1865   l_cc_in_ids                   WSH_UTIL_CORE.Id_Tab_Type;
1866   l_cc_fail_ids                 WSH_UTIL_CORE.Id_Tab_Type;
1867   -- deliveryMerge
1868   l_appended_det_tbl              WSH_DELIVERY_DETAILS_UTILITIES.delivery_assignment_rec_tbl;
1869   l_unappended_det_tbl            WSH_UTIL_CORE.Id_Tab_Type;
1870   l_default_ship_confirm_rule_id  NUMBER := NULL;
1871   l_appended_del_tbl              WSH_UTIL_CORE.Id_Tab_Type;
1872   l_tmp_del_tbl                   WSH_UTIL_CORE.Id_Tab_Type;
1873   --
1874   l_debug_on BOOLEAN;
1875   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'AUTOCREATE_DELIVERIES';
1876   --
1877 
1878 BEGIN
1879 
1880   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
1881   IF l_debug_on IS NULL
1882   THEN
1883     l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
1884   END IF;
1885 
1886   IF l_debug_on THEN
1887      WSH_DEBUG_SV.push(l_module_name);
1888      WSH_DEBUG_SV.log(l_module_name,'P_APPEND_FLAG',P_APPEND_FLAG);
1889      WSH_DEBUG_SV.log(l_module_name,'P_USE_HEADER_FLAG',P_USE_HEADER_FLAG);
1890      WSH_DEBUG_SV.log(l_module_name,'P_DEL_DETAILS_TBL.COUNT',P_DEL_DETAILS_TBL.COUNT);
1891   END IF;
1892 
1893   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1894 
1895   l_del_details_tbl := p_del_details_tbl;
1896   l_appended_del_tbl.delete;
1897 
1898   -- Check whether we have eligible lines to autocreate
1899   IF (l_del_details_tbl.count > 0) THEN
1900   --{
1901      --Compatibility Changes
1902      IF wsh_util_core.fte_is_installed = 'Y' THEN
1903      --{
1904         l_cc_line_groups.delete;
1905         l_cc_group_info.delete;
1906         l_cc_failed_records.delete;
1907         IF l_debug_on THEN
1908            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_FTE_COMP_CONSTRAINT_PKG.validate_constraint_main' ,WSH_DEBUG_SV.C_PROC_LEVEL);
1909            WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
1910         END IF;
1911         WSH_FTE_COMP_CONSTRAINT_PKG.validate_constraint_main (
1912                                                                p_api_version_number =>  1.0,
1913                                                                p_init_msg_list      =>  FND_API.G_FALSE,
1914                                                                p_entity_type        =>  'L',
1915                                                                p_target_id          =>  null,
1916                                                                p_action_code        =>  'AUTOCREATE-DEL',
1917                                                                p_del_attr_tab       =>  l_cc_del_attr_tab,
1918                                                                p_det_attr_tab       =>  l_cc_det_attr_tab,
1919                                                                p_trip_attr_tab      =>  l_cc_trip_attr_tab,
1920                                                                p_stop_attr_tab      =>  l_cc_stop_attr_tab,
1921                                                                p_in_ids             =>  l_del_details_tbl,
1922                                                                x_fail_ids           =>  l_cc_fail_ids,
1923                                                                x_validate_result    =>  l_cc_validate_result,
1924                                                                x_failed_lines       =>  l_cc_failed_records,
1925                                                                x_line_groups        =>  l_cc_line_groups,
1926                                                                x_group_info         =>  l_cc_group_info,
1927                                                                x_msg_count          =>  l_msg_count,
1928                                                                x_msg_data           =>  l_msg_data,
1929                                                                x_return_status      =>  l_return_status );
1930         IF l_debug_on THEN
1931            WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
1932            WSH_DEBUG_SV.log(l_module_name,'Return Status After Calling validate_constraint_main',l_return_status);
1933            WSH_DEBUG_SV.log(l_module_name,'validate_result After Calling validate_constraint_main'
1934                                          ,l_cc_validate_result);
1935            WSH_DEBUG_SV.log(l_module_name,'msg_count After Calling validate_constraint_main',l_msg_count);
1936            WSH_DEBUG_SV.log(l_module_name,'msg_data After Calling validate_constraint_main',l_msg_data);
1937            WSH_DEBUG_SV.log(l_module_name,'fail_ids count After Calling validate_constraint_main'
1938                                          ,l_cc_failed_records.COUNT);
1939            WSH_DEBUG_SV.log(l_module_name,'l_cc_line_groups.count count After Calling validate_constraint_main'
1940                                          ,l_cc_line_groups.COUNT);
1941            WSH_DEBUG_SV.log(l_module_name,'group_info count After Calling validate_constraint_main'
1942                                          ,l_cc_group_info.COUNT);
1943         END IF;
1944         IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1945         --{
1946             x_return_status := l_return_status;
1947             WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_FTE_COMP_CONSTRAINT_PKG.validate_constraint_main');
1948             IF l_debug_on THEN
1949                WSH_DEBUG_SV.pop(l_module_name);
1950             END IF;
1951             RETURN;
1952         --}
1953         END IF;
1954 
1955         IF l_cc_line_groups.COUNT > 0 AND l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
1956         --{
1957            --set return_status as warning
1958            IF l_cc_failed_records.COUNT <> l_del_details_tbl.COUNT THEN
1959               l_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
1960            END IF;
1961 
1962            --1. get the group ids by which the constraints API has grouped the lines
1963            l_cc_count_group_ids := 1;
1964            FOR i in l_cc_line_groups.FIRST..l_cc_line_groups.LAST LOOP
1965                b_cc_groupidexists := FALSE;
1966                IF l_cc_group_ids.COUNT > 0 THEN
1967                   FOR j in l_cc_group_ids.FIRST..l_cc_group_ids.LAST LOOP
1968                       IF (l_cc_line_groups(i).line_group_id = l_cc_group_ids(j)) THEN
1969                           b_cc_groupidexists := TRUE;
1970                       END IF;
1971                   END LOOP;
1972                END IF;
1973                IF (NOT(b_cc_groupidexists)) THEN
1974                    l_cc_group_ids(l_cc_count_group_ids) := l_cc_line_groups(i).line_group_id;
1975                    l_cc_count_group_ids := l_cc_count_group_ids+1;
1976                END IF;
1977            END LOOP;
1978 
1979            --2. from the group id table above, loop thru lines table to get the lines which belong
1980            --to each group and call autocreate_trip for each group
1981            FOR i in l_cc_group_ids.FIRST..l_cc_group_ids.LAST LOOP
1982            --{
1983                l_id_tab_temp.delete;
1984                l_cc_count_rec := 1;
1985                FOR j in l_cc_line_groups.FIRST..l_cc_line_groups.LAST LOOP
1986                    IF l_cc_line_groups(j).line_group_id = l_cc_group_ids(i) THEN
1987                       l_id_tab_temp(l_cc_count_rec) := l_cc_line_groups(j).entity_line_id;
1988                       l_cc_count_rec := l_cc_count_rec+1;
1989                    END IF;
1990                END LOOP;
1991                --{
1992                IF l_debug_on THEN
1993                   WSH_DEBUG_SV.log(l_module_name,'det. tab count: '|| l_id_tab_temp.count);
1994                   WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_UTILITIES.Append_to_Deliveries' ,WSH_DEBUG_SV.C_PROC_LEVEL);
1995                   WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
1996                END IF;
1997                WSH_DELIVERY_DETAILS_UTILITIES.Append_to_Deliveries (
1998                             p_delivery_detail_tbl     => l_id_tab_temp,
1999                             p_append_flag             => p_append_flag,
2000                             p_group_by_header         => p_use_header_flag,
2001                             p_commit                  => FND_API.G_FALSE,
2002                             p_lock_rows               => FND_API.G_FALSE,
2003                             p_check_fte_compatibility => FND_API.G_FALSE,
2004                             x_appended_det_tbl        => l_appended_det_tbl,
2005                             x_unappended_det_tbl      => l_unappended_det_tbl,
2006                             x_appended_del_tbl        => l_tmp_del_tbl,
2007                             x_return_status           => l_return_status );
2008                IF l_debug_on THEN
2009                   WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2010                   WSH_DEBUG_SV.log(l_module_name,'Return status from Append_to_Deliveries is: ',l_return_status );
2011                END IF;
2012                IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR
2013                OR l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
2014                   x_return_status := l_return_status;
2015                   WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_DELIVERY_DETAILS_UTILITIES.Append_to_Deliveries');
2016                   IF l_debug_on THEN
2017                      WSH_DEBUG_SV.pop(l_module_name);
2018                   END IF;
2019                   RETURN;
2020                END IF;
2021                --}
2022 
2023                -- deliveryMerge, collect appended deliveries
2024                IF l_appended_del_tbl.COUNT = 0 THEN
2025                   l_appended_del_tbl := l_tmp_del_tbl;
2026                ELSE
2027                   IF l_tmp_del_tbl.COUNT > 0 THEN
2028                      FOR i in l_tmp_del_tbl.FIRST..l_tmp_del_tbl.LAST LOOP
2029                          l_appended_del_tbl(l_appended_del_tbl.count+1) := l_tmp_del_tbl(i);
2030                      END LOOP;
2031                   END IF;
2032                END IF;
2033 
2034                l_id_tab_temp.delete;
2035                l_id_tab_temp := l_unappended_det_tbl;
2036 
2037                IF l_debug_on THEN
2038                   WSH_DEBUG_SV.log(l_module_name,'id_tab_temp count ',l_id_tab_temp.COUNT);
2039                   WSH_DEBUG_SV.log(l_module_name,'det. tab count: '|| l_del_details_tbl.count);
2040                   WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_AUTOCREATE.AUTOCREATE_DELIVERIES',WSH_DEBUG_SV.C_PROC_LEVEL);
2041                   WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2042                END IF;
2043                --{
2044                IF l_id_tab_temp.count > 0 THEN
2045                   WSH_DELIVERY_AUTOCREATE.Autocreate_Deliveries (
2046                                p_line_rows         =>  l_id_tab_temp,
2047                                p_init_flag         =>  'Y',  -- Should refresh the PL/SQL tables for compatibility
2048                                p_pick_release_flag =>  'N',
2049                                x_del_rows          =>  l_delivery_ids_tbl,
2050                                x_grouping_rows     =>  l_grouping_tbl,
2051                                x_return_status     =>  l_cc_return_status );
2052                   IF l_debug_on THEN
2053                      WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2054                      WSH_DEBUG_SV.log(l_module_name,'WSH_DELIVERY_AUTOCREATE.Autocreate_Deliveries l_cc_return_status',l_cc_return_status);
2055                   END IF;
2056 
2057                   -- set the intermediate ship to, ship method to null if group rec from constraint validation
2058                   -- has these as 'N'
2059                   l_cc_upd_dlvy_intmed_ship_to := 'Y';
2060                   l_cc_upd_dlvy_ship_method    := 'Y';
2061                   IF l_cc_group_info.COUNT > 0 THEN
2062                      FOR j in l_cc_group_info.FIRST..l_cc_group_info.LAST LOOP
2063                          IF l_cc_group_info(j).line_group_id = l_cc_group_ids(i) THEN
2064                             l_cc_upd_dlvy_intmed_ship_to := l_cc_group_info(j).upd_dlvy_intmed_ship_to;
2065                             l_cc_upd_dlvy_ship_method := l_cc_group_info(j).upd_dlvy_ship_method;
2066                          END IF;
2067                      END LOOP;
2068                   END IF;
2069 
2070                   IF l_debug_on THEN
2071                      WSH_DEBUG_SV.log(l_module_name,'l_cc_upd_dlvy_intmed_ship_to ',l_cc_upd_dlvy_intmed_ship_to);
2072                      WSH_DEBUG_SV.log(l_module_name,'l_cc_upd_dlvy_ship_method ',l_cc_upd_dlvy_ship_method);
2073                      WSH_DEBUG_SV.log(l_module_name,'l_delivery_ids_tbl.COUNT ',l_delivery_ids_tbl.COUNT);
2074                      WSH_DEBUG_SV.log(l_module_name,'l_grouping_tbl.COUNT ',l_grouping_tbl.COUNT);
2075                      WSH_DEBUG_SV.log(l_module_name,'l_cc_return_status ',l_cc_return_status);
2076                   END IF;
2077 
2078                   IF l_cc_upd_dlvy_intmed_ship_to = 'N' OR l_cc_upd_dlvy_ship_method = 'N' THEN
2079                      IF l_delivery_ids_tbl.COUNT > 0 THEN
2080                         FOR i in l_delivery_ids_tbl.FIRST..l_delivery_ids_tbl.LAST LOOP
2081                             FOR delcurtemp in del_cur(l_delivery_ids_tbl(i)) LOOP
2082                                 l_cc_dlvy_intmed_ship_to := delcurtemp.INTMED_SHIP_TO_LOCATION_ID;
2083                                 l_cc_dlvy_ship_method := delcurtemp.SHIP_METHOD_CODE;
2084                                 IF l_cc_upd_dlvy_intmed_ship_to = 'N' and l_cc_dlvy_intmed_ship_to IS NOT NULL THEN
2085                                    UPDATE wsh_new_deliveries
2086                                    SET    intmed_ship_to_location_id = NULL
2087                                    WHERE  delivery_id                = l_delivery_ids_tbl(i);
2088                                 END IF;
2089                                 --IF l_cc_upd_dlvy_ship_method = 'N' and l_cc_dlvy_ship_method IS NOT NULL THEN
2090                                 IF l_cc_upd_dlvy_ship_method = 'N' THEN
2091 
2092                                    --OTM R12, this update is FTE part of code, OTM flow will not go through here
2093 
2094                                    UPDATE wsh_new_deliveries
2095                                    SET    ship_method_code  = NULL,
2096                                           carrier_id        = NULL,
2097                                           mode_of_transport = NULL,
2098                                           service_level     = NULL
2099                                    WHERE  delivery_id       = l_delivery_ids_tbl(i);
2100                                 END IF;
2101                             END LOOP;
2102                         END LOOP;
2103                      END IF;
2104                   END IF;
2105                   -- set the intermediate ship to, ship method to null if group rec from constraint
2106                   -- validation has these as 'N'
2107 
2108                   IF l_cc_del_rows.COUNT=0 THEN
2109                      l_cc_del_rows := l_delivery_ids_tbl;
2110                   ELSE
2111                      l_cc_count_del_rows := l_cc_del_rows.COUNT;
2112                      IF l_delivery_ids_tbl.COUNT > 0 THEN
2113                         FOR i in l_delivery_ids_tbl.FIRST..l_delivery_ids_tbl.LAST LOOP
2114                             l_cc_del_rows(l_cc_count_del_rows+i) := l_delivery_ids_tbl(i);
2115                         END LOOP;
2116                      END IF;
2117                   END IF;
2118 
2119                   IF l_cc_grouping_rows.COUNT = 0 THEN
2120                      l_cc_grouping_rows := l_grouping_tbl;
2121                   ELSE
2122                      l_cc_count_grouping_rows := l_cc_grouping_rows.COUNT;
2123                      IF l_grouping_tbl.COUNT > 0 THEN
2124                         FOR i in l_grouping_tbl.FIRST..l_grouping_tbl.LAST LOOP
2125                             l_cc_grouping_rows(l_cc_count_grouping_rows+i) := l_grouping_tbl(i);
2126                         END LOOP;
2127                      END IF;
2128                   END IF;
2129 
2130                   IF (l_cc_return_status IS NOT NULL AND l_cc_return_status IN
2131                   (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
2132                       l_return_status := l_cc_return_status;
2133                   ELSIF (l_cc_return_status IS NOT NULL AND l_cc_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING
2134                   AND l_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
2135                       l_return_status := l_cc_return_status;
2136                   ELSE
2137                       l_cc_return_status := l_return_status;
2138                   END IF;
2139                END IF;
2140                --}
2141            --}
2142            END LOOP;
2143 
2144            l_delivery_ids_tbl := l_cc_del_rows;
2145            l_grouping_tbl     := l_cc_grouping_rows;
2146 
2147            IF l_debug_on THEN
2148               WSH_DEBUG_SV.log(l_module_name,'l_delivery_ids_tbl.COUNT after loop ',l_delivery_ids_tbl.COUNT);
2149               WSH_DEBUG_SV.log(l_module_name,'l_grouping_tbl.COUNT after loop',l_grouping_tbl.COUNT);
2150            END IF;
2151            IF l_cc_return_status IS NOT NULL THEN
2152               l_return_status := l_cc_return_status;
2153            END IF;
2154         --}
2155 
2156         ELSE -- validate_status is succese implies no failed lines so call autocreate_del directly
2157         --{
2158            -- deliveryMerge
2159            IF l_debug_on THEN
2160               WSH_DEBUG_SV.log(l_module_name,'det. tab count: '|| l_del_details_tbl.count);
2161               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_UTILITIES.Append_to_Deliveries' ,WSH_DEBUG_SV.C_PROC_LEVEL);
2162               WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2163            END IF;
2164            WSH_DELIVERY_DETAILS_UTILITIES.Append_to_Deliveries(
2165                          p_delivery_detail_tbl     => l_del_details_tbl,
2166                          p_append_flag             => p_append_flag,
2167                          p_group_by_header         => p_use_header_flag,
2168                          p_commit                  => FND_API.G_FALSE,
2169                          p_lock_rows               => FND_API.G_FALSE,
2170                          p_check_fte_compatibility => FND_API.G_FALSE,
2171                          x_appended_det_tbl        => l_appended_det_tbl,
2172                          x_unappended_det_tbl      => l_unappended_det_tbl,
2173                          x_appended_del_tbl        => l_appended_del_tbl,
2174                          x_return_status           => l_return_status);
2175            IF l_debug_on THEN
2176               WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2177               WSH_DEBUG_SV.log(l_module_name,'Return status from Append_to_Deliveries is',l_return_status );
2178            END IF;
2179            IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR
2180            OR l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
2181               x_return_status := l_return_status;
2182               WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_DELIVERY_DETAILS_UTILITIES.Append_to_Deliveries');
2183               IF l_debug_on THEN
2184                  WSH_DEBUG_SV.pop(l_module_name);
2185               END IF;
2186               RETURN;
2187            END IF;
2188 
2189            l_del_details_tbl.delete;
2190            l_del_details_tbl := l_unappended_det_tbl;
2191 
2192            IF l_debug_on THEN
2193               WSH_DEBUG_SV.log(l_module_name,'det. tab count: '|| l_del_details_tbl.count);
2194               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_AUTOCREATE.AUTOCREATE_DELIVERIES',WSH_DEBUG_SV.C_PROC_LEVEL);
2195               WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2196            END IF;
2197 
2198            IF  l_del_details_tbl.count > 0 THEN
2199            --{
2200               WSH_DELIVERY_AUTOCREATE.Autocreate_Deliveries (
2201                             p_line_rows         =>  l_del_details_tbl,
2202                             p_init_flag         =>  'N',  -- Should not refresh the PL/SQL tables
2203                             p_pick_release_flag =>  p_use_header_flag,
2204                             x_del_rows          =>  l_delivery_ids_tbl,
2205                             x_grouping_rows     =>  l_grouping_tbl,
2206                             x_return_status     =>  l_return_status
2207                              );
2208 
2209               IF l_debug_on THEN
2210                  WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2211                  WSH_DEBUG_SV.log(l_module_name,'WSH_DELIVERY_AUTOCREATE.Autocreate_Deliveries l_return_status',l_return_status);
2212               END IF;
2213 
2214               -- set the intermediate ship to, ship method to null if group rec from constraint
2215               -- validation has these as 'N'
2216               IF l_cc_group_info.COUNT > 0 THEN
2217               --{
2218                  l_cc_upd_dlvy_intmed_ship_to := 'Y';
2219                  l_cc_upd_dlvy_ship_method    := 'Y';
2220                  l_cc_upd_dlvy_intmed_ship_to := l_cc_group_info(1).upd_dlvy_intmed_ship_to;
2221                  l_cc_upd_dlvy_ship_method    := l_cc_group_info(1).upd_dlvy_ship_method;
2222 
2223                  IF l_debug_on THEN
2224                     WSH_DEBUG_SV.log(l_module_name,'l_cc_upd_dlvy_intmed_ship_to ',l_cc_upd_dlvy_intmed_ship_to);
2225                     WSH_DEBUG_SV.log(l_module_name,'l_cc_upd_dlvy_ship_method ',l_cc_upd_dlvy_ship_method);
2226                     WSH_DEBUG_SV.log(l_module_name,'l_delivery_ids_tbl.COUNT ',l_delivery_ids_tbl.COUNT);
2227                  END IF;
2228 
2229                  IF l_cc_upd_dlvy_intmed_ship_to = 'N' OR l_cc_upd_dlvy_ship_method = 'N' THEN
2230                     IF l_delivery_ids_tbl.COUNT > 0 THEN
2231                        FOR i in l_delivery_ids_tbl.FIRST..l_delivery_ids_tbl.LAST LOOP
2232                            FOR delcurtemp in del_cur(l_delivery_ids_tbl(i)) LOOP
2233                                l_cc_dlvy_intmed_ship_to := delcurtemp.INTMED_SHIP_TO_LOCATION_ID;
2234                                l_cc_dlvy_ship_method    := delcurtemp.SHIP_METHOD_CODE;
2235                                IF l_cc_upd_dlvy_intmed_ship_to = 'N' and l_cc_dlvy_intmed_ship_to IS NOT NULL THEN
2236                                   UPDATE wsh_new_deliveries
2237                                   SET    intmed_ship_to_location_id = NULL
2238                                   WHERE  delivery_id                = l_delivery_ids_tbl(i);
2239                                END IF;
2240                                --IF l_cc_upd_dlvy_ship_method = 'N' and l_cc_dlvy_ship_method IS NOT NULL THEN
2241                                IF l_cc_upd_dlvy_ship_method = 'N' THEN
2242 
2243                                   --OTM R12, this update is FTE part of code, OTM flow will not go through here
2244 
2245                                   UPDATE wsh_new_deliveries
2246                                   SET    ship_method_code  = NULL,
2247                                          carrier_id        = NULL,
2248                                          mode_of_transport = NULL,
2249                                          service_level     = NULL
2250                                   WHERE  delivery_id       = l_delivery_ids_tbl(i);
2251                                END IF;
2252                            END LOOP;
2253                        END LOOP;
2254                     END IF;
2255                  END IF;
2256               --}
2257               END IF;
2258 
2259            --}
2260            END IF;
2261 
2262         --}
2263         END IF;--line_groups is not null
2264 
2265      --}
2266      ELSE -- fte not installed
2267      --{
2268         -- deliveryMerge
2269         IF l_debug_on THEN
2270            WSH_DEBUG_SV.log(l_module_name,'det. tab count: '|| l_del_details_tbl.count);
2271            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_DETAILS_UTILITIES.Append_to_Deliveries' ,WSH_DEBUG_SV.C_PROC_LEVEL);
2272            WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2273         END IF;
2274 
2275         WSH_DELIVERY_DETAILS_UTILITIES.Append_to_Deliveries(
2276                       p_delivery_detail_tbl     => l_del_details_tbl,
2277                       p_append_flag             => p_append_flag,
2278                       p_group_by_header         => p_use_header_flag,
2279                       p_commit                  => FND_API.G_FALSE,
2280                       p_lock_rows               => FND_API.G_FALSE,
2281                       p_check_fte_compatibility => FND_API.G_FALSE,
2282                       x_appended_det_tbl        => l_appended_det_tbl,
2283                       x_unappended_det_tbl      => l_unappended_det_tbl,
2284                       x_appended_del_tbl        => l_appended_del_tbl,
2285                       x_return_status           => l_return_status);
2286 
2287         IF l_debug_on THEN
2288            WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2289            WSH_DEBUG_SV.log(l_module_name,'Return status from Append_to_Deliveries is: ',l_return_status );
2290         END IF;
2291 
2292         IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR OR
2293         l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
2294         --{
2295            x_return_status := l_return_status;
2296            WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_DELIVERY_DETAILS_UTILITIES.Append_to_Deliveries');
2297            IF l_debug_on THEN
2298               WSH_DEBUG_SV.pop(l_module_name);
2299            END IF;
2300            RETURN;
2301         --}
2302         END IF;
2303 
2304         l_del_details_tbl.delete;
2305         l_del_details_tbl := l_unappended_det_tbl;
2306 
2307         IF l_debug_on THEN
2308            WSH_DEBUG_SV.log(l_module_name,'det. tab count: '|| l_del_details_tbl.count);
2309            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_AUTOCREATE.AUTOCREATE_DELIVERIES',WSH_DEBUG_SV.C_PROC_LEVEL);
2310            WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2311         END IF;
2312 
2313         IF l_del_details_tbl.count > 0 THEN
2314         --{
2315            WSH_DELIVERY_AUTOCREATE.Autocreate_Deliveries (
2316                         p_line_rows         =>  l_del_details_tbl,
2317                         p_init_flag         =>  'N',  -- Should not refresh the PL/SQL tables
2318                         p_pick_release_flag =>  p_use_header_flag,
2319                         x_del_rows          =>  l_delivery_ids_tbl,
2320                         x_grouping_rows     =>  l_grouping_tbl,
2321                         x_return_status     =>  l_return_status
2322                          );
2323            IF l_debug_on THEN
2324               WSH_DEBUG_SV.log(l_module_name,'WSH_DELIVERY_AUTOCREATE.Autocreate_Deliveries l_return_status',l_return_status);
2325               WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2326            END IF;
2327 
2328            IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
2329            OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
2330                x_return_status := l_return_status;
2331                WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_DELIVERY_AUTOCREATE.Autocreate_Deliveries');
2332                IF l_debug_on THEN
2333                   WSH_DEBUG_SV.pop(l_module_name);
2334                END IF;
2335                RETURN;
2336            END IF;
2337         --}
2338         END IF;
2339      --}
2340      END IF;
2341 
2342   --}
2343   ELSE
2344      WSH_UTIL_CORE.printMsg('No eligible lines to autocreate deliveries');
2345   END IF;
2346 
2347   IF l_debug_on THEN
2348      WSH_DEBUG_SV.pop(l_module_name);
2349   END IF;
2350 
2351 EXCEPTION
2352   WHEN OTHERS THEN
2353        x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2354        IF l_debug_on THEN
2355           WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '
2356                                 || SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2357           WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
2358        END IF;
2359 
2360 END Autocreate_Deliveries;
2361 
2362 -- Start of comments
2363 -- API name : Release_Batch_Sub
2364 -- Type     : Public
2365 -- Pre-reqs : None.
2366 -- Procedure: This is core api to pick release a batch, api does
2367 --            1. Gets initializes batch criteria.
2368 --            2. Select details lines based on release criteria.
2369 --            3. Calls Inventory Move Order api for allocation and pick confirmation.
2370 --            4. Create/Appened deliveries, pack or ship confirmed based on release criteria.
2371 --            5. Print document sets.
2372 -- Parameters :
2373 -- IN:
2374 --      p_batch_id            IN  Batch Id.
2375 --      p_worker_id           IN  Worker Id.
2376 --      p_mode                IN  Mode.
2377 --      p_log_level           IN  Set the debug log level.
2378 -- OUT:
2379 --      errbuf       OUT NOCOPY  Error message.
2380 --      retcode      OUT NOCOPY  Error Code 1:Successs, 2:Warning and 3:Error.
2381 -- End of comments
2382 PROCEDURE Release_Batch_Sub(
2383       errbuf                            OUT NOCOPY      VARCHAR2,
2384       retcode                           OUT NOCOPY      VARCHAR2,
2385       p_batch_id                        IN      NUMBER,
2386       p_worker_id                       IN      NUMBER,
2387       p_mode                            IN      VARCHAR2,
2388       p_log_level                       IN      NUMBER  DEFAULT 0
2389    ) IS
2390 
2391   -- get distinct organization - move order header from worker table
2392   CURSOR  get_org_mo_hdr(c_batch_id IN NUMBER) IS
2393   SELECT  DISTINCT ORGANIZATION_ID, MO_HEADER_ID
2394   FROM    WSH_PR_WORKERS
2395   WHERE   BATCH_ID = c_batch_id
2396   AND     PROCESSED = 'N'
2397   ORDER BY ORGANIZATION_ID;
2398 
2399   -- get delivery information for auto ship and auto pack
2400   CURSOR  c_get_del IS
2401   SELECT  pa_sc_batch_id, delivery_id, organization_id, pickup_location_id, ap_level, sc_rule_id,ROWID -- Bug # 9369504 : added rowid
2402   FROM    wsh_pr_workers
2403   WHERE   batch_id = p_batch_id
2404   AND     type = 'PS'
2405   ORDER   BY 1,3,2;
2406 
2407   CURSOR get_sc_batch(c_batch_id IN NUMBER) IS
2408   SELECT ship_confirm_rule_id, creation_date
2409   FROM   wsh_picking_batches
2410   WHERE  batch_id = c_batch_id;
2411 
2412   --
2413   l_ship_confirm_rule_rec   WSH_BATCH_PROCESS.G_GET_SHIP_CONFIRM_RULE%ROWTYPE;
2414   l_ship_confirm_rule_id          NUMBER;
2415   l_batch_creation_date           DATE;
2416   l_del_details_tbl               WSH_UTIL_CORE.Id_Tab_Type;
2417   l_curr_count                    NUMBER;
2418   l_return_status                 VARCHAR2(1);
2419   l_completion_status             VARCHAR2(30);
2420   e_Return                        EXCEPTION;
2421   l_temp                          BOOLEAN;
2422   l_dummy                         VARCHAR2(1);
2423   l_rec_found                     BOOLEAN;
2424   l_msg_count                     NUMBER;
2425   l_msg_data                      VARCHAR2(2000);
2426   l_commit                        VARCHAR2(1) := FND_API.G_FALSE;
2427   l_request_id                    NUMBER;
2428   l_item_name                     VARCHAR2(2000);
2429   l_api_version_number            NUMBER := 1.0;
2430   l_message                       VARCHAR2(2000);
2431   l_message1                      VARCHAR2(2000);
2432   l_exception_return_status       VARCHAR2(30);
2433   l_exception_msg_count           NUMBER;
2434   l_exception_msg_data            VARCHAR2(4000) := NULL;
2435   l_dummy_exception_id            NUMBER;
2436   l_counter                       NUMBER := 0;
2437   l_total_detailed_count          NUMBER := 0;
2438   l_detail_count                  NUMBER := 0;
2439   l_del_pack_count                NUMBER := 0;
2440   l_del_sc_count                  NUMBER := 0;
2441   l_packed_results_success        NUMBER := 0;
2442   l_packed_results_warning        NUMBER := 0;
2443   l_packed_results_failure        NUMBER := 0;
2444   l_confirmed_results_success     NUMBER := 0;
2445   l_confirmed_results_warning     NUMBER := 0;
2446   l_confirmed_results_failure     NUMBER := 0;
2447   i                               NUMBER;
2448   j                               NUMBER;
2449   l_prev_detail_id                NUMBER;
2450   l_prev_sc_rule_id               NUMBER;
2451   --
2452   l_done_flag                     VARCHAR2(1);
2453   l_pick_release_stat             INV_PICK_RELEASE_PUB.INV_Release_Status_Tbl_Type;
2454   l_mmtt_tbl                      INV_MO_LINE_DETAIL_UTIL.G_MMTT_Tbl_Type;
2455   l_org_info                      WSH_PICK_LIST.Org_Params_Rec;
2456   l_tmp_rel_status                VARCHAR2(1);
2457   --
2458   l_auto_pick_confirm_num         NUMBER;
2459   l_plan_tasks                    BOOLEAN;
2460   l_skip_cartonization            BOOLEAN;
2461   l_pr_batch_size                 NUMBER;
2462   --
2463   l_continue_create_del VARCHAR2(1); -- bug # 8915460
2464   l_debug_on BOOLEAN;
2465   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'RELEASE_BATCH_SUB';
2466   --
2467 
2468 BEGIN
2469 
2470   SAVEPOINT s_Release_Batch_Sub_sf;
2471 
2472   -- If this is a worker, then it is a concurrent request
2473   IF p_worker_id IS NOT NULL THEN
2474      G_CONC_REQ := FND_API.G_TRUE;
2475   END IF;
2476 
2477   IF G_CONC_REQ = FND_API.G_TRUE AND p_worker_id IS NOT NULL THEN
2478      WSH_UTIL_CORE.Enable_Concurrent_Log_Print;
2479      IF p_log_level IS NOT NULL  THEN   -- log level fix
2480         WSH_UTIL_CORE.Set_Log_Level(p_log_level);
2481         WSH_UTIL_CORE.PrintMsg('p_log_level is ' || to_char(p_log_level));
2482      END IF;
2483   END IF;
2484 
2485   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
2486   IF l_debug_on IS NULL
2487   THEN
2488     l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
2489   END IF;
2490 
2491   l_completion_status := 'NORMAL';
2492 
2493   IF l_debug_on THEN
2494      WSH_DEBUG_SV.push(l_module_name);
2495      WSH_DEBUG_SV.log(l_module_name,'P_BATCH_ID',P_BATCH_ID);
2496      WSH_DEBUG_SV.log(l_module_name,'P_WORKER_ID',P_WORKER_ID);
2497      WSH_DEBUG_SV.log(l_module_name,'P_MODE',P_MODE);
2498      WSH_DEBUG_SV.log(l_module_name,'P_LOG_LEVEL',P_LOG_LEVEL);
2499   END IF;
2500 
2501   -- If worker_id is present, set Global variable as Parallel Pick Release and Parallel Pick Slips
2502   IF p_worker_id IS NOT NULL THEN
2503      WSH_PICK_LIST.G_PICK_REL_PARALLEL  := TRUE;
2504      IF l_debug_on THEN
2505         WSH_DEBUG_SV.logmsg(l_module_name,'Pick Release Mode is Parallel ');
2506      END IF;
2507   END IF;
2508 
2509   -- 10. For p_mode = 'PICK' / 'PICK-SS'
2510   --{
2511   IF p_mode IN ('PICK','PICK-SS') THEN
2512 
2513      IF p_worker_id IS NOT NULL THEN --{
2514         -- 10.10 Calling Init_Pick_Release API to initialize global variables in WSH_PR_CRITERIA package
2515         --       and also set Batch_Id and Seeded Pick Release Document Set
2516         IF l_debug_on THEN
2517               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit INIT_PICK_RELEASE',WSH_DEBUG_SV.C_PROC_LEVEL);
2518         END IF;
2519         Init_Pick_Release( p_batch_id      => p_batch_id,
2520                            p_worker_id     => p_worker_id,
2521                            x_return_status => l_return_status);
2522         IF l_debug_on THEN
2523            WSH_DEBUG_SV.log(l_module_name,'INIT_PICK_RELEASE l_return_status',l_return_status);
2524         END IF;
2525 
2526         IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR)
2527         OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
2528             WSH_UTIL_CORE.PrintMsg('Error occurred in Init_Pick_Release');
2529             RAISE e_return;
2530         END IF;
2531      END IF; --}
2532 
2533      -- Clear Demand Table
2534      g_demand_table.delete;
2535 
2536      WSH_PR_CRITERIA.g_credit_check_option := WSH_CUSTOM_PUB.Credit_Check_Details_Option;
2537 
2538      -- Determine Pick Release Batch Size based on Profile
2539      --Bug 5137504 Handling if Batch size is set to value less than 1 or is aphanumeric
2540      BEGIN
2541      l_pr_batch_size := TO_NUMBER(FND_PROFILE.VALUE('WSH_PICK_RELEASE_BATCH_SIZE'));
2542      IF l_pr_batch_size IS NULL OR l_pr_batch_size < 1 THEN
2543         l_pr_batch_size := 50;
2544      ELSIF l_pr_batch_size > 1000 THEN
2545         l_pr_batch_size := 1000;
2546      END IF;
2547      l_pr_batch_size := ROUND(l_pr_batch_size);
2548      EXCEPTION
2549      WHEN value_error THEN
2550      l_pr_batch_size :=50;
2551      WHEN INVALID_NUMBER THEN
2552      l_pr_batch_size :=50;
2553      END;
2554      -- MAX_LINES should never be less than 3 or else infinite loop will occur.
2555      IF l_pr_batch_size IS NOT NULL THEN
2556         WSH_PR_CRITERIA.MAX_LINES := l_pr_batch_size;
2557      END IF;
2558 
2559      -- MAX_LINES should never be less than 3 or greater than 1000
2560      IF WSH_PR_CRITERIA.MAX_LINES < 3 THEN
2561         WSH_PR_CRITERIA.MAX_LINES := 3;
2562      END IF;
2563 
2564      IF WSH_PR_CRITERIA.MAX_LINES > 1000 THEN
2565         WSH_PR_CRITERIA.MAX_LINES := 1000;
2566      END IF;
2567 
2568      IF l_debug_on THEN
2569         WSH_DEBUG_SV.logmsg(l_module_name,  'MAX_LINES IS ' || TO_CHAR(WSH_PR_CRITERIA.MAX_LINES));
2570      END IF;
2571 
2572      -- 10.20 Looping thru Organization-Move Order Header Combination
2573      FOR batch_rec IN get_org_mo_hdr(p_batch_id) LOOP
2574      --{
2575          IF l_debug_on THEN
2576             WSH_DEBUG_SV.logmsg(l_module_name,'**** Processing Organization '||BATCH_REC.ORGANIZATION_ID||
2577                                               ' Move Order Header Id '||BATCH_REC.MO_HEADER_ID||' ****');
2578          END IF;
2579 
2580          -- 10.20.10 Clear the Global PL/SQL Tables for printers.
2581          WSH_INV_INTEGRATION_GRP.G_PRINTERTAB.delete ;
2582          WSH_INV_INTEGRATION_GRP.G_ORGTAB.delete ;
2583          WSH_INV_INTEGRATION_GRP.G_ORGSUBTAB.delete ;
2584 
2585          -- Set count for release rows to 0
2586          l_curr_count           := 0;
2587          l_done_flag            := FND_API.G_FALSE;
2588          l_total_detailed_count := 0;
2589 
2590          -- Reset the Non-Reservable Item Flag as 'N'
2591          WSH_PR_CRITERIA.g_nonreservable_item := 'N';
2592 
2593          -- 10.20.20 Getting Organization Parameters
2594          --{
2595          IF l_debug_on THEN
2596             WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit GET_ORG_PARAMS',WSH_DEBUG_SV.C_PROC_LEVEL);
2597          END IF;
2598          Get_Org_Params( p_organization_id => batch_rec.organization_id,
2599                          x_org_info        => l_org_info,
2600                          x_return_status   => l_return_status);
2601          IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
2602              WSH_UTIL_CORE.PrintMsg('Error occurred in Get_Org_Params');
2603              RAISE e_return;
2604          END IF;
2605          --}
2606 
2607          -- 10.20.30 Initialize the cursor to fetch Worker Records
2608          --{
2609          IF l_debug_on THEN
2610             WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PR_CRITERIA.GET_WORKER_RECORDS',WSH_DEBUG_SV.C_PROC_LEVEL);
2611          END IF;
2612          WSH_PR_CRITERIA.Get_Worker_Records (
2613                                               p_mode              => p_mode,
2614                                               p_batch_id          => p_batch_id,
2615                                               p_organization_id   => batch_rec.organization_id,
2616                                               x_api_status        => l_return_status );
2617          IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
2618              WSH_UTIL_CORE.PrintMsg('Error occurred in Get_Worker_Records');
2619              RAISE e_return;
2620          END IF;
2621          --}
2622          l_continue_create_del := 'Y'; -- bug # 8915460 :
2623          -- 10.20.40 Get all lines for Organization-Item Combination and process them
2624          WHILE (l_done_flag = FND_API.G_FALSE) LOOP
2625          --{
2626             -- 10.20.40.10 Select a number of order lines at a time
2627             --{
2628             IF l_debug_on THEN
2629                WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PR_CRITERIA.Get_Lines',WSH_DEBUG_SV.C_PROC_LEVEL);
2630                WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2631             END IF;
2632             WSH_PR_CRITERIA.Get_Lines(
2633                                        p_enforce_ship_set_and_smc => l_org_info.enforce_ship_set_and_smc,
2634                                        p_wms_flag                 => l_org_info.wms_org,
2635                                        p_express_pick_flag        => l_org_info.express_pick_flag,
2636                                        p_batch_id                 => p_batch_id,
2637                                        x_done_flag                => l_done_flag,
2638                                        x_api_status               => l_return_status );
2639             IF l_debug_on THEN
2640               WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2641               WSH_DEBUG_SV.log(l_module_name,'WSH_PR_CRITERIA.Get_Lines l_return_status',l_return_status);
2642             END IF;
2643             IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
2644             OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
2645                WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_PR_CRITERIA.Get_Lines');
2646                RAISE e_return;
2647             ELSIF (l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING) THEN
2648                G_ONLINE_PICK_RELEASE_SKIP := 'Y';
2649                l_completion_status := 'WARNING';
2650                IF l_debug_on THEN
2651                   WSH_DEBUG_SV.log(l_Module_name, 'WSH_PR_CRITERIA.Get_Lines returned with warning');
2652                END IF;
2653             END IF;
2654             --}
2655 
2656             -- If there are no more lines to be processed, then go for Next Org-Move Order Combo
2657             IF WSH_PR_CRITERIA.release_table.count = 0 THEN
2658                GOTO NEXT_ORG_MO_WORKER;
2659             END IF;
2660 
2661             -- Savepoint to rollback for any error during pick release API
2662             SAVEPOINT BEF_MOVE_ORDER_LINE_CREATE;
2663 
2664             IF l_debug_on THEN
2665                WSH_DEBUG_SV.log(l_module_name, 'l_curr_count',L_CURR_COUNT);
2666             END IF;
2667 
2668             -- 10.20.40.20 Calling Move Order Line API
2669             --{
2670             IF l_debug_on THEN
2671                WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PICK_LIST.Create_Move_Order_Lines'
2672                                                  ,WSH_DEBUG_SV.C_PROC_LEVEL);
2673                WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2674             END IF;
2675             Create_Move_Order_Lines (
2676                                       p_batch_id                     => p_batch_id,
2677                                       p_worker_id                    => p_worker_id,
2678                                       p_organization_id              => batch_rec.organization_id,
2679                                       p_mo_header_id                 => batch_rec.mo_header_id,
2680                                       p_wms_flag                     => l_org_info.wms_org,
2681                                       p_auto_pick_confirm            => l_org_info.auto_pick_confirm,
2682                                       p_express_pick_flag            => l_org_info.express_pick_flag,
2683                                       p_pick_slip_grouping_rule      => l_org_info.pick_grouping_rule_id,
2684                                       p_to_subinventory              => l_org_info.to_subinventory,
2685                                       p_to_locator                   => l_org_info.to_locator,
2686 				      p_use_header_flag              => l_org_info.use_header_flag, -- bug 8623544
2687                                       x_curr_count                   => l_curr_count,
2688                                       x_return_status                => l_return_status
2689                                     );
2690             IF l_debug_on THEN
2691               WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2692               WSH_DEBUG_SV.log(l_module_name,'WSH_PICK_LIST.Create_Move_Order_Lines l_return_status' ,l_return_status);
2693             END IF;
2694             IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
2695             OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
2696                WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_PICK_LIST.Create_Move_Order_Lines');
2697                RAISE e_return;
2698             ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2699                IF l_completion_status = 'NORMAL' THEN
2700                  l_completion_status := 'WARNING';
2701                END IF;
2702                IF l_debug_on THEN
2703                  WSH_DEBUG_SV.log(l_Module_name, 'Create_Move_Order_Lines returned with warning');
2704                END IF;
2705             END IF;
2706             --}
2707 
2708             -- Autocreate Deliveries is done, if any of following conditions are met:
2709             -- 1) If it is worker, then check if Pick Slip Printing Mode is Immediate
2710             --    or Delivery is part of Pick Slip Grouping Rule
2711             -- 2) If it is not worker and parameter p_num_workers in Release_Batch API > 1
2712             --    and if Pick Slip Printing Mode is Immediate or Delivery is part of Pick Slip Grouping Rule
2713             -- 3) If it is not worker and parameter p_num_workers in Release_Batch API = 1
2714             --{
2715             IF (p_worker_id IS NOT NULL AND (WSH_PR_CRITERIA.g_use_delivery_ps = 'Y' OR l_org_info.print_pick_slip_mode = 'I')) OR
2716                (p_worker_id IS NULL AND WSH_PICK_LIST.G_NUM_WORKERS > 1 AND (WSH_PR_CRITERIA.g_use_delivery_ps = 'Y'
2717                                                                           OR l_org_info.print_pick_slip_mode = 'I')) OR
2718                (p_worker_id IS NULL AND WSH_PICK_LIST.G_NUM_WORKERS = 1) THEN
2719                -- bug # 8915460 : Added l_continue_create_del
2720                IF ((l_org_info.autocreate_deliveries = 'Y') AND (WSH_PR_CRITERIA.g_trip_id = 0)
2721                AND (WSH_PR_CRITERIA.g_delivery_id = 0) AND (WSH_PR_CRITERIA.release_table.count > 0)
2722                AND l_continue_create_del = 'Y' )THEN
2723                --{
2724                   IF l_debug_on THEN
2725                      WSH_DEBUG_SV.logmsg(l_module_name,  '==================='  );
2726                      WSH_DEBUG_SV.logmsg(l_module_name,  'AUTOCREATE DELIVERY'  );
2727                      WSH_DEBUG_SV.logmsg(l_module_name,  '==================='  );
2728                   END IF;
2729                   -- Clear delivery detail IDs from table
2730                   l_del_details_tbl.delete;
2731                   -- Populate table with delivery detail IDs
2732                   l_detail_count := 1;
2733                   IF l_org_info.express_pick_flag = 'N' THEN
2734                   --{
2735                      i := g_del_detail_ids.FIRST;
2736                      -- Populate all Transactable Lines which are not assigned to a Delivery
2737                      WHILE i is NOT NULL LOOP
2738                            IF g_trolin_delivery_ids(i) IS NULL THEN
2739                               l_del_details_tbl(l_detail_count) := g_del_detail_ids(i);
2740                               l_detail_count := l_detail_count + 1;
2741                            END IF;
2742                            i := g_del_detail_ids.NEXT(i);
2743                      END LOOP;
2744                      -- Populate all Non Transactable Lines which are not assigned to a Delivery
2745                      FOR i IN 1..WSH_PR_CRITERIA.release_table.count LOOP
2746                          IF WSH_PR_CRITERIA.release_table(i).released_status = 'X' AND
2747                             WSH_PR_CRITERIA.release_table(i).delivery_id IS NULL THEN
2748                             l_del_details_tbl(l_detail_count) := WSH_PR_CRITERIA.release_table(i).delivery_detail_id;
2749                             l_detail_count := l_detail_count + 1;
2750                          END IF;
2751                      END LOOP;
2752                      -- Populate all X-dock Lines which are not assigned to a Delivery
2753                      i := g_xdock_detail_ids.FIRST;
2754                      WHILE i is NOT NULL LOOP
2755                            IF g_xdock_delivery_ids(i) IS NULL THEN
2756                               l_del_details_tbl(l_detail_count) := g_xdock_detail_ids(i);
2757                               l_detail_count := l_detail_count + 1;
2758                            END IF;
2759                            i := g_xdock_detail_ids.NEXT(i);
2760                      END LOOP;
2761 
2762                   --}
2763                   ELSE -- l_express_pick_flag =
2764                   --{
2765                      l_detail_count := 1;
2766                      l_prev_detail_id := NULL;
2767                      FOR i in g_exp_pick_release_stat.FIRST..g_exp_pick_release_stat.LAST LOOP
2768                          IF NVL(l_prev_detail_id,-99) <> g_exp_pick_release_stat(i).delivery_detail_id THEN
2769                             IF l_prev_detail_id is null THEN
2770                                j := g_del_detail_ids.FIRST;
2771                             ELSE
2772                                j := g_del_detail_ids.NEXT(j);
2773                             END IF;
2774                          END IF;
2775                          IF l_debug_on THEN
2776                             WSH_DEBUG_SV.logmsg(l_module_name,i||' Exp Org DD= '
2777                                          ||g_exp_pick_release_stat(i).delivery_detail_id|| ' j= '||j
2778                                          ||' Org DD '||g_del_detail_ids(j)||' Trolin Del '||g_trolin_delivery_ids(j));
2779                          END IF;
2780                          IF (g_exp_pick_release_stat(i).delivery_detail_id = g_del_detail_ids(j)
2781                          AND g_trolin_delivery_ids(j) is NULL) THEN
2782                              IF g_exp_pick_release_stat(i).pick_status in ('S') THEN
2783                                 IF g_exp_pick_release_stat(i).split_delivery_id IS NOT NULL THEN
2784                                    l_del_details_tbl(l_detail_count) := g_exp_pick_release_stat(i).split_delivery_id;
2785                                    l_detail_count := l_detail_count + 1;
2786                                 ELSE
2787                                    l_del_details_tbl(l_detail_count) := g_exp_pick_release_stat(i).delivery_detail_id;
2788                                    l_detail_count := l_detail_count + 1;
2789                                 END IF;
2790                              END IF;
2791                          END IF;
2792 
2793                          l_prev_detail_id := g_exp_pick_release_stat(i).delivery_detail_id;
2794                      END LOOP;
2795                   --}
2796                   END IF;
2797                   IF l_debug_on THEN
2798                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PICK_LIST.Autocreate_Deliveries'
2799                                                  ,WSH_DEBUG_SV.C_PROC_LEVEL);
2800                      WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2801                   END IF;
2802                   Autocreate_Deliveries (
2803                                           p_append_flag         => l_org_info.append_flag,
2804                                           p_use_header_flag     => l_org_info.use_header_flag,
2805                                           p_del_details_tbl     => l_del_details_tbl,
2806                                           x_return_status       => l_return_status
2807                                         );
2808                   IF l_debug_on THEN
2809                      WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2810                      WSH_DEBUG_SV.log(l_module_name,'WSH_PICK_LIST.Autocreate_Deliveries l_return_status'
2811                                                 ,l_return_status);
2812                   END IF;
2813                   IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
2814                   OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
2815                      WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_PICK_LIST.Autocreate_Deliveries');
2816                      RAISE e_return;
2817                   END IF;
2818                   -- bug # 8915460 : When pick release is performed by specifying deliery detail id/containerDDId
2819                   --                then auto create delivery can be performed only once because
2820                   --                 i) all details are assigned to same container(incase of containerDD as a parameter).
2821                   --                 ii) Single delivery detail id incase deliveydetailid as a parameter
2822                   IF ( l_del_details_tbl.COUNT > 0 AND NVL(WSH_PR_CRITERIA.g_del_detail_id,0) = -2 ) THEN
2823                   --{
2824                     l_continue_create_del := 'N';
2825                   --}
2826                   END IF;
2827                END IF;
2828                --}
2829             END IF;
2830             --}
2831 
2832             -- Call FTE Load Tender and Issue Commit for Concurrent Express Pick Release
2833             IF l_org_info.express_pick_flag = 'Y' AND ( G_CONC_REQ = FND_API.G_TRUE ) THEN --{
2834 		    IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
2835 		       IF l_debug_on THEN
2836 			     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Process_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
2837 		       END IF;
2838 		       WSH_UTIL_CORE.Process_stops_for_load_tender (
2839                                                                      p_reset_flags   => FALSE,
2840 							             x_return_status => l_return_status );
2841 		       IF l_debug_on THEN
2842 		    	    WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
2843 		       END IF;
2844                        IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR)
2845                        OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
2846                            WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_UTIL_CORE.Process_stops_for_load_tender');
2847                            RAISE e_return;
2848                        ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2849                            IF l_completion_status = 'NORMAL' THEN
2850                               l_completion_status := 'WARNING';
2851                            END IF;
2852                        END IF;
2853 	            END IF;
2854                     IF l_debug_on THEN
2855                        WSH_DEBUG_SV.logmsg(l_module_name,  'Commiting...');
2856                     END IF;
2857                     COMMIT;
2858             END IF; --}
2859 
2860             -- Autodetailing Logic
2861             -- X-dock, no need to add filter for allocation_method in I,X,N only
2862             -- as g_trolin_tbl is populated only for these allocation methods
2863             IF l_org_info.express_pick_flag = 'N' AND (l_org_info.autodetail_flag =  'Y')
2864             AND (g_trolin_tbl.count > 0) THEN
2865             --{
2866                   IF l_org_info.auto_pick_confirm = 'Y' THEN
2867                      l_auto_pick_confirm_num := 1;
2868                   ELSE
2869                      l_auto_pick_confirm_num := 2;
2870                   END IF;
2871                   IF l_org_info.task_planning_flag = 'Y' THEN
2872                      l_plan_tasks := TRUE;
2873                      l_auto_pick_confirm_num := 2;
2874                      l_org_info.auto_pick_confirm := 'N';
2875                   ELSE
2876                      l_plan_tasks := FALSE;
2877                   END IF;
2878 
2879                   -- If Parallel process, then Cartonization is done in Parent Process
2880                   -- Else done here
2881                   IF WSH_PICK_LIST.G_PICK_REL_PARALLEL THEN
2882                      l_skip_cartonization := TRUE;
2883                      l_plan_tasks         := TRUE;
2884                   ELSE
2885                      l_skip_cartonization := FALSE;
2886                   END IF;
2887 
2888                   IF l_debug_on THEN
2889                      WSH_DEBUG_SV.logmsg(l_module_name,  '=========='  );
2890                      WSH_DEBUG_SV.logmsg(l_module_name,  'AUTODETAIL'  );
2891                      WSH_DEBUG_SV.logmsg(l_module_name,  '=========='  );
2892                      WSH_DEBUG_SV.logmsg(l_module_name, 'G_TROLIN_TBL.COUNT '||G_TROLIN_TBL.COUNT
2893                                                    ||'  G_ALLOCATION_METHOD :'||G_ALLOCATION_METHOD);
2894                      WSH_DEBUG_SV.log(l_module_name, 'l_auto_pick_confirm_num',l_auto_pick_confirm_num);
2895                      IF l_plan_tasks THEN
2896                         WSH_DEBUG_SV.logmsg(l_module_name, 'l_plan_tasks is TRUE');
2897                      ELSE
2898                         WSH_DEBUG_SV.logmsg(l_module_name, 'l_plan_tasks is FALSE');
2899                      END IF;
2900                      IF l_skip_cartonization THEN
2901                         WSH_DEBUG_SV.logmsg(l_module_name, 'l_skip_cartonization is TRUE');
2902                      ELSE
2903                         WSH_DEBUG_SV.logmsg(l_module_name, 'l_skip_cartonization is FALSE');
2904                      END IF;
2905                      WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2906                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit INV_PICK_RELEASE_PUB.PICK_RELEASE',
2907                                          WSH_DEBUG_SV.C_PROC_LEVEL);
2908                   END IF;
2909                   -- X-dock
2910                   -- add parameters for X-dock
2911                   -- P_DEL_DETAIL_ID (g_xdock_detail_ids) :contains the list of delivery
2912                   --     details which have been  successfully planned for X-dock
2913                   -- P_TROLIN_DELIVERY_IDS (g_xdock_delivery_ids) : Matches index with
2914                   --     p_del_detail_id and stores delivery ids for the delivery
2915                   --     details(derived from release_table)
2916                   -- P_WSH_RELEASE_TABLE(wsh_pr_criteria.release_table) : IN/OUT variable,
2917                   --     in case of splitting of delivery details  new records will be added
2918                   --     to p_wsh_release_table
2919                   --bug# 6689448 (replenishment project): added the parameter P_dynamic_replenishment_flag
2920                   INV_Pick_Release_Pub.Pick_Release
2921                     (p_api_version         => l_api_version_number,
2922                      p_init_msg_list       => fnd_api.g_true,
2923                      p_commit              => l_commit,
2924                      p_mo_line_tbl         => g_trolin_tbl,
2925                      p_auto_pick_confirm   => l_auto_pick_confirm_num,
2926                      p_plan_tasks          => l_plan_tasks,
2927                      p_dynamic_replenishment => l_org_info.dynamic_replenishment_flag,
2928                      p_grouping_rule_id    => l_org_info.pick_grouping_rule_id,
2929                      p_skip_cartonization  => l_skip_cartonization,
2930                      p_wsh_release_table   => wsh_pr_criteria.release_table,
2931                      p_trolin_delivery_ids => g_xdock_delivery_ids,
2932                      p_del_detail_id       => g_xdock_detail_ids,
2933                      x_pick_release_status => l_pick_release_stat,
2934                      x_return_status       => l_return_status,
2935                      x_msg_count           => l_msg_count,
2936                      x_msg_data            => l_msg_data);
2937 
2938                   IF l_debug_on THEN
2939                      WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
2940                      WSH_DEBUG_SV.log(l_module_name,'INV_Pick_Release_Pub.Pick_Release l_return_status',
2941                                       l_return_status);
2942                   END IF;
2943                   IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
2944                   OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
2945                   --{
2946                      WSH_UTIL_CORE.PrintMsg('Error occurred in Inv_Pick_Release_Pub.Pick_Release');
2947                      FOR i in 1..l_msg_count LOOP
2948                          l_message := fnd_msg_pub.get(i,'F');
2949                          l_message := replace(l_message,chr(0),' ');
2950                          WSH_UTIL_CORE.PrintMsg(l_message);
2951                          IF (i = 1) THEN
2952                             l_message1 := l_message;
2953                          END IF;
2954                      END LOOP;
2955                      l_completion_status := 'WARNING';
2956                      fnd_msg_pub.delete_msg();
2957                      IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
2958                         WSH_UTIL_CORE.PrintMsg('Unexpected error from INV_Pick_Release_Pub.Pick_Release. Exiting');
2959                         RAISE e_return;
2960                      ELSE
2961                      --{
2962                         ROLLBACK TO BEF_MOVE_ORDER_LINE_CREATE;
2963                         WSH_UTIL_CORE.PrintMsg('Auto Detailing Returned Expected Error');
2964                         l_request_id := fnd_global.conc_request_id;
2965                         IF (l_request_id <> -1 OR G_BATCH_ID IS NOT NULL ) THEN
2966                         --{
2967                            FOR i in 1 .. WSH_PR_CRITERIA.release_table.count
2968                            LOOP
2969                               IF l_debug_on THEN
2970                                  WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.GET_ITEM_NAME',WSH_DEBUG_SV.C_PROC_LEVEL);
2971                               END IF;
2972                               l_item_name := WSH_UTIL_CORE.Get_Item_Name(
2973                                                     WSH_PR_CRITERIA.release_table(i).inventory_item_id,
2974                                                     WSH_PR_CRITERIA.release_table(i).organization_id);
2975                               FND_MESSAGE.SET_NAME('WSH','WSH_INV_EXPECTED_ERROR');
2976                               FND_MESSAGE.SET_TOKEN('ITEM',l_item_name);
2977                               FND_MESSAGE.SET_TOKEN('ORDER',WSH_PR_CRITERIA.release_table(i).source_header_number);
2978                               FND_MESSAGE.SET_TOKEN('INVMESSAGE',l_message1);
2979                               l_message := FND_MESSAGE.GET;
2980                               l_exception_return_status := NULL;
2981                               l_exception_msg_count := NULL;
2982                               l_exception_msg_data := NULL;
2983                               l_dummy_exception_id := NULL;
2984                               IF l_debug_on THEN
2985                                  WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_XC_UTIL.LOG_EXCEPTION'
2986                                                          ,WSH_DEBUG_SV.C_PROC_LEVEL);
2987                               END IF;
2988                               wsh_xc_util.log_exception(
2989                                   p_api_version   => 1.0,
2990                                   p_logging_entity  => 'SHIPPER',
2991                                   p_logging_entity_id => FND_GLOBAL.USER_ID,
2992                                   p_exception_name  => 'WSH_INV_EXPECTED_ERROR',
2993                                   p_message   => l_message,
2994                                   p_inventory_item_id => WSH_PR_CRITERIA.release_table(i).inventory_item_id,
2995                                   p_logged_at_location_id   => WSH_PR_CRITERIA.release_table(i).ship_from_location_id,
2996                                   p_exception_location_id   => WSH_PR_CRITERIA.release_table(i).ship_from_location_id,
2997                                   p_request_id  => l_request_id,
2998                                   p_batch_id  => WSH_PICK_LIST.g_batch_id,
2999                                   x_return_status   => l_exception_return_status,
3000                                   x_msg_count   => l_exception_msg_count,
3001                                   x_msg_data  => l_exception_msg_data,
3002                                   x_exception_id  => l_dummy_exception_id);
3003                               IF l_debug_on THEN
3004                                  WSH_DEBUG_SV.logmsg(l_module_name,  'LOGGED EXCEPTION '||L_DUMMY_EXCEPTION_ID  );
3005                               END IF;
3006                            END LOOP;
3007                         --}
3008                         END IF;
3009                      --}
3010                      END IF;
3011                   --}
3012                   END IF;
3013             --}
3014             -- For Auto Detail = No, set the Detailed Count to 1 always
3015             -- This is required so that we know that atleast 1 record was picked
3016             ELSIF l_org_info.express_pick_flag = 'N' AND (l_org_info.autodetail_flag =  'N')
3017             AND (g_trolin_tbl.count > 0) THEN
3018 
3019                  l_total_detailed_count := 1;
3020             END IF;
3021 
3022 
3023             -- Printing Pick Slips in Immediate Mode
3024             IF l_org_info.express_pick_flag = 'N' AND (l_org_info.autodetail_flag =  'Y')
3025             AND (g_trolin_tbl.count > 0) THEN
3026             --{
3027                   IF ( G_CONC_REQ = FND_API.G_TRUE ) THEN
3028                   --{
3029                      IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
3030                         IF l_debug_on THEN
3031                            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Process_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
3032                         END IF;
3033                         WSH_UTIL_CORE.Process_stops_for_load_tender(
3034                                                                      p_reset_flags   => FALSE,
3035 				                                     x_return_status => l_tmp_rel_status );
3036                         IF l_debug_on THEN
3037                            WSH_DEBUG_SV.log(l_module_name,'l_tmp_rel_status',l_tmp_rel_status);
3038                         END IF;
3039                         IF (l_tmp_rel_status = WSH_UTIL_CORE.G_RET_STS_ERROR)
3040                         OR (l_tmp_rel_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
3041                             WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_UTIL_CORE.Process_stops_for_load_tender');
3042                             RAISE e_return;
3043                         ELSIF l_tmp_rel_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
3044                             IF l_completion_status = 'NORMAL' THEN
3045                                l_completion_status := 'WARNING';
3046                             END IF;
3047                         END IF;
3048                      END IF;
3049                   --}
3050                   END IF;
3051 
3052                   IF ((l_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS)
3053                   OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR)) THEN
3054                   --{
3055                      FOR i in 1..l_pick_release_stat.count LOOP
3056                          IF l_debug_on THEN
3057                             WSH_DEBUG_SV.logmsg(l_module_name,
3058                                'MOVE ORDER LINE ID: '
3059                                || L_PICK_RELEASE_STAT(I).MO_LINE_ID
3060                                || ' RELEASE STATUS: '
3061                                || L_PICK_RELEASE_STAT(I).RETURN_STATUS
3062                                || ' DETAIL REC COUNT: '
3063                                || L_PICK_RELEASE_STAT(I).DETAIL_REC_COUNT  );
3064                          END IF;
3065                          IF l_pick_release_stat(i).detail_rec_count = 0 THEN
3066                             l_counter := g_trolin_tbl.FIRST ;
3067                             WHILE l_counter is NOT NULL LOOP
3068                                IF (g_trolin_tbl(l_counter).line_id = l_pick_release_stat(i).mo_line_id) THEN
3069                                   IF l_debug_on THEN
3070                                      WSH_DEBUG_SV.logmsg(l_module_name,  'REMOVING MOVE ORDER LINE '
3071                                                          ||L_PICK_RELEASE_STAT(I).MO_LINE_ID  );
3072                                   END IF;
3073                                   g_trolin_tbl.DELETE(l_counter);
3074                                END IF;
3075                                l_counter := g_trolin_tbl.NEXT(l_counter);
3076                             END LOOP;
3077                             l_pick_release_stat.DELETE(i);
3078                          END IF;
3079                      END LOOP;
3080                   --}
3081                   END IF;
3082                   IF ( G_CONC_REQ = FND_API.G_TRUE ) THEN
3083                        IF l_debug_on THEN
3084                           WSH_DEBUG_SV.logmsg(l_module_name,  'Commiting...');
3085                        END IF;
3086                        COMMIT;
3087                   END IF;
3088 
3089                   -- If Pick Slip Print Mode is Immediate for Non-WMS Orgs
3090                   -- OR Pick Slip Print Mode is Immediate and Cartonization is done before Allocation for WMS Orgs
3091                   IF (l_org_info.print_pick_slip_mode = 'I') AND (l_org_info.wms_org = 'N' OR
3092                   (l_org_info.wms_org = 'Y' AND p_worker_id IS NULL AND WSH_PICK_LIST.G_NUM_WORKERS = 1)) THEN
3093                   --{
3094                      IF (WSH_PR_PICK_SLIP_NUMBER.g_print_ps_table.COUNT > 0) THEN
3095                      --{
3096                         IF l_debug_on THEN
3097                              WSH_DEBUG_SV.logmsg(l_module_name,  'PRINTING PICK SLIPS IN IMMEDIATE MODE...'  );
3098                         END IF;
3099                         FOR i in WSH_PR_PICK_SLIP_NUMBER.g_print_ps_table.FIRST ..
3100                                                      WSH_PR_PICK_SLIP_NUMBER.g_print_ps_table.LAST
3101                         LOOP
3102                           IF l_debug_on THEN
3103                              WSH_DEBUG_SV.logmsg(l_module_name,  ' === PRINTING PICK SLIP '
3104                                                  ||WSH_PR_PICK_SLIP_NUMBER.G_PRINT_PS_TABLE ( I ) ||' ==='  );
3105                              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PR_PICK_SLIP_NUMBER.PRINT_PICK_SLIP',WSH_DEBUG_SV.C_PROC_LEVEL);
3106                           END IF;
3107                           WSH_PR_PICK_SLIP_NUMBER.Print_Pick_Slip(
3108                              p_pick_slip_number => WSH_PR_PICK_SLIP_NUMBER.g_print_ps_table(i),
3109                              p_report_set_id    => WSH_PICK_LIST.G_SEED_DOC_SET,
3110                              p_organization_id  => batch_rec.organization_id,
3111                              p_ps_mode          => 'I',
3112                              x_api_status       => l_return_status,
3113                              x_error_message    => l_message );
3114                           IF l_debug_on THEN
3115                              WSH_DEBUG_SV.log(l_module_name,'WSH_PR_PICK_SLIP_NUMBER.Print_Pick_Slip l_return_status'
3116                                                            ,l_return_status);
3117                              WSH_DEBUG_SV.log(l_module_name,'WSH_PR_PICK_SLIP_NUMBER.Print_Pick_Slip l_message'
3118                                                            ,l_message);
3119                           END IF;
3120                           IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
3121                           OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
3122                               WSH_UTIL_CORE.PrintMsg('** Warning: Cannot Print Pick Slip **');
3123                               WSH_UTIL_CORE.PrintMsg(l_message);
3124                               l_completion_status := 'WARNING';
3125                           END IF;
3126                         END LOOP;
3127                      --}
3128                      ELSE
3129                         IF l_debug_on THEN
3130                            WSH_DEBUG_SV.logmsg(l_module_name,  'NO PICK SLIPS TO PRINT'  );
3131                         END IF;
3132                      END IF;
3133                      WSH_PR_PICK_SLIP_NUMBER.g_print_ps_table.DELETE;
3134                   --}
3135                   END IF;
3136 
3137                   l_total_detailed_count := l_total_detailed_count + l_pick_release_stat.count ;
3138             --}
3139             ELSIF l_org_info.express_pick_flag = 'N' AND (l_org_info.autodetail_flag =  'N') THEN
3140                   -- Need to add this commit for scenarios where Auto Allocate is No and, if number of lines is
3141                   -- greater than Pick Release Batch size
3142 	          IF ( G_CONC_REQ = FND_API.G_TRUE ) THEN
3143                      IF l_debug_on THEN
3144                         WSH_DEBUG_SV.logmsg(l_module_name,  'Commiting...');
3145                      END IF;
3146 	             COMMIT;
3147 	          END IF;
3148             END IF;
3149 
3150             fnd_msg_pub.delete_msg(); -- Clear Msg Buffer
3151 
3152             -- Auto Pick Confirm
3153             IF l_org_info.express_pick_flag = 'N' AND l_org_info.auto_pick_confirm = 'Y'
3154             AND l_pick_release_stat.count > 0 THEN
3155             --{
3156                WSH_PICK_LIST.G_AUTO_PICK_CONFIRM := 'Y';
3157                --{
3158                IF l_debug_on THEN
3159                   WSH_DEBUG_SV.logmsg(l_module_name,  '================='  );
3160                   WSH_DEBUG_SV.logmsg(l_module_name,  'AUTO PICK CONFIRM'  );
3161                   WSH_DEBUG_SV.logmsg(l_module_name,  '================='  );
3162                   WSH_DEBUG_SV.logmsg(l_module_name, 'G_TROLIN_TBL.COUNT '||G_TROLIN_TBL.COUNT
3163                                                    ||'  G_ALLOCATION_METHOD :'||G_ALLOCATION_METHOD);
3164                   WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
3165                   WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit INV_PICK_WAVE_PICK_CONFIRM_PUB.PICK_CONFIRM',WSH_DEBUG_SV.C_PROC_LEVEL);
3166                END IF;
3167                INV_Pick_Wave_Pick_Confirm_PUB.Pick_Confirm
3168                  (p_api_version_number => l_api_version_number,
3169                   p_init_msg_list      => FND_API.G_TRUE,
3170                   p_commit             => l_commit,
3171                   p_move_order_type    => INV_GLOBALS.G_MOVE_ORDER_PICK_WAVE,
3172                   p_transaction_mode   => 1,
3173                   p_trolin_tbl         => g_trolin_tbl,
3174                   p_mold_tbl           => l_mmtt_tbl,
3175                   x_mmtt_tbl           => l_mmtt_tbl,
3176                   x_trolin_tbl         => g_trolin_tbl,
3177                   x_return_status      => l_return_status,
3178                   x_msg_count          => l_msg_count,
3179                   x_msg_data           => l_msg_data
3180                  );
3181                IF l_debug_on THEN
3182                   WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
3183                   WSH_DEBUG_SV.log(l_module_name,'INV_Pick_Wave_Pick_Confirm_PUB.Pick_Confirm l_return_status',l_return_status);
3184                END IF;
3185                --}
3186                IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
3187                OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
3188                --{
3189                   WSH_UTIL_CORE.PrintMsg('Error occurred in INV_Pick_Wave_Pick_Confirm_PUB.Pick_Confirm');
3190                   FOR i in 1..l_msg_count LOOP
3191                       l_message := fnd_msg_pub.get(i,'F');
3192                       l_message := replace(l_message,chr(0),' ');
3193                       WSH_UTIL_CORE.PrintMsg(l_message);
3194                   END LOOP;
3195                   l_completion_status := 'WARNING';
3196                   fnd_msg_pub.delete_msg();
3197                   IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
3198                       WSH_UTIL_CORE.PrintMsg('Unexpected error. Exiting');
3199 		      --Bug 4906830
3200 		      IF ( G_CONC_REQ = FND_API.G_TRUE ) THEN
3201                         l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR','');
3202                         errbuf := 'Unexpected error. Exiting';
3203                         retcode := '2';
3204                       ELSE
3205                         G_ONLINE_PICK_RELEASE_PHASE :='START';
3206                       END IF;
3207 		      --Bug 4906830
3208                       RAISE e_return;
3209                   ELSE
3210                       WSH_UTIL_CORE.PrintMsg('Pick Confirm Partially Sucessful');
3211                   END IF;
3212                --}
3213                ELSIF (l_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
3214                   IF l_debug_on THEN
3215                      WSH_DEBUG_SV.logmsg(l_module_name,  'PICK CONFIRM SUCESSFUL'  );
3216                   END IF;
3217                END IF;
3218 
3219 	       IF ( G_CONC_REQ = FND_API.G_TRUE ) THEN
3220                --{
3221   	            IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
3222 		       IF l_debug_on THEN
3223 		 	  WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Process_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
3224 		       END IF;
3225 		       WSH_UTIL_CORE.Process_stops_for_load_tender ( p_reset_flags   => FALSE,
3226 							             x_return_status => l_return_status );
3227 		       IF l_debug_on THEN
3228 		   	  WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
3229 		       END IF;
3230                        IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR)
3231                        OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
3232                            WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_UTIL_CORE.Process_stops_for_load_tender');
3233                            RAISE e_return;
3234                        ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
3235                            IF l_completion_status = 'NORMAL' THEN
3236                               l_completion_status := 'WARNING';
3237                            END IF;
3238                        END IF;
3239 		    END IF;
3240                     IF l_debug_on THEN
3241                        WSH_DEBUG_SV.logmsg(l_module_name,  'Commiting...');
3242                     END IF;
3243 		    COMMIT;
3244 	       END IF; --}
3245             --}
3246             END IF; /* Confirm Logic */
3247 
3248 
3249             -- Clear the table of move order line records for next loop
3250             g_trolin_tbl.delete;
3251             l_pick_release_stat.delete;
3252 
3253          --}
3254          END LOOP;
3255 
3256          -- Bug 9953872 - Need to update detailed_count in WSH_PR_WORKERS table,
3257          -- so that move order header is NOT deleted in specific case where last
3258          -- batch of lines picked are ignored (say if all the lines are part of
3259          -- ship set and if there are some more lines in OM that are not interfaced
3260          -- yet to shipping).
3261          -- Next Organization - Move Order Header Combination
3262          <<NEXT_ORG_MO_WORKER>>
3263          -- { Next Org MO Worker
3264          -- Increment worker record 'DOC' with records detailed count
3265          --{
3266          IF WSH_PR_CRITERIA.g_nonreservable_item = 'Y' and l_total_detailed_count = 0 THEN
3267             l_total_detailed_count := 1;
3268          END IF;
3269          IF l_total_detailed_count > 0 THEN
3270 
3271             UPDATE WSH_PR_WORKERS
3272             SET    detailed_count   = detailed_count + l_total_detailed_count
3273             WHERE  batch_id         = WSH_PICK_LIST.G_BATCH_ID
3274             AND    organization_id  = batch_rec.organization_id
3275             AND    type             = 'DOC';
3276             --
3277             IF l_debug_on THEN
3278                WSH_DEBUG_SV.log(l_module_name, 'No of rows updated for type DOC with detailed_count ' || l_total_detailed_count, sql%rowcount);
3279             END IF;
3280             --
3281          END IF;
3282          --}
3283 
3284          -- Insert printer record into worker table for pick slip printing on specific printers
3285          --{
3286          IF WSH_INV_INTEGRATION_GRP.G_PRINTERTAB.COUNT > 0 THEN
3287             FOR i in 1..WSH_INV_INTEGRATION_GRP.G_PRINTERTAB.COUNT LOOP
3288                 IF WSH_INV_INTEGRATION_GRP.G_PRINTERTAB(i).printer_name IS NOT null THEN
3289                    INSERT INTO WSH_PR_WORKERS (
3290                                                 batch_id,
3291                                                 type,
3292                                                 organization_id,
3293                                                 printer_name,
3294 						conc_program_name
3295                                               )
3296                                       SELECT
3297                                                 WSH_PICK_LIST.G_BATCH_ID,
3298                                                 'PRINTER',
3299                                                 batch_rec.organization_id,
3300                                                 WSH_INV_INTEGRATION_GRP.G_PRINTERTAB(i).printer_name,
3301                                                 WSH_INV_INTEGRATION_GRP.G_PRINTERTAB(i).conc_program_name
3302                                       FROM dual
3303                                       WHERE NOT EXISTS (
3304                                                          SELECT 'x'
3305                                                          FROM   wsh_pr_workers
3306                                                          WHERE  batch_id = WSH_PICK_LIST.G_BATCH_ID
3307                                                          AND    type = 'PRINTER'
3308                                                          AND    organization_id = batch_rec.organization_id
3309                                                          AND    printer_name = WSH_INV_INTEGRATION_GRP.G_PRINTERTAB(i).printer_name
3310 							 AND    conc_program_name=WSH_INV_INTEGRATION_GRP.G_PRINTERTAB(i).conc_program_name);
3311                 END IF;
3312             END LOOP;
3313          END IF;
3314          --}
3315 
3316 	 IF ( G_CONC_REQ = FND_API.G_TRUE ) THEN
3317             IF l_debug_on THEN
3318                WSH_DEBUG_SV.logmsg(l_module_name,  'Commiting...');
3319             END IF;
3320 	    COMMIT;
3321 	 END IF;
3322          -- } Next Org MO Worker
3323 
3324      --}
3325      END LOOP;
3326 
3327      -- Set Completion Status
3328      -- Completion status to warning for error backordered.
3329      IF ( G_BACKORDERED ) AND l_completion_status <> 'ERROR' THEN
3330         l_completion_status := 'WARNING';
3331      END IF;
3332 
3333      WSH_UTIL_CORE.PrintMsg('Picking in Release_Batch_Sub is completed');
3334 
3335   END IF;
3336   --}
3337 
3338   -- 20. For p_mode = 'PS'
3339   --{
3340   IF p_mode = 'PS' THEN
3341 
3342      FOR crec in c_get_del LOOP
3343      --{
3344          l_rec_found := FALSE;
3345          DECLARE
3346            worker_row_locked exception;
3347            PRAGMA EXCEPTION_INIT(worker_row_locked, -54);
3348          BEGIN
3349            IF l_debug_on THEN
3350               WSH_DEBUG_SV.logmsg(l_module_name,'Getting lock for Del '||crec.delivery_id);
3351            END IF;
3352            -- Bug # 9369504 : Added rowid in the where clause.
3353            SELECT 'x'
3354            INTO   l_dummy
3355            FROM   wsh_pr_workers
3356            WHERE  rowid = crec.rowid
3357            AND    processed = 'N'
3358            FOR    UPDATE NOWAIT;
3359            l_rec_found := TRUE;
3360 
3361            UPDATE wsh_pr_workers
3362            SET    processed = 'Y'
3363            WHERE  rowid= crec.rowid;
3364 
3365          EXCEPTION
3366            WHEN NO_DATA_FOUND THEN
3367              l_rec_found := FALSE;
3368            WHEN WORKER_ROW_LOCKED THEN
3369              l_rec_found := FALSE;
3370          END;
3371 
3372          IF l_rec_found THEN
3373          --{
3374             IF crec.ap_level > 0 THEN
3375             --{
3376                IF l_debug_on THEN
3377                   WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_BATCH_PROCESS.Auto_Pack_A_Delivery'
3378                                                     ,WSH_DEBUG_SV.C_PROC_LEVEL);
3379                END IF;
3380                l_del_pack_count := l_del_pack_count + 1;
3381                WSH_BATCH_PROCESS.Auto_Pack_A_Delivery (
3382                                                         p_delivery_id     => crec.delivery_id,
3383                                                         p_ap_batch_id     => crec.PA_SC_BATCH_ID,
3384                                                         p_auto_pack_level => crec.ap_level,
3385                                                         p_log_level       => p_log_level,
3386                                                         x_return_status   => l_return_status
3387                                                       );
3388                IF l_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3389                   l_packed_results_success := l_packed_results_success + 1;
3390                ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING   THEN
3391                   l_packed_results_warning := l_packed_results_warning + 1;
3392                   WSH_BATCH_PROCESS.log_batch_messages (
3393                                                          crec.PA_SC_BATCH_ID,
3394                                                          crec.delivery_id,
3395                                                          NULL,
3396                                                          crec.PICKUP_LOCATION_ID,
3397                                                          'W' );
3398                ELSE
3399                   l_packed_results_failure := l_packed_results_failure + 1;
3400                   WSH_BATCH_PROCESS.log_batch_messages (
3401                                                          crec.PA_SC_BATCH_ID,
3402                                                          crec.delivery_id,
3403                                                          NULL,
3404                                                          crec.PICKUP_LOCATION_ID,
3405                                                          'E' );
3406                END IF;
3407             --}
3408             END IF;
3409 
3410             IF l_debug_on THEN
3411                WSH_DEBUG_SV.log(l_module_name,'sc_rule_id',crec.sc_rule_id);
3412             END IF;
3413 
3414             IF crec.sc_rule_id IS NOT NULL THEN
3415             --{
3416                DECLARE
3417                  WSH_MISSING_SC_BATCH EXCEPTION;
3418                  WSH_MISSING_SC_RULE EXCEPTION;
3419                BEGIN
3420                  l_del_sc_count := l_del_sc_count + 1;
3421                  IF crec.sc_rule_id <> nvl(l_prev_sc_rule_id,-99) THEN
3422                  --{
3423                     OPEN WSH_BATCH_PROCESS.G_GET_SHIP_CONFIRM_RULE(crec.sc_rule_id);
3424                     FETCH WSH_BATCH_PROCESS.G_GET_SHIP_CONFIRM_RULE
3425                        INTO l_ship_confirm_rule_rec;
3426                     IF WSH_BATCH_PROCESS.G_GET_SHIP_CONFIRM_RULE%NOTFOUND THEN
3427                        CLOSE WSH_BATCH_PROCESS.G_GET_SHIP_CONFIRM_RULE;
3428                        RAISE WSH_MISSING_SC_RULE;
3429                     ELSE
3430                        CLOSE WSH_BATCH_PROCESS.G_GET_SHIP_CONFIRM_RULE;
3431                     END IF;
3432                     l_prev_sc_rule_id := crec.sc_rule_id;
3433                  --}
3434                  END IF;
3435 
3436                  --{
3437                  IF l_debug_on THEN
3438                     WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_BATCH_PROCESS.Ship_Confirm_A_Delivery');
3439                  END IF;
3440                  WSH_BATCH_PROCESS.Ship_Confirm_A_Delivery (
3441                          p_delivery_id            => crec.delivery_id,
3442                          p_sc_batch_id            => crec.pa_sc_batch_id,
3443                          p_ship_confirm_rule_rec  => l_ship_confirm_rule_rec,
3444                          p_log_level              => p_log_level,
3445                          p_actual_departure_date  => WSH_PR_CRITERIA.g_actual_departure_date,
3446                          x_return_status          => l_return_status
3447                         );
3448                  IF l_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3449                     l_confirmed_results_success := l_confirmed_results_success + 1;
3450                  ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING   THEN
3451                     l_confirmed_results_warning := l_confirmed_results_warning + 1;
3452                     WSH_BATCH_PROCESS.log_batch_messages (
3453                                                            crec.PA_SC_BATCH_ID,
3454                                                            crec.delivery_id,
3455                                                            NULL,
3456                                                            crec.PICKUP_LOCATION_ID,
3457                                                            'W' );
3458                  ELSE
3459                     l_confirmed_results_failure := l_confirmed_results_failure + 1;
3460                     WSH_BATCH_PROCESS.log_batch_messages (
3461                                                            crec.PA_SC_BATCH_ID,
3462                                                            crec.delivery_id,
3463                                                            NULL,
3464                                                            crec.PICKUP_LOCATION_ID,
3465                                                            'E' );
3466                  END IF;
3467                  --}
3468                EXCEPTION
3469                  WHEN WSH_MISSING_SC_RULE THEN
3470                    WSH_UTIL_CORE.PrintMsg('ERROR: Failed to find the ship confirm rule ');
3471                    l_confirmed_results_failure := l_confirmed_results_failure + 1;
3472                END;
3473             --}
3474             END IF;
3475 
3476          --}
3477          END IF;
3478 
3479      --}
3480      END LOOP;
3481 
3482      IF l_debug_on THEN
3483         WSH_DEBUG_SV.log(l_module_name,'l_completion_status ', l_completion_status);
3484         WSH_DEBUG_SV.logmsg(l_module_name,'l_del_pack_count '||l_del_pack_count
3485                                     ||' l_packed_results_success '||l_packed_results_success
3486                                     ||' l_del_sc_count '||l_del_sc_count
3487                                     ||' l_confirmed_results_success '||l_confirmed_results_success);
3488      END IF;
3489      IF l_completion_status = 'NORMAL' THEN
3490         IF (l_del_pack_count > 0 AND l_packed_results_success <> l_del_pack_count)
3491         OR (l_del_sc_count > 0 AND l_confirmed_results_success <> l_del_sc_count) THEN
3492             l_completion_status := 'WARNING';
3493         END IF;
3494      END IF;
3495 
3496   END IF;
3497   --}
3498 
3499   --{ Online Message
3500   IF (l_completion_status = 'WARNING') THEN
3501       G_ONLINE_PICK_RELEASE_RESULT := 'W';
3502   ELSE
3503       G_ONLINE_PICK_RELEASE_RESULT := 'S';
3504       G_ONLINE_PICK_RELEASE_PHASE := 'SUCCESS';
3505   END IF;
3506 
3507   IF G_CONC_REQ = FND_API.G_TRUE THEN
3508      -- Set the completion status only in the case of Child Request
3509      -- If this is done as part of Parent Process, this setting will cause program to stop without doing
3510      -- any further processing
3511      IF p_worker_id is not null then
3512         l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS(l_completion_status,'');
3513      END IF;
3514 
3515      IF l_completion_status = 'NORMAL' THEN
3516         retcode := '0';
3517      ELSIF l_completion_status = 'WARNING' THEN
3518         retcode := '1';
3519      ELSE
3520         retcode := '2';
3521      END IF;
3522   END IF;
3523   --}
3524 
3525   IF l_debug_on THEN
3526      WSH_DEBUG_SV.logmsg(l_module_name,'ERRBUF :'||errbuf ||' RETCODE :'||retcode||' l_completion_status :'||l_completion_status);
3527      WSH_DEBUG_SV.pop(l_module_name);
3528   END IF;
3529 
3530 EXCEPTION
3531   WHEN e_return THEN
3532 
3533       --Bug 5355135
3534       IF G_CONC_REQ = FND_API.G_TRUE THEN
3535          ROLLBACK;
3536       ELSE
3537          ROLLBACK TO s_Release_Batch_Sub_sf;
3538       END IF;
3539 
3540       WSH_UTIL_CORE.PrintMsg('SQLCODE: '||sqlcode||' SQLERRM: '||sqlerrm);
3541       WSH_UTIL_CORE.PrintMsg('Exception occurred in WSH_PICK_LIST.Release_Batch_Sub');
3542       IF G_CONC_REQ = FND_API.G_TRUE THEN
3543          -- Set the completion status only in the case of Child Request
3544          -- If this is done as part of Parent Process, this setting will cause program to stop without doing
3545          -- any further processing
3546          IF p_worker_id is not null then
3547             l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR','');
3548          END IF;
3549          errbuf := 'Exception occurred in WSH_PICK_LIST';
3550          retcode := '2';
3551       END IF;
3552       G_ONLINE_PICK_RELEASE_RESULT := 'F';
3553       IF l_debug_on THEN
3554          WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:E_RETURN');
3555       END IF;
3556   WHEN OTHERS THEN
3557       --Bug 5355135
3558       IF G_CONC_REQ = FND_API.G_TRUE THEN
3559          ROLLBACK;
3560       ELSE
3561          ROLLBACK TO s_Release_Batch_Sub_sf;
3562       END IF;
3563 
3564       WSH_UTIL_CORE.PrintMsg('SQLCODE: '||sqlcode||' SQLERRM: '||sqlerrm);
3565       WSH_UTIL_CORE.PrintMsg('Exception occurred in WSH_PICK_LIST.Release_Batch_Sub');
3566       IF G_CONC_REQ = FND_API.G_TRUE THEN
3567          -- Set the completion status only in the case of Child Request
3568          -- If this is done as part of Parent Process, this setting will cause program to stop without doing
3569          -- any further processing
3570          IF p_worker_id is not null then
3571             l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR','');
3572          END IF;
3573          errbuf := 'Exception occurred in WSH_PICK_LIST';
3574          retcode := '2';
3575       END IF;
3576       G_ONLINE_PICK_RELEASE_RESULT := 'F';
3577       IF l_debug_on THEN
3578          WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '
3579                                            || SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
3580          WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
3581       END IF;
3582 
3583 END Release_Batch_Sub;
3584 
3585 
3586 -- Start of comments
3587 -- API name : Release_Batch
3588 -- Type     : Public
3589 -- Pre-reqs : None.
3590 -- Procedure: This is core api to pick release a batch, api does
3591 --            1. Gets initializes batch criteria.
3592 --            2. Select details lines based on release criteria.
3593 --            3. Calls Inventory Move Order api for allocation and pick confirmation.
3594 --            4. Create/Appened deliveries, pack or ship confirmed based on release criteria.
3595 --            5. Print document sets.
3596 -- Parameters :
3597 -- IN:
3598 --      p_batch_id            IN  Batch Id.
3599 --      p_log_level           IN  Set the debug log level.
3600 --      p_num_workers         IN  Number of workers
3601 -- OUT:
3602 --      errbuf       OUT NOCOPY  Error message.
3603 --      retcode      OUT NOCOPY  Error Code 1:Successs, 2:Warning and 3:Error.
3604 -- End of comments
3605 PROCEDURE Release_Batch (
3606           errbuf    OUT NOCOPY   VARCHAR2,
3607           retcode OUT NOCOPY   VARCHAR2,
3608           p_batch_id  IN  NUMBER,
3609           p_log_level  IN   NUMBER,
3610           p_num_workers IN  NUMBER
3611            ) IS
3612           record_locked  EXCEPTION;
3613           PRAGMA EXCEPTION_INIT(record_locked, -54);
3614 
3615 
3616           -- Cursor to select organization ids when no
3617           -- organization is specified in the picking batch
3618           -- Only one select statement will be executed
3619 
3620           -- Added DISTINCT for the first 2 queries to fix Bug 1644985
3621            CURSOR get_orgs(v_trip_id   IN NUMBER,
3622             v_trip_stop_id  IN NUMBER,
3623             v_from_loc_id   IN NUMBER,
3624             v_delivery_id   IN NUMBER,
3625             v_order_hdr_id  IN NUMBER,
3626             v_del_detail_id IN NUMBER,
3627             v_batch_id  IN NUMBER,
3628 	    v_fromSchDate IN DATE,
3629 	    v_ToSchDate   IN DATE,
3630             v_FromReqDate IN DATE,
3631 	    v_ToReqDate	  IN DATE
3632           ) IS
3633           SELECT DISTINCT WND.ORGANIZATION_ID
3634           FROM   WSH_NEW_DELIVERIES WND,
3635            WSH_DELIVERY_LEGS WLG,
3636            WSH_TRIP_STOPS WTS
3637           WHERE  WTS.TRIP_ID   = v_trip_id
3638           AND WTS.STOP_ID = WLG.PICK_UP_STOP_ID
3639           AND WLG.DELIVERY_ID  = WND.DELIVERY_ID
3640           AND nvl(WND.SHIPMENT_DIRECTION , 'O') IN ('O', 'IO')   -- J Inbound Logistics
3641           AND v_trip_stop_id = 0
3642           AND v_delivery_id = 0
3643           AND v_order_hdr_id = 0
3644           -- Bug 11669468: Included -2 in IN clause
3645           AND v_del_detail_id in (0,-1,-2)
3646           AND (v_from_loc_id = -1
3647           OR WND.ORGANIZATION_ID IN (SELECT organization_id
3648                FROM   hr_organization_units hr,
3649               wsh_locations wl
3650               WHERE wl.wsh_location_id = v_from_loc_id
3651               AND wl.location_source_code = 'HR'
3652               AND wl.source_location_id =
3653                  hr.location_id))
3654           UNION ALL
3655           SELECT DISTINCT WND.ORGANIZATION_ID
3656           FROM   WSH_NEW_DELIVERIES WND,
3657            WSH_DELIVERY_LEGS WLG,
3658            WSH_TRIP_STOPS WTS
3659           WHERE  WTS.STOP_ID  = WLG.PICK_UP_STOP_ID
3660           AND WLG.DELIVERY_ID  = WND.DELIVERY_ID
3661           AND WTS.STOP_ID = v_trip_stop_id
3662           AND nvl(WND.SHIPMENT_DIRECTION , 'O') IN ('O', 'IO')   -- J Inbound Logistics
3663           AND v_delivery_id = 0
3664           AND v_order_hdr_id = 0
3665           -- Bug 11669468: Included -2 in IN clause
3666           AND v_del_detail_id in (0,-1,-2)
3667           UNION ALL
3668           SELECT WND.ORGANIZATION_ID
3669           FROM   WSH_NEW_DELIVERIES WND
3670           WHERE  WND.DELIVERY_ID = v_delivery_id
3671           AND nvl(WND.SHIPMENT_DIRECTION , 'O') IN ('O', 'IO')   -- J Inbound Logistics
3672           UNION ALL
3673           SELECT DISTINCT ORGANIZATION_ID
3674           FROM   WSH_DELIVERY_DETAILS
3675           WHERE  SOURCE_CODE = 'OE'
3676           AND    RELEASED_STATUS IN ('R', 'B', 'X') -- Added For Bug-2722194 (Non-Assigned and
3677                                                -- Ready to release Lines -> Base Bug-2687090)
3678           AND SOURCE_HEADER_ID = v_order_hdr_id
3679           -- Bug 11669468: Included -2 in IN clause
3680           AND v_del_detail_id  in (0,-1,-2)
3681           AND v_delivery_id = 0
3682           UNION ALL
3683           SELECT DISTINCT ORGANIZATION_ID
3684           FROM WSH_DELIVERY_DETAILS
3685           WHERE DELIVERY_DETAIL_ID =   v_del_detail_id
3686           AND nvl(LINE_DIRECTION , 'O') IN ('O', 'IO')   -- J Inbound Logistics
3687           AND  v_delivery_id  = 0
3688           UNION ALL
3689           SELECT DISTINCT WDD.ORGANIZATION_ID
3690           FROM WSH_DELIVERY_DETAILS WDD
3691           WHERE  v_delivery_id  = 0
3692           AND nvl(WDD.LINE_DIRECTION , 'O') IN ('O', 'IO')   -- J Inbound Logistics
3693           -- Bug 11669468: Included -2 in IN clause
3694           AND v_del_detail_id  in (0, -1,-2)
3695           AND  WDD.BATCH_ID =   v_batch_id;
3696 
3697           --Cursor to get ship confirm rule and Packing level.
3698           CURSOR get_pack_ship_groups(v_batch_id in number) IS
3699           SELECT wsp.ship_confirm_rule_id, wsp.autopack_level
3700           FROM   wsh_shipping_parameters wsp, wsh_delivery_details wdd
3701           WHERE  wdd.batch_id = v_batch_id
3702           AND    wsp.organization_id = wdd.organization_id
3703           GROUP  BY wsp.ship_confirm_rule_id, wsp.autopack_level;
3704 
3705           TYPE group_details_rec_tab_type IS TABLE OF get_pack_ship_groups%ROWTYPE INDEX BY BINARY_INTEGER;
3706 
3707           --Cursor to get delivery detail attributes for ship confirm rule and Packing level.
3708           CURSOR get_dels_in_group(v_batch_id in number, v_sc_rule_id in number, v_ap_level in number) IS
3709           SELECT DISTINCT wda.delivery_id, wdd.organization_id,
3710 	         wdd.ship_from_location_id
3711           FROM   wsh_delivery_assignments_v wda, wsh_delivery_details wdd,
3712                  wsh_shipping_parameters wsp
3713           WHERE  wdd.batch_id = v_batch_id
3714           AND    wdd.delivery_detail_id = wda.delivery_detail_id
3715           AND    wdd.organization_id = wsp.organization_id
3716           AND    NVL(wsp.ship_confirm_rule_id, 0) = NVL(v_sc_rule_id, 0)
3717           AND    NVL(wsp.autopack_level, 0) = NVL(v_ap_level, 0)
3718           AND    NVL(wdd.LINE_DIRECTION , 'O') IN ('O', 'IO');   -- J Inbound Logistics
3719 
3720           --Cursor to get delivery detail attributes for batch_id.
3721           CURSOR get_dels_in_batch(v_batch_id in number) IS
3722           SELECT DISTINCT wda.delivery_id, wdd.organization_id,
3723                  wdd.ship_from_location_id
3724           FROM   wsh_delivery_assignments_v wda, wsh_delivery_details wdd
3725           WHERE  wdd.batch_id = v_batch_id
3726           AND    wdd.delivery_detail_id = wda.delivery_detail_id
3727           AND    NVL(wdd.LINE_DIRECTION , 'O') IN ('O', 'IO');   -- J Inbound Logistics
3728 
3729           l_group_details_rec_tab   group_details_rec_tab_type;
3730 
3731           -- Sort the organization ids to prevent processing of duplicate organization ids
3732           CURSOR c_distinct_organization_id IS
3733           SELECT distinct id FROM wsh_tmp;
3734 
3735           CURSOR c_get_backordered_details(l_batch_id NUMBER) IS
3736           SELECT wdd.delivery_detail_id, wda.delivery_id, wda.parent_delivery_detail_id, wdd.organization_id,
3737                  wdd.line_direction, wdd.gross_weight, wdd.net_weight, wdd.volume,
3738                  wnd.planned_flag, wnd.batch_id
3739           FROM   wsh_delivery_details wdd,
3740                  wsh_delivery_assignments_v wda,
3741                  wsh_new_deliveries wnd
3742           WHERE  wdd.batch_id = l_batch_id
3743           AND    wdd.delivery_detail_id = wda.delivery_detail_id
3744           AND    wdd.released_status = 'B'
3745           AND    wdd.replenishment_status IS NULL  -- replenishment2, select only back order delivery lines.
3746           AND    wda.delivery_id = wnd.delivery_id(+);
3747 
3748           l_backorder_rec_tbl    WSH_USA_INV_PVT.Back_Det_Rec_Tbl;
3749 
3750           CURSOR c_batch_orgs(l_batch_id NUMBER) IS
3751           SELECT organization_id
3752           FROM   wsh_pr_workers
3753           WHERE  batch_id = l_batch_id
3754           AND    type = 'DOC';
3755 
3756           CURSOR c_get_unassigned_details(l_batch_id NUMBER, l_organization_id NUMBER) IS
3757           SELECT wdd.delivery_detail_id
3758           FROM   wsh_delivery_details wdd,
3759                  wsh_delivery_assignments_v wda
3760           WHERE  wdd.batch_id = l_batch_id
3761           AND    wdd.released_status in ('S','Y')
3762           AND    wdd.delivery_detail_id = wda.delivery_detail_id
3763           AND    wdd.organization_id = l_organization_id
3764           AND    wda.delivery_id IS NULL;
3765 
3766           -- get total worker records for Pick Release
3767           CURSOR c_tot_worker_records(l_batch_id NUMBER) is
3768           SELECT COUNT(*)
3769           FROM   wsh_pr_workers
3770           WHERE  batch_id = l_batch_id
3771           AND    type = 'PICK'
3772           AND    PROCESSED = 'N';
3773 
3774           CURSOR c_sum_worker(l_batch_id NUMBER) is
3775           SELECT organization_id, mo_header_id, DETAILED_COUNT tot_detailed
3776           FROM   wsh_pr_workers
3777           WHERE  batch_id = l_batch_id
3778           AND    type = 'DOC'
3779           ORDER  BY organization_id;
3780 
3781           CURSOR c_defer_interface(l_batch_id NUMBER) is
3782           SELECT DISTINCT wpr.pa_sc_batch_id, wscr.ac_defer_interface_flag
3783           FROM   wsh_pr_workers wpr,
3784                  wsh_ship_confirm_rules wscr
3785           WHERE  wpr.batch_id = l_batch_id
3786           AND    wpr.type = 'PS'
3787           AND    wpr.sc_rule_id = wscr.SHIP_CONFIRM_RULE_ID
3788           AND    NVL(EFFECTIVE_START_DATE, sysdate) <= sysdate
3789           AND    NVL(EFFECTIVE_END_DATE, sysdate ) >= sysdate;
3790 
3791           CURSOR c_close_trip(l_pickrel_batch_id NUMBER) is
3792           SELECT DISTINCT wpr.batch_id, wpb.creation_date,
3793                  wscr.ac_close_trip_flag, wscr.ac_intransit_flag
3794           FROM   wsh_picking_batches wpb, wsh_ship_confirm_rules wscr, wsh_pr_workers wpr
3795           WHERE  wpr.batch_id = l_pickrel_batch_id
3796           AND    wpr.type = 'PS'
3797           AND    wpb.batch_id = wpr.pa_sc_batch_id
3798           AND    wpb.ship_confirm_rule_id = wscr.ship_confirm_rule_id
3799           AND    NVL(wscr.EFFECTIVE_START_DATE, sysdate) <= sysdate
3800           AND    NVL(wscr.EFFECTIVE_END_DATE, sysdate ) >= sysdate;
3801 
3802           CURSOR get_pick_up_stops (c_sc_batch_id NUMBER)  IS
3803           SELECT DISTINCT wtp.trip_id, wst.stop_sequence_number,
3804                  wst.stop_id, wst.stop_location_id
3805           FROM wsh_new_deliveries wnd,
3806                wsh_delivery_legs  wlg,
3807                wsh_trip_stops  wst,
3808                wsh_trips      wtp
3809           WHERE wnd.delivery_id = wlg.delivery_id AND
3810                 wlg.pick_up_stop_id = wst.stop_id AND
3811                 wnd.status_code = 'CO' AND
3812                 wnd.batch_id = c_sc_batch_id AND
3813                 wtp.trip_id = wst.trip_id AND
3814                 wst.status_code = 'OP' AND
3815                 NOT EXISTS (
3816                 select '1' from wsh_exceptions we where
3817                 we.delivery_id = wnd.delivery_id AND
3818                 we.severity = 'ERROR' AND
3819                 we.status = 'OPEN' AND
3820                 we.EXCEPTION_NAME = 'WSH_SC_REQ_EXPORT_COMPL')
3821           ORDER BY wtp.trip_id, wst.stop_sequence_number, wst.stop_id ;
3822 
3823 
3824           CURSOR get_all_stops (c_sc_batch_id NUMBER) IS
3825           SELECT  wtp.trip_id, wst.stop_sequence_number, wst.stop_id ,
3826                   wst.stop_location_id
3827           FROM wsh_new_deliveries wnd,
3828                wsh_delivery_legs  wlg,
3829                wsh_trip_stops  wst,
3830                wsh_trips      wtp
3831           WHERE wnd.delivery_id = wlg.delivery_id and
3832                 wlg.pick_up_stop_id = wst.stop_id and
3833                 wnd.status_code = 'CO' and
3834                 wnd.batch_id = c_sc_batch_id and
3835                 wst.trip_id = wtp.trip_id and
3836                 wst.status_code = 'OP' AND
3837           NOT EXISTS (
3838                 select '1' from wsh_exceptions we where
3839                 we.delivery_id = wnd.delivery_id AND
3840                 we.severity = 'ERROR' AND
3841                 we.status = 'OPEN' AND
3842                 we.EXCEPTION_NAME = 'WSH_SC_REQ_EXPORT_COMPL')
3843           UNION (
3844           SELECT wtp2.trip_id, wst2.stop_sequence_number,
3845                  wst2.stop_id, wst2.stop_location_id
3846           FROM wsh_new_deliveries wnd2,
3847                wsh_delivery_legs  wlg2,
3848                wsh_trip_stops  wst2,
3849                wsh_trips      wtp2
3850           WHERE wnd2.delivery_id = wlg2.delivery_id and
3851                 wlg2.drop_off_stop_id = wst2.stop_id and
3852                 wnd2.status_code = 'CO' and
3853                 wnd2.batch_id = c_sc_batch_id and
3854                 wst2.trip_id = wtp2.trip_id and
3855                 wst2.status_code = 'OP' AND
3856           NOT EXISTS (
3857                 select '1' from wsh_exceptions we where
3858                 we.delivery_id = wnd2.delivery_id AND
3859                 we.severity = 'ERROR' AND
3860                 we.status = 'OPEN' AND
3861                 we.EXCEPTION_NAME = 'WSH_SC_REQ_EXPORT_COMPL'))
3862           ORDER BY 1, 2, 3;
3863 
3864 
3865           CURSOR c_batch_stop(l_batch_id NUMBER) IS
3866           SELECT wts.stop_id
3867           FROM   wsh_trip_stops    wts,
3868                  wsh_delivery_legs  wdl,
3869                  wsh_new_deliveries wnd,
3870                  wsh_picking_batches wpb
3871           WHERE p_batch_id IS NOT NULL
3872           AND   wnd.batch_id    = l_batch_id
3873           AND   wdl.delivery_id = wnd.delivery_id
3874           AND   wts.stop_id     = wdl.pick_up_stop_id
3875           AND   wts.stop_location_id = wnd.initial_pickup_location_id
3876           AND   wpb.batch_id = wnd.batch_id
3877           AND   wts.status_code = 'CL'
3878           AND   rownum = 1;
3879 
3880           CURSOR c_batch_unplanned_del(l_batch_id NUMBER) IS
3881           SELECT DISTINCT wda.delivery_id
3882           FROM   wsh_delivery_details wdd,
3883                  wsh_delivery_assignments_v wda,
3884                  wsh_new_deliveries wnd,
3885                  wsh_shipping_parameters wsp
3886           WHERE  wdd.delivery_detail_id = wda.delivery_detail_id
3887           AND    wdd.batch_id = l_batch_id
3888           AND    wdd.released_status = 'Y'
3889           AND    wda.delivery_id = wnd.delivery_id
3890           AND    wda.delivery_id IS NOT NULL
3891           AND    wnd.planned_flag = 'N'
3892           AND    wnd.organization_id = wsp.organization_id
3893           AND    NVL(wsp.appending_limit, 'N') <> 'N';
3894 
3895           CURSOR c_ap_batch(l_batch_id NUMBER) IS
3896           SELECT DISTINCT pa_sc_batch_id
3897           FROM   wsh_pr_workers
3898           WHERE  batch_id = l_batch_id
3899           AND    type = 'PS'
3900           AND    NVL(ap_level,0) > 0;
3901 
3902           CURSOR c_wms_orgs (l_batch_id NUMBER) IS
3903           SELECT organization_id, mo_header_id
3904           FROM   wsh_pr_workers
3905           WHERE  batch_id  = l_batch_id
3906           AND    type  = 'WMS'
3907           AND    processed = 'N'      --WMS High Vol Support, Added this AND cond and ORDER BY clause
3908           ORDER BY organization_id;
3909 
3910           -- X-dock changes to only select which have been released to warehouse from Inventory
3911           CURSOR c_wms_details (l_batch_id NUMBER, l_organization_id NUMBER, l_mo_header_id NUMBER) IS
3912           SELECT wdd.delivery_detail_id, wdd.move_order_line_id
3913           FROM   wsh_delivery_details wdd,
3914                  mtl_txn_request_lines mtrl,
3915                  mtl_txn_request_headers mtrh
3916           WHERE  wdd.batch_id         = l_batch_id
3917           AND    wdd.organization_id  = l_organization_id
3918           AND    wdd.move_order_line_id IS NOT NULL
3919           AND    wdd.move_order_line_id = mtrl.line_id
3920           AND    mtrl.header_id = mtrh.header_id
3921           AND    mtrh.header_id = l_mo_header_id
3922           AND    mtrh.move_order_type <> 6
3923           AND    wdd.released_status  = WSH_DELIVERY_DETAILS_PKG.C_RELEASED_TO_WAREHOUSE; -- auto pick confirm = 'N' for these lines
3924 
3925 
3926           CURSOR c_dels_in_batch(l_batch_id NUMBER, p_organization_id NUMBER) IS
3927           SELECT delivery_id
3928           FROM   wsh_new_deliveries
3929           WHERE  batch_id = l_batch_id
3930           AND    organization_id = p_organization_id;
3931 
3932           CURSOR c_get_location(p_delivery_id NUMBER) IS
3933           SELECT initial_pickup_location_id
3934           FROM   wsh_new_deliveries
3935           WHERE  delivery_id  = p_delivery_id;
3936 
3937           CURSOR c_requests (p_parent_request_id NUMBER) IS
3938           SELECT request_id
3939           FROM   FND_CONCURRENT_REQUESTS
3940           WHERE  parent_request_id = p_parent_request_id
3941           AND    NVL(is_sub_request, 'N') = 'Y';
3942 
3943           CURSOR c_is_psgr_del(p_psgr_id NUMBER) IS
3944           select NVL(wpgr.delivery_flag, 'N')
3945           from  wsh_pick_grouping_rules wpgr
3946           where  wpgr.pick_grouping_rule_id = p_psgr_id
3947           and    sysdate between trunc(nvl(wpgr.start_date_active, sysdate)) and
3948                                           nvl(wpgr.end_date_active, trunc(sysdate)+1);
3949 
3950           CURSOR c_is_print_ps_mode_I IS
3951           select wsp.organization_id
3952           from wsh_shipping_parameters wsp, wsh_tmp wt
3953           where wt.id = wsp.organization_id
3954           and wsp.print_pick_slip_mode = 'I'
3955           and rownum = 1;
3956 
3957           CURSOR c_is_print_ps_mode_I_for_org(p_org_id NUMBER) IS
3958           select wsp.organization_id
3959           from wsh_shipping_parameters wsp
3960           where wsp.organization_id = p_org_id
3961           and wsp.print_pick_slip_mode = 'I';
3962 
3963           CURSOR c_prnt_PS_mode_PS_grp IS
3964           select wsp.organization_id
3965           from wsh_shipping_parameters wsp, wsh_tmp wt
3966           where wt.id = wsp.organization_id
3967           and (wsp.print_pick_slip_mode = 'I'
3968           OR exists
3969           (select '1'
3970           from  wsh_pick_grouping_rules wpgr
3971           where  wpgr.pick_grouping_rule_id = wsp.pick_grouping_rule_id
3972           and    sysdate between trunc(nvl(wpgr.start_date_active, sysdate)) and
3973                                           nvl(wpgr.end_date_active, trunc(sysdate)+1)
3974           AND wpgr.delivery_flag = 'Y'))
3975           AND rownum = 1;
3976 
3977           CURSOR c_prnt_PS_mode_PS_grp_for_org (p_org_id NUMBER) IS
3978           select wsp.organization_id
3979           from wsh_shipping_parameters wsp
3980           where wsp.organization_id = p_org_id
3981           and (wsp.print_pick_slip_mode = 'I'
3982           OR exists
3983           (select '1'
3984           from  wsh_pick_grouping_rules wpgr
3985           where  wpgr.pick_grouping_rule_id = wsp.pick_grouping_rule_id
3986           and    sysdate between trunc(nvl(wpgr.start_date_active, sysdate)) and
3987                                           nvl(wpgr.end_date_active, trunc(sysdate)+1)
3988           AND wpgr.delivery_flag = 'Y'));
3989 
3990           --bug# 6689448 (replenishment project) : needs to pass replenishment requested lines to WMS
3991           CURSOR get_replenish_orgs(c_batch_id NUMBER) IS
3992           SELECT DISTINCT organization_id
3993           FROM wsh_delivery_details
3994           WHERE  released_status = 'B'
3995           AND    replenishment_status = 'R'
3996           AND    batch_id = c_batch_id;
3997 
3998 
3999           l_return_status VARCHAR2(1);
4000           l_completion_status VARCHAR2(30);
4001           l_temp    BOOLEAN;
4002           l_trohdr_rec              INV_MOVE_ORDER_PUB.Trohdr_Rec_Type;
4003           l_empty_trohdr_rec  INV_MOVE_ORDER_PUB.Trohdr_Rec_Type;
4004           l_trohdr_val_rec  INV_MOVE_ORDER_PUB.Trohdr_Val_Rec_Type;
4005           l_empty_trohdr_val_rec  INV_MOVE_ORDER_PUB.Trohdr_Val_Rec_Type;
4006           l_trolin_tbl                   INV_MOVE_ORDER_PUB.Trolin_Tbl_Type;
4007           l_trolin_val_tbl               INV_MOVE_ORDER_PUB.Trolin_Val_Tbl_Type;
4008           l_api_version_number   NUMBER := 1.0;
4009           l_msg_count   NUMBER;
4010           l_msg_data  VARCHAR2(2000);
4011           l_commit  VARCHAR2(1) := FND_API.G_FALSE;
4012           l_delivery_id   NUMBER;
4013           l_trip_id   NUMBER;
4014           l_trip_stop_id  NUMBER;
4015           l_ship_from_loc_id  NUMBER;
4016           l_source_header_id  NUMBER;
4017           l_delivery_detail_id  NUMBER;
4018           l_to_subinventory VARCHAR2(10);
4019           l_to_locator  NUMBER;
4020           l_fromSchDate  DATE;
4021           l_toSchDate    DATE;
4022           l_fromReqDate  DATE;
4023           l_toReqDate    DATE;
4024           l_tmp_org_id NUMBER;
4025           l_psgr_delivery_flag VARCHAR2(1);
4026 
4027 	  TYPE organization_tab_type IS TABLE OF NUMBER index by BINARY_INTEGER ;
4028 	  l_organization_tab            organization_tab_type;
4029           l_distinct_organization_tab   organization_tab_type;
4030           l_dummy_tab                   organization_tab_type;
4031           l_dummy1_tab                  organization_tab_type;
4032 
4033           l_index NUMBER;
4034 	  l_organization_id NUMBER;
4035 
4036           l_user_id   NUMBER;
4037           l_login_id  NUMBER;
4038           l_date    DATE;
4039           l_message   VARCHAR2(2000);
4040           l_rowid   VARCHAR2(30);
4041           l_curr_count   NUMBER;
4042           l_batch_name  VARCHAR2(30);
4043           l_task_planning_flag  WSH_PICKING_BATCHES.task_planning_flag%TYPE;
4044           l_init_rules  VARCHAR2(1) := FND_API.G_FALSE;
4045           l_print_cursor_flag  VARCHAR2(1);
4046           l_pr_worker_rec_count NUMBER := 0;
4047           l_counter   NUMBER := 0;
4048           l_count NUMBER := 0;
4049           l_del_batch_id  NUMBER;
4050           l_del_batch_name  VARCHAR2(30);
4051           l_tmp_row_id  VARCHAR2(2000);
4052           l_delivery_ids  WSH_UTIL_CORE.Id_Tab_Type;
4053           l_request_id NUMBER;
4054           l_item_name VARCHAR2(2000);
4055           l_message1   VARCHAR2(2000);
4056           l_exception_return_status  VARCHAR2(30);
4057           l_exception_msg_count   NUMBER;
4058           l_exception_msg_data   VARCHAR2(4000) := NULL;
4059           l_dummy_exception_id   NUMBER;
4060           l_warehouse_type   VARCHAR2(10);
4061           l_temp_num     NUMBER;
4062           l_del_ids_tab  wsh_util_core.id_tab_type;   -- empty table of delivery ids
4063 
4064           i   NUMBER;
4065           j   NUMBER;
4066 
4067           l_ps_delivery_tab         WSH_UTIL_CORE.Id_Tab_Type;
4068           l_ps_org_tab              WSH_UTIL_CORE.Id_Tab_Type;
4069           l_ps_pick_loc_tab         WSH_UTIL_CORE.Id_Tab_Type;
4070           l_ap_batch_id             NUMBER;
4071           l_sc_id_tab               WSH_UTIL_CORE.Id_Tab_Type;
4072           l_interface_stop_id       NUMBER;
4073           l_batch_creation_date     DATE := NULL;
4074           l_ac_close_trip_flag      VARCHAR2(1);
4075           l_ac_intransit_flag       VARCHAR2(1);
4076           l_stop_sequence_number    NUMBER;
4077           l_stop_id                 NUMBER;
4078           l_stop_location_id        NUMBER;
4079           l_stops_to_close          WSH_UTIL_CORE.Id_Tab_Type;
4080           l_stop_location_ids       WSH_UTIL_CORE.Id_Tab_Type;
4081           l_stops_sc_ids            WSH_UTIL_CORE.Id_Tab_Type;
4082           l_closing_stop_success    NUMBER := 0;
4083           l_closing_stop_failure    NUMBER := 0;
4084           l_closing_stop_warning    NUMBER := 0;
4085           l_lock_error              VARCHAR2(1);
4086 
4087           l_act_ap_level            NUMBER;
4088           l_ap_level                NUMBER;
4089           l_act_ap_flag             VARCHAR2(1);
4090           l_ap_flag                 VARCHAR2(1);
4091           l_sc_rule_id              NUMBER;
4092           l_group_nums              NUMBER;
4093           l_del_count               NUMBER;
4094           l_grp_count               NUMBER;
4095           --
4096           l_debug_on                BOOLEAN;
4097           l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'RELEASE_BATCH';
4098           --
4099           l_num_workers             NUMBER;
4100           l_tot_worker_records      NUMBER;
4101           l_tot_smc_records         NUMBER;
4102           l_tot_dd_records          NUMBER;
4103           l_worker_records          NUMBER;
4104           l_smc_records             NUMBER;
4105           l_dd_records              NUMBER;
4106           l_org_info                WSH_PICK_LIST.Org_Params_Rec;
4107           l_org_info_tbl            WSH_PICK_LIST.Org_Params_Rec_Tbl;
4108           l_detail_cfetch           NUMBER;
4109           l_detail_pfetch           NUMBER;
4110           l_del_details_tbl         WSH_UTIL_CORE.Id_Tab_Type;
4111           l_mo_lines_tbl            INV_MOVE_ORDER_PUB.Num_Tbl_Type;
4112           l_carton_grouping_tbl     INV_MOVE_ORDER_PUB.Num_Tbl_Type;
4113           l_print_ps                VARCHAR2(1);
4114           l_phase                   VARCHAR2(100);
4115           l_status                  VARCHAR2(100);
4116           l_dev_phase               VARCHAR2(100);
4117           l_dev_status              VARCHAR2(100);
4118           l_child_req_ids           WSH_UTIL_CORE.Id_Tab_Type;
4119           l_this_request            NUMBER;
4120           l_dummy                   BOOLEAN;
4121           l_errors                  NUMBER := 0;
4122           l_warnings                NUMBER := 0;
4123           l_pr_batch_size           NUMBER;
4124 
4125           l_attr_tab                WSH_DELIVERY_AUTOCREATE.Grp_attr_tab_type;
4126           l_group_tab               WSH_DELIVERY_AUTOCREATE.Grp_attr_tab_type;
4127           l_action_rec              WSH_DELIVERY_AUTOCREATE.Action_rec_type;
4128           l_target_rec              WSH_DELIVERY_AUTOCREATE.Grp_attr_rec_type;
4129           l_matched_entities        WSH_UTIL_CORE.id_tab_type;
4130           l_out_rec                 WSH_DELIVERY_AUTOCREATE.Out_rec_type;
4131 
4132 	  l_check_dcp               NUMBER;
4133           l_in_param_rec            WSH_FTE_INTEGRATION.rate_del_in_param_rec;
4134           l_out_param_rec           WSH_FTE_INTEGRATION.rate_del_out_param_rec;
4135           l_rate_dels_tab           WSH_UTIL_CORE.Id_Tab_Type;
4136 
4137           l_excp_location_id        NUMBER;
4138 
4139           l_api_session_name CONSTANT VARCHAR2(150) := G_PKG_NAME ||'.' || l_module_name;
4140           l_reset_flags             BOOLEAN;
4141           e_return                  EXCEPTION;
4142 
4143           l_request_data            VARCHAR2(30);
4144           l_mode                    VARCHAR2(30);
4145           l_retcode                 VARCHAR2(10);
4146           l_errbuf                  VARCHAR2(2000);
4147 
4148 	  --bug 7171766
4149           l_match_found BOOLEAN;
4150           l_group_match_seq_tbl    WSH_PICK_LIST.group_match_seq_tab_type;
4151           K NUMBER ;
4152 	  l_org_complete           VARCHAR2(1);         --WMS High Vol Support
4153           v_wms_org_rec            c_wms_orgs%ROWTYPE;  --WMS High Vol Support
4154 
4155 
4156 BEGIN
4157 
4158   SAVEPOINT s_Release_Batch_sp;
4159 
4160   -- 10. Load Tendering Initializations
4161   IF WSH_UTIL_CORE.G_START_OF_SESSION_API is null THEN
4162      WSH_UTIL_CORE.G_START_OF_SESSION_API     := l_api_session_name;
4163      WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API := FALSE;
4164   END IF;
4165 
4166   -- 20. DCP Checks
4167   l_check_dcp := WSH_DCP_PVT.G_CHECK_DCP;
4168   IF l_check_dcp IS NULL THEN
4169      l_check_dcp := wsh_dcp_pvt.is_dcp_enabled;
4170   END IF;
4171 
4172   --Set global for DCP checks
4173   --Since pick release does dcp check at the end, group apis need not do the same check.
4174   IF NVL(l_check_dcp, -99) IN (1,2) THEN
4175      WSH_DCP_PVT.G_CALL_DCP_CHECK := 'N';
4176   END IF;
4177 
4178   -- 30. Logging Settings
4179   IF G_CONC_REQ = FND_API.G_TRUE THEN
4180      WSH_UTIL_CORE.Enable_Concurrent_Log_Print;
4181      IF p_log_level IS NOT NULL  THEN
4182         WSH_UTIL_CORE.Set_Log_Level(p_log_level);
4183         WSH_UTIL_CORE.PrintMsg('p_log_level is ' || to_char(p_log_level));
4184      END IF;
4185   END IF;
4186 
4187   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
4188   IF l_debug_on IS NULL
4189   THEN
4190     l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
4191   END IF;
4192 
4193   IF l_debug_on THEN
4194      WSH_DEBUG_SV.push(l_module_name);
4195      WSH_DEBUG_SV.log(l_module_name,'P_BATCH_ID',P_BATCH_ID);
4196      WSH_DEBUG_SV.log(l_module_name,'P_LOG_LEVEL',P_LOG_LEVEL);
4197      WSH_DEBUG_SV.log(l_module_name,'P_NUM_WORKERS',P_NUM_WORKERS);
4198   END IF;
4199 
4200   -- Set Online Pick Release Result
4201   -- 40. Initialized  pick release phase to Start.
4202   G_ONLINE_PICK_RELEASE_PHASE := 'START';
4203   G_BACKORDERED := FALSE;
4204   G_ONLINE_PICK_RELEASE_SKIP := 'N';
4205   G_NUM_WORKERS := NVL(P_NUM_WORKERS, 1);
4206   IF G_NUM_WORKERS = 1 THEN
4207      G_PICK_REL_PARALLEL := FALSE;
4208   END IF;
4209 
4210   l_completion_status := 'NORMAL';
4211   -- Bug 5222079
4212   -- Clear the pick slip number table
4213   --
4214   IF l_debug_on THEN
4215      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PR_PICK_SLIP_NUMBER.DELETE_PS_TBL',WSH_DEBUG_SV.C_PROC_LEVEL);
4216   END IF;
4217   --
4218   WSH_PR_PICK_SLIP_NUMBER.Delete_ps_tbl (x_api_status => l_return_status,
4219                                          x_error_message => l_message);
4220   IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
4221      OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
4222   --{
4223      WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_PR_PICK_SLIP_NUMBER.Delete_ps_tbl');
4224      RAISE e_return;
4225   END IF; --}
4226   -- end bug 5222079
4227 
4228   -- Read the Value from REQUEST_DATA. Based on this value, we will know
4229   -- if the Process is restarted after child processes are complete
4230   -- The format of Request_Data is 'Batch_id:Request_Status:Mode', where
4231   -- Batch_id is the Pick Release Batch, Request_Status is either 0 (Success) or 1 (Warning)
4232   -- and Mode is either of the following values.
4233   -- Valid Values :
4234   -- 1) NULL    : Implies First Time or Single Worker Mode
4235   -- 2) PICK-SS : Resuming Parent Process after Child Processes for SMCs/Ship Sets have completed
4236   -- 3) PICK    : Resuming Parent Process after Child Processes for Standard Items have completed
4237   -- 4) PS      : Resuming Parent Process after Child Processes for Pack and Ship have completed
4238   -- Parent process will always be restarted after child processes complete
4239   l_request_data := FND_CONC_GLOBAL.Request_Data;
4240   l_mode         := SUBSTR(l_request_data, INSTR(l_request_data,':',1,2)+1, LENGTH(l_request_data));
4241 
4242   -- Check for current request status from request_data
4243   -- Set the Backorder Flag to denote that Current Request Status need to be as Warning
4244   IF l_request_data IS NOT NULL AND SUBSTR(l_request_data, INSTR(l_request_data,':',1,1)+1, 1) = 1 THEN
4245      G_BACKORDERED := TRUE;
4246   END IF;
4247 
4248   -- 50. Any other initializations
4249   -- Set flag to print cursor information
4250   l_print_cursor_flag := 'Y';
4251 
4252   IF l_debug_on THEN
4253      WSH_DEBUG_SV.log(l_module_name,'l_mode ',l_mode);
4254   END IF;
4255 
4256   IF l_mode IS NULL THEN
4257      IF l_debug_on THEN
4258         WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4259         select count(*) into l_temp_num from wsh_Delivery_details where batch_id = p_batch_id;
4260         WSH_DEBUG_SV.log(l_module_name,'DDs for batch ',l_temp_num);
4261         WSH_DEBUG_SV.log(l_module_name,'G_NUM_WORKERS ',G_NUM_WORKERS);
4262      END IF;
4263   END IF;
4264 
4265   -- 60. Calling Init_Pick_Release API to initialize global variables in WSH_PR_CRITERIA package
4266   --     and also set Batch_Id and Seeded Pick Release Document Set
4267   IF l_debug_on THEN
4268         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit INIT_PICK_RELEASE',WSH_DEBUG_SV.C_PROC_LEVEL);
4269   END IF;
4270   Init_Pick_Release( p_batch_id      => p_batch_id,
4271                      p_worker_id     => NULL,
4272                      x_return_status => l_return_status);
4273 
4274   IF l_debug_on THEN
4275      WSH_DEBUG_SV.log(l_module_name,'INIT_PICK_RELEASE l_return_status',l_return_status);
4276      select count(*) into l_temp_num from wsh_Delivery_details where batch_id = p_batch_id;
4277      WSH_DEBUG_SV.log(l_module_name,'DDs for batch ',l_temp_num);
4278      WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4279   END IF;
4280 
4281   IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
4282      WSH_UTIL_CORE.PrintMsg('Error occurred in Init_Pick_Release');
4283      RAISE e_return;
4284   END IF;
4285 
4286   -- 70. Initializations for local variables
4287 
4288   -- Set values selected in criteria package
4289   l_user_id            := WSH_PR_CRITERIA.g_user_id;
4290   l_login_id           := WSH_PR_CRITERIA.g_login_id;
4291   l_date               := SYSDATE;
4292   l_organization_id    := WSH_PR_CRITERIA.g_organization_id;
4293   l_trip_id            := WSH_PR_CRITERIA.g_trip_id;
4294   l_trip_stop_id       := WSH_PR_CRITERIA.g_trip_stop_id;
4295   l_ship_from_loc_id   := WSH_PR_CRITERIA.g_ship_from_loc_id;
4296   l_delivery_id        := WSH_PR_CRITERIA.g_delivery_id;
4297   l_source_header_id   := WSH_PR_CRITERIA.g_order_header_id;
4298   l_delivery_detail_id := WSH_PR_CRITERIA.g_del_detail_id;
4299   l_batch_name         := WSH_PR_CRITERIA.g_batch_name;
4300   l_task_planning_flag := WSH_PR_CRITERIA.g_task_planning_flag;
4301   l_fromSchDate        := WSH_PR_CRITERIA.g_FROM_SCHED_SHIP_DATE;
4302   l_toSchDate          := WSH_PR_CRITERIA.G_TO_SCHED_SHIP_DATE;
4303   l_FromReqDate        := WSH_PR_CRITERIA.G_FROM_REQUEST_DATE;
4304   l_ToReqDate          := WSH_PR_CRITERIA.G_TO_REQUEST_DATE;
4305 
4306   -- 80. Fetching Organization(s).
4307   IF l_organization_id IS NULL THEN --{
4308         IF l_mode IS NULL THEN --{
4309         -- Parent Process
4310 	   OPEN  get_orgs(l_trip_id, l_trip_stop_id, l_ship_from_loc_id,
4311 	   	          l_delivery_id, l_source_header_id,
4312                  	  l_delivery_detail_id, p_batch_id,
4313 		          l_fromSchDate, l_toSchDate, l_FromReqDate, l_toReqDate);
4314 	   FETCH get_orgs BULK COLLECT INTO l_organization_tab;
4315 	   CLOSE get_orgs;
4316         ELSE
4317         -- Organization records can be obtained from worker table as original cursor cannot be reused
4318            OPEN  c_batch_orgs(p_batch_id);
4319            FETCH c_batch_orgs BULK COLLECT INTO l_organization_tab;
4320            CLOSE c_batch_orgs;
4321         END IF; --}
4322 
4323 	IF l_debug_on THEN
4324            WSH_DEBUG_SV.log(l_module_name,  'Number of Organizations',l_organization_tab.count);
4325 	END IF;
4326 	IF l_organization_tab.COUNT = 0 THEN
4327 	   WSH_UTIL_CORE.PrintMsg('No organization found. Cannot Pick Release.');
4328 	   RAISE e_return;
4329 	END IF;
4330   --}
4331   ELSE
4332 	-- Need to initialize the table , when l_organization_id is not NULL
4333         --Cursor get_orgs is not opened.
4334 	l_organization_tab(1) := l_organization_id;
4335 	IF l_debug_on THEN
4336 	   WSH_DEBUG_SV.log(l_module_name,  'Number of Organizations',l_organization_tab.count);
4337 	END IF;
4338   END IF;
4339 
4340   -- 80. Sorting for Distinct records of Organizations
4341   IF l_organization_tab.count > 1 AND l_mode IS NULL THEN --{
4342     IF l_debug_on THEN
4343       WSH_DEBUG_SV.log(l_module_name,'Count is more than 1 : ',l_organization_tab.count);
4344     END IF;
4345     DELETE FROM wsh_tmp;
4346 
4347     FORALL i IN l_organization_tab.FIRST..l_organization_tab.LAST
4348       INSERT INTO wsh_tmp (id) VALUES(l_organization_tab(i));
4349 
4350     OPEN c_distinct_organization_id;
4351     FETCH c_distinct_organization_id BULK COLLECT INTO l_distinct_organization_tab;
4352     CLOSE c_distinct_organization_id;
4353 
4354     IF l_debug_on THEN
4355       WSH_DEBUG_SV.log(l_module_name,'Distinct Count : ',l_distinct_organization_tab.count);
4356       WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4357       WSH_DEBUG_SV.log(l_module_name,'G_NUM_WORKERS ',G_NUM_WORKERS);
4358     END IF;
4359 
4360 
4361     -- Bug 5247554: Force the number of workers to be 1 if the pick slip grouping criteria includes
4362     -- delivery or print pick slip mode is immediate.
4363 
4364     IF l_debug_on THEN
4365        WSH_DEBUG_SV.log(l_module_name,'WSH_PR_CRITERIA.g_pick_grouping_rule_id ',WSH_PR_CRITERIA.g_pick_grouping_rule_id);
4366        WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4367        WSH_DEBUG_SV.log(l_module_name,'G_NUM_WORKERS ',G_NUM_WORKERS);
4368     END IF;
4369     IF WSH_PR_CRITERIA.g_pick_grouping_rule_id IS NOT NULL THEN
4370        OPEN c_is_psgr_del(WSH_PR_CRITERIA.g_pick_grouping_rule_id);
4371        FETCH c_is_psgr_del INTO l_psgr_delivery_flag;
4372        CLOSE c_is_psgr_del;
4373 
4374        IF l_psgr_delivery_flag = 'Y' THEN
4375           G_NUM_WORKERS := 1;
4376           G_PICK_REL_PARALLEL := FALSE;
4377           IF l_debug_on THEN
4378              WSH_DEBUG_SV.log(l_module_name,'l_psgr_delivery_flag',l_psgr_delivery_flag);
4379              WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4380              WSH_DEBUG_SV.log(l_module_name,'G_NUM_WORKERS ',G_NUM_WORKERS);
4381           END IF;
4382        ELSE
4383           OPEN c_is_print_ps_mode_I;
4384           FETCH c_is_print_ps_mode_I INTO l_tmp_org_id;
4385           IF c_is_print_ps_mode_I%FOUND THEN
4386              G_NUM_WORKERS := 1;
4387              G_PICK_REL_PARALLEL := FALSE;
4388           END IF;
4389           CLOSE c_is_print_ps_mode_I;
4390           IF l_debug_on THEN
4391              WSH_DEBUG_SV.log(l_module_name,'l_psgr_delivery_flag',l_psgr_delivery_flag);
4392              WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4393              WSH_DEBUG_SV.log(l_module_name,'G_NUM_WORKERS ',G_NUM_WORKERS);
4394           END IF;
4395        END IF;
4396     ELSE
4397        OPEN c_prnt_PS_mode_PS_grp;
4398        FETCH c_prnt_PS_mode_PS_grp INTO l_tmp_org_id;
4399        IF c_prnt_PS_mode_PS_grp%FOUND THEN
4400           G_NUM_WORKERS := 1;
4401           G_PICK_REL_PARALLEL := FALSE;
4402        END IF;
4403        CLOSE c_prnt_PS_mode_PS_grp;
4404        IF l_debug_on THEN
4405           WSH_DEBUG_SV.log(l_module_name,'l_psgr_delivery_flag',l_psgr_delivery_flag);
4406           WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4407           WSH_DEBUG_SV.log(l_module_name,'G_NUM_WORKERS ',G_NUM_WORKERS);
4408        END IF;
4409     END IF;
4410 
4411     -- END  Bug 5247554.
4412 
4413     DELETE FROM wsh_tmp;
4414 
4415     l_organization_tab.delete;
4416     l_organization_tab := l_distinct_organization_tab;
4417   ELSIF l_organization_tab.count = 1 AND l_mode IS NULL THEN
4418 
4419      -- Bug 5247554: Force the number of workers to be 1 if the pick slip grouping criteria includes
4420      -- delivery or print pick slip mode is immediate.
4421     IF l_debug_on THEN
4422        WSH_DEBUG_SV.log(l_module_name,'WSH_PR_CRITERIA.g_pick_grouping_rule_id ',WSH_PR_CRITERIA.g_pick_grouping_rule_id);
4423        WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4424        WSH_DEBUG_SV.log(l_module_name,'G_NUM_WORKERS ',G_NUM_WORKERS);
4425     END IF;
4426     IF WSH_PR_CRITERIA.g_pick_grouping_rule_id IS NOT NULL THEN
4427        OPEN c_is_psgr_del(WSH_PR_CRITERIA.g_pick_grouping_rule_id);
4428        FETCH c_is_psgr_del INTO l_psgr_delivery_flag;
4429        CLOSE c_is_psgr_del;
4430 
4431        IF l_psgr_delivery_flag = 'Y' THEN
4432           G_NUM_WORKERS := 1;
4433           G_PICK_REL_PARALLEL := FALSE;
4434           IF l_debug_on THEN
4435              WSH_DEBUG_SV.log(l_module_name,'l_psgr_delivery_flag ',l_psgr_delivery_flag);
4436              WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4437              WSH_DEBUG_SV.log(l_module_name,'G_NUM_WORKERS ',G_NUM_WORKERS);
4438           END IF;
4439        ELSE
4440           OPEN c_is_print_ps_mode_I_for_org(l_organization_tab(1));
4441           FETCH c_is_print_ps_mode_I_for_org INTO l_tmp_org_id;
4442           IF c_is_print_ps_mode_I_for_org%FOUND THEN
4443              G_NUM_WORKERS := 1;
4444              G_PICK_REL_PARALLEL := FALSE;
4445           END IF;
4446           CLOSE c_is_print_ps_mode_I_for_org;
4447           IF l_debug_on THEN
4448              WSH_DEBUG_SV.log(l_module_name,'l_psgr_delivery_flag ',l_psgr_delivery_flag);
4449              WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4450              WSH_DEBUG_SV.log(l_module_name,'G_NUM_WORKERS ',G_NUM_WORKERS);
4451           END IF;
4452        END IF;
4453     ELSE
4454        OPEN c_prnt_PS_mode_PS_grp_for_org(l_organization_tab(1));
4455        FETCH c_prnt_PS_mode_PS_grp_for_org INTO l_tmp_org_id;
4456        IF c_prnt_PS_mode_PS_grp_for_org%FOUND THEN
4457           G_NUM_WORKERS := 1;
4458           G_PICK_REL_PARALLEL := FALSE;
4459        END IF;
4460        CLOSE c_prnt_PS_mode_PS_grp_for_org;
4461        IF l_debug_on THEN
4462           WSH_DEBUG_SV.log(l_module_name,'WSH_PR_CRITERIA.g_use_delivery_ps ',WSH_PR_CRITERIA.g_use_delivery_ps);
4463           WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4464           WSH_DEBUG_SV.log(l_module_name,'G_NUM_WORKERS ',G_NUM_WORKERS);
4465        END IF;
4466     END IF;
4467 
4468     -- END  Bug 5247554.
4469 
4470   END IF; --}
4471 
4472   -- 90. Loop through each organization and create a Move Order
4473   --     Header and calculate workers records
4474   l_tot_worker_records := 0; -- total worker records
4475   l_tot_smc_records    := 0; -- total smc worker count
4476   l_tot_dd_records     := 0; -- total details count
4477 
4478   FOR idx in l_organization_tab.FIRST..l_organization_tab.LAST LOOP  --{
4479 
4480       l_organization_id := l_organization_tab(idx);
4481 
4482       -- 90.1 Clear the Global PL/SQL Tables for printers.
4483       WSH_INV_INTEGRATION_GRP.G_PRINTERTAB.delete ;
4484       WSH_INV_INTEGRATION_GRP.G_ORGTAB.delete ;
4485       WSH_INV_INTEGRATION_GRP.G_ORGSUBTAB.delete ;
4486 
4487       IF l_debug_on THEN
4488 	 WSH_DEBUG_SV.logmsg(l_module_name, '********************************************');
4489          WSH_DEBUG_SV.logmsg(l_module_name, 'Processing Org ' || l_organization_id);
4490       END IF;
4491 
4492       IF l_mode IS NULL THEN --{
4493 
4494          -- 90.2 : Reinitialize dd count and worker count for each Organization
4495          l_worker_records := 0; -- worker records for single org
4496          l_smc_records    := 0; -- smc worker count for single org
4497          l_dd_records     := 0; -- details count for single org
4498 
4499 
4500          -- 90.3 Get the Warehouse type.
4501          l_warehouse_type := WSH_EXTERNAL_INTERFACE_SV.Get_Warehouse_Type(
4502             p_organization_id => l_organization_id,
4503             p_event_key => NULL,
4504             x_return_status   => l_return_status);
4505          IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN --{
4506              IF l_debug_on THEN
4507                 WSH_DEBUG_SV.log(l_module_name, 'Org Type', L_WAREHOUSE_TYPE  );
4508              END IF;
4509 
4510              --- TPW - Distributed Organization Changes
4511              --IF l_warehouse_type = 'TPW' THEN
4512              IF l_warehouse_type in ( 'TPW', 'TW2' ) THEN
4513                 IF l_debug_on THEN
4514                    WSH_DEBUG_SV.logmsg(l_module_name,'SKIPPING TPW ORGANIZATION (PICKING IS NOT SUPPORTED)');
4515                 END IF;
4516                 GOTO next_organization;
4517              END IF;
4518          --}
4519          ELSIF (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) OR
4520                (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN --{
4521 
4522                 WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_EXTERNAL_INTERFACE_SV.Get_Warehouse_Type');
4523                 RAISE e_return;
4524 
4525          END IF;  --}
4526 
4527       END IF; --}
4528 
4529       -- 90.4 Getting Organization Parameters
4530       IF l_debug_on THEN
4531          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit GET_ORG_PARAMS',WSH_DEBUG_SV.C_PROC_LEVEL);
4532       END IF;
4533       Get_Org_Params ( p_organization_id => l_organization_id,
4534                        x_org_info        => l_org_info,
4535                        x_return_status   => l_return_status);
4536       IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) OR
4537          (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
4538           IF l_debug_on THEN
4539              WSH_DEBUG_SV.logmsg(l_module_name, 'Error occurred in Get_Org_Params');
4540           END IF;
4541           RAISE e_return;
4542       END IF;
4543 
4544       -- Table of Organizations Related Info
4545       -- This is used in Autocreate Deliveries in Parent Process
4546       l_org_info_tbl(l_organization_id).autocreate_deliveries     := l_org_info.autocreate_deliveries;
4547       l_org_info_tbl(l_organization_id).autodetail_flag           := l_org_info.autodetail_flag;
4548       l_org_info_tbl(l_organization_id).append_flag               := l_org_info.append_flag;
4549       l_org_info_tbl(l_organization_id).print_pick_slip_mode      := l_org_info.print_pick_slip_mode;
4550       l_org_info_tbl(l_organization_id).pick_grouping_rule_id     := l_org_info.pick_grouping_rule_id;
4551       l_org_info_tbl(l_organization_id).doc_set_id                := l_org_info.doc_set_id;
4552       l_org_info_tbl(l_organization_id).use_header_flag           := l_org_info.use_header_flag;
4553       l_org_info_tbl(l_organization_id).auto_apply_routing_rules  := l_org_info.auto_apply_routing_rules;
4554       l_org_info_tbl(l_organization_id).auto_calc_fgt_rate_cr_del := l_org_info.auto_calc_fgt_rate_cr_del;
4555       l_org_info_tbl(l_organization_id).task_planning_flag        := l_org_info.task_planning_flag;
4556       l_org_info_tbl(l_organization_id).express_pick_flag         := l_org_info.express_pick_flag;
4557       l_org_info_tbl(l_organization_id).wms_org                   := l_org_info.wms_org;
4558       --bug# 6689448 (replenishment project)
4559       l_org_info_tbl(l_organization_id).pick_seq_rule_id          := l_org_info.pick_seq_rule_id;
4560 
4561 
4562 
4563       IF l_mode IS NULL THEN --{
4564           -- 90.5 Clear move order header records
4565           l_trohdr_rec     := l_empty_trohdr_rec;
4566           l_trohdr_val_rec := l_empty_trohdr_val_rec;
4567 
4568           -- 90.6 Insert values into record for Create Move Order Header
4569           l_trohdr_rec.created_by       := l_user_id;
4570           l_trohdr_rec.creation_date    := l_date;
4571           l_trohdr_rec.last_updated_by  := l_user_id;
4572           l_trohdr_rec.last_update_date := l_date;
4573           l_trohdr_rec.last_update_login := l_login_id;
4574           l_trohdr_rec.organization_id  := l_organization_id;
4575           l_trohdr_rec.grouping_rule_id := l_org_info.pick_grouping_rule_id;
4576           l_trohdr_rec.move_order_type  := INV_GLOBALS.G_MOVE_ORDER_PICK_WAVE;
4577           l_trohdr_rec.transaction_type_id := NULL;
4578           l_trohdr_rec.operation        := INV_GLOBALS.G_OPR_CREATE;
4579           l_trohdr_rec.header_status    :=  INV_Globals.G_TO_STATUS_PREAPPROVED;
4580           l_trohdr_rec.request_number   := l_batch_name;
4581 
4582           -- 90.7 Create Move Order Header
4583           IF l_debug_on THEN
4584              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit INV_MOVE_ORDER_PUB.CREATE_MOVE_ORDER_HEADER',WSH_DEBUG_SV.C_PROC_LEVEL);
4585              WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4586           END IF;
4587 
4588           Inv_Move_Order_Pub.Create_Move_Order_Header
4589               (
4590                 p_api_version_number => l_api_version_number,
4591                 p_init_msg_list      => FND_API.G_FALSE,
4592                 p_return_values      => FND_API.G_TRUE,
4593                 p_commit             => l_commit,
4594                 p_trohdr_rec         => l_trohdr_rec,
4595                 p_trohdr_val_rec     => l_trohdr_val_rec,
4596                 x_trohdr_rec         => l_trohdr_rec,
4597                 x_trohdr_val_rec     => l_trohdr_val_rec,
4598                 x_return_status      => l_return_status,
4599                 x_msg_count          => l_msg_count,
4600                 x_msg_data           => l_msg_data
4601               );
4602 
4603           IF l_debug_on THEN
4604              WSH_DEBUG_SV.log(l_module_name,'Inv_Move_Order_Pub.Create_Move_Order_Header l_return_status',l_return_status);
4605              WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4606           END IF;
4607 
4608           IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
4609           OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN --{
4610 
4611               WSH_UTIL_CORE.PrintMsg('Error occurred in Inv_Move_Order_Pub.Create_Move_Order_Header');
4612               FOR i in 1..l_msg_count LOOP
4613                   l_message := fnd_msg_pub.get(i,'F');
4614                   l_message := replace(l_message,chr(0),' ');
4615                   WSH_UTIL_CORE.PrintMsg(l_message);
4616               END LOOP;
4617               fnd_msg_pub.delete_msg();
4618               RAISE e_return;
4619           --}
4620           ELSIF (l_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
4621               IF l_debug_on THEN
4622                  WSH_DEBUG_SV.logmsg(l_module_name,  'Created MO Header '||TO_CHAR(L_TROHDR_REC.HEADER_ID)||' Sucessfully'  );
4623               END IF;
4624           END IF;
4625 
4626           -- 90.8 Data should be committed only in case of a concurrent request.
4627           --      Data should not be commited if its ONLINE/From PUBLIC API.
4628           --      In case of Online data is committed from Pick Release form.
4629           IF ( G_CONC_REQ = FND_API.G_TRUE ) THEN
4630 	       IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
4631 		  IF l_debug_on THEN
4632 		     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Process_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
4633 		  END IF;
4634 		  WSH_UTIL_CORE.Process_stops_for_load_tender ( p_reset_flags   => FALSE,
4635 						                x_return_status => l_return_status);
4636 
4637 		  IF l_debug_on THEN
4638 		     WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
4639 		  END IF;
4640                   IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) OR
4641                      (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
4642                       WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_UTIL_CORE.Process_stops_for_load_tender');
4643                       RAISE e_return;
4644                   ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4645                       IF l_completion_status = 'NORMAL' THEN
4646                          l_completion_status := 'WARNING';
4647                       END IF;
4648                   END IF;
4649 	       END IF;
4650                IF l_debug_on THEN
4651                   WSH_DEBUG_SV.logmsg(l_module_name,  'Commiting...');
4652                END IF;
4653                COMMIT; -- commit for move order header creation
4654           END IF;
4655 
4656           -- 90.9 For WMS org with auto pick confirm as 'N', insert 'WMS' rec type in worker table
4657           IF l_org_info.wms_org = 'Y' AND l_org_info.auto_pick_confirm = 'N' THEN --{
4658              BEGIN
4659                INSERT INTO WSH_PR_WORKERS (
4660                  BATCH_ID,
4661                  TYPE,
4662                  MO_HEADER_ID,
4663                  ORGANIZATION_ID,
4664                  PROCESSED)
4665                VALUES (
4666                  p_batch_id,
4667                  'WMS',
4668                  l_trohdr_rec.header_id,
4669                  l_organization_id,
4670                  'N');
4671 
4672              EXCEPTION
4673                WHEN OTHERS THEN
4674                  WSH_UTIL_CORE.PrintMsg('Error occurred in trying to insert WMS rec type in worker table');
4675                  RAISE e_return;
4676              END;
4677           END IF; --}
4678 
4679           -- 90.10 Depending on number of workers call either insert 1 record in
4680           --       worker table or call init_cursor api to insert worker records
4681           -- Bug 5247554: Changed NVL(p_num_workers,1) to NVL(g_num_workers,1) in the below IF.
4682             IF NVL(g_num_workers,1) <= 1 THEN --{
4683                BEGIN
4684                  INSERT INTO WSH_PR_WORKERS (
4685                    BATCH_ID,
4686                    TYPE,
4687                    MO_HEADER_ID,
4688                    MO_START_LINE_NUMBER,
4689                    ORGANIZATION_ID,
4690                    PROCESSED)
4691                  VALUES (
4692                    p_batch_id,
4693                    'PICK',
4694                    l_trohdr_rec.header_id,
4695                    1, -- initialize to 1 for move order line number
4696                    l_organization_id,
4697                    'N');
4698 
4699                  l_tot_worker_records := l_tot_worker_records + 1;
4700                  l_tot_smc_records    := 0;
4701 
4702                EXCEPTION
4703 
4704                  WHEN OTHERS THEN
4705                    WSH_UTIL_CORE.PrintMsg('Error occurred in trying to insert PICK rec type in worker table');
4706                    RAISE e_return;
4707                END; --}
4708 
4709             ELSE --{
4710 
4711                IF l_debug_on THEN
4712                   WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PR_CRITERIA.Init_Cursor',
4713                                                     WSH_DEBUG_SV.C_PROC_LEVEL);
4714                   WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4715                END IF;
4716 
4717                WSH_PR_CRITERIA.Init_Cursor(
4718                  p_organization_id          => l_organization_id,
4719                  p_mode                     => 'SUMMARY', -- insert in worker table
4720                  p_wms_org                  => l_org_info.wms_org,
4721                  p_mo_header_id             => l_trohdr_rec.header_id,
4722                  p_inv_item_id              => NULL,
4723                  p_enforce_ship_set_and_smc => l_org_info.enforce_ship_set_and_smc,
4724                  p_print_flag               => l_print_cursor_flag,
4725                  p_express_pick             => l_org_info.express_pick_flag,
4726                  p_batch_id		    => p_batch_id,
4727                  x_worker_count             => l_worker_records,
4728                  x_smc_worker_count         => l_smc_records,
4729                  x_dd_count                 => l_dd_records,
4730 	         x_api_status               => l_return_status);
4731 
4732                IF l_debug_on THEN
4733 	    	  WSH_DEBUG_SV.log(l_module_name, 'WSH_PR_CRITERIA.Init_Cursor l_return_status',l_return_status);
4734                   WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
4735                END IF;
4736 
4737                IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
4738                   OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
4739                   WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_PR_CRITERIA.Init_Cursor');
4740                   RAISE e_return;
4741                END IF;
4742 
4743                l_tot_worker_records := l_tot_worker_records + NVL(l_worker_records,0);
4744                l_tot_smc_records    := l_tot_smc_records + NVL(l_smc_records,0);
4745                l_tot_dd_records     := l_tot_dd_records + l_dd_records;
4746 
4747             END IF; --}
4748 
4749           -- 90.11 Insert DOC rec type in worker table
4750             BEGIN --{
4751               INSERT INTO WSH_PR_WORKERS (
4752                 BATCH_ID,
4753                 TYPE,
4754                 MO_HEADER_ID,
4755                 ORGANIZATION_ID,
4756                 DETAILED_COUNT,
4757                 PROCESSED)
4758               VALUES (
4759                 p_batch_id,
4760                 'DOC',
4761                 l_trohdr_rec.header_id,
4762                 l_organization_id,
4763                 0,
4764                 'N');
4765 
4766             EXCEPTION
4767               WHEN OTHERS THEN
4768                 WSH_UTIL_CORE.PrintMsg('Error occurred in trying to insert DOC rec type in worker table');
4769                 RAISE e_return;
4770             END; --}
4771 
4772       END IF; -- l_mode is null --}
4773 
4774       -- 940/945 disallow picking of TPW org
4775       <<next_organization>>
4776       NULL;
4777 
4778   END LOOP; -- end of Organization Loop }
4779 
4780   -- For 'PICK-SS' request data, get the number of worker records again
4781   -- so that it can be processed for p_mode as 'PICK'
4782   IF NVL(l_mode,'X') = 'PICK-SS' THEN --{
4783      OPEN  c_tot_worker_records(p_batch_id);
4784      FETCH c_tot_worker_records INTO l_tot_worker_records;
4785      IF    c_tot_worker_records%NOTFOUND THEN
4786            l_tot_worker_records := 0;
4787      END IF;
4788      CLOSE c_tot_worker_records;
4789 
4790      -- Since PICK-SS spawned workers, then set Pick Slip Mode as Parallel
4791      G_PICK_REL_PARALLEL := TRUE;
4792   END IF; --}
4793 
4794   -- Print log messages only if request is not resuming from Regular Pick or Pack/Ship Mode
4795   IF NVL(l_mode,'X') NOT IN ('PICK', 'PS') THEN --{
4796      IF l_debug_on THEN
4797         WSH_DEBUG_SV.log(l_module_name,'l_tot_worker_records ',l_tot_worker_records);
4798         WSH_DEBUG_SV.log(l_module_name,'l_tot_smc_records ',l_tot_smc_records);
4799         WSH_DEBUG_SV.log(l_module_name,'l_tot_dd_records ',l_tot_dd_records);
4800         WSH_DEBUG_SV.log(l_module_name,'Run Ship Sets / SMCs in Parallel ',WSH_CUSTOM_PUB.Run_PR_SMC_SS_Parallel);
4801      END IF;
4802   END IF; --}
4803 
4804   -- 100. Calculate Actual number of worker requests to be spawned
4805   -- For SMCs/Ship Sets not running in Parallel
4806   IF (l_mode is NULL) AND (l_tot_smc_records >= 1) AND (WSH_CUSTOM_PUB.Run_PR_SMC_SS_Parallel = 'N')
4807   THEN --{
4808      -- Number of Child processes
4809      l_num_workers := LEAST(l_tot_smc_records, NVL(g_num_workers,1));
4810 
4811      IF l_num_workers > 1 THEN --{
4812         IF l_debug_on THEN
4813            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Spawn_Workers for PICK-SS', WSH_DEBUG_SV.C_PROC_LEVEL);
4814         END IF;
4815         Spawn_Workers (
4816                         p_batch_id      => p_batch_id,
4817                         p_num_requests  => l_num_workers,
4818                         p_mode          => 'PICK-SS',
4819                         p_req_status    => 0, -- First time Request Status is success (0)
4820                         p_log_level     => p_log_level,
4821                         x_return_status => l_return_status );
4822         IF l_debug_on THEN
4823            WSH_DEBUG_SV.log(l_module_name, 'Spawn_Workers l_return_status',l_return_status);
4824         END IF;
4825         IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
4826         OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
4827             WSH_UTIL_CORE.PrintMsg('Error occurred in Spawn_Workers for PICK-SS');
4828             RAISE e_return;
4829         ELSE
4830             -- This is required as we do not need to process rest of the code till
4831             -- workers complete
4832             GOTO End_Release_Batch;
4833         END IF;
4834         --}
4835      ELSE
4836         -- For Single Worker Mode, call Release_Batch_Sub api directly {
4837         -- If there will be spawning of workers for Regular Items, then set Pick Slip Mode as Parallel
4838         IF LEAST(l_tot_worker_records - l_tot_smc_records, NVL(g_num_workers,1)) > 1 THEN
4839            G_PICK_REL_PARALLEL := TRUE;
4840         END IF;
4841         IF l_debug_on THEN
4842            IF G_PICK_REL_PARALLEL THEN
4843               WSH_DEBUG_SV.logmsg(l_module_name,'Pick Release Mode is Parallel ');
4844            ELSE
4845               WSH_DEBUG_SV.logmsg(l_module_name,'Pick Release Mode is Single Worker Mode ');
4846            END IF;
4847            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Release_Batch_Sub', WSH_DEBUG_SV.C_PROC_LEVEL);
4848         END IF;
4849         l_retcode := NULL;
4850         l_errbuf  := NULL;
4851         Release_Batch_Sub (
4852                          errbuf       => l_errbuf,
4853                          retcode      => l_retcode,
4854                          p_batch_id   => p_batch_id,
4855                          p_worker_id  => NULL,
4856                          p_mode       => 'PICK-SS',
4857                          p_log_level  => p_log_level );
4858         IF l_debug_on THEN
4859            WSH_DEBUG_SV.logmsg(l_module_name, 'Return from Release_Batch_Sub');
4860            WSH_DEBUG_SV.log(l_module_name, 'retcode',l_retcode);
4861            WSH_DEBUG_SV.log(l_module_name, 'errbuf',l_errbuf);
4862         END IF;
4863         IF l_retcode = 2 THEN
4864            WSH_UTIL_CORE.PrintMsg('Error occurred in Release_Batch_Sub');
4865            RAISE e_return;
4866         ELSIF l_retcode = 1 THEN
4867            G_BACKORDERED := TRUE; -- To set the request status as Warning
4868         ELSIF l_retcode IS NULL THEN -- Online Process
4869           IF G_ONLINE_PICK_RELEASE_RESULT = 'W' THEN
4870             G_BACKORDERED := TRUE; -- To set the request status as Warning
4871           ELSIF G_ONLINE_PICK_RELEASE_RESULT = 'F' THEN
4872             WSH_UTIL_CORE.PrintMsg('Error in Online Release_batch_sub');
4873             RAISE e_return;
4874           END IF;
4875         END IF;
4876      END IF; --}
4877   END IF; --}
4878 
4879   -- For all Regular Items and Ship Sets/SMCs in Parallel
4880   IF ((l_mode is NULL) OR (l_mode = 'PICK-SS')) AND (l_tot_worker_records >= 1) THEN
4881   --{
4882      IF l_mode IS NULL AND (WSH_CUSTOM_PUB.Run_PR_SMC_SS_Parallel = 'N')
4883      THEN
4884         l_tot_worker_records := l_tot_worker_records - NVL(l_tot_smc_records,0);
4885      END IF;
4886 
4887      -- Number of Child processes
4888      l_num_workers := LEAST(l_tot_worker_records, NVL(g_num_workers,1));
4889 
4890      IF l_num_workers > 1 THEN --{
4891         -- 100.2 Spawn requests for all Items
4892         IF l_debug_on THEN
4893            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Spawn_Workers for PICK', WSH_DEBUG_SV.C_PROC_LEVEL);
4894         END IF;
4895         Spawn_Workers (
4896                         p_batch_id      => p_batch_id,
4897                         p_num_requests  => l_num_workers,
4898                         p_mode          => 'PICK',
4899                         p_req_status    => NVL(l_retcode,0), -- Current Request Status
4900                         p_log_level     => p_log_level,
4901                         x_return_status => l_return_status );
4902         IF l_debug_on THEN
4903            WSH_DEBUG_SV.log(l_module_name, 'Spawn_Workers l_return_status',l_return_status);
4904         END IF;
4905         IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
4906         OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
4907             WSH_UTIL_CORE.PrintMsg('Error occurred in Spawn_Workers for PICK');
4908             RAISE e_return;
4909         ELSE
4910             -- This is required as we do not need to process rest of the code till
4911             -- workers complete
4912             GOTO End_Release_Batch;
4913         END IF;
4914       --}
4915       ELSIF l_num_workers = 1 THEN
4916         -- For Single Worker Mode, call Release_Batch_Sub api directly {
4917         IF l_debug_on THEN
4918            IF G_PICK_REL_PARALLEL THEN
4919               WSH_DEBUG_SV.logmsg(l_module_name,'Pick Release Mode is Parallel ');
4920            ELSE
4921               WSH_DEBUG_SV.logmsg(l_module_name,'Pick Release Mode is Single Worker Mode ');
4922            END IF;
4923            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Release_Batch_Sub', WSH_DEBUG_SV.C_PROC_LEVEL);
4924         END IF;
4925         l_retcode := NULL;
4926         l_errbuf  := NULL;
4927         Release_Batch_Sub (
4928                          errbuf       => l_errbuf,
4929                          retcode      => l_retcode,
4930                          p_batch_id   => p_batch_id,
4931                          p_worker_id  => NULL,
4932                          p_mode       => 'PICK',
4933                          p_log_level  => p_log_level );
4934         IF l_debug_on THEN
4935            WSH_DEBUG_SV.logmsg(l_module_name, 'Return from Release_Batch_Sub');
4936            WSH_DEBUG_SV.log(l_module_name, 'retcode',l_retcode);
4937            WSH_DEBUG_SV.log(l_module_name, 'errbuf',l_errbuf);
4938         END IF;
4939         IF l_retcode = 2 THEN
4940            WSH_UTIL_CORE.PrintMsg('Error occurred in Release_Batch_Sub');
4941            RAISE e_return;
4942         ELSIF l_retcode = 1 THEN
4943            G_BACKORDERED := TRUE; -- To set the request status as Warning
4944         ELSIF l_retcode IS NULL THEN -- Online Process
4945           IF G_ONLINE_PICK_RELEASE_RESULT = 'W' THEN
4946             G_BACKORDERED := TRUE; -- To set the request status as Warning
4947           ELSIF G_ONLINE_PICK_RELEASE_RESULT = 'F' THEN
4948             WSH_UTIL_CORE.PrintMsg('Error in Online Release_batch_sub');
4949             RAISE e_return;
4950           END IF;
4951         END IF;
4952       END IF; --}
4953   END IF; --}
4954 
4955   IF (l_mode IS NULL OR l_mode IN ('PICK-SS','PICK','OPA','TTA','LABEL'))  --WMS High Vol Support, Added modes OPA, TTA and LABEL
4956   AND (l_completion_status <> 'ERROR') THEN --{
4957 
4958      --Bug 5137504 Handling if Batch size is set to value less than 1 or is aphanumeric
4959      BEGIN
4960      l_pr_batch_size := TO_NUMBER(FND_PROFILE.VALUE('WSH_PICK_RELEASE_BATCH_SIZE'));
4961      IF l_pr_batch_size IS NULL OR l_pr_batch_size < 1 THEN
4962         l_pr_batch_size := 50;
4963      ELSIF l_pr_batch_size > 1000 THEN
4964         l_pr_batch_size := 1000;
4965      END IF;
4966      l_pr_batch_size := ROUND(l_pr_batch_size);
4967      EXCEPTION
4968      WHEN value_error THEN
4969      l_pr_batch_size :=50;
4970      WHEN INVALID_NUMBER THEN
4971      l_pr_batch_size :=50;
4972      END;
4973 
4974      IF l_debug_on THEN
4975         WSH_DEBUG_SV.log(l_module_name,'l_pr_batch_size ',l_pr_batch_size);
4976      END IF;
4977 
4978      IF l_mode IN ('PICK-SS','PICK') THEN --{
4979         -- Unassign Backordered details from Delivery/Container
4980         l_detail_pfetch := 0;
4981         l_detail_cfetch := 0;
4982         l_errors    := 0;
4983         OPEN c_get_backordered_details(p_batch_id);
4984         LOOP --{
4985           FETCH c_get_backordered_details BULK COLLECT INTO l_backorder_rec_tbl LIMIT l_pr_batch_size;
4986           l_detail_cfetch := c_get_backordered_details%ROWCOUNT - l_detail_pfetch;
4987           EXIT WHEN (l_detail_cfetch = 0);
4988           IF l_debug_on THEN
4989              WSH_DEBUG_SV.log(l_module_name,'Number of backordered lines ',l_backorder_rec_tbl.COUNT);
4990              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_USA_INV_PVT.Unassign_Backordered_Details',WSH_DEBUG_SV.C_PROC_LEVEL);
4991           END IF;
4992           WSH_USA_INV_PVT.Unassign_Backordered_Details(
4993                                                         p_backorder_rec_tbl => l_backorder_rec_tbl,
4994                                                         p_org_info_tbl      => l_org_info_tbl,
4995                                                         x_return_status     => l_return_status);
4996           IF l_debug_on THEN
4997              WSH_DEBUG_SV.log(l_module_name,'WSH_USA_INV_PVT.Unassign_Backordered_Details l_return_status' ,l_return_status);
4998           END IF;
4999           IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
5000              WSH_UTIL_CORE.PrintMsg('Unexpected Error occurred in WSH_USA_INV_PVT.Unassign_Backordered_Details');
5001              RAISE e_return;
5002           ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
5003              l_errors := l_errors + 1;
5004           END IF;
5005           l_detail_pfetch := c_get_backordered_details%ROWCOUNT;
5006           IF ( G_CONC_REQ = FND_API.G_TRUE ) THEN
5007                IF l_debug_on THEN
5008                   WSH_DEBUG_SV.logmsg(l_module_name,  'Commiting...');
5009                END IF;
5010                COMMIT;
5011           END IF;
5012         END LOOP; --}
5013         CLOSE c_get_backordered_details;
5014 
5015         -- If there are any Errors encountered, stop processing immediately
5016         IF l_errors > 0 THEN
5017            WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_USA_INV_PVT.Unassign_Backordered_Details');
5018            RAISE e_return;
5019         END IF;
5020      END IF; --}
5021 
5022      -- Unassign empty containers for deliveries that are unassigned during backodering
5023      IF g_unassigned_delivery_ids.COUNT > 0 AND (l_mode IS NULL OR l_mode IN ('PICK-SS','PICK')) THEN --WMS High Vol Support, Added AND cond
5024         IF l_debug_on THEN
5025            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_AUTOCREATE.unassign_empty_containers',WSH_DEBUG_SV.C_PROC_LEVEL);
5026         END IF;
5027         WSH_DELIVERY_AUTOCREATE.Unassign_Empty_Containers(g_unassigned_delivery_ids,l_return_status);
5028         IF l_debug_on THEN
5029            WSH_DEBUG_SV.log(l_module_name,'WSH_DELIVERY_AUTOCREATE.unassign_empty_containers l_return_status',l_return_status);
5030         END IF;
5031         IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
5032             l_completion_status := 'WARNING';
5033         END IF;
5034      END IF;
5035 
5036      -- Autocreate Deliveries only if G_NUM_WORKERS > 1
5037      -- Otherwise it would have been done before Allocation in Release_Batch_Sub
5038      IF WSH_PICK_LIST.G_NUM_WORKERS > 1 THEN --{
5039       IF l_mode IS NULL OR l_mode IN ('PICK-SS','PICK') THEN --{   --WMS High Vol Support, Added IF condition
5040         -- Call Autocreate Deliveries for the Batch
5041         -- Loop thru all Organization - Details that are not assigned to any deliveries
5042         IF l_debug_on THEN
5043            WSH_DEBUG_SV.logmsg(l_module_name,  '==================='  );
5044            WSH_DEBUG_SV.logmsg(l_module_name,  'AUTOCREATE DELIVERY'  );
5045            WSH_DEBUG_SV.logmsg(l_module_name,  '==================='  );
5046            WSH_DEBUG_SV.logmsg(l_module_name,'Trip '||WSH_PR_CRITERIA.g_trip_id||
5047                                              ' Del '||WSH_PR_CRITERIA.g_delivery_id);
5048            WSH_DEBUG_SV.logmsg(l_module_name,'Del Pick Slip Grouping '||WSH_PR_CRITERIA.g_use_delivery_ps);
5049         END IF;
5050 
5051         FOR crec in c_batch_orgs(p_batch_id) LOOP --{
5052 
5053             IF l_debug_on THEN
5054                WSH_DEBUG_SV.logmsg(l_module_name,'Org '||crec.organization_id||' Auto Create Del Flag '
5055                                   ||l_org_info_tbl(crec.organization_id).autocreate_deliveries
5056                                   ||' Pick Slip Mode '||l_org_info_tbl(crec.organization_id).print_pick_slip_mode);
5057             END IF;
5058             -- Create deliveries only if Pick Slip Mode is 'End' and Delivery is not Part of Grouping
5059             -- Rule and Autocreate deliveries is Yes.
5060             IF l_org_info_tbl(crec.organization_id).autocreate_deliveries = 'Y'
5061             AND WSH_PR_CRITERIA.g_trip_id = 0 AND WSH_PR_CRITERIA.g_delivery_id = 0
5062             AND WSH_PR_CRITERIA.g_use_delivery_ps = 'N'
5063             AND l_org_info_tbl(crec.organization_id).print_pick_slip_mode = 'E' THEN --{
5064                l_del_details_tbl.delete;
5065                l_detail_pfetch := 0;
5066                l_detail_cfetch := 0;
5067                OPEN c_get_unassigned_details(p_batch_id, crec.organization_id);
5068                LOOP --{
5069                   FETCH c_get_unassigned_details BULK COLLECT INTO l_del_details_tbl LIMIT l_pr_batch_size;
5070                   l_detail_cfetch := c_get_unassigned_details%ROWCOUNT - l_detail_pfetch;
5071                   EXIT WHEN (l_detail_cfetch = 0);
5072                   IF l_debug_on THEN
5073                      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PICK_LIST.Autocreate_Deliveries'
5074                                                          ,WSH_DEBUG_SV.C_PROC_LEVEL);
5075                      WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
5076                   END IF;
5077                   Autocreate_Deliveries (
5078                                           p_append_flag       => l_org_info_tbl(crec.organization_id).append_flag,
5079                                           p_use_header_flag   => l_org_info_tbl(crec.organization_id).use_header_flag,
5080                                           p_del_details_tbl   => l_del_details_tbl,
5081                                           x_return_status     => l_return_status
5082                                         );
5083                   IF l_debug_on THEN
5084                      WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
5085                      WSH_DEBUG_SV.log(l_module_name,'WSH_PICK_LIST.Autocreate_Deliveries l_return_status'
5086                                                      ,l_return_status);
5087                   END IF;
5088                   IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
5089                   OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
5090                       WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_PICK_LIST.Autocreate_Deliveries');
5091                       RAISE e_return;
5092                   END IF;
5093                   -- bug # 8915460 : When pick release is performed by specifying deliery detail id/containerDDId
5094                   --                 then auto create delivery can be performed only once because
5095                   --                 i) all details are assigned to same container(incase of containerDD as a parameter).
5096                   --                 ii) Single delivery detail id incase deliveydetailid as a parameter
5097                   EXIT WHEN (NVL(WSH_PR_CRITERIA.g_del_detail_id,0) = -2);
5098 
5099                   l_detail_pfetch := c_get_unassigned_details%ROWCOUNT;
5100 
5101                END LOOP; --}
5102                CLOSE c_get_unassigned_details;
5103             END IF; --}
5104         END LOOP; --}
5105       END IF; --}  --WMS High Vol Support
5106      END IF; --}
5107 
5108      -- Code for Carrier Selections needs to be added here ...
5109     IF l_mode IS NULL OR l_mode IN ('PICK-SS','PICK') THEN --{  --WMS High Vol Support, Added IF cond
5110      IF (p_batch_id is not null) THEN --{
5111         -- Check the shipping parameter for "auto select carrier", if this is
5112         -- on then FTE must be installed and carrier selction is requested
5113         i := l_org_info_tbl.FIRST;
5114         WHILE i IS NOT NULL LOOP --{
5115            IF NVL(l_org_info_tbl(i).AUTO_APPLY_ROUTING_RULES, 'N') = 'D' THEN --{
5116               -- Oh Yeah!! Carrier selection is a go - lets rock and roll!
5117               -- Call the Carrier Selection Processing Procedure with the batch id
5118               --
5119               -- make sure the table is empty
5120               --
5121               l_del_ids_tab.DELETE;
5122               IF l_debug_on THEN
5123                  WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_NEW_DELIVERY_ACTIONS.PROCESS_CARRIER_SELECTION',WSH_DEBUG_SV.C_PROC_LEVEL);
5124               END IF;
5125               WSH_NEW_DELIVERY_ACTIONS.PROCESS_CARRIER_SELECTION (
5126                                                                    p_delivery_id_tab => l_del_ids_tab,
5127                                                                    p_batch_id        => p_batch_id,
5128                                                                    p_form_flag       => 'N',
5129                                                                    p_caller          => 'WSH_PICK_RELEASE',
5130                                                                    p_organization_id => i, -- Organization_id
5131                                                                    x_return_message  => l_message,
5132                                                                    x_return_status   => l_return_status );
5133               IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
5134                  IF l_debug_on THEN
5135                     WSH_DEBUG_SV.logmsg(l_module_name,  'ERROR OR WARNING OCCURRED WHILE PROCESSING CARRIER SELECTION ( PICK SLIP ) '  );
5136                  END IF;
5137               END IF;
5138               WSH_UTIL_CORE.add_message(l_return_status);
5139            --}
5140            END IF;
5141 
5142            -- Bug 3714834: If there are more lines to be picked than the pick release batch size
5143            -- we autocreate del for the first batch and then keep assigning the consequent lines.
5144            -- So we need to rate the delivery after all the lines have been picked, not during auto
5145            -- creation of delivery.
5146            IF l_org_info_tbl(i).auto_calc_fgt_rate_cr_del = 'Y' THEN --{
5147               OPEN  c_dels_in_batch (p_batch_id , i);
5148               FETCH c_dels_in_batch BULK COLLECT into l_rate_dels_tab;
5149               CLOSE c_dels_in_batch;
5150 
5151               IF l_rate_dels_tab.count > 0 THEN --{
5152                  l_in_param_rec.delivery_id_list := l_rate_dels_tab;
5153                  l_in_param_rec.action := 'RATE';
5154                  l_in_param_rec.seq_tender_flag := 'Y';
5155 
5156                  IF l_debug_on THEN
5157                     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_FTE_INTEGRATION.Rate_Delivery',WSH_DEBUG_SV.C_PROC_LEVEL);
5158                  END IF;
5159                  WSH_FTE_INTEGRATION.Rate_Delivery (
5160                                                      p_api_version      => 1.0,
5161                                                      p_init_msg_list    => FND_API.G_FALSE,
5162                                                      p_commit           => FND_API.G_FALSE,
5163                                                      p_in_param_rec     => l_in_param_rec,
5164                                                      x_out_param_rec    => l_out_param_rec,
5165                                                      x_return_status    => l_return_status,
5166                                                      x_msg_count        => l_msg_count,
5167                                                      x_msg_data         => l_msg_data );
5168                  IF l_debug_on THEN
5169                     WSH_DEBUG_SV.log(l_module_name,'Return Status from WSH_FTE_INTEGRATION.Rate_Delivery',l_return_status);
5170                  END IF;
5171                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN --{
5172                     IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
5173                        WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_FTE_INTEGRATION.Rate_Delivery');
5174                        RAISE e_return;
5175                     ELSE
5176                        j := l_out_param_rec.failed_delivery_id_list.FIRST;
5177                        WHILE j is not NULL LOOP
5178                          OPEN c_get_location(l_out_param_rec.failed_delivery_id_list(j));
5179                          FETCH c_get_location INTO l_excp_location_id;
5180                          CLOSE c_get_location;
5181                          FND_MESSAGE.SET_NAME('WSH', 'WSH_RATE_CREATE_DEL');
5182                          FND_MESSAGE.SET_TOKEN('DELIVERY_ID',to_char(l_out_param_rec.failed_delivery_id_list(j)));
5183                          l_message := FND_MESSAGE.Get;
5184                          l_dummy_exception_id := NULL;
5185                          wsh_xc_util.log_exception(
5186                             p_api_version           => 1.0,
5187                             x_return_status         => l_return_status,
5188                             x_msg_count             => l_exception_msg_count,
5189                             x_msg_data              => l_exception_msg_data,
5190                             x_exception_id          => l_dummy_exception_id,
5191                             p_exception_location_id => l_excp_location_id,
5192                             p_logged_at_location_id => l_excp_location_id,
5193                             p_logging_entity        => 'SHIPPER',
5194                             p_logging_entity_id     => FND_GLOBAL.USER_ID,
5195                             p_exception_name        => 'WSH_RATE_CREATE_DEL',
5196                             p_message               => substrb(l_message,1,2000),
5197                             p_delivery_id           => l_out_param_rec.failed_delivery_id_list(j),
5198                             p_batch_id              => p_batch_id,
5199                             p_request_id            => fnd_global.conc_request_id );
5200                          j := l_out_param_rec.failed_delivery_id_list.NEXT(j);
5201                        END LOOP;
5202                     END IF;
5203                  END IF; --}
5204               END IF; --}
5205            END IF; --}
5206            i := l_org_info_tbl.NEXT(i);
5207         END LOOP; --}
5208        END IF; --}  --WMS High Vol Support
5209      END IF; --}
5210 
5211      -- Delivery Merge For Pre-existing / Appended Deliveries
5212      IF g_assigned_del_tbl.COUNT > 0 AND (l_mode IS NULL OR l_mode IN ('PICK-SS','PICK')) THEN --{ --WMS High Vol Support, Added AND cond
5213         IF l_debug_on THEN
5214            WSH_DEBUG_SV.log(l_module_name,'g_assigned_del_tbl.COUNT', g_assigned_del_tbl.COUNT);
5215            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_NEW_DELIVERY_ACTIONS.Adjust_Planned_Flag',WSH_DEBUG_SV.C_PROC_LEVEL);
5216         END IF;
5217         WSH_NEW_DELIVERY_ACTIONS.Adjust_Planned_Flag (
5218                                                        p_delivery_ids          => g_assigned_del_tbl,
5219                                                        p_caller                => 'WSH_DLMG',
5220                                                        p_force_appending_limit => 'N',
5221                                                        p_call_lcss             => 'Y',
5222                                                        x_return_status         => l_return_status );
5223         IF l_debug_on THEN
5224            WSH_DEBUG_SV.log(l_module_name,'Adjust_Planned_Flag returns ',l_return_status);
5225         END IF;
5226         IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR
5227         OR l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
5228            WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_NEW_DELIVERY_ACTIONS.Adjust_Planned_Flag');
5229            RAISE e_Return;
5230         END IF;
5231      END IF; --}
5232 
5233      -- Get all New Deliveries for Delivery Merge
5234     IF l_mode IS NULL OR l_mode IN ('PICK-SS','PICK') THEN --{  --WMS High Vol Support, Added IF cond
5235      l_detail_cfetch := 0;
5236      l_detail_pfetch := 0;
5237      OPEN c_batch_unplanned_del(p_batch_id); --{
5238      LOOP
5239         FETCH c_batch_unplanned_del BULK COLLECT INTO l_delivery_ids LIMIT l_pr_batch_size;
5240         l_detail_cfetch := c_batch_unplanned_del%ROWCOUNT - l_detail_pfetch;
5241         EXIT WHEN (l_detail_cfetch = 0);
5242         IF l_debug_on THEN
5243            WSH_DEBUG_SV.log(l_module_name,'l_delivery_ids.COUNT', l_delivery_ids.COUNT);
5244            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_NEW_DELIVERY_ACTIONS.Adjust_Planned_Flag',WSH_DEBUG_SV.C_PROC_LEVEL);
5245         END IF;
5246         WSH_NEW_DELIVERY_ACTIONS.Adjust_Planned_Flag (
5247                                                         p_delivery_ids          => l_delivery_ids,
5248                                                         p_caller                => 'WSH_DLMG',
5249                                                         p_force_appending_limit => 'N',
5250                                                         p_call_lcss             => 'Y',
5251                                                         x_return_status         => l_return_status );
5252         IF l_debug_on THEN
5253            WSH_DEBUG_SV.log(l_module_name,'Adjust_Planned_Flag returns ',l_return_status);
5254         END IF;
5255         IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR
5256         OR l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
5257            WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_NEW_DELIVERY_ACTIONS.Adjust_Planned_Flag');
5258            RAISE e_Return;
5259         END IF;
5260         l_detail_pfetch := c_batch_unplanned_del%ROWCOUNT;
5261      END LOOP; --}
5262     END IF; --}  --WMS High Vol Support
5263 
5264      IF ( G_CONC_REQ = FND_API.G_TRUE ) THEN
5265           IF l_debug_on THEN
5266              WSH_DEBUG_SV.logmsg(l_module_name,  'Commiting...');
5267           END IF;
5268           COMMIT;
5269      END IF;
5270 
5271      -- WMS Cartonization is done only if p_num_workers in Release_Batch is > 1
5272      IF ( WSH_PICK_LIST.G_NUM_WORKERS > 1 )
5273      -- X-dock
5274      -- Need to add check to ensure delivery detail is not X-docked
5275      -- either MOL is null or MOL is not null and move order type = PUTAWAY
5276      AND g_allocation_method IN (WSH_PICK_LIST.C_INVENTORY_ONLY,
5277                               WSH_PICK_LIST.C_PRIORITIZE_CROSSDOCK,
5278                               WSH_PICK_LIST.C_PRIORITIZE_INVENTORY) THEN
5279         --{
5280        IF l_mode IN ('PICK-SS','PICK') THEN --{  --WMS High Vol Support, Added IF cond
5281         FOR crec IN c_wms_orgs(p_batch_id) LOOP --{
5282            IF l_org_info_tbl(crec.organization_id).auto_pick_confirm = 'Y' THEN
5283               IF l_debug_on THEN
5284                  WSH_DEBUG_SV.logmsg(l_module_name,'Skipping Cartonization as Auto Pick Confirm is Yes for Org :'||crec.organization_id);
5285               END IF;
5286               GOTO SKIP_WMS_ORG;
5287            END IF;
5288            l_del_details_tbl.delete;
5289            l_mo_lines_tbl.delete;
5290            l_carton_grouping_tbl.delete;
5291            -- X-dock changes to only select Rel. to warehouse lines from Inventory
5292            OPEN c_wms_details(p_batch_id, crec.organization_id, crec.mo_header_id);
5293            --LOOP --{   --WMS High Vol Support, Commented
5294               FETCH c_wms_details BULK COLLECT INTO l_del_details_tbl, l_mo_lines_tbl;  --LIMIT l_pr_batch_size;   --WMS High Vol Support, Removed LIMIT
5295               --l_detail_cfetch := c_wms_details%ROWCOUNT - l_detail_pfetch;  --WMS High Vol Support, Commented
5296               --EXIT WHEN (l_detail_cfetch = 0);  --WMS High Vol Support, Commented
5297               CLOSE c_wms_details;  --WMS High Vol Support
5298               -- Generate Carton Grouping Ids
5299               l_attr_tab.delete;
5300               FOR i in 1.. l_del_details_tbl.COUNT LOOP
5301                   l_attr_tab(i).entity_id   := l_del_details_tbl(i);
5302                   l_attr_tab(i).entity_type := 'DELIVERY_DETAIL';
5303               END LOOP;
5304               l_action_rec.action := 'MATCH_GROUPS';
5305 	      l_action_rec.group_by_header_flag := l_org_info_tbl(crec.organization_id).use_header_flag ; --bug 8623544
5306 
5307               IF l_debug_on THEN
5308                  WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_AUTOCREATE.Find_Matching_Groups'
5309                                                       ,WSH_DEBUG_SV.C_PROC_LEVEL);
5310                  WSH_DEBUG_SV.log(l_module_name,'l_attr_tab.COUNT ',l_attr_tab.COUNT);
5311                  WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
5312               END IF;
5313               WSH_DELIVERY_AUTOCREATE.Find_Matching_Groups (
5314                                                               p_attr_tab         => l_attr_tab,
5315                                                               p_action_rec       => l_action_rec,
5316                                                               p_target_rec       => l_target_rec,
5317                                                               p_group_tab        => l_group_tab,
5318                                                               x_matched_entities => l_matched_entities,
5319                                                               x_out_rec          => l_out_rec,
5320                                                               x_return_status    => l_return_status );
5321               IF l_debug_on THEN
5322                  WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
5323                  WSH_DEBUG_SV.log(l_module_name,'WSH_DELIVERY_AUTOCREATE.Find_Matching_Groups l_return_status'
5324                                                ,l_return_status);
5325               END IF;
5326               IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
5327               OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
5328                   WSH_UTIL_CORE.PrintMsg('Error occurred in WSH_DELIVERY_AUTOCREATE.Find_Matching_Groups');
5329                   RAISE e_return;
5330               END IF;
5331 
5332              --bug 7171766
5333               l_group_match_seq_tbl.delete;
5334 
5335               FOR i in 1.. l_attr_tab.count LOOP
5336               --{
5337                   l_match_found :=FALSE;
5338                   IF l_group_match_seq_tbl.count > 0 THEN
5339                   --{
5340                       FOR k in l_group_match_seq_tbl.FIRST..l_group_match_seq_tbl.LAST LOOP
5341 	              --{
5342                           IF l_attr_tab(i).group_id = l_group_match_seq_tbl(k).match_group_id THEN
5343                           --{
5344                               l_group_match_seq_tbl(i).delivery_group_id := l_group_match_seq_tbl(k).delivery_group_id ;
5345 			      l_match_found := TRUE;
5346 		              EXIT;
5347 	                  --}
5348                           End IF;
5349 		      --}
5350 		      END LOOP;
5351 	          --}
5352 		 END IF ;
5353 
5354 		 IF NOT l_match_found THEN
5355 		 --{
5356 	             l_group_match_seq_tbl(i).match_group_id :=l_attr_tab(i).group_id;
5357 	             select WSH_DELIVERY_GROUP_S.nextval into l_group_match_seq_tbl(i).delivery_group_id  from dual;
5358                  --}
5359 	         End IF;
5360 
5361 	         l_carton_grouping_tbl(l_carton_grouping_tbl.COUNT+1) := l_group_match_seq_tbl(i).delivery_group_id;
5362               --}
5363 	      END LOOP;
5364              --bug 7171766 till here
5365 
5366               IF l_debug_on THEN
5367                  WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit INV_MOVE_ORDER_PUB.Stamp_Cart_Id'
5368                                                       ,WSH_DEBUG_SV.C_PROC_LEVEL);
5369                  WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
5370               END IF;
5371               INV_MOVE_ORDER_PUB.Stamp_Cart_Id (
5372                                                  p_validation_level    => FND_API.G_VALID_LEVEL_FULL,
5373                                                  p_carton_grouping_tbl => l_carton_grouping_tbl,
5374                                                  p_move_order_line_tbl => l_mo_lines_tbl );
5375               IF l_debug_on THEN
5376                  WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
5377                  WSH_DEBUG_SV.logmsg(l_module_name,'Return from program unit INV_MOVE_ORDER_PUB.Stamp_Cart_Id');
5378               END IF;
5379 
5380            <<SKIP_WMS_ORG>>
5381            NULL;
5382 
5383         END LOOP; --}
5384      END IF; --}
5385 
5386      --WMS High Vol Support Starts
5387      IF l_mode IN ('PICK-SS','PICK','OPA','TTA','LABEL') THEN --{
5388            LOOP --{
5389               OPEN c_wms_orgs(p_batch_id);
5390               FETCH c_wms_orgs INTO v_wms_org_rec;
5391               EXIT WHEN c_wms_orgs%NOTFOUND;
5392               CLOSE c_wms_orgs;
5393 
5394               l_org_complete := 'Y';
5395               IF l_org_info_tbl(v_wms_org_rec.organization_id).auto_pick_confirm = 'Y' THEN
5396                  IF l_debug_on THEN
5397                     WSH_DEBUG_SV.logmsg(l_module_name,'Skipping Find_Matching_Groups as Auto Pick Confirm is Yes for Org :'||v_wms_org_rec.organization_id);
5398                  END IF;
5399                  GOTO SKIP_WMS_POSTALLOC;
5400               END IF;
5401 
5402               -- Call to WMS Cartonize API
5403               IF l_debug_on THEN
5404                  WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WMS_POST_ALLOCATION.launch'
5405                                     ,WSH_DEBUG_SV.C_PROC_LEVEL);
5406                  WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
5407               END IF;
5408               WMS_POST_ALLOCATION.launch (
5409                                p_organization_id      => v_wms_org_rec.organization_id,
5410                                p_mo_header_id         => v_wms_org_rec.mo_header_id,
5411                                p_batch_id             => p_batch_id,
5412                                p_num_workers          => WSH_PICK_LIST.G_NUM_WORKERS,
5413                                p_auto_pick_confirm    => l_org_info_tbl(v_wms_org_rec.organization_id).auto_pick_confirm,
5414                                p_wsh_status           => NVL(l_retcode,0), -- Current Request Status
5415                                p_wsh_mode             => l_mode,
5416                                p_grouping_rule_id     => l_org_info_tbl(v_wms_org_rec.organization_id).pick_grouping_rule_id,
5417                                p_allow_partial_pick   => FND_API.G_TRUE,
5418                                p_plan_tasks           => l_org_info_tbl(l_organization_id).task_planning_flag,
5419                                x_return_status        => l_return_status,
5420                                x_org_complete         => l_org_complete);
5421               IF l_debug_on THEN
5422                  WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
5423                  WSH_DEBUG_SV.log(l_module_name,'Return status from WMS_POST_ALLOCATION.launch ', l_return_status);
5424               END IF;
5425               IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
5426               OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
5427                   WSH_UTIL_CORE.PrintMsg('Error occurred in WMS_POST_ALLOCATION.launch');
5428                   RAISE e_return;
5429               END IF;
5430 
5431               <<SKIP_WMS_POSTALLOC>>
5432               IF NVL(l_org_complete,'Y') = 'Y' THEN
5433                  UPDATE wsh_pr_workers
5434                     SET processed = 'Y'
5435                   WHERE batch_id = p_batch_id
5436                     AND organization_id = v_wms_org_rec.organization_id
5437                     AND type = 'WMS';
5438 
5439 		 l_mode := 'PICK'; --WMS High Vol Support
5440                  COMMIT;
5441               ELSE
5442                  -- WMS post-allocation API spawned child requests, so the parent request
5443                  -- is being PAUSED.
5444                  GOTO End_Release_Batch;
5445               END IF;
5446            END LOOP; --}
5447            IF c_wms_orgs%ISOPEN THEN
5448               CLOSE c_wms_orgs;
5449            END IF;
5450            -- Restore mode after all WMS post-allocation processing is completed
5451            IF l_mode IN ('OPA','TTA','LABEL') THEN
5452               l_mode := 'PICK';
5453            END IF;
5454         END IF; --}
5455      END IF; --}
5456      --WMS High Vol Support Ends
5457 
5458      -- Print Pick Slips / Pick Release Document Set
5459      FOR crec in c_sum_worker(p_batch_id) LOOP --{
5460         IF l_debug_on THEN
5461            WSH_DEBUG_SV.logmsg(l_module_name,'Printing Documents for Organization '||crec.organization_id);
5462            WSH_DEBUG_SV.logmsg(l_module_name,  'TOTAL DETAILED COUNT IS '||crec.tot_detailed);
5463            WSH_DEBUG_SV.logmsg(l_module_name,  'Seeded Pick Slip Document Set '||WSH_PICK_LIST.G_SEED_DOC_SET);
5464            WSH_DEBUG_SV.logmsg(l_module_name,  'Pick Release Document Set '||l_org_info_tbl(crec.organization_id).doc_set_id);
5465         END IF;
5466         l_print_ps := 'N';
5467         IF crec.tot_detailed > 0 AND WSH_PICK_LIST.G_SEED_DOC_SET IS NOT NULL AND
5468            l_org_info_tbl(crec.organization_id).express_pick_flag = 'N' AND
5469            l_org_info_tbl(crec.organization_id).autodetail_flag = 'Y' THEN
5470                l_print_ps := 'Y';
5471         END IF;
5472         IF (l_print_ps = 'Y') OR (l_org_info_tbl(crec.organization_id).doc_set_id <> -1) THEN
5473            IF l_debug_on THEN
5474               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PICK_LIST.Print_Docs'
5475                                                ,WSH_DEBUG_SV.C_PROC_LEVEL);
5476            END IF;
5477            Print_docs (
5478                         p_batch_id         => p_batch_id,
5479                         p_organization_id  => crec.organization_id,
5480                         p_print_ps         => l_print_ps,
5481                         p_ps_mode          => l_org_info_tbl(crec.organization_id).print_pick_slip_mode,
5482                         p_doc_set_id       => l_org_info_tbl(crec.organization_id).doc_set_id,
5483                         p_batch_name       => l_batch_name,
5484                         p_order_number     => NULL, -- this will be derived in Print_Docs API itself
5485                         x_return_status    => l_return_status );
5486            IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR, WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
5487              l_completion_status := 'WARNING';
5488            END IF;
5489         END IF;
5490         -- No records detailed, so delete Move Order Header for Organization
5491         IF crec.tot_detailed = 0 THEN --{
5492            IF l_debug_on THEN
5493               WSH_DEBUG_SV.logmsg(l_module_name,  'NO LINES SELECTED FOR ORG ' ||TO_CHAR(crec.organization_id));
5494               WSH_DEBUG_SV.logmsg(l_module_name,  'DELETE MOVE ORDER HEADER'  );
5495            END IF;
5496            -- Clear move order header/line records
5497            l_trohdr_rec := l_empty_trohdr_rec;
5498            l_trohdr_val_rec := l_empty_trohdr_val_rec;
5499            l_trohdr_rec.header_id := crec.mo_header_id;
5500            l_trohdr_rec.operation := INV_GLOBALS.G_OPR_DELETE;
5501            l_trolin_tbl.delete;
5502            l_trolin_val_tbl.delete;
5503            IF l_debug_on THEN
5504               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit INV_MOVE_ORDER_PUB.PROCESS_MOVE_ORDER'
5505                                                ,WSH_DEBUG_SV.C_PROC_LEVEL);
5506            END IF;
5507            Inv_Move_Order_Pub.Process_Move_Order (
5508                                                    p_api_version_number => l_api_version_number,
5509                                                    p_init_msg_list      => FND_API.G_FALSE,
5510                                                    p_return_values      => FND_API.G_TRUE,
5511                                                    p_commit             => l_commit,
5512                                                    p_trohdr_rec         => l_trohdr_rec,
5513                                                    x_trohdr_rec         => l_trohdr_rec,
5514                                                    x_trohdr_val_rec     => l_trohdr_val_rec,
5515                                                    x_trolin_tbl         => l_trolin_tbl,
5516                                                    x_trolin_val_tbl     => l_trolin_val_tbl,
5517                                                    x_return_status      => l_return_status,
5518                                                    x_msg_count          => l_msg_count,
5519                                                    x_msg_data           => l_msg_data );
5520            IF l_debug_on THEN
5521               WSH_DEBUG_SV.log(l_module_name,'Inv_Move_Order_Pub.Process_Move_Order l_return_status'
5522                                             ,l_return_status);
5523            END IF;
5524            IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
5525            OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
5526                WSH_UTIL_CORE.PrintMsg('Error occurred in Inv_Move_Order_Pub.Process_Move_Order');
5527                FOR i in 1..l_msg_count LOOP
5528                    l_message := fnd_msg_pub.get(i,'F');
5529                    l_message := replace(l_message,chr(0),' ');
5530                    WSH_UTIL_CORE.PrintMsg(l_message);
5531                 END LOOP;
5532                 fnd_msg_pub.delete_msg();
5533                 RAISE e_return;
5534            END IF;
5535         END IF; --}
5536      END LOOP; --}
5537 
5538      -- Delete empty deliveries
5539      IF l_debug_on THEN
5540         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_AUTOCREATE.Delete_Empty_Deliveries' ,WSH_DEBUG_SV.C_PROC_LEVEL);
5541      END IF;
5542      WSH_DELIVERY_AUTOCREATE.Delete_Empty_Deliveries(g_batch_id,l_return_status);
5543      IF l_debug_on THEN
5544         WSH_DEBUG_SV.log(l_module_name,'WSH_DELIVERY_AUTOCREATE.Delete_Empty_Deliveries l_return_status',l_return_status);
5545      END IF;
5546      IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
5547          l_completion_status := 'WARNING';
5548      END IF;
5549 
5550      -- Reset delivery batch id.
5551      UPDATE wsh_new_deliveries
5552      SET    batch_id = NULL
5553      WHERE  batch_id = g_batch_id;
5554 
5555      --Bug 3433645 :Automated Shipping Failing for Order with Huge Delivery Lines
5556      --Batch ID set to NULL for all the children of Containers that did not get Pick Released.
5557 
5558      --bug# 6689448 (replenishment project):  should not update batch_id value on the replenishment
5559      -- requested delivery detail lines.
5560      UPDATE wsh_delivery_details
5561      SET    batch_id = NULL
5562      WHERE  batch_id = g_batch_id
5563      AND    ( (released_status in ('R','X'))
5564                OR ( released_status = 'B' and nvl(REPLENISHMENT_STATUS,'C') <> 'R') );
5565 
5566      --bug# 6689448 (replenishment project): begin
5567      -- At the end of the pick release process, submit 'Dynamic Replenishment' concurrent
5568      -- request for each WMS org where atleast one detail is in replenishment requested status.
5569      FOR crec IN get_replenish_orgs(g_batch_id) LOOP
5570      --{
5571          IF l_debug_on THEN
5572              WSH_DEBUG_SV.log(l_module_name,'Submitting dynamic replenishment conc. request for the org: ',crec.organization_id);
5573          END IF;
5574          l_request_id := FND_REQUEST.Submit_Request(
5575                                                       application => 'WMS',
5576                                                       program     => 'WMSDYREPL',
5577                                                       description => '',
5578                                                       start_time  => '',
5579                                                       argument1   => g_batch_id,   -- pick release batch_id
5580                                                       argument2   => crec.organization_id,
5581                                                       argument3   => l_org_info_tbl(crec.organization_id).task_planning_flag,-- task planning flag
5582                                                       argument4   => l_org_info_tbl(crec.organization_id).pick_seq_rule_id  --     pick sequence rule
5583                                                );
5584          IF l_debug_on THEN
5585              WSH_DEBUG_SV.log(l_module_name,'request Id: ',l_request_id);
5586          END IF;
5587      --}
5588      END LOOP;
5589      --bug# 6689448 (replenishment project): end
5590 
5591      G_BATCH_ID := NULL;
5592 
5593      IF l_mode IS NULL THEN --{
5594         -- Completion status to warning for error backordered.
5595         IF ( G_BACKORDERED ) AND l_completion_status <> 'ERROR' THEN
5596              l_completion_status := 'WARNING';
5597         END IF;
5598 
5599      --}
5600      ELSE --{
5601         --set the l_completion_status based on the other programs
5602         FND_PROFILE.Get('CONC_REQUEST_ID', l_this_request);
5603         OPEN  c_requests(l_this_request);
5604         FETCH c_requests BULK COLLECT INTO l_child_req_ids;
5605         CLOSE c_requests;
5606         l_errors   := 0;
5607         l_warnings := 0;
5608         j := l_child_req_ids.FIRST;
5609         WHILE j IS NOT NULL LOOP
5610            l_dev_status := NULL;
5611            l_dummy := FND_CONCURRENT.get_request_status(
5612                                      request_id => l_child_req_ids(j),
5613                                      phase      => l_phase,
5614                                      status     => l_status,
5615                                      dev_phase  => l_dev_phase,
5616                                      dev_status => l_dev_status,
5617                                      message    => l_message);
5618 
5619            IF l_dev_status = 'WARNING' THEN
5620               l_warnings:= l_warnings + 1;
5621            ELSIF l_dev_status <> 'NORMAL' THEN
5622               l_errors := l_errors + 1;
5623            END IF;
5624            IF l_debug_on THEN
5625               WSH_DEBUG_SV.logmsg(l_module_name,'Child Request id :' ||l_child_req_ids(j)||' Status :'||l_dev_status);
5626            END IF;
5627 
5628            FND_MESSAGE.SET_NAME('WSH','WSH_CHILD_REQ_STATUS');
5629            FND_MESSAGE.SET_TOKEN('REQ_ID', to_char(l_child_req_ids(j)));
5630            FND_MESSAGE.SET_TOKEN('STATUS', l_status);
5631            WSH_UTIL_CORE.PrintMsg(FND_MESSAGE.GET);
5632            j := l_child_req_ids.NEXT(j);
5633         END LOOP;
5634 
5635         IF ( G_BACKORDERED ) THEN
5636              l_warnings:= l_warnings + 1;
5637         END IF;
5638 
5639         IF l_errors = 0  AND l_warnings = 0 THEN
5640            l_completion_status := 'NORMAL';
5641         ELSIF (l_errors > 0 ) THEN
5642            l_completion_status := 'ERROR';
5643         ELSE
5644            l_completion_status := 'WARNING';
5645         END IF;
5646      END IF; --}
5647 
5648      WSH_UTIL_CORE.PrintMsg('Pick selection is completed');
5649 
5650      -- Set Online Pick Release Result
5651      -- Warning Mesg. for Online
5652      IF (l_completion_status = 'WARNING') THEN
5653          G_ONLINE_PICK_RELEASE_RESULT := 'W';
5654      ELSE
5655          G_ONLINE_PICK_RELEASE_RESULT := 'S';
5656          G_ONLINE_PICK_RELEASE_PHASE := 'SUCCESS';
5657      END IF;
5658 
5659      IF G_CONC_REQ = FND_API.G_TRUE THEN
5660         IF l_completion_status = 'NORMAL' THEN
5661            errbuf := 'Pick selection completed successfully';
5662         ELSIF l_completion_status = 'WARNING' THEN
5663            errbuf := 'Pick selection is completed with warning';
5664         ELSE
5665            errbuf := 'Pick selection is completed with error';
5666         END IF;
5667      END IF;
5668 
5669      IF l_debug_on THEN
5670         WSH_DEBUG_SV.log(l_module_name,'l_completion_status',l_completion_status);
5671      END IF;
5672 
5673      IF ( G_CONC_REQ = FND_API.G_TRUE ) THEN
5674           IF l_debug_on THEN
5675              WSH_DEBUG_SV.logmsg(l_module_name,  'Commiting...');
5676           END IF;
5677           COMMIT;
5678      END IF;
5679 
5680   END IF; --}
5681 
5682   -- If pick released successfully see if we want to autopack/shipconfirm
5683   IF ((G_CONC_REQ = FND_API.G_TRUE AND l_completion_status <> 'ERROR') OR
5684        G_ONLINE_PICK_RELEASE_RESULT IN ('S', 'W'))
5685   AND (WSH_PR_CRITERIA.g_autopack_flag = 'Y' OR WSH_PR_CRITERIA.g_non_picking_flag in  ('P', 'S') OR
5686        WSH_PR_CRITERIA.g_auto_ship_confirm_rule_id IS NOT NULL)
5687   AND (l_mode IS NULL OR l_mode IN ('PICK-SS','PICK')) THEN
5688   --{
5689      IF l_debug_on THEN
5690         WSH_DEBUG_SV.log(l_module_name,'NON PICKFLAG',WSH_PR_CRITERIA.g_non_picking_flag);
5691      END IF;
5692      -- this is from Pick Release Form, hence only 1 record
5693      IF WSH_PR_CRITERIA.g_non_picking_flag IS NULL THEN
5694         l_ap_level    := WSH_PR_CRITERIA.g_autopack_level;
5695         l_ap_flag     := WSH_PR_CRITERIA.g_autopack_flag;
5696         l_sc_rule_id  := WSH_PR_CRITERIA.g_auto_ship_confirm_rule_id;
5697         IF l_debug_on THEN
5698            WSH_DEBUG_SV.log(l_module_name,'L_AP_LEVEL', l_ap_level);
5699            WSH_DEBUG_SV.log(l_module_name,'L_AP_FLAG', l_ap_flag);
5700            WSH_DEBUG_SV.log(l_module_name,'L_SC_RULE', l_sc_rule_id);
5701         END IF;
5702      END IF;
5703 
5704      IF WSH_PR_CRITERIA.g_non_picking_flag in  ('P', 'S') THEN
5705      --{
5706         -- see if PR batch created for Pick, (Pack,) and Ship through STF
5707         -- if yes, group into batches by SC Rules, AP level
5708         l_grp_count := 0;
5709         OPEN get_pack_ship_groups(p_batch_id);
5710         LOOP
5711           l_grp_count := l_grp_count + 1;
5712           FETCH get_pack_ship_groups into l_group_details_rec_tab(l_grp_count);
5713           EXIT WHEN get_pack_ship_groups%NOTFOUND;
5714         END LOOP;
5715         CLOSE get_pack_ship_groups;
5716 
5717         l_group_nums := l_group_details_rec_tab.count;
5718 
5719         IF l_debug_on THEN
5720            WSH_DEBUG_SV.log(l_module_name,'l_group_nums', l_group_nums);
5721         END IF;
5722 
5723         IF l_group_nums = 1 THEN
5724         --{
5725            -- if only one group, no need to create child batches.
5726            -- we can pack/ship this group using the same PR batch.
5727            l_ap_level    := l_group_details_rec_tab(l_group_details_rec_tab.FIRST).autopack_level;
5728            l_sc_rule_id  := l_group_details_rec_tab(l_group_details_rec_tab.FIRST).ship_confirm_rule_id;
5729            IF NVL(l_ap_level, 0) > 0 THEN
5730               l_ap_flag  :=  'Y';
5731            END IF;
5732            IF l_debug_on THEN
5733               WSH_DEBUG_SV.log(l_module_name,'l_ap_level', l_ap_level);
5734            END IF;
5735         --}
5736         ELSIF (l_group_nums > 1) THEN
5737         --{
5738            IF l_debug_on THEN
5739               WSH_DEBUG_SV.log(l_module_name,'l_group_nums > 1',l_group_nums);
5740            END IF;
5741            -- loop through each group creating child batch.
5742            -- and then pack/ship it.
5743            FOR i in l_group_details_rec_tab.FIRST..l_group_details_rec_tab.LAST LOOP
5744            --{
5745                l_ap_level := l_group_details_rec_tab(i).autopack_level;
5746                l_sc_rule_id  := l_group_details_rec_tab(i).ship_confirm_rule_id;
5747                IF NVL(l_ap_level, 0) > 0 THEN
5748                   l_ap_flag :=  'Y';
5749                END IF;
5750                IF l_debug_on THEN
5751                   WSH_DEBUG_SV.log(l_module_name,'ELSE l_ap_level', l_ap_level);
5752                END IF;
5753                l_del_count := 1;
5754                OPEN get_dels_in_group(p_batch_id, l_sc_rule_id, l_ap_level);
5755                LOOP
5756                  -- group all the deliveries that go into a child batch
5757                  -- to be packed/shipped together.
5758                  FETCH get_dels_in_group INTO l_ps_delivery_tab(l_del_count),
5759                                               l_ps_org_tab(l_del_count),
5760                                               l_ps_pick_loc_tab(l_del_count);
5761                  EXIT when get_dels_in_group%NOTFOUND;
5762                  l_del_count := l_del_count + 1;
5763                END LOOP;
5764                IF get_dels_in_group%ISOPEN THEN
5765                   CLOSE get_dels_in_group;
5766                END IF;
5767                IF l_debug_on THEN
5768                   WSH_DEBUG_SV.log(l_module_name,'BEFORE INSERTING l_ap_level', l_ap_level);
5769                END IF;
5770 
5771                -- Autopack should be set only if Non Pick Flag as 'P' and AP Level is set
5772                IF WSH_PR_CRITERIA.g_non_picking_flag = 'P' AND NVL(l_ap_level,0) > 0 THEN
5773                   l_act_ap_level := NVL(l_ap_level,0);
5774                ELSIF WSH_PR_CRITERIA.g_non_picking_flag = 'P' AND NVL(l_ap_level,0) = 0 THEN
5775                   IF G_CONC_REQ = FND_API.G_TRUE THEN
5776                      WSH_UTIL_CORE.PrintMsg('** Warning : Autopack Option is No for the organization - Packing action not performed **');
5777                   END IF;
5778                   l_act_ap_level := 0;
5779                ELSE
5780                   l_act_ap_level := 0;
5781                END IF;
5782                IF l_act_ap_level = 0 THEN
5783                   l_act_ap_flag := 'N';
5784                ELSE
5785                   l_act_ap_flag := 'Y';
5786                END IF;
5787 
5788                -- create pack/ship batch for this group.
5789                l_del_batch_id := NULL;
5790                l_del_batch_name := NULL;
5791 
5792                WSH_PICKING_BATCHES_PKG.Insert_Row (
5793                                                     X_Rowid     => l_tmp_row_id,
5794                                                     X_Batch_Id   => l_del_batch_id,
5795                                                     P_Creation_Date   => NULL,
5796                                                     P_Created_By => NULL,
5797                                                     P_Last_Update_Date => NULL,
5798                                                     P_Last_Updated_By   => NULL,
5799                                                     P_Last_Update_Login   => NULL,
5800                                                     X_Name   => l_del_batch_name,
5801                                                     P_Backorders_Only_Flag  => NULL,
5802                                                     P_Document_Set_Id   => NULL,
5803                                                     P_Existing_Rsvs_Only_Flag => NULL,
5804                                                     P_Shipment_Priority_Code   => NULL,
5805                                                     P_Ship_Method_Code => NULL,
5806                                                     P_Customer_Id   => NULL,
5807                                                     P_Order_Header_Id   => NULL,
5808                                                     P_Ship_Set_Number   => NULL,
5809                                                     P_Inventory_Item_Id   => NULL,
5810                                                     P_Order_Type_Id   => NULL,
5811                                                     P_From_Requested_Date   => NULL,
5812                                                     P_To_Requested_Date   => NULL,
5813                                                     P_From_Scheduled_Ship_Date   => NULL,
5814                                                     P_To_Scheduled_Ship_Date   => NULL,
5815                                                     P_Ship_To_Location_Id   => NULL,
5816                                                     P_Ship_From_Location_Id   => NULL,
5817                                                     P_Trip_Id   => NULL,
5818                                                     P_Delivery_Id    => NULL,
5819                                                     P_Include_Planned_Lines   => NULL,
5820                                                     P_Pick_Grouping_Rule_Id   => NULL,
5821                                                     P_pick_sequence_rule_id   => NULL,
5822                                                     P_Autocreate_Delivery_Flag   => NULL,
5823                                                     P_Attribute_Category  => NULL,
5824                                                     P_Attribute1 => NULL,
5825                                                     P_Attribute2 => NULL,
5826                                                     P_Attribute3 => NULL,
5827                                                     P_Attribute4 => NULL,
5828                                                     P_Attribute5 => NULL,
5829                                                     P_Attribute6 => NULL,
5830                                                     P_Attribute7 => NULL,
5831                                                     P_Attribute8 => NULL,
5832                                                     P_Attribute9 => NULL,
5833                                                     P_Attribute10   => NULL,
5834                                                     P_Attribute11   => NULL,
5835                                                     P_Attribute12   => NULL,
5836                                                     P_Attribute13   => NULL,
5837                                                     P_Attribute14   => NULL,
5838                                                     P_Attribute15=> NULL,
5839                                                     P_Autodetail_Pr_Flag  => NULL,
5840                                                     P_Carrier_Id=> NULL,
5841                                                     P_Trip_Stop_Id=> NULL,
5842                                                     P_Default_stage_subinventory => NULL,
5843                                                     P_Default_stage_locator_id   => NULL,
5844                                                     P_Pick_from_subinventory   => NULL,
5845                                                     P_Pick_from_locator_id  => NULL,
5846                                                     P_Auto_pick_confirm_flag   => NULL,
5847                                                     P_Delivery_Detail_ID  => NULL,
5848                                                     P_Project_ID=> NULL,
5849                                                     P_Task_ID=> NULL,
5850                                                     P_Organization_Id   => NULL,
5851                                                     P_Ship_Confirm_Rule_Id  => l_sc_rule_id,
5852                                                     P_Autopack_Flag=> l_act_ap_flag,
5853                                                     P_Autopack_Level=> l_act_ap_level,
5854                                                     P_TASK_PLANNING_FLAG=> NULL,
5855                                                     P_Non_Picking_Flag => 'Y',
5856             	                                      /* Enhancement */
5857 	                                            p_RegionID	=> NULL,
5858             	                                    p_ZoneID	=> NULL,
5859             	                                    p_categoryID	=> NULL,
5860                                                     p_categorySetID => NULL,
5861                                                     p_acDelivCriteria => NULL,
5862 	                                            p_RelSubinventory => NULL,
5863             	                                      -- deliveryMerge
5864             	                                    p_append_flag => 'N',
5865                                                     p_task_priority => NULL,
5866                                                     p_allocation_method => NULL,
5867                                                     p_crossdock_criteria_id => NULL,
5868                                                     p_client_id             => NULL -- LSP PROJECT
5869                                                  );
5870 
5871                -- Bulk Insert
5872                FORALL i in 1..l_ps_delivery_tab.COUNT
5873                       INSERT INTO WSH_PR_WORKERS (
5874                                                    BATCH_ID,
5875                                                    TYPE,
5876                                                    PA_SC_BATCH_ID,
5877                                                    DELIVERY_ID,
5878                                                    ORGANIZATION_ID,
5879                                                    PICKUP_LOCATION_ID,
5880                                                    AP_LEVEL,
5881                                                    SC_RULE_ID,
5882                                                    PROCESSED
5883                                                  )
5884                                           VALUES (
5885                                                    p_batch_id,
5886                                                    'PS',
5887                                                    l_del_batch_id,
5888                                                    l_ps_delivery_tab(i),
5889                                                    l_ps_org_tab(i),
5890                                                    l_ps_pick_loc_tab(i),
5891                                                    l_act_ap_level,
5892                                                    l_sc_rule_id,
5893                                                    'N'
5894                                                  );
5895                l_pr_worker_rec_count := l_pr_worker_rec_count + SQL%ROWCOUNT;
5896            --}
5897            END LOOP;
5898         --}
5899         END IF;
5900      --}
5901      END IF;
5902 
5903      IF l_debug_on THEN
5904         WSH_DEBUG_SV.logmsg(l_module_name,'Flags: l_ap_level='||l_ap_level||', Autopack flag='||WSH_PR_CRITERIA.g_autopack_flag);
5905      END IF;
5906      -- if only one (sc rules/ap level) group for all pickreleased lines,
5907      -- or picking/packing/shipping through PR form or STF for deliveries,
5908      -- no need to spawn seperate batches. use existing PR batch.
5909      IF (l_group_nums = 1)  OR (WSH_PR_CRITERIA.g_auto_ship_confirm_rule_id IS NOT NULL)
5910      OR (WSH_PR_CRITERIA.g_autopack_flag = 'Y') THEN
5911      --{
5912         IF l_debug_on THEN
5913            WSH_DEBUG_SV.logmsg(l_module_name,'l_ap_level='||l_ap_level||', Autopack flag='||WSH_PR_CRITERIA.g_autopack_flag||l_group_nums);
5914         END IF;
5915 
5916         -- Autopack should be set only if Non Pick Flag as 'P' or if Pick Release Criteria has Autopack specified
5917         IF (WSH_PR_CRITERIA.g_autopack_flag = 'Y')
5918         OR (NVL(l_ap_level,0) > 0 AND WSH_PR_CRITERIA.g_non_picking_flag = 'P') THEN
5919             l_act_ap_level := NVL(l_ap_level,0);
5920         ELSIF WSH_PR_CRITERIA.g_non_picking_flag = 'P' AND NVL(l_ap_level,0) = 0 THEN
5921             IF G_CONC_REQ = FND_API.G_TRUE THEN
5922                WSH_UTIL_CORE.PrintMsg('** Warning : Autopack Option is No for the organization - Packing action not performed **');
5923             END IF;
5924             l_act_ap_level := 0;
5925         ELSE
5926             l_act_ap_level := 0;
5927         END IF;
5928 
5929         IF l_group_nums = 1 THEN
5930            -- if for one group of details through STF, then update
5931            -- PR batch to be a packing/shipping batch as well.
5932            UPDATE wsh_picking_batches
5933            SET    ship_confirm_rule_id = l_sc_rule_id,
5934                   autopack_flag  = DECODE(l_act_ap_level,0,'N','Y'),
5935                   autopack_level = l_act_ap_level
5936            WHERE  batch_id = p_batch_id;
5937         END IF;
5938 
5939         l_del_count := 1;
5940         OPEN get_dels_in_batch(p_batch_id);
5941         LOOP
5942           -- group all the deliveries for the batch to be
5943           -- packed/shipped together.
5944           FETCH get_dels_in_batch INTO l_ps_delivery_tab(l_del_count),
5945                                        l_ps_org_tab(l_del_count),
5946                                        l_ps_pick_loc_tab(l_del_count);
5947           EXIT WHEN get_dels_in_batch%NOTFOUND;
5948           l_del_count := l_del_count + 1;
5949         END LOOP;
5950         IF get_dels_in_batch%ISOPEN THEN
5951            CLOSE get_dels_in_batch;
5952         END IF;
5953 
5954         IF l_debug_on THEN
5955            WSH_DEBUG_SV.logmsg(l_module_name,'Flags again: l_ap_level='||l_ap_level||', Autopack flag='||WSH_PR_CRITERIA.g_autopack_flag||l_group_nums);
5956         END IF;
5957 
5958         -- Bulk Insert
5959         FORALL i in 1..l_ps_delivery_tab.COUNT
5960                INSERT INTO WSH_PR_WORKERS (
5961                                            BATCH_ID,
5962                                            TYPE,
5963                                            PA_SC_BATCH_ID,
5964                                            DELIVERY_ID,
5965                                            ORGANIZATION_ID,
5966                                            PICKUP_LOCATION_ID,
5967                                            AP_LEVEL,
5968                                            SC_RULE_ID,
5969                                            PROCESSED
5970                                          )
5971                                   VALUES (
5972                                            p_batch_id,
5973                                            'PS',
5974                                            p_batch_id,
5975                                            l_ps_delivery_tab(i),
5976                                            l_ps_org_tab(i),
5977                                            l_ps_pick_loc_tab(i),
5978                                            l_act_ap_level,
5979                                            l_sc_rule_id,
5980                                            'N'
5981                                          );
5982         l_pr_worker_rec_count := l_pr_worker_rec_count + SQL%ROWCOUNT;
5983      --}
5984      END IF;
5985 
5986      IF l_pr_worker_rec_count = 0 THEN
5987         IF l_debug_on THEN
5988            WSH_DEBUG_SV.logmsg(l_module_name,'No eligible records to Pack and Ship');
5989         END IF;
5990      ELSE
5991         IF l_debug_on THEN
5992            WSH_DEBUG_SV.logmsg(l_module_name,'Total number of eligible records to Pack and Ship : '|| l_pr_worker_rec_count);
5993         END IF;
5994      --{
5995         l_num_workers := LEAST(l_pr_worker_rec_count, NVL(g_num_workers,1));
5996         IF l_num_workers > 1 THEN
5997         --{
5998            IF l_debug_on THEN
5999               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Spawn_Workers for PS',
6000                                   WSH_DEBUG_SV.C_PROC_LEVEL);
6001            END IF;
6002            -- If the current status is Warning, pass the value as 1, else pass value as 0
6003            IF ( G_BACKORDERED ) THEN
6004               l_retcode := 1;
6005            ELSE
6006               l_retcode := 0;
6007            END IF;
6008            Spawn_Workers (
6009                            p_batch_id      => p_batch_id,
6010                            p_num_requests  => l_num_workers,
6011                            p_mode          => 'PS',
6012                            p_req_status    => l_retcode,
6013                            p_log_level     => p_log_level,
6014                            x_return_status => l_return_status );
6015            IF l_debug_on THEN
6016               WSH_DEBUG_SV.log(l_module_name, 'Spawn_Workers l_return_status',l_return_status);
6017            END IF;
6018            IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
6019            OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
6020                WSH_UTIL_CORE.PrintMsg('Error occurred in Spawn_Workers for PS');
6021                RAISE e_return;
6022            ELSE
6023                -- After pausing parent process, we need to skip rest of the code
6024                -- till all workers complete and parent process restarts
6025                GOTO End_Release_Batch;
6026            END IF;
6027         --}
6028         ELSE
6029         --{
6030            IF l_debug_on THEN
6031               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Release_Batch_Sub'
6032                                   , WSH_DEBUG_SV.C_PROC_LEVEL);
6033            END IF;
6034            l_retcode := NULL;
6035            l_errbuf  := NULL;
6036            Release_Batch_Sub (
6037                             errbuf       => l_errbuf,
6038                             retcode      => l_retcode,
6039                             p_batch_id   => p_batch_id,
6040                             p_worker_id  => NULL,
6041                             p_mode       => 'PS',
6042                             p_log_level  => p_log_level );
6043            IF l_debug_on THEN
6044               WSH_DEBUG_SV.logmsg(l_module_name, 'Return from Release_Batch_Sub');
6045               WSH_DEBUG_SV.log(l_module_name, 'retcode',l_retcode);
6046               WSH_DEBUG_SV.log(l_module_name, 'errbuf',l_errbuf);
6047            END IF;
6048            IF l_retcode = 2 THEN
6049               WSH_UTIL_CORE.PrintMsg('Error occurred in Release_Batch_Sub');
6050               RAISE e_return;
6051            ELSIF l_retcode IS NULL AND
6052                  G_ONLINE_PICK_RELEASE_RESULT = 'F' THEN
6053              WSH_UTIL_CORE.PrintMsg('Error in Online Release_batch_sub');
6054              RAISE e_return;
6055            END IF;
6056         --}
6057         END IF;
6058      --}
6059      END IF;
6060   --}
6061   END IF; -- Pack/Ship Grouping
6062 
6063   WSH_UTIL_CORE.PrintDateTime;
6064 
6065   IF ((G_CONC_REQ = FND_API.G_TRUE AND l_completion_status <> 'ERROR') OR
6066        G_ONLINE_PICK_RELEASE_RESULT IN ('S', 'W'))
6067   AND (WSH_PR_CRITERIA.g_autopack_flag = 'Y' OR WSH_PR_CRITERIA.g_non_picking_flag in  ('P', 'S') OR
6068        WSH_PR_CRITERIA.g_auto_ship_confirm_rule_id IS NOT NULL) THEN --{
6069      -- Get all Trip Stops for setting Trip to In-Transit or Closed
6070      --{
6071      l_sc_id_tab.delete;
6072      OPEN  c_close_trip(p_batch_id);
6073      LOOP
6074        FETCH c_close_trip INTO l_sc_id_tab(l_sc_id_tab.COUNT+1), l_batch_creation_date,
6075                                l_ac_close_trip_flag, l_ac_intransit_flag;
6076        EXIT WHEN c_close_trip%NOTFOUND;
6077        IF l_ac_close_trip_flag = 'Y' THEN
6078           OPEN get_all_stops(l_sc_id_tab(l_sc_id_tab.COUNT));
6079           LOOP
6080             FETCH get_all_stops into l_trip_id, l_stop_sequence_number, l_stop_id, l_stop_location_id ;
6081             EXIT WHEN get_all_stops%NOTFOUND;
6082             l_stops_to_close(l_stops_to_close.COUNT+1)       := l_stop_id;
6083             l_stop_location_ids(l_stop_location_ids.COUNT+1) := l_stop_location_id;
6084             l_stops_sc_ids(l_stops_sc_ids.COUNT+1)      := l_sc_id_tab(l_sc_id_tab.COUNT);
6085           END LOOP;
6086           CLOSE get_all_stops;
6087 
6088        ELSIF l_ac_intransit_flag = 'Y' THEN
6089           OPEN get_pick_up_stops(l_sc_id_tab(l_sc_id_tab.COUNT));
6090           LOOP
6091             FETCH get_pick_up_stops into l_trip_id, l_stop_sequence_number, l_stop_id, l_stop_location_id;
6092             EXIT WHEN get_pick_up_stops%NOTFOUND;
6093             l_stops_to_close(l_stops_to_close.COUNT+1)       := l_stop_id;
6094             l_stop_location_ids(l_stop_location_ids.COUNT+1) := l_stop_location_id;
6095             l_stops_sc_ids(l_stops_sc_ids.COUNT+1)      := l_sc_id_tab(l_sc_id_tab.COUNT);
6096           END LOOP;
6097           CLOSE get_pick_up_stops;
6098        END IF;
6099      END LOOP;
6100      CLOSE c_close_trip;
6101      IF l_debug_on THEN
6102         WSH_DEBUG_SV.logmsg(l_module_name,'l_stops_to_close.COUNT '||l_stops_to_close.COUNT);
6103      END IF;
6104      --}
6105 
6106      IF l_stops_to_close.count > 0 THEN
6107      --{
6108         IF l_debug_on THEN
6109            WSH_DEBUG_SV.logmsg(l_module_name, 'Closing stops');
6110         END IF;
6111         FOR i in 1..l_stops_to_close.count LOOP
6112         --{
6113            IF l_debug_on THEN
6114             WSH_DEBUG_SV.logmsg(l_module_name, 'Calling program unit WSH_BATCH_PROCESS.Close_A_Stop');
6115            END IF;
6116            WSH_BATCH_PROCESS.Close_A_Stop (
6117              p_stop_id    => l_stops_to_close(i),
6118              p_actual_date => NVL(WSH_PR_CRITERIA.g_actual_departure_date, SYSDATE),
6119              p_defer_interface_flag => 'Y',
6120              x_return_status        => l_return_status );
6121 
6122            IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
6123                IF l_debug_on THEN
6124                   WSH_DEBUG_SV.log(l_module_name,'Successfully closed stop',l_stops_to_close(i));
6125                END IF;
6126                l_closing_stop_success := l_closing_stop_success + 1;
6127            ELSIF (l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING) THEN
6128                IF l_debug_on THEN
6129                   WSH_DEBUG_SV.log(l_module_name,'Trip stop ', l_stops_to_close(i) ||' is closed with warnings');
6130                END IF;
6131                l_closing_stop_warning := l_closing_stop_warning + 1;
6132                WSH_BATCH_PROCESS.log_batch_messages(l_stops_sc_ids(i), NULL , l_stops_to_close(i) ,
6133                                                     l_stop_location_ids(i), NULL);
6134            ELSE
6135                IF l_debug_on THEN
6136                   WSH_DEBUG_SV.log(l_module_name,'Failed to close stop ', l_stops_to_close(i));
6137                END IF;
6138                l_closing_stop_failure := l_closing_stop_failure + 1;
6139                WSH_BATCH_PROCESS.log_batch_messages(l_stops_sc_ids(i), NULL , l_stops_to_close(i) ,
6140                                                     l_stop_location_ids(i), NULL);
6141            END IF;
6142            IF l_debug_on THEN
6143               WSH_DEBUG_SV.logmsg(l_module_name,  'Commiting...');
6144            END IF;
6145            COMMIT;
6146         --}
6147         END LOOP;
6148         --
6149         IF l_debug_on THEN
6150            WSH_DEBUG_SV.logmsg(l_module_name,'Successfully closed '|| l_closing_stop_success
6151                                         ||' stops' );
6152            WSH_DEBUG_SV.logmsg(l_module_name,'Closed '|| l_closing_stop_warning
6153                                         ||' stops with warnings' );
6154            WSH_DEBUG_SV.logmsg(l_module_name,'Failed to close '|| l_closing_stop_failure
6155                                         ||' stops');
6156         END IF;
6157      --}
6158      ELSE
6159         IF l_debug_on THEN
6160            WSH_DEBUG_SV.log(l_module_name, 'No stops to close');
6161         END IF;
6162      END IF;
6163 
6164      WSH_UTIL_CORE.PrintDateTime;
6165 
6166      -- Submit ITS for Batch
6167      FOR crec in c_defer_interface(p_batch_id) LOOP
6168      --{
6169          IF crec.ac_defer_interface_flag = 'N'  AND l_closing_stop_success > 0
6170          THEN
6171          --{
6172             l_interface_stop_id := 0;
6173             -- added cursor to check if interface is necessary
6174             OPEN c_batch_stop (crec.pa_sc_batch_id);
6175             FETCH c_batch_stop INTO l_interface_stop_id;
6176             CLOSE c_batch_stop;
6177             --
6178             IF l_interface_stop_id <> 0 THEN
6179                l_request_id := FND_REQUEST.submit_Request (
6180                                                             'WSH', 'WSHINTERFACE', '', '', FALSE,
6181                                                             'ALL', '', '', p_log_level, crec.pa_sc_batch_id);
6182                IF l_request_id = 0 THEN
6183                   NULL;
6184                ELSE
6185                   IF l_debug_on THEN
6186                      WSH_DEBUG_SV.logmsg(l_module_name,  'Commiting...');
6187                   END IF;
6188                   COMMIT;
6189                   WSH_UTIL_CORE.PrintMsg('Interface request submitted for stops, request ID: '||to_char(l_request_id));
6190                END IF;
6191             END IF;
6192          --}
6193          END IF;
6194      --}
6195      END LOOP;
6196 
6197      -- Submit Auto Pack Report
6198      --{
6199      OPEN c_ap_batch(p_batch_id);
6200      LOOP
6201        FETCH c_ap_batch INTO l_ap_batch_id;
6202        EXIT WHEN c_ap_batch%NOTFOUND;
6203        l_request_id := FND_REQUEST.Submit_Request (
6204                                                     'WSH',
6205                                                     'WSHRDAPK','Auto Pack Report',NULL,FALSE
6206                                                     ,l_ap_batch_id,'','','','','','','','',''
6207                                                     ,'','','','','','','AP','','',''
6208                                                     ,'','','','','','','','','',''
6209                                                     ,'','','','','','','','','',''
6210                                                     ,'','','','','','','','','',''
6211                                                     ,'','','','','','','','','',''
6212                                                     ,'','','','','','','','','',''
6213                                                     ,'','','','','','','','','',''
6214                                                     ,'','','','','','','','','',''
6215                                                     ,'','','','','','','','','','' );
6216        IF l_debug_on THEN
6217           WSH_DEBUG_SV.logmsg(l_module_name,  'Commiting...');
6218        END IF;
6219        COMMIT;
6220      END LOOP;
6221      CLOSE c_ap_batch;
6222      WSH_UTIL_CORE.PrintDateTime;
6223      --}
6224 
6225      -- Submit Auto Ship Confirm Report
6226      --{
6227      IF l_sc_id_tab.COUNT > 0 THEN
6228         IF l_debug_on THEN
6229            WSH_DEBUG_SV.logmsg(l_module_name, 'Submitting Auto Ship Confirm Report');
6230            WSH_DEBUG_SV.log(l_module_name, 'l_sc_id_tab.COUNT', l_sc_id_tab.COUNT);
6231         END IF;
6232         WSH_UTIL_CORE.PrintDateTime;
6233         FOR i in l_sc_id_tab.FIRST..l_sc_id_tab.LAST
6234         LOOP
6235             l_request_id := FND_REQUEST.Submit_Request (
6236                                                          'WSH',
6237                                                          'WSHRDASC','Auto Ship Confirm Report',NULL,FALSE
6238                                                          ,l_sc_id_tab(i),'','','','','','','','',''
6239                                                          ,'','','','','','','','SC','',''
6240                                                          ,'','','','','','','','','',''
6241                                                          ,'','','','','','','','','',''
6242                                                          ,'','','','','','','','','',''
6243                                                          ,'','','','','','','','','',''
6244                                                          ,'','','','','','','','','',''
6245                                                          ,'','','','','','','','','',''
6246                                                          ,'','','','','','','','','',''
6247                                                          ,'','','','','','','','','','' );
6248             IF l_debug_on THEN
6249                WSH_DEBUG_SV.logmsg(l_module_name,  'Commiting...');
6250             END IF;
6251             COMMIT;
6252         END LOOP;
6253      END IF;
6254      WSH_UTIL_CORE.PrintDateTime;
6255      --}
6256 
6257      IF l_mode = 'PS' THEN --{
6258         --set the l_completion_status based on the other programs
6259         FND_PROFILE.Get('CONC_REQUEST_ID', l_this_request);
6260         OPEN  c_requests(l_this_request);
6261         FETCH c_requests BULK COLLECT INTO l_child_req_ids;
6262         CLOSE c_requests;
6263         l_errors   := 0;
6264         l_warnings := 0;
6265         j := l_child_req_ids.FIRST;
6266         WHILE j IS NOT NULL LOOP
6267            l_dev_status := NULL;
6268            l_dummy := FND_CONCURRENT.get_request_status(
6269                                      request_id => l_child_req_ids(j),
6270                                      phase      => l_phase,
6271                                      status     => l_status,
6272                                      dev_phase  => l_dev_phase,
6273                                      dev_status => l_dev_status,
6274                                      message    => l_message);
6275 
6276            IF l_dev_status = 'WARNING' THEN
6277               l_warnings:= l_warnings + 1;
6278            ELSIF l_dev_status <> 'NORMAL' THEN
6279               l_errors := l_errors + 1;
6280            END IF;
6281            IF l_debug_on THEN
6282               WSH_DEBUG_SV.logmsg(l_module_name,'Child Request id :' ||l_child_req_ids(j)||' Status :'||l_dev_status);
6283            END IF;
6284 
6285            FND_MESSAGE.SET_NAME('WSH','WSH_CHILD_REQ_STATUS');
6286            FND_MESSAGE.SET_TOKEN('REQ_ID', to_char(l_child_req_ids(j)));
6287            FND_MESSAGE.SET_TOKEN('STATUS', l_status);
6288            WSH_UTIL_CORE.PrintMsg(FND_MESSAGE.GET);
6289            j := l_child_req_ids.NEXT(j);
6290         END LOOP;
6291 
6292         IF ( G_BACKORDERED ) THEN
6293              l_warnings:= l_warnings + 1;
6294         END IF;
6295 
6296         IF l_errors = 0  AND l_warnings = 0 THEN
6297            l_completion_status := 'NORMAL';
6298         ELSIF (l_errors > 0 ) THEN
6299            l_completion_status := 'ERROR';
6300         ELSE
6301            l_completion_status := 'WARNING';
6302         END IF;
6303      END IF; --}
6304 
6305   --}
6306   END IF; -- Close Stops / Run ITS / Run Auto Pack and Auto Ship Confirm Reports
6307 
6308   --{
6309   -- Delete records from Worker Table and Credit Check table
6310   DELETE FROM wsh_pr_workers
6311   WHERE  batch_id = p_batch_id;
6312 
6313   DELETE FROM wsh_pr_header_holds
6314   WHERE  batch_id = p_batch_id;
6315 
6316   -- Call Inventory API to delete pick slip numbers from table as Inventory stores the numbers
6317   -- in physical table in case of Parallel Pick Release mode
6318   IF l_debug_on THEN
6319      WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
6320      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PR_PICK_SLIP_NUMBER.delete_pick_slip_numbers' ,WSH_DEBUG_SV.C_PROC_LEVEL);
6321   END IF;
6322   WSH_PR_PICK_SLIP_NUMBER.Delete_Pick_Slip_Numbers ( p_batch_id => p_batch_id );
6323   IF l_debug_on THEN
6324      WSH_DEBUG_SV.logmsg(l_module_name,'Return from WSH_PR_PICK_SLIP_NUMBER.delete_pick_slip_numbers');
6325      WSH_DEBUG_SV.log(l_module_name,'Current Time is ',SYSDATE);
6326   END IF;
6327   --}
6328 
6329   IF G_CONC_REQ = FND_API.G_TRUE THEN
6330      l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS(l_completion_status,'');
6331      IF l_completion_status = 'NORMAL' THEN
6332         retcode := '0';
6333      ELSIF l_completion_status = 'WARNING' THEN
6334         retcode := '1';
6335      ELSE
6336         retcode := '2';
6337      END IF;
6338   END IF;
6339 
6340   -- Call to DCP if profile is turned on.
6341   BEGIN --{
6342      IF l_debug_on THEN
6343         WSH_DEBUG_SV.log(l_module_name, 'l_check_dcp', l_check_dcp);
6344      END IF;
6345      IF NVL(l_check_dcp, -99) IN (1,2) THEN
6346         IF l_debug_on THEN
6347            WSH_DEBUG_SV.LOGMSG(L_MODULE_NAME, 'CALLING DCP ');
6348         END IF;
6349         WSH_DCP_PVT.Check_Pick_Release(p_batch_id => p_batch_id);
6350      END IF;
6351   EXCEPTION
6352      WHEN wsh_dcp_pvt.data_inconsistency_exception THEN
6353           IF l_debug_on THEN
6354              WSH_DEBUG_SV.logmsg(l_module_name,'data_inconsistency_exception');
6355           END IF;
6356      WHEN OTHERS THEN
6357           IF l_debug_on THEN
6358              WSH_DEBUG_SV.logmsg(l_module_name,'When Others');
6359           END IF;
6360   END; --}
6361 
6362   --
6363 
6364   SAVEPOINT S_CALL_FTE_LOAD_TENDER_API_SP;
6365 
6366   IF  UPPER(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = UPPER(l_api_session_name) THEN
6367   --{
6368      IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
6369         IF l_debug_on THEN
6370            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Process_stops_for_load_tender'
6371                                             ,WSH_DEBUG_SV.C_PROC_LEVEL);
6372         END IF;
6373         WSH_UTIL_CORE.Process_stops_for_load_tender (
6374                                                      p_reset_flags   => TRUE,
6375                                                      x_return_status => l_return_status );
6376         IF l_debug_on THEN
6377            WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
6378         END IF;
6379         IF (l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)
6380         OR (l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
6381             IF G_CONC_REQ = FND_API.G_TRUE THEN
6382                l_completion_status := 'ERROR';
6383                l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS(l_completion_status,'');
6384                errbuf := 'Pick selection is completed with error';
6385                retcode := '2';
6386                ROLLBACK;
6387             ELSE
6388                G_ONLINE_PICK_RELEASE_RESULT := 'F';
6389                ROLLBACK TO S_CALL_FTE_LOAD_TENDER_API_SP;
6390             END IF;
6391 
6392         ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
6393             IF G_CONC_REQ = FND_API.G_TRUE THEN
6394                IF l_completion_status = 'NORMAL' THEN
6395                   l_completion_status := 'WARNING';
6396                   l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS(l_completion_status,'');
6397                   errbuf := 'Pick selection is completed with warning';
6398                   retcode := '1';
6399                END IF;
6400             ELSE
6401                IF l_completion_status = 'S' THEN
6402                   G_ONLINE_PICK_RELEASE_RESULT := 'W';
6403                END IF;
6404             END IF;
6405         END IF;
6406      END IF;
6407   --}
6408   END IF;
6409 
6410   << End_Release_Batch >>
6411 
6412 --
6413  IF l_debug_on THEN
6414     WSH_DEBUG_SV.logmsg(l_module_name,'ERRBUF :'||errbuf ||' RETCODE :'||retcode);
6415     WSH_DEBUG_SV.pop(l_module_name);
6416  END IF;
6417 --
6418 
6419 EXCEPTION
6420    WHEN e_return THEN
6421 
6422       --Bug 5355135
6423       -- Since we rollback to savepoint do not use this exception if
6424       -- a commit or rollback has happened for on-line mode
6425 
6426       IF ( G_CONC_REQ = FND_API.G_TRUE ) THEN
6427          ROLLBACK;
6428       ELSE
6429          ROLLBACK TO s_Release_Batch_sp;
6430       END IF;
6431 
6432       WSH_UTIL_CORE.PrintMsg('SQLCODE: '||sqlcode||' SQLERRM: '||sqlerrm);
6433       WSH_UTIL_CORE.PrintMsg('Exception occurred in WSH_PICK_LIST');
6434       IF get_orgs%ISOPEN THEN
6435          CLOSE get_orgs;
6436       END IF;
6437       IF get_pack_ship_groups%ISOPEN THEN
6438          CLOSE get_pack_ship_groups;
6439       END IF;
6440       IF get_dels_in_group%ISOPEN THEN
6441          CLOSE get_dels_in_group;
6442       END IF;
6443       IF get_dels_in_batch%ISOPEN THEN
6444          CLOSE get_dels_in_batch;
6445       END IF;
6446       IF c_distinct_organization_id%ISOPEN THEN
6447          CLOSE c_distinct_organization_id;
6448       END IF;
6449       IF c_batch_orgs%ISOPEN THEN
6450          CLOSE c_batch_orgs;
6451       END IF;
6452       IF c_get_backordered_details%ISOPEN THEN
6453          CLOSE c_get_backordered_details;
6454       END IF;
6455       IF c_get_unassigned_details%ISOPEN THEN
6456          CLOSE c_get_unassigned_details;
6457       END IF;
6458       IF c_tot_worker_records%ISOPEN THEN
6459          CLOSE c_tot_worker_records;
6460       END IF;
6461       IF c_sum_worker%ISOPEN THEN
6462          CLOSE c_sum_worker;
6463       END IF;
6464       IF c_defer_interface%ISOPEN THEN
6465          CLOSE c_defer_interface;
6466       END IF;
6467       IF c_close_trip%ISOPEN THEN
6468          CLOSE c_close_trip;
6469       END IF;
6470       IF get_pick_up_stops%ISOPEN THEN
6471          CLOSE get_pick_up_stops;
6472       END IF;
6473       IF get_all_stops%ISOPEN THEN
6474          CLOSE get_all_stops;
6475       END IF;
6476       IF c_batch_stop%ISOPEN THEN
6477          CLOSE c_batch_stop;
6478       END IF;
6479       IF c_batch_unplanned_del%ISOPEN THEN
6480          CLOSE c_batch_unplanned_del;
6481       END IF;
6482       IF c_ap_batch%ISOPEN THEN
6483          CLOSE c_ap_batch;
6484       END IF;
6485       IF c_wms_orgs%ISOPEN THEN
6486          CLOSE c_wms_orgs;
6487       END IF;
6488       IF c_wms_details%ISOPEN THEN
6489          CLOSE c_wms_details;
6490       END IF;
6491       IF c_dels_in_batch%ISOPEN THEN
6492          CLOSE c_dels_in_batch;
6493       END IF;
6494       IF c_get_location%ISOPEN THEN
6495          CLOSE c_get_location;
6496       END IF;
6497       IF c_requests%ISOPEN THEN
6498          CLOSE c_requests;
6499       END IF;
6500       IF G_CONC_REQ = FND_API.G_TRUE THEN
6501          l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR','');
6502          errbuf := 'Exception occurred in WSH_PICK_LIST';
6503          retcode := '2';
6504       END IF;
6505       G_ONLINE_PICK_RELEASE_RESULT := 'F';
6506       IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name) THEN
6507 	  IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
6508 	     IF l_debug_on THEN
6509 	        WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
6510 	     END IF;
6511 	     WSH_UTIL_CORE.Reset_stops_for_load_tender(p_reset_flags   => TRUE,
6512 							   x_return_status => l_return_status);
6513 	     IF l_debug_on THEN
6514 	        WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
6515 	     END IF;
6516 	  END IF;
6517       END IF;
6518       --
6519       IF l_debug_on THEN
6520          WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:E_RETURN');
6521       END IF;
6522       --
6523    WHEN OTHERS THEN
6524       --
6525       ROLLBACK;
6526       WSH_UTIL_CORE.PrintMsg('SQLCODE: '||sqlcode||' SQLERRM: '||sqlerrm);
6527       WSH_UTIL_CORE.PrintMsg('Exception occurred in WSH_PICK_LIST');
6528       IF get_orgs%ISOPEN THEN
6529          CLOSE get_orgs;
6530       END IF;
6531       IF get_pack_ship_groups%ISOPEN THEN
6532          CLOSE get_pack_ship_groups;
6533       END IF;
6534       IF get_dels_in_group%ISOPEN THEN
6535          CLOSE get_dels_in_group;
6536       END IF;
6537       IF get_dels_in_batch%ISOPEN THEN
6538          CLOSE get_dels_in_batch;
6539       END IF;
6540       IF c_distinct_organization_id%ISOPEN THEN
6541          CLOSE c_distinct_organization_id;
6542       END IF;
6543       IF c_batch_orgs%ISOPEN THEN
6544          CLOSE c_batch_orgs;
6545       END IF;
6546       IF c_get_backordered_details%ISOPEN THEN
6547          CLOSE c_get_backordered_details;
6548       END IF;
6549       IF c_get_unassigned_details%ISOPEN THEN
6550          CLOSE c_get_unassigned_details;
6551       END IF;
6552       IF c_tot_worker_records%ISOPEN THEN
6553          CLOSE c_tot_worker_records;
6554       END IF;
6555       IF c_sum_worker%ISOPEN THEN
6556          CLOSE c_sum_worker;
6557       END IF;
6558       IF c_defer_interface%ISOPEN THEN
6559          CLOSE c_defer_interface;
6560       END IF;
6561       IF c_close_trip%ISOPEN THEN
6562          CLOSE c_close_trip;
6563       END IF;
6564       IF get_pick_up_stops%ISOPEN THEN
6565          CLOSE get_pick_up_stops;
6566       END IF;
6567       IF get_all_stops%ISOPEN THEN
6568          CLOSE get_all_stops;
6569       END IF;
6570       IF c_batch_stop%ISOPEN THEN
6571          CLOSE c_batch_stop;
6572       END IF;
6573       IF c_batch_unplanned_del%ISOPEN THEN
6574          CLOSE c_batch_unplanned_del;
6575       END IF;
6576       IF c_ap_batch%ISOPEN THEN
6577          CLOSE c_ap_batch;
6578       END IF;
6579       IF c_wms_orgs%ISOPEN THEN
6580          CLOSE c_wms_orgs;
6581       END IF;
6582       IF c_wms_details%ISOPEN THEN
6583          CLOSE c_wms_details;
6584       END IF;
6585       IF c_dels_in_batch%ISOPEN THEN
6586          CLOSE c_dels_in_batch;
6587       END IF;
6588       IF c_get_location%ISOPEN THEN
6589          CLOSE c_get_location;
6590       END IF;
6591       IF c_requests%ISOPEN THEN
6592          CLOSE c_requests;
6593       END IF;
6594       IF G_CONC_REQ = FND_API.G_TRUE THEN
6595          l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR','');
6596          errbuf := 'Exception occurred in WSH_PICK_LIST';
6597          retcode := '2';
6598       END IF;
6599       G_ONLINE_PICK_RELEASE_RESULT := 'F';
6600       IF  upper(WSH_UTIL_CORE.G_START_OF_SESSION_API)  = upper(l_api_session_name) THEN
6601           IF NOT(WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API) THEN
6602              IF l_debug_on THEN
6603                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.Reset_stops_for_load_tender',WSH_DEBUG_SV.C_PROC_LEVEL);
6604              END IF;
6605              WSH_UTIL_CORE.Reset_stops_for_load_tender(p_reset_flags   => TRUE,
6606                                                            x_return_status => l_return_status);
6607              IF l_debug_on THEN
6608                 WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
6609              END IF;
6610           END IF;
6611       END IF;
6612       --
6613       IF l_debug_on THEN
6614          WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured.
6615                            Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
6616          WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
6617       END IF;
6618       --
6619 END Release_Batch;
6620 
6621 
6622 
6623 -- Start of comments
6624 -- API name : Release_Batch_SRS
6625 -- Type     : Public
6626 -- Pre-reqs : None.
6627 -- Procedure: This procedure gets the defaults from Shipping Parameters and
6628 --            generate the batch id.  It saves to the picking batch table and
6629 --            call Release_Batch. It is called from Pick Release SRS.
6630 -- Parameters :
6631 -- IN:
6632 --      p_batch_prefix        IN  Batch Id.
6633 --      p_rule_id             IN  Rule Id.
6634 --      p_log_level           IN  Set the debug log level.
6635 --      p_num_workers         IN  Number of workers
6636 -- OUT:
6637 --      errbuf       OUT NOCOPY  Error message.
6638 --      retcode      OUT NOCOPY  Error Code 1:Successs, 2:Warning and 3:Error.
6639 -- End of comments
6640 PROCEDURE Release_Batch_SRS (
6641       errbuf    OUT NOCOPY   VARCHAR2,
6642       retcode    OUT NOCOPY   VARCHAR2,
6643       p_rule_id  IN   NUMBER,
6644       p_batch_prefix  IN   VARCHAR2,
6645       p_log_level  IN   NUMBER, -- Commented as per GSCC Standards DEFAULT FND_API.G_MISS_NUM  log level fix
6646       p_ship_confirm_rule_id IN NUMBER,
6647       p_actual_departure_date IN VARCHAR2,
6648       p_num_workers IN  NUMBER
6649        ) IS
6650 
6651 	--
6652         l_batch_name  VARCHAR2(30);
6653         l_batch_id  NUMBER;
6654         l_user_id   NUMBER;
6655         l_login_id   NUMBER;
6656         l_ret_code  BOOLEAN;
6657         l_rowid  VARCHAR2(100);
6658         --
6659         l_debug_on BOOLEAN;
6660         l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'RELEASE_BATCH_SRS';
6661         --
6662 	-- rlanka : Pack J Enhancement
6663         --Cursor to get picking rule info
6664 	CURSOR c_RuleInfo(p_ruleID IN NUMBER) IS
6665         --BUG#3330869
6666 	SELECT	name,    --Added bug 7316707
6667 	        organization_id,
6668 		sch_start_days,
6669 		sch_start_hours,
6670 		sch_end_days,
6671 		sch_end_hours,
6672 		req_start_days,
6673 		req_start_hours,
6674 		req_end_days,
6675 		req_end_hours,
6676 		from_scheduled_ship_date,
6677 		to_scheduled_ship_date,
6678 		from_requested_date,
6679 		to_requested_date,
6680 		backorders_only_flag,
6681 		document_set_id,
6682 		existing_rsvs_only_flag,
6683 		shipment_priority_code,
6684 		order_header_id,
6685 		order_type_id,
6686 		ship_from_location_id,
6687 		ship_method_code,
6688 	 	customer_id,
6689 	 	ship_to_location_id,
6690 	 	pick_from_subinventory,
6691 	 	pick_from_locator_id,
6692 	 	default_stage_subinventory,
6693 	 	default_stage_locator_id,
6694 	 	autodetail_pr_flag,
6695 	 	auto_pick_confirm_flag,
6696 	 	ship_set_number,
6697 	 	inventory_item_id,
6698 	 	pick_grouping_rule_id,
6699 	 	pick_sequence_rule_id,
6700 	 	project_id,
6701 	 	task_id,
6702 	 	include_planned_lines,
6703 	 	autocreate_delivery_flag,
6704 	 	ship_confirm_rule_id,
6705 	 	autopack_flag,
6706 	 	autopack_level,
6707 	 	task_planning_flag,
6708 	 	region_id,
6709 	 	zone_id,
6710 	 	category_id,
6711 	 	category_set_id,
6712 	 	ac_delivery_criteria,
6713 		rel_subinventory,
6714 		allocation_method,    --  X-dock
6715 		crossdock_criteria_id, -- X-dock
6716 		append_flag,    --Bug 8225893
6717 		task_priority,
6718                 client_id,  -- LSP PROJECT
6719 		dynamic_replenishment_flag --Bug 10306215: Dynamic replenishment project missing code
6720         FROM wsh_picking_rules
6721         WHERE picking_rule_id = p_ruleID
6722         AND sysdate BETWEEN NVL(start_date_active, SYSDATE) AND NVL(END_DATE_ACTIVE, SYSDATE+1);
6723 
6724         --Cursor to get calendar code
6725         CURSOR c_CalCode(p_orgID NUMBER) IS
6726         SELECT calendar_code
6727         FROM wsh_calendar_assignments
6728         WHERE calendar_type = 'SHIPPING' AND
6729         organization_id = p_orgID AND
6730         enabled_flag = 'Y';
6731         --
6732         l_schStartDate	DATE;
6733         l_schEndDate	DATE;
6734         l_reqStartDate	DATE;
6735         l_reqEndDate	DATE;
6736         v_RuleInfo	c_RuleInfo%ROWTYPE;
6737         v_CalCode	VARCHAR2(10);
6738         --
6739         l_actual_departure_date DATE;
6740         l_request_data          VARCHAR2(30);
6741         l_mode                  VARCHAR2(30);
6742         --
6743         WSH_NO_FUTURE_SHIPDATE  EXCEPTION;
6744 BEGIN
6745    -- Fetch user and login information
6746    --
6747    WSH_UTIL_CORE.Enable_Concurrent_Log_Print;
6748    --
6749    IF p_log_level IS NOT NULL THEN   -- log level fix
6750       WSH_UTIL_CORE.Set_Log_Level(p_log_level);
6751       WSH_UTIL_CORE.PrintMsg('p_log_level is ' || to_char(p_log_level));
6752    END IF;
6753    --
6754    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
6755    --
6756    IF l_debug_on IS NULL
6757    THEN
6758      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
6759    END IF;
6760 
6761    -- Read the Value from REQUEST_DATA. Based on this value, we will know
6762    -- if the Process is restarted after child processes are complete
6763    -- The format of Request_Data is 'Batch_id:Request_Status:Mode', where
6764    -- Batch_id is the Pick Release Batch, Request_Status is either 0 (Success) or 1 (Warning)
6765    -- and Mode is either of the following values.
6766    -- Valid Values :
6767    -- 1) NULL    : Implies First Time or Single Worker Mode
6768    -- 2) PICK-SS : Resuming Parent Process after Child Processes for SMCs/Ship Sets have completed
6769    -- 3) PICK    : Resuming Parent Process after Child Processes for Standard Items have completed
6770    -- 4) PS      : Resuming Parent Process after Child Processes for Pack and Ship have completed
6771    -- Parent process will always be restarted after child processes complete
6772    l_request_data := FND_CONC_GLOBAL.Request_Data;
6773    l_mode         := SUBSTR(l_request_data, INSTR(l_request_data,':',1,2)+1, LENGTH(l_request_data));
6774 
6775    IF l_debug_on THEN
6776       WSH_DEBUG_SV.push(l_module_name);
6777       WSH_DEBUG_SV.log(l_module_name,'P_RULE_ID',P_RULE_ID);
6778       WSH_DEBUG_SV.log(l_module_name,'P_BATCH_PREFIX',P_BATCH_PREFIX);
6779       WSH_DEBUG_SV.log(l_module_name,'P_LOG_LEVEL',P_LOG_LEVEL);
6780       WSH_DEBUG_SV.log(l_module_name,'P_NUM_WORKERS',P_NUM_WORKERS);
6781       WSH_DEBUG_SV.log(l_module_name,'p_Ship_confirm_rule_id',
6782                        p_ship_confirm_rule_id);
6783       WSH_DEBUG_SV.log(l_module_name,'p_Actual_Departure_date',
6784                        p_actual_departure_date);
6785       WSH_DEBUG_SV.log(l_module_name,'l_mode',l_mode);
6786    END IF;
6787 
6788    IF l_mode IS NULL THEN --{
6789 
6790       l_user_id := FND_GLOBAL.USER_ID;
6791       l_login_id := FND_GLOBAL.CONC_LOGIN_ID;
6792       l_actual_departure_date := FND_DATE.CANONICAL_TO_DATE(p_actual_departure_date);
6793 
6794       IF (l_actual_departure_date IS NOT NULL) THEN
6795           IF NOT WSH_UTIL_CORE.ValidateActualDepartureDate(p_ship_confirm_rule_id, l_actual_departure_date) THEN
6796               raise WSH_NO_FUTURE_SHIPDATE;
6797           END IF;
6798       END IF;
6799       --
6800       -- rlanka : Pack J Enhancement
6801       -- common cursor to check existence of rule and also to fetch rule info
6802       --
6803       OPEN c_RuleInfo(p_rule_id);
6804       FETCH c_RuleInfo INTO v_RuleInfo;
6805       --
6806       IF c_RuleInfo%NOTFOUND THEN
6807        --
6808        WSH_UTIL_CORE.PrintMsg('Rule ' || p_rule_id || ' does not exist or has expired');
6809        CLOSE c_RuleInfo;
6810        --
6811        IF l_debug_on THEN
6812          wsh_Debug_sv.pop(l_module_name);
6813        END IF;
6814        --
6815        RETURN;
6816        --
6817       END IF;
6818       --
6819       IF c_RuleInfo%ISOPEN THEN
6820        CLOSE c_RuleInfo;
6821       END IF;
6822 
6823       --
6824       -- rlanka : Pack J Enhancement
6825       -- Get Calendar code
6826       OPEN c_CalCode(v_RuleInfo.organization_id);
6827       FETCH c_CalCode INTO v_CalCode;
6828       CLOSE c_CalCode;
6829       --
6830       IF l_debug_on THEN
6831         wsh_debug_sv.log(l_module_name, 'Org ID for Rule', v_RuleInfo.organization_id);
6832         wsh_debug_sv.log(l_module_name, 'v_calCode', v_CalCode);
6833         wsh_debug_sv.log(l_module_name, 'sch_start_days', v_RuleInfo.sch_start_days);
6834         wsh_debug_sv.log(l_module_name, 'sch_start_hours', v_RuleInfo.sch_start_hours);
6835         wsh_debug_sv.log(l_module_name, 'sch_end_days', v_RuleInfo.sch_end_days);
6836         wsh_debug_sv.log(l_module_name, 'sch_end_hours', v_RuleInfo.sch_end_hours);
6837         wsh_debug_sv.log(l_module_name, 'req_start_days', v_RuleInfo.req_start_days);
6838         wsh_debug_sv.log(l_module_name, 'req_start_hours', v_RuleInfo.req_start_hours);
6839         wsh_debug_sv.log(l_module_name, 'req_end_days', v_RuleInfo.req_end_days);
6840         wsh_debug_sv.log(l_module_name, 'req_end_hours', v_RuleInfo.req_end_hours);
6841         wsh_Debug_sv.log(l_module_name, 'from_scheduled_ship_date', v_RuleInfo.from_scheduled_ship_date);
6842         wsh_Debug_sv.log(l_module_name, 'to_scheduled_ship_date', v_RuleInfo.to_scheduled_ship_date);
6843         wsh_Debug_sv.log(l_module_name, 'from_requested_date', v_RuleInfo.from_requested_date);
6844         wsh_Debug_sv.log(l_module_name, 'to_requested_date', v_RuleInfo.to_requested_date);
6845         wsh_Debug_sv.log(l_module_name, 'Allocation_Method', v_RuleInfo.allocation_method); -- X-dock
6846         wsh_Debug_sv.log(l_module_name, 'Crossdock_Criteria_id', v_RuleInfo.crossdock_criteria_id); --X-dock
6847 	  wsh_Debug_sv.log(l_module_name, 'Dynamic_Replenishment_Flag', v_RuleInfo.dynamic_replenishment_flag); --Bug 10306215
6848       --
6849       END IF;
6850       --
6851       IF v_RuleInfo.sch_start_days IS NOT NULL THEN
6852         --Detrmine the working days
6853         CalcWorkingDay(v_RuleInfo.organization_id,v_RuleInfo.name, v_RuleInfo.sch_start_days, v_RuleInfo.sch_start_hours,
6854    		    v_CalCode, l_schStartDate); --Added  v_RuleInfo.name bug 7316707
6855       END IF;
6856       --
6857       IF v_RuleInfo.sch_end_days IS NOT NULL THEN
6858         CalcWorkingDay(v_RuleInfo.organization_id,v_RuleInfo.name, v_RuleInfo.sch_end_days, v_RuleInfo.sch_end_hours,
6859    		    v_CalCode, l_schEndDate);   --Added  v_RuleInfo.name bug 7316707
6860       END IF;
6861       --
6862       IF v_RuleInfo.req_start_days IS NOT NULL THEN
6863         --Detrmine the working days
6864         CalcWorkingDay(NULL,NULL, v_RuleInfo.req_start_days, v_RuleInfo.req_start_hours,
6865    		    v_CalCode, l_reqStartDate);   --Added  NULL bug 7316707
6866       END IF;
6867       --
6868       IF v_RuleInfo.req_end_days IS NOT NULL THEN
6869         --Detrmine the working days
6870         CalcWorkingDay(NULL,NULL, v_RuleInfo.req_end_days, v_RuleInfo.req_end_hours,
6871    		    v_CalCode, l_reqEndDate);   --Added  NULL bug 7316707
6872       END IF;
6873       --
6874       l_schStartDate := NVL(l_schStartDate, v_RuleInfo.from_scheduled_ship_date);
6875       l_schEndDate := NVL(l_schEndDate, v_RuleInfo.to_scheduled_ship_date);
6876       l_reqStartDate := NVL(l_reqStartDate, v_RuleInfo.from_requested_date);
6877       l_reqEndDate := NVL(l_reqEndDate, v_RuleInfo.to_requested_date);
6878       --
6879       IF l_debug_on THEN
6880         wsh_debug_sv.log(l_module_name, 'calc. scheduled ship start date', l_schStartDate);
6881         wsh_debug_sv.log(l_module_name, 'calc. scheduled ship end date', l_schEndDate);
6882         wsh_debug_sv.log(l_module_name, 'calc. requested start date', l_reqStartDate);
6883         wsh_debug_sv.log(l_module_name, 'calc. requested end date', l_reqEndDate);
6884       END IF;
6885       --
6886       IF l_debug_on THEN
6887         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PICKING_BATCHES_PKG.INSERT_ROW',WSH_DEBUG_SV.C_PROC_LEVEL);
6888       END IF;
6889 
6890       -- bug5117876, insert statement is replace with the following call
6891       WSH_PICKING_BATCHES_PKG.Insert_Row(
6892           X_Rowid                   => l_rowid,
6893           X_Batch_Id                => l_batch_id,
6894           P_Creation_Date           => SYSDATE,
6895           P_Created_By              => l_user_id,
6896           P_Last_Update_Date        => SYSDATE,
6897           P_Last_Updated_By         => l_user_id,
6898           P_Last_Update_Login       => l_login_id,
6899           P_batch_name_prefix       => p_batch_prefix,
6900           X_Name                    => l_batch_name,
6901           P_Backorders_Only_Flag    => v_RuleInfo.BACKORDERS_ONLY_FLAG,
6902           P_Document_Set_Id         => v_RuleInfo.DOCUMENT_SET_ID,
6903           P_Existing_Rsvs_Only_Flag => NVL(v_RuleInfo.EXISTING_RSVS_ONLY_FLAG, 'N'),
6904           P_Shipment_Priority_Code  => v_RuleInfo.SHIPMENT_PRIORITY_CODE,
6905           P_Ship_Method_Code        => v_RuleInfo.SHIP_METHOD_CODE,
6906           P_Customer_Id             => v_RuleInfo.CUSTOMER_ID,
6907           P_Order_Header_Id         => v_RuleInfo.ORDER_HEADER_ID,
6908           P_Ship_Set_Number         => v_RuleInfo.SHIP_SET_NUMBER,
6909           P_Inventory_Item_Id       => v_RuleInfo.INVENTORY_ITEM_ID,
6910           P_Order_Type_Id           => v_RuleInfo.ORDER_TYPE_ID,
6911           P_From_Requested_Date     => l_reqStartDate,
6912           P_To_Requested_Date       => l_reqEndDate,
6913           P_From_Scheduled_Ship_Date => l_schStartDate,
6914           P_To_Scheduled_Ship_Date   => l_schEndDate,
6915           P_Ship_To_Location_Id      => v_RuleInfo.SHIP_TO_LOCATION_ID,
6916           P_Ship_From_Location_Id    => v_RuleInfo.SHIP_FROM_LOCATION_ID,
6917           P_Trip_Id                  => NULL,
6918           P_Delivery_Id              => NULL,
6919           P_Include_Planned_Lines    => v_RuleInfo.INCLUDE_PLANNED_LINES,
6920           P_Pick_Grouping_Rule_Id    => v_RuleInfo.PICK_GROUPING_RULE_ID,
6921           P_pick_sequence_rule_id    => v_RuleInfo.PICK_SEQUENCE_RULE_ID,
6922           P_Autocreate_Delivery_Flag => v_RuleInfo.AUTOCREATE_DELIVERY_FLAG,
6923           P_Attribute_Category       => NULL,
6924           P_Attribute1               => NULL,
6925           P_Attribute2               => NULL,
6926           P_Attribute3               => NULL,
6927           P_Attribute4               => NULL,
6928           P_Attribute5               => NULL,
6929           P_Attribute6               => NULL,
6930           P_Attribute7               => NULL,
6931           P_Attribute8               => NULL,
6932           P_Attribute9               => NULL,
6933           P_Attribute10              => NULL,
6934           P_Attribute11              => NULL,
6935           P_Attribute12              => NULL,
6936           P_Attribute13              => NULL,
6937           P_Attribute14              => NULL,
6938           P_Attribute15              => NULL,
6939           P_Autodetail_Pr_Flag       => v_RuleInfo.AUTODETAIL_PR_FLAG,
6940           P_Carrier_Id               => NULL,
6941           P_Trip_Stop_Id             => NULL,
6942           P_Default_stage_subinventory => v_RuleInfo.DEFAULT_STAGE_SUBINVENTORY,
6943           P_Default_stage_locator_id => v_RuleInfo.DEFAULT_STAGE_LOCATOR_ID,
6944           P_Pick_from_subinventory   => v_RuleInfo.PICK_FROM_SUBINVENTORY,
6945           P_Pick_from_locator_id     => v_RuleInfo.PICK_FROM_LOCATOR_ID,
6946           P_Auto_pick_confirm_flag   => v_RuleInfo.AUTO_PICK_CONFIRM_FLAG,
6947           P_Delivery_Detail_ID       => NULL,
6948           P_Project_ID               => v_RuleInfo.PROJECT_ID,
6949           P_Task_ID                  => v_RuleInfo.TASK_ID,
6950           P_Organization_Id          => v_RuleInfo.ORGANIZATION_ID,
6951           P_Ship_Confirm_Rule_Id     => v_RuleInfo.SHIP_CONFIRM_RULE_ID,
6952           P_Autopack_Flag            => v_RuleInfo.AUTOPACK_FLAG,
6953           P_Autopack_Level           => v_RuleInfo.AUTOPACK_LEVEL,
6954           P_Task_Planning_Flag       => v_RuleInfo.TASK_PLANNING_FLAG,
6955           p_regionID                 => v_RuleInfo.REGION_ID,
6956           p_zoneId                   => v_RuleInfo.ZONE_ID,
6957           p_categoryID               => v_RuleInfo.CATEGORY_ID,
6958           p_categorySetID            => v_RuleInfo.CATEGORY_SET_ID,
6959           p_acDelivCriteria          => v_RuleInfo.AC_DELIVERY_CRITERIA,
6960           p_RelSubinventory          => v_RuleInfo.REL_SUBINVENTORY,
6961           p_actual_departure_date    => l_actual_departure_date,
6962           p_allocation_method        => nvl(v_RuleInfo.ALLOCATION_METHOD,'I'),
6963           p_crossdock_criteria_id    => v_RuleInfo.CROSSDOCK_CRITERIA_ID,
6964           p_append_flag              => v_RuleInfo.APPEND_FLAG,   --Bug 8225893,
6965           p_task_priority            => v_RuleInfo.TASK_PRIORITY,
6966           p_client_id                => v_RuleInfo.CLIENT_ID, -- LSP PROJECT
6967           p_dynamic_replenishment_flag => v_RuleInfo.DYNAMIC_REPLENISHMENT_FLAG); --Bug 10306215
6968       --
6969       IF l_debug_on THEN
6970         WSH_DEBUG_SV.log(l_module_name, 'BATCH NAME ', L_BATCH_NAME);
6971         WSH_DEBUG_SV.log(l_module_name, 'BATCH_ID ', L_BATCH_ID);
6972       END IF;
6973       --
6974 
6975    ELSE
6976       -- Return from worker process
6977       l_batch_id := SUBSTR(l_request_data, 1, INSTR(l_request_data,':',1,1)-1);
6978 
6979    END IF; --}
6980 
6981    --Pick Release the batch
6982    Release_Batch(errbuf, retcode, l_batch_id,p_log_level, NVL(p_num_workers,1));  -- log level fix
6983    --
6984    IF l_debug_on THEN
6985       WSH_DEBUG_SV.log(l_module_name,'ERRBUF',errbuf);
6986       WSH_DEBUG_SV.log(l_module_name,'RETCODE',retcode);
6987       WSH_DEBUG_SV.pop(l_module_name);
6988    END IF;
6989    --
6990 EXCEPTION
6991       --
6992 
6993       WHEN WSH_NO_FUTURE_SHIPDATE THEN
6994 
6995           WSH_UTIL_CORE.PrintMsg('No Lines were selected for Ship Confirmation because Allow Future Ship Date Parameter is disabled and Actual Ship Date is greater than current system date');
6996           l_ret_code := FND_CONCURRENT.SET_COMPLETION_STATUS('WARNING','Release_Batch_SRS');
6997           errbuf := 'Pick Selection List Generation SRS completed with warning';
6998           retcode := '1';
6999           IF l_debug_on THEN
7000               WSH_DEBUG_SV.pop(l_module_name);
7001           END IF;
7002 
7003       WHEN OTHERS THEN
7004 	 --
7005          IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
7006             FND_MSG_PUB.Add_Exc_Msg( 'WSH_PICK_LIST', 'Release_Batch_SRS' );
7007          END IF;
7008 	 --
7009          IF G_CONC_REQ = FND_API.G_TRUE THEN
7010              l_ret_code := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR','');
7011              errbuf := 'Exception occurred in Release_Batch_SRS';
7012              retcode := '2';
7013          END IF;
7014          --
7015          IF l_debug_on THEN
7016             WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
7017             WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
7018          END IF;
7019             --
7020 END Release_Batch_SRS;
7021 
7022 
7023 -- Start of comments
7024 -- API name : Online_Release
7025 -- Type     : Public
7026 -- Pre-reqs : None.
7027 -- Procedure: This procedure calls Release_Batch based on batch id passed,
7028 --            this is call from Release Sales Order from in online mode.
7029 -- Parameters :
7030 -- IN:
7031 --      p_batch_id            IN  Batch Id.
7032 -- OUT:
7033 --      p_pick_result     OUT NOCOPY  Pick Release Phase, Valid value 'START','MOVE ORDER LINE','SUCCESS'.
7034 --      p_pick_phase      OUT NOCOPY  Pick Release Result,Valid value Success,Warning,Error
7035 --      p_pick_skip       OUT NOCOPY  If Pick Release has been skip, valid value Y/N.
7036 -- End of comments
7037 PROCEDURE Online_Release (
7038        p_batch_id  IN   NUMBER,
7039        p_pick_result   OUT NOCOPY   VARCHAR2,
7040        p_pick_phase  OUT NOCOPY   VARCHAR2,
7041        p_pick_skip   OUT NOCOPY   VARCHAR2	/*2432800*/
7042         ) IS
7043         l_dummy1 VARCHAR2(300);
7044         l_dummy2 VARCHAR2(1);
7045         --
7046         l_debug_on BOOLEAN;
7047         l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'ONLINE_RELEASE';
7048         --
7049 BEGIN
7050    --
7051    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
7052    --
7053    IF l_debug_on IS NULL
7054    THEN
7055      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
7056    END IF;
7057    --
7058    IF l_debug_on THEN
7059      WSH_DEBUG_SV.push(l_module_name);
7060      WSH_DEBUG_SV.log(l_module_name,'P_BATCH_ID',P_BATCH_ID);
7061    END IF;
7062    --
7063    G_CONC_REQ := FND_API.G_FALSE;
7064    Release_Batch(l_dummy1,l_dummy2,p_batch_id, p_num_workers => 1);
7065    p_pick_phase :=  G_ONLINE_PICK_RELEASE_PHASE  ;
7066    p_pick_result := G_ONLINE_PICK_RELEASE_RESULT ;
7067    p_pick_skip := G_ONLINE_PICK_RELEASE_SKIP;	/*2432800*/
7068    --
7069    IF l_debug_on THEN
7070    WSH_DEBUG_SV.pop(l_module_name);
7071    END IF;
7072    --
7073 END Online_Release;
7074 
7075 
7076 
7077 -- Start of comments
7078 -- API name : Launch_Pick_Release
7079 -- Type     : Public
7080 -- Pre-reqs : None.
7081 -- Procedure: API to launch pick Release process based on input entity passed. Api dose
7082 --            1. Get the Entity name for the passed entity
7083 --            2. Get the entity status.
7084 --            3. Create picking batch by calling WSH_PICKING_BATCHES_PKG.Insert_Row.
7085 --            4. Update the detail lines with batch id.
7086 --            5. Submit request to release batch created by calling WSH_PICKING_BATCHES_PKG.Submit_Release_Request
7087 -- Parameters :
7088 -- IN:
7089 --      p_trip_ids            IN  Trip id.
7090 --      p_stop_ids            IN  Stop Id.
7091 --      p_delivery_ids        IN  Delivery id.
7092 --      p_detail_ids          IN  Delivery detail Id.
7093 --      p_auto_pack_ship      IN  SC - Auto Ship Confirm after Pick Release
7094 --                                PS - Auto Pack and Ship Confirm after Pick Release.
7095 -- OUT:
7096 --      x_return_status     OUT NOCOPY  Standard to output api status.
7097 --      x_request_ids       OUT NOCOPY  Request ID of concurrent program.
7098 -- End of comments
7099 -- bug# 6719369 (replenishment project): For dynamic replenishment case, WMS passes the delivery detail ids as well as
7100 -- the picking batch id value. In this case it shoud create a new batch by taking the attribute values from the old batch
7101 -- information.
7102 PROCEDURE Launch_Pick_Release(
7103   p_trip_ids   IN  WSH_UTIL_CORE.Id_Tab_Type,
7104   p_stop_ids   IN  WSH_UTIL_CORE.Id_Tab_Type,
7105   p_delivery_ids   IN  WSH_UTIL_CORE.Id_Tab_Type,
7106   p_detail_ids   IN  WSH_UTIL_CORE.Id_Tab_Type,
7107   x_request_ids  OUT NOCOPY  WSH_UTIL_CORE.Id_Tab_Type,
7108   p_auto_pack_ship  IN VARCHAR2 DEFAULT NULL,
7109   p_batch_id        IN NUMBER   DEFAULT NULL, -- bug# 6719369 (replenishment project)
7110   x_return_status   OUT NOCOPY  VARCHAR2
7111   ) IS
7112 
7113    --Cursor to get container attributes.
7114    CURSOR get_container(l_del_detail_id IN VARCHAR2) IS
7115    SELECT container_name, container_flag , organization_id
7116    FROM   WSH_DELIVERY_DETAILS
7117    WHERE  delivery_detail_id = l_del_detail_id;
7118 
7119    --Cursor to get trip status.
7120    CURSOR check_trip(c_trip_id IN NUMBER) IS
7121    select status_code from wsh_trips
7122    where trip_id = c_trip_id;
7123 
7124    --Cursor to get stop status.
7125    CURSOR check_stop(c_stop_id IN NUMBER) IS
7126    select status_code from wsh_trip_stops
7127    where stop_id = c_stop_id;
7128 
7129    --Cursor to get delivery attributes.
7130    CURSOR check_delivery(c_delivery_id IN NUMBER) IS
7131    select status_code, organization_id from wsh_new_deliveries
7132    where delivery_id = c_delivery_id;
7133 
7134    CURSOR check_detail (c_delivery_detail_id IN NUMBER) IS
7135    select released_status from wsh_delivery_details
7136    where delivery_detail_id = c_delivery_detail_id;
7137 
7138    --Cursor to validate auto packing.
7139    CURSOR check_detail_for_AP (c_batch_id IN NUMBER) IS
7140    select distinct p.organization_id
7141    from wsh_delivery_details d, wsh_shipping_parameters p
7142    where d.organization_id = p.organization_id
7143    and NVL(p.autopack_level,0) = 0
7144    and d.batch_id = c_batch_id;
7145 
7146 
7147    --Cursor to validate ship confirm.
7148    CURSOR check_detail_for_SC (c_batch_id IN NUMBER) IS
7149    select distinct p.organization_id, p.ship_confirm_rule_id,
7150                    p.autocreate_deliveries_flag, m.mo_pick_confirm_required
7151    from wsh_delivery_details d, wsh_shipping_parameters p, mtl_parameters m
7152    where d.organization_id = p.organization_id and
7153    m.organization_id = d.organization_id
7154    and (ship_confirm_rule_id IS NULL
7155    or NVL(p.autocreate_deliveries_flag, 'N') <> 'Y'
7156    or NVL(m.mo_pick_confirm_required,0) <> 2)
7157    and d.batch_id = c_batch_id;
7158 
7159    --Cursor to check unassign delivery for an batch.
7160    CURSOR check_unassigned_dels(c_org_id IN NUMBER, c_batch_id IN NUMBER) IS
7161    select 1 from wsh_delivery_assignments_v a, wsh_delivery_details d
7162    where  d.organization_id = c_org_id
7163    and d.batch_id = c_batch_id
7164    and d.delivery_detail_id = a.delivery_detail_id
7165    and a.delivery_id is null
7166    and rownum = 1;
7167 
7168    --Cursor to check inventory pick confirm requried flag.
7169    CURSOR pick_confirm_required_for_del(c_org_id IN NUMBER) IS
7170    select mo_pick_confirm_required
7171    from mtl_parameters
7172    where organization_id = c_org_id;
7173 
7174    --OTM R12, this cursor is found if detail is not assigned to delivery
7175    --and include for planning
7176    CURSOR c_is_detail_assigned(p_detail_id IN NUMBER) IS
7177      SELECT 1
7178      FROM   wsh_delivery_assignments wda,
7179             wsh_delivery_details wdd
7180      WHERE  wda.delivery_detail_id = p_detail_id
7181      AND    wda.delivery_detail_id = wdd.delivery_detail_id
7182      AND    wda.delivery_id IS NULL
7183      AND    NVL(wdd.ignore_for_planning, 'N') = 'N';
7184    --
7185 
7186    CURSOR c_batch_info(x_batch_id NUMBER) IS
7187    SELECT
7188      Document_Set_Id,
7189      Include_Planned_Lines,
7190      Pick_Grouping_Rule_Id,
7191      Pick_Sequence_Rule_Id,
7192      Autocreate_Delivery_Flag,
7193      Attribute_Category,
7194      Attribute1,
7195      Attribute2,
7196      Attribute3,
7197      Attribute4,
7198      Attribute5,
7199      Attribute6,
7200      Attribute7,
7201      Attribute8,
7202      Attribute9,
7203      Attribute10,
7204      Attribute11,
7205      Attribute12,
7206      Attribute13,
7207      Attribute14,
7208      Attribute15,
7209      Autodetail_Pr_Flag,
7210      Default_Stage_Subinventory,
7211      Default_Stage_Locator_Id,
7212      Pick_From_Subinventory,
7213      Pick_From_locator_Id,
7214      Auto_Pick_Confirm_Flag,
7215      Organization_Id,
7216      Ship_Confirm_Rule_Id,
7217      Autopack_Flag,
7218      Autopack_Level,
7219      Task_Planning_Flag,
7220      ac_Delivery_Criteria,
7221      append_flag,
7222      task_priority,
7223      actual_departure_date,
7224      allocation_method,
7225      crossdock_criteria_id,
7226      Non_Picking_Flag,
7227      dynamic_replenishment_flag,
7228      Order_Header_Id,
7229      Order_Type_Id,
7230      Existing_Rsvs_Only_Flag,
7231      client_id -- LSP PROJECT
7232    FROM wsh_picking_batches
7233    WHERE batch_id = x_batch_id;
7234 
7235    l_batch_rec   c_batch_info%ROWTYPE;
7236 
7237    type del_params_cache is record(
7238               organization_id        NUMBER,
7239               ship_confirm_rule_id   NUMBER,
7240               autopack_level         NUMBER,
7241               autopack_flag          VARCHAR2(1),
7242               task_planning_flag     VARCHAR2(1));
7243 
7244    type del_params_cache_tab is table of del_params_cache INDEX BY BINARY_INTEGER;
7245 
7246    l_del_org_params_cache_tab  del_params_cache_tab;
7247 
7248    l_rowid  VARCHAR2(100);
7249    l_batch_id  NUMBER;
7250    l_batch_name  VARCHAR2(30);
7251    l_index   NUMBER;
7252    l_trip_id   NUMBER;
7253    l_stop_id   NUMBER;
7254    l_delivery_id   NUMBER;
7255    l_detail_id   NUMBER;
7256    l_name    VARCHAR2(100);
7257    l_type    VARCHAR2(30);
7258    l_entity_id   NUMBER;
7259    l_container_flag  VARCHAR2(1);
7260    l_entity_status VARCHAR2(2);
7261    l_count_fail  NUMBER := 0;
7262    l_count_succ  NUMBER := 0;
7263    l_temp_autopack_level   NUMBER;
7264    l_ship_confirm_rule_id   NUMBER;
7265    l_autopack_level   NUMBER := NULL;
7266    l_autopack_flag  VARCHAR2(1) := NULL;
7267    l_autocreate_del_flag  VARCHAR2(1);
7268    l_pickconfirm_required NUMBER;
7269    l_del_org NUMBER;
7270    l_det_org NUMBER;
7271    l_param_info   WSH_SHIPPING_PARAMS_PVT.Parameter_Rec_Typ;
7272    l_return_status   VARCHAR2(1);
7273    l_task_planning_flag   VARCHAR2(1) := NULL;
7274    l_non_picking_flag   VARCHAR2(1) := NULL;
7275    l_warn_org   NUMBER;
7276    l_num_warn   NUMBER := 0;
7277    l_org_name   VARCHAR2(240);
7278    l_assigned   NUMBER;
7279    l_cached_flag VARCHAR2(1);
7280    j  NUMBER := 0;
7281 
7282    --OTM R12
7283    l_detail_ids       WSH_UTIL_CORE.Id_Tab_Type;
7284    i                  NUMBER;
7285    l_counter          NUMBER;
7286    l_result           NUMBER;
7287    l_gc3_is_installed VARCHAR2(1);
7288    api_return_fail    EXCEPTION;
7289    --
7290    INVALID_RELEASED_STATUS EXCEPTION;
7291    INVALID_ENTITY_STATUS   EXCEPTION;
7292    --
7293    l_debug_on BOOLEAN;
7294    --
7295    l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'LAUNCH_PICK_RELEASE';
7296    --
7297    l_log_level NUMBER:=0;
7298 
7299 BEGIN
7300    --
7301    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
7302    --
7303    IF l_debug_on IS NULL
7304    THEN
7305      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
7306    END IF;
7307    --
7308    IF l_debug_on THEN
7309       WSH_DEBUG_SV.push(l_module_name);
7310       WSH_DEBUG_SV.log(l_module_name,'TRIP_IDS.COUNT',p_trip_ids.count);
7311       WSH_DEBUG_SV.log(l_module_name,'STOP_IDS.COUNT',p_stop_ids.count);
7312       WSH_DEBUG_SV.log(l_module_name,'DELIVERY_IDS.COUNT',p_delivery_ids.count);
7313       WSH_DEBUG_SV.log(l_module_name,'DETAIL_IDS.COUNT',p_detail_ids.count);
7314       l_log_level := 1;
7315    END IF;
7316 
7317    --OTM R12
7318    --include for planning delivery lines will all be
7319    --set to ignore for planning
7320    l_gc3_is_installed := WSH_UTIL_CORE.G_GC3_IS_INSTALLED; -- this is global variable
7321 
7322    IF l_gc3_is_installed IS NULL THEN
7323      l_gc3_is_installed := WSH_UTIL_CORE.GC3_IS_INSTALLED; -- this is actual function
7324    END IF;
7325 
7326    IF (p_detail_ids.COUNT > 0
7327        AND p_auto_pack_ship IS NOT NULL
7328        AND l_gc3_is_installed = 'Y') THEN
7329 
7330      i := p_detail_ids.FIRST;
7331      l_counter := 1;
7332 
7333      WHILE i IS NOT NULL LOOP
7334 
7335        OPEN c_is_detail_assigned(p_detail_ids(i));
7336        FETCH c_is_detail_assigned INTO l_result;
7337 
7338        -- Only for unassigned include for planning delivery lines, flip the flag
7339        IF (c_is_detail_assigned%FOUND) THEN
7340          l_detail_ids(l_counter) := p_detail_ids(i);
7341          l_counter := l_counter + 1;
7342        END IF;
7343 
7344        CLOSE c_is_detail_assigned;
7345 
7346        i := p_detail_ids.NEXT(i);
7347 
7348      END LOOP;
7349 
7350      IF l_debug_on THEN
7351        WSH_DEBUG_SV.log(l_module_name,'COUNT FOR THE DETAIL_IDS TO IGNORE PLAN',l_detail_ids.COUNT);
7352      END IF;
7353 
7354      IF (l_detail_ids.COUNT > 0) THEN
7355 
7356        WSH_TP_RELEASE.change_ignoreplan_status
7357          (p_entity        => 'DLVB',
7358           p_in_ids        => l_detail_ids,
7359           p_action_code   => 'IGNORE_PLAN',
7360           x_return_status => l_return_status);
7361 
7362        IF l_debug_on THEN
7363          wsh_debug_sv.log(l_module_name,'Return Status After Calling change_ignoreplan_status ',l_return_status);
7364        END IF;
7365 
7366        IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
7367 
7368          --
7369          IF l_debug_on THEN
7370            WSH_DEBUG_SV.logmsg(l_module_name,'ERROR IN WSH_TP_RELEASE.CHANGE_IGNOREPLAN_STATUS');
7371          END IF;
7372          --
7373          RAISE api_return_fail;
7374 
7375        ELSIF (l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING) THEN
7376          l_num_warn := l_num_warn + 1;
7377        END IF;
7378 
7379      END IF;
7380    END IF;
7381    --END OTM R12
7382 
7383    --
7384    IF (p_trip_ids.COUNT > 0) THEN
7385       -- Get the index to the first ID
7386       l_index := p_trip_ids.FIRST;
7387       l_trip_id := p_trip_ids(l_index);
7388       l_type := 'Trip';
7389       --
7390       l_name :=  WSH_TRIPS_PVT.Get_Name(l_trip_id);
7391    ELSIF (p_stop_ids.COUNT > 0) THEN
7392       l_index := p_stop_ids.FIRST;
7393       l_stop_id := p_stop_ids(l_index);
7394       --
7395       l_name := WSH_TRIP_STOPS_PVT.Get_Name(l_stop_id);
7396       l_type := 'Stop';
7397    ELSIF (p_delivery_ids.COUNT > 0) THEN
7398       l_index := p_delivery_ids.FIRST;
7399       l_delivery_id := p_delivery_ids(l_index);
7400       --
7401       l_name := WSH_NEW_DELIVERIES_PVT.Get_Name(l_delivery_id);
7402       l_type := 'Delivery';
7403    ELSIF (p_detail_ids.COUNT > 0) THEN
7404       l_index := p_detail_ids.FIRST;
7405       l_detail_id := p_detail_ids(l_index);
7406 
7407       -- Determine if releasing a line or a container
7408       OPEN get_container(l_detail_id);
7409       FETCH get_container INTO l_name, l_container_flag, l_det_org;
7410       CLOSE get_container;
7411       IF l_container_flag = 'N' THEN
7412          l_name := to_char(l_detail_id);
7413          l_type := 'Line ID';
7414       ELSE
7415          l_type := 'Container';
7416       END IF;
7417       l_detail_id := -1;
7418 
7419       IF p_auto_pack_ship IS NOT NULL THEN
7420 
7421 
7422          IF p_auto_pack_ship = 'PS' THEN
7423 
7424             l_non_picking_flag  := 'P';
7425 
7426          ELSIF p_auto_pack_ship = 'SC' THEN
7427 
7428              l_non_picking_flag  := 'S';
7429 
7430          END IF;
7431 
7432          IF l_debug_on THEN
7433             WSH_DEBUG_SV.log(l_module_name,'ship_confirm_rule_id',l_param_info.ship_confirm_rule_id);
7434          END IF;
7435       END IF;
7436    ELSE
7437        --Non of pick release entity passed.
7438        x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
7439        FND_MESSAGE.SET_NAME('WSH','WSH_PR_NULL_IDS');
7440        WSH_UTIL_CORE.Add_Message(x_return_status);
7441        IF l_debug_on THEN
7442           WSH_DEBUG_SV.pop(l_module_name);
7443        END IF;
7444        --
7445        ROLLBACK; -- 2746314
7446        RETURN;
7447    END IF;
7448 
7449    LOOP
7450    --{
7451       --Get the entity status.
7452 
7453       IF l_type = 'Trip' THEN
7454         OPEN check_trip(l_trip_id);
7455         FETCH check_trip INTO l_entity_status;
7456         CLOSE check_trip;
7457 
7458       ELSIF l_type = 'Stop' THEN
7459         OPEN check_stop(l_stop_id);
7460         FETCH check_stop INTO l_entity_status;
7461         CLOSE check_stop;
7462 
7463       ELSIF l_type = 'Delivery' THEN
7464         OPEN check_delivery(l_delivery_id);
7465         FETCH check_delivery INTO l_entity_status, l_del_org;
7466         CLOSE check_delivery;
7467 
7468         l_cached_flag := 'N';
7469         FOR i in 1..l_del_org_params_cache_tab.count LOOP
7470           IF l_del_org_params_cache_tab(i).organization_id = l_del_org THEN
7471              l_cached_flag := 'Y';
7472              j := i;
7473              EXIT;
7474           END IF;
7475 
7476         END LOOP;
7477 
7478         IF l_cached_flag = 'Y' THEN
7479 
7480            l_task_planning_flag := l_del_org_params_cache_tab(j).task_planning_flag;
7481            l_ship_confirm_rule_id := l_del_org_params_cache_tab(j).ship_confirm_rule_id;
7482            l_autopack_level := l_del_org_params_cache_tab(j).autopack_level;
7483            l_autopack_flag  := l_del_org_params_cache_tab(j).autopack_flag;
7484 
7485         ELSE
7486 
7487            j := l_del_org_params_cache_tab.count + 1;
7488 
7489            l_del_org_params_cache_tab(j).organization_id := l_del_org;
7490 
7491            WSH_SHIPPING_PARAMS_PVT.Get(p_organization_id => l_del_org,
7492                                        x_param_info  => l_param_info,
7493                                        x_return_status   => l_return_status);
7494            l_task_planning_flag := l_param_info.task_planning_flag;
7495            l_del_org_params_cache_tab(j).task_planning_flag := l_task_planning_flag;
7496 
7497 
7498            IF p_auto_pack_ship IS NOT NULL THEN
7499 
7500              OPEN pick_confirm_required_for_del(l_del_org);
7501              FETCH pick_confirm_required_for_del into l_pickconfirm_required;
7502              CLOSE pick_confirm_required_for_del;
7503 
7504              IF l_pickconfirm_required <> 2 THEN
7505                 l_org_name := WSH_UTIL_CORE.Get_Org_Name(l_del_org);
7506                 -- set warning for org
7507                 FND_MESSAGE.SET_NAME('WSH','WSH_NO_AUTOPICK_FOR_ORG');
7508                 FND_MESSAGE.SET_TOKEN('ORG_NAME',l_org_name);
7509                 x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
7510                 WSH_UTIL_CORE.Add_Message(x_return_status);
7511                 l_num_warn := l_num_warn + 1;
7512              END IF;
7513 
7514               -- always ship when action is pick,ship or pick,pack,ship
7515               l_ship_confirm_rule_id := l_param_info.ship_confirm_rule_id;
7516               l_del_org_params_cache_tab(j).ship_confirm_rule_id := l_ship_confirm_rule_id;
7517 
7518               IF l_ship_confirm_rule_id IS NULL THEN
7519                 l_org_name := WSH_UTIL_CORE.Get_Org_Name(l_del_org);
7520                 -- set warning for org
7521                 FND_MESSAGE.SET_NAME('WSH','WSH_NO_SC_RULE_FOR_ORG');
7522                 FND_MESSAGE.SET_TOKEN('ORG_NAME',l_org_name);
7523                 x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
7524                 WSH_UTIL_CORE.Add_Message(x_return_status);
7525                 l_num_warn := l_num_warn + 1;
7526               END IF;
7527 
7528               IF p_auto_pack_ship = 'PS' THEN
7529 
7530                 l_autopack_level := l_param_info.autopack_level;
7531                 l_del_org_params_cache_tab(j).autopack_level := l_autopack_level;
7532                 l_autopack_flag  := 'Y';
7533                 l_del_org_params_cache_tab(j).autopack_flag := l_autopack_flag;
7534 
7535                 IF NVL(l_autopack_level,0) = 0 THEN
7536                   l_org_name := WSH_UTIL_CORE.Get_Org_Name(l_del_org);
7537                    -- set warning for org
7538                   FND_MESSAGE.SET_NAME('WSH','WSH_NO_AP_LEVEL_FOR_ORG');
7539                   FND_MESSAGE.SET_TOKEN('ORG_NAME',l_org_name);
7540                   x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
7541                   WSH_UTIL_CORE.Add_Message(x_return_status);
7542                   l_num_warn := l_num_warn + 1;
7543                END IF;
7544              END IF;
7545            END IF;
7546         END IF;
7547 
7548       END IF;
7549 
7550       --bug# 6719369 (replenishment project) (begin) : For dynamic replenishment case, WMS passes the delivery detail ids as well as
7551       -- the picking batch id value. In this case it shoud create a new batch by taking the attribute values from the old batch
7552       -- information.
7553 
7554       -- Initialize batch id and name to null
7555       -- New batch name and id will be generated
7556       l_batch_id := '';
7557       l_batch_name := '';
7558       --
7559       IF p_batch_id is not null THEN
7560       --{
7561           OPEN  c_batch_info(p_batch_id);
7562           FETCH c_batch_info INTO l_batch_rec;
7563 	  IF c_batch_info%NOTFOUND THEN
7564           --{
7565               IF l_debug_on THEN
7566                   wsh_Debug_sv.log(l_module_name, 'dynamic replenishment (WMS), Invalid batch Id', p_batch_id);
7567 		  WSH_DEBUG_SV.pop(l_module_name);
7568               END IF;
7569 	      x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
7570 	      CLOSE c_batch_info;
7571               RETURN;
7572           --}
7573           END IF;
7574           CLOSE c_batch_info;
7575           --
7576 	  IF l_debug_on THEN
7577               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PICKING_BATCHES_PKG.INSERT_ROW',WSH_DEBUG_SV.C_PROC_LEVEL);
7578           END IF;
7579           --
7580           WSH_PICKING_BATCHES_PKG.Insert_Row(
7581           X_Rowid   => l_rowid,
7582           X_Batch_Id     => l_batch_id,
7583           P_Creation_Date => NULL,
7584           P_Created_By   => NULL,
7585           P_Last_Update_Date   => NULL,
7586           P_Last_Updated_By  => NULL,
7587           P_Last_Update_Login  => NULL,
7588           X_Name     => l_batch_name,
7589           P_Backorders_Only_Flag   => 'M',  -- consider only replenishment completed delivery detail lines.
7590           P_Document_Set_Id  => l_batch_rec.Document_Set_Id,
7591           P_Existing_Rsvs_Only_Flag => l_batch_rec.Existing_Rsvs_Only_Flag,
7592           P_Shipment_Priority_Code   => NULL,
7593           P_Ship_Method_Code   => NULL,
7594           P_Customer_Id => NULL,
7595           P_Order_Header_Id  => l_batch_rec.Order_Header_Id,
7596           P_Ship_Set_Number  => NULL,
7597           P_Inventory_Item_Id  => NULL,
7598           P_Order_Type_Id => l_batch_rec.Order_Type_Id,
7599           P_From_Requested_Date   => NULL,
7600           P_To_Requested_Date  => NULL,
7601           P_From_Scheduled_Ship_Date   => NULL,
7602           P_To_Scheduled_Ship_Date   => NULL,
7603           P_Ship_To_Location_Id   => NULL,
7604           P_Ship_From_Location_Id   => NULL,
7605           P_Trip_Id => NULL,
7606           P_Delivery_Id  => NULL,
7607           P_Include_Planned_Lines   => 'Y',   -- Bug 6908504 (replenishment
7608 -- project): Replenishment Completed dd's may be associated to deliveries.
7609           P_Pick_Grouping_Rule_Id   => l_batch_rec.Pick_Grouping_Rule_Id,
7610           P_pick_sequence_rule_id   => l_batch_rec.pick_sequence_rule_id,
7611           P_Autocreate_Delivery_Flag   => l_batch_rec.Autocreate_Delivery_Flag,
7612           P_Attribute_Category   => l_batch_rec.Attribute_Category,
7613           P_Attribute1   => l_batch_rec.Attribute1,
7614           P_Attribute2   => l_batch_rec.Attribute2,
7615           P_Attribute3   => l_batch_rec.Attribute3,
7616           P_Attribute4   => l_batch_rec.Attribute4,
7617           P_Attribute5   => l_batch_rec.Attribute5,
7618           P_Attribute6   => l_batch_rec.Attribute6,
7619           P_Attribute7   => l_batch_rec.Attribute7,
7620           P_Attribute8   => l_batch_rec.Attribute8,
7621           P_Attribute9   => l_batch_rec.Attribute9,
7622           P_Attribute10 => l_batch_rec.Attribute10,
7623           P_Attribute11 => l_batch_rec.Attribute11,
7624           P_Attribute12 => l_batch_rec.Attribute12,
7625           P_Attribute13 => l_batch_rec.Attribute13,
7626           P_Attribute14 => l_batch_rec.Attribute14,
7627           P_Attribute15 => l_batch_rec.Attribute15,
7628           P_Autodetail_Pr_Flag   => l_batch_rec.Autodetail_Pr_Flag,
7629           P_Carrier_Id   => NULL,
7630           P_Trip_Stop_Id   => NULL,
7631           P_Default_stage_subinventory => l_batch_rec.Default_stage_subinventory,
7632           P_Default_stage_locator_id   => l_batch_rec.Default_stage_locator_id,
7633           P_Pick_from_subinventory   => l_batch_rec.Pick_from_subinventory,
7634           P_Pick_from_locator_id   => l_batch_rec.Pick_from_locator_id ,
7635           P_Auto_pick_confirm_flag   => l_batch_rec.Auto_pick_confirm_flag,
7636           P_Delivery_Detail_ID   => -1,
7637           P_Project_ID   => NULL,
7638           P_Task_ID => NULL,
7639           P_Organization_Id  => l_batch_rec.Organization_Id,
7640           P_Ship_Confirm_Rule_Id   => l_batch_rec.ship_confirm_rule_id,
7641           P_Autopack_Flag => l_batch_rec.autopack_flag,
7642           P_Autopack_Level   => l_batch_rec.autopack_level,
7643           P_TASK_PLANNING_FLAG   => l_batch_rec.task_planning_flag,
7644           P_Non_Picking_Flag   => l_batch_rec.non_picking_flag,
7645 	  /* Enhancement */
7646 	  p_RegionID	=> NULL,
7647 	  p_ZoneID	=> NULL,
7648 	  p_categoryID	=> NULL,
7649           p_categorySetID => NULL,
7650           p_acDelivCriteria => l_batch_rec.ac_Delivery_Criteria,
7651 	  p_RelSubinventory => NULL,
7652 	  -- deliveryMerge
7653 	  p_append_flag => l_batch_rec.append_flag,
7654           p_task_priority => l_batch_rec.task_priority,
7655           p_actual_departure_date => l_batch_rec.actual_departure_date,
7656           p_allocation_method => l_batch_rec.allocation_method,
7657           p_crossdock_criteria_id => l_batch_rec.crossdock_criteria_id,
7658 	  P_dynamic_replenishment_flag => l_batch_rec.dynamic_replenishment_flag,
7659           p_selected_batch_id          => p_batch_id,  --Bug# 8492625  :Need to store the original picking batch id value.
7660           p_client_id              => l_batch_rec.client_id -- LSP PROJECT
7661            );
7662           --
7663       ELSE
7664           --
7665           --
7666           IF l_debug_on THEN
7667               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PICKING_BATCHES_PKG.INSERT_ROW',WSH_DEBUG_SV.C_PROC_LEVEL);
7668           END IF;
7669           --
7670           WSH_PICKING_BATCHES_PKG.Insert_Row(
7671           X_Rowid   => l_rowid,
7672           X_Batch_Id     => l_batch_id,
7673           P_Creation_Date => NULL,
7674           P_Created_By   => NULL,
7675           P_Last_Update_Date   => NULL,
7676           P_Last_Updated_By  => NULL,
7677           P_Last_Update_Login  => NULL,
7678           X_Name     => l_batch_name,
7679           P_Backorders_Only_Flag   => 'I',
7680           P_Document_Set_Id  => NULL,
7681           P_Existing_Rsvs_Only_Flag => NULL,
7682           P_Shipment_Priority_Code   => NULL,
7683           P_Ship_Method_Code   => NULL,
7684           P_Customer_Id => NULL,
7685           P_Order_Header_Id  => NULL,
7686           P_Ship_Set_Number  => NULL,
7687           P_Inventory_Item_Id  => NULL,
7688           P_Order_Type_Id => NULL,
7689           P_From_Requested_Date   => NULL,
7690           P_To_Requested_Date  => NULL,
7691           P_From_Scheduled_Ship_Date   => NULL,
7692           P_To_Scheduled_Ship_Date   => NULL,
7693           P_Ship_To_Location_Id   => NULL,
7694           P_Ship_From_Location_Id   => NULL,
7695           P_Trip_Id => l_trip_id,
7696           P_Delivery_Id  => l_delivery_id,
7697           P_Include_Planned_Lines   => 'Y',
7698           P_Pick_Grouping_Rule_Id   => NULL,
7699           P_pick_sequence_rule_id   => NULL,
7700           P_Autocreate_Delivery_Flag   => NULL,
7701           P_Attribute_Category   => NULL,
7702           P_Attribute1   => NULL,
7703           P_Attribute2   => NULL,
7704           P_Attribute3   => NULL,
7705           P_Attribute4   => NULL,
7706           P_Attribute5   => NULL,
7707           P_Attribute6   => NULL,
7708           P_Attribute7   => NULL,
7709           P_Attribute8   => NULL,
7710           P_Attribute9   => NULL,
7711           P_Attribute10 => NULL,
7712           P_Attribute11 => NULL,
7713           P_Attribute12 => NULL,
7714           P_Attribute13 => NULL,
7715           P_Attribute14 => NULL,
7716           P_Attribute15 => NULL,
7717           P_Autodetail_Pr_Flag   => NULL,
7718           P_Carrier_Id   => NULL,
7719           P_Trip_Stop_Id   => l_stop_id,
7720           P_Default_stage_subinventory => NULL,
7721           P_Default_stage_locator_id   => NULL,
7722           P_Pick_from_subinventory   => NULL,
7723           P_Pick_from_locator_id   => NULL,
7724           P_Auto_pick_confirm_flag   => NULL,
7725           P_Delivery_Detail_ID   => l_detail_id,
7726           P_Project_ID   => NULL,
7727           P_Task_ID => NULL,
7728           P_Organization_Id  => NULL,
7729           P_Ship_Confirm_Rule_Id   => l_ship_confirm_rule_id,
7730           P_Autopack_Flag => l_autopack_flag,
7731           P_Autopack_Level   => l_autopack_level,
7732           P_TASK_PLANNING_FLAG   => l_task_planning_flag,
7733           P_Non_Picking_Flag   => l_Non_Picking_Flag,
7734 	  /* Enhancement */
7735 	  p_RegionID	=> NULL,
7736 	  p_ZoneID	=> NULL,
7737 	  p_categoryID	=> NULL,
7738           p_categorySetID => NULL,
7739           p_acDelivCriteria => NULL,
7740 	  p_RelSubinventory => NULL,
7741 	  -- deliveryMerge
7742 	  p_append_flag => 'N',
7743           p_task_priority => NULL,
7744           p_actual_departure_date => NULL,
7745           p_allocation_method => 'I', --X-dock
7746           p_crossdock_criteria_id => NULL, -- X-dock
7747           p_client_id             => NULL -- LSP PROJECT
7748           );
7749       --}
7750       END IF;
7751       --bug# 6719369 (replenishment project): end
7752 
7753       IF p_detail_ids.count > 0 THEN
7754             --Update the detail lines with batch id.
7755             FORALL i in 1..p_detail_ids.count
7756             update wsh_delivery_details
7757             set batch_id = l_batch_id
7758             where released_status in ('R', 'B', 'X')
7759             and   nvl(replenishment_status,'C') = 'C'  --bug# 6719369 (replenishment project)
7760             and delivery_detail_id = p_detail_ids(i);
7761 
7762             IF sql%notfound then
7763 	       l_detail_id := p_detail_ids(1); --Bug#: 2870731
7764                IF l_debug_on THEN
7765                  for i in 1..p_detail_ids.count loop
7766                     WSH_DEBUG_SV.logmsg(l_module_name,'Unreleased delivery_detail -> '||p_detail_ids(i),WSH_DEBUG_SV.C_PROC_LEVEL);
7767                  end loop;
7768                END IF;
7769                RAISE INVALID_RELEASED_STATUS;
7770             END IF;
7771 
7772             IF l_debug_on THEN
7773                for i in 1..p_detail_ids.count loop
7774                   WSH_DEBUG_SV.logmsg(l_module_name,'updating delivery_detail '||p_detail_ids(i) ||' with batch '||l_batch_id,WSH_DEBUG_SV.C_PROC_LEVEL);
7775                end loop;
7776 
7777             END IF;
7778 
7779             IF p_auto_pack_ship in ('SC', 'PS') THEN
7780                OPEN check_detail_for_SC (l_batch_id);
7781                LOOP
7782 
7783                 FETCH check_detail_for_SC into  l_warn_org, l_ship_confirm_rule_id,
7784                                                 l_autocreate_del_flag, l_pickconfirm_required;
7785                 EXIT when check_detail_for_SC%NOTFOUND;
7786                 l_org_name := WSH_UTIL_CORE.Get_Org_Name(l_warn_org);
7787                 -- set warning for org
7788                 IF l_ship_confirm_rule_id IS NULL THEN
7789                   FND_MESSAGE.SET_NAME('WSH','WSH_NO_SC_RULE_FOR_ORG');
7790                   FND_MESSAGE.SET_TOKEN('ORG_NAME',l_org_name);
7791                   x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
7792                   WSH_UTIL_CORE.Add_Message(x_return_status);
7793                   l_num_warn := l_num_warn + 1;
7794                 END IF;
7795                 IF NVL(l_pickconfirm_required,0) <> 2 THEN
7796                   FND_MESSAGE.SET_NAME('WSH','WSH_NO_AUTOPICK_FOR_ORG');
7797                   FND_MESSAGE.SET_TOKEN('ORG_NAME',l_org_name);
7798                   x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
7799                   WSH_UTIL_CORE.Add_Message(x_return_status);
7800                   l_num_warn := l_num_warn + 1;
7801                 END IF;
7802                 IF NVL(l_autocreate_del_flag, 'N') <> 'Y' THEN
7803                   OPEN check_unassigned_dels(l_warn_org, l_batch_id);
7804                   FETCH check_unassigned_dels INTO l_assigned;
7805                   IF check_unassigned_dels%FOUND THEN
7806                      FND_MESSAGE.SET_NAME('WSH','WSH_NO_DELS_FOR_ORG');
7807                      FND_MESSAGE.SET_TOKEN('ORG_NAME',l_org_name);
7808                      x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
7809                      WSH_UTIL_CORE.Add_Message(x_return_status);
7810                      l_num_warn := l_num_warn + 1;
7811                    END IF;
7812                    CLOSE check_unassigned_dels;
7813                  END IF;
7814                END LOOP;
7815                IF check_detail_for_SC%isopen THEN
7816                  CLOSE check_detail_for_SC;
7817                END IF;
7818             END IF;
7819             IF p_auto_pack_ship = 'PS' THEN
7820                OPEN check_detail_for_AP (l_batch_id);
7821                LOOP
7822                  FETCH check_detail_for_AP into l_warn_org;
7823                  EXIT when check_detail_for_AP%NOTFOUND;
7824                  -- set message for org
7825                  l_org_name := WSH_UTIL_CORE.Get_Org_Name(l_warn_org);
7826                  FND_MESSAGE.SET_NAME('WSH','WSH_NO_AP_LEVEL_FOR_ORG');
7827                  FND_MESSAGE.SET_TOKEN('ORG_NAME',l_org_name);
7828                  x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
7829                  WSH_UTIL_CORE.Add_Message(x_return_status);
7830                  l_num_warn := l_num_warn + 1;
7831                END LOOP;
7832                IF check_detail_for_AP%isopen THEN
7833                  CLOSE check_detail_for_AP;
7834                END IF;
7835             END IF;
7836       END IF;
7837 
7838 
7839       IF l_debug_on THEN
7840          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_PICKING_BATCHES_PKG.SUBMIT_RELEASE_REQUEST',WSH_DEBUG_SV.C_PROC_LEVEL);
7841       END IF;
7842       --Submit request to release batch created.
7843       x_request_ids(l_index) := WSH_PICKING_BATCHES_PKG.Submit_Release_Request(
7844                                                                                p_batch_id    =>  l_batch_id,
7845                                                                                p_log_level   =>  l_log_level,
7846                                                                                p_num_workers =>  1, -- Always 1
7847                                                                                p_commit      =>  'N');
7848       IF (x_request_ids(l_index) = 0) THEN
7849          x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
7850          FND_MESSAGE.SET_NAME('WSH','WSH_PR_LAUNCH_FAILED');
7851          FND_MESSAGE.SET_TOKEN('RELEASE_TYPE',l_type);
7852          FND_MESSAGE.SET_TOKEN('NAME',l_name);
7853          WSH_UTIL_CORE.Add_Message(x_return_status);
7854          l_count_fail := l_count_fail + 1;
7855       ELSE
7856          x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
7857          FND_MESSAGE.SET_NAME('WSH','WSH_PR_LAUNCH_SUCCESS');
7858         --change for Bug#3379553
7859         -- FND_MESSAGE.SET_TOKEN('RELEASE_TYPE',l_type);
7860         -- FND_MESSAGE.SET_TOKEN('NAME',l_name);
7861         --End of change for Bug#3379553
7862          FND_MESSAGE.SET_TOKEN('REQUEST_ID', to_char(x_request_ids(l_index)));
7863          WSH_UTIL_CORE.Add_Message(x_return_status);
7864          l_count_succ := l_count_succ + 1;
7865       END IF;
7866 
7867       IF l_trip_id IS NOT NULL THEN
7868          EXIT WHEN l_index = p_trip_ids.LAST;
7869          l_index := p_trip_ids.NEXT(l_index);
7870          l_trip_id := p_trip_ids(l_index);
7871          --
7872          IF l_debug_on THEN
7873            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_TRIPS_PVT.GET_NAME',WSH_DEBUG_SV.C_PROC_LEVEL);
7874          END IF;
7875             --
7876             l_name := WSH_TRIPS_PVT.Get_Name(l_trip_id);
7877       ELSIF l_stop_id IS NOT NULL THEN
7878             EXIT WHEN l_index = p_stop_ids.LAST;
7879             l_index := p_stop_ids.NEXT(l_index);
7880             l_stop_id := p_stop_ids(l_index);
7881             --
7882             IF l_debug_on THEN
7883               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_TRIP_STOPS_PVT.GET_NAME',WSH_DEBUG_SV.C_PROC_LEVEL);
7884             END IF;
7885             --
7886             l_name := WSH_TRIP_STOPS_PVT.Get_Name(l_stop_id);
7887       ELSIF l_delivery_id IS NOT NULL THEN
7888             EXIT WHEN l_index = p_delivery_ids.LAST;
7889             l_index := p_delivery_ids.NEXT(l_index);
7890             l_delivery_id := p_delivery_ids(l_index);
7891             --
7892             IF l_debug_on THEN
7893               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_NEW_DELIVERIES_PVT.GET_NAME',WSH_DEBUG_SV.C_PROC_LEVEL);
7894             END IF;
7895             --
7896             l_name := WSH_NEW_DELIVERIES_PVT.Get_Name(l_delivery_id);
7897       ELSE
7898             EXIT;  -- Only one loop when launching pick release for delivery details.
7899       END IF;
7900 
7901    --}
7902    END LOOP;
7903 
7904    IF l_count_fail > 0 THEN
7905       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
7906    END IF;
7907 
7908 
7909 
7910    -- Summary message
7911    FND_MESSAGE.SET_NAME('WSH','WSH_PR_LAUNCH_SUMMARY');
7912    FND_MESSAGE.SET_TOKEN('SUCCESS',to_char(l_count_succ));
7913    FND_MESSAGE.SET_TOKEN('FAIL',to_char(l_count_fail));
7914    WSH_UTIL_CORE.Add_Message(x_return_status);
7915 
7916    IF ((l_num_warn > 0) and (x_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS)) THEN
7917 
7918       x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
7919       FND_MESSAGE.SET_NAME('WSH','WSH_QS_LAUNCH_SUMMARY');
7920       WSH_UTIL_CORE.Add_Message(x_return_status);
7921 
7922    END IF;
7923    --
7924    IF l_debug_on THEN
7925      WSH_DEBUG_SV.pop(l_module_name);
7926    END IF;
7927    --
7928 EXCEPTION
7929     --OTM R12
7930     WHEN api_return_fail THEN
7931       x_return_status := l_return_status;
7932       IF l_debug_on THEN
7933         WSH_DEBUG_SV.log(l_module_name, 'x_return_status', x_return_status);
7934         WSH_DEBUG_SV.pop(l_module_name);
7935       END IF;
7936     --END OTM R12
7937 
7938     WHEN INVALID_RELEASED_STATUS THEN
7939           --OTM R12
7940           IF (c_is_detail_assigned%ISOPEN) THEN
7941             CLOSE c_is_detail_assigned;
7942           END IF;
7943           --
7944 
7945           x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
7946           FND_MESSAGE.SET_NAME('WSH','WSH_PR_INVALID_DETAIL');
7947           FND_MESSAGE.SET_TOKEN('detail',to_char(l_detail_id));
7948           WSH_UTIL_CORE.Add_Message(x_return_status);
7949           --
7950           -- Debug Statements
7951           --
7952           IF l_debug_on THEN
7953           WSH_DEBUG_SV.logmsg(l_module_name,'INVALID_RELEASED_STATUS exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
7954           WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:INVALID_RELEASED_STATUS');
7955           END IF;
7956           --
7957           return;
7958 
7959     WHEN INVALID_ENTITY_STATUS THEN
7960           --OTM R12
7961           IF (c_is_detail_assigned%ISOPEN) THEN
7962             CLOSE c_is_detail_assigned;
7963           END IF;
7964           --
7965 
7966           x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
7967           FND_MESSAGE.SET_NAME('WSH','WSH_PR_INVALID_ENTITY');
7968           FND_MESSAGE.SET_TOKEN('entity_type',lower(l_type));
7969           IF l_type = 'Trip' THEN
7970              l_entity_id := l_trip_id;
7971           ELSIF l_type = 'Stop' THEN
7972              l_entity_id := l_stop_id;
7973           ELSIF l_type = 'Delivery' THEN
7974              l_entity_id := l_delivery_id;
7975           END IF;
7976           FND_MESSAGE.SET_TOKEN('entity_id',l_entity_id);
7977           WSH_UTIL_CORE.Add_Message(x_return_status);
7978           --
7979           -- Debug Statements
7980           --
7981           IF l_debug_on THEN
7982              WSH_DEBUG_SV.logmsg(l_module_name,'INVALID_ENTITY_STATUS exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
7983              WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:INVALID_ENTITY_STATUS');
7984           END IF;
7985           --
7986           return;
7987 
7988     WHEN Others THEN
7989          --OTM R12
7990          IF (c_is_detail_assigned%ISOPEN) THEN
7991            CLOSE c_is_detail_assigned;
7992          END IF;
7993          --
7994 
7995          WSH_UTIL_CORE.Default_Handler('WSH_PICK_LIST.Launch_Pick_Release');
7996          x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
7997          IF check_detail_for_SC%ISOPEN THEN
7998             CLOSE check_detail_for_SC;
7999          END IF;
8000          IF check_detail_for_AP%ISOPEN THEN
8001             CLOSE check_detail_for_AP;
8002          END IF;
8003          IF get_container%ISOPEN THEN
8004           CLOSE get_container;
8005          END IF;
8006          IF pick_confirm_required_for_del%ISOPEN THEN
8007             CLOSE pick_confirm_required_for_del;
8008          END IF;
8009          IF check_unassigned_dels%ISOPEN THEN
8010           CLOSE check_unassigned_dels;
8011          END IF;
8012          --
8013          -- Debug Statements
8014          --
8015          IF l_debug_on THEN
8016          WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
8017          WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
8018          END IF;
8019          --
8020 END Launch_Pick_Release;
8021 
8022 -- Start of comments
8023 -- API name : Calculate_Reservations
8024 -- Type     : Public
8025 -- Pre-reqs : None.
8026 -- Procedure: API to calculate the Reservations quantity, api does
8027 --            1. Scan through global demand table and find out if reservation exists for input header and line.
8028 --            2. If not fetch the reservation from inventory reservation table.
8029 --            3. Calculate the reservation quantity (Primary and Secondary).
8030 -- Parameters :
8031 -- IN:
8032 --      p_demand_source_header_id        IN  Demand hedaer id.
8033 --      p_demand_source_line_id          IN  Demand line id.
8034 --      p_requested_quantity             IN  Requested Quantity.
8035 --      p_requested_quantity_uom         IN  Requested Quantity UOM.
8036 --      p_src_requested_quantity_uom     IN  Source Requested Quantity UOM.
8037 --      p_src_requested_quantity         IN  Source Requested Quantity.
8038 --      p_src_requested_quantity2        IN  Source Secondary Requested Quantity.
8039 --      p_inv_item_id                    IN  Item Id.
8040 --      p_requested_quantity2            IN  Secondary Requested Quantity.
8041 -- OUT:
8042 --      x_fulfill_base  OUT NOCOPY Fulfillment Base.
8043 --      x_result        OUT NOCOPY Reservations quantity.
8044 --      x_result2       OUT NOCOPY Secondary Reservations quantity.
8045 -- End of comments
8046 -- HW OPMCONV - Added parameter p_requested_quantity2
8047 --Bug 4775539 added four IN parameters
8048 
8049 PROCEDURE Calculate_Reservations(
8050     p_demand_source_header_id IN NUMBER,
8051     p_demand_source_line_id   IN NUMBER,
8052     p_requested_quantity IN NUMBER,
8053     -- Bug 4775539
8054     p_requested_quantity_uom     IN VARCHAR2,
8055     p_src_requested_quantity_uom IN VARCHAR2,
8056     p_src_requested_quantity     IN NUMBER,
8057     -- muom
8058     p_src_requested_quantity2    IN NUMBER,
8059     p_inv_item_id                IN NUMBER,
8060     p_requested_quantity2 IN NUMBER default NULL,
8061     -- muom
8062     x_fulfill_base OUT NOCOPY VARCHAR2,
8063     x_result  OUT NOCOPY  NUMBER,
8064     x_result2 OUT NOCOPY  NUMBER) IS
8065 
8066    --Cursor to get the reservation quantity from inventory table.
8067    CURSOR reservation_quantity(c_demand_source_header_id IN NUMBER,
8068 			       c_demand_source_line_id IN NUMBER) is
8069 -- HW OPMCONV - Added qty2
8070    SELECT  SUM(mr.primary_reservation_quantity - nvl(mr.detailed_quantity,0)),
8071           SUM(mr.SECONDARY_RESERVATION_QUANTITY - nvl(mr.SECONDARY_DETAILED_QUANTITY,0))
8072    FROM   mtl_reservations mr
8073    WHERE  mr.demand_source_header_id = c_demand_source_header_id
8074    AND mr.demand_source_line_id   = c_demand_source_line_id
8075    AND nvl(mr.subinventory_code, nvl(WSH_PR_CRITERIA.g_from_subinventory,'-99')) = nvl(WSH_PR_CRITERIA.g_from_subinventory,nvl(mr.subinventory_code,'-99'))
8076    AND nvl(mr.locator_id, nvl(WSH_PR_CRITERIA.g_from_locator,'-99')) = nvl(WSH_PR_CRITERIA.g_from_locator,nvl(mr.locator_id,-99))
8077    AND nvl(mr.staged_flag, 'N') <> 'Y'
8078    AND mr.primary_reservation_quantity - nvl(mr.detailed_quantity,0) > 0
8079    AND mr.demand_source_type_id IN (2,8) -- Bug 4046748
8080    AND mr.supply_source_type_id = 13; -- Bug 4046748;
8081 
8082    -- Bug 4775539
8083    CURSOR discard_reservation_quantity(
8084             c_demand_source_header_id IN NUMBER,
8085 	    c_demand_source_line_id IN NUMBER) is
8086    SELECT SUM(mr.primary_reservation_quantity - nvl(mr.detailed_quantity,0)),
8087           SUM(mr.SECONDARY_RESERVATION_QUANTITY - nvl(mr.SECONDARY_DETAILED_QUANTITY,0))
8088    FROM   mtl_reservations mr
8089    WHERE  mr.demand_source_header_id = c_demand_source_header_id
8090    AND    mr.demand_source_line_id   = c_demand_source_line_id
8091    AND ((nvl(mr.staged_flag, 'N') <> 'Y'
8092         AND (nvl(mr.subinventory_code, nvl(WSH_PR_CRITERIA.g_from_subinventory,'-99')) <> nvl(WSH_PR_CRITERIA.g_from_subinventory,nvl(mr.subinventory_code,'-99'))
8093              OR  nvl(mr.locator_id, nvl(WSH_PR_CRITERIA.g_from_locator,-99)) <> nvl(WSH_PR_CRITERIA.g_from_locator,nvl(mr.locator_id,-99))))
8094       OR (nvl(mr.staged_flag, 'N') = 'Y'))
8095    AND mr.primary_reservation_quantity - nvl(mr.detailed_quantity,0) > 0
8096    AND mr.demand_source_type_id IN (2,8)
8097    AND mr.supply_source_type_id = 13;
8098 
8099    l_total_requested_quantity number;
8100    --Variable added for bug 6459193
8101    l_unallocated_quantity     number;
8102 
8103    l_demand_exists BOOLEAN;
8104    l_reservation_quantity NUMBER := 0;
8105 -- HW OPMCONV - Added qty2
8106    l_reservation_quantity2 NUMBER := 0;
8107    --
8108    l_debug_on BOOLEAN;
8109    l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CALCULATE_RESERVATIONS';
8110    --
8111    l_hash_string      VARCHAR2(1000) := NULL;
8112    l_hash_value       NUMBER;
8113    l_hash_exists      BOOLEAN;
8114    -- muom
8115    l_fulfill_base     varchar2(1);
8116    l_total_requested_quantity2 number;
8117    l_unallocated_quantity2 number;
8118 
8119 BEGIN
8120    --
8121    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
8122    --
8123    IF l_debug_on IS NULL THEN
8124      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
8125    END IF;
8126    --
8127    IF l_debug_on THEN
8128       WSH_DEBUG_SV.push(l_module_name);
8129       WSH_DEBUG_SV.log(l_module_name,'P_DEMAND_SOURCE_HEADER_ID',P_DEMAND_SOURCE_HEADER_ID);
8130       WSH_DEBUG_SV.log(l_module_name,'P_DEMAND_SOURCE_LINE_ID',P_DEMAND_SOURCE_LINE_ID);
8131       WSH_DEBUG_SV.log(l_module_name,'P_REQUESTED_QUANTITY',P_REQUESTED_QUANTITY);
8132 -- HW OPMCONV - Added requested_qty2
8133       WSH_DEBUG_SV.log(l_module_name,'P_REQUESTED_QUANTITY2',P_REQUESTED_QUANTITY2);
8134       -- Bug 4775539
8135       WSH_DEBUG_SV.log(l_module_name,'P_REQUESTED_QUANTITY_UOM',P_REQUESTED_QUANTITY_UOM);
8136       WSH_DEBUG_SV.log(l_module_name,'P_SRC_REQUESTED_QUANTITY_UOM',P_SRC_REQUESTED_QUANTITY_UOM);
8137       WSH_DEBUG_SV.log(l_module_name,'P_SRC_REQUESTED_QUANTITY',P_SRC_REQUESTED_QUANTITY);
8138       -- muom
8139       WSH_DEBUG_SV.log(l_module_name,'P_SRC_REQUESTED_QUANTITY2',P_SRC_REQUESTED_QUANTITY2);
8140       WSH_DEBUG_SV.log(l_module_name,'P_INV_ITEM_ID',P_INV_ITEM_ID);
8141    END IF;
8142    --
8143    l_demand_exists := FALSE;
8144    l_hash_exists   := FALSE;
8145    --
8146    -- muom
8147    IF WSH_UTIL_CORE.Get_Line_Fulfillment_Base('OE', p_demand_source_line_id) = 'S' THEN
8148      l_fulfill_base := 'S';
8149    ELSE
8150      l_fulfill_base := 'P';
8151    END IF;
8152    x_fulfill_base := l_fulfill_base;
8153    --
8154    l_hash_string := to_char(p_demand_source_header_id)||'-'||to_char(p_demand_source_line_id) ;
8155    IF WSH_PR_CRITERIA.g_from_subinventory IS NOT NULL THEN
8156       l_hash_string := l_hash_string ||'-'|| WSH_PR_CRITERIA.g_from_subinventory;
8157    END IF;
8158    IF WSH_PR_CRITERIA.g_from_locator IS NOT NULL THEN
8159       l_hash_string := l_hash_string ||'-'|| to_char(WSH_PR_CRITERIA.g_from_locator);
8160    END IF;
8161    -- Generating new hash values
8162    l_hash_value := dbms_utility.get_hash_value (
8163                                                  name => l_hash_string,
8164                                                  base => g_hash_base,
8165                                                  hash_size => g_hash_size );
8166 
8167    IF l_debug_on THEN
8168       WSH_DEBUG_SV.logmsg(l_module_name, 'L_HASH_STRING :'||l_hash_string||' , L_HASH_VALUE :'||l_hash_value);
8169    END IF;
8170 
8171    --Scan through global demand table and find out if reservation exists for input header and line.
8172    WHILE NOT l_hash_exists LOOP
8173      IF g_demand_table.EXISTS(l_hash_value) THEN
8174         IF ((g_demand_table(l_hash_value).demand_source_header_id = p_demand_source_header_id) AND
8175             (g_demand_table(l_hash_value).demand_source_line_id = p_demand_source_line_id  ) AND
8176             (nvl(g_demand_table(l_hash_value).subinventory_code,'-99') = nvl(WSH_PR_CRITERIA.g_from_subinventory,'-99')) AND
8177             (nvl(g_demand_table(l_hash_value).locator_id,-99) = nvl(WSH_PR_CRITERIA.g_from_locator,-99))) THEN
8178            l_demand_exists := TRUE;
8179            --
8180            IF l_debug_on THEN
8181               WSH_DEBUG_SV.logmsg(l_module_name,  'FOUND THE RESERVATION DETAILS'  );
8182               WSH_DEBUG_SV.log(l_module_name,'L_HASH_VALUE',L_HASH_VALUE);
8183            END IF;
8184            --
8185            EXIT;
8186         ELSE
8187            -- Hash value exists but attributes do not match
8188            -- Increment the hash value and check again
8189            l_hash_value := l_hash_value + 1;
8190         END IF;
8191      ELSE
8192         -- Hash value does not exist, so this is a new hash value
8193         l_hash_exists := TRUE;
8194         IF l_debug_on THEN
8195            WSH_DEBUG_SV.log(l_module_name,'L_HASH_VALUE',L_HASH_VALUE);
8196         END IF;
8197      END IF;
8198    END LOOP;
8199    --
8200 
8201    IF (not l_demand_exists) THEN --{
8202    -- Bug 4775539
8203       IF (WSH_PR_CRITERIA.g_existing_rsvs_only_flag = 'Y') THEN
8204       --Get the reservation details for header and line.
8205       IF l_debug_on THEN
8206          WSH_DEBUG_SV.logmsg(l_module_name,  'FETCHING RESERVATION DETAILS'  );
8207       END IF;
8208       --
8209       OPEN  reservation_quantity(p_demand_source_header_id, p_demand_source_line_id);
8210       FETCH reservation_quantity
8211 -- HW OPMCONV -Added qty2
8212       INTO  l_reservation_quantity, l_reservation_quantity2;
8213       CLOSE reservation_quantity;
8214 
8215       IF (l_reservation_quantity IS NULL) THEN
8216          l_reservation_quantity := 0;
8217 -- HW OPMCONV - Added qty2
8218          l_reservation_quantity2 := 0;
8219       END IF;
8220 
8221        -- Bug 4775539
8222 
8223         --Start of fix for bug 6459193
8224         IF ( l_reservation_quantity > 0 ) THEN
8225            SELECT sum(wdd.requested_quantity)
8226                   -- muom
8227                   ,sum(wdd.requested_quantity2)
8228            INTO   l_unallocated_quantity
8229                   -- muom
8230                   ,l_unallocated_quantity2
8231            FROM   wsh_delivery_details wdd
8232            WHERE  wdd.released_status = 'S'
8233            AND    wdd.source_code = 'OE'
8234            AND    wdd.source_line_id = p_demand_source_line_id
8235            AND    NOT EXISTS
8236                 ( SELECT 'X'
8237                   FROM   mtl_material_transactions_temp mmtt
8238                   WHERE  mmtt.move_order_line_id = wdd.move_order_line_id );
8239 
8240            --
8241            IF l_debug_on THEN
8242               -- muom
8243               WSH_DEBUG_SV.logmsg(l_module_name,  'RESERVATION QUANTITY '||l_reservation_quantity||' RESERVATION QUANTITY2 '||l_reservation_quantity2 );
8244               WSH_DEBUG_SV.logmsg(l_module_name,  'UNALLOCATED QUANTITY '||l_unallocated_quantity||' UNALLOCATED QUANTITY2 '||l_unallocated_quantity2 );
8245            END IF;
8246            --
8247            l_reservation_quantity := l_reservation_quantity - nvl(l_unallocated_quantity, 0);
8248            --To Make sure that reservation quantity is NOT less than Zero
8249            IF ( l_reservation_quantity < 0 ) THEN
8250               l_reservation_quantity := 0;
8251            END IF;
8252            -- muom
8253            l_reservation_quantity2 := l_reservation_quantity2 - nvl(l_unallocated_quantity2, 0);
8254            IF ( l_reservation_quantity2 < 0 ) THEN
8255               l_reservation_quantity2 := 0;
8256            END IF;
8257         END IF;
8258         --End of fix for bug 6459193
8259       ELSE
8260 
8261         IF p_requested_quantity_uom <> p_src_requested_quantity_uom THEN
8262           l_total_requested_quantity :=
8263              WSH_WV_UTILS.Convert_UOM(
8264 	       From_uom => p_src_requested_quantity_uom,
8265 	       To_uom   => p_requested_quantity_uom,
8266 	       Quantity => p_src_requested_quantity,
8267 	       Item_id  => p_inv_item_id);
8268         ELSE
8269           l_total_requested_quantity := round(p_src_requested_quantity,WSH_UTIL_CORE.C_MAX_DECIMAL_DIGITS_INV); --Bugfix 8557457
8270         END IF;
8271         -- muom
8272         l_total_requested_quantity2 := p_src_requested_quantity2;
8273 
8274         IF l_debug_on THEN --Bugfix 8557457
8275            WSH_DEBUG_SV.logmsg(l_module_name,'L_TOTAL_REQUESTED_QUANTITY '||l_total_requested_quantity);
8276         END IF;
8277 
8278 
8279         --Get the other reservation details for header and line.
8280         IF l_debug_on THEN
8281            WSH_DEBUG_SV.logmsg(l_module_name,  'FETCHING OTHER RESERVATION DETAILS'  );
8282         END IF;
8283         --
8284         OPEN  discard_reservation_quantity(p_demand_source_header_id, p_demand_source_line_id);
8285         FETCH discard_reservation_quantity
8286         INTO  l_reservation_quantity,l_reservation_quantity2;
8287         CLOSE discard_reservation_quantity;
8288 
8289         -- muom
8290         IF (l_reservation_quantity IS NULL) OR (l_reservation_quantity2 IS NULL) THEN
8291            l_reservation_quantity := 0;
8292 	    l_reservation_quantity2 := 0;
8293         END IF;
8294                l_reservation_quantity := l_total_requested_quantity - l_reservation_quantity;
8295                -- muom
8296                l_reservation_quantity2 := l_total_requested_quantity2 - l_reservation_quantity2;
8297       END IF;
8298       --
8299       --Store reservation details in global demand table.
8300       g_demand_table(l_hash_value).demand_source_header_id := p_demand_source_header_id;
8301       g_demand_table(l_hash_value).demand_source_line_id   := p_demand_source_line_id;
8302       g_demand_table(l_hash_value).subinventory_code := WSH_PR_CRITERIA.g_from_subinventory;
8303       g_demand_table(l_hash_value).locator_id  := WSH_PR_CRITERIA.g_from_locator;
8304       g_demand_table(l_hash_value).reserved_quantity := l_reservation_quantity;
8305 -- HW OPMCONV - Added qty2
8306       g_demand_table(l_hash_value).reserved_quantity2 := l_reservation_quantity2;
8307       --
8308       IF l_debug_on THEN
8309          WSH_DEBUG_SV.logmsg(l_module_name,  'RESERVED QTY AVAILABLE IS '||L_RESERVATION_QUANTITY  );
8310 -- HW OPMCONV - print qty2
8311          WSH_DEBUG_SV.logmsg(l_module_name,  'RESERVED QTY2 AVAILABLE IS '||L_RESERVATION_QUANTITY2  );
8312       END IF;
8313       --
8314       IF (g_demand_table(l_hash_value).reserved_quantity < 0) THEN
8315          g_demand_table(l_hash_value).reserved_quantity := 0;
8316       END IF;
8317       -- muom
8318       IF (g_demand_table(l_hash_value).reserved_quantity2 < 0) THEN
8319          g_demand_table(l_hash_value).reserved_quantity2 := 0;
8320       END IF;
8321       --
8322    END IF; --}
8323    --
8324    -- muom
8325    IF (l_fulfill_base = 'P' and g_demand_table(l_hash_value).reserved_quantity = 0) OR (l_fulfill_base = 'S' and g_demand_table(l_hash_value).reserved_quantity2 = 0) THEN  --Bugfix 16663056
8326       x_result := 0;
8327 -- HW OPMCONV - Added x_result2
8328       x_result2 := 0;
8329     ELSIF ((l_fulfill_base = 'P') and ((g_demand_table(l_hash_value).reserved_quantity > 0) AND (g_demand_table(l_hash_value).reserved_quantity < p_requested_quantity))) OR
8330           ((l_fulfill_base = 'S') and ((g_demand_table(l_hash_value).reserved_quantity2 > 0) AND (g_demand_table(l_hash_value).reserved_quantity2 < p_requested_quantity2))) THEN
8331       x_result := g_demand_table(l_hash_value).reserved_quantity;
8332       x_result2:= g_demand_table(l_hash_value).reserved_quantity2;
8333       g_demand_table(l_hash_value).reserved_quantity := 0;
8334       g_demand_table(l_hash_value).reserved_quantity2 := 0;
8335     ELSE
8336       x_result := p_requested_quantity;
8337 -- HW OPMCONV - Added x_result2
8338       x_result2 := p_requested_quantity2;
8339       g_demand_table(l_hash_value).reserved_quantity := g_demand_table(l_hash_value).reserved_quantity - p_requested_quantity;
8340 -- HW OPMCONV - Added qty2
8341       g_demand_table(l_hash_value).reserved_quantity2 := g_demand_table(l_hash_value).reserved_quantity2 - p_requested_quantity2;
8342    END IF;
8343    --
8344    IF l_debug_on THEN
8345       -- muom
8346       WSH_DEBUG_SV.logmsg(l_module_name,  'FULFILL BASE IS '||X_FULFILL_BASE  );
8347       WSH_DEBUG_SV.logmsg(l_module_name,  'RESERVED QTY AVAILABLE '||X_RESULT  );
8348 -- HW OPMCONV - Print qty2
8349       WSH_DEBUG_SV.logmsg(l_module_name,  'RESERVED QTY2 AVAILABLE '||X_RESULT2  );
8350       WSH_DEBUG_SV.pop(l_module_name);
8351    END IF;
8352    --
8353    return;
8354    --
8355 END Calculate_Reservations;
8356 
8357 -- muom for Overloading (WMS)- Wave Planning
8358 -- Start of comments
8359 -- API name : Calculate_Reservations
8360 -- Type     : Public
8361 -- Pre-reqs : None.
8362 -- Procedure: API to calculate the Reservations quantity, api does
8363 --            1. Scan through global demand table and find out if reservation exists for input header and line.
8364 --            2. If not fetch the reservation from inventory reservation table.
8365 --            3. Calculate the reservation quantity
8366 -- Parameters :
8367 -- IN:
8368 --      p_demand_source_header_id        IN  Demand hedaer id.
8369 --      p_demand_source_line_id          IN  Demand line id.
8370 --      p_requested_quantity             IN  Requested Quantity.
8371 --      p_requested_quantity_uom         IN  Requested Quantity UOM.
8372 --      p_src_requested_quantity_uom     IN  Source Requested Quantity UOM.
8373 --      p_src_requested_quantity         IN  Source Requested Quantity.
8374 --      p_inv_item_id                    IN  Item Id.
8375 --      p_requested_quantity2            IN  Secondary Requested Quantity.
8376 -- OUT:
8377 --      x_result        OUT NOCOPY Reservations quantity.
8378 --      x_result2       OUT NOCOPY Secondary Reservations quantity.
8379 -- End of comments
8380 PROCEDURE Calculate_Reservations(
8381     p_demand_source_header_id IN NUMBER,
8382     p_demand_source_line_id   IN NUMBER,
8383     p_requested_quantity IN NUMBER,
8384     -- Bug 4775539
8385     p_requested_quantity_uom     IN VARCHAR2,
8386     p_src_requested_quantity_uom IN VARCHAR2,
8387     p_src_requested_quantity     IN NUMBER,
8388     p_inv_item_id                IN NUMBER,
8389     p_requested_quantity2 IN NUMBER default NULL,
8390     x_result  OUT NOCOPY  NUMBER,
8391     x_result2 OUT NOCOPY  NUMBER) IS
8392 
8393    --
8394    l_debug_on BOOLEAN;
8395    l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CALCULATE_RESERVATIONS1';
8396    --
8397    -- muom
8398    l_fulfill_base               varchar2(1):= NULL;
8399    l_src_requested_quantity2    NUMBER :=0;
8400 
8401    l_demand_source_header_id  NUMBER;
8402    l_demand_source_line_id    NUMBER;
8403    l_requested_quantity       NUMBER;
8404    l_requested_quantity_uom      WSH_DELIVERY_DETAILS.requested_quantity_uom%TYPE;
8405    l_src_requested_quantity_uom  WSH_DELIVERY_DETAILS.requested_quantity_uom2%TYPE;
8406    l_src_requested_quantity   NUMBER;
8407    l_inv_item_id              NUMBER;
8408    l_requested_quantity2      NUMBER;
8409    l_result                   NUMBER;
8410    l_result2                  NUMBER;
8411 
8412 BEGIN
8413    --
8414    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
8415    --
8416    IF l_debug_on IS NULL THEN
8417      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
8418    END IF;
8419    --
8420    IF l_debug_on THEN
8421       WSH_DEBUG_SV.push(l_module_name);
8422       WSH_DEBUG_SV.log(l_module_name,'muom: P_DEMAND_SOURCE_HEADER_ID',P_DEMAND_SOURCE_HEADER_ID);
8423       WSH_DEBUG_SV.log(l_module_name,'P_DEMAND_SOURCE_LINE_ID',P_DEMAND_SOURCE_LINE_ID);
8424       WSH_DEBUG_SV.log(l_module_name,'P_REQUESTED_QUANTITY',P_REQUESTED_QUANTITY);
8425       WSH_DEBUG_SV.log(l_module_name,'P_REQUESTED_QUANTITY2',P_REQUESTED_QUANTITY2);
8426       WSH_DEBUG_SV.log(l_module_name,'P_REQUESTED_QUANTITY_UOM',P_REQUESTED_QUANTITY_UOM);
8427       WSH_DEBUG_SV.log(l_module_name,'P_SRC_REQUESTED_QUANTITY_UOM',P_SRC_REQUESTED_QUANTITY_UOM);
8428       WSH_DEBUG_SV.log(l_module_name,'P_SRC_REQUESTED_QUANTITY',P_SRC_REQUESTED_QUANTITY);
8429       WSH_DEBUG_SV.log(l_module_name,'P_INV_ITEM_ID',P_INV_ITEM_ID);
8430    END IF;
8431    --
8432                   l_demand_source_header_id    := p_demand_source_header_id;
8433                   l_demand_source_line_id      := p_demand_source_line_id;
8434                   l_requested_quantity         := p_requested_quantity;
8435                   l_requested_quantity_uom     := p_requested_quantity_uom;
8436                   l_src_requested_quantity_uom := p_src_requested_quantity_uom;
8437                   l_src_requested_quantity     := p_src_requested_quantity;
8438                   l_src_requested_quantity2    := 0;
8439                   l_inv_item_id                := p_inv_item_id;
8440   		  l_requested_quantity2        := p_requested_quantity2;
8441                   l_fulfill_base               := NULL;
8442 
8443 	Calculate_Reservations(
8444                   p_demand_source_header_id    => l_demand_source_header_id,
8445                   p_demand_source_line_id      => l_demand_source_line_id,
8446                   p_requested_quantity         => l_requested_quantity,
8447                   p_requested_quantity_uom     => l_requested_quantity_uom,
8448                   p_src_requested_quantity_uom => l_src_requested_quantity_uom,
8449                   p_src_requested_quantity     => l_src_requested_quantity,
8450                   p_src_requested_quantity2    => l_src_requested_quantity2,
8451                   p_inv_item_id                => l_inv_item_id,
8452   		  p_requested_quantity2        => l_requested_quantity2, /* Bug 7291415 Uncommented this line */
8453                   x_fulfill_base               => l_fulfill_base,
8454 		  x_result                     => l_result,
8455 		  x_result2                    => l_result2);
8456 		  X_RESULT                     := l_result;
8457 		  X_RESULT2                    := l_result2;
8458    --
8459    IF l_debug_on THEN
8460       WSH_DEBUG_SV.logmsg(l_module_name,  'RESERVED QTY AVAILABLE '||l_result  );
8461 -- HW OPMCONV - Print qty2
8462       WSH_DEBUG_SV.logmsg(l_module_name,  'RESERVED QTY2 AVAILABLE '||l_result2  );
8463       WSH_DEBUG_SV.pop(l_module_name);
8464    END IF;
8465    --
8466    return;
8467    --
8468 END Calculate_Reservations;
8469 
8470 -- Start of comments
8471 -- API name : CalcWorkingDay
8472 -- Type     : Public
8473 -- Pre-reqs : None.
8474 -- Procedure: This procedure uses the shipping calendar to determine
8475 --            the next (or) prior working day.  Used if the picking rule has dynamic date components.
8476 -- Parameters :
8477 -- IN:
8478 --      p_orgID            IN  Organization Id.
8479 --      p_days             IN  Days in Number 1-31.
8480 --      p_Time             IN  Time.
8481 --      p_CalCode          IN  Shipping Calender Code.
8482 -- OUT:
8483 --      x_date       OUT NOCOPY Working days date.
8484 -- End of comments
8485 PROCEDURE CalcWorkingDay(p_orgID 	IN NUMBER,
8486                          p_PickRule     IN VARCHAR2,
8487 			 p_days 	IN NUMBER,
8488 			 p_Time 	IN NUMBER,
8489                          p_CalCode 	IN VARCHAR2,
8490 			 x_date 	IN OUT NOCOPY DATE) IS
8491    --
8492    v_Trials     NUMBER;
8493    j            NUMBER := 0;
8494    v_Err        NUMBER;
8495    v_Msg        VARCHAR2(100);
8496    v_WorkDay    BOOLEAN := FALSE;
8497    v_Date       DATE;
8498    v_Hrs        NUMBER;
8499    v_Min        NUMBER;
8500    v_Sec        NUMBER;
8501    v_TimeChar   VARCHAR2(10);
8502    v_DateChar   VARCHAR2(50);
8503 
8504     --Added in bug 7316707
8505     v_org_code   VARCHAR2(50);
8506     e_return EXCEPTION;
8507 
8508     CURSOR get_org_code (org_id IN NUMBER)
8509     IS
8510     SELECT organization_code
8511     FROM
8512       ORG_ORGANIZATION_DEFINITIONS
8513     WHERE organization_id = org_id;
8514     --bug 7316707 till here
8515 
8516    --
8517    l_debug_on	BOOLEAN;
8518    l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.CalcWorkingDay';
8519 
8520    --BUG# 13655114
8521    l_server_timezone varchar2(50);
8522    l_client_timezone varchar2(50);
8523    l_client_time DATE;
8524    --
8525 BEGIN
8526   --
8527   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
8528   --
8529   IF l_debug_on IS NULL
8530   THEN
8531     l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
8532   END IF;
8533   --
8534   IF l_debug_on THEN
8535     WSH_DEBUG_SV.push(l_module_name);
8536     WSH_DEBUG_SV.log(l_module_name, 'p_orgID', p_orgID);
8537     WSH_DEBUG_SV.log(l_module_name, 'p_calCode', p_calCode);
8538     WSH_DEBUG_SV.log(l_module_name, 'p_Time', p_Time);
8539     WSH_DEBUG_SV.log(l_module_name, 'p_days', p_days);
8540   END IF;
8541   --
8542   v_Hrs := TRUNC(p_Time / 3600);
8543   v_Min := TRUNC((p_Time - (v_Hrs * 3600))/60);
8544   v_Sec := p_Time - (v_Hrs * 3600) - (v_Min * 60);
8545   v_TimeChar := v_Hrs || ':' || v_Min || ':' || v_Sec;
8546 
8547   --BUG# 13655114
8548   l_server_timezone := fnd_timezones.get_server_timezone_code;
8549   l_client_timezone := fnd_timezones.get_client_timezone_code;
8550   l_client_time := fnd_timezone_pub.adjust_datetime (sysdate,l_server_timezone,l_client_timezone);
8551   --
8552   IF l_debug_on THEN
8553    WSH_DEBUG_SV.log(l_module_name, 'v_Hrs', v_Hrs);
8554    WSH_DEBUG_SV.log(l_module_name, 'v_Min', v_Min);
8555    WSH_DEBUG_SV.log(l_module_name, 'v_Sec', v_Sec);
8556    WSH_DEBUG_SV.log(l_module_name, 'v_TimeChar', v_TimeChar);
8557    wsh_debug_sv.log(l_module_name, 'l_server_timezone', l_server_timezone);
8558    wsh_debug_sv.log(l_module_name, 'l_client_timezoene', l_client_timezone);
8559    wsh_debug_sv.log(l_module_name, 'sysdate', sysdate);
8560    wsh_debug_sv.log(l_module_name, 'l_client_time', l_client_time);
8561   END IF;
8562   --
8563   -- Cannot apply calendar without knowing warehouse.
8564   -- So, just perform simple date arithmetic.
8565   --
8566   IF p_orgId IS NULL OR p_CalCode IS NULL THEN
8567       --BUG# 13655114
8568       v_DateChar := to_char((TRUNC(l_client_time) + p_Days), 'DD/MM/YYYY') || ' ' || v_TimeChar;
8569       v_Date := to_date(v_DateChar, 'DD/MM/YYYY HH24:MI:SS');
8570 	  x_Date := fnd_timezone_pub.adjust_datetime (v_Date,l_client_timezone, l_server_timezone);
8571 
8572       --
8573       IF l_debug_on THEN
8574 	    wsh_debug_sv.log(l_module_name, 'x_Date', x_Date);
8575         wsh_debug_sv.pop(l_module_name);
8576       END IF;
8577       --
8578       RETURN;
8579   END IF;
8580   --
8581   v_Trials := ABS(p_days);
8582   --BUG# 13655114
8583   v_DateChar := to_char(TRUNC(l_client_time), 'DD/MM/YYYY') || ' ' || v_TimeChar;
8584   v_Date   := to_date(v_DateChar, 'DD/MM/YYYY HH24:MI:SS');
8585   --
8586   IF l_debug_on THEN
8587    wsh_debug_sv.log(l_module_name, 'v_Trials', v_Trials);
8588    wsh_debug_sv.log(l_module_name, 'v_DateChar', v_DateChar);
8589    wsh_debug_sv.log(l_module_name, 'v_Date', v_Date);
8590   END IF;
8591   --
8592   WHILE j < v_Trials LOOP
8593    --
8594    IF p_Days < 0 THEN
8595     v_Date := v_Date - 1;
8596    ELSE
8597     v_Date := v_Date + 1;
8598    END IF;
8599    --
8600    BOM_CALENDAR_API_BK.Check_Working_Day(p_CalCode,v_Date, v_WorkDay,v_Err,v_Msg);
8601    --
8602    --bug 7316707 handle error returned by API
8603    IF v_Err = -1 THEN
8604    --{
8605 
8606         OPEN get_org_code(p_orgId);
8607         FETCH get_org_code
8608         INTO  v_org_code;
8609         CLOSE get_org_code;
8610         v_Date := null;
8611         FND_MESSAGE.SET_NAME('WSH','WSH_NO_CALENDAR_DATE');
8612         FND_MESSAGE.SET_TOKEN('NAME',p_PickRule);
8613         FND_MESSAGE.SET_TOKEN('CALENDAR',p_CalCode);
8614         FND_MESSAGE.SET_TOKEN('WAREHOUSE',v_org_code);
8615         wsh_util_core.add_message(WSH_UTIL_CORE.G_RET_STS_ERROR,l_module_name);
8616         RAISE e_return;
8617         EXIT;
8618 
8619    --}
8620    END IF;
8621    --bug 7316707 till here
8622 
8623    IF v_WorkDay THEN
8624       j := j + 1;
8625    END IF;
8626    --
8627   END LOOP;
8628   --
8629   --BUG# 13655114
8630   x_Date := fnd_timezone_pub.adjust_datetime (v_Date,l_client_timezone, l_server_timezone);
8631   --
8632   IF l_debug_on THEN
8633     wsh_debug_sv.log(l_module_name, 'x_Date', x_Date);
8634     wsh_debug_sv.pop(l_module_name);
8635   END IF;
8636   --
8637 END CalcWorkingDay;
8638 END WSH_PICK_LIST;