DBA Data[Home] [Help]

PACKAGE BODY: APPS.OE_OE_PRICING_AVAILABILITY

Source


1 PACKAGE BODY oe_oe_pricing_availability AS
2 /* $Header: OEXFPRAB.pls 120.10.12010000.8 2008/11/26 17:27:27 vmachett ship $ */
3 
4   --Global variables
5 
6   G_PKG_NAME         CONSTANT VARCHAR2(30) := 'oe_oe_pricing_availability';
7   G_ATP_TBL          OE_ATP.atp_tbl_type;
8   g_order_source_id  CONSTANT NUMBER :=26;
9   G_line_id          CONSTANT NUMBER :=1244;
10   G_atp_line_id      CONSTANT NUMBER := -9987;
11   g_header_id        CONSTANT NUMBER :=2345;
12   g_hsecs            number;
13   g_place            varchar2(100);
14   g_total            number :=0;
15   g_total2           number ;
16   global_line_index number;
17   g_upgrade_item_exists varchar2(1):='N';
18   g_upgrade_item_id number;
19   g_upgrade_order_qty_uom varchar2(30);
20   g_upgrade_ship_from_org_id number;
21 
22    --Global Tables required for temp_table population.
23 
24   G_LINE_INDEX_tbl               QP_PREQ_GRP.pls_integer_type;
25   G_LINE_TYPE_CODE_TBL           QP_PREQ_GRP.VARCHAR_TYPE;
26   G_PRICING_EFFECTIVE_DATE_TBL   QP_PREQ_GRP.DATE_TYPE   ;
27   G_ACTIVE_DATE_FIRST_TBL        QP_PREQ_GRP.DATE_TYPE   ;
28   G_ACTIVE_DATE_FIRST_TYPE_TBL   QP_PREQ_GRP.VARCHAR_TYPE;
29   G_ACTIVE_DATE_SECOND_TBL       QP_PREQ_GRP.DATE_TYPE   ;
30   G_ACTIVE_DATE_SECOND_TYPE_TBL  QP_PREQ_GRP.VARCHAR_TYPE ;
31   G_LINE_QUANTITY_TBL            QP_PREQ_GRP.NUMBER_TYPE ;
32   G_LINE_UOM_CODE_TBL            QP_PREQ_GRP.VARCHAR_TYPE;
33   G_REQUEST_TYPE_CODE_TBL        QP_PREQ_GRP.VARCHAR_TYPE;
34   G_PRICED_QUANTITY_TBL          QP_PREQ_GRP.NUMBER_TYPE;
35   G_UOM_QUANTITY_TBL             QP_PREQ_GRP.NUMBER_TYPE;
36   G_PRICED_UOM_CODE_TBL          QP_PREQ_GRP.VARCHAR_TYPE;
37   G_CURRENCY_CODE_TBL            QP_PREQ_GRP.VARCHAR_TYPE;
38   G_UNIT_PRICE_TBL               QP_PREQ_GRP.NUMBER_TYPE;
39   G_PERCENT_PRICE_TBL            QP_PREQ_GRP.NUMBER_TYPE;
40   G_ADJUSTED_UNIT_PRICE_TBL      QP_PREQ_GRP.NUMBER_TYPE;
41   G_UPD_ADJUSTED_UNIT_PRICE_TBL  QP_PREQ_GRP.NUMBER_TYPE;
42   G_PROCESSED_FLAG_TBL           QP_PREQ_GRP.VARCHAR_TYPE;
43   G_PRICE_FLAG_TBL               QP_PREQ_GRP.VARCHAR_TYPE;
44   G_LINE_ID_TBL                  QP_PREQ_GRP.NUMBER_TYPE;
45   G_PROCESSING_ORDER_TBL         QP_PREQ_GRP.PLS_INTEGER_TYPE;
46   G_ROUNDING_FACTOR_TBL          QP_PREQ_GRP.PLS_INTEGER_TYPE;
47   G_ROUNDING_FLAG_TBL            QP_PREQ_GRP.FLAG_TYPE;
48   G_QUALIFIERS_EXIST_FLAG_TBL    QP_PREQ_GRP.VARCHAR_TYPE;
49   G_PRICING_ATTRS_EXIST_FLAG_TBL QP_PREQ_GRP.VARCHAR_TYPE;
50   G_PRICE_LIST_ID_TBL            QP_PREQ_GRP.NUMBER_TYPE;
51   G_PL_VALIDATED_FLAG_TBL        QP_PREQ_GRP.VARCHAR_TYPE;
52   G_PRICE_REQUEST_CODE_TBL       QP_PREQ_GRP.VARCHAR_TYPE;
53   G_USAGE_PRICING_TYPE_TBL       QP_PREQ_GRP.VARCHAR_TYPE;
54   G_LINE_CATEGORY_TBL            QP_PREQ_GRP.VARCHAR_TYPE;
55   G_PRICING_STATUS_CODE_tbl      QP_PREQ_GRP.VARCHAR_TYPE;
56   G_PRICING_STATUS_TEXT_tbl      QP_PREQ_GRP.VARCHAR_TYPE;
57   G_ATTR_LINE_INDEX_tbl          QP_PREQ_GRP.PLS_INTEGER_TYPE;
58   G_ATTR_LINE_DETAIL_INDEX_tbl   QP_PREQ_GRP.PLS_INTEGER_TYPE;
59   G_ATTR_VALIDATED_FLAG_tbl      QP_PREQ_GRP.VARCHAR_TYPE;
60   G_ATTR_PRICING_CONTEXT_tbl     QP_PREQ_GRP.VARCHAR_TYPE;
61   G_ATTR_PRICING_ATTRIBUTE_tbl   QP_PREQ_GRP.VARCHAR_TYPE;
62   G_ATTR_ATTRIBUTE_LEVEL_tbl	 QP_PREQ_GRP.VARCHAR_TYPE;
63   G_ATTR_ATTRIBUTE_TYPE_tbl	 QP_PREQ_GRP.VARCHAR_TYPE;
64   G_ATTR_APPLIED_FLAG_tbl	 QP_PREQ_GRP.VARCHAR_TYPE;
65   G_ATTR_PRICING_STATUS_CODE_tbl QP_PREQ_GRP.VARCHAR_TYPE;
66   G_ATTR_PRICING_ATTR_FLAG_tbl 	 QP_PREQ_GRP.VARCHAR_TYPE;
67   G_ATTR_LIST_HEADER_ID_tbl	 QP_PREQ_GRP.NUMBER_TYPE;
68   G_ATTR_LIST_LINE_ID_tbl	 QP_PREQ_GRP.NUMBER_TYPE;
69   G_ATTR_VALUE_FROM_tbl          QP_PREQ_GRP.VARCHAR_TYPE;
70   G_ATTR_SETUP_VALUE_FROM_tbl    QP_PREQ_GRP.VARCHAR_TYPE;
71   G_ATTR_VALUE_TO_tbl     	 QP_PREQ_GRP.VARCHAR_TYPE;
72   G_ATTR_SETUP_VALUE_TO_tbl	 QP_PREQ_GRP.VARCHAR_TYPE;
73   G_ATTR_GROUPING_NUMBER_tbl 	 QP_PREQ_GRP.PLS_INTEGER_TYPE;
74   G_ATTR_NO_QUAL_IN_GRP_tbl      QP_PREQ_GRP.PLS_INTEGER_TYPE;
75   G_ATTR_COMP_OPERATOR_TYPE_tbl  QP_PREQ_GRP.VARCHAR_TYPE;
76   G_ATTR_PRICING_STATUS_TEXT_tbl QP_PREQ_GRP.VARCHAR_TYPE;
77   G_ATTR_QUAL_PRECEDENCE_tbl     QP_PREQ_GRP.PLS_INTEGER_TYPE;
78   G_ATTR_DATATYPE_tbl            QP_PREQ_GRP.VARCHAR_TYPE;
79   G_ATTR_QUALIFIER_TYPE_tbl      QP_PREQ_GRP.VARCHAR_TYPE;
80   G_ATTR_PRODUCT_UOM_CODE_TBL    QP_PREQ_GRP.VARCHAR_TYPE;
81   G_ATTR_EXCLUDER_FLAG_TBL       QP_PREQ_GRP.VARCHAR_TYPE;
82   G_ATTR_PRICING_PHASE_ID_TBL    QP_PREQ_GRP.PLS_INTEGER_TYPE;
83   G_ATTR_INCOM_GRP_CODE_TBL      QP_PREQ_GRP.VARCHAR_TYPE;
84   G_ATTR_LDET_TYPE_CODE_TBL      QP_PREQ_GRP.VARCHAR_TYPE;
85   G_ATTR_MODIFIER_LEVEL_CODE_TBL QP_PREQ_GRP.VARCHAR_TYPE;
86   G_ATTR_PRIMARY_UOM_FLAG_TBL    QP_PREQ_GRP.VARCHAR_TYPE;
87   G_CATCHWEIGHT_QTY_TBL          QP_PREQ_GRP.NUMBER_TYPE;
88   G_ACTUAL_ORDER_QTY_TBL         QP_PREQ_GRP.NUMBER_TYPE;
89   G_IS_THERE_FREEZE_OVERRIDE  Boolean:=TRUE;
90 
91 
92 --g_panda_rec_table panda_rec_table;
93   g_promotions_tbl Promotions_Tbl;
94   g_manual_modifier_tbl Manual_modifier_tbl;
95   g_modf_attributes_tbl Modifier_attributes_Tbl;
96   g_modf_rel_Tbl Modifier_assoc_Tbl;
97   g_enforce_price_flag varchar2(2) :='N';
98   g_applied_manual_tbl oe_oe_pricing_availability.number_type;
99 
100 --Start of bug#7380336
101   G_PR_AV  VARCHAR(20):= 'N';
102 
103  	   FUNCTION  IS_PRICING_AVAILIBILITY RETURN VARCHAR2
104  	   IS
105 
106  	    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
107 
108  	   BEGIN
109  	   IF l_debug_level > 0 THEN
110  	      oe_debug_pub.add('In function IS_PRICING_AVAILIBILITY',1);
111  	      oe_debug_pub.add('G_PR_AV ' || G_PR_AV);
112 
113  	   END IF;
114  	   IF G_PR_AV = 'Y' THEN
115  	     RETURN('Y') ;
116  	   ELSE
117  	     G_PR_AV := 'N';
118  	     RETURN('N');
119  	   END IF;
120  	   G_PR_AV := 'N';
121  	   RETURN('N')   ;
122 
123  	   END  IS_PRICING_AVAILIBILITY;    --End of bug#7380336
124 
125 
126 Procedure Initialize_mrp_record
127          ( p_x_atp_rec IN  OUT NOCOPY MRP_ATP_PUB.ATP_Rec_Typ
128           ,l_count     IN  NUMBER) IS
129 
130 l_return_status varchar2(10);
131 
132 --
133 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
134 --
135 BEGIN
136 
137   IF l_debug_level  > 0 THEN
138       oe_debug_pub.add(  'EXTENDING THE TABLE BY ' || L_COUNT , 5 ) ;
139   END IF;
140 
141   MSC_SATP_FUNC.Extend_ATP
142   (p_atp_tab       => p_x_atp_rec,
143    p_index         => l_count,
144    x_return_status => l_return_status);
145 
146 EXCEPTION
147 
148    WHEN OTHERS THEN
149 
150       IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
151 	 OE_MSG_PUB.Add_Exc_Msg
152             (   G_PKG_NAME,
153 		'Initialize_mrp_record');
154 END IF;
155 
156 END Initialize_mrp_record;
157 
158 
159 Procedure Check_Results_from_rec (
160         in_global_orgs in varchar2
161        ,p_atp_rec         IN  MRP_ATP_PUB.ATP_Rec_Typ
162 ,x_return_status OUT NOCOPY VARCHAR2
163 
164 ,x_msg_count OUT NOCOPY NUMBER
165 
166 ,x_msg_data OUT NOCOPY VARCHAR2
167 
168 ,x_error_message OUT NOCOPY varchar2
169 
170                                 )IS
171 
172 atp_count          NUMBER := 1;
173 J                  NUMBER := 1;
174 l_explanation      VARCHAR2(80);
175 l_type_code        VARCHAR2(30);
176 l_ship_set_name    VARCHAR2(30);
177 l_arrival_set_name VARCHAR2(30);
178 l_arrival_date     DATE := NULL;
179 l_sch_action       varchar2(100) := 'OESCH_ACT_ATP_CHECK';
180 --
181 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
182 --
183 l_lookup_type VARCHAR2(50); -- added for bug 3776769
184 l_lookup_code NUMBER;
185 
186 BEGIN
187 
188   x_return_status :=  'S';
189   l_lookup_type := 'MTL_DEMAND_INTERFACE_ERRORS';  -- added for bug 3776769
190 
191   IF l_debug_level  > 0 AND
192     p_atp_rec.error_code.COUNT > 0 THEN
193     oe_debug_pub.add(  '2. ENTERING CHECK_RESULTS ERROR_CODE='|| P_ATP_REC.ERROR_CODE ( J ) ||
194 		       ' IN_GLOBAL_ORGS='||IN_GLOBAL_ORGS ) ;
195   END IF;
196 
197   IF p_atp_rec.error_code.COUNT > 0 AND
198      p_atp_rec.error_code(J) <> 0 AND
199         p_atp_rec.error_code(J) <> -99  AND -- Multi org changes.
200         p_atp_rec.error_code(J) <> 150 -- to fix bug 1880166
201 
202      THEN
203 
204       IF l_debug_level  > 0 THEN
205           oe_debug_pub.add(  'ERROR FROM MRP: ' || P_ATP_REC.ERROR_CODE ( J ) , 1 ) ;
206       END IF;
207 
208       IF p_atp_rec.error_code(J) = 80 THEN
209 
210           l_explanation := null;
211           l_lookup_code := 80;
212           select meaning
213             into l_explanation
214             from mfg_lookups
215            where lookup_type = l_lookup_type
216              and lookup_code = l_lookup_code;   -- added for bug 3776769
217 
218 
219           IF l_debug_level  > 0 THEN
220               oe_debug_pub.add(  'SETTING THE MESSAGE FOR OE_SCH_NO_SOURCE' ) ;
221           END IF;
222 
223           IF in_global_orgs = 'N' then
224 
225             FND_MESSAGE.SET_NAME('ONT','ONT_AVAIL_NO_SOURCES');
226             OE_MSG_PUB.Add;
227           ELSE
228             x_error_message := l_explanation;
229           END IF;
230 
231       ELSE
232 
233           IF l_debug_level  > 0 THEN
234               oe_debug_pub.add(  'SCH FAILED ERROR CODE='||P_ATP_REC.ERROR_CODE ( J ) ) ;
235           END IF;
236 
237           l_explanation := null;
238           l_lookup_code := p_atp_rec.error_code(J) ;   -- added for bug 3776769
239           select meaning
240             into l_explanation
241             from mfg_lookups
242            where lookup_type = l_lookup_type
243              and lookup_code =l_lookup_code;    -- added for bug 3776769
244 
245           IF p_atp_rec.error_code(J) = 19 THEN
246              -- This error code is given for those lines which are
247              -- in a group and whose scheduling failed due to some other lines.
248              -- We do not want to give this out as a message.
249              null;
250 
251           ELSIF p_atp_rec.error_code(J) = 61 THEN
252 
253             -- setting the status flag to partial for ATP not applicable
254             IF l_debug_level  > 0 THEN
255                 oe_debug_pub.add(  'ERROR CODE = 61' ) ;
256             END IF;
257 
258             x_return_status := 'P';
259             x_error_message := l_explanation;
260 
261 	    /* Added the following code to fix the bug 3245976 - issue 8 */
262 
263           ELSIF p_atp_rec.error_code(J) = 53 THEN
264 
265             x_return_status := 'E';
266             IF l_debug_level  > 0 THEN
267                 oe_debug_pub.add(  'ERROR CODE = 53' ) ;
268             END IF;
269 
270             FND_MESSAGE.SET_NAME('ONT','ONT_PRC_AVA_NO_REQUESTED_QTY');
271             FND_MESSAGE.SET_TOKEN('PARTIAL_QUANTITY', p_atp_rec.requested_date_quantity(J));
272             FND_MESSAGE.SET_TOKEN('REQUEST_DATE', p_atp_rec.requested_ship_date(J));
273             FND_MESSAGE.SET_TOKEN('EARLIEST_DATE', p_atp_rec.ship_date(J));
274 
275 	    g_mrp_error_msg :=FND_MESSAGE.GET;
276 	    g_mrp_error_msg_flag := 'T';
277 
278 	    FND_MESSAGE.SET_NAME('ONT','ONT_PRC_AVA_NO_REQUESTED_QTY');
279             FND_MESSAGE.SET_TOKEN('PARTIAL_QUANTITY', p_atp_rec.requested_date_quantity(J));
280             FND_MESSAGE.SET_TOKEN('REQUEST_DATE', p_atp_rec.requested_ship_date(J));
281             FND_MESSAGE.SET_TOKEN('EARLIEST_DATE', p_atp_rec.ship_date(J));
282 
283             IF in_global_orgs = 'N' then
284 	        OE_MSG_PUB.Add;
285             ELSE
286                 x_error_message := fnd_message.get;
287             END IF;
288 
289 	/* End of code added to fix the bug 3245976 - issue 8 */
290 
291           ELSIF p_atp_rec.Ship_Set_Name(J) is not null OR
292                   p_atp_rec.Arrival_Set_Name(J) is not null THEN
293 
294              -- This line belongs to a scheduling group. We do not want
295              -- to give out individual messages for each line.
296              null;
297 
298           ELSE
299               IF l_debug_level  > 0 THEN
300                   oe_debug_pub.add(  'ADDING MESSAGE TO THE STACK' , 1 ) ;
301               END IF;
302               --FND_MESSAGE.SET_NAME('ONT','OE_SCH_OE_ORDER_FAILED');
303               --FND_MESSAGE.SET_TOKEN('EXPLANATION',l_explanation);
304 
305               IF in_global_orgs = 'N' then
306                 FND_MESSAGE.SET_NAME('ONT','ONT_INLNE_CUSTOMER');
307                 FND_MESSAGE.SET_TOKEN('TEXT',l_explanation);
308                 OE_MSG_PUB.Add;
309               ELSE
310                 x_error_message := l_explanation;
311               END IF;
312 
313           END IF;
314 
315       END IF; -- 80
316 
317       IF l_debug_level  > 0 THEN
318           oe_debug_pub.add(  'SETTING ERROR' , 1 ) ;
319       END IF;
320       IF x_return_status <> 'P' then
321         x_return_status := 'E';
322       END IF;
323 
324   ELSE
325 
326                       IF l_debug_level  > 0 THEN
327                           oe_debug_pub.add(  ' ELSE '||P_ATP_REC.SOURCE_ORGANIZATION_ID ( 1 ) ||
328 					     ' ERROR CODE : ' || P_ATP_REC.ERROR_CODE ( J ) ) ;
329                       END IF;
330 
331       -- Muti org changes.
332       IF (p_atp_rec.error_code(J) <> -99 ) THEN
333 
334                         IF l_debug_level  > 0 THEN
335                             oe_debug_pub.add(  'ERROR CODE : ' || P_ATP_REC.ERROR_CODE ( J ) || 'IDENTIFIER : ' ||
336 					       P_ATP_REC.IDENTIFIER ( J ) || 'ITEM : ' ||
337 					       P_ATP_REC.INVENTORY_ITEM_ID ( J ));
338                             oe_debug_pub.add( 'REQUEST SHIP DATE :' ||
339 					      TO_CHAR ( P_ATP_REC.REQUESTED_SHIP_DATE ( J ) , 'DD-MON-RR:HH:MM:SS' )
340 					      || 'REQUEST ARRIVAL DATE :' || P_ATP_REC.REQUESTED_ARRIVAL_DATE ( J ));
341                             oe_debug_pub.add( 'ARRIVAL DATE :' ||
342 					      TO_CHAR ( P_ATP_REC.ARRIVAL_DATE ( J ) , 'DD-MON-RR:HH:MM:SS' ) ||
343 					      'SHIP DATE :' ||
344 					      TO_CHAR ( P_ATP_REC.SHIP_DATE ( J ) , 'DD-MON-RR:HH:MM:SS' ));
345                            oe_debug_pub.add( 'LEAD TIME :' ||P_ATP_REC.DELIVERY_LEAD_TIME ( J ) ||
346 					     'GROUP SHIP DATE :'||P_ATP_REC.GROUP_SHIP_DATE ( J ) ||
347 					     'GROUP ARR DATE :'||P_ATP_REC.GROUP_ARRIVAL_DATE ( J ) ) ;
348                         END IF;
349 
350         l_explanation := null;
351 
352         IF (p_atp_rec.error_code(J) <> 0) THEN
353 
354           BEGIN
355 	     l_lookup_code := p_atp_rec.error_code(J) ;   -- added for bug 3776769
356               select meaning
357                 into l_explanation
358                 from mfg_lookups
359                where lookup_type =l_lookup_type
360                  and lookup_code =l_lookup_code;   -- added for bug 3776769
361 
362               g_atp_tbl(atp_count).error_message   := l_explanation;
363               IF l_debug_level  > 0 THEN
364                   oe_debug_pub.add(  'EXPLANATION IS : ' || L_EXPLANATION , 1 ) ;
365               END IF;
366               x_error_message := l_explanation;
367 
368               IF p_atp_rec.error_code(J) = 150 THEN
369                 OE_MSG_PUB.add_text(l_explanation);
370               END IF;
371 
372           EXCEPTION
373               WHEN OTHERS THEN
374                   Null;
375           END;
376 
377         END IF;
378 
379       END IF; --Check for -99.
380 
381   END IF; -- Main If;
382 
383   -- umcomment for testing the error handling
384   --x_return_status := 'E';
385   --FND_MESSAGE.SET_NAME('ONT','OE_SCH_NO_SOURCE');
386   --OE_MSG_PUB.Add;
387 
388   IF x_return_status ='E'  and in_global_orgs = 'N' then
389     IF l_debug_level  > 0 THEN
390         oe_debug_pub.add(  'DOING COUNT_AND_GET' ) ;
391     END IF;
392     oe_msg_pub.count_and_get(p_encoded=>fnd_api.G_TRUE,
393                              p_count => x_msg_count,
394                              p_data=>x_msg_data
395                              );
396     IF l_debug_level  > 0 THEN
397         oe_debug_pub.add(  'COUNT = '||X_MSG_COUNT||' MSG='||X_MSG_DATA ) ;
398     END IF;
399   END IF;
400 
401   IF l_debug_level  > 0 THEN
402       oe_debug_pub.add(  'EXITING CHECK_RESULTS: ' || X_RETURN_STATUS , 1 ) ;
403   END IF;
404 
405 EXCEPTION
406   WHEN OTHERS THEN
407       IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
408       THEN
409             OE_MSG_PUB.Add_Exc_Msg
410             (   G_PKG_NAME
411             ,   'Check_Results'
412             );
413       END IF;
414       IF l_debug_level  > 0 THEN
415           oe_debug_pub.add(  'UNEXPECTED ERROR IN CHECK_RESULTS' ) ;
416       END IF;
417       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
418 
419 END Check_Results_from_rec;
420 
421 
422 
423 Procedure Call_MRP_ATP(
424                in_global_orgs  in varchar2,
425                in_ship_from_org_id in number,
426 out_available_qty out nocopy varchar2,
427 
428 out_ship_from_org_id out nocopy number,
429 
430 out_available_date out nocopy date,
431 
432 out_qty_uom out nocopy varchar2,
433 
434 x_out_message out nocopy varchar2,
435 
436 x_return_status OUT NOCOPY VARCHAR2,
437 
438 x_msg_count OUT NOCOPY NUMBER,
439 
440 x_msg_data OUT NOCOPY VARCHAR2,
441 
442 x_error_message out nocopy varchar2
443 
444                       ) IS
445 
446 l_session_id              NUMBER := 0;
447 l_mrp_atp_rec             MRP_ATP_PUB.ATP_Rec_Typ;
448 l_atp_supply_demand       MRP_ATP_PUB.ATP_Supply_Demand_Typ;
449 l_atp_period              MRP_ATP_PUB.ATP_Period_Typ;
450 l_atp_details             MRP_ATP_PUB.ATP_Details_Typ;
451 x_atp_rec                 MRP_ATP_PUB.ATP_Rec_Typ;
452 in_atp_rec                 MRP_ATP_PUB.ATP_Rec_Typ;
453 I                         NUMBER := 1;
454 
455 
456 --
457 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
458 --
459 BEGIN
460 
461    IF l_debug_level  > 0 THEN
462        oe_debug_pub.add(  'ENTERING CALL ATP' ) ;
463    END IF;
464 
465    Initialize_mrp_record
466        ( p_x_atp_rec => in_atp_rec
467          ,l_count    =>1 );
468 
469 
470                     IF l_debug_level  > 0 THEN
471                         oe_debug_pub.add(  'INVENTORY_ITEM_ID='||g_panda_rec_table(1).P_INVENTORY_ITEM_ID
472 					   || ' SHIP_FORM_ORG_ID='||G_panda_rec_table(1).p_SHIP_FROM_ORG_ID
473 					   || ' IN_GLOBAL_ORGS='||IN_GLOBAL_ORGS);
474                         oe_debug_pub.add(' CUST_ID='||G_panda_rec_table(1).p_CUSTOMER_ID|| ' SHIP_TO_ORG_ID='
475 					 ||G_panda_rec_table(1).p_SHIP_TO_ORG_ID||' QTY='||G_panda_rec_table(1).p_QTY
476 					 || ' UOM='||G_panda_rec_table(1).p_UOM||' REQ DATE='||
477 					 G_panda_rec_table(1).p_REQUEST_DATE ) ;
478                     END IF;
479 
480    --if the call is made for GA then the org_id is passed
481    IF in_global_orgs = 'Y' and
482       in_ship_from_org_id is not null then
483 
484      in_atp_rec.Source_Organization_Id(1)  := in_ship_from_org_id;
485    ELSE
486 
487      in_atp_rec.Source_Organization_Id(1)  := g_panda_rec_table(1).p_ship_from_org_id;
488    END IF;
489 
490    /*SELECT  OE_ORDER_LINES_S.NEXTVAL
491      INTO  l_line_id
492      FROM  DUAL;
493    */
494 
495    IF l_debug_level  > 0 THEN
496        oe_debug_pub.add(  'LINE_ID='||G_ATP_LINE_ID ) ;
497    END IF;
498 
499    in_atp_rec.Identifier(I)              := g_atp_line_id;
500    in_atp_rec.Action(I)                  := 100;
501    in_atp_rec.calling_module(I)          := 660;
502    in_atp_rec.customer_id(I)             := g_panda_rec_table(1).p_customer_id;
503    in_atp_rec.customer_site_id(I)        := g_panda_rec_table(1).p_ship_to_org_id;
504    in_atp_rec.inventory_item_id(I)       := g_panda_rec_table(1).p_inventory_item_id;
505    in_atp_rec.quantity_ordered(I)        := g_panda_rec_table(1).p_qty;
506    in_atp_rec.quantity_uom(I)            := g_panda_rec_table(1).p_uom;
507    in_atp_rec.Earliest_Acceptable_Date(I):= null;
508    in_atp_rec.Requested_Ship_Date(I)     := g_panda_rec_table(1).p_request_date;
509    in_atp_rec.Requested_Arrival_Date(I)  := null;
510    in_atp_rec.Delivery_Lead_Time(I)      := Null;
511    in_atp_rec.Freight_Carrier(I)         := null;
512    in_atp_rec.Ship_Method(I)             := null;
513    in_atp_rec.Demand_Class(I)            := null;
514    in_atp_rec.Ship_Set_Name(I)           := null;
515    in_atp_rec.Arrival_Set_Name(I)        := null;
516    in_atp_rec.Override_Flag(I)           := 'N';
517    in_atp_rec.Ship_Date(I)               := null;
518    in_atp_rec.Available_Quantity(I)      := null;
519    in_atp_rec.Requested_Date_Quantity(I) := null;
520    in_atp_rec.Group_Ship_Date(I)         := null;
521    in_atp_rec.Group_Arrival_Date(I)      := null;
522    in_atp_rec.Vendor_Id(I)               := null;
523    in_atp_rec.Vendor_Site_Id(I)          := null;
524    in_atp_rec.Insert_Flag(I)             := 1; -- it can be 0 or 1
525    in_atp_rec.Error_Code(I)              := null;
526    in_atp_rec.Message(I)                 := null;
527    in_atp_rec.atp_lead_time(I)           := 0;
528 
529    SELECT mrp_atp_schedule_temp_s.nextval
530      INTO l_session_id
531      FROM dual;
532 
533   IF   OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510'
534       AND  MSC_ATP_GLOBAL.GET_APS_VERSION = 10 THEN
535       in_atp_rec.Included_item_flag(I)  := 1; -- This has to be 1 since OM explodes included items before calling ATP.
536      -- in_atp_rec.top_model_line_id(I)  := p_line_rec.top_model_line_id;
537       in_atp_rec.validation_org(I) := OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
538  END IF;
539 
540    -- Call ATP
541   -- Added to display upgraded item information
542  IF  g_upgrade_item_exists ='Y' then
543 
544     IF l_debug_level  > 0 THEN
545        oe_debug_pub.add('The Upgrade ITem Infomation before calling MRP');
546        oe_debug_pub.add('Upgraded Item id'||g_upgrade_item_id);
547        oe_debug_pub.add('Upgrade Order Uom'||g_upgrade_order_qty_uom);
548        oe_debug_pub.add('Upgrade Ship from org'||g_upgrade_ship_from_org_id);
549     END IF;
550 
551     IF	g_upgrade_ship_from_org_id is not null then
552        in_atp_rec.Source_Organization_Id(1):= g_upgrade_ship_from_org_id;
553     END IF;
554     IF g_upgrade_item_id is not null then
555        in_atp_rec.inventory_item_id(I):=g_upgrade_item_id;
556     END IF;
557     IF g_upgrade_order_qty_uom is not null then
558        in_atp_rec.quantity_uom(I):=g_upgrade_order_qty_uom;
559     END IF;
560 
561  END IF;
562 
563    IF l_debug_level  > 0 THEN
564        oe_debug_pub.add('1.CALLING MRP API WITH SESSION ID '||L_SESSION_ID);
565    END IF;
566 
567     IF l_debug_level  > 0 THEN
568      print_time('Calling MRP');
569     END IF;
570 
571    MRP_ATP_PUB.Call_ATP (
572                  p_session_id             =>  l_session_id
573                , p_atp_rec                =>  in_atp_rec
574                , x_atp_rec                =>  x_atp_rec
575                , x_atp_supply_demand      =>  l_atp_supply_demand
576                , x_atp_period             =>  l_atp_period
577                , x_atp_details            =>  l_atp_details
578                , x_return_status          =>  x_return_status
579                , x_msg_data               =>  x_msg_data
580                , x_msg_count              =>  x_msg_count
581                     );
582 
583     IF l_debug_level  > 0 THEN
584      print_time('After Calling MRP');
585     END IF;
586 
587    IF l_debug_level  > 0 THEN
588      oe_debug_pub.add(  'AFTER CALL MRP_ATP_PUB.CALL_ATP STS='||X_RETURN_STATUS|| ' MSG COUNT='||X_MSG_COUNT);
589 
590      IF x_atp_rec.available_quantity.COUNT > 0 AND
591         x_atp_rec.source_organization_id.COUNT > 0 then
592      oe_debug_pub.add( ' MSG DATA='||X_MSG_DATA|| 'AVL QTY='|| X_ATP_REC.AVAILABLE_QUANTITY ( 1 ) ||
593 		       'SHIP_FROM_ORG_ID =' ||X_ATP_REC.SOURCE_ORGANIZATION_ID ( 1 ) ) ;
594      END IF;
595    END IF;
596 
597    IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
598        IF l_debug_level  > 0 THEN
599            oe_debug_pub.add(  'ERROR IS' || X_MSG_DATA , 1 ) ;
600        END IF;
601        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
602    END IF;
603 
604 
605    Check_Results_from_rec(
606                        in_global_orgs =>in_global_orgs
607                       ,p_atp_rec       => x_atp_rec
608                       ,x_return_status => x_return_status
609                       ,x_msg_count  =>x_msg_count
610                       ,x_msg_data =>x_msg_data
611                       ,x_error_message  =>x_error_message
612                          );
613 
614    IF l_debug_level  > 0 THEN
615      oe_debug_pub.add(  'STATUS='||X_RETURN_STATUS|| ' X_ERROR_MESSAGE ='
616 			||X_ERROR_MESSAGE|| ' MSG DATA='||X_MSG_DATA ) ;
617    END IF;
618 
619    /* Commented the following code to fix the bug 3245976 -- issue 8*/
620    /*
621    IF nvl(x_return_status,'E') <> 'P' then
622 
623      IF l_debug_level  > 0 THEN
624          oe_debug_pub.add(  'RETURN_STATUS<>P' ) ;
625      END IF;
626 
627      IF nvl(x_return_status,'E') <> 'E' THEN
628        IF  nvl(x_atp_rec.available_quantity(1),0) = 0 then
629 
630          IF l_debug_level  > 0 THEN
631            oe_debug_pub.add(  'AVAILABLE QUANTITY IS 0' ) ;
632          END IF;
633          out_available_date   := null;
634          out_available_qty    := 0;
635 
636        ELSE
637          IF x_atp_rec.available_quantity.COUNT > 0 THEN
638            out_available_qty    := x_atp_rec.available_quantity(1);
639          END IF;
640          IF x_atp_rec.ship_date.COUNT > 0 THEN
641            out_available_date    := x_atp_rec.ship_date(1);
642          END IF;
643          IF x_atp_rec.group_ship_date.COUNT > 0 THEN
644            IF x_atp_rec.group_ship_date(1) is not null THEN
645              out_available_date  := x_atp_rec.group_ship_date(1);
646            END IF;
647          END IF;
648 
649        END IF;
650      ELSE
651        out_available_date   := null;
652        out_available_qty    := 0;
653 
654      END IF; -- if status is not E
655 
656    ELSE -- if status is P
657 
658      IF l_debug_level  > 0 THEN
659          oe_debug_pub.add(  'RETURN_STATUS=P MESG='||X_ERROR_MESSAGE ) ;
660      END IF;
661      out_available_qty    := x_error_message;
662      out_available_date   := null;
663      IF  nvl(x_atp_rec.available_quantity(1),0) = 0 then
664 	IF l_debug_level  > 0 THEN
665            oe_debug_pub.add(  'AVAILABLE QUANTITY IS 0' ) ;
666 	END IF;
667      ELSE
668 	IF x_atp_rec.ship_date.COUNT > 0 THEN
669            out_available_date    := x_atp_rec.ship_date(1);
670 	END IF;
671 	IF x_atp_rec.group_ship_date.COUNT > 0 THEN
672            IF x_atp_rec.group_ship_date(1) is not null THEN
673 	      out_available_date  := x_atp_rec.group_ship_date(1);
674            END IF;
675 	END IF;
676 
677      END IF;
678      x_error_message := null;
679 
680    END IF; -- if return status is not P
681 
682    */
683    /* End of code commented to fix the bug 3245976  - issue 8*/
684 
685    /* Added the following code to fix the bug 3245976 - issue 8 */
686 
687          IF x_atp_rec.available_quantity.COUNT > 0 THEN
688            out_available_qty    := x_atp_rec.available_quantity(1);
689          END IF;
690          IF x_atp_rec.ship_date.COUNT > 0 THEN
691            out_available_date    := x_atp_rec.ship_date(1);
692          END IF;
693          IF x_atp_rec.group_ship_date.COUNT > 0 THEN
694            IF x_atp_rec.group_ship_date(1) is not null THEN
695              out_available_date  := x_atp_rec.group_ship_date(1);
696            END IF;
697          END IF;
698          IF x_atp_rec.error_code(1) = 53 then
699            out_available_qty    := x_atp_rec.requested_date_quantity(1);
700          END IF;
701 
702 /* End of new code added to fix the bug 3245976 - issue 8 */
703 
704    IF x_atp_rec.source_organization_id.COUNT > 0 THEN
705      out_ship_from_org_id := x_atp_rec.source_organization_id(1);
706    END IF;
707    IF x_atp_rec.quantity_uom.COUNT > 0 THEN
708      out_qty_uom          := x_atp_rec.quantity_uom(1);
709    END IF;
710 
711 
712    IF l_debug_level  > 0 THEN
713      oe_debug_pub.add( 'OUT_AVAL_QTY='||OUT_AVAILABLE_QTY|| ' SHIP_FORM_ORG_ID='||
714 		       OUT_SHIP_FROM_ORG_ID|| ' UOM='||OUT_QTY_UOM);
715 
716 
717      IF x_atp_rec.ship_date.COUNT > 0 THEN
718        oe_debug_pub.add(' OUT SHIP DATE='||X_ATP_REC.SHIP_DATE(1));
719      END IF;
720 
721      IF x_atp_rec.group_ship_date.COUNT > 0 THEN
722         oe_debug_pub.add(' OUT GRP SHIP DATE='||X_ATP_REC.GROUP_SHIP_DATE(1));
723      END IF;
724 
725      IF x_atp_rec.arrival_date.COUNT > 0 THEN
726       oe_debug_pub.add(' OUT ARRIVAL DATE='||X_ATP_REC.ARRIVAL_DATE(1));
727      END IF;
728 
729      IF x_atp_rec.requested_date_quantity.COUNT > 0 THEN
730         oe_debug_pub.add('REQ DATE QTY='||X_ATP_REC.REQUESTED_DATE_QUANTITY(1));
731      END IF;
732      IF x_atp_rec.available_quantity.COUNT > 0 THEN
733         oe_debug_pub.add(' AVAILABLE QTY='||X_ATP_REC.AVAILABLE_QUANTITY(1));
734      END IF;
735 
736    END IF; -- if debug is on
737 
738 
739    IF l_debug_level  > 0 THEN
740        oe_debug_pub.add(  'EXITING CALL ATP' , 1 ) ;
741    END IF;
742 
743 
744 EXCEPTION
745 
746    WHEN OTHERS THEN
747 
748         IF l_debug_level  > 0 THEN
749             oe_debug_pub.add(  'WHEN OTHERS OF CALL_MRP_ATP' ) ;
750         END IF;
751         IF l_debug_level  > 0 THEN
752             oe_debug_pub.add(  'CODE='||SQLCODE||' MSG='||SQLERRM ) ;
753         END IF;
754         x_return_status := 'E';
755         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
756         --  Get message count and data
757         OE_MSG_PUB.Count_And_Get
758         (   p_count                       => x_msg_count
759         ,   p_data                        => x_msg_data
760         );
761 
762         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
763             OE_MSG_PUB.Add_Exc_Msg
764             (   G_PKG_NAME,
765               'Call_MRP_ATP');
766         END IF;
767 
768         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
769 
770 END Call_MRP_ATP;
771 
772 Procedure Enforce_price_list(in_order_type_id in number,
773 			     out_enforce_price_flag out nocopy varchar2)
774 IS
775 Begin
776      select nvl(enforce_line_prices_flag,'N') into out_enforce_price_flag
777        from oe_Order_types_v where Order_type_id=in_order_type_id;
778    g_enforce_price_flag:= out_enforce_price_flag;
779 exception when no_data_found then
780 out_enforce_price_flag := 'N';
781 g_enforce_price_flag:= out_enforce_price_flag;
782 End Enforce_price_list;
783 
784 Procedure Pass_Upgrade_information(in_upgrade_item_exists varchar2,
785 				   in_upgrade_item_id in number,
786 				   in_upgrade_order_qty_uom in varchar2,
787 				   in_upgrade_ship_from_org_id in number) IS
788 BEGIN
789    g_upgrade_item_exists:=in_upgrade_item_exists;
790    g_upgrade_item_id:=in_upgrade_item_id;
791    g_upgrade_order_qty_uom:=in_upgrade_order_qty_uom;
792    g_upgrade_ship_from_org_id:= in_upgrade_ship_from_org_id;
793 END Pass_Upgrade_information;
794 
795 
796 PROCEDURE defaulting(
797             in_source in varchar2
798             ,in_org_id in varchar2
799             ,in_item_id in number
800             ,in_customer_id in number
801             ,in_ship_to_org_id in number
802             ,in_bill_to_org_id in number
803             ,in_agreement_id in number
804             ,in_order_type_id in number
805             ,out_wsh_id out nocopy number
806             ,out_uom out nocopy varchar2
807             ,out_item_type_code  out nocopy varchar2
808             ,out_price_list_id out nocopy number
809             ,out_conversion_type out nocopy varchar2
810 
811                      ) IS
812 
813 x_msg_count number;
814 tmp_var varchar2(2000);
815 tmp_var1 varchar2(2000);
816 x_msg_data varchar2(2000);
817 x_return_status varchar2(2000);
818 
819 l_old_rec oe_ak_order_lines_v%ROWTYPE;
820 l_rec     oe_ak_order_lines_v%ROWTYPE;
821 l_out_rec oe_ak_order_lines_v%ROWTYPE;
822 l_old_header_rec OE_AK_ORDER_HEADERS_V%ROWTYPE;
823 l_record         OE_AK_ORDER_HEADERS_V%ROWTYPE;
824 l_out_record         OE_AK_ORDER_HEADERS_V%ROWTYPE;
825 
826 --
827 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
828 --
829 l_bom_item_type Varchar2(1);
830 l_pick_components_flag Varchar2(1);
831 BEGIN
832 
833 
834                   IF l_debug_level  > 0 THEN
835                       oe_debug_pub.add(  'ENTERING OE_AVAILABILITY.DEFAULTING '|| ' ITEM_ID='||
836 					 IN_ITEM_ID|| ' SOURCE TYPE ='||IN_SOURCE|| ' ORG ID TYPE ='||IN_ORG_ID);
837                      oe_debug_pub.add( ' CUSTOMER_ID ='||IN_CUSTOMER_ID|| ' SHIP_TO_ORG_ID ='||
838 				       IN_SHIP_TO_ORG_ID|| ' IN_BILL_TO_ORG_ID ='||IN_BILL_TO_ORG_ID
839 				       || ' IN_AGREEMENT_ID ='||IN_AGREEMENT_ID|| ' IN_ORDER_TYPE_ID ='
840 				       ||IN_ORDER_TYPE_ID ) ;
841                   END IF;
842 
843 
844 
845   IF in_source = 'ITEM' then
846 
847     l_rec.inventory_item_id     := in_item_id;
848     l_rec.org_id                := in_org_id;
849     l_rec.sold_to_org_id        := in_customer_id;
850     l_rec.ship_to_org_id        := in_ship_to_org_id;
851     l_rec.ship_from_org_id      := FND_API.G_MISS_NUM;
852     l_rec.order_quantity_uom    := FND_API.G_MISS_CHAR;
853     --l_rec.price_list_id       := FND_API.G_MISS_NUM;
854 
855     l_out_rec := l_rec;
856 
857     ONT_LINE_DEF_HDLR.Default_record(
858                         p_x_rec => l_out_rec,
859                         p_initial_rec =>l_rec,
860                         p_in_old_rec  => l_old_rec
861                                     );
862     out_wsh_id           := l_out_rec.ship_from_org_id;
863     out_uom              := l_out_rec.order_quantity_uom;
864     out_price_list_id    := null;
865     BEGIN
866       SELECT BOM_ITEM_TYPE,PICK_COMPONENTS_FLAG
867       INTO l_bom_item_type,l_pick_components_flag
868       FROM MTL_SYSTEM_ITEMS
869       WHERE INVENTORY_ITEM_ID= in_item_id
870       AND ORGANIZATION_ID=in_org_id;
871       IF l_bom_item_type=4 AND l_pick_components_flag='N' THEN
872         out_item_type_code := 'STANDARD';
873       END IF;
874     EXCEPTION
875     WHEN NO_DATA_FOUND THEN
876       Null;
877     WHEN TOO_MANY_ROWS THEN
878       Null;
879     WHEN OTHERS THEN
880       Null;
881     END;
882 
883                      IF l_debug_level  > 0 THEN
884                          oe_debug_pub.add(  'WSH_ID='||OUT_WSH_ID|| ' UOM='||OUT_UOM|| ' PRICE_LIST_ID='||
885 					    OUT_PRICE_LIST_ID ) ;
886                      END IF;
887 
888   ELSIF in_source = 'CUSTOMER' then
889 
890     IF l_debug_level  > 0 THEN
891         oe_debug_pub.add(  'SOURCE = CUSTOMER' ) ;
892     END IF;
893     l_record.sold_to_org_id        := in_customer_id;
894     l_record.org_id                := in_org_id;
895     l_record.ship_to_org_id        := in_ship_to_org_id;
896     l_record.agreement_id          := in_agreement_id;
897     l_record.invoice_to_org_id     := in_bill_to_org_id;
898     l_record.ship_from_org_id      := FND_API.G_MISS_NUM;
899     l_record.price_list_id         := FND_API.G_MISS_NUM;
900 
901     l_out_record := l_record;
902 
903     ONT_HEADER_Def_Hdlr.Default_Record
904          ( p_x_rec       => l_out_record
905          , p_initial_rec => l_record
906          , p_in_old_rec	 => l_old_header_rec
907          , p_iteration	 => 1
908          );
909 
910     out_wsh_id           := l_out_record.ship_from_org_id;
911     out_price_list_id    := l_out_record.price_list_id;
912 
913                      IF l_debug_level  > 0 THEN
914                          oe_debug_pub.add(  'WSH_ID='||OUT_WSH_ID|| ' UOM='||OUT_UOM|| ' PRICE_LIST_ID='
915 					    ||OUT_PRICE_LIST_ID ) ;
916                      END IF;
917 
918   ELSIF in_source = 'SHIP_TO' then
919 
920     l_record.sold_to_org_id        := in_customer_id;
921     l_record.org_id                := in_org_id;
922     l_record.ship_to_org_id        := in_ship_to_org_id;
923     l_record.agreement_id          := in_agreement_id;
924     l_record.invoice_to_org_id     := in_bill_to_org_id;
925     l_record.ship_from_org_id      := FND_API.G_MISS_NUM;
926     l_record.price_list_id         := FND_API.G_MISS_NUM;
927 
928     l_out_record := l_record;
929 
930     ONT_HEADER_Def_Hdlr.Default_Record
931          ( p_x_rec       => l_out_record
932          , p_initial_rec => l_record
933          , p_in_old_rec	 => l_old_header_rec
934          , p_iteration	 => 1
935          );
936 
937     out_wsh_id           := l_out_record.ship_from_org_id;
938     out_price_list_id    := l_out_record.price_list_id;
939 
940                      IF l_debug_level  > 0 THEN
941                          oe_debug_pub.add(  'WSH_ID='||OUT_WSH_ID|| ' UOM='||OUT_UOM||
942 					    ' PRICE_LIST_ID='||OUT_PRICE_LIST_ID ) ;
943                      END IF;
944 
945   ELSIF in_source = 'BILL_TO' then
946 
947     l_record.sold_to_org_id        := in_customer_id;
948     l_record.org_id                := in_org_id;
949     l_record.ship_to_org_id        := in_ship_to_org_id;
950     l_record.agreement_id          := in_agreement_id;
951     l_record.invoice_to_org_id     := in_bill_to_org_id;
952     l_record.price_list_id         := FND_API.G_MISS_NUM;
953 
954     l_out_record := l_record;
955 
956     ONT_HEADER_Def_Hdlr.Default_Record
957          ( p_x_rec       => l_out_record
958          , p_initial_rec => l_record
959          , p_in_old_rec	 => l_old_header_rec
960          , p_iteration	 => 1
961          );
962 
963     out_wsh_id           := null;
964     out_uom              := null;
965     out_price_list_id    := l_out_record.price_list_id;
966 
967                      IF l_debug_level  > 0 THEN
968                          oe_debug_pub.add(  'WSH_ID='||OUT_WSH_ID|| ' UOM='||OUT_UOM
969 					    || ' PRICE_LIST_ID='||OUT_PRICE_LIST_ID ) ;
970                      END IF;
971 
972   ELSIF in_source = 'AGREEMENT' then
973 
974     l_rec.agreement_id          := in_agreement_id;
975     l_rec.ship_to_org_id        := in_ship_to_org_id;
976     l_rec.invoice_to_org_id     := in_bill_to_org_id;
977     l_rec.sold_to_org_id        := in_customer_id;
978     l_rec.org_id                := in_org_id;
979     l_rec.price_list_id         := FND_API.G_MISS_NUM;
980 
981     l_out_rec := l_rec;
982 
983     ONT_LINE_DEF_HDLR.Default_record(
984                         p_x_rec => l_out_rec,
985                         p_initial_rec =>l_rec,
986                         p_in_old_rec  => l_old_rec
987                                     );
988     out_wsh_id           := null;
989     out_uom              := null;
990     out_price_list_id    := l_out_rec.price_list_id;
991 
992                      IF l_debug_level  > 0 THEN
993                          oe_debug_pub.add(  'WSH_ID='||OUT_WSH_ID|| ' UOM='||
994 					    OUT_UOM|| ' PRICE_LIST_ID='||OUT_PRICE_LIST_ID ) ;
995                      END IF;
996 
997   ELSIF in_source = 'ORDER_TYPE' then
998 
999     l_record.org_id                := in_org_id;
1000     l_record.order_type_id         := in_order_type_id;
1001     l_record.conversion_type_code  := FND_API.G_MISS_CHAR;
1002 
1003     l_out_record := l_record;
1004 
1005 
1006     ONT_HEADER_Def_Hdlr.Default_Record
1007          ( p_x_rec       => l_out_record
1008          , p_initial_rec => l_record
1009          , p_in_old_rec	 => l_old_header_rec
1010          , p_iteration	 => 1
1011          );
1012 
1013     out_conversion_type  := l_out_record.conversion_type_code;
1014     out_uom              := null;
1015     out_price_list_id    := null;
1016     out_wsh_id           := null;
1017 
1018                      IF l_debug_level  > 0 THEN
1019                          oe_debug_pub.add(  'WSH_ID='||OUT_WSH_ID|| ' UOM='||OUT_UOM
1020 					    || ' CONVERSION_TYPE_CODE='||OUT_CONVERSION_TYPE ) ;
1021                      END IF;
1022 
1023   ELSIF in_source = 'STARTUP' then
1024 
1025     l_record.org_id                := in_org_id;
1026 
1027     l_record.conversion_type_code  := FND_API.G_MISS_CHAR;
1028     l_record.price_list_id         := FND_API.G_MISS_NUM;
1029     l_record.ship_from_org_id      := FND_API.G_MISS_NUM;
1030 
1031     l_out_record := l_record;
1032 
1033     ONT_HEADER_Def_Hdlr.Default_Record
1034          ( p_x_rec       => l_out_record
1035          , p_initial_rec => l_record
1036          , p_in_old_rec	 => l_old_header_rec
1037          , p_iteration	 => 1
1038          );
1039 
1040       out_wsh_id           := l_out_rec.ship_from_org_id;
1041     out_uom              := l_out_rec.order_quantity_uom;
1042     out_price_list_id    := l_out_record.price_list_id;
1043     out_conversion_type  := l_out_record.conversion_type_code;
1044 
1045 
1046 
1047 
1048 
1049   END IF; -- in source_type
1050 
1051   IF l_debug_level  > 0 THEN
1052       oe_debug_pub.add(  'EXITING OE_AVAILABILITY.DEFAULTING' ) ;
1053   END IF;
1054 
1055 EXCEPTION
1056 
1057     WHEN FND_API.G_EXC_ERROR THEN
1058 
1059         x_return_status := FND_API.G_RET_STS_ERROR;
1060 
1061         --  Get message count and data
1062 
1063         OE_MSG_PUB.Count_And_Get
1064         (   p_count                       => x_msg_count
1065         ,   p_data                        => x_msg_data
1066         );
1067 
1068     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1069 
1070         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1071 
1072         --  Get message count and data
1073 
1074         OE_MSG_PUB.Count_And_Get
1075         (   p_count                       => x_msg_count
1076         ,   p_data                        => x_msg_data
1077         );
1078 
1079     WHEN OTHERS THEN
1080 
1081         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1082 
1083         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1084         THEN
1085             OE_MSG_PUB.Add_Exc_Msg
1086             (   G_PKG_NAME
1087             ,   'defaulting'
1088             );
1089         END IF;
1090 
1091         --  Get message count and data
1092 
1093         OE_MSG_PUB.Count_And_Get
1094         (   p_count                       => x_msg_count
1095         ,   p_data                        => x_msg_data
1096         );
1097 
1098 END defaulting;
1099 
1100 PROCEDURE defaulting(
1101                      in_source in varchar2,
1102                      in_out_default_rec  in out NOCOPY /* file.sql.39 change */ default_rec
1103                      ) IS
1104 
1105 x_msg_count number;
1106 tmp_var varchar2(2000);
1107 tmp_var1 varchar2(2000);
1108 x_msg_data varchar2(2000);
1109 x_return_status varchar2(2000);
1110 
1111 l_old_rec oe_ak_order_lines_v%ROWTYPE;
1112 l_rec     oe_ak_order_lines_v%ROWTYPE;
1113 l_out_rec oe_ak_order_lines_v%ROWTYPE;
1114 l_old_header_rec OE_AK_ORDER_HEADERS_V%ROWTYPE;
1115 l_record         OE_AK_ORDER_HEADERS_V%ROWTYPE;
1116 l_out_record         OE_AK_ORDER_HEADERS_V%ROWTYPE;
1117 
1118 --
1119 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1120 --
1121 l_bom_item_type Varchar2(1);
1122 l_pick_components_flag Varchar2(1);
1123 BEGIN
1124 
1125    in_out_default_rec.created_by := FND_GLOBAL.user_id;
1126    IF l_debug_level  > 0 THEN
1127       oe_debug_pub.add('ENTERING DEFAULTING PROCEDURE');
1128       oe_debug_pub.add('SOURCE ='|| in_source);
1129       oe_debug_pub.add('VALUES PASSED');
1130       oe_debug_pub.add('************************************************');
1131       oe_debug_pub.add('ORG_ID ='|| in_out_default_rec.org_id);
1132       oe_debug_pub.add('SOLD_TO_ORG_ID =' || in_out_default_rec.sold_to_org_id);
1133       oe_debug_pub.add('INVENTORY_ITEM_ID ='|| in_out_default_rec.inventory_item_id);
1134       oe_debug_pub.add('ITEM_TYPE_CODE =' || in_out_default_rec.item_type_code);
1135       oe_debug_pub.add('USER_ID ='|| in_out_default_rec.user_id);
1136       oe_debug_pub.add('CREATED_BY ='|| in_out_default_rec.created_by);
1137       oe_debug_pub.add('SHIP_TO_ORG_ID =' || in_out_default_rec.ship_to_org_id);
1138       oe_debug_pub.add('ORDER_QUANTITY_UOM =' ||in_out_default_rec.order_quantity_uom);
1139       oe_debug_pub.add('LINE_TYPE_ID ='|| in_out_default_rec.line_type_id);
1140       oe_debug_pub.add('INVOICE_TO_ORG_ID = '|| in_out_default_rec.invoice_to_org_id);
1141       oe_debug_pub.add('DEMAND_CLASS_CODE = ' || in_out_default_rec.demand_class_code);
1142       oe_debug_pub.add('AGREEMENT_ID = ' || in_out_default_rec.agreement_id );
1143       oe_debug_pub.add('ORDER_TYPE_ID ='|| in_out_default_rec.order_type_id);
1144       oe_debug_pub.add('PRICE_LIST_ID = '|| in_out_default_rec.price_list_id);
1145       oe_debug_pub.add('SHIP_FROM_ORG_ID =' || in_out_default_rec.ship_from_org_id);
1146       oe_debug_pub.add('TRANSACTIONAL_CURR_CODE ='|| in_out_default_rec.transactional_curr_code);
1147       oe_debug_pub.add('REQUEST_DATE ='|| in_out_default_rec.request_date);
1148       oe_debug_pub.add('****************************************************************');
1149             END IF;
1150 
1151       IF in_source = 'ITEM' then
1152 
1153 	 l_rec.inventory_item_id     := in_out_default_rec.inventory_item_id;
1154 	 l_rec.org_id                := in_out_default_rec.org_id;
1155 	 l_rec.sold_to_org_id        := in_out_default_rec.sold_to_org_id;
1156 	 l_rec.ship_to_org_id        := in_out_default_rec.ship_to_org_id;
1157 	 l_rec.created_by            := in_out_default_rec.created_by;
1158 	 l_rec.agreement_id          := in_out_default_rec.agreement_id;
1159 	 l_rec.invoice_to_org_id     := in_out_default_rec.invoice_to_org_id;
1160 	 l_rec.request_date          := in_out_default_rec.request_date;
1161 	 l_rec.price_list_id         := in_out_default_rec.price_list_id;
1162 	 l_rec.line_type_id          := in_out_default_rec.line_type_id;
1163 	 l_rec.demand_class_code     := in_out_default_rec.demand_class_code;
1164 	 l_rec.ship_from_org_id      := FND_API.G_MISS_NUM;
1165 	 l_rec.order_quantity_uom    := FND_API.G_MISS_CHAR;
1166 	 l_out_rec := l_rec;
1167 
1168 
1169 	 ONT_LINE_DEF_HDLR.Default_record(
1170 					  p_x_rec => l_out_rec,
1171 					  p_initial_rec =>l_rec,
1172 					  p_in_old_rec  => l_old_rec
1173 					  );
1174 
1175 	 in_out_default_rec.ship_from_org_id := l_out_rec.ship_from_org_id;
1176 	 in_out_default_rec.order_quantity_uom := l_out_rec.order_quantity_uom;
1177 
1178 
1179 	 BEGIN
1180 	      SELECT BOM_ITEM_TYPE,PICK_COMPONENTS_FLAG
1181 		INTO l_bom_item_type,l_pick_components_flag
1182 		FROM MTL_SYSTEM_ITEMS
1183 	       WHERE INVENTORY_ITEM_ID= in_out_default_rec.inventory_item_id
1184 		 AND ORGANIZATION_ID=in_out_default_rec.org_id;
1185 	    IF l_bom_item_type=4 AND l_pick_components_flag='N' THEN
1186 	       in_out_default_rec.item_type_code := 'STANDARD';
1187 	    END IF;
1188 	 EXCEPTION
1189 	    WHEN NO_DATA_FOUND THEN
1190 	       Null;
1191 
1192 	    WHEN TOO_MANY_ROWS THEN
1193 
1194 	       Null;
1195 
1196 	    WHEN OTHERS THEN
1197 	       Null;
1198 	 END;
1199 
1200 
1201       ELSIF in_source = 'CUSTOMER' then
1202 
1203 	 l_record.sold_to_org_id        := in_out_default_rec.sold_to_org_id;
1204 	 l_record.org_id                := in_out_default_rec.org_id;
1205 	 l_record.transactional_curr_code := in_out_default_rec.transactional_curr_code;
1206 	 l_record.created_by            := in_out_default_rec.created_by;
1207 	 l_record.request_date          := in_out_default_rec.request_date;
1208 	 l_record.demand_class_code     := in_out_default_rec.demand_class_code;
1209 	 l_record.ship_To_org_id        := FND_API.G_MISS_NUM;
1210 	 l_record.ship_from_org_id      := FND_API.G_MISS_NUM;
1211 	 l_record.price_list_id         := FND_API.G_MISS_NUM;
1212 	 l_record.order_type_id         := FND_API.G_MISS_NUM;
1213 	 l_record.invoice_to_org_id     := FND_API.G_MISS_NUM;
1214 	 l_record.agreement_id          := FND_API.G_MISS_NUM;
1215 	 l_out_record := l_record;
1216 
1217 	 ONT_HEADER_Def_Hdlr.Default_Record
1218 	    ( p_x_rec       => l_out_record
1219 	      , p_initial_rec => l_record
1220 	      , p_in_old_rec	 => l_old_header_rec
1221 	      , p_iteration	 => 1
1222 	      );
1223 
1224 	 in_out_default_rec.ship_from_org_id :=l_out_record.ship_from_org_id;
1225 	 in_out_default_rec.price_list_id := l_out_record.price_list_id;
1226 	 in_out_default_rec.order_type_id := l_out_record.order_type_id;
1227 	 in_out_default_rec.invoice_to_org_id := l_out_record.invoice_to_org_id;
1228 	 in_out_default_rec.agreement_id  := l_out_record.agreement_id;
1229 	 in_out_default_rec.ship_to_org_id := l_out_record.ship_to_org_id;
1230 
1231 
1232       ELSIF in_source = 'SHIP_TO' then
1233 
1234 	 l_record.sold_to_org_id        := in_out_default_rec.sold_to_org_id;
1235 	 l_record.org_id                := in_out_default_rec.org_id;
1236 	 l_record.ship_to_org_id        := in_out_default_rec.ship_to_org_id;
1237 	 l_record.agreement_id          := in_out_default_rec.agreement_id;
1238 	 l_record.created_by            := in_out_default_rec.created_by;
1239 	 l_record.invoice_to_org_id     := in_out_default_rec.invoice_to_org_id;
1240 	 l_record.transactional_curr_code := in_out_default_rec.transactional_curr_code;
1241 	 l_record.request_date          := in_out_default_rec.request_date;
1242 	 l_record.ship_from_org_id      := FND_API.G_MISS_NUM;
1243 	 l_record.price_list_id         := FND_API.G_MISS_NUM;
1244 	 l_record.order_type_id         := FND_API.G_MISS_NUM;
1245 	 l_record.demand_class_code      := FND_API.G_MISS_CHAR;
1246 	 l_record.invoice_to_org_id     := FND_API.G_MISS_NUM;
1247 
1248 	 l_out_record := l_record;
1249 
1250 	 ONT_HEADER_Def_Hdlr.Default_Record
1251 	    ( p_x_rec       => l_out_record
1252 	      , p_initial_rec => l_record
1253 	      , p_in_old_rec	 => l_old_header_rec
1254 	      , p_iteration	 => 1
1255 	      );
1256 	 in_out_default_rec.ship_from_org_id := l_out_record.ship_from_org_id;
1257 	 in_out_default_rec.price_list_id    := l_out_record.price_list_id;
1258 	 in_out_default_rec.order_type_id    := l_out_record.order_type_id;
1259 	 in_out_default_rec.demand_class_code  := l_out_record.demand_class_code;
1260 	 in_out_default_rec.invoice_to_org_id:= l_out_record.invoice_to_org_id;
1261 
1262       ELSIF in_source = 'BILL_TO' then
1263 
1264 	 l_record.sold_to_org_id        := in_out_default_rec.sold_to_org_id;
1265 	 l_record.org_id                := in_out_default_rec.org_id;
1266 	 l_record.ship_to_org_id        := in_out_default_rec.ship_to_org_id;
1267 	 l_record.agreement_id          := in_out_default_rec.agreement_id;
1268 	 l_record.invoice_to_org_id     := in_out_default_rec.invoice_to_org_id;
1269 	 l_record.transactional_curr_code := in_out_default_rec.transactional_curr_code;
1270 	 l_record.ship_from_org_id      := in_out_default_rec.ship_from_org_id;
1271 	 l_record.demand_class_code     := in_out_default_rec.demand_class_code;
1272 	 l_record.created_by            := in_out_default_rec.created_by;
1273 	 l_record.request_date          := in_out_default_rec.request_date;
1274 	 l_record.price_list_id         := FND_API.G_MISS_NUM;
1275 	 l_record.order_type_id         := FND_API.G_MISS_NUM;
1276 	 l_out_record := l_record;
1277 
1278 	 ONT_HEADER_Def_Hdlr.Default_Record
1279 	    ( p_x_rec       => l_out_record
1280 	      , p_initial_rec => l_record
1281 	      , p_in_old_rec	 => l_old_header_rec
1282 	      , p_iteration	 => 1
1283 	      );
1284 
1285 	 in_out_default_rec.price_list_id := l_out_record.price_list_id;
1286 	 in_out_default_rec.order_type_id := l_out_record.order_type_id;
1287 
1288       ELSIF in_source = 'AGREEMENT' then
1289 
1290 
1291 	 l_rec.agreement_id          := in_out_default_rec.agreement_id;
1292 	 l_rec.ship_to_org_id        := in_out_default_rec.ship_to_org_id;
1293 	 l_rec.inventory_item_id     := in_out_default_rec.inventory_item_id;
1294 	 l_rec.request_date          := in_out_default_rec.request_date;
1295 	 l_rec.line_type_id          := in_out_default_rec.line_type_id;
1296 	 l_rec.ship_from_org_id      := in_out_default_rec.ship_from_org_id;
1297 	 l_rec.order_quantity_uom    := in_out_default_rec.order_quantity_uom;
1298 	 l_rec.demand_class_code     := in_out_default_rec.demand_class_code;
1299 	 l_rec.sold_to_org_id        := in_out_default_rec.sold_to_org_id;
1300 	 l_rec.org_id                := in_out_default_rec.org_id;
1301 	 l_rec.created_by            := in_out_default_rec.created_by;
1302 	 l_rec.price_list_id         := FND_API.G_MISS_NUM;
1303 	 l_rec.invoice_to_org_id     := FND_API.G_MISS_NUM;
1304 	 l_out_rec := l_rec;
1305 
1306 
1307 
1308 	 ONT_LINE_DEF_HDLR.Default_record(
1309 					  p_x_rec => l_out_rec,
1310 					  p_initial_rec =>l_rec,
1311 					  p_in_old_rec  => l_old_rec
1312 					  );
1313 	 in_out_default_rec.price_list_id := l_out_rec.price_list_id;
1314 	 in_out_default_rec.invoice_to_org_id := l_out_rec.invoice_to_org_id;
1315 
1316 	 --bug 4517640
1317 	 l_record.agreement_id          := in_out_default_rec.agreement_id;
1318 	 l_record.ship_to_org_id        := in_out_default_rec.ship_to_org_id;
1319 	 l_record.request_date          := in_out_default_rec.request_date;
1320 	 l_record.ship_from_org_id      := in_out_default_rec.ship_from_org_id;
1321 	 l_record.demand_class_code     := in_out_default_rec.demand_class_code;
1322 	 l_record.sold_to_org_id        := in_out_default_rec.sold_to_org_id;
1323 	 l_record.org_id                := in_out_default_rec.org_id;
1324 	 l_record.created_by            := in_out_default_rec.created_by;
1325 	 l_record.price_list_id         := in_out_default_rec.price_list_id;
1326 	 l_record.invoice_to_org_id     := in_out_default_rec.invoice_to_org_id;
1327 	 l_record.transactional_curr_code :=FND_API.G_MISS_CHAR;
1328 	 l_out_record := l_record;
1329 
1330           ONT_HEADER_Def_Hdlr.Default_Record
1331 	    ( p_x_rec       => l_out_record
1332 	      , p_initial_rec => l_record
1333 	      , p_in_old_rec	 => l_old_header_rec
1334 	      , p_iteration	 => 1
1335 	     );
1336 	 in_out_default_rec.transactional_curr_code :=l_out_record.transactional_curr_code;
1337 
1338 	 --end 4517640
1339 
1340       ELSIF in_source = 'ORDER_TYPE' then
1341 
1342 	 l_record.org_id                := in_out_default_rec.org_id;
1343 	 l_record.order_type_id         := in_out_default_rec.order_type_id;
1344 	 l_record.sold_to_org_id        := in_out_default_rec.sold_to_org_id;
1345 	 l_record.ship_to_org_id        := in_out_default_rec.ship_to_org_id;
1346 	 l_record.agreement_id          := in_out_default_rec.agreement_id;
1347 	 l_record.invoice_to_org_id     := in_out_default_rec.invoice_to_org_id;
1348 	 l_record.created_by            := in_out_default_rec.created_by;
1349 	 l_record.request_date          := in_out_default_rec.request_date;
1350 	 --Bug 7347299
1351 	 l_record.conversion_type_code := FND_API.G_MISS_CHAR;
1352 
1353 	 l_record.demand_class_code     := FND_API.G_MISS_CHAR;
1354 	 l_record.price_list_id         := FND_API.G_MISS_NUM;
1355 	 l_record.ship_from_org_id      := FND_API.G_MISS_NUM;
1356 	 l_record.transactional_curr_code := FND_API.G_MISS_CHAR;
1357 	 l_out_record := l_record;
1358 
1359 
1360 	 ONT_HEADER_Def_Hdlr.Default_Record
1361 	    ( p_x_rec       => l_out_record
1362 	      , p_initial_rec => l_record
1363 	      , p_in_old_rec	 => l_old_header_rec
1364 	      , p_iteration	 => 1
1365 	      );
1366 
1367 
1368 	 in_out_default_rec.demand_class_code := l_out_record.demand_class_code;
1369 	 in_out_default_rec.price_list_id := l_out_record.price_list_id;
1370 	 in_out_default_rec.ship_from_org_id := l_out_record.ship_from_org_id;
1371 	 in_out_default_rec.transactional_curr_code := l_out_record.transactional_curr_code;
1372 	 --Bug 7347299
1373          in_out_default_rec.conversion_type_code := l_out_record.conversion_type_code;
1374 
1375 
1376       ELSIF in_source ='LINE_TYPE' then
1377 
1378 	 l_rec.agreement_id          := in_out_default_rec.agreement_id;
1379 	 l_rec.ship_to_org_id        := in_out_default_rec.ship_to_org_id;
1380 	 l_rec.inventory_item_id     := in_out_default_rec.inventory_item_id;
1381 	 l_rec.request_date          := in_out_default_rec.request_date;
1382 	 l_rec.line_type_id          := in_out_default_rec.line_type_id;
1383 	 l_rec.invoice_to_org_id     := in_out_default_rec.invoice_to_org_id;
1384 	 l_rec.order_quantity_uom    := in_out_default_rec.order_quantity_uom;
1385 	 l_rec.created_by            := in_out_default_rec.created_by;
1386 	 l_rec.sold_to_org_id        := in_out_default_rec.sold_to_org_id;
1387 	 l_rec.org_id                := in_out_default_rec.org_id;
1388 
1389 	 l_rec.price_list_id         := FND_API.G_MISS_NUM;
1390 	 l_rec.ship_from_org_id   := FND_API.G_MISS_NUM;
1391 	 l_rec.demand_class_code   := FND_API.G_MISS_CHAR;
1392 	 l_out_rec := l_rec;
1393 
1394 	 ONT_LINE_DEF_HDLR.Default_record(
1395 					  p_x_rec => l_out_rec,
1396 					  p_initial_rec =>l_rec,
1397 					  p_in_old_rec  => l_old_rec
1398 					  );
1399 
1400 	 in_out_default_rec.price_list_id := l_out_rec.price_list_id;
1401 	 in_out_default_rec.ship_from_org_id := l_out_rec.ship_from_org_id;
1402 	 in_out_default_rec.demand_class_code := l_out_rec.demand_class_code;
1403 
1404       ELSIF in_source = 'PRICE_LIST' then
1405 
1406 	 IF  UPPER(fnd_profile.value('QP_MULTI_CURRENCY_INSTALLED')) NOT  IN ('Y', 'YES') THEN
1407 
1408 	    l_record.org_id                := in_out_default_rec.org_id;
1409 	    l_record.order_type_id         := in_out_default_rec.order_type_id;
1410 	    l_record.sold_to_org_id        := in_out_default_rec.sold_to_org_id;
1411 	    l_record.ship_to_org_id        := in_out_default_rec.ship_to_org_id;
1412 	    l_record.agreement_id          := in_out_default_rec.agreement_id;
1413 	    l_record.invoice_to_org_id     := in_out_default_rec.invoice_to_org_id;
1414 	    l_record.created_by            := in_out_default_rec.created_by;
1415 	    l_record.request_date          := in_out_default_rec.request_date;
1416 
1417 	    l_record.demand_class_code     := in_out_default_rec.demand_class_code;
1418 	    l_record.price_list_id         := in_out_default_rec.price_list_id;
1419 	    l_record.ship_from_org_id      := in_out_default_rec.ship_from_org_id;
1420 
1421 	    l_record.transactional_curr_code := FND_API.G_MISS_CHAR;
1422 	    l_out_record := l_record;
1423 	    ONT_HEADER_Def_Hdlr.Default_Record
1424 	       ( p_x_rec       => l_out_record
1425 		 , p_initial_rec => l_record
1426 		 , p_in_old_rec	 => l_old_header_rec
1427 		 , p_iteration	 => 1
1428 		 );
1429 
1430 
1431 	    in_out_default_rec.transactional_curr_code := l_out_record.transactional_curr_code;
1432 
1433 	 END IF;
1434 
1435       ELSIF in_source = 'STARTUP' then
1436 
1437 	 l_record.org_id                := in_out_default_rec.org_id;
1438 	 l_record.created_by            := in_out_default_rec.created_by;
1439 	 l_record.request_date          := in_out_default_rec.request_date;
1440 	-- for line level defaulting
1441 	 l_rec.org_id                := in_out_default_rec.org_id;
1442 	 l_rec.created_by            := in_out_default_rec.created_by;
1443 	 l_rec.request_date          := in_out_default_rec.request_date;
1444 
1445 
1446 
1447 	 l_record.price_list_id         := FND_API.G_MISS_NUM;
1448 	 l_record.ship_from_org_id      := FND_API.G_MISS_NUM;
1449 	 l_record.order_type_id         := FND_API.G_MISS_NUM;
1450 	 l_record.agreement_id          := FND_API.G_MISS_NUM;
1451 	 l_record.demand_class_code     := FND_API.G_MISS_CHAR;
1452 	 l_record.transactional_curr_code := FND_API.G_MISS_CHAR;
1453 	 l_record.invoice_to_org_id     := FND_API.G_MISS_NUM;
1454 	 l_record.ship_to_org_id        := FND_API.G_MISS_NUM;
1455          l_record.sold_to_org_id        := FND_API.G_MISS_NUM;
1456 	 --Bug 7347299
1457          l_record.conversion_type_code := FND_API.G_MISS_CHAR;
1458 
1459 	 l_out_record := l_record;
1460 
1461           ONT_HEADER_Def_Hdlr.Default_Record
1462 	    ( p_x_rec       => l_out_record
1463 	      , p_initial_rec => l_record
1464 	      , p_in_old_rec	 => l_old_header_rec
1465 	      , p_iteration	 => 1
1466 	      );
1467 
1468 	  in_out_default_rec.ship_from_org_id := l_out_record.ship_from_org_id;
1469 	  in_out_default_rec.price_list_id    := l_out_record.price_list_id;
1470 	  in_out_default_rec.order_type_id := l_out_record.order_type_id;
1471 	  in_out_default_rec.agreement_id := l_out_record.agreement_id;
1472 	  in_out_default_rec.demand_class_code := l_out_record.demand_class_code;
1473 	  in_out_default_rec.transactional_curr_code := l_out_record.transactional_curr_code;
1474 	  in_out_default_rec.invoice_to_org_id := l_out_record.invoice_to_org_id;
1475 	  in_out_default_rec.ship_to_org_id   := l_out_record.ship_to_org_id;
1476 	  in_out_default_rec.sold_to_org_id    := l_out_record.sold_to_org_id;
1477           --Bug 7347299
1478           in_out_default_rec.conversion_type_code := l_out_record.conversion_type_code;
1479 	 -- code added to get the item identifier type
1480 
1481 	  l_rec.agreement_id          := FND_API.G_MISS_NUM;
1482 	  l_rec.ship_to_org_id        := FND_API.G_MISS_NUM;
1483 	  l_rec.inventory_item_id     := FND_API.G_MISS_NUM;
1484 	  l_rec.line_type_id          := FND_API.G_MISS_NUM;
1485 	  l_rec.invoice_to_org_id     := FND_API.G_MISS_NUM;
1486 	  l_rec.order_quantity_uom    := FND_API.G_MISS_CHAR;
1487 	  l_rec.sold_to_org_id        :=FND_API.G_MISS_NUM;
1488 	  l_rec.price_list_id         := FND_API.G_MISS_NUM;
1489 	  l_rec.ship_from_org_id   := FND_API.G_MISS_NUM;
1490 	  l_rec.demand_class_code   := FND_API.G_MISS_CHAR;
1491 	  l_rec.item_identifier_type := FND_API.G_MISS_CHAR;
1492 	  l_out_rec := l_rec;
1493 
1494 	  ONT_LINE_DEF_HDLR.Default_record(
1495 					  p_x_rec => l_out_rec,
1496 					  p_initial_rec =>l_rec,
1497 					  p_in_old_rec  => l_old_rec
1498 					  );
1499 
1500 
1501 	 in_out_default_rec.item_type_code := l_out_rec.item_identifier_type;
1502 
1503 
1504       END IF; -- in source_type
1505 
1506       IF l_debug_level  > 0 THEN
1507 
1508 	 oe_debug_pub.add('VALUES RETURNED FROM DEFAULTING');
1509 	 oe_debug_pub.add('************************************************');
1510 	 oe_debug_pub.add('SOLD_TO_ORG_ID =' || in_out_default_rec.sold_to_org_id);
1511 	 oe_debug_pub.add('ITEM_TYPE_CODE =' || in_out_default_rec.item_type_code);
1512 	 oe_debug_pub.add('SHIP_TO_ORG_ID =' || in_out_default_rec.ship_to_org_id);
1513 	 oe_debug_pub.add('ORDER_QUANTITY_UOM =' ||in_out_default_rec.order_quantity_uom);
1514 	 oe_debug_pub.add('LINE_TYPE_ID ='|| in_out_default_rec.line_type_id);
1515 	 oe_debug_pub.add('INVOICE_TO_ORG_ID = '|| in_out_default_rec.invoice_to_org_id);
1516 	 oe_debug_pub.add('DEMAND_CLASS_CODE = ' || in_out_default_rec.demand_class_code);
1517 	 oe_debug_pub.add('AGREEMENT_ID = ' || in_out_default_rec.agreement_id );
1518 	 oe_debug_pub.add('ORDER_TYPE_ID ='|| in_out_default_rec.order_type_id);
1519 	 oe_debug_pub.add('PRICE_LIST_ID = '|| in_out_default_rec.price_list_id);
1520 	 oe_debug_pub.add('SHIP_FROM_ORG_ID =' || in_out_default_rec.ship_from_org_id);
1521 	 oe_debug_pub.add('TRANSACTIONAL_CURR_CODE ='|| in_out_default_rec.transactional_curr_code);
1522 	 oe_debug_pub.add('****************************************************************');
1523 	 oe_debug_pub.add(  'EXITING OE_AVAILABILITY.DEFAULTING' ) ;
1524       END IF;
1525 
1526    EXCEPTION
1527 
1528       WHEN FND_API.G_EXC_ERROR THEN
1529 
1530 	 x_return_status := FND_API.G_RET_STS_ERROR;
1531 
1532 	 --  Get message count and data
1533 
1534 	 OE_MSG_PUB.Count_And_Get
1535 	    (   p_count                       => x_msg_count
1536 		,   p_data                        => x_msg_data
1537 		);
1538 
1539       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1540 
1541 	 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1542 
1543         --  Get message count and data
1544 
1545 	 OE_MSG_PUB.Count_And_Get
1546 	    (   p_count                       => x_msg_count
1547 		,   p_data                        => x_msg_data
1548 		);
1549 
1550       WHEN OTHERS THEN
1551 
1552 	 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1553 
1554 	 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1555 	 THEN
1556             OE_MSG_PUB.Add_Exc_Msg
1557 	       (   G_PKG_NAME
1558 		   ,   'defaulting'
1559 		   );
1560         END IF;
1561 
1562         --  Get message count and data
1563 
1564         OE_MSG_PUB.Count_And_Get
1565 	   (   p_count                       => x_msg_count
1566 	       ,   p_data                        => x_msg_data
1567 	       );
1568 
1569      END defaulting;
1570 
1571 
1572 
1573 
1574 Procedure Query_Qty_Tree(p_org_id            IN NUMBER,
1575                          p_item_id           IN NUMBER,
1576                          p_sch_date          IN DATE DEFAULT NULL,
1577 x_on_hand_qty OUT NOCOPY NUMBER,
1578 
1579 x_avail_to_reserve OUT NOCOPY NUMBER
1580 
1581                          ) IS
1582 
1583 l_return_status           VARCHAR2(1);
1584 l_msg_count               NUMBER;
1585 l_msg_data                VARCHAR2(2000);
1586 l_qoh                     NUMBER;
1587 l_rqoh                    NUMBER;
1588 l_qr                      NUMBER;
1589 l_qs                      NUMBER;
1590 l_att                     NUMBER;
1591 l_atr                     NUMBER;
1592 l_msg_index               NUMBER;
1593 l_lot_control_flag        BOOLEAN;
1594 l_lot_control_code        NUMBER;
1595 l_org_id                  NUMBER;
1596 
1597 --
1598 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1599 --
1600 BEGIN
1601 
1602                    IF l_debug_level  > 0 THEN
1603                        oe_debug_pub.add(  'ENTERING QUERY_QTY_TREE'|| 'ORG IS : ' || P_ORG_ID
1604 					  || 'ITEM IS : ' || P_ITEM_ID ) ;
1605                    END IF;
1606 
1607   BEGIN
1608     IF p_org_id is null THEN
1609        l_org_id := OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
1610     END IF;
1611 
1612     SELECT msi.lot_control_code
1613     INTO   l_lot_control_code
1614     FROM   mtl_system_items msi
1615     WHERE  msi.inventory_item_id = p_item_id
1616     AND    msi.organization_id   = nvl(p_org_id,l_org_id);
1617 
1618     IF l_lot_control_code = 2 THEN
1619        l_lot_control_flag := TRUE;
1620     ELSE
1621        l_lot_control_flag := FALSE;
1622     END IF;
1623 
1624   EXCEPTION
1625    WHEN OTHERS THEN
1626    l_lot_control_flag := FALSE;
1627   END;
1628 
1629   inv_quantity_tree_pub.query_quantities
1630     (  p_api_version_number      => 1.0
1631      , x_return_status           => l_return_status
1632      , x_msg_count               => l_msg_count
1633      , x_msg_data                => l_msg_data
1634      , p_organization_id         => p_org_id
1635      , p_inventory_item_id       => p_item_id
1636      , p_tree_mode               => 2
1637      , p_is_revision_control     => false
1638      , p_is_lot_control          => l_lot_control_flag
1639      , p_lot_expiration_date     => nvl(p_sch_date,sysdate)
1640      , p_is_serial_control       => false
1641      , p_revision                => null
1642      , p_lot_number              => null
1643      , p_subinventory_code       => null
1644      , p_locator_id              => null
1645      , x_qoh                     => l_qoh
1646      , x_rqoh                    => l_rqoh
1647      , x_qr                      => l_qr
1648      , x_qs                      => l_qs
1649      , x_att                     => l_att
1650      , x_atr                     => l_atr
1651      );
1652 
1653                    IF l_debug_level  > 0 THEN
1654                        oe_debug_pub.add(  'RR: L_QOH ' || L_QOH|| 'RR: L_QOH ' || L_ATR ) ;
1655                    END IF;
1656 
1657   x_on_hand_qty      := l_qoh;
1658   x_avail_to_reserve := l_atr;
1659 
1660   IF l_debug_level  > 0 THEN
1661       oe_debug_pub.add(  'EXITING QUERY_QTY_TREE ' , 1 ) ;
1662   END IF;
1663 
1664 END Query_Qty_Tree;
1665 
1666 
1667 
1668 PROCEDURE get_ship_from_org(in_org_id in number,
1669 out_code out nocopy varchar2,
1670 
1671 out_name out nocopy varchar2
1672 
1673                            )IS
1674 
1675 --
1676 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1677 --
1678 BEGIN
1679     SELECT organization_code,
1680            name
1681       INTO out_code,
1682            out_name
1683       FROM oe_ship_from_orgs_v
1684      WHERE organization_id = in_org_id;
1685 
1686 EXCEPTION
1687 
1688 WHEN OTHERS THEN
1689                      IF l_debug_level  > 0 THEN
1690                          oe_debug_pub.add(  'GET_SHIP_FROM_ORG WHEN OTHERS '|| SQLCODE||SQLERRM ) ;
1691                      END IF;
1692 
1693 END get_ship_From_org;
1694 
1695 PROCEDURE get_sold_to_org(in_org_id in number,
1696 			  out_name out nocopy varchar2,
1697                            out_cust_id out nocopy  number
1698                            )IS
1699 
1700 --
1701 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1702 --
1703 BEGIN
1704     SELECT p.party_name,p.party_id
1705       INTO out_name,out_cust_id
1706       FROM hz_parties p ,hz_cust_accounts c
1707      WHERE p.party_id=c.party_id and c.cust_account_id = in_org_id;
1708 
1709 EXCEPTION
1710 WHEN OTHERS THEN
1711                      IF l_debug_level  > 0 THEN
1712                          oe_debug_pub.add(  'GET_SHIP_FROM_ORG WHEN OTHERS '|| SQLCODE||SQLERRM ) ;
1713                      END IF;
1714 
1715 END get_sold_to_org;
1716 
1717 --bug5621717
1718 PROCEDURE get_sold_to_org(in_org_id in number,
1719 			  out_name out nocopy varchar2,
1720                            out_cust_id out nocopy  varchar2
1721                            )IS
1722 
1723 --
1724 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1725 --
1726 BEGIN
1727     SELECT p.party_name,c.ACCOUNT_NUMBER
1728       INTO out_name,out_cust_id
1729       FROM hz_parties p ,hz_cust_accounts c
1730      WHERE p.party_id=c.party_id and c.cust_account_id = in_org_id;
1731 
1732 EXCEPTION
1733 WHEN OTHERS THEN
1734                      IF l_debug_level  > 0 THEN
1735                          oe_debug_pub.add(  'GET_SHIP_FROM_ORG WHEN OTHERS varchar-'|| SQLCODE||SQLERRM ) ;
1736                      END IF;
1737 
1738 END get_sold_to_org;
1739 
1740 PROCEDURE get_ship_to_org(in_org_id in number,
1741 			  out_name out nocopy varchar2
1742 
1743                            )IS
1744 
1745 --
1746 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1747 --
1748 BEGIN
1749     SELECT name
1750       INTO out_name
1751       FROM oe_ship_to_orgs_v
1752      WHERE organization_id = in_org_id;
1753 
1754 EXCEPTION
1755 
1756 WHEN OTHERS THEN
1757                      IF l_debug_level  > 0 THEN
1758                          oe_debug_pub.add(  'GET_SHIP_TO_ORG WHEN OTHERS '|| SQLCODE||SQLERRM ) ;
1759                      END IF;
1760 
1761 END get_ship_to_org;
1762 
1763 
1764 PROCEDURE get_order_type(in_order_type_id in number,
1765 			 out_name out nocopy varchar2
1766 
1767                            )IS
1768 
1769 --
1770 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1771 --
1772 BEGIN
1773     SELECT  name
1774       INTO  out_name
1775       FROM oe_order_types_v
1776      WHERE order_type_id = in_order_type_id;
1777 
1778 EXCEPTION
1779 
1780 WHEN OTHERS THEN
1781                      IF l_debug_level  > 0 THEN
1782                          oe_debug_pub.add(  'GET_ORDER_TYPE WHEN OTHERS '|| SQLCODE||SQLERRM ) ;
1783                      END IF;
1784 
1785 
1786 END get_order_type;
1787 
1788 
1789 
1790 
1791 PROCEDURE get_currency_name(in_transactional_curr_code in varchar2,
1792 			 out_name out nocopy varchar2
1793 
1794                            )IS
1795 
1796 --
1797 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1798 l_temp varchar2(30);
1799 --
1800 BEGIN
1801     if l_debug_level > 0 then
1802        oe_debug_pub.add('entering transactional curency with currency code'||in_transactional_curr_code);
1803        end if;
1804 l_temp := UPPER(in_transactional_curr_code)||'%';
1805      SELECT  name
1806       INTO  out_name
1807       FROM fnd_currencies_vl
1808      WHERE currency_code like  l_temp;
1809 
1810 EXCEPTION
1811 
1812 WHEN OTHERS THEN
1813                      IF l_debug_level  > 0 THEN
1814                          oe_debug_pub.add(  'GET_CURRENCY WHEN OTHERS '|| SQLCODE||SQLERRM ) ;
1815                      END IF;
1816 
1817 END get_currency_name;
1818 
1819 
1820 PROCEDURE get_demand_class(in_demand_class_code in varchar2,
1821 			 out_name out nocopy varchar2
1822 
1823                            )IS
1824 
1825 --
1826 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1827 l_temp  varchar2(30);
1828 --
1829 BEGIN
1830     if l_debug_level > 0 then
1831       oe_Debug_pub.add('entering demand class doe with'||in_demand_class_code);
1832       end if;
1833 l_temp:= UPPER(in_demand_class_code)||'%';
1834 
1835      SELECT  demand_class
1836       INTO  out_name
1837       FROM oe_demand_classes_v
1838      WHERE demand_class_code like l_temp;
1839 	   EXCEPTION
1840 
1841 WHEN OTHERS THEN
1842                      IF l_debug_level  > 0 THEN
1843                          oe_debug_pub.add(  'GET_DEMAND_CLASS WHEN OTHERS '|| SQLCODE||SQLERRM ) ;
1844                      END IF;
1845 
1846 
1847 END get_demand_class;
1848 
1849 PROCEDURE get_invoice_to_org(in_bill_to_org_id in number,
1850 			 out_name out nocopy varchar2
1851 
1852                            )IS
1853 
1854 --
1855 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1856 --
1857 BEGIN
1858     SELECT  name
1859       INTO  out_name
1860       FROM oe_invoice_to_orgs_v
1861      WHERE organization_id = in_bill_to_org_id;
1862 
1863 EXCEPTION
1864 
1865 WHEN OTHERS THEN
1866                      IF l_debug_level  > 0 THEN
1867                          oe_debug_pub.add(  'GET_INVOICE_TO_ORG WHEN OTHERS '|| SQLCODE||SQLERRM ) ;
1868                      END IF;
1869 
1870 
1871 END get_invoice_to_org;
1872 
1873 PROCEDURE get_agreement_name(in_agreement_id in number,
1874 			 out_name out nocopy varchar2
1875 
1876                            )IS
1877 
1878 --
1879 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1880 --
1881 BEGIN
1882     SELECT  agreement_name
1883       INTO  out_name
1884       FROM oe_agreements_lov_v
1885      WHERE agreement_id = in_agreement_id;
1886 
1887 EXCEPTION
1888 
1889 WHEN OTHERS THEN
1890                      IF l_debug_level  > 0 THEN
1891                          oe_debug_pub.add(  'GET_AGREEMENT_NAME  WHEN OTHERS '|| SQLCODE||SQLERRM ) ;
1892                      END IF;
1893 
1894 
1895 END get_agreement_name;
1896 
1897 
1898 
1899 
1900 
1901 
1902 procedure copy_Header_to_request(
1903 				 p_request_type_code in varchar2
1904 				 ,p_calculate_price_flag in varchar2
1905 				-- ,px_req_line_tbl   in out nocopy	QP_PREQ_GRP.LINE_TBL_TYPE
1906                                 ,px_req_line_tbl   in out nocopy	oe_oe_pricing_availability.QP_LINE_TBL_TYPE
1907 				 ) is
1908 
1909    l_line_index	pls_integer := 0;
1910 
1911    --
1912    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1913    --
1914 BEGIN
1915 
1916    IF l_debug_level  > 0 THEN
1917       oe_debug_pub.add(  'ENTERING OE_AVAILABILITY.COPY_HEADER_TO_REQUEST' , 1 ) ;
1918    END IF;
1919 
1920    l_line_index := l_line_index+1;
1921    px_req_line_tbl(l_line_index).REQUEST_TYPE_CODE :=p_Request_Type_Code;
1922    px_req_line_tbl(l_line_index).LINE_INDEX := l_line_index;
1923    px_req_line_tbl(l_line_index).LINE_TYPE_CODE := 'ORDER';
1924    -- Hold the header_id in line_id for 'HEADER' Records
1925 
1926    px_req_line_tbl(l_line_index).line_id := g_line_id;
1927 
1928    if g_panda_rec_table(1).p_pricing_date is null or g_panda_rec_table(1).p_pricing_date = fnd_api.g_miss_date then
1929       px_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE := trunc(sysdate);
1930    Else
1931       px_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE := g_panda_rec_table(1).p_pricing_date;
1932    End If;
1933 
1934    px_req_line_tbl(l_line_index).CURRENCY_CODE := g_panda_rec_table(1).p_currency;
1935    px_req_line_tbl(l_line_index).PRICE_FLAG := p_calculate_price_flag;
1936    px_req_line_tbl(l_line_index).Active_date_first_type := 'ORD';
1937    px_req_line_tbl(l_line_index).Active_date_first := g_panda_rec_table(1).p_request_date;
1938 
1939    --If G_ROUNDING_FLAG = 'Y' Then
1940    IF g_panda_rec_table(1).p_price_list_id is not null then
1941       px_req_line_tbl(l_line_index).Rounding_factor := Get_Rounding_factor(g_panda_rec_table(1).p_price_list_id);
1942    END IF;
1943    --End If;
1944 
1945    IF l_debug_level  > 0 THEN
1946       oe_debug_pub.add(  'CURR='||G_panda_rec_table(1).p_CURRENCY||' REQ DATE='||
1947 			 G_panda_rec_table(1).p_REQUEST_DATE||' ROUNDING_FACTOR='||
1948 			 PX_REQ_LINE_TBL ( L_LINE_INDEX ) .ROUNDING_FACTOR ) ;
1949    END IF;
1950 
1951    --px_req_line_tbl(l_line_index).price_request_code := p_header_rec.price_request_code; -- PROMOTIONS SEP/01
1952    --populating temp tables
1953     G_LINE_INDEX_TBL.delete;
1954    if l_debug_level > 0 then
1955       oe_debug_pub.add('********** POPULATING HEADER RECORD INTO TEMP TABLE *********************');
1956       --oe_debug_pub.add('line index is='||G_LINE_INDEX_TBL(l_line_index));
1957    end if;
1958    G_LINE_INDEX_TBL(l_line_index)             :=  px_req_line_tbl(l_line_index).LINE_INDEX;
1959    G_LINE_TYPE_CODE_TBL(l_line_index)         :=  px_req_line_tbl(l_line_index).LINE_TYPE_CODE;
1960    G_PRICING_EFFECTIVE_DATE_TBL(l_line_index) :=  TRUNC(px_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE);
1961    G_ACTIVE_DATE_FIRST_TBL(l_line_index)      :=  TRUNC(px_req_line_tbl(l_line_index).ACTIVE_DATE_FIRST);
1962    G_ACTIVE_DATE_FIRST_TYPE_TBL(l_line_index) :=  px_req_line_tbl(l_line_index).ACTIVE_DATE_FIRST_TYPE;
1963    G_ACTIVE_DATE_SECOND_TBL(l_line_index)     :=  TRUNC(px_req_line_tbl(l_line_index).ACTIVE_DATE_SECOND);
1964    G_ACTIVE_DATE_SECOND_TYPE_TBL(l_line_index):= px_req_line_tbl(l_line_index).ACTIVE_DATE_SECOND_TYPE;
1965    G_LINE_QUANTITY_TBL(l_line_index)          := px_req_line_tbl(l_line_index).LINE_QUANTITY;
1966    G_LINE_UOM_CODE_TBL(l_line_index)          := px_req_line_tbl(l_line_index).LINE_UOM_CODE;
1967    G_REQUEST_TYPE_CODE_TBL(l_line_index)      := px_req_line_tbl(l_line_index).REQUEST_TYPE_CODE;
1968    G_PRICED_QUANTITY_TBL(l_line_index)        := px_req_line_tbl(l_line_index).PRICED_QUANTITY;
1969    G_UOM_QUANTITY_TBL(l_line_index)           := px_req_line_tbl(l_line_index).UOM_QUANTITY;
1970    G_PRICED_UOM_CODE_TBL(l_line_index)        := px_req_line_tbl(l_line_index).PRICED_UOM_CODE;
1971    G_CURRENCY_CODE_TBL(l_line_index)          := px_req_line_tbl(l_line_index).CURRENCY_CODE;
1972    G_UNIT_PRICE_TBL(l_line_index)             := px_req_line_tbl(l_line_index).unit_price;  -- AG
1973    G_PERCENT_PRICE_TBL(l_line_index)          := px_req_line_tbl(l_line_index).PERCENT_PRICE;
1974    G_ADJUSTED_UNIT_PRICE_TBL(l_line_index)    := px_req_line_tbl(l_line_index).ADJUSTED_UNIT_PRICE;
1975    G_PROCESSED_FLAG_TBL(l_line_index)         := QP_PREQ_GRP.G_NOT_PROCESSED;
1976    G_PRICE_FLAG_TBL(l_line_index)             := px_req_line_tbl(l_line_index).PRICE_FLAG;
1977    G_LINE_ID_TBL(l_line_index)                := px_req_line_tbl(l_line_index).LINE_ID;
1978    if l_debug_level >0 then
1979       oe_debug_pub.add('the order line id'||G_LINE_ID_TBL(l_line_index));
1980    end if;
1981    G_ROUNDING_FLAG_TBL(l_line_index)          := NULL;
1982    G_ROUNDING_FACTOR_TBL(l_line_index)        := px_req_line_tbl(l_line_index).ROUNDING_FACTOR;
1983    G_PROCESSING_ORDER_TBL(l_line_index)       := NULL;
1984    G_PRICING_STATUS_CODE_tbl(l_line_index)    := QP_PREQ_GRP.G_STATUS_UNCHANGED;
1985    G_PRICING_STATUS_TEXT_tbl(l_line_index)    := NULL;
1986 
1987    G_QUALIFIERS_EXIST_FLAG_TBL(l_line_index)            :='N';
1988    G_PRICING_ATTRS_EXIST_FLAG_TBL(l_line_index)       :='N';
1989    G_PRICE_LIST_ID_TBL(l_line_index)                 :=g_panda_rec_table(1).p_price_list_id;
1990    G_PL_VALIDATED_FLAG_TBL(l_line_index)                := 'N';
1991    G_PRICE_REQUEST_CODE_TBL(l_line_index)        := NULL;
1992    G_USAGE_PRICING_TYPE_TBL(l_line_index)        :='REGULAR';
1993    G_UPD_ADJUSTED_UNIT_PRICE_TBL(l_line_index) :=NULL;
1994    G_LINE_CATEGORY_TBL(l_line_index)           :=NULL;
1995    G_CATCHWEIGHT_QTY_TBL(l_line_index)         := NULL;
1996    G_ACTUAL_ORDER_QTY_TBL(l_line_index)        :=NULL;
1997 
1998    --Temp Table population done
1999 
2000    IF l_debug_level  > 0 THEN
2001       oe_debug_pub.add(  'EXITING oe_oe_pricing_availability.COPY_HEADER_TO_REQUEST' ) ;
2002    END IF;
2003 
2004 END copy_Header_to_request;
2005 
2006 
2007 PROCEDURE copy_Line_to_request(
2008 			      -- px_req_line_tbl   in out nocopy QP_PREQ_GRP.LINE_TBL_TYPE
2009                                 px_req_line_tbl   in out nocopy oe_oe_pricing_availability.QP_LINE_TBL_TYPE
2010 			       ,p_pricing_event   in    varchar2
2011 			       ,p_Request_Type_Code in	varchar2
2012 			       ,p_honor_price_flag in VARCHAR2 Default 'Y'
2013 			       ,p_line_index in number
2014 			       ) IS
2015 
2016    l_line_index	pls_integer := nvl(px_req_line_tbl.count,0);
2017    l_uom_rate      NUMBER;
2018    v_discounting_privilege VARCHAR2(30);
2019    l_item_type_code VARCHAR2(30);
2020 
2021    --
2022    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2023    --
2024 begin
2025 
2026    IF l_debug_level  > 0 THEN
2027       oe_debug_pub.add(  'ENTERING OE_ORDER_ADJ_PVT.COPY_LINE_TO_REQUEST' , 1 ) ;
2028    END IF;
2029 
2030    l_line_index := l_line_index+1;
2031    global_line_index:=l_line_index;
2032 --   px_req_line_tbl(l_line_index).Line_id := g_line_id;
2033    px_req_line_tbl(l_line_index).Line_id := g_panda_rec_table(p_line_index).p_line_id;
2034    px_req_line_tbl(l_line_index).REQUEST_TYPE_CODE := p_Request_Type_Code;
2035    px_req_line_tbl(l_line_index).LINE_INDEX := l_line_index;
2036    px_req_line_tbl(l_line_index).LINE_TYPE_CODE := 'LINE';
2037 
2038    IF g_panda_rec_table(p_line_index).p_pricing_date is null or
2039       g_panda_rec_table(p_line_index).p_pricing_date = fnd_api.g_miss_date then
2040       px_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE := trunc(sysdate);
2041    ELSE
2042       px_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE := g_panda_rec_table(p_line_index).p_pricing_date;
2043    END IF;
2044 
2045    px_req_line_tbl(l_line_index).LINE_QUANTITY := g_panda_rec_table(p_line_index).p_qty ;
2046    px_req_line_tbl(l_line_index).LINE_UOM_CODE := g_panda_rec_table(p_line_index).p_uom;
2047    px_req_line_tbl(l_line_index).PRICED_QUANTITY := g_panda_rec_table(p_line_index).p_qty;
2048    px_req_line_tbl(l_line_index).PRICED_UOM_CODE := g_panda_rec_table(p_line_index).p_uom;
2049    px_req_line_tbl(l_line_index).CURRENCY_CODE :=g_panda_rec_table(p_line_index).p_currency;
2050    px_req_line_tbl(l_line_index).UNIT_PRICE := Null;
2051    --px_req_line_tbl(l_line_index).PERCENT_PRICE := p_Line_rec.unit_list_percent;
2052    IF l_debug_level  > 0 THEN
2053       oe_debug_pub.add(  'QTY='||G_panda_rec_table(p_line_index).p_QTY||' UOM ='||
2054 			 G_panda_rec_table(p_line_index).p_UOM||' CURR='||G_panda_rec_table(p_line_index).p_CURRENCY ) ;
2055    END IF;
2056 
2057   /*If (p_Line_rec.service_period = p_Line_rec.Order_quantity_uom) Then
2058     px_req_line_tbl(l_line_index).UOM_QUANTITY := p_Line_rec.service_duration;
2059   Else
2060     INV_CONVERT.INV_UM_CONVERSION(From_Unit => p_Line_rec.service_period
2061                              ,To_Unit   => p_Line_rec.Order_quantity_uom
2062                              ,Item_ID   => p_Line_rec.Inventory_item_id
2063                              ,Uom_Rate  => l_Uom_rate);
2064     px_req_line_tbl(l_line_index).UOM_QUANTITY := p_Line_rec.service_duration * l_uom_rate;
2065   End If; */
2066 
2067    /* Rounding factor is not needed now as it willbe calculated in QP since the rounding
2068    flag passed in control req is 'Q'. Bug fix for issue 5893353 --FP bug 7363233 smbalara
2069    --If G_ROUNDING_FLAG = 'Y' Then
2070    px_req_line_tbl(l_line_index).Rounding_factor :=
2071       Get_Rounding_factor(g_panda_rec_table(p_line_index).p_price_list_id);
2072    --End If;
2073    */
2074 
2075    px_req_line_tbl(l_line_index).PRICE_FLAG := 'Y';
2076 
2077 
2078    -- Get Discounting Privilege Profile Option value
2079    fnd_profile.get('ONT_DISCOUNTING_PRIVILEGE', v_discounting_privilege);
2080 
2081    -- Execute the pricing phase if the list price is null
2082 
2083    IF p_pricing_event = 'PRICE' and
2084 
2085 
2086      px_req_line_tbl(l_line_index).UNIT_PRICE is null then
2087 
2088     px_req_line_tbl(l_line_index).PRICE_FLAG := 'Y' ;
2089 
2090   END IF;
2091 
2092   --l_item_type_code := oe_line_util.Get_Return_Item_Type_Code(p_Line_rec);
2093   l_item_type_code := 'STANDARD';
2094 
2095   px_req_line_tbl(l_line_index).Active_date_first_type := 'ORD';
2096   px_req_line_tbl(l_line_index).Active_date_first := g_panda_rec_table(p_line_index).p_request_date;
2097 
2098   IF g_panda_rec_table(p_line_index).p_request_date is not null then
2099     px_req_line_tbl(l_line_index).Active_date_Second_type := 'SHIP';
2100     px_req_line_tbl(l_line_index).Active_date_Second := g_panda_rec_table(p_line_index).p_request_date;
2101   End If;
2102 
2103   --px_req_line_tbl(l_line_index).price_request_code := p_line_rec.price_request_code; -- PROMOTIONS  SEP/01
2104   --px_req_line_tbl(l_line_index).line_category :=p_line_rec.line_category_code;
2105    If l_debug_level >0 then
2106    oe_debug_pub.add('********Temp tables population for lines **************');
2107    oe_debug_pub.add('LINE INDEX'||l_line_index);
2108    END IF;
2109 
2110    G_LINE_INDEX_TBL(l_line_index)            :=  px_req_line_tbl(l_line_index).LINE_INDEX;
2111    G_LINE_TYPE_CODE_TBL(l_line_index)        :=  px_req_line_tbl(l_line_index).LINE_TYPE_CODE;
2112    G_PRICING_EFFECTIVE_DATE_TBL(l_line_index):=  TRUNC(px_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE);
2113    G_ACTIVE_DATE_FIRST_TBL(l_line_index)     :=  TRUNC(px_req_line_tbl(l_line_index).ACTIVE_DATE_FIRST);
2114    G_ACTIVE_DATE_FIRST_TYPE_TBL(l_line_index):=  px_req_line_tbl(l_line_index).ACTIVE_DATE_FIRST_TYPE;
2115    G_ACTIVE_DATE_SECOND_TBL(l_line_index)    :=  TRUNC(px_req_line_tbl(l_line_index).ACTIVE_DATE_SECOND);
2116    G_ACTIVE_DATE_SECOND_TYPE_TBL(l_line_index):= px_req_line_tbl(l_line_index).ACTIVE_DATE_SECOND_TYPE;
2117   --px_req_line_tbl(l_line_index).priced_quantity := NULL;
2118    IF l_debug_level  > 0 THEN
2119        oe_debug_pub.add(  'QUANTITY'||PX_REQ_LINE_TBL(L_LINE_INDEX).LINE_QUANTITY||' '||
2120 			  PX_REQ_LINE_TBL(L_LINE_INDEX).PRICED_QUANTITY , 3 ) ;
2121    END IF;
2122    IF l_debug_level  > 0 THEN
2123        oe_debug_pub.add(  'PRICE FLAG'||PX_REQ_LINE_TBL(L_LINE_INDEX).PRICE_FLAG ) ;
2124    END IF;
2125    G_LINE_QUANTITY_TBL(l_line_index)          := px_req_line_tbl(l_line_index).LINE_QUANTITY;
2126 
2127    G_LINE_UOM_CODE_TBL(l_line_index)          := px_req_line_tbl(l_line_index).LINE_UOM_CODE;
2128    G_REQUEST_TYPE_CODE_TBL(l_line_index)      := px_req_line_tbl(l_line_index).REQUEST_TYPE_CODE;
2129    G_PRICED_QUANTITY_TBL(l_line_index)        := px_req_line_tbl(l_line_index).PRICED_QUANTITY;
2130    G_UOM_QUANTITY_TBL(l_line_index)           := NULL;
2131    G_PRICED_UOM_CODE_TBL(l_line_index)        := px_req_line_tbl(l_line_index).PRICED_UOM_CODE;
2132    G_CURRENCY_CODE_TBL(l_line_index)          := px_req_line_tbl(l_line_index).CURRENCY_CODE;
2133     IF l_debug_level  > 0 THEN
2134         oe_debug_pub.add(  'UNIT PRICE'||PX_REQ_LINE_TBL(L_LINE_INDEX).UNIT_PRICE||' '||
2135 			   PX_REQ_LINE_TBL(L_LINE_INDEX).ADJUSTED_UNIT_PRICE ) ;
2136     END IF;
2137    G_UNIT_PRICE_TBL(l_line_index)             := px_req_line_tbl(l_line_index).unit_price;  -- AG
2138    G_PERCENT_PRICE_TBL(l_line_index)          := NULL;
2139    G_ADJUSTED_UNIT_PRICE_TBL(l_line_index)    := px_req_line_tbl(l_line_index).ADJUSTED_UNIT_PRICE;
2140    G_PROCESSED_FLAG_TBL(l_line_index)         := QP_PREQ_GRP.G_NOT_PROCESSED;
2141    G_PRICE_FLAG_TBL(l_line_index)             := px_req_line_tbl(l_line_index).PRICE_FLAG;
2142    G_LINE_ID_TBL(l_line_index)                := px_req_line_tbl(l_line_index).LINE_ID;
2143    IF l_debug_level  > 0 THEN
2144        oe_debug_pub.add(  'LINE ID IN G_LINE_ID_TBL:'|| G_LINE_ID_TBL ( L_LINE_INDEX ) ) ;
2145    END IF;
2146    G_ROUNDING_FLAG_TBL(l_line_index)          := NULL;  -- AG
2147    G_ROUNDING_FACTOR_TBL(l_line_index)        := px_req_line_tbl(l_line_index).ROUNDING_FACTOR;
2148    G_PROCESSING_ORDER_TBL(l_line_index)       := NULL;
2149    G_PRICING_STATUS_CODE_tbl(l_line_index)    := QP_PREQ_GRP.G_STATUS_UNCHANGED;  -- AG
2150    G_PRICING_STATUS_TEXT_tbl(l_line_index)    := NULL;
2151    G_QUALIFIERS_EXIST_FLAG_TBL(l_line_index)            :='N';
2152    G_PRICING_ATTRS_EXIST_FLAG_TBL(l_line_index)       :='N';
2153 
2154 --start 3471501
2155       --G_PRICE_LIST_ID_TBL(l_line_index)                 :=g_panda_rec_table(1).p_price_list_id;
2156 
2157    G_PRICE_LIST_ID_TBL(l_line_index)          :=g_panda_rec_table(p_line_index).p_price_list_id;
2158 
2159  --end 3471501
2160 
2161    G_PL_VALIDATED_FLAG_TBL(l_line_index)                := 'N';
2162    G_PRICE_REQUEST_CODE_TBL(l_line_index)        := NULL;
2163    G_USAGE_PRICING_TYPE_TBL(l_line_index)        :='REGULAR';
2164    G_UPD_ADJUSTED_UNIT_PRICE_TBL(l_line_index) :=NULL;
2165    G_LINE_CATEGORY_TBL(l_line_index) := NULL;
2166 
2167 
2168   IF l_debug_level  > 0 THEN
2169       oe_debug_pub.add(  'EXITING oe_oe_pricing_availability.COPY_LINE_TO_REQUEST' , 1 ) ;
2170   END IF;
2171 
2172 END copy_Line_to_request;
2173 
2174 
2175 
2176 PROCEDURE set_pricing_control_record (
2177 				      l_Control_Rec  in out NOCOPY /* file.sql.39 change */ oe_oe_pricing_availability.QP_CONTROL_RECORD_TYPE
2178 				      ,in_pricing_event in varchar2)IS
2179 
2180    --
2181    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2182    --
2183 BEGIN
2184    if g_enforce_price_flag ='Y' then
2185       l_control_rec.pricing_event := 'PRICE';
2186    else
2187       l_control_rec.pricing_event    := in_pricing_event;
2188    end if;
2189    l_Control_Rec.calculate_flag   := QP_PREQ_GRP.G_SEARCH_N_CALCULATE;
2190    l_control_rec.simulation_flag  := 'Y';
2191 
2192    l_control_rec.gsa_check_flag := 'Y';
2193    l_control_rec.gsa_dup_check_flag := 'Y';
2194    --newly added
2195    l_control_rec.temp_table_insert_flag := 'N';
2196    l_control_rec.request_type_code := 'ONT';
2197   --l_control_rec.request_type_code := 'ASO';
2198    l_control_rec.rounding_flag := 'Q';
2199    l_control_rec.use_multi_currency:='Y';
2200    l_control_rec.SOURCE_ORDER_AMOUNT_FLAG := 'Y';   -- bug 5965668--FP bug 7491750 smbalara
2201 
2202 END set_pricing_control_record;
2203 
2204 Procedure copy_control_rec(in_Control_Rec  in  oe_oe_pricing_availability.QP_CONTROL_RECORD_TYPE,
2205 			   x_Control_Rec   out NOCOPY /* file.sql.39 change */ QP_PREQ_GRP.CONTROL_RECORD_TYPE) IS
2206 
2207 Begin
2208    x_control_rec.pricing_event :=	    in_control_rec.pricing_event;
2209    x_Control_Rec.calculate_flag  := 	    in_control_Rec.calculate_flag;
2210    x_control_rec.simulation_flag:=  	    in_control_rec.simulation_flag;
2211    x_control_rec.gsa_check_flag :=	    in_control_rec.gsa_check_flag;
2212    x_control_rec.gsa_dup_check_flag := 	    in_Control_rec.gsa_dup_check_flag;
2213    x_control_rec.temp_table_insert_flag :=  in_control_rec.temp_table_insert_flag;
2214    x_control_rec.request_type_code := 	    in_control_rec.request_type_code;
2215    x_control_rec.rounding_flag :=	    in_control_rec.rounding_flag;
2216    x_control_rec.use_multi_currency:=	    in_Control_rec.use_multi_currency;
2217    x_control_rec.SOURCE_ORDER_AMOUNT_FLAG :=in_Control_rec.SOURCE_ORDER_AMOUNT_FLAG;  -- bug 5965668--FP bug 7491750 smbalara
2218 
2219 
2220 End copy_control_rec;
2221 
2222 
2223 PROCEDURE build_context_for_line(
2224         p_req_line_tbl_count in number,
2225         p_price_request_code in varchar2,
2226         p_item_type_code in varchar2,
2227         p_Req_line_attr_tbl in out nocopy  oe_oe_pricing_availability.QP_LINE_ATTR_TBL_TYPE,
2228         p_Req_qual_tbl in out  nocopy  oe_oe_pricing_availability.QP_QUAL_TBL_TYPE,
2229 	p_line_index in number
2230        )IS
2231 
2232 qp_attr_mapping_error exception;
2233 l_master_org_id Number:= OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
2234 l_org_id Number;
2235 p_pricing_contexts_Tbl	  QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type;
2236 p_qualifier_contexts_Tbl  QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type;
2237 
2238 --
2239 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2240 l_pass_line VARCHAR2(1) :='N';
2241 --
2242 BEGIN
2243 
2244   IF l_debug_level  > 0 THEN
2245       oe_debug_pub.add(  'BEFORE QP_ATTR_MAPPING_PUB.BUILD_CONTEXTS FOR LINE' , 1 ) ;
2246   END IF;
2247 
2248  -- added for bug 5645866/5847803
2249       l_org_id := OE_GLOBALS.G_ORG_ID;
2250       IF l_org_id IS NULL THEN
2251          OE_GLOBALS.Set_Context;
2252          l_org_id := OE_GLOBALS.G_ORG_ID;
2253       END IF;
2254 
2255                   IF l_debug_level  > 0 THEN
2256                       oe_debug_pub.add(  'ORG_ID='||L_ORG_ID|| ' PRICING_DATE='||
2257 					 G_panda_rec_table(p_line_index).p_PRICING_DATE|| ' INV ITEM_IE='
2258 					 ||G_panda_rec_table(p_line_index).p_INVENTORY_ITEM_ID);
2259                       oe_debug_pub.add( ' AGREEMENT_ID='||G_panda_rec_table(p_line_index).p_AGREEMENT_ID||
2260 					' REQ DATE='||G_panda_rec_table(p_line_index).p_REQUEST_DATE||
2261 					' SHIP_TO_ORG_ID='||G_panda_rec_table(p_line_index).p_SHIP_TO_ORG_ID||
2262 					' INVOICE_TO_ORG_ID='||G_panda_rec_table(p_line_index).p_INVOICE_TO_ORG_ID ) ;
2263                   END IF;
2264 
2265                  IF l_debug_level  > 0 THEN
2266                      oe_debug_pub.add(  'QTY='||G_panda_rec_table(p_line_index).p_QTY||
2267 					' ITEM_TYPE_CODE='||P_ITEM_TYPE_CODE||
2268 					' PRICE_LIST_ID='||G_panda_rec_table(p_line_index).p_PRICE_LIST_ID||
2269 					' CUST_ID='||G_panda_rec_table(p_line_index).p_CUSTOMER_ID||
2270 					' PRICE REQ CODE='||P_PRICE_REQUEST_CODE||
2271 					' UOM='||G_panda_rec_table(p_line_index).p_UOM ) ;
2272                  END IF;
2273 
2274   oe_order_pub.g_line.org_id             := l_org_id;
2275   oe_order_pub.g_line.pricing_date       := g_panda_rec_table(p_line_index).p_pricing_date;
2276   oe_order_pub.g_line.inventory_item_id  := g_panda_rec_table(p_line_index).p_inventory_item_id;
2277   oe_order_pub.g_line.agreement_id       := g_panda_rec_table(p_line_index).p_agreement_id;
2278   --oe_order_pub.g_line.ordered_date     := g_request_date;
2279   oe_order_pub.g_line.ship_to_org_id     := g_panda_rec_table(p_line_index).p_ship_to_org_id;
2280   oe_order_pub.g_line.invoice_to_org_id  := g_panda_rec_table(p_line_index).p_invoice_to_org_id;
2281   oe_order_pub.g_line.ordered_quantity   := g_panda_rec_table(p_line_index).p_qty;
2282   oe_order_pub.g_line.line_type_id       := g_panda_rec_table(p_line_index).p_line_type_id;
2283   oe_order_pub.g_line.item_identifier_type := g_panda_rec_table(p_line_index).p_item_identifier_type;
2284   oe_order_pub.g_line.ordered_item_id := g_panda_rec_table(p_line_index).p_ordered_item_id;
2285   --oe_order_pub.g_line.line_id            := g_line_id;
2286   oe_order_pub.g_line.line_id            := g_panda_rec_table(p_line_index).p_line_id;
2287   oe_order_pub.g_line.header_id          := g_header_id;
2288   oe_order_pub.g_line.item_type_code     := p_item_type_code;
2289   oe_order_pub.g_line.price_list_id      := g_panda_rec_table(p_line_index).p_price_list_id;
2290   oe_order_pub.g_line.sold_to_org_id     := g_panda_rec_table(p_line_index).p_customer_id;
2291   oe_order_pub.g_line.price_request_code := p_price_request_code;
2292   oe_order_pub.g_line.order_quantity_uom := g_panda_rec_table(p_line_index).p_uom;
2293   -- Added for the bug 4150554
2294   oe_order_pub.g_line.ship_from_org_id := g_panda_rec_table(p_line_index).p_ship_from_org_id;
2295 
2296 
2297   IF g_panda_rec_table(p_line_index).p_item_identifier_type ='INT' then
2298 
2299      SELECT concatenated_segments
2300        INTO  oe_order_pub.g_line.ordered_item
2301        FROM   mtl_system_items_kfv
2302        WHERE  inventory_item_id = g_panda_rec_table(p_line_index).p_inventory_item_id
2303        AND    organization_id = l_master_org_id; -- bug 5645866/5847803
2304 
2305   End IF;
2306 
2307   QP_Attr_Mapping_PUB.Build_Contexts(
2308      p_request_type_code => 'ONT',
2309      p_line_index =>global_line_index,
2310      p_pricing_type_code =>'L',
2311      p_check_line_flag => 'N',
2312      p_pricing_event =>'BATCH',
2313      x_pass_line =>l_pass_line);
2314 
2315 
2316   IF l_debug_level > 0 THEN
2317      oe_debug_pub.add('l_PASS_LINE'||l_pass_line);
2318      END IF;
2319 
2320   IF l_debug_level  > 0 THEN
2321       oe_debug_pub.add(  'EXIT QP_ATTR_MAPPING_PUB.BUILD_CONTEXTS FOR LINE' , 1 ) ;
2322   END IF;
2323 
2324 EXCEPTION
2325     when no_data_found then
2326       Null;
2327     when others then
2328       Raise QP_ATTR_MAPPING_ERROR;
2329 
2330 END build_context_for_line;
2331 
2332 
2333 
2334 PROCEDURE build_context_for_header(
2335         p_req_line_tbl_count in number,
2336         p_price_request_code in varchar2,
2337         p_item_type_code in varchar2,
2338         p_Req_line_attr_tbl in out nocopy  oe_oe_pricing_availability.QP_LINE_ATTR_TBL_TYPE,
2339         p_Req_qual_tbl in out  nocopy  oe_oe_pricing_availability.QP_QUAL_TBL_TYPE
2340        )IS
2341 
2342 qp_attr_mapping_error exception;
2343 -- l_org_id Number:= OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
2344 l_org_id Number;
2345 p_pricing_contexts_Tbl	  QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type;
2346 p_qualifier_contexts_Tbl  QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type;
2347 
2348 --
2349 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2350 --
2351 BEGIN
2352 
2353   IF l_debug_level  > 0 THEN
2354       oe_debug_pub.add(  'BEFORE QP_ATTR_MAPPING_PUB.BUILD_CONTEXTS FOR HEADER' , 1 ) ;
2355   END IF;
2356 
2357 -- bug 5645866/5847803
2358     l_org_id := OE_GLOBALS.G_ORG_ID;
2359     IF l_org_id IS NULL THEN
2360        OE_GLOBALS.Set_Context;
2361        l_org_id := OE_GLOBALS.G_ORG_ID;
2362     END IF;
2363 
2364                   IF l_debug_level  > 0 THEN
2365                       oe_debug_pub.add(  'ORG_ID='||L_ORG_ID|| ' PRICING_DATE='||
2366 					 G_panda_rec_table(1).p_PRICING_DATE|| ' AGREEMENT_ID='||
2367 					 G_panda_rec_table(1).p_AGREEMENT_ID|| ' REQ DATE='||
2368 					 G_panda_rec_table(1).p_REQUEST_DATE|| ' SHIP_TO_ORG_ID='||
2369 					 G_panda_rec_table(1).p_SHIP_TO_ORG_ID|| ' INVOICE_TO_ORG_ID='||
2370 					 G_panda_rec_table(1).p_INVOICE_TO_ORG_ID ) ;
2371                   END IF;
2372 
2373                  IF l_debug_level  > 0 THEN
2374                      oe_debug_pub.add(  'QTY='||G_panda_rec_table(1).p_QTY||
2375 					' PRICE_LIST_ID='||G_panda_rec_table(1).p_PRICE_LIST_ID||
2376 					' CUST_ID='||G_panda_rec_table(1).p_CUSTOMER_ID|| ' PRICE REQ CODE='||
2377 					P_PRICE_REQUEST_CODE ) ;
2378                  END IF;
2379 
2380   oe_order_pub.g_hdr.agreement_id       := g_panda_rec_table(1).p_agreement_id;
2381   oe_order_pub.g_hdr.invoice_to_org_id  := g_panda_rec_table(1).p_invoice_to_org_id;
2382   oe_order_pub.g_hdr.ordered_date       := g_panda_rec_table(1).p_request_date;
2383   oe_order_pub.g_hdr.header_id          := g_header_id;
2384   oe_order_pub.g_hdr.org_id             := l_org_id;
2385   oe_order_pub.g_hdr.price_list_id      := g_panda_rec_table(1).p_price_list_id;
2386   oe_order_pub.g_hdr.price_request_code := p_price_request_code;
2387   oe_order_pub.g_hdr.pricing_date       := g_panda_rec_table(1).p_pricing_date;
2388   oe_order_pub.g_hdr.request_date       := g_panda_rec_table(1).p_request_date;
2389   oe_order_pub.g_hdr.ship_to_org_id     := g_panda_rec_table(1).p_ship_to_org_id;
2390   oe_order_pub.g_hdr.sold_to_org_id     := g_panda_rec_table(1).p_customer_id;
2391   oe_order_pub.g_hdr.order_type_id      := g_panda_rec_table(1).p_order_type_id;
2392   oe_order_pub.g_hdr.ship_from_org_id   := g_panda_rec_table(1).p_ship_from_org_id;
2393   --oe_order_pub.g_line.inventory_item_id  := p_inventory_item_id;
2394   --oe_order_pub.g_line.ordered_quantity   := p_ordered_quantity;
2395   --oe_order_pub.g_line.line_id            := g_line_id;
2396   --oe_order_pub.g_line.item_type_code     := p_item_type_code;
2397   --oe_order_pub.g_line.order_quantity_uom := p_uom;
2398 
2399 
2400 
2401      QP_ATTR_Mapping_PUB.Build_Contexts(
2402           p_request_type_code =>'ONT',
2403           p_line_index =>1,
2404           p_pricing_type_code =>'H');
2405 
2406 
2407 
2408   IF l_debug_level  > 0 THEN
2409       oe_debug_pub.add(  'EXIT QP_ATTR_MAPPING_PUB.BUILD_CONTEXTS FOR HEADER' , 1 ) ;
2410   END IF;
2411 
2412 EXCEPTION
2413     when no_data_found then
2414       Null;
2415     when others then
2416       Raise QP_ATTR_MAPPING_ERROR;
2417 
2418 END build_context_for_header;
2419 
2420 
2421 
2422 procedure  Append_attributes(
2423 			     p_header_id number default null
2424 			     ,p_Line_id number default null
2425 			     ,p_line_index number
2426 			     ,px_Req_line_attr_tbl in out nocopy  oe_oe_pricing_availability.QP_LINE_ATTR_TBL_TYPE
2427 			     ,px_Req_qual_tbl in out nocopy  oe_oe_pricing_availability.QP_QUAL_TBL_TYPE
2428 			     ,p_g_line_index in number
2429 
2430 			     ) is
2431 
2432    i	pls_integer;
2433 
2434    --
2435    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2436 
2437       --
2438 BEGIN
2439 
2440    IF l_debug_level  > 0 THEN
2441       oe_debug_pub.add('ENTERING oe_oe_pricing_availability.APPEND_ATTRIBUTES'||
2442                          ' p_line_id='||p_line_id);
2443    END IF;
2444 
2445     -- if line_id is not null, this does not apply to header level
2446    IF p_line_id is not null then
2447 
2448    IF l_debug_level  > 0 THEN
2449       oe_debug_pub.add(  'appending main attributes');
2450    END IF;
2451 
2452    IF g_panda_rec_table(p_g_line_index).p_pricing_attribute1 is not null then
2453       i := px_Req_line_attr_tbl.count+1;
2454       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2455       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2456       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2457       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE1';
2458       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE1;
2459    END IF;
2460 
2461    IF g_panda_rec_table(p_g_line_index).p_pricing_attribute2 is not null then
2462       i := px_Req_line_attr_tbl.count+1;
2463       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2464       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2465       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2466       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE2';
2467       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE2;
2468    END IF;
2469 
2470    IF g_panda_rec_table(p_g_line_index).p_pricing_attribute3 is not null then
2471       i := px_Req_line_attr_tbl.count+1;
2472       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2473       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2474       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2475       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE3';
2476       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE3;
2477    END IF;
2478 
2479    IF g_panda_rec_table(p_g_line_index).p_pricing_attribute4 is not null then
2480       i := px_Req_line_attr_tbl.count+1;
2481       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2482       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2483       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2484       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE4';
2485       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE4;
2486    END IF;
2487 
2488    if g_panda_rec_table(p_g_line_index).p_pricing_attribute5 is not null then
2489       i := px_Req_line_attr_tbl.count+1;
2490       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2491       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2492       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2493       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE5';
2494       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE5;
2495    end if;
2496 
2497    if g_panda_rec_table(p_g_line_index).p_pricing_attribute6 is not null then
2498       i := px_Req_line_attr_tbl.count+1;
2499       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2500       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2501       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2502       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE6';
2503       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE6;
2504    end if;
2505 
2506    if g_panda_rec_table(p_g_line_index).p_pricing_attribute7 is not null then
2507       i := px_Req_line_attr_tbl.count+1;
2508       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2509       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2510       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2511       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE7';
2512       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE7;
2513    end if;
2514 
2515    if g_panda_rec_table(p_g_line_index).p_pricing_attribute8 is not null then
2516       i := px_Req_line_attr_tbl.count+1;
2517       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2518       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2519       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2520       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE8';
2521       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE8;
2522    end if;
2523 
2524    if g_panda_rec_table(p_g_line_index).p_pricing_attribute9 is not null then
2525       i := px_Req_line_attr_tbl.count+1;
2526       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2527       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2528       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2529       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE9';
2530       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE9;
2531    end if;
2532 
2533    if g_panda_rec_table(p_g_line_index).p_pricing_attribute10 is not null then
2534       i := px_Req_line_attr_tbl.count+1;
2535       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2536       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2537       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2538       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE10';
2539       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE10;
2540    end if;
2541 
2542    if g_panda_rec_table(p_g_line_index).p_pricing_attribute11 is not null then
2543       i := px_Req_line_attr_tbl.count+1;
2544       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2545       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2546       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2547       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE11';
2548       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE11;
2549    end if;
2550 
2551    if g_panda_rec_table(p_g_line_index).p_pricing_attribute12 is not null then
2552       i := px_Req_line_attr_tbl.count+1;
2553       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2554       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2555       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2556       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE12';
2557       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE12;
2558    end if;
2559 
2560    if g_panda_rec_table(p_g_line_index).p_pricing_attribute13 is not null then
2561       i := px_Req_line_attr_tbl.count+1;
2562       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2563       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2564       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2565       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE13';
2566       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE13;
2567    end if;
2568 
2569    if g_panda_rec_table(p_g_line_index).p_pricing_attribute14 is not null then
2570       i := px_Req_line_attr_tbl.count+1;
2571       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2572       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2573       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2574       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE14';
2575       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE14;
2576    end if;
2577 
2578    if g_panda_rec_table(p_g_line_index).p_pricing_attribute15 is not null then
2579       i := px_Req_line_attr_tbl.count+1;
2580       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2581       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2582       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2583       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE15';
2584       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE15;
2585    end if;
2586 
2587    if g_panda_rec_table(p_g_line_index).p_pricing_attribute16 is not null then
2588       i := px_Req_line_attr_tbl.count+1;
2589       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2590       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2591       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2592       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE16';
2593       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE16;
2594    end if;
2595 
2596    if g_panda_rec_table(p_g_line_index).p_pricing_attribute17 is not null then
2597       i := px_Req_line_attr_tbl.count+1;
2598       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2599       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2600       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2601       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE17';
2602       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE17;
2603    end if;
2604 
2605    if g_panda_rec_table(p_g_line_index).p_pricing_attribute18 is not null then
2606       i := px_Req_line_attr_tbl.count+1;
2607       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2608       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2609       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2610       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE18';
2611       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE18;
2612    end if;
2613 
2614    if g_panda_rec_table(p_g_line_index).p_pricing_attribute19 is not null then
2615       i := px_Req_line_attr_tbl.count+1;
2616       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2617       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2618       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2619       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE19';
2620       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE19;
2621    end if;
2622 
2623    if g_panda_rec_table(p_g_line_index).p_pricing_attribute20 is not null then
2624       i := px_Req_line_attr_tbl.count+1;
2625       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2626       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2627       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2628       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE20';
2629       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE20;
2630    end if;
2631 
2632    if g_panda_rec_table(p_g_line_index).p_pricing_attribute21 is not null then
2633       i := px_Req_line_attr_tbl.count+1;
2634       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2635       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2636       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2637       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE21';
2638       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE21;
2639    end if;
2640 
2641    if g_panda_rec_table(p_g_line_index).p_pricing_attribute22 is not null then
2642       i := px_Req_line_attr_tbl.count+1;
2643       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2644       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2645       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2646       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE22';
2647       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE22;
2648    end if;
2649 
2650    if g_panda_rec_table(p_g_line_index).p_pricing_attribute23 is not null then
2651       i := px_Req_line_attr_tbl.count+1;
2652       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2653       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2654       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2655       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE23';
2656       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE23;
2657    end if;
2658 
2659    if g_panda_rec_table(p_g_line_index).p_pricing_attribute24 is not null then
2660       i := px_Req_line_attr_tbl.count+1;
2661       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2662       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2663       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2664       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE24';
2665       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE24;
2666    end if;
2667 
2668    if g_panda_rec_table(p_g_line_index).p_pricing_attribute25 is not null then
2669       i := px_Req_line_attr_tbl.count+1;
2670       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2671       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2672       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2673       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE25';
2674       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE25;
2675    end if;
2676 
2677    if g_panda_rec_table(p_g_line_index).p_pricing_attribute26 is not null then
2678       i := px_Req_line_attr_tbl.count+1;
2679       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2680       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2681       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2682       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE26';
2683       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE26;
2684    end if;
2685 
2686    if g_panda_rec_table(p_g_line_index).p_pricing_attribute27 is not null then
2687       i := px_Req_line_attr_tbl.count+1;
2688       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2689       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2690       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2691       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE27';
2692       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE27;
2693    end if;
2694 
2695    if g_panda_rec_table(p_g_line_index).p_pricing_attribute28 is not null then
2696       i := px_Req_line_attr_tbl.count+1;
2697       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2698       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2699       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2700       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE28';
2701       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE28;
2702    end if;
2703 
2704    if g_panda_rec_table(p_g_line_index).p_pricing_attribute29 is not null then
2705       i := px_Req_line_attr_tbl.count+1;
2706       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2707       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2708       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2709       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE29';
2710       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_PRICING_ATTRIBUTE29;
2711    end if;
2712 
2713    if g_panda_rec_table(p_g_line_index).p_pricing_attribute30 is not null then
2714       i := px_Req_line_attr_tbl.count+1;
2715       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2716       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2717       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2718       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE30';
2719       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute30;
2720    end if;
2721 
2722    if g_panda_rec_table(p_g_line_index).p_pricing_attribute31 is not null then
2723       i := px_Req_line_attr_tbl.count+1;
2724       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2725       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2726       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2727       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE31';
2728       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute31;
2729    end if;
2730 
2731    if g_panda_rec_table(p_g_line_index).p_pricing_attribute32 is not null then
2732       i := px_Req_line_attr_tbl.count+1;
2733       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2734       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2735       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2736       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE32';
2737       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute32;
2738    end if;
2739 
2740    if g_panda_rec_table(p_g_line_index).p_pricing_attribute33 is not null then
2741       i := px_Req_line_attr_tbl.count+1;
2742       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2743       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2744       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2745       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE33';
2746       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute33;
2747    end if;
2748 
2749    if g_panda_rec_table(p_g_line_index).p_pricing_attribute34 is not null then
2750       i := px_Req_line_attr_tbl.count+1;
2751       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2752       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2753       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2754       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE34';
2755       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute34;
2756    end if;
2757 
2758    if g_panda_rec_table(p_g_line_index).p_pricing_attribute35 is not null then
2759       i := px_Req_line_attr_tbl.count+1;
2760       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2761       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2762       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2763       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE35';
2764       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute35;
2765    end if;
2766 
2767    if g_panda_rec_table(p_g_line_index).p_pricing_attribute36 is not null then
2768       i := px_Req_line_attr_tbl.count+1;
2769       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2770       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2771       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2772       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE36';
2773       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute36;
2774    end if;
2775 
2776    if g_panda_rec_table(p_g_line_index).p_pricing_attribute37 is not null then
2777       i := px_Req_line_attr_tbl.count+1;
2778       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2779       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2780       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2781       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE37';
2782       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute37;
2783    end if;
2784 
2785    if g_panda_rec_table(p_g_line_index).p_pricing_attribute38 is not null then
2786       i := px_Req_line_attr_tbl.count+1;
2787       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2788       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2789       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2790       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE38';
2791       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute38;
2792    end if;
2793 
2794    if g_panda_rec_table(p_g_line_index).p_pricing_attribute39 is not null then
2795       i := px_Req_line_attr_tbl.count+1;
2796       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2797       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2798       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2799       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE39';
2800       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute39;
2801    end if;
2802 
2803    if g_panda_rec_table(p_g_line_index).p_pricing_attribute40 is not null then
2804       i := px_Req_line_attr_tbl.count+1;
2805       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2806       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2807       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2808       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE40';
2809       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute40;
2810    end if;
2811 
2812    if g_panda_rec_table(p_g_line_index).p_pricing_attribute41 is not null then
2813       i := px_Req_line_attr_tbl.count+1;
2814       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2815       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2816       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2817       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE41';
2818       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute41;
2819    end if;
2820 
2821    if g_panda_rec_table(p_g_line_index).p_pricing_attribute42 is not null then
2822       i := px_Req_line_attr_tbl.count+1;
2823       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2824       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2825       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2826       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE42';
2827       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute42;
2828    end if;
2829 
2830    if g_panda_rec_table(p_g_line_index).p_pricing_attribute43 is not null then
2831       i := px_Req_line_attr_tbl.count+1;
2832       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2833       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2834       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2835       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE43';
2836       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute43;
2837    end if;
2838 
2839    if g_panda_rec_table(p_g_line_index).p_pricing_attribute44 is not null then
2840       i := px_Req_line_attr_tbl.count+1;
2841       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2842       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2843       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2844       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE44';
2845       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute44;
2846    end if;
2847 
2848    if g_panda_rec_table(p_g_line_index).p_pricing_attribute45 is not null then
2849       i := px_Req_line_attr_tbl.count+1;
2850       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2851       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2852       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2853       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE45';
2854       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute45;
2855    end if;
2856 
2857    if g_panda_rec_table(p_g_line_index).p_pricing_attribute46 is not null then
2858       i := px_Req_line_attr_tbl.count+1;
2859       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2860       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2861       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2862       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE46';
2863       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute46;
2864    end if;
2865 
2866    if g_panda_rec_table(p_g_line_index).p_pricing_attribute47 is not null then
2867       i := px_Req_line_attr_tbl.count+1;
2868       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2869       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2870       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2871       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE47';
2872       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute47;
2873    end if;
2874 
2875    if g_panda_rec_table(p_g_line_index).p_pricing_attribute48 is not null then
2876       i := px_Req_line_attr_tbl.count+1;
2877       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2878       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2879       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2880       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE48';
2881       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute48;
2882    end if;
2883 
2884    if g_panda_rec_table(p_g_line_index).p_pricing_attribute49 is not null then
2885       i := px_Req_line_attr_tbl.count+1;
2886       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2887       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2888       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2889       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE49';
2890       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute49;
2891    end if;
2892 
2893 
2894    if g_panda_rec_table(p_g_line_index).p_pricing_attribute50 is not null then
2895       i := px_Req_line_attr_tbl.count+1;
2896       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2897       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2898       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2899       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE20';
2900       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute20;
2901    end if;
2902 
2903    if g_panda_rec_table(p_g_line_index).p_pricing_attribute51 is not null then
2904       i := px_Req_line_attr_tbl.count+1;
2905       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2906       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2907       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2908       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE51';
2909       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute51;
2910    end if;
2911 
2912    if g_panda_rec_table(p_g_line_index).p_pricing_attribute52 is not null then
2913       i := px_Req_line_attr_tbl.count+1;
2914       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2915       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2916       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2917       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE52';
2918       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute52;
2919    end if;
2920 
2921    if g_panda_rec_table(p_g_line_index).p_pricing_attribute53 is not null then
2922       i := px_Req_line_attr_tbl.count+1;
2923       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2924       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2925       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2926       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE53';
2927       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute53;
2928    end if;
2929 
2930    if g_panda_rec_table(p_g_line_index).p_pricing_attribute54 is not null then
2931       i := px_Req_line_attr_tbl.count+1;
2932       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2933       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2934       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2935       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE54';
2936       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute54;
2937    end if;
2938 
2939    if g_panda_rec_table(p_g_line_index).p_pricing_attribute55 is not null then
2940       i := px_Req_line_attr_tbl.count+1;
2941       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2942       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2943       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2944       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE55';
2945       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute55;
2946    end if;
2947 
2948    if g_panda_rec_table(p_g_line_index).p_pricing_attribute56 is not null then
2949       i := px_Req_line_attr_tbl.count+1;
2950       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2951       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2952       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2953       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE56';
2954       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute56;
2955    end if;
2956 
2957    if g_panda_rec_table(p_g_line_index).p_pricing_attribute57 is not null then
2958       i := px_Req_line_attr_tbl.count+1;
2959       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2960       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2961       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2962       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE57';
2963       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute57;
2964    end if;
2965 
2966    if g_panda_rec_table(p_g_line_index).p_pricing_attribute58 is not null then
2967       i := px_Req_line_attr_tbl.count+1;
2968       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2969       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2970       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2971       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE58';
2972       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute58;
2973    end if;
2974 
2975    if g_panda_rec_table(p_g_line_index).p_pricing_attribute59 is not null then
2976       i := px_Req_line_attr_tbl.count+1;
2977       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2978       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2979       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2980       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE59';
2981       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute59;
2982    end if;
2983 
2984 
2985    if g_panda_rec_table(p_g_line_index).p_pricing_attribute60 is not null then
2986       i := px_Req_line_attr_tbl.count+1;
2987       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2988       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2989       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2990       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE60';
2991       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute60;
2992    end if;
2993 
2994    if g_panda_rec_table(p_g_line_index).p_pricing_attribute61 is not null then
2995       i := px_Req_line_attr_tbl.count+1;
2996       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2997       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
2998       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
2999       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE61';
3000       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute61;
3001    end if;
3002 
3003    if g_panda_rec_table(p_g_line_index).p_pricing_attribute62 is not null then
3004       i := px_Req_line_attr_tbl.count+1;
3005       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3006       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3007       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3008       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE62';
3009       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute62;
3010    end if;
3011 
3012    if g_panda_rec_table(p_g_line_index).p_pricing_attribute63 is not null then
3013       i := px_Req_line_attr_tbl.count+1;
3014       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3015       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3016       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3017       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE63';
3018       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute63;
3019    end if;
3020 
3021    if g_panda_rec_table(p_g_line_index).p_pricing_attribute64 is not null then
3022       i := px_Req_line_attr_tbl.count+1;
3023       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3024       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3025       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3026       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE64';
3027       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute64;
3028    end if;
3029 
3030    if g_panda_rec_table(p_g_line_index).p_pricing_attribute65 is not null then
3031       i := px_Req_line_attr_tbl.count+1;
3032       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3033       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3034       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3035       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE65';
3036       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute65;
3037    end if;
3038 
3039    if g_panda_rec_table(p_g_line_index).p_pricing_attribute66 is not null then
3040       i := px_Req_line_attr_tbl.count+1;
3041       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3042       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3043       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3044       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE66';
3045       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute66;
3046    end if;
3047 
3048    if g_panda_rec_table(p_g_line_index).p_pricing_attribute67 is not null then
3049       i := px_Req_line_attr_tbl.count+1;
3050       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3051       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3052       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3053       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE67';
3054       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute67;
3055    end if;
3056 
3057    if g_panda_rec_table(p_g_line_index).p_pricing_attribute68 is not null then
3058       i := px_Req_line_attr_tbl.count+1;
3059       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3060       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3061       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3062       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE68';
3063       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute68;
3064    end if;
3065 
3066    if g_panda_rec_table(p_g_line_index).p_pricing_attribute69 is not null then
3067       i := px_Req_line_attr_tbl.count+1;
3068       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3069       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3070       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3071       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE69';
3072       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute69;
3073    end if;
3074 
3075 
3076    if g_panda_rec_table(p_g_line_index).p_pricing_attribute70 is not null then
3077       i := px_Req_line_attr_tbl.count+1;
3078       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3079       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3080       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3081       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE70';
3082       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute70;
3083    end if;
3084 
3085    if g_panda_rec_table(p_g_line_index).p_pricing_attribute71 is not null then
3086       i := px_Req_line_attr_tbl.count+1;
3087       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3088       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3089       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3090       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE71';
3091       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute71;
3092    end if;
3093 
3094    if g_panda_rec_table(p_g_line_index).p_pricing_attribute72 is not null then
3095       i := px_Req_line_attr_tbl.count+1;
3096       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3097       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3098       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3099       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE72';
3100       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute72;
3101    end if;
3102 
3103    if g_panda_rec_table(p_g_line_index).p_pricing_attribute73 is not null then
3104       i := px_Req_line_attr_tbl.count+1;
3105       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3106       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3107       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3108       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE73';
3109       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute73;
3110    end if;
3111 
3112    if g_panda_rec_table(p_g_line_index).p_pricing_attribute74 is not null then
3113       i := px_Req_line_attr_tbl.count+1;
3114       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3115       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3116       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3117       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE74';
3118       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute74;
3119    end if;
3120 
3121    if g_panda_rec_table(p_g_line_index).p_pricing_attribute75 is not null then
3122       i := px_Req_line_attr_tbl.count+1;
3123       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3124       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3125       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3126       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE75';
3127       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute75;
3128    end if;
3129 
3130    if g_panda_rec_table(p_g_line_index).p_pricing_attribute76 is not null then
3131       i := px_Req_line_attr_tbl.count+1;
3132       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3133       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3134       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3135       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE76';
3136       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute76;
3137    end if;
3138 
3139    if g_panda_rec_table(p_g_line_index).p_pricing_attribute77 is not null then
3140       i := px_Req_line_attr_tbl.count+1;
3141       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3142       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3143       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3144       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE77';
3145       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute77;
3146    end if;
3147 
3148    if g_panda_rec_table(p_g_line_index).p_pricing_attribute78 is not null then
3149       i := px_Req_line_attr_tbl.count+1;
3150       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3151       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3152       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3153       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE78';
3154       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute27;
3155    end if;
3156 
3157    if g_panda_rec_table(p_g_line_index).p_pricing_attribute79 is not null then
3158       i := px_Req_line_attr_tbl.count+1;
3159       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3160       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3161       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3162       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE79';
3163       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute27;
3164    end if;
3165 
3166 
3167    if g_panda_rec_table(p_g_line_index).p_pricing_attribute80 is not null then
3168       i := px_Req_line_attr_tbl.count+1;
3169       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3170       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3171       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3172       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE80';
3173       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute80;
3174    end if;
3175 
3176    if g_panda_rec_table(p_g_line_index).p_pricing_attribute81 is not null then
3177       i := px_Req_line_attr_tbl.count+1;
3178       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3179       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3180       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3181       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE81';
3182       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute81;
3183    end if;
3184 
3185    if g_panda_rec_table(p_g_line_index).p_pricing_attribute82 is not null then
3186       i := px_Req_line_attr_tbl.count+1;
3187       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3188       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3189       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3190       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE82';
3191       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute82;
3192    end if;
3193 
3194    if g_panda_rec_table(p_g_line_index).p_pricing_attribute83 is not null then
3195       i := px_Req_line_attr_tbl.count+1;
3196       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3197       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3198       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3199       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE83';
3200       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute83;
3201    end if;
3202 
3203    if g_panda_rec_table(p_g_line_index).p_pricing_attribute84 is not null then
3204       i := px_Req_line_attr_tbl.count+1;
3205       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3206       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3207       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3208       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE84';
3209       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute84;
3210    end if;
3211 
3212    if g_panda_rec_table(p_g_line_index).p_pricing_attribute85 is not null then
3213       i := px_Req_line_attr_tbl.count+1;
3214       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3215       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3216       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3217       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE85';
3218       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute85;
3219    end if;
3220 
3221    if g_panda_rec_table(p_g_line_index).p_pricing_attribute86 is not null then
3222       i := px_Req_line_attr_tbl.count+1;
3223       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3224       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3225       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3226       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE86';
3227       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute86;
3228    end if;
3229 
3230    if g_panda_rec_table(p_g_line_index).p_pricing_attribute87 is not null then
3231       i := px_Req_line_attr_tbl.count+1;
3232       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3233       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3234       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3235       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE87';
3236       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute87;
3237    end if;
3238 
3239    if g_panda_rec_table(p_g_line_index).p_pricing_attribute88 is not null then
3240       i := px_Req_line_attr_tbl.count+1;
3241       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3242       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3243       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3244       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE88';
3245       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute88;
3246    end if;
3247 
3248    if g_panda_rec_table(p_g_line_index).p_pricing_attribute89 is not null then
3249       i := px_Req_line_attr_tbl.count+1;
3250       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3251       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3252       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3253       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE89';
3254       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute89;
3255    end if;
3256 
3257 
3258    if g_panda_rec_table(p_g_line_index).p_pricing_attribute90 is not null then
3259       i := px_Req_line_attr_tbl.count+1;
3260       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3261       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3262       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3263       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE90';
3264       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute90;
3265    end if;
3266 
3267    if g_panda_rec_table(p_g_line_index).p_pricing_attribute91 is not null then
3268       i := px_Req_line_attr_tbl.count+1;
3269       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3270       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3271       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3272       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE91';
3273       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute91;
3274    end if;
3275 
3276    if g_panda_rec_table(p_g_line_index).p_pricing_attribute92 is not null then
3277       i := px_Req_line_attr_tbl.count+1;
3278       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3279       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3280       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3281       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE92';
3282       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute92;
3283    end if;
3284 
3285    if g_panda_rec_table(p_g_line_index).p_pricing_attribute93 is not null then
3286       i := px_Req_line_attr_tbl.count+1;
3287       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3288       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3289       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3290       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE93';
3291       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=g_panda_rec_table(p_g_line_index).p_pricing_attribute93;
3292    end if;
3293 
3294    if g_panda_rec_table(p_g_line_index).p_pricing_attribute94 is not null then
3295       i := px_Req_line_attr_tbl.count+1;
3296       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3297       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3298       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3299       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE94';
3300       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute94;
3301    end if;
3302 
3303    if g_panda_rec_table(p_g_line_index).p_pricing_attribute95 is not null then
3304       i := px_Req_line_attr_tbl.count+1;
3305       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3306       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3307       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3308       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE95';
3309       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute95;
3310    end if;
3311 
3312    if g_panda_rec_table(p_g_line_index).p_pricing_attribute96 is not null then
3313       i := px_Req_line_attr_tbl.count+1;
3314       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3315       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3316       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3317       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE96';
3318       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute96;
3319    end if;
3320 
3321    if g_panda_rec_table(p_g_line_index).p_pricing_attribute97 is not null then
3322       i := px_Req_line_attr_tbl.count+1;
3323       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3324       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3325       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3326       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE97';
3327       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute97;
3328    end if;
3329 
3330    if g_panda_rec_table(p_g_line_index).p_pricing_attribute98 is not null then
3331       i := px_Req_line_attr_tbl.count+1;
3332       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3333       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3334       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3335       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE98';
3336       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute98;
3337    end if;
3338 
3339    if g_panda_rec_table(p_g_line_index).p_pricing_attribute99 is not null then
3340       i := px_Req_line_attr_tbl.count+1;
3341       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3342       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3343       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3344       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE99';
3345       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_panda_rec_table(p_g_line_index).p_pricing_attribute99;
3346    end if;
3347 
3348    if g_panda_rec_table(p_g_line_index).p_pricing_attribute100 is not null then
3349       i := px_Req_line_attr_tbl.count+1;
3350       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3351       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3352       px_Req_line_attr_tbl(i).pricing_context := g_panda_rec_table(p_g_line_index).p_pricing_context;
3353       px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE100';
3354       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From:=g_panda_rec_table(p_g_line_index).p_pricing_attribute100;
3355    end if;
3356 
3357    end if; -- if line_id is not null
3358 
3359    oe_debug_pub.add(' p_line_id='||p_line_id||
3360                     ' promo count='||g_promotions_tbl.COUNT
3361                     );
3362 
3363    IF p_line_id is not null and g_promotions_tbl.COUNT > 0 then
3364 
3365    FOR k in g_promotions_tbl.first..g_promotions_tbl.last
3366    LOOP
3367 
3368      oe_debug_pub.add('promo line_id='||g_promotions_tbl(k).p_line_id||
3369                       ' p_level='||g_promotions_tbl(k).p_level||
3370                       ' p_line_id='||p_line_id);
3371 
3372 
3373    IF g_promotions_tbl(k).p_level <> 'ORDER' then
3374 
3375      IF g_promotions_tbl(k).p_line_id = p_line_id and
3376         g_promotions_tbl(k).p_type = 'COUPON' then
3377 
3378        oe_debug_pub.add(' Append line coupon attr='||g_promotions_tbl(k).p_pricing_attribute3);
3379        i := px_Req_line_attr_tbl.count+1;
3380        px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3381        px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3382        --If asked_for_rec.flex_title = 'QP_ATTR_DEFNS_QUALIFIER' then
3383        px_Req_line_attr_tbl(i).Pricing_Context := 'MODLIST';
3384        px_Req_line_attr_tbl(i).Pricing_Attribute := 'QUALIFIER_ATTRIBUTE3';
3385        px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_promotions_tbl(k).p_PRICING_ATTRIBUTE3;
3386 
3387      ELSIF g_promotions_tbl(k).p_line_id = p_line_id and
3388            g_promotions_tbl(k).p_type = 'PROMOTION' then
3389 
3390       oe_debug_pub.add(' Append Line Promotion attr1='||g_promotions_tbl(k).p_pricing_attribute1);
3391       i := px_Req_line_attr_tbl.count+1;
3392       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3393       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3394       px_Req_line_attr_tbl(i).Pricing_Context := 'MODLIST';
3395       px_Req_line_attr_tbl(i).Pricing_Attribute := 'QUALIFIER_ATTRIBUTE1';
3396       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_promotions_tbl(k).p_PRICING_ATTRIBUTE1;
3397 
3398 
3399       IF g_promotions_tbl(k).p_pricing_attribute2 is not null then
3400         oe_debug_pub.add(' Append Line Promotion attr2='||g_promotions_tbl(k).p_pricing_attribute2);
3401         i := px_Req_line_attr_tbl.count+1;
3402         px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
3403         px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3404         px_Req_line_attr_tbl(i).Pricing_Context := 'MODLIST';
3405         px_Req_line_attr_tbl(i).Pricing_Attribute := 'QUALIFIER_ATTRIBUTE2';
3406         px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_promotions_tbl(k).p_PRICING_ATTRIBUTE2;
3407       END IF; -- attr2 is not null
3408 
3409     END IF; -- if type coupon
3410   END IF; -- if level is not ORDER
3411   END LOOP;
3412   END IF; -- if promotions temp table is not null
3413 
3414 
3415   oe_debug_pub.add(' Applying Header Promotions p_line_id='||p_line_id||
3416                     ' promo count='||g_promotions_tbl.COUNT||
3417                    ' p_line_id='||p_line_id
3418                     );
3419 
3420   IF p_line_id is null and g_promotions_tbl.COUNT > 0 then
3421    FOR k in g_promotions_tbl.first..g_promotions_tbl.last
3422    LOOP
3423 
3424    IF g_promotions_tbl(k).p_level = 'ORDER' then
3425 
3426      IF g_promotions_tbl(k).p_type = 'COUPON' then
3427 
3428        oe_debug_pub.add(' Append Hdr coupon attr='||g_promotions_tbl(k).p_pricing_attribute3);
3429        i := px_Req_line_attr_tbl.count+1;
3430        px_Req_line_attr_tbl(i).Line_Index := 1; --p_Line_Index;
3431        px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3432        --If asked_for_rec.flex_title = 'QP_ATTR_DEFNS_QUALIFIER' then
3433        px_Req_line_attr_tbl(i).Pricing_Context := 'MODLIST';
3434        px_Req_line_attr_tbl(i).Pricing_Attribute := 'QUALIFIER_ATTRIBUTE3';
3435        px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_promotions_tbl(k).p_PRICING_ATTRIBUTE3;
3436 
3437      ELSIF g_promotions_tbl(k).p_type = 'PROMOTION' then
3438 
3439       oe_debug_pub.add(' Append Hdr Promotion attr1='||g_promotions_tbl(k).p_pricing_attribute1);
3440       i := px_Req_line_attr_tbl.count+1;
3441       px_Req_line_attr_tbl(i).Line_Index := 1; --p_Line_Index;
3442       px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3443       px_Req_line_attr_tbl(i).Pricing_Context := 'MODLIST';
3444       px_Req_line_attr_tbl(i).Pricing_Attribute := 'QUALIFIER_ATTRIBUTE1';
3445       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_promotions_tbl(k).p_PRICING_ATTRIBUTE1;
3446 
3447 
3448       IF g_promotions_tbl(k).p_pricing_attribute2 is not null then
3449         oe_debug_pub.add(' Append Hdr Promotion Line attr2='||g_promotions_tbl(k).p_pricing_attribute2);
3450         i := px_Req_line_attr_tbl.count+1;
3451         px_Req_line_attr_tbl(i).Line_Index := 1; --p_Line_Index;
3452         px_Req_line_attr_tbl(i).Validated_Flag := 'N';
3453         px_Req_line_attr_tbl(i).Pricing_Context := 'MODLIST';
3454         px_Req_line_attr_tbl(i).Pricing_Attribute := 'QUALIFIER_ATTRIBUTE2';
3455         px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := g_promotions_tbl(k).p_PRICING_ATTRIBUTE2;
3456       END IF; -- attr2 is not null
3457 
3458     END IF; -- if type coupon
3459   END IF; -- if level is not ORDER
3460 
3461   END LOOP;
3462   END IF; -- if promotions temp table is not null and for header
3463 
3464   IF l_debug_level  > 0 THEN
3465     oe_debug_pub.add(  'EXITING oe_oe_pricing_availability.APPEND_ATTRIBUTES' , 1 ) ;
3466   END IF;
3467 
3468 END Append_attributes;
3469 
3470 
3471 
3472 PROCEDURE Append_attr_to_ttables(px_req_line_attr_tbl in out nocopy oe_oe_pricing_availability.QP_LINE_ATTR_TBL_TYPE
3473 				 )
3474 IS
3475    i number;
3476    k number;
3477    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3478    l_attribute_type VARCHAR2(30);
3479 BEGIN
3480    --Temp Tables
3481    k:=G_ATTR_PRICING_ATTRIBUTE_TBL.count;
3482    i := px_req_line_attr_tbl.first;
3483    if l_debug_level >0 then
3484       oe_debug_pub.add('****populating attributes in to temp table **********');
3485    end if;
3486 
3487    if l_debug_level > 0 then
3488 
3489       oe_debug_pub.add('k='||k||'i='||i);
3490    end if;
3491 
3492    while i is not null  loop
3493       k:=k+1;
3494       IF l_debug_level  > 0 THEN
3495 	 oe_debug_pub.add(  'POPULATE LINE ATTRS'||K||' '||PX_REQ_LINE_ATTR_TBL ( I ) .PRICING_CONTEXT , 3 ) ;
3496       END IF;
3497 
3498       IF (px_req_line_attr_tbl(I).PRICING_CONTEXT = QP_PREQ_GRP.G_ITEM_CONTEXT) THEN
3499 	 l_attribute_type := QP_PREQ_GRP.G_PRODUCT_TYPE;
3500       ELSIF (px_req_line_attr_tbl(I).PRICING_CONTEXT = 'MODLIST') THEN
3501 	 l_attribute_type := QP_PREQ_GRP.G_QUALIFIER_TYPE;
3502       ELSE
3503 	 l_attribute_type := QP_PREQ_GRP.G_PRICING_TYPE;
3504       END IF;
3505       G_ATTR_LINE_INDEX_tbl(k) := px_req_line_attr_tbl(i).line_index;
3506       IF l_debug_level  > 0 THEN
3507 	 oe_debug_pub.add(  'LINE_INDEX:'||G_ATTR_LINE_INDEX_TBL ( K ) ) ;
3508       END IF;
3509       G_ATTR_LINE_DETAIL_INDEX_tbl(k) := NULL;
3510       G_ATTR_ATTRIBUTE_LEVEL_tbl(k) := QP_PREQ_GRP.G_LINE_LEVEL;
3511       G_ATTR_VALIDATED_FLAG_tbl(k) := 'N';
3512       G_ATTR_ATTRIBUTE_TYPE_tbl(k) := l_attribute_type;
3513       G_ATTR_PRICING_CONTEXT_tbl(k)
3514 	 := px_req_line_attr_tbl(i).pricing_context;
3515       G_ATTR_PRICING_ATTRIBUTE_tbl(k)
3516 	 := px_req_line_attr_tbl(i).pricing_attribute;
3517       G_ATTR_APPLIED_FLAG_tbl(k) := QP_PREQ_GRP.G_LIST_NOT_APPLIED;--NULL;
3518 	 G_ATTR_PRICING_STATUS_CODE_tbl(k) := QP_PREQ_GRP.G_STATUS_UNCHANGED;
3519       G_ATTR_PRICING_ATTR_FLAG_tbl (k) := QP_PREQ_GRP.G_YES;--NULL;
3520 	 G_ATTR_LIST_HEADER_ID_tbl(k) := NULL;
3521       G_ATTR_LIST_LINE_ID_tbl(k) := NULL;
3522       G_ATTR_VALUE_FROM_tbl(k)      :=px_req_line_attr_tbl(i).pricing_attr_value_from;
3523       G_ATTR_SETUP_VALUE_FROM_tbl(k):=NULL;
3524       G_ATTR_VALUE_TO_tbl(k)      :=NULL;
3525       G_ATTR_SETUP_VALUE_TO_tbl(k) := NULL;
3526       G_ATTR_GROUPING_NUMBER_tbl(k) := NULL;
3527       G_ATTR_NO_QUAL_IN_GRP_tbl(k)     :=NULL;
3528       G_ATTR_COMP_OPERATOR_TYPE_tbl(k):= NULL;
3529       G_ATTR_PRICING_STATUS_TEXT_tbl(k) :=NULL;
3530       G_ATTR_QUAL_PRECEDENCE_tbl(k):=NULL;
3531       G_ATTR_DATATYPE_tbl(k)          := NULL;
3532       G_ATTR_QUALIFIER_TYPE_tbl(k)   := NULL;
3533       G_ATTR_PRODUCT_UOM_CODE_TBL(k) := NULL;
3534       G_ATTR_EXCLUDER_FLAG_TBL(k) := NULL;
3535       G_ATTR_PRICING_PHASE_ID_TBL(k) := NULL;
3536       G_ATTR_INCOM_GRP_CODE_TBL(k):=NULL;
3537       G_ATTR_LDET_TYPE_CODE_TBL(k):=NULL;
3538       G_ATTR_MODIFIER_LEVEL_CODE_TBL(k):=NULL;
3539       G_ATTR_PRIMARY_UOM_FLAG_TBL(k):=NULL;
3540       i:= px_req_line_attr_tbl.next(i);
3541     END LOOP;
3542 
3543 
3544   --G_ATTR_LINE_INDEX_tbl(G_ATTR_LINE_INDEX_tbl.count+1):=2;
3545   --G_ATTR_ATTRIBUTE_LEVEL_tbl(G_ATTR_LINE_INDEX_tbl.count):=QP_PREQ_GRP.G_LINE_LEVEL;
3546 
3547    --Temp_tables population ends
3548 
3549 end append_attr_to_TTables;
3550 
3551 PROCEDURE Reset_All_Tbls
3552 AS
3553 l_routine VARCHAR2(240):='QP_PREQ_GRP.Reset_All_Tbls';
3554 --
3555 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3556 --
3557 BEGIN
3558  G_LINE_INDEX_tbl.delete;
3559  G_LINE_TYPE_CODE_TBL.delete          ;
3560  G_PRICING_EFFECTIVE_DATE_TBL.delete  ;
3561  G_ACTIVE_DATE_FIRST_TBL.delete       ;
3562  G_ACTIVE_DATE_FIRST_TYPE_TBL.delete  ;
3563  G_ACTIVE_DATE_SECOND_TBL.delete      ;
3564  G_ACTIVE_DATE_SECOND_TYPE_TBL.delete ;
3565  G_LINE_QUANTITY_TBL.delete           ;
3566  G_LINE_UOM_CODE_TBL.delete           ;
3567  G_REQUEST_TYPE_CODE_TBL.delete       ;
3568  G_PRICED_QUANTITY_TBL.delete         ;
3569  G_UOM_QUANTITY_TBL.delete         ;
3570  G_PRICED_UOM_CODE_TBL.delete         ;
3571  G_CURRENCY_CODE_TBL.delete           ;
3572  G_UNIT_PRICE_TBL.delete              ;
3573  G_PERCENT_PRICE_TBL.delete           ;
3574  G_ADJUSTED_UNIT_PRICE_TBL.delete     ;
3575  G_PROCESSED_FLAG_TBL.delete          ;
3576  G_PRICE_FLAG_TBL.delete              ;
3577  G_LINE_ID_TBL.delete                 ;
3578  G_PROCESSING_ORDER_TBL.delete        ;
3579  G_ROUNDING_FLAG_TBL.delete;
3580  G_ROUNDING_FACTOR_TBL.delete              ;
3581  G_PRICING_STATUS_CODE_TBL.delete       ;
3582  G_PRICING_STATUS_TEXT_TBL.delete       ;
3583  G_ATTR_LINE_INDEX_tbl.delete;
3584  G_ATTR_ATTRIBUTE_LEVEL_tbl.delete;
3585  G_ATTR_VALIDATED_FLAG_tbl.delete;
3586  G_ATTR_ATTRIBUTE_TYPE_tbl.delete;
3587  G_ATTR_PRICING_CONTEXT_tbl.delete;
3588  G_ATTR_PRICING_ATTRIBUTE_tbl.delete;
3589  G_ATTR_APPLIED_FLAG_tbl.delete;
3590  G_ATTR_PRICING_STATUS_CODE_tbl.delete;
3591  G_ATTR_PRICING_ATTR_FLAG_tbl.delete;
3592  G_ATTR_LIST_HEADER_ID_tbl.delete;
3593  G_ATTR_LIST_LINE_ID_tbl.delete;
3594  G_ATTR_VALUE_FROM_tbl.delete;
3595  G_ATTR_SETUP_VALUE_FROM_tbl.delete;
3596  G_ATTR_VALUE_TO_tbl.delete;
3597  G_ATTR_SETUP_VALUE_TO_tbl.delete;
3598  G_ATTR_GROUPING_NUMBER_tbl.delete;
3599  G_ATTR_NO_QUAL_IN_GRP_tbl.delete;
3600  G_ATTR_COMP_OPERATOR_TYPE_tbl.delete;
3601  G_ATTR_VALIDATED_FLAG_tbl.delete;
3602  G_ATTR_APPLIED_FLAG_tbl.delete;
3603  G_ATTR_PRICING_STATUS_CODE_tbl.delete;
3604  G_ATTR_PRICING_STATUS_TEXT_tbl.delete;
3605  G_ATTR_QUAL_PRECEDENCE_tbl.delete;
3606  G_ATTR_DATATYPE_tbl.delete;
3607  G_ATTR_PRICING_ATTR_FLAG_tbl.delete    ;
3608  G_ATTR_QUALIFIER_TYPE_tbl.delete;
3609  G_ATTR_PRODUCT_UOM_CODE_TBL.delete;
3610  G_ATTR_EXCLUDER_FLAG_TBL.delete;
3611  G_ATTR_PRICING_PHASE_ID_TBL.delete;
3612  G_ATTR_INCOM_GRP_CODE_TBL.delete;
3613  G_ATTR_LDET_TYPE_CODE_TBL.delete;
3614  G_ATTR_MODIFIER_LEVEL_CODE_TBL.delete;
3615  G_ATTR_PRIMARY_UOM_FLAG_TBL.delete;
3616 EXCEPTION
3617 WHEN OTHERS THEN
3618 IF l_debug_level  > 0 THEN
3619     oe_debug_pub.add(  L_ROUTINE||': '||SQLERRM , 1 ) ;
3620 END IF;
3621 END reset_all_tbls;
3622 
3623 
3624 procedure Populate_Temp_Table
3625 IS
3626    l_return_status  varchar2(1) := FND_API.G_RET_STS_SUCCESS;
3627    l_return_status_Text     varchar2(240) ;
3628    --
3629    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3630    --
3631 BEGIN
3632    IF l_debug_level  > 0 THEN
3633       oe_debug_pub.add(  'BEFORE DIRECT INSERT INTO TEMP TABLE: BULK INSERT'||G_LINE_INDEX_TBL.COUNT , 1 ) ;
3634    END IF;
3635    QP_PREQ_GRP.INSERT_LINES2
3636       (p_LINE_INDEX =>   G_LINE_INDEX_TBL,
3637        p_LINE_TYPE_CODE =>  G_LINE_TYPE_CODE_TBL,
3638        p_PRICING_EFFECTIVE_DATE =>G_PRICING_EFFECTIVE_DATE_TBL,
3639        p_ACTIVE_DATE_FIRST       =>G_ACTIVE_DATE_FIRST_TBL,
3640        p_ACTIVE_DATE_FIRST_TYPE  =>G_ACTIVE_DATE_FIRST_TYPE_TBL,
3641        p_ACTIVE_DATE_SECOND      =>G_ACTIVE_DATE_SECOND_TBL,
3642        p_ACTIVE_DATE_SECOND_TYPE =>G_ACTIVE_DATE_SECOND_TYPE_TBL,
3643        p_LINE_QUANTITY =>     G_LINE_QUANTITY_TBL,
3644        p_LINE_UOM_CODE =>     G_LINE_UOM_CODE_TBL,
3645        p_REQUEST_TYPE_CODE => G_REQUEST_TYPE_CODE_TBL,
3646        p_PRICED_QUANTITY =>   G_PRICED_QUANTITY_TBL,
3647        p_PRICED_UOM_CODE =>   G_PRICED_UOM_CODE_TBL,
3648        p_CURRENCY_CODE   =>   G_CURRENCY_CODE_TBL,
3649        p_UNIT_PRICE      =>   G_UNIT_PRICE_TBL,
3650        p_PERCENT_PRICE   =>   G_PERCENT_PRICE_TBL,
3651        p_UOM_QUANTITY =>      G_UOM_QUANTITY_TBL,
3652        p_ADJUSTED_UNIT_PRICE =>G_ADJUSTED_UNIT_PRICE_TBL,
3653        p_UPD_ADJUSTED_UNIT_PRICE =>G_UPD_ADJUSTED_UNIT_PRICE_TBL,
3654        p_PROCESSED_FLAG      =>G_PROCESSED_FLAG_TBL,
3655        p_PRICE_FLAG          =>G_PRICE_FLAG_TBL,
3656        p_LINE_ID             =>G_LINE_ID_TBL,
3657        p_PROCESSING_ORDER    =>G_PROCESSING_ORDER_TBL,
3658        p_PRICING_STATUS_CODE =>G_PRICING_STATUS_CODE_tbl,
3659        p_PRICING_STATUS_TEXT =>G_PRICING_STATUS_TEXT_tbl,
3660        p_ROUNDING_FLAG       =>G_ROUNDING_FLAG_TBL,
3661        p_ROUNDING_FACTOR     =>G_ROUNDING_FACTOR_TBL,
3662        p_QUALIFIERS_EXIST_FLAG => G_QUALIFIERS_EXIST_FLAG_TBL,
3663        p_PRICING_ATTRS_EXIST_FLAG =>G_PRICING_ATTRS_EXIST_FLAG_TBL,
3664        p_PRICE_LIST_ID          => G_PRICE_LIST_ID_TBL,
3665        p_VALIDATED_FLAG         => G_PL_VALIDATED_FLAG_TBL,
3666        p_PRICE_REQUEST_CODE     => G_PRICE_REQUEST_CODE_TBL,
3667        p_USAGE_PRICING_TYPE  =>    G_USAGE_PRICING_TYPE_tbl,
3668        p_line_category       =>    G_LINE_CATEGORY_tbl,
3669        --p_catchweight_qty     =>    G_CATCHWEIGHT_QTY_tbl,
3670        --p_actual_order_qty    =>    G_ACTUAL_ORDER_QTY_TBL,
3671        x_status_code         =>l_return_status,
3672        x_status_text         =>l_return_status_text);
3673 
3674    IF l_return_status = FND_API.G_RET_STS_ERROR THEN
3675       IF l_debug_level  > 0 THEN
3676 	 oe_debug_pub.add(  'WRONG IN INSERT_LINES2'||L_RETURN_STATUS_TEXT , 1 ) ;
3677       END IF;
3678       FND_MESSAGE.SET_NAME('ONT','ONT_PRICING_ERRORS'); --bug#7149497
3679       FND_MESSAGE.SET_TOKEN('ERR_TEXT',l_return_status_text);
3680       OE_MSG_PUB.Add;
3681       RAISE FND_API.G_EXC_ERROR;
3682    END IF;
3683 
3684    IF G_ATTR_LINE_INDEX_tbl.count > 0 THEN
3685       QP_PREQ_GRP.INSERT_LINE_ATTRS2
3686 	 (    G_ATTR_LINE_INDEX_tbl,
3687 	      G_ATTR_LINE_DETAIL_INDEX_tbl  ,
3688 	      G_ATTR_ATTRIBUTE_LEVEL_tbl    ,
3689 	      G_ATTR_ATTRIBUTE_TYPE_tbl     ,
3690 	      G_ATTR_LIST_HEADER_ID_tbl     ,
3691 	      G_ATTR_LIST_LINE_ID_tbl       ,
3692 	      G_ATTR_PRICING_CONTEXT_tbl            ,
3693 	      G_ATTR_PRICING_ATTRIBUTE_tbl          ,
3694 	      G_ATTR_VALUE_FROM_tbl         ,
3695 	      G_ATTR_SETUP_VALUE_FROM_tbl   ,
3696 	      G_ATTR_VALUE_TO_tbl           ,
3697 	      G_ATTR_SETUP_VALUE_TO_tbl     ,
3698 	      G_ATTR_GROUPING_NUMBER_tbl         ,
3699 	      G_ATTR_NO_QUAL_IN_GRP_tbl      ,
3700 	      G_ATTR_COMP_OPERATOR_TYPE_tbl  ,
3701 	      G_ATTR_VALIDATED_FLAG_tbl            ,
3702 	      G_ATTR_APPLIED_FLAG_tbl              ,
3703 	      G_ATTR_PRICING_STATUS_CODE_tbl       ,
3704 	      G_ATTR_PRICING_STATUS_TEXT_tbl       ,
3705 	      G_ATTR_QUAL_PRECEDENCE_tbl      ,
3706 	      G_ATTR_DATATYPE_tbl                  ,
3707 	      G_ATTR_PRICING_ATTR_FLAG_tbl         ,
3708 	      G_ATTR_QUALIFIER_TYPE_tbl            ,
3709 	      G_ATTR_PRODUCT_UOM_CODE_TBL          ,
3710 	      G_ATTR_EXCLUDER_FLAG_TBL             ,
3711 	      G_ATTR_PRICING_PHASE_ID_TBL ,
3712 	      G_ATTR_INCOM_GRP_CODE_TBL,
3713 	      G_ATTR_LDET_TYPE_CODE_TBL,
3714 	      G_ATTR_MODIFIER_LEVEL_CODE_TBL,
3715 	      G_ATTR_PRIMARY_UOM_FLAG_TBL,
3716 	      l_return_status                   ,
3717 	      l_return_status_text                   );
3718 
3719       IF l_return_status = FND_API.G_RET_STS_ERROR THEN
3720 	 IF l_debug_level  > 0 THEN
3721 	    oe_debug_pub.add(  'ERROR INSERTING INTO LINE ATTRS'||SQLERRM ) ;
3722 	 END IF;
3723 	 FND_MESSAGE.SET_NAME('ONT','ONT_PRICING_ERRORS'); --bug#7149497
3724 	 FND_MESSAGE.SET_TOKEN('ERR_TEXT',l_return_status_text);
3725 	 OE_MSG_PUB.Add;
3726 	 raise fnd_api.g_exc_unexpected_error;
3727       END IF;
3728 
3729    END IF;
3730    IF l_debug_level  > 0 THEN
3731       oe_debug_pub.add(  'AFTER DIRECT INSERT INTO TEMP TABLE: BULK INSERT' , 1 ) ;
3732    END IF;
3733 
3734 EXCEPTION
3735    WHEN OTHERS THEN
3736       RAISE FND_API.G_EXC_ERROR;
3737 END POPULATE_TEMP_TABLE;
3738 
3739 
3740 PROCEDURE Populate_results
3741    (x_line_tbl          OUT NOCOPY /* file.sql.39 change */  OE_OE_PRICING_AVAILABILITY.QP_LINE_TBL_TYPE,
3742     x_line_qual_tbl        OUT NOCOPY /* file.sql.39 change */  OE_OE_PRICING_AVAILABILITY.QP_QUAL_TBL_TYPE,
3743     x_line_attr_tbl        OUT NOCOPY /* file.sql.39 change */  OE_OE_PRICING_AVAILABILITY.QP_LINE_ATTR_TBL_TYPE,
3744     x_line_detail_tbl      OUT NOCOPY /* file.sql.39 change */  OE_OE_PRICING_AVAILABILITY.QP_LINE_DETAIL_TBL_TYPE,
3745     x_line_detail_qual_tbl OUT NOCOPY /* file.sql.39 change */  OE_OE_PRICING_AVAILABILITY.QP_LINE_DQUAL_TBL_TYPE,
3746     x_line_detail_attr_tbl OUT NOCOPY /* file.sql.39 change */  OE_OE_PRICING_AVAILABILITY.QP_LINE_DATTR_TBL_TYPE,
3747     x_related_lines_tbl    OUT NOCOPY /* file.sql.39 change */  OE_OE_PRICING_AVAILABILITY.QP_RLTD_LINES_TBL_TYPE)
3748 AS
3749 
3750   -- Cursor l_lines_cur changed for removing NMV SQL Id : 14877269
3751 
3752   CURSOR l_lines_cur IS
3753   SELECT qpt.line_index, qpt.line_id, qpt.price_list_header_id,
3754        qpt.line_type_code, qpt.line_quantity, qpt.line_uom_code,
3755        qpt.line_unit_price, qpt.rounding_factor, qpt.priced_quantity,
3756        qpt.uom_quantity, qpt.priced_uom_code, qpt.currency_code,
3757        qpt.unit_price, qpt.percent_price, qpt.parent_price,
3758        qpt.parent_quantity, qpt.parent_uom_code, qpt.price_flag,
3759        qpt.adjusted_unit_price, qpt.updated_adjusted_unit_price,
3760        qpt.processing_order, qpt.processed_code, qpt.pricing_status_code,
3761        qpt.pricing_status_text, qpt.hold_code, qpt.hold_text,
3762        qpt.price_request_code, qpt.pricing_effective_date, qpt.extended_price,
3763        qpt.order_uom_selling_price
3764   FROM qp_preq_lines_tmp_t qpt
3765  WHERE qp_java_engine_util_pub.java_engine_running = 'N'
3766    AND request_id = NVL (SYS_CONTEXT ('qp_context', 'request_id'), 1)
3767  UNION ALL
3768   SELECT qpt.line_index, qpt.line_id, qpt.price_list_header_id,
3769        qpt.line_type_code, qpt.line_quantity, qpt.line_uom_code,
3770        qpt.line_unit_price, qpt.rounding_factor, qpt.priced_quantity,
3771        qpt.uom_quantity, qpt.priced_uom_code, qpt.currency_code,
3772        qpt.unit_price, qpt.percent_price, qpt.parent_price,
3773        qpt.parent_quantity, qpt.parent_uom_code, qpt.price_flag,
3774        qpt.adjusted_unit_price, qpt.updated_adjusted_unit_price,
3775        qpt.processing_order, qpt.processed_code, qpt.pricing_status_code,
3776        qpt.pricing_status_text, qpt.hold_code, qpt.hold_text,
3777        qpt.price_request_code, qpt.pricing_effective_date, qpt.extended_price,
3778        qpt.order_uom_selling_price
3779   FROM qp_int_lines_t qpt
3780  WHERE qp_java_engine_util_pub.java_engine_running = 'Y'
3781    AND request_id = NVL (SYS_CONTEXT ('qp_context', 'request_id'), -9999);
3782 
3783 
3784 
3785   CURSOR l_qual_cur (L_ATTRIBUTE_LEVEL VARCHAR2)IS
3786     SELECT QPLAT.LINE_INDEX,
3787            QPLAT.LINE_DETAIL_INDEX,
3788            QPLAT.CONTEXT,
3789            QPLAT.ATTRIBUTE,
3790            QPLAT.SETUP_VALUE_FROM,
3791            QPLAT.SETUP_VALUE_TO,
3792            QPLAT.COMPARISON_OPERATOR_TYPE_CODE,
3793            QPLAT.VALIDATED_FLAG,
3794            QPLAT.PRICING_STATUS_CODE,
3795            QPLAT.PRICING_STATUS_TEXT
3796       FROM  QP_PREQ_LDETS_TMP QPLD ,
3797 	    QP_PREQ_LINE_ATTRS_TMP QPLAT
3798      WHERE QPLD.LINE_DETAIL_INDEX = QPLAT.LINE_DETAIL_INDEX
3799        AND   QPLD.PRICING_STATUS_CODE = QP_PREQ_GRP.G_STATUS_NEW
3800        AND   QPLAT.ATTRIBUTE_TYPE = 'QUALIFIER';
3801            --AND QPLAT.PRICING_STATUS_CODE = G_STATUS_NEW;
3802 
3803 
3804   CURSOR l_pricing_attr_cur IS
3805     SELECT QPLAT_PRICING.CONTEXT        PRICING_CONTEXT,
3806            QPLAT_PRICING.ATTRIBUTE      PRICING_ATTRIBUTE,
3807            nvl(QPLAT_PRICING.SETUP_VALUE_FROM,QPLAT_PRICING.VALUE_FROM)     PRICING_ATTR_VALUE_FROM,
3808            QPLAT_PRICING.SETUP_VALUE_TO       PRICING_ATTR_VALUE_TO,
3809            QPLAT_PRICING.COMPARISON_OPERATOR_TYPE_CODE,
3810            QPLAT_PRICING.LINE_DETAIL_INDEX,
3811            QPLAT_PRICING.LINE_INDEX,
3812            QPLAT_PRICING.VALIDATED_FLAG
3813       FROM  QP_PREQ_LDETS_TMP QPLD ,
3814 	    QP_PREQ_LINE_ATTRS_TMP QPLAT_PRICING
3815      WHERE QPLD.LINE_DETAIL_INDEX = QPLAT_PRICING.LINE_DETAIL_INDEX
3816        AND   QPLD.PRICING_STATUS_CODE = QP_PREQ_GRP.G_STATUS_NEW
3817        AND   QPLAT_PRICING.ATTRIBUTE_TYPE IN ('PRICING','PRODUCT');
3818   --AND QPLAT_PRICING.PRICING_STATUS_CODE = G_STATUS_NEW;
3819 
3820 
3821  -- Cursor l_ldets_cur is changed to remove NMV and reduce Sharable Memory SQL Id 14877295
3822 
3823 CURSOR l_ldets_cur IS
3824 SELECT qpt.line_detail_index, qpt.line_detail_type_code, qpt.line_index,
3825        qpt.created_from_list_header_id list_header_id,
3826        qpt.created_from_list_line_id list_line_id,
3827        qpt.created_from_list_line_type list_line_type_code,
3828        qpt.price_break_type_code, qpt.line_quantity, qpt.adjustment_amount,qpt.automatic_flag,
3829        qpt.pricing_phase_id, qpt.operand_calculation_code, qpt.operand_value,
3830        qpt.pricing_group_sequence, qpt.created_from_list_type_code,
3831        qpt.applied_flag, qpt.pricing_status_code, qpt.pricing_status_text,
3832        qpt.limit_code, qpt.limit_text, qpt.list_line_no, qpt.group_quantity,
3833        qpt.group_amount, qpt.updated_flag, qpt.process_code,
3834        qpt.calculation_code, qpt.change_reason_code, qpt.change_reason_text,
3835        qpt.order_qty_adj_amt, b.substitution_value substitution_value_to,
3836        b.substitution_attribute, b.accrual_flag, b.modifier_level_code,
3837        b.estim_gl_value, b.accrual_conversion_rate, b.override_flag,
3838        b.print_on_invoice_flag, b.inventory_item_id, b.organization_id,
3839        b.related_item_id, b.relationship_type_id, b.estim_accrual_rate,
3840        b.expiration_date, b.benefit_price_list_line_id, b.recurring_flag,
3841        b.recurring_value, b.benefit_limit, b.charge_type_code,
3842        b.charge_subtype_code, b.benefit_qty, b.benefit_uom_code,
3843        b.proration_type_code, b.include_on_returns_flag,
3844        b.rebate_transaction_type_code, b.number_expiration_periods,
3845        b.expiration_period_uom, b.comments
3846   FROM qp_preq_ldets_tmp_t qpt, qp_list_lines b
3847  WHERE qp_java_engine_util_pub.java_engine_running = 'N'
3848    AND qpt.request_id = NVL (SYS_CONTEXT ('QP_CONTEXT', 'REQUEST_ID'), 1)
3849    AND qpt.created_from_list_line_id = b.list_line_id
3850    AND qpt.pricing_status_code = QP_PREQ_GRP.G_STATUS_NEW
3851 UNION ALL
3852 SELECT qpt.line_detail_index, qpt.line_detail_type_code, qpt.line_index,
3853        qpt.created_from_list_header_id list_header_id, qpt.created_from_list_line_id list_line_id,
3854        qpt.created_from_list_line_type list_line_type_code, qpt.price_break_type_code,
3855        qpt.line_quantity, qpt.adjustment_amount, qpt.automatic_flag, qpt.pricing_phase_id,
3856        qpt.operand_calculation_code, qpt.operand_value,
3857        qpt.pricing_group_sequence, qpt.created_from_list_type_code,
3858        qpt.applied_flag, qpt.pricing_status_code, qpt.pricing_status_text,
3859        qpt.limit_code, qpt.limit_text, qpt.list_line_no, qpt.group_quantity,
3860        qpt.group_amount, qpt.updated_flag, qpt.process_code,
3861        qpt.calculation_code, qpt.change_reason_code, qpt.change_reason_text,
3862        qpt.order_qty_adj_amt, b.substitution_value substitution_value_to,
3863        b.substitution_attribute, b.accrual_flag, b.modifier_level_code,
3864        b.estim_gl_value, b.accrual_conversion_rate, b.override_flag,
3865        b.print_on_invoice_flag, b.inventory_item_id, b.organization_id,
3866        b.related_item_id, b.relationship_type_id, b.estim_accrual_rate,
3867        b.expiration_date, b.benefit_price_list_line_id, b.recurring_flag,
3868        b.recurring_value, b.benefit_limit, b.charge_type_code,
3869        b.charge_subtype_code, b.benefit_qty, b.benefit_uom_code,
3870        b.proration_type_code, b.include_on_returns_flag,
3871        b.rebate_transaction_type_code, b.number_expiration_periods,
3872        b.expiration_period_uom, b.comments
3873   FROM qp_int_ldets_t qpt, qp_list_lines b
3874  WHERE qp_java_engine_util_pub.java_engine_running = 'Y'
3875    AND qpt.request_id = NVL (SYS_CONTEXT ('QP_CONTEXT', 'REQUEST_ID'), -9999)
3876    AND qpt.created_from_list_line_id = b.list_line_id
3877    AND qpt.pricing_status_code = QP_PREQ_GRP.G_STATUS_NEW;
3878 
3879 
3880   CURSOR l_rltd_lines_cur IS
3881     SELECT  LINE_INDEX,
3882             LINE_DETAIL_INDEX,
3883             RELATIONSHIP_TYPE_CODE,
3884             RELATED_LINE_INDEX,
3885             RELATED_LINE_DETAIL_INDEX,
3886             PRICING_STATUS_CODE,
3887             PRICING_STATUS_TEXT
3888       FROM QP_PREQ_RLTD_LINES_TMP
3889      WHERE PRICING_STATUS_CODE = QP_PREQ_GRP.G_STATUS_NEW
3890      ORDER BY SETUP_VALUE_FROM;
3891 
3892 
3893 I PLS_INTEGER :=1;
3894 J PLS_INTEGER :=1;
3895 l_expiration_period_end_date Date;
3896 l_status_code VARCHAR2(30);
3897 l_status_text VARCHAR2(30);
3898 E_ROUTINE_ERROR EXCEPTION;
3899 l_routine VARCHAR2(240):='QP_PREQ_GRP.POPULATE_OUTPUT';
3900 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3901 
3902 BEGIN
3903 
3904    IF l_debug_level >0 then
3905    oe_debug_pub.add('----Before populate l_line_tbl-----');
3906    oe_debug_pub.add('----Line information return back to caller----');
3907    END IF;
3908 
3909    FOR l_line IN l_lines_cur LOOP
3910       --requirement from Jay, will cause holes in pl/sql table.
3911       I :=  l_line.LINE_INDEX;
3912       x_line_tbl(I).LINE_INDEX := l_line.LINE_INDEX;
3913       x_line_tbl(I).LINE_ID    := l_line.LINE_ID;
3914       x_line_tbl(I).HEADER_ID    := l_line.PRICE_LIST_HEADER_ID;
3915       x_line_tbl(I).LINE_TYPE_CODE := l_line.LINE_TYPE_CODE;
3916       x_line_tbl(I).PRICED_QUANTITY := l_line.PRICED_QUANTITY;
3917       x_line_tbl(I).CURRENCY_CODE := l_line.CURRENCY_CODE;
3918       x_line_tbl(I).ROUNDING_FACTOR := l_line.ROUNDING_FACTOR;
3919       x_line_tbl(I).PRICED_UOM_CODE := l_line.PRICED_UOM_CODE;
3920       x_line_tbl(I).UNIT_PRICE := l_line.UNIT_PRICE; --shu_latest
3921       x_line_tbl(I).LINE_QUANTITY:=l_line.LINE_QUANTITY;
3922       x_line_tbl(I).LINE_UOM_CODE:=l_line.LINE_UOM_CODE;
3923       x_line_tbl(I).LINE_UNIT_PRICE := l_line.LINE_UNIT_PRICE; --shu_latest
3924       x_line_tbl(I).UOM_QUANTITY := l_line.UOM_QUANTITY; --shu_latest
3925       x_line_tbl(I).PERCENT_PRICE := l_line.PERCENT_PRICE;
3926    -- x_line_tbl(I).ADJUSTED_UNIT_PRICE := l_line.ADJUSTED_UNIT_PRICE;
3927       x_line_tbl(I).ADJUSTED_UNIT_PRICE:= l_line.ORDER_UOM_SELLING_PRICE;
3928       x_line_tbl(I).UPDATED_ADJUSTED_UNIT_PRICE := l_line.UPDATED_ADJUSTED_UNIT_PRICE;
3929       x_line_tbl(I).PARENT_PRICE := l_line.PARENT_PRICE;
3930       x_line_tbl(I).PARENT_QUANTITY := l_line.PARENT_QUANTITY;
3931       x_line_tbl(I).PARENT_UOM_CODE := l_line.PARENT_UOM_CODE;
3932       x_line_tbl(I).PROCESSED_CODE := l_line.PROCESSED_CODE;
3933       x_line_tbl(I).PRICE_FLAG := l_line.PRICE_FLAG;
3934       x_line_tbl(I).STATUS_CODE := l_line.PRICING_STATUS_CODE;
3935       x_line_tbl(I).STATUS_TEXT := substr(l_line.PRICING_STATUS_TEXT,1,2000); -- shulin, fix bug 1745788
3936       x_line_tbl(I).HOLD_CODE := l_line.HOLD_CODE;
3937       x_line_tbl(I).HOLD_TEXT := substr(l_line.HOLD_TEXT,1,240);
3938       x_line_tbl(I).PRICE_REQUEST_CODE := l_line.PRICE_REQUEST_CODE;
3939       x_line_tbl(I).PRICING_EFFECTIVE_DATE := l_line.PRICING_EFFECTIVE_DATE;
3940       x_line_tbl(I).EXTENDED_PRICE := l_line.EXTENDED_PRICE; -- block pricing
3941 
3942 
3943    END LOOP;
3944    I:=1;
3945 
3946 
3947    --Populate Line detail
3948    IF l_debug_level > 0 then
3949    oe_debug_pub.add('----Line detail information return back to caller----');
3950    END IF;
3951 
3952    FOR l_dets IN l_ldets_cur LOOP
3953       IF l_debug_level > 0 then
3954       oe_debug_pub.add('----populating line detail output------');
3955       END IF;
3956       --requirement by Jay, will cause holes in pl/sql tbl
3957       I := l_dets.line_detail_index;
3958       x_line_detail_tbl(I).LINE_DETAIL_INDEX := l_dets.LINE_DETAIL_INDEX;
3959       x_line_detail_tbl(I).LINE_DETAIL_TYPE_CODE:=l_dets.LINE_DETAIL_TYPE_CODE;
3960       x_line_detail_tbl(I).LINE_INDEX:=l_dets.LINE_INDEX;
3961       x_line_detail_tbl(I).LIST_HEADER_ID:=l_dets.LIST_HEADER_ID;
3962       x_line_detail_tbl(I).LIST_LINE_ID:=l_dets.LIST_LINE_ID;
3963       x_line_detail_tbl(I).LIST_LINE_TYPE_CODE:=l_dets.LIST_LINE_TYPE_CODE;
3964       x_line_detail_tbl(I).SUBSTITUTION_TO:=l_dets.SUBSTITUTION_VALUE_TO;
3965       x_line_detail_tbl(I).LINE_QUANTITY :=l_dets.LINE_QUANTITY;
3966       --x_line_detail_tbl(I).ADJUSTMENT_AMOUNT := l_dets.ADJUSTMENT_AMOUNT;
3967       x_line_detail_tbl(I).ADJUSTMENT_AMOUNT:= nvl(l_dets.ORDER_QTY_ADJ_AMT,l_dets.ADJUSTMENT_AMOUNT);
3968       --   nvl(ldets.order_qty_adj_amt, ldets.adjustment_amount*nvl(lines.priced_quantity,1)/nvl(lines.line_quantity,1))
3969       x_line_detail_tbl(I).AUTOMATIC_FLAG    := l_dets.AUTOMATIC_FLAG;
3970       x_line_detail_tbl(I).APPLIED_FLAG      := l_dets.APPLIED_FLAG;
3971       x_line_detail_tbl(I).PRICING_GROUP_SEQUENCE := l_dets.PRICING_GROUP_SEQUENCE;
3972       x_line_detail_tbl(I).CREATED_FROM_LIST_TYPE_CODE:=l_dets.CREATED_FROM_LIST_TYPE_CODE;
3973       x_line_detail_tbl(I).PRICE_BREAK_TYPE_CODE := l_dets.PRICE_BREAK_TYPE_CODE;
3974       x_line_detail_tbl(I).OVERRIDE_FLAG   := L_Dets.override_flag;
3975       x_line_detail_tbl(I).PRINT_ON_INVOICE_FLAG :=l_dets.print_on_invoice_flag;
3976       x_line_detail_tbl(I).PRICING_PHASE_ID := l_dets.PRICING_PHASE_ID;
3977       x_line_detail_tbl(I).APPLIED_FLAG := l_dets.APPLIED_FLAG;
3978       x_line_detail_tbl(I).OPERAND_CALCULATION_CODE := l_dets.OPERAND_CALCULATION_CODE;
3979       x_line_detail_tbl(I).OPERAND_VALUE := l_dets.OPERAND_VALUE;
3980       x_line_detail_tbl(I).STATUS_CODE:=l_dets.PRICING_STATUS_CODE;
3981       x_line_detail_tbl(I).STATUS_TEXT:=substr(l_dets.PRICING_STATUS_TEXT,1,240);
3982       x_line_detail_tbl(I).SUBSTITUTION_ATTRIBUTE:=l_dets.SUBSTITUTION_ATTRIBUTE;
3983       x_line_detail_tbl(I).ACCRUAL_FLAG:=l_dets.ACCRUAL_FLAG;
3984       x_line_detail_tbl(I).LIST_LINE_NO:=l_dets.LIST_LINE_NO;
3985       x_line_detail_tbl(I).ESTIM_GL_VALUE:=l_dets.ESTIM_GL_VALUE;
3986       x_line_detail_tbl(I).ACCRUAL_CONVERSION_RATE:=l_dets.ACCRUAL_CONVERSION_RATE;
3987       --Pass throuh components
3988       x_line_detail_tbl(I).OVERRIDE_FLAG:= l_dets.OVERRIDE_FLAG;
3989       x_line_detail_tbl(I).PRINT_ON_INVOICE_FLAG:=l_dets.PRINT_ON_INVOICE_FLAG;
3990       x_line_detail_tbl(I).INVENTORY_ITEM_ID:=l_dets.INVENTORY_ITEM_ID;
3991       x_line_detail_tbl(I).ORGANIZATION_ID:=l_dets.ORGANIZATION_ID;
3992       x_line_detail_tbl(I).RELATED_ITEM_ID:= l_dets.RELATED_ITEM_ID;
3993       x_line_detail_tbl(I).RELATIONSHIP_TYPE_ID:=l_dets.RELATIONSHIP_TYPE_ID;
3994       x_line_detail_tbl(I).ESTIM_ACCRUAL_RATE:=l_dets.ESTIM_ACCRUAL_RATE;
3995 
3996       x_line_detail_tbl(I).BENEFIT_PRICE_LIST_LINE_ID:=l_dets.BENEFIT_PRICE_LIST_LINE_ID;
3997       x_line_detail_tbl(I).RECURRING_FLAG:= l_dets.RECURRING_FLAG;
3998       x_line_detail_tbl(I).RECURRING_VALUE:= l_dets.RECURRING_VALUE;
3999       x_line_detail_tbl(I).BENEFIT_LIMIT:= l_dets.BENEFIT_LIMIT;
4000       x_line_detail_tbl(I).CHARGE_TYPE_CODE:=  l_dets.CHARGE_TYPE_CODE;
4001       x_line_detail_tbl(I).CHARGE_SUBTYPE_CODE:=l_dets.CHARGE_SUBTYPE_CODE;
4002       x_line_detail_tbl(I).BENEFIT_QTY:=l_dets.BENEFIT_QTY;
4003       x_line_detail_tbl(I).BENEFIT_UOM_CODE:=l_dets.BENEFIT_UOM_CODE;
4004       x_line_detail_tbl(I).PRORATION_TYPE_CODE:=l_dets.PRORATION_TYPE_CODE;
4005       x_line_detail_tbl(I).INCLUDE_ON_RETURNS_FLAG := l_dets.INCLUDE_ON_RETURNS_FLAG;
4006       x_line_detail_tbl(I).LIST_LINE_NO := l_dets.LIST_LINE_NO;
4007       x_line_detail_tbl(I).MODIFIER_LEVEL_CODE := l_dets.MODIFIER_LEVEL_CODE;
4008       x_line_detail_tbl(I).GROUP_VALUE := nvl(l_dets.GROUP_QUANTITY,l_dets.GROUP_AMOUNT); -- 2388011_new
4009       x_line_detail_tbl(I).COMMENTS := l_dets.COMMENTS;
4010       x_line_detail_tbl(I).UPDATED_FLAG := l_dets.UPDATED_FLAG;
4011       x_line_detail_tbl(I).PROCESS_CODE := l_dets.PROCESS_CODE;
4012       x_line_detail_tbl(I).LIMIT_CODE := l_dets.LIMIT_CODE;
4013       x_line_detail_tbl(I).LIMIT_TEXT := substr(l_dets.LIMIT_TEXT,1,240);
4014       x_line_detail_tbl(I).CALCULATION_CODE := l_dets.CALCULATION_CODE;
4015       x_line_detail_tbl(I).CHANGE_REASON_CODE := l_dets.CHANGE_REASON_CODE;
4016       x_line_detail_tbl(I).CHANGE_REASON_CODE := substr(l_dets.CHANGE_REASON_CODE,1,240);
4017 
4018       IF l_status_code = FND_API.G_RET_STS_ERROR THEN
4019 	 --  IF G_DEBUG_ENGINE = FND_API.G_TRUE THEN
4020 	IF l_debug_level > 0 then
4021 	    oe_debug_pub.add(l_routine||':'||substr(l_status_text,1,240));
4022 	    END IF;
4023 	 --END IF;
4024       END IF;
4025 
4026       x_line_detail_tbl(I).EXPIRATION_DATE :=l_expiration_period_end_date;
4027    END LOOP;
4028    I:=1;
4029 
4030    --Populate Qualifier detail
4031    --IF G_DEBUG_ENGINE = FND_API.G_TRUE THEN
4032    IF l_debug_level > 0 then
4033    oe_debug_pub.add('----Before populate x_qual_tbl-----');
4034    END IF;
4035    --END IF;
4036    FOR l_qual IN l_qual_cur(QP_PREQ_GRP.G_DETAIL_LEVEL) LOOP
4037       x_line_detail_qual_tbl(I).LINE_DETAIL_INDEX := l_qual.LINE_DETAIL_INDEX;
4038       x_line_detail_qual_tbl(I).QUALIFIER_CONTEXT := l_qual.CONTEXT;
4039       x_line_detail_qual_tbl(I).QUALIFIER_ATTRIBUTE := l_qual.ATTRIBUTE;
4040       x_line_detail_qual_tbl(I).QUALIFIER_ATTR_VALUE_FROM := l_qual.SETUP_VALUE_FROM;
4041       x_line_detail_qual_tbl(I).QUALIFIER_ATTR_VALUE_TO := l_qual.SETUP_VALUE_TO;
4042       x_line_detail_qual_tbl(I).COMPARISON_OPERATOR_CODE := l_qual.COMPARISON_OPERATOR_TYPE_CODE;
4043       x_line_detail_qual_tbl(I).status_code := l_qual.PRICING_STATUS_CODE;
4044       x_line_detail_qual_tbl(I).VALIDATED_FLAG :=l_qual.VALIDATED_FLAG;
4045 
4046       I:=I+1;
4047    END LOOP;
4048    I:=1;
4049 
4050    --LINE ATTRIBUTE DETAIL NEEDED
4051 
4052   IF l_debug_level > 0 then
4053    oe_debug_pub.add('----Before populate attr_tbl-----');
4054    END IF;
4055 
4056    FOR l_prc IN l_pricing_attr_cur LOOP
4057       IF l_debug_level >0 then
4058       oe_debug_pub.add('--------populating x_line_detail_attr----------');
4059       oe_debug_pub.add('Line Detail Index: '||l_prc.LINE_DETAIL_INDEX);
4060       END IF;
4061       x_line_detail_attr_tbl(I).LINE_DETAIL_INDEX := l_prc.LINE_DETAIL_INDEX;
4062       x_line_detail_attr_tbl(I).PRICING_CONTEXT := l_prc.PRICING_CONTEXT;
4063       x_line_detail_attr_tbl(I).PRICING_ATTRIBUTE := l_prc.PRICING_ATTRIBUTE;
4064       x_line_detail_attr_tbl(I).PRICING_ATTR_VALUE_FROM :=l_prc.PRICING_ATTR_VALUE_FROM;
4065       x_line_detail_attr_tbl(I).PRICING_ATTR_VALUE_TO :=l_prc.PRICING_ATTR_VALUE_TO;
4066       x_line_detail_attr_tbl(I).VALIDATED_FLAG :=l_prc.VALIDATED_FLAG;
4067       --x_line_attr_tbl(I).PRICING_STATUS_CODE := l_prc.PRICING_STATUS_CODE;
4068       --x_line_attr_tbl(I).PRICING_STATUS_TEXT := l_prc.PRICING_STATUS_TEXT;
4069       I:=I+1;
4070    END LOOP;
4071 
4072    I:=1;
4073 
4074    IF l_debug_level > 0 then
4075    oe_debug_pub.add('----Before populate l_rltd_lines_tbl-----');
4076    END IF;
4077    FOR l_rltd IN l_rltd_lines_cur LOOP
4078       x_related_lines_tbl(I).LINE_INDEX := l_rltd.Line_index;
4079       x_related_lines_tbl(I).LINE_DETAIL_INDEX :=  l_rltd.LINE_DETAIL_INDEX;
4080       x_related_lines_tbl(I).RELATIONSHIP_TYPE_CODE :=l_rltd.RELATIONSHIP_TYPE_CODE;
4081       x_related_lines_tbl(I).RELATED_LINE_INDEX     :=l_rltd.RELATED_LINE_INDEX;
4082       x_related_lines_tbl(I).RELATED_LINE_DETAIL_INDEX :=l_rltd.RELATED_LINE_DETAIL_INDEX;
4083       x_related_lines_tbl(I).STATUS_CODE :=l_rltd.PRICING_STATUS_CODE;
4084       x_related_lines_tbl(I).STATUS_TEXT :=l_rltd.PRICING_STATUS_TEXT;
4085       I:=I+1;
4086    END LOOP;
4087 
4088 EXCEPTION
4089    WHEN E_ROUTINE_ERROR THEN
4090          IF l_debug_level >0 then
4091       oe_debug_pub.add(l_routine||':'||substr(l_status_text,1,240));
4092        END IF;
4093 
4094 END Populate_results;
4095 
4096 
4097 
4098 
4099 PROCEDURE price_item(out_req_line_tbl in out NOCOPY /* file.sql.39 change */ OE_OE_PRICING_AVAILABILITY.QP_LINE_TBL_TYPE,
4100 		     out_Req_line_attr_tbl         in out nocopy  OE_OE_PRICING_AVAILABILITY.QP_LINE_ATTR_TBL_TYPE,
4101 		     out_Req_LINE_DETAIL_attr_tbl  in out nocopy  OE_OE_PRICING_AVAILABILITY.QP_LINE_DATTR_TBL_TYPE,
4102 		     out_Req_LINE_DETAIL_tbl        in out nocopy OE_OE_PRICING_AVAILABILITY.QP_LINE_DETAIL_TBL_TYPE,
4103 		     out_Req_related_lines_tbl      in out nocopy OE_OE_PRICING_AVAILABILITY.QP_RLTD_LINES_TBL_TYPE,
4104 		     out_Req_qual_tbl               in out nocopy OE_OE_PRICING_AVAILABILITY.QP_QUAL_TBL_TYPE,
4105 		     out_Req_LINE_DETAIL_qual_tbl   in out nocopy OE_OE_PRICING_AVAILABILITY.QP_LINE_DQUAL_TBL_TYPE,
4106 		     out_child_detail_type out nocopy varchar2
4107                      ) IS
4108 
4109    l_return_status               varchar2(10);
4110    l_return_status_Text	      varchar2(240) ;
4111    lx_Control_Rec                 QP_PREQ_GRP.CONTROL_RECORD_TYPE;
4112    l_Control_Rec                 OE_OE_PRICING_AVAILABILITY.QP_CONTROL_RECORD_TYPE;
4113    l_req_line_tbl                OE_OE_PRICING_AVAILABILITY.QP_LINE_TBL_TYPE;
4114    l_Req_qual_tbl                OE_OE_PRICING_AVAILABILITY.QP_QUAL_TBL_TYPE;
4115    l_Req_line_attr_tbl           OE_OE_PRICING_AVAILABILITY.QP_LINE_ATTR_TBL_TYPE;
4116    l_Req_LINE_DETAIL_tbl         OE_OE_PRICING_AVAILABILITY.QP_LINE_DETAIL_TBL_TYPE;
4117    l_Req_LINE_DETAIL_qual_tbl    OE_OE_PRICING_AVAILABILITY.QP_LINE_DQUAL_TBL_TYPE;
4118    l_Req_LINE_DETAIL_attr_tbl    OE_OE_PRICING_AVAILABILITY.QP_LINE_DATTR_TBL_TYPE;
4119    l_Req_related_lines_tbl       OE_OE_PRICING_AVAILABILITY.QP_RLTD_LINES_TBL_TYPE;
4120 
4121    --
4122    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4123    --
4124 BEGIN
4125 
4126    out_child_detail_type := qp_preq_grp.G_CHILD_DETAIL_TYPE;
4127    reset_all_tbls;
4128 
4129    IF l_debug_level  > 0 THEN
4130       oe_debug_pub.add(  'SETTING REQUEST ID' , 1 ) ;
4131    END IF;
4132 
4133    qp_price_request_context.set_request_id;
4134 
4135    IF l_debug_level  > 0 THEN
4136       oe_debug_pub.add('REQUEST ID IS : ' || QP_PREQ_GRP.G_REQUEST_ID , 1 ) ;
4137    END IF;
4138 
4139 
4140    OE_ORDER_PUB.G_HDR:=NULL;
4141    OE_ORDER_PUB.G_LINE:=NULL;
4142 
4143    IF l_debug_level  > 0 THEN
4144       print_time('Before Calling Copy Header to Request');
4145    END IF;
4146    g_applied_manual_tbl.delete;
4147    copy_Header_to_request(
4148 			 p_request_type_code => 'ONT'
4149                         --  p_request_type_code => 'ASO'
4150 			  ,p_calculate_price_flag  => 'Y'
4151 			  ,px_req_line_tbl => l_req_line_tbl
4152 			  );
4153 
4154    IF l_debug_level  > 0 THEN
4155       print_time('After Calling Copy Header to Request');
4156    END IF;
4157    set_pricing_control_record (
4158 			       l_Control_Rec  => l_control_rec
4159 			       ,in_pricing_event => 'BATCH'
4160                                );
4161 
4162     copy_control_rec(in_Control_Rec => l_control_rec,
4163 			   x_Control_Rec=>lx_control_rec);
4164 
4165     build_context_for_header(
4166 			    p_req_line_tbl_count =>l_req_line_tbl.count,
4167 			    p_price_request_code => null,
4168 			    p_item_type_code => null,
4169 			    p_Req_line_attr_tbl =>l_req_line_attr_tbl,
4170 			    p_Req_qual_tbl =>l_req_qual_tbl
4171 			    );
4172 
4173 
4174    IF l_debug_level  > 0 THEN
4175       print_time('Before Looping through Copy Line to request');
4176    END IF;
4177    for l_line_index in g_panda_rec_table.first..g_panda_rec_table.last
4178 		       LOOP
4179 
4180          IF l_debug_level  > 0 THEN
4181          oe_debug_pub.add('the line index'||l_line_index);
4182 	 END IF;
4183       copy_Line_to_request(
4184 			   px_req_line_tbl => l_req_line_tbl
4185 			   ,p_pricing_event => 'BATCH'
4186 			   ,p_Request_Type_Code => 'ONT'
4187                           -- ,p_Request_Type_Code => 'ASO'
4188 			   ,p_honor_price_flag => 'Y'
4189 			   ,p_line_index=>l_line_index
4190 			   );
4191 
4192       build_context_for_line(
4193 			     p_req_line_tbl_count =>l_req_line_tbl.count,
4194 			     p_price_request_code => null,
4195 			     p_item_type_code => null,
4196 			     p_Req_line_attr_tbl =>l_req_line_attr_tbl,
4197 			     p_Req_qual_tbl =>l_req_qual_tbl,
4198 			     p_line_index=>l_line_index
4199 			     );
4200 
4201 
4202 
4203        oe_Debug_pub.add('Calling Append Attributes for Line');
4204 	 Append_attributes(
4205 			p_header_id => g_header_id
4206 			,p_Line_id   => g_panda_rec_table(l_line_index).p_line_id
4207 			,p_line_index =>global_line_index
4208 			,px_Req_line_attr_tbl => l_req_line_attr_tbl
4209 			,px_Req_qual_tbl => l_req_qual_tbl
4210 			,p_g_line_index =>l_line_index
4211 			);
4212 
4213 -- inserting manual adjsutments
4214            oe_Debug_pub.add('modfier count'||g_manual_modifier_tbl.count);
4215 	 if g_manual_modifier_tbl.count > 0 then
4216 
4217 	    IF l_debug_level  > 0 THEN
4218 	       oe_debug_pub.add('before inserting manual adjustment'||g_manual_modifier_tbl.count);
4219 	    END IF;
4220 
4221 	    insert_manual_adjustment(in_line_id=>g_panda_rec_table(l_line_index).p_line_id,
4222 				      in_line_index=>global_line_index) ;
4223 
4224 	    IF l_debug_level  > 0 THEN
4225 	       oe_debug_pub.add('after inserting manual adjustment');
4226 	    END IF;
4227 	 end if;
4228 
4229 
4230    end loop; -- Looping for each line
4231 
4232    IF l_debug_level  > 0 THEN
4233       print_time('After Looping through Copy Line to Request');
4234    END IF;
4235 
4236 /*   build_context_for_header(
4237 			    p_req_line_tbl_count =>l_req_line_tbl.count,
4238 			    p_price_request_code => null,
4239 			    p_item_type_code => null,
4240 			    p_Req_line_attr_tbl =>l_req_line_attr_tbl,
4241 			    p_Req_qual_tbl =>l_req_qual_tbl
4242 			    );  */
4243 
4244    oe_Debug_pub.add('Calling Append Attributes for Header');
4245 
4246    Append_attributes(
4247 		     p_header_id => g_header_id
4248 		     ,p_Line_id   => null
4249 		     ,p_line_index => l_req_line_tbl.count
4250 		     ,px_Req_line_attr_tbl => l_req_line_attr_tbl
4251 		     ,px_Req_qual_tbl => l_req_qual_tbl
4252 		     ,p_g_line_index =>1
4253 		     );
4254 
4255 
4256    IF l_debug_level  > 0 THEN
4257       print_time('After appending the Header Attributes and Before Appending attributes to Temp Tables');
4258       oe_Debug_pub.add(' Populating the attr tables');
4259    END IF;
4260 
4261    append_attr_to_TTables(px_req_line_attr_tbl=>l_req_line_attr_tbl);
4262    IF l_debug_level  > 0 THEN
4263       print_time('After Appending attributes to Temp Tables');
4264    END IF;
4265    out_req_line_tbl(1).status_Code := null;
4266    out_req_line_tbl(1).status_text := null;
4267 
4268 
4269    IF l_debug_level > 0 then
4270    oe_Debug_pub.add(' Populating the temp tables');
4271    print_time('Before Populate Temp Tables');
4272    END IF;
4273    populate_temp_table;
4274 
4275     IF l_debug_level  > 0 THEN
4276       print_time(' After populating temp tables and Before calling PE');
4277    END IF;
4278    QP_PREQ_PUB.PRICE_REQUEST
4279       (p_control_rec           =>lx_control_rec,
4280        x_return_status         =>l_return_status,
4281        x_return_status_Text    =>l_return_status_Text
4282        );
4283 
4284    IF l_debug_level  > 0 THEN
4285       print_time('After calling PE');
4286       oe_debug_pub.add('After calling the pricing engine');
4287    END IF;
4288    IF l_debug_level  > 0 THEN
4289       print_time('Before populate results ');
4290    END IF;
4291    populate_results(
4292 		    x_line_tbl =>out_req_line_tbl
4293 		    ,x_line_qual_tbl =>out_Req_qual_tbl
4294 		    ,x_line_attr_tbl =>out_Req_line_attr_tbl
4295 		    ,x_line_detail_tbl =>out_req_line_detail_tbl
4296 		    ,x_line_detail_qual_tbl=>out_req_line_detail_qual_tbl
4297 		    ,x_line_detail_attr_tbl =>out_req_line_detail_attr_tbl
4298 		    ,x_related_lines_tbl=>out_req_related_lines_tbl);
4299 
4300    IF l_debug_level  > 0 THEN
4301       print_time('After populating results');
4302    END IF;
4303    IF l_debug_level > 0 THEN
4304       print_time('After populating the pl/sql records');
4305    END IF;
4306 
4307    IF l_debug_level  > 0 THEN
4308       oe_debug_pub.add('******AFTER CALLING PRICING ENGINE' ) ;
4309       oe_debug_pub.add('MAIN STATUS ='||L_RETURN_STATUS ) ;
4310       oe_debug_pub.add('MAIN TEXT ='||L_RETURN_STATUS_TEXT ) ;
4311       oe_debug_pub.add('COUNT LINE TABLE='||OUT_REQ_LINE_TBL.COUNT ) ;
4312    END IF;
4313 
4314    if out_req_line_tbl.count > 0 then
4315       for i in out_req_line_tbl.first..out_req_line_tbl.last
4316 	       loop
4317 
4318 	 IF l_debug_level  > 0 THEN
4319 	    oe_debug_pub.add('*******************************' ) ;
4320             oe_debug_pub.add(' LINE_INDEX ='||OUT_REQ_LINE_TBL (I).LINE_INDEX );
4321 	    oe_debug_pub.add('LINE_ID='||OUT_REQ_LINE_TBL (I).LINE_ID);
4322 	    oe_debug_pub.add('REQUEST_TYPE_CODE ='|| OUT_REQ_LINE_TBL (I) .REQUEST_TYPE_CODE ) ;
4323 	    oe_debug_pub.add('PRICING_EVENT ='||OUT_REQ_LINE_TBL (I) .PRICING_EVENT ) ;
4324 	    oe_debug_pub.add('HEADER_ID ='||OUT_REQ_LINE_TBL (I) .HEADER_ID ) ;
4325 	    oe_debug_pub.add('LINE_TYPE_CODE='||OUT_REQ_LINE_TBL (I) .LINE_TYPE_CODE ) ;
4326 	    oe_debug_pub.add('LINE_QUANTITY ='||OUT_REQ_LINE_TBL (I) .LINE_QUANTITY ) ;
4327 	    oe_debug_pub.add('LINE_UOM_CODE ='||OUT_REQ_LINE_TBL (I) .LINE_UOM_CODE ) ;
4328 	    oe_debug_pub.add('UOM_QUANTITY ='||OUT_REQ_LINE_TBL (I) .UOM_QUANTITY ) ;
4329 	    oe_debug_pub.add('PRI_QUANTITY='||OUT_REQ_LINE_TBL (I) .PRICED_QUANTITY ) ;
4330 	    oe_debug_pub.add('PR_UOM_CODE ='||OUT_REQ_LINE_TBL (I) .PRICED_UOM_CODE ) ;
4331 	    oe_debug_pub.add('CURRENCY_CODE ='||OUT_REQ_LINE_TBL (I) .CURRENCY_CODE ) ;
4332 	    oe_debug_pub.add('UNIT_PRICE ='||OUT_REQ_LINE_TBL (I) .UNIT_PRICE ) ;
4333 	    oe_debug_pub.add('PERCENT_PRICE ='||OUT_REQ_LINE_TBL (I) .PERCENT_PRICE ) ;
4334 	    oe_debug_pub.add('ADJ_UNIT_PRICE='|| OUT_REQ_LINE_TBL (I) .ADJUSTED_UNIT_PRICE ) ;
4335 	    oe_debug_pub.add('UPDATED_ADJUSTED_UNIT_PRICE ='|| OUT_REQ_LINE_TBL (I) .UPDATED_ADJUSTED_UNIT_PRICE ) ;
4336 	    oe_debug_pub.add('ROUNDING_FAC='||OUT_REQ_LINE_TBL (I) .ROUNDING_FACTOR ) ;
4337 	    oe_debug_pub.add('PRICE_FLAG ='||OUT_REQ_LINE_TBL (I) .PRICE_FLAG ) ;
4338 	    oe_debug_pub.add('PRICE_REQUEST_CODE ='|| OUT_REQ_LINE_TBL (I) .PRICE_REQUEST_CODE ) ;
4339 	    oe_debug_pub.add('HOLD_CODE ='||OUT_REQ_LINE_TBL (I) .HOLD_CODE ) ;
4340 	    oe_debug_pub.add('HOLD_TEXT ='||OUT_REQ_LINE_TBL (I) .HOLD_TEXT ) ;
4341 	    oe_debug_pub.add('STATUS_CODE ='||OUT_REQ_LINE_TBL (I) .STATUS_CODE ) ;
4342 	    oe_debug_pub.add('STATUS_TEXT ='||OUT_REQ_LINE_TBL (I) .STATUS_TEXT ) ;
4343 	    oe_debug_pub.add('USAGE_PRICING_TYPE ='|| OUT_REQ_LINE_TBL (I) .USAGE_PRICING_TYPE ) ;
4344 	    oe_debug_pub.add('LINE_CATEGORY ='||OUT_REQ_LINE_TBL (I) .LINE_CATEGORY ) ;
4345 	    oe_debug_pub.add('PRICING EFFECTIVE DATE='|| OUT_REQ_LINE_TBL (I) .PRICING_EFFECTIVE_DATE ) ;
4346 	    oe_debug_pub.add('ACTIVE_DATE_FIRST ='|| OUT_REQ_LINE_TBL (I) .ACTIVE_DATE_FIRST ) ;
4347 	    oe_debug_pub.add('ACTIVE_DATE_FIRST_TYPE ='|| OUT_REQ_LINE_TBL (I) .ACTIVE_DATE_FIRST_TYPE ) ;
4348 	    oe_debug_pub.add('ACTIVE_DATE_SECOND ='|| OUT_REQ_LINE_TBL (I) .ACTIVE_DATE_SECOND ) ;
4349 	    oe_debug_pub.add('ACTIVE_DATE_SECOND_TYPE ='|| OUT_REQ_LINE_TBL (I) .ACTIVE_DATE_SECOND_TYPE ) ;
4350 	 END IF;
4351       end loop;
4352    end if;
4353 
4354    IF l_debug_level  > 0 THEN
4355       oe_debug_pub.add('COUNT LINE DETAIL TABLE='||OUT_REQ_LINE_DETAIL_TBL.COUNT ) ;
4356    END IF;
4357 
4358    if out_req_line_detail_tbl.count > 0 then
4359 
4360       for i in out_req_line_detail_tbl.first..out_req_line_detail_tbl.last
4361 	       loop
4362 
4363 	 IF l_debug_level  > 0 THEN
4364 	    oe_debug_pub.add('LINE DETAIL TABLE RECORD='||I ) ;
4365 	 END IF;
4366 
4367 	 IF out_req_line_detail_tbl.exists(i) then
4368 
4369 	    IF l_debug_level  > 0 THEN
4370 	       oe_debug_pub.add('*******************************' ) ;
4371 	       oe_debug_pub.add('LINE_DETAIL_INDEX ='||OUT_REQ_LINE_DETAIL_TBL (I).LINE_DETAIL_INDEX);
4372 	       oe_debug_pub.add('LINE_DETAIL_TYPE_CODE='||OUT_REQ_LINE_DETAIL_TBL (I).LINE_DETAIL_TYPE_CODE);
4373 	       oe_debug_pub.add('LIN_INDEX='||OUT_REQ_LINE_DETAIL_TBL (I) .LINE_INDEX ) ;
4374 	       oe_debug_pub.add('LIST_HEADER_ID='|| OUT_REQ_LINE_DETAIL_TBL (I) .LIST_HEADER_ID ) ;
4375 	       oe_debug_pub.add('LIST_LINE_ID='|| OUT_REQ_LINE_DETAIL_TBL (I) .LIST_LINE_ID ) ;
4376 	       oe_debug_pub.add('LIST_LINE_TYPE_CODE='|| OUT_REQ_LINE_DETAIL_TBL (I) .LIST_LINE_TYPE_CODE ) ;
4377 	       oe_debug_pub.add('LINE_DETAIL_TYPE_CODE='|| OUT_REQ_LINE_DETAIL_TBL (I) .LINE_DETAIL_TYPE_CODE ) ;
4378 	       oe_debug_pub.add('SUBSTITUTION_TO='||OUT_REQ_LINE_DETAIL_TBL (I).SUBSTITUTION_TO);
4379 	       oe_debug_pub.add('LINE_QUANTITY='||OUT_REQ_LINE_DETAIL_TBL (I).LINE_QUANTITY);
4380 	       oe_debug_pub.add('ADJUSTMENT_AMOUNT='|| OUT_REQ_LINE_DETAIL_TBL (I) .ADJUSTMENT_AMOUNT ) ;
4381 	       oe_debug_pub.add('AUTOMATIC_FLAG='|| OUT_REQ_LINE_DETAIL_TBL (I) .AUTOMATIC_FLAG ) ;
4382 	       oe_debug_pub.add('APPLIED_FLAG ='||OUT_REQ_LINE_DETAIL_TBL (I).APPLIED_FLAG );
4383 	       oe_debug_pub.add('PRICING_GROUP_SEQUENCE='||OUT_REQ_LINE_DETAIL_TBL (I).PRICING_GROUP_SEQUENCE);
4384 	       oe_debug_pub.add('CREATED_FROM_LIST_TYPE_CODE='|| OUT_REQ_LINE_DETAIL_TBL (I) .CREATED_FROM_LIST_TYPE_CODE ) ;
4385 	       oe_debug_pub.add('PRICE_BREAK_TYPE_CODE='|| OUT_REQ_LINE_DETAIL_TBL (I) .PRICE_BREAK_TYPE_CODE ) ;
4386 	       oe_debug_pub.add('OVERRIDE_FLAG='||OUT_REQ_LINE_DETAIL_TBL (I).OVERRIDE_FLAG);
4387 	       oe_debug_pub.add('PRINT_ON_INVOICE_FLAG='||OUT_REQ_LINE_DETAIL_TBL (I).PRINT_ON_INVOICE_FLAG);
4388 	       oe_debug_pub.add('PRICING_PHASE_ID='||OUT_REQ_LINE_DETAIL_TBL (I).PRICING_PHASE_ID);
4389 	       oe_debug_pub.add('OPERAND_CALCULATION_CODE='||OUT_REQ_LINE_DETAIL_TBL(I).OPERAND_CALCULATION_CODE);
4390 	       oe_debug_pub.add('OPERAND_VALUE='||OUT_REQ_LINE_DETAIL_TBL (I).OPERAND_VALUE);
4391 	       oe_debug_pub.add('STATUS_CODE='||OUT_REQ_LINE_DETAIL_TBL (I).STATUS_CODE);
4392 	       oe_debug_pub.add('STATUS_TEXT='||OUT_REQ_LINE_DETAIL_TBL (I).STATUS_TEXT);
4393 	       oe_debug_pub.add('SUBSTITUTION_ATTRIBUTE='||OUT_REQ_LINE_DETAIL_TBL (I).SUBSTITUTION_ATTRIBUTE);
4394 	       oe_debug_pub.add('ACCRUAL='||OUT_REQ_LINE_DETAIL_TBL (I) .ACCRUAL_FLAG ) ;
4395 	       oe_debug_pub.add('LIST_LINE_NO='||OUT_REQ_LINE_DETAIL_TBL (I).LIST_LINE_NO);
4396 	       oe_debug_pub.add('ESTIM_GL_VALUE='||OUT_REQ_LINE_DETAIL_TBL (I).ESTIM_GL_VALUE);
4397 	       oe_debug_pub.add('ACCRUAL_CONVERSION_RATE='||OUT_REQ_LINE_DETAIL_TBL (I).ACCRUAL_CONVERSION_RATE);
4398 	       oe_debug_pub.add('PRINT_ON_INVOICE_FLAG='||OUT_REQ_LINE_DETAIL_TBL (I).PRINT_ON_INVOICE_FLAG);
4399 	       oe_debug_pub.add('INVENTORY_ITEM_ID='|| OUT_REQ_LINE_DETAIL_TBL (I) .INVENTORY_ITEM_ID ) ;
4400 	       oe_debug_pub.add('ORGANIZATION_ID='||OUT_REQ_LINE_DETAIL_TBL (I).ORGANIZATION_ID);
4401 	       oe_debug_pub.add('RELATED_ITEM_ID='||OUT_REQ_LINE_DETAIL_TBL (I).RELATED_ITEM_ID);
4402 	       oe_debug_pub.add('RELATIONSHIP_TYPE_ID='||OUT_REQ_LINE_DETAIL_TBL (I).RELATIONSHIP_TYPE_ID);
4403 	       oe_debug_pub.add('ESTIM_ACCRUAL_RATE='||OUT_REQ_LINE_DETAIL_TBL (I).ESTIM_ACCRUAL_RATE);
4404 	       oe_debug_pub.add('BENEFIT_PRICE_LIST_LINE_ID='||OUT_REQ_LINE_DETAIL_TBL (I).BENEFIT_PRICE_LIST_LINE_ID);
4405 	       oe_debug_pub.add('RECURRING_FLAG='||OUT_REQ_LINE_DETAIL_TBL (I).RECURRING_FLAG );
4406 	       oe_debug_pub.add('RECURRING_VALUE='||OUT_REQ_LINE_DETAIL_TBL(I).RECURRING_VALUE);
4407 	       oe_debug_pub.add('BENEFIT_LIMIT='||OUT_REQ_LINE_DETAIL_TBL (I).BENEFIT_LIMIT);
4408 	       oe_debug_pub.add('CHARGE_TYPE_CODE='||OUT_REQ_LINE_DETAIL_TBL (I).CHARGE_TYPE_CODE);
4409 	       oe_debug_pub.add('CHARGE_SUBTYPE_CODE='||OUT_REQ_LINE_DETAIL_TBL (I).CHARGE_SUBTYPE_CODE);
4410 	       oe_debug_pub.add('BENEFIT_QTY='||OUT_REQ_LINE_DETAIL_TBL (I).BENEFIT_QTY);
4411 	       oe_debug_pub.add('BENEFIT_UOM_CODE='||OUT_REQ_LINE_DETAIL_TBL (I).BENEFIT_UOM_CODE);
4412 	       oe_debug_pub.add('PRORATION_TYPE_CODE='||OUT_REQ_LINE_DETAIL_TBL (I).PRORATION_TYPE_CODE);
4413 	       oe_debug_pub.add('NCLUDE_ON_RETURNS_FLAG ='||OUT_REQ_LINE_DETAIL_TBL (I).INCLUDE_ON_RETURNS_FLAG );
4414 	       oe_debug_pub.add('CALCULATION_CODE='||OUT_REQ_LINE_DETAIL_TBL (I).CALCULATION_CODE);
4415 	       oe_debug_pub.add('LST_PRICE='||OUT_REQ_LINE_DETAIL_TBL (I) .LIST_PRICE ) ;
4416 	       oe_debug_pub.add('MODIFIER_LEVEL_CODE='|| OUT_REQ_LINE_DETAIL_TBL (I) .MODIFIER_LEVEL_CODE ) ;
4417 
4418 
4419 	    end if;
4420 	 end if;
4421       end loop;
4422 
4423    end if;
4424 
4425 
4426    IF l_debug_level  > 0 THEN
4427       oe_debug_pub.add('COUNT LINE DETAIL ATTR TBL='|| OUT_REQ_LINE_DETAIL_ATTR_TBL.COUNT ) ;
4428    END IF;
4429 
4430    if out_req_line_detail_attr_tbl.count > 0 then
4431       for i in out_req_line_detail_attr_tbl.first..out_req_line_detail_attr_tbl.last
4432 	       loop
4433 	 IF l_debug_level  > 0 THEN
4434 	    oe_debug_pub.add('*******************************' ) ;
4435 	    oe_debug_pub.add('LINE DETAIL ATTR_TABLE RECORD='||I ) ;
4436 	    oe_debug_pub.add('LINE_DETAIL_INDEX='|| OUT_REQ_LINE_DETAIL_ATTR_TBL (I) .LINE_DETAIL_INDEX ) ;
4437 	    oe_debug_pub.add('PRICING_CONTEXT='|| OUT_REQ_LINE_DETAIL_ATTR_TBL (I) .PRICING_CONTEXT ) ;
4438 	    oe_debug_pub.add('PRICING_ATTRIBUTE='|| OUT_REQ_LINE_DETAIL_ATTR_TBL (I) .PRICING_ATTRIBUTE ) ;
4439 	    oe_debug_pub.add('PRICING_ATTR_VALUE_FROM='|| OUT_REQ_LINE_DETAIL_ATTR_TBL (I) .PRICING_ATTR_VALUE_FROM ) ;
4440 	    oe_debug_pub.add('PRICING_ATTR_VALUE_TO='|| OUT_REQ_LINE_DETAIL_ATTR_TBL (I) .PRICING_ATTR_VALUE_TO ) ;
4441 	 END IF;
4442 
4443       end loop;
4444    end if;
4445 
4446 
4447    IF l_debug_level  > 0 THEN
4448       oe_debug_pub.add('COUNT LINE ATTR TBL='||OUT_REQ_LINE_ATTR_TBL.COUNT ) ;
4449    END IF;
4450 
4451    if out_req_line_attr_tbl.count > 0 then
4452       for i in out_req_line_attr_tbl.first..out_req_line_attr_tbl.last
4453 	       loop
4454 	 IF l_debug_level  > 0 THEN
4455 	    oe_debug_pub.add('*******************************' ) ;
4456 	    oe_debug_pub.add('LINE ATTR_TABLE RECORD='||I ) ;
4457 	    oe_debug_pub.add('LINE_INDEX='||OUT_REQ_LINE_ATTR_TBL (I) .LINE_INDEX ) ;
4458 	    oe_debug_pub.add('PRICING_CONTEXT='|| OUT_REQ_LINE_ATTR_TBL (I) .PRICING_CONTEXT ) ;
4459 	    oe_debug_pub.add('PRICING_ATTRIBUTE='|| OUT_REQ_LINE_ATTR_TBL (I) .PRICING_ATTRIBUTE ) ;
4460 	    oe_debug_pub.add('PRICING_ATTR_VALUE_FROM='|| OUT_REQ_LINE_ATTR_TBL (I) .PRICING_ATTR_VALUE_FROM ) ;
4461 	    oe_debug_pub.add('PRICING_ATTR_VALUE_TO='|| OUT_REQ_LINE_ATTR_TBL (I) .PRICING_ATTR_VALUE_TO ) ;
4462 	 END IF;
4463 
4464       end loop;
4465    end if;
4466 
4467 
4468    IF l_debug_level  > 0 THEN
4469       oe_debug_pub.add('COUNT RELATED LINES TBL='|| OUT_REQ_RELATED_LINES_TBL.COUNT ) ;
4470    END IF;
4471 
4472    if out_req_related_lines_tbl.count > 0 then
4473       for i in out_req_related_lines_tbl.first..out_req_related_lines_tbl.last
4474 	       loop
4475 	 IF l_debug_level  > 0 THEN
4476 	    oe_debug_pub.add('*******************************' ) ;
4477 	    oe_debug_pub.add('RELATD LINES RECORD='||I ) ;
4478 	    oe_debug_pub.add('LIN_INDEX='||OUT_REQ_RELATED_LINES_TBL (I) .LINE_INDEX ) ;
4479 	    oe_debug_pub.add('LINE_DETAIL_INDEX='|| OUT_REQ_RELATED_LINES_TBL (I) .LINE_DETAIL_INDEX ) ;
4480 	    oe_debug_pub.add('RELATIONSHIP_TYPE_CODE='|| OUT_REQ_RELATED_LINES_TBL (I) .RELATIONSHIP_TYPE_CODE ) ;
4481 	    oe_debug_pub.add('RELATED_LINE_INDEX='|| OUT_REQ_RELATED_LINES_TBL (I) .RELATED_LINE_INDEX ) ;
4482 	    oe_debug_pub.add('RELATED_LINE_DETAIL_INDEX='|| OUT_REQ_RELATED_LINES_TBL (I) .RELATED_LINE_DETAIL_INDEX ) ;
4483 	 END IF;
4484 
4485       end loop;
4486    end if;
4487 
4488 
4489    IF l_debug_level  > 0 THEN
4490       oe_debug_pub.add('COUNT LINE QUAL TBL='||OUT_REQ_QUAL_TBL.COUNT ) ;
4491    END IF;
4492 
4493    if out_req_qual_tbl.count > 0 then
4494       for i in out_req_qual_tbl.first..out_req_qual_tbl.last
4495 	       loop
4496 	 IF l_debug_level  > 0 THEN
4497 	    oe_debug_pub.add('*******************************' ) ;
4498 	    oe_debug_pub.add('QUAL TABLE RECORD='||I ) ;
4499 	    oe_debug_pub.add('LINE_INDEX='||OUT_REQ_QUAL_TBL (I) .LINE_INDEX ) ;
4500 	    oe_debug_pub.add('QUALIFIER_CONTEXT='|| OUT_REQ_QUAL_TBL (I) .QUALIFIER_CONTEXT ) ;
4501 	    oe_debug_pub.add('QUALIFIER_ATTRIBUTE='|| OUT_REQ_QUAL_TBL (I) .QUALIFIER_ATTRIBUTE ) ;
4502 	    oe_debug_pub.add('QUALIFIER_ATTR_VALUE_FROM='|| OUT_REQ_QUAL_TBL (I) .QUALIFIER_ATTR_VALUE_FROM ) ;
4503 	    oe_debug_pub.add('QUALIFIER_ATTR_VALUE_TO='|| OUT_REQ_QUAL_TBL (I) .QUALIFIER_ATTR_VALUE_TO ) ;
4504 	    oe_debug_pub.add('COMPARISON_OPERATOR_CODE='|| OUT_REQ_QUAL_TBL (I) .COMPARISON_OPERATOR_CODE ) ;
4505 	    oe_debug_pub.add('VALIDATED_FLAG='||OUT_REQ_QUAL_TBL (I) .VALIDATED_FLAG ) ;
4506 	 END IF;
4507 
4508       end loop;
4509    end if;
4510 
4511 
4512    IF l_debug_level  > 0 THEN
4513       oe_debug_pub.add('COUNT LINE DETAIL QUAL TBL='|| OUT_REQ_LINE_DETAIL_QUAL_TBL.COUNT ) ;
4514    END IF;
4515 
4516    if out_req_line_detail_qual_tbl.count > 0 then
4517       for i in out_req_line_detail_qual_tbl.first..out_req_line_detail_qual_tbl.last
4518 	       loop
4519 	 IF l_debug_level  > 0 THEN
4520 	    oe_debug_pub.add('*******************************' ) ;
4521 	    oe_debug_pub.add('LINE DETAIL QUAL TABLE RECORD='||I ) ;
4522 	    oe_debug_pub.add('LINE_DETAIL_INDEX='|| OUT_REQ_LINE_DETAIL_QUAL_TBL (I) .LINE_DETAIL_INDEX ) ;
4523 	    oe_debug_pub.add('QUALIFIER_CONTEXT='|| OUT_REQ_LINE_DETAIL_QUAL_TBL (I) .QUALIFIER_CONTEXT ) ;
4524 	    oe_debug_pub.add('QUALIFIER_ATTRIBUTE='|| OUT_REQ_LINE_DETAIL_QUAL_TBL (I) .QUALIFIER_ATTRIBUTE ) ;
4525 	    oe_debug_pub.add('QUALIFIER_ATTR_VALUE_FROM='|| OUT_REQ_LINE_DETAIL_QUAL_TBL (I) .QUALIFIER_ATTR_VALUE_FROM ) ;
4526 	    oe_debug_pub.add('QUALIFIER_ATTR_VALUE_TO='|| OUT_REQ_LINE_DETAIL_QUAL_TBL (I) .QUALIFIER_ATTR_VALUE_TO ) ;
4527 	    oe_debug_pub.add('COMPARISON_OPERATOR_CODE='|| OUT_REQ_LINE_DETAIL_QUAL_TBL (I) .COMPARISON_OPERATOR_CODE ) ;
4528 	    oe_debug_pub.add('VALIDATED_FLAG='|| OUT_REQ_LINE_DETAIL_QUAL_TBL (I) .VALIDATED_FLAG ) ;
4529 	 END IF;
4530 
4531       end loop;
4532    end if;
4533 
4534 
4535    IF l_debug_level  > 0 THEN
4536       oe_debug_pub.add( 'EXITING PRICE_ITEM*******************************' ) ;
4537    END IF;
4538 
4539 EXCEPTION
4540    when others then
4541 
4542       IF l_debug_level  > 0 THEN
4543 	 oe_debug_pub.add(  'PRICE ITEM EXCEPTION WHEN OTHERS CODE='|| SQLCODE||' MESSAGE='||SQLERRM ) ;
4544 END IF;
4545 
4546 END price_item;
4547 
4548 PROCEDURE pass_values_to_backend (
4549 				  in_panda_rec_table in panda_rec_table)
4550 IS
4551  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4552 BEGIN
4553 
4554    g_panda_rec_table.delete;
4555    for i in in_panda_rec_table.first..in_panda_rec_table.last
4556       loop
4557       if l_debug_level > 0 then
4558       oe_debug_pub.add(' Line Record Nbr='||i);
4559       end if;
4560       g_panda_rec_table(i):=in_panda_rec_table(i);
4561       if l_debug_level > 0 then
4562       oe_debug_pub.add('*******IT STARTS HERE*****');
4563 	    oe_debug_pub.add('index is'||i||' item is='||g_panda_rec_table(i).p_inventory_item_id);
4564 	    end if;
4565 
4566       end loop;
4567 
4568 END pass_values_to_backend;
4569 
4570 Procedure Delete_manual_modifiers Is
4571    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4572    Begin
4573 
4574  if l_debug_level > 0 then
4575     oe_debug_pub.add('entered delete manual modifiers');
4576  end if;
4577  g_manual_modifier_tbl.delete;
4578  g_modf_rel_tbl.delete;
4579  g_modf_attributes_tbl.delete;
4580  if l_debug_level > 0 then
4581     oe_debug_pub.add('exiting delete manual modifiers');
4582  end if;
4583 
4584 End Delete_manual_modifiers;
4585 
4586 Procedure Pass_Modifiers_to_backend(in_manual_adj_tbl in Manual_modifier_tbl,
4587                                      in_modf_rel_tbl  in Modifier_assoc_Tbl,
4588 				       in_modf_attr_tbl in Modifier_attributes_Tbl)  IS
4589 
4590  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4591  l_ctr number;
4592 
4593 BEGIN
4594    if l_debug_level > 0 then
4595      oe_debug_pub.add('Entering PLS pass modifiers to backend');
4596   end if;
4597 
4598    l_ctr := g_manual_modifier_tbl.COUNT ;
4599 
4600   /* add the passed modifier and the line id accordingly */
4601    if in_manual_Adj_tbl.count >0 then
4602    for i in in_manual_adj_tbl.first..in_manual_adj_tbl.last
4603 	    loop
4604    IF  in_manual_adj_tbl.exists(i)  then
4605       l_ctr:=l_ctr+1;
4606       g_manual_modifier_tbl(l_ctr):=in_manual_adj_tbl(i);
4607       oe_Debug_pub.add('after assigning modifiers');
4608       oe_Debug_pub.add('after increasing counter');
4609 
4610     IF l_debug_level > 0 then
4611        oe_debug_pub.add('line_id='||g_manual_modifier_tbl(l_ctr).p_line_id);
4612 
4613     END IF;
4614 
4615    END IF;
4616   end loop;
4617   end if;
4618   -- g_modf_Rel_tbl.delete;
4619    l_ctr:=g_modf_rel_Tbl.count;
4620    if in_modf_rel_tbl.count >0 then
4621 
4622       for i in in_modf_rel_tbl.first..in_modf_rel_tbl.last
4623 	    loop
4624 	 IF  in_modf_rel_tbl.exists(i) then
4625 	     l_ctr:=l_ctr+1;
4626 	     g_modf_rel_tbl(l_ctr):=in_modf_rel_tbl(i);
4627 	     oe_Debug_pub.add('after assigning modifiers relationship');
4628 	     oe_Debug_pub.add('after increasing counter');
4629 
4630 	    IF l_debug_level > 0 then
4631 	       oe_debug_pub.add('line_id='||g_manual_modifier_tbl(l_ctr).p_line_id);
4632 
4633 	    END IF;
4634 
4635 	 END IF;
4636       end loop;
4637    end if;
4638 
4639       l_ctr:=g_modf_attributes_Tbl.count;
4640       if in_modf_attr_tbl.count >0 then
4641       for i in in_modf_attr_tbl.first..in_modf_attr_tbl.last
4642 	    loop
4643 	 IF  in_modf_attr_tbl.exists(i)  then
4644 	    l_ctr:=l_ctr+1;
4645 	    g_modf_attributes_tbl(l_ctr):=in_modf_attr_tbl(i);
4646 	    oe_Debug_pub.add('after assigning modifiers attributes');
4647 
4648 
4649 	    IF l_debug_level > 0 then
4650 	       oe_debug_pub.add('line_id='||g_manual_modifier_tbl(l_ctr).p_line_id);
4651 
4652 	    END IF;
4653 
4654 	 END IF;
4655       end loop;
4656    end if;
4657 
4658    oe_debug_pub.add('Exiting PLS pass modifiers to backend count='||
4659                      g_manual_modifier_tbl.COUNT);
4660 
4661 
4662    END Pass_Modifiers_to_backend;
4663 
4664     PROCEDURE Delete_Applied_Manual_Adj(in_line_id in number,
4665 				       in_list_line_id in number,
4666 				       in_list_header_id in number)
4667     IS
4668        l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4669     BEGIN
4670 
4671        IF l_debug_level > 0 then
4672 	  oe_debug_pub.add('Entered Delete Applied Manual Adj');
4673 	  oe_debug_pub.add('line_id='||in_line_id||' List line id'||in_list_line_id ||'List header id'
4674 			   ||in_list_header_id);
4675        END IF;
4676 
4677 
4678        for i in g_manual_modifier_tbl.first..g_manual_modifier_tbl.last
4679 	   loop
4680       if ( g_manual_modifier_tbl.exists(i) and
4681 	   g_manual_modifier_tbl(i).p_line_id = in_line_id and
4682 	   g_manual_modifier_tbl(i).list_line_id =in_list_line_id and
4683 	   g_manual_modifier_tbl(i).list_header_id=in_list_header_id) then
4684 
4685 
4686 
4687 	 IF g_manual_modifier_tbl(i).list_line_type_code ='PBH' then
4688 
4689 	    for k in g_modf_rel_tbl.first..g_modf_rel_tbl.last
4690 		    loop
4691 	      if ( g_modf_rel_tbl.exists(k) and
4692 		   g_modf_rel_tbl(k).line_detail_index = in_list_line_id)
4693 		 then
4694 
4695 		 for ix in g_manual_modifier_tbl.first..g_manual_modifier_tbl.last
4696 			   loop
4697 		    if ( g_manual_modifier_tbl.exists(ix) and
4698 			 g_manual_modifier_tbl(ix).p_line_id = in_line_id and
4699 			 g_manual_modifier_tbl(ix).list_line_id =g_modf_rel_Tbl(k).rltd_line_detail_index)
4700 		    then
4701                       -- delete the corresponding attributes
4702 		       if g_modf_attributes_tbl.count >0 then
4703 			  for ms in g_modf_attributes_tbl.first..g_modf_attributes_tbl.last
4704 				    loop
4705 			     if (g_modf_attributes_tbl.exists(ms) and
4706 				 g_modf_attributes_tbl(ms).p_line_id = in_line_id and
4707 				 g_modf_attributes_tbl(ms).p_list_line_id = g_manual_modifier_tbl(ix).list_line_id)
4708 			     then
4709 				g_modf_attributes_tbl.DELETE(ms);
4710 			     end if;
4711 			  end loop;
4712 		       end if;
4713 
4714 		       g_manual_modifier_tbl.DELETE(ix);
4715 		    end if;
4716 		 end loop;
4717                   g_modf_rel_tbl.delete(k);
4718 	      end if;
4719 	      end loop;
4720 
4721 	    end if; -- if pbh;
4722 
4723 	    -- delete the corresponding attributes
4724 	/*    if g_modf_attributes_tbl.count >0 then
4725 	       for ms in g_modf_attributes_tbl.first..g_modf_attributes_tbl.last
4726 			 loop
4727 		  if (g_modf_attributes_tbl.exists(ms) and
4728 		      g_modf_attributes_tbl(ms).p_line_id = in_line_id and
4729 		      g_modf_attributes_tbl(ms).p_list_line_id = g_manual_modifier_tbl(i).list_line_id)
4730 		  then
4731 		     g_modf_attributes_tbl.DELETE(ms);
4732 		  end if;
4733 	       end loop;
4734 	    end if; */
4735 
4736 	    g_manual_modifier_tbl.DELETE(i);
4737 
4738 	 IF l_debug_level > 0 then
4739 	  oe_debug_pub.add('Deleted the modifier');
4740        END IF;
4741 
4742       end if;
4743    end loop;
4744 END Delete_Applied_Manual_Adj;
4745 
4746 
4747    PROCEDURE Insert_Manual_Adjustment(in_line_id in number,
4748 				in_line_index in number)
4749    IS
4750       x_status_code  varchar2(100);
4751       x_status_text varchar2(2000);
4752       in_line_detail_index number;
4753       l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4754       l_line_index number;
4755       l_line_detail_index number;
4756       rltd_line_index number;
4757       rltd_line_detail_index number;
4758      l_applied_flag varchar2(1):='Y';
4759       l_price_break_type_code varchar2(30);
4760       l_insert_flag varchar2(2);
4761       rs number;
4762    BEGIN
4763       oe_debug_pub.add('entered insert adjustment'||g_manual_modifier_tbl.count);
4764       select count(*)  into in_line_detail_index from qp_preq_ldets_tmp;
4765 
4766       for i in g_manual_modifier_tbl.first..g_manual_modifier_tbl.last
4767 	       Loop
4768            l_insert_flag:='Y';
4769 
4770 	   IF g_manual_modifier_tbl(i).modifier_level_code ='ORDER' then
4771             if g_applied_manual_tbl.count > 0 then
4772 	      for xs in g_applied_manual_tbl.first..g_applied_manual_tbl.last
4773 			loop
4774 		 if (g_applied_manual_tbl.exists(xs) and
4775 		     g_applied_manual_tbl(xs)= g_manual_modifier_tbl(i).list_line_id)
4776 		 then
4777 		    l_insert_flag:='N';
4778 		    exit;
4779 		    end if;
4780 		 end loop;
4781                 end if;-- for count;
4782               end if;-- for order level;
4783 
4784 	      if l_insert_flag = 'Y' then
4785 
4786 	      rs:= g_applied_manual_tbl.count;
4787 	      g_applied_manual_tbl(rs+1):= g_manual_modifier_tbl(i).list_line_id;
4788 
4789 	 if g_manual_modifier_tbl(i).p_line_id=in_line_id or g_manual_modifier_tbl(i).modifier_level_code = 'ORDER' then
4790            in_line_detail_index:= in_line_detail_index+1;
4791 
4792 
4793            IF (nvl(g_manual_modifier_tbl(i).list_line_type_code,NULL) <>'PBH'
4794 	       and g_manual_modifier_tbl(i).line_detail_type_code ='CHILD_DETAIL_LINE')
4795 	   then
4796 	      l_applied_flag :='N';
4797 	      l_price_break_type_code:=NULL;
4798 	   else
4799 	      l_applied_flag := 'Y';
4800 	      l_price_break_type_code:=g_manual_modifier_tbl(i).price_break_type_code;
4801 	   end if;
4802 
4803 	   IF l_debug_level >0 then
4804 	      oe_debug_pub.add('line index'||in_line_index);
4805 	      oe_debug_pub.add('line detail index'||in_line_detail_index);
4806 	      oe_debug_pub.add('Line id'||g_manual_modifier_tbl(i).p_line_id);
4807 	      oe_debug_pub.add('Modifier_number'||g_manual_modifier_tbl(i).modifier_number);
4808 	      oe_debug_pub.add('List type code'||g_manual_modifier_tbl(i).list_line_type_code);
4809 	      oe_debug_pub.add('Operator'||g_manual_modifier_tbl(i).operator);
4810 	      oe_debug_pub.add('Operand'||g_manual_modifier_tbl(i).operand);
4811 	      oe_debug_pub.add('List line id'||g_manual_modifier_tbl(i).list_line_id);
4812 	      oe_debug_pub.add('List header id'||g_manual_modifier_tbl(i).list_header_id);
4813 	      oe_debug_pub.add('Pricing phase id'||g_manual_modifier_tbl(i).pricing_phase_id);
4814 	      oe_debug_pub.add('automatic flag'||g_manual_modifier_tbl(i).automatic_flag);
4815 	      oe_debug_pub.add('modifier_level_code'||g_manual_modifier_tbl(i).modifier_level_code);
4816 	      oe_debug_pub.add('Override flag'||g_manual_modifier_tbl(i).override_flag);
4817               oe_Debug_pub.add('line_detail_type_code'||g_manual_modifier_tbl(i).line_detail_type_code);
4818 	      oe_debug_pub.add('price break type code'||g_manual_modifier_tbl(i).price_break_type_code);
4819 	      oe_debug_pub.add('Applied flag'||l_applied_flag||
4820 			       ' price_break_type='||l_price_break_type_code);
4821 	   END IF;
4822 
4823 
4824 	   IF g_manual_modifier_tbl(i).modifier_level_code = 'ORDER' then
4825 	      l_line_index := 1;
4826 	   ELSE
4827 	      l_line_index := in_line_index;
4828 	   END IF;
4829 
4830 
4831 INSERT INTO QP_NPREQ_LDETS_TMP
4832 		 (LINE_DETAIL_INDEX,
4833 		  LINE_DETAIL_TYPE_CODE,
4834 		  LINE_INDEX,
4835 		  PROCESS_CODE,
4836 		  PRICING_PHASE_ID,
4837 		  OPERAND_CALCULATION_CODE,
4838 		  OPERAND_VALUE,
4839 		  OVERRIDE_FLAG,
4840 		  CREATED_FROM_LIST_TYPE_CODE,
4841 		  CREATED_FROM_LIST_HEADER_ID,
4842 		  CREATED_FROM_LIST_LINE_ID,
4843 		  CREATED_FROM_LIST_LINE_TYPE,
4844 		  PRICING_STATUS_CODE,
4845 		  APPLIED_FLAG,
4846 		  MODIFIER_LEVEL_CODE,
4847 		  UPDATED_FLAG,
4848                   PRICE_BREAK_TYPE_CODE)
4849 		  --ORDER_QTY_OPERAND)
4850 
4851   VALUES (       in_LINE_DETAIL_INDEX,
4852 		' ',
4853 		 --in_LINE_INDEX,
4854 		 l_LINE_INDEX,
4855 		 'N',
4856 		 g_manual_modifier_tbl(i).pricing_phase_id,
4857 		 g_manual_modifier_tbl(i).operator,
4858 		 g_manual_modifier_tbl(i).operand,
4859 		 g_manual_modifier_tbl(i).override_flag,
4860 		 ' ',
4861 		 g_manual_modifier_tbl(i).list_header_id,
4862 		 g_manual_modifier_tbl(i).list_line_id,
4863 		 g_manual_modifier_tbl(i).list_line_type_code,
4864 		 'X',
4865 		 --'N',
4866                  l_applied_flag,
4867 		 g_manual_modifier_tbl(i).modifier_level_code,
4868 		 'Y',
4869                  l_price_break_type_code);
4870 		-- 1);
4871 --END IF;
4872 
4873 
4874        if g_manual_modifier_tbl(i).list_line_type_code='PBH' then
4875 	  Insert into qp_npreq_line_attrs_tmp
4876 		     (Line_index,
4877 		      Line_detail_index,
4878 		      attribute_level,
4879 		      attribute_type,
4880 		      list_header_id,
4881 		      list_line_id,
4882 		      context,
4883 		      attribute,
4884 		      value_from,
4885 		      value_to,
4886 		      pricing_status_code,
4887                       pricing_phase_id,
4888                       modifier_level_code,
4889 		      validated_flag)
4890 		     values
4891 	             (in_line_index,
4892 		      in_line_detail_index,
4893 		      'LINE',
4894 		      'PRICING',
4895 	              g_manual_modifier_tbl(i).list_header_id,
4896 		      g_manual_modifier_tbl(i).list_line_id,
4897 		     'VOLUME',
4898 		     'PRICING_ATTRIBUTE10',
4899 		      0,
4900 		      0 ,
4901 		      'X',
4902 		      g_manual_modifier_tbl(i).pricing_phase_id,
4903 		      g_manual_modifier_tbl(i).modifier_level_code,
4904 		      'N');
4905 	 oe_debug_pub.add('inserted pbh line into qp_preq_line_attrs_tmp');
4906         end if;
4907 
4908    if g_modf_attributes_tbl.count >0 then
4909    for k in g_modf_attributes_tbl.first..g_modf_attributes_tbl.last
4910 	    loop
4911       if g_modf_attributes_tbl(k).p_list_line_id = g_manual_modifier_Tbl(i).list_line_id then
4912 
4913  IF l_debug_level >0 then
4914 	      oe_debug_pub.add('line index'||in_line_index);
4915 	      oe_debug_pub.add('line detail index'||in_line_detail_index);
4916 	      oe_debug_pub.add('list_header_id'|| g_manual_modifier_tbl(i).list_header_id);
4917 	      oe_debug_pub.add('list line id'|| g_manual_modifier_tbl(i).list_line_id);
4918 	      oe_debug_pub.add('context'|| g_modf_attributes_tbl(k).p_context);
4919 	      oe_debug_pub.add('attribute'|| g_modf_attributes_tbl(k).p_attribute);
4920               oe_debug_pub.add('Value from'|| g_modf_attributes_tbl(k).p_attr_value_from);
4921 	      oe_debug_pub.add('Value to'|| g_modf_attributes_tbl(k).p_attr_value_to);
4922 
4923 	  end if;
4924 
4925          Insert into qp_npreq_line_attrs_tmp
4926 		     (Line_index,
4927 		      Line_detail_index,
4928 		      attribute_level,
4929 		      attribute_type,
4930 		      list_header_id,
4931 		      list_line_id,
4932 		      context,
4933 		      attribute,
4934 		      value_from,
4935 		      value_to,
4936 		      pricing_status_code,
4937                       pricing_phase_id,
4938                       modifier_level_code,
4939 		      validated_flag)
4940 		     values
4941 	             (in_line_index,
4942 		      in_line_detail_index,
4943 		      'LINE',
4944 		      'PRICING',
4945 	              g_manual_modifier_tbl(i).list_header_id,
4946 		      g_manual_modifier_tbl(i).list_line_id,
4947 		      g_modf_attributes_tbl(k).p_context,
4948 		      g_modf_attributes_tbl(k).p_attribute,
4949 		      g_modf_attributes_tbl(k).p_attr_value_from,
4950 		      g_modf_attributes_tbl(k).p_attr_value_to,
4951 		      'X',
4952 		      g_manual_modifier_tbl(i).pricing_phase_id,
4953 		      g_manual_modifier_tbl(i).modifier_level_code,
4954 		      'N');
4955 	    end if;
4956 	 end loop;
4957       end if;
4958 
4959 oe_debug_pub.add('after inserting attributes');
4960 
4961 END IF;-- if line id
4962 END IF; -- if order level modifiers not applied
4963 End Loop;
4964 
4965 if g_modf_rel_Tbl.count>0 then
4966  for s in g_modf_rel_tbl.first..g_modf_rel_tbl.last
4967 	  loop
4968     if g_modf_rel_tbl.exists(s) and g_modf_rel_Tbl(s).p_line_id=in_line_id
4969 				then
4970 
4971        select line_index,line_detail_index into l_line_index,l_line_detail_index
4972 	 from qp_preq_ldets_Tmp where created_From_list_line_id=g_modf_rel_tbl(s).line_detail_index;
4973 
4974      select line_index,line_detail_index into rltd_line_index,rltd_line_detail_index from
4975       qp_preq_ldets_tmp where created_from_list_line_id=g_modf_rel_tbl(s).rltd_line_detail_index;
4976 
4977 IF l_debug_level >0 then
4978 	      oe_debug_pub.add('line index'||l_line_index);
4979 	      oe_debug_pub.add('line detail index'||l_line_detail_index);
4980 	      oe_debug_pub.add('related line index'|| rltd_line_index);
4981 	      oe_debug_pub.add('related line detail index'||rltd_line_detail_index );
4982 	end if;
4983 
4984 
4985      Insert into qp_npreq_rltd_lines_tmp
4986 		  (line_index,
4987 		   line_detail_index,
4988 		   related_line_index,
4989 		   related_line_detail_index,
4990 		   pricing_status_code,
4991 		   relationship_type_code)
4992 		  Values
4993                   (l_line_index,
4994 		   l_line_detail_index,
4995 		   rltd_line_index,
4996 		   rltd_line_detail_index,
4997 		   'N',
4998 		   'PBH_LINE');
4999 
5000        end if;
5001  end loop;
5002  oe_Debug_pub.add('after inserting relationship types');
5003 end if;
5004 
5005 oe_debug_pub.add('end of inserting');
5006 
5007 EXCEPTION
5008    WHEN OTHERS THEN
5009       x_status_code := FND_API.G_RET_STS_ERROR;
5010       x_status_text :=SQLERRM;
5011       oe_debug_pub.add('insert into ldets'||x_status_code||'error'||x_status_text);
5012 END Insert_Manual_Adjustment;
5013 
5014       PROCEDURE pass_promotions_to_backend (in_promotions_tbl promotions_tbl,
5015                                       in_line_id in number) IS
5016 
5017  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5018  l_ctr number;
5019 
5020 BEGIN
5021 
5022    if l_debug_level > 0 then
5023      oe_debug_pub.add('Entering PLS pass promotions to backend');
5024      oe_debug_pub.add('line_id='||in_line_id||
5025                       ' Count ='||in_promotions_tbl.COUNT);
5026    end if;
5027 
5028    l_ctr := g_promotions_tbl.COUNT + 1;
5029 
5030    -- Remove the promotion records if they already exist for that line_id
5031    IF g_promotions_tbl.COUNT > 0 then
5032      for m in g_promotions_tbl.FIRST..g_promotions_tbl.LAST
5033      LOOP
5034        oe_Debug_pub.add('deleting current promotions');
5035        IF g_promotions_tbl(m).p_line_id = in_line_id then
5036          oe_Debug_pub.add('actually deleting current promotions');
5037          g_promotions_tbl.DELETE(m);
5038        END IF;
5039 
5040      END LOOP;
5041    END IF;
5042 
5043    IF  in_promotions_tbl.COUNT > 0 then
5044 
5045    for i in in_promotions_tbl.first..in_promotions_tbl.last
5046    LOOP
5047 
5048      g_promotions_tbl(l_ctr):=in_promotions_tbl(i);
5049 
5050      IF l_debug_level > 0 then
5051        oe_debug_pub.add('line_id='||g_promotions_tbl(l_ctr).p_line_id||
5052                      ' type= '||g_promotions_tbl(l_ctr).p_type||
5053                      ' Level='||g_promotions_tbl(l_ctr).p_level||
5054                      ' Attr1='||g_promotions_tbl(l_ctr).p_pricing_attribute1||
5055                      ' Attr2='||g_promotions_tbl(l_ctr).p_pricing_attribute2||
5056                      ' Attr3='||g_promotions_tbl(l_ctr).p_pricing_attribute3);
5057      END IF;
5058      l_ctr := l_ctr + 1;
5059 
5060    END LOOP;
5061    END IF;
5062 
5063    oe_debug_pub.add('Exiting PLS pass promotions to backend count='||
5064                      g_promotions_tbl.COUNT);
5065 
5066 END pass_promotions_to_backend;
5067 
5068 
5069 PROCEDURE copy_attribs_to_Req(
5070        p_line_index number
5071       ,px_Req_line_attr_tbl in out nocopy  oe_oe_pricing_availability.QP_LINE_ATTR_TBL_TYPE
5072       ,px_Req_qual_tbl in out  nocopy  oe_oe_pricing_availability.QP_QUAL_TBL_TYPE
5073       ,p_pricing_contexts_Tbl  QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type
5074       ,p_qualifier_contexts_Tbl  QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type
5075 ) IS
5076 
5077 i pls_integer := 0;
5078 l_attr_index	pls_integer := nvl(px_Req_line_attr_tbl.last,0);
5079 l_qual_index	pls_integer := nvl(px_Req_qual_tbl.last,0);
5080 
5081 --
5082 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5083 --
5084 BEGIN
5085 
5086   IF l_debug_level  > 0 THEN
5087       oe_debug_pub.add(  'ENTERING oe_oe_pricing_availability.COPY_ATTRIBS_TO_REQ' , 1 ) ;
5088   END IF;
5089   i := p_pricing_contexts_Tbl.First;
5090   While i is not null loop
5091     l_attr_index := l_attr_index +1;
5092     px_Req_line_attr_tbl(l_attr_index).VALIDATED_FLAG := 'N';
5093     px_Req_line_attr_tbl(l_attr_index).line_index := p_line_index;
5094 
5095     -- Product and Pricing Contexts go into pricing contexts...
5096     px_Req_line_attr_tbl(l_attr_index).PRICING_CONTEXT :=
5097     p_pricing_contexts_Tbl(i).context_name;
5098     px_Req_line_attr_tbl(l_attr_index).PRICING_ATTRIBUTE :=
5099     p_pricing_contexts_Tbl(i).Attribute_Name;
5100     px_Req_line_attr_tbl(l_attr_index).PRICING_ATTR_VALUE_FROM :=
5101     p_pricing_contexts_Tbl(i).attribute_value;
5102 
5103     i := p_pricing_contexts_Tbl.Next(i);
5104   end loop;
5105 
5106   -- Copy the qualifiers
5107   i := p_qualifier_contexts_Tbl.First;
5108   While i is not null loop
5109     l_qual_index := l_qual_index +1;
5110 
5111     If p_qualifier_contexts_Tbl(i).context_name ='MODLIST' and
5112       p_qualifier_contexts_Tbl(i).Attribute_Name ='QUALIFIER_ATTRIBUTE4' then
5113 
5114       If OE_Order_PUB.G_Line.agreement_id is not null and
5115         OE_Order_PUB.G_Line.agreement_id <> fnd_api.g_miss_num then
5116         px_Req_Qual_Tbl(l_qual_index).Validated_Flag := 'Y';
5117       Else
5118         px_Req_Qual_Tbl(l_qual_index).Validated_Flag := 'N';
5119       End If;
5120 
5121     Else
5122       px_Req_Qual_Tbl(l_qual_index).Validated_Flag := 'N';
5123     End If;
5124 
5125     px_Req_qual_tbl(l_qual_index).line_index := p_line_index;
5126 
5127     px_Req_qual_tbl(l_qual_index).QUALIFIER_CONTEXT :=
5128     p_qualifier_contexts_Tbl(i).context_name;
5129     px_Req_qual_tbl(l_qual_index).QUALIFIER_ATTRIBUTE :=
5130     p_qualifier_contexts_Tbl(i).Attribute_Name;
5131     px_Req_qual_tbl(l_qual_index).QUALIFIER_ATTR_VALUE_FROM :=
5132     p_qualifier_contexts_Tbl(i).attribute_value;
5133 
5134     i := p_qualifier_contexts_Tbl.Next(i);
5135   end loop;
5136 
5137 IF l_debug_level  > 0 THEN
5138     oe_debug_pub.add(  'EXITING oe_oe_pricing_availability.COPY_ATTRIBS_TO_REQ' , 1 ) ;
5139 END IF;
5140 
5141 END copy_attribs_to_Req;
5142 
5143 
5144 
5145 
5146 PROCEDURE process_pricing_errors(in_line_type_code in varchar2,
5147                                  in_status_code    in varchar2,
5148                                  in_status_text    in varchar2,
5149                                  in_ordered_item    in varchar2,
5150                                  in_uom    in varchar2,
5151                                  in_unit_price    in number,
5152                                  in_adjusted_unit_price    in number,
5153                                  in_process_code    in varchar2 ,
5154                                  in_price_flag    in varchar2,
5155                                  in_price_list_id in number,
5156 l_return_status out nocopy varchar2,
5157 
5158 l_msg_count out nocopy number,
5159 
5160 l_msg_data out nocopy varchar2
5161 
5162                                  ) IS
5163 
5164 l_price_list varchar2(200);
5165 l_allow_negative_price varchar2(10):= nvl(OE_Sys_Parameters.VALUE('ONT_NEGATIVE_PRICING'),'N');
5166 --Bug 7409782
5167 --l_gsa_violation_action Varchar2(30) :=fnd_profile.value('ONT_GSA_VIOLATION_ACTION');
5168 l_org_id Number:= OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
5169 
5170 --Bug 7409782
5171 l_GSA_Enabled_Flag 	Varchar2(30) := FND_PROFILE.VALUE('QP_VERIFY_GSA');
5172 l_gsa_violation_action  Varchar2(30) := nvl(oe_sys_parameters.value('ONT_GSA_VIOLATION_ACTION'),'WARNING');
5173 Cursor get_gsa_list_lines is
5174 Select/*+ ordered use_nl(qpq qppa qpll qplh) */ min(qpll.operand)
5175  From
5176       qp_qualifiers qpq
5177  ,    qp_pricing_attributes qppa
5178  ,    qp_list_lines qpll
5179  ,    qp_list_headers_b qplh
5180  ,    qp_price_req_sources qpprs
5181  where
5182  qpq.qualifier_context='CUSTOMER'
5183  and qpq.qualifier_attribute='QUALIFIER_ATTRIBUTE15'
5184  and qpq.qualifier_attr_value='Y'
5185  and qppa.list_header_id=qplh.list_header_id
5186  and qplh.Active_flag='Y'
5187  and qpprs.request_type_code = 'ONT'
5188  and qpprs.source_system_code=qplh.source_system_code
5189  and    qppa.pricing_phase_id  = 2
5190  and    qppa.qualification_ind = 6
5191  and qppa.product_attribute_context ='ITEM'
5192  and qppa.product_attribute='PRICING_ATTRIBUTE1'
5193  and qppa.product_attr_value= g_panda_rec_table(1).p_inventory_item_id
5194  and qppa.excluder_flag = 'N'
5195  and qppa.list_header_id=qpq.list_header_id
5196  and qppa.list_line_id=qpll.list_line_id
5197  and  g_panda_rec_table(1).p_pricing_date between nvl(trunc(qplh.start_date_active),g_panda_rec_table(1).p_pricing_date)
5198  and nvl(trunc(qplh.End_date_active),g_panda_rec_table(1).p_pricing_date);
5199 
5200 l_operand  number;
5201 l_msg_text Varchar2(2000);
5202 
5203 --
5204 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5205 --
5206 BEGIN
5207 
5208   IF l_debug_level  > 0 THEN
5209       oe_debug_pub.add(  'ENTERING PROCESS_PRICING_ERRORS' ) ;
5210   END IF;
5211                    IF l_debug_level  > 0 THEN
5212  oe_debug_pub.add(  'LINE_TYPE_CODE='||IN_LINE_TYPE_CODE|| ' STATUS CODE='||IN_STATUS_CODE|| ' NEGATIVE PRICE ='||L_ALLOW_NEGATIVE_PRICE|| ' IN_UNIT_PRICE ='||IN_UNIT_PRICE|| ' IN_ADJUSTED_UNIT_PRICE ='||IN_ADJUSTED_UNIT_PRICE ) ;
5213                    END IF;
5214 
5215 
5216   IF in_line_Type_code ='LINE' and
5217     in_status_code in ( QP_PREQ_GRP.G_STATUS_INVALID_PRICE_LIST,
5218                         QP_PREQ_GRP.G_STS_LHS_NOT_FOUND,
5219                         QP_PREQ_GRP.G_STATUS_FORMULA_ERROR,
5220                         QP_PREQ_GRP.G_STATUS_OTHER_ERRORS,
5221                         FND_API.G_RET_STS_UNEXP_ERROR,
5222                         FND_API.G_RET_STS_ERROR,
5223                         QP_PREQ_GRP.G_STATUS_CALC_ERROR,
5224                         QP_PREQ_GRP.G_STATUS_UOM_FAILURE,
5225                         QP_PREQ_GRP.G_STATUS_INVALID_UOM,
5226                         QP_PREQ_GRP.G_STATUS_DUP_PRICE_LIST,
5227                         QP_PREQ_GRP.G_STATUS_INVALID_UOM_CONV,
5228                         QP_PREQ_GRP.G_STATUS_INVALID_INCOMP,
5229                         QP_PREQ_GRP.G_STATUS_BEST_PRICE_EVAL_ERROR)
5230   then
5231 
5232     l_return_status := 'E';
5233 
5234     IF in_price_list_id is not null then
5235       Begin
5236         Select name into l_price_list
5237           from qp_list_headers_vl
5238          where list_header_id = in_price_list_id;
5239       Exception When No_data_found then
5240         l_price_list := in_price_list_id;
5241       End;
5242     END IF;
5243 
5244     IF in_status_code  = QP_PREQ_GRP.G_STATUS_INVALID_PRICE_LIST then
5245 
5246                       IF l_debug_level  > 0 THEN
5247                           oe_debug_pub.add(  'INVALID PRICE LIST'|| ' PRICE_LIST_ID='||G_panda_rec_table(1).p_PRICE_LIST_ID ) ;
5248                       END IF;
5249       IF g_panda_rec_table(1).p_price_list_id is null then
5250 
5251         FND_MESSAGE.SET_NAME('ONT','ONT_AVAIL_GENERIC');
5252         FND_MESSAGE.SET_TOKEN('TEXT',in_status_text);
5253         IF l_debug_level  > 0 THEN
5254             oe_debug_pub.add(  'INVALID PL ERR TXT='||IN_STATUS_TEXT ) ;
5255         END IF;
5256         OE_MSG_PUB.Add;
5257 
5258       ELSE
5259         IF l_debug_level  > 0 THEN
5260             oe_debug_pub.add(  'INVALID PRICE LIST' ) ;
5261         END IF;
5262         FND_MESSAGE.SET_NAME('ONT','OE_PRC_NO_LIST_PRICE');
5263         FND_MESSAGE.SET_TOKEN('ITEM',in_Ordered_Item);
5264         FND_MESSAGE.SET_TOKEN('UNIT',in_uom);
5265         FND_MESSAGE.SET_TOKEN('PRICE_LIST',l_Price_List);
5266         OE_MSG_PUB.Add;
5267 
5268       END IF;
5269 
5270     ELSIF in_status_code = QP_PREQ_GRP.G_STS_LHS_NOT_FOUND Then
5271 
5272       FND_MESSAGE.SET_NAME('ONT','ONT_NO_PRICE_LIST_FOUND');
5273       FND_MESSAGE.SET_TOKEN('ITEM',in_Ordered_Item);
5274       FND_MESSAGE.SET_TOKEN('UOM',in_uom);
5275       OE_MSG_PUB.Add;
5276 
5277     ELSIF in_status_code = QP_PREQ_GRP.G_STATUS_FORMULA_ERROR then
5278       FND_MESSAGE.SET_NAME('ONT','ONT_PRC_ERROR_IN_FORMULA');
5279       FND_MESSAGE.SET_TOKEN('ERR_TEXT',in_status_text); --3730467
5280       OE_MSG_PUB.Add;
5281 
5282 
5283     ELSIF in_status_code in
5284     ( QP_PREQ_GRP.G_STATUS_OTHER_ERRORS , FND_API.G_RET_STS_UNEXP_ERROR,
5285       FND_API.G_RET_STS_ERROR) then
5286       FND_MESSAGE.SET_NAME('ONT','ONT_PRICING_ERRORS'); --bug#7149497
5287       FND_MESSAGE.SET_TOKEN('ERR_TEXT',in_status_text);
5288       OE_MSG_PUB.Add;
5289 
5290     ELSIF in_status_code = QP_PREQ_GRP.G_STATUS_INVALID_UOM then
5291       FND_MESSAGE.SET_NAME('ONT','ONT_PRC_INVALID_UOM');
5292       FND_MESSAGE.SET_TOKEN('ITEM',in_Ordered_Item);
5293       FND_MESSAGE.SET_TOKEN('UOM',in_uom);
5294       OE_MSG_PUB.Add;
5295 
5296     ElSIF in_status_code = QP_PREQ_GRP.G_STATUS_DUP_PRICE_LIST then
5297       FND_MESSAGE.SET_NAME('ONT','ONT_PRC_DUPLICATE_PRICE_LIST');
5298 
5299       IF l_debug_level  > 0 THEN
5300           oe_debug_pub.add(  'DUPLICATE PRICE LIST ERROR' ) ;
5301       END IF;
5302       Begin
5303         Select name into l_price_list
5304         from qp_list_headers_vl a,qp_list_lines b where
5305         b.list_line_id =  to_number(substr(in_status_text,1,
5306         instr(in_status_text,',')-1))
5307         and a.list_header_id=b.list_header_id ;
5308       Exception When No_data_found then
5309         l_price_list := to_number(substr(in_status_text,1,
5310         instr(in_status_text,',')-1));
5311       When invalid_number then
5312         l_price_list := substr(in_status_text,1,
5313         instr(in_status_text,',')-1);
5314       End;
5315 
5316       IF l_debug_level  > 0 THEN
5317           oe_debug_pub.add(  'PRICE LIST 1='||L_PRICE_LIST ) ;
5318       END IF;
5319       FND_MESSAGE.SET_TOKEN('PRICE_LIST1','( '||in_Ordered_Item||' ) '|| l_price_list);
5320       Begin
5321         Select name into l_price_list
5322         from qp_list_headers_vl a,qp_list_lines b where
5323         b.list_line_id =  to_number(substr(in_status_text,
5324         instr(in_status_text,',')+1))
5325         and a.list_header_id=b.list_header_id	;
5326       Exception When No_data_found then
5327         l_price_list := to_number(substr(in_status_text,
5328         instr(in_status_text,',')+1));
5329       When invalid_number then
5330         l_price_list := substr(in_status_text,
5331         instr(in_status_text,',')+1);
5332       End;
5333       IF l_debug_level  > 0 THEN
5334           oe_debug_pub.add(  'PRICE LIST 2='||L_PRICE_LIST ) ;
5335       END IF;
5336 
5337       FND_MESSAGE.SET_TOKEN('PRICE_LIST2',l_price_list);
5338       OE_MSG_PUB.Add;
5339 
5340     ELSIF in_status_code = QP_PREQ_GRP.G_STATUS_INVALID_UOM_CONV then
5341       FND_MESSAGE.SET_NAME('ONT','ONT_PRC_INVALID_UOM_CONVERSION');
5342       FND_MESSAGE.SET_TOKEN('UOM_TEXT','( '||in_Ordered_Item||' ) '||
5343 				in_status_text);
5344       OE_MSG_PUB.Add;
5345 
5346     ElSIF in_status_code = QP_PREQ_GRP.G_STATUS_INVALID_INCOMP then
5347       FND_MESSAGE.SET_NAME('ONT','ONT_PRC_INVALID_INCOMP');
5348       FND_MESSAGE.SET_TOKEN('ERR_TEXT','( '||in_Ordered_Item||' ) '||
5349                            in_status_text);
5350       OE_MSG_PUB.Add;
5351 
5352     ELSIF in_status_code = QP_PREQ_GRP.G_STATUS_BEST_PRICE_EVAL_ERROR then
5353       FND_MESSAGE.SET_NAME('ONT','ONT_PRC_BEST_PRICE_ERROR');
5354       FND_MESSAGE.SET_TOKEN('ITEM',in_Ordered_Item);
5355       FND_MESSAGE.SET_TOKEN('ERR_TEXT',in_status_text);
5356       OE_MSG_PUB.Add;
5357     END IF;
5358 
5359 
5360 
5361   ELSIF in_line_Type_code ='LINE' and
5362    in_status_code = QP_PREQ_GRP.G_STATUS_OTHER_ERRORS Then
5363 
5364     IF l_debug_level  > 0 THEN
5365         oe_debug_pub.add(  'OE_PRICING_ERROR' ) ;
5366     END IF;
5367     FND_MESSAGE.SET_NAME('ONT','OE_PRICING_ERROR');
5368     FND_MESSAGE.SET_TOKEN('ERR_TEXT','( '||in_Ordered_Item||' ) '||in_STATUS_TEXT);
5369     OE_MSG_PUB.Add;
5370 
5371   ELSIF in_line_Type_code ='LINE' and in_status_code in
5372              --( QP_PREQ_GRP.G_STATUS_UPDATED,
5373                (QP_PREQ_GRP.G_STATUS_GSA_VIOLATION) and
5374              --  QP_PREQ_GRP.G_STATUS_UNCHANGED) and
5375 	   nvl(in_process_code,'0') <> QP_PREQ_GRP.G_BY_ENGINE
5376 	   and in_price_flag IN ('Y','P')
5377       --we do not want to go in this loop if price_flag is set up 'N' because
5378       --engine doesn't look at the line and will not return adjustments. In this
5379       --case we DON't want to remove the adjustments that engine doesn't return.
5380     then
5381       IF l_debug_level  > 0 THEN
5382           oe_debug_pub.add(  'OE_PRICING_ERROR 2' ) ;
5383       END IF;
5384 
5385       IF in_status_text is not null then
5386         --Bug 7409782 starts
5387         IF l_gsa_violation_action = 'WARNING'
5388         THEN
5389            l_return_status := 'W';
5390         ELSE
5391            l_return_status := 'E';
5392         END IF;
5393         --Bug 7409782 ends
5394 
5395         FND_MESSAGE.SET_NAME('ONT','ONT_PRICING_ERRORS'); --bug#7149497
5396         FND_MESSAGE.SET_TOKEN('ERR_TEXT',in_status_text);
5397         OE_MSG_PUB.Add;
5398       END IF;
5399 
5400       -- we need to do this check in UPDATED code or do the gsa check through
5401       -- the control record of Pricing
5402       /*OPEN get_gsa_list_lines;
5403       FETCH get_gsa_list_lines
5404        INTO l_operand;
5405       CLOSE get_gsa_list_lines;
5406       oe_debug_pub.add('After select OE_PRICING_ERROR 2');
5407       oe_debug_pub.add('Adj price='||in_adjusted_unit_price||
5408                        ' Operand='||l_operand);
5409 
5410       IF in_adjusted_unit_price <= l_operand then
5411         oe_debug_pub.add('If unit price less than operand violation='||
5412                           l_gsa_violation_action);
5413         --Check if the GSA check needs to be done.
5414         If l_gsa_violation_action in ('WARNING','ERROR') then
5415 
5416           oe_debug_pub.add('GSA warning or error');
5417           Begin
5418             SELECT concatenated_segments
5419               INTO l_msg_text
5420               FROM mtl_system_items_kfv
5421              WHERE inventory_item_id = g_inventory_item_id
5422                AND organization_id = l_org_id;
5423           Exception
5424             when no_data_found then
5425             Null;
5426           End;
5427 
5428           l_return_status := 'E';
5429           oe_debug_pub.add('GSA warning or error 2 msg_Text='||l_msg_text);
5430           FND_MESSAGE.SET_NAME('ONT','OE_GSA_VIOLATION');
5431           l_msg_text := l_operand||' ( '||l_msg_text||' )';
5432           FND_MESSAGE.SET_TOKEN('GSA_PRICE',l_msg_text);
5433           OE_MSG_PUB.Add;
5434         END IF;
5435       END IF; */
5436 
5437 
5438   ELSIF  -- Process header level adjustments
5439     in_line_type_code ='ORDER' and
5440     (in_status_code in ( QP_PREQ_GRP.G_STATUS_UPDATED ,
5441                          QP_PREQ_GRP.G_STATUS_GSA_VIOLATION)
5442      --In this case even engine doesn't update the order (status = UNCHANGED)
5443      --because of one of the lined is frozen,
5444      --there can be some order level adjustments in database which
5445      --need to be pulled out by append_adjustment_lines routine
5446       or (in_status_code = QP_PREQ_GRP.G_STATUS_UNCHANGED))
5447 	Then
5448     IF l_debug_level  > 0 THEN
5449         oe_debug_pub.add(  'OE_PRICING_ERROR 3' ) ;
5450     END IF;
5451     null;
5452 
5453   ELSIF in_line_Type_code ='LINE' and in_status_code = 'UPDATED' then
5454 
5455     IF l_debug_level  > 0 THEN
5456         oe_debug_pub.add(  'STATUS = UPDATED' ) ;
5457     END IF;
5458 
5459   END IF;-- Status_Code
5460 
5461 
5462   IF l_debug_level  > 0 THEN
5463       oe_debug_pub.add(  'PROCESS PRICING ERROR AFTER ERR CHK ST='||L_RETURN_STATUS ) ;
5464   END IF;
5465 
5466   --Bug 7409782
5467   IF l_return_status IN('E','W') then
5468     IF l_debug_level  > 0 THEN
5469         oe_debug_pub.add(  'DOING COUNT_AND_GET' ) ;
5470     END IF;
5471     oe_msg_pub.count_and_get(p_encoded=>fnd_api.G_TRUE,
5472                              p_count => l_msg_count,
5473                              p_data=>l_msg_data
5474                                     );
5475   END IF;
5476 
5477   IF l_debug_level  > 0 THEN
5478       oe_debug_pub.add(  'EXITING PROCESS_PRICING_ERRORS' ) ;
5479   END IF;
5480 
5481 EXCEPTION
5482 
5483   when others then
5484                         IF l_debug_level  > 0 THEN
5485                             oe_debug_pub.add(  'PROCESS PRICING ERRORS WHEN OTHERS EXCEPTION CODE='|| SQLCODE||' MESSAGE='||SQLERRM ) ;
5486                         END IF;
5487 
5488 END process_pricing_errors;
5489 
5490 
5491 
5492 FUNCTION Get_Rounding_factor(p_list_header_id number) return number is
5493 
5494 l_rounding_factor number;
5495 
5496 --
5497 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5498 --
5499 BEGIN
5500 
5501     select rounding_factor
5502       into l_rounding_factor
5503       from qp_list_headers_b
5504      where list_header_id = p_list_header_id;
5505 
5506     If l_rounding_factor = fnd_api.g_miss_num then
5507       l_rounding_factor:= Null;
5508     End If;
5509 
5510     Return l_rounding_factor;
5511 
5512 
5513 EXCEPTION
5514     when no_data_found then
5515         Return Null;
5516 END Get_Rounding_factor;
5517 
5518 PROCEDURE get_item_name(l_inv_item_id in number,
5519 			out_inv_item_name out nocopy varchar2
5520 			)
5521 IS
5522 l_org_id number := OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
5523 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5524 BEGIN
5525 SELECT concatenated_segments
5526        INTO  out_inv_item_name
5527        FROM   mtl_system_items_kfv
5528        WHERE  inventory_item_id = l_inv_item_id
5529        AND    organization_id = l_org_id;
5530 
5531 
5532 EXCEPTION
5533     when no_data_found then
5534         IF l_debug_level  > 0 THEN
5535             oe_debug_pub.add(  'OE_AVAILABILITY.GET_item_name NO DATA FOUND' ) ;
5536         END IF;
5537     when others then
5538                         IF l_debug_level  > 0 THEN
5539                             oe_debug_pub.add(  'OE_AVAILABILITY.GET_item_NAME WHEN OTHERS '|| SQLERRM||SQLCODE ) ;
5540                         END IF;
5541 
5542 END get_item_name;
5543 
5544 PROCEDURE get_item_type(in_item_type_code in  varchar2,
5545 			out_meaning out nocopy varchar2
5546 			)
5547 IS
5548 
5549 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5550 l_lookup_type varchar2(50) ;  -- added for bug 3776769
5551 BEGIN
5552    l_lookup_type := 'ITEM_IDENTIFIER_TYPE';
5553    Select meaning into out_meaning from oe_lookups
5554       where lookup_type = l_lookup_type  and  -- added for bug 3776769
5555             lookup_code=in_item_type_code;
5556 
5557 
5558 EXCEPTION
5559     when no_data_found then
5560         IF l_debug_level  > 0 THEN
5561             oe_debug_pub.add(  'OE_AVAILABILITY.GET_item_type NO DATA FOUND' ) ;
5562         END IF;
5563     when others then
5564                         IF l_debug_level  > 0 THEN
5565                             oe_debug_pub.add(  'OE_AVAILABILITY.GET_item_type WHEN OTHERS '|| SQLERRM||SQLCODE ) ;
5566                         END IF;
5567 
5568 END get_item_type;
5569 
5570 
5571 PROCEDURE get_upgrade_item_details(l_inv_item_id in number,
5572 				   out_inv_item_name out nocopy varchar2,
5573 				   out_inv_desc out nocopy varchar2,
5574 				   out_inv_item_type out nocopy varchar2
5575 			)
5576 IS
5577 l_org_id number := OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
5578 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5579 BEGIN
5580 SELECT concatenated_segments,description,item_type
5581        INTO  out_inv_item_name,out_inv_desc,out_inv_item_type
5582        FROM   mtl_system_items_kfv
5583        WHERE  inventory_item_id = l_inv_item_id
5584        AND    organization_id = l_org_id;
5585 
5586 
5587 EXCEPTION
5588     when no_data_found then
5589         IF l_debug_level  > 0 THEN
5590             oe_debug_pub.add(  'OE_AVAILABILITY.GET_item_upgrade_details NO DATA FOUND' ) ;
5591         END IF;
5592     when others then
5593                         IF l_debug_level  > 0 THEN
5594                             oe_debug_pub.add(  'OE_AVAILABILITY.GET_item_NAME WHEN OTHERS '|| SQLERRM||SQLCODE ) ;
5595                         END IF;
5596 
5597 END get_upgrade_item_details;
5598 
5599 PROCEDURE get_oid_information(l_list_line_no in number,
5600 			      out_inv_item_name out nocopy varchar2)
5601 IS
5602    l_item_id number;
5603    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5604    l_desc varchar2(200);
5605 BEGIN
5606      select product_attr_value into l_item_id from qp_pricing_attributes
5607       where list_line_id=l_list_line_no;
5608 
5609    oe_debug_pub.add('after fetching the attribute value');
5610 
5611    get_item_name(l_inv_item_id=>l_item_id,
5612 		 out_inv_item_name=>out_inv_item_name);
5613 
5614 
5615 
5616 
5617 EXCEPTION
5618    when no_data_found then
5619       IF l_debug_level  > 0 THEN
5620 	 oe_debug_pub.add(  'OE_AVAILABILITY.GET_oid_information NO DATA FOUND' ) ;
5621 END IF;
5622 when others then
5623 IF l_debug_level  > 0 THEN
5624    oe_debug_pub.add(  'OE_AVAILABILITY.GET_oid_information WHEN OTHERS '|| SQLERRM||SQLCODE ) ;
5625 END IF;
5626 
5627 END get_oid_information;
5628 
5629 PROCEDURE get_coupon_details(in_list_line_id in number,
5630 			     in_list_header_id in number,
5631 			     out_benefit out nocopy varchar2,
5632 			     out_benefit_method out nocopy varchar2,
5633 			     out_benefit_value out nocopy varchar2,
5634 			     out_benefit_item out nocopy varchar2)
5635 
5636 IS
5637    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5638    l_list_line_no NUMBER;
5639    l_code varchar2(200);
5640    l_operator varchar2(100);
5641    l_operand number;
5642    l_item_id varchar2(100);
5643    l_desc varchar2(100);
5644 BEGIN
5645    oe_debug_pub.add('before fetching the related lines');
5646 
5647      select to_rltd_modifier_id into l_list_line_no
5648        from qp_rltd_modifiers where
5649       from_rltd_modifier_id=in_list_line_id;
5650 
5651    oe_debug_pub.add('after fetching the related line');
5652 
5653      select list_line_type_code,
5654 	    arithmetic_operator,
5655 	    operand into
5656       l_code,l_operator,l_operand
5657        from qp_list_lines where list_line_id=l_list_line_no;
5658 
5659    oe_debug_pub.add('after fetching the line details ');
5660 
5661    out_benefit:= get_qp_lookup_meaning(in_lookup_type=>'LIST_LINE_TYPE_CODE',
5662 				       in_lookup_code=>l_code);
5663    out_benefit_method := get_qp_lookup_meaning(in_lookup_type=>'ARITHMETIC_OPERATOR',
5664 					       in_lookup_code=>l_operator);
5665    out_benefit_value := l_operand;
5666 
5667    oe_debug_pub.add('out_benefit'||out_benefit||'out_benefit_method'
5668 		    ||out_benefit_method||'out_benefit_value'||out_benefit_value);
5669 
5670      select product_attr_value into l_item_id from qp_pricing_attributes
5671       where list_line_id=l_list_line_no;
5672 
5673    oe_debug_pub.add('after fetching the attribute value');
5674 
5675    get_item_name(l_inv_item_id=>l_item_id,
5676 		 out_inv_item_name=>out_benefit_item);
5677 
5678 
5679    oe_debug_pub.add('inventory item returned'||out_benefit_item);
5680 EXCEPTION
5681    when no_data_found then
5682       IF l_debug_level  > 0 THEN
5683 	 oe_debug_pub.add(  'OE_AVAILABILITY.GET_coupon_details NO DATA FOUND' ) ;
5684 END IF;
5685 when others then
5686 IF l_debug_level  > 0 THEN
5687    oe_debug_pub.add(  'OE_AVAILABILITY.GET_coupon_details WHEN OTHERS '|| SQLERRM||SQLCODE ) ;
5688 END IF;
5689 
5690 END get_coupon_details;
5691 
5692 PROCEDURE get_terms_details(in_substitution_attribute in varchar2,
5693 			    in_substitution_to in varchar2,
5694 			    out_benefit_method out nocopy varchar2,
5695 			    out_benefit_value out nocopy varchar2)
5696 
5697 IS
5698 
5699    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5700    l_benefit_method Varchar2(500);
5701    l_segment_code Varchar2(500);
5702    l_lang_code Varchar2(10);
5703    l_lookup_type Varchar2(50);
5704 BEGIN
5705 
5706   if l_Debug_level >0 then
5707    oe_debug_pub.add('entering terms with parameter Substitution attribute'||in_substitution_attribute||'substituion'||
5708 		    in_substitution_to);
5709    end if;
5710    Begin
5711 	select segment_code into l_benefit_method  from qp_segments_b qsb,qp_prc_contexts_b qpcb
5712 	 where qsb.prc_context_id=qpcb.prc_context_id and
5713       qsb.segment_mapping_column=in_substitution_attribute and qpcb.prc_context_code='TERMS';
5714    Exception
5715       When others then
5716 	 oe_Debug_pub.add('Exception while quering for the terms'||SQLCODE||SQLERRM);
5717    End ;
5718    -- added recently
5719 
5720 
5721  /*  qp_util.Get_Attribute_Code(p_FlexField_Name  => 'QP_ATTR_DEFNS_QUALIFIER',
5722 			      p_Context_Name    =>  'TERMS',
5723 			      p_attribute       => l_benefit_method, -- <attribute_code>, -- pass the code like "FREIGHT_TERMS"
5724 			      x_attribute_code  =>out_benefit_method,   -- <attribute_text>, -- get the text like "Freight Terms"
5725 			      x_segment_name    => l_segment_code
5726                                   );*/
5727    Begin
5728 	select language_code into l_lang_code from fnd_languages  where installed_flag='B';
5729 
5730 	select user_segment_name into out_benefit_method from qp_segments_tl qst,qp_segments_b qsb
5731    where qst.segment_id= qsb.segment_id and qsb.segment_code=l_benefit_method and qst.language=l_lang_code;
5732    Exception
5733       When Others then
5734 	 oe_Debug_pub.add(' Exception while queries for  terms and language code'||SQLCODE||SQLERRM);
5735    End;
5736    if l_Debug_level >0 then
5737    oe_debug_pub.add('final benefit method'||out_benefit_method);
5738    end if;
5739 
5740 
5741 
5742        IF l_benefit_method ='PAYMENT_TERMS' then
5743 	    select name into out_benefit_value from ra_terms where term_id=in_substitution_to;
5744        ELSIF l_benefit_method='FREIGHT_TERMS' then
5745 	    select freight_terms into out_benefit_value from oe_frght_terms_Active_v
5746 	     where freight_terms_code=in_substitution_to;
5747        ELSIF l_benefit_method ='SHIPPING_TERMS' then
5748 	     l_lookup_type := 'SHIP_METHOD';
5749 	    select meaning into out_benefit_value from oe_ship_methods_v where
5750 	     lookup_type = l_lookup_type and lookup_code=in_substitution_to;
5751        END IF;
5752 
5753        oe_debug_pub.add('final benefit value'||out_benefit_value);
5754 
5755     EXCEPTION
5756        when no_data_found then
5757 	  IF l_debug_level  > 0 THEN
5758 	     oe_debug_pub.add(  'OE_AVAILABILITY.GET_terms_details NO DATA FOUND' ) ;
5759     END IF;
5760     when others then
5761     IF l_debug_level  > 0 THEN
5762        oe_debug_pub.add(  'OE_AVAILABILITY.GET_terms_details WHEN OTHERS '|| SQLERRM||SQLCODE ) ;
5763     END IF;
5764 
5765 END get_terms_details;
5766 
5767 
5768 
5769 PROCEDURE Get_modifier_name( in_list_header_id in number
5770 			     ,out_name out nocopy varchar2
5771 
5772 			     ,out_description out nocopy varchar2
5773 
5774 			     ,out_end_date out nocopy date
5775 
5776 			     ,out_start_date out nocopy date
5777 
5778 			     ,out_currency out nocopy varchar2
5779 
5780 			     ,out_ask_for_flag out nocopy varchar2
5781 
5782 			     ) IS
5783 
5784 
5785    l_list_type_code varchar2(300);
5786 
5787    --
5788    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5789    --
5790 BEGIN
5791 
5792      SELECT name,
5793       description,
5794       list_type_code,
5795       end_date_active,
5796       start_date_active,
5797       currency_code,
5798       ask_for_flag
5799        INTO out_name,
5800       out_description,
5801       l_list_type_code,
5802       out_end_date,
5803       out_start_date,
5804       out_currency,
5805       out_ask_for_flag
5806 
5807        FROM qp_list_headers_vl
5808       WHERE list_header_id = in_list_header_id;
5809 
5810 
5811    IF l_debug_level  > 0 THEN
5812       oe_debug_pub.add(  'END_DATE='||OUT_END_DATE|| ' START_DATE='||OUT_START_DATE ) ;
5813    END IF;
5814    IF l_debug_level  > 0 THEN
5815       oe_debug_pub.add(  'EXITING OE_AVA.GET_MODIFIER_NAME TYP='||L_LIST_TYPE_CODE ) ;
5816    END IF;
5817 
5818 EXCEPTION
5819    when no_data_found then
5820       IF l_debug_level  > 0 THEN
5821 	 oe_debug_pub.add(  'OE_AVAILABILITY.GET_MODIFIER_NAME NO DATA FOUND' ) ;
5822 END IF;
5823 when others then
5824 IF l_debug_level  > 0 THEN
5825    oe_debug_pub.add(  'OE_AVAILABILITY.GET_MODIFIER_NAME WHEN OTHERS '|| SQLERRM||SQLCODE ) ;
5826 END IF;
5827 
5828 END get_modifier_name;
5829 
5830 
5831 
5832 PROCEDURE Get_list_line_details( in_list_line_id in number
5833 				 ,out_end_date out nocopy date
5834 
5835 				 ,out_start_date out nocopy date
5836 
5837 				 ,out_list_line_type_Code out nocopy varchar2
5838 
5839 				 ,out_modifier_level_code out nocopy varchar2
5840 
5841 				 ) IS
5842 
5843    --
5844    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5845    --
5846 BEGIN
5847 
5848   SELECT
5849       l.list_line_type_code,
5850       nvl(l.end_date_active,h.end_date_active),
5851       l.start_date_active,
5852       l.modifier_level_code
5853        INTO
5854       out_list_line_type_code,
5855       out_end_date,
5856       out_start_date,
5857       out_modifier_level_code
5858 
5859        FROM qp_list_lines l,qp_list_headers h
5860       WHERE l.list_line_id = in_list_line_id
5861         AND h.list_header_id = l.list_header_id;
5862 
5863 
5864    IF l_debug_level  > 0 THEN
5865       oe_debug_pub.add(  'EXITING OE_AVA.GET_LINE_DETAILS TYPE='|| 'LIST_LINE_TYPE_CODE='|| OUT_LIST_LINE_TYPE_CODE|| 'END_DATE='||OUT_END_DATE|| ' START_DATE='||OUT_START_DATE ) ;
5866    END IF;
5867 
5868 EXCEPTION
5869    when no_data_found then
5870       IF l_debug_level  > 0 THEN
5871 	 oe_debug_pub.add(  'OE_AVAILABILITY.GET_LIST_LINE_DETAILS NO DATA FOUND' ) ;
5872 END IF;
5873 when others then
5874 IF l_debug_level  > 0 THEN
5875    oe_debug_pub.add(  'OE_AVAILABILITY.GET_LIST_LINE_DETAILS WHEN OTHERS '|| SQLERRM||SQLCODE ) ;
5876 END IF;
5877 
5878 END get_list_line_details;
5879 
5880 
5881 FUNCTION Get_qp_lookup_meaning( in_lookup_code in varchar2,
5882                                 in_lookup_type in varchar2) return varchar2 IS
5883 
5884    l_meaning varchar2(300);
5885 
5886    --
5887    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5888    --
5889 BEGIN
5890 
5891    IF l_debug_level  > 0 THEN
5892       oe_debug_pub.add(  'CODE='||IN_LOOKUP_CODE||' TYPE='||IN_LOOKUP_TYPE ) ;
5893    END IF;
5894 
5895      SELECT meaning
5896        INTO l_meaning
5897        FROM qp_lookups
5898       WHERE lookup_type = in_lookup_type
5899 	AND lookup_code = in_lookup_code;
5900 
5901    IF l_meaning = fnd_api.g_miss_char then
5902       l_meaning:= Null;
5903    END IF;
5904 
5905    Return l_meaning;
5906 
5907 EXCEPTION
5908    when no_data_found then
5909       IF l_debug_level  > 0 THEN
5910 	 oe_debug_pub.add(  'OE_AVAILABILITY.GET_QP_LOOKUP_MEANING NO DATA FOUND' ) ;
5911 END IF;
5912 Return Null;
5913 
5914 END get_qp_lookup_meaning;
5915 
5916 
5917 FUNCTION get_pricing_attribute(
5918 						     in_CONTEXT_NAME in varchar2,
5919 						     in_ATTRIBUTE_NAME in varchar2
5920 						     ) return varchar2 IS
5921    l_pricing_attribute varchar2(300);
5922 
5923    --
5924    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5925    --
5926 BEGIN
5927 
5928    IF l_debug_level  > 0 THEN
5929       oe_debug_pub.add(  'GET_PRICING_ATTRIBUTE '|| 'IN_CONTEXT = '||IN_CONTEXT_NAME|| 'IN_ATTRIBUTE_NAME='||IN_ATTRIBUTE_NAME ) ;
5930    END IF;
5931    l_pricing_attribute := QP_UTIL.get_attribute_name(
5932 						     p_application_short_name=> 'QP',
5933 						     P_FLEXFIELD_NAME =>'QP_ATTR_DEFNS_PRICING',
5934 						     P_CONTEXT_NAME =>in_context_name,
5935 						     P_ATTRIBUTE_NAME =>in_attribute_name
5936 						     );
5937    IF l_debug_level  > 0 THEN
5938       oe_debug_pub.add(  'EXITING GET_PRICING_ATTRIBUTE ='||L_PRICING_ATTRIBUTE ) ;
5939    END IF;
5940 
5941    return l_pricing_attribute;
5942 
5943 EXCEPTION
5944 
5945    WHEN others then
5946       IF l_debug_level  > 0 THEN
5947 	 oe_debug_pub.add(  'WHEN OTHERS FOR GET_PRICING_ATTRIBUTE'|| SQLCODE||SQLERRM ) ;
5948 END IF;
5949 return null;
5950 
5951 END get_pricing_attribute;
5952 
5953 
5954 
5955 PROCEDURE get_Price_List_info(
5956 			      p_price_list_id IN  NUMBER,
5957 			      out_name out nocopy varchar2,
5958 
5959 			      out_end_date out nocopy date,
5960 
5961 			      out_start_date out nocopy date,
5962 
5963 			      out_automatic_flag out nocopy varchar2,
5964 
5965 			      out_rounding_factor out nocopy varchar2,
5966 
5967 			      out_terms_id out nocopy number,
5968 
5969 			      out_gsa_indicator out nocopy varchar2,
5970 
5971 			      out_currency out nocopy varchar2,
5972 
5973 			      out_freight_terms_code out nocopy varchar2
5974 
5975 			      ) IS
5976 
5977    --
5978    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5979    --
5980 BEGIN
5981 
5982    IF l_debug_level  > 0 THEN
5983       oe_debug_pub.add(  'GET PRICE_LIST ID='||P_PRICE_LIST_ID ) ;
5984    END IF;
5985 
5986    IF p_price_list_id IS NOT NULL THEN
5987 
5988         SELECT  NAME,
5989                 end_date_active,
5990                 start_date_active,
5991                 automatic_flag,
5992                 rounding_factor,
5993                 terms_id,
5994                 gsa_indicator,
5995                 currency_code,
5996                 freight_terms_code
5997 	  INTO    out_name,
5998 		  out_end_date,
5999 		  out_start_date,
6000 		  out_automatic_flag,
6001 		  out_rounding_factor,
6002 		  out_terms_id,
6003 		  out_gsa_indicator,
6004 		  out_currency,
6005 		  out_freight_terms_code
6006 
6007 	  FROM    qp_list_headers_vl
6008 	 WHERE   list_header_id = p_price_list_id
6009 	   and   list_type_code in ('PRL', 'AGR');
6010 
6011    END IF;
6012 
6013    IF l_debug_level  > 0 THEN
6014       oe_debug_pub.add(  'END_DATE='||OUT_END_DATE|| ' START_DATE='||OUT_START_DATE ) ;
6015    END IF;
6016 
6017 EXCEPTION
6018 
6019    WHEN NO_DATA_FOUND THEN
6020       IF l_debug_level  > 0 THEN
6021 	 oe_debug_pub.add(  'NO DATA FOUND GET PRICE LIST_INFO' ) ;
6022 END IF;
6023 
6024 WHEN OTHERS THEN
6025 IF l_debug_level  > 0 THEN
6026    oe_debug_pub.add(  'WHEN OTHERS GET PRICE LIST_INFO'|| SQLCODE||SQLERRM ) ;
6027 END IF;
6028 
6029 END get_Price_List_info;
6030 
6031 
6032 
6033 
6034 PROCEDURE  get_item_information(
6035 				 in_inventory_item_id in number
6036 				,in_org_id in number
6037 				,out_item_status out nocopy varchar2
6038 				,out_wsh out nocopy varchar2
6039 				,out_wsh_name out nocopy varchar2
6040 				,out_category out nocopy varchar2
6041 				,out_lead_time out nocopy number
6042 				,out_cost out nocopy number
6043 				,out_primary_uom out nocopy varchar2
6044 				,out_user_item_type out nocopy varchar2
6045 				,out_make_or_buy out nocopy varchar2
6046 				,out_weight_uom out nocopy varchar2
6047 				,out_unit_weight out nocopy number
6048 				,out_volume_uom out nocopy varchar2
6049 				,out_unit_volume out nocopy number
6050 				,out_min_order_quantity out nocopy number
6051 				,out_max_order_quantity out nocopy number
6052 				,out_fixed_order_quantity out nocopy number
6053 				,out_customer_order_flag out nocopy varchar2
6054 				,out_internal_order_flag out nocopy varchar2
6055 				,out_stockable out nocopy varchar2
6056 				,out_reservable out nocopy varchar2
6057 				,out_returnable out nocopy varchar2
6058 				,out_shippable out nocopy varchar2
6059 				,out_orderable_on_web out nocopy varchar2
6060 				,out_taxable out nocopy varchar2
6061 				,out_serviceable out nocopy varchar2
6062 				,out_atp_flag out nocopy varchar2
6063                                 ,out_bom_item_type out nocopy varchar2
6064                                 ,out_replenish_to_order_flag out nocopy varchar2
6065                                 ,out_build_in_wip_flag out nocopy varchar2
6066                                 ,out_default_so_source_type out nocopy varchar2
6067 				) IS
6068 
6069    CURSOR c_item_info IS
6070      SELECT shippable_item_flag,
6071 	    customer_order_enabled_flag,
6072 	    internal_order_enabled_flag,
6073 	    stock_enabled_flag,
6074 	    default_shipping_org,
6075 	    returnable_flag,
6076 	    source_organization_id,
6077 	    unit_weight,
6078 	    weight_uom_code,
6079 	    unit_volume,
6080 	    volume_uom_code,
6081 	    cum_manufacturing_lead_time,
6082 	    cumulative_total_lead_time,
6083 	    primary_unit_of_measure,
6084 	    inventory_item_status_code,
6085 	    full_lead_time,
6086 	    order_cost,
6087 	    minimum_order_quantity,
6088 	    maximum_order_quantity,
6089 	    fixed_order_quantity,
6090 	    reservable_type,
6091 	    item_type,
6092 	    orderable_on_web_flag,
6093 	    planning_make_buy_code,
6094 	    taxable_flag ,
6095 	    serviceable_product_flag,
6096 	    atp_flag,
6097             bom_item_type,
6098             replenish_to_order_flag,
6099             build_in_wip_flag,
6100             decode(default_so_source_type,'EXTERNAL','External','INTERNAL','Internal')
6101        FROM mtl_system_items
6102       WHERE inventory_item_id = in_inventory_item_id
6103 	AND organization_id   = in_org_id;
6104 
6105    l_default_shipping_org number;
6106    l_source_organization_id number;
6107    l_cum_manufactureing_lead_time number;
6108    l_cummulative_total_lead_time number;
6109    l_inventory_item_status_code varchar2(10);
6110    l_full_lead_time number;
6111    l_order_cost number;
6112    l_reservable_type number;
6113    l_user_item_type varchar2(30);
6114    l_ship_from_org varchar2(200);
6115    l_ship_from_org_name varchar2(200);
6116    l_make_buy number;
6117 
6118    --
6119    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6120    --
6121    l_lookup_type varchar2(50);
6122 BEGIN
6123 
6124    IF l_debug_level  > 0 THEN
6125       oe_debug_pub.add(  'ENTERING oe_oe_pricing_availability.GET_ITEM_INFO'||
6126 			 'INV_ITEM_ID='||IN_INVENTORY_ITEM_ID|| 'ORG_ID='||IN_ORG_ID ) ;
6127    END IF;
6128 
6129    OPEN  c_item_info;
6130    FETCH c_item_info
6131        INTO out_shippable,
6132 	    out_customer_order_flag,
6133 	    out_internal_order_flag,
6134 	    out_stockable,
6135 	    l_default_shipping_org,
6136 	    out_returnable,
6137 	    l_source_organization_id,
6138 	    out_unit_weight,
6139 	    out_weight_uom,
6140 	    out_unit_volume,
6141 	    out_volume_uom,
6142 	    l_cum_manufactureing_lead_time,
6143 	    l_cummulative_total_lead_time,
6144 	    out_primary_uom,
6145 	    l_inventory_item_status_code,
6146 	    l_full_lead_time,
6147 	    l_order_cost,
6148 	    out_min_order_quantity,
6149 	    out_max_order_quantity,
6150 	    out_fixed_order_quantity,
6151 	    l_reservable_type,
6152 	    l_user_item_type,
6153 	    out_orderable_on_web,
6154 	    l_make_buy,
6155 	    out_taxable,
6156 	    out_serviceable,
6157 	    out_atp_flag,
6158             out_bom_item_type,
6159             out_replenish_to_order_flag,
6160             out_build_in_wip_flag,
6161             out_default_so_source_type;
6162 
6163    CLOSE c_item_Info;
6164 
6165    out_item_status := l_inventory_item_status_code;
6166 
6167    IF l_make_buy = 1 then
6168       out_make_or_buy := 'Make';
6169    ELSE
6170       out_make_or_buy := 'Buy';
6171    END IF;
6172 
6173 
6174    oe_oe_pricing_availability.get_Ship_From_Org
6175       (   in_org_id => in_org_id
6176 	  ,   out_code=>out_wsh
6177 	  ,   out_name =>out_wsh_name
6178           );
6179 
6180    IF l_debug_level  > 0 THEN
6181       oe_debug_pub.add(  'USER_ITEM_TYPE='||L_USER_ITEM_TYPE ) ;
6182    END IF;
6183 
6184    out_lead_time := l_cummulative_total_lead_time;
6185    out_cost := l_order_cost;
6186 
6187    IF l_reservable_type = 1 then
6188       out_reservable := 'Y';
6189    ELSE
6190       out_reservable := 'N';
6191 
6192    END IF;
6193    l_lookup_type := 'ITEM_TYPE';   -- added for bug 3776769
6194    IF l_user_item_type is NOT NULL then
6195 	select meaning
6196           into out_user_item_type
6197 	 from fnd_common_lookups
6198         where lookup_type = l_lookup_type   -- added for bug 3776769
6199           and lookup_code = l_user_item_type;
6200    ELSE
6201       out_user_item_type := null;
6202 
6203    END IF;
6204    IF l_debug_level  > 0 THEN
6205       oe_debug_pub.add(  'EXITING oe_oe_pricing_availability.GET_ITEM_INFO'||
6206 			 ' ITEM_STATUS ='||OUT_ITEM_STATUS ) ;
6207    END IF;
6208 
6209 EXCEPTION
6210 
6211    WHEN OTHERS THEN
6212       IF c_item_info%ISOPEN then
6213 	 CLOSE c_item_info;
6214 END IF;
6215 
6216 IF l_debug_level  > 0 THEN
6217    oe_debug_pub.add(  'WHEN OTHERS oe_oe_pricing_availability.GET_ITEM_INFO '||
6218 		      'INV_ITEM_ID='||IN_INVENTORY_ITEM_ID|| 'ORG_ID='||IN_ORG_ID||
6219 		      'SQLCODE='||SQLCODE|| 'SQLERRM='||SQLERRM ) ;
6220 END IF;
6221 
6222 END get_item_information;
6223 
6224 
6225 
6226 PROCEDURE print_time(in_place in varchar2) IS
6227 
6228    cursor c_hsecs is
6229      select hsecs
6230        from v$timer;
6231 
6232    l_hsecs number;
6233    l_total number;
6234 
6235    --
6236    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6237    --
6238 BEGIN
6239 
6240    --print_time2;
6241    OPEN c_hsecs;
6242    FETCH c_hsecs
6243        INTO l_hsecs;
6244    CLOSE c_hsecs;
6245 
6246    IF g_hsecs is null then
6247 
6248       g_hsecs := l_hsecs;
6249       g_place := in_place;
6250       IF l_debug_level  > 0 THEN
6251 	 oe_debug_pub.add(  'TIME STARTING AT PLACE '||G_PLACE||' TIME='||G_HSECS ) ;
6252       END IF;
6253 
6254    ELSE
6255       l_total := (l_hsecs - g_hsecs)/100;
6256       g_total := g_total + l_total;
6257       IF l_debug_level  > 0 THEN
6258 	 oe_debug_pub.add(  'TIME FROM ' ||G_PLACE||' TO '||IN_PLACE||
6259 			    ' TIME DIFF='|| L_TOTAL||' SECONDS'||' TOTAL SO FAR='||G_TOTAL ) ;
6260       END IF;
6261       g_hsecs := l_hsecs;
6262       g_place := in_place;
6263 
6264    END IF;
6265    --print_time2;
6266 
6267 END print_time;
6268 
6269 
6270 PROCEDURE print_time2 IS
6271 
6272    cursor c2_hsecs is
6273      select hsecs
6274        from v$timer;
6275 
6276    l_hsecs number;
6277    l_total number;
6278 
6279    --
6280    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6281    --
6282 BEGIN
6283 
6284    OPEN c2_hsecs;
6285    FETCH c2_hsecs
6286        INTO l_hsecs;
6287    CLOSE c2_hsecs;
6288 
6289    IF g_total2 is null then
6290       IF l_debug_level  > 0 THEN
6291 	 oe_debug_pub.add(  'G_TOTAL2 IS NULL L_HSECS='||L_HSECS ) ;
6292       END IF;
6293       g_total2 := l_hsecs;
6294    ELSE
6295       IF l_debug_level  > 0 THEN
6296 	 oe_debug_pub.add(  'L_HSECS='||L_HSECS||' TOTAL2='||G_TOTAL2 ) ;
6297       END IF;
6298       l_total := (l_hsecs - g_total2)/100;
6299       IF l_debug_level  > 0 THEN
6300 	 oe_debug_pub.add(  'G_TOTAL2='||L_TOTAL ) ;
6301       END IF;
6302       g_total2 := l_hsecs;
6303    END IF;
6304 
6305 END print_time2;
6306 
6307 
6308 PROCEDURE get_global_availability (
6309 				   in_customer_id in number
6310 				   ,in_customer_site_id in number
6311 				   ,in_inventory_item_id in number
6312 				   ,in_org_id            in number
6313 				   ,x_return_status out nocopy varchar2
6314 				   ,x_msg_data out nocopy varchar2
6315 				   ,x_msg_count out nocopy number
6316 				   ,l_source_orgs_table out nocopy source_orgs_table
6317 				   )IS
6318 
6319    l_instance_id number;
6320    CURSOR c_instance_id IS
6321      SELECT instance_id,
6322 	    instance_code
6323        FROM mrp_ap_apps_instances;
6324 
6325    l_mrp_atp_database_link varchar2(300);
6326    x_assignment_set_id number;
6327    x_assignment_set_name varchar2(300);
6328    x_plan_id number;
6329    x_plan_name varchar2(300);
6330    x_ret_code varchar2(300);
6331    x_err_mesg varchar2(2000);
6332    l_session_id number;
6333    --l_item_arr  mrp_atp_pub.number_arr := mrp_atp_pub.number_arr(1);
6334    l_organization_id number;
6335    x_sources mrp_atp_pvt.atp_source_typ;
6336    l_calling_module number;
6337    x_error_mesg varchar2(2000);
6338    l_other_cols  order_sch_wb.other_cols_typ;
6339    --l_source_orgs_table source_orgs_table;
6340    l_count number := 1;
6341    l_on_hand_qty number;
6342    l_reservable_qty number;
6343    l_available_qty    number;
6344    l_ship_from_org_id number;
6345    l_available_date   date;
6346    l_qty_uom          varchar2(25);
6347    l_out_message      varchar2(300);
6348    l_return_status    VARCHAR2(1);
6349    l_msg_count        NUMBER;
6350    l_msg_data         VARCHAR2(2000);
6351    l_error_message varchar2(2000);
6352    l_org_id number;
6353    l_customer_id number;
6354    l_customer_site_id number;
6355    l_ship_method varchar2(30);
6356    l_dynstring           VARCHAR2(500) := NULL;
6357    l_instance_code varchar2(100);
6358 
6359    l_inv_ctp number;
6360 
6361    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6362 
6363    CURSOR c_temp_table(in_session_id in number) IS
6364      SELECT source_organization_id,
6365 	    sr_instance_id,
6366 	    ship_method,
6367 	    delivery_lead_time,
6368 	    freight_carrier
6369        FROM mrp_atp_schedule_temp
6370       WHERE session_id = in_session_id
6371 	    --AND status_flag = -99;
6372 	AND status_flag = 22;
6373 
6374    sql_stmt              VARCHAR2(3200);
6375 
6376 BEGIN
6377 
6378    IF l_debug_level  > 0 THEN
6379       oe_debug_pub.add(  'ENTERING GA IN_ORG_ID='||IN_ORG_ID|| ' IN_CUSTOMER_ID='||IN_CUSTOMER_ID
6380 			 || ' IN_SITE_ID ='||IN_CUSTOMER_SITE_ID|| ' IN_ITEM_ID ='||IN_INVENTORY_ITEM_ID ) ;
6381    END IF;
6382 
6383    OPEN c_instance_id;
6384    FETCH c_instance_id
6385        INTO l_instance_id,
6386 	    l_instance_code;
6387    CLOSE c_instance_id;
6388 
6389 
6390    x_return_status := 'S';
6391    -- No need to check profile.. Instead get the link from
6392    -- table mrp_ap_apps_instances 4113599
6393    -- l_mrp_atp_database_link := fnd_profile.value('MRP_ATP_DATABASE_LINK');
6394 
6395    --Bug 6716697: Wrong dblink name was selected. Corrcted as per ATP team
6396    select a2m_dblink
6397    into l_mrp_atp_database_link
6398    from mrp_ap_apps_instances;
6399 
6400    IF l_debug_level  > 0 THEN
6401       oe_debug_pub.add(  'L_INSTANCE_ID='||L_INSTANCE_ID|| ' DB LINK='
6402 			 ||L_MRP_ATP_DATABASE_LINK ||' Ins Code='||l_instance_code) ;
6403    END IF;
6404 
6405    msc_sch_wb.get_assignment_set(
6406 				 x_dblink        => l_mrp_atp_database_link
6407 				 ,x_assignment_set_id=>x_assignment_set_id
6408 				 ,x_assignment_set_name=>x_assignment_set_name
6409 				 ,x_plan_id            =>x_plan_id
6410 				 ,x_plan_name          =>x_plan_name
6411 				 ,x_sr_instance_id=>l_instance_id
6412 				 ,x_inst          =>'APPS'
6413 				 ,x_ret_code      =>x_return_status
6414 				 ,x_err_mesg      =>x_err_mesg
6415 				 );
6416 
6417    IF l_debug_level  > 0 THEN
6418       oe_debug_pub.add(  'ASSIGNMENT_SET_ID='||X_ASSIGNMENT_SET_ID|| ' SET NAME='||
6419 			 X_ASSIGNMENT_SET_NAME|| ' PLAN ID='||X_PLAN_ID|| ' PLAN NAME='
6420 			 ||X_PLAN_NAME|| ' RET CODE='||X_RETURN_STATUS|| ' ERR MESG='||X_ERR_MESG ) ;
6421    END IF;
6422 
6423    IF nvl(x_return_status,'E') = 'E'
6424 	and x_assignment_set_id is null  then
6425 
6426       x_msg_data := x_err_mesg;
6427       IF l_debug_level  > 0 THEN
6428 	 oe_debug_pub.add(  'RETURNING IN GA 1' ) ;
6429       END IF;
6430 
6431       IF x_msg_data is not null then
6432 
6433 	 IF l_debug_level  > 0 THEN
6434 	    oe_debug_pub.add(  'MSG DATA IS NOT NULL' ) ;
6435 	 END IF;
6436 	 x_return_status := 'E';
6437 	 FND_MESSAGE.SET_NAME('ONT','ONT_AVAIL_GENERIC');
6438 	 IF l_debug_level  > 0 THEN
6439 	    oe_debug_pub.add(  'MSG DATA IS NOT NULL 2' ) ;
6440 	 END IF;
6441 	 FND_MESSAGE.SET_TOKEN('TEXT',x_msg_data);
6442 	 OE_MSG_PUB.Add;
6443 
6444       END IF;
6445 
6446 
6447    ELSE -- if get_assignment_set was sucessful
6448 
6449 
6450 	SELECT mrp_atp_schedule_temp_s.nextval
6451 	  INTO l_session_id
6452 	  FROM dual;
6453 
6454       x_return_status := 'S';
6455 
6456       IF in_customer_site_id is not null and in_customer_id is not null then
6457 	 l_customer_id := in_customer_id;
6458 	 l_customer_site_id := in_customer_site_id;
6459 	 l_org_id := null;
6460       ELSE
6461 	 l_org_id := in_org_id;
6462 	 l_customer_id := null;
6463 	 l_customer_site_id := null;
6464       END IF;
6465 
6466 
6467     /*fnd_profile.get('INV_CTP',l_inv_ctp);
6468     IF l_debug_level  > 0 THEN
6469       oe_debug_pub.add(' Inventory Capable to Promise='||l_inv_ctp);
6470     END IF;
6471 
6472       --Profile Inventory Capable to Prmise
6473       -- 4= PDS and we need to select a plan_id for org-org sourcing
6474       -- 5= ODS and we need to pass -1 as plan_id
6475     IF l_inv_ctp = 5 then
6476       x_plan_id := -1;
6477     END IF;
6478 
6479       -- if destination is the org, then for looking at the sourcing rule
6480       -- we need to pass the plan_id from the planning server
6481       -- get_assignment_set currently does not return plan_id
6482     IF l_inv_ctp <> 5 AND
6483        l_org_id is not null and
6484       (l_customer_id is null and l_customer_site_id is null) then
6485 
6486       IF l_mrp_atp_database_link IS NOT NULL THEN
6487         l_dynstring := '@'||l_mrp_atp_database_link;
6488       END IF;
6489 
6490       IF l_debug_level  > 0 THEN
6491         oe_debug_pub.add('Getting Plan Id dynamic string='||l_dynstring);
6492       END IF;
6493 
6494       sql_stmt :=
6495        ' SELECT '||
6496        ' mast.plan_id '||
6497        ' FROM msc_atp_plan_sn'||l_dynstring||' mast '||
6498        ' WHERE mast.sr_instance_id = :in_instance_id '||
6499        ' AND mast.sr_inventory_item_id = :in_inventory_item_id'||
6500        ' AND mast.organization_id = :in_org_id';
6501 
6502       IF l_debug_level  > 0 THEN
6503         oe_debug_pub.add('Planning Sql='||sql_stmt);
6504       END IF;
6505 
6506 
6507       EXECUTE IMMEDIATE sql_stmt INTO x_plan_id
6508 		using l_instance_id,in_inventory_item_id,l_org_id;
6509 
6510 
6511       IF x_plan_id is null then
6512         fnd_message.set_name('MSC', 'MSC_NO_PLANS_DEFINED');
6513         oe_msg_pub.add;
6514         x_return_status := 'E';
6515         oe_debug_pub.add('Plan Id NOT FOUND');
6516       END IF;
6517 
6518     END IF; -- if plan_id needs to be fetched */
6519 
6520 
6521       IF x_plan_id is null then
6522 	 x_plan_id := -1;
6523       END IF;
6524 
6525       -- if the plan was fetched and found then continue
6526       IF nvl(x_return_status,'E') <> 'E' then
6527 
6528 	 IF l_debug_level  > 0 THEN
6529 	    oe_debug_pub.add(' Before inserting into temp table '||
6530 			     ' instance_id='||l_instance_id||
6531 			     ' session_id='||l_session_id||
6532 			     ' inv_item_id='||in_inventory_item_id||
6533 			     ' customer_id='||l_customer_id||
6534 			     ' customer_site_id='||l_customer_site_id||
6535 			     ' org_id='||l_org_id||
6536 			     ' ship_method='||l_ship_method
6537 			     );
6538 	 END IF;
6539 
6540 	 -- insert into mrp_atp_schedule_Temp
6541 	   INSERT INTO MRP_ATP_SCHEDULE_TEMP(
6542 					     sr_instance_id,
6543 					     session_id,
6544 					     inventory_item_id,
6545 					     organization_id,
6546 					     scenario_id,
6547 					     customer_id,
6548 					     customer_site_id,
6549 					     ship_method,
6550 					     status_flag,
6551                                              order_line_id)
6552 	   VALUES
6553 	    (l_instance_id,
6554 	     l_session_id,
6555 	     in_inventory_item_id,
6556 	     l_org_id,
6557 	     -1,
6558 	     l_customer_id,
6559 	     l_customer_site_id,
6560 	     l_ship_method,
6561 	     4,
6562              -1
6563 	     );
6564 
6565 
6566 	 IF l_debug_level  > 0 THEN
6567 	    print_time('Calling Get Supply Sources');
6568 	 END IF;
6569 
6570 	 msc_sch_wb.get_supply_sources_local(
6571 					     x_dblink=>l_mrp_atp_database_link,
6572 					     x_session_id=>l_session_id,
6573 					     x_sr_instance_id=>l_instance_id,
6574 					     x_assignment_set_id=>x_assignment_set_id,
6575 					     x_plan_id=>x_plan_id,
6576 					     x_calling_inst=>'APPS',
6577 					     x_ret_status=>x_return_status,
6578 					     x_error_mesg=>x_err_mesg);
6579 
6580 	 IF l_debug_level  > 0 THEN
6581 	    print_time('After Calling Get Supply Sources');
6582 
6583 	    oe_debug_pub.add(  ' After CALLing  get_supply_sources_local '||
6584 			       ' status='||x_return_status||
6585 			       ' message='||x_err_mesg);
6586 
6587 	 END IF;
6588 
6589 	 IF nvl(x_return_status,'S') <> 'S' THEN
6590 	    IF l_debug_level  > 0 THEN
6591 	       oe_debug_pub.add(  ' ERROR IN CALL TO get_supply_sources_local');
6592 	    END IF;
6593 	    fnd_message.set_name('MSC', x_err_mesg);
6594 	    oe_msg_pub.add;
6595 
6596 	 ELSE
6597 
6598 	    IF x_return_status IS NULL THEN
6599 	       x_return_status := 'S';
6600 	    END IF;
6601 
6602 	    IF l_debug_level  > 0 THEN
6603 	       oe_debug_pub.add(  ' SUCCESS IN CALL TO get_supply_sources_local');
6604 	    END IF;
6605 
6606 	    -- Read from mrp_atp_schedule_Temp
6607 	    -- Insert into l_sources_orgs_table org_id and instance_id
6608 	    -- delete from mrp_atp_schedule_temp
6609 
6610 	    FOR l_temp_rec in c_temp_table(l_session_id)
6611 			      LOOP
6612 	       IF l_debug_level  > 0 THEN
6613 		  oe_debug_pub.add(  ' Reading data from temp table');
6614 	       END IF;
6615 	       l_source_orgs_table(l_count).org_id:=l_temp_rec.source_organization_id;
6616 	       l_source_orgs_table(l_count).instance_id:=l_temp_rec.sr_instance_id;
6617 	       l_source_orgs_table(l_count).ship_method:=l_temp_rec.ship_method;
6618 	       l_source_orgs_table(l_count).delivery_lead_time:=l_temp_rec.delivery_lead_time;
6619 	       l_source_orgs_table(l_count).freight_carrier:=l_temp_rec.freight_carrier;
6620 	       l_source_orgs_table(l_count).instance_code:=l_instance_code;
6621 	       l_count := l_count + 1;
6622 
6623 	    END LOOP;
6624 
6625 	    IF l_debug_level  > 0 THEN
6626 	       oe_debug_pub.add(  ' After Reading data from temp table');
6627 	    END IF;
6628 
6629 	    IF l_source_orgs_table.COUNT > 0 then
6630 	       FOR i in l_source_orgs_table.FIRST..l_source_orgs_table.LAST
6631 			LOOP
6632 		  IF l_debug_level  > 0 THEN
6633 		     oe_debug_pub.add(' Record = '||i||
6634 				      ' org_id ='||l_source_orgs_table(i).org_id||
6635 				      ' instance_id ='||l_source_orgs_table(i).instance_id||
6636 				      ' ship_method ='||l_source_orgs_table(i).ship_method||
6637 				      ' del_lead_time ='||l_source_orgs_table(i).delivery_lead_time||
6638 				      ' Instance_Code ='||l_source_orgs_table(i).Instance_Code
6639 				      );
6640 
6641 		  END IF;
6642 
6643 	       END LOOP;
6644 	    ELSE
6645 
6646 	       IF l_debug_level  > 0 THEN
6647 		  oe_debug_pub.add(  ' THERE ARE NO SOURCES TO BE DISPLAYED ' ) ;
6648 	       END IF;
6649 	       x_return_status := 'E';
6650 	       x_error_mesg := 'MRP_ATP_NO_SOURCES';
6651 	       FND_MESSAGE.SET_NAME('MSC','MRP_ATP_NO_SOURCES');
6652 	       OE_MSG_PUB.Add;
6653 	       x_return_status := 'E';
6654 
6655 	    END IF; -- IF x_sources.organization_id.COUNT > 0
6656 
6657 	 END IF; -- if get_supply_sources is not successful
6658 
6659 	 --deleting from the temp table
6660 	   DELETE mrp_atp_schedule_temp
6661 	    WHERE session_id = l_session_id;
6662 
6663       END IF; -- if the fetching of plan was successful
6664 
6665    END IF; -- if get_assignment fails
6666 
6667 
6668    -- if it was a failure then we retrieve the message
6669    IF nvl(x_return_status,'E') <> 'S' then
6670       IF l_debug_level  > 0 THEN
6671 	 oe_debug_pub.add(  'DOING COUNT_AND_GET' ) ;
6672       END IF;
6673       oe_msg_pub.count_and_get(p_encoded=>fnd_api.G_TRUE,
6674 			       p_count => x_msg_count,
6675 			       p_data=>x_msg_data
6676 			       );
6677       IF l_debug_level  > 0 THEN
6678 	 oe_debug_pub.add(  'COUNT = '||X_MSG_COUNT||' MSG='||X_MSG_DATA ) ;
6679       END IF;
6680    END IF;
6681 
6682    IF l_debug_level  > 0 THEN
6683       oe_debug_pub.add(  'EXITING GA' ) ;
6684    END IF;
6685 
6686 EXCEPTION
6687    WHEN OTHERS THEN
6688 
6689       IF l_debug_level  > 0 THEN
6690 	 oe_debug_pub.add(  'WHEN OTHERS OF get_global_availability' ) ;
6691 	 oe_debug_pub.add(  'CODE='||SQLCODE||' MSG='||SQLERRM ) ;
6692 END IF;
6693 
6694 x_return_status := 'E';
6695 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6696 
6697 --  Get message count and data
6698 OE_MSG_PUB.Count_And_Get
6699    (   p_count                       => x_msg_count
6700        ,   p_data                        => x_msg_data
6701        );
6702 
6703 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
6704    OE_MSG_PUB.Add_Exc_Msg
6705       (   G_PKG_NAME,
6706 	  'Get_Global_Availability');
6707 END IF;
6708 
6709 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6710 
6711 END get_global_availability;
6712 
6713 
6714 
6715 PROCEDURE different_uom(
6716                         in_org_id in number
6717 			,in_ordered_uom in varchar2
6718 			,in_pricing_uom in varchar2
6719 			,out_conversion_rate out nocopy number
6720 
6721 			)IS
6722 
6723    CURSOR c_items IS
6724      SELECT primary_uom_code
6725        FROM mtl_system_items_b
6726       WHERE organization_id = in_org_id
6727 	AND inventory_item_id = g_panda_rec_table(1).p_Inventory_item_id;
6728 
6729    CURSOR c_class(in_ordered_uom in varchar2) is
6730      SELECT uom_Class
6731        FROM mtl_units_of_measure_tl
6732       WHERE uom_code = in_ordered_uom;
6733 
6734    CURSOR c_base_uom(in_class in varchar2) IS
6735      SELECT uom_code
6736        FROM mtl_units_of_measure_tl
6737       WHERE uom_class = in_class
6738 	AND base_uom_flag = 'Y';
6739 
6740    l_primary_Uom varchar2(100);
6741    l_uom_class varchar2(50);
6742    l_base_uom varchar2(50);
6743    l_conversion_rate number;
6744    l_ordered_conversion number;
6745    l_pricing_conversion number;
6746 
6747    --
6748    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6749    --
6750 BEGIN
6751 
6752    IF l_debug_level  > 0 THEN
6753       oe_debug_pub.add(  'ENTERING OE_AVAILABILITY.DIFFERENT_UOM'||
6754 			 ' ORDERED_UOM ='||IN_ORDERED_UOM|| ' PRICING_UOM='||
6755 			 IN_PRICING_UOM|| ' IN_INV_ITEM_ID='||
6756 			 G_panda_rec_table(1).p_INVENTORY_ITEM_ID|| ' IN_ORG_ID='||IN_ORG_ID ) ;
6757    END IF;
6758 
6759    OPEN c_items;
6760    FETCH c_items
6761        INTO l_primary_uom;
6762 
6763    IF c_items%FOUND then
6764 
6765       OPEN c_class(l_primary_uom);
6766       FETCH c_class
6767 	  INTO l_uom_class;
6768 
6769       IF c_class%FOUND then
6770 
6771 	 OPEN c_base_uom(l_uom_class);
6772 	 FETCH c_base_Uom
6773 	     INTO l_base_uom;
6774 
6775 	 IF c_base_uom%FOUND then
6776 
6777 	    -- Both Ordered and Pricing are not Base UOM
6778 	    IF in_ordered_uom <> l_base_uom AND
6779            in_pricing_uom <> l_base_uom THEN
6780 
6781           IF l_debug_level  > 0 THEN
6782               oe_debug_pub.add(  'NEITHER THE ORDERED OR PRICING UOM IS BASE UOM' ) ;
6783           END IF;
6784 
6785           l_ordered_conversion := get_conversion_rate(
6786                                      in_uom_code => in_ordered_uom,
6787                                      in_base_uom => l_base_uom
6788                                                       );
6789           IF l_debug_level  > 0 THEN
6790               oe_debug_pub.add(  'THE ORD RATE ='||L_ORDERED_CONVERSION ) ;
6791           END IF;
6792           l_pricing_conversion := get_conversion_rate(
6793                                      in_uom_code => in_pricing_uom,
6794                                      in_base_uom => l_base_uom
6795                                                       );
6796           IF l_debug_level  > 0 THEN
6797               oe_debug_pub.add(  'THE PRICING RATE ='||L_PRICING_CONVERSION ) ;
6798           END IF;
6799 
6800           out_conversion_rate := l_ordered_conversion/l_pricing_conversion;
6801           IF l_debug_level  > 0 THEN
6802               oe_debug_pub.add(  'THE RATE ='||OUT_CONVERSION_RATE ) ;
6803           END IF;
6804 
6805         -- Ordered Uom is the Base Uom,sending the pricing uom for conversion
6806         ELSIF  in_ordered_uom = l_base_uom then
6807 
6808           IF l_debug_level  > 0 THEN
6809               oe_debug_pub.add(  'THE ORDERED UOM IS BASE UOM' ) ;
6810           END IF;
6811 
6812           l_ordered_conversion := get_conversion_rate(
6813                                      in_uom_code => in_pricing_uom,
6814                                      in_base_uom => l_base_uom
6815                                                       );
6816           out_conversion_rate := l_ordered_conversion;
6817           IF l_debug_level  > 0 THEN
6818               oe_debug_pub.add(  'THE RATE ='||OUT_CONVERSION_RATE ) ;
6819           END IF;
6820 
6821         -- Pricing Uom is the Base Uom
6822         ELSIF  in_pricing_uom = l_base_uom then
6823 
6824           IF l_debug_level  > 0 THEN
6825               oe_debug_pub.add(  'THE PRICING UOM IS BASE UOM' ) ;
6826           END IF;
6827           l_pricing_conversion := get_conversion_rate(
6828                                      in_uom_code => in_ordered_uom,
6829                                      in_base_uom => l_base_uom
6830                                                       );
6831           out_conversion_rate := l_pricing_conversion;
6832           IF l_debug_level  > 0 THEN
6833               oe_debug_pub.add(  'THE RATE ='||OUT_CONVERSION_RATE ) ;
6834           END IF;
6835 
6836         END IF;
6837 
6838       END IF;
6839 
6840       CLOSE c_base_uom;
6841 
6842     END IF;
6843 
6844     CLOSE c_class;
6845 
6846   END IF;
6847   CLOSE c_items;
6848 
6849 EXCEPTION
6850 
6851   WHEN NO_DATA_FOUND THEN
6852     IF l_debug_level  > 0 THEN
6853         oe_debug_pub.add(  'NO DATA FONUNG DIFFERENT_UOM ' ) ;
6854     END IF;
6855 
6856   WHEN OTHERS THEN
6857     IF c_items%ISOPEN then
6858       CLOSE c_items;
6859     END IF;
6860     IF c_class%ISOPEN then
6861       CLOSE c_class;
6862     END IF;
6863     IF c_base_uom%ISOPEN then
6864       CLOSE c_base_uom;
6865     END IF;
6866                     IF l_debug_level  > 0 THEN
6867                         oe_debug_pub.add(  'ERROR IN DIFFERENT_UOM '|| SQLCODE||SQLERRM ) ;
6868                     END IF;
6869 
6870 END different_uom;
6871 
6872 
6873 
6874 FUNCTION get_conversion_rate (in_uom_code in varchar2,
6875                               in_base_uom in varchar2
6876                              ) RETURN number is
6877 
6878 
6879 CURSOR c_item_conversion IS
6880   SELECT round(1/conversion_rate,6)
6881     FROM mtl_uom_conversions
6882    WHERE uom_code  = in_uom_code
6883      AND inventory_item_id = g_panda_rec_table(1).p_inventory_item_id;
6884 
6885 CURSOR c_conversion IS
6886   SELECT round(1/conversion_rate,6)
6887     FROM mtl_uom_conversions
6888    WHERE uom_Code = in_uom_code
6889      AND inventory_item_id = 0;
6890 
6891 CURSOR c_inter_class IS
6892   SELECT round(1/conversion_rate,6)
6893     FROM mtl_uom_class_conversions
6894    WHERE to_uom_code = in_uom_code
6895      AND from_uom_code  = in_base_uom
6896      AND inventory_item_id = g_panda_rec_table(1).p_inventory_item_id;
6897 
6898 l_conversion_rate number;
6899 l_uom_code varchar2(50);
6900 
6901 --
6902 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6903 --
6904 BEGIN
6905 
6906                     IF l_debug_level  > 0 THEN
6907                         oe_debug_pub.add(  'INSIDE GET_CONVERSION_RATE '|| ' IN_UOM_CODE='||IN_UOM_CODE|| ' IN_BASE_UOM='||IN_BASE_UOM ) ;
6908                     END IF;
6909 
6910     OPEN c_item_conversion;
6911     FETCH c_item_conversion
6912      INTO l_conversion_rate;
6913 
6914     IF c_item_conversion%NOTFOUND THEN
6915 
6916       IF l_debug_level  > 0 THEN
6917           oe_debug_pub.add(  'ITEM SPECIFIC CONVERSION RATE NOT FOUND' ) ;
6918       END IF;
6919 
6920       OPEN c_conversion;
6921       FETCH c_conversion
6922        INTO l_conversion_rate;
6923 
6924       IF c_conversion%NOTFOUND THEN
6925 
6926         IF l_debug_level  > 0 THEN
6927             oe_debug_pub.add(  'GENERIC CONVERSION NOT FOUND' ) ;
6928         END IF;
6929         OPEN c_inter_class;
6930         FETCH c_inter_class
6931          INTO l_conversion_rate;
6932 
6933         IF c_inter_class%NOTFOUND THEN
6934            IF l_debug_level  > 0 THEN
6935                oe_debug_pub.add(  'INTER CLASS RETURN RATE NOT FOUND= 1' ) ;
6936            END IF;
6937            l_conversion_rate := 1;
6938 
6939         ELSE
6940            IF l_debug_level  > 0 THEN
6941                oe_debug_pub.add(  'INTER CLASS RETURN RATE = '||L_CONVERSION_RATE ) ;
6942            END IF;
6943 
6944         END IF;
6945         CLOSE c_inter_class;
6946 
6947       ELSIF c_conversion%FOUND then
6948 
6949            IF l_debug_level  > 0 THEN
6950                oe_debug_pub.add(  'RETURN RATE GENERIC= '||L_CONVERSION_RATE ) ;
6951            END IF;
6952 
6953       END IF;
6954       CLOSE c_conversion;
6955 
6956     ELSIF c_item_conversion%FOUND THEN
6957 
6958         IF l_debug_level  > 0 THEN
6959             oe_debug_pub.add(  'ITEM SPECIFIC CONVERSION RATE='||L_CONVERSION_RATE ) ;
6960         END IF;
6961 
6962     END IF;
6963     CLOSE c_item_conversion;
6964 
6965     return l_conversion_rate;
6966 
6967 EXCEPTION
6968 
6969   WHEN ZERO_DIVIDE THEN
6970                      IF l_debug_level  > 0 THEN
6971                          oe_debug_pub.add(  'DIVIDE BY ZERO ERROR IN_UOM_CODE='||IN_UOM_CODE|| ' BASE UOM='||IN_BASE_UOM ) ;
6972                      END IF;
6973 
6974     IF c_item_conversion%ISOPEN then
6975       CLOSE c_item_conversion;
6976     END IF;
6977     IF c_conversion%ISOPEN then
6978       CLOSE c_conversion;
6979     END IF;
6980     IF c_inter_class%ISOPEN then
6981       CLOSE c_inter_class;
6982     END IF;
6983 
6984   WHEN OTHERS THEN
6985 
6986     IF c_item_conversion%ISOPEN then
6987       CLOSE c_item_conversion;
6988     END IF;
6989     IF c_conversion%ISOPEN then
6990       CLOSE c_conversion;
6991     END IF;
6992     IF c_inter_class%ISOPEN then
6993       CLOSE c_inter_class;
6994     END IF;
6995                     IF l_debug_level  > 0 THEN
6996                         oe_debug_pub.add(  'ERROR IN GET_CONVERSION_RATE '|| SQLCODE||SQLERRM ) ;
6997                     END IF;
6998     return 1;
6999 END get_conversion_rate;
7000 
7001 
7002 PROCEDURE Call_mrp_and_inventory(
7003 				 in_org_id in number
7004 				 ,out_on_hand_qty out nocopy number
7005 
7006 				 ,out_reservable_qty out nocopy number
7007 
7008 				 ,out_available_qty out nocopy varchar2
7009 
7010 				 ,out_available_date out nocopy date
7011 
7012 				 ,out_error_message out nocopy varchar2
7013 
7014 				 ,out_qty_uom out nocopy varchar2
7015 
7016 				 ) IS
7017 
7018 l_ship_from_org_id number;
7019 l_out_message varchar2(4000);
7020 l_return_status varchar2(1);
7021 l_msg_count number;
7022 l_msg_data varchar2(4000);
7023 l_item_id number;
7024 l_org_id number;
7025 --
7026 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
7027 --
7028 BEGIN
7029 
7030    l_item_id:=g_panda_rec_table(1).p_inventory_item_id;
7031    l_org_id:= in_org_id;
7032 
7033    if g_upgrade_item_exists ='Y' then
7034       if g_upgrade_item_id is not null then
7035 	 l_item_id:= g_upgrade_item_id;
7036       end if;
7037       if g_upgrade_ship_from_org_id is not null then
7038 	 l_org_id:=g_upgrade_ship_from_org_id;
7039       end if;
7040    end if;
7041 
7042     Query_Qty_Tree( p_org_id=>l_org_id
7043                    ,p_item_id=>l_item_id
7044                    ,p_sch_date=>g_panda_rec_table(1).p_request_date
7045                    ,x_on_hand_qty =>out_on_hand_qty
7046                    ,x_avail_to_reserve =>out_reservable_qty
7047                    );
7048 
7049 
7050     Call_MRP_ATP(
7051           in_global_orgs => 'Y'
7052          ,in_ship_from_org_id =>in_org_id
7053          ,out_available_qty => out_available_qty
7054          ,out_ship_from_org_id =>l_ship_from_org_id
7055          ,out_available_date  =>out_available_date
7056          ,out_qty_uom        =>out_qty_uom
7057          ,x_out_message      =>l_out_message
7058          ,x_return_status    =>l_return_status
7059          ,x_msg_count        =>l_msg_count
7060          ,x_msg_data         =>l_msg_data
7061          ,x_error_message    =>out_error_message
7062                 );
7063 
7064                     IF l_debug_level  > 0 THEN
7065                         oe_debug_pub.add(  'L_RETURN_STATUS='||L_RETURN_STATUS|| ' OUT_AVAILABLE_QTY='||OUT_AVAILABLE_QTY|| ' L_OUT_MESSAGE='||L_OUT_MESSAGE|| ' OUT_ERROR_MESSAGE='||OUT_ERROR_MESSAGE ) ;
7066                     END IF;
7067 
7068 
7069                     IF l_debug_level  > 0 THEN
7070                         oe_debug_pub.add(  'CALL_MRP_AND_INVENTORY'|| ' OUT_AVAILABLE_DATE ='||OUT_AVAILABLE_DATE|| ' OUT_AVAILABLE_QTY ='||OUT_AVAILABLE_QTY);
7071                         oe_debug_pub.add( ' OUT_ON_HAND_QTY ='||OUT_ON_HAND_QTY|| ' OUT_RESERVABLE_QTY ='||OUT_RESERVABLE_QTY|| ' OUT_ERROR_MESSAGE ='||OUT_ERROR_MESSAGE ) ;
7072                     END IF;
7073 
7074 EXCEPTION
7075    WHEN OTHERS THEN
7076                      IF l_debug_level  > 0 THEN
7077                          oe_debug_pub.add(  'INSIDE CALL_MRP_AND_INVENTORY '|| SQLERRM||SQLERRM ) ;
7078                      END IF;
7079 
7080 END call_mrp_and_inventory;
7081 
7082 
7083 
7084 PROCEDURE set_mrp_debug(out_mrp_file out nocopy varchar2) IS
7085 
7086 
7087 l_session_id number;
7088 l_mrp_dir varchar2(200);
7089 
7090 --
7091 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
7092 --
7093 BEGIN
7094 
7095     SELECT mrp_atp_schedule_temp_s.nextval
7096       INTO l_session_id
7097       FROM dual;
7098 
7099     SELECT ltrim(rtrim(substr(value, instr(value,',',-1,1)+1)))
7100       INTO l_mrp_dir
7101       FROM v$parameter
7102      WHERE name='utl_file_dir';
7103 
7104     order_sch_wb.mr_debug := 'Y';
7105     order_sch_wb.debug_session_id := l_session_id;
7106 
7107                     IF l_debug_level  > 0 THEN
7108                         oe_debug_pub.add(  'MSC_ATP_DEBUG DIR='||L_MRP_DIR|| ' SESSION ID ='||L_SESSION_ID ) ;
7109                     END IF;
7110     l_mrp_dir := substr(l_mrp_dir,1,18);
7111     IF l_debug_level  > 0 THEN
7112         oe_debug_pub.add(  'MSC_ATP_DEBUG DIR2='||L_MRP_DIR ) ;
7113     END IF;
7114     out_mrp_file := l_mrp_dir||'/session-'||l_session_id;
7115 
7116 EXCEPTION
7117   WHEN NO_DATA_FOUND THEN
7118     IF l_debug_level  > 0 THEN
7119         oe_debug_pub.add(  'oe_oe_pricing_availability.SET_MRP_DEBUG NO_DATA_FOUND' ) ;
7120     END IF;
7121   WHEN OTHERS THEN
7122                     IF l_debug_level  > 0 THEN
7123                         oe_debug_pub.add(  'WHEN OTHERS oe_oe_pricing_availability.SET_MRP_DEBUG '|| SQLCODE||SQLERRM ) ;
7124                     END IF;
7125 
7126 END set_mrp_debug;
7127 
7128 PROCEDURE CopyINTO_PO_RecStruc
7129    (         p_header_rec in  oe_oe_pricing_availability.PA_Header_Tbl_Type,
7130              p_line_tbl in Oe_Oe_Pricing_Availability.PA_Line_Tbl_Type,
7131              p_Header_Adj_tbl in Oe_Oe_Pricing_Availability.PA_H_Adj_Tbl_Type,
7132              p_Line_Adj_tbl in  Oe_Oe_Pricing_Availability.PA_LAdj_Tbl_Type,
7133              p_Header_price_Att_tbl in Oe_Oe_Pricing_Availability.PA_H_PAtt_Tbl_Type,
7134              p_Header_Adj_Att_tbl in Oe_Oe_Pricing_Availability.PA_H_Adj_Att_Tbl_Type,
7135              p_Header_Adj_Assoc_tbl in  Oe_Oe_Pricing_Availability.PA_H_Adj_AsTbl_Type,
7136              p_Line_price_Att_tbl in  Oe_Oe_Pricing_Availability.PA_Line_PAtt_Tbl_Type,
7137              p_Line_Adj_Att_tbl in  Oe_Oe_Pricing_Availability.PA_LAdj_Att_Tbl_Type,
7138              p_Line_Adj_Assoc_tbl in Oe_Oe_Pricing_Availability.PA_L_Adj_AssTbl_Type,
7139              x_header_rec out NOCOPY /* file.sql.39 change */ OE_order_pub.Header_Rec_Type,
7140              x_line_tbl out NOCOPY /* file.sql.39 change */ OE_Order_Pub.Line_Tbl_Type,
7141              x_Header_Adj_tbl out NOCOPY /* file.sql.39 change */ Oe_Order_Pub.Header_Adj_Tbl_Type,
7142              x_Line_Adj_tbl   out NOCOPY /* file.sql.39 change */ Oe_Order_Pub.Line_Adj_Tbl_Type,
7143              x_Header_price_Att_tbl out NOCOPY /* file.sql.39 change */ Oe_Order_Pub.Header_Price_Att_Tbl_Type,
7144              x_Header_Adj_Att_tbl out NOCOPY /* file.sql.39 change */ Oe_Order_Pub.Header_Adj_Att_Tbl_Type,
7145              x_Header_Adj_Assoc_tbl  out NOCOPY /* file.sql.39 change */ Oe_Order_Pub.Header_Adj_Assoc_Tbl_Type,
7146              x_Line_price_Att_tbl  out NOCOPY /* file.sql.39 change */ Oe_Order_Pub.Line_Price_Att_Tbl_Type,
7147              x_Line_Adj_Att_tbl  out NOCOPY /* file.sql.39 change */ Oe_Order_Pub.Line_Adj_Att_Tbl_Type,
7148              x_Line_Adj_Assoc_tbl out NOCOPY /* file.sql.39 change */ Oe_Order_Pub.Line_Adj_Assoc_Tbl_Type)
7149 IS
7150  j Number;
7151 Begin
7152 
7153 
7154 
7155    IF p_header_rec.EXISTS(1) Then
7156       --copy header info
7157 x_header_rec:=OE_Order_PUB.G_MISS_HEADER_REC;
7158 
7159   IF p_header_rec(1).sold_to_org_id  is not null then
7160     x_header_rec.sold_to_org_id :=p_header_rec(1).sold_to_org_id;
7161   END IF;
7162 
7163   IF p_header_rec(1).conversion_type_code is not null then
7164     x_header_rec.conversion_type_code := p_header_rec(1).conversion_type_code;
7165   END IF;
7166 
7167  IF p_header_rec(1).conversion_rate is not null then
7168   x_header_rec.conversion_rate := p_header_rec(1).conversion_rate;
7169   END IF;
7170 
7171   IF p_header_rec(1).ship_to_org_id is not null then
7172     x_header_rec.ship_to_org_id := p_header_rec(1).ship_to_org_id;
7173   END IF;
7174 
7175   IF p_header_rec(1).invoice_to_org_id is not null then
7176     x_header_rec.invoice_to_org_id := p_header_rec(1).invoice_to_org_id;
7177   END IF;
7178 
7179   IF p_header_rec(1).demand_class_code is not null then
7180     x_header_rec.demand_class_code :=p_header_rec(1).demand_class_code;
7181   END IF;
7182 
7183   x_header_rec.ordered_date := sysdate;
7184 
7185   IF p_header_rec(1).order_type_id is not null then
7186     x_header_rec.order_type_id := p_header_rec(1).order_type_id;
7187   END IF;
7188 
7189   IF  p_header_rec(1).pricing_date is not null then
7190   x_header_rec.pricing_date := p_header_rec(1).pricing_date;
7191   END IF;
7192 
7193   IF p_header_rec(1).ship_from_org_id is not null then
7194     x_header_rec.ship_from_org_id := p_header_rec(1).ship_from_org_id;
7195   END IF;
7196   IF p_header_rec(1).request_date is not null then
7197   x_header_rec.request_date :=p_header_rec(1).request_date;
7198   END IF;
7199 
7200   IF p_header_rec(1).transactional_curr_code is not null then
7201     x_header_rec.transactional_curr_code := p_header_rec(1).transactional_curr_code;
7202   END IF;
7203   IF p_header_rec(1).order_number is not null then
7204     x_header_rec.order_number := p_header_rec(1).order_number;
7205   END IF;
7206 
7207  oe_debug_pub.add('=====After copying Header==================================='||
7208 		  ' Customer id = '||x_header_rec.sold_to_org_id||
7209            ' Currency ='||x_header_rec.transactional_curr_code||
7210            ' order_type_id ='||x_header_rec.order_type_id||
7211            ' agreement_id ='||x_header_rec.agreement_id||
7212            ' price_list_id ='||x_header_rec.price_list_id||
7213            ' ship_to_org_id ='||x_header_rec.ship_to_org_id||
7214            ' invoice_to_org_id ='||x_header_rec.invoice_to_org_id||
7215            ' Conversion_type_code ='||x_header_rec.Conversion_type_code||
7216            ' Conversion_rate ='||x_header_rec.Conversion_rate||
7217            ' Order_Number ='||x_header_rec.order_number||
7218 		  'Header id='||x_header_rec.header_id
7219           );
7220 End if;
7221 
7222 IF p_Header_Adj_tbl.count > 0 Then
7223 	 -- Copy header adjustments
7224    j:=0;
7225    for i in p_Header_Adj_tbl.first..p_Header_Adj_tbl.last
7226 	    Loop
7227       If p_Header_Adj_tbl.Exists(i) Then
7228 	 j:=j+1;
7229 	 x_header_adj_tbl(j):= Oe_Order_Pub.G_Miss_Header_Adj_rec;
7230 
7231 	 if  p_header_adj_tbl(i).list_header_id is not null then
7232 	    x_header_adj_tbl(j).list_header_id:= p_header_adj_tbl(i).list_header_id;
7233 	 end if;
7234 	 if p_header_adj_tbl(i).list_line_id is not null then
7235 	    x_header_adj_tbl(j).list_line_id:=  p_header_adj_tbl(i).list_line_id;
7236 	 end if;
7237 	 if  p_header_adj_tbl(i).list_line_type_code is not null then
7238 	    x_header_adj_tbl(j).list_line_type_code:=  p_header_adj_tbl(i).list_line_type_code;
7239 	 end if;
7240 	 if  p_header_adj_tbl(i).updated_flag is not null then
7241 	    x_header_adj_tbl(j).updated_flag:= p_header_adj_tbl(i).updated_flag;
7242 	 end if;
7243 
7244 	 if  p_header_adj_tbl(i).applied_flag is not null then
7245 	    x_header_adj_tbl(j).applied_flag:= p_header_adj_tbl(i).applied_flag;
7246 	 end if;
7247 
7248 	 if  p_header_adj_tbl(i).operand is not null then
7249 	    x_header_adj_tbl(j).operand   :=  p_header_adj_tbl(i).operand;
7250 	 end if;
7251 
7252 	 if p_header_adj_tbl(i).arithmetic_operator is not null then
7253 	    x_header_adj_tbl(j).arithmetic_operator := p_header_adj_tbl(i).arithmetic_operator;
7254 	 end if;
7255 	 if  p_header_adj_tbl(i).pricing_phase_id is not null then
7256 	    x_header_adj_tbl(j).pricing_phase_id  :=  p_header_adj_tbl(i).pricing_phase_id;
7257 	 end if;
7258 
7259 	 if  p_header_adj_tbl(i).modifier_level_code is not null then
7260 	    x_header_adj_tbl(j).modifier_level_code	 := 	    p_header_adj_tbl(i).modifier_level_code;
7261 	 end if;
7262 	 if p_header_adj_tbl(i).price_break_type_code is not null then
7263 	    x_header_adj_tbl(j).price_break_type_code := 	    p_header_adj_tbl(i).price_break_type_code;
7264 	 end if;
7265 
7266       End If;
7267    End Loop;
7268 End if;
7269 
7270 
7271 
7272 IF p_Header_price_Att_tbl.count > 0 Then
7273       -- Copy header price attribute table
7274  j:=0;
7275  for i in p_header_price_att_tbl.first..p_header_price_att_tbl.last
7276 	  Loop
7277     if p_header_price_att_tbl.Exists(i) then
7278        j:=j+1;
7279 x_header_price_att_tbl(j):=OE_ORDER_PUB.G_MISS_HEADER_PRICE_ATT_REC;
7280 
7281 if p_header_price_att_tbl(i).flex_title is not null then
7282 x_header_price_att_tbl(j).flex_title		 := p_header_price_att_tbl(i).flex_title;
7283 end if;
7284 if p_header_price_att_tbl(i).pricing_context is not null then
7285 x_header_price_att_tbl(j).pricing_context  	 := p_header_price_att_tbl(i).pricing_context;
7286 end if;
7287 if p_header_price_att_tbl(i).pricing_attribute1 is not null then
7288 x_header_price_att_tbl(j).pricing_attribute1     := p_header_price_att_tbl(i).pricing_attribute1;
7289 end if;
7290 if p_header_price_att_tbl(i).pricing_attribute2 is not null then
7291 x_header_price_att_tbl(j).pricing_attribute2     := p_header_price_att_tbl(i).pricing_attribute2;
7292 end if;
7293 if p_header_price_att_tbl(i).pricing_attribute3 is not null then
7294 x_header_price_att_tbl(j).pricing_attribute3     := p_header_price_att_tbl(i).pricing_attribute3;
7295 end if;
7296 
7297 end if;
7298 End Loop;
7299 End if;
7300 
7301 
7302 IF p_Header_Adj_Att_tbl.count > 0 Then
7303           -- Copy header adjustments attribute
7304 j:=0;
7305 For i in p_Header_Adj_Att_tbl.first..p_Header_Adj_Att_tbl.last
7306 	 Loop
7307 If p_Header_Adj_Att_tbl.Exists(i) Then
7308    j:=j+1;
7309 x_Header_Adj_Att_tbl(j):=OE_ORDER_PUB.G_MISS_HEADER_ADJ_ATT_REC;
7310 
7311 End if;
7312 End Loop;
7313 End if;
7314 
7315 
7316 IF p_Header_Adj_Assoc_tbl.count > 0 Then
7317       -- Copy header adjustments associations
7318 j:=0;
7319 For i in p_Header_Adj_Assoc_tbl.first..p_Header_Adj_Assoc_tbl.last
7320 	 Loop
7321    If p_Header_Adj_Assoc_tbl.Exists(i) Then
7322       j:=j+1;
7323 x_Header_Adj_Assoc_tbl(j):=OE_ORDER_PUB.G_MISS_HEADER_ADJ_ASSOC_REC;
7324 
7325 End if;
7326 End loop;
7327 End if;
7328 
7329 
7330 IF p_line_Tbl.count > 0 Then
7331    -- Copy line infor
7332 j:=0;
7333 For i in p_line_Tbl.first..p_line_Tbl.last
7334 	 Loop
7335    j:=j+1;
7336    if p_line_Tbl.Exists(i) Then
7337 x_line_Tbl(j):=OE_ORDER_PUB.G_MISS_LINE_REC;
7338 
7339 if  p_line_Tbl(i).agreement_id is not null then
7340 x_line_Tbl(j).agreement_id                    		   :=  p_line_Tbl(i).agreement_id;
7341 end if;
7342 
7343 if  p_line_Tbl(i).created_by is not null then
7344 x_line_Tbl(j).created_by                      		   :=  p_line_Tbl(i).created_by;
7345 end if;
7346 if p_line_Tbl(i).creation_date is not null then
7347 x_line_Tbl(j).creation_date                   		   :=  p_line_Tbl(i).creation_date;
7348 end if;
7349 
7350 if p_line_Tbl(i).deliver_to_org_id is not null then
7351 x_line_Tbl(j).deliver_to_org_id               		   :=  p_line_Tbl(i).deliver_to_org_id;
7352 end if;
7353 
7354 if  p_line_Tbl(i).demand_class_code is not null then
7355 x_line_Tbl(j).demand_class_code               		   :=  p_line_Tbl(i).demand_class_code;
7356 end if;
7357 
7358 if  p_line_Tbl(i).inventory_item_id is not null then
7359 x_line_Tbl(j).inventory_item_id             		   :=  p_line_Tbl(i).inventory_item_id;
7360 end if;
7361 
7362 if  p_line_Tbl(i).invoice_to_org_id is not null then
7363 x_line_Tbl(j).invoice_to_org_id             		   :=  p_line_Tbl(i).invoice_to_org_id;
7364 end if;
7365 
7366 if  p_line_Tbl(i).ordered_item is not null then
7367 x_line_Tbl(j).ordered_item                  		   :=  p_line_Tbl(i).ordered_item;
7368 end if;
7369 
7370 if  p_line_Tbl(i).item_type_code is not null then
7371 x_line_Tbl(j).item_type_code                 		   :=  p_line_Tbl(i).item_type_code;
7372 end if;
7373 
7374 if  p_line_Tbl(i).line_type_id is not null then
7375 x_line_Tbl(j).line_type_id                   		   :=  p_line_Tbl(i).line_type_id;
7376 end if;
7377 
7378 if  p_line_Tbl(i).ordered_quantity is not null then
7379 x_line_Tbl(j).ordered_quantity               		   :=  p_line_Tbl(i).ordered_quantity;
7380 end if;
7381 
7382 if  p_line_Tbl(i).order_quantity_uom is not null then
7383 x_line_Tbl(j).order_quantity_uom             		   :=  p_line_Tbl(i).order_quantity_uom;
7384 end if;
7385 
7386 if  p_line_Tbl(i).price_list_id is not null then
7387 x_line_Tbl(j).price_list_id                  		   :=  p_line_Tbl(i).price_list_id;
7388 end if;
7389 
7390 if  p_line_Tbl(i).pricing_date is not null then
7391 x_line_Tbl(j).pricing_date                     		   :=  p_line_Tbl(i).pricing_date;
7392 end if;
7393 
7394 if  p_line_Tbl(i).request_date is not null then
7395 x_line_Tbl(j).request_date                     		   :=  p_line_Tbl(i).request_date;
7396 end if;
7397 
7398 if  p_line_Tbl(i).ship_from_org_id is not null then
7399 x_line_Tbl(j).ship_from_org_id              		   :=  p_line_Tbl(i).ship_from_org_id;
7400 end if;
7401 
7402 if  p_line_Tbl(i).ship_to_org_id is not null then
7403 x_line_Tbl(j).ship_to_org_id                		   :=  p_line_Tbl(i).ship_to_org_id;
7404 end if;
7405 
7406 if  p_line_Tbl(i).ordered_item_id is not null then
7407 x_line_Tbl(j).ordered_item_id                   	   :=  p_line_Tbl(i).ordered_item_id;
7408 end if;
7409 if p_line_Tbl(i).item_identifier_type is not null then
7410 x_line_Tbl(j).item_identifier_type         		   :=  p_line_Tbl(i).item_identifier_type;
7411 end if;
7412 
7413 if p_line_Tbl(i).Original_Inventory_Item_Id is not null then
7414 x_line_Tbl(j).Original_Inventory_Item_Id   		   :=  p_line_Tbl(i).Original_Inventory_Item_Id;
7415 end if;
7416 if  p_line_Tbl(i).Original_item_identifier_Type is not null then
7417 x_line_Tbl(j).Original_item_identifier_Type		   :=  p_line_Tbl(i).Original_item_identifier_Type;
7418 end if;
7419 if  p_line_Tbl(i).Original_ordered_item_id is not null then
7420 x_line_Tbl(j).Original_ordered_item_id     		   :=  p_line_Tbl(i).Original_ordered_item_id;
7421 end if;
7422 if  p_line_Tbl(i).Original_ordered_item is not null then
7423 x_line_Tbl(j).Original_ordered_item       		   :=  p_line_Tbl(i).Original_ordered_item;
7424 end if;
7425 if  p_line_Tbl(i).Item_substitution_type_code is not null then
7426 x_line_Tbl(j).Item_substitution_type_code  		   :=  p_line_Tbl(i).Item_substitution_type_code;
7427 end if;
7428 
7429 if  p_line_Tbl(i).item_relationship_type is not null then
7430 x_line_Tbl(j).item_relationship_type       		   :=  p_line_Tbl(i).item_relationship_type;
7431 end if;
7432 
7433 End if;
7434 End Loop;
7435 End if;
7436 oe_debug_pub.add('line_table count in copy'||x_line_tbl.count);
7437 oe_Debug_pub.add('Adjsutment table count'||p_line_adj_tbl.count);
7438 IF p_line_Adj_tbl.count > 0 Then
7439    -- Copy line adjustment table infor
7440 j:=0;
7441 For i in p_line_Adj_tbl.first..p_line_Adj_tbl.last
7442 	 Loop
7443    If p_line_Adj_tbl.Exists(i) then
7444       j:=j+1;
7445 x_line_Adj_tbl(j):=OE_ORDER_PUB.G_MISS_LINE_ADJ_REC;
7446 
7447 if  p_line_Adj_tbl(i).line_index is not null then
7448 
7449 --commented for bug 3566972
7450 /*
7451 x_line_Adj_tbl(j).line_index :=1;
7452       --p_line_Adj_tbl(i).line_index;*/
7453 
7454 x_line_Adj_tbl(j).line_index :=p_line_Adj_tbl(i).line_index;  -- added for bug 3566972
7455 
7456 end if;
7457 
7458 if  p_line_Adj_tbl(i).list_header_id is not null then
7459 x_line_Adj_tbl(j).list_header_id :=   p_line_Adj_tbl(i).list_header_id;
7460 end if;
7461 if  p_line_Adj_tbl(i).list_line_id is not null then
7462 x_line_Adj_tbl(j).list_line_id :=p_line_Adj_tbl(i).list_line_id;
7463 end if;
7464 if  p_line_Adj_tbl(i).list_line_type_code is not null then
7465 x_line_Adj_tbl(j).list_line_type_code :=p_line_Adj_tbl(i).list_line_type_code;
7466 end if;
7467 
7468 if  p_line_Adj_tbl(i).updated_flag is not null then
7469 x_line_Adj_tbl(j).updated_flag :=p_line_Adj_tbl(i).updated_flag;
7470 end if;
7471 
7472 if p_line_Adj_tbl(i).applied_flag is not null then
7473 x_line_Adj_tbl(j).applied_flag:= p_line_Adj_tbl(i).applied_flag;
7474 end if;
7475 
7476 if  p_line_Adj_tbl(i).operand is not null then
7477 x_line_Adj_tbl(j).operand :=p_line_Adj_tbl(i).operand;
7478 end if;
7479 
7480 if  p_line_Adj_tbl(i).arithmetic_operator is not null then
7481 x_line_Adj_tbl(j).arithmetic_operator := p_line_Adj_tbl(i).arithmetic_operator;
7482 end if;
7483 
7484 if p_line_Adj_tbl(i).pricing_phase_id is not null then
7485 x_line_Adj_tbl(j).pricing_phase_id		      :=   p_line_Adj_tbl(i).pricing_phase_id;
7486 end if;
7487 
7488 if p_line_Adj_tbl(i).modifier_level_code is not null then
7489 x_line_Adj_tbl(j).modifier_level_code		      :=   p_line_Adj_tbl(i).modifier_level_code;
7490 end if;
7491 if p_line_Adj_tbl(i).price_break_type_code is not null then
7492 x_line_Adj_tbl(j).price_break_type_code	   	      :=   p_line_Adj_tbl(i).price_break_type_code;
7493 end if;
7494 
7495 oe_Debug_pub.add('line index'||x_line_Adj_tbl(j).line_index||'list header id'||x_line_Adj_tbl(j).list_header_id
7496 		 ||'list line id'||x_line_Adj_tbl(j).list_line_id ||'list line type code'||x_line_Adj_tbl(j).list_line_type_code
7497 		 ||'applied flag'||x_line_Adj_tbl(j).applied_flag||'updated_flag'||x_line_Adj_tbl(j).updated_flag
7498 		 );
7499 
7500 End if;
7501 End Loop;
7502 End if;
7503 
7504 
7505 IF p_line_price_Att_tbl.count > 0 Then
7506        -- Copy line pricing attribute table infor
7507 j:=0;
7508 For i in p_line_price_Att_tbl.first..p_line_price_Att_tbl.last
7509 	 Loop
7510    if p_line_price_Att_tbl.Exists(i) then
7511       j:=j+1;
7512 x_line_price_Att_tbl(j):= OE_ORDER_PUB.G_MISS_Line_Price_Att_Rec;
7513 
7514 if p_line_price_Att_tbl(i).line_index is not null then
7515 x_line_price_Att_tbl(j).line_index	                   :=  p_line_price_Att_tbl(i).line_index;
7516 end if;
7517 
7518 
7519 if  p_line_price_Att_tbl(i).flex_title is not null then
7520 x_line_price_Att_tbl(j).flex_title			  :=  p_line_price_Att_tbl(i).flex_title;
7521 end if;
7522 if p_line_price_Att_tbl(i).pricing_context is not null then
7523 x_line_price_Att_tbl(j).pricing_context			  :=  p_line_price_Att_tbl(i).pricing_context;
7524 end if;
7525 if p_line_price_Att_tbl(i).pricing_attribute1 is not null then
7526 x_line_price_Att_tbl(j).pricing_attribute1		  :=  p_line_price_Att_tbl(i).pricing_attribute1;
7527 end if;
7528 if  p_line_price_Att_tbl(i).pricing_attribute2 is not null then
7529 x_line_price_Att_tbl(j).pricing_attribute2		  :=  p_line_price_Att_tbl(i).pricing_attribute2;
7530 end if;
7531 if  p_line_price_Att_tbl(i).pricing_attribute3 is not null then
7532 x_line_price_Att_tbl(j).pricing_attribute3		  :=  p_line_price_Att_tbl(i).pricing_attribute3;
7533 end if;
7534 
7535 
7536 End if;
7537 End Loop;
7538 End if;
7539 
7540 
7541 IF p_line_Adj_Att_tbl.count > 0 Then
7542        -- Copy line adjustment attribute table
7543 j:=0;
7544 For i in p_line_Adj_Att_tbl.first..p_line_Adj_Att_tbl.last
7545 	 Loop
7546    if p_line_Adj_Att_tbl.Exists(i) Then
7547       j:=j+1;
7548 x_line_Adj_att_tbl(j):= OE_ORDER_PUB.G_MISS_Line_Adj_Att_Rec;
7549 if p_line_Adj_att_tbl(i).Adj_index is not null then
7550 x_line_Adj_att_tbl(j).Adj_index			  :=  p_line_Adj_att_tbl(i).Adj_index;
7551 end if;
7552 if  p_line_Adj_att_tbl(i).flex_title is not null then
7553 x_line_Adj_att_tbl(j).flex_title             	  :=  p_line_Adj_att_tbl(i).flex_title;
7554 end if;
7555 if p_line_Adj_att_tbl(i).pricing_context is not null then
7556 x_line_Adj_att_tbl(j).pricing_context        	  :=  p_line_Adj_att_tbl(i).pricing_context;
7557 end if;
7558 if  p_line_Adj_att_tbl(i).pricing_attribute is not null then
7559 x_line_Adj_att_tbl(j).pricing_attribute      	  :=  p_line_Adj_att_tbl(i).pricing_attribute;
7560 end if;
7561 
7562 if  p_line_Adj_att_tbl(i).pricing_attr_value_from is not null then
7563 x_line_Adj_att_tbl(j).pricing_attr_value_from 	  :=  p_line_Adj_att_tbl(i).pricing_attr_value_from;
7564 end if;
7565 if  p_line_Adj_att_tbl(i).pricing_attr_value_to is not null then
7566 x_line_Adj_att_tbl(j).pricing_attr_value_to  	  :=  p_line_Adj_att_tbl(i).pricing_attr_value_to;
7567 end if;
7568 
7569 End if;
7570 End Loop;
7571 End if;
7572 
7573 IF p_line_Adj_Assoc_tbl.count > 0 Then
7574    -- Copy line adjustment association table infor
7575 j:=0;
7576 For i in p_line_Adj_Assoc_tbl.first..p_line_Adj_Assoc_tbl.last
7577 	 Loop
7578    if p_line_Adj_Assoc_tbl.Exists(i) Then
7579       j:=j+1;
7580 
7581 if p_line_Adj_Assoc_tbl(i).Line_index is not null then
7582 x_line_Adj_Assoc_tbl(j).Line_index	       :=   p_line_Adj_Assoc_tbl(i).Line_index;
7583 end if;
7584 
7585 if  p_line_Adj_Assoc_tbl(i).Adj_index is not null then
7586 x_line_Adj_Assoc_tbl(j).Adj_index	       :=   p_line_Adj_Assoc_tbl(i).Adj_index;
7587 end if;
7588 
7589 --x_line_Adj_Assoc_tbl(j).rltd_Price_Adj_Id      :=   p_line_Adj_Assoc_tbl(i).rltd_Price_Adj_Id;
7590 if  p_line_Adj_Assoc_tbl(i).Rltd_Adj_Index is not null then
7591 x_line_Adj_Assoc_tbl(j).Rltd_Adj_Index         :=   p_line_Adj_Assoc_tbl(i).Rltd_Adj_Index;
7592 end if;
7593 
7594 End if;
7595 End Loop;
7596 End if;
7597 
7598 
7599 End CopyINTO_PO_RecStruc;
7600 
7601 
7602 
7603 PROCEDURE Create_Order(
7604              in_order in varchar2,
7605              in_header_rec oe_oe_pricing_availability.PA_Header_Tbl_Type,
7606              in_line_tbl Oe_Oe_Pricing_Availability.PA_Line_Tbl_Type,
7607              in_Header_Adj_tbl Oe_Oe_Pricing_Availability.PA_H_Adj_Tbl_Type,
7608              in_Line_Adj_tbl   Oe_Oe_Pricing_Availability.PA_LAdj_Tbl_Type,
7609              in_Header_price_Att_tbl Oe_Oe_Pricing_Availability.PA_H_PAtt_Tbl_Type,
7610              in_Header_Adj_Att_tbl Oe_Oe_Pricing_Availability.PA_H_Adj_Att_Tbl_Type,
7611              in_Header_Adj_Assoc_tbl  Oe_Oe_Pricing_Availability.PA_H_Adj_AsTbl_Type,
7612              in_Line_price_Att_tbl  Oe_Oe_Pricing_Availability.PA_Line_PAtt_Tbl_Type,
7613              in_Line_Adj_Att_tbl  Oe_Oe_Pricing_Availability.PA_LAdj_Att_Tbl_Type,
7614              in_Line_Adj_Assoc_tbl Oe_Oe_Pricing_Availability.PA_L_Adj_AssTbl_Type,
7615              out_order_number out NOCOPY varchar2,
7616              out_header_id out NOCOPY number,
7617              out_order_total out NOCOPY number,
7618              out_order_amount out nocopy number,
7619              out_order_charges out nocopy number,
7620              out_order_discount out nocopy number,
7621              out_order_tax     out nocopy number,
7622              out_item        out nocopy varchar2,
7623              out_currency out nocopy varchar2,
7624              x_msg_count OUT NOCOPY NUMBER,
7625              x_msg_data OUT NOCOPY VARCHAR2,
7626              x_return_status OUT NOCOPY VARCHAR2
7627                       ) IS
7628 
7629 l_Header_price_Att_tbl	      OE_Order_PUB.Header_Price_Att_Tbl_Type;
7630 l_Header_Adj_Att_tbl	      OE_Order_PUB.Header_Adj_Att_Tbl_Type;
7631 l_Header_Adj_Assoc_tbl	      OE_Order_PUB.Header_Adj_Assoc_Tbl_Type;
7632 l_Line_price_Att_tbl	      OE_Order_PUB.Line_Price_Att_Tbl_Type;
7633 l_Line_Adj_Att_tbl	      OE_Order_PUB.Line_Adj_Att_Tbl_Type;
7634 l_Line_Adj_Assoc_tbl	      OE_Order_PUB.Line_Adj_Assoc_Tbl_Type;
7635 l_line_rec                    OE_Order_PUB.Line_Rec_Type;
7636 l_line_adj_rec                OE_Order_PUB.Line_Adj_Rec_Type;
7637 l_line_tbl                    OE_Order_PUB.Line_Tbl_Type;
7638 l_line_adj_tbl                OE_Order_PUB.Line_Adj_Tbl_Type;
7639 l_Header_Adj_tbl              OE_Order_PUB.Header_Adj_Tbl_Type;
7640 l_x_header_rec                OE_Order_PUB.Header_Rec_Type;
7641 l_x_Header_Adj_tbl            OE_Order_PUB.Header_Adj_Tbl_Type;
7642 l_x_Header_Scredit_tbl        OE_Order_PUB.Header_Scredit_Tbl_Type;
7643 l_x_line_tbl                  OE_Order_PUB.Line_Tbl_Type;
7644 l_x_Line_Adj_tbl              OE_Order_PUB.Line_Adj_Tbl_Type;
7645 l_x_Line_Scredit_tbl          OE_Order_PUB.Line_Scredit_Tbl_Type;
7646 l_action_request_tbl          OE_Order_PUB.request_tbl_type;
7647 l_x_action_request_tbl        OE_Order_PUB.request_tbl_type;
7648 l_x_lot_serial_tbl	      OE_Order_PUB.lot_serial_tbl_type;
7649 l_file_val                    Varchar2(30);
7650 x_msg_index                   number;
7651 v                             Varchar2(30);
7652 l_date                        date;
7653 l_booked_flag                 varchar2(1);
7654 l_shipping_interfaced_flag    varchar2(1);
7655 l_header_rec OE_ORDER_PUB.HEADER_REC_TYPE;
7656 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
7657 
7658 l_subtotal number;
7659 l_discount number;
7660 l_charges  number;
7661 l_tax      number;
7662 l_transaction_phase_code varchar2(30);
7663 l_x_Header_Payment_tbl OE_Order_PUB.Header_Payment_Tbl_Type;
7664 l_x_Line_Payment_tbl  OE_Order_PUB.Line_Payment_Tbl_Type;
7665 p_old_line_rec OE_ORDER_PUB.Line_Rec_Type;
7666 p_x_line_rec OE_ORDER_PUB.Line_Rec_Type;
7667 BEGIN
7668 
7669   IF l_debug_level  > 0 THEN
7670     oe_debug_pub.add('==========================================='||
7671            ' Enter create_order database '||
7672            ' in_order = '||in_order||
7673            ' Customer id = '||in_header_rec(1).sold_to_org_id||
7674            ' Currency ='||in_header_rec(1).transactional_curr_code||
7675            ' order_type_id ='||in_header_rec(1).order_type_id||
7676            ' agreement_id ='||in_header_rec(1).agreement_id||
7677            ' price_list_id ='||in_header_rec(1).price_list_id||
7678            ' ship_to_org_id ='||in_header_rec(1).ship_to_org_id||
7679            ' invoice_to_org_id ='||in_header_rec(1).invoice_to_org_id||
7680            ' Conversion_type_code ='||in_header_rec(1).Conversion_type_code||
7681            ' Conversion_rate ='||in_header_rec(1).Conversion_rate||
7682            ' Order_Number ='||in_header_rec(1).order_number||
7683            ' line_tbl_count='||in_line_tbl.COUNT||
7684 		     'Line_Adj_tbl_count'||in_line_Adj_Tbl.count ||
7685 		     'Line_Adj_Attr_tbl'||in_line_adj_att_tbl.count
7686           );
7687   END IF;
7688 
7689   IF in_order = 'Y' then
7690     l_transaction_phase_code := 'F';
7691   ELSE
7692     l_transaction_phase_code := 'N';
7693   END IF;
7694 
7695 
7696 -- Copy from the P_A record structure to Process Order structure is done....
7697 
7698 
7699  CopyINTO_PO_RecStruc
7700    (         p_header_rec=>in_header_rec,
7701              p_line_tbl=>in_line_tbl,
7702              p_Header_Adj_tbl=>in_header_adj_tbl,
7703              p_Line_Adj_tbl=> in_line_adj_tbl,
7704              p_Header_price_Att_tbl=> in_header_price_att_tbl,
7705              p_Header_Adj_Att_tbl => in_header_adj_att_tbl,
7706              p_Header_Adj_Assoc_tbl => in_header_adj_assoc_tbl,
7707              p_Line_price_Att_tbl => in_line_price_att_tbl,
7708              p_Line_Adj_Att_tbl => in_line_adj_att_tbl,
7709              p_Line_Adj_Assoc_tbl => in_line_adj_assoc_tbl,
7710              x_header_rec =>l_header_rec,
7711              x_line_tbl => l_line_tbl,
7712              x_Header_Adj_tbl=>l_Header_adj_tbl,
7713              x_Line_Adj_tbl => l_line_adj_tbl,
7714              x_Header_price_Att_tbl=> l_header_price_att_tbl,
7715              x_Header_Adj_Att_tbl => l_header_adj_att_tbl,
7716              x_Header_Adj_Assoc_tbl => l_header_adj_assoc_tbl,
7717              x_Line_price_Att_tbl => l_line_price_att_tbl,
7718              x_Line_Adj_Att_tbl => l_line_adj_att_tbl,
7719              x_Line_Adj_Assoc_tbl => l_line_adj_assoc_tbl);
7720 
7721 
7722   IF l_debug_level  > 0 THEN
7723     IF l_line_tbl.COUNT > 0 then
7724       FOR i in l_line_tbl.FIRST..l_line_tbl.LAST
7725       LOOP
7726         oe_debug_pub.add('=========================================='||
7727               ' Line '||i||
7728               ' item_id='||l_line_Tbl(i).inventory_item_id||
7729               ' line_type_id='||l_line_Tbl(i).line_type_id||
7730               ' agreement_id='||l_line_Tbl(i).agreement_id||
7731               ' ship_to_org_id='||l_line_Tbl(i).ship_to_org_id||
7732               ' invoice_to_org_id='||l_line_Tbl(i).invoice_to_org_id||
7733               ' item_type_code='||l_line_Tbl(i).item_type_code||
7734               ' ordered_quantity='||l_line_Tbl(i).ordered_quantity||
7735               ' quantity_uom='||l_line_Tbl(i).order_quantity_uom||
7736               ' ship_from_org_id='||l_line_Tbl(i).ship_from_org_id||
7737               ' ordered_item_id='||l_line_Tbl(i).ordered_item_id||
7738               ' item_id_type='||l_line_Tbl(i).item_identifier_type||
7739               ' orig_inv_id='||l_line_Tbl(i).original_inventory_item_id||
7740               ' orig_id_type='||l_line_Tbl(i).original_item_identifier_type||
7741               ' orig_ordered_id='||l_line_Tbl(i).original_ordered_item_id||
7742               ' Price_list='||l_line_Tbl(i).price_list_id||
7743               ' line_category_code='||l_line_Tbl(i).line_category_code||
7744               ' transaction_phase_code='||l_transaction_phase_code
7745                    );
7746       END LOOP;
7747     END IF;
7748   END IF;
7749  -- l_header_rec := in_header_rec; -- should copy header record values
7750 
7751   l_header_rec.operation := OE_Globals.G_OPR_CREATE;
7752   --l_header_rec.order_number := null;
7753   l_header_rec.order_source_id := g_order_source_id;
7754   l_header_rec.transaction_phase_code := l_transaction_phase_code;
7755 
7756 
7757  -- l_line_tbl := in_line_tbl; -- should copy line table
7758   oe_debug_pub.add(' in create order line table count'||l_line_tbl.count);
7759   FOR i in l_line_tbl.FIRST..l_line_tbl.LAST
7760   LOOP
7761     l_line_tbl(i).operation := OE_Globals.G_OPR_CREATE;
7762     l_line_tbl(i).calculate_price_flag := 'Y';
7763     l_line_tbl(i).order_source_id := g_order_source_id;
7764     l_line_tbl(i).transaction_phase_code := l_transaction_phase_code;
7765   END LOOP;
7766 
7767 --IF in_line_price_att_tbl.COUNT > 0 then
7768 IF l_line_price_att_tbl.COUNT > 0 then
7769    -- l_Line_price_Att_tbl	:= in_line_price_att_tbl; -- copy line pricing attributes
7770     FOR i in l_line_price_att_tbl.FIRST..l_line_price_att_tbl.LAST
7771     LOOP
7772       l_line_price_att_tbl(i).operation := OE_Globals.G_OPR_CREATE;
7773     END LOOP;
7774 
7775     IF l_debug_level  > 0 THEN
7776       IF l_line_price_att_tbl.COUNT > 0 then
7777       FOR i in l_line_price_att_tbl.first..l_line_price_att_tbl.last
7778       LOOP
7779         oe_debug_pub.add('BEFORE Process Order line_price_att_tbl rec='||i||
7780         ' line_index='||l_line_price_att_tbl(i).line_index||
7781         ' flex_title='||l_line_price_att_tbl(i).flex_title||
7782         ' pricing_context='||l_line_price_att_tbl(i).pricing_context||
7783         ' attr1='||l_line_price_att_tbl(i).pricing_attribute1||
7784         ' attr2='||l_line_price_att_tbl(i).pricing_attribute2||
7785         ' attr3='||l_line_price_att_tbl(i).pricing_attribute3
7786                       );
7787       END LOOP;
7788       END IF;
7789     END IF; -- if debug level
7790   END IF; -- if price_atts are passed
7791 
7792 
7793 
7794 
7795 --  IF in_header_price_att_tbl.COUNT > 0 then
7796      IF l_header_price_att_tbl.COUNT > 0 then
7797   --  l_Header_price_Att_tbl	:= in_header_price_att_tbl; -- copy header pricing attributes
7798     FOR i in l_header_price_att_tbl.FIRST..l_header_price_att_tbl.LAST
7799     LOOP
7800       l_header_price_att_tbl(i).operation := OE_Globals.G_OPR_CREATE;
7801     END LOOP;
7802 
7803     IF l_debug_level  > 0 THEN
7804       IF l_header_price_att_tbl.COUNT > 0 then
7805       FOR i in l_header_price_att_tbl.first..l_header_price_att_tbl.last
7806       LOOP
7807         oe_debug_pub.add('BEFORE Process Order Hdr_price_att_tbl rec='||i||
7808         ' flex_title='||l_header_price_att_tbl(i).flex_title||
7809         ' pricing_context='||l_header_price_att_tbl(i).pricing_context||
7810         ' attr1='||l_header_price_att_tbl(i).pricing_attribute1||
7811         ' attr2='||l_header_price_att_tbl(i).pricing_attribute2||
7812         ' attr3='||l_header_price_att_tbl(i).pricing_attribute3
7813                       );
7814       END LOOP;
7815       END IF;
7816     END IF; -- if debug level
7817   END IF; -- if header price_atts are passed
7818 
7819 oe_Debug_pub.add('Line adjustment count'||l_line_Adj_tbl.count);
7820 --IF in_line_adj_tbl.COUNT > 0 then
7821    IF l_line_adj_tbl.COUNT > 0 then
7822   --  l_Line_adj_tbl:= in_line_adj_tbl;  -- copy line adj table
7823     FOR i in l_line_adj_tbl.FIRST..l_line_adj_tbl.LAST
7824     LOOP
7825       l_line_adj_tbl(i).operation := OE_Globals.G_OPR_CREATE;
7826     END LOOP;
7827 
7828     IF l_debug_level  > 0 THEN
7829        IF l_line_adj_tbl.COUNT > 0 then
7830 	  FOR i in l_line_adj_tbl.first..l_line_adj_tbl.last
7831 		   LOOP
7832 	     oe_debug_pub.add('BEFORE Process Order line_adj_tbl rec='||i||
7833 			      ' line_index='||l_line_adj_tbl(i).line_index||
7834 			      ' List_line_id='||l_line_adj_tbl(i).List_line_id||
7835 			      ' List Header id='||l_line_adj_tbl(i).list_header_id ||
7836 			      ' Pricing Phase id='||l_line_adj_tbl(i).pricing_phase_id ||
7837 			      ' Modifier Level code='||l_line_adj_tbl(i).Modifier_level_code ||
7838 			      ' Operand='||l_line_adj_tbl(i).operand ||
7839 			      ' List line type code='||l_line_adj_tbl(i).list_line_type_code ||
7840 			      'Updated Flag=' ||l_line_adj_tbl(i).updated_flag ||
7841 			      'Applied Flag=' ||l_line_adj_tbl(i).applied_flag ||
7842 			      'Arithmetic Operator ='||l_line_adj_tbl(i).arithmetic_operator ||
7843 			      'Price Break Type code =' ||l_line_adj_tbl(i).price_break_type_code
7844 			      );
7845 	  END LOOP;
7846        END IF;
7847     END IF; -- if debug level
7848  END IF; -- if line adj being passed.
7849 
7850 
7851  --IF in_header_adj_tbl.COUNT > 0 then
7852 IF l_header_adj_tbl.COUNT > 0 then
7853   --  l_header_adj_tbl:= in_header_adj_tbl;  -- copy header adjustments
7854     FOR i in l_header_adj_tbl.FIRST..l_header_adj_tbl.LAST
7855 	     LOOP
7856        l_header_adj_tbl(i).operation := OE_Globals.G_OPR_CREATE;
7857     END LOOP;
7858 
7859     IF l_debug_level  > 0 THEN
7860        IF l_header_adj_tbl.COUNT > 0 then
7861 	  FOR i in l_header_adj_tbl.first..l_header_adj_tbl.last
7862 		   LOOP
7863 	     oe_debug_pub.add('BEFORE Process Order header_adj_tbl rec='||i||
7864 			      ' List_line_id='||l_header_adj_tbl(i).List_line_id||
7865 			      ' List Header id='||l_header_adj_tbl(i).list_header_id ||
7866 			      ' Pricing Phase id='||l_header_adj_tbl(i).pricing_phase_id ||
7867 			      ' Modifier Level code='||l_header_adj_tbl(i).Modifier_level_code ||
7868 			      ' Operand='||l_header_adj_tbl(i).operand ||
7869 			      ' List line type code='||l_header_adj_tbl(i).list_line_type_code ||
7870 			      'Updated Flag=' ||l_header_adj_tbl(i).updated_flag ||
7871 			      'Applied Flag=' ||l_header_adj_tbl(i).applied_flag ||
7872 			      'Arithmetic Operator ='||l_header_adj_tbl(i).arithmetic_operator ||
7873 			      'Price Break Type code =' ||l_header_adj_tbl(i).price_break_type_code
7874 			      );
7875 	  END LOOP;
7876        END IF;
7877     END IF; -- if debug level
7878  END IF; -- if header adj being passed.
7879 
7880 --IF in_line_adj_att_tbl.COUNT > 0 then
7881 IF l_line_adj_att_tbl.COUNT > 0 then
7882   -- l_Line_adj_att_tbl:= in_line_adj_att_tbl;  -- copy line_adjustemnts table
7883    FOR i in l_line_adj_att_tbl.FIRST..l_line_adj_att_tbl.LAST
7884 	    LOOP
7885       l_line_adj_att_tbl(i).operation := OE_Globals.G_OPR_CREATE;
7886    END LOOP;
7887 
7888     IF l_debug_level  > 0 THEN
7889        IF l_line_adj_att_tbl.COUNT > 0 then
7890 	  FOR i in l_line_adj_att_tbl.first..l_line_adj_att_tbl.last
7891 		   LOOP
7892 	     oe_debug_pub.add('BEFORE Process Order line_adj_att_tbl rec='||i||
7893 			      ' line_index='||l_line_adj_att_tbl(i).adj_index||
7894 			      ' pricing context='||l_line_adj_att_tbl(i).pricing_context||
7895 			      'pricing attribute='||l_line_adj_att_tbl(i).pricing_attribute||
7896 			      'pricing attribute value from='||l_line_adj_att_tbl(i).pricing_attr_value_from||
7897 			      'pricing attribute value to=' ||l_line_adj_att_tbl(i).pricing_attr_value_to
7898 			      );
7899 	  END LOOP;
7900        END IF;
7901     END IF; -- if debug level
7902  END IF; -- if line adj attr being passed.
7903 
7904 --IF in_line_adj_assoc_tbl.COUNT > 0 then
7905 IF l_line_adj_assoc_tbl.COUNT > 0 then
7906    -- l_Line_adj_assoc_tbl:= in_line_adj_assoc_tbl;
7907     FOR i in l_line_adj_assoc_tbl.FIRST..l_line_adj_assoc_tbl.LAST
7908     LOOP
7909       l_line_adj_assoc_tbl(i).operation := OE_Globals.G_OPR_CREATE;
7910     END LOOP;
7911 
7912     IF l_debug_level  > 0 THEN
7913        IF l_line_adj_assoc_tbl.COUNT > 0 then
7914 	  FOR i in l_line_adj_assoc_tbl.first..l_line_adj_assoc_tbl.last
7915 		   LOOP
7916 	     oe_debug_pub.add('BEFORE Process Order line_adj_att_tbl rec='||i||
7917 			      ' line_index='||l_line_adj_assoc_tbl(i).line_index||
7918 			      ' Adjustment index='||l_line_adj_assoc_tbl(i).adj_index||
7919 			      'Related adjustment index'||l_line_adj_assoc_tbl(i).rltd_adj_index
7920 			      );
7921 	  END LOOP;
7922        END IF;
7923     END IF; -- if debug level
7924  END IF; -- if line adj assoc being passed.
7925 
7926 
7927 --IF in_header_adj_att_tbl.COUNT > 0 then
7928 IF l_header_adj_att_tbl.COUNT > 0 then
7929   -- l_header_adj_att_tbl:= in_header_adj_att_tbl;
7930    FOR i in l_header_adj_att_tbl.FIRST..l_header_adj_att_tbl.LAST
7931 	    LOOP
7932       l_header_adj_att_tbl(i).operation := OE_Globals.G_OPR_CREATE;
7933    END LOOP;
7934 
7935     IF l_debug_level  > 0 THEN
7936        IF l_header_adj_att_tbl.COUNT > 0 then
7937 	  FOR i in l_header_adj_att_tbl.first..l_header_adj_att_tbl.last
7938 		   LOOP
7939 	     oe_debug_pub.add('BEFORE Process Order header_adj_att_tbl rec='||i||
7940 			      ' line_index='||l_header_adj_att_tbl(i).adj_index||
7941 			      ' pricing context='||l_header_adj_att_tbl(i).pricing_context||
7942 			      'pricing attribute='||l_header_adj_att_tbl(i).pricing_attribute||
7943 			      'pricing attribute value from='||l_header_adj_att_tbl(i).pricing_attr_value_from||
7944 			      'pricing attribute value to=' ||l_header_adj_att_tbl(i).pricing_attr_value_to
7945 			      );
7946 	  END LOOP;
7947        END IF;
7948     END IF; -- if debug level
7949  END IF; -- if header adj attr being passed.
7950 
7951 
7952 --IF in_header_adj_assoc_tbl.COUNT > 0 then
7953 IF l_header_adj_assoc_tbl.COUNT > 0 then
7954   --  l_header_adj_assoc_tbl:= in_header_adj_assoc_tbl;
7955     FOR i in l_header_adj_assoc_tbl.FIRST..l_header_adj_assoc_tbl.LAST
7956     LOOP
7957       l_header_adj_assoc_tbl(i).operation := OE_Globals.G_OPR_CREATE;
7958     END LOOP;
7959 
7960     IF l_debug_level  > 0 THEN
7961        IF l_header_adj_assoc_tbl.COUNT > 0 then
7962 	  FOR i in l_header_adj_assoc_tbl.first..l_header_adj_assoc_tbl.last
7963 		   LOOP
7964 	     oe_debug_pub.add('BEFORE Process Order header_adj_att_tbl rec='||i||
7965 			      ' line_index='||l_header_adj_assoc_tbl(i).line_index||
7966 			      ' Adjustment index='||l_header_adj_assoc_tbl(i).adj_index||
7967 			      'Related adjustment index'||l_header_adj_assoc_tbl(i).rltd_adj_index
7968 			      );
7969 	  END LOOP;
7970        END IF;
7971     END IF; -- if debug level
7972  END IF; -- if header adj assoc being passed.
7973 
7974 
7975   -- this is not required as it will book the order
7976   --l_action_request_tbl(1).entity_code := OE_GLOBALS.G_ENTITY_HEADER;
7977   --l_action_request_tbl(1).request_type:= OE_GLOBALS.G_BOOK_ORDER;
7978 
7979   oe_debug_pub.initialize;
7980   IF l_debug_level  > 0 THEN
7981      print_time('Before Calling Process Order'||l_Line_Adj_tbl.count);
7982   END IF;
7983 
7984   OE_GLOBALS.g_validate_desc_flex:='Y';
7985   IF OE_ORDER_CACHE.IS_FLEX_ENABLED('OE_HEADER_ATTRIBUTES') = 'Y'
7986   AND OE_GLOBALS.g_validate_desc_flex='Y' THEN
7987 
7988     IF NOT OE_VALIDATE.Header_Desc_Flex
7989           (p_context            => l_header_rec.context
7990           ,p_attribute1         => l_header_rec.attribute1
7991           ,p_attribute2         => l_header_rec.attribute2
7992           ,p_attribute3         => l_header_rec.attribute3
7993           ,p_attribute4         => l_header_rec.attribute4
7994           ,p_attribute5         => l_header_rec.attribute5
7995           ,p_attribute6         => l_header_rec.attribute6
7996           ,p_attribute7         => l_header_rec.attribute7
7997           ,p_attribute8         => l_header_rec.attribute8
7998           ,p_attribute9         => l_header_rec.attribute9
7999           ,p_attribute10        => l_header_rec.attribute10
8000           ,p_attribute11        => l_header_rec.attribute11
8001           ,p_attribute12        => l_header_rec.attribute12
8002           ,p_attribute13        => l_header_rec.attribute13
8003           ,p_attribute14        => l_header_rec.attribute14
8004           ,p_attribute15        => l_header_rec.attribute15
8005           ,p_attribute16        => l_header_rec.attribute16
8006           ,p_attribute17        => l_header_rec.attribute17
8007           ,p_attribute18        => l_header_rec.attribute18
8008           ,p_attribute19        => l_header_rec.attribute19
8009           ,p_attribute20        => l_header_rec.attribute20)
8010           THEN
8011       OE_GLOBALS.g_validate_desc_flex:='N';
8012       oe_debug_pub.add('Pricing  AVa, HEaderAttribue1-NOT VALID  ');
8013     END IF;
8014       oe_debug_pub.add('Pricing  AVa, HEaderAttribute1  '||l_header_rec.attribute1,1);
8015   END IF;
8016 
8017   IF OE_ORDER_CACHE.IS_FLEX_ENABLED('OE_HEADER_GLOBAL_ATTRIBUTE') = 'Y'
8018   AND OE_GLOBALS.g_validate_desc_flex='Y' THEN
8019           IF NOT OE_VALIDATE.G_Header_Desc_Flex
8020           (p_context            => l_header_rec.global_attribute_category
8021           ,p_attribute1         => l_header_rec.global_attribute1
8022           ,p_attribute2         => l_header_rec.global_attribute2
8023           ,p_attribute3         => l_header_rec.global_attribute3
8024           ,p_attribute4         => l_header_rec.global_attribute4
8025           ,p_attribute5         => l_header_rec.global_attribute5
8026           ,p_attribute6         => l_header_rec.global_attribute6
8027           ,p_attribute7         => l_header_rec.global_attribute7
8028           ,p_attribute8         => l_header_rec.global_attribute8
8029           ,p_attribute9         => l_header_rec.global_attribute9
8030           ,p_attribute10        => l_header_rec.global_attribute10
8031           ,p_attribute11        => l_header_rec.global_attribute11
8032           ,p_attribute12        => l_header_rec.global_attribute12
8033           ,p_attribute13        => l_header_rec.global_attribute13
8034           ,p_attribute14        => l_header_rec.global_attribute13
8035           ,p_attribute15        => l_header_rec.global_attribute14
8036           ,p_attribute16        => l_header_rec.global_attribute16
8037           ,p_attribute17        => l_header_rec.global_attribute17
8038           ,p_attribute18        => l_header_rec.global_attribute18
8039           ,p_attribute19        => l_header_rec.global_attribute19
8040           ,p_attribute20        => l_header_rec.global_attribute20)
8041           THEN
8042       OE_GLOBALS.g_validate_desc_flex:='N';
8043     END IF;
8044   END IF;
8045 
8046   IF Oe_Order_Cache.IS_FLEX_ENABLED('OE_HEADER_TP_ATTRIBUTES') = 'Y'
8047   AND OE_GLOBALS.g_validate_desc_flex='Y' THEN
8048        IF NOT OE_VALIDATE.TP_Header_Desc_Flex
8049           (p_context            => l_header_rec.tp_context
8050           ,p_attribute1         => l_header_rec.tp_attribute1
8051           ,p_attribute2         => l_header_rec.tp_attribute2
8052           ,p_attribute3         => l_header_rec.tp_attribute3
8053           ,p_attribute4         => l_header_rec.tp_attribute4
8054           ,p_attribute5         => l_header_rec.tp_attribute5
8055           ,p_attribute6         => l_header_rec.tp_attribute6
8056           ,p_attribute7         => l_header_rec.tp_attribute7
8057           ,p_attribute8         => l_header_rec.tp_attribute8
8058           ,p_attribute9         => l_header_rec.tp_attribute9
8059           ,p_attribute10        => l_header_rec.tp_attribute10
8060           ,p_attribute11        => l_header_rec.tp_attribute11
8061           ,p_attribute12        => l_header_rec.tp_attribute12
8062           ,p_attribute13        => l_header_rec.tp_attribute13
8063           ,p_attribute14        => l_header_rec.tp_attribute14
8064           ,p_attribute15        => l_header_rec.tp_attribute15) THEN
8065       OE_GLOBALS.g_validate_desc_flex:='N';
8066     END IF;
8067   END IF;
8068   IF OE_GLOBALS.g_validate_desc_flex='Y' THEN
8069     p_old_line_rec:=OE_ORDER_PUB.G_MISS_LINE_REC;
8070   FOR i in l_line_tbl.FIRST..l_line_tbl.LAST
8071   LOOP
8072     p_x_line_rec:=l_line_tbl(i);
8073     G_PR_AV:='Y' ;  -- bug7380336
8074     OE_VALIDATE_LINE.Validate_Flex(
8075                    p_x_line_rec        => p_x_line_rec,
8076                    p_old_line_rec      => p_old_line_rec,
8077                    p_validation_level  => FND_API.G_VALID_LEVEL_FULL,
8078                    x_return_status     => x_return_status
8079                    );
8080       oe_debug_pub.add('Pricing  AVa,Attribute1  '||p_x_line_rec.attribute1,1);
8081       oe_debug_pub.add('Pricing  AVa,Attribute1-Return'||x_return_status,1);
8082     G_PR_AV:='N' ;  -- bug7380336
8083 
8084     IF x_return_status  = FND_API.G_RET_STS_UNEXP_ERROR THEN
8085       OE_GLOBALS.g_validate_desc_flex:='N';
8086     ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
8087       OE_GLOBALS.g_validate_desc_flex:='N';
8088     ELSIF x_return_status=FND_API.G_RET_STS_SUCCESS THEN
8089       null;
8090     END IF;
8091     x_return_status := FND_API.G_RET_STS_SUCCESS;
8092   END LOOP;
8093   END IF;
8094 
8095   OE_Order_PVT.Process_order
8096     (   p_api_version_number          => 1.0
8097     ,   p_init_msg_list               => FND_API.G_TRUE
8098     ,   x_return_status               => x_return_status
8099     ,   x_msg_count                   => x_msg_count
8100     ,   x_msg_data                    => x_msg_data
8101  -- ,   p_control_rec                 => l_control_rec
8102  -- ,   p_validation_level	      => FND_API.G_VALID_LEVEL_NONE
8103     ,   p_x_header_Rec                => l_header_rec
8104     ,   p_x_line_tbl	              => l_line_tbl
8105  -- ,   p_line_adj_tbl	              => l_line_adj_tbl
8106     ,   p_x_action_request_tbl	      => l_action_request_tbl
8107     ,   p_x_Header_Adj_tbl            => l_Header_Adj_tbl
8108     ,   p_x_Header_Payment_tbl        =>l_x_Header_Payment_tbl
8109     ,   p_x_Header_Scredit_tbl        => l_x_Header_Scredit_tbl
8110     ,   p_x_Line_Adj_tbl              => l_Line_Adj_tbl
8111     ,   p_x_Line_Scredit_tbl          => l_x_Line_Scredit_tbl
8112     ,   p_x_Lot_Serial_tbl	      => l_x_lot_serial_tbl
8113     ,	p_x_Line_Payment_tbl          => l_x_Line_Payment_tbl
8114     ,   p_x_Header_price_Att_tbl	=> l_Header_price_Att_tbl
8115     ,   p_x_Header_Adj_Att_tbl	=> l_Header_Adj_Att_tbl
8116     ,   p_x_Header_Adj_Assoc_tbl	=> l_Header_Adj_Assoc_tbl
8117     ,   p_x_Line_price_Att_tbl	=> l_Line_price_Att_tbl
8118     ,   p_x_Line_Adj_Att_tbl	=> l_Line_Adj_Att_tbl
8119     ,   p_x_Line_Adj_Assoc_tbl	=> l_Line_Adj_Assoc_tbl
8120     );
8121 
8122 
8123     IF l_debug_level  > 0 THEN
8124      print_time('After Calling Process Order Return ');
8125     END IF;
8126 
8127   -- Check the status and print appropriate messages
8128   IF x_return_status <>  FND_API.G_RET_STS_SUCCESS then
8129 
8130     IF l_debug_level  > 0 THEN
8131       oe_debug_pub.add('error in process order 1',1);
8132       oe_Debug_pub.add('ERROR while creating order!');
8133     END IF;
8134     rollback;
8135 
8136   ELSE
8137 
8138     IF l_debug_level  > 0 THEN
8139       oe_debug_pub.add('Header ID :' ||l_header_rec.header_id,1);
8140       oe_debug_pub.add('Order number :'||l_header_rec.order_number,1);
8141       oe_debug_pub.add('Sold To :'||l_header_rec.sold_to_org_id,1);
8142       oe_debug_pub.add('Invoice To :'||l_header_rec.invoice_to_org_id,1);
8143       oe_debug_pub.add('Ship To :'||l_header_rec.ship_to_org_id,1);
8144     END IF;
8145 
8146     commit;
8147     out_header_id := l_header_rec.header_id;
8148     out_order_number := l_header_rec.order_number;
8149     out_currency := l_header_rec.transactional_curr_code;
8150 
8151 
8152     IF l_debug_level  > 0 THEN
8153       FOR i in l_line_tbl.FIRST..l_line_tbl.LAST
8154       LOOP
8155         oe_debug_pub.add('counter = '||i||
8156                        ' qty='||l_line_tbl(i).ordered_quantity||
8157                        'price='||l_line_tbl(i).unit_selling_price
8158                       );
8159       END LOOP;
8160     END IF;
8161 
8162     oe_oe_totals_summary.order_totals(
8163                       p_header_id=>out_header_id,
8164                       p_subtotal=>l_subtotal,
8165                       p_discount=>l_discount,
8166                       p_charges=>l_charges,
8167                       p_tax=>l_tax
8168                                      );
8169 
8170     IF l_debug_level  > 0 THEN
8171       oe_Debug_pub.add('After calling Order_Totals '||
8172                      ' subtotal='||l_subtotal||
8173                      ' discount='||l_discount||
8174                      ' charges='||l_charges||
8175                      ' tax='||l_tax
8176                     );
8177     END IF;
8178 
8179     out_order_total := l_subtotal + l_discount + l_charges + l_tax;
8180     out_order_amount := l_subtotal;
8181     out_order_charges := l_charges;
8182     out_order_discount := l_discount;
8183     out_order_tax   := l_tax;
8184 
8185     IF l_debug_level  > 0 THEN
8186       oe_Debug_pub.add('out_order_total ='||out_order_total);
8187     END IF;
8188 
8189     --out_order_total := l_line_tbl(1).ordered_quantity *
8190     --                   l_line_tbl(1).unit_selling_price;
8191    -- out_item := l_line_tbl(1).ordered_item;
8192     if l_debug_level > 0 then
8193        oe_Debug_pub.add('before quering');
8194        end if;
8195     begin
8196      	 select booked_flag, shipping_interfaced_flag
8197     into l_booked_flag, l_shipping_interfaced_flag
8198     from oe_order_lines_all
8199     where header_id = l_header_rec.header_id
8200       and rownum = 1;
8201        oe_Debug_pub.add('booked_flag'||l_booked_flag ||'shipping interfaced flag'||l_shipping_interfaced_flag);
8202      Exception
8203 	When others then
8204 	   oe_debug_pub.add('error while querying the oe_order_lines_all'||SQLERRM||SQLCODE);
8205      End;
8206 
8207      if l_debug_level >0 then
8208 	    oe_Debug_pub.add('booked_flag'||l_booked_flag ||'shipping interfaced flag'||l_shipping_interfaced_flag);
8209 	    end if;
8210 
8211     IF l_shipping_interfaced_flag <> 'Y' then
8212 
8213       IF l_debug_level  > 0 THEN
8214           oe_Debug_pub.add('Order was created but there was an ERROR during the order processing flow.');
8215           oe_Debug_pub.add('Order Number: '||l_header_rec.order_number);
8216       END IF;
8217 
8218       if l_booked_flag <> 'Y' then
8219 
8220         IF l_debug_level  > 0 THEN
8221           oe_Debug_pub.add('There was an error during the booking activity.');
8222           --x_return_status := 'E'; --fnd_api.g_ret_sts_error;
8223         END IF;
8224       else
8225         IF l_debug_level  > 0 THEN
8226           oe_Debug_pub.add('Order booked but line not interfaced to shipping.');
8227           oe_Debug_pub.add('There was a failure either in scheduling or shipping interface activity.');
8228          --x_return_status := fnd_api.g_ret_sts_error;
8229         END IF;
8230       end if;
8231 
8232     ELSE
8233 
8234       IF l_debug_level  > 0 THEN
8235         oe_Debug_pub.add('Order processed successfully.');
8236         oe_Debug_pub.add('Order Number: '||l_header_rec.order_number);
8237         oe_Debug_pub.add('Order has been booked and line has been scheduled,');
8238         oe_Debug_pub.add('interfaced to shipping.');
8239       END IF;
8240 
8241     END IF; -- if interfaced to shipping
8242 
8243   END IF;
8244 
8245   IF x_return_status <> fnd_api.g_ret_sts_success then
8246 
8247     -- Print out the error messages, if any
8248 
8249     IF l_debug_level  > 0 THEN
8250       IF x_msg_count > 0 then
8251         oe_debug_pub.add('Number of Messages :'||x_msg_count,1);
8252         oe_Debug_pub.add('Number of Messages :'||x_msg_count);
8253       END IF;
8254     END IF;
8255 
8256     FOR k in 1 .. x_msg_count loop
8257       x_msg_data := oe_msg_pub.get( p_msg_index => k,
8258                                     p_encoded => 'F'
8259                                    );
8260 
8261       IF l_debug_level  > 0 THEN
8262         oe_debug_pub.add(substr(x_msg_data,1,255));
8263         oe_debug_pub.add(substr(x_msg_data,255,length(x_msg_data)));
8264         oe_Debug_pub.add('Message: '||substr(x_msg_data,1,200));
8265       END IF;
8266 
8267     END LOOP;
8268 
8269 
8270   END IF; -- if 2nd return status not success
8271 
8272 
8273 EXCEPTION
8274 
8275     WHEN FND_API.G_EXC_ERROR THEN
8276 
8277         x_return_status := FND_API.G_RET_STS_ERROR;
8278 
8279         --  Get message count and data
8280 
8281         OE_MSG_PUB.Count_And_Get
8282         (   p_count                       => x_msg_count
8283         ,   p_data                        => x_msg_data
8284         );
8285 
8286     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8287 
8288         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
8289 
8290         --  Get message count and data
8291 
8292         OE_MSG_PUB.Count_And_Get
8293         (   p_count                       => x_msg_count
8294         ,   p_data                        => x_msg_data
8295         );
8296 
8297     WHEN OTHERS THEN
8298 
8299         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
8300 
8301         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
8302         THEN
8303             OE_MSG_PUB.Add_Exc_Msg
8304             (   G_PKG_NAME
8305             ,   'Create_Order'
8306             );
8307         END IF;
8308 
8309         --  Get message count and data
8310 
8311         OE_MSG_PUB.Count_And_Get
8312         (   p_count                       => x_msg_count
8313         ,   p_data                        => x_msg_data
8314         );
8315 
8316 
8317 
8318 END Create_Order;
8319 
8320 
8321 PROCEDURE get_atp_flag(
8322                in_inventory_item_id in number
8323                ,in_org_id in number
8324                ,out_atp_flag out NOCOPY /* file.sql.39 change */ varchar2
8325                ,out_default_source_type out NOCOPY /* file.sql.39 change */ varchar2
8326                       ) IS
8327 
8328 
8329 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8330 
8331 CURSOR c_atp_flag IS
8332   SELECT atp_flag,
8333          decode(default_so_source_type,'EXTERNAL','External','INTERNAL','Internal')
8334     FROM mtl_system_items
8335    WHERE inventory_item_id = in_inventory_item_id
8336      AND organization_id   = in_org_id;
8337 
8338 BEGIN
8339 
8340   IF in_inventory_item_id is not null  then
8341 
8342     OPEN  c_atp_flag;
8343     FETCH c_atp_flag
8344      INTO out_atp_flag,
8345           out_default_source_type;
8346     CLOSE c_atp_flag;
8347 
8348   ELSE
8349     IF l_debug_level > 0 then
8350       oe_debug_pub.add('get_atp_flag in_id is null');
8351     END IF;
8352 
8353   END IF;
8354 
8355 EXCEPTION
8356    WHEN OTHERS THEN
8357      IF c_atp_flag%ISOPEN then
8358        CLOSE c_atp_flag;
8359      END IF;
8360      oe_debug_pub.add('get_atp_flag id='||In_inventory_item_id||
8361                       SQLERRM||SQLCODE
8362                      );
8363 
8364 END get_atp_flag;
8365 
8366 
8367 FUNCTION  Is_AdPricing_inst return varchar2 IS
8368 
8369 l_status varchar2(10);
8370 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8371 
8372 BEGIN
8373 
8374   -- we need to call qp_util.get_qp_status,
8375   -- I=advanced , S=Basic, N=No Installation
8376 
8377   l_status := qp_util.get_qp_status;
8378 
8379   IF l_debug_level > 0 then
8380     oe_debug_pub.add('Advanced Pricing Instaleed status ='||l_status);
8381   END IF;
8382 
8383   return l_status;
8384   --return 'I';
8385  -- return 'S';
8386 
8387 END Is_AdPricing_Inst;
8388 
8389 --   start .Added for bug 3559935 , to avoid recompiling the pld again and again
8390  --  whenever there is a change in OEXFHDRB.pls
8391 
8392 PROCEDURE RESET_DEBUG_LEVEL
8393 IS
8394 
8395 BEGIN
8396  OE_DEBUG_PUB.G_DEBUG_LEVEL:=0;
8397 
8398 END RESET_DEBUG_LEVEL;
8399 
8400 PROCEDURE SET_DEBUG_LEVEL (p_debug_level IN NUMBER)
8401 IS
8402 
8403 BEGIN
8404  OE_DEBUG_PUB.G_DEBUG_LEVEL:=p_debug_level;
8405 
8406 END SET_DEBUG_LEVEL;
8407 
8408 
8409 PROCEDURE Get_Form_Startup_Values
8410 (Item_Id_Flex_Code         IN VARCHAR2,
8411 Item_Id_Flex_Num OUT NOCOPY NUMBER) IS
8412 
8413     CURSOR C_Item_Flex(X_Id_Flex_Code VARCHAR2) is
8414       SELECT id_flex_num
8415       FROM   fnd_id_flex_structures
8416       WHERE  id_flex_code = X_Id_Flex_Code;
8417 BEGIN
8418 
8419     oe_debug_pub.add('Entering OE_OE_PRICING_AVAILABILITY.GET_FORM_STARTUP_VALUES', 1);
8420 
8421     OPEN C_Item_Flex(Item_Id_Flex_Code);
8422     FETCH C_Item_Flex INTO Item_Id_Flex_Num;
8423     CLOSE C_Item_Flex;
8424 
8425     oe_debug_pub.add('Exiting OE_OE_FORM_HEADER.GET_FORM_STARTUP_VALUES', 1);
8426 
8427   EXCEPTION
8428     WHEN OTHERS THEN
8429       oe_debug_pub.add('In when others exception : OE_OE_PRICING_AVAILABILITY.GET_FORM_STARTUP_VALUES', 1);
8430      IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
8431      THEN
8432          OE_MSG_PUB.Add_Exc_Msg
8433          (     G_PKG_NAME         ,
8434              'Get_Form_Startup_Values'
8435          );
8436      END IF;
8437 
8438      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8439 
8440 
8441 END Get_Form_Startup_Values;
8442 
8443 
8444 Procedure get_user_item_Pricing_Contexts(
8445 			p_request_type_code IN   VARCHAR2,
8446 			x_user_attribs_tbl  OUT NOCOPY USER_ATTRIBUTE_TBL_TYPE)  IS
8447 
8448 l_user_attribs_tbl QP_Attr_Mapping_PUB.USER_ATTRIBUTE_TBL_TYPE;
8449 
8450 
8451 Begin
8452 
8453 	QP_Attr_Mapping_PUB.get_user_item_Pricing_Contexts(
8454 		p_request_type_code,
8455 		p_user_attribs_tbl =>	l_user_attribs_tbl);
8456 
8457 	FOR I IN 1..l_user_attribs_tbl.COUNT LOOP
8458 
8459 		x_user_attribs_tbl(I).context_name	:=   l_user_attribs_tbl(I).context_name;
8460 		x_user_attribs_tbl(I).attribute_name	:= l_user_attribs_tbl(I).attribute_name;
8461 	END LOOP;
8462 
8463  End   get_user_item_Pricing_Contexts;
8464 
8465  -- end 3559935
8466 
8467 --add 3245976
8468 
8469 
8470 FUNCTION GET_MRP_ERR_MSG_FLAG
8471 RETURN CHAR
8472 IS
8473 BEGIN
8474   return g_mrp_error_msg_flag;
8475 END GET_MRP_ERR_MSG_FLAG;
8476 
8477 
8478 FUNCTION GET_MRP_ERR_MSG RETURN VARCHAR
8479 IS
8480 err_msg varchar2(1000);
8481 BEGIN
8482 	 err_msg :=g_mrp_error_msg;
8483 	 g_mrp_error_msg :=NULL;
8484 	 g_mrp_error_msg_flag :='F';
8485 	 return err_msg;
8486 
8487 END  GET_MRP_ERR_MSG;
8488 
8489 /* start bug 3440778 , Created to convert the reference to other products serverside code  inside OEXPRAVA pld into a local call. to OE_OE_PRICING_AVAILABILITY package*/
8490 
8491 FUNCTION Get_Cost (p_line_rec       IN  OE_ORDER_PUB.LINE_REC_TYPE   DEFAULT OE_Order_Pub.G_MISS_LINE_REC
8492                   ,p_request_rec    IN Oe_Order_Pub.Request_Rec_Type DEFAULT Oe_Order_Pub.G_MISS_REQUEST_REC
8493                   ,p_order_currency IN VARCHAR2 Default NULL
8494                   ,p_sob_currency   IN VARCHAR2 Default NULL
8495                   ,p_inventory_item_id    IN NUMBER Default NULL
8496                   ,p_ship_from_org_id     IN NUMBER Default NULL
8497                   ,p_conversion_Type_code IN VARCHAR2 Default NULL
8498                   ,p_conversion_rate      IN NUMBER   Default NULL
8499                   ,p_item_type_code       IN VARCHAR2 Default 'STANDARD'
8500                   ,p_header_flag          IN Boolean Default FALSE)
8501 ----------------------------------------------------------------
8502 RETURN NUMBER IS
8503 
8504 l_unit_cost number;
8505 BEGIN
8506 	l_unit_cost :=OE_MARGIN_PVT.Get_Cost(p_line_rec
8507 	                                      ,p_request_rec
8508 					      ,p_order_currency
8509 					      ,p_sob_currency
8510 					      ,p_inventory_item_id
8511 					      ,p_ship_from_org_id
8512 					      ,p_conversion_Type_code
8513 					      ,p_conversion_rate
8514 					      ,p_item_type_code
8515 					      ,p_header_flag);
8516 	return (l_unit_cost);
8517 END  Get_Cost;
8518 
8519 
8520 PROCEDURE Get_Agreement
8521 (
8522     p_sold_to_org_id            IN NUMBER DEFAULT NULL
8523    ,p_transaction_type_id       IN NUMBER DEFAULT NULL
8524    ,p_pricing_effective_date    IN DATE
8525    ,p_agreement_tbl            OUT NOCOPY agreement_tbl
8526 ) IS
8527 
8528 l_agreement_tbl QP_UTIL_PUB.agreement_tbl;
8529 BEGIN
8530 
8531 	QP_UTIL_PUB.Get_Agreement(  p_sold_to_org_id
8532 				   ,p_transaction_type_id
8533 				   ,p_pricing_effective_date
8534 				   ,l_agreement_tbl);
8535 
8536 	FOR I IN 1..l_agreement_tbl.COUNT LOOP
8537 	  p_agreement_tbl(I).agreement_name	:= l_agreement_tbl(I).agreement_name;
8538 	  p_agreement_tbl(I).agreement_id	:= l_agreement_tbl(I).agreement_id;
8539           p_agreement_tbl(I).agreement_type	:= l_agreement_tbl(I).agreement_type;
8540           p_agreement_tbl(I).price_list_name	:= l_agreement_tbl(I).price_list_name;
8541           p_agreement_tbl(I).customer_name   	:= l_agreement_tbl(I).price_list_name;
8542           p_agreement_tbl(I).payment_term_name	:= l_agreement_tbl(I).payment_term_name;
8543           p_agreement_tbl(I).start_date_active  := l_agreement_tbl(I).start_date_active;
8544           p_agreement_tbl(I).end_date_active  	:= l_agreement_tbl(I).end_date_active;
8545 
8546 	END LOOP;
8547 
8548 END Get_Agreement;
8549 
8550   -- round_price.p_operand_type could be 'A' for adjustment amount or 'S' for item price
8551 PROCEDURE round_price
8552 (
8553      p_operand                  IN NUMBER
8554     ,p_rounding_factor          IN NUMBER
8555     ,p_use_multi_currency       IN VARCHAR2
8556     ,p_price_list_id            IN NUMBER
8557     ,p_currency_code            IN VARCHAR2
8558     ,p_pricing_effective_date   IN DATE
8559     ,x_rounded_operand         IN OUT NOCOPY NUMBER
8560     ,x_status_code             IN OUT NOCOPY VARCHAR2
8561     ,p_operand_type             IN VARCHAR2 default 'S'
8562 )
8563 IS
8564 BEGIN
8565 	QP_UTIL_PUB.round_price
8566 	(
8567 	     p_operand
8568 	    ,p_rounding_factor
8569 	    ,p_use_multi_currency
8570 	    ,p_price_list_id
8571 	    ,p_currency_code
8572 	    ,p_pricing_effective_date
8573 	    ,x_rounded_operand
8574 	    ,x_status_code
8575 	    ,p_operand_type
8576 	);
8577 END round_price;
8578 
8579 -- end   bug 3440778
8580 
8581 END oe_oe_pricing_availability;