DBA Data[Home] [Help]

PACKAGE BODY: APPS.OE_OE_FORM_CANCEL_LINE

Source


1 PACKAGE BODY OE_OE_FORM_CANCEL_LINE AS
2 /* $Header: OEXFCANB.pls 120.3.12020000.4 2013/04/10 09:01:40 kadiraju ship $ */
3 
4 
5 --  Start of Comments
6 --  API name    OE_OE_FORM_CANCEL_LINE
7 --  Type        Private
8 --  Function
9 --
10 --  Pre-reqs
11 --
12 --  Parameters
13 --
14 --  Version     Current version = 1.0
15 --              Initial version = 1.0
16 --
17 --  Notes
18 --
19 --  End of Comments
20 g_line_rec                    OE_Order_PUB.Line_Rec_Type;
21 g_db_line_rec                 OE_Order_PUB.Line_Rec_Type;
22 FUNCTION Get_line
23 (   p_db_record                     IN  BOOLEAN := FALSE
24 ,   p_line_id                       IN  NUMBER
25 )
26 RETURN OE_Order_PUB.Line_Rec_Type;
27 
28 Procedure Process_cancel_quantity
29 (    p_num_of_records       IN NUMBER
30     ,p_record_ids           IN OE_GLOBALS.Selected_Record_Tbl -- MOAC
31     ,p_cancel_to_quantity   IN NUMBER
32     ,p_cancellation_comments IN VARCHAR2
33     ,p_reason_code          IN VARCHAR2
34     ,p_cancellation_type    IN VARCHAR2
35     ,p_mc_err_handling_flag IN NUMBER := FND_API.G_MISS_NUM
36 ,x_msg_count OUT NOCOPY NUMBER
37 
38 ,x_msg_data OUT NOCOPY VARCHAR2
39 
40 ,x_return_status OUT NOCOPY VARCHAR2
41 
42 ,x_error_count OUT NOCOPY NUMBER
43 
44 ) IS
45 l_line_rec            OE_ORDER_PUB.line_rec_type;
46 l_control_rec         OE_GLOBALS.Control_Rec_Type;
47 l_line_tbl            OE_ORDER_PUB.Line_Tbl_Type;
48 l_old_line_tbl        OE_ORDER_PUB.Line_Tbl_Type;
49 l_api_name            CONSTANT VARCHAR2(30) := 'Process_Cancel_quantity';
50 l_line_id             NUMBER;
51 l_return_status       VARCHAR2(30);
52 l_error_count         NUMBER :=0;
53 l_ordered_quantity    NUMBER ;
54 l_ordered_quantity2   NUMBER ; /* OPM change. NC - 03/30/01. Bug#1651766 */
55 j                     Integer;
56 initial               Integer;
57 nextpos               Integer;
58 
59 /* B:Included for bug# 2233213 */
60 t_line_id             NUMBER;
61 m                     Integer;
62 initialval            Integer;
63 nextposval            Integer;
64 set_flag              VARCHAR2(1) := 'N';
65 /* E:Included for bug# 2233213 */
66 
67 l_record_ids          OE_GLOBALS.Selected_Record_Tbl := p_record_ids ;
68 l_num_of_records      NUMBER;
69 l_cancel_to_quantity  NUMBER := p_cancel_to_quantity ;
70 l_prg_line_id         NUMBER;
71 
72 cursor prg_parent(c_line_id number)
73 is
74 select opa1.line_id
75 from   oe_price_adjustments opa1,
76        oe_price_adjustments opa2,
77        oe_price_adj_assocs opaa
78 where  opa1.list_line_type_code = 'PRG'
79 and    opa1.price_adjustment_id = opaa.price_adjustment_id
80 and    opa2.price_adjustment_id = opaa.rltd_price_adj_id
81 and    opa2.line_id             = c_line_id;
82 --
83 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
84 l_orgid number;
85 l_skip_process varchar2(1) := 'N';
86 l_header_id number;
87 l_tblcount number := 0;
88 --
89 BEGIN
90 x_return_status := fnd_api.g_ret_sts_success;
91 g_record_ids := l_record_ids;   -- Added For bug#2965878
92   IF l_debug_level  > 0 THEN
93       oe_debug_pub.add(  'ENTER PROCEDURE PROCESS CANCEL QTY' , 1 ) ;
94   END IF;
95   oe_msg_pub.initialize;
96   x_error_count := l_error_count;
97 
98   IF l_debug_level  > 0 THEN
99       oe_debug_pub.add(  ' NO. OF RECORDS: '||TO_CHAR ( P_NUM_OF_RECORDS ) , 1 ) ;
100   END IF;
101 
102  /* Not needed with MOAC
103  j := 1.0;
104   initial := 1.0;
105   nextpos := INSTR(l_record_ids,',',1,j) ;
106  */
107 
108   IF l_debug_level  > 0 THEN
109       oe_debug_pub.add(  'POS'||TO_CHAR ( NEXTPOS ) , 1 ) ;
110   END IF;
111   l_num_of_records := p_num_of_records;
112  g_num_of_records := l_num_of_records;  -- Added For bug#2965878
113 
114   l_line_tbl := OE_ORDER_PUB.G_MISS_LINE_TBL;
115   l_old_line_tbl := OE_ORDER_PUB.G_MISS_LINE_TBL;
116 
117   SAVEPOINT Process_cancel_quantity;
118 
119    	IF l_orgid is null  THEN
120 		l_orgid := l_record_ids(1).Org_Id;
121 
122   IF l_debug_level  > 0 THEN
123 oe_debug_pub.add(  ' ORG ID: '||TO_CHAR ( l_orgid ) , 1 ) ;
124   END IF;
125 
126  Mo_Global.Set_Policy_Context (p_access_mode => 'S',
127                                p_org_id      => l_record_ids(1).Org_Id);
128 
129 	END IF;
130 
131   FOR i IN 1..l_num_of_records LOOP
132 
133     --OE_DEBUG_PUB.Add('Number Of records'||to_char(l_num_of_records),1);
134     --dbms_output.put_line('ini='||to_char(initial)||'next='||to_char(nextpos));
135 
136     --Start of bug# 16249970. Following outer if l_record_ids(i).id3 IS NOT NULL, is added because header_id will be present in id3 only when the cancel operation was
137     --performed from Order Organiser/Quick Order Organiser form. So, modified the inner statements to use id3 instead of id2. On the other hand, if the cancellation is
138     --done from LINE block of Sales Order form / Quick Sales order form, id3 will have NULL value and we can directly insert the selected records into l_line_tbl to call
139     --PO API thereafter to cancel them.
140     IF  l_record_ids(i).id3 IS NOT NULL THEN
141 		if l_header_id is null then
142 			l_header_id := l_record_ids(i).id3;
143 		elsif l_header_id <> l_record_ids(i).id3 THEN
144 			IF l_line_tbl.count <> 0 THEN
145   IF l_debug_level  > 0 THEN
146 oe_debug_pub.add(  ' Header ID: '||TO_CHAR ( l_header_id ) , 1 ) ;
147   END IF;
148 
149 			Call_Process_Order (p_line_tbl => l_line_tbl,
150 				p_old_line_tbl => l_old_line_tbl,
151 			    x_return_status => l_return_status);
152 
153 			END IF;
154 
155     		IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
156       			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
157     		ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
158       			RAISE FND_API.G_EXC_ERROR;
159     		END IF;
160 				l_header_id := l_record_ids(i).id3;
161 				l_line_tbl.delete;
162 				l_tblcount := 0;
163 				l_old_line_tbl.delete;
164 		end if; -- end if l header id
165     END IF;  -- END IF l_record_ids(i).id3  End of bug# 16249970
166 
167    	IF l_record_ids(i).org_id <> l_orgid THEN
168 		l_orgid := l_record_ids(i).Org_Id;
169   IF l_debug_level  > 0 THEN
170 oe_debug_pub.add(  ' ORG ID Change: '||TO_CHAR ( l_orgid ) , 1 ) ;
171   END IF;
172 
173  Mo_Global.Set_Policy_Context (p_access_mode => 'S',
174                                p_org_id      => l_record_ids(i).Org_Id);
175 
176 	END IF;
177 
178 	l_line_id := l_record_ids(i).id1;
179     IF l_debug_level  > 0 THEN
180         oe_debug_pub.add(  'LINE ID: '||TO_CHAR ( L_LINE_ID ) , 1 ) ;
181     END IF;
182 
183 /* Not needed with MOAC changes
184     initial := nextpos + 1.0;
185     j := j + 1.0;
186     nextpos := INSTR(l_record_ids,',',1,j) ;
187 */
188 
189     OE_LINE_UTIL.Lock_Row
190     (   p_line_id       => l_line_id,
191 	p_x_line_rec    => l_line_rec,
192 	x_return_status => l_return_status
193     );
194 
195     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
196       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
197     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
198       RAISE FND_API.G_EXC_ERROR;
199     END IF;
200 
201     IF l_line_rec.split_action_code = FND_API.G_MISS_CHAR THEN
202       IF l_debug_level  > 0 THEN
203           oe_debug_pub.add(  'SPLIT ACTION CODE MISSING' , 1 ) ;
204       END IF;
205     ELSIF l_line_rec.split_action_code IS NULL THEN
206       IF l_debug_level  > 0 THEN
207           oe_debug_pub.add(  'SPLIT ACTION CODE NULL' , 1 ) ;
208       END IF;
209     ELSE
210       IF l_debug_level  > 0 THEN
211           oe_debug_pub.add(  'SPLIT ACTION CODE '||L_LINE_REC.SPLIT_ACTION_CODE , 1 ) ;
212       END IF;
213     END IF;
214 
215     IF l_debug_level  > 0 THEN
216         oe_debug_pub.add(  'LINE CATEGORY: '||L_LINE_REC.LINE_CATEGORY_CODE , 1 ) ;
217     END IF;
218 
219     l_ordered_quantity := l_line_rec.ordered_quantity;
220     /* OPM change. NC - 03/30/01. Bug#1651766 */
221     l_ordered_quantity2 := l_line_rec.ordered_quantity2;
222 
223     if (l_ordered_quantity = 0 or l_line_rec.cancelled_flag = 'Y') then
224       fnd_message.set_name('ONT', 'OE_CANCEL_NOTHING');
225       oe_msg_pub.add;
226       RAISE FND_API.G_EXC_ERROR ;
227     end if;
228 
229                      IF l_debug_level  > 0 THEN
230                          oe_debug_pub.add(  'LINE ID '||TO_CHAR ( L_LINE_REC.LINE_ID ) || ' , ORD QTY '||TO_CHAR ( L_LINE_REC.ORDERED_QUANTITY ) || ' , CANCEL TYPE '|| P_CANCELLATION_TYPE , 1 ) ;
231                      END IF;
232 
233     /* Begin:Included for bug# 2233213 */
234     IF l_line_rec.item_type_code = OE_Globals.G_ITEM_SERVICE AND
235        l_line_rec.service_reference_type_code = 'ORDER' THEN
236 
237      /* Not needed with MOAC changes  m := 1.0;
238       initialval := 1.0;
239       nextposval := INSTR(l_record_ids,',',1,m) ; */
240       set_flag := 'N';
241 
242       for n in 1..l_num_of_records loop
243         t_line_id := l_record_ids(n).id1;
244 /* Not needed with MOAC changes
245         initialval := nextposval + 1.0;
246         m := m + 1.0;
247         nextposval := INSTR(l_record_ids,',',1,m) ;
248 */
249 
250         if l_line_rec.service_reference_line_id = t_line_id then
251           set_flag := 'Y';
252           exit;
253         end if;
254       end loop;
255 
256       IF set_flag = 'Y' THEN
257         IF l_debug_level  > 0 THEN
258             oe_debug_pub.add(  'SKIP , PARENT OF THIS SERVICE LINE IS SELECTED FOR CANCELLATION' ) ;
259         END IF;
260         goto  end_loop;
261       END IF;
262     END IF;
263     /* End:Included for bug# 2233213 */
264 
265     /* Fix for bug # 2387919 */
266     set_flag := 'N';
267     for prg_parent_rec in prg_parent(l_line_rec.line_id) loop
268       IF set_flag = 'Y' THEN
269         exit;
270       end if;
271 
272  /* Not required for MOAC
273      m := 1.0;
274       initialval := 1.0;
275       nextposval := INSTR(l_record_ids,',',1,m) ; */
276 
277       for n in 1..l_num_of_records loop
278         t_line_id := l_record_ids(n).id1;
279 /* Not required with MOAC changes
280         initialval:= nextposval + 1.0;
281         m := m + 1.0;
282         nextposval := INSTR(l_record_ids,',',1,m) ;
283 */
284 
285         if prg_parent_rec.line_id = t_line_id then
286           set_flag := 'Y';
287           exit;
288         end if;
289       end loop;
290     end loop;
291 
292     IF set_flag = 'Y' THEN
293       IF l_debug_level  > 0 THEN
294           oe_debug_pub.add(  'SKIP , THIS IS A PROMOTIONAL LINE' ) ;
295       END IF;
296       goto  end_loop;
297     END IF;
298 
299     --l_line_tbl(1) := OE_ORDER_PUB.G_MISS_LINE_REC;
300 		IF l_tblcount = 0 THEN
301 			l_tblcount := 1;
302 		END IF;
303     l_line_tbl(l_tblcount) := l_line_rec;
304     -- l_old_line_tbl(l_tblcount) := l_line_rec;
305     -- l_line_tbl(1).line_id := l_line_id;
306     l_old_line_tbl(l_tblcount) := l_line_rec;
307     l_line_tbl(l_tblcount).operation := OE_GLOBALS.G_OPR_UPDATE;
308     l_ordered_quantity := 0;
309     l_line_tbl(l_tblcount).ordered_quantity :=l_ordered_quantity;
310 
311     /* OPM change. NC - 03/30/01. Bug#1651766 */
312     IF(l_ordered_quantity2 IS NOT NULL AND l_ordered_quantity2 <> 0 ) THEN
313       l_ordered_quantity2 := 0;
314       l_line_tbl(1).ordered_quantity2 := l_ordered_quantity2;
315     END IF;
316     /* End OPM change */
317 
318     l_line_tbl(l_tblcount).change_reason :=p_reason_code;
319     l_line_tbl(l_tblcount).change_comments :=p_cancellation_comments;
320 	l_tblcount := l_tblcount + 1;
321 
322     /* Included for bug# 2233213 */
323     <<end_loop>>
324     null;
325 
326   END LOOP;
327 
328   --  Call OE_Order_PVT.Process_order for last set of rows
329 
330   IF l_debug_level  > 0 THEN
331       oe_debug_pub.add(  'BEFORE CALLING PROCESSS ORDER LINES PROCEDURE' , 1 ) ;
332   END IF;
333 
334 
335 			IF l_line_tbl.count <> 0 THEN
336 
337 			Call_Process_Order (p_line_tbl => l_line_tbl,
338 				p_old_line_tbl => l_old_line_tbl,
339 			    x_return_status => l_return_status);
340 
341 			END IF;
342 
343   IF l_debug_level  > 0 THEN
344       oe_debug_pub.add(  'AFTER CALLING LINES PROCEDURE' , 1 ) ;
345   END IF;
346 
347   IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
348     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
349   ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
350     RAISE FND_API.G_EXC_ERROR;
351   END IF;
352 
353   IF l_debug_level  > 0 THEN
354       oe_debug_pub.add(  'AFTER CALLING PROCESSE for last set' , 1 ) ;
355   END IF;
356 
357   OE_MSG_PUB.Count_And_Get
358             ( p_count => x_msg_count,
359               p_data  => x_msg_data
360             );
361 
362   x_return_status  := l_return_status;
363 
364   IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
365     IF l_debug_level  > 0 THEN
366         oe_debug_pub.add(  'INTO CANCELATION UNEXPECTED FAILURE' ) ;
367     END IF;
368     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
369   ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
370     IF l_debug_level  > 0 THEN
371         oe_debug_pub.add(  'INTO CANCELLATION EXPECTED FAILURE' ) ;
372     END IF;
373     RAISE FND_API.G_EXC_ERROR;
374   END IF;
375 
376   IF l_debug_level  > 0 THEN
377       oe_debug_pub.add(  L_RETURN_STATUS ) ;
378   END IF;
379 
380 EXCEPTION  /* Procedure exception handler */
381 
382  WHEN FND_API.G_EXC_ERROR THEN
383         x_return_status := FND_API.G_RET_STS_ERROR ;
384         OE_MSG_PUB.Count_And_Get
385             ( p_count => x_msg_count,
386               p_data  => x_msg_data
387             );
388        ROLLBACK TO SAVEPOINT Process_cancel_quantity;
389 
390  WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
391         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
392         OE_MSG_PUB.Count_And_Get
393             ( p_count => x_msg_count,
394               p_data  => x_msg_data
395             );
396 	ROLLBACK TO SAVEPOINT Process_cancel_quantity;
397 
398  WHEN OTHERS THEN
399         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
400         IF OE_MSG_PUB.Check_Msg_Level
401             (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
402         THEN
403              OE_MSG_PUB.Add_Exc_Msg
404                     (G_PKG_NAME,
405                      l_api_name
406                 );
407         END IF;
408         OE_MSG_PUB.Count_And_Get
409             ( p_count => x_msg_count,
410               p_data  => x_msg_data);
411        ROLLBACK TO SAVEPOINT Process_cancel_quantity;
412 
413 end Process_cancel_quantity;
414 
415 Procedure Process_cancel_order
416 (    p_num_of_records       IN NUMBER
417     ,p_record_ids           IN OE_GLOBALS.Selected_Record_Tbl -- MOAC
418     ,p_cancellation_comments IN VARCHAR2
419     ,p_reason_code          IN VARCHAR2
420     ,p_mc_err_handling_flag IN NUMBER := FND_API.G_MISS_NUM
421 ,x_msg_count OUT NOCOPY NUMBER
422 
423 ,x_msg_data OUT NOCOPY VARCHAR2
424 
425 ,x_return_status OUT NOCOPY VARCHAR2
426 
427 ,x_error_count OUT NOCOPY NUMBER
428 
429 ) IS
430 l_header_rec                OE_ORDER_PUB.Header_Rec_Type;
431 l_line_rec                OE_ORDER_PUB.line_rec_type;
432 l_old_header_rec            OE_ORDER_PUB.Header_Rec_Type;
433 l_control_rec               OE_GLOBALS.Control_Rec_Type;
434 l_api_name         CONSTANT VARCHAR2(30)         := 'Process_Cancel_Order';
435 l_header_id         Number;
436 l_return_status             VARCHAR2(30);
437 l_error_count   NUMBER :=0;
438 l_ordered_quantity NUMBER ;
439 j Integer;
440 initial Integer;
441 nextpos Integer;
442 l_record_ids  OE_GLOBALS.Selected_Record_Tbl := p_record_ids ;
443 l_num_of_records number;
444 --
445 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
446 l_orgid number;
447 --
448 BEGIN
449 	oe_msg_pub.initialize;
450      IF l_debug_level  > 0 THEN
451          oe_debug_pub.add(  'PROCEDURE PROCESS_CANCEL_ORDER' , 1 ) ;
452      END IF;
453  l_header_rec := OE_ORDER_PUB.G_MISS_HEADER_REC;
454  l_old_header_rec := OE_ORDER_PUB.G_MISS_HEADER_REC;
455  l_header_rec.operation := OE_GLOBALS.G_OPR_NONE;   --OE.G_OPR_UPDATE;
456  x_error_count := l_error_count;
457  g_ord_lvl_can := TRUE; --Fix for bug# 2922468.
458   IF l_debug_level  > 0 THEN
459       oe_debug_pub.add(  'No of IDS'||TO_CHAR ( P_NUM_OF_RECORDS ) , 1 ) ;
460   END IF;
461 /* Not required with MOAC changes
462          j := 1.0;
463          initial := 1.0;
464          nextpos := INSTR(l_record_ids,',',1,j) ;
465 */
466 
467 l_num_of_records := p_num_of_records;
468 
469 
470 FOR i IN 1..l_num_of_records LOOP
471  SAVEPOINT Process_cancel_order;
472 
473 
474  l_header_rec := OE_ORDER_PUB.G_MISS_HEADER_REC;
475  l_old_header_rec := OE_ORDER_PUB.G_MISS_HEADER_REC;
476    	IF l_orgid is null OR l_record_ids(i).org_id <> l_orgid THEN
477 		l_orgid := l_record_ids(i).Org_Id;
478 
479  Mo_Global.Set_Policy_Context (p_access_mode => 'S',
480                                p_org_id      => l_record_ids(i).Org_Id);
481 
482 	END IF;
483 
484  l_header_id := l_record_ids(i).id1;
485 IF l_debug_level  > 0 THEN
486     oe_debug_pub.add(  'INSTR'||TO_CHAR ( L_HEADER_ID ) , 1 ) ;
487 END IF;
488 /* not required with MOAC changes
489  initial := nextpos + 1.0;
490  j := j + 1.0;
491  nextpos := INSTR(l_record_ids,',',1,j) ;
492 */
493 
494  OE_Header_Util.lock_Row
495         (   p_header_id                   => l_header_id,
496 		  p_x_header_rec                  => l_header_rec
497 		   ,x_return_status => l_return_status
498         );
499     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
500         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
501     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
502         RAISE FND_API.G_EXC_ERROR;
503     END IF;
504 
505 l_old_header_rec := l_header_rec;
506 IF l_debug_level  > 0 THEN
507     oe_debug_pub.add(  'CANCELLED FLAG'||L_HEADER_REC.CANCELLED_FLAG , 1 ) ;
508 END IF;
509 IF l_header_rec.cancelled_flag = 'Y' THEN
510 IF l_debug_level  > 0 THEN
511     oe_debug_pub.add(  'CANCELLED FLAG'||L_HEADER_REC.CANCELLED_FLAG , 1 ) ;
512 END IF;
513                 fnd_message.set_name('ONT', 'OE_CAN_ORDER_CANCEL_ALREADY');
514                  FND_MESSAGE.SET_TOKEN('ORDER',
515                                    L_header_rec.Order_Number);
516 
517 
518                 oe_msg_pub.Add;
519           	RAISE FND_API.G_EXC_ERROR ;
520 END IF;
521 IF nvl(l_header_rec.open_flag,'N') = 'N' THEN
522 IF l_debug_level  > 0 THEN
523     oe_debug_pub.add(  'CANCELLED FLAG'||L_HEADER_REC.CANCELLED_FLAG , 1 ) ;
524 END IF;
525                 fnd_message.set_name('ONT', 'OE_CAN_ORDER_CLOSED');
526                  FND_MESSAGE.SET_TOKEN('ORDER',
527                                    L_header_rec.Order_Number);
528                 oe_msg_pub.Add;
529           	RAISE FND_API.G_EXC_ERROR ;
530 END IF;
531 
532   l_header_rec.cancelled_flag :='Y';
533   l_header_rec.change_reason :=p_reason_code;
534  l_header_rec.change_comments :=p_cancellation_comments;
535  l_header_rec.operation := OE_GLOBALS.G_OPR_UPDATE;
536 
537 	oe_order_pvt.Header
538 (   p_validation_level               =>    FND_API.G_VALID_LEVEL_NONE
539 ,   p_control_rec                   => l_control_rec
540 ,   p_x_header_rec                    =>  l_header_rec
541 ,   p_x_old_header_rec                => l_old_header_rec
542 ,   x_return_status     => l_return_status
543 
544 );
545 
546         OE_MSG_PUB.Count_And_Get
547             ( p_count => x_msg_count,
548               p_data  => x_msg_data
549             );
550 
551 
552 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
553         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
554     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
555         RAISE FND_API.G_EXC_ERROR;
556  END IF;
557 
558 
559 -- Api to call notify OC and Process Delayed Requests
560 
561      OE_Order_PVT.Process_Requests_And_Notify
562           ( p_process_requests          => TRUE
563           , p_notify                    => TRUE
564           , x_return_status             => l_return_status
565           , p_header_rec                => l_header_rec
566           , p_old_header_rec            => l_old_header_rec
567           );
568 --16594370 start
569         OE_MSG_PUB.Count_And_Get
570             ( p_count => x_msg_count,
571               p_data  => x_msg_data
572             );
573 --16594370 end
574 
575 
576 
577 x_return_status  := l_return_status;
578      IF l_debug_level  > 0 THEN
579          oe_debug_pub.add(  L_RETURN_STATUS ) ;
580      END IF;
581        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
582                IF l_debug_level  > 0 THEN
583                    oe_debug_pub.add(  'CANCELLATION UNEXPECTED FAILURE' ) ;
584                END IF;
585                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
586        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
587                IF l_debug_level  > 0 THEN
588                    oe_debug_pub.add(  'CANCELLATION EXPECTED FAILURE' ) ;
589                END IF;
590                  RAISE FND_API.G_EXC_ERROR;
591        END IF;
592 
593 
594 End LOOP; /* end of FOR loop */
595 
596 g_ord_lvl_can := FALSE; --For fix bug# 2922468.
597 
598 EXCEPTION  /* Procedure exception handler */
599 
600  WHEN FND_API.G_EXC_ERROR THEN
601         x_return_status := FND_API.G_RET_STS_ERROR ;
602         OE_MSG_PUB.Count_And_Get
603             ( p_count => x_msg_count,
604               p_data  => x_msg_data
605             );
606        g_ord_lvl_can := FALSE; --For fix bug# 2922468.
607        ROLLBACK TO SAVEPOINT Process_cancel_order;
608 
609  WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
610         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
611         OE_MSG_PUB.Count_And_Get
612             ( p_count => x_msg_count,
613               p_data  => x_msg_data
614             );
615 g_ord_lvl_can:=FALSE; --Fix for bug# 2922468.
616 ROLLBACK TO SAVEPOINT Process_cancel_order;
617 
618  WHEN OTHERS THEN
619         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
620         IF OE_MSG_PUB.Check_Msg_Level
621             (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
622         THEN
623              OE_MSG_PUB.Add_Exc_Msg
624                     (G_PKG_NAME,
625                      l_api_name
626                 );
627         END IF;
628         OE_MSG_PUB.Count_And_Get
629             ( p_count => x_msg_count,
630               p_data  => x_msg_data);
631        g_ord_lvl_can := FALSE; --Fix for bug# 2922468.
632        ROLLBACK TO SAVEPOINT Process_cancel_order;
633 
634 
635 end Process_cancel_order;
636 
637 
638 
639 FUNCTION Get_line
640 (   p_db_record                     IN  BOOLEAN := FALSE
641 ,   p_line_id                       IN  NUMBER
642 )
643 RETURN OE_Order_PUB.Line_Rec_Type
644 IS
645 --
646 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
647 --
648 BEGIN
649 
650     IF l_debug_level  > 0 THEN
651         oe_debug_pub.add(  'ENTERING OE_OE_FORM_CANCEL_LINE.GET_LINE' , 1 ) ;
652     END IF;
653 
654     IF  p_line_id <> g_line_rec.line_id
655     THEN
656 
657         --  Query row from DB
658 
659          OE_Line_Util.Query_Row
660         (   p_line_id                     => p_line_id,
661 		  x_line_rec                    => g_line_rec
662         );
663         g_line_rec.db_flag             := FND_API.G_TRUE;
664 
665         --  Load DB record
666 
667 
668         g_db_line_rec                  := g_line_rec;
669 
670     END IF;
671 
672     IF l_debug_level  > 0 THEN
673         oe_debug_pub.add(  'EXITING OE_OE_FORM_LINE.GET_LINE' , 1 ) ;
674     END IF;
675 
676     IF p_db_record THEN
677 
678         RETURN g_db_line_rec;
679 
680     ELSE
681 
682         RETURN g_line_rec;
683 
684     END IF;
685 
686 END Get_Line;
687 
688 -- Fix for bug 2259556.This procedure is now coded to take care of mass order cancellation.
689 Procedure Cancel_Remaining_Order(p_num_of_records IN NUMBER,
690                   p_record_ids IN OE_GLOBALS.Selected_Record_Tbl, --MOAC
691 x_return_status OUT NOCOPY VARCHAR2,
692 
693                     p_cancellation_comments IN VARCHAR2,
694                     p_reason_code          IN VARCHAR2,
695 x_msg_count OUT NOCOPY NUMBER,
696 
697 x_msg_data OUT NOCOPY VARCHAR2)IS
698 
699 l_header_rec OE_ORDER_PUB.header_rec_type :=
700 		oe_order_pub.g_miss_header_rec;
701 l_api_name varchar2(30) := 'Cancel Remaining Order';
702 l_header_id         Number;
703 j Integer;
704 initial Integer;
705 nextpos Integer;
706 l_record_ids  OE_GLOBALS.Selected_Record_Tbl := p_record_ids ;
707 l_num_of_records number;
708 
709 --
710 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
711 --
712 
713 l_orgid number;
714 BEGIN
715          l_header_rec.operation := OE_GLOBALS.G_OPR_NONE;
716 IF l_debug_level  > 0 THEN
717     oe_debug_pub.add(  'num of IDS '||TO_CHAR ( P_NUM_OF_RECORDS ) , 1 ) ;
718 END IF;
719 /* Not required with MOAC changes
720          j := 1.0;
721          initial := 1.0;
722          nextpos := INSTR(l_record_ids,',',1,j) ;
723 */
724          l_num_of_records := p_num_of_records;
725 FOR i IN 1..l_num_of_records LOOP
726         SAVEPOINT Cancel_Remaining_Order;
727  l_header_rec := OE_ORDER_PUB.G_MISS_HEADER_REC;
728    	IF l_orgid is null OR l_record_ids(i).org_id <> l_orgid THEN
729 		l_orgid := l_record_ids(i).Org_Id;
730 
731  Mo_Global.Set_Policy_Context (p_access_mode => 'S',
732                                p_org_id      => l_record_ids(i).Org_Id);
733 
734 	END IF;
735 
736  l_header_id := l_record_ids(i).id1;
737  IF l_debug_level  > 0 THEN
738      oe_debug_pub.add(  'INSTR'||TO_CHAR ( L_HEADER_ID ) , 1 ) ;
739  END IF;
740 
741 /* Not required with MOAC changes
742  initial := nextpos + 1.0;
743  j := j + 1.0;
744  nextpos := INSTR(l_record_ids,',',1,j) ;
745 */
746 
747          OE_Header_Util.Query_Row
748         (   p_header_id                   => l_header_id,
749             x_header_rec                  =>l_header_rec
750         );
751 
752 		 l_header_rec.change_reason := p_reason_code;
753 		l_header_rec.change_comments := p_cancellation_comments;
754 
755 oe_sales_can_util.Cancel_Remaining_Order
756     (p_header_rec        => l_header_rec,
757      p_header_id         => l_header_id
758 ,   x_return_status      => x_return_status
759 );
760 
761        IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
762                IF l_debug_level  > 0 THEN
763                    oe_debug_pub.add(  'INTO CANCELATION UNEXPECTED FAILURE' ) ;
764                END IF;
765                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
766        ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
767                IF l_debug_level  > 0 THEN
768                    oe_debug_pub.add(  'INTO CANCELLATION EXPECTED FAILURE' ) ;
769                END IF;
770         OE_MSG_PUB.Count_And_Get
771             ( p_count => x_msg_count,
772               p_data  => x_msg_data
773             );
774 
775          /* Fix Bug # 3000720: If there is an error, everything must rollback */
776          RAISE FND_API.G_EXC_ERROR;
777        END IF;
778 
779 END LOOP;
780 
781 EXCEPTION  /* Procedure exception handler */
782 
783 WHEN FND_API.G_EXC_ERROR THEN
784         x_return_status := FND_API.G_RET_STS_ERROR ;
785         OE_MSG_PUB.Count_And_Get
786             ( p_count => x_msg_count,
787               p_data  => x_msg_data
788             );
789         ROLLBACK TO SAVEPOINT Cancel_Remaining_Order;
790  WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
791         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
792         OE_MSG_PUB.Count_And_Get
793             ( p_count => x_msg_count,
794               p_data  => x_msg_data
795             );
796  WHEN OTHERS THEN
797         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
798         IF OE_MSG_PUB.Check_Msg_Level
799             (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
800         THEN
801              OE_MSG_PUB.Add_Exc_Msg
802                     (G_PKG_NAME,
803                      l_api_name
804                 );
805         END IF;
806         OE_MSG_PUB.Count_And_Get
807             ( p_count => x_msg_count,
808               p_data  => x_msg_data);
809        ROLLBACK TO SAVEPOINT Cancel_Remaining_Order;
810 
811 END cancel_remaining_order;
812 
813 Procedure Call_Process_Order ( p_line_tbl IN OE_ORDER_PUB.LINE_TBL_TYPE,
814 			       p_old_line_tbl IN OE_ORDER_PUB.LINE_TBL_TYPE,
815 				x_return_status  OUT NOCOPY VARCHAR2)
816 IS
817 
818 l_line_tbl OE_ORDER_PUB.LINE_TBL_TYPE := p_line_tbl;
819 l_old_line_tbl OE_ORDER_PUB.LINE_TBL_TYPE := p_old_line_tbl;
820 x_msg_count number;
821 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
822 x_msg_data varchar2(32000);
823 l_control_rec         OE_GLOBALS.Control_Rec_Type;
824 l_api_name            CONSTANT VARCHAR2(30) := 'Call_Process_Order';
825 BEGIN
826 
827   IF l_debug_level  > 0 THEN
828       oe_debug_pub.add(  'BEFORE CALLING PROCESSS ORDER LINES PROCEDURE' , 1 ) ;
829   END IF;
830 
831 		x_return_status := FND_API.G_RET_STS_SUCCESS;
832 
833 
834   --  Call OE_Order_PVT.Process_order
835   IF l_debug_level  > 0 THEN
836       oe_debug_pub.add(  'CALLING PROCESS ORDER' , 1 ) ;
837   END IF;
838       oe_order_pvt.Lines
839   (   p_validation_level  =>    FND_API.G_VALID_LEVEL_NONE
840   ,   p_control_rec       => l_control_rec
841   ,   p_x_line_tbl         =>  l_line_tbl
842   ,   p_x_old_line_tbl    =>  l_old_line_tbl
843   ,   x_return_status     => x_return_status
844   );
845 
846   IF l_debug_level  > 0 THEN
847       oe_debug_pub.add(  'AFTER CALLING LINES PROCEDURE' , 1 ) ;
848   END IF;
849 
850   IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
851     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
852   ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
853     RAISE FND_API.G_EXC_ERROR;
854   END IF;
855 
856   OE_Order_PVT.Process_Requests_And_Notify
857           ( p_process_requests          => TRUE
858           , p_notify                    => TRUE
859           , x_return_status             => x_return_status
860           , p_line_tbl                  => l_line_tbl
861           , p_old_line_tbl             => l_old_line_tbl
862           );
863   IF l_debug_level  > 0 THEN
864       oe_debug_pub.add(  'AFTER CALLING PROCESSE' , 1 ) ;
865   END IF;
866 
867   OE_MSG_PUB.Count_And_Get
868             ( p_count => x_msg_count,
869               p_data  => x_msg_data
870             );
871 
872   x_return_status  := x_return_status;
873 
874   IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
875     IF l_debug_level  > 0 THEN
876         oe_debug_pub.add(  'INTO CANCELATION UNEXPECTED FAILURE' ) ;
877     END IF;
878     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
879   ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
880     IF l_debug_level  > 0 THEN
881         oe_debug_pub.add(  'INTO CANCELLATION EXPECTED FAILURE' ) ;
882     END IF;
883     RAISE FND_API.G_EXC_ERROR;
884   END IF;
885 
886   IF l_debug_level  > 0 THEN
887       oe_debug_pub.add(  x_RETURN_STATUS ) ;
888   END IF;
889 
890 EXCEPTION  /* Procedure exception handler */
891 
892  WHEN FND_API.G_EXC_ERROR THEN
893         x_return_status := FND_API.G_RET_STS_ERROR ;
894         OE_MSG_PUB.Count_And_Get
895             ( p_count => x_msg_count,
896               p_data  => x_msg_data
897             );
898 
899  WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
900         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
901         OE_MSG_PUB.Count_And_Get
902             ( p_count => x_msg_count,
903               p_data  => x_msg_data
904             );
905  WHEN OTHERS THEN
906         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
907         IF OE_MSG_PUB.Check_Msg_Level
908             (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
909         THEN
910              OE_MSG_PUB.Add_Exc_Msg
911                     (G_PKG_NAME,
912                      l_api_name
913                 );
914         END IF;
915         OE_MSG_PUB.Count_And_Get
916             ( p_count => x_msg_count,
917               p_data  => x_msg_data);
918 
919 END Call_Process_Order;
920 
921 END OE_OE_FORM_CANCEL_LINE;