DBA Data[Home] [Help]

PACKAGE BODY: APPS.OE_ORDER_PVT

Source


1 PACKAGE BODY OE_Order_PVT AS
2 /* $Header: OEXVORDB.pls 120.14 2007/12/24 05:07:59 snimmaga ship $ */
3 
4 --  Global constant holding the package name
5 
6 G_PKG_NAME                    CONSTANT VARCHAR2(30) := 'OE_Order_PVT';
7 g_header_id                   NUMBER;
8 g_upgraded_flag		     VARCHAR2(1);
9 g_booked_flag                 VARCHAR2(1);
10 
11 --  Header
12 
13 -- Global Flags for setting Recursion
14 po_ctr number := 0;
15 hdr_ctr number := 0;
16 hdr_adj_ctr number := 0;
17 hdr_scredit_ctr number := 0;
18 line_ctr number := 0;
19 line_adj_ctr number := 0;
20 line_scredit_ctr number := 0;
21 prn_ctr number := 0;
22 pr_ctr number := 0;
23 prrt_ctr number := 0;
24 poa_ctr number := 0;
25 
26 -- Set recursion Mode
27 
28 -- SAM
29 TYPE OE_OPTION_INDEX_TBL_TYPE IS TABLE OF NUMBER
30 INDEX BY BINARY_INTEGER;
31 
32 Procedure Set_Recursion_Mode (p_Entity_Code number,
33                               p_In_Out number := 1)
34 IS
35 --
36 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
37 --
38 Begin
39         IF l_debug_level  > 0 THEN
40             oe_debug_pub.add(  'ENTER SET RECURSION MODE' , 1 ) ;
41             oe_debug_pub.add(  'ENTITY CODE-'||P_ENTITY_CODE , 1 ) ;
42             oe_debug_pub.add(  'ENTRY-EXIT MODE -'||P_IN_OUT , 1 ) ;
43     oe_debug_pub.add(  'RECURSION MODE AT ENTRY -' || OE_GLOBALS.G_RECURSION_MODE , 1 ) ;
44 		     oe_debug_pub.add(  'RECURSION MODE WITHOUT EXP AT ENTRY -' || OE_ORDER_UTIL.G_RECURSION_WITHOUT_EXCEPTION , 1 ) ;
45         END IF;
46 
47           IF p_entity_code = 1 THEN
48                         IF p_In_Out = 1 THEN
49                                 po_ctr := po_ctr + 1;
50                         ELSIF p_In_Out = 0 THEN
51                                 po_ctr := po_ctr - 1;
52                         END IF;
53                          IF (line_ctr > 0 OR
54                           Hdr_ctr > 0 OR
55                           Hdr_adj_ctr > 0 OR
56                           Hdr_scredit_ctr > 0 OR
57                           line_adj_ctr > 0 OR
58                           line_scredit_ctr > 0 OR
59                           prn_ctr > 0 OR
60                                 pr_ctr > 0 ) THEN
61 				--prrt_ctr > 0  ) THEN
62                          oe_globals.g_recursion_mode := 'Y';
63                            OE_ORDER_UTIL.G_Recursion_Without_Exception := 'Y';
64                     ELSE
65                          oe_globals.g_recursion_mode := 'N';
66                          OE_ORDER_UTIL.G_Recursion_Without_Exception := 'N';
67                     END IF;
68 
69 /* This is added to control notification call to just one call out. */
70 			IF po_ctr > 1 THEN
71 		OE_ORDER_UTIL.G_Recursion_Without_Exception := 'Y';
72 			ELSE
73 		OE_ORDER_UTIL.G_Recursion_Without_Exception := 'N';
74 			END IF;
75 
76                NULL;
77           ELSIF p_entity_code = 2 THEN
78 
79                       IF p_In_Out = 1 THEN
80                                 hdr_ctr := hdr_ctr + 1;
81                         ELSIF p_In_Out = 0 THEN
82                                 hdr_ctr := hdr_ctr - 1;
83                         END IF;
84                     IF hdr_ctr > 1 THEN
85                          oe_globals.g_recursion_mode := 'Y';
86                          OE_ORDER_UTIL.G_Recursion_Without_Exception := 'Y';
87                     ELSE
88                          OE_ORDER_UTIL.G_Recursion_Without_Exception := 'N';
89                          null; /* SAM */
90                     END IF;
91 
92 
93                NULL;
94           ELSIF p_entity_code = 3 THEN
95                       IF p_In_Out = 1 THEN
96                                 hdr_adj_ctr := hdr_adj_ctr + 1;
97                         ELSIF p_In_Out = 0 THEN
98                                 hdr_adj_ctr := hdr_adj_ctr - 1;
99                         END IF;
100                     IF hdr_adj_ctr > 1 THEN
101                          oe_globals.g_recursion_mode := 'Y';
102                       OE_ORDER_UTIL.G_Recursion_Without_Exception := 'Y';
103                     ELSE
104                          oe_globals.g_recursion_mode := 'N';
105                        OE_ORDER_UTIL.G_Recursion_Without_Exception := 'N';
106                     END IF;
107 
108                NULL;
109 
110           ELSIF p_entity_code = 4 THEN
111 
112                         IF p_In_Out = 1 THEN
113                                 hdr_scredit_ctr := hdr_scredit_ctr + 1;
114                         ELSIF p_In_Out = 0 THEN
115                                 hdr_scredit_ctr := hdr_scredit_ctr - 1;
116                         END IF;
117                     IF hdr_scredit_ctr > 1 THEN
118                          oe_globals.g_recursion_mode := 'Y';
119                        OE_ORDER_UTIL.G_Recursion_Without_Exception := 'Y';
120                     ELSE
121                          oe_globals.g_recursion_mode := 'N';
122                         OE_ORDER_UTIL.G_Recursion_Without_Exception := 'N';
123                     END IF;
124 
125                NULL;
126           ELSIF p_entity_code = 5 THEN
127                       IF p_In_Out = 1 THEN
128                                 line_ctr := line_ctr + 1;
129                         ELSIF p_In_Out = 0 THEN
130                                 line_ctr := line_ctr - 1;
131                         END IF;
132                     IF line_ctr > 1 THEN
133                          oe_globals.g_recursion_mode := 'Y';
134                      OE_ORDER_UTIL.G_Recursion_Without_Exception := 'Y';
135                     ELSE
136                          oe_globals.g_recursion_mode := 'N';
137                        OE_ORDER_UTIL.G_Recursion_Without_Exception := 'N';
138                     END IF;
139 
140                NULL;
141           ELSIF p_entity_code = 6 THEN
142                      IF p_In_Out = 1 THEN
143                                 line_adj_ctr := line_adj_ctr + 1;
144                         ELSIF p_In_Out = 0 THEN
145                                 line_adj_ctr := line_adj_ctr - 1;
146                         END IF;
147                     IF line_adj_ctr > 1 THEN
148                          oe_globals.g_recursion_mode := 'Y';
149                       OE_ORDER_UTIL.G_Recursion_Without_Exception := 'Y';
150                     ELSE
151                          oe_globals.g_recursion_mode := 'N';
152                        OE_ORDER_UTIL.G_Recursion_Without_Exception := 'N';
153                     END IF;
154 
155                NULL;
156           ELSIF p_entity_code = 7 THEN
157                       IF p_In_Out = 1 THEN
158                                 line_scredit_ctr := line_scredit_ctr + 1;
159                         ELSIF p_In_Out = 0 THEN
160                                 line_scredit_ctr := line_scredit_ctr - 1;
161                       END IF;
162                     IF line_scredit_ctr > 1 THEN
163                          oe_globals.g_recursion_mode := 'Y';
164                      OE_ORDER_UTIL.G_Recursion_Without_Exception := 'Y';
165                     ELSE
166                          oe_globals.g_recursion_mode := 'N';
167                      OE_ORDER_UTIL.G_Recursion_Without_Exception := 'N';
168                     END IF;
169 
170                NULL;
171           ELSIF p_entity_code = 8 THEN
172                       IF p_In_Out = 1 THEN
173                                 prn_ctr := prn_ctr + 1;
174                         ELSIF p_In_Out = 0 THEN
175                                 prn_ctr := prn_ctr - 1;
176                       END IF;
177 
178                    /* IF (prn_ctr > 1 AND
179                                 pr_ctr >  0) THEN
180                          oe_globals.g_recursion_mode := 'Y';*/
181                     IF prn_ctr > 0 AND
182                          (line_ctr > 0 OR
183                           Hdr_ctr > 0 OR
184                           Hdr_adj_ctr > 0 OR
185                           Hdr_scredit_ctr > 0 OR
186                           line_adj_ctr > 0 OR
187                           line_scredit_ctr > 0 OR
188                           po_ctr > 1 OR
189 			  --prrt_ctr > 0 OR
190                                 pr_ctr > 0  ) THEN
191                          oe_globals.g_recursion_mode := 'Y';
192 		    ELSIF prn_ctr > 1 THEN
193 			oe_globals.g_recursion_mode := 'Y';
194 		    ELSIF
195 			 prn_ctr = 0 AND
196                          (line_ctr > 1 OR
197                           Hdr_ctr > 1 OR
198                           Hdr_adj_ctr > 1 OR
199                           Hdr_scredit_ctr > 1 OR
200                           line_adj_ctr > 1 OR
201                           line_scredit_ctr > 1 OR
202                           po_ctr > 1 OR
203                                 pr_ctr > 1  ) THEN
204 			oe_globals.g_recursion_mode := 'Y';
205 
206                     ELSE
207                          oe_globals.g_recursion_mode := 'N';
208                      END IF;
209 
210                    IF prn_ctr > 0 AND
211                          (line_ctr > 0 OR
212                           Hdr_ctr > 0 OR
213                           Hdr_adj_ctr > 0 OR
214                           Hdr_scredit_ctr > 0 OR
215                           line_adj_ctr > 0 OR
216                           line_scredit_ctr > 0 OR
217                           po_ctr > 1 OR
218                                 pr_ctr > 0 OR
219 				--prrt_ctr > 0 OR
220 			poa_ctr > 0  ) THEN
221 
222 			OE_ORDER_UTIL.G_Recursion_Without_Exception := 'Y';
223 		   ELSIF  prn_ctr > 1 THEN
224 			OE_ORDER_UTIL.G_Recursion_Without_Exception := 'Y';
225                     ELSE
226 			OE_ORDER_UTIL.G_Recursion_Without_Exception := 'N';
227 
228                     END IF;
229 
230 
231                         NULL;
232           ELSIF p_entity_code = 9 THEN
233                       IF p_In_Out = 1 THEN
234                                 pr_ctr := pr_ctr + 1;
235                         ELSIF p_In_Out = 0 THEN
236                                 pr_ctr := pr_ctr - 1;
237                         END IF;
238                     IF pr_ctr > 1 THEN
239                          oe_globals.g_recursion_mode := 'Y';
240                       OE_ORDER_UTIL.G_Recursion_Without_Exception := 'Y';
241                     ELSE
242                          oe_globals.g_recursion_mode := 'N';
243                        OE_ORDER_UTIL.G_Recursion_Without_Exception := 'N';
244                     END IF;
245                         NULL;
246 
247            ELSIF p_entity_code = 10 THEN
248                       IF p_In_Out = 1 THEN
249                                 poa_ctr := poa_ctr + 1;
250                         ELSIF p_In_Out = 0 THEN
251                                 poa_ctr := poa_ctr - 1;
252                         END IF;
253                     IF poa_ctr > 1 THEN
254 			OE_ORDER_UTIL.G_Recursion_Without_Exception := 'Y';
255                     ELSE
256 			OE_ORDER_UTIL.G_Recursion_Without_Exception := 'N';
257 
258                     END IF;
259                         NULL;
260 		ELSIF p_entity_code = 11 THEN
261                       IF p_In_Out = 1 THEN
262                                 prrt_ctr := prrt_ctr + 1;
263                         ELSIF p_In_Out = 0 THEN
264                                 prrt_ctr := prrt_ctr - 1;
265                         END IF;
266 -- We stopped tracking recursion in request type since it was causing issues
267 -- around executing configuration related requests and update shipping.
268 -- Pricing is now going by ui flag to set the process as false while
269 -- executing request for req type in validate and write.
270 
271                     /*IF prrt_ctr > 1 THEN
272                          oe_globals.g_recursion_mode := 'Y';
273                       OE_ORDER_UTIL.G_Recursion_Without_Exception := 'Y';
274                     ELSE
275                          oe_globals.g_recursion_mode := 'N';
276                        OE_ORDER_UTIL.G_Recursion_Without_Exception := 'N';
277                     END IF; */
278                         NULL;
279 
280 
281           ELSE
282                          oe_globals.g_recursion_mode := 'N';
283                    OE_ORDER_UTIL.G_Recursion_Without_Exception := 'N';
284                NULL;
285           END IF;
286 IF l_debug_level  > 0 THEN
287     oe_debug_pub.add(  'RECURSION MODE AT EXIT -' || OE_GLOBALS.G_RECURSION_MODE , 1 ) ;
288     oe_debug_pub.add(  'RECURSION MODE WITHOUT EXP AT EXIT -' || OE_ORDER_UTIL.G_RECURSION_WITHOUT_EXCEPTION , 1 ) ;
289 END IF;
290 End Set_Recursion_Mode ;
291 
292 
293 /*---------------------------------------------------------------------
294  Forward Declarations related to configurations.
295 ----------------------------------------------------------------------*/
296 PROCEDURE Print_Time(p_msg   IN  VARCHAR2);
297 
298 
299 -- ##1828866 added p_process_partial.
300 PROCEDURE Complete_Config_line
301 ( p_x_line_rec       IN OUT NOCOPY OE_ORDER_PUB.Line_Rec_Type
302  ,p_item_type        IN     NUMBER
303  ,p_x_line_tbl       IN     OE_ORDER_PUB.Line_Tbl_Type
304  ,p_process_partial  IN     BOOLEAN := FALSE);
305 
306 PROCEDURE Get_Missing_Class_Lines
307 ( p_x_line_tbl         IN  OUT NOCOPY OE_ORDER_PUB.Line_Tbl_Type
308  ,p_options_index_tbl  IN  OE_OPTION_INDEX_TBL_TYPE
309 ,x_class_index OUT NOCOPY NUMBER
310 
311 ,x_class_count OUT NOCOPY NUMBER);
312 
313 
314 
315 /*-------------------------------------------------------------------
316 FUNCTION Valid_Upgraded_Order
317 
318 --------------------------------------------------------------------*/
319 FUNCTION Valid_Upgraded_Order(p_header_id Number)
320 RETURN Boolean
321 IS
322 --
323 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
324 --
325 BEGIN
326 
327   IF l_debug_level  > 0 THEN
328       oe_debug_pub.add(  'ENTER VALID UPGRADED ORDER' ) ;
329   END IF;
330   IF (NOT OE_GLOBALS.EQUAL(p_header_id, g_header_id)) OR
331 -- aksingh perf removing OR part of below condition as not required
332 -- (g_header_id IS  NULL OR g_upgraded_flag IS NULL)
333    (g_header_id IS  NULL)
334   THEN
335     select UPGRADED_FLAG, booked_flag into
336     g_upgraded_flag, g_booked_flag
337     from oe_order_headers_all
338     where header_id = p_header_id;
339     g_header_id := p_header_id;
340   END IF;
341 
342   IF g_upgraded_flag IN ('P','I') THEN
343     IF l_debug_level  > 0 THEN
344         oe_debug_pub.add(  'ORDER PARTIALLY UPGRADED ' ) ;
345     END IF;
346     FND_MESSAGE.SET_NAME('ONT','OE_INVALID_UPG_ORDER');
347     OE_MSG_PUB.Add;
348     RETURN FALSE;
349   END IF;
350 
351   IF l_debug_level  > 0 THEN
352       oe_debug_pub.add(  'EXIT VALID UPGRADED ORDER ' ) ;
353   END IF;
354   RETURN TRUE;
355 
356 EXCEPTION
357 
358   WHEN NO_DATA_FOUND THEN
359 
360     RETURN TRUE;
361 
362 END Valid_Upgraded_Order;
363 
364 
365 /*----------------------------------------------------------------------
366 PROCEDURE Header
367 -----------------------------------------------------------------------*/
368 
369 PROCEDURE Header
370 (   p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
371 ,   p_validation_level              IN  NUMBER
372 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
373 ,   p_x_header_rec                  IN OUT NOCOPY  OE_Order_PUB.Header_Rec_Type
374 ,   p_x_old_header_rec              IN OUT NOCOPY  OE_Order_PUB.Header_Rec_Type
375 , x_return_status OUT NOCOPY VARCHAR2
376 
377 )
378 IS
379 l_return_status               VARCHAR2(1);
380 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
381 l_user_id                      NUMBER;
382 l_resp_id                      NUMBER;
383 l_application_id               NUMBER;
384 l_hdr_process_name             VARCHAR2(30);
385 -- local variables to store OUT parameters from security check procedures
386 l_sec_result            NUMBER;
387 l_on_operation_action   NUMBER;
388 x_msg_count		NUMBER;
389 x_msg_data		VARCHAR2(2000);
390 --
391 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
392 l_org_id    number ;
393 --
394 BEGIN
395     --Moac changes start
396     l_org_id := MO_GLOBAL.get_current_org_id;
397     IF (l_org_id IS NULL OR l_org_id = FND_API.G_MISS_NUM) THEN
398        FND_MESSAGE.set_name('FND','MO_ORG_REQUIRED');
399        OE_MSG_PUB.Add;
400        RAISE FND_API.G_EXC_ERROR;
401      END IF;
402     --Moac changes end
403     --  Initialize message list.
404     set_recursion_mode(p_Entity_Code => 2,
405                        p_In_out  => 1);
406 
407     IF FND_API.to_Boolean(p_init_msg_list) THEN
408         OE_MSG_PUB.initialize;
409     END IF;
410 
411     x_return_status := FND_API.G_RET_STS_SUCCESS;
412 
413     IF l_debug_level  > 0 THEN
414         oe_debug_pub.add(  'ENTERING OE_ORDER_PVT.HEADER' , 1 ) ;
415     END IF;
416 
417     -- This is to check if the order is an upgraded order and is upgraded
418     -- correctly
419     IF p_x_header_rec.operation <> OE_GLOBALS.G_OPR_CREATE THEN
420 
421         IF l_debug_level  > 0 THEN
422             oe_debug_pub.add(  'BEFORE CALLING VALID UPGRADE ORDER' , 2 ) ;
423         END IF;
424 	   IF NOT Valid_Upgraded_Order(p_x_header_rec.header_id ) THEN
425                  RAISE FND_API.G_EXC_ERROR;
426         END IF;
427 
428     END IF;
429 
430     IF p_x_old_header_rec.header_id = FND_API.G_MISS_NUM
431 	  OR p_x_old_header_rec.header_id IS NULL
432     THEN
433 
434       OE_MSG_PUB.set_msg_context(
435 	 p_entity_code			=> 'HEADER'
436   	,p_entity_id         		=> p_x_header_rec.header_id
437     	,p_header_id         		=> p_x_header_rec.header_id
438     	,p_line_id           		=> null
439     	,p_orig_sys_document_ref	=> p_x_header_rec.orig_sys_document_ref
440     	,p_orig_sys_document_line_ref	=> null
441         ,p_change_sequence              => p_x_header_rec.change_sequence
442     	,p_source_document_id		=> p_x_header_rec.source_document_id
443     	,p_source_document_line_id	=> null
444 	,p_order_source_id            => p_x_header_rec.order_source_id
445 	,p_source_document_type_id    => p_x_header_rec.source_document_type_id);
446 
447     ELSE
448 
449       OE_MSG_PUB.set_msg_context(
450 	 p_entity_code			=> 'HEADER'
451   	,p_entity_id         		=> p_x_old_header_rec.header_id
452     	,p_header_id         		=> p_x_old_header_rec.header_id
453     	,p_line_id           		=> null
454     	,p_orig_sys_document_ref	=> p_x_old_header_rec.orig_sys_document_ref
455     	,p_orig_sys_document_line_ref	=> null
456         ,p_change_sequence              => p_x_header_rec.change_sequence
457     	,p_source_document_id		=> p_x_old_header_rec.source_document_id
458     	,p_source_document_line_id	=> null
459 	,p_order_source_id            => p_x_old_header_rec.order_source_id
460 	,p_source_document_type_id    => p_x_old_header_rec.source_document_type_id);
461 
462     END IF;
463 
464 
465     --  Load API control record
466 
467     l_control_rec := OE_GLOBALS.Init_Control_Rec
468     (   p_operation     => p_x_header_rec.operation
469     ,   p_control_rec   => p_control_rec
470     );
471 
472    IF l_debug_level  > 0 THEN
473        oe_debug_pub.add(  'OE_ORDER_PVT.HEADER AFTER INIT CONTROL REC' , 2 ) ;
474    END IF;
475 
476     --  Set record return status.
477 
478     p_x_header_rec.return_status     := FND_API.G_RET_STS_SUCCESS;
479 
480     --  Prepare record.
481 
482     IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
483 
484     	IF l_debug_level  > 0 THEN
485     	    oe_debug_pub.add(  'OPERATION = CREATE SO SET OLD TO NULL' , 2 ) ;
486     	END IF;
487         p_x_header_rec.db_flag := FND_API.G_FALSE;
488 
489         --  Set missing old record elements to NULL.
490 
491         OE_Header_Util.Convert_Miss_To_Null (p_x_old_header_rec);
492 
493     ELSIF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
494     OR    p_x_header_rec.operation = OE_GLOBALS.G_OPR_DELETE
495     THEN
496 
497     	IF l_debug_level  > 0 THEN
498     	    oe_debug_pub.add(  'OPERATION = UPDATE SO QUERY OLD' , 2 ) ;
499     	END IF;
500 
501         p_x_header_rec.db_flag := FND_API.G_TRUE;
502 
503         --  Query Old if missing
504 
505         IF  p_x_old_header_rec.header_id = FND_API.G_MISS_NUM
506 		  OR p_x_old_header_rec.header_id IS NULL
507         THEN
508 		  IF l_debug_level  > 0 THEN
509 		      oe_debug_pub.add(  'QUERYING OLD HEADER REC' ) ;
510 		  END IF;
511 
512             OE_Header_Util.Query_Row
513             (   p_header_id                   => p_x_header_rec.header_id
514 		  ,   x_header_rec                  => p_x_old_header_rec
515             );
516 
517         ELSE
518 
519             --  Set missing old record elements to NULL.
520 
521            OE_Header_Util.Convert_Miss_To_Null (p_x_old_header_rec);
522 
523         END IF;
524 
525        IF l_debug_level  > 0 THEN
526            oe_debug_pub.add(  'CALLING COMPLETE RECORD' , 2 ) ;
527        END IF;
528 
529         --  Complete new record from old
530 
531         OE_Header_Util.Complete_Record
532         (   p_x_header_rec                => p_x_header_rec
533         ,   p_old_header_rec              => p_x_old_header_rec
534         );
535 
536 	OE_MSG_PUB.update_msg_context(
537 	   p_entity_code		=> 'HEADER'
538   	  ,p_entity_id         		=> p_x_header_rec.header_id
539     	  ,p_header_id         		=> p_x_header_rec.header_id
540     	  ,p_line_id           		=> null
541           ,p_order_source_id            => p_x_header_rec.order_source_id
542     	  ,p_orig_sys_document_ref	=> p_x_header_rec.orig_sys_document_ref
543     	  ,p_orig_sys_document_line_ref	=> null
544     	  ,p_source_document_id		=> p_x_header_rec.source_document_id
545     	  ,p_source_document_line_id	=> null );
546 
547     END IF;
548 
549   IF ( p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE
550     OR p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
551     OR p_x_header_rec.operation = OE_GLOBALS.G_OPR_DELETE)  THEN
552 
553 
554    -- Check security
555    IF l_control_rec.check_security
556     AND (p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE
557          OR p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE)
558    THEN
559 
560         IF l_debug_level  > 0 THEN
561             oe_debug_pub.add(  'CHECK ATTRIBUTES SECURITY' ) ;
562         END IF;
563         -- check if this operation is allowed
564         -- on all the changed attributes
565            OE_Header_Security.Attributes
566                 (p_header_rec   	=> p_x_header_rec
567                 , p_old_header_rec	=> p_x_old_header_rec
568                 , x_result      	=> l_sec_result
569                 , x_return_status 	=> l_return_status
570                 );
571 
572             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
573                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
574             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
575                 RAISE FND_API.G_EXC_ERROR;
576             END IF;
577 
578            IF l_sec_result = OE_PC_GLOBALS.YES THEN
579                 RAISE FND_API.G_EXC_ERROR;
580            END IF;
581 
582     END IF;
583 
584     --  Attribute level validation.
585 
586         IF p_validation_level > FND_API.G_VALID_LEVEL_NONE THEN
587 
588         IF l_debug_level  > 0 THEN
589             oe_debug_pub.add(  'VALIDATE ATTRIBUTES' , 2 ) ;
590         END IF;
591 
592             OE_Validate_Header.Attributes
593             (   x_return_status               => l_return_status
594             ,   p_x_header_rec                => p_x_header_rec
595             ,   p_old_header_rec              => p_x_old_header_rec
596             ,   p_validation_level	      => p_validation_level
597             );
598 
599 	    IF p_validation_level <> OE_GLOBALS.G_VALID_LEVEL_PARTIAL THEN
600             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
601                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
602             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
603                 RAISE FND_API.G_EXC_ERROR;
604             END IF;
605 	    END IF;
606         END IF;
607 
608 
609         --  Clear dependent attributes.
610 
611     IF  l_control_rec.clear_dependents THEN
612 
613         IF l_debug_level  > 0 THEN
614             oe_debug_pub.add(  'CLEAR DEPENDENT' , 2 ) ;
615         END IF;
616 
617         OE_Header_Util.Clear_Dependent_Attr
618         (   p_x_header_rec                => p_x_header_rec
619         ,   p_old_header_rec              => p_x_old_header_rec
620         );
621 
622     END IF;
623 
624     --  Default missing attributes
625 
626     IF  l_control_rec.default_attributes
627     THEN
628 
629     	IF l_debug_level  > 0 THEN
630     	    oe_debug_pub.add(  'DEFAULT MISSING' , 2 ) ;
631     	END IF;
632 
633         OE_Default_Header.Attributes
634         (   p_x_header_rec                => p_x_header_rec
635         ,   p_old_header_rec              => p_x_old_header_rec
636         );
637 
638     END IF;
639 
640     IF l_debug_level  > 0 THEN
641         oe_debug_pub.add(  'AFTER DEFAULT MISSING' , 2 ) ;
642     END IF;
643 
644     --  Apply attribute changes
645 
646     IF  l_control_rec.change_attributes
647     THEN
648 
649     	IF l_debug_level  > 0 THEN
650     	    oe_debug_pub.add(  'APPLY ATTRIBUTE CHANGES' , 2 ) ;
651     	END IF;
652 
653         OE_Header_Util.Apply_Attribute_Changes
654         (   p_x_header_rec                => p_x_header_rec
655         ,   p_old_header_rec              => p_x_old_header_rec
656         );
657 
658     END IF;
659 
660     --  Entity level validation.
661 
662     IF l_control_rec.validate_entity
663     and p_x_header_rec.cancelled_flag<>'Y'  --added for bug 6494347
664     THEN
665 
666         IF l_debug_level  > 0 THEN
667             oe_debug_pub.add(  'VALIDATE ENTITY' , 2 ) ;
668         END IF;
669 
670         IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
671 
672             OE_Validate_Header.Entity_Delete
673             (   x_return_status               => l_return_status
674             ,   p_header_rec                  => p_x_header_rec
675             );
676 
677         ELSE
678 
679             OE_Validate_Header.Entity
680             (   x_return_status               => l_return_status
681             ,   p_header_rec                  => p_x_header_rec
682             ,   p_old_header_rec              => p_x_old_header_rec
683             ,   p_validation_level            => p_validation_level
684 /* Added the above line to fix the bug 2824240 */
685             );
686 
687         END IF;
688 
689         IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
690             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
691         ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
692             RAISE FND_API.G_EXC_ERROR;
693         END IF;
694 
695     END IF;
696 
697 
698     -- Check entity level security again as some attributes
699     -- may have changed due to defaulting.
700     -- For UPDATE operations, entity security checks for constraints setup
701     -- with a NULL column i.e. the constraint restricts update on ANY of
702     -- the columns.
703     -- However, this check should NOT be done if user did not try to update
704     -- any of the constrainable attributes and also none of the defaulted
705     -- attributes was constrainable!. In such a case, the g_check_all_cols
706     -- _constraint flag would still be 'Y' as the flag is reset only
707     -- when checking for constraints.
708     IF NOT (p_x_header_rec.operation  = OE_GLOBALS.G_OPR_UPDATE
709                AND OE_Header_Security.g_check_all_cols_constraint = 'Y')
710        AND l_control_rec.check_security
711     THEN
712         IF l_debug_level  > 0 THEN
713             oe_debug_pub.add(  'CHECK ENTITY SECURITY' ) ;
714         END IF;
715 
716            OE_Header_Security.Entity
717                 (p_header_rec   	=> p_x_header_rec
718                 , x_result      	=> l_sec_result
719                 , x_return_status 	=> l_return_status
720                 );
721 
722             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
723                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
724             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
725                 RAISE FND_API.G_EXC_ERROR;
726             END IF;
727 
728            IF l_sec_result = OE_PC_GLOBALS.YES THEN
729                 RAISE FND_API.G_EXC_ERROR;
730            END IF;
731 
732     END IF;
733 
734     --  Step 4. Write to DB
735     IF l_control_rec.write_to_db THEN
736 		Oe_Header_Util.Pre_Write_Process(p_x_header_rec => p_x_header_rec,
737 						p_old_header_rec => p_x_old_header_rec);
738     END IF;
739 
740     IF l_control_rec.write_to_db THEN
741 
742     	IF l_debug_level  > 0 THEN
743     	    oe_debug_pub.add(  'WRITE TO DB' , 2 ) ;
744     	END IF;
745 
746         IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
747 
748             OE_Header_Util.Delete_Row
749             (   p_header_id                   => p_x_header_rec.header_id
750             );
751 
752         ELSE
753 
754             --  Get Who Information
755 
756             p_x_header_rec.last_update_date  := SYSDATE;
757             p_x_header_rec.last_updated_by   := NVL(OE_STANDARD_WF.g_user_id, FND_GLOBAL.USER_ID); -- 3169637
758             p_x_header_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
759 
760             IF p_x_header_rec.credit_card_approval_date = FND_API.G_MISS_DATE THEN
761 			p_x_header_rec.credit_card_approval_date := NULL;
762             END IF;
763 
764             IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
765 
766 			IF l_debug_level  > 0 THEN
767 			    oe_debug_pub.add(  'HEADER FLOW STATUS :'||P_X_HEADER_REC.FLOW_STATUS_CODE , 1 ) ;
768 			END IF;
769                 OE_Header_Util.Update_Row (p_x_header_rec);
770 
771             ELSIF p_x_header_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
772 
773                 p_x_header_rec.creation_date     := SYSDATE;
774                 p_x_header_rec.created_by        := NVL(OE_STANDARD_WF.g_user_id, FND_GLOBAL.USER_ID); -- 3169637
775 
776                 l_user_id := NVL(OE_STANDARD_WF.g_user_id, FND_GLOBAL.USER_ID); -- 3169637
777                 l_resp_id := FND_GLOBAL.RESP_ID;
778                 l_application_id := FND_GLOBAL.RESP_APPL_ID;
779 
780 		IF l_debug_level  > 0 THEN
781 		    oe_debug_pub.add(  'USER ID IS '|| L_USER_ID ) ;
782                     oe_debug_pub.add(  'RESP ID IS '|| L_RESP_ID ) ;
783                     oe_debug_pub.add(  'APPL ID IS '|| L_APPLICATION_ID ) ;
784                 END IF;
785 
786 
787                 OE_Header_Util.Insert_Row (p_x_header_rec);
788 
789             END IF;
790 
791         END IF;
792 
793     END IF;
794 
795     --  Step 4. Write to DB
796     IF l_control_rec.write_to_db THEN
797 		OE_Header_Util.Post_Write_Process
798 		  ( p_x_header_rec    => p_x_header_rec,
799 		    p_old_header_rec  => p_x_old_header_rec
800 		   );
801     END IF;
802 
803   END IF;
804 
805     --  Load OUT parameters
806     p_x_header_rec.return_status     := FND_API.G_RET_STS_SUCCESS;
807 
808     OE_Header_Security.g_check_all_cols_constraint := 'Y';
809 
810     IF l_debug_level  > 0 THEN
811         oe_debug_pub.add(  'EXITING OE_ORDER_PVT.HEADER' , 1 ) ;
812     END IF;
813     OE_MSG_PUB.reset_msg_context('HEADER');
814 
815     set_recursion_mode(p_Entity_Code => 2,
816                        p_In_out  => 0);
817 
818 EXCEPTION
819 
820     WHEN FND_API.G_EXC_ERROR THEN
821 
822         set_recursion_mode(p_Entity_Code => 2,
823                            p_In_out  => 0);
824         p_x_header_rec.return_status     := FND_API.G_RET_STS_ERROR;
825 	   x_return_status 				 := FND_API.G_RET_STS_ERROR;
826         OE_Header_Security.g_check_all_cols_constraint := 'Y';
827         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
828           IF l_debug_level  > 0 THEN
829               oe_debug_pub.add(  'DELETE REQUEST1' , 2 ) ;
830           END IF;
831           OE_Delayed_Requests_Pvt.Clear_Request
832                     (x_return_status => l_return_status);
833         END IF;
834         OE_MSG_PUB.reset_msg_context('HEADER');
835 
836     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
837 
838         set_recursion_mode(p_Entity_Code => 2,
839                                    p_In_out  => 0);
840         p_x_header_rec.return_status     := FND_API.G_RET_STS_UNEXP_ERROR;
841 	   x_return_status 				 := FND_API.G_RET_STS_UNEXP_ERROR;
842         OE_Header_Security.g_check_all_cols_constraint := 'Y';
843         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
844           IF l_debug_level  > 0 THEN
845               oe_debug_pub.add(  'DELETE REQUEST2' , 2 ) ;
846           END IF;
847           OE_Delayed_Requests_Pvt.Clear_Request
848                     (x_return_status => l_return_status);
849         END IF;
850         OE_MSG_PUB.reset_msg_context('HEADER');
851 
852     WHEN OTHERS THEN
853 
854         set_recursion_mode(p_Entity_Code => 2,
855                                    p_In_out  => 0);
856         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
857         THEN
858             OE_MSG_PUB.Add_Exc_Msg
859             (   G_PKG_NAME
860             ,   'Header'
861             );
862         END IF;
863 
864         p_x_header_rec.return_status     := FND_API.G_RET_STS_UNEXP_ERROR;
865 	   x_return_status 				 := FND_API.G_RET_STS_UNEXP_ERROR;
866         OE_Header_Security.g_check_all_cols_constraint := 'Y';
867         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
868           IF l_debug_level  > 0 THEN
869               oe_debug_pub.add(  'DELETE REQUEST3' , 2 ) ;
870           END IF;
871           OE_Delayed_Requests_Pvt.Clear_Request
872                     (x_return_status => l_return_status);
873         END IF;
874         OE_MSG_PUB.reset_msg_context('HEADER');
875 
876 END Header;
877 
878 
879 
880 /*-------------------------------------------------------------------
881 PROCEDURE  Header_Scredits
882 -------------------------------------------------------------------*/
883 PROCEDURE Header_Scredits
884 (   p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
885 ,   p_validation_level              IN  NUMBER
886 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
887 ,   p_x_Header_Scredit_tbl          IN OUT NOCOPY  OE_Order_PUB.Header_Scredit_Tbl_Type
888 ,   p_x_old_Header_Scredit_tbl      IN OUT NOCOPY  OE_Order_PUB.Header_Scredit_Tbl_Type
889 , x_return_status OUT NOCOPY VARCHAR2
890 
891 )
892 IS
893 l_del_ret_status              VARCHAR2(1);
894 l_return_status               VARCHAR2(1);
895 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
896 l_Header_Scredit_rec          OE_Order_PUB.Header_Scredit_Rec_Type;
897 l_old_Header_Scredit_rec      OE_Order_PUB.Header_Scredit_Rec_Type;
898 -- local variables to store OUT parameters from security check procedures
899 l_sec_result            NUMBER;
900 l_on_operation_action   NUMBER;
901   l_order_source_id           NUMBER;
902   l_orig_sys_document_ref     VARCHAR2(50);
903   l_change_sequence           VARCHAR2(50);
904   l_source_document_type_id   NUMBER;
905   l_source_document_id        NUMBER;
906 
907 I 				    NUMBER; -- Used as index for while loop
908 --bug 5049879
909 l_booked_flag                 VARCHAR2(1);
910 l_quota_flag                  VARCHAR2(1);
911 --bug 5049879
912 --
913 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
914 l_org_id number ;
915 --
916 BEGIN
917 
918     --MOAC changes start
919       l_org_id := MO_GLOBAL.get_current_org_id;
920       IF (l_org_id IS NULL OR l_org_id = FND_API.G_MISS_NUM) THEN
921          FND_MESSAGE.set_name('FND','MO_ORG_REQUIRED');
922          OE_MSG_PUB.Add;
923          RAISE FND_API.G_EXC_ERROR;
924       END IF;
925     --MOAC changes end
926 
927     set_recursion_mode(p_Entity_Code => 4,
928                                    p_In_out  => 1);
929     x_return_status := FND_API.G_RET_STS_SUCCESS;
930 
931     --  Initialize message list.
932 
933     IF FND_API.to_Boolean(p_init_msg_list) THEN
934         OE_MSG_PUB.initialize;
935     END IF;
936 
937     IF p_control_rec.Process_Partial THEN
938         SAVEPOINT Header_Scredits;
939     END IF;
940 
941     --  Init local table variables.
942 
943     IF l_debug_level  > 0 THEN
944         oe_debug_pub.add(  'ENTERING OE_ORDER_PVT.HEADER_SCREDITS' , 1 ) ;
945     END IF;
946 
947 --    FOR I IN 1..p_x_Header_Scredit_tbl.COUNT LOOP
948 
949     I := p_x_Header_Scredit_tbl.FIRST;
950 
951     WHILE I IS NOT NULL LOOP
952     BEGIN
953 
954         --  Load local records.
955 
956         l_Header_Scredit_rec := p_x_Header_Scredit_tbl(I);
957 
958         IF p_x_old_Header_Scredit_tbl.EXISTS(I) THEN
959             l_old_Header_Scredit_rec := p_x_old_Header_Scredit_tbl(I);
960         ELSE
961             l_old_Header_Scredit_rec := OE_Order_PUB.G_MISS_HEADER_SCREDIT_REC;
962         END IF;
963 
964       if l_old_header_Scredit_rec.sales_credit_id = FND_API.G_MISS_NUM
965 	    OR l_old_header_Scredit_rec.sales_credit_id IS NULL
966 	 Then
967 
968          IF l_header_Scredit_rec.header_id IS NOT NULL AND
969             l_header_Scredit_rec.header_id <> FND_API.G_MISS_NUM THEN
970             BEGIN
971                IF l_debug_level  > 0 THEN
972                   oe_debug_pub.add('Getting reference data for header_id:'||l_header_Scredit_rec.header_id);
973                END IF;
974                SELECT order_source_id, orig_sys_document_ref, change_sequence,
975                source_document_type_id, source_document_id
976                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
977                l_source_document_type_id, l_source_document_id
978                FROM   OE_ORDER_HEADERS_ALL
979                WHERE  header_id = l_header_Scredit_rec.header_id;
980             EXCEPTION
981                WHEN NO_DATA_FOUND THEN
982                    l_order_source_id := null;
983                    l_orig_sys_document_ref := null;
984                    l_change_sequence := null;
985                    l_source_document_type_id := null;
986                    l_source_document_id := null;
987                WHEN OTHERS THEN
988                    l_order_source_id := null;
989                    l_orig_sys_document_ref := null;
990                    l_change_sequence := null;
991                    l_source_document_type_id := null;
992                    l_source_document_id := null;
993             END;
994          END IF;
995 
996         OE_MSG_PUB.set_msg_context(
997 	 	p_entity_code			=> 'HEADER_SCREDIT'
998   		,p_entity_id         		=> l_header_Scredit_rec.sales_credit_id
999     		,p_header_id         		=> l_header_Scredit_rec.header_Id
1000     		,p_line_id           		=> null
1001                 ,p_order_source_id              => l_order_source_id
1002     		,p_orig_sys_document_ref	=> l_orig_sys_document_ref
1003     		,p_orig_sys_document_line_ref	=> null
1004                 ,p_change_sequence              => l_change_sequence
1005                 ,p_source_document_type_id      => l_source_document_type_id
1006     		,p_source_document_id		=> l_source_document_id
1007     		,p_source_document_line_id	=> null );
1008 
1009      else
1010          IF l_old_header_Scredit_rec.header_id IS NOT NULL AND
1011             l_old_header_Scredit_rec.header_id <> FND_API.G_MISS_NUM THEN
1012 
1013             BEGIN
1014                IF l_debug_level  > 0 THEN
1015                   oe_debug_pub.add('Getting reference data for old header_id:'||l_old_header_Scredit_rec.header_id);
1016                END IF;
1017                SELECT order_source_id, orig_sys_document_ref, change_sequence,
1018                source_document_type_id, source_document_id
1019                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
1020                l_source_document_type_id, l_source_document_id
1021                FROM   OE_ORDER_HEADERS_ALL
1022                WHERE  header_id = l_old_header_Scredit_rec.header_id;
1023             EXCEPTION
1024                WHEN NO_DATA_FOUND THEN
1025                    l_order_source_id := null;
1026                    l_orig_sys_document_ref := null;
1027                    l_change_sequence := null;
1028                    l_source_document_type_id := null;
1029                    l_source_document_id := null;
1030                WHEN OTHERS THEN
1031                    l_order_source_id := null;
1032                    l_orig_sys_document_ref := null;
1033                    l_change_sequence := null;
1034                    l_source_document_type_id := null;
1035                    l_source_document_id := null;
1036             END;
1037          END IF;
1038 
1039 
1040         OE_MSG_PUB.set_msg_context(
1041 	 	p_entity_code			=> 'HEADER_SCREDIT'
1042   		,p_entity_id         		=> l_old_header_Scredit_rec.sales_credit_id
1043     		,p_header_id         		=> l_old_header_Scredit_rec.header_Id
1044     		,p_line_id           		=> null
1045                 ,p_order_source_id              => l_order_source_id
1046                 ,p_orig_sys_document_ref        => l_orig_sys_document_ref
1047                 ,p_orig_sys_document_line_ref   => null
1048                 ,p_change_sequence              => l_change_sequence
1049                 ,p_source_document_type_id      => l_source_document_type_id
1050                 ,p_source_document_id           => l_source_document_id
1051     		,p_source_document_line_id	=> null );
1052 
1053      end if;
1054 
1055         --  Load API control record
1056 
1057         l_control_rec := OE_GLOBALS.Init_Control_Rec
1058         (   p_operation     => l_Header_Scredit_rec.operation
1059         ,   p_control_rec   => p_control_rec
1060         );
1061 
1062         --  Set record return status.
1063 
1064         l_Header_Scredit_rec.return_status := FND_API.G_RET_STS_SUCCESS;
1065 
1066         --  Prepare record.
1067 
1068         IF l_Header_Scredit_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
1069 
1070             l_Header_Scredit_rec.db_flag := FND_API.G_FALSE;
1071 
1072             --  Set missing old record elements to NULL.
1073 
1074             OE_Header_Scredit_Util.Convert_Miss_To_Null (l_old_Header_Scredit_rec);
1075 
1076         ELSIF l_Header_Scredit_rec.operation = OE_GLOBALS.G_OPR_UPDATE
1077         OR    l_Header_Scredit_rec.operation = OE_GLOBALS.G_OPR_DELETE
1078         THEN
1079 
1080             l_Header_Scredit_rec.db_flag := FND_API.G_TRUE;
1081 
1082             --  Query Old if missing
1083 
1084             IF  l_old_Header_Scredit_rec.sales_credit_id = FND_API.G_MISS_NUM
1085 			 OR l_old_Header_Scredit_rec.sales_credit_id IS NULL
1086             THEN
1087 
1088                 OE_Header_Scredit_Util.Query_Row
1089                 (   p_sales_credit_id             => l_Header_Scredit_rec.sales_credit_id
1090 			 ,   x_header_scredit_rec          => l_old_Header_Scredit_rec
1091                 );
1092 
1093             ELSE
1094 
1095                 --  Set missing old record elements to NULL.
1096 
1097                 OE_Header_Scredit_Util.Convert_Miss_To_Null (l_old_Header_Scredit_rec);
1098 
1099             END IF;
1100 
1101             --  Complete new record from old
1102 
1103             OE_Header_Scredit_Util.Complete_Record
1104             (   p_x_Header_Scredit_rec        => l_Header_Scredit_rec
1105             ,   p_old_Header_Scredit_rec      => l_old_Header_Scredit_rec
1106             );
1107 
1108             OE_MSG_PUB.update_msg_context(
1109 	 	p_entity_code			=> 'HEADER_SCREDIT'
1110   		,p_entity_id         		=> l_header_Scredit_rec.sales_credit_id
1111     		,p_header_id         		=> l_header_Scredit_rec.header_Id);
1112 
1113 
1114         END IF;
1115 
1116         IF I = p_x_header_scredit_tbl.FIRST THEN
1117 	       IF NOT Valid_Upgraded_Order(l_header_scredit_rec.header_id) THEN
1118                  RAISE FND_API.G_EXC_ERROR;
1119             END IF;
1120         END IF;
1121 
1122    -- Check security
1123    IF l_control_rec.check_security
1124       AND (l_header_scredit_rec.operation = OE_GLOBALS.G_OPR_CREATE
1125          OR l_header_scredit_rec.operation = OE_GLOBALS.G_OPR_UPDATE)
1126    THEN
1127 
1128         IF l_debug_level  > 0 THEN
1129             oe_debug_pub.add(  'CHECK ATTRIBUTES SECURITY' ) ;
1130         END IF;
1131         -- check if this operation is allowed
1132         -- on all the changed attributes
1133            OE_Header_Scredit_Security.Attributes
1134                 (p_header_scredit_rec  	=> l_header_scredit_rec
1135                 , p_old_header_scredit_rec	=> l_old_header_scredit_rec
1136                 , x_result      	=> l_sec_result
1137                 , x_return_status 	=> l_return_status
1138                 );
1139 
1140             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1141                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1142             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1143                 RAISE FND_API.G_EXC_ERROR;
1144             END IF;
1145 
1146            IF l_sec_result = OE_PC_GLOBALS.YES THEN
1147                 RAISE FND_API.G_EXC_ERROR;
1148            END IF;
1149 
1150     END IF;
1151 
1152         --  Attribute level validation.
1153 
1154             IF p_validation_level > FND_API.G_VALID_LEVEL_NONE THEN
1155 
1156                 OE_Validate_Header_Scredit.Attributes
1157                 (   x_return_status               => l_return_status
1158                 ,   p_Header_Scredit_rec          => l_Header_Scredit_rec
1159                 ,   p_old_Header_Scredit_rec      => l_old_Header_Scredit_rec
1160                 );
1161 
1162                 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1163                     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1164                 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1165                     RAISE FND_API.G_EXC_ERROR;
1166                 END IF;
1167 
1168             END IF;
1169 
1170 
1171             --  Clear dependent attributes.
1172 
1173         IF  l_control_rec.clear_dependents THEN
1174 
1175             OE_Header_Scredit_Util.Clear_Dependent_Attr
1176             (   p_x_Header_Scredit_rec        => l_Header_Scredit_rec
1177             ,   p_old_Header_Scredit_rec      => l_old_Header_Scredit_rec
1178             );
1179 
1180         END IF;
1181 
1182         --  Default missing attributes
1183 
1184         IF  l_control_rec.default_attributes
1185         THEN
1186 
1187             OE_Default_Header_Scredit.Attributes
1188             (   p_x_Header_Scredit_rec        => l_Header_Scredit_rec
1189             ,   p_old_header_scredit_rec      => l_old_header_scredit_rec
1190             );
1191 
1192         END IF;
1193 
1194         --  Apply attribute changes
1195 
1196         IF  l_control_rec.change_attributes
1197         THEN
1198 
1199             OE_Header_Scredit_Util.Apply_Attribute_Changes
1200             (   p_x_Header_Scredit_rec          => l_Header_Scredit_rec
1201             ,   p_old_Header_Scredit_rec      => l_old_Header_Scredit_rec
1202             );
1203 
1204         END IF;
1205 
1206         --  Entity level validation.
1207 
1208         IF l_control_rec.validate_entity THEN
1209 
1210             IF l_Header_Scredit_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
1211 
1212                 OE_Validate_Header_Scredit.Entity_Delete
1213                 (   x_return_status               => l_return_status
1214                 ,   p_Header_Scredit_rec          => l_Header_Scredit_rec
1215                 );
1216 
1217             ELSE
1218 
1219                 OE_Validate_Header_Scredit.Entity
1220                 (   x_return_status               => l_return_status
1221                 ,   p_Header_Scredit_rec          => l_Header_Scredit_rec
1222                 ,   p_old_Header_Scredit_rec      => l_old_Header_Scredit_rec
1223                 );
1224 
1225             END IF;
1226 
1227             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1228                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1229             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1230                 RAISE FND_API.G_EXC_ERROR;
1231             END IF;
1232 
1233         END IF;
1234 
1235     -- Check entity level security again as some attributes
1236     -- may have changed due to defaulting.
1237     -- For UPDATE operations, entity security checks for constraints setup
1238     -- with a NULL column i.e. the constraint restricts update on ANY of
1239     -- the columns.
1240     -- However, this check should NOT be done if user did not try to update
1241     -- any of the constrainable attributes and also none of the defaulted
1242     -- attributes was constrainable!. In such a case, the g_check_all_cols
1243     -- _constraint flag would still be 'Y' as the flag is reset only
1244     -- when checking for constraints.
1245     IF NOT (l_header_scredit_rec.operation  = OE_GLOBALS.G_OPR_UPDATE
1246                AND OE_Header_Scredit_Security.g_check_all_cols_constraint = 'Y')
1247        AND l_control_rec.check_security
1248     THEN
1249         IF l_debug_level  > 0 THEN
1250             oe_debug_pub.add(  'CHECK ENTITY SECURITY' ) ;
1251         END IF;
1252 
1253            OE_Header_Scredit_Security.Entity
1254                 (p_header_scredit_rec   	=> l_header_scredit_rec
1255                 , x_result      	=> l_sec_result
1256                 , x_return_status 	=> l_return_status
1257                 );
1258 
1259             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1260                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1261             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1262                 RAISE FND_API.G_EXC_ERROR;
1263             END IF;
1264 
1265            IF l_sec_result = OE_PC_GLOBALS.YES THEN
1266                 RAISE FND_API.G_EXC_ERROR;
1267            END IF;
1268 
1269     END IF;
1270 
1271         --  Step 4. Write to DB
1272 
1273         IF l_control_rec.write_to_db THEN
1274 		 /* Start Audit Trail */
1275       	 Oe_Header_Scredit_Util.Pre_Write_Process
1276 		   (p_x_header_scredit_rec => l_header_scredit_rec,
1277 		    p_old_header_scredit_rec => l_old_header_scredit_rec);
1278            /* End AuditTrail */
1279 
1280             IF l_Header_Scredit_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
1281                SAVEPOINT DELETE_SCREDIT_FAILED; --bug 5331854
1282    --bug 5049879
1283                 select quota_flag into l_quota_flag from oe_sales_credit_types where sales_credit_type_id = l_header_scredit_rec.sales_credit_type_id;
1284                 select booked_flag into l_booked_flag from oe_order_headers where header_id = l_header_scredit_rec.header_id;
1285                 OE_Header_Scredit_Util.Delete_Row
1286                 (   p_sales_credit_id             => l_Header_Scredit_rec.sales_credit_id
1287                 );
1288 
1289                 IF nvl(l_booked_flag, 'N') = 'Y' and nvl(l_quota_flag, 'N') = 'Y' THEN
1290                    OE_Validate_Header_Scredit.Validate_HSC_TOTAL_FOR_BK(l_header_scredit_rec.return_status,
1291                                                                     l_header_scredit_rec.header_id);
1292                    IF l_debug_level > 0 THEN
1293                       oe_debug_pub.add('after delete_row and hdr validate_hsc_quota_total rt status : ' || l_header_scredit_rec.return_status);
1294                    END IF;
1295                    l_del_ret_status := l_header_scredit_rec.return_status; --bug 5331854
1296 
1297                 END IF;
1298   --bug 5049879
1299             ELSE
1300 
1301                 --  Get Who Information
1302 
1303                 l_Header_Scredit_rec.last_update_date := SYSDATE;
1304                 l_Header_Scredit_rec.last_updated_by := NVL(OE_STANDARD_WF.g_user_id, FND_GLOBAL.USER_ID); -- 3169637
1305                 l_Header_Scredit_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
1306 
1307                 IF l_Header_Scredit_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
1308 
1309                     OE_Header_Scredit_Util.Update_Row (l_Header_Scredit_rec);
1310 
1311                 ELSIF l_Header_Scredit_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
1312 
1313                     l_Header_Scredit_rec.creation_date := SYSDATE;
1314                     l_Header_Scredit_rec.created_by := NVL(OE_STANDARD_WF.g_user_id, FND_GLOBAL.USER_ID); -- 3169637
1315 
1316                     OE_Header_Scredit_Util.Insert_Row (l_Header_Scredit_rec);
1317 
1318                 END IF;
1319 
1320             END IF;
1321 
1322         END IF;
1323 
1324     	OE_Header_Scredit_Security.g_check_all_cols_constraint := 'Y';
1325         OE_MSG_PUB.reset_msg_context('HEADER_SCREDIT');
1326 
1327      --  loop exception handler.
1328 	IF l_header_scredit_rec.return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1329 		   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1330 	 ELSIF l_header_scredit_rec.return_status = FND_API.G_RET_STS_ERROR THEN
1331 		   RAISE FND_API.G_EXC_ERROR;
1332 	END IF;
1333 
1334         --  Load tables.
1335 
1336         l_Header_Scredit_rec.return_status        := FND_API.G_RET_STS_SUCCESS;
1337         p_x_Header_Scredit_tbl(I)        := l_Header_Scredit_rec;
1338         p_x_old_Header_Scredit_tbl(I)    := l_old_Header_Scredit_rec;
1339 
1340 
1341     EXCEPTION
1342 
1343         WHEN FND_API.G_EXC_ERROR THEN
1344 
1345           l_Header_Scredit_rec.return_status := FND_API.G_RET_STS_ERROR;
1346 	     x_return_status 				:= FND_API.G_RET_STS_ERROR;
1347           p_x_Header_Scredit_tbl(I)        := l_Header_Scredit_rec;
1348           p_x_old_Header_Scredit_tbl(I)    := l_old_Header_Scredit_rec;
1349 
1350     	     OE_Header_Scredit_Security.g_check_all_cols_constraint := 'Y';
1351           OE_MSG_PUB.reset_msg_context('HEADER_SCREDIT');
1352 
1353 		IF l_control_Rec.Process_Partial THEN
1354              IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
1355                IF l_debug_level  > 0 THEN
1356                    oe_debug_pub.add(  'DELETE REQUEST4' , 2 ) ;
1357                END IF;
1358                oe_delayed_requests_pvt.Delete_Reqs_for_Deleted_Entity
1359                  (p_entity_code =>OE_GLOBALS.G_ENTITY_HEADER_SCREDIT,
1360                   p_entity_id => l_header_scredit_rec.sales_credit_id,
1361                   x_return_status => l_return_status);
1362              END IF;
1363 		   ROLLBACK TO SAVEPOINT Header_Scredits;
1364 		ELSE
1365                    --bug 5331854
1366                    IF OE_GLOBALS.G_UI_FLAG AND
1367                       l_del_ret_status = FND_API.G_RET_STS_ERROR THEN
1368                       ROLLBACK TO SAVEPOINT DELETE_SCREDIT_FAILED;
1369                    END IF;
1370                    --bug 5331854
1371 		   RAISE FND_API.G_EXC_ERROR;
1372 		END IF;
1373 
1374         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1375 
1376             l_Header_Scredit_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1377 		  x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
1378             p_x_Header_Scredit_tbl(I)        := l_Header_Scredit_rec;
1379             p_x_old_Header_Scredit_tbl(I)    := l_old_Header_Scredit_rec;
1380     	       OE_Header_Scredit_Security.g_check_all_cols_constraint := 'Y';
1381             OE_MSG_PUB.reset_msg_context('HEADER_SCREDIT');
1382             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1383 
1384         WHEN OTHERS THEN
1385 
1386             l_Header_Scredit_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1387 		  x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
1388             p_x_Header_Scredit_tbl(I)        := l_Header_Scredit_rec;
1389             p_x_old_Header_Scredit_tbl(I)    := l_old_Header_Scredit_rec;
1390 
1391     	       OE_Header_Scredit_Security.g_check_all_cols_constraint := 'Y';
1392             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1393             THEN
1394                 OE_MSG_PUB.Add_Exc_Msg
1395                 (   G_PKG_NAME
1396                 ,   'Header_Scredits'
1397                 );
1398             END IF;
1399 
1400             OE_MSG_PUB.reset_msg_context('HEADER_SCREDIT');
1401             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1402 
1403     END;
1404      I := p_x_Header_Scredit_tbl.NEXT(I);
1405     END LOOP;
1406 
1407     IF l_debug_level  > 0 THEN
1408         oe_debug_pub.add(  'EXITING OE_ORDER_PVT.HEADER_SCREDITS' , 1 ) ;
1409     END IF;
1410          OE_MSG_PUB.reset_msg_context('HEADER_SCREDIT');
1411 
1412     set_recursion_mode(p_Entity_Code => 4,
1413                                    p_In_out  => 0);
1414 EXCEPTION
1415 
1416     WHEN FND_API.G_EXC_ERROR THEN
1417 
1418         set_recursion_mode(p_Entity_Code => 4,
1419                                    p_In_out  => 0);
1420 	   x_return_status 				:= FND_API.G_RET_STS_ERROR;
1421         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
1422           IF l_debug_level  > 0 THEN
1423               oe_debug_pub.add(  'DELETE REQUEST5' , 2 ) ;
1424           END IF;
1425           OE_Delayed_Requests_Pvt.Clear_Request
1426                     (x_return_status => l_return_status);
1427         END IF;
1428         OE_MSG_PUB.reset_msg_context('HEADER_SCREDIT');
1429 
1430     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1431 
1432         set_recursion_mode(p_Entity_Code => 4,
1433                                    p_In_out  => 0);
1434 	   x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
1435         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
1436           IF l_debug_level  > 0 THEN
1437               oe_debug_pub.add(  'DELETE REQUEST6' , 2 ) ;
1438           END IF;
1439           OE_Delayed_Requests_Pvt.Clear_Request
1440                     (x_return_status => l_return_status);
1441         END IF;
1442         OE_MSG_PUB.reset_msg_context('HEADER_SCREDIT');
1443 
1444     WHEN OTHERS THEN
1445 
1446         set_recursion_mode(p_Entity_Code => 4,
1447                                    p_In_out  => 0);
1448 	   x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
1449         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
1450           IF l_debug_level  > 0 THEN
1451               oe_debug_pub.add(  'DELETE REQUEST7' , 2 ) ;
1452           END IF;
1453           OE_Delayed_Requests_Pvt.Clear_Request
1454                     (x_return_status => l_return_status);
1455         END IF;
1456         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1457         THEN
1458             OE_MSG_PUB.Add_Exc_Msg
1459             (   G_PKG_NAME
1460             ,   'Header_Scredits'
1461             );
1462         END IF;
1463 
1464 
1465         OE_MSG_PUB.reset_msg_context('HEADER_SCREDIT');
1466 
1467 END Header_Scredits;
1468 
1469 
1470 /*-------------------------------------------------------------------
1471 PROCEDURE  Header_Payments
1472 -------------------------------------------------------------------*/
1473 PROCEDURE Header_Payments
1474 (   p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
1475 ,   p_validation_level              IN  NUMBER
1476 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
1477 ,   p_x_Header_Payment_tbl          IN OUT NOCOPY  OE_Order_PUB.Header_Payment_Tbl_Type
1478 ,   p_x_old_Header_Payment_tbl      IN OUT NOCOPY  OE_Order_PUB.Header_Payment_Tbl_Type
1479 , x_return_status OUT NOCOPY VARCHAR2
1480 
1481 )
1482 IS
1483 l_return_status               VARCHAR2(1);
1484 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
1485 l_Header_Payment_rec          OE_Order_PUB.Header_Payment_Rec_Type;
1486 l_old_Header_Payment_rec      OE_Order_PUB.Header_Payment_Rec_Type;
1487 -- local variables to store OUT parameters from security check procedures
1488 l_sec_result            NUMBER;
1489 l_on_operation_action   NUMBER;
1490   l_order_source_id           NUMBER;
1491   l_orig_sys_document_ref     VARCHAR2(50);
1492   l_change_sequence           VARCHAR2(50);
1493   l_source_document_type_id   NUMBER;
1494   l_source_document_id        NUMBER;
1495 
1496 I 				    NUMBER; -- Used as index for while loop
1497 --
1498 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1499 l_org_id      number ;
1500 --
1501 BEGIN
1502 
1503     --MOAC changes start
1504       l_org_id := MO_GLOBAL.get_current_org_id;
1505       IF (l_org_id IS NULL OR l_org_id = FND_API.G_MISS_NUM) THEN
1506          FND_MESSAGE.set_name('FND','MO_ORG_REQUIRED');
1507          OE_MSG_PUB.Add;
1508          RAISE FND_API.G_EXC_ERROR;
1509       END IF;
1510     --MOAC changes end
1511 
1512     x_return_status := FND_API.G_RET_STS_SUCCESS;
1513 
1514     --  Initialize message list.
1515 
1516     IF FND_API.to_Boolean(p_init_msg_list) THEN
1517         OE_MSG_PUB.initialize;
1518     END IF;
1519 
1520     IF p_control_rec.Process_Partial THEN
1521         SAVEPOINT Header_Payments;
1522     END IF;
1523 
1524     --  Init local table variables.
1525 
1526     IF l_debug_level  > 0 THEN
1527         oe_debug_pub.add(  'ENTERING OE_ORDER_PVT.HEADER_PAYMENTS' , 1 ) ;
1528     END IF;
1529 
1530 --    FOR I IN 1..p_x_Header_Payment_tbl.COUNT LOOP
1531 
1532     I := p_x_Header_Payment_tbl.FIRST;
1533 
1534     WHILE I IS NOT NULL LOOP
1535     BEGIN
1536 
1537         --  Load local records.
1538 
1539         l_Header_Payment_rec := p_x_Header_Payment_tbl(I);
1540 
1541         IF p_x_old_Header_Payment_tbl.EXISTS(I) THEN
1542             l_old_Header_Payment_rec := p_x_old_Header_Payment_tbl(I);
1543         ELSE
1544             l_old_Header_Payment_rec := OE_Order_PUB.G_MISS_HEADER_PAYMENT_REC;
1545         END IF;
1546 
1547       if l_old_header_Payment_rec.payment_number = FND_API.G_MISS_NUM
1548 	    OR l_old_header_Payment_rec.payment_number IS NULL
1549 	 Then
1550 
1551          IF l_header_Payment_rec.header_id IS NOT NULL AND
1552             l_header_Payment_rec.header_id <> FND_API.G_MISS_NUM THEN
1553             BEGIN
1554                IF l_debug_level  > 0 THEN
1555                   oe_debug_pub.add('Getting reference data for header_id:'||l_header_Payment_rec.header_id);
1556                END IF;
1557                SELECT order_source_id, orig_sys_document_ref, change_sequence,
1558                source_document_type_id, source_document_id
1559                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
1560                l_source_document_type_id, l_source_document_id
1561                FROM   OE_ORDER_HEADERS_ALL
1562                WHERE  header_id = l_header_Payment_rec.header_id;
1563             EXCEPTION
1564                WHEN NO_DATA_FOUND THEN
1565                    l_order_source_id := null;
1566                    l_orig_sys_document_ref := null;
1567                    l_change_sequence := null;
1568                    l_source_document_type_id := null;
1569                    l_source_document_id := null;
1570                WHEN OTHERS THEN
1571                    l_order_source_id := null;
1572                    l_orig_sys_document_ref := null;
1573                    l_change_sequence := null;
1574                    l_source_document_type_id := null;
1575                    l_source_document_id := null;
1576             END;
1577          END IF;
1578 
1579         OE_MSG_PUB.set_msg_context(
1580 	 	p_entity_code			=> 'HEADER_PAYMENT'
1581   		,p_entity_id         		=> l_header_Payment_rec.payment_number
1582     		,p_header_id         		=> l_header_Payment_rec.header_Id
1583     		,p_line_id           		=> null
1584                 ,p_order_source_id              => l_order_source_id
1585     		,p_orig_sys_document_ref	=> l_orig_sys_document_ref
1586     		,p_orig_sys_document_line_ref	=> null
1587                 ,p_change_sequence              => l_change_sequence
1588                 ,p_source_document_type_id      => l_source_document_type_id
1589     		,p_source_document_id		=> l_source_document_id
1590     		,p_source_document_line_id	=> null );
1591 
1592      else
1593          IF l_old_header_Payment_rec.header_id IS NOT NULL AND
1594             l_old_header_Payment_rec.header_id <> FND_API.G_MISS_NUM THEN
1595 
1596             BEGIN
1597                IF l_debug_level  > 0 THEN
1598                   oe_debug_pub.add('Getting reference data for old header_id:'||l_old_header_Payment_rec.header_id);
1599                END IF;
1600                SELECT order_source_id, orig_sys_document_ref, change_sequence,
1601                source_document_type_id, source_document_id
1602                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
1603                l_source_document_type_id, l_source_document_id
1604                FROM   OE_ORDER_HEADERS_ALL
1605                WHERE  header_id = l_old_header_Payment_rec.header_id;
1606             EXCEPTION
1607                WHEN NO_DATA_FOUND THEN
1608                    l_order_source_id := null;
1609                    l_orig_sys_document_ref := null;
1610                    l_change_sequence := null;
1611                    l_source_document_type_id := null;
1612                    l_source_document_id := null;
1613                WHEN OTHERS THEN
1614                    l_order_source_id := null;
1615                    l_orig_sys_document_ref := null;
1616                    l_change_sequence := null;
1617                    l_source_document_type_id := null;
1618                    l_source_document_id := null;
1619             END;
1620          END IF;
1621 
1622 
1623         OE_MSG_PUB.set_msg_context(
1624 	 	p_entity_code			=> 'HEADER_PAYMENT'
1625   		,p_entity_id         		=> l_old_header_Payment_rec.payment_number
1626     		,p_header_id         		=> l_old_header_Payment_rec.header_Id
1627     		,p_line_id           		=> null
1628                 ,p_order_source_id              => l_order_source_id
1629                 ,p_orig_sys_document_ref        => l_orig_sys_document_ref
1630                 ,p_orig_sys_document_line_ref   => null
1631                 ,p_change_sequence              => l_change_sequence
1632                 ,p_source_document_type_id      => l_source_document_type_id
1633                 ,p_source_document_id           => l_source_document_id
1634     		,p_source_document_line_id	=> null );
1635 
1636      end if;
1637 
1638         --  Load API control record
1639 
1640         l_control_rec := OE_GLOBALS.Init_Control_Rec
1641         (   p_operation     => l_Header_Payment_rec.operation
1642         ,   p_control_rec   => p_control_rec
1643         );
1644 
1645         --  Set record return status.
1646 
1647         l_Header_Payment_rec.return_status := FND_API.G_RET_STS_SUCCESS;
1648 
1649         --  Prepare record.
1650 
1651         IF l_Header_Payment_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
1652 
1653             l_Header_Payment_rec.db_flag := FND_API.G_FALSE;
1654 
1655             --  Set missing old record elements to NULL.
1656 
1657             IF l_debug_level  > 0 THEN
1658                oe_debug_pub.add('Payment:before OE_Header_Payment_Util.Convert_Miss_To_Null', 5);
1659             END IF;
1660             OE_Header_Payment_Util.Convert_Miss_To_Null (l_old_Header_Payment_rec);
1661             IF l_debug_level  > 0 THEN
1662                oe_debug_pub.add('Payment:after OE_Header_Payment_Util.Convert_Miss_To_Null', 5);
1663             END IF;
1664 
1665         ELSIF l_Header_Payment_rec.operation = OE_GLOBALS.G_OPR_UPDATE
1666         OR    l_Header_Payment_rec.operation = OE_GLOBALS.G_OPR_DELETE
1667         THEN
1668 
1669             l_Header_Payment_rec.db_flag := FND_API.G_TRUE;
1670 
1671             --  Query Old if missing
1672 
1673             IF  l_old_Header_Payment_rec.payment_number = FND_API.G_MISS_NUM
1674 			 OR l_old_Header_Payment_rec.payment_number IS NULL
1675             THEN
1676 
1677                 IF l_debug_level  > 0 THEN
1678                    oe_debug_pub.add('Payment:before OE_Header_Payment_Util.Query_Row', 5);
1679                 END IF;
1680                 OE_Header_Payment_Util.Query_Row
1681                 (   p_payment_number             => l_Header_Payment_rec.payment_number
1682                 ,   p_header_id                  => l_Header_Payment_rec.header_id
1683 		,   x_header_payment_rec          => l_old_Header_Payment_rec
1684                 );
1685                 IF l_debug_level  > 0 THEN
1686                    oe_debug_pub.add('Payment:after OE_Header_Payment_Util.Query_Row', 5);
1687                 END IF;
1688 
1689             ELSE
1690 
1691                 --  Set missing old record elements to NULL.
1692 
1693                 IF l_debug_level  > 0 THEN
1694                    oe_debug_pub.add('Payment:before OE_Header_Payment_Util.Convert_Miss_To_Null', 5);
1695                 END IF;
1696                 OE_Header_Payment_Util.Convert_Miss_To_Null (l_old_Header_Payment_rec);
1697                 IF l_debug_level  > 0 THEN
1698                    oe_debug_pub.add('Payment:after OE_Header_Payment_Util.Convert_Miss_To_Null', 5);
1699                 END IF;
1700 
1701             END IF;
1702 
1703             --  Complete new record from old
1704 
1705             IF l_debug_level  > 0 THEN
1706                oe_debug_pub.add('Payment:before OE_Header_Payment_Util.Complete_Record', 5);
1707             END IF;
1708             OE_Header_Payment_Util.Complete_Record
1709             (   p_x_Header_Payment_rec        => l_Header_Payment_rec
1710             ,   p_old_Header_Payment_rec      => l_old_Header_Payment_rec
1711             );
1712             IF l_debug_level  > 0 THEN
1713                oe_debug_pub.add('Payment:after OE_Header_Payment_Util.Complete_Record', 5);
1714             END IF;
1715 
1716             OE_MSG_PUB.update_msg_context(
1717 	 	p_entity_code			=> 'HEADER_PAYMENT'
1718   		,p_entity_id         		=> l_header_Payment_rec.payment_number
1719     		,p_header_id         		=> l_header_Payment_rec.header_Id);
1720 
1721 
1722         END IF;
1723 
1724         IF I = p_x_header_Payment_tbl.FIRST THEN
1725 	       IF NOT Valid_Upgraded_Order(l_header_Payment_rec.header_id) THEN
1726                  RAISE FND_API.G_EXC_ERROR;
1727             END IF;
1728         END IF;
1729 
1730    -- Check security
1731    IF l_control_rec.check_security
1732       AND (l_header_payment_rec.operation = OE_GLOBALS.G_OPR_CREATE
1733          OR l_header_payment_rec.operation = OE_GLOBALS.G_OPR_UPDATE)
1734    THEN
1735 
1736         IF l_debug_level  > 0 THEN
1737             oe_debug_pub.add(  'CHECK ATTRIBUTES SECURITY' ) ;
1738         END IF;
1739         -- check if this operation is allowed
1740         -- on all the changed attributes
1741            IF l_debug_level  > 0 THEN
1742               oe_debug_pub.add('Payment:before OE_Header_Payment_Security.Attributes', 5);
1743            END IF;
1744            OE_Header_Payment_Security.Attributes
1745                 (p_header_payment_rec  	=> l_header_payment_rec
1746                 , p_old_header_payment_rec	=> l_old_header_payment_rec
1747                 , x_result      	=> l_sec_result
1748                 , x_return_status 	=> l_return_status
1749                 );
1750            IF l_debug_level  > 0 THEN
1751               oe_debug_pub.add('Payment:after OE_Header_Payment_Security.Attributes', 5);
1752            END IF;
1753 
1754             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1755                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1756             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1757                 RAISE FND_API.G_EXC_ERROR;
1758             END IF;
1759 
1760            IF l_sec_result = OE_PC_GLOBALS.YES THEN
1761                 RAISE FND_API.G_EXC_ERROR;
1762            END IF;
1763 
1764     END IF;
1765 
1766         --  Attribute level validation.
1767 
1768             IF p_validation_level > FND_API.G_VALID_LEVEL_NONE THEN
1769                 IF l_debug_level  > 0 THEN
1770                    oe_debug_pub.add('Payment:before OE_Validate_Header_Payment.Attributes', 5);
1771                 END IF;
1772 
1773                 OE_Validate_Header_Payment.Attributes
1774                 (   x_return_status               => l_return_status
1775                 ,   p_Header_Payment_rec          => l_Header_Payment_rec
1776                 ,   p_old_Header_Payment_rec      => l_old_Header_Payment_rec
1777                 );
1778                 IF l_debug_level  > 0 THEN
1779                    oe_debug_pub.add('Payment:after OE_Validate_Header_Payment.Attributes',5);
1780                 END IF;
1781 
1782                 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1783                     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1784                 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1785                     RAISE FND_API.G_EXC_ERROR;
1786                 END IF;
1787 
1788             END IF;
1789 
1790 
1791             --  Clear dependent attributes.
1792 
1793         IF  l_control_rec.clear_dependents THEN
1794 
1795             IF l_debug_level  > 0 THEN
1796                oe_debug_pub.add('Payment:before OE_Header_Payment_Util.Clear_Dependent_Attr', 5);
1797             END IF;
1798             OE_Header_Payment_Util.Clear_Dependent_Attr
1799             (   p_x_Header_Payment_rec        => l_Header_Payment_rec
1800             ,   p_old_Header_Payment_rec      => l_old_Header_Payment_rec
1801             );
1802             IF l_debug_level  > 0 THEN
1803                oe_debug_pub.add('Payment:after OE_Header_Payment_Util.Clear_Dependent_Attr', 5);
1804             END IF;
1805 
1806         END IF;
1807 
1808         --  Default missing attributes
1809 
1810         IF  l_control_rec.default_attributes
1811         THEN
1812             IF l_debug_level  > 0 THEN
1813                oe_debug_pub.add('Payment:before OE_Default_Header_Payment.Attributes', 5);
1814             END IF;
1815 
1816             OE_Default_Header_Payment.Attributes
1817             (   p_x_Header_Payment_rec        => l_Header_Payment_rec
1818             ,   p_old_header_payment_rec      => l_old_header_payment_rec
1819             );
1820             IF l_debug_level  > 0 THEN
1821                oe_debug_pub.add('Payment:after OE_Default_Header_Payment.Attributes', 5);
1822             END IF;
1823 
1824         END IF;
1825 
1826         --  Apply attribute changes
1827 
1828         IF  l_control_rec.change_attributes
1829         THEN
1830 
1831             IF l_debug_level  > 0 THEN
1832                oe_debug_pub.add('Payment:before OE_Header_Payment_Util.Apply_Attribute_Changes', 5);
1833             END IF;
1834             OE_Header_Payment_Util.Apply_Attribute_Changes
1835             (   p_x_Header_Payment_rec          => l_Header_Payment_rec
1836             ,   p_old_Header_Payment_rec      => l_old_Header_Payment_rec
1837             );
1838             IF l_debug_level  > 0 THEN
1839                oe_debug_pub.add('Payment:after OE_Header_Payment_Util.Apply_Attribute_Changes', 5);
1840             END IF;
1841 
1842         END IF;
1843 
1844         --  Entity level validation.
1845 
1846         IF l_control_rec.validate_entity THEN
1847 
1848             IF l_Header_Payment_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
1849 
1850                 IF l_debug_level  > 0 THEN
1851                    oe_debug_pub.add('Payment:before OE_Validate_Header_Payment.Entity_Delete', 5);
1852                 END IF;
1853                 OE_Validate_Header_Payment.Entity_Delete
1854                 (   x_return_status               => l_return_status
1855                 ,   p_Header_Payment_rec          => l_Header_Payment_rec
1856                 );
1857                 IF l_debug_level  > 0 THEN
1858                    oe_debug_pub.add('Payment:after OE_Validate_Header_Payment.Entity_Delete', 5);
1859                 END IF;
1860 
1861             ELSE
1862                 IF l_debug_level  > 0 THEN
1863                    oe_debug_pub.add('Payment:before OE_Validate_Header_Payment.Entity',5);
1864                 END IF;
1865 
1866                 OE_Validate_Header_Payment.Entity
1867                 (   x_return_status               => l_return_status
1868                 ,   p_Header_Payment_rec          => l_Header_Payment_rec
1869                 ,   p_old_Header_Payment_rec      => l_old_Header_Payment_rec
1870                 );
1871                 IF l_debug_level  > 0 THEN
1872                    oe_debug_pub.add('Payment:after OE_Validate_Header_Payment.Entity, 5');
1873                 END IF;
1874 
1875             END IF;
1876 
1877             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1878                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1879             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1880                 RAISE FND_API.G_EXC_ERROR;
1881             END IF;
1882 
1883         END IF;
1884 
1885     -- Check entity level security again as some attributes
1886     -- may have changed due to defaulting.
1887     -- For UPDATE operations, entity security checks for constraints setup
1888     -- with a NULL column i.e. the constraint restricts update on ANY of
1889     -- the columns.
1890     -- However, this check should NOT be done if user did not try to update
1891     -- any of the constrainable attributes and also none of the defaulted
1892     -- attributes was constrainable!. In such a case, the g_check_all_cols
1893     -- _constraint flag would still be 'Y' as the flag is reset only
1894     -- when checking for constraints.
1895     IF NOT (l_header_payment_rec.operation  = OE_GLOBALS.G_OPR_UPDATE
1896                AND OE_Header_Payment_Security.g_check_all_cols_constraint = 'Y')
1897        AND l_control_rec.check_security
1898     THEN
1899         IF l_debug_level  > 0 THEN
1900             oe_debug_pub.add(  'CHECK ENTITY SECURITY' ) ;
1901         END IF;
1902            IF l_debug_level  > 0 THEN
1903               oe_debug_pub.add('Payment:before OE_Header_Payment_Security.Entity', 5);
1904            END IF;
1905 
1906            OE_Header_Payment_Security.Entity
1907                 (p_header_payment_rec   	=> l_header_payment_rec
1908                 , x_result      	=> l_sec_result
1909                 , x_return_status 	=> l_return_status
1910                 );
1911            IF l_debug_level  > 0 THEN
1912               oe_debug_pub.add('Payment:after OE_Header_Payment_Security.Entity', 5);
1913            END IF;
1914 
1915             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1916                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1917             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1918                 RAISE FND_API.G_EXC_ERROR;
1919             END IF;
1920 
1921            IF l_sec_result = OE_PC_GLOBALS.YES THEN
1922                 RAISE FND_API.G_EXC_ERROR;
1923            END IF;
1924 
1925     END IF;
1926 
1927         --  Step 4. Write to DB
1928 
1929         IF l_control_rec.write_to_db THEN
1930 
1931 		 /* Start Audit Trail */
1932          IF l_debug_level  > 0 THEN
1933             oe_debug_pub.add('Payment:before Oe_Header_Payment_Util.Pre_Write_Process', 5);
1934          END IF;
1935       	 Oe_Header_Payment_Util.Pre_Write_Process
1936 		   (p_x_header_Payment_rec => l_header_payment_rec,
1937 		    p_old_header_payment_rec => l_old_header_payment_rec);
1938          IF l_debug_level  > 0 THEN
1939             oe_debug_pub.add('Payment:after Oe_Header_Payment_Util.Pre_Write_Process', 5);
1940          END IF;
1941            /* End AuditTrail */
1942 
1943             IF l_Header_Payment_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
1944                 IF l_debug_level  > 0 THEN
1945                    oe_debug_pub.add('Payment:before Oe_Header_Payment_Util.Delete_Row',5);
1946                 END IF;
1947 
1948                 OE_Header_Payment_Util.Delete_Row
1949                 (   p_payment_number     => l_Header_Payment_rec.payment_number
1950                 ,   p_header_id          => l_Header_Payment_rec.header_id
1951                 );
1952                 IF l_debug_level  > 0 THEN
1953                    oe_debug_pub.add('Payment:after Oe_Header_Payment_Util.Delete_Row',5);
1954                 END IF;
1955 
1956             ELSE
1957 
1958                 --  Get Who Information
1959 
1960                 l_Header_Payment_rec.last_update_date := SYSDATE;
1961                 l_Header_Payment_rec.last_updated_by := FND_GLOBAL.USER_ID;
1962                 l_Header_Payment_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
1963 
1964                 IF l_Header_Payment_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
1965 
1966                     OE_Header_Payment_Util.Update_Row (l_Header_Payment_rec);
1967 
1968                 ELSIF l_Header_Payment_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
1969 
1970                     l_Header_Payment_rec.creation_date := SYSDATE;
1971                     l_Header_Payment_rec.created_by := FND_GLOBAL.USER_ID;
1972 
1973                     IF l_debug_level  > 0 THEN
1974                        oe_debug_pub.add('Payment:before Oe_Header_Payment_Util.Insert_Row', 5);
1975                     END IF;
1976                     OE_Header_Payment_Util.Insert_Row (l_Header_Payment_rec);
1977                     IF l_debug_level  > 0 THEN
1978                        oe_debug_pub.add('Payment:after Oe_Header_Payment_Util.Insert_Row', 5);
1979                     END IF;
1980 
1981                 END IF;
1982 
1983             END IF;
1984 
1985         END IF;
1986 
1987     	OE_Header_Payment_Security.g_check_all_cols_constraint := 'Y';
1988         OE_MSG_PUB.reset_msg_context('HEADER_PAYMENT');
1989 
1990      --  loop exception handler.
1991 	IF l_header_payment_rec.return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1992 		   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1993 	 ELSIF l_header_payment_rec.return_status = FND_API.G_RET_STS_ERROR THEN
1994 		   RAISE FND_API.G_EXC_ERROR;
1995 	END IF;
1996 
1997         --  Load tables.
1998 
1999         l_Header_Payment_rec.return_status        := FND_API.G_RET_STS_SUCCESS;
2000         p_x_Header_Payment_tbl(I)        := l_Header_Payment_rec;
2001         p_x_old_Header_Payment_tbl(I)    := l_old_Header_Payment_rec;
2002 
2003 
2004     EXCEPTION
2005 
2006         WHEN FND_API.G_EXC_ERROR THEN
2007 
2008           l_Header_Payment_rec.return_status := FND_API.G_RET_STS_ERROR;
2009 	     x_return_status 				:= FND_API.G_RET_STS_ERROR;
2010           p_x_Header_Payment_tbl(I)        := l_Header_Payment_rec;
2011           p_x_old_Header_Payment_tbl(I)    := l_old_Header_Payment_rec;
2012 
2013     	     OE_Header_Payment_Security.g_check_all_cols_constraint := 'Y';
2014           OE_MSG_PUB.reset_msg_context('HEADER_PAYMENT');
2015 		IF l_control_Rec.Process_Partial THEN
2016              IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
2017                IF l_debug_level  > 0 THEN
2018                    oe_debug_pub.add(  'DELETE REQUEST4' , 2 ) ;
2019                END IF;
2020                oe_delayed_requests_pvt.Delete_Reqs_for_Deleted_Entity
2021                  (p_entity_code =>OE_GLOBALS.G_ENTITY_HEADER_PAYMENT,
2022                   p_entity_id => l_header_payment_rec.header_id,
2023                   x_return_status => l_return_status);
2024              END IF;
2025 		   ROLLBACK TO SAVEPOINT Header_Payments;
2026 		ELSE
2027 		   RAISE FND_API.G_EXC_ERROR;
2028 		END IF;
2029 
2030         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2031 
2032             l_Header_Payment_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2033 		  x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
2034             p_x_Header_Payment_tbl(I)        := l_Header_Payment_rec;
2035             p_x_old_Header_Payment_tbl(I)    := l_old_Header_Payment_rec;
2036     	       OE_Header_Payment_Security.g_check_all_cols_constraint := 'Y';
2037             OE_MSG_PUB.reset_msg_context('HEADER_PAYMENT');
2038             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2039 
2040         WHEN OTHERS THEN
2041 
2042             l_Header_Payment_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2043 		  x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
2044             p_x_Header_Payment_tbl(I)        := l_Header_Payment_rec;
2045             p_x_old_Header_Payment_tbl(I)    := l_old_Header_Payment_rec;
2046 
2047     	       OE_Header_Payment_Security.g_check_all_cols_constraint := 'Y';
2048             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2049             THEN
2050                 OE_MSG_PUB.Add_Exc_Msg
2051                 (   G_PKG_NAME
2052                 ,   'Header_Payments'
2053                 );
2054             END IF;
2055 
2056             OE_MSG_PUB.reset_msg_context('HEADER_PAYMENT');
2057             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2058 
2059     END;
2060      I := p_x_Header_Payment_tbl.NEXT(I);
2061     END LOOP;
2062 
2063     IF l_debug_level  > 0 THEN
2064         oe_debug_pub.add(  'EXITING OE_ORDER_PVT.HEADER_PAYMENTS' , 1 ) ;
2065     END IF;
2066          OE_MSG_PUB.reset_msg_context('HEADER_PAYMENT');
2067 
2068 EXCEPTION
2069 
2070     WHEN FND_API.G_EXC_ERROR THEN
2071 
2072 	   x_return_status 				:= FND_API.G_RET_STS_ERROR;
2073         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
2074           IF l_debug_level  > 0 THEN
2075               oe_debug_pub.add(  'DELETE REQUEST5' , 2 ) ;
2076           END IF;
2077           OE_Delayed_Requests_Pvt.Clear_Request
2078                     (x_return_status => l_return_status);
2079         END IF;
2080         OE_MSG_PUB.reset_msg_context('HEADER_PAYMENT');
2081 
2082     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2083 
2084 	   x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
2085         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
2086           IF l_debug_level  > 0 THEN
2087               oe_debug_pub.add(  'DELETE REQUEST6' , 2 ) ;
2088           END IF;
2089           OE_Delayed_Requests_Pvt.Clear_Request
2090                     (x_return_status => l_return_status);
2091         END IF;
2092         OE_MSG_PUB.reset_msg_context('HEADER_PAYMENT');
2093 
2094     WHEN OTHERS THEN
2095 
2096 	   x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
2097         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
2098           IF l_debug_level  > 0 THEN
2099               oe_debug_pub.add(  'DELETE REQUEST7' , 2 ) ;
2100           END IF;
2101           OE_Delayed_Requests_Pvt.Clear_Request
2102                     (x_return_status => l_return_status);
2103         END IF;
2104         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2105         THEN
2106             OE_MSG_PUB.Add_Exc_Msg
2107             (   G_PKG_NAME
2108             ,   'Header_Payments'
2109             );
2110         END IF;
2111 
2112 
2113         OE_MSG_PUB.reset_msg_context('HEADER_PAYMENT');
2114 
2115 END Header_Payments;
2116 
2117 
2118 /*---------------------------------------------------------------------
2119 FUNCTION Check_Item_Type
2120 
2121 -- LOCAL function called in procedure Lines
2122 -- Return value from this function indicates what should be the order in
2123 -- which this line is processed based on the type of item on
2124 -- this line. The logic is based on whether the top_model_line or
2125 -- service_line identifiers are populated on the record or not.
2126 -- (Item Type is NOT used to derive this information as item_type_code
2127 -- is available only after defaulting)
2128 -- Possible Return Values:
2129 -- 1:	Standard/ Model Line
2130 -- 2:	Option/Class Line
2131 -- 3:	Service Line
2132 ----------------------------------------------------------------------*/
2133 FUNCTION Check_Item_Type
2134 (   p_line_rec              		IN  OE_Order_PUB.Line_Rec_Type
2135 ,   p_line_index				IN  NUMBER
2136 )
2137 RETURN NUMBER
2138 IS
2139 --
2140 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2141 --
2142 BEGIN
2143 
2144 	-- SERVICE line if service line identifiers are populated
2145 	IF (	NVL(p_line_rec.service_reference_line_id,FND_API.G_MISS_NUM)
2146 					<> FND_API.G_MISS_NUM
2147      	OR NVL(p_line_rec.service_line_index,FND_API.G_MISS_NUM)
2148 					<>  FND_API.G_MISS_NUM )
2149 	THEN
2150 
2151 			IF l_debug_level  > 0 THEN
2152 			    oe_debug_pub.add(  'SERVICE LINE' , 1 ) ;
2153 			END IF;
2154 			RETURN 3;
2155 
2156 	-- Top model line identifiers are populated
2157 	ELSIF ( NVL(p_line_rec.top_model_line_id,FND_API.G_MISS_NUM)
2158 					<> FND_API.G_MISS_NUM
2159      	OR NVL(p_line_rec.top_model_line_index,FND_API.G_MISS_NUM)
2160 					<>  FND_API.G_MISS_NUM )
2161 	THEN
2162 
2163 		-- MODEL line if top model line is same as the current line
2164 		IF ( p_line_rec.top_model_line_id <> FND_API.G_MISS_NUM
2165 		     AND p_line_rec.top_model_line_id = p_line_rec.line_id )
2166 	         OR ( p_line_rec.top_model_line_index <> FND_API.G_MISS_NUM
2167 			AND p_line_rec.top_model_line_index = p_line_index )
2168 		THEN
2169 			IF l_debug_level  > 0 THEN
2170 			    oe_debug_pub.add(  'TOP MODEL LINE' , 1 ) ;
2171 			END IF;
2172 			RETURN 1;
2173 		-- OPTION/CLASS line if line is NOT the model line
2174 		ELSE
2175 			IF l_debug_level  > 0 THEN
2176 			    oe_debug_pub.add(  'OPTION/CLASS LINE' , 1 ) ;
2177 			END IF;
2178 		     RETURN 2;
2179 		END IF;
2180 
2181 	ELSE
2182 
2183 		-- STANDARD line if neither the top model line identifiers
2184 		-- nor the service line identifiers are populated
2185 			IF l_debug_level  > 0 THEN
2186 			    oe_debug_pub.add(  'STANDARD LINE' , 1 ) ;
2187 			END IF;
2188 			RETURN 1;
2189 
2190 	END IF;
2191 
2192 
2193 END Check_Item_Type;
2194 
2195 
2196 
2197 /*----------------------------------------------------------------------
2198 PROCEDURE Lines
2199 
2200 changes to get ato_line_id in case of pto + ato case, bug 1654987.
2201 
2202 WHEN:
2203 
2204 1) Almost all the additional code should never get called if the
2205    configuration is created using options window or configurator,
2206    since we already do all the work in respective code.
2207 
2208 2) Some of the additional stuff happens for copy order and split.
2209 3) All the additionsl work happens for order import and any other
2210    batch api callers.
2211 
2212 
2213 WHY:
2214 1) We need to process all the top level parents
2215    (MODEL, KIT, STANDARD) before we start processing any of the
2216    child lines. This is because all the child lines refer to the
2217    parent lines using top_model_line_index,
2218    service_reference_line_index etc.  and the child lines
2219    processing assumes that all the parents are saved in database
2220    and now it can convert all the indexes to proper values.
2221    e.g. top_model_line_index to top_model_line_id.
2222 
2223 2) Thus we process
2224      all the models and standrds lines first,
2225      then all the classes, options
2226      then all service lines.
2227      This is irrespective of the operation on the lines.
2228 
2229 2) New stuff:
2230    For various reasons (2 bugs till now), we need to process
2231    the class lines before the option lines for the operation
2232    of create. The single most imp. reason is that in case pto+ato
2233    case, we can make sure that all the option lines
2234    will have ato_line_id correclty populated in defaulting code
2235    itself. This is necessary for schedluing and shipping to
2236    behave correctly.
2237 
2238 
2239 
2240 HOW:
2241   Instead of coming up with another mode of CLASS, we now have
2242   a peudo mode of CLASS within the mode of OPTIONS. This means
2243   that we will loop twice within the mode of OPTIONS, in certain
2244   cases as explained below.
2245   The reason for pseudo mode,
2246   1) The check_item_type procedure can not distinguish between a
2247      class and option. We need the (new) complete_config_line
2248      procedure for that.
2249   2) most of the code in the 2 modes(CLASS and OPTION) is common,
2250      the uncommon portion is tightly bound to each other.
2251   3) I also have modified the lines loop to goto the end_of_lines_loop
2252      instead of beging_of_line_loop. This makes sure that switch mode
2253      happens at one place and my extra login will also go at that point.
2254   4) There is no change if the operation is UPDATE or DELETE on
2255      class/options lines.
2256   5) If the call is made from configurator code or options window
2257      code, on all the classl lines, item_type_code is passed.
2258 
2259 
2260 LOGIC:
2261  only the new stuff is explained here(at a high level), rest is same.
2262  ***: indiactes previous code.
2263 
2264  if boolean COMPLETE_AND_CLASS_SAVE_MODE is TRUE, we create CLASSES
2265  if it is fales, we create OPTIONS.
2266 
2267 
2268 MODE = standard_and_models and check_item_type = 1
2269   l_process_this_line = TRUE;
2270   ***
2271   IF top model,
2272     IF not called by config UI,
2273       explode the model
2274       fill in bom related stuff
2275     END IF
2276   END IF;
2277 
2278 
2279 MODE = OPTIONS and check_item_type = 2
2280   IF the line is processed
2281     go to end_of_lines (e.g class during option create, or update of option)
2282   END IF;
2283 
2284   ***
2285 
2286   IF operation = create
2287 
2288     IF COMPLETE_AND_CLASS_SAVE_MODE = TRUE and no config UI used.
2289       fill in bom related stuff(indicates IF class when you are done)
2290     END IF;
2291 
2292       IF this is not a CLASS line
2293         note the index, go to end_of_lines(will process, when the mode is false)
2294       END IF
2295     END IF
2296   END IF;
2297 
2298 
2299 MODE = SERVICE and check_item_type = 3
2300   l_process_this_line = TRUE;
2301   ***
2302 
2303 
2304 IF l_process_this_line = FALSE
2305   go to end_of_line_loop
2306 END IF;
2307 
2308 <<end_of_line_loop>> SWITCHING modes.
2309 
2310  IF MODE = 'MODELS_AND_STANDARD' AND END of lines table(only models,std done)
2311    l_mode := 'OPTIONS';
2312    COMPLETE_AND_CLASS_SAVE_MODE := TRUE;
2313    start from the first record again.
2314 
2315  IF mode = 'OPTIONS' AND END of lines table (classes create, upd/del done)
2316 
2317    IF COMPLETE_AND_CLASS_SAVE_MODE
2318 
2319       COMPLETE_AND_CLASS_SAVE_MODE = FALSE;
2320       -- false means, create OPTIONS, mode is still OPTIONS
2321 
2322      IF not config UI Used  AND
2323         some of the options were skipped in creation
2324 
2325         fill in all missing classes, use componenet_code and the fact
2326         that all the classes are saved now.
2327 
2328         IF some new classes added,
2329           set the mode back to classes, save all of them.
2330           thus set the COMPLETE_AND_CLASS_SAVE_MODE = TRUE
2331         END IF;
2332 
2333      END IF;
2334 
2335    ELSE
2336      MODE = 'SERVICE';
2337    END IF;
2338 
2339  END IF;
2340 
2341     -- Fixed bug# 1362872: Removed code to set return_status to SUCCESS on
2342     -- the records as it was overwriting error statuses.
2343     -- The return_status is set at the end of the loop and in the case
2344     -- of errors, it is set in the exception handlers.
2345 
2346 Change Record:
2347 
2348 1828866: to not raise error if some of the option/class items
2349 are not available in bom_explosions. Populate message and continue.
2350 related changes in : OEXUCFGB.pls, OEXUCPYB.pls
2351 
2352 We will not call the complete_config_line for splits. This is
2353 because split already passes all the columns to be filled
2354 in the complete_config. Also the call the get_missing_classes
2355 is not required for the splits. The assumption is split code
2356 already populates/copies all the config related attributes.
2357 
2358 2027611: call to complete_config_line when the mode is OPTION,
2359 will be done only if top_model_line_index is present.
2360 In future we should remove check for config_ui_used global
2361 and also top_model_line_id not null, not miss_num check
2362 while calling  complete_config_line.
2363 -----------------------------------------------------------------------*/
2364 
2365 PROCEDURE Lines
2366 (p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
2367 ,p_validation_level              IN  NUMBER
2368 ,p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
2369 ,p_x_line_tbl                    IN  OUT NOCOPY  OE_Order_PUB.Line_Tbl_Type
2370 ,p_x_old_line_tbl                IN  OUT NOCOPY  OE_Order_PUB.Line_Tbl_Type
2371 ,x_return_status OUT NOCOPY VARCHAR2)
2372 
2373 IS
2374   l_return_status         VARCHAR2(1);
2375   l_control_rec           OE_GLOBALS.Control_Rec_Type;
2376   l_line_rec              OE_Order_PUB.Line_Rec_Type;
2377   l_old_line_rec          OE_Order_PUB.Line_Rec_Type;
2378   l_mode                  VARCHAR2(20);
2379   I                       NUMBER;
2380   l_top_model_line_index  NUMBER;
2381   l_service_line_index    NUMBER;
2382   l_user_id               NUMBER;
2383   l_resp_id               NUMBER;
2384   l_application_id        NUMBER;
2385   l_line_process_name     VARCHAR2(30);
2386 
2387   -- local variables to store OUT parameters from security check procedures
2388   l_sec_result                  NUMBER;
2389   l_on_operation_action         NUMBER;
2390   l_result                      Varchar2(30);
2391   l_request_ind                 NUMBER;
2392   l_check_item_type             NUMBER;
2393   l_daemon_type                 VARCHAR2(1);
2394   l_is_ota_line                 BOOLEAN;
2395   l_order_quantity_uom          VARCHAR2(3);
2396   l_header_locked               VARCHAR2(1) := FND_API.G_MISS_CHAR;
2397   l_locked_header_rec           OE_Order_PUB.Header_Rec_Type;
2398   l_process_this_line           BOOLEAN;
2399   COMPLETE_AND_CLASS_SAVE_MODE  BOOLEAN := TRUE;
2400   l_options_index_tbl           OE_OPTION_INDEX_TBL_TYPE;
2401   l_class_index                 NUMBER;
2402   l_class_count                 NUMBER;
2403   J                             NUMBER := 0;
2404   l_num_lines                   NUMBER;
2405   l_bom_item_type               NUMBER;
2406   --
2407   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2408   l_org_id number ;
2409   --
2410 BEGIN
2411     --Moac changes start
2412     l_org_id := MO_GLOBAL.get_current_org_id;
2413     IF (l_org_id IS NULL OR l_org_id = FND_API.G_MISS_NUM) THEN
2414        FND_MESSAGE.set_name('FND','MO_ORG_REQUIRED');
2415        OE_MSG_PUB.Add;
2416        RAISE FND_API.G_EXC_ERROR;
2417      END IF;
2418     --Moac changes end
2419   set_recursion_mode(p_Entity_Code => 5,
2420                                    p_In_out  => 1);
2421 
2422   l_num_lines := p_x_line_tbl.COUNT;
2423 
2424   Print_Time('Entering OE_ORDER_PVT.LINES ' || l_num_lines);
2425 
2426   x_return_status := FND_API.G_RET_STS_SUCCESS;
2427 
2428   IF OE_GLOBALS.G_RECURSION_MODE <> 'Y' THEN
2429            SAVEPOINT Lines_Non_Partial;
2430   END IF;
2431 
2432   --  Initialize message list.
2433 
2434   IF FND_API.to_Boolean(p_init_msg_list) THEN
2435     OE_MSG_PUB.initialize;
2436   END IF;
2437 
2438   -- Looping through the table to first process all the models and
2439   -- standard lines in the table. When models and options are processed in
2440   -- one Process Order Call (like in Copy Order)  options do not have
2441   -- top_model_line_id
2442   -- and link_to_line_id populated. Thus the Parent line has to be
2443   -- processed before the
2444   -- options so that we can populate the option's top_model_line_id and
2445   -- link_to_line_id.
2446 
2447   IF l_debug_level  > 0 THEN
2448       oe_debug_pub.add(  'G_CONFIG_UI_USED '|| OE_CONFIG_UTIL.G_CONFIG_UI_USED , 5 ) ;
2449   END IF;
2450 
2451   l_mode  :=  'MODELS_AND_STANDARD' ;
2452 
2453   I := p_x_line_tbl.FIRST;
2454 
2455   WHILE I IS NOT NULL AND l_num_lines > 0
2456   LOOP
2457     IF l_debug_level  > 0 THEN
2458         oe_debug_pub.add(  '---------LOOPING FOR NTH TIME N= '|| I , 1 ) ;
2459     END IF;
2460 
2461     IF p_x_line_tbl(I).operation = OE_GLOBALS.G_OPR_NONE THEN
2462       IF l_debug_level  > 0 THEN
2463           oe_debug_pub.add(  'OPERATION IS NONE ' , 1 ) ;
2464       END IF;
2465 
2466       IF nvl(p_x_line_tbl(I).semi_processed_flag, FALSE) = FALSE THEN
2467         IF l_debug_level  > 0 THEN
2468             oe_debug_pub.add(  'ALREADY CAME IN , OPR = NONE' , 5 ) ;
2469         END IF;
2470         p_x_line_tbl(I).semi_processed_flag := TRUE;
2471         l_num_lines := l_num_lines - 1;
2472       END IF;
2473 
2474       GOTO end_of_lines_loop;
2475     END IF;
2476 
2477     l_process_this_line := FALSE;
2478 
2479     BEGIN
2480 
2481       -- Added following logic to identify the RMA lines if user has sent in the
2482       -- ordered_quantity as negative. (bug2620749)
2483 
2484       IF p_x_line_tbl(I).ordered_quantity < 0 AND
2485          ( p_x_line_tbl(I).line_category_code IS NULL OR
2486            p_x_line_tbl(I).line_category_code = FND_API.G_MISS_CHAR OR
2487            p_x_line_tbl(I).line_category_code = 'RETURN')
2488       THEN
2489           p_x_line_tbl(I).line_category_code := 'RETURN';
2490           p_x_line_tbl(I).ordered_quantity := (-1) *
2491                                            p_x_line_tbl(I).ordered_quantity;
2492       END IF;
2493 
2494       -- Change the same on the OLD record.
2495       IF p_x_old_line_tbl.EXISTS(I) THEN
2496           IF p_x_old_line_tbl(I).ordered_quantity < 0 AND
2497            ( p_x_old_line_tbl(I).line_category_code IS NULL OR
2498              p_x_old_line_tbl(I).line_category_code = FND_API.G_MISS_CHAR OR
2499              p_x_old_line_tbl(I).line_category_code = 'RETURN')
2500           THEN
2501               p_x_old_line_tbl(I).line_category_code := 'RETURN';
2502               p_x_old_line_tbl(I).ordered_quantity := (-1) *
2503                                            p_x_old_line_tbl(I).ordered_quantity;
2504           END IF;
2505 
2506       END IF;
2507 
2508       --Added for bug 4937633 source type for Internal orders will be Internal
2509       IF  p_x_line_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE THEN
2510 
2511 		IF p_x_line_tbl(I).source_document_type_id = 10
2512                 OR oe_order_cache.g_header_rec.source_document_type_id = 10 THEN
2513 	           p_x_line_tbl(I).source_type_code := OE_GLOBALS.G_SOURCE_INTERNAL;
2514 		END IF;
2515       END IF;
2516       --Added for bug 4937633 end
2517 
2518       l_line_rec := p_x_line_tbl(I);
2519       IF l_debug_level  > 0 THEN
2520           oe_debug_pub.add(  'SCH ARR DATE='||L_LINE_REC.SCHEDULE_ARRIVAL_DATE ) ;
2521       END IF;
2522 
2523       -- Load old records
2524       IF p_x_old_line_tbl.EXISTS(I) THEN
2525         l_old_line_rec := p_x_old_line_tbl(I);
2526       ELSE
2527         l_old_line_rec := OE_Order_PUB.G_MISS_LINE_REC;
2528       END IF;
2529 
2530       IF l_old_line_rec.line_id = FND_API.G_MISS_NUM OR
2531          l_old_line_rec.line_id IS NULL
2532       THEN
2533 
2534         OE_MSG_PUB.set_msg_context
2535         ( p_entity_code                 => 'LINE'
2536          ,p_entity_id                   => l_line_rec.line_id
2537          ,p_header_id                   => l_line_rec.header_id
2538          ,p_line_id                     => l_line_rec.line_id
2539          ,p_orig_sys_document_ref       => l_line_rec.orig_sys_document_ref
2540          ,p_orig_sys_document_line_ref  => l_line_rec.orig_sys_line_ref
2541          ,p_orig_sys_shipment_ref       => l_line_rec.orig_sys_shipment_ref
2542          ,p_change_sequence             => l_line_rec.change_sequence
2543          ,p_source_document_id          => l_line_rec.source_document_id
2544          ,p_source_document_line_id     => l_line_rec.source_document_line_id
2545          ,p_order_source_id             => l_line_rec.order_source_id
2546          ,p_source_document_type_id     => l_line_rec.source_document_type_id);
2547 
2548       ELSE
2549 
2550         OE_MSG_PUB.set_msg_context
2551         ( p_entity_code             => 'LINE'
2552          ,p_entity_id               => l_old_line_rec.line_id
2553          ,p_header_id               => l_old_line_rec.header_id
2554          ,p_line_id                 => l_old_line_rec.line_id
2555          ,p_orig_sys_document_ref   => l_old_line_rec.orig_sys_document_ref
2556          ,p_orig_sys_document_line_ref  => l_old_line_rec.orig_sys_line_ref
2557          ,p_orig_sys_shipment_ref       => l_old_line_rec.orig_sys_shipment_ref
2558          ,p_change_sequence             => l_old_line_rec.change_sequence
2559          ,p_source_document_id      => l_old_line_rec.source_document_id
2560          ,p_source_document_line_id => l_old_line_rec.source_document_line_id
2561          ,p_order_source_id         => l_old_line_rec.order_source_id
2562          ,p_source_document_type_id => l_old_line_rec.source_document_type_id);
2563 
2564       END IF;
2565 
2566 
2567       --  Set Save Point
2568       IF p_control_rec.Process_Partial THEN
2569         SAVEPOINT Lines;
2570       END IF;
2571 
2572       -- Fixed bug# 1362872: Removed code to set return_status to SUCCESS on
2573       -- the records as it was overwriting error statuses.
2574       -- The return_status is set at the end of the loop and in the case
2575       -- of errors, it is set in the exception handlers.
2576 
2577       --  Prepare record.
2578 
2579       IF l_line_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
2580 
2581         IF l_debug_level  > 0 THEN
2582             oe_debug_pub.add(  'OPERATION = CREATE SO SETTING OLD TO NULL' , 2 ) ;
2583         END IF;
2584 
2585         l_line_rec.db_flag := FND_API.G_FALSE;
2586 
2587         --  Set missing old record elements to NULL.
2588 
2589         OE_Line_Util.Convert_Miss_To_Null (l_old_line_rec);
2590 
2591         -- Lock the order header for unbooked orders: This would prevent order
2592         -- lines from being inserted on an order when it is being booked
2593         -- as the booking process also locks the order header.
2594 
2595 /*******
2596         IF l_header_locked = FND_API.G_MISS_CHAR THEN
2597           oe_debug_pub.add('locking the header record');
2598 
2599           SAVEPOINT Header_Lock;
2600 
2601           OE_Header_Util.Lock_Row
2602                ( p_header_id      => l_line_rec.header_id
2603                , x_return_status  => l_return_status
2604                , p_x_header_rec   => l_locked_header_rec);
2605 
2606           IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2607             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2608           ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
2609             RAISE FND_API.G_EXC_ERROR;
2610           END IF;
2611 
2612           IF l_locked_header_rec.booked_flag = 'N' THEN
2613             l_header_locked := 'Y';
2614           ELSE
2615             l_header_locked := 'N';
2616             ROLLBACK TO Header_Lock;
2617           END IF;
2618 
2619         END IF;
2620 *******/
2621 
2622       ELSIF l_line_rec.operation = OE_GLOBALS.G_OPR_UPDATE OR
2623             l_line_rec.operation = OE_GLOBALS.G_OPR_DELETE
2624       THEN
2625 
2626         IF l_debug_level  > 0 THEN
2627             oe_debug_pub.add(  'OPERATION = UPDATE SO QUERY OLD' , 1 ) ;
2628         END IF;
2629 
2630         l_line_rec.db_flag := FND_API.G_TRUE;
2631 
2632         --  Query Old if missing
2633 
2634         IF  l_old_line_rec.line_id = FND_API.G_MISS_NUM OR
2635             l_old_line_rec.line_id IS NULL
2636         THEN
2637 
2638           OE_Line_Util.Query_Row
2639           (   p_line_id                     => l_line_rec.line_id
2640           ,   x_line_rec                    => l_old_line_rec );
2641 
2642           -- Only for lines we are reassiging queried line into old tbl
2643           -- to avoid requery.
2644           p_x_old_line_tbl(I) := l_old_line_rec;
2645 
2646         ELSE
2647           --  Set missing old record elements to NULL.
2648           OE_Line_Util.Convert_Miss_To_Null (l_old_line_rec);
2649 
2650         END IF;
2651 
2652         --  Complete new record from old
2653 
2654         IF l_debug_level  > 0 THEN
2655             oe_debug_pub.add(  'COMPLETE NEW RECORD FROM OLD' , 1 ) ;
2656         END IF;
2657 
2658         OE_Line_Util.Complete_Record
2659         (   p_x_line_rec                  => l_line_rec
2660            ,p_old_line_rec                => l_old_line_rec);
2661 
2662         IF l_debug_level  > 0 THEN
2663             oe_debug_pub.add(  'AFTER COMPLETE NEW RECORD FROM OLD' , 2 ) ;
2664         END IF;
2665 
2666         OE_MSG_PUB.update_msg_context
2667         ( p_entity_code             => 'LINE'
2668          ,p_entity_id               => l_line_rec.line_id
2669          ,p_header_id               => l_line_rec.header_id
2670          ,p_line_id                 => l_line_rec.line_id
2671          ,p_order_source_id         => l_line_rec.order_source_id
2672          ,p_orig_sys_document_ref   => l_line_rec.orig_sys_document_ref
2673          ,p_orig_sys_document_line_ref  => l_line_rec.orig_sys_line_ref
2674          ,p_source_document_type_id     => l_line_rec.source_document_type_id
2675          ,p_source_document_id      => l_line_rec.source_document_id
2676          ,p_source_document_line_id => l_line_rec.source_document_line_id );
2677 
2678         IF OE_Code_Control.code_release_level >= '110510'
2679            AND  NVL(FND_PROFILE.VALUE('ONT_3A7_RESPONSE_REQUIRED'), 'N') = 'Y'
2680            -- Added this check because, holds will be applied only when this profile is set to 'YES'.
2681            AND  l_line_rec.order_source_id = OE_Acknowledgment_Pub.G_XML_ORDER_SOURCE_ID
2682            AND nvl(l_line_rec.xml_transaction_type_code, FND_API.G_MISS_CHAR)
2683                  IN (OE_Acknowledgment_Pub.G_TRANSACTION_CHO,OE_Acknowledgment_Pub.G_TRANSACTION_CPO) THEN -- 3A8/3A9
2684 
2685            IF l_debug_level  > 0 THEN
2686               oe_debug_pub.add(  'Calling OE_Acknowledgment_PUB.Process_3A8 for transaction type: '|| l_line_rec.xml_transaction_type_code, 2 ) ;
2687            END IF;
2688            OE_Acknowledgment_PUB.Process_3A8
2689                       (  p_x_line_rec           => l_line_rec
2690                       ,  p_old_line_rec         => l_old_line_rec
2691                       ,  x_return_status        => l_return_status
2692                       );
2693            IF l_debug_level  > 0 THEN
2694               oe_debug_pub.add(  'Return status after call to Process_3A8:' || l_return_status, 2 ) ;
2695            END IF;
2696 
2697            IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2698               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2699            ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
2700               RAISE FND_API.G_EXC_ERROR;
2701            END IF;
2702         END IF;
2703 
2704       END IF; -- if operation is create.
2705 
2706       IF l_debug_level  > 0 THEN
2707           oe_debug_pub.add(  'AT LINE LEVEL HEADER_ID' || L_LINE_REC.HEADER_ID , 2 ) ;
2708       END IF;
2709       IF I = p_x_line_tbl.FIRST THEN
2710         IF NOT Valid_Upgraded_Order(l_line_rec.header_id) THEN
2711           RAISE FND_API.G_EXC_ERROR;
2712         END IF;
2713       END IF;
2714 
2715       -- Lock the order header for unbooked orders: This would prevent order
2716       -- lines from being inserted on an order when it is being booked
2717       -- as the booking process also locks the order header.
2718       -- The g_booked_flag should have been set by the call to
2719       -- Valid_Upgraded_Order before.
2720 
2721       IF l_line_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
2722          -- QUOTING changes
2723          -- Comment out booked flag check, move header locked
2724          -- check inside this IF statement.
2725         IF l_header_locked = FND_API.G_MISS_CHAR THEN -- AND g_booked_flag = 'N' THEN #2940426
2726 
2727         -- Lock only if the po is called by UI or
2728         -- with write_to_db flag , this way for validate_only
2729         -- don't lock.
2730 
2731         IF (OE_GLOBALS.G_UI_FLAG  AND
2732           NOT (OE_GLOBALS.G_HTML_FLAG))  OR
2733           p_control_rec.write_to_db THEN
2734 
2735           IF l_debug_level  > 0 THEN
2736               oe_debug_pub.add(  'LOCKING THE HEADER RECORD' ) ;
2737           END IF;
2738 
2739           OE_Header_Util.Lock_Row
2740           ( p_header_id          => l_line_rec.header_id
2741            ,x_return_status      => l_return_status
2742            ,p_x_header_rec       => l_locked_header_rec);
2743 
2744           IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2745             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2746           ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
2747             RAISE FND_API.G_EXC_ERROR;
2748           END IF;
2749 
2750           l_header_locked := 'Y';
2751         END IF; -- UI flag
2752 
2753         END IF; -- if header locked check
2754 
2755         -- QUOTING changes
2756         -- Initialize line transaction phase from locked header rec
2757         l_line_rec.transaction_phase_code :=
2758                l_locked_header_rec.transaction_phase_code;
2759 
2760       END IF; -- opr = create and hdr locked etc.
2761 
2762 
2763       ------------- lines loop starts ------------------------------
2764 
2765       IF l_debug_level  > 0 THEN
2766           oe_debug_pub.add(  'ITEM TYPE :'||P_X_LINE_TBL ( I ) .ITEM_TYPE_CODE ) ;
2767       END IF;
2768 
2769       l_check_item_type := Check_Item_Type(l_line_rec,I);
2770 
2771       IF l_debug_level  > 0 THEN
2772           oe_debug_pub.add(  'CHECK_ITEM_TYPE RETURNS :'||L_CHECK_ITEM_TYPE ) ;
2773       END IF;
2774 
2775 
2776 
2777       IF (l_mode = 'MODELS_AND_STANDARD') AND
2778           l_check_item_type = 1 THEN
2779 
2780         IF l_debug_level  > 0 THEN
2781             oe_debug_pub.add(  'L_MODE IS MODELS_AND_STANDARD' , 1 ) ;
2782         END IF;
2783 
2784         IF OE_Config_Util.G_Config_UI_Used = 'N' AND
2785            l_line_rec.operation = OE_GLOBALS.G_OPR_CREATE AND
2786            ((l_line_rec.top_model_line_index is NOT NULL AND
2787              l_line_rec.top_model_line_index <> FND_API.G_MISS_NUM) OR
2788             (l_line_rec.top_model_line_id is NOT NULL AND
2789              l_line_rec.top_model_line_id <> FND_API.G_MISS_NUM)) AND
2790              (l_line_rec.split_from_line_id is NULL OR
2791               l_line_rec.split_from_line_id = FND_API.G_MISS_NUM)
2792         THEN
2793            -- bug 3286378
2794            IF l_line_rec.inventory_item_id IS NULL THEN
2795               IF l_debug_level  > 0 THEN
2796                  oe_debug_pub.add(  'No Item at the line' , 1 ) ;
2797               END IF;
2798               p_x_line_tbl(I).component_code := null;
2799               p_x_line_tbl(I).component_sequence_id := null;
2800               p_x_line_tbl(I).sort_order     := null;
2801            ELSIF NOT OE_GLOBALS.EQUAL(l_line_rec.inventory_item_id,
2802                                       l_old_line_rec.inventory_item_id) THEN
2803               IF l_debug_level  > 0 THEN
2804                  oe_debug_pub.add('Line Item is Changed '
2805                                    ||l_line_rec.inventory_item_id , 1 ) ;
2806               END IF;
2807 
2808               BEGIN
2809                 IF l_old_line_rec.inventory_item_id is NOT NULL THEN
2810                    SELECT bom_item_type
2811                    INTO   l_bom_item_type
2812                    FROM   mtl_system_items
2813                    WHERE  inventory_item_id = l_line_rec.inventory_item_id
2814                    AND    organization_id
2815                    = OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
2816 
2817                    IF l_debug_level  > 0 THEN
2818                      oe_debug_pub.add('old Line Item exists '
2819                                      ||l_bom_item_type, 1);
2820                    END IF;
2821 
2822                 ELSE
2823                    l_bom_item_type := 1;
2824                 END IF;
2825                  IF l_debug_level  > 0 THEN
2826                     oe_debug_pub.add('BOM ITEM TYPE : '||l_bom_item_type, 1);
2827                  END IF;
2828 
2829                  IF l_bom_item_type = 1 THEN
2830                     IF l_debug_level  > 0 THEN
2831                        oe_debug_pub.add(  'CALLING Complete_Config_Line' ,1);
2832                        oe_debug_pub.add
2833                        ('comp seq id '||l_line_rec.component_sequence_id,1);
2834                     END IF;
2835 
2836                     l_line_rec.component_code := null;
2837                     l_line_rec.component_sequence_id := null;
2838                     l_line_rec.sort_order     := null;
2839 
2840                     Complete_Config_Line
2841                       ( p_x_line_rec     =>  l_line_rec
2842                        ,p_item_type      =>  1
2843                        ,p_x_line_tbl     =>  p_x_line_tbl);
2844 
2845                     p_x_line_tbl(I).component_code
2846                          := l_line_rec.component_code;
2847                     p_x_line_tbl(I).component_sequence_id
2848                          := l_line_rec.component_sequence_id;
2849                     p_x_line_tbl(I).sort_order     := l_line_rec.sort_order;
2850                  ELSE
2851                     IF l_debug_level  > 0 THEN
2852                       oe_debug_pub.add(  'Setting Component code to Null',1);
2853                     END IF;
2854                     p_x_line_tbl(I).component_code := null;
2855                     p_x_line_tbl(I).component_sequence_id := null;
2856                     p_x_line_tbl(I).sort_order     := null;
2857                  END IF;
2858               EXCEPTION
2859                  WHEN OTHERS THEN
2860                     IF l_debug_level  > 0 THEN
2861                        oe_debug_pub.add(  'Did not get any bom item type',1);
2862                     END IF;
2863                     --RAISE FND_API.G_EXC_ERROR;
2864                     RAISE;
2865               END;
2866            END IF;
2867         END IF;
2868 
2869         l_process_this_line := TRUE;
2870 
2871       END IF; -- mode is standard.
2872 
2873 
2874       ----------------------  mode is options ----------------------
2875       IF (l_mode = 'OPTIONS') AND
2876           l_check_item_type = 2 THEN
2877 
2878         IF l_debug_level  > 0 THEN
2879             oe_debug_pub.add(  'L_MODE IS OPTIONS' , 1 ) ;
2880         END IF;
2881 
2882         IF nvl(l_line_rec.semi_processed_flag, FALSE) = TRUE THEN
2883           IF l_debug_level  > 0 THEN
2884               oe_debug_pub.add(  'LINE IS ALREADY PROCESSED , GOTO END..' , 1 ) ;
2885           END IF;
2886           GOTO end_of_lines_loop;
2887         END IF;
2888 
2889         l_process_this_line := TRUE;
2890 
2891         -- If the line has top_model_line_index, populate it's
2892         -- top_model_line_id from p_x_line_tbl(top_model_line_index).line_id
2893         -- note that the top most model line will get its top_model_line_id in
2894         -- hardcoded defaulting and since we process models before options,
2895         -- model should already have the top model line id.
2896 
2897         IF ((l_line_rec.top_model_line_index <> FND_API.G_MISS_NUM) AND
2898             (l_line_rec.top_model_line_index IS NOT NULL))
2899         THEN
2900           l_top_model_line_index := l_line_rec.top_model_line_index;
2901 
2902           IF p_x_line_tbl.EXISTS(l_top_model_line_index) THEN
2903 
2904             IF (l_line_rec.top_model_line_id = FND_API.G_MISS_NUM) OR
2905                (l_line_rec.top_model_line_id IS NULL) THEN
2906 
2907               IF l_debug_level  > 0 THEN
2908                   oe_debug_pub.add(  'MODEL:'||P_X_LINE_TBL ( L_TOP_MODEL_LINE_INDEX ) .RETURN_STATUS ) ;
2909               END IF;
2910 
2911 
2912               IF p_x_line_tbl(l_top_model_line_index).return_status =
2913                            FND_API.G_RET_STS_SUCCESS THEN
2914 
2915                 l_line_rec.top_model_line_id :=
2916                            p_x_line_tbl(l_top_model_line_index).line_id;
2917 
2918                 p_x_line_tbl(I).top_model_line_id := l_line_rec.top_model_line_id;
2919 
2920               ELSE
2921                 IF p_x_line_tbl(l_top_model_line_index).return_status IS NULL
2922                 THEN
2923                   IF l_debug_level  > 0 THEN
2924                       oe_debug_pub.add(  'TOP MODEL RETURN STATUS IS NULL' , 1 ) ;
2925                   END IF;
2926                 END IF;
2927 
2928                 IF l_debug_level  > 0 THEN
2929                     oe_debug_pub.add(  'TOP MODEL LINE PROCESSED WITH ERRORS' , 1 ) ;
2930                 END IF;
2931 
2932                 GOTO end_of_lines_loop;
2933               END IF; -- ret sts success
2934 
2935             END IF;
2936 
2937 
2938           ELSE -- Invalid Index
2939             IF l_debug_level  > 0 THEN
2940                 oe_debug_pub.add(  'INVALID LINE INDEX ' , 2 ) ;
2941             END IF;
2942             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2943           END IF;  -- if valid index, top model is not at the index
2944 
2945         ELSE
2946           IF l_debug_level  > 0 THEN
2947               oe_debug_pub.add(  'MODE IS OPTIONS BUT NO TOP MODEL LINE INDEX??' , 1 ) ;
2948           END IF;
2949         END IF; -- if top model line index is populated
2950 
2951         -- if it comes here, everything was OK. ---------
2952 
2953         IF l_line_rec.operation = OE_GLOBALS.G_OPR_CREATE AND
2954            (nvl(l_line_rec.item_type_code, 'A') <> OE_GLOBALS.G_ITEM_INCLUDED
2955             AND
2956             nvl(l_line_rec.item_type_code, 'A') <> OE_GLOBALS.G_ITEM_CONFIG)
2957         THEN
2958 
2959           IF COMPLETE_AND_CLASS_SAVE_MODE THEN
2960 
2961             IF OE_Config_Util.G_Config_UI_Used = 'N' AND
2962                (l_line_rec.split_from_line_id is NULL OR
2963                 l_line_rec.split_from_line_id = FND_API.G_MISS_NUM) AND
2964                (l_line_rec.top_model_line_index is NOT NULL AND
2965                 l_line_rec.top_model_line_index <> FND_API.G_MISS_NUM)
2966             THEN
2967 
2968               Complete_Config_Line
2969               ( p_x_line_rec       =>  l_line_rec
2970                ,p_item_type        =>  2
2971                ,p_x_line_tbl       =>  p_x_line_tbl
2972                ,p_process_partial  =>  p_control_rec.process_partial);
2973 
2974                p_x_line_tbl(I).component_code := l_line_rec.component_code;
2975                p_x_line_tbl(I).component_sequence_id
2976                                        := l_line_rec.component_sequence_id;
2977                p_x_line_tbl(I).sort_order     := l_line_rec.sort_order;
2978                p_x_line_tbl(I).order_quantity_uom
2979                                        := l_line_rec.order_quantity_uom;
2980                p_x_line_tbl(I).operation      := l_line_rec.operation;
2981                p_x_line_tbl(I).return_status  := l_line_rec.return_status;
2982 
2983             END IF;
2984 
2985             IF nvl(l_line_rec.item_type_code, 'A') <> OE_GLOBALS.G_ITEM_CLASS
2986             THEN
2987               IF l_debug_level  > 0 THEN
2988                   oe_debug_pub.add(  'NOT A CLASS , SKIP' , 3 ) ;
2989               END IF;
2990 
2991               IF l_line_rec.split_from_line_id is NULL THEN
2992                 J := J + 1;
2993                 l_options_index_tbl(J) := I;
2994               END IF;
2995 
2996               l_process_this_line   := FALSE;
2997             END IF;
2998 
2999           ELSE -- now saving options -- may not req.
3000 
3001             IF nvl(l_line_rec.item_type_code, 'A') = OE_GLOBALS.G_ITEM_CLASS
3002             THEN
3003               IF l_debug_level  > 0 THEN
3004                   oe_debug_pub.add(  'THIS CLASS IS ALREADY SAVED' , 3 ) ;
3005               END IF;
3006               l_process_this_line   := FALSE;
3007             END IF;
3008 
3009           END IF; -- complete mode check
3010 
3011         END IF; -- operation = create
3012 
3013         -- this is important in case of the recursive calls.
3014 
3015         IF l_line_rec.top_model_line_id is NOT NULL THEN
3016           l_line_rec.top_model_line_index       := NULL;
3017           p_x_line_tbl(I).top_model_line_index  := NULL;
3018         END IF;
3019       END IF; -- if mode is option
3020 
3021 
3022       ----------------------  mode is service ----------------------
3023 
3024       IF (l_mode = 'SERVICE') AND
3025           l_check_item_type = 3 THEN
3026 
3027         IF l_debug_level  > 0 THEN
3028             oe_debug_pub.add(  'JPN: MODE IS SERVICE' ) ;
3029         END IF;
3030         l_process_this_line := TRUE;
3031 
3032         IF  ((l_line_rec.service_line_index <> FND_API.G_MISS_NUM) AND
3033              (l_line_rec.service_line_index IS NOT NULL))
3034         THEN
3035           l_service_line_index := l_line_rec.service_line_index;
3036 
3037           -- If the line has service_line_index, populate it's
3038           -- service_reference_line_id from the
3039           -- p_x_line_tbl(service_line_index).line_id
3040 
3041           IF p_x_line_tbl.EXISTS(l_service_line_index) THEN
3042             IF (l_line_rec.service_reference_line_id = FND_API.G_MISS_NUM)
3043                 OR (l_line_rec.service_reference_line_id IS NULL) THEN
3044 
3045               IF p_x_line_tbl(l_service_line_index).return_status =
3046                 FND_API.G_RET_STS_SUCCESS THEN
3047             -- lchen added to check parent line operation to fix bug 2017271
3048                  IF p_x_line_tbl(l_service_line_index).operation = OE_GLOBALS.G_OPR_NONE
3049                  THEN
3050                    GOTO end_of_lines_loop;
3051                  ELSE
3052                 l_line_rec.service_reference_line_id :=
3053                                p_x_line_tbl(l_service_line_index).line_id;
3054                   END IF; /* operation = none */
3055 
3056               ELSE
3057                 GOTO end_of_lines_loop;
3058               END IF;
3059 
3060             END IF;
3061           ELSE -- Invalid Index
3062             IF l_debug_level  > 0 THEN
3063                 oe_debug_pub.add(  'INVALID SERVICE LINE INDEX ' , 2 ) ;
3064             END IF;
3065             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3066           END IF;  -- If Valid Line Index
3067 
3068         END IF;
3069 
3070       END IF; -- end of service.
3071 
3072 
3073 
3074       IF l_process_this_line = FALSE THEN
3075 
3076         IF l_debug_level  > 0 THEN
3077             oe_debug_pub.add(  'MODE AND ITEM TYPE DOES NOT MATCH , GO TO END' , 1 ) ;
3078         END IF;
3079 
3080         l_line_rec.semi_processed_flag      := FALSE;
3081         p_x_line_tbl(I).semi_processed_flag := FALSE;
3082         GOTO end_of_lines_loop;
3083 
3084       ELSE
3085 
3086         l_line_rec.semi_processed_flag      := TRUE;
3087         p_x_line_tbl(I).semi_processed_flag := TRUE;
3088         l_num_lines                         := l_num_lines - 1;
3089         IF l_debug_level  > 0 THEN
3090             oe_debug_pub.add(  L_NUM_LINES|| ' '||L_LINE_REC.ITEM_TYPE_CODE||L_LINE_REC.LINE_ID , 1 ) ;
3091         END IF;
3092 
3093       END IF; -- to process the line or not
3094 
3095 
3096 
3097       --  Load old records.
3098 
3099                         IF l_debug_level  > 0 THEN
3100                             oe_debug_pub.add(  'STARTING LINE LOOP. HEADER_ID = '|| TO_CHAR ( L_LINE_REC.HEADER_ID ) , 2 ) ;
3101                         END IF;
3102 
3103       --  Load API control record
3104 
3105       l_control_rec := OE_GLOBALS.Init_Control_Rec
3106                       ( p_operation     => l_line_rec.operation
3107                        ,p_control_rec   => p_control_rec);
3108 
3109 
3110       OE_LINE_UTIL.Pre_Attribute_Security(p_x_line_rec   => l_line_rec
3111                                          ,p_old_line_rec => l_old_line_rec
3112                                          ,p_index        => I  );
3113 
3114       -- CHECK SECURITY
3115 
3116       IF l_control_rec.check_security AND
3117          (l_line_rec.operation = OE_GLOBALS.G_OPR_CREATE OR
3118           l_line_rec.operation = OE_GLOBALS.G_OPR_UPDATE)
3119       THEN
3120 
3121         IF l_debug_level  > 0 THEN
3122             oe_debug_pub.add(  'CHECK ATTRIBUTES SECURITY' , 1 ) ;
3123         END IF;
3124         -- check if this operation is allowed on all the changed attributes
3125         OE_Line_Security.Attributes
3126         ( p_line_rec        => l_line_rec
3127          ,p_old_line_rec    => l_old_line_rec
3128          ,x_result          => l_sec_result
3129          ,x_return_status   => l_return_status);
3130 
3131         IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3132           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3133         ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3134           RAISE FND_API.G_EXC_ERROR;
3135         END IF;
3136 
3137         -- if operation on any attribute is constrained
3138         IF l_sec_result = OE_PC_GLOBALS.YES THEN
3139           RAISE FND_API.G_EXC_ERROR;
3140         END IF;
3141 
3142       END IF; -- security
3143 
3144 
3145       -- ATTRIBUTE LEVEL VALIDATION
3146 
3147       IF NOT (l_line_rec.operation = oe_globals.g_opr_create and
3148              (l_line_rec.split_from_line_id IS NOT NULL AND
3149               l_line_rec.split_from_line_id <> FND_API.G_MISS_NUM))
3150       THEN
3151 
3152         IF l_debug_level  > 0 THEN
3153             oe_debug_pub.add(  'ATTRIBUTE VALIDATION' , 1 ) ;
3154         END IF;
3155 
3156         IF p_validation_level > FND_API.G_VALID_LEVEL_NONE THEN
3157 
3158           OE_Validate_Line.Attributes
3159           ( x_return_status               => l_return_status
3160            ,p_x_line_rec                  => l_line_rec
3161            ,p_old_line_rec                => l_old_line_rec
3162            ,p_validation_level            => p_validation_level);
3163 
3164           IF l_debug_level  > 0 THEN
3165               oe_debug_pub.add(  'AFTER ATTRIBUTE VALIDATION' , 1 ) ;
3166           END IF;
3167 
3168           IF p_validation_level <> OE_GLOBALS.G_VALID_LEVEL_PARTIAL THEN
3169             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3170               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3171             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3172               RAISE FND_API.G_EXC_ERROR;
3173             END IF;
3174           END IF;
3175 
3176         END IF; -- end of check to see if validation level > NONE
3177 
3178       END IF; -- validation
3179 
3180 
3181       --  CLEAR DEPENDENT ATTRIBUTES
3182 
3183       IF  l_control_rec.clear_dependents AND
3184       NOT (l_line_rec.operation = oe_globals.g_opr_create and
3185           (l_line_rec.split_from_line_id IS NOT NULL AND
3186            l_line_rec.split_from_line_id <> FND_API.G_MISS_NUM))
3187       THEN
3188 
3189         IF l_debug_level  > 0 THEN
3190             oe_debug_pub.add(  'CLEAR DEPENDENT ATTRIBUTES' , 1 ) ;
3191         END IF;
3192 
3193         OE_Line_Util_Ext.Clear_Dependent_Attr
3194         ( p_x_line_rec                  => l_line_rec
3195          ,p_old_line_rec                => l_old_line_rec );
3196 
3197       END IF;
3198 
3199 
3200       --  DEFAULT MISSING ATTRIBUTES
3201 
3202       IF (l_control_rec.default_attributes) THEN
3203         IF NOT (l_line_rec.operation = oe_globals.g_opr_create and
3204                (l_line_rec.split_from_line_id IS NOT NULL AND
3205                 l_line_rec.split_from_line_id <> FND_API.G_MISS_NUM))
3206         THEN
3207 
3208           IF l_debug_level  > 0 THEN
3209               oe_debug_pub.add(  'DEFAULT MISSING' , 1 ) ;
3210           END IF;
3211 
3212           OE_Default_Line.Attributes
3213           ( p_x_line_rec                  => l_line_rec
3214            ,p_old_line_rec                => l_old_line_rec);
3215 
3216         ELSE
3217 
3218           IF l_debug_level  > 0 THEN
3219               oe_debug_pub.add(  'SPLIT:DEFAULT ATTRIBUTES ' , 1 ) ;
3220           END IF;
3221           OE_Split_Util.Default_Attributes
3222           ( p_x_line_rec                  => l_line_rec
3223            ,p_old_line_rec                => l_old_line_rec);
3224 
3225         END IF;
3226 
3227       END IF; -- default missing
3228 
3229 
3230       -- APPLY ATTRIBUTE CHANGES
3231 
3232       IF  (l_control_rec.change_attributes)
3233            -- AND NOT (l_line_rec.operation = oe_globals.g_opr_create and
3234            --  (l_line_rec.split_from_line_id IS NOT NULL AND
3235            --  l_line_rec.split_from_line_id <> FND_API.G_MISS_NUM))
3236       THEN
3237 
3238         IF l_debug_level  > 0 THEN
3239             oe_debug_pub.add(  'APPLY ATTRIBUTE CHANGES' , 2 ) ;
3240         END IF;
3241 
3242         OE_Line_Util.Apply_Attribute_Changes
3243         ( p_x_line_rec                  => l_line_rec
3244          ,p_old_line_rec                => l_old_line_rec );
3245 
3246         IF l_line_rec.return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3247           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3248         ELSIF l_line_rec.return_status = FND_API.G_RET_STS_ERROR THEN
3249           RAISE FND_API.G_EXC_ERROR;
3250         END IF;
3251       END IF;
3252 
3253 
3254       --  Entity level validation.
3255 
3256       IF l_control_rec.validate_entity
3257          AND NOT (l_line_rec.operation = oe_globals.g_opr_create and
3258                  (l_line_rec.split_from_line_id IS NOT NULL AND
3259                   l_line_rec.split_from_line_id <> FND_API.G_MISS_NUM))
3260          and l_line_rec.ordered_quantity<>0 -- added for bug 6494347
3261 
3262       THEN
3263 
3264         IF l_debug_level  > 0 THEN
3265             oe_debug_pub.add(  'VALIDATE ENTITY' , 2 ) ;
3266         END IF;
3267 
3268         IF l_line_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
3269 
3270           OE_Validate_Line.Entity_Delete
3271           ( x_return_status               => l_return_status
3272            ,p_line_rec                    => l_line_rec );
3273 
3274         ELSE
3275 
3276           OE_Validate_Line.Entity
3277           ( x_return_status               => l_return_status
3278            ,p_line_rec                    => l_line_rec
3279            ,p_old_line_rec                => l_old_line_rec
3280            ,p_validation_level            => p_validation_level);
3281 
3282         END IF;
3283 
3284         IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3285           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3286         ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3287           RAISE FND_API.G_EXC_ERROR;
3288         END IF;
3289 
3290       END IF; -- entity validation
3291 
3292 
3293       -- Fixed bug 1647143: Entity security check should be before
3294       -- pre_write_process. This is important for DELETEs as the
3295       -- constraints check should fire before other events like
3296       -- unscheduling are fired in pre_write_process
3297 
3298       -- Check entity level security as some attributes may have
3299       -- changed due to defaulting or scheduling
3300       -- For UPDATE operations, entity security checks for constraints setup
3301       -- with a NULL column i.e. the constraint restricts update on ANY of
3302       -- the columns.
3303       -- However, this check should NOT be done if user did not try to update
3304       -- any of the constrainable attributes and also none of the defaulted
3305       -- attributes was constrainable!. In such a case, the g_check_all_cols
3306       -- _constraint flag would still be 'Y' as the flag is reset only
3307       -- when checking for constraints.
3308 
3309       IF NOT (l_line_rec.operation  = OE_GLOBALS.G_OPR_UPDATE AND
3310          OE_Line_Security.g_check_all_cols_constraint = 'Y') AND
3311          l_control_rec.check_security THEN
3312 
3313         IF l_debug_level  > 0 THEN
3314             oe_debug_pub.add(  'CHECK ENTITY SECURITY' , 2 ) ;
3315         END IF;
3316 
3317         OE_Line_Security.Entity
3318         ( p_line_rec        => l_line_rec
3319          ,x_result          => l_sec_result
3320          ,x_return_status   => l_return_status );
3321 
3322         IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3323           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3324         ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3325           RAISE FND_API.G_EXC_ERROR;
3326         END IF;
3327 
3328         -- if operation on any attribute is constrained
3329         IF l_sec_result = OE_PC_GLOBALS.YES THEN
3330           RAISE FND_API.G_EXC_ERROR;
3331         END IF;
3332 
3333       END IF;
3334 
3335 
3336       IF l_debug_level  > 0 THEN
3337           oe_debug_pub.add(  'STATUS' || L_LINE_REC.SCHEDULE_STATUS_CODE , 1 ) ;
3338       END IF;
3339 
3340       --  Step 3.5. Perform action which need to be performed before
3341       --            writing to the DB (like Scheduling).
3342 
3343       IF l_control_rec.write_to_db THEN
3344 
3345         OE_LINE_UTIL.PRE_WRITE_PROCESS
3346         ( p_x_line_rec      => l_line_rec
3347          , p_old_line_rec    => l_old_line_rec);
3348       END IF;
3349 
3350       --  Step 4. Write to DB
3351 
3352       IF l_control_rec.write_to_db THEN
3353          IF l_debug_level  > 0 THEN
3354              oe_debug_pub.add(  'WRITE TO DB' , 1 ) ;
3355          END IF;
3356 
3357         IF l_line_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
3358            OE_Line_Util.Delete_Row
3359           ( p_line_id   => l_line_rec.line_id);
3360 
3361           -- If an OTA line has been deleted, then call the OTA API
3362           -- to delete the event in the OTA tables
3363 
3364           l_order_quantity_uom := l_line_rec.order_quantity_uom;
3365           l_is_ota_line     := OE_OTA_UTIL.Is_OTA_Line(l_order_quantity_uom);
3366 
3367           If (l_is_ota_line) THEN
3368             IF l_debug_level  > 0 THEN
3369                 oe_debug_pub.add(  'LINE IS OF OTA TYPE' , 1 ) ;
3370             END IF;
3371             OE_OTA_UTIL.Notify_OTA
3372             ( p_line_id            => l_line_rec.line_id
3373              ,p_org_id             => l_line_rec.org_id
3374              ,p_order_quantity_uom => l_order_quantity_uom
3375              ,p_daemon_type        => 'D'
3376              ,x_return_status      => l_return_status );
3377 
3378             IF l_debug_level  > 0 THEN
3379                 oe_debug_pub.add(  'AFTER NOTIFY_OTA API' , 1 ) ;
3380             END IF;
3381             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3382               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3383             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3384               RAISE FND_API.G_EXC_ERROR;
3385             END IF;
3386           END IF; --End of OTA processing
3387 
3388         ELSE -- operation is update or create
3389 
3390           --  Get Who Information
3391 
3392           l_line_rec.last_update_date    := SYSDATE;
3393           l_line_rec.last_updated_by     :=  NVL(OE_STANDARD_WF.g_user_id, FND_GLOBAL.USER_ID); -- 3169637
3394           l_line_rec.last_update_login   := FND_GLOBAL.LOGIN_ID;
3395           l_user_id                      := NVL(OE_STANDARD_WF.g_user_id, FND_GLOBAL.USER_ID); -- 3169637
3396           l_resp_id                      := FND_GLOBAL.RESP_ID;
3397           l_application_id               := FND_GLOBAL.RESP_APPL_ID;
3398 
3399           IF l_line_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
3400             IF l_debug_level  > 0 THEN
3401                 oe_debug_pub.add(  'CALLING UPDATE ROW' , 1 ) ;
3402             END IF;
3403 
3404             OE_Line_Util.Update_Row (l_line_rec);
3405 
3406           ELSIF l_line_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
3407 
3408             l_line_rec.creation_date       := SYSDATE;
3409             l_line_rec.created_by          := NVL(OE_STANDARD_WF.g_user_id, FND_GLOBAL.USER_ID); -- 3169637
3410 
3411             IF l_debug_level  > 0 THEN
3412                 oe_debug_pub.add(  '3.STATUS '||L_LINE_REC.SCHEDULE_STATUS_CODE , 1 ) ;
3413             END IF;
3414 
3415             OE_Line_Util.Insert_Row (l_line_rec);
3416 
3417           END IF;
3418 
3419         END IF; -- operation = delete
3420 
3421         -- Post Db Processes
3422         Oe_Line_Util.Post_Write_Process
3423         (p_x_line_rec      => l_line_rec,
3424          p_old_line_rec    => l_old_line_rec );
3425 
3426       END IF; -- write to db true
3427 
3428       --  loop exception handler.
3429       IF l_line_rec.return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3430         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3431       ELSIF l_line_rec.return_status = FND_API.G_RET_STS_ERROR THEN
3432         RAISE FND_API.G_EXC_ERROR;
3433       END IF;
3434 
3435       --  Load tables.
3436 
3437       l_line_rec.return_status            := FND_API.G_RET_STS_SUCCESS;
3438       p_x_line_tbl(I)                     := l_line_rec;
3439       p_x_old_line_tbl(I)                 := l_old_line_rec;
3440       p_x_line_tbl(I).semi_processed_flag := l_process_this_line;
3441 
3442       IF p_x_line_tbl(I).semi_processed_flag THEN
3443         IF l_debug_level  > 0 THEN
3444             oe_debug_pub.add(  I || ' SEMI PROCESSED FLAG SET ' , 1 ) ;
3445         END IF;
3446       END IF;
3447 
3448       IF l_debug_level  > 0 THEN
3449           oe_debug_pub.add(  'BOTTOM OF LINE LOOP' , 2 ) ;
3450       END IF;
3451 
3452       OE_Line_Security.g_check_all_cols_constraint := 'Y';
3453       OE_MSG_PUB.reset_msg_context('LINE');
3454 
3455       IF l_debug_level  > 0 THEN
3456           oe_debug_pub.add(  'SCH ARRIVAL_DATE='||L_LINE_REC.SCHEDULE_ARRIVAL_DATE ) ;
3457       END IF;
3458 
3459     EXCEPTION
3460 
3461       WHEN FND_API.G_EXC_ERROR THEN
3462 
3463         x_return_status:= FND_API.G_RET_STS_ERROR;
3464         l_line_rec.return_status            := FND_API.G_RET_STS_ERROR;
3465         p_x_line_tbl(I)                     := l_line_rec;
3466         p_x_line_tbl(I).semi_processed_flag := l_process_this_line;
3467         p_x_old_line_tbl(I)                 := l_old_line_rec;
3468 
3469         OE_Line_Security.g_check_all_cols_constraint := 'Y';
3470 
3471         -- if process partial flag is set to true this would
3472         -- continue processing else exit out of loop
3473 
3474         IF l_control_rec.Process_Partial THEN
3475 
3476           -- Raise error when one of the lines in a SET fails
3477           -- while copying.
3478           IF l_line_rec.source_document_type_id = 2 AND
3479              l_line_rec.line_set_id IS NOT NULL AND
3480              l_line_rec.OPERATION = OE_GLOBALS.G_OPR_CREATE
3481           THEN
3482               RAISE FND_API.G_EXC_ERROR;
3483           END IF;
3484 
3485 
3486           IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
3487             IF l_debug_level  > 0 THEN
3488                 oe_debug_pub.add(  'DELETE REQUEST8' , 2 ) ;
3489             END IF;
3490 
3491             oe_delayed_requests_pvt.Delete_Reqs_for_Deleted_Entity
3492             (p_entity_code   => OE_GLOBALS.G_ENTITY_LINE,
3493              p_entity_id     => l_line_rec.line_id,
3494              x_return_status => l_return_status);
3495           END IF;
3496 
3497           ROLLBACK TO SAVEPOINT Lines;
3498 
3499         ELSE
3500           RAISE FND_API.G_EXC_ERROR ;
3501         END IF; -- process partial = true
3502 
3503 
3504       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3505 
3506         x_return_status:= FND_API.G_RET_STS_UNEXP_ERROR;
3507         l_line_rec.return_status            := FND_API.G_RET_STS_UNEXP_ERROR;
3508         p_x_line_tbl(I)                     := l_line_rec;
3509         p_x_line_tbl(I).semi_processed_flag := l_process_this_line;
3510         p_x_old_line_tbl(I)                 := l_old_line_rec;
3511 
3512 
3513         OE_MSG_PUB.reset_msg_context('LINE');
3514         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3515 
3516 
3517       WHEN OTHERS THEN
3518 
3519         x_return_status                := FND_API.G_RET_STS_UNEXP_ERROR;
3520         l_line_rec.return_status       := FND_API.G_RET_STS_UNEXP_ERROR;
3521         p_x_line_tbl(I)                := l_line_rec;
3522         p_x_line_tbl(I).semi_processed_flag := l_process_this_line;
3523         p_x_old_line_tbl(I)            := l_old_line_rec;
3524 
3525 
3526         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3527         THEN
3528           OE_MSG_PUB.Add_Exc_Msg
3529           (   G_PKG_NAME
3530              ,'Lines' );
3531         END IF;
3532 
3533         OE_Line_Security.g_check_all_cols_constraint := 'Y';
3534         OE_MSG_PUB.reset_msg_context('LINE');
3535         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3536 
3537     END; -- of the big BEGIN with the WHILE
3538 
3539 
3540 
3541     ---------------- switch modes ---------------------------
3542 
3543     <<end_of_lines_loop>>
3544 
3545     IF l_debug_level  > 0 THEN
3546         oe_debug_pub.add(  'NO. OF LINES TO PROCESS ' || L_NUM_LINES , 1 ) ;
3547     END IF;
3548 
3549     I := p_x_line_tbl.NEXT(I);
3550 
3551     IF (l_mode = 'MODELS_AND_STANDARD') AND (I IS NULL)
3552     THEN
3553        I := p_x_line_tbl.FIRST;
3554        l_mode := 'OPTIONS';
3555        COMPLETE_AND_CLASS_SAVE_MODE := TRUE;
3556 
3557     ELSIF (l_mode = 'OPTIONS')AND (I IS NULL)
3558     THEN
3559 
3560        I := p_x_line_tbl.FIRST;
3561 
3562        IF l_debug_level  > 0 THEN
3563            oe_debug_pub.add(  'NO. OF SKIPPED OPTIONS ' || L_OPTIONS_INDEX_TBL.COUNT , 1 ) ;
3564        END IF;
3565 
3566        IF COMPLETE_AND_CLASS_SAVE_MODE AND l_num_lines > 0 THEN
3567 
3568          IF l_debug_level  > 0 THEN
3569              oe_debug_pub.add(  'COMPLETE MODE WAS TRUE' , 3 ) ;
3570          END IF;
3571          COMPLETE_AND_CLASS_SAVE_MODE := FALSE;
3572 
3573          IF OE_Config_Util.G_Config_UI_Used = 'N' AND
3574             l_options_index_tbl.COUNT > 0
3575          THEN
3576 
3577            Get_Missing_Class_Lines
3578            ( p_x_line_tbl          => p_x_line_tbl
3579             ,p_options_index_tbl   => l_options_index_tbl
3580             ,x_class_index         => l_class_index
3581             ,x_class_count         => l_class_count);
3582 
3583            l_options_index_tbl.DELETE;
3584 
3585            IF l_class_index is NOT NULL THEN
3586               IF l_debug_level  > 0 THEN
3587                   oe_debug_pub.add(  'NEW CLASSES ADDED' , 3 ) ;
3588               END IF;
3589 
3590               COMPLETE_AND_CLASS_SAVE_MODE := TRUE;
3591 
3592               l_num_lines := l_num_lines + l_class_count;
3593               I := l_class_index;
3594            END IF;
3595 
3596          END IF;
3597        ELSE
3598          IF l_debug_level  > 0 THEN
3599              oe_debug_pub.add(  'MODE IS SERVICE NOW' , 3 ) ;
3600          END IF;
3601          l_mode := 'SERVICE';
3602        END IF;
3603 
3604     END IF; -- end mode switch
3605 
3606   END LOOP; -- end of the big WHILE LOOP
3607 
3608 
3609   -- New event has been created to handle post line loop issues.
3610 
3611   OE_LINE_UTIL.Post_Line_Process
3612   (p_control_rec   => l_control_rec,
3613    p_x_line_tbl    => p_x_line_tbl);
3614 
3615 
3616   Print_Time('Exiting OE_ORDER_PVT.LINES');
3617 
3618   OE_MSG_PUB.reset_msg_context('LINE');
3619 
3620   set_recursion_mode(p_Entity_Code => 5,
3621                                    p_In_out  => 0);
3622 
3623 EXCEPTION
3624 
3625   WHEN FND_API.G_EXC_ERROR THEN
3626     OE_SET_UTIL.G_SET_TBL.delete; --bug#2428456
3627     OE_SET_UTIL.G_SET_OPT_TBL.delete; -- bug#2428456
3628     x_return_status  := FND_API.G_RET_STS_ERROR;
3629     set_recursion_mode(p_Entity_Code => 5,
3630                                    p_In_out  => 0);
3631     OE_MSG_PUB.reset_msg_context('LINE');
3632 
3633 
3634     IF NOT (OE_GLOBALS.G_UI_FLAG) AND line_ctr = 1 THEN
3635       IF l_debug_level  > 0 THEN
3636           oe_debug_pub.add(  'DELETE REQUEST9' , 2 ) ;
3637       END IF;
3638       oe_delayed_requests_pvt.Clear_Request
3639       (x_return_status => l_return_status);
3640 
3641        IF OE_Config_Pvt.OE_MODIFY_INC_ITEMS_TBL.COUNT > 0 THEN --  for the bug 3726337
3642                 OE_Config_Pvt.OE_MODIFY_INC_ITEMS_TBL.DELETE;
3643                 END IF;
3644        ROLLBACK TO SAVEPOINT Lines_Non_Partial;
3645 	-- Bug 2801876
3646 	-- This condition would be  true only when the process order
3647         -- is called with proecs partial flag and the error comes out
3648 	-- of the post line process. This is same as an error coming
3649         -- out of delayed requests and hence we should raise and not continue.
3650 
3651 	IF l_control_rec.Process_Partial THEN
3652 	RAISE FND_API.G_EXC_ERROR;
3653 	END IF;
3654 
3655     END IF;
3656 
3657   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3658     OE_SET_UTIL.G_SET_TBL.delete; --bug#2428456
3659     OE_SET_UTIL.G_SET_OPT_TBL.delete; -- bug#2428456
3660     x_return_status  := FND_API.G_RET_STS_UNEXP_ERROR;
3661     set_recursion_mode(p_Entity_Code => 5,
3662                                    p_In_out  => 0);
3663 
3664     OE_MSG_PUB.reset_msg_context('LINE');
3665 
3666     IF NOT (OE_GLOBALS.G_UI_FLAG) and line_ctr = 1 THEN
3667       IF l_debug_level  > 0 THEN
3668           oe_debug_pub.add(  'DELETE REQUEST10' , 2 ) ;
3669       END IF;
3670       oe_delayed_requests_pvt.Clear_Request
3671       (x_return_status => l_return_status);
3672 
3673        IF OE_Config_Pvt.OE_MODIFY_INC_ITEMS_TBL.COUNT > 0 THEN --  for the bug 3726337
3674                 OE_Config_Pvt.OE_MODIFY_INC_ITEMS_TBL.DELETE;
3675                 END IF;
3676       ROLLBACK TO SAVEPOINT Lines_Non_Partial;
3677 
3678 	-- Same as comments give above for exc error
3679 	-- Bug 2801876
3680 
3681 	IF l_control_rec.Process_Partial THEN
3682     	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3683 	END IF;
3684 
3685     END IF;
3686 
3687   WHEN OTHERS THEN
3688     OE_SET_UTIL.G_SET_TBL.delete; --bug#2428456
3689     OE_SET_UTIL.G_SET_OPT_TBL.delete; -- bug#2428456
3690     x_return_status  := FND_API.G_RET_STS_UNEXP_ERROR;
3691 
3692     IF NOT (OE_GLOBALS.G_UI_FLAG) and line_ctr = 1 THEN
3693       IF l_debug_level  > 0 THEN
3694           oe_debug_pub.add(  'DELETE REQUEST11' , 2 ) ;
3695       END IF;
3696       oe_delayed_requests_pvt.Clear_Request
3697       (x_return_status => l_return_status);
3698 
3699       IF OE_Config_Pvt.OE_MODIFY_INC_ITEMS_TBL.COUNT > 0 THEN -- for the bug 3726337
3700 	 OE_Config_Pvt.OE_MODIFY_INC_ITEMS_TBL.DELETE;
3701       END IF;
3702       ROLLBACK TO SAVEPOINT Lines_Non_Partial;
3703     END IF;
3704     set_recursion_mode(p_Entity_Code => 5,
3705                                    p_In_out  => 0);
3706 
3707     IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3708     THEN
3709       OE_MSG_PUB.Add_Exc_Msg
3710       ( G_PKG_NAME
3711        ,'Lines');
3712     END IF;
3713 
3714     OE_MSG_PUB.reset_msg_context('LINE');
3715     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3716 
3717 END Lines;
3718 
3719 
3720 /*----------------------------------------------------------------------
3721 PROCEDURE Line_Scredits
3722 -----------------------------------------------------------------------*/
3723 
3724 PROCEDURE Line_Scredits
3725 (   p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
3726 ,   p_validation_level              IN  NUMBER
3727 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
3728 ,   p_x_Line_Scredit_tbl            IN OUT NOCOPY  OE_Order_PUB.Line_Scredit_Tbl_Type
3729 ,   p_x_old_Line_Scredit_tbl        IN OUT NOCOPY  OE_Order_PUB.Line_Scredit_Tbl_Type
3730 , x_return_status OUT NOCOPY VARCHAR2
3731 
3732 )
3733 IS
3734 l_return_status               VARCHAR2(1);
3735 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
3736 l_Line_Scredit_rec            OE_Order_PUB.Line_Scredit_Rec_Type;
3737 l_old_Line_Scredit_rec        OE_Order_PUB.Line_Scredit_Rec_Type;
3738 -- local variables to store OUT parameters from security check procedures
3739 l_sec_result            NUMBER;
3740 l_on_operation_action   NUMBER;
3741 I                       NUMBER; -- Used as index.
3742 l_order_source_id           NUMBER;
3743 l_orig_sys_document_ref     VARCHAR2(50);
3744 l_orig_sys_line_ref     VARCHAR2(50);
3745 l_orig_sys_shipment_ref     VARCHAR2(50);
3746 l_change_sequence           VARCHAR2(50);
3747 l_source_document_type_id   NUMBER;
3748 l_source_document_id        NUMBER;
3749 l_source_document_line_id        NUMBER;
3750 
3751 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3752 l_org_id number ;
3753 BEGIN
3754     --MOAC changes start
3755     l_org_id := MO_GLOBAL.get_current_org_id;
3756     IF (l_org_id IS NULL OR l_org_id = FND_API.G_MISS_NUM) THEN
3757        FND_MESSAGE.set_name('FND','MO_ORG_REQUIRED');
3758        OE_MSG_PUB.Add;
3759        RAISE FND_API.G_EXC_ERROR;
3760      END IF;
3761     --MOAC changes end
3762     set_recursion_mode(p_Entity_Code => 7,
3763                                    p_In_out  => 1);
3764     x_return_status := FND_API.G_RET_STS_SUCCESS;
3765 
3766     --  Initialize message list.
3767 
3768     IF FND_API.to_Boolean(p_init_msg_list) THEN
3769         OE_MSG_PUB.initialize;
3770     END IF;
3771 
3772     IF p_control_rec.Process_Partial THEN
3773      	SAVEPOINT Line_Scredits;
3774     END IF;
3775 
3776     IF l_debug_level  > 0 THEN
3777         oe_debug_pub.add(  'ENTERING OE_ORDER_PVT.LINE_SCREDITS' , 1 ) ;
3778     END IF;
3779 
3780     --    FOR I IN 1..p_x_Line_Scredit_tbl.COUNT LOOP
3781 
3782     I := p_x_Line_Scredit_tbl.FIRST;
3783     WHILE I IS NOT NULL LOOP
3784     BEGIN
3785 
3786         --  Load local records.
3787 
3788         l_Line_Scredit_rec := p_x_Line_Scredit_tbl(I);
3789 
3790         IF p_x_old_Line_Scredit_tbl.EXISTS(I) THEN
3791             l_old_Line_Scredit_rec := p_x_old_Line_Scredit_tbl(I);
3792         ELSE
3793             l_old_Line_Scredit_rec := OE_Order_PUB.G_MISS_LINE_SCREDIT_REC;
3794         END IF;
3795         if l_old_line_Scredit_rec.sales_credit_id = FND_API.G_MISS_NUM  Then
3796            IF l_line_Scredit_rec.line_id IS NOT NULL AND
3797               l_line_Scredit_rec.line_id <> FND_API.G_MISS_NUM THEN
3798               BEGIN
3799                IF l_debug_level  > 0 THEN
3800                   oe_debug_pub.add('Getting reference data for line_id:'||l_line_Scredit_rec.line_id);
3801                END IF;
3802                SELECT order_source_id, orig_sys_document_ref, change_sequence,
3803                source_document_type_id, source_document_id, orig_sys_line_ref,
3804                source_document_line_id, orig_sys_shipment_ref
3805                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
3806                l_source_document_type_id, l_source_document_id, l_orig_sys_line_ref,
3807                l_source_document_line_id, l_orig_sys_shipment_ref
3808                FROM   OE_ORDER_LINES_ALL
3809                WHERE  line_id = l_line_Scredit_rec.line_id;
3810               EXCEPTION
3811                WHEN NO_DATA_FOUND THEN
3812                    l_order_source_id := null;
3813                    l_orig_sys_document_ref := null;
3814                    l_change_sequence := null;
3815                    l_source_document_type_id := null;
3816                    l_source_document_id := null;
3817                    l_orig_sys_line_ref := null;
3818                    l_source_document_line_id := null;
3819                    l_orig_sys_shipment_ref := null;
3820                WHEN OTHERS THEN
3821                    l_order_source_id := null;
3822                    l_orig_sys_document_ref := null;
3823                    l_change_sequence := null;
3824                    l_source_document_type_id := null;
3825                    l_source_document_id := null;
3826                    l_orig_sys_line_ref := null;
3827                    l_source_document_line_id := null;
3828                    l_orig_sys_shipment_ref := null;
3829               END;
3830            END IF;
3831 
3832            OE_MSG_PUB.set_msg_context(
3833 		 p_entity_code			=> 'LINE_SCREDIT'
3834   		,p_entity_id         		=> l_line_Scredit_rec.sales_credit_id
3835     		,p_header_id         		=> l_line_Scredit_rec.header_id
3836     		,p_line_id           		=> l_line_Scredit_rec.line_id
3837                 ,p_order_source_id              => l_order_source_id
3838     		,p_orig_sys_document_ref	=> l_orig_sys_document_ref
3839     		,p_orig_sys_document_line_ref	=> l_orig_sys_line_ref
3840                 ,p_orig_sys_shipment_ref        => l_orig_sys_shipment_ref
3841                 ,p_change_sequence              => l_change_sequence
3842                 ,p_source_document_type_id      => l_source_document_type_id
3843     		,p_source_document_id		=> l_source_document_id
3844     		,p_source_document_line_id	=> l_source_document_line_id );
3845 
3846         else
3847            IF l_old_line_Scredit_rec.line_id IS NOT NULL AND
3848               l_old_line_Scredit_rec.line_id <> FND_API.G_MISS_NUM THEN
3849               BEGIN
3850                IF l_debug_level  > 0 THEN
3851                   oe_debug_pub.add('Getting reference data for old line_id:'||l_old_line_Scredit_rec.line_id);
3852                END IF;
3853                SELECT order_source_id, orig_sys_document_ref, change_sequence,
3854                source_document_type_id, source_document_id, orig_sys_line_ref,
3855                source_document_line_id, orig_sys_shipment_ref
3856                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
3857                l_source_document_type_id, l_source_document_id, l_orig_sys_line_ref,
3858                l_source_document_line_id, l_orig_sys_shipment_ref
3859                FROM   OE_ORDER_LINES_ALL
3860                WHERE  line_id = l_old_line_Scredit_rec.line_id;
3861               EXCEPTION
3862                WHEN NO_DATA_FOUND THEN
3863                    l_order_source_id := null;
3864                    l_orig_sys_document_ref := null;
3865                    l_change_sequence := null;
3866                    l_source_document_type_id := null;
3867                    l_source_document_id := null;
3868                    l_orig_sys_line_ref := null;
3869                    l_source_document_line_id := null;
3870                    l_orig_sys_shipment_ref := null;
3871                WHEN OTHERS THEN
3872                    l_order_source_id := null;
3873                    l_orig_sys_document_ref := null;
3874                    l_change_sequence := null;
3875                    l_source_document_type_id := null;
3876                    l_source_document_id := null;
3877                    l_orig_sys_line_ref := null;
3878                    l_source_document_line_id := null;
3879                    l_orig_sys_shipment_ref := null;
3880               END;
3881            END IF;
3882 
3883            OE_MSG_PUB.set_msg_context(
3884 		 p_entity_code			=> 'LINE_SCREDIT'
3885   		,p_entity_id         		=> l_old_line_Scredit_rec.sales_credit_id
3886     		,p_header_id         		=> l_old_line_Scredit_rec.header_id
3887     		,p_line_id           		=> l_old_line_Scredit_rec.line_id
3888                 ,p_order_source_id              => l_order_source_id
3889     		,p_orig_sys_document_ref	=> l_orig_sys_document_ref
3890     		,p_orig_sys_document_line_ref	=> l_orig_sys_line_ref
3891                 ,p_orig_sys_shipment_ref        => l_orig_sys_shipment_ref
3892                 ,p_change_sequence              => l_change_sequence
3893                 ,p_source_document_type_id      => l_source_document_type_id
3894     		,p_source_document_id		=> l_source_document_id
3895     		,p_source_document_line_id	=> l_source_document_line_id );
3896 
3897         end if;
3898 
3899 
3900         --  Load API control record
3901 
3902         l_control_rec := OE_GLOBALS.Init_Control_Rec
3903         (   p_operation     => l_Line_Scredit_rec.operation
3904         ,   p_control_rec   => p_control_rec
3905         );
3906 
3907         --  Set record return status.
3908 
3909         l_Line_Scredit_rec.return_status := FND_API.G_RET_STS_SUCCESS;
3910 
3911         --  Prepare record.
3912 
3913         IF l_Line_Scredit_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
3914 
3915             l_Line_Scredit_rec.db_flag := FND_API.G_FALSE;
3916 
3917             --  Set missing old record elements to NULL.
3918 
3919             OE_Line_Scredit_Util.Convert_Miss_To_Null (l_old_Line_Scredit_rec);
3920 
3921         ELSIF l_Line_Scredit_rec.operation = OE_GLOBALS.G_OPR_UPDATE
3922         OR    l_Line_Scredit_rec.operation = OE_GLOBALS.G_OPR_DELETE
3923         THEN
3924 
3925             l_Line_Scredit_rec.db_flag := FND_API.G_TRUE;
3926 
3927             --  Query Old if missing
3928 
3929             IF  l_old_Line_Scredit_rec.sales_credit_id = FND_API.G_MISS_NUM
3930             THEN
3931 
3932                 OE_Line_Scredit_Util.Query_Row
3933                 (   p_sales_credit_id        => l_Line_Scredit_rec.sales_credit_id
3934 			 ,   x_line_scredit_rec       => l_old_Line_Scredit_rec
3935                 );
3936 
3937             ELSE
3938 
3939                 --  Set missing old record elements to NULL.
3940 
3941                 OE_Line_Scredit_Util.Convert_Miss_To_Null (l_old_Line_Scredit_rec);
3942 
3943             END IF;
3944 
3945             --  Complete new record from old
3946 
3947             OE_Line_Scredit_Util.Complete_Record
3948             (   p_x_Line_Scredit_rec          => l_Line_Scredit_rec
3949             ,   p_old_Line_Scredit_rec        => l_old_Line_Scredit_rec
3950             );
3951 
3952            OE_MSG_PUB.update_msg_context(
3953 		 p_entity_code			=> 'LINE_SCREDIT'
3954   		,p_entity_id         		=> l_line_Scredit_rec.sales_credit_id
3955     		,p_header_id         		=> l_line_Scredit_rec.header_id
3956     		,p_line_id           		=> l_line_Scredit_rec.line_id);
3957 
3958         END IF;
3959 
3960         IF I = p_x_line_scredit_tbl.FIRST THEN
3961 	       IF NOT Valid_Upgraded_Order(l_line_scredit_rec.header_id) THEN
3962                  RAISE FND_API.G_EXC_ERROR;
3963             END IF;
3964         END IF;
3965 
3966    -- Check security
3967    IF l_control_rec.check_security
3968       AND (l_line_scredit_rec.operation = OE_GLOBALS.G_OPR_CREATE
3969          OR l_line_scredit_rec.operation = OE_GLOBALS.G_OPR_UPDATE)
3970    THEN
3971 
3972         IF l_debug_level  > 0 THEN
3973             oe_debug_pub.add(  'CHECK ATTRIBUTES SECURITY' ) ;
3974         END IF;
3975 
3976            OE_Line_Scredit_Security.Attributes
3977                 (p_line_scredit_rec   	=> l_line_scredit_rec
3978                 , p_old_line_scredit_rec	=> l_old_line_scredit_rec
3979                 , x_result      	=> l_sec_result
3980                 , x_return_status 	=> l_return_status
3981                 );
3982 
3983             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3984                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3985             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3986                 RAISE FND_API.G_EXC_ERROR;
3987             END IF;
3988 
3989            IF l_sec_result = OE_PC_GLOBALS.YES THEN
3990                 RAISE FND_API.G_EXC_ERROR;
3991            END IF;
3992 
3993     END IF;
3994 
3995         --  Attribute level validation.
3996 
3997             IF p_validation_level > FND_API.G_VALID_LEVEL_NONE THEN
3998 
3999                 OE_Validate_Line_Scredit.Attributes
4000                 (   x_return_status               => l_return_status
4001                 ,   p_Line_Scredit_rec            => l_Line_Scredit_rec
4002                 ,   p_old_Line_Scredit_rec        => l_old_Line_Scredit_rec
4003                 );
4004 
4005                 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4006                     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4007                 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4008                     RAISE FND_API.G_EXC_ERROR;
4009                 END IF;
4010 
4011             END IF;
4012 
4013             --  Clear dependent attributes.
4014 		 IF l_debug_level  > 0 THEN
4015 		     oe_debug_pub.add(  ' CLEAR DEPENDENT' || L_LINE_SCREDIT_REC.HEADER_ID ) ;
4016 		 END IF;
4017 
4018         IF  l_control_rec.clear_dependents THEN
4019 
4020             OE_Line_Scredit_Util.Clear_Dependent_Attr
4021             (   p_x_Line_Scredit_rec          => l_Line_Scredit_rec
4022             ,   p_old_Line_Scredit_rec        => l_old_Line_Scredit_rec
4023             );
4024 
4025         END IF;
4026 
4027         --  Default missing attributes
4028 		 IF l_debug_level  > 0 THEN
4029 		     oe_debug_pub.add(  ' DEFAULTING' || L_LINE_SCREDIT_REC.HEADER_ID ) ;
4030 		 END IF;
4031 
4032         IF  l_control_rec.default_attributes
4033         THEN
4034 
4035             OE_Default_Line_Scredit.Attributes
4036             (   p_x_Line_Scredit_rec          => l_Line_Scredit_rec
4037 	    ,   p_old_line_scredit_rec        => l_old_line_Scredit_Rec
4038             );
4039 
4040         END IF;
4041 
4042         --  Apply attribute changes
4043 		 IF l_debug_level  > 0 THEN
4044 		     oe_debug_pub.add(  ' APPLY ATTRIBUTES' || L_LINE_SCREDIT_REC.HEADER_ID ) ;
4045 		 END IF;
4046 
4047         IF  l_control_rec.change_attributes
4048         THEN
4049 
4050             OE_Line_Scredit_Util.Apply_Attribute_Changes
4051             (   p_x_Line_Scredit_rec          => l_Line_Scredit_rec
4052             ,   p_old_Line_Scredit_rec        => l_old_Line_Scredit_rec
4053             );
4054 
4055         END IF;
4056 
4057         --  Entity level validation.
4058 		 IF l_debug_level  > 0 THEN
4059 		     oe_debug_pub.add(  ' ENTITY VALIDATION ' || L_LINE_SCREDIT_REC.HEADER_ID ) ;
4060 		 END IF;
4061 
4062         IF l_control_rec.validate_entity THEN
4063 
4064             IF l_Line_Scredit_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
4065 
4066                 OE_Validate_Line_Scredit.Entity_Delete
4067                 (   x_return_status               => l_return_status
4068                 ,   p_Line_Scredit_rec            => l_Line_Scredit_rec
4069                 );
4070 
4071             ELSE
4072 
4073                 OE_Validate_Line_Scredit.Entity
4074                 (   x_return_status               => l_return_status
4075                 ,   p_Line_Scredit_rec            => l_Line_Scredit_rec
4076                 ,   p_old_Line_Scredit_rec        => l_old_Line_Scredit_rec
4077                 );
4078 
4079             END IF;
4080 
4081             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4082                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4083             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4084                 RAISE FND_API.G_EXC_ERROR;
4085             END IF;
4086 
4087         END IF;
4088 
4089     -- Check entity level security again as some attributes
4090     -- may have changed due to defaulting.
4091     -- For UPDATE operations, entity security checks for constraints setup
4092     -- with a NULL column i.e. the constraint restricts update on ANY of
4093     -- the columns.
4094     -- However, this check should NOT be done if user did not try to update
4095     -- any of the constrainable attributes and also none of the defaulted
4096     -- attributes was constrainable!. In such a case, the g_check_all_cols
4097     -- _constraint flag would still be 'Y' as the flag is reset only
4098     -- when checking for constraints.
4099 /* Bug fix 2020390, Removed the changes added for the bug 1696681 */
4100     IF NOT (l_line_scredit_rec.operation  = OE_GLOBALS.G_OPR_UPDATE
4101            AND OE_Line_Scredit_Security.g_check_all_cols_constraint = 'Y')
4102            AND l_control_rec.check_security
4103     THEN
4104 
4105         IF l_debug_level  > 0 THEN
4106             oe_debug_pub.add(  'CHECK ENTITY SECURITY' ) ;
4107         END IF;
4108 
4109            OE_Line_Scredit_Security.Entity
4110                 (p_line_scredit_rec   	=> l_line_scredit_rec
4111                 , x_result      	=> l_sec_result
4112                 , x_return_status 	=> l_return_status
4113                 );
4114 
4115             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4116                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4117             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4118                 RAISE FND_API.G_EXC_ERROR;
4119             END IF;
4120 
4121            IF l_sec_result = OE_PC_GLOBALS.YES THEN
4122                 RAISE FND_API.G_EXC_ERROR;
4123            END IF;
4124 
4125     END IF;
4126 
4127         --  Step 4. Write to DB
4128 
4129         IF l_control_rec.write_to_db THEN
4130 
4131 		 /* Start Audit Trail */
4132            Oe_line_Scredit_Util.Pre_Write_Process
4133 		 (p_x_line_scredit_rec => l_line_scredit_rec,
4134 		  p_old_line_scredit_rec => l_old_line_scredit_rec);
4135 		 /* End AuditTrail */
4136 
4137             IF l_Line_Scredit_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
4138 
4139                 OE_Line_Scredit_Util.Delete_Row
4140                 (   p_sales_credit_id             => l_Line_Scredit_rec.sales_credit_id
4141                 );
4142 
4143             ELSE
4144 
4145                 --  Get Who Information
4146 
4147                 l_Line_Scredit_rec.last_update_date := SYSDATE;
4148                 l_Line_Scredit_rec.last_updated_by :=  NVL(OE_STANDARD_WF.g_user_id, FND_GLOBAL.USER_ID); -- 3169637
4149                 l_Line_Scredit_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
4150 
4151                 IF l_Line_Scredit_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
4152 
4153                     OE_Line_Scredit_Util.Update_Row (l_Line_Scredit_rec);
4154 
4155                 ELSIF l_Line_Scredit_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
4156 
4157                     l_Line_Scredit_rec.creation_date := SYSDATE;
4158                     l_Line_Scredit_rec.created_by  := NVL(OE_STANDARD_WF.g_user_id, FND_GLOBAL.USER_ID); -- 3169637
4159 
4160                     OE_Line_Scredit_Util.Insert_Row (l_Line_Scredit_rec);
4161 
4162                 END IF;
4163 
4164             END IF;
4165 
4166         END IF;
4167 
4168     	OE_Line_Scredit_Security.g_check_all_cols_constraint := 'Y';
4169      OE_MSG_PUB.reset_msg_context('LINE_SCREDIT');
4170 
4171      --  loop exception handler.
4172 	IF l_line_scredit_rec.return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4173 		   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4174 	ELSIF l_line_scredit_rec.return_status = FND_API.G_RET_STS_ERROR THEN
4175 		   RAISE FND_API.G_EXC_ERROR;
4176 	END IF;
4177 
4178         --  Load tables.
4179 
4180         l_Line_Scredit_rec.return_status          := FND_API.G_RET_STS_SUCCESS;
4181         p_x_Line_Scredit_tbl(I)          := l_Line_Scredit_rec;
4182         p_x_old_Line_Scredit_tbl(I)      := l_old_Line_Scredit_rec;
4183 
4184 
4185     EXCEPTION
4186 
4187         WHEN FND_API.G_EXC_ERROR THEN
4188 
4189             x_return_status 				:= FND_API.G_RET_STS_ERROR;
4190             l_Line_Scredit_rec.return_status := FND_API.G_RET_STS_ERROR;
4191             p_x_Line_Scredit_tbl(I)          := l_Line_Scredit_rec;
4192             p_x_old_Line_Scredit_tbl(I)      := l_old_Line_Scredit_rec;
4193 
4194     	    OE_Line_Scredit_Security.g_check_all_cols_constraint := 'Y';
4195          OE_MSG_PUB.reset_msg_context('LINE_SCREDIT');
4196 	    IF l_control_rec.Process_Partial THEN
4197              IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
4198               IF l_debug_level  > 0 THEN
4199                   oe_debug_pub.add(  'DELETE REQUEST12' , 2 ) ;
4200               END IF;
4201               oe_delayed_requests_pvt.Delete_Reqs_for_Deleted_Entity
4202                     (p_entity_code =>OE_GLOBALS.G_ENTITY_LINE_SCREDIT,
4203                     p_entity_id => l_line_scredit_rec.sales_credit_id,
4204                     x_return_status => l_return_status);
4205              END IF;
4206 		   ROLLBACK TO SAVEPOINT Line_Scredits;
4207 	    ELSE
4208 		   RAISE FND_API.G_EXC_ERROR;
4209 	    END IF;
4210 
4211         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4212 
4213             x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
4214             l_Line_Scredit_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4215             p_x_Line_Scredit_tbl(I)          := l_Line_Scredit_rec;
4216             p_x_old_Line_Scredit_tbl(I)      := l_old_Line_Scredit_rec;
4217     	       OE_Line_Scredit_Security.g_check_all_cols_constraint := 'Y';
4218             OE_MSG_PUB.reset_msg_context('LINE_SCREDIT');
4219             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4220 
4221         WHEN OTHERS THEN
4222 
4223             x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
4224             l_Line_Scredit_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4225             p_x_Line_Scredit_tbl(I)          := l_Line_Scredit_rec;
4226             p_x_old_Line_Scredit_tbl(I)      := l_old_Line_Scredit_rec;
4227     	       OE_Line_Scredit_Security.g_check_all_cols_constraint := 'Y';
4228             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4229             THEN
4230                 OE_MSG_PUB.Add_Exc_Msg
4231                 (   G_PKG_NAME
4232                 ,   'Line_Scredits'
4233                 );
4234             END IF;
4235 
4236             OE_MSG_PUB.reset_msg_context('LINE_SCREDIT');
4237             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4238 
4239     END;
4240      I := p_x_Line_Scredit_tbl.NEXT(I);
4241     END LOOP;
4242 
4243 
4244     IF l_debug_level  > 0 THEN
4245         oe_debug_pub.add(  'EXITING OE_ORDER_PVT.LINE_SCREDITS' , 1 ) ;
4246     END IF;
4247     OE_MSG_PUB.reset_msg_context('LINE_SCREDIT');
4248     set_recursion_mode(p_Entity_Code => 7,
4249                                    p_In_out  => 0);
4250 EXCEPTION
4251 
4252     WHEN FND_API.G_EXC_ERROR THEN
4253 
4254         set_recursion_mode(p_Entity_Code => 7,
4255                                    p_In_out  => 0);
4256         x_return_status 				:= FND_API.G_RET_STS_ERROR;
4257         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
4258           IF l_debug_level  > 0 THEN
4259               oe_debug_pub.add(  'DELETE REQUEST13' , 2 ) ;
4260           END IF;
4261           OE_Delayed_Requests_Pvt.Clear_Request
4262                     (x_return_status => l_return_status);
4263         END IF;
4264         OE_MSG_PUB.reset_msg_context('LINE_SCREDIT');
4265 
4266     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4267 
4268         set_recursion_mode(p_Entity_Code => 7,
4269                                    p_In_out  => 0);
4270         x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
4271         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
4272           IF l_debug_level  > 0 THEN
4273               oe_debug_pub.add(  'DELETE REQUEST14' , 2 ) ;
4274           END IF;
4275           OE_Delayed_Requests_Pvt.Clear_Request
4276                     (x_return_status => l_return_status);
4277         END IF;
4278         OE_MSG_PUB.reset_msg_context('LINE_SCREDIT');
4279 
4280     WHEN OTHERS THEN
4281 
4282         set_recursion_mode(p_Entity_Code => 7,
4283                                    p_In_out  => 0);
4284         x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
4285         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
4286           IF l_debug_level  > 0 THEN
4287               oe_debug_pub.add(  'DELETE REQUEST15' , 2 ) ;
4288           END IF;
4289           OE_Delayed_Requests_Pvt.Clear_Request
4290                     (x_return_status => l_return_status);
4291         END IF;
4292         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4293         THEN
4294             OE_MSG_PUB.Add_Exc_Msg
4295             (   G_PKG_NAME
4296             ,   'Line_Scredits'
4297             );
4298         END IF;
4299         OE_MSG_PUB.reset_msg_context('LINE_SCREDIT');
4300 
4301 END Line_Scredits;
4302 
4303 
4304 /*----------------------------------------------------------------------
4305 PROCEDURE Line_Payments
4306 -----------------------------------------------------------------------*/
4307 
4308 PROCEDURE Line_Payments
4309 (   p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
4310 ,   p_validation_level              IN  NUMBER
4311 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
4312 ,   p_x_Line_Payment_tbl            IN OUT NOCOPY  OE_Order_PUB.Line_Payment_Tbl_Type
4313 ,   p_x_old_Line_Payment_tbl        IN OUT NOCOPY  OE_Order_PUB.Line_Payment_Tbl_Type
4314 , x_return_status OUT NOCOPY VARCHAR2
4315 
4316 )
4317 IS
4318 l_return_status               VARCHAR2(1);
4319 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
4320 l_Line_Payment_rec            OE_Order_PUB.Line_Payment_Rec_Type;
4321 l_old_Line_Payment_rec        OE_Order_PUB.Line_Payment_Rec_Type;
4322 -- local variables to store OUT parameters from security check procedures
4323 l_sec_result            NUMBER;
4324 l_on_operation_action   NUMBER;
4325 I                       NUMBER; -- Used as index.
4326 l_order_source_id           NUMBER;
4327 l_orig_sys_document_ref     VARCHAR2(50);
4328 l_orig_sys_line_ref     VARCHAR2(50);
4329 l_orig_sys_shipment_ref     VARCHAR2(50);
4330 l_change_sequence           VARCHAR2(50);
4331 l_source_document_type_id   NUMBER;
4332 l_source_document_id        NUMBER;
4333 l_source_document_line_id        NUMBER;
4334 
4335 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4336 l_org_id number ;
4337 BEGIN
4338     --MOAC changes start
4339       l_org_id := MO_GLOBAL.get_current_org_id;
4340       IF (l_org_id IS NULL OR l_org_id = FND_API.G_MISS_NUM) THEN
4341          FND_MESSAGE.set_name('FND','MO_ORG_REQUIRED');
4342          OE_MSG_PUB.Add;
4343          RAISE FND_API.G_EXC_ERROR;
4344       END IF;
4345     --MOAC changes end
4346     x_return_status := FND_API.G_RET_STS_SUCCESS;
4347 
4348     --  Initialize message list.
4349 
4350     IF FND_API.to_Boolean(p_init_msg_list) THEN
4351         OE_MSG_PUB.initialize;
4352     END IF;
4353 
4354     IF p_control_rec.Process_Partial THEN
4355      	SAVEPOINT Line_Payments;
4356     END IF;
4357 
4358     IF l_debug_level  > 0 THEN
4359         oe_debug_pub.add(  'ENTERING OE_ORDER_PVT.LINE_PAYMENTS' , 1 ) ;
4360     END IF;
4361 
4362     --    FOR I IN 1..p_x_Line_Payment_tbl.COUNT LOOP
4363 
4364     I := p_x_Line_Payment_tbl.FIRST;
4365     WHILE I IS NOT NULL LOOP
4366     BEGIN
4367 
4368         --  Load local records.
4369 
4370         l_Line_Payment_rec := p_x_Line_Payment_tbl(I);
4371 
4372         IF p_x_old_Line_Payment_tbl.EXISTS(I) THEN
4373             l_old_Line_Payment_rec := p_x_old_Line_Payment_tbl(I);
4374         ELSE
4375             l_old_Line_Payment_rec := OE_Order_PUB.G_MISS_LINE_PAYMENT_REC;
4376         END IF;
4377         if l_old_line_Payment_rec.payment_number = FND_API.G_MISS_NUM  Then
4378            IF l_line_Payment_rec.line_id IS NOT NULL AND
4379               l_line_Payment_rec.line_id <> FND_API.G_MISS_NUM THEN
4380               BEGIN
4381                IF l_debug_level  > 0 THEN
4382                   oe_debug_pub.add('Getting reference data for line_id:'||l_line_Payment_rec.line_id);
4383                END IF;
4384                SELECT order_source_id, orig_sys_document_ref, change_sequence,
4385                source_document_type_id, source_document_id, orig_sys_line_ref,
4386                source_document_line_id, orig_sys_shipment_ref
4387                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
4388                l_source_document_type_id, l_source_document_id, l_orig_sys_line_ref,
4389                l_source_document_line_id, l_orig_sys_shipment_ref
4390                FROM   OE_ORDER_LINES_ALL
4391                WHERE  line_id = l_line_Payment_rec.line_id;
4392               EXCEPTION
4393                WHEN NO_DATA_FOUND THEN
4394                    l_order_source_id := null;
4395                    l_orig_sys_document_ref := null;
4396                    l_change_sequence := null;
4397                    l_source_document_type_id := null;
4398                    l_source_document_id := null;
4399                    l_orig_sys_line_ref := null;
4400                    l_source_document_line_id := null;
4401                    l_orig_sys_shipment_ref := null;
4402                WHEN OTHERS THEN
4403                    l_order_source_id := null;
4404                    l_orig_sys_document_ref := null;
4405                    l_change_sequence := null;
4406                    l_source_document_type_id := null;
4407                    l_source_document_id := null;
4408                    l_orig_sys_line_ref := null;
4409                    l_source_document_line_id := null;
4410                    l_orig_sys_shipment_ref := null;
4411               END;
4412            END IF;
4413 
4414            OE_MSG_PUB.set_msg_context(
4415 		 p_entity_code			=> 'LINE_PAYMENT'
4416   		,p_entity_id         		=> l_line_Payment_rec.payment_number
4417     		,p_header_id         		=> l_line_Payment_rec.header_id
4418     		,p_line_id           		=> l_line_Payment_rec.line_id
4419                 ,p_order_source_id              => l_order_source_id
4420     		,p_orig_sys_document_ref	=> l_orig_sys_document_ref
4421     		,p_orig_sys_document_line_ref	=> l_orig_sys_line_ref
4422                 ,p_orig_sys_shipment_ref        => l_orig_sys_shipment_ref
4423                 ,p_change_sequence              => l_change_sequence
4424                 ,p_source_document_type_id      => l_source_document_type_id
4425     		,p_source_document_id		=> l_source_document_id
4426     		,p_source_document_line_id	=> l_source_document_line_id );
4427 
4428         else
4429            IF l_old_line_Payment_rec.line_id IS NOT NULL AND
4430               l_old_line_Payment_rec.line_id <> FND_API.G_MISS_NUM THEN
4431               BEGIN
4432                IF l_debug_level  > 0 THEN
4433                   oe_debug_pub.add('Getting reference data for old line_id:'||l_old_line_Payment_rec.line_id);
4434                END IF;
4435                SELECT order_source_id, orig_sys_document_ref, change_sequence,
4436                source_document_type_id, source_document_id, orig_sys_line_ref,
4437                source_document_line_id, orig_sys_shipment_ref
4438                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
4439                l_source_document_type_id, l_source_document_id, l_orig_sys_line_ref,
4440                l_source_document_line_id, l_orig_sys_shipment_ref
4441                FROM   OE_ORDER_LINES_ALL
4442                WHERE  line_id = l_old_line_Payment_rec.line_id;
4443               EXCEPTION
4444                WHEN NO_DATA_FOUND THEN
4445                    l_order_source_id := null;
4446                    l_orig_sys_document_ref := null;
4447                    l_change_sequence := null;
4448                    l_source_document_type_id := null;
4449                    l_source_document_id := null;
4450                    l_orig_sys_line_ref := null;
4451                    l_source_document_line_id := null;
4452                    l_orig_sys_shipment_ref := null;
4453                WHEN OTHERS THEN
4454                    l_order_source_id := null;
4455                    l_orig_sys_document_ref := null;
4456                    l_change_sequence := null;
4457                    l_source_document_type_id := null;
4458                    l_source_document_id := null;
4459                    l_orig_sys_line_ref := null;
4460                    l_source_document_line_id := null;
4461                    l_orig_sys_shipment_ref := null;
4462               END;
4463            END IF;
4464 
4465            OE_MSG_PUB.set_msg_context(
4466 		 p_entity_code			=> 'LINE_PAYMENT'
4467   		,p_entity_id         		=> l_old_line_Payment_rec.payment_number
4468     		,p_header_id         		=> l_old_line_Payment_rec.header_id
4469     		,p_line_id           		=> l_old_line_Payment_rec.line_id
4470                 ,p_order_source_id              => l_order_source_id
4471     		,p_orig_sys_document_ref	=> l_orig_sys_document_ref
4472     		,p_orig_sys_document_line_ref	=> l_orig_sys_line_ref
4473                 ,p_orig_sys_shipment_ref        => l_orig_sys_shipment_ref
4474                 ,p_change_sequence              => l_change_sequence
4475                 ,p_source_document_type_id      => l_source_document_type_id
4476     		,p_source_document_id		=> l_source_document_id
4477     		,p_source_document_line_id	=> l_source_document_line_id );
4478 
4479         end if;
4480 
4481 
4482         --  Load API control record
4483 
4484         l_control_rec := OE_GLOBALS.Init_Control_Rec
4485         (   p_operation     => l_Line_Payment_rec.operation
4486         ,   p_control_rec   => p_control_rec
4487         );
4488 
4489         --  Set record return status.
4490 
4491         l_Line_Payment_rec.return_status := FND_API.G_RET_STS_SUCCESS;
4492 
4493         --  Prepare record.
4494 
4495         IF l_Line_Payment_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
4496 
4497             l_Line_Payment_rec.db_flag := FND_API.G_FALSE;
4498 
4499             --  Set missing old record elements to NULL.
4500 
4501             IF l_debug_level  > 0 THEN
4502                oe_debug_pub.add('Payment:before OE_Line_Payment_Util.Convert_Miss_To_Null', 5);
4503             END IF;
4504             OE_Line_Payment_Util.Convert_Miss_To_Null (l_old_Line_Payment_rec);
4505             IF l_debug_level  > 0 THEN
4506                oe_debug_pub.add('Payment:after OE_Line_Payment_Util.Convert_Miss_To_Null', 5);
4507             END IF;
4508 
4509         ELSIF l_Line_Payment_rec.operation = OE_GLOBALS.G_OPR_UPDATE
4510         OR    l_Line_Payment_rec.operation = OE_GLOBALS.G_OPR_DELETE
4511         THEN
4512 
4513             l_Line_Payment_rec.db_flag := FND_API.G_TRUE;
4514 
4515             --  Query Old if missing
4516 
4517             IF  l_old_Line_Payment_rec.payment_number = FND_API.G_MISS_NUM
4518             THEN
4519 
4520                 IF l_debug_level  > 0 THEN
4521                    oe_debug_pub.add('Payment:before OE_Line_Payment_Util.Query_Row', 5);
4522                 END IF;
4523                 OE_Line_Payment_Util.Query_Row
4524                 (   p_payment_number        => l_Line_Payment_rec.payment_number
4525                 ,   p_line_id               => l_Line_Payment_rec.line_id
4526                 ,   p_header_id             => l_Line_Payment_rec.header_id
4527 		,   x_line_payment_rec       => l_old_Line_Payment_rec
4528                 );
4529                 IF l_debug_level  > 0 THEN
4530                    oe_debug_pub.add('Payment:after OE_Line_Payment_Util.Query_Row', 5);
4531                 END IF;
4532 
4533             ELSE
4534 
4535                 --  Set missing old record elements to NULL.
4536 
4537                 OE_Line_Payment_Util.Convert_Miss_To_Null (l_old_Line_Payment_rec);
4538 
4539             END IF;
4540 
4541             --  Complete new record from old
4542 
4543             IF l_debug_level  > 0 THEN
4544                oe_debug_pub.add('Payment:before OE_Line_Payment_Util.Complete_Record', 5);
4545             END IF;
4546             OE_Line_Payment_Util.Complete_Record
4547             (   p_x_Line_Payment_rec          => l_Line_Payment_rec
4548             ,   p_old_Line_Payment_rec        => l_old_Line_Payment_rec
4549             );
4550             IF l_debug_level  > 0 THEN
4551                oe_debug_pub.add('Payment:after OE_Line_Payment_Util.Complete_Record', 5);
4552             END IF;
4553 
4554            OE_MSG_PUB.update_msg_context(
4555 		 p_entity_code			=> 'LINE_PAYMENT'
4556   		,p_entity_id         		=> l_line_Payment_rec.payment_number
4557     		,p_header_id         		=> l_line_Payment_rec.header_id
4558     		,p_line_id           		=> l_line_Payment_rec.line_id);
4559 
4560         END IF;
4561 
4562         IF I = p_x_line_payment_tbl.FIRST THEN
4563 	       IF NOT Valid_Upgraded_Order(l_line_payment_rec.header_id) THEN
4564                  RAISE FND_API.G_EXC_ERROR;
4565             END IF;
4566         END IF;
4567 
4568    -- Check security
4569    IF l_control_rec.check_security
4570       AND (l_line_payment_rec.operation = OE_GLOBALS.G_OPR_CREATE
4571          OR l_line_payment_rec.operation = OE_GLOBALS.G_OPR_UPDATE)
4572    THEN
4573 
4574            IF l_debug_level  > 0 THEN
4575               oe_debug_pub.add('Payment:before OE_Line_Payment_Security.Attributes', 5);
4576            END IF;
4577            OE_Line_Payment_Security.Attributes
4578                 (p_line_payment_rec   	=> l_line_payment_rec
4579                 , p_old_line_payment_rec	=> l_old_line_payment_rec
4580                 , x_result      	=> l_sec_result
4581                 , x_return_status 	=> l_return_status
4582                 );
4583            IF l_debug_level  > 0 THEN
4584               oe_debug_pub.add('Payment:after OE_Line_Payment_Security.Attributes', 5);
4585            END IF;
4586 
4587             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4588                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4589             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4590                 RAISE FND_API.G_EXC_ERROR;
4591             END IF;
4592 
4593            IF l_sec_result = OE_PC_GLOBALS.YES THEN
4594                 RAISE FND_API.G_EXC_ERROR;
4595            END IF;
4596 
4597     END IF;
4598 
4599         --  Attribute level validation.
4600 
4601             IF p_validation_level > FND_API.G_VALID_LEVEL_NONE THEN
4602 
4603                 IF l_debug_level  > 0 THEN
4604                    oe_debug_pub.add('Payment:before OE_Validate_Line_Payment.Attributes', 5);
4605                 END IF;
4606                 OE_Validate_Line_Payment.Attributes
4607                 (   x_return_status               => l_return_status
4608                 ,   p_Line_Payment_rec            => l_Line_Payment_rec
4609                 ,   p_old_Line_Payment_rec        => l_old_Line_Payment_rec
4610                 );
4611                 IF l_debug_level  > 0 THEN
4612                    oe_debug_pub.add('Payment:after OE_Validate_Line_Payment.Attributes', 5);
4613                 END IF;
4614 
4615                 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4616                     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4617                 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4618                     RAISE FND_API.G_EXC_ERROR;
4619                 END IF;
4620 
4621             END IF;
4622 
4623             --  Clear dependent attributes.
4624 		 IF l_debug_level  > 0 THEN
4625 		     oe_debug_pub.add(  ' CLEAR DEPENDENT' || L_LINE_PAYMENT_REC.HEADER_ID ) ;
4626 		 END IF;
4627 
4628         IF  l_control_rec.clear_dependents THEN
4629 
4630             IF l_debug_level  > 0 THEN
4631                oe_debug_pub.add('Payment:before OE_Line_Payment_Util.Clear_Dependent_Attr', 5);
4632             END IF;
4633             OE_Line_Payment_Util.Clear_Dependent_Attr
4634             (   p_x_Line_Payment_rec          => l_Line_Payment_rec
4635             ,   p_old_Line_Payment_rec        => l_old_Line_Payment_rec
4636             );
4637             IF l_debug_level  > 0 THEN
4638                oe_debug_pub.add('Payment:after OE_Line_Payment_Util.Clear_Dependent_Attr', 5);
4639             END IF;
4640 
4641         END IF;
4642 
4643         --  Default missing attributes
4644 		 IF l_debug_level  > 0 THEN
4645 		     oe_debug_pub.add(  ' DEFAULTING' || L_LINE_PAYMENT_REC.HEADER_ID ) ;
4646 		 END IF;
4647 
4648         IF  l_control_rec.default_attributes
4649         THEN
4650 
4651             IF l_debug_level  > 0 THEN
4652                oe_debug_pub.add('Payment:before OE_Default_Line_Payment.Attributes', 5);
4653             END IF;
4654             OE_Default_Line_Payment.Attributes
4655             (   p_x_Line_Payment_rec          => l_Line_Payment_rec
4656 	    ,   p_old_line_payment_rec        => l_old_line_Payment_Rec
4657             );
4658             IF l_debug_level  > 0 THEN
4659                oe_debug_pub.add('Payment:after OE_Default_Line_Payment.Attributes', 5);
4660             END IF;
4661 
4662         END IF;
4663 
4664         --  Apply attribute changes
4665 		 IF l_debug_level  > 0 THEN
4666 		     oe_debug_pub.add(  ' APPLY ATTRIBUTES' || L_LINE_PAYMENT_REC.HEADER_ID ) ;
4667 		 END IF;
4668 
4669         IF  l_control_rec.change_attributes
4670         THEN
4671 
4672             IF l_debug_level  > 0 THEN
4673                oe_debug_pub.add('Payment:before OE_Line_Payment_Util.Apply_Attribute_Changes', 5);
4674             END IF;
4675             OE_Line_Payment_Util.Apply_Attribute_Changes
4676             (   p_x_Line_Payment_rec          => l_Line_Payment_rec
4677             ,   p_old_Line_Payment_rec        => l_old_Line_Payment_rec
4678             );
4679             IF l_debug_level  > 0 THEN
4680                oe_debug_pub.add('Payment:after OE_Line_Payment_Util.Apply_Attribute_Changes', 5);
4681             END IF;
4682 
4683         END IF;
4684 
4685         --  Entity level validation.
4686 		 IF l_debug_level  > 0 THEN
4687 		     oe_debug_pub.add(  ' ENTITY VALIDATION ' || L_LINE_PAYMENT_REC.HEADER_ID ) ;
4688 		 END IF;
4689 
4690         IF l_control_rec.validate_entity THEN
4691 
4692             IF l_Line_Payment_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
4693 
4694                 IF l_debug_level  > 0 THEN
4695                    oe_debug_pub.add('Payment:before OE_Validate_Line_Payment.Entity_Delete', 5);
4696                 END IF;
4697                 OE_Validate_Line_Payment.Entity_Delete
4698                 (   x_return_status               => l_return_status
4699                 ,   p_Line_Payment_rec            => l_Line_Payment_rec
4700                 );
4701                 IF l_debug_level  > 0 THEN
4702                    oe_debug_pub.add('Payment:after OE_Validate_Line_Payment.Entity_Delete', 5);
4703                 END IF;
4704 
4705             ELSE
4706 
4707                 IF l_debug_level  > 0 THEN
4708                    oe_debug_pub.add('Payment:before OE_Validate_Line_Payment.Entity', 5);
4709                 END IF;
4710                 OE_Validate_Line_Payment.Entity
4711                 (   x_return_status               => l_return_status
4712                 ,   p_Line_Payment_rec            => l_Line_Payment_rec
4713                 ,   p_old_Line_Payment_rec        => l_old_Line_Payment_rec
4714                 );
4715                 IF l_debug_level  > 0 THEN
4716                    oe_debug_pub.add('Payment:after OE_Validate_Line_Payment.Entity', 5);
4717                 END IF;
4718 
4719             END IF;
4720 
4721             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4722                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4723             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4724                 RAISE FND_API.G_EXC_ERROR;
4725             END IF;
4726 
4727         END IF;
4728 
4729     -- Check entity level security again as some attributes
4730     -- may have changed due to defaulting.
4731     -- For UPDATE operations, entity security checks for constraints setup
4732     -- with a NULL column i.e. the constraint restricts update on ANY of
4733     -- the columns.
4734     -- However, this check should NOT be done if user did not try to update
4735     -- any of the constrainable attributes and also none of the defaulted
4736     -- attributes was constrainable!. In such a case, the g_check_all_cols
4737     -- _constraint flag would still be 'Y' as the flag is reset only
4738     -- when checking for constraints.
4739 /* Bug fix 2020390, Removed the changes added for the bug 1696681 */
4740     IF NOT (l_line_payment_rec.operation  = OE_GLOBALS.G_OPR_UPDATE
4741            AND OE_Line_Payment_Security.g_check_all_cols_constraint = 'Y')
4742            AND l_control_rec.check_security
4743     THEN
4744 
4745            IF l_debug_level  > 0 THEN
4746               oe_debug_pub.add('Payment:before OE_Line_Payment_Security.Entity', 5);
4747            END IF;
4748            OE_Line_Payment_Security.Entity
4749                 (p_line_payment_rec   	=> l_line_payment_rec
4750                 , x_result      	=> l_sec_result
4751                 , x_return_status 	=> l_return_status
4752                 );
4753            IF l_debug_level  > 0 THEN
4754               oe_debug_pub.add('Payment:after OE_Line_Payment_Security.Entity', 5);
4755            END IF;
4756 
4757             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4758                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4759             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4760                 RAISE FND_API.G_EXC_ERROR;
4761             END IF;
4762 
4763            IF l_sec_result = OE_PC_GLOBALS.YES THEN
4764                 RAISE FND_API.G_EXC_ERROR;
4765            END IF;
4766 
4767     END IF;
4768 
4769         --  Step 4. Write to DB
4770 
4771         IF l_control_rec.write_to_db THEN
4772 
4773 		 /* Start Audit Trail */
4774            IF l_debug_level  > 0 THEN
4775               oe_debug_pub.add('Payment:before Oe_line_Payment_Util.Pre_Write_Process', 5);
4776            END IF;
4777            Oe_line_Payment_Util.Pre_Write_Process
4778 		 (p_x_line_payment_rec => l_line_payment_rec,
4779 		  p_old_line_payment_rec => l_old_line_payment_rec);
4780            IF l_debug_level  > 0 THEN
4781               oe_debug_pub.add('Payment:after Oe_line_Payment_Util.Pre_Write_Process', 5);
4782            END IF;
4783 		 /* End AuditTrail */
4784 
4785             IF l_Line_Payment_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
4786 
4787                 IF l_debug_level  > 0 THEN
4788                    oe_debug_pub.add('Payment:before OE_Line_Payment_Util.Delete_Row', 5);
4789                 END IF;
4790                 OE_Line_Payment_Util.Delete_Row
4791                 (   p_payment_number        => l_Line_Payment_rec.payment_number
4792                 ,   p_line_id               => l_Line_Payment_rec.line_id
4793                 ,   p_header_id             => l_Line_Payment_rec.header_id
4794                 );
4795                 IF l_debug_level  > 0 THEN
4796                    oe_debug_pub.add('Payment:after OE_Line_Payment_Util.Delete_Row', 5);
4797                 END IF;
4798 
4799             ELSE
4800 
4801                 --  Get Who Information
4802 
4803                 l_Line_Payment_rec.last_update_date := SYSDATE;
4804                 l_Line_Payment_rec.last_updated_by := NVL(OE_STANDARD_WF.g_user_id, FND_GLOBAL.USER_ID); -- 3169637
4805                 l_Line_Payment_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
4806 
4807                 IF l_Line_Payment_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
4808 
4809                     IF l_debug_level  > 0 THEN
4810                        oe_debug_pub.add('Payment:before OE_Line_Payment_Util.Update_Row', 5);
4811                     END IF;
4812                     OE_Line_Payment_Util.Update_Row (l_Line_Payment_rec);
4813                     IF l_debug_level  > 0 THEN
4814                        oe_debug_pub.add('Payment:after OE_Line_Payment_Util.Update_Row', 5);
4815                     END IF;
4816 
4817                 ELSIF l_Line_Payment_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
4818 
4819                     l_Line_Payment_rec.creation_date := SYSDATE;
4820                     l_Line_Payment_rec.created_by  := NVL(OE_STANDARD_WF.g_user_id, FND_GLOBAL.USER_ID); -- 3169637
4821 
4822                     IF l_debug_level  > 0 THEN
4823                        oe_debug_pub.add('Payment:before OE_Line_Payment_Util.Insert_Row', 5);
4824                     END IF;
4825                     OE_Line_Payment_Util.Insert_Row (l_Line_Payment_rec);
4826                     IF l_debug_level  > 0 THEN
4827                        oe_debug_pub.add('Payment:after OE_Line_Payment_Util.Insert_Row', 5);
4828                     END IF;
4829 
4830                 END IF;
4831 
4832             END IF;
4833 
4834         END IF;
4835 
4836     	OE_Line_Payment_Security.g_check_all_cols_constraint := 'Y';
4837      OE_MSG_PUB.reset_msg_context('LINE_PAYMENT');
4838 
4839      --  loop exception handler.
4840 	IF l_line_payment_rec.return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4841 		   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4842 	ELSIF l_line_payment_rec.return_status = FND_API.G_RET_STS_ERROR THEN
4843 		   RAISE FND_API.G_EXC_ERROR;
4844 	END IF;
4845 
4846         --  Load tables.
4847 
4848         l_Line_Payment_rec.return_status          := FND_API.G_RET_STS_SUCCESS;
4849         p_x_Line_Payment_tbl(I)          := l_Line_Payment_rec;
4850         p_x_old_Line_Payment_tbl(I)      := l_old_Line_Payment_rec;
4851 
4852 
4853     EXCEPTION
4854 
4855         WHEN FND_API.G_EXC_ERROR THEN
4856 
4857             x_return_status 				:= FND_API.G_RET_STS_ERROR;
4858             l_Line_Payment_rec.return_status := FND_API.G_RET_STS_ERROR;
4859             p_x_Line_Payment_tbl(I)          := l_Line_Payment_rec;
4860             p_x_old_Line_Payment_tbl(I)      := l_old_Line_Payment_rec;
4861 
4862     	    OE_Line_Payment_Security.g_check_all_cols_constraint := 'Y';
4863          OE_MSG_PUB.reset_msg_context('LINE_PAYMENT');
4864 	    IF l_control_rec.Process_Partial THEN
4865              IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
4866               IF l_debug_level  > 0 THEN
4867                   oe_debug_pub.add(  'DELETE REQUEST12' , 2 ) ;
4868               END IF;
4869               oe_delayed_requests_pvt.Delete_Reqs_for_Deleted_Entity
4870                     (p_entity_code =>OE_GLOBALS.G_ENTITY_LINE_PAYMENT,
4871                     p_entity_id => l_line_payment_rec.line_id,
4872                     x_return_status => l_return_status);
4873              END IF;
4874 		   ROLLBACK TO SAVEPOINT Line_Payments;
4875 	    ELSE
4876 		   RAISE FND_API.G_EXC_ERROR;
4877 	    END IF;
4878 
4879         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4880 
4881             x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
4882             l_Line_Payment_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4883             p_x_Line_Payment_tbl(I)          := l_Line_Payment_rec;
4884             p_x_old_Line_Payment_tbl(I)      := l_old_Line_Payment_rec;
4885     	       OE_Line_Payment_Security.g_check_all_cols_constraint := 'Y';
4886             OE_MSG_PUB.reset_msg_context('LINE_PAYMENT');
4887             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4888 
4889         WHEN OTHERS THEN
4890 
4891             x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
4892             l_Line_Payment_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4893             p_x_Line_Payment_tbl(I)          := l_Line_Payment_rec;
4894             p_x_old_Line_Payment_tbl(I)      := l_old_Line_Payment_rec;
4895     	       OE_Line_Payment_Security.g_check_all_cols_constraint := 'Y';
4896             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4897             THEN
4898                 OE_MSG_PUB.Add_Exc_Msg
4899                 (   G_PKG_NAME
4900                 ,   'Line_Payments'
4901                 );
4902             END IF;
4903 
4904             OE_MSG_PUB.reset_msg_context('LINE_PAYMENT');
4905             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4906 
4907     END;
4908      I := p_x_Line_Payment_tbl.NEXT(I);
4909     END LOOP;
4910 
4911 
4912     IF l_debug_level  > 0 THEN
4913         oe_debug_pub.add(  'EXITING OE_ORDER_PVT.LINE_PAYMENTS' , 1 ) ;
4914     END IF;
4915     OE_MSG_PUB.reset_msg_context('LINE_PAYMENT');
4916 EXCEPTION
4917 
4918     WHEN FND_API.G_EXC_ERROR THEN
4919 
4920         x_return_status 				:= FND_API.G_RET_STS_ERROR;
4921         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
4922           IF l_debug_level  > 0 THEN
4923               oe_debug_pub.add(  'DELETE REQUEST13' , 2 ) ;
4924           END IF;
4925           OE_Delayed_Requests_Pvt.Clear_Request
4926                     (x_return_status => l_return_status);
4927         END IF;
4928         OE_MSG_PUB.reset_msg_context('LINE_PAYMENT');
4929 
4930     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4931 
4932         x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
4933         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
4934           IF l_debug_level  > 0 THEN
4935               oe_debug_pub.add(  'DELETE REQUEST14' , 2 ) ;
4936           END IF;
4937           OE_Delayed_Requests_Pvt.Clear_Request
4938                     (x_return_status => l_return_status);
4939         END IF;
4940         OE_MSG_PUB.reset_msg_context('LINE_PAYMENT');
4941 
4942     WHEN OTHERS THEN
4943 
4944         x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
4945         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
4946           IF l_debug_level  > 0 THEN
4947               oe_debug_pub.add(  'DELETE REQUEST15' , 2 ) ;
4948           END IF;
4949           OE_Delayed_Requests_Pvt.Clear_Request
4950                     (x_return_status => l_return_status);
4951         END IF;
4952         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4953         THEN
4954             OE_MSG_PUB.Add_Exc_Msg
4955             (   G_PKG_NAME
4956             ,   'Line_Payments'
4957             );
4958         END IF;
4959         OE_MSG_PUB.reset_msg_context('LINE_PAYMENT');
4960 
4961 END Line_Payments;
4962 
4963 
4964 /*-------------------------------------------------------------------
4965 PROCEDURE Lot_Serials
4966 --------------------------------------------------------------------*/
4967 
4968 PROCEDURE Lot_Serials
4969 (   p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
4970 ,   p_validation_level              IN  NUMBER
4971 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
4972 ,   p_x_Lot_Serial_tbl              IN OUT NOCOPY  OE_Order_PUB.Lot_Serial_Tbl_Type
4973 ,   p_x_old_Lot_Serial_tbl          IN OUT NOCOPY  OE_Order_PUB.Lot_Serial_Tbl_Type
4974 , x_return_status OUT NOCOPY VARCHAR2
4975 
4976 )
4977 IS
4978 l_return_status               VARCHAR2(1);
4979 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
4980 l_Lot_Serial_rec              OE_Order_PUB.Lot_Serial_Rec_Type;
4981 l_old_Lot_Serial_rec          OE_Order_PUB.Lot_Serial_Rec_Type;
4982 I					     NUMBER; -- Used as index.
4983 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4984 l_org_id number;
4985 BEGIN
4986     --MOAC changes start
4987       l_org_id := MO_GLOBAL.get_current_org_id;
4988       IF (l_org_id IS NULL OR l_org_id = FND_API.G_MISS_NUM) THEN
4989          FND_MESSAGE.set_name('FND','MO_ORG_REQUIRED');
4990          OE_MSG_PUB.Add;
4991          RAISE FND_API.G_EXC_ERROR;
4992       END IF;
4993     --MOAC changes end
4994     x_return_status := FND_API.G_RET_STS_SUCCESS;
4995 
4996     --  Initialize message list.
4997 
4998     IF FND_API.to_Boolean(p_init_msg_list) THEN
4999         OE_MSG_PUB.initialize;
5000     END IF;
5001 
5002 --    FOR I IN 1..p_x_Lot_Serial_tbl.COUNT LOOP
5003 
5004     I := p_x_Lot_Serial_tbl.FIRST;
5005 
5006     WHILE I IS NOT NULL LOOP
5007     BEGIN
5008 
5009         --  Load local records.
5010 
5011         l_Lot_Serial_rec := p_x_Lot_Serial_tbl(I);
5012 
5013         IF p_x_old_Lot_Serial_tbl.EXISTS(I) THEN
5014             l_old_Lot_Serial_rec := p_x_old_Lot_Serial_tbl(I);
5015         ELSE
5016             l_old_Lot_Serial_rec := OE_Order_PUB.G_MISS_LOT_SERIAL_REC;
5017         END IF;
5018 
5019         --  Load API control record
5020 
5021         l_control_rec := OE_GLOBALS.Init_Control_Rec
5022         (   p_operation     => l_Lot_Serial_rec.operation
5023         ,   p_control_rec   => p_control_rec
5024         );
5025 
5026         --  Set record return status.
5027 
5028         l_Lot_Serial_rec.return_status := FND_API.G_RET_STS_SUCCESS;
5029 
5030         --  Prepare record.
5031 
5032         IF l_Lot_Serial_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
5033 
5034             l_Lot_Serial_rec.db_flag := FND_API.G_FALSE;
5035 
5036             --  Set missing old record elements to NULL.
5037 
5038             OE_Lot_Serial_Util.Convert_Miss_To_Null (l_old_Lot_Serial_rec);
5039 
5040         ELSIF l_Lot_Serial_rec.operation = OE_GLOBALS.G_OPR_UPDATE
5041         OR    l_Lot_Serial_rec.operation = OE_GLOBALS.G_OPR_DELETE
5042         THEN
5043 
5044             l_Lot_Serial_rec.db_flag := FND_API.G_TRUE;
5045 
5046             --  Query Old if missing
5047 
5048             IF  l_old_Lot_Serial_rec.lot_serial_id = FND_API.G_MISS_NUM
5049             THEN
5050 
5051                 OE_Lot_Serial_Util.Query_Row
5052                 (   p_lot_serial_id               => l_Lot_Serial_rec.lot_serial_id
5053 			 ,   x_Lot_Serial_rec              => l_old_Lot_Serial_rec
5054                 );
5055 
5056             ELSE
5057 
5058                 --  Set missing old record elements to NULL.
5059 
5060                 OE_Lot_Serial_Util.Convert_Miss_To_Null (l_old_Lot_Serial_rec);
5061 
5062             END IF;
5063 
5064             --  Complete new record from old
5065 
5066             OE_Lot_Serial_Util.Complete_Record
5067             (   p_x_Lot_Serial_rec            => l_Lot_Serial_rec
5068             ,   p_old_Lot_Serial_rec          => l_old_Lot_Serial_rec
5069             );
5070 
5071         END IF;
5072 
5073         --  Attribute level validation.
5074 
5075             IF p_validation_level > FND_API.G_VALID_LEVEL_NONE THEN
5076 
5077                 OE_Validate_Lot_Serial.Attributes
5078                 (   x_return_status               => l_return_status
5079                 ,   p_Lot_Serial_rec              => l_Lot_Serial_rec
5080                 ,   p_old_Lot_Serial_rec          => l_old_Lot_Serial_rec
5081                 );
5082 
5083                 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5084                     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5085                 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5086                     RAISE FND_API.G_EXC_ERROR;
5087                 END IF;
5088 
5089             END IF;
5090 
5091             --  Clear dependent attributes.
5092 
5093         IF  l_control_rec.clear_dependents THEN
5094 
5095             OE_Lot_Serial_Util.Clear_Dependent_Attr
5096             (   p_x_Lot_Serial_rec            => l_Lot_Serial_rec
5097             ,   p_old_Lot_Serial_rec          => l_old_Lot_Serial_rec
5098             );
5099 
5100         END IF;
5101 
5102         --  Default missing attributes
5103 
5104         IF  l_control_rec.default_attributes
5105         THEN
5106 
5107             OE_Default_Lot_Serial.Attributes
5108             (   p_x_Lot_Serial_rec            => l_Lot_Serial_rec
5109             );
5110 
5111         END IF;
5112 
5113         --  Apply attribute changes
5114 
5115         IF  l_control_rec.change_attributes
5116         THEN
5117 
5118             OE_Lot_Serial_Util.Apply_Attribute_Changes
5119             (   p_x_Lot_Serial_rec            => l_Lot_Serial_rec
5120             ,   p_old_Lot_Serial_rec          => l_old_Lot_Serial_rec
5121             );
5122 
5123         END IF;
5124 
5125         --  Entity level validation.
5126 
5127         IF l_control_rec.validate_entity THEN
5128 
5129             IF l_Lot_Serial_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
5130 
5131                 OE_Validate_Lot_Serial.Entity_Delete
5132                 (   x_return_status               => l_return_status
5133                 ,   p_Lot_Serial_rec              => l_Lot_Serial_rec
5134                 );
5135 
5136             ELSE
5137 
5138                 OE_Validate_Lot_Serial.Entity
5139                 (   x_return_status               => l_return_status
5140                 ,   p_Lot_Serial_rec              => l_Lot_Serial_rec
5141                 ,   p_old_Lot_Serial_rec          => l_old_Lot_Serial_rec
5142                 );
5143 
5144             END IF;
5145 
5146             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5147                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5148             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5149                 RAISE FND_API.G_EXC_ERROR;
5150             END IF;
5151 
5152         END IF;
5153 
5154         --  Step 4. Write to DB
5155 
5156         IF l_control_rec.write_to_db THEN
5157 
5158             IF l_Lot_Serial_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
5159 
5160                 OE_Lot_Serial_Util.Delete_Row
5161                 (   p_lot_serial_id               => l_Lot_Serial_rec.lot_serial_id
5162                 );
5163 
5164             ELSE
5165 
5166                 --  Get Who Information
5167 
5168                 l_Lot_Serial_rec.last_update_date := SYSDATE;
5169                 l_Lot_Serial_rec.last_updated_by := NVL(OE_STANDARD_WF.g_user_id, FND_GLOBAL.USER_ID); -- 3169637
5170                 l_Lot_Serial_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
5171 
5172                 IF l_Lot_Serial_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
5173 
5174                     OE_Lot_Serial_Util.Update_Row (l_Lot_Serial_rec);
5175 
5176                 ELSIF l_Lot_Serial_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
5177 
5178                     l_Lot_Serial_rec.creation_date := SYSDATE;
5179                     l_Lot_Serial_rec.created_by    := NVL(OE_STANDARD_WF.g_user_id, FND_GLOBAL.USER_ID); -- 3169637
5180 
5181                     OE_Lot_Serial_Util.Insert_Row (l_Lot_Serial_rec);
5182 
5183                 END IF;
5184 
5185             END IF;
5186 
5187         END IF;
5188 
5189         --  Load tables.
5190 
5191         p_x_Lot_Serial_tbl(I)            := l_Lot_Serial_rec;
5192         p_x_old_Lot_Serial_tbl(I)        := l_old_Lot_Serial_rec;
5193 
5194        --  loop exception handler.
5195 
5196 
5197     EXCEPTION
5198 
5199         WHEN FND_API.G_EXC_ERROR THEN
5200 
5201             x_return_status 				:= FND_API.G_RET_STS_ERROR;
5202             l_Lot_Serial_rec.return_status 	:= FND_API.G_RET_STS_ERROR;
5203             p_x_Lot_Serial_tbl(I)            := l_Lot_Serial_rec;
5204             p_x_old_Lot_Serial_tbl(I)        := l_old_Lot_Serial_rec;
5205 
5206         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5207 
5208             x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
5209             l_Lot_Serial_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5210             p_x_Lot_Serial_tbl(I)            := l_Lot_Serial_rec;
5211             p_x_old_Lot_Serial_tbl(I)        := l_old_Lot_Serial_rec;
5212             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5213 
5214         WHEN OTHERS THEN
5215 
5216             x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
5217             l_Lot_Serial_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5218             p_x_Lot_Serial_tbl(I)            := l_Lot_Serial_rec;
5219             p_x_old_Lot_Serial_tbl(I)        := l_old_Lot_Serial_rec;
5220 
5221             IF oe_msg_pub.Check_Msg_Level(oe_msg_pub.G_MSG_LVL_UNEXP_ERROR)
5222             THEN
5223                 oe_msg_pub.Add_Exc_Msg
5224                 (   G_PKG_NAME
5225                 ,   'Lot_Serials'
5226                 );
5227             END IF;
5228 
5229             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5230 
5231     END;
5232 		I := p_x_Lot_Serial_tbl.NEXT(I);
5233     END LOOP;
5234 
5235 EXCEPTION
5236 
5237     WHEN FND_API.G_EXC_ERROR THEN
5238 
5239         x_return_status 				:= FND_API.G_RET_STS_ERROR;
5240         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
5241           IF l_debug_level  > 0 THEN
5242               oe_debug_pub.add(  'DELETE REQUEST17' , 2 ) ;
5243           END IF;
5244           OE_Delayed_Requests_Pvt.Clear_Request
5245                     (x_return_status => l_return_status);
5246         END IF;
5247 
5248     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5249 
5250         x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
5251         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
5252           IF l_debug_level  > 0 THEN
5253               oe_debug_pub.add(  'DELETE REQUEST18' , 2 ) ;
5254           END IF;
5255           OE_Delayed_Requests_Pvt.Clear_Request
5256                     (x_return_status => l_return_status);
5257         END IF;
5258 
5259     WHEN OTHERS THEN
5260 
5261         x_return_status 				:= FND_API.G_RET_STS_UNEXP_ERROR;
5262         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
5263           IF l_debug_level  > 0 THEN
5264               oe_debug_pub.add(  'DELETE REQUEST19' , 2 ) ;
5265           END IF;
5266           OE_Delayed_Requests_Pvt.Clear_Request
5267                     (x_return_status => l_return_status);
5268         END IF;
5269         IF oe_msg_pub.Check_Msg_Level(oe_msg_pub.G_MSG_LVL_UNEXP_ERROR)
5270         THEN
5271             oe_msg_pub.Add_Exc_Msg
5272             (   G_PKG_NAME
5273             ,   'Lot_Serials'
5274             );
5275         END IF;
5276 
5277 END Lot_Serials;
5278 
5279 
5280 /*-----------------------------------------------------------------
5281 PROCEDURE Process_Requests_And_Notify
5282 ------------------------------------------------------------------*/
5283 
5284 PROCEDURE Process_Requests_And_Notify
5285 (   p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
5286 ,   p_process_requests              IN  BOOLEAN := TRUE
5287 ,   p_notify                        IN  BOOLEAN := TRUE
5288 ,   p_process_ack                   IN  BOOLEAN := TRUE
5289 , x_return_status OUT NOCOPY VARCHAR2
5290 
5291 ,   p_header_rec                    IN  OE_Order_PUB.Header_Rec_Type :=
5292                                         OE_Order_PUB.G_MISS_HEADER_REC
5293 ,   p_old_header_rec                IN  OE_Order_PUB.Header_Rec_Type :=
5294                                         OE_Order_PUB.G_MISS_HEADER_REC
5295 ,   p_Header_Adj_tbl                IN  OE_Order_PUB.Header_Adj_Tbl_Type :=
5296                                         OE_Order_PUB.G_MISS_HEADER_ADJ_TBL
5297 ,   p_old_Header_Adj_tbl            IN  OE_Order_PUB.Header_Adj_Tbl_Type :=
5298                                         OE_Order_PUB.G_MISS_HEADER_ADJ_TBL
5299 ,   p_Header_Price_Att_tbl          IN  OE_Order_PUB.Header_Price_Att_Tbl_Type :=
5300                                         OE_Order_PUB.G_MISS_HEADER_PRICE_ATT_TBL
5301 ,   p_old_Header_Price_Att_tbl      IN  OE_Order_PUB.Header_Price_Att_Tbl_Type :=
5302                                         OE_Order_PUB.G_MISS_HEADER_PRICE_ATT_TBL
5303 ,   p_Header_Adj_Att_tbl            IN  OE_Order_PUB.Header_Adj_Att_Tbl_Type :=
5304                                         OE_Order_PUB.G_MISS_HEADER_ADJ_ATT_TBL
5305 ,   p_old_Header_Adj_Att_tbl        IN  OE_Order_PUB.Header_Adj_Att_Tbl_Type :=
5306                                         OE_Order_PUB.G_MISS_HEADER_ADJ_ATT_TBL
5307 ,   p_Header_Adj_Assoc_tbl          IN  OE_Order_PUB.Header_Adj_Assoc_Tbl_Type :=
5308                                         OE_Order_PUB.G_MISS_HEADER_ADJ_ASSOC_TBL
5309 ,   p_old_Header_Adj_Assoc_tbl      IN  OE_Order_PUB.Header_Adj_Assoc_Tbl_Type :=
5310                                         OE_Order_PUB.G_MISS_HEADER_ADJ_ASSOC_TBL
5311 ,   p_Header_Scredit_tbl            IN  OE_Order_PUB.Header_Scredit_Tbl_Type :=
5312                                         OE_Order_PUB.G_MISS_HEADER_SCREDIT_TBL
5313 ,   p_old_Header_Scredit_tbl        IN  OE_Order_PUB.Header_Scredit_Tbl_Type :=
5314                                         OE_Order_PUB.G_MISS_HEADER_SCREDIT_TBL
5315 ,   p_Header_Payment_tbl            IN  OE_Order_PUB.Header_Payment_Tbl_Type :=
5316                                         OE_Order_PUB.G_MISS_HEADER_PAYMENT_TBL
5317 ,   p_old_Header_Payment_tbl        IN  OE_Order_PUB.Header_Payment_Tbl_Type :=
5318                                         OE_Order_PUB.G_MISS_HEADER_PAYMENT_TBL
5319 ,   p_line_tbl                      IN  OE_Order_PUB.Line_Tbl_Type :=
5320                                         OE_Order_PUB.G_MISS_LINE_TBL
5321 ,   p_old_line_tbl                  IN  OE_Order_PUB.Line_Tbl_Type :=
5322                                         OE_Order_PUB.G_MISS_LINE_TBL
5323 ,   p_Line_Adj_tbl                  IN  OE_Order_PUB.Line_Adj_Tbl_Type :=
5324                                         OE_Order_PUB.G_MISS_LINE_ADJ_TBL
5325 ,   p_old_Line_Adj_tbl              IN  OE_Order_PUB.Line_Adj_Tbl_Type :=
5326                                         OE_Order_PUB.G_MISS_LINE_ADJ_TBL
5327 ,   p_Line_Price_Att_tbl            IN  OE_Order_PUB.Line_Price_Att_Tbl_Type :=
5328                                         OE_Order_PUB.G_MISS_LINE_PRICE_ATT_TBL
5329 ,   p_old_Line_Price_Att_tbl        IN  OE_Order_PUB.Line_Price_Att_Tbl_Type :=
5330                                         OE_Order_PUB.G_MISS_LINE_PRICE_ATT_TBL
5331 ,   p_Line_Adj_Att_tbl              IN  OE_Order_PUB.Line_Adj_Att_Tbl_Type :=
5332                                         OE_Order_PUB.G_MISS_LINE_ADJ_ATT_TBL
5333 ,   p_old_Line_Adj_Att_tbl          IN  OE_Order_PUB.Line_Adj_Att_Tbl_Type :=
5334                                         OE_Order_PUB.G_MISS_LINE_ADJ_ATT_TBL
5335 ,   p_Line_Adj_Assoc_tbl            IN  OE_Order_PUB.Line_Adj_Assoc_Tbl_Type :=
5336                                         OE_Order_PUB.G_MISS_LINE_ADJ_ASSOC_TBL
5337 ,   p_old_Line_Adj_Assoc_tbl        IN  OE_Order_PUB.Line_Adj_Assoc_Tbl_Type :=
5338                                         OE_Order_PUB.G_MISS_LINE_ADJ_ASSOC_TBL
5339 ,   p_Line_Scredit_tbl              IN  OE_Order_PUB.Line_Scredit_Tbl_Type :=
5340                                         OE_Order_PUB.G_MISS_LINE_SCREDIT_TBL
5341 ,   p_old_Line_Scredit_tbl          IN  OE_Order_PUB.Line_Scredit_Tbl_Type :=
5342                                         OE_Order_PUB.G_MISS_LINE_SCREDIT_TBL
5343 ,   p_Line_Payment_tbl              IN  OE_Order_PUB.Line_Payment_Tbl_Type :=
5344                                         OE_Order_PUB.G_MISS_LINE_PAYMENT_TBL
5345 ,   p_old_Line_Payment_tbl          IN  OE_Order_PUB.Line_Payment_Tbl_Type :=
5346                                         OE_Order_PUB.G_MISS_LINE_PAYMENT_TBL
5347 ,   p_Lot_Serial_tbl                IN  OE_Order_PUB.Lot_Serial_Tbl_Type :=
5348                                         OE_Order_PUB.G_MISS_LOT_SERIAL_TBL
5349 ,   p_old_Lot_Serial_tbl            IN  OE_Order_PUB.Lot_Serial_Tbl_Type :=
5350                                         OE_Order_PUB.G_MISS_LOT_SERIAL_TBL
5351 ,   p_Lot_Serial_val_tbl            IN  OE_Order_PUB.Lot_Serial_Val_Tbl_Type :=
5352                                         OE_Order_PUB.G_MISS_LOT_SERIAL_VAL_TBL
5353 ,   p_old_Lot_Serial_val_tbl        IN  OE_Order_PUB.Lot_Serial_Val_Tbl_Type :=
5354                                         OE_Order_PUB.G_MISS_LOT_SERIAL_VAL_TBL
5355 )
5356 IS
5357 l_return_status			VARCHAR2(30);
5358 l_msg_count				NUMBER;
5359 l_msg_data				VARCHAR2(2000);
5360 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5361 l_header_id			NUMBER; -- added for bug 2781468 hashraf
5362 l_index  			NUMBER;
5363 l_line_id			NUMBER;
5364 l_edi_ack_pfile                 Varchar2(3);
5365 
5366 BEGIN
5367 
5368     set_recursion_mode(p_Entity_Code => 8,
5369                                    p_In_out  => 1);
5370     IF l_debug_level  > 0 THEN
5371         oe_debug_pub.add(  'ENTER OE_ORDER_PVT.PROCESS_REQUESTS_AND_NOTIFY' , 1 ) ;
5372     END IF;
5373 
5374     x_return_status := FND_API.G_RET_STS_SUCCESS;
5375     fnd_profile.get('ONT_NEW_EDI_ACK_FWK', l_edi_ack_pfile);
5376     l_edi_ack_pfile := nvl(l_edi_ack_pfile, 'NO');
5377 
5378     --  Initialize message list.
5379 
5380     IF FND_API.to_Boolean(p_init_msg_list) THEN
5381         OE_MSG_PUB.initialize;
5382     END IF;
5383 
5384 
5385     -- IF p_process_requests, then process all delayed requests
5386 
5387     IF (    OE_GLOBALS.G_RECURSION_MODE = 'N'
5388 	   AND p_process_requests
5389         AND OE_DELAYED_REQUESTS_PVT.Requests_Count > 0 )
5390     THEN
5391 
5392        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
5393           (p_entity_code   => OE_GLOBALS.G_ENTITY_HEADER_ADJ
5394           ,p_delete        => FND_API.G_TRUE
5395           ,x_return_status => l_return_status
5396           );
5397        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5398                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5399        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5400                  RAISE FND_API.G_EXC_ERROR;
5401        END IF;
5402 
5403        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
5404           (p_entity_code   => OE_GLOBALS.G_ENTITY_Header_Price_Att
5405           ,p_delete        => FND_API.G_TRUE
5406           ,x_return_status => l_return_status
5407           );
5408        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5409                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5410        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5411                  RAISE FND_API.G_EXC_ERROR;
5412        END IF;
5413 
5414        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
5415           (p_entity_code   => OE_GLOBALS.G_ENTITY_Header_Adj_Att
5416           ,p_delete        => FND_API.G_TRUE
5417           ,x_return_status => l_return_status
5418           );
5419        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5420                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5421        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5422                  RAISE FND_API.G_EXC_ERROR;
5423        END IF;
5424 
5425        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
5426           (p_entity_code   => OE_GLOBALS.G_ENTITY_Header_Adj_Assoc
5427           ,p_delete        => FND_API.G_TRUE
5428           ,x_return_status => l_return_status
5429           );
5430        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5431                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5432        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5433                  RAISE FND_API.G_EXC_ERROR;
5434        END IF;
5435 
5436        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
5437           (p_entity_code   => OE_GLOBALS.G_ENTITY_Header_Scredit
5438           ,p_delete        => FND_API.G_TRUE
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        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
5448           (p_entity_code   => OE_GLOBALS.G_ENTITY_HEADER_PAYMENT
5449           ,p_delete        => FND_API.G_TRUE
5450           ,x_return_status => l_return_status
5451           );
5452        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5453                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5454        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5455                  RAISE FND_API.G_EXC_ERROR;
5456        END IF;
5457 
5458        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
5459           (p_entity_code   => OE_GLOBALS.G_ENTITY_LINE
5460           ,p_delete        => FND_API.G_TRUE
5461           ,x_return_status => l_return_status
5462           );
5463        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5464                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5465        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5466                  RAISE FND_API.G_EXC_ERROR;
5467        END IF;
5468 
5469        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
5470           (p_entity_code   => OE_GLOBALS.G_ENTITY_LINE_ADJ
5471           ,p_delete        => FND_API.G_TRUE
5472           ,x_return_status => l_return_status
5473           );
5474        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5475                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5476        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5477                  RAISE FND_API.G_EXC_ERROR;
5478        END IF;
5479 
5480        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
5481           (p_entity_code   => OE_GLOBALS.G_ENTITY_Line_Scredit
5482           ,p_delete        => FND_API.G_TRUE
5483           ,x_return_status => l_return_status
5484           );
5485        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5486                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5487        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5488                  RAISE FND_API.G_EXC_ERROR;
5489        END IF;
5490 
5491        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
5492           (p_entity_code   => OE_GLOBALS.G_ENTITY_LINE_PAYMENT
5493           ,p_delete        => FND_API.G_TRUE
5494           ,x_return_status => l_return_status
5495           );
5496        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5497                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5498        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5499                  RAISE FND_API.G_EXC_ERROR;
5500        END IF;
5501 
5502        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
5503           (p_entity_code   => OE_GLOBALS.G_ENTITY_Line_Price_Att
5504           ,p_delete        => FND_API.G_TRUE
5505           ,x_return_status => l_return_status
5506           );
5507        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5508                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5509        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5510                  RAISE FND_API.G_EXC_ERROR;
5511        END IF;
5512 
5513        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
5514           (p_entity_code   => OE_GLOBALS.G_ENTITY_Line_Adj_Att
5515           ,p_delete        => FND_API.G_TRUE
5516           ,x_return_status => l_return_status
5517           );
5518        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5519                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5520        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5521                  RAISE FND_API.G_EXC_ERROR;
5522        END IF;
5523 
5524        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
5525           (p_entity_code   => OE_GLOBALS.G_ENTITY_Line_Adj_Assoc
5526           ,p_delete        => FND_API.G_TRUE
5527           ,x_return_status => l_return_status
5528           );
5529        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5530                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5531        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5532                  RAISE FND_API.G_EXC_ERROR;
5533        END IF;
5534 
5535        -- Execute all remaining delayed requests. This would execute
5536 	  -- requests logged against entity G_ENTITY_HEADER and G_ENTITY_ALL
5537 
5538        OE_DELAYED_REQUESTS_PVT.Process_Delayed_Requests(
5539           x_return_status => l_return_status
5540           );
5541 
5542        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5543                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5544        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5545                  RAISE FND_API.G_EXC_ERROR;
5546        END IF;
5547 
5548 
5549     END IF; --End of requests processing
5550 
5551     -- Start flows for the Entity.
5552     IF (p_process_requests AND
5553         OE_GLOBALS.G_RECURSION_MODE = 'N') THEN
5554 
5555 	   OE_ORDER_WF_UTIL.START_ALL_FLOWS;
5556     END IF;
5557 
5558   IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL < '110508'
5559   AND oe_order_cache.g_header_rec.booked_flag = 'Y' THEN
5560     -- If notify, then call service and acknowledgments notify APIs
5561 
5562     IF p_notify THEN
5563     IF l_debug_level  > 0 THEN
5564         oe_debug_pub.add(  'CALLING NOTIFY_OC API' , 1 ) ;
5565     END IF;
5566 
5567     OE_SERVICE_UTIL.Notify_OC
5568     (   p_api_version_number                  =>  1.0
5569     ,   p_init_msg_list                       =>  FND_API.G_FALSE
5570     ,   x_return_status                       =>  l_return_status
5571     ,   x_msg_count                           =>  l_msg_count
5572     ,   x_msg_data                            =>  l_msg_data
5573     ,   p_header_rec                          =>  p_header_rec
5574     ,   p_old_header_rec                      =>  p_old_header_rec
5575     ,   p_header_adj_tbl                      =>  p_header_adj_tbl
5576     ,   p_old_header_adj_tbl		           =>  p_old_header_adj_tbl
5577     ,   p_header_price_att_tbl                =>  p_header_price_att_tbl
5578     ,   p_old_header_price_att_tbl            =>  p_old_header_price_att_tbl
5579     ,   p_Header_Adj_Att_tbl                  =>  p_Header_Adj_Att_tbl
5580     ,   p_old_Header_Adj_Att_tbl              =>  p_old_Header_Adj_Att_tbl
5581     ,   p_Header_Adj_Assoc_tbl                =>  p_Header_Adj_Assoc_tbl
5582     ,   p_old_Header_Adj_Assoc_tbl            =>  p_old_Header_Adj_Assoc_tbl
5583     ,   p_Header_Scredit_tbl                  =>  p_Header_Scredit_tbl
5584     ,   p_old_Header_Scredit_tbl              =>  p_old_Header_Scredit_tbl
5585 --  ,   p_Header_Payment_tbl                  =>  p_Header_Payment_tbl
5586 --  ,   p_old_Header_Payment_tbl              =>  p_old_Header_Payment_tbl
5587     ,   p_line_tbl                            =>  p_line_tbl
5588     ,   p_old_line_tbl                        =>  p_old_line_tbl
5589     ,   p_Line_Adj_tbl                        =>  p_Line_Adj_tbl
5590     ,   p_old_Line_Adj_tbl                    =>  p_old_Line_Adj_tbl
5591     ,   p_Line_Price_Att_tbl                  =>  p_Line_Price_Att_tbl
5592     ,   p_old_Line_Price_Att_tbl              =>  p_old_Line_Price_Att_tbl
5593     ,   p_Line_Adj_Att_tbl                    =>  p_Line_Adj_Att_tbl
5594     ,   p_old_Line_Adj_Att_tbl                =>  p_old_Line_Adj_Att_tbl
5595     ,   p_Line_Adj_Assoc_tbl                  =>  p_Line_Adj_Assoc_tbl
5596     ,   p_old_Line_Adj_Assoc_tbl              =>  p_old_Line_Adj_Assoc_tbl
5597     ,   p_Line_Scredit_tbl                    =>  p_Line_Scredit_tbl
5598     ,   p_old_Line_Scredit_tbl                =>  p_old_Line_Scredit_tbl
5599 --  ,   p_Line_Payment_tbl                    =>  p_Line_Payment_tbl
5600 --  ,   p_old_Line_Payment_tbl                =>  p_old_Line_Payment_tbl
5601     ,   p_Lot_Serial_tbl                      =>  p_Lot_Serial_tbl
5602     ,   p_old_Lot_Serial_tbl                  =>  p_old_Lot_Serial_tbl
5603     ,   p_Lot_Serial_val_tbl                  =>  p_Lot_Serial_val_tbl
5604     ,   p_old_Lot_Serial_val_tbl              =>  p_old_Lot_Serial_val_tbl
5605     );
5606 
5607        IF l_debug_level  > 0 THEN
5608            oe_debug_pub.add(  'AFTER NOTIFY_OC API' , 1 ) ;
5609        END IF;
5610 	  IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5611           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5612        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5613           RAISE FND_API.G_EXC_ERROR;
5614        END IF;
5615     END IF; --p_notify
5616 
5617     IF l_debug_level  > 0 THEN
5618         oe_debug_pub.add(  'PROCESSING ACKS' , 1 ) ;
5619     END IF;
5620 
5621     IF p_notify AND p_process_ack THEN
5622       IF l_debug_level  > 0 THEN
5623           oe_debug_pub.add(  'CALLING ACKS API' , 1 ) ;
5624       END IF;
5625 
5626      -- ediack changes
5627      If Oe_Code_Control.Code_Release_level >= '110510' And
5628         p_header_rec.order_source_id In (0,2,6) And
5629         l_edi_ack_pfile = 'YES'  Then
5630 
5631         OE_Acknowledgment_Pvt.Process_Acknowledgment
5632         (p_header_rec           => p_header_rec,
5633          p_line_tbl             => p_line_tbl,
5634          p_old_header_rec       => p_old_header_rec,
5635          p_old_line_tbl         => p_old_line_tbl,
5636          x_return_status        => l_return_status);
5637 
5638      Elsif l_edi_ack_pfile = 'NO' And
5639            p_header_rec.order_source_id In (0,2,6,20) Then
5640 
5641       OE_Acknowledgment_Pvt.Process_Acknowledgment
5642      (p_api_version_number 		=> 1
5643      ,p_init_msg_list 		        => FND_API.G_FALSE
5644      ,p_header_rec 			=> p_header_rec
5645      ,p_header_adj_tbl		        => p_header_adj_tbl
5646      ,p_header_Scredit_tbl		=> p_header_scredit_tbl
5647      ,p_line_tbl 			=> p_line_tbl
5648      ,p_line_adj_tbl			=> p_line_adj_tbl
5649      ,p_line_scredit_tbl		=> p_line_scredit_tbl
5650      ,p_lot_serial_tbl		        => p_lot_serial_tbl
5651      ,p_old_header_rec 		   	=> p_old_header_rec
5652      ,p_old_header_adj_tbl 		=> p_old_header_adj_tbl
5653      ,p_old_header_Scredit_tbl 	   	=> p_old_header_scredit_tbl
5654      ,p_old_line_tbl 		        => p_old_line_tbl
5655      ,p_old_line_adj_tbl 		=> p_old_line_adj_tbl
5656      ,p_old_line_scredit_tbl 	   	=> p_old_line_scredit_tbl
5657      ,p_old_lot_serial_tbl		=> p_old_lot_serial_tbl
5658 
5659      ,p_buyer_seller_flag           	=> 'B'
5660      ,p_reject_order                	=> 'N'
5661 
5662      ,x_return_status                   => l_return_status
5663      );
5664 
5665      End If;
5666 
5667      IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5668         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5669      ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5670         RAISE FND_API.G_EXC_ERROR;
5671         x_return_status := l_return_status;
5672      END IF;
5673     END IF; -- p_notify and p_process_ack
5674 
5675   ELSE  /*post pack H*/
5676       IF l_debug_level  > 0 THEN
5677           oe_debug_pub.add(  'JPN: GLOBAL RECURSION WITHOUT EXCEPTION: ' || OE_ORDER_UTIL.G_RECURSION_WITHOUT_EXCEPTION ) ;
5678           oe_debug_pub.add(  'JPN: GLOBAL CACHE BOOKED FLAG' || OE_ORDER_CACHE.G_HEADER_REC.BOOKED_FLAG ) ;
5679         oe_debug_pub.add(  'JPN: GLOBAL PICTURE HEADER BOOKED FLAG' || OE_ORDER_UTIL.G_HEADER_REC.BOOKED_FLAG ) ;
5680          oe_debug_pub.add(  'JPN: COUNT OF NEW LINE TABLE= '|| OE_ORDER_UTIL.G_LINE_TBL.COUNT ) ;
5681          oe_debug_pub.add(  'JPN: COUNT OF OLD LINE TABLE= '|| OE_ORDER_UTIL.G_OLD_LINE_TBL.COUNT ) ;
5682          oe_debug_pub.add(  'JPN: COUNT OF NEW LINE ADJ TABLE= '|| OE_ORDER_UTIL.G_LINE_ADJ_TBL.COUNT ) ;
5683         oe_debug_pub.add(  'JPN: COUNT OF OLD LINE ADJ TABLE= '|| OE_ORDER_UTIL.G_OLD_LINE_ADJ_TBL.COUNT ) ;
5684         oe_debug_pub.add(  'JPN: COUNT OF NEW HDR ADJ TABLE= '|| OE_ORDER_UTIL.G_HEADER_ADJ_TBL.COUNT ) ;
5685         oe_debug_pub.add(  'JPN: COUNT OF OLD HDR ADJ TABLE= '|| OE_ORDER_UTIL.G_OLD_HEADER_ADJ_TBL.COUNT ) ;
5686         oe_debug_pub.add(  'JPN: COUNT OF NEW HDR SCREDIT TABLE= '|| OE_ORDER_UTIL.G_HEADER_SCREDIT_TBL.COUNT ) ;
5687         oe_debug_pub.add(  'JPN: COUNT OF OLD HDR SCREDIT TABLE= '|| OE_ORDER_UTIL.G_OLD_HEADER_SCREDIT_TBL.COUNT ) ;
5688       oe_debug_pub.add(  'JPN: COUNT OF NEW LINE SCREDIT TABLE= '|| OE_ORDER_UTIL.G_LINE_SCREDIT_TBL.COUNT ) ;
5689         oe_debug_pub.add(  'JPN: COUNT OF OLD LINE SCREDIT TABLE= '|| OE_ORDER_UTIL.G_OLD_LINE_SCREDIT_TBL.COUNT ) ;
5690        oe_debug_pub.add(  'JPN: COUNT OF NEW LOT SERIAL TABLE= '|| OE_ORDER_UTIL.G_LOT_SERIAL_TBL.COUNT ) ;
5691         oe_debug_pub.add(  'JPN: COUNT OF OLD LOT SERIAL TABLE= '|| OE_ORDER_UTIL.G_OLD_LOT_SERIAL_TBL.COUNT ) ;
5692     END IF;
5693 
5694   /*check global pictures, to see if there's any record in the seven key entities*/
5695 
5696   IF ( OE_ORDER_UTIL.g_header_rec.header_id is not null
5697       OR OE_ORDER_UTIL.g_header_rec.header_id <> FND_API.G_MISS_NUM
5698       OR  OE_ORDER_UTIL.g_header_adj_tbl.count >0
5699       OR OE_ORDER_UTIL.g_Header_Scredit_tbl.count >0
5700 --    OR OE_ORDER_UTIL.g_Header_Payment_tbl.count >0
5701       OR OE_ORDER_UTIL.g_line_tbl.count >0
5702       OR OE_ORDER_UTIL.g_Line_Adj_tbl.count >0
5703       OR OE_ORDER_UTIL.g_Line_Scredit_tbl.count >0
5704 --    OR OE_ORDER_UTIL.g_Line_Payment_tbl.count >0
5705       OR  OE_ORDER_UTIL.g_Lot_Serial_tbl.count >0 ) THEN
5706 
5707 /* start of bug 2781468 hashraf */
5708 
5709 /* need to get the header_id which will then be passed to load_order_header
5710    to refresh the record in cache
5711 */
5712 
5713     l_index := 1;
5714 
5715     IF ( OE_ORDER_UTIL.g_header_rec.header_id is not null
5716          AND OE_ORDER_UTIL.g_header_rec.header_id <> FND_API.G_MISS_NUM) THEN
5717       l_header_id :=  OE_ORDER_UTIL.g_header_rec.header_id;
5718 
5719       IF l_debug_level  > 0 THEN
5720         oe_debug_pub.add('header id in g_header_rec is: ' || l_header_id ) ;
5721       END IF;
5722 
5723     ELSIF ( OE_ORDER_UTIL.g_header_adj_tbl.count >0 ) THEN
5724       IF l_debug_level > 0 THEN
5725         oe_debug_pub.add('Inside the header_adj_tbl loop');
5726       END IF;
5727       l_index := OE_ORDER_UTIL.g_header_adj_tbl.first;
5728       IF (l_index is not null) THEN
5729         l_header_id :=  OE_ORDER_UTIL.g_header_adj_tbl(l_index).header_id;
5730         IF l_debug_level > 0 THEN
5731         oe_debug_pub.add('header id in g_header_adj_tbl is: ' || l_header_id ) ;
5732         oe_debug_pub.add('l_index  in g_header_adj_tbl is: ' || l_index ) ;
5733         END IF;
5734       END IF;
5735 
5736     ELSIF ( OE_ORDER_UTIL.g_Header_Scredit_tbl.count >0 ) THEN
5737       IF l_debug_level > 0 THEN
5738         oe_debug_pub.add('Inside the header_Scredit_tbl loop');
5739       END IF;
5740       l_index := OE_ORDER_UTIL.g_header_Scredit_tbl.first;
5741       IF (l_index is not null) THEN
5742         l_header_id :=  OE_ORDER_UTIL.g_header_Scredit_tbl(l_index).header_id;
5743         IF l_debug_level > 0 THEN
5744         oe_debug_pub.add('header id in g_header_Scredit_tbl is: ' || l_header_id ) ;
5745         oe_debug_pub.add('l_index  in g_header_Scredit_tbl is: ' || l_index ) ;
5746         END IF;
5747       END IF;
5748 
5749     ELSIF ( OE_ORDER_UTIL.g_line_tbl.count >0 ) THEN
5750       IF l_debug_level > 0 THEN
5751         oe_debug_pub.add('Inside the line loop');
5752       END IF;
5753       l_index := OE_ORDER_UTIL.g_line_tbl.first;
5754       IF (l_index is not null) THEN
5755         l_header_id :=  OE_ORDER_UTIL.g_line_tbl(l_index).header_id;
5756         IF l_debug_level > 0 THEN
5757         oe_debug_pub.add('header id in g_line_tbl is: ' || l_header_id ) ;
5758         oe_debug_pub.add('l_index  in g_line_tbl is: ' || l_index ) ;
5759         END IF;
5760       END IF;
5761 
5762     ELSIF ( OE_ORDER_UTIL.g_line_adj_tbl.count >0 ) THEN
5763 
5764       IF l_debug_level > 0 THEN
5765         oe_debug_pub.add('Inside the line_adj loop');
5766       END IF;
5767       l_index := OE_ORDER_UTIL.g_line_adj_tbl.first;
5768       IF (l_index is not null) THEN
5769 
5770         l_header_id := OE_ORDER_UTIL.g_line_adj_tbl(l_index).header_id;
5771         IF l_debug_level > 0 THEN
5772           oe_debug_pub.add('header id in g_line_adj_tbl is: ' || l_header_id ) ;
5773           oe_debug_pub.add('l_index  in g_line_adj_tbl is: ' || l_index ) ;
5774         END IF;
5775       END IF;
5776 
5777     ELSIF ( OE_ORDER_UTIL.g_line_Scredit_tbl.count >0 ) THEN
5778 
5779       IF l_debug_level > 0 THEN
5780         oe_debug_pub.add('Inside the line_Scredit loop');
5781       END IF;
5782       l_index := OE_ORDER_UTIL.g_line_Scredit_tbl.first;
5783       IF (l_index is not null) THEN
5784 
5785         l_header_id := OE_ORDER_UTIL.g_line_Scredit_tbl(l_index).header_id;
5786         IF l_debug_level > 0 THEN
5787           oe_debug_pub.add('header id in g_line_Scredit_tbl is: ' || l_header_id );
5788           oe_debug_pub.add('l_index  in g_line_Scredit_tbl is: ' || l_index ) ;
5789         END IF;
5790       END IF;
5791 
5792     ELSIF ( OE_ORDER_UTIL.g_Lot_Serial_tbl.count >0 ) THEN
5793       IF l_debug_level > 0 THEN
5794         oe_debug_pub.add('Inside the group by_lot_serial loop');
5795       END IF;
5796       l_index := OE_ORDER_UTIL.g_Lot_Serial_tbl.first;
5797       IF (l_index is not null) THEN
5798         l_line_id := OE_ORDER_UTIL.g_Lot_Serial_tbl(l_index).line_id;
5799 
5800         BEGIN
5801           SELECT header_id
5802  	  INTO l_header_id
5803  	  FROM OE_ORDER_LINES_ALL
5804  	  WHERE line_id = l_line_id;
5805         EXCEPTION
5806  	  WHEN NO_DATA_FOUND THEN
5807     	    null;
5808         END;
5809 
5810         IF l_debug_level  > 0 THEN
5811           oe_debug_pub.add('header id in g_Lot_Serial_tbl is: ' || l_header_id);
5812           oe_debug_pub.add('line id in g_Lot_Serial_tbl is: ' || l_line_id);
5813           oe_debug_pub.add('l_index in g_Lot_Serial_tbl is: ' || l_index);
5814         END IF;
5815       END IF; -- l_index is not null in g_lot
5816 
5817     END IF;  -- end if-elsif
5818 
5819     IF l_debug_level  > 0 THEN
5820         oe_debug_pub.add(  'header id is: ' || l_header_id ) ;
5821     END IF;
5822 
5823     IF (l_header_id is not null AND l_header_id <> FND_API.G_MISS_NUM) THEN
5824 
5825       IF l_debug_level  > 0 THEN
5826         oe_debug_pub.add('Just before calling Load_Order_Header');
5827       END IF;
5828 
5829       Oe_Order_Cache.Load_Order_Header(l_header_id);
5830     END IF;
5831 
5832     IF l_debug_level  > 0 THEN
5833       oe_debug_pub.add('Out of Load_Order_Header in PRN');
5834     END IF;
5835 /* end of bug 2781468*/
5836 
5837     IF (OE_ORDER_UTIL.G_Recursion_Without_Exception = 'N' AND
5838        OE_ORDER_CACHE.g_header_rec.booked_flag = 'Y') THEN
5839 
5840     IF l_debug_level  > 0 THEN
5841         oe_debug_pub.add(  'POST PACK H. CALLING NOTIFY_OC API' , 1 ) ;
5842     END IF;
5843 
5844     OE_SERVICE_UTIL.Notify_OC
5845     (   p_api_version_number                  =>  1.0
5846     ,   p_init_msg_list                       =>  FND_API.G_FALSE
5847     ,   x_return_status                       =>  l_return_status
5848     ,   x_msg_count                           =>  l_msg_count
5849     ,   x_msg_data                            =>  l_msg_data
5850     ,   p_header_rec                          =>  OE_ORDER_UTIL.g_header_rec
5851     ,   p_old_header_rec                      =>  OE_ORDER_UTIL.g_old_header_rec
5852     ,   p_header_adj_tbl                      =>  OE_ORDER_UTIL.g_header_adj_tbl
5853     ,   p_old_header_adj_tbl		      =>  OE_ORDER_UTIL.g_old_header_adj_tbl
5854     ,   p_Header_Scredit_tbl                  =>  OE_ORDER_UTIL.g_Header_Scredit_tbl
5855     ,   p_old_Header_Scredit_tbl              =>  OE_ORDER_UTIL.g_old_Header_Scredit_tbl
5856 --  ,   p_Header_Payment_tbl                  =>  OE_ORDER_UTIL.g_Header_Payment_tbl
5857 --  ,   p_old_Header_Payment_tbl              =>  OE_ORDER_UTIL.g_old_Header_Payment_tbl
5858     ,   p_line_tbl                            =>  OE_ORDER_UTIL.g_line_tbl
5859     ,   p_old_line_tbl                        =>  OE_ORDER_UTIL.g_old_line_tbl
5860     ,   p_Line_Adj_tbl                        =>  OE_ORDER_UTIL.g_Line_Adj_tbl
5861     ,   p_old_Line_Adj_tbl                    =>  OE_ORDER_UTIL.g_old_Line_Adj_tbl
5862     ,   p_Line_Scredit_tbl                    =>  OE_ORDER_UTIL.g_Line_Scredit_tbl
5863     ,   p_old_Line_Scredit_tbl                =>  OE_ORDER_UTIL.g_old_Line_Scredit_tbl
5864 --  ,   p_Line_Payment_tbl                    =>  OE_ORDER_UTIL.g_Line_Payment_tbl
5865 --  ,   p_old_Line_Payment_tbl                =>  OE_ORDER_UTIL.g_old_Line_Payment_tbl
5866     ,   p_Lot_Serial_tbl                      =>  OE_ORDER_UTIL.g_Lot_Serial_tbl
5867     ,   p_old_Lot_Serial_tbl                  =>  OE_ORDER_UTIL.g_old_Lot_Serial_tbl
5868     );
5869 
5870        IF l_debug_level  > 0 THEN
5871            oe_debug_pub.add(  'AFTER NOTIFY_OC API' , 1 ) ;
5872        END IF;
5873 	  IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5874           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5875        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5876           RAISE FND_API.G_EXC_ERROR;
5877        END IF;
5878 
5879 
5880     END IF;
5881 
5882     IF l_debug_level  > 0 THEN
5883         oe_debug_pub.add(  'PROCESSING ACKS' , 1 ) ;
5884         oe_debug_pub.add(  'PACKS ' || OE_ORDER_UTIL.G_RECURSION_WITHOUT_EXCEPTION , 1 ) ;
5885         oe_debug_pub.add(  'PACKS' || OE_ORDER_CACHE.G_HEADER_REC.BOOKED_FLAG , 1 ) ;
5886     END IF;
5887 
5888     IF (OE_ORDER_UTIL.G_Recursion_Without_Exception = 'N' AND
5889        OE_ORDER_CACHE.g_header_rec.booked_flag = 'Y' AND p_process_ack) THEN
5890 
5891       IF l_debug_level  > 0 THEN
5892           oe_debug_pub.add(  'POST PACK H.CALLING ACKS API' , 1 ) ;
5893       END IF;
5894 
5895      -- { Start 3A6 changes, Design will still honor the Booking as
5896      --   the starting point of the triggering of the Show Sales Order
5897      --   collaboration. Later some point If we decided (by Cust requirment)
5898      --   that it should not wait till booking and workflow solution is not
5899      --   acceptable, we should review this code to removed the booking
5900      --   condition, i.e. write a new if for 3A6.
5901 
5902      -- { Start of If order_source_id = 20
5903      --   The below condition will only executed for the the XML Xactions
5904     IF l_debug_level  > 0 THEN
5905         oe_debug_pub.add(  'PACKS ' || OE_ORDER_CACHE.G_HEADER_REC.ORDER_SOURCE_ID , 1 ) ;
5906         oe_debug_pub.add(  'PACKS ' || OE_ORDER_CACHE.G_HEADER_REC.SOLD_TO_ORG_ID , 1 ) ;
5907     END IF;
5908 
5909      If  OE_ORDER_CACHE.g_header_rec.order_source_id in (20) OR
5910          (OE_GENESIS_UTIL.source_aia_enabled(OE_ORDER_CACHE.g_header_rec.order_source_id)) THEN -- GENESIS
5911 
5912 
5913       OE_Acknowledgment_Pub.Process_SSO
5914      (p_api_version_number              => 1
5915      ,p_init_msg_list                   => FND_API.G_FALSE
5916      ,p_header_rec                      => OE_ORDER_CACHE.g_header_rec
5917      ,p_line_tbl                        => OE_ORDER_UTIL.g_line_tbl
5918      ,p_old_header_rec                  => OE_ORDER_UTIL.g_old_header_rec
5919      ,p_old_line_tbl                    => OE_ORDER_UTIL.g_old_line_tbl
5920 
5921      ,x_return_status                   => l_return_status
5922      );
5923 
5924      --   The below condition to leave the existing flow to work as it is
5925      Elsif Oe_Code_Control.Code_Release_Level >= '110510' And
5926            OE_ORDER_CACHE.g_header_rec.order_source_id in (0,2,6) And
5927            l_edi_ack_pfile = 'YES' Then
5928         OE_Acknowledgment_Pvt.Process_Acknowledgment
5929         (p_header_rec           => OE_ORDER_UTIL.g_header_rec,
5930          p_line_tbl             => OE_ORDER_UTIL.g_line_tbl,
5931          p_old_header_rec       => OE_ORDER_UTIL.g_old_header_rec,
5932          p_old_line_tbl         => OE_ORDER_UTIL.g_old_line_tbl,
5933          x_return_status        => l_return_status);
5934      Elsif l_edi_ack_pfile = 'NO' And
5935            OE_ORDER_CACHE.g_header_rec.order_source_id in (0,2,6) Then
5936       OE_Acknowledgment_Pvt.Process_Acknowledgment
5937      (p_api_version_number 		=> 1
5938      ,p_init_msg_list 		        => FND_API.G_FALSE
5939      ,p_header_rec 			=> OE_ORDER_UTIL.g_header_rec
5940      ,p_header_adj_tbl		        => OE_ORDER_UTIL.g_header_adj_tbl
5941      ,p_header_Scredit_tbl		=> OE_ORDER_UTIL.g_header_scredit_tbl
5942      ,p_line_tbl 			=> OE_ORDER_UTIL.g_line_tbl
5943      ,p_line_adj_tbl			=> OE_ORDER_UTIL.g_line_adj_tbl
5944      ,p_line_scredit_tbl		=> OE_ORDER_UTIL.g_line_scredit_tbl
5945      ,p_lot_serial_tbl		        => OE_ORDER_UTIL.g_lot_serial_tbl
5946      ,p_old_header_rec 		   	=> OE_ORDER_UTIL.g_old_header_rec
5947      ,p_old_header_adj_tbl 		=> OE_ORDER_UTIL.g_old_header_adj_tbl
5948      ,p_old_header_Scredit_tbl 	   	=> OE_ORDER_UTIL.g_old_header_scredit_tbl
5949      ,p_old_line_tbl 		        => OE_ORDER_UTIL.g_old_line_tbl
5950      ,p_old_line_adj_tbl 		=> OE_ORDER_UTIL.g_old_line_adj_tbl
5951      ,p_old_line_scredit_tbl 	   	=> OE_ORDER_UTIL.g_old_line_scredit_tbl
5952      ,p_old_lot_serial_tbl		=> OE_ORDER_UTIL.g_old_lot_serial_tbl
5953 
5954      ,p_buyer_seller_flag           	=> 'B'
5955      ,p_reject_order                	=> 'N'
5956 
5957      ,x_return_status                   => l_return_status
5958      );
5959 
5960      End If;
5961      -- End of If order_source_id = 20 }
5962      -- End 3A6 changes}
5963 
5964      IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5965         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5966      ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5967         RAISE FND_API.G_EXC_ERROR;
5968         x_return_status := l_return_status;
5969      END IF;
5970 
5971     END IF;
5972 
5973 -- DBI project changes start
5974     IF l_debug_level  > 0 THEN
5975         oe_debug_pub.add(  'CALLING OE_DBI_UTIL' , 1 ) ;
5976         oe_debug_pub.add(  'CACHED VALUE' || OE_ORDER_CACHE.G_HEADER_REC.BOOKED_FLAG ) ;
5977         oe_debug_pub.add(  'RECURSION VALUE' || OE_ORDER_UTIL.G_RECURSION_WITHOUT_EXCEPTION ) ;
5978         oe_debug_pub.add(  'PROFILE VALUE' || FND_PROFILE.VALUE ( 'ONT_DBI_INSTALLED' ) ) ;
5979     END IF;
5980 
5981     IF  NVL(FND_PROFILE.VALUE('ONT_DBI_INSTALLED'), 'N') = 'Y' AND
5982      oe_order_cache.g_header_rec.booked_flag = 'Y' AND
5983      OE_ORDER_UTIL.G_Recursion_Without_Exception = 'N'
5984    -- AND p_header_rec.header_id IS NOT NULL AND
5985     --p_header_rec.header_id <> FND_API.G_MISS_NUM
5986    THEN
5987     OE_DBI_UTIL.Update_DBI_Log( x_return_status  => l_return_status);
5988 
5989       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5990         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5991      ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5992         RAISE FND_API.G_EXC_ERROR;
5993         x_return_status := l_return_status;
5994      END IF;
5995     END IF;
5996    -- DBI project changes end
5997 
5998 
5999 
6000     /* Now clear the global pl/sql tables */
6001     /* Also clear for >= 11i10 for versioning */
6002     IF (OE_ORDER_UTIL.G_Recursion_Without_Exception = 'N' AND
6003        (OE_ORDER_CACHE.g_header_rec.booked_flag = 'Y' OR
6004         OE_CODE_CONTROL.Code_Release_Level >= '110510' )) THEN
6005     OE_ORDER_UTIL.Clear_Global_Picture(l_return_status);
6006     END IF;
6007 
6008    END IF;     /*check for record in key entities*/
6009  END IF; /*code_release_level*/
6010 
6011  /* Fix Bug # 3241831: Reset Global after all requests have been processed */
6012  IF OE_GLOBALS.G_RECURSION_MODE = 'N' AND OE_GLOBALS.G_UI_FLAG = FALSE THEN
6013    IF OE_OE_FORM_CANCEL_LINE.g_ord_lvl_can THEN
6014      IF l_debug_level  > 0 THEN
6015        oe_debug_pub.add('SET G_ORD_LVL_CAN TO FALSE FOR NON UI ORDER CANCEL');
6016      END IF;
6017      OE_OE_FORM_CANCEL_LINE.g_ord_lvl_can := FALSE;
6018    END IF;
6019  END IF;
6020 
6021   --resetting g_header_created flag
6022     IF OE_GLOBALS.G_RECURSION_MODE <> 'Y' AND
6023        OE_GLOBALS.G_PRICING_RECURSION <> 'Y' THEN
6024        OE_GLOBALS.G_HEADER_CREATED := FALSE;
6025     END IF;
6026 
6027     IF l_debug_level  > 0 THEN
6028         oe_debug_pub.add(  'EXIT OE_ORDER_PVT.PROCESS_REQUESTS_AND_NOTIFY' , 1 ) ;
6029     END IF;
6030     set_recursion_mode(p_Entity_Code => 8,
6031                                    p_In_out  => 0);
6032     IF l_debug_level  > 0 THEN
6033         oe_debug_pub.add(  'GLOBAL REQUEST TABLE COUNT- PRN'|| OE_DELAYED_REQUESTS_PVT.G_DELAYED_REQUESTS.COUNT , 1 ) ;
6034     END IF;
6035 
6036 
6037 EXCEPTION
6038 
6039     WHEN FND_API.G_EXC_ERROR THEN
6040 
6041         set_recursion_mode(p_Entity_Code => 8,
6042                                    p_In_out  => 0);
6043         x_return_status := FND_API.G_RET_STS_ERROR;
6044         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
6045            OE_DELAYED_REQUESTS_PVT.Clear_Request(l_return_status);
6046            IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110508' THEN
6047                  OE_ORDER_UTIL.Clear_Global_Picture(l_return_status);
6048            END IF;
6049         END IF;
6050 
6051     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6052 
6053         set_recursion_mode(p_Entity_Code => 8,
6054                                    p_In_out  => 0);
6055         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6056         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
6057            OE_DELAYED_REQUESTS_PVT.Clear_Request(l_return_status);
6058            IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110508' THEN
6059                  OE_ORDER_UTIL.Clear_Global_Picture(l_return_status);
6060            END IF;
6061         END IF;
6062 
6063     WHEN OTHERS THEN
6064 
6065         set_recursion_mode(p_Entity_Code => 8,
6066                                    p_In_out  => 0);
6067         IF l_debug_level  > 0 THEN
6068             oe_debug_pub.add(  'PO: EXITING PROCESS_REQUESTS_AND_NOTIFY WITH OTHERS ERROR' , 2 ) ;
6069         END IF;
6070         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6071         IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
6072            OE_DELAYED_REQUESTS_PVT.Clear_Request(l_return_status);
6073             IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110508' THEN
6074                  OE_ORDER_UTIL.Clear_Global_Picture(l_return_status);
6075            END IF;
6076         END IF;
6077         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6078         THEN
6079             OE_MSG_PUB.Add_Exc_Msg
6080             (   G_PKG_NAME
6081             ,   'Process_Requests_And_Notify'
6082             );
6083         END IF;
6084 
6085 END Process_Requests_And_Notify;
6086 
6087 PROCEDURE Process_Order_AG
6088 (   p_api_version_number            IN  NUMBER
6089 ,   p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
6090 ,   p_validation_level              IN  NUMBER := FND_API.G_VALID_LEVEL_FULL
6091 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type :=
6092                                         OE_GLOBALS.G_MISS_CONTROL_REC
6093 , x_return_status OUT NOCOPY VARCHAR2
6094 
6095 , x_msg_count OUT NOCOPY NUMBER
6096 
6097 , x_msg_data OUT NOCOPY VARCHAR2
6098 
6099 ,   p_x_header_rec                  IN OUT NOCOPY OE_Order_PUB.Header_Rec_Type
6100 ,   p_old_header_rec                IN  OE_Order_PUB.Header_Rec_Type :=
6101                                         OE_Order_PUB.G_MISS_HEADER_REC
6102 ,   p_x_Header_Adj_tbl              IN OUT NOCOPY OE_Order_PUB.Header_Adj_Tbl_Type
6103 ,   p_old_Header_Adj_tbl            IN  OE_Order_PUB.Header_Adj_Tbl_Type :=
6104                                         OE_Order_PUB.G_MISS_HEADER_ADJ_TBL
6105 ,   p_x_Header_Price_Att_tbl        IN OUT NOCOPY OE_Order_PUB.Header_Price_Att_Tbl_Type
6106 ,   p_old_Header_Price_Att_tbl      IN  OE_Order_PUB.Header_Price_Att_Tbl_Type :=
6107                                         OE_Order_PUB.G_MISS_HEADER_PRICE_ATT_TBL
6108 ,   p_x_Header_Adj_Att_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Adj_Att_Tbl_Type
6109 ,   p_old_Header_Adj_Att_tbl        IN  OE_Order_PUB.Header_Adj_Att_Tbl_Type :=
6110     								OE_Order_PUB.G_MISS_HEADER_ADJ_ATT_TBL
6111 ,   p_x_Header_Adj_Assoc_tbl        IN OUT NOCOPY OE_Order_PUB.Header_Adj_Assoc_Tbl_Type
6112 ,   p_old_Header_Adj_Assoc_tbl      IN  OE_Order_PUB.Header_Adj_Assoc_Tbl_Type :=
6113     								OE_Order_PUB.G_MISS_HEADER_ADJ_ASSOC_TBL
6114 ,   p_x_Header_Scredit_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Scredit_Tbl_Type
6115 ,   p_old_Header_Scredit_tbl        IN  OE_Order_PUB.Header_Scredit_Tbl_Type :=
6116                                         OE_Order_PUB.G_MISS_HEADER_SCREDIT_TBL
6117 ,   p_x_Header_Payment_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Payment_Tbl_Type
6118 ,   p_old_Header_Payment_tbl        IN  OE_Order_PUB.Header_Payment_Tbl_Type :=
6119                                         OE_Order_PUB.G_MISS_HEADER_PAYMENT_TBL
6120 ,   p_x_line_tbl                    IN OUT NOCOPY OE_Order_PUB.Line_Tbl_Type
6121 ,   p_old_line_tbl                  IN  OE_Order_PUB.Line_Tbl_Type :=
6122                                         OE_Order_PUB.G_MISS_LINE_TBL
6123 ,   p_x_Line_Adj_tbl                IN OUT NOCOPY OE_Order_PUB.Line_Adj_Tbl_Type
6124 ,   p_old_Line_Adj_tbl              IN  OE_Order_PUB.Line_Adj_Tbl_Type :=
6125                                         OE_Order_PUB.G_MISS_LINE_ADJ_TBL
6126 ,   p_x_Line_Price_Att_tbl          IN OUT NOCOPY OE_Order_PUB.Line_Price_Att_Tbl_Type
6127 ,   p_old_Line_Price_Att_tbl        IN  OE_Order_PUB.Line_Price_Att_Tbl_Type :=
6128                                         OE_Order_PUB.G_MISS_LINE_PRICE_ATT_TBL
6129 ,   p_x_Line_Adj_Att_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Adj_Att_Tbl_Type
6130 ,   p_old_Line_Adj_Att_tbl          IN  OE_Order_PUB.Line_Adj_Att_Tbl_Type :=
6131     								OE_Order_PUB.G_MISS_LINE_ADJ_ATT_TBL
6132 ,   p_x_Line_Adj_Assoc_tbl          IN OUT NOCOPY OE_Order_PUB.Line_Adj_Assoc_Tbl_Type
6133 ,   p_old_Line_Adj_Assoc_tbl        IN  OE_Order_PUB.Line_Adj_Assoc_Tbl_Type :=
6134     								OE_Order_PUB.G_MISS_LINE_ADJ_ASSOC_TBL
6135 ,   p_x_Line_Scredit_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Scredit_Tbl_Type
6136 ,   p_old_Line_Scredit_tbl          IN  OE_Order_PUB.Line_Scredit_Tbl_Type :=
6137                                         OE_Order_PUB.G_MISS_LINE_SCREDIT_TBL
6138 ,   p_x_Line_Payment_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Payment_Tbl_Type
6139 ,   p_old_Line_Payment_tbl          IN  OE_Order_PUB.Line_Payment_Tbl_Type :=
6140                                         OE_Order_PUB.G_MISS_LINE_PAYMENT_TBL
6141 ,   p_x_Lot_Serial_tbl              IN OUT NOCOPY OE_Order_PUB.Lot_Serial_Tbl_Type
6142 ,   p_old_Lot_Serial_tbl            IN  OE_Order_PUB.Lot_Serial_Tbl_Type :=
6143                                         OE_Order_PUB.G_MISS_LOT_SERIAL_TBL
6144 ,   p_Lot_Serial_val_tbl            IN  OE_Order_PUB.Lot_Serial_Val_Tbl_Type :=
6145                                         OE_Order_PUB.G_MISS_LOT_SERIAL_VAL_TBL
6146 ,   p_old_Lot_Serial_val_tbl        IN  OE_Order_PUB.Lot_Serial_Val_Tbl_Type :=
6147                                         OE_Order_PUB.G_MISS_LOT_SERIAL_VAL_TBL
6148 ,   p_x_action_request_tbl	      IN OUT NOCOPY OE_Order_PUB.request_tbl_type
6149 ,   p_action_commit				 IN  VARCHAR2 := FND_API.G_FALSE
6150 )
6151 IS
6152 l_api_version_number          CONSTANT NUMBER := 1.0;
6153 l_control_rec                 OE_GLOBALS.Control_Rec_Type := p_control_rec;
6154 l_return_status      VARCHAR2(1);
6155 I                    NUMBER;
6156 l_header_id          NUMBER;
6157 l_call_split         BOOLEAN := FALSE;
6158 l_line_index         NUMBER;
6159 l_old_header_rec              OE_Order_PUB.Header_Rec_Type ;
6160 l_old_Header_Adj_tbl          OE_Order_PUB.Header_Adj_Tbl_Type;
6161 l_Old_Header_price_Att_Tbl    OE_Order_PUB.Header_Price_Att_Tbl_Type ;
6162 l_Old_Header_Adj_Att_Tbl      OE_Order_PUB.Header_Adj_Att_Tbl_Type ;
6163 l_old_Header_Adj_Assoc_tbl    OE_Order_PUB.Header_Adj_Assoc_Tbl_Type ;
6164 l_old_Header_Scredit_tbl      OE_Order_PUB.Header_Scredit_Tbl_Type;
6165 l_old_Header_Payment_tbl      OE_Order_PUB.Header_Payment_Tbl_Type;
6166 l_old_line_tbl                OE_Order_PUB.Line_Tbl_Type;
6167 l_old_Line_Adj_tbl            OE_Order_PUB.Line_Adj_Tbl_Type;
6168 l_Old_Line_price_Att_Tbl      OE_Order_PUB.Line_Price_Att_Tbl_Type ;
6169 l_old_Line_Adj_Att_tbl        OE_Order_PUB.Line_Adj_Att_Tbl_Type ;
6170 l_old_Line_Adj_Assoc_tbl      OE_Order_PUB.Line_Adj_Assoc_Tbl_Type ;
6171 l_old_Line_Scredit_tbl        OE_Order_PUB.Line_Scredit_Tbl_Type;
6172 l_old_Line_Payment_tbl        OE_Order_PUB.Line_Payment_Tbl_Type;
6173 l_old_Lot_Serial_tbl          OE_Order_PUB.Lot_Serial_Tbl_Type;
6174 l_old_Lot_Serial_val_tbl      OE_Order_PUB.Lot_Serial_Val_Tbl_Type;
6175 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6176 l_edi_ack_pfile               Varchar2(3);
6177 l_transaction_phase_code      VARCHAR2(1); -- Added for bug 4758902
6178 BEGIN
6179 IF l_debug_level  > 0 THEN
6180     oe_debug_pub.add(  'ENTER PROCESS_ORDER_AG' , 1 ) ;
6181 END IF;
6182 
6183     -- Initialize x_return_status
6184     x_return_status  := FND_API.G_RET_STS_SUCCESS;
6185     fnd_profile.get('ONT_NEW_EDI_ACK_FWK', l_edi_ack_pfile);
6186     l_edi_ack_pfile := nvl(l_edi_ack_pfile, 'NO');
6187 
6188     --  Init local table variables for old tables as these are only
6189     --  IN params.
6190 
6191     l_old_header_Rec               := p_old_header_rec;
6192     l_old_Header_Adj_tbl           := p_old_Header_Adj_tbl;
6193     l_old_Header_price_Att_tbl    := p_old_Header_Price_Att_Tbl;
6194     l_old_Header_Adj_Att_tbl      := p_old_Header_Adj_Att_Tbl;
6195     l_old_Header_Adj_Assoc_tbl    := P_old_Header_Adj_Assoc_Tbl;
6196     l_old_Header_Scredit_tbl       := p_old_Header_Scredit_tbl;
6197     l_old_Header_Payment_tbl       := p_old_Header_Payment_tbl;
6198     l_old_line_tbl                 := p_old_line_tbl;
6199     l_old_Line_Adj_tbl             := p_old_Line_Adj_tbl;
6200     l_old_Line_price_Att_tbl    := p_old_Line_Price_Att_Tbl;
6201     l_old_Line_Adj_Att_tbl      := p_old_Line_Adj_Att_Tbl;
6202     l_old_Line_Adj_Assoc_tbl    := P_old_Line_Adj_Assoc_Tbl;
6203     l_old_Line_Scredit_tbl         := p_old_Line_Scredit_tbl;
6204     l_old_Line_Payment_tbl         := p_old_Line_Payment_tbl;
6205     l_old_Lot_Serial_tbl           := p_old_Lot_Serial_tbl;
6206 
6207 
6208     IF l_debug_level  > 0 THEN
6209         oe_debug_pub.add(  'BEFORE HEADER PROCESSING' , 2 ) ;
6210         oe_debug_pub.add(  'HEADER_ID' || P_X_HEADER_REC.HEADER_ID , 2 ) ;
6211         oe_debug_pub.add(  'OPERATION' || P_X_HEADER_REC.OPERATION , 2 ) ;
6212     END IF;
6213 
6214     -------------------------------------------------------
6215     -- Process Header
6216     -------------------------------------------------------
6217 
6218     --Bug 2790512: Prevent processing of header if operation is invalid
6219     --Bug 2878121: Ignore NULL operation code
6220    IF p_x_header_rec.header_id is NOT NULL AND
6221 	p_x_header_rec.header_id <> FND_API.G_MISS_NUM THEN
6222     IF  p_x_header_rec.operation IS NOT NULL AND
6223         p_x_header_rec.operation NOT IN (OE_GLOBALS.G_OPR_CREATE,
6224               OE_GLOBALS.G_OPR_DELETE, OE_GLOBALS.G_OPR_UPDATE,
6225               OE_GLOBALS.G_OPR_NONE) THEN
6226            FND_MESSAGE.SET_NAME('ONT','OE_OI_OPERATION_CODE');
6227            OE_MSG_PUB.Add;
6228            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6229     END IF;
6230   END IF;
6231 
6232     IF p_x_header_rec.operation IS NOT NULL
6233 	  AND p_x_header_rec.operation <> OE_GLOBALS.G_OPR_NONE
6234     THEN
6235 
6236     -- This if is add to honor users sales credits if they do not
6237     -- want the default sales credit for the salesrep on the order
6238 
6239     IF p_x_header_scredit_tbl.COUNT > 0 and
6240 	  p_x_header_rec.operation = oe_globals.g_opr_create THEN
6241       OE_Validate_Header_Scredit.G_Create_Auto_Sales_Credit  := 'N';
6242     END IF;
6243 
6244       Header
6245       (   p_validation_level            => p_validation_level
6246       ,   p_control_rec                 => p_control_rec
6247       ,   p_x_header_rec                => p_x_header_rec
6248       ,   p_x_old_header_rec            => l_old_header_rec
6249       ,   x_return_status               => l_return_status
6250       );
6251 
6252       OE_Validate_Header_Scredit.G_Create_Auto_Sales_Credit  := 'Y';
6253 
6254       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6255        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6256       ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
6257        RAISE FND_API.G_EXC_ERROR;
6258       END IF;
6259     END IF;
6260       IF l_debug_level  > 0 THEN
6261           oe_debug_pub.add(  'AFTER HEADER PROCESSING HEADER_ID = '|| TO_CHAR ( P_X_HEADER_REC.HEADER_ID ) , 2 ) ;
6262       END IF;
6263 
6264     --  Perform header group requests.
6265 
6266     IF (p_control_rec.process AND
6267     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
6268         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
6269         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_HEADER)
6270     THEN
6271 
6272         NULL;
6273 
6274     END IF;
6275 
6276 
6277     -------------------------------------------------------
6278     -- Process Header Adjustments
6279     -------------------------------------------------------
6280 
6281     -- Set Header Id on Hdr Adjustments
6282 
6283     I := p_x_header_adj_tbl.FIRST;
6284     WHILE I IS NOT NULL LOOP
6285 
6286     --    FOR I IN 1..p_x_header_adj_tbl.COUNT LOOP
6287 
6288         IF l_debug_level  > 0 THEN
6289             oe_debug_pub.add(  'SETTING HEADER ID ON HDR_ADJ_TBL' , 2 ) ;
6290         END IF;
6291 
6292         IF p_x_header_adj_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
6293         AND (p_x_header_adj_tbl(I).header_id IS NULL OR
6294             p_x_header_adj_tbl(I).header_id = FND_API.G_MISS_NUM)
6295         THEN
6296           IF p_x_header_rec.header_id IS NULL OR
6297              p_x_header_rec.header_id = FND_API.G_MISS_NUM THEN
6298                FND_MESSAGE.SET_NAME('ONT','OE_HEADER_MISSING');
6299                OE_MSG_PUB.Add;
6300                RAISE FND_API.G_EXC_ERROR;
6301           ELSE
6302             --  Copy parent_id.
6303             p_x_header_adj_tbl(I).header_id := p_x_header_rec.header_id;
6304           END IF;
6305         END IF;
6306 
6307         -- This is added to prevent invalid  upgraded orders
6308         IF I = p_x_header_adj_tbl.FIRST THEN
6309            IF  (p_x_header_adj_tbl(I).header_id IS NOT NULL AND
6310 		      p_x_header_adj_tbl(I).header_id <> FND_API.G_MISS_NUM) THEN
6311 	      IF NOT Valid_Upgraded_Order(p_x_header_adj_tbl(I).header_id ) THEN
6312                  RAISE FND_API.G_EXC_ERROR;
6313            END IF;
6314         END IF;
6315 
6316     END IF;
6317 
6318         I := p_x_header_adj_tbl.NEXT(I);
6319 
6320     END LOOP;
6321 
6322     --  Header_Adjs
6323 
6324     IF p_x_header_adj_tbl.COUNT > 0 THEN
6325       IF l_debug_level  > 0 THEN
6326           oe_debug_pub.add(  'BEFORE OE_ORDER_ADJ_PVT.HEADER_ADJS PROCESSING' , 2 ) ;
6327       END IF;
6328       oe_order_adj_pvt.Header_Adjs
6329       (   p_validation_level            => p_validation_level
6330       ,   p_control_rec                 => p_control_rec
6331       ,   p_x_Header_Adj_tbl            => p_x_header_adj_tbl
6332       ,   p_x_old_Header_Adj_tbl        => l_old_header_Adj_tbl
6333       );
6334     END IF;
6335 
6336         IF l_debug_level  > 0 THEN
6337             oe_debug_pub.add(  'AFTER HEADER_ADJS PROCESSING' , 2 ) ;
6338         END IF;
6339     --  Perform Header_Adj group requests.
6340 
6341     IF (p_control_rec.process AND
6342       OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
6343         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
6344         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_HEADER_ADJ)
6345     THEN
6346 
6347        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
6348           (p_entity_code   => OE_GLOBALS.G_ENTITY_HEADER_ADJ
6349           ,p_delete        => FND_API.G_TRUE
6350           ,x_return_status => l_return_status
6351           );
6352        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6353                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6354        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
6355                  RAISE FND_API.G_EXC_ERROR;
6356        END IF;
6357 
6358 
6359     END IF;
6360 
6361 
6362     -------------------------------------------------------
6363     -- Process Header Price Attributes
6364     -------------------------------------------------------
6365 
6366     -- Set Header Id on Hdr Price Attributes
6367 
6368     I := p_x_header_price_att_tbl.FIRST;
6369 
6370     WHILE I IS NOT NULL LOOP
6371 
6372         IF l_debug_level  > 0 THEN
6373             oe_debug_pub.add(  'SETTING HEADER ID ON HDR_PRICE_ATT_TBL' , 2 ) ;
6374         END IF;
6375         IF p_x_header_price_att_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
6376         AND (p_x_header_price_att_tbl(I).header_id IS NULL OR
6377             p_x_header_price_att_tbl(I).header_id = FND_API.G_MISS_NUM)
6378         THEN
6379           IF p_x_header_rec.header_id IS NULL OR
6380              p_x_header_rec.header_id = FND_API.G_MISS_NUM THEN
6381                FND_MESSAGE.SET_NAME('ONT','OE_HEADER_MISSING');
6382                OE_MSG_PUB.Add;
6383                RAISE FND_API.G_EXC_ERROR;
6384           ELSE
6385 
6386             --  Copy parent_id.
6387 
6388             p_x_header_price_Att_tbl(I).header_id := p_x_header_rec.header_id;
6389           END IF;
6390         END IF;
6391         I := p_x_header_price_Att_tbl.NEXT(I);
6392     END LOOP;
6393 
6394     --  Header_Price_Atts
6395 
6396     IF p_x_header_price_Att_tbl.COUNT > 0 THEN
6397       IF l_debug_level  > 0 THEN
6398           oe_debug_pub.add(  'BEFORE OE_ORDER_ADJ_PVT.HEADER_PRICE_ATTS PROCESSING' , 2 ) ;
6399       END IF;
6400       oe_order_adj_pvt.Header_Price_Atts
6401       (   p_validation_level            => p_validation_level
6402       ,   p_control_rec                 => p_control_rec
6403       ,   p_x_Header_Price_Att_tbl      => p_x_header_price_Att_tbl
6404       ,   p_x_old_Header_Price_Att_tbl  => l_old_header_Price_Att_tbl
6405       );
6406     END IF;
6407 
6408         IF l_debug_level  > 0 THEN
6409             oe_debug_pub.add(  'AFTER HEADER_PRICE_ATTS PROCESSING' , 2 ) ;
6410         END IF;
6411     --  Perform Header_Price_Att group requests.
6412 
6413     IF (p_control_rec.process AND
6414       OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
6415         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL
6416 	   OR
6417         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_Header_Price_Att
6418 	   )
6419     THEN
6420 
6421        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
6422           (p_entity_code   => OE_GLOBALS.G_ENTITY_Header_Price_Att
6423           ,p_delete        => FND_API.G_TRUE
6424           ,x_return_status => l_return_status
6425           );
6426        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6427                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6428        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
6429                  RAISE FND_API.G_EXC_ERROR;
6430        END IF;
6431 
6432 
6433     END IF;
6434 
6435 
6436     -------------------------------------------------------
6437     -- Process Header Adj Attributes
6438     -------------------------------------------------------
6439 
6440     -- Set Header Id on Hdr Adj. Attributes
6441 
6442     I := p_x_header_adj_Att_tbl.FIRST;
6443 
6444     WHILE I IS NOT NULL LOOP
6445 
6446         IF l_debug_level  > 0 THEN
6447             oe_debug_pub.add(  'SETTING PRICE ADJUSTMENT ID ON HDR_ADJ_ATTBS' , 2 ) ;
6448         END IF;
6449         IF p_x_header_adj_att_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
6450         AND (p_x_header_adj_att_tbl(I).price_adjustment_id IS NULL OR
6451             p_x_header_adj_att_tbl(I).price_adjustment_id = FND_API.G_MISS_NUM)
6452         THEN
6453 
6454 		  IF p_x_header_adj_Tbl.exists(p_x_header_adj_att_tbl(I).Adj_index)
6455 			Then
6456             --  Copy parent_id.
6457 
6458               p_x_header_adj_Att_tbl(I).price_adjustment_id :=
6459 				p_x_header_adj_Tbl(p_x_header_adj_att_tbl(I).adj_index).price_adjustment_id;
6460 	  	  ELSE
6461 		     IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
6462 			THEN
6463 						IF l_debug_level  > 0 THEN
6464 						    oe_debug_pub.add(  'INVALID ADJ INDEX '|| TO_CHAR ( P_X_HEADER_ADJ_ATT_TBL ( I ) .ADJ_INDEX ) || 'ON HEADER ADJ ATTRIBUTES' , 2 ) ;
6465 						END IF;
6466 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6467 			     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
6468 			     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Header_Adj_Attribs');
6469 				FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
6470 				FND_MESSAGE.SET_TOKEN('PARENT_INDEX',p_x_header_adj_att_tbl(I).adj_index);
6471 				OE_MSG_PUB.Add;
6472                 END IF;
6473            END IF;
6474 
6475         END IF;
6476         I := p_x_header_adj_Att_tbl.NEXT(I);
6477     END LOOP;
6478 
6479     --  Header_Adj_Atts
6480     IF p_x_header_adj_Att_tbl.COUNT > 0 THEN
6481 
6482     IF l_debug_level  > 0 THEN
6483         oe_debug_pub.add(  'BEFORE OE_ORDER_ADJ_PVT.HEADER_ADJ_ATTS PROCESSING' , 2 ) ;
6484     END IF;
6485     oe_order_adj_pvt.Header_Adj_Atts
6486     (   p_validation_level            => p_validation_level
6487     ,   p_control_rec                 => p_control_rec
6488     ,   p_x_Header_Adj_Att_tbl        => p_x_header_adj_Att_tbl
6489     ,   p_x_old_Header_Adj_Att_tbl    => l_old_header_Adj_Att_tbl
6490     );
6491 
6492         IF l_debug_level  > 0 THEN
6493             oe_debug_pub.add(  'AFTER HEADER_ADJ_ATTS PROCESSING' , 2 ) ;
6494         END IF;
6495 
6496     END IF;
6497 
6498 
6499     -------------------------------------------------------
6500     -- Process Header Adjustment Associations
6501     -------------------------------------------------------
6502 
6503     -- Set Header Id on Hdr Adjustment Associations
6504 
6505     I := p_x_header_adj_Assoc_tbl.FIRST;
6506 
6507     WHILE I IS NOT NULL LOOP
6508 
6509         IF l_debug_level  > 0 THEN
6510             oe_debug_pub.add(  'SETTING HEADER ID ON HDR_ADJ_ASSOC_TBL' , 2 ) ;
6511         END IF;
6512         IF p_x_header_adj_assoc_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
6513         AND (p_x_header_adj_assoc_tbl(I).Price_Adjustment_id IS NULL OR
6514             p_x_header_adj_assoc_tbl(I).Price_Adjustment_id = FND_API.G_MISS_NUM)
6515         THEN
6516 
6517 		  IF p_x_header_adj_Tbl.exists(p_x_header_adj_assoc_tbl(I).Adj_Index) Then
6518             --  Copy parent_id.
6519 
6520               p_x_header_adj_Assoc_tbl(I).price_adjustment_id :=
6521 				p_x_header_adj_Tbl(p_x_header_adj_assoc_tbl(I).adj_index).price_adjustment_id;
6522 	  	  ELSE
6523 		     IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
6524 			THEN
6525 						IF l_debug_level  > 0 THEN
6526 						    oe_debug_pub.add(  'INVALID ADJ INDEX '|| TO_CHAR ( P_X_HEADER_ADJ_ASSOC_TBL ( I ) .ADJ_INDEX ) || 'ON HEADER ADJ ATTRIBUTES' , 2 ) ;
6527 						END IF;
6528 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6529 			     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
6530 			     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Header_Adj_Assocs');
6531 				FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
6532 				FND_MESSAGE.SET_TOKEN('PARENT_INDEX',p_x_header_adj_assoc_tbl(I).adj_index);
6533 				OE_MSG_PUB.Add;
6534                 END IF;
6535             END IF;
6536 
6537         END IF;
6538 
6539         IF p_x_header_adj_assoc_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
6540         AND (p_x_header_adj_assoc_tbl(I).rltd_Price_Adj_Id IS NULL OR
6541             p_x_header_adj_assoc_tbl(I).rltd_Price_Adj_Id = FND_API.G_MISS_NUM)
6542         THEN
6543 
6544 		  IF p_x_header_adj_Tbl.exists(p_x_header_adj_assoc_tbl(I).Rltd_Adj_Index) Then
6545             --  Copy parent_id.
6546 
6547               p_x_header_adj_Assoc_tbl(I).rltd_Price_Adj_Id :=
6548 				p_x_header_adj_Tbl(p_x_header_adj_assoc_tbl(I).Rltd_Adj_Index).Price_adjustment_id;
6549             END IF;
6550 
6551         END IF;
6552         I := p_x_header_adj_Assoc_tbl.NEXT(I);
6553     END LOOP;
6554 
6555     --  Header_Adj_Assocs
6556 
6557     IF p_x_header_adj_Assoc_tbl.COUNT > 0 THEN
6558 
6559     IF l_debug_level  > 0 THEN
6560         oe_debug_pub.add(  'BEFORE OE_ORDER_ADJ_PVT.HEADER_ADJ_ASSOCS PROCESSING' , 2 ) ;
6561     END IF;
6562     oe_order_adj_pvt.Header_Adj_Assocs
6563     (   p_validation_level            => p_validation_level
6564     ,   p_control_rec                 => p_control_rec
6565     ,   p_x_Header_Adj_Assoc_tbl      => p_x_header_adj_Assoc_tbl
6566     ,   p_x_old_Header_Adj_Assoc_tbl  => l_old_header_Adj_Assoc_tbl
6567     );
6568 
6569     IF l_debug_level  > 0 THEN
6570         oe_debug_pub.add(  'AFTER HEADER_ADJ_ASSOCS PROCESSING' , 2 ) ;
6571     END IF;
6572     END IF;
6573 
6574 
6575     -------------------------------------------------------
6576     -- Process Header Sales Credits
6577     -------------------------------------------------------
6578 
6579 
6580     -- Set Header Id on Sales Credits
6581 
6582     I := p_x_header_scredit_tbl.FIRST;
6583     WHILE I IS NOT NULL LOOP
6584 
6585         IF l_debug_level  > 0 THEN
6586             oe_debug_pub.add(  'SETTING HEADER_ID ON HEADER_SCREDIT_TBL' , 2 ) ;
6587         END IF;
6588         IF p_x_header_scredit_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
6589         AND (p_x_header_scredit_tbl(I).header_id IS NULL OR
6590 		p_x_header_scredit_tbl(I).header_id = FND_API.G_MISS_NUM)
6591 	   THEN
6592 
6593               IF p_x_header_rec.header_id IS NULL OR
6594                   p_x_header_rec.header_id = FND_API.G_MISS_NUM THEN
6595                    FND_MESSAGE.SET_NAME('ONT','OE_HEADER_MISSING');
6596                    OE_MSG_PUB.Add;
6597                    RAISE FND_API.G_EXC_ERROR;
6598               ELSE
6599 		--  Copy parent_id.
6600 
6601 		  p_x_header_scredit_tbl(I).header_id := p_x_header_rec.header_id;
6602               END IF;
6603 	   END IF;
6604 
6605 	   I := p_x_header_scredit_tbl.NEXT(I);
6606     END LOOP;
6607 
6608     --  Header_Scredits
6609 
6610     IF p_x_header_scredit_tbl.COUNT > 0 THEN
6611 
6612     IF l_debug_level  > 0 THEN
6613         oe_debug_pub.add(  'BEFORE HEADER_SCREDITS PROCESSING' , 2 ) ;
6614     END IF;
6615     Header_Scredits
6616     (   p_validation_level            => p_validation_level
6617     ,   p_control_rec                 => p_control_rec
6618     ,   p_x_Header_Scredit_tbl        => p_x_header_scredit_tbl
6619     ,   p_x_old_Header_Scredit_tbl    => l_old_header_Scredit_tbl
6620     ,   x_return_status               => l_return_status
6621     );
6622     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6623        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6624     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
6625 	 IF p_control_rec.process_partial THEN
6626 	    x_return_status := FND_API.G_RET_STS_ERROR;
6627       ELSE
6628          RAISE FND_API.G_EXC_ERROR;
6629       END IF;
6630     END IF;
6631     IF l_debug_level  > 0 THEN
6632         oe_debug_pub.add(  'AFTER HEADER_SCREDITS PROCESSING' , 2 ) ;
6633     END IF;
6634 
6635     END IF;
6636 
6637     --  Perform Header_Scredit group requests.
6638 
6639     IF (p_control_rec.process AND
6640     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
6641         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
6642         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_HEADER_SCREDIT)
6643     THEN
6644 
6645        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
6646           (p_entity_code   => OE_GLOBALS.G_ENTITY_Header_Scredit
6647           ,p_delete        => FND_API.G_TRUE
6648           ,x_return_status => l_return_status
6649           );
6650        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6651                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6652        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
6653                  RAISE FND_API.G_EXC_ERROR;
6654        END IF;
6655 
6656     END IF;
6657 
6658 
6659     -- Get header_id from the header and put it on the line.
6660 
6661 -- Kris = decide if
6662 -- Header id may not be passed on the header record if the operation is none
6663 -- I think we should pass header_id on the header rec all the time
6664 
6665 /*
6666 	IF p_x_line_tbl.COUNT > 0 THEN
6667 
6668 		For k in p_x_line_tbl.first .. p_x_line_tbl.last LOOP
6669 
6670 		   IF  (p_x_line_tbl(k).header_id = FND_API.G_MISS_NUM
6671 		   OR   p_x_line_tbl(k).header_id is null ) THEN
6672 
6673 -- Kris do not loop through the lines unless they have the right header_id
6674 -- If people pass in a header_id with a bogus value, the record should be ignored
6675 
6676 				p_x_line_tbl(k).header_id := p_x_header_rec.header_id;
6677 
6678 		   END IF;
6679 
6680 		End Loop;
6681 
6682   	END IF;
6683 */
6684 
6685 
6686     -------------------------------------------------------
6687     -- Process Header Payments
6688     -------------------------------------------------------
6689 
6690   IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
6691     -- Set Header Id on Payments
6692 
6693     I := p_x_header_payment_tbl.FIRST;
6694     WHILE I IS NOT NULL LOOP
6695 
6696         IF l_debug_level  > 0 THEN
6697             oe_debug_pub.add(  'SETTING HEADER_ID ON HEADER_PAYMENT_TBL' , 2 ) ;
6698         END IF;
6699         IF p_x_header_payment_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
6700         AND (p_x_header_payment_tbl(I).header_id IS NULL OR
6701 		p_x_header_payment_tbl(I).header_id = FND_API.G_MISS_NUM)
6702 	   THEN
6703 
6704               IF p_x_header_rec.header_id IS NULL OR
6705                   p_x_header_rec.header_id = FND_API.G_MISS_NUM THEN
6706                    FND_MESSAGE.SET_NAME('ONT','OE_HEADER_MISSING');
6707                    OE_MSG_PUB.Add;
6708                    RAISE FND_API.G_EXC_ERROR;
6709               ELSE
6710 		--  Copy parent_id.
6711 
6712 		  p_x_header_payment_tbl(I).header_id := p_x_header_rec.header_id;
6713               END IF;
6714 	   END IF;
6715 
6716 	   I := p_x_header_payment_tbl.NEXT(I);
6717     END LOOP;
6718 
6719     --  Header_Payments
6720 
6721     IF p_x_header_payment_tbl.COUNT > 0 THEN
6722 
6723     IF l_debug_level  > 0 THEN
6724         oe_debug_pub.add(  'BEFORE HEADER_PAYMENTS PROCESSING' , 2 ) ;
6725     END IF;
6726     Header_Payments
6727     (   p_validation_level            => p_validation_level
6728     ,   p_control_rec                 => p_control_rec
6729     ,   p_x_Header_Payment_tbl        => p_x_header_Payment_tbl
6730     ,   p_x_old_Header_Payment_tbl    => l_old_header_Payment_tbl
6731     ,   x_return_status               => l_return_status
6732     );
6733     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6734        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6735     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
6736 	 IF p_control_rec.process_partial THEN
6737 	    x_return_status := FND_API.G_RET_STS_ERROR;
6738       ELSE
6739          RAISE FND_API.G_EXC_ERROR;
6740       END IF;
6741     END IF;
6742     IF l_debug_level  > 0 THEN
6743         oe_debug_pub.add(  'AFTER HEADER_PAYMENTS PROCESSING' , 2 ) ;
6744     END IF;
6745 
6746     END IF;
6747 
6748     --  Perform Header_Payment group requests.
6749 
6750     IF (p_control_rec.process AND
6751     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
6752         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
6753         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_HEADER_PAYMENT)
6754     THEN
6755 
6756        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
6757           (p_entity_code   => OE_GLOBALS.G_ENTITY_Header_Payment
6758           ,p_delete        => FND_API.G_TRUE
6759           ,x_return_status => l_return_status
6760           );
6761        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6762                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6763        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
6764                  RAISE FND_API.G_EXC_ERROR;
6765        END IF;
6766 
6767     END IF;
6768   END IF;
6769     -------------------------------------------------------
6770     -- Process Lines
6771     -------------------------------------------------------
6772 
6773     I := p_x_line_tbl.FIRST;
6774 
6775     WHILE I IS NOT NULL LOOP
6776 
6777         --Bug 2790512: Prevent processing of line if operation is invalid
6778         --Bug 2878121: Ignore NULL operation code
6779         IF p_x_line_tbl(I).operation IS NOT NULL AND
6780            p_x_line_tbl(I).operation NOT IN (OE_GLOBALS.G_OPR_CREATE,
6781                     OE_GLOBALS.G_OPR_DELETE, OE_GLOBALS.G_OPR_UPDATE,
6782                     OE_GLOBALS.G_OPR_INSERT, OE_GLOBALS.G_OPR_NONE) THEN
6783            FND_MESSAGE.SET_NAME('ONT','OE_OI_OPERATION_CODE');
6784            OE_MSG_PUB.Add;
6785            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6786         END IF;
6787 
6788         IF p_x_line_tbl(I).operation = oe_globals.g_opr_update
6789            AND p_x_line_tbl(I).split_action_code = 'SPLIT' THEN
6790 
6791           -- Negotiation check has been added for bug 4758902
6792           BEGIN
6793             SELECT transaction_phase_code
6794             INTO   l_transaction_phase_code
6795             FROM   oe_order_lines_all
6796             WHERE  line_id = p_x_line_tbl(I).line_id;
6797           EXCEPTION
6798             WHEN NO_DATA_FOUND THEN
6799               oe_debug_pub.add(' No Transaction Phase Code for parent split line.',1);
6800               NULL;
6801             WHEN OTHERS THEN
6802               oe_debug_pub.add(' OTHERS: No Transaction Phase Code for parent split line.',1);
6803               NULL;
6804           END;
6805 
6806           IF NVL(l_transaction_phase_code,'F') = 'N' THEN
6807             oe_debug_pub.add(' Line  Id : '||p_x_line_tbl(I).line_id||' cannot be split. It is in Negotiation Phase.');
6808             FND_MESSAGE.SET_NAME('ONT','OE_PC_SPLIT_VIOLATION');
6809             FND_MESSAGE.SET_TOKEN('OBJECT',p_x_line_tbl(I).line_id);
6810             FND_MESSAGE.SET_TOKEN('REASON','Line is in Negotiation Phase');
6811             OE_MSG_PUB.Add;
6812             RAISE FND_API.G_EXC_ERROR;
6813           ELSE
6814             l_call_split := TRUE;
6815           END IF;
6816         END IF;
6817 
6818         -- START: CHECK IF ALL LINES BELONG TO THE SAME ORDER
6819 
6820         -- Retrieve the header ID, either from the header record
6821         -- or from the first line
6822         IF (I = p_x_line_tbl.FIRST) THEN
6823           IF (p_x_header_rec.header_id IS NOT NULL AND
6824             p_x_header_rec.header_id <> FND_API.G_MISS_NUM) THEN
6825 		  l_header_id := p_x_header_rec.header_id;
6826           ELSIF (p_x_line_tbl(I).header_id IS NOT NULL AND
6827             p_x_line_tbl(I).header_id <> FND_API.G_MISS_NUM) THEN
6828 		  l_header_id := p_x_line_tbl(I).header_id;
6829           END IF;
6830         END IF;
6831 
6832         IF p_x_line_tbl(I).operation <> OE_GLOBALS.G_OPR_CREATE
6833         AND (p_x_line_tbl(I).header_id IS NULL OR
6834             p_x_line_tbl(I).header_id = FND_API.G_MISS_NUM)
6835         THEN
6836           IF (l_header_id IS NOT NULL AND
6837               l_header_id <> FND_API.G_MISS_NUM) THEN
6838 		    p_x_line_tbl(I).header_id := l_header_id;
6839 	     ELSE
6840 	         oe_line_util.query_header
6841 				   (p_line_id => p_x_line_tbl(I).line_id,
6842 			         x_header_id => l_header_id);
6843               p_x_line_tbl(I).header_id := l_header_id;
6844 	     END IF;
6845         END IF;
6846 
6847         -- Copy the parent ID (header ID), if not passed, on
6848         -- the record for CREATE operations
6849         IF p_x_line_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE THEN
6850           IF  (p_x_line_tbl(I).header_id IS NULL OR
6851             p_x_line_tbl(I).header_id = FND_API.G_MISS_NUM)
6852           THEN
6853             --  Copy parent_id.
6854             p_x_line_tbl(I).header_id := l_header_id;
6855 	  END IF;
6856         END IF;
6857 
6858         -- Raise error if the header ID for the line is different
6859         -- from header ID on the header record or other lines
6860         IF (l_header_id IS NOT NULL AND
6861             l_header_id <> FND_API.G_MISS_NUM) THEN
6862             IF p_x_line_tbl(I).header_id <> l_header_id THEN
6863                 fnd_message.set_name('ONT', 'OE_HEADER_MISSING');
6864                 oe_msg_pub.add;
6865                 RAISE FND_API.G_EXC_ERROR;
6866             END IF;
6867         END IF;
6868 
6869         -- END: CHECK IF ALL LINES BELONG TO THE SAME ORDER
6870 
6871         I := p_x_line_tbl.NEXT(I);
6872 
6873     END LOOP;
6874 
6875 
6876     -- Pre Split Process
6877     IF l_call_split THEN
6878       OE_Split_Util.Check_Split_Course
6879 	 ( p_x_line_tbl => p_x_line_tbl,
6880 	   p_x_line_adj_tbl => p_x_line_adj_tbl,
6881 	   p_x_line_scredit_tbl => p_x_line_scredit_tbl
6882 	  );
6883     END IF;
6884 
6885     --  Lines
6886 
6887     IF p_x_line_tbl.COUNT > 0 THEN
6888 
6889     IF l_debug_level  > 0 THEN
6890         oe_debug_pub.add(  'BEFORE LINES PROCESSING' , 2 ) ;
6891     END IF;
6892     Lines
6893     (   p_validation_level            => p_validation_level
6894     ,   p_control_rec                 => p_control_rec
6895     ,   p_x_line_tbl                  => p_x_line_tbl
6896     ,   p_x_old_line_tbl              => l_old_line_tbl
6897     ,   x_return_status               => l_return_status
6898     );
6899     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6900        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6901     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
6902         IF p_control_rec.process_partial THEN
6903 	   x_return_status := FND_API.G_RET_STS_ERROR;
6904         ELSE
6905            RAISE FND_API.G_EXC_ERROR;
6906         END IF;
6907     END IF;
6908     IF l_debug_level  > 0 THEN
6909         oe_debug_pub.add(  'AFTER LINES PROCESSING' , 2 ) ;
6910     END IF;
6911 
6912     END IF;
6913 
6914 
6915     I := p_x_line_scredit_tbl.FIRST;
6916     WHILE I IS NOT NULL LOOP
6917 
6918         IF l_debug_level  > 0 THEN
6919             oe_debug_pub.add(  'SETTING HEADER/LINE IDS ON LINE SC TABLE' ) ;
6920         END IF;
6921         IF p_x_line_scredit_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
6922         AND (p_x_line_scredit_tbl(I).line_id IS NULL OR
6923             p_x_line_scredit_tbl(I).line_id = FND_API.G_MISS_NUM)
6924         THEN
6925             IF l_debug_level  > 0 THEN
6926                 oe_debug_pub.add(  'SETTING LINE IDS ON LINE SC TABLE' , 2 ) ;
6927             END IF;
6928 
6929             --  Check If parent exists.
6930 
6931             IF p_x_line_tbl.EXISTS(p_x_line_scredit_tbl(I).line_index) THEN
6932 
6933                 --  Copy parent_id.
6934 
6935                 p_x_line_scredit_tbl(I).line_id := p_x_line_tbl(p_x_line_scredit_tbl(I).line_index).line_id;
6936                 p_x_line_scredit_tbl(I).header_id := p_x_line_tbl(p_x_line_scredit_tbl(I).line_index).header_id;
6937 
6938                 -- Following procedure is called to fix bug 2482365
6939                 -- If sales credit info is passed by the user we will honor it.
6940                 -- Any sales credit record created for this line so far shall be deleted.
6941 
6942                 OE_Line_Scredit_Util.Delete_Row(p_line_id =>p_x_line_scredit_tbl(I).line_id);
6943           ELSE
6944 
6945                 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
6946                 THEN
6947                                                 IF l_debug_level  > 0 THEN
6948                                                     oe_debug_pub.add(  'INVALID LINE INDEX ' ||TO_CHAR ( L_LINE_INDEX ) ||'ON LINE SALES CREDITS' , 2 ) ;
6949                                                 END IF;
6950                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6951                     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
6952                     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Line_Scredit');
6953                     FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
6954                     FND_MESSAGE.SET_TOKEN('PARENT_INDEX',p_x_line_scredit_tbl(I).line_index);
6955                     OE_MSG_PUB.Add;
6956 
6957                 END IF;
6958             END IF;
6959        END IF;
6960 
6961        I := p_x_line_scredit_tbl.NEXT(I);
6962     END LOOP;
6963 
6964 
6965   IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
6966     I := p_x_line_payment_tbl.FIRST;
6967     WHILE I IS NOT NULL LOOP
6968 
6969         IF l_debug_level  > 0 THEN
6970             oe_debug_pub.add(  'SETTING HEADER/LINE IDS ON LINE SC TABLE' ) ;
6971         END IF;
6972         IF p_x_line_payment_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
6973         AND (p_x_line_payment_tbl(I).line_id IS NULL OR
6974             p_x_line_payment_tbl(I).line_id = FND_API.G_MISS_NUM)
6975         THEN
6976             IF l_debug_level  > 0 THEN
6977                 oe_debug_pub.add(  'SETTING LINE IDS ON LINE PAYMENT TABLE' , 2 ) ;
6978             END IF;
6979 
6980             --  Check If parent exists.
6981 
6982             IF p_x_line_tbl.EXISTS(p_x_line_payment_tbl(I).line_index) THEN
6983 
6984                 --  Copy parent_id.
6985 
6986                 p_x_line_payment_tbl(I).line_id := p_x_line_tbl(p_x_line_payment_tbl(I).line_index).line_id;
6987                 p_x_line_payment_tbl(I).header_id := p_x_line_tbl(p_x_line_payment_tbl(I).line_index).header_id;
6988 
6989           ELSE
6990 
6991                 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
6992                 THEN
6993                                                 IF l_debug_level  > 0 THEN
6994                                                     oe_debug_pub.add(  'INVALID LINE INDEX ' ||TO_CHAR ( L_LINE_INDEX ) ||'ON LINE SALES CREDITS' , 2 ) ;
6995                                                 END IF;
6996                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6997                     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
6998                     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Line_Payment');
6999                     FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
7000                     FND_MESSAGE.SET_TOKEN('PARENT_INDEX',p_x_line_payment_tbl(I).line_index);
7001                     OE_MSG_PUB.Add;
7002 
7003                 END IF;
7004             END IF;
7005        END IF;
7006 
7007        I := p_x_line_payment_tbl.NEXT(I);
7008     END LOOP;
7009   END IF;
7010 
7011 
7012     I := p_x_line_adj_tbl.FIRST;
7013     WHILE I IS NOT NULL LOOP
7014 
7015         IF l_debug_level  > 0 THEN
7016             oe_debug_pub.add(  'SETTING HEADER/LINE IDS ON LINE ADJ TABLE' , 2 ) ;
7017         END IF;
7018 
7019         IF p_x_line_adj_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
7020         AND (p_x_line_adj_tbl(I).line_id IS NULL OR
7021             p_x_line_adj_tbl(I).line_id = FND_API.G_MISS_NUM)
7022         THEN
7023 
7024             IF l_debug_level  > 0 THEN
7025                 oe_debug_pub.add(  'SETTING LINE IDS ON LINE ADJ TABLE' , 2 ) ;
7026             END IF;
7027             --  Check If parent exists.
7028 
7029             IF p_x_line_adj_tbl(I).line_index <> fnd_api.g_miss_num and
7030 			p_x_line_tbl.EXISTS(p_x_line_adj_tbl(I).line_index) THEN
7031 
7032                 --  Copy parent_id.
7033 
7034                 p_x_line_adj_tbl(I).line_id := p_x_line_tbl(p_x_Line_adj_tbl(I).line_index).line_id;
7035                 p_x_line_adj_tbl(I).header_id := p_x_line_tbl(p_x_Line_adj_tbl(I).line_index).header_id;
7036 
7037             ELSIF p_x_line_adj_tbl(I).header_id is not null and
7038 				p_x_line_adj_tbl(I).header_id <> FND_API.G_MISS_NUM Then
7039 			-- Treat the adjustment record as a header_adjustment record
7040 			IF l_debug_level  > 0 THEN
7041 			    oe_debug_pub.add(  'TREATING THE RECORD AS HEADER_ADJUSTMENT' ) ;
7042 			END IF;
7043 		  ELSE
7044 
7045                 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
7046                 THEN
7047                                                 IF l_debug_level  > 0 THEN
7048                                                     oe_debug_pub.add(  'INVALID LINE INDEX ' ||TO_CHAR ( L_LINE_INDEX ) ||'ON PRICE ADJUSTMENTS' , 2 ) ;
7049                                                 END IF;
7050                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7051 
7052                     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
7053                     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Line_Adj');
7054                     FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
7055                     FND_MESSAGE.SET_TOKEN('PARENT_INDEX',p_x_line_adj_tbl(I).line_index);
7056                     OE_MSG_PUB.Add;
7057 
7058                 END IF;
7059             END IF;
7060         END IF;
7061 
7062         I := p_x_line_adj_tbl.NEXT(I);
7063     END LOOP;
7064 
7065     --  Perform line group requests.
7066 
7067     IF (p_control_rec.process AND
7068     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
7069         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
7070         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_LINE)
7071     THEN
7072             IF l_debug_level  > 0 THEN
7073                 oe_debug_pub.add(  'PROCESS LINE REQUESTS' ) ;
7074             END IF;
7075 
7076        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
7077           (p_entity_code   => OE_GLOBALS.G_ENTITY_LINE
7078           ,p_delete        => FND_API.G_TRUE
7079           ,x_return_status => l_return_status
7080           );
7081        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7082           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7083        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
7084           RAISE FND_API.G_EXC_ERROR;
7085        END IF;
7086 
7087     END IF;
7088 
7089 
7090     -------------------------------------------------------
7091     -- Process Lines Adjustments
7092     -------------------------------------------------------
7093 
7094     IF p_x_line_adj_tbl.COUNT > 0 THEN
7095 
7096     --  Line_Adjs
7097 
7098     oe_order_adj_pvt.Line_Adjs
7099     (   p_validation_level            => p_validation_level
7100     ,   p_control_rec                 => p_control_rec
7101     ,   p_x_Line_Adj_tbl              => p_x_line_adj_tbl
7102     ,   p_x_old_Line_Adj_tbl          => l_old_line_Adj_tbl
7103     );
7104 
7105     END IF;
7106 
7107     --  Perform Line_Adj group requests.
7108 
7109     IF (p_control_rec.process AND
7110     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
7111         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
7112         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_LINE_ADJ)
7113     THEN
7114 
7115        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
7116           (p_entity_code   => OE_GLOBALS.G_ENTITY_LINE_ADJ
7117           ,p_delete        => FND_API.G_TRUE
7118           ,x_return_status => l_return_status
7119           );
7120        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7121             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7122        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
7123             RAISE FND_API.G_EXC_ERROR;
7124        END IF;
7125 
7126     END IF;
7127 
7128     -------------------------------------------------------
7129     -- Process Line Sales Credits
7130     -------------------------------------------------------
7131 
7132     --  Line_Scredits
7133 
7134     IF p_x_line_scredit_tbl.COUNT > 0 THEN
7135 
7136       Line_Scredits
7137       (   p_validation_level            => p_validation_level
7138       ,   p_control_rec                 => p_control_rec
7139       ,   p_x_Line_Scredit_tbl          => p_x_line_scredit_tbl
7140       ,   p_x_old_Line_Scredit_tbl      => l_old_line_Scredit_tbl
7141       ,   x_return_status               => l_return_status
7142       );
7143      IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7144        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7145      ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
7146 	  IF p_control_rec.process_partial THEN
7147 	     x_return_status := FND_API.G_RET_STS_ERROR;
7148        ELSE
7149           RAISE FND_API.G_EXC_ERROR;
7150        END IF;
7151      END IF;
7152 
7153     END IF;
7154 
7155     --  Perform Line_Scredit group requests.
7156 
7157     IF (p_control_rec.process AND
7158     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
7159         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
7160         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_LINE_SCREDIT)
7161     THEN
7162 
7163        IF l_debug_level  > 0 THEN
7164            oe_debug_pub.add(  'PROCESSING DELAYED REQUESTS FOR LINES' , 2 ) ;
7165        END IF;
7166 
7167        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
7168           (p_entity_code   => OE_GLOBALS.G_ENTITY_Line_Scredit
7169           ,p_delete        => FND_API.G_TRUE
7170           ,x_return_status => l_return_status
7171           );
7172 
7173        IF l_debug_level  > 0 THEN
7174            oe_debug_pub.add(  'PROCESSED DELAYED REQUESTS FOR LINES' , 2 ) ;
7175        END IF;
7176 
7177        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7178                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7179        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
7180                  RAISE FND_API.G_EXC_ERROR;
7181        END IF;
7182 
7183     END IF;
7184 
7185 
7186     -------------------------------------------------------
7187     -- Process Line Payments
7188     -------------------------------------------------------
7189 
7190   IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
7191     --  Line_Payments
7192 
7193     IF p_x_line_payment_tbl.COUNT > 0 THEN
7194 
7195       Line_Payments
7196       (   p_validation_level            => p_validation_level
7197       ,   p_control_rec                 => p_control_rec
7198       ,   p_x_Line_Payment_tbl          => p_x_line_Payment_tbl
7199       ,   p_x_old_Line_Payment_tbl      => l_old_line_Payment_tbl
7200       ,   x_return_status               => l_return_status
7201       );
7202      IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7203        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7204      ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
7205 	  IF p_control_rec.process_partial THEN
7206 	     x_return_status := FND_API.G_RET_STS_ERROR;
7207        ELSE
7208           RAISE FND_API.G_EXC_ERROR;
7209        END IF;
7210      END IF;
7211 
7212     END IF;
7213 
7214     --  Perform Line_Payment group requests.
7215 
7216     IF (p_control_rec.process AND
7217     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
7218         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
7219         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_LINE_PAYMENT)
7220     THEN
7221 
7222        IF l_debug_level  > 0 THEN
7223            oe_debug_pub.add(  'PROCESSING DELAYED REQUESTS FOR LINES' , 2 ) ;
7224        END IF;
7225 
7226        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
7227           (p_entity_code   => OE_GLOBALS.G_ENTITY_LINE_PAYMENT
7228           ,p_delete        => FND_API.G_TRUE
7229           ,x_return_status => l_return_status
7230           );
7231 
7232        IF l_debug_level  > 0 THEN
7233            oe_debug_pub.add(  'PROCESSED DELAYED REQUESTS FOR LINES' , 2 ) ;
7234        END IF;
7235 
7236        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7237                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7238        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
7239                  RAISE FND_API.G_EXC_ERROR;
7240        END IF;
7241 
7242     END IF;
7243   END IF;
7244 
7245     -------------------------------------------------------
7246     -- Process Lot Serials
7247     -------------------------------------------------------
7248 
7249     IF p_x_lot_serial_tbl.COUNT > 0 THEN
7250 
7251     --  Load parent key if missing and operation is create.
7252 
7253     I := p_x_lot_serial_tbl.FIRST;
7254     WHILE I IS NOT NULL LOOP
7255 
7256         IF p_x_lot_serial_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
7257         AND (p_x_lot_serial_tbl(I).line_id IS NULL OR
7258             p_x_lot_serial_tbl(I).line_id = FND_API.G_MISS_NUM)
7259         THEN
7260 
7261             --  Check If parent exists.
7262 
7263             IF p_x_line_tbl.EXISTS(p_x_lot_serial_tbl(I).line_index) THEN
7264 
7265                 --  Copy parent_id.
7266 
7267                 p_x_lot_serial_tbl(I).line_id := p_x_line_tbl(p_x_Lot_serial_tbl(I).line_index).line_id;
7268 
7269             ELSE
7270 
7271                 IF oe_msg_pub.Check_Msg_Level(oe_msg_pub.G_MSG_LVL_ERROR)
7272                 THEN
7273 
7274                     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
7275                     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Lot_Serial');
7276                     FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
7277                     FND_MESSAGE.SET_TOKEN('PARENT_INDEX',p_x_lot_serial_tbl(I).line_index);
7278                     oe_msg_pub.Add;
7279 
7280                 END IF;
7281             END IF;
7282             END IF;
7283         I := p_x_lot_serial_tbl.NEXT(I);
7284     END LOOP;
7285 
7286     --  Lot_Serials
7287 
7288     Lot_Serials
7289     (   p_validation_level            => p_validation_level
7290     ,   p_control_rec                 => p_control_rec
7291     ,   p_x_Lot_Serial_tbl            => p_x_lot_serial_tbl
7292     ,   p_x_old_Lot_Serial_tbl        => l_old_lot_Serial_tbl
7293     ,   x_return_status               => l_return_status
7294     );
7295     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7296        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7297     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
7298 	  IF p_control_rec.process_partial THEN
7299 	     x_return_status := FND_API.G_RET_STS_ERROR;
7300        ELSE
7301           RAISE FND_API.G_EXC_ERROR;
7302        END IF;
7303     END IF;
7304 
7305     END IF;
7306 
7307     --  Perform Lot_Serial group requests.
7308 
7309     IF (p_control_rec.process AND
7310     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
7311         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
7312         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_LOT_SERIAL)
7313     THEN
7314 
7315         NULL;
7316 
7317     END IF;
7318 
7319     -------------------------------------------------------
7320     -- Process Line Price Attributes
7321     -------------------------------------------------------
7322 
7323     -- Process line Price Attributes
7324 
7325     I := p_x_line_price_Att_tbl.FIRST;
7326     WHILE I IS NOT NULL LOOP
7327 
7328         IF l_debug_level  > 0 THEN
7329             oe_debug_pub.add(  'SETTING HEADER/LINE IDS ON LINE ATTRIBUTES TABLE' , 2 ) ;
7330         END IF;
7331         IF p_x_line_price_att_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
7332         AND (p_x_line_price_att_tbl(I).line_id IS NULL OR
7333             p_x_line_price_att_tbl(I).line_id = FND_API.G_MISS_NUM)
7334         THEN
7335 
7336             IF l_debug_level  > 0 THEN
7337                 oe_debug_pub.add(  'SETTING LINE IDS ON LINE ATTRIB TABLE' , 2 ) ;
7338             END IF;
7339             --  Check If parent exists.
7340 
7341             IF p_x_line_tbl.EXISTS(p_x_line_price_att_tbl(I).line_index) THEN
7342 
7343                 --  Copy parent_id.
7344 
7345                 p_x_line_price_Att_tbl(I).line_id := p_x_line_tbl(p_x_line_price_att_tbl(I).line_index).line_id;
7346                 p_x_line_price_Att_tbl(I).header_id := p_x_line_tbl(p_x_line_price_att_tbl(I).line_index).header_id;
7347 
7348             ELSE
7349 
7350                 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
7351                 THEN
7352                                                 IF l_debug_level  > 0 THEN
7353                                                     oe_debug_pub.add(  'INVALID LINE INDEX ' ||TO_CHAR ( P_X_LINE_PRICE_ATT_TBL ( I ) .LINE_INDEX ) ||'ON PRICE ADJUSTMENTS' , 2 ) ;
7354                                                 END IF;
7355                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7356 
7357                     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
7358                     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Line_Price_Att');
7359                     FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
7360                     FND_MESSAGE.SET_TOKEN('PARENT_INDEX',p_x_line_price_att_tbl(I).line_index);
7361                     OE_MSG_PUB.Add;
7362 
7363                 END IF;
7364             END IF;
7365         END IF;
7366         I := p_x_line_price_Att_tbl.NEXT(I);
7367     END LOOP;
7368 
7369     --  Line_Attribs
7370 
7371     IF p_x_line_price_Att_tbl.COUNT > 0 THEN
7372 
7373     oe_order_adj_pvt.Line_Price_Atts
7374     (   p_validation_level            => p_validation_level
7375     ,   p_control_rec                 => p_control_rec
7376     ,   p_x_Line_Price_Att_tbl        => p_x_line_price_Att_tbl
7377     ,   p_x_old_Line_Price_Att_tbl    => l_old_line_Price_Att_tbl
7378     );
7379 
7380     END IF;
7381 
7382     --  Perform Line_Price_Att group requests.
7383 
7384     IF (p_control_rec.process AND
7385     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
7386         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
7387         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_Line_Price_Att)
7388     THEN
7389 
7390        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
7391           (p_entity_code   => OE_GLOBALS.G_ENTITY_Line_Price_Att
7392           ,p_delete        => FND_API.G_TRUE
7393           ,x_return_status => l_return_status
7394           );
7395        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7396                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7397        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
7398                  RAISE FND_API.G_EXC_ERROR;
7399        END IF;
7400 
7401     END IF;
7402 
7403 
7404     -------------------------------------------------------
7405     -- Process Line Adjustment Attributes
7406     -------------------------------------------------------
7407 
7408     -- Process line Adj Attributes
7409 
7410     I := p_x_line_adj_Att_tbl.FIRST;
7411     WHILE I IS NOT NULL LOOP
7412 
7413         IF l_debug_level  > 0 THEN
7414             oe_debug_pub.add(  'SETTING PRICE_ADJUSTMENT_ID ON LINE ADJ ATTRIB TABLE' , 2 ) ;
7415         END IF;
7416 
7417         IF p_x_line_adj_att_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
7418         AND (p_x_line_adj_att_tbl(I).price_adjustment_id IS NULL OR
7419             p_x_line_adj_att_tbl(I).price_adjustment_id = FND_API.G_MISS_NUM)
7420         THEN
7421 
7422             IF l_debug_level  > 0 THEN
7423                 oe_debug_pub.add(  'SETTING ADJ IDS ON LINE ADJ ATTRIB TABLE' , 2 ) ;
7424             END IF;
7425             --  Check If parent exists.
7426 
7427             IF p_x_line_adj_tbl.EXISTS(p_x_Line_Adj_att_tbl(I).Adj_index) THEN
7428 
7429                 --  Copy parent_id.
7430 
7431                 p_x_line_adj_Att_tbl(I).price_adjustment_id := p_x_line_Adj_tbl(p_x_Line_Adj_att_tbl(I).Adj_index).price_adjustment_id;
7432 
7433             ELSE
7434 
7435                 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
7436                 THEN
7437                                                 IF l_debug_level  > 0 THEN
7438                                                     oe_debug_pub.add(  'INVALID ADJ INDEX ' ||TO_CHAR ( P_X_LINE_ADJ_ATT_TBL ( I ) .ADJ_INDEX ) ||'ON ADJ ATTRIBS' , 2 ) ;
7439                                                 END IF;
7440                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7441 
7442                     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
7443                     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Line_Adj_Att');
7444                     FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
7445                     FND_MESSAGE.SET_TOKEN('PARENT_INDEX',p_x_line_adj_att_tbl(I).Adj_index);
7446                     OE_MSG_PUB.Add;
7447 
7448                 END IF;
7449             END IF;
7450         END IF;
7451         I := p_x_line_adj_Att_tbl.NEXT(I);
7452     END LOOP;
7453 
7454     --  Line_Attribs
7455 
7456     IF p_x_line_adj_Att_tbl.COUNT > 0 THEN
7457 
7458     oe_order_adj_pvt.Line_Adj_Atts
7459     (   p_validation_level            => p_validation_level
7460     ,   p_control_rec                 => p_control_rec
7461     ,   p_x_Line_Adj_Att_tbl          => p_x_line_adj_Att_tbl
7462     ,   p_x_old_Line_Adj_Att_tbl      => l_old_line_Adj_Att_tbl
7463     );
7464 
7465     END IF;
7466 
7467     -------------------------------------------------------
7468     -- Process Line Adjustment Associations
7469     -------------------------------------------------------
7470 
7471     -- Process line Adj Associations
7472 
7473     I := p_x_line_adj_Assoc_tbl.FIRST;
7474     WHILE I IS NOT NULL LOOP
7475 
7476         IF l_debug_level  > 0 THEN
7477             oe_debug_pub.add(  'SETTING PRICE_ADJUSTMENT_ID ON LINE ADJ ASSOCS TABLE' , 2 ) ;
7478         END IF;
7479         IF p_x_line_adj_assoc_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
7480         AND (p_x_line_adj_assoc_tbl(I).price_adjustment_id IS NULL OR
7481             p_x_line_adj_assoc_tbl(I).price_adjustment_id = FND_API.G_MISS_NUM)
7482         THEN
7483 
7484             IF l_debug_level  > 0 THEN
7485                 oe_debug_pub.add(  'SETTING ADJ IDS ON LINE ADJ ASSOCS TABLE' , 2 ) ;
7486             END IF;
7487             --  Check If parent exists.
7488 
7489             IF p_x_line_adj_tbl.EXISTS(p_x_Line_Adj_assoc_tbl(I).Adj_index) THEN
7490 
7491                 --  Copy parent_id.
7492 
7493                 p_x_line_adj_Assoc_tbl(I).price_adjustment_id := p_x_line_Adj_tbl(p_x_Line_Adj_assoc_tbl(I).Adj_index).price_adjustment_id;
7494 
7495             ELSE
7496 
7497                 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
7498                 THEN
7499                                                 IF l_debug_level  > 0 THEN
7500                                                     oe_debug_pub.add(  'INVALID ADJ INDEX ' ||TO_CHAR ( P_X_LINE_ADJ_ASSOC_TBL ( I ) .ADJ_INDEX ) ||'ON ADJ ASSOCS' , 2 ) ;
7501                                                 END IF;
7502                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7503 
7504                     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
7505                     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Line_Adj_Assoc');
7506                     FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
7507                     FND_MESSAGE.SET_TOKEN('PARENT_INDEX',p_x_line_adj_assoc_tbl(I).Adj_index);
7508                     OE_MSG_PUB.Add;
7509 
7510                 END IF;
7511             END IF;
7512         END IF;
7513 
7514         IF p_x_line_adj_assoc_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
7515         AND (p_x_line_adj_assoc_tbl(I).Line_id IS NULL OR
7516             p_x_line_adj_assoc_tbl(I).Line_id = FND_API.G_MISS_NUM)
7517         THEN
7518 
7519             IF l_debug_level  > 0 THEN
7520                 oe_debug_pub.add(  'SETTING LINE IDS ON LINE ADJ ASSOCS TABLE' , 2 ) ;
7521             END IF;
7522             --  Check If parent exists.
7523 
7524             IF p_x_line_tbl.EXISTS(p_x_line_adj_assoc_tbl(I).Line_Index) THEN
7525 
7526                 --  Copy parent_id.
7527 
7528                 p_x_line_adj_Assoc_tbl(I).Line_Id := p_x_line_tbl(p_x_Line_Adj_assoc_tbl(I).Line_index).Line_id;
7529             END IF;
7530         END IF;
7531 
7532         IF p_x_line_adj_assoc_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE
7533         AND (p_x_line_adj_assoc_tbl(I).rltd_Price_Adj_Id IS NULL OR
7534             p_x_line_adj_assoc_tbl(I).rltd_Price_Adj_Id = FND_API.G_MISS_NUM)
7535         THEN
7536 
7537 		  IF p_x_line_adj_Tbl.exists(p_x_Line_Adj_assoc_tbl(I).Rltd_Adj_Index) Then
7538             --  Copy parent_id.
7539 
7540               p_x_line_adj_Assoc_tbl(I).rltd_Price_Adj_Id :=
7541 				p_x_line_adj_Tbl(p_x_Line_Adj_assoc_tbl(I).Rltd_Adj_Index).Price_adjustment_id;
7542             END IF;
7543 
7544         END IF;
7545         I := p_x_line_adj_Assoc_tbl.NEXT(I);
7546     END LOOP;
7547 
7548     --  Line_Attribs
7549 
7550     IF p_x_line_adj_Assoc_tbl.COUNT > 0 THEN
7551 
7552     oe_order_adj_pvt.Line_Adj_Assocs
7553     (   p_validation_level            => p_validation_level
7554     ,   p_control_rec                 => p_control_rec
7555     ,   p_x_Line_Adj_Assoc_tbl        => p_x_line_adj_Assoc_tbl
7556     ,   p_x_old_Line_Adj_Assoc_tbl    => l_old_line_Adj_Assoc_tbl
7557     );
7558 
7559     END IF;
7560 
7561 
7562     -- Step 6. Perform Delayed Requests
7563     --  Set entity_id on request table using the line index.
7564 
7565     I := p_x_action_request_tbl.FIRST;
7566     WHILE I IS NOT NULL LOOP
7567 
7568         IF l_debug_level  > 0 THEN
7569             oe_debug_pub.add(  'SETTING HEADER/LINE IDS ON REQUEST TABLE' , 2 ) ;
7570         END IF;
7571 
7572         IF (p_x_action_request_tbl(I).entity_code = OE_GLOBALS.G_ENTITY_HEADER) THEN
7573 
7574             IF (p_x_action_request_tbl(I).entity_id IS NULL OR
7575                 p_x_action_request_tbl(I).entity_id = FND_API.G_MISS_NUM)
7576             THEN
7577                 IF l_debug_level  > 0 THEN
7578                     oe_debug_pub.add(  'SETTING HEADER IDS ON REQUEST TABLE FOR HEADER ENTITY' , 2 ) ;
7579                 END IF;
7580               IF p_x_header_rec.header_id IS NULL OR
7581                  p_x_header_rec.header_id = FND_API.G_MISS_NUM THEN
7582                    FND_MESSAGE.SET_NAME('ONT','OE_HEADER_MISSING');
7583                    OE_MSG_PUB.Add;
7584                    RAISE FND_API.G_EXC_ERROR;
7585               ELSE
7586                 p_x_action_request_tbl(I).entity_id := p_x_header_rec.header_id;
7587               END IF;
7588             END IF;
7589 
7590         ELSIF (p_x_action_request_tbl(I).entity_code = OE_GLOBALS.G_ENTITY_LINE) THEN
7591 
7592             IF (p_x_action_request_tbl(I).entity_id IS NULL OR
7593                 p_x_action_request_tbl(I).entity_id = FND_API.G_MISS_NUM)
7594             THEN
7595                 IF l_debug_level  > 0 THEN
7596                     oe_debug_pub.add(  'SETTING LINE IDS ON REQUEST TABLE FOR LINE ENTITY' , 2 ) ;
7597                 END IF;
7598             --  Check If entity record exists.
7599 
7600                IF p_x_line_tbl.EXISTS(p_x_action_request_tbl(I).entity_index) THEN
7601 
7602                 --  Copy entity_id.
7603 
7604                   p_x_action_request_tbl(I).entity_id := p_x_line_tbl(p_x_action_request_tbl(I).entity_index).line_id;
7605 
7606                ELSE
7607 
7608                   IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
7609                   THEN
7610                                                 IF l_debug_level  > 0 THEN
7611                                                     oe_debug_pub.add(  'INVALID ENTITY INDEX ' ||TO_CHAR ( p_x_action_request_tbl ( I ) .ENTITY_INDEX ) ||'ON REQUEST TABLE FOR LINE ENTITY' , 2 ) ;
7612                                                 END IF;
7613                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7614                    END IF;
7615                END IF;
7616           END IF;
7617 
7618         ELSIF (p_x_action_request_tbl(I).request_type = OE_GLOBALS.G_VERIFY_PAYMENT) THEN
7619 
7620             IF (p_x_action_request_tbl(I).entity_id IS NULL OR
7621                 p_x_action_request_tbl(I).entity_id = FND_API.G_MISS_NUM)
7622             THEN
7623                 IF l_debug_level  > 0 THEN
7624                     oe_debug_pub.add(  'SETTING HEADER IDS ON REQUEST TABLE FOR VERIFY_PAYMENT' , 2 ) ;
7625                 END IF;
7626               IF p_x_header_rec.header_id IS NULL OR
7627                  p_x_header_rec.header_id = FND_API.G_MISS_NUM THEN
7628                    FND_MESSAGE.SET_NAME('ONT','OE_HEADER_MISSING');
7629                    OE_MSG_PUB.Add;
7630                    RAISE FND_API.G_EXC_ERROR;
7631               ELSE
7632                 p_x_action_request_tbl(I).entity_id := p_x_header_rec.header_id;
7633               END IF;
7634             END IF;
7635       END IF;
7636 	 I := p_x_action_request_tbl.NEXT(I);
7637     END LOOP;
7638 
7639 -------------------------------------------------------------------------------
7640 
7641     --  Step 7. Perform Object group logic
7642 
7643     --  Perform Delayed Requests for all the the entities
7644     IF l_debug_level  > 0 THEN
7645         oe_debug_pub.add(  'OEXVORDB: BEFORE CALLING PROCESS_DELAYED_REQUESTS' , 2 ) ;
7646     END IF;
7647     IF (p_control_rec.process AND
7648     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
7649        p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL
7650     THEN
7651 
7652        OE_DELAYED_REQUESTS_PVT.Process_Delayed_Requests(
7653           x_return_status => l_return_status
7654           );
7655                     IF l_debug_level  > 0 THEN
7656                         oe_debug_pub.add(  'OEXVORDB: COMPLETED PROCESS_DELAYED_REQUESTS ' || ' WITH RETURN STATUS' || L_RETURN_STATUS , 2 ) ;
7657                     END IF;
7658        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7659                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7660        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
7661                  RAISE FND_API.G_EXC_ERROR;
7662        END IF;
7663 
7664     END IF;
7665 
7666     -- Only do non-WF requests.
7667     IF p_x_action_request_tbl.COUNT > 0 THEN
7668 
7669     -- Perform NON-WF Action Requests
7670     OE_Delayed_Requests_PVT.Process_Order_Actions
7671            (p_validation_level  => p_validation_level,
7672                p_x_request_tbl  => p_x_action_request_tbl,
7673                p_process_WF_Requests => FALSE);
7674 
7675     END IF;
7676    /* comm rej
7677     --R12 CVV2
7678     IF l_debug_level > 0 THEN
7679        oe_debug_pub.add('after OE_Delayed_Requests_PVT.Process_Order_Actions cvv2');
7680     END IF;
7681     i := p_x_action_request_tbl.first;
7682     while i is not null loop
7683       IF l_debug_level > 0 THEN
7684          oe_debug_pub.add('return_status : ' || p_x_action_request_tbl(i).return_status);
7685          oe_debug_pub.add('request_type : ' || p_x_action_request_tbl(i).request_type);
7686       END IF;
7687       IF p_x_action_request_tbl(i).return_status = FND_API.G_RET_STS_ERROR
7688          AND p_x_action_request_tbl(i).request_type = OE_GLOBALS.G_VERIFY_PAYMENT THEN
7689              x_return_status := FND_API.G_RET_STS_ERROR;
7690              RAISE FND_API.G_EXC_ERROR;
7691       END IF;
7692       i := p_x_action_request_tbl.next(i);
7693     end loop;
7694     --R12 CVV2
7695   comm rej  */
7696 
7697     -- Start flows for the Entity.
7698     IF (p_control_rec.process AND
7699         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL AND
7700         OE_GLOBALS.G_RECURSION_MODE = 'N')
7701     THEN
7702         OE_ORDER_WF_UTIL.START_ALL_FLOWS;
7703         -- Process WF Action requests.
7704         IF p_x_action_request_tbl.COUNT > 0 THEN
7705 
7706           OE_Delayed_Requests_PVT.Process_Order_Actions
7707 
7708            (p_validation_level  => p_validation_level,
7709                p_x_request_tbl  => p_x_action_request_tbl,
7710                p_process_WF_Requests => TRUE);
7711 
7712         END IF;
7713 
7714     END IF;
7715 
7716 
7717     IF l_debug_level  > 0 THEN
7718         oe_debug_pub.add(  'OEXVORDB: AFTER PROCESS_ORDER_ACTIONS' , 2 ) ;
7719     END IF;
7720 
7721 
7722     --  Clear API cache.
7723 
7724     IF p_control_rec.clear_api_cache THEN
7725         NULL;
7726     END IF;
7727 
7728     --  Clear API request tbl.
7729 
7730     IF p_control_rec.clear_api_requests THEN
7731         NULL;
7732     END IF;
7733 
7734     -- Derive return status
7735 
7736     IF p_x_header_rec.return_status = FND_API.G_RET_STS_ERROR THEN
7737         x_return_status := FND_API.G_RET_STS_ERROR;
7738     END IF;
7739 
7740     -- Do not need to loop through header_scredits, lines
7741     -- line_scredits or lot_serials as the x_return_status is set
7742     -- based on the x_return_status returned by the entity procedures
7743 
7744     I := p_x_header_adj_tbl.FIRST;
7745     WHILE I IS NOT NULL LOOP
7746 
7747         IF p_x_header_adj_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
7748             x_return_status := FND_API.G_RET_STS_ERROR;
7749         END IF;
7750 
7751 	      I := p_x_header_adj_tbl.NEXT(I);
7752     END LOOP;
7753 
7754     I := p_x_header_price_Att_tbl.FIRST;
7755     WHILE I IS NOT NULL LOOP
7756 
7757         IF p_x_header_price_Att_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
7758             x_return_status := FND_API.G_RET_STS_ERROR;
7759         END IF;
7760 
7761 	      I := p_x_header_price_Att_tbl.NEXT(I);
7762     END LOOP;
7763 
7764     I := p_x_header_adj_Att_tbl.FIRST;
7765     WHILE I IS NOT NULL LOOP
7766 
7767         IF p_x_header_adj_Att_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
7768             x_return_status := FND_API.G_RET_STS_ERROR;
7769         END IF;
7770 
7771 	      I := p_x_header_adj_Att_tbl.NEXT(I);
7772     END LOOP;
7773 
7774     I := p_x_header_adj_Assoc_tbl.FIRST;
7775     WHILE I IS NOT NULL LOOP
7776 
7777         IF p_x_header_adj_Assoc_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
7778             x_return_status := FND_API.G_RET_STS_ERROR;
7779         END IF;
7780 
7781 	      I := p_x_header_adj_Assoc_tbl.NEXT(I);
7782     END LOOP;
7783 
7784     I := p_x_line_adj_tbl.FIRST;
7785     WHILE I IS NOT NULL LOOP
7786 
7787         IF p_x_line_adj_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
7788             x_return_status := FND_API.G_RET_STS_ERROR;
7789         END IF;
7790 
7791 		 I := p_x_line_adj_tbl.NEXT(I);
7792     END LOOP;
7793 
7794     I := p_x_line_price_Att_tbl.FIRST;
7795     WHILE I IS NOT NULL LOOP
7796 
7797         IF p_x_line_price_Att_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
7798             x_return_status := FND_API.G_RET_STS_ERROR;
7799         END IF;
7800 
7801 	      I := p_x_line_price_Att_tbl.NEXT(I);
7802     END LOOP;
7803 
7804     I := p_x_line_adj_Att_tbl.FIRST;
7805     WHILE I IS NOT NULL LOOP
7806 
7807         IF p_x_line_adj_Att_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
7808             x_return_status := FND_API.G_RET_STS_ERROR;
7809         END IF;
7810 
7811 	      I := p_x_line_adj_Att_tbl.NEXT(I);
7812     END LOOP;
7813 
7814     I := p_x_line_adj_Assoc_tbl.FIRST;
7815     WHILE I IS NOT NULL LOOP
7816 
7817         IF p_x_line_adj_Assoc_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
7818             x_return_status := FND_API.G_RET_STS_ERROR;
7819         END IF;
7820 
7821 	      I := p_x_line_adj_Assoc_tbl.NEXT(I);
7822     END LOOP;
7823 
7824     IF l_debug_level  > 0 THEN
7825         oe_debug_pub.add(  'JPN: BEFORE CALLING NOTIFY , HEADER_ID IS: ' || P_X_HEADER_REC.HEADER_ID ) ;
7826     END IF;
7827 --  Calling Update Notice API - Provided by OC
7828 --  This API will notify OC about the changes happen in OM side for order
7829 
7830     /* Notification Project changes */
7831     /* Call Process_Requests_and_Notify to inform all subscribers */
7832 
7833  IF (OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110508') then
7834       /* Call Process Requests and notify */
7835           IF l_debug_level  > 0 THEN
7836            oe_debug_pub.add(  'CALLING PROCESS_REQUESTS_AND_NOTIFY FOR PACK H IN PROCESS_ORDER_AG' );
7837           END IF;
7838           Process_Requests_And_Notify(
7839                       p_process_requests => FALSE,
7840                       p_notify           => TRUE,
7841                       x_return_status    => l_return_status,
7842                       p_header_rec       => p_x_header_rec,
7843                       p_old_header_rec   => l_old_header_rec,
7844                       p_Header_Adj_tbl   => p_x_Header_Adj_tbl,
7845                       p_old_Header_Adj_tbl => l_old_Header_Adj_tbl,
7846                       p_Header_Scredit_tbl => p_x_header_Scredit_tbl,
7847                       p_old_Header_Scredit_tbl => l_old_Header_Scredit_tbl,
7848                       p_Header_Payment_tbl => p_x_header_Payment_tbl,
7849                       p_old_Header_Payment_tbl => l_old_Header_Payment_tbl,
7850                       p_line_tbl          =>p_x_line_tbl,
7851                       p_old_line_tbl      => l_old_line_tbl,
7852                       p_Line_Adj_tbl      => p_x_line_adj_tbl,
7853                       p_old_line_adj_tbl  => l_old_line_adj_tbl,
7854                       p_Line_Scredit_tbl  => p_x_Line_Scredit_tbl,
7855                       p_old_Line_Scredit_tbl   => l_old_line_Scredit_tbl,
7856                       p_Line_Payment_tbl  => p_x_Line_Payment_tbl,
7857                       p_old_Line_Payment_tbl   => l_old_line_Payment_tbl,
7858                       p_Lot_Serial_tbl    => p_x_lot_Serial_tbl,
7859                       p_old_Lot_Serial_tbl => l_old_Lot_Serial_tbl);
7860 
7861                       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7862                          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7863                       ELSIF l_return_status  = FND_API.G_RET_STS_ERROR THEN
7864                          RAISE FND_API.G_EXC_ERROR;
7865                       END IF;
7866 
7867     ELSE
7868         /* Pre Pack H processsing */
7869 
7870 
7871     IF l_debug_level  > 0 THEN
7872         oe_debug_pub.add(  'CS BEFORE CALLING NOTIFY_OC API' , 1 ) ;
7873     END IF;
7874     IF x_return_status = FND_API.G_RET_STS_SUCCESS AND
7875 	   p_control_rec.write_to_db = TRUE
7876       AND oe_order_cache.g_header_rec.booked_flag = 'Y'
7877     THEN
7878       IF l_debug_level  > 0 THEN
7879           oe_debug_pub.add(  'CS CALLING NOTIFY_OC API' , 1 ) ;
7880       END IF;
7881 
7882     OE_SERVICE_UTIL.Notify_OC
7883     (   p_api_version_number                  =>  l_api_version_number
7884     ,   p_init_msg_list                       =>  FND_API.G_FALSE
7885     ,   p_validation_level                    =>  p_validation_level
7886     ,   p_control_rec                         =>  p_control_rec
7887     ,   x_return_status                       =>  l_return_status
7888     ,   x_msg_count                           =>  x_msg_count
7889     ,   x_msg_data                            =>  x_msg_data
7890     ,   p_header_rec                          =>  p_x_header_rec
7891     ,   p_old_header_rec                      =>  l_old_header_rec
7892     ,   p_header_adj_tbl                      =>  p_x_header_adj_tbl
7893     ,   p_old_header_adj_tbl		           =>  l_old_header_adj_tbl
7894     ,   p_header_price_att_tbl                =>  p_x_header_price_att_tbl
7895     ,   p_old_header_price_att_tbl            =>  l_old_header_price_att_tbl
7896     ,   p_Header_Adj_Att_tbl                  =>  p_x_header_adj_Att_tbl
7897     ,   p_old_Header_Adj_Att_tbl              =>  l_old_header_Adj_Att_tbl
7898     ,   p_Header_Adj_Assoc_tbl                =>  p_x_header_adj_Assoc_tbl
7899     ,   p_old_Header_Adj_Assoc_tbl            =>  l_old_header_Adj_Assoc_tbl
7900     ,   p_Header_Scredit_tbl                  =>  p_x_header_scredit_tbl
7901     ,   p_old_Header_Scredit_tbl              =>  l_old_header_Scredit_tbl
7902 --  ,   p_Header_Payment_tbl                  =>  p_x_header_Payment_tbl
7903 --  ,   p_old_Header_Payment_tbl              =>  l_old_header_Payment_tbl
7904     ,   p_line_tbl                            =>  p_x_line_tbl
7905     ,   p_old_line_tbl                        =>  l_old_line_tbl
7906     ,   p_Line_Adj_tbl                        =>  p_x_line_adj_tbl
7907     ,   p_old_Line_Adj_tbl                    =>  l_old_line_Adj_tbl
7908     ,   p_Line_Price_Att_tbl                  =>  p_x_line_price_Att_tbl
7909     ,   p_old_Line_Price_Att_tbl              =>  l_old_line_Price_Att_tbl
7910     ,   p_Line_Adj_Att_tbl                    =>  p_x_line_adj_Att_tbl
7911     ,   p_old_Line_Adj_Att_tbl                =>  l_old_line_Adj_Att_tbl
7912     ,   p_Line_Adj_Assoc_tbl                  =>  p_x_line_adj_Assoc_tbl
7913     ,   p_old_Line_Adj_Assoc_tbl              =>  l_old_line_Adj_Assoc_tbl
7914     ,   p_Line_Scredit_tbl                    =>  p_x_line_scredit_tbl
7915     ,   p_old_Line_Scredit_tbl                =>  l_old_line_Scredit_tbl
7916 --  ,   p_Line_Payment_tbl                    =>  p_x_line_Payment_tbl
7917 --  ,   p_old_Line_Payment_tbl                =>  l_old_line_Payment_tbl
7918     ,   p_Lot_Serial_tbl                      =>  p_x_lot_serial_tbl
7919     ,   p_old_Lot_Serial_tbl                  =>  l_old_lot_Serial_tbl
7920     ,   p_Lot_Serial_val_tbl                  =>  p_lot_serial_val_tbl
7921     ,   p_old_Lot_Serial_val_tbl              =>  l_old_lot_Serial_val_tbl
7922     ,   p_action_request_tbl	              =>  p_x_action_request_tbl
7923     );
7924 
7925 
7926        IF l_debug_level  > 0 THEN
7927            oe_debug_pub.add(  'AFTER NOTIFY_OC API' , 1 ) ;
7928        END IF;
7929 	  IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7930           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7931        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
7932           RAISE FND_API.G_EXC_ERROR;
7933        END IF;
7934 
7935 
7936     END IF;
7937 
7938     IF l_debug_level  > 0 THEN
7939         oe_debug_pub.add(  'PROCESSING ACKS' , 1 ) ;
7940     END IF;
7941 
7942     IF  OE_Globals.G_RECURSION_MODE <> 'Y' AND
7943         x_return_status = FND_API.G_RET_STS_SUCCESS AND
7944 	   l_control_rec.write_to_db = TRUE
7945     THEN
7946       IF l_debug_level  > 0 THEN
7947           oe_debug_pub.add(  'CALLING ACKS API' , 1 ) ;
7948       END IF;
7949 
7950       If Oe_Code_Control.Code_Release_Level >= '110510' And
7951          p_x_header_rec.order_source_id in (0,2,6) And
7952          l_edi_ack_pfile = 'YES' Then
7953         OE_Acknowledgment_Pvt.Process_Acknowledgment
7954         (p_header_rec           => p_x_header_rec,
7955          p_line_tbl             => p_x_line_tbl,
7956          p_old_header_rec       => l_old_header_rec,
7957          p_old_line_tbl         => l_old_line_tbl,
7958          x_return_status        => l_return_status);
7959       Elsif l_edi_ack_pfile = 'NO' And
7960             p_x_header_rec.order_source_id in (0,2,6,20) Then
7961 
7962       OE_Acknowledgment_Pvt.Process_Acknowledgment
7963      (p_api_version_number 		=> 1
7964      ,p_init_msg_list 		        => p_init_msg_list
7965 
7966      ,p_header_rec 			=> p_x_header_rec
7967      ,p_header_adj_tbl		        => p_x_header_adj_tbl
7968      ,p_header_Scredit_tbl		=> p_x_header_scredit_tbl
7969      ,p_line_tbl 			=> p_x_line_tbl
7970      ,p_line_adj_tbl			=> p_x_line_adj_tbl
7971      ,p_line_scredit_tbl		=> p_x_line_scredit_tbl
7972      ,p_lot_serial_tbl		        => p_x_lot_serial_tbl
7973      ,p_action_request_tbl 		=> p_x_action_request_tbl
7974 
7975      ,p_old_header_rec 		   	=> l_old_header_rec
7976      ,p_old_header_adj_tbl 		=> l_old_header_adj_tbl
7977      ,p_old_header_Scredit_tbl 	   	=> l_old_header_scredit_tbl
7978      ,p_old_line_tbl 		        => l_old_line_tbl
7979      ,p_old_line_adj_tbl 		=> l_old_line_adj_tbl
7980      ,p_old_line_scredit_tbl 	   	=> l_old_line_scredit_tbl
7981      ,p_old_lot_serial_tbl		=> l_old_lot_serial_tbl
7982 
7983      ,p_buyer_seller_flag           	=> 'B'
7984      ,p_reject_order                	=> 'N'
7985 
7986      ,x_return_status                   => l_return_status
7987      );
7988 
7989      End If;
7990 
7991      IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7992         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7993      ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
7994         RAISE FND_API.G_EXC_ERROR;
7995         x_return_status := l_return_status;
7996      END IF;
7997     END IF;
7998 
7999 END IF; /* Code Level check */
8000 
8001 --    Bug 2909598 - do not copy return status back from local
8002 --    variable. For errors, x_return_status is set after call to
8003 --    every procedure. Copying now may result in copying a success
8004 --    value back as the last procedure called returned success but
8005 --    a prior procedure could have returned error - in this case,
8006 --    error should be the overall return status.
8007 
8008 --    x_return_status := l_return_status;
8009 
8010 IF l_debug_level  > 0 THEN
8011     oe_debug_pub.add(  'EXIT PROCESS_ORDER_AG' , 1 ) ;
8012 END IF;
8013 END Process_Order_AG;
8014 
8015 /*----------------------------------------------------------------
8016 --  Start of Comments
8017 --  API name    Process_Order
8018 --  Type        Private
8019 --
8020 --  Pre-reqs
8021 --
8022 --  Parameters
8023 --
8024 --  Version     Current version = 1.0
8025 --              Initial version = 1.0
8026 --
8027 --  Notes
8028 --
8029 --  End of Comments
8030 ----------------------------------------------------------------*/
8031 PROCEDURE Process_Order
8032 (   p_api_version_number            IN  NUMBER
8033 ,   p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
8034 ,   p_validation_level              IN  NUMBER := FND_API.G_VALID_LEVEL_FULL
8035 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type :=
8036                                         OE_GLOBALS.G_MISS_CONTROL_REC
8037 , x_return_status OUT NOCOPY VARCHAR2
8038 
8039 , x_msg_count OUT NOCOPY NUMBER
8040 
8041 , x_msg_data OUT NOCOPY VARCHAR2
8042 
8043 ,   p_x_header_rec                  IN OUT NOCOPY OE_Order_PUB.Header_Rec_Type
8044 ,   p_old_header_rec                IN  OE_Order_PUB.Header_Rec_Type :=
8045                                         OE_Order_PUB.G_MISS_HEADER_REC
8046 ,   p_x_Header_Adj_tbl              IN OUT NOCOPY OE_Order_PUB.Header_Adj_Tbl_Type
8047 ,   p_old_Header_Adj_tbl            IN  OE_Order_PUB.Header_Adj_Tbl_Type :=
8048                                         OE_Order_PUB.G_MISS_HEADER_ADJ_TBL
8049 ,   p_x_Header_Price_Att_tbl        IN OUT NOCOPY OE_Order_PUB.Header_Price_Att_Tbl_Type
8050 ,   p_old_Header_Price_Att_tbl      IN  OE_Order_PUB.Header_Price_Att_Tbl_Type :=
8051                                         OE_Order_PUB.G_MISS_HEADER_PRICE_ATT_TBL
8052 ,   p_x_Header_Adj_Att_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Adj_Att_Tbl_Type
8053 ,   p_old_Header_Adj_Att_tbl        IN  OE_Order_PUB.Header_Adj_Att_Tbl_Type :=
8054     								OE_Order_PUB.G_MISS_HEADER_ADJ_ATT_TBL
8055 ,   p_x_Header_Adj_Assoc_tbl        IN OUT NOCOPY OE_Order_PUB.Header_Adj_Assoc_Tbl_Type
8056 ,   p_old_Header_Adj_Assoc_tbl      IN  OE_Order_PUB.Header_Adj_Assoc_Tbl_Type :=
8057     								OE_Order_PUB.G_MISS_HEADER_ADJ_ASSOC_TBL
8058 ,   p_x_Header_Scredit_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Scredit_Tbl_Type
8059 ,   p_old_Header_Scredit_tbl        IN  OE_Order_PUB.Header_Scredit_Tbl_Type :=
8060                                         OE_Order_PUB.G_MISS_HEADER_SCREDIT_TBL
8061 ,   p_x_line_tbl                    IN OUT NOCOPY OE_Order_PUB.Line_Tbl_Type
8062 ,   p_old_line_tbl                  IN  OE_Order_PUB.Line_Tbl_Type :=
8063                                         OE_Order_PUB.G_MISS_LINE_TBL
8064 ,   p_x_Line_Adj_tbl                IN OUT NOCOPY OE_Order_PUB.Line_Adj_Tbl_Type
8065 ,   p_old_Line_Adj_tbl              IN  OE_Order_PUB.Line_Adj_Tbl_Type :=
8066                                         OE_Order_PUB.G_MISS_LINE_ADJ_TBL
8067 ,   p_x_Line_Price_Att_tbl          IN OUT NOCOPY OE_Order_PUB.Line_Price_Att_Tbl_Type
8068 ,   p_old_Line_Price_Att_tbl        IN  OE_Order_PUB.Line_Price_Att_Tbl_Type :=
8069                                         OE_Order_PUB.G_MISS_LINE_PRICE_ATT_TBL
8070 ,   p_x_Line_Adj_Att_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Adj_Att_Tbl_Type
8071 ,   p_old_Line_Adj_Att_tbl          IN  OE_Order_PUB.Line_Adj_Att_Tbl_Type :=
8072     								OE_Order_PUB.G_MISS_LINE_ADJ_ATT_TBL
8073 ,   p_x_Line_Adj_Assoc_tbl          IN OUT NOCOPY OE_Order_PUB.Line_Adj_Assoc_Tbl_Type
8074 ,   p_old_Line_Adj_Assoc_tbl        IN  OE_Order_PUB.Line_Adj_Assoc_Tbl_Type :=
8075     								OE_Order_PUB.G_MISS_LINE_ADJ_ASSOC_TBL
8076 ,   p_x_Line_Scredit_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Scredit_Tbl_Type
8077 ,   p_old_Line_Scredit_tbl          IN  OE_Order_PUB.Line_Scredit_Tbl_Type :=
8078                                         OE_Order_PUB.G_MISS_LINE_SCREDIT_TBL
8079 ,   p_x_Lot_Serial_tbl              IN OUT NOCOPY OE_Order_PUB.Lot_Serial_Tbl_Type
8080 ,   p_old_Lot_Serial_tbl            IN  OE_Order_PUB.Lot_Serial_Tbl_Type :=
8081                                         OE_Order_PUB.G_MISS_LOT_SERIAL_TBL
8082 ,   p_Lot_Serial_val_tbl            IN  OE_Order_PUB.Lot_Serial_Val_Tbl_Type :=
8083                                         OE_Order_PUB.G_MISS_LOT_SERIAL_VAL_TBL
8084 ,   p_old_Lot_Serial_val_tbl        IN  OE_Order_PUB.Lot_Serial_Val_Tbl_Type :=
8085                                         OE_Order_PUB.G_MISS_LOT_SERIAL_VAL_TBL
8086 ,   p_x_action_request_tbl	      IN OUT NOCOPY OE_Order_PUB.request_tbl_type
8087 ,   p_action_commit				 IN  VARCHAR2 := FND_API.G_FALSE
8088 )
8089 IS
8090 l_x_Header_Payment_tbl          OE_Order_PUB.Header_Payment_Tbl_Type;
8091 l_x_Line_Payment_tbl            OE_Order_PUB.Line_Payment_Tbl_Type;
8092 BEGIN
8093 
8094      Process_Order
8095      (   p_api_version_number            => p_api_version_number
8096      ,   p_init_msg_list                 => p_init_msg_list
8097      ,   p_validation_level              => p_validation_level
8098      ,   p_control_rec                   => p_control_rec
8099      ,   x_return_status => x_return_status
8100 
8101      ,   x_msg_count => x_msg_count
8102 
8103      ,   x_msg_data => x_msg_data
8104 
8105      ,   p_x_header_rec                  => p_x_header_rec
8106      ,   p_old_header_rec                => p_old_header_rec
8107      ,   p_x_Header_Adj_tbl              => p_x_Header_Adj_tbl
8108      ,   p_old_Header_Adj_tbl            => p_old_Header_Adj_tbl
8109      ,   p_x_Header_Price_Att_tbl        => p_x_Header_Price_Att_tbl
8110      ,   p_old_Header_Price_Att_tbl      => p_old_Header_Price_Att_tbl
8111      ,   p_x_Header_Adj_Att_tbl          => p_x_Header_Adj_Att_tbl
8112      ,   p_old_Header_Adj_Att_tbl        => p_old_Header_Adj_Att_tbl
8113      ,   p_x_Header_Adj_Assoc_tbl        => p_x_Header_Adj_Assoc_tbl
8114      ,   p_old_Header_Adj_Assoc_tbl      => p_old_Header_Adj_Assoc_tbl
8115      ,   p_x_Header_Scredit_tbl          => p_x_Header_Scredit_tbl
8116      ,   p_old_Header_Scredit_tbl        => p_old_Header_Scredit_tbl
8117      ,   p_x_Header_Payment_tbl          => l_x_Header_Payment_tbl
8118      ,   p_x_line_tbl                    => p_x_line_tbl
8119      ,   p_old_line_tbl                  => p_old_line_tbl
8120      ,   p_x_Line_Adj_tbl                => p_x_Line_Adj_tbl
8121      ,   p_old_Line_Adj_tbl              => p_old_Line_Adj_tbl
8122      ,   p_x_Line_Price_Att_tbl          => p_x_Line_Price_Att_tbl
8123      ,   p_old_Line_Price_Att_tbl        => p_old_Line_Price_Att_tbl
8124      ,   p_x_Line_Adj_Att_tbl            => p_x_Line_Adj_Att_tbl
8125      ,   p_old_Line_Adj_Att_tbl          => p_old_Line_Adj_Att_tbl
8126      ,   p_x_Line_Adj_Assoc_tbl          => p_x_Line_Adj_Assoc_tbl
8127      ,   p_old_Line_Adj_Assoc_tbl        => p_old_Line_Adj_Assoc_tbl
8128      ,   p_x_Line_Scredit_tbl            => p_x_Line_Scredit_tbl
8129      ,   p_old_Line_Scredit_tbl          => p_old_Line_Scredit_tbl
8130      ,   p_x_Line_Payment_tbl            => l_x_Line_Payment_tbl
8131      ,   p_x_Lot_Serial_tbl              => p_x_Lot_Serial_tbl
8132      ,   p_old_Lot_Serial_tbl            => p_old_Lot_Serial_tbl
8133      ,   p_Lot_Serial_val_tbl            => p_Lot_Serial_val_tbl
8134      ,   p_old_Lot_Serial_val_tbl        => p_old_Lot_Serial_val_tbl
8135      ,   p_x_action_request_tbl          => p_x_action_request_tbl
8136      ,   p_action_commit		 => p_action_commit
8137      );
8138 END Process_Order;
8139 
8140 -- overloaded for payments
8141 PROCEDURE Process_Order
8142 (   p_api_version_number            IN  NUMBER
8143 ,   p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
8144 ,   p_validation_level              IN  NUMBER := FND_API.G_VALID_LEVEL_FULL
8145 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type :=
8146                                         OE_GLOBALS.G_MISS_CONTROL_REC
8147 , x_return_status OUT NOCOPY VARCHAR2
8148 
8149 , x_msg_count OUT NOCOPY NUMBER
8150 
8151 , x_msg_data OUT NOCOPY VARCHAR2
8152 
8153 ,   p_x_header_rec                  IN OUT NOCOPY OE_Order_PUB.Header_Rec_Type
8154 ,   p_old_header_rec                IN  OE_Order_PUB.Header_Rec_Type :=
8155                                         OE_Order_PUB.G_MISS_HEADER_REC
8156 ,   p_x_Header_Adj_tbl              IN OUT NOCOPY OE_Order_PUB.Header_Adj_Tbl_Type
8157 ,   p_old_Header_Adj_tbl            IN  OE_Order_PUB.Header_Adj_Tbl_Type :=
8158                                         OE_Order_PUB.G_MISS_HEADER_ADJ_TBL
8159 ,   p_x_Header_Price_Att_tbl        IN OUT NOCOPY OE_Order_PUB.Header_Price_Att_Tbl_Type
8160 ,   p_old_Header_Price_Att_tbl      IN  OE_Order_PUB.Header_Price_Att_Tbl_Type :=
8161                                         OE_Order_PUB.G_MISS_HEADER_PRICE_ATT_TBL
8162 ,   p_x_Header_Adj_Att_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Adj_Att_Tbl_Type
8163 ,   p_old_Header_Adj_Att_tbl        IN  OE_Order_PUB.Header_Adj_Att_Tbl_Type :=
8164     								OE_Order_PUB.G_MISS_HEADER_ADJ_ATT_TBL
8165 ,   p_x_Header_Adj_Assoc_tbl        IN OUT NOCOPY OE_Order_PUB.Header_Adj_Assoc_Tbl_Type
8166 ,   p_old_Header_Adj_Assoc_tbl      IN  OE_Order_PUB.Header_Adj_Assoc_Tbl_Type :=
8167     								OE_Order_PUB.G_MISS_HEADER_ADJ_ASSOC_TBL
8168 ,   p_x_Header_Scredit_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Scredit_Tbl_Type
8169 ,   p_old_Header_Scredit_tbl        IN  OE_Order_PUB.Header_Scredit_Tbl_Type :=
8170                                         OE_Order_PUB.G_MISS_HEADER_SCREDIT_TBL
8171 ,   p_x_Header_Payment_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Payment_Tbl_Type
8172 ,   p_old_Header_Payment_tbl        IN  OE_Order_PUB.Header_Payment_Tbl_Type :=
8173                                         OE_Order_PUB.G_MISS_HEADER_PAYMENT_TBL
8174 ,   p_x_line_tbl                    IN OUT NOCOPY OE_Order_PUB.Line_Tbl_Type
8175 ,   p_old_line_tbl                  IN  OE_Order_PUB.Line_Tbl_Type :=
8176                                         OE_Order_PUB.G_MISS_LINE_TBL
8177 ,   p_x_Line_Adj_tbl                IN OUT NOCOPY OE_Order_PUB.Line_Adj_Tbl_Type
8178 ,   p_old_Line_Adj_tbl              IN  OE_Order_PUB.Line_Adj_Tbl_Type :=
8179                                         OE_Order_PUB.G_MISS_LINE_ADJ_TBL
8180 ,   p_x_Line_Price_Att_tbl          IN OUT NOCOPY OE_Order_PUB.Line_Price_Att_Tbl_Type
8181 ,   p_old_Line_Price_Att_tbl        IN  OE_Order_PUB.Line_Price_Att_Tbl_Type :=
8182                                         OE_Order_PUB.G_MISS_LINE_PRICE_ATT_TBL
8183 ,   p_x_Line_Adj_Att_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Adj_Att_Tbl_Type
8184 ,   p_old_Line_Adj_Att_tbl          IN  OE_Order_PUB.Line_Adj_Att_Tbl_Type :=
8185     								OE_Order_PUB.G_MISS_LINE_ADJ_ATT_TBL
8186 ,   p_x_Line_Adj_Assoc_tbl          IN OUT NOCOPY OE_Order_PUB.Line_Adj_Assoc_Tbl_Type
8187 ,   p_old_Line_Adj_Assoc_tbl        IN  OE_Order_PUB.Line_Adj_Assoc_Tbl_Type :=
8188     								OE_Order_PUB.G_MISS_LINE_ADJ_ASSOC_TBL
8189 ,   p_x_Line_Scredit_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Scredit_Tbl_Type
8190 ,   p_old_Line_Scredit_tbl          IN  OE_Order_PUB.Line_Scredit_Tbl_Type :=
8191                                         OE_Order_PUB.G_MISS_LINE_SCREDIT_TBL
8192 ,   p_x_Line_Payment_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Payment_Tbl_Type
8193 ,   p_old_Line_Payment_tbl          IN  OE_Order_PUB.Line_Payment_Tbl_Type :=
8194                                         OE_Order_PUB.G_MISS_LINE_PAYMENT_TBL
8195 ,   p_x_Lot_Serial_tbl              IN OUT NOCOPY OE_Order_PUB.Lot_Serial_Tbl_Type
8196 ,   p_old_Lot_Serial_tbl            IN  OE_Order_PUB.Lot_Serial_Tbl_Type :=
8197                                         OE_Order_PUB.G_MISS_LOT_SERIAL_TBL
8198 ,   p_Lot_Serial_val_tbl            IN  OE_Order_PUB.Lot_Serial_Val_Tbl_Type :=
8199                                         OE_Order_PUB.G_MISS_LOT_SERIAL_VAL_TBL
8200 ,   p_old_Lot_Serial_val_tbl        IN  OE_Order_PUB.Lot_Serial_Val_Tbl_Type :=
8201                                         OE_Order_PUB.G_MISS_LOT_SERIAL_VAL_TBL
8202 ,   p_x_action_request_tbl	      IN OUT NOCOPY OE_Order_PUB.request_tbl_type
8203 ,   p_action_commit				 IN  VARCHAR2 := FND_API.G_FALSE
8204 )
8205 IS
8206 l_api_version_number          CONSTANT NUMBER := 1.0;
8207 l_api_name                    CONSTANT VARCHAR2(30):= 'Process_Order';
8208 l_return_status               VARCHAR2(1);
8209 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
8210 l_header_rec                  OE_Order_PUB.Header_Rec_Type := p_x_header_rec;
8211 l_old_header_rec              OE_Order_PUB.Header_Rec_Type := p_old_header_rec;
8212 l_Header_Adj_rec              OE_Order_PUB.Header_Adj_Rec_Type;
8213 l_Header_Adj_tbl              OE_Order_PUB.Header_Adj_Tbl_Type;
8214 l_old_Header_Adj_rec          OE_Order_PUB.Header_Adj_Rec_Type;
8215 l_old_Header_Adj_tbl          OE_Order_PUB.Header_Adj_Tbl_Type;
8216 l_Header_price_Att_rec        OE_Order_PUB.Header_Price_Att_Rec_Type ;
8217 l_old_Header_price_Att_rec    OE_Order_PUB.Header_Price_Att_Rec_Type ;
8218 l_Header_price_Att_Tbl        OE_Order_PUB.Header_Price_Att_Tbl_Type ;
8219 l_Old_Header_price_Att_Tbl    OE_Order_PUB.Header_Price_Att_Tbl_Type ;
8220 l_Header_Adj_Att_tbl          OE_Order_PUB.Header_Adj_Att_Tbl_Type ;
8221 l_old_Header_Adj_Att_tbl      OE_Order_PUB.Header_Adj_Att_Tbl_Type ;
8222 l_Header_Adj_Att_Rec          OE_Order_PUB.Header_Adj_Att_Rec_Type ;
8223 l_old_Header_Adj_Att_Rec      OE_Order_PUB.Header_Adj_Att_Rec_Type ;
8224 l_Header_Adj_Assoc_tbl        OE_Order_PUB.Header_Adj_Assoc_Tbl_Type ;
8225 l_old_Header_Adj_Assoc_tbl    OE_Order_PUB.Header_Adj_Assoc_Tbl_Type ;
8226 l_Header_Adj_Assoc_Rec        OE_Order_PUB.Header_Adj_Assoc_Rec_Type ;
8227 l_old_Header_Adj_Assoc_Rec    OE_Order_PUB.Header_Adj_Assoc_Rec_Type ;
8228 l_Header_Scredit_rec          OE_Order_PUB.Header_Scredit_Rec_Type;
8229 l_Header_Scredit_tbl          OE_Order_PUB.Header_Scredit_Tbl_Type;
8230 l_old_Header_Scredit_rec      OE_Order_PUB.Header_Scredit_Rec_Type;
8231 l_old_Header_Scredit_tbl      OE_Order_PUB.Header_Scredit_Tbl_Type;
8232 l_line_rec                    OE_Order_PUB.Line_Rec_Type;
8233 l_line_tbl                    OE_Order_PUB.Line_Tbl_Type;
8234 l_old_line_rec                OE_Order_PUB.Line_Rec_Type;
8235 l_old_line_tbl                OE_Order_PUB.Line_Tbl_Type;
8236 l_Line_Adj_rec                OE_Order_PUB.Line_Adj_Rec_Type;
8237 l_Line_Adj_tbl                OE_Order_PUB.Line_Adj_Tbl_Type;
8238 l_old_Line_Adj_rec            OE_Order_PUB.Line_Adj_Rec_Type;
8239 l_old_Line_Adj_tbl            OE_Order_PUB.Line_Adj_Tbl_Type;
8240 l_Line_price_Att_rec          OE_Order_PUB.Line_Price_Att_Rec_Type ;
8241 l_old_Line_price_Att_rec      OE_Order_PUB.Line_Price_Att_Rec_Type ;
8242 l_Line_price_Att_Tbl          OE_Order_PUB.Line_Price_Att_Tbl_Type ;
8243 l_Old_Line_price_Att_Tbl      OE_Order_PUB.Line_Price_Att_Tbl_Type ;
8244 l_Line_Adj_Att_tbl            OE_Order_PUB.Line_Adj_Att_Tbl_Type ;
8245 l_old_Line_Adj_Att_tbl        OE_Order_PUB.Line_Adj_Att_Tbl_Type ;
8246 l_Line_Adj_Att_Rec            OE_Order_PUB.Line_Adj_Att_Rec_Type ;
8247 l_old_Line_Adj_Att_Rec        OE_Order_PUB.Line_Adj_Att_Rec_Type ;
8248 l_Line_Adj_Assoc_tbl          OE_Order_PUB.Line_Adj_Assoc_Tbl_Type ;
8249 l_old_Line_Adj_Assoc_tbl      OE_Order_PUB.Line_Adj_Assoc_Tbl_Type ;
8250 l_Line_Adj_Assoc_Rec          OE_Order_PUB.Line_Adj_Assoc_Rec_Type ;
8251 l_old_Line_Adj_Assoc_Rec      OE_Order_PUB.Line_Adj_Assoc_Rec_Type ;
8252 l_Line_Scredit_rec            OE_Order_PUB.Line_Scredit_Rec_Type;
8253 l_Line_Scredit_tbl            OE_Order_PUB.Line_Scredit_Tbl_Type;
8254 l_old_Line_Scredit_rec        OE_Order_PUB.Line_Scredit_Rec_Type;
8255 l_old_Line_Scredit_tbl        OE_Order_PUB.Line_Scredit_Tbl_Type;
8256 l_Lot_Serial_rec              OE_Order_PUB.Lot_Serial_Rec_Type;
8257 l_Lot_Serial_tbl              OE_Order_PUB.Lot_Serial_Tbl_Type;
8258 l_old_Lot_Serial_rec          OE_Order_PUB.Lot_Serial_Rec_Type;
8259 l_old_Lot_Serial_tbl          OE_Order_PUB.Lot_Serial_Tbl_Type;
8260 l_request_tbl		      OE_Order_PUB.REQUEST_TBL_TYPE :=
8261  				 		p_x_action_request_tbl;
8262 
8263 l_lot_serial_val_tbl         OE_Order_Pub.Lot_Serial_Val_Tbl_Type;
8264 l_old_lot_serial_val_tbl     OE_Order_Pub.Lot_Serial_Val_Tbl_Type;
8265 l_line_index                  NUMBER;
8266 l_header_id 			NUMBER;
8267 I 					NUMBER; -- Used for as table index.
8268 l_init_msg_list          VARCHAR2(1) := p_init_msg_list;
8269 l_validation_level       NUMBER      := FND_API.G_VALID_LEVEL_FULL;
8270 l_Call_Split             BOOLEAN := FALSE;
8271 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8272 l_edi_ack_pfile          Varchar2(3);
8273 
8274 BEGIN
8275 
8276      -- Track the recursion
8277 
8278        set_recursion_mode(p_Entity_Code => 1,
8279                           p_In_out  => 1);
8280 
8281         x_return_status := FND_API.G_RET_STS_SUCCESS;
8282         fnd_profile.get('ONT_NEW_EDI_ACK_FWK', l_edi_ack_pfile);
8283         l_edi_ack_pfile := nvl(l_edi_ack_pfile, 'NO');
8284 
8285 	IF OE_GLOBALS.G_RECURSION_MODE <> 'Y' THEN
8286 
8287 	   SAVEPOINT Process_Order;
8288      END IF;
8289 
8290 
8291     IF l_debug_level  > 0 THEN
8292         oe_debug_pub.add(  'ENTERING OE_ORDER_PUB.PROCESS_ORDER' , 1 ) ;
8293     END IF;
8294     --  Standard call to check for call compatibility
8295 
8296     IF NOT FND_API.Compatible_API_Call
8297            (   l_api_version_number
8298            ,   p_api_version_number
8299            ,   l_api_name
8300            ,   G_PKG_NAME
8301            )
8302     THEN
8303         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8304     END IF;
8305 
8306     --  Initialize message list.
8307 
8308     IF FND_API.to_Boolean(p_init_msg_list) THEN
8309         OE_MSG_PUB.initialize;
8310     END IF;
8311 
8312     -- Set Org Context
8313 
8314     OE_GLOBALS.Set_Context;
8315 
8316     -- Bug 1929163: improving performance by not copying in variables
8317     -- to local variables. Can directly work on the IN OUT variables
8318     -- IMPORTANT NOTE:
8319     -- Please add code both in process_order AND process_order_ag
8320     -- procedures when making further modifications. At some later point
8321     -- when QA has completely tested the new code path, process_order
8322     -- will be replaced with code in process_order_ag.
8323 
8324     -- With OM Family Pack I or 11.5.9 onwards, new performance code
8325     -- will be activated.
8326 
8327     IF OE_CODE_CONTROL.Code_Release_Level >= '110509' THEN
8328        Process_Order_AG
8329        (   p_api_version_number                  =>  p_api_version_number
8330         ,   p_init_msg_list                       =>  p_init_msg_list
8331         ,   p_validation_level                    =>  p_validation_level
8332         ,   p_control_rec                         =>  p_control_rec
8333         ,   x_return_status                       =>  x_return_status
8334         ,   x_msg_count                           =>  x_msg_count
8335         ,   x_msg_data                            =>  x_msg_data
8336         ,   p_x_header_rec                        =>  p_x_header_rec
8337         ,   p_old_header_rec                      =>  p_old_header_rec
8338         ,   p_x_header_adj_tbl                    =>  p_x_header_adj_tbl
8339         ,   p_old_header_adj_tbl                  =>  p_old_header_adj_tbl
8340         ,   p_x_header_price_att_tbl              =>  p_x_header_price_att_tbl
8341         ,   p_old_header_price_att_tbl            =>  p_old_header_price_att_tbl
8342         ,   p_x_Header_Adj_Att_tbl                =>  p_x_header_adj_Att_tbl
8343         ,   p_old_Header_Adj_Att_tbl              =>  p_old_header_Adj_Att_tbl
8344         ,   p_x_Header_Adj_Assoc_tbl              =>  p_x_header_adj_Assoc_tbl
8345         ,   p_old_Header_Adj_Assoc_tbl            =>  p_old_header_Adj_Assoc_tbl
8346         ,   p_x_Header_Scredit_tbl                =>  p_x_header_scredit_tbl
8347         ,   p_old_Header_Scredit_tbl              =>  p_old_header_Scredit_tbl
8348         ,   p_x_Header_Payment_tbl                =>  p_x_header_Payment_tbl
8349         ,   p_old_Header_Payment_tbl              =>  p_old_header_Payment_tbl
8350         ,   p_x_line_tbl                          =>  p_x_line_tbl
8351         ,   p_old_line_tbl                        =>  p_old_line_tbl
8352         ,   p_x_Line_Adj_tbl                      =>  p_x_line_adj_tbl
8353         ,   p_old_Line_Adj_tbl                    =>  p_old_line_Adj_tbl
8354         ,   p_x_Line_Price_Att_tbl                =>  p_x_line_price_Att_tbl
8355         ,   p_old_Line_Price_Att_tbl              =>  p_old_line_Price_Att_tbl
8356         ,   p_x_Line_Adj_Att_tbl                  =>  p_x_line_adj_Att_tbl
8357         ,   p_old_Line_Adj_Att_tbl                =>  p_old_line_Adj_Att_tbl
8358         ,   p_x_Line_Adj_Assoc_tbl                =>  p_x_line_adj_Assoc_tbl
8359         ,   p_old_Line_Adj_Assoc_tbl              =>  p_old_line_Adj_Assoc_tbl
8360         ,   p_x_Line_Scredit_tbl                  =>  p_x_line_scredit_tbl
8361         ,   p_old_Line_Scredit_tbl                =>  p_old_line_Scredit_tbl
8362         ,   p_x_Line_Payment_tbl                  =>  p_x_line_Payment_tbl
8363         ,   p_old_Line_Payment_tbl                =>  p_old_line_Payment_tbl
8364         ,   p_x_Lot_Serial_tbl                    =>  p_x_lot_serial_tbl
8365         ,   p_old_Lot_Serial_tbl                  =>  p_old_lot_Serial_tbl
8366         ,   p_Lot_Serial_val_tbl                  =>  p_lot_serial_val_tbl
8367         ,   p_old_Lot_Serial_val_tbl              =>  p_old_lot_Serial_val_tbl
8368         ,   p_x_action_request_tbl                =>  p_x_action_request_tbl
8369         );
8370        GOTO END_OF_PROCESS_ORDER;
8371     END IF;
8372 
8373     --  Init local table variables.
8374 
8375     l_Header_Adj_tbl               := p_x_Header_Adj_tbl;
8376     l_old_Header_Adj_tbl           := p_old_Header_Adj_tbl;
8377 
8378 	l_Header_price_Att_tbl        := p_x_Header_Price_Att_Tbl;
8379 	l_old_Header_price_Att_tbl    := p_old_Header_Price_Att_Tbl;
8380 
8381 	l_Header_Adj_Att_tbl          := p_x_Header_Adj_Att_Tbl;
8382 	l_old_Header_Adj_Att_tbl      := p_old_Header_Adj_Att_Tbl;
8383 
8384 	l_Header_Adj_Assoc_tbl        := P_x_Header_Adj_Assoc_Tbl;
8385 	l_old_Header_Adj_Assoc_tbl    := P_old_Header_Adj_Assoc_Tbl;
8386 
8387     --  Init local table variables.
8388 
8389     l_Header_Scredit_tbl           := p_x_Header_Scredit_tbl;
8390     l_old_Header_Scredit_tbl       := p_old_Header_Scredit_tbl;
8391 
8392     --  Init local table variables.
8393 
8394     l_line_tbl                     := p_x_line_tbl;
8395     l_old_line_tbl                 := p_old_line_tbl;
8396 
8397     --  Init local table variables.
8398 
8399     l_Line_Adj_tbl                 := p_x_Line_Adj_tbl;
8400     l_old_Line_Adj_tbl             := p_old_Line_Adj_tbl;
8401 
8402 	l_Line_price_Att_tbl        := p_x_Line_Price_Att_Tbl;
8403 	l_old_Line_price_Att_tbl    := p_old_Line_Price_Att_Tbl;
8404 
8405 	l_Line_Adj_Att_tbl          := p_x_Line_Adj_Att_Tbl;
8406 	l_old_Line_Adj_Att_tbl      := p_old_Line_Adj_Att_Tbl;
8407 
8408 	l_Line_Adj_Assoc_tbl        := P_x_Line_Adj_Assoc_Tbl;
8409 	l_old_Line_Adj_Assoc_tbl    := P_old_Line_Adj_Assoc_Tbl;
8410 
8411     --  Init local table variables.
8412 
8413     l_Line_Scredit_tbl             := p_x_Line_Scredit_tbl;
8414     l_old_Line_Scredit_tbl         := p_old_Line_Scredit_tbl;
8415 
8416      --  Init local table variables.
8417 
8418     l_Lot_Serial_tbl               := p_x_Lot_Serial_tbl;
8419     l_old_Lot_Serial_tbl           := p_old_Lot_Serial_tbl;
8420 
8421     --  Header
8422 
8423     IF l_debug_level  > 0 THEN
8424         oe_debug_pub.add(  'BEFORE HEADER PROCESSING' , 2 ) ;
8425         oe_debug_pub.add(  'HEADER_ID' || L_HEADER_REC.HEADER_ID , 2 ) ;
8426         oe_debug_pub.add(  'OPERATION' || L_HEADER_REC.OPERATION , 2 ) ;
8427     END IF;
8428 
8429     -------------------------------------------------------
8430     -- Process Header
8431     -------------------------------------------------------
8432 
8433     --Bug 2790512: Prevent processing of header if operation is invalid
8434     --Bug 2878121: Ignore NULL operation code
8435    IF l_header_rec.header_id is NOT NULL AND
8436         l_header_rec.header_id <> FND_API.G_MISS_NUM THEN
8437     IF  l_header_rec.operation IS NOT NULL AND
8438         l_header_rec.operation NOT IN (OE_GLOBALS.G_OPR_CREATE,
8439               OE_GLOBALS.G_OPR_DELETE, OE_GLOBALS.G_OPR_UPDATE,
8440               OE_GLOBALS.G_OPR_NONE) THEN
8441            FND_MESSAGE.SET_NAME('ONT','OE_OI_OPERATION_CODE');
8442            OE_MSG_PUB.Add;
8443            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8444     END IF;
8445    END IF;
8446 
8447     IF l_header_rec.operation IS NOT NULL
8448 	  AND l_header_rec.operation <> OE_GLOBALS.G_OPR_NONE
8449     THEN
8450 
8451     -- This if is add to honor users sales credits if they do not
8452     -- want the default sales credit for the salesrep on the order
8453 
8454     IF l_Header_Scredit_tbl.COUNT > 0 and
8455 	  l_header_rec.operation = oe_globals.g_opr_create THEN
8456       OE_Validate_Header_Scredit.G_Create_Auto_Sales_Credit  := 'N';
8457     END IF;
8458 
8459       Header
8460       (   p_validation_level            => p_validation_level
8461       ,   p_control_rec                 => p_control_rec
8462       ,   p_x_header_rec                => l_header_rec
8463       ,   p_x_old_header_rec            => l_old_header_rec
8464       ,   x_return_status               => l_return_status
8465       );
8466 
8467       OE_Validate_Header_Scredit.G_Create_Auto_Sales_Credit  := 'Y';
8468 
8469       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8470        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8471       ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8472        RAISE FND_API.G_EXC_ERROR;
8473       END IF;
8474     END IF;
8475       IF l_debug_level  > 0 THEN
8476           oe_debug_pub.add(  'AFTER HEADER PROCESSING HEADER_ID = '|| TO_CHAR ( L_HEADER_REC.HEADER_ID ) , 2 ) ;
8477       END IF;
8478 
8479     --  Perform header group requests.
8480 
8481     IF (p_control_rec.process AND
8482     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
8483         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
8484         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_HEADER)
8485     THEN
8486 
8487         NULL;
8488 
8489     END IF;
8490 
8491 
8492     -------------------------------------------------------
8493     -- Process Header Adjustments
8494     -------------------------------------------------------
8495 
8496     -- Set Header Id on Hdr Adjustments
8497 
8498     I := l_Header_Adj_tbl.FIRST;
8499     WHILE I IS NOT NULL LOOP
8500 
8501     --    FOR I IN 1..l_Header_Adj_tbl.COUNT LOOP
8502 
8503         IF l_debug_level  > 0 THEN
8504             oe_debug_pub.add(  'SETTING HEADER ID ON HDR_ADJ_TBL' , 2 ) ;
8505         END IF;
8506         l_Header_Adj_rec := l_Header_Adj_tbl(I);
8507 
8508         IF l_Header_Adj_rec.operation = OE_GLOBALS.G_OPR_CREATE
8509         AND (l_Header_Adj_rec.header_id IS NULL OR
8510             l_Header_Adj_rec.header_id = FND_API.G_MISS_NUM)
8511         THEN
8512           IF l_header_rec.header_id IS NULL OR
8513              l_header_rec.header_id = FND_API.G_MISS_NUM THEN
8514             FND_MESSAGE.SET_NAME('ONT','OE_HEADER_MISSING');
8515             OE_MSG_PUB.Add;
8516             RAISE FND_API.G_EXC_ERROR;
8517           ELSE
8518             --  Copy parent_id.
8519             l_Header_Adj_tbl(I).header_id := l_header_rec.header_id;
8520           END IF;
8521         END IF;
8522 
8523         -- This is added to prevent invalid  upgraded orders
8524         IF I = l_Header_Adj_tbl.FIRST THEN
8525            IF  (l_header_adj_rec.header_id IS NOT NULL AND
8526 		      l_header_adj_rec.header_id <> FND_API.G_MISS_NUM) THEN
8527 	      IF NOT Valid_Upgraded_Order(l_header_adj_rec.header_id ) THEN
8528                  RAISE FND_API.G_EXC_ERROR;
8529            END IF;
8530         END IF;
8531 
8532     END IF;
8533 
8534         I := l_Header_Adj_tbl.NEXT(I);
8535 
8536     END LOOP;
8537 
8538     --  Header_Adjs
8539 
8540     IF l_Header_Adj_tbl.COUNT > 0 THEN
8541       IF l_debug_level  > 0 THEN
8542           oe_debug_pub.add(  'BEFORE OE_ORDER_ADJ_PVT.HEADER_ADJS PROCESSING' , 2 ) ;
8543       END IF;
8544       oe_order_adj_pvt.Header_Adjs
8545       (   p_validation_level            => p_validation_level
8546       ,   p_control_rec                 => p_control_rec
8547       ,   p_x_Header_Adj_tbl            => l_Header_Adj_tbl
8548       ,   p_x_old_Header_Adj_tbl        => l_old_Header_Adj_tbl
8549       );
8550     END IF;
8551 
8552         IF l_debug_level  > 0 THEN
8553             oe_debug_pub.add(  'AFTER HEADER_ADJS PROCESSING' , 2 ) ;
8554         END IF;
8555     --  Perform Header_Adj group requests.
8556 
8557     IF (p_control_rec.process AND
8558       OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
8559         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
8560         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_HEADER_ADJ)
8561     THEN
8562 
8563        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
8564           (p_entity_code   => OE_GLOBALS.G_ENTITY_HEADER_ADJ
8565           ,p_delete        => FND_API.G_TRUE
8566           ,x_return_status => l_return_status
8567           );
8568        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8569                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8570        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8571                  RAISE FND_API.G_EXC_ERROR;
8572        END IF;
8573 
8574 
8575     END IF;
8576 
8577 
8578     -------------------------------------------------------
8579     -- Process Header Price Attributes
8580     -------------------------------------------------------
8581 
8582     -- Set Header Id on Hdr Price Attributes
8583 
8584     I := l_Header_Price_att_tbl.FIRST;
8585 
8586     WHILE I IS NOT NULL LOOP
8587 
8588         IF l_debug_level  > 0 THEN
8589             oe_debug_pub.add(  'SETTING HEADER ID ON HDR_PRICE_ATT_TBL' , 2 ) ;
8590         END IF;
8591         l_Header_Price_Att_Rec := l_Header_Price_att_tbl(I);
8592 
8593         IF l_Header_Price_Att_rec.operation = OE_GLOBALS.G_OPR_CREATE
8594         AND (l_Header_Price_Att_rec.header_id IS NULL OR
8595             l_Header_Price_Att_rec.header_id = FND_API.G_MISS_NUM)
8596         THEN
8597           IF l_header_rec.header_id IS NULL OR
8598              l_header_rec.header_id = FND_API.G_MISS_NUM THEN
8599             FND_MESSAGE.SET_NAME('ONT','OE_HEADER_MISSING');
8600             OE_MSG_PUB.Add;
8601             RAISE FND_API.G_EXC_ERROR;
8602           ELSE
8603 
8604             --  Copy parent_id.
8605 
8606             l_Header_Price_Att_tbl(I).header_id := l_header_rec.header_id;
8607           END IF;
8608         END IF;
8609         I := l_Header_Price_Att_tbl.NEXT(I);
8610     END LOOP;
8611 
8612     --  Header_Price_Atts
8613 
8614     IF l_Header_Price_Att_tbl.COUNT > 0 THEN
8615       IF l_debug_level  > 0 THEN
8616           oe_debug_pub.add(  'BEFORE OE_ORDER_ADJ_PVT.HEADER_PRICE_ATTS PROCESSING' , 2 ) ;
8617       END IF;
8618       oe_order_adj_pvt.Header_Price_Atts
8619       (   p_validation_level            => p_validation_level
8620       ,   p_control_rec                 => p_control_rec
8621       ,   p_x_Header_Price_Att_tbl      => l_Header_Price_Att_tbl
8622       ,   p_x_old_Header_Price_Att_tbl  => l_old_Header_Price_Att_tbl
8623       );
8624     END IF;
8625 
8626         IF l_debug_level  > 0 THEN
8627             oe_debug_pub.add(  'AFTER HEADER_PRICE_ATTS PROCESSING' , 2 ) ;
8628         END IF;
8629     --  Perform Header_Price_Att group requests.
8630 
8631     IF (p_control_rec.process AND
8632       OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
8633         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL
8634 	   OR
8635         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_Header_Price_Att
8636 	   )
8637     THEN
8638 
8639        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
8640           (p_entity_code   => OE_GLOBALS.G_ENTITY_Header_Price_Att
8641           ,p_delete        => FND_API.G_TRUE
8642           ,x_return_status => l_return_status
8643           );
8644        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8645                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8646        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8647                  RAISE FND_API.G_EXC_ERROR;
8648        END IF;
8649 
8650 
8651     END IF;
8652 
8653 
8654     -------------------------------------------------------
8655     -- Process Header Adj Attributes
8656     -------------------------------------------------------
8657 
8658     -- Set Header Id on Hdr Adj. Attributes
8659 
8660     I := l_Header_Adj_Att_tbl.FIRST;
8661 
8662     WHILE I IS NOT NULL LOOP
8663 
8664         IF l_debug_level  > 0 THEN
8665             oe_debug_pub.add(  'SETTING PRICE ADJUSTMENT ID ON HDR_ADJ_ATTBS' , 2 ) ;
8666         END IF;
8667         l_Header_Adj_Att_rec := l_Header_Adj_Att_tbl(I);
8668 
8669         IF l_Header_Adj_Att_rec.operation = OE_GLOBALS.G_OPR_CREATE
8670         AND (l_Header_Adj_Att_rec.price_adjustment_id IS NULL OR
8671             l_Header_Adj_Att_rec.price_adjustment_id = FND_API.G_MISS_NUM)
8672         THEN
8673 
8674 		  IF l_header_Adj_Tbl.exists(l_Header_Adj_Att_Rec.Adj_index)
8675 			Then
8676             --  Copy parent_id.
8677 
8678               l_Header_Adj_Att_tbl(I).price_adjustment_id :=
8679 				l_header_Adj_Tbl(l_Header_Adj_Att_Rec.adj_index).price_adjustment_id;
8680 	  	  ELSE
8681 		     IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
8682 			THEN
8683 						IF l_debug_level  > 0 THEN
8684 						    oe_debug_pub.add(  'INVALID ADJ INDEX '|| TO_CHAR ( L_HEADER_ADJ_ATT_REC.ADJ_INDEX ) || 'ON HEADER ADJ ATTRIBUTES' , 2 ) ;
8685 						END IF;
8686 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8687 			     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
8688 			     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Header_Adj_Attribs');
8689 				FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
8690 				FND_MESSAGE.SET_TOKEN('PARENT_INDEX',l_Header_Adj_Att_Rec.adj_index);
8691 				OE_MSG_PUB.Add;
8692                 END IF;
8693            END IF;
8694 
8695         END IF;
8696         I := l_Header_Adj_Att_tbl.NEXT(I);
8697     END LOOP;
8698 
8699     --  Header_Adj_Atts
8700     IF l_Header_Adj_Att_tbl.COUNT > 0 THEN
8701 
8702     IF l_debug_level  > 0 THEN
8703         oe_debug_pub.add(  'BEFORE OE_ORDER_ADJ_PVT.HEADER_ADJ_ATTS PROCESSING' , 2 ) ;
8704     END IF;
8705     oe_order_adj_pvt.Header_Adj_Atts
8706     (   p_validation_level            => p_validation_level
8707     ,   p_control_rec                 => p_control_rec
8708     ,   p_x_Header_Adj_Att_tbl        => l_Header_Adj_Att_tbl
8709     ,   p_x_old_Header_Adj_Att_tbl    => l_old_Header_Adj_Att_tbl
8710     );
8711 
8712         IF l_debug_level  > 0 THEN
8713             oe_debug_pub.add(  'AFTER HEADER_ADJ_ATTS PROCESSING' , 2 ) ;
8714         END IF;
8715 
8716     END IF;
8717 
8718     --  Perform Header_Adj_Att group requests.
8719 
8720     /*
8721     IF (p_control_rec.process AND
8722     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
8723         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL
8724 	   OR
8725         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_Header_Adj_Att
8726 	   )
8727     THEN
8728 
8729        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
8730           (p_entity_code   => OE_GLOBALS.G_ENTITY_Header_Adj_Att
8731           ,p_delete        => FND_API.G_TRUE
8732           ,x_return_status => l_return_status
8733           );
8734        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8735                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8736        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8737                  RAISE FND_API.G_EXC_ERROR;
8738        END IF;
8739 
8740 
8741     END IF;
8742     */
8743 
8744 
8745     -------------------------------------------------------
8746     -- Process Header Adjustment Associations
8747     -------------------------------------------------------
8748 
8749     -- Set Header Id on Hdr Adjustment Associations
8750 
8751     I := l_Header_Adj_Assoc_tbl.FIRST;
8752 
8753     WHILE I IS NOT NULL LOOP
8754 
8755         IF l_debug_level  > 0 THEN
8756             oe_debug_pub.add(  'SETTING HEADER ID ON HDR_ADJ_ASSOC_TBL' , 2 ) ;
8757         END IF;
8758         l_Header_Adj_Assoc_rec := l_Header_Adj_Assoc_tbl(I);
8759 
8760         IF l_Header_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_CREATE
8761         AND (l_Header_Adj_Assoc_rec.Price_Adjustment_id IS NULL OR
8762             l_Header_Adj_Assoc_rec.Price_Adjustment_id = FND_API.G_MISS_NUM)
8763         THEN
8764 
8765 		  IF l_header_Adj_Tbl.exists(l_Header_Adj_Assoc_Rec.Adj_Index) Then
8766             --  Copy parent_id.
8767 
8768               l_Header_Adj_Assoc_tbl(I).price_adjustment_id :=
8769 				l_header_Adj_Tbl(l_Header_Adj_Assoc_Rec.adj_index).price_adjustment_id;
8770 	  	  ELSE
8771 		     IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
8772 			THEN
8773 						IF l_debug_level  > 0 THEN
8774 						    oe_debug_pub.add(  'INVALID ADJ INDEX '|| TO_CHAR ( L_HEADER_ADJ_ASSOC_REC.ADJ_INDEX ) || 'ON HEADER ADJ ATTRIBUTES' , 2 ) ;
8775 						END IF;
8776 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8777 			     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
8778 			     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Header_Adj_Assocs');
8779 				FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
8780 				FND_MESSAGE.SET_TOKEN('PARENT_INDEX',l_Header_Adj_Assoc_Rec.adj_index);
8781 				OE_MSG_PUB.Add;
8782                 END IF;
8783             END IF;
8784 
8785         END IF;
8786 
8787         IF l_Header_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_CREATE
8788         AND (l_Header_Adj_Assoc_rec.rltd_Price_Adj_Id IS NULL OR
8789             l_Header_Adj_Assoc_rec.rltd_Price_Adj_Id = FND_API.G_MISS_NUM)
8790         THEN
8791 
8792 		  IF l_header_Adj_Tbl.exists(l_Header_Adj_Assoc_Rec.Rltd_Adj_Index) Then
8793             --  Copy parent_id.
8794 
8795               l_Header_Adj_Assoc_tbl(I).rltd_Price_Adj_Id :=
8796 				l_header_Adj_Tbl(l_Header_Adj_Assoc_Rec.Rltd_Adj_Index).Price_adjustment_id;
8797             END IF;
8798 
8799         END IF;
8800         I := l_Header_Adj_Assoc_tbl.NEXT(I);
8801     END LOOP;
8802 
8803     --  Header_Adj_Assocs
8804 
8805     IF l_Header_Adj_Assoc_tbl.COUNT > 0 THEN
8806 
8807     IF l_debug_level  > 0 THEN
8808         oe_debug_pub.add(  'BEFORE OE_ORDER_ADJ_PVT.HEADER_ADJ_ASSOCS PROCESSING' , 2 ) ;
8809     END IF;
8810     oe_order_adj_pvt.Header_Adj_Assocs
8811     (   p_validation_level            => p_validation_level
8812     ,   p_control_rec                 => p_control_rec
8813     ,   p_x_Header_Adj_Assoc_tbl      => l_Header_Adj_Assoc_tbl
8814     ,   p_x_old_Header_Adj_Assoc_tbl  => l_old_Header_Adj_Assoc_tbl
8815     );
8816 
8817     IF l_debug_level  > 0 THEN
8818         oe_debug_pub.add(  'AFTER HEADER_ADJ_ASSOCS PROCESSING' , 2 ) ;
8819     END IF;
8820     END IF;
8821 
8822     --  Perform Header_Adj_Assoc group requests.
8823 
8824     /*
8825     IF (p_control_rec.process AND
8826     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
8827         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL
8828 	   OR
8829         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_Header_Adj_Assoc
8830 	   )
8831     THEN
8832 
8833        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
8834           (p_entity_code   => OE_GLOBALS.G_ENTITY_Header_Adj_Assoc
8835           ,p_delete        => FND_API.G_TRUE
8836           ,x_return_status => l_return_status
8837           );
8838        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8839                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8840        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8841                  RAISE FND_API.G_EXC_ERROR;
8842        END IF;
8843 
8844 
8845     END IF;
8846     */
8847 
8848 
8849     -------------------------------------------------------
8850     -- Process Header Sales Credits
8851     -------------------------------------------------------
8852 
8853 
8854     -- Set Header Id on Sales Credits
8855 
8856 --    FOR I IN 1..l_Header_Scredit_tbl.COUNT LOOP
8857 
8858     I := l_Header_Scredit_tbl.FIRST;
8859     WHILE I IS NOT NULL LOOP
8860 
8861         IF l_debug_level  > 0 THEN
8862             oe_debug_pub.add(  'SETTING HEADER_ID ON HEADER_SCREDIT_TBL:'||to_char(l_header_rec.header_id)||'.' , 2 ) ;
8863         END IF;
8864 
8865         l_Header_Scredit_rec := l_Header_Scredit_tbl(I);
8866 
8867         IF l_Header_Scredit_rec.operation = OE_GLOBALS.G_OPR_CREATE
8868         AND (l_Header_Scredit_rec.header_id IS NULL OR
8869 		l_Header_Scredit_rec.header_id = FND_API.G_MISS_NUM)
8870 	   THEN
8871              IF l_header_rec.header_id IS NULL OR      --  p_x_header_rec replaced with l_header_rec for 2896409
8872                 l_header_rec.header_id = FND_API.G_MISS_NUM THEN
8873                  FND_MESSAGE.SET_NAME('ONT','OE_HEADER_MISSING');
8874                  OE_MSG_PUB.Add;
8875                  RAISE FND_API.G_EXC_ERROR;
8876              ELSE
8877 
8878 		--  Copy parent_id.
8879 
8880 		  l_Header_Scredit_tbl(I).header_id := l_header_rec.header_id;
8881              END IF;
8882 	   END IF;
8883 
8884 	   I := l_Header_Scredit_tbl.NEXT(I);
8885     END LOOP;
8886 
8887     --  Header_Scredits
8888 
8889     IF l_Header_Scredit_tbl.COUNT > 0 THEN
8890 
8891     IF l_debug_level  > 0 THEN
8892         oe_debug_pub.add(  'BEFORE HEADER_SCREDITS PROCESSING' , 2 ) ;
8893     END IF;
8894     Header_Scredits
8895     (   p_validation_level            => p_validation_level
8896     ,   p_control_rec                 => p_control_rec
8897     ,   p_x_Header_Scredit_tbl        => l_Header_Scredit_tbl
8898     ,   p_x_old_Header_Scredit_tbl    => l_old_Header_Scredit_tbl
8899     ,   x_return_status               => l_return_status
8900     );
8901     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8902        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8903     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8904 	 IF p_control_rec.process_partial THEN
8905 	    x_return_status := FND_API.G_RET_STS_ERROR;
8906       ELSE
8907          RAISE FND_API.G_EXC_ERROR;
8908       END IF;
8909     END IF;
8910     IF l_debug_level  > 0 THEN
8911         oe_debug_pub.add(  'AFTER HEADER_SCREDITS PROCESSING' , 2 ) ;
8912     END IF;
8913 
8914     END IF;
8915 
8916     --  Perform Header_Scredit group requests.
8917 
8918     IF (p_control_rec.process AND
8919     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
8920         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
8921         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_HEADER_SCREDIT)
8922     THEN
8923 
8924        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
8925           (p_entity_code   => OE_GLOBALS.G_ENTITY_Header_Scredit
8926           ,p_delete        => FND_API.G_TRUE
8927           ,x_return_status => l_return_status
8928           );
8929        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8930                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8931        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8932                  RAISE FND_API.G_EXC_ERROR;
8933        END IF;
8934 
8935     END IF;
8936 
8937 
8938     -- Get header_id from the header and put it on the line.
8939 
8940 -- Kris = decide if
8941 -- Header id may not be passed on the header record if the operation is none
8942 -- I think we should pass header_id on the header rec all the time
8943 
8944 /*
8945 	IF l_line_tbl.COUNT > 0 THEN
8946 
8947 		For k in l_line_tbl.first .. l_line_tbl.last LOOP
8948 
8949 		   IF  (l_line_tbl(k).header_id = FND_API.G_MISS_NUM
8950 		   OR   l_line_tbl(k).header_id is null ) THEN
8951 
8952 -- Kris do not loop through the lines unless they have the right header_id
8953 -- If people pass in a header_id with a bogus value, the record should be ignored
8954 
8955 				l_line_tbl(k).header_id := l_header_rec.header_id;
8956 
8957 		   END IF;
8958 
8959 		End Loop;
8960 
8961   	END IF;
8962 */
8963 
8964 
8965     -------------------------------------------------------
8966     -- Process Lines
8967     -------------------------------------------------------
8968 
8969 --    FOR I IN 1..l_line_tbl.COUNT LOOP
8970 
8971     I := l_line_tbl.FIRST;
8972 
8973     WHILE I IS NOT NULL LOOP
8974 
8975         l_line_rec := l_line_tbl(I);
8976 
8977         --Bug 2790512: Prevent processing of line if operation is invalid
8978         --Bug 2878121: Ignore NULL operation code
8979         IF l_line_rec.operation IS NOT NULL AND
8980            l_line_rec.operation NOT IN (OE_GLOBALS.G_OPR_CREATE,
8981                OE_GLOBALS.G_OPR_DELETE, OE_GLOBALS.G_OPR_UPDATE,
8982                OE_GLOBALS.G_OPR_INSERT, OE_GLOBALS.G_OPR_NONE) THEN
8983            FND_MESSAGE.SET_NAME('ONT','OE_OI_OPERATION_CODE');
8984            OE_MSG_PUB.Add;
8985            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8986         END IF;
8987 
8988         IF l_line_rec.operation = oe_globals.g_opr_update
8989            AND l_line_rec.split_action_code = 'SPLIT' THEN
8990            l_call_split := TRUE;
8991         END IF;
8992 
8993         -- START: CHECK IF ALL LINES BELONG TO THE SAME ORDER
8994 
8995         -- Retrieve the header ID, either from the header record
8996 	   -- or from the first line
8997 	   IF (I = l_line_tbl.FIRST) THEN
8998           IF (l_header_rec.header_id IS NOT NULL AND
8999             l_header_rec.header_id <> FND_API.G_MISS_NUM) THEN
9000 		  l_header_id := l_header_rec.header_id;
9001           ELSIF (l_line_rec.header_id IS NOT NULL AND
9002             l_line_rec.header_id <> FND_API.G_MISS_NUM) THEN
9003 		  l_header_id := l_line_tbl(I).header_id;
9004 	     END IF;
9005 	   END IF;
9006 
9007         IF l_line_rec.operation <> OE_GLOBALS.G_OPR_CREATE
9008         AND (l_line_rec.header_id IS NULL OR
9009             l_line_rec.header_id = FND_API.G_MISS_NUM)
9010         THEN
9011           IF (l_header_id IS NOT NULL AND
9012               l_header_id <> FND_API.G_MISS_NUM) THEN
9013 		    l_line_tbl(I).header_id := l_header_id;
9014 	     ELSE
9015 	         oe_line_util.query_header
9016 				   (p_line_id => l_line_rec.line_id,
9017 			         x_header_id => l_header_id);
9018               l_line_tbl(I).header_id := l_header_id;
9019 	     END IF;
9020         END IF;
9021 
9022         -- Copy the parent ID (header ID), if not passed, on
9023 	   -- the record for CREATE operations
9024         IF l_line_rec.operation = OE_GLOBALS.G_OPR_CREATE
9025 	   THEN
9026 
9027           IF  (l_line_rec.header_id IS NULL OR
9028             l_line_rec.header_id = FND_API.G_MISS_NUM)
9029           THEN
9030             --  Copy parent_id.
9031             l_line_tbl(I).header_id := l_header_id;
9032 	     END IF;
9033 
9034         END IF;
9035 
9036         -- Raise error if the header ID for the line is different
9037 	   -- from header ID on the header record or other lines
9038         IF (l_header_id IS NOT NULL AND
9039             l_header_id <> FND_API.G_MISS_NUM) THEN
9040             IF l_line_tbl(I).header_id <> l_header_id THEN
9041                 fnd_message.set_name('ONT', 'OE_HEADER_MISSING');
9042                 oe_msg_pub.add;
9043                 RAISE FND_API.G_EXC_ERROR;
9044 	       END IF;
9045         END IF;
9046 
9047         -- END: CHECK IF ALL LINES BELONG TO THE SAME ORDER
9048 
9049 
9050 	   I := l_line_tbl.NEXT(I);
9051 
9052     END LOOP;
9053 
9054 
9055     -- Pre Split Process
9056     IF l_call_split THEN
9057       OE_Split_Util.Check_Split_Course
9058 	 ( p_x_line_tbl => l_line_tbl,
9059 	   p_x_line_adj_tbl => l_line_adj_tbl,
9060 	   p_x_line_scredit_tbl => l_line_scredit_tbl
9061 	  );
9062     END IF;
9063 
9064     --  Lines
9065 
9066     IF l_line_tbl.COUNT > 0 THEN
9067 
9068     IF l_debug_level  > 0 THEN
9069         oe_debug_pub.add(  'BEFORE LINES PROCESSING' , 2 ) ;
9070     END IF;
9071     Lines
9072     (   p_validation_level            => p_validation_level
9073     ,   p_control_rec                 => p_control_rec
9074     ,   p_x_line_tbl                  => l_line_tbl
9075     ,   p_x_old_line_tbl              => l_old_line_tbl
9076     ,   x_return_status               => l_return_status
9077     );
9078     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9079        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9080     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9081 	 IF p_control_rec.process_partial THEN
9082 	    x_return_status := FND_API.G_RET_STS_ERROR;
9083       ELSE
9084          RAISE FND_API.G_EXC_ERROR;
9085       END IF;
9086     END IF;
9087     IF l_debug_level  > 0 THEN
9088         oe_debug_pub.add(  'AFTER LINES PROCESSING' , 2 ) ;
9089     END IF;
9090 
9091     END IF;
9092 
9093     --  Set Header/Line_id on Line Sc and Line Pr Adj tables using the line index.
9094     --  We do this so that Lines and its children can be inserted in one call.
9095 
9096 /*        IF l_line_tbl.COUNT > 0 THEN
9097 
9098                  IF l_Line_Scredit_tbl.COUNT > 0 THEN
9099 
9100                     oe_debug_pub.add('Setting Header/Line Ids on Line SC table', 2);
9101 
9102                     FOR k in l_Line_Scredit_tbl.first .. l_line_Scredit_tbl.last LOOP
9103 
9104                        -- oe_debug_pub.add('Processing Line SC Record ' ||TO_CHAR(k), 2);
9105 
9106                        IF  (l_line_Scredit_tbl(k).line_index <> FND_API.G_MISS_NUM)
9107                            AND (l_line_Scredit_tbl(k).line_index  IS NOT NULL) THEN
9108 
9109                            l_line_index := l_line_Scredit_tbl(k).line_index;
9110 
9111                            IF l_line_tbl.EXISTS(l_line_index) THEN
9112 
9113                               IF (l_line_Scredit_tbl(k).line_id = FND_API.G_MISS_NUM)
9114                                   OR (l_line_Scredit_tbl(k).line_id IS NULL) THEN
9115 
9116                                   l_line_Scredit_tbl(k).line_id := l_line_tbl(l_line_index).line_id;
9117 
9118                               END IF; -- Line Id on Child is missing or is null
9119 
9120 
9121                               IF (l_line_Scredit_tbl(k).header_id = FND_API.G_MISS_NUM)
9122                                   OR (l_line_Scredit_tbl(k).header_id IS NULL) THEN
9123 
9124                                   l_line_Scredit_tbl(k).header_id := l_line_tbl(l_line_index).header_id;
9125 
9126                               END IF; -- Header Id on Child is missing or is null
9127 
9128 
9129                            ELSE -- Invalid Index
9130 
9131                               oe_debug_pub.add('Invalid Line Index '
9132                                                 ||TO_CHAR(l_line_index)
9133                                                 ||' on Line Sales Credits', 2);
9134                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9135 
9136                            END IF;  -- If Valid Line Index
9137                         END IF; -- Line Index is not null and not missing
9138 
9139                     END LOOP;
9140                   END IF; -- If Child table has rows
9141 
9142 
9143                  IF l_Line_Adj_tbl.COUNT > 0 THEN
9144 
9145                     oe_debug_pub.add('Setting Header/Line Ids on Line Adj  table', 2);
9146 
9147                     FOR k in l_Line_Adj_tbl.first .. l_line_Adj_tbl.last LOOP
9148 
9149                        -- oe_debug_pub.add('Processing Line Adj Record ' ||TO_CHAR(k), 2);
9150 
9151                        IF  (l_line_Adj_tbl(k).line_index <> FND_API.G_MISS_NUM)
9152                            AND (l_line_Adj_tbl(k).line_index  IS NOT NULL) THEN
9153 
9154                            l_line_index := l_line_Adj_tbl(k).line_index;
9155                            oe_debug_pub.add('Line Index is '||TO_CHAR(l_line_index), 2);
9156 
9157                            IF l_line_tbl.EXISTS(l_line_index) THEN
9158 
9159                               IF (l_line_Adj_tbl(k).line_id = FND_API.G_MISS_NUM)
9160                                   OR (l_line_Adj_tbl(k).line_id IS NULL) THEN
9161 
9162                                   l_line_Adj_tbl(k).line_id := l_line_tbl(l_line_index).line_id;
9163 
9164                               END IF; -- Line Id on Child is missing or is null
9165 
9166                               IF (l_line_Adj_tbl(k).Header_id = FND_API.G_MISS_NUM)
9167                                   OR (l_line_Adj_tbl(k).Header_id IS NULL) THEN
9168 
9169                                   l_line_Adj_tbl(k).Header_id := l_line_tbl(l_line_index).Header_id;
9170 
9171                               END IF; -- Header Id on Child is missing or is null
9172 
9173                            ELSE -- Invalid Index
9174 
9175                               oe_debug_pub.add('Invalid Line Index '
9176                                                 ||TO_CHAR(l_line_index)
9177                                                 ||'on Line Price Adjustments', 2);
9178                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9179 
9180                            END IF;  -- If Valid Line Index
9181                         END IF; -- Line Index is not null and not missing
9182 
9183                     END LOOP;
9184                   END IF; -- If Child table has rows
9185          END IF; -- If Line Table has rows
9186 */
9187 
9188 
9189 --    FOR I IN 1..l_Line_Scredit_tbl.COUNT LOOP
9190 
9191     I := l_Line_Scredit_tbl.FIRST;
9192     WHILE I IS NOT NULL LOOP
9193 
9194         IF l_debug_level  > 0 THEN
9195             oe_debug_pub.add(  'SETTING HEADER/LINE IDS ON LINE SC TABLE' ) ;
9196         END IF;
9197         l_Line_Scredit_rec := l_Line_Scredit_tbl(I);
9198 
9199         IF l_Line_Scredit_rec.operation = OE_GLOBALS.G_OPR_CREATE
9200         AND (l_Line_Scredit_rec.line_id IS NULL OR
9201             l_Line_Scredit_rec.line_id = FND_API.G_MISS_NUM)
9202         THEN
9203             IF l_debug_level  > 0 THEN
9204                 oe_debug_pub.add(  'SETTING LINE IDS ON LINE SC TABLE' , 2 ) ;
9205             END IF;
9206 
9207             --  Check If parent exists.
9208 
9209             IF l_line_tbl.EXISTS(l_Line_Scredit_rec.line_index) THEN
9210 
9211                 --  Copy parent_id.
9212 
9213                 l_Line_Scredit_tbl(I).line_id := l_line_tbl(l_Line_Scredit_rec.line_index).line_id;
9214                 l_Line_Scredit_tbl(I).header_id := l_line_tbl(l_Line_Scredit_rec.line_index).header_id;
9215 
9216                 -- Following procedure is called to fix bug 2482365
9217                 -- If sales credit info is passed by the user we will honor it.
9218                 -- Any sales credit record created for this line so far shall be deleted.
9219 
9220                 OE_Line_Scredit_Util.Delete_Row(p_line_id =>l_Line_Scredit_tbl(I).line_id);
9221           ELSE
9222 
9223                 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
9224                 THEN
9225                                                 IF l_debug_level  > 0 THEN
9226                                                     oe_debug_pub.add(  'INVALID LINE INDEX ' ||TO_CHAR ( L_LINE_INDEX ) ||'ON LINE SALES CREDITS' , 2 ) ;
9227                                                 END IF;
9228                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9229                     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
9230                     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Line_Scredit');
9231                     FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
9232                     FND_MESSAGE.SET_TOKEN('PARENT_INDEX',l_Line_Scredit_rec.line_index);
9233                     OE_MSG_PUB.Add;
9234 
9235                 END IF;
9236             END IF;
9237        END IF;
9238 
9239        I := l_Line_Scredit_tbl.NEXT(I);
9240     END LOOP;
9241 
9242 
9243 --    FOR I IN 1..l_Line_Adj_tbl.COUNT LOOP
9244 
9245     I := l_Line_Adj_tbl.FIRST;
9246     WHILE I IS NOT NULL LOOP
9247 
9248         IF l_debug_level  > 0 THEN
9249             oe_debug_pub.add(  'SETTING HEADER/LINE IDS ON LINE ADJ TABLE' , 2 ) ;
9250         END IF;
9251         l_Line_Adj_rec := l_Line_Adj_tbl(I);
9252 
9253         IF l_Line_Adj_rec.operation = OE_GLOBALS.G_OPR_CREATE
9254         AND (l_Line_Adj_rec.line_id IS NULL OR
9255             l_Line_Adj_rec.line_id = FND_API.G_MISS_NUM)
9256         THEN
9257 
9258             IF l_debug_level  > 0 THEN
9259                 oe_debug_pub.add(  'SETTING LINE IDS ON LINE ADJ TABLE' , 2 ) ;
9260             END IF;
9261             --  Check If parent exists.
9262 
9263             IF l_Line_Adj_rec.line_index <> fnd_api.g_miss_num and
9264 			l_line_tbl.EXISTS(l_Line_Adj_rec.line_index) THEN
9265 
9266                 --  Copy parent_id.
9267 
9268                 l_Line_Adj_tbl(I).line_id := l_line_tbl(l_Line_Adj_rec.line_index).line_id;
9269                 l_Line_Adj_tbl(I).header_id := l_line_tbl(l_Line_Adj_rec.line_index).header_id;
9270 
9271             ELSIF l_Line_Adj_tbl(I).header_id is not null and
9272 				l_Line_Adj_tbl(I).header_id <> FND_API.G_MISS_NUM Then
9273 			-- Treat the adjustment record as a header_adjustment record
9274 			IF l_debug_level  > 0 THEN
9275 			    oe_debug_pub.add(  'TREATING THE RECORD AS HEADER_ADJUSTMENT' ) ;
9276 			END IF;
9277 		  ELSE
9278 
9279                 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
9280                 THEN
9281                                                 IF l_debug_level  > 0 THEN
9282                                                     oe_debug_pub.add(  'INVALID LINE INDEX ' ||TO_CHAR ( L_LINE_INDEX ) ||'ON PRICE ADJUSTMENTS' , 2 ) ;
9283                                                 END IF;
9284                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9285 
9286                     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
9287                     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Line_Adj');
9288                     FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
9289                     FND_MESSAGE.SET_TOKEN('PARENT_INDEX',l_Line_Adj_rec.line_index);
9290                     OE_MSG_PUB.Add;
9291 
9292                 END IF;
9293             END IF;
9294         END IF;
9295 
9296         I := l_Line_Adj_tbl.NEXT(I);
9297     END LOOP;
9298 
9299     --  Perform line group requests.
9300 
9301     IF (p_control_rec.process AND
9302     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
9303         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
9304         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_LINE)
9305     THEN
9306             IF l_debug_level  > 0 THEN
9307                 oe_debug_pub.add(  'PROCESS LINE REQUESTS' ) ;
9308             END IF;
9309 
9310        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
9311           (p_entity_code   => OE_GLOBALS.G_ENTITY_LINE
9312           ,p_delete        => FND_API.G_TRUE
9313           ,x_return_status => l_return_status
9314           );
9315        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9316           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9317        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9318           RAISE FND_API.G_EXC_ERROR;
9319        END IF;
9320 
9321     END IF;
9322 
9323 
9324     -------------------------------------------------------
9325     -- Process Lines Adjustments
9326     -------------------------------------------------------
9327 
9328     IF l_Line_Adj_tbl.COUNT > 0 THEN
9329 
9330     --  Line_Adjs
9331 
9332     oe_order_adj_pvt.Line_Adjs
9333     (   p_validation_level            => p_validation_level
9334     ,   p_control_rec                 => p_control_rec
9335     ,   p_x_Line_Adj_tbl              => l_Line_Adj_tbl
9336     ,   p_x_old_Line_Adj_tbl          => l_old_Line_Adj_tbl
9337     );
9338 
9339     END IF;
9340 
9341     --  Perform Line_Adj group requests.
9342 
9343     IF (p_control_rec.process AND
9344     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
9345         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
9346         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_LINE_ADJ)
9347     THEN
9348 
9349        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
9350           (p_entity_code   => OE_GLOBALS.G_ENTITY_LINE_ADJ
9351           ,p_delete        => FND_API.G_TRUE
9352           ,x_return_status => l_return_status
9353           );
9354        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9355             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9356        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9357             RAISE FND_API.G_EXC_ERROR;
9358        END IF;
9359 
9360     END IF;
9361 
9362     -------------------------------------------------------
9363     -- Process Line Sales Credits
9364     -------------------------------------------------------
9365 
9366     --  Line_Scredits
9367 
9368     IF l_Line_Scredit_tbl.COUNT > 0 THEN
9369 
9370       Line_Scredits
9371       (   p_validation_level            => p_validation_level
9372       ,   p_control_rec                 => p_control_rec
9373       ,   p_x_Line_Scredit_tbl          => l_Line_Scredit_tbl
9374       ,   p_x_old_Line_Scredit_tbl      => l_old_Line_Scredit_tbl
9375       ,   x_return_status               => l_return_status
9376       );
9377      IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9378        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9379      ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9380 	  IF p_control_rec.process_partial THEN
9381 	     x_return_status := FND_API.G_RET_STS_ERROR;
9382        ELSE
9383           RAISE FND_API.G_EXC_ERROR;
9384        END IF;
9385      END IF;
9386 
9387     END IF;
9388 
9389     --  Perform Line_Scredit group requests.
9390 
9391     IF (p_control_rec.process AND
9392     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
9393         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
9394         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_LINE_SCREDIT)
9395     THEN
9396 
9397        IF l_debug_level  > 0 THEN
9398            oe_debug_pub.add(  'PROCESSING DELAYED REQUESTS FOR LINES' , 2 ) ;
9399        END IF;
9400 
9401        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
9402           (p_entity_code   => OE_GLOBALS.G_ENTITY_Line_Scredit
9403           ,p_delete        => FND_API.G_TRUE
9404           ,x_return_status => l_return_status
9405           );
9406 
9407        IF l_debug_level  > 0 THEN
9408            oe_debug_pub.add(  'PROCESSED DELAYED REQUESTS FOR LINES' , 2 ) ;
9409        END IF;
9410 
9411        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9412                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9413        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9414                  RAISE FND_API.G_EXC_ERROR;
9415        END IF;
9416 
9417     END IF;
9418 
9419 
9420     -------------------------------------------------------
9421     -- Process Lot Serials
9422     -------------------------------------------------------
9423 
9424     IF l_Lot_Serial_tbl.COUNT > 0 THEN
9425 
9426     --  Load parent key if missing and operation is create.
9427 
9428 --    FOR I IN 1..l_Lot_Serial_tbl.COUNT LOOP
9429 
9430     I := l_Lot_Serial_tbl.FIRST;
9431     WHILE I IS NOT NULL LOOP
9432 
9433         l_Lot_Serial_rec := l_Lot_Serial_tbl(I);
9434 
9435         IF l_Lot_Serial_rec.operation = OE_GLOBALS.G_OPR_CREATE
9436         AND (l_Lot_Serial_rec.line_id IS NULL OR
9437             l_Lot_Serial_rec.line_id = FND_API.G_MISS_NUM)
9438         THEN
9439 
9440             --  Check If parent exists.
9441 
9442             IF l_line_tbl.EXISTS(l_Lot_Serial_rec.line_index) THEN
9443 
9444                 --  Copy parent_id.
9445 
9446                 l_Lot_Serial_tbl(I).line_id := l_line_tbl(l_Lot_Serial_rec.line_index).line_id;
9447 
9448             ELSE
9449 
9450                 IF oe_msg_pub.Check_Msg_Level(oe_msg_pub.G_MSG_LVL_ERROR)
9451                 THEN
9452 
9453                     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
9454                     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Lot_Serial');
9455                     FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
9456                     FND_MESSAGE.SET_TOKEN('PARENT_INDEX',l_Lot_Serial_rec.line_index);
9457                     oe_msg_pub.Add;
9458 
9459                 END IF;
9460             END IF;
9461             END IF;
9462         I := l_Lot_Serial_tbl.NEXT(I);
9463     END LOOP;
9464 
9465     --  Lot_Serials
9466 
9467     Lot_Serials
9468     (   p_validation_level            => p_validation_level
9469     ,   p_control_rec                 => p_control_rec
9470     ,   p_x_Lot_Serial_tbl            => l_Lot_Serial_tbl
9471     ,   p_x_old_Lot_Serial_tbl        => l_old_Lot_Serial_tbl
9472     ,   x_return_status               => l_return_status
9473     );
9474     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9475        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9476     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9477 	  IF p_control_rec.process_partial THEN
9478 	     x_return_status := FND_API.G_RET_STS_ERROR;
9479        ELSE
9480           RAISE FND_API.G_EXC_ERROR;
9481        END IF;
9482     END IF;
9483 
9484     END IF;
9485 
9486     --  Perform Lot_Serial group requests.
9487 
9488     IF (p_control_rec.process AND
9489     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
9490         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
9491         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_LOT_SERIAL)
9492     THEN
9493 
9494         NULL;
9495 
9496     END IF;
9497 
9498     -------------------------------------------------------
9499     -- Process Line Price Attributes
9500     -------------------------------------------------------
9501 
9502     -- Process line Price Attributes
9503 
9504     I := l_Line_Price_Att_tbl.FIRST;
9505     WHILE I IS NOT NULL LOOP
9506 
9507         IF l_debug_level  > 0 THEN
9508             oe_debug_pub.add(  'SETTING HEADER/LINE IDS ON LINE ATTRIBUTES TABLE' , 2 ) ;
9509         END IF;
9510         l_Line_Price_Att_rec := l_Line_Price_Att_tbl(I);
9511 
9512         IF l_Line_Price_Att_rec.operation = OE_GLOBALS.G_OPR_CREATE
9513         AND (l_Line_Price_Att_rec.line_id IS NULL OR
9514             l_Line_Price_Att_rec.line_id = FND_API.G_MISS_NUM)
9515         THEN
9516 
9517             IF l_debug_level  > 0 THEN
9518                 oe_debug_pub.add(  'SETTING LINE IDS ON LINE ATTRIB TABLE' , 2 ) ;
9519             END IF;
9520             --  Check If parent exists.
9521 
9522             IF l_line_tbl.EXISTS(l_Line_Price_Att_rec.line_index) THEN
9523 
9524                 --  Copy parent_id.
9525 
9526                 l_Line_Price_Att_tbl(I).line_id := l_line_tbl(l_Line_Price_Att_rec.line_index).line_id;
9527                 l_Line_Price_Att_tbl(I).header_id := l_line_tbl(l_Line_Price_Att_rec.line_index).header_id;
9528 
9529             ELSE
9530 
9531                 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
9532                 THEN
9533                                                 IF l_debug_level  > 0 THEN
9534                                                     oe_debug_pub.add(  'INVALID LINE INDEX ' ||TO_CHAR ( L_LINE_PRICE_ATT_REC.LINE_INDEX ) ||'ON PRICE ADJUSTMENTS' , 2 ) ;
9535                                                 END IF;
9536                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9537 
9538                     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
9539                     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Line_Price_Att');
9540                     FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
9541                     FND_MESSAGE.SET_TOKEN('PARENT_INDEX',l_Line_Price_Att_rec.line_index);
9542                     OE_MSG_PUB.Add;
9543 
9544                 END IF;
9545             END IF;
9546         END IF;
9547         I := l_Line_Price_Att_tbl.NEXT(I);
9548     END LOOP;
9549 
9550     --  Line_Attribs
9551 
9552     IF l_Line_Price_Att_tbl.COUNT > 0 THEN
9553 
9554     oe_order_adj_pvt.Line_Price_Atts
9555     (   p_validation_level            => p_validation_level
9556     ,   p_control_rec                 => p_control_rec
9557     ,   p_x_Line_Price_Att_tbl        => l_Line_Price_Att_tbl
9558     ,   p_x_old_Line_Price_Att_tbl    => l_old_Line_Price_Att_tbl
9559     );
9560 
9561     END IF;
9562 
9563     --  Perform Line_Price_Att group requests.
9564 
9565     IF (p_control_rec.process AND
9566     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
9567         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
9568         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_Line_Price_Att)
9569     THEN
9570 
9571        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
9572           (p_entity_code   => OE_GLOBALS.G_ENTITY_Line_Price_Att
9573           ,p_delete        => FND_API.G_TRUE
9574           ,x_return_status => l_return_status
9575           );
9576        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9577                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9578        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9579                  RAISE FND_API.G_EXC_ERROR;
9580        END IF;
9581 
9582     END IF;
9583 
9584 
9585     -------------------------------------------------------
9586     -- Process Line Adjustment Attributes
9587     -------------------------------------------------------
9588 
9589     -- Process line Adj Attributes
9590 
9591     I := l_Line_Adj_Att_tbl.FIRST;
9592     WHILE I IS NOT NULL LOOP
9593 
9594         IF l_debug_level  > 0 THEN
9595             oe_debug_pub.add(  'SETTING PRICE_ADJUSTMENT_ID ON LINE ADJ ATTRIB TABLE' , 2 ) ;
9596         END IF;
9597         l_Line_Adj_Att_rec := l_Line_Adj_Att_tbl(I);
9598 
9599         IF l_Line_Adj_Att_rec.operation = OE_GLOBALS.G_OPR_CREATE
9600         AND (l_Line_Adj_Att_rec.price_adjustment_id IS NULL OR
9601             l_Line_Adj_Att_rec.price_adjustment_id = FND_API.G_MISS_NUM)
9602         THEN
9603 
9604             IF l_debug_level  > 0 THEN
9605                 oe_debug_pub.add(  'SETTING ADJ IDS ON LINE ADJ ATTRIB TABLE' , 2 ) ;
9606             END IF;
9607             --  Check If parent exists.
9608 
9609             IF l_line_Adj_tbl.EXISTS(l_Line_Adj_Att_rec.Adj_index) THEN
9610 
9611                 --  Copy parent_id.
9612 
9613                 l_Line_Adj_Att_tbl(I).price_adjustment_id := l_line_Adj_tbl(l_Line_Adj_Att_rec.Adj_index).price_adjustment_id;
9614 
9615             ELSE
9616 
9617                 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
9618                 THEN
9619                                                 IF l_debug_level  > 0 THEN
9620                                                     oe_debug_pub.add(  'INVALID ADJ INDEX ' ||TO_CHAR ( L_LINE_ADJ_ATT_REC.ADJ_INDEX ) ||'ON ADJ ATTRIBS' , 2 ) ;
9621                                                 END IF;
9622                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9623 
9624                     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
9625                     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Line_Adj_Att');
9626                     FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
9627                     FND_MESSAGE.SET_TOKEN('PARENT_INDEX',l_Line_Adj_Att_rec.Adj_index);
9628                     OE_MSG_PUB.Add;
9629 
9630                 END IF;
9631             END IF;
9632         END IF;
9633         I := l_Line_Adj_Att_tbl.NEXT(I);
9634     END LOOP;
9635 
9636     --  Line_Attribs
9637 
9638     IF l_Line_Adj_Att_tbl.COUNT > 0 THEN
9639 
9640     oe_order_adj_pvt.Line_Adj_Atts
9641     (   p_validation_level            => p_validation_level
9642     ,   p_control_rec                 => p_control_rec
9643     ,   p_x_Line_Adj_Att_tbl          => l_Line_Adj_Att_tbl
9644     ,   p_x_old_Line_Adj_Att_tbl      => l_old_Line_Adj_Att_tbl
9645     );
9646 
9647     END IF;
9648 
9649     --  Perform Line_Adj_Att group requests.
9650 /*
9651 
9652     IF (p_control_rec.process AND
9653     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
9654         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
9655         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_Line_Adj_Att)
9656     THEN
9657 
9658        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
9659           (p_entity_code   => OE_GLOBALS.G_ENTITY_Line_Adj_Att
9660           ,p_delete        => FND_API.G_TRUE
9661           ,x_return_status => l_return_status
9662           );
9663        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9664                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9665        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9666                  RAISE FND_API.G_EXC_ERROR;
9667        END IF;
9668 
9669     END IF;
9670 */
9671 
9672     -------------------------------------------------------
9673     -- Process Line Adjustment Associations
9674     -------------------------------------------------------
9675 
9676     -- Process line Adj Associations
9677 
9678     I := l_Line_Adj_Assoc_tbl.FIRST;
9679     WHILE I IS NOT NULL LOOP
9680 
9681         IF l_debug_level  > 0 THEN
9682             oe_debug_pub.add(  'SETTING PRICE_ADJUSTMENT_ID ON LINE ADJ ASSOCS TABLE' , 2 ) ;
9683         END IF;
9684         l_Line_Adj_Assoc_rec := l_Line_Adj_Assoc_tbl(I);
9685 
9686         IF l_Line_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_CREATE
9687         AND (l_Line_Adj_Assoc_rec.price_adjustment_id IS NULL OR
9688             l_Line_Adj_Assoc_rec.price_adjustment_id = FND_API.G_MISS_NUM)
9689         THEN
9690 
9691             IF l_debug_level  > 0 THEN
9692                 oe_debug_pub.add(  'SETTING ADJ IDS ON LINE ADJ ASSOCS TABLE' , 2 ) ;
9693             END IF;
9694             --  Check If parent exists.
9695 
9696             IF l_line_Adj_tbl.EXISTS(l_Line_Adj_Assoc_rec.Adj_index) THEN
9697 
9698                 --  Copy parent_id.
9699 
9700                 l_Line_Adj_Assoc_tbl(I).price_adjustment_id := l_line_Adj_tbl(l_Line_Adj_Assoc_rec.Adj_index).price_adjustment_id;
9701 
9702             ELSE
9703 
9704                 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
9705                 THEN
9706                                                 IF l_debug_level  > 0 THEN
9707                                                     oe_debug_pub.add(  'INVALID ADJ INDEX ' ||TO_CHAR ( L_LINE_ADJ_ASSOC_REC.ADJ_INDEX ) ||'ON ADJ ASSOCS' , 2 ) ;
9708                                                 END IF;
9709                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9710 
9711                     fnd_message.set_name('ONT','OE_API_INV_PARENT_INDEX');
9712                     FND_MESSAGE.SET_TOKEN('ENTITY_NAME','Line_Adj_Assoc');
9713                     FND_MESSAGE.SET_TOKEN('ENTITY_INDEX',I);
9714                     FND_MESSAGE.SET_TOKEN('PARENT_INDEX',l_Line_Adj_Assoc_rec.Adj_index);
9715                     OE_MSG_PUB.Add;
9716 
9717                 END IF;
9718             END IF;
9719         END IF;
9720 
9721         IF l_Line_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_CREATE
9722         AND (l_Line_Adj_Assoc_rec.Line_id IS NULL OR
9723             l_Line_Adj_Assoc_rec.Line_id = FND_API.G_MISS_NUM)
9724         THEN
9725 
9726             IF l_debug_level  > 0 THEN
9727                 oe_debug_pub.add(  'SETTING LINE IDS ON LINE ADJ ASSOCS TABLE' , 2 ) ;
9728             END IF;
9729             --  Check If parent exists.
9730 
9731             IF l_line_tbl.EXISTS(l_Line_Adj_Assoc_rec.Line_Index) THEN
9732 
9733                 --  Copy parent_id.
9734 
9735                 l_Line_Adj_Assoc_tbl(I).Line_Id := l_line_tbl(l_Line_Adj_Assoc_rec.Line_index).Line_id;
9736             END IF;
9737         END IF;
9738 
9739         IF l_Line_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_CREATE
9740         AND (l_Line_Adj_Assoc_rec.rltd_Price_Adj_Id IS NULL OR
9741             l_Line_Adj_Assoc_rec.rltd_Price_Adj_Id = FND_API.G_MISS_NUM)
9742         THEN
9743 
9744 		  IF l_Line_Adj_Tbl.exists(l_Line_Adj_Assoc_Rec.Rltd_Adj_Index) Then
9745             --  Copy parent_id.
9746 
9747               l_Line_Adj_Assoc_tbl(I).rltd_Price_Adj_Id :=
9748 				l_Line_Adj_Tbl(l_Line_Adj_Assoc_Rec.Rltd_Adj_Index).Price_adjustment_id;
9749             END IF;
9750 
9751         END IF;
9752         I := l_Line_Adj_Assoc_tbl.NEXT(I);
9753     END LOOP;
9754 
9755     --  Line_Attribs
9756 
9757     IF l_Line_Adj_Assoc_tbl.COUNT > 0 THEN
9758 
9759     oe_order_adj_pvt.Line_Adj_Assocs
9760     (   p_validation_level            => p_validation_level
9761     ,   p_control_rec                 => p_control_rec
9762     ,   p_x_Line_Adj_Assoc_tbl        => l_Line_Adj_Assoc_tbl
9763     ,   p_x_old_Line_Adj_Assoc_tbl    => l_old_Line_Adj_Assoc_tbl
9764     );
9765 
9766     END IF;
9767 
9768     --  Perform Line_Adj_Assoc group requests.
9769 /*
9770 
9771     IF (p_control_rec.process AND
9772     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
9773         (p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL OR
9774         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_Line_Adj_Assoc)
9775     THEN
9776 
9777        OE_DELAYED_REQUESTS_PVT.Process_Request_for_Entity
9778           (p_entity_code   => OE_GLOBALS.G_ENTITY_Line_Adj_Assoc
9779           ,p_delete        => FND_API.G_TRUE
9780           ,x_return_status => l_return_status
9781           );
9782        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9783                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9784        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9785                  RAISE FND_API.G_EXC_ERROR;
9786        END IF;
9787 
9788     END IF;
9789 */
9790 
9791     -- Step 6. Perform Delayed Requests
9792     --  Set entity_id on request table using the line index.
9793 /*
9794     IF l_request_tbl.COUNT > 0 THEN
9795 
9796        oe_debug_pub.add('Setting Header/Line Ids on Line Adj  table', 2);
9797 
9798        FOR k in l_request_tbl.first .. l_request_tbl.last LOOP
9799 
9800           -- oe_debug_pub.add('Processing Line Requests ' ||TO_CHAR(k), 2);
9801           IF  (l_request_tbl(k).entity_code IS NULL OR
9802 				l_request_tbl(k).entity_code = Oe_Globals.G_ENTITY_HEADER) THEN
9803 
9804              IF  (l_request_tbl(k).entity_id = FND_API.G_MISS_NUM
9805                    OR   l_request_tbl(k).entity_id is null ) THEN
9806                IF l_header_rec.header_id IS NULL OR
9807                   l_header_rec.header_id = FND_API.G_MISS_NUM THEN
9808                 FND_MESSAGE.SET_NAME('ONT','OE_HEADER_MISSING');
9809                 OE_MSG_PUB.Add;
9810                 RAISE FND_API.G_EXC_ERROR;
9811                ELSE
9812 
9813                 l_request_tbl(k).entity_id := l_header_rec.header_id;
9814 
9815                END IF;
9816              END IF;
9817           ELSIF  (l_request_tbl(k).entity_code = Oe_Globals.G_ENTITY_LINE) THEN
9818 
9819              IF  (to_number(l_request_tbl(k).param1) <> FND_API.G_MISS_NUM)
9820                     AND (l_request_tbl(k).param1 IS NOT NULL) THEN
9821 
9822                 l_line_index := to_number(l_request_tbl(k).param1)  ;
9823                 oe_debug_pub.add('Line Index is '||TO_CHAR(l_line_index), 2);
9824 
9825                 IF l_line_tbl.EXISTS(l_line_index) THEN
9826 
9827                    IF (l_request_tbl(k).entity_id = FND_API.G_MISS_NUM)
9828                                   OR (l_request_tbl(k).entity_id IS NULL) THEN
9829 
9830                       l_request_tbl(k).entity_id := l_line_tbl(l_line_index).line_id;
9831 
9832                    END IF; -- Line Id on Child is missing or is null
9833 
9834                 ELSE -- Invalid Index
9835 
9836                     oe_debug_pub.add('Invalid Line Index '
9837                                       ||TO_CHAR(l_line_index)
9838                                       ||'on Action Request', 2);
9839                     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9840                 END IF;  -- If Valid Line Index
9841              END IF; -- Line Index is not null and not missing
9842           END IF;
9843        END LOOP;
9844     END IF; -- If Child table has rows
9845 */
9846 -------------------------------------------------------------------------------
9847 
9848 --    FOR I IN 1..l_request_tbl.COUNT LOOP
9849 
9850     I := l_request_tbl.FIRST;
9851     WHILE I IS NOT NULL LOOP
9852 
9853         IF l_debug_level  > 0 THEN
9854             oe_debug_pub.add(  'SETTING HEADER/LINE IDS ON REQUEST TABLE' , 2 ) ;
9855         END IF;
9856 
9857         IF (l_request_tbl(I).entity_code = OE_GLOBALS.G_ENTITY_HEADER) THEN
9858 
9859             IF (l_request_tbl(I).entity_id IS NULL OR
9860                 l_request_tbl(I).entity_id = FND_API.G_MISS_NUM)
9861             THEN
9862                 IF l_debug_level  > 0 THEN
9863                     oe_debug_pub.add(  'SETTING HEADER IDS ON REQUEST TABLE FOR HEADER ENTITY' , 2 ) ;
9864                 END IF;
9865               IF l_header_rec.header_id IS NULL OR
9866                  l_header_rec.header_id = FND_API.G_MISS_NUM THEN
9867                 FND_MESSAGE.SET_NAME('ONT','OE_HEADER_MISSING');
9868                 OE_MSG_PUB.Add;
9869                 RAISE FND_API.G_EXC_ERROR;
9870               ELSE
9871                 l_request_tbl(I).entity_id := l_header_rec.header_id;
9872               END IF;
9873             END IF;
9874 
9875         ELSIF (l_request_tbl(I).entity_code = OE_GLOBALS.G_ENTITY_LINE) THEN
9876 
9877             IF (l_request_tbl(I).entity_id IS NULL OR
9878                 l_request_tbl(I).entity_id = FND_API.G_MISS_NUM)
9879             THEN
9880                 IF l_debug_level  > 0 THEN
9881                     oe_debug_pub.add(  'SETTING LINE IDS ON REQUEST TABLE FOR LINE ENTITY' , 2 ) ;
9882                 END IF;
9883             --  Check If entity record exists.
9884 
9885                IF l_line_tbl.EXISTS(l_request_tbl(I).entity_index) THEN
9886 
9887                 --  Copy entity_id.
9888 
9889                   l_request_tbl(I).entity_id := l_line_tbl(l_request_tbl(I).entity_index).line_id;
9890 
9891                ELSE
9892 
9893                   IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
9894                   THEN
9895                                                 IF l_debug_level  > 0 THEN
9896                                                     oe_debug_pub.add(  'INVALID ENTITY INDEX ' ||TO_CHAR ( L_REQUEST_TBL ( I ) .ENTITY_INDEX ) ||'ON REQUEST TABLE FOR LINE ENTITY' , 2 ) ;
9897                                                 END IF;
9898                               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9899                    END IF;
9900                END IF;
9901           END IF;
9902       END IF;
9903 	 I := l_request_tbl.NEXT(I);
9904     END LOOP;
9905 
9906 -------------------------------------------------------------------------------
9907 
9908     --  Step 7. Perform Object group logic
9909 
9910     --  Perform Delayed Requests for all the the entities
9911     IF l_debug_level  > 0 THEN
9912         oe_debug_pub.add(  'OEXVORDB: BEFORE CALLING PROCESS_DELAYED_REQUESTS' , 2 ) ;
9913     END IF;
9914     IF (p_control_rec.process AND
9915     OE_GLOBALS.G_RECURSION_MODE <> 'Y') AND
9916        p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL
9917     THEN
9918 
9919        OE_DELAYED_REQUESTS_PVT.Process_Delayed_Requests(
9920           x_return_status => l_return_status
9921           );
9922                     IF l_debug_level  > 0 THEN
9923                         oe_debug_pub.add(  'OEXVORDB: COMPLETED PROCESS_DELAYED_REQUESTS ' || ' WITH RETURN STATUS' || L_RETURN_STATUS , 2 ) ;
9924                     END IF;
9925        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9926                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9927        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9928                  RAISE FND_API.G_EXC_ERROR;
9929        END IF;
9930 
9931     END IF;
9932 
9933     -- Only do non-WF requests.
9934     IF p_x_action_request_tbl.COUNT > 0 THEN
9935 
9936     -- Perform NON-WF Action Requests
9937     OE_Delayed_Requests_PVT.Process_Order_Actions
9938            (p_validation_level	=> p_validation_level,
9939 	       p_x_request_tbl	=> l_request_tbl,
9940 	       p_process_WF_Requests => FALSE);
9941 
9942     END IF;
9943 
9944 
9945     -- Start flows for the Entity.
9946     IF (p_control_rec.process AND
9947         p_control_rec.process_entity = OE_GLOBALS.G_ENTITY_ALL AND
9948         OE_GLOBALS.G_RECURSION_MODE = 'N')
9949     THEN
9950         OE_ORDER_WF_UTIL.START_ALL_FLOWS;
9951         -- Process WF Action requests.
9952         IF p_x_action_request_tbl.COUNT > 0 THEN
9953 
9954           OE_Delayed_Requests_PVT.Process_Order_Actions
9955 
9956            (p_validation_level	=> p_validation_level,
9957 	       p_x_request_tbl	=> l_request_tbl,
9958 	       p_process_WF_Requests => TRUE);
9959 
9960         END IF;
9961 
9962     END IF;
9963 
9964 
9965     IF l_debug_level  > 0 THEN
9966         oe_debug_pub.add(  'OEXVORDB: AFTER PROCESS_ORDER_ACTIONS' , 2 ) ;
9967     END IF;
9968 
9969 
9970     --  Clear API cache.
9971 
9972     IF p_control_rec.clear_api_cache THEN
9973         NULL;
9974     END IF;
9975 
9976     --  Clear API request tbl.
9977 
9978     IF p_control_rec.clear_api_requests THEN
9979         NULL;
9980     END IF;
9981 
9982     -- Derive return status
9983 
9984     IF l_header_rec.return_status = FND_API.G_RET_STS_ERROR THEN
9985         x_return_status := FND_API.G_RET_STS_ERROR;
9986     END IF;
9987 
9988     -- Do not need to loop through header_scredits, lines
9989     -- line_scredits or lot_serials as the x_return_status is set
9990     -- based on the x_return_status returned by the entity procedures
9991 
9992 --    FOR I IN 1..l_Header_Adj_tbl.COUNT LOOP
9993     I := l_Header_Adj_tbl.FIRST;
9994     WHILE I IS NOT NULL LOOP
9995 
9996         IF l_Header_Adj_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
9997             x_return_status := FND_API.G_RET_STS_ERROR;
9998         END IF;
9999 
10000 	      I := l_Header_Adj_tbl.NEXT(I);
10001     END LOOP;
10002 
10003     I := l_Header_Price_Att_tbl.FIRST;
10004     WHILE I IS NOT NULL LOOP
10005 
10006         IF l_Header_Price_Att_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
10007             x_return_status := FND_API.G_RET_STS_ERROR;
10008         END IF;
10009 
10010 	      I := l_Header_Price_Att_tbl.NEXT(I);
10011     END LOOP;
10012 
10013     I := l_Header_Adj_Att_tbl.FIRST;
10014     WHILE I IS NOT NULL LOOP
10015 
10016         IF l_Header_Adj_Att_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
10017             x_return_status := FND_API.G_RET_STS_ERROR;
10018         END IF;
10019 
10020 	      I := l_Header_Adj_Att_tbl.NEXT(I);
10021     END LOOP;
10022 
10023     I := l_Header_Adj_Assoc_tbl.FIRST;
10024     WHILE I IS NOT NULL LOOP
10025 
10026         IF l_Header_Adj_Assoc_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
10027             x_return_status := FND_API.G_RET_STS_ERROR;
10028         END IF;
10029 
10030 	      I := l_Header_Adj_Assoc_tbl.NEXT(I);
10031     END LOOP;
10032 
10033 --    FOR I IN 1..l_Line_Adj_tbl.COUNT LOOP
10034 
10035     I := l_Line_Adj_tbl.FIRST;
10036     WHILE I IS NOT NULL LOOP
10037 
10038         IF l_Line_Adj_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
10039             x_return_status := FND_API.G_RET_STS_ERROR;
10040         END IF;
10041 
10042 		 I := l_Line_Adj_tbl.NEXT(I);
10043     END LOOP;
10044 
10045     I := l_Line_Price_Att_tbl.FIRST;
10046     WHILE I IS NOT NULL LOOP
10047 
10048         IF l_Line_Price_Att_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
10049             x_return_status := FND_API.G_RET_STS_ERROR;
10050         END IF;
10051 
10052 	      I := l_Line_Price_Att_tbl.NEXT(I);
10053     END LOOP;
10054 
10055     I := l_Line_Adj_Att_tbl.FIRST;
10056     WHILE I IS NOT NULL LOOP
10057 
10058         IF l_Line_Adj_Att_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
10059             x_return_status := FND_API.G_RET_STS_ERROR;
10060         END IF;
10061 
10062 	      I := l_Line_Adj_Att_tbl.NEXT(I);
10063     END LOOP;
10064 
10065     I := l_Line_Adj_Assoc_tbl.FIRST;
10066     WHILE I IS NOT NULL LOOP
10067 
10068         IF l_Line_Adj_Assoc_tbl(I).return_status = FND_API.G_RET_STS_ERROR THEN
10069             x_return_status := FND_API.G_RET_STS_ERROR;
10070         END IF;
10071 
10072 	      I := l_Line_Adj_Assoc_tbl.NEXT(I);
10073     END LOOP;
10074 
10075     IF l_debug_level  > 0 THEN
10076         oe_debug_pub.add(  'JPN: BEFORE CALLING NOTIFY , HEADER_ID IS: ' || L_HEADER_REC.HEADER_ID ) ;
10077     END IF;
10078 --  Calling Update Notice API - Provided by OC
10079 --  This API will notify OC about the changes happen in OM side for order
10080 
10081     /* Notification Project changes */
10082     /* Call Process_Requests_and_Notify to inform all subscribers */
10083 
10084  IF (OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110508') then
10085       /* Call Process Requests and notify */
10086           IF l_debug_level  > 0 THEN
10087               oe_debug_pub.add(  'CALLING PROCESS_REQUESTS_AND_NOTIFY FOR PACK H' ) ;
10088           END IF;
10089           Process_Requests_And_Notify(
10090                       p_process_requests => FALSE,
10091                       p_notify           => TRUE,
10092                       x_return_status    => l_return_status,
10093                       p_header_rec       => l_header_rec,
10094                       p_old_header_rec   => l_old_header_rec,
10095                       p_Header_Adj_tbl   => l_Header_Adj_tbl,
10096                       p_old_Header_Adj_tbl => l_old_Header_Adj_tbl,
10097                       p_Header_Scredit_tbl => l_header_Scredit_tbl,
10098                       p_old_Header_Scredit_tbl => l_old_Header_Scredit_tbl,
10099                       p_line_tbl          => l_line_tbl,
10100                       p_old_line_tbl      => l_old_line_tbl,
10101                       p_Line_Adj_tbl      => l_line_adj_tbl,
10102                       p_old_line_adj_tbl  => l_old_line_adj_tbl,
10103                       p_Line_Scredit_tbl  => l_Line_Scredit_tbl,
10104                       p_old_Line_Scredit_tbl   => l_old_line_Scredit_tbl,
10105                       p_Lot_Serial_tbl    => l_lot_Serial_tbl,
10106                       p_old_Lot_Serial_tbl => l_old_Lot_Serial_tbl);
10107 
10108                       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10109                          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10110                       ELSIF l_return_status  = FND_API.G_RET_STS_ERROR THEN
10111                          RAISE FND_API.G_EXC_ERROR;
10112                       END IF;
10113 
10114     ELSE
10115       /* Pre Pack H processsing */
10116 
10117        IF l_debug_level  > 0 THEN
10118            oe_debug_pub.add(  'CS BEFORE CALLING NOTIFY_OC API' , 1 ) ;
10119        END IF;
10120 
10121     IF x_return_status = FND_API.G_RET_STS_SUCCESS AND
10122 	   p_control_rec.write_to_db = TRUE
10123     AND oe_order_cache.g_header_rec.booked_flag = 'Y'
10124     THEN
10125       IF l_debug_level  > 0 THEN
10126           oe_debug_pub.add(  'CS CALLING NOTIFY_OC API' , 1 ) ;
10127       END IF;
10128 
10129     OE_SERVICE_UTIL.Notify_OC
10130     (   p_api_version_number                  =>  l_api_version_number
10131     ,   p_init_msg_list                       =>  l_init_msg_list
10132     ,   p_validation_level                    =>  l_validation_level
10133     ,   p_control_rec                         =>  p_control_rec
10134     ,   x_return_status                       =>  l_return_status
10135     ,   x_msg_count                           =>  x_msg_count
10136     ,   x_msg_data                            =>  x_msg_data
10137     ,   p_header_rec                          =>  l_header_rec
10138     ,   p_old_header_rec                      =>  l_old_header_rec
10139     ,   p_header_adj_tbl                      =>  l_header_adj_tbl
10140     ,   p_old_header_adj_tbl		           =>  l_old_header_adj_tbl
10141     ,   p_header_price_att_tbl                =>  l_header_price_att_tbl
10142     ,   p_old_header_price_att_tbl            =>  l_old_header_price_att_tbl
10143     ,   p_Header_Adj_Att_tbl                  =>  l_Header_Adj_Att_tbl
10144     ,   p_old_Header_Adj_Att_tbl              =>  l_old_Header_Adj_Att_tbl
10145     ,   p_Header_Adj_Assoc_tbl                =>  l_Header_Adj_Assoc_tbl
10146     ,   p_old_Header_Adj_Assoc_tbl            =>  l_old_Header_Adj_Assoc_tbl
10147     ,   p_Header_Scredit_tbl                  =>  l_Header_Scredit_tbl
10148     ,   p_old_Header_Scredit_tbl              =>  l_old_Header_Scredit_tbl
10149     ,   p_line_tbl                            =>  l_line_tbl
10150     ,   p_old_line_tbl                        =>  l_old_line_tbl
10151     ,   p_Line_Adj_tbl                        =>  l_Line_Adj_tbl
10152     ,   p_old_Line_Adj_tbl                    =>  l_old_Line_Adj_tbl
10153     ,   p_Line_Price_Att_tbl                  =>  l_Line_Price_Att_tbl
10154     ,   p_old_Line_Price_Att_tbl              =>  l_old_Line_Price_Att_tbl
10155     ,   p_Line_Adj_Att_tbl                    =>  l_Line_Adj_Att_tbl
10156     ,   p_old_Line_Adj_Att_tbl                =>  l_old_Line_Adj_Att_tbl
10157     ,   p_Line_Adj_Assoc_tbl                  =>  l_Line_Adj_Assoc_tbl
10158     ,   p_old_Line_Adj_Assoc_tbl              =>  l_old_Line_Adj_Assoc_tbl
10159     ,   p_Line_Scredit_tbl                    =>  l_Line_Scredit_tbl
10160     ,   p_old_Line_Scredit_tbl                =>  l_old_Line_Scredit_tbl
10161     ,   p_Lot_Serial_tbl                      =>  l_Lot_Serial_tbl
10162     ,   p_old_Lot_Serial_tbl                  =>  l_old_Lot_Serial_tbl
10163     ,   p_Lot_Serial_val_tbl                  =>  l_Lot_Serial_val_tbl
10164     ,   p_old_Lot_Serial_val_tbl              =>  l_old_Lot_Serial_val_tbl
10165     ,   p_action_request_tbl	                 =>  l_request_tbl
10166     );
10167 
10168 
10169        IF l_debug_level  > 0 THEN
10170            oe_debug_pub.add(  'AFTER NOTIFY_OC API' , 1 ) ;
10171        END IF;
10172 	  IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10173           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10174        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10175           RAISE FND_API.G_EXC_ERROR;
10176        END IF;
10177 
10178 
10179     END IF;
10180 
10181     IF l_debug_level  > 0 THEN
10182         oe_debug_pub.add(  'PROCESSING ACKS' , 1 ) ;
10183     END IF;
10184       -- Following check is commented to fix 2380911
10185     IF -- OE_Globals.G_RECURSION_MODE <> 'Y' AND
10186         x_return_status = FND_API.G_RET_STS_SUCCESS AND
10187 	   l_control_rec.write_to_db = TRUE
10188     THEN
10189       IF l_debug_level  > 0 THEN
10190           oe_debug_pub.add(  'CALLING ACKS API' , 1 ) ;
10191       END IF;
10192 
10193       If Oe_Code_Control.Code_Release_Level >= '110510' And
10194            l_header_rec.order_source_id in (0,2,6) And
10195            l_edi_ack_pfile = 'YES' Then
10196         OE_Acknowledgment_Pvt.Process_Acknowledgment
10197         (p_header_rec           => l_header_rec,
10198          p_line_tbl             => l_line_tbl,
10199          p_old_header_rec       => l_old_header_rec,
10200          p_old_line_tbl         => l_old_line_tbl,
10201          x_return_status        => l_return_status);
10202      Elsif l_edi_ack_pfile = 'NO'  And
10203          p_x_header_rec.order_source_id in (0,2,6,20) Then
10204       OE_Acknowledgment_Pvt.Process_Acknowledgment
10205      (p_api_version_number 		=> 1
10206      ,p_init_msg_list 		        => p_init_msg_list
10207 
10208      ,p_header_rec 			=> l_header_rec
10209      ,p_header_adj_tbl		        => l_header_adj_tbl
10210      ,p_header_Scredit_tbl		=> l_header_scredit_tbl
10211      ,p_line_tbl 			=> l_line_tbl
10212      ,p_line_adj_tbl			=> l_line_adj_tbl
10213      ,p_line_scredit_tbl		=> l_line_scredit_tbl
10214      ,p_lot_serial_tbl		        => l_lot_serial_tbl
10215      ,p_action_request_tbl 		=> l_request_tbl
10216 
10217      ,p_old_header_rec 		   	=> l_old_header_rec
10218      ,p_old_header_adj_tbl 		=> l_old_header_adj_tbl
10219      ,p_old_header_Scredit_tbl 	   	=> l_old_header_scredit_tbl
10220      ,p_old_line_tbl 		        => l_old_line_tbl
10221      ,p_old_line_adj_tbl 		=> l_old_line_adj_tbl
10222      ,p_old_line_scredit_tbl 	   	=> l_old_line_scredit_tbl
10223      ,p_old_lot_serial_tbl		=> l_old_lot_serial_tbl
10224 
10225      ,p_buyer_seller_flag           	=> 'B'
10226      ,p_reject_order                	=> 'N'
10227 
10228      ,x_return_status                   => l_return_status
10229      );
10230      End If;
10231 
10232      IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10233         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10234      ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10235         RAISE FND_API.G_EXC_ERROR;
10236         x_return_status := l_return_status;
10237      END IF;
10238     END IF;
10239 
10240   END IF; /* Code Level check */
10241 
10242     --  Done processing, load OUT parameters.
10243 
10244     p_x_header_rec                   := l_header_rec;
10245     p_x_Header_Adj_tbl               := l_Header_Adj_tbl;
10246     p_x_Header_Price_Att_tbl         := l_Header_Price_Att_tbl;
10247     p_x_Header_Adj_Att_tbl           := l_Header_Adj_Att_tbl;
10248     p_x_Header_Adj_Assoc_tbl         := l_Header_Adj_Assoc_tbl;
10249     p_x_Header_Scredit_tbl           := l_Header_Scredit_tbl;
10250     p_x_line_tbl                     := l_line_tbl;
10251     p_x_Line_Adj_tbl                 := l_Line_Adj_tbl;
10252     p_x_Line_Price_Att_tbl           := l_Line_Price_Att_tbl;
10253     p_x_Line_Adj_Att_tbl             := l_Line_Adj_Att_tbl;
10254     p_x_Line_Adj_Assoc_tbl           := l_Line_Adj_Assoc_tbl;
10255     p_x_Line_Scredit_tbl             := l_Line_Scredit_tbl;
10256     p_x_Lot_Serial_tbl               := l_Lot_Serial_tbl;
10257     p_x_action_request_tbl           := l_request_tbl;
10258 
10259     <<END_OF_PROCESS_ORDER>>
10260     --  Get message count and data
10261 
10262     OE_MSG_PUB.Count_And_Get
10263     (   p_count                       => x_msg_count
10264     ,   p_data                        => x_msg_data
10265     );
10266 
10267     set_recursion_mode(p_Entity_Code => 1,
10268                                    p_In_out  => 0);
10269 
10270    IF l_debug_level  > 0 THEN
10271        oe_debug_pub.add(  'GLOBAL REQUEST TABLE COUNT- PO'|| OE_DELAYED_REQUESTS_PVT.G_DELAYED_REQUESTS.COUNT , 1 ) ;
10272        oe_debug_pub.add(  'EXITING OE_ORDER_PUB.PROCESS_ORDER' , 1 ) ;
10273    END IF;
10274 
10275 EXCEPTION
10276 
10277     WHEN FND_API.G_EXC_ERROR THEN
10278 
10279         IF l_debug_level  > 0 THEN
10280             oe_debug_pub.add(  'PO: EXITING PROCESS ORDER WITH ERROR' , 2 ) ;
10281         END IF;
10282         set_recursion_mode(p_Entity_Code => 1,
10283                                    p_In_out  => 0);
10284         OE_SET_UTIL.G_SET_TBL.delete; --bug#2428456
10285         OE_SET_UTIL.G_SET_OPT_TBL.delete; -- bug#2428456
10286         x_return_status := FND_API.G_RET_STS_ERROR;
10287 
10288 	   IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
10289 		    IF l_debug_level  > 0 THEN
10290 		        oe_debug_pub.add(  'DELETE REQUEST11' , 2 ) ;
10291 		    END IF;
10292 
10293            OE_DELAYED_REQUESTS_PVT.Clear_Request(l_return_status);
10294            IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110508' THEN
10295                  OE_ORDER_UTIL.Clear_Global_Picture(l_return_status);
10296            END IF;
10297            OE_ORDER_WF_UTIL.CLEAR_FLOWSTART_GLOBALS;
10298   	      ROLLBACK TO SAVEPOINT Process_Order;
10299 
10300 	   END IF;
10301 
10302         --  Get message count and data
10303 
10304         OE_MSG_PUB.Count_And_Get
10305         (   p_count                       => x_msg_count
10306         ,   p_data                        => x_msg_data
10307         );
10308 
10309     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
10310 
10311         IF l_debug_level  > 0 THEN
10312             oe_debug_pub.add(  'PO: EXITING PROCESS ORDER WITH UNEXPECTED ERROR' , 2 ) ;
10313         END IF;
10314         set_recursion_mode(p_Entity_Code => 1,
10315                                    p_In_out  => 0);
10316         OE_SET_UTIL.G_SET_TBL.delete; --bug#2428456
10317         OE_SET_UTIL.G_SET_OPT_TBL.delete; -- bug#2428456
10318         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
10319 
10320 	   IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
10321 		    IF l_debug_level  > 0 THEN
10322 		        oe_debug_pub.add(  'DELETE REQUEST12' , 2 ) ;
10323 		    END IF;
10324 
10325            OE_DELAYED_REQUESTS_PVT.Clear_Request(l_return_status);
10326            IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110508' THEN
10327                  OE_ORDER_UTIL.Clear_Global_Picture(l_return_status);
10328            END IF;
10329            OE_ORDER_WF_UTIL.CLEAR_FLOWSTART_GLOBALS;
10330 	      ROLLBACK TO SAVEPOINT Process_Order;
10331 
10332 
10333 	   END IF;
10334 
10335         --  Get message count and data
10336 
10337         OE_MSG_PUB.Count_And_Get
10338         (   p_count                       => x_msg_count
10339         ,   p_data                        => x_msg_data
10340         );
10341 
10342     WHEN OTHERS THEN
10343 
10344         IF l_debug_level  > 0 THEN
10345             oe_debug_pub.add(  'PO: EXITING PROCESS ORDER WITH OTHERS ERROR' , 2 ) ;
10346         END IF;
10347         set_recursion_mode(p_Entity_Code => 1,
10348                                    p_In_out  => 0);
10349         OE_SET_UTIL.G_SET_TBL.delete; --bug#2428456
10350         OE_SET_UTIL.G_SET_OPT_TBL.delete; -- bug#2428456
10351         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
10352 
10353 	   IF NOT (OE_GLOBALS.G_UI_FLAG) THEN
10354 		    IF l_debug_level  > 0 THEN
10355 		        oe_debug_pub.add(  'DELETE REQUEST13' , 2 ) ;
10356 		    END IF;
10357 
10358           OE_DELAYED_REQUESTS_PVT.Clear_Request(l_return_status);
10359            IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110508' THEN
10360                  OE_ORDER_UTIL.Clear_Global_Picture(l_return_status);
10361            END IF;
10362         OE_ORDER_WF_UTIL.CLEAR_FLOWSTART_GLOBALS;
10363      	ROLLBACK TO SAVEPOINT Process_Order;
10364 
10365         END IF;
10366 
10367         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
10368         THEN
10369             OE_MSG_PUB.Add_Exc_Msg
10370             (   G_PKG_NAME
10371             ,   'Process_Order'
10372             );
10373         END IF;
10374 
10375         --  Get message count and data
10376 
10377         OE_MSG_PUB.Count_And_Get
10378         (   p_count                       => x_msg_count
10379         ,   p_data                        => x_msg_data
10380         );
10381 
10382 END Process_Order;
10383 
10384 
10385 /*---------------------------------------------------------------
10386 --  Start of Comments
10387 --  API name    Lock_Order
10388 --  Type        Private
10389 --
10390 --  Pre-reqs
10391 --
10392 --  Parameters
10393 --
10394 --  Version     Current version = 1.0
10395 --              Initial version = 1.0
10396 --
10397 --  Notes
10398 --
10399 --  End of Comments
10400 ---------------------------------------------------------------*/
10401 PROCEDURE Lock_Order
10402 (   p_api_version_number            IN  NUMBER
10403 ,   p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
10404 , x_return_status OUT NOCOPY VARCHAR2
10405 
10406 , x_msg_count OUT NOCOPY NUMBER
10407 
10408 , x_msg_data OUT NOCOPY VARCHAR2
10409 
10410 ,   p_x_header_rec                  IN OUT NOCOPY OE_Order_PUB.Header_Rec_Type
10411 ,   p_x_Header_Adj_tbl              IN OUT NOCOPY OE_Order_PUB.Header_Adj_Tbl_Type
10412 ,   p_x_Header_Price_Att_tbl        IN OUT NOCOPY OE_Order_PUB.Header_Price_Att_Tbl_Type
10413 ,   p_x_Header_Adj_Att_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Adj_Att_Tbl_Type
10414 ,   p_x_Header_Adj_Assoc_tbl        IN OUT NOCOPY OE_Order_PUB.Header_Adj_Assoc_Tbl_Type
10415 ,   p_x_Header_Scredit_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Scredit_Tbl_Type
10416 ,   p_x_line_tbl                    IN OUT NOCOPY OE_Order_PUB.Line_Tbl_Type
10417 ,   p_x_Line_Adj_tbl                IN OUT NOCOPY OE_Order_PUB.Line_Adj_Tbl_Type
10418 ,   p_x_Line_Price_Att_tbl          IN OUT NOCOPY OE_Order_PUB.Line_Price_Att_Tbl_Type
10419 ,   p_x_Line_Adj_Att_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Adj_Att_Tbl_Type
10420 ,   p_x_Line_Adj_Assoc_tbl          IN OUT NOCOPY OE_Order_PUB.Line_Adj_Assoc_Tbl_Type
10421 ,   p_x_Line_Scredit_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Scredit_Tbl_Type
10422 ,   p_x_Lot_Serial_tbl              IN OUT NOCOPY OE_Order_PUB.Lot_Serial_Tbl_Type
10423 ) IS
10424 l_x_Header_Payment_tbl          OE_Order_PUB.Header_Payment_Tbl_Type;
10425 l_x_Line_Payment_tbl            OE_Order_PUB.Line_Payment_Tbl_Type;
10426 BEGIN
10427    Lock_Order
10428     (  p_api_version_number            => p_api_version_number
10429    ,   p_init_msg_list                 => p_init_msg_list
10430    ,   x_return_status                 => x_return_status
10431    ,   x_msg_count                     => x_msg_count
10432    ,   x_msg_data                      => x_msg_data
10433    ,   p_x_header_rec                  => p_x_header_rec
10434    ,   p_x_Header_Adj_tbl              => p_x_Header_Adj_tbl
10435    ,   p_x_Header_Price_Att_tbl        => p_x_Header_Price_Att_tbl
10436    ,   p_x_Header_Adj_Att_tbl          => p_x_Header_Adj_Att_tbl
10437    ,   p_x_Header_Adj_Assoc_tbl        => p_x_Header_Adj_Assoc_tbl
10438    ,   p_x_Header_Scredit_tbl          => p_x_Header_Scredit_tbl
10439    ,   p_x_Header_Payment_tbl          => l_x_Header_Payment_tbl
10440    ,   p_x_line_tbl                    => p_x_line_tbl
10441    ,   p_x_Line_Adj_tbl                => p_x_Line_Adj_tbl
10442    ,   p_x_Line_Price_Att_tbl          => p_x_Line_Price_Att_tbl
10443    ,   p_x_Line_Adj_Att_tbl            => p_x_Line_Adj_Att_tbl
10444    ,   p_x_Line_Adj_Assoc_tbl          => p_x_Line_Adj_Assoc_tbl
10445    ,   p_x_Line_Scredit_tbl            => p_x_Line_Scredit_tbl
10446    ,   p_x_Line_Payment_tbl            => l_x_Line_Payment_tbl
10447    ,   p_x_Lot_Serial_tbl              => p_x_Lot_Serial_tbl
10448    );
10449 END Lock_Order;
10450 
10451 -- overloaded for payments parameters
10452 PROCEDURE Lock_Order
10453 (   p_api_version_number            IN  NUMBER
10454 ,   p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
10455 , x_return_status OUT NOCOPY VARCHAR2
10456 
10457 , x_msg_count OUT NOCOPY NUMBER
10458 
10459 , x_msg_data OUT NOCOPY VARCHAR2
10460 
10461 ,   p_x_header_rec                  IN OUT NOCOPY OE_Order_PUB.Header_Rec_Type
10462 ,   p_x_Header_Adj_tbl              IN OUT NOCOPY OE_Order_PUB.Header_Adj_Tbl_Type
10463 ,   p_x_Header_Price_Att_tbl        IN OUT NOCOPY OE_Order_PUB.Header_Price_Att_Tbl_Type
10464 ,   p_x_Header_Adj_Att_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Adj_Att_Tbl_Type
10465 ,   p_x_Header_Adj_Assoc_tbl        IN OUT NOCOPY OE_Order_PUB.Header_Adj_Assoc_Tbl_Type
10466 ,   p_x_Header_Scredit_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Scredit_Tbl_Type
10467 ,   p_x_Header_Payment_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Payment_Tbl_Type
10468 ,   p_x_line_tbl                    IN OUT NOCOPY OE_Order_PUB.Line_Tbl_Type
10469 ,   p_x_Line_Adj_tbl                IN OUT NOCOPY OE_Order_PUB.Line_Adj_Tbl_Type
10470 ,   p_x_Line_Price_Att_tbl          IN OUT NOCOPY OE_Order_PUB.Line_Price_Att_Tbl_Type
10471 ,   p_x_Line_Adj_Att_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Adj_Att_Tbl_Type
10472 ,   p_x_Line_Adj_Assoc_tbl          IN OUT NOCOPY OE_Order_PUB.Line_Adj_Assoc_Tbl_Type
10473 ,   p_x_Line_Scredit_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Scredit_Tbl_Type
10474 ,   p_x_Line_Payment_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Payment_Tbl_Type
10475 ,   p_x_Lot_Serial_tbl              IN OUT NOCOPY OE_Order_PUB.Lot_Serial_Tbl_Type
10476 )
10477 IS
10478 l_api_version_number          CONSTANT NUMBER := 1.0;
10479 l_api_name                    CONSTANT VARCHAR2(30):= 'Lock_Order';
10480 l_return_status               VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
10481 I                             NUMBER; -- Used for index.
10482 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
10483 BEGIN
10484 
10485     IF l_debug_level  > 0 THEN
10486         oe_debug_pub.add(  'ENTERING OE_ORDER_PVT.LOCK_ORDER' , 1 ) ;
10487     END IF;
10488     --  Standard call to check for call compatibility
10489 
10490     IF NOT FND_API.Compatible_API_Call
10491            (   l_api_version_number
10492            ,   p_api_version_number
10493            ,   l_api_name
10494            ,   G_PKG_NAME
10495            )
10496     THEN
10497         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10498     END IF;
10499 
10500     --  Initialize message list.
10501 
10502     IF FND_API.to_Boolean(p_init_msg_list) THEN
10503         OE_MSG_PUB.initialize;
10504     END IF;
10505 
10506     --  Set Savepoint
10507 
10508     SAVEPOINT Lock_Order_PVT;
10509 
10510     --  Lock header
10511 
10512     IF p_x_header_rec.operation = OE_GLOBALS.G_OPR_LOCK THEN
10513 
10514         OE_Header_Util.Lock_Row
10515         (   p_x_header_rec                => p_x_header_rec
10516         ,   x_return_status               => l_return_status
10517         );
10518 
10519         IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10520             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10521         ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10522             RAISE FND_API.G_EXC_ERROR;
10523         END IF;
10524 
10525 
10526     END IF;
10527 
10528     --  Lock Header_Adj
10529 
10530 --    FOR I IN 1..p_Header_Adj_tbl.COUNT LOOP
10531 
10532     I := p_x_Header_Adj_tbl.FIRST;
10533     WHILE I IS NOT NULL LOOP
10534 
10535         IF p_x_Header_Adj_tbl(I).operation = OE_GLOBALS.G_OPR_LOCK THEN
10536 
10537             OE_Header_Adj_Util.Lock_Row
10538             (   p_x_Header_Adj_rec            => p_x_Header_Adj_tbl(I)
10539             ,   x_return_status               => l_return_status
10540             );
10541 
10542             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10543                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10544             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10545                 RAISE FND_API.G_EXC_ERROR;
10546             END IF;
10547 
10548         END IF;
10549 
10550 		 I := p_x_Header_Adj_tbl.NEXT(I);
10551 
10552     END LOOP;
10553 
10554     --  Lock Header_Attribs
10555 
10556     I := p_x_Header_Price_Att_tbl.FIRST;
10557     WHILE I IS NOT NULL LOOP
10558 
10559         IF p_x_Header_Price_Att_tbl(I).operation = OE_GLOBALS.G_OPR_LOCK THEN
10560 
10561             OE_Header_PAttr_Util.Lock_Row
10562             (   p_x_Header_Price_Att_rec      => p_x_Header_Price_Att_tbl(I)
10563             ,   x_return_status               => l_return_status
10564             );
10565 
10566             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10567                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10568             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10569                 RAISE FND_API.G_EXC_ERROR;
10570             END IF;
10571 
10572         END IF;
10573 
10574 		 I := p_x_Header_Price_Att_tbl.NEXT(I);
10575 
10576     END LOOP;
10577 
10578     --  Lock Header_Adj_Attribs
10579 
10580     I := p_x_Header_Adj_Att_tbl.FIRST;
10581     WHILE I IS NOT NULL LOOP
10582 
10583         IF p_x_Header_Adj_Att_tbl(I).operation = OE_GLOBALS.G_OPR_LOCK THEN
10584 
10585             OE_Header_Price_Aattr_Util.Lock_Row
10586             (   p_x_Header_Adj_Att_rec        => p_x_Header_Adj_Att_tbl(I)
10587             ,   x_return_status               => l_return_status
10588             );
10589 
10590             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10591                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10592             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10593                 RAISE FND_API.G_EXC_ERROR;
10594             END IF;
10595 
10596         END IF;
10597 
10598 		 I := p_x_Header_Adj_Att_tbl.NEXT(I);
10599 
10600     END LOOP;
10601 
10602     --  Lock Header_Adj_Associations
10603 
10604     I := p_x_Header_Adj_Assoc_tbl.FIRST;
10605     WHILE I IS NOT NULL LOOP
10606 
10607         IF p_x_Header_Adj_Assoc_tbl(I).operation = OE_GLOBALS.G_OPR_LOCK THEN
10608 
10609             OE_Header_Adj_Assocs_Util.Lock_Row
10610             (   p_x_Header_Adj_Assoc_rec      => p_x_Header_Adj_Assoc_tbl(I)
10611             ,   x_return_status               => l_return_status
10612             );
10613 
10614             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10615                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10616             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10617                 RAISE FND_API.G_EXC_ERROR;
10618             END IF;
10619 
10620         END IF;
10621 
10622 		 I := p_x_Header_Adj_Assoc_tbl.NEXT(I);
10623 
10624     END LOOP;
10625 
10626     --  Lock Header_Scredit
10627 
10628 --    FOR I IN 1..p_Header_Scredit_tbl.COUNT LOOP
10629 
10630 	  I := p_x_Header_Scredit_tbl.FIRST;
10631 	  WHILE I IS NOT NULL LOOP
10632 
10633         IF p_x_Header_Scredit_tbl(I).operation = OE_GLOBALS.G_OPR_LOCK THEN
10634 
10635             OE_Header_Scredit_Util.Lock_Row
10636             (   p_x_Header_Scredit_rec        => p_x_Header_Scredit_tbl(I)
10637             ,   x_return_status               => l_return_status
10638             );
10639 
10640             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10641                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10642             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10643                 RAISE FND_API.G_EXC_ERROR;
10644             END IF;
10645 
10646         END IF;
10647 
10648 		 I := p_x_Header_Scredit_tbl.NEXT(I);
10649 
10650     END LOOP;
10651 
10652     --  Lock Header_Payment
10653 
10654   IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
10655 	  I := p_x_Header_Payment_tbl.FIRST;
10656 	  WHILE I IS NOT NULL LOOP
10657 
10658         IF p_x_Header_Payment_tbl(I).operation = OE_GLOBALS.G_OPR_LOCK THEN
10659 
10660             OE_Header_Payment_Util.Lock_Row
10661             (   p_x_Header_Payment_rec        => p_x_Header_Payment_tbl(I)
10662             ,   x_return_status               => l_return_status
10663             );
10664 
10665             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10666                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10667             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10668                 RAISE FND_API.G_EXC_ERROR;
10669             END IF;
10670 
10671         END IF;
10672 
10673 		 I := p_x_Header_Payment_tbl.NEXT(I);
10674 
10675     END LOOP;
10676   END IF;
10677 
10678     --  Lock line
10679 
10680 --    FOR I IN 1..p_line_tbl.COUNT LOOP
10681 
10682 	  I := p_x_line_tbl.FIRST;
10683 	  WHILE I IS NOT NULL LOOP
10684 
10685         IF p_x_line_tbl(I).operation = OE_GLOBALS.G_OPR_LOCK THEN
10686 
10687             OE_Line_Util.Lock_Row
10688             (   p_x_line_rec                  => p_x_line_tbl(I)
10689             ,   x_return_status               => l_return_status
10690             );
10691 
10692             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10693                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10694             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10695                 RAISE FND_API.G_EXC_ERROR;
10696             END IF;
10697 
10698         END IF;
10699 
10700 		 I := p_x_line_tbl.NEXT(I);
10701 
10702     END LOOP;
10703 
10704     --  Lock Line_Adj
10705 
10706 --    FOR I IN 1..p_Line_Adj_tbl.COUNT LOOP
10707 
10708 	  I := p_x_Line_Adj_tbl.FIRST;
10709     WHILE I IS NOT NULL LOOP
10710 
10711         IF p_x_Line_Adj_tbl(I).operation = OE_GLOBALS.G_OPR_LOCK THEN
10712 
10713             OE_Line_Adj_Util.Lock_Row
10714             (   p_x_Line_Adj_rec              => p_x_Line_Adj_tbl(I)
10715             ,   x_return_status               => l_return_status
10716             );
10717 
10718             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10719                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10720             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10721                 RAISE FND_API.G_EXC_ERROR;
10722             END IF;
10723 
10724         END IF;
10725 
10726 		 I := p_x_Line_Adj_tbl.NEXT(I);
10727 
10728     END LOOP;
10729 
10730     --  Lock Line_Attribs
10731 
10732     I := p_x_Line_Price_Att_tbl.FIRST;
10733     WHILE I IS NOT NULL LOOP
10734 
10735         IF p_x_Line_Price_Att_tbl(I).operation = OE_GLOBALS.G_OPR_LOCK THEN
10736 
10737             OE_Line_PAttr_Util.Lock_Row
10738             (   p_x_Line_Price_Att_rec            => p_x_Line_Price_Att_tbl(I)
10739             ,   x_return_status               => l_return_status
10740             );
10741 
10742             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10743                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10744             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10745                 RAISE FND_API.G_EXC_ERROR;
10746             END IF;
10747 
10748         END IF;
10749 
10750 		 I := p_x_Line_Price_Att_tbl.NEXT(I);
10751 
10752     END LOOP;
10753 
10754     --  Lock Line_Adj_Attribs
10755 
10756     I := p_x_Line_Adj_Att_tbl.FIRST;
10757     WHILE I IS NOT NULL LOOP
10758 
10759         IF p_x_Line_Adj_Att_tbl(I).operation = OE_GLOBALS.G_OPR_LOCK THEN
10760 
10761             OE_Line_Price_Aattr_Util.Lock_Row
10762             (   p_x_Line_Adj_Att_rec            => p_x_Line_Adj_Att_tbl(I)
10763             ,   x_return_status               => l_return_status
10764             );
10765 
10766             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10767                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10768             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10769                 RAISE FND_API.G_EXC_ERROR;
10770             END IF;
10771 
10772         END IF;
10773 
10774 		 I := p_x_Line_Adj_Att_tbl.NEXT(I);
10775 
10776     END LOOP;
10777 
10778     --  Lock Line_Adj_Associations
10779 
10780     I := p_x_Line_Adj_Assoc_tbl.FIRST;
10781     WHILE I IS NOT NULL LOOP
10782 
10783         IF p_x_Line_Adj_Assoc_tbl(I).operation = OE_GLOBALS.G_OPR_LOCK THEN
10784 
10785             OE_Line_Adj_Assocs_Util.Lock_Row
10786             (   p_x_Line_Adj_Assoc_rec        => p_x_Line_Adj_Assoc_tbl(I)
10787             ,   x_return_status               => l_return_status
10788             );
10789 
10790             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10791                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10792             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10793                 RAISE FND_API.G_EXC_ERROR;
10794             END IF;
10795 
10796         END IF;
10797 
10798 		 I := p_x_Line_Adj_Assoc_tbl.NEXT(I);
10799 
10800     END LOOP;
10801 
10802     --  Lock Line_Scredit
10803 
10804 --    FOR I IN 1..p_Line_Scredit_tbl.COUNT LOOP
10805     I := p_x_Line_Scredit_tbl.FIRST;
10806     WHILE I IS NOT NULL LOOP
10807 
10808         IF p_x_Line_Scredit_tbl(I).operation = OE_GLOBALS.G_OPR_LOCK THEN
10809 
10810             OE_Line_Scredit_Util.Lock_Row
10811             (   p_x_Line_Scredit_rec          => p_x_Line_Scredit_tbl(I)
10812             ,   x_return_status               => l_return_status
10813             );
10814 
10815             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10816                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10817             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10818                 RAISE FND_API.G_EXC_ERROR;
10819             END IF;
10820 
10821         END IF;
10822 
10823 		 I := p_x_Line_Scredit_tbl.NEXT(I);
10824 
10825     END LOOP;
10826 
10827     --  Lock Line_Payment
10828 
10829   IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
10830     I := p_x_Line_Payment_tbl.FIRST;
10831 
10832     WHILE I IS NOT NULL LOOP
10833 
10834         IF p_x_Line_Payment_tbl(I).operation = OE_GLOBALS.G_OPR_LOCK THEN
10835 
10836             OE_Line_Payment_Util.Lock_Row
10837             (   p_x_Line_Payment_rec          => p_x_Line_Payment_tbl(I)
10838             ,   x_return_status               => l_return_status
10839             );
10840 
10841             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10842                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10843             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10844                 RAISE FND_API.G_EXC_ERROR;
10845             END IF;
10846 
10847         END IF;
10848 
10849 		 I := p_x_Line_Payment_tbl.NEXT(I);
10850 
10851     END LOOP;
10852   END IF;
10853 
10854     --  Lock Lot_Serial
10855 
10856 --    FOR I IN 1..p_Lot_Serial_tbl.COUNT LOOP
10857 
10858 	  I := p_x_Lot_Serial_tbl.FIRST;
10859 	  WHILE I IS NOT NULL LOOP
10860 
10861         IF p_x_Lot_Serial_tbl(I).operation = OE_GLOBALS.G_OPR_LOCK THEN
10862 
10863             OE_Lot_Serial_Util.Lock_Row
10864             (   p_x_Lot_Serial_rec            => p_x_Lot_Serial_tbl(I)
10865             ,   x_return_status               => l_return_status
10866             );
10867 
10868             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10869                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10870             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10871                 RAISE FND_API.G_EXC_ERROR;
10872             END IF;
10873 
10874         END IF;
10875 
10876 		 I := p_x_Lot_Serial_tbl.NEXT(I);
10877 
10878     END LOOP;
10879 
10880     --  Set return status
10881 
10882     x_return_status := FND_API.G_RET_STS_SUCCESS;
10883 
10884     --  Get message count and data
10885 
10886     OE_MSG_PUB.Count_And_Get
10887     (   p_count                       => x_msg_count
10888     ,   p_data                        => x_msg_data
10889     );
10890 
10891    if p_x_line_tbl.count > 0 then
10892 	IF l_debug_level  > 0 THEN
10893 	    oe_debug_pub.add(  'LINE ID:'||P_X_LINE_TBL ( 1 ) .LINE_ID ) ;
10894 	END IF;
10895    end if;
10896    IF l_debug_level  > 0 THEN
10897        oe_debug_pub.add(  'EXITING OE_ORDER_PUB.LOCK_ORDER' , 1 ) ;
10898    END IF;
10899 
10900 EXCEPTION
10901 
10902     WHEN FND_API.G_EXC_ERROR THEN
10903 
10904         x_return_status := FND_API.G_RET_STS_ERROR;
10905 
10906         --  Get message count and data
10907 
10908         OE_MSG_PUB.Count_And_Get
10909         (   p_count                       => x_msg_count
10910         ,   p_data                        => x_msg_data
10911         );
10912 
10913         --  Rollback
10914 
10915         ROLLBACK TO Lock_Order_PVT;
10916 
10917     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
10918 
10919         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
10920 
10921         --  Get message count and data
10922 
10923         OE_MSG_PUB.Count_And_Get
10924         (   p_count                       => x_msg_count
10925         ,   p_data                        => x_msg_data
10926         );
10927 
10928         --  Rollback
10929 
10930         ROLLBACK TO Lock_Order_PVT;
10931 
10932     WHEN OTHERS THEN
10933 
10934         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
10935 
10936         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
10937         THEN
10938             OE_MSG_PUB.Add_Exc_Msg
10939             (   G_PKG_NAME
10940             ,   'Lock_Order'
10941             );
10942         END IF;
10943 
10944         --  Get message count and data
10945 
10946         OE_MSG_PUB.Count_And_Get
10947         (   p_count                       => x_msg_count
10948         ,   p_data                        => x_msg_data
10949         );
10950 
10951         --  Rollback
10952 
10953         ROLLBACK TO Lock_Order_PVT;
10954 
10955 END Lock_Order;
10956 
10957 
10958 /*---------------------------------------------------------------
10959 --  Start of Comments
10960 --  API name    Get_Order
10961 --  Type        Private
10962 --
10963 --  Pre-reqs
10964 --
10965 --  Parameters
10966 --
10967 --  Version     Current version = 1.0
10968 --              Initial version = 1.0
10969 --
10970 --  Notes
10971 --
10972 --  End of Comments
10973 
10974 --------------------------------------------------------------*/
10975 PROCEDURE Get_Order
10976 (   p_api_version_number            IN  NUMBER
10977 ,   p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
10978 , x_return_status OUT NOCOPY VARCHAR2
10979 
10980 , x_msg_count OUT NOCOPY NUMBER
10981 
10982 , x_msg_data OUT NOCOPY VARCHAR2
10983 
10984 ,   p_header_id                     IN  NUMBER
10985 ,   x_header_rec                    IN OUT NOCOPY OE_Order_PUB.Header_Rec_Type
10986 ,   x_Header_Adj_tbl                IN OUT NOCOPY OE_Order_PUB.Header_Adj_Tbl_Type
10987 ,   x_Header_price_Att_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Price_Att_Tbl_Type
10988 ,   x_Header_Adj_Att_tbl            IN OUT NOCOPY OE_Order_PUB.Header_Adj_Att_Tbl_Type
10989 ,   x_Header_Adj_Assoc_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Adj_Assoc_Tbl_Type
10990 ,   x_Header_Scredit_tbl            IN OUT NOCOPY OE_Order_PUB.Header_Scredit_Tbl_Type
10991 ,   x_line_tbl                      IN OUT NOCOPY OE_Order_PUB.Line_Tbl_Type
10992 ,   x_Line_Adj_tbl                  IN OUT NOCOPY OE_Order_PUB.Line_Adj_Tbl_Type
10993 ,   x_Line_price_Att_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Price_Att_Tbl_Type
10994 ,   x_Line_Adj_Att_tbl              IN OUT NOCOPY OE_Order_PUB.Line_Adj_Att_Tbl_Type
10995 ,   x_Line_Adj_Assoc_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Adj_Assoc_Tbl_Type
10996 ,   x_Line_Scredit_tbl              IN OUT NOCOPY OE_Order_PUB.Line_Scredit_Tbl_Type
10997 ,   x_Lot_Serial_tbl                IN OUT NOCOPY OE_Order_PUB.Lot_Serial_Tbl_Type
10998 ) IS
10999 x_Header_Payment_tbl          OE_Order_PUB.Header_Payment_Tbl_Type;
11000 x_Line_Payment_tbl            OE_Order_PUB.Line_Payment_Tbl_Type;
11001 BEGIN
11002    Get_Order
11003    (   p_api_version_number            => p_api_version_number
11004    ,   p_init_msg_list                 => p_init_msg_list
11005    ,   x_return_status                 => x_return_status
11006    ,   x_msg_count                     => x_msg_count
11007    ,   x_msg_data                      => x_msg_data
11008    ,   p_header_id                     => p_header_id
11009    ,   x_header_rec                    => x_header_rec
11010    ,   x_Header_Adj_tbl                => x_Header_Adj_tbl
11011    ,   x_Header_price_Att_tbl          => x_Header_price_Att_tbl
11012    ,   x_Header_Adj_Att_tbl            => x_Header_Adj_Att_tbl
11013    ,   x_Header_Adj_Assoc_tbl          => x_Header_Adj_Assoc_tbl
11014    ,   x_Header_Scredit_tbl            => x_Header_Scredit_tbl
11015    ,   x_Header_Payment_tbl            => x_Header_Payment_tbl
11016    ,   x_line_tbl                      => x_line_tbl
11017    ,   x_Line_Adj_tbl                  => x_Line_Adj_tbl
11018    ,   x_Line_price_Att_tbl            => x_Line_price_Att_tbl
11019    ,   x_Line_Adj_Att_tbl              => x_Line_Adj_Att_tbl
11020    ,   x_Line_Adj_Assoc_tbl            => x_Line_Adj_Assoc_tbl
11021    ,   x_Line_Scredit_tbl              => x_Line_Scredit_tbl
11022    ,   x_Line_Payment_tbl              => x_Line_Payment_tbl
11023    ,   x_Lot_Serial_tbl                => x_Lot_Serial_tbl
11024    );
11025 END Get_Order;
11026 
11027 -- overloaded for payments parameters
11028 PROCEDURE Get_Order
11029 (   p_api_version_number            IN  NUMBER
11030 ,   p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
11031 , x_return_status OUT NOCOPY VARCHAR2
11032 
11033 , x_msg_count OUT NOCOPY NUMBER
11034 
11035 , x_msg_data OUT NOCOPY VARCHAR2
11036 
11037 ,   p_header_id                     IN  NUMBER
11038 ,   x_header_rec                    IN OUT NOCOPY OE_Order_PUB.Header_Rec_Type
11039 ,   x_Header_Adj_tbl                IN OUT NOCOPY OE_Order_PUB.Header_Adj_Tbl_Type
11040 ,   x_Header_price_Att_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Price_Att_Tbl_Type
11041 ,   x_Header_Adj_Att_tbl            IN OUT NOCOPY OE_Order_PUB.Header_Adj_Att_Tbl_Type
11042 ,   x_Header_Adj_Assoc_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Adj_Assoc_Tbl_Type
11043 ,   x_Header_Scredit_tbl            IN OUT NOCOPY OE_Order_PUB.Header_Scredit_Tbl_Type
11044 ,   x_Header_Payment_tbl            IN OUT NOCOPY OE_Order_PUB.Header_Payment_Tbl_Type
11045 ,   x_line_tbl                      IN OUT NOCOPY OE_Order_PUB.Line_Tbl_Type
11046 ,   x_Line_Adj_tbl                  IN OUT NOCOPY OE_Order_PUB.Line_Adj_Tbl_Type
11047 ,   x_Line_price_Att_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Price_Att_Tbl_Type
11048 ,   x_Line_Adj_Att_tbl              IN OUT NOCOPY OE_Order_PUB.Line_Adj_Att_Tbl_Type
11049 ,   x_Line_Adj_Assoc_tbl            IN OUT NOCOPY OE_Order_PUB.Line_Adj_Assoc_Tbl_Type
11050 ,   x_Line_Scredit_tbl              IN OUT NOCOPY OE_Order_PUB.Line_Scredit_Tbl_Type
11051 ,   x_Line_Payment_tbl              IN OUT NOCOPY OE_Order_PUB.Line_Payment_Tbl_Type
11052 ,   x_Lot_Serial_tbl                IN OUT NOCOPY OE_Order_PUB.Lot_Serial_Tbl_Type
11053 )
11054 IS
11055 l_api_version_number          CONSTANT NUMBER := 1.0;
11056 l_api_name                    CONSTANT VARCHAR2(30):= 'Get_Order';
11057 l_Header_Adj_tbl              OE_Order_PUB.Header_Adj_Tbl_Type;
11058 l_Header_Price_Att_tbl        OE_Order_PUB.Header_Price_Att_Tbl_Type;
11059 l_Header_Adj_Att_tbl          OE_Order_PUB.Header_Adj_Att_Tbl_Type;
11060 l_Header_Adj_Assoc_tbl        OE_Order_PUB.Header_Adj_Assoc_Tbl_Type;
11061 l_Line_Adj_tbl                OE_Order_PUB.Line_Adj_Tbl_Type;
11062 l_Line_Price_Att_tbl          OE_Order_PUB.Line_Price_Att_Tbl_Type;
11063 l_Line_Adj_Att_tbl            OE_Order_PUB.Line_Adj_Att_Tbl_Type;
11064 l_Line_Adj_Assoc_tbl          OE_Order_PUB.Line_Adj_Assoc_Tbl_Type;
11065 l_Line_Scredit_tbl            OE_Order_PUB.Line_Scredit_Tbl_Type;
11066 l_Line_Payment_tbl            OE_Order_PUB.Line_Payment_Tbl_Type;
11067 l_Lot_Serial_tbl              OE_Order_PUB.Lot_Serial_Tbl_Type;
11068 I2					   NUMBER; --Used as index.
11069 I3					   NUMBER; --Used as index.
11070 I4					   NUMBER; --Used as index.
11071 I5					   NUMBER; --Used as index.
11072 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
11073 BEGIN
11074 
11075     --  Standard call to check for call compatibility
11076 
11077     IF NOT FND_API.Compatible_API_Call
11078            (   l_api_version_number
11079            ,   p_api_version_number
11080            ,   l_api_name
11081            ,   G_PKG_NAME
11082            )
11083     THEN
11084         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11085     END IF;
11086 
11087     --  Initialize message list.
11088 
11089     IF FND_API.to_Boolean(p_init_msg_list) THEN
11090         OE_MSG_PUB.initialize;
11091     END IF;
11092 
11093     --  Get header ( parent = header )
11094 
11095     OE_Header_Util.Query_Row
11096     (   p_header_id           => p_header_id
11097     ,   x_header_rec          => x_header_rec
11098     );
11099 
11100         --  Get Header_Adj ( parent = header )
11101 
11102         OE_Header_Adj_Util.Query_Rows
11103         (   p_header_id             => p_header_id
11104 	   ,   x_Header_Adj_Tbl        => x_Header_Adj_Tbl
11105         );
11106 
11107         --  Get Header_Attribs ( parent = header )
11108 
11109         OE_Header_PAttr_Util.Query_Rows
11110         (   p_header_id             => p_header_id
11111 	   ,   x_Header_Price_Att_tbl  => x_Header_Price_Att_tbl
11112         );
11113 
11114 
11115 	   I2 := l_Header_Adj_tbl.FIRST;
11116         WHILE I2 IS NOT NULL LOOP
11117         --  Get Header_adj_attribs ( parent = Adjustments )
11118 
11119            l_Header_Adj_Att_tbl.delete;   --6052770
11120            Oe_Header_Price_Aattr_util.Query_Rows
11121            (   p_price_adjustment_id             =>
11122 						l_Header_Adj_tbl(I2).price_adjustment_id
11123 		 ,  x_Header_Adj_Att_tbl        => l_Header_Adj_Att_tbl
11124             );
11125 
11126 	      I3 := l_Header_Adj_Att_tbl.first;
11127 
11128 	      While I3 is not Null Loop
11129 
11130 			l_Header_Adj_Att_tbl(I3).Adj_Index := I2;
11131 			x_Header_Adj_Att_tbl(x_Header_Adj_Att_tbl.count+1) :=
11132 				l_Header_Adj_Att_tbl(I3);
11133 			I3 := l_Header_Adj_Att_tbl.Next(I3);
11134 
11135 		 end loop;
11136 
11137         --  Get Header_adj_Assocs ( parent = Adjutments )
11138 
11139            l_Header_Adj_Assoc_Tbl.delete;  --6052770
11140            Oe_Header_Adj_Assocs_util.Query_Rows
11141            (   p_price_adjustment_id             =>
11142 						l_header_Adj_tbl(I2).Price_Adjustment_id
11143            ,  x_Header_Adj_Assoc_Tbl            => l_Header_Adj_Assoc_Tbl
11144            );
11145 
11146 	      I3 := l_Header_Adj_Assoc_tbl.first;
11147 
11148 	      While I3 is not Null Loop
11149 
11150 			l_Header_Adj_Assoc_tbl(I3).Adj_Index := I2;
11151 			x_Header_Adj_Assoc_tbl(x_Header_Adj_Assoc_tbl.count+1) :=
11152 				l_Header_Adj_Assoc_tbl(I3);
11153 			I3 := l_Header_Adj_Assoc_tbl.Next(I3);
11154 
11155 		 end loop;
11156 	   I2 := l_header_Adj_tbl.next(I2);
11157 	   end loop;
11158 
11159         --  Get Header_Scredit ( parent = header )
11160 
11161         OE_Header_Scredit_Util.Query_Rows
11162         (   p_header_id             => p_header_id
11163 	   ,   x_Header_Scredit_tbl    => x_Header_Scredit_tbl
11164         );
11165 
11166         IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
11167            --  Get Header_Payment ( parent = header )
11168 
11169            OE_Header_Payment_Util.Query_Rows
11170            (   p_header_id             => p_header_id
11171    	   ,   x_Header_Payment_tbl    => x_Header_Payment_tbl
11172            );
11173         END IF;
11174 
11175         --  Get line ( parent = header )
11176 
11177         OE_Line_Util.Query_Rows
11178         (   p_header_id             => p_header_id
11179 	   ,   x_line_tbl              => x_line_tbl
11180         );
11181 
11182 
11183         --  Loop over line's children
11184 
11185 --        FOR I2 IN 1..x_line_tbl.COUNT LOOP
11186 		I2 := x_line_tbl.FIRST;
11187 		WHILE I2 IS NOT NULL LOOP
11188 
11189             --  Get Line_Adj ( parent = line )
11190 
11191             l_Line_Adj_tbl.delete;  --6052770
11192             OE_Line_Adj_Util.Query_Rows
11193             (   p_line_id                 => x_line_tbl(I2).line_id
11194 		  ,   x_Line_Adj_tbl            => l_Line_Adj_tbl
11195             );
11196 
11197 			I3 := l_Line_Adj_tbl.FIRST;
11198 			WHILE I3 IS NOT NULL LOOP
11199 
11200                 l_Line_Adj_tbl(I3).line_Index  := I2;
11201                 x_Line_Adj_tbl
11202                 (x_Line_Adj_tbl.COUNT + 1)   := l_Line_Adj_tbl(I3);
11203 			    I3 := l_Line_Adj_tbl.NEXT(I3);
11204 
11205                END LOOP;
11206 
11207 
11208             --  Get Line_Attibs ( parent = Line )
11209 
11210                 l_Line_Price_Att_tbl.delete;  --6052770
11211             	OE_Line_Pattr_Util.Query_Rows
11212             	(   P_Line_Id  => x_line_tbl(I2).Line_id
11213 			,   x_Line_Price_Att_tbl         => l_Line_Price_Att_tbl
11214             	);
11215 
11216 			I3 := l_Line_Price_Att_tbl.FIRST;
11217 			WHILE I3 IS NOT NULL LOOP
11218 
11219                 l_Line_Price_Att_tbl(I3).line_Index  := I2;
11220                 x_Line_Price_Att_tbl
11221                 (x_Line_Price_Att_tbl.COUNT + 1)   := l_Line_Price_Att_tbl(I3);
11222 			    I3 := l_Line_Price_Att_tbl.NEXT(I3);
11223 
11224                END LOOP;
11225 
11226             --  Get Line_Adj_Attribs ( parent = Adj )
11227 
11228 			I4 := l_line_Adj_tbl.FIRST;
11229 			WHILE I4 IS NOT NULL LOOP
11230 
11231                   l_Line_Adj_Att_tbl.delete;  --6052770
11232             	  Oe_Line_Price_Aattr_util.Query_Rows
11233             	  (   p_price_adjustment_id  =>
11234 						l_line_Adj_tbl(I4).price_Adjustment_id
11235                  ,   x_Line_Adj_Att_tbl     => l_Line_Adj_Att_tbl
11236             	  );
11237 
11238 			  I5 := l_Line_Adj_Att_tbl.FIRST;
11239 			  WHILE I5 IS NOT NULL LOOP
11240 
11241                 	l_Line_Adj_Att_tbl(I5).Adj_Index  := I4;
11242                 	x_Line_Adj_Att_tbl
11243                 	(x_Line_Adj_Att_tbl.COUNT + 1)   := l_Line_Adj_Att_tbl(I5);
11244 			    	I5 := l_Line_Adj_Att_tbl.NEXT(I5);
11245 
11246             	  END LOOP;
11247 
11248             --  Get Line_Adj_Assocs ( parent = Adj )
11249 
11250                  l_Line_Adj_Assoc_tbl.delete;   --6052770
11251                  Oe_Line_Adj_Assocs_util.Query_Rows
11252                  (   p_price_Adjustment_id  =>
11253 						l_line_Adj_tbl(I4).price_Adjustment_id
11254                  ,   x_Line_Adj_Assoc_tbl   => l_Line_Adj_Assoc_tbl
11255                  );
11256 
11257 			     I5 := l_Line_Adj_Assoc_tbl.FIRST;
11258 			     WHILE I5 IS NOT NULL LOOP
11259 
11260                      l_Line_Adj_Assoc_tbl(I5).Adj_Index  := I4;
11261                      x_Line_Adj_Assoc_tbl
11262                      (x_Line_Adj_Assoc_tbl.COUNT + 1)   :=
11263 								l_Line_Adj_Assoc_tbl(I5);
11264 			         I5 := l_Line_Adj_Assoc_tbl.NEXT(I5);
11265 
11266                       END LOOP;
11267 				I4 := l_line_Adj_tbl.next(I4);
11268 			end loop;
11269 
11270             --  Get Line_Scredit ( parent = line )
11271 
11272             l_Line_Scredit_tbl.delete;  --6052770
11273             OE_Line_Scredit_Util.Query_Rows
11274             (   p_line_id                 => x_line_tbl(I2).line_id
11275 		  ,   x_Line_Scredit_tbl        => l_Line_Scredit_tbl
11276             );
11277 
11278 --            FOR I3 IN 1..l_Line_Scredit_tbl.COUNT LOOP
11279 
11280 			I3 := l_Line_Scredit_tbl.FIRST;
11281 			WHILE I3 IS NOT NULL LOOP
11282 
11283                 l_Line_Scredit_tbl(I3).line_Index := I2;
11284                 x_Line_Scredit_tbl
11285                 (x_Line_Scredit_tbl.COUNT + 1) := l_Line_Scredit_tbl(I3);
11286 			    I3 := l_Line_Scredit_tbl.NEXT(I3);
11287 
11288             END LOOP;
11289 
11290             IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
11291                --  Get Line_Payment ( parent = line )
11292 
11293                l_Line_Payment_tbl.delete;  --6052770
11294                OE_Line_Payment_Util.Query_Rows
11295                (   p_line_id                 => x_line_tbl(I2).line_id
11296                ,   p_header_id		     => x_line_tbl(I2).header_id
11297    	       ,   x_Line_Payment_tbl        => l_Line_Payment_tbl
11298                );
11299 
11300 			I3 := l_Line_Payment_tbl.FIRST;
11301 			WHILE I3 IS NOT NULL LOOP
11302 
11303                    l_Line_Payment_tbl(I3).line_Index := I2;
11304                    x_Line_Payment_tbl
11305                    (x_Line_Payment_tbl.COUNT + 1) := l_Line_Payment_tbl(I3);
11306 			    I3 := l_Line_Payment_tbl.NEXT(I3);
11307 
11308                END LOOP;
11309             END IF;
11310 
11311             --  Get Lot_Serial ( parent = line )
11312 
11313             l_Lot_Serial_tbl.delete;  --6052770
11314             OE_Lot_Serial_Util.Query_Rows
11315             (   p_line_id                 => x_line_tbl(I2).line_id
11316 		  ,   x_Lot_Serial_tbl          => l_Lot_Serial_tbl
11317             );
11318 
11319 --            FOR I3 IN 1..l_Lot_Serial_tbl.COUNT LOOP
11320 			I3 := l_Lot_Serial_tbl.FIRST;
11321 			WHILE I3 IS NOT NULL LOOP
11322 
11323                 l_Lot_Serial_tbl(I3).line_Index := I2;
11324                 x_Lot_Serial_tbl
11325                 (x_Lot_Serial_tbl.COUNT + 1) := l_Lot_Serial_tbl(I3);
11326 			    I3 := l_Lot_Serial_tbl.NEXT(I3);
11327 
11328             END LOOP;
11329 
11330 			I2 := x_line_tbl.NEXT(I2);
11331 
11332         END LOOP;
11333 
11334     --  Set return status
11335 
11336     x_return_status := FND_API.G_RET_STS_SUCCESS;
11337 
11338     --  Get message count and data
11339 
11340     OE_MSG_PUB.Count_And_Get
11341     (   p_count                       => x_msg_count
11342     ,   p_data                        => x_msg_data
11343     );
11344 
11345 
11346 EXCEPTION
11347 
11348     WHEN FND_API.G_EXC_ERROR THEN
11349 
11350         x_return_status := FND_API.G_RET_STS_ERROR;
11351 
11352         --  Get message count and data
11353 
11354         OE_MSG_PUB.Count_And_Get
11355         (   p_count                       => x_msg_count
11356         ,   p_data                        => x_msg_data
11357         );
11358 
11359     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
11360 
11361         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
11362 
11363         --  Get message count and data
11364 
11365         OE_MSG_PUB.Count_And_Get
11366         (   p_count                       => x_msg_count
11367         ,   p_data                        => x_msg_data
11368         );
11369 
11370     WHEN OTHERS THEN
11371 
11372         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
11373 
11374         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
11375         THEN
11376             OE_MSG_PUB.Add_Exc_Msg
11377             (   G_PKG_NAME
11378             ,   'Get_Order'
11379             );
11380         END IF;
11381 
11382         --  Get message count and data
11383 
11384         OE_MSG_PUB.Count_And_Get
11385         (   p_count                       => x_msg_count
11386         ,   p_data                        => x_msg_data
11387         );
11388 
11389 END Get_Order;
11390 
11391 
11392 /*---------------------------------------------------------------
11393 Procedure Cancel_Order
11394 --------------------------------------------------------------*/
11395 
11396 Procedure Cancel_Order
11397 (    p_api_version_number            IN  NUMBER
11398 ,    p_init_msg_list                 IN  VARCHAR2 := FND_API.G_FALSE
11399 , x_return_status OUT NOCOPY VARCHAR2
11400 
11401 , x_msg_count OUT NOCOPY NUMBER
11402 
11403 , x_msg_data OUT NOCOPY VARCHAR2
11404 
11405 ,    x_can_req                       IN OUT
11406                                         OE_ORDER_PUB.Cancel_Line_Tbl_Type
11407 ) IS
11408 l_api_version_number       number := 1.0;
11409 l_api_name                 Varchar2(30) := 'CANCEL_ORDER';
11410 l_return_status            Varchar2(1);
11411 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
11412 Begin
11413     --  Standard call to check for call compatibility
11414 
11415     IF l_debug_level  > 0 THEN
11416         oe_debug_pub.add(  'ENTERING OE_ORDER_PUB.CANCEL_ORDER' , 1 ) ;
11417     END IF;
11418 
11419     IF NOT FND_API.Compatible_API_Call
11420            (   l_api_version_number
11421            ,   p_api_version_number
11422            ,   l_api_name
11423            ,   G_PKG_NAME
11424            )
11425     THEN
11426         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11427     END IF;
11428 
11429     -- Initialize message list if p_init_msg_list is set to TRUE.
11430     IF FND_API.to_Boolean( p_init_msg_list ) THEN
11431         OE_MSG_PUB.initialize;
11432     END IF;
11433 
11434     --  Initialize API return status to success
11435     x_return_status := FND_API.G_RET_STS_SUCCESS;
11436 
11437     IF l_debug_level  > 0 THEN
11438         oe_debug_pub.add(  'CALLING OE_SALES_CAN_UTIL.CANCEL_LINE' , 2 ) ;
11439     END IF;
11440   /*  OE_SALES_CAN_UTIL.Cancel_Line
11441                      ( x_return_status => l_return_status
11442                      ,x_msg_count      => x_msg_count
11443                      ,x_msg_data       => x_msg_data
11444                      ,x_can_req         => x_can_req
11445                      );*/
11446                             IF l_debug_level  > 0 THEN
11447                                 oe_debug_pub.add(  'COMPLETED OE_SALES_CAN_UTIL.CANCEL_LINE WITH STATUS ' || L_RETURN_STATUS , 2 ) ;
11448                             END IF;
11449 
11450     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
11451         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11452     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
11453         RAISE FND_API.G_EXC_ERROR;
11454     END IF;
11455 
11456     IF l_debug_level  > 0 THEN
11457         oe_debug_pub.add(  'EXITING OE_ORDER_PUB.CANCEL_ORDER' , 1 ) ;
11458     END IF;
11459 
11460 EXCEPTION
11461 
11462     WHEN FND_API.G_EXC_ERROR THEN
11463       x_return_status := FND_API.G_RET_STS_ERROR;
11464 
11465     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
11466           IF OE_MSG_PUB.Check_MSg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
11467              OE_MSG_PUB.Add_Exc_Msg
11468              (G_PKG_NAME
11469               ,'Cancel_Order');
11470           END IF;
11471       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11472 
11473    WHEN OTHERS THEN
11474 
11475        IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
11476 	 THEN
11477             OE_MSG_PUB.Add_Exc_Msg
11478 	      (   G_PKG_NAME
11479 		  ,   'Cancel_Order'
11480 		  );
11481        END IF;
11482 
11483        x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11484 
11485 END Cancel_Order;
11486 
11487 
11488 /*------------------------------------------------------------------------
11489 PROCEDURE Print_Time
11490 
11491 -------------------------------------------------------------------------*/
11492 
11493 PROCEDURE Print_Time(p_msg   IN  VARCHAR2)
11494 IS
11495   l_time    VARCHAR2(100);
11496   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
11497 BEGIN
11498   l_time := to_char (new_time (sysdate, 'PST', 'EST'),
11499                                  'DD-MON-YY HH24:MI:SS');
11500   IF l_debug_level  > 0 THEN
11501       oe_debug_pub.add(  P_MSG || ': '|| L_TIME , 1 ) ;
11502   END IF;
11503 END Print_Time;
11504 
11505 
11506 
11507 /*------------------------------------------------------------------------
11508 PROCEDURE Complete_Config_Line
11509 
11510 This procedure should never get called f the configuration is
11511 created using options window or configurator, since we already
11512 do all the work in respective code.
11513 
11514 if p_item_type = 1, we do work related to models
11515 if p_item_type = 2, we do work related to classes and options.
11516 
11517 In all cases, we have a common work of loading the
11518 in rec with BOM values, viz.
11519 component_code
11520 component_sequence_id
11521 order_quantity_uom
11522 sort_order
11523 
11524 For p_item_type = 2,
11525 When we come out nocopy of this procedure, all the class lines will have
11526 
11527 item_type_code set and this plays imp role in the lines loop, when
11528 the mode = OPTIONS.
11529 Since any batch api caller can send in junk item_type_code, until
11530 this procedure is executed, the item_type_code on the line_rec
11531 should not be considered as a valid one.
11532 
11533 
11534 I do not have to handle return status of explode_bill api.
11535 It raises a exception if error by BOM api, check code in OEXVCFGB.pls
11536 
11537 I guess we do not need oe_config_util.complete_configuration anymore.
11538 
11539 Explode_Bill api will take care of the model line.
11540 
11541 ASSUMPTION is classes are not shippable, hence we will not try to order
11542 the way class under a class is saved.
11543 
11544 1828866: Even if all the required fields are populated on the line,
11545 we have to always do a select from bom_explosions. This is so that
11546 we can figure out nocopy if all the items are currenlty part of the Bill.
11547 
11548 
11549 Should not come here for split lines.
11550 
11551 2221666 : order import sends option in already create model.
11552 2299910 : copy order, sort_order for MI.
11553 -------------------------------------------------------------------------*/
11554 PROCEDURE Complete_Config_Line
11555 ( p_x_line_rec       IN OUT NOCOPY OE_ORDER_PUB.Line_Rec_Type
11556  ,p_item_type        IN     NUMBER
11557  ,p_x_line_tbl       IN     OE_ORDER_PUB.Line_Tbl_Type
11558  ,p_process_partial  IN     BOOLEAN := FALSE)
11559 IS
11560   l_model_seq_id              NUMBER;
11561   l_rev_date                  DATE;
11562   l_validation_org            NUMBER := OE_SYS_PARAMETERS.VALUE
11563                                         ('MASTER_ORGANIZATION_ID');
11564   l_model_ordered_item        VARCHAR2(2000);
11565   l_bom_item_type             NUMBER;
11566   l_line_rec                  OE_Order_Pub.Line_Rec_Type;
11567   l_return_status             VARCHAR2(1);
11568   l_frozen_model_bill         VARCHAR2(1);
11569   l_old_behavior              VARCHAR2(1);
11570   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
11571   --bug4015696
11572   l_msg_count                 NUMBER;
11573   l_msg_data                  VARCHAR2(2000);
11574   l_item_identifier_type      VARCHAR2(25);
11575 BEGIN
11576 
11577   Print_Time('entering Complete_Config_Line');
11578 
11579   IF p_item_type = 1 THEN
11580 
11581     oe_config_pvt.Explode_Bill
11582     ( p_model_line_rec        => p_x_line_rec
11583      ,p_do_update             => FALSE
11584      ,p_check_effective_date  => 'N'
11585      ,x_config_effective_date => l_rev_date
11586      ,x_frozen_model_bill     => l_frozen_model_bill
11587      ,x_return_status         => l_return_status);
11588 
11589     RETURN;
11590   END IF;
11591 
11592   l_model_seq_id       :=
11593      p_x_line_tbl(p_x_line_rec.top_model_line_index).component_sequence_id;
11594 
11595   l_model_ordered_item :=
11596      p_x_line_tbl(p_x_line_rec.top_model_line_index).ordered_item;
11597 
11598   OE_Config_Util.Get_Config_Effective_Date
11599   ( p_model_line_rec        => p_x_line_tbl(p_x_line_rec.top_model_line_index)
11600    ,x_old_behavior          => l_old_behavior
11601    ,x_config_effective_date => l_rev_date
11602    ,x_frozen_model_bill     => l_frozen_model_bill);
11603 
11604   -- if only a class/options is created in exiting model,
11605   -- you need to explode the model, rare case.
11606 
11607   IF p_x_line_rec.top_model_line_index is NOT NULL AND
11608      p_x_line_rec.top_model_line_index <> FND_API.G_MISS_NUM AND
11609      nvl(p_x_line_tbl(p_x_line_rec.top_model_line_index).operation, 'A') <>
11610      OE_GLOBALS.G_OPR_CREATE
11611   THEN
11612     l_line_rec := p_x_line_tbl(p_x_line_rec.top_model_line_index);
11613 
11614     oe_config_pvt.Explode_Bill
11615     ( p_model_line_rec        => l_line_rec
11616      ,p_do_update             => FALSE
11617      ,x_config_effective_date => l_rev_date
11618      ,x_frozen_model_bill     => l_frozen_model_bill
11619      ,x_return_status         => l_return_status);
11620 
11621     l_model_seq_id       := l_line_rec.component_sequence_id;
11622     l_model_ordered_item := l_line_rec.ordered_item;
11623   END IF;
11624 
11625 
11626   IF l_debug_level  > 0 THEN
11627     oe_debug_pub.add('COMP_SEQ_ID OF MODEL: ' || L_MODEL_SEQ_ID , 2 ) ;
11628     oe_debug_pub.add('COMPLETE ITEM: '|| P_X_LINE_REC.INVENTORY_ITEM_ID ,1);
11629   END IF;
11630 
11631 
11632   BEGIN
11633 
11634     IF p_x_line_rec.config_header_id is not NULL AND
11635        p_x_line_rec.configuration_id is not NULL AND
11636        p_x_line_rec.config_header_id <> FND_API.G_MISS_NUM AND
11637        p_x_line_rec.configuration_id <> FND_API.G_MISS_NUM AND
11638        OE_CODE_CONTROL.Get_Code_Release_Level >= '110508' THEN
11639 
11640       IF l_debug_level  > 0 THEN
11641           oe_debug_pub.add(  'COMP_CONFIG VORDB: PACK H NEW LOGIC MI' , 1 ) ;
11642           oe_debug_pub.add(  'CFG_HDR '||P_X_LINE_REC.CONFIG_HEADER_ID , 3 ) ;
11643           oe_debug_pub.add(  'CFG_REV '||P_X_LINE_REC.CONFIG_REV_NBR , 3 ) ;
11644           oe_debug_pub.add(  'CFG_ID '||P_X_LINE_REC.CONFIGURATION_ID , 3 ) ;
11645       END IF;
11646 
11647       SELECT component_code, component_sequence_id, bom_sort_order,
11648              uom_code, bom_item_type
11649       INTO   p_x_line_rec.component_code, p_x_line_rec.component_sequence_id,
11650              p_x_line_rec.sort_order, p_x_line_rec.order_quantity_uom,
11651              l_bom_item_type
11652       FROM   cz_config_details_v
11653       WHERE  config_hdr_id  = p_x_line_rec.config_header_id
11654       AND    config_rev_nbr = p_x_line_rec.config_rev_nbr
11655       AND    config_item_id = p_x_line_rec.configuration_id;
11656 
11657     ELSE
11658       IF l_debug_level  > 0 THEN
11659           oe_debug_pub.add(  'COMP_CONFIG VORDB: USING BOM_EXPLOSION' , 1 ) ;
11660       END IF;
11661 
11662       IF p_x_line_rec.component_code is not NULL AND
11663          p_x_line_rec.component_code <> FND_API.G_MISS_CHAR
11664       THEN
11665         IF l_debug_level  > 0 THEN
11666             oe_debug_pub.add(  'COMPONENT CODE PASSED , SOMETHING ELSE NULL' , 3 ) ;
11667         END IF;
11668 
11669         SELECT component_code, component_sequence_id, sort_order,
11670                primary_uom_code, bom_item_type
11671         INTO   p_x_line_rec.component_code, p_x_line_rec.component_sequence_id,
11672                p_x_line_rec.sort_order, p_x_line_rec.order_quantity_uom,
11673                l_bom_item_type
11674         FROM   bom_explosions
11675         WHERE  component_item_id    = p_x_line_rec.inventory_item_id
11676         AND    explosion_type       = Oe_Config_Util.OE_BMX_OPTION_COMPS
11677         AND    top_bill_sequence_id = l_model_seq_id
11678         AND    effectivity_date     <= l_rev_date
11679         AND    disable_date         >  l_rev_date
11680         AND    organization_id      =  l_validation_org
11681         AND    component_code       =  p_x_line_rec.component_code;
11682 
11683       ELSE
11684         IF l_debug_level  > 0 THEN
11685             oe_debug_pub.add(  'COMPONENT CODE NOT PASSED' , 3 ) ;
11686         END IF;
11687 
11688         SELECT component_code, component_sequence_id, sort_order,
11689                primary_uom_code, bom_item_type
11690         INTO   p_x_line_rec.component_code, p_x_line_rec.component_sequence_id,
11691                p_x_line_rec.sort_order, p_x_line_rec.order_quantity_uom,
11692                l_bom_item_type
11693         FROM   bom_explosions
11694         WHERE  component_item_id    = p_x_line_rec.inventory_item_id
11695         AND    explosion_type       = Oe_Config_Util.OE_BMX_OPTION_COMPS
11696         AND    top_bill_sequence_id = l_model_seq_id
11697         AND    effectivity_date     <= l_rev_date
11698         AND    disable_date         > l_rev_date
11699         AND    organization_id      =  l_validation_org;
11700       END IF;
11701     END IF; -- if configuration_id is passed.
11702 
11703   EXCEPTION
11704     WHEN NO_DATA_FOUND THEN
11705       IF l_debug_level  > 0 THEN
11706           oe_debug_pub.add(  'SELECT COMP_CODE FAILED , NO DATA FOUND ' , 1 ) ;
11707           oe_debug_pub.add(  'ITEM: '|| P_X_LINE_REC.INVENTORY_ITEM_ID , 1 ) ;
11708       END IF;
11709       FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_ITEM_NOT_IN_BILL');
11710       --bug4015696
11711       IF p_x_line_rec.ordered_item IS NULL OR
11712          p_x_line_rec.ordered_item = FND_API.G_MISS_CHAR THEN
11713 	 IF p_x_line_rec.item_identifier_type = FND_API.G_MISS_CHAR THEN
11714 	    l_item_identifier_type := NULL;
11715 	 ELSE
11716 	    l_item_identifier_type := p_x_line_rec.item_identifier_type;
11717 	 END IF;
11718 	 OE_OE_FORM_LINE.Get_Ordered_Item
11719 	 (  x_return_status        => l_return_status
11720 	   ,x_msg_count            => l_msg_count
11721 	   ,x_msg_data             => l_msg_data
11722 	   ,p_item_identifier_type => l_item_identifier_type
11723 	   ,p_inventory_item_id    => p_x_line_rec.inventory_item_id
11724 	   ,p_ordered_item_id      => p_x_line_rec.ordered_item_id
11725 	   ,p_sold_to_org_id       => p_x_line_rec.sold_to_org_id
11726 	   ,x_ordered_item         => p_x_line_rec.ordered_item   );
11727 	 IF p_x_line_rec.ordered_item IS NULL OR
11728 	    p_x_line_rec.ordered_item = FND_API.G_MISS_CHAR THEN
11729 	    FND_MESSAGE.Set_Token('ITEM',p_x_line_rec.inventory_item_id);
11730 	 ELSE
11731 	    FND_MESSAGE.Set_Token('ITEM',p_x_line_rec.ordered_item);
11732 	 END IF;
11733       ELSE
11734          FND_MESSAGE.Set_Token('ITEM', p_x_line_rec.ordered_item);
11735       END IF;
11736       FND_MESSAGE.Set_Token('MODEL', nvl(l_model_ordered_item,l_line_rec.inventory_item_id));
11737       oe_msg_pub.add;
11738 
11739       IF p_process_partial THEN
11740         IF l_debug_level  > 0 THEN /* Bug # 4036765 */
11741             oe_debug_pub.add(  'PROCESS PARTIAL IS TRUE' , 3 ) ;
11742         END IF;
11743         p_x_line_rec.return_status := FND_API.G_RET_STS_ERROR;
11744         p_x_line_rec.operation     := OE_GLOBALS.G_OPR_NONE;
11745         OE_GLOBALS.G_FAIL_ORDER_IMPORT := TRUE; /* Bug # 4036765 */
11746       ELSE
11747         IF l_debug_level  > 0 THEN
11748             oe_debug_pub.add(  'PROCESS PARTIAL IS NOT TRUE' , 3 ) ;
11749         END IF;
11750         RAISE FND_API.G_EXC_ERROR;
11751       END IF;
11752 
11753     WHEN TOO_MANY_ROWS THEN
11754       IF l_debug_level  > 0 THEN
11755           oe_debug_pub.add(  'SELECT COMP_CODE FAILED , TOO_MANY ROWS ' , 1 ) ;
11756           oe_debug_pub.add(  'ITEM: '|| P_X_LINE_REC.INVENTORY_ITEM_ID , 1 ) ;
11757       END IF;
11758 
11759       FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_AMBIGUITY');
11760       FND_MESSAGE.Set_Token('COMPONENT', p_x_line_rec.ordered_item);
11761       FND_MESSAGE.Set_Token('MODEL', nvl(l_model_ordered_item,l_line_rec.inventory_item_id));
11762       oe_msg_pub.add;
11763       RAISE FND_API.G_EXC_ERROR;
11764 
11765     WHEN OTHERS THEN
11766       IF l_debug_level  > 0 THEN
11767           oe_debug_pub.add(  'SELECT COMP_CODE FAILED , OTHERS ' , 1 ) ;
11768           oe_debug_pub.add(  'ITEM: '|| P_X_LINE_REC.INVENTORY_ITEM_ID , 1 ) ;
11769       END IF;
11770       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11771   END;
11772 
11773 
11774   IF l_bom_item_type = 2 OR
11775      l_bom_item_type = 1 THEN
11776     IF l_debug_level  > 0 THEN
11777         oe_debug_pub.add(  'THIS IS A CLASS' , 5 ) ;
11778     END IF;
11779     p_x_line_rec.item_type_code := OE_GLOBALS.G_ITEM_CLASS;
11780 
11781   ELSIF l_bom_item_type = 4 THEN
11782     IF l_debug_level  > 0 THEN
11783         oe_debug_pub.add(  'THIS IS A OPTION/KIT' , 1 ) ;
11784     END IF;
11785   ELSE
11786     IF l_debug_level  > 0 THEN
11787         oe_debug_pub.add(  'INVALID ITEM TYPE' , 1 ) ;
11788     END IF;
11789   END IF;
11790 
11791   IF l_debug_level  > 0 THEN
11792     oe_debug_pub.add(  'HDR/REV/ID '|| P_X_LINE_REC.CONFIG_HEADER_ID
11793     || P_X_LINE_REC.CONFIG_REV_NBR || P_X_LINE_REC.CONFIGURATION_ID ,1);
11794   END IF;
11795 
11796   Print_Time('leaving Complete_Config_Line');
11797 
11798 EXCEPTION
11799   WHEN OTHERS THEN
11800     IF l_debug_level  > 0 THEN
11801         oe_debug_pub.add(  'COMPLETE_CONFIG_LINE EXCEPTIION '|| SQLERRM , 1 ) ;
11802     END IF;
11803     RAISE;
11804 END Complete_Config_Line;
11805 
11806 
11807 /*-------------------------------------------------------------------------
11808 PRODEDURE Get_Missing_Class_Lines
11809 
11810 Do not call if p_option_lines does not have any lines.
11811 just put index in the p_options_tbl, get a rec at a time.
11812 p_options_tbl.line_id is actually the index of option lines.
11813 
11814 In this procedure we will get all the missing classes, for all the
11815 options in one call.
11816 We decided to loop over the p_options_index_tbl instead of calling
11817 this procedure per option line because,
11818   1) v.imp: switching modes back and forth between the class save vs
11819      option save is complicated to code, debug and maintain.
11820   2) p_options_index_tbl is table of numbers, not expensive, also
11821 
11822 we are making use of the fact that the class lines are already
11823 saved. This fact and the component_code field is used to decide
11824 if some of the parents are missing and add them to the lines table.
11825 
11826 when we get out nocopy of the procedure, the x_class_index contains
11827 
11828 the index of the first newly added class, we start looping through
11829 the lines table at thei index. if x_class_index is null, it means
11830 no new classes were added.
11831 
11832 -------------------------------------------------------------------------*/
11833 
11834 PROCEDURE Get_Missing_Class_Lines
11835 ( p_x_line_tbl         IN  OUT NOCOPY OE_ORDER_PUB.Line_Tbl_Type
11836  ,p_options_index_tbl  IN  OE_OPTION_INDEX_TBL_TYPE
11837 ,x_class_index OUT NOCOPY NUMBER
11838 
11839 ,x_class_count OUT NOCOPY NUMBER)
11840 
11841 IS
11842   I                      NUMBER;
11843   J                      NUMBER;
11844   l_add_parent           BOOLEAN;
11845   l_index                NUMBER;
11846   l_component_code       VARCHAR2(1000);
11847   l_model_quantity       NUMBER;
11848   l_model_seq_id         NUMBER;
11849   l_rev_date             DATE;
11850   l_validation_org       NUMBER := OE_SYS_PARAMETERS.VALUE
11851                                  ('MASTER_ORGANIZATION_ID');
11852   l_ato_line_id          NUMBER;
11853   l_option_index         NUMBER;
11854   l_remember_index       NUMBER;
11855   l_top_model_line_index NUMBER;
11856   l_bom_item_type        NUMBER;
11857   l_frozen_model_bill    VARCHAR2(1);
11858   l_old_behavior         VARCHAR2(1);
11859   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
11860 BEGIN
11861   Print_Time('entering Get_Missing_Class_Lines');
11862 
11863 
11864   IF OE_Config_Util.G_Config_UI_Used = 'Y' THEN
11865     IF l_debug_level  > 0 THEN
11866         oe_debug_pub.add(  'CONFIGURATOR/OW USED , SHOULD NOT COME HERE' , 1 ) ;
11867     END IF;
11868     RAISE FND_API.G_EXC_ERROR;
11869   END IF;
11870 
11871 
11872   l_index          := p_x_line_tbl.LAST;
11873   l_remember_index := l_index;
11874   I                := p_options_index_tbl.FIRST;
11875   J                := l_index;
11876 
11877   WHILE I is not NULL
11878   LOOP
11879     l_option_index := p_options_index_tbl(I);
11880 
11881     IF l_debug_level  > 0 THEN
11882       oe_debug_pub.add(  'I '|| I || ' '
11883       || P_X_LINE_TBL ( L_OPTION_INDEX ) .TOP_MODEL_LINE_ID , 3 ) ;
11884       oe_debug_pub.add(  L_OPTION_INDEX || ' '
11885       || P_X_LINE_TBL ( L_OPTION_INDEX ) .COMPONENT_CODE , 3 ) ;
11886     END IF;
11887 
11888     l_component_code := SUBSTR(p_x_line_tbl(l_option_index).component_code, 1,
11889              (INSTR(p_x_line_tbl(l_option_index).component_code, '-', -1) -1));
11890 
11891     WHILE l_component_code is not NULL
11892     LOOP
11893 
11894       IF l_debug_level  > 0 THEN
11895           oe_debug_pub.add(  'CHECK IF EXIST: ' || L_COMPONENT_CODE , 1 ) ;
11896       END IF;
11897 
11898       BEGIN
11899 
11900         SELECT ato_line_id
11901         INTO   l_ato_line_id
11902         FROM   oe_order_lines
11903         WHERE  top_model_line_id
11904                = p_x_line_tbl(l_option_index).top_model_line_id
11905         AND    component_code = l_component_code
11906         AND    open_flag = 'Y';
11907 
11908       EXCEPTION
11909         WHEN no_data_found THEN
11910           IF l_debug_level  > 0 THEN
11911               oe_debug_pub.add(  'NO DATA FOUND' , 3 ) ;
11912           END IF;
11913 
11914           l_add_parent := TRUE;
11915 
11916           IF l_remember_index <> l_index THEN
11917             J            := l_remember_index + 1;
11918             WHILE J is NOT NULL
11919             LOOP
11920              IF p_x_line_tbl(J).component_code = l_component_code THEN
11921                IF l_debug_level  > 0 THEN
11922                    oe_debug_pub.add(  'DO NOT ADD' , 3 ) ;
11923                END IF;
11924                l_add_parent := FALSE;
11925              END IF;
11926              J := p_x_line_tbl.NEXT(J);
11927             END LOOP;
11928 
11929           END IF;
11930 
11931           IF l_add_parent THEN
11932             l_index := l_index + 1;
11933 
11934             p_x_line_tbl(l_index) := OE_Order_Pub.G_Miss_Line_Rec;
11935 
11936             p_x_line_tbl(l_index).operation      := OE_GLOBALS.G_OPR_CREATE;
11937             p_x_line_tbl(l_index).component_code := l_component_code;
11938             p_x_line_tbl(l_index).top_model_line_id
11939                   := p_x_line_tbl(l_option_index).top_model_line_id;
11940             p_x_line_tbl(l_index).header_id
11941                   :=  p_x_line_tbl(l_option_index).header_id;
11942 
11943 
11944             IF p_x_line_tbl(l_option_index).config_header_id is not NULL AND
11945                p_x_line_tbl(l_option_index).configuration_id is not NULL AND
11946                p_x_line_tbl(l_option_index).config_header_id <>
11947                                             FND_API.G_MISS_NUM AND
11948                p_x_line_tbl(l_option_index).configuration_id <>
11949                                             FND_API.G_MISS_NUM AND
11950                OE_CODE_CONTROL.Get_Code_Release_Level >= '110508' THEN
11951 
11952               IF l_debug_level  > 0 THEN
11953                   oe_debug_pub.add(  'VORDB: PACK H NEW LOGIC MI' , 1 ) ;
11954               END IF;
11955 
11956               IF l_debug_level  > 0 THEN
11957                 oe_debug_pub.add('CFG_HDR '
11958                 ||P_X_LINE_TBL ( L_OPTION_INDEX ) .CONFIG_HEADER_ID , 3 ) ;
11959                 oe_debug_pub.add('CFG_REV '
11960                 ||P_X_LINE_TBL ( L_OPTION_INDEX ) .CONFIG_REV_NBR , 3 ) ;
11961                 oe_debug_pub.add('CFG_ID '
11962                 ||P_X_LINE_TBL ( L_OPTION_INDEX ) .CONFIGURATION_ID , 3 ) ;
11963               END IF;
11964 
11965               BEGIN
11966                 SELECT component_sequence_id, inventory_item_id,
11967                        bom_sort_order, uom_code, quantity, bom_item_type
11968                 INTO  p_x_line_tbl(l_index).component_sequence_id,
11969                       p_x_line_tbl(l_index).inventory_item_id,
11970                       p_x_line_tbl(l_index).sort_order,
11971                       p_x_line_tbl(l_index).order_quantity_uom,
11972                       p_x_line_tbl(l_index).ordered_quantity,
11973                       l_bom_item_type
11974                 FROM  cz_config_details_v
11975                 WHERE component_code = l_component_code
11976                 AND   config_hdr_id
11977                         = p_x_line_tbl(l_option_index).config_header_id
11978                 AND   config_rev_nbr
11979                         = p_x_line_tbl(l_option_index).config_rev_nbr
11980                 AND   config_item_id
11981                         = p_x_line_tbl(l_option_index).configuration_id;
11982               EXCEPTION
11983                 WHEN TOO_MANY_ROWS THEN
11984                   IF l_debug_level  > 0 THEN
11985                       oe_debug_pub.add(  'CZ TOO_MANY_ROWS ' , 1 ) ;
11986                   END IF;
11987                   RAISE;
11988                 WHEN NO_DATA_FOUND THEN
11989                   IF l_debug_level  > 0 THEN
11990                       oe_debug_pub.add(  'CZ NO_DATA_FOUND' , 1 ) ;
11991                   END IF;
11992                   RAISE;
11993                 WHEN OTHERS THEN
11994                   IF l_debug_level  > 0 THEN
11995                       oe_debug_pub.add(  'CZ OTHERS' , 1 ) ;
11996                   END IF;
11997                   RAISE;
11998               END;
11999             ELSE
12000               IF l_debug_level  > 0 THEN
12001                   oe_debug_pub.add(  'VORDB: USE BOX_EXPLOSINS' , 3 ) ;
12002               END IF;
12003 
12004               IF l_rev_date is NULL THEN
12005 
12006                 l_top_model_line_index
12007                    := p_x_line_tbl(l_option_index).top_model_line_index;
12008 
12009                 IF l_top_model_line_index is NOT NULL THEN
12010                   l_model_quantity
12011                    := p_x_line_tbl(l_top_model_line_index).ordered_quantity;
12012                   l_model_seq_id
12013                 := p_x_line_tbl(l_top_model_line_index).component_sequence_id;
12014 
12015                   OE_Config_Util.Get_Config_Effective_Date
12016                   ( p_model_line_rec    => p_x_line_tbl(l_top_model_line_index)
12017                    ,x_old_behavior          => l_old_behavior
12018                    ,x_config_effective_date => l_rev_date
12019                    ,x_frozen_model_bill     => l_frozen_model_bill);
12020 
12021                 ELSE
12022 
12023                   SELECT ordered_quantity, component_sequence_id
12024                   INTO   l_model_quantity, l_model_seq_id
12025                   FROM   oe_order_lines
12026                   WHERE  line_id =
12027                           p_x_line_tbl(l_option_index).top_model_line_id;
12028 
12029 
12030                   OE_Config_Util.Get_Config_Effective_Date
12031                   ( p_model_line_id         =>
12032                     p_x_line_tbl(l_option_index).top_model_line_id
12033                    ,x_old_behavior          => l_old_behavior
12034                    ,x_config_effective_date => l_rev_date
12035                    ,x_frozen_model_bill     => l_frozen_model_bill);
12036 
12037                 END IF;
12038 
12039               END IF; -- if rev date null
12040 
12041                 SELECT component_sequence_id, component_item_id, sort_order,
12042                        primary_uom_code, EXTENDED_QUANTITY * l_model_quantity,
12043                        bom_item_type
12044                 INTO  p_x_line_tbl(l_index).component_sequence_id,
12045                       p_x_line_tbl(l_index).inventory_item_id,
12046                       p_x_line_tbl(l_index).sort_order,
12047                       p_x_line_tbl(l_index).order_quantity_uom,
12048                       p_x_line_tbl(l_index).ordered_quantity,
12049                       l_bom_item_type
12050                 FROM  bom_explosions be
12051                 WHERE be.explosion_type  = OE_Config_Util.OE_BMX_OPTION_COMPS
12052                 AND   be.top_bill_sequence_id = l_model_seq_id
12053                 AND   be.plan_level > 0
12054                 AND   be.effectivity_date <= l_rev_date
12055                 AND   be.disable_date > l_rev_date
12056                 AND   be.component_code = l_component_code
12057                 AND   rownum = 1;
12058 
12059             END IF; -- if pack H
12060 
12061             IF l_bom_item_type = 2 OR
12062                l_bom_item_type = 1 THEN
12063                IF l_debug_level  > 0 THEN
12064                    oe_debug_pub.add(  'THIS IS A CLASS' , 5 ) ;
12065                END IF;
12066                p_x_line_tbl(l_index).item_type_code
12067                          := OE_GLOBALS.G_ITEM_CLASS;
12068             END IF;
12069 
12070             IF l_debug_level  > 0 THEN
12071                 oe_debug_pub.add(  'GET ORDERED ITEM NAME' , 3 ) ;
12072             END IF;
12073 
12074             BEGIN
12075               SELECT concatenated_segments
12076               INTO   p_x_line_tbl(l_index).ordered_item
12077               FROM   MTL_SYSTEM_ITEMS_KFV
12078               WHERE  inventory_item_id = p_x_line_tbl(I).inventory_item_id
12079               AND    organization_id = l_validation_org;
12080             EXCEPTION
12081               WHEN NO_DATA_FOUND THEN
12082                 IF l_debug_level  > 0 THEN
12083                     oe_debug_pub.add(  'NAME OF THE ITEM NOT FOUND' , 1 ) ;
12084                 END IF;
12085                 RAISE FND_API.G_EXC_ERROR;
12086             END;
12087 
12088             IF l_debug_level  > 0 THEN
12089               oe_debug_pub.add
12090               ('ADDED'||P_X_LINE_TBL(L_INDEX).INVENTORY_ITEM_ID,3);
12091             END IF;
12092 
12093           END IF; -- if add_parent = true
12094 
12095         WHEN TOO_MANY_ROWS THEN
12096           IF p_x_line_tbl(l_option_index).config_header_id is not NULL AND
12097              p_x_line_tbl(l_option_index).configuration_id is not NULL AND
12098              OE_CODE_CONTROL.Get_Code_Release_Level >= '110508' THEN
12099                IF l_debug_level  > 0 THEN
12100                  oe_debug_pub.add
12101                  ('TOO MANY ROWS IN MISSING_CLASSES: PACK H NEW MI',1);
12102                END IF;
12103           ELSE
12104             FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_MI_NOT_ALLOWED');
12105             FND_MESSAGE.SET_TOKEN
12106             ('MODEL', nvl(p_x_line_tbl(l_top_model_line_index).ordered_item,
12107                               p_x_line_tbl(l_top_model_line_index).inventory_item_id));
12108             FND_MESSAGE.SET_TOKEN('LINE_NUMBER',
12109                        p_x_line_tbl(l_top_model_line_index).line_number ||
12110                        p_x_line_tbl(l_top_model_line_index).shipment_number);
12111             OE_MSG_PUB.Add;
12112             RAISE;
12113           END IF;
12114 
12115         WHEN OTHERS THEN
12116           IF l_debug_level  > 0 THEN
12117               oe_debug_pub.add(  'OTHERS IN MISSING_CLASSES '|| SQLERRM , 1 ) ;
12118           END IF;
12119           RAISE;
12120       END; -- to check if this comp exists
12121 
12122       l_component_code := SUBSTR(l_component_code, 1,
12123                                 (INSTR(l_component_code, '-', -1) -1));
12124 
12125     END LOOP;
12126 
12127     I  := p_options_index_tbl.NEXT(I);
12128 
12129   END LOOP;
12130 
12131   IF l_index <> l_remember_index THEN
12132     x_class_index  := l_remember_index + 1;
12133   END IF;
12134 
12135   x_class_count := l_index - l_remember_index;
12136 
12137   Print_Time('leaving Get_Missing_Class_Lines '||  x_class_count);
12138 
12139 EXCEPTION
12140   WHEN OTHERS THEN
12141     IF l_debug_level  > 0 THEN
12142       oe_debug_pub.add('ERROR IN GET_MISSING_CLASS_LINES '|| SQLERRM,1);
12143     END IF;
12144     RAISE;
12145 END Get_Missing_Class_Lines;
12146 
12147 
12148 END OE_Order_PVT;