DBA Data[Home] [Help]

PACKAGE BODY: APPS.OKC_PRICE_PVT

Source


1 PACKAGE BODY OKC_PRICE_PVT AS
2 /* $Header: OKCRPREB.pls 120.2 2006/02/28 14:52:17 smallya noship $ */
3 
4 
5 -- package body level variables-----------------
6 
7  l_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N');
8 
9  l_exception_stop Exception;
10  TYPE flag_tab_type is table of varchar2(1);
11  TYPE CHAR_TBL_TYPE is TABLE of VARCHAR2(450) INDEX BY BINARY_INTEGER;
12 
13  G_HDR_RUL_TBL            GLOBAL_RPRLE_TBL_TYPE;
14  G_HDR_PRLE_TBL           GLOBAL_RPRLE_TBL_TYPE;
15 
16  g_hdr_pricelist          NUMBER;
17  g_authoring_org_id       NUMBER;
18  g_hdr_pricing_date       DATE   DEFAULT TRUNC(SYSDATE);
19 
20  g_qa_mode                VARCHAR2(1) := 'N';
21 
22 
23 Procedure my_debug(p_msg varchar2,p_level NUMBER DEFAULT 1, p_module IN Varchar2 Default  'OKC') IS
24  BEGIN
25    IF (l_debug = 'Y') THEN
26       okc_debug.Log(p_msg,p_level,p_module);
27    END IF;
28     --dbms_output.put_line(substr(p_msg,1,240));
29     --dbms_output.put_line(p_msg);
30 END my_debug;
31 ----------------------------------------------------
32 ------------------------------------------------------------------------------
33  -- Set_control_re sets the control rec for price request if not alraedy set
34 ------------------------------------------------------------------------------
35 Procedure Set_control_rec(px_control_rec IN OUT NOCOPY OKC_CONTROL_REC_TYPE) IS
36   BEGIN
37      IF (l_debug = 'Y') THEN
38         okc_debug.Set_Indentation('Set_control_rec');
39      END IF;
40      IF (l_debug = 'Y') THEN
41         my_debug('100 : Entering Set_control_rec', 2);
42      END IF;
43 
44     If px_control_rec.p_request_type_code is null then
45        px_control_rec.p_request_type_code := 'OKC';
46     End If;
47     IF (l_debug = 'Y') THEN
48        my_debug('110 : request type code'||px_control_rec.p_request_type_code, 1);
49     END IF;
50 
51     If px_control_rec.qp_control_rec.pricing_event is null then
52        px_control_rec.qp_control_rec.pricing_event := 'BATCH';
53     End If;
54     IF (l_debug = 'Y') THEN
55        my_debug('120 :pricing event'||px_control_rec.qp_control_rec.pricing_event, 1);
56     END IF;
57 
58     If px_control_rec.qp_control_rec.calculate_flag is null then
59      If px_control_rec.p_calc_flag = 'B' then
60         px_control_rec.qp_control_rec.calculate_flag := 'Y';
61      ELsif px_control_rec.p_calc_flag = 'C' then
62         px_control_rec.qp_control_rec.calculate_flag := 'C';
63      ELsif px_control_rec.p_calc_flag = 'S' then
64         px_control_rec.qp_control_rec.calculate_flag := 'Y'; --???this can be later changed to 'S' if pub is tested for this
65         px_control_rec.qp_control_rec.SIMULATION_flag := 'Y'; --???? check if we need to set simulation_flag 'Y' here
66      End If;
67     End If;
68     IF (l_debug = 'Y') THEN
69        my_debug('130 :okc calc flag'||px_control_rec.p_calc_flag, 1);
70        my_debug('140 :qp calculate flag'||px_control_rec.qp_control_rec.calculate_flag, 1);
71        my_debug('145 :p level'||px_control_rec.p_level, 1);
72     END IF;
73 
74     If px_control_rec.qp_control_rec.SIMULATION_flag is null and px_control_rec.p_level <> 'QA' then
75        px_control_rec.qp_control_rec.SIMULATION_flag := 'N';
76     Elsif px_control_rec.p_level = 'QA' then
77            px_control_rec.qp_control_rec.SIMULATION_flag := 'Y';
78     End If;
79     IF (l_debug = 'Y') THEN
80        my_debug('150 :simulation flag'||px_control_rec.qp_control_rec.SIMULATION_flag, 1);
81     END IF;
82 
83     If px_control_rec.qp_control_rec.TEMP_TABLE_INSERT_FLAG is null then
84        px_control_rec.qp_control_rec.TEMP_TABLE_INSERT_FLAG := 'Y';
85     End If;
86     IF (l_debug = 'Y') THEN
87        my_debug('160 :Temp table insert flag'||px_control_rec.qp_control_rec.TEMP_TABLE_INSERT_FLAG, 1);
88     END IF;
89 
90 -- set OE_DEBUG. Along with this flag, set profile option QP:DEBUG(QP_DEBUG)
91 -- to generate debug file for QP
92     If px_control_rec.qp_control_rec.DEBUG_FLAG  is null then
93        --px_control_rec.qp_control_rec.DEBUG_FLAG  := 'N';
94        px_control_rec.qp_control_rec.DEBUG_FLAG  := 'Y';
95     End If;
96     IF (l_debug = 'Y') THEN
97        my_debug('170 :Pricing Debug ON/OFF flag'||px_control_rec.qp_control_rec.DEBUG_FLAG, 1);
98     END IF;
99 
100     IF (l_debug = 'Y') THEN
101        my_debug('900 : Exiting Set_control_rec', 2);
102     END IF;
103     IF (l_debug = 'Y') THEN
104        okc_debug.Reset_Indentation;
105     END IF;
106 END Set_control_rec;
107 
108 -------------------------Called from form---------------------------------------------------
109 -- Update_Line_price
110 -- This procedure will calculate the price for all the Priced lines below sent in line
111 -- Called when a line is updated in the form
112 -- p_lowest_level- Level number of the lowest subline being displayed
113 -- p_cle_id - id of the line updated
114 -- p_chr_id - id of the header
115 -- p_lowest_level Possible values 0(p_cle_id not null and this line is subline),
116 --                                 1(p_cle_id not null and this line is upper line),
117 --                                 -1(update all lines)
118 --                                 -2(update all lines and header)
119 --                                 DEFAULT -2
120 --px_chr_list_price  IN OUT -holds the total line list price, for right value pass in the existing value,
121 --px_chr_net_price   IN OUT -holds the total line net price, for right value pass in the existing value
122 -- px_cle_amt gets back the net price for the line that was updated. In case of
123 -- p_negotiated_changed, it brings in the old net price of the line updated
124 ----------------------------------------------------------------------------
125 PROCEDURE Update_LINE_price(
126           p_api_version                 IN          NUMBER,
127           p_init_msg_list               IN          VARCHAR2 ,
128           p_commit                      IN          VARCHAR2 ,
129           p_CHR_ID                      IN          NUMBER,
130           p_cle_id			            IN	        NUMBER ,
131           p_lowest_level                IN          NUMBER ,
132           px_Control_Rec			    IN  OUT NOCOPY     OKC_CONTROL_REC_TYPE,
133           px_chr_list_price             IN  OUT NOCOPY     NUMBER,
134           px_chr_net_price              IN  OUT NOCOPY     NUMBER,
135           px_cle_amt    		        IN  OUT NOCOPY     NUMBER,
136           x_CLE_PRICE_TBL		        OUT  NOCOPY CLE_PRICE_TBL_TYPE,
137           --???? x_cle_list_price           OUT  NOCOPY NUMBER,
138           x_return_status               OUT  NOCOPY VARCHAR2,
139           x_msg_count                   OUT  NOCOPY NUMBER,
140           x_msg_data                    OUT  NOCOPY VARCHAR2) IS
141     l_return_status varchar2(1) :=OKC_API.G_RET_STS_SUCCESS;
142 
143     l_api_name constant VARCHAR2(30) := 'Update_line_PRICE';
144     l_cle_id_tbl num_tbl_type;
145     i pls_integer :=0;
146     j pls_integer :=0;
147     l_ind pls_integer :=0;
148 
149     l_lvl_tbl num_tbl_type;
150     l_id_tbl num_tbl_type;
151     l_obj_tbl num_tbl_type;
152     l_p_tbl   flag_tab_type ;
153     l_bpi_tbl flag_tab_type ;
154     l_amt_tbl num_tbl_type;
155     l_list_tbl num_tbl_type;
156     --???? take this out when uncommented above
157      x_cle_list_price       NUMBER;
158      x_cle_amt              NUMBER;
159     l_new_amt number :=0;
160     l_new_list_price number :=0;
161     l_obj number :=1;
162     l_amt number :=0;
163     l_list_price number :=0;
164 
165     l_cle_id number;
166 
167     l_chr_rec  okc_contract_pub.chrv_rec_type;
168     x_chr_rec  okc_contract_pub.chrv_rec_type;
169     l_cle_tbl  okc_contract_pub.clev_tbl_type;
170     x_cle_tbl  okc_contract_pub.clev_tbl_type;
171 
172     l_req_line_tbl              QP_PREQ_GRP.LINE_TBL_TYPE;
173     l_req_line_qual_tbl         QP_PREQ_GRP.QUAL_TBL_TYPE;
174     l_req_line_attr_tbl         QP_PREQ_GRP.LINE_ATTR_TBL_TYPE;
175     l_req_line_detail_tbl       QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE;
176     l_req_line_detail_qual_tbl  QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE;
177     l_req_line_detail_attr_tbl  QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE;
178     l_req_related_line_tbl      QP_PREQ_GRP.RELATED_LINES_TBL_TYPE;
179 
180     TYPE char_TBL_TYPE is TABLE of varchar2(3) INDEX BY BINARY_INTEGER;
181 
182     l_pat_id_tbl  num_tbl_type;
183     l_operand_tbl  num_tbl_type;
184     l_value_tbl  num_tbl_type;
185 
186     l_operator_tbl char_tbl_type;
187 
188     l_rowlevel number :=0;
189     l_p_found boolean :=false;
190 
191     l_patv_tbl   OKC_PRICE_ADJUSTMENT_PUB.patv_tbl_type;
192     lx_patv_tbl  OKC_PRICE_ADJUSTMENT_PUB.patv_tbl_type;
193 BEGIN
194     IF (l_debug = 'Y') THEN
195        okc_debug.Set_Indentation('Update_line_PRICE');
196     END IF;
197     IF (l_debug = 'Y') THEN
198        my_debug('1000 : Entering Update_line_PRICE', 2);
199     END IF;
200 
201     x_return_status := OKC_API.G_RET_STS_SUCCESS;
202 
203     l_return_status := OKC_API.START_ACTIVITY(l_api_name,
204                                               p_init_msg_list,
205                                               '_PROCESS',
206                                                x_return_status);
207     IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
208                     raise OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
209     ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
210                     raise OKC_API.G_EXCEPTION_ERROR;
211     END IF;
212 
213     Set_control_rec(px_control_rec);
214     if px_control_rec.p_calc_flag = 'S' then
215        OKC_API.set_message(p_app_name      => g_app_name,
216                                  p_msg_name      => 'OKC_INVALID_CALC_FLAG',
217                                  p_token1        => 'calc_flag',
218                                  p_token1_value  => 'S');
219 
220         RAISE OKC_API.G_EXCEPTION_ERROR;
221     End if;
222     px_control_rec.p_level:= 'L';
223     --get all the  lines below the sent in p_cle_id
224       select level,cle_id,id,object_version_number,price_level_ind,price_basis_yn
225       bulk collect into l_lvl_tbl,l_cle_id_tbl,l_id_tbl,l_obj_tbl,l_p_tbl,l_bpi_tbl
226       from OKC_K_LINES_B
227       --where config_item_type is null
228       connect by (prior id = cle_id  and config_item_type is null)
229       start with id=p_cle_id;
230       IF (l_debug = 'Y') THEN
231          my_debug('1050 : select rowcount:'||SQL%ROWCOUNT, 1);
232       END IF;
233 
234 
235     i:= l_id_tbl.first;
236     l_p_found := false;
237     l_rowlevel :=0;
238     -- This loop will take out all the first occurrences of priced lines(there can be more
239     -- if recursive)
240     IF (l_debug = 'Y') THEN
241        my_debug('1055 :starting out nocopy loop to filter priced lines', 1);
242     END IF;
243     while i is not null loop
244         If l_lvl_tbl(i) = 1 or l_lvl_tbl(i)<= l_rowlevel then
245             l_p_found :=false;
246             l_rowlevel:=l_lvl_tbl(i);
247         End if;
248         If l_p_tbl(i)='Y'  and l_p_found=false then
249            IF (l_debug = 'Y') THEN
250               my_debug('1060 : Priced Lines returned'||l_id_tbl(i), 1);
251            END IF;
252            x_cle_price_tbl(i).id:=l_id_tbl(i);
253            l_p_found := true;
254            l_rowlevel := l_lvl_tbl(i);
255         ELSE
256            l_p_tbl(i):='N';
257         End If;
258         IF (l_debug = 'Y') THEN
259            my_debug('1061 : line id'||l_id_tbl(i), 1);
260            my_debug('1062 : priced flag'||l_p_tbl(i), 1);
261            my_debug('1064 : row level'||l_lvl_tbl(i), 1);
262         END IF;
263         If l_p_found then
264           IF (l_debug = 'Y') THEN
265              my_debug('1065 : priced already found', 1);
266           END IF;
267         Else
268           IF (l_debug = 'Y') THEN
269              my_debug('1066 : priced not found', 1);
270           END IF;
271         End if;
272         IF (l_debug = 'Y') THEN
273            my_debug('1067 : saved rowlevel'||l_rowlevel, 1);
274         END IF;
275 
276         i:=l_id_tbl.next(i);
277    END loop;
278 
279 
280    IF (l_debug = 'Y') THEN
281       my_debug('1070 : Before call to Calculate price priced count'||x_cle_price_tbl.count, 1);
282    END IF;
283    --call calculate price and pass in the array of priced lines
284     CALCULATE_price(p_api_version                => p_api_version,
285                     p_CHR_ID                     => p_chr_id,
286                     p_Control_Rec			     => px_control_rec,
287                     px_req_line_tbl              => l_req_line_tbl,
288                     px_Req_qual_tbl              => l_req_line_qual_tbl,
289                     px_Req_line_attr_tbl         => l_req_line_attr_tbl,
290                     px_Req_LINE_DETAIL_tbl       => l_req_line_detail_tbl,
291                     px_Req_LINE_DETAIL_qual_tbl  => l_req_line_detail_qual_tbl,
292                     px_Req_LINE_DETAIL_attr_tbl  => l_req_line_detail_attr_tbl,
293                     px_Req_RELATED_LINE_TBL      => l_req_related_line_tbl,
294                     px_CLE_PRICE_TBL		     => x_CLE_PRICE_TBL,
295                     x_return_status              => x_return_status,
296                     x_msg_count                  => x_msg_count,
297                     x_msg_data                   => x_msg_data);
298    IF (l_debug = 'Y') THEN
299       my_debug('1080 : After call to Calculate price return status'||x_return_status, 1);
300    END IF;
301 
302      IF x_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
303                    RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
304      ELSIF x_return_status = OKC_API.G_RET_STS_ERROR THEN
305                   RAISE OKC_API.G_EXCEPTION_ERROR;
306      -- here not raising an exception but just returning error status as
307      -- we donot want to rollback If one line failed to price
308      ELSIF x_return_status = G_SOME_LINE_ERRORED THEN
309            x_return_status := OKC_API.G_RET_STS_ERROR;
310      END IF;
311      -- go on even if error
312   -- do rollups
313    IF (l_debug = 'Y') THEN
314       my_debug('1090 : After call to Calculate price, Priced_Count'||x_cle_price_tbl.count, 1);
315    END IF;
316 
317       j:=0;
318       --for all the priced lines , do the following
319       i:= x_cle_price_tbl.first;
320       while i is not null loop
321         IF (l_debug = 'Y') THEN
322            my_debug('1100 : In while loop I is '||i, 1);
323            my_debug('1110 : Return status'||x_cle_price_tbl(i).ret_sts, 1);
324            my_debug('1120 : Line Id'||x_cle_price_tbl(i).id, 1);
325         END IF;
326         --if the priced line is P(and not BPI) and the return status is not unexpected error
327         If  x_cle_price_tbl(i).pi_bpi ='P' and x_cle_price_tbl(i).ret_sts <> 'U' then --??????ret_sts='S'
328           -- make cle buffer equal to priced id
329           l_cle_id := x_cle_price_tbl(i).id;
330           -- start from the last in array as the parents of the priced line will be prior to it in array
331           l_ind := l_id_tbl.last;
332           while l_ind is not null loop
333                   IF (l_debug = 'Y') THEN
334                      my_debug('1130 : In while l_cle_id'||x_cle_price_tbl(i).id, 1);
335                      my_debug('1140 : In while l_id'||l_id_tbl(l_ind), 1);
336                      my_debug('1150 : In while bpi'||l_bpi_tbl(l_ind), 1);
337                      my_debug('1150 : In while level'||(l_lvl_tbl(l_ind)-p_lowest_level), 1);
338                   END IF;
339             -- if the cle buffer id found
340              If (l_id_tbl(l_ind)=l_cle_id ) Then --#1
341                  If  (nvl(l_bpi_tbl(l_ind),'N') <> 'Y' and (l_lvl_tbl(l_ind)-p_lowest_level > 1) )then --#2
342                     IF (l_debug = 'Y') THEN
343                        my_debug('1160 : In NOT BPI IF:', 1);
344                     END IF;
345                     -- create a record to update the okc_k_lines
346 
347                     l_cle_tbl(l_ind).id :=l_id_tbl(l_ind);
348                     IF (l_debug = 'Y') THEN
349                        my_debug('1162 : loop for line id:'||l_cle_tbl(l_ind).id, 1);
350                     END IF;
351 
352                     l_cle_tbl(l_ind).object_version_number :=l_obj_tbl(l_ind);
353                     If l_cle_tbl(l_ind).line_list_price = OKC_API.G_MISS_NUM then
354                          l_cle_tbl(l_ind).line_list_price := null;
355                     End if;
356                     If l_cle_tbl(l_ind).price_negotiated = OKC_API.G_MISS_NUM then
357                         l_cle_tbl(l_ind).price_negotiated := null;
358                     End if;
359 
360                     -- If the priced line had some negotiated amount over it
361                     IF x_cle_price_tbl(i).negotiated_amt is not null then
362                        l_cle_tbl(l_ind).price_negotiated :=
363                          nvl(l_cle_tbl(l_ind).price_negotiated,0) + x_cle_price_tbl(i).negotiated_amt;
364                     End If;
365                     IF (l_debug = 'Y') THEN
366                        my_debug('1170 : negotiated amount on line:'||l_cle_tbl(l_ind).price_negotiated, 1);
367                     END IF;
368                       -- if the priced line had some list price over it
369                     IF  x_cle_price_tbl(i).list_price is not null  then
370                       l_cle_tbl(l_ind).line_list_price :=
371                          nvl(l_cle_tbl(l_ind).line_list_price,0) + x_cle_price_tbl(i).list_price;
372                     END IF;
373                     IF (l_debug = 'Y') THEN
374                        my_debug('1180 : list price  on line:'||l_cle_tbl(l_ind).line_list_price, 1);
375                     END IF;
376 
377                     If l_id_tbl(l_ind) = x_cle_price_tbl(i).id then -- that means priced line #3
378                       If x_cle_price_tbl(i).PRICELIST_ID is not null
379                             and x_cle_price_tbl(i).PRICELIST_ID<> OKC_API.G_MISS_NUM then
380                          l_cle_tbl(l_ind).price_list_id :=x_cle_price_tbl(i).PRICELIST_ID;
381                          l_cle_tbl(l_ind).pricing_date :=x_cle_price_tbl(i).pricing_date;
382                          l_cle_tbl(l_ind).price_list_line_id :=x_cle_price_tbl(i).list_line_id;
383                          IF (l_debug = 'Y') THEN
384                             my_debug('1190 : price list found  price list id:'||l_cle_tbl(l_ind).price_list_id, 1);
385                             my_debug('1200 : price list found  price list line id:'||l_cle_tbl(l_ind).price_list_line_id, 1);
386                          END IF;
387 
388                       End If;
389                   ---???? nothing regarding rolling up of updated neg price in contract apis. ask john
390                       l_cle_tbl(l_ind).price_unit:= x_cle_price_tbl(i).unit_price;
391                       IF (l_debug = 'Y') THEN
392                          my_debug('1210 : unit price:'||l_cle_tbl(l_ind).price_unit, 1);
393                       END IF;
394                    END IF; --#3
395                END IF; --#2
396                -- if we have reached the topmost line
397                If l_lvl_tbl(l_ind)=1  then
398                  -- say there is a parent for the topmost line, store its prices to update the parents
399                  l_new_amt := l_cle_tbl(l_ind).price_negotiated ;
400                  l_new_list_price := l_cle_tbl(l_ind).line_list_price ;
401 
402                  IF (l_debug = 'Y') THEN
403                     my_debug('1220 : p_cle_ids negotiated amount:'||l_new_amt, 1);
404                     my_debug('1225 : p_cle_ids list price:'||l_new_list_price, 1);
405                  END IF;
406 
407                  x_cle_amt := l_new_amt;
408                  x_cle_list_price := l_new_list_price;
409                  exit; -- we have reached the top. so no point going any further
410 
411                End If;
412                --pick up the parent of the processed line
413                l_cle_id :=nvl(l_cle_id_tbl(l_ind),0);
414               End If;--#1
415                l_ind:=l_id_tbl.prior(l_ind);
416           end loop;
417         End If;
418         i:=x_cle_price_tbl.next(i);
419      END loop;
420      IF (l_debug = 'Y') THEN
421         my_debug('1240 : number of lines to be updated:'||l_cle_tbl.count);
422      END IF;
423 
424      IF p_lowest_level < 0  and p_cle_id is not null and x_cle_price_tbl.count > 0
425          and (nvl(l_new_amt,-1) <> 0 OR nvl(l_new_list_price,-1) <> 0) then
426               IF (l_debug = 'Y') THEN
427                  my_debug('1245 : In the if for processing parents of p_cle_id. p_lowest_level:'||p_lowest_level);
428               END IF;
429               -- get the parents of passed in p_cle_id
430                select cle_id,id,object_version_number,nvl(price_negotiated,0),nvl(line_list_price,0)
431                bulk collect into l_cle_id_tbl,l_id_tbl,l_obj_tbl,l_amt_tbl,l_list_tbl
432                from OKC_K_LINES_B
433                 --where dnz_chr_id=p_chr_id
434                connect by prior cle_id = id
435                start with id=p_cle_id;
436                IF (l_debug = 'Y') THEN
437                   my_debug('1250 : select rowcount for the parents:'||SQL%ROWCOUNT, 1);
438                   my_debug('1251 : p_negotiated_changed:'||px_control_rec.p_negotiated_changed, 1);
439                   my_debug('1252 : px_cle_amt:'||px_cle_amt, 1);
440                END IF;
441 
442                l_ind := l_cle_tbl.count;
443                i := l_id_tbl.first;
444                While i is not null loop
445                  -- if the record for updated p_cle_id then
446                  If l_id_tbl(i) = p_cle_id then
447                        -- If the line passsed as updated is the priced line and also its
448                        -- net price has been overridden then the database is right now showing the
449                        -- new price as form has posted the changes to database.
450                        -- In that case, take the old price not from database
451                        -- but from what is passed in by form in px_cle_amt
452                        If x_cle_price_tbl(x_cle_price_tbl.first).id = l_id_tbl(i)
453                           and x_cle_price_tbl(i).pi_bpi ='P'
454                           and px_control_rec.p_negotiated_changed = 'Y' and px_cle_amt is not null then
455                                  l_amt_tbl(i) := px_cle_amt;
456                        End If;
457                         --calculate the difference in old amount on p_cle_id and the new amount
458                         -- the difference will be added to all of its parents
459                          l_new_amt := nvl(l_new_amt,0) - nvl(l_amt_tbl(i),0);
460                          l_new_list_price := nvl(l_new_list_price,0) - nvl(l_list_tbl(i),0);
461                          IF (l_debug = 'Y') THEN
462                             my_debug('1260 :In IF old list price:'||l_list_tbl(i), 1);
463                             my_debug('1265 :In IF old negotiated amount:'||l_amt_tbl(i), 1);
464                          END IF;
465 
466                          IF (l_debug = 'Y') THEN
467                             my_debug('1268 :In IF new list price:'||l_new_list_price, 1);
468                             my_debug('1270 :In IF new negotiated amount:'||l_new_amt, 1);
469                          END IF;
470                  Else
471                     -- if the parent of updated line
472                      l_ind:=l_ind+1;
473                      l_cle_tbl(l_ind).id :=l_id_tbl(i);
474                      l_cle_tbl(l_ind).object_version_number :=l_obj_tbl(i);
475                      If l_new_amt <>0 then
476                         l_cle_tbl(l_ind).price_negotiated := nvl(l_amt_tbl(i),0)+l_new_amt;
477                      End if;
478                      If l_new_list_price <> 0 then
479                        l_cle_tbl(l_ind).line_list_price := nvl(l_list_tbl(i),0)+l_new_list_price;
480                      End if;
481                      IF (l_debug = 'Y') THEN
482                         my_debug('1280 :id of the parent:'||l_cle_tbl(l_ind).id , 1);
483                         my_debug('1290 :price negotiated of parent:'||l_cle_tbl(l_ind).price_negotiated, 1);
484                         my_debug('1295 :list price of parent:'||l_cle_tbl(l_ind).line_list_price, 1);
485                      END IF;
486 
487 
488                  End if;
489                  i:= l_id_tbl.next(i);
490                End loop;
491                If l_new_amt is not null and l_new_amt <>0 then
492                   px_chr_net_price := nvl(px_chr_net_price,0)+l_new_amt;
493                End If;
494                If l_new_list_price is not null and l_new_list_price <>0 then
495                   px_chr_list_price := nvl(px_chr_list_price,0)+l_new_list_price;
496                End If;
497                -- if the header also has to be updated
498                If p_lowest_level = -2 then
499                  Begin
500                    Select object_version_number,estimated_amount,total_line_list_price
501                    into l_obj,l_amt,l_list_price
502                    From okc_k_headers_b
503                    where id=p_chr_id;
504                    IF (l_debug = 'Y') THEN
505                       my_debug('1300 : select rowcount for header should be 1: '||SQL%ROWCOUNT, 1);
506                       my_debug('1310 : old amount on header'||l_amt, 1);
507                       my_debug('1320 : old list price on header'||l_list_price, 1);
508                    END IF;
509 
510                      l_chr_rec.id := p_chr_id;
511                      l_chr_rec.object_version_number := l_obj;
512                      If l_new_amt <> 0 then
513                        l_chr_rec.estimated_amount := nvl(l_amt,0)+l_new_amt;
514                      End if;
515                      If l_new_list_price <> 0 then
516                         l_chr_rec.total_line_list_price := nvl(l_list_price,0)+l_new_list_price;
517                      End if;
518                    IF (l_debug = 'Y') THEN
519                       my_debug('1330 : new amount on header'||l_chr_rec.estimated_amount, 1);
520                       my_debug('1340 : new list price on header'||l_chr_rec.total_line_list_price, 1);
521                    END IF;
522 
523                    IF (l_debug = 'Y') THEN
524                       my_debug('1350 : Before calling update contract header', 1);
525                    END IF;
526                    okc_contract_pub.update_contract_header (
527 	                    p_api_version => 1,
528 	                    p_init_msg_list => OKC_API.G_FALSE,
529 	                    x_return_status => l_return_status,
530 	                    x_msg_count => x_msg_count,
531 	                    x_msg_data => x_msg_data,
532 		              -- p_restricted_update => okc_api.g_true,
533 	                    p_chrv_rec => l_chr_rec,
534 	                    x_chrv_rec => x_chr_rec);
535                    IF (l_debug = 'Y') THEN
536                       my_debug('1355 : after calling update contract header status :'||l_return_status, 1);
537                    END IF;
538 
539                     IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
540                      RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
541                     ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
542                      RAISE OKC_API.G_EXCEPTION_ERROR;
543                     END IF;
544 
545                    Exception
546                      When no_data_found then
547                       IF (l_debug = 'Y') THEN
548                          my_debug('1360 : no data found This is not possible. some error', 1);
549                       END IF;
550                        null;
551                  End;
552                 End if; -- p_lowest_level=-2
553      End if;-- px_lowest_level <0
554      IF (l_debug = 'Y') THEN
555         my_debug('1365 : before calling update contract line, count :'||l_cle_tbl.count, 1);
556      END IF;
557 
558      okc_contract_pub.update_contract_line (
559 	      p_api_version => 1,
560 	      p_init_msg_list => OKC_API.G_FALSE,
561 	      x_return_status => l_return_status,
562 	      x_msg_count => x_msg_count,
563 	      x_msg_data => x_msg_data,
564 		 -- p_restricted_update => okc_api.g_true,
565 	      p_clev_tbl => l_cle_tbl,
566 	      x_clev_tbl => x_cle_tbl);
567      IF (l_debug = 'Y') THEN
568         my_debug('1366 : after calling update contract line status :'||l_return_status, 1);
569      END IF;
570 
571      IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
572            RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
573      ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
574            RAISE OKC_API.G_EXCEPTION_ERROR;
575      END IF;
576 
577      -- update header level adjustments with the new adjusted value. Right now we
578      -- just have % adjustments on header and that also in bucket 1 only
579      -- If this changes, then revisit this code
580      select id,operand,arithmetic_operator,object_version_number,adjusted_amount
581        bulk collect into l_pat_id_tbl,l_operand_tbl,l_operator_tbl,l_obj_tbl,l_value_tbl
582        from OKC_PRICE_ADJUSTMENTS
583        where chr_id=p_chr_id and cle_id is null;
584        IF (l_debug = 'Y') THEN
585           my_debug('1370 : header adjustments select rowcount'||SQL%ROWCOUNT, 1);
586        END IF;
587        If l_pat_id_tbl.count > 0 then
588          i:=l_pat_id_tbl.first;
589          while i is not null LOOP
590             IF (l_debug = 'Y') THEN
591                my_debug('1371 : header adjustment id'||l_pat_id_tbl(i), 1);
592                my_debug('1372 : operand'||l_operand_tbl(i), 1);
593                my_debug('1373 : operator'||l_operator_tbl(i), 1);
594                my_debug('1374 : old adjusted value'||l_value_tbl(i), 1);
595             END IF;
596 
597             If l_operator_tbl(i)='%' then
598                     l_patv_tbl(i).ID                      := l_pat_id_tbl(i);
599                     l_patv_tbl(i).object_version_number   := l_obj_tbl(i);
600                     --  calculate the new adjusted value for this header adjustment
601                     l_patv_tbl(i).ADJUSTED_AMOUNT         := (l_operand_tbl(i)/100)*px_chr_list_price;
602                     If l_value_tbl(i) < 0 then
603                         l_patv_tbl(i).ADJUSTED_AMOUNT         :=l_patv_tbl(i).ADJUSTED_AMOUNT * (-1);
604                     end if;
605                 IF (l_debug = 'Y') THEN
606                    my_debug('1374 : adjusted value'||l_patv_tbl(i).ADJUSTED_AMOUNT, 1);
607                 END IF;
608 
609             End If;
610             i:=l_pat_id_tbl.next(i);
611          End loop;
612           IF (l_debug = 'Y') THEN
613              my_debug('1378 : Before calling update price adjustment '||l_return_status, 1);
614           END IF;
615 
616           OKC_PRICE_ADJUSTMENT_PUB.update_price_adjustment(
617                     p_api_version      => p_api_version,
618                     x_return_status    => l_return_status ,
619                     x_msg_count        => x_msg_count,
620                     x_msg_data         => x_msg_data,
621                     p_patv_tbl         => l_patv_tbl,
622                     x_patv_tbl         => lx_patv_tbl );
623           IF (l_debug = 'Y') THEN
624              my_debug('1379 : after calling update price adjustment '||l_return_status, 1);
625           END IF;
626           --since adjsuted value column is just fyi, we would not want to rollback just because it returned some
627           --error. only if it is unexpected error we rollback
628           IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
629               RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
630           END IF;
631        End If;-- l_pat_id_tbl.count>0
632        px_cle_amt := x_cle_amt;
633        IF (l_debug = 'Y') THEN
634           my_debug('1379 : cle amount returned:'||px_cle_amt, 1);
635        END IF;
636 
637        IF (l_debug = 'Y') THEN
638           my_debug('1380 : p_commit :'||p_commit, 1);
639        END IF;
640 
641      If p_commit = OKC_API.G_TRUE then
642         Commit work;
643      End If;
644      IF (l_debug = 'Y') THEN
645         my_debug('1390:--------------Priced line tbl returned from update line price---------------');
646      END IF;
647 I := x_cle_price_tbl.FIRST;
648 IF I IS NOT NULL THEN
649  LOOP
650 
651 
652                       IF (l_debug = 'Y') THEN
653                          my_debug(' 1400: pi_bpi:'||x_cle_price_tbl(i).pi_bpi,1);
654                          my_debug(' 1410:ID :'||x_cle_price_tbl(i).ID ,1);
655                          my_debug(' 1420:UOM :'||x_cle_price_tbl(i).UOM_CODE,1 );
656                          my_debug(' 1430:LINE_NUM:'||x_cle_price_tbl(i).LINE_NUM,1 );
657                          my_debug(' 1440:LIST_PRICE :'|| x_cle_price_tbl(i).LIST_PRICE ,1);
658                          my_debug(' 1450:UNIT_PRICE:'||x_cle_price_tbl(i).UNIT_PRICE ,1);
659                          my_debug(' 1460:NEGOTIATED_AMT :'||x_cle_price_tbl(i).NEGOTIATED_AMT,1 );
660                          my_debug(' 1470:PRICELIST_ID :'||x_cle_price_tbl(i).PRICELIST_ID ,1);
661                          my_debug(' 1480: RET_CODE :'||x_cle_price_tbl(i).RET_CODE,1);
662                          my_debug(' 1490: qty :'||x_cle_price_tbl(i).qty ,1);
663                          my_debug(' 1500: RET_STS :'||x_cle_price_tbl(i).RET_STS ,1);
664                       END IF;
665   EXIT WHEN I =x_cle_price_tbl.LAST;
666   I := x_cle_price_tbl.NEXT(I);
667    END LOOP;
668 END IF;
669     IF (l_debug = 'Y') THEN
670        my_debug(' 1510: Header Net price :'||px_chr_net_price ,1);
671        my_debug(' 1515: Header List price :'||px_chr_list_price ,1);
672     END IF;
673     OKC_API.END_ACTIVITY(x_msg_count, x_msg_data);
674 
675     IF (l_debug = 'Y') THEN
676        my_debug('1600 : Exiting Update_line_PRICE', 2);
677     END IF;
678     IF (l_debug = 'Y') THEN
679        okc_debug.Reset_Indentation;
680     END IF;
681     EXCEPTION
682           WHEN OKC_API.G_EXCEPTION_ERROR THEN
683               x_return_status := OKC_API.HANDLE_EXCEPTIONS
684                        (l_api_name,
685                         G_PKG_NAME,
686                        'OKC_API.G_RET_STS_ERROR',
687                         x_msg_count,
688                         x_msg_data,
689                         '_PROCESS');
690                 IF (l_debug = 'Y') THEN
691                    my_debug('1700 : Exiting Update_line_PRICE', 4);
692                 END IF;
693                 IF (l_debug = 'Y') THEN
694                    okc_debug.Reset_Indentation;
695                 END IF;
696 
697          WHEN OKC_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
698               x_return_status := OKC_API.HANDLE_EXCEPTIONS
699                        (l_api_name,
700                         G_PKG_NAME,
701                        'OKC_API.G_RET_STS_UNEXP_ERROR',
702                         x_msg_count,
703                         x_msg_data,
704                         '_PROCESS');
705                 IF (l_debug = 'Y') THEN
706                    my_debug('1800 : Exiting Update_line_PRICE', 4);
707                 END IF;
708                 IF (l_debug = 'Y') THEN
709                    okc_debug.Reset_Indentation;
710                 END IF;
711 
712          WHEN OTHERS THEN
713               OKC_API.set_message(p_app_name      => g_app_name,
714                                  p_msg_name      => g_unexpected_error,
715                                  p_token1        => g_sqlcode_token,
716                                  p_token1_value  => sqlcode,
717                                  p_token2        => g_sqlerrm_token,
718                                  p_token2_value  => sqlerrm);
719             x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
720             IF (l_debug = 'Y') THEN
721                my_debug('1900 : Exiting Update_line_PRICE', 4);
722             END IF;
723             IF (l_debug = 'Y') THEN
724                okc_debug.Reset_Indentation;
725             END IF;
726 
727  END Update_line_price;
728 
729 
730  /*****************************************************************************/
731 /*****************************************************************************
732   commenting out nocopy as this check has been moved to new procedure
733   OKC_QA_PRICE_PVT.check_covered_line_qty  (Bug 2503412)
734 
735 
736 -------------------------------------------------------------------------------
737 -- Procedure:       validate_covered_line_qty
738 -- Version:         1.0
739 -- Purpose:         check to ensure that the quantity of a (sub) line of linestyle 'covered line' matches
740 --                  that of the (top) line to which it points.
741 -- In Parameters:   p_cle_id        the (sub) line of linestyle 'covered line'
742 --
743 
744 -- Out Parameters:  x_return_status
745 --
746 -- Comments:       This procedure is to be called only by QA
747 
748 PROCEDURE validate_covered_line_qty ( p_chr_id             IN  okc_k_headers_b.ID%TYPE,
749                                       p_cle_id             IN  okc_k_lines_b.ID%TYPE,
750                                       p_l_id_tbl           IN  num_tbl_type,
751                                       p_l_cle_id_tbl       IN  num_tbl_type,
752                                       p_l_line_number_tbl  IN  char_tbl_type,
753                                       x_return_status      OUT NOCOPY VARCHAR2
754         	                    ) IS
755 
756 
757    --gets quantity of (sub) line of linestyle 'covered line'
758    --also gets the id (object1_id1) of the parent line which is being pointed to
759    --NOTE: validate_covered_line_qty is to be called ONLY for (sub) lines with lse_id = 41 as we support only
760    --      this particular linestyle for 'OKX_COVLINE' object code
761    CURSOR c_get_quantity1 (b_cle_id NUMBER) is
762    SELECT object1_id1, number_of_items qty
763    FROM   okc_k_items
764    WHERE  cle_id = b_cle_id
765    AND    dnz_chr_id = p_chr_id
766    AND    jtot_object1_code = 'OKX_COVLINE';
767 
768 
769 
770    --gets the quantity of the parent non-service item line being pointed to
771    CURSOR c_get_quantity2 (b_cle_id NUMBER) is
772    SELECT number_of_items qty
773    FROM   okc_k_items
774    WHERE  cle_id = b_cle_id
775    AND    dnz_chr_id = p_chr_id;
776 
777 
778    l_return_status     VARCHAR2(1);
779 
780    l_qty1                NUMBER := OKC_API.G_MISS_NUM;
781    l_qty2                NUMBER := OKC_API.G_MISS_NUM;
782    l_parent_cle_id       OKC_K_LINES_B.ID%TYPE;
783    l_line_number         OKC_K_LINES_B.LINE_NUMBER%TYPE := '0';
784    l_parent_line_number  OKC_K_LINES_B.LINE_NUMBER%TYPE := '0';
785    i                     PLS_INTEGER := 0;
786    l_top_line_id         NUMBER := OKC_API.G_MISS_NUM;
787 
788 BEGIN
789    x_return_status := okc_api.g_ret_sts_success;
790    IF (l_debug = 'Y') THEN
791       my_debug('Start : okc_price_pvt.validate_covered_line_qty ',3);
792    END IF;
793    /* Note: we already perform validation to ensure that the contract is for intent of sale and for OKC, OKO
794       in OKC_QA_PRICE_PVT.Check_Price
795 
796 
797    /* Get quantity of (sub) line of linestyle 'covered line'
798    IF (l_debug = 'Y') THEN
799       my_debug('Get quantity of line with id: ' || p_cle_id, 5);
800       my_debug('Get quantity of line p_cle_id = ' || p_cle_id || 'with jtot_object=''OKX_COVLINE'' and lse_id=41',5);
801    END IF;
802    IF c_get_quantity1%ISOPEN THEN
803       CLOSE c_get_quantity1;
804    END IF;
805    OPEN c_get_quantity1 (b_cle_id => p_cle_id);
806    FETCH c_get_quantity1 INTO l_parent_cle_id, l_qty1;
807    CLOSE c_get_quantity1;
808    IF (l_debug = 'Y') THEN
809       my_debug('l_qty1: ' || l_qty1, 5);
810    END IF;
811 
812 
813    /* Get quantity of parent (top) line being pointed to
814    IF (l_debug = 'Y') THEN
815       my_debug('Get quantity of parent (top) line being pointed to: '||l_parent_cle_id, 5);
816    END IF;
817    IF c_get_quantity2%ISOPEN THEN
818       CLOSE c_get_quantity2;
819    END IF;
820    OPEN c_get_quantity2 (b_cle_id => l_parent_cle_id);
821    FETCH c_get_quantity2 INTO l_qty2;
822    CLOSE c_get_quantity2;
823    IF (l_debug = 'Y') THEN
824       my_debug('l_qty2: ' || l_qty2, 5);
825    END IF;
826 
827 
828 
829    IF l_qty1 <> OKC_API.G_MISS_NUM AND l_qty2 <> OKC_API.G_MISS_NUM AND l_qty1 <> l_qty2 THEN
830           IF (l_debug = 'Y') THEN
831              my_debug('l_qty1 and l_qty2 are not the same so setting error message on stack...',5);
832           END IF;
833 
834          /* get the line number of the immediate (top) line
835           i:= p_l_id_tbl.first;
836           WHILE i IS NOT NULL LOOP
837               IF p_l_id_tbl(i) = p_cle_id THEN
838                  l_top_line_id := p_l_cle_id_tbl(i);
839                  EXIT;
840               END IF;
841               i := p_l_id_tbl.next(i);
842           END LOOP;
843 
844           i:= p_l_id_tbl.first;
845           WHILE i IS NOT NULL LOOP
846               IF p_l_id_tbl(i) = l_top_line_id THEN
847                  l_line_number := p_l_line_number_tbl(i);
848                  EXIT;
849               END IF;
850               i := p_l_id_tbl.next(i);
851           END LOOP;
852 
853 
854           --now concatenate it with the line number of the (sub) line of linestyle 'covered line'
855           i:= p_l_id_tbl.first;
856           WHILE i IS NOT NULL LOOP
857               IF p_l_id_tbl(i) = p_cle_id THEN
858                  l_line_number := l_line_number || '.' || p_l_line_number_tbl(i);
859                  EXIT;
860               END IF;
861               i := p_l_id_tbl.next(i);
862           END LOOP;
863 
864          /* finally get the line number of the parent (top) line which is being pointed to
865           i:= p_l_id_tbl.first;
866           WHILE i IS NOT NULL LOOP
867               IF p_l_id_tbl(i) = l_parent_cle_id THEN
868                  l_parent_line_number := p_l_line_number_tbl(i);
869                  EXIT;
870               END IF;
871               i := p_l_id_tbl.next(i);
872           END LOOP;
873 
874 
875           OKC_API.set_message(p_app_name      => G_APP_NAME,
876                               p_msg_name      => 'OKC_QA_MISMATCH_QTY',
877                               p_token1        => 'LNUMB1',
878                               p_token1_value  =>  l_line_number,
879                               p_token2        => 'LNUMB2',
880                               p_token2_value  =>  l_parent_line_number);
881            IF (l_debug = 'Y') THEN
882               my_debug('Covered line number ' || l_line_number || 'and id: ' || p_cle_id || 'serviceable product have a quantity mismatch.',5);
883               my_debug('l_qty1: ' || l_qty1,5);
884               my_debug('l_qty2: ' || l_qty2,5);
885            END IF;
886            x_return_status := OKC_API.G_RET_STS_ERROR;
887 
888    END IF;
889 
890 
891    If x_return_status <>  OKC_API.G_RET_STS_ERROR then
892       IF (l_debug = 'Y') THEN
893          my_debug('passed okc_price_pvt.validate_covered_line_qty');
894       END IF;
895    End if;
896 
897    IF (l_debug = 'Y') THEN
898       my_debug('End : okc_price_pvt.validate_covered_line_qty ',3);
899    END IF;
900 
901 EXCEPTION
902 WHEN OTHERS THEN
903    IF (l_debug = 'Y') THEN
904       my_debug('Error : unexpected error in okc_price_pvt.validate_covered_line_qty ',3);
905       my_debug('Error : '|| sqlerrm, 3);
906    END IF;
907 
908    IF c_get_quantity1%ISOPEN THEN
909       CLOSE c_get_quantity1;
910    END IF;
911    IF c_get_quantity2%ISOPEN THEN
912       CLOSE c_get_quantity2;
913    END IF;
914    OKC_API.set_message(G_APP_NAME,
915                             G_UNEXPECTED_ERROR,
916                             G_SQLCODE_TOKEN,
917                             SQLCODE,
918                             G_SQLERRM_TOKEN,
919                             SQLERRM);
920     x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
921 END;
922 
923  *****************************************************************************
924  *****************************************************************************/
925 
926 
927 
928 
929  --------------------------------------------------------------------------
930 -- Update_Contract_price
931 -- This procedure will calculate the price for all the Priced lines in a contract
932 -- while calculating whether header level adjustments are to be considrerd
933 -- or not will be taken care of by px_control_rec.p_level (possible values 'L','H','QA')
934 -- p_chr_id - id of the header
935 -- x_chr_net_price - estimated amount on header
936 
937 ----------------------------------------------------------------------------
938 PROCEDURE Update_CONTRACT_price(
939           p_api_version                 IN          NUMBER,
940           p_init_msg_list               IN          VARCHAR2 ,
941           p_commit                      IN          VARCHAR2 ,
942           p_CHR_ID                      IN          NUMBER,
943           px_Control_Rec			    IN  OUT NOCOPY     OKC_CONTROL_REC_TYPE,
944           x_CLE_PRICE_TBL		        OUT  NOCOPY CLE_PRICE_TBL_TYPE,
945           x_chr_net_price               OUT  NOCOPY NUMBER,
946           x_return_status               OUT  NOCOPY VARCHAR2,
947           x_msg_count                   OUT  NOCOPY NUMBER,
948           x_msg_data                    OUT  NOCOPY VARCHAR2) IS
949     l_return_status varchar2(1) :=OKC_API.G_RET_STS_SUCCESS;
950 
951     l_api_name constant VARCHAR2(30) := 'Update_Contract_PRICE';
952     l_cle_id_tbl num_tbl_type;
953     i pls_integer :=0;
954     j pls_integer :=0;
955     l_ind pls_integer :=0;
956 
957     l_lvl_tbl num_tbl_type;
958     l_id_tbl num_tbl_type;
959     l_obj_tbl num_tbl_type;
960     l_p_tbl   flag_tab_type ;
961     l_bpi_tbl flag_tab_type ;
962     l_top_model_tbl num_tbl_type;
963 
964     l_line_number_tbl char_tbl_type;
965     l_lse_id_tbl num_tbl_type;
966     ----l_qa_covered_line_qty_mismatch boolean := FALSE;
967 
968 
969     l_obj number :=1;
970     l_amt number :=0;
971     l_list_price number :=0;
972 
973     l_cle_id number;
974     l_rowlevel number :=0;
975     l_p_found boolean :=false;
976     l_chr_rec  okc_contract_pub.chrv_rec_type;
977     x_chr_rec  okc_contract_pub.chrv_rec_type;
978     l_cle_tbl  okc_contract_pub.clev_tbl_type;
979     x_cle_tbl  okc_contract_pub.clev_tbl_type;
980 
981     l_req_line_tbl              QP_PREQ_GRP.LINE_TBL_TYPE;
982     l_req_line_qual_tbl         QP_PREQ_GRP.QUAL_TBL_TYPE;
983     l_req_line_attr_tbl         QP_PREQ_GRP.LINE_ATTR_TBL_TYPE;
984     l_req_line_detail_tbl       QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE;
985     l_req_line_detail_qual_tbl  QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE;
986     l_req_line_detail_attr_tbl  QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE;
987     l_req_related_line_tbl      QP_PREQ_GRP.RELATED_LINES_TBL_TYPE;
988 BEGIN
989     IF (l_debug = 'Y') THEN
990        okc_debug.Set_Indentation('Update_CONTRACT_price');
991     END IF;
992     IF (l_debug = 'Y') THEN
993        my_debug('2000 : Entering Update_CONTRACT_price', 2);
994     END IF;
995 
996     x_return_status := OKC_API.G_RET_STS_SUCCESS;
997 
998     l_return_status := OKC_API.START_ACTIVITY(l_api_name,
999                                               p_init_msg_list,
1000                                               '_PROCESS',
1001                                                x_return_status);
1002     IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
1003                     raise OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
1004     ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
1005                     raise OKC_API.G_EXCEPTION_ERROR;
1006     END IF;
1007 
1008     Set_control_rec(px_control_rec);
1009     if px_control_rec.p_calc_flag = 'S' then
1010        OKC_API.set_message(p_app_name      => g_app_name,
1011                                  p_msg_name      => 'OKC_INVALID_CALC_FLAG',
1012                                  p_token1        => 'calc_flag',
1013                                  p_token1_value  => 'S');
1014 
1015         RAISE OKC_API.G_EXCEPTION_ERROR;
1016     End if;
1017 
1018 
1019     IF px_control_rec.p_level = 'QA' THEN
1020        g_qa_mode := 'Y';
1021     ELSE
1022        g_qa_mode := 'N';
1023     END IF;
1024 
1025     ---???? how to control only header adjustments get applied.
1026     --px_control_rec.p_level:= 'L';
1027     --????  how to control that only header adj applied to passed in lines ask jay
1028       select level,cle_id,id,object_version_number,price_level_ind,price_basis_yn,config_top_model_line_id,
1029              line_number, lse_id
1030       bulk collect into l_lvl_tbl,l_cle_id_tbl,l_id_tbl,l_obj_tbl,l_p_tbl,l_bpi_tbl,l_top_model_tbl,
1031                         l_line_number_tbl, l_lse_id_tbl
1032       from OKC_K_LINES_B
1033       connect by prior id = cle_id
1034       start with chr_id = p_chr_id;
1035       IF (l_debug = 'Y') THEN
1036          my_debug('2100 : select rowcount'||SQL%ROWCOUNT, 1);
1037       END IF;
1038 
1039     i:= l_id_tbl.first;
1040     l_p_found := false;
1041     l_rowlevel :=0;
1042     -- This loop will take out all the first occurrences of priced lines(there can be more
1043     -- if recursive) and all occurrneces in case of config lines
1044     IF (l_debug = 'Y') THEN
1045        my_debug('2102 :starting out nocopy loop to filter priced lines', 1);
1046     END IF;
1047 -- this might not work if config item below non config item which I think is not possible right now
1048     while i is not null loop
1049 
1050         /*****************************************************************
1051            commenting out nocopy as this check has been moved to new procedure
1052            OKC_QA_PRICE_PVT.check_covered_line_qty  (Bug 2503412)
1053 
1054         IF px_control_rec.p_level = 'QA' AND l_lse_id_tbl(i) = 41 Then
1055            /** if this procedure is being called from QA i.e. OKC_QA_PRICE_PVT.Check_Price then
1056                perform validation to ensure that the quantity of a (sub) line of linestyle 'covered line'
1057                matches  that of the (top) line to which it points.
1058            validate_covered_line_qty (p_chr_id             =>  p_CHR_ID,
1059                                       p_cle_id             =>  l_id_tbl(i),
1060                                       p_l_id_tbl           =>  l_id_tbl,
1061                                       p_l_cle_id_tbl       =>  l_cle_id_tbl,
1062                                       p_l_line_number_tbl  =>  l_line_number_tbl,
1063                                       x_return_status      =>  l_return_status
1064                                      );
1065 
1066            IF l_return_status = OKC_API.G_RET_STS_ERROR THEN
1067               --we want QA to eventually pick up the error messages on the stack
1068               l_qa_covered_line_qty_mismatch := TRUE;
1069            End If;
1070 
1071            IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
1072               RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
1073            End If;
1074         End If;
1075         ******************************************************************/
1076 
1077         If l_lvl_tbl(i) = 1 or l_lvl_tbl(i)<= l_rowlevel then
1078             l_p_found :=false;
1079             l_rowlevel:=l_lvl_tbl(i);
1080         End if;
1081         If l_p_tbl(i)='Y'  and l_p_found=false
1082         AND ((l_top_model_tbl(i) is null) OR
1083               (l_top_model_tbl(i) is not null and l_top_model_tbl(i) <> l_id_tbl(i)))
1084         then
1085           IF (l_debug = 'Y') THEN
1086              my_debug('2109 : Priced Lines returned'||l_id_tbl(i), 1);
1087           END IF;
1088            x_cle_price_tbl(i).id:=l_id_tbl(i);
1089            If l_top_model_tbl(i) is null then
1090               l_p_found := true;
1091               l_rowlevel := l_lvl_tbl(i);
1092            END IF;
1093         ELSE
1094            l_p_tbl(i):='N';
1095         End If;
1096         IF (l_debug = 'Y') THEN
1097            my_debug('2110 : line id'||l_id_tbl(i), 1);
1098            my_debug('2111 : priced flag'||l_p_tbl(i), 1);
1099            my_debug('2112 : top model line'||l_top_model_tbl(i), 1);
1100            my_debug('2113 : row level'||l_lvl_tbl(i), 1);
1101         END IF;
1102         If l_p_found then
1103           IF (l_debug = 'Y') THEN
1104              my_debug('2114 : priced already found', 1);
1105           END IF;
1106         Else
1107           IF (l_debug = 'Y') THEN
1108              my_debug('2115 : priced not found', 1);
1109           END IF;
1110         End if;
1111         IF (l_debug = 'Y') THEN
1112            my_debug('2116 : saved rowlevel'||l_rowlevel, 1);
1113         END IF;
1114 
1115         i:=l_id_tbl.next(i);
1116    END loop;
1117 
1118    IF (l_debug = 'Y') THEN
1119       my_debug('2120 : Before call to Calculate price priced count'||x_cle_price_tbl.count, 1);
1120    END IF;
1121 
1122     CALCULATE_price(p_api_version                => p_api_version,
1123                     p_CHR_ID                     => p_chr_id,
1124                     p_Control_Rec			     => px_control_rec,
1125                     px_req_line_tbl              => l_req_line_tbl,
1126                     px_Req_qual_tbl              => l_req_line_qual_tbl,
1127                     px_Req_line_attr_tbl         => l_req_line_attr_tbl,
1128                     px_Req_LINE_DETAIL_tbl       => l_req_line_detail_tbl,
1129                     px_Req_LINE_DETAIL_qual_tbl  => l_req_line_detail_qual_tbl,
1130                     px_Req_LINE_DETAIL_attr_tbl  => l_req_line_detail_attr_tbl,
1131                     px_Req_RELATED_LINE_TBL      => l_req_related_line_tbl,
1132                     px_CLE_PRICE_TBL		     => x_CLE_PRICE_TBL,
1133                     x_return_status              => x_return_status,
1134                     x_msg_count                  => x_msg_count,
1135                     x_msg_data                   => x_msg_data);
1136       IF (l_debug = 'Y') THEN
1137          my_debug('2130 : After call to Calculate price return status'||x_return_status, 1);
1138       END IF;
1139 
1140      IF x_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
1141                    RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
1142     --In case of header any error means total rollback
1143      ELSIF x_return_status = OKC_API.G_RET_STS_ERROR THEN
1144                   RAISE OKC_API.G_EXCEPTION_ERROR;
1145      END IF;
1146     IF (l_debug = 'Y') THEN
1147        my_debug('2140 : After call to Calculate price Priced Count'||x_cle_price_tbl.count, 1);
1148     END IF;
1149 
1150      -- go on even if error
1151   -- do rollups
1152      Begin
1153         Select object_version_number,estimated_amount,total_line_list_price
1154         into l_obj,l_amt,l_list_price
1155         From okc_k_headers_b
1156         where id=p_chr_id;
1157         l_chr_rec.id := p_chr_id;
1158         l_chr_rec.object_version_number := l_obj;
1159         l_chr_rec.estimated_amount := null;
1160         l_chr_rec.total_line_list_price := null;
1161         l_chr_rec.pricing_date := g_hdr_pricing_date;
1162 
1163         IF (l_debug = 'Y') THEN
1164            my_debug('2200 : header select rowcount should be 1: '||SQL%ROWCOUNT, 1);
1165         END IF;
1166 
1167       Exception
1168          When no_data_found then
1169                             IF (l_debug = 'Y') THEN
1170                                my_debug('2210 : no data found. Not possible code error', 1);
1171                             END IF;
1172 
1173                       null;
1174      End;
1175       j:=0;
1176        --for all the priced lines , do the following
1177       i:= x_cle_price_tbl.first;
1178       while i is not null loop
1179         IF (l_debug = 'Y') THEN
1180            my_debug('2220 : In while loop I is '||i, 1);
1181            my_debug('2230 : Return status'||x_cle_price_tbl(i).ret_sts, 1);
1182            my_debug('2240 : Line Id'||x_cle_price_tbl(i).id, 1);
1183         END IF;
1184         --if the priced line is P(and not BPI) and the return status is not unexpected error
1185         If  x_cle_price_tbl(i).pi_bpi ='P' and x_cle_price_tbl(i).ret_sts <> 'U' then --??????ret_sts='S'
1186           -- make cle buffer equal to priced id
1187 
1188           l_cle_id := x_cle_price_tbl(i).id;
1189           -- start from the last in array as the parents of the priced line will be prior to it in array\
1190           l_ind := l_id_tbl.last;
1191           while l_ind is not null loop
1192                   IF (l_debug = 'Y') THEN
1193                      my_debug('2250 : In while l_cle_id'||l_cle_id, 1);
1194                      my_debug('2260 : In while l_id'||l_id_tbl(l_ind), 1);
1195                      my_debug('2270 : In while bpi'||l_bpi_tbl(l_ind), 1);
1196                   END IF;
1197             -- if the cle buffer id found
1198              If (l_id_tbl(l_ind)=l_cle_id ) then --#1
1199                 If  (nvl(l_bpi_tbl(l_ind),'N') <> 'Y' )then --#2
1200                     IF (l_debug = 'Y') THEN
1201                        my_debug('2280 : In NOT BPI IF:', 1);
1202                     END IF;
1203                     -- create a record to update the okc_k_lines
1204 
1205                    l_cle_tbl(l_ind).id :=l_id_tbl(l_ind);
1206                     IF (l_debug = 'Y') THEN
1207                        my_debug('2290 : loop for line id:'||l_cle_tbl(l_ind).id, 1);
1208                     END IF;
1209 
1210                    l_cle_tbl(l_ind).object_version_number :=l_obj_tbl(l_ind);
1211                    If l_cle_tbl(l_ind).price_negotiated = OKC_API.G_MISS_NUM then
1212                        l_cle_tbl(l_ind).price_negotiated := null;
1213                    End if;
1214                    If l_cle_tbl(l_ind).line_list_price = OKC_API.G_MISS_NUM then
1215                        l_cle_tbl(l_ind).line_list_price := null;
1216                    End if;
1217                     -- If the priced line had some negotiated amount over it
1218                     IF x_cle_price_tbl(i).negotiated_amt is not null then
1219                        l_cle_tbl(l_ind).price_negotiated :=
1220                          nvl(l_cle_tbl(l_ind).price_negotiated,0) + x_cle_price_tbl(i).negotiated_amt;
1221                     End If;
1222                     IF (l_debug = 'Y') THEN
1223                        my_debug('2300 : negotiated amount on line:'||l_cle_tbl(l_ind).price_negotiated, 1);
1224                     END IF;
1225                       -- if the priced line had some list price over it
1226                     IF  x_cle_price_tbl(i).list_price is not null  then
1227                       l_cle_tbl(l_ind).line_list_price :=
1228                          nvl(l_cle_tbl(l_ind).line_list_price,0) + x_cle_price_tbl(i).list_price;
1229                     END IF;
1230                     IF (l_debug = 'Y') THEN
1231                        my_debug('2310 : list price  on line:'||l_cle_tbl(l_ind).line_list_price, 1);
1232                     END IF;
1233 
1234 
1235                    If l_id_tbl(l_ind) = x_cle_price_tbl(i).id then -- that means priced line #3
1236                       If x_cle_price_tbl(i).PRICELIST_ID is not null
1237                             and x_cle_price_tbl(i).PRICELIST_ID<> OKC_API.G_MISS_NUM then
1238                          l_cle_tbl(l_ind).price_list_id :=x_cle_price_tbl(i).PRICELIST_ID;
1239                          l_cle_tbl(l_ind).pricing_date :=x_cle_price_tbl(i).pricing_date;
1240                          l_cle_tbl(l_ind).price_list_line_id :=x_cle_price_tbl(i).list_line_id;
1241                          IF (l_debug = 'Y') THEN
1242                             my_debug('2320 : price list found  price list id:'||l_cle_tbl(l_ind).price_list_id, 1);
1243                             my_debug('2330 : price list found  price list line id:'||l_cle_tbl(l_ind).price_list_line_id, 1);
1244                          END IF;
1245 
1246                       End If;
1247                   ---???? nothing regarding rolling up of updated neg price in contract apis. ask john
1248                     -- l_cle_tbl(l_ind).line_list_price := x_cle_price_tbl(i).list_price;
1249                      l_cle_tbl(l_ind).price_unit:= x_cle_price_tbl(i).unit_price;
1250                      IF (l_debug = 'Y') THEN
1251                         my_debug('2340 : unit price:'||l_cle_tbl(l_ind).price_unit, 1);
1252                      END IF;
1253                    END IF; --#3
1254                END IF; --#2
1255                -- if we have reached the topmost line
1256                If l_lvl_tbl(l_ind)=1 then
1257                   If x_cle_price_tbl(i).negotiated_amt is not null then
1258                      l_chr_rec.estimated_amount := nvl(l_chr_rec.estimated_amount,0)+x_cle_price_tbl(i).negotiated_amt;
1259                   End If;
1260                   If x_cle_price_tbl(i).list_price is not null then
1261                      l_chr_rec.total_line_list_price := nvl(l_chr_rec.total_line_list_price,0)+x_cle_price_tbl(i).list_price;
1262                   End if;
1263                  IF (l_debug = 'Y') THEN
1264                     my_debug('2350 : priced lines negotiated amount:'||x_cle_price_tbl(i).negotiated_amt, 1);
1265                     my_debug('2360 : priced lines list price:'||x_cle_price_tbl(i).list_price, 1);
1266                     my_debug('2370 : new header estimated amount:'||l_chr_rec.estimated_amount, 1);
1267                     my_debug('2380 : new header list price:'||l_chr_rec.total_line_list_price, 1);
1268                  END IF;
1269 
1270                   exit; -- we have reached the top. so no point going any further
1271                End If;
1272                -- if configurator line then rollup to top model line directly
1273                If l_top_model_tbl.exists(l_ind)  and  l_top_model_tbl(l_ind) is not null
1274                   and l_top_model_tbl(l_ind) <> l_id_tbl(l_ind) then
1275                   IF (l_debug = 'Y') THEN
1276                      my_debug('2390 : Top model line exists top model id is:'||l_top_model_tbl(l_ind), 1);
1277                   END IF;
1278                   l_cle_id := l_top_model_tbl(l_ind);
1279                Else
1280                   l_cle_id :=nvl(l_cle_id_tbl(l_ind),0);
1281                End If;
1282                  IF (l_debug = 'Y') THEN
1283                     my_debug('2392 : l_cle_id is:'||l_cle_id, 1);
1284                  END IF;
1285 
1286              END IF; --#1
1287             l_ind:=l_id_tbl.prior(l_ind);
1288           end loop;
1289           IF (l_debug = 'Y') THEN
1290              my_debug('2394 : loop ended l_ind:'||l_ind, 1);
1291           END IF;
1292 
1293         End If;
1294         i:=x_cle_price_tbl.next(i);
1295      END loop;
1296      -- do not pick up directly  from the summary line
1297      -- we might have to deduct BPI amount from that as we donot rollup
1298      -- amount on BPI. Also the amount there is after header discounts
1299      x_chr_net_price := l_chr_rec.estimated_amount;
1300      IF (l_debug = 'Y') THEN
1301         my_debug('2392 :Header amount '||x_chr_net_price, 1);
1302         my_debug('2394 :p_level '||px_control_rec.p_level, 1);
1303      END IF;
1304 
1305      If px_control_rec.p_level = 'H' then
1306          IF (l_debug = 'Y') THEN
1307             my_debug('2400 : Before calling update contract line', 1);
1308          END IF;
1309          okc_contract_pub.update_contract_line (
1310     	      p_api_version => 1,
1311     	      p_init_msg_list => OKC_API.G_FALSE,
1312     	      x_return_status => l_return_status,
1313     	      x_msg_count => x_msg_count,
1314     	      x_msg_data => x_msg_data,
1315     		 -- p_restricted_update => okc_api.g_true,
1316     	      p_clev_tbl => l_cle_tbl,
1317     	      x_clev_tbl => x_cle_tbl);
1318          IF (l_debug = 'Y') THEN
1319             my_debug('2410 : after calling update contract line status :'||l_return_status, 1);
1320          END IF;
1321 
1322          IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
1323                RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
1324          ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
1325                RAISE OKC_API.G_EXCEPTION_ERROR;
1326          END IF;
1327          IF (l_debug = 'Y') THEN
1328             my_debug('2420 : Before calling update contract header', 1);
1329          END IF;
1330           okc_contract_pub.update_contract_header (
1331     	                    p_api_version => 1,
1332     	                    p_init_msg_list => OKC_API.G_FALSE,
1333     	                    x_return_status => l_return_status,
1334     	                    x_msg_count => x_msg_count,
1335     	                    x_msg_data => x_msg_data,
1336     		              -- p_restricted_update => okc_api.g_true,
1337     	                    p_chrv_rec => l_chr_rec,
1338     	                    x_chrv_rec => x_chr_rec);
1339          IF (l_debug = 'Y') THEN
1340             my_debug('2430 : after calling update contract header status :'||l_return_status, 1);
1341          END IF;
1342 
1343           IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
1344                   RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
1345           ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
1346                   RAISE OKC_API.G_EXCEPTION_ERROR;
1347           END IF;
1348       End If; --p_level='H'
1349       IF (l_debug = 'Y') THEN
1350          my_debug('2440 : p_commit :'||p_commit, 1);
1351       END IF;
1352      If p_commit = OKC_API.G_TRUE then
1353         Commit work;
1354      End If;
1355      IF (l_debug = 'Y') THEN
1356         my_debug('2450:--------------Priced line tbl returned from update contract price---------------');
1357      END IF;
1358 I := x_cle_price_tbl.FIRST;
1359 IF I IS NOT NULL THEN
1360  LOOP
1361 
1362                       IF (l_debug = 'Y') THEN
1363                          my_debug(' 2460: pi_bpi:'||x_cle_price_tbl(i).pi_bpi,1);
1364                          my_debug(' 2470:ID :'||x_cle_price_tbl(i).ID ,1);
1365                          my_debug(' 2480:UOM :'||x_cle_price_tbl(i).UOM_CODE,1 );
1366                          my_debug(' 2490:LINE_NUM:'||x_cle_price_tbl(i).LINE_NUM,1 );
1367                          my_debug(' 2500:LIST_PRICE :'|| x_cle_price_tbl(i).LIST_PRICE ,1);
1368                          my_debug(' 2510:UNIT_PRICE:'||x_cle_price_tbl(i).UNIT_PRICE ,1);
1369                          my_debug(' 2520:NEGOTIATED_AMT :'||x_cle_price_tbl(i).NEGOTIATED_AMT,1 );
1370                          my_debug(' 2530:PRICELIST_ID :'||x_cle_price_tbl(i).PRICELIST_ID ,1);
1371                          my_debug(' 2540: RET_CODE :'||x_cle_price_tbl(i).RET_CODE,1);
1372                          my_debug(' 2550: qty :'||x_cle_price_tbl(i).qty ,1);
1373                          my_debug(' 2560: RET_STS :'||x_cle_price_tbl(i).RET_STS ,1);
1374                       END IF;
1375   EXIT WHEN I =x_cle_price_tbl.LAST;
1376   I := x_cle_price_tbl.NEXT(I);
1377    END LOOP;
1378 END IF;
1379 
1380   /***************************************************************************
1381     commenting out nocopy as this check has been moved to new procedure
1382     OKC_QA_PRICE_PVT.check_covered_line_qty  (Bug 2503412)
1383 
1384   If px_control_rec.p_level = 'QA' AND l_qa_covered_line_qty_mismatch = TRUE Then
1385      /** this means that validate_covered_line_qty() has put some error messages on the
1386          error stack which we now want QA to display in the QA results
1387      x_return_status := OKC_API.G_RET_STS_ERROR;
1388   End If;
1389   ****************************************************************************/
1390 
1391 
1392 
1393  OKC_API.END_ACTIVITY(x_msg_count, x_msg_data);
1394 
1395  IF (l_debug = 'Y') THEN
1396     my_debug('2600 : Exiting Update_Contract_price', 2);
1397  END IF;
1398  IF (l_debug = 'Y') THEN
1399     okc_debug.Reset_Indentation;
1400  END IF;
1401 
1402 
1403     EXCEPTION
1404           WHEN l_exception_stop then
1405                x_return_status := OKC_API.G_RET_STS_SUCCESS;
1406               IF (l_debug = 'Y') THEN
1407                  my_debug('2690 : Exiting Update_Contract_price', 4);
1408               END IF;
1409               IF (l_debug = 'Y') THEN
1410                  okc_debug.Reset_Indentation;
1411               END IF;
1412 
1413           WHEN OKC_API.G_EXCEPTION_ERROR THEN
1414               x_return_status := OKC_API.HANDLE_EXCEPTIONS
1415                        (l_api_name,
1416                         G_PKG_NAME,
1417                        'OKC_API.G_RET_STS_ERROR',
1418                         x_msg_count,
1419                         x_msg_data,
1420                         '_PROCESS');
1421            IF (l_debug = 'Y') THEN
1422               my_debug('2700 : Exiting Update_Contract_price', 4);
1423            END IF;
1424            IF (l_debug = 'Y') THEN
1425               okc_debug.Reset_Indentation;
1426            END IF;
1427 
1428          WHEN OKC_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
1429               x_return_status := OKC_API.HANDLE_EXCEPTIONS
1430                        (l_api_name,
1431                         G_PKG_NAME,
1432                        'OKC_API.G_RET_STS_UNEXP_ERROR',
1433                         x_msg_count,
1434                         x_msg_data,
1435                         '_PROCESS');
1436            IF (l_debug = 'Y') THEN
1437               my_debug('2800 : Exiting Update_Contract_price', 4);
1438            END IF;
1439            IF (l_debug = 'Y') THEN
1440               okc_debug.Reset_Indentation;
1441            END IF;
1442 
1443          WHEN OTHERS THEN
1444               OKC_API.set_message(p_app_name      => g_app_name,
1445                                  p_msg_name      => g_unexpected_error,
1446                                  p_token1        => g_sqlcode_token,
1447                                  p_token1_value  => sqlcode,
1448                                  p_token2        => g_sqlerrm_token,
1449                                  p_token2_value  => sqlerrm);
1450             x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
1451            IF (l_debug = 'Y') THEN
1452               my_debug('2900 : Exiting Update_Contract_price', 4);
1453            END IF;
1454            IF (l_debug = 'Y') THEN
1455               okc_debug.Reset_Indentation;
1456            END IF;
1457 
1458  END Update_Contract_price;
1459 
1460 --------------------Called from APIs------------------------------------------------
1461 --FUNCTION - GET_LSE_SOURCE_VALUE
1462 -- This function is used in mapping of attributes between QP and OKC lines
1463 -- The calls to this function will be made by QP Engine to get values for
1464 --various Qualifiers and Pricing Attributes
1465 -- p_lse_tbl - Global Table holding various OKX_SOURCES and their values for lse
1466 -- p_registered_source - The source for which value should be returned
1467 -- Returns the value for the p_registered_source
1468 ----------------------------------------------------------------------------
1469 FUNCTION Get_LSE_SOURCE_VALUE (
1470             p_lse_tbl            IN      global_lse_tbl_type,
1471             p_registered_source  IN      VARCHAR2)
1472 RETURN VARCHAR2 IS
1473      i NUMBER:=0;
1474 Begin
1475     IF (l_debug = 'Y') THEN
1476        okc_debug.Set_Indentation('Get_LSE_SOURCE_VALUE');
1477     END IF;
1478     IF (l_debug = 'Y') THEN
1479        my_debug('3000 : Entering Get_LSE_SOURCE_VALUE', 2);
1480     END IF;
1481 
1482             If p_lse_tbl.count>0 then
1483                  i:= p_lse_tbl.first;
1484                  LOOP
1485                     If p_lse_tbl(i).current_source = p_registered_source then
1486                             IF (l_debug = 'Y') THEN
1487                                my_debug('3300 : Exiting Get_LSE_SOURCE_VALUE', 2);
1488                             END IF;
1489                             IF (l_debug = 'Y') THEN
1490                                okc_debug.Reset_Indentation;
1491                             END IF;
1492 
1493                             return   p_lse_tbl(i).source_value;
1494 
1495                     End If;
1496                     Exit When i=p_lse_tbl.last;
1497                     i:= p_lse_tbl.next(i);
1498                 End Loop;
1499             End If; -- p_lse_type.count
1500            IF (l_debug = 'Y') THEN
1501               my_debug('3400 : Exiting Get_LSE_SOURCE_VALUE', 2);
1502            END IF;
1503            IF (l_debug = 'Y') THEN
1504               okc_debug.Reset_Indentation;
1505            END IF;
1506 
1507            return null;
1508 
1509            EXCEPTION
1510            WHEN OTHERS then
1511              IF (l_debug = 'Y') THEN
1512                 my_debug('3450 :should not have come current source:'|| p_lse_tbl(i).current_source,1);
1513                 my_debug('3460 :sql code:'||sqlcode,1);
1514                 my_debug('3470 :msg:'||sqlerrm,1);
1515                 my_debug('3500 : Exiting Get_LSE_SOURCE_VALUE', 4);
1516              END IF;
1517              IF (l_debug = 'Y') THEN
1518                 okc_debug.Reset_Indentation;
1519              END IF;
1520 
1521               RETURN NULL;
1522 END Get_LSE_SOURCE_VALUE;
1523 
1524 -----------------------------------------------------------------------------
1525 --FUNCTION - GET_RUL_SOURCE_VALUE
1526 -- This function is used in mapping of attributes between QP and OKC rules
1527 -- The calls to this function will be made by QP Engine to get values for
1528 --various Qualifiers and Pricing Attributes
1529 -- p_rul_tbl - Global Table holding various OKX_SOURCES and their values for rules
1530 -- p_registered_code - The rule code for which value should be returned
1531 -- p_registered_source - The source for which value should be returned
1532 -- Returns the value for the p_registered_source+p_registered_code
1533 ----------------------------------------------------------------------------
1534 FUNCTION Get_RUL_SOURCE_VALUE (
1535             p_rul_tbl            IN      global_rprle_tbl_type,
1536             p_registered_code    IN      varchar2,
1537             p_registered_source  IN      VARCHAR2)
1538 RETURN VARCHAR2 IS
1539      i NUMBER:=0;
1540 Begin
1541     IF (l_debug = 'Y') THEN
1542        okc_debug.Set_Indentation('GET_RUL_SOURCE_VALUE');
1543     END IF;
1544     IF (l_debug = 'Y') THEN
1545        my_debug('3600 : Entering GET_RUL_SOURCE_VALUE', 2);
1546        my_debug('3610 :looking for code'||p_registered_code, 1);
1547        my_debug('3620 : looking for source'||p_registered_source, 1);
1548        my_debug('3630 :table count'||p_rul_tbl.count, 1);
1549     END IF;
1550 
1551 
1552             If p_rul_tbl.count>0 then
1553                  i:= p_rul_tbl.first;
1554                  LOOP
1555                      IF (l_debug = 'Y') THEN
1556                         my_debug('3635 :going thru code'||p_rul_tbl(i).code, 1);
1557                         my_debug('3640 : going thru source'||p_rul_tbl(i).current_source, 1);
1558                      END IF;
1559 
1560                     If p_rul_tbl(i).current_source = p_registered_source
1561                          and p_rul_tbl(i).code = p_registered_code then
1562                              IF (l_debug = 'Y') THEN
1563                                 my_debug('3650 : Found the rec , value-'||p_rul_tbl(i).source_value, 1);
1564                              END IF;
1565 
1566                              IF (l_debug = 'Y') THEN
1567                                 my_debug('3700 : Exiting GET_RUL_SOURCE_VALUE', 2);
1568                              END IF;
1569                              IF (l_debug = 'Y') THEN
1570                                 okc_debug.Reset_Indentation;
1571                              END IF;
1572 
1573                              return   p_rul_tbl(i).source_value;
1574                     End If;
1575                     Exit When i=p_rul_tbl.last;
1576                     i:= p_rul_tbl.next(i);
1577                 End Loop;
1578             End If; -- p_rul_type.count
1579     IF (l_debug = 'Y') THEN
1580        my_debug('3750 : Could not find the rec', 1);
1581     END IF;
1582 
1583     IF (l_debug = 'Y') THEN
1584        my_debug('3800 : Exiting GET_RUL_SOURCE_VALUE', 2);
1585     END IF;
1586     IF (l_debug = 'Y') THEN
1587        okc_debug.Reset_Indentation;
1588     END IF;
1589 
1590            return null;
1591 
1592            EXCEPTION
1593            WHEN OTHERS then
1594              IF (l_debug = 'Y') THEN
1595                 my_debug('3850 :should not have come current source:'|| p_rul_tbl(i).current_source,1);
1596                 my_debug('3860 :sql code:'||sqlcode,1);
1597                 my_debug('3870 :msg:'||sqlerrm,1);
1598                 my_debug('3900 : Exiting GET_RUL_SOURCE_VALUE', 4);
1599              END IF;
1600              IF (l_debug = 'Y') THEN
1601                 okc_debug.Reset_Indentation;
1602              END IF;
1603 
1604               RETURN NULL;
1605 END Get_RUL_SOURCE_VALUE;
1606 
1607 -----------------------------------------------------------------------------
1608 --FUNCTION - GET_PRLE_SOURCE_VALUE
1609 -- This function is used in mapping of attributes between QP and OKC rules
1610 -- The calls to this function will be made by QP Engine to get values for
1611 --various Qualifiers and Pricing Attributes
1612 -- p_rul_tbl - Global Table holding various OKX_SOURCES and their values for rules
1613 -- p_registered_code - The role code for which value should be returned
1614 -- p_registered_source - The source for which value should be returned
1615 -- Returns the value for the p_registered_source+p_registered_code
1616 ----------------------------------------------------------------------------
1617 FUNCTION Get_PRLE_SOURCE_VALUE (
1618             p_prle_tbl            IN      global_rprle_tbl_type,
1619             p_registered_code    IN      varchar2,
1620             p_registered_source  IN      VARCHAR2)
1621 RETURN VARCHAR2 IS
1622      i NUMBER:=0;
1623 Begin
1624          IF (l_debug = 'Y') THEN
1625             okc_debug.Set_Indentation('Get_PRLE_SOURCE_VALUE');
1626          END IF;
1627          IF (l_debug = 'Y') THEN
1628             my_debug('4000 : Entering Get_PRLE_SOURCE_VALUE', 2);
1629          END IF;
1630             If p_prle_tbl.count>0 then
1631                  i:= p_prle_tbl.first;
1632                  LOOP
1633                     If p_prle_tbl(i).current_source = p_registered_source
1634                          and p_prle_tbl(i).code = p_registered_code then
1635                               IF (l_debug = 'Y') THEN
1636                                  my_debug('4100 : Exiting Get_PRLE_SOURCE_VALUE', 2);
1637                               END IF;
1638                               IF (l_debug = 'Y') THEN
1639                                  okc_debug.Reset_Indentation;
1640                               END IF;
1641 
1642                              return   p_prle_tbl(i).source_value;
1643                     End If;
1644                     Exit When i=p_prle_tbl.last;
1645                     i:= p_prle_tbl.next(i);
1646                 End Loop;
1647             End If; -- p_prle_type.count
1648          IF (l_debug = 'Y') THEN
1649             my_debug('4200 : Exiting Get_PRLE_SOURCE_VALUE', 2);
1650          END IF;
1651          IF (l_debug = 'Y') THEN
1652             okc_debug.Reset_Indentation;
1653          END IF;
1654 
1655            return null;
1656 
1657            EXCEPTION
1658            WHEN OTHERS then
1659              IF (l_debug = 'Y') THEN
1660                 my_debug('4250 :should not have come current source:'|| p_prle_tbl(i).current_source,1);
1661                 my_debug('4260 :sql code:'||sqlcode,1);
1662                 my_debug('4270 :msg:'||sqlerrm,1);
1663                 my_debug('4300 : Exiting Get_PRLE_SOURCE_VALUE', 4);
1664              END IF;
1665              IF (l_debug = 'Y') THEN
1666                 okc_debug.Reset_Indentation;
1667              END IF;
1668 
1669               RETURN NULL;
1670 END Get_PRLE_SOURCE_VALUE;
1671 ---------------------------------------------------------------------------
1672 --FUNCTION - ADD_TO_GLOBAL_lse_TBL
1673 -- This proc. checks if the data source specified is alredy there
1674 -- in global tbl or not. If not, it adds the sent in record to the global table
1675 -- else just comes out without adding
1676 -- p_global_rec - Global record with source and its value;
1677 -- Returns status of the call
1678 ----------------------------------------------------------------------------
1679 FUNCTION Add_TO_GLOBAL_LSE_TBL (
1680             p_global_rec         IN      global_lse_rec_type)
1681             Return varchar2 IS
1682             l_return_status varchar2(1):=OKC_API.G_RET_STS_SUCCESS;
1683             i               number :=0;
1684             l_already_there   Exception;
1685 Begin
1686     IF (l_debug = 'Y') THEN
1687        okc_debug.Set_Indentation('Add_TO_GLOBAL_LSE_TBL');
1688     END IF;
1689     IF (l_debug = 'Y') THEN
1690        my_debug('4400 : Entering Add_TO_GLOBAL_LSE_TBL', 2);
1691     END IF;
1692 
1693            If okc_price_pub.g_lse_tbl.count>0 then
1694                  i:= okc_price_pub.g_lse_tbl.first;
1695                  LOOP
1696                     If okc_price_pub.g_lse_tbl(i).current_source = p_global_rec.current_source then
1697                              raise l_already_there;
1698                     End If;
1699                     Exit When i= okc_price_pub.g_lse_tbl.last;
1700                     i:= okc_price_pub.g_lse_tbl.next(i);
1701                 End Loop;
1702            End If; -- g_lse_type.count
1703            IF (l_debug = 'Y') THEN
1704               my_debug('4450 : current source'||p_global_rec.current_source, 1);
1705               my_debug('4460 : source value'||p_global_rec.source_value, 1);
1706            END IF;
1707 
1708            okc_price_pub.g_lse_tbl(i+1):=p_global_rec;
1709            IF (l_debug = 'Y') THEN
1710               my_debug('4500 : Exiting Add_TO_GLOBAL_LSE_TBL', 2);
1711            END IF;
1712            IF (l_debug = 'Y') THEN
1713               okc_debug.Reset_Indentation;
1714            END IF;
1715 
1716            return l_return_status;
1717   EXCEPTION
1718     WHEN l_already_there then
1719            IF (l_debug = 'Y') THEN
1720               my_debug('4550 : Already there current source'||p_global_rec.current_source, 1);
1721               my_debug('4560 : source value'||p_global_rec.source_value, 1);
1722            END IF;
1723 
1724            IF (l_debug = 'Y') THEN
1725               my_debug('4600 : Exiting Add_TO_GLOBAL_LSE_TBL', 4);
1726            END IF;
1727            IF (l_debug = 'Y') THEN
1728               okc_debug.Reset_Indentation;
1729            END IF;
1730 
1731 	   return l_return_status;
1732     when others then
1733       OKC_API.set_message(p_app_name      => g_app_name,
1734                           p_msg_name      => g_unexpected_error,
1735                           p_token1        => g_sqlcode_token,
1736                           p_token1_value  => sqlcode,
1737                           p_token2        => g_sqlerrm_token,
1738                           p_token2_value  => sqlerrm);
1739       l_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
1740       IF (l_debug = 'Y') THEN
1741          my_debug('4620 :Unexpected Error:'|| p_global_rec.current_source,1);
1742          my_debug('4630 :sql code:'||sqlcode,1);
1743          my_debug('4640 :msg:'||sqlerrm,1);
1744       END IF;
1745 
1746        IF (l_debug = 'Y') THEN
1747           my_debug('4700 : Exiting Add_TO_GLOBAL_LSE_TBL', 2);
1748        END IF;
1749        IF (l_debug = 'Y') THEN
1750           okc_debug.Reset_Indentation;
1751        END IF;
1752 
1753       return l_return_status;
1754 End Add_TO_GLOBAL_LSE_TBL;
1755 
1756 ---------------------------------------------------------------------------
1757 --FUNCTION - ADD_TO_GLOBAL_TBL
1758 -- This proc. checks if the data source specified is alredy there
1759 -- in global tbl or not. If not, it adds the sent in record to the global table
1760 -- else just comes out without adding
1761 -- p_global_rec - Global record with source and its value;
1762 -- Returns status of the call
1763 ----------------------------------------------------------------------------
1764 FUNCTION Add_TO_GLOBAL_TBL (
1765             p_global_tbl         IN OUT NOCOPY      global_rprle_tbl_type,
1766             p_global_rec         IN      global_rprle_rec_type)
1767             Return varchar2 IS
1768             l_return_status varchar2(1):=OKC_API.G_RET_STS_SUCCESS;
1769             i               number :=0;
1770             l_already_there   Exception;
1771 Begin
1772          IF (l_debug = 'Y') THEN
1773             okc_debug.Set_Indentation('Add_TO_GLOBAL_TBL');
1774          END IF;
1775          IF (l_debug = 'Y') THEN
1776             my_debug('4800 : Entering Add_TO_GLOBAL_TBL', 2);
1777          END IF;
1778 
1779            If p_global_tbl.count>0 then
1780                  i:= p_global_tbl.first;
1781                  LOOP
1782                     If p_global_tbl(i).current_source = p_global_rec.current_source
1783                          and p_global_tbl(i).code = p_global_rec.code then
1784                              raise l_already_there;
1785                     End If;
1786                     Exit When i= p_global_tbl.last;
1787                     i:= p_global_tbl.next(i);
1788                 End Loop;
1789            End If; -- p_global_tbl.count
1790            IF (l_debug = 'Y') THEN
1791               my_debug('4850 : current source'||p_global_rec.current_source, 1);
1792               my_debug('4860 : current code'||p_global_rec.code, 1);
1793               my_debug('4860 : source value'||p_global_rec.source_value, 1);
1794            END IF;
1795 
1796            p_global_tbl(i+1):=p_global_rec;
1797             IF (l_debug = 'Y') THEN
1798                my_debug('4900 : Exiting Add_TO_GLOBAL_TBL', 2);
1799             END IF;
1800             IF (l_debug = 'Y') THEN
1801                okc_debug.Reset_Indentation;
1802             END IF;
1803 
1804            return l_return_status;
1805   EXCEPTION
1806     WHEN l_already_there then
1807            IF (l_debug = 'Y') THEN
1808               my_debug('4950 : Already there current source'||p_global_rec.current_source, 1);
1809               my_debug('4960 : Already there current code'||p_global_rec.code, 1);
1810               my_debug('4970 : source value'||p_global_rec.source_value, 1);
1811            END IF;
1812 
1813             IF (l_debug = 'Y') THEN
1814                my_debug('5000 : Exiting Add_TO_GLOBAL_TBL', 4);
1815             END IF;
1816             IF (l_debug = 'Y') THEN
1817                okc_debug.Reset_Indentation;
1818             END IF;
1819 
1820 	   return l_return_status;
1821     when others then
1822       OKC_API.set_message(p_app_name      => g_app_name,
1823                           p_msg_name      => g_unexpected_error,
1824                           p_token1        => g_sqlcode_token,
1825                           p_token1_value  => sqlcode,
1826                           p_token2        => g_sqlerrm_token,
1827                           p_token2_value  => sqlerrm);
1828       l_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
1829             IF (l_debug = 'Y') THEN
1830                my_debug('5050 :Unexpected Error:'|| p_global_rec.current_source,1);
1831                my_debug('5060 :sql code:'||sqlcode,1);
1832                my_debug('5070 :msg:'||sqlerrm,1);
1833             END IF;
1834 
1835             IF (l_debug = 'Y') THEN
1836                my_debug('5100 : Exiting Add_TO_GLOBAL_TBL', 4);
1837             END IF;
1838             IF (l_debug = 'Y') THEN
1839                okc_debug.Reset_Indentation;
1840             END IF;
1841 
1842       return l_return_status;
1843 End Add_TO_GLOBAL_TBL;
1844 ---------------------------------------------------------------------------
1845 --FUNCTION - Attach_rules
1846 -- This proc. puts the rule source in the global table
1847 -- Returns status of the call
1848 ----------------------------------------------------------------------------
1849 Function Attach_Rules(p_chr_id  NUMBER, p_cle_id number default null)
1850   Return Varchar2 Is
1851   cursor l_rul_csr(p_chr_id IN NUMBER) Is
1852 
1853      -- The query below has been introduced in place of one below it because of performance reasons
1854      -- Right now the rules cannot be defined by a user. Neither can he set the pricing_related_yn
1855      -- flag nor change the source of the rule. Also, we are not expecting the user to enter
1856      -- Attribute mapping for rules. All these things might be allowed in phase 2. Because of all
1857      -- these restrictions, we donot need the bigger picture here where we expect the user to
1858      -- map his own rules in his own rulegroups and then map them to some pricing qualifier/pricing
1859      -- attribute. So we decided to restrict the query to filter out the unnecessary data that we will
1860      -- never use. At some point , If the phase 2 is implemented and the user is expected to define
1861      -- his own rules in rulegroups and define the sources and set pricing_related_yn flag and then
1862      -- map the value to some pricing attribute, this query will have to be changed to one below.
1863      -- In that scenario, even the one below will work but will not be efficient and has to be modified to filter based
1864      -- pricing_related_yn flag
1865      -- This query also has to be changed if we map some other rule in attribute mapping at some point
1866      -- Also, this query assumes, based on current mapping of rules in rulegroups, that BTO rule
1867      -- will only be in rulegroup BILLING and not in SHIPPING or PAYMENT , STO in SHIPPING and not in
1868      -- BILLING or PAYMENT , PTR in PAYMENT and not in SHIPPING or BILLING (that is the way it is right now)
1869      -- If the rules mapping is picking up wrong values, check for the validity of this assumption first
1870       select rul.jtot_object1_code,rul.object1_id1,rul.object1_id2
1871             ,rul.jtot_object2_code,rul.object2_id1,rul.object2_id2
1872             ,rul.jtot_object3_code,rul.object3_id1,rul.object3_id2
1873             ,rul.rule_information_category
1874       from okc_rules_b rul, okc_rule_groups_b rgp
1875       where rul.rgp_id = rgp.id and
1876             rgp.rgd_code in ('BILLING','SHIPPING','PAYMENT') and
1877             rul.rule_information_category in ('BTO','STO','PTR','CAN') and
1878             rgp.dnz_chr_id = p_chr_id and rgp.chr_id is not null;
1879 
1880 --  the query below has been replaced by one above.please read the comments
1881   /*  select rul.jtot_object1_code,rul.object1_id1,rul.object1_id2,rul.jtot_object2_code,
1882            rul.object2_id1,rul.object2_id2, rul.jtot_object3_code,rul.object3_id1,rul.object3_id2
1883            ,rul.rule_information_category
1884           -- ,rul.rule_information1,rul.rule_information2,
1885            --rul.rule_information3,rul.rule_information4,rul.rule_information5,rul.rule_information6,
1886            --rul.rule_information7,rul.rule_information8,rul.rule_information9,rul.rule_information10,
1887            --rul.rule_information11,rul.rule_information12,rul.rule_information13,rul.rule_information14,
1888            --rul.rule_information15
1889            from okc_rules_b rul, okc_rule_groups_b rgp
1890            where rul.rgp_id = rgp.id and rgp.chr_id = p_chr_id;*/
1891 
1892  cursor l_cle_rul_csr(p_chr_id IN NUMBER,p_cle_id IN NUMBER) Is
1893 
1894       -- The query below has been introduced in place of one below it because of performance reasons
1895       -- see comments above for header
1896       select rul.jtot_object1_code,rul.object1_id1,rul.object1_id2
1897             ,rul.jtot_object2_code,rul.object2_id1,rul.object2_id2
1898             ,rul.jtot_object3_code,rul.object3_id1,rul.object3_id2
1899             ,rul.rule_information_category
1900 
1901       from okc_rules_b rul, okc_rule_groups_b rgp
1902       where rul.rgp_id = rgp.id and rgp.dnz_chr_id = p_chr_id and
1903             rgp.cle_id=p_cle_id and
1904             rgp.rgd_code in ('BILLING','SHIPPING','PAYMENT') and
1905             rul.rule_information_category in ('BTO','STO','PTR','CAN');
1906 
1907   /*  select rul.jtot_object1_code,rul.object1_id1,rul.object1_id2,rul.jtot_object2_code,
1908            rul.object2_id1,rul.object2_id2, rul.jtot_object3_code,rul.object3_id1,rul.object3_id2
1909            ,rul.rule_information_category
1910           -- ,rul.rule_information1,rul.rule_information2,
1911            --rul.rule_information3,rul.rule_information4,rul.rule_information5,rul.rule_information6,
1912            --rul.rule_information7,rul.rule_information8,rul.rule_information9,rul.rule_information10,
1913            --rul.rule_information11,rul.rule_information12,rul.rule_information13,rul.rule_information14,
1914            --rul.rule_information15
1915            from okc_rules_b rul, okc_rule_groups_b rgp
1916            where rul.rgp_id = rgp.id and rgp.dnz_chr_id = p_chr_id and rgp.cle_id=p_cle_id;*/
1917 
1918   l_return_status varchar2(1):=OKC_API.G_RET_STS_SUCCESS;
1919   l_rul_rec    global_rprle_rec_type;
1920   l_rul_data   l_rul_csr%rowtype;
1921 BEGIN
1922     IF (l_debug = 'Y') THEN
1923        okc_debug.Set_Indentation('Attach_Rules');
1924     END IF;
1925     IF (l_debug = 'Y') THEN
1926        my_debug('5200 : Entering Attach_Rules', 2);
1927     END IF;
1928 
1929      If p_cle_id is null then
1930         OPEN l_rul_csr(p_chr_id);
1931      Else
1932         OPEN l_cle_rul_csr(p_chr_id,p_cle_id);
1933      END IF;
1934 
1935      LOOP
1936         If p_cle_id is null then
1937            fetch l_rul_csr into l_rul_data;
1938            Exit when l_rul_csr%NOTFOUND;
1939         Else
1940             fetch l_cle_rul_csr into l_rul_data;
1941             Exit when l_cle_rul_csr%NOTFOUND;
1942         END IF;
1943          IF (l_debug = 'Y') THEN
1944             my_debug('5210 : Found a record', 1);
1945             my_debug('5212 : object1_id1'||l_rul_data.object1_id1, 1);
1946             my_debug('5214 : object1_code'||l_rul_data.jtot_object1_code, 1);
1947             my_debug('5216 : rule code'||l_rul_data.rule_information_category, 1);
1948          END IF;
1949 
1950 --???? This condition that l_rul_data.object1_id2 = '#' might have to go when
1951 -- service starts using Pricing as in category of Warranty... some records have
1952 -- second value
1953         If l_rul_data.object1_id1 is not null and l_rul_data.object1_id2 = '#' then
1954                   l_rul_rec.current_source:=l_rul_data.jtot_object1_code;
1955                   l_rul_rec.code :=l_rul_data.rule_information_category;
1956                   l_rul_rec.source_value := l_rul_data.object1_id1;
1957                   l_return_status:= add_to_global_tbl(okc_price_pub.g_rul_tbl,l_rul_rec);
1958                   IF l_return_status <> OKC_API.G_RET_STS_SUCCESS THEN
1959 					 RAISE l_exception_stop;
1960                   END IF;
1961 
1962         End If;
1963         If l_rul_data.object2_id1 is not null and l_rul_data.object2_id2  = '#' then
1964                   l_rul_rec.current_source:=l_rul_data.jtot_object2_code;
1965                   l_rul_rec.code :=l_rul_data.rule_information_category;
1966                   l_rul_rec.source_value := l_rul_data.object2_id1;
1967                   l_return_status:= add_to_global_tbl(okc_price_pub.g_rul_tbl,l_rul_rec);
1968                   IF l_return_status <> OKC_API.G_RET_STS_SUCCESS THEN
1969 					 RAISE l_exception_stop;
1970                   END IF;
1971         End If;
1972         If l_rul_data.object3_id1 is not null and l_rul_data.object3_id2 = '#' then
1973                   l_rul_rec.current_source:=l_rul_data.jtot_object3_code;
1974                   l_rul_rec.code :=l_rul_data.rule_information_category;
1975                   l_rul_rec.source_value := l_rul_data.object3_id1;
1976                   l_return_status:= add_to_global_tbl(okc_price_pub.g_rul_tbl,l_rul_rec);
1977                   IF l_return_status <> OKC_API.G_RET_STS_SUCCESS THEN
1978 					 RAISE l_exception_stop;
1979                   END IF;
1980 
1981         End If;
1982      End LOOP;
1983      If l_rul_csr%ISOPEN then
1984          close l_rul_csr;
1985      ELSIf l_cle_rul_csr%ISOPEN then
1986          close l_cle_rul_csr;
1987      END IF;
1988      IF (l_debug = 'Y') THEN
1989         my_debug('5700 : Exiting Attach_Rules', 2);
1990      END IF;
1991      IF (l_debug = 'Y') THEN
1992         okc_debug.Reset_Indentation;
1993      END IF;
1994 
1995      return l_return_status;
1996 
1997   EXCEPTION
1998     WHEN l_exception_stop then
1999      If l_rul_csr%ISOPEN then
2000          close l_rul_csr;
2001      ELSIf l_cle_rul_csr%ISOPEN then
2002          close l_cle_rul_csr;
2003      END IF;
2004      IF (l_debug = 'Y') THEN
2005         my_debug('5800 : Exiting Attach_Rules', 4);
2006      END IF;
2007      IF (l_debug = 'Y') THEN
2008         okc_debug.Reset_Indentation;
2009      END IF;
2010 
2011 	 return l_return_status;
2012     when others then
2013       OKC_API.set_message(p_app_name      => g_app_name,
2014                           p_msg_name      => g_unexpected_error,
2015                           p_token1        => g_sqlcode_token,
2016                           p_token1_value  => sqlcode,
2017                           p_token2        => g_sqlerrm_token,
2018                           p_token2_value  => sqlerrm);
2019       If l_rul_csr%ISOPEN then
2020          close l_rul_csr;
2021       ELSIf l_cle_rul_csr%ISOPEN then
2022          close l_cle_rul_csr;
2023       END IF;
2024       l_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
2025       IF (l_debug = 'Y') THEN
2026          my_debug('5900 : Exiting Attach_Rules', 4);
2027       END IF;
2028       IF (l_debug = 'Y') THEN
2029          okc_debug.Reset_Indentation;
2030       END IF;
2031 
2032       return l_return_status;
2033 END Attach_rules;
2034 
2035 ---------------------------------------------------------------------------
2036 --FUNCTION - Attach_party_roles
2037 -- This proc. puts the party role source in the global table
2038 -- Returns status of the call
2039 ----------------------------------------------------------------------------
2040 Function Attach_party_roles(p_chr_id  NUMBER, p_cle_id IN NUMBER default null)
2041   Return Varchar2 Is
2042   cursor l_chr_csr(p_chr_id IN NUMBER) Is
2043             ---???????? only id1
2044     select jtot_object1_code, object1_id1,object1_id2,rle_code
2045     from okc_k_party_roles_b
2046      where dnz_chr_id = p_chr_id and chr_id is not null;
2047 
2048   cursor l_cle_csr(p_chr_id IN NUMBER, p_cle_id IN NUMBER) Is
2049             ---???????? only id1
2050     select jtot_object1_code,object1_id1,object1_id2,rle_code
2051     from okc_k_party_roles_b
2052     where dnz_chr_id = p_chr_id and cle_id=p_cle_id;
2053   l_prle_data   l_chr_csr%rowtype;
2054   l_return_status varchar2(1):=OKC_API.G_RET_STS_SUCCESS;
2055   l_prle_rec    global_rprle_rec_type;
2056 BEGIN
2057     IF (l_debug = 'Y') THEN
2058        okc_debug.Set_Indentation('Attach_party_roles');
2059     END IF;
2060     IF (l_debug = 'Y') THEN
2061        my_debug('6000 : Entering Attach_party_roles', 2);
2062     END IF;
2063 
2064      If p_cle_id is null then
2065         OPEN l_chr_csr(p_chr_id);
2066      Else
2067         OPEN l_cle_csr(p_chr_id,p_cle_id);
2068      END IF;
2069      LOOP
2070            If p_cle_id is null then
2071                 Fetch l_chr_csr into l_prle_data;
2072                 Exit when l_chr_csr%NOTFOUND;
2073            Else
2074                 Fetch l_cle_csr into l_prle_data;
2075                 Exit when l_cle_csr%NOTFOUND;
2076            END IF;
2077            If l_prle_data.object1_id1 is not null and l_prle_data.object1_id2 = '#' then
2078                   l_prle_rec.current_source:=l_prle_data.jtot_object1_code;
2079                   l_prle_rec.code :=l_prle_data.rle_code;
2080                   l_prle_rec.source_value := l_prle_data.object1_id1;
2081                   ---?????????? do we need unique check in global prle table as
2082                   ---??????????? there could be same role multiple times on a contract
2083                   ---????? coming from same source e.d third party  in gsi
2084                   ---??? Then do we pick the first one only or do we allow duplication here
2085                   ---??? as any of the third party could get us some modifier
2086                   --??? doing above might become a problem when duplication checked in extra pricing attributes.
2087                   -- ?????Use party precedence column to check which party role should be sent
2088                   ---???? when same role multiple times on a contract.
2089                   l_return_status:= add_to_global_tbl(okc_price_pub.g_prle_tbl,l_prle_rec);
2090                   IF l_return_status <> OKC_API.G_RET_STS_SUCCESS THEN
2091 					 RAISE l_exception_stop;
2092                   END IF;
2093            End If;
2094 
2095      END LOOP;
2096      If l_chr_csr%isopen then
2097            close l_chr_csr;
2098      ELSIF l_cle_csr%isopen then
2099            close l_cle_csr;
2100      END IF;
2101     IF (l_debug = 'Y') THEN
2102        my_debug('6700 : Exiting Attach_party_roles',2);
2103     END IF;
2104     IF (l_debug = 'Y') THEN
2105        okc_debug.Reset_Indentation;
2106     END IF;
2107 
2108      return l_return_status;
2109   -- --dbms_output.put_line('attach_party_roles');
2110   EXCEPTION
2111     WHEN l_exception_stop then
2112        If l_chr_csr%isopen then
2113            close l_chr_csr;
2114        ELSIF l_cle_csr%isopen then
2115            close l_cle_csr;
2116         END IF;
2117     IF (l_debug = 'Y') THEN
2118        my_debug('6800 : Exiting Attach_party_roles', 4);
2119     END IF;
2120     IF (l_debug = 'Y') THEN
2121        okc_debug.Reset_Indentation;
2122     END IF;
2123 
2124 	   return l_return_status;
2125     when others then
2126       OKC_API.set_message(p_app_name      => g_app_name,
2127                           p_msg_name      => g_unexpected_error,
2128                           p_token1        => g_sqlcode_token,
2129                           p_token1_value  => sqlcode,
2130                           p_token2        => g_sqlerrm_token,
2131                           p_token2_value  => sqlerrm);
2132        l_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
2133        If l_chr_csr%isopen then
2134            close l_chr_csr;
2135        ELSIF l_cle_csr%isopen then
2136            close l_cle_csr;
2137         END IF;
2138     IF (l_debug = 'Y') THEN
2139        my_debug('6900 : Exiting Attach_party_roles', 4);
2140     END IF;
2141     IF (l_debug = 'Y') THEN
2142        okc_debug.Reset_Indentation;
2143     END IF;
2144 
2145       return l_return_status;
2146 END Attach_party_roles;
2147 ---------------------------------------------------------------------------
2148 --FUNCTION - IS_ALREADY_THERE
2149 -- This function determines if the attribute sent in is already there or not
2150 -- Returns 'Y' if already there else 'N'
2151 --p_pricing_contexts_Tbl - Pricing context table from build_context
2152 --p_qualifier_contexts_Tbl- Qualifier context table from build_context
2153 --p_context - Context name
2154 --p_attrib_name-Attribute name
2155 ---------------------------------------------------------------------------
2156 FUNCTION IS_ALREADY_THERE(
2157           p_pricing_attrib_tbl    QP_PREQ_GRP.LINE_ATTR_TBL_TYPE
2158          ,p_qual_tbl              QP_PREQ_GRP.QUAL_TBL_TYPE
2159          ,p_line_index            number
2160          ,p_context               varchar2
2161          ,p_attrib_name           varchar2
2162          ) Return varchar2 IS
2163 
2164          i  pls_integer;
2165          l_return_flag  varchar2(1):='N';
2166  BEGIN
2167     IF (l_debug = 'Y') THEN
2168        okc_debug.Set_Indentation('IS_ALREADY_THERE');
2169     END IF;
2170     IF (l_debug = 'Y') THEN
2171        my_debug('7000 : Entering IS_ALREADY_THERE', 2);
2172     END IF;
2173 
2174       If p_attrib_name like 'PRICING%' then --#1
2175             i := p_pricing_attrib_Tbl.First;
2176 	        While i is not null loop
2177                 IF  p_context =  p_pricing_attrib_tbl(i).PRICING_CONTEXT
2178                     and p_attrib_name = p_pricing_attrib_tbl(i).PRICING_ATTRIBUTE
2179                     and p_line_index = p_pricing_attrib_tbl(i).line_index
2180                 THEN
2181                     IF (l_debug = 'Y') THEN
2182                        my_debug('7050 : Exiting IS_ALREADY_THERE', 2);
2183                     END IF;
2184                     IF (l_debug = 'Y') THEN
2185                        okc_debug.Reset_Indentation;
2186                     END IF;
2187 
2188                     return 'Y';
2189                 END IF;
2190 		        i := p_pricing_attrib_Tbl.Next(i);
2191 	        end loop;
2192       ELSIF p_attrib_name like 'QUALIFIER%' then  --#1
2193             i := p_qual_Tbl.First;
2194 	        While i is not null loop
2195                 IF  p_context =  p_qual_tbl(i).QUALIFIER_CONTEXT
2196                     and p_attrib_name = p_qual_tbl(i).QUALIFIER_ATTRIBUTE
2197                     and p_line_index = p_qual_tbl(i).line_index
2198 
2199                 THEN
2200                     IF (l_debug = 'Y') THEN
2201                        my_debug('7100 : Exiting IS_ALREADY_THERE', 2);
2202                     END IF;
2203                     IF (l_debug = 'Y') THEN
2204                        okc_debug.Reset_Indentation;
2205                     END IF;
2206 
2207                     return 'Y';
2208                 END IF;
2209 		        i := p_qual_Tbl.Next(i);
2210 	        end loop;
2211 
2212       END IF; --#1
2213     IF (l_debug = 'Y') THEN
2214        my_debug('7200 : Exiting IS_ALREADY_THERE', 2);
2215     END IF;
2216     IF (l_debug = 'Y') THEN
2217        okc_debug.Reset_Indentation;
2218     END IF;
2219 
2220       return l_return_flag;
2221  END IS_ALREADY_THERE;
2222 ---------------------------------------------------------------------------
2223 --Procedure - Copy_Attribs_To_req
2224 -- This proc. copies the data returned by build_context to request line
2225 -- qulaifier and pricing attribute tables.
2226 --p_line_index - Index of the request line
2227 --p_pricing_contexts_Tbl - Pricing context table from build_context
2228 --p_qualifier_contexts_Tbl- Qualifier context table from build_context
2229 --px_Req_line_attr_tbl - Pricing context table for request line
2230 --px_Req_qual_tbl - Qualifier context table for request line
2231 ----------------------------------------------------------------------------
2232 procedure copy_attribs_to_Req(
2233         p_line_index				               number
2234        ,p_pricing_contexts_Tbl 		               QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type
2235        ,p_qualifier_contexts_Tbl 	               QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type
2236        ,px_Req_line_attr_tbl		in out nocopy  QP_PREQ_GRP.LINE_ATTR_TBL_TYPE
2237        ,px_Req_qual_tbl			    in out nocopy  QP_PREQ_GRP.QUAL_TBL_TYPE
2238 )is
2239 i			    pls_integer := 0;
2240 l_attr_index	pls_integer := nvl(px_Req_line_attr_tbl.last,0);
2241 l_qual_index	pls_integer := nvl(px_Req_qual_tbl.last,0);
2242 begin
2243     IF (l_debug = 'Y') THEN
2244        okc_debug.Set_Indentation('copy_attribs_to_Req');
2245     END IF;
2246     IF (l_debug = 'Y') THEN
2247        my_debug('7300 : Entering copy_attribs_to_Req', 2);
2248        my_debug('7302 : p_line_index'||p_line_index, 1);
2249        my_debug('7303 : pricing attrib count '||px_Req_line_attr_tbl.count, 1);
2250     END IF;
2251 
2252 	i := p_pricing_contexts_Tbl.First;
2253 	While i is not null loop
2254 
2255            IF (IS_ALREADY_THERE(px_Req_line_attr_tbl,px_Req_qual_tbl,p_line_index
2256                       ,p_pricing_contexts_Tbl(i).context_name
2257                       ,p_pricing_contexts_Tbl(i).Attribute_Name) = 'N') then
2258 
2259 
2260             		l_attr_index := l_attr_index +1;
2261                     IF (l_debug = 'Y') THEN
2262                        my_debug('7304 : attrib added table index'||l_attr_index, 1);
2263                     END IF;
2264 
2265 		            px_Req_line_attr_tbl(l_attr_index).VALIDATED_FLAG := 'N';
2266 		            px_Req_line_attr_tbl(l_attr_index).line_index := p_line_index;
2267 
2268 			        -- Product and Pricing Contexts go into pricing contexts...
2269 			        px_Req_line_attr_tbl(l_attr_index).PRICING_CONTEXT :=
2270 								p_pricing_contexts_Tbl(i).context_name;
2271 			        px_Req_line_attr_tbl(l_attr_index).PRICING_ATTRIBUTE :=
2272 							p_pricing_contexts_Tbl(i).Attribute_Name;
2273 			        px_Req_line_attr_tbl(l_attr_index).PRICING_ATTR_VALUE_FROM :=
2274 							p_pricing_contexts_Tbl(i).attribute_value;
2275                    IF (l_debug = 'Y') THEN
2276                       my_debug('7320 : context name'||p_pricing_contexts_Tbl(i).context_name, 1);
2277                       my_debug('7322 : context attrib'||p_pricing_contexts_Tbl(i).Attribute_Name, 1);
2278                       my_debug('7324 : context value'||p_pricing_contexts_Tbl(i).attribute_value, 1);
2279                    END IF;
2280 
2281              END IF;
2282 
2283 		i := p_pricing_contexts_Tbl.Next(i);
2284 	end loop;
2285 -- Copy the qualifiers
2286 	i := p_qualifier_contexts_Tbl.First;
2287 	While i is not null loop
2288 		If NOT(p_qualifier_contexts_Tbl(i).context_name ='MODLIST' and
2289 			p_qualifier_contexts_Tbl(i).Attribute_Name ='QUALIFIER_ATTRIBUTE4' )then
2290                  IF (IS_ALREADY_THERE(px_Req_line_attr_tbl,px_Req_qual_tbl,p_line_index
2291                                   ,p_qualifier_contexts_Tbl(i).context_name
2292                                   ,p_qualifier_contexts_Tbl(i).Attribute_Name) = 'N') then
2293 		                  l_qual_index := l_qual_index +1;
2294 		                  px_Req_qual_tbl(l_qual_index).VALIDATED_FLAG := 'N';
2295                           px_Req_qual_tbl(l_qual_index).line_index := p_line_index;
2296 		                  px_Req_qual_tbl(l_qual_index).QUALIFIER_CONTEXT :=
2297 					           p_qualifier_contexts_Tbl(i).context_name;
2298 		                  px_Req_qual_tbl(l_qual_index).QUALIFIER_ATTRIBUTE :=
2299 					           p_qualifier_contexts_Tbl(i).Attribute_Name;
2300 		                  px_Req_qual_tbl(l_qual_index).QUALIFIER_ATTR_VALUE_FROM :=
2301 					   	       p_qualifier_contexts_Tbl(i).attribute_value;
2302                  END IF;
2303 
2304 		End If;
2305 		i := p_qualifier_contexts_Tbl.Next(i);
2306 	end loop;
2307    IF (l_debug = 'Y') THEN
2308       my_debug('7490 : pricing attrib count '||px_Req_line_attr_tbl.count, 1);
2309    END IF;
2310 
2311     IF (l_debug = 'Y') THEN
2312        my_debug('7500 : Exiting copy_attribs_to_Req', 2);
2313     END IF;
2314     IF (l_debug = 'Y') THEN
2315        okc_debug.Reset_Indentation;
2316     END IF;
2317 
2318 end copy_attribs_to_Req;
2319 
2320 ---------------------------------------------------------------------------
2321 --Procedure - Copy_Attribs
2322 -- This proc. copies the PA and QA to request line's
2323 -- qulaifier and pricing attribute tables.
2324 --p_line_index - Index of the request line
2325 --p_pricing_contexts_Tbl - Pricing context table from build_context
2326 --p_qualifier_contexts_Tbl- Qualifier context table from build_context
2327 --px_Req_line_attr_tbl - Pricing context table for request line
2328 --px_Req_qual_tbl - Qualifier context table for request line
2329 --p_check - call is_already_there or not. possible 'Y','N' Default 'Y'
2330 ----------------------------------------------------------------------------
2331 procedure copy_attribs(
2332         p_line_index				               number
2333        ,p_check                                    varchar2
2334        ,p_pricing_contexts_Tbl 		               QP_PREQ_GRP.LINE_ATTR_TBL_TYPE
2335        ,p_qualifier_contexts_Tbl 	               QP_PREQ_GRP.QUAL_TBL_TYPE
2336        ,px_Req_line_attr_tbl		in out nocopy  QP_PREQ_GRP.LINE_ATTR_TBL_TYPE
2337        ,px_Req_qual_tbl			    in out nocopy  QP_PREQ_GRP.QUAL_TBL_TYPE
2338 )is
2339 i			    pls_integer := 0;
2340 l_attr_index	pls_integer := nvl(px_Req_line_attr_tbl.last,0);
2341 l_qual_index	pls_integer := nvl(px_Req_qual_tbl.last,0);
2342 new_line_index number;
2343 begin
2344     IF (l_debug = 'Y') THEN
2345        okc_debug.Set_Indentation('copy_attribs');
2346     END IF;
2347     IF (l_debug = 'Y') THEN
2348        my_debug('7600 : Entering copy_attribs', 2);
2349     END IF;
2350 
2351     IF (l_debug = 'Y') THEN
2352        my_debug('7610 : Qualifier Attribs to be copied:'||p_qualifier_contexts_Tbl.count,1);
2353     END IF;
2354   i:=p_qualifier_contexts_Tbl.first;
2355   while i is not null loop
2356          IF (l_debug = 'Y') THEN
2357             my_debug('7612 :index:'||p_qualifier_contexts_Tbl(i).line_index,1);
2358             my_debug('7614 :Qualifier Context:'||p_qualifier_contexts_Tbl(i).qualifier_context,1);
2359             my_debug('7616 :Qualifier Attribute:'||p_qualifier_contexts_Tbl(i).qualifier_attribute,1);
2360             my_debug('7618 :Qualifier Value:'||p_qualifier_contexts_Tbl(i).qualifier_attr_value_from,1);
2361             my_debug('7620 :validated:'||p_qualifier_contexts_Tbl(i).validated_flag,1);
2362             my_debug('7622 :status code:'||p_qualifier_contexts_Tbl(i).status_code,1);
2363             my_debug('7624 :status text:'||p_qualifier_contexts_Tbl(i).status_text,1);
2364          END IF;
2365 
2366    i:=p_qualifier_contexts_Tbl.next(i);
2367 
2368    end loop;
2369      IF (l_debug = 'Y') THEN
2370         my_debug('7626 :Qualifier attribs already there before copy:'||px_Req_qual_tbl.count,1);
2371      END IF;
2372   i:=px_Req_qual_tbl.first;
2373   while i is not null loop
2374 
2375         IF (l_debug = 'Y') THEN
2376            my_debug('7628 :index:'||px_Req_qual_tbl(i).line_index);
2377            my_debug('7630 :Qualifier Context:'||px_Req_qual_tbl(i).qualifier_context);
2378            my_debug('7632 :Qualifier Attribute:'||px_Req_qual_tbl(i).qualifier_attribute);
2379            my_debug('7634 :Qualifier Value:'||px_Req_qual_tbl(i).qualifier_attr_value_from);
2380            my_debug('7636 :validated:'||px_Req_qual_tbl(i).validated_flag);
2381            my_debug('7638 :status code:'||px_Req_qual_tbl(i).status_code);
2382            my_debug('7640 :status text:'||px_Req_qual_tbl(i).status_text);
2383         END IF;
2384 
2385         i:=px_Req_qual_tbl.next(i);
2386    end loop;
2387 
2388 
2389 
2390   IF (l_debug = 'Y') THEN
2391      my_debug('7642 : Pricing Attribs to be copied:'||p_Pricing_contexts_Tbl.count,1);
2392   END IF;
2393   i:=p_Pricing_contexts_Tbl.first;
2394   while i is not null loop
2395          IF (l_debug = 'Y') THEN
2396             my_debug('7644 :index:'||p_Pricing_contexts_Tbl(i).line_index,1);
2397             my_debug('7646 :Pricing Context:'||p_Pricing_contexts_Tbl(i).Pricing_context,1);
2398             my_debug('76 :Pricing Attribute:'||p_Pricing_contexts_Tbl(i).Pricing_attribute,1);
2399             my_debug('7800 :Pricing Value:'||p_Pricing_contexts_Tbl(i).Pricing_attr_value_from,1);
2400             my_debug('7810 :validated:'||p_Pricing_contexts_Tbl(i).validated_flag,1);
2401             my_debug('7820 :status code:'||p_Pricing_contexts_Tbl(i).status_code,1);
2402             my_debug('7830 :status text:'||p_Pricing_contexts_Tbl(i).status_text,1);
2403          END IF;
2404 
2405    i:=p_Pricing_contexts_Tbl.next(i);
2406 
2407    end loop;
2408      IF (l_debug = 'Y') THEN
2409         my_debug('7840 :Pricing attribs already there before copy:'||px_Req_line_attr_tbl.count,1);
2410      END IF;
2411   i:=px_Req_line_attr_tbl.first;
2412   while i is not null loop
2413 
2414         IF (l_debug = 'Y') THEN
2415            my_debug('7850 :index:'||px_Req_line_attr_tbl(i).line_index);
2416            my_debug('7860 :Pricing Context:'||px_Req_line_attr_tbl(i).Pricing_context);
2417            my_debug('7870 :Pricing Attribute:'||px_Req_line_attr_tbl(i).Pricing_attribute);
2418            my_debug('7880 :Pricing Value:'||px_Req_line_attr_tbl(i).Pricing_attr_value_from);
2419            my_debug('7890 :validated:'||px_Req_line_attr_tbl(i).validated_flag);
2420            my_debug('7892 :status code:'||px_Req_line_attr_tbl(i).status_code);
2421            my_debug('7894 :status text:'||px_Req_line_attr_tbl(i).status_text);
2422         END IF;
2423 
2424         i:=px_Req_line_attr_tbl.next(i);
2425    end loop;
2426 
2427 	i := p_pricing_contexts_Tbl.First;
2428 	While i is not null loop
2429 	 --Bug 2543687
2430            IF (p_check in( 'N','NS')) OR
2431            --Tope Bug 2272022 --Modified to compare/copy index from record
2432 
2433              /* (IS_ALREADY_THERE(px_Req_line_attr_tbl,px_Req_qual_tbl,p_line_index
2434                       ,p_pricing_contexts_Tbl(i).pricing_context
2435                      ,p_pricing_contexts_Tbl(i).pricing_attribute) = 'N')
2436               */
2437 
2438               (IS_ALREADY_THERE(px_Req_line_attr_tbl,px_Req_qual_tbl,p_pricing_contexts_Tbl(i).line_index
2439                      ,p_pricing_contexts_Tbl(i).pricing_context
2440                      ,p_pricing_contexts_Tbl(i).pricing_attribute) = 'N')
2441 
2442                  then
2443 
2444             		l_attr_index := l_attr_index +1;
2445 		            px_Req_line_attr_tbl(l_attr_index).line_index := p_pricing_contexts_Tbl(i).line_index;
2446 
2447 			        -- Product and Pricing Contexts go into pricing contexts...
2448    		            px_Req_line_attr_tbl(l_attr_index).VALIDATED_FLAG := p_pricing_contexts_Tbl(i).validated_flag;
2449 			        px_Req_line_attr_tbl(l_attr_index).PRICING_CONTEXT :=
2450 								p_pricing_contexts_Tbl(i).PRICING_CONTEXT;
2451 			        px_Req_line_attr_tbl(l_attr_index).PRICING_ATTRIBUTE :=
2452 							p_pricing_contexts_Tbl(i).PRICING_ATTRIBUTE;
2453 			        px_Req_line_attr_tbl(l_attr_index).PRICING_ATTR_VALUE_FROM :=
2454 							p_pricing_contexts_Tbl(i).PRICING_ATTR_VALUE_FROM;
2455              END IF;
2456 
2457 		i := p_pricing_contexts_Tbl.Next(i);
2458 	end loop;
2459 -- Copy the qualifiers
2460 	i := p_qualifier_contexts_Tbl.First;
2461 	While i is not null loop
2462        ---Bug 2543687
2463      If p_check = 'NS' Then
2464          new_line_index := p_qualifier_contexts_Tbl(i).line_index;
2465      Else
2466          new_line_index := p_line_index;
2467      End If;
2468 
2469 		--???? is this check needed
2470        --- If NOT(p_qualifier_contexts_Tbl(i).QUALIFIER_CONTEXT ='MODLIST' and
2471 		--	p_qualifier_contexts_Tbl(i).QUALIFIER_ATTRIBUTE ='QUALIFIER_ATTRIBUTE4' )then
2472 
2473       	 IF (IS_ALREADY_THERE(px_Req_line_attr_tbl,px_Req_qual_tbl,new_line_index
2474                                   ,p_qualifier_contexts_Tbl(i).QUALIFIER_CONTEXT
2475                                   ,p_qualifier_contexts_Tbl(i).QUALIFIER_ATTRIBUTE) = 'N') then
2476 
2477 		                  l_qual_index := l_qual_index +1;
2478                           px_Req_qual_tbl(l_qual_index).line_index := new_line_index;
2479        		              px_Req_qual_tbl(l_qual_index).VALIDATED_FLAG := p_qualifier_contexts_Tbl(i).validated_flag;
2480 		                  px_Req_qual_tbl(l_qual_index).QUALIFIER_CONTEXT :=
2481 					           p_qualifier_contexts_Tbl(i).QUALIFIER_CONTEXT;
2482 		                  px_Req_qual_tbl(l_qual_index).QUALIFIER_ATTRIBUTE :=
2483 					           p_qualifier_contexts_Tbl(i).QUALIFIER_ATTRIBUTE;
2484 		                  px_Req_qual_tbl(l_qual_index).QUALIFIER_ATTR_VALUE_FROM :=
2485 					   	       p_qualifier_contexts_Tbl(i).QUALIFIER_ATTR_VALUE_FROM;
2486                  END IF;
2487 
2488 	--	End If;
2489 		i := p_qualifier_contexts_Tbl.Next(i);
2490 	end loop;
2491   --dbms_output.put_line('after copyattribs'||px_Req_qual_tbl.count);
2492   i:=px_Req_qual_tbl.first;
2493   while i is not null loop
2494 
2495          --dbms_output.put_line('index '||px_Req_qual_tbl(i).line_index);
2496           --dbms_output.put_line('starting SAN QA '||'-'||px_Req_qual_tbl(i).qualifier_context);
2497           --dbms_output.put_line('starting SAN QA '||'-'||px_Req_qual_tbl(i).qualifier_attribute);
2498           --dbms_output.put_line('starting SAN QA '||'-'||px_Req_qual_tbl(i).qualifier_attr_value_from);
2499           --dbms_output.put_line('validated '||px_Req_qual_tbl(i).validated_flag);
2500           --dbms_output.put_line('status code '||px_Req_qual_tbl(i).status_code);
2501           --dbms_output.put_line('status text '||px_Req_qual_tbl(i).status_text);
2502 
2503         i:=px_Req_qual_tbl.next(i);
2504    end loop;
2505     IF (l_debug = 'Y') THEN
2506        my_debug('7900 : Exiting copy_attribs', 2);
2507     END IF;
2508     IF (l_debug = 'Y') THEN
2509        okc_debug.Reset_Indentation;
2510     END IF;
2511 
2512 end copy_ATTRIBS;
2513 
2514 --  This Procedure will return the user enterable pricing attributes in contracts
2515 ---------------------------------------------------------------------------
2516 --Procedure - Load_User_Defined_Pattrs
2517 -- This Procedure will return the user enterable pricing attributes in contracts
2518 --p_line_index - Index of the request line
2519 --px_Req_line_attr_tbl - Pricing context table for request line
2520 --px_Req_qual_tbl - Qualifier context table for request line
2521 ----------------------------------------------------------------------------
2522 Procedure Load_User_Defined_Pattrs(p_chr_id   NUMBER,
2523                                    p_line_index NUMBER,
2524                                    px_Req_line_attr_tbl IN OUT NOCOPY QP_PREQ_GRP.LINE_ATTR_TBL_TYPE,
2525                                    px_Req_qual_tbl IN OUT NOCOPY QP_PREQ_GRP.QUAL_TBL_TYPE,
2526                                    x_return_status   IN OUT NOCOPY varchar2,
2527                                    p_cle_id  IN  NUMBER DEFAULT NULL
2528 ) IS
2529   cursor okc_pattr_cur(p_chr_id number) is
2530   select pricing_context,
2531 	    pricing_attribute1,  pricing_attribute2,  pricing_attribute3,  pricing_attribute4,
2532 	    pricing_attribute5,  pricing_attribute6,  pricing_attribute7,  pricing_attribute8,
2533 	    pricing_attribute9,  pricing_attribute10, pricing_attribute11, pricing_attribute12,
2534 	    pricing_attribute13, pricing_attribute14, pricing_attribute15, pricing_attribute16,
2535 	    pricing_attribute17, pricing_attribute18, pricing_attribute19, pricing_attribute20,
2536 	    pricing_attribute21, pricing_attribute22, pricing_attribute23, pricing_attribute24,
2537 	    pricing_attribute25, pricing_attribute26, pricing_attribute27, pricing_attribute28,
2538 	    pricing_attribute29, pricing_attribute30, pricing_attribute31, pricing_attribute32,
2539 	    pricing_attribute33, pricing_attribute34, pricing_attribute35, pricing_attribute36,
2540 	    pricing_attribute37, pricing_attribute38, pricing_attribute39, pricing_attribute40,
2541 	    pricing_attribute41, pricing_attribute42, pricing_attribute43, pricing_attribute44,
2542 	    pricing_attribute45, pricing_attribute46, pricing_attribute47, pricing_attribute48,
2543 	    pricing_attribute49, pricing_attribute50, pricing_attribute51, pricing_attribute52,
2544 	    pricing_attribute53, pricing_attribute54, pricing_attribute55, pricing_attribute56,
2545 	    pricing_attribute57, pricing_attribute58, pricing_attribute59, pricing_attribute60,
2546 	    pricing_attribute61, pricing_attribute62, pricing_attribute63, pricing_attribute64,
2547 	    pricing_attribute65, pricing_attribute66, pricing_attribute67, pricing_attribute68,
2548 	    pricing_attribute69, pricing_attribute70, pricing_attribute71, pricing_attribute72,
2549 	    pricing_attribute73, pricing_attribute74, pricing_attribute75, pricing_attribute76,
2550 	    pricing_attribute77, pricing_attribute78, pricing_attribute79, pricing_attribute80,
2551 	    pricing_attribute81, pricing_attribute82, pricing_attribute83, pricing_attribute84,
2552 	    pricing_attribute85, pricing_attribute86, pricing_attribute87, pricing_attribute88,
2553 	    pricing_attribute89, pricing_attribute90, pricing_attribute91, pricing_attribute92,
2554 	    pricing_attribute93, pricing_attribute94, pricing_attribute95, pricing_attribute96,
2555 	    pricing_attribute97, pricing_attribute98, pricing_attribute99, pricing_attribute100
2556         ,Qualifier_context,
2557 	    qualifier_attribute1,  qualifier_attribute2,  qualifier_attribute3,  qualifier_attribute4,
2558 	    qualifier_attribute5,  qualifier_attribute6,  qualifier_attribute7,  qualifier_attribute8,
2559 	    qualifier_attribute9,  qualifier_attribute10, qualifier_attribute11, qualifier_attribute12,
2560 	    qualifier_attribute13, qualifier_attribute14, qualifier_attribute15, qualifier_attribute16,
2561 	    qualifier_attribute17, qualifier_attribute18, qualifier_attribute19, qualifier_attribute20,
2562 	    qualifier_attribute21, qualifier_attribute22, qualifier_attribute23, qualifier_attribute24,
2563 	    qualifier_attribute25, qualifier_attribute26, qualifier_attribute27, qualifier_attribute28,
2564 	    qualifier_attribute29, qualifier_attribute30, qualifier_attribute31, qualifier_attribute32,
2565 	    qualifier_attribute33, qualifier_attribute34, qualifier_attribute35, qualifier_attribute36,
2566 	    qualifier_attribute37, qualifier_attribute38, qualifier_attribute39, qualifier_attribute40,
2567 	    qualifier_attribute41, qualifier_attribute42, qualifier_attribute43, qualifier_attribute44,
2568 	    qualifier_attribute45, qualifier_attribute46, qualifier_attribute47, qualifier_attribute48,
2569 	    qualifier_attribute49, qualifier_attribute50, qualifier_attribute51, qualifier_attribute52,
2570 	    qualifier_attribute53, qualifier_attribute54, qualifier_attribute55, qualifier_attribute56,
2571 	    qualifier_attribute57, qualifier_attribute58, qualifier_attribute59, qualifier_attribute60,
2572 	    qualifier_attribute61, qualifier_attribute62, qualifier_attribute63, qualifier_attribute64,
2573 	    qualifier_attribute65, qualifier_attribute66, qualifier_attribute67, qualifier_attribute68,
2574 	    qualifier_attribute69, qualifier_attribute70, qualifier_attribute71, qualifier_attribute72,
2575 	    qualifier_attribute73, qualifier_attribute74, qualifier_attribute75, qualifier_attribute76,
2576 	    qualifier_attribute77, qualifier_attribute78, qualifier_attribute79, qualifier_attribute80,
2577 	    qualifier_attribute81, qualifier_attribute82, qualifier_attribute83, qualifier_attribute84,
2578 	    qualifier_attribute85, qualifier_attribute86, qualifier_attribute87, qualifier_attribute88,
2579 	    qualifier_attribute89, qualifier_attribute90, qualifier_attribute91, qualifier_attribute92,
2580 	    qualifier_attribute93, qualifier_attribute94, qualifier_attribute95, qualifier_attribute96,
2581 	    qualifier_attribute97, qualifier_attribute98, qualifier_attribute99, qualifier_attribute100
2582     from okc_price_att_values_v
2583    where chr_id = p_chr_id and cle_id is null;
2584 
2585 
2586   cursor okc_pattr_cle_cur(p_chr_id number, p_cle_id number) is
2587   select pricing_context,
2588 	    pricing_attribute1,  pricing_attribute2,  pricing_attribute3,  pricing_attribute4,
2589 	    pricing_attribute5,  pricing_attribute6,  pricing_attribute7,  pricing_attribute8,
2590 	    pricing_attribute9,  pricing_attribute10, pricing_attribute11, pricing_attribute12,
2591 	    pricing_attribute13, pricing_attribute14, pricing_attribute15, pricing_attribute16,
2592 	    pricing_attribute17, pricing_attribute18, pricing_attribute19, pricing_attribute20,
2593 	    pricing_attribute21, pricing_attribute22, pricing_attribute23, pricing_attribute24,
2594 	    pricing_attribute25, pricing_attribute26, pricing_attribute27, pricing_attribute28,
2595 	    pricing_attribute29, pricing_attribute30, pricing_attribute31, pricing_attribute32,
2596 	    pricing_attribute33, pricing_attribute34, pricing_attribute35, pricing_attribute36,
2597 	    pricing_attribute37, pricing_attribute38, pricing_attribute39, pricing_attribute40,
2598 	    pricing_attribute41, pricing_attribute42, pricing_attribute43, pricing_attribute44,
2599 	    pricing_attribute45, pricing_attribute46, pricing_attribute47, pricing_attribute48,
2600 	    pricing_attribute49, pricing_attribute50, pricing_attribute51, pricing_attribute52,
2601 	    pricing_attribute53, pricing_attribute54, pricing_attribute55, pricing_attribute56,
2602 	    pricing_attribute57, pricing_attribute58, pricing_attribute59, pricing_attribute60,
2603 	    pricing_attribute61, pricing_attribute62, pricing_attribute63, pricing_attribute64,
2604 	    pricing_attribute65, pricing_attribute66, pricing_attribute67, pricing_attribute68,
2605 	    pricing_attribute69, pricing_attribute70, pricing_attribute71, pricing_attribute72,
2606 	    pricing_attribute73, pricing_attribute74, pricing_attribute75, pricing_attribute76,
2607 	    pricing_attribute77, pricing_attribute78, pricing_attribute79, pricing_attribute80,
2608 	    pricing_attribute81, pricing_attribute82, pricing_attribute83, pricing_attribute84,
2609 	    pricing_attribute85, pricing_attribute86, pricing_attribute87, pricing_attribute88,
2610 	    pricing_attribute89, pricing_attribute90, pricing_attribute91, pricing_attribute92,
2611 	    pricing_attribute93, pricing_attribute94, pricing_attribute95, pricing_attribute96,
2612 	    pricing_attribute97, pricing_attribute98, pricing_attribute99, pricing_attribute100
2613         ,Qualifier_context,
2614 	    qualifier_attribute1,  qualifier_attribute2,  qualifier_attribute3,  qualifier_attribute4,
2615 	    qualifier_attribute5,  qualifier_attribute6,  qualifier_attribute7,  qualifier_attribute8,
2616 	    qualifier_attribute9,  qualifier_attribute10, qualifier_attribute11, qualifier_attribute12,
2617 	    qualifier_attribute13, qualifier_attribute14, qualifier_attribute15, qualifier_attribute16,
2618 	    qualifier_attribute17, qualifier_attribute18, qualifier_attribute19, qualifier_attribute20,
2619 	    qualifier_attribute21, qualifier_attribute22, qualifier_attribute23, qualifier_attribute24,
2620 	    qualifier_attribute25, qualifier_attribute26, qualifier_attribute27, qualifier_attribute28,
2621 	    qualifier_attribute29, qualifier_attribute30, qualifier_attribute31, qualifier_attribute32,
2622 	    qualifier_attribute33, qualifier_attribute34, qualifier_attribute35, qualifier_attribute36,
2623 	    qualifier_attribute37, qualifier_attribute38, qualifier_attribute39, qualifier_attribute40,
2624 	    qualifier_attribute41, qualifier_attribute42, qualifier_attribute43, qualifier_attribute44,
2625 	    qualifier_attribute45, qualifier_attribute46, qualifier_attribute47, qualifier_attribute48,
2626 	    qualifier_attribute49, qualifier_attribute50, qualifier_attribute51, qualifier_attribute52,
2627 	    qualifier_attribute53, qualifier_attribute54, qualifier_attribute55, qualifier_attribute56,
2628 	    qualifier_attribute57, qualifier_attribute58, qualifier_attribute59, qualifier_attribute60,
2629 	    qualifier_attribute61, qualifier_attribute62, qualifier_attribute63, qualifier_attribute64,
2630 	    qualifier_attribute65, qualifier_attribute66, qualifier_attribute67, qualifier_attribute68,
2631 	    qualifier_attribute69, qualifier_attribute70, qualifier_attribute71, qualifier_attribute72,
2632 	    qualifier_attribute73, qualifier_attribute74, qualifier_attribute75, qualifier_attribute76,
2633 	    qualifier_attribute77, qualifier_attribute78, qualifier_attribute79, qualifier_attribute80,
2634 	    qualifier_attribute81, qualifier_attribute82, qualifier_attribute83, qualifier_attribute84,
2635 	    qualifier_attribute85, qualifier_attribute86, qualifier_attribute87, qualifier_attribute88,
2636 	    qualifier_attribute89, qualifier_attribute90, qualifier_attribute91, qualifier_attribute92,
2637 	    qualifier_attribute93, qualifier_attribute94, qualifier_attribute95, qualifier_attribute96,
2638 	    qualifier_attribute97, qualifier_attribute98, qualifier_attribute99, qualifier_attribute100
2639 
2640     from okc_price_att_values_v
2641    where cle_id = p_cle_id;
2642 
2643 --Commenting Line below b/c chr_id is not populated for price attr for lines
2644    --and chr_id=p_chr_id;
2645 
2646    l_row      okc_pattr_cur%rowtype;
2647   Procedure Load_Tbl(p_prc_context Varchar2,
2648                      p_prc_attr Varchar2,
2649                      p_prc_attr_value Varchar2) Is
2650     i NUMBER;
2651   Begin
2652     --okc_debug.Set_Indentation('Load_Tbl');
2653     --my_debug('8000 : Entering Load_Tbl', 2);
2654     If p_prc_attr_value Is Not Null
2655        and (UPPER(substr(p_prc_attr,1,1))= 'P' )
2656        Then
2657       i := nvl(px_Req_line_attr_tbl.last,0) +1;
2658       px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
2659       px_Req_line_attr_tbl(i).Validated_Flag := 'Y';
2660       px_Req_line_attr_tbl(i).pricing_context := p_prc_context;
2661       px_Req_line_attr_tbl(i).Pricing_Attribute := p_prc_attr;
2662       px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=p_prc_attr_value;
2663       ELSIf p_prc_attr_value Is Not Null
2664       and (UPPER(substr(p_prc_attr,1,1))= 'Q' )
2665       Then
2666       --?????check for validated_flag for promos
2667       i := nvl(px_Req_qual_tbl.last,0) +1;
2668       px_Req_qual_tbl(i).Line_Index := p_Line_Index;
2669       px_Req_qual_tbl(i).Validated_Flag := 'Y';
2670       px_Req_qual_tbl(i).qualifier_context := p_prc_context;
2671       px_Req_qual_tbl(i).qualifier_Attribute := p_prc_attr;
2672       px_Req_qual_tbl(i).qualifier_attr_Value_From :=p_prc_attr_value;
2673 
2674     End If;
2675    -- my_debug('8200 : Exiting Load_Tbl', 2);
2676    -- okc_debug.Reset_Indentation;
2677 
2678   End;
2679 BEGIN
2680     IF (l_debug = 'Y') THEN
2681        okc_debug.Set_Indentation('Load_User_Defined_Pattrs');
2682     END IF;
2683     IF (l_debug = 'Y') THEN
2684        my_debug('8300 : Entering Load_User_Defined_Pattrs', 2);
2685     END IF;
2686 
2687     x_return_status := OKC_API.G_RET_STS_SUCCESS;
2688 
2689     If p_cle_id is null then
2690          open okc_pattr_cur(p_chr_id);
2691     Else
2692          open okc_pattr_cle_cur(p_chr_id,p_cle_id);
2693     END IF;
2694     LOOP
2695            If p_cle_id is null then
2696                 Fetch okc_pattr_cur into l_row;
2697                 Exit when okc_pattr_cur%NOTFOUND;
2698            Else
2699                 Fetch okc_pattr_cle_cur into l_row;
2700                 Exit when okc_pattr_cle_cur%NOTFOUND;
2701            END IF;
2702          --  here PRICING_ATTRIBUTE... is cse sensitive. It should always be uppercase
2703          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE1', l_row.PRICING_ATTRIBUTE1);
2704          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE2', l_row.PRICING_ATTRIBUTE2);
2705          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE3', l_row.PRICING_ATTRIBUTE3);
2706          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE4', l_row.PRICING_ATTRIBUTE4);
2707          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE5', l_row.PRICING_ATTRIBUTE5);
2708          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE6', l_row.PRICING_ATTRIBUTE6);
2709          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE7', l_row.PRICING_ATTRIBUTE7);
2710          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE8', l_row.PRICING_ATTRIBUTE8);
2711          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE9', l_row.PRICING_ATTRIBUTE9);
2712          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE10', l_row.PRICING_ATTRIBUTE10);
2713          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE11', l_row.PRICING_ATTRIBUTE11);
2714          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE12', l_row.PRICING_ATTRIBUTE12);
2715          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE13', l_row.PRICING_ATTRIBUTE13);
2716          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE14', l_row.PRICING_ATTRIBUTE14);
2717          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE15', l_row.PRICING_ATTRIBUTE15);
2718          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE16', l_row.PRICING_ATTRIBUTE16);
2719          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE17', l_row.PRICING_ATTRIBUTE17);
2720          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE18', l_row.PRICING_ATTRIBUTE18);
2721          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE19', l_row.PRICING_ATTRIBUTE19);
2722          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE20', l_row.PRICING_ATTRIBUTE20);
2723          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE21', l_row.PRICING_ATTRIBUTE21);
2724          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE22', l_row.PRICING_ATTRIBUTE22);
2725          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE23', l_row.PRICING_ATTRIBUTE23);
2726          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE24', l_row.PRICING_ATTRIBUTE24);
2727          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE25', l_row.PRICING_ATTRIBUTE25);
2728          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE26', l_row.PRICING_ATTRIBUTE26);
2729          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE27', l_row.PRICING_ATTRIBUTE27);
2730          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE28', l_row.PRICING_ATTRIBUTE28);
2731          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE29', l_row.PRICING_ATTRIBUTE29);
2732          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE30', l_row.PRICING_ATTRIBUTE30);
2733          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE31', l_row.PRICING_ATTRIBUTE31);
2734          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE32', l_row.PRICING_ATTRIBUTE32);
2735          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE33', l_row.PRICING_ATTRIBUTE33);
2736          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE34', l_row.PRICING_ATTRIBUTE34);
2737          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE35', l_row.PRICING_ATTRIBUTE35);
2738          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE36', l_row.PRICING_ATTRIBUTE36);
2739          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE37', l_row.PRICING_ATTRIBUTE37);
2740          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE38', l_row.PRICING_ATTRIBUTE38);
2741          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE39', l_row.PRICING_ATTRIBUTE39);
2742          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE40', l_row.PRICING_ATTRIBUTE40);
2743          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE41', l_row.PRICING_ATTRIBUTE41);
2744          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE42', l_row.PRICING_ATTRIBUTE42);
2745          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE43', l_row.PRICING_ATTRIBUTE43);
2746          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE44', l_row.PRICING_ATTRIBUTE44);
2747          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE45', l_row.PRICING_ATTRIBUTE45);
2748          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE46', l_row.PRICING_ATTRIBUTE46);
2749          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE47', l_row.PRICING_ATTRIBUTE47);
2750          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE48', l_row.PRICING_ATTRIBUTE48);
2751          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE49', l_row.PRICING_ATTRIBUTE49);
2752          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE50', l_row.PRICING_ATTRIBUTE50);
2753          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE51', l_row.PRICING_ATTRIBUTE51);
2754          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE52', l_row.PRICING_ATTRIBUTE52);
2755          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE53', l_row.PRICING_ATTRIBUTE53);
2756          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE54', l_row.PRICING_ATTRIBUTE54);
2757          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE55', l_row.PRICING_ATTRIBUTE55);
2758          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE56', l_row.PRICING_ATTRIBUTE56);
2759          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE57', l_row.PRICING_ATTRIBUTE57);
2760          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE58', l_row.PRICING_ATTRIBUTE58);
2761          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE59', l_row.PRICING_ATTRIBUTE59);
2762          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE60', l_row.PRICING_ATTRIBUTE60);
2763          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE61', l_row.PRICING_ATTRIBUTE61);
2764          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE62', l_row.PRICING_ATTRIBUTE62);
2765          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE63', l_row.PRICING_ATTRIBUTE63);
2766          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE64', l_row.PRICING_ATTRIBUTE64);
2767          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE65', l_row.PRICING_ATTRIBUTE65);
2768          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE66', l_row.PRICING_ATTRIBUTE66);
2769          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE67', l_row.PRICING_ATTRIBUTE67);
2770          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE68', l_row.PRICING_ATTRIBUTE68);
2771          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE69', l_row.PRICING_ATTRIBUTE69);
2772          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE70', l_row.PRICING_ATTRIBUTE70);
2773          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE71', l_row.PRICING_ATTRIBUTE71);
2774          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE72', l_row.PRICING_ATTRIBUTE72);
2775          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE73', l_row.PRICING_ATTRIBUTE73);
2776          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE74', l_row.PRICING_ATTRIBUTE74);
2777          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE75', l_row.PRICING_ATTRIBUTE75);
2778          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE76', l_row.PRICING_ATTRIBUTE76);
2779          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE77', l_row.PRICING_ATTRIBUTE77);
2780          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE78', l_row.PRICING_ATTRIBUTE78);
2781          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE79', l_row.PRICING_ATTRIBUTE79);
2782          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE80', l_row.PRICING_ATTRIBUTE80);
2783          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE81', l_row.PRICING_ATTRIBUTE81);
2784          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE82', l_row.PRICING_ATTRIBUTE82);
2785          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE83', l_row.PRICING_ATTRIBUTE83);
2786          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE84', l_row.PRICING_ATTRIBUTE84);
2787          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE85', l_row.PRICING_ATTRIBUTE85);
2788          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE86', l_row.PRICING_ATTRIBUTE86);
2789          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE87', l_row.PRICING_ATTRIBUTE87);
2790          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE88', l_row.PRICING_ATTRIBUTE88);
2791          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE89', l_row.PRICING_ATTRIBUTE89);
2792          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE90', l_row.PRICING_ATTRIBUTE90);
2793          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE91', l_row.PRICING_ATTRIBUTE91);
2794          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE92', l_row.PRICING_ATTRIBUTE92);
2795          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE93', l_row.PRICING_ATTRIBUTE93);
2796          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE94', l_row.PRICING_ATTRIBUTE94);
2797          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE95', l_row.PRICING_ATTRIBUTE95);
2798          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE96', l_row.PRICING_ATTRIBUTE96);
2799          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE97', l_row.PRICING_ATTRIBUTE97);
2800          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE98', l_row.PRICING_ATTRIBUTE98);
2801          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE99', l_row.PRICING_ATTRIBUTE99);
2802          LOAD_TBL(l_row.pricing_context, 'PRICING_ATTRIBUTE100', l_row.PRICING_ATTRIBUTE100);
2803          --qualifiers here QUALIFIER_ATTRIBUTE... is cse sensitive. It should always be uppercase
2804          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE1', l_row.qualifier_ATTRIBUTE1);
2805          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE2', l_row.qualifier_ATTRIBUTE2);
2806          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE3', l_row.qualifier_ATTRIBUTE3);
2807          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE4', l_row.qualifier_ATTRIBUTE4);
2808          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE5', l_row.QUALIFIER_ATTRIBUTE5);
2809          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE6', l_row.QUALIFIER_ATTRIBUTE6);
2810          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE7', l_row.QUALIFIER_ATTRIBUTE7);
2811          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE8', l_row.QUALIFIER_ATTRIBUTE8);
2812          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE9', l_row.QUALIFIER_ATTRIBUTE9);
2813          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE10', l_row.QUALIFIER_ATTRIBUTE10);
2814          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE11', l_row.QUALIFIER_ATTRIBUTE11);
2815          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE12', l_row.QUALIFIER_ATTRIBUTE12);
2816          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE13', l_row.QUALIFIER_ATTRIBUTE13);
2817          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE14', l_row.QUALIFIER_ATTRIBUTE14);
2818          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE15', l_row.QUALIFIER_ATTRIBUTE15);
2819          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE16', l_row.QUALIFIER_ATTRIBUTE16);
2820          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE17', l_row.QUALIFIER_ATTRIBUTE17);
2821          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE18', l_row.QUALIFIER_ATTRIBUTE18);
2822          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE19', l_row.QUALIFIER_ATTRIBUTE19);
2823          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE20', l_row.QUALIFIER_ATTRIBUTE20);
2824          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE21', l_row.QUALIFIER_ATTRIBUTE21);
2825          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE22', l_row.QUALIFIER_ATTRIBUTE22);
2826          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE23', l_row.QUALIFIER_ATTRIBUTE23);
2827          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE24', l_row.QUALIFIER_ATTRIBUTE24);
2828          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE25', l_row.QUALIFIER_ATTRIBUTE25);
2829          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE26', l_row.QUALIFIER_ATTRIBUTE26);
2830          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE27', l_row.QUALIFIER_ATTRIBUTE27);
2831          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE28', l_row.QUALIFIER_ATTRIBUTE28);
2832          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE29', l_row.QUALIFIER_ATTRIBUTE29);
2833          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE30', l_row.QUALIFIER_ATTRIBUTE30);
2834          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE31', l_row.QUALIFIER_ATTRIBUTE31);
2835          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE32', l_row.QUALIFIER_ATTRIBUTE32);
2836          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE33', l_row.QUALIFIER_ATTRIBUTE33);
2837          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE34', l_row.QUALIFIER_ATTRIBUTE34);
2838          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE35', l_row.QUALIFIER_ATTRIBUTE35);
2839          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE36', l_row.QUALIFIER_ATTRIBUTE36);
2840          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE37', l_row.QUALIFIER_ATTRIBUTE37);
2841          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE38', l_row.QUALIFIER_ATTRIBUTE38);
2842          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE39', l_row.qualifier_ATTRIBUTE39);
2843          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE40', l_row.qualifier_ATTRIBUTE40);
2844          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE41', l_row.qualifier_ATTRIBUTE41);
2845          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE42', l_row.qualifier_ATTRIBUTE42);
2846          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE43', l_row.qualifier_ATTRIBUTE43);
2847          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE44', l_row.qualifier_ATTRIBUTE44);
2848          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE45', l_row.qualifier_ATTRIBUTE45);
2849          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE46', l_row.qualifier_ATTRIBUTE46);
2850          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE47', l_row.qualifier_ATTRIBUTE47);
2851          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE48', l_row.qualifier_ATTRIBUTE48);
2852          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE49', l_row.qualifier_ATTRIBUTE49);
2853          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE50', l_row.qualifier_ATTRIBUTE50);
2854          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE51', l_row.qualifier_ATTRIBUTE51);
2855          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE52', l_row.qualifier_ATTRIBUTE52);
2856          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE53', l_row.qualifier_ATTRIBUTE53);
2857          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE54', l_row.qualifier_ATTRIBUTE54);
2858          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE55', l_row.qualifier_ATTRIBUTE55);
2859          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE56', l_row.qualifier_ATTRIBUTE56);
2860          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE57', l_row.qualifier_ATTRIBUTE57);
2861          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE58', l_row.qualifier_ATTRIBUTE58);
2862          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE59', l_row.qualifier_ATTRIBUTE59);
2863          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE60', l_row.qualifier_ATTRIBUTE60);
2864          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE61', l_row.qualifier_ATTRIBUTE61);
2865          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE62', l_row.qualifier_ATTRIBUTE62);
2866          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE63', l_row.qualifier_ATTRIBUTE63);
2867          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE64', l_row.qualifier_ATTRIBUTE64);
2868          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE65', l_row.qualifier_ATTRIBUTE65);
2869          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE66', l_row.qualifier_ATTRIBUTE66);
2870          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE67', l_row.qualifier_ATTRIBUTE67);
2871          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE68', l_row.qualifier_ATTRIBUTE68);
2872          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE69', l_row.qualifier_ATTRIBUTE69);
2873          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE70', l_row.qualifier_ATTRIBUTE70);
2874          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE71', l_row.qualifier_ATTRIBUTE71);
2875          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE72', l_row.qualifier_ATTRIBUTE72);
2876          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE73', l_row.qualifier_ATTRIBUTE73);
2877          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE74', l_row.qualifier_ATTRIBUTE74);
2878          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE75', l_row.qualifier_ATTRIBUTE75);
2879          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE76', l_row.qualifier_ATTRIBUTE76);
2880          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE77', l_row.qualifier_ATTRIBUTE77);
2881          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE78', l_row.qualifier_ATTRIBUTE78);
2882          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE79', l_row.qualifier_ATTRIBUTE79);
2883          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE80', l_row.qualifier_ATTRIBUTE80);
2884          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE81', l_row.qualifier_ATTRIBUTE81);
2885          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE82', l_row.qualifier_ATTRIBUTE82);
2886          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE83', l_row.qualifier_ATTRIBUTE83);
2887          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE84', l_row.qualifier_ATTRIBUTE84);
2888          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE85', l_row.qualifier_ATTRIBUTE85);
2889          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE86', l_row.qualifier_ATTRIBUTE86);
2890          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE87', l_row.qualifier_ATTRIBUTE87);
2891          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE88', l_row.qualifier_ATTRIBUTE88);
2892          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE89', l_row.qualifier_ATTRIBUTE89);
2893          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE90', l_row.qualifier_ATTRIBUTE90);
2894          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE91', l_row.qualifier_ATTRIBUTE91);
2895          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE92', l_row.qualifier_ATTRIBUTE92);
2896          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE93', l_row.qualifier_ATTRIBUTE93);
2897          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE94', l_row.qualifier_ATTRIBUTE94);
2898          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE95', l_row.qualifier_ATTRIBUTE95);
2899          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE96', l_row.qualifier_ATTRIBUTE96);
2900          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE97', l_row.qualifier_ATTRIBUTE97);
2901          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE98', l_row.qualifier_ATTRIBUTE98);
2902          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE99', l_row.qualifier_ATTRIBUTE99);
2903          LOAD_TBL(l_row.qualifier_context, 'QUALIFIER_ATTRIBUTE100', l_row.qualifier_ATTRIBUTE100);
2904      END LOOP;
2905      If okc_pattr_cur%isopen then
2906            close okc_pattr_cur;
2907      ELSIF okc_pattr_cle_cur%isopen then
2908            close okc_pattr_cle_cur;
2909      END IF;
2910     IF (l_debug = 'Y') THEN
2911        my_debug('8700 : Exiting Load_User_Defined_Pattrs', 2);
2912     END IF;
2913     IF (l_debug = 'Y') THEN
2914        okc_debug.Reset_Indentation;
2915     END IF;
2916 
2917 
2918   EXCEPTION
2919     when others then
2920       OKC_API.set_message(p_app_name      => g_app_name,
2921                           p_msg_name      => g_unexpected_error,
2922                           p_token1        => g_sqlcode_token,
2923                           p_token1_value  => sqlcode,
2924                           p_token2        => g_sqlerrm_token,
2925                           p_token2_value  => sqlerrm);
2926        x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
2927        If okc_pattr_cur%isopen then
2928            close okc_pattr_cur;
2929        ELSIF okc_pattr_cle_cur%isopen then
2930            close okc_pattr_cle_cur;
2931        END IF;
2932     IF (l_debug = 'Y') THEN
2933        my_debug('8800 : Exiting Load_User_Defined_Pattrs', 4);
2934     END IF;
2935     IF (l_debug = 'Y') THEN
2936        okc_debug.Reset_Indentation;
2937     END IF;
2938 
2939 END Load_User_Defined_Pattrs;
2940 
2941 ----------------------------------------------------------------------------
2942 -- PROCEDURE BUILD_CHR_CONTEXT
2943 -- This procedure will populate the global table with the data sources
2944 -- and values for them defined at header level
2945 ----------------------------------------------------------------------------
2946 PROCEDURE BUILD_CHR_CONTEXT(
2947           p_api_version             IN         NUMBER ,
2948           p_init_msg_list           IN         VARCHAR2 ,
2949           p_request_type_code       IN         VARCHAR2 ,
2950           p_chr_id                  IN         NUMBER,
2951           p_pricing_type            IN         VARCHAR2    ,
2952           p_line_index              IN         NUMBER ,
2953           x_pricing_contexts_Tbl    OUT NOCOPY QP_PREQ_GRP.LINE_ATTR_TBL_TYPE,
2954           x_qualifier_contexts_Tbl  OUT NOCOPY QP_PREQ_GRP.QUAL_TBL_TYPE,
2955           x_return_status           OUT NOCOPY VARCHAR2,
2956           x_msg_count               OUT NOCOPY NUMBER,
2957           x_msg_data                OUT NOCOPY VARCHAR2) IS
2958 
2959           l_return_status varchar2(1) := OKC_API.G_RET_STS_SUCCESS;
2960           l_api_name constant VARCHAR2(30) := 'BUILD_CHR_CONTEXT';
2961           l_pricing_contexts_Tbl     QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type;
2962           l_qualifier_contexts_Tbl   QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type;
2963           k pls_integer;
2964           l_price_list_id  number := null;
2965           l_count pls_integer := 0;
2966           i pls_integer;
2967 Begin
2968      IF (l_debug = 'Y') THEN
2969         okc_debug.Set_Indentation('BUILD_CHR_CONTEXT');
2970      END IF;
2971      IF (l_debug = 'Y') THEN
2972         my_debug('9000 : Entering BUILD_CHR_CONTEXT', 2);
2973      END IF;
2974 
2975     --dbms_output.put_line('start build_chr_context');
2976 
2977            x_return_status := OKC_API.G_RET_STS_SUCCESS;
2978 
2979            l_return_status := OKC_API.START_ACTIVITY(l_api_name,
2980                                               p_init_msg_list,
2981                                               '_PROCESS',
2982                                                x_return_status);
2983            IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
2984                     raise OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
2985            ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
2986                     raise OKC_API.G_EXCEPTION_ERROR;
2987            END IF;
2988 
2989            -- put values from attached rules in global table
2990            l_return_status:=attach_rules(p_chr_id);
2991            --dbms_output.put_line('2return status'||l_return_status);
2992 
2993            IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
2994                 RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
2995            ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
2996                 RAISE OKC_API.G_EXCEPTION_ERROR;
2997            END IF;
2998            -- put values from attached party roles in global table
2999            l_return_status:=attach_party_roles(p_chr_id);
3000            --dbms_output.put_line('3return status'||l_return_status);
3001 
3002            IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
3003                 RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
3004            ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
3005                 RAISE OKC_API.G_EXCEPTION_ERROR;
3006            END IF;
3007            Load_User_Defined_Pattrs(p_chr_id ,
3008                                    p_line_index ,
3009                                    x_pricing_contexts_Tbl,
3010                                    x_qualifier_contexts_Tbl,
3011                                    x_return_status);
3012            --dbms_output.put_line('4return status'||x_return_status);
3013 
3014            IF x_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
3015                 RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
3016            ELSIF x_return_status = OKC_API.G_RET_STS_ERROR THEN
3017                 RAISE OKC_API.G_EXCEPTION_ERROR;
3018            END IF;
3019                       --call pricing build context
3020            --dbms_output.put_line('5return status'||x_return_status);
3021 
3022            Begin
3023               /*    --dbms_output.put_line('okc_price_pub.g_rul_tbl');
3024                   k:=okc_price_pub.g_rul_tbl.first;
3025                   while k is not null loop
3026                        --dbms_output.put_line('okc_price_pub.g_rul_tbl'||k||'-'||okc_price_pub.g_rul_tbl(k).code);
3027                        --dbms_output.put_line('okc_price_pub.g_rul_tbl'||k||'-'||okc_price_pub.g_rul_tbl(k).current_source);
3028                        --dbms_output.put_line('okc_price_pub.g_rul_tbl'||k||'-'||okc_price_pub.g_rul_tbl(k).source_value);
3029                        k:=okc_price_pub.g_rul_tbl.next(k);
3030                    END LOOP;
3031                   --dbms_output.put_line('okc_price_pub.g_prle_tbl');
3032                   k:=okc_price_pub.g_prle_tbl.first;
3033 
3034                    while k is not null loop
3035                        --dbms_output.put_line('okc_price_pub.g_prle_tbl'||k||'-'||okc_price_pub.g_prle_tbl(k).code);
3036                        --dbms_output.put_line('okc_price_pub.g_prle_tbl'||k||'-'||okc_price_pub.g_prle_tbl(k).current_source);
3037                        --dbms_output.put_line('okc_price_pub.g_prle_tbl'||k||'-'||okc_price_pub.g_prle_tbl(k).source_value);
3038                        k:=okc_price_pub.g_prle_tbl.next(k);
3039                    END LOOP;
3040 
3041 */
3042                   -- populate global record g_contract_info
3043                   OKC_PRICE_PUB.G_CONTRACT_INFO:=null;
3044                   Begin
3045                       select INV_ORGANIZATION_ID,price_list_id,authoring_org_id,nvl(pricing_date,sysdate)
3046                       into OKC_PRICE_PUB.G_CONTRACT_INFO.INV_ORG_ID , l_price_list_id,g_authoring_org_id,OKC_PRICE_PUB.G_CONTRACT_INFO.PRICING_DATE
3047                       from okc_k_headers_b
3048                       where id = p_chr_id;
3049 
3050                    EXCEPTION
3051                      when no_data_found then
3052                           IF (l_debug = 'Y') THEN
3053                              my_debug('9020 : NO authoring org id found', 1);
3054                           END IF;
3055                  END;
3056 -- Bug:2695614 Changes for Price Hold
3057                Begin
3058                       select chr_id_referred
3059                       into OKC_PRICE_PUB.G_CONTRACT_INFO.governing_contract_id
3060                       from okc_governances
3061                       where dnz_chr_id = p_chr_id
3062                       and cle_id is null
3063                       and rownum=1;
3064 
3065                    EXCEPTION
3066                      when no_data_found then
3067                           IF (l_debug = 'Y') THEN
3068                              my_debug('9020 : No Governing Contract Found', 1);
3069                           END IF;
3070                  END;
3071 
3072 -- end Bug:2695614
3073 			  -- Modified for Bug 2292742
3074 
3075                  --OKC_PRICE_PUB.G_CONTRACT_INFO.PRICING_DATE:=SYSDATE;
3076 			  g_hdr_pricing_date := OKC_PRICE_PUB.G_CONTRACT_INFO.PRICING_DATE;
3077                   --populate global variable sold_to_org_id. made it global as it is used
3078                   -- at many places for build context functions
3079                  OKC_PRICE_PUB.G_CONTRACT_INFO.SOLD_TO_ORG_ID :=
3080                               GET_RUL_SOURCE_VALUE(OKC_PRICE_PUB.G_RUL_TBL,'CAN','OKX_CUSTACCT');
3081 
3082                 -- add header level pricelist as an attrib if found
3083                 IF  l_price_list_id is not null then
3084                         g_hdr_pricelist:= l_price_list_id;
3085                         l_count := x_qualifier_contexts_Tbl.count +1;
3086                          x_qualifier_contexts_Tbl(l_count).LINE_INDEX := p_line_index;
3087                          x_qualifier_contexts_Tbl(l_count).QUALIFIER_CONTEXT :='MODLIST';
3088                          x_qualifier_contexts_Tbl(l_count).QUALIFIER_ATTRIBUTE :='QUALIFIER_ATTRIBUTE4';
3089                          x_qualifier_contexts_Tbl(l_count).QUALIFIER_ATTR_VALUE_FROM := to_char(l_price_list_id); -- Price List Id
3090                          x_qualifier_contexts_Tbl(l_count).COMPARISON_OPERATOR_CODE := '=';
3091                          --x_qualifier_contexts_Tbl(l_count).VALIDATED_FLAG :='Y';
3092                          x_qualifier_contexts_Tbl(l_count).VALIDATED_FLAG :='N'; --Bug 2760904: we need QP to validate the price list
3093                END IF;
3094                  IF (l_debug = 'Y') THEN
3095                     my_debug('9030 : G_CONTRACT_INFO.PRICING_DATE for header'||OKC_PRICE_PUB.G_CONTRACT_INFO.PRICING_DATE,1);
3096                     my_debug('9040 : G_CONTRACT_INFO.INV_ORG_ID for header'||OKC_PRICE_PUB.G_CONTRACT_INFO.INV_ORG_ID, 1);
3097                     my_debug('9050 : G_CONTRACT_INFO.SOLD_TO_ORG_ID for header'||OKC_PRICE_PUB.G_CONTRACT_INFO.SOLD_TO_ORG_ID, 1);
3098                     my_debug('9060 : G_CONTRACT_INFO.Inventory id for header'||OKC_PRICE_PUB.G_CONTRACT_INFO.INVENTORY_ITEM_ID, 1);
3099                     my_debug('9070 : G_CONTRACT_INFO.top_model_line for header'||OKC_PRICE_PUB.G_CONTRACT_INFO.TOP_MODEL_LINE_ID, 1);
3100                     my_debug('9072 : Price list id for header'||l_price_list_id, 1);
3101                  END IF;
3102 
3103                 -- call build context
3104                 IF (l_debug = 'Y') THEN
3105                    my_debug('9060 : Before Call Build Context for header for request type'||p_request_type_code, 1);
3106                 END IF;
3107                 QP_Attr_Mapping_PUB.Build_Contexts(p_request_type_code => p_request_type_code,
3108 			                                         p_pricing_type	=>	p_pricing_type,
3109 			                                         x_price_contexts_result_tbl => l_pricing_contexts_Tbl,
3110 			                                         x_qual_contexts_result_tbl  => l_qualifier_Contexts_Tbl);
3111                 IF (l_debug = 'Y') THEN
3112                    my_debug('9070 : After Call Build Context for header', 1);
3113                 END IF;
3114                 -- copy header values to copy them to line global tbls, in case not found on line
3115                   g_hdr_rul_tbl:=okc_price_pub.g_rul_tbl;
3116                   g_hdr_prle_tbl:=okc_price_pub.g_prle_tbl;
3117                   If g_hdr_rul_tbl.count >0 then
3118                     i:=g_hdr_rul_tbl.first-1;
3119                     g_hdr_rul_tbl(i).code :='CHR_ID';
3120                     g_hdr_rul_tbl(i).source_value := p_chr_id;
3121                   end if;
3122                   If g_hdr_prle_tbl.count >0 then
3123                     i:=g_hdr_prle_tbl.first-1;
3124                     g_hdr_prle_tbl(i).code :='CHR_ID';
3125                     g_hdr_prle_tbl(i).source_value := p_chr_id;
3126                   end if;
3127 
3128                   okc_price_pub.g_rul_tbl.DELETE;
3129                   okc_price_pub.g_prle_tbl.DELETE;
3130                   OKC_PRICE_PUB.G_CONTRACT_INFO:=null;
3131 
3132               Exception
3133                   When Others then
3134                       --dbms_output.put_line('error'||substr(sqlerrm,1,240));
3135                       OKC_API.set_message(p_app_name      => g_app_name,
3136                                       p_msg_name      => 'OKC_QP_INT_ERROR',
3137                                       p_token1        => 'Proc',
3138                                       p_token1_value  => 'Build_Context for Header',
3139                                       p_token2        => 'SQLCODE',
3140                                       p_token2_value  => SQLCODE,
3141                                       p_token3        => 'Err_TEXT',
3142                                       p_token3_value  => SQLERRM);
3143                       Raise OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
3144            End; --call pricing build context
3145            -- copy build context attribs to request table
3146 
3147            copy_attribs_to_Req(
3148                   p_line_index
3149                  ,l_pricing_contexts_Tbl
3150                  ,l_qualifier_contexts_Tbl
3151                  ,x_pricing_contexts_Tbl
3152                  ,x_qualifier_contexts_Tbl);
3153 
3154    OKC_API.END_ACTIVITY(x_msg_count, x_msg_data);
3155 
3156     IF (l_debug = 'Y') THEN
3157        my_debug('9600 : Exiting BUILD_CHR_CONTEXT', 2);
3158     END IF;
3159     IF (l_debug = 'Y') THEN
3160        okc_debug.Reset_Indentation;
3161     END IF;
3162 
3163   EXCEPTION
3164 
3165           WHEN OKC_API.G_EXCEPTION_ERROR THEN
3166               x_return_status := OKC_API.HANDLE_EXCEPTIONS
3167                        (l_api_name,
3168                         G_PKG_NAME,
3169                        'OKC_API.G_RET_STS_ERROR',
3170                         x_msg_count,
3171                         x_msg_data,
3172                         '_PROCESS');
3173                IF (l_debug = 'Y') THEN
3174                   my_debug('9700 : Exiting BUILD_CHR_CONTEXT', 4);
3175                END IF;
3176                IF (l_debug = 'Y') THEN
3177                   okc_debug.Reset_Indentation;
3178                END IF;
3179 
3180          WHEN OKC_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
3181               x_return_status := OKC_API.HANDLE_EXCEPTIONS
3182                        (l_api_name,
3183                         G_PKG_NAME,
3184                        'OKC_API.G_RET_STS_UNEXP_ERROR',
3185                         x_msg_count,
3186                         x_msg_data,
3187                         '_PROCESS');
3188                 IF (l_debug = 'Y') THEN
3189                    my_debug('9800 : Exiting BUILD_CHR_CONTEXT', 4);
3190                 END IF;
3191                IF (l_debug = 'Y') THEN
3192                   okc_debug.Reset_Indentation;
3193                END IF;
3194 
3195          WHEN OTHERS THEN
3196               OKC_API.set_message(p_app_name      => g_app_name,
3197                                  p_msg_name      => g_unexpected_error,
3198                                  p_token1        => g_sqlcode_token,
3199                                  p_token1_value  => sqlcode,
3200                                  p_token2        => g_sqlerrm_token,
3201                                  p_token2_value  => sqlerrm);
3202             x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
3203             IF (l_debug = 'Y') THEN
3204                my_debug('9900 : Exiting BUILD_CHR_CONTEXT', 4);
3205             END IF;
3206             IF (l_debug = 'Y') THEN
3207                okc_debug.Reset_Indentation;
3208             END IF;
3209 
3210 END BUILD_CHR_CONTEXT;
3211 
3212 ---------------------------------------------------------------------------
3213 --Procedure - get_line_ids
3214 -- This Procedure will return the ids of the line that will make a request line
3215 --p_cle_id - Id of the priced line
3216 --x_line_tbl- This table will hold the line ids rec for all the lines that
3217 -- make a request line.For related lines, it will hold both the PI as well BPI
3218 ----------------------------------------------------------------------------
3219 Procedure get_line_ids (p_chr_id                 NUMBER,
3220                         p_cle_id                 NUMBER ,
3221                         x_return_status   IN OUT NOCOPY varchar2,
3222                         x_line_tbl        OUT NOCOPY    line_TBL_TYPE,
3223                         x_bpi_ind          OUT NOCOPY    NUMBER ,
3224                         x_pi_ind           OUT NOCOPY    NUMBER
3225 ) IS
3226 
3227      Cursor l_item_csr(p_cle_id NUMBER,p_chr_id NUMBER) is
3228         SELECT object1_id1, object1_id2, jtot_object1_code, uom_code,number_of_items
3229         FROM okc_k_items
3230         where cle_id = p_cle_id and dnz_chr_id=p_chr_id;
3231 
3232      Cursor l_item_csr1(p_cle_id NUMBER) is
3233         SELECT number_of_items
3234         FROM okc_k_items
3235         where Cle_id = p_cle_id and dnz_chr_id=p_chr_id;
3236 
3237 
3238 --Bug 2543687
3239     Cursor l_cle_pl(p_cle_id NUMBER) is
3240 	 Select price_list_id from okc_k_lines_b
3241 		   where id = p_cle_id;
3242 
3243 
3244      TYPE Cur_tab_type is table of okc_k_lines_b.currency_code%type;
3245      TYPE Date_tbl_type is table of DATE INDEX BY BINARY_INTEGER;
3246 
3247     l_id                num_tbl_type;
3248     l_cur               Cur_tab_type;
3249     l_pricelist_id      num_tbl_type;
3250     l_price_tbl         num_tbl_type;
3251     l_list_price_tbl    num_tbl_type;
3252     l_unit_price_tbl    num_tbl_type;
3253     l_top_model_tbl     num_tbl_type;
3254     l_prc_date_tbl      Date_tbl_type;
3255     l_end_date_tbl      Date_tbl_type;
3256     l_cle_id_tbl       num_tbl_type;
3257 
3258     l_p                flag_tab_type;
3259     l_pi               flag_tab_type;
3260     l_bpi              flag_tab_type;
3261     l_srvc             flag_tab_type;
3262     l_item_row  l_item_csr%rowtype;
3263 
3264     l_p_ind  number :=0; -- should always be 1 as we assume that we are getting the id of priced item
3265     i pls_integer :=0;
3266     l_item_row1 l_item_csr1%rowtype;
3267  BEGIN
3268     IF (l_debug = 'Y') THEN
3269        okc_debug.Set_Indentation('get_line_ids');
3270     END IF;
3271     IF (l_debug = 'Y') THEN
3272        my_debug('10000 : Entering get_line_ids', 2);
3273     END IF;
3274      x_return_status := OKC_API.G_RET_STS_SUCCESS;
3275      x_bpi_ind :=0;
3276      x_pi_ind  :=0;
3277      OKC_PRICE_PUB.G_CONTRACT_INFO.top_model_line_id:=null;
3278      select id,currency_code,price_level_ind
3279      ,item_to_price_yn,price_basis_yn,nvl(service_item_yn,'N'),price_list_id,price_negotiated,line_list_price,price_unit,config_top_model_line_id,nvl(pricing_date,g_hdr_pricing_date),end_date,cle_id
3280      BULK COLLECT INTO l_id,l_cur, l_p
3281       ,l_pi, l_bpi,l_srvc,l_pricelist_id,l_price_tbl,l_list_price_tbl,l_unit_price_tbl, l_top_model_tbl,l_prc_date_tbl,l_end_date_tbl,l_cle_id_tbl
3282      from okc_k_lines_b
3283      connect by prior cle_id = id
3284      start with id=p_cle_id;
3285      IF (l_debug = 'Y') THEN
3286         my_debug('10005 : select rowcount for lines fetched'||SQL%ROWCOUNT, 1);
3287      END IF;
3288 
3289      IF (l_debug = 'Y') THEN
3290         my_debug('10010 :priced line in question'||p_cle_id);
3291      END IF;
3292 
3293      IF l_id.count>0 then
3294         i:= l_id.FIRST;
3295         While i is not null loop
3296              -- for configurator lines, we just want to include the config line in question and its parents
3297              -- from top model line upwards. If there are any other parents in between, they have to be
3298              -- ignored.
3299              If  ((l_top_model_tbl(i) is null)
3300                  OR  (l_top_model_tbl(i) is not null and (l_id(i) = l_top_model_tbl(i) OR  l_id(i) = p_cle_id)))
3301              then   --#filter dummy config parents
3302                  OPEN l_item_csr(l_id(i),p_chr_id);
3303                  Fetch l_item_csr into l_item_row;
3304                  -- set p_yn , pi_yn flag to 'N' for top model dummy config line
3305                  If (l_top_model_tbl(i) is not null and l_id(i) = l_top_model_tbl(i)) then
3306                      l_p(i) := 'N';
3307                      l_pi(i) := 'N';
3308                      OKC_PRICE_PUB.G_CONTRACT_INFO.top_model_line_id :=l_item_row.object1_id1;
3309                  END IF;
3310 
3311                  x_line_tbl(i).id             := l_id(i);
3312                  x_line_tbl(i).currency       := l_cur(i);
3313                  x_line_tbl(i).p_yn           := l_p(i);
3314                  x_line_tbl(i).service_yn     := l_srvc(i);
3315 
3316 			  If( l_end_date_tbl(i)  is not null AND
3317                    (l_prc_date_tbl(i) > l_end_date_tbl(i))) then
3318                    x_line_tbl(i).pricing_date   := sysdate;
3319                  Else
3320 				x_line_tbl(i).pricing_date   := l_prc_date_tbl(i);
3321                  End If;
3322 --Bug Tope
3323                  If l_item_row.jtot_object1_code in  ('OKX_COVLINE','OKX_CUSTITEM','OKX_CUSTPROD')
3324                     AND ( l_pricelist_id(i) is  null OR l_pricelist_id(i) = OKC_API.G_MISS_NUM ) THEN
3325                     For cle_pl_rec in l_cle_pl(l_cle_id_tbl(i)) Loop
3326                       l_pricelist_id(i):= cle_pl_rec.price_list_id;
3327                        -- my_debug('price for the serv is '|| cle_pl_rec.price_list_id);
3328                     End Loop;
3329                  End If;
3330 
3331                  If l_pricelist_id(i) is not null then
3332                     x_line_tbl(i).pricelist_id   := l_pricelist_id(i);
3333                  ELSE
3334                     x_line_tbl(i).pricelist_id   := g_hdr_pricelist;
3335                  END IF;
3336 
3337                  IF (l_debug = 'Y') THEN
3338                     my_debug('10015 :id of line in question'||l_id(i));
3339                     my_debug('10017 :currency '||l_cur(i));
3340                     my_debug('10019 :priced flag on line'||l_p(i));
3341                     my_debug('10021 :pricelist id'||l_pricelist_id(i));
3342                     my_debug('10023 :item_to_price flag'||l_pi(i));
3343                     my_debug('10025 :bprice basis  flag'||l_bpi(i));
3344                  END IF;
3345 
3346                  -- the condition below should never arise if code is correct
3347                  If l_p(i)='Y' and i <> 1 then
3348                    close l_item_csr;
3349                    RAISE l_exception_stop;
3350                  END IF;
3351                  -- we are right now setting all pi and bpi 'N' so that after loop finishes
3352                  -- we will set the highest pi index as 'Y' and highest 'BPI' as 'Y'
3353                  -- This we are doing because of recursive line styles
3354                  x_line_tbl(i).pi_yn          := 'N';
3355                  x_line_tbl(i).bpi_yn         := 'N';
3356                  IF l_pi(i) = 'Y' then
3357                   x_pi_ind := i;
3358                  END IF;
3359                  IF l_bpi(i) = 'Y' then
3360                   x_bpi_ind := i;
3361                  END IF;
3362 
3363                  x_line_tbl(i).qty            := l_item_row.number_of_items;
3364 
3365  --Tope Bug 2386767
3366                  ---IF l_item_row.jtot_object1_code = 'OKX_COVLINE' Then
3367                  IF l_item_row.jtot_object1_code = 'OKX_COVLINE' AND g_qa_mode <> 'Y' Then  --abkumar Bug 2503412
3368                    IF (l_debug = 'Y') THEN
3369                       my_debug('id1 is '||l_item_row.object1_id1);
3370                    END IF;
3371 			    Open l_item_csr1(l_item_row.object1_id1);
3372                    Fetch l_item_csr1 into l_item_row1;
3373 
3374                    If l_item_csr1%found and ((l_item_row1.number_of_items <> x_line_tbl(i).qty)
3375 				   and (l_item_row1.number_of_items is not null)) Then
3376                          x_line_tbl(i).qty            := l_item_row1.number_of_items ;
3377 
3378                          Update okc_k_items
3379                          set number_of_items=l_item_row1.number_of_items
3380                          where cle_id = x_line_tbl(i).id
3381                          and dnz_chr_id = p_chr_id;
3382                          IF (l_debug = 'Y') THEN
3383                             my_debug ('Updated with Service qty'||l_item_row1.number_of_items);
3384                          END IF;
3385                     End If;
3386 				Close l_item_csr1;
3387                   End IF;
3388 ---
3389                  x_line_tbl(i).uom_code       := l_item_row.uom_code;
3390                  x_line_tbl(i).object_code    := l_item_row.jtot_object1_code;
3391                  x_line_tbl(i).id1            := l_item_row.object1_id1;
3392                  x_line_tbl(i).id2            := l_item_row.object1_id2;
3393                  If x_line_tbl(i).qty is not null and l_list_price_tbl(i)is not null and l_price_tbl(i) is not null then
3394                     If l_unit_price_tbl(i) is null then
3395                         x_line_tbl(i).unit_price  := l_list_price_tbl(i);
3396                     Else
3397                         x_line_tbl(i).unit_price  := l_unit_price_tbl(i);
3398                     End If;
3399                     --???? round off errors
3400                     x_line_tbl(i).updated_price  := nvl(l_price_tbl(i),0)/x_line_tbl(i).qty;
3401                  End if;
3402                  close l_item_csr;
3403              END IF; -- # end filter dummy config parents
3404              i:= l_id.next(i);
3405         END LOOP;
3406      END IF; -- l_id.count
3407      If l_item_csr%isopen then
3408            close l_item_csr;
3409      END IF;
3410 
3411      If x_pi_ind <>0 then
3412          x_line_tbl(x_pi_ind).pi_yn:='Y';
3413      END IF;
3414      IF x_bpi_ind <> 0 then
3415          x_line_tbl(x_bpi_ind).bpi_yn:='Y';
3416      END IF;
3417     IF (l_debug = 'Y') THEN
3418        my_debug('10700 : Exiting get_line_ids', 2);
3419     END IF;
3420     IF (l_debug = 'Y') THEN
3421        okc_debug.Reset_Indentation;
3422     END IF;
3423 
3424 
3425   EXCEPTION
3426     WHEN l_exception_stop then
3427        --dbms_output.put_line('some thing wrong in code. This should not be reached');
3428        x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
3429        If l_item_csr%isopen then
3430            close l_item_csr;
3431        END IF;
3432     IF (l_debug = 'Y') THEN
3433        my_debug('10800 : Exiting get_line_ids', 4);
3434     END IF;
3435     IF (l_debug = 'Y') THEN
3436        okc_debug.Reset_Indentation;
3437     END IF;
3438 
3439     when others then
3440       OKC_API.set_message(p_app_name      => g_app_name,
3441                           p_msg_name      => g_unexpected_error,
3442                           p_token1        => g_sqlcode_token,
3443                           p_token1_value  => sqlcode,
3444                           p_token2        => g_sqlerrm_token,
3445                           p_token2_value  => sqlerrm);
3446        x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
3447        If l_item_csr%isopen then
3448            close l_item_csr;
3449        END IF;
3450     IF (l_debug = 'Y') THEN
3451        my_debug('10900 : Exiting get_line_ids', 4);
3452     END IF;
3453     IF (l_debug = 'Y') THEN
3454        okc_debug.Reset_Indentation;
3455     END IF;
3456 
3457 END get_line_ids;
3458 
3459 
3460 ----------------------------------------------------------------------------
3461 -- PROCEDURE BUILD_CLE_CONTEXT
3462 -- This procedure will populate the global table with the data sources
3463 -- and values for them defined at line level
3464 -- p_cle_id - The Priced Line Id.
3465 ----------------------------------------------------------------------------
3466 
3467 PROCEDURE BUILD_CLE_CONTEXT(
3468           p_api_version             IN         NUMBER ,
3469           p_init_msg_list           IN         VARCHAR2 ,
3470           p_request_type_code       IN         VARCHAR2 ,
3471           p_chr_id                  IN         NUMBER,
3472           P_line_tbl                IN         line_TBL_TYPE,
3473           p_pricing_type            IN         VARCHAR2    ,
3474           p_line_index              IN         NUMBER    ,
3475           p_service_price           IN VARCHAR2 ,
3476           p_service_price_list      IN VARCHAR2 DEFAULT NULL,
3477           x_pricing_contexts_Tbl    IN OUT NOCOPY  QP_PREQ_GRP.LINE_ATTR_TBL_TYPE,
3478           x_qualifier_contexts_Tbl  IN OUT NOCOPY  QP_PREQ_GRP.QUAL_TBL_TYPE,
3479           x_return_status           OUT NOCOPY VARCHAR2,
3480           x_msg_count               OUT NOCOPY NUMBER,
3481           x_msg_data                OUT NOCOPY VARCHAR2) IS
3482 
3483           i pls_integer :=0;
3484           l_return_status varchar2(1) := OKC_API.G_RET_STS_SUCCESS;
3485           l_api_name constant VARCHAR2(30) := 'BUILD_CLE_CONTEXT';
3486           l_pricing_contexts_Tbl     QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type;
3487           l_qualifier_contexts_Tbl   QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type;
3488           k pls_integer;
3489           line_attr_rec               QP_PREQ_GRP.LINE_ATTR_REC_TYPE;
3490           qual_rec                    QP_PREQ_GRP.QUAL_REC_TYPE;
3491 
3492 
3493           l_lse_rec     global_lse_rec_type;
3494           l_prle_rec    global_rprle_rec_type;
3495           t pls_integer :=0;
3496           inv_id1     number := 0;
3497           pricelist   number;
3498 
3499 		Cursor covered_prod_csr(p_id number) is
3500 		 Select inventory_item_id
3501 		 from okx_customer_products_v
3502 		 where id1=p_id
3503 		 and status='A'
3504 		 and organization_id=g_authoring_org_id;
3505 Begin
3506     IF (l_debug = 'Y') THEN
3507        okc_debug.Set_Indentation('BUILD_CLE_CONTEXT');
3508     END IF;
3509     IF (l_debug = 'Y') THEN
3510        my_debug('11000 : Entering BUILD_CLE_CONTEXT', 2);
3511     END IF;
3512 
3513            x_return_status := OKC_API.G_RET_STS_SUCCESS;
3514 
3515            l_return_status := OKC_API.START_ACTIVITY(l_api_name,
3516                                               p_init_msg_list,
3517                                               '_PROCESS',
3518                                                x_return_status);
3519            IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
3520                     raise OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
3521            ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
3522                     raise OKC_API.G_EXCEPTION_ERROR;
3523            END IF;
3524 
3525           IF (l_debug = 'Y') THEN
3526              my_debug('11010 : number of lines in heirarchy '||p_line_tbl.count,1);
3527           END IF;
3528           If p_line_tbl.count > 0 then
3529                i:= p_line_tbl.first;
3530                while i is not null loop -- lines loop
3531                       IF (l_debug = 'Y') THEN
3532                          my_debug('11020 : index number '||i,1);
3533                          my_debug('11030 : Id of line under process '||p_line_tbl(i).id,1);
3534                          my_debug('11035 : value of pi_yn flag '||p_line_tbl(i).pi_yn,1);
3535                          my_debug('11036 : value of bpi_yn flag '||p_line_tbl(i).bpi_yn,1);
3536                          my_debug('11037 : value of pricing_date  '||p_line_tbl(i).pricing_date,1);
3537                       END IF;
3538 
3539                        If p_line_tbl(i).pi_yn ='N' and p_line_tbl(i).bpi_yn = 'N'
3540                        then
3541                        --right now only id1 is going. Free format line styles
3542                        -- are mapped with hypothetical object code 'OKX_FREE'
3543                            If p_line_tbl(i).object_code is not null then --object_code not null
3544                               l_lse_rec.current_source := p_line_tbl(i).object_code;
3545                               l_lse_rec.source_value   := p_line_tbl(i).id1;
3546                               l_return_status :=ADD_TO_GLOBAL_LSE_TBL(l_lse_rec);
3547 
3548                                IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
3549                                   RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
3550                                ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
3551                                  RAISE OKC_API.G_EXCEPTION_ERROR;
3552                                END IF;
3553                            ELSIF p_line_tbl(i).object_code is null then --object_code not null
3554                                 -- the following pricing context ALL is being sent as for some cases
3555                                 -- like top line priced free format line styles the item is not comimg
3556                                 -- from inventory and the user still wants to price it.
3557                                 -- So , we send this generic parameter, so that if in Pricing there
3558                                 -- is some price defined for all items when price for item to be priced
3559                                 -- cannot be found, this will fetch that price.
3560                                  line_attr_rec.line_index := p_line_index;
3561                                  line_attr_rec.PRICING_CONTEXT :='ITEM';
3562                                  line_attr_rec.PRICING_ATTRIBUTE :='PRICING_ATTRIBUTE3';
3563                                  line_attr_rec.PRICING_ATTR_VALUE_FROM  := 'ALL'; -- generic value
3564                                  line_attr_rec.VALIDATED_FLAG :='N';
3565                                  x_pricing_contexts_Tbl(nvl(x_pricing_contexts_Tbl.last,0)+1):= line_attr_rec;
3566                                  OKC_PRICE_PUB.G_CONTRACT_INFO.inventory_item_id := null;
3567                                  -- Along with send ITEM_ALL attrib, we will map free line styles
3568                                  -- with dummy object code 'OKX_FREE', so that if the user has defined
3569                                  -- some attrib in pricing context ITEM which picks varchar2 value and
3570                                  -- then using it has defined a unit price for that attrib in price list
3571                                  -- it gets picked. Here we are populating the global lse table with
3572                                  -- object code 'OKX_FREE' and value in column name instead of Id1.
3573                                  BEGIN
3574                                     select name into l_lse_rec.source_value
3575                                     FROM okc_k_lines_v
3576                                     where id=p_line_tbl(i).id;
3577 
3578                                     l_lse_rec.current_source := 'OKX_FREE';
3579                                     l_return_status :=ADD_TO_GLOBAL_LSE_TBL(l_lse_rec);
3580 
3581                                     IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
3582                                         RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
3583                                     ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
3584                                         RAISE OKC_API.G_EXCEPTION_ERROR;
3585                                     END IF;
3586 
3587                                    EXCEPTION
3588                                     WHEN NO_DATA_FOUND then
3589                                       null;
3590                                   END;
3591 
3592                                  IF (l_debug = 'Y') THEN
3593                                     my_debug('11049 : object code not found ',1);
3594                                  END IF;
3595                             End if; --end object_code is not null
3596                         -- For covered line/product/item build attributes tbl
3597                             If p_service_price =   'Y' and p_line_tbl(i).p_yn='Y' then
3598                               line_attr_rec.line_index := p_line_index;
3599                               line_attr_rec.PRICING_CONTEXT :='ITEM';
3600                               line_attr_rec.PRICING_ATTRIBUTE :='PRICING_ATTRIBUTE1';
3601                             -- For covered lines get inventory id from lines
3602                               If p_line_tbl(i).object_code = 'OKX_COVLINE' then
3603 
3604                                select object1_id1 into inv_id1
3605                                from okc_k_items
3606                                where cle_id = p_line_tbl(1).id1;
3607 
3608                                line_attr_rec.PRICING_ATTR_VALUE_FROM  := inv_id1;
3609                                OKC_PRICE_PUB.G_CONTRACT_INFO.inventory_item_id := inv_id1;
3610                               ------Elsif  p_line_tbl(i).object_code in ('OKX_CUSTPOD','OKX_CUSTITEM') then
3611                               Elsif  p_line_tbl(i).object_code in ('OKX_CUSTPROD','OKX_CUSTITEM') then
3612 						  Open covered_prod_csr(p_line_tbl(i).id1);
3613 						  Fetch covered_prod_csr into inv_id1;
3614 						  Close  covered_prod_csr;
3615 						  IF (l_debug = 'Y') THEN
3616    						  my_debug('11049 inventory id covered :'|| inv_id1);
3617 						  END IF;
3618                                 line_attr_rec.PRICING_ATTR_VALUE_FROM  := inv_id1 ;
3619                                 OKC_PRICE_PUB.G_CONTRACT_INFO.inventory_item_id := inv_id1;
3620                               End If;
3621                               line_attr_rec.VALIDATED_FLAG :='N';
3622                               x_pricing_contexts_Tbl(nvl(x_pricing_contexts_Tbl.last,0)+1):= line_attr_rec;
3623                               IF (l_debug = 'Y') THEN
3624                                  my_debug('11050 : Item Id '||p_line_tbl(i).id1,1);
3625                               END IF;
3626                             End If;
3627                        ELSIF p_line_tbl(i).pi_yn ='Y'  then
3628                             line_attr_rec.line_index := p_line_index;
3629                             line_attr_rec.PRICING_CONTEXT :='ITEM';
3630                             line_attr_rec.PRICING_ATTRIBUTE :='PRICING_ATTRIBUTE1';
3631 
3632 
3633                              -- Inventory Item Id
3634                             line_attr_rec.PRICING_ATTR_VALUE_FROM  := p_line_tbl(i).id1;
3635 
3636                             line_attr_rec.VALIDATED_FLAG :='N';
3637                             OKC_PRICE_PUB.G_CONTRACT_INFO.inventory_item_id := p_line_tbl(i).id1;
3638                             x_pricing_contexts_Tbl(nvl(x_pricing_contexts_Tbl.last,0)+1):= line_attr_rec;
3639                             IF (l_debug = 'Y') THEN
3640                                my_debug('11050 : Item Id '||p_line_tbl(i).id1,1);
3641                             END IF;
3642 
3643  -- Bug:2695614 Changes for Price Hold
3644                             Begin
3645                                 select chr_id_referred
3646                                 into OKC_PRICE_PUB.G_CONTRACT_INFO.governing_contract_id
3647                                 from okc_governances
3648                                 where dnz_chr_id = p_chr_id
3649                                 and cle_id =p_line_tbl(i).id
3650                                 and rownum=1;
3651 
3652                        EXCEPTION
3653                          when no_data_found then
3654                               IF (l_debug = 'Y') THEN
3655                                  my_debug('9020 : Governing Contract not Found', 1);
3656                               END IF;
3657                        END;
3658 
3659 --End Bug:2695614
3660 
3661                       ELSIF p_line_tbl(i).bpi_yn ='Y' then
3662                        -- assuming pi and bpi will never be there on the same line
3663                           If p_line_tbl(i).object_code is not null then
3664                              --here we will pass OKX_MTL_SYSTEM_ITEM as object_code and not actual object code
3665                              --as the BPI can be a product or something else and then product can come from many views
3666                              -- with different names but the common thing
3667                              --in all these views is that they all have usage 'OKX_MTL_SYSTEM_ITEM'
3668                              -- we could have hardcoded the passing but didnot
3669                              -- because of BPI as the source of BPI could be a product or something else
3670                              --as well like Customer Item. Hence decided to map this to item if it is
3671                              -- product
3672                              BEGIN
3673                                select 'OKX_MTL_SYSTEM_ITEM' into l_lse_rec.current_source
3674                                from JTF_OBJECT_USAGES
3675                                where object_code= p_line_tbl(i).object_code
3676                                and OBJECT_USER_CODE = 'OKX_MTL_SYSTEM_ITEM';
3677                                IF (l_debug = 'Y') THEN
3678                                   my_debug('11060 : rowcount for OBJECT_USER_CODE '||SQL%ROWCOUNT,1);
3679                                END IF;
3680                                -- since this is an inventory item, assigning it to inventory_id
3681                                OKC_PRICE_PUB.G_CONTRACT_INFO.inventory_item_id := p_line_tbl(i).id1;
3682 
3683                                EXCEPTION
3684                                 WHEN NO_DATA_FOUND THEN
3685                                     IF (l_debug = 'Y') THEN
3686                                        my_debug('11060 : OKX_MTL_SYSTEM_ITEM not assigned '||p_line_tbl(i).object_code,1);
3687                                     END IF;
3688                                     l_lse_rec.current_source := p_line_tbl(i).object_code;
3689 
3690                               END;
3691                               l_lse_rec.source_value   := p_line_tbl(i).id1;
3692                               l_return_status :=ADD_TO_GLOBAL_LSE_TBL(l_lse_rec);
3693 
3694                                IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
3695                                   RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
3696                                ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
3697                                  RAISE OKC_API.G_EXCEPTION_ERROR;
3698                                END IF;
3699                           End if; -- if p_line_tbl(i).object_code is not null
3700                        END IF; -- pi_yn<> 'Y'
3701                        --attach pricelist if availavble
3702                        --attach for pi as well when pricing for service
3703                        IF (p_line_tbl(i).p_yn ='Y'  or  (p_service_price = 'Y' and (p_line_tbl(i).pi_yn ='Y')))
3704                           Then
3705                           /**********
3706                           and (p_line_tbl(i).pricelist_id is not null )and  (p_line_tbl(i).pricelist_id <> OKC_API.G_MISS_NUM) then
3707                             qual_rec.LINE_INDEX := p_line_index;
3708                             qual_rec.QUALIFIER_CONTEXT :='MODLIST';
3709                             qual_rec.QUALIFIER_ATTRIBUTE :='QUALIFIER_ATTRIBUTE4';
3710                             --qual_rec.QUALIFIER_ATTR_VALUE_FROM := to_char(p_line_tbl(i).pricelist_id); -- Price List Id
3711                            ***********/
3712                            --commented out for Bug 2774859: the service line may not have a price list attached to it
3713                            --in which case, we go on to get the price list from the covered line
3714 
3715 
3716                            --bug 2543687
3717                              If p_line_tbl(i).p_yn = 'Y' and p_service_price = 'Y' and
3718                                p_line_tbl(i).object_code in ('OKX_COVLINE')Then
3719                                begin
3720 
3721                                  select price_list_id into  pricelist from okc_k_lines_b
3722                                  where id = p_line_tbl(i).id1;
3723                                  If pricelist is not null Then
3724                                       qual_rec.QUALIFIER_ATTR_VALUE_FROM := pricelist;
3725                                  Else
3726                                       qual_rec.QUALIFIER_ATTR_VALUE_FROM := to_char(p_line_tbl(i).pricelist_id);
3727                                  End If;
3728                                Exception
3729                                   when others then
3730                                      IF (l_debug = 'Y') THEN
3731 								my_debug(' No price list in non service item');
3732                                      END IF;
3733                                End;
3734                             Elsif p_service_price = 'Y' and  (p_line_tbl(i).pi_yn ='Y') and p_service_price_list is not null then
3735                                     qual_rec.QUALIFIER_ATTR_VALUE_FROM := p_service_price_list;
3736                             Else
3737                                  qual_rec.QUALIFIER_ATTR_VALUE_FROM := to_char(p_line_tbl(i).pricelist_id);
3738                             End If;
3739 --2543687
3740 
3741 
3742 
3743                              /** Bug 2774859: the service line may not have a price list attached to it
3744                                  in which case, we have already got the price list from the covered line
3745                                  which we need to attach to the service line  **/
3746                              If  ( qual_rec.QUALIFIER_ATTR_VALUE_FROM is not null ) and
3747                                  ( qual_rec.QUALIFIER_ATTR_VALUE_FROM <> OKC_API.G_MISS_CHAR) then
3748 
3749                                  qual_rec.LINE_INDEX := p_line_index;
3750                                  qual_rec.QUALIFIER_CONTEXT :='MODLIST';
3751                                  qual_rec.QUALIFIER_ATTRIBUTE :='QUALIFIER_ATTRIBUTE4';
3752 
3753 
3754                                  qual_rec.COMPARISON_OPERATOR_CODE := '=';
3755                                  --qual_rec.VALIDATED_FLAG :='Y';
3756                                  qual_rec.VALIDATED_FLAG :='N'; --Bug 2760904: we need QP to validate the price list
3757 
3758                                  x_qualifier_contexts_Tbl(nvl(x_qualifier_contexts_Tbl.last,0)+1):= qual_rec;
3759                             End If;
3760 
3761 
3762                             /********
3763                             qual_rec.COMPARISON_OPERATOR_CODE := '=';
3764                             --qual_rec.VALIDATED_FLAG :='Y';
3765                             qual_rec.VALIDATED_FLAG :='N'; --Bug 2760904: we need QP to validate the price list
3766 
3767                             x_qualifier_contexts_Tbl(nvl(x_qualifier_contexts_Tbl.last,0)+1):= qual_rec;
3768                             ***********/
3769 
3770                        END IF;
3771                       --assign pricing_date
3772                        OKC_PRICE_PUB.G_CONTRACT_INFO.PRICING_DATE:=p_line_tbl(i).pricing_date;
3773 
3774              --If x_qualifier_contexts_tbl.count >0 then
3775                      IF (l_debug = 'Y') THEN
3776                         my_debug('11070 :Pricelist specified '||p_line_tbl(i).pricelist_id,1);
3777                      END IF;
3778 
3779                        -- put values from attached rules in global table
3780                       l_return_status:=attach_rules(p_chr_id,p_line_tbl(i).id);
3781                      -- --dbms_output.put_line('2 cle return status'||l_return_status);
3782 
3783                       IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
3784                            RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
3785                       ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
3786                            RAISE OKC_API.G_EXCEPTION_ERROR;
3787                       END IF;
3788                       -- put values from attached party roles in global table
3789                       l_return_status:=attach_party_roles(p_chr_id,p_line_tbl(i).id);
3790                      -- --dbms_output.put_line('3 cle return status'||l_return_status);
3791 
3792                       IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
3793                            RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
3794                       ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
3795                            RAISE OKC_API.G_EXCEPTION_ERROR;
3796                       END IF;
3797 
3798                       Load_User_Defined_Pattrs(p_chr_id ,
3799                                                p_line_index ,
3800                                                x_pricing_contexts_Tbl,
3801                                                x_qualifier_contexts_Tbl,
3802                                                x_return_status,
3803                                                p_line_tbl(i).id);
3804                      -- --dbms_output.put_line('4 cle return status'||x_return_status);
3805                       IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
3806                            RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
3807                       ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
3808                            RAISE OKC_API.G_EXCEPTION_ERROR;
3809                       END IF;
3810                       --call pricing build context
3811                      -- --dbms_output.put_line('5 cle return status'||x_return_status);
3812                       i:=p_line_tbl.next(i);
3813                END LOOP;--lines loop
3814 
3815                --attach the header level values for party roles and rules if not already there on line
3816                IF g_hdr_rul_tbl.count >0 then --hdr_rul if
3817                  i:=g_hdr_rul_tbl.first;
3818                  If g_hdr_rul_tbl(i).source_value=p_chr_id and
3819                     g_hdr_rul_tbl(i).code= 'CHR_ID' then
3820                     i:=g_hdr_rul_tbl.next(i);
3821                     while i is not null loop
3822                       l_prle_rec:=g_hdr_rul_tbl(i);
3823                            l_return_status:= add_to_global_tbl(okc_price_pub.g_rul_tbl,l_prle_rec);
3824                            IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
3825                                RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
3826                            ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
3827                                RAISE OKC_API.G_EXCEPTION_ERROR;
3828                            END IF;
3829                       i:=g_hdr_rul_tbl.next(i);
3830                     End loop;
3831                  end if;
3832                END IF; --end hdr_rul if
3833 
3834                IF g_hdr_prle_tbl.count >0 then --#prle if
3835                  i:=g_hdr_prle_tbl.first;
3836                  If g_hdr_prle_tbl(i).source_value=p_chr_id and
3837                     g_hdr_prle_tbl(i).code= 'CHR_ID' then
3838                     i:=g_hdr_prle_tbl.next(i);
3839                     while i is not null loop
3840                       l_prle_rec:=g_hdr_prle_tbl(i);
3841                            l_return_status:= add_to_global_tbl(okc_price_pub.g_prle_tbl,l_prle_rec);
3842                            IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
3843                                RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
3844                            ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
3845                                RAISE OKC_API.G_EXCEPTION_ERROR;
3846                            END IF;
3847                       i:=g_hdr_prle_tbl.next(i);
3848                     End loop;
3849                  end if;
3850                END IF; --#hdr prle if
3851 
3852                Begin
3853                          /* --dbms_output.put_line('okc_price_pub.g_lse_tbl');
3854                           k:=okc_price_pub.g_lse_tbl.first;
3855                           while k is not null loop
3856 
3857                                 --dbms_output.put_line('okc_price_pub.g_lse_tbl'||k||'-'||okc_price_pub.g_lse_tbl(k).current_source);
3858                                 --dbms_output.put_line('okc_price_pub.g_lse_tbl'||k||'-'||okc_price_pub.g_lse_tbl(k).source_value);
3859                                 k:=okc_price_pub.g_lse_tbl.next(k);
3860                           END LOOP;
3861 
3862                           --dbms_output.put_line('okc_price_pub.g_rul_tbl');
3863                           k:=okc_price_pub.g_rul_tbl.first;
3864                           while k is not null loop
3865                                 --dbms_output.put_line('okc_price_pub.g_rul_tbl'||k||'-'||okc_price_pub.g_rul_tbl(k).code);
3866                                 --dbms_output.put_line('okc_price_pub.g_rul_tbl'||k||'-'||okc_price_pub.g_rul_tbl(k).current_source);
3867                                 --dbms_output.put_line('okc_price_pub.g_rul_tbl'||k||'-'||okc_price_pub.g_rul_tbl(k).source_value);
3868                                 k:=okc_price_pub.g_rul_tbl.next(k);
3869                           END LOOP;
3870                           --dbms_output.put_line('okc_price_pub.g_prle_tbl');
3871                           k:=okc_price_pub.g_prle_tbl.first;
3872 
3873                           while k is not null loop
3874                               -- --dbms_output.put_line('okc_price_pub.g_prle_tbl'||k||'-'||okc_price_pub.g_prle_tbl(k).code);
3875                               -- --dbms_output.put_line('okc_price_pub.g_prle_tbl'||k||'-'||okc_price_pub.g_prle_tbl(k).current_source);
3876                               -- --dbms_output.put_line('okc_price_pub.g_prle_tbl'||k||'-'||okc_price_pub.g_prle_tbl(k).source_value);
3877                                k:=okc_price_pub.g_prle_tbl.next(k);
3878                           END LOOP;*/
3879 
3880                         -- populate global record g_contract_info
3881                        If OKC_PRICE_PUB.G_CONTRACT_INFO.INV_ORG_ID is null then
3882 
3883                            Begin
3884                              select INV_ORGANIZATION_ID
3885                              into OKC_PRICE_PUB.G_CONTRACT_INFO.INV_ORG_ID
3886                              from okc_k_headers_b
3887                              where id = p_chr_id;
3888                              IF (l_debug = 'Y') THEN
3889                                 my_debug('11290 : rowcount'||SQL%ROWCOUNT, 1);
3890                              END IF;
3891 
3892                             EXCEPTION
3893                                when no_data_found then
3894                                 IF (l_debug = 'Y') THEN
3895                                    my_debug('11300 : NO authoring org id found', 1);
3896                                 END IF;
3897                             END;
3898                         END IF; --  If OKC_PRICE_PUB.G_CONTRACT_INFO.INV_ORG_ID is null
3899 
3900                         --OKC_PRICE_PUB.G_CONTRACT_INFO.PRICING_DATE:=SYSDATE;
3901                         --populate global variable sold_to_org_id. made it global as it is used
3902                         --OKC_PRICE_PUB.G_CONTRACT_INFO.PRICING_DATE:=p_line_tbl(i).pricing_date;
3903                         -- at many places for build context functions
3904                         If OKC_PRICE_PUB.G_RUL_TBL.count > 0 then
3905                             OKC_PRICE_PUB.G_CONTRACT_INFO.SOLD_TO_ORG_ID :=
3906                                    GET_RUL_SOURCE_VALUE(OKC_PRICE_PUB.G_RUL_TBL,'CAN','OKX_CUSTACCT');
3907                         END IF;
3908                         IF (l_debug = 'Y') THEN
3909                            my_debug('11310 : G_CONTRACT_INFO.PRICING_DATE for line '||OKC_PRICE_PUB.G_CONTRACT_INFO.PRICING_DATE,1);
3910                            my_debug('11320: G_CONTRACT_INFO.INV_ORG_ID fo line'||OKC_PRICE_PUB.G_CONTRACT_INFO.INV_ORG_ID, 1);
3911                            my_debug('11330: G_CONTRACT_INFO.SOLD_TO_ORG_ID for line'||OKC_PRICE_PUB.G_CONTRACT_INFO.SOLD_TO_ORG_ID, 1);
3912                            my_debug('11340 : G_CONTRACT_INFO.Inventory id for line'||OKC_PRICE_PUB.G_CONTRACT_INFO.INVENTORY_ITEM_ID, 1);
3913                            my_debug('11350 : G_CONTRACT_INFO.top_model_line for line'||OKC_PRICE_PUB.G_CONTRACT_INFO.TOP_MODEL_LINE_ID, 1);
3914                         END IF;
3915 
3916 
3917                         IF (l_debug = 'Y') THEN
3918                            my_debug('11400 : Before Calling Build context request type'||p_request_type_code, 1);
3919                         END IF;
3920 
3921                         QP_Attr_Mapping_PUB.Build_Contexts(p_request_type_code => p_request_type_code,
3922 			                                                 p_pricing_type	=>	p_pricing_type,
3923 			                                                 x_price_contexts_result_tbl => l_pricing_contexts_Tbl,
3924                                                            x_qual_contexts_result_tbl  => l_qualifier_Contexts_Tbl);
3925 
3926 
3927                         IF (l_debug = 'Y') THEN
3928                            my_debug('11402 : After Calling Build context request type', 1);
3929                         END IF;
3930 
3931                         okc_price_pub.g_rul_tbl.DELETE;
3932                         okc_price_pub.g_prle_tbl.DELETE;
3933                         okc_price_pub.g_lse_tbl.DELETE;
3934                         OKC_PRICE_PUB.G_CONTRACT_INFO.inventory_item_id:=null;
3935 
3936                    Exception
3937                       When Others then
3938                         --dbms_output.put_line('error'||substr(sqlerrm,1,240));
3939                         OKC_API.set_message(p_app_name      => g_app_name,
3940                                       p_msg_name      => 'OKC_QP_INT_ERROR',
3941                                       p_token1        => 'Proc',
3942                                       p_token1_value  => 'Build_Context for LINE',
3943                                       p_token2        => 'SQLCODE',
3944                                       p_token2_value  => SQLCODE,
3945                                       p_token3        => 'Err_TEXT',
3946                                       p_token3_value  => SQLERRM);
3947                         IF (l_debug = 'Y') THEN
3948                            my_debug('11450 : QP Build Context Error Exiting BUILD_CLE_CONTEXT', 2);
3949                         END IF;
3950                         Raise OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
3951 
3952                End; --call pricing build context
3953                -- copy build context attribs to request table
3954               -- --dbms_output.put_line('6 cle return status'||x_return_status);
3955               IF (l_debug = 'Y') THEN
3956                  my_debug('11596 : before copy attrib count '||x_qualifier_contexts_Tbl.count, 1);
3957               END IF;
3958 
3959                copy_attribs_to_Req(
3960                            p_line_index
3961                           ,l_pricing_contexts_Tbl
3962                           ,l_qualifier_contexts_Tbl
3963                           ,x_pricing_contexts_Tbl
3964                           ,x_qualifier_contexts_Tbl
3965                         );
3966             END IF;--p_line_tbl.count
3967             IF (l_debug = 'Y') THEN
3968                my_debug('11598 : after copy attrib count '||x_qualifier_contexts_Tbl.count, 1);
3969             END IF;
3970     OKC_API.END_ACTIVITY(x_msg_count, x_msg_data);
3971 
3972     IF (l_debug = 'Y') THEN
3973        my_debug('11600 : Exiting BUILD_CLE_CONTEXT', 2);
3974     END IF;
3975     IF (l_debug = 'Y') THEN
3976        okc_debug.Reset_Indentation;
3977     END IF;
3978     EXCEPTION
3979           WHEN OKC_API.G_EXCEPTION_ERROR THEN
3980               x_return_status := OKC_API.HANDLE_EXCEPTIONS
3981                        (l_api_name,
3982                         G_PKG_NAME,
3983                        'OKC_API.G_RET_STS_ERROR',
3984                         x_msg_count,
3985                         x_msg_data,
3986                         '_PROCESS');
3987                IF (l_debug = 'Y') THEN
3988                   my_debug('11700 : Exiting BUILD_CLE_CONTEXT', 4);
3989                END IF;
3990                IF (l_debug = 'Y') THEN
3991                   okc_debug.Reset_Indentation;
3992                END IF;
3993 
3994          WHEN OKC_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
3995               x_return_status := OKC_API.HANDLE_EXCEPTIONS
3996                        (l_api_name,
3997                         G_PKG_NAME,
3998                        'OKC_API.G_RET_STS_UNEXP_ERROR',
3999                         x_msg_count,
4000                         x_msg_data,
4001                         '_PROCESS');
4002            IF (l_debug = 'Y') THEN
4003               my_debug('11800 : Exiting BUILD_CLE_CONTEXT', 4);
4004            END IF;
4005            IF (l_debug = 'Y') THEN
4006               okc_debug.Reset_Indentation;
4007            END IF;
4008 
4009          WHEN OTHERS THEN
4010               OKC_API.set_message(p_app_name      => g_app_name,
4011                                  p_msg_name      => g_unexpected_error,
4012                                  p_token1        => g_sqlcode_token,
4013                                  p_token1_value  => sqlcode,
4014                                  p_token2        => g_sqlerrm_token,
4015                                  p_token2_value  => sqlerrm);
4016             x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
4017            IF (l_debug = 'Y') THEN
4018               my_debug('11900 : Exiting BUILD_CLE_CONTEXT', 4);
4019            END IF;
4020            IF (l_debug = 'Y') THEN
4021               okc_debug.Reset_Indentation;
4022            END IF;
4023 
4024 END BUILD_CLE_CONTEXT;
4025 
4026 ----------------------------------------------------------------------------
4027 -- CREATE_REQUEST_LINE
4028 -- This procedure creates a request line for the sent in line recs
4029 ----------------------------------------------------------------------------
4030 PROCEDURE Create_request_line( p_api_version           IN            NUMBER,
4031                                p_init_msg_list         IN            VARCHAR2,
4032                                p_control_rec           IN            OKC_CONTROL_REC_TYPE,
4033                                p_chr_id                IN            NUMBER,
4034                                p_line_tbl              IN            line_tbl_type,
4035                                p_pi_ind                IN            NUMBER ,
4036                                p_bpi_ind               IN            NUMBER ,
4037                                p_pricing_event         IN            varchar2 ,
4038                                p_hdr_prc_contexts_Tbl  IN            QP_PREQ_GRP.LINE_ATTR_TBL_TYPE,
4039                                p_hdr_qual_contexts_Tbl IN            QP_PREQ_GRP.QUAL_TBL_TYPE,
4040                                px_req_line_tbl         IN OUT NOCOPY        QP_PREQ_GRP.LINE_TBL_TYPE ,
4041                                px_Req_related_lines_tbl  IN OUT NOCOPY      QP_PREQ_GRP.RELATED_LINES_TBL_TYPE,
4042                                x_pricing_contexts_Tbl     OUT NOCOPY QP_PREQ_GRP.LINE_ATTR_TBL_TYPE,
4043                                x_qualifier_contexts_Tbl   OUT NOCOPY QP_PREQ_GRP.QUAL_TBL_TYPE,
4044                                x_return_status            OUT NOCOPY        varchar2,
4045                                x_msg_count                OUT NOCOPY        NUMBER,
4046                                x_msg_data                 OUT NOCOPY        VARCHAR2) IS
4047 
4048      l_return_status           varchar2(1) := OKC_API.G_RET_STS_SUCCESS;
4049      l_related_lines_Index     pls_integer :=0;
4050      l_bpi_ind                 number := p_bpi_ind;
4051      l_line_index	           pls_integer := nvl(px_req_line_tbl.count,0);
4052      l_line_tbl                line_tbl_type := p_line_tbl;
4053      l_num_loops               number :=2;
4054 BEGIN
4055     IF (l_debug = 'Y') THEN
4056        okc_debug.Set_Indentation('Create_request_line');
4057     END IF;
4058     IF (l_debug = 'Y') THEN
4059        my_debug('12000 : Entering Create_request_line', 2);
4060     END IF;
4061 
4062      x_return_status := OKC_API.G_RET_STS_SUCCESS;
4063      -- create request line for a given line. The p_line_tbl here has the list of lines
4064      -- in the same heirarchy. One of these lines should hold Priced flag and one should have
4065      -- item_to_price_flag. If there is a relationship between two lines the index of that
4066      -- line would be stored in bpi_ind. The relationship right now defaults to SERVICE
4067      IF (l_debug = 'Y') THEN
4068         my_debug('12010 : l_line_tbl line count'||l_line_tbl.count, 1);
4069         my_debug('12015 : BPI index'||l_bpi_ind, 1);
4070      END IF;
4071      IF l_line_tbl.count>0 then
4072 
4073        Loop -- This loop should be running maximum twice- first time it runs for pi
4074        -- and second time it runs for bpi if bpi_ind is >0
4075            l_num_loops := l_num_loops -1;
4076            IF (l_debug = 'Y') THEN
4077               my_debug('12020 : l_num_loops'||l_num_loops, 1);
4078            END IF;
4079 
4080            l_line_index := l_line_index+1;
4081            IF (l_debug = 'Y') THEN
4082               my_debug('12021 : line index'||l_line_index, 1);
4083            END IF;
4084 
4085            -- here for recognition of which req line belongs to which priced line
4086            -- populate line id for pi request line with the id of 'P' as we are
4087            -- interested in the price of 'P'. IF there is a related line as well
4088            -- Then in that request line's line id we will put the id of
4089            -- line holding BPI.
4090            If l_num_loops =0  and l_bpi_ind >0 then -- that means bpi is there and populating bpi right now
4091       	       px_req_line_tbl(l_line_index).Line_id := l_line_tbl(l_bpi_ind).id;--???? for bpi
4092                IF (l_debug = 'Y') THEN
4093                   my_debug('12030 :If bpi then bpi line id'||l_line_tbl(l_bpi_ind).id, 1);
4094                END IF;
4095 
4096            ELSE
4097            	   px_req_line_tbl(l_line_index).Line_id := l_line_tbl(1).id;--???? assuming p is the first rec
4098                --??? assumming bpi cannot be at the same level as p. This would change soon based on OKO requirements
4099                l_line_tbl.delete(l_bpi_ind);
4100                IF (l_debug = 'Y') THEN
4101                   my_debug('12035 : deleted BPI entry-'||l_bpi_ind, 1);
4102                END IF;
4103 
4104                IF (l_debug = 'Y') THEN
4105                   my_debug('12040 :If not BPI then priced line id'|| l_line_tbl(1).id, 1);
4106                END IF;
4107 
4108            END IF;
4109 	       px_req_line_tbl(l_line_index).REQUEST_TYPE_CODE := p_control_rec.p_Request_Type_Code;
4110 	       px_req_line_tbl(l_line_index).LINE_INDEX     := l_line_index;
4111 	       px_req_line_tbl(l_line_index).LINE_TYPE_CODE  := 'LINE';
4112 		  --To honour pricing date
4113            px_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE := l_line_tbl(1).pricing_date;
4114            --px_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE := trunc(sysdate);--???? is sysdate fine?
4115    	       px_req_line_tbl(l_line_index).LINE_QUANTITY   := l_Line_tbl(1).qty ;
4116            IF (l_debug = 'Y') THEN
4117               my_debug('12050 :negotiated price overriden or not flag'|| p_control_rec.p_negotiated_changed, 1);
4118            END IF;
4119            If p_control_rec.p_negotiated_changed = 'Y' then
4120    	           px_req_line_tbl(l_line_index).UPDATED_ADJUSTED_UNIT_PRICE:= l_line_tbl(1).updated_price;
4121            END IF;
4122    	     --  px_req_line_tbl(l_line_index).ADJUSTED_UNIT_PRICE:= l_line_tbl(1).unit_price;
4123 
4124           px_req_line_tbl(l_line_index).LINE_UOM_CODE   := l_Line_tbl(1).uom_code;
4125           --????do we need to send whatever info about adjustements on line is alredy there
4126 	      px_req_line_tbl(l_line_index).CURRENCY_CODE := l_Line_tbl(1).currency;
4127           px_req_line_tbl(l_line_index).PRICE_FLAG := 'Y';
4128 
4129            --??? donno if relevant in our case
4130      /*
4131      -- uom begin
4132 	If p_Line_rec.unit_list_price_per_pqty <> FND_API.G_MISS_NUM Then
4133 		px_req_line_tbl(l_line_index).UNIT_PRICE := p_Line_rec.unit_list_price_per_pqty;
4134 	Else
4135 		 px_req_line_tbl(l_line_index).UNIT_PRICE := Null;
4136 	End If;
4137         -- uom end
4138 	px_req_line_tbl(l_line_index).PERCENT_PRICE := p_Line_rec.unit_list_percent;
4139 
4140         If (p_Line_rec.service_period = p_Line_rec.Order_quantity_uom) Then
4141   	  px_req_line_tbl(l_line_index).UOM_QUANTITY := p_Line_rec.service_duration;
4142         Else
4143           INV_CONVERT.INV_UM_CONVERSION(From_Unit => p_Line_rec.service_period
4144                                        ,To_Unit   => p_Line_rec.Order_quantity_uom
4145                                        ,Item_ID   => p_Line_rec.Inventory_item_id
4146                                        ,Uom_Rate  => l_Uom_rate);
4147           px_req_line_tbl(l_line_index).UOM_QUANTITY := p_Line_rec.service_duration * l_uom_rate;
4148         End If;
4149      */
4150            --???? do we want to give discounts on configured items through this?
4151            --dbms_output.put_line('here comes calc flag'||p_control_rec.p_calc_flag||l_line_tbl.count );
4152            If p_control_rec.p_calc_flag <> 'C' then
4153               IF (l_debug = 'Y') THEN
4154                  my_debug('12060 :Before calling Build _cle_context attrib count'||x_pricing_contexts_Tbl.count, 1);
4155               END IF;
4156 
4157            --build context for the line
4158               BUILD_CLE_CONTEXT(
4159                 p_api_version             => p_api_version,
4160                 p_init_msg_list           => p_init_msg_list,
4161                 p_request_type_code       => p_control_rec.p_Request_Type_Code,
4162                 p_chr_id                  => p_chr_id,
4163                 P_line_tbl                => l_line_tbl,
4164                 p_line_index              => l_line_index,
4165                 x_pricing_contexts_Tbl    => x_pricing_contexts_Tbl,
4166                 x_qualifier_contexts_Tbl  => x_qualifier_contexts_Tbl,
4167                 x_return_status           => l_return_status,
4168                 x_msg_count               => x_msg_count,
4169                 x_msg_data                => x_msg_data);
4170               IF (l_debug = 'Y') THEN
4171                  my_debug('12062 :After calling Build _cle_context return status '||l_return_status, 1);
4172               END IF;
4173 
4174               IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
4175                    RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
4176               ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
4177                    RAISE OKC_API.G_EXCEPTION_ERROR;
4178               END IF;
4179               --attach header attribs
4180 
4181                If (p_hdr_prc_contexts_Tbl.count >0 or p_hdr_qual_contexts_Tbl.count>0) then
4182                        IF (l_debug = 'Y') THEN
4183                           my_debug('12063 :header priceing attrib '||p_hdr_prc_contexts_Tbl.count, 1);
4184                           my_debug('12064 :header qual attrib '||p_hdr_qual_contexts_Tbl.count, 1);
4185                        END IF;
4186 
4187                 copy_attribs(
4188                      l_line_index
4189                     ,'Y'
4190                     ,p_hdr_prc_contexts_Tbl
4191                     ,p_hdr_qual_contexts_Tbl
4192                     ,x_pricing_contexts_Tbl
4193                     ,x_qualifier_contexts_Tbl);
4194               END IF;
4195            End If; -- p_calc_flag
4196          IF l_num_loops >0 and l_bpi_ind > 0 then
4197              IF (l_debug = 'Y') THEN
4198                 my_debug('12070 :l_bpi_ind is greater than 0 '||l_bpi_ind, 1);
4199              END IF;
4200 
4201               l_line_tbl := p_line_tbl;
4202               IF (l_debug = 'Y') THEN
4203                  my_debug('12072 :l_line_tbl reassigned from p_line_tbl ', 1);
4204                  my_debug('12074 :item_to_price_ind '||p_pi_ind, 1);
4205               END IF;
4206 
4207                 IF p_pi_ind > 1 then -- that means P is not same level as PI
4208                     l_line_tbl.delete(p_pi_ind);
4209                 ELSE -- that means p and pi at same level
4210                     -- make sure pi flag is not set on priced line. as we plan to pick the
4211                     -- item from bpi flag
4212                     l_line_tbl(1).pi_yn:='B';--B means it was both- P as well as PI
4213                 END IF;
4214                 -- Populate the Relationship this we are doing before defining the 2nd request line
4215 	            l_related_lines_Index	:= px_Req_related_lines_tbl.count+1;
4216 	            px_Req_related_lines_tbl(l_related_lines_Index).Line_Index := l_line_index;
4217 	            px_Req_related_lines_tbl(l_related_lines_Index).Related_Line_Index := l_line_index+1;
4218                 -- Right now hardcoding relationship to service
4219 	            px_Req_related_lines_tbl(l_related_lines_Index).Relationship_Type_Code:= QP_PREQ_GRP.G_SERVICE_LINE;
4220                 -- make p_bpi_ind=0 to exit the loop next time around
4221                 --l_bpi_ind :=0;
4222          ELSE
4223                l_num_loops:=0;
4224          END IF;--l_bpi_ind>0
4225          EXIT WHEN l_num_loops =0;
4226       END LOOP;
4227     END IF; -- l_line_tbl.count
4228     IF (l_debug = 'Y') THEN
4229        my_debug('12800 : Exiting Create_request_line', 2);
4230     END IF;
4231     IF (l_debug = 'Y') THEN
4232        okc_debug.Reset_Indentation;
4233     END IF;
4234 
4235   EXCEPTION
4236       when others then
4237       OKC_API.set_message(p_app_name      => g_app_name,
4238                           p_msg_name      => g_unexpected_error,
4239                           p_token1        => g_sqlcode_token,
4240                           p_token1_value  => sqlcode,
4241                           p_token2        => g_sqlerrm_token,
4242                           p_token2_value  => sqlerrm);
4243        x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
4244     IF (l_debug = 'Y') THEN
4245        my_debug('12900 : Exiting Create_request_line', 4);
4246     END IF;
4247     IF (l_debug = 'Y') THEN
4248        okc_debug.Reset_Indentation;
4249     END IF;
4250 
4251 END CREATE_REQUEST_LINE;
4252 
4253 ----------------------------------------------------------------------------
4254 -- CREATE_REQUEST_LINE_SERVICE
4255 -- This procedure creates 2 request line for the sent in line recs
4256 -- This is used only for OKO service Lines, as we need to send to QP both the
4257 --- Service item and the covered line/product/item
4258 ----------------------------------------------------------------------------
4259 PROCEDURE Create_request_line_service
4260                               ( p_api_version           IN            NUMBER,
4261                                p_init_msg_list         IN            VARCHAR2,
4262                                p_control_rec           IN            OKC_CONTROL_REC_TYPE,
4263                                p_chr_id                IN            NUMBER,
4264                                p_line_tbl              IN            line_tbl_type,
4265                                p_pi_ind                IN            NUMBER ,
4266                                p_bpi_ind               IN            NUMBER ,
4267                                p_pricing_event         IN            varchar2 ,
4268                                p_hdr_prc_contexts_Tbl  IN            QP_PREQ_GRP.LINE_ATTR_TBL_TYPE,
4269                                p_hdr_qual_contexts_Tbl IN            QP_PREQ_GRP.QUAL_TBL_TYPE,
4270                                px_req_line_tbl         IN OUT NOCOPY        QP_PREQ_GRP.LINE_TBL_TYPE ,
4271                                px_Req_related_lines_tbl  IN OUT NOCOPY      QP_PREQ_GRP.RELATED_LINES_TBL_TYPE,
4272                                x_pricing_contexts_Tbl     OUT NOCOPY QP_PREQ_GRP.LINE_ATTR_TBL_TYPE,
4273                                x_qualifier_contexts_Tbl   OUT NOCOPY QP_PREQ_GRP.QUAL_TBL_TYPE,
4274                                x_return_status            OUT NOCOPY        varchar2,
4275                                x_msg_count                OUT NOCOPY        NUMBER,
4276                                x_msg_data                 OUT NOCOPY        VARCHAR2)  IS
4277 
4278      l_return_status           varchar2(1) := OKC_API.G_RET_STS_SUCCESS;
4279      l_related_lines_Index     pls_integer :=0;
4280      l_bpi_ind                 number := p_bpi_ind;
4281      l_line_index	           pls_integer := nvl(px_req_line_tbl.count,0);
4282      l_line_tbl                line_tbl_type := p_line_tbl;
4283      l_num_loops               number := 2;
4284      i pls_integer :=0;
4285      p_list_id                 VARCHAR2(30);
4286 BEGIN
4287     IF (l_debug = 'Y') THEN
4288        okc_debug.Set_Indentation('Create_request_line_service');
4289     END IF;
4290     IF (l_debug = 'Y') THEN
4291        my_debug('12000 : Entering Create_request_line_service', 2);
4292     END IF;
4293 
4294      x_return_status := OKC_API.G_RET_STS_SUCCESS;
4295      -- create request line for a given line. The p_line_tbl here has the list of lines
4296      -- in the same heirarchy. One of these lines should hold Priced flag and one should have
4297      -- item_to_price_flag. The price of item_to_price depends of price of priced
4298      --  The relationship right now defaults to SERVICE
4299      IF (l_debug = 'Y') THEN
4300         my_debug('12010 : l_line_tbl line count'||l_line_tbl.count, 1);
4301      END IF;
4302     IF l_line_tbl.count>0 then
4303        i := l_line_tbl.first;
4304 
4305        While i is not null Loop
4306 
4307          If i = l_line_tbl.first or i= p_pi_ind then
4308             l_line_index := l_line_index+1;
4309            IF i = l_line_tbl.first then
4310             -- first line contains priced line
4311             -- create request line for covered line/product/item with id of pi
4312 
4313               px_req_line_tbl(l_line_index).LINE_INDEX     := l_line_index;
4314               px_req_line_tbl(l_line_index).line_id        := l_line_tbl(p_pi_ind).id;
4315               p_list_id := NULL;
4316            else
4317             --create request line for service item with id of P
4318 
4319              px_req_line_tbl(l_line_index).line_id        := l_line_tbl(l_line_tbl.first).id;
4320              px_req_line_tbl(l_line_index).line_index     := l_line_index;
4321 		   p_list_id := l_line_tbl(l_line_tbl.first).pricelist_id;
4322            end if;
4323 
4324 	       px_req_line_tbl(l_line_index).REQUEST_TYPE_CODE := p_control_rec.p_Request_Type_Code;
4325 	       px_req_line_tbl(l_line_index).LINE_TYPE_CODE  := 'LINE';
4326 
4327            -- px_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE := trunc(sysdate);--???? is sysdate fine?
4328             px_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE := l_line_tbl(1).pricing_date;
4329    	       px_req_line_tbl(l_line_index).LINE_QUANTITY   := l_Line_tbl(i).qty ;
4330 
4331            IF (l_debug = 'Y') THEN
4332               my_debug('12050 :negotiated price overriden or not flag'|| p_control_rec.p_negotiated_changed, 1);
4333            END IF;
4334            If p_control_rec.p_negotiated_changed = 'Y' then
4335    	           px_req_line_tbl(l_line_index).UPDATED_ADJUSTED_UNIT_PRICE:= l_line_tbl(i).updated_price;
4336            END IF;
4337 
4338           px_req_line_tbl(l_line_index).LINE_UOM_CODE   := l_Line_tbl(i).uom_code;
4339           --????do we need to send whatever info about adjustements on line is alredy there
4340 	      px_req_line_tbl(l_line_index).CURRENCY_CODE := l_Line_tbl(i).currency;
4341           px_req_line_tbl(l_line_index).PRICE_FLAG := 'Y';
4342 
4343            --??? donno if relevant in our case
4344      /*
4345      -- uom begin
4346 	If p_Line_rec.unit_list_price_per_pqty <> FND_API.G_MISS_NUM Then
4347 		px_req_line_tbl(l_line_index).UNIT_PRICE := p_Line_rec.unit_list_price_per_pqty;
4348 	Else
4349 		 px_req_line_tbl(l_line_index).UNIT_PRICE := Null;
4350 	End If;
4351         -- uom end
4352 	px_req_line_tbl(l_line_index).PERCENT_PRICE := p_Line_rec.unit_list_percent;
4353 
4354         If (p_Line_rec.service_period = p_Line_rec.Order_quantity_uom) Then
4355   	  px_req_line_tbl(l_line_index).UOM_QUANTITY := p_Line_rec.service_duration;
4356         Else
4357           INV_CONVERT.INV_UM_CONVERSION(From_Unit => p_Line_rec.service_period
4358                                        ,To_Unit   => p_Line_rec.Order_quantity_uom
4359                                        ,Item_ID   => p_Line_rec.Inventory_item_id
4360                                        ,Uom_Rate  => l_Uom_rate);
4361           px_req_line_tbl(l_line_index).UOM_QUANTITY := p_Line_rec.service_duration * l_uom_rate;
4362         End If;
4363      */
4364            --???? do we want to give discounts on configured items through this?
4365            --dbms_output.put_line('here comes calc flag'||p_control_rec.p_calc_flag||l_line_tbl.count );
4366            If p_control_rec.p_calc_flag <> 'C' then
4367               IF (l_debug = 'Y') THEN
4368                  my_debug('12060 :Before calling Build _cle_context attrib count'||x_pricing_contexts_Tbl.count, 1);
4369               END IF;
4370 --           Before calling build_cle_context delete record not being processed
4371              If i= 1 then
4372                l_line_tbl.delete(p_pi_ind);
4373              Else
4374                l_line_tbl.delete(l_line_tbl.first);
4375              end if;
4376 
4377            --build context for the line
4378               BUILD_CLE_CONTEXT(
4379                 p_api_version             => p_api_version,
4380                 p_init_msg_list           => p_init_msg_list,
4381                 p_request_type_code       => p_control_rec.p_Request_Type_Code,
4382                 p_chr_id                  => p_chr_id,
4383                 P_line_tbl                => l_line_tbl,
4384                 p_line_index              => l_line_index,
4385                 p_service_price           => 'Y',
4386 			 p_service_price_list      => p_list_id,
4387                 x_pricing_contexts_Tbl    => x_pricing_contexts_Tbl,
4388                 x_qualifier_contexts_Tbl  => x_qualifier_contexts_Tbl,
4389                 x_return_status           => l_return_status,
4390                 x_msg_count               => x_msg_count,
4391                 x_msg_data                => x_msg_data);
4392 
4393                 IF (l_debug = 'Y') THEN
4394                    my_debug('12062 :After calling Build _cle_context return status '||l_return_status, 1);
4395                 END IF;
4396 
4397             --Repopulate line table
4398               l_line_tbl:= p_line_tbl;
4399 
4400               IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
4401                    RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
4402               ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
4403                    RAISE OKC_API.G_EXCEPTION_ERROR;
4404               END IF;
4405               --attach header attribs
4406 
4407                If (p_hdr_prc_contexts_Tbl.count >0 or p_hdr_qual_contexts_Tbl.count>0) then
4408                        IF (l_debug = 'Y') THEN
4409                           my_debug('12063 :header priceing attrib '||p_hdr_prc_contexts_Tbl.count, 1);
4410                           my_debug('12064 :header qual attrib '||p_hdr_qual_contexts_Tbl.count, 1);
4411                        END IF;
4412 
4413                 copy_attribs(
4414                      l_line_index
4415                     ,'Y'
4416                     ,p_hdr_prc_contexts_Tbl
4417                     ,p_hdr_qual_contexts_Tbl
4418                     ,x_pricing_contexts_Tbl
4419                     ,x_qualifier_contexts_Tbl);
4420               END IF;
4421            End If; -- p_calc_flag
4422            IF i = l_line_tbl.first  then
4423              -- Populate the Relationship this we are doing before defining the 2nd request line
4424 	        l_related_lines_Index	:= px_Req_related_lines_tbl.count+1;
4425 	        px_Req_related_lines_tbl(l_related_lines_Index).Line_Index := l_line_index; --index of cov line
4426 	        px_Req_related_lines_tbl(l_related_lines_Index).Related_Line_Index := l_line_index+1; -- index of  service item
4427             -- Right now hardcoding relationship to service
4428 	        px_Req_related_lines_tbl(l_related_lines_Index).Relationship_Type_Code:= QP_PREQ_GRP.G_SERVICE_LINE;
4429            end if;
4430         end if; --If for pi/p
4431         i := l_line_tbl.next(i);
4432 
4433       END LOOP;
4434     END IF; -- l_line_tbl.count
4435     IF (l_debug = 'Y') THEN
4436        my_debug('12800 : Exiting Create_request_line_service', 2);
4437     END IF;
4438     IF (l_debug = 'Y') THEN
4439        okc_debug.Reset_Indentation;
4440     END IF;
4441 
4442   EXCEPTION
4443       when others then
4444       OKC_API.set_message(p_app_name      => g_app_name,
4445                           p_msg_name      => g_unexpected_error,
4446                           p_token1        => g_sqlcode_token,
4447                           p_token1_value  => sqlcode,
4448                           p_token2        => g_sqlerrm_token,
4449                           p_token2_value  => sqlerrm);
4450        x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
4451     IF (l_debug = 'Y') THEN
4452        my_debug('12900 : Exiting Create_request_line', 4);
4453     END IF;
4454     IF (l_debug = 'Y') THEN
4455        okc_debug.Reset_Indentation;
4456     END IF;
4457 
4458 END CREATE_REQUEST_LINE_service;
4459 
4460 
4461 
4462 ----------------------------------------------------------------------------
4463 -- Process_Adjustment_DETAILS
4464 -- This procedure will check all the lines that get returned from pricing
4465 -- and take appropriate action.
4466 --Modified for pricing of service lines
4467 ----------------------------------------------------------------------------
4468 PROCEDURE PROCESS_ADJUSTMENT_DETAILS(
4469           p_api_version               IN            NUMBER,
4470           p_init_msg_list             IN            VARCHAR2 DEFAULT OKC_API.G_FALSE ,
4471           p_CHR_ID                     IN     NUMBER,
4472           p_Control_Rec			    IN     OKC_CONTROL_REC_TYPE,
4473           p_req_line_tbl               IN     QP_PREQ_GRP.LINE_TBL_TYPE,
4474           p_Req_LINE_DETAIL_tbl        IN     QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE,
4475           p_Req_LINE_DETAIL_qual_tbl   IN     QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE,
4476           p_Req_LINE_DETAIL_attr_tbl   IN     QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE,
4477           p_Req_RELATED_LINE_TBL       IN     QP_PREQ_GRP.RELATED_LINES_TBL_TYPE,
4478           p_CLE_PRICE_tbl		    IN     CLE_PRICE_tbl_TYPE,
4479 		p_service_qty_tbl            IN     NUM_TBL_TYPE,
4480           x_return_status               OUT  NOCOPY VARCHAR2,
4481           x_msg_count                   OUT NOCOPY NUMBER,
4482           x_msg_data                    OUT NOCOPY VARCHAR2) IS
4483 
4484        i pls_integer :=0;
4485        j pls_integer :=0;
4486        k pls_integer :=0;
4487 
4488        l_patv_rec          OKC_PRICE_ADJUSTMENT_PUB.patv_rec_type;
4489        l_patv_dummy_rec          OKC_PRICE_ADJUSTMENT_PUB.patv_rec_type;
4490 
4491        lx_patv_rec         OKC_PRICE_ADJUSTMENT_PUB.patv_rec_type;
4492        l_patv_tbl          OKC_PRICE_ADJUSTMENT_PUB.patv_tbl_type;
4493        l_new_pat_tbl       num_tbl_type;
4494       -- l_new_detail_tbl    num_tbl_type;
4495        l_pacv_tbl          OKC_PRICE_ADJUSTMENT_PUB.pacv_tbl_type;
4496        l_paav_tbl          OKC_PRICE_ADJUSTMENT_PUB.paav_tbl_type;
4497        lx_pacv_tbl          OKC_PRICE_ADJUSTMENT_PUB.pacv_tbl_type;
4498        lx_paav_tbl          OKC_PRICE_ADJUSTMENT_PUB.paav_tbl_type;
4499 
4500         TYPE CHAR_TBL_TYPE is TABLE of varchar2(240) INDEX BY BINARY_INTEGER;
4501 
4502 
4503        TYPE Price_break_rec is RECORD (
4504 		   Line_detail_index NUMBER,
4505 		   Pat_id   NUMBER,
4506 		   CLE_ID  NUMBER,
4507 		   CHR_ID NUMBER,
4508 		   list_line_type_code VARCHAR2(30) );
4509 
4510        TYPE PRICE_BREAK_TBL IS TABLE OF Price_break_rec INDEX BY   BINARY_INTEGER;
4511 
4512        l_price_break_tbl price_break_tbl;
4513        l_id_tbl            num_tbl_type;
4514        l_pat_id_tbl       NUM_TBL_TYPE;
4515        l_line_no_tbl      CHAR_TBL_TYPE;
4516        l_list_hdr_tbl     NUM_TBL_TYPE;
4517        l_obj_tbl          NUM_TBL_TYPE;
4518 
4519        l_id_tmp_tbl       NUM_TBL_TYPE;
4520        l_pat_tmp_tbl      NUM_TBL_TYPE;
4521        l_line_tmp_tbl     CHAR_TBL_TYPE;
4522        l_list_tmp_tbl     NUM_TBL_TYPE;
4523        l_obj_tmp_tbl      NUM_TBL_TYPE;
4524 
4525       l_id number :=0;
4526 
4527       l_found boolean :=false;
4528       p_qty number;
4529 
4530       lx_serviced_rec_yn               VARCHAR2(1);
4531       lx_process_child_yn               VARCHAR2(1);
4532 
4533 
4534    FUNCTION clean_adj_assocs(p_id_tbl num_tbl_type) RETURN varchar2 IS
4535     l_return_status varchar2(1) := OKC_API.G_RET_STS_SUCCESS;
4536     k pls_integer :=0;
4537     l pls_integer :=0;
4538     j pls_integer :=0;
4539 
4540     l_id_tbl  num_tbl_type;
4541    BEGIN
4542     IF (l_debug = 'Y') THEN
4543        okc_debug.Set_Indentation('clean_adj_assocs');
4544     END IF;
4545     IF (l_debug = 'Y') THEN
4546        my_debug('13300 : Entering clean_adj_assocs', 2);
4547     END IF;
4548 
4549      k:=p_id_tbl.first;
4550      while k is not null loop
4551            select id
4552            bulk collect into l_id_tbl
4553            from okc_price_adj_assocs
4554            where pat_id = p_id_tbl(k) or pat_id_from = p_id_tbl(k);
4555            IF (l_debug = 'Y') THEN
4556               my_debug('13310 : select rowcount'||SQL%ROWCOUNT, 1);
4557            END IF;
4558 
4559            l:=l_id_tbl.first;
4560            while l is not null loop
4561               j:=j+1;
4562               l_pacv_tbl(j).id:=l_id_tbl(l);
4563              l:=l_id_tbl.next(l);
4564            end loop;
4565            k:=p_id_tbl.next(k);
4566      end loop;
4567      OKC_PRICE_ADJUSTMENT_PUB.delete_price_adj_assoc(
4568        p_api_version      => p_api_version,
4569        x_return_status    => l_return_status ,
4570        x_msg_count        => x_msg_count,
4571        x_msg_data         => x_msg_data,
4572        p_pacv_tbl         => l_pacv_tbl);
4573       l_pacv_tbl.delete;
4574     IF (l_debug = 'Y') THEN
4575        my_debug('13400 : Exiting clean_adj_assocs', 2);
4576     END IF;
4577     IF (l_debug = 'Y') THEN
4578        okc_debug.Reset_Indentation;
4579     END IF;
4580 
4581      return (l_return_status);
4582  EXCEPTION
4583   when others then
4584    OKC_API.set_message(p_app_name      => g_app_name,
4585                        p_msg_name      => g_unexpected_error,
4586                        p_token1        => g_sqlcode_token,
4587                        p_token1_value  => sqlcode,
4588                        p_token2        => g_sqlerrm_token,
4589                        p_token2_value  => sqlerrm);
4590    l_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
4591     IF (l_debug = 'Y') THEN
4592        my_debug('13500 : Exiting clean_adj_assocs', 4);
4593     END IF;
4594     IF (l_debug = 'Y') THEN
4595        okc_debug.Reset_Indentation;
4596     END IF;
4597 
4598    return (l_return_status);
4599 
4600  END clean_adj_assocs;
4601  FUNCTION clean_adj_attrib(p_id_tbl num_tbl_type) RETURN varchar2 IS
4602     l_return_status varchar2(1) := OKC_API.G_RET_STS_SUCCESS;
4603     k pls_integer :=0;
4604     l pls_integer :=0;
4605     j pls_integer :=0;
4606 
4607     l_id_tbl  num_tbl_type;
4608    BEGIN
4609     IF (l_debug = 'Y') THEN
4610        okc_debug.Set_Indentation('clean_adj_attrib');
4611     END IF;
4612     IF (l_debug = 'Y') THEN
4613        my_debug('13600 : Entering clean_adj_attrib', 2);
4614     END IF;
4615 
4616      k:=p_id_tbl.first;
4617      while k is not null loop
4618            select id
4619            bulk collect into l_id_tbl
4620            from okc_price_adj_attribs
4621            where pat_id = p_id_tbl(k);
4622             IF (l_debug = 'Y') THEN
4623                my_debug('13610 : select rowcount'||SQL%ROWCOUNT, 1);
4624             END IF;
4625 
4626            l:=l_id_tbl.first;
4627            while l is not null loop
4628               j:=j+1;
4629               l_paav_tbl(j).id:=l_id_tbl(l);
4630              l:=l_id_tbl.next(l);
4631            end loop;
4632            k:=p_id_tbl.next(k);
4633      end loop;
4634      OKC_PRICE_ADJUSTMENT_PUB.delete_price_adj_attrib(
4635        p_api_version      => p_api_version,
4636        x_return_status    => l_return_status ,
4637        x_msg_count        => x_msg_count,
4638        x_msg_data         => x_msg_data,
4639        p_paav_tbl         => l_paav_tbl);
4640        l_paav_tbl.delete;
4641     IF (l_debug = 'Y') THEN
4642        my_debug('13700 : Exiting clean_adj_attrib', 2);
4643     END IF;
4644     IF (l_debug = 'Y') THEN
4645        okc_debug.Reset_Indentation;
4646     END IF;
4647 
4648      return (l_return_status);
4649  EXCEPTION
4650   when others then
4651    OKC_API.set_message(p_app_name      => g_app_name,
4652                        p_msg_name      => g_unexpected_error,
4653                        p_token1        => g_sqlcode_token,
4654                        p_token1_value  => sqlcode,
4655                        p_token2        => g_sqlerrm_token,
4656                        p_token2_value  => sqlerrm);
4657    l_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
4658    IF (l_debug = 'Y') THEN
4659       my_debug('13800 : Exiting clean_adj_attrib', 4);
4660    END IF;
4661    IF (l_debug = 'Y') THEN
4662       okc_debug.Reset_Indentation;
4663    END IF;
4664 
4665    return (l_return_status);
4666 
4667  END clean_adj_attrib;
4668 
4669  FUNCTION create_adj_attrib RETURN varchar2 IS
4670     l_return_status varchar2(1) := OKC_API.G_RET_STS_SUCCESS;
4671     k pls_integer :=0;
4672     l pls_integer :=0;
4673     j pls_integer :=0;
4674     l_is_there boolean :=false;
4675    BEGIN
4676     IF (l_debug = 'Y') THEN
4677        okc_debug.Set_Indentation('create_adj_attrib');
4678     END IF;
4679     IF (l_debug = 'Y') THEN
4680        my_debug('14000 : Entering create_adj_attrib', 2);
4681     END IF;
4682 
4683      k:=p_Req_LINE_DETAIL_qual_tbl.first;
4684      while k is not null loop
4685            l_is_there := false;
4686            l:=l_new_pat_tbl.first;
4687            while l is not null loop
4688                if p_req_line_detail_tbl(l).line_detail_index = p_Req_LINE_DETAIL_qual_tbl(k).line_detail_index then
4689                    l_is_there := true;
4690                    exit;
4691                end if;
4692             l:=l_new_pat_tbl.next(l);
4693            end loop;
4694            IF (l_debug = 'Y') THEN
4695               my_debug('14040 :qualpat_line detail index'||p_Req_LINE_DETAIL_qual_tbl(k).line_detail_index);
4696               my_debug('14050 :qualpat_ qualifier contxet'||p_Req_LINE_DETAIL_qual_tbl(k).Qualifier_Context);
4697               my_debug('14060 :qualpat_ qualifier attribute'||p_Req_LINE_DETAIL_qual_tbl(k).Qualifier_Attribute);
4698               my_debug('14070 :qualpat_idattr value'||p_Req_LINE_DETAIL_qual_tbl(k).Qualifier_Attr_Value_From);
4699            END IF;
4700 
4701 
4702            If l_is_there then
4703                IF (l_debug = 'Y') THEN
4704                   my_debug('14080 : line detail index found'||l, 1);
4705                   my_debug('14082 :pat_id'||l_new_pat_tbl(l));
4706                END IF;
4707 
4708                	j := j+1;
4709                 l_paav_tbl(j).pat_id := l_new_pat_tbl(l);
4710 	            l_paav_tbl(j).flex_title := 'QP_ATTR_DEFNS_QUALIFIER';
4711 	            l_paav_tbl(j).pricing_context :=
4712 				                      p_Req_LINE_DETAIL_qual_tbl(k).Qualifier_Context;
4713 	            l_paav_tbl(j).pricing_attribute :=
4714 				                    p_Req_LINE_DETAIL_qual_tbl(k).Qualifier_Attribute;
4715 	            l_paav_tbl(j).pricing_attr_value_from :=
4716 				                    p_Req_LINE_DETAIL_qual_tbl(k).Qualifier_Attr_Value_From;
4717             	l_paav_tbl(j).pricing_attr_value_To :=
4718 			                    	p_Req_LINE_DETAIL_qual_tbl(k).Qualifier_Attr_Value_To;
4719 	            l_paav_tbl(j).comparison_operator :=
4720 				                    p_Req_LINE_DETAIL_qual_tbl(k).comparison_operator_Code;
4721 
4722                 IF (l_debug = 'Y') THEN
4723                    my_debug('14082 :index'||j);
4724                 END IF;
4725 
4726                IF (l_debug = 'Y') THEN
4727                   my_debug('14082 :pat_id'||l_paav_tbl(j).pat_id);
4728                END IF;
4729 
4730             else
4731                 IF (l_debug = 'Y') THEN
4732                    my_debug('14200 : adjustment corresponding to qualifier not saved');
4733                 END IF;
4734               null;
4735            End If;
4736 
4737            k:=p_Req_LINE_DETAIL_qual_tbl.next(k);
4738      end loop;
4739 
4740      k:=p_Req_LINE_DETAIL_attr_tbl.first;
4741      while k is not null loop
4742            l_is_there := false;
4743            l:=l_new_pat_tbl.first;
4744            while l is not null loop
4745                if p_req_line_detail_tbl(l).line_detail_index = p_Req_LINE_DETAIL_attr_tbl(k).line_detail_index then
4746                    l_is_there := true;
4747                    exit;
4748                end if;
4749             l:=l_new_pat_tbl.next(l);
4750            end loop;
4751            IF (l_debug = 'Y') THEN
4752               my_debug('14240 :prcpat_line detail index'||p_Req_LINE_DETAIL_attr_tbl(k).line_detail_index);
4753               my_debug('14250 :prcpat_id1 contxet'||p_Req_LINE_DETAIL_attr_tbl(k).PRICING_Context);
4754               my_debug('14260 :prcpat_id1 pricing attribute'||p_Req_LINE_DETAIL_attr_tbl(k).PRICING_Attribute);
4755               my_debug('14270 :prcpat_idattr vale'||p_Req_LINE_DETAIL_attr_tbl(k).PRICING_Attr_Value_From);
4756            END IF;
4757 
4758 
4759            If l_is_there then
4760                 IF (l_debug = 'Y') THEN
4761                    my_debug('14280 : line detail index found'||l, 1);
4762                    my_debug('14282 :pat_id'||l_new_pat_tbl(l));
4763                 END IF;
4764 
4765                	j := j+1;
4766                 l_paav_tbl(j).pat_id := l_new_pat_tbl(l);
4767 	            l_paav_tbl(j).flex_title := 'QP_ATTR_DEFNS_PRICING';
4768 	            l_paav_tbl(j).pricing_context :=
4769 				                      p_Req_LINE_DETAIL_attr_tbl(k).PRICING_Context;
4770 	            l_paav_tbl(j).pricing_attribute :=
4771 				                    p_Req_LINE_DETAIL_attr_tbl(k).PRICING_Attribute;
4772 	            l_paav_tbl(j).pricing_attr_value_from :=
4773 				                    p_Req_LINE_DETAIL_attr_tbl(k).PRICING_Attr_Value_From;
4774             	l_paav_tbl(j).pricing_attr_value_To :=
4775 			                    	p_Req_LINE_DETAIL_attr_tbl(k).PRICING_Attr_Value_To;
4776 
4777             else
4778 
4779                 IF (l_debug = 'Y') THEN
4780                    my_debug('14300 : adjustment corresponding to pricing attribute not saved');
4781                 END IF;
4782                 null;
4783            End If;
4784 
4785            k:=p_Req_LINE_DETAIL_attr_tbl.next(k);
4786      end loop;
4787     IF (l_debug = 'Y') THEN
4788        my_debug('14350 : before calling OKC_PRICE_ADJUSTMENT_PUB.create_price_adj_attrib count '||l_paav_tbl.count, 1);
4789     END IF;
4790     If l_paav_tbl.count >0 then
4791         OKC_PRICE_ADJUSTMENT_PUB.create_price_adj_attrib(
4792         --OKC_PAA_PVT.INSERT_ROW(
4793           p_api_version      => p_api_version,
4794           x_return_status    => l_return_status ,
4795           x_msg_count        => x_msg_count,
4796           x_msg_data         => x_msg_data,
4797           p_paav_tbl         => l_paav_tbl,
4798           x_paav_tbl         => lx_paav_tbl);
4799     IF (l_debug = 'Y') THEN
4800        my_debug('14352 : after calling OKC_PRICE_ADJUSTMENT_PUB.create_price_adj_attrib '||l_return_status, 1);
4801     END IF;
4802 
4803        l_paav_tbl.delete;
4804     End if; --l_paav_tbl.count
4805     IF (l_debug = 'Y') THEN
4806        my_debug('14500 : Exiting create_adj_attrib', 2);
4807     END IF;
4808     IF (l_debug = 'Y') THEN
4809        okc_debug.Reset_Indentation;
4810     END IF;
4811 
4812      return l_return_status;
4813  EXCEPTION
4814   when others then
4815    OKC_API.set_message(p_app_name      => g_app_name,
4816                        p_msg_name      => g_unexpected_error,
4817                        p_token1        => g_sqlcode_token,
4818                        p_token1_value  => sqlcode,
4819                        p_token2        => g_sqlerrm_token,
4820                        p_token2_value  => sqlerrm);
4821    l_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
4822     IF (l_debug = 'Y') THEN
4823        my_debug('14600 : Exiting create_adj_attrib', 4);
4824     END IF;
4825     IF (l_debug = 'Y') THEN
4826        okc_debug.Reset_Indentation;
4827     END IF;
4828 
4829    return (l_return_status);
4830 
4831  END create_adj_attrib;
4832  -------------------------------------------------------------------------
4833 -- LOAD_ADJ_LINES
4834 -------------------------------------------------------------------------
4835 PROCEDURE LOAD_ADJ_LINES(
4836      p_Req_LINE_DETAIL_rec        IN     QP_PREQ_GRP.LINE_DETAIL_REC_TYPE,
4837      p_opr                         IN    varchar2 DEFAULT 'I' ,
4838 	p_service_qty                 IN NUMBER DEFAULT 1,
4839      p_adj_id                      IN    NUMBER default 0,
4840      p_obj                         IN    NUMBER default 1,
4841      px_patv_rec                   IN OUT NOCOPY OKC_PRICE_ADJUSTMENT_PUB.patv_rec_type
4842 ) IS
4843 Begin
4844     IF (l_debug = 'Y') THEN
4845        okc_debug.Set_Indentation('LOAD_ADJ_LINES');
4846     END IF;
4847     IF (l_debug = 'Y') THEN
4848        my_debug('13000 : Entering LOAD_ADJ_LINES', 2);
4849     END IF;
4850 
4851   If p_opr = 'U' then
4852      px_patv_rec.ID                      := p_adj_id;
4853      px_patv_rec.object_version_number   := p_obj;
4854   End If;
4855   --dbms_output.put_line('load adjs'||p_Req_LINE_DETAIL_rec.line_detail_id);
4856   --px_patv_rec.CLE_ID                            := p_Req_LINE_DETAIL_rec.line_detail_id; --????? check if this is populated
4857   px_patv_rec.ACCRUAL_CONVERSION_RATE           := p_Req_LINE_DETAIL_rec.accrual_conversion_rate;
4858   px_patv_rec.ACCRUAL_FLAG                      := p_Req_LINE_DETAIL_rec.accrual_flag;
4859   px_patv_rec.ADJUSTED_AMOUNT                   := p_Req_LINE_DETAIL_rec.adjustment_amount*p_service_qty;
4860   px_patv_rec.APPLIED_FLAG                      := p_Req_LINE_DETAIL_rec.applied_flag;
4861   px_patv_rec.ARITHMETIC_OPERATOR               := p_Req_LINE_DETAIL_rec.operand_calculation_code;
4862   px_patv_rec.AUTOMATIC_FLAG                    := p_Req_LINE_DETAIL_rec.automatic_flag;
4863   px_patv_rec.BENEFIT_QTY                       := p_Req_LINE_DETAIL_rec.benefit_qty;
4864   px_patv_rec.BENEFIT_UOM_CODE                  := p_Req_LINE_DETAIL_rec.benefit_uom_code;
4865   px_patv_rec.CHARGE_SUBTYPE_CODE               := p_Req_LINE_DETAIL_rec.charge_subtype_code;
4866   px_patv_rec.CHARGE_TYPE_CODE                  := p_Req_LINE_DETAIL_rec.charge_type_code;
4867   px_patv_rec.EXPIRATION_DATE                   := p_Req_LINE_DETAIL_rec.expiration_date;
4868   px_patv_rec.INCLUDE_ON_RETURNS_FLAG           := p_Req_LINE_DETAIL_rec.include_on_returns_flag;
4869   px_patv_rec.LIST_HEADER_ID                    := p_Req_LINE_DETAIL_rec.list_header_id;
4870   px_patv_rec.LIST_LINE_ID                      := p_Req_LINE_DETAIL_rec.list_line_id;
4871   px_patv_rec.LIST_LINE_NO                      := p_Req_LINE_DETAIL_rec.list_line_no;
4872   px_patv_rec.LIST_LINE_TYPE_CODE               := p_Req_LINE_DETAIL_rec.list_line_type_code;
4873   px_patv_rec.MODIFIER_LEVEL_CODE               := p_Req_LINE_DETAIL_rec.modifier_level_code;
4874   px_patv_rec.MODIFIER_MECHANISM_TYPE_CODE      := p_Req_LINE_DETAIL_rec.created_from_list_type_code;
4875   px_patv_rec.OPERAND                           := p_Req_LINE_DETAIL_rec.operand_value;
4876   px_patv_rec.PRICE_BREAK_TYPE_CODE             := p_Req_LINE_DETAIL_rec.price_break_type_code;
4877   px_patv_rec.PRICING_GROUP_SEQUENCE            := p_Req_LINE_DETAIL_rec.pricing_group_sequence;
4878   px_patv_rec.PRICING_PHASE_ID                  := p_Req_LINE_DETAIL_rec.pricing_phase_id;
4879   px_patv_rec.PRORATION_TYPE_CODE               := p_Req_LINE_DETAIL_rec.proration_type_code;
4880   px_patv_rec.REBATE_TRANSACTION_TYPE_CODE      := p_Req_LINE_DETAIL_rec.rebate_transaction_type_code;
4881   px_patv_rec.RANGE_BREAK_QUANTITY              := p_Req_LINE_DETAIL_rec.line_quantity;
4882   px_patv_rec.SOURCE_SYSTEM_CODE                := p_Req_LINE_DETAIL_rec.source_system_code;
4883   px_patv_rec.SUBSTITUTION_ATTRIBUTE            := p_Req_LINE_DETAIL_rec.substitution_attribute;
4884   px_patv_rec.UPDATE_ALLOWED                   := p_Req_LINE_DETAIL_rec.override_flag;
4885   px_patv_rec.UPDATED_FLAG                      := p_Req_LINE_DETAIL_rec.updated_flag;
4886 
4887   IF (l_debug = 'Y') THEN
4888      my_debug('13200 : Exiting LOAD_ADJ_LINES', 2);
4889   END IF;
4890   IF (l_debug = 'Y') THEN
4891      okc_debug.Reset_Indentation;
4892   END IF;
4893 
4894 END LOAD_ADJ_LINES;
4895 --Added for pricing of service lines
4896 
4897 --tope pbh changes  comment the function out
4898 /*
4899 FUNCTION IS_SERVICED_REQ_LINE(   p_req_line_rec                IN     QP_PREQ_GRP.LINE_rec_TYPE,
4900                                  p_Req_RELATED_LINE_TBL       IN     QP_PREQ_GRP.RELATED_LINES_TBL_TYPE)
4901                                  RETURN VARCHAR2 IS
4902    serviced_rec varchar2(1)  := 'N';
4903    i pls_integer := 0;
4904 
4905   BEGIN
4906        i := p_Req_RELATED_LINE_TBL.first;
4907        While i is not null loop
4908          If p_req_line_rec.line_index = p_req_related_line_tbl(i).line_index
4909           and p_Req_related_line_tbl(i).Relationship_Type_Code = QP_PREQ_GRP.G_SERVICE_LINE
4910          Then
4911            serviced_rec := 'Y';
4912            IF (l_debug = 'Y') THEN
4913               my_debug('line index '||p_req_line_rec.line_index||'No updates to id'||p_req_line_rec.line_id);
4914            END IF;
4915            exit;
4916          End If;
4917          i := p_Req_RELATED_LINE_TBL.next(i);
4918        End loop;
4919           return serviced_rec;
4920 END IS_SERVICED_REQ_LINE;
4921 */
4922 
4923 --tope pbh changes
4924 PROCEDURE IS_SERVICED_REQ_LINE(p_req_line_rec IN     QP_PREQ_GRP.LINE_rec_TYPE,
4925 			       detail_index                  IN NUMBER ,
4926 			       l_serviced_rec_yn               OUT NOCOPY     VARCHAR2  ,
4927 			       l_process_child_yn              OUT NOCOPY  VARCHAR2  )
4928 IS
4929      i pls_integer         := 0;
4930 
4931    BEGIN
4932       i := p_Req_RELATED_LINE_TBL.first;
4933 	 While i is not null loop
4934 	    If p_req_line_rec.line_index = p_req_related_line_tbl(i).line_index
4935 	       and p_Req_related_line_tbl(i).Relationship_Type_Code = QP_PREQ_GRP.G_SERVICE_LINE
4936 	    Then
4937 		  l_serviced_rec_yn := 'Y';
4938 		  IF (l_debug = 'Y') THEN
4939    		  my_debug('line index '||p_req_line_rec.line_index||'No updates to id'||p_req_line_rec.line_id);
4940 		  END IF;
4941 		  exit;
4942 	    End If;
4943 
4944 	    IF p_req_related_line_tbl(i).related_line_detail_index = detail_index
4945 	       and p_req_line_detail_tbl(detail_index).line_detail_type_code ='CHILD_DETAIL_LINE'
4946 	   	  and p_req_line_detail_tbl(p_req_related_line_tbl(i).line_detail_index).applied_flag = 'Y'
4947 		  and p_Req_related_line_tbl(i).Relationship_Type_Code = 'PBH_LINE'
4948 	    Then
4949 	       l_process_child_yn := 'Y';
4950 		  IF (l_debug = 'Y') THEN
4951    		  my_debug(' process child line ');
4952 		  END IF;
4953 		  exit;
4954 		End If;
4955 
4956 		i := p_Req_RELATED_LINE_TBL.next(i);
4957 	End loop;
4958 
4959 END IS_SERVICED_REQ_LINE;
4960 --tope pbh changes
4961 
4962 
4963 BEGIN
4964     IF (l_debug = 'Y') THEN
4965        okc_debug.Set_Indentation('PROCESS_ADJUSTMENT_DETAILS');
4966     END IF;
4967     IF (l_debug = 'Y') THEN
4968        my_debug('14700 : Entering PROCESS_ADJUSTMENT_DETAILS', 2);
4969        my_debug('14702 : chr_id'||p_chr_id, 1);
4970     END IF;
4971 
4972 ---????The below search for pat_ids can be replaced with saving pat_ids in load_applied_adjustments
4973 -- using a global pl/sql table but donot know how that will behave when we switch to html.
4974 -- So check more on that and if feasible, change below for better performance
4975   IF (l_debug = 'Y') THEN
4976      my_debug('14702 : Number of lines to be processed'||p_cle_price_tbl.count, 2);
4977   END IF;
4978   x_return_status := OKC_API.G_RET_STS_SUCCESS;
4979   IF p_cle_price_tbl.count > 0 then
4980     i:=p_cle_price_tbl.first;
4981     IF (l_debug = 'Y') THEN
4982        my_debug('14704 :line Id whose adjustments are being fetched'||p_cle_price_tbl(i).id, 2);
4983     END IF;
4984 
4985     while i is not null loop
4986        select cle_id,id,list_line_no,list_header_id,object_version_number
4987        bulk collect into l_id_tmp_tbl,l_pat_tmp_tbl,l_line_tmp_tbl,l_list_tmp_tbl,l_obj_tmp_tbl
4988        from OKC_PRICE_ADJUSTMENTS
4989        where cle_id=p_cle_price_tbl(i).id and chr_id=p_chr_id;
4990          IF (l_debug = 'Y') THEN
4991             my_debug('14710 :line adjustments select rowcount'||SQL%ROWCOUNT, 1);
4992          END IF;
4993 
4994             k:= l_pat_tmp_tbl.first;
4995             j:= l_id_tbl.count;
4996             while k is not null loop
4997                 j:=j+1;
4998                 l_id_tbl(j):=l_id_tmp_tbl(k);
4999                 l_pat_id_tbl(j):=l_pat_tmp_tbl(k);
5000                 l_line_no_tbl(j) := l_line_tmp_tbl(k);
5001                 l_list_hdr_tbl(j) := l_list_tmp_tbl(k);
5002                 l_obj_tbl(j)    := l_obj_tmp_tbl(k);
5003               k:=l_pat_tmp_tbl.next(k);
5004             End Loop;
5005         i:=p_cle_price_tbl.next(i);
5006     End Loop;
5007   End If; --p_cle_price_tbl.count
5008   --  we always send the header line even when a line
5009   -- is repriced. When a line is repriced , we send header line's price_flag='N'
5010   --  We donot expect to get new header adjustments. Any mismacth
5011   -- will be caught when header is repriced again that is header line's price_flag='Y' or in QA
5012  If p_control_rec.p_level = 'H' and p_chr_id is not null then
5013  -- we donot want to touch the header adjustments if only one line is getting repriced
5014        select chr_id,id,list_line_no,list_header_id,object_version_number
5015        bulk collect into l_id_tmp_tbl,l_pat_tmp_tbl,l_line_tmp_tbl,l_list_tmp_tbl,l_obj_tmp_tbl
5016        from OKC_PRICE_ADJUSTMENTS
5017        where chr_id=p_chr_id and cle_id is null;
5018        IF (l_debug = 'Y') THEN
5019           my_debug('14750 : header adjustments select rowcount'||SQL%ROWCOUNT, 1);
5020        END IF;
5021 
5022             k:= l_pat_tmp_tbl.first;
5023             j:= l_id_tbl.count;
5024             while k is not null loop
5025                 j:=j+1;
5026                 l_id_tbl(j):=l_id_tmp_tbl(k);
5027                 l_pat_id_tbl(j):=l_pat_tmp_tbl(k);
5028                 l_line_no_tbl(j) := l_line_tmp_tbl(k);
5029                 l_list_hdr_tbl(j) := l_list_tmp_tbl(k);
5030                 l_obj_tbl(j)    := l_obj_tmp_tbl(k);
5031               k:=l_pat_tmp_tbl.next(k);
5032             End Loop;
5033   End if;
5034 
5035 -- add the adjustments at top model dummy line Id. There could be some if the
5036 -- line was first evaluated without configuring. These need to be deleted now
5037   IF (l_debug = 'Y') THEN
5038      my_debug('14740 :config flag'||p_control_rec.p_config_yn, 1);
5039      my_debug('14741 : top model line id'||p_control_rec.p_top_model_id, 1);
5040      my_debug('14741 : chr id'||p_chr_id, 1);
5041   END IF;
5042  If p_control_rec.p_config_yn = 'S' and p_control_rec.p_top_model_id is not null  then
5043 
5044        select cle_id,id,list_line_no,list_header_id,object_version_number
5045        bulk collect into l_id_tmp_tbl,l_pat_tmp_tbl,l_line_tmp_tbl,l_list_tmp_tbl,l_obj_tmp_tbl
5046        from OKC_PRICE_ADJUSTMENTS
5047        where cle_id=p_control_rec.p_top_model_id and chr_id=p_chr_id;
5048        IF (l_debug = 'Y') THEN
5049           my_debug('14745 : top dummy line adjustments select rowcount'||SQL%ROWCOUNT, 1);
5050        END IF;
5051 
5052             k:= l_pat_tmp_tbl.first;
5053             j:= l_id_tbl.count;
5054             while k is not null loop
5055                 j:=j+1;
5056                 l_id_tbl(j):=l_id_tmp_tbl(k);
5057                 l_pat_id_tbl(j):=l_pat_tmp_tbl(k);
5058                 l_line_no_tbl(j) := l_line_tmp_tbl(k);
5059                 l_list_hdr_tbl(j) := l_list_tmp_tbl(k);
5060                 l_obj_tbl(j)    := l_obj_tmp_tbl(k);
5061               k:=l_pat_tmp_tbl.next(k);
5062             End Loop;
5063         i:=p_cle_price_tbl.next(i);
5064   End if;
5065 
5066    x_return_status := clean_adj_assocs(l_pat_id_tbl);
5067    IF x_return_status <> OKC_API.G_RET_STS_SUCCESS THEN
5068           RAISE l_exception_stop;
5069    END IF;
5070 
5071    x_return_status := clean_adj_attrib(l_pat_id_tbl);
5072    IF x_return_status <> OKC_API.G_RET_STS_SUCCESS THEN
5073           RAISE l_exception_stop;
5074    END IF;
5075 
5076    IF (l_debug = 'Y') THEN
5077       my_debug('14755 :starting adjustment loop', 1);
5078    END IF;
5079 
5080    i:= p_req_line_detail_tbl.first;
5081    while i is not null loop --#1.1
5082        IF (l_debug = 'Y') THEN
5083           my_debug('14760 : Index of the request line detail under process '||i, 1);
5084           my_debug('14762 : status code '||p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).status_code, 1);
5085           my_debug('14764 : process code '||p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).processed_code, 1);
5086           my_debug('14766 : applied flag '||p_req_line_detail_tbl(i).applied_flag, 1);
5087           my_debug('14767 : created from list type code '||p_req_line_detail_Tbl(i).created_from_list_type_code, 1);
5088           my_debug('14768 : line OR header adjustment-'||p_req_line_tbl(p_req_line_detail_Tbl(i).line_index).line_Type_code, 1);
5089        END IF;
5090 
5091 
5092        --tope pbh changes
5093        IS_SERVICED_REQ_LINE(  p_req_line_tbl( p_req_line_detail_Tbl(i).line_index),
5094 	                      i,
5095 			      lx_serviced_rec_yn      ,
5096 			      lx_process_child_yn    );
5097        --tope pbh changes
5098 
5099 
5100 
5101        if  p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).status_code in (
5102 				QP_PREQ_GRP.G_STATUS_UPDATED
5103                 ,QP_PREQ_GRP.G_STATUS_GSA_VIOLATION
5104                 ,QP_PREQ_GRP.G_STATUS_NEW
5105 			 ,QP_PREQ_GRP.G_STATUS_UNCHANGED
5106                 ,QP_PREQ_GRP.G_STATUS_SYSTEM_GENERATED )
5107 			and (p_req_line_tbl(p_req_line_detail_Tbl(i).line_index).line_Type_code ='LINE'
5108                   and nvl(p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).processed_code,'0')
5109 			           <> QP_PREQ_GRP.G_BY_ENGINE
5110 			  --commented out to support negative pricing
5111                  --   and ( p_req_line_tbl(p_req_line_detail_Tbl(i).line_index).unit_price >= 0
5112                  --        and p_req_line_tbl(p_req_line_detail_Tbl(i).line_index).Adjusted_unit_price >= 0))
5113                 OR
5114                 (p_req_line_tbl(p_req_line_detail_Tbl(i).line_index).line_Type_code ='ORDER'
5115                   and  p_control_rec.p_level='H'))
5116 
5117                 --????? If we plan a UI for Price breaks, this condition might go
5118            -- tope pbh changes
5119            and ( p_req_line_detail_tbl(i).applied_flag= 'Y'
5120 		     OR  nvl(lx_process_child_yn,'N')='Y' )
5121            -- do not process adjustment if request line created just for pricing service only
5122            --and is_serviced_req_line(p_req_line_tbl( p_req_line_detail_Tbl(i).line_index),p_req_related_line_tbl) = 'N'
5123 		 and  nvl(lx_serviced_rec_yn,'N') = 'N'
5124 	   then
5125 
5126 
5127 		if p_req_line_detail_Tbl(i).created_from_list_type_code <> 'PRL' and  --#2
5128 		   p_req_line_detail_Tbl(i).created_from_list_type_code <> 'AGR' and
5129 		   p_req_line_detail_Tbl(i).list_line_type_code <> 'PLL' and
5130 		   --Bug 2452258 Do not display freight charges as we donot handle them
5131 		   p_req_line_detail_Tbl(i).list_line_type_code <> 'FREIGHT_CHARGE'
5132 		then
5133 
5134           k:= l_id_tbl.first;
5135           l_found := false;
5136           IF (l_debug = 'Y') THEN
5137              my_debug('14772 : looking for line/header id'||p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).line_id, 1);
5138           END IF;
5139          --Bug 2389314 Get qty of service line to display accurate adjustment value
5140           If p_service_qty_tbl.exists( p_req_line_detail_Tbl(i).line_index) Then
5141              p_qty :=  p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).priced_quantity;
5142              IF (l_debug = 'Y') THEN
5143                 my_debug('14773 : service qty'||p_qty);
5144              END IF;
5145           Elsif p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).priced_quantity <> p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).line_quantity Then
5146 		    p_qty:=(p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).priced_quantity/p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).line_quantity);
5147 
5148 		    IF (l_debug = 'Y') THEN
5149    		    my_debug('14773.1: priced qty '||p_qty);
5150 		    END IF;
5151 		Else
5152 		    p_qty:=1;
5153           End If;
5154 
5155           while k is not null  loop
5156 
5157              If l_id_tbl(k) = p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).line_id
5158                 and p_req_line_detail_tbl(i).list_line_no = l_line_no_tbl(k) and
5159                   p_req_line_detail_tbl(i).list_header_id = l_list_hdr_tbl(k) then
5160                 l_found := true;
5161                 exit;
5162              END IF;
5163              k:=l_id_tbl.next(k);
5164           End loop;
5165           If l_found  then
5166               --add record for update
5167              IF (l_debug = 'Y') THEN
5168                 my_debug('14774 : Update the record as found the adjustment at k '||k, 1);
5169              END IF;
5170              LOAD_ADJ_LINES(
5171                p_req_line_detail_tbl(i),
5172                'U',
5173                nvl(p_qty,1),
5174             --   l_pat_id_tbl(j),
5175               -- l_obj_tbl(j),
5176               l_pat_id_tbl(k),
5177               l_obj_tbl(k),
5178                l_patv_rec
5179                );
5180               l_pat_id_tbl.delete(k);
5181               l_patv_rec.chr_id :=p_chr_id;
5182               If p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).line_id <> p_chr_id then
5183                l_patv_rec.cle_id :=p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).line_id;
5184               End if;
5185 
5186              IF (l_debug = 'Y') THEN
5187                 my_debug('14776 : Before calling update price adjustment '||x_return_status, 1);
5188              END IF;
5189 
5190               OKC_PRICE_ADJUSTMENT_PUB.update_price_adjustment(
5191                     p_api_version      => p_api_version,
5192                     x_return_status    => x_return_status ,
5193                     x_msg_count        => x_msg_count,
5194                     x_msg_data         => x_msg_data,
5195                     p_patv_rec         => l_patv_rec,
5196                     x_patv_rec         => lx_patv_rec );
5197             IF (l_debug = 'Y') THEN
5198                my_debug('14778 : after calling update price adjustment '||x_return_status, 1);
5199             END IF;
5200 
5201              IF x_return_status <> OKC_API.G_RET_STS_SUCCESS THEN
5202                    RAISE l_exception_stop;
5203              END IF;
5204 
5205 
5206              -- store the pat_id of pbh and child_detail_lines as we are going to use get associations
5207 		   --tope pbh changes
5208 		   If p_req_line_detail_Tbl(i).list_line_type_code ='PBH' OR
5209 		      p_req_line_detail_Tbl(i).line_detail_type_code = 'CHILD_DETAIL_LINE'  Then
5210 
5211 			 l_price_break_tbl(i).pat_id := lx_patv_rec.id;
5212 			 l_price_break_tbl(i).line_detail_index := i;
5213 			 l_price_break_tbl(i).cle_id := p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).line_id;
5214 
5215 			 IF p_req_line_detail_Tbl(i).list_line_type_code ='PBH' Then
5216 			    l_price_break_tbl(i).list_line_type_code :=p_req_line_detail_Tbl(i).list_line_type_code ;
5217 			 Else
5218 			    l_price_break_tbl(i).list_line_type_code :=p_req_line_detail_Tbl(i).line_detail_type_code ;
5219 			 end if;
5220 		   End if;
5221 	     --tope pbh
5222 
5223            else -- if not found
5224              IF (l_debug = 'Y') THEN
5225                 my_debug('14779 : Insert the record as not found the adjustment', 1);
5226              END IF;
5227 
5228                LOAD_ADJ_LINES(
5229                p_Req_LINE_DETAIL_rec=>p_req_line_detail_tbl(i),
5230                px_patv_rec=>l_patv_rec,
5231                p_service_qty => nvl(p_qty,1)
5232                );
5233               l_patv_rec.chr_id :=p_chr_id;
5234               If p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).line_id <> p_chr_id then
5235                l_patv_rec.cle_id :=p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).line_id;
5236               End if;
5237 
5238 
5239             IF (l_debug = 'Y') THEN
5240                my_debug('14780 : before calling create price adjustment '||x_return_status, 1);
5241             END IF;
5242 
5243                 OKC_PRICE_ADJUSTMENT_PUB.create_price_adjustment(
5244                     p_api_version      => p_api_version,
5245                     x_return_status    => x_return_status ,
5246                     x_msg_count        => x_msg_count,
5247                     x_msg_data         => x_msg_data,
5248                     p_patv_rec         => l_patv_rec,
5249                     x_patv_rec         => lx_patv_rec );
5250             IF (l_debug = 'Y') THEN
5251                my_debug('14781 : after calling create price adjustment '||x_return_status, 1);
5252             END IF;
5253 
5254                 IF x_return_status <> OKC_API.G_RET_STS_SUCCESS THEN
5255                   RAISE l_exception_stop;
5256                 Else
5257 		    --tope pbh
5258 		    -- store the pat_id of pbh and child_detail_lines as we are going to use get associations
5259 		    If p_req_line_detail_Tbl(i).list_line_type_code ='PBH' OR
5260 			      p_req_line_detail_Tbl(i).line_detail_type_code = 'CHILD_DETAIL_LINE'  Then
5261 
5262 			 l_price_break_tbl(i).pat_id := lx_patv_rec.id;
5263 			 l_price_break_tbl(i).line_detail_index := i;
5264 			 l_price_break_tbl(i).cle_id := p_req_line_tbl( p_req_line_detail_Tbl(i).line_index).line_id;
5265 			 IF p_req_line_detail_Tbl(i).list_line_type_code ='PBH' Then
5266 				    l_price_break_tbl(i).list_line_type_code :=p_req_line_detail_Tbl(i).list_line_type_code ;
5267 			 Else
5268 				    l_price_break_tbl(i).list_line_type_code :=p_req_line_detail_Tbl(i).line_detail_type_code ;
5269 			 end if;
5270 		    End if;
5271 		    --tope pbh
5272 
5273                 END IF;
5274 
5275            END IF; --l_found
5276             IF (l_debug = 'Y') THEN
5277                my_debug('14782 : record added to new adjustment table at index '||i, 1);
5278             END IF;
5279 
5280            l_new_pat_tbl(i):=lx_patv_rec.id;
5281            l_patv_rec:=l_patv_dummy_rec;
5282            lx_patv_rec:=l_patv_dummy_rec;
5283          END IF; --#2
5284 
5285          --???? insert logic for inserting price break relationships if needed.
5286       End If;--big if
5287       i:= p_req_line_detail_tbl.next(i);
5288 
5289    end loop;--#1.1
5290 
5291 
5292 
5293    -- tope pbh process adjustment associations
5294 
5295     declare
5296 
5297              cursor c1(p_pat_id_from number ,p_pat_id number ,p_cle_id number)  is
5298 		   select id from okc_price_adj_assocs_v
5299 		   where pat_id_from = p_pat_id_from
5300 		   and pat_id =p_pat_id
5301 		   and cle_id = p_cle_id;
5302 
5303 		   p_pacv_rec okc_price_adjustment_pub.pacv_rec_type;
5304 		   x_pacv_rec okc_price_adjustment_pub.pacv_rec_type;
5305 		   l_id number;
5306 		   p_pat_id_from number;
5307 		   p_pat_id number;
5308 		   p_cle_id number;
5309 
5310     begin
5311 	/* x := l_price_break_tbl.first;
5312 	while x is not null loop
5313           IF (l_debug = 'Y') THEN
5314              my_debug('x'||x);
5315    	     my_debug('TOPE pat id '||l_price_break_tbl(x).pat_id );
5316    	     my_debug('TOPE line_index '||l_price_break_tbl(x).line_detail_index );
5317    	     my_debug('TOPE cle_id '||l_price_break_tbl(x).cle_id );
5318    	     my_debug('TOPE type_code '||l_price_break_tbl(x).list_line_type_code );
5319           END IF;
5320           x := l_price_break_tbl.next(x);
5321 	 end loop;
5322 	*/
5323 
5324 	i := p_Req_RELATED_LINE_TBL.first;
5325 	while (i is not null) and (p_Req_RELATED_LINE_TBL(i).relationship_type_code= 'PBH_LINE') LOOP
5326 	     --id of the adjustment header
5327 	     If l_price_break_tbl.exists(p_Req_RELATED_LINE_TBL(i).line_detail_index) Then
5328 	        p_pat_id_from  :=  l_price_break_tbl( p_Req_RELATED_LINE_TBL(i).line_detail_index).pat_id;
5329 
5330              --id of the child line
5331 		   p_pat_id       :=  l_price_break_tbl( p_Req_RELATED_LINE_TBL(i).related_line_detail_index).pat_id;
5332 
5333 		   -- line_id
5334 		   p_cle_id       :=  l_price_break_tbl( p_Req_RELATED_LINE_TBL(i).related_line_detail_index).cle_id;
5335 
5336 		   open c1(p_pat_id_from,p_pat_id,p_cle_id);
5337 		   fetch c1 into l_id;
5338 		   close c1;
5339 
5340              If l_id is null Then
5341 			 p_pacv_rec.pat_id := p_pat_id;
5342 			 p_pacv_rec.cle_id  := p_cle_id;
5343 			 p_pacv_rec.pat_id_from := p_pat_id_from;
5344 
5345                 okc_price_adjustment_pub.create_price_adj_assoc(
5346 			     p_api_version      => p_api_version,
5347 			     x_return_status    => x_return_status ,
5348 			     p_init_msg_list    => p_init_msg_list ,
5349 			     x_msg_data      => x_msg_data,
5350 			     x_msg_count        => x_msg_count,
5351 			     p_pacv_rec       =>   p_pacv_rec,
5352 			     x_pacv_rec       =>   x_pacv_rec) ;
5353 
5354              Else
5355 		      IF (l_debug = 'Y') THEN
5356    		      my_debug('already exists'||l_id);
5357 		      END IF;
5358 		   End If;
5359 		End If;
5360 		   l_id :=null;
5361 		   i := p_Req_RELATED_LINE_TBL.next(i);
5362 	End LOOP;
5363 	end;
5364 	---tope pbh CHANGES
5365 
5366 
5367 
5368 
5369            --????delete all the records with whatever ids left in l_pat_id_tbl;
5370            IF (l_debug = 'Y') THEN
5371               my_debug('14784 : delete the left over old price adjustments '||l_pat_id_tbl.count, 1);
5372            END IF;
5373 
5374            i:=l_pat_id_tbl.first;
5375            while i is not null loop
5376              l_patv_tbl(i).id := l_pat_id_tbl(i);
5377 ---Bug 2143816
5378              l_patv_tbl(i).chr_id := p_chr_id;
5379 		   If l_id_tbl(i) <> p_chr_id then
5380      		    l_patv_tbl(i).cle_id := l_id_tbl(i);
5381              End If;
5382 -----
5383              IF (l_debug = 'Y') THEN
5384                 my_debug('14785 : id of the deleted adjustment '||l_patv_tbl(i).id, 1);
5385              END IF;
5386 
5387              i:=l_pat_id_tbl.next(i);
5388            end loop;
5389 
5390            IF (l_debug = 'Y') THEN
5391               my_debug('14786 :before calling delete price adjustments'||x_return_status, 1);
5392            END IF;
5393 
5394            IF l_patv_tbl.count > 0 then
5395                OKC_PRICE_ADJUSTMENT_PUB.delete_price_adjustment(
5396                     p_api_version      => p_api_version,
5397                     x_return_status    => x_return_status ,
5398                     x_msg_count        => x_msg_count,
5399                     x_msg_data         => x_msg_data,
5400                     p_patv_tbl         => l_patv_tbl);
5401                IF (l_debug = 'Y') THEN
5402                   my_debug('14787 :after calling delete price adjustments'||x_return_status, 1);
5403                END IF;
5404 
5405               IF x_return_status <> OKC_API.G_RET_STS_SUCCESS THEN
5406                    RAISE l_exception_stop;
5407               END IF;
5408            END IF;
5409            --???create records in adj_assocs;
5410             IF (l_debug = 'Y') THEN
5411                my_debug('14790 :Before calling Create adjustment attribs'||x_return_status, 1);
5412             END IF;
5413            --create records in adj attribs
5414               x_return_status := create_adj_attrib;
5415             IF (l_debug = 'Y') THEN
5416                my_debug('14792 :after calling Create adjustment attribs'||x_return_status, 1);
5417             END IF;
5418 
5419               IF x_return_status <> OKC_API.G_RET_STS_SUCCESS THEN
5420                   RAISE l_exception_stop;
5421               END IF;
5422               --?????process relationship recs
5423     IF (l_debug = 'Y') THEN
5424        my_debug('14800 : Exiting PROCESS_ADJUSTMENT_DETAILS', 2);
5425     END IF;
5426 
5427 
5428     IF (l_debug = 'Y') THEN
5429        okc_debug.Reset_Indentation;
5430     END IF;
5431 
5432   EXCEPTION
5433     when l_exception_stop then
5434        null;
5435        IF (l_debug = 'Y') THEN
5436           my_debug('14850 : Exiting PROCESS_ADJUSTMENT_DETAILS', 4);
5437        END IF;
5438        IF (l_debug = 'Y') THEN
5439           okc_debug.Reset_Indentation;
5440        END IF;
5441 
5442     When others then
5443          --dbms_output.put_line('came here'||sqlcode||substr(sqlerrm,1,235));
5444           OKC_API.set_message(p_app_name      => g_app_name,
5445                                    p_msg_name      => G_UNEXPECTED_ERROR,
5446                                    p_token1        => G_SQLCODE_TOKEN,
5447                                    p_token1_value  => SQLCODE,
5448                                    p_token2        => G_SQLERRM_TOKEN,
5449                                    p_token2_value  => SQLERRM);
5450            x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
5451        IF (l_debug = 'Y') THEN
5452           my_debug('14900 : Exiting PROCESS_ADJUSTMENT_DETAILS', 4);
5453        END IF;
5454        IF (l_debug = 'Y') THEN
5455           okc_debug.Reset_Indentation;
5456        END IF;
5457 
5458 
5459 END PROCESS_ADJUSTMENT_DETAILS;
5460 ----------------------------------------------------------------------------
5461 -- Process_Adjustments
5462 -- This procedure will check all the lines that get returned from pricing
5463 -- and take appropriate action.
5464 -- Modified to price service lines
5465 ----------------------------------------------------------------------------
5466 PROCEDURE PROCESS_ADJUSTMENTS(
5467           p_api_version                IN     NUMBER,
5468           p_init_msg_list              IN     VARCHAR2 DEFAULT OKC_API.G_FALSE,
5469           p_CHR_ID                     IN     NUMBER,
5470           p_Control_Rec			       IN     OKC_CONTROL_REC_TYPE,
5471           p_req_line_tbl               IN     QP_PREQ_GRP.LINE_TBL_TYPE,
5472           p_Req_LINE_DETAIL_tbl        IN     QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE,
5473           p_Req_LINE_DETAIL_qual_tbl   IN     QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE,
5474           p_Req_LINE_DETAIL_attr_tbl   IN     QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE,
5475           p_Req_RELATED_LINE_TBL       IN     QP_PREQ_GRP.RELATED_LINES_TBL_TYPE,
5476           px_CLE_PRICE_TBL		       IN OUT NOCOPY    CLE_PRICE_TBL_TYPE,
5477           x_return_status              OUT  NOCOPY VARCHAR2,
5478           x_msg_count                  OUT  NOCOPY NUMBER,
5479           x_msg_data                   OUT  NOCOPY VARCHAR2) IS
5480 
5481           I pls_integer :=0;
5482           J pls_integer :=0;
5483           K pls_integer :=0;
5484 
5485           l_prc1   varchar(240);
5486           l_prc2   varchar(240);
5487           l_line_rec    cle_price_REC_TYPE;
5488           l_dummy_rec   cle_price_REC_TYPE;
5489           l_return_status varchar2(1):= OKC_API.G_RET_STS_SUCCESS;
5490           l_sts        varchar2(1):='S';
5491           p_line_ind     number  := 0;
5492           p_found boolean  := false;
5493           t pls_integer  :=0;
5494           l_cle_price_tbl cle_price_tbl_type := px_cle_price_tbl;
5495           p_service_qty_tbl NUM_TBL_TYPE;
5496           CURSOR l_cur is
5497                  Select name
5498                  from okx_list_headers_v a,okx_qp_list_lines_v b
5499                  where
5500                  (b.id1 =  to_number(substr(p_req_line_tbl(i).status_text,1,
5501 									instr(p_req_line_tbl(i).status_text,',')-1))
5502                  OR
5503                  b.id1 =  to_number(substr(p_req_line_tbl(i).status_text,
5504 									instr(p_req_line_tbl(i).status_text,',')+1)))
5505                  and a.id1=b.list_header_id;
5506 
5507 
5508    Function is_service_subline(p_id number) return varchar2 is
5509       result  varchar2(1) := 'N';
5510 	BEGIN
5511 
5512      IF (l_debug = 'Y') THEN
5513         my_debug('100:In is_service_subline ');
5514      END IF;
5515 
5516      Select nvl(service_item_yn,'N') service_item_yn into result
5517 	From okc_k_lines_b
5518      where id = (Select cle_id from okc_k_lines_b where id =p_id);
5519 
5520      IF (l_debug = 'Y') THEN
5521         my_debug('101: Result is'||result);
5522      END IF;
5523      return result;
5524 
5525 	Exception
5526 	 when no_data_found then
5527         IF (l_debug = 'Y') THEN
5528            my_debug ('102: No data found');
5529         END IF;
5530 	   return result ;
5531       when others then
5532 	   IF (l_debug = 'Y') THEN
5533    	   my_debug('103: Other error');
5534 	   END IF;
5535    END is_service_subline;
5536 
5537 
5538   BEGIN
5539     IF (l_debug = 'Y') THEN
5540        okc_debug.Set_Indentation('PROCESS_ADJUSTMENTS');
5541     END IF;
5542     IF (l_debug = 'Y') THEN
5543        my_debug('15000 : Entering PROCESS_ADJUSTMENTS', 2);
5544     END IF;
5545 
5546          --dbms_output.put_line('a1-starting process adjustments'||p_req_line_tbl.count);
5547           If px_cle_price_tbl.count =0  then
5548               IF p_control_rec.p_level = 'QA' then
5549                  -- this case might never be reached by QA but still putting the check
5550                    l_return_status:= OKC_API.G_RET_STS_SUCCESS;
5551               Else
5552                   OKC_API.set_message(p_app_name      => g_app_name,
5553                                       p_msg_name      => 'OKC_NO_QP_ROW');
5554                    l_return_status:= OKC_API.G_RET_STS_ERROR;
5555 
5556               End IF;
5557               Raise l_exception_stop;
5558           End If;
5559           i:=  p_req_line_tbl.first;
5560           While I is not null Loop --#1
5561                        p_found := false;
5562                        p_line_ind := 0;
5563     -- Check If line is in priced_tbl
5564    --- Using l_cle_price_tbl as px_cle_price_tbl gets updated later
5565                        t := l_cle_price_tbl.first;
5566                        While t is not null loop
5567                          if l_cle_price_tbl(t).id = p_req_line_tbl(i).line_id then
5568                             p_line_ind := t;
5569                             p_found := true;
5570                          exit ;
5571                          End If;
5572                          t:= l_cle_price_tbl.next(t);
5573                        End Loop;
5574                 l_prc1:=null;
5575                 If p_found  then
5576   				l_line_rec := px_cle_price_tbl(p_line_ind);
5577                     IF (l_debug = 'Y') THEN
5578                        my_debug('15005:index of request line being processed'||(p_req_line_tbl(i).line_index));
5579                        my_debug('15006:id of request line being processed'||(p_req_line_tbl(i).line_id));
5580                     END IF;
5581                 else
5582                      l_line_rec := l_dummy_rec;
5583                      IF (l_debug = 'Y') THEN
5584                         my_debug('15010:check :is it generated line'||(p_req_line_tbl(i).line_index));
5585                      END IF;
5586                 End if;
5587 
5588                 If l_line_rec.id <> 0 then  --#1.1 That means found the rec. filter out nocopy free goods and header line
5589                   l_line_rec.ret_sts := 'E';
5590               	  if--#2
5591                       p_req_line_tbl(i).line_Type_code ='LINE' and  --#2
5592   	                  p_req_line_tbl(i).status_code in ( QP_PREQ_GRP.G_STATUS_INVALID_PRICE_LIST,
5593 				              QP_PREQ_GRP.G_STS_LHS_NOT_FOUND,
5594 				              QP_PREQ_GRP.G_STATUS_FORMULA_ERROR,
5595 				              QP_PREQ_GRP.G_STATUS_OTHER_ERRORS,
5596 				              OKC_API.G_RET_STS_UNEXP_ERROR,
5597 				              OKC_API.G_RET_STS_ERROR,
5598 				              QP_PREQ_GRP.G_STATUS_CALC_ERROR,
5599 				              QP_PREQ_GRP.G_STATUS_UOM_FAILURE,
5600 				              QP_PREQ_GRP.G_STATUS_INVALID_UOM,
5601 				              QP_PREQ_GRP.G_STATUS_DUP_PRICE_LIST,
5602 				              QP_PREQ_GRP.G_STATUS_INVALID_UOM_CONV,
5603 				              QP_PREQ_GRP.G_STATUS_INVALID_INCOMP,
5604 				              QP_PREQ_GRP.G_STATUS_BEST_PRICE_EVAL_ERROR,
5605 			                  QP_PREQ_PUB.G_BACK_CALCULATION_STS)
5606 	                then
5607                       IF (l_debug = 'Y') THEN
5608                          my_debug('15020: some error in request, code-'||p_req_line_tbl(i).status_code);
5609                          my_debug('15022: pricelist id on line-'||l_line_rec.pricelist_id);
5610                       END IF;
5611                       If l_line_rec.pricelist_id is not null then
5612 		               Begin
5613 	 		                 Select name
5614                              into l_prc1
5615 			                 from okx_list_headers_v
5616                              where id1 = l_line_rec.pricelist_id;
5617                              IF (l_debug = 'Y') THEN
5618                                 my_debug('15050 : select rowcount for pricelist name'||SQL%ROWCOUNT, 1);
5619                              END IF;
5620 
5621 			                 Exception
5622                                When No_data_found then
5623                                  l_prc1 := l_line_rec.pricelist_id;
5624                                  IF (l_debug = 'Y') THEN
5625                                     my_debug('15051 : Exception no data found', 2);
5626                                  END IF;
5627 
5628 		               End;
5629                       END IF;
5630 
5631                        If l_line_rec.line_num is null then
5632                        -- get the concatenated line number to show in error message
5633                            l_line_rec.line_num := OKC_CONTRACT_PUB.Get_concat_line_no(
5634                               p_cle_id       =>  l_line_rec.id ,
5635                               x_return_status => l_return_status
5636                            );
5637                            If l_return_status <> okc_api.g_ret_sts_success Then
5638                                l_line_rec.line_num := 'Unknown';
5639                            End If;
5640 
5641                        End if;
5642                        IF (l_debug = 'Y') THEN
5643                           my_debug('15060 : error line Id'||l_line_rec.id, 1);
5644                           my_debug('15062 : Error Line String'||l_line_rec.line_num, 1);
5645                        END IF;
5646 
5647 
5648                       --san  x_return_status := OKC_API.G_RET_STS_ERROR;
5649                       x_return_status :=G_SOME_LINE_ERRORED;
5650                        --?????change all pricing error names to OKC_QP_... later
5651                        If p_req_line_tbl(i).status_code  = QP_PREQ_GRP.G_STATUS_INVALID_PRICE_LIST
5652                              and l_prc1 is not null then --#3
5653                                 OKC_API.set_message(p_app_name      => g_app_name,
5654                                    p_msg_name      => 'OKC_QP_INVALID_PRICE_LIST', --invalid pricelist/item combi
5655                                    p_token1        => 'line_num',
5656                                    p_token1_value  => l_line_rec.line_num,
5657                                    p_token2        => 'Price_list',
5658                                    p_token2_value  => l_prc1);
5659                        Elsif p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STS_LHS_NOT_FOUND
5660                              OR (p_req_line_tbl(i).status_code  = QP_PREQ_GRP.G_STATUS_INVALID_PRICE_LIST
5661                              AND l_prc1 is null ) Then
5662                                 OKC_API.set_message(p_app_name      => g_app_name,
5663                                    p_msg_name      => 'OKC_QP_NO_PRICE_LIST', --pricelist not found
5664                                    p_token1        => 'LINE_NUM',
5665                                    p_token1_value  => l_line_rec.line_num);
5666   		               Elsif p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STATUS_FORMULA_ERROR then
5667                                 OKC_API.set_message(p_app_name      => g_app_name,
5668                                    p_msg_name      => 'OKC_QP_FORMULA_ERROR', --Error in formula processing
5669                                    p_token1        => 'line_num',
5670                                    p_token1_value  => l_line_rec.line_num);
5671   		               Elsif p_req_line_tbl(i).status_code in
5672 				          (QP_PREQ_GRP.G_STATUS_OTHER_ERRORS , FND_API.G_RET_STS_UNEXP_ERROR,
5673 						       FND_API.G_RET_STS_ERROR)
5674 		               then
5675                             OKC_API.set_message(p_app_name      => g_app_name,
5676                                    p_msg_name      => 'OKC_QP_PRICING_ERROR', --other errors in processing
5677                                    p_token1        => 'line_num',
5678                                    p_token1_value  => l_line_rec.line_num,
5679                                    p_token2        => 'Err_Text',
5680                                    p_token2_value  => p_req_line_tbl(i).status_text);
5681 
5682 		               Elsif p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STATUS_INVALID_UOM then
5683                              OKC_API.set_message(p_app_name      => g_app_name,
5684                                    p_msg_name      => 'OKC_QP_INVALID_UOM', --invalid uom
5685                                    p_token1        => 'UOM',
5686                                    p_token1_value  => p_req_line_tbl(i).line_uom_code,
5687                                    p_token2        => 'line_num',
5688                                    p_token2_value  => l_line_rec.line_num);--????check priced or line uom here
5689                             --dbms_output.put_line('ddddd'||l_line_rec.line_num||'fff'||p_req_line_tbl(i).line_uom_code);
5690 		               Elsif p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STATUS_DUP_PRICE_LIST then
5691                            BEGIN
5692 					   ---Modified to show correct price lists in error message
5693 						 l_prc1 := null;
5694                                --open l_cur;
5695                                For cur_rec in l_cur LOOP
5696                                   If l_prc1 is null then
5697 							 l_prc1 := cur_rec.name;
5698                                    --Fetch l_cur into l_prc1;
5699                                   ELSE
5700 					           l_prc2 := cur_rec.name;
5701                                    --FETCH l_cur into l_prc2;
5702                                   END IF;
5703                                   --Exit when l_cur%NOTFOUND;
5704                                END LOOP; --????test this
5705                                --close l_cur;
5706                                If l_prc1 is null then
5707                                   l_prc1 := p_req_line_tbl(i).status_text;
5708                                ELSIF l_prc2 is null then
5709                                   l_prc1 := p_req_line_tbl(i).status_text;
5710                                END IF;
5711 
5712                                Exception
5713                                      When others then
5714                                         l_prc1 := p_req_line_tbl(i).status_text;
5715 
5716   	                       End;
5717 
5718                            OKC_API.set_message(p_app_name      => g_app_name,
5719                                    p_msg_name      => 'OKC_QP_DUP_PRICELIST', --duplicate pricelist
5720                                    p_token1        => 'line_num',
5721                                    p_token1_value  => l_line_rec.line_num,
5722                                    p_token2        => 'Price1',
5723                                    p_token2_value  => l_prc1,
5724                                    p_token3        => 'Price2',
5725                                    p_token3_value  => l_prc2);
5726 
5727                                    l_prc1:=null;
5728                                    l_prc2:=null;
5729                                             --dbms_output.put_line('a3');
5730 
5731 
5732 		               Elsif p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STATUS_INVALID_UOM_CONV then
5733                             OKC_API.set_message(p_app_name      => g_app_name,
5734                                    p_msg_name      => 'OKC_QP_INVAL_UOM_CONV', --invalid uom conversion
5735                                    p_token1        => 'line_num',
5736                                    p_token1_value  => l_line_rec.line_num,
5737                                    p_token2        => 'err_text',
5738                                    p_token2_value  => p_req_line_tbl(i).status_text);
5739 
5740                        Elsif p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STATUS_INVALID_INCOMP then
5741                             OKC_API.set_message(p_app_name      => g_app_name,
5742                                    p_msg_name      => 'OKC_QP_INVALID_INCOMP', --Unable to resolve incompatibility
5743                                    p_token1        => 'line_num',
5744                                    p_token1_value  => l_line_rec.line_num,
5745                                    p_token2        => 'err_text',
5746                                    p_token2_value  => p_req_line_tbl(i).status_text);
5747 		               Elsif p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STATUS_BEST_PRICE_EVAL_ERROR then
5748                             OKC_API.set_message(p_app_name      => g_app_name,
5749                                    p_msg_name      => 'OKC_QP_BEST_PRICE', --error while evaluating best price
5750                                    p_token1        => 'line_num',
5751                                    p_token1_value  => l_line_rec.line_num,
5752                                    p_token2        => 'err_text',
5753                                    p_token2_value  => p_req_line_tbl(i).status_text);
5754 
5755   	                   Else
5756                             OKC_API.set_message(p_app_name      => g_app_name,
5757                                    p_msg_name      => 'OKC_PRICING_ERROR', --error while pricing
5758                                    p_token1        => 'line_num',
5759                                    p_token1_value  => l_line_rec.line_num,
5760                                    p_token2        => 'err_text',
5761                                    p_token2_value  => p_req_line_tbl(i).status_text);
5762 
5763                       END IF;--#3
5764                       --???? if one price fails, say negative price, then do we raise error and come out
5765 				  --commenting out to support negative pricing
5766                   /* ELSIF  ( p_req_line_tbl(i).unit_price < 0 or p_req_line_tbl(i).Adjusted_unit_price < 0) then     --#2
5767                        IF l_line_rec.line_num is null then
5768                           -- get the concatenated line number to show in error message
5769                            l_line_rec.line_num := OKC_CONTRACT_PUB.Get_concat_line_no(
5770                               p_cle_id       =>  l_line_rec.id ,
5771                               x_return_status => l_return_status
5772                            );
5773                            If l_return_status <> okc_api.g_ret_sts_success Then
5774                                l_line_rec.line_num := 'Unknown';
5775                            End If;
5776                        END IF;
5777                        IF (l_debug = 'Y') THEN
5778                           my_debug('15450 : error line Id'||l_line_rec.id, 1);
5779                           my_debug('15460 : Error Line String'||l_line_rec.line_num, 1);
5780                        END IF;
5781 
5782 		                   OKC_API.set_message(p_app_name      => g_app_name,
5783                                    p_msg_name      => 'OKC_QP_NEG_PRICE', --???Is it an error for us?
5784                                    p_token1        => 'line_num',
5785                                    p_token1_value  => l_line_rec.line_num,
5786                                    p_token2        => 'LIST_PRICE',
5787                                    p_token2_value  => p_req_line_tbl(i).unit_price,
5788                                    p_token3        => 'SELLING_PRICE',
5789                                    p_token3_value  => p_req_line_tbl(i).adjusted_unit_price);
5790                             --san x_return_status := OKC_API.G_RET_STS_ERROR;
5791                             x_return_status := G_SOME_LINE_ERRORED;
5792                       */
5793 	               elsif p_req_line_tbl(i).line_Type_code ='LINE' and
5794                          p_req_line_tbl(i).status_code in
5795 				                ( QP_PREQ_GRP.G_STATUS_UPDATED,
5796                                   QP_PREQ_GRP.G_STATUS_NEW,
5797                                   QP_PREQ_GRP.G_STATUS_SYSTEM_GENERATED,
5798                                   QP_PREQ_GRP.G_STATUS_GSA_VIOLATION,
5799                                   QP_PREQ_GRP.G_STATUS_UNCHANGED,
5800 			                      QP_PREQ_PUB.G_BACK_CALCULATION_STS) and
5801 	                     --???? change later nvl(p_req_line_tbl(i).processed_code,'0') = QP_PREQ_PUB.G_BACK_CALCULATION_STS then
5802                          -- right now this way because of a bug in QP. Later on QP might return this error  in retcode on request line
5803                          -- also   QP_PREQ_PUB.G_BACK_CALCULATION_STS might hold 'BACK CALCULATION ERROR' instaed of
5804                          -- 'BACK_CALCULATION_ERROR'. Right now processed code returns 'BACK CALCULATION ERROR'
5805                          -- while QP_PREQ_PUB.G_BACK_CALCULATION_STS has value 'BACK_CALCULATION_ERROR'
5806                                  nvl(p_req_line_tbl(i).processed_code,'0') = 'BACK CALCULATION ERROR' then
5807                        IF l_line_rec.line_num is null then
5808                           -- get the concatenated line number to show in error message
5809                           l_line_rec.line_num := OKC_CONTRACT_PUB.Get_concat_line_no(
5810                               p_cle_id       =>  l_line_rec.id ,
5811                               x_return_status => l_return_status
5812                            );
5813                            If l_return_status <> okc_api.g_ret_sts_success Then
5814                               l_line_rec.line_num := 'Unknown';
5815                            End If;
5816                        END IF;
5817                        IF (l_debug = 'Y') THEN
5818                           my_debug('15500 : error line Id'||l_line_rec.id, 1);
5819                           my_debug('15510 : Error Line String'||l_line_rec.line_num, 1);
5820                        END IF;
5821 
5822                            OKC_API.set_message(p_app_name      => g_app_name,
5823                                    p_msg_name      => 'OKC_BACK_CALC_ERROR',
5824                                    p_token1        => 'line_num',
5825                                    p_token1_value  => l_line_rec.line_num);
5826                            --san  x_return_status := OKC_API.G_RET_STS_ERROR;
5827                             x_return_status := G_SOME_LINE_ERRORED;
5828 
5829 
5830 	               elsif p_req_line_tbl(i).line_Type_code ='LINE' and
5831                        p_req_line_tbl(i).status_code in
5832 				                ( QP_PREQ_GRP.G_STATUS_UPDATED,
5833                                   QP_PREQ_GRP.G_STATUS_NEW,
5834                                   QP_PREQ_GRP.G_STATUS_SYSTEM_GENERATED,
5835                                   QP_PREQ_GRP.G_STATUS_GSA_VIOLATION,
5836                                   QP_PREQ_GRP.G_STATUS_UNCHANGED) and
5837 	                     nvl(p_req_line_tbl(i).processed_code,'0') <> QP_PREQ_PUB.G_BY_ENGINE--????check this one
5838 	                     and p_req_line_tbl(i).price_flag IN ('Y','P')
5839 	                 then
5840                        --??? update line's unit price to null in case of error
5841                           --dbms_output.put_line('a2.5');
5842 
5843                         l_line_rec.ret_sts := 'S';
5844 
5845                         If is_service_subline(p_req_line_tbl(i).line_id) = 'N'   then
5846                           IF (l_debug = 'Y') THEN
5847                              my_debug(p_req_line_tbl(i).line_index||'not found'||p_req_line_tbl(i).line_id||'i'||i);
5848                           END IF;
5849                           If nvl(p_req_line_tbl(i).priced_quantity,0) <> nvl(p_req_line_tbl(i).line_quantity,0) then
5850                         ---???? unit price should be null in case of pbh
5851                                 l_line_rec.unit_price := p_req_line_tbl(i).unit_price
5852                                                  * (p_req_line_tbl(i).priced_quantity/p_req_line_tbl(i).line_quantity);
5853                           Else
5854                         ---???? unit price should be null in case of pbh
5855                                l_line_rec.unit_price := p_req_line_tbl(i).unit_price;
5856                           End if;
5857                         --l_line_rec.qty:= p_req_line_tbl(i).priced_quantity ;
5858                         --l_line_rec.uom_code:= p_req_line_tbl(i).priced_uom_code ;
5859                           l_line_rec.negotiated_amt := p_req_line_tbl(i).adjusted_unit_price* p_req_line_tbl(i).priced_quantity ;
5860                   --      l_line_rec.list_price := l_line_rec.unit_price * p_req_line_tbl(i).priced_quantity;
5861                   -- Bug 2487799
5862 			           l_line_rec.list_price := l_line_rec.unit_price * p_req_line_tbl(i).line_quantity;
5863                           l_line_rec.qty:= p_req_line_tbl(i).line_quantity ;
5864                           l_line_rec.uom_code := p_req_line_tbl(i).priced_uom_code;
5865 
5866                         Else
5867 
5868                             IF (l_debug = 'Y') THEN
5869                                my_debug('Service qty'||p_req_line_tbl(i).line_quantity );
5870                                my_debug('Service uom'||p_req_line_tbl(i).priced_uom_code);
5871                                my_debug('Cov uom'||p_req_line_tbl(i-1).priced_uom_code);
5872                                my_debug('Cov qty '||p_req_line_tbl(i-1).priced_quantity);
5873                                MY_DEBUG('Service adj_price'||p_req_line_tbl(i).adjusted_unit_price);
5874                                MY_DEBUG('Service unit_price'||p_req_line_tbl(i).unit_price);
5875                             END IF;
5876 
5877                            ---Multiply amounts by qty of service item
5878                            -- assign back qty and uom of covered line/item/products
5879                            -- using previous record, as covered line request is always before service line
5880 
5881                           If nvl(p_req_line_tbl(i).priced_quantity,0) <> nvl(p_req_line_tbl(i).line_quantity,0) then
5882                         ---???? unit price should be null in case of pbh
5883                                 l_line_rec.unit_price :=( p_req_line_tbl(i).unit_price
5884                                                  * (p_req_line_tbl(i).priced_quantity/p_req_line_tbl(i).line_quantity))*p_req_line_tbl(i).line_quantity;
5885                           Else
5886                         ---???? unit price should be null in case of pbh
5887                                l_line_rec.unit_price := p_req_line_tbl(i).unit_price* p_req_line_tbl(i).line_quantity;
5888                           End if;
5889                           l_line_rec.negotiated_amt := p_req_line_tbl(i).adjusted_unit_price* p_req_line_tbl(i).priced_quantity*p_req_line_tbl(i-1).line_quantity;
5890 					 l_line_rec.list_price := l_line_rec.unit_price * p_req_line_tbl(i-1).line_quantity;
5891                           l_line_rec.qty:= p_req_line_tbl(i-1).line_quantity ;
5892                           l_line_rec.uom_code:= p_req_line_tbl(i-1).line_uom_code;
5893                           --Bug 2389314
5894                           p_service_qty_tbl(p_req_line_tbl(i).line_index) := p_req_line_tbl(i).line_id;
5895 
5896                        End if;
5897 
5898 
5899                         l_line_rec.pricing_date := p_req_line_tbl(i).pricing_effective_date;
5900 
5901                         k:= p_req_line_detail_tbl.first;
5902                         while k is not null loop
5903                            If p_req_line_detail_tbl(k).line_index = p_req_line_tbl(i).line_index
5904                             and p_req_line_detail_tbl(k).list_line_type_code = 'PLL' then
5905                                l_line_rec.pricelist_id := p_req_line_detail_tbl(k).list_header_id;
5906                                l_line_rec.list_line_id := p_req_line_detail_tbl(k).list_line_id;
5907                                Exit;
5908                            ELSIF p_req_line_detail_tbl(k).line_index = p_req_line_tbl(i).line_index
5909                                  and   p_req_line_detail_tbl(k).created_from_list_type_code IN ('PRL','AGR')
5910                                  and  p_req_line_detail_tbl(k).list_line_type_code = 'PBH' then
5911 
5912                                  l_line_rec.pricelist_id := p_req_line_detail_tbl(k).list_header_id;
5913                                  l_line_rec.list_line_id := p_req_line_detail_tbl(k).list_line_id;
5914                                  --Bug 2565815
5915                                  IF p_req_line_detail_tbl(k).created_from_list_type_code = 'PRL' THEN
5916                                     --l_line_rec.list_price := l_line_rec.unit_price;
5917                                     --l_line_rec.unit_price := null;
5918                                     --l_line_rec.negotiated_amt := l_line_rec.negotiated_amt/p_req_line_tbl(i).line_quantity ;
5919 
5920                                      --Bug 2791272:  keep whatever value l_line_rec.unit_price already has for eg.
5921                                      --              qty of service line * unit price of service line
5922                                      --              i.e. we already have a calculated value in l_line_rec.unit_price
5923                                      --              which we want to retain
5924                                     /***
5925                                      commented out for above reason
5926                                     l_line_rec.unit_price := p_req_line_tbl(i).unit_price; --Added for bug fix
5927                                     ***/
5928                                     null;
5929 
5930 
5931                                  --Bug 2565815
5932                                  ELSE
5933                                     l_line_rec.list_price := l_line_rec.unit_price;
5934                                     l_line_rec.unit_price := null;
5935                                     l_line_rec.negotiated_amt := l_line_rec.negotiated_amt/p_req_line_tbl(i).line_quantity ;
5936                                  END IF;
5937 
5938                                  -- Bug 2604686  fixes formatting issue related to fix made for Bug 2565815
5939                                  IF l_line_rec.unit_price IS NOT NULL THEN
5940                                     l_line_rec.unit_price := ROUND(l_line_rec.unit_price,2);
5941                                  END IF;
5942                                  IF l_line_rec.list_price IS NOT NULL THEN
5943                                     l_line_rec.list_price := ROUND(l_line_rec.list_price,2);
5944                                  END IF;
5945                                  IF l_line_rec.negotiated_amt IS NOT NULL THEN
5946                                     l_line_rec.negotiated_amt := ROUND(l_line_rec.negotiated_amt,2);
5947                                  END IF;    --end Bug 2604686
5948 
5949 
5950                                Exit;
5951 
5952                            END IF;
5953                         k:=p_req_line_detail_tbl.next(k);
5954                         End loop;
5955 
5956                     END IF;--#2
5957                        --dbms_output.put_line('a4'||p_req_line_tbl(i).status_code);
5958 
5959                        l_line_rec.ret_code := p_req_line_tbl(i).status_code;
5960 --Assign update record back to price table
5961                        px_cle_price_tbl(p_line_ind) := l_line_rec;
5962 
5963 
5964                  END IF; --#1.1
5965                  i:=  p_req_line_tbl.next(i);
5966           END LOOP; --#1
5967 
5968 
5969 
5970 /* I := px_cle_price_tbl.first;
5971 If i is not null then loop
5972 IF (l_debug = 'Y') THEN
5973    my_debug('id '||i||px_cle_price_tbl(i).id);
5974    my_debug('line_index '||i||px_cle_price_tbl(i).line_index);
5975    my_debug('list price '||i||px_cle_price_tbl(i).list_price);
5976    my_debug('unit price '||i||px_cle_price_tbl(i).unit_price);
5977 END IF;
5978 
5979 --my_debug('TOPEK:pi tbl index'||l_services_tbl(i).srv_item_tbl_index);
5980 exit when i = px_cle_price_tbl.last;
5981 i := px_cle_price_tbl.next(i);
5982 end loop;
5983 end if;*/
5984 
5985           -- If we are trying to reprice the whole contract and even one request line came back with
5986           -- an error, we would rollback for all the lines as header level pricing should succeed
5987           -- either for all lines or none.
5988           If x_return_status <> OKC_API.G_RET_STS_SUCCESS and
5989           (p_control_rec.p_level in ( 'H','QA') OR p_control_rec.p_config_yn <> 'N') then
5990                 l_return_status:= x_return_status;
5991                 -- Though for header pricing we want to rollback even if one line failed
5992                 If l_return_status = G_SOME_LINE_ERRORED then
5993                   l_return_status:= OKC_API.G_RET_STS_ERROR;
5994                 END IF;
5995                 IF p_control_rec.p_level in ( 'H','QA') then
5996                      OKC_API.set_message(p_app_name      => g_app_name,
5997                                      p_msg_name      => 'OKC_STOP_HDR_ADJS');
5998                 END IF;
5999                 Raise l_exception_stop;
6000           End If;
6001 
6002            --process adjustment details
6003 
6004            If p_control_rec.p_calc_flag = 'B'
6005               and p_control_rec.p_config_yn <> 'Y'
6006                   and p_control_rec.p_level <> 'QA'
6007            then
6008                       IF (l_debug = 'Y') THEN
6009                          my_debug('15685 :before process adjustment details Priced lines count'||px_cle_price_tbl.count);
6010                          my_debug('15686 :before process adjustment details l_return status'||l_return_status);
6011                       END IF;
6012 
6013                            PROCESS_ADJUSTMENT_DETAILS(p_api_version    =>  p_api_version,
6014                               p_CHR_ID                     => p_chr_id,
6015                               p_Control_Rec			       => p_control_rec,
6016                               p_req_line_tbl               => p_req_line_tbl,
6017                               p_Req_LINE_DETAIL_tbl        => p_req_line_detail_tbl,
6018                               p_Req_LINE_DETAIL_qual_tbl   => p_req_line_detail_qual_tbl,
6019                               p_Req_LINE_DETAIL_attr_tbl   => p_req_line_detail_attr_tbl,
6020                               p_Req_RELATED_LINE_TBL       => p_req_related_line_tbl,
6021                               p_CLE_PRICE_TBL		    => px_CLE_PRICE_TBL,
6022                               p_service_qty_tbl            => p_service_qty_tbl,
6023                               x_return_status              => l_return_status,
6024                               x_msg_count                  => x_msg_count,
6025                               x_msg_data                   => x_msg_data);
6026                        IF (l_debug = 'Y') THEN
6027                           my_debug('15690 :After process adjustment details return status:- '||l_return_status);
6028                        END IF;
6029                             If l_return_status <> OKC_API.G_RET_STS_SUCCESS then
6030                                raise l_exception_stop;
6031                             End if;
6032            END IF;
6033     IF (l_debug = 'Y') THEN
6034        my_debug('15700 : Exiting PROCESS_ADJUSTMENTS', 2);
6035     END IF;
6036     IF (l_debug = 'Y') THEN
6037        okc_debug.Reset_Indentation;
6038     END IF;
6039 
6040    EXCEPTION
6041       When l_exception_stop then
6042          x_return_status := l_return_status;
6043     IF (l_debug = 'Y') THEN
6044        my_debug('15800 : Exiting PROCESS_ADJUSTMENTS', 4);
6045     END IF;
6046     IF (l_debug = 'Y') THEN
6047        okc_debug.Reset_Indentation;
6048     END IF;
6049 
6050       When others then
6051          --dbms_output.put_line('came here'||sqlcode||substr(sqlerrm,1,235));
6052           OKC_API.set_message(p_app_name      => g_app_name,
6053                                    p_msg_name      => G_UNEXPECTED_ERROR,
6054                                    p_token1        => G_SQLCODE_TOKEN,
6055                                    p_token1_value  => SQLCODE,
6056                                    p_token2        => G_SQLERRM_TOKEN,
6057                                    p_token2_value  => SQLERRM);
6058            x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
6059      IF (l_debug = 'Y') THEN
6060         my_debug('15900 : Exiting PROCESS_ADJUSTMENTS', 4);
6061      END IF;
6062     IF (l_debug = 'Y') THEN
6063        okc_debug.Reset_Indentation;
6064     END IF;
6065 
6066    END PROCESS_ADJUSTMENTS;
6067 
6068    ----------------------------------------------------------------------------
6069 -- CALCULATE_PRICE
6070 -- This procedure will calculate the price for the sent in line/header
6071 -- px_cle_price_tbl returns the priced line ids and thier prices
6072 -- p_level tells whether line level or header level
6073 -- possible value 'L' line ,'H' the whole contract including header,'QA' only QA DEFAULT 'L'
6074 --p_calc_flag   'B'(Both -calculate and search),'C'(Calculate Only), 'S' (Search only)
6075 ----------------------------------------------------------------------------
6076 PROCEDURE CALCULATE_price(
6077           p_api_version                 IN          NUMBER ,
6078           p_init_msg_list               IN          VARCHAR2 ,
6079           p_CHR_ID                      IN          NUMBER,
6080           p_Control_Rec			        IN          OKC_CONTROL_REC_TYPE,
6081           px_req_line_tbl               IN  OUT NOCOPY   QP_PREQ_GRP.LINE_TBL_TYPE,
6082           px_Req_qual_tbl               IN  OUT NOCOPY   QP_PREQ_GRP.QUAL_TBL_TYPE,
6083           px_Req_line_attr_tbl          IN  OUT NOCOPY   QP_PREQ_GRP.LINE_ATTR_TBL_TYPE,
6084           px_Req_LINE_DETAIL_tbl        IN  OUT NOCOPY   QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE,
6085           px_Req_LINE_DETAIL_qual_tbl   IN  OUT NOCOPY   QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE,
6086           px_Req_LINE_DETAIL_attr_tbl   IN  OUT NOCOPY   QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE,
6087           px_Req_RELATED_LINE_TBL       IN  OUT NOCOPY   QP_PREQ_GRP.RELATED_LINES_TBL_TYPE,
6088           px_CLE_PRICE_TBL		        IN  OUT NOCOPY   CLE_PRICE_TBL_TYPE,
6089           x_return_status               OUT  NOCOPY VARCHAR2,
6090           x_msg_count             OUT  NOCOPY NUMBER,
6091           x_msg_data              OUT  NOCOPY VARCHAR2) IS
6092 
6093      l_return_status varchar2(1) := OKC_API.G_RET_STS_SUCCESS;
6094      l_api_name constant VARCHAR2(30) := 'CALCULATE PRICE';
6095      l_hdr_prc_contexts_Tbl    QP_PREQ_GRP.LINE_ATTR_TBL_TYPE;
6096      l_hdr_qual_contexts_Tbl  QP_PREQ_GRP.QUAL_TBL_TYPE;
6097 
6098 
6099      l_line_tbl line_tbl_type;
6100      l_id_tbl num_tbl_type;
6101      l_id1 varchar2(40);
6102      l_id2 varchar2(100);
6103      l_jtot1_code varchar2(30);
6104 
6105      l_bpi_ind pls_integer:=0;
6106      l_pi_ind  pls_integer:=0;
6107 
6108      l_pricing_event varchar2(10) := p_control_rec.qp_control_rec.pricing_event;
6109 
6110 
6111      l_Req_related_lines_tbl         QP_PREQ_GRP.RELATED_LINES_TBL_TYPE:=px_Req_RELATED_LINE_TBL;
6112      l_req_line_tbl                  QP_PREQ_GRP.LINE_TBL_TYPE:=px_req_line_tbl ;
6113      l_pricing_contexts_Tbl          QP_PREQ_GRP.LINE_ATTR_TBL_TYPE := px_Req_line_attr_tbl;
6114      l_qualifiers_contexts_Tbl       QP_PREQ_GRP.QUAL_TBL_TYPE := px_Req_qual_tbl;
6115      l_Req_LINE_DETAIL_tbl           QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE:= px_Req_LINE_DETAIL_tbl;
6116      l_Req_LINE_DETAIL_qual_tbl      QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE:= px_Req_LINE_DETAIL_qual_tbl;
6117      l_Req_LINE_DETAIL_attr_tbl      QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE:= px_Req_LINE_DETAIL_attr_tbl;
6118 
6119      l_prc_Tbl                       QP_PREQ_GRP.LINE_ATTR_TBL_TYPE;
6120      l_qual_Tbl                      QP_PREQ_GRP.QUAL_TBL_TYPE ;
6121 
6122      l_bpi_prc_Tbl                       QP_PREQ_GRP.LINE_ATTR_TBL_TYPE;
6123      l_bpi_qual_Tbl                      QP_PREQ_GRP.QUAL_TBL_TYPE ;
6124 
6125      l_index                        pls_integer;
6126      l_Req_LINE_index                number :=null;
6127      l_control_rec                   QP_PREQ_GRP.CONTROL_RECORD_TYPE:=p_control_rec.qp_control_rec;
6128      l_return_status_text            Varchar2(240);
6129      l_okc_control_rec               OKC_CONTROL_REC_TYPE := p_control_rec;
6130      l_line_index  pls_integer :=0;
6131 
6132      l_curr           varchar2(15);
6133      i pls_integer   :=0;
6134      j pls_integer   :=0;
6135 
6136      l_related_lines_index number :=0;
6137      l_priced_tbl   NUM_TBL_TYPE;
6138      l_price_list   number;
6139      l_check    VARCHAR(2) := 'N';
6140 
6141    FUNCTION load_applied_adjs(i pls_integer)
6142      Return varchar2 is
6143      l_return_status varchar2(1):= OKC_API.G_RET_STS_SUCCESS;
6144      cursor l_cle(p_id number,pchr_id number) is
6145         select *
6146         from okc_price_adjustments a
6147         where
6148            cle_id = p_id and chr_id=pchr_id
6149            and applied_flag='Y'
6150            --do not process child detail lines      -- tope pbh changes
6151 	   and id not in (Select pat_id
6152 		          from okc_price_adj_assocs_v
6153 			  where  cle_id =p_id
6154 			  and pat_id_from is not null
6155 			  and pat_id = a.id);
6156 	    --tope pbh changes
6157 
6158 
6159 
6160      cursor l_chr(p_id number) is
6161         select *
6162         from okc_price_adjustments
6163         where
6164            chr_id = p_id and cle_id is null --???ask sripriya do we just send manual.(what about overrides)
6165            and applied_flag='Y';
6166 
6167 
6168      cursor l_related_lines(p_pat_id number,p_cle_id number) is
6169      select  b.*
6170 	from okc_price_adj_assocs_v a, okc_price_adjustments b
6171 	where a.pat_id_from =p_pat_id
6172 	and a.pat_id = b.id
6173 	and a.cle_id =p_cle_id
6174 	and a.cle_id = b.cle_id;
6175 
6176 
6177      cursor l_attribs(p_id number) is
6178        select flex_title,pricing_context,pricing_attribute,
6179               pricing_attr_value_from, pricing_attr_value_to,comparison_operator
6180        From okc_price_adj_attribs
6181        where pat_id=p_id;
6182        pbh_index number;
6183       l_row l_cle%rowtype;
6184       l_attrib_row l_attribs%rowtype;
6185       j  pls_integer := l_req_line_detail_tbl.count;
6186       k  pls_integer := l_req_line_detail_qual_tbl.count;
6187       l pls_integer := 0;
6188 
6189    Begin
6190        IF (l_debug = 'Y') THEN
6191           okc_debug.Set_Indentation('load_applied_adjs');
6192        END IF;
6193        IF (l_debug = 'Y') THEN
6194           my_debug('16000 : Entering load_applied_adjs', 2);
6195        END IF;
6196 
6197        If l_req_line_tbl(i).line_type_code = 'ORDER' then
6198          Open l_chr(l_req_line_tbl(i).line_id);
6199        Else
6200           open l_cle(l_req_line_tbl(i).line_id,p_chr_id);
6201        End if;
6202        Loop --#1
6203          j:=j+1;
6204          If l_req_line_tbl(i).line_type_code = 'ORDER' then
6205            Fetch l_chr into l_row;
6206            Exit when l_chr%NOTFOUND;
6207            l_req_line_detail_tbl(j).line_detail_type_code := 'ORDER';
6208 
6209          Else
6210             Fetch l_cle into l_row;
6211             Exit when l_cle%notfound;
6212             l_req_line_detail_tbl(j).line_detail_type_code := 'LINE';
6213 
6214          End if;
6215          l_req_line_detail_tbl (j).line_index := l_req_line_tbl(i).line_index;
6216          l_req_line_detail_tbl(j).line_detail_index := j;
6217       --???l_req_line_detail_tbl(j).inventory_item_id :=
6218          l_req_line_detail_tbl (j).list_line_no := l_row.list_line_no;
6219          l_req_line_detail_tbl(j).pricing_phase_id := l_row.pricing_phase_id;
6220          l_req_line_detail_tbl(j).list_header_id := l_row.list_header_id;
6221          l_req_line_detail_tbl(j).list_line_id := l_row.list_line_id;
6222          l_req_line_detail_tbl(j).list_line_type_code := l_row.list_line_type_code;
6223          l_req_line_detail_tbl(j).created_from_list_type_code:= l_row.modifier_mechanism_type_code;
6224          l_req_line_detail_tbl(j).automatic_flag := l_row.automatic_flag;
6225          l_req_line_detail_tbl(j).applied_flag := l_row.applied_flag;
6226          l_req_line_detail_tbl(j).updated_flag := l_row.updated_flag;
6227          l_req_line_detail_tbl(j).operand_calculation_code := l_row.arithmetic_operator;
6228          l_req_line_detail_tbl(j).operand_value := l_row.operand;
6229          l_req_line_detail_tbl(j).modifier_level_code := l_row.modifier_level_code;
6230          l_req_line_detail_tbl(j).override_flag := l_row.UPDATE_ALLOWED ;
6231          l_req_line_detail_tbl(j).line_quantity := l_row.range_break_quantity;
6232 
6233           For l_attrib_row in l_attribs(l_row.pat_id) loop
6234             k:=k+1;
6235             If l_attrib_row.flex_title = 'QP_ATTR_DEFNS_QUALIFIER' then
6236                	l_Req_LINE_DETAIL_qual_tbl(k).line_detail_index := j;
6237             	l_Req_LINE_DETAIL_qual_tbl(k).Qualifier_Context := l_attrib_row.pricing_context;
6238 				l_Req_LINE_DETAIL_qual_tbl(k).Qualifier_Attribute:= l_attrib_row.pricing_attribute;
6239 				l_Req_LINE_DETAIL_qual_tbl(k).Qualifier_Attr_Value_From:= l_attrib_row.pricing_attr_value_from;
6240 			    l_Req_LINE_DETAIL_qual_tbl(k).Qualifier_Attr_Value_To:= l_attrib_row.pricing_attr_value_to;
6241 				l_Req_LINE_DETAIL_qual_tbl(k).comparison_operator_Code:= l_attrib_row.comparison_operator;
6242 
6243             Elsif l_attrib_row.flex_title = 'QP_ATTR_DEFNS_PRICING' then
6244               	l_Req_LINE_DETAIL_attr_tbl(k).line_detail_index := j;
6245                 l_Req_LINE_DETAIL_attr_tbl(k).PRICING_Context := l_attrib_row.pricing_context;
6246 				l_Req_LINE_DETAIL_attr_tbl(k).PRICING_Attribute:= l_attrib_row.pricing_attribute;
6247 				l_Req_LINE_DETAIL_attr_tbl(k).PRICING_Attr_Value_From:= l_attrib_row.pricing_attr_value_from;
6248 			    l_Req_LINE_DETAIL_attr_tbl(k).PRICING_Attr_Value_To:= l_attrib_row.pricing_attr_value_to;
6249 
6250             End if;
6251          End loop; --l_attrib
6252 
6253          IF (l_debug = 'Y') THEN
6254             my_debug ('type_code'|| l_row.list_line_type_code);
6255          END IF;
6256          -- tope pbh changes
6257 	 If l_row.list_line_type_code = 'PBH' Then
6258 		   ---Update the qualifying child line with new operand
6259 		   ---Set updated flag for all child lines to 'Y'
6260 		   ---Remove in phase 3
6261 		   /******************************
6262 		   If l_row.updated_flag = 'Y' and l_row.operand is not null Then
6263 			 For l_related_row in l_related_lines(l_row.id,l_row.cle_id) Loop
6264 			     IF (l_debug = 'Y') THEN
6265    			     my_debug(' adjusted_amount line ' || l_related_row.adjusted_amount);
6266    			     my_debug(' range break line' || l_related_row.range_break_quantity);
6267                        my_debug('adjusted_amount hdr ' || l_row.adjusted_amount);
6268    			     my_debug('range break hdr' || l_row.range_break_quantity);
6269 			     END IF;
6270 
6271                     If (nvl(l_related_row.range_break_quantity,-99) = l_row.range_break_quantity
6272 			        and l_related_row.adjusted_amount is not null )
6273 
6274                     Then
6275 			       Update okc_price_adjustments
6276 				  set applied_flag = 'Y',
6277 				      operand = l_row.operand,
6278 					 updated_flag = 'Y'
6279 				  where id = l_related_row.id;
6280 				Else
6281 				   Update okc_price_adjustments
6282 				   set updated_flag = 'Y'
6283 				   where id = l_related_row.id;
6284 				End If;
6285 			  End loop;
6286 		     End If;
6287 			********************************/
6288 		     ---Remove in pase 3
6289 
6290 
6291                -- populate child lines and relationship lines
6292 
6293                pbh_index := j;
6294 	       l_req_line_detail_tbl(j).price_break_type_code := l_row.price_break_type_code;
6295 	       For l_related_row in l_related_lines(l_row.id,l_row.cle_id) Loop
6296 			    j:= j+1;
6297 			    l_req_line_detail_tbl(j).line_index := l_req_line_tbl(i).line_index;
6298 			    l_req_line_detail_tbl(j).line_detail_index := j;
6299 
6300                             l_req_line_detail_tbl (j).list_line_no := l_related_row.list_line_no;
6301 			    l_req_line_detail_tbl(j).pricing_phase_id := l_related_row.pricing_phase_id;
6302 			    l_req_line_detail_tbl(j).list_header_id := l_related_row.list_header_id;
6303 			    l_req_line_detail_tbl(j).list_line_id := l_related_row.list_line_id;
6304 			    l_req_line_detail_tbl(j).list_line_type_code := l_related_row.list_line_type_code;
6305 			    l_req_line_detail_tbl(j).created_from_list_type_code:= l_related_row.modifier_mechanism_type_code;
6306 			    l_req_line_detail_tbl(j).automatic_flag := l_related_row.automatic_flag;
6307 			    l_req_line_detail_tbl(j).applied_flag := l_related_row.applied_flag;
6308 			    l_req_line_detail_tbl(j).updated_flag := l_related_row.updated_flag;
6309 			    l_req_line_detail_tbl(j).operand_calculation_code := l_related_row.arithmetic_operator;
6310 			    l_req_line_detail_tbl(j).operand_value := l_related_row.operand;
6311 			    l_req_line_detail_tbl(j).modifier_level_code := l_related_row.modifier_level_code;
6312 			    l_req_line_detail_tbl(j).override_flag := l_related_row.UPDATE_ALLOWED ;
6313 			    l_req_line_detail_tbl(j).line_quantity := l_related_row.range_break_quantity;
6314 			    l_req_line_detail_tbl(j).line_detail_type_code := 'CHILD_DETAIL_LINE';
6315 			    l_req_line_detail_tbl(j).price_break_type_code := l_related_row.price_break_type_code;
6316 
6317                             --Populate relationship
6318 			    l := nvl(l_Req_related_lines_tbl.last,0)+1;
6319 			    l_req_related_lines_tbl(l).line_index :=  l_req_line_tbl(i).line_index ;
6320 			    l_req_related_lines_tbl(l).LINE_DETAIL_INDEX := pbh_index;
6321 			    l_req_related_lines_tbl(l).relationship_type_code := 'PBH_LINE';
6322 			    --  l_req_related_lines_tbl(l).RELATED_LINE_INDEX     := ;
6323 			    l_req_related_lines_tbl(l).related_line_detail_index := j;
6324                End loop;
6325 
6326             End If;
6327 	    --Tope pbh changes
6328 
6329 
6330        End loop; --#1
6331        If l_chr%isopen then
6332           close l_chr;
6333        Elsif l_cle%isopen then
6334           close l_cle;
6335        End if;
6336       IF (l_debug = 'Y') THEN
6337          my_debug('16300 : Exiting load_applied_adjs', 2);
6338       END IF;
6339       IF (l_debug = 'Y') THEN
6340          okc_debug.Reset_Indentation;
6341       END IF;
6342 
6343       return l_return_status;
6344     exception
6345       When Others then
6346            OKC_API.set_message(p_app_name      => g_app_name,
6347                        p_msg_name      => g_unexpected_error,
6348                        p_token1        => g_sqlcode_token,
6349                        p_token1_value  => sqlcode,
6350                        p_token2        => g_sqlerrm_token,
6351                        p_token2_value  => sqlerrm);
6352             l_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
6353             If l_chr%isopen then
6354               close l_chr;
6355             Elsif l_cle%isopen then
6356               close l_cle;
6357             End if;
6358       IF (l_debug = 'Y') THEN
6359          my_debug('16400 : Exiting load_applied_adjs', 4);
6360       END IF;
6361       IF (l_debug = 'Y') THEN
6362          okc_debug.Reset_Indentation;
6363       END IF;
6364 
6365             return (l_return_status);
6366 --????what about assocs(pbh)
6367 
6368    End load_applied_adjs;
6369 
6370 Begin
6371 --?????? validations- pricing config lines. p_chr_id is null
6372     IF (l_debug = 'Y') THEN
6373        okc_debug.Set_Indentation('CALCULATE_PRICE');
6374     END IF;
6375     IF (l_debug = 'Y') THEN
6376        my_debug('16500 : Entering CALCULATE_PRICE', 2);
6377     END IF;
6378 
6379            x_return_status := OKC_API.G_RET_STS_SUCCESS;
6380 
6381            l_return_status := OKC_API.START_ACTIVITY(l_api_name,
6382                                               p_init_msg_list,
6383                                               '_PROCESS',
6384                                                x_return_status);
6385            IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
6386                     raise OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
6387            ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
6388                     raise OKC_API.G_EXCEPTION_ERROR;
6389            END IF;
6390 
6391            IF p_control_rec.p_level = 'QA' THEN
6392               g_qa_mode := 'Y';
6393            ELSE
6394               g_qa_mode := 'N';
6395            END IF;
6396 
6397            IF l_okc_control_rec.p_calc_Flag <> 'C' then --calc flag
6398                 -- header context has to be built anyways whether its header or line
6399                 BUILD_CHR_CONTEXT(
6400                     p_api_version             => p_api_version,
6401                     p_init_msg_list           => p_init_msg_list,
6402                     p_request_type_code       => l_okc_control_rec.p_request_type_code,
6403                     p_chr_id                  => p_chr_id,
6404                     p_line_index              => 1,
6405                     x_pricing_contexts_Tbl    => l_hdr_prc_contexts_Tbl,
6406                     x_qualifier_contexts_Tbl  => l_hdr_qual_contexts_Tbl,
6407                     x_return_status           => x_return_status,
6408                     x_msg_count               => x_msg_count,
6409                     x_msg_data                => x_msg_data);
6410                   --dbms_output.put_line('4return status'||x_return_status);
6411 
6412                 IF x_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
6413                  RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
6414                 ELSIF x_return_status = OKC_API.G_RET_STS_ERROR THEN
6415                  RAISE OKC_API.G_EXCEPTION_ERROR;
6416                 END IF;
6417                End If; -- p_calc_flag
6418               -- if not a configurated line
6419                If l_okc_control_rec.p_config_yn = 'N' then
6420                    --if already some priced lines are there in price tbl, move them to the tables
6421                    -- that we will use to send data
6422                     If px_cle_price_tbl.count <> 0 then
6423                          i:= px_cle_price_tbl.first;
6424                          while i is not null LOOP
6425                              l_priced_tbl(i)  := px_cle_price_tbl(i).id;
6426                              i:= px_cle_price_tbl.next(i);
6427                          END LOOP;
6428                          -- if no line was sent in, that means reprice all the lines
6429                          -- of the given conract. fetch them from database
6430                     ELSE
6431                           select id
6432                              BULK COLLECT into l_priced_tbl
6433                              from okc_k_lines_b where dnz_chr_id = p_chr_id
6434                              and price_level_ind ='Y';
6435                            IF (l_debug = 'Y') THEN
6436                               my_debug('16550 : select rowcount'||SQL%ROWCOUNT, 1);
6437                            END IF;
6438 
6439                     END IF;
6440                     If l_priced_tbl.count<1  then
6441                        IF l_okc_control_rec.p_level = 'QA' then
6442                            RAISE l_exception_STOP;
6443                       Else
6444                           OKC_API.set_message(p_app_name      => g_app_name,
6445                                               p_msg_name      => 'OKC_NO_QP_ROW');
6446 
6447                           l_return_status:= OKC_API.G_RET_STS_ERROR;
6448                           RAISE OKC_API.G_EXCEPTION_ERROR;
6449 
6450                       End IF;
6451 
6452                     End if;
6453 
6454                     px_cle_price_tbl.delete;
6455                     i:= l_priced_tbl.first;
6456                     j:=0;
6457                     --?????maybe we can do without initializing  global rec  here for better performance
6458                     OKC_PRICE_PUB.G_CONTRACT_INFO := null;
6459                     While i is not null LOOP -- l_priced_tbl loop
6460                          l_price_list:=null;
6461                          l_prc_Tbl.delete;
6462                          l_qual_Tbl.delete;
6463                          l_bpi_prc_Tbl.delete;
6464                          l_bpi_qual_Tbl.delete;
6465 
6466                          l_req_line_index := null;
6467                          get_line_ids (p_chr_id => p_chr_id,
6468                               p_cle_id         => l_priced_tbl(i) , --- priced line id
6469                               x_return_status  => l_return_status,
6470                               x_line_tbl       => l_line_tbl,
6471                               x_bpi_ind        => l_bpi_ind ,
6472                               x_pi_ind         => l_pi_ind);
6473                          IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
6474                             RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
6475                          ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
6476                             RAISE OKC_API.G_EXCEPTION_ERROR;
6477                          END IF;
6478                          If l_line_tbl.count = 0 then
6479                             IF (l_debug = 'Y') THEN
6480                                my_debug('16555 :Code error should not happen '||l_priced_tbl(i),2);
6481                             END IF;
6482                             OKC_API.set_message(p_app_name      => g_app_name,
6483                                                 p_msg_name      => 'OKC_NO_ROW');
6484                              RAISE OKC_API.G_EXCEPTION_ERROR;
6485                          End If;
6486                           IF (l_debug = 'Y') THEN
6487                              my_debug('16556 :got line ids -count '||l_line_tbl.count,1);
6488                              my_debug('16557 :Id of the Priced line should be '||l_line_tbl(1).id,1);
6489                           END IF;
6490 
6491                          j:=j+1;
6492                          px_cle_price_tbl(j).id :=l_priced_tbl(i);
6493                          -- using index 1 here as Priced line should be the first one
6494                          IF (l_debug = 'Y') THEN
6495                             my_debug('16558 :first id for line tbl'||l_line_tbl(l_line_tbl.first).id,1);
6496                          END IF;
6497 
6498                          l_price_list:=l_line_tbl(l_line_tbl.first).pricelist_id;
6499                          px_cle_price_tbl(j).pricelist_id := l_price_list;
6500                          IF (l_debug = 'Y') THEN
6501                             my_debug('16560 : pricelist for priced line'||l_price_list, 1);
6502                          END IF;
6503 
6504                          px_cle_price_tbl(j).pi_bpi := 'P';
6505                          px_cle_price_tbl(j).uom_code:= l_line_tbl(l_line_tbl.first).uom_code;
6506 
6507                          If l_bpi_ind > 0 then
6508                             j:=j+1;
6509                             px_cle_price_tbl(j).id :=l_line_tbl(l_bpi_ind).id;
6510                             px_cle_price_tbl(j).pi_bpi := 'B';
6511                             --??????pricelist for pi and bpi will be same as per our design
6512                             px_cle_price_tbl(j).pricelist_id := l_price_list;
6513                          END IF;
6514                          IF (l_debug = 'Y') THEN
6515                             my_debug('16562 :  before calling create_request_line'||l_return_status);
6516                          END IF;
6517 			     --Line Below commented for Bug 2403028, Results in ora-01403 when
6518 			     -- user omits item_to_price in line style setup
6519 
6520                     --If l_line_tbl(l_pi_ind).service_yn = 'Y'then
6521 
6522 			          If (l_pi_ind > 0 AND l_line_tbl(l_pi_ind).service_yn = 'Y') Then
6523                           Create_request_line_service(
6524                                              p_api_version             => p_api_version,
6525                                              p_init_msg_list           => p_init_msg_list,
6526                                              p_control_rec               => l_okc_control_rec,
6527                                              p_chr_id                  => p_chr_id,
6528                                              p_line_tbl                => l_line_tbl,
6529                                              p_pi_ind                  => l_pi_ind,
6530                                              p_bpi_ind                 => l_bpi_ind,
6531                                              p_pricing_event           => l_pricing_event,
6532                                              p_hdr_prc_contexts_Tbl    => l_hdr_prc_contexts_Tbl,
6533                                              p_hdr_qual_contexts_Tbl   => l_hdr_qual_contexts_Tbl,
6534                                              px_req_line_tbl           => l_req_line_tbl,
6535                                              px_Req_related_lines_tbl  => l_Req_related_lines_tbl,
6536                                              x_pricing_contexts_Tbl    => l_prc_Tbl,
6537                                              x_qualifier_contexts_Tbl  => l_qual_Tbl,
6538                                              x_return_status           => l_return_status,
6539                                              x_msg_count               => x_msg_count,
6540                                              x_msg_data                => x_msg_data);
6541                           --bug 2543687
6542 					 l_check := 'NS';
6543 
6544                           IF (l_debug = 'Y') THEN
6545                              my_debug('16563 : after  calling create_request_line_service'||l_return_status);
6546                           END IF;
6547                         Else
6548                          Create_request_line(
6549                                              p_api_version             => p_api_version,
6550                                              p_init_msg_list           => p_init_msg_list,
6551                                              p_control_rec               => l_okc_control_rec,
6552                                              p_chr_id                  => p_chr_id,
6553                                              p_line_tbl                => l_line_tbl,
6554                                              p_pi_ind                  => l_pi_ind,
6555                                              p_bpi_ind                 => l_bpi_ind,
6556                                              p_pricing_event           => l_pricing_event,
6557                                              p_hdr_prc_contexts_Tbl    => l_hdr_prc_contexts_Tbl,
6558                                              p_hdr_qual_contexts_Tbl   => l_hdr_qual_contexts_Tbl,
6559                                              px_req_line_tbl           => l_req_line_tbl,
6560                                              px_Req_related_lines_tbl  => l_Req_related_lines_tbl,
6561                                              x_pricing_contexts_Tbl    => l_prc_Tbl,
6562                                              x_qualifier_contexts_Tbl  => l_qual_Tbl,
6563                                              x_return_status           => l_return_status,
6564                                              x_msg_count               => x_msg_count,
6565                                              x_msg_data                => x_msg_data);
6566                          IF (l_debug = 'Y') THEN
6567                             my_debug('16563 : after  calling create_request_line'||l_return_status);
6568                          END IF;
6569                         End If;
6570                         IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
6571                                    RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
6572                         ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
6573                                   RAISE OKC_API.G_EXCEPTION_ERROR;
6574                         END IF;
6575                         l_req_line_index := nvl(l_req_line_tbl.last,0);
6576                         If l_bpi_ind > 0 then
6577                             --loop and take out all the pricing attributes belonging to bpi
6578                             -- and put them in separate table
6579                             l_index := l_prc_Tbl.first;
6580                             while l_index is not null loop
6581                                If l_prc_Tbl(l_index).line_index = 2 then
6582                                   l_bpi_prc_tbl(l_index):= l_prc_Tbl(l_index);
6583                                   l_prc_Tbl.delete(l_index);
6584                                End If;
6585                                l_index:=l_prc_Tbl.next(l_index);
6586                             END LOOP;
6587                               --loop and take out all the qualifier attributes belonging to bpi
6588                             -- and put them in separate table
6589                             l_index := l_qual_Tbl.first;
6590                             while l_index is not null loop
6591                                If l_qual_Tbl(l_index).line_index = 2 then
6592                                   l_bpi_qual_tbl(l_index):= l_qual_Tbl(l_index);
6593                                   l_qual_Tbl.delete(l_index);
6594                                End If;
6595                                l_index:=l_qual_Tbl.next(l_index);
6596                             END LOOP;
6597                             IF  l_okc_control_rec.p_calc_Flag <> 'C' and l_req_line_index is not null then
6598                                  copy_attribs(
6599                                       l_req_line_index
6600                                      ,'N'
6601                                      ,l_bpi_prc_Tbl
6602                                      ,l_bpi_qual_Tbl
6603                                      ,l_pricing_contexts_tbl
6604                                      ,l_qualifiers_contexts_tbl);
6605                            End If;
6606                             -- since in case of bpi, first normal line is attached and then
6607                             -- bpi line is attached line_index for normal line would be
6608                             -- l_req_line_tbl.last-1
6609                             l_req_line_index := l_req_line_index -1;
6610 
6611                         End If;-- l_bpi_ind>0
6612 
6613                         IF (l_debug = 'Y') THEN
6614                            my_debug('16570 : request line index'||l_req_line_index);
6615                         END IF;
6616 
6617                         IF  l_okc_control_rec.p_calc_Flag <> 'C' and l_req_line_index is not null then
6618                            copy_attribs(
6619                                       l_req_line_index
6620                                      ,l_check
6621                                      ,l_prc_Tbl
6622                                      ,l_qual_Tbl
6623                                      ,l_pricing_contexts_tbl
6624                                      ,l_qualifiers_contexts_tbl);
6625                         End If;
6626 
6627                            i:=l_priced_tbl.next(i);
6628                     END LOOP; -- l_priced_tbl loop
6629            Elsif  l_okc_control_rec.p_config_yn in ('Y','S') then  --p_config_flag
6630            OKC_PRICE_PUB.G_CONTRACT_INFO:= null;
6631                 If l_okc_control_rec.p_top_model_id is null then
6632                       OKC_API.set_message(p_app_name      => g_app_name,
6633                                    p_msg_name      => 'OKC_INVALID_TOP_MODEL');
6634                        RAISE OKC_API.G_EXCEPTION_ERROR;
6635                 End if;
6636                 If px_cle_price_tbl.count<1  then
6637                       OKC_API.set_message(p_app_name      => g_app_name,
6638                                    p_msg_name      => 'OKC_NO_QP_ROW');
6639                        RAISE OKC_API.G_EXCEPTION_ERROR;
6640                 End if;
6641                 Set_control_rec(l_okc_control_rec);
6642                 l_control_rec := l_okc_control_rec.qp_control_rec;
6643                 l_line_tbl.delete;
6644 
6645                   --collect all the line styles and rules and party roles attached to lines above configurated lines
6646                   select id
6647                   BULK COLLECT INTO l_id_tbl
6648                   from okc_k_lines_b
6649                   connect by prior cle_id = id
6650                   start with id=l_okc_control_rec.p_top_model_id;
6651                   --dbms_output.put_line('rows found'||l_id_tbl.count);
6652                   IF (l_debug = 'Y') THEN
6653                      my_debug('16650 : select rowcount'||SQL%ROWCOUNT, 1);
6654                   END IF;
6655 
6656                   i:= l_id_tbl.first;
6657                   while i is not null LOOP --#2config
6658                                     --dbms_output.put_line('san while'||l_id_tbl(i));
6659 
6660                     BEGIN
6661                       SELECT object1_id1, object1_id2, jtot_object1_code
6662                       into l_id1,l_id2,l_jtot1_code
6663                       FROM okc_k_items
6664                       where cle_id = l_id_tbl(i) and dnz_chr_id=p_chr_id;
6665                                                           --dbms_output.put_line('while again'||l_id_tbl(i));
6666                        IF (l_debug = 'Y') THEN
6667                           my_debug('16700 : select rowcount'||SQL%ROWCOUNT, 1);
6668                        END IF;
6669 
6670                       l_line_tbl(i).id:= l_id_tbl(i);
6671                       l_line_tbl(i).object_code:=l_jtot1_code ;
6672                       l_line_tbl(i).id1:=l_id1;
6673                       l_line_tbl(i).id2:=l_id2;
6674                       -- populate global top model intevnetory item id with this value
6675                       IF l_id_tbl(i) = l_okc_control_rec.p_top_model_id then
6676                          OKC_PRICE_PUB.G_CONTRACT_INFO.top_model_line_id:= l_id1;
6677                       END IF;
6678                       i:=l_id_tbl.next(i);
6679                     EXCEPTION
6680                       WHEN NO_DATA_FOUND then
6681                                                           --dbms_output.put_line('no data');
6682 
6683                          l_line_tbl(i).id:= l_id_tbl(i);
6684                     END;
6685                   End Loop; --#2config
6686                                                       --dbms_output.put_line('out of loop');
6687 
6688                   i:=px_cle_price_tbl.first;
6689 
6690                   while i is not null loop--#3config
6691 
6692                   --??????? an issue here that build_context has to be called now for each line as the
6693                   --following values will differ.
6694                   OKC_PRICE_PUB.G_CONTRACT_INFO.inventory_item_id := px_cle_price_tbl(i).id1;
6695                   /*-- here the assumption is that out of the pl/sql tbl sent by configurtor cal
6696                   -- the first record is the one with the top model line. hence
6697                   -- picking its inventory_item_id
6698                   If i = px_cle_price_tbl.first then
6699                    OKC_PRICE_PUB.G_CONTRACT_INFO.top_model_line_id:= px_cle_price_tbl(i).id1;
6700                   end if;*/
6701                    BUILD_CLE_CONTEXT(
6702                         p_api_version             => p_api_version,
6703                         p_init_msg_list           => p_init_msg_list,
6704                         p_request_type_code       => l_okc_control_rec.p_Request_Type_Code,
6705                         p_chr_id                  => p_chr_id,
6706                         P_line_tbl                => l_line_tbl,
6707                         p_line_index              => i,
6708                         x_pricing_contexts_Tbl    => l_prc_Tbl,
6709                         x_qualifier_contexts_Tbl  => l_qual_Tbl,
6710                         x_return_status           => l_return_status,
6711                         x_msg_count               => x_msg_count,
6712                         x_msg_data                => x_msg_data);
6713                       IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
6714                            RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
6715                       ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
6716                            RAISE OKC_API.G_EXCEPTION_ERROR;
6717                       END IF;
6718                       --dbms_output.put_line('config 1');
6719 
6720                       --attach header attribs
6721                        If (l_hdr_prc_contexts_Tbl.count >0 or l_hdr_qual_contexts_Tbl.count>0) then
6722                         copy_attribs(
6723                              i
6724                             ,'Y'
6725                             ,l_hdr_prc_contexts_Tbl
6726                             ,l_hdr_qual_contexts_Tbl
6727                             ,l_prc_Tbl
6728                             ,l_qual_Tbl);
6729                       END IF;
6730                     -- build context done
6731 
6732                       l_pricing_contexts_Tbl(i).line_index := i;
6733                       l_pricing_contexts_Tbl(i).PRICING_CONTEXT :='ITEM';
6734                       l_pricing_contexts_Tbl(i).PRICING_ATTRIBUTE :='PRICING_ATTRIBUTE1';
6735                       l_pricing_contexts_Tbl(i).PRICING_ATTR_VALUE_FROM  := px_cle_price_tbl(i).id1; -- Inventory Item Id
6736                       l_pricing_contexts_Tbl(i).VALIDATED_FLAG :='N';
6737 
6738                       IF   px_cle_price_tbl(i).pricelist_id is not null
6739                            and  px_cle_price_tbl(i).pricelist_id <> OKC_API.G_MISS_NUM then
6740                             l_qualifiers_contexts_Tbl(i).LINE_INDEX := i;
6741                             l_qualifiers_contexts_Tbl(i).QUALIFIER_CONTEXT :='MODLIST';
6742                             l_qualifiers_contexts_Tbl(i).QUALIFIER_ATTRIBUTE :='QUALIFIER_ATTRIBUTE4';
6743                             l_qualifiers_contexts_Tbl(i).QUALIFIER_ATTR_VALUE_FROM := to_char(px_cle_price_tbl(i).pricelist_id); -- Price List Id
6744                             l_qualifiers_contexts_Tbl(i).COMPARISON_OPERATOR_CODE := '=';
6745                             --l_qualifiers_contexts_Tbl(i).VALIDATED_FLAG :='Y';
6746                             l_qualifiers_contexts_Tbl(i).VALIDATED_FLAG :='N'; --Bug 2760904: we need QP to validate the price list
6747                       Else
6748                          px_cle_price_tbl(i).pricelist_id:=g_hdr_pricelist;
6749                       END IF;
6750 
6751                    	   l_req_line_tbl(i).Line_id := px_cle_price_tbl(i).id;
6752 	                   l_req_line_tbl(i).REQUEST_TYPE_CODE := l_okc_control_rec.p_Request_Type_Code;
6753 	                   l_req_line_tbl(i).LINE_INDEX     := i;
6754 	                   l_req_line_tbl(i).LINE_TYPE_CODE  := 'LINE';
6755                 --       l_req_line_tbl(i).PRICING_EFFECTIVE_DATE := trunc(sysdate);--???? is sysdate fine?
6756                        l_req_line_tbl(i).PRICING_EFFECTIVE_DATE := nvl(px_cle_price_tbl(i).pricing_date,g_hdr_pricing_date);
6757 			  l_req_line_tbl(i).LINE_QUANTITY   := px_cle_price_tbl(i).qty ;
6758                        l_req_line_tbl(i).LINE_UOM_CODE   := px_cle_price_tbl(i).uom_code;
6759 	                   l_req_line_tbl(i).CURRENCY_CODE   := px_cle_price_tbl(i).currency;
6760                        l_req_line_tbl(i).PRICE_FLAG := 'Y';
6761                        If (l_prc_Tbl.count >0 or l_qual_Tbl.count>0) then
6762                         copy_attribs(
6763                              i
6764                             ,'N'
6765                             ,l_prc_Tbl
6766                             ,l_qual_Tbl
6767                             ,l_pricing_contexts_Tbl
6768                             ,l_qualifiers_contexts_Tbl);
6769                       END IF;
6770                       --dbms_output.put_line('config 3');
6771 
6772                     i:=px_cle_price_tbl.next(i);
6773                   End loop;--#3config
6774 
6775            Else   --p_config_flag
6776                 --dbms_output.put_line('code error: config flag should be Y or N');
6777                 null;
6778            End If;--p_config_yn
6779             -- create header request line everytime irrespective of p_level
6780            Begin
6781                 select currency_code
6782                 into l_curr
6783                 from okc_k_headers_b
6784                 where id = p_chr_id;
6785                 IF (l_debug = 'Y') THEN
6786                    my_debug('16750 : select rowcount'||SQL%ROWCOUNT, 1);
6787                 END IF;
6788 
6789                 EXCEPTION
6790                       WHEN NO_DATA_FOUND then
6791                        l_curr:='USD';
6792            END;
6793 
6794           l_line_index := l_req_line_tbl.count+1;
6795           l_req_line_tbl(l_line_index).REQUEST_TYPE_CODE :=l_okc_control_rec.p_request_type_code;
6796           l_req_line_tbl(l_line_index).PRICING_EVENT :=l_pricing_event;
6797           l_req_line_tbl(l_line_index).LINE_INDEX := l_line_index;
6798           l_req_line_tbl(l_line_index).LINE_TYPE_CODE := 'ORDER';
6799 
6800           -- Hold the header_id in line_id for 'HEADER' Records
6801 
6802           l_req_line_tbl(l_line_index).line_id := p_chr_id;
6803           --l_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE := trunc(sysdate);
6804           l_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE := g_hdr_pricing_date;
6805           l_req_line_tbl(l_line_index).CURRENCY_CODE := l_curr;
6806           -- Ask for pricing the Header only if we are pricing the whole contract or
6807           -- QA
6808           If l_okc_control_rec.p_level in ('H','QA')  then
6809 	              l_req_line_tbl(l_line_index).PRICE_FLAG := 'Y';
6810           ELSE
6811           	      l_req_line_tbl(l_line_index).PRICE_FLAG := 'N';
6812 
6813           END IF;
6814           IF  l_okc_control_rec.p_calc_Flag <> 'C' then
6815 
6816            --attach header context
6817              copy_attribs(
6818                l_req_line_tbl.count
6819               ,'N'
6820               ,l_hdr_prc_contexts_Tbl
6821               ,l_hdr_qual_contexts_Tbl
6822               ,l_pricing_contexts_tbl
6823               ,l_qualifiers_contexts_tbl);
6824            End If;
6825            -- load the applied adjustments for the all the request lines
6826           i:= l_req_line_tbl.first;
6827           while i is not null loop
6828                l_return_status :=load_applied_adjs(i);
6829                IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
6830                  RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
6831                ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
6832                   RAISE OKC_API.G_EXCEPTION_ERROR;
6833                END IF;
6834 
6835              i:=l_req_line_tbl.next(i);
6836           End loop;
6837 
6838                 --assuming pi line with bpi is last and in case of header, header line is last
6839                 --??? assuming they come back in the same order as they were sent
6840           BEGIN
6841 --dbmsoutput area
6842 
6843                IF (l_debug = 'Y') THEN
6844                   my_debug('16800:+---------Information Returned to Caller before price request---------------------+ ');
6845                END IF;
6846 
6847                IF (l_debug = 'Y') THEN
6848                   my_debug('16802:-------------Request Line Information Sent IN------------------');
6849                END IF;
6850                I := l_req_line_tbl.FIRST;
6851 IF I IS NOT NULL THEN
6852  LOOP
6853  	      IF (l_debug = 'Y') THEN
6854     	      my_debug('16803:.Line Id: '||l_req_line_tbl(I).line_id);
6855    	      my_debug('16804:.REQUEST_TYPE_CODE: '||l_req_line_tbl(I).REQUEST_TYPE_CODE);
6856    	      my_debug('16806:.LINE_TYPE_CODE: '||l_req_line_tbl(I).LINE_TYPE_CODE);
6857              my_debug('16808:.PRICING_EFFECTIVE_DATE: '||l_req_line_tbl(I).PRICING_EFFECTIVE_DATE );
6858    	      my_debug('16810:.LINE_QUANTITY: '||l_req_line_tbl(I).LINE_QUANTITY);
6859  	      END IF;
6860 
6861           IF (l_debug = 'Y') THEN
6862              my_debug('16812:.LINE_UOM_CODE: '||l_req_line_tbl(I).LINE_UOM_CODE);
6863    	      my_debug('16814:.CURRENCY_CODE: '||l_req_line_tbl(I).CURRENCY_CODE);
6864              my_debug('16816:.PRICE_FLAG: '||l_req_line_tbl(I).PRICE_FLAG);
6865           END IF;
6866 
6867           IF (l_debug = 'Y') THEN
6868              my_debug('16818:Line Index: '||l_req_line_tbl(I).line_index);
6869              my_debug('16820:Unit_price: '||l_req_line_tbl(I).unit_price);
6870              my_debug('16822:Percent price: '||l_req_line_tbl(I).percent_price);
6871              my_debug('16824:Adjusted Unit Price: '||l_req_line_tbl(I).adjusted_unit_price);
6872              my_debug('16826:UPDATED_ADJUSTED_UNIT_PRICE: '||l_req_line_tbl(I).UPDATED_ADJUSTED_UNIT_PRICE);
6873              my_debug('16828:Pricing status code: '||l_req_line_tbl(I).status_code);
6874              my_debug('16830:Pricing status text: '||l_req_line_tbl(I).status_text);
6875              my_debug('16832:phase san'||l_req_line_tbl(I).pricing_phase_id);
6876           END IF;
6877 
6878   EXIT WHEN I = l_req_line_tbl.LAST;
6879   I := l_req_line_tbl.NEXT(I);
6880  END LOOP;
6881 END IF;
6882 
6883 I := l_req_line_detail_tbl.FIRST;
6884 
6885 IF (l_debug = 'Y') THEN
6886    my_debug('16834:------------Price List/Discount Information Sent In------------');
6887 END IF;
6888 
6889 IF I IS NOT NULL THEN
6890  LOOP
6891    IF (l_debug = 'Y') THEN
6892       my_debug('16834:I: '||I);
6893      my_debug('16836:Line Index: '||l_req_line_detail_tbl(I).line_index);
6894      my_debug('16838:Line Detail Index: '||l_req_line_detail_tbl(I).line_detail_index);
6895      my_debug('16840:Line Detail Type:'||l_req_line_detail_tbl(I).line_detail_type_code);
6896      my_debug('16840:Modifier level Code:'||l_req_line_detail_tbl(I).modifier_level_code);
6897      my_debug('16842:List Header Id: '||l_req_line_detail_tbl(I).list_header_id);
6898      my_debug('16844:List Line Id: '||l_req_line_detail_tbl(I).list_line_id);
6899      my_debug('16845:List Line Number: '||l_req_line_detail_tbl(I).list_line_no);
6900      my_debug('16846:List Line Type Code: '||l_req_line_detail_tbl(I).list_line_type_code);
6901      my_debug('16848:created from Type Code: '||l_req_line_detail_tbl(I).created_from_list_type_code);
6902      my_debug('16850:Adjustment Amount : '||l_req_line_detail_tbl(I).adjustment_amount);
6903      my_debug('16852:Line Quantity : '||l_req_line_detail_tbl(I).line_quantity);
6904      my_debug('16854:Operand Calculation Code: '||l_req_line_detail_tbl(I).Operand_calculation_code);
6905      my_debug('16856:Operand value: '||l_req_line_detail_tbl(I).operand_value);
6906      my_debug('16858:Automatic Flag: '||l_req_line_detail_tbl(I).automatic_flag);
6907      my_debug('16860:Override Flag: '||l_req_line_detail_tbl(I).override_flag);
6908      my_debug('16862:Applied flag: '||l_req_line_detail_tbl(I).applied_flag);
6909      my_debug('16864:Updated Flag: '||l_req_line_detail_tbl(I).UPDATED_FLAG);
6910      my_debug('16866:status_code: '||l_req_line_detail_tbl(I).status_code);
6911      my_debug('16868:status text: '||l_req_line_detail_tbl(I).status_text);
6912      my_debug('16870:-------------------------------------------');
6913    END IF;
6914   EXIT WHEN I =  l_req_line_detail_tbl.LAST;
6915   I := l_req_line_detail_tbl.NEXT(I);
6916  END LOOP;
6917 END IF;
6918  IF (l_debug = 'Y') THEN
6919     my_debug('16872:--------------Pricng Context Information Sent In --------------');
6920  END IF;
6921 
6922 IF (l_debug = 'Y') THEN
6923    my_debug('16874:starting PA '||l_pricing_contexts_tbl.count);
6924 END IF;
6925 If l_pricing_contexts_tbl.count >0 then
6926       i:=l_pricing_contexts_tbl.first;
6927       loop
6928           IF (l_debug = 'Y') THEN
6929              my_debug('16876:index '||l_pricing_contexts_tbl(i).line_index);
6930              my_debug('16878:context '||l_pricing_contexts_tbl(i).pricing_context);
6931              my_debug('16880:attribute'||l_pricing_contexts_tbl(i).pricing_attribute);
6932              my_debug('16882:pricing_attr_value_from '||l_pricing_contexts_tbl(i).pricing_attr_value_from);
6933              my_debug('16884:validated '||l_pricing_contexts_tbl(i).validated_flag);
6934              my_debug('16886:status code '||l_pricing_contexts_tbl(i).status_code);
6935              my_debug('16888:status text '||l_pricing_contexts_tbl(i).status_text);
6936           END IF;
6937           exit when i=l_pricing_contexts_tbl.last;
6938           i:= l_pricing_contexts_tbl.next(i);
6939       end loop;
6940 end if;
6941  IF (l_debug = 'Y') THEN
6942     my_debug('16890:--------------Qual Context Information Sent In --------------');
6943    my_debug('16892:starting  QA'||l_qualifiers_contexts_tbl.count);
6944  END IF;
6945 If l_qualifiers_contexts_tbl.count >0 then
6946       i:=l_qualifiers_contexts_tbl.first;
6947       loop
6948          IF (l_debug = 'Y') THEN
6949             my_debug('16894:index '||l_qualifiers_contexts_tbl(i).line_index);
6950              my_debug('16896:starting SAN QA '||i||'-'||l_qualifiers_contexts_tbl(i).qualifier_context);
6951              my_debug('16900:starting SAN QA '||i||'-'||l_qualifiers_contexts_tbl(i).qualifier_attribute);
6952              my_debug('16902:starting SAN QA '||i||'-'||l_qualifiers_contexts_tbl(i).qualifier_attr_value_from);
6953              my_debug('16904:validated '||l_qualifiers_contexts_tbl(i).validated_flag);
6954              my_debug('16906:status code '||l_qualifiers_contexts_tbl(i).status_code);
6955              my_debug('16908:status text '||l_qualifiers_contexts_tbl(i).status_text);
6956          END IF;
6957 
6958           exit when i=l_qualifiers_contexts_tbl.last;
6959           i:= l_qualifiers_contexts_tbl.next(i);
6960       end loop;
6961 end if;
6962 
6963 IF (l_debug = 'Y') THEN
6964    my_debug('16910:--------------Related Lines Information Sent In for Price Breaks/Service Items---------------');
6965 END IF;
6966 I := l_req_related_lines_tbl.FIRST;
6967 IF I IS NOT NULL THEN
6968  LOOP
6969   IF (l_debug = 'Y') THEN
6970      my_debug('16912:Line Index :'||l_req_related_lines_tbl(I).line_index);
6971      my_debug('16914:Line Detail Index: '||l_req_related_lines_tbl(I).LINE_DETAIL_INDEX);
6972      my_debug('16916:Relationship Type Code: '||l_req_related_lines_tbl(I).relationship_type_code);
6973      my_debug('16918:Related Line Index: '||l_req_related_lines_tbl(I).RELATED_LINE_INDEX);
6974      my_debug('16920:Related Line Detail Index: '||l_req_related_lines_tbl(I).related_line_detail_index);
6975      my_debug('16922:Status Code: '|| l_req_related_lines_tbl(I).STATUS_CODE);
6976   END IF;
6977   EXIT WHEN I =  l_req_related_lines_tbl.LAST;
6978   I :=  l_req_related_lines_tbl.NEXT(I);
6979  END LOOP;
6980 END IF;
6981 -- dbmsoutput area*/
6982              IF (l_debug = 'Y') THEN
6983                 my_debug('16924:Before Calling Price Request calculate flag'||l_control_rec.calculate_flag);
6984              END IF;
6985              QP_PREQ_PUB.PRICE_REQUEST
6986              --QP_PREQ_GRP.PRICE_REQUEST
6987 		           (p_control_rec	 	    => l_control_rec
6988 		           ,p_line_tbl              => l_Req_line_tbl
6989  		           ,p_qual_tbl              => l_qualifiers_contexts_tbl
6990   		           ,p_line_attr_tbl         => l_pricing_contexts_tbl
6991 		           ,p_line_detail_tbl       => l_req_line_detail_tbl
6992 	 	           ,p_line_detail_qual_tbl  => l_req_line_detail_qual_tbl
6993 	  	           ,p_line_detail_attr_tbl  => l_req_line_detail_attr_tbl
6994 	   	           ,p_related_lines_tbl     => l_req_related_lines_tbl
6995 		           ,x_line_tbl              => px_req_line_tbl
6996 	   	           ,x_line_qual             => px_Req_qual_tbl
6997 	    	       ,x_line_attr_tbl         => px_Req_line_attr_tbl
6998 		           ,x_line_detail_tbl       => px_req_line_detail_tbl
6999 	 	           ,x_line_detail_qual_tbl  => px_req_line_detail_qual_tbl
7000  	  	           ,x_line_detail_attr_tbl  => px_req_line_detail_attr_tbl
7001 	   	           ,x_related_lines_tbl     => px_req_related_line_tbl
7002 	    	       ,x_return_status         => l_return_status
7003 	    	       ,x_return_status_Text    => l_return_status_Text
7004 		           );
7005                 IF (l_debug = 'Y') THEN
7006                    my_debug('16925:After Calling Price Request. Return status'||l_return_status);
7007                 END IF;
7008 
7009                  IF l_return_status <> OKC_API.G_RET_STS_SUCCESS THEN
7010                    RAISE l_exception_stop;
7011                  END IF;
7012 
7013                  Exception
7014                   WHEN l_exception_stop THEN
7015                    OKC_API.set_message(p_app_name      => g_app_name,
7016                                    p_msg_name      => 'OKC_QP_PRICE_ERROR',
7017                                    p_token1        => 'Proc',
7018                                    p_token1_value  => 'Price Request',
7019                                    p_token2        => 'err_text',
7020                                    p_token2_value  => l_return_status_text);
7021                    If l_return_status = OKC_API.G_RET_STS_ERROR then
7022                      Raise OKC_API.G_EXCEPTION_ERROR;
7023                    ELSE
7024                      RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
7025                    END IF;
7026 
7027                   when others then
7028                     IF (l_debug = 'Y') THEN
7029                        my_debug('16926:error'||substr(sqlerrm,1,240));
7030                     END IF;
7031                     OKC_API.set_message(p_app_name      => g_app_name,
7032                                    p_msg_name      => 'OKC_QP_INT_ERROR',
7033                                    p_token1        => 'Proc',
7034                                    p_token1_value  => 'Price Request',
7035                                    p_token2        => 'SQLCODE',
7036                                    p_token2_value  => SQLCODE,
7037                                    p_token3        => 'SQLERRM',
7038                                    p_token3_value  => SQLERRM);
7039                     RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
7040 
7041             END;
7042              --dbmsoutput area
7043               IF (l_debug = 'Y') THEN
7044                  my_debug('16928:lines sent in'||l_req_line_tbl.count);
7045               END IF;
7046 
7047               IF (l_debug = 'Y') THEN
7048                  my_debug('16930:-------------Request Line Information Sent out------------------'||px_req_line_tbl.count);
7049               END IF;
7050 
7051 I := px_req_line_tbl.FIRST;
7052 IF I IS NOT NULL THEN
7053  LOOP
7054   IF (l_debug = 'Y') THEN
7055      my_debug('16931:Line id: '||px_req_line_tbl(I).line_id);
7056      my_debug('16932:Line Index: '||px_req_line_tbl(I).line_index);
7057      my_debug('16934:Unit_price: '||px_req_line_tbl(I).unit_price);
7058      my_debug('16936:list type code: '||px_req_line_tbl(I).line_type_code);
7059      my_debug('16938:Percent price: '||px_req_line_tbl(I).percent_price);
7060      my_debug('16940:Adjusted Unit Price: '||px_req_line_tbl(I).adjusted_unit_price);
7061      my_debug('16942:UPDATED_ADJUSTED_UNIT_PRICE: '||px_req_line_tbl(I).UPDATED_ADJUSTED_UNIT_PRICE);
7062      my_debug('16944:Pricing status code: '||px_req_line_tbl(I).status_code);
7063      my_debug('16946:Pricing status text: '||px_req_line_tbl(I).status_text);
7064      my_debug('16948:phase san'||px_req_line_tbl(I).pricing_phase_id);
7065      my_debug('16950:PROCESS CODE: '||px_req_line_tbl(I).PROCESSED_CODE);
7066      my_debug('16952:Line Qty: '||px_req_line_tbl(I).line_quantity);
7067      my_debug('16954:Line UOM Code: '||px_req_line_tbl(I).line_uom_code);
7068      my_debug('16956:Priced Qty: '||px_req_line_tbl(I).priced_quantity);
7069      my_debug('16958:priced UOM Code: '||px_req_line_tbl(I).priced_uom_code);
7070      my_debug('16959:Pricing_date : '||px_req_line_tbl(I).pricing_effective_date);
7071   END IF;
7072 
7073   EXIT WHEN I = px_req_line_tbl.LAST;
7074   I := px_req_line_tbl.NEXT(I);
7075  END LOOP;
7076 END IF;
7077   IF (l_debug = 'Y') THEN
7078      my_debug('16960:--------------Pricng Context  --------------');
7079   END IF;
7080 
7081 IF (l_debug = 'Y') THEN
7082    my_debug('16962:starting  '||px_Req_line_attr_tbl.count);
7083 END IF;
7084 If px_Req_line_attr_tbl.count >0 then
7085       i:=px_Req_line_attr_tbl.first;
7086       loop
7087           IF (l_debug = 'Y') THEN
7088              my_debug('16964:index '||px_Req_line_attr_tbl(i).line_index);
7089              my_debug('16966:context '||px_Req_line_attr_tbl(i).pricing_context);
7090              my_debug('16968:attribute'||px_Req_line_attr_tbl(i).pricing_attribute);
7091              my_debug('16970:pricing_attr_value_from '||px_Req_line_attr_tbl(i).pricing_attr_value_from);
7092              my_debug('16972:validated '||px_Req_line_attr_tbl(i).validated_flag);
7093              my_debug('16974:status code '||px_Req_line_attr_tbl(i).status_code);
7094              my_debug('16976:status text '||px_Req_line_attr_tbl(i).status_text);
7095           END IF;
7096 
7097           exit when i=px_Req_line_attr_tbl.last;
7098           i:= px_Req_line_attr_tbl.next(i);
7099       end loop;
7100 end if;
7101  IF (l_debug = 'Y') THEN
7102     my_debug('16978:--------------Qual Context Information--------------');
7103    my_debug('16980:starting  QA'||px_Req_qual_tbl.count);
7104  END IF;
7105 If px_Req_qual_tbl.count >0 then
7106       i:=px_Req_qual_tbl.first;
7107       loop
7108           IF (l_debug = 'Y') THEN
7109              my_debug('16982:index '||px_Req_qual_tbl(i).line_index);
7110              my_debug('16984:context '||i||'-'||px_Req_qual_tbl(i).qualifier_context);
7111              my_debug('16986:attrib '||i||'-'||px_Req_qual_tbl(i).qualifier_attribute);
7112              my_debug('16988:from'||i||'-'||px_Req_qual_tbl(i).qualifier_attr_value_from);
7113              my_debug('16990:validated '||px_Req_qual_tbl(i).validated_flag);
7114              my_debug('16992:status code '||px_Req_qual_tbl(i).status_code);
7115              my_debug('16994:status text '||px_Req_qual_tbl(i).status_text);
7116           END IF;
7117 
7118           exit when i=px_Req_qual_tbl.last;
7119           i:= px_Req_qual_tbl.next(i);
7120       end loop;
7121 end if;
7122 IF (l_debug = 'Y') THEN
7123    my_debug('16996:-----------Pricing Attributes Information-------------');
7124    my_debug('16997:starting  PA'||px_req_line_detail_attr_tbl.count);
7125 END IF;
7126 I := px_req_line_detail_attr_tbl.FIRST;
7127 IF I IS NOT NULL THEN
7128  LOOP
7129 
7130   IF (l_debug = 'Y') THEN
7131      my_debug('16998:Line detail Index '||px_req_line_detail_attr_tbl(I).line_detail_index);
7132      my_debug('16999:Context '||px_req_line_detail_attr_tbl(I).pricing_context);
7133      my_debug('17000:Attribute '||px_req_line_detail_attr_tbl(I).pricing_attribute);
7134      my_debug('17002:Value '||px_req_line_detail_attr_tbl(I).pricing_attr_value_from);
7135   END IF;
7136 --  my_debug('17004:validated '||l_pricing_contexts_tbl(i).validated_flag);
7137   --my_debug('17006:status code '||l_pricing_contexts_tbl(i).status_code);
7138  -- my_debug('17008:status text '||l_pricing_contexts_tbl(i).status_text);
7139 
7140   IF (l_debug = 'Y') THEN
7141      my_debug('17010:---------------------------------------------------');
7142   END IF;
7143 
7144   EXIT WHEN I = px_req_line_detail_attr_tbl.last;
7145   I:=px_req_line_detail_attr_tbl.NEXT(I);
7146 
7147  END LOOP;
7148 END IF;
7149 
7150 IF (l_debug = 'Y') THEN
7151    my_debug('17012:-----------Qualifier Attributes Information-------------');
7152 END IF;
7153 
7154 I := px_req_line_detail_qual_tbl.FIRST;
7155 IF I IS NOT NULL THEN
7156  LOOP
7157   IF (l_debug = 'Y') THEN
7158      my_debug('17014:Line Detail Index '||px_req_line_detail_qual_tbl(I).line_detail_index);
7159      my_debug('17018:Context '||px_req_line_detail_qual_tbl(I).qualifier_context);
7160      my_debug('17020:Attribute '||px_req_line_detail_qual_tbl(I).qualifier_attribute);
7161      my_debug('17022:Value '||px_req_line_detail_qual_tbl(I).qualifier_attr_value_from);
7162      my_debug('17024:Status Code '||px_req_line_detail_qual_tbl(I).status_code);
7163      my_debug('17026:---------------------------------------------------');
7164   END IF;
7165 
7166   EXIT WHEN I = px_req_line_detail_qual_tbl.last;
7167   I:=px_req_line_detail_qual_tbl.NEXT(I);
7168 
7169  END LOOP;
7170 END IF;
7171 I := px_req_line_detail_tbl.FIRST;
7172 
7173 IF (l_debug = 'Y') THEN
7174    my_debug('17028:------------Price List/Discount Information------------');
7175 END IF;
7176 
7177 IF I IS NOT NULL THEN
7178  LOOP
7179    IF (l_debug = 'Y') THEN
7180       my_debug('17030:I: '||I);
7181      my_debug('17032:Line Index: '||px_req_line_detail_tbl(I).line_index);
7182      my_debug('17034:Line Detail Index: '||px_req_line_detail_tbl(I).line_detail_index);
7183      my_debug('17036:Line Detail Type:'||px_req_line_detail_tbl(I).line_detail_type_code);
7184      my_debug('17036:Modifier level code:'||px_req_line_detail_tbl(I).modifier_level_code);
7185      my_debug('17038:List Header Id: '||px_req_line_detail_tbl(I).list_header_id);
7186      my_debug('17040:List Line Id: '||px_req_line_detail_tbl(I).list_line_id);
7187      my_debug('17041:List Line Number: '||px_req_line_detail_tbl(I).list_line_no);
7188      my_debug('17042:List Line Type Code: '||px_req_line_detail_tbl(I).list_line_type_code);
7189      my_debug('17044:created from Type Code: '||px_req_line_detail_tbl(I).created_from_list_type_code);
7190      my_debug('17046:Adjustment Amount : '||px_req_line_detail_tbl(I).adjustment_amount);
7191      my_debug('17048:Line Quantity : '||px_req_line_detail_tbl(I).line_quantity);
7192      my_debug('17050:Operand Calculation Code: '||px_req_line_detail_tbl(I).Operand_calculation_code);
7193      my_debug('17052:Operand value: '||px_req_line_detail_tbl(I).operand_value);
7194      my_debug('17054:Automatic Flag: '||px_req_line_detail_tbl(I).automatic_flag);
7195      my_debug('17056:Override Flag: '||px_req_line_detail_tbl(I).override_flag);
7196      my_debug('17058:Applied flag: '||px_req_line_detail_tbl(I).applied_flag);
7197      my_debug('17060:Updated Flag: '||px_req_line_detail_tbl(I).UPDATED_FLAG);
7198      my_debug('17062:PROCESS CODE: '||px_req_line_detail_tbl(I).PROCESS_CODE);
7199      my_debug('17064:status_code: '||px_req_line_detail_tbl(I).status_code);
7200      my_debug('17066:status text: '||px_req_line_detail_tbl(I).status_text);
7201      my_debug('17068:-------------------------------------------');
7202    END IF;
7203   EXIT WHEN I =  px_req_line_detail_tbl.LAST;
7204   I := px_req_line_detail_tbl.NEXT(I);
7205  END LOOP;
7206 END IF;
7207 
7208 
7209 
7210 
7211 IF (l_debug = 'Y') THEN
7212    my_debug('17070:--------------Related Lines Information for Price Breaks/Service Items---------------');
7213 END IF;
7214 I := px_req_related_line_tbl.FIRST;
7215 IF I IS NOT NULL THEN
7216  LOOP
7217   IF (l_debug = 'Y') THEN
7218      my_debug('17072:Line Index :'||px_req_related_line_tbl(I).line_index);
7219      my_debug('17074:Line Detail Index: '||px_req_related_line_tbl(I).LINE_DETAIL_INDEX);
7220      my_debug('17076:Relationship Type Code: '||px_req_related_line_tbl(I).relationship_type_code);
7221      my_debug('17078:Related Line Index: '||px_req_related_line_tbl(I).RELATED_LINE_INDEX);
7222      my_debug('17080:Related Line Detail Index: '||px_req_related_line_tbl(I).related_line_detail_index);
7223      my_debug('17082:Status Code: '|| px_req_related_line_tbl(I).STATUS_CODE);
7224   END IF;
7225   EXIT WHEN I =  px_req_related_line_tbl.LAST;
7226   I :=  px_req_related_line_tbl.NEXT(I);
7227  END LOOP;
7228 END IF;
7229 --san */
7230 
7231             ----end dbmsoutput area
7232             -- nulligy body local tables
7233             g_hdr_rul_tbl.delete;
7234             g_hdr_prle_tbl.delete;
7235             g_hdr_pricelist :=null;
7236           --return lines and prices and any errors if any.
7237           IF (l_debug = 'Y') THEN
7238              my_debug('17084:Before Calling process_adjustments'||px_CLE_PRICE_TBL.count);
7239           END IF;
7240 
7241           PROCESS_ADJUSTMENTS(p_api_version               =>  p_api_version,
7242                               p_CHR_ID                     => p_chr_id,
7243                               p_Control_Rec			       => l_okc_control_rec,
7244                               p_req_line_tbl               => px_req_line_tbl,
7245                               p_Req_LINE_DETAIL_tbl        => px_req_line_detail_tbl,
7246                               p_Req_LINE_DETAIL_qual_tbl   => px_req_line_detail_qual_tbl,
7247                               p_Req_LINE_DETAIL_attr_tbl   => px_req_line_detail_attr_tbl,
7248                               p_Req_RELATED_LINE_TBL       => px_req_related_line_tbl,
7249                               px_CLE_PRICE_TBL		       => px_CLE_PRICE_TBL,
7250                               x_return_status              => l_return_status,
7251                               x_msg_count                  => x_msg_count,
7252                               x_msg_data                   => x_msg_data);
7253 
7254           IF (l_debug = 'Y') THEN
7255              my_debug('17090:After calling process_adjustments'||l_return_status);
7256           END IF;
7257 
7258                   IF l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
7259                              RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
7260                   ELSIF l_return_status = OKC_API.G_RET_STS_ERROR THEN
7261                              RAISE OKC_API.G_EXCEPTION_ERROR;
7262                   ELSIF l_return_status = G_SOME_LINE_ERRORED THEN
7263                            x_return_status := l_return_status;
7264 
7265                   END IF;
7266 
7267 
7268     OKC_API.END_ACTIVITY(x_msg_count, x_msg_data);
7269 
7270     IF (l_debug = 'Y') THEN
7271        my_debug('17096 : Exiting CALCULATE_PRICE', 2);
7272     END IF;
7273     IF (l_debug = 'Y') THEN
7274        okc_debug.Reset_Indentation;
7275     END IF;
7276 
7277 
7278     EXCEPTION
7279           when l_exception_stop then
7280               x_return_status:= OKC_API.G_RET_STS_SUCCESS;
7281               RAISE l_exception_stop;
7282               IF (l_debug = 'Y') THEN
7283                  my_debug('17690 : Exiting CALCULATE_PRICE', 4);
7284               END IF;
7285               IF (l_debug = 'Y') THEN
7286                  okc_debug.Reset_Indentation;
7287               END IF;
7288 
7289           WHEN OKC_API.G_EXCEPTION_ERROR THEN
7290               x_return_status := OKC_API.HANDLE_EXCEPTIONS
7291                        (l_api_name,
7292                         G_PKG_NAME,
7293                        'OKC_API.G_RET_STS_ERROR',
7294                         x_msg_count,
7295                         x_msg_data,
7296                         '_PROCESS');
7297          IF (l_debug = 'Y') THEN
7298             my_debug('17700 : Exiting CALCULATE_PRICE', 4);
7299          END IF;
7300          IF (l_debug = 'Y') THEN
7301             okc_debug.Reset_Indentation;
7302          END IF;
7303 
7304          WHEN OKC_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
7305               x_return_status := OKC_API.HANDLE_EXCEPTIONS
7306                        (l_api_name,
7307                         G_PKG_NAME,
7308                        'OKC_API.G_RET_STS_UNEXP_ERROR',
7309                         x_msg_count,
7310                         x_msg_data,
7311                         '_PROCESS');
7312          IF (l_debug = 'Y') THEN
7313             my_debug('17800 : Exiting CALCULATE_PRICE', 4);
7314          END IF;
7315          IF (l_debug = 'Y') THEN
7316             okc_debug.Reset_Indentation;
7317          END IF;
7318 
7319          WHEN OTHERS THEN
7320               OKC_API.set_message(p_app_name      => g_app_name,
7321                                  p_msg_name      => g_unexpected_error,
7322                                  p_token1        => g_sqlcode_token,
7323                                  p_token1_value  => sqlcode,
7324                                  p_token2        => g_sqlerrm_token,
7325                                  p_token2_value  => sqlerrm);
7326             x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
7327          IF (l_debug = 'Y') THEN
7328             my_debug('17898 : error ocurred'||sqlcode||sqlerrm, 4);
7329          END IF;
7330 
7331          IF (l_debug = 'Y') THEN
7332             my_debug('17900 : Exiting CALCULATE_PRICE', 4);
7333          END IF;
7334          IF (l_debug = 'Y') THEN
7335             okc_debug.Reset_Indentation;
7336          END IF;
7337 
7338 END CALCULATE_price;
7339 
7340 
7341 ----------------------------------------------------------------------------
7342 -- GET_MANUAL_ADJUSTMENTS
7343 -- This procedure will return all the manual adjustments that qualify for the
7344 -- sent in lines and header
7345 -- To get adjustments for a line pass p_cle_id and p_control_rec.p_level='L'
7346 -- To get adjustments for a Header pass p_cle_id as null and p_control_rec.p_level='H'
7347 ----------------------------------------------------------------------------
7348 PROCEDURE get_manual_adjustments(
7349           p_api_version                 IN          NUMBER,
7350           p_init_msg_list               IN          VARCHAR2 ,
7351           p_CHR_ID                      IN          NUMBER,
7352           p_cle_id                      IN          number                     ,
7353           p_Control_Rec			        IN          OKC_CONTROL_REC_TYPE,
7354           x_ADJ_tbl                     OUT  NOCOPY MANUAL_Adj_Tbl_Type,
7355           x_return_status               OUT  NOCOPY VARCHAR2,
7356           x_msg_count                   OUT  NOCOPY NUMBER,
7357           x_msg_data                    OUT  NOCOPY VARCHAR2) IS
7358     l_return_status varchar2(1) :=OKC_API.G_RET_STS_SUCCESS;
7359 
7360     l_api_name constant VARCHAR2(30) := 'Get_manual_adjustments';
7361     l_cle_id_tbl num_tbl_type;
7362     i pls_integer :=0;
7363     j pls_integer :=0;
7364     l_ind pls_integer :=0;
7365     l_id                        number;
7366     l_control_rec               OKC_CONTROL_REC_TYPE:= p_control_rec;
7367     l_id_tbl num_tbl_type;
7368     l_cle_price_tbl             CLE_PRICE_TBL_TYPE;
7369     l_req_line_tbl              QP_PREQ_GRP.LINE_TBL_TYPE;
7370     l_req_line_qual_tbl         QP_PREQ_GRP.QUAL_TBL_TYPE;
7371     l_req_line_attr_tbl         QP_PREQ_GRP.LINE_ATTR_TBL_TYPE;
7372     l_req_line_detail_tbl       QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE;
7373     l_req_line_detail_qual_tbl  QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE;
7374     l_req_line_detail_attr_tbl  QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE;
7375     l_req_related_line_tbl      QP_PREQ_GRP.RELATED_LINES_TBL_TYPE;
7376 BEGIN
7377     --dbms_output.put_line('start new get manual adjs');
7378     IF (l_debug = 'Y') THEN
7379        okc_debug.Set_Indentation('GET_MANUAL_ADJUSTMENTS');
7380     END IF;
7381     IF (l_debug = 'Y') THEN
7382        my_debug('18000 : Entering GET_MANUAL_ADJUSTMENTS', 2);
7383     END IF;
7384 
7385     x_return_status := OKC_API.G_RET_STS_SUCCESS;
7386 
7387     l_return_status := OKC_API.START_ACTIVITY(l_api_name,
7388                                               p_init_msg_list,
7389                                               '_PROCESS',
7390                                                x_return_status);
7391     IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
7392                     raise OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
7393     ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
7394                     raise OKC_API.G_EXCEPTION_ERROR;
7395     END IF;
7396     l_control_rec.p_calc_flag:='S';
7397     Set_control_rec(l_control_rec);
7398 
7399     If l_control_rec.p_level = 'H' and p_chr_id is not null then
7400       select id
7401       bulk collect into l_id_tbl
7402       from OKC_K_LINES_B
7403       where price_level_ind='Y' and dnz_chr_id = p_chr_id;
7404       IF (l_debug = 'Y') THEN
7405          my_debug('18010 : select rowcount'||SQL%ROWCOUNT, 1);
7406       END IF;
7407 
7408        i:= l_id_tbl.first;
7409        while i is not null loop
7410            l_cle_price_tbl(i).id:=l_id_tbl(i);
7411         i:=l_id_tbl.next(i);
7412        END loop;
7413        l_id := p_chr_id;
7414     ELSIF l_control_rec.p_level = 'L' and p_cle_id is not null then
7415                l_cle_price_tbl(1).id:=p_cle_id;
7416                l_id := p_cle_id;
7417     ELSIF  l_control_rec.p_level = 'QA' then
7418        OKC_API.set_message(p_app_name      => g_app_name,
7419                                  p_msg_name      => 'OKC_INVALID_LEVEL',
7420                                  p_token1        => 'level',
7421                                  p_token1_value  => 'QA');
7422 
7423         RAISE OKC_API.G_EXCEPTION_ERROR;
7424     End if;
7425 
7426     CALCULATE_price(p_api_version                => p_api_version,
7427                     p_CHR_ID                     => p_chr_id,
7428                     p_Control_Rec			     => l_control_rec,
7429                     px_req_line_tbl              => l_req_line_tbl,
7430                     px_Req_qual_tbl              => l_req_line_qual_tbl,
7431                     px_Req_line_attr_tbl         => l_req_line_attr_tbl,
7432                     px_Req_LINE_DETAIL_tbl       => l_req_line_detail_tbl,
7433                     px_Req_LINE_DETAIL_qual_tbl  => l_req_line_detail_qual_tbl,
7434                     px_Req_LINE_DETAIL_attr_tbl  => l_req_line_detail_attr_tbl,
7435                     px_Req_RELATED_LINE_TBL      => l_req_related_line_tbl,
7436                     px_CLE_PRICE_TBL		     => l_CLE_PRICE_TBL,
7437                     x_return_status              => x_return_status,
7438                     x_msg_count                  => x_msg_count,
7439                     x_msg_data                   => x_msg_data);
7440      IF x_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
7441                    RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
7442     --Since there is only one line here in case of error return the error found
7443      ELSIF x_return_status = OKC_API.G_RET_STS_ERROR OR x_return_status = OKC_API.G_RET_STS_ERROR THEN
7444                   RAISE OKC_API.G_EXCEPTION_ERROR;
7445      END IF;
7446      i:=l_req_line_detail_tbl.first;
7447 	        While i Is not Null Loop
7448                If l_req_line_detail_tbl(i).automatic_flag = 'N' Then --#2
7449 
7450                    If l_req_line_tbl(l_req_line_detail_tbl(i).line_index).line_id=l_id --#1
7451 --                      and l_req_line_detail_tbl(i).line_index = l_discount_line_ind
7452                       and (( p_control_rec.p_level='L' and
7453                             l_req_line_tbl(l_req_line_detail_tbl(i).line_index).line_type_code = 'LINE')
7454                             OR (p_control_rec.p_level='H' and
7455                             l_req_line_tbl(l_req_line_detail_tbl(i).line_index).line_type_code = 'ORDER'))
7456                        then
7457 
7458                        x_adj_tbl(i).modifier_number:=l_req_line_detail_tbl(i).list_line_no;
7459                        x_adj_tbl(i).list_line_type_code :=l_req_line_detail_tbl(i).list_line_type_code;
7460                        x_adj_tbl(i).operand          :=l_req_line_detail_tbl(i).operand_value;
7461                        x_adj_tbl(i).list_line_id     :=l_req_line_detail_tbl(i).list_line_id;
7462                        x_adj_tbl(i).list_header_id   :=l_req_line_detail_tbl(i).list_header_id;
7463                        x_adj_tbl(i).pricing_phase_id :=l_req_line_detail_tbl(i).pricing_phase_id;
7464                        x_adj_tbl(i).automatic_flag   :=l_req_line_detail_tbl(i).automatic_flag;
7465                        x_adj_tbl(i).modifier_level_code:=l_req_line_detail_tbl(i).modifier_level_code;
7466                        x_adj_tbl(i).override_flag    :=l_req_line_detail_tbl(i).override_flag;
7467                        x_adj_tbl(i).applied_flag     :=l_req_line_detail_tbl(i).applied_flag;
7468                        x_adj_tbl(i).operator         :=l_req_line_detail_tbl(i).operand_calculation_code;
7469                        x_adj_tbl(i).MODIFIER_MECHANISM_TYPE_CODE      := l_req_line_detail_tbl(i).created_from_list_type_code;
7470 
7471 
7472                        /** Bug 2692818: for manual adjustments based on line AMOUNT, we need to store the 'line quantity'
7473                            coming from pricing as range break quantity. Pricing returns 'line quantity' for the PBH.
7474                        **/
7475                        If l_req_line_detail_tbl(i).list_line_type_code = 'PBH' Then
7476                           x_adj_tbl(i).range_break_quantity := l_req_line_detail_tbl(i).line_quantity;
7477 
7478 
7479                           --Bug 2784735: need to use this for price break modifiers using formula
7480                           x_adj_tbl(i).line_detail_index := l_req_line_detail_tbl(i).line_detail_index;
7481 
7482                        End If;
7483 
7484 
7485                    End If; --#1
7486 
7487                 End If; --#2
7488 
7489 
7490                   i:=l_req_line_detail_tbl.next(i);
7491                 End Loop;
7492 
7493 
7494 IF (l_debug = 'Y') THEN
7495    my_debug('18400 : --------------Manual discounts returned for Id'||l_id);
7496 END IF;
7497 I := x_adj_tbl.FIRST;
7498 IF I IS NOT NULL THEN
7499  LOOP
7500                       IF (l_debug = 'Y') THEN
7501                          my_debug('18400 : modifier no :'||x_adj_tbl(i).modifier_number,1);
7502                          my_debug('18410 : list line type code :'||x_adj_tbl(i).list_line_type_code,1);
7503                          my_debug('18420 : operand :'||x_adj_tbl(i).operand,1);
7504                          my_debug('18430 : list line id :'|| x_adj_tbl(i).list_line_id,1);
7505                          my_debug('18440 : list header id :'||x_adj_tbl(i).list_header_id,1);
7506                          my_debug('18450 : pricing phase id :'||x_adj_tbl(i).pricing_phase_id ,1);
7507                          my_debug('18460 : automatic flag :'||x_adj_tbl(i).automatic_flag ,1);
7508                          my_debug('18470 :  modifier level code :'||x_adj_tbl(i).modifier_level_code,1);
7509                          my_debug('18480 : override flag :'||x_adj_tbl(i).override_flag ,1);
7510                          my_debug('18490 :  Applied flag :'||x_adj_tbl(i).Applied_flag,1);
7511                          my_debug('18500 :  operator :'||x_adj_tbl(i).operator ,1);
7512                          my_debug('18502 :  modifier mechanism type code :'||x_adj_tbl(i).modifier_mechanism_type_code ,1);
7513                          my_debug('18503 : range break quantity :'||x_adj_tbl(i).range_break_quantity,1);
7514                          my_debug('18504 : line detail index :'||x_adj_tbl(i).line_detail_index,1);
7515                       END IF;
7516   EXIT WHEN I =x_adj_tbl.LAST;
7517   I := x_adj_tbl.NEXT(I);
7518 
7519 
7520  END LOOP;
7521     OKC_API.END_ACTIVITY(x_msg_count, x_msg_data);
7522 
7523     IF (l_debug = 'Y') THEN
7524        my_debug('18600 : Exiting GET_MANUAL_ADJUSTMENTS', 2);
7525     END IF;
7526     IF (l_debug = 'Y') THEN
7527        okc_debug.Reset_Indentation;
7528     END IF;
7529 
7530 END IF;  ----end dbmsoutput area
7531     EXCEPTION
7532           WHEN OKC_API.G_EXCEPTION_ERROR THEN
7533               x_return_status := OKC_API.HANDLE_EXCEPTIONS
7534                        (l_api_name,
7535                         G_PKG_NAME,
7536                        'OKC_API.G_RET_STS_ERROR',
7537                         x_msg_count,
7538                         x_msg_data,
7539                         '_PROCESS');
7540          IF (l_debug = 'Y') THEN
7541             my_debug('18700 : Exiting GET_MANUAL_ADJUSTMENTS', 4);
7542          END IF;
7543          IF (l_debug = 'Y') THEN
7544             okc_debug.Reset_Indentation;
7545          END IF;
7546 
7547          WHEN OKC_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
7548               x_return_status := OKC_API.HANDLE_EXCEPTIONS
7549                        (l_api_name,
7550                         G_PKG_NAME,
7551                        'OKC_API.G_RET_STS_UNEXP_ERROR',
7552                         x_msg_count,
7553                         x_msg_data,
7554                         '_PROCESS');
7555          IF (l_debug = 'Y') THEN
7556             my_debug('18800 : Exiting GET_MANUAL_ADJUSTMENTS', 4);
7557          END IF;
7558          IF (l_debug = 'Y') THEN
7559             okc_debug.Reset_Indentation;
7560          END IF;
7561 
7562          WHEN OTHERS THEN
7563               OKC_API.set_message(p_app_name     => g_app_name,
7564                                  p_msg_name      => g_unexpected_error,
7565                                  p_token1        => g_sqlcode_token,
7566                                  p_token1_value  => sqlcode,
7567                                  p_token2        => g_sqlerrm_token,
7568                                  p_token2_value  => sqlerrm);
7569             x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
7570          IF (l_debug = 'Y') THEN
7571             my_debug('18900 : Exiting GET_MANUAL_ADJUSTMENTS', 4);
7572          END IF;
7573          IF (l_debug = 'Y') THEN
7574             okc_debug.Reset_Indentation;
7575          END IF;
7576 
7577  END get_manual_adjustments;
7578 
7579 --????? no foriegn key checks in PAT for cle/chr
7580 --??????ask sri assocs- we donot generate extra lines , so relate how. for price breaks need to store unapplied ones as well
7581 END OKC_PRICE_PVT;