1 PACKAGE BODY OE_ORDER_SCH_UTIL AS
2 /* $Header: OEXVSCHB.pls 120.5 2005/12/15 03:42:56 rmoharan noship $ */
3
4 G_PKG_NAME CONSTANT VARCHAR2(30):='OE_Schedule';
5 G_SOURCE_AGAIN VARCHAR2(1) := 'Y';
6 G_OVERRIDE_FLAG VARCHAR2(1) := 'N';
7 G_UPDATE_FLAG VARCHAR2(1) := FND_API.G_TRUE;
8 G_LINE_ACTION VARCHAR2(30) := null;
9 G_HEADER_ID NUMBER := null;
10 G_DATE_TYPE VARCHAR2(30) := null;
11 USER_SPLIT CONSTANT VARCHAR2(30) := 'USER_SPLIT';
12 SYSTEM_SPLIT CONSTANT VARCHAR2(30) := 'SYSTEM_SPLIT';
13 G_LINE_PART_OF_SET BOOLEAN := FALSE;
14
15 FUNCTION Get_Date_Type
16 ( p_header_id IN NUMBER)
17 RETURN VARCHAR2;
18
19 Procedure Update_PO
20 (p_schedule_ship_date IN DATE,
21 p_source_document_id IN VARCHAR2,
22 p_source_document_line_id IN VARCHAR2);
23
24 FUNCTION Item_Is_Ato_Model(p_line_rec IN OE_ORDER_PUB.line_rec_type)
25 RETURN BOOLEAN
26 IS
27 --
28 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
29 --
30 BEGIN
31 IF l_debug_level > 0 THEN
32 oe_debug_pub.add( 'ENTERING ITEM IS ATO MODEL' , 1 ) ;
33 END IF;
34 IF p_line_rec.item_type_code = OE_GLOBALS.G_ITEM_MODEL
35 and p_line_rec.line_id = p_line_rec.ato_line_id
36 THEN
37 IF l_debug_level > 0 THEN
38 oe_debug_pub.add( 'RR: RETURNING TRUE' , 1 ) ;
39 END IF;
40 RETURN TRUE;
41 ELSE
42 IF l_debug_level > 0 THEN
43 oe_debug_pub.add( 'RR: RETURNING FALSE' , 1 ) ;
44 END IF;
45 RETURN FALSE;
46
47 END IF;
48
49 END Item_Is_Ato_Model;
50
51 /* --------------------------------------------------------------------
52 Function Name : Group_Scheduling_Required
53 Description : This function will return true if the line to be scheduled
54 is in a scheduling group:
55 Ship Set
56 Arrival Set
57 Ship Model Complete PTO
58 ATO Model
59 This function will also return true, for a different kind
60 of group: Lines which are split. When a line is split into
61 multiple lines, the scheduling (if one exists) for the line
62 also needs to split. This function will return TRUE if a line
63 is split and it has been scheduled. The main (Schedule Line)
64 function, will then log a delayed request to split the
65 scheduling on the line.
66
67 ----------------------------------------------------------------------- */
68 FUNCTION Group_Scheduling_Required(p_line_rec OE_ORDER_PUB.line_rec_type,
69 p_old_line_rec OE_ORDER_PUB.line_rec_type)
70 RETURN BOOLEAN
71 IS
72 --
73 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
74 --
75 BEGIN
76
77 IF l_debug_level > 0 THEN
78 oe_debug_pub.add( 'ENTERING GROUP_SCHEDULING_REQUIRED' , 1 ) ;
79 END IF;
80
81 -- If the operation is delete, we just need to unschedule this line.
82 -- So we do not need to perform any group scheduling right away.
83
84 IF p_line_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
85 RETURN FALSE;
86 END IF;
87
88 -- If the line belongs to a remnant set, we should not treat it in a
89 -- group, even if it did belong to a scheduling group before the split.
90
91 IF p_line_rec.model_remnant_flag = 'Y' THEN
92 RETURN FALSE;
93 END IF;
94
95
96 IF (p_line_rec.operation = OE_GLOBALS.G_OPR_CREATE) THEN
97
98 IF l_debug_level > 0 THEN
99 oe_debug_pub.add( 'IT IS A CREATE ACTION ON THE LINE' , 1 ) ;
100 END IF;
101
102 IF (p_line_rec.ship_set_id is not null AND
103 p_line_rec.ship_set_id <> FND_API.G_MISS_NUM) OR
104 (p_line_rec.arrival_set_id is not null AND
105 p_line_rec.arrival_set_id <> FND_API.G_MISS_NUM) OR
106 (p_line_rec.ship_model_complete_flag = 'Y') OR
107 (p_line_rec.ato_line_id is not null AND
108 p_line_rec.ato_line_id <> FND_API.G_MISS_NUM AND
109 NOT (p_line_rec.ato_line_id = p_line_rec.line_id AND
110 p_line_rec.item_type_code IN (OE_GLOBALS.G_ITEM_STANDARD,
111 OE_GLOBALS.G_ITEM_OPTION))) THEN
112
113 RETURN TRUE;
114
115 END IF;
116 END IF;
117
118 IF (p_line_rec.operation = OE_GLOBALS.G_OPR_UPDATE) THEN
119
120 IF l_debug_level > 0 THEN
121 oe_debug_pub.add( 'IT IS A UPDATE ACTION ON THE LINE' , 1 ) ;
122 END IF;
123
124 IF (NOT OE_GLOBALS.Equal(p_line_rec.ship_set_id,
125 p_old_line_rec.ship_set_id)
126 AND p_line_rec.ship_set_id IS NOT NULL ) OR
127 (NOT OE_GLOBALS.Equal(p_line_rec.arrival_set_id,
128 p_old_line_rec.arrival_set_id)
129 AND p_line_rec.arrival_set_id IS NOT NULL) THEN
130 RETURN TRUE;
131 END IF;
132
133 END IF;
134
135
136 -- If the ship_set_id has changed on the line, it means
137 -- that the line is being added to a set, or being moved from
138 -- one to another. This does not need group scheduling right away. We
139 -- will just try to schedule the line as is.
140
141 IF NOT OE_GLOBALS.Equal(p_line_rec.ship_set_id,
142 p_old_line_rec.ship_set_id)
143 THEN
144 RETURN FALSE;
145 END IF;
146
147 IF NOT OE_GLOBALS.Equal(p_line_rec.arrival_set_id,
148 p_old_line_rec.arrival_set_id)
149 THEN
150 RETURN FALSE;
151 END IF;
152
153
154 -- If the line belongs to a set and the user is trying
155 -- to unschedule the line, it is not group schedule.Or if you are
156 -- trying to reserve the line, it is not a group schedule.
157
158 IF (p_line_rec.ship_set_id is not null OR
159 p_line_rec.arrival_set_id is not null OR
160 p_line_rec.ship_model_complete_flag = 'Y') THEN
161
162 IF (p_line_rec.schedule_action_code = OESCH_ACT_UNSCHEDULE OR
163 p_line_rec.schedule_action_code = OESCH_ACT_UNRESERVE) THEN
164 RETURN FALSE;
165 END IF;
166
167 -- Adding this code so that, if an item is changed on one of the line
168 -- which belong to set require a group_scheduling.
169
170 IF p_line_rec.operation = OE_GLOBALS.G_OPR_UPDATE AND
171 p_line_rec.schedule_status_code IS NOT NULL AND
172 (NOT OE_GLOBALS.Equal(p_line_rec.inventory_item_id,
173 p_old_line_rec.inventory_item_id))
174
175 THEN
176 RETURN TRUE;
177 END IF;
178
179 END IF;
180
181
182 IF (p_line_rec.ato_line_id is not null AND
183 NOT (p_line_rec.ato_line_id = p_line_rec.line_id AND
184 p_line_rec.item_type_code IN (OE_GLOBALS.G_ITEM_STANDARD,
185 OE_GLOBALS.G_ITEM_OPTION))) OR
186 (nvl(p_line_rec.ship_model_complete_flag,'N') = 'Y') OR
187 (p_line_rec.ship_set_id is not null) OR
188 (p_line_rec.arrival_set_id is not null)
189 THEN
190 IF (p_line_rec.schedule_action_code = OESCH_ACT_SCHEDULE OR
191 p_line_rec.schedule_action_code = OESCH_ACT_UNSCHEDULE OR
192 p_line_rec.schedule_action_code = OESCH_ACT_ATP_CHECK OR
193 p_line_rec.schedule_action_code = OESCH_ACT_RESERVE AND
194 p_line_rec.schedule_status_code is null)
195 THEN
196 RETURN TRUE;
197 END IF;
198 END IF;
199
200
201 IF (p_line_rec.ato_line_id is not null) AND
202 NOT (p_line_rec.ato_line_id = p_line_rec.line_id AND
203 p_line_rec.item_type_code IN (OE_GLOBALS.G_ITEM_STANDARD,
204 OE_GLOBALS.G_ITEM_OPTION))
205 THEN
206
207 IF l_debug_level > 0 THEN
208 oe_debug_pub.add( 'ITEM CHANGED IS ATO MODEL OR OPTION' , 1 ) ;
209 END IF;
210
211 -- Change of following attributes affects the whole set
212 -- and thus we must create a group request for it.
213
214
215 IF NOT OE_GLOBALS.Equal(p_line_rec.DEMAND_CLASS_CODE,
216 p_old_line_rec.DEMAND_CLASS_CODE)
217 THEN
218 RETURN TRUE;
219 END IF;
220
221 -- Added > 0 to fix bug 2019034.
222 IF NOT OE_GLOBALS.Equal(p_line_rec.ORDERED_QUANTITY,
223 p_old_line_rec.ORDERED_QUANTITY)
224 --AND p_line_rec.ORDERED_QUANTITY > 0
225 /* commented the above line for bug 2690471 */
226 THEN
227 RETURN TRUE;
228 END IF;
229
230 IF NOT OE_GLOBALS.Equal(p_line_rec.REQUEST_DATE,
231 p_old_line_rec.REQUEST_DATE)
232 THEN
233 RETURN TRUE;
234 END IF;
235
236 IF NOT OE_GLOBALS.Equal(p_line_rec.SHIP_FROM_ORG_ID,
237 p_old_line_rec.SHIP_FROM_ORG_ID)
238 THEN
239 RETURN TRUE;
240 END IF;
241
242 IF NOT OE_GLOBALS.Equal(p_line_rec.SHIP_TO_ORG_ID,
243 p_old_line_rec.SHIP_TO_ORG_ID)
244 THEN
245 RETURN TRUE;
246 END IF;
247
248 IF NOT OE_GLOBALS.Equal(p_line_rec.SCHEDULE_SHIP_DATE,
249 p_old_line_rec.SCHEDULE_SHIP_DATE)
250 THEN
251 RETURN TRUE;
252 END IF;
253
254 IF NOT OE_GLOBALS.Equal(p_line_rec.SCHEDULE_ARRIVAL_DATE,
255 p_old_line_rec.SCHEDULE_ARRIVAL_DATE)
256 THEN
257 RETURN TRUE;
258 END IF;
259
260 IF NOT OE_GLOBALS.Equal(p_line_rec.SHIPPING_METHOD_CODE,
261 p_old_line_rec.SHIPPING_METHOD_CODE)
262 THEN
263 RETURN TRUE;
264 END IF;
265
266 END IF;
267
268 IF l_debug_level > 0 THEN
269 oe_debug_pub.add( 'G6' , 1 ) ;
270 END IF;
271
272 IF (p_line_rec.ship_set_id is not null) OR
273 (nvl(p_line_rec.ship_model_complete_flag,'N') = 'Y') THEN
274
275 -- Change of following attributes affects the whole set
276 -- and thus we must create a group request for it.
277
278 IF NOT OE_GLOBALS.Equal(p_line_rec.SHIP_FROM_ORG_ID,
279 p_old_line_rec.SHIP_FROM_ORG_ID)
280 THEN
281 RETURN TRUE;
282 END IF;
283
284 IF NOT OE_GLOBALS.Equal(p_line_rec.SHIP_TO_ORG_ID,
285 p_old_line_rec.SHIP_TO_ORG_ID)
286 THEN
287 RETURN TRUE;
288 END IF;
289
290 IF NOT OE_GLOBALS.Equal(p_line_rec.SCHEDULE_SHIP_DATE,
291 p_old_line_rec.SCHEDULE_SHIP_DATE)
292 THEN
293 RETURN TRUE;
294 END IF;
295
296 IF NOT OE_GLOBALS.Equal(p_line_rec.SCHEDULE_ARRIVAL_DATE,
297 p_old_line_rec.SCHEDULE_ARRIVAL_DATE)
298 THEN
299 RETURN TRUE;
300 END IF;
301
302 IF (nvl(p_line_rec.ship_model_complete_flag,'N') = 'Y')
303 THEN
304 -- We will reschedule the whole set for change in ordered
305 -- quantity of a ship_model_complete PTO only ).
306
307 -- If the line is getting unscheduled due to cancellation
308 -- let it not be group schedule.
309 -- Added 0 check to fix 2019034.
310 IF NOT OE_GLOBALS.Equal(p_line_rec.ORDERED_QUANTITY,
311 p_old_line_rec.ORDERED_QUANTITY)
312 AND p_line_rec.ORDERED_QUANTITY > 0
313 THEN
314 RETURN TRUE;
315 END IF;
316
317 /* Commented the following lines to fix the bug 2720398
318 IF NOT OE_GLOBALS.Equal(p_line_rec.SHIPPING_METHOD_CODE,
319 p_old_line_rec.SHIPPING_METHOD_CODE)
320 THEN
321 RETURN TRUE;
322 END IF;
323 */
324
325 END IF;
326
327 /* Added the following if condition to fix the bug 2720398 */
328
329 IF NOT OE_GLOBALS.Equal(p_line_rec.SHIPPING_METHOD_CODE,
330 p_old_line_rec.SHIPPING_METHOD_CODE)
331 THEN
332 RETURN TRUE;
333 END IF;
334
335 /* End of new code added to fix the bug 2720398 */
336
337 IF NOT OE_GLOBALS.Equal(p_line_rec.REQUEST_DATE,
338 p_old_line_rec.REQUEST_DATE)
339 THEN
340 RETURN TRUE;
341 END IF;
342
343 END IF;
344
345 IF (p_line_rec.arrival_set_id is not null) THEN
346
347 -- Change of following attributes affects the whole set
348 -- and thus we must create a group request for it.
349
350
351 IF NOT OE_GLOBALS.Equal(p_line_rec.SCHEDULE_ARRIVAL_DATE,
352 p_old_line_rec.SCHEDULE_ARRIVAL_DATE)
353 THEN
354 RETURN TRUE;
355 END IF;
356
357 IF NOT OE_GLOBALS.Equal(p_line_rec.SCHEDULE_SHIP_DATE,
358 p_old_line_rec.SCHEDULE_SHIP_DATE)
359 THEN
360 RETURN TRUE;
361 END IF;
362
363 IF NOT OE_GLOBALS.Equal(p_line_rec.SHIP_TO_ORG_ID,
364 p_old_line_rec.SHIP_TO_ORG_ID)
365 THEN
366 RETURN TRUE;
367 END IF;
368
369 IF NOT OE_GLOBALS.Equal(p_line_rec.REQUEST_DATE,
370 p_old_line_rec.REQUEST_DATE)
371 THEN
372 RETURN TRUE;
373 END IF;
374
375 END IF;
376
377 RETURN FALSE;
378 END Group_Scheduling_Required;
379
380 /* --------------------------------------------------------------------
381 Procedure Name : Update_Group_Sch_Results
382 Description :
383 ----------------------------------------------------------------------- */
384
385 Procedure Update_Group_Sch_Results
386 (p_x_line_rec IN OUT NOCOPY /* file.sql.39 change */ OE_ORDER_PUB.line_rec_type,
387 x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
388 IS
389 l_line_rec OE_ORDER_PUB.line_rec_type;
390 --
391 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
392 --
393 BEGIN
394 -- x_line_rec := p_line_rec;
395
396 -- l_line_rec := OE_Line_Util.Query_Row
397 -- (p_line_id => p_x_line_rec.line_id);
398
399 OE_Line_Util.Query_Row(p_line_id => p_x_line_rec.line_id,
400 x_line_rec => l_line_rec);
401
402 IF NOT OE_GLOBALS.Equal(p_x_line_rec.ship_from_org_id,
403 l_line_rec.ship_from_org_id)
404 THEN
405 p_x_line_rec.ship_from_org_id := l_line_rec.ship_from_org_id;
406 END IF;
407
408 IF NOT OE_GLOBALS.Equal(p_x_line_rec.schedule_ship_date,
409 l_line_rec.schedule_ship_date)
410 THEN
411 p_x_line_rec.schedule_ship_date := l_line_rec.schedule_ship_date;
412 END IF;
413
414 IF NOT OE_GLOBALS.Equal(p_x_line_rec.schedule_arrival_date,
415 l_line_rec.schedule_arrival_date)
416 THEN
417 p_x_line_rec.schedule_arrival_date := l_line_rec.schedule_arrival_date;
418 END IF;
419
420 IF NOT OE_GLOBALS.Equal(p_x_line_rec.schedule_status_code,
421 l_line_rec.schedule_status_code)
422 THEN
423 p_x_line_rec.schedule_status_code := l_line_rec.schedule_status_code;
424 END IF;
425
426 IF NOT OE_GLOBALS.Equal(p_x_line_rec.shipping_method_code,
427 l_line_rec.shipping_method_code)
428 THEN
429 p_x_line_rec.shipping_method_code := l_line_rec.shipping_method_code;
430 END IF;
431
432 IF NOT OE_GLOBALS.Equal(p_x_line_rec.visible_demand_flag,
433 l_line_rec.visible_demand_flag)
434 THEN
435 p_x_line_rec.visible_demand_flag := l_line_rec.visible_demand_flag;
436 END IF;
437
438 END Update_Group_Sch_Results;
439
440 /* -----------------------------------------------------------
441 Procedure : Build_Included_Items
442 Description : This API is called when you want to get the included
443 items for a particular order line (if the order line
444 is model, class or kit).
445 When a model, class or kit is scheduled, the included
446 items under it should also get scheduled. This
447 API returns back the included items for item.
448
449 For the following cases, it just queries the included items
450 and returns them to the calling API:
451 1. If the included items are frozen (explosion date is
452 populated on the line).
453 2. The action on the line is UNSCHEDULE or UNRESERVE
454 3. The operation on the line is DELETE.
455
456 If will explode the included items (by calling
457 process_included_items) for the following cases
458
459 1. Explosion date is null on the line and operation is
460 UPDATE on the line.
461
462
463 ----------------------------------------------------------- */
464 PROCEDURE Build_Included_Items
465 (p_line_rec IN OE_ORDER_PUB.line_rec_type,
466 x_line_tbl IN OUT NOCOPY OE_ORDER_PUB.line_tbl_type)
467 IS
468 --l_line_tbl OE_ORDER_PUB.line_tbl_type;
469 l_validation_org NUMBER;
470 l_group_id NUMBER;
471 l_session_id NUMBER;
472 l_levels NUMBER;
473 l_stdcompflag VARCHAR2(30);
474 l_exp_quantity NUMBER;
475 l_return_status VARCHAR2(1);
476 l_explode BOOLEAN;
477 is_set_recursion VARCHAR2(1) := 'Y';
478 --
479 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
480 --
481 BEGIN
482
483 IF l_debug_level > 0 THEN
484 oe_debug_pub.add( 'ENTERING BUILD_INCLUDED_ITEMS' , 1 ) ;
485 END IF;
486
487 IF ((p_line_rec.schedule_action_code = OESCH_ACT_UNSCHEDULE) OR
488 (p_line_rec.schedule_action_code = OESCH_ACT_UNDEMAND) OR
489 (p_line_rec.schedule_action_code = OESCH_ACT_UNRESERVE)) THEN
490 l_explode := FALSE;
491 END IF;
492
493 IF p_line_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
494 l_explode := TRUE;
495 END IF;
496
497 IF p_line_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
498 l_explode := FALSE;
499 END IF;
500
501 IF p_line_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
502 IF l_debug_level > 0 THEN
503 oe_debug_pub.add( 'RR:I1' ) ;
504 END IF;
505 IF p_line_rec.explosion_date is not null AND
506 p_line_rec.explosion_date <> FND_API.G_MISS_DATE THEN
507 l_explode := FALSE;
508 ELSE
509 l_explode := TRUE;
510 END IF;
511 END IF;
512
513 IF l_explode THEN
514 IF l_debug_level > 0 THEN
515 oe_debug_pub.add( 'L_EXPLODE IS TRUE' , 1 ) ;
516 END IF;
517 ELSE
518 IF l_debug_level > 0 THEN
519 oe_debug_pub.add( 'L_EXPLODE IS FALSE' , 1 ) ;
520 END IF;
521 END IF;
522
523 IF l_explode THEN
524
525 -- Set the recursion flag here to suppress sets related logic
526
527 IF NOT oe_set_util.g_set_recursive_flag THEN
528 is_set_recursion := 'N';
529 oe_set_util.g_set_recursive_flag := TRUE;
530 END IF;
531
532 -- Calling Process_Included_Items. This procedure
533 -- will take care of explosions and updateing the picture
534 -- of included_items in the oe_order_lines table.
535
536 IF l_debug_level > 0 THEN
537 oe_debug_pub.add( 'CALLING PROCESS_INCLUDED_ITEMS' , 1 ) ;
538 END IF;
539
540 l_return_status := OE_CONFIG_UTIL.Process_Included_Items
541 (p_line_id => p_line_rec.line_id,
542 p_freeze => FALSE);
543
544 IF is_set_recursion = 'N' THEN
545 is_set_recursion := 'Y';
546 oe_set_util.g_set_recursive_flag := FALSE;
547 END IF;
548
549
550 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
551 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
552 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
553 RAISE FND_API.G_EXC_ERROR;
554 END IF;
555
556 -- x_line_tbl :=
557 -- oe_config_util.query_included_items(p_line_rec.line_id);
558
559 OE_Config_Util.Query_Included_Items(p_line_id => p_line_rec.line_id,
560 p_header_id => p_line_rec.header_id,
561 p_top_model_line_id => p_line_rec.top_model_line_id,
562 x_line_tbl => x_line_tbl);
563
564 IF l_debug_level > 0 THEN
565 oe_debug_pub.add( 'COUNT IS: ' || X_LINE_TBL.COUNT , 1 ) ;
566 END IF;
567 ELSE
568
569 -- Query the records from the database
570
571 IF l_debug_level > 0 THEN
572 oe_debug_pub.add( 'QUERYING INCLUDED ITEMS' , 1 ) ;
573 END IF;
574
575 -- x_line_tbl :=
576 -- oe_config_util.query_included_items(p_line_rec.line_id);
577
578 OE_Config_Util.Query_Included_Items(p_line_id => p_line_rec.line_id,
579 p_header_id => p_line_rec.header_id,
580 p_top_model_line_id => p_line_rec.top_model_line_id,
581 x_line_tbl => x_line_tbl);
582 IF l_debug_level > 0 THEN
583 oe_debug_pub.add( 'COUNT IS: ' || X_LINE_TBL.COUNT , 1 ) ;
584 END IF;
585
586 END IF;
587
588 IF l_debug_level > 0 THEN
589 oe_debug_pub.add( 'EXITING BUILD_INCLUDED_ITEMS' , 1 ) ;
590 END IF;
591 -- RETURN l_line_tbl;
592
593 EXCEPTION
594
595 WHEN FND_API.G_EXC_ERROR THEN
596 RAISE FND_API.G_EXC_ERROR;
597
598 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
599
600 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
601 THEN
602 OE_MSG_PUB.Add_Exc_Msg
603 ( G_PKG_NAME
604 , 'Build_Included_Items'
605 );
606 END IF;
607
608
609 WHEN OTHERS THEN
610
611
612 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
613 THEN
614 OE_MSG_PUB.Add_Exc_Msg
615 ( G_PKG_NAME
616 , 'Build_Included_Items'
617 );
618 END IF;
619
620 END Build_Included_Items;
621
622 /* -----------------------------------------------------------
623 Procedure: Schedule_Parent_line
624 Description:This procedure will be called, if the user is trying to
625 schedule a parent (a model or a class) of a non-ship model
626 complete PTO. We need to get included items associated with the
627 parent before we schedule the line.
628 ---------------------------------------------------------------*/
629 Procedure Schedule_Parent_line
630 ( p_old_line_rec IN OE_ORDER_PUB.line_rec_type
631 , p_write_to_db IN VARCHAR2
632 , p_x_line_rec IN OUT NOCOPY OE_ORDER_PUB.line_rec_type
633 , p_recursive_call IN VARCHAR2
634 , x_out_atp_tbl OUT NOCOPY /* file.sql.39 change */ OE_ATP.Atp_Tbl_Type
635 , x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
636 IS
637 l_line_rec OE_ORDER_PUB.line_rec_type;
638 l_line_tbl OE_ORDER_PUB.line_tbl_type;
639 l_new_line_tbl OE_ORDER_PUB.line_tbl_type;
640 l_included_items_tbl OE_ORDER_PUB.line_tbl_type;
641 l_old_line_tbl OE_ORDER_PUB.line_tbl_type;
642 l_inc_upd_tbl OE_ORDER_PUB.line_tbl_type;
643 l_inc_upd_index NUMBER;
644 l_inc_old_tbl OE_ORDER_PUB.line_tbl_type;
645 l_inc_old_index NUMBER;
646 l_top_old_tbl OE_ORDER_PUB.line_tbl_type;
647 l_top_old_index NUMBER;
648 l_explode BOOLEAN;
649 l_old_ordered_quantity NUMBER;
650 l_out_line_rec OE_ORDER_PUB.line_rec_type;
651 K NUMBER :=0;
652 atp_count NUMBER :=0;
653 l_out_atp_tbl OE_ATP.atp_tbl_type;
654 l_return_status VARCHAR2(1);
655 l_schedule_action_code VARCHAR2(30);
656 l_sales_order_id NUMBER;
657 l_old_recursion_mode VARCHAR2(1);
658 l_process_requests BOOLEAN;
659 --
660 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
661 --
662 BEGIN
663
664 IF l_debug_level > 0 THEN
665 oe_debug_pub.add( 'ENTERING SCHEDULE PARENT LINE '||P_X_LINE_REC.SCHEDULE_ACTION_CODE , 1 ) ;
666 END IF;
667
668 l_line_tbl(1) := p_x_line_rec;
669 l_old_line_tbl(1) := p_old_line_rec;
670 l_top_old_tbl(1) := p_old_line_rec;
671
672 -- We need to figure out the action which needs to be performed.
673
674 /*
675 IF p_x_line_rec.schedule_action_code is null THEN
676 IF p_x_line_rec.schedule_status_code is null THEN
677 -- The line was never scheduled before. So it needs to
678 -- get scheduled.
679 l_schedule_action_code := OESCH_ACT_SCHEDULE;
680 ELSIF p_x_line_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
681 l_schedule_action_code := OESCH_ACT_UNSCHEDULE;
682 ELSE
683 l_schedule_action_code := OESCH_ACT_RESCHEDULE;
684 END IF;
685 ELSE
686 l_schedule_action_code := p_x_line_rec.schedule_action_code;
687 END IF;
688
689 l_line_tbl(1).schedule_action_code := l_schedule_action_code;
690 oe_debug_pub.add('Action is ' || l_schedule_action_code,1);
691
692 */
693
694 -- The primary reason to have this procedure for parent lines
695 -- is because we need to prepare included items to scheduling when
696 -- it's parent is scheduled. Depending on the action needed to be performed,
697 -- we might need to explode the included items.
698
699 IF l_debug_level > 0 THEN
700 oe_debug_pub.add( 'SCH:CALLING BUILD_INCLUDED_ITEMS' , 1 ) ;
701 END IF;
702
703 -- l_included_items_tbl := Build_Included_Items
704 -- (p_line_rec => p_x_line_rec);
705
706 l_old_recursion_mode := OE_GLOBALS.G_RECURSION_MODE;
707
708 IF p_recursive_call = FND_API.G_TRUE
709 THEN
710
711 -- OE_GLOBALS.G_RECURSION_MODE := 'Y';
712 null;
713
714 END IF;
715
716 Build_Included_Items( p_line_rec => p_x_line_rec,
717 x_line_tbl => l_included_items_tbl);
718
719 -- OE_GLOBALS.G_RECURSION_MODE := l_old_recursion_mode;
720
721 IF l_debug_level > 0 THEN
722 oe_debug_pub.add( 'SCH:AFTER CALLING BUILD_INCLUDED_ITEMS' , 1 ) ;
723 END IF;
724
725 -- Starting with the index of 2 since the first element has
726 -- been occupied by the parent line.
727
728 -- Get reserved quantity for the lines.
729 l_sales_order_id := OE_ORDER_SCH_UTIL.Get_mtl_sales_order_id
730 (p_x_line_rec.HEADER_ID);
731
732 l_inc_old_index := 0;
733 l_top_old_index := 0;
734
735 K := 2;
736 FOR I IN 1..l_included_items_tbl.count LOOP
737
738 l_line_rec := l_included_items_tbl(I);
739
740 IF l_debug_level > 0 THEN
741 oe_debug_pub.add( 'SCHEDULE_STATUS CODE/LINE : '||L_LINE_REC.SCHEDULE_STATUS_CODE||'/'||L_LINE_REC.LINE_ID , 3 ) ;
742 END IF;
743
744 IF p_x_line_rec.schedule_action_code = OESCH_ACT_SCHEDULE AND
745 l_line_rec.schedule_status_code IS NOT NULL THEN
746
747 GOTO END_INCLUDED;
748
749 END IF;
750
751 l_old_line_tbl(K) := l_line_rec;
752
753 l_line_rec.schedule_action_code :=
754 p_x_line_rec.schedule_action_code;
755
756 l_line_rec.operation := OE_GLOBALS.G_OPR_UPDATE;
757
758 /* -----------Bug 2315471 Start ---------------------*/
759
760 IF NOT OE_GLOBALS.Equal(p_x_line_rec.ordered_quantity,
761 p_old_line_rec.ordered_quantity)
762 AND p_x_line_rec.ordered_quantity = 0 THEN
763 l_line_rec.schedule_action_code := OESCH_ACT_UNDEMAND;
764 END IF;
765
766 /* -----------Bug 2315471 End -----------------------*/
767
768
769 IF NOT OE_GLOBALS.Equal(p_x_line_rec.ship_from_org_id,
770 p_old_line_rec.ship_from_org_id) OR
771 l_line_rec.ship_from_org_id IS NULL OR
772 l_line_rec.ship_from_org_id = FND_API.G_MISS_NUM
773 THEN
774 l_line_rec.ship_from_org_id :=
775 p_x_line_rec.ship_from_org_id;
776 END IF;
777
778 IF l_debug_level > 0 THEN
779 oe_debug_pub.add( 'OLD ORDERED QUANTITY : '|| P_OLD_LINE_REC.ORDERED_QUANTITY , 3 ) ;
780 oe_debug_pub.add( 'NEW ORDERED QUANTITY : '|| P_X_LINE_REC.ORDERED_QUANTITY , 3 ) ;
781 END IF;
782 IF NOT OE_GLOBALS.Equal(p_x_line_rec.ordered_quantity,
783 p_old_line_rec.ordered_quantity)
784 THEN
785 l_old_ordered_quantity := p_old_line_rec.ordered_quantity;
786 IF l_old_ordered_quantity IS null OR
787 l_old_ordered_quantity = 0 OR
788 l_old_ordered_quantity = FND_API.G_MISS_NUM THEN
789 l_old_ordered_quantity := p_x_line_rec.ordered_quantity;
790 END IF;
791
792 IF l_debug_level > 0 THEN
793 oe_debug_pub.add( 'OLD ORDERED QUANTITY : '|| L_OLD_ORDERED_QUANTITY , 3 ) ;
794 END IF;
795 /*
796 l_line_rec.ordered_quantity := l_line_rec.ordered_quantity *
797 p_x_line_rec.ordered_quantity /
798 l_old_ordered_quantity;
799 */
800 END IF;
801
802
803 IF NOT OE_GLOBALS.Equal(p_x_line_rec.schedule_ship_date,
804 p_old_line_rec.schedule_ship_date)
805 THEN
806 l_line_rec.schedule_ship_date := p_x_line_rec.schedule_ship_date;
807 END IF;
808
809 IF NOT OE_GLOBALS.Equal(p_x_line_rec.schedule_arrival_date,
810 p_old_line_rec.schedule_arrival_date)
811 THEN
812 l_line_rec.schedule_arrival_date :=
813 p_x_line_rec.schedule_arrival_date;
814 END IF;
815
816 IF NOT OE_GLOBALS.Equal(p_x_line_rec.shipping_method_code,
817 p_old_line_rec.shipping_method_code)
818 THEN
819 l_line_rec.shipping_method_code :=
820 p_x_line_rec.shipping_method_code;
821 END IF;
822
823 IF NOT OE_GLOBALS.Equal(p_x_line_rec.delivery_lead_time,
824 p_old_line_rec.delivery_lead_time)
825 THEN
826 l_line_rec.delivery_lead_time := p_x_line_rec.delivery_lead_time;
827 END IF;
828
829 l_line_rec.reserved_quantity :=
830 OE_LINE_UTIL.Get_Reserved_Quantity
831 (p_header_id => l_sales_order_id,
832 p_line_id => l_line_rec.line_id,
833 p_org_id => l_line_rec.ship_from_org_id);
834
835 -- Assigning the quried reserved quantity to old record to fix bug 1567015.
836
837 l_old_line_tbl(k).reserved_quantity := l_line_rec.reserved_quantity;
838
839 l_line_tbl(K) := l_line_rec;
840
841 IF l_line_rec.line_id = p_x_line_rec.line_id THEN
842 IF l_debug_level > 0 THEN
843 oe_debug_pub.add( 'ADDED TO TOP OLD TABLE '||L_LINE_REC.LINE_ID , 3 ) ;
844 END IF;
845 l_top_old_index := l_top_old_index + 1;
846 l_top_old_tbl(l_top_old_index) := l_old_line_tbl(K);
847 ELSE
848 IF l_debug_level > 0 THEN
849 oe_debug_pub.add( 'ADDED TO INCLUDED OLD TABLE '||L_LINE_REC.LINE_ID , 3 ) ;
850 END IF;
851 l_inc_old_index := l_inc_old_index + 1;
852 l_inc_old_tbl(l_inc_old_index) := l_old_line_tbl(K);
853
854 END IF;
855
856 K := K+1;
857
858 << END_INCLUDED >>
859 NULL;
860
861 END LOOP;
862
863 l_inc_upd_index := 0;
864
865 FOR I in 1..l_line_tbl.count LOOP
866
867 l_out_line_rec := l_line_tbl(I);
868 Process_request(p_x_line_rec => l_out_line_rec,
869 p_old_line_rec => l_old_line_tbl(I),
870 x_out_atp_tbl => l_out_atp_tbl ,
871 x_return_status => l_return_status);
872
873 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
874 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
875 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
876 RAISE FND_API.G_EXC_ERROR;
877 END IF;
878
879 IF p_x_line_rec.line_id = l_out_line_rec.line_id THEN
880 IF l_debug_level > 0 THEN
881 oe_debug_pub.add( 'ASSIGNING TO NEW TABLE '||L_OUT_LINE_REC.ORDERED_QUANTITY , 3 ) ;
882 END IF;
883 l_new_line_tbl(I) := l_out_line_rec;
884 ELSE
885 IF l_debug_level > 0 THEN
886 oe_debug_pub.add( 'ASSIGNING TO INCLUDED TABLE '||L_OUT_LINE_REC.ORDERED_QUANTITY , 3 ) ;
887 END IF;
888 l_inc_upd_index := l_inc_upd_index + 1;
889 l_inc_upd_tbl(l_inc_upd_index) := l_out_line_rec;
890
891 END IF;
892
893 l_line_tbl(I) := l_out_line_rec;
894
895 IF l_out_atp_tbl.count = 1 THEN
896 atp_count := atp_count + 1;
897 x_out_atp_tbl(atp_count) := l_out_atp_tbl(1);
898 END IF;
899 END LOOP;
900
901 -- Update order lines if the scheduling resulted in any attribute change.
902
903 IF NOT OE_GLOBALS.Equal(p_x_line_rec.schedule_action_code,
904 OESCH_ACT_ATP_CHECK) AND
905 NOT OE_GLOBALS.Equal(p_x_line_rec.schedule_action_code,
906 OESCH_ACT_UNRESERVE) AND
907 g_update_flag = FND_API.G_TRUE
908 THEN
909
910 IF l_debug_level > 0 THEN
911 oe_debug_pub.add( 'CALLING UPDATE_LINE_RECORD WITH NEW TABLE ' , 1 ) ;
912 END IF;
913
914 Update_line_record(p_line_tbl => l_top_old_tbl,
915 p_x_new_line_tbl => l_new_line_tbl,
916 p_write_to_db => p_write_to_db,
917 p_recursive_call => p_recursive_call,
918 x_return_status => l_return_status);
919
920 IF l_debug_level > 0 THEN
921 oe_debug_pub.add( 'AFTER CALLING UPDATE_LINE_RECORD :' || L_RETURN_STATUS , 1 ) ;
922 END IF;
923
924 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
925 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
926 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
927 RAISE FND_API.G_EXC_ERROR;
928 END IF;
929
930 IF l_inc_upd_index <> 0 THEN
931
932 IF l_debug_level > 0 THEN
933 oe_debug_pub.add( 'CALLING UPDATE_LINE_RECORD WITH INC TABLE '||L_INC_UPD_INDEX||'/'||L_INC_OLD_INDEX , 2 ) ;
934 END IF;
935
936 Update_line_record(p_line_tbl => l_inc_old_tbl,
937 p_x_new_line_tbl => l_inc_upd_tbl,
938 p_write_to_db => FND_API.G_TRUE,
939 p_recursive_call => p_recursive_call,
940 x_return_status => l_return_status);
941
942 IF l_debug_level > 0 THEN
943 oe_debug_pub.add( 'AFTER CALLING UPDATE_LINE_RECORD :' || L_RETURN_STATUS , 1 ) ;
944 END IF;
945
946 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
947 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
948 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
949 RAISE FND_API.G_EXC_ERROR;
950 END IF;
951
952 END IF;
953
954 -- Do not process delayed requests if this was a recursive
955 -- call (e.g. from oe_line_util.pre_write_process)
956 IF p_recursive_call = FND_API.G_TRUE THEN
957 l_process_requests := FALSE;
958 ELSE
959 l_process_requests := TRUE;
960 END IF;
961
962 -- 2351698.
963 IF OESCH_SCH_POST_WRITE = 'Y' THEN
964
965 l_line_tbl(1).operation := OE_GLOBALS.G_OPR_CREATE;
966
967 END IF;
968
969 OE_Order_PVT.Process_Requests_And_Notify
970 ( p_process_requests => l_process_requests
971 , p_notify => TRUE
972 , p_line_tbl => l_line_tbl
973 , p_old_line_tbl => l_old_line_tbl
974 , x_return_status => l_return_status
975 );
976
977 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
978 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
979 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
980 RAISE FND_API.G_EXC_ERROR;
981 END IF;
982
983 END IF;
984
985 p_x_line_rec := l_new_line_tbl(1);
986
987 IF l_debug_level > 0 THEN
988 oe_debug_pub.add( 'EXITING SCHEDULE PARENT LINE' , 1 ) ;
989 END IF;
990 EXCEPTION
991
992 WHEN FND_API.G_EXC_ERROR THEN
993
994 x_return_status := FND_API.G_RET_STS_ERROR;
995
996 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
997
998 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
999
1000 WHEN OTHERS THEN
1001
1002 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1003
1004 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1005 THEN
1006 OE_MSG_PUB.Add_Exc_Msg
1007 ( G_PKG_NAME
1008 , 'Schedule_Parent_line'
1009 );
1010 END IF;
1011
1012
1013 END Schedule_Parent_line;
1014
1015 /*-----------------------------------------------------------------------
1016 Procedure Name : Reschedule_Set
1017 Description : ** Currently Not Used **
1018 -------------------------------------------------------------------------- */
1019 Procedure Reschedule_Set
1020 (p_line_rec IN OE_ORDER_PUB.line_rec_type,
1021 p_old_line_rec IN OE_ORDER_PUB.line_rec_type,
1022 x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
1023 IS
1024 l_return_status VARCHAR2(1);
1025 l_line_tbl OE_ORDER_PUB.line_tbl_type;
1026 l_old_line_tbl OE_ORDER_PUB.line_tbl_type;
1027 l_atp_tbl OE_ATP.atp_tbl_type;
1028 l_count NUMBER;
1029 --
1030 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1031 --
1032 BEGIN
1033 IF l_debug_level > 0 THEN
1034 oe_debug_pub.add( 'ENTERING RESCHEDULE_SET' , 1 ) ;
1035 END IF;
1036 x_return_status := l_return_status;
1037 -- l_line_tbl := OE_Set_util.Query_Set_Rows(p_line_rec.ship_set_id);
1038 OE_Set_Util.Query_Set_Rows(p_set_id => p_line_rec.ship_set_id,
1039 x_line_tbl => l_line_tbl);
1040
1041 -- Let us first unschedule the whole set
1042 FOR I IN 1..l_line_tbl.count LOOP
1043 l_line_tbl(I).schedule_action_code :=
1044 OE_ORDER_SCH_UTIL.OESCH_ACT_UNDEMAND;
1045 END LOOP;
1046
1047 OE_GRP_SCH_UTIL.Process_set_of_lines
1048 ( p_old_line_tbl => l_old_line_tbl,
1049 p_write_to_db => FND_API.G_FALSE,
1050 x_atp_tbl => l_atp_tbl,
1051 p_x_line_tbl => l_line_tbl,
1052 x_return_status => l_return_status);
1053
1054 -- Now let us try to schedule the whole set with the new line
1055 -- which was to be inserted to the set.
1056
1057 l_count := l_line_tbl.count;
1058
1059 l_line_tbl(l_count+1) := p_line_rec;
1060 l_old_line_tbl(l_count+1) := p_old_line_rec;
1061
1062 -- Let us now schedule the whole set
1063 FOR I IN 1..l_line_tbl.count LOOP
1064 l_line_tbl(I).schedule_action_code :=
1065 OE_ORDER_SCH_UTIL.OESCH_ACT_SCHEDULE;
1066 END LOOP;
1067
1068 OE_GRP_SCH_UTIL.Process_set_of_lines
1069 ( p_old_line_tbl => l_old_line_tbl,
1070 p_write_to_db => FND_API.G_FALSE,
1071 x_atp_tbl => l_atp_tbl,
1072 p_x_line_tbl => l_line_tbl,
1073 x_return_status => l_return_status);
1074
1075 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1076 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1077 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1078 RAISE FND_API.G_EXC_ERROR;
1079 END IF;
1080
1081 IF l_debug_level > 0 THEN
1082 oe_debug_pub.add( 'EXITING RESCHEDULE_SET' , 1 ) ;
1083 END IF;
1084 END;
1085 /*---------------------------------------------------------------------
1086 Procedure Name : Action_Undemand
1087 Description : This procedure is called from SCHEDULE LINE proecudure
1088 to perform the UNDEMAD on the line when an item is changed.
1089 --------------------------------------------------------------------- */
1090
1091 Procedure Action_Undemand(p_old_line_rec IN OE_ORDER_PUB.line_rec_type,
1092 x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
1093
1094 IS
1095 l_old_line_tbl OE_ORDER_PUB.line_tbl_type;
1096 l_return_status VARCHAR2(1);
1097 l_msg_count NUMBER;
1098 l_msg_data VARCHAR2(2000);
1099 l_session_id NUMBER := 0;
1100 l_mrp_atp_rec MRP_ATP_PUB.ATP_Rec_Typ;
1101 l_out_mtp_atp_rec MRP_ATP_PUB.ATP_Rec_Typ;
1102 l_atp_supply_demand MRP_ATP_PUB.ATP_Supply_Demand_Typ;
1103 l_atp_period MRP_ATP_PUB.ATP_Period_Typ;
1104 l_atp_details MRP_ATP_PUB.ATP_Details_Typ;
1105
1106 --
1107 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1108 --
1109 BEGIN
1110
1111 IF l_debug_level > 0 THEN
1112 oe_debug_pub.add( 'ENTERING ACTION_UNDEMAND' , 1 ) ;
1113 END IF;
1114
1115 -- Create MRP record with action of UNDEMAND.
1116
1117
1118
1119 l_old_line_tbl(1) := p_old_line_rec;
1120 l_old_line_tbl(1).schedule_action_code := OESCH_ACT_UNDEMAND;
1121
1122 Load_MRP_Request
1123 ( p_line_tbl => l_old_line_tbl
1124 , p_old_line_tbl => l_old_line_tbl
1125 , x_atp_table => l_mrp_atp_rec);
1126
1127 l_session_id := Get_Session_Id;
1128
1129 -- Call ATP
1130
1131 IF l_debug_level > 0 THEN
1132 oe_debug_pub.add( '4. CALLING MRP API WITH SESSION ID '||L_SESSION_ID , 1 ) ;
1133 END IF;
1134
1135 MRP_ATP_PUB.Call_ATP
1136 ( p_session_id => l_session_id
1137 , p_atp_rec => l_mrp_atp_rec
1138 , x_atp_rec => l_out_mtp_atp_rec
1139 , x_atp_supply_demand => l_atp_supply_demand
1140 , x_atp_period => l_atp_period
1141 , x_atp_details => l_atp_details
1142 , x_return_status => l_return_status
1143 , x_msg_data => l_msg_data
1144 , x_msg_count => l_msg_count);
1145
1146 IF l_debug_level > 0 THEN
1147 oe_debug_pub.add( '4. AFTER CALLING MRP_ATP_PUB.CALL_ATP' || L_RETURN_STATUS , 1 ) ;
1148 END IF;
1149
1150 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1151 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1152 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1153 RAISE FND_API.G_EXC_ERROR;
1154 END IF;
1155
1156 IF l_debug_level > 0 THEN
1157 oe_debug_pub.add( 'EXITING ACTION_UNDEMAND' , 1 ) ;
1158 END IF;
1159
1160 END Action_Undemand;
1161
1162 /*-----------------------------------------------------------------------
1163 Procedure Name : Schedule_line
1164 Description : This routine is called when:
1165 Schedule_action is entered on a line
1166 Scheduling Attribute Changes on the line
1167 This procedure will take the new attributes and compares
1168 them to the old attributes and decide on what scheduling
1169 action needs to be performed.
1170 This API is called From
1171 1. Process_Order (in pre_write_process in OEXULINB.pls)
1172 2. Schedule Workflow Process (in OEXWSCHB.pls)
1173 3. Schedule_Order process (in OEXVGRPB.pls)
1174 4. Sch_Multi_Selected_Lines (in OEXVGRPB.pls)
1175
1176 -------------------------------------------------------------------------- */
1177
1178 Procedure Schedule_line( p_old_line_rec IN OE_ORDER_PUB.line_rec_type,
1179 p_write_to_db IN VARCHAR2,
1180 p_update_flag IN VARCHAR2 := FND_API.G_TRUE,
1181 p_recursive_call IN VARCHAR2 := FND_API.G_TRUE,
1182 p_x_line_rec IN OUT NOCOPY OE_ORDER_PUB.line_rec_type,
1183 x_atp_tbl OUT NOCOPY /* file.sql.39 change */ OE_ATP.atp_tbl_type,
1184 x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2
1185 )
1186 IS
1187 l_schedule_line_rec request_rec_type;
1188 l_line_rec OE_ORDER_PUB.line_rec_type;
1189 l_line_tbl OE_ORDER_PUB.line_tbl_type;
1190 l_new_line_tbl OE_ORDER_PUB.line_tbl_type;
1191 l_old_line_rec OE_ORDER_PUB.line_rec_type;
1192 l_out_line_rec OE_ORDER_PUB.line_rec_type;
1193 l_out_atp_tbl OE_ATP.atp_tbl_type;
1194 l_request_rec request_rec_type;
1195 l_group_req_rec OE_GRP_SCH_UTIL.Sch_Group_Rec_Type;
1196 l_out_request_rec request_rec_type;
1197 l_need_sch BOOLEAN;
1198 l_entity_type VARCHAR2(30);
1199 l_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
1200 l_dummy VARCHAR2(240);
1201 l_set_id NUMBER;
1202 l_sales_order_id NUMBER;
1203 l_request_type VARCHAR2(30);
1204 l_schedule_ship_date DATE;
1205 l_schedule_arrival_date DATE;
1206 l_action VARCHAR2(30);
1207 l_o_request_date DATE := null;
1208 l_o_sch_ship_date DATE := null;
1209 l_o_sch_arr_date DATE := null;
1210 l_o_ship_from_org_id NUMBER := null;
1211 l_o_ship_to_org_id NUMBER := null;
1212 l_o_ord_qty NUMBER := null;
1213 l_o_ord_qty2 NUMBER := null; -- INVCONV
1214 l_type_code VARCHAR2(30);
1215 l_param NUMBER;
1216 l_process_requests BOOLEAN;
1217 l_set_rec OE_ORDER_CACHE.set_rec_type;
1218 --
1219 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1220 --
1221 BEGIN
1222
1223
1224 IF l_debug_level > 0 THEN
1225 oe_debug_pub.add( '56: ENTERING OE_ORDER_SCH_UTIL.SCHEDULE_LINE' , 1 ) ;
1226 oe_debug_pub.add( '---- OLD RECORD ---- ' , 1 ) ;
1227 oe_debug_pub.add( 'LINE ID : ' || P_OLD_LINE_REC.LINE_ID , 1 ) ;
1228 oe_debug_pub.add( 'ATO LINE ID : ' || P_OLD_LINE_REC.ATO_LINE_ID , 1 ) ;
1229 oe_debug_pub.add( 'ORDERED QUANTITY : ' || P_OLD_LINE_REC.ORDERED_QUANTITY , 1 ) ;
1230 oe_debug_pub.add( 'SHIP FROM : ' || P_OLD_LINE_REC.SHIP_FROM_ORG_ID , 1 ) ;
1231 oe_debug_pub.add( 'SUBINVENTORY : ' || P_OLD_LINE_REC.SUBINVENTORY , 1 ) ;
1232 oe_debug_pub.add( 'SCH SHIP DATE : ' || P_OLD_LINE_REC.SCHEDULE_SHIP_DATE , 1 ) ;
1233 oe_debug_pub.add( 'SCH ARRIVAL DATE : ' || P_OLD_LINE_REC.SCHEDULE_ARRIVAL_DATE , 1 ) ;
1234 oe_debug_pub.add( 'SHIP SET ID : ' || P_OLD_LINE_REC.SHIP_SET_ID , 1 ) ;
1235 oe_debug_pub.add( 'ARRIVAL SET ID : ' || P_OLD_LINE_REC.ARRIVAL_SET_ID , 1 ) ;
1236 oe_debug_pub.add( 'ACTION : ' || P_OLD_LINE_REC.SCHEDULE_ACTION_CODE , 1 ) ;
1237 oe_debug_pub.add( 'STATUS : ' || P_OLD_LINE_REC.SCHEDULE_STATUS_CODE , 1 ) ;
1238 oe_debug_pub.add( 'RESERVED QUANTITY: ' || P_OLD_LINE_REC.RESERVED_QUANTITY , 1 ) ;
1239 oe_debug_pub.add( ' ' , 1 ) ;
1240 oe_debug_pub.add( '---- NEW RECORD ----' , 1 ) ;
1241 oe_debug_pub.add( 'LINE ID : ' || P_X_LINE_REC.LINE_ID , 1 ) ;
1242 oe_debug_pub.add( 'ATO LINE ID : ' || P_X_LINE_REC.ATO_LINE_ID , 1 ) ;
1243 oe_debug_pub.add( 'ORDERED QUANTITY : ' || P_X_LINE_REC.ORDERED_QUANTITY , 1 ) ;
1244 oe_debug_pub.add( 'ORDERED QUANTITY2 : ' || P_X_LINE_REC.ORDERED_QUANTITY2 , 1 ) ;
1245 oe_debug_pub.add( 'SHIP FROM : ' || P_X_LINE_REC.SHIP_FROM_ORG_ID , 1 ) ;
1246 oe_debug_pub.add( 'SUBINVENTORY : ' || P_X_LINE_REC.SUBINVENTORY , 1 ) ;
1247 oe_debug_pub.add( 'SCH SHIP DATE : ' || P_X_LINE_REC.SCHEDULE_SHIP_DATE , 1 ) ;
1248 oe_debug_pub.add( 'SCH ARRIVAL DATE : ' || P_X_LINE_REC.SCHEDULE_ARRIVAL_DATE , 1 ) ;
1249 oe_debug_pub.add( 'SHIP SET ID : ' || P_X_LINE_REC.SHIP_SET_ID , 1 ) ;
1250 oe_debug_pub.add( 'ARRIVAL SET ID : ' || P_X_LINE_REC.ARRIVAL_SET_ID , 1 ) ;
1251 oe_debug_pub.add( 'ACTION : ' || P_X_LINE_REC.SCHEDULE_ACTION_CODE , 1 ) ;
1252 oe_debug_pub.add( 'STATUS : ' || P_X_LINE_REC.SCHEDULE_STATUS_CODE , 1 ) ;
1253 oe_debug_pub.add( 'RESERVED QTY : ' || P_X_LINE_REC.RESERVED_QUANTITY , 1 ) ;
1254 oe_debug_pub.add( 'RESERVED QTY2 : ' || P_X_LINE_REC.RESERVED_QUANTITY2 , 1 ) ;
1255 oe_debug_pub.add( 'OPERATION : ' || P_X_LINE_REC.OPERATION , 1 ) ;
1256 oe_debug_pub.add( ' ' , 1 ) ;
1257 END IF;
1258
1259
1260 l_line_rec := p_x_line_rec;
1261 l_old_line_rec := p_old_line_rec;
1262
1263 -- Copying the value of p_update_flag to g_update_flag. G_UPDATE_FLAG
1264 -- value might be modified by process_request procedure.
1265
1266 g_update_flag := p_update_flag;
1267
1268 -- We need to decide the value of re_source_flag of the line before
1269 -- we proceed with scheduling.
1270
1271 IF l_line_rec.ship_from_org_id = FND_API.G_MISS_NUM THEN
1272 l_line_rec.ship_from_org_id := null;
1273 END IF;
1274
1275 IF l_old_line_rec.ship_from_org_id = FND_API.G_MISS_NUM THEN
1276 l_old_line_rec.ship_from_org_id := null;
1277 END IF;
1278
1279
1280 IF NOT OE_GLOBALS.Equal(l_old_line_rec.ship_from_org_id,
1281 l_line_rec.ship_from_org_id) THEN
1282 IF l_line_rec.ship_from_org_id is not null
1283 THEN
1284 IF l_debug_level > 0 THEN
1285 oe_debug_pub.add( 'SETTING RE_SOURCE_FLAG TO N' , 1 ) ;
1286 END IF;
1287 l_line_rec.re_source_flag := 'N';
1288 ELSE
1289 IF l_debug_level > 0 THEN
1290 oe_debug_pub.add( '1.SETTING RE_SOURCE_FLAG TO NULL' , 1 ) ;
1291 END IF;
1292 l_line_rec.re_source_flag := '';
1293 END IF;
1294 ELSIF l_line_rec.ship_from_org_id is null
1295 THEN
1296 IF l_debug_level > 0 THEN
1297 oe_debug_pub.add( '2.SETTING RE_SOURCE_FLAG TO NULL' , 1 ) ;
1298 END IF;
1299 l_line_rec.re_source_flag := '';
1300 END IF;
1301
1302 l_new_line_tbl(1) := l_line_rec;
1303
1304 -- Query the old reservations from reservations table
1305
1306
1307 IF l_line_rec.schedule_status_code is not null THEN
1308
1309 l_sales_order_id := Get_mtl_sales_order_id(l_line_rec.HEADER_ID);
1310
1311 IF l_old_line_rec.reserved_quantity is null THEN
1312 IF l_debug_level > 0 THEN
1313 oe_debug_pub.add( 'RR: L_OLD_LINE_REC.RESERVED_QUANTITY IS NULL' , 1 ) ;
1314 END IF;
1315 ELSIF l_old_line_rec.reserved_quantity = FND_API.G_MISS_NUM THEN
1316 IF l_debug_level > 0 THEN
1317 oe_debug_pub.add( 'RR: L_OLD_LINE_REC.RESERVED_QUANTITY IS MISSING' , 1 ) ;
1318 END IF;
1319 END IF;
1320
1321 -- INVCONV - MERGED CALLS FOR OE_LINE_UTIL.Get_Reserved_Quantity and OE_LINE_UTIL.Get_Reserved_Quantity2
1322
1323 OE_LINE_UTIL.Get_Reserved_Quantities(p_header_id => l_sales_order_id
1324 ,p_line_id => l_line_rec.line_id
1325 ,p_org_id => l_line_rec.ship_from_org_id
1326 ,x_reserved_quantity => l_old_line_rec.reserved_quantity
1327 ,x_reserved_quantity2 => l_old_line_rec.reserved_quantity2
1328 );
1329 /*l_old_line_rec.reserved_quantity :=
1330 OE_LINE_UTIL.Get_Reserved_Quantity
1331 (p_header_id => l_sales_order_id,
1332 p_line_id => l_line_rec.line_id,
1333 p_org_id => l_line_rec.ship_from_org_id);
1334
1335 l_old_line_rec.reserved_quantity2 := -- INVCONV
1336 OE_LINE_UTIL.Get_Reserved_Quantity2
1337 (p_header_id => l_sales_order_id,
1338 p_line_id => l_line_rec.line_id,
1339 p_org_id => l_line_rec.ship_from_org_id); */
1340
1341 ELSE
1342 l_old_line_rec.reserved_quantity := null;
1343 l_old_line_rec.reserved_quantity2 := null; -- INVCONV
1344 END IF;
1345
1346 IF l_old_line_rec.reserved_quantity = 0
1347 THEN
1348 -- Currently setting the reserved quantity to null if it is zero.
1349 l_old_line_rec.reserved_quantity := null;
1350 END IF;
1351
1352 IF l_old_line_rec.reserved_quantity2 = 0 -- INVCONV
1353 THEN
1354 -- Currently setting the reserved2 quantity to null if it is zero.
1355 l_old_line_rec.reserved_quantity2 := null;
1356 END IF;
1357
1358 IF l_line_rec.reserved_quantity = FND_API.G_MISS_NUM
1359 THEN
1360 -- Converting missing to old value
1361 l_line_rec.reserved_quantity := l_old_line_rec.reserved_quantity;
1362 END IF;
1363
1364 IF l_line_rec.reserved_quantity2 = FND_API.G_MISS_NUM -- INVCONV
1365 THEN
1366 -- Converting missing to old value
1367 l_line_rec.reserved_quantity2 := l_old_line_rec.reserved_quantity2;
1368 END IF;
1369
1370 IF l_debug_level > 0 THEN
1371 oe_debug_pub.add( ' ' , 1 ) ;
1372 oe_debug_pub.add( 'OLD RESERVED QUANTITY :' || L_OLD_LINE_REC.RESERVED_QUANTITY , 1 ) ;
1373 oe_debug_pub.add( 'NEW RESERVED QUANTITY :' || L_LINE_REC.RESERVED_QUANTITY , 1 ) ;
1374 oe_debug_pub.add( 'OLD RESERVED QUANTITY2 :' || L_OLD_LINE_REC.RESERVED_QUANTITY2 , 1 ) ; -- INVCONV
1375 oe_debug_pub.add( 'NEW RESERVED QUANTITY2 :' || L_LINE_REC.RESERVED_QUANTITY2 , 1 ) ; -- INVCONV
1376 oe_debug_pub.add( ' ' , 1 ) ;
1377 END IF;
1378
1379 l_need_sch := Need_Scheduling(p_line_rec => l_line_rec,
1380 p_old_line_rec => l_old_line_rec);
1381
1382 IF not(l_need_sch) THEN
1383 IF l_debug_level > 0 THEN
1384 oe_debug_pub.add( 'SCHEDULING NOT REQUIRED' , 1 ) ;
1385 END IF;
1386 goto end_schedule_line;
1387 END IF;
1388
1389 IF l_debug_level > 0 THEN
1390 oe_debug_pub.add( 'CALLING OE_ORDER_SCH_UTIL.VALIDATE LINE' , 1 ) ;
1391 END IF;
1392
1393 Validate_Line(p_line_rec => l_line_rec,
1394 p_old_line_rec => l_old_line_rec,
1395 x_return_status => l_return_status);
1396
1397 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1398 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1399 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1400 l_return_status := FND_API.G_RET_STS_ERROR;
1401 goto end_schedule_line;
1402 END IF;
1403
1404 /*
1405 Check to see what type of line is this :
1406
1407 1 - PTO : Will go through normal scheduling.
1408
1409 2 - ATO Item : Will go through normal scheduling.
1410
1411 3 - ATO Model : We will translate this request into a group
1412 request if there is an action on it, and then call Group_Scheduling
1413 to perform the action.
1414
1415 4 - ATO Option : Will go through normal scheduling.
1416 */
1417
1418 IF OESCH_PERFORM_GRP_SCHEDULING = 'Y' AND
1419 Group_Scheduling_Required(p_line_rec => l_line_rec,
1420 p_old_line_rec => l_old_line_rec)
1421 THEN
1422 -- Get the Order Date Type Code
1423 l_type_code := Get_Date_Type(l_line_rec.header_id);
1424 IF ((l_line_rec.schedule_status_code IS NOT NULL AND
1425 l_line_rec.schedule_status_code <> FND_API.G_MISS_CHAR) AND
1426 l_line_rec.operation = OE_GLOBALS.G_OPR_UPDATE AND
1427 (NOT OE_GLOBALS.Equal(p_x_line_rec.inventory_item_id,
1428 p_old_line_rec.inventory_item_id)))
1429 THEN
1430
1431 -- If the scheduling is happening due to inventory item change.
1432 -- We should call MRP twice. First time we should call MRP with
1433 -- Undemand for old item. Second call would be redemand.
1434
1435 IF (l_old_line_rec.reserved_quantity is not null AND
1436 l_old_line_rec.reserved_quantity <> FND_API.G_MISS_NUM)
1437 THEN
1438
1439 -- Call INV API to delete the reservations on the line.
1440
1441
1442 Unreserve_Line
1443 ( p_line_rec => l_old_line_rec
1444 , p_quantity_to_unreserve => l_old_line_rec.reserved_quantity
1445 , p_quantity2_to_unreserve => l_old_line_rec.reserved_quantity2 -- INVCONV
1446 , x_return_status => l_return_status);
1447
1448 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1449 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1450 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1451 RAISE FND_API.G_EXC_ERROR;
1452 END IF;
1453
1454
1455 END IF;
1456
1457 Action_Undemand(p_old_line_rec => l_old_line_rec,
1458 x_return_status => l_return_status);
1459
1460
1461 END IF; -- Undemand.
1462
1463 IF l_line_rec.schedule_action_code is null THEN
1464
1465 IF (l_line_rec.ato_line_id is not null) THEN
1466 l_entity_type := OESCH_ENTITY_ATO_CONFIG;
1467 l_set_id := p_x_line_rec.ato_line_id;
1468 END IF;
1469
1470 IF nvl(l_line_rec.ship_model_complete_flag,'N') = 'Y' THEN
1471 l_entity_type := OESCH_ENTITY_SMC;
1472 l_set_id := p_x_line_rec.top_model_line_id;
1473 END IF;
1474
1475 -- Fix for bug 2898623 added AND condition
1476 IF ((l_line_rec.ship_set_id is not null) AND
1477 (l_line_rec.ordered_quantity > 0)) THEN
1478 l_entity_type := OESCH_ENTITY_SHIP_SET;
1479 l_set_id := p_x_line_rec.ship_set_id;
1480 END IF;
1481
1482 -- Fix for bug 2898623 added AND condition
1483 IF ((l_line_rec.arrival_set_id is not null) AND
1484 (l_line_Rec.ordered_quantity > 0)) THEN
1485 l_entity_type := OESCH_ENTITY_ARRIVAL_SET;
1486 l_set_id := p_x_line_rec.arrival_set_id;
1487 END IF;
1488
1489 IF l_line_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
1490
1491 -- Line is getting created, and is also being added to a set.
1492
1493 IF l_line_rec.ato_line_id is NOT NULL THEN
1494
1495 IF l_line_rec.ship_model_complete_flag = 'Y' THEN
1496
1497 l_param := l_line_rec.top_model_line_id;
1498
1499 ELSE
1500
1501 l_param := l_line_rec.ato_line_id;
1502
1503 END IF;
1504 IF l_debug_level > 0 THEN
1505 oe_debug_pub.add( 'LOGGING REQUEST: GROUP_SCHEDULE ATO' , 1 ) ;
1506 oe_debug_pub.add( 'L_PARAM ' || L_PARAM , 1 ) ;
1507 END IF;
1508
1509 OE_delayed_requests_Pvt.log_request
1510 (p_entity_code => OE_GLOBALS.G_ENTITY_LINE,
1511 p_entity_id => l_param,
1512 p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
1513 p_requesting_entity_id => p_x_line_rec.line_id,
1514 p_request_type => OE_GLOBALS.G_GROUP_SCHEDULE,
1515 p_param1 => l_set_id,
1516 p_param2 => p_x_line_rec.header_id,
1517 p_param3 => l_entity_type,
1518 p_param4 => OESCH_ACT_RESCHEDULE,
1519 p_param11 => 'Y',
1520 x_return_status => l_return_status);
1521
1522 goto end_schedule_line;
1523
1524 ELSE -- Not an ato option/class
1525 IF l_debug_level > 0 THEN
1526 oe_debug_pub.add( 'LOGGING REQUEST: SCHEDULE LINE' , 1 ) ;
1527 END IF;
1528
1529 OE_delayed_requests_Pvt.log_request
1530 (p_entity_code => OE_GLOBALS.G_ENTITY_LINE,
1531 p_entity_id => l_line_rec.line_id,
1532 p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
1533 p_requesting_entity_id => l_line_rec.line_id,
1534 p_request_type => OE_GLOBALS.G_SCHEDULE_LINE,
1535 p_param1 => l_set_id,
1536 p_param2 => p_x_line_rec.header_id,
1537 p_param3 => l_entity_type,
1538 x_return_status => l_return_status);
1539
1540 goto end_schedule_line;
1541
1542 END IF; -- ATO Check
1543 ELSIF l_line_rec.operation = OE_GLOBALS.G_OPR_UPDATE AND
1544 ((NOT OE_GLOBALS.Equal(p_x_line_rec.ship_set_id,
1545 p_old_line_rec.ship_set_id)) OR
1546 (NOT OE_GLOBALS.Equal(p_x_line_rec.arrival_set_id,
1547 p_old_line_rec.arrival_set_id)))
1548 THEN
1549
1550 -- Line is either being moved from one set to another,
1551 -- or is being added to a new set.
1552
1553 IF l_line_rec.schedule_status_code is null THEN
1554
1555 -- New line which is being added to the set is not
1556 -- scheduled.
1557
1558 l_request_type := OE_GLOBALS.G_SCHEDULE_LINE;
1559 l_o_request_date := l_old_line_rec.request_date;
1560 l_o_ship_from_org_id := l_old_line_rec.ship_from_org_id;
1561 l_o_ship_to_org_id := l_old_line_rec.ship_to_org_id;
1562
1563
1564 ELSE
1565
1566 -- Code for bug 2431390.
1567 -- See if any schedule attributes are changed along with the
1568 -- set information, if changed we cannot bypass ato call.
1569
1570 IF NOT Schedule_Attribute_Changed(p_line_rec => l_line_rec,
1571 p_old_line_rec => l_old_line_rec)
1572 AND OE_GLOBALS.Equal(l_line_rec.ordered_quantity,
1573 l_old_line_rec.ordered_quantity)
1574 AND (l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_STANDARD OR
1575 nvl(l_line_rec.model_remnant_flag,'N') = 'Y')
1576 THEN
1577
1578
1579 IF l_line_rec.arrival_set_id is not null OR
1580 l_line_rec.ship_set_id IS NOT NULL THEN
1581 l_set_rec := OE_ORDER_CACHE.Load_Set
1582 (nvl(l_line_rec.arrival_set_id,l_line_rec.ship_set_id));
1583 ELSE
1584 l_set_rec := Null;
1585 END IF;
1586
1587
1588 IF l_set_rec.ship_from_org_id is null
1589 OR l_set_rec.ship_from_org_id = FND_API.G_MISS_NUM THEN
1590
1591 IF l_debug_level > 0 THEN
1592 oe_debug_pub.add( 'ONLY SCHEDULED LINE IS GETTING INTO NEW SET' , 2 ) ;
1593 END IF;
1594
1595 GOTO end_schedule_line;
1596
1597 ELSE
1598
1599 IF oe_grp_sch_util.Compare_Set_Attr
1600 (p_set_ship_from_org_id => l_set_rec.ship_from_org_id ,
1601 p_line_ship_from_org_id => l_line_rec.ship_from_org_id,
1602 p_set_ship_to_org_id => l_set_rec.ship_to_org_id ,
1603 p_line_ship_to_org_id => l_line_rec.ship_to_org_id ,
1604 p_set_schedule_ship_date => l_set_rec.schedule_ship_date ,
1605 p_line_schedule_ship_date => l_line_rec.schedule_ship_date,
1606 p_set_arrival_date => l_set_rec.schedule_arrival_date,
1607 p_line_arrival_date => l_line_rec.schedule_arrival_date,
1608 p_set_type => l_set_rec.set_type) THEN
1609
1610 IF l_debug_level > 0 THEN
1611 oe_debug_pub.add( 'ONLY SCHEDULED LINE IS GETTING INTO OLD SET' , 2 ) ;
1612 END IF;
1613
1614 GOTO end_schedule_line;
1615
1616 END IF; -- compare.
1617
1618
1619 END IF; -- ship from .
1620 END IF; -- end of 2431390.
1621
1622 -- New line which is being added to the set is
1623 -- scheduled. We need to reschedule it with
1624 -- the set attributes.
1625
1626 l_request_type := OE_GLOBALS.G_RESCHEDULE_LINE;
1627 l_o_request_date := l_old_line_rec.request_date;
1628 l_o_sch_ship_date := l_old_line_rec.schedule_ship_date;
1629 l_o_sch_arr_date := l_old_line_rec.schedule_arrival_date;
1630 l_o_ship_from_org_id := l_old_line_rec.ship_from_org_id;
1631 l_o_ship_to_org_id := l_old_line_rec.ship_to_org_id;
1632 l_o_ord_qty := l_old_line_rec.ordered_quantity;
1633 l_o_ord_qty2 := l_old_line_rec.ordered_quantity2;
1634
1635 END IF;
1636
1637 IF l_debug_level > 0 THEN
1638 oe_debug_pub.add( '2. LOGGING REQUEST: '|| OE_GLOBALS.G_SCHEDULE_LINE , 1 ) ;
1639 END IF;
1640 -- Added param7 to list to fix bug 1894284.
1641 OE_delayed_requests_Pvt.log_request
1642 (p_entity_code => OE_GLOBALS.G_ENTITY_LINE,
1643 p_entity_id => l_line_rec.line_id,
1644 p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
1645 p_requesting_entity_id => l_line_rec.line_id,
1646 p_request_type => l_request_type,
1647 p_param1 => l_set_id,
1648 p_param2 => p_x_line_rec.header_id,
1649 p_param3 => l_entity_type,
1650 p_date_param1 => l_o_request_date,
1651 p_date_param2 => l_o_sch_ship_date,
1652 p_date_param3 => l_o_sch_arr_date,
1653 p_param7 => l_o_ship_from_org_id,
1654 p_param8 => l_o_ship_to_org_id,
1655 p_param9 => l_old_line_rec.ship_set_id,
1656 p_param10 => l_old_line_rec.arrival_set_id,
1657 x_return_status => l_return_status);
1658
1659 goto end_schedule_line;
1660
1661 ELSE
1662
1663
1664 -- There is a change to a attribute of a line which belongs
1665 -- to a set and will affect the whole set.Logging a delayed
1666 -- request since it will affect the whole set.
1667
1668 IF l_debug_level > 0 THEN
1669 oe_debug_pub.add( '2. LOGGING A GROUP_SCH_REQUEST' , 1 ) ;
1670 oe_debug_pub.add( 'SET ATTRIBUTE HAS BEEN CHANGED' , 1 ) ;
1671 END IF;
1672
1673 -- Group is either being rescheduling, and being scheduled for the
1674 -- first time.
1675
1676 IF l_line_rec.schedule_status_code is null THEN
1677 l_action := OESCH_ACT_SCHEDULE;
1678 ELSE
1679 l_action := OESCH_ACT_RESCHEDULE;
1680 END IF;
1681
1682 /*
1683 IF NOT OE_GLOBALS.Equal(l_line_rec.request_date,
1684 l_old_line_rec.request_date)
1685 THEN
1686 IF (l_type_code = 'ARRIVAL') THEN
1687 l_line_rec.schedule_arrival_date := l_line_rec.request_date;
1688 ELSE
1689 l_line_rec.schedule_ship_date := l_line_rec.request_date;
1690 END IF;
1691 l_new_line_tbl(1) := l_line_rec;
1692 END IF;
1693 */
1694
1695 -- We dont require this check here. This data will be
1696 -- used in group_schedule delayed request.
1697 /* IF NOT OE_GLOBALS.Equal(l_line_rec.schedule_ship_date,
1698 l_old_line_rec.schedule_ship_date)
1699 THEN
1700 l_schedule_ship_date := l_old_line_rec.schedule_ship_date;
1701 END IF;
1702
1703 IF NOT OE_GLOBALS.Equal(l_line_rec.schedule_arrival_date,
1704 l_old_line_rec.schedule_arrival_date)
1705 THEN
1706 l_schedule_arrival_date := l_old_line_rec.schedule_arrival_date;
1707 END IF;
1708 */
1709
1710 l_schedule_ship_date := l_old_line_rec.schedule_ship_date;
1711 l_schedule_arrival_date := l_old_line_rec.schedule_arrival_date;
1712 IF l_debug_level > 0 THEN
1713 oe_debug_pub.add( '2. LOGGING A GROUP_SCH_REQUEST' , 1 ) ;
1714 END IF;
1715
1716 OE_delayed_requests_Pvt.log_request
1717 (p_entity_code => OE_GLOBALS.G_ENTITY_LINE,
1718 p_entity_id => p_x_line_rec.line_id,
1719 p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
1720 p_requesting_entity_id => p_x_line_rec.line_id,
1721 p_request_type => OE_GLOBALS.G_GROUP_SCHEDULE,
1722 p_param1 => l_set_id,
1723 p_param2 => p_x_line_rec.header_id,
1724 p_param3 => l_entity_type,
1725 p_param4 => l_action,
1726 p_param7 => l_old_line_rec.ship_from_org_id,
1727 p_date_param1 => l_schedule_ship_date,
1728 p_date_param2 => l_schedule_arrival_date,
1729 p_date_param3 => l_old_line_rec.request_date,
1730 p_param9 => l_old_line_rec.ship_set_id,
1731 p_param10 => l_old_line_rec.arrival_set_id,
1732 x_return_status => l_return_status);
1733
1734
1735 goto end_schedule_line;
1736
1737 END IF;
1738 ELSE
1739
1740 IF l_debug_level > 0 THEN
1741 oe_debug_pub.add( 'CALLING CREATE_GROUP_REQUEST' , 1 ) ;
1742 END IF;
1743
1744 Create_Group_Request(p_line_rec => l_line_rec,
1745 p_old_line_rec => p_old_line_rec,
1746 x_group_req_rec => l_group_req_rec,
1747 x_return_status => l_return_status);
1748
1749 IF l_debug_level > 0 THEN
1750 oe_debug_pub.add( 'AFTER CALLING CREATE_GROUP_REQUEST: ' || L_RETURN_STATUS , 1 ) ;
1751 END IF;
1752
1753 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1754 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1755 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1756 RAISE FND_API.G_EXC_ERROR;
1757 END IF;
1758
1759 IF l_debug_level > 0 THEN
1760 oe_debug_pub.add( 'CALLING GROUP_SCHEDULE' , 1 ) ;
1761 END IF;
1762
1763 OE_GRP_SCH_UTIL.Group_Schedule
1764 ( p_group_req_rec => l_group_req_rec
1765 ,x_atp_tbl => l_out_atp_tbl
1766 ,x_return_status => l_return_status);
1767
1768 IF l_debug_level > 0 THEN
1769 oe_debug_pub.add( 'AFTER CALLING GROUP_SCHEDULE: ' || L_RETURN_STATUS , 1 ) ;
1770 END IF;
1771
1772 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1773 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1774 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1775 RAISE FND_API.G_EXC_ERROR;
1776 END IF;
1777
1778 IF NOT OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
1779 OESCH_ACT_ATP_CHECK)
1780 THEN
1781
1782 -- Group Schedule had updated all the scheduling related
1783 -- attributes on the line. But there could be non scheduling
1784 -- related attributes which could have changed and whose
1785 -- values are in p_line_rec. We will update the p_line_rec
1786 -- with scheduling attributes which have been saved to the
1787 -- database.
1788
1789 IF l_debug_level > 0 THEN
1790 oe_debug_pub.add( 'CALLING UPDATE_GROUP_SCH_RESULTS' , 1 ) ;
1791 END IF;
1792
1793 l_out_line_rec := l_line_rec;
1794
1795 Update_Group_Sch_Results(p_x_line_rec => l_out_line_rec,
1796 x_return_status => l_return_status);
1797
1798 IF l_debug_level > 0 THEN
1799 oe_debug_pub.add( 'AFTER CALLING UPDATE_GROUP_SCH_RESULTS' , 1 ) ;
1800 END IF;
1801 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1802 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1803 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1804 RAISE FND_API.G_EXC_ERROR;
1805 END IF;
1806
1807 -- Set the cascade_flag to TRUE, so that we query the block,
1808 -- since multiple lines have changed.
1809
1810 IF l_debug_level > 0 THEN
1811 oe_debug_pub.add( 'SETTING G_CASCADING_REQUEST_LOGGED' , 1 ) ;
1812 END IF;
1813 OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
1814 l_new_line_tbl(1) := l_out_line_rec;
1815
1816 END IF;
1817
1818 goto end_schedule_line;
1819
1820 END IF; /* calling group_request */
1821
1822 END IF;
1823
1824 -- Follow this path only for standard items and option items.
1825
1826 /*
1827 Check_Item_Attribute(p_line_rec => l_line_rec);
1828 */
1829
1830 -- Scheduling Parent lines separately. These parent lines will be for
1831 -- non-SMC complete PTO only. For parents, the group request would have
1832 -- taken care of it.
1833
1834 IF (l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_MODEL OR
1835 l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_CLASS OR
1836 l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_KIT) AND
1837 l_line_rec.ato_line_id is null THEN
1838
1839
1840
1841 IF l_line_rec.OPERATION = OE_GLOBALS.G_OPR_CREATE THEN
1842
1843 IF l_debug_level > 0 THEN
1844 oe_debug_pub.add( 'CALL SCHEDULE_PARENT_LINE IN POST-WRITE' , 3 ) ;
1845 END IF;
1846
1847 OESCH_SCH_POST_WRITE := 'Y';
1848
1849 l_out_line_rec := l_line_rec;
1850 ELSE
1851
1852 IF l_debug_level > 0 THEN
1853 oe_debug_pub.add( 'SCH: CALLING SCHEDULE_PARENT_LINE' , 1 ) ;
1854 END IF;
1855
1856 l_out_line_rec := l_line_rec;
1857
1858 Schedule_Parent_line( p_old_line_rec => l_old_line_rec,
1859 p_write_to_db => p_write_to_db,
1860 p_x_line_rec => l_out_line_rec,
1861 p_recursive_call => p_recursive_call,
1862 x_out_atp_tbl => l_out_atp_tbl,
1863 x_return_status => l_return_status);
1864
1865 IF l_debug_level > 0 THEN
1866 oe_debug_pub.add( 'AFTER CALLING SCHEDULE_PARENT_LINE: ' || L_RETURN_STATUS , 1 ) ;
1867 END IF;
1868
1869 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1870 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1871 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1872 RAISE FND_API.G_EXC_ERROR;
1873 END IF;
1874
1875 l_new_line_tbl(1) := l_out_line_rec;
1876 x_atp_tbl := l_out_atp_tbl;
1877 x_return_status := l_return_status;
1878
1879 END IF;
1880
1881 ELSE
1882 -- We are now scheduling line independently. So if the line belongs
1883 -- to a set, we should not let the set attributes change. So we will
1884 -- set the global variable G_SOURCE_AGAIN to 'N' and also set the
1885 -- the acceptable dates to be the same as the schedule_date (which
1886 -- means window acceptable.
1887
1888 IF (l_line_rec.ship_set_id is not null AND
1889 l_line_rec.ship_set_id <> FND_API.G_MISS_NUM) OR
1890 (l_line_rec.arrival_set_id is not null AND
1891 l_line_rec.arrival_set_id <> FND_API.G_MISS_NUM) THEN
1892
1893 G_SOURCE_AGAIN := 'N';
1894
1895 END IF;
1896
1897 IF l_debug_level > 0 THEN
1898 oe_debug_pub.add( 'CALLING PROCESS_REQUEST' , 1 ) ;
1899 END IF;
1900
1901 l_out_line_rec := l_line_rec;
1902
1903 Process_request(p_x_line_rec => l_out_line_rec,
1904 p_old_line_rec => l_old_line_rec,
1905 x_out_atp_tbl => l_out_atp_tbl ,
1906 x_return_status => l_return_status);
1907
1908 IF l_debug_level > 0 THEN
1909 oe_debug_pub.add( 'AFTER CALLING PROCESS_REQUEST: ' || L_RETURN_STATUS , 1 ) ;
1910 END IF;
1911
1912 -- Setting back g_source_again
1913
1914 G_SOURCE_AGAIN := 'Y';
1915
1916 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1917 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1918 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1919 RAISE FND_API.G_EXC_ERROR;
1920 END IF;
1921
1922 IF l_debug_level > 0 THEN
1923 oe_debug_pub.add( 'COUNT IS ' || L_OUT_ATP_TBL.COUNT , 1 ) ;
1924 END IF;
1925
1926 FOR P IN 1..l_out_atp_tbl.count LOOP
1927 IF l_debug_level > 0 THEN
1928 oe_debug_pub.add( 'ON HAND IS: ' || L_OUT_ATP_TBL ( P ) .ON_HAND_QTY , 1 ) ;
1929 END IF;
1930 END LOOP;
1931 l_new_line_tbl(1) := l_out_line_rec;
1932 -- Added Reserve statement to if to fix bug 1567688.
1933 -- Update order lines if the scheduling resulted in any attribute change.
1934 IF l_debug_level > 0 THEN
1935 oe_debug_pub.add( 'SCHEDULE STATUS OLD : '||L_OLD_LINE_REC.SCHEDULE_STATUS_CODE , 3 ) ;
1936 oe_debug_pub.add( 'SCHEDULE STATUS NEW : '||L_OUT_LINE_REC.SCHEDULE_STATUS_CODE , 3 ) ;
1937 END IF;
1938 IF NOT OE_GLOBALS.Equal(l_out_line_rec.schedule_action_code,
1939 OESCH_ACT_ATP_CHECK) AND
1940 NOT OE_GLOBALS.Equal(l_out_line_rec.schedule_action_code,
1941 OESCH_ACT_UNRESERVE) AND
1942 NOT (OE_GLOBALS.EQUAL(l_out_line_rec.schedule_action_code,
1943 OESCH_ACT_RESERVE) AND
1944 l_old_line_rec.schedule_status_code IS NOT NULL) AND
1945 g_update_flag = FND_API.G_TRUE
1946 THEN
1947
1948 IF l_debug_level > 0 THEN
1949 oe_debug_pub.add( 'CALLING UPDATE_LINE_RECORD ' , 1 ) ;
1950 END IF;
1951
1952 l_line_tbl(1) := l_line_rec;
1953
1954 Update_line_record(p_line_tbl => l_line_tbl,
1955 p_x_new_line_tbl => l_new_line_tbl,
1956 p_write_to_db => p_write_to_db,
1957 p_recursive_call => p_recursive_call,
1958 x_return_status => l_return_status);
1959
1960 IF l_debug_level > 0 THEN
1961 oe_debug_pub.add( 'AFTER CALLING UPDATE_LINE_RECORD :' || L_RETURN_STATUS , 1 ) ;
1962 END IF;
1963
1964 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1965 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1966 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1967 RAISE FND_API.G_EXC_ERROR;
1968 END IF;
1969
1970 -- Do not process delayed requests if this was a recursive
1971 -- call (e.g. from oe_line_util.pre_write_process)
1972 IF p_recursive_call = FND_API.G_TRUE THEN
1973 l_process_requests := FALSE;
1974 ELSE
1975 l_process_requests := TRUE;
1976 END IF;
1977
1978 OE_Order_PVT.Process_Requests_And_Notify
1979 ( p_process_requests => l_process_requests
1980 , p_notify => TRUE
1981 , p_line_tbl => l_new_line_tbl
1982 , p_old_line_tbl => l_line_tbl
1983 , x_return_status => l_return_status
1984 );
1985
1986 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1987 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1988 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1989 RAISE FND_API.G_EXC_ERROR;
1990 END IF;
1991
1992 -- If schedule date has change, we need to call PO callback function
1993 -- to indicate the change.
1994
1995 IF p_x_line_rec.operation = oe_globals.g_opr_update AND
1996 p_x_line_rec.source_document_type_id = 10 THEN
1997
1998 /* Changing schedule ship date to schedule arrival date for
1999 bug 2024748 */
2000 IF NOT OE_GLOBALS.EQUAL(l_out_line_rec.schedule_arrival_date,
2001 p_old_line_rec.schedule_arrival_date) THEN
2002
2003 IF l_debug_level > 0 THEN
2004 oe_debug_pub.add( 'PASSING SCHEDULE_ARRIVAL_DATE TO PO ' , 3 ) ;
2005 END IF;
2006 Update_PO(l_out_line_rec.schedule_arrival_date,
2007 l_out_line_rec.source_document_id,
2008 l_out_line_rec.source_document_line_id);
2009 END IF;
2010 END IF;
2011
2012 -- Commented this portion to fix bug 1883110.
2013 -- ReSet recursion mode.
2014 -- OE_GLOBALS.G_RECURSION_MODE := 'N';
2015
2016 END IF;
2017
2018 p_x_line_rec := l_new_line_tbl(1);
2019 x_atp_tbl := l_out_atp_tbl;
2020 x_return_status := l_return_status;
2021
2022 END IF;
2023
2024 <<end_schedule_line>>
2025
2026 p_x_line_rec := l_new_line_tbl(1);
2027 x_return_status := l_return_status;
2028
2029 -- Setting G_LINE_PART_OF_SET back to FALSE
2030
2031 G_LINE_PART_OF_SET := FALSE;
2032
2033 IF l_debug_level > 0 THEN
2034 oe_debug_pub.add( ' ' , 1 ) ;
2035 oe_debug_pub.add( 'PRINTING OUT NOCOPY RECORD: ' , 1 ) ;
2036 oe_debug_pub.add( ' P_X_LINE_REC LINE ID :'|| L_NEW_LINE_TBL ( 1 ) .LINE_ID , 1 ) ;
2037 oe_debug_pub.add( ' P_X_LINE_REC OPERATION :'|| L_NEW_LINE_TBL ( 1 ) .OPERATION , 1 ) ;
2038 oe_debug_pub.add( ' P_X_LINE_REC SCH STATUS :'|| L_NEW_LINE_TBL ( 1 ) .SCHEDULE_STATUS_CODE , 1 ) ;
2039 oe_debug_pub.add( ' P_X_LINE_REC RESERVED QTY : '|| L_NEW_LINE_TBL ( 1 ) .RESERVED_QUANTITY , 1 ) ;
2040 oe_debug_pub.add( 'AFTER PRINTING OUT NOCOPY RECORD: ' , 1 ) ;
2041 oe_debug_pub.add( ' ' , 1 ) ;
2042 oe_debug_pub.add( 'EXITING OE_ORDER_SCH_UTIL.SCHEDULE_LINE' , 1 ) ;
2043 END IF;
2044
2045
2046 EXCEPTION
2047
2048 WHEN FND_API.G_EXC_ERROR THEN
2049
2050 G_LINE_PART_OF_SET := FALSE;
2051 x_return_status := FND_API.G_RET_STS_ERROR;
2052
2053 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2054
2055 G_LINE_PART_OF_SET := FALSE;
2056 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2057
2058 WHEN OTHERS THEN
2059
2060 G_LINE_PART_OF_SET := FALSE;
2061 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2062
2063 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2064 THEN
2065 OE_MSG_PUB.Add_Exc_Msg
2066 ( G_PKG_NAME
2067 , 'Schedule_line'
2068 );
2069 END IF;
2070
2071 END Schedule_line;
2072
2073 /*---------------------------------------------------------------------
2074 Procedure Name : Update_line_record
2075 Description : This process is called after scheduling is performed
2076 on the line and the result needs to be verified and/or
2077 updated to the database.
2078 --------------------------------------------------------------------- */
2079
2080 Procedure Update_line_record
2081 ( p_line_tbl IN OE_ORDER_PUB.line_tbl_type
2082 , p_x_new_line_tbl IN OUT NOCOPY OE_ORDER_PUB.line_tbl_type
2083 , p_write_to_db IN VARCHAR2
2084 , p_recursive_call IN VARCHAR2
2085 , x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
2086 IS
2087 l_schedule_line_rec request_rec_type;
2088 l_line_rec OE_ORDER_PUB.line_rec_type;
2089 l_old_line_rec OE_ORDER_PUB.line_rec_type;
2090 l_sch_rec sch_rec_type;
2091 I NUMBER;
2092 l_return_status VARCHAR2(1);
2093 l_msg_count NUMBER;
2094 l_msg_data VARCHAR2(2000);
2095 l_control_rec OE_GLOBALS.control_rec_type;
2096 l_line_tbl OE_ORDER_PUB.line_tbl_type;
2097 l_process_requests BOOLEAN;
2098 is_set_recursion VARCHAR2(1) := 'Y';
2099 /*
2100 l_old_line_tbl OE_ORDER_PUB.line_tbl_type;
2101 l_header_out_rec OE_Order_PUB.Header_Rec_Type;
2102 l_header_rec OE_Order_PUB.Header_Rec_Type;
2103 l_line_out_tbl OE_Order_PUB.Line_Tbl_Type;
2104 l_header_adj_out_tbl OE_Order_PUB.Header_Adj_Tbl_Type;
2105 l_header_scredit_out_tbl OE_Order_PUB.Header_Scredit_Tbl_Type;
2106 l_line_adj_out_tbl OE_Order_PUB.Line_Adj_Tbl_Type;
2107 l_line_scredit_out_tbl OE_Order_PUB.Line_Scredit_Tbl_Type;
2108 l_lot_serial_out_tbl OE_Order_PUB.Lot_Serial_Tbl_Type;
2109 l_action_request_out_tbl OE_Order_PUB.Request_Tbl_Type;
2110 l_Header_Adj_Att_tbl OE_ORDER_PUB.Header_Adj_Att_Tbl_Type;
2111 l_Header_Adj_Assoc_tbl OE_ORDER_PUB.Header_Adj_Assoc_Tbl_Type;
2112 l_Header_price_Att_tbl OE_ORDER_PUB.Header_Price_Att_Tbl_Type;
2113 l_Line_Price_Att_tbl OE_ORDER_PUB.Line_Price_Att_Tbl_Type;
2114 l_Line_Adj_Att_tbl OE_ORDER_PUB.Line_Adj_Att_Tbl_Type;
2115 l_Line_Adj_Assoc_tbl OE_ORDER_PUB.Line_Adj_Assoc_Tbl_Type;
2116 */
2117 --
2118 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2119 --
2120 BEGIN
2121
2122 IF l_debug_level > 0 THEN
2123 oe_debug_pub.add( 'ENTERING UPDATE_LINE_RECORD' , 1 ) ;
2124 END IF;
2125 -- Set control flags.
2126
2127 l_control_rec.controlled_operation := TRUE;
2128 l_control_rec.change_attributes := TRUE;
2129
2130 l_control_rec.default_attributes := TRUE;
2131 l_control_rec.validate_entity := FALSE;
2132 l_control_rec.check_security := TRUE;
2133
2134 IF (p_write_to_db = FND_API.G_TRUE) THEN
2135 IF l_debug_level > 0 THEN
2136 oe_debug_pub.add( 'H1' , 1 ) ;
2137 END IF;
2138 l_control_rec.write_to_DB := TRUE;
2139 l_control_rec.validate_entity := TRUE;
2140 ELSE
2141 IF l_debug_level > 0 THEN
2142 oe_debug_pub.add( 'H2' , 1 ) ;
2143 END IF;
2144 l_control_rec.write_to_DB := FALSE;
2145 END IF;
2146
2147 l_control_rec.process := FALSE;
2148
2149 -- Instruct API to retain its caches
2150
2151 l_control_rec.clear_api_cache := FALSE;
2152 l_control_rec.clear_api_requests := FALSE;
2153
2154 OE_ORDER_SCH_UTIL.OESCH_PERFORM_SCHEDULING := 'N';
2155
2156 IF l_debug_level > 0 THEN
2157 oe_debug_pub.add( 'CALLING PROCESS ORDER' , 1 ) ;
2158 END IF;
2159
2160 FOR I IN 1..p_x_new_line_tbl.count LOOP
2161 IF l_debug_level > 0 THEN
2162 oe_debug_pub.add( 'I :' || I , 1 ) ;
2163 oe_debug_pub.add( 'OPERATION IS :' || P_X_NEW_LINE_TBL ( I ) .OPERATION , 1 ) ;
2164 END IF;
2165 /* Start Audit Trail */
2166 p_x_new_line_tbl(I).change_reason := 'SYSTEM';
2167 p_x_new_line_tbl(I).change_comments := 'Scheduling Action';
2168 /* End Audit Trail */
2169 END LOOP;
2170
2171 /*
2172 l_old_line_rec := p_line_tbl(1);
2173 l_line_rec := p_x_new_line_tbl(1);
2174 */
2175
2176 l_line_tbl := p_line_tbl;
2177
2178 -- Set global set recursive flag
2179 -- The global flag to supress the sets logic to fire in
2180 -- get set id api in lines
2181 /*
2182 IF p_recursive_call = FND_API.G_TRUE THEN
2183 oe_set_util.g_set_recursive_flag := TRUE;
2184 END IF;
2185 */
2186 IF NOT oe_set_util.g_set_recursive_flag THEN
2187 is_set_recursion := 'N';
2188 oe_set_util.g_set_recursive_flag := TRUE;
2189 END IF;
2190
2191 -- Call OE_Order_PVT.Process_order
2192
2193 OE_Order_PVT.Lines
2194 (p_validation_level => FND_API.G_VALID_LEVEL_NONE,
2195 p_control_rec => l_control_rec,
2196 p_x_line_tbl => p_x_new_line_tbl,
2197 p_x_old_line_tbl => l_line_tbl,
2198 x_return_status => l_return_status);
2199
2200 -- unset global set recursive flag
2201 -- The global flag to supress the sets logic to
2202 -- fire in get set id api in lines
2203
2204 IF is_set_recursion = 'N' THEN
2205 is_set_recursion := 'Y';
2206 oe_set_util.g_set_recursive_flag := FALSE;
2207 END IF;
2208
2209 /*
2210 IF p_recursive_call = FND_API.G_TRUE THEN
2211 oe_set_util.g_set_recursive_flag := FALSE;
2212 END IF;
2213 */
2214 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2215 IF l_debug_level > 0 THEN
2216 oe_debug_pub.add( 'RR: UNEXP ERRORED OUT' , 1 ) ;
2217 END IF;
2218 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2219 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
2220 IF l_debug_level > 0 THEN
2221 oe_debug_pub.add( 'RR: ERRORED OUT' , 1 ) ;
2222 END IF;
2223 RAISE FND_API.G_EXC_ERROR;
2224 END IF;
2225
2226 /** Commenting out this Process_request_and_notify call **/
2227 /** Since it is causing scheduling to to process requests too early **/
2228 /** Instead call process_requests_and_notify after this update_line_rec **/
2229 /** procedure is called. **/
2230 /*
2231 -- Do not process delayed requests if this was a recursive
2232 -- call (e.g. from oe_line_util.pre_write_process)
2233 IF p_recursive_call = FND_API.G_TRUE THEN
2234 l_process_requests := FALSE;
2235 ELSE
2236 l_process_requests := TRUE;
2237 END IF;
2238
2239 OE_Order_PVT.Process_Requests_And_Notify
2240 ( p_process_requests => l_process_requests
2241 , p_notify => TRUE
2242 , p_line_tbl => p_x_new_line_tbl
2243 , p_old_line_tbl => l_line_tbl
2244 , x_return_status => l_return_status
2245 );
2246 */
2247 /*
2248 OE_ORDER_PVT.Process_order
2249 ( p_api_version_number => 1.0
2250 , p_init_msg_list => FND_API.G_FALSE
2251 , p_validation_level => FND_API.G_VALID_LEVEL_NONE
2252 , x_return_status => l_return_status
2253 , x_msg_count => l_msg_count
2254 , x_msg_data => l_msg_data
2255 , p_x_header_rec => l_header_rec
2256 , p_control_rec => l_control_rec
2257 , p_x_line_tbl => p_x_new_line_tbl
2258 , p_old_line_tbl => p_line_tbl
2259 , p_x_Header_Adj_tbl => l_Header_Adj_out_tbl
2260 , p_x_Header_Price_Att_tbl => l_Header_Price_Att_tbl
2261 , p_x_Header_Adj_Att_tbl => l_Header_Adj_Att_tbl
2262 , p_x_Header_Adj_Assoc_tbl => l_Header_Adj_Assoc_tbl
2263 , p_x_Header_Scredit_tbl => l_Header_Scredit_out_tbl
2264 , p_x_Line_Adj_tbl => l_Line_Adj_out_tbl
2265 , p_x_Line_Price_Att_tbl => l_Line_Price_Att_tbl
2266 , p_x_Line_Adj_Att_tbl => l_Line_Adj_Att_tbl
2267 , p_x_Line_Adj_Assoc_tbl => l_Line_Adj_Assoc_tbl
2268 , p_x_Line_Scredit_tbl => l_Line_Scredit_out_tbl
2269 , p_x_action_request_tbl => l_Action_Request_out_tbl
2270 , p_x_Lot_Serial_Tbl => l_lot_serial_out_tbl
2271 );
2272 */
2273 IF l_debug_level > 0 THEN
2274 oe_debug_pub.add( 'SCH: AFTER CALLING PROCESS ORDER' , 1 ) ;
2275 oe_debug_pub.add( 'L_RETURN_STATUS IS ' || L_RETURN_STATUS , 1 ) ;
2276 END IF;
2277
2278 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2279 IF l_debug_level > 0 THEN
2280 oe_debug_pub.add( 'RR: UNEXP ERRORED OUT' , 1 ) ;
2281 END IF;
2282 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2283 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
2284 IF l_debug_level > 0 THEN
2285 oe_debug_pub.add( 'RR: ERRORED OUT' , 1 ) ;
2286 END IF;
2287 RAISE FND_API.G_EXC_ERROR;
2288 END IF;
2289
2290 OE_ORDER_SCH_UTIL.OESCH_PERFORM_SCHEDULING := 'Y';
2291
2292 x_return_status := l_return_status;
2293
2294 IF l_debug_level > 0 THEN
2295 oe_debug_pub.add( 'EXITING UPDATE LINE RECORD' , 1 ) ;
2296 END IF;
2297 EXCEPTION
2298
2299 -- resetting the flag to fix bug 2043973.
2300
2301 WHEN FND_API.G_EXC_ERROR THEN
2302
2303 OE_ORDER_SCH_UTIL.OESCH_PERFORM_SCHEDULING := 'Y';
2304 x_return_status := FND_API.G_RET_STS_ERROR;
2305
2306 IF is_set_recursion = 'N' THEN
2307 oe_set_util.g_set_recursive_flag := FALSE;
2308 END IF;
2309
2310 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2311
2312 OE_ORDER_SCH_UTIL.OESCH_PERFORM_SCHEDULING := 'Y';
2313 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2314
2315 IF is_set_recursion = 'N' THEN
2316 oe_set_util.g_set_recursive_flag := FALSE;
2317 END IF;
2318
2319 WHEN OTHERS THEN
2320
2321 OE_ORDER_SCH_UTIL.OESCH_PERFORM_SCHEDULING := 'Y';
2322 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2323
2324 IF is_set_recursion = 'N' THEN
2325 oe_set_util.g_set_recursive_flag := FALSE;
2326 END IF;
2327
2328 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2329 THEN
2330 OE_MSG_PUB.Add_Exc_Msg
2331 ( G_PKG_NAME
2332 , 'Schedule_line'
2333 );
2334 END IF;
2335 END Update_line_record;
2336
2337 /*---------------------------------------------------------------------
2338 Function Name : Need_Scheduling
2339 Description : This API will return to the calling process if scheduling
2340 needs to be performed on the line or not.
2341 --------------------------------------------------------------------- */
2342 FUNCTION Need_Scheduling(p_line_rec IN OE_ORDER_PUB.line_rec_type,
2343 p_old_line_rec IN OE_ORDER_PUB.line_rec_type)
2344 RETURN BOOLEAN
2345 IS
2346 l_schedule_action_code VARCHAR2(30);
2347 l_schedule_status_code VARCHAR2(30);
2348 l_order_date_type_code VARCHAR2(30):='';
2349 --
2350 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2351 --
2352 BEGIN
2353
2354 IF l_debug_level > 0 THEN
2355 oe_debug_pub.add( 'ENTERING NEED SCHEDULING' , 1 ) ;
2356 oe_debug_pub.add( 'SPLIT ACTION :' || P_LINE_REC.SPLIT_ACTION_CODE , 1 ) ;
2357 oe_debug_pub.add( 'S. LINE_ID :' || P_LINE_REC.SPLIT_FROM_LINE_ID , 1 ) ;
2358 END IF;
2359
2360 -- We do not schedule service lines. So return false for them.
2361 IF (p_line_rec.item_type_code = OE_GLOBALS.G_ITEM_SERVICE) THEN
2362 RETURN FALSE;
2363 END IF;
2364
2365 -- We do not schedule OTA lines. So return false for them.
2366 IF OE_OTA_UTIL.Is_OTA_Line(p_line_rec.order_quantity_uom)
2367 THEN
2368 RETURN FALSE;
2369 END IF;
2370
2371 -- If a config item is deleted, we do not need to call scheduling.
2372 -- Config Item can be deleted only through delink API. While delinking,
2373 -- CTO team takes care of updating the demand picture for the
2374 -- configuration.
2375
2376 IF (p_line_rec.item_type_code = OE_GLOBALS.G_ITEM_CONFIG AND
2377 p_line_rec.operation = OE_GLOBALS.G_OPR_DELETE)
2378 THEN
2379 RETURN FALSE;
2380 END IF;
2381
2382 -- If a config item is getting created, we do not need to call scheduling.
2383
2384 IF (p_line_rec.item_type_code = OE_GLOBALS.G_ITEM_CONFIG AND
2385 p_line_rec.operation = OE_GLOBALS.G_OPR_CREATE)
2386 THEN
2387 RETURN FALSE;
2388 END IF;
2389
2390 IF OE_OTA_UTIL.Is_OTA_Line(p_line_rec.order_quantity_uom)
2391 THEN
2392 RETURN FALSE;
2393 END IF;
2394
2395 -- Check to see if this line is a new line which has been created
2396 -- due to the split action. If yes, then do not schedule it, since we
2397 -- have already scheduled the line before.
2398
2399 IF (p_line_rec.split_from_line_id is not null) AND
2400 (p_line_rec.split_from_line_id <> FND_API.G_MISS_NUM) AND
2401 (p_line_rec.operation = OE_GLOBALS.G_OPR_CREATE)
2402 THEN
2403 IF l_debug_level > 0 THEN
2404 oe_debug_pub.add( 'THIS IS A NEW LINE CREATED THRU SPLIT' , 1 ) ;
2405 END IF;
2406 RETURN FALSE;
2407 END IF;
2408
2409
2410 -- Check to see if this line is the one which is getting split.
2411 -- If it is, then return FALSE, since this line is already rescheduled.
2412
2413 IF (p_line_rec.split_action_code = 'SPLIT') THEN
2414 IF (p_line_rec.schedule_status_code is not null) AND
2415 (p_line_rec.operation = OE_GLOBALS.G_OPR_UPDATE)
2416 THEN
2417 IF l_debug_level > 0 THEN
2418 oe_debug_pub.add( 'THIS LINE IS BEING SPLIT' , 1 ) ;
2419 END IF;
2420 RETURN FALSE;
2421 END IF;
2422 END IF;
2423
2424 l_schedule_action_code := p_line_rec.schedule_action_code;
2425 l_schedule_status_code := p_line_rec.schedule_status_code;
2426
2427 IF (l_schedule_action_code = FND_API.G_MISS_CHAR) THEN
2428 l_schedule_action_code := null;
2429 END IF;
2430
2431 -- If a scheduled line is deleted, the line should be unscheduled.
2432 IF (l_schedule_status_code is not null) AND
2433 (p_line_rec.operation = OE_GLOBALS.G_OPR_DELETE)
2434 THEN
2435 RETURN TRUE;
2436 END IF;
2437
2438 -- Currently, we will not perform any scheduling action
2439 -- for lines with source_type=EXTERNAL
2440
2441 IF (p_line_rec.source_type_code = OE_GLOBALS.G_SOURCE_EXTERNAL)
2442 AND (p_old_line_rec.schedule_status_code is null)
2443 THEN
2444 FND_MESSAGE.SET_NAME('ONT','OE_DS_COULD_NOT_SCH');
2445 FND_MESSAGE.SET_TOKEN('LINE',p_line_rec.line_number);
2446 RETURN FALSE;
2447 END IF;
2448
2449 If (l_schedule_status_code is null) AND
2450 ((l_schedule_action_code = OESCH_ACT_UNSCHEDULE) OR
2451 (l_schedule_action_code = OESCH_ACT_UNDEMAND) OR
2452 (l_schedule_action_code = OESCH_ACT_UNRESERVE))
2453 THEN
2454 FND_MESSAGE.SET_NAME('ONT','OE_SCH_NO_ACTION_DONE_NO_EXP');
2455 OE_MSG_PUB.Add;
2456 RETURN FALSE;
2457 END IF;
2458
2459 IF l_debug_level > 0 THEN
2460 oe_debug_pub.add( 'N6' , 1 ) ;
2461 END IF;
2462 IF (l_schedule_status_code = OESCH_STATUS_SCHEDULED AND
2463 l_schedule_action_code = OESCH_ACT_SCHEDULE AND
2464 p_line_rec.ordered_quantity = p_old_line_rec.reserved_quantity) THEN
2465
2466 -- We should not perform scheduling if the line is already scheduled
2467 RETURN FALSE;
2468 END IF;
2469
2470 IF l_debug_level > 0 THEN
2471 oe_debug_pub.add( 'N7: ' || L_SCHEDULE_ACTION_CODE , 1 ) ;
2472 END IF;
2473 IF (l_schedule_action_code is not null)
2474 THEN
2475 RETURN TRUE;
2476 END IF;
2477
2478 IF l_debug_level > 0 THEN
2479 oe_debug_pub.add( 'N8' , 1 ) ;
2480 END IF;
2481 IF NOT OE_GLOBALS.Equal(p_line_rec.schedule_ship_date,
2482 p_old_line_rec.schedule_ship_date)
2483 THEN
2484 RETURN TRUE;
2485 END IF;
2486
2487 IF NOT OE_GLOBALS.Equal(p_line_rec.schedule_arrival_date,
2488 p_old_line_rec.schedule_arrival_date)
2489 THEN
2490 RETURN TRUE;
2491 END IF;
2492
2493 IF l_debug_level > 0 THEN
2494 oe_debug_pub.add( 'NEW RESERVED QTY' || P_LINE_REC.RESERVED_QUANTITY ) ;
2495 oe_debug_pub.add( 'OLD RESERVED QTY' || P_OLD_LINE_REC.RESERVED_QUANTITY ) ;
2496 END IF;
2497
2498 IF NOT OE_GLOBALS.Equal(p_line_rec.reserved_quantity,
2499 p_old_line_rec.reserved_quantity)
2500 THEN
2501 RETURN TRUE;
2502 END IF;
2503
2504 IF ((l_schedule_status_code is NULL AND
2505 l_schedule_action_code is NULL) AND
2506 OESCH_AUTO_SCH_FLAG = 'N')
2507 THEN
2508 RETURN FALSE;
2509 END IF;
2510
2511
2512 IF l_debug_level > 0 THEN
2513 oe_debug_pub.add( 'RR:G5' , 1 ) ;
2514 END IF;
2515 IF (p_line_rec.operation = OE_GLOBALS.G_OPR_CREATE) THEN
2516 IF (OESCH_AUTO_SCH_FLAG = 'N')
2517 THEN
2518 RETURN FALSE;
2519 ELSE
2520 -- We are currently autoscheduling only standard lines not in any
2521 -- an model or option items.
2522
2523 IF p_line_rec.top_model_line_id is not null AND
2524 p_line_rec.top_model_line_id <> FND_API.G_MISS_NUM AND
2525 p_line_rec.item_type_code <> OE_GLOBALS.G_ITEM_STANDARD THEN
2526 RETURN FALSE;
2527 ELSE
2528 RETURN TRUE;
2529 END IF;
2530 END IF;
2531 END IF;
2532
2533 -- We should avoid calling scheduling when user changes values of the below
2534 -- attributes on the unscheduled lines. The below code is valid only for
2535 -- scheduled lines.
2536
2537 IF p_line_rec.schedule_status_code is NOT NULL THEN
2538 IF l_debug_level > 0 THEN
2539 oe_debug_pub.add( 'RR:G6' , 6 ) ;
2540 END IF;
2541
2542 IF NOT OE_GLOBALS.Equal(p_line_rec.ship_from_org_id,
2543 p_old_line_rec.ship_from_org_id)
2544 THEN
2545 RETURN TRUE;
2546 END IF;
2547
2548 IF NOT OE_GLOBALS.Equal(p_line_rec.subinventory,
2549 p_old_line_rec.subinventory)
2550 THEN
2551 IF l_debug_level > 0 THEN
2552 oe_debug_pub.add( 'SUBINVENTORY CHANGED , NEED RESCHEDULING' , 1 ) ;
2553 END IF;
2554 RETURN TRUE;
2555 END IF;
2556
2557 IF NOT OE_GLOBALS.Equal(p_line_rec.ordered_quantity,
2558 p_old_line_rec.ordered_quantity)
2559 THEN
2560 RETURN TRUE;
2561 END IF;
2562
2563 IF l_debug_level > 0 THEN
2564 oe_debug_pub.add( 'RR:G7' , 1 ) ;
2565 END IF;
2566 IF NOT OE_GLOBALS.Equal(p_line_rec.order_quantity_uom,
2567 p_old_line_rec.order_quantity_uom)
2568 THEN
2569 RETURN TRUE;
2570 END IF;
2571
2572 IF l_debug_level > 0 THEN
2573 oe_debug_pub.add( 'RR:G8' , 1 ) ;
2574 END IF;
2575 IF NOT OE_GLOBALS.Equal(p_line_rec.request_date,
2576 p_old_line_rec.request_date)
2577 THEN
2578 RETURN TRUE;
2579 END IF;
2580
2581 IF l_debug_level > 0 THEN
2582 oe_debug_pub.add( 'RR:G9' , 1 ) ;
2583 END IF;
2584 IF NOT OE_GLOBALS.Equal(p_line_rec.shipping_method_code,
2585 p_old_line_rec.shipping_method_code)
2586 THEN
2587 RETURN TRUE;
2588 END IF;
2589
2590 IF l_debug_level > 0 THEN
2591 oe_debug_pub.add( 'RR:G10' , 1 ) ;
2592 END IF;
2593 IF NOT OE_GLOBALS.Equal(p_line_rec.delivery_lead_time,
2594 p_old_line_rec.delivery_lead_time)
2595 THEN
2596
2597 BEGIN
2598 select order_date_type_code into l_order_date_type_code
2599 from oe_order_headers_all
2600 where header_id = p_line_rec.header_id;
2601
2602 IF l_order_date_type_code = 'ARRIVAL' THEN
2603 RETURN TRUE;
2604 END IF;
2605 EXCEPTION
2606 WHEN NO_DATA_FOUND THEN
2607 NULL;
2608 WHEN OTHERS THEN
2609 NULL;
2610 END;
2611
2612 END IF;
2613
2614 IF l_debug_level > 0 THEN
2615 oe_debug_pub.add( 'RR:G11' , 1 ) ;
2616 END IF;
2617 IF NOT OE_GLOBALS.Equal(p_line_rec.demand_class_code,
2618 p_old_line_rec.demand_class_code)
2619 THEN
2620 RETURN TRUE;
2621 END IF;
2622
2623 /*
2624 Forecasting attributes.
2625 */
2626
2627 IF l_debug_level > 0 THEN
2628 oe_debug_pub.add( 'RR:G12' , 1 ) ;
2629 END IF;
2630 IF NOT OE_GLOBALS.Equal(p_line_rec.ship_to_org_id,
2631 p_old_line_rec.ship_to_org_id)
2632 THEN
2633 RETURN TRUE;
2634 END IF;
2635
2636 IF l_debug_level > 0 THEN
2637 oe_debug_pub.add( 'RR:G13' , 1 ) ;
2638 END IF;
2639 IF NOT OE_GLOBALS.Equal(p_line_rec.sold_to_org_id,
2640 p_old_line_rec.sold_to_org_id)
2641 THEN
2642 RETURN TRUE;
2643 END IF;
2644
2645 IF l_debug_level > 0 THEN
2646 oe_debug_pub.add( 'RR:G14' , 1 ) ;
2647 END IF;
2648 IF NOT OE_GLOBALS.Equal(p_line_rec.inventory_item_id,
2649 p_old_line_rec.inventory_item_id)
2650 THEN
2651 RETURN TRUE;
2652 END IF;
2653
2654 -- Changing the source type on a scheduled line.
2655 -- We should unschedule the line
2656 IF p_line_rec.source_type_code = OE_GLOBALS.G_SOURCE_EXTERNAL AND
2657 NOT OE_GLOBALS.Equal(p_line_rec.source_type_code,
2658 p_old_line_rec.source_type_code)
2659 THEN
2660 IF l_debug_level > 0 THEN
2661 oe_debug_pub.add( 'SOURCE TYPE MADE EXTERNAL , UNSCHEDULE' , 4 ) ;
2662 END IF;
2663 RETURN TRUE;
2664 END IF;
2665
2666
2667 END IF; -- Check for schedule_status_code.
2668
2669 RETURN FALSE;
2670 END Need_Scheduling;
2671
2672 /*---------------------------------------------------------------------
2673 Procedure Name : Get_Scheduling_Level
2674 Description : This function gets back the scheduling level
2675 on the order type. The scheduling levels could be
2676 ONE: Perform on ATP
2677 TWO: Perform ATP and Scheduling. (no reservations)
2678 THREE: Perform ATP,Scheduling and RESERVATIONS.
2679 08/25 : changes are being made for bug 1385153 to get the
2680 scheduling level based on line type instead of order type.
2681 --------------------------------------------------------------------- */
2682
2683 FUNCTION Get_Scheduling_Level( p_header_id IN NUMBER,
2684 p_line_type_id IN NUMBER)
2685 RETURN VARCHAR2
2686 IS
2687 l_scheduling_level_code VARCHAR2(30) := null;
2688 l_line_type VARCHAR2(80) := null;
2689 l_order_type VARCHAR2(80) := null;
2690 --
2691 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2692 --
2693 BEGIN
2694
2695 IF l_debug_level > 0 THEN
2696 oe_debug_pub.add( 'ENTERING GET_SCHEDULING_LEVEL: ' || P_HEADER_ID||'/'||P_LINE_TYPE_ID , 1 ) ;
2697 END IF;
2698
2699 IF p_line_type_id = sch_cached_line_type_id
2700 THEN
2701
2702 sch_cached_sch_level_code := sch_cached_sch_level_code_line;
2703 RETURN sch_cached_sch_level_code;
2704
2705 END IF;
2706
2707 SELECT name, scheduling_level_code
2708 INTO l_line_type,l_scheduling_level_code
2709 FROM oe_transaction_types
2710 WHERE transaction_type_id = p_line_type_id AND
2711 transaction_type_code = 'LINE';
2712
2713 IF l_scheduling_level_code IS NOT NULL THEN
2714
2715 sch_cached_line_type_id := p_line_type_id;
2716 sch_cached_sch_level_code := l_scheduling_level_code;
2717 sch_cached_sch_level_code_line := l_scheduling_level_code;
2718 sch_cached_line_type := l_line_type;
2719 RETURN l_scheduling_level_code;
2720
2721 END IF;
2722
2723 IF p_header_id = sch_cached_header_id
2724 THEN
2725
2726 sch_cached_sch_level_code := sch_cached_sch_level_code_head;
2727 RETURN sch_cached_sch_level_code;
2728
2729 END IF;
2730
2731 SELECT name, scheduling_level_code
2732 INTO l_order_type,l_scheduling_level_code
2733 FROM oe_order_types_v ot, oe_order_headers h
2734 WHERE h.header_id = p_header_id AND
2735 h.order_type_id = ot.order_type_id;
2736
2737 sch_cached_header_id := p_header_id;
2738 sch_cached_sch_level_code := l_scheduling_level_code;
2739 sch_cached_sch_level_code_head := l_scheduling_level_code;
2740 sch_cached_order_type := l_order_type;
2741
2742 IF l_debug_level > 0 THEN
2743 oe_debug_pub.add( 'EXITING GET_SCHEDULING_LEVEL' , 1 ) ;
2744 END IF;
2745 RETURN l_scheduling_level_code;
2746
2747 EXCEPTION
2748 WHEN NO_DATA_FOUND THEN
2749 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2750
2751 END Get_Scheduling_Level;
2752
2753 /*---------------------------------------------------------------------
2754 Procedure Name : Validate_Line
2755 Description : Validates a line before scheduling.
2756 It will make sure the required attributes are the
2757 there on the line.
2758 Only standard lines can be scheduled.Service lines
2759 return lines cannot be scheduled.
2760 IF the profile OE:Schedule Line on Hold is set to 'Y'
2761 we will perform scheduling on lines on hold. If it is
2762 set to 'N', we will not perform scheduling.
2763 --------------------------------------------------------------------- */
2764 Procedure Validate_Line(p_line_rec IN OE_ORDER_PUB.Line_Rec_Type,
2765 p_old_line_rec IN OE_ORDER_PUB.Line_Rec_Type,
2766 x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
2767 IS
2768 l_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
2769 l_msg_count NUMBER;
2770 l_msg_data VARCHAR2(2000);
2771 l_result Varchar2(30);
2772 l_scheduling_level_code VARCHAR2(30) := NULL;
2773 l_out_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
2774 l_type_code VARCHAR2(30);
2775 l_org_id NUMBER;
2776 l_bill_seq_id NUMBER;
2777 l_make_buy NUMBER;
2778 --
2779 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2780 --
2781 BEGIN
2782
2783 IF l_debug_level > 0 THEN
2784 oe_debug_pub.add( '..ENTERING OE_ORDER_SCH_UTIL.VALIDATE_LINE' , 6 ) ;
2785 END IF;
2786
2787 -- If the quantity on the line is missing or null and if
2788 -- the user is trying to performing scheduling, it is an error
2789
2790 IF ((p_old_line_rec.ordered_quantity is null OR
2791 p_old_line_rec.ordered_quantity = FND_API.G_MISS_NUM) AND
2792 (p_line_rec.ordered_quantity is null OR
2793 p_line_rec.ordered_quantity = FND_API.G_MISS_NUM)) THEN
2794
2795 FND_MESSAGE.SET_NAME('ONT','OE_SCH_MISSING_QUANTITY');
2796 OE_MSG_PUB.Add;
2797
2798 l_return_status := FND_API.G_RET_STS_ERROR;
2799 END IF;
2800
2801 -- If the quantity on the line is zero(which is different from
2802 -- missing) and if the user is trying to performing scheduling,
2803 -- it is an error
2804
2805 IF (((p_old_line_rec.ordered_quantity is null OR
2806 p_old_line_rec.ordered_quantity = FND_API.G_MISS_NUM OR
2807 p_old_line_rec.ordered_quantity = 0) AND
2808 p_line_rec.ordered_quantity = 0) AND
2809 (nvl(p_line_rec.cancelled_flag,'N') = 'N')) THEN
2810
2811 IF p_line_rec.schedule_action_code is not null THEN
2812
2813 FND_MESSAGE.SET_NAME('ONT','OE_SCH_ZERO_QTY');
2814 OE_MSG_PUB.Add;
2815
2816 IF l_debug_level > 0 THEN
2817 oe_debug_pub.add( 'E2' , 1 ) ;
2818 END IF;
2819 l_return_status := FND_API.G_RET_STS_ERROR;
2820 END IF;
2821
2822 END IF;
2823
2824 -- If the line is cancelled, scheduling is not allowed.
2825
2826 IF (p_line_rec.cancelled_flag = 'Y') THEN
2827
2828 IF p_line_rec.schedule_action_code is not null THEN
2829
2830 -- The line is cancelled. Cannot perform scheduling
2831 -- on it.
2832
2833 FND_MESSAGE.SET_NAME('ONT','OE_SCH_LINE_FULLY_CANCELLED');
2834 OE_MSG_PUB.Add;
2835
2836 IF l_debug_level > 0 THEN
2837 oe_debug_pub.add( 'E3' , 1 ) ;
2838 END IF;
2839 l_return_status := FND_API.G_RET_STS_ERROR;
2840
2841 END IF;
2842 END IF;
2843
2844 -- If the line is shipped, scheduling is not allowed.
2845
2846 IF (p_line_rec.shipped_quantity is not null) AND
2847 (p_line_rec.shipped_quantity <> FND_API.G_MISS_NUM) THEN
2848
2849 /* modified he following if condition for fixing the bug 2763764 */
2850
2851 IF p_line_rec.schedule_action_code is not null OR
2852 (p_line_rec.reserved_quantity is not null AND
2853 p_line_rec.reserved_quantity <> FND_API.G_MISS_NUM) THEN
2854
2855
2856 -- The line is cancelled. Cannot perform scheduling
2857 -- on it.
2858
2859 FND_MESSAGE.SET_NAME('ONT','OE_SCH_LINE_SHIPPED');
2860 OE_MSG_PUB.Add;
2861
2862 IF l_debug_level > 0 THEN
2863 oe_debug_pub.add( 'OE_SCH_LINE_SHIPPED' , 1 ) ;
2864 END IF;
2865 l_return_status := FND_API.G_RET_STS_ERROR;
2866
2867 END IF;
2868 END IF;
2869
2870 -- Check to see if the reserved quantity is changed and is more
2871 -- than the ordered quantity. This should not be allowed.
2872
2873 IF NOT OE_GLOBALS.Equal(p_old_line_rec.reserved_quantity,
2874 p_line_rec.reserved_quantity) THEN
2875
2876 -- Bug 2314463 Start
2877 IF p_line_rec.item_type_code = OE_GLOBALS.G_ITEM_CONFIG THEN
2878 IF l_debug_level > 0 THEN
2879 oe_debug_pub.add( 'INSIDE CONFIG ITEM...RESERVED QTY CHANGED' , 1 ) ;
2880 END IF;
2881 FND_MESSAGE.SET_NAME('ONT','OE_INVALID_ACTION');
2882 FND_MESSAGE.SET_TOKEN('ACTION',OE_Id_To_Value.Inventory_Item(p_line_rec.inventory_item_id));
2883 OE_MSG_PUB.Add;
2884 l_return_status := FND_API.G_RET_STS_ERROR;
2885 END IF;
2886 -- Bug 2314463 End
2887
2888 -- Reserved Quantity has changed
2889 IF (p_line_rec.ordered_quantity < p_line_rec.reserved_quantity)
2890 THEN
2891
2892 FND_MESSAGE.SET_NAME('ONT','OE_SCH_RES_MORE_ORD_QTY');
2893 OE_MSG_PUB.Add;
2894
2895 IF l_debug_level > 0 THEN
2896 oe_debug_pub.add( 'E4' , 1 ) ;
2897 END IF;
2898 l_return_status := FND_API.G_RET_STS_ERROR;
2899 END IF;
2900
2901 -- Reserved2 Quantity has changed -- INVCONV
2902 IF (p_line_rec.ordered_quantity2 < p_line_rec.reserved_quantity2)
2903 THEN
2904
2905 FND_MESSAGE.SET_NAME('ONT','OE_SCH_RES_MORE_ORD_QTY');
2906 OE_MSG_PUB.Add;
2907
2908 IF l_debug_level > 0 THEN
2909 oe_debug_pub.add( 'E4a' , 1 ) ;
2910 END IF;
2911 l_return_status := FND_API.G_RET_STS_ERROR;
2912 END IF;
2913
2914
2915 -- after changing reserved qty, trying to unschedule or unreserve
2916 -- dose not make sense.
2917 IF (p_line_rec.schedule_action_code = OESCH_ACT_UNSCHEDULE OR
2918 p_line_rec.schedule_action_code = OESCH_ACT_UNRESERVE) AND
2919 (p_line_rec.reserved_quantity is not null) THEN
2920
2921 FND_MESSAGE.SET_NAME('ONT','OE_SCH_RES_QTY_CHG_NOT_ALLOWED');
2922 OE_MSG_PUB.Add;
2923 l_return_status := FND_API.G_RET_STS_ERROR;
2924 IF l_debug_level > 0 THEN
2925 oe_debug_pub.add( 'E5' , 1 ) ;
2926 END IF;
2927 END IF;
2928 END IF;
2929
2930 -- Check to see if the ordered quantity and reserved quantity
2931 -- both have changed and if the ordered quantity is less than
2932 -- the reserved quantity. This should not be allowed.
2933
2934 IF NOT OE_GLOBALS.Equal(p_old_line_rec.ordered_quantity,
2935 p_line_rec.ordered_quantity)
2936 THEN
2937 -- Ordered Quantity has changed
2938 IF NOT OE_GLOBALS.Equal(p_old_line_rec.reserved_quantity,
2939 p_line_rec.reserved_quantity)
2940 THEN
2941 IF (p_line_rec.ordered_quantity < p_line_rec.reserved_quantity)
2942 THEN
2943
2944 FND_MESSAGE.SET_NAME('ONT','OE_SCH_RES_MORE_ORD_QTY');
2945 OE_MSG_PUB.Add;
2946
2947 l_return_status := FND_API.G_RET_STS_ERROR;
2948 IF l_debug_level > 0 THEN
2949 oe_debug_pub.add( 'E6' , 1 ) ;
2950 END IF;
2951 END IF;
2952 END IF;
2953 END IF;
2954
2955 -- INVCONV
2956 -- Check to see if the ordered quantity2 and reserved quantity2
2957 -- both have changed and if the ordered quantity2 is less than
2958 -- the reserved quantity2. This should not be allowed.
2959
2960 IF NOT OE_GLOBALS.Equal(p_old_line_rec.ordered_quantity2,
2961 p_line_rec.ordered_quantity2)
2962 THEN
2963 -- Ordered Quantity has changed
2964 IF NOT OE_GLOBALS.Equal(p_old_line_rec.reserved_quantity2,
2965 p_line_rec.reserved_quantity2)
2966 THEN
2967 IF (p_line_rec.ordered_quantity2 < p_line_rec.reserved_quantity2)
2968 THEN
2969
2970 FND_MESSAGE.SET_NAME('ONT','OE_SCH_RES_MORE_ORD_QTY');
2971 OE_MSG_PUB.Add;
2972
2973 l_return_status := FND_API.G_RET_STS_ERROR;
2974 IF l_debug_level > 0 THEN
2975 oe_debug_pub.add( 'E6a' , 1 ) ;
2976 END IF;
2977 END IF;
2978 END IF;
2979 END IF;
2980
2981
2982 -- If the order quantity uom on the line is missing or null
2983 -- and if the user is trying to performing scheduling,
2984 -- it is an error
2985
2986 IF (p_line_rec.order_quantity_uom is null OR
2987 p_line_rec.order_quantity_uom = FND_API.G_MISS_CHAR) THEN
2988
2989 FND_MESSAGE.SET_NAME('ONT','OE_SCH_MISSING_UOM');
2990 OE_MSG_PUB.Add;
2991
2992 l_return_status := FND_API.G_RET_STS_ERROR;
2993 IF l_debug_level > 0 THEN
2994 oe_debug_pub.add( 'E7' , 1 ) ;
2995 END IF;
2996 END IF;
2997
2998 -- If the item on the line is missing or null and if the user
2999 -- is trying to performing scheduling, it is an error
3000
3001 IF l_debug_level > 0 THEN
3002 oe_debug_pub.add( 'CHECKING THE ITEM....' , 1 ) ;
3003 END IF;
3004
3005 IF (p_line_rec.inventory_item_id is null OR
3006 p_line_rec.inventory_item_id = FND_API.G_MISS_NUM) THEN
3007
3008 FND_MESSAGE.SET_NAME('ONT','OE_SCH_MISSING_ITEM');
3009 OE_MSG_PUB.Add;
3010
3011 l_return_status := FND_API.G_RET_STS_ERROR;
3012 END IF;
3013
3014 -- If the request_date on the line is missing or null and
3015 -- if the user is trying to performing scheduling,
3016 -- it is an error
3017
3018 IF l_debug_level > 0 THEN
3019 oe_debug_pub.add( 'CHECKING THE REQUEST DATE....' , 1 ) ;
3020 END IF;
3021 IF (p_line_rec.request_date is null OR
3022 p_line_rec.request_date = FND_API.G_MISS_DATE) THEN
3023
3024 FND_MESSAGE.SET_NAME('ONT','OE_SCH_MISSING_REQUEST_DATE');
3025 OE_MSG_PUB.Add;
3026 l_return_status := FND_API.G_RET_STS_ERROR;
3027 END IF;
3028
3029 -- If the line belongs to a set, you cannot unschedule the line
3030 IF l_debug_level > 0 THEN
3031 oe_debug_pub.add( 'CHECKING FOR SET VALIDATIONS....' , 1 ) ;
3032 END IF;
3033 IF ((p_line_rec.ship_set_id is not null AND
3034 p_line_rec.ship_set_id <> FND_API.G_MISS_NUM) AND
3035 (p_line_rec.schedule_action_code = OESCH_ACT_UNDEMAND OR
3036 p_line_rec.schedule_action_code = OESCH_ACT_UNSCHEDULE))
3037 THEN
3038
3039 FND_MESSAGE.SET_NAME('ONT','OE_SCH_OE_ORDER_FAILED');
3040 OE_MSG_PUB.Add;
3041
3042 l_return_status := FND_API.G_RET_STS_ERROR;
3043 END IF;
3044
3045 IF l_debug_level > 0 THEN
3046 oe_debug_pub.add( 'CHECKING FOR HOLDS....' , 1 ) ;
3047 END IF;
3048 IF FND_PROFILE.VALUE('ONT_SCHEDULE_LINE_ON_HOLD') = 'N' AND
3049 (p_line_rec.schedule_action_code = OESCH_ACT_SCHEDULE OR
3050 p_line_rec.schedule_action_code = OESCH_ACT_RESERVE OR
3051 (p_line_rec.schedule_status_code is not null AND
3052 Schedule_Attribute_Changed(p_line_rec => p_line_rec,
3053 p_old_line_rec => p_old_line_rec)) OR
3054 (p_line_rec.schedule_status_code is not null AND
3055 p_line_rec.ordered_quantity > p_old_line_rec.ordered_quantity))
3056
3057 /* (p_line_rec.operation = OE_GLOBALS.G_OPR_CREATE AND
3058 OESCH_AUTO_SCH_FLAG = 'Y' AND
3059 p_line_rec.item_type_code = OE_GLOBALS.G_ITEM_STANDARD) OR
3060 (p_line_rec.schedule_status_code is null AND
3061 (p_line_rec.schedule_ship_date is NOT NULL OR
3062 p_line_rec.schedule_arrival_date is NOT NULL)))
3063 */
3064 THEN
3065 -- Since the profile is set to NO, we should not schedule
3066 -- the line if the line is on hold.
3067
3068 IF l_debug_level > 0 THEN
3069 oe_debug_pub.add( 'CALLING CHECK HOLDS' , 1 ) ;
3070 END IF;
3071
3072 OE_Holds_PUB.Check_Holds
3073 ( p_api_version => 1.0
3074 , p_init_msg_list => FND_API.G_FALSE
3075 , p_commit => FND_API.G_FALSE
3076 , p_validation_level => FND_API.G_VALID_LEVEL_FULL
3077 , x_return_status => l_out_return_status
3078 , x_msg_count => l_msg_count
3079 , x_msg_data => l_msg_data
3080 , p_line_id => p_line_rec.line_id
3081 , p_hold_id => NULL
3082 , p_entity_code => NULL
3083 , p_entity_id => NULL
3084 , x_result_out => l_result
3085 );
3086
3087 IF l_debug_level > 0 THEN
3088 oe_debug_pub.add( 'AFTER CALLING CHECK HOLDS: ' || L_OUT_RETURN_STATUS , 1 ) ;
3089 END IF;
3090
3091 IF (l_out_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
3092 IF l_out_return_status = FND_API.G_RET_STS_ERROR THEN
3093 RAISE FND_API.G_EXC_ERROR;
3094 ELSE
3095 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3096 END IF;
3097 END IF;
3098
3099 IF (l_result = FND_API.G_TRUE) THEN
3100 FND_MESSAGE.SET_NAME('ONT','OE_SCH_LINE_ON_HOLD');
3101 OE_MSG_PUB.Add;
3102 l_return_status := FND_API.G_RET_STS_ERROR;
3103 END IF;
3104
3105 END IF;
3106
3107 -- Check to see what scheduling level is allowed to be performed
3108 -- on this line. If the action requested is not allowed for the
3109 -- scheduling action, error out.
3110
3111 IF l_debug_level > 0 THEN
3112 oe_debug_pub.add( 'CHECKING SCHEDULING LEVEL...' , 1 ) ;
3113 END IF;
3114 l_scheduling_level_code := Get_Scheduling_Level(p_line_rec.header_id,
3115 p_line_rec.line_type_id);
3116
3117 IF l_debug_level > 0 THEN
3118 oe_debug_pub.add( 'L_SCHEDULING_LEVEL_CODE : ' || L_SCHEDULING_LEVEL_CODE , 1 ) ;
3119 END IF;
3120
3121 IF l_scheduling_level_code is not null THEN
3122 IF l_scheduling_level_code = SCH_LEVEL_ONE THEN
3123 IF p_line_rec.schedule_action_code = OESCH_ACT_SCHEDULE OR
3124 p_line_rec.schedule_action_code = OESCH_ACT_RESERVE OR
3125 (p_line_rec.schedule_status_code is null AND
3126 (p_line_rec.schedule_ship_date is NOT NULL OR
3127 p_line_rec.schedule_arrival_date is NOT NULL))
3128 THEN
3129
3130 FND_MESSAGE.SET_NAME('ONT','OE_SCH_ACTION_NOT_ALLOWED');
3131 FND_MESSAGE.SET_TOKEN('ACTION',
3132 nvl(p_line_rec.schedule_action_code,OESCH_ACT_SCHEDULE));
3133 FND_MESSAGE.SET_TOKEN('ORDER_TYPE',
3134 nvl(sch_cached_line_type,sch_cached_order_type));
3135 OE_MSG_PUB.Add;
3136 l_return_status := FND_API.G_RET_STS_ERROR;
3137 END IF;
3138 ELSIF l_scheduling_level_code = SCH_LEVEL_TWO OR
3139 p_line_rec.reserved_quantity > 0 THEN
3140 IF p_line_rec.schedule_action_code = OESCH_ACT_RESERVE THEN
3141 FND_MESSAGE.SET_NAME('ONT','OE_SCH_ACTION_NOT_ALLOWED');
3142 FND_MESSAGE.SET_TOKEN('ACTION',
3143 nvl(p_line_rec.schedule_action_code,OESCH_ACT_RESERVE));
3144 FND_MESSAGE.SET_TOKEN('ORDER_TYPE',
3145 nvl(sch_cached_line_type,sch_cached_order_type));
3146 OE_MSG_PUB.Add;
3147 l_return_status := FND_API.G_RET_STS_ERROR;
3148 END IF;
3149 END IF;
3150 END IF;
3151
3152 -- Added this part of validation to fix bug 2051855
3153 IF p_line_rec.ato_line_id = p_line_rec.line_id
3154 AND p_line_rec.item_type_code in ('STANDARD','OPTION')
3155 AND fnd_profile.value('INV_CTP') = '5' THEN
3156
3157 l_org_id := OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
3158
3159 -- Added code to fix bug 2156268
3160 BEGIN
3161
3162 SELECT planning_make_buy_code
3163 INTO l_make_buy
3164 FROM mtl_system_items
3165 WHERE inventory_item_id = p_line_rec.inventory_item_id
3166 AND ORGANIZATION_ID = nvl(p_line_rec.ship_from_org_id,
3167 l_org_id);
3168
3169 EXCEPTION
3170 WHEN NO_DATA_FOUND THEN
3171 l_make_buy := 1;
3172 END;
3173
3174 IF l_debug_level > 0 THEN
3175 oe_debug_pub.add( 'L_MAKE_BUY' || L_MAKE_BUY , 2 ) ;
3176 END IF;
3177
3178 IF nvl(l_make_buy,1) <> 2 THEN
3179 BEGIN
3180
3181 SELECT BILL_SEQUENCE_ID
3182 INTO l_bill_seq_id
3183 FROM BOM_BILL_OF_MATERIALS
3184 WHERE ORGANIZATION_ID = nvl(p_line_rec.ship_from_org_id,l_org_id)
3185 AND ASSEMBLY_ITEM_ID = p_line_rec.inventory_item_id
3186 AND ALTERNATE_BOM_DESIGNATOR IS NULL;
3187
3188 EXCEPTION
3189 WHEN NO_DATA_FOUND THEN
3190 IF l_debug_level > 0 THEN
3191 oe_debug_pub.add( 'NO BILL IS DEFINED' , 2 ) ;
3192 END IF;
3193 FND_MESSAGE.SET_NAME('ONT','OE_BOM_NO_BILL_IN_VAL_ORG');
3194 FND_MESSAGE.SET_TOKEN('ITEM',nvl(p_line_rec.ordered_item,p_line_rec.inventory_item_id));
3195 FND_MESSAGE.SET_TOKEN('ORG',l_org_id);
3196 OE_MSG_PUB.Add;
3197 l_return_status := FND_API.G_RET_STS_ERROR;
3198
3199 WHEN OTHERS THEN
3200 Null;
3201 END;
3202 END IF;
3203 END IF;
3204
3205 x_return_status := l_return_status;
3206
3207 IF l_debug_level > 0 THEN
3208 oe_debug_pub.add( '..EXITING OE_ORDER_SCH_UTIL.VALIDATE_LINE WITH ' || L_RETURN_STATUS , 1 ) ;
3209 END IF;
3210 END Validate_Line;
3211
3212 /*---------------------------------------------------------------------
3213 Procedure Name : Scheduling_Activity
3214 Description : ** CURRENT NOT USED **
3215 --------------------------------------------------------------------- */
3216 FUNCTION Scheduling_Activity(p_line_rec IN OE_ORDER_PUB.line_rec_type)
3217 RETURN BOOLEAN
3218 IS
3219 --
3220 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3221 --
3222 BEGIN
3223 RETURN TRUE;
3224 END Scheduling_Activity;
3225
3226 /*---------------------------------------------------------------------
3227 Procedure Name : Check_Item_Attributes
3228 Description : ** CURRENT NOT USED **
3229 --------------------------------------------------------------------- */
3230 Procedure Check_Item_Attribute(p_line_rec IN OE_ORDER_PUB.line_rec_type)
3231 IS
3232 l_item_rec OE_ORDER_CACHE.item_rec_type;
3233 --
3234 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3235 --
3236 BEGIN
3237
3238 IF l_debug_level > 0 THEN
3239 oe_debug_pub.add( '..ENTERING CHECK_ITEM_ATTRIBUTE' , 1 ) ;
3240 END IF;
3241
3242 /*
3243 l_item_rec := Oe_Order_Cache.Load_Item
3244 (p_key1 => p_line_rec.inventory_item_id,
3245 p_key2 => p_line_rec.ship_from_org_id);
3246
3247 oe_debug_pub.add('..Exiting Check_Item_Attribute',1);
3248 */
3249
3250 END Check_Item_Attribute;
3251
3252 /*---------------------------------------------------------------------
3253 Procedure Name : Query_Qty_Tree
3254 Description : Queries the On-Hand and Available to Reserve
3255 quantites by calling INV's
3256 inv_quantity_tree_pub.query_quantities.
3257 The quantities are given at the highest level (Item, Org
3258 combination).
3259 --------------------------------------------------------------------- */
3260 Procedure Query_Qty_Tree(p_org_id IN NUMBER,
3261 p_item_id IN NUMBER,
3262 p_line_id IN NUMBER DEFAULT NULL,
3263 p_sch_date IN DATE DEFAULT NULL,
3264 x_on_hand_qty OUT NOCOPY /* file.sql.39 change */ NUMBER,
3265 x_avail_to_reserve OUT NOCOPY /* file.sql.39 change */ NUMBER,
3266 x_on_hand_qty2 OUT NOCOPY NUMBER, -- INVCONV
3267 x_avail_to_reserve2 OUT NOCOPY NUMBER -- INVCONV
3268 )
3269 IS
3270 l_return_status VARCHAR2(1);
3271 l_msg_count NUMBER;
3272 l_msg_data VARCHAR2(2000);
3273 l_qoh NUMBER;
3274 l_rqoh NUMBER;
3275 l_qr NUMBER;
3276 l_qs NUMBER;
3277 l_att NUMBER;
3278 l_atr NUMBER;
3279 l_msg_index NUMBER;
3280 l_lot_control_flag BOOLEAN;
3281 l_lot_control_code NUMBER;
3282 l_org_id NUMBER;
3283
3284 -- added by fabdi 03/May/2001 -- INVCONV NO LONGER NEEDED
3285 l_process_flag VARCHAR2(1) := FND_API.G_FALSE;
3286 -- l_ic_item_mst_rec GMI_RESERVATION_UTIL.ic_item_mst_rec; OPM INVCONV 4742691
3287 -- end fabdi
3288
3289 l_sqoh NUMBER; -- INVCONV
3290 l_srqoh NUMBER; -- INVCONV
3291 l_sqr NUMBER; -- INVCONV
3292 l_sqs NUMBER; -- INVCONV
3293 l_satt NUMBER; -- INVCONV
3294 l_satr NUMBER; -- INVCONV
3295
3296
3297
3298 --
3299 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3300 --
3301 BEGIN
3302
3303 IF l_debug_level > 0 THEN
3304 oe_debug_pub.add( 'ENTERING QUERY_QTY_TREE ' , 1 ) ;
3305 oe_debug_pub.add( 'ORG IS : ' || P_ORG_ID , 1 ) ;
3306 oe_debug_pub.add( 'ITEM IS : ' || P_ITEM_ID , 1 ) ;
3307 END IF;
3308 /* -- added by fabdi 03/May/2001
3309 IF NOT INV_GMI_RSV_BRANCH.Process_Branch(p_organization_id => p_org_id)
3310 THEN
3311 l_process_flag := FND_API.G_FALSE;
3312 ELSE
3313 l_process_flag := FND_API.G_TRUE;
3314 END IF;
3315
3316 IF l_process_flag = FND_API.G_TRUE
3317 THEN
3318
3319 GMI_RESERVATION_UTIL.Get_OPM_item_from_Apps
3320 ( p_organization_id => p_org_id
3321 , p_inventory_item_id => p_item_id
3322 , x_ic_item_mst_rec => l_ic_item_mst_rec
3323 , x_return_status => l_return_status
3324 , x_msg_count => l_msg_count
3325 , x_msg_data => l_msg_data);
3326
3327 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS)
3328 THEN
3329 FND_MESSAGE.SET_NAME('GMI','GMI_ERROR');
3330 FND_MESSAGE.SET_TOKEN('BY_PROC','GMI_Reservation_Util.Get_OPM_item_from_Apps');
3331 FND_MESSAGE.SET_TOKEN('WHERE','OE_ORDER_SCH_UTIL');
3332 RAISE FND_API.G_EXC_ERROR;
3333 END IF;
3334
3335 get_process_query_quantities ( p_org_id => p_org_id,
3336 p_item_id => l_ic_item_mst_rec.item_id,
3337 p_line_id => p_line_id,
3338 x_on_hand_qty => l_qoh,
3339 x_avail_to_reserve => l_atr
3340 );
3341 -- end fabdi
3342 ELSE */
3343
3344 BEGIN
3345 -- Added code to fix bug 2111470
3346 IF p_org_id is null THEN
3347 l_org_id := OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
3348 END IF;
3349
3350 SELECT msi.lot_control_code
3351 INTO l_lot_control_code
3352 FROM mtl_system_items msi
3353 WHERE msi.inventory_item_id = p_item_id
3354 AND msi.organization_id = nvl(p_org_id,l_org_id);
3355
3356 IF l_lot_control_code = 2 THEN
3357 l_lot_control_flag := TRUE;
3358 ELSE
3359 l_lot_control_flag := FALSE;
3360 END IF;
3361
3362 EXCEPTION
3363 WHEN OTHERS THEN
3364 l_lot_control_flag := FALSE;
3365 END;
3366
3367 -- Bug 2259553.
3368 --inv_quantity_tree_pvt.clear_quantity_cache;
3369 inv_quantity_tree_pvt.mark_all_for_refresh
3370 ( p_api_version_number => 1.0
3371 , p_init_msg_lst => FND_API.G_TRUE
3372 , x_return_status => l_return_status
3373 , x_msg_count => l_msg_count
3374 , x_msg_data => l_msg_data
3375 );
3376
3377 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3378 oe_msg_pub.transfer_msg_stack;
3379 l_msg_count:=OE_MSG_PUB.COUNT_MSG;
3380 for I in 1..l_msg_count loop
3381 l_msg_data := OE_MSG_PUB.Get(I,'F');
3382 IF l_debug_level > 0 THEN
3383 oe_debug_pub.add( L_MSG_DATA , 1 ) ;
3384 END IF;
3385 end loop;
3386 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3387 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3388 oe_msg_pub.transfer_msg_stack;
3389 l_msg_count:=OE_MSG_PUB.COUNT_MSG;
3390 for I in 1..l_msg_count loop
3391 l_msg_data := OE_MSG_PUB.Get(I,'F');
3392 IF l_debug_level > 0 THEN
3393 oe_debug_pub.add( L_MSG_DATA , 1 ) ;
3394 END IF;
3395 end loop;
3396 RAISE FND_API.G_EXC_ERROR;
3397 END IF;
3398
3399 inv_quantity_tree_pub.query_quantities
3400 ( p_api_version_number => 1.0
3401 , x_return_status => l_return_status
3402 , x_msg_count => l_msg_count
3403 , x_msg_data => l_msg_data
3404 , p_organization_id => p_org_id
3405 , p_inventory_item_id => p_item_id
3406 , p_tree_mode => 2
3407 , p_is_revision_control => false
3408 , p_grade_code => NULL -- INVCONV
3409 , p_is_lot_control => l_lot_control_flag
3410 , p_lot_expiration_date => nvl(p_sch_date,sysdate)
3411 , p_is_serial_control => false
3412 , p_revision => null
3413 , p_lot_number => null
3414 , p_subinventory_code => null
3415 , p_locator_id => null
3416 , x_qoh => l_qoh
3417 , x_rqoh => l_rqoh
3418 , x_qr => l_qr
3419 , x_qs => l_qs
3420 , x_att => l_att
3421 , x_atr => l_atr
3422 , x_sqoh => l_sqoh -- INVCONV
3423 , x_srqoh => l_srqoh -- INVCONV
3424 , x_sqr => l_sqr -- INVCONV
3425 , x_sqs => l_sqs -- INVCONV
3426 , x_satt => l_satt -- INVCONV
3427 , x_satr => l_satr -- INVCONV
3428 );
3429
3430 IF l_debug_level > 0 THEN
3431 oe_debug_pub.add( 'AFTER CALLING QUERY_QUANTITIES' , 1 ) ;
3432 END IF;
3433
3434 -- END IF;
3435
3436
3437
3438 /* if l_return_status != fnd_api.g_ret_sts_success then
3439 dbms_output.put_line('status: '|| l_return_status);
3440 dbms_output.put_line('error message count: '|| l_msg_count);
3441 if l_msg_count = 1 then
3442 dbms_output.put_line('error message: '|| l_msg_data);
3443 else
3444 for l_index in 1..l_msg_count loop
3445 fnd_msg_pub.get( p_data => l_msg_data
3446 , p_msg_index_out => l_msg_index);
3447 dbms_output.put_line('error message: ' || l_msg_data);
3448 end loop;
3449 end if;
3450 end if; */
3451
3452 IF l_debug_level > 0 THEN
3453 oe_debug_pub.add( 'RR: L_QOH ' || L_QOH , 1 ) ;
3454 oe_debug_pub.add( 'RR: L_QOH ' || L_ATR , 1 ) ;
3455 END IF;
3456
3457 x_on_hand_qty := l_qoh;
3458 x_avail_to_reserve := l_atr;
3459
3460 IF l_debug_level > 0 THEN
3461 oe_debug_pub.add( 'EXITING QUERY_QTY_TREE ' , 1 ) ;
3462 END IF;
3463
3464 END Query_Qty_Tree;
3465
3466 /*---------------------------------------------------------------------
3467 Function Name : Within_Rsv_Time_Fence
3468 Description : The function returns:
3469 TRUE: If the Schedule_Ship_Date is within the
3470 time fence of the system date. The time fence
3471 is defined in the profile option
3472 ONT_RESERVATION_TIME_FENCE.
3473 FALSE: If the Schedule_Ship_Date is note within the
3474 time fence of the system date.
3475 The date part of the dates (and not the time) are compared
3476 to return the value.
3477 --------------------------------------------------------------------- */
3478 Function Within_Rsv_Time_Fence(p_schedule_ship_date IN DATE)
3479 RETURN BOOLEAN
3480 IS
3481 l_rsv_time_fence_profile VARCHAR2(30);
3482 l_rsv_time_fence NUMBER;
3483 l_time_to_ship NUMBER;
3484 l_sysdate DATE;
3485 l_schedule_ship_date DATE;
3486 --
3487 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3488 --
3489 BEGIN
3490 -- We will check to see if the the schedule_ship_date is within
3491 -- the reservation time fence. i.e:
3492 -- If schedule_date - SYSDATE < reservation_time_fence
3493 -- we will return TRUE, else will return FALSE
3494
3495 -- Moac. Commented the below code
3496 -- l_rsv_time_fence_profile :=
3497 -- FND_PROFILE.VALUE('ONT_RESERVATION_TIME_FENCE');
3498
3499 -- Moac. Fetching the reservation time fence from system parameter.
3500 l_rsv_time_fence_profile := OE_Sys_Parameters.VALUE('ONT_RESERVATION_TIME_FENCE');
3501
3502 BEGIN
3503 l_rsv_time_fence := to_number(l_rsv_time_fence_profile);
3504 EXCEPTION
3505 WHEN OTHERS THEN
3506 IF l_debug_level > 0 THEN
3507 oe_debug_pub.add( 'IGNORING RESERVATION TIME FENCE' , 1 ) ;
3508 END IF;
3509 l_rsv_time_fence := null;
3510 END;
3511
3512 l_sysdate := trunc(SYSDATE);
3513 l_schedule_ship_date := trunc(p_schedule_ship_date);
3514
3515 l_time_to_ship := to_number(l_schedule_ship_date -l_sysdate);
3516
3517 IF l_debug_level > 0 THEN
3518 oe_debug_pub.add( 'L_TIME_TO_SHIP' || L_TIME_TO_SHIP , 1 ) ;
3519 oe_debug_pub.add( 'L_RSV_TIME_FENCE' || L_RSV_TIME_FENCE , 1 ) ;
3520 END IF;
3521
3522 IF l_time_to_ship < 0 THEN
3523 -- We don't know what this means. Schedule ship date is already
3524 -- past due. So we are not trying to reserve any inventory for this
3525 -- line.
3526 RETURN FALSE;
3527 ELSIF l_time_to_ship <= l_rsv_time_fence THEN
3528 RETURN TRUE;
3529 ELSE
3530 RETURN FALSE;
3531 END IF;
3532
3533 END Within_Rsv_Time_Fence;
3534 /*---------------------------------------------------------------------
3535 Procedure Name : Action_Schedule
3536 Description : This procedure is called from Process_Request proecudure
3537 to perform the action of SCHEDULE or RESERVE on the line.
3538 --------------------------------------------------------------------- */
3539
3540 Procedure Action_Schedule(p_x_line_rec IN OUT NOCOPY OE_ORDER_PUB.line_rec_type,
3541 p_old_line_rec IN OE_ORDER_PUB.line_rec_type,
3542 p_action IN VARCHAR2,
3543 p_qty_to_reserve IN NUMBER := null,
3544 p_qty2_to_reserve IN NUMBER := null, -- INVCONV
3545 x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
3546 IS
3547 l_line_rec OE_ORDER_PUB.line_rec_type;
3548 l_old_line_rec OE_ORDER_PUB.line_rec_type;
3549 l_out_line_rec OE_ORDER_PUB.line_rec_type;
3550 l_line_tbl OE_ORDER_PUB.line_tbl_type;
3551 l_old_line_tbl OE_ORDER_PUB.line_tbl_type;
3552 l_out_line_tbl OE_ORDER_PUB.line_tbl_type;
3553 l_old_atp_tbl OE_ATP.atp_tbl_type;
3554 l_return_status VARCHAR2(1);
3555 l_msg_count NUMBER;
3556 l_msg_data VARCHAR2(2000);
3557
3558 l_session_id NUMBER := 0;
3559 l_mrp_atp_rec MRP_ATP_PUB.ATP_Rec_Typ;
3560 l_out_mtp_atp_rec MRP_ATP_PUB.ATP_Rec_Typ;
3561 l_atp_supply_demand MRP_ATP_PUB.ATP_Supply_Demand_Typ;
3562 l_atp_period MRP_ATP_PUB.ATP_Period_Typ;
3563 l_atp_details MRP_ATP_PUB.ATP_Details_Typ;
3564 l_out_atp_tbl OE_ATP.atp_tbl_type;
3565 mrp_msg_data VARCHAR2(200);
3566
3567 l_reservation_rec inv_reservation_global.mtl_reservation_rec_type;
3568 l_dummy_sn inv_reservation_global.serial_number_tbl_type;
3569 l_quantity_reserved NUMBER;
3570 l_qty_to_reserve NUMBER;
3571 l_quantity2_reserved NUMBER; -- INVCONV
3572 l_qty2_to_reserve NUMBER; -- INVCONV
3573
3574 l_rsv_id NUMBER;
3575
3576
3577 l_reservable_type NUMBER;
3578
3579 l_buffer VARCHAR2(2000);
3580
3581 -- subinventory
3582 l_revision_code NUMBER;
3583 l_lot_code NUMBER;
3584 l_serial_code NUMBER;
3585
3586 --
3587 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3588 --
3589 BEGIN
3590
3591 IF l_debug_level > 0 THEN
3592 oe_debug_pub.add( 'ENTERING ACTION SCHEDULE' , 1 ) ;
3593 END IF;
3594 l_line_rec := p_x_line_rec;
3595 l_out_line_rec := p_x_line_rec;
3596 l_old_line_rec := p_old_line_rec;
3597
3598 IF l_debug_level > 0 THEN
3599 oe_debug_pub.add( 'RR5: ATO LINE ID: ' || L_LINE_REC.ATO_LINE_ID , 1 ) ;
3600 END IF;
3601 IF (l_line_rec.schedule_status_code is null)
3602 THEN
3603
3604 -- The line is not scheduled, so go ahead and schedule the line
3605 -- Create MRP record from the line record with the action of schedule
3606 -- The result of the request should be in x_request_rec
3607
3608 IF l_debug_level > 0 THEN
3609 oe_debug_pub.add( 'SCHEDULE THE LINE' , 1 ) ;
3610 END IF;
3611
3612 -- Setting the action to schedule since first we need to schedule the line.
3613 -- Will reset the action to what is actually was after calling MRP.
3614
3615 l_line_rec.schedule_action_code := OESCH_ACT_SCHEDULE;
3616
3617 l_line_tbl(1) := l_line_rec;
3618 l_old_line_tbl(1) := l_old_line_rec;
3619
3620 Load_MRP_Request
3621 ( p_line_tbl => l_line_tbl
3622 , p_old_line_tbl => l_old_line_tbl
3623 , x_atp_table => l_mrp_atp_rec);
3624
3625 IF l_debug_level > 0 THEN
3626 oe_debug_pub.add( 'SCH1 COUNT IS ' || L_MRP_ATP_REC.ERROR_CODE.COUNT , 1 ) ;
3627 END IF;
3628
3629 -- We are adding this so that we will not call MRP when
3630 -- table count is 0.
3631
3632 IF l_mrp_atp_rec.error_code.count > 0 THEN
3633
3634
3635 l_session_id := Get_Session_Id;
3636
3637 IF l_debug_level > 0 THEN
3638 oe_debug_pub.add( '1. CALLING MRP API WITH SESSION ID '||L_SESSION_ID , 1 ) ;
3639 END IF;
3640
3641 MRP_ATP_PUB.Call_ATP
3642 ( p_session_id => l_session_id
3643 , p_atp_rec => l_mrp_atp_rec
3644 , x_atp_rec => l_out_mtp_atp_rec
3645 , x_atp_supply_demand => l_atp_supply_demand
3646 , x_atp_period => l_atp_period
3647 , x_atp_details => l_atp_details
3648 , x_return_status => l_return_status
3649 , x_msg_data => mrp_msg_data
3650 , x_msg_count => l_msg_count);
3651
3652 IF l_debug_level > 0 THEN
3653 oe_debug_pub.add( '1. AFTER CALLING MRP_ATP_PUB.CALL_ATP' || L_RETURN_STATUS , 1 ) ;
3654 END IF;
3655 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3656 IF l_debug_level > 0 THEN
3657 oe_debug_pub.add( 'ERROR IS' || MRP_MSG_DATA , 1 ) ;
3658 END IF;
3659 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3660 END IF;
3661
3662 Load_Results(p_atp_table => l_out_mtp_atp_rec,
3663 p_x_line_tbl => l_line_tbl,
3664 x_atp_tbl => l_out_atp_tbl,
3665 x_return_status => l_return_status);
3666
3667 END IF; -- Check for MRP count.
3668
3669 l_out_line_rec := l_line_tbl(1);
3670
3671 IF l_debug_level > 0 THEN
3672 oe_debug_pub.add( 'RR: L_RETURN_STATUS ' || L_RETURN_STATUS , 1 ) ;
3673 END IF;
3674 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3675 IF l_debug_level > 0 THEN
3676 oe_debug_pub.add( 'RR: L1' , 1 ) ;
3677 END IF;
3678 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3679 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3680 IF l_debug_level > 0 THEN
3681 oe_debug_pub.add( 'RR: L2' , 1 ) ;
3682 END IF;
3683 RAISE FND_API.G_EXC_ERROR;
3684 END IF;
3685
3686 -- Reloading l_line_rec from l_out_line_tbl since the record
3687 -- in the table is the one which is demanded.
3688
3689 IF l_debug_level > 0 THEN
3690 oe_debug_pub.add( 'RR: L3' , 1 ) ;
3691 END IF;
3692 l_line_rec := l_line_tbl(1);
3693 l_line_rec.schedule_action_code := p_action;
3694
3695 END IF; /* If schedule_status_code is null */
3696
3697 IF l_debug_level > 0 THEN
3698 oe_debug_pub.add( 'RR: L4' , 1 ) ;
3699 oe_debug_pub.add( 'SCH_CACHED_SCH_LEVEL_CODE ' || SCH_CACHED_SCH_LEVEL_CODE , 1 ) ;
3700 END IF;
3701
3702 IF (p_action = OESCH_ACT_RESERVE)
3703 OR (p_action = OESCH_ACT_SCHEDULE AND
3704 (sch_cached_sch_level_code = SCH_LEVEL_THREE OR
3705 sch_cached_sch_level_code is null) AND
3706 Within_Rsv_Time_Fence(l_line_rec.schedule_ship_date)) OR
3707 (p_qty_to_reserve is not null)
3708 THEN
3709
3710 /* Assigning reserved_quantity to 0 if MISS_NUM, to fix the bug 1384831 */
3711
3712 IF l_old_line_rec.reserved_quantity = FND_API.G_MISS_NUM THEN
3713
3714 l_old_line_rec.reserved_quantity := 0;
3715
3716 END IF;
3717 IF l_old_line_rec.reserved_quantity2 = FND_API.G_MISS_NUM THEN -- INVCONV
3718
3719 l_old_line_rec.reserved_quantity2 := 0;
3720
3721 END IF;
3722
3723
3724 IF nvl(l_line_rec.shippable_flag,'N') = 'Y'
3725 THEN
3726 -- Create INV record from the line to reserve
3727
3728 IF p_qty_to_reserve is null THEN
3729 l_qty_to_reserve := l_line_rec.ordered_quantity -
3730 nvl(l_old_line_rec.reserved_quantity,0);
3731 ELSE
3732 l_qty_to_reserve := p_qty_to_reserve;
3733 END IF;
3734
3735 IF p_qty2_to_reserve is null THEN -- INVCONV
3736 l_qty2_to_reserve := l_line_rec.ordered_quantity2 -
3737 nvl(l_old_line_rec.reserved_quantity2,0);
3738 ELSE
3739 l_qty2_to_reserve := p_qty2_to_reserve;
3740 END IF;
3741
3742
3743
3744 IF l_qty_to_reserve > 0 THEN
3745
3746 IF l_line_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
3747 -- We cannot create a reservation currently if the line is
3748 -- being created (since the lines is yet not in the database,
3749 -- and there is a validation done with this line id when we
3750 -- call INV API.). We will populate the reserved quantity on
3751 -- the line record, and in the post-write procedure (in OEXULINB),
3752 -- we will perform the reservation.
3753
3754 l_out_line_rec := l_line_rec;
3755 l_out_line_rec.schedule_status_code := OESCH_STATUS_SCHEDULED;
3756 l_out_line_rec.reserved_quantity := l_qty_to_reserve;
3757 l_out_line_rec.reserved_quantity2 := l_qty2_to_reserve; -- INVCONV
3758 ELSE
3759
3760 IF p_action <> OESCH_ACT_RESERVE THEN
3761 SELECT RESERVABLE_TYPE
3762 INTO l_reservable_type
3763 FROM MTL_SYSTEM_ITEMS
3764 WHERE INVENTORY_ITEM_ID = l_line_rec.inventory_item_id
3765 AND ORGANIZATION_ID = l_line_rec.ship_from_org_id;
3766
3767 IF l_reservable_type <> 1 THEN
3768
3769 IF l_debug_level > 0 THEN
3770 oe_debug_pub.add( 'NON RESERVABLE ITEM RESERVATION NOT REQUIRED '||L_RESERVABLE_TYPE , 3 ) ;
3771 END IF;
3772 GOTO NO_RESERVATION;
3773 END IF;
3774
3775 END IF;
3776
3777 IF l_debug_level > 0 THEN
3778 oe_debug_pub.add( 'L_QTY_TO_RESERVE : ' || L_QTY_TO_RESERVE , 3 ) ;
3779 oe_debug_pub.add( 'L_QTY2_TO_RESERVE : ' || L_QTY2_TO_RESERVE , 3 ) ; -- INVCONV
3780 END IF;
3781 --newsub check if item is under lot/revision/serial control
3782 IF l_line_rec.subinventory is not null
3783 AND l_line_rec.subinventory <> FND_API.G_MISS_CHAR THEN
3784 BEGIN
3785 SELECT revision_qty_control_code, lot_control_code,
3786 serial_number_control_code
3787 INTO l_revision_code, l_lot_code, l_serial_code
3788 FROM mtl_system_items
3789 WHERE inventory_item_id = l_line_rec.inventory_item_id
3790 AND organization_id = l_line_rec.ship_from_org_id;
3791
3792 EXCEPTION
3793 WHEN OTHERS THEN
3794 l_return_status := FND_API.G_RET_STS_ERROR;
3795 fnd_message.set_name('ONT', 'OE_INVALID_ITEM_WHSE');
3796 OE_MSG_PUB.Add;
3797 END;
3798
3799
3800 IF l_revision_code = 2 OR l_lot_code = 2 THEN
3801 -- 2 == YES
3802 fnd_message.set_name('ONT', 'OE_SUBINV_NOT_ALLOWED');
3803 OE_MSG_PUB.Add;
3804 IF p_action = OESCH_ACT_RESERVE THEN
3805 l_return_status := FND_API.G_RET_STS_ERROR;
3806 RAISE FND_API.G_EXC_ERROR;
3807 ELSE
3808 l_return_status := FND_API.G_RET_STS_SUCCESS;
3809 l_quantity_reserved := null;
3810 l_quantity2_reserved := null; -- INVCONV
3811 GOTO NO_RESERVATION;
3812 END IF;
3813
3814 END IF;
3815 END IF;
3816 --end newsub
3817
3818 Load_INV_Request
3819 ( p_line_rec => l_line_rec
3820 , p_quantity_to_reserve => l_qty_to_reserve
3821 , p_quantity2_to_reserve => l_qty2_to_reserve -- INVCONV
3822 , x_reservation_rec => l_reservation_rec);
3823
3824 -- Call INV with action = RESERVE
3825
3826 inv_reservation_pub.create_reservation
3827 ( p_api_version_number => 1.0
3828 , p_init_msg_lst => FND_API.G_TRUE
3829 , x_return_status => l_return_status
3830 , x_msg_count => l_msg_count
3831 , x_msg_data => l_msg_data
3832 , p_rsv_rec => l_reservation_rec
3833 , p_serial_number => l_dummy_sn
3834 , x_serial_number => l_dummy_sn
3835 , p_partial_reservation_flag => FND_API.G_FALSE
3836 , p_force_reservation_flag => FND_API.G_FALSE
3837 , p_validation_flag => FND_API.G_TRUE
3838 , x_quantity_reserved => l_quantity_reserved
3839 , x_secondary_quantity_reserved => l_quantity2_reserved -- INVCONV
3840 , x_reservation_id => l_rsv_id
3841 );
3842
3843 IF l_debug_level > 0 THEN
3844 oe_debug_pub.add( '1. AFTER CALLING CREATE RESERVATION' || L_RETURN_STATUS , 1 ) ;
3845 oe_debug_pub.add( L_MSG_DATA , 1 ) ;
3846 END IF;
3847
3848 -- Bug No:2097933
3849 -- If the Reservation was succesfull we set
3850 -- the package variable to "Y".
3851 IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
3852 OESCH_PERFORMED_RESERVATION := 'Y';
3853 END IF;
3854
3855 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3856 IF l_debug_level > 0 THEN
3857 oe_debug_pub.add( 'RAISING UNEXPECTED ERROR' , 1 ) ;
3858 END IF;
3859 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3860 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3861 IF l_msg_data is not null THEN
3862 fnd_message.set_encoded(l_msg_data);
3863 l_buffer := fnd_message.get;
3864 oe_msg_pub.add_text(p_message_text => l_buffer);
3865 IF l_debug_level > 0 THEN
3866 oe_debug_pub.add( L_MSG_DATA , 1 ) ;
3867 END IF;
3868 END IF;
3869
3870 IF p_action = OESCH_ACT_RESERVE THEN
3871
3872 -- The user has explicitly required a reservation.
3873 -- We should error out since reservation failed.
3874
3875 RAISE FND_API.G_EXC_ERROR;
3876
3877 ELSE
3878 -- Reservation action took place since the line
3879 -- was within reservation time fence. We do not
3880 -- need to error out for this. The message will
3881 -- indicate that reservation did not take place.
3882
3883 l_return_status := FND_API.G_RET_STS_SUCCESS;
3884 l_quantity_reserved := null;
3885 l_quantity2_reserved := null; -- INVCONV
3886 END IF;
3887
3888 END IF;
3889
3890 << NO_RESERVATION >>
3891
3892 l_out_line_rec := l_line_rec;
3893 l_out_line_rec.schedule_status_code := OESCH_STATUS_SCHEDULED;
3894 --l_out_line_rec.reserved_quantity := l_quantity_reserved;
3895 END IF; /* Operation on the line is create or not */
3896
3897 ELSE
3898
3899 l_out_line_rec := l_line_rec;
3900 l_out_line_rec.schedule_status_code := OESCH_STATUS_SCHEDULED;
3901 l_out_line_rec.reserved_quantity :=
3902 l_old_line_rec.reserved_quantity;
3903 l_out_line_rec.reserved_quantity2 :=
3904 l_old_line_rec.reserved_quantity2; -- INVCONV
3905
3906
3907 END IF; /* l_qty_to_reserve > 0 */
3908 END IF; /* If shippable Flag = Y */
3909
3910 END IF; /* If reservation needs to be performed */
3911
3912 p_x_line_rec := l_out_line_rec;
3913 x_return_status := l_return_status;
3914
3915 IF l_debug_level > 0 THEN
3916 oe_debug_pub.add( 'EXITING ACTION SCHEDULE: ' || L_RETURN_STATUS , 1 ) ;
3917 END IF;
3918
3919 EXCEPTION
3920 WHEN FND_API.G_EXC_ERROR THEN
3921
3922 p_x_line_rec := l_out_line_rec;
3923 x_return_status := FND_API.G_RET_STS_ERROR;
3924
3925 WHEN OTHERS THEN
3926
3927 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3928
3929 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3930 THEN
3931 OE_MSG_PUB.Add_Exc_Msg
3932 ( G_PKG_NAME
3933 , 'Action_Schedule'
3934 );
3935 END IF;
3936
3937 END Action_Schedule;
3938
3939 /*---------------------------------------------------------------------
3940 Procedure Name : Action_UnSchedule
3941 Description : This procedure is called from Process_Request proecudure
3942 to perform the action of UNSCHEDULE or UNRESERVE on the line.
3943 --------------------------------------------------------------------- */
3944
3945 Procedure Action_UnSchedule(p_old_line_rec IN OE_ORDER_PUB.line_rec_type,
3946 p_action IN VARCHAR2,
3947 p_x_line_rec IN OUT NOCOPY OE_ORDER_PUB.line_rec_type,
3948 x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
3949 IS
3950
3951 l_line_rec OE_ORDER_PUB.line_rec_type;
3952 l_old_line_rec OE_ORDER_PUB.line_rec_type;
3953 l_out_line_rec OE_ORDER_PUB.line_rec_type;
3954 l_line_tbl OE_ORDER_PUB.line_tbl_type;
3955 l_old_line_tbl OE_ORDER_PUB.line_tbl_type;
3956 l_out_line_tbl OE_ORDER_PUB.line_tbl_type;
3957 l_old_atp_tbl OE_ATP.atp_tbl_type;
3958 l_return_status VARCHAR2(1);
3959 l_msg_count NUMBER;
3960 l_msg_data VARCHAR2(2000);
3961 l_out_atp_rec OE_ATP.atp_rec_type;
3962 l_session_id NUMBER := 0;
3963 l_mrp_atp_rec MRP_ATP_PUB.ATP_Rec_Typ;
3964 l_out_mtp_atp_rec MRP_ATP_PUB.ATP_Rec_Typ;
3965 l_atp_supply_demand MRP_ATP_PUB.ATP_Supply_Demand_Typ;
3966 l_atp_period MRP_ATP_PUB.ATP_Period_Typ;
3967 l_atp_details MRP_ATP_PUB.ATP_Details_Typ;
3968 l_out_atp_tbl OE_ATP.atp_tbl_type;
3969 mrp_msg_data VARCHAR2(200);
3970 l_reservation_rec inv_reservation_global.mtl_reservation_rec_type;
3971 l_dummy_sn inv_reservation_global.serial_number_tbl_type;
3972 l_qty_to_unreserve NUMBER;
3973 l_rsv_id NUMBER;
3974
3975 l_qty2_to_unreserve NUMBER; -- INVCONV
3976 --
3977 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3978 --
3979 BEGIN
3980
3981 IF l_debug_level > 0 THEN
3982 oe_debug_pub.add( 'ENTERING ACTION_UNSCHEDULE ' , 1 ) ;
3983 END IF;
3984
3985 l_line_rec := p_x_line_rec;
3986 l_old_line_rec := p_old_line_rec;
3987
3988
3989 -- Only unreserve line if line has NOT been interfaced to WSH
3990
3991 IF (nvl(l_line_rec.shipping_interfaced_flag, 'N') = 'N' AND
3992 l_old_line_rec.reserved_quantity is not null AND
3993 l_old_line_rec.reserved_quantity <> FND_API.G_MISS_NUM)
3994 THEN
3995
3996 -- Call INV API to delete the reservations on the line.
3997
3998 l_qty_to_unreserve := l_old_line_rec.reserved_quantity;
3999 l_qty_to_unreserve := nvl(l_old_line_rec.reserved_quantity, 0); -- INVCONV
4000
4001 Unreserve_Line
4002 ( p_line_rec => l_old_line_rec
4003 , p_quantity_to_unreserve => l_qty_to_unreserve
4004 , p_quantity2_to_unreserve => l_qty2_to_unreserve -- INVCONV
4005 , x_return_status => l_return_status);
4006
4007 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4008 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4009 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4010 RAISE FND_API.G_EXC_ERROR;
4011 END IF;
4012
4013 l_out_line_rec := l_line_rec;
4014 l_out_line_rec.schedule_status_code := OESCH_STATUS_SCHEDULED;
4015
4016 END IF;
4017
4018
4019 -- If the action was unreserve, we do not need to unschedule the line.
4020 -- Thus we will check for this condition before unscheduling.
4021
4022 IF p_action <> OESCH_ACT_UNRESERVE THEN
4023
4024 -- Create MRP record with action of UNDEMAND.
4025
4026
4027 l_line_rec.schedule_action_code := OESCH_ACT_UNDEMAND;
4028
4029 l_line_tbl(1) := l_line_rec;
4030 l_old_line_tbl(1) := l_old_line_rec;
4031
4032 Load_MRP_Request
4033 ( p_line_tbl => l_line_tbl
4034 , p_old_line_tbl => l_old_line_tbl
4035 , x_atp_table => l_mrp_atp_rec);
4036
4037 l_session_id := Get_Session_Id;
4038
4039 -- Call ATP
4040
4041 IF l_debug_level > 0 THEN
4042 oe_debug_pub.add( '1. CALLING MRP API WITH SESSION ID '||L_SESSION_ID , 1 ) ;
4043 END IF;
4044
4045 MRP_ATP_PUB.Call_ATP
4046 ( p_session_id => l_session_id
4047 , p_atp_rec => l_mrp_atp_rec
4048 , x_atp_rec => l_out_mtp_atp_rec
4049 , x_atp_supply_demand => l_atp_supply_demand
4050 , x_atp_period => l_atp_period
4051 , x_atp_details => l_atp_details
4052 , x_return_status => l_return_status
4053 , x_msg_data => mrp_msg_data
4054 , x_msg_count => l_msg_count);
4055
4056 IF l_debug_level > 0 THEN
4057 oe_debug_pub.add( '2. AFTER CALLING MRP_ATP_PUB.CALL_ATP' || L_RETURN_STATUS , 1 ) ;
4058 END IF;
4059
4060 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4061 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4062 END IF;
4063
4064 Load_Results(p_atp_table => l_out_mtp_atp_rec,
4065 p_x_line_tbl => l_line_tbl,
4066 x_atp_tbl => l_out_atp_tbl,
4067 x_return_status => l_return_status);
4068
4069 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4070 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4071 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4072 RAISE FND_API.G_EXC_ERROR;
4073 END IF;
4074
4075 l_out_line_rec := l_line_tbl(1);
4076 l_out_atp_rec := l_out_atp_tbl(1);
4077
4078 END IF;
4079
4080 -- If the action performed is UNSCHEDULE, then the reserved quantity is now -- null.
4081 l_out_line_rec.reserved_quantity := null;
4082
4083 p_x_line_rec := l_out_line_rec;
4084 x_return_status := l_return_status;
4085
4086 IF l_debug_level > 0 THEN
4087 oe_debug_pub.add( 'EXITING ACTION_UNSCHEDULE ' , 1 ) ;
4088 END IF;
4089
4090 END Action_UnSchedule;
4091
4092 /*---------------------------------------------------------------------
4093 Procedure Name : Process_Request
4094 Description : This procedure is called from the Schedule_Line procedure
4095 to schedule a SINGLE LINE (a set or a parent line is scheduled
4096 in different procedure). The single line could be a part
4097 of the set which is getting scheduled independently
4098 (because there was not change in the set related attribute),
4099 or it could be just a simple standard line which does not
4100 belong to any set.
4101
4102 --------------------------------------------------------------------- */
4103
4104 Procedure Process_request( p_old_line_rec IN OE_ORDER_PUB.line_rec_type,
4105 p_x_line_rec IN OUT NOCOPY OE_ORDER_PUB.line_rec_type,
4106 x_out_atp_tbl OUT NOCOPY /* file.sql.39 change */ OE_ATP.atp_tbl_type,
4107 x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
4108 IS
4109
4110 l_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
4111 l_line_rec OE_ORDER_PUB.line_rec_type;
4112 l_line_tbl OE_ORDER_PUB.line_tbl_type;
4113 l_old_line_tbl OE_ORDER_PUB.line_tbl_type;
4114 l_out_line_rec OE_ORDER_PUB.line_rec_type;
4115 l_out_atp_rec OE_ATP.atp_rec_type;
4116 l_out_line_tbl OE_ORDER_PUB.line_tbl_type;
4117 l_out_atp_tbl OE_ATP.atp_tbl_type;
4118 l_old_line_rec OE_ORDER_PUB.line_rec_type;
4119 l_action VARCHAR2(30);
4120 l_old_status VARCHAR2(30);
4121 l_msg_count NUMBER;
4122 l_msg_data VARCHAR2(2000);
4123 l_reservation_rec inv_reservation_global.mtl_reservation_rec_type;
4124 l_query_rsv_rec inv_reservation_global.mtl_reservation_rec_type;
4125 l_rsv_tbl inv_reservation_global.mtl_reservation_tbl_type;
4126 l_dummy_sn inv_reservation_global.serial_number_tbl_type;
4127 l_quantity_reserved NUMBER;
4128 l_rsv_id NUMBER;
4129 l_qty_unreserved NUMBER := 0;
4130 l_qty_reserved NUMBER;
4131
4132 l_changed_ordered_qty NUMBER := 0;
4133 l_changed_reserved_qty NUMBER := 0;
4134 l_qty_to_unreserve NUMBER := 0;
4135 l_qty_to_reserve NUMBER := 0;
4136
4137 -- INVCONV
4138 l_qty2_unreserved NUMBER := 0;
4139 l_qty2_reserved NUMBER;
4140
4141 l_changed_ordered_qty2 NUMBER := 0;
4142 l_changed_reserved_qty2 NUMBER := 0;
4143 l_qty2_to_unreserve NUMBER := 0;
4144 l_qty2_to_reserve NUMBER := 0;
4145 l_on_hand_qty2 NUMBER;
4146 l_quantity2_reserved NUMBER; -- INVCONV
4147
4148
4149 l_session_id NUMBER := 0;
4150 l_mrp_atp_rec MRP_ATP_PUB.ATP_Rec_Typ;
4151 l_out_mtp_atp_rec MRP_ATP_PUB.ATP_Rec_Typ;
4152 l_atp_supply_demand MRP_ATP_PUB.ATP_Supply_Demand_Typ;
4153 l_atp_period MRP_ATP_PUB.ATP_Period_Typ;
4154 l_atp_details MRP_ATP_PUB.ATP_Details_Typ;
4155 mrp_msg_data VARCHAR2(200);
4156 l_on_hand_qty NUMBER;
4157 l_avail_to_reserve NUMBER;
4158 l_avail_to_reserve2 NUMBER; -- INVCONV
4159 l_buffer VARCHAR2(2000);
4160 l_reservable_type NUMBER;
4161 l_re_reserve_flag VARCHAR2(1) := 'N';
4162 -- added by fabdi 03/May/2001
4163 -- l_process_flag VARCHAR2(1) := FND_API.G_FALSE; -- INVCONV
4164 -- end fabdi
4165 l_sales_order_id NUMBER;
4166 l_x_error_code NUMBER;
4167 l_lock_records VARCHAR2(1);
4168 l_sort_by_req_date NUMBER ;
4169 l_count NUMBER;
4170 -- subinventory
4171 l_revision_code NUMBER;
4172 l_lot_code NUMBER;
4173 l_serial_code NUMBER;
4174
4175
4176 --
4177 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4178 --
4179 BEGIN
4180
4181 IF l_debug_level > 0 THEN
4182 oe_debug_pub.add( 'ENTERING OE_ORDER_SCH_UTIL.PROCESS_REQUEST' , 1 ) ;
4183 oe_debug_pub.add( 'OESCH_AUTO_SCH_FLAG : ' || OESCH_AUTO_SCH_FLAG , 1 ) ;
4184 END IF;
4185
4186 l_line_rec := p_x_line_rec;
4187 l_out_line_rec := p_x_line_rec;
4188 l_old_line_rec := p_old_line_rec;
4189 l_action := p_x_line_rec.schedule_action_code;
4190 l_old_status := p_old_line_rec.schedule_status_code;
4191
4192 -- There is a possiblity that the schedule_action_code comes to this
4193 -- code as missing. If it does, we will assign null value to it.
4194
4195 IF (l_line_rec.schedule_action_code = FND_API.G_MISS_CHAR) THEN
4196 l_line_rec.schedule_action_code := null;
4197 END IF;
4198
4199
4200 IF (l_line_rec.schedule_action_code is NULL) THEN
4201
4202 IF l_debug_level > 0 THEN
4203 oe_debug_pub.add( 'SCHEDULE ACTION CODE IS NULL' , 1 ) ;
4204 END IF;
4205
4206 IF (l_line_rec.schedule_status_code IS NULL) AND
4207 (OESCH_AUTO_SCH_FLAG = 'N') AND
4208 OE_GLOBALS.Equal(l_line_rec.schedule_ship_date,
4209 l_old_line_rec.schedule_ship_date) AND
4210 OE_GLOBALS.Equal(l_line_rec.schedule_arrival_date,
4211 l_old_line_rec.schedule_arrival_date) AND
4212 OE_GLOBALS.Equal(l_line_rec.reserved_quantity,
4213 l_old_line_rec.reserved_quantity)
4214 THEN
4215
4216 IF l_debug_level > 0 THEN
4217 oe_debug_pub.add( 'NO ACTION NEEDED TO BE PERFORMED' , 1 ) ;
4218 END IF;
4219 -- no action needs to be performed;
4220 goto end_of_processing;
4221
4222 END IF;
4223
4224 IF (l_line_rec.operation = OE_GLOBALS.G_OPR_DELETE) OR
4225 ((l_line_rec.source_type_code = OE_GLOBALS.G_SOURCE_EXTERNAL) AND
4226 (l_line_rec.schedule_status_code is not null)) THEN
4227
4228 -- If the line is deleted, we need to unschedule it.
4229 -- If the line's source type is being changed from INTERNAL to
4230 -- EXTERNAL, and the old line was scheduled, we need to unschedule it.
4231
4232 l_line_rec.schedule_action_code := OESCH_ACT_UNSCHEDULE;
4233 l_out_line_rec := l_line_rec;
4234 Action_UnSchedule(p_x_line_rec => l_out_line_rec,
4235 p_old_line_rec => l_old_line_rec,
4236 p_action => OESCH_ACT_UNSCHEDULE,
4237 x_return_status => l_return_status);
4238
4239 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4240 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4241 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4242 RAISE FND_API.G_EXC_ERROR;
4243 END IF;
4244
4245 goto end_of_processing;
4246
4247 END IF; /* If operation on line was DELETE */
4248
4249 IF NOT OE_GLOBALS.Equal(l_line_rec.schedule_ship_date,
4250 l_old_line_rec.schedule_ship_date) THEN
4251
4252 IF l_debug_level > 0 THEN
4253 oe_debug_pub.add( 'NEW' || L_LINE_REC.SCHEDULE_SHIP_DATE ) ;
4254 oe_debug_pub.add( 'OLD' || L_OLD_LINE_REC.SCHEDULE_SHIP_DATE ) ;
4255 END IF;
4256
4257 -- We will treat a special case here where the date changes
4258 -- from no date to some date. If this change takes place,
4259 -- it means the line was not scheduled and needs to get scheduled
4260 -- and not rescheduled.
4261
4262 IF (l_old_line_rec.schedule_ship_date) is null OR
4263 (l_old_line_rec.schedule_ship_date = FND_API.G_MISS_DATE) THEN
4264
4265 -- Set the action on the line as schedule
4266 l_line_rec.schedule_action_code := OESCH_ACT_SCHEDULE;
4267
4268 l_out_line_rec := l_line_rec;
4269 Action_Schedule(p_x_line_rec => l_out_line_rec,
4270 p_old_line_rec => l_old_line_rec,
4271 p_action => OESCH_ACT_SCHEDULE,
4272 x_return_status => l_return_status);
4273
4274 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4275 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4276 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4277 RAISE FND_API.G_EXC_ERROR;
4278 END IF;
4279
4280
4281 goto end_of_processing;
4282
4283 END IF; /* For special demand */
4284 END IF; /* If schedule date has changed */
4285
4286 IF l_debug_level > 0 THEN
4287 oe_debug_pub.add( 'OLD AD ' || L_OLD_LINE_REC.SCHEDULE_ARRIVAL_DATE , 1 ) ;
4288 oe_debug_pub.add( 'NEW AD ' || L_OLD_LINE_REC.SCHEDULE_ARRIVAL_DATE , 1 ) ;
4289 END IF;
4290
4291 IF NOT OE_GLOBALS.Equal(l_line_rec.schedule_arrival_date,
4292 l_old_line_rec.schedule_arrival_date) THEN
4293
4294 IF l_debug_level > 0 THEN
4295 oe_debug_pub.add( 'NEW' || L_LINE_REC.SCHEDULE_ARRIVAL_DATE ) ;
4296 oe_debug_pub.add( 'OLD' || L_OLD_LINE_REC.SCHEDULE_ARRIVAL_DATE ) ;
4297 END IF;
4298
4299 -- We will treat a special case here where the date changes
4300 -- from no date to some date. If this change takes place,
4301 -- it means the line was not scheduled and needs to get scheduled
4302 -- and not rescheduled.
4303
4304 IF (l_old_line_rec.schedule_arrival_date) is null OR
4305 (l_old_line_rec.schedule_arrival_date = FND_API.G_MISS_DATE) THEN
4306
4307 l_out_line_rec := l_line_rec;
4308 Action_Schedule(p_x_line_rec => l_out_line_rec,
4309 p_old_line_rec => l_old_line_rec,
4310 p_action => OESCH_ACT_SCHEDULE,
4311 x_return_status => l_return_status);
4312
4313 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4314 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4315 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4316 RAISE FND_API.G_EXC_ERROR;
4317 END IF;
4318
4319
4320 goto end_of_processing;
4321
4322 END IF; /* For special demand */
4323 END IF; /* If schedule date has changed */
4324
4325 /* status_code <> null and action_code is null */
4326 /* This condition means, existing order has been changed */
4327
4328 IF p_x_line_rec.schedule_status_code is not null AND
4329 Schedule_Attribute_Changed(p_line_rec => l_line_rec,
4330 p_old_line_rec => l_old_line_rec)
4331
4332 THEN
4333
4334 /* ordered_quantity has changed. Set the flag G_LINE_PART_OF_SET
4335 if the line belongs to a ship or arrival set */
4336
4337 IF l_line_rec.ship_set_id is not null OR
4338 l_line_rec.arrival_set_id is not null THEN
4339 G_LINE_PART_OF_SET := TRUE;
4340 END IF;
4341
4342 -- Right now I am assuming that when the scheduling attributes
4343 -- changes, we will unreserve all the quantity
4344
4345 IF l_debug_level > 0 THEN
4346 oe_debug_pub.add( 'RESCHEDULING SINCE SCHEDULE ATTRIBUTE CHANGED' ) ;
4347 oe_debug_pub.add( 'OLD RESERV QTY ' || L_OLD_LINE_REC.RESERVED_QUANTITY , 1 ) ;
4348 END IF;
4349 IF (l_old_line_rec.reserved_quantity is not null)
4350 THEN
4351
4352 -- Added this part of code to fix bug 1797109.
4353 -- Unreserve only when one of the below mentioned, attrubutes
4354 -- changes, in other case simply re-schedule the line.
4355 --During the fix l_re_reserve_flag is introduced.
4356 l_re_reserve_flag := 'N';
4357 -- Only unreserve line if line has NOT been interfaced to WSH
4358 IF (nvl(l_line_rec.shipping_interfaced_flag, 'N') = 'N' AND
4359 (NOT OE_GLOBALS.Equal(l_line_rec.inventory_item_id,
4360 l_old_line_rec.inventory_item_id)
4361 OR NOT OE_GLOBALS.Equal(l_line_rec.subinventory,
4362 l_old_line_rec.subinventory)
4363 OR NOT OE_GLOBALS.Equal(l_line_rec.ordered_quantity,
4364 l_old_line_rec.ordered_quantity)
4365 OR NOT OE_GLOBALS.Equal(l_line_rec.order_quantity_uom,
4366 l_old_line_rec.order_quantity_uom)
4367 OR NOT OE_GLOBALS.Equal(l_line_rec.ship_from_org_id,
4368 l_old_line_rec.ship_from_org_id))) THEN
4369
4370 l_re_reserve_flag := 'Y';
4371 -- Call INV to delete the old reservations
4372 Unreserve_Line
4373 (p_line_rec => l_old_line_rec,
4374 p_quantity_to_unreserve => l_old_line_rec.reserved_quantity,
4375 p_quantity2_to_unreserve => nvl(l_old_line_rec.reserved_quantity2, 0), -- INVCONV
4376 x_return_status => l_return_status);
4377 END IF;
4378
4379 ELSE
4380 l_re_reserve_flag := 'Y';
4381 IF l_debug_level > 0 THEN
4382 oe_debug_pub.add( 'SETTING RE RESERVE IN ELSE' , 1 ) ;
4383 END IF;
4384 END IF;
4385
4386 -- If the scheduling is happening due to inventory item change.
4387 -- We should call MRP twice. First time we should call the with
4388 -- Undemand for old item. Second call would be redemand.
4389
4390 IF NOT OE_GLOBALS.Equal(l_line_rec.inventory_item_id,
4391 l_old_line_rec.inventory_item_id)
4392 THEN
4393
4394 Action_undemand(p_old_line_rec => l_old_line_rec,
4395 x_return_status => l_return_status);
4396
4397 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4398 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4399 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4400 RAISE FND_API.G_EXC_ERROR;
4401 END IF;
4402 END IF;
4403
4404 -- Call MRP with action = REDEMAND
4405
4406 l_line_rec.schedule_action_code := OESCH_ACT_REDEMAND;
4407 l_line_tbl(1) := l_line_rec;
4408 l_old_line_tbl(1) := l_old_line_rec;
4409
4410 Load_MRP_Request
4411 ( p_line_tbl => l_line_tbl
4412 , p_old_line_tbl => l_old_line_tbl
4413 , x_atp_table => l_mrp_atp_rec);
4414
4415 l_session_id := Get_Session_Id;
4416
4417 -- Call ATP
4418
4419 IF l_debug_level > 0 THEN
4420 oe_debug_pub.add( '1. CALLING MRP API WITH SESSION ID '||L_SESSION_ID , 1 ) ;
4421 END IF;
4422
4423 MRP_ATP_PUB.Call_ATP
4424 ( p_session_id => l_session_id
4425 , p_atp_rec => l_mrp_atp_rec
4426 , x_atp_rec => l_out_mtp_atp_rec
4427 , x_atp_supply_demand => l_atp_supply_demand
4428 , x_atp_period => l_atp_period
4429 , x_atp_details => l_atp_details
4430 , x_return_status => l_return_status
4431 , x_msg_data => mrp_msg_data
4432 , x_msg_count => l_msg_count);
4433
4434 IF l_debug_level > 0 THEN
4435 oe_debug_pub.add( '3. AFTER CALLING MRP_ATP_PUB.CALL_ATP' || L_RETURN_STATUS , 1 ) ;
4436 END IF;
4437
4438 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4439 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4440 END IF;
4441
4442 Load_Results(p_atp_table => l_out_mtp_atp_rec,
4443 p_x_line_tbl => l_line_tbl,
4444 x_atp_tbl => l_out_atp_tbl,
4445 x_return_status => l_return_status);
4446
4447 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4448 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4449 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4450 RAISE FND_API.G_EXC_ERROR;
4451 END IF;
4452
4453 l_out_line_rec := l_line_tbl(1);
4454
4455 -- Adding code to fix bug 2126165.
4456
4457 IF NOT OE_GLOBALS.Equal(l_out_line_rec.schedule_ship_date,
4458 l_old_line_rec.schedule_ship_date)
4459 AND l_old_line_rec.reserved_quantity > 0
4460 AND l_re_reserve_flag = 'N'
4461 THEN
4462
4463
4464 l_query_rsv_rec.reservation_id := fnd_api.g_miss_num;
4465
4466 l_sales_order_id
4467 := Get_mtl_sales_order_id(l_old_line_rec.header_id);
4468 l_query_rsv_rec.demand_source_header_id := l_sales_order_id;
4469 l_query_rsv_rec.demand_source_line_id := l_old_line_rec.line_id;
4470
4471 -- 02-jun-2000 mpetrosi added org_id to query_reservation start
4472 l_query_rsv_rec.organization_id := l_old_line_rec.ship_from_org_id;
4473 -- 02-jun-2000 mpetrosi added org_id to query_reservation end
4474
4475
4476 IF l_debug_level > 0 THEN
4477 oe_debug_pub.add( 'RSCH: CALLING INVS QUERY_RESERVATION ' , 1 ) ;
4478 END IF;
4479
4480 inv_reservation_pub.query_reservation
4481 ( p_api_version_number => 1.0
4482 , p_init_msg_lst => fnd_api.g_true
4483 , x_return_status => l_return_status
4484 , x_msg_count => l_msg_count
4485 , x_msg_data => l_msg_data
4486 , p_query_input => l_query_rsv_rec
4487 , x_mtl_reservation_tbl => l_rsv_tbl
4488 , x_mtl_reservation_tbl_count => l_count
4489 , x_error_code => l_x_error_code
4490 , p_lock_records => l_lock_records
4491 , p_sort_by_req_date => l_sort_by_req_date
4492 );
4493
4494 IF l_debug_level > 0 THEN
4495 oe_debug_pub.add( 'AFTER CALLING INVS QUERY_RESERVATION: ' || L_RETURN_STATUS , 1 ) ;
4496 END IF;
4497
4498 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4499 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4500 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4501 RAISE FND_API.G_EXC_ERROR;
4502 END IF;
4503
4504 IF l_debug_level > 0 THEN
4505 oe_debug_pub.add( 'RESERVATION RECORD COUNT IS: ' || L_RSV_TBL.COUNT , 1 ) ;
4506 END IF;
4507
4508 -- Let's get the total reserved_quantity
4509 FOR K IN 1..l_rsv_tbl.count LOOP
4510
4511 l_reservation_rec := l_rsv_tbl(K);
4512 l_reservation_rec.requirement_date := l_out_line_rec.schedule_ship_date;
4513
4514 IF l_debug_level > 0 THEN
4515 oe_debug_pub.add( 'RSCH: CALLING INVS UPDATE RESERVATION ' , 1 ) ;
4516 END IF;
4517 inv_reservation_pub.update_reservation
4518 ( p_api_version_number => 1.0
4519 , p_init_msg_lst => fnd_api.g_true
4520 , x_return_status => l_return_status
4521 , x_msg_count => l_msg_count
4522 , x_msg_data => l_msg_data
4523 , p_original_rsv_rec => l_rsv_tbl(k)
4524 , p_to_rsv_rec => l_reservation_rec
4525 , p_original_serial_number => l_dummy_sn -- no serial contorl
4526 , p_to_serial_number => l_dummy_sn -- no serial control
4527 , p_validation_flag => fnd_api.g_true
4528 );
4529
4530 IF l_debug_level > 0 THEN
4531 oe_debug_pub.add( 'AFTER CALLING INVS UPDATE_RESERVATION: ' || L_RETURN_STATUS , 1 ) ;
4532 END IF;
4533
4534 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4535 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4536 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4537 IF l_msg_data is not null THEN
4538 fnd_message.set_encoded(l_msg_data);
4539 l_buffer := fnd_message.get;
4540 oe_msg_pub.add_text(p_message_text => l_buffer);
4541 IF l_debug_level > 0 THEN
4542 oe_debug_pub.add( 'ERROR : '|| L_BUFFER , 1 ) ;
4543 END IF;
4544 END IF;
4545 RAISE FND_API.G_EXC_ERROR;
4546 END IF;
4547 END LOOP;
4548
4549 END IF;
4550
4551 -- End code for bug 2126165.
4552
4553 IF nvl(l_line_rec.shippable_flag,'N') = 'Y'
4554 THEN
4555 -- This check will avoid calling reservation for
4556 -- non-shippable items.
4557
4558 -- Inv code expect the item to be available in database before
4559 -- making reservation. If the reservation is being made due to
4560 -- change in inventory_item_id, we will move the reservation
4561 -- call to post_write. -- 1913263.
4562
4563 IF (NOT OE_GLOBALS.Equal(l_line_rec.inventory_item_id,
4564 l_old_line_rec.inventory_item_id) OR
4565 NOT OE_GLOBALS.Equal(l_line_rec.ship_from_org_id,
4566 l_old_line_rec.ship_from_org_id)) AND
4567 l_re_reserve_flag = 'Y' THEN
4568
4569 IF l_debug_level > 0 THEN
4570 oe_debug_pub.add( 'NO RE-RESERVE DUE TO ITEM/WAREHOUSE CHANGE' , 1 ) ;
4571 END IF;
4572 goto end_of_processing;
4573
4574 END IF;
4575
4576 -- Call INV to create reservation if the line
4577 -- was previously reserved.
4578
4579 IF l_debug_level > 0 THEN
4580 oe_debug_pub.add( 'BEFORE RESERVATION CHECK' , 1 ) ;
4581 END IF;
4582
4583 IF (l_line_rec.reserved_quantity IS NOT NULL
4584 OR ((sch_cached_sch_level_code = SCH_LEVEL_THREE OR
4585 sch_cached_sch_level_code is null)
4586 AND Within_Rsv_Time_Fence(l_out_line_rec.schedule_ship_date)))
4587 AND l_re_reserve_flag = 'Y'
4588 THEN
4589 -- Create INV record from the line to reserve
4590
4591 IF l_line_rec.reserved_quantity is not null AND
4592 OE_GLOBALS.Equal(p_x_line_rec.order_quantity_uom,
4593 p_old_line_rec.order_quantity_uom)
4594 THEN
4595 --If quantity and request(any scheduling dates) changed, system
4596 --is re_reserving based on the reserved qty, even when qty is
4597 --is decresed. Modified to take ordered qty when it is less than
4598 --previously reserved qty.
4599
4600 IF l_line_rec.reserved_quantity > p_x_line_rec.ordered_quantity
4601 THEN
4602 l_qty_to_reserve := p_x_line_rec.ordered_quantity;
4603 ELSE
4604 l_qty_to_reserve := l_line_rec.reserved_quantity;
4605 END IF;
4606
4607 IF l_line_rec.reserved_quantity2 > p_x_line_rec.ordered_quantity2 -- INVCONV
4608 THEN
4609 l_qty2_to_reserve := p_x_line_rec.ordered_quantity2;
4610 ELSE
4611 l_qty2_to_reserve := l_line_rec.reserved_quantity2;
4612 END IF;
4613
4614
4615 ELSE
4616 l_qty_to_reserve := p_x_line_rec.ordered_quantity;
4617 l_qty2_to_reserve := p_x_line_rec.ordered_quantity2; -- INVCONV
4618 END IF;
4619
4620 -- Load the INV record
4621
4622 SELECT RESERVABLE_TYPE
4623 INTO l_reservable_type
4624 FROM MTL_SYSTEM_ITEMS
4625 WHERE INVENTORY_ITEM_ID = l_line_rec.inventory_item_id
4626 AND ORGANIZATION_ID = l_line_rec.ship_from_org_id;
4627
4628 IF l_reservable_type <> 1 THEN
4629
4630 IF l_debug_level > 0 THEN
4631 oe_debug_pub.add( 'NON RESERVABLE ITEM RESERVATION NOT REQUIRED '||L_RESERVABLE_TYPE , 3 ) ;
4632 END IF;
4633 GOTO NO_RESERVATION;
4634 END IF;
4635
4636 --newsub check if item is under lot/revision/serial control
4637 IF l_line_rec.subinventory is not null
4638 AND l_line_rec.subinventory <> FND_API.G_MISS_CHAR THEN
4639 BEGIN
4640 SELECT revision_qty_control_code, lot_control_code,
4641 serial_number_control_code
4642 INTO l_revision_code, l_lot_code, l_serial_code
4643 FROM mtl_system_items
4644 WHERE inventory_item_id = l_line_rec.inventory_item_id
4645 AND organization_id = l_line_rec.ship_from_org_id;
4646
4647 EXCEPTION
4648 WHEN OTHERS THEN
4649 l_return_status := FND_API.G_RET_STS_ERROR;
4650 fnd_message.set_name('ONT', 'OE_INVALID_ITEM_WHSE');
4651 OE_MSG_PUB.Add;
4652 END;
4653
4654
4655 IF l_revision_code = 2 OR l_lot_code = 2 THEN
4656 -- 2 == YES
4657 fnd_message.set_name('ONT', 'OE_SUBINV_NOT_ALLOWED');
4658 OE_MSG_PUB.Add;
4659 IF l_line_rec.schedule_action_code = OESCH_ACT_RESERVE THEN
4660 l_return_status := FND_API.G_RET_STS_ERROR;
4661 RAISE FND_API.G_EXC_ERROR;
4662 ELSE
4663 l_return_status := FND_API.G_RET_STS_SUCCESS;
4664 l_quantity_reserved := null;
4665 l_quantity2_reserved := null; -- INVCONV
4666 GOTO NO_RESERVATION;
4667 END IF;
4668
4669 END IF;
4670 END IF;
4671 --end newsub
4672
4673 IF l_debug_level > 0 THEN
4674 oe_debug_pub.add( 'CALLING LOAD_INV_REQUEST' , 1 ) ;
4675 END IF;
4676
4677 Load_INV_Request
4678 ( p_line_rec => l_line_rec
4679 , p_quantity_to_reserve => l_qty_to_reserve
4680 , p_quantity2_to_reserve => l_qty2_to_reserve -- INVCONV
4681 , x_reservation_rec => l_reservation_rec);
4682
4683 -- Call INV with action = RESERVE
4684
4685 IF l_debug_level > 0 THEN
4686 oe_debug_pub.add( 'CALLING INVS CREATE_RESERVATION' , 1 ) ;
4687 END IF;
4688
4689 inv_reservation_pub.create_reservation
4690 (
4691 p_api_version_number => 1.0
4692 , p_init_msg_lst => FND_API.G_TRUE
4693 , x_return_status => l_return_status
4694 , x_msg_count => l_msg_count
4695 , x_msg_data => l_msg_data
4696 , p_rsv_rec => l_reservation_rec
4697 , p_serial_number => l_dummy_sn
4698 , x_serial_number => l_dummy_sn
4699 , p_partial_reservation_flag => FND_API.G_FALSE
4700 , p_force_reservation_flag => FND_API.G_FALSE
4701 , p_validation_flag => FND_API.G_TRUE
4702 , x_quantity_reserved => l_quantity_reserved
4703 , x_secondary_quantity_reserved => l_quantity2_reserved -- INVCONV
4704 , x_reservation_id => l_rsv_id
4705 );
4706
4707 IF l_debug_level > 0 THEN
4708 oe_debug_pub.add( '2. AFTER CALLING CREATE RESERVATION' || L_RETURN_STATUS , 1 ) ;
4709 END IF;
4710 -- Bug No:2097933
4711 -- If the Reservation was succesfull we set
4712 -- the package variable to "Y".
4713 IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
4714 OESCH_PERFORMED_RESERVATION := 'Y';
4715 END IF;
4716 IF l_debug_level > 0 THEN
4717 oe_debug_pub.add( L_MSG_DATA , 1 ) ;
4718 END IF;
4719
4720 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4721 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4722 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4723 IF l_msg_data is not null THEN
4724 fnd_message.set_encoded(l_msg_data);
4725 l_buffer := fnd_message.get;
4726 oe_msg_pub.add_text(p_message_text => l_buffer);
4727 END IF;
4728
4729 IF l_line_rec.Schedule_action_code = OESCH_ACT_RESERVE THEN
4730 RAISE FND_API.G_EXC_ERROR;
4731 ELSE
4732 l_return_status := FND_API.G_RET_STS_SUCCESS;
4733 IF l_debug_level > 0 THEN
4734 oe_debug_pub.add( 'UNABLE TO RESERVE' , 2 ) ;
4735 END IF;
4736 END IF;
4737
4738 END IF;
4739
4740 IF l_debug_level > 0 THEN
4741 oe_debug_pub.add( 'AFTER CALLING INVS CREATE_RESERVATION' , 1 ) ;
4742 END IF;
4743
4744 << NO_RESERVATION >>
4745 NULL;
4746
4747 END IF;
4748 END IF; -- Check for shippable flag.
4749
4750
4751 -- Added this part of the code to fix bug 2536435
4752 -- Code to handle reserved quantity
4753 IF l_old_line_rec.reserved_quantity is null OR
4754 l_old_line_rec.reserved_quantity = FND_API.G_MISS_NUM THEN
4755 l_old_line_rec.reserved_quantity := 0;
4756 END IF;
4757 IF l_old_line_rec.reserved_quantity2 is null OR -- INVCONV
4758 l_old_line_rec.reserved_quantity2 = FND_API.G_MISS_NUM THEN
4759 l_old_line_rec.reserved_quantity2 := 0;
4760 END IF;
4761
4762
4763
4764 IF l_line_rec.ordered_quantity >= l_line_rec.reserved_quantity THEN
4765
4766 -- After the changes are made to the order, the order qty is still
4767 -- greater than the reserved quantity. This is a valid change.
4768
4769 l_changed_reserved_qty := l_old_line_rec.reserved_quantity -
4770 l_line_rec.reserved_quantity;
4771
4772 IF l_changed_reserved_qty > 0 THEN
4773 -- this definitely is a reserved_quantity decrement
4774 -- CMS is not touching this explicit rsv qty decrease
4775 IF nvl(l_line_rec.shipping_interfaced_flag, 'N') = 'N' THEN
4776
4777 IF l_debug_level > 0 THEN
4778 oe_debug_pub.add( '1 RESERVED QUANTITY HAS DECREASED' , 1 ) ;
4779 END IF;
4780
4781
4782 l_qty_to_unreserve := l_old_line_rec.reserved_quantity -
4783 l_line_rec.reserved_quantity;
4784 l_qty2_to_unreserve := nvl(l_old_line_rec.reserved_quantity2, 0) - -- INVCONV
4785 nvl(l_line_rec.reserved_quantity, 0);
4786
4787
4788 -- No need to pass old record. Since this is a change
4789 -- due to quantity.
4790 Unreserve_Line
4791 ( p_line_rec => l_line_rec
4792 , p_quantity_to_unreserve => l_qty_to_unreserve
4793 , p_quantity2_to_unreserve => l_qty2_to_unreserve -- INVCONV
4794 , x_return_status => l_return_status);
4795
4796 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4797 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4798 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4799 RAISE FND_API.G_EXC_ERROR;
4800 END IF;
4801
4802 ELSE
4803
4804 IF l_debug_level > 0 THEN
4805 oe_debug_pub.add( '1 RESERVED QTY HAS DECREASED , WSH INTERFACED' , 1 ) ;
4806 END IF;
4807 -- Reservation qty cannot be reduced when line is
4808 -- interfaced to wsh.
4809 -- Give a message here tell the user we are not unreserving
4810 -- Added code here to fix bug 2038201.
4811 FND_MESSAGE.SET_NAME('ONT','OE_SCH_UNRSV_NOT_ALLOWED');
4812 OE_MSG_PUB.Add;
4813
4814 goto end_of_processing;
4815
4816
4817 END IF;
4818
4819 ELSIF l_changed_reserved_qty < 0 THEN
4820
4821 IF l_debug_level > 0 THEN
4822 oe_debug_pub.add( '1 RESERVED QUANTITY HAS INCREASED' , 1 ) ;
4823 END IF;
4824
4825 l_qty_to_reserve := l_line_rec.reserved_quantity -
4826 l_old_line_rec.reserved_quantity;
4827
4828 l_qty2_to_reserve := nvl(l_line_rec.reserved_quantity2, 0) - -- INVCONV
4829 nvl(l_old_line_rec.reserved_quantity2, 0);
4830
4831 Action_Schedule(p_x_line_rec => l_line_rec,
4832 p_old_line_rec => l_old_line_rec,
4833 p_action => OESCH_ACT_SCHEDULE,
4834 p_qty_to_reserve => l_qty_to_reserve,
4835 p_qty2_to_reserve => l_qty2_to_reserve, -- INVCONV
4836 x_return_status => l_return_status);
4837
4838 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4839 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4840 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4841 RAISE FND_API.G_EXC_ERROR;
4842 END IF;
4843
4844 --Added this stmt to fix bug 1800048(2).
4845 goto end_of_processing;
4846 END IF; /* end of reserved_quantity change code */
4847
4848
4849 ELSE
4850 /* ordered_quantity < reserved_quantity. If this has happened
4851 due to ordered_quantity had decreased and reserved_quantity has
4852 remained the same, then it is a valid change. We will just unreserve
4853 the difference */
4854
4855 l_qty_to_unreserve := l_line_rec.reserved_quantity -
4856 l_line_rec.ordered_quantity;
4857
4858 l_qty2_to_unreserve := nvl(l_line_rec.reserved_quantity2, 0) - --INVCONV
4859 nvl(l_line_rec.ordered_quantity2, 0) ;
4860
4861 IF l_changed_reserved_qty = 0 and
4862 nvl(l_line_rec.shipping_interfaced_flag, 'N') = 'N' and
4863 l_qty_to_unreserve > 0 THEN
4864
4865 -- We dont need to change the record to old.
4866 Unreserve_Line
4867 ( p_line_rec => l_line_rec
4868 , p_quantity_to_unreserve => l_qty_to_unreserve
4869 , p_quantity2_to_unreserve => l_qty2_to_unreserve -- INVCONV
4870 , x_return_status => l_return_status);
4871
4872 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4873 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4874 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4875 RAISE FND_API.G_EXC_ERROR;
4876 END IF;
4877
4878 END IF; /* reserved_quantity same, ordered_quantity changed*/
4879
4880 END IF; /* Quantity change handling code ends */
4881
4882 goto end_of_processing;
4883 END IF /* IF scheduling attributes changed */;
4884
4885
4886 /* IF ordered_quantity and/or reserved_quantity changed. */
4887
4888 IF l_old_line_rec.reserved_quantity is null OR
4889 l_old_line_rec.reserved_quantity = FND_API.G_MISS_NUM THEN
4890 l_old_line_rec.reserved_quantity := 0;
4891 END IF;
4892
4893 IF l_line_rec.reserved_quantity is null OR
4894 l_line_rec.reserved_quantity = FND_API.G_MISS_NUM THEN
4895 l_line_rec.reserved_quantity := 0;
4896 END IF;
4897
4898 l_changed_ordered_qty := l_old_line_rec.ordered_quantity -
4899 l_line_rec.ordered_quantity;
4900
4901 IF l_old_line_rec.reserved_quantity2 is null OR -- INVCONV
4902 l_old_line_rec.reserved_quantity2 = FND_API.G_MISS_NUM THEN
4903 l_old_line_rec.reserved_quantity2 := 0;
4904 END IF;
4905
4906 IF l_line_rec.reserved_quantity2 is null OR
4907 l_line_rec.reserved_quantity2 = FND_API.G_MISS_NUM THEN
4908 l_line_rec.reserved_quantity2 := 0;
4909 END IF;
4910
4911 l_changed_ordered_qty2 := l_old_line_rec.ordered_quantity2 -
4912 l_line_rec.ordered_quantity2;
4913
4914
4915 IF l_changed_ordered_qty <> 0 THEN
4916
4917 /* ordered_quantity has changed. Set the flag G_LINE_PART_OF_SET
4918 if the line belongs to a ship or arrival set */
4919
4920 IF l_line_rec.ship_set_id is not null OR
4921 l_line_rec.arrival_set_id is not null THEN
4922 G_LINE_PART_OF_SET := TRUE;
4923 END IF;
4924
4925 IF l_changed_ordered_qty > 0 THEN
4926
4927 IF l_debug_level > 0 THEN
4928 oe_debug_pub.add( 'ORDERED QUANTITY HAS DECREASED' , 1 ) ;
4929 END IF;
4930
4931 IF l_line_rec.ordered_quantity = 0 THEN
4932 -- Since ordered quantity is now 0, undemand
4933 -- Call MRP with action = UNDEMAND
4934
4935 IF l_debug_level > 0 THEN
4936 oe_debug_pub.add( 'CALLING MRP WITH THE ACTION OF UNDEMAND' , 1 ) ;
4937 END IF;
4938 l_line_rec.schedule_action_code := OESCH_ACT_UNDEMAND;
4939 ELSE
4940 IF l_debug_level > 0 THEN
4941 oe_debug_pub.add( 'CALLING MRP WITH THE ACTION OF REDEMAND' , 1 ) ;
4942 END IF;
4943 l_line_rec.schedule_action_code := OESCH_ACT_REDEMAND;
4944 END IF;
4945
4946 ELSIF l_changed_ordered_qty < 0 THEN
4947
4948 IF l_debug_level > 0 THEN
4949 oe_debug_pub.add( 'ORDERED QUANTITY HAS INCRESED' , 1 ) ;
4950 END IF;
4951
4952 -- Assuming that change in quantity will take place only in the
4953 -- warehouse where the quantity was previously scheduled.
4954 -- Since ordered quantity is incresed, ATP check and redemand
4955 -- Call MRP with action = REDEMAND
4956
4957 IF l_debug_level > 0 THEN
4958 oe_debug_pub.add( 'CALLING MRP WITH THE ACTION OF REDEMAND' , 1 ) ;
4959 END IF;
4960 l_line_rec.schedule_action_code := OESCH_ACT_REDEMAND;
4961
4962 END IF;
4963
4964 l_line_tbl(1) := l_line_rec;
4965 l_old_line_tbl(1) := l_old_line_rec;
4966
4967 Load_MRP_Request
4968 ( p_line_tbl => l_line_tbl
4969 , p_old_line_tbl => l_old_line_tbl
4970 , x_atp_table => l_mrp_atp_rec);
4971
4972 l_session_id := Get_Session_Id;
4973
4974 -- Call ATP
4975
4976 IF l_debug_level > 0 THEN
4977 oe_debug_pub.add( '1. CALLING MRP API WITH SESSION ID '||L_SESSION_ID , 1 ) ;
4978 END IF;
4979
4980 MRP_ATP_PUB.Call_ATP
4981 ( p_session_id => l_session_id
4982 , p_atp_rec => l_mrp_atp_rec
4983 , x_atp_rec => l_out_mtp_atp_rec
4984 , x_atp_supply_demand => l_atp_supply_demand
4985 , x_atp_period => l_atp_period
4986 , x_atp_details => l_atp_details
4987 , x_return_status => l_return_status
4988 , x_msg_data => mrp_msg_data
4989 , x_msg_count => l_msg_count);
4990
4991
4992 IF l_debug_level > 0 THEN
4993 oe_debug_pub.add( '4. AFTER CALLING MRP_ATP_PUB.CALL_ATP' || L_RETURN_STATUS , 1 ) ;
4994 END IF;
4995
4996 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4997 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4998 END IF;
4999
5000 Load_Results
5001 ( p_atp_table => l_out_mtp_atp_rec
5002 , p_x_line_tbl => l_line_tbl
5003 , x_atp_tbl => l_out_atp_tbl
5004 , x_return_status => l_return_status);
5005
5006 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5007 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5008 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5009 RAISE FND_API.G_EXC_ERROR;
5010 END IF;
5011
5012 l_out_line_rec := l_line_tbl(1);
5013
5014 END IF; /* If l_changed_ordered_qty <> 0 */
5015
5016 -- Code to handle reserved quantity
5017
5018 IF l_line_rec.ordered_quantity >= l_line_rec.reserved_quantity THEN
5019
5020 -- After the changes are made to the order, the order qty is still
5021 -- greater than the reserved quantity. This is a valid change.
5022
5023 l_changed_reserved_qty := l_old_line_rec.reserved_quantity -
5024 l_line_rec.reserved_quantity;
5025
5026 IF l_changed_reserved_qty > 0 THEN
5027 -- this definitely is a reserved_quantity decrement
5028 -- CMS is not touching this explicit rsv qty decrease
5029 IF nvl(l_line_rec.shipping_interfaced_flag, 'N') = 'N' THEN
5030
5031 IF l_debug_level > 0 THEN
5032 oe_debug_pub.add( 'RESERVED QUANTITY HAS DECREASED' , 1 ) ;
5033 END IF;
5034
5035
5036 l_qty_to_unreserve := l_old_line_rec.reserved_quantity -
5037 l_line_rec.reserved_quantity;
5038 l_qty2_to_unreserve := nvl(l_old_line_rec.reserved_quantity2, 0) - -- INVCONV
5039 nvl(l_line_rec.reserved_quantity2, 0) ;
5040
5041
5042 -- No need to pass old record. Since this is a change
5043 -- due to quantity.
5044 Unreserve_Line
5045 ( p_line_rec => l_line_rec
5046 , p_quantity_to_unreserve => l_qty_to_unreserve
5047 , p_quantity2_to_unreserve => l_qty2_to_unreserve -- INVCONV
5048 , x_return_status => l_return_status);
5049
5050
5051 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5052 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5053 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5054 RAISE FND_API.G_EXC_ERROR;
5055 END IF;
5056
5057 ELSE
5058
5059 IF l_debug_level > 0 THEN
5060 oe_debug_pub.add( 'RESERVED QTY HAS DECREASED , WSH INTERFACED' , 1 ) ;
5061 END IF;
5062 -- Reservation qty cannot be reduced when line is
5063 -- interfaced to wsh.
5064 -- Give a message here tell the user we are not unreserving
5065 -- Added code here to fix bug 2038201.
5066 FND_MESSAGE.SET_NAME('ONT','OE_SCH_UNRSV_NOT_ALLOWED');
5067 OE_MSG_PUB.Add;
5068
5069 goto end_of_processing;
5070
5071
5072 END IF;
5073
5074 ELSIF l_changed_reserved_qty < 0 THEN
5075
5076 IF l_debug_level > 0 THEN
5077 oe_debug_pub.add( 'RESERVED QUANTITY HAS INCREASED' , 1 ) ;
5078 END IF;
5079
5080 l_qty_to_reserve := l_line_rec.reserved_quantity -
5081 l_old_line_rec.reserved_quantity;
5082
5083 l_qty2_to_reserve := nvl(l_line_rec.reserved_quantity2, 0) - -- INVCONV
5084 nvl(l_old_line_rec.reserved_quantity2, 0);
5085 l_out_line_rec := l_line_rec;
5086 Action_Schedule(p_x_line_rec => l_out_line_rec,
5087 p_old_line_rec => l_old_line_rec,
5088 p_action => OESCH_ACT_SCHEDULE,
5089 p_qty_to_reserve => l_qty_to_reserve,
5090 p_qty2_to_reserve => l_qty2_to_reserve, -- INVCONV
5091 x_return_status => l_return_status);
5092
5093 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5094 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5095 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5096 RAISE FND_API.G_EXC_ERROR;
5097 END IF;
5098
5099 --Added this stmt to fix bug 1800048(2).
5100 goto end_of_processing;
5101 END IF; /* end of reserved_quantity change code */
5102
5103
5104 ELSE
5105 /* ordered_quantity < reserved_quantity. If this has happened
5106 due to ordered_quantity had decreased and reserved_quantity has
5107 remained the same, then it is a valid change. We will just unreserve
5108 the difference */
5109
5110 l_qty_to_unreserve := l_line_rec.reserved_quantity -
5111 l_line_rec.ordered_quantity;
5112 l_qty2_to_unreserve := nvl(l_line_rec.reserved_quantity2, 0) - -- INVCONV
5113 nvl(l_line_rec.ordered_quantity2, 0);
5114
5115
5116 IF l_changed_reserved_qty = 0 and
5117 nvl(l_line_rec.shipping_interfaced_flag, 'N') = 'N' and
5118 l_qty_to_unreserve > 0 THEN
5119
5120 -- We dont need to change the record to old.
5121 Unreserve_Line
5122 ( p_line_rec => l_line_rec
5123 , p_quantity_to_unreserve => l_qty_to_unreserve
5124 , p_quantity2_to_unreserve => l_qty2_to_unreserve -- INVCONV
5125 , x_return_status => l_return_status);
5126
5127 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5128 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5129 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5130 RAISE FND_API.G_EXC_ERROR;
5131 END IF;
5132
5133 END IF; /* reserved_quantity same, ordered_quantity changed*/
5134 goto end_of_processing;
5135
5136 END IF; /* Quantity change handling code ends */
5137
5138 END IF; /* If the schedule_action_code was null */
5139
5140
5141
5142 IF l_debug_level > 0 THEN
5143 oe_debug_pub.add( 'STARTING THE BIG ELSE LOOP' , 1 ) ;
5144 oe_debug_pub.add( 'OPR: ' || L_LINE_REC.OPERATION , 1 ) ;
5145 END IF;
5146
5147 IF OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
5148 OESCH_ACT_UNRESERVE)
5149 THEN
5150
5151 -- Setting update flag to false, so that schedule_line does not
5152 -- process_order as unreserving does not cause any line attributes
5153 -- to change.
5154
5155 g_update_flag := FND_API.G_FALSE;
5156 -- CMS is not touching the following explicit unreserve logic
5157
5158 IF (l_old_line_rec.reserved_quantity is not null AND
5159 l_old_line_rec.reserved_quantity <> FND_API.G_MISS_NUM)
5160 THEN
5161 IF nvl(l_line_rec.shipping_interfaced_flag, 'N') = 'N' THEN
5162
5163 l_out_line_rec := l_line_rec;
5164 Action_UnSchedule(p_x_line_rec => l_out_line_rec,
5165 p_old_line_rec => l_old_line_rec,
5166 p_action => OESCH_ACT_UNRESERVE,
5167 x_return_status => l_return_status);
5168
5169 goto end_of_processing;
5170 ELSE
5171 -- Action_Unschedule will only unreserve if not interfaced to WSH
5172 -- Give a message here tell the user we are not unreserving
5173 FND_MESSAGE.SET_NAME('ONT','OE_SCH_UNRSV_NOT_ALLOWED');
5174 OE_MSG_PUB.Add;
5175 goto end_of_processing;
5176 END IF;
5177
5178 ELSE
5179 FND_MESSAGE.SET_NAME('ONT','OE_SCH_NO_ACTION_DONE_NO_EXP');
5180 OE_MSG_PUB.Add;
5181 goto end_of_processing;
5182 END IF;
5183
5184 -- schedule_action_code --> OESCH_ACT_UNDEMAND
5185 ELSIF OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
5186 OESCH_ACT_UNDEMAND)
5187 THEN
5188 IF OE_GLOBALS.Equal(l_line_rec.schedule_status_code,
5189 OESCH_STATUS_DEMANDED) THEN
5190
5191 l_out_line_rec := l_line_rec;
5192 Action_UnSchedule(p_x_line_rec => l_out_line_rec,
5193 p_old_line_rec => l_old_line_rec,
5194 p_action => OESCH_ACT_UNDEMAND,
5195 x_return_status => l_return_status);
5196
5197 goto end_of_processing;
5198
5199 ELSE
5200 FND_MESSAGE.SET_NAME('ONT','OE_SCH_NO_ACTION_DONE_NO_EXP');
5201 OE_MSG_PUB.Add;
5202 goto end_of_processing;
5203 END IF;
5204
5205
5206 --schedule_action_code --> OESCH_ACT_UNSCHEDULE
5207 ELSIF OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
5208 OESCH_ACT_UNSCHEDULE)
5209 THEN
5210
5211 l_out_line_rec := l_line_rec;
5212 Action_UnSchedule(p_x_line_rec => l_out_line_rec,
5213 p_old_line_rec => l_old_line_rec,
5214 p_action => OESCH_ACT_UNSCHEDULE,
5215 x_return_status => l_return_status);
5216
5217 goto end_of_processing;
5218
5219
5220 --l_line_rec.schedule_action_code --> OESCH_ACT_ATP_CHECK
5221 ELSIF OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
5222 OESCH_ACT_ATP_CHECK)
5223 THEN
5224
5225 IF l_debug_level > 0 THEN
5226 oe_debug_pub.add( 'ACTION REQUESTED IS OESCH_ACT_ATP_CHECK' , 1 ) ;
5227 END IF;
5228 -- Call MRP API
5229
5230 l_line_tbl(1) := l_line_rec;
5231 l_old_line_tbl(1) := l_old_line_rec;
5232
5233 Load_MRP_Request
5234 ( p_line_tbl => l_line_tbl
5235 , p_old_line_tbl => l_old_line_tbl
5236 , x_atp_table => l_mrp_atp_rec);
5237
5238 l_session_id := Get_Session_Id;
5239
5240 -- Call ATP
5241
5242 IF l_debug_level > 0 THEN
5243 oe_debug_pub.add( '1. CALLING MRP API WITH SESSION ID '||L_SESSION_ID , 1 ) ;
5244 END IF;
5245
5246 MRP_ATP_PUB.Call_ATP
5247 ( p_session_id => l_session_id
5248 , p_atp_rec => l_mrp_atp_rec
5249 , x_atp_rec => l_out_mtp_atp_rec
5250 , x_atp_supply_demand => l_atp_supply_demand
5251 , x_atp_period => l_atp_period
5252 , x_atp_details => l_atp_details
5253 , x_return_status => l_return_status
5254 , x_msg_data => mrp_msg_data
5255 , x_msg_count => l_msg_count);
5256
5257
5258 IF l_debug_level > 0 THEN
5259 oe_debug_pub.add( '5. AFTER CALLING MRP_ATP_PUB.CALL_ATP' || L_RETURN_STATUS , 1 ) ;
5260 END IF;
5261 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5262 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5263 END IF;
5264
5265 Load_Results(p_atp_table => l_out_mtp_atp_rec,
5266 p_x_line_tbl => l_line_tbl,
5267 x_atp_tbl => l_out_atp_tbl,
5268 x_return_status => l_return_status);
5269
5270 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5271 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5272 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5273 RAISE FND_API.G_EXC_ERROR;
5274 END IF;
5275
5276 l_out_line_rec := l_line_tbl(1);
5277
5278 -- We also need to pass back on-hand qty and available_to_reserve
5279 -- qties while performing ATP. Getting these values from inventory.
5280
5281 FOR K IN 1..l_out_atp_tbl.count LOOP
5282 IF l_debug_level > 0 THEN
5283 oe_debug_pub.add( 'CALLING QUERY_QTY_TREE' , 1 ) ;
5284 END IF;
5285 Query_Qty_Tree(p_org_id => l_out_atp_tbl(K).ship_from_org_id,
5286 p_item_id => l_out_atp_tbl(K).inventory_item_id,
5287 p_line_id => l_out_atp_tbl(K).line_id,
5288 p_sch_date =>
5289 nvl(l_out_atp_tbl(K).group_available_date,
5290 l_out_atp_tbl(K).ordered_qty_Available_Date),
5291 x_on_hand_qty => l_on_hand_qty,
5292 x_avail_to_reserve => l_avail_to_reserve,
5293 x_on_hand_qty2 => l_on_hand_qty2, -- INVCONV
5294 x_avail_to_reserve2 => l_avail_to_reserve2 -- INVCONV
5295 );
5296
5297 /* -- added by fabdi 03/May/2001 INVCONV - NOT NEEDED NOW
5298 IF NOT INV_GMI_RSV_BRANCH.Process_Branch(p_organization_id => l_out_atp_tbl(K).ship_from_org_id)
5299 THEN
5300 l_process_flag := FND_API.G_FALSE;
5301 ELSE
5302 l_process_flag := FND_API.G_TRUE;
5303 END IF;
5304
5305 IF l_process_flag = FND_API.G_TRUE
5306 THEN
5307 l_out_atp_tbl(K).on_hand_qty := l_on_hand_qty;
5308 l_out_atp_tbl(K).available_to_reserve := l_avail_to_reserve;
5309 l_out_atp_tbl(K).QTY_ON_REQUEST_DATE := l_avail_to_reserve; -- Available field in ATP
5310
5311 IF l_debug_level > 0 THEN
5312 oe_debug_pub.add( 'L_ON_HAND_QTY' || L_ON_HAND_QTY ) ;
5313 oe_debug_pub.add( 'L_AVAIL_TO_RESERVE' || L_AVAIL_TO_RESERVE ) ;
5314 oe_debug_pub.add( 'AVAILABLE ' || L_AVAIL_TO_RESERVE ) ;
5315 END IF;
5316 else */
5317
5318 l_out_atp_tbl(K).on_hand_qty := l_on_hand_qty;
5319 -- l_out_atp_tbl(K).on_hand_qty2 :=l_on_hand_qty2; -- INVCONV PAL
5320 l_out_atp_tbl(K).available_to_reserve := l_avail_to_reserve;
5321 -- l_out_atp_tbl(K).available_to_reserve2 := l_avail_to_reserve2; -- INVCONV == PAL
5322 IF l_debug_level > 0 THEN
5323 oe_debug_pub.add( 'L_ON_HAND_QTY' || L_ON_HAND_QTY ) ;
5324 oe_debug_pub.add( 'L_AVAIL_TO_RESERVE' || L_AVAIL_TO_RESERVE ) ;
5325 --oe_debug_pub.add( 'L_ON_HAND_QTY2' || L_ON_HAND_QTY2 ) ; -- INVCONV
5326 -- oe_debug_pub.add( 'L_AVAIL_TO_RESERVE2' || L_AVAIL_TO_RESERVE2 ) ;
5327 END IF;
5328 -- end if; -- INVCONV
5329 -- end fabdi
5330
5331 END LOOP;
5332
5333
5334 --l_line_rec.schedule_action_code --> OESCH_ACT_SOURC
5335 ELSIF OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
5336 OESCH_ACT_SOURCE)
5337 THEN
5338
5339 IF l_debug_level > 0 THEN
5340 oe_debug_pub.add( 'ACTION REQUESTED IS OESCH_ACT_SOURCE' , 1 ) ;
5341 END IF;
5342 IF (l_line_rec.ship_from_org_id IS NULL)
5343 THEN
5344 -- Call MRP API to get the source for the line
5345
5346 -- Since we do not have MRP API currently, the following
5347 -- line is a kludge to get the ship_from_org_id
5348
5349 l_out_line_rec.ship_from_org_id :=
5350 OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
5351
5352 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5353 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5354 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5355 RAISE FND_API.G_EXC_ERROR;
5356 END IF;
5357 ELSE
5358 null;
5359 goto end_of_processing;
5360 END IF;
5361
5362
5363 --l_line_rec.schedule_action_code --> OESCH_ACT_SCHEDULE
5364 /* ELSIF OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
5365 OESCH_ACT_SCHEDULE)
5366 THEN
5367 OE_DEBUG_PUB.ADD('Action Requested is OESCH_ACT_SCHEDULE',1);
5368
5369 l_out_line_rec := l_line_rec;
5370 Action_Schedule(p_x_line_rec => l_out_line_rec,
5371 p_old_line_rec => l_old_line_rec,
5372 p_action => OESCH_ACT_SCHEDULE,
5373 x_return_status => l_return_status);
5374
5375 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5376 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5377 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5378 RAISE FND_API.G_EXC_ERROR;
5379 END IF;
5380 */
5381 ELSIF OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
5382 OESCH_ACT_SCHEDULE)
5383 THEN
5384 IF l_debug_level > 0 THEN
5385 oe_debug_pub.add( 'ACTION REQUESTED IS OESCH_ACT_SCHEDULE' , 1 ) ;
5386 END IF;
5387
5388 -- We will check to see if the status is not null. If the status
5389 -- is not null, it means that the line is either demanded or reserved.
5390 -- In this case, we will not need to perform the action of DEMAND.
5391
5392 --Commenting this code not to display the message when
5393 --scheduled inclued lines being re-scheduled through schedule_parent-line.
5394 IF (l_line_rec.schedule_status_code IS NOT NULL) THEN
5395 /* FND_MESSAGE.SET_NAME('ONT','OE_SCH_NO_ACTION_DONE_NO_EXP');
5396 OE_MSG_PUB.Add;*/
5397 IF l_debug_level > 0 THEN
5398 oe_debug_pub.add( ' SCHEDULED LINE , GOTO END OF PROCESSING' , 3 ) ;
5399 END IF;
5400 goto end_of_processing;
5401 END IF;
5402
5403 -- The line is not scheduled, so go ahead and schedule the line
5404
5405 l_out_line_rec := l_line_rec;
5406 Action_Schedule(p_x_line_rec => l_out_line_rec,
5407 p_old_line_rec => l_old_line_rec,
5408 p_action => OESCH_ACT_SCHEDULE,
5409 x_return_status => l_return_status);
5410
5411 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5412 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5413 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5414 RAISE FND_API.G_EXC_ERROR;
5415 END IF;
5416
5417
5418
5419 --l_line_rec.schedule_action_code --> OESCH_ACT_RESERVE
5420 ELSIF OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
5421 OESCH_ACT_RESERVE)
5422 THEN
5423 IF l_debug_level > 0 THEN
5424 oe_debug_pub.add( 'ACTION IS RESERVE' , 1 ) ;
5425 END IF;
5426
5427 IF OE_GLOBALS.Equal(l_line_rec.ordered_quantity,
5428 l_line_rec.reserved_quantity) THEN
5429 FND_MESSAGE.SET_NAME('ONT','OE_SCH_NO_ACTION_DONE_NO_EXP');
5430 OE_MSG_PUB.Add;
5431 goto end_of_processing;
5432
5433 END IF;
5434
5435 l_out_line_rec := l_line_rec;
5436 Action_Schedule(p_x_line_rec => l_out_line_rec,
5437 p_old_line_rec => l_old_line_rec,
5438 p_action => OESCH_ACT_RESERVE,
5439 x_return_status => l_return_status);
5440
5441 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5442 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5443 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5444 RAISE FND_API.G_EXC_ERROR;
5445 END IF;
5446
5447 -- autoschedule flag is Y
5448 ELSIF (OESCH_AUTO_SCH_FLAG = 'Y') AND
5449 l_line_rec.operation = OE_GLOBALS.G_OPR_CREATE
5450 THEN
5451 -- We are taking care of autoscheduling only if scheduling_action
5452 -- code is null. If the action code has a value, we will perform
5453 -- that action instead of autoscheduling. Thus this check is done
5454 -- after all other checks are taken care of.
5455
5456 -- If the line quantity is 0 (the line maybe cancelled or the
5457 -- quantity was assigned zero) , then we do not need to perform
5458 -- any scheduling action.
5459
5460 IF (l_line_rec.ordered_quantity = 0) THEN
5461 -- Assigning l_out_line_rec the same values as that
5462 -- l_line_rec.
5463
5464 l_out_line_rec := l_line_rec;
5465 goto end_of_processing;
5466
5467 END IF;
5468
5469 IF (l_line_rec.item_type_code <> OE_GLOBALS.G_ITEM_STANDARD) THEN
5470 -- Assigning l_out_line_rec the same values as that
5471 -- l_line_rec.
5472
5473 l_out_line_rec := l_line_rec;
5474 goto end_of_processing;
5475
5476 END IF;
5477
5478 -- Check to see the scheduling level for this order line.
5479 -- If the scheduling_level does not allow performing any scheduling
5480 -- then do not perform scheduling.
5481
5482 IF (sch_cached_sch_level_code = SCH_LEVEL_ONE) THEN
5483 l_out_line_rec := l_line_rec;
5484 goto end_of_processing;
5485 END IF;
5486
5487 IF l_debug_level > 0 THEN
5488 oe_debug_pub.add( 'PERFORMING ACTION SCHEDULE' , 1 ) ;
5489 END IF;
5490
5491 l_line_rec.schedule_action_code := OESCH_ACT_SCHEDULE;
5492
5493 l_out_line_rec := l_line_rec;
5494 Action_Schedule(p_x_line_rec => l_out_line_rec,
5495 p_old_line_rec => l_old_line_rec,
5496 p_action => OESCH_ACT_SCHEDULE,
5497 x_return_status => l_return_status);
5498
5499 IF l_debug_level > 0 THEN
5500 oe_debug_pub.add( 'AFTER ACTION SCHEDULE : ' || L_RETURN_STATUS , 1 ) ;
5501 END IF;
5502
5503 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5504 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5505 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5506 -- We donot want to error out the insert if autoscheduling
5507 -- failed. So we will return success.
5508 -- We also do not want to do any update, so we will set
5509 -- the g_update_flag to FALSE.
5510 g_update_flag := FND_API.G_FALSE;
5511 l_return_status := FND_API.G_RET_STS_SUCCESS;
5512 END IF;
5513
5514 END IF;
5515
5516
5517 <<end_of_processing>>
5518 x_return_status := l_return_status;
5519 p_x_line_rec := l_out_line_rec;
5520 x_out_atp_tbl := l_out_atp_tbl;
5521 IF l_debug_level > 0 THEN
5522 oe_debug_pub.add( 'EXITING OE_ORDER_SCH_UTIL.PROCESS_REQUEST: ' || X_RETURN_STATUS , 1 ) ;
5523 END IF;
5524
5525 END Process_request;
5526
5527 /*-----------------------------------------------------------------------------
5528 Procedure Name : Initialize_mrp_record
5529 Description : This procedure create l_count records each for each table
5530 in the record of tables of MRP's p_atp_rec.
5531 ----------------------------------------------------------------------------- */
5532 Procedure Initialize_mrp_record(p_atp_rec IN MRP_ATP_PUB.ATP_Rec_Typ,
5533 l_count IN NUMBER,
5534 x_atp_rec OUT NOCOPY /* file.sql.39 change */ MRP_ATP_PUB.ATP_Rec_Typ)
5535 IS
5536 l_atp_rec MRP_ATP_PUB.ATP_Rec_Typ;
5537 --
5538 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5539 --
5540 BEGIN
5541
5542 IF l_debug_level > 0 THEN
5543 oe_debug_pub.add( 'EXTENDING THE TABLE BY ' || L_COUNT , 5 ) ;
5544 END IF;
5545 l_atp_rec := p_atp_rec;
5546 l_atp_rec.Inventory_Item_Id.extend(l_count);
5547 l_atp_rec.Source_Organization_Id.extend(l_count);
5548 l_atp_rec.Identifier.extend(l_count);
5549 l_atp_rec.Order_Number.extend(l_count);
5550 l_atp_rec.Calling_Module.extend(l_count);
5551 l_atp_rec.Customer_Id.extend(l_count);
5552 l_atp_rec.Customer_Site_Id.extend(l_count);
5553 l_atp_rec.Destination_Time_Zone.extend(l_count);
5554 l_atp_rec.Quantity_Ordered.extend(l_count);
5555 l_atp_rec.Quantity_UOM.extend(l_count);
5556 l_atp_rec.Requested_Ship_Date.extend(l_count);
5557 l_atp_rec.Requested_Arrival_Date.extend(l_count);
5558 l_atp_rec.Earliest_Acceptable_Date.extend(l_count);
5559 l_atp_rec.Latest_Acceptable_Date.extend(l_count);
5560 l_atp_rec.Delivery_Lead_Time.extend(l_count);
5561 l_atp_rec.Atp_Lead_Time.extend(l_count);
5562 l_atp_rec.Freight_Carrier.extend(l_count);
5563 l_atp_rec.Ship_Method.extend(l_count);
5564 l_atp_rec.Demand_Class.extend(l_count);
5565 l_atp_rec.Ship_Set_Name.extend(l_count);
5566 l_atp_rec.Arrival_Set_Name.extend(l_count);
5567 l_atp_rec.Override_Flag.extend(l_count);
5568 l_atp_rec.Action.extend(l_count);
5569 l_atp_rec.ship_date.extend(l_count);
5570 l_atp_rec.Available_Quantity.extend(l_count);
5571 l_atp_rec.Requested_Date_Quantity.extend(l_count);
5572 l_atp_rec.Group_Ship_Date.extend(l_count);
5573 l_atp_rec.Group_Arrival_Date.extend(l_count);
5574 l_atp_rec.Vendor_Id.extend(l_count);
5575 l_atp_rec.Vendor_Site_Id.extend(l_count);
5576 l_atp_rec.Insert_Flag.extend(l_count);
5577 l_atp_rec.Error_Code.extend(l_count);
5578 l_atp_rec.Message.extend(l_count);
5579 l_atp_rec.Old_Source_Organization_Id.extend(l_count);
5580 l_atp_rec.Old_Demand_Class.extend(l_count);
5581 l_atp_rec.oe_flag.extend(l_count);
5582 -- Added below attributes to fix bug 1912138.
5583 l_atp_rec.ato_delete_flag.extend(l_count);
5584 l_atp_rec.attribute_05.extend(l_count);
5585 l_atp_rec.attribute_01.extend(l_count);
5586 l_atp_rec.vendor_name.extend(l_count);
5587 x_atp_rec := l_atp_rec;
5588 END;
5589
5590 /*-----------------------------------------------------------------------------
5591 Procedure Name : Get_Lead_Time
5592 Description : This function returns the manufacturing lead team for ATO
5593 Options and Classes. While performing ATP, and scheduling
5594 for an ATO configuration, we just don't have to check
5595 the availability of the items, we also need to find out
5596 the amount of time it takes to build those items.
5597 This procedure gives the time it takes to build the ATO.
5598 It is standard formula which is used. The value is derived
5599 from the ATO model. Thus all options for a given model
5600 will have the same Lead Time.
5601 ----------------------------------------------------------------------------- */
5602 FUNCTION Get_Lead_Time
5603 ( p_ato_line_id IN NUMBER
5604 , p_ship_from_org_id IN NUMBER)
5605 RETURN NUMBER
5606 IS
5607 l_model_ordered_quantity NUMBER := 0;
5608 l_model_order_qty_uom NUMBER := 0;
5609 primary_model_qty NUMBER := 0;
5610 st_lead_time NUMBER := 0;
5611 db_full_lead_time NUMBER := 0;
5612 db_fixed_lead_time NUMBER := 0;
5613 db_variable_lead_time NUMBER := 0;
5614 db_primary_uom_code VARCHAR2(3);
5615 db_model_item_id NUMBER := 0;
5616 db_line_unit_code VARCHAR2(3);
5617 --
5618 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5619 --
5620 BEGIN
5621
5622 IF l_debug_level > 0 THEN
5623 oe_debug_pub.add( 'ENTERING GET_LEAD_TIME' , 1 ) ;
5624 oe_debug_pub.add( 'ATO LINE IS ' || P_ATO_LINE_ID , 1 ) ;
5625 oe_debug_pub.add( 'SHIP FROM IS ' || P_SHIP_FROM_ORG_ID , 1 ) ;
5626 END IF;
5627
5628 SELECT NVL ( MSI.FULL_LEAD_TIME , 0 )
5629 , NVL ( MSI.FIXED_LEAD_TIME , 0 )
5630 , NVL ( MSI.VARIABLE_LEAD_TIME , 0 )
5631 , MSI.PRIMARY_UOM_CODE
5632 , NVL ( OL.INVENTORY_ITEM_ID , 0 )
5633 , OL.order_quantity_uom
5634 , OL.ordered_quantity
5635 INTO db_full_lead_time
5636 , db_fixed_lead_time
5637 , db_variable_lead_time
5638 , db_primary_uom_code
5639 , db_model_item_id
5640 , db_line_unit_code
5641 , primary_model_qty
5642 FROM MTL_SYSTEM_ITEMS MSI
5643 , OE_ORDER_LINES OL
5644 WHERE MSI.INVENTORY_ITEM_ID = OL.INVENTORY_ITEM_ID
5645 AND MSI.ORGANIZATION_ID = p_ship_from_org_id
5646 AND OL.LINE_ID = p_ato_line_id ;
5647
5648
5649 -- Get the model quantity in primary UOM
5650
5651 -- Set the Lead time
5652
5653 st_lead_time := ceil( nvl(db_fixed_lead_time,0) + nvl(db_variable_lead_time,0)
5654 * nvl(primary_model_qty,0));
5655
5656 IF nvl(db_full_lead_time,0) > nvl(st_lead_time,0) THEN
5657 st_lead_time := ceil(db_full_lead_time);
5658 END IF;
5659
5660 RETURN st_lead_time;
5661 EXCEPTION
5662 WHEN NO_DATA_FOUND THEN
5663 RETURN 0;
5664 WHEN OTHERS THEN
5665 RETURN 0;
5666 END Get_Lead_Time;
5667
5668 /*-----------------------------------------------------------------------------
5669 Procedure Name : Get_Date_Type
5670 Description : This procedure returns the date type of the order.
5671 The date type could be SHIP or ARRIVAl or null. Null
5672 value is treated at SHIP in the scheduling code.
5673 -----------------------------------------------------------------------------*/
5674
5675 FUNCTION Get_Date_Type
5676 ( p_header_id IN NUMBER)
5677 RETURN VARCHAR2
5678 IS
5679 l_order_date_type_code VARCHAR2(30) := null;
5680 --
5681 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5682 --
5683 BEGIN
5684
5685 IF p_header_id <> nvl(G_HEADER_ID,0) THEN
5686 BEGIN
5687 SELECT order_date_type_code
5688 INTO l_order_date_type_code
5689 FROM oe_order_headers
5690 WHERE header_id = p_header_id;
5691
5692 G_HEADER_ID := p_header_id;
5693 G_DATE_TYPE := l_order_date_type_code;
5694 EXCEPTION
5695 WHEN OTHERS THEN
5696 RETURN null;
5697 END;
5698 ELSE
5699 l_order_date_type_code := G_DATE_TYPE;
5700 END IF;
5701
5702 RETURN l_order_date_type_code;
5703
5704 EXCEPTION
5705 WHEN NO_DATA_FOUND THEN
5706 RETURN NULL;
5707 END Get_Date_Type;
5708
5709 /*--------------------------------------------------------------------------
5710 Procedure Name : Get_Order_Number
5711 Description : This procedure returns the order_number from the header
5712 record, which we will pass to the MRP API.
5713 --------------------------------------------------------------------------*/
5714 FUNCTION Get_Order_Number(p_header_id in number)
5715 RETURN number
5716 IS
5717 l_order_number NUMBER;
5718 --
5719 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5720 --
5721 BEGIN
5722
5723 IF l_debug_level > 0 THEN
5724 oe_debug_pub.add( 'ENTERING GET_ORDER_NUMBER: ' || P_HEADER_ID , 1 ) ;
5725 END IF;
5726
5727 IF p_header_id is not null AND p_header_id <> FND_API.G_MISS_NUM
5728 THEN
5729 BEGIN
5730 select order_number
5731 into l_order_number
5732 from oe_order_headers
5733 where header_id = p_header_id;
5734 EXCEPTION
5735 WHEN OTHERS THEN
5736 RETURN null;
5737 END;
5738 END IF;
5739
5740 IF l_debug_level > 0 THEN
5741 oe_debug_pub.add( 'ORDER NUMBER : ' || L_ORDER_NUMBER ) ;
5742 END IF;
5743 RETURN l_order_number;
5744 EXCEPTION
5745 WHEN OTHERS THEN
5746 RETURN null;
5747 END Get_Order_Number;
5748
5749 /*-----------------------------------------------------------------------------
5750 Procedure Name : Load_Request
5751 Description : This procedure loads the MRP record or tables to be passed
5752 to MRP's API from the OM's table of records of order lines.
5753 If line line to be passed to MRP is an ATO model, we call
5754 CTO's GET_MANDATORY_COMPONENTS API to get the mandatory
5755 components, and we pass them along with the ATO model
5756 to MRP.
5757 ----------------------------------------------------------------------------- */
5758 Procedure Load_MRP_Request
5759 ( p_line_tbl IN Oe_Order_Pub.Line_Tbl_Type
5760 , p_old_line_tbl IN Oe_Order_Pub.Line_Tbl_Type
5761 , x_atp_table OUT NOCOPY /* file.sql.39 change */ MRP_ATP_PUB.ATP_Rec_Typ)
5762 IS
5763 I number := 1;
5764 l_atp_rec MRP_ATP_PUB.ATP_Rec_Typ;
5765 l_smc_rec MRP_ATP_PUB.ATP_Rec_Typ;
5766 l_line_rec Oe_Order_Pub.Line_Rec_Type;
5767 l_old_line_rec Oe_Order_Pub.Line_Rec_Type;
5768
5769 l_type_code VARCHAR2(30);
5770 l_st_atp_lead_time NUMBER;
5771 l_st_ato_line_id NUMBER;
5772
5773 l_message_name VARCHAR2(30);
5774 l_error_message VARCHAR2(2000);
5775 l_table_name VARCHAR2(30);
5776 l_model_rec MRP_ATP_PUB.ATP_Rec_Typ;
5777 l_smc_recs MRP_ATP_PUB.ATP_Rec_Typ;
5778 l_ship_set VARCHAR2(30);
5779 l_arrival_set VARCHAR2(30);
5780
5781 l_cto_result NUMBER;
5782 l_order_number NUMBER;
5783
5784 lTableName VARCHAR2(30);
5785 lMessageName VARCHAR2(30);
5786 lErrorMessage VARCHAR2(2000);
5787
5788 l_result NUMBER := 1;
5789 l_oe_flag VARCHAR2(1);
5790
5791 l_mrp_calc_sd VARCHAR2(240);
5792 l_insert_flag NUMBER;
5793
5794 l_organization_id NUMBER;
5795 l_inventory_item_id NUMBER;
5796
5797 l_inv_ctp VARCHAR2(240);
5798 l_explode BOOLEAN;
5799 l_action NUMBER;
5800
5801 --
5802 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5803 --
5804 BEGIN
5805 IF l_debug_level > 0 THEN
5806 oe_debug_pub.add( '....ENTERING OE_ORDER_SCH_UTIL.LOAD_MRP_REQUEST' , 1 ) ;
5807 oe_debug_pub.add( 'COUNT IS ' || P_LINE_TBL.COUNT , 1 ) ;
5808 oe_debug_pub.add( '------------------LOAD MRP TABLE---------------' , 1 ) ;
5809 END IF;
5810
5811
5812 l_mrp_calc_sd := fnd_profile.value('MRP_ATP_CALC_SD');
5813
5814 IF l_debug_level > 0 THEN
5815 oe_debug_pub.add( 'MRP_ATP_CALC_SD : '||L_MRP_CALC_SD , 3 ) ;
5816 END IF;
5817
5818 IF nvl(l_mrp_calc_sd,'N') = 'Y' THEN
5819 l_insert_flag := 1;
5820 ELSE
5821 l_insert_flag := 0;
5822 END IF;
5823
5824 IF l_debug_level > 0 THEN
5825 oe_debug_pub.add( 'INSERT FLAG : '||L_INSERT_FLAG , 3 ) ;
5826 END IF;
5827
5828 IF (p_line_tbl.count >= 1) THEN
5829
5830 I := 0;
5831
5832 FOR cnt IN 1..p_line_tbl.count LOOP
5833
5834 l_line_rec := p_line_tbl(cnt);
5835 l_old_line_rec := p_old_line_tbl(cnt);
5836
5837 IF cnt = 1 THEN
5838 -- This is the first line.
5839 -- We will get the order date type and order number
5840
5841 l_type_code := Get_Date_Type(l_line_rec.header_id);
5842 l_order_number := Get_Order_Number(l_line_rec.header_id);
5843
5844 END IF;
5845
5846 IF l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_CONFIG THEN
5847
5848 -- The config item might be a part of the table since query
5849 -- of a group of lines returns back the config item too. But
5850 -- we should not pass this item to MRP. Thus we will bypass this
5851 -- record out here.
5852
5853 goto end_loop;
5854 END IF;
5855
5856 I := I + 1;
5857
5858 Initialize_mrp_record(p_atp_rec => l_atp_rec,
5859 l_count => 1,
5860 x_atp_rec => l_atp_rec);
5861
5862 IF l_debug_level > 0 THEN
5863 oe_debug_pub.add( '--**-- ' , 3 ) ;
5864 END IF;
5865 l_atp_rec.atp_lead_time(I) := 0;
5866
5867 IF l_debug_level > 0 THEN
5868 oe_debug_pub.add( 'LINE ID : ' || L_LINE_REC.LINE_ID , 3 ) ;
5869 oe_debug_pub.add( 'SCHEDULE ACTION : ' || L_LINE_REC.SCHEDULE_ACTION_CODE , 3 ) ;
5870 END IF;
5871
5872 -- Set the non database files ship_set and arrival_set to null
5873 -- in case they are missing.
5874
5875 IF l_line_rec.ship_set = FND_API.G_MISS_CHAR THEN
5876 l_line_rec.ship_set := null;
5877 END IF;
5878
5879 IF l_line_rec.arrival_set = FND_API.G_MISS_CHAR THEN
5880 l_line_rec.arrival_set := null;
5881 END IF;
5882
5883 IF l_line_rec.arrival_set_id is null THEN
5884 l_arrival_set := l_line_rec.arrival_set;
5885 ELSE
5886 l_arrival_set := nvl(l_line_rec.arrival_set,to_char(l_line_rec.arrival_set_id));
5887 END IF;
5888
5889 IF l_line_rec.ship_set_id is null THEN
5890 l_ship_set := l_line_rec.ship_set;
5891 ELSE
5892 l_ship_set := nvl(l_line_rec.ship_set,to_char(l_line_rec.ship_set_id));
5893 END IF;
5894
5895 IF l_debug_level > 0 THEN
5896 oe_debug_pub.add( 'SHIP_SET : ' || L_SHIP_SET , 3 ) ;
5897 oe_debug_pub.add( 'ARRIVAL SET : ' || L_ARRIVAL_SET , 3 ) ;
5898 END IF;
5899
5900 l_atp_rec.Inventory_Item_Id(I) := l_line_rec.inventory_item_id;
5901
5902 IF (l_line_rec.ship_from_org_id = FND_API.G_MISS_NUM) THEN
5903 l_line_rec.ship_from_org_id := null;
5904 END IF;
5905 IF (l_old_line_rec.ship_from_org_id = FND_API.G_MISS_NUM) THEN
5906 l_old_line_rec.ship_from_org_id := null;
5907 END IF;
5908
5909 /*
5910 IF NOT OE_GLOBALS.Equal(l_line_rec.ship_from_org_id,
5911 l_old_line_rec.ship_from_org_id) OR
5912 (l_line_rec.re_source_flag = 'N')
5913 */
5914 IF (l_line_rec.ship_from_org_id IS NOT NULL)
5915 THEN
5916 l_atp_rec.Source_Organization_Id(I)
5917 := l_line_rec.ship_from_org_id;
5918 IF l_debug_level > 0 THEN
5919 oe_debug_pub.add( 'SHIP FROM : ' || L_LINE_REC.SHIP_FROM_ORG_ID , 3 ) ;
5920 END IF;
5921 ELSE
5922 l_atp_rec.Source_Organization_Id(I) := null;
5923 IF l_debug_level > 0 THEN
5924 oe_debug_pub.add( 'SHIP FROM IS NULL ' , 3 ) ;
5925 END IF;
5926 END IF;
5927 l_atp_rec.Identifier(I) := l_line_rec.line_id;
5928 l_atp_rec.Order_Number(I) := l_order_number;
5929 l_atp_rec.Calling_Module(I) := 660;
5930 l_atp_rec.Customer_Id(I) := l_line_rec.sold_to_org_id;
5931 l_atp_rec.Customer_Site_Id(I) := l_line_rec.ship_to_org_id;
5932 -- l_atp_rec.Destination_Time_Zone(I) := null;
5933 l_atp_rec.Destination_Time_Zone(I) := l_line_rec.item_type_code;
5934 l_atp_rec.Quantity_Ordered(I) := l_line_rec.ordered_quantity;
5935 l_atp_rec.Quantity_UOM(I) := l_line_rec.order_quantity_uom;
5936 l_atp_rec.Earliest_Acceptable_Date(I) := null;
5937
5938 -- For ATP check atp requested should be line_rec.request_date.
5939 -- Adding code to fix bug 2136818.
5940
5941 IF l_debug_level > 0 THEN
5942 oe_debug_pub.add( 'A1 : ' || L_LINE_REC.ARRIVAL_SET_ID , 1 ) ;
5943 oe_debug_pub.add( 'A2 : ' || L_OLD_LINE_REC.ARRIVAL_SET_ID , 1 ) ;
5944 END IF;
5945
5946 IF NOT OE_GLOBALS.Equal(l_line_rec.arrival_set_id,
5947 l_old_line_rec.arrival_set_id)
5948 OR (G_LINE_PART_OF_SET = TRUE AND
5949 l_line_rec.arrival_set_id is not null)
5950 THEN
5951
5952 IF l_debug_level > 0 THEN
5953 oe_debug_pub.add( 'T1' , 1 ) ;
5954 END IF;
5955 IF l_line_rec.schedule_action_code = OESCH_ACT_ATP_CHECK THEN
5956 l_atp_rec.Requested_Arrival_Date(I) :=
5957 l_line_rec.request_date;
5958 ELSE
5959
5960 l_atp_rec.Requested_Arrival_Date(I) :=
5961 l_line_rec.schedule_arrival_date;
5962 END IF;
5963
5964 l_atp_rec.Requested_Ship_Date(I) := null;
5965
5966 ELSIF NOT OE_GLOBALS.Equal(l_line_rec.ship_set_id,
5967 l_old_line_rec.ship_set_id)
5968 OR (G_LINE_PART_OF_SET = TRUE AND
5969 l_line_rec.ship_set_id is not null)
5970 THEN
5971
5972 IF l_debug_level > 0 THEN
5973 oe_debug_pub.add( 'T2' , 1 ) ;
5974 END IF;
5975 IF l_line_rec.schedule_action_code = OESCH_ACT_ATP_CHECK THEN
5976 l_atp_rec.Requested_Ship_Date(I) :=
5977 l_line_rec.request_date;
5978 ELSE
5979 l_atp_rec.Requested_Ship_Date(I) :=
5980 l_line_rec.schedule_ship_date;
5981 END IF;
5982 l_atp_rec.Requested_Arrival_Date(I) := null;
5983
5984 ELSIF (l_type_code = 'ARRIVAL')
5985 THEN
5986
5987 -- If user changes schedule_arrival_date then schedule based
5988 -- on the arrival_date. Otherwise look for the change in request date.
5989 -- If user changed request date, schedule based on the request
5990 -- date. Otherwise if the scheduling is happening because of
5991 -- some other changes, use nvl on arrival_date and request_dates.
5992
5993 IF l_debug_level > 0 THEN
5994 oe_debug_pub.add( 'T3' , 1 ) ;
5995 END IF;
5996 IF l_line_rec.schedule_action_code = OESCH_ACT_ATP_CHECK THEN
5997 l_atp_rec.Requested_Arrival_Date(I) :=
5998 l_line_rec.request_date;
5999 ELSE
6000 IF NOT OE_GLOBALS.Equal(l_line_rec.schedule_arrival_date,
6001 l_old_line_rec.schedule_arrival_date) AND
6002 l_line_rec.schedule_arrival_date IS NOT NULL AND
6003 l_line_rec.schedule_arrival_date <> FND_API.G_MISS_DATE
6004 THEN
6005
6006 l_atp_rec.Requested_Arrival_Date(I) :=
6007 l_line_rec.schedule_arrival_date;
6008
6009 ELSIF NOT OE_GLOBALS.Equal(l_line_rec.request_date,
6010 l_old_line_rec.request_date) AND
6011 l_line_rec.request_date IS NOT NULL AND
6012 l_line_rec.request_date <> FND_API.G_MISS_DATE
6013 THEN
6014
6015 l_atp_rec.Requested_Arrival_Date(I) :=
6016 l_line_rec.request_date;
6017
6018 ELSE
6019
6020 l_atp_rec.Requested_Arrival_Date(I) :=
6021 nvl(l_line_rec.schedule_arrival_date,l_line_rec.request_date);
6022
6023 END IF;
6024 END IF; -- ATP CHECK.
6025 l_atp_rec.Requested_Ship_Date(I) := null;
6026 IF l_debug_level > 0 THEN
6027 oe_debug_pub.add( 'REQ ARR DATE : ' || L_ATP_REC.REQUESTED_ARRIVAL_DATE ( I ) , 3 ) ;
6028 END IF;
6029 ELSE
6030
6031 -- If user changes schedule_ship_date then schedule based
6032 -- on the ship_date. Otherwise look for the change in request date.
6033 -- If user changed request date, schedule based on the request
6034 -- date. Otherwise if the scheduling is happening because of
6035 -- some other changes, use nvl on schedule_ship and request_dates.
6036
6037 IF l_debug_level > 0 THEN
6038 oe_debug_pub.add( 'T4' , 1 ) ;
6039 END IF;
6040 IF l_line_rec.schedule_action_code = OESCH_ACT_ATP_CHECK THEN
6041 l_atp_rec.Requested_Ship_Date(I) :=
6042 l_line_rec.request_date;
6043 ELSE
6044
6045 IF NOT OE_GLOBALS.Equal(l_line_rec.schedule_ship_date,
6046 l_old_line_rec.schedule_ship_date) AND
6047 l_line_rec.schedule_ship_date IS NOT NULL AND
6048 l_line_rec.schedule_ship_date <> FND_API.G_MISS_DATE
6049 THEN
6050
6051 l_atp_rec.Requested_Ship_Date(I) :=
6052 l_line_rec.schedule_ship_date;
6053
6054 ELSIF NOT OE_GLOBALS.Equal(l_line_rec.request_date,
6055 l_old_line_rec.request_date) AND
6056 l_line_rec.request_date IS NOT NULL AND
6057 l_line_rec.request_date <> FND_API.G_MISS_DATE
6058 THEN
6059
6060 l_atp_rec.Requested_Ship_Date(I) :=
6061 l_line_rec.request_date;
6062
6063 ELSE
6064
6065 l_atp_rec.Requested_Ship_Date(I) :=
6066 nvl(l_line_rec.schedule_ship_date,l_line_rec.request_date);
6067
6068 END IF;
6069
6070 END IF; -- ATP CHECK.
6071
6072 l_atp_rec.Requested_Arrival_Date(I) := null;
6073 IF l_debug_level > 0 THEN
6074 oe_debug_pub.add( 'REQ SHIP DATE : ' || L_ATP_REC.REQUESTED_SHIP_DATE ( I ) , 3 ) ;
6075 END IF;
6076
6077 END IF;
6078
6079 IF l_debug_level > 0 THEN
6080 oe_debug_pub.add( 'REQUEST SHIP DATE : ' || TO_CHAR ( L_ATP_REC.REQUESTED_SHIP_DATE ( I ) , 'DD-MON-RR:HH:MM:SS' ) , 3 ) ;
6081 oe_debug_pub.add( 'REQUEST ARRIVAL DATE : ' || TO_CHAR ( L_ATP_REC.REQUESTED_ARRIVAL_DATE ( I ) , 'DD-MON-RR:HH:MM:SS' ) , 3 ) ;
6082 END IF;
6083
6084
6085 IF OESCH_PERFORM_GRP_SCHEDULING = 'Y'
6086 THEN
6087 l_atp_rec.Latest_Acceptable_Date(I) :=
6088 l_line_rec.latest_acceptable_date;
6089 END IF;
6090
6091 IF G_LINE_PART_OF_SET = TRUE
6092 THEN
6093
6094 -- If the line is part of a set and we are rescheduling it
6095 -- just by itself, we should not let MRP change the date.
6096 -- Thus we will pass null Latest_Acceptable_Date
6097
6098 l_atp_rec.Latest_Acceptable_Date(I) := null;
6099 END IF;
6100
6101 -- Clearing delivery lead time to fix bug 2111591.
6102 l_atp_rec.Delivery_Lead_Time(I) := Null;
6103 --l_atp_rec.Delivery_Lead_Time(I) := l_line_rec.delivery_lead_time;
6104 IF l_debug_level > 0 THEN
6105 oe_debug_pub.add( 'DELIVERY : '||L_ATP_REC.DELIVERY_LEAD_TIME ( I ) , 3 ) ;
6106 END IF;
6107 l_atp_rec.Freight_Carrier(I) := null;
6108 l_atp_rec.Ship_Method(I) := l_line_rec.shipping_method_code;
6109 l_atp_rec.Demand_Class(I) := l_line_rec.demand_class_code;
6110 l_atp_rec.Ship_Set_Name(I) := l_ship_set;
6111 l_atp_rec.Arrival_Set_Name(I) := l_arrival_set;
6112 IF G_OVERRIDE_FLAG = 'Y' THEN
6113 l_atp_rec.Override_Flag(I) := 'Y';
6114 ELSE
6115 l_atp_rec.Override_Flag(I) := null;
6116 END IF;
6117 l_atp_rec.Ship_Date(I) := null;
6118 l_atp_rec.Available_Quantity(I) := null;
6119 l_atp_rec.Requested_Date_Quantity(I) := null;
6120 l_atp_rec.Group_Ship_Date(I) := null;
6121 l_atp_rec.Group_Arrival_Date(I) := null;
6122 l_atp_rec.Vendor_Id(I) := null;
6123 l_atp_rec.Vendor_Site_Id(I) := null;
6124 l_atp_rec.Insert_Flag(I) := l_insert_flag;
6125 IF l_debug_level > 0 THEN
6126 oe_debug_pub.add( 'INSERT FLAG IN ATP_REC : '||L_ATP_REC.INSERT_FLAG ( I ) , 3 ) ;
6127 oe_debug_pub.add( 'ATO LINE ID : '||L_LINE_REC.ATO_LINE_ID , 3 ) ;
6128 oe_debug_pub.add( 'ITEM TYPE : '||L_LINE_REC.ITEM_TYPE_CODE , 3 ) ;
6129 END IF;
6130 l_atp_rec.Error_Code(I) := null;
6131
6132 /* Changes for Internal Orders */
6133
6134 IF l_line_rec.source_document_type_id = 10 THEN
6135 IF l_debug_level > 0 THEN
6136 oe_debug_pub.add( 'IT IS AN INTERNAL ORDER ' , 3 ) ;
6137 END IF;
6138 l_oe_flag := 'Y';
6139
6140 IF (l_line_rec.schedule_ship_date IS NOT NULL AND
6141 l_line_rec.schedule_ship_date <> FND_API.G_MISS_DATE ) OR
6142 (l_line_rec.schedule_arrival_date IS NOT NULL AND
6143 l_line_rec.schedule_arrival_date <> FND_API.G_MISS_DATE ) THEN
6144
6145 IF l_debug_level > 0 THEN
6146 oe_debug_pub.add( 'NO CHANGES TO DATE AS IT HAS BEEN PASSED' , 3 ) ;
6147 END IF;
6148 ELSE
6149 IF l_debug_level > 0 THEN
6150 oe_debug_pub.add( 'PASS THE REQUEST DATE AS ARRIVAL DATE' , 3 ) ;
6151 END IF;
6152
6153 l_atp_rec.Requested_ship_Date(I) := null;
6154 l_atp_rec.Requested_arrival_Date(I) := l_line_rec.request_date;
6155
6156 END IF;
6157
6158 l_atp_rec.attribute_01(I) := l_line_rec.source_document_id;
6159
6160 ELSE
6161 IF l_debug_level > 0 THEN
6162 oe_debug_pub.add( 'IT IS NOT AN INTERNAL ORDER ' , 3 ) ;
6163 END IF;
6164 l_oe_flag := 'N';
6165 END IF;
6166
6167 l_atp_rec.oe_flag(I) := l_oe_flag;
6168 IF l_debug_level > 0 THEN
6169 oe_debug_pub.add( 'OE FLAG/SOURCE DOC IS : '||L_ATP_REC.OE_FLAG ( I ) ||'/'||L_ATP_REC.ATTRIBUTE_01 ( I ) , 3 ) ;
6170 END IF;
6171
6172 l_atp_rec.Message(I) := null;
6173
6174 IF (l_line_rec.schedule_action_code =
6175 OE_ORDER_SCH_UTIL.OESCH_ACT_ATP_CHECK)
6176 THEN
6177 l_atp_rec.Action(I) := 100;
6178 ELSIF (l_line_rec.schedule_action_code =
6179 OE_ORDER_SCH_UTIL.OESCH_ACT_DEMAND) OR
6180 (l_line_rec.schedule_action_code =
6181 OE_ORDER_SCH_UTIL.OESCH_ACT_SCHEDULE)
6182 THEN
6183 l_atp_rec.Action(I) := 110;
6184 ELSIF (l_line_rec.schedule_action_code =
6185 OE_ORDER_SCH_UTIL.OESCH_ACT_REDEMAND) OR
6186 (l_line_rec.schedule_action_code =
6187 OE_ORDER_SCH_UTIL.OESCH_ACT_RESCHEDULE)
6188 THEN
6189 l_atp_rec.Action(I) := 120;
6190 l_atp_rec.Old_Source_Organization_Id(I) :=
6191 l_old_line_rec.ship_from_org_id;
6192 l_atp_rec.Old_Demand_Class(I) :=
6193 l_old_line_rec.demand_class_code;
6194 ELSIF (l_line_rec.schedule_action_code =
6195 OE_ORDER_SCH_UTIL.OESCH_ACT_UNDEMAND)
6196 THEN
6197 l_atp_rec.Action(I) := 120;
6198 l_atp_rec.Quantity_Ordered(I) := 0;
6199 l_atp_rec.Old_Source_Organization_Id(I) :=
6200 l_old_line_rec.ship_from_org_id;
6201 l_atp_rec.Old_Demand_Class(I) :=
6202 l_old_line_rec.demand_class_code;
6203
6204 /*L.G. OPM bug 1828340 jul 19,01*/
6205 IF ( INV_GMI_RSV_BRANCH.Process_Branch(p_organization_id => l_old_line_rec.ship_from_org_id) ) THEN
6206 Update oe_order_lines_all
6207 Set ordered_quantity = 0,
6208 ordered_quantity2 = 0
6209 Where line_id=l_old_line_rec.line_id;
6210 END IF;
6211 END IF;
6212
6213 -- storing in local var to assing action to ato mandatory components
6214 -- to fix bug 1947539.
6215
6216 l_action := l_atp_rec.Action(I);
6217 l_atp_rec.atp_lead_time(I) := 0;
6218
6219 IF l_line_rec.ato_line_id is not null AND
6220 l_line_rec.line_id <> l_line_rec.ato_line_id
6221 THEN
6222
6223 -- This lines is a ato option or class.
6224 -- Set the atp_lead_time for it.
6225
6226 IF l_line_rec.ato_line_id = l_st_ato_line_id
6227 THEN
6228 l_atp_rec.atp_lead_time(I) := l_st_atp_lead_time;
6229 IF l_debug_level > 0 THEN
6230 oe_debug_pub.add( 'ATO LEAD TIME IS ' || L_ST_ATP_LEAD_TIME , 3 ) ;
6231 END IF;
6232 ELSE
6233 IF l_debug_level > 0 THEN
6234 oe_debug_pub.add( 'CALLING GET_LEAD_TIME' , 3 ) ;
6235 END IF;
6236 l_st_atp_lead_time :=
6237 Get_Lead_Time
6238 (p_ato_line_id => l_line_rec.ato_line_id,
6239 p_ship_from_org_id => l_line_rec.ship_from_org_id);
6240
6241 IF l_debug_level > 0 THEN
6242 oe_debug_pub.add( 'AFTER CALLING GET_LEAD_TIME' , 3 ) ;
6243 oe_debug_pub.add( 'LEAD TIME: ' || L_ST_ATP_LEAD_TIME , 3 ) ;
6244 END IF;
6245
6246 l_atp_rec.atp_lead_time(I) := l_st_atp_lead_time;
6247 l_st_ato_line_id := l_line_rec.ato_line_id;
6248 END IF;
6249 END IF;
6250
6251 l_inv_ctp := fnd_profile.value('INV_CTP');
6252
6253 l_explode := TRUE;
6254
6255 IF l_debug_level > 0 THEN
6256 oe_debug_pub.add( 'INV_CTP : '||L_INV_CTP , 3 ) ;
6257 END IF;
6258
6259 IF l_line_rec.ato_line_id = l_line_rec.line_id AND
6260 (l_line_rec.item_type_code in ('MODEL','CLASS') OR
6261 (l_line_rec.item_type_code in ('STANDARD','OPTION') AND
6262 l_inv_ctp = '5'))
6263 THEN
6264
6265 -- Added this code to fix bug 1998613.
6266 IF l_line_rec.schedule_status_code is not null
6267 AND nvl(l_line_rec.ordered_quantity,0) <
6268 l_old_line_rec.ordered_quantity
6269 AND l_old_line_rec.reserved_quantity > 0
6270 AND NOT Schedule_Attribute_Changed(p_line_rec => l_line_rec,
6271 p_old_line_rec => l_old_line_rec)
6272 AND OE_GLOBALS.Equal(l_line_rec.sold_to_org_id,
6273 l_old_line_rec.sold_to_org_id)
6274 THEN
6275
6276 IF l_debug_level > 0 THEN
6277 oe_debug_pub.add( 'ONLY ORDERED QTY GOT REDUCED , NO EXPLOSION' , 3 ) ;
6278 END IF;
6279 l_explode := FALSE;
6280
6281 END IF;
6282
6283 IF l_explode THEN
6284
6285 -- If the line scheduled is an ATO Model, call ATO's API
6286 -- to get the Standard Mandatory Components
6287
6288 IF l_debug_level > 0 THEN
6289 oe_debug_pub.add( 'ATO ITEM TYPE : '||L_LINE_REC.ITEM_TYPE_CODE , 3 ) ;
6290 END IF;
6291
6292 IF l_line_rec.item_type_code = 'STANDARD' AND
6293 l_atp_rec.ship_set_name(I) is NULL THEN
6294
6295 IF l_debug_level > 0 THEN
6296 oe_debug_pub.add( 'ASSIGNING SHIP SET FOR ATO ITEM ' , 3 ) ;
6297 END IF;
6298 l_atp_rec.Ship_Set_Name(I) := l_line_rec.ato_line_id;
6299
6300 END IF;
6301
6302 IF l_line_rec.item_type_code = 'STANDARD' THEN
6303
6304 IF l_debug_level > 0 THEN
6305 oe_debug_pub.add( 'ASSIGNING WAREHOUSE AND ITEM ' , 3 ) ;
6306 END IF;
6307 l_organization_id := l_line_rec.ship_from_org_id;
6308 l_inventory_item_id := l_line_rec.inventory_item_id;
6309 IF l_debug_level > 0 THEN
6310 oe_debug_pub.add( 'WAREHOUSE/ITEM : '||L_ORGANIZATION_ID||'/'||L_INVENTORY_ITEM_ID , 3 ) ;
6311 END IF;
6312
6313 ELSE
6314
6315 l_organization_id := NULL;
6316 l_inventory_item_id := NULL;
6317 IF l_debug_level > 0 THEN
6318 oe_debug_pub.add( 'WAREHOUSE/ITEM : '||L_ORGANIZATION_ID||'/'||L_INVENTORY_ITEM_ID , 3 ) ;
6319 END IF;
6320
6321 END IF;
6322
6323 --Load Model Rec to pass to ATO's API
6324 --Load Model Rec to pass to ATO's API
6325
6326 l_model_rec.Inventory_Item_Id := MRP_ATP_PUB.number_arr
6327 (l_atp_rec.Inventory_Item_Id(I));
6328
6329 l_model_rec.Source_Organization_Id := MRP_ATP_PUB.number_arr
6330 (l_atp_rec.Source_Organization_Id(I));
6331
6332 l_model_rec.Identifier := MRP_ATP_PUB.number_arr
6333 (l_atp_rec.Identifier(I));
6334
6335 l_model_rec.Calling_Module := MRP_ATP_PUB.number_arr
6336 (l_atp_rec.Calling_Module(I));
6337
6338 l_model_rec.Customer_Id := MRP_ATP_PUB.number_arr
6339 (l_atp_rec.Customer_Id(I));
6340
6341 l_model_rec.Customer_Site_Id := MRP_ATP_PUB.number_arr
6342 (l_atp_rec.Customer_Site_Id(I));
6343
6344 l_model_rec.Destination_Time_Zone := MRP_ATP_PUB.char30_arr
6345 (l_atp_rec.Destination_Time_Zone(I));
6346
6347 l_model_rec.Quantity_Ordered := MRP_ATP_PUB.number_arr
6348 (l_atp_rec.Quantity_Ordered(I));
6349
6350 l_model_rec.Quantity_UOM := MRP_ATP_PUB.char3_arr
6351 (l_atp_rec.Quantity_UOM(I));
6352
6353 l_model_rec.Earliest_Acceptable_Date := MRP_ATP_PUB.date_arr
6354 (l_atp_rec.Earliest_Acceptable_Date(I));
6355
6356 l_model_rec.Requested_Ship_Date := MRP_ATP_PUB.date_arr
6357 (l_atp_rec.Requested_Ship_Date(I));
6358
6359 l_model_rec.Requested_Arrival_Date := MRP_ATP_PUB.date_arr
6360 (l_atp_rec.Requested_Arrival_Date(I));
6361
6362 l_model_rec.Latest_Acceptable_Date := MRP_ATP_PUB.date_arr
6363 (l_atp_rec.Latest_Acceptable_Date(I));
6364
6365 l_model_rec.Delivery_Lead_Time := MRP_ATP_PUB.number_arr
6366 (l_atp_rec.Delivery_Lead_Time(I));
6367
6368 l_model_rec.Atp_lead_Time := MRP_ATP_PUB.number_arr
6369 (l_atp_rec.Atp_lead_Time(I));
6370
6371 l_model_rec.Freight_Carrier := MRP_ATP_PUB.char30_arr
6372 (l_atp_rec.Freight_Carrier(I));
6373
6374 l_model_rec.Ship_Method := MRP_ATP_PUB.char30_arr
6375 (l_atp_rec.Ship_Method(I));
6376
6377 l_model_rec.Demand_Class := MRP_ATP_PUB.char30_arr
6378 (l_atp_rec.Demand_Class(I));
6379
6380 l_model_rec.Ship_Set_Name := MRP_ATP_PUB.char30_arr
6381 (l_atp_rec.Ship_Set_Name(I));
6382
6383 l_model_rec.Arrival_Set_Name := MRP_ATP_PUB.char30_arr
6384 (l_atp_rec.Arrival_Set_Name(I));
6385
6386 l_model_rec.Override_Flag := MRP_ATP_PUB.char1_arr
6387 (l_atp_rec.Override_Flag(I));
6388
6389 l_model_rec.Ship_Date := MRP_ATP_PUB.date_arr
6390 (l_atp_rec.Ship_Date(I));
6391
6392 l_model_rec.Available_Quantity := MRP_ATP_PUB.number_arr
6393 (l_atp_rec.Available_Quantity(I));
6394
6395 l_model_rec.Requested_Date_Quantity := MRP_ATP_PUB.number_arr
6396 (l_atp_rec.Requested_Date_Quantity(I));
6397
6398 l_model_rec.Group_Ship_Date := MRP_ATP_PUB.date_arr
6399 (l_atp_rec.Group_Ship_Date(I));
6400
6401 l_model_rec.Group_Arrival_Date := MRP_ATP_PUB.date_arr
6402 (l_atp_rec.Group_Arrival_Date(I));
6403
6404 l_model_rec.Vendor_Id := MRP_ATP_PUB.number_arr
6405 (l_atp_rec.Vendor_Id(I));
6406
6407 l_model_rec.Vendor_Site_Id := MRP_ATP_PUB.number_arr
6408 (l_atp_rec.Vendor_Site_Id(I));
6409
6410 l_model_rec.Insert_Flag := MRP_ATP_PUB.number_arr
6411 (l_atp_rec.Insert_Flag(I));
6412 --oe_debug_pub.add('Insert flag in model_rec : '||l_model_rec.insert_flag,3);
6413
6414 l_model_rec.Error_Code := MRP_ATP_PUB.number_arr
6415 (l_atp_rec.Error_Code(I));
6416
6417 l_model_rec.Message := MRP_ATP_PUB.char2000_arr
6418 (l_atp_rec.Message(I));
6419
6420 l_model_rec.Action := MRP_ATP_PUB.number_arr
6421 (l_atp_rec.action(I));
6422
6423 l_model_rec.order_number := MRP_ATP_PUB.number_arr
6424 (l_atp_rec.order_number(I));
6425
6426 IF l_atp_rec.Old_Source_Organization_Id.Exists(I) THEN
6427 l_model_rec.Old_Source_Organization_Id := MRP_ATP_PUB.number_arr
6428 (l_atp_rec.Old_Source_Organization_Id(I));
6429 END IF;
6430
6431 IF l_atp_rec.Old_Demand_Class.Exists(I) THEN
6432 l_model_rec.Old_Demand_Class :=
6433 MRP_ATP_PUB.char30_arr(l_atp_rec.Old_Demand_Class(I));
6434 END IF;
6435
6436 BEGIN
6437 IF l_debug_level > 0 THEN
6438 oe_debug_pub.add( '2.. CALLING CTO GET_BOM_MANDATORY_COMPS' , 3 ) ;
6439 END IF;
6440
6441 l_result := CTO_CONFIG_ITEM_PK.GET_MANDATORY_COMPONENTS
6442 (p_ship_set => l_model_rec,
6443 p_organization_id => l_organization_id,
6444 p_inventory_item_id => l_inventory_item_id,
6445 x_smc_rec => l_smc_rec,
6446 xErrorMessage => lErrorMessage,
6447 xMessageName => lMessageName,
6448 xTableName => lTableName);
6449
6450 IF l_debug_level > 0 THEN
6451 oe_debug_pub.add( '2..AFTER CALLING CTO API : ' || L_RESULT , 3 ) ;
6452 END IF;
6453
6454 EXCEPTION
6455 WHEN OTHERS THEN
6456 IF l_debug_level > 0 THEN
6457 oe_debug_pub.add( 'CTO API RETURNED AN UNEXPECTED ERROR' ) ;
6458 END IF;
6459 l_result := 0;
6460 END;
6461
6462
6463 /*
6464 IF l_result <> 1 THEN
6465 IF lErrorMessage is not null THEN
6466 oe_msg_pub.add_text(p_message_text => lErrorMessage);
6467 END IF;
6468 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6469 END IF;
6470 */
6471
6472 IF l_result = 1 AND
6473 l_smc_rec.Identifier.count >= 1 THEN
6474 IF l_debug_level > 0 THEN
6475 oe_debug_pub.add( 'SMC COUNT IS : ' || L_SMC_REC.IDENTIFIER.COUNT , 1 ) ;
6476 END IF;
6477
6478 Initialize_mrp_record(p_atp_rec => l_atp_rec,
6479 l_count => l_smc_rec.Identifier.count,
6480 x_atp_rec => l_atp_rec);
6481
6482 FOR J IN 1..l_smc_rec.Identifier.count LOOP
6483 I := I + 1;
6484 -- Added atp_lead_time, order Number to fix bug 1560461.
6485 l_atp_rec.atp_lead_time(I) := 0;
6486 l_atp_rec.oe_flag(I) := l_oe_flag;
6487 -- As part of the bug fix 2910899, OM will indicate and remember the
6488 -- Standard Madatory record positions using vendor_name. This will be -- used in the load_results procedure to bypass the SMC records.
6489
6490 l_atp_rec.vendor_name(I) := 'SMC';
6491 IF l_debug_level > 0 THEN
6492 oe_debug_pub.add( 'OE FLAG IS : '||L_ATP_REC.OE_FLAG ( I ) , 3 ) ;
6493 END IF;
6494
6495 l_atp_rec.Inventory_Item_Id(I) := l_smc_rec.Inventory_Item_Id(J);
6496 l_atp_rec.Source_Organization_Id(I) :=
6497 l_smc_rec.Source_Organization_Id(J);
6498
6499 l_atp_rec.Identifier(I) := l_smc_rec.Identifier(J);
6500 l_atp_rec.Order_Number(I) := l_order_number;
6501 l_atp_rec.Calling_Module(I) := l_smc_rec.Calling_Module(J);
6502 l_atp_rec.Customer_Id(I) := l_smc_rec.Customer_Id(J);
6503 l_atp_rec.Customer_site_Id(I) := l_smc_rec.Customer_site_Id(J);
6504 l_atp_rec.Destination_Time_Zone(I) :=
6505 l_smc_rec.Destination_Time_Zone(J);
6506 l_atp_rec.Quantity_Ordered(I) := l_smc_rec.Quantity_Ordered(J);
6507 l_atp_rec.Quantity_UOM(I) := l_smc_rec.Quantity_UOM(J);
6508 l_atp_rec.Earliest_Acceptable_Date(I) :=
6509 l_smc_rec.Earliest_Acceptable_Date(J);
6510 l_atp_rec.Requested_Ship_Date(I) :=
6511 l_smc_rec.Requested_Ship_Date(J);
6512 l_atp_rec.Requested_Arrival_Date(I) :=
6513 l_smc_rec.Requested_Arrival_Date(J);
6514 l_atp_rec.Latest_Acceptable_Date(I) :=
6515 l_smc_rec.Latest_Acceptable_Date(J);
6516 l_atp_rec.Delivery_Lead_Time(I) :=
6517 l_smc_rec.Delivery_Lead_Time(J);
6518 l_atp_rec.Freight_Carrier(I) :=
6519 l_smc_rec.Freight_Carrier(J);
6520 l_atp_rec.Ship_Method(I) :=
6521 l_smc_rec.Ship_Method(J);
6522 l_atp_rec.Demand_Class(I) :=
6523 l_smc_rec.Demand_Class(J);
6524 l_atp_rec.Ship_Set_Name(I) :=
6525 l_smc_rec.Ship_Set_Name(J);
6526 l_atp_rec.Arrival_Set_Name(I) :=
6527 l_smc_rec.Arrival_Set_Name(J);
6528 l_atp_rec.Override_Flag(I) :=
6529 l_smc_rec.Override_Flag(J);
6530 l_atp_rec.Ship_Date(I) :=
6531 l_smc_rec.Ship_Date(J);
6532 l_atp_rec.Available_Quantity(I) :=
6533 l_smc_rec.Available_Quantity(J);
6534 l_atp_rec.Requested_Date_Quantity(I):=
6535 l_smc_rec.Requested_Date_Quantity(J);
6536 l_atp_rec.Group_Ship_Date(I) :=
6537 l_smc_rec.Group_Ship_Date(J);
6538 l_atp_rec.Group_Arrival_Date(I) :=
6539 l_smc_rec.Group_Arrival_Date(J);
6540 l_atp_rec.Vendor_Id(I) :=
6541 l_smc_rec.Vendor_Id(J);
6542 l_atp_rec.Vendor_Site_Id(I) :=
6543 l_smc_rec.Vendor_Site_Id(J);
6544 l_atp_rec.Insert_Flag(I) :=
6545 l_smc_rec.Insert_Flag(J);
6546 l_atp_rec.atp_lead_time(I) :=
6547 l_smc_rec.atp_lead_time(J);
6548 IF l_debug_level > 0 THEN
6549 oe_debug_pub.add( 'INSERT FLAG IN SMC_REC : '||L_SMC_REC.INSERT_FLAG ( J ) , 3 ) ;
6550 oe_debug_pub.add( 'INSERT FLAG IN ATP_REC : '||L_ATP_REC.INSERT_FLAG ( I ) , 3 ) ;
6551 END IF;
6552 l_atp_rec.Error_Code(I) :=
6553 l_smc_rec.Error_Code(J);
6554 l_atp_rec.Message(I) :=
6555 l_smc_rec.Message(J);
6556 l_atp_rec.Action(I) := l_action;
6557 END LOOP;
6558 END IF;
6559 END IF; -- l_explode.
6560 END IF; /* If line is a ATO model */
6561
6562 <<end_loop>>
6563
6564 null;
6565
6566 END LOOP;
6567 END IF;
6568
6569 IF l_debug_level > 0 THEN
6570 oe_debug_pub.add( '--**-- ' , 1 ) ;
6571 END IF;
6572 x_atp_table := l_atp_rec;
6573
6574 IF l_debug_level > 0 THEN
6575 oe_debug_pub.add( '....EXITING OE_ORDER_SCH_UTIL.LOAD_REQUEST' , 1 ) ;
6576 END IF;
6577 EXCEPTION
6578 WHEN OTHERS THEN
6579 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6580 THEN
6581 OE_MSG_PUB.Add_Exc_Msg
6582 ( G_PKG_NAME
6583 , 'Load_MRP_Request'
6584 );
6585 END IF;
6586 IF l_debug_level > 0 THEN
6587 oe_debug_pub.add( 'UNEXPECTED ERROR IN LOAD_RESULTS' ) ;
6588 END IF;
6589 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6590 END Load_MRP_Request;
6591
6592 /*-----------------------------------------------------------------------------
6593 Procedure Name : Load_INV_Request
6594 Description : This procedure loads the INV's record structure which
6595 we will pass to INV for reservation purpose.
6596 We need to pass to INV the idenfier for OM demand.
6597 We pass the constant INV_RESERVATION_GLOBAL.G_SOURCE_TYPE_OE
6598 for all OM Order Lines except Internal Orders.
6599 For Internal Orders we pass
6600 INV_RESERVATION_GLOBAL.G_SOURCE_TYPE_INTERNAL_ORD
6601 as the identifier.
6602 ----------------------------------------------------------------------------- */
6603 Procedure Load_INV_Request
6604 ( p_line_rec IN Oe_Order_Pub.Line_Rec_Type
6605 , p_quantity_to_reserve IN NUMBER
6606 , p_quantity2_to_reserve IN NUMBER -- INVCONV
6607 , x_reservation_rec OUT NOCOPY /* file.sql.39 change */ Inv_Reservation_Global.Mtl_Reservation_Rec_Type)
6608 IS
6609 l_rsv Inv_Reservation_Global.Mtl_Reservation_Rec_Type;
6610 l_source_code VARCHAR2(40) := FND_PROFILE.VALUE('ONT_SOURCE_CODE');
6611 l_sales_order_id NUMBER;
6612 l_subinventory VARCHAR2(10);
6613 --
6614 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6615 --
6616 BEGIN
6617 IF l_debug_level > 0 THEN
6618 oe_debug_pub.add( 'ENTERING LOAD INV REQUEST' , 1 ) ;
6619 END IF;
6620
6621 l_rsv.reservation_id := fnd_api.g_miss_num; -- cannot know
6622 l_rsv.requirement_date := p_line_rec.schedule_ship_date;
6623 l_rsv.organization_id := p_line_rec.ship_from_org_id;
6624 l_rsv.inventory_item_id := p_line_rec.inventory_item_id;
6625
6626 IF p_line_rec.source_document_type_id = 10 THEN
6627
6628 -- This is an internal order line. We need to give
6629 -- a different demand source type for these lines.
6630
6631 l_rsv.demand_source_type_id :=
6632 INV_RESERVATION_GLOBAL.G_SOURCE_TYPE_INTERNAL_ORD;
6633 -- intenal order
6634
6635 ELSE
6636
6637 l_rsv.demand_source_type_id :=
6638 INV_RESERVATION_GLOBAL.G_SOURCE_TYPE_OE; -- order entry
6639
6640 END IF;
6641
6642 l_rsv.demand_source_name := NULL;
6643
6644 -- Get demand_source_header_id from mtl_sales_orders
6645
6646 l_sales_order_id := Get_mtl_sales_order_id(p_line_rec.HEADER_ID);
6647
6648 IF l_debug_level > 0 THEN
6649 oe_debug_pub.add( 'L_SALES_ORDER_ID' || L_SALES_ORDER_ID , 1 ) ;
6650 END IF;
6651
6652 IF p_line_rec.subinventory = FND_API.G_MISS_CHAR THEN
6653 l_subinventory := NULL;
6654 ELSE
6655 l_subinventory := p_line_rec.subinventory;
6656 END IF;
6657
6658 l_rsv.demand_source_header_id := l_sales_order_id;
6659 l_rsv.demand_source_line_id := p_line_rec.line_id;
6660 l_rsv.demand_source_delivery := NULL;
6661 l_rsv.primary_uom_code := NULL;
6662 l_rsv.primary_uom_id := NULL;
6663 l_rsv.reservation_uom_code := p_line_rec.order_quantity_uom;
6664 l_rsv.reservation_uom_id := NULL;
6665 l_rsv.reservation_quantity := p_quantity_to_reserve;
6666 l_rsv.primary_reservation_quantity := NULL;
6667 l_rsv.autodetail_group_id := NULL;
6668 l_rsv.external_source_code := NULL;
6669 l_rsv.external_source_line_id := NULL;
6670
6671 l_rsv.supply_source_type_id :=
6672 INV_RESERVATION_GLOBAL.G_SOURCE_TYPE_INV;
6673
6674 l_rsv.supply_source_header_id := NULL;
6675 l_rsv.supply_source_line_id := NULL;
6676 l_rsv.supply_source_name := NULL;
6677 l_rsv.supply_source_line_detail := NULL;
6678 l_rsv.revision := NULL;
6679 l_rsv.subinventory_code := l_subinventory;
6680 l_rsv.subinventory_id := NULL;
6681 l_rsv.locator_id := NULL;
6682 l_rsv.lot_number := NULL;
6683 l_rsv.lot_number_id := NULL;
6684 l_rsv.pick_slip_number := NULL;
6685 l_rsv.lpn_id := NULL;
6686 l_rsv.attribute_category := NULL;
6687 /* OPM 02/JUN/00 send process attributes into the reservation
6688 =============================================================
6689 l_rsv.attribute1 := p_line_rec.preferred_grade;
6690 l_rsv.attribute2 := p_line_rec.ordered_quantity2;
6691 l_rsv.attribute3 := p_line_rec.ordered_quantity_uom2;
6692 OPM 02/JUN/00 END
6693 ==================== -- INVCONV */
6694
6695 l_rsv.secondary_reservation_quantity := p_line_rec.ordered_quantity2; -- INVCONV
6696 l_rsv.secondary_uom_code := p_line_rec.ordered_quantity_uom2;
6697
6698 l_rsv.attribute1 := NULL; -- INVCONV
6699 l_rsv.attribute2 := NULL; -- INVCONV
6700 l_rsv.attribute3 := NULL; -- INVCONV
6701 l_rsv.attribute4 := NULL;
6702 l_rsv.attribute5 := NULL;
6703 l_rsv.attribute6 := NULL;
6704 l_rsv.attribute7 := NULL;
6705 l_rsv.attribute8 := NULL;
6706 l_rsv.attribute9 := NULL;
6707 l_rsv.attribute10 := NULL;
6708 l_rsv.attribute11 := NULL;
6709 l_rsv.attribute12 := NULL;
6710 l_rsv.attribute13 := NULL;
6711 l_rsv.attribute14 := NULL;
6712 l_rsv.attribute15 := NULL;
6713 l_rsv.ship_ready_flag := NULL;
6714 x_reservation_rec := l_rsv;
6715 IF l_debug_level > 0 THEN
6716 oe_debug_pub.add( 'EXITING LOAD INV REQUEST' , 1 ) ;
6717 END IF;
6718 EXCEPTION
6719
6720 WHEN NO_DATA_FOUND
6721 THEN
6722 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6723
6724 END Load_INV_Request;
6725 /*-----------------------------------------------------------------------------
6726 Procedure Name : Schedule_Attribute_Changed
6727 Description : This function returns TRUE is scheduling attribute is changed
6728 on a line. This is required for rescheduling.
6729 ----------------------------------------------------------------------------- */
6730
6731
6732 FUNCTION Schedule_Attribute_Changed
6733 ( p_line_rec IN Oe_Order_Pub.line_rec_type
6734 , p_old_line_rec IN Oe_Order_Pub.line_rec_type)
6735 RETURN BOOLEAN
6736 IS
6737 --
6738 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6739 --
6740 BEGIN
6741
6742 IF NOT OE_GLOBALS.Equal(p_line_rec.SHIP_FROM_ORG_ID,
6743 p_old_line_rec.SHIP_FROM_ORG_ID)
6744 THEN
6745 RETURN TRUE;
6746 END IF;
6747
6748 IF NOT OE_GLOBALS.Equal(p_line_rec.SUBINVENTORY,
6749 p_old_line_rec.SUBINVENTORY)
6750 THEN
6751 RETURN TRUE;
6752 END IF;
6753
6754 IF NOT OE_GLOBALS.Equal(p_line_rec.SHIP_TO_ORG_ID,
6755 p_old_line_rec.SHIP_TO_ORG_ID)
6756 THEN
6757 RETURN TRUE;
6758 END IF;
6759
6760 IF NOT OE_GLOBALS.Equal(p_line_rec.DEMAND_CLASS_CODE,
6761 p_old_line_rec.DEMAND_CLASS_CODE)
6762 THEN
6763 RETURN TRUE;
6764 END IF;
6765
6766 IF NOT OE_GLOBALS.Equal(p_line_rec.SCHEDULE_SHIP_DATE,
6767 p_old_line_rec.SCHEDULE_SHIP_DATE)
6768 THEN
6769 RETURN TRUE;
6770 END IF;
6771
6772 IF NOT OE_GLOBALS.Equal(p_line_rec.SCHEDULE_ARRIVAL_DATE,
6773 p_old_line_rec.SCHEDULE_ARRIVAL_DATE)
6774 THEN
6775 RETURN TRUE;
6776 END IF;
6777
6778 IF NOT OE_GLOBALS.Equal(p_line_rec.SHIPPING_METHOD_CODE,
6779 p_old_line_rec.SHIPPING_METHOD_CODE)
6780 THEN
6781 RETURN TRUE;
6782 END IF;
6783
6784 IF NOT OE_GLOBALS.Equal(p_line_rec.REQUEST_DATE,
6785 p_old_line_rec.REQUEST_DATE)
6786 THEN
6787 RETURN TRUE;
6788 END IF;
6789
6790 IF NOT OE_GLOBALS.Equal(p_line_rec.DELIVERY_LEAD_TIME,
6791 p_old_line_rec.DELIVERY_LEAD_TIME)
6792 THEN
6793 RETURN TRUE;
6794 END IF;
6795
6796
6797 IF NOT OE_GLOBALS.Equal(p_line_rec.inventory_item_id,
6798 p_old_line_rec.inventory_item_id)
6799 THEN
6800 RETURN TRUE;
6801 END IF;
6802
6803 IF NOT OE_GLOBALS.Equal(p_line_rec.order_quantity_uom,
6804 p_old_line_rec.order_quantity_uom)
6805 THEN
6806 RETURN TRUE;
6807 END IF;
6808
6809
6810 RETURN FALSE;
6811 IF l_debug_level > 0 THEN
6812 oe_debug_pub.add( 'RETURNING FALSE ' , 3 ) ;
6813 END IF;
6814 END Schedule_Attribute_Changed;
6815
6816 /*---------------------------------------------------------------------
6817 Procedure Name : Unreserve_Line
6818 Description : This API calls Inventory's APIs to Unreserve. It first
6819 queries the reservation records, and then calls
6820 delete_reservations until the p_quantity_to_unreserve
6821 is satisfied.
6822 --------------------------------------------------------------------- */
6823
6824 Procedure Unreserve_Line
6825 ( p_line_rec IN OE_ORDER_PUB.Line_Rec_Type
6826 , p_quantity_to_unreserve IN NUMBER
6827 , p_quantity2_to_unreserve IN NUMBER -- INVCONV
6828 , x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
6829 IS
6830 l_line_rec OE_ORDER_PUB.line_rec_type;
6831 l_rsv_rec inv_reservation_global.mtl_reservation_rec_type;
6832 l_rsv_new_rec inv_reservation_global.mtl_reservation_rec_type;
6833 l_msg_count NUMBER;
6834 l_msg_data VARCHAR2(240);
6835 l_rsv_id NUMBER;
6836 l_return_status VARCHAR2(1);
6837 l_rsv_tbl inv_reservation_global.mtl_reservation_tbl_type;
6838 l_count NUMBER;
6839 l_dummy_sn inv_reservation_global.serial_number_tbl_type;
6840 l_qty_to_unreserve NUMBER;
6841 l_source_code VARCHAR2(40) := FND_PROFILE.VALUE('ONT_SOURCE_CODE');
6842 l_sales_order_id NUMBER;
6843 l_x_error_code NUMBER;
6844 l_lock_records VARCHAR2(1);
6845 l_sort_by_req_date NUMBER ;
6846
6847 l_buffer VARCHAR2(2000);
6848
6849 l_qty2_to_unreserve NUMBER; -- INVCONV
6850 --
6851 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6852 --
6853 BEGIN
6854
6855 IF l_debug_level > 0 THEN
6856 oe_debug_pub.add( 'ENTERING UNRESERVE LINE' , 3 ) ;
6857 oe_debug_pub.add( 'QUANTITY TO UNRESERVE :' || P_QUANTITY_TO_UNRESERVE , 3 ) ;
6858 oe_debug_pub.add( 'QUANTITY2 TO UNRESERVE :' || P_QUANTITY2_TO_UNRESERVE , 3 ) ;
6859 END IF;
6860
6861 -- If the quantity to reserve is passed and null or missing, we do not
6862 -- need to go throug this procedure.
6863
6864 IF p_quantity_to_unreserve is null OR
6865 p_quantity_to_unreserve = FND_API.G_MISS_NUM THEN
6866 goto end_of_loop;
6867 END IF;
6868
6869 l_line_rec := p_line_rec;
6870
6871 IF p_line_rec.source_document_type_id = 10 THEN
6872
6873 -- This is an internal order line. We need to give
6874 -- a different demand source type for these lines.
6875
6876 l_rsv_rec.demand_source_type_id :=
6877 INV_RESERVATION_GLOBAL.G_SOURCE_TYPE_INTERNAL_ORD;
6878 -- intenal order
6879
6880 ELSE
6881
6882 l_rsv_rec.demand_source_type_id :=
6883 INV_RESERVATION_GLOBAL.G_SOURCE_TYPE_OE; -- order entry
6884
6885 END IF;
6886
6887 -- Get demand_source_header_id from mtl_sales_orders
6888
6889 l_sales_order_id := Get_mtl_sales_order_id(p_line_rec.HEADER_ID);
6890
6891 IF l_debug_level > 0 THEN
6892 oe_debug_pub.add( 'L_SALES_ORDER_ID' || L_SALES_ORDER_ID , 3 ) ;
6893 END IF;
6894
6895 l_rsv_rec.demand_source_header_id := l_sales_order_id;
6896 l_rsv_rec.demand_source_line_id := l_line_rec.line_id;
6897
6898 -- 02-jun-2000 mpetrosi added org_id to query_reservation start
6899 l_rsv_rec.organization_id := l_line_rec.ship_from_org_id;
6900 -- 02-jun-2000 mpetrosi end change
6901
6902 inv_reservation_pub.query_reservation
6903 ( p_api_version_number => 1.0
6904 , p_init_msg_lst => fnd_api.g_true
6905 , x_return_status => l_return_status
6906 , x_msg_count => l_msg_count
6907 , x_msg_data => l_msg_data
6908 , p_query_input => l_rsv_rec
6909 , p_cancel_order_mode => INV_RESERVATION_GLOBAL.G_CANCEL_ORDER_YES
6910 , x_mtl_reservation_tbl => l_rsv_tbl
6911 , x_mtl_reservation_tbl_count => l_count
6912 , x_error_code => l_x_error_code
6913 , p_lock_records => l_lock_records
6914 , p_sort_by_req_date => l_sort_by_req_date
6915 );
6916
6917 IF l_debug_level > 0 THEN
6918 oe_debug_pub.add( '3. AFTER CALLING QUERY RESERVATION' || L_RETURN_STATUS , 1 ) ;
6919 oe_debug_pub.add( L_MSG_DATA , 1 ) ;
6920 END IF;
6921
6922 l_qty_to_unreserve := p_quantity_to_unreserve;
6923 l_qty2_to_unreserve := p_quantity2_to_unreserve; -- INVCONV
6924 FOR I IN 1..l_rsv_tbl.COUNT LOOP
6925
6926 l_rsv_rec := l_rsv_tbl(I);
6927 IF l_debug_level > 0 THEN
6928 oe_debug_pub.add( 'RESERVED QTY : ' || L_RSV_REC.RESERVATION_QUANTITY , 1 ) ;
6929 oe_debug_pub.add( 'QTY TO UNRESERVE: ' || L_QTY_TO_UNRESERVE , 1 ) ;
6930 oe_debug_pub.add( 'RESERVED QTY2 : ' || L_RSV_REC.secondary_reservation_quantity, 1 ) ;
6931 oe_debug_pub.add( 'QTY2 TO UNRESERVE: ' || L_QTY2_TO_UNRESERVE , 1 ) ;
6932
6933 END IF;
6934
6935 IF (l_rsv_rec.reservation_quantity <= l_qty_to_unreserve)
6936 THEN
6937
6938 IF l_debug_level > 0 THEN
6939 oe_debug_pub.add( 'CALLING INVS DELETE_RESERVATION' , 3 ) ;
6940 END IF;
6941 inv_reservation_pub.delete_reservation
6942 ( p_api_version_number => 1.0
6943 , p_init_msg_lst => fnd_api.g_true
6944 , x_return_status => l_return_status
6945 , x_msg_count => l_msg_count
6946 , x_msg_data => l_msg_data
6947 , p_rsv_rec => l_rsv_rec
6948 , p_serial_number => l_dummy_sn
6949 );
6950
6951 IF l_debug_level > 0 THEN
6952 oe_debug_pub.add( 'AFTER CALLING INVS DELETE_RESERVATION: ' || L_RETURN_STATUS , 1 ) ;
6953 END IF;
6954
6955 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6956 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6957 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
6958 RAISE FND_API.G_EXC_ERROR;
6959 END IF;
6960
6961 l_qty_to_unreserve := l_qty_to_unreserve -
6962 l_rsv_rec.reservation_quantity;
6963
6964 l_qty2_to_unreserve := l_qty2_to_unreserve - -- INVCONV
6965 l_rsv_rec.secondary_reservation_quantity;
6966
6967 IF (l_qty_to_unreserve <= 0) THEN
6968 goto end_of_loop;
6969 END IF;
6970
6971 ELSE
6972
6973 l_rsv_new_rec := l_rsv_rec;
6974 l_rsv_new_rec.reservation_quantity :=
6975 l_rsv_rec.reservation_quantity - l_qty_to_unreserve ;
6976 l_rsv_new_rec.primary_reservation_quantity := fnd_api.g_miss_num;
6977 -- l_rsv_rec.reservation_quantity - l_qty_to_unreserve ;
6978
6979 l_rsv_new_rec.secondary_reservation_quantity := --INVCONV
6980 l_rsv_rec.secondary_reservation_quantity - l_qty2_to_unreserve ;
6981
6982
6983 IF l_debug_level > 0 THEN
6984 oe_debug_pub.add( 'OLD QTY : ' || L_RSV_REC.RESERVATION_QUANTITY , 3 ) ;
6985 oe_debug_pub.add( 'NEW QTY : ' || L_RSV_NEW_REC.RESERVATION_QUANTITY , 3 ) ;
6986 oe_debug_pub.add( 'OLD QTY2 : ' || L_RSV_REC.SECONDARY_RESERVATION_QUANTITY , 3 ) ; -- INVCONV
6987 oe_debug_pub.add( 'NEW QTY2 : ' || L_RSV_NEW_REC.SECONDARY_RESERVATION_QUANTITY , 3 ) ;
6988 END IF;
6989
6990 /* OPM 14/SEP/00 send process attributes into the reservation
6991 =============================================================
6992 IF INV_GMI_RSV_BRANCH.Process_Branch(p_organization_id => l_line_rec.ship_from_org_id) -- OPM 2645605
6993 then
6994
6995 l_rsv_new_rec.attribute1 := p_line_rec.preferred_grade;
6996 l_rsv_new_rec.attribute2 := p_line_rec.ordered_quantity2;
6997 l_rsv_new_rec.attribute3 := p_line_rec.ordered_quantity_uom2;
6998
6999 END IF;
7000
7001 OPM 14/SEP/00 END INVCONV
7002 ====================*/
7003 l_rsv_new_rec.secondary_reservation_quantity := p_line_rec.ordered_quantity2; -- INVCONV
7004 l_rsv_new_rec.secondary_uom_code := p_line_rec.ordered_quantity_uom2;
7005
7006
7007 IF l_debug_level > 0 THEN
7008 oe_debug_pub.add( 'CALLING INVS UPDATE_RESERVATION: ' , 3 ) ;
7009 END IF;
7010
7011 inv_reservation_pub.update_reservation
7012 ( p_api_version_number => 1.0
7013 , p_init_msg_lst => fnd_api.g_true
7014 , x_return_status => l_return_status
7015 , x_msg_count => l_msg_count
7016 , x_msg_data => l_msg_data
7017 , p_original_rsv_rec => l_rsv_rec
7018 , p_to_rsv_rec => l_rsv_new_rec
7019 , p_original_serial_number => l_dummy_sn -- no serial contorl
7020 , p_to_serial_number => l_dummy_sn -- no serial control
7021 , p_validation_flag => fnd_api.g_true
7022 );
7023
7024 IF l_debug_level > 0 THEN
7025 oe_debug_pub.add( 'AFTER CALLING INVS UPDATE_RESERVATION: ' || L_RETURN_STATUS , 1 ) ;
7026 END IF;
7027
7028 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7029 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7030 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
7031 IF l_msg_data is not null THEN
7032 fnd_message.set_encoded(l_msg_data);
7033 l_buffer := fnd_message.get;
7034 oe_msg_pub.add_text(p_message_text => l_buffer);
7035 IF l_debug_level > 0 THEN
7036 oe_debug_pub.add( 'ERROR : '|| L_BUFFER , 1 ) ;
7037 END IF;
7038 END IF;
7039 RAISE FND_API.G_EXC_ERROR;
7040 END IF;
7041
7042 l_qty_to_unreserve := 0;
7043
7044 IF (l_qty_to_unreserve <= 0) THEN
7045 goto end_of_loop;
7046 END IF;
7047
7048
7049 END IF;
7050 END LOOP;
7051 <<end_of_loop>>
7052 null;
7053
7054 IF l_debug_level > 0 THEN
7055 oe_debug_pub.add( 'EXITING UNRESERVE_LINES' , 3 ) ;
7056 END IF;
7057
7058 EXCEPTION
7059 WHEN FND_API.G_EXC_ERROR THEN
7060
7061 x_return_status := FND_API.G_RET_STS_ERROR;
7062
7063 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7064
7065 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7066
7067 WHEN OTHERS THEN
7068
7069 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7070
7071 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
7072 THEN
7073 OE_MSG_PUB.Add_Exc_Msg
7074 ( G_PKG_NAME
7075 , 'Schedule_line'
7076 );
7077 END IF;
7078
7079 END Unreserve_Line;
7080
7081 /*--------------------------------------------------------------------------
7082 Procedure Name : Create_Group_Request
7083 Description : This procedure is called to create a group request for
7084 group_scheduling.
7085 We have 4 scheduling groups:
7086 1. Arrival Set
7087 2. Ship Set
7088 3. Ship Model Complete PTO configuration
7089 4. ATO configuration
7090
7091 The entity type on the x_group_req_rec is populated
7092 based on the type of group it is.
7093
7094 The group attributes are populated on the x_group_req_rec
7095 based on the ones changed.
7096 -------------------------------------------------------------------------- */
7097 Procedure Create_Group_Request
7098 ( p_line_rec IN OE_ORDER_PUB.line_rec_type
7099 , p_old_line_rec IN OE_ORDER_PUB.line_rec_type
7100 , x_group_req_rec OUT NOCOPY /* file.sql.39 change */ OE_GRP_SCH_UTIL.Sch_Group_Rec_Type
7101 , x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2
7102 )
7103 IS
7104 l_group_req_rec OE_GRP_SCH_UTIL.Sch_Group_Rec_Type; -- INVCONV PAL - not sure if need to change this - purpose of this ?
7105 --
7106 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
7107 --
7108 BEGIN
7109 IF l_debug_level > 0 THEN
7110 oe_debug_pub.add( 'ENTERING CREATE_GROUP_REQUEST' , 1 ) ;
7111 END IF;
7112
7113 IF (p_line_rec.arrival_set_id is not null) THEN
7114 l_group_req_rec.entity_type := OESCH_ENTITY_ARRIVAL_SET;
7115 l_group_req_rec.arrival_set_number := p_line_rec.arrival_set_id;
7116 ELSIF (p_line_rec.ship_set_id is not null) THEN
7117 l_group_req_rec.entity_type := OESCH_ENTITY_SHIP_SET;
7118 l_group_req_rec.ship_set_number := p_line_rec.ship_set_id;
7119 ELSIF (p_line_rec.ship_model_complete_flag ='Y') THEN
7120 l_group_req_rec.entity_type := OESCH_ENTITY_SMC;
7121 l_group_req_rec.ship_set_number := p_line_rec.top_model_line_id;
7122 ELSIF (p_line_rec.ato_line_id is not null) THEN
7123 l_group_req_rec.entity_type := OESCH_ENTITY_ATO_CONFIG;
7124 l_group_req_rec.ship_set_number := p_line_rec.ato_line_id;
7125 END IF;
7126
7127 l_group_req_rec.header_id := p_line_rec.header_id;
7128 l_group_req_rec.line_id := p_line_rec.line_id;
7129 IF p_line_rec.schedule_action_code is not null THEN
7130 l_group_req_rec.action := p_line_rec.schedule_action_code;
7131 ELSE
7132 l_group_req_rec.action := OESCH_ACT_RESCHEDULE;
7133 END IF;
7134
7135 IF p_line_rec.ship_from_org_id is NOT NULL and
7136 p_line_rec.ship_from_org_id <> FND_API.G_MISS_NUM
7137 THEN
7138 l_group_req_rec.ship_from_org_id := p_line_rec.ship_from_org_id;
7139 END IF;
7140
7141 -- Added this code to fix bug 1894284.
7142 IF p_old_line_rec.ship_from_org_id is NOT NULL and
7143 p_old_line_rec.ship_from_org_id <> FND_API.G_MISS_NUM
7144 THEN
7145 l_group_req_rec.old_ship_from_org_id := p_old_line_rec.ship_from_org_id;
7146 END IF;
7147
7148 IF NOT OE_GLOBALS.Equal(p_line_rec.request_date,
7149 p_old_line_rec.request_date) THEN
7150 l_group_req_rec.request_date := p_line_rec.request_date;
7151 END IF;
7152
7153 IF NOT OE_GLOBALS.Equal(p_line_rec.schedule_ship_date,
7154 p_old_line_rec.schedule_ship_date)
7155 THEN
7156
7157 l_group_req_rec.schedule_ship_date := p_line_rec.schedule_ship_date;
7158
7159 -- If the old date is missing, then set the action as SCHEDULE
7160
7161 IF (p_old_line_rec.schedule_ship_date is null OR
7162 p_old_line_rec.schedule_ship_date = FND_API.G_MISS_DATE) THEN
7163 l_group_req_rec.action := OESCH_ACT_SCHEDULE;
7164 END IF;
7165
7166 END IF;
7167
7168 IF NOT OE_GLOBALS.Equal(p_line_rec.schedule_arrival_date,
7169 p_old_line_rec.schedule_arrival_date)
7170 THEN
7171
7172 l_group_req_rec.schedule_arrival_date :=
7173 p_line_rec.schedule_arrival_date;
7174
7175 -- If the old date is missing, then set the action as SCHEDULE
7176
7177 IF (p_old_line_rec.schedule_arrival_date is null OR
7178 p_old_line_rec.schedule_arrival_date = FND_API.G_MISS_DATE)
7179 THEN
7180 l_group_req_rec.action := OESCH_ACT_SCHEDULE;
7181 END IF;
7182
7183 END IF;
7184
7185 IF NOT OE_GLOBALS.Equal(p_line_rec.shipping_method_code,
7186 p_old_line_rec.shipping_method_code) THEN
7187
7188 -- NOTE!!!!
7189 -- We are storing the shipping_method_code value in the
7190 -- freight_carrier field of the l_group_req_rec.
7191
7192 l_group_req_rec.freight_carrier := p_line_rec.shipping_method_code;
7193
7194 END IF;
7195
7196 IF NOT OE_GLOBALS.Equal(p_line_rec.ship_to_org_id,
7197 p_old_line_rec.ship_to_org_id) THEN
7198 l_group_req_rec.ship_to_org_id := p_line_rec.ship_to_org_id;
7199 END IF;
7200
7201 IF NOT OE_GLOBALS.Equal(p_line_rec.ordered_quantity,
7202 p_old_line_rec.ordered_quantity) THEN
7203 l_group_req_rec.quantity := p_line_rec.ordered_quantity;
7204 l_group_req_rec.old_quantity := p_old_line_rec.ordered_quantity;
7205 END IF;
7206
7207 l_group_req_rec.old_ship_set_number := p_old_line_rec.ship_set_id;
7208 l_group_req_rec.old_arrival_set_number := p_old_line_rec.arrival_set_id;
7209
7210 IF l_debug_level > 0 THEN
7211 oe_debug_pub.add( '*********PRINTING GROUP REQUEST ATTRIBUTES***********' , 1 ) ;
7212 oe_debug_pub.add( 'GROUP ENTITY :' || L_GROUP_REQ_REC.ENTITY_TYPE , 1 ) ;
7213 oe_debug_pub.add( 'GROUP HEADER ID :' || L_GROUP_REQ_REC.HEADER_ID , 1 ) ;
7214 oe_debug_pub.add( 'LINE ID :' || L_GROUP_REQ_REC.LINE_ID , 1 ) ;
7215 oe_debug_pub.add( 'GROUP ACTION :' || L_GROUP_REQ_REC.ACTION , 1 ) ;
7216 oe_debug_pub.add( 'GROUP WAREHOUSE :' || L_GROUP_REQ_REC.SHIP_FROM_ORG_ID , 1 ) ;
7217 oe_debug_pub.add( 'GROUP SHIP TO :' || L_GROUP_REQ_REC.SHIP_TO_ORG_ID , 1 ) ;
7218 oe_debug_pub.add( 'GROUP SHIP SET# :' || L_GROUP_REQ_REC.SHIP_SET_NUMBER , 1 ) ;
7219 oe_debug_pub.add( 'GROUP ARR SET# :' || L_GROUP_REQ_REC.ARRIVAL_SET_NUMBER , 1 ) ;
7220 oe_debug_pub.add( 'SHIP METHOD :' || L_GROUP_REQ_REC.FREIGHT_CARRIER , 1 ) ;
7221 oe_debug_pub.add( 'GRP REQUEST DATE :' || L_GROUP_REQ_REC.REQUEST_DATE , 1 ) ;
7222 oe_debug_pub.add( 'GRP SHIP DATE :' || L_GROUP_REQ_REC.SCHEDULE_SHIP_DATE , 1 ) ;
7223 oe_debug_pub.add( 'GRP ARRIVAL DATE :' || L_GROUP_REQ_REC.SCHEDULE_ARRIVAL_DATE , 1 ) ;
7224 END IF;
7225
7226 x_group_req_rec := l_group_req_rec;
7227
7228 IF l_debug_level > 0 THEN
7229 oe_debug_pub.add( 'EXITING CREATE_GROUP_REQUEST' , 1 ) ;
7230 END IF;
7231
7232 END Create_Group_Request;
7233
7234 /*--------------------------------------------------------------------------
7235 Procedure Name : Call_ATP
7236 Description : ** Not Used **
7237 -------------------------------------------------------------------------- */
7238
7239 PROCEDURE Call_ATP
7240 ( p_atp_table IN MRP_ATP_PUB.ATP_Rec_Typ
7241 , x_atp_table OUT NOCOPY /* file.sql.39 change */ MRP_ATP_PUB.ATP_Rec_Typ
7242 , x_atp_supply_demand OUT NOCOPY /* file.sql.39 change */ MRP_ATP_PUB.ATP_Supply_Demand_Typ
7243 , x_atp_period OUT NOCOPY /* file.sql.39 change */ MRP_ATP_PUB.ATP_Period_Typ
7244 , x_atp_details OUT NOCOPY /* file.sql.39 change */ MRP_ATP_PUB.ATP_Details_Typ
7245 , x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2
7246 , x_msg_data OUT NOCOPY /* file.sql.39 change */ VARCHAR2
7247 , x_msg_count OUT NOCOPY /* file.sql.39 change */ NUMBER)
7248 IS
7249 I NUMBER;
7250 --
7251 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
7252 --
7253 BEGIN
7254 I := 1;
7255 IF l_debug_level > 0 THEN
7256 oe_debug_pub.add( 'ENTERING CALL ATP' , 1 ) ;
7257 oe_debug_pub.add( P_ATP_TABLE.INVENTORY_ITEM_ID ( 1 ) ) ;
7258 END IF;
7259
7260 x_atp_table := p_atp_table;
7261
7262 x_atp_table.Requested_Date_Quantity := MRP_ATP_PUB.number_arr
7263 (p_atp_table.Quantity_Ordered(I));
7264 x_atp_table.Source_Organization_Id := MRP_ATP_PUB.number_arr(204);
7265 x_atp_table.Requested_Date_Quantity := MRP_ATP_PUB.number_arr(967900);
7266 x_atp_table.error_code := MRP_ATP_PUB.number_arr(0);
7267 x_return_status := FND_API.G_RET_STS_SUCCESS;
7268 x_msg_count := 0;
7269 null;
7270
7271 IF l_debug_level > 0 THEN
7272 oe_debug_pub.add( 'EXITING CALL ATP' , 1 ) ;
7273 END IF;
7274 END;
7275
7276 /*--------------------------------------------------------------------------
7277 Procedure Name : Load_Results
7278 Description : This API loads the results from MRP's ATP_REC_TYPE to
7279 OM's order line. It also populates OM's ATP Table which
7280 is used to display the ATP results on the client side.
7281 We ignore the mandatory components which we passed to MRP
7282 while loading the results.
7283 -------------------------------------------------------------------------- */
7284 Procedure Load_Results
7285 ( p_atp_table IN MRP_ATP_PUB.ATP_Rec_Typ
7286 , p_x_line_tbl IN OUT NOCOPY OE_ORDER_PUB.line_tbl_type
7287 , x_atp_tbl OUT NOCOPY /* file.sql.39 change */ OE_ATP.ATP_Tbl_Type
7288 , x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
7289 IS
7290 I NUMBER := 0;
7291 J NUMBER := 0;
7292 ATP NUMBER := 0;
7293 l_line_rec OE_ORDER_PUB.line_rec_type;
7294 l_atp_rec OE_ATP.atp_rec_type;
7295 l_msg_count NUMBER;
7296 l_msg_data VARCHAR2(2000);
7297 l_explanation VARCHAR2(80);
7298 l_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
7299 l_type_code VARCHAR2(30);
7300 l_ship_set_name VARCHAR2(30);
7301 l_arrival_set_name VARCHAR2(30);
7302 l_arrival_date DATE := NULL;
7303 l_config_exists VARCHAR2(1):= 'N';
7304 l_organization_id NUMBER; -------- Bug -2316250
7305 l_inventory_item VARCHAR2(2000); -------- Bug - 2316250
7306 l_old_ato_line_id Number := -99;
7307
7308 --
7309 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
7310 --
7311 BEGIN
7312 IF l_debug_level > 0 THEN
7313 oe_debug_pub.add( '2. ENTERING LOAD_RESULTS' , 1 ) ;
7314 oe_debug_pub.add( '-----------------LOADING MRP RESULTS---------------' , 1 ) ;
7315 oe_debug_pub.add( 'MRP COUNT IS ' || P_ATP_TABLE.ERROR_CODE.COUNT , 1 ) ;
7316 oe_debug_pub.add( 'LINE COUNT IS ' || P_X_LINE_TBL.COUNT , 1 ) ;
7317 END IF;
7318
7319 J := J + 1;
7320 FOR I in 1..p_x_line_tbl.count LOOP
7321
7322
7323 -- Added code to fix bug 1925326
7324 IF p_x_line_tbl(I).ato_line_id is not null
7325 AND p_x_line_tbl(I).ato_line_id <> l_old_ato_line_id
7326 THEN
7327
7328 l_old_ato_line_id := p_x_line_tbl(I).ato_line_id;
7329 IF l_debug_level > 0 THEN
7330 oe_debug_pub.add('Check for config on line ' || P_X_LINE_TBL(I).ATO_LINE_ID , 1 ) ;
7331 END IF;
7332 BEGIN
7333
7334 Select 'Y'
7335 Into l_config_exists
7336 From oe_order_lines_all
7337 Where header_id = p_x_line_tbl(I).header_id
7338 And ato_line_id = p_x_line_tbl(I).ato_line_id
7339 And item_type_code = OE_GLOBALS.G_ITEM_CONFIG;
7340
7341 EXCEPTION
7342 WHEN OTHERS THEN
7343 IF l_debug_level > 0 THEN
7344 oe_debug_pub.add( 'NO CONFIG EXISTS FOR ATO ' , 1 ) ;
7345 END IF;
7346 l_config_exists := 'N';
7347 END;
7348
7349 END IF;
7350
7351 l_line_rec := p_x_line_tbl(I);
7352
7353 IF l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_CONFIG THEN
7354
7355 -- The config item might be a part of the table since query
7356 -- of a group of lines returns back the config item too. But
7357 -- we did not pass this item to MRP (in load_mrp_request). Thus
7358 -- we will bypass this record out here too.
7359
7360 -- Since we don't pass config line to MRP we need populate schedule date
7361 -- on config from Model line. This is to fix bug1576412.
7362
7363 IF OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
7364 OESCH_ACT_RESCHEDULE) THEN
7365
7366 -- Modified this part to fix bug 1900085.
7367 IF l_debug_level > 0 THEN
7368 oe_debug_pub.add( 'UPDATING CONFIG LINE ' || L_LINE_REC.LINE_ID , 1 ) ;
7369 END IF;
7370 IF p_atp_table.group_ship_date(1) IS NOT NULL
7371 THEN
7372 l_line_rec.schedule_ship_date := p_atp_table.group_ship_date(1);
7373 l_line_rec.schedule_arrival_date :=
7374 l_line_rec.schedule_ship_date +
7375 nvl(p_atp_table.delivery_lead_time(1),0);
7376
7377 ELSIF p_atp_table.group_arrival_date(1) IS NOT NULL
7378 THEN
7379 l_line_rec.schedule_arrival_date :=
7380 p_atp_table.group_arrival_date(1);
7381 l_line_rec.schedule_ship_date :=
7382 l_line_rec.schedule_arrival_date -
7383 nvl(p_atp_table.delivery_lead_time(1),0);
7384
7385 END IF;
7386
7387 -- l_line_rec.schedule_ship_date := p_atp_table.group_ship_date(1);
7388
7389 -- Get the arrival_date from model and populate the same to
7390 -- Config line. The l_arrival_date should be used only for
7391 -- populating config.
7392
7393 -- l_line_rec.schedule_arrival_date := l_arrival_date;
7394
7395 IF l_debug_level > 0 THEN
7396 oe_debug_pub.add( 'CONFIG SCHEDULE ' || L_LINE_REC.SCHEDULE_SHIP_DATE , 2 ) ;
7397 oe_debug_pub.add( 'CONFIG ARRIVAL ' || L_LINE_REC.SCHEDULE_ARRIVAL_DATE , 2 ) ;
7398 END IF;
7399 END IF;
7400
7401 goto end_loop;
7402
7403 END IF;
7404
7405 -- Setting Message Context
7406
7407
7408 IF l_debug_level > 0 THEN
7409 oe_debug_pub.add( 'SCHEDULE ACTION CODE ' || L_LINE_REC.SCHEDULE_ACTION_CODE , 1 ) ;
7410 END IF;
7411
7412 IF (p_atp_table.error_code(J) <> 0) AND
7413 NOT OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
7414 OESCH_ACT_ATP_CHECK) AND
7415 (p_atp_table.error_code(J) <> -99 ) AND -- Multi org changes.
7416 (p_atp_table.error_code(J) <> 150) -- to fix bug 1880166
7417
7418 THEN
7419
7420 IF l_debug_level > 0 THEN
7421 oe_debug_pub.add( 'ERROR FROM MRP: ' || P_ATP_TABLE.ERROR_CODE ( J ) , 1 ) ;
7422 END IF;
7423 IF p_atp_table.error_code(J) = 80 THEN
7424 FND_MESSAGE.SET_NAME('ONT','OE_SCH_NO_SOURCE');
7425 OE_MSG_PUB.Add;
7426 ELSE
7427
7428 IF l_debug_level > 0 THEN
7429 oe_debug_pub.add( 'SCHEDULING FAILED' , 1 ) ;
7430 oe_debug_pub.add( P_ATP_TABLE.ERROR_CODE ( J ) , 1 ) ;
7431 END IF;
7432
7433 OE_MSG_PUB.set_msg_context(
7434 p_entity_code => 'LINE'
7435 ,p_entity_id => l_line_rec.line_id
7436 ,p_header_id => l_line_rec.header_id
7437 ,p_line_id => l_line_rec.line_id
7438 ,p_order_source_id => l_line_rec.order_source_id
7439 ,p_orig_sys_document_ref => l_line_rec.orig_sys_document_ref
7440 ,p_orig_sys_document_line_ref => l_line_rec.orig_sys_line_ref
7441 ,p_orig_sys_shipment_ref => l_line_rec.orig_sys_shipment_ref
7442 ,p_change_sequence => l_line_rec.change_sequence
7443 ,p_source_document_type_id => l_line_rec.source_document_type_id
7444 ,p_source_document_id => l_line_rec.source_document_id
7445 ,p_source_document_line_id => l_line_rec.source_document_line_id );
7446
7447 l_explanation := null;
7448
7449 select meaning
7450 into l_explanation
7451 from mfg_lookups where
7452 lookup_type = 'MTL_DEMAND_INTERFACE_ERRORS'
7453 and lookup_code = p_atp_table.error_code(J) ;
7454
7455 IF p_atp_table.error_code(J) = 19 THEN
7456 -- This error code is given for those lines which are
7457 -- in a group and whose scheduling failed due to some other lines.
7458 -- We do not want to give this out as a message.
7459 null;
7460 ELSIF OESCH_PERFORM_GRP_SCHEDULING = 'N' THEN
7461
7462 -- Flag OESCH_PERFORM_GRP_SCHEDULING is set to 'N' when
7463 -- scheduling is called from delayed request to schedule
7464 -- a line being inserted into a set. If there is an error,
7465 -- we will be trying to schedule the whole set again, so
7466 -- we should not display this error message.
7467 null;
7468
7469 -- Commenting below code to fix bug 2389242.
7470 /* ELSIF p_atp_table.Ship_Set_Name(J) is not null OR
7471 p_atp_table.Arrival_Set_Name(J) is not null THEN
7472
7473 -- This line belongs to a scheduling group. We do not want
7474 -- to give out individual messages for each line. We will store
7475 -- them in atp_tbl which can be displayed by the user.
7476 null;
7477 */
7478 ELSE
7479 IF l_debug_level > 0 THEN
7480 oe_debug_pub.add( 'ADDING MESSAGE TO THE STACK' , 1 ) ;
7481 END IF;
7482 FND_MESSAGE.SET_NAME('ONT','OE_SCH_OE_ORDER_FAILED');
7483 FND_MESSAGE.SET_TOKEN('EXPLANATION',l_explanation);
7484 OE_MSG_PUB.Add;
7485 END IF;
7486 END IF;
7487
7488 l_atp_rec.error_message := l_explanation;
7489
7490 l_atp_rec.inventory_item_id := l_line_rec.inventory_item_id;
7491 l_atp_rec.ordered_quantity := l_line_rec.ordered_quantity;
7492 l_atp_rec.order_quantity_uom := l_line_rec.order_quantity_uom;
7493 l_atp_rec.request_date := l_line_rec.request_date;
7494 l_atp_rec.ship_from_org_id :=
7495 p_atp_table.Source_Organization_Id(J);
7496 l_atp_rec.qty_on_request_date :=
7497 p_atp_table.Requested_Date_Quantity(J);
7498 l_atp_rec.ordered_qty_Available_Date :=
7499 p_atp_table.Ship_Date(J);
7500 l_atp_rec.qty_on_available_date :=
7501 p_atp_table.Available_Quantity(J);
7502 l_atp_rec.group_available_date :=
7503 p_atp_table.group_ship_date(J);
7504 IF p_atp_table.group_arrival_date(J) is not null THEN
7505 l_atp_rec.group_available_date :=
7506 p_atp_table.group_arrival_date(J);
7507 END IF;
7508
7509 -- Display Values
7510 l_atp_rec.line_id := l_line_rec.line_id;
7511 l_atp_rec.header_id := l_line_rec.header_id;
7512 l_atp_rec.line_number := l_line_rec.line_number;
7513 l_atp_rec.shipment_number := l_line_rec.shipment_number;
7514 l_atp_rec.option_number := l_line_rec.option_number;
7515 l_atp_rec.item_input := l_line_rec.ordered_item;
7516
7517 IF l_line_rec.ship_set_id is not null THEN
7518 BEGIN
7519 SELECT SET_NAME
7520 INTO l_ship_set_name
7521 FROM OE_SETS
7522 WHERE set_id = l_line_rec.ship_set_id;
7523 EXCEPTION
7524 WHEN NO_DATA_FOUND THEN
7525 l_ship_set_name := null;
7526 END;
7527 END IF;
7528
7529 IF l_line_rec.arrival_set_id is not null THEN
7530 BEGIN
7531 SELECT SET_NAME
7532 INTO l_arrival_set_name
7533 FROM OE_SETS
7534 WHERE set_id = l_line_rec.arrival_set_id;
7535 EXCEPTION
7536 WHEN NO_DATA_FOUND THEN
7537 l_arrival_set_name := null;
7538 END;
7539 END IF;
7540
7541 l_atp_rec.ship_set := l_ship_set_name;
7542 l_atp_rec.arrival_set := l_arrival_set_name;
7543
7544 IF l_debug_level > 0 THEN
7545 oe_debug_pub.add( 'SETTING ERROR' , 1 ) ;
7546 END IF;
7547 l_return_status := FND_API.G_RET_STS_ERROR;
7548
7549 ELSE
7550
7551 IF l_debug_level > 0 THEN
7552 oe_debug_pub.add( 'LOADING ATP RECORD' , 1 ) ;
7553 oe_debug_pub.add( P_ATP_TABLE.SOURCE_ORGANIZATION_ID ( 1 ) , 1 ) ;
7554 oe_debug_pub.add( 'ERROR CODE : ' || P_ATP_TABLE.ERROR_CODE ( J ) , 1 ) ;
7555 END IF;
7556 -- Muti org changes.
7557 IF (p_atp_table.error_code(J) <> -99 ) THEN
7558
7559 IF l_debug_level > 0 THEN
7560 oe_debug_pub.add( '3. ERROR CODE : ' || P_ATP_TABLE.ERROR_CODE ( J ) , 1 ) ;
7561 oe_debug_pub.add( '3. J : ' || J , 3 ) ;
7562 oe_debug_pub.add( '3. IDENTIFIER : ' || P_ATP_TABLE.IDENTIFIER ( J ) , 1 ) ;
7563 oe_debug_pub.add( '3. ITEM : ' || P_ATP_TABLE.INVENTORY_ITEM_ID ( J ) , 1 ) ;
7564 oe_debug_pub.add( '3.REQUEST SHIP DATE :' || TO_CHAR ( P_ATP_TABLE.REQUESTED_SHIP_DATE ( J ) , 'DD-MON-RR:HH:MM:SS' ) , 1 ) ;
7565 oe_debug_pub.add( '3.REQUEST ARRIVAL DATE :' || P_ATP_TABLE.REQUESTED_ARRIVAL_DATE ( J ) , 1 ) ;
7566 oe_debug_pub.add( '3.SHIP DATE :' || TO_CHAR ( P_ATP_TABLE.SHIP_DATE ( J ) , 'DD-MON-RR:HH:MM:SS' ) , 1 ) ;
7567 oe_debug_pub.add( '3.LEAD TIME :' || P_ATP_TABLE.DELIVERY_LEAD_TIME ( J ) , 1 ) ;
7568 oe_debug_pub.add( '3.GROUP SHIP DATE :' || P_ATP_TABLE.GROUP_SHIP_DATE ( J ) , 1 ) ;
7569 oe_debug_pub.add( '3.GROUP ARRIVAL DATE :' || P_ATP_TABLE.GROUP_ARRIVAL_DATE ( J ) , 1 ) ;
7570 END IF;
7571
7572 l_explanation := null;
7573
7574 IF (p_atp_table.error_code(J) <> 0) THEN
7575
7576 BEGIN
7577 select meaning
7578 into l_explanation
7579 from mfg_lookups where
7580 lookup_type = 'MTL_DEMAND_INTERFACE_ERRORS'
7581 and lookup_code = p_atp_table.error_code(J) ;
7582
7583 l_atp_rec.error_message := l_explanation;
7584 IF l_debug_level > 0 THEN
7585 oe_debug_pub.add( 'EXPLANATION IS : ' || L_EXPLANATION , 1 ) ;
7586 END IF;
7587
7588 IF p_atp_table.error_code(J) = 150 THEN -- to fix bug 1880166.
7589 OE_MSG_PUB.add_text(l_explanation);
7590 END IF;
7591
7592 EXCEPTION
7593 WHEN OTHERS THEN
7594 Null;
7595 END;
7596
7597 END IF;
7598
7599 l_atp_rec.inventory_item_id := l_line_rec.inventory_item_id;
7600 l_atp_rec.ordered_quantity := l_line_rec.ordered_quantity;
7601 l_atp_rec.order_quantity_uom := l_line_rec.order_quantity_uom;
7602 l_atp_rec.request_date := l_line_rec.request_date;
7603 l_atp_rec.ship_from_org_id :=
7604 p_atp_table.Source_Organization_Id(J);
7605 l_atp_rec.qty_on_request_date :=
7606 p_atp_table.Requested_Date_Quantity(J);
7607 l_atp_rec.ordered_qty_Available_Date :=
7608 p_atp_table.Ship_Date(J);
7609 l_atp_rec.qty_on_available_date :=
7610 p_atp_table.Available_Quantity(J);
7611 l_atp_rec.group_available_date :=
7612 p_atp_table.group_ship_date(J);
7613 IF p_atp_table.group_arrival_date(J) is not null THEN
7614 l_atp_rec.group_available_date :=
7615 p_atp_table.group_arrival_date(J);
7616 END IF;
7617
7618 -- Display Values
7619 l_atp_rec.line_id := l_line_rec.line_id;
7620 l_atp_rec.header_id := l_line_rec.header_id;
7621 l_atp_rec.line_number := l_line_rec.line_number;
7622 l_atp_rec.shipment_number := l_line_rec.shipment_number;
7623 l_atp_rec.option_number := l_line_rec.option_number;
7624 l_atp_rec.item_input := l_line_rec.ordered_item;
7625 l_atp_rec.error_message := l_explanation;
7626
7627 IF l_line_rec.ship_set_id is not null THEN
7628 BEGIN
7629 SELECT SET_NAME
7630 INTO l_ship_set_name
7631 FROM OE_SETS
7632 WHERE set_id = l_line_rec.ship_set_id;
7633 EXCEPTION
7634 WHEN NO_DATA_FOUND THEN
7635 l_ship_set_name := null;
7636 END;
7637 END IF;
7638
7639 IF l_line_rec.arrival_set_id is not null THEN
7640 BEGIN
7641 SELECT SET_NAME
7642 INTO l_arrival_set_name
7643 FROM OE_SETS
7644 WHERE set_id = l_line_rec.arrival_set_id;
7645 EXCEPTION
7646 WHEN NO_DATA_FOUND THEN
7647 l_arrival_set_name := null;
7648 END;
7649 END IF;
7650
7651 l_atp_rec.ship_set := l_ship_set_name;
7652 l_atp_rec.arrival_set := l_arrival_set_name;
7653
7654 ---------------------- Changes for Bug-2316250 ---------------------------
7655 l_organization_id := OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
7656 --to fix bug 2795033,passing below l_line_rec.ordered_item instead of
7657 --l_line_rec.Original_ordered_item
7658
7659 OE_ID_TO_VALUE.Ordered_Item
7660 (p_Item_Identifier_type => l_line_rec.item_identifier_type
7661 ,p_inventory_item_id => l_line_rec.inventory_item_id
7662 ,p_organization_id => l_organization_id
7663 ,p_ordered_item_id => l_line_rec.ordered_item_id
7664 ,p_sold_to_org_id => l_line_rec.sold_to_org_id
7665 ,p_ordered_item => l_line_rec.ordered_item
7666 ,x_ordered_item => l_atp_rec.Ordered_item_name
7667 ,x_inventory_item => l_inventory_item);
7668
7669 ---------------------- Changes for Bug-2316250 ---------------------------
7670
7671 END IF; --Check for -99.
7672
7673 IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
7674
7675 IF OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
7676 OESCH_ACT_DEMAND)
7677 OR OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
7678 OESCH_ACT_SCHEDULE)
7679 THEN
7680 IF l_debug_level > 0 THEN
7681 oe_debug_pub.add( 'LOADING RESULTS OF SCHEDULE' , 1 ) ;
7682 oe_debug_pub.add( '1.REQUEST SHIP DATE :' || TO_CHAR ( P_ATP_TABLE.REQUESTED_SHIP_DATE ( J ) , 'DD-MON-RR:HH:MM:SS' ) , 1 ) ;
7683 oe_debug_pub.add( '1.REQUEST ARRIVAL DATE :' || P_ATP_TABLE.REQUESTED_ARRIVAL_DATE ( J ) , 1 ) ;
7684 oe_debug_pub.add( '1.SHIP DATE :' || TO_CHAR ( P_ATP_TABLE.SHIP_DATE ( J ) , 'DD-MON-RR:HH:MM:SS' ) , 1 ) ;
7685 oe_debug_pub.add( '1.LEAD TIME :' || P_ATP_TABLE.DELIVERY_LEAD_TIME ( J ) , 1 ) ;
7686 oe_debug_pub.add( '1.GROUP SHIP DATE :' || P_ATP_TABLE.GROUP_SHIP_DATE ( J ) , 1 ) ;
7687 oe_debug_pub.add( '1.GROUP ARRIVAL DATE :' || P_ATP_TABLE.GROUP_ARRIVAL_DATE ( J ) , 1 ) ;
7688 END IF;
7689
7690
7691 l_line_rec.ship_from_org_id :=
7692 p_atp_table.Source_Organization_Id(J);
7693
7694 l_line_rec.schedule_ship_date := p_atp_table.ship_date(J);
7695
7696 /* ------------------------Bug 2327620 Start -------------------
7697 IF l_line_rec.latest_acceptable_date is not null THEN
7698 IF l_line_rec.latest_acceptable_date <
7699 l_line_rec.schedule_ship_date
7700 THEN
7701 l_line_rec.latest_acceptable_date :=
7702 l_line_rec.schedule_ship_date;
7703 END IF;
7704 ELSE
7705 OE_DEBUG_PUB.Add('Latest Acceptable Date is NULL');
7706 l_line_rec.latest_acceptable_date :=
7707 l_line_rec.schedule_ship_date;
7708 END IF;
7709 ------------------------Bug 2327620 End ------------------- */
7710
7711 l_line_rec.schedule_arrival_date :=
7712 p_atp_table.ship_date(J) +
7713 nvl(p_atp_table.delivery_lead_time(J),0);
7714
7715 IF p_atp_table.group_arrival_date(J) IS NOT NULL
7716 THEN
7717 l_line_rec.schedule_arrival_date :=
7718 p_atp_table.group_arrival_date(J);
7719 l_line_rec.schedule_ship_date :=
7720 l_line_rec.schedule_arrival_date -
7721 nvl(p_atp_table.delivery_lead_time(J),0);
7722
7723 /* ------------------------Bug 2327620 Start -------------------
7724 IF l_line_rec.latest_acceptable_date is not null THEN
7725 IF l_line_rec.latest_acceptable_date <
7726 l_line_rec.schedule_arrival_date
7727 THEN
7728 l_line_rec.latest_acceptable_date :=
7729 l_line_rec.schedule_arrival_date;
7730 END IF;
7731 ELSE
7732 OE_DEBUG_PUB.Add('Latest Acceptable Date is NULL');
7733 l_line_rec.latest_acceptable_date :=
7734 l_line_rec.schedule_arrival_date;
7735 END IF;
7736
7737 ------------------------Bug 2327620 End ------------------- */
7738
7739 END IF;
7740
7741 IF p_atp_table.group_ship_date(J) IS NOT NULL
7742 THEN
7743 l_line_rec.schedule_ship_date := p_atp_table.group_ship_date(J);
7744 l_line_rec.schedule_arrival_date :=
7745 l_line_rec.schedule_ship_date +
7746 nvl(p_atp_table.delivery_lead_time(J),0);
7747
7748 /* ------------------------Bug 2327620 Start -------------------
7749 IF l_line_rec.latest_acceptable_date is not null THEN
7750 IF l_line_rec.latest_acceptable_date <
7751 l_line_rec.schedule_ship_date
7752 THEN
7753 l_line_rec.latest_acceptable_date :=
7754 l_line_rec.schedule_ship_date;
7755 END IF;
7756 ELSE
7757 OE_DEBUG_PUB.Add('Latest Acceptable Date is NULL');
7758 l_line_rec.latest_acceptable_date :=
7759 l_line_rec.schedule_ship_date;
7760 END IF;
7761 ------------------------Bug 2327620 End ------------------- */
7762 END IF;
7763
7764 IF p_atp_table.ship_method(J) IS NOT NULL THEN
7765 l_line_rec.shipping_method_code := p_atp_table.ship_method(J);
7766 END IF;
7767
7768 l_line_rec.delivery_lead_time := p_atp_table.delivery_lead_time(J);
7769 l_line_rec.mfg_lead_time := p_atp_table.atp_lead_time(J);
7770 l_line_rec.schedule_status_code := OESCH_STATUS_SCHEDULED;
7771
7772 IF l_debug_level > 0 THEN
7773 oe_debug_pub.add( 'BEFORE ATTRIBUTE 05' , 5 ) ;
7774 END IF;
7775
7776 -- bug fix 1965182/1925326
7777 IF p_atp_table.attribute_05.COUNT > 0 THEN
7778 IF p_atp_table.attribute_05(J) IS NULL THEN
7779 IF l_config_exists = 'N' THEN
7780 l_line_rec.visible_demand_flag := 'Y';
7781 ELSE
7782 IF l_debug_level > 0 THEN
7783 oe_debug_pub.add( 'INSIDE CONFIG EXISTS' , 3 ) ;
7784 END IF;
7785 END IF;
7786
7787 ELSIF p_atp_table.attribute_05(J) = 'N' THEN
7788 l_line_rec.visible_demand_flag := 'N';
7789 ELSIF p_atp_table.attribute_05(J) = 'Y' THEN
7790 l_line_rec.visible_demand_flag := 'Y';
7791 END IF;
7792 ELSE
7793 IF l_config_exists = 'N' THEN
7794 l_line_rec.visible_demand_flag := 'Y';
7795 ELSE
7796 IF l_debug_level > 0 THEN
7797 oe_debug_pub.add( 'CONFIG EXISTS' , 3 ) ;
7798 END IF;
7799 END IF;
7800 END IF;
7801 IF l_debug_level > 0 THEN
7802 oe_debug_pub.add( 'AFTER ATTRIBUTE 05' , 5 ) ;
7803 END IF;
7804
7805 -- We had set the ship_set and arrival_set (which are value
7806 -- fields) to the set name values for calling MRP purpose.
7807 -- Setting these back to null since sets defaulting logic
7808 -- gets fired if these values are populated.
7809
7810 IF l_line_rec.ship_set_id IS NOT NULL
7811 AND l_line_rec.ship_set_id <> FND_API.G_MISS_NUM THEN
7812 l_line_rec.ship_set := null;
7813 END IF;
7814
7815 IF l_line_rec.arrival_set_id IS NOT NULL
7816 AND l_line_rec.arrival_set_id <> FND_API.G_MISS_NUM THEN
7817 l_line_rec.arrival_set := null;
7818 END IF;
7819
7820
7821 -- Bug 2375055 Start
7822 -- Adding code to trap if mrp is returning success and not
7823 -- returning correct data to OM.
7824 /* Modified the following if condition to fix the bug 2919141 */
7825 IF (l_line_rec.schedule_ship_date is null) and (l_line_rec.ordered_quantity <> 0) THEN
7826 IF l_debug_level > 0 THEN
7827 oe_debug_pub.add( 'SCH: MRP HAS RETURNED A NULL SHIP DATE' , 2 ) ;
7828 END IF;
7829 l_line_rec.visible_demand_flag := 'N';
7830 FND_MESSAGE.SET_NAME('ONT','OE_SCH_ATP_ERROR');
7831 OE_MSG_PUB.Add;
7832 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7833 END IF;
7834 -- Bug 2375055 End
7835
7836
7837
7838 ELSIF OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
7839 OESCH_ACT_REDEMAND) OR
7840 OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
7841 OESCH_ACT_RESCHEDULE)
7842 THEN
7843 IF l_debug_level > 0 THEN
7844 oe_debug_pub.add( 'LOAD THE RESULT OF RESCHEDULE' , 3 ) ;
7845 oe_debug_pub.add( '2.REQUEST SHIP DATE :' || P_ATP_TABLE.REQUESTED_SHIP_DATE ( J ) , 3 ) ;
7846 oe_debug_pub.add( '2.REQUEST ARRIVAL DATE :' || P_ATP_TABLE.REQUESTED_ARRIVAL_DATE ( J ) , 3 ) ;
7847 oe_debug_pub.add( '2.SHIP DATE :' || TO_CHAR ( P_ATP_TABLE.SHIP_DATE ( J ) , 'DD-MON-RR:HH:MM:SS' ) , 3 ) ;
7848 oe_debug_pub.add( '2.LEAD TIME :' || P_ATP_TABLE.DELIVERY_LEAD_TIME ( J ) , 3 ) ;
7849 oe_debug_pub.add( '2.GROUP SHIP DATE :' || P_ATP_TABLE.GROUP_SHIP_DATE ( J ) , 3 ) ;
7850 oe_debug_pub.add( '2.GROUP ARRIVAL DATE :' || P_ATP_TABLE.GROUP_ARRIVAL_DATE ( J ) , 3 ) ;
7851 END IF;
7852
7853 l_line_rec.ship_from_org_id :=
7854 p_atp_table.Source_Organization_Id(J);
7855
7856 l_line_rec.schedule_ship_date := p_atp_table.ship_date(J);
7857
7858 /* ------------------------Bug 2327620 Start -------------------
7859 IF l_line_rec.latest_acceptable_date is not null THEN
7860 IF l_line_rec.latest_acceptable_date <
7861 l_line_rec.schedule_ship_date
7862 THEN
7863 l_line_rec.latest_acceptable_date :=
7864 l_line_rec.schedule_ship_date;
7865 END IF;
7866 ELSE
7867 l_line_rec.latest_acceptable_date :=
7868 l_line_rec.schedule_ship_date;
7869 END IF;
7870 ------------------------Bug 2327620 End ------------------- */
7871
7872 l_line_rec.schedule_arrival_date :=
7873 p_atp_table.ship_date(J) +
7874 nvl(p_atp_table.delivery_lead_time(J),0);
7875
7876 IF p_atp_table.group_ship_date(J) IS NOT NULL
7877 THEN
7878 l_line_rec.schedule_ship_date := p_atp_table.group_ship_date(J);
7879 l_line_rec.schedule_arrival_date :=
7880 l_line_rec.schedule_ship_date +
7881 nvl(p_atp_table.delivery_lead_time(J),0);
7882
7883 /* ------------------------Bug 2327620 Start -------------------
7884 IF l_line_rec.latest_acceptable_date is not null THEN
7885 IF l_line_rec.latest_acceptable_date <
7886 l_line_rec.schedule_ship_date
7887 THEN
7888 l_line_rec.latest_acceptable_date :=
7889 l_line_rec.schedule_ship_date;
7890 END IF;
7891 ELSE
7892 l_line_rec.latest_acceptable_date :=
7893 l_line_rec.schedule_ship_date;
7894 END IF;
7895 ------------------------Bug 2327620 End ------------------- */
7896
7897 END IF;
7898
7899 IF p_atp_table.group_arrival_date(J) IS NOT NULL
7900 THEN
7901 l_line_rec.schedule_arrival_date :=
7902 p_atp_table.group_arrival_date(J);
7903 l_line_rec.schedule_ship_date :=
7904 l_line_rec.schedule_arrival_date -
7905 nvl(p_atp_table.delivery_lead_time(J),0);
7906
7907 /* ------------------------Bug 2327620 Start -------------------
7908 IF l_line_rec.latest_acceptable_date is not null THEN
7909 IF l_line_rec.latest_acceptable_date <
7910 l_line_rec.schedule_ship_date
7911 THEN
7912 l_line_rec.latest_acceptable_date :=
7913 l_line_rec.schedule_ship_date;
7914 END IF;
7915 ELSE
7916 l_line_rec.latest_acceptable_date :=
7917 l_line_rec.schedule_ship_date;
7918 END IF;
7919
7920 ------------------------Bug 2327620 End ------------------- */
7921 END IF;
7922
7923 IF p_atp_table.ship_method(J) IS NOT NULL THEN
7924 l_line_rec.shipping_method_code := p_atp_table.ship_method(J);
7925 END IF;
7926
7927 l_line_rec.delivery_lead_time := p_atp_table.delivery_lead_time(J);
7928 l_line_rec.mfg_lead_time := p_atp_table.atp_lead_time(J);
7929
7930 -- When a new option is added to scheduled SMC/SET OM will
7931 -- call MRP with action re-schedule. So, for the new line we need to
7932 -- assign the following values.
7933
7934 l_line_rec.schedule_status_code := OESCH_STATUS_SCHEDULED;
7935
7936 --- Bug 1925326
7937 IF l_debug_level > 0 THEN
7938 oe_debug_pub.add( 'RSCH BEFORE ATTRIBUTE 05' , 5 ) ;
7939 END IF;
7940 IF p_atp_table.attribute_05.COUNT > 0 THEN
7941
7942 IF p_atp_table.attribute_05(J) IS NULL THEN
7943
7944 IF l_config_exists = 'N' THEN
7945 l_line_rec.visible_demand_flag := 'Y';
7946 ELSE
7947 IF l_debug_level > 0 THEN
7948 oe_debug_pub.add( 'RSCH INSIDE: CONFIG EXISTS' , 3 ) ;
7949 END IF;
7950 END IF;
7951
7952 ELSIF p_atp_table.attribute_05(J) = 'N' THEN
7953 l_line_rec.visible_demand_flag := 'N';
7954 ELSIF p_atp_table.attribute_05(J) = 'Y' THEN
7955 l_line_rec.visible_demand_flag := 'Y';
7956 END IF;
7957 ELSE
7958
7959 -- Check if config exists. If exists then leave
7960 -- visible demand flag as it is.
7961 IF l_config_exists = 'N' THEN
7962 l_line_rec.visible_demand_flag := 'Y';
7963 ELSE
7964 IF l_debug_level > 0 THEN
7965 oe_debug_pub.add( 'RSCH: CONFIG EXISTS' , 3 ) ;
7966 END IF;
7967 END IF;
7968
7969 END IF;
7970 IF l_debug_level > 0 THEN
7971 oe_debug_pub.add( 'RSCH AFTER ATTRIBUTE 05' , 5 ) ;
7972 END IF;
7973
7974 IF (l_line_rec.ordered_quantity = 0)
7975 THEN
7976 -- Conditional clearing code has beed added as
7977 -- part of CMS changes. Bug 2101332.
7978 IF l_debug_level > 0 THEN
7979 oe_debug_pub.add( 'LOAD THE RESULTS OF RESCHEDULE: ' || L_LINE_REC.RE_SOURCE_FLAG , 1 ) ;
7980 END IF;
7981 -- 2388445 commenting below code.
7982 /* IF l_line_rec.re_source_flag='Y' or
7983 l_line_rec.re_source_flag is null THEN
7984 oe_debug_pub.add('Setting Ship From to null',1);
7985 l_line_rec.ship_from_org_id := null;
7986 END IF; */
7987 l_line_rec.schedule_ship_date := null;
7988 l_line_rec.schedule_arrival_date := null;
7989 l_line_rec.schedule_status_code := null;
7990 END IF;
7991
7992 -- We had set the ship_set and arrival_set (which are value
7993 -- fields) to the set name values for calling MRP purpose.
7994 -- Setting these back to null since sets defaulting logic
7995 -- gets fired if these values are populated.
7996
7997 IF l_line_rec.ship_set_id IS NOT NULL
7998 AND l_line_rec.ship_set_id <> FND_API.G_MISS_NUM THEN
7999 l_line_rec.ship_set := null;
8000 END IF;
8001
8002 IF l_line_rec.arrival_set_id IS NOT NULL
8003 AND l_line_rec.arrival_set_id <> FND_API.G_MISS_NUM THEN
8004 l_line_rec.arrival_set := null;
8005 END IF;
8006
8007 IF l_line_rec.top_model_line_id = l_line_rec.line_id THEN
8008
8009 IF l_debug_level > 0 THEN
8010 oe_debug_pub.add( 'STORE ARRIVAL_DATE ' || L_LINE_REC.SCHEDULE_ARRIVAL_DATE , 2 ) ;
8011 END IF;
8012 l_arrival_date := l_line_rec.schedule_arrival_date;
8013
8014 END IF;
8015
8016
8017 -- Bug 2375055 Start
8018 -- Adding code to trap if mrp is returning success and not
8019 -- returning correct data to OM.
8020 /* Modified the following if condition to fix the bug 2919141 */
8021 IF (l_line_rec.schedule_ship_date is null) and (l_line_rec.ordered_quantity <> 0) THEN
8022 IF l_debug_level > 0 THEN
8023 oe_debug_pub.add( 'SCH: MRP HAS RETURNED A NULL SHIP DATE' , 2 ) ;
8024 END IF;
8025 l_line_rec.visible_demand_flag := 'N';
8026 FND_MESSAGE.SET_NAME('ONT','OE_SCH_ATP_ERROR');
8027 OE_MSG_PUB.Add;
8028 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8029 END IF;
8030 -- Bug 2375055 End
8031
8032
8033 ELSIF OE_GLOBALS.Equal(l_line_rec.schedule_action_code,
8034 OESCH_ACT_UNDEMAND)
8035 THEN
8036 IF l_debug_level > 0 THEN
8037 oe_debug_pub.add( 'RR2:LOAD THE RESULTS OF UNDEMAND: ' || L_LINE_REC.RE_SOURCE_FLAG , 1 ) ;
8038 END IF;
8039 IF l_line_rec.re_source_flag='Y' or
8040 l_line_rec.re_source_flag is null THEN
8041 -- 2427769.
8042 IF l_line_rec.ordered_quantity > 0 THEN
8043 IF l_debug_level > 0 THEN
8044 oe_debug_pub.add( 'SETTING SHIP FROM TO NULL' , 1 ) ;
8045 END IF;
8046 l_line_rec.ship_from_org_id := null;
8047 END IF;
8048 END IF;
8049 l_line_rec.schedule_ship_date := null;
8050 l_line_rec.schedule_arrival_date := null;
8051 l_line_rec.schedule_status_code := null;
8052 l_line_rec.visible_demand_flag := null;
8053
8054 -- We had set the ship_set and arrival_set (which are value
8055 -- fields) to the set name values for calling MRP purpose.
8056 -- Setting these back to null since sets defaulting logic
8057 -- gets fired if these values are populated.
8058
8059 IF l_line_rec.ship_set_id IS NOT NULL
8060 AND l_line_rec.ship_set_id <> FND_API.G_MISS_NUM THEN
8061 l_line_rec.ship_set := null;
8062 END IF;
8063
8064 IF l_line_rec.arrival_set_id IS NOT NULL
8065 AND l_line_rec.arrival_set_id <> FND_API.G_MISS_NUM THEN
8066 l_line_rec.arrival_set := null;
8067 END IF;
8068
8069
8070 END IF;
8071 END IF; -- Return Status.
8072 END IF; -- Main If;
8073
8074 -- Muti org changes.
8075 IF(p_atp_table.error_code(J) <> -99 ) THEN
8076
8077 ATP := ATP + 1;
8078 x_atp_tbl(ATP) := l_atp_rec;
8079
8080 END IF;
8081
8082 <<end_loop>>
8083
8084 p_x_line_tbl(I) := l_line_rec;
8085 -- Modified if stmt to fix bug 2115211
8086 IF I < p_x_line_tbl.count AND
8087 l_line_rec.item_type_code <> 'CONFIG' AND
8088 J < p_atp_table.Identifier.count THEN
8089 J := J + 1;
8090 IF (nvl(p_atp_table.vendor_name(J),'N') = 'SMC')
8091 THEN
8092
8093 WHILE (nvl(p_atp_table.vendor_name(J),'N') = 'SMC')
8094 LOOP
8095 J := J + 1;
8096 IF p_atp_table.identifier.count < J THEN
8097 GOTO END_ATP_WHILE;
8098 END IF;
8099 END LOOP;
8100
8101 << END_ATP_WHILE >>
8102 NULL;
8103
8104 END IF;
8105 END IF;
8106
8107 END LOOP;
8108
8109 x_return_status := l_return_status;
8110 IF l_debug_level > 0 THEN
8111 oe_debug_pub.add( 'EXITING LOAD_RESULTS: ' || L_RETURN_STATUS , 1 ) ;
8112 END IF;
8113
8114 EXCEPTION
8115 WHEN OTHERS THEN
8116 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
8117 THEN
8118 OE_MSG_PUB.Add_Exc_Msg
8119 ( G_PKG_NAME
8120 , 'Load_Results'
8121 );
8122 END IF;
8123 IF l_debug_level > 0 THEN
8124 oe_debug_pub.add( 'UNEXPECTED ERROR IN LOAD_RESULTS' ) ;
8125 END IF;
8126 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8127 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8128 END Load_Results;
8129
8130 /*--------------------------------------------------------------------------
8131 Procedure Name : Insert_Into_Mtl_Sales_Orders
8132 Description : This API creates a record in MTL_SALES_ORDERS for a given
8133 order header.
8134 Every header in oe_order_headers_all will have a record
8135 in MTL_SALES_ORDERS. The unique key to get the sales_order_id
8136 from mtl_sales_orders is
8137 Order_Number
8138 Order_Type (in base language)
8139 OM:Source Code profile option (stored as ont_source_code).
8140
8141 The above values are stored in a flex in MTL_SALES_ORDERS.
8142 SEGMENT1 : stores the order number
8143 SEGMENT2 : stores the order type
8144 SEGMENT3 : stores the ont_source_code value
8145
8146 -------------------------------------------------------------------------- */
8147 Procedure Insert_Into_Mtl_Sales_Orders
8148 ( p_header_rec IN OE_ORDER_PUB.header_rec_type)
8149 IS
8150 l_order_type_name VARCHAR2(80);
8151 l_source_code VARCHAR2(40) := FND_PROFILE.VALUE('ONT_SOURCE_CODE');
8152 l_sales_order_id NUMBER;
8153 l_msg_data VARCHAR2(2000);
8154 l_msg_count NUMBER;
8155 l_return_status VARCHAR2(1);
8156 --
8157 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8158 --
8159 BEGIN
8160
8161 IF l_debug_level > 0 THEN
8162 oe_debug_pub.add( 'ENTERING INSERT_INTO_MTL_SALES_ORDERS' , 1 ) ;
8163 END IF;
8164
8165 BEGIN
8166 -- Fix for bug#1078323: the order type name should be selected in
8167 -- the base language
8168 SELECT NAME
8169 INTO l_order_type_name
8170 FROM OE_TRANSACTION_TYPES_TL
8171 WHERE TRANSACTION_TYPE_ID = p_header_rec.order_type_id
8172 AND language = (select language_code
8173 from fnd_languages
8174 where installed_flag = 'B');
8175 EXCEPTION
8176 WHEN NO_DATA_FOUND THEN
8177 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8178 END;
8179
8180 IF l_debug_level > 0 THEN
8181 oe_debug_pub.add( 'CALLING INVS CREATE_SALESORDER' , 1 ) ;
8182 oe_debug_pub.add( 'ORDER TYPE: ' || L_ORDER_TYPE_NAME , 1 ) ;
8183 oe_debug_pub.add( 'SOURCE CODE: ' || L_SOURCE_CODE , 1 ) ;
8184 END IF;
8185
8186 inv_salesorder.create_salesorder
8187 ( p_api_version_number => 1.0,
8188 p_segment1 => p_header_rec.order_number,
8189 p_segment2 => l_order_type_name,
8190 p_segment3 => l_source_code,
8191 p_validation_date => p_header_rec.creation_date,
8192 x_salesorder_id => l_sales_order_id,
8193 x_message_data => l_msg_data,
8194 x_message_count => l_msg_count,
8195 x_return_status => l_return_status);
8196
8197
8198 IF l_debug_level > 0 THEN
8199 oe_debug_pub.add( 'L_MSG_COUNT ' || L_MSG_COUNT , 1 ) ;
8200 END IF;
8201 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8202 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8203 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8204 RAISE FND_API.G_EXC_ERROR;
8205 END IF;
8206
8207 IF l_debug_level > 0 THEN
8208 oe_debug_pub.add( 'EXITING INSERT_INTO_MTL_SALES_ORDERS' , 1 ) ;
8209 END IF;
8210
8211 EXCEPTION
8212
8213 WHEN OTHERS THEN
8214
8215 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
8216 THEN
8217 OE_MSG_PUB.Add_Exc_Msg
8218 ( G_PKG_NAME
8219 , 'Insert_Into_Mtl_Sales_Orders'
8220 );
8221 END IF;
8222
8223 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8224
8225 END Insert_Into_Mtl_Sales_Orders;
8226
8227 /*--------------------------------------------------------------------------
8228 Procedure Name : Get_mtl_sales_order_id
8229 Description : This funtion returns the SALES_ORDER_ID (frm mtl_sales_orders)
8230 for a given heeader_id.
8231 Every header in oe_order_headers_all will have a record
8232 in MTL_SALES_ORDERS. The unique key to get the sales_order_id
8233 from mtl_sales_orders is
8234 Order_Number
8235 Order_Type (in base language)
8236 OM:Source Code profile option (stored as ont_source_code).
8237
8238 The above values are stored in a flex in MTL_SALES_ORDERS.
8239 SEGMENT1 : stores the order number
8240 SEGMENT2 : stores the order type
8241 SEGMENT3 : stores the ont_source_code value
8242
8243 -------------------------------------------------------------------------- */
8244 FUNCTION Get_mtl_sales_order_id(p_header_id IN NUMBER)
8245 RETURN NUMBER
8246 IS
8247 l_source_code VARCHAR2(40) := FND_PROFILE.VALUE('ONT_SOURCE_CODE');
8248 l_sales_order_id NUMBER := 0;
8249 l_order_type_name VARCHAR2(80);
8250 l_order_type_id NUMBER;
8251 --
8252 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8253 --
8254 BEGIN
8255 --3748723
8256 --4504362 : Branch scheduling code removed.
8257 l_sales_order_id := oe_schedule_util.Get_Mtl_Sales_Order_Id(p_header_id);
8258 IF l_debug_level > 0 THEN
8259 oe_debug_pub.add( 'L_SALES_ORDER_ID' || L_SALES_ORDER_ID , 2 ) ;
8260 END IF;
8261
8262 RETURN l_sales_order_id;
8263
8264 EXCEPTION
8265 WHEN NO_DATA_FOUND THEN
8266 IF l_debug_level > 0 THEN
8267 oe_debug_pub.add( '2. L_SALES_ORDER_ID IS 0' , 2 ) ;
8268 END IF;
8269 RETURN 0;
8270 WHEN OTHERS THEN
8271 IF l_debug_level > 0 THEN
8272 oe_debug_pub.add( '2. L_SALES_ORDER_ID IS 0' , 2 ) ;
8273 END IF;
8274 RETURN 0;
8275 END Get_mtl_sales_order_id;
8276
8277 /*
8278 PROCEDURE Set_Auto_Sch_From_Order_Type
8279 (p_value_from_user IN VARCHAR2 := FND_API.G_MISS_CHAR)
8280 IS
8281 BEGIN
8282
8283 IF p_value_from_user <> FND_API.G_MISS_CHAR THEN
8284 OESCH_AUTO_SCH_FROM_OT := p_value_from_user;
8285 END IF;
8286
8287 IF OESCH_AUTO_SCH_FLAG = 'N' OR
8288 OESCH_AUTO_SCH_FLAG is null
8289 -- oe_debug_pub.add('RSF-p_value is ' || p_value);
8290
8291 -- OESCH_AUTO_SCH_FLAG_FROM_USER := p_value;
8292 END Set_Auto_Sch_From_Order_Type;
8293 */
8294
8295 PROCEDURE Set_Auto_Sch_Flag
8296 (p_value_from_user IN VARCHAR2 := FND_API.G_MISS_CHAR)
8297 IS
8298 --
8299 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8300 --
8301 BEGIN
8302 OESCH_AUTO_SCH_FLAG := p_value_from_user;
8303 END Set_Auto_Sch_Flag;
8304
8305 /* Function find line
8306
8307 This is be used to find the line in the pl/sql table.
8308 */
8309 FUNCTION Find_line( p_x_line_tbl IN OE_ORDER_PUB.Line_Tbl_Type,
8310 p_line_id IN NUMBER)
8311 Return BOOLEAN
8312 IS
8313 --
8314 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8315 --
8316 BEGIN
8317
8318 IF l_debug_level > 0 THEN
8319 oe_debug_pub.add( 'ENTERING FIND_LINE: ' || P_LINE_ID , 1 ) ;
8320 END IF;
8321
8322 FOR J IN 1..p_x_line_tbl.count LOOP
8323
8324 IF p_line_id = p_x_line_tbl(J).line_id THEN
8325
8326 IF l_debug_level > 0 THEN
8327 oe_debug_pub.add( ' LINE EXISTS IN THE TABLE' , 1 ) ;
8328 END IF;
8329
8330 RETURN TRUE;
8331 END IF;
8332 END LOOP;
8333
8334 RETURN FALSE;
8335
8336 END Find_line;
8337
8338 /*PROCEDURE PROCESS_SPLIT
8339 This procedure will be used to call mrp with appropriate records:
8340 If the ato model is part of SMC, then Whome smc model will be called
8341 If the ato model is part of set, then whole set information will
8342 be passed to MRP and so on */
8343
8344 PROCEDURE PROCESS_SPLIT
8345 (p_x_line_tbl IN OE_ORDER_PUB.Line_Tbl_Type)
8346
8347 IS
8348 l_line_tbl OE_ORDER_PUB.line_tbl_type;
8349 l_local_line_tbl OE_ORDER_PUB.line_tbl_type;
8350 K NUMBER;
8351 I NUMBER;
8352 l_ato_line_id NUMBER;
8353 l_entity VARCHAR2(30);
8354
8355 -- MRP API variables
8356 l_session_id NUMBER := 0;
8357 l_mrp_atp_rec MRP_ATP_PUB.ATP_Rec_Typ;
8358 l_out_mtp_atp_rec MRP_ATP_PUB.ATP_Rec_Typ;
8359 l_atp_supply_demand MRP_ATP_PUB.ATP_Supply_Demand_Typ;
8360 l_atp_period MRP_ATP_PUB.ATP_Period_Typ;
8361 l_atp_details MRP_ATP_PUB.ATP_Details_Typ;
8362 mrp_msg_data VARCHAR2(200);
8363 l_on_hand_qty NUMBER;
8364 l_avail_to_reserve NUMBER;
8365
8366 l_out_atp_tbl OE_ATP.atp_tbl_type;
8367 l_found BOOLEAN := FALSE;
8368 l_buffer VARCHAR2(2000);
8369 l_msg_count NUMBER;
8370 l_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
8371
8372
8373 --
8374 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8375 --
8376 BEGIN
8377
8378 IF l_debug_level > 0 THEN
8379 oe_debug_pub.add( 'ENTERING PROCESS SPLIT' , 1 ) ;
8380 END IF;
8381
8382 K := 0;
8383
8384 FOR I IN 1..p_x_line_tbl.count LOOP
8385 --bug 2669788
8386 if p_x_line_tbl(I).schedule_status_code is not null then
8387 IF l_debug_level > 0 THEN
8388 oe_debug_pub.add( 'BUG 2669788:'||P_X_LINE_TBL ( I ) .LINE_ID , 1 ) ;
8389 END IF;
8390
8391 IF NOT find_line(p_x_line_tbl => l_line_tbl,
8392 p_line_id => p_x_line_tbl(I).line_id)
8393 THEN
8394
8395 IF p_x_line_tbl(I).arrival_set_id is not null THEN
8396
8397 OE_Set_Util.Query_Set_Rows(p_set_id => p_x_line_tbl(I).arrival_set_id,
8398 x_line_tbl => l_local_line_tbl);
8399
8400
8401 FOR L IN 1..l_local_line_tbl.count LOOP
8402
8403 K := K +1;
8404 l_line_tbl(K) := l_local_line_tbl(L);
8405 l_line_tbl(K).schedule_action_code :=
8406 OE_ORDER_SCH_UTIL.OESCH_ACT_RESCHEDULE;
8407
8408 END LOOP;
8409
8410 l_local_line_tbl.delete;
8411
8412 ELSIF p_x_line_tbl(I).ship_set_id is not null THEN
8413
8414
8415 OE_Set_Util.Query_Set_Rows(p_set_id => p_x_line_tbl(I).ship_set_id,
8416 x_line_tbl => l_local_line_tbl);
8417
8418 FOR L IN 1..l_local_line_tbl.count LOOP
8419
8420 K := K +1;
8421 l_line_tbl(K) := l_local_line_tbl(L);
8422 l_line_tbl(K).schedule_action_code :=
8423 OE_ORDER_SCH_UTIL.OESCH_ACT_RESCHEDULE;
8424
8425 END LOOP;
8426
8427 l_local_line_tbl.delete;
8428
8429 ELSIF p_x_line_tbl(I).ship_model_complete_flag ='Y'
8430 AND nvl(p_x_line_tbl(I).model_remnant_flag,'N') = 'N' THEN
8431
8432
8433 OE_Config_Util.Query_Options
8434 (p_top_model_line_id => p_x_line_tbl(I).top_model_line_id,
8435 x_line_tbl => l_local_line_tbl);
8436
8437
8438 FOR L IN 1..l_local_line_tbl.count LOOP
8439
8440 K := K +1;
8441 l_line_tbl(K) := l_local_line_tbl(L);
8442 l_line_tbl(K).schedule_action_code :=
8443 OE_ORDER_SCH_UTIL.OESCH_ACT_RESCHEDULE;
8444 l_line_tbl(K).ship_set := p_x_line_tbl(I).top_model_line_id;
8445
8446 END LOOP;
8447
8448 l_local_line_tbl.delete;
8449
8450 ELSIF (p_x_line_tbl(I).ato_line_id is not null)
8451 AND nvl(p_x_line_tbl(I).model_remnant_flag,'N') = 'N' THEN
8452
8453 Begin
8454
8455 Select ato_line_id
8456 Into l_ato_line_id
8457 From oe_order_lines_all
8458 Where line_id = p_x_line_tbl(I).line_id;
8459 EXCEPTION
8460
8461 WHEN OTHERS THEN
8462
8463 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8464
8465 END;
8466
8467 OE_Config_Util.Query_ATO_Options
8468 (p_ato_line_id => l_ato_line_id,
8469 x_line_tbl => l_local_line_tbl);
8470
8471
8472 FOR L IN 1..l_local_line_tbl.count LOOP
8473
8474 K := K +1;
8475 l_line_tbl(K) := l_local_line_tbl(L);
8476 l_line_tbl(K).schedule_action_code :=
8477 OE_ORDER_SCH_UTIL.OESCH_ACT_RESCHEDULE;
8478 l_line_tbl(K).ship_set := l_ato_line_id;
8479
8480
8481 END LOOP;
8482
8483 l_local_line_tbl.delete;
8484
8485
8486 ELSE
8487
8488 K := K +1;
8489 l_line_tbl(K) := p_x_line_tbl(I);
8490 l_line_tbl(K).schedule_action_code :=
8491 OE_ORDER_SCH_UTIL.OESCH_ACT_RESCHEDULE;
8492
8493
8494 END IF;
8495
8496 END IF; -- line is not part of the locak table.
8497 END IF; --bug 2669788
8498 END LOOP;
8499
8500 G_OVERRIDE_FLAG := 'Y';
8501
8502 IF l_line_tbl.count > 0 THEN
8503
8504 IF l_debug_level > 0 THEN
8505 oe_debug_pub.add( 'SPLIT BEFORE CALLING LOAD_MRP_REQUEST' , 2 ) ;
8506 END IF;
8507 Load_MRP_Request
8508 ( p_line_tbl => l_line_tbl
8509 , p_old_line_tbl => l_line_tbl
8510 , x_atp_table => l_mrp_atp_rec);
8511
8512 l_session_id := Get_Session_Id;
8513
8514 -- Call ATP
8515 IF l_debug_level > 0 THEN
8516 oe_debug_pub.add( 'COUNT IS ' || L_MRP_ATP_REC.ERROR_CODE.COUNT , 1 ) ;
8517 END IF;
8518
8519 -- We are adding this so that we will not call MRP when
8520 -- table count is 0.
8521
8522 IF l_mrp_atp_rec.error_code.count > 0 THEN
8523
8524 IF l_debug_level > 0 THEN
8525 oe_debug_pub.add( 'SPLIT CALLING MRP API WITH SESSION ID '||L_SESSION_ID , 1 ) ;
8526 END IF;
8527
8528 MRP_ATP_PUB.Call_ATP
8529 ( p_session_id => l_session_id
8530 , p_atp_rec => l_mrp_atp_rec
8531 , x_atp_rec => l_out_mtp_atp_rec
8532 , x_atp_supply_demand => l_atp_supply_demand
8533 , x_atp_period => l_atp_period
8534 , x_atp_details => l_atp_details
8535 , x_return_status => l_return_status
8536 , x_msg_data => mrp_msg_data
8537 , x_msg_count => l_msg_count);
8538
8539
8540 IF l_debug_level > 0 THEN
8541 oe_debug_pub.add( 'SPLIT. AFTER CALLING MRP_ATP_PUB.CALL_ATP' || L_RETURN_STATUS , 1 ) ;
8542 END IF;
8543
8544 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8545 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8546 END IF;
8547
8548 Load_Results
8549 ( p_atp_table => l_out_mtp_atp_rec
8550 , p_x_line_tbl => l_line_tbl
8551 , x_atp_tbl => l_out_atp_tbl
8552 , x_return_status => l_return_status);
8553
8554 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8555 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8556 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8557 RAISE FND_API.G_EXC_ERROR;
8558 END IF;
8559
8560 END IF; -- MRP count check.
8561
8562
8563 END IF; -- line count.
8564
8565 G_OVERRIDE_FLAG := 'N';
8566 IF l_debug_level > 0 THEN
8567 oe_debug_pub.add( 'EXITING PROCESS SPLIT' , 1 ) ;
8568 END IF;
8569 EXCEPTION
8570 WHEN OTHERS THEN
8571
8572 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
8573 THEN
8574 OE_MSG_PUB.Add_Exc_Msg
8575 ( G_PKG_NAME
8576 , 'PROCESS_SPLIT'
8577 );
8578 END IF;
8579
8580 END PROCESS_SPLIT;
8581
8582
8583 /*--------------------------------------------------------------------
8584 Procedure Name : Split_Scheduling
8585 Description : The split API calls this procedure with a table of record.
8586 There is an update line (the line which is getting split)
8587 and multiple insert lines (new lines created due to the split).
8588 We need to do the following:
8589
8590 For scheduling
8591 -------------
8592 On the updated line: Reschedule the line.
8593 On the inserted lines: Schedule the lines.
8594
8595 For reservation
8596 ---------------
8597 If the split is due to shipping, we need to update the
8598 reservations (whichever exist) to the new line which
8599 got created.
8600
8601 If the split is due to the user splitting, there could be
8602 multiple records created due to the split. We should update
8603 the old reservation to reflect the change in qty for the
8604 original line, and create new reservations for the new lines
8605 which got created.
8606
8607
8608 ---------------------------------------------------------------------- */
8609 Procedure SPLIT_SCHEDULING
8610 ( p_x_line_tbl IN OUT NOCOPY OE_ORDER_PUB.line_tbl_type
8611 , x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
8612 IS
8613 l_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
8614 l_header_id NUMBER;
8615 l_p_header_id NUMBER;
8616 l_line_id NUMBER;
8617 l_demand_source_line_id NUMBER;
8618 l_ordered_quantity NUMBER;
8619 l_shipped_quantity NUMBER;
8620 l_qty_to_transfer NUMBER;
8621 l_qty_to_reserve NUMBER;
8622 l_sales_order_id NUMBER;
8623 l_reserved_quantity NUMBER;
8624 l_qty_to_tfer_in_this_record NUMBER;
8625 l_qty_to_retain NUMBER;
8626 l_count NUMBER;
8627 l_x_error_code NUMBER;
8628 l_lock_records VARCHAR2(1);
8629 l_sort_by_req_date NUMBER;
8630 continue_loop BOOLEAN := TRUE;
8631 l_line_tbl OE_ORDER_PUB.line_tbl_type;
8632 l_out_line_tbl OE_ORDER_PUB.line_tbl_type;
8633 l_x_line_tbl OE_ORDER_PUB.line_tbl_type;
8634 l_line_rec OE_ORDER_PUB.line_rec_type;
8635 l_out_line_rec OE_ORDER_PUB.line_rec_type;
8636 l_split_line_rec OE_ORDER_PUB.line_rec_type;
8637 l_out_split_line_rec OE_ORDER_PUB.line_rec_type;
8638 K NUMBER;
8639 J NUMBER;
8640
8641 -- INVCONV
8642 l_ordered_quantity2 NUMBER;
8643 l_shipped_quantity2 NUMBER;
8644 l_qty2_to_transfer NUMBER;
8645 l_qty2_to_reserve NUMBER;
8646 l_reserved_quantity2 NUMBER;
8647 l_qty2_to_tfer_in_this_record NUMBER;
8648 l_qty2_to_retain NUMBER;
8649
8650
8651 -- Reservation API variables
8652 l_query_rsv_rec inv_reservation_global.mtl_reservation_rec_type;
8653 l_rsv_rec inv_reservation_global.mtl_reservation_rec_type;
8654 l_rsv_new_rec inv_reservation_global.mtl_reservation_rec_type;
8655 l_msg_count NUMBER;
8656 l_msg_data VARCHAR2(240);
8657 l_rsv_id NUMBER;
8658 l_rsv_tbl inv_reservation_global.mtl_reservation_tbl_type;
8659 l_dummy_sn inv_reservation_global.serial_number_tbl_type;
8660 l_qty_reserved NUMBER;
8661 -- INVCONV
8662 l_qty2_reserved NUMBER;
8663
8664 -- MRP API variables
8665 --l_session_id NUMBER := 0;
8666 --l_mrp_atp_rec MRP_ATP_PUB.ATP_Rec_Typ;
8667 --l_out_mtp_atp_rec MRP_ATP_PUB.ATP_Rec_Typ;
8668 --l_atp_supply_demand MRP_ATP_PUB.ATP_Supply_Demand_Typ;
8669 --l_atp_period MRP_ATP_PUB.ATP_Period_Typ;
8670 --l_atp_details MRP_ATP_PUB.ATP_Details_Typ;
8671 --mrp_msg_data VARCHAR2(200);
8672 --l_on_hand_qty NUMBER;
8673 --l_avail_to_reserve NUMBER;
8674 --l_out_atp_tbl OE_ATP.atp_tbl_type;
8675 l_found BOOLEAN := FALSE;
8676 l_buffer VARCHAR2(2000);
8677
8678
8679 --
8680 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8681 --
8682 BEGIN
8683
8684 IF l_debug_level > 0 THEN
8685 oe_debug_pub.add( '31. ENTERING SPLIT_SCHEDULING' , 1 ) ;
8686 oe_debug_pub.add( 'PICTURE SENT ' , 1 ) ;
8687 END IF;
8688 FOR I IN 1..p_x_line_tbl.count LOOP
8689 IF l_debug_level > 0 THEN
8690 oe_debug_pub.add( 'LINE ID ' || P_X_LINE_TBL ( I ) .LINE_ID , 1 ) ;
8691 oe_debug_pub.add( 'SPLIT ID ' || P_X_LINE_TBL ( I ) .SPLIT_FROM_LINE_ID , 1 ) ;
8692 oe_debug_pub.add( 'SPLIT ACTION ' || P_X_LINE_TBL ( I ) .SPLIT_ACTION_CODE , 1 ) ;
8693 oe_debug_pub.add( 'OPERATIONS ' || P_X_LINE_TBL ( I ) .OPERATION , 1 ) ;
8694 END IF;
8695 END LOOP;
8696 -- We will first set the flag g_source_again to 'N' since we do not
8697 -- want any resoucing to happen due to a split.
8698
8699 G_SOURCE_AGAIN := 'N';
8700 G_OVERRIDE_FLAG := 'Y';
8701
8702 IF l_debug_level > 0 THEN
8703 oe_debug_pub.add( 'COUNT IS :' || P_X_LINE_TBL.COUNT , 1 ) ;
8704 END IF;
8705 l_out_line_tbl := p_x_line_tbl;
8706
8707 process_split(p_x_line_tbl => p_x_line_tbl);
8708
8709 FOR I in 1..p_x_line_tbl.count LOOP
8710
8711 IF p_x_line_tbl(I).operation = OE_GLOBALS.G_OPR_UPDATE AND
8712 p_x_line_tbl(I).schedule_status_code is not null AND
8713 p_x_line_tbl(I).split_action_code = 'SPLIT' THEN
8714
8715 IF l_debug_level > 0 THEN
8716 oe_debug_pub.add( 'SPLITTING SCHEDULING' , 1 ) ;
8717 oe_debug_pub.add( ' ' , 1 ) ;
8718 END IF;
8719 g_line_action := USER_SPLIT;
8720
8721 l_line_rec := p_x_line_tbl(I);
8722
8723 IF l_debug_level > 0 THEN
8724 oe_debug_pub.add( 'SPLITTING SCHEDULING FOR LINE: ' || L_LINE_REC.LINE_ID , 1 ) ;
8725 END IF;
8726 /*
8727 -- This is the line which is getting split. We should
8728 -- reschedule the line with the new quantity.
8729
8730 -- Let's first reschedule this line and then schedule
8731 -- the new split lines.
8732
8733 -- Add the action on the line as reschedule
8734
8735 l_line_rec.schedule_action_code := OESCH_ACT_RESCHEDULE;
8736 l_line_tbl(1) := l_line_rec;
8737
8738 Load_MRP_Request
8739 ( p_line_tbl => l_line_tbl
8740 , p_old_line_tbl => l_line_tbl
8741 , x_atp_table => l_mrp_atp_rec);
8742
8743 l_session_id := Get_Session_Id;
8744
8745 -- Call ATP
8746 oe_debug_pub.add('Count is ' || l_mrp_atp_rec.error_code.count,1);
8747
8748 -- We are adding this so that we will not call MRP when
8749 -- table count is 0.
8750
8751 IF l_mrp_atp_rec.error_code.count > 0 THEN
8752
8753 oe_debug_pub.add('1. Calling MRP API with session id '||l_session_id,1);
8754
8755 MRP_ATP_PUB.Call_ATP
8756 ( p_session_id => l_session_id
8757 , p_atp_rec => l_mrp_atp_rec
8758 , x_atp_rec => l_out_mtp_atp_rec
8759 , x_atp_supply_demand => l_atp_supply_demand
8760 , x_atp_period => l_atp_period
8761 , x_atp_details => l_atp_details
8762 , x_return_status => l_return_status
8763 , x_msg_data => mrp_msg_data
8764 , x_msg_count => l_msg_count);
8765
8766
8767 oe_debug_pub.add('6. After Calling MRP_ATP_PUB.Call_ATP' ||
8768 l_return_status,1);
8769
8770 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8771 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8772 END IF;
8773
8774 Load_Results
8775 ( p_atp_table => l_out_mtp_atp_rec
8776 , p_x_line_tbl => l_line_tbl
8777 , x_atp_tbl => l_out_atp_tbl
8778 , x_return_status => l_return_status);
8779
8780 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8781 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8782 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8783 RAISE FND_API.G_EXC_ERROR;
8784 END IF;
8785
8786 END IF; -- MRP count check.
8787
8788 l_out_line_tbl(I) := l_line_tbl(1);
8789 */
8790 -- Resetting the action to null, before this record is passed
8791 -- back to the caller.
8792 /*
8793 l_out_line_tbl(I).schedule_action_code := null;
8794
8795 -- Now let's schedule the new split lines.
8796 FOR J IN 1..p_x_line_tbl.count LOOP
8797 IF p_x_line_tbl(J).operation = OE_GLOBALS.G_OPR_CREATE AND
8798 p_x_line_tbl(J).split_from_line_id = l_line_rec.line_id
8799 THEN
8800 l_split_line_rec := p_x_line_tbl(J);
8801 oe_debug_pub.add('Split lines ship from: ' ||
8802 l_split_line_rec.ship_from_org_id,1);
8803 l_out_split_line_rec := l_split_line_rec;
8804
8805 --- Bug fix for 1881229
8806
8807 l_out_split_line_rec.schedule_action_code := OESCH_ACT_SCHEDULE;
8808 l_line_tbl(1) := l_out_split_line_rec;
8809
8810 Load_MRP_Request
8811 ( p_line_tbl => l_line_tbl
8812 , p_old_line_tbl => l_line_tbl
8813 , x_atp_table => l_mrp_atp_rec);
8814
8815
8816 -- Call ATP
8817 oe_debug_pub.add('Split Count is ' || l_mrp_atp_rec.error_code.count,1);
8818
8819 -- We are adding this so that we will not call MRP when
8820 -- table count is 0.
8821
8822 IF l_mrp_atp_rec.error_code.count > 0 THEN
8823
8824 l_session_id := Get_Session_Id;
8825
8826
8827 oe_debug_pub.add('2. Calling MRP API with session id '||l_session_id,1);
8828
8829 MRP_ATP_PUB.Call_ATP
8830 ( p_session_id => l_session_id
8831 , p_atp_rec => l_mrp_atp_rec
8832 , x_atp_rec => l_out_mtp_atp_rec
8833 , x_atp_supply_demand => l_atp_supply_demand
8834 , x_atp_period => l_atp_period
8835 , x_atp_details => l_atp_details
8836 , x_return_status => l_return_status
8837 , x_msg_data => mrp_msg_data
8838 , x_msg_count => l_msg_count);
8839
8840
8841 oe_debug_pub.add('2. After Calling MRP_ATP_PUB.Call_ATP' ||
8842 l_return_status,1);
8843
8844 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8845 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8846 END IF;
8847
8848 Load_Results
8849 ( p_atp_table => l_out_mtp_atp_rec
8850 , p_x_line_tbl => l_line_tbl
8851 , x_atp_tbl => l_out_atp_tbl
8852 , x_return_status => l_return_status);
8853
8854 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8855 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8856 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8857 RAISE FND_API.G_EXC_ERROR;
8858 END IF;
8859
8860 END IF; -- MRP count check.
8861
8862 -- Bug
8863 Action_Schedule
8864 (p_x_line_rec => l_out_split_line_rec,
8865 p_old_line_rec => l_split_line_rec,
8866 p_action => OESCH_ACT_SCHEDULE,
8867 x_return_status => l_return_status);
8868
8869 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8870 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8871 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8872 RAISE FND_API.G_EXC_ERROR;
8873 END IF;
8874
8875 l_out_line_tbl(J) := l_line_tbl(1);
8876 -- reset the action to null
8877 l_out_line_tbl(j).schedule_action_code := null;
8878
8879 END IF;
8880 END LOOP;
8881 */
8882 -- G_SOURCE_AGAIN := 'Y';
8883 -- G_OVERRIDE_FLAG := 'N';
8884 -- We have updated the demand picture in MRP with the split.
8885 -- Now let's update the reservation picture.
8886
8887 l_query_rsv_rec.reservation_id := fnd_api.g_miss_num;
8888
8889 l_sales_order_id
8890 := Get_mtl_sales_order_id(l_line_rec.header_id);
8891 l_query_rsv_rec.demand_source_header_id := l_sales_order_id;
8892 l_query_rsv_rec.demand_source_line_id := l_line_rec.line_id;
8893
8894 -- 02-jun-2000 mpetrosi added org_id to query_reservation start
8895 l_query_rsv_rec.organization_id := l_line_rec.ship_from_org_id;
8896 -- 02-jun-2000 mpetrosi added org_id to query_reservation end
8897
8898
8899 IF l_debug_level > 0 THEN
8900 oe_debug_pub.add( 'CALLING INVS QUERY_RESERVATION ' , 1 ) ;
8901 END IF;
8902
8903 inv_reservation_pub.query_reservation
8904 ( p_api_version_number => 1.0
8905 , p_init_msg_lst => fnd_api.g_true
8906 , x_return_status => l_return_status
8907 , x_msg_count => l_msg_count
8908 , x_msg_data => l_msg_data
8909 , p_query_input => l_query_rsv_rec
8910 , x_mtl_reservation_tbl => l_rsv_tbl
8911 , x_mtl_reservation_tbl_count => l_count
8912 , x_error_code => l_x_error_code
8913 , p_lock_records => l_lock_records
8914 , p_sort_by_req_date => l_sort_by_req_date
8915 );
8916
8917 IF l_debug_level > 0 THEN
8918 oe_debug_pub.add( 'AFTER CALLING INVS QUERY_RESERVATION: ' || L_RETURN_STATUS , 1 ) ;
8919 END IF;
8920
8921 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8922 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8923 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8924 RAISE FND_API.G_EXC_ERROR;
8925 END IF;
8926
8927 IF l_debug_level > 0 THEN
8928 oe_debug_pub.add( 'RESERVATION RECORD COUNT IS: ' || L_RSV_TBL.COUNT , 1 ) ;
8929 END IF;
8930
8931 -- Let's get the total reserved_quantity
8932 l_reserved_quantity := 0;
8933 FOR K IN 1..l_rsv_tbl.count LOOP
8934 l_reserved_quantity := l_reserved_quantity +
8935 l_rsv_tbl(K).reservation_quantity;
8936 END LOOP;
8937
8938 IF l_debug_level > 0 THEN
8939 oe_debug_pub.add( 'RESERVED QUANTITY : ' || L_RESERVED_QUANTITY , 1 ) ;
8940 END IF;
8941
8942 IF l_reserved_quantity > 0
8943 THEN
8944 -- There can be 2 kinds of splits. One where the user split,
8945 -- in which case, the reservations have to split. And another
8946 -- when shipping occurs partially. In that case, the remaining
8947 -- reservations are trasferred to the new line.
8948
8949 IF l_line_rec.shipped_quantity is null AND /* shipped_quantity is null */
8950 nvl(l_line_rec.shipping_interfaced_flag, 'N') = 'N' THEN
8951 -- If we are here, it means the split was beacuse the user
8952 -- split the line. We should check to see if we need to
8953 -- split reservations or not.
8954 IF l_debug_level > 0 THEN
8955 oe_debug_pub.add( 'USER INITIATED SPLIT' , 1 ) ;
8956 END IF;
8957 IF l_line_rec.ordered_quantity > l_reserved_quantity
8958 THEN
8959
8960 -- The first line (which got split) is taking up all
8961 -- the reservations. So we do not need to split any
8962 -- reservations.
8963
8964 goto end_loop;
8965 END IF;
8966
8967 l_qty_to_transfer := l_reserved_quantity -
8968 l_line_rec.ordered_quantity;
8969
8970 l_demand_source_line_id := l_line_rec.line_id;
8971 l_ordered_quantity := l_line_rec.ordered_quantity;
8972
8973 -- INVCONV
8974 l_qty2_to_transfer := NVL(l_reserved_quantity2,0) -
8975 NVL(l_line_rec.ordered_quantity2, 0);
8976
8977 l_ordered_quantity2 := l_line_rec.ordered_quantity2;
8978
8979
8980
8981 IF l_debug_level > 0 THEN
8982 oe_debug_pub.add( 'QUANTITY TO TRANSFER: ' || L_QTY_TO_TRANSFER , 1 ) ;
8983 END IF;
8984 K := l_rsv_tbl.first;
8985 J := 0;
8986
8987 l_qty_to_retain := l_line_rec.ordered_quantity;
8988 l_qty2_to_retain := l_line_rec.ordered_quantity2; -- INVCONV
8989
8990 WHILE K is not null LOOP
8991 IF l_debug_level > 0 THEN
8992 oe_debug_pub.add( 'L2' , 1 ) ;
8993 END IF;
8994 l_rsv_rec := l_rsv_tbl(K);
8995
8996 l_qty_to_tfer_in_this_record :=
8997 l_rsv_rec.reservation_quantity;
8998
8999 l_qty2_to_tfer_in_this_record := -- INVCONV -- PAL
9000 l_rsv_rec.secondary_reservation_quantity;
9001
9002 -- Update this reservation and also create a
9003 -- new reservation for the remaining quantity to a
9004 -- new split line .
9005
9006 l_rsv_new_rec := l_rsv_rec;
9007 IF l_rsv_rec.reservation_quantity <= l_ordered_quantity
9008 THEN
9009 IF l_rsv_rec.demand_source_line_id = l_line_rec.line_id
9010 THEN
9011 -- No update required.
9012 l_qty_to_retain := l_qty_to_retain -
9013 l_rsv_rec.reservation_quantity;
9014 l_qty2_to_retain := NVL(l_qty2_to_retain,0) - -- INVCONV
9015 nvl(l_rsv_rec.secondary_reservation_quantity, 0);
9016 l_qty_to_tfer_in_this_record := 0;
9017 l_qty2_to_tfer_in_this_record := 0; -- INVCONV
9018 ELSE
9019 -- update reservation with the new line_id
9020 IF l_debug_level > 0 THEN
9021 oe_debug_pub.add( 'UPDATING RESERVATION ' , 1 ) ;
9022 END IF;
9023
9024 l_rsv_new_rec := l_rsv_rec;
9025 l_rsv_new_rec.demand_source_line_id :=
9026 l_line_rec.line_id;
9027 /* OPM 14/SEP/00 send process attributes into the reservation
9028 =============================================================
9029 l_rsv_new_rec.attribute1 := l_line_rec.preferred_grade;
9030 l_rsv_new_rec.attribute2 := l_line_rec.ordered_quantity2;
9031 l_rsv_new_rec.attribute3 := l_line_rec.ordered_quantity_uom2;
9032 OPM 14/SEP/00 END -- INVCONV
9033 ====================*/
9034
9035 l_rsv_new_rec.secondary_reservation_quantity := l_line_rec.ordered_quantity2; -- INVCONV
9036 l_rsv_new_rec.secondary_uom_code := l_line_rec.ordered_quantity_uom2;
9037
9038
9039
9040 IF l_debug_level > 0 THEN
9041 oe_debug_pub.add( '11. CALLING INVS UPDATE RSV: ' , 1 ) ;
9042 END IF;
9043
9044 inv_reservation_pub.update_reservation
9045 ( p_api_version_number => 1.0
9046 , p_init_msg_lst => fnd_api.g_true
9047 , x_return_status => l_return_status
9048 , x_msg_count => l_msg_count
9049 , x_msg_data => l_msg_data
9050 , p_original_rsv_rec => l_rsv_rec
9051 , p_to_rsv_rec => l_rsv_new_rec
9052 , p_original_serial_number => l_dummy_sn
9053 , p_to_serial_number => l_dummy_sn
9054 , p_validation_flag => fnd_api.g_true
9055 );
9056
9057 IF l_debug_level > 0 THEN
9058 oe_debug_pub.add( ' 11 AFTER CALLING INVS UPD_RESERVATION: ' || L_RETURN_STATUS , 1 ) ;
9059 END IF;
9060
9061 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
9062 THEN
9063 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9064 ELSIF l_return_status = FND_API.G_RET_STS_ERROR
9065 THEN
9066 IF l_msg_data is not null THEN
9067 fnd_message.set_encoded(l_msg_data);
9068 l_buffer := fnd_message.get;
9069 oe_msg_pub.add_text(p_message_text => l_buffer);
9070 IF l_debug_level > 0 THEN
9071 oe_debug_pub.add( 'ERROR : '|| L_BUFFER , 1 ) ;
9072 END IF;
9073 END IF;
9074 RAISE FND_API.G_EXC_ERROR;
9075 END IF;
9076
9077 l_qty_to_tfer_in_this_record := 0;
9078 END IF;
9079 ELSIF l_ordered_quantity is not null THEN
9080 IF l_debug_level > 0 THEN
9081 oe_debug_pub.add( 'NEW QTY: ' || L_ORDERED_QUANTITY , 1 ) ;
9082 END IF;
9083 l_rsv_new_rec.reservation_quantity :=
9084 l_ordered_quantity;
9085 l_rsv_new_rec.primary_reservation_quantity := fnd_api.g_miss_num;
9086 -- l_ordered_quantity;
9087
9088 l_rsv_new_rec.demand_source_line_id :=
9089 l_demand_source_line_id;
9090
9091 l_rsv_new_rec.secondary_reservation_quantity := -- INVCONV
9092 l_ordered_quantity2;
9093 l_rsv_new_rec.secondary_uom_code := -- INVCONV
9094 l_line_rec.ordered_quantity_uom2;
9095
9096
9097
9098 /* OPM 14/SEP/00 send process attributes into the reservation
9099 =============================================================
9100 l_rsv_new_rec.attribute1 := l_line_rec.preferred_grade;
9101 l_rsv_new_rec.attribute2 := l_line_rec.ordered_quantity2;
9102 l_rsv_new_rec.attribute3 := l_line_rec.ordered_quantity_uom2;
9103 OPM 14/SEP/00 END
9104 ====================*/ -- INVCONV
9105 IF l_debug_level > 0 THEN
9106 oe_debug_pub.add( '1. CALLING INVS UPDATE RSV: ' , 1 ) ;
9107 END IF;
9108
9109 inv_reservation_pub.update_reservation
9110 ( p_api_version_number => 1.0
9111 , p_init_msg_lst => fnd_api.g_true
9112 , x_return_status => l_return_status
9113 , x_msg_count => l_msg_count
9114 , x_msg_data => l_msg_data
9115 , p_original_rsv_rec => l_rsv_rec
9116 , p_to_rsv_rec => l_rsv_new_rec
9117 , p_original_serial_number => l_dummy_sn
9118 , p_to_serial_number => l_dummy_sn
9119 , p_validation_flag => fnd_api.g_true
9120 );
9121
9122 IF l_debug_level > 0 THEN
9123 oe_debug_pub.add( '1 AFTER CALLING INVS UPDATE_RESERVATION: ' || L_RETURN_STATUS , 1 ) ;
9124 END IF;
9125
9126 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
9127 THEN
9128 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9129 ELSIF l_return_status = FND_API.G_RET_STS_ERROR
9130 THEN
9131 IF l_msg_data is not null THEN
9132 fnd_message.set_encoded(l_msg_data);
9133 l_buffer := fnd_message.get;
9134 oe_msg_pub.add_text(p_message_text => l_buffer);
9135 IF l_debug_level > 0 THEN
9136 oe_debug_pub.add( 'ERROR : '|| L_BUFFER , 1 ) ;
9137 END IF;
9138 END IF;
9139 RAISE FND_API.G_EXC_ERROR;
9140 END IF;
9141
9142 l_qty_to_tfer_in_this_record :=
9143 l_qty_to_tfer_in_this_record -
9144 l_ordered_quantity;
9145
9146 l_qty_to_retain := l_ordered_quantity -
9147 l_rsv_rec.reservation_quantity;
9148
9149 l_ordered_quantity := 0;
9150
9151
9152 l_qty2_to_tfer_in_this_record := -- INVCONV
9153 nvl(l_qty2_to_tfer_in_this_record, 0) -
9154 nvl(l_ordered_quantity2, 0);
9155
9156 l_qty2_to_retain := nvl(l_ordered_quantity2, 0) -
9157 nvl(l_rsv_rec.secondary_reservation_quantity, 0);
9158
9159 l_ordered_quantity2 := 0;
9160
9161
9162 END IF;
9163
9164 -- If there is any qty left in the reservation record
9165 -- which needs to be transferred, let's find a split line
9166 -- for it.
9167
9168 IF l_debug_level > 0 THEN
9169 oe_debug_pub.add( '2. QTY TO XFER IN THIS RSV :' || L_QTY_TO_TFER_IN_THIS_RECORD ) ;
9170 END IF;
9171 <<find_split_line>>
9172 IF l_qty_to_tfer_in_this_record > 0
9173 THEN
9174
9175 IF l_debug_level > 0 THEN
9176 oe_debug_pub.add( '1. FINDING THE NEXT SPLIT LINE' , 1 ) ;
9177 END IF;
9178 IF l_ordered_quantity <= 0 THEN
9179 J := J + 1;
9180 continue_loop := TRUE;
9181 WHILE J <= p_x_line_tbl.count AND continue_loop
9182 LOOP
9183 IF p_x_line_tbl(J).operation =
9184 OE_GLOBALS.G_OPR_CREATE AND
9185 p_x_line_tbl(J).split_from_line_id =
9186 l_line_rec.line_id
9187 THEN
9188 continue_loop := FALSE;
9189 ELSE
9190 J := J + 1;
9191 END IF;
9192 END LOOP;
9193
9194 IF l_debug_level > 0 THEN
9195 oe_debug_pub.add( 'FOUND THE NEXT SPLIT LINE' , 1 ) ;
9196 END IF;
9197 l_split_line_rec := p_x_line_tbl(J);
9198
9199
9200 -- We can transfer the whole of the remaining qty to
9201 -- this new split line.
9202
9203 l_demand_source_line_id := l_split_line_rec.line_id;
9204 l_ordered_quantity :=
9205 l_split_line_rec.ordered_quantity;
9206 l_ordered_quantity2 := -- INVCONV
9207 l_split_line_rec.ordered_quantity2;
9208 END IF;
9209
9210 -- We have found a record to which we should transfer the
9211 -- reservation. If the amount we need to reserve is more
9212 -- than the amount on this new split line, we will look for
9213 -- next split line to transfer the reservation to.
9214
9215
9216 IF l_ordered_quantity < l_qty_to_tfer_in_this_record
9217 THEN
9218 l_qty_to_reserve := l_ordered_quantity;
9219 l_qty_to_tfer_in_this_record :=
9220 l_qty_to_tfer_in_this_record -
9221 l_ordered_quantity;
9222 l_ordered_quantity := 0;
9223 ELSE
9224 l_qty_to_reserve := l_qty_to_tfer_in_this_record;
9225 l_qty_to_tfer_in_this_record := 0;
9226 l_ordered_quantity := l_ordered_quantity -
9227 l_qty_to_tfer_in_this_record;
9228 END IF;
9229
9230 IF l_ordered_quantity2 < l_qty2_to_tfer_in_this_record
9231 THEN
9232 l_qty2_to_reserve := l_ordered_quantity2;
9233 l_qty2_to_tfer_in_this_record :=
9234 l_qty2_to_tfer_in_this_record -
9235 l_ordered_quantity2;
9236 l_ordered_quantity2 := 0;
9237 ELSE
9238 l_qty2_to_reserve := l_qty2_to_tfer_in_this_record;
9239 l_qty2_to_tfer_in_this_record := 0;
9240 l_ordered_quantity2 := nvl(l_ordered_quantity2,0) -
9241 nvl(l_qty2_to_tfer_in_this_record, 0);
9242 END IF;
9243
9244 l_rsv_new_rec := l_rsv_rec;
9245 l_rsv_new_rec.reservation_id := fnd_api.g_miss_num;
9246 l_rsv_new_rec.reservation_quantity :=
9247 l_qty_to_reserve;
9248 l_rsv_new_rec.secondary_reservation_quantity := -- INVCONV
9249 l_qty2_to_reserve;
9250 l_rsv_new_rec.secondary_uom_code := l_split_line_rec.ordered_quantity_uom2; -- INVCONV
9251 l_rsv_new_rec.primary_reservation_quantity := NULL;
9252 -- l_qty_to_reserve;
9253 l_rsv_new_rec.demand_source_line_id :=
9254 l_split_line_rec.line_id;
9255
9256 -- Call INV's API to Create Reservation.
9257
9258 IF l_debug_level > 0 THEN
9259 oe_debug_pub.add( 'CREATING A NEW RESERVATION FOR : ' || L_QTY_TO_RESERVE || ' WITH LINE ID ' || L_SPLIT_LINE_REC.LINE_ID , 1 ) ;
9260 END IF;
9261
9262 inv_reservation_pub.create_reservation
9263 ( p_api_version_number => 1.0
9264 , p_init_msg_lst => FND_API.G_TRUE
9265 , x_return_status => l_return_status
9266 , x_msg_count => l_msg_count
9267 , x_msg_data => l_msg_data
9268 , p_rsv_rec => l_rsv_new_rec
9269 , p_serial_number => l_dummy_sn
9270 , x_serial_number => l_dummy_sn
9271 , p_partial_reservation_flag => FND_API.G_FALSE
9272 , p_force_reservation_flag => FND_API.G_FALSE
9273 , p_validation_flag => FND_API.G_TRUE
9274 , x_quantity_reserved => l_qty_reserved
9275 , x_secondary_quantity_reserved => l_qty2_reserved -- INVCONV
9276
9277 , x_reservation_id => l_rsv_id);
9278
9279 IF l_debug_level > 0 THEN
9280 oe_debug_pub.add( '5. AFTER CALLING CREATE RESERVATION' || L_RETURN_STATUS , 1 ) ;
9281 oe_debug_pub.add( L_MSG_DATA , 1 ) ;
9282 END IF;
9283
9284 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
9285 THEN
9286 IF l_debug_level > 0 THEN
9287 oe_debug_pub.add( 'UNEXP ERROR : '|| L_MSG_DATA , 1 ) ;
9288 END IF;
9289 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9290 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9291 IF l_msg_data is not null THEN
9292 fnd_message.set_encoded(l_msg_data);
9293 l_buffer := fnd_message.get;
9294 oe_msg_pub.add_text(p_message_text => l_buffer);
9295 IF l_debug_level > 0 THEN
9296 oe_debug_pub.add( 'ERROR : '|| L_BUFFER , 1 ) ;
9297 END IF;
9298 END IF;
9299 -- Need to raise an error, if we are not able to
9300 -- transfer from parent record.
9301 RAISE FND_API.G_EXC_ERROR;
9302 END IF;
9303
9304 IF l_qty_to_tfer_in_this_record > 0
9305 THEN
9306 -- The new split line's ordered quantity is less
9307 -- the quantity of reservation which needs to be
9308 -- transferred. So let's try to find the next record
9309 -- to transfer the the qty to.
9310
9311 goto find_split_line;
9312
9313 END IF;
9314
9315 END IF; /* l_qty_to_tfer_in_this_record > 0 */
9316
9317 l_rsv_tbl.delete(K);
9318 K := l_rsv_tbl.next(K);
9319
9320 END LOOP;
9321 END IF; /* shipped_quantity is null AND not yet interfaced to WSH */
9322
9323 END IF; /* reserved_quantity > 0 */
9324
9325 END IF; /* If operation on the line was UPDATE */
9326
9327 <<end_loop>>
9328 null;
9329 END LOOP;
9330
9331 g_line_action := '';
9332
9333 -- Reset the global flags
9334
9335 G_SOURCE_AGAIN := 'Y';
9336 G_OVERRIDE_FLAG := 'N';
9337
9338 p_x_line_tbl := l_out_line_tbl;
9339 x_return_status := l_return_status;
9340
9341 IF l_debug_level > 0 THEN
9342 oe_debug_pub.add( 'SCHEDULING RESULTS OF THE LINES: ' , 1 ) ;
9343 oe_debug_pub.add( ' ' , 1 ) ;
9344 END IF;
9345
9346 FOR I IN 1..l_out_line_tbl.count LOOP
9347 IF l_debug_level > 0 THEN
9348 oe_debug_pub.add( 'LINE ID : ' || L_OUT_LINE_TBL ( I ) .LINE_ID , 1 ) ;
9349 oe_debug_pub.add( 'SCHEDULE STATUS : ' || L_OUT_LINE_TBL ( I ) .SCHEDULE_STATUS_CODE , 1 ) ;
9350 oe_debug_pub.add( ' ' , 1 ) ;
9351 END IF;
9352 END LOOP;
9353 IF l_debug_level > 0 THEN
9354 oe_debug_pub.add( 'EXITING SPLIT_SCHEDULING WITH ' || L_RETURN_STATUS , 1 ) ;
9355 oe_debug_pub.add( ' ' , 1 ) ;
9356 END IF;
9357
9358 EXCEPTION
9359 WHEN OTHERS THEN
9360 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9361
9362 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
9363 THEN
9364 OE_MSG_PUB.Add_Exc_Msg
9365 ( G_PKG_NAME
9366 , 'Split_Scheduling'
9367 );
9368 END IF;
9369
9370 END SPLIT_SCHEDULING;
9371
9372 /*--------------------------------------------------------------------------
9373 Procedure Name : SPLIT_RESERVATIONS
9374 Description : ** Currently not used. **
9375 -------------------------------------------------------------------------- */
9376
9377 Procedure SPLIT_RESERVATIONS
9378 ( p_reserved_line_id IN NUMBER
9379 , p_ordered_quantity IN NUMBER
9380 , p_reserved_quantity IN NUMBER
9381 , x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
9382 IS
9383 l_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
9384 l_header_id NUMBER;
9385 l_p_header_id NUMBER;
9386 l_line_id NUMBER;
9387 l_ordered_quantity NUMBER;
9388 l_shipped_quantity NUMBER;
9389 l_sales_order_id NUMBER;
9390 l_count NUMBER;
9391 l_x_error_code NUMBER;
9392 l_lock_records VARCHAR2(1);
9393 l_sort_by_req_date NUMBER;
9394
9395 l_rsv_rec inv_reservation_global.mtl_reservation_rec_type;
9396 l_rsv_new_rec inv_reservation_global.mtl_reservation_rec_type;
9397 l_msg_count NUMBER;
9398 l_msg_data VARCHAR2(240);
9399 l_rsv_id NUMBER;
9400 l_rsv_tbl inv_reservation_global.mtl_reservation_tbl_type;
9401 l_dummy_sn inv_reservation_global.serial_number_tbl_type;
9402
9403 l_buffer VARCHAR2(2000);
9404 l_ship_from_org_id NUMBER;
9405
9406 cursor split_lines
9407 IS select header_id,
9408 line_id ,
9409 ordered_quantity,
9410 shipped_quantity
9411 from oe_order_lines where
9412 split_from_line_id = p_reserved_line_id;
9413
9414 --
9415 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
9416 --
9417 BEGIN
9418
9419 -- Query the reserved records
9420
9421 BEGIN
9422 SELECT header_id, ship_from_org_id
9423 into l_p_header_id, l_ship_from_org_id
9424 from oe_order_lines
9425 where line_id = p_reserved_line_id;
9426 EXCEPTION
9427 WHEN NO_DATA_FOUND THEN
9428 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9429 END;
9430
9431 l_sales_order_id := Get_mtl_sales_order_id(l_header_id);
9432 l_rsv_rec.demand_source_header_id := l_sales_order_id;
9433 l_rsv_rec.demand_source_line_id := p_reserved_line_id;
9434 l_rsv_rec.organization_id := l_ship_from_org_id;
9435
9436 IF l_debug_level > 0 THEN
9437 oe_debug_pub.add( 'CALLING INVS QUERY_RESERVATION ' , 1 ) ;
9438 END IF;
9439
9440 inv_reservation_pub.query_reservation
9441 ( p_api_version_number => 1.0
9442 , p_init_msg_lst => fnd_api.g_true
9443 , x_return_status => l_return_status
9444 , x_msg_count => l_msg_count
9445 , x_msg_data => l_msg_data
9446 , p_query_input => l_rsv_rec
9447 , x_mtl_reservation_tbl => l_rsv_tbl
9448 , x_mtl_reservation_tbl_count => l_count
9449 , x_error_code => l_x_error_code
9450 , p_lock_records => l_lock_records
9451 , p_sort_by_req_date => l_sort_by_req_date
9452 );
9453
9454 IF l_debug_level > 0 THEN
9455 oe_debug_pub.add( 'AFTER CALLING INVS QUERY_RESERVATION: ' || L_RETURN_STATUS , 1 ) ;
9456 END IF;
9457
9458 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9459 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9460 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9461 RAISE FND_API.G_EXC_ERROR;
9462 END IF;
9463
9464 IF l_debug_level > 0 THEN
9465 oe_debug_pub.add( 'COUNT IS RESERVATION RECORDS IS' || L_RSV_TBL.COUNT , 1 ) ;
9466 END IF;
9467
9468 -- There can be 2 kinds of splits. One where the use split,
9469 -- in which case, the reservations have to split. And another
9470 -- when shipping occurs partially. In that case, the remaining
9471 -- reservation is trasferred to the new line.
9472
9473 OPEN split_lines;
9474
9475 LOOP
9476
9477 FETCH split_lines
9478 INTO
9479 l_header_id,l_line_id,l_ordered_quantity, l_shipped_quantity;
9480 EXIT WHEN split_lines%NOTFOUND;
9481
9482 IF l_shipped_quantity is not null THEN
9483 -- This is the case where line was split due to shipping
9484
9485 FOR I IN 1..l_rsv_tbl.COUNT LOOP
9486
9487 l_rsv_rec := l_rsv_tbl(I);
9488
9489 l_rsv_new_rec := l_rsv_rec;
9490 l_rsv_new_rec.demand_source_line_id := l_line_id;
9491
9492 IF l_debug_level > 0 THEN
9493 oe_debug_pub.add( 'CALLING INVS UPDATE_RESERVATION: ' , 1 ) ;
9494 END IF;
9495
9496 inv_reservation_pub.update_reservation
9497 ( p_api_version_number => 1.0
9498 , p_init_msg_lst => fnd_api.g_true
9499 , x_return_status => l_return_status
9500 , x_msg_count => l_msg_count
9501 , x_msg_data => l_msg_data
9502 , p_original_rsv_rec => l_rsv_rec
9503 , p_to_rsv_rec => l_rsv_new_rec
9504 , p_original_serial_number => l_dummy_sn -- no serial contorl
9505 , p_to_serial_number => l_dummy_sn -- no serial control
9506 , p_validation_flag => fnd_api.g_true
9507 );
9508
9509 IF l_debug_level > 0 THEN
9510 oe_debug_pub.add( 'AFTER CALLING INVS UPDATE_RESERVATION: ' || L_RETURN_STATUS , 1 ) ;
9511 END IF;
9512
9513 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9514 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9515 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9516 IF l_msg_data is not null THEN
9517 fnd_message.set_encoded(l_msg_data);
9518 l_buffer := fnd_message.get;
9519 oe_msg_pub.add_text(p_message_text => l_buffer);
9520 IF l_debug_level > 0 THEN
9521 oe_debug_pub.add( 'ERROR : '|| L_BUFFER , 1 ) ;
9522 END IF;
9523 END IF;
9524 RAISE FND_API.G_EXC_ERROR;
9525 END IF;
9526 END LOOP;
9527
9528 ELSE
9529 -- This is the case where line was split by the user
9530 null;
9531 END IF;
9532 END LOOP;
9533
9534 x_return_status := l_return_status;
9535
9536 END SPLIT_RESERVATIONS;
9537
9538 /*--------------------------------------------------------------------------
9539 Procedure Name : Update_Results_from_backlog_wb
9540 Description : This procedure is called from the backlog's scheduler's
9541 workbenck and the Supply Chain ATP form, after the user
9542 has performed some scheduling in their form. They call
9543 this API to update the results of scheduling on the order
9544 lines table.
9545 For the purpose of this call, we have created a new table type
9546 mrp_line_tbl_type, which is table of mrp_line_rec_type.
9547 This record is created with only those fields whose values
9548 we can get back from MRP's form. We take the field values
9549 from this record and update the lines information in
9550 oe_order_lines table.
9551 -------------------------------------------------------------------------- */
9552 Procedure Update_Results_from_backlog_wb
9553 ( p_mrp_line_tbl IN mrp_line_tbl_type
9554 , x_msg_count OUT NOCOPY /* file.sql.39 change */ NUMBER
9555 , x_msg_data OUT NOCOPY /* file.sql.39 change */ VARCHAR2
9556 , x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
9557 IS
9558 l_schedule_line_rec request_rec_type;
9559 l_line_rec OE_ORDER_PUB.line_rec_type;
9560 l_sch_rec sch_rec_type;
9561 I NUMBER;
9562 l_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
9563 l_msg_count NUMBER := 0;
9564 l_msg_data VARCHAR2(2000) := null;
9565 l_control_rec OE_GLOBALS.control_rec_type;
9566 l_line_tbl OE_ORDER_PUB.line_tbl_type;
9567 l_old_line_tbl OE_ORDER_PUB.line_tbl_type;
9568 l_mrp_line_tbl OE_SCHEDULE_UTIL.mrp_line_tbl_type;
9569 /*
9570 l_header_out_rec OE_Order_PUB.Header_Rec_Type;
9571 l_header_rec OE_Order_PUB.Header_Rec_Type;
9572 l_line_out_tbl OE_Order_PUB.Line_Tbl_Type;
9573 l_header_adj_out_tbl OE_Order_PUB.Header_Adj_Tbl_Type;
9574 l_header_scredit_out_tbl OE_Order_PUB.Header_Scredit_Tbl_Type;
9575 l_line_adj_out_tbl OE_Order_PUB.Line_Adj_Tbl_Type;
9576 l_line_scredit_out_tbl OE_Order_PUB.Line_Scredit_Tbl_Type;
9577 l_lot_serial_out_tbl OE_Order_PUB.Lot_Serial_Tbl_Type;
9578 l_action_request_out_tbl OE_Order_PUB.Request_Tbl_Type;
9579 l_Header_Adj_Att_tbl OE_ORDER_PUB.Header_Adj_Att_Tbl_Type;
9580 l_Header_Adj_Assoc_tbl OE_ORDER_PUB.Header_Adj_Assoc_Tbl_Type;
9581 l_Header_price_Att_tbl OE_ORDER_PUB.Header_Price_Att_Tbl_Type;
9582 l_Line_Price_Att_tbl OE_ORDER_PUB.Line_Price_Att_Tbl_Type;
9583 l_Line_Adj_Att_tbl OE_ORDER_PUB.Line_Adj_Att_Tbl_Type;
9584 l_Line_Adj_Assoc_tbl OE_ORDER_PUB.Line_Adj_Assoc_Tbl_Type;
9585 */
9586 l_file_val VARCHAR2(80);
9587 --
9588 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
9589 --
9590 BEGIN
9591
9592
9593 -- l_file_val := OE_DEBUG_PUB.Set_Debug_Mode('FILE');
9594 -- OE_DEBUG_PUB.Initialize;
9595 -- OE_DEBUG_PUB.Debug_Off;
9596 -- OE_DEBUG_PUB.Debug_On;
9597 -- oe_Debug_pub.setdebuglevel(5);
9598
9599 -- 4504362 : Branch scheduling check removed.
9600
9601 IF l_debug_level > 0 THEN
9602 oe_debug_pub.add( 'BEFORE CALLING NEW CODE' , 1 ) ;
9603 END IF;
9604
9605 FOR I in 1..p_mrp_line_tbl.count LOOP
9606
9607 l_mrp_line_tbl(I).line_id := p_mrp_line_tbl(I).line_id;
9608 l_mrp_line_tbl(I).schedule_ship_date := p_mrp_line_tbl(I).schedule_ship_date;
9609 l_mrp_line_tbl(I).schedule_arrival_date := p_mrp_line_tbl(I).schedule_arrival_date;
9610 l_mrp_line_tbl(I).ship_from_org_id := p_mrp_line_tbl(I).ship_from_org_id;
9611 l_mrp_line_tbl(I).ship_method_code := p_mrp_line_tbl(I).ship_method_code;
9612 END LOOP;
9613
9614 OE_SCHEDULE_UTIL.Update_Results_from_backlog_wb
9615 (p_mrp_line_tbl => l_mrp_line_tbl,
9616 x_msg_count => x_msg_count,
9617 x_msg_data => x_msg_data,
9618 x_return_status => x_return_status);
9619
9620 IF l_debug_level > 0 THEN
9621 oe_debug_pub.add( 'X_RETURN_STATUS IS ' || X_RETURN_STATUS , 1 ) ;
9622 END IF;
9623
9624
9625 IF l_debug_level > 0 THEN
9626 oe_debug_pub.add( 'EXITING UPDATE_RESULTS_FROM_BACKLOG_WB' , 1 ) ;
9627 END IF;
9628 OE_DEBUG_PUB.Debug_Off;
9629 EXCEPTION
9630
9631 WHEN FND_API.G_EXC_ERROR THEN
9632
9633 x_return_status := FND_API.G_RET_STS_ERROR;
9634
9635 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9636
9637 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9638
9639 WHEN OTHERS THEN
9640
9641 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9642
9643 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
9644 THEN
9645 OE_MSG_PUB.Add_Exc_Msg
9646 ( G_PKG_NAME
9647 , 'Schedule_line'
9648 );
9649 END IF;
9650 END Update_Results_from_backlog_wb;
9651
9652 /*--------------------------------------------------------------------------
9653 Procedure Name : Get_Session_Id
9654 Description : This procedure returns the session_id which will be
9655 passed to MRP's ATP API.
9656 --------------------------------------------------------------------------*/
9657 FUNCTION Get_Session_Id
9658 RETURN number
9659 IS
9660 --
9661 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
9662 --
9663 BEGIN
9664
9665 -- IF MRP_SESSION_ID = 0 THEN
9666 SELECT mrp_atp_schedule_temp_s.nextval
9667 INTO MRP_SESSION_ID
9668 from dual;
9669 -- END IF;
9670
9671 return MRP_SESSION_ID;
9672 EXCEPTION
9673 WHEN OTHERS THEN
9674 return 0;
9675 END Get_Session_Id;
9676
9677 /*--------------------------------------------------------------------------
9678 Procedure Name : Get_MRP_Session_Id
9679 Description : This procedure returns the MRP_session_id which will be
9680 Used in the pld.
9681 --------------------------------------------------------------------------*/
9682 FUNCTION Get_MRP_Session_Id
9683 RETURN number
9684 IS
9685 --
9686 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
9687 --
9688 BEGIN
9689 return MRP_SESSION_ID;
9690 EXCEPTION
9691 WHEN OTHERS THEN
9692 return 0;
9693 END Get_MRP_Session_Id;
9694
9695 /*--------------------------------------------------------------------------
9696 Procedure Name : Insert_Mandatory_Components
9697 Description : This procedure is called from the form side, when the user
9698 clicks on global availability button and the item to check
9699 global availability is an ATO Model. We insert the mandatory
9700 components in MRP_ATP_SCHEDULE_TEMP for global availability.
9701 --------------------------------------------------------------------------*/
9702 Procedure Insert_Mandatory_Components
9703 (p_order_number IN NUMBER,
9704 p_ato_line_id IN NUMBER,
9705 p_customer_name IN VARCHAR2,
9706 p_customer_location IN VARCHAR2,
9707 p_arrival_set_name IN VARCHAR2,
9708 p_ship_set_name IN VARCHAR2,
9709 p_ship_set_id IN NUMBER,
9710 p_requested_ship_date IN DATE,
9711 p_requested_arrival_date IN DATE,
9712 p_session_id IN NUMBER,
9713 p_instance_id IN NUMBER,
9714 p_insert_code IN NUMBER,
9715 x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2
9716 )
9717 IS
9718 l_model_line_rec OE_ORDER_PUB.line_rec_type;
9719 l_model_rec MRP_ATP_PUB.ATP_Rec_Typ;
9720 l_smc_rec MRP_ATP_PUB.ATP_Rec_Typ;
9721 l_ship_set VARCHAR2(30);
9722 lTableName VARCHAR2(30);
9723 lMessageName VARCHAR2(30);
9724 lErrorMessage VARCHAR2(2000);
9725 l_result NUMBER := 1;
9726
9727 l_scenario_id NUMBER := -1;
9728 l_line_id NUMBER;
9729 l_header_id NUMBER;
9730 l_ato_line_id NUMBER;
9731 l_inventory_item_id NUMBER;
9732 l_ordered_item VARCHAR2(2000);
9733 l_sold_to_org_id NUMBER;
9734 l_ship_to_org_id NUMBER;
9735 l_ship_from_org_id NUMBER;
9736 l_quantity_ordered NUMBER;
9737 l_uom_code VARCHAR2(3);
9738 l_latest_acceptable_date DATE;
9739 l_line_number NUMBER;
9740 l_shipment_number NUMBER;
9741 l_option_number NUMBER;
9742 l_delivery_lead_time NUMBER;
9743 l_promise_date DATE;
9744 l_project_id NUMBER;
9745 l_task_id NUMBER;
9746 l_ship_method VARCHAR2(30) := null;
9747 l_demand_class VARCHAR2(30) := null;
9748 l_ship_set_id NUMBER;
9749 l_arrival_set_id NUMBER;
9750 l_ship_method_text VARCHAR2(80);
9751 l_project_number NUMBER;
9752 l_task_number NUMBER;
9753 l_st_atp_lead_time NUMBER := 0;
9754 l_order_number NUMBER;
9755 --
9756 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
9757 --
9758 BEGIN
9759 SAVEPOINT insert_mand_comp;
9760
9761 -- l_model_line_rec := OE_LINE_UTIL.Query_Row(p_ato_line_id);
9762
9763 OE_Line_Util.Query_Row(p_line_id => p_ato_line_id,
9764 x_line_rec => l_model_line_rec);
9765
9766 l_st_atp_lead_time :=
9767 Get_Lead_Time
9768 (p_ato_line_id => l_model_line_rec.ato_line_id,
9769 p_ship_from_org_id => l_model_line_rec.ship_from_org_id);
9770
9771 l_model_rec.Inventory_Item_Id := MRP_ATP_PUB.number_arr
9772 (l_model_line_rec.Inventory_Item_Id);
9773
9774 l_model_rec.Source_Organization_Id := MRP_ATP_PUB.number_arr
9775 (l_model_line_rec.ship_from_org_id);
9776
9777 l_model_rec.Identifier := MRP_ATP_PUB.number_arr
9778 (l_model_line_rec.line_id);
9779
9780 l_model_rec.Calling_Module := MRP_ATP_PUB.number_arr
9781 (660);
9782
9783 l_model_rec.Customer_Id := MRP_ATP_PUB.number_arr
9784 (l_model_line_rec.sold_to_org_id);
9785
9786 l_model_rec.Customer_Site_Id := MRP_ATP_PUB.number_arr
9787 (l_model_line_rec.ship_to_org_id);
9788
9789 l_model_rec.Destination_Time_Zone := MRP_ATP_PUB.char30_arr
9790 (null);
9791
9792 l_model_rec.Quantity_Ordered := MRP_ATP_PUB.number_arr
9793 (l_model_line_rec.ordered_quantity);
9794
9795 l_model_rec.Quantity_UOM := MRP_ATP_PUB.char3_arr
9796 (l_model_line_rec.order_quantity_uom);
9797
9798 l_model_rec.Earliest_Acceptable_Date := MRP_ATP_PUB.date_arr
9799 (l_model_line_rec.Earliest_Acceptable_Date);
9800
9801 l_model_rec.Requested_Ship_Date := MRP_ATP_PUB.date_arr
9802 (l_model_line_rec.request_date);
9803
9804 l_model_rec.Requested_Arrival_Date := MRP_ATP_PUB.date_arr
9805 (l_model_line_rec.request_date);
9806
9807 l_model_rec.Latest_Acceptable_Date := MRP_ATP_PUB.date_arr
9808 (l_model_line_rec.Latest_Acceptable_Date);
9809
9810 l_model_rec.Delivery_Lead_Time := MRP_ATP_PUB.number_arr
9811 (l_model_line_rec.Delivery_Lead_Time);
9812 l_model_rec.Atp_lead_Time := MRP_ATP_PUB.number_arr
9813 (l_st_atp_lead_time);
9814
9815 l_model_rec.Freight_Carrier := MRP_ATP_PUB.char30_arr
9816 (l_model_line_rec.Freight_Carrier_Code);
9817
9818 l_model_rec.Ship_Method := MRP_ATP_PUB.char30_arr
9819 (null);
9820
9821 l_model_rec.Demand_Class := MRP_ATP_PUB.char30_arr
9822 (l_model_line_rec.Demand_Class_Code);
9823
9824 l_model_rec.Ship_Set_Name := MRP_ATP_PUB.char30_arr
9825 (l_model_line_rec.ship_set_id);
9826
9827 l_model_rec.Arrival_Set_Name := MRP_ATP_PUB.char30_arr
9828 (l_model_line_rec.arrival_set_id);
9829
9830 l_model_rec.Override_Flag := MRP_ATP_PUB.char1_arr
9831 (null);
9832
9833 l_model_rec.Ship_Date := MRP_ATP_PUB.date_arr
9834 (null);
9835
9836 l_model_rec.Available_Quantity := MRP_ATP_PUB.number_arr
9837 (null);
9838
9839 l_model_rec.Requested_Date_Quantity := MRP_ATP_PUB.number_arr
9840 (null);
9841
9842 l_model_rec.Group_Ship_Date := MRP_ATP_PUB.date_arr
9843 (null);
9844
9845 l_model_rec.Group_Arrival_Date := MRP_ATP_PUB.date_arr
9846 (null);
9847
9848 l_model_rec.Vendor_Id := MRP_ATP_PUB.number_arr
9849 (null);
9850
9851 l_model_rec.Vendor_Site_Id := MRP_ATP_PUB.number_arr
9852 (null);
9853
9854 l_model_rec.Insert_Flag := MRP_ATP_PUB.number_arr
9855 (null);
9856
9857 l_model_rec.Error_Code := MRP_ATP_PUB.number_arr
9858 (null);
9859
9860 l_model_rec.Message := MRP_ATP_PUB.char2000_arr
9861 (null);
9862
9863 l_model_rec.Action := MRP_ATP_PUB.number_arr
9864 (null);
9865
9866 l_order_number := Get_order_number(l_model_line_rec.header_id);
9867
9868 l_model_rec.Order_number := MRP_ATP_PUB.number_arr
9869 (l_order_number);
9870
9871 IF l_debug_level > 0 THEN
9872 oe_debug_pub.add( '1.. CALLING CTO GET_BOM_MANDATORY_COMPS' , 1 ) ;
9873 END IF;
9874
9875 BEGIN
9876 l_result := CTO_CONFIG_ITEM_PK.GET_MANDATORY_COMPONENTS
9877 (p_ship_set => l_model_rec,
9878 p_organization_id => null,
9879 p_inventory_item_id => null,
9880 x_smc_rec => l_smc_rec,
9881 xErrorMessage => lErrorMessage,
9882 xMessageName => lMessageName,
9883 xTableName => lTableName);
9884
9885 IF l_debug_level > 0 THEN
9886 oe_debug_pub.add( '1. AFTER CALLING CTO API : ' || L_RESULT , 1 ) ;
9887 oe_debug_pub.add( 'COUNT IS: ' || L_SMC_REC.INVENTORY_ITEM_ID.COUNT , 1 ) ;
9888 END IF;
9889
9890 EXCEPTION
9891 WHEN OTHERS THEN
9892 IF l_debug_level > 0 THEN
9893 oe_debug_pub.add( 'CTO API RETURNED AN UNEXPECTED ERROR' ) ;
9894 END IF;
9895 l_result := 0;
9896 END;
9897
9898 /*
9899 IF l_result <> 1 THEN
9900 IF lErrorMessage is not null THEN
9901 oe_msg_pub.add_text(p_message_text => lErrorMessage);
9902 END IF;
9903 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9904 END IF;
9905 */
9906
9907 IF l_result = 1 AND
9908 l_smc_rec.Identifier.count >= 1 THEN
9909
9910 IF l_debug_level > 0 THEN
9911 oe_debug_pub.add( 'SMC COUNT IS : ' || L_SMC_REC.IDENTIFIER.COUNT , 1 ) ;
9912 END IF;
9913
9914 FOR J IN 1..l_smc_rec.Identifier.count LOOP
9915 l_line_id := l_smc_rec.Identifier(J);
9916 l_header_id := l_model_line_rec.header_id;
9917 l_ato_line_id := l_model_line_rec.ato_line_id;
9918 l_inventory_item_id := l_smc_rec.Inventory_Item_Id(J);
9919 l_ordered_item := null;
9920 l_sold_to_org_id := l_model_line_rec.sold_to_org_id;
9921 l_ship_to_org_id := l_model_line_rec.ship_to_org_id;
9922 l_ship_from_org_id := l_model_line_rec.ship_from_org_id;
9923 l_demand_class := l_model_line_rec.demand_class_code;
9924 l_quantity_ordered := l_smc_rec.Quantity_Ordered(J);
9925 l_uom_code := l_smc_rec.Quantity_UOM(J);
9926 l_latest_acceptable_date :=
9927 l_model_line_rec.latest_acceptable_date;
9928 l_line_number := l_model_line_rec.line_number;
9929 l_shipment_number := l_model_line_rec.line_number;
9930 l_option_number := l_model_line_rec.option_number;
9931 l_delivery_lead_time := l_model_line_rec.delivery_lead_time;
9932 l_promise_date := l_model_line_rec.promise_date;
9933 l_project_id := l_model_line_rec.project_id;
9934 l_task_id := l_model_line_rec.task_id;
9935 l_ship_method := l_model_line_rec.shipping_method_code;
9936 l_arrival_set_id := l_model_line_rec.arrival_set_id;
9937
9938 l_ship_method_text := l_ship_method;
9939 l_project_number := l_project_id;
9940 l_task_number := l_task_id;
9941
9942 IF l_inventory_item_id is not null AND
9943 l_ship_from_org_id is not null
9944 THEN
9945 BEGIN
9946
9947 SELECT concatenated_segments
9948 INTO l_ordered_item
9949 FROM mtl_system_items_vl
9950 WHERE inventory_item_id = l_inventory_item_id
9951 AND organization_id = l_ship_from_org_id;
9952
9953 EXCEPTION
9954 WHEN OTHERS THEN
9955 null;
9956 END;
9957
9958 END IF;
9959
9960
9961 INSERT INTO MRP_ATP_SCHEDULE_TEMP
9962 (INVENTORY_ITEM_ID,
9963 SR_INSTANCE_ID,
9964 SOURCE_ORGANIZATION_ID,
9965 CUSTOMER_ID,
9966 CUSTOMER_SITE_ID,
9967 DESTINATION_TIME_ZONE,
9968 QUANTITY_ORDERED,
9969 UOM_CODE,
9970 REQUESTED_SHIP_DATE,
9971 REQUESTED_ARRIVAL_DATE,
9972 LATEST_ACCEPTABLE_DATE,
9973 DELIVERY_LEAD_TIME,
9974 FREIGHT_CARRIER,
9975 INSERT_FLAG,
9976 SHIP_METHOD,
9977 DEMAND_CLASS,
9978 SHIP_SET_NAME,
9979 SHIP_SET_ID,
9980 ARRIVAL_SET_NAME,
9981 ARRIVAL_SET_ID,
9982 ATP_LEAD_TIME,
9983 OVERRIDE_FLAG,
9984 SESSION_ID,
9985 ORDER_HEADER_ID,
9986 ORDER_LINE_ID,
9987 INVENTORY_ITEM_NAME,
9988 SOURCE_ORGANIZATION_CODE,
9989 ORDER_LINE_NUMBER,
9990 SHIPMENT_NUMBER,
9991 OPTION_NUMBER,
9992 PROMISE_DATE,
9993 CUSTOMER_NAME,
9994 CUSTOMER_LOCATION,
9995 OLD_LINE_SCHEDULE_DATE,
9996 OLD_SOURCE_ORGANIZATION_CODE,
9997 CALLING_MODULE,
9998 ACTION,
9999 STATUS_FLAG,
10000 SCENARIO_ID,
10001 ORDER_NUMBER,
10002 OLD_SOURCE_ORGANIZATION_ID,
10003 OLD_DEMAND_CLASS,
10004 PROJECT_ID,
10005 TASK_ID,
10006 PROJECT_NUMBER,
10007 TASK_NUMBER,
10008 SHIP_METHOD_TEXT
10009 )
10010 VALUES
10011 (l_inventory_item_id,
10012 p_instance_id,
10013 null,
10014 l_sold_to_org_id, -- CUSTOMER_ID
10015 l_ship_to_org_id, -- CUSTOMER_SITE_ID
10016 null, -- DESTINATION_TIME_ZONE
10017 l_quantity_ordered,
10018 l_uom_code,
10019 p_requested_ship_date,
10020 p_requested_arrival_date,
10021 l_latest_acceptable_date,
10022 l_delivery_lead_time,
10023 null, -- FREIGHT_CARRIER,
10024 p_insert_code,
10025 l_ship_method,
10026 l_demand_class,
10027 p_ship_set_name,
10028 p_ship_set_id,
10029 p_arrival_set_name,
10030 l_arrival_set_id,
10031 l_st_atp_lead_time,
10032 null, -- OVERRIDE_FLAG
10033 p_session_id,
10034 l_header_id,
10035 l_line_id,
10036 l_ordered_item, -- l_INVENTORY_ITEM_NAME,
10037 null, -- l_SOURCE_ORGANIZATION_CODE,
10038 l_line_number,
10039 l_shipment_number,
10040 l_option_number,
10041 l_promise_date,
10042 p_customer_name,
10043 p_customer_location,
10044 null, -- l_OLD_LINE_SCHEDULE_DATE,
10045 null, -- l_OLD_SOURCE_ORGANIZATION_CODE,
10046 null, -- l_CALLING_MODULE,
10047 100,
10048 4, -- l_STATUS_FLAG,
10049 l_scenario_id,
10050 p_order_number,
10051 l_ship_from_org_id,
10052 l_demand_class,
10053 l_project_id,
10054 l_task_id,
10055 l_project_number,
10056 l_task_number,
10057 l_ship_method_text
10058 );
10059
10060 END LOOP;
10061 END IF;
10062
10063 x_return_status := FND_API.G_RET_STS_SUCCESS;
10064
10065 EXCEPTION
10066 WHEN OTHERS THEN
10067 ROLLBACK TO SAVEPOINT insert_mand_comp;
10068 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10069
10070 END Insert_Mandatory_Components;
10071
10072 /*--------------------------------------------------------------------------
10073 Procedure Name : Update_PO
10074 Description : This procedure is called whenever there is a change to
10075 schedule_ship_date on an internal order. PO has a callback
10076 we need to call to notify them of this change.
10077 --------------------------------------------------------------------------*/
10078
10079 Procedure Update_PO(p_schedule_ship_date IN DATE,
10080 p_source_document_id IN VARCHAR2,
10081 p_source_document_line_id IN VARCHAR2)
10082 IS
10083 po_result BOOLEAN;
10084 --
10085 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
10086 --
10087 BEGIN
10088
10089 IF l_debug_level > 0 THEN
10090 oe_debug_pub.add( 'ENTERING OE_ORDER_SCH_UTIL.UPDATE_PO' , 2 ) ;
10091 END IF;
10092
10093 -- Call po if internal req and quantity is changed
10094
10095 IF p_source_document_line_id IS NOT NULL THEN
10096
10097 IF l_debug_level > 0 THEN
10098 oe_debug_pub.add( 'DATE ' || P_SCHEDULE_SHIP_DATE , 2 ) ;
10099 END IF;
10100
10101 po_result := po_supply.po_req_supply(
10102 p_docid => p_source_document_id,
10103 p_lineid => p_source_document_line_id,
10104 p_shipid => p_source_document_line_id,
10105 p_action => 'Update_Req_Line_Date',
10106 p_recreate_flag => FALSE,
10107 p_qty => null,
10108 p_receipt_date => p_schedule_ship_date);
10109 END IF;
10110
10111 IF l_debug_level > 0 THEN
10112 oe_debug_pub.add( 'EXITING OE_ORDER_SCH_UTIL.UPDATE_PO' , 1 ) ;
10113 END IF;
10114
10115 EXCEPTION
10116 WHEN OTHERS THEN
10117 IF l_debug_level > 0 THEN
10118 oe_debug_pub.add( 'EXCEPTION IN UPDATE_PO' , 2 ) ;
10119 END IF;
10120 END Update_PO;
10121
10122 Procedure Delete_Row(p_line_id IN NUMBER)
10123 IS
10124 l_line_rec OE_ORDER_PUB.line_rec_type;
10125 l_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
10126 l_sales_order_id NUMBER;
10127 --
10128 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
10129 --
10130 BEGIN
10131
10132 IF l_debug_level > 0 THEN
10133 oe_debug_pub.add( 'ENTERING OE_ORDER_SCH_UTIL.DELETE_ROW' , 1 ) ;
10134 END IF;
10135 OE_Line_Util.Query_Row(p_line_id => p_line_id,
10136 x_line_rec => l_line_rec);
10137
10138 IF l_debug_level > 0 THEN
10139 oe_debug_pub.add( 'ITEM TYPE :' || L_LINE_REC.ITEM_TYPE_CODE , 1 ) ;
10140 END IF;
10141
10142 /* Fix for bug 2643593, reservations to be removed only for
10143 shippable line */
10144
10145 IF nvl(l_line_rec.shippable_flag,'N') = 'Y' THEN
10146
10147 l_sales_order_id := OE_ORDER_SCH_UTIL.Get_mtl_sales_order_id
10148 (l_line_rec.HEADER_ID);
10149
10150 -- INVCONV - MERGED CALLS FOR OE_LINE_UTIL.Get_Reserved_Quantity and OE_LINE_UTIL.Get_Reserved_Quantity2
10151
10152 OE_LINE_UTIL.Get_Reserved_Quantities(p_header_id => l_sales_order_id
10153 ,p_line_id => l_line_rec.line_id
10154 ,p_org_id => l_line_rec.ship_from_org_id
10155 ,x_reserved_quantity => l_line_rec.reserved_quantity
10156 ,x_reserved_quantity2 => l_line_rec.reserved_quantity2
10157 );
10158
10159
10160 /*l_line_rec.reserved_quantity :=
10161 OE_LINE_UTIL.Get_Reserved_Quantity
10162 (p_header_id => l_sales_order_id,
10163 p_line_id => l_line_rec.line_id,
10164 p_org_id => l_line_rec.ship_from_org_id);
10165 l_line_rec.reserved_quantity2 := -- INVCONV
10166 OE_LINE_UTIL.Get_Reserved_Quantity2
10167 (p_header_id => l_sales_order_id,
10168 p_line_id => l_line_rec.line_id,
10169 p_org_id => l_line_rec.ship_from_org_id); */
10170
10171 IF l_line_rec.reserved_quantity is not null AND
10172 nvl(l_line_rec.shipping_interfaced_flag, 'N') = 'N'
10173 THEN
10174 -- Call INV to delete the old reservations
10175 Unreserve_Line
10176 (p_line_rec => l_line_rec,
10177 p_quantity_to_unreserve => l_line_rec.reserved_quantity,
10178 p_quantity2_to_unreserve => l_line_rec.reserved_quantity2, -- INVCONV
10179
10180 x_return_status => l_return_status);
10181 END IF;
10182
10183 END IF; /* Check for shippable flag */
10184
10185 -- To fix bug 2060293
10186 IF l_line_rec.item_type_code <> OE_GLOBALS.G_ITEM_CONFIG THEN
10187 Action_Undemand(p_old_line_rec => l_line_rec,
10188 x_return_status => l_return_status);
10189 END IF;
10190
10191
10192 IF l_debug_level > 0 THEN
10193 oe_debug_pub.add( 'EXITING OE_ORDER_SCH_UTIL.DELETE_ROW' , 1 ) ;
10194 END IF;
10195 EXCEPTION
10196
10197 WHEN OTHERS THEN
10198
10199 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
10200 THEN
10201 OE_MSG_PUB.Add_Exc_Msg
10202 ( G_PKG_NAME
10203 , 'Delete_row'
10204 );
10205 END IF;
10206 END Delete_Row;
10207
10208 -- added by fabdi 03/May/2001 - For process ATP
10209 /*--------------------------------------------------------------------------
10210 Procedure Name : get_process_query_quantities
10211 Description : This precedure works out the on_hand_qty and avail_to_reserve
10212 quanties to display in the same ATP window for process inventory only. The procedure
10213 takes into account grade controlled items and displays inventory result for a particular
10214 grade as well a total sum if grade is null.
10215 This procedure is called from Query_Qty_Tree only
10216 -------------------------------------------------------------------------- INVCONV - NOT USED NOW
10217
10218 PROCEDURE get_process_query_quantities
10219 ( p_org_id IN NUMBER
10220 , p_item_id IN NUMBER
10221 , p_line_id IN NUMBER
10222 , x_on_hand_qty OUT NOCOPY NUMBER
10223 , x_avail_to_reserve OUT NOCOPY NUMBER
10224 ) IS
10225
10226 l_on_hand_qty2 NUMBER;
10227 l_avail_to_reserve2 NUMBER;
10228 --
10229 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
10230 --
10231 BEGIN
10232
10233 IF l_debug_level > 0 THEN
10234 oe_debug_pub.add( 'INSIDE GET_PROCESS_QUERY_QUANTITIES ' ) ;
10235 oe_debug_pub.add( 'P_LINE_ID - IN GET_PROCESS_QUERY_QUANTITIES IS: '|| P_LINE_ID ) ;
10236 END IF;
10237 GMI_RESERVATION_PVT.query_qty_for_ATP
10238 ( p_organization_id => p_org_id
10239 , p_item_id => p_item_id
10240 , p_demand_source_line_id => p_line_id
10241 , x_onhand_qty1 => x_on_hand_qty
10242 , x_onhand_qty2 => l_on_hand_qty2
10243 , x_avail_qty1 => x_avail_to_reserve
10244 , x_avail_qty2 => l_avail_to_reserve2
10245 );
10246
10247
10248 IF l_debug_level > 0 THEN
10249 oe_debug_pub.add( 'POCESS X_ON_HAND_QTY IS: '|| X_ON_HAND_QTY ) ;
10250 oe_debug_pub.add( 'PROCESS X_AVAIL_TO_RESERVE IS: '|| X_AVAIL_TO_RESERVE ) ;
10251 END IF;
10252
10253 END get_process_query_quantities; */
10254 -- end fabdi
10255
10256 /*-----------------------------------------------------+
10257 | Name : Post_Forms_Commit |
10258 | Parameters : |
10259 | |
10260 | Description : This Procedure is called from |
10261 | OEOXOEFRM.pld POST_FORMS_COMMIT |
10262 | This Procedure was added for |
10263 | Bug: 2097933. |
10264 | With this procedure we check if |
10265 | there is sufficient Qty for |
10266 | Reservation just before we are |
10267 | Committing the line. |
10268 | If there is no sufficient Qty for |
10269 | reservation then the Inventory |
10270 | populates a pl-sql table. Before |
10271 | commit we check if the pl-sql table |
10272 | is NOT Null or not. |
10273 +-----------------------------------------------------*/
10274
10275 Procedure Post_Forms_Commit
10276 (x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2
10277 ,x_msg_count OUT NOCOPY /* file.sql.39 change */ NUMBER
10278 ,x_msg_data OUT NOCOPY /* file.sql.39 change */ VARCHAR2) IS
10279 l_return_status VARCHAR2(100);
10280 l_msg_count NUMBER;
10281 l_msg_data VARCHAR2(500);
10282 l_failed_rsv_temp_tbl INV_RESERVATION_GLOBAL.mtl_failed_rsv_tbl_type;
10283 --
10284 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
10285 --
10286 Begin
10287
10288 IF l_debug_level > 0 THEN
10289 oe_debug_pub.add( '*** INSIDE THE POST_FORMS_COMMIT ***' , 1 ) ;
10290 END IF;
10291
10292 x_return_status := FND_API.G_RET_STS_SUCCESS;
10293
10294 -- Check for Performed Reservation Start
10295 IF OESCH_PERFORMED_RESERVATION = 'Y' THEN
10296
10297 IF l_debug_level > 0 THEN
10298 oe_debug_pub.add( ' BEFORE CALLING THE INV FOR DO_CHECK_FOR_COMMIT' , 1 ) ;
10299 END IF;
10300 INV_RESERVATION_PVT.Do_Check_For_Commit
10301 (p_api_version_number => 1.0
10302 ,p_init_msg_lst => FND_API.G_FALSE
10303 ,x_return_status => l_return_status
10304 ,x_msg_count => l_msg_count
10305 ,x_msg_data => l_msg_data
10306 ,x_failed_rsv_temp_tbl => l_failed_rsv_temp_tbl);
10307
10308 IF l_debug_level > 0 THEN
10309 oe_debug_pub.add( 'AFTER CALLING THE INV FOR DO_CHECK_FOR_COMMIT : ' || L_RETURN_STATUS , 1 ) ;
10310 END IF;
10311
10312 -- We need to find out if the Reservation has failed
10313 IF l_failed_rsv_temp_tbl.count > 0 THEN
10314 IF l_debug_level > 0 THEN
10315 oe_debug_pub.add( ' THE RESERVATION PROCESS HAS FAILED ' , 1 ) ;
10316 END IF;
10317 FND_MESSAGE.SET_NAME('ONT','OE_SCH_RSV_FAILURE');
10318 OE_MSG_PUB.Add;
10319 END IF;
10320
10321 -- Error Handling Start
10322 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10323 IF l_debug_level > 0 THEN
10324 oe_debug_pub.add( 'INSIDE UNEXPECTED ERROR' , 1 ) ;
10325 END IF;
10326 OE_MSG_PUB.Transfer_Msg_Stack;
10327 l_msg_count := OE_MSG_PUB.COUNT_MSG;
10328
10329 FOR I IN 1..l_msg_count LOOP
10330 l_msg_data := OE_MSG_PUB.Get(I,'F');
10331 IF l_debug_level > 0 THEN
10332 oe_debug_pub.add( L_MSG_DATA , 1 ) ;
10333 END IF;
10334 END LOOP;
10335 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10336
10337 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10338 IF l_debug_level > 0 THEN
10339 oe_debug_pub.add( ' INSIDE EXPECTED ERROR' , 1 ) ;
10340 END IF;
10341 OE_MSG_PUB.Transfer_Msg_Stack;
10342 l_msg_count := OE_MSG_PUB.COUNT_MSG;
10343
10344 FOR I IN 1..l_msg_count LOOP
10345 l_msg_data := OE_MSG_PUB.Get(I,'F');
10346 IF l_debug_level > 0 THEN
10347 oe_debug_pub.add( L_MSG_DATA , 1 ) ;
10348 END IF;
10349 END LOOP;
10350 RAISE FND_API.G_EXC_ERROR;
10351
10352 END IF;
10353 --Error Handling End
10354
10355 OESCH_PERFORMED_RESERVATION := 'N';
10356
10357 -- Check for Performed Reservation End
10358 END IF;
10359
10360 -- Get message count and data
10361
10362 oe_msg_pub.count_and_get
10363 ( p_count => x_msg_count
10364 , p_data => x_msg_data
10365 );
10366
10367
10368 IF l_debug_level > 0 THEN
10369 oe_debug_pub.add( '*** BEFORE EXITING POST_FORMS_COMMIT ***' , 1 ) ;
10370 END IF;
10371
10372 EXCEPTION
10373 WHEN FND_API.G_EXC_ERROR THEN
10374 -- OESCH_PERFORMED_RESERVATION := 'N';
10375
10376 x_return_status := FND_API.G_RET_STS_ERROR;
10377
10378 -- Get message count and data
10379
10380 oe_msg_pub.count_and_get
10381 ( p_count => x_msg_count
10382 , p_data => x_msg_data);
10383
10384 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
10385 -- OESCH_PERFORMED_RESERVATION := 'N';
10386 IF OE_MSG_PUB.Check_Msg_Level
10387 (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
10388 THEN
10389 OE_MSG_PUB.Add_Exc_Msg
10390 (G_PKG_NAME , 'Post_Forms_Commit');
10391 END IF;
10392
10393 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
10394
10395 -- Get message count and data
10396
10397 oe_msg_pub.count_and_get
10398 ( p_count => x_msg_count
10399 , p_data => x_msg_data);
10400
10401
10402 END Post_Forms_Commit;
10403
10404
10405 END OE_ORDER_SCH_UTIL;