DBA Data[Home] [Help]

PACKAGE BODY: APPS.WSH_PICK_LIST

Source


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