DBA Data[Home] [Help]

PACKAGE BODY: APPS.OKS_MASSCHANGE_PVT

Source


1 PACKAGE BODY OKS_MASSCHANGE_PVT AS
2 /* $Header: OKSRMASB.pls 120.31 2007/12/14 10:44:09 mkarra ship $ */
3 
4  l_conc_program Varchar2(1);
5 
6 
7  PROCEDURE get_eligible_contracts
8 		 (p_api_version           IN  Number
9 		 ,p_init_msg_list         IN  Varchar2
10 		 ,p_ctr_rec               IN  criteria_rec_type
11                  ,p_query_type            IN  Varchar2 DEFAULT 'FETCH'
12                  ,p_upg_orig_system_ref   IN  Varchar2
13 		 ,x_return_status         OUT NOCOPY Varchar2
14 		 ,x_msg_count             OUT NOCOPY Number
15 		 ,x_msg_data              OUT NOCOPY Varchar2
16 		 ,x_eligible_contracts    OUT NOCOPY eligible_contracts_tbl)
17 
18       IS
19 
20 	   TYPE t_contracts IS REF CURSOR;
21 
22 	   v_CurContract           t_contracts;
23 	   l_stmt                  Varchar2(10000);
24            l_stmt_all              Varchar2(10000);
25 	   l_select                Varchar2(2000);
26 	   l_from                  Varchar2(2000);
27 	   l_where                 Varchar2(20000);
28            l_org_where             Varchar2(2000);
29            l_org_id                OKC_K_HEADERS_B.org_id%type;
30        l_eligible_contracts    eligible_contracts_tbl;
31 
32         i               Number := 0;
33         j               Number := 0;
34         k               Number := 0;
35         v_present         Varchar2(1);
36         l_old_value	Varchar2(500);
37 
38   BEGIN
39 
40     x_return_status := G_RET_STS_SUCCESS;
41 
42     IF p_query_type = 'FETCH' THEN
43 
44  	           l_select :='SELECT distinct okh.id,
45                                   okh.contract_number,
46                                   okh.contract_number_modifier,
47                                   okh.start_date,
48                                   okh.end_date,
49                                   okh.short_description,
50                                   okh.sts_code,
51                                   oxp.name party
52                                   ,org.name
53 				   ,okh.billed_at_source';
54 
55               l_from :=' FROM  okc_k_headers_v okh,okc_k_party_roles_b okp,okx_parties_v oxp, hr_operating_units org,okc_assents_v oas
56                         , okc_k_lines_b ocl';
57 
58        If p_ctr_rec.attribute in ('CONTRACT_START_DATE','CONTRACT_END_DATE') Then
59           IF p_ctr_rec.oie_id IS NOT NULL THEN
60 
61       	      l_where:=' WHERE okh.scs_code in (''SERVICE'',''SUBSCRIPTION'',''WARRANTY'')
62 		         AND okh.datetime_cancelled IS NULL  -- Added as part of LLC
63     			 AND okh.date_terminated is NULL
64 	       		 AND okh.id not in(
65                                  SELECT ole.subject_chr_id
66                                  FROM  okc_operation_instances_v oie,
67                                        okc_operation_lines_v ole,
68                                        okc_class_operations_v oco
69                                  WHERE oie.id = ole.oie_id
70                                  AND   oie.id = :p_ctr_rec_oie_id
71                                  AND   oie.cop_id = oco.id AND   opn_code = ''MASS_CHANGE'')
72 		                AND oas.sts_code = okh.sts_code
73 	                        AND oas.opn_code = ''UPDATE''
74 		          	AND oas.scs_code = okh.scs_code
75 				AND  ocl.chr_id = okh.id
76 				AND  nvl(ocl.upg_orig_system_ref,''X'') <> ''MIG_NOBILL''
77 		        AND okh.id = okp.chr_id
78 			AND okp.rle_code in ( ''CUSTOMER'',''SUBSCRIBER'')
79     	                AND okp.object1_id1 = oxp.id1
80 	                And  org.organization_id = okh.authoring_org_id
81 	                AND oxp.id2 = ''#'''  ;
82           ELSE -- oie_id null
83      	       l_where:=' WHERE okh.scs_code in (''SERVICE'',''SUBSCRIPTION'',''WARRANTY'')
84                      AND okh.datetime_cancelled IS NULL  -- Added as part of LLC
85 	             AND okh.date_terminated is NULL
86                                  AND oas.sts_code = okh.sts_code
87                                  AND oas.opn_code = ''UPDATE''
88                                  AND oas.scs_code = okh.scs_code
89                                   AND  ocl.chr_id = okh.id
90                                   AND  nvl(ocl.upg_orig_system_ref,''X'') <> ''MIG_NOBILL''
91                    AND okh.id = okp.chr_id
92                    AND okp.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
93                    AND okp.object1_id1 = oxp.id1
94                    And  org.organization_id = okh.authoring_org_id
95                    AND oxp.id2 = ''#''';
96          END IF;
97 
98       Else  -- Attribute is stat_date or end_date
99 
100          IF p_ctr_rec.oie_id IS NOT NULL THEN
101 
102       	    l_where:=' WHERE okh.scs_code in (''SERVICE'',''SUBSCRIPTION'',''WARRANTY'')
103                      AND okh.datetime_cancelled IS NULL  -- Added as part of LLC
104 	             AND okh.date_terminated is NULL
105                      AND  okh.id not in ( SELECT ole.subject_chr_id
106                                  FROM  okc_operation_instances_v oie,
107                                        okc_operation_lines_v ole,
108                                        okc_class_operations_v oco
109                                  WHERE oie.id = ole.oie_id
110                                  AND   oie.id = :p_ctr_rec_oie_id
111                                  AND   oie.cop_id = oco.id AND   opn_code = ''MASS_CHANGE'')
112 	                         AND oas.sts_code = okh.sts_code
113                                 AND oas.opn_code = ''UPDATE''
114 		                AND oas.scs_code = okh.scs_code
115                                   AND  ocl.chr_id = okh.id
116                                   AND  ocl.lse_id <> 14
117                                   AND   nvl(ocl.upg_orig_system_ref,''X'') <> ''MIG_NOBILL''
118                     AND okh.id = okp.chr_id
119                     AND okp.rle_code in ( ''CUSTOMER'',''SUBSCRIBER'')
120                     AND okp.object1_id1 = oxp.id1
121                     And  org.organization_id = okh.authoring_org_id
122                     AND oxp.id2 = ''#'''  ;
123           ELSE -- oie_id is null
124      	      l_where:=' WHERE okh.scs_code in (''SERVICE'',''SUBSCRIPTION'',''WARRANTY'')
125                      AND okh.datetime_cancelled IS NULL  -- Added as part of LLC
126                      AND okh.date_terminated is NULL
127                                  AND   oas.sts_code = okh.sts_code
128                                  AND   oas.opn_code = ''UPDATE''
129                                  AND   oas.scs_code = okh.scs_code
130                                  AND   ocl.chr_id = okh.id
131                                  AND   ocl.lse_id <> 14
132                                  AND   nvl(ocl.upg_orig_system_ref,''X'') <> ''MIG_NOBILL''
133                    AND okh.id = okp.chr_id
134                    AND okp.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
135                    AND okp.object1_id1 = oxp.id1
136                    And org.organization_id = okh.authoring_org_id
137                    AND oxp.id2 = ''#''';
138          END IF;
139 
140       End If ; -- attribute is stat_date or end_date
141 
142     ELSIF (p_query_type = 'PROCESS' AND p_ctr_rec.oie_id IS NOT NULL) THEN
143 
144 	     l_select :='SELECT okh.id,
145                             okh.contract_number,
146                             okh.contract_number_modifier,
147                             okh.start_date,
148                             okh.end_date,
149                             okh.short_description,
150                             okh.sts_code,
151                             okh.qcl_id ,
152                             okh.object_version_number,
153                             ole.id ole_id,
154                             okh.org_id,
155                             mod.qa_check_yn,
156                             org.name ,
157 			    okh.billed_at_source';
158 
159         l_from :=' FROM  okc_k_headers_v okh,okc_operation_lines_v ole ,oks_mschg_operations_dtls mod, hr_operating_units org';
160       	l_where:=' WHERE ole.select_yn = ''Y''
161 	           AND   ole.process_flag IN (''A'',''E'')
162                    AND   okh.id = ole.subject_chr_id
163                    AND   ole.oie_id = :p_ctr_rec_oie_id
164                    AND   mod.ole_id = ole.id
165                    And  org.organization_id = okh.authoring_org_id ';
166 
167       END IF;
168 
169  --dbms_output.put_line('Update_level:'||p_ctr_rec.update_level);
170  --dbms_output.put_line('Update_level_value:'||p_ctr_rec.update_level_value);
171  --dbms_output.put_line('Attribute:'||p_ctr_rec.attribute);
172  --dbms_output.put_line('Old value:'||p_ctr_rec.old_value);
173 
174  --------------------------------
175  --  Update Level : Contract
176  --------------------------------
177  IF p_ctr_rec.update_level = 'OKS_K_HEADER' THEN
178 
179  --------------------------------------------------------
180  --  Update Level : Contract , Attribute: Revenue Account(REV_ACCT)
181  --------------------------------------------------------
182       IF p_ctr_rec.attribute = 'REV_ACCT' THEN
183 
184        -- Old Value: NULL (-9999)
185 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
186              l_stmt := l_select||' ,NULL old_value'||
187                        l_from||l_where||
188                        ' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
189                                      WHERE rev.chr_id = okh.id
190                                      AND   rev.code_combination_id is NULL)
191                         AND okh.id = to_number(:update_level_value)' ; --||to_number(p_ctr_rec.update_level_value);
192 
193        -- Old Value: ALL (-1111)
194           ELSIF p_ctr_rec.old_value = '-1111' THEN
195 
196              l_stmt := l_select||' ,NULL old_value'||
197                        l_from||l_where||
198                        ' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
199                                      WHERE rev.chr_id = okh.id)
200                         AND okh.id = to_number(:update_level_value)';
201 
202  -- Old Value: Other than NULL or ALL
203 
204           ELSE
205              l_old_value := p_ctr_rec.old_value;
206              l_stmt := l_select||' , :l_old_value old_value'||
207                        l_from||l_where||
208                        ' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
209                                      WHERE rev.chr_id = okh.id
210                                      AND   rev.code_combination_id = to_number(:p_ctr_rec_old_value))
211                         AND okh.id = to_number(:update_level_value)';
212 
213           END IF;
214   --------------------------------------------------------------------------
215  --  Update Level : Contract , Attribute: Payment Term(PAYMENT_TERM)
216  ---------------------------------------------------------------------------
217       ELSIF p_ctr_rec.attribute = 'PAYMENT_TERM' THEN
218 
219        -- Old Value: NULL (-9999)
220 	     IF    p_ctr_rec.old_value = '-9999' THEN
221 
222                        l_stmt := l_select||' ,NULL old_value' ||
223                        l_from||l_where||
224                        ' AND  okh.PAYMENT_TERM_ID is NULL
225                          AND  okh.id = to_number(:p_ctr_rec_old_value) ';
226 
227          ELSIF p_ctr_rec.old_value = '-1111' THEN
228                        l_stmt := l_select||' ,okh.payment_term_id old_value' ||
229                        l_from||l_where||
230                                'AND okh.id = to_number(:update_level_value)';
231  -- Old Value: Other than NULL or ALL
232 
233           ELSE
234 
235              l_stmt := l_select||' ,okh.payment_term_id old_value' ||
236                        l_from||l_where||
237                        ' AND  okh.PAYMENT_TERM_ID = to_number(:p_ctr_rec_old_value)
238                          AND  okh.id = to_number(:p_ctr_rec_old_value) ';
239 
240           END IF;
241 
242  --------------------------------------------------------------------------
243  --  Update Level : Contract , Attribute: Contract Renewal Type(CON_RENEWAL_TYPE)
244  ---------------------------------------------------------------------------
245       ELSIF p_ctr_rec.attribute = 'CON_RENEWAL_TYPE' THEN
246 
247        -- Old Value: NULL (-9999)
248 	     IF    p_ctr_rec.old_value = '-9999' THEN
249 
250                        l_stmt := l_select||' ,NULL old_value' ||
251                        l_from||l_where||
252                        ' AND  okh.renewal_type_code is NULL
253                          AND not exists(
254                                         select ol.object_chr_id
255                                         from okc_operation_lines ol
256                                             ,okc_operation_instances oi
257                                             ,okc_class_operations co
258                                         WHERE ol.object_chr_id = okh.id
259                                           AND ol.process_flag = ''P''
260                                           AND ol.ACTIVE_YN    = ''Y''
261                                           AND oi.id = ol.oie_id
262                                           AND oi.cop_id = co.id
263                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
264                                           AND co.CLS_CODE = ''SERVICE'')
265                          AND  okh.id = to_number(:p_ctr_rec_old_value) ';
266 
267          ELSIF p_ctr_rec.old_value = '-1111' THEN
268                        l_old_value := p_ctr_rec.old_value;
269                        l_stmt := l_select||' , :l_old_value old_value' ||
270                        l_from||l_where||
271                                 ' AND not exists(
272                                         select ol.object_chr_id
273                                         from okc_operation_lines ol
274                                             ,okc_operation_instances oi
275                                             ,okc_class_operations co
276                                         WHERE ol.object_chr_id = okh.id
277                                           AND ol.process_flag = ''P''
278                                           AND ol.ACTIVE_YN    = ''Y''
279                                           AND oi.id = ol.oie_id
280                                           AND oi.cop_id = co.id
281                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
282                                           AND co.CLS_CODE = ''SERVICE'')
283                                 AND okh.id = to_number(:update_level_value)';
284  -- Old Value: ERN
285 
286           ELSIF p_ctr_rec.old_value = 'ERN' then
287              l_old_value := p_ctr_rec.old_value;
288              l_stmt := l_select||' , :l_old_value old_value' ||
289                        l_from||', oks_k_headers_b oksh'||
290                        l_where||
291                        ' AND oksh.chr_id = okh.id
292                         AND   (okh.renewal_type_code = ''NSR''
293                                  AND ''ERN'' = :p_ctr_rec_old_value
294                                  AND oksh.ELECTRONIC_RENEWAL_FLAG =''Y'')
295                          AND not exists(
296                                         select ol.object_chr_id
297                                         from okc_operation_lines ol
298                                             ,okc_operation_instances oi
299                                             ,okc_class_operations co
300                                         WHERE ol.object_chr_id = okh.id
301                                           AND ol.process_flag = ''P''
302                                           AND ol.ACTIVE_YN    = ''Y''
303                                           AND oi.id = ol.oie_id
304                                           AND oi.cop_id = co.id
305                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
306                                           AND co.CLS_CODE = ''SERVICE'')
307                         AND  okh.id = to_number(:p_ctr_rec_old_value) ';
308 
309  -- Old Value: Other than NULL or ALL
310           ELSE
311              l_old_value := p_ctr_rec.old_value;
312              l_stmt := l_select||' , :l_old_value old_value' ||
313                        l_from||', oks_k_headers_b oksh'||
314                        l_where||
315                        ' AND oksh.chr_id = okh.id
316                         AND  okh.renewal_type_code = :p_ctr_rec_old_value
317                         AND  nvl(oksh.ELECTRONIC_RENEWAL_FLAG,''N'') <>''Y''
318                          AND not exists(
319                                         select ol.object_chr_id
320                                         from okc_operation_lines ol
321                                             ,okc_operation_instances oi
322                                             ,okc_class_operations co
323                                         WHERE ol.object_chr_id = okh.id
324                                           AND ol.process_flag = ''P''
325                                           AND ol.ACTIVE_YN    = ''Y''
326                                           AND oi.id = ol.oie_id
327                                           AND oi.cop_id = co.id
328                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
329                                           AND co.CLS_CODE = ''SERVICE'')
330                         AND  okh.id = to_number(:p_ctr_rec_old_value) ';
331           END IF;
332 
333  ---------------------------------------------------------------------------
334  --  Update Level : Contract , Attribute: Business Process Price List (BP_PRICE_LIST)
335  ---------------------------------------------------------------------------
336       ELSIF p_ctr_rec.attribute = 'BP_PRICE_LIST' THEN
337 
338      -- Old Value: NULL (-9999)
339 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
340               l_stmt := l_select||' ,NULL old_value' ||
341                         l_from||
342                         l_where|| 'AND exists ( Select dnz_chr_id from okc_k_lines_b cln
343                                           Where cln.dnz_chr_id = okh.id
344                                             AND cln.lse_id in(3,16,21)
345                                             AND cln.price_list_id is NULL)
346                                    AND  okh.id = to_number(:update_level_value)';
347 
348      -- Old Value: ALL (-1111)
349           ELSIF p_ctr_rec.old_value = '-1111' THEN
350              l_old_value := p_ctr_rec.old_value;
351              l_stmt := l_select||' , :l_old_value old_value' ||
352                        l_from||
353                        l_where|| ' AND exists ( Select dnz_chr_id from okc_k_lines_b cln
354                                           Where cln.dnz_chr_id = okh.id
355                                             AND cln.lse_id in(3,16,21))
356                                    AND  okh.id = to_number(:update_level_value)';
357 
358      -- Old Value: Other than NULL or ALL
359           ELSE
360              l_old_value := p_ctr_rec.old_value;
361              l_stmt := l_select||' , :l_old_value old_value' ||
362                        l_from||
363                        l_where|| ' AND exists ( Select dnz_chr_id from okc_k_lines_b cln
364                                       Where cln.dnz_chr_id = okh.id
365                                       AND cln.lse_id in(3,16,21)
366                                       AND cln.price_list_id = to_number(:p_ctr_rec_old_value))
367                                   AND  okh.id = to_number(:update_level_value)';
368 
369           END IF;
370 
371 
372  ---------------------------------------------------------------------------
373  --  Update Level : Contract , Attribute: Accounting Rule(ACCT_RULE)
374  ---------------------------------------------------------------------------
375       ELSIF p_ctr_rec.attribute = 'ACCT_RULE' THEN
376 
377      -- Old Value: NULL (-9999)
378 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
379 
380               l_stmt := l_select||' ,NULL old_value' ||
381                         l_from||' ,oks_k_headers_v oksh '||
382                         l_where|| 'AND oksh.chr_id = okh.id
383                                    AND oksh.acct_rule_id IS NULL
384                                    AND  okh.id = to_number(:update_level_value)';
385      -- Old Value: ALL (-1111)
386 
387           ELSIF p_ctr_rec.old_value = '-1111' THEN
388              l_stmt := l_select||' ,oksh.acct_rule_id old_value' ||
389                        l_from||' ,oks_k_headers_v oksh '||
390                        l_where|| 'AND oksh.chr_id = okh.id
391                                   AND  okh.id = to_number(:update_level_value)';
392      -- Old Value: Other than NULL or ALL
393 
394           ELSE
395              l_stmt := l_select||' ,oksh.acct_rule_id old_value' ||
396                        l_from||' ,oks_k_headers_v oksh '||
397                        l_where|| 'AND oksh.chr_id = okh.id
398                                   AND oksh.acct_rule_id = to_number(:p_ctr_rec_old_value)
399                                   AND  okh.id = to_number(:update_level_value)';
400 
401           END IF;
402  ---------------------------------------------------------------------------
403  --  Update Level : Contract , Attribute: Invoice Rule(INV_RULE)
404  ---------------------------------------------------------------------------
405       ELSIF p_ctr_rec.attribute = 'INV_RULE' THEN
406 
407        -- Old Value: NULL (-9999)
408          IF  p_ctr_rec.old_value = '-9999' THEN
409 
410              l_stmt := l_select||' ,NULL old_value' ||
411                        l_from||l_where||
412                              ' AND  okh.inv_rule_id IS NULL
413                                AND  okh.id = to_number(:update_level_value) ';
414 
415          ELSIF p_ctr_rec.old_value = '-1111' THEN
416                     l_stmt := l_select||' ,okh.inv_rule_id old_value' ||
417                               l_from||l_where||
418                                     ' AND  okh.id = to_number(:update_level_value) ';
419 
420        -- Old Value: Other than NULL or ALL
421 
422           ELSE
423 
424                 l_stmt := l_select||' ,okh.inv_rule_id old_value' ||
425                           l_from||l_where||
426                                 ' AND  okh.inv_rule_id = to_number(:p_ctr_rec_old_value)
427                                   AND  okh.id = to_number(:update_level_value) ';
428 
429           END IF;
430 
431  ---------------------------------------------------------------------------
432  -- Update Level : Contract , Attribute: Coverage Type(COV_TYPE)
433  ---------------------------------------------------------------------------
434       ELSIF p_ctr_rec.attribute = 'COV_TYPE' THEN
435 
436        -- Old Value: NULL (-9999)
437 	     IF p_ctr_rec.old_value = '-9999' THEN
438              l_stmt := l_select||' ,NULL old_value'||
439                        l_from||l_where||
440                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V okl, oks_k_lines_v oksl
441                                              WHERE okl.dnz_chr_id = okh.id
442                                              AND oksl.cle_id = okl.id
443                                              AND oksl.coverage_type is NULL )
444                         AND  okh.id = to_number(:update_level_value)' ;
445 
446         -- Old Value: Other than NULL or ALL
447 
448           ELSIF p_ctr_rec.old_value = '-1111' THEN
449 
450                 l_old_value := p_ctr_rec.old_value;
451                 l_stmt := l_select||' , :l_old_value old_value'||
452                           l_from||
453                           l_where||'AND EXISTS (SELECT ''x'' from okc_k_lines_v okl, oks_k_lines_v oksl
454                                     WHERE okl.dnz_chr_id = okh.id
455                                     AND oksl.cle_id = okl.id )
456                         AND  okh.id = to_number(:update_level_value)' ;
457           ELSE
458                  l_old_value := p_ctr_rec.old_value;
459                  l_stmt := l_select||' , :l_old_value old_value'||
460                            l_from||
461                            l_where||'AND EXISTS (SELECT ''x'' from okc_k_lines_v okl, oks_k_lines_v oksl
462                                      WHERE okl.dnz_chr_id = okh.id
463                                      AND oksl.cle_id = okl.id
464                                      AND oksl.coverage_type = :p_ctr_rec_old_value )
465                         AND  okh.id = to_number(:update_level_value)' ;
466 
467           END IF;
468 
469  ---------------------------------------------------------------------------
470  -- Update Level : Contract , Attribute: Coverage Type(COV_TIMEZONE)
471  ---------------------------------------------------------------------------
472       ELSIF p_ctr_rec.attribute = 'COV_TIMEZONE' THEN
473 
474        -- Old Value: NULL (-9999)
475 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
476              l_stmt := l_select||' ,NULL old_value'||
477                        l_from||l_where||
478                        ' AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
479                                       WHERE ctz.dnz_chr_id = okh.id
480                                       AND   ctz.timezone_id IS NULL )
481                          AND   okh.id = to_number(:update_level_value)';
482 
483        -- Old Value: ALL (-1111)
484           ELSIF p_ctr_rec.old_value = '-1111' THEN
485 
486              l_old_value := p_ctr_rec.old_value;
487              l_stmt := l_select||' , :l_old_value old_value'||
488                        l_from||
489                        l_where||'AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
490                                              WHERE ctz.dnz_chr_id = okh.id
491                                              AND   ctz.timezone_id IS NOT NULL )
492                                              AND   okh.id = to_number(:update_level_value)';
493         -- Old Value: Other than NULL or ALL
494           ELSE
495 
496              l_old_value := p_ctr_rec.old_value;
497              l_stmt := l_select||' , :l_old_value old_value'||
498                        l_from||
499                        l_where||'AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
500                                              WHERE ctz.dnz_chr_id = okh.id
501                                              AND  ctz.timezone_id = to_number(:p_ctr_rec_old_value))
502                                              AND  okh.id = to_number(:update_level_value)';
503 
504           END IF;
505  ---------------------------------------------------------------------------
506  -- Update Level : Contract , Attribute: Coverage Type(PREF_ENGG)
507  ---------------------------------------------------------------------------
508       ELSIF p_ctr_rec.attribute = 'PREF_ENGG' THEN
509 
510           IF p_ctr_rec.old_value = '-1111' THEN
511 
512                 l_old_value := p_ctr_rec.old_value;
513                 l_stmt := l_select||' , :l_old_value old_value'||
514                        l_from||
515                        l_where||'AND EXISTS (SELECT ''x'' from
516                                              okc_contacts oco
517                                              WHERE oco.dnz_chr_id = okh.id
518                                              AND   oco.cro_code = ''ENGINEER''
519                                              AND   oco.jtot_object1_code = ''OKX_RESOURCE'')
520                                              AND  okh.id = to_number(:update_level_value)';
521 
522           ELSE
523              l_old_value := p_ctr_rec.old_value;
524              l_stmt := l_select||' , :l_old_value old_value'||
525                        l_from||
526                        l_where||'AND EXISTS (SELECT ''x'' from
527                                              okc_contacts oco
528                                              WHERE oco.dnz_chr_id = okh.id
529                                              AND   oco.cro_code = ''ENGINEER''
530                                              AND   oco.jtot_object1_code = ''OKX_RESOURCE''
531                                              AND   oco.object1_id1  = :p_ctr_rec_old_value)
532                                              AND  okh.id = to_number(:update_level_value)';
533           END IF;
534  ---------------------------------------------------------------------------
535  -- Update Level : Contract , Attribute: Coverage Type(RES_GROUP)
536  ---------------------------------------------------------------------------
537       ELSIF p_ctr_rec.attribute = 'RES_GROUP' THEN
538 
539 
540           IF p_ctr_rec.old_value = '-1111' THEN
541 
542              l_old_value := p_ctr_rec.old_value;
543              l_stmt := l_select||' , :l_old_value old_value'||
544                        l_from||
545                        l_where||'AND EXISTS (SELECT ''x'' from
546                                              okc_contacts oco
547                                              WHERE oco.dnz_chr_id = okh.id
548                                              AND   oco.cro_code = ''RSC_GROUP''
549                                              AND   oco.jtot_object1_code = ''OKS_RSCGROUP'')
550                                              AND  okh.id = to_number(:update_level_value)';
551 
552           ELSE
553              l_old_value := p_ctr_rec.old_value;
554              l_stmt := l_select||' , :l_old_value old_value'||
555                        l_from||
556                        l_where||'AND EXISTS (SELECT ''x'' from
557                                              okc_contacts oco
558                                              WHERE oco.dnz_chr_id = okh.id
559                                              AND   oco.cro_code = ''RSC_GROUP''
560                                              AND   oco.jtot_object1_code = ''OKS_RSCGROUP''
561                                              AND   oco.object1_id1  = :p_ctr_rec_old_value)
562                                              AND   okh.id = to_number(:update_level_value)';
563           END IF;
564 
565  ---------------------------------------------------------------------------
566  -- Update Level : Contract , Attribute: Coverage Type(AGREEMENT_NAME)
567  ---------------------------------------------------------------------------
568       ELSIF p_ctr_rec.attribute = 'AGREEMENT_NAME' THEN
569 
570  -- Old Value: Other than NULL or ALL
571 
572              l_old_value := p_ctr_rec.old_value;
573              l_stmt := l_select||' , :l_old_value old_value'||
574                        l_from||
575                        l_where||'AND EXISTS (SELECT ''x'' from okc_governances_v ogv
576                                              WHERE ogv.dnz_chr_id = okh.id
577                                              AND   ogv.isa_agreement_id = :p_ctr_rec_old_value)
578                                              AND  okh.id = to_number(:update_level_value)';
579  ------------------------------------------------------------------------------
580  --  Update Level : Contract , Attribute: Product Alias (PRODUCT_ALIAS)
581  ------------------------------------------------------------------------------
582       ELSIF p_ctr_rec.attribute = 'PRODUCT_ALIAS' THEN
583 
584        -- Old Value: NULL (-9999)
585 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
586              l_stmt := l_select||' ,NULL old_value'||
587                        l_from||l_where||
588                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
589                                      WHERE cle.dnz_chr_id = okh.id
590                                      AND   cle.lse_id IN (7,8,9,10,11,18,25,35)
591                                      AND   cle.cognomen is NULL)
592                         AND okh.id = to_number(:update_level_value)';
593 
594        -- Old Value: ALL (-1111)
595           ELSIF p_ctr_rec.old_value = '-1111' THEN
596 
597              l_stmt := l_select||' ,NULL old_value'||
598                        l_from||l_where||
599                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
600                                      WHERE cle.dnz_chr_id = okh.id
601                                      AND   cle.lse_id IN (7,8,9,10,11,18,25,35))
602                         AND okh.id = to_number(:update_level_value)';
603 
604  -- Old Value: Other than NULL or ALL
605 
606           ELSE
607             --nerrorout_n('Here**********');
608             l_old_value := p_ctr_rec.old_value;
609             l_stmt := l_select||' , :l_old_value old_value'||
610                        l_from||l_where||
611                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
612                          WHERE cle.dnz_chr_id = okh.id
613                          AND   cle.lse_id IN (7,8,9,10,11,18,25,35)
614                          AND   cle.cognomen = :p_ctr_rec_old_value)
615                         AND okh.id = to_number(:update_level_value)';
616                         --errorout_n('Here**********' ||l_stmt);
617 
618           END IF;
619 
620  --------------------------------------------------------
621  --  Update Level : Contract , Attribute: Contract Line Ref(CONTRACT_LINE_REF)
622  --------------------------------------------------------
623       ELSIF p_ctr_rec.attribute = 'CONTRACT_LINE_REF' THEN
624 
625        -- Old Value: NULL (-9999)
626 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
627              l_stmt := l_select||' ,NULL old_value'||
628                        l_from||l_where||
629                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
630                                      WHERE cle.chr_id = okh.id
631                                      AND   cle.lse_id IN (1,12,14,19)
632                                      AND   cle.cognomen is NULL)
633                         AND okh.id = to_number(:update_level_value)';
634 
635        -- Old Value: ALL (-1111)
636 
637           ELSIF p_ctr_rec.old_value = '-1111' THEN
638              l_stmt := l_select||' ,NULL old_value'||
639                        l_from||l_where||
640                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
641                                      WHERE cle.chr_id = okh.id
642                                      AND   cle.lse_id IN (1,12,14,19))
643                                      AND okh.id = to_number(:update_level_value)';
644 
645  -- Old Value: Other than NULL or ALL
646 
647           ELSE
648 
649              l_old_value := p_ctr_rec.old_value;
650              l_stmt := l_select||' , :l_old_value old_value'||
651                        l_from||l_where||
652                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
653                                      WHERE cle.chr_id = okh.id
654                                      AND   cle.lse_id IN (1,12,14,19)
655                                      AND   cle.cognomen = :p_ctr_rec_old_value)
656                         AND okh.id = to_number(:update_level_value)';
657 
658           END IF;
659 
660    --------------------------------------------------------
661  --  Update Level : Contract , Attribute: Header Ship-to Address (HDR_SHIP_TO_ADDRESS)
662  --------------------------------------------------------
663       ELSIF p_ctr_rec.attribute = 'HDR_SHIP_TO_ADDRESS' THEN
664 
665        -- Old Value: NULL (-9999)
666 	     IF  p_ctr_rec.old_value = '-9999' THEN
667                  l_stmt := l_select||' ,NULL old_value' ||
668                            l_from||l_where||
669                                 ' AND  okh.ship_to_site_use_id is NULL
670                                   AND  okh.id = to_number(:p_ctr_rec_old_value) ';
671 
672         -- Old Value: Other than NULL or ALL
673 
674          ELSE
675                  l_stmt := l_select||' ,okh.ship_to_site_use_id old_value' ||
676                            l_from||l_where||
677                                    ' AND  okh.ship_to_site_use_id = to_number(:p_ctr_rec_old_value)
678                                      AND  okh.id = to_number(:p_ctr_rec_old_value) ';
679          END IF;
680 
681   --------------------------------------------------------
682  --  Update Level : Contract , Attribute: Header Bill-to Address(HDR_BILL_TO_ADDRESS)
683  --------------------------------------------------------
684       ELSIF p_ctr_rec.attribute = 'HDR_BILL_TO_ADDRESS' THEN
685 
686        -- Old Value: NULL (-9999)
687 	     IF  p_ctr_rec.old_value = '-9999' THEN
688                  l_stmt := l_select||' ,NULL old_value' ||
689                            l_from||l_where||
690                                    ' AND  okh.bill_to_site_use_id is NULL
691                                      AND  okh.id = to_number(:p_ctr_rec_old_value) ';
692        -- Old Value: Other than NULL or ALL
693 
694          ELSE
695                  l_stmt := l_select||' ,okh.bill_to_site_use_id old_value' ||
696                            l_from||l_where||
697                                    ' AND  okh.bill_to_site_use_id = to_number(:p_ctr_rec_old_value)
698                                      AND  okh.id = to_number(:p_ctr_rec_old_value) ';
699          END IF;
700 
701 
702  --------------------------------------------------------
703  --  Update Level : Contract , Attribute: Sales Rep (SALES_REP)
704  --------------------------------------------------------
705       ELSIF p_ctr_rec.attribute = 'SALES_REP' THEN
706 
707        -- Old Value: NULL (-9999)
708 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
709              l_stmt := l_select||' ,NULL old_value'||
710                        l_from||l_where||
711                        ' AND (EXISTS (Select ''x'' from okc_contacts oc
712                                          where oc.dnz_chr_id = okh.id
713                                          and   oc.cro_code = ''SALESPERSON''
714                                          and   oc.object1_id1 is null
715                                          and   oc.jtot_object1_code = ''OKX_SALEPERS'')
716                         OR EXISTS (Select ''x'' from oks_k_sales_credits_v osc
717                                    Where osc.chr_id = okh.id
718                                    and osc.ctc_id is NULL))
719                         AND okh.id = to_number(:update_level_value)';
720 
721        -- Old Value: ALL (-1111)
722 
723           ELSIF p_ctr_rec.old_value = '-1111' THEN
724 
725              l_stmt := l_select||' ,oc.object1_id1 old_value '||
726                        l_from||', okc_contacts oc '||
727                        l_where||' and oc.dnz_chr_id = okh.id
728                           and   oc.cro_code = ''SALESPERSON''
729                           and   oc.jtot_object1_code = ''OKX_SALEPERS''
730                        AND okh.id = to_number(:update_level_value)';
731 
732  -- Old Value: Other than NULL or ALL
733 
734           ELSE
735              l_old_value := p_ctr_rec.old_value;
736              l_stmt := l_select||' , :l_old_value old_value'||
737                        l_from||l_where||
738                        ' AND (EXISTS (Select ''x'' from okc_contacts oc
739                                          where oc.dnz_chr_id = okh.id
740                                          and   oc.cro_code = ''SALESPERSON''
741                                          and   oc.object1_id1=:p_ctr_rec_old_value
742                                          and   oc.jtot_object1_code = ''OKX_SALEPERS'')
743                         OR EXISTS (Select ''x'' from oks_k_sales_credits_v osc
744                                    Where osc.chr_id = okh.id
745                                    and osc.ctc_id = to_number(:p_ctr_rec_old_value)))
746                          AND  okh.id = to_number(:update_level_value)';
747 
748           END IF;
749 
750  ----------------------------------------------------------------------------------------
751  --  Update Level : Contract , Attribute: Party Shipping Contact (PARTY_SHIPPING_CONTACT)
752  ----------------------------------------------------------------------------------------
753       ELSIF p_ctr_rec.attribute = 'PARTY_SHIPPING_CONTACT' THEN
754 
755        -- Old Value: NULL (-9999)
756 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
757              l_stmt := l_select||' ,NULL old_value'||
758                        l_from||l_where||
759                        ' AND EXISTS (Select ''x'' from okc_contacts oc
760                                          where oc.dnz_chr_id = okh.id
761                                          and   oc.cro_code = ''SHIPPING''
762                                          and   oc.object1_id1 is null
763                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
764                         AND okh.id = to_number(:update_level_value)';
765 
766        -- Old Value: ALL (-1111)
767 
768           ELSIF p_ctr_rec.old_value = '-1111' THEN
769              l_stmt := l_select||' ,oc.object1_id1 old_value'||
770                        l_from||', okc_contacts oc '||
771                        l_where||
772                         ' and oc.dnz_chr_id = okh.id
773                           and   oc.cro_code = ''SHIPPING''
774                           and   oc.jtot_object1_code = ''OKX_PCONTACT'')
775                        AND okh.id = to_number(:update_level_value)';
776 
777  -- Old Value: Other than NULL or ALL
778 
779           ELSE
780 
781              l_old_value := p_ctr_rec.old_value;
782              l_stmt := l_select||' , :l_old_value old_value'||
783                        l_from||l_where||
784                        ' AND EXISTS (Select ''x'' from okc_contacts oc
785                                          where oc.dnz_chr_id = okh.id
786                                          and   oc.cro_code = ''SHIPPING''
787                                          and   oc.object1_id1=:p_ctr_rec_old_value
788                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
789                          AND  okh.id = to_number(:update_level_value)';
790 
791           END IF;
792 
793  --------------------------------------------------------------------------------------------
794  --  Update Level : Contract , Attribute: Party Billing Contact (PARTY_BILLING_CONTACT)
795  --------------------------------------------------------------------------------------------
796       ELSIF p_ctr_rec.attribute = 'PARTY_BILLING_CONTACT' THEN
797 
798        -- Old Value: NULL (-9999)
799 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
800              l_stmt := l_select||' ,NULL old_value'||
801                        l_from||l_where||
802                        ' AND EXISTS (Select ''x'' from okc_contacts oc
803                                          where oc.dnz_chr_id = okh.id
804                                          and   oc.cro_code = ''BILLING''
805                                          and   oc.object1_id1 is null
806                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
807                         AND okh.id = to_number(:update_level_value)';
808 
809        -- Old Value: ALL (-1111)
810 
811           ELSIF p_ctr_rec.old_value = '-1111' THEN
812              l_stmt := l_select||' ,oc.object1_id1 old_value'||
813                        l_from||', okc_contacts oc '||
814                        l_where||
815                         ' and oc.dnz_chr_id = okh.id
816                           and   oc.cro_code = ''BILLING''
817                           and   oc.jtot_object1_code = ''OKX_PCONTACT'')
818                        AND okh.id = to_number(:update_level_value)';
819 
820  -- Old Value: Other than NULL or ALL
821 
822           ELSE
823 
824              l_old_value := p_ctr_rec.old_value;
825              l_stmt := l_select||' , :l_old_value old_value'||
826                        l_from||l_where||
827                        ' AND EXISTS (Select ''x'' from okc_contacts oc
828                                          where oc.dnz_chr_id = okh.id
829                                          and   oc.cro_code = ''BILLING''
830                                          and   oc.object1_id1=:p_ctr_rec_old_value
831                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
832                          AND  okh.id = to_number(:update_level_value)';
833           END IF;
834 
835  ----------------------------------------------------------------------------------------
836  --  Update Level : Contract , Attribute: Party Shipping Contact (LINE_SHIPPING_CONTACT)
837  ----------------------------------------------------------------------------------------
838       ELSIF p_ctr_rec.attribute = 'LINE_SHIPPING_CONTACT' THEN
839 
840        -- Old Value: NULL (-9999)
841 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
842              l_stmt := l_select||' ,NULL old_value'||
843                        l_from||l_where||
844                        ' AND EXISTS (Select ''x'' from okc_contacts oc
845                                          where oc.dnz_chr_id = okh.id
846                                          and   oc.cro_code = ''CUST_SHIPPING''
847                                          and   oc.object1_id1 is null
848                                          and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
849                         AND okh.id = to_number(:update_level_value)';
850 
851        -- Old Value: ALL (-1111)
852 
853           ELSIF p_ctr_rec.old_value = '-1111' THEN
854              l_stmt := l_select||' ,oc.object1_id1 old_value'||
855                        l_from||', okc_contacts oc '||
856                        l_where||
857                         ' and oc.dnz_chr_id = okh.id
858                           and   oc.cro_code = ''CUST_SHIPPING''
859                           and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
860                        AND okh.id = to_number(:update_level_value)';
861 
862  -- Old Value: Other than NULL or ALL
863 
864           ELSE
865 
866              l_old_value := p_ctr_rec.old_value;
867              l_stmt := l_select||' , :l_old_value old_value'||
868                        l_from||l_where||
869                        ' AND EXISTS (Select ''x'' from okc_contacts oc
870                                          where oc.dnz_chr_id = okh.id
871                                          and   oc.cro_code = ''CUST_SHIPPING''
872                                          and   oc.object1_id1=:p_ctr_rec_old_value
873                                          and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
874                          AND  okh.id = to_number(:update_level_value)';
875 
876           END IF;
877 
878  --------------------------------------------------------------------------------------------
879  --  Update Level : Contract , Attribute: Party Billing Contact (LINE_BILLING_CONTACT)
880  --------------------------------------------------------------------------------------------
881       ELSIF p_ctr_rec.attribute = 'LINE_BILLING_CONTACT' THEN
882 
883        -- Old Value: NULL (-9999)
884 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
885              l_stmt := l_select||' ,NULL old_value'||
886                        l_from||l_where||
887                        ' AND EXISTS (Select ''x'' from okc_contacts oc
888                                          where oc.dnz_chr_id = okh.id
889                                          and   oc.cro_code = ''CUST_BILLING''
890                                          and   oc.object1_id1 is null
891                                          and   oc.jtot_object1_code = ''OKX_CONTBILL'')
892                         AND okh.id = to_number(:update_level_value)';
893 
894        -- Old Value: ALL (-1111)
895 
896           ELSIF p_ctr_rec.old_value = '-1111' THEN
897              l_stmt := l_select||' ,oc.object1_id1 old_value'||
898                        l_from||', okc_contacts oc '||
899                        l_where||
900                         ' and oc.dnz_chr_id = okh.id
901                           and   oc.cro_code = ''CUST_BILLING''
902                           and   oc.jtot_object1_code = ''OKX_CONTBILL'')
903                        AND okh.id = to_number(:update_level_value)';
904 
905  -- Old Value: Other than NULL or ALL
906 
907           ELSE
908 
909              l_old_value := p_ctr_rec.old_value;
910              l_stmt := l_select||' , :l_old_value old_value'||
911                        l_from||l_where||
912                        ' AND EXISTS (Select ''x'' from okc_contacts oc
913                                          where oc.dnz_chr_id = okh.id
914                                          and   oc.cro_code = ''CUST_BILLING''
915                                          and   oc.object1_id1 = :p_ctr_rec_old_value
916                                          and   oc.jtot_object1_code = ''OKX_CONTBILL'')
917                          AND  okh.id = to_number(:update_level_value)';
918           END IF;
919 
920 
921  --------------------------------------------------------
922  --  Update Level : Contract , Attribute: Coverage Time (COVERAGE_START_TIME)
923  --------------------------------------------------------
924       ELSIF p_ctr_rec.attribute = 'COVERAGE_START_TIME' THEN
925 
926        -- Old Value: NULL (-9999)
927 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
928              l_stmt := l_select||' ,NULL old_value'||
929                        l_from||l_where||
930                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
931                                          where oct.dnz_chr_id = okh.id
932                                          and   oct.start_hour is null
933                                          and   oct.start_minute is null)
934                         AND okh.id = to_number(:update_level_value)';
935 
936           ELSE
937 
938              l_old_value := p_ctr_rec.old_value;
939              l_stmt := l_select||' , :l_old_value old_value'||
940                        l_from||l_where||
941                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
942                                      where oct.dnz_chr_id = okh.id
943                                      and   oct.start_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
944                                      and   oct.start_minute = mod(to_number(:p_ctr_rec_old_value),60))
945                          AND  okh.id = to_number(:update_level_value)';
946           END IF;
947 
948 --------------------------------------------------------
949  --  Update Level : Contract , Attribute: Coverage Time (COVERAGE_END_TIME)
950  --------------------------------------------------------
951       ELSIF p_ctr_rec.attribute = 'COVERAGE_END_TIME' THEN
952 
953        -- Old Value: NULL (-9999)
954 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
955              l_stmt := l_select||' ,NULL old_value'||
956                        l_from||l_where||
957                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
958                                          where oct.dnz_chr_id = okh.id
959                                          and   oct.end_hour is null
960                                          and   oct.end_minute is null)
961                         AND okh.id = to_number(:update_level_value)';
962 
963           ELSE
964 
965              l_old_value := p_ctr_rec.old_value;
966              l_stmt := l_select||' , :l_old_value old_value'||
967                        l_from||l_where||
968                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
969                                      where oct.dnz_chr_id = okh.id
970                                      and   oct.end_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
971                                      and   oct.end_minute = mod(to_number(:p_ctr_rec_old_value),60))
972                          AND  okh.id = to_number(:update_level_value)';
973           END IF;
974 
975  --------------------------------------------------------
976  --  Update Level : Contract , Attribute: Resolution Time (RESOLUTION_TIME)
977  --------------------------------------------------------
978       ELSIF p_ctr_rec.attribute = 'RESOLUTION_TIME'   THEN
979 
980        -- Old Value: NULL (-9999)
981 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
982              l_stmt := l_select||', NULL old_value'||
983                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '|| l_where||
984                        ' AND kl.dnz_chr_id = okh.id
985 		         AND kl.id = att.cle_id
986                          And kl.lse_id in (4,17,22)
987                          AND   att.action_type_code = ''RSN''
988                          AND   att.id = oat.cov_action_type_id
989                          AND   ( sun_duration IS NULL
990                                  OR mon_duration IS NULL
991                                  OR tue_duration IS NULL
992                                  OR wed_duration IS NULL
993                                  OR thu_duration IS NULL
994                                  OR fri_duration IS NULL
995                                  OR sat_duration IS NULL)
996                         AND okh.id = to_number(:update_level_value)';
997 
998  -- Old Value: Other than NULL or ALL
999           ELSE
1000 
1001             l_old_value := p_ctr_rec.old_value;
1002             l_stmt := l_select||' , :l_old_value old_value'||
1003                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '||l_where||
1004                        ' AND kl.dnz_chr_id = okh.id
1005 		         AND kl.id = att.cle_id
1006                          And kl.lse_id in (4,17,22)
1007                          AND   att.action_type_code = ''RSN''
1008                          AND   att.id = oat.cov_action_type_id
1009                          AND   ( sun_duration = :p_ctr_rec_old_value
1010                                                OR mon_duration = :p_ctr_rec_old_value
1011                                                OR tue_duration = :p_ctr_rec_old_value
1012                                                OR wed_duration = :p_ctr_rec_old_value
1013                                                OR thu_duration = :p_ctr_rec_old_value
1014                                                OR fri_duration = :p_ctr_rec_old_value
1015                                                OR sat_duration = :p_ctr_rec_old_value)
1016                         AND okh.id = to_number(:update_level_value)';
1017           END IF;
1018 
1019  --------------------------------------------------------
1020  --  Update Level : Contract , Attribute: Reaction Time (REACTION_TIME)
1021  --------------------------------------------------------
1022       ELSIF p_ctr_rec.attribute = 'REACTION_TIME' THEN
1023 
1024    -- Old Value: NULL (-9999)
1025 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1026                        l_stmt := l_select||', NULL old_value'||
1027                          l_from||', okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '||l_where||
1028                        '  AND kl.dnz_chr_id = okh.id
1029                           AND kl.id = att.cle_id
1030                           And kl.lse_id in (4,17,22)
1031                          AND   att.action_type_code = ''RCN''
1032                          AND   att.id = oat.cov_action_type_id
1033                          AND   ( sun_duration IS NULL
1034                                                OR mon_duration IS NULL
1035                                                OR tue_duration IS NULL
1036                                                OR wed_duration IS NULL
1037                                                OR thu_duration IS NULL
1038                                                OR fri_duration IS NULL
1039                                                OR sat_duration IS NULL)
1040                         AND  okh.id = to_number(:update_level_value)';
1041  -- Old Value: Other than NULL or ALL
1042 
1043           ELSE
1044 
1045              l_old_value := p_ctr_rec.old_value;
1046              l_stmt := l_select||' , :l_old_value old_value'||
1047                       l_from||', okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '||l_where||
1048                        '  AND kl.dnz_chr_id = okh.id
1049                           AND kl.id = att.cle_id
1050                           And kl.lse_id in (4,17,22)
1051                          AND   att.action_type_code = ''RCN''
1052                          AND   att.id = oat.cov_action_type_id
1053                          AND   ( sun_duration = :p_ctr_rec_old_value
1054                                                OR mon_duration = :p_ctr_rec_old_value
1055                                                OR tue_duration = :p_ctr_rec_old_value
1056                                                OR wed_duration = :p_ctr_rec_old_value
1057                                                OR thu_duration = :p_ctr_rec_old_value
1058                                                OR fri_duration = :p_ctr_rec_old_value
1059                                                OR sat_duration = :p_ctr_rec_old_value)
1060                         AND  okh.id = to_number(:update_level_value)';
1061 
1062           END IF;
1063 
1064  --------------------------------------------------------
1065  --  Update Level : Contract , Attribute: Price List(PRICE_LIST)
1066  --------------------------------------------------------
1067       ELSIF p_ctr_rec.attribute = 'PRICE_LIST' THEN
1068 
1069        -- Old Value: NULL (-9999)
1070 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1071 
1072               l_stmt := l_select||' ,NULL old_value'||
1073                         l_from||l_where||
1074                          ' AND  okh.price_list_id is NULL
1075                            AND  okh.id = to_number(:update_level_value) ';
1076 
1077        -- Old Value: ALL (-1111)
1078 
1079           ELSIF p_ctr_rec.old_value = '-1111' THEN
1080 
1081              l_stmt := l_select||' ,okh.price_list_id old_value' ||
1082                          l_from||l_where||
1083                          ' AND  okh.id = to_number(:update_level_value) ';
1084 
1085 
1086           ELSE
1087 
1088              l_stmt := l_select||' ,okh.price_list_id old_value' ||
1089                        l_from||l_where||
1090                        ' AND  okh.price_list_id = to_number(:p_ctr_rec_old_value)
1091                          AND  okh.id = to_number(:update_level_value) ';
1092 
1093           END IF;
1094 
1095  --------------------------------------------------------
1096  --  Update Level : Contract , Attribute: Known As(CONTRACT_ALIAS)
1097  --------------------------------------------------------
1098       ELSIF p_ctr_rec.attribute = 'CONTRACT_ALIAS' THEN
1099 
1100        -- Old Value: NULL (-9999)
1101 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1102              l_stmt := l_select||' ,NULL old_value'||
1103                        l_from||l_where||
1104                        ' AND okh.cognomen is null
1105                         AND okh.id = :update_level_value ' ;
1106 
1107        -- Old Value: ALL (-1111)
1108 
1109           ELSIF p_ctr_rec.old_value = '-1111' THEN
1110 
1111              l_stmt := l_select||' ,okh.cognomen old_value'||
1112                        l_from||l_where||
1113                        ' AND okh.id = :update_level_value ' ;
1114 
1115  -- Old Value: Other than NULL or ALL
1116 
1117           ELSE
1118 
1119              l_stmt := l_select||', okh.cognomen old_value'||
1120                        l_from||l_where||
1121                        '  AND okh.cognomen = :p_ctr_rec_old_value
1122                         AND okh.id = :update_level_value';
1123 
1124           END IF;
1125 
1126  --------------------------------------------------------
1127  --  Update Level : Contract , Attribute: PO NUMBER(PO_NUMBER_BILL)
1128  --------------------------------------------------------
1129       ELSIF p_ctr_rec.attribute = 'PO_NUMBER_BILL' THEN
1130 
1131        -- Old Value: NULL (-9999)
1132 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1133              l_stmt := l_select||' ,NULL old_value'||
1134                        l_from||l_where||
1135                        ' AND okh.cust_po_number is null
1136                          AND ( okh.payment_instruction_type  Is Null Or okh.payment_instruction_type = ''PON'')
1137                         AND okh.id = :update_level_value ' ;
1138 
1139        -- Old Value: ALL (-1111)
1140 
1141           ELSIF p_ctr_rec.old_value = '-1111' THEN
1142             If p_ctr_rec.new_value is Null Then
1143              l_stmt := l_select||' ,okh.cust_po_number old_value'||
1144                        l_from||l_where||
1145                        ' AND okh.payment_instruction_type = ''PON''
1146                          AND okh.id = :update_level_value And okh.cust_po_number_req_yn <> ''Y''' ;
1147             Else
1148 
1149 	                 l_stmt := l_select||' ,okh.cust_po_number old_value'||
1150                        l_from||l_where||
1151                        ' AND okh.payment_instruction_type = ''PON''
1152                          AND okh.id = :update_level_value ' ;
1153             End If;
1154  -- Old Value: Other than NULL or ALL
1155 
1156           ELSE
1157 	     If p_ctr_rec.new_value is Null Then
1158 
1159 
1160              l_stmt := l_select||', okh.cust_po_number old_value'||
1161                        l_from||l_where||
1162                        '  AND okh.cust_po_number = :p_ctr_rec_old_value
1163                           AND okh.payment_instruction_type = ''PON''
1164                         AND okh.id = :update_level_value And okh.cust_po_number_req_yn <>
1165 			''Y''';
1166 
1167 	   Else
1168 	   l_stmt := l_select||', okh.cust_po_number old_value'||
1169                        l_from||l_where||
1170                        '  AND okh.cust_po_number = :p_ctr_rec_old_value
1171                           AND okh.payment_instruction_type = ''PON''
1172                         AND okh.id = :update_level_value';
1173 	   End If;
1174 
1175           END IF;
1176 
1177  -----------------------------------------------------------------------------
1178  --  Update Level : Contract , Attribute: PO NUMBER Required(PO_REQUIRED_REN)
1179  -----------------------------------------------------------------------------
1180       ELSIF p_ctr_rec.attribute = 'PO_REQUIRED_REN' THEN
1181 
1182 
1183            IF p_ctr_rec.old_value = '-1111' THEN
1184 
1185              l_old_value := p_ctr_rec.old_value;
1186              l_stmt := l_select||' , :l_old_value old_value'||
1187                        l_from||l_where||
1188                        'AND okh.id = :update_level_value';
1189 
1190      -- Old Value: Other than NULL or ALL
1191            ELSE
1192              l_old_value := p_ctr_rec.old_value;
1193              l_stmt := l_select||' , :l_old_value old_value'||
1194                         l_from||' ,oks_k_headers_v oksh '||
1195                         l_where||' AND oksh.chr_id = okh.id
1196                                    AND nvl(oksh.renewal_po_required,''N'') = :p_ctr_rec_old_value
1197                                    AND okh.id = to_number(:update_level_value)';
1198            END IF ;
1199 
1200  --------------------------------------------------------
1201  --  Update Level : Contract , Attribute: Summary Print(SUMMARY_PRINT)
1202  --------------------------------------------------------
1203       ELSIF p_ctr_rec.attribute = 'SUMMARY_PRINT' THEN
1204 
1205        -- Old Value: All (-1111)
1206 
1207         IF p_ctr_rec.old_value = '-1111' THEN
1208             l_old_value := p_ctr_rec.old_value;
1209             l_stmt := l_select||' , :l_old_value old_value'||
1210                       l_from||' ,oks_k_headers_v oksh '||
1211                       l_where||' AND oksh.chr_id = okh.id
1212                                  AND okh.id = :update_level_value';
1213 
1214       -- Old Value: Other than NULL or ALL
1215         ELSE
1216               l_old_value := p_ctr_rec.old_value;
1217               l_stmt := l_select||' , :l_old_value old_value'||
1218                         l_from||' ,oks_k_headers_v oksh '||
1219                         l_where||' AND oksh.chr_id = okh.id
1220                                    AND nvl(oksh.inv_print_profile,''N'') = :p_ctr_rec_old_value
1221                                    AND okh.id = to_number(:update_level_value)';
1222 
1223         END IF ;
1224 
1225  -------------------------------------------------------------------------
1226  --  Update Level : Contract , Attribute: Contract Group (CONTRACT_GROUP)
1227  --------------------------------------------------------------------------
1228       ELSIF p_ctr_rec.attribute = 'CONTRACT_GROUP' THEN
1229 
1230 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1231              l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
1232                        l_from||',okc_k_groups_grpings_v okg'||
1233                        l_where||' AND okg.included_chr_id = okh.id
1234      					          AND okg.cgp_parent_id is NULL
1235      					          AND okh.id = to_number(:update_level_value)';
1236 --/*
1237 --             l_stmt := l_select||' ,NULL old_value'||
1238 --                       l_from||l_where||
1239 --                       'AND EXISTS (SELECT id from okc_k_headers_v a
1240 --                                    WHERE a.id = okh.id
1241 --                                    MINUS
1242 --                                    SELECT okg.included_chr_id
1243 --                                    FROM okc_k_groups_grpings_v okg
1244 --									WHERE okg.included_chr_id = okh.id)
1245 --                       AND okh.id = '||to_number(p_ctr_rec.update_level_value);
1246 --*/
1247 
1248           ELSIF p_ctr_rec.old_value = '-1111' THEN
1249              l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
1250                        l_from||',okc_k_groups_grpings_v okg'||
1251                        l_where||' AND okg.included_chr_id = okh.id
1252                        AND okh.id = to_number(:update_level_value)';
1253 
1254           ELSE
1255              l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
1256                        l_from||',okc_k_groups_grpings_v okg'||
1257                        l_where||' AND okg.included_chr_id = okh.id
1258      					          AND okg.cgp_parent_id = to_number(:p_ctr_rec_old_value)
1259      					          AND okh.id = to_number(:update_level_value)';
1260 
1261           END IF;
1262 
1263  ------------------------------------------------------------------------------------------
1264  --  Update Level : Contract , Attribute: Contract Start date (CONTRACT_START_DATE)
1265  ------------------------------------------------------------------------------------------
1266 
1267       ELSIF p_ctr_rec.attribute = 'CONTRACT_START_DATE' Then
1268 
1269           IF p_ctr_rec.old_value is NULL THEN   -- For Contract Start date as NULL
1270              l_stmt := l_select||',to_char(okh.start_date) old_value'||
1271                        l_from||
1272                        l_where||' AND okh.start_date is NULL
1273      					          AND okh.id = to_number(:update_level_value)';
1274 
1275           ELSIF p_ctr_rec.old_value is not NULL THEN   -- For Contract Start date not NULL
1276              l_stmt := l_select||',to_char(okh.start_date) old_value'||
1277                        l_from||
1278                        l_where||' AND trunc(okh.start_date) = trunc(to_date(:p_ctr_rec_old_value,''YYYY/MM/DD HH24:MI:SS''))
1279      					          AND okh.id = to_number(:update_level_value)';
1280           END IF;
1281  ------------------------------------------------------------------------------------------
1282  --  Update Level : Contract , Attribute: Contract End date (CONTRACT_END_DATE)
1283  ------------------------------------------------------------------------------------------
1284 
1285       ELSIF UPPER(p_ctr_rec.attribute) = UPPER('CONTRACT_END_DATE') Then
1286 
1287           IF p_ctr_rec.old_value is NULL THEN   -- For Contract End date as NULL
1288              l_stmt := l_select||',to_char(okh.end_date) old_value'||
1289                        l_from||
1290                        l_where||' AND okh.end_date is NULL
1291      					          AND okh.id = to_number(:update_level_value)';
1292 
1293           ELSIF p_ctr_rec.old_value is not NULL THEN   -- For Contract End date not NULL
1294              l_stmt := l_select||',to_char(okh.end_date) old_value'||
1295                        l_from||
1296                        l_where||' AND trunc(okh.end_date) = trunc(to_date(:p_ctr_rec_old_value,''YYYY/MM/DD HH24:MI:SS''))
1297      					          AND okh.id = to_number(:update_level_value)';
1298           END IF;
1299 
1300       END IF;
1301 
1302 -----------------------------------
1303  --  Update Level : ORGANIZATION
1304  -----------------------------------
1305 
1306  ELSIF p_ctr_rec.update_level = 'OKX_OPERUNIT' THEN --'ORGANIZATION' THEN
1307 
1308 
1309  ---------------------------------------------------------
1310  --  Update Level : Organization , Attribute: Revenue Account (REV_ACCT)
1311  --------------------------------------------------------
1312       IF p_ctr_rec.attribute = 'REV_ACCT' THEN
1313 
1314        -- Old Value: NULL (-9999)
1315 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1316              l_stmt := l_select||' ,NULL old_value'||
1317                        l_from||l_where||
1318                        ' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
1319                                      WHERE rev.chr_id = okh.id
1320                                      AND   rev.code_combination_id is NULL)
1321                         AND okh.org_id = to_number(:update_level_value)';
1322 
1323        -- Old Value: ALL (-1111)
1324 
1325           ELSIF p_ctr_rec.old_value = '-1111' THEN
1326 
1327              l_stmt := l_select||' ,NULL old_value'||
1328                        l_from||l_where||
1329                        ' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
1330                                      WHERE rev.chr_id = okh.id)
1331                         AND okh.org_id = to_number(:update_level_value)';
1332 
1333  -- Old Value: Other than NULL or ALL
1334 
1335           ELSE
1336 
1337              l_old_value := p_ctr_rec.old_value;
1338              l_stmt := l_select||' , :l_old_value old_value'||
1339                        l_from||l_where||
1340                        ' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
1341                                      WHERE rev.chr_id = okh.id
1342                                      AND   rev.code_combination_id  = to_number(:p_ctr_rec_old_value))
1343                         AND okh.org_id = to_number(:update_level_value)';
1344 
1345           END IF;
1346 
1347  ---------------------------------------------------------
1348  --  Update Level : Organization, Attribute: Payment Term (PAYMENT_TERM)
1349  --------------------------------------------------------
1350 
1351        ELSIF p_ctr_rec.attribute = 'PAYMENT_TERM' THEN
1352 
1353        -- Old Value: NULL (-9999)
1354 
1355    	     IF    p_ctr_rec.old_value = '-9999' THEN
1356 
1357                        l_stmt := l_select||' ,NULL old_value' ||
1358                        l_from||l_where||
1359                        ' AND  okh.PAYMENT_TERM_ID is NULL
1360                          AND okh.org_id = to_number(:update_level_value)';
1361        -- Old Value: ALL (-1111)
1362          ELSIF p_ctr_rec.old_value = '-1111' THEN
1363                        l_stmt := l_select||' ,okh.payment_term_id old_value' ||
1364                        l_from||l_where||
1365                                'AND okh.org_id = to_number(:update_level_value)';
1366        -- Old Value: Other than NULL or ALL
1367 
1368           ELSE
1369 
1370              l_stmt := l_select||' ,okh.payment_term_id old_value' ||
1371                        l_from||l_where||
1372                        ' AND  okh.payment_term_id = to_number(:p_ctr_rec_old_value)
1373                          AND okh.org_id = to_number(:update_level_value)';
1374 
1375           END IF;
1376 
1377 -------------------------------------------------------------------------------------
1378  --  Update Level : Organization , Attribute: Contract Renewal Type(CON_RENEWAL_TYPE)
1379 ------------------------------------------------------------------------------------
1380       ELSIF p_ctr_rec.attribute = 'CON_RENEWAL_TYPE' THEN
1381 
1382        -- Old Value: NULL (-9999)
1383 	     IF    p_ctr_rec.old_value = '-9999' THEN
1384 
1385                        l_stmt := l_select||' ,NULL old_value' ||
1386                        l_from||
1387                        l_where||
1388                        ' AND  okh.renewal_type_code is NULL
1389                          AND not exists(
1390                                         select ol.object_chr_id
1391                                         from okc_operation_lines ol
1392                                             ,okc_operation_instances oi
1393                                             ,okc_class_operations co
1394                                         WHERE ol.object_chr_id = okh.id
1395                                           AND ol.process_flag = ''P''
1396                                           AND ol.ACTIVE_YN    = ''Y''
1397                                           AND oi.id = ol.oie_id
1398                                           AND oi.cop_id = co.id
1399                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
1400                                           AND co.CLS_CODE = ''SERVICE'')
1401                          AND okh.org_id = to_number(:update_level_value)';
1402 
1403          ELSIF p_ctr_rec.old_value = '-1111' THEN
1404                        l_old_value := p_ctr_rec.old_value;
1405                        l_stmt := l_select||' , :l_old_value old_value' ||
1406                        l_from||
1407                        l_where||
1408                              ' AND not exists(
1409                                         select ol.object_chr_id
1410                                         from okc_operation_lines ol
1411                                             ,okc_operation_instances oi
1412                                             ,okc_class_operations co
1413                                         WHERE ol.object_chr_id = okh.id
1414                                           AND ol.process_flag = ''P''
1415                                           AND ol.ACTIVE_YN    = ''Y''
1416                                           AND oi.id = ol.oie_id
1417                                           AND oi.cop_id = co.id
1418                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
1419                                           AND co.CLS_CODE = ''SERVICE'')
1420                                 AND okh.org_id = to_number(:update_level_value)';
1421 
1422  -- Old Value: ERN
1423 
1424           ELSIF p_ctr_rec.old_value = 'ERN' then
1425 
1426              l_old_value := p_ctr_rec.old_value;
1427              l_stmt := l_select||' , :l_old_value old_value' ||
1428                        l_from||' ,oks_k_headers_b oksh'||
1429                        l_where||
1430                        ' AND oksh.chr_id = okh.id
1431                         AND  okh.renewal_type_code = ''NSR''
1432                         AND ''ERN'' = :p_ctr_rec_old_value
1433                         AND oksh.ELECTRONIC_RENEWAL_FLAG =''Y''
1434                          AND not exists(
1435                                         select ol.object_chr_id
1436                                         from okc_operation_lines ol
1437                                             ,okc_operation_instances oi
1438                                             ,okc_class_operations co
1439                                         WHERE ol.object_chr_id = okh.id
1440                                           AND ol.process_flag = ''P''
1441                                           AND ol.ACTIVE_YN    = ''Y''
1442                                           AND oi.id = ol.oie_id
1443                                           AND oi.cop_id = co.id
1444                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
1445                                           AND co.CLS_CODE = ''SERVICE'')
1446                          AND okh.org_id = to_number(:update_level_value)';
1447 
1448  -- Old Value: Other than NULL or ALL
1449 
1450           ELSE
1451              l_old_value := p_ctr_rec.old_value;
1452              l_stmt := l_select||' , :l_old_value old_value' ||
1453                        l_from||' ,oks_k_headers_b oksh'||
1454                        l_where||
1455                        ' AND oksh.chr_id = okh.id
1456                         AND  okh.renewal_type_code = :p_ctr_rec_old_value
1457                         AND   nvl(oksh.ELECTRONIC_RENEWAL_FLAG,''N'') <> ''Y''
1458                          AND not exists(
1459                                         select ol.object_chr_id
1460                                         from okc_operation_lines ol
1461                                             ,okc_operation_instances oi
1462                                             ,okc_class_operations co
1463                                         WHERE ol.object_chr_id = okh.id
1464                                           AND ol.process_flag = ''P''
1465                                           AND ol.ACTIVE_YN    = ''Y''
1466                                           AND oi.id = ol.oie_id
1467                                           AND oi.cop_id = co.id
1468                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
1469                                           AND co.CLS_CODE = ''SERVICE'')
1470                          AND okh.org_id = to_number(:update_level_value)';
1471           END IF;
1472 
1473  ---------------------------------------------------------------------------
1474  --  Update Level : Organization , Attribute: Business Process Price List (BP_PRICE_LIST)
1475  ---------------------------------------------------------------------------
1476       ELSIF p_ctr_rec.attribute = 'BP_PRICE_LIST' THEN
1477 
1478      -- Old Value: NULL (-9999)
1479 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1480               l_stmt := l_select||' ,NULL old_value' ||
1481                         l_from||
1482                         l_where|| 'AND exists ( Select dnz_chr_id from okc_k_lines_b cln
1483                                           Where cln.dnz_chr_id = okh.id
1484                                             AND cln.lse_id in(3,16,21)
1485                                             AND cln.price_list_id is NULL)
1486                                    AND okh.org_id = to_number(:update_level_value)';
1487 
1488      -- Old Value: ALL (-1111)
1489           ELSIF p_ctr_rec.old_value = '-1111' THEN
1490              l_old_value := p_ctr_rec.old_value;
1491              l_stmt := l_select||' , :l_old_value old_value' ||
1492                        l_from||
1493                        l_where|| ' AND exists ( Select dnz_chr_id from okc_k_lines_b cln
1494                                           Where cln.dnz_chr_id = okh.id
1495                                             AND cln.lse_id in(3,16,21))
1496                                    AND okh.org_id = to_number(:update_level_value)';
1497 
1498      -- Old Value: Other than NULL or ALL
1499           ELSE
1500              l_old_value := p_ctr_rec.old_value;
1501              l_stmt := l_select||' , :l_old_value old_value' ||
1502                        l_from||
1503                        l_where|| ' AND exists ( Select dnz_chr_id from okc_k_lines_b cln
1504                                       Where cln.dnz_chr_id = okh.id
1505                                       AND cln.lse_id in(3,16,21)
1506                                       AND cln.price_list_id = to_number(:p_ctr_rec_old_value))
1507                                   AND okh.org_id = to_number(:update_level_value)';
1508 
1509           END IF;
1510 
1511 
1512  ---------------------------------------------------------
1513  --  Update Level : Organization, Attribute: Accounting Rule (ACCT_RULE)
1514  --------------------------------------------------------
1515 
1516        ELSIF p_ctr_rec.attribute = 'ACCT_RULE' THEN
1517 
1518       -- Old Value: NULL (-9999)
1519 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1520 
1521               l_stmt := l_select||' ,NULL old_value' ||
1522                         l_from||' ,oks_k_headers_v oksh '||
1523                         l_where|| 'AND oksh.chr_id = okh.id
1524                                    AND oksh.acct_rule_id IS NULL
1525                                    AND okh.org_id = to_number(:update_level_value)';
1526      -- Old Value: ALL (-1111)
1527 
1528           ELSIF p_ctr_rec.old_value = '-1111' THEN
1529              l_stmt := l_select||' ,oksh.acct_rule_id old_value' ||
1530                        l_from||' ,oks_k_headers_v oksh '||
1531                        l_where|| 'AND oksh.chr_id = okh.id
1532                                   AND okh.org_id = to_number(:update_level_value)';
1533      -- Old Value: Other than NULL or ALL
1534 
1535           ELSE
1536              l_stmt := l_select||' ,oksh.acct_rule_id old_value' ||
1537                        l_from||' ,oks_k_headers_v oksh '||
1538                        l_where|| 'AND oksh.chr_id = okh.id
1539                                   AND oksh.acct_rule_id = to_number(:p_ctr_rec_old_value)
1540                                   AND okh.org_id = to_number(:update_level_value)';
1541           END IF;
1542 
1543  ---------------------------------------------------------
1544  --  Update Level : Organization, Attribute: Invoice Rule (INV_RULE)
1545  --------------------------------------------------------
1546 
1547        ELSIF p_ctr_rec.attribute = 'INV_RULE' THEN
1548 
1549        -- Old Value: NULL (-9999)
1550          IF  p_ctr_rec.old_value = '-9999' THEN
1551 
1552              l_stmt := l_select||' ,NULL old_value' ||
1553                        l_from||l_where||
1554                              ' AND  okh.inv_rule_id IS NULL
1555                                AND  okh.org_id = to_number(:update_level_value)';
1556 
1557          ELSIF p_ctr_rec.old_value = '-1111' THEN
1558              l_stmt := l_select||' ,okh.inv_rule_id old_value' ||
1559                        l_from||l_where||
1560                              ' AND  okh.org_id = to_number(:update_level_value)';
1561 
1562        -- Old Value: Other than NULL or ALL
1563 
1564           ELSE
1565              l_stmt := l_select||' ,okh.inv_rule_id old_value' ||
1566                        l_from||l_where||
1567                              ' AND  okh.inv_rule_id = to_number(:p_ctr_rec_old_value)
1568                                AND  okh.org_id = to_number(:update_level_value)';
1569 
1570           END IF;
1571 ---------------------------------------------------------------------------
1572  --  Update Level : Organization , Attribute: Coverage Type(COV_TYPE)
1573  ---------------------------------------------------------------------------
1574       ELSIF p_ctr_rec.attribute = 'COV_TYPE' THEN
1575 
1576         -- Old Value: NULL (-9999)
1577 	     IF p_ctr_rec.old_value = '-9999' THEN
1578              l_stmt := l_select||' ,NULL old_value'||
1579                        l_from||l_where||
1580                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V okl, oks_k_lines_v oksl
1581                                              WHERE okl.dnz_chr_id = okh.id
1582                                              AND oksl.cle_id = okl.id
1583                                              AND oksl.coverage_type is NULL )
1584                         AND  okh.org_id = to_number(:update_level_value)';
1585 
1586         -- Old Value: ALL
1587 
1588           ELSIF p_ctr_rec.old_value = '-1111' THEN
1589 
1590                 l_old_value := p_ctr_rec.old_value;
1591                 l_stmt := l_select||' , :l_old_value old_value'||
1592                           l_from||
1593                           l_where||'AND EXISTS (SELECT ''x'' from okc_k_lines_v okl, oks_k_lines_v oksl
1594                                     WHERE okl.dnz_chr_id = okh.id
1595                                     AND oksl.cle_id = okl.id )
1596                         AND  okh.org_id = to_number(:update_level_value)';
1597          -- Old Value: Other than NULL or ALL
1598           ELSE
1599                  l_old_value := p_ctr_rec.old_value;
1600                  l_stmt := l_select||' , :l_old_value old_value'||
1601                            l_from||
1602                            l_where||'AND EXISTS (SELECT ''x'' from okc_k_lines_v okl, oks_k_lines_v oksl
1603                                      WHERE okl.dnz_chr_id = okh.id
1604                                      AND oksl.cle_id = okl.id
1605                                      AND oksl.coverage_type = :p_ctr_rec_old_value )
1606                          AND  okh.org_id = to_number(:update_level_value)';
1607 
1608           END IF;
1609 
1610 
1611  ---------------------------------------------------------------------------
1612  --  Update Level : Organization , Attribute: Coverage Type(COV_TIMEZONE)
1613  ---------------------------------------------------------------------------
1614       ELSIF p_ctr_rec.attribute = 'COV_TIMEZONE' THEN
1615 
1616        -- Old Value: NULL (-9999)
1617 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1618              l_stmt := l_select||' ,NULL old_value'||
1619                        l_from||l_where||
1620                        ' AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
1621                                       WHERE ctz.dnz_chr_id = okh.id
1622                                       AND   ctz.timezone_id IS NULL )
1623                          AND  okh.org_id = to_number(:update_level_value)';
1624 
1625        -- Old Value: ALL (-1111)
1626           ELSIF p_ctr_rec.old_value = '-1111' THEN
1627 
1628              l_old_value := p_ctr_rec.old_value;
1629              l_stmt := l_select||' , :l_old_value old_value'||
1630                        l_from||
1631                        l_where||'AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
1632                                              WHERE ctz.dnz_chr_id = okh.id
1633                                              AND   ctz.timezone_id IS NOT NULL )
1634                                              AND  okh.org_id = to_number(:update_level_value)';
1635         -- Old Value: Other than NULL or ALL
1636           ELSE
1637 
1638              l_old_value := p_ctr_rec.old_value;
1639              l_stmt := l_select||' , :l_old_value old_value'||
1640                        l_from||
1641                        l_where||'AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
1642                                              WHERE ctz.dnz_chr_id = okh.id
1643                                              AND  ctz.timezone_id = to_number(:p_ctr_rec_old_value))
1644                                              AND  okh.org_id = to_number(:update_level_value)';
1645 
1646           END IF;
1647 
1648  ---------------------------------------------------------------------------
1649  --  Update Level : Organization , Attribute: Coverage Type(PREF_ENGG)
1650  ---------------------------------------------------------------------------
1651       ELSIF p_ctr_rec.attribute = 'PREF_ENGG' THEN
1652 
1653 
1654           IF p_ctr_rec.old_value = '-1111' THEN
1655 
1656                 l_old_value := p_ctr_rec.old_value;
1657                 l_stmt := l_select||' , :l_old_value old_value'||
1658                        l_from||
1659                        l_where||'AND EXISTS (SELECT ''x'' from
1660                                              okc_contacts oco
1661                                              WHERE oco.dnz_chr_id = okh.id
1662                                              AND   oco.cro_code = ''ENGINEER''
1663                                              AND   oco.jtot_object1_code = ''OKX_RESOURCE'')
1664                                              AND   okh.org_id = to_number(:update_level_value)';
1665                                  --            AND   oco.object1_id1  = '''||p_ctr_rec.old_value||''')
1666                                  --            AND  okh.id = '||to_number(p_ctr_rec.update_level_value) ;
1667 
1668           ELSE
1669              l_old_value := p_ctr_rec.old_value;
1670              l_stmt := l_select||' , :l_old_value old_value'||
1671                        l_from||
1672                        l_where||'AND EXISTS (SELECT ''x'' from
1673                                              okc_contacts oco
1674                                              WHERE oco.dnz_chr_id = okh.id
1675                                              AND   oco.cro_code = ''ENGINEER''
1676                                              AND   oco.jtot_object1_code = ''OKX_RESOURCE''
1677                                              AND   oco.object1_id1  = :p_ctr_rec_old_value)
1678                                              AND   okh.org_id = to_number(:update_level_value)';
1679 --                                             AND  okh.id = '||to_number(p_ctr_rec.update_level_value) ;
1680           END IF;
1681  ---------------------------------------------------------------------------
1682  --  Update Level : Organization , Attribute: Coverage Type(RES_GROUP)
1683  ---------------------------------------------------------------------------
1684       ELSIF p_ctr_rec.attribute = 'RES_GROUP' THEN
1685 
1686          IF p_ctr_rec.old_value = '-1111' THEN
1687 
1688              l_old_value := p_ctr_rec.old_value;
1689              l_stmt := l_select||' , :l_old_value old_value'||
1690                        l_from||
1691                        l_where||'AND EXISTS (SELECT ''x'' from
1692                                              okc_contacts oco
1693                                              WHERE oco.dnz_chr_id = okh.id
1694                                              AND   oco.cro_code = ''RSC_GROUP''
1695                                              AND   oco.jtot_object1_code = ''OKS_RSCGROUP'')
1696                                              AND   okh.org_id = to_number(:update_level_value)';
1697                                  --            AND   oco.object1_id1  = '''||p_ctr_rec.old_value||''')
1698                                  --            AND  okh.id = '||to_number(p_ctr_rec.update_level_value) ;
1699 
1700           ELSE
1701              l_old_value := p_ctr_rec.old_value;
1702              l_stmt := l_select||' , :l_old_value old_value'||
1703                        l_from||
1704                        l_where||'AND EXISTS (SELECT ''x'' from
1705                                              okc_contacts oco
1706                                              WHERE oco.dnz_chr_id = okh.id
1707                                              AND   oco.cro_code = ''RSC_GROUP''
1708                                              AND   oco.jtot_object1_code = ''OKS_RSCGROUP''
1709                                              AND   oco.object1_id1  = :p_ctr_rec_old_value)
1710                                              AND   okh.org_id = to_number(:update_level_value)';
1711                                             -- AND   okh.id = '||to_number(p_ctr_rec.update_level_value) ;
1712           END IF;
1713 
1714 
1715 
1716  ---------------------------------------------------------------------------
1717  --  Update Level : Organization , Attribute: Coverage Type(AGREEMENT_NAME)
1718  ---------------------------------------------------------------------------
1719       ELSIF p_ctr_rec.attribute = 'AGREEMENT_NAME' THEN
1720 
1721              l_old_value := p_ctr_rec.old_value;
1722              l_stmt := l_select||' , :l_old_value old_value'||
1723                        l_from||
1724                        l_where||'AND EXISTS (SELECT ''x'' from okc_governances_v ogv
1725                                              WHERE ogv.dnz_chr_id = okh.id
1726                                              AND   ogv.isa_agreement_id = :p_ctr_rec_old_value)
1727                                              AND   okh.org_id = to_number(:update_level_value)';
1728 
1729  ---------------------------------------------------------
1730  --  Update Level : Organization , Attribute: Product Alias (PRODUCT_ALIAS)
1731  --------------------------------------------------------
1732       ELSIF p_ctr_rec.attribute = 'PRODUCT_ALIAS' THEN
1733 
1734        -- Old Value: NULL (-9999)
1735 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1736              l_stmt := l_select||' ,NULL old_value'||
1737                        l_from||l_where||
1738                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
1739                                      WHERE cle.dnz_chr_id = okh.id
1740                                      AND   cle.lse_id IN (7,8,9,10,11,18,25,35)
1741                                      AND   cle.cognomen is NULL)
1742                         AND okh.org_id = to_number(:update_level_value)';
1743 
1744        -- Old Value: ALL (-1111)
1745 
1746           ELSIF p_ctr_rec.old_value = '-1111' THEN
1747 
1748              l_stmt := l_select||' ,NULL old_value'||
1749                        l_from||l_where||
1750                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
1751                                      WHERE cle.dnz_chr_id = okh.id
1752                                      AND   cle.lse_id IN (7,8,9,10,11,18,25,35))
1753                         AND okh.org_id = to_number(:update_level_value)';
1754 
1755  -- Old Value: Other than NULL or ALL
1756 
1757           ELSE
1758 
1759              l_old_value := p_ctr_rec.old_value;
1760              l_stmt := l_select||' , :l_old_value old_value'||
1761                        l_from||l_where||
1762                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
1763                                      WHERE cle.dnz_chr_id = okh.id
1764                                      AND   cle.lse_id IN (7,8,9,10,11,18,25,35)
1765                                      AND   cle.cognomen = :p_ctr_rec_old_value)
1766                         AND okh.org_id = to_number(:update_level_value)';
1767 
1768           END IF;
1769 
1770  ---------------------------------------------------------
1771  --  Update Level : Organization , Attribute: Contract Line Ref(CONTRACT_LINE_REF)
1772  --------------------------------------------------------
1773       ELSIF p_ctr_rec.attribute = 'CONTRACT_LINE_REF' THEN
1774 
1775        -- Old Value: NULL (-9999)
1776 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1777              l_stmt := l_select||' ,NULL old_value'||
1778                        l_from||l_where||
1779                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
1780                                      WHERE cle.chr_id = okh.id
1781                                      AND   cle.lse_id IN (1,12,14,19)
1782                                      AND   cle.cognomen is NULL)
1783                         AND okh.org_id = to_number(:update_level_value)';
1784 
1785        -- Old Value: ALL (-1111)
1786 
1787           ELSIF p_ctr_rec.old_value = '-1111' THEN
1788              l_stmt := l_select||' ,NULL old_value'||
1789                        l_from||l_where||
1790                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
1791                                      WHERE cle.chr_id = okh.id
1792                                      AND   cle.lse_id IN (1,12,14,19))
1793                         AND okh.org_id = to_number(:update_level_value)';
1794 
1795  -- Old Value: Other than NULL or ALL
1796 
1797           ELSE
1798 
1799              l_old_value := p_ctr_rec.old_value;
1800              l_stmt := l_select||' , :l_old_value old_value'||
1801                        l_from||l_where||
1802                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
1803                                      WHERE cle.chr_id = okh.id
1804                                      AND   cle.lse_id IN (1,12,14,19)
1805                                      AND   cle.cognomen = :p_ctr_rec_old_value)
1806                         AND okh.org_id = to_number(:update_level_value)';
1807 
1808           END IF;
1809 
1810  ---------------------------------------------------------------------------------------
1811  --  Update Level : Organization , Attribute: Header Ship-to Address(HDR_SHIP_TO_ADDRESS)
1812  ----------------------------------------------------------------------------------------
1813       ELSIF p_ctr_rec.attribute = 'HDR_SHIP_TO_ADDRESS' THEN
1814 
1815        -- Old Value: NULL (-9999)
1816 	     IF  p_ctr_rec.old_value = '-9999' THEN
1817                  l_stmt := l_select||' ,NULL old_value' ||
1818                            l_from||l_where||
1819                                 ' AND  okh.ship_to_site_use_id is NULL
1820                                   AND okh.org_id = to_number(:update_level_value)';
1821 
1822        -- Old Value: Other than NULL or ALL
1823 
1824          ELSE
1825                  l_stmt := l_select||' ,okh.ship_to_site_use_id old_value' ||
1826                            l_from||l_where||
1827                                    ' AND  okh.ship_to_site_use_id = to_number(:p_ctr_rec_old_value)
1828                                      AND okh.org_id = to_number(:update_level_value)';
1829          END IF;
1830 
1831   ----------------------------------------------------------------------------------------------
1832  --  Update Level : Organization , Attribute: Header Bill-to Address(HDR_BILL_TO_ADDRESS)
1833  -----------------------------------------------------------------------------------------------
1834       ELSIF p_ctr_rec.attribute = 'HDR_BILL_TO_ADDRESS' THEN
1835 
1836        -- Old Value: NULL (-9999)
1837 	     IF  p_ctr_rec.old_value = '-9999' THEN
1838                  l_stmt := l_select||' ,NULL old_value' ||
1839                            l_from||l_where||
1840                                    ' AND  okh.bill_to_site_use_id is NULL
1841                                      AND okh.org_id = to_number(:update_level_value)';
1842        -- Old Value: Other than NULL or ALL
1843 
1844          ELSE
1845                  l_stmt := l_select||' ,okh.bill_to_site_use_id old_value' ||
1846                            l_from||l_where||
1847                                    ' AND  okh.bill_to_site_use_id = to_number(:p_ctr_rec_old_value)
1848                                      AND okh.org_id = to_number(:update_level_value)';
1849          END IF;
1850 
1851 -------------------------------------------------------
1852  --  Update Level : Organization , Attribute: Sales Rep (SALES_REP)
1853 --------------------------------------------------------
1854       ELSIF p_ctr_rec.attribute = 'SALES_REP' THEN
1855 
1856 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1857              l_stmt := l_select||' ,NULL old_value'||
1858                        l_from||l_where||
1859                        ' AND EXISTS (Select ''x'' from okc_contacts oc
1860                                          where oc.dnz_chr_id = okh.id
1861                                          and   oc.cro_code = ''SALESPERSON''
1862                                          and   oc.object1_id1 is null
1863                                          and   oc.jtot_object1_code = ''OKX_SALEPERS'')
1864                         AND okh.org_id = to_number(:update_level_value)';
1865 
1866           ELSIF p_ctr_rec.old_value = '-1111' THEN
1867 
1868              l_stmt := l_select||' ,oc.object1_id1 old_value '||
1869                        l_from||', okc_contacts oc '||
1870                        l_where||' and oc.dnz_chr_id = okh.id
1871                           and   oc.cro_code = ''SALESPERSON''
1872                           and   oc.jtot_object1_code = ''OKX_SALEPERS''
1873                        AND okh.org_id = to_number(:update_level_value)';
1874           ELSE
1875 
1876              l_old_value := p_ctr_rec.old_value;
1877              l_stmt := l_select||' , :l_old_value old_value'||
1878                        l_from||l_where||
1879                        ' AND (EXISTS (Select ''x'' from okc_contacts oc
1880                                          where oc.dnz_chr_id = okh.id
1881                                          and   oc.cro_code = ''SALESPERSON''
1882                                          and   oc.object1_id1= :p_ctr_rec_old_value
1883                                          and   oc.jtot_object1_code = ''OKX_SALEPERS'')
1884                         OR EXISTS (Select ''x'' from oks_k_sales_credits_v osc
1885                                    Where osc.chr_id = okh.id
1886                                    and osc.ctc_id = to_number(:p_ctr_rec_old_value)))
1887                          AND okh.org_id = to_number(:update_level_value)';
1888 
1889           END IF;
1890 
1891  ----------------------------------------------------------------------------------------
1892  --  Update Level : Organization, Attribute: Party Shipping Contact (PARTY_SHIPPING_CONTACT)
1893  ----------------------------------------------------------------------------------------
1894       ELSIF p_ctr_rec.attribute = 'PARTY_SHIPPING_CONTACT' THEN
1895 
1896 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1897              l_stmt := l_select||' ,NULL old_value'||
1898                        l_from||l_where||
1899                        ' AND EXISTS (Select ''x'' from okc_contacts oc
1900                                          where oc.dnz_chr_id = okh.id
1901                                          and   oc.cro_code = ''SHIPPING''
1902                                          and   oc.object1_id1 is null
1903                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
1904                         AND okh.org_id = to_number(:update_level_value)';
1905 
1906           ELSIF p_ctr_rec.old_value = '-1111' THEN
1907              l_stmt := l_select||' ,oc.object1_id1 old_value'||
1908                        l_from||', okc_contacts oc '||
1909                        l_where||
1910                         ' and oc.dnz_chr_id = okh.id
1911                           and   oc.cro_code = ''SHIPPING''
1912                           and   oc.jtot_object1_code = ''OKX_PCONTACT'')
1913                        AND okh.org_id = to_number(:update_level_value)';
1914 
1915           ELSE
1916 
1917              l_old_value := p_ctr_rec.old_value;
1918              l_stmt := l_select||' , :l_old_value old_value'||
1919                        l_from||l_where||
1920                        ' AND EXISTS (Select ''x'' from okc_contacts oc
1921                                          where oc.dnz_chr_id = okh.id
1922                                          and   oc.cro_code = ''SHIPPING''
1923                                          and   oc.object1_id1= :p_ctr_rec_old_value
1924                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
1925                          AND okh.org_id = to_number(:update_level_value)';
1926 
1927           END IF;
1928 
1929  --------------------------------------------------------
1930  --  Update Level : Organization , Attribute: Party Billing Contact (PARTY_BILLING_CONTACT)
1931  --------------------------------------------------------
1932       ELSIF p_ctr_rec.attribute = 'PARTY_BILLING_CONTACT' THEN
1933 
1934 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1935              l_stmt := l_select||' ,NULL old_value'||
1936                        l_from||l_where||
1937                        ' AND EXISTS (Select ''x'' from okc_contacts oc
1938                                          where oc.dnz_chr_id = okh.id
1939                                          and   oc.cro_code = ''BILLING''
1940                                          and   oc.object1_id1 is null
1941                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
1942                         AND okh.org_id = to_number(:update_level_value)';
1943 
1944           ELSIF p_ctr_rec.old_value = '-1111' THEN
1945              l_stmt := l_select||' ,oc.object1_id1 old_value'||
1946                        l_from||', okc_contacts oc '||
1947                        l_where||
1948                         ' and oc.dnz_chr_id = okh.id
1949                           and   oc.cro_code = ''BILLING''
1950                           and   oc.jtot_object1_code = ''OKX_PCONTACT'')
1951                        AND okh.org_id = to_number(:update_level_value)';
1952 
1953           ELSE
1954               -- dbms_output.put_line('Inside billing else');
1955              l_old_value := p_ctr_rec.old_value;
1956              l_stmt := l_select||' , :l_old_value old_value'||
1957                        l_from||l_where||
1958                        ' AND EXISTS (Select ''x'' from okc_contacts oc
1959                                          where oc.dnz_chr_id = okh.id
1960                                          and   oc.cro_code = ''BILLING''
1961                                          and   oc.object1_id1= :p_ctr_rec_old_value
1962                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
1963                          AND okh.org_id = to_number(:update_level_value)';
1964 
1965           END IF;
1966 
1967  ----------------------------------------------------------------------------------------
1968  --  Update Level : Organization, Attribute: Party Shipping Contact (LINE_SHIPPING_CONTACT)
1969  ----------------------------------------------------------------------------------------
1970       ELSIF p_ctr_rec.attribute = 'LINE_SHIPPING_CONTACT' THEN
1971 
1972 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
1973              l_stmt := l_select||' ,NULL old_value'||
1974                        l_from||l_where||
1975                        ' AND EXISTS (Select ''x'' from okc_contacts oc
1976                                          where oc.dnz_chr_id = okh.id
1977                                          and   oc.cro_code = ''CUST_SHIPPING''
1978                                          and   oc.object1_id1 is null
1979                                          and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
1980                         AND okh.org_id = to_number(:update_level_value)';
1981 
1982           ELSIF p_ctr_rec.old_value = '-1111' THEN
1983              l_stmt := l_select||' ,oc.object1_id1 old_value'||
1984                        l_from||', okc_contacts oc '||
1985                        l_where||
1986                         ' and oc.dnz_chr_id = okh.id
1987                           and   oc.cro_code = ''CUST_SHIPPING''
1988                           and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
1989                        AND okh.org_id = to_number(:update_level_value)';
1990 
1991           ELSE
1992               -- dbms_output.put_line('Inside else');
1993              l_old_value := p_ctr_rec.old_value;
1994              l_stmt := l_select||' , :l_old_value old_value'||
1995                        l_from||l_where||
1996                        ' AND EXISTS (Select ''x'' from okc_contacts oc
1997                                          where oc.dnz_chr_id = okh.id
1998                                          and   oc.cro_code = ''CUST_SHIPPING''
1999                                          and   oc.object1_id1= :p_ctr_rec_old_value
2000                                          and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
2001                          AND okh.org_id = to_number(:update_level_value)';
2002 
2003           END IF;
2004 
2005  --------------------------------------------------------
2006  --  Update Level : Organization , Attribute: Party Billing Contact (LINE_BILLING_CONTACT)
2007  --------------------------------------------------------
2008       ELSIF p_ctr_rec.attribute = 'LINE_BILLING_CONTACT' THEN
2009 
2010 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2011              l_stmt := l_select||' ,NULL old_value'||
2012                        l_from||l_where||
2013                        ' AND EXISTS (Select ''x'' from okc_contacts oc
2014                                          where oc.dnz_chr_id = okh.id
2015                                          and   oc.cro_code = ''CUST_BILLING''
2016                                          and   oc.object1_id1 is null
2017                                          and   oc.jtot_object1_code = ''OKX_CONTBILL'')
2018                         AND okh.org_id = to_number(:update_level_value)';
2019 
2020           ELSIF p_ctr_rec.old_value = '-1111' THEN
2021              l_stmt := l_select||' ,oc.object1_id1 old_value'||
2022                        l_from||', okc_contacts oc '||
2023                        l_where||
2024                         ' and oc.dnz_chr_id = okh.id
2025                           and   oc.cro_code = ''CUST_BILLING''
2026                           and   oc.jtot_object1_code = ''OKX_CONTBILL'')
2027                        AND okh.org_id = to_number(:update_level_value)';
2028 
2029           ELSE
2030               -- dbms_output.put_line('Inside billing else');
2031              l_old_value := p_ctr_rec.old_value;
2032              l_stmt := l_select||' , :l_old_value old_value'||
2033                        l_from||l_where||
2034                        ' AND EXISTS (Select ''x'' from okc_contacts oc
2035                                          where oc.dnz_chr_id = okh.id
2036                                          and   oc.cro_code = ''CUST_BILLING''
2037                                          and   oc.object1_id1= :p_ctr_rec_old_value
2038                                          and   oc.jtot_object1_code = ''OKX_CONTBILL'')
2039                          AND okh.org_id = to_number(:update_level_value)';
2040 
2041           END IF;
2042 
2043 
2044  --------------------------------------------------------
2045  --  Update Level : Organization , Attribute: Coverage Start Time (COVERAGE_START_TIME)
2046  --------------------------------------------------------
2047          ELSIF p_ctr_rec.attribute = 'COVERAGE_START_TIME' THEN
2048 
2049        -- Old Value: NULL (-9999)
2050 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2051              l_stmt := l_select||' ,NULL old_value'||
2052                        l_from||l_where||
2053                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
2054                                          where oct.dnz_chr_id = okh.id
2055                                          and   oct.start_hour is null
2056                                          and   oct.start_minute is null)
2057                         AND okh.org_id = to_number(:update_level_value)';
2058 
2059           ELSE
2060               -- dbms_output.put_line('Inside else');
2061              l_old_value := p_ctr_rec.old_value;
2062              l_stmt := l_select||' , :l_old_value old_value'||
2063                        l_from||l_where||
2064                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
2065                                      where oct.dnz_chr_id = okh.id
2066                                      and   oct.start_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
2067                                      and   oct.start_minute = mod(to_number(:p_ctr_rec_old_value),60))
2068                          AND okh.org_id = to_number(:update_level_value)';
2069           END IF;
2070 
2071  --------------------------------------------------------
2072  --  Update Level : Organization , Attribute: Coverage End Time (COVERAGE_END_TIME)
2073  --------------------------------------------------------
2074          ELSIF p_ctr_rec.attribute = 'COVERAGE_END_TIME' THEN
2075 
2076        -- Old Value: NULL (-9999)
2077 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2078              l_stmt := l_select||' ,NULL old_value'||
2079                        l_from||l_where||
2080                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
2081                                          where oct.dnz_chr_id = okh.id
2082                                          and   oct.end_hour is null
2083                                          and   oct.end_minute is null)
2084                         AND okh.org_id = to_number(:update_level_value)';
2085 
2086          ELSE
2087              l_old_value := p_ctr_rec.old_value;
2088              l_stmt := l_select||' , :l_old_value old_value'||
2089                        l_from||l_where||
2090                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
2091                                      where oct.dnz_chr_id = okh.id
2092                                      and   oct.end_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
2093                                      and   oct.end_minute = mod(to_number(:p_ctr_rec_old_value),60))
2094                         AND okh.org_id = to_number(:update_level_value)';
2095          END IF;
2096 
2097  --------------------------------------------------------
2098  --  Update Level : Organization , Attribute: Resolution Time (RESOLUTION_TIME)
2099  --------------------------------------------------------
2100       ELSIF p_ctr_rec.attribute = 'RESOLUTION_TIME' THEN
2101 
2102        -- Old Value: NULL (-9999)
2103 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2104              l_stmt := l_select||', NULL old_value'||
2105                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '|| l_where||
2106                        ' AND kl.dnz_chr_id = okh.id
2107 		         AND kl.id = att.cle_id
2108                          And kl.lse_id in (4,17,22)
2109                          AND   att.action_type_code = ''RSN''
2110                          AND   att.id = oat.cov_action_type_id
2111                          AND   ( sun_duration IS NULL
2112                                  OR mon_duration IS NULL
2113                                  OR tue_duration IS NULL
2114                                  OR wed_duration IS NULL
2115                                  OR thu_duration IS NULL
2116                                  OR fri_duration IS NULL
2117                                  OR sat_duration IS NULL)
2118                         AND okh.authoring_org_id = to_number(:update_level_value)';
2119 
2120 
2121        -- Old Value: Other than NULL or ALL
2122 
2123           ELSE
2124               -- dbms_output.put_line('Inside else 111111');
2125             l_old_value := p_ctr_rec.old_value;
2126             l_stmt := l_select||' , :l_old_value old_value'||
2127                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '||l_where||
2128                        ' AND kl.dnz_chr_id = okh.id
2129 		         AND kl.id = att.cle_id
2130                          And kl.lse_id in (4,17,22)
2131                          AND   att.action_type_code = ''RSN''
2132                          AND   att.id = oat.cov_action_type_id
2133                          AND   ( sun_duration = :p_ctr_rec_old_value
2134                                                OR mon_duration = :p_ctr_rec_old_value
2135                                                OR tue_duration = :p_ctr_rec_old_value
2136                                                OR wed_duration = :p_ctr_rec_old_value
2137                                                OR thu_duration = :p_ctr_rec_old_value
2138                                                OR fri_duration = :p_ctr_rec_old_value
2139                                                OR sat_duration = :p_ctr_rec_old_value)
2140                         AND okh.authoring_org_id = to_number(:update_level_value)';
2141           END IF;
2142 
2143  --------------------------------------------------------
2144  --  Update Level : Organization , Attribute: Reaction Time (REACTION_TIME)
2145  --------------------------------------------------------
2146       ELSIF p_ctr_rec.attribute = 'REACTION_TIME' THEN
2147 
2148    -- Old Value: NULL (-9999)
2149 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2150                        l_stmt := l_select||', NULL old_value'||
2151                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '||l_where||
2152                        '  AND kl.dnz_chr_id = okh.id
2153 		          AND kl.id = att.cle_id
2154                           And kl.lse_id in (4,17,22)
2155                          AND   att.action_type_code = ''RCN''
2156                          AND   att.id = oat.cov_action_type_id
2157                          AND   ( sun_duration IS NULL
2158                                                OR mon_duration IS NULL
2159                                                OR tue_duration IS NULL
2160                                                OR wed_duration IS NULL
2161                                                OR thu_duration IS NULL
2162                                                OR fri_duration IS NULL
2163                                                OR sat_duration IS NULL)
2164                         AND okh.authoring_org_id = to_number(:update_level_value)';
2165  -- Old Value: Other than NULL or ALL
2166 
2167           ELSE
2168 
2169              l_old_value := p_ctr_rec.old_value;
2170              l_stmt := l_select||' , :l_old_value old_value'||
2171                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '||l_where||
2172                        '  AND kl.dnz_chr_id = okh.id
2173 		          AND kl.id = att.cle_id
2174                           And kl.lse_id in (4,17,22)
2175                          AND   att.action_type_code = ''RCN''
2176                          AND   att.id = oat.cov_action_type_id
2177                          AND   ( sun_duration = :p_ctr_rec_old_value
2178                                                OR mon_duration = :p_ctr_rec_old_value
2179                                                OR tue_duration = :p_ctr_rec_old_value
2180                                                OR wed_duration = :p_ctr_rec_old_value
2181                                                OR thu_duration = :p_ctr_rec_old_value
2182                                                OR fri_duration = :p_ctr_rec_old_value
2183                                                OR sat_duration = :p_ctr_rec_old_value)
2184                         AND okh.authoring_org_id = to_number(:update_level_value)';
2185 
2186           END IF;
2187 
2188  --------------------------------------------------------
2189  --  Update Level : Organization , Attribute: Price List(PRICE_LIST)
2190  --------------------------------------------------------
2191       ELSIF p_ctr_rec.attribute = 'PRICE_LIST' THEN
2192 
2193         -- Old Value: NULL (-9999)
2194 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2195 
2196               l_stmt := l_select||' ,NULL old_value'||
2197                         l_from||l_where||
2198                          ' AND  okh.price_list_id is NULL
2199                            AND okh.org_id = to_number(:update_level_value)';
2200        -- Old Value: ALL (-1111)
2201 
2202           ELSIF p_ctr_rec.old_value = '-1111' THEN
2203 
2204              l_stmt := l_select||' ,okh.price_list_id old_value' ||
2205                          l_from||l_where||
2206                          ' AND okh.org_id = to_number(:update_level_value)';
2207 
2208         -- Old Value: Other than NULL or ALL
2209 
2210           ELSE
2211 
2212              l_stmt := l_select||' ,okh.price_list_id old_value' ||
2213                        l_from||l_where||
2214                        ' AND  okh.price_list_id = to_number(:p_ctr_rec_old_value)
2215                          AND okh.org_id = to_number(:update_level_value)';
2216 
2217           END IF;
2218 
2219  ------------------------------------------------------------------------------------------
2220  --  Update Level : Organization , Attribute: Known As (CONTRACT_ALIAS)
2221  ------------------------------------------------------------------------------------------
2222 	   ELSIF p_ctr_rec.attribute = 'CONTRACT_ALIAS' THEN
2223 
2224 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2225              l_stmt := l_select||' ,NULL old_value '||
2226                        l_from||l_where||
2227                        'AND okh.cognomen IS NULL
2228      					AND okh.org_id = to_number(:update_level_value)';
2229 
2230           ELSIF p_ctr_rec.old_value = '-1111' THEN -- For old Value as ALL
2231              l_stmt := l_select||' ,okh.cognomen old_value'||
2232                        l_from||
2233                        l_where||' AND okh.org_id = to_number(:update_level_value)';
2234 
2235           ELSE
2236              l_stmt := l_select||', okh.cognomen old_value'||
2237                        l_from||
2238                        l_where||' AND okh.cognomen = :p_ctr_rec_old_value
2239      			        AND okh.org_id = to_number(:update_level_value)';
2240           END IF;
2241 
2242  ------------------------------------------------------------------------------------------
2243  --  Update Level : Organization , Attribute: Purchase Order Number (PO_NUMBER_BILL)
2244  ------------------------------------------------------------------------------------------
2245 	   ELSIF p_ctr_rec.attribute = 'PO_NUMBER_BILL' THEN
2246 
2247 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2248              l_stmt := l_select||' ,NULL old_value '||
2249                        l_from||l_where||
2250                        'AND okh.cust_po_number IS NULL
2251                         AND ( okh.payment_instruction_type  Is Null Or okh.payment_instruction_type = ''PON'')
2252      					AND okh.org_id = to_number(:update_level_value)';
2253 
2254           ELSIF p_ctr_rec.old_value = '-1111' THEN -- For old Value as ALL
2255 	     If p_ctr_rec.new_value is Null Then
2256                        l_stmt := l_select||' ,okh.cust_po_number old_value'||
2257                        l_from||
2258                        l_where||' AND okh.org_id = to_number(:update_level_value) AND okh.payment_instruction_type = ''PON''
2259                                  and okh.cust_po_number_req_yn <> ''Y''';
2260 
2261              Else
2262 	              l_stmt := l_select||' ,okh.cust_po_number old_value'||
2263                        l_from||
2264                        l_where||' AND okh.payment_instruction_type = ''PON'' AND okh.org_id = to_number(:update_level_value)';
2265 	    End If;
2266           ELSE
2267 	    If p_ctr_rec.new_value is Null Then
2268              l_stmt := l_select||', okh.cust_po_number old_value'||
2269                        l_from||
2270                        l_where||' AND okh.cust_po_number = :p_ctr_rec_old_value
2271      					          AND okh.payment_instruction_type = ''PON'' AND okh.org_id = to_number(:update_level_value) and okh.cust_po_number_req_yn <> ''Y''';
2272 	    Else
2273              l_stmt := l_select||', okh.cust_po_number old_value'||
2274                        l_from||
2275                        l_where||' AND okh.cust_po_number = :p_ctr_rec_old_value
2276      					         AND okh.payment_instruction_type = ''PON''  AND okh.org_id = to_number(:update_level_value)';
2277 
2278 
2279 
2280 	    End If;
2281 
2282 
2283           END IF;
2284 
2285 
2286  -----------------------------------------------------------------------------
2287  --  Update Level : Organization , Attribute: PO NUMBER Required(PO_REQUIRED_REN)
2288  -----------------------------------------------------------------------------
2289       ELSIF p_ctr_rec.attribute = 'PO_REQUIRED_REN' THEN
2290 
2291 
2292            IF p_ctr_rec.old_value = '-1111' THEN
2293 
2294              l_old_value := p_ctr_rec.old_value;
2295              l_stmt := l_select||' , :l_old_value old_value'||
2296                        l_from||l_where||
2297                        'AND okh.org_id = to_number(:update_level_value)';
2298 
2299      -- Old Value: Other than NULL or ALL
2300            ELSE
2301 
2302              l_old_value := p_ctr_rec.old_value;
2303              l_stmt := l_select||' , :l_old_value old_value'||
2304                         l_from||' ,oks_k_headers_v oksh '||
2305                         l_where||' AND oksh.chr_id = okh.id
2306                                    AND nvl(oksh.renewal_po_required,''N'') = :p_ctr_rec_old_value
2307                           AND okh.org_id = to_number(:update_level_value)';
2308            END IF ;
2309 
2310  --------------------------------------------------------
2311  --  Update Level : Organization , Attribute: Summary Print(SUMMARY_PRINT)
2312  --------------------------------------------------------
2313       ELSIF p_ctr_rec.attribute = 'SUMMARY_PRINT' THEN
2314 
2315        -- Old Value: ALL (-1111)
2316 
2317         IF p_ctr_rec.old_value = '-1111' THEN
2318             l_old_value := p_ctr_rec.old_value;
2319             l_stmt := l_select||'  , :l_old_value old_value'||
2320                       l_from||' ,oks_k_headers_v oksh '||
2321                       l_where||' AND oksh.chr_id = okh.id
2322                                  AND okh.org_id = to_number(:update_level_value)';
2323 
2324 
2325       -- Old Value: Other than NULL or ALL
2326 
2327         ELSE
2328               l_old_value := p_ctr_rec.old_value;
2329               l_stmt := l_select||' , :l_old_value old_value'||
2330                         l_from||' ,oks_k_headers_v oksh '||
2331                         l_where||' AND oksh.chr_id = okh.id
2332                                    AND nvl(oksh.inv_print_profile,''N'') = :p_ctr_rec_old_value
2333                                    AND okh.org_id = to_number(:update_level_value)';
2334 
2335         END IF ;
2336 
2337 
2338  ------------------------------------------------------------------------------------------
2339   --  Update Level : Organization , Attribute: Contract Group (CONTRACT_GROUP)
2340  ------------------------------------------------------------------------------------------
2341 
2342 	   ELSIF p_ctr_rec.attribute = 'CONTRACT_GROUP' THEN
2343 
2344 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2345              l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
2346                        l_from||',okc_k_groups_grpings_v okg'||
2347                        l_where||' AND okg.included_chr_id = okh.id
2348      					          AND okg.cgp_parent_id is NULL
2349      					          AND okh.org_id = to_number(:update_level_value)';
2350 
2351          ELSIF p_ctr_rec.old_value = '-1111' THEN -- For old Value as ALL
2352 
2353              l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
2354                        l_from||',okc_k_groups_grpings_v okg'||
2355                        l_where||' AND okg.included_chr_id = okh.id
2356      					          AND okh.org_id = to_number(:update_level_value)';
2357 
2358          ELSE
2359              l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
2360                        l_from||',okc_k_groups_grpings_v okg'||
2361                        l_where||' AND okg.included_chr_id = okh.id
2362      					          AND okg.cgp_parent_id = to_number(:p_ctr_rec_old_value)
2363      					          AND okh.org_id = to_number(:update_level_value)';
2364           END IF;
2365  ------------------------------------------------------------------------------------------
2366  --  Update Level : Organization , Attribute: Contract Start date(CONTRACT_START_DATE)
2367  ------------------------------------------------------------------------------------------
2368 
2369         ELSIF p_ctr_rec.attribute = 'CONTRACT_START_DATE' Then
2370 
2371           IF p_ctr_rec.old_value is NULL THEN   -- For Contract Start date as NULL
2372              l_stmt:= l_select||',to_char(okh.start_date) old_value '||
2373                       l_from||
2374                       l_where||' AND okh.start_date is NULL
2375                                  AND okh.org_id = to_number(:update_level_value)';
2376 
2377           ELSIF p_ctr_rec.old_value is not NULL THEN   -- For Contract Start date not NULL
2378              l_stmt:= l_select||',to_char(okh.start_date) old_value '||
2379                       l_from||
2380                       l_where||' AND trunc(okh.start_date) = trunc(to_date(:p_ctr_rec_old_value,''YYYY/MM/DD HH24:MI:SS''))
2381                                  AND okh.org_id = to_number(:update_level_value)';
2382           END IF;
2383  ------------------------------------------------------------------------------------------
2384  --  Update Level : Organization , Attribute: Contract Start date(CONTRACT_END_DATE)
2385  ------------------------------------------------------------------------------------------
2386 
2387         ELSIF UPPER(p_ctr_rec.attribute) = UPPER('CONTRACT_END_DATE') Then
2388 
2389           IF p_ctr_rec.old_value is NULL THEN   -- For Contract End date as NULL
2390              l_stmt := l_select||',to_char(okh.end_date) old_value'||
2391                        l_from||
2392                        l_where||' AND okh.end_date is NULL
2393 						          AND okh.org_id = to_number(:update_level_value)';
2394 
2395           ELSIF p_ctr_rec.old_value is not NULL THEN   -- For Contract End date not NULL
2396              l_stmt := l_select||',to_char(okh.end_date) old_value'||
2397                        l_from||
2398                        l_where||' AND trunc(okh.end_date) = trunc(to_date(:p_ctr_rec_old_value,''YYYY/MM/DD HH24:MI:SS''))
2399 						          AND okh.org_id = to_number(:update_level_value)';
2400           END IF;
2401         END IF;
2402 
2403 -----------------------------------
2404  --  Update Level : PARTY
2405  -----------------------------------
2406 
2407  ELSIF p_ctr_rec.update_level = 'OKX_PARTY' THEN
2408 
2409  --------------------------------------------------------
2410  --  Update Level : Party , Attribute: Revenue Account(REV_ACCT)
2411  --------------------------------------------------------
2412       IF p_ctr_rec.attribute = 'REV_ACCT' THEN
2413 
2414 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2415              l_stmt := l_select||' ,NULL old_value'||
2416                        l_from||' ,okc_k_party_roles_b okp1 '||l_where||
2417                        ' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
2418                                      WHERE rev.chr_id = okh.id
2419                                      AND   rev.code_combination_id is NULL)
2420                          AND  okh.id = okp1.chr_id
2421                          AND  okp1.rle_code in ( ''CUSTOMER'',''SUBSCRIBER'')
2422                          AND  okp1.object1_id1 = :update_level_value';
2423 
2424           ELSIF p_ctr_rec.old_value = '-1111' THEN
2425 
2426              l_stmt := l_select||' ,NULL old_value'||
2427                        l_from||' ,okc_k_party_roles_b okp1 '||l_where||
2428                        ' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
2429                                      WHERE rev.chr_id = okh.id)
2430                          AND  okh.id = okp1.chr_id
2431                          AND  okp1.rle_code in ( ''CUSTOMER'',''SUBSCRIBER'')
2432                          AND  okp1.object1_id1 = :update_level_value';
2433 
2434 
2435           ELSE
2436               -- dbms_output.put_line('Inside else');
2437              l_old_value := p_ctr_rec.old_value;
2438              l_stmt := l_select||' , :l_old_value old_value'||
2439                        l_from||' ,okc_k_party_roles_b okp1 '||
2440                        l_where||' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
2441                                      WHERE rev.chr_id = okh.id
2442                                      AND   rev.code_combination_id = to_number(:p_ctr_rec_old_value))
2443                          AND  okh.id = okp1.chr_id
2444                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2445                          AND  okp1.object1_id1 = :update_level_value';
2446 
2447           END IF;
2448 
2449  ---------------------------------------------------------
2450  --  Update Level :  Party , Attribute: Payment Term (PAYMENT_TERM)
2451  --------------------------------------------------------
2452 
2453       ELSIF p_ctr_rec.attribute = 'PAYMENT_TERM' THEN
2454 
2455 
2456          IF    p_ctr_rec.old_value = '-9999' THEN
2457 
2458                        l_stmt := l_select||' ,NULL old_value' ||
2459                        l_from|| ' ,okc_k_party_roles_b okp1 '||
2460                        l_where||' AND  okh.PAYMENT_TERM_ID is NULL
2461                                   AND  okh.id = okp1.chr_id
2462                                   AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2463                                   AND  okp1.object1_id1 = :update_level_value ' ;
2464 
2465          ELSIF p_ctr_rec.old_value = '-1111' THEN
2466                        l_stmt := l_select||' ,okh.payment_term_id old_value' ||
2467                        l_from||' ,okc_k_party_roles_b okp1 '||
2468                        l_where||'AND  okh.id = okp1.chr_id
2469                                  AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2470                                  AND  okp1.object1_id1 = :update_level_value ' ;
2471  -- Old Value: Other than NULL or ALL
2472 
2473           ELSE
2474 
2475              l_stmt := l_select||' ,okh.payment_term_id old_value' ||
2476                        l_from||' ,okc_k_party_roles_b okp1 '||
2477                        l_where|| ' AND  okh.payment_term_id = to_number(:p_ctr_rec_old_value)
2478                                    AND  okh.id = okp1.chr_id
2479                                    AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2480                                    AND  okp1.object1_id1 = :update_level_value ' ;
2481 
2482           END IF;
2483 
2484 -------------------------------------------------------------------------------------
2485  --  Update Level : Party , Attribute: Contract Renewal Type(CON_RENEWAL_TYPE)
2486 ------------------------------------------------------------------------------------
2487       ELSIF p_ctr_rec.attribute = 'CON_RENEWAL_TYPE' THEN
2488 
2489        -- Old Value: NULL (-9999)
2490 	     IF    p_ctr_rec.old_value = '-9999' THEN
2491 
2492                        l_stmt := l_select||' ,NULL old_value' ||
2493                        l_from||' ,okc_k_party_roles_b okp1 '||
2494                        l_where||
2495                        ' AND  okh.renewal_type_code is NULL
2496                          AND not exists(
2497                                         select ol.object_chr_id
2498                                         from okc_operation_lines ol
2499                                             ,okc_operation_instances oi
2500                                             ,okc_class_operations co
2501                                         WHERE ol.object_chr_id = okh.id
2502                                           AND ol.process_flag = ''P''
2503                                           AND ol.ACTIVE_YN    = ''Y''
2504                                           AND oi.id = ol.oie_id
2505                                           AND oi.cop_id = co.id
2506                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
2507                                           AND co.CLS_CODE = ''SERVICE'')
2508                          AND  okh.id = okp1.chr_id
2509                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2510                          AND  okp1.object1_id1 = :update_level_value ' ;
2511 
2512          ELSIF p_ctr_rec.old_value = '-1111' THEN
2513                        l_old_value := p_ctr_rec.old_value;
2514                        l_stmt := l_select||' , :l_old_value old_value' ||
2515                        l_from||' ,okc_k_party_roles_b okp1 '||
2516                        l_where|| 'AND  okh.id = okp1.chr_id
2517                                   AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2518                                   AND not exists(
2519                                         select ol.object_chr_id
2520                                         from okc_operation_lines ol
2521                                             ,okc_operation_instances oi
2522                                             ,okc_class_operations co
2523                                         WHERE ol.object_chr_id = okh.id
2524                                           AND ol.process_flag = ''P''
2525                                           AND ol.ACTIVE_YN    = ''Y''
2526                                           AND oi.id = ol.oie_id
2527                                           AND oi.cop_id = co.id
2528                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
2529                                           AND co.CLS_CODE = ''SERVICE'')
2530                                   AND  okp1.object1_id1 = :update_level_value ' ;
2531 
2532  -- Old Value: ERN
2533           ELSIF p_ctr_rec.old_value = 'ERN' then
2534 
2535              l_old_value := p_ctr_rec.old_value;
2536              l_stmt := l_select||' , :l_old_value old_value' ||
2537                        l_from||' ,oks_k_headers_b oksh ,okc_k_party_roles_b okp1'||
2538                        l_where||
2539                        ' AND oksh.chr_id = okh.id
2540                         AND  okh.renewal_type_code = ''NSR''
2541                         AND ''ERN'' = :p_ctr_rec_old_value
2542                         AND oksh.ELECTRONIC_RENEWAL_FLAG =''Y''
2543                          AND not exists(
2544                                         select ol.object_chr_id
2545                                         from okc_operation_lines ol
2546                                             ,okc_operation_instances oi
2547                                             ,okc_class_operations co
2548                                         WHERE ol.object_chr_id = okh.id
2549                                           AND ol.process_flag = ''P''
2550                                           AND ol.ACTIVE_YN    = ''Y''
2551                                           AND oi.id = ol.oie_id
2552                                           AND oi.cop_id = co.id
2553                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
2554                                           AND co.CLS_CODE = ''SERVICE'')
2555                          AND  okh.id = okp1.chr_id
2556                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2557                          AND  okp1.object1_id1 = :update_level_value ' ;
2558 
2559  -- Old Value: Other than NULL or ALL
2560           ELSE
2561 
2562              l_old_value := p_ctr_rec.old_value;
2563              l_stmt := l_select||' , :l_old_value old_value' ||
2564                        l_from||' ,oks_k_headers_b oksh ,okc_k_party_roles_b okp1'||
2565                        l_where||
2566                        ' AND oksh.chr_id = okh.id
2567                         AND  okh.renewal_type_code = :p_ctr_rec_old_value
2568                         AND nvl(oksh.ELECTRONIC_RENEWAL_FLAG,''N'') <> ''Y''
2569                          AND not exists(
2570                                         select ol.object_chr_id
2571                                         from okc_operation_lines ol
2572                                             ,okc_operation_instances oi
2573                                             ,okc_class_operations co
2574                                         WHERE ol.object_chr_id = okh.id
2575                                           AND ol.process_flag = ''P''
2576                                           AND ol.ACTIVE_YN    = ''Y''
2577                                           AND oi.id = ol.oie_id
2578                                           AND oi.cop_id = co.id
2579                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
2580                                           AND co.CLS_CODE = ''SERVICE'')
2581                          AND  okh.id = okp1.chr_id
2582                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2583                          AND  okp1.object1_id1 = :update_level_value ' ;
2584 
2585           END IF;
2586 
2587  ---------------------------------------------------------------------------
2588  --  Update Level : Party , Attribute: Business Process Price List (BP_PRICE_LIST)
2589  ---------------------------------------------------------------------------
2590       ELSIF p_ctr_rec.attribute = 'BP_PRICE_LIST' THEN
2591 
2592      -- Old Value: NULL (-9999)
2593 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2594               l_stmt := l_select||' ,NULL old_value' ||
2595                         l_from||' ,okc_k_party_roles_b okp1  '||
2596                         l_where|| 'AND exists ( Select dnz_chr_id from okc_k_lines_b cln
2597                                           Where cln.dnz_chr_id = okh.id
2598                                             AND cln.lse_id in(3,16,21)
2599                                             AND cln.price_list_id is NULL)
2600                          AND  okh.id = okp1.chr_id
2601                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2602                          AND  okp1.object1_id1 = :update_level_value ';
2603 
2604      -- Old Value: ALL (-1111)
2605           ELSIF p_ctr_rec.old_value = '-1111' THEN
2606              l_old_value := p_ctr_rec.old_value;
2607              l_stmt := l_select||' , :l_old_value old_value' ||
2608                        l_from||' ,okc_k_party_roles_b okp1  '||
2609                        l_where|| ' AND exists ( Select dnz_chr_id from okc_k_lines_b cln
2610                                           Where cln.dnz_chr_id = okh.id
2611                                             AND cln.lse_id in(3,16,21))
2612                          AND  okh.id = okp1.chr_id
2613                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2614                          AND  okp1.object1_id1 = :update_level_value ';
2615 
2616      -- Old Value: Other than NULL or ALL
2617           ELSE
2618              l_old_value := p_ctr_rec.old_value;
2619              l_stmt := l_select||' , :l_old_value old_value' ||
2620                        l_from||' ,okc_k_party_roles_b okp1 '||
2621                        l_where|| ' AND exists ( Select dnz_chr_id from okc_k_lines_b cln
2622                                       Where cln.dnz_chr_id = okh.id
2623                                       AND cln.lse_id in(3,16,21)
2624                                       AND cln.price_list_id = to_number(:p_ctr_rec_old_value))
2625                          AND  okh.id = okp1.chr_id
2626                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2627                          AND  okp1.object1_id1 = :update_level_value ';
2628 
2629           END IF;
2630 
2631  ---------------------------------------------------------
2632  --  Update Level :  Party , Attribute: Accounting Rule (ACCT_RULE)
2633  --------------------------------------------------------
2634 
2635       ELSIF p_ctr_rec.attribute = 'ACCT_RULE' THEN
2636 
2637       -- Old Value: NULL (-9999)
2638 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2639 
2640               l_stmt := l_select||' ,NULL old_value' ||
2641                        l_from||' ,oks_k_headers_v oksh ,okc_k_party_roles_b okp1 '||
2642                         l_where|| 'AND oksh.chr_id = okh.id
2643                                    AND oksh.acct_rule_id IS NULL
2644                                    AND  okh.id = okp1.chr_id
2645                                    AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2646                                    AND  okp1.object1_id1 = :update_level_value';
2647      -- Old Value: ALL (-1111)
2648 
2649           ELSIF p_ctr_rec.old_value = '-1111' THEN
2650              l_stmt := l_select||' ,oksh.acct_rule_id old_value' ||
2651                        l_from||' ,oks_k_headers_v oksh ,okc_k_party_roles_b okp1 '||
2652                        l_where|| 'AND oksh.chr_id = okh.id
2653                                   AND  okh.id = okp1.chr_id
2654                                   AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2655                                   AND  okp1.object1_id1 = :update_level_value';
2656      -- Old Value: Other than NULL or ALL
2657 
2658           ELSE
2659              l_stmt := l_select||' ,oksh.acct_rule_id old_value' ||
2660                        l_from||' ,oks_k_headers_v oksh ,okc_k_party_roles_b okp1 '||
2661                        l_where|| 'AND oksh.chr_id = okh.id
2662                                   AND oksh.acct_rule_id = to_number(:p_ctr_rec_old_value)
2663                                   AND  okh.id = okp1.chr_id
2664                                   AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2665                                   AND  okp1.object1_id1 = :update_level_value';
2666           END IF;
2667 
2668  ---------------------------------------------------------
2669  --  Update Level :  Party , Attribute: Invoice Rule (INV_RULE)
2670  --------------------------------------------------------
2671 
2672       ELSIF p_ctr_rec.attribute = 'INV_RULE' THEN
2673 
2674        -- Old Value: NULL (-9999)
2675          IF  p_ctr_rec.old_value = '-9999' THEN
2676 
2677              l_stmt := l_select||' ,NULL old_value' ||
2678                        l_from||',okc_k_party_roles_b okp1 '||
2679                        l_where||
2680                              ' AND  okh.inv_rule_id IS NULL
2681                                AND  okh.id = okp1.chr_id
2682                                AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2683                                AND  okp1.object1_id1 = :update_level_value';
2684 
2685          ELSIF p_ctr_rec.old_value = '-1111' THEN
2686              l_stmt := l_select||' ,okh.inv_rule_id old_value' ||
2687                        l_from||' ,okc_k_party_roles_b okp1 '||
2688                        l_where||
2689                              ' AND  okh.id = okp1.chr_id
2690                                AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2691                                AND  okp1.object1_id1 = :update_level_value';
2692 
2693        -- Old Value: Other than NULL or ALL
2694 
2695           ELSE
2696              l_stmt := l_select||' ,okh.inv_rule_id old_value' ||
2697                        l_from||',okc_k_party_roles_b okp1 '||
2698                        l_where||
2699                              ' AND  okh.inv_rule_id = to_number(:p_ctr_rec_old_value)
2700                                AND  okh.id = okp1.chr_id
2701                                AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2702                                AND  okp1.object1_id1 = :update_level_value';
2703 
2704           END IF;
2705 
2706  ---------------------------------------------------------------------------
2707  --  Update Level : Party , Attribute: Coverage Type(COV_TYPE)
2708  ---------------------------------------------------------------------------
2709       ELSIF p_ctr_rec.attribute = 'COV_TYPE' THEN
2710 
2711        -- Old Value: NULL (-9999)
2712 	     IF p_ctr_rec.old_value = '-9999' THEN
2713              l_stmt := l_select||' ,NULL old_value'||
2714                        l_from||',okc_k_party_roles_v okp1'||
2715                        l_where||' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V okl, oks_k_lines_v oksl
2716                                              WHERE okl.dnz_chr_id = okh.id
2717                                              AND oksl.cle_id = okl.id
2718                                              AND oksl.coverage_type is NULL )
2719                          AND  okh.id = okp1.chr_id
2720                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2721                          AND  okp1.object1_id1 = :update_level_value';
2722 
2723         -- Old Value: ALL
2724 
2725           ELSIF p_ctr_rec.old_value = '-1111' THEN
2726 
2727              l_old_value := p_ctr_rec.old_value;
2728              l_stmt := l_select||' , :l_old_value old_value'||
2729                        l_from||',okc_k_party_roles_v okp1'||
2730                        l_where||'AND EXISTS (SELECT ''x'' from okc_k_lines_v okl, oks_k_lines_v oksl
2731                                  WHERE okl.dnz_chr_id = okh.id
2732                                  AND oksl.cle_id      = okl.id )
2733                          AND  okh.id = okp1.chr_id
2734                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2735                          AND  okp1.object1_id1 = :update_level_value';
2736 
2737         -- Old Value: Other than NULL or ALL
2738           ELSE
2739               l_old_value := p_ctr_rec.old_value;
2740               l_stmt := l_select||' , :l_old_value old_value'||
2741                         l_from||',okc_k_party_roles_v okp1'||
2742                         l_where||'AND EXISTS (SELECT ''x'' from okc_k_lines_v okl, oks_k_lines_v oksl
2743                                   WHERE okl.dnz_chr_id   = okh.id
2744                                   AND oksl.cle_id        = okl.id
2745                                   AND oksl.coverage_type = :p_ctr_rec_old_value )
2746                          AND  okh.id = okp1.chr_id
2747                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2748                          AND  okp1.object1_id1 = :update_level_value';
2749 
2750           END IF;
2751 
2752 
2753  ---------------------------------------------------------------------------
2754  --  Update Level : Party , Attribute: Coverage Type(COV_TIMEZONE)
2755  ---------------------------------------------------------------------------
2756       ELSIF p_ctr_rec.attribute = 'COV_TIMEZONE' THEN
2757 
2758         -- Old Value: NULL (-9999)
2759 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2760              l_stmt := l_select||' ,NULL old_value'||
2761                        l_from||',okc_k_party_roles_v okp1'||
2762                        l_where||
2763                        ' AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
2764                                       WHERE ctz.dnz_chr_id = okh.id
2765                                       AND   ctz.timezone_id IS NULL )
2766                          AND  okh.id = okp1.chr_id
2767                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2768                          AND  okp1.object1_id1 = :update_level_value';
2769 
2770        -- Old Value: ALL (-1111)
2771           ELSIF p_ctr_rec.old_value = '-1111' THEN
2772 
2773              l_old_value := p_ctr_rec.old_value;
2774              l_stmt := l_select||' , :l_old_value old_value'||
2775                        l_from||',okc_k_party_roles_v okp1'||
2776                        l_where||'AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
2777                                              WHERE ctz.dnz_chr_id = okh.id
2778                                              AND   ctz.timezone_id IS NOT NULL )
2779                           AND  okh.id = okp1.chr_id
2780                           AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2781                           AND  okp1.object1_id1 = :update_level_value';
2782         -- Old Value: Other than NULL or ALL
2783           ELSE
2784 
2785              l_old_value := p_ctr_rec.old_value;
2786              l_stmt := l_select||' , :l_old_value old_value'||
2787                        l_from||',okc_k_party_roles_v okp1'||
2788                        l_where||'AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
2789                                              WHERE ctz.dnz_chr_id = okh.id
2790                                              AND  ctz.timezone_id = to_number(:p_ctr_rec_old_value))
2791                           AND  okh.id = okp1.chr_id
2792                           AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2793                           AND  okp1.object1_id1 = :update_level_value';
2794 
2795           END IF;
2796  ---------------------------------------------------------------------------
2797  --  Update Level : Party , Attribute: Coverage Type(PREF_ENGG)
2798  ---------------------------------------------------------------------------
2799       ELSIF p_ctr_rec.attribute = 'PREF_ENGG' THEN
2800 
2801          IF p_ctr_rec.old_value = '-1111' THEN
2802 
2803                 l_old_value := p_ctr_rec.old_value;
2804                 l_stmt := l_select||' , :l_old_value old_value'||
2805                        l_from||',okc_k_party_roles_v okp1'||
2806                        l_where||'AND EXISTS (SELECT ''x'' from
2807                                              okc_contacts oco
2808                                              WHERE oco.dnz_chr_id = okh.id
2809                                              AND   oco.cro_code = ''ENGINEER''
2810                                              AND   oco.jtot_object1_code = ''OKX_RESOURCE'')
2811                                              AND  okh.id = okp1.chr_id
2812                                              AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2813                                              AND  okp1.object1_id1 = :update_level_value';
2814                                  --            AND   okh.org_id = '||to_number(p_ctr_rec.update_level_value);
2815                                  --            AND   oco.object1_id1  = '''||p_ctr_rec.old_value||''')
2816                                  --            AND  okh.id = '||to_number(p_ctr_rec.update_level_value) ;
2817 
2818           ELSE
2819              l_old_value := p_ctr_rec.old_value;
2820              l_stmt := l_select||' , :l_old_value old_value'||
2821                        l_from||',okc_k_party_roles_v okp1'||
2822                        l_where||'AND EXISTS (SELECT ''x'' from
2823                                              okc_contacts oco
2824                                              WHERE oco.dnz_chr_id = okh.id
2825                                              AND   oco.cro_code = ''ENGINEER''
2826                                              AND   oco.jtot_object1_code = ''OKX_RESOURCE''
2827                                              AND   oco.object1_id1  = :p_ctr_rec_old_value)
2828                                              AND  okh.id = okp1.chr_id
2829                                              AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2830                                              AND  okp1.object1_id1 = :update_level_value';
2831 --                                             AND   okh.org_id = '||to_number(p_ctr_rec.update_level_value);
2832 --                                             AND  okh.id = '||to_number(p_ctr_rec.update_level_value) ;
2833           END IF;
2834  ---------------------------------------------------------------------------
2835  --  Update Level : Party , Attribute: Coverage Type(RES_GROUP)
2836  ---------------------------------------------------------------------------
2837       ELSIF p_ctr_rec.attribute = 'RES_GROUP' THEN
2838 
2839 	     IF p_ctr_rec.old_value = '-1111' THEN
2840 
2841              l_old_value := p_ctr_rec.old_value;
2842              l_stmt := l_select||' , :l_old_value old_value'||
2843                        l_from||',okc_k_party_roles_v okp1'||
2844                        l_where||'AND EXISTS (SELECT ''x'' from
2845                                              okc_contacts oco
2846                                              WHERE oco.dnz_chr_id = okh.id
2847                                              AND   oco.cro_code = ''RSC_GROUP''
2848                                              AND   oco.jtot_object1_code = ''OKS_RSCGROUP'')
2849                                              AND   okh.id = okp1.chr_id
2850                                              AND   okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2851                                              AND   okp1.object1_id1 = :update_level_value';
2852                                  --            AND   okh.org_id = '||to_number(p_ctr_rec.update_level_value);
2853                                  --            AND   oco.object1_id1  = '''||p_ctr_rec.old_value||''')
2854                                  --            AND  okh.id = '||to_number(p_ctr_rec.update_level_value) ;
2855 
2856           ELSE
2857              l_old_value := p_ctr_rec.old_value;
2858              l_stmt := l_select||' , :l_old_value old_value'||
2859                        l_from||',okc_k_party_roles_v okp1'||
2860                        l_where||'AND EXISTS (SELECT ''x'' from
2861                                              okc_contacts oco
2862                                              WHERE oco.dnz_chr_id = okh.id
2863                                              AND   oco.cro_code = ''RSC_GROUP''
2864                                              AND   oco.jtot_object1_code = ''OKS_RSCGROUP''
2865                                              AND   oco.object1_id1  =  :p_ctr_rec_old_value)
2866                                              AND   okh.id = okp1.chr_id
2867                                              AND   okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2868                                              AND   okp1.object1_id1 = :update_level_value';
2869                                             -- AND   okh.org_id = '||to_number(p_ctr_rec.update_level_value);
2870                                             -- AND   okh.id = '||to_number(p_ctr_rec.update_level_value) ;
2871           END IF;
2872 
2873  ---------------------------------------------------------------------------
2874  --  Update Level : Party, Attribute: Coverage Type(AGREEMENT_NAME)
2875  ---------------------------------------------------------------------------
2876       ELSIF p_ctr_rec.attribute = 'AGREEMENT_NAME' THEN
2877 
2878              l_old_value := p_ctr_rec.old_value;
2879              l_stmt := l_select||' , :l_old_value old_value'||
2880                        l_from||',okc_k_party_roles_v okp1'||
2881                        l_where||'AND EXISTS (SELECT ''x'' from okc_governances_v ogv
2882                                              WHERE ogv.dnz_chr_id = okh.id
2883                                              AND   ogv.isa_agreement_id = :p_ctr_rec_old_value)
2884                                              AND   okh.id = okp1.chr_id
2885                                              AND   okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2886                                              AND   okp1.object1_id1 = :update_level_value';
2887 
2888  ------------------------------------------------------------------------------------------
2889  --  Update Level :  Party , Attribute: Product Alias (PRODUCT_ALIAS)
2890  ------------------------------------------------------------------------------------------
2891       ELSIF p_ctr_rec.attribute = 'PRODUCT_ALIAS' THEN
2892 
2893 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2894              l_stmt := l_select||' ,NULL old_value'||
2895                        l_from||' ,okc_k_party_roles_b okp1 '||l_where||
2896                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
2897                                      WHERE cle.dnz_chr_id = okh.id
2898                                      AND   cle.lse_id in (7,8,9,10,11,18,25,35)
2899                                      AND   cle.cognomen is NULL)
2900                          AND  okh.id = okp1.chr_id
2901                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2902                          AND  okp1.object1_id1 = :update_level_value';
2903 
2904           ELSIF p_ctr_rec.old_value = '-1111' THEN
2905 
2906              l_stmt := l_select||' ,NULL old_value'||
2907                        l_from||' ,okc_k_party_roles_b okp1 '||l_where||
2908                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
2909                                      WHERE cle.dnz_chr_id = okh.id
2910                                      AND   cle.lse_id in (7,8,9,10,11,18,25,35))
2911                          AND  okh.id = okp1.chr_id
2912                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2913                          AND  okp1.object1_id1 = :update_level_value';
2914 
2915           ELSE
2916               -- dbms_output.put_line('Inside else');
2917              l_old_value := p_ctr_rec.old_value;
2918              l_stmt := l_select||' , :l_old_value old_value'||
2919                        l_from||' ,okc_k_party_roles_b okp1 '||l_where||
2920                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
2921                                      WHERE cle.dnz_chr_id = okh.id
2922                                      AND   cle.lse_id in (7,8,9,10,11,18,25,35)
2923                                      AND   cle.cognomen = :p_ctr_rec_old_value)
2924                          AND  okh.id = okp1.chr_id
2925                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2926                          AND  okp1.object1_id1 = :update_level_value';
2927 
2928           END IF;
2929 
2930  --------------------------------------------------------
2931  --  Update Level :  Party , Attribute: Contract Line Ref(CONTRACT_LINE_REF)
2932  --------------------------------------------------------
2933       ELSIF p_ctr_rec.attribute = 'CONTRACT_LINE_REF' THEN
2934 
2935 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
2936              l_stmt := l_select||' ,NULL old_value'||
2937                        l_from||' ,okc_k_party_roles_b okp1 '||l_where||
2938                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
2939                                      WHERE cle.chr_id = okh.id
2940                                      AND   cle.lse_id in (1,12,14,19)
2941                                      AND   cle.cognomen is NULL)
2942                          AND  okh.id = okp1.chr_id
2943                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2944                          AND  okp1.object1_id1 = :update_level_value';
2945 
2946           ELSIF p_ctr_rec.old_value = '-1111' THEN
2947 
2948              l_stmt := l_select||' ,NULL old_value'||
2949                        l_from||' ,okc_k_party_roles_b okp1 '||l_where||
2950                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
2951                                      WHERE cle.chr_id = okh.id
2952                                      AND   cle.lse_id in (1,12,14,19))
2953                          AND  okh.id = okp1.chr_id
2954                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2955                          AND  okp1.object1_id1 = :update_level_value';
2956 
2957           ELSE
2958               -- dbms_output.put_line('Inside else');
2959              l_old_value := p_ctr_rec.old_value;
2960              l_stmt := l_select||' , :l_old_value old_value'||
2961                        l_from||' ,okc_k_party_roles_b okp1 '||l_where||
2962                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
2963                                      WHERE cle.chr_id = okh.id
2964                                      AND   cle.lse_id in (1,12,14,19)
2965                                      AND   cle.cognomen = :p_ctr_rec_old_value)
2966                          AND  okh.id = okp1.chr_id
2967                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2968                          AND  okp1.object1_id1 = :update_level_value';
2969 
2970           END IF;
2971 
2972  -----------------------------------------------------------------------
2973  --  Update Level :  Party, Attribute: Header Ship-to Address(HDR_SHIP_TO_ADDRESS)
2974  ------------------------------------------------------------------------
2975       ELSIF p_ctr_rec.attribute = 'HDR_SHIP_TO_ADDRESS' THEN
2976 
2977       -- Old Value: NULL (-9999)
2978 	     IF  p_ctr_rec.old_value = '-9999' THEN
2979                  l_stmt := l_select||' ,NULL old_value' ||
2980                            l_from||',okc_k_party_roles_b okp1'||
2981                            l_where||' AND  okh.ship_to_site_use_id is NULL
2982                                   AND  okh.id = okp1.chr_id
2983                                   AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2984                                   AND  okp1.object1_id1 = :update_level_value';
2985 
2986        -- Old Value: Other than NULL or ALL
2987 
2988          ELSE
2989                  l_stmt := l_select||' ,okh.ship_to_site_use_id old_value' ||
2990                            l_from||',okc_k_party_roles_b okp1'||
2991                            l_where||' AND  okh.ship_to_site_use_id = to_number(:p_ctr_rec_old_value)
2992                                      AND  okh.id = okp1.chr_id
2993                                      AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
2994                                      AND  okp1.object1_id1 = :update_level_value';
2995          END IF;
2996 
2997 
2998 
2999  --------------------------------------------------------
3000  --  Update Level :  Party, Attribute: Header Bill-to Address(HDR_BILL_TO_ADDRESS)
3001  --------------------------------------------------------
3002       ELSIF p_ctr_rec.attribute = 'HDR_BILL_TO_ADDRESS' THEN
3003 
3004        -- Old Value: NULL (-9999)
3005 	     IF  p_ctr_rec.old_value = '-9999' THEN
3006                  l_stmt := l_select||' ,NULL old_value' ||
3007                            l_from||',okc_k_party_roles_b okp1'||
3008                            l_where||
3009                                    ' AND  okh.bill_to_site_use_id is NULL
3010                                      AND  okh.id = okp1.chr_id
3011                                      AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3012                                      AND  okp1.object1_id1 = :update_level_value';
3013        -- Old Value: Other than NULL or ALL
3014 
3015          ELSE
3016                  l_stmt := l_select||' ,okh.bill_to_site_use_id old_value' ||
3017                            l_from||',okc_k_party_roles_b okp1'||
3018                            l_where||
3019                                    ' AND  okh.bill_to_site_use_id = to_number(:p_ctr_rec_old_value)
3020                                      AND  okh.id = okp1.chr_id
3021                                      AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3022                                      AND  okp1.object1_id1 = :update_level_value';
3023          END IF;
3024 
3025 
3026  --------------------------------------------------------
3027  --  Update Level :  Party, Attribute: Sales Rep (SALES_REP)
3028  --------------------------------------------------------
3029       ELSIF p_ctr_rec.attribute = 'SALES_REP' THEN
3030 
3031 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3032              l_stmt := l_select||' ,NULL old_value'||
3033                        l_from||',okc_k_party_roles_b okp1 '||l_where||
3034                        ' AND EXISTS (Select ''x'' from okc_contacts oc
3035                                          where oc.dnz_chr_id = okh.id
3036                                          and   oc.cro_code = ''SALESPERSON''
3037                                          and   oc.object1_id1 is null
3038                                          and   oc.jtot_object1_code = ''OKX_SALEPERS'')
3039                          AND  okh.id = okp1.chr_id
3040                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3041                          AND  okp1.object1_id1 = :update_level_value';
3042 
3043           ELSIF p_ctr_rec.old_value = '-1111' THEN
3044              l_stmt := l_select||' ,oc.object1_id1 old_value'||
3045                        l_from||',okc_k_party_roles_b okp1, okc_contacts oc '||
3046                        l_where||
3047                         ' and oc.dnz_chr_id = okh.id
3048                           and   oc.cro_code = ''SALESPERSON''
3049                           and   oc.jtot_object1_code = ''OKX_SALEPERS'')
3050                          AND  okh.id = okp1.chr_id
3051                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3052                          AND  okp1.object1_id1 = :update_level_value';
3053 
3054           ELSE
3055              l_old_value := p_ctr_rec.old_value;
3056              l_stmt := l_select||' , :l_old_value old_value'||
3057                        l_from||',okc_k_party_roles_b okp1 '||l_where||
3058                        ' AND (EXISTS (Select ''x'' from okc_contacts oc
3059                                          where oc.dnz_chr_id = okh.id
3060                                          and   oc.cro_code = ''SALESPERSON''
3061                                          and   oc.object1_id1= :p_ctr_rec_old_value
3062                                          and   oc.jtot_object1_code = ''OKX_SALEPERS'')
3063                         OR EXISTS (Select ''x'' from oks_k_sales_credits_v osc
3064                                    Where osc.chr_id = okh.id
3065                                    and osc.ctc_id = to_number(:p_ctr_rec_old_value)))
3066                          AND  okh.id = okp1.chr_id
3067                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3068                          AND  okp1.object1_id1 = :update_level_value';
3069           END IF;
3070  ----------------------------------------------------------------------------------------
3071  --  Update Level :  Party , Attribute: Party Shipping Contact (PARTY_SHIPPING_CONTACT)
3072  ----------------------------------------------------------------------------------------
3073       ELSIF p_ctr_rec.attribute = 'PARTY_SHIPPING_CONTACT' THEN
3074 
3075 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3076              l_stmt := l_select||' ,NULL old_value'||
3077                        l_from||',okc_k_party_roles_b okp1 '||l_where||
3078                        ' AND EXISTS (Select ''x'' from okc_contacts oc
3079                                          where oc.dnz_chr_id = okh.id
3080                                          and   oc.cro_code = ''SHIPPING''
3081                                          and   oc.object1_id1 is null
3082                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
3083                          AND  okh.id = okp1.chr_id
3084                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3085                          AND  okp1.object1_id1 = :update_level_value';
3086 
3087           ELSIF p_ctr_rec.old_value = '-1111' THEN
3088              l_stmt := l_select||' ,oc.object1_id1 old_value'||
3089                        l_from||',okc_k_party_roles_b okp1, okc_contacts oc '||
3090                        l_where||
3091                         ' and oc.dnz_chr_id = okh.id
3092                           and   oc.cro_code = ''SHIPPING''
3093                           and   oc.jtot_object1_code = ''OKX_PCONTACT'')
3094                          AND  okh.id = okp1.chr_id
3095                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3096                          AND  okp1.object1_id1 = :update_level_value';
3097 
3098           ELSE
3099               -- dbms_output.put_line('Inside billing else');
3100              l_old_value := p_ctr_rec.old_value;
3101              l_stmt := l_select||' , :l_old_value old_value'||
3102                        l_from||',okc_k_party_roles_b okp1 '||l_where||
3103                        ' AND EXISTS (Select ''x'' from okc_contacts oc
3104                                          where oc.dnz_chr_id = okh.id
3105                                          and   oc.cro_code = ''SHIPPING''
3106                                          and   oc.object1_id1= :p_ctr_rec_old_value
3107                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
3108                          AND  okh.id = okp1.chr_id
3109                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3110                          AND  okp1.object1_id1 = :update_level_value';
3111           END IF;
3112 
3113  --------------------------------------------------------
3114  --  Update Level :  Party , Attribute: Party Billing Contact (PARTY_BILLING_CONTACT)
3115  --------------------------------------------------------
3116       ELSIF p_ctr_rec.attribute = 'PARTY_BILLING_CONTACT' THEN
3117 
3118 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3119              l_stmt := l_select||' ,NULL old_value'||
3120                        l_from||',okc_k_party_roles_b okp1 '||l_where||
3121                        ' AND EXISTS (Select ''x'' from okc_contacts oc
3122                                          where oc.dnz_chr_id = okh.id
3123                                          and   oc.cro_code = ''BILLING''
3124                                          and   oc.object1_id1 is null
3125                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
3126                          AND  okh.id = okp1.chr_id
3127                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3128                          AND  okp1.object1_id1 = :update_level_value';
3129 
3130           ELSIF p_ctr_rec.old_value = '-1111' THEN
3131              l_stmt := l_select||' ,oc.object1_id1 old_value'||
3132                        l_from||',okc_k_party_roles_b okp1, okc_contacts oc '||
3133                        l_where||
3134                         ' and oc.dnz_chr_id = okh.id
3135                           and   oc.cro_code = ''BILLING''
3136                           and   oc.jtot_object1_code = ''OKX_PCONTACT'')
3137                          AND  okh.id = okp1.chr_id
3138                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3139                          AND  okp1.object1_id1 = :update_level_value';
3140 
3141           ELSE
3142               -- dbms_output.put_line('Inside billing else');
3143              l_old_value := p_ctr_rec.old_value;
3144              l_stmt := l_select||' , :l_old_value old_value'||
3145                        l_from||',okc_k_party_roles_b okp1 '||l_where||
3146                        ' AND EXISTS (Select ''x'' from okc_contacts oc
3147                                          where oc.dnz_chr_id = okh.id
3148                                          and   oc.cro_code = ''BILLING''
3149                                          and   oc.object1_id1= :p_ctr_rec_old_value
3150                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
3151                          AND  okh.id = okp1.chr_id
3152                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3153                          AND  okp1.object1_id1 = :update_level_value';
3154 
3155           END IF;
3156 
3157  ----------------------------------------------------------------------------------------
3158  --  Update Level :  Party , Attribute: Line Shipping Contact (LINE_SHIPPING_CONTACT)
3159  ----------------------------------------------------------------------------------------
3160       ELSIF p_ctr_rec.attribute = 'LINE_SHIPPING_CONTACT' THEN
3161 
3162 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3163              l_stmt := l_select||' ,NULL old_value'||
3164                        l_from||',okc_k_party_roles_b okp1 '||l_where||
3165                        ' AND EXISTS (Select ''x'' from okc_contacts oc
3166                                          where oc.dnz_chr_id = okh.id
3167                                          and   oc.cro_code = ''CUST_SHIPPING''
3168                                          and   oc.object1_id1 is null
3169                                          and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
3170                          AND  okh.id = okp1.chr_id
3171                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3172                          AND  okp1.object1_id1 = :update_level_value';
3173 
3174           ELSIF p_ctr_rec.old_value = '-1111' THEN
3175              l_stmt := l_select||' ,oc.object1_id1 old_value'||
3176                        l_from||',okc_k_party_roles_b okp1, okc_contacts oc '||
3177                        l_where||
3178                         ' and oc.dnz_chr_id = okh.id
3179                           and   oc.cro_code = ''CUST_SHIPPING''
3180                           and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
3181                          AND  okh.id = okp1.chr_id
3182                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3183                          AND  okp1.object1_id1 = :update_level_value';
3184 
3185           ELSE
3186               -- dbms_output.put_line('Inside billing else');
3187              l_old_value := p_ctr_rec.old_value;
3188              l_stmt := l_select||' , :l_old_value old_value'||
3189                        l_from||',okc_k_party_roles_b okp1 '||l_where||
3190                        ' AND EXISTS (Select ''x'' from okc_contacts oc
3191                                          where oc.dnz_chr_id = okh.id
3192                                          and   oc.cro_code = ''CUST_SHIPPING''
3193                                          and   oc.object1_id1= :p_ctr_rec_old_value
3194                                          and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
3195                          AND  okh.id = okp1.chr_id
3196                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3197                          AND  okp1.object1_id1 = :update_level_value';
3198           END IF;
3199 
3200  --------------------------------------------------------
3201  --  Update Level :  Party , Attribute: Line Billing Contact (LINE_BILLING_CONTACT)
3202  --------------------------------------------------------
3203       ELSIF p_ctr_rec.attribute = 'LINE_BILLING_CONTACT' THEN
3204 
3205 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3206              l_stmt := l_select||' ,NULL old_value'||
3207                        l_from||',okc_k_party_roles_b okp1 '||l_where||
3208                        ' AND EXISTS (Select ''x'' from okc_contacts oc
3209                                          where oc.dnz_chr_id = okh.id
3210                                          and   oc.cro_code = ''CUST_BILLING''
3211                                          and   oc.object1_id1 is null
3212                                          and   oc.jtot_object1_code = ''OKX_CONTBILL'')
3213                          AND  okh.id = okp1.chr_id
3214                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3215                          AND  okp1.object1_id1 = :update_level_value';
3216 
3217           ELSIF p_ctr_rec.old_value = '-1111' THEN
3218              l_stmt := l_select||' ,oc.object1_id1 old_value'||
3219                        l_from||',okc_k_party_roles_b okp1, okc_contacts oc '||
3220                        l_where||
3221                         ' and oc.dnz_chr_id = okh.id
3222                           and   oc.cro_code = ''CUST_BILLING''
3223                           and   oc.jtot_object1_code = ''OKX_CONTBILL'')
3224                          AND  okh.id = okp1.chr_id
3225                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3226                          AND  okp1.object1_id1 = :update_level_value';
3227 
3228           ELSE
3229               -- dbms_output.put_line('Inside billing else');
3230              l_old_value := p_ctr_rec.old_value;
3231              l_stmt := l_select||' , :l_old_value old_value'||
3232                        l_from||',okc_k_party_roles_b okp1 '||l_where||
3233                        ' AND EXISTS (Select ''x'' from okc_contacts oc
3234                                          where oc.dnz_chr_id = okh.id
3235                                          and   oc.cro_code = ''CUST_BILLING''
3236                                          and   oc.object1_id1= :p_ctr_rec_old_value
3237                                          and   oc.jtot_object1_code = ''OKX_CONTBILL'')
3238                          AND  okh.id = okp1.chr_id
3239                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3240                          AND  okp1.object1_id1 = :update_level_value';
3241 
3242           END IF;
3243 
3244 
3245 
3246 --------------------------------------------------------
3247  --  Update Level : Party , Attribute: Coverage Start Time (COVERAGE_START_TIME)
3248  --------------------------------------------------------
3249       ELSIF p_ctr_rec.attribute = 'COVERAGE_START_TIME' THEN
3250 
3251     /*   -- Old Value: NULL (-9999)
3252 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3253              l_stmt := l_select||' ,NULL old_value'||
3254                        l_from||',okc_k_party_roles_b okp1 '||l_where||
3255                        ' AND EXISTS (Select ''x'' from okc_time_ig_startend_val_v igs
3256                                          where igs.dnz_chr_id = okh.id
3257                                          and   igs.start_hour is null
3258                                          and   igs.start_minute is null)
3259                          AND  okh.id = okp1.chr_id
3260                          AND  okp1.rle_code = ''CUSTOMER''
3261                          AND  okp1.object1_id1 = :update_level_value';
3262 
3263 
3264           ELSE
3265               -- dbms_output.put_line('Inside else');
3266              l_old_value := p_ctr_rec.old_value;
3267              l_stmt := l_select||' , :l_old_value old_value'||
3268                        l_from||',okc_k_party_roles_b okp1 '||l_where||
3269                        ' AND EXISTS (Select ''x'' from okc_time_ig_startend_val_v igs
3270                                       where igs.dnz_chr_id = okh.id
3271                                       and   igs.start_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
3272                                       AND   igs.start_minute = mod(to_number(:p_ctr_rec_old_value),60))
3273                          AND  okh.id = okp1.chr_id
3274                          AND  okp1.rle_code in = ''CUSTOMER''
3275                          AND  okp1.object1_id1 = :update_level_value';
3276 
3277           END IF;
3278           */
3279 
3280                  -- Old Value: NULL (-9999)
3281 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3282              l_stmt := l_select||' ,NULL old_value'||
3283                        l_from||',okc_k_party_roles_b okp1 '||
3284                        l_where||
3285                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
3286                                          where oct.dnz_chr_id = okh.id
3287                                          and   oct.start_hour is null
3288                                          and   oct.start_minute is null)
3289                         AND okh.org_id = to_number(:update_level_value)';
3290 
3291           ELSE
3292               -- dbms_output.put_line('Inside else');
3293              l_old_value := p_ctr_rec.old_value;
3294              l_stmt := l_select||' , :l_old_value old_value'||
3295                        l_from||',okc_k_party_roles_b okp1 '||
3296                        l_where||
3297                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
3298                                      where oct.dnz_chr_id = okh.id
3299                                      and   oct.start_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
3300                                      and   oct.start_minute = mod(to_number(:p_ctr_rec_old_value),60))
3301                          AND  okh.id = okp1.chr_id
3302                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3303                          AND  okp1.object1_id1 = :update_level_value';
3304           END IF;
3305 
3306 
3307 
3308 --------------------------------------------------------
3309  --  Update Level : Party , Attribute: Coverage Time (COVERAGE_END_TIME)
3310  --------------------------------------------------------
3311       ELSIF p_ctr_rec.attribute = 'COVERAGE_END_TIME' THEN
3312 
3313   /*     -- Old Value: NULL (-9999)
3314 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3315              l_stmt := l_select||' ,NULL old_value'||
3316                        l_from||',okc_k_party_roles_b okp1 '||l_where||
3317                        ' AND EXISTS (Select ''x'' from okc_time_ig_startend_val_v igs
3318                                          where igs.dnz_chr_id = okh.id
3319                                          and     igs.end_hour is null
3320                                          and   igs.end_minute is null)
3321                          AND  okh.id = okp1.chr_id
3322                          AND  okp1.rle_code = ''CUSTOMER''
3323                          AND  okp1.object1_id1 = :update_level_value';
3324 
3325 
3326           ELSE
3327               -- dbms_output.put_line('Inside else');
3328              l_old_value := p_ctr_rec.old_value;
3329              l_stmt := l_select||' , :l_old_value old_value'||
3330                        l_from||',okc_k_party_roles_b okp1 '||l_where||
3331                        ' AND EXISTS (Select ''x'' from okc_time_ig_startend_val_v igs
3332                                       where igs.dnz_chr_id = okh.id
3333                                       and  igs.end_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
3334                                       AND   igs.end_minute = mod(to_number(:p_ctr_rec_old_value),60))
3335                          AND  okh.id = okp1.chr_id
3336                          AND  okp1.rle_code = ''CUSTOMER''
3337                          AND  okp1.object1_id1 = :update_level_value';
3338 
3339           END IF;
3340           */
3341         -- Old Value: NULL (-9999)
3342 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3343              l_stmt := l_select||' ,NULL old_value'||
3344                        l_from||',okc_k_party_roles_b okp1 '||
3345                        l_where||
3346                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
3347                                          where oct.dnz_chr_id = okh.id
3348                                          and   oct.end_hour is null
3349                                          and   oct.end_minute is null)
3350                          AND  okh.id = okp1.chr_id
3351                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3352                          AND  okp1.object1_id1 = :update_level_value';
3353 
3354          ELSE
3355              l_old_value := p_ctr_rec.old_value;
3356              l_stmt := l_select||' , :l_old_value old_value'||
3357                        l_from||',okc_k_party_roles_b okp1 '||
3358                        l_where||
3359                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
3360                                      where oct.dnz_chr_id = okh.id
3361                                      and   oct.end_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
3362                                      and   oct.end_minute = mod(to_number(:p_ctr_rec_old_value),60))
3363                          AND  okh.id = okp1.chr_id
3364                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3365                          AND  okp1.object1_id1 = :update_level_value';
3366          END IF;
3367 
3368  --------------------------------------------------------
3369  --  Update Level : Party , Attribute: Resolution Time (RESOLUTION_TIME)
3370  --------------------------------------------------------
3371       ELSIF p_ctr_rec.attribute = 'RESOLUTION_TIME' THEN
3372 
3373        -- Old Value: NULL (-9999)
3374 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3375              l_stmt := l_select||', NULL old_value'||
3376                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat,okc_k_party_roles_b okp1 '|| l_where||
3377                        ' AND kl.dnz_chr_id = okh.id
3378 		         AND kl.id = att.cle_id
3379                          And kl.lse_id in (4,17,22)
3380                          AND   att.action_type_code = ''RSN''
3381                          AND   att.id = oat.cov_action_type_id
3382                          AND   ( sun_duration IS NULL
3383                                  OR mon_duration IS NULL
3384                                  OR tue_duration IS NULL
3385                                  OR wed_duration IS NULL
3386                                  OR thu_duration IS NULL
3387                                  OR fri_duration IS NULL
3388                                  OR sat_duration IS NULL)
3389                          AND  okp1.dnz_chr_id = okh.id  And okp1.cle_id Is Null
3390                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3391                          AND  okp1.object1_id1 = :update_level_value';
3392 
3393  -- Old Value: Other than NULL or ALL
3394 
3395           ELSE
3396               -- dbms_output.put_line('Inside else 111111');
3397             l_old_value := p_ctr_rec.old_value;
3398             l_stmt := l_select||' , :l_old_value old_value'||
3399                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat,okc_k_party_roles_b okp1 '||l_where||
3400                        ' AND kl.dnz_chr_id = okh.id
3401 		         AND kl.id = att.cle_id
3402                          And kl.lse_id in (4,17,22)
3403                          AND   att.action_type_code = ''RSN''
3404                          AND   att.id = oat.cov_action_type_id
3405                          AND   ( sun_duration = :p_ctr_rec_old_value
3406                                                OR mon_duration = :p_ctr_rec_old_value
3407                                                OR tue_duration = :p_ctr_rec_old_value
3408                                                OR wed_duration = :p_ctr_rec_old_value
3409                                                OR thu_duration = :p_ctr_rec_old_value
3410                                                OR fri_duration = :p_ctr_rec_old_value
3411                                                OR sat_duration = :p_ctr_rec_old_value)
3412                          AND  okp1.dnz_chr_id = okh.id  And okp1.cle_id Is Null
3413                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3414                          AND  okp1.object1_id1 = :update_level_value';
3415           END IF;
3416 
3417  --------------------------------------------------------
3418  --  Update Level : Party , Attribute: Reaction Time (REACTION_TIME)
3419  --------------------------------------------------------
3420       ELSIF p_ctr_rec.attribute = 'REACTION_TIME' THEN
3421 
3422        -- Old Value: NULL (-9999)
3423 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3424                        l_stmt := l_select||', NULL old_value'||
3425                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat,okc_k_party_roles_b okp1 '||l_where||
3426                        '  AND kl.dnz_chr_id = okh.id
3427 		          AND kl.id = att.cle_id
3428                           And kl.lse_id in (4,17,22)
3429                          AND   att.action_type_code = ''RCN''
3430                          AND   att.id = oat.cov_action_type_id
3431                          AND   ( sun_duration IS NULL
3432                                                OR mon_duration IS NULL
3433                                                OR tue_duration IS NULL
3434                                                OR wed_duration IS NULL
3435                                                OR thu_duration IS NULL
3436                                                OR fri_duration IS NULL
3437                                                OR sat_duration IS NULL)
3438                         AND  okp1.dnz_chr_id = okh.id  And okp1.cle_id Is Null
3439                         AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3440                         AND  okp1.object1_id1 = :update_level_value';
3441          -- Old Value: Other than NULL or ALL
3442 
3443           ELSE
3444 
3445              l_old_value := p_ctr_rec.old_value;
3446              l_stmt := l_select||' , :l_old_value old_value'||
3447                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat,okc_k_party_roles_b okp1 '||l_where||
3448                        '  AND kl.dnz_chr_id = okh.id
3449 		          AND kl.id = att.cle_id
3450                           And kl.lse_id in (4,17,22)
3451                          AND   att.action_type_code = ''RCN''
3452                          AND   att.id = oat.cov_action_type_id
3453                          AND   ( sun_duration = :p_ctr_rec_old_value
3454                                                OR mon_duration = :p_ctr_rec_old_value
3455                                                OR tue_duration = :p_ctr_rec_old_value
3456                                                OR wed_duration = :p_ctr_rec_old_value
3457                                                OR thu_duration = :p_ctr_rec_old_value
3458                                                OR fri_duration = :p_ctr_rec_old_value
3459                                                OR sat_duration = :p_ctr_rec_old_value)
3460                         AND  okp1.dnz_chr_id = okh.id  And okp1.cle_id Is Null
3461                         AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3462                         AND  okp1.object1_id1 = :update_level_value';
3463 
3464           END IF;
3465 
3466 
3467  --------------------------------------------------------
3468  --  Update Level : Party , Attribute: Price List(PRICE_LIST)
3469  --------------------------------------------------------
3470       ELSIF p_ctr_rec.attribute = 'PRICE_LIST' THEN
3471        -- Old Value: NULL (-9999)
3472 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3473 
3474               l_stmt := l_select||' ,NULL old_value'||
3475                         l_from||' ,okc_k_party_roles_b okp1'||
3476                         l_where||
3477                          ' AND  okh.price_list_id is NULL
3478                            AND  okh.id = okp1.chr_id
3479                            AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3480                            AND  okp1.object1_id1 = :update_level_value';
3481 
3482        -- Old Value: ALL (-1111)
3483 
3484           ELSIF p_ctr_rec.old_value = '-1111' THEN
3485 
3486              l_stmt := l_select||' ,okh.price_list_id old_value' ||
3487                        l_from||' ,okc_k_party_roles_b okp1'||
3488                        l_where||
3489                          ' AND  okh.id = okp1.chr_id
3490                            AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3491                            AND  okp1.object1_id1 = :update_level_value';
3492 
3493 
3494         -- Old Value: Other than NULL or ALL
3495 
3496           ELSE
3497 
3498              l_stmt := l_select||' ,okh.price_list_id old_value' ||
3499                        l_from||' ,okc_k_party_roles_b okp1'||
3500                        l_where||
3501                        ' AND  okh.price_list_id = to_number(:p_ctr_rec_old_value)
3502                          AND  okh.id = okp1.chr_id
3503                          AND  okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3504                          AND  okp1.object1_id1 = :update_level_value';
3505 
3506           END IF;
3507 
3508  ------------------------------------------------------------------------------------------
3509  --  Update Level : Party , Attribute: Known As( CONTRACT_ALIAS )
3510  ------------------------------------------------------------------------------------------
3511 
3512 	   ELSIF p_ctr_rec.attribute = 'CONTRACT_ALIAS' THEN
3513 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3514              l_stmt := l_select||' ,NULL old_value '||
3515                        l_from||', okc_k_party_roles_b okp1'||
3516                        l_where||'AND okh.cognomen IS NULL
3517                                  AND okh.id = okp1.chr_id
3518                                  AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3519                                  AND okp1.object1_id1 = :update_level_value';
3520 
3521           ELSIF p_ctr_rec.old_value = '-1111' THEN -- For old Value as ALL
3522 
3523              l_stmt := l_select||' ,okh.cognomen old_value'||
3524                        l_from||', okc_k_party_roles_b okp1 '||
3525                        l_where||' AND okh.id = okp1.chr_id
3526                                   AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3527                                   AND okp1.object1_id1 = :update_level_value';
3528 
3529           ELSE
3530              l_stmt := l_select||', okh.cognomen  old_value'||
3531                        l_from||', okc_k_party_roles_b okp1'||
3532                        l_where||' AND okh.cognomen = :p_ctr_rec_old_value
3533                                   AND okh.id = okp1.chr_id
3534                                   AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3535                                   AND okp1.object1_id1 = :update_level_value';
3536           END IF;
3537 
3538  ------------------------------------------------------------------------------------------
3539  --  Update Level : Party , Attribute: Purchase Order Number (PO_NUMBER_BILL)
3540  ------------------------------------------------------------------------------------------
3541 
3542 	   ELSIF p_ctr_rec.attribute = 'PO_NUMBER_BILL' THEN
3543 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3544              l_stmt := l_select||' ,NULL old_value '||
3545                        l_from||', okc_k_party_roles_b okp1'||
3546                        l_where||'AND okh.cust_po_number IS NULL
3547                                  AND okh.id = okp1.chr_id
3548                                  AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3549                                  AND ( okh.payment_instruction_type  Is Null Or okh.payment_instruction_type = ''PON'')
3550                                  AND okp1.object1_id1 = :update_level_value';
3551 
3552           ELSIF p_ctr_rec.old_value = '-1111' THEN -- For old Value as ALL
3553              If p_ctr_rec.new_value Is Null Then
3554                 l_stmt := l_select||' ,okh.cust_po_number old_value'||
3555                        l_from||', okc_k_party_roles_b okp1 '||
3556                        l_where||' AND okh.id = okp1.chr_id
3557                                   AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3558                                   AND okh.payment_instruction_type = ''PON''
3559                                   AND okp1.object1_id1 = :update_level_value and okh.cust_po_number_req_yn <> ''Y''';
3560 	     Else
3561                 l_stmt := l_select||' ,okh.cust_po_number old_value'||
3562                        l_from||', okc_k_party_roles_b okp1 '||
3563                        l_where||' AND okh.id = okp1.chr_id
3564                                   AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3565                                   AND okh.payment_instruction_type = ''PON''
3566                                   AND okp1.object1_id1 = :update_level_value';
3567 
3568 
3569 
3570 
3571 	     End If;
3572 
3573           ELSE
3574 
3575 	     If p_ctr_rec.new_value Is Null Then
3576 
3577                 l_stmt := l_select||', okh.cust_po_number old_value'||
3578                        l_from||', okc_k_party_roles_b okp1'||
3579                        l_where||' AND okh.cust_po_number = :p_ctr_rec_old_value
3580                                   AND okh.id = okp1.chr_id
3581                                   AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3582                                   AND okh.payment_instruction_type = ''PON''
3583                                   AND okp1.object1_id1 = :update_level_value and okh.cust_po_number_req_yn <> ''Y''';
3584 	     Else
3585 
3586                 l_stmt := l_select||', okh.cust_po_number old_value'||
3587                        l_from||', okc_k_party_roles_b okp1'||
3588                        l_where||' AND okh.cust_po_number = :p_ctr_rec_old_value
3589                                   AND okh.id = okp1.chr_id
3590                                   AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3591                                   AND okh.payment_instruction_type = ''PON''
3592                                   AND okp1.object1_id1 = :update_level_value';
3593 
3594 
3595 
3596 	     End If;
3597 
3598           END IF;
3599 
3600  -----------------------------------------------------------------------------
3601  --  Update Level : Party , Attribute: PO NUMBER Required(PO_REQUIRED_REN)
3602  -----------------------------------------------------------------------------
3603       ELSIF p_ctr_rec.attribute = 'PO_REQUIRED_REN' THEN
3604 
3605 
3606            IF p_ctr_rec.old_value = '-1111' THEN
3607 
3608              l_old_value := p_ctr_rec.old_value;
3609              l_stmt := l_select||' , :l_old_value old_value'||
3610                        l_from||', okc_k_party_roles_b okp1'||
3611                        l_where||'AND okh.id = okp1.chr_id
3612                                 AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3613                                 AND okp1.object1_id1 = :update_level_value';
3614 
3615      -- Old Value: Other than NULL or ALL
3616            ELSE
3617 
3618              l_old_value := p_ctr_rec.old_value;
3619              l_stmt := l_select||' , :l_old_value old_value'||
3620                         l_from||', okc_k_party_roles_b okp1 ,oks_k_headers_v oksh '||
3621                         l_where||' AND oksh.chr_id = okh.id
3622                                    AND nvl(oksh.renewal_po_required,''N'') = :p_ctr_rec_old_value
3623                                    AND okh.id = okp1.chr_id
3624                                    AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3625                                    AND okp1.object1_id1 = :update_level_value';
3626            END IF ;
3627 
3628  --------------------------------------------------------
3629  --  Update Level : Party , Attribute: Summary Print(SUMMARY_PRINT)
3630  --------------------------------------------------------
3631       ELSIF p_ctr_rec.attribute = 'SUMMARY_PRINT' THEN
3632 
3633        -- Old Value:ALL (-1111)
3634 
3635         IF p_ctr_rec.old_value = '-1111' THEN
3636             l_old_value := p_ctr_rec.old_value;
3637             l_stmt := l_select||' , :l_old_value old_value'||
3638                       l_from||', okc_k_party_roles_b okp1 ,oks_k_headers_v oksh '||
3639                       l_where||' AND oksh.chr_id = okh.id
3640                                  AND okh.id = okp1.chr_id
3641                                  AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3642                                  AND okp1.object1_id1 = :update_level_value';
3643 
3644 
3645       -- Old Value: Other than NULL or ALL
3646 
3647         ELSE
3648               l_old_value := p_ctr_rec.old_value;
3649               l_stmt := l_select||' , :l_old_value old_value'||
3650                         l_from||', okc_k_party_roles_b okp1 ,oks_k_headers_v oksh '||
3651                         l_where||' AND oksh.chr_id = okh.id
3652                                    AND nvl(oksh.inv_print_profile,''N'') = :p_ctr_rec_old_value
3653                                    AND okh.id = okp1.chr_id
3654                                    AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3655                                    AND okp1.object1_id1 = :update_level_value';
3656 
3657         END IF ;
3658 
3659  ------------------------------------------------------------------------------------------
3660  --  Update Level : Party , Attribute: Contract Group (CONTRACT_GROUP)
3661  ------------------------------------------------------------------------------------------
3662 
3663 	   ELSIF p_ctr_rec.attribute = 'CONTRACT_GROUP' THEN
3664 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3665              l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
3666                        l_from||',okc_k_groups_grpings_v okg, okc_k_party_roles_b okp1'||
3667                        l_where||' AND okg.included_chr_id = okh.id
3668      					          AND okg.cgp_parent_id is NULL
3669                                   AND okh.id = okp1.chr_id
3670                                   AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3671                                   AND okp1.object1_id1 = :update_level_value';
3672 /*
3673              l_stmt := l_select||' ,NULL old_value'||
3674                        l_from||',okc_k_party_roles_b okp1'||
3675                        l_where||' AND EXISTS (SELECT id from okc_k_headers_v a
3676                                     WHERE a.id = okh.id
3677                                     MINUS
3678                                     SELECT okg.included_chr_id
3679                                     FROM okc_k_groups_grpings_v okg
3680 									WHERE okg.included_chr_id = okh.id)
3681                                   AND okh.id = okp1.chr_id
3682                                   AND okp1.rle_code = ''CUSTOMER''
3683                                   AND okp1.object1_id1 = :update_level_value';
3684 */
3685 
3686           ELSIF p_ctr_rec.old_value = '-1111' THEN -- For old Value as ALL
3687              l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
3688                        l_from||',okc_k_groups_grpings_v okg, okc_k_party_roles_b okp1'||
3689                        l_where||' AND okg.included_chr_id = okh.id
3690                                   AND okh.id = okp1.chr_id
3691                                   AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3692                                   AND okp1.object1_id1 = :update_level_value';
3693           ELSE
3694 
3695              l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
3696                        l_from||',okc_k_groups_grpings_v okg, okc_k_party_roles_b okp1'||
3697                        l_where||' AND okg.included_chr_id = okh.id
3698      					          AND okg.cgp_parent_id = to_number(:p_ctr_rec_old_value)
3699                                   AND okh.id = okp1.chr_id
3700                                   AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3701                                   AND okp1.object1_id1 = :update_level_value';
3702           END IF;
3703  ------------------------------------------------------------------------------------------
3704  --  Update Level : Party , Attribute: Contract Start date (CONTRACT_START_DATE)
3705  ------------------------------------------------------------------------------------------
3706 
3707         ELSIF p_ctr_rec.attribute = 'CONTRACT_START_DATE' Then
3708 
3709           IF p_ctr_rec.old_value is NULL THEN   -- For Contract Start date as NULL
3710              l_stmt:= l_select||',to_char(okh.start_date) old_value '||
3711                       l_from||', okc_k_party_roles_b okp1'||
3712                       l_where||' AND okh.start_date is NULL
3713                                   AND okh.id = okp1.chr_id
3714                                   AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3715                                   AND okp1.object1_id1 = :update_level_value';
3716           ELSIF p_ctr_rec.old_value is not NULL THEN   -- For Contract Start date not NULL
3717              l_stmt:= l_select||',to_char(okh.start_date) old_value '||
3718                       l_from||', okc_k_party_roles_b okp1'||
3719                       l_where||'  AND trunc(okh.start_date) = trunc(to_date(:p_ctr_rec_old_value,''YYYY/MM/DD HH24:MI:SS''))
3720                                   AND okh.id = okp1.chr_id
3721                                   AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3722                                   AND okp1.object1_id1 = :update_level_value';
3723           END IF;
3724  ------------------------------------------------------------------------------------------
3725  --  Update Level : Party , Attribute: Contract End date (CONTRACT_END_DATE)
3726  ------------------------------------------------------------------------------------------
3727 
3728         ELSIF p_ctr_rec.attribute = 'CONTRACT_END_DATE' Then
3729 
3730           IF p_ctr_rec.old_value is NULL THEN   -- For Contract End date as NULL
3731              l_stmt := l_select||',to_char(okh.end_date) old_value'||
3732                        l_from||', okc_k_party_roles_b okp1'||
3733                        l_where||' AND okh.end_date is NULL
3734                                   AND okh.id = okp1.chr_id
3735                                   AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3736                                   AND okp1.object1_id1 = :update_level_value';
3737 
3738           ELSIF p_ctr_rec.old_value is not NULL THEN   -- For Contract End date not NULL
3739              l_stmt := l_select||',to_char(okh.end_date) old_value'||
3740                        l_from||', okc_k_party_roles_b okp1'||
3741                        l_where||' AND trunc(okh.end_date) = trunc(to_date(:p_ctr_rec_old_value,''YYYY/MM/DD HH24:MI:SS''))
3742                                   AND okh.id = okp1.chr_id
3743                                   AND okp1.rle_code in (''CUSTOMER'',''SUBSCRIBER'')
3744                                   AND okp1.object1_id1 = :update_level_value';
3745            END IF;
3746         END IF;
3747 
3748  ----------------------------------
3749  --  Update Level : Category
3750  ----------------------------------
3751 
3752  ELSIF p_ctr_rec.update_level = 'OKS_K_CATEGORY' THEN
3753 
3754 
3755 ---------------------------------------------------------------------
3756  --  Update Level : Category , Attribute: Revenue Account(REV_ACCT)
3757  ---------------------------------------------------------------------
3758       IF p_ctr_rec.attribute = 'REV_ACCT' THEN
3759 
3760 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3761              l_stmt := l_select||' ,NULL old_value'||
3762                        l_from||l_where||
3763                        ' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
3764                                      WHERE rev.chr_id = okh.id
3765                                      AND   rev.code_combination_id is NULL)
3766                         AND  okh.scs_code = :update_level_value';
3767 
3768           ELSIF p_ctr_rec.old_value = '-1111' THEN
3769 
3770              l_stmt := l_select||' ,NULL old_value'||
3771                        l_from||l_where||
3772                        ' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
3773                                      WHERE rev.chr_id = okh.id)
3774                         AND  okh.scs_code = :update_level_value';
3775 
3776           ELSE
3777              l_old_value := p_ctr_rec.old_value;
3778              l_stmt := l_select||' , :l_old_value old_value'||
3779                        l_from||l_where||
3780                        ' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
3781                                      WHERE rev.chr_id = okh.id
3782                                      AND   rev.code_combination_id = to_number(:p_ctr_rec_old_value))
3783                         AND  okh.scs_code = :update_level_value';
3784           END IF;
3785 
3786  --------------------------------------------------------------------------
3787  --  Update Level : Category , Attribute: Payment Term (PAYMENT_TERM)
3788  --------------------------------------------------------------------------
3789 
3790       ELSIF p_ctr_rec.attribute = 'PAYMENT_TERM' THEN
3791 
3792          IF    p_ctr_rec.old_value = '-9999' THEN
3793 
3794                        l_stmt := l_select||' ,NULL old_value' ||
3795                        l_from||l_where||
3796                        ' AND  okh.PAYMENT_TERM_ID is NULL
3797                          AND  okh.scs_code = :update_level_value';
3798 
3799         -- Old Value: ALL (-1111)
3800 
3801           ELSIF p_ctr_rec.old_value = '-1111' THEN
3802                        l_stmt := l_select||' ,okh.payment_term_id old_value' ||
3803                        l_from||l_where||
3804                                'AND  okh.scs_code = :update_level_value';
3805        -- Old Value: Other than NULL or ALL
3806 
3807           ELSE
3808 
3809              l_stmt := l_select||' ,okh.payment_term_id old_value' ||
3810                        l_from||l_where||
3811                        ' AND  okh.payment_term_id = to_number(:p_ctr_rec_old_value)
3812                          AND  okh.scs_code = :update_level_value';
3813 
3814           END IF;
3815 
3816 -------------------------------------------------------------------------------------
3817  --  Update Level : Category , Attribute: Contract Renewal Type(CON_RENEWAL_TYPE)
3818 ------------------------------------------------------------------------------------
3819       ELSIF p_ctr_rec.attribute = 'CON_RENEWAL_TYPE' THEN
3820 
3821        -- Old Value: NULL (-9999)
3822 	     IF    p_ctr_rec.old_value = '-9999' THEN
3823 
3824                        l_stmt := l_select||' ,NULL old_value' ||
3825                        l_from||
3826                        l_where||
3827                        ' AND  okh.renewal_type_code is NULL
3828                          AND not exists(
3829                                         select ol.object_chr_id
3830                                         from okc_operation_lines ol
3831                                             ,okc_operation_instances oi
3832                                             ,okc_class_operations co
3833                                         WHERE ol.object_chr_id = okh.id
3834                                           AND ol.process_flag = ''P''
3835                                           AND ol.ACTIVE_YN    = ''Y''
3836                                           AND oi.id = ol.oie_id
3837                                           AND oi.cop_id = co.id
3838                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
3839                                           AND co.CLS_CODE = ''SERVICE'')
3840                          AND  okh.scs_code = :update_level_value';
3841 
3842          ELSIF p_ctr_rec.old_value = '-1111' THEN
3843                        l_old_value := p_ctr_rec.old_value;
3844                        l_stmt := l_select||' , :l_old_value old_value' ||
3845                        l_from||
3846                        l_where||
3847                               ' AND not exists(
3848                                         select ol.object_chr_id
3849                                         from okc_operation_lines ol
3850                                             ,okc_operation_instances oi
3851                                             ,okc_class_operations co
3852                                         WHERE ol.object_chr_id = okh.id
3853                                           AND ol.process_flag = ''P''
3854                                           AND ol.ACTIVE_YN    = ''Y''
3855                                           AND oi.id = ol.oie_id
3856                                           AND oi.cop_id = co.id
3857                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
3858                                           AND co.CLS_CODE = ''SERVICE'')
3859                                 AND  okh.scs_code = :update_level_value';
3860 
3861  -- Old Value: ERN
3862 
3863           ELSIF p_ctr_rec.old_value = 'ERN' then
3864              l_old_value := p_ctr_rec.old_value;
3865              l_stmt := l_select||' , :l_old_value old_value' ||
3866                        l_from||' ,oks_k_headers_b oksh'||
3867                        l_where||
3868                        ' AND oksh.chr_id = okh.id
3869                          AND okh.renewal_type_code = ''NSR''
3870                          AND ''ERN'' = :p_ctr_rec_old_value
3871                          AND oksh.ELECTRONIC_RENEWAL_FLAG = ''Y''
3872                          AND not exists(
3873                                         select ol.object_chr_id
3874                                         from okc_operation_lines ol
3875                                             ,okc_operation_instances oi
3876                                             ,okc_class_operations co
3877                                         WHERE ol.object_chr_id = okh.id
3878                                           AND ol.process_flag = ''P''
3879                                           AND ol.ACTIVE_YN    = ''Y''
3880                                           AND oi.id = ol.oie_id
3881                                           AND oi.cop_id = co.id
3882                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
3883                                           AND co.CLS_CODE = ''SERVICE'')
3884                          AND  okh.scs_code = :update_level_value';
3885 
3886  -- Old Value: Other than NULL or ALL
3887 
3888           ELSE
3889              l_old_value := p_ctr_rec.old_value;
3890              l_stmt := l_select||' , :l_old_value old_value' ||
3891                        l_from||' ,oks_k_headers_b oksh'||
3892                        l_where||
3893                        ' AND oksh.chr_id = okh.id
3894                          AND okh.renewal_type_code = :p_ctr_rec_old_value
3895                          AND nvl(oksh.ELECTRONIC_RENEWAL_FLAG,''N'') <> ''Y''
3896                          AND not exists(
3897                                         select ol.object_chr_id
3898                                         from okc_operation_lines ol
3899                                             ,okc_operation_instances oi
3900                                             ,okc_class_operations co
3901                                         WHERE ol.object_chr_id = okh.id
3902                                           AND ol.process_flag = ''P''
3903                                           AND ol.ACTIVE_YN    = ''Y''
3904                                           AND oi.id = ol.oie_id
3905                                           AND oi.cop_id = co.id
3906                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
3907                                           AND co.CLS_CODE = ''SERVICE'')
3908                          AND  okh.scs_code = :update_level_value';
3909           END IF;
3910 
3911  ---------------------------------------------------------------------------
3912  --  Update Level : Category , Attribute: Business Process Price List (BP_PRICE_LIST)
3913  ---------------------------------------------------------------------------
3914       ELSIF p_ctr_rec.attribute = 'BP_PRICE_LIST' THEN
3915 
3916      -- Old Value: NULL (-9999)
3917 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3918               l_stmt := l_select||' ,NULL old_value' ||
3919                         l_from||
3920                         l_where|| 'AND exists ( Select dnz_chr_id from okc_k_lines_b cln
3921                                           Where cln.dnz_chr_id = okh.id
3922                                             AND cln.lse_id in(3,16,21)
3923                                             AND cln.price_list_id is NULL)
3924                                    AND okh.scs_code = :update_level_value';
3925 
3926      -- Old Value: ALL (-1111)
3927           ELSIF p_ctr_rec.old_value = '-1111' THEN
3928              l_old_value := p_ctr_rec.old_value;
3929              l_stmt := l_select||' , :l_old_value old_value' ||
3930                        l_from||
3931                        l_where|| ' AND exists ( Select dnz_chr_id from okc_k_lines_b cln
3932                                           Where cln.dnz_chr_id = okh.id
3933                                             AND cln.lse_id in(3,16,21))
3934                                    AND  okh.scs_code = :update_level_value';
3935 
3936      -- Old Value: Other than NULL or ALL
3937           ELSE
3938              l_old_value := p_ctr_rec.old_value;
3939              l_stmt := l_select||' , :l_old_value old_value' ||
3940                        l_from||
3941                        l_where|| ' AND exists ( Select dnz_chr_id from okc_k_lines_b cln
3942                                       Where cln.dnz_chr_id = okh.id
3943                                       AND cln.lse_id in(3,16,21)
3944                                       AND cln.price_list_id = to_number(:p_ctr_rec_old_value))
3945                                   AND  okh.scs_code = :update_level_value';
3946 
3947           END IF;
3948 
3949  --------------------------------------------------------------------------
3950  --  Update Level : Category , Attribute: Accounting Rule (ACCT_RULE)
3951  --------------------------------------------------------------------------
3952 
3953       ELSIF p_ctr_rec.attribute = 'ACCT_RULE' THEN
3954 
3955      -- Old Value: ALL (-9999)
3956  	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
3957 
3958               l_stmt := l_select||' ,NULL old_value' ||
3959                         l_from||' ,oks_k_headers_v oksh '||
3960                         l_where|| 'AND oksh.chr_id = okh.id
3961                                    AND oksh.acct_rule_id IS NULL
3962                                    AND okh.scs_code = :update_level_value';
3963      -- Old Value: ALL (-1111)
3964 
3965           ELSIF p_ctr_rec.old_value = '-1111' THEN
3966              l_stmt := l_select||' ,oksh.acct_rule_id old_value' ||
3967                        l_from||' ,oks_k_headers_v oksh '||
3968                        l_where|| 'AND oksh.chr_id = okh.id
3969                                   AND okh.scs_code = :update_level_value';
3970      -- Old Value: Other than NULL or ALL
3971 
3972           ELSE
3973              l_stmt := l_select||' ,oksh.acct_rule_id old_value' ||
3974                        l_from||' ,oks_k_headers_v oksh '||
3975                        l_where|| 'AND oksh.chr_id = okh.id
3976                                   AND oksh.acct_rule_id = to_number(:p_ctr_rec_old_value)
3977                                   AND okh.scs_code = :update_level_value';
3978           END IF;
3979 
3980 --------------------------------------------------------------------------
3981  --  Update Level : Category , Attribute: Invoice Rule (INV_RULE)
3982 --------------------------------------------------------------------------
3983 
3984       ELSIF p_ctr_rec.attribute = 'INV_RULE' THEN
3985 
3986 
3987        -- Old Value: NULL (-9999)
3988          IF  p_ctr_rec.old_value = '-9999' THEN
3989 
3990              l_stmt := l_select||' ,NULL old_value' ||
3991                        l_from||l_where||
3992                              ' AND  okh.inv_rule_id IS NULL
3993                                AND  okh.scs_code = :update_level_value';
3994 
3995        -- Old Value: ALL (-1111)
3996          ELSIF p_ctr_rec.old_value = '-1111' THEN
3997                     l_stmt := l_select||' ,okh.inv_rule_id old_value' ||
3998                               l_from||l_where||
3999                                     ' AND  okh.scs_code = :update_level_value';
4000 
4001        -- Old Value: Other than NULL or ALL
4002 
4003           ELSE
4004                 --errorout_n('in here'||l_select||l_from||l_where);
4005 
4006                 l_stmt := l_select||' ,okh.inv_rule_id old_value' ||
4007                           l_from||l_where||
4008                                 ' AND  okh.inv_rule_id = to_number(:p_ctr_rec_old_value)
4009                                   AND  okh.scs_code = :update_level_value';
4010 --errorout_n('in here'||l_stmt);
4011           END IF;
4012 
4013 ---------------------------------------------------------------------------
4014  --  Update Level : Category , Attribute: Coverage Type(COV_TYPE)
4015  ---------------------------------------------------------------------------
4016       ELSIF p_ctr_rec.attribute = 'COV_TYPE' THEN
4017 
4018         -- Old Value: NULL (-9999)
4019 	     IF p_ctr_rec.old_value = '-9999' THEN
4020              l_stmt := l_select||' ,NULL old_value'||
4021                        l_from||l_where||
4022                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V okl, oks_k_lines_v oksl
4023                                              WHERE okl.dnz_chr_id = okh.id
4024                                              AND oksl.cle_id = okl.id
4025                                              AND oksl.coverage_type is NULL )
4026                                              AND  okh.scs_code = :update_level_value';
4027 
4028         -- Old Value: ALL
4029 
4030           ELSIF p_ctr_rec.old_value = '-1111' THEN
4031 
4032                 l_old_value := p_ctr_rec.old_value;
4033                 l_stmt := l_select||' , :l_old_value old_value'||
4034                           l_from||
4035                           l_where||'AND EXISTS (SELECT ''x'' from okc_k_lines_v okl, oks_k_lines_v oksl
4036                                     WHERE okl.dnz_chr_id = okh.id
4037                                     AND oksl.cle_id = okl.id )
4038                                     AND  okh.scs_code = :update_level_value';
4039          -- Old Value: Other than NULL or ALL
4040           ELSE
4041                  l_old_value := p_ctr_rec.old_value;
4042                  l_stmt := l_select||' , :l_old_value old_value'||
4043                            l_from||
4044                            l_where||'AND EXISTS (SELECT ''x'' from okc_k_lines_v okl, oks_k_lines_v oksl
4045                                      WHERE okl.dnz_chr_id = okh.id
4046                                      AND oksl.cle_id = okl.id
4047                                      AND oksl.coverage_type = :p_ctr_rec_old_value )
4048                                      AND  okh.scs_code = :update_level_value';
4049 
4050           END IF;
4051 
4052  ---------------------------------------------------------------------------
4053  --  Update Level : Category , Attribute: Coverage Time zone(COV_TIMEZONE)
4054  ---------------------------------------------------------------------------
4055       ELSIF p_ctr_rec.attribute = 'COV_TIMEZONE' THEN
4056 
4057        -- Old Value: NULL (-9999)
4058 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4059              l_stmt := l_select||' ,NULL old_value'||
4060                        l_from||l_where||
4061                        ' AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
4062                                       WHERE ctz.dnz_chr_id = okh.id
4063                                       AND   ctz.timezone_id IS NULL )
4064                          AND  okh.scs_code = :update_level_value' ;
4065 
4066        -- Old Value: ALL (-1111)
4067           ELSIF p_ctr_rec.old_value = '-1111' THEN
4068 
4069              l_old_value := p_ctr_rec.old_value;
4070              l_stmt := l_select||' , :l_old_value old_value'||
4071                        l_from||
4072                        l_where||'AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
4073                                              WHERE ctz.dnz_chr_id = okh.id
4074                                              AND   ctz.timezone_id IS NOT NULL )
4075                                              AND  okh.scs_code = :update_level_value' ;
4076         -- Old Value: Other than NULL or ALL
4077           ELSE
4078 
4079              l_old_value := p_ctr_rec.old_value;
4080              l_stmt := l_select||' , :l_old_value old_value'||
4081                        l_from||
4082                        l_where||'AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
4083                                              WHERE ctz.dnz_chr_id = okh.id
4084                                              AND  ctz.timezone_id = to_number(:p_ctr_rec_old_value))
4085                                              AND  okh.scs_code = :update_level_value' ;
4086 
4087           END IF;
4088  ---------------------------------------------------------------------------
4089  --  Update Level : Category , Attribute: Prferred Engineer (PREF_ENGG)
4090  ---------------------------------------------------------------------------
4091       ELSIF p_ctr_rec.attribute = 'PREF_ENGG' THEN
4092 
4093 	     IF p_ctr_rec.old_value = '-1111' THEN
4094 
4095                 l_old_value := p_ctr_rec.old_value;
4096                 l_stmt := l_select||' , :l_old_value old_value'||
4097                        l_from||
4098                        l_where||'AND EXISTS (SELECT ''x'' from
4099                                              okc_contacts oco
4100                                              WHERE oco.dnz_chr_id = okh.id
4101                                              AND   oco.cro_code = ''ENGINEER''
4102                                              AND   oco.jtot_object1_code = ''OKX_RESOURCE'')
4103                                  AND  okh.scs_code = :update_level_value';
4104 
4105           ELSE
4106              l_old_value := p_ctr_rec.old_value;
4107              l_stmt := l_select||' , :l_old_value old_value'||
4108                        l_from||
4109                        l_where||'AND EXISTS (SELECT ''x'' from
4110                                              okc_contacts oco
4111                                              WHERE oco.dnz_chr_id = okh.id
4112                                              AND   oco.cro_code = ''ENGINEER''
4113                                              AND   oco.jtot_object1_code = ''OKX_RESOURCE''
4114                                              AND   oco.object1_id1  = :p_ctr_rec_old_value)
4115                                  AND   okh.scs_code = :update_level_value';
4116           END IF;
4117  ---------------------------------------------------------------------------
4118  --  Update Level : Category , Attribute: Preferred Resource group(RES_GROUP)
4119  ---------------------------------------------------------------------------
4120       ELSIF p_ctr_rec.attribute = 'RES_GROUP' THEN
4121 
4122 	     IF p_ctr_rec.old_value = '-1111' THEN
4123 
4124              l_old_value := p_ctr_rec.old_value;
4125              l_stmt := l_select||' , :l_old_value old_value'||
4126                        l_from||
4127                        l_where||'AND EXISTS (SELECT ''x'' from
4128                                              okc_contacts oco
4129                                              WHERE oco.dnz_chr_id = okh.id
4130                                              AND   oco.cro_code = ''RSC_GROUP''
4131                                              AND   oco.jtot_object1_code = ''OKS_RSCGROUP'')
4132                                              AND  okh.scs_code = :update_level_value';
4133 
4134           ELSE
4135              l_old_value := p_ctr_rec.old_value;
4136              l_stmt := l_select||' , :l_old_value old_value'||
4137                        l_from||
4138                        l_where||'AND EXISTS (SELECT ''x'' from
4139                                              okc_contacts oco
4140                                              WHERE oco.dnz_chr_id = okh.id
4141                                              AND   oco.cro_code = ''RSC_GROUP''
4142                                              AND   oco.jtot_object1_code = ''OKS_RSCGROUP''
4143                                              AND   oco.object1_id1  = :p_ctr_rec_old_value)
4144                                              AND  okh.scs_code = :update_level_value';
4145           END IF;
4146 
4147 
4148  ---------------------------------------------------------------------------
4149  --  Update Level : Category , Attribute: Coverage Type(AGREEMENT_NAME)
4150  ---------------------------------------------------------------------------
4151       ELSIF p_ctr_rec.attribute = 'AGREEMENT_NAME' THEN
4152 
4153              l_old_value := p_ctr_rec.old_value;
4154              l_stmt := l_select||' , :l_old_value old_value'||
4155                        l_from||
4156                        l_where||'AND EXISTS (SELECT ''x'' from okc_governances_v ogv
4157                                              WHERE ogv.dnz_chr_id = okh.id
4158                                              AND   ogv.isa_agreement_id = :p_ctr_rec_old_value)
4159                                              AND   okh.scs_code=:update_level_value';
4160 
4161  ---------------------------------------------------------------------
4162  --  Update Level : Category , Attribute: Product Alias(PRODUCT_ALIAS)
4163  ---------------------------------------------------------------------
4164       ELSIF p_ctr_rec.attribute = 'PRODUCT_ALIAS' THEN
4165 
4166 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4167              l_stmt := l_select||' ,NULL old_value'||
4168                        l_from||l_where||
4169                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
4170                                      WHERE cle.dnz_chr_id = okh.id
4171                                      AND   cle.lse_id IN (7,8,9,10,11,18,25,35)
4172                                      AND   cle.cognomen is NULL)
4173                         AND  okh.scs_code = :update_level_value';
4174           ELSIF p_ctr_rec.old_value = '-1111' THEN
4175 
4176              l_stmt := l_select||' ,NULL old_value'||
4177                        l_from||l_where||
4178                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
4179                                      WHERE cle.dnz_chr_id = okh.id
4180                                      AND   cle.lse_id IN (7,8,9,10,11,18,25,35))
4181                         AND  okh.scs_code = :update_level_value';
4182 
4183           ELSE
4184              l_old_value := p_ctr_rec.old_value;
4185              l_stmt := l_select||' , :l_old_value old_value'||
4186                        l_from||l_where||
4187                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
4188                                      WHERE cle.dnz_chr_id = okh.id
4189                                      AND   cle.lse_id IN (7,8,9,10,11,18,25,35)
4190                                      AND   cle.cognomen = :p_ctr_rec_old_value)
4191                         AND  okh.scs_code = :update_level_value';
4192 
4193           END IF;
4194 
4195  ---------------------------------------------------------
4196  --  Update Level : Category , Attribute: Contract Line Ref(CONTRACT_LINE_REF)
4197  --------------------------------------------------------
4198       ELSIF p_ctr_rec.attribute = 'CONTRACT_LINE_REF' THEN
4199 
4200          IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4201              l_stmt := l_select||' ,NULL old_value'||
4202                        l_from||l_where||
4203                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
4204                                      WHERE cle.chr_id = okh.id
4205                                      AND   cle.lse_id IN (1,12,14,19)
4206                                      AND   cle.cognomen is NULL)
4207                         AND  okh.scs_code = :update_level_value';
4208 
4209          ELSIF p_ctr_rec.old_value = '-1111' THEN
4210 
4211              l_stmt := l_select||' ,NULL old_value'||
4212                        l_from||l_where||
4213                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
4214                                      WHERE cle.chr_id = okh.id
4215                                      AND   cle.lse_id IN (1,12,14,19))
4216                         AND  okh.scs_code = :update_level_value';
4217           ELSE
4218              l_old_value := p_ctr_rec.old_value;
4219              l_stmt := l_select||' , :l_old_value old_value'||
4220                        l_from||l_where||
4221                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
4222                                      WHERE cle.chr_id = okh.id
4223                                      AND   cle.lse_id IN (1,12,14,19)
4224                                      AND   cle.cognomen = :p_ctr_rec_old_value)
4225                         AND  okh.scs_code = :update_level_value';
4226 
4227           END IF;
4228 
4229  --------------------------------------------------------
4230  --  Update Level : Category , Attribute: Header Ship-to Address(HDR_SHIP_TO_ADDRESS)
4231  --------------------------------------------------------
4232       ELSIF p_ctr_rec.attribute = 'HDR_SHIP_TO_ADDRESS' THEN
4233 
4234        -- Old Value: NULL (-9999)
4235 	     IF  p_ctr_rec.old_value = '-9999' THEN
4236                  l_stmt := l_select||' ,NULL old_value' ||
4237                            l_from||l_where||
4238                                 ' AND  okh.ship_to_site_use_id is NULL
4239                                   AND  okh.scs_code = :update_level_value';
4240 
4241        -- Old Value: Other than NULL or ALL
4242 
4243          ELSE
4244                  l_stmt := l_select||' ,okh.ship_to_site_use_id old_value' ||
4245                            l_from||l_where||
4246                                    ' AND  okh.ship_to_site_use_id = to_number(:p_ctr_rec_old_value)
4247                                      AND  okh.scs_code = :update_level_value';
4248          END IF;
4249 
4250 
4251  --------------------------------------------------------------------------------------
4252  --  Update Level : Category , Attribute: Header Bill-to Address(HDR_BILL_TO_ADDRESS)
4253  --------------------------------------------------------------------------------------
4254       ELSIF p_ctr_rec.attribute = 'HDR_BILL_TO_ADDRESS' THEN
4255 
4256         -- Old Value: NULL (-9999)
4257 	     IF  p_ctr_rec.old_value = '-9999' THEN
4258                  l_stmt := l_select||' ,NULL old_value' ||
4259                            l_from||l_where||
4260                                    ' AND  okh.bill_to_site_use_id is NULL
4261                                      AND  okh.scs_code = :update_level_value';
4262        -- Old Value: Other than NULL or ALL
4263 
4264          ELSE
4265                  l_stmt := l_select||' ,okh.bill_to_site_use_id old_value' ||
4266                            l_from||l_where||
4267                                    ' AND  okh.bill_to_site_use_id = to_number(:p_ctr_rec_old_value)
4268                                      AND  okh.scs_code = :update_level_value';
4269          END IF;
4270 
4271  --------------------------------------------------------
4272  --  Update Level : Category , Attribute: Sales Rep (SALES_REP)
4273  --------------------------------------------------------
4274       ELSIF p_ctr_rec.attribute = 'SALES_REP' THEN
4275 
4276 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4277              l_stmt := l_select||' ,NULL old_value'||
4278                        l_from||l_where||
4279                        ' AND EXISTS (Select ''x'' from okc_contacts oc
4280                                          where oc.dnz_chr_id = okh.id
4281                                          and   oc.cro_code = ''SALESPERSON''
4282                                          and   oc.object1_id1 is null
4283                                          and   oc.jtot_object1_code = ''OKX_SALEPERS'')
4284                         AND  okh.scs_code = :update_level_value';
4285           ELSIF p_ctr_rec.old_value = '-1111' THEN
4286               -- dbms_output.put_line('Inside else ALL SALES_REP');
4287              l_stmt := l_select||' ,oc.object1_id1 old_value '||
4288                        l_from||', okc_contacts oc '||
4289                        l_where||' and oc.dnz_chr_id = okh.id
4290                           and   oc.cro_code = ''SALESPERSON''
4291                           and   oc.jtot_object1_code = ''OKX_SALEPERS''
4292                        AND  okh.scs_code = :update_level_value';
4293           ELSE
4294               -- dbms_output.put_line('Inside else');
4295              l_old_value := p_ctr_rec.old_value;
4296              l_stmt := l_select||' , :l_old_value old_value'||
4297                        l_from||l_where||
4298                        ' AND (EXISTS (Select ''x'' from okc_contacts oc
4299                                          where oc.dnz_chr_id = okh.id
4300                                          and   oc.cro_code = ''SALESPERSON''
4301                                          and   oc.object1_id1=:p_ctr_rec_old_value
4302                                          and   oc.jtot_object1_code = ''OKX_SALEPERS'')
4303                          OR EXISTS (Select ''x'' from oks_k_sales_credits_v osc
4304                                    Where osc.chr_id = okh.id
4305                                    and osc.ctc_id = to_number(:p_ctr_rec_old_value)))
4306                          AND  okh.scs_code = :update_level_value';
4307 
4308           END IF;
4309 
4310  ----------------------------------------------------------------------------------------
4311  --  Update Level : Category , Attribute: Party Shipping Contact (PARTY_SHIPPING_CONTACT)
4312  ----------------------------------------------------------------------------------------
4313       ELSIF p_ctr_rec.attribute = 'PARTY_SHIPPING_CONTACT' THEN
4314 
4315 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4316              l_stmt := l_select||' ,NULL old_value'||
4317                        l_from||l_where||
4318                        ' AND EXISTS (Select ''x'' from okc_contacts oc
4319                                          where oc.dnz_chr_id = okh.id
4320                                          and   oc.cro_code = ''SHIPPING''
4321                                          and   oc.object1_id1 is null
4322                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
4323                         AND  okh.scs_code = :update_level_value';
4324 
4325           ELSIF p_ctr_rec.old_value = '-1111' THEN
4326              l_stmt := l_select||' ,oc.object1_id1 old_value'||
4327                        l_from||', okc_contacts oc '||
4328                        l_where||
4329                         ' and oc.dnz_chr_id = okh.id
4330                           and   oc.cro_code = ''SHIPPING''
4331                           and   oc.jtot_object1_code = ''OKX_PCONTACT'')
4332                        AND  okh.scs_code = :update_level_value';
4333 
4334 
4335           ELSE
4336 
4337              l_old_value := p_ctr_rec.old_value;
4338              l_stmt := l_select||' , :l_old_value old_value'||
4339                        l_from||l_where||
4340                        ' AND EXISTS (Select ''x'' from okc_contacts oc
4341                                          where oc.dnz_chr_id = okh.id
4342                                          and   oc.cro_code = ''SHIPPING''
4343                                          and   oc.object1_id1=:p_ctr_rec_old_value
4344                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
4345                          AND  okh.scs_code = :update_level_value';
4346 
4347           END IF;
4348 
4349  --------------------------------------------------------
4350  --  Update Level : Category , Attribute: Party Billing Contact (PARTY_BILLING_CONTACT)
4351  --------------------------------------------------------
4352       ELSIF p_ctr_rec.attribute = 'PARTY_BILLING_CONTACT' THEN
4353 
4354 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4355              l_stmt := l_select||' ,NULL old_value'||
4356                        l_from||l_where||
4357                        ' AND EXISTS (Select ''x'' from okc_contacts oc
4358                                          where oc.dnz_chr_id = okh.id
4359                                          and   oc.cro_code = ''BILLING''
4360                                          and   oc.object1_id1 is null
4361                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
4362                         AND  okh.scs_code = :update_level_value';
4363 
4364           ELSIF p_ctr_rec.old_value = '-1111' THEN
4365              l_stmt := l_select||' ,oc.object1_id1 old_value'||
4366                        l_from||', okc_contacts oc '||
4367                        l_where||
4368                         ' and oc.dnz_chr_id = okh.id
4369                           and   oc.cro_code = ''BILLING''
4370                           and   oc.jtot_object1_code = ''OKX_PCONTACT'')
4371                        AND  okh.scs_code = :update_level_value';
4372 
4373           ELSE
4374               -- dbms_output.put_line('Inside billing else');
4375              l_old_value := p_ctr_rec.old_value;
4376              l_stmt := l_select||' , :l_old_value old_value'||
4377                        l_from||l_where||
4378                        ' AND EXISTS (Select ''x'' from okc_contacts oc
4379                                          where oc.dnz_chr_id = okh.id
4380                                          and   oc.cro_code = ''BILLING''
4381                                          and   oc.object1_id1=:p_ctr_rec_old_value
4382                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
4383                          AND  okh.scs_code = :update_level_value';
4384 
4385           END IF;
4386 
4387  ----------------------------------------------------------------------------------------
4388  --  Update Level : Category , Attribute: Line Shipping Contact (LINE_SHIPPING_CONTACT)
4389  ----------------------------------------------------------------------------------------
4390       ELSIF p_ctr_rec.attribute = 'LINE_SHIPPING_CONTACT' THEN
4391 
4392 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4393              l_stmt := l_select||' ,NULL old_value'||
4394                        l_from||l_where||
4395                        ' AND EXISTS (Select ''x'' from okc_contacts oc
4396                                          where oc.dnz_chr_id = okh.id
4397                                          and   oc.cro_code = ''CUST_SHIPPING''
4398                                          and   oc.object1_id1 is null
4399                                          and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
4400                         AND  okh.scs_code = :update_level_value';
4401 
4402           ELSIF p_ctr_rec.old_value = '-1111' THEN
4403              l_stmt := l_select||' ,oc.object1_id1 old_value'||
4404                        l_from||', okc_contacts oc '||
4405                        l_where||
4406                         ' and oc.dnz_chr_id = okh.id
4407                           and   oc.cro_code = ''CUST_SHIPPING''
4408                           and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
4409                        AND  okh.scs_code = :update_level_value';
4410 
4411 
4412           ELSE
4413 
4414              l_old_value := p_ctr_rec.old_value;
4415              l_stmt := l_select||' , :l_old_value old_value'||
4416                        l_from||l_where||
4417                        ' AND EXISTS (Select ''x'' from okc_contacts oc
4418                                          where oc.dnz_chr_id = okh.id
4419                                          and   oc.cro_code = ''CUST_SHIPPING''
4420                                          and   oc.object1_id1=:p_ctr_rec_old_value
4421                                          and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
4422                          AND  okh.scs_code = :update_level_value';
4423 
4424           END IF;
4425 
4426  --------------------------------------------------------
4427  --  Update Level : Category , Attribute: Line Billing Contact (LINE_BILLING_CONTACT)
4428  --------------------------------------------------------
4429       ELSIF p_ctr_rec.attribute = 'LINE_BILLING_CONTACT' THEN
4430 
4431 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4432              l_stmt := l_select||' ,NULL old_value'||
4433                        l_from||l_where||
4434                        ' AND EXISTS (Select ''x'' from okc_contacts oc
4435                                          where oc.dnz_chr_id = okh.id
4436                                          and   oc.cro_code = ''CUST_BILLING''
4437                                          and   oc.object1_id1 is null
4438                                          and   oc.jtot_object1_code = ''OKX_CONTBILL'')
4439                         AND  okh.scs_code= = :update_level_value';
4440 
4441           ELSIF p_ctr_rec.old_value = '-1111' THEN
4442              l_stmt := l_select||' ,oc.object1_id1 old_value'||
4443                        l_from||', okc_contacts oc '||
4444                        l_where||
4445                         ' and oc.dnz_chr_id = okh.id
4446                           and   oc.cro_code = ''CUST_BILLING''
4447                           and   oc.jtot_object1_code = ''OKX_CONTBILL'')
4448                        AND  okh.scs_code = :update_level_value';
4449 
4450           ELSE
4451               -- dbms_output.put_line('Inside billing else');
4452              l_old_value := p_ctr_rec.old_value;
4453              l_stmt := l_select||' , :l_old_value old_value'||
4454                        l_from||l_where||
4455                        ' AND EXISTS (Select ''x'' from okc_contacts oc
4456                                          where oc.dnz_chr_id = okh.id
4457                                          and   oc.cro_code = ''CUST_BILLING''
4458                                          and   oc.object1_id1= :p_ctr_rec_old_value
4459                                          and   oc.jtot_object1_code = ''OKX_CONTBILL'')
4460                          AND  okh.scs_code = :update_level_value';
4461 
4462           END IF;
4463 
4464  --------------------------------------------------------
4465  --  Update Level : Category , Attribute: Coverage Time (COVERAGE_TIME)
4466  --------------------------------------------------------
4467       ELSIF p_ctr_rec.attribute = 'COVERAGE_TIME' THEN
4468 
4469        -- Old Value: NULL (-9999)
4470 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4471              l_stmt := l_select||' ,NULL old_value'||
4472                        l_from||l_where||
4473                        ' AND EXISTS (Select ''x'' from okc_time_ig_startend_val_v igs
4474                                          where igs.dnz_chr_id = okh.id
4475                                          and   ((igs.start_hour is null
4476                                          and   igs.start_minute is null)
4477                                          OR
4478                                          (     igs.end_hour is null
4479                                          and   igs.end_minute is null))
4480                         AND  okh.scs_code = :update_level_value';
4481 
4482           ELSE
4483               -- dbms_output.put_line('Inside else');
4484              l_old_value := p_ctr_rec.old_value;
4485              l_stmt := l_select||' , :l_old_value old_value'||
4486                        l_from||l_where||
4487                        ' AND EXISTS (Select ''x'' from okc_time_ig_startend_val_v igs
4488                                       where igs.dnz_chr_id = okh.id
4489                                       and  (( igs.start_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
4490                                       AND   igs.start_minute = mod(to_number(:p_ctr_rec_old_value),60))
4491                                       OR
4492                                       ( igs.end_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
4493                                       AND   igs.end_minute = mod(to_number(:p_ctr_rec_old_value),60)))
4494                          AND  okh.scs_code = :update_level_value';
4495 
4496           END IF;
4497 
4498  --------------------------------------------------------
4499  --  Update Level : Category , Attribute: Coverage Start Time (COVERAGE_START_TIME)
4500  --------------------------------------------------------
4501       ELSIF p_ctr_rec.attribute = 'COVERAGE_START_TIME' THEN
4502 
4503        -- Old Value: NULL (-9999)
4504 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4505              l_stmt := l_select||' ,NULL old_value'||
4506                        l_from||l_where||
4507                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
4508                                          where oct.dnz_chr_id = okh.id
4509                                          and   oct.start_hour is null
4510                                          and   oct.start_minute is null)
4511                         AND  okh.scs_code = :update_level_value';
4512 
4513           ELSE
4514        -- dbms_output.put_line('Inside else');
4515              l_old_value := p_ctr_rec.old_value;
4516              l_stmt := l_select||' , :l_old_value old_value'||
4517                        l_from||l_where||
4518                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
4519                                      where oct.dnz_chr_id = okh.id
4520                                      and   oct.start_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
4521                                      and   oct.start_minute = mod(to_number(:p_ctr_rec_old_value),60))
4522                          AND  okh.scs_code = :update_level_value';
4523           END IF;
4524 
4525  --------------------------------------------------------
4526  --  Update Level : Category , Attribute: Coverage End Time (COVERAGE_END_TIME)
4527  --------------------------------------------------------
4528       ELSIF p_ctr_rec.attribute = 'COVERAGE_END_TIME' THEN
4529 
4530        -- Old Value: NULL (-9999)
4531 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4532              l_stmt := l_select||' ,NULL old_value'||
4533                        l_from||l_where||
4534                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
4535                                          where oct.dnz_chr_id = okh.id
4536                                          and   oct.end_hour is null
4537                                          and   oct.end_minute is null)
4538                         AND  okh.scs_code = :update_level_value';
4539 
4540          ELSE
4541              l_old_value := p_ctr_rec.old_value;
4542              l_stmt := l_select||' , :l_old_value old_value'||
4543                        l_from||l_where||
4544                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
4545                                      where oct.dnz_chr_id = okh.id
4546                                      and   oct.end_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
4547                                      and   oct.end_minute = mod(to_number(:p_ctr_rec_old_value),60))
4548                         AND  okh.scs_code = :update_level_value';
4549          END IF;
4550 
4551  --------------------------------------------------------
4552  --  Update Level : Category , Attribute: Resolution Time (RESOLUTION_TIME)
4553  --------------------------------------------------------
4554       ELSIF p_ctr_rec.attribute = 'RESOLUTION_TIME' THEN
4555 
4556         -- Old Value: NULL (-9999)
4557 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4558              l_stmt := l_select||', NULL old_value'||
4559                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '|| l_where||
4560                        ' AND kl.dnz_chr_id = okh.id
4561 		         AND kl.id = att.cle_id
4562                          And kl.lse_id in (4,17,22)
4563                          AND   att.action_type_code = ''RSN''
4564                          AND   att.id = oat.cov_action_type_id
4565                          AND   ( sun_duration IS NULL
4566                                  OR mon_duration IS NULL
4567                                  OR tue_duration IS NULL
4568                                  OR wed_duration IS NULL
4569                                  OR thu_duration IS NULL
4570                                  OR fri_duration IS NULL
4571                                  OR sat_duration IS NULL)
4572 
4573                         AND  okh.scs_code = :update_level_value';
4574        -- Old Value: Other than NULL or ALL
4575 
4576           ELSE
4577               -- dbms_output.put_line('Inside else 111111');
4578             l_old_value := p_ctr_rec.old_value;
4579             l_stmt := l_select||' , :l_old_value old_value'||
4580                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '||l_where||
4581                        ' AND kl.dnz_chr_id = okh.id
4582 		         AND kl.id = att.cle_id
4583                          And kl.lse_id in (4,17,22)
4584                          AND   att.action_type_code = ''RSN''
4585                          AND   att.id = oat.cov_action_type_id
4586                          AND   ( sun_duration = :p_ctr_rec_old_value
4587                                                OR mon_duration = :p_ctr_rec_old_value
4588                                                OR tue_duration = :p_ctr_rec_old_value
4589                                                OR wed_duration = :p_ctr_rec_old_value
4590                                                OR thu_duration = :p_ctr_rec_old_value
4591                                                OR fri_duration = :p_ctr_rec_old_value
4592                                                OR sat_duration = :p_ctr_rec_old_value)
4593                         AND  okh.scs_code = :update_level_value';
4594           END IF;
4595 
4596  --------------------------------------------------------
4597  --  Update Level : Category , Attribute: Reaction Time (REACTION_TIME)
4598  --------------------------------------------------------
4599       ELSIF p_ctr_rec.attribute = 'REACTION_TIME' THEN
4600 
4601    -- Old Value: NULL (-9999)
4602 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4603                        l_stmt := l_select||', NULL old_value'||
4604                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '||l_where||
4605                        '  AND kl.dnz_chr_id = okh.id
4606 		          AND kl.id = att.cle_id
4607                           And kl.lse_id in (4,17,22)
4608                          AND   att.action_type_code = ''RCN''
4609                          AND   att.id = oat.cov_action_type_id
4610                          AND   ( sun_duration IS NULL
4611                                                OR mon_duration IS NULL
4612                                                OR tue_duration IS NULL
4613                                                OR wed_duration IS NULL
4614                                                OR thu_duration IS NULL
4615                                                OR fri_duration IS NULL
4616                                                OR sat_duration IS NULL)
4617                         AND  okh.scs_code = :update_level_value';
4618     -- Old Value: Other than NULL or ALL
4619           ELSE
4620              l_old_value := p_ctr_rec.old_value;
4621              l_stmt := l_select||' , :l_old_value old_value'||
4622                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '||l_where||
4623                        '  AND kl.dnz_chr_id = okh.id
4624 		          AND kl.id = att.cle_id
4625                           And kl.lse_id in (4,17,22)
4626                          AND   att.action_type_code = ''RCN''
4627                          AND   att.id = oat.cov_action_type_id
4628                          AND   ( sun_duration = :p_ctr_rec_old_value
4629                                                OR mon_duration = :p_ctr_rec_old_value
4630                                                OR tue_duration = :p_ctr_rec_old_value
4631                                                OR wed_duration = :p_ctr_rec_old_value
4632                                                OR thu_duration = :p_ctr_rec_old_value
4633                                                OR fri_duration = :p_ctr_rec_old_value
4634                                                OR sat_duration = :p_ctr_rec_old_value)
4635                         AND  okh.scs_code = :update_level_value';
4636 
4637           END IF;
4638 
4639  --------------------------------------------------------
4640  --  Update Level : Category , Attribute: Price List(PRICE_LIST)
4641  --------------------------------------------------------
4642       ELSIF p_ctr_rec.attribute = 'PRICE_LIST' THEN
4643 
4644         -- Old Value: NULL (-9999)
4645 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4646 
4647               l_stmt := l_select||' ,NULL old_value'||
4648                         l_from||l_where||
4649                          ' AND  okh.price_list_id is NULL
4650                            AND okh.scs_code = :update_level_value';
4651        -- Old Value: ALL (-1111)
4652 
4653           ELSIF p_ctr_rec.old_value = '-1111' THEN
4654 
4655              l_stmt := l_select||' ,okh.price_list_id old_value' ||
4656                          l_from||l_where||
4657                          ' AND okh.scs_code = :update_level_value';
4658         -- Old Value: Other than NULL or ALL
4659 
4660           ELSE
4661 
4662              l_stmt := l_select||' ,okh.price_list_id old_value' ||
4663                        l_from||l_where||
4664                        ' AND  okh.price_list_id = to_number(:p_ctr_rec_old_value)
4665                          AND okh.scs_code = :update_level_value';
4666 
4667           END IF;
4668 
4669 
4670  ------------------------------------------------------------------------------------------
4671  --  Update Level : Category , Attribute:Known As (CONTRACT_ALIAS)
4672  ------------------------------------------------------------------------------------------
4673 
4674 	   ELSIF p_ctr_rec.attribute = 'CONTRACT_ALIAS' THEN
4675 
4676 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4677              l_stmt := l_select||' ,NULL old_value '||
4678                        l_from||
4679                        l_where||'AND okh.cognomen IS NULL
4680                                  AND okh.scs_code = :update_level_value';
4681 
4682          ELSIF p_ctr_rec.old_value = '-1111' THEN -- For old Value as ALL
4683 
4684              l_stmt := l_select||' ,okh.cognomen old_value'||
4685                        l_from||
4686                        l_where||' AND okh.scs_code = :update_level_value';
4687 
4688          ELSE
4689              l_stmt := l_select||' ,okh.cognomen old_value'||
4690                        l_from||
4691                        l_where||' AND okh.cognomen = :p_ctr_rec_old_value
4692                                   AND okh.scs_code = :update_level_value';
4693          END IF;
4694 
4695  ------------------------------------------------------------------------------------------
4696  --  Update Level : Category , Attribute: Purchase Order Number (PO_NUMBER_BILL)
4697  ------------------------------------------------------------------------------------------
4698 
4699 	   ELSIF p_ctr_rec.attribute = 'PO_NUMBER_BILL' THEN
4700 
4701 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4702              l_stmt := l_select||' ,NULL old_value '||
4703                        l_from||
4704                        l_where||'AND okh.cust_po_number IS NULL
4705                                  AND ( okh.payment_instruction_type  Is Null Or okh.payment_instruction_type = ''PON'')
4706                                  AND okh.scs_code = :update_level_value';
4707 
4708          ELSIF p_ctr_rec.old_value = '-1111' THEN -- For old Value as ALL
4709            If p_ctr_rec.new_value is Null Then
4710              l_stmt := l_select||' ,okh.cust_po_number old_value'||
4711                        l_from||
4712                        l_where||' AND okh.payment_instruction_type = ''PON'' AND okh.scs_code = :update_level_value and okh.cust_po_number_req_yn <> ''Y''';
4713 
4714            Else
4715 	                l_stmt := l_select||' ,okh.cust_po_number old_value'||
4716                        l_from||
4717                        l_where||'AND okh.payment_instruction_type = ''PON'' AND okh.scs_code = :update_level_value ';
4718 
4719 	   End If;
4720          ELSE
4721            If p_ctr_rec.new_value is Null Then
4722 
4723              l_stmt := l_select||' ,okh.cust_po_number old_value'||
4724                        l_from||
4725                        l_where||' AND okh.cust_po_number = :p_ctr_rec_old_value
4726                                   AND okh.payment_instruction_type = ''PON''
4727                                   AND okh.scs_code = :update_level_value and okh.cust_po_number_req_yn <> ''Y''';
4728 
4729 	   Else
4730              l_stmt := l_select||' ,okh.cust_po_number old_value'||
4731                        l_from||
4732                        l_where||' AND okh.cust_po_number = :p_ctr_rec_old_value AND okh.payment_instruction_type = ''PON''
4733                                  AND okh.scs_code = :update_level_value ';
4734 	 End If;
4735          END IF;
4736 
4737  -----------------------------------------------------------------------------
4738  --  Update Level : Category , Attribute: PO NUMBER Required(PO_REQUIRED_REN)
4739  -----------------------------------------------------------------------------
4740       ELSIF p_ctr_rec.attribute = 'PO_REQUIRED_REN' THEN
4741 
4742 
4743            IF p_ctr_rec.old_value = '-1111' THEN
4744 
4745              l_old_value := p_ctr_rec.old_value;
4746              l_stmt := l_select||' , :l_old_value old_value'||
4747                        l_from||
4748                        l_where||
4749                        'AND okh.scs_code = :update_level_value';
4750 
4751      -- Old Value: Other than NULL or ALL
4752            ELSE
4753 
4754              l_old_value := p_ctr_rec.old_value;
4755              l_stmt := l_select||' , :l_old_value old_value'||
4756                         l_from||' ,oks_k_headers_v oksh '||
4757                         l_where||' AND oksh.chr_id = okh.id
4758                                    AND nvl(oksh.renewal_po_required,''N'') = :p_ctr_rec_old_value
4759                                    AND okh.scs_code = :update_level_value';
4760            END IF ;
4761 
4762  --------------------------------------------------------
4763  --  Update Level : Category , Attribute: Summary Print(SUMMARY_PRINT)
4764  --------------------------------------------------------
4765       ELSIF p_ctr_rec.attribute = 'SUMMARY_PRINT' THEN
4766 
4767        -- Old Value: ALL (-1111)
4768         IF p_ctr_rec.old_value = '-1111' THEN
4769             l_stmt := l_select||' , :l_old_value old_value'||
4770                       l_from||' ,oks_k_headers_v oksh '||
4771                       l_where||' AND oksh.chr_id = okh.id
4772                                  AND okh.scs_code = :update_level_value';
4773 
4774 
4775       -- Old Value: Other than NULL or ALL
4776         ELSE
4777               l_old_value := p_ctr_rec.old_value;
4778               l_stmt := l_select||' , :l_old_value old_value'||
4779                         l_from||' ,oks_k_headers_v oksh '||
4780                         l_where||' AND oksh.chr_id = okh.id
4781                                    AND nvl(oksh.inv_print_profile,''N'') = :p_ctr_rec_old_value
4782                                    AND okh.scs_code = :update_level_value';
4783 
4784         END IF ;
4785 
4786 
4787  ------------------------------------------------------------------------------------------
4788  --  Update Level : Category , Attribute: Contract Group (CONTRACT_GROUP)
4789  ------------------------------------------------------------------------------------------
4790 
4791 	   ELSIF p_ctr_rec.attribute = 'CONTRACT_GROUP' THEN
4792 
4793 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4794               l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
4795                        l_from||',okc_k_groups_grpings_v okg'||
4796                        l_where||' AND okg.included_chr_id = okh.id
4797      					          AND okg.cgp_parent_id is NULL
4798      					          AND okh.scs_code = :update_level_value';
4799 
4800  /*             l_stmt := l_select||' ,NULL old_value'||
4801                        l_from||
4802                        l_where||' AND EXISTS (SELECT id from okc_k_headers_v a
4803                                     WHERE a.id = okh.id
4804                                     MINUS
4805                                     SELECT okg.included_chr_id
4806                                     FROM okc_k_groups_grpings_v okg
4807 									WHERE okg.included_chr_id = okh.id)
4808      					          AND okh.scs_code='''||p_ctr_rec.update_level_value||'''';
4809 */
4810 
4811           ELSIF p_ctr_rec.old_value = '-1111' THEN -- For old Value as ALL
4812               l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
4813                        l_from||',okc_k_groups_grpings_v okg'||
4814                        l_where||' AND okg.included_chr_id = okh.id
4815      					          AND okh.scs_code = :update_level_value';
4816           ELSE
4817 
4818               l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
4819                        l_from||',okc_k_groups_grpings_v okg'||
4820                        l_where||' AND okg.included_chr_id = okh.id
4821      					          AND okg.cgp_parent_id = to_number(:p_ctr_rec_old_value)
4822      					          AND okh.scs_code = :update_level_value';
4823           END IF;
4824  ------------------------------------------------------------------------------------------
4825  --  Update Level : Category , Attribute: Contract Start date (CONTRACT_START_DATE)
4826  ------------------------------------------------------------------------------------------
4827 
4828         ELSIF UPPER(p_ctr_rec.attribute) = UPPER('CONTRACT_START_DATE') Then
4829 
4830           IF p_ctr_rec.old_value is NULL THEN   -- For Contract Start date as NULL
4831              l_stmt := l_select||',to_char(okh.start_date) old_value'||
4832                        l_from||
4833                        l_where||' AND okh.start_date is NULL
4834 						          AND okh.scs_code = :update_level_value';
4835           ELSIF p_ctr_rec.old_value is not NULL THEN   -- For Contract Start date not NULL
4836              l_stmt := l_select||',to_char(okh.start_date) old_value'||
4837                        l_from||
4838                        l_where||' AND trunc(okh.start_date) = trunc(to_date(:p_ctr_rec_old_value,''YYYY/MM/DD HH24:MI:SS''))
4839 						          AND okh.scs_code = :update_level_value';
4840           END IF;
4841 
4842  ------------------------------------------------------------------------------------------
4843  --  Update Level : Category , Attribute: Contract End date (CONTRACT_END_DATE)
4844  ------------------------------------------------------------------------------------------
4845 
4846         ELSIF UPPER(p_ctr_rec.attribute) = UPPER('CONTRACT_END_DATE') Then
4847 
4848           IF p_ctr_rec.old_value is NULL THEN   -- For Contract End date as NULL
4849              l_stmt := l_select||',to_char(okh.end_date) old_value'||
4850                        l_from||
4851                        l_where||' AND okh.end_date is NULL
4852 						          AND okh.scs_code = :update_level_value';
4853           ELSIF p_ctr_rec.old_value is not NULL THEN   -- For Contract End date not NULL
4854              l_stmt := l_select||',to_char(okh.end_date) old_value'||
4855                        l_from||
4856                        l_where||' AND trunc(okh.end_date) = trunc(to_date(:p_ctr_rec_old_value,''YYYY/MM/DD HH24:MI:SS''))
4857 						          AND okh.scs_code = :update_level_value';
4858           END IF;
4859         END IF;
4860 
4861  ----------------------------------------------------------------------------
4862  --  Update Level : Contract Group
4863  ----------------------------------------------------------------------------
4864  ELSIF p_ctr_rec.update_level = 'OKS_K_GROUP' THEN
4865 
4866  --------------------------------------------------------
4867  --  Update Level : Contract Group , Attribute: Revenue Account(REV_ACCT)
4868  --------------------------------------------------------
4869       IF p_ctr_rec.attribute = 'REV_ACCT' THEN
4870 
4871 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
4872              l_stmt := l_select||' ,NULL old_value'||
4873                        l_from||l_where||
4874                        ' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
4875                                      WHERE rev.chr_id = okh.id
4876                                      AND   rev.code_combination_id is NULL)
4877                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
4878                                        WHERE okg1.included_chr_id is not null
4879                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
4880                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
4881 
4882           ELSIF p_ctr_rec.old_value = '-1111' THEN
4883              l_stmt := l_select||' ,NULL old_value'||
4884                        l_from||l_where||
4885                        ' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
4886                                      WHERE rev.chr_id = okh.id)
4887                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
4888                                        WHERE okg1.included_chr_id is not null
4889                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
4890                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
4891 
4892 
4893           ELSE
4894              l_old_value := p_ctr_rec.old_value;
4895              l_stmt := l_select||' , :l_old_value old_value'||
4896                        l_from||l_where||
4897                        ' AND EXISTS (SELECT ''x'' from OKS_REV_DISTRIBUTIONS_V rev
4898                                      WHERE rev.chr_id = okh.id
4899                                      AND   rev.code_combination_id  = to_number(:p_ctr_rec_old_value))
4900                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
4901                                        WHERE okg1.included_chr_id is not null
4902                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
4903                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
4904 
4905           END IF;
4906 
4907 
4908  ---------------------------------------------------------
4909  --  Update Level : Contract Group, Attribute: Payment Term (PAYMENT_TERM)
4910  --------------------------------------------------------
4911 
4912       ELSIF p_ctr_rec.attribute = 'PAYMENT_TERM' THEN
4913 
4914 
4915           IF    p_ctr_rec.old_value = '-9999' THEN
4916 
4917                        l_stmt := l_select||' ,NULL old_value' ||
4918                        l_from||l_where||
4919                        ' AND  okh.PAYMENT_TERM_ID is NULL
4920                          AND  okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
4921                                                    WHERE okg1.included_chr_id is not null
4922                                                    START WITH okg1.cgp_parent_id = to_number(:update_level_value)
4923                                                    CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)' ;
4924 
4925         -- Old Value: ALL (-1111)
4926 
4927           ELSIF p_ctr_rec.old_value = '-1111' THEN
4928                        l_stmt := l_select||' ,okh.payment_term_id old_value' ||
4929                        l_from||l_where||
4930                                'AND  okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
4931                                                    WHERE okg1.included_chr_id is not null
4932                                                    START WITH okg1.cgp_parent_id = to_number(:update_level_value)
4933                                                    CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)' ;
4934        -- Old Value: Other than NULL or ALL
4935 
4936           ELSE
4937 
4938              l_stmt := l_select||' ,okh.payment_term_id old_value' ||
4939                        l_from||l_where||
4940                        ' AND  okh.payment_term_id = to_number(:p_ctr_rec_old_value)
4941                          AND  okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
4942                                                    WHERE okg1.included_chr_id is not null
4943                                                    START WITH okg1.cgp_parent_id = to_number(:update_level_value)
4944                                                    CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)' ;
4945 
4946           END IF;
4947 
4948 -------------------------------------------------------------------------------------
4949  --  Update Level : Contract Group , Attribute: Contract Renewal Type(CON_RENEWAL_TYPE)
4950 ------------------------------------------------------------------------------------
4951       ELSIF p_ctr_rec.attribute = 'CON_RENEWAL_TYPE' THEN
4952 
4953        -- Old Value: NULL (-9999)
4954 	     IF    p_ctr_rec.old_value = '-9999' THEN
4955 
4956                        l_stmt := l_select||' ,NULL old_value' ||
4957                        l_from||
4958                        l_where||
4959                        ' AND  okh.renewal_type_code is NULL
4960                          AND not exists(
4961                                         select ol.object_chr_id
4962                                         from okc_operation_lines ol
4963                                             ,okc_operation_instances oi
4964                                             ,okc_class_operations co
4965                                         WHERE ol.object_chr_id = okh.id
4966                                           AND ol.process_flag = ''P''
4967                                           AND ol.ACTIVE_YN    = ''Y''
4968                                           AND oi.id = ol.oie_id
4969                                           AND oi.cop_id = co.id
4970                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
4971                                           AND co.CLS_CODE = ''SERVICE'')
4972                          AND  okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
4973                                                    WHERE okg1.included_chr_id is not null
4974                                                    START WITH okg1.cgp_parent_id = to_number(:update_level_value)
4975                                                    CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)' ;
4976 
4977          ELSIF p_ctr_rec.old_value = '-1111' THEN
4978                        l_old_value := p_ctr_rec.old_value;
4979                        l_stmt := l_select||' , :l_old_value old_value' ||
4980                        l_from||
4981                        l_where||
4982                                ' AND not exists(
4983                                         select ol.object_chr_id
4984                                         from okc_operation_lines ol
4985                                             ,okc_operation_instances oi
4986                                             ,okc_class_operations co
4987                                         WHERE ol.object_chr_id = okh.id
4988                                           AND ol.process_flag = ''P''
4989                                           AND ol.ACTIVE_YN    = ''Y''
4990                                           AND oi.id = ol.oie_id
4991                                           AND oi.cop_id = co.id
4992                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
4993                                           AND co.CLS_CODE = ''SERVICE'')
4994                                  AND  okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
4995                                                    WHERE okg1.included_chr_id is not null
4996                                                    START WITH okg1.cgp_parent_id = to_number(:update_level_value)
4997                                                    CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)' ;
4998  -- Old Value: Other than NULL or ALL
4999 
5000           ELSIF p_ctr_rec.old_value = 'ERN' then
5001 
5002              l_old_value := p_ctr_rec.old_value;
5003              l_stmt := l_select||' , :l_old_value old_value' ||
5004                        l_from||' ,oks_k_headers_b oksh'||
5005                        l_where||
5006                        ' AND oksh.chr_id = okh.id
5007                         AND  okh.renewal_type_code = ''NSR''
5008                         AND ''ERN'' = :p_ctr_rec_old_value
5009                         AND oksh.ELECTRONIC_RENEWAL_FLAG =''Y''
5010                          AND not exists(
5011                                         select ol.object_chr_id
5012                                         from okc_operation_lines ol
5013                                             ,okc_operation_instances oi
5014                                             ,okc_class_operations co
5015                                         WHERE ol.object_chr_id = okh.id
5016                                           AND ol.process_flag = ''P''
5017                                           AND ol.ACTIVE_YN    = ''Y''
5018                                           AND oi.id = ol.oie_id
5019                                           AND oi.cop_id = co.id
5020                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
5021                                           AND co.CLS_CODE = ''SERVICE'')
5022                          AND  okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5023                                                    WHERE okg1.included_chr_id is not null
5024                                                    START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5025                                                    CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)' ;
5026 
5027  -- Old Value: Other than NULL or ALL
5028 
5029           ELSE
5030 
5031              l_old_value := p_ctr_rec.old_value;
5032              l_stmt := l_select||' , :l_old_value old_value' ||
5033                        l_from||' ,oks_k_headers_b oksh'||
5034                        l_where||
5035                        ' AND oksh.chr_id = okh.id
5036                         AND  okh.renewal_type_code = :p_ctr_rec_old_value
5037                          AND nvl(oksh.ELECTRONIC_RENEWAL_FLAG,''N'') <>''Y''
5038                          AND not exists(
5039                                         select ol.object_chr_id
5040                                         from okc_operation_lines ol
5041                                             ,okc_operation_instances oi
5042                                             ,okc_class_operations co
5043                                         WHERE ol.object_chr_id = okh.id
5044                                           AND ol.process_flag = ''P''
5045                                           AND ol.ACTIVE_YN    = ''Y''
5046                                           AND oi.id = ol.oie_id
5047                                           AND oi.cop_id = co.id
5048                                           AND co.opn_code in (''RENEWAL'',''REN_CON'')
5049                                           AND co.CLS_CODE = ''SERVICE'')
5050                          AND  okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5051                                                    WHERE okg1.included_chr_id is not null
5052                                                    START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5053                                                    CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)' ;
5054 
5055           END IF;
5056 
5057  ---------------------------------------------------------------------------
5058  --  Update Level : Contract Group , Attribute: Business Process Price List (BP_PRICE_LIST)
5059  ---------------------------------------------------------------------------
5060       ELSIF p_ctr_rec.attribute = 'BP_PRICE_LIST' THEN
5061 
5062      -- Old Value: NULL (-9999)
5063 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5064               l_stmt := l_select||' ,NULL old_value' ||
5065                         l_from||
5066                         l_where|| 'AND exists ( Select dnz_chr_id from okc_k_lines_b cln
5067                                           Where cln.dnz_chr_id = okh.id
5068                                             AND cln.lse_id in(3,16,21)
5069                                             AND cln.price_list_id is NULL)
5070                                    AND  okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5071                                                    WHERE okg1.included_chr_id is not null
5072                                                    START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5073                                                    CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5074 
5075      -- Old Value: ALL (-1111)
5076           ELSIF p_ctr_rec.old_value = '-1111' THEN
5077              l_old_value := p_ctr_rec.old_value;
5078              l_stmt := l_select||' , :l_old_value old_value' ||
5079                        l_from||
5080                        l_where|| ' AND exists ( Select dnz_chr_id from okc_k_lines_b cln
5081                                           Where cln.dnz_chr_id = okh.id
5082                                             AND cln.lse_id in(3,16,21))
5083                                    AND  okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5084                                                    WHERE okg1.included_chr_id is not null
5085                                                    START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5086                                                    CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5087 
5088      -- Old Value: Other than NULL or ALL
5089           ELSE
5090              l_old_value := p_ctr_rec.old_value;
5091              l_stmt := l_select||' , :l_old_value old_value' ||
5092                        l_from||
5093                        l_where|| ' AND exists ( Select dnz_chr_id from okc_k_lines_b cln
5094                                       Where cln.dnz_chr_id = okh.id
5095                                       AND cln.lse_id in(3,16,21)
5096                                       AND cln.price_list_id = to_number(:p_ctr_rec_old_value))
5097                                   AND  okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5098                                                    WHERE okg1.included_chr_id is not null
5099                                                    START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5100                                                    CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5101 
5102           END IF;
5103 
5104  ---------------------------------------------------------
5105  --  Update Level : Contract Group, Attribute: Accounting Rule (ACCT_RULE)
5106  --------------------------------------------------------
5107 
5108       ELSIF p_ctr_rec.attribute = 'ACCT_RULE' THEN
5109 
5110      -- Old Value: ALL (-9999)
5111 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5112 
5113               l_stmt := l_select||' ,NULL old_value' ||
5114                         l_from||' ,oks_k_headers_v oksh '||
5115                         l_where|| 'AND oksh.chr_id = okh.id
5116                                    AND oksh.acct_rule_id IS NULL
5117                                    AND okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5118                                         WHERE okg1.included_chr_id is not null
5119                                         START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5120                                         CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5121      -- Old Value: ALL (-1111)
5122 
5123           ELSIF p_ctr_rec.old_value = '-1111' THEN
5124              l_stmt := l_select||' ,oksh.acct_rule_id old_value' ||
5125                        l_from||' ,oks_k_headers_v oksh '||
5126                        l_where|| 'AND oksh.chr_id = okh.id
5127                                   AND okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5128                                         WHERE okg1.included_chr_id is not null
5129                                         START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5130                                         CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5131      -- Old Value: Other than NULL or ALL
5132 
5133           ELSE
5134              l_stmt := l_select||' ,oksh.acct_rule_id old_value' ||
5135                        l_from||' ,oks_k_headers_v oksh '||
5136                        l_where|| 'AND oksh.chr_id = okh.id
5137                                   AND oksh.acct_rule_id = to_number(:p_ctr_rec_old_value)
5138                                   AND okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5139                                         WHERE okg1.included_chr_id is not null
5140                                         START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5141                                         CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5142           END IF;
5143 
5144 
5145  ---------------------------------------------------------------------------
5146  --  Update Level : Contract Group, Attribute: Invoice Rule (INV_RULE)
5147  ---------------------------------------------------------------------------
5148 
5149       ELSIF p_ctr_rec.attribute = 'INV_RULE' THEN
5150 
5151 
5152         -- Old Value: NULL (-9999)
5153          IF  p_ctr_rec.old_value = '-9999' THEN
5154 
5155              l_stmt := l_select||' ,NULL old_value' ||
5156                        l_from||l_where||
5157                              ' AND  okh.inv_rule_id IS NULL
5158                                AND  okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5159                                                    WHERE okg1.included_chr_id is not null
5160                                                    START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5161                                                    CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5162 
5163          ELSIF p_ctr_rec.old_value = '-1111' THEN
5164                     l_stmt := l_select||' ,okh.inv_rule_id old_value' ||
5165                               l_from||l_where||
5166                                     ' AND  okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5167                                                    WHERE okg1.included_chr_id is not null
5168                                                    START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5169                                                    CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5170 
5171        -- Old Value: Other than NULL or ALL
5172 
5173           ELSE
5174                 l_stmt := l_select||' ,okh.inv_rule_id old_value' ||
5175                           l_from||l_where||
5176                                 ' AND  okh.inv_rule_id = to_number(:p_ctr_rec_old_value)
5177                                   AND  okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5178                                                    WHERE okg1.included_chr_id is not null
5179                                                    START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5180                                                    CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5181 
5182           END IF;
5183 
5184 ---------------------------------------------------------------------------
5185  --  Update Level : Contract Group , Attribute: Coverage Type(COV_TYPE)
5186  ---------------------------------------------------------------------------
5187       ELSIF p_ctr_rec.attribute = 'COV_TYPE' THEN
5188 
5189        -- Old Value: NULL (-9999)
5190 
5191         IF p_ctr_rec.old_value = '-9999' THEN
5192              l_stmt := l_select||' ,NULL old_value'||
5193                        l_from||l_where||
5194                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V okl, oks_k_lines_v oksl
5195                                              WHERE okl.dnz_chr_id = okh.id
5196                                              AND oksl.cle_id      = okl.id
5197                                              AND oksl.coverage_type is NULL )
5198                                              AND okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5199                                                              WHERE okg1.included_chr_id is not null
5200                                                              START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5201                                                              CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5202 
5203         -- Old Value: ALL
5204 
5205           ELSIF p_ctr_rec.old_value = '-1111' THEN
5206 
5207                 l_old_value := p_ctr_rec.old_value;
5208                 l_stmt := l_select||' , :l_old_value old_value'||
5209                           l_from||
5210                           l_where||'AND EXISTS (SELECT ''x'' from okc_k_lines_v okl, oks_k_lines_v oksl
5211                                     WHERE okl.dnz_chr_id = okh.id
5212                                     AND oksl.cle_id      = okl.id )
5213                                     AND okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5214                                                              WHERE okg1.included_chr_id is not null
5215                                                              START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5216                                                              CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5217 
5218          -- Old Value: Other than NULL or ALL
5219           ELSE
5220                  l_old_value := p_ctr_rec.old_value;
5221                  l_stmt := l_select||' , :l_old_value old_value'||
5222                            l_from||
5223                            l_where||'AND EXISTS (SELECT ''x'' from okc_k_lines_v okl, oks_k_lines_v oksl
5224                                      WHERE okl.dnz_chr_id   = okh.id
5225                                      AND oksl.cle_id        = okl.id
5226                                      AND oksl.coverage_type = :p_ctr_rec_old_value )
5227                                      AND okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5228                                                              WHERE okg1.included_chr_id is not null
5229                                                              START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5230                                                              CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5231 
5232 
5233           END IF;
5234 
5235  ---------------------------------------------------------------------------
5236  --  Update Level : Contract Group , Attribute: Coverage Type(COV_TIMEZONE)
5237  ---------------------------------------------------------------------------
5238       ELSIF p_ctr_rec.attribute = 'COV_TIMEZONE' THEN
5239 
5240 
5241         -- Old Value: NULL (-9999)
5242 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5243              l_stmt := l_select||' ,NULL old_value'||
5244                        l_from||l_where||
5245                        ' AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
5246                                       WHERE ctz.dnz_chr_id = okh.id
5247                                       AND   ctz.timezone_id IS NULL )
5248                                       AND okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5249                                                       WHERE okg1.included_chr_id is not null
5250                                                       START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5251                                                       CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5252 
5253        -- Old Value: ALL (-1111)
5254           ELSIF p_ctr_rec.old_value = '-1111' THEN
5255 
5256              l_old_value := p_ctr_rec.old_value;
5257              l_stmt := l_select||' , :l_old_value old_value'||
5258                        l_from||
5259                        l_where||'AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
5260                                              WHERE ctz.dnz_chr_id = okh.id
5261                                              AND   ctz.timezone_id IS NOT NULL )
5262                                              AND okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5263                                                              WHERE okg1.included_chr_id is not null
5264                                                              START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5265                                                              CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5266         -- Old Value: Other than NULL or ALL
5267           ELSE
5268 
5269              l_old_value := p_ctr_rec.old_value;
5270              l_stmt := l_select||' , :l_old_value old_value'||
5271                        l_from||
5272                        l_where||'AND EXISTS (SELECT ''x'' from  oks_coverage_timezones_v ctz
5273                                              WHERE ctz.dnz_chr_id = okh.id
5274                                              AND  ctz.timezone_id = to_number(:p_ctr_rec_old_value))
5275                                              AND okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5276                                                              WHERE okg1.included_chr_id is not null
5277                                                              START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5278                                                              CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5279 
5280           END IF;
5281  ---------------------------------------------------------------------------
5282  --  Update Level : Category , Attribute: Coverage Type(PREF_ENGG)
5283  ---------------------------------------------------------------------------
5284       ELSIF p_ctr_rec.attribute = 'PREF_ENGG' THEN
5285 
5286 	     IF p_ctr_rec.old_value = '-1111' THEN
5287 
5288                 l_old_value := p_ctr_rec.old_value;
5289                 l_stmt := l_select||' , :l_old_value old_value'||
5290                        l_from||
5291                        l_where||'AND EXISTS (SELECT ''x'' from
5292                                              okc_contacts oco
5293                                              WHERE oco.dnz_chr_id = okh.id
5294                                              AND   oco.cro_code = ''ENGINEER''
5295                                              AND   oco.jtot_object1_code = ''OKX_RESOURCE'')
5296                                              AND okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5297                                                              WHERE okg1.included_chr_id is not null
5298                                                              START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5299                                                              CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5300 
5301           ELSE
5302              l_old_value := p_ctr_rec.old_value;
5303              l_stmt := l_select||' , :l_old_value old_value'||
5304                        l_from||
5305                        l_where||'AND EXISTS (SELECT ''x'' from
5306                                              okc_contacts oco
5307                                              WHERE oco.dnz_chr_id = okh.id
5308                                              AND   oco.cro_code = ''ENGINEER''
5309                                              AND   oco.jtot_object1_code = ''OKX_RESOURCE''
5310                                              AND   oco.object1_id1  = :p_ctr_rec_old_value)
5311                                              AND okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5312                                                              WHERE okg1.included_chr_id is not null
5313                                                              START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5314                                                              CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5315           END IF;
5316  ---------------------------------------------------------------------------
5317  --  Update Level : Category , Attribute: Coverage Type(RES_GROUP)
5318  ---------------------------------------------------------------------------
5319       ELSIF p_ctr_rec.attribute = 'RES_GROUP' THEN
5320 
5321 	     IF p_ctr_rec.old_value = '-1111' THEN
5322 
5323              l_old_value := p_ctr_rec.old_value;
5324              l_stmt := l_select||' , :l_old_value old_value'||
5325                        l_from||
5326                        l_where||'AND EXISTS (SELECT ''x'' from
5327                                              okc_contacts oco
5328                                              WHERE oco.dnz_chr_id = okh.id
5329                                              AND   oco.cro_code = ''RSC_GROUP''
5330                                              AND   oco.jtot_object1_code = ''OKS_RSCGROUP'')
5331                                              AND okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5332                                                              WHERE okg1.included_chr_id is not null
5333                                                              START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5334                                                              CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5335 
5336           ELSE
5337              l_old_value := p_ctr_rec.old_value;
5338              l_stmt := l_select||' , :l_old_value old_value'||
5339                        l_from||
5340                        l_where||'AND EXISTS (SELECT ''x'' from
5341                                              okc_contacts oco
5342                                              WHERE oco.dnz_chr_id = okh.id
5343                                              AND   oco.cro_code = ''RSC_GROUP''
5344                                              AND   oco.jtot_object1_code = ''OKS_RSCGROUP''
5345                                              AND   oco.object1_id1  = :p_ctr_rec_old_value)
5346                                              AND okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5347                                                              WHERE okg1.included_chr_id is not null
5348                                                              START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5349                                                              CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5350           END IF;
5351 
5352 
5353 
5354  ---------------------------------------------------------------------------
5355  --  Update Level : Contract Group , Attribute: Coverage Type(AGREEMENT_NAME)
5356  ---------------------------------------------------------------------------
5357       ELSIF p_ctr_rec.attribute = 'AGREEMENT_NAME' THEN
5358 
5359              l_old_value := p_ctr_rec.old_value;
5360              l_stmt := l_select||' , :l_old_value old_value'||
5361                        l_from||
5362                        l_where||'AND EXISTS (SELECT ''x'' from okc_governances_v ogv
5363                                              WHERE ogv.dnz_chr_id = okh.id
5364                                              AND   ogv.isa_agreement_id = :p_ctr_rec_old_value)
5365                                              AND okh.id in(  SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5366                                                              WHERE okg1.included_chr_id is not null
5367                                                              START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5368                                                              CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5369 
5370 
5371 
5372  --------------------------------------------------------
5373  --  Update Level : Contract Group , Attribute: Product Alias(PRODUCT_ALIAS)
5374  --------------------------------------------------------
5375       ELSIF p_ctr_rec.attribute = 'PRODUCT_ALIAS' THEN
5376 
5377  	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5378              l_stmt := l_select||' ,NULL old_value'||
5379                        l_from||l_where||
5380                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
5381                                      WHERE cle.dnz_chr_id = okh.id
5382                                      AND   cle.lse_id IN (7,8,9,10,11,18,25,35)
5383                                      AND   cle.cognomen is NULL)
5384                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5385                                        WHERE okg1.included_chr_id is not null
5386                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5387                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5388 
5389           ELSIF p_ctr_rec.old_value = '-1111' THEN
5390              l_stmt := l_select||' ,NULL old_value'||
5391                        l_from||l_where||
5392                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
5393                                      WHERE cle.dnz_chr_id = okh.id
5394                                      AND   cle.lse_id IN (7,8,9,10,11,18,25,35))
5395                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5396                                        WHERE okg1.included_chr_id is not null
5397                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5398                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5399 
5400           ELSE
5401               -- dbms_output.put_line('Inside else');
5402              l_old_value := p_ctr_rec.old_value;
5403              l_stmt := l_select||' , :l_old_value old_value'||
5404                        l_from||l_where||
5405                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
5406                                      WHERE cle.dnz_chr_id = okh.id
5407                                      AND   cle.lse_id IN (7,8,9,10,11,18,25,35)
5408                                      AND   cle.cognomen = :p_ctr_rec_old_value)
5409                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5410                                        WHERE okg1.included_chr_id is not null
5411                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5412                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5413 
5414           END IF;
5415  --------------------------------------------------------
5416  --  Update Level :Contract Group , Attribute: Contract Line Ref(CONTRACT_LINE_REF)
5417  --------------------------------------------------------
5418       ELSIF p_ctr_rec.attribute = 'CONTRACT_LINE_REF' THEN
5419 
5420 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5421              l_stmt := l_select||' ,NULL old_value'||
5422                        l_from||l_where||
5423                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
5424                                      WHERE cle.chr_id = okh.id
5425                                      AND   cle.lse_id IN (1,12,14,19)
5426                                      AND   cle.cognomen is NULL)
5427                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5428                                        WHERE okg1.included_chr_id is not null
5429                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5430                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5431 
5432           ELSIF p_ctr_rec.old_value = '-1111' THEN
5433              l_stmt := l_select||' ,NULL old_value'||
5434                        l_from||l_where||
5435                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
5436                                      WHERE cle.chr_id = okh.id
5437                                      AND   cle.lse_id IN (1,12,14,19))
5438                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5439                                        WHERE okg1.included_chr_id is not null
5440                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5441                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5442           ELSE
5443               -- dbms_output.put_line('Inside else');
5444              l_old_value := p_ctr_rec.old_value;
5445              l_stmt := l_select||' , :l_old_value old_value'||
5446                        l_from||l_where||
5447                        ' AND EXISTS (SELECT ''x'' from OKC_K_LINES_V cle
5448                                      WHERE cle.chr_id = okh.id
5449                                      AND   cle.lse_id IN (1,12,14,19)
5450                                      AND   cle.cognomen = :p_ctr_rec_old_value)
5451                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5452                                        WHERE okg1.included_chr_id is not null
5453                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5454                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5455 
5456           END IF;
5457 
5458    -----------------------------------------------------------------------------------
5459  --  Update Level : Contract Group , Attribute: Header Ship-to Address(HDR_SHIP_TO_ADDRESS)
5460  -------------------------------------------------------------------------------------
5461       ELSIF p_ctr_rec.attribute = 'HDR_SHIP_TO_ADDRESS' THEN
5462        -- Old Value: NULL (-9999)
5463 	     IF  p_ctr_rec.old_value = '-9999' THEN
5464                  l_stmt := l_select||' ,NULL old_value' ||
5465                            l_from||l_where||
5466                                 ' AND  okh.ship_to_site_use_id is NULL
5467                                   AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5468                                                  WHERE okg1.included_chr_id is not null
5469                                                  START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5470                                                  CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5471 
5472        -- Old Value: Other than NULL or ALL
5473 
5474          ELSE
5475                  l_stmt := l_select||' ,okh.ship_to_site_use_id old_value' ||
5476                            l_from||l_where||
5477                                    ' AND  okh.ship_to_site_use_id = to_number(:p_ctr_rec_old_value)
5478                                      AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5479                                                  WHERE okg1.included_chr_id is not null
5480                                                  START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5481                                                  CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5482          END IF;
5483 
5484   ------------------------------------------------------------------------------------
5485  --  Update Level : Contract Group , Attribute: Header Bill-to Address(HDR_BILL_TO_ADDRESS)
5486  -------------------------------------------------------------------------------------
5487       ELSIF p_ctr_rec.attribute = 'HDR_BILL_TO_ADDRESS' THEN
5488 
5489        -- Old Value: NULL (-9999)
5490 	     IF  p_ctr_rec.old_value = '-9999' THEN
5491                  l_stmt := l_select||' ,NULL old_value' ||
5492                            l_from||l_where||
5493                                    ' AND  okh.bill_to_site_use_id is NULL
5494                                      AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5495                                                  WHERE okg1.included_chr_id is not null
5496                                                  START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5497                                                  CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5498        -- Old Value: Other than NULL or ALL
5499 
5500          ELSE
5501                  l_stmt := l_select||' ,okh.bill_to_site_use_id old_value' ||
5502                            l_from||l_where||
5503                                    ' AND  okh.bill_to_site_use_id = to_number(:p_ctr_rec_old_value)
5504                                      AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5505                                                  WHERE okg1.included_chr_id is not null
5506                                                  START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5507                                                  CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5508          END IF;
5509 
5510  --------------------------------------------------------
5511  --  Update Level : Contract Group , Attribute: Sales Rep(SALES_REP)
5512  --------------------------------------------------------
5513       ELSIF p_ctr_rec.attribute = 'SALES_REP' THEN
5514 
5515          IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5516              l_stmt := l_select||' ,NULL old_value'||
5517                        l_from||l_where||
5518                        ' AND EXISTS (Select ''x'' from okc_contacts oc
5519                                          where oc.dnz_chr_id = okh.id
5520                                          and   oc.cro_code = ''SALESPERSON''
5521                                          and   oc.object1_id1 is null
5522                                          and   oc.jtot_object1_code = ''OKX_SALEPERS'')
5523                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5524                                        WHERE okg1.included_chr_id is not null
5525                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5526                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5527 
5528            ELSIF p_ctr_rec.old_value = '-1111' THEN
5529               -- dbms_output.put_line('Inside else ALL SALES_REP');
5530              l_stmt := l_select||' ,oc.object1_id1 old_value '||
5531                        l_from||', okc_contacts oc '||
5532                        l_where||' and oc.dnz_chr_id = okh.id
5533                           and   oc.cro_code = ''SALESPERSON''
5534                           and   oc.jtot_object1_code = ''OKX_SALEPERS''
5535                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5536                                        WHERE okg1.included_chr_id is not null
5537                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5538                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5539          ELSE
5540              l_old_value := p_ctr_rec.old_value;
5541              l_stmt := l_select||' , :l_old_value old_value'||
5542                        l_from||l_where||
5543                        ' AND (EXISTS (Select ''x'' from okc_contacts oc
5544                                          where oc.dnz_chr_id = okh.id
5545                                          and   oc.cro_code = ''SALESPERSON''
5546                                          and   oc.object1_id1=:p_ctr_rec_old_value
5547                                          and   oc.jtot_object1_code = ''OKX_SALEPERS'')
5548                          OR EXISTS (Select ''x'' from oks_k_sales_credits_v osc
5549                                    Where osc.chr_id = okh.id
5550                                    and osc.ctc_id = to_number(:p_ctr_rec_old_value)))
5551                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5552                                        WHERE okg1.included_chr_id is not null
5553                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5554                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5555 
5556           END IF;
5557 
5558  ----------------------------------------------------------------------------------------
5559  --  Update Level : Contract Group , Attribute: Party Shipping Contact (PARTY_SHIPPING_CONTACT)
5560  ----------------------------------------------------------------------------------------
5561       ELSIF p_ctr_rec.attribute = 'PARTY_SHIPPING_CONTACT' THEN
5562 
5563 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5564              l_stmt := l_select||' ,NULL old_value'||
5565                        l_from||l_where||
5566                        ' AND EXISTS (Select ''x'' from okc_contacts oc
5567                                          where oc.dnz_chr_id = okh.id
5568                                          and   oc.cro_code = ''SHIPPING''
5569                                          and   oc.object1_id1 is null
5570                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
5571                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5572                                        WHERE okg1.included_chr_id is not null
5573                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5574                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5575 
5576           ELSIF p_ctr_rec.old_value = '-1111' THEN
5577              l_stmt := l_select||' ,oc.object1_id1 old_value'||
5578                        l_from||', okc_contacts oc '||
5579                        l_where||
5580                         ' and oc.dnz_chr_id = okh.id
5581                           and   oc.cro_code = ''SHIPPING''
5582                           and   oc.jtot_object1_code = ''OKX_PCONTACT'')
5583                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5584                                        WHERE okg1.included_chr_id is not null
5585                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5586                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5587 
5588           ELSE
5589              l_old_value := p_ctr_rec.old_value;
5590              l_stmt := l_select||' , :l_old_value old_value'||
5591                        l_from||l_where||
5592                        ' AND EXISTS (Select ''x'' from okc_contacts oc
5593                                          where oc.dnz_chr_id = okh.id
5594                                          and   oc.cro_code = ''SHIPPING''
5595                                          and   oc.object1_id1=:p_ctr_rec_old_value
5596                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
5597                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5598                                        WHERE okg1.included_chr_id is not null
5599                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5600                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5601 
5602           END IF;
5603 
5604  ------------------------------------------------------------------------------------------------
5605  --  Update Level : Contract Group , Attribute: Party Billing Contact (PARTY_BILLING_CONTACT)
5606  ------------------------------------------------------------------------------------------------
5607       ELSIF p_ctr_rec.attribute = 'PARTY_BILLING_CONTACT' THEN
5608 
5609 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5610              l_stmt := l_select||' ,NULL old_value'||
5611                        l_from||l_where||
5612                        ' AND EXISTS (Select ''x'' from okc_contacts oc
5613                                          where oc.dnz_chr_id = okh.id
5614                                          and   oc.cro_code = ''BILLING''
5615                                          and   oc.object1_id1 is null
5616                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
5617                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5618                                        WHERE okg1.included_chr_id is not null
5619                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5620                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5621 
5622           ELSIF p_ctr_rec.old_value = '-1111' THEN
5623              l_stmt := l_select||' ,oc.object1_id1 old_value'||
5624                        l_from||', okc_contacts oc '||
5625                        l_where||
5626                         ' and oc.dnz_chr_id = okh.id
5627                           and   oc.cro_code = ''BILLING''
5628                           and   oc.jtot_object1_code = ''OKX_PCONTACT'')
5629                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5630                                        WHERE okg1.included_chr_id is not null
5631                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5632                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5633           ELSE
5634              l_old_value := p_ctr_rec.old_value;
5635              l_stmt := l_select||' , :l_old_value old_value'||
5636                        l_from||l_where||
5637                        ' AND EXISTS (Select ''x'' from okc_contacts oc
5638                                          where oc.dnz_chr_id = okh.id
5639                                          and   oc.cro_code = ''BILLING''
5640                                          and   oc.object1_id1=:p_ctr_rec_old_value
5641                                          and   oc.jtot_object1_code = ''OKX_PCONTACT'')
5642                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5643                                        WHERE okg1.included_chr_id is not null
5644                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5645                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5646 
5647           END IF;
5648  ----------------------------------------------------------------------------------------
5649  --  Update Level : Contract Group , Attribute: Line Shipping Contact (LINE_SHIPPING_CONTACT)
5650  ----------------------------------------------------------------------------------------
5651       ELSIF p_ctr_rec.attribute = 'LINE_SHIPPING_CONTACT' THEN
5652 
5653 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5654              l_stmt := l_select||' ,NULL old_value'||
5655                        l_from||l_where||
5656                        ' AND EXISTS (Select ''x'' from okc_contacts oc
5657                                          where oc.dnz_chr_id = okh.id
5658                                          and   oc.cro_code = ''CUST_SHIPPING''
5659                                          and   oc.object1_id1 is null
5660                                          and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
5661                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5662                                        WHERE okg1.included_chr_id is not null
5663                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5664                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5665 
5666           ELSIF p_ctr_rec.old_value = '-1111' THEN
5667              l_stmt := l_select||' ,oc.object1_id1 old_value'||
5668                        l_from||', okc_contacts oc '||
5669                        l_where||
5670                         ' and oc.dnz_chr_id = okh.id
5671                           and   oc.cro_code = ''CUST_SHIPPING''
5672                           and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
5673                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5674                                        WHERE okg1.included_chr_id is not null
5675                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5676                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5677 
5678           ELSE
5679              l_old_value := p_ctr_rec.old_value;
5680              l_stmt := l_select||' , :l_old_value old_value'||
5681                        l_from||l_where||
5682                        ' AND EXISTS (Select ''x'' from okc_contacts oc
5683                                          where oc.dnz_chr_id = okh.id
5684                                          and   oc.cro_code = ''CUST_SHIPPING''
5685                                          and   oc.object1_id1=:p_ctr_rec_old_value
5686                                          and   oc.jtot_object1_code = ''OKX_CONTSHIP'')
5687                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5688                                        WHERE okg1.included_chr_id is not null
5689                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5690                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5691 
5692           END IF;
5693 
5694  ------------------------------------------------------------------------------------------------
5695  --  Update Level : Contract Group , Attribute: Line Billing Contact (LINE_BILLING_CONTACT)
5696  ------------------------------------------------------------------------------------------------
5697       ELSIF p_ctr_rec.attribute = 'LINE_BILLING_CONTACT' THEN
5698 
5699 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5700              l_stmt := l_select||' ,NULL old_value'||
5701                        l_from||l_where||
5702                        ' AND EXISTS (Select ''x'' from okc_contacts oc
5703                                          where oc.dnz_chr_id = okh.id
5704                                          and   oc.cro_code = ''CUST_BILLING''
5705                                          and   oc.object1_id1 is null
5706                                          and   oc.jtot_object1_code = ''OKX_CONTBILL'')
5707                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5708                                        WHERE okg1.included_chr_id is not null
5709                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5710                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5711 
5712           ELSIF p_ctr_rec.old_value = '-1111' THEN
5713              l_stmt := l_select||' ,oc.object1_id1 old_value'||
5714                        l_from||', okc_contacts oc '||
5715                        l_where||
5716                         ' and oc.dnz_chr_id = okh.id
5717                           and   oc.cro_code = ''CUST_BILLING''
5718                           and   oc.jtot_object1_code = ''OKX_CONTBILL'')
5719                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5720                                        WHERE okg1.included_chr_id is not null
5721                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5722                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5723           ELSE
5724              l_old_value := p_ctr_rec.old_value;
5725              l_stmt := l_select||' , :l_old_value old_value'||
5726                        l_from||l_where||
5727                        ' AND EXISTS (Select ''x'' from okc_contacts oc
5728                                          where oc.dnz_chr_id = okh.id
5729                                          and   oc.cro_code = ''CUST_BILLING''
5730                                          and   oc.object1_id1=:p_ctr_rec_old_value
5731                                          and   oc.jtot_object1_code = ''OKX_CONTBILL'')
5732                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5733                                        WHERE okg1.included_chr_id is not null
5734                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5735                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5736 
5737           END IF;
5738 
5739  ---------------------------------------------------------------------------------
5740  --  Update Level :Contract Group , Attribute: Coverage Time (COVERAGE_TIME)
5741  ---------------------------------------------------------------------------------
5742       ELSIF p_ctr_rec.attribute = 'COVERAGE_TIME' THEN
5743 
5744        -- Old Value: NULL (-9999)
5745 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5746              l_stmt := l_select||' ,NULL old_value'||
5747                        l_from||l_where||
5748                        ' AND EXISTS (Select ''x'' from okc_time_ig_startend_val_v igs
5749                                          where igs.dnz_chr_id = okh.id
5750                                          and   ((igs.start_hour is null
5751                                          and   igs.start_minute is null)
5752                                          OR
5753                                          (     igs.end_hour is null
5754                                          and   igs.end_minute is null))
5755                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5756                                        WHERE okg1.included_chr_id is not null
5757                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5758                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5759 
5760 
5761           ELSE
5762               -- dbms_output.put_line('Inside else');
5763              l_old_value := p_ctr_rec.old_value;
5764              l_stmt := l_select||' , :l_old_value old_value'||
5765                        l_from||l_where||
5766                        ' AND EXISTS (Select ''x'' from okc_time_ig_startend_val_v igs
5767                                       where igs.dnz_chr_id = okh.id
5768                                       and  (( igs.start_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
5769                                       AND   igs.start_minute = mod(to_number(:p_ctr_rec_old_value),60))
5770                                       OR
5771                                       ( igs.end_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
5772                                       AND   igs.end_minute = mod(to_number(:p_ctr_rec_old_value),60)))
5773                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5774                                        WHERE okg1.included_chr_id is not null
5775                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5776                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5777 
5778           END IF;
5779 
5780 
5781 
5782    --------------------------------------------------------
5783  --  Update Level : Contract Group , Attribute: Coverage Start Time (COVERAGE_START_TIME)
5784  --------------------------------------------------------
5785       ELSIF p_ctr_rec.attribute = 'COVERAGE_START_TIME' THEN
5786 
5787 
5788        -- Old Value: NULL (-9999)
5789 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5790              l_stmt := l_select||' ,NULL old_value'||
5791                        l_from||l_where||
5792                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
5793                                          where oct.dnz_chr_id = okh.id
5794                                          and   oct.start_hour is null
5795                                          and   oct.start_minute is null)
5796                         AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5797                                        WHERE okg1.included_chr_id is not null
5798                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5799                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5800 
5801 
5802           ELSE
5803        -- dbms_output.put_line('Inside else');
5804              l_old_value := p_ctr_rec.old_value;
5805              l_stmt := l_select||' , :l_old_value old_value'||
5806                        l_from||l_where||
5807                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
5808                                      where oct.dnz_chr_id = okh.id
5809                                      and   oct.start_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
5810                                      and   oct.start_minute = mod(to_number(:p_ctr_rec_old_value),60))
5811                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5812                                        WHERE okg1.included_chr_id is not null
5813                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5814                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5815 
5816           END IF;
5817 
5818  ------------------------------------------------------------------------------------
5819  --  Update Level : Contract Group , Attribute: Coverage End Time (COVERAGE_END_TIME)
5820  --------------------------------------------------------------------------------------
5821       ELSIF p_ctr_rec.attribute = 'COVERAGE_END_TIME' THEN
5822 
5823        -- Old Value: NULL (-9999)
5824 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5825              l_stmt := l_select||' ,NULL old_value'||
5826                        l_from||l_where||
5827                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
5828                                          where oct.dnz_chr_id = okh.id
5829                                          and   oct.end_hour is null
5830                                          and   oct.end_minute is null)
5831                         AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5832                                        WHERE okg1.included_chr_id is not null
5833                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5834                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5835 
5836          ELSE
5837              l_old_value := p_ctr_rec.old_value;
5838              l_stmt := l_select||' , :l_old_value old_value'||
5839                        l_from||l_where||
5840                        ' AND EXISTS (Select ''x'' from oks_coverage_times_v oct
5841                                      where oct.dnz_chr_id = okh.id
5842                                      and   oct.end_hour = trunc(to_number(:p_ctr_rec_old_value)/60)
5843                                      and   oct.end_minute = mod(to_number(:p_ctr_rec_old_value),60))
5844                         AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5845                                        WHERE okg1.included_chr_id is not null
5846                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5847                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5848          END IF;
5849 
5850 -----------------------------------------------------------------------------------
5851  --  Update Level : Contract Group , Attribute: Resolution Time (RESOLUTION_TIME)
5852 -----------------------------------------------------------------------------------
5853       ELSIF p_ctr_rec.attribute = 'RESOLUTION_TIME' THEN
5854 
5855         -- Old Value: NULL (-9999)
5856 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5857              l_stmt := l_select||', NULL old_value'||
5858                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '|| l_where||
5859                        ' AND kl.dnz_chr_id = okh.id
5860 		         AND kl.id = att.cle_id
5861                          And kl.lse_id in (4,17,22)
5862                          AND   att.action_type_code = ''RSN''
5863                          AND   att.id = oat.cov_action_type_id
5864                          AND   ( sun_duration IS NULL
5865                                  OR mon_duration IS NULL
5866                                  OR tue_duration IS NULL
5867                                  OR wed_duration IS NULL
5868                                  OR thu_duration IS NULL
5869                                  OR fri_duration IS NULL
5870                                  OR sat_duration IS NULL)
5871 
5872                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5873                                        WHERE okg1.included_chr_id is not null
5874                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5875                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5876 
5877        -- Old Value: Other than NULL or ALL
5878 
5879           ELSE
5880               -- dbms_output.put_line('Inside else 111111');
5881             l_old_value := p_ctr_rec.old_value;
5882             l_stmt := l_select||' , :l_old_value old_value'||
5883                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '||l_where||
5884                        ' AND kl.dnz_chr_id = okh.id
5885 		         AND kl.id = att.cle_id
5886                          And kl.lse_id in (4,17,22)
5887                          AND   att.action_type_code = ''RSN''
5888                          AND   att.id = oat.cov_action_type_id
5889                          AND   ( sun_duration = :p_ctr_rec_old_value
5890                                                OR mon_duration = :p_ctr_rec_old_value
5891                                                OR tue_duration = :p_ctr_rec_old_value
5892                                                OR wed_duration = :p_ctr_rec_old_value
5893                                                OR thu_duration = :p_ctr_rec_old_value
5894                                                OR fri_duration = :p_ctr_rec_old_value
5895                                                OR sat_duration = :p_ctr_rec_old_value)
5896                          AND okh.id in (SELECT okg1.included_chr_id from  okc_k_grpings okg1
5897                                        WHERE okg1.included_chr_id is not null
5898                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5899                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5900           END IF;
5901 
5902  -------------------------------------------------------------------------------
5903  --  Update Level : Contract Group , Attribute: Reaction Time (REACTION_TIME)
5904  -------------------------------------------------------------------------------
5905       ELSIF p_ctr_rec.attribute = 'REACTION_TIME' THEN
5906 
5907    -- Old Value: NULL (-9999)
5908 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5909                        l_stmt := l_select||', NULL old_value'||
5910                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '||l_where||
5911                        '  AND kl.dnz_chr_id = okh.id
5912 		          AND kl.id = att.cle_id
5913                           And kl.lse_id in (4,17,22)
5914                          AND   att.action_type_code = ''RCN''
5915                          AND   att.id = oat.cov_action_type_id
5916                          AND   ( sun_duration IS NULL
5917                                                OR mon_duration IS NULL
5918                                                OR tue_duration IS NULL
5919                                                OR wed_duration IS NULL
5920                                                OR thu_duration IS NULL
5921                                                OR fri_duration IS NULL
5922                                                OR sat_duration IS NULL)
5923                         AND okh.id in(SELECT okg1.included_chr_id from  okc_k_grpings okg1
5924                                        WHERE okg1.included_chr_id is not null
5925                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5926                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5927     -- Old Value: Other than NULL or ALL
5928           ELSE
5929              l_old_value := p_ctr_rec.old_value;
5930              l_stmt := l_select||' , :l_old_value old_value'||
5931                        l_from||',okc_k_lines_b kl, oks_action_time_types_v att , oks_action_times_v oat '||l_where||
5932                        ' AND kl.dnz_chr_id = okh.id
5933 		         AND kl.id = att.cle_id
5934                          And kl.lse_id in (4,17,22)
5935                          AND   att.action_type_code = ''RCN''
5936                          AND   att.id = oat.cov_action_type_id
5937                          AND   ( sun_duration = :p_ctr_rec_old_value
5938                                                OR mon_duration = :p_ctr_rec_old_value
5939                                                OR tue_duration = :p_ctr_rec_old_value
5940                                                OR wed_duration = :p_ctr_rec_old_value
5941                                                OR thu_duration = :p_ctr_rec_old_value
5942                                                OR fri_duration = :p_ctr_rec_old_value
5943                                                OR sat_duration = :p_ctr_rec_old_value)
5944                         AND okh.id in(SELECT okg1.included_chr_id from  okc_k_grpings okg1
5945                                        WHERE okg1.included_chr_id is not null
5946                                        START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5947                                        CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5948 
5949           END IF;
5950  -------------------------------------------------------------------
5951  --  Update Level : Contract Group , Attribute: Price List(PRICE_LIST)
5952  -------------------------------------------------------------------
5953       ELSIF p_ctr_rec.attribute = 'PRICE_LIST' THEN
5954 
5955         -- Old Value: NULL (-9999)
5956 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5957 
5958               l_stmt := l_select||' ,NULL old_value'||
5959                         l_from||l_where||
5960                          ' AND  okh.price_list_id is NULL
5961                            AND okh.id in( SELECT okg1.included_chr_id from  okc_k_grpings okg1
5962                                         WHERE okg1.included_chr_id is not null
5963                                         START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5964                                         CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5965        -- Old Value: ALL (-1111)
5966 
5967           ELSIF p_ctr_rec.old_value = '-1111' THEN
5968 
5969              l_stmt := l_select||' ,okh.price_list_id old_value' ||
5970                          l_from||l_where||
5971                          ' AND okh.id in( SELECT okg1.included_chr_id from  okc_k_grpings okg1
5972                                         WHERE okg1.included_chr_id is not null
5973                                         START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5974                                         CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5975         -- Old Value: Other than NULL or ALL
5976 
5977           ELSE
5978 
5979              l_stmt := l_select||' ,okh.price_list_id old_value' ||
5980                        l_from||l_where||
5981                        ' AND  okh.price_list_id = to_number(:p_ctr_rec_old_value)
5982                          AND okh.id in( SELECT okg1.included_chr_id from  okc_k_grpings okg1
5983                                         WHERE okg1.included_chr_id is not null
5984                                         START WITH okg1.cgp_parent_id = to_number(:update_level_value)
5985                                         CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
5986 
5987           END IF;
5988 ----------------------------------------------------------------------------
5989 --  Update Level : Contract Group , Attribute: Known As (CONTRACT_ALIAS)
5990 ----------------------------------------------------------------------------
5991 
5992 	   ELSIF p_ctr_rec.attribute = 'CONTRACT_ALIAS' THEN
5993 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
5994              l_stmt := l_select||' ,  NULL old_value'||
5995                        l_from||
5996                        l_where||' AND okh.cognomen IS NULL
5997                                   AND okh.id in(
5998                                                 SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
5999                                                 WHERE okg1.included_chr_id is not null
6000                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6001                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6002          ELSIF p_ctr_rec.old_value = '-1111' THEN -- For old Value as ALL
6003 
6004              l_stmt := l_select||' ,okh.cognomen old_value'||
6005                        l_from||
6006                        l_where||' AND okh.id in(
6007                                                 SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
6008                                                 WHERE okg1.included_chr_id is not null
6009                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6010                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6011          ELSE
6012              l_stmt := l_select||', okh.cognomen old_value'||
6013                        l_from||
6014                        l_where||' AND okh.cognomen = :p_ctr_rec_old_value
6015                                   AND okh.id in(
6016                                                 SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
6017                                                 WHERE okg1.included_chr_id is not null
6018                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6019                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6020 
6021          END IF;
6022 
6023 -------------------------------------------------------------------------------------
6024 --  Update Level : Contract Group , Attribute: Purchase Order Number (PO_NUMBER_BILL)
6025 -------------------------------------------------------------------------------------
6026 
6027 	   ELSIF p_ctr_rec.attribute = 'PO_NUMBER_BILL' THEN
6028 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
6029              l_stmt := l_select||' ,  NULL old_value'||
6030                        l_from||
6031                        l_where||' AND okh.cust_po_number IS NULL
6032                                   AND ( okh.payment_instruction_type  Is Null Or okh.payment_instruction_type = ''PON'')
6033                                   AND okh.id in(
6034                                                 SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
6035                                                 WHERE okg1.included_chr_id is not null
6036                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6037                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6038          ELSIF p_ctr_rec.old_value = '-1111' THEN -- For old Value as ALL
6039 
6040 	     If p_ctr_rec.new_value is null Then
6041 
6042 
6043                   l_stmt := l_select||' ,okh.cust_po_number old_value'||
6044                        l_from||
6045                        l_where||'   AND okh.payment_instruction_type = ''PON'' AND okh.id in(
6046                                                 SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
6047                                                 WHERE okg1.included_chr_id is not null
6048                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6049                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.inclued_cgp_id)
6050 				  AND okh.cust_po_number_req_yn <> ''Y''';
6051 		Else
6052 
6053 		   l_stmt := l_select||' ,okh.cust_po_number old_value'||
6054                        l_from||
6055                        l_where||'  AND okh.payment_instruction_type = ''PON'' AND okh.id in(
6056                                                 SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
6057                                                 WHERE okg1.included_chr_id is not null
6058                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6059                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.inclued_cgp_id)';
6060 
6061 
6062 
6063 		 End If;
6064 
6065          ELSE
6066 	    If p_ctr_rec.new_value is null Then
6067 
6068                        l_stmt := l_select||' ,okh.cust_po_number old_value'||
6069                                  l_from||
6070                                  l_where||' AND okh.cust_po_number = :p_ctr_rec_old_value
6071                                             AND okh.payment_instruction_type = ''PON''
6072                                             AND okh.id in(
6073                                                 SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
6074                                                 WHERE okg1.included_chr_id is not null
6075                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6076                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)
6077 					    And okh.cust_po_number_req_yn <> ''Y''';
6078 	      Else
6079 
6080 	                 l_stmt := l_select||' ,okh.cust_po_number old_value'||
6081                                  l_from||
6082                                  l_where||' AND okh.cust_po_number = :p_ctr_rec_old_value
6083                                             AND okh.payment_instruction_type = ''PON''
6084                                             AND okh.id in(
6085                                                 SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
6086                                                 WHERE okg1.included_chr_id is not null
6087                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6088                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6089               End If;
6090          END IF;
6091 
6092 
6093  -----------------------------------------------------------------------------
6094  --  Update Level : Contract Group , Attribute: PO NUMBER Required(PO_REQUIRED_REN)
6095  -----------------------------------------------------------------------------
6096       ELSIF p_ctr_rec.attribute = 'PO_REQUIRED_REN' THEN
6097 
6098 
6099            IF p_ctr_rec.old_value = '-1111' THEN
6100 
6101              l_old_value := p_ctr_rec.old_value;
6102              l_stmt := l_select||' , :l_old_value old_value'||
6103                        l_from||
6104                        l_where||
6105                        'AND okh.id in(
6106                                                SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
6107                                                 WHERE okg1.included_chr_id is not null
6108                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6109                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6110 
6111      -- Old Value: Other than NULL or ALL
6112            ELSE
6113 
6114              l_old_value := p_ctr_rec.old_value;
6115              l_stmt := l_select||' , :l_old_value old_value'||
6116                         l_from||' ,oks_k_headers_v oksh '||
6117                         l_where||' AND oksh.chr_id = okh.id
6118                                    AND nvl(oksh.renewal_po_required,''N'') = :p_ctr_rec_old_value
6119                                    AND okh.id in(
6120                                                 SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
6121                                                 WHERE okg1.included_chr_id is not null
6122                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6123                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6124            END IF ;
6125 
6126  --------------------------------------------------------
6127  --  Update Level : Contract Group , Attribute: Summary Print(SUMMARY_PRINT)
6128  --------------------------------------------------------
6129       ELSIF p_ctr_rec.attribute = 'SUMMARY_PRINT' THEN
6130 
6131        -- Old Value: All (-1111)
6132 
6133         IF p_ctr_rec.old_value = '-1111' THEN
6134             l_old_value := p_ctr_rec.old_value;
6135             l_stmt := l_select||' , :l_old_value old_value'||
6136                       l_from||' ,oks_k_headers_v oksh '||
6137                       l_where||' AND oksh.chr_id = okh.id
6138                                  AND okh.id in(
6139                                                 SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
6140                                                 WHERE okg1.included_chr_id is not null
6141                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6142                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6143 
6144 
6145       -- Old Value: Other than NULL or ALL
6146 
6147         ELSE
6148               l_old_value := p_ctr_rec.old_value;
6149               l_stmt := l_select||' , :l_old_value old_value'||
6150                         l_from||' ,oks_k_headers_v oksh '||
6151                         l_where||' AND oksh.chr_id = okh.id
6152                                    AND nvl(oksh.inv_print_profile,''N'') = :p_ctr_rec_old_value
6153                                    AND okh.id in(
6154                                                 SELECT distinct okg1.included_chr_id from  okc_k_grpings okg1
6155                                                 WHERE okg1.included_chr_id is not null
6156                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6157                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6158 
6159         END IF ;
6160 
6161 
6162  ------------------------------------------------------------------------------------
6163  --  Update Level : Contract Group , Attribute: Contract Group(CONTRACT_GROUP)
6164  ------------------------------------------------------------------------------------
6165 
6166 	   ELSIF p_ctr_rec.attribute = 'CONTRACT_GROUP' THEN
6167 
6168 	     IF p_ctr_rec.old_value = '-9999' THEN   -- For old Value as NULL
6169         l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
6170                   l_from||',okc_k_groups_grpings_v okg'||
6171                   l_where||' AND okg.included_chr_id = okh.id
6172      	                     AND okg.cgp_parent_id is NULL
6173                              AND okh.id in(
6174                                                SELECT okg1.included_chr_id from  okc_k_grpings okg1
6175                                                 WHERE okg1.included_chr_id is not null
6176                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6177                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6178 /*
6179               l_stmt := l_select||' ,NULL old_value'||
6180                        l_from||
6181                        l_where||' AND EXISTS (SELECT id from okc_k_headers_v a
6182                                     WHERE a.id = okh.id
6183                                     MINUS
6184                                     SELECT okg.included_chr_id
6185                                     FROM okc_k_groups_grpings_v okg
6186 			       	    WHERE okg.included_chr_id = okh.id)
6187                                   AND okh.id in(
6188                                                 SELECT okg1.included_chr_id from  okc_k_grpings okg1
6189                                                 WHERE okg1.included_chr_id is not null
6190                                                 START WITH okg1.cgp_parent_id = '||to_number(p_ctr_rec.update_level_value)||'
6191                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6192 */
6193 
6194           ELSIF p_ctr_rec.old_value = '-1111' THEN
6195              IF p_query_type = 'PROCESS' then
6196               l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
6197                        l_from||',okc_k_groups_grpings_v okg'||
6198                        l_where||' AND okg.included_chr_id = okh.id
6199                                   AND (okg.cgp_parent_id in(
6200                                                 SELECT okg1.included_cgp_id from  okc_k_grpings okg1
6201                                                 WHERE okg1.included_cgp_id is not null
6202                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6203                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id))
6204                                   AND okh.id in(
6205                                                 SELECT okg1.included_chr_id from  okc_k_grpings okg1
6206                                                 WHERE okg1.included_chr_id is not null
6207                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6208                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6209              ELSIF p_query_type = 'FETCH' then
6210               l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
6211                        l_from||',okc_k_groups_grpings_v okg'||
6212                        l_where||' AND okg.included_chr_id = okh.id
6213                                   AND (okg.cgp_parent_id = to_number(:update_level_value)
6214                                        OR okg.cgp_parent_id in(
6215                                                 SELECT okg1.included_cgp_id from  okc_k_grpings okg1
6216                                                 WHERE okg1.included_cgp_id is not null
6217                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6218                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id))
6219                                   AND okh.id in(
6220                                                 SELECT okg1.included_chr_id from  okc_k_grpings okg1
6221                                                 WHERE okg1.included_chr_id is not null
6222                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6223                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6224             END IF;
6225           ELSE
6226               l_stmt := l_select||' ,okg.cgp_parent_id old_value'||
6227                        l_from||',okc_k_groups_grpings_v okg'||
6228                        l_where||' AND okg.included_chr_id = okh.id
6229      					          AND okg.cgp_parent_id = to_number(:p_ctr_rec_old_value)
6230                                   AND okh.id in(
6231                                                 SELECT okg1.included_chr_id from  okc_k_grpings okg1
6232                                                 WHERE okg1.included_chr_id is not null
6233                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6234                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6235          END IF;
6236  ------------------------------------------------------------------------------------------
6237  --  Update Level : Contract Group , Attribute: Contract Start date(CONTRACT_START_DATE)
6238  ------------------------------------------------------------------------------------------
6239 
6240         ELSIF UPPER(p_ctr_rec.attribute) = UPPER('CONTRACT_START_DATE') Then
6241 
6242           IF p_ctr_rec.old_value is NULL THEN   -- For Contract Start date as NULL
6243               l_stmt := l_select||',to_char(okh.start_date) old_value'||
6244                        l_from||
6245                        l_where||' AND okh.start_date is NULL
6246                                   AND okh.id in(
6247                                                 SELECT okg1.included_chr_id from  okc_k_grpings okg1
6248                                                 WHERE okg1.included_chr_id is not null
6249                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6250                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6251           ELSIF p_ctr_rec.old_value is not NULL THEN   -- For Contract Start date not NULL
6252               l_stmt := l_select||',to_char(okh.start_date) old_value'||
6253                        l_from||
6254                        l_where||' AND trunc(okh.start_date) = trunc(to_date(:p_ctr_rec_old_value,''YYYY/MM/DD HH24:MI:SS''))
6255                                   AND okh.id in(
6256                                                 SELECT okg1.included_chr_id from  okc_k_grpings okg1
6257                                                 WHERE okg1.included_chr_id is not null
6258                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6259                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6260           END IF;
6261  ------------------------------------------------------------------------------------------
6262  --  Update Level : Contract Group , Attribute: Contract End date (CONTRACT_END_DATE)
6263  ------------------------------------------------------------------------------------------
6264 
6265         ELSIF UPPER(p_ctr_rec.attribute) = UPPER('CONTRACT_END_DATE') Then
6266 
6267           IF p_ctr_rec.old_value is NULL THEN   -- For Contract End date as NULL
6268               l_stmt := l_select||',to_char(okh.end_date) old_value'||
6269                        l_from||
6270                        l_where||' AND okh.end_date is NULL
6271                                   AND okh.id in(
6272                                                 SELECT okg1.included_chr_id from  okc_k_grpings okg1
6273                                                 WHERE okg1.included_chr_id is not null
6274                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6275                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6276           ELSIF p_ctr_rec.old_value is not NULL THEN   -- For Contract End date not NULL
6277               l_stmt := l_select||',to_char(okh.end_date) old_value'||
6278                        l_from||
6279                        l_where||' AND trunc(okh.end_date) = trunc(to_date(:p_ctr_rec_old_value,''YYYY/MM/DD HH24:MI:SS''))
6280                                   AND okh.id in(
6281                                                 SELECT okg1.included_chr_id from  okc_k_grpings okg1
6282                                                 WHERE okg1.included_chr_id is not null
6283                                                 START WITH okg1.cgp_parent_id = to_number(:update_level_value)
6284                                                 CONNECT BY okg1.cgp_parent_id = PRIOR okg1.included_cgp_id)';
6285            END IF;
6286         END IF;
6287 
6288  END IF;
6289 
6290 --   dbms_output.put_line(' Starts') ;
6291   IF p_query_type = 'FETCH' THEN
6292 
6293      /*If fnd_profile.value('OKC_VIEW_K_BY_ORG') = 'Y' THEN
6294             l_org_id    := FND_PROFILE.VALUE('ORG_ID');
6295             l_org_where := ' AND okh.org_id  = :org_id' ;
6296             l_stmt      := l_stmt||l_org_where||' order by okh.contract_number' ;
6297 
6298 --   dbms_output.put_line('Inside l_org_id:'||to_char(l_org_id)) ;
6299 
6300             IF p_ctr_rec.oie_id IS NOT NULL then
6301                   IF p_ctr_rec.old_value IN ('-1111', '-9999') THEN
6302 
6303 	    	   IF p_ctr_rec.old_value = '-1111'
6304                        AND p_ctr_rec.attribute IN ('PO_REQUIRED_REN','SUMMARY_PRINT'
6305                              ,'CON_RENEWAL_TYPE','BP_PRICE_LIST','COV_TYPE','COV_TIMEZONE'
6306                              ,'PREF_ENGG','RES_GROUP' ) Then
6307 
6308 	    	 	OPEN v_CurContract FOR l_stmt
6309 	    	 	using l_old_value, p_ctr_rec.oie_id
6310 	    	 	     , p_ctr_rec.update_level_value,l_org_id;
6311 	    	   Else
6312 	    	 	OPEN v_CurContract FOR l_stmt
6313 	    	 	using p_ctr_rec.oie_id , p_ctr_rec.update_level_value,l_org_id;
6314 	    	   End If;
6315                   ELSE
6316                         IF p_ctr_rec.attribute  IN ( 'COVERAGE_START_TIME'
6317                         ,'COVERAGE_END_TIME','SALES_REP') then
6318                                OPEN v_CurContract FOR l_stmt
6319                                using l_old_value, p_ctr_rec.oie_id ,
6320                                     p_ctr_rec.old_value, p_ctr_rec.old_value
6321                                     , p_ctr_rec.update_level_value ,l_org_id;
6322                         ELSIF p_ctr_rec.attribute IN( 'REACTION_TIME' , 'RESOLUTION_TIME') then
6323                            OPEN v_CurContract FOR l_stmt
6324                            using l_old_value, p_ctr_rec.oie_id , p_ctr_rec.old_value,
6325                                p_ctr_rec.old_value,p_ctr_rec.old_value,p_ctr_rec.old_value
6326                                ,p_ctr_rec.old_value, p_ctr_rec.old_value,p_ctr_rec.old_value
6327                                ,p_ctr_rec.update_level_value,l_org_id;
6328 
6329                         ELSIF p_ctr_rec.attribute IN ('REV_ACCT','AGREEMENT_NAME','PRODUCT_ALIAS'
6330                               ,'CONTRACT_LINE_REF','PARTY_SHIPPING_CONTACT'
6331                               ,'PARTY_BILLING_CONTACT','LINE_SHIPPING_CONTACT','LINE_BILLING_CONTACT'
6332                               ,'PO_REQUIRED_REN','SUMMARY_PRINT','CON_RENEWAL_TYPE','BP_PRICE_LIST'
6333                               ,'COV_TYPE','COV_TIMEZONE', 'PREF_ENGG','RES_GROUP' ) Then
6334                              OPEN v_CurContract FOR l_stmt
6335                              using l_old_value, p_ctr_rec.oie_id ,
6336                                     p_ctr_rec.old_value, p_ctr_rec.update_level_value,l_org_id;
6337 
6338                         ELSE
6339                             OPEN v_CurContract FOR l_stmt using p_ctr_rec.oie_id ,
6340                              p_ctr_rec.old_value, p_ctr_rec.update_level_value,l_org_id;
6341                         END IF ;
6342                   END IF;
6343             ELSE -- *** p_ctr_rec.oie_id IS NULL ***
6344             --   dbms_output.put_line('Inside l_org_id else:') ;
6345                  IF p_ctr_rec.old_value IN ('-1111', '-9999') THEN
6346 
6347 	    	      IF p_ctr_rec.old_value = '-1111'
6348                           AND p_ctr_rec.attribute IN ('PO_REQUIRED_REN','SUMMARY_PRINT'
6349                                 ,'CON_RENEWAL_TYPE','BP_PRICE_LIST','COV_TYPE','COV_TIMEZONE'
6350                                 ,'PREF_ENGG','RES_GROUP' ) Then
6351                              OPEN v_CurContract FOR l_stmt
6352                              using l_old_value, p_ctr_rec.update_level_value,l_org_id;
6353 	    	      Else
6354                              OPEN v_CurContract FOR l_stmt
6355                              using p_ctr_rec.update_level_value,l_org_id;
6356 	    	      End If;
6357                  ELSE
6358                        IF p_ctr_rec.attribute IN ( 'COVERAGE_START_TIME',
6359                           'COVERAGE_END_TIME','SALES_REP') then
6360                              OPEN v_CurContract FOR l_stmt
6361                              using l_old_value, p_ctr_rec.old_value,
6362                                    p_ctr_rec.old_value , p_ctr_rec.update_level_value,l_org_id;
6363                        ELSIF p_ctr_rec.attribute IN ( 'REACTION_TIME' , 'RESOLUTION_TIME') then
6364                                OPEN v_CurContract FOR l_stmt
6365                                using l_old_value, p_ctr_rec.old_value,
6366                                     p_ctr_rec.old_value,p_ctr_rec.old_value,p_ctr_rec.old_value,
6367                                     p_ctr_rec.old_value,p_ctr_rec.old_value,p_ctr_rec.old_value,
6368                                     p_ctr_rec.update_level_value,l_org_id;
6369                        ELSIF p_ctr_rec.attribute IN ('REV_ACCT','AGREEMENT_NAME','PRODUCT_ALIAS'
6370                                 ,'CONTRACT_LINE_REF','PARTY_SHIPPING_CONTACT'
6371                                 ,'PARTY_BILLING_CONTACT','LINE_SHIPPING_CONTACT','LINE_BILLING_CONTACT'
6372                                 ,'PO_REQUIRED_REN','SUMMARY_PRINT','CON_RENEWAL_TYPE','BP_PRICE_LIST'
6373                                 ,'COV_TYPE','COV_TIMEZONE', 'PREF_ENGG','RES_GROUP' ) Then
6374                             OPEN v_CurContract FOR l_stmt
6375                             using l_old_value, p_ctr_rec.old_value,
6376                                  p_ctr_rec.update_level_value,l_org_id;
6377                        ELSE
6378                             OPEN v_CurContract FOR l_stmt using p_ctr_rec.old_value,
6379                                  p_ctr_rec.update_level_value,l_org_id;
6380                        END IF ;
6381                  END IF;
6382             END IF;
6383 
6384      Else -- *** Org not enabled ***
6385      */
6386 	  If p_ctr_rec.attribute  IN ('SALES_REP', 'REV_ACCT') Then
6387                 l_org_id    := p_ctr_rec.ORG_ID ;
6388                 l_org_where := ' AND okh.org_id  = :org_id' ;
6389                 l_stmt      := l_stmt||l_org_where||' order by okh.contract_number' ;
6390           Else
6391                 l_stmt      := l_stmt||' order by okh.contract_number' ;
6392           End If;
6393 
6394           IF p_ctr_rec.oie_id IS NOT NULL then
6395 
6396                  IF p_ctr_rec.old_value IN ('-1111', '-9999') THEN
6397 	  	       IF p_ctr_rec.old_value = '-1111'
6398 	  	          AND p_ctr_rec.attribute IN ('PO_REQUIRED_REN','SUMMARY_PRINT'
6399 	  	              ,'CON_RENEWAL_TYPE','BP_PRICE_LIST','COV_TYPE','COV_TIMEZONE'
6400 	  	              ,'PREF_ENGG','RES_GROUP' ) Then
6401                               OPEN v_CurContract FOR l_stmt
6402                               using l_old_value, p_ctr_rec.oie_id , p_ctr_rec.update_level_value;
6403 	  	       Else
6404 	  	              OPEN v_CurContract FOR l_stmt
6405 	  	              using p_ctr_rec.oie_id , p_ctr_rec.update_level_value;
6406 	  	       End If;
6407                  ELSE
6408                       IF p_ctr_rec.attribute IN ( 'COVERAGE_START_TIME','COVERAGE_END_TIME') then
6409                             OPEN v_CurContract FOR l_stmt
6410                             using l_old_value, p_ctr_rec.oie_id ,
6411                                   p_ctr_rec.old_value, p_ctr_rec.old_value
6412 	                          , p_ctr_rec.update_level_value;
6413                       ELSIF p_ctr_rec.attribute = 'SALES_REP' then
6414                             OPEN v_CurContract FOR l_stmt
6415                             using l_old_value, p_ctr_rec.oie_id ,
6416                                   p_ctr_rec.old_value, p_ctr_rec.old_value
6417 	                          , p_ctr_rec.update_level_value, l_org_id;
6418                       ELSIF p_ctr_rec.attribute = 'REV_ACCT' then
6419                            OPEN v_CurContract FOR l_stmt
6420                            using l_old_value, p_ctr_rec.oie_id ,
6421                            p_ctr_rec.old_value, p_ctr_rec.update_level_value, l_org_id;
6422                       ELSIF p_ctr_rec.attribute IN ( 'REACTION_TIME' , 'RESOLUTION_TIME') then
6423                           OPEN v_CurContract FOR l_stmt
6424 	  	 	    using l_old_value, p_ctr_rec.oie_id , p_ctr_rec.old_value,
6425 	  	 	    p_ctr_rec.old_value,p_ctr_rec.old_value,p_ctr_rec.old_value,p_ctr_rec.old_value,
6426 	  	 	    p_ctr_rec.old_value,p_ctr_rec.old_value,p_ctr_rec.update_level_value;
6427                       ELSIF p_ctr_rec.attribute IN ( 'AGREEMENT_NAME','PRODUCT_ALIAS'
6428 	  	 	    ,'CONTRACT_LINE_REF','PARTY_SHIPPING_CONTACT'
6429 	  	 	    ,'PARTY_BILLING_CONTACT','LINE_SHIPPING_CONTACT','LINE_BILLING_CONTACT'
6430 	  	 	    ,'PO_REQUIRED_REN','SUMMARY_PRINT','CON_RENEWAL_TYPE','BP_PRICE_LIST'
6431 	  	 	    ,'COV_TYPE','COV_TIMEZONE', 'PREF_ENGG','RES_GROUP' ) Then
6432                            OPEN v_CurContract FOR l_stmt
6433                            using l_old_value, p_ctr_rec.oie_id ,
6434                            p_ctr_rec.old_value, p_ctr_rec.update_level_value;
6435                       ELSE
6436                            OPEN v_CurContract FOR l_stmt using p_ctr_rec.oie_id ,
6437                             p_ctr_rec.old_value, p_ctr_rec.update_level_value;
6438                       END IF ;
6439                  END IF;
6440 
6441           ELSE  -- *** p_ctr_rec.oie_id IS NULL ***
6442 
6443 	       IF p_ctr_rec.old_value IN ('-1111', '-9999') THEN
6444 	  	      IF p_ctr_rec.old_value = '-1111'
6445 	  	      AND p_ctr_rec.attribute IN ('PO_REQUIRED_REN','SUMMARY_PRINT'
6446 	  	          ,'CON_RENEWAL_TYPE','BP_PRICE_LIST','COV_TYPE','COV_TIMEZONE'
6447 	  	          ,'PREF_ENGG','RES_GROUP' ) Then
6448 	  	          OPEN v_CurContract FOR l_stmt
6449 	  	          using l_old_value, p_ctr_rec.update_level_value;
6450 	  	      Else
6451 	  	          OPEN v_CurContract FOR l_stmt using p_ctr_rec.update_level_value;
6452 	  	      End If;
6453                ELSE
6454                      IF p_ctr_rec.attribute IN ('COVERAGE_START_TIME','COVERAGE_END_TIME') then
6455 	  	  	OPEN v_CurContract FOR l_stmt
6456 	  	  	USING l_old_value, p_ctr_rec.old_value,
6457                                 p_ctr_rec.old_value , p_ctr_rec.update_level_value;
6458                       ELSIF p_ctr_rec.attribute = 'SALES_REP' then
6459 	  	  	OPEN v_CurContract FOR l_stmt
6460 	  	  	USING l_old_value, p_ctr_rec.old_value,
6461                                 p_ctr_rec.old_value , p_ctr_rec.update_level_value, l_org_id;
6462                       ELSIF p_ctr_rec.attribute = 'REV_ACCT' then
6463 	  	  	OPEN v_CurContract FOR l_stmt
6464 	  	  	USING l_old_value, p_ctr_rec.old_value,
6465 	  	  	     p_ctr_rec.update_level_value, l_org_id;
6466                      ELSIF  p_ctr_rec.attribute  IN ( 'REACTION_TIME' , 'RESOLUTION_TIME' ) then
6467                          OPEN v_CurContract FOR l_stmt
6468 	  	  	 using l_old_value, p_ctr_rec.old_value,
6469                                   p_ctr_rec.old_value,p_ctr_rec.old_value,p_ctr_rec.old_value,
6470                                   p_ctr_rec.old_value,p_ctr_rec.old_value,p_ctr_rec.old_value,
6471                                   p_ctr_rec.update_level_value;
6472                      ELSIF p_ctr_rec.attribute IN ('AGREEMENT_NAME','PRODUCT_ALIAS'
6473 	  	  	,'CONTRACT_LINE_REF','PARTY_SHIPPING_CONTACT'
6474 	  	  	,'PARTY_BILLING_CONTACT','LINE_SHIPPING_CONTACT','LINE_BILLING_CONTACT'
6475 	  	  	,'PO_REQUIRED_REN','SUMMARY_PRINT','CON_RENEWAL_TYPE','BP_PRICE_LIST'
6476 	  	  	,'COV_TYPE','COV_TIMEZONE', 'PREF_ENGG','RES_GROUP' ) Then
6477 	  	  	OPEN v_CurContract FOR l_stmt
6478 	  	  	USING l_old_value, p_ctr_rec.old_value,
6479 	  	  	     p_ctr_rec.update_level_value;
6480                      ELSE
6481                           OPEN v_CurContract FOR l_stmt using p_ctr_rec.old_value,
6482                                p_ctr_rec.update_level_value;
6483                      END IF ;
6484                END IF;
6485           END IF; -- *** p_ctr_rec.oie_id IS NULL ?? ***
6486 --   dbms_output.put_line(' Before End If ') ;
6487   --  End If; -- Org Enabled
6488 	 i := 0;
6489 	 LOOP
6490 	    i := i +1;
6491 	    FETCH v_CurContract INTO
6492 		  x_eligible_contracts(i).CONTRACT_ID ,
6493                   x_eligible_contracts(i).CONTRACT_NUMBER ,
6494 		  x_eligible_contracts(i).CONTRACT_NUMBER_MODIFIER,
6495 		  x_eligible_contracts(i).START_DATE,
6496 		  x_eligible_contracts(i).END_DATE,
6497 		  x_eligible_contracts(i).SHORT_DESCRIPTION,
6498 		  x_eligible_contracts(i).CONTRACT_STATUS,
6499 		  x_eligible_contracts(i).PARTY ,
6500 		  x_eligible_contracts(i).operating_unit,
6501 		  x_eligible_contracts(i).billed_at_source,
6502                   x_eligible_contracts(i).OLD_VALUE  ;
6503 
6504 
6505 	   EXIT WHEN v_CurContract%NOTFOUND;
6506 
6507            END LOOP;
6508 
6509          CLOSE v_CurContract;
6510          --errorout_n(x_eligible_contracts.count);
6511    ELSIF p_query_type = 'PROCESS' THEN
6512 
6513       /*If fnd_profile.value('OKC_VIEW_K_BY_ORG') = 'Y' THEN
6514           l_org_id    := FND_PROFILE.VALUE('ORG_ID');
6515           l_org_where := ' AND okh.org_id  = :org_id' ;
6516           l_stmt      := l_stmt||l_org_where ;
6517 
6518            IF p_ctr_rec.old_value IN ('-1111', '-9999') THEN
6519 		IF p_ctr_rec.old_value = '-1111'
6520 		AND p_ctr_rec.attribute IN ('PO_REQUIRED_REN','SUMMARY_PRINT'
6521 		    ,'CON_RENEWAL_TYPE','BP_PRICE_LIST','COV_TYPE','COV_TIMEZONE'
6522 		    ,'PREF_ENGG','RES_GROUP' ) Then
6523 
6524 		    OPEN v_CurContract FOR l_stmt
6525 		    using l_old_value, p_ctr_rec.oie_id ,
6526                           p_ctr_rec.update_level_value,l_org_id;
6527 		Else
6528 		    OPEN v_CurContract FOR l_stmt using p_ctr_rec.oie_id ,
6529                          p_ctr_rec.update_level_value,l_org_id;
6530 		End If;
6531            ELSE
6532               IF p_ctr_rec.attribute  IN ('COVERAGE_START_TIME'
6533 		 ,'COVERAGE_END_TIME', 'SALES_REP') then
6534                   OPEN v_CurContract FOR l_stmt
6535 		  USING l_old_value, p_ctr_rec.oie_id ,p_ctr_rec.old_value,
6536                        p_ctr_rec.old_value , p_ctr_rec.update_level_value,l_org_id;
6537               ELSIF p_ctr_rec.attribute  IN ( 'REACTION_TIME' ,'RESOLUTION_TIME') then
6538                     OPEN v_CurContract FOR l_stmt
6539 		    USING l_old_value, p_ctr_rec.oie_id, p_ctr_rec.old_value,
6540                          p_ctr_rec.old_value,p_ctr_rec.old_value,p_ctr_rec.old_value,
6541                          p_ctr_rec.old_value,p_ctr_rec.old_value,p_ctr_rec.old_value,
6542                          p_ctr_rec.update_level_value,l_org_id;
6543 	      ELSIF p_ctr_rec.attribute IN ('REV_ACCT','AGREEMENT_NAME','PRODUCT_ALIAS'
6544 			,'CONTRACT_LINE_REF','PARTY_SHIPPING_CONTACT'
6545 			,'PARTY_BILLING_CONTACT','LINE_SHIPPING_CONTACT','LINE_BILLING_CONTACT'
6546 			,'PO_REQUIRED_REN','SUMMARY_PRINT','CON_RENEWAL_TYPE','BP_PRICE_LIST'
6547 			,'COV_TYPE','COV_TIMEZONE', 'PREF_ENGG','RES_GROUP' ) Then
6548                    OPEN v_CurContract FOR l_stmt
6549 		   using l_old_value, p_ctr_rec.oie_id ,
6550                         p_ctr_rec.old_value,p_ctr_rec.update_level_value,l_org_id;
6551               ELSE
6552                    OPEN v_CurContract FOR l_stmt using p_ctr_rec.oie_id ,
6553                         p_ctr_rec.old_value,p_ctr_rec.update_level_value,l_org_id;
6554               END IF ;
6555            END IF;*/
6556       --Else  -- *** Org Not Enabled ***
6557 	  If p_ctr_rec.attribute  IN ('SALES_REP', 'REV_ACCT') Then
6558                 l_org_id    := p_ctr_rec.ORG_ID ;
6559                 l_org_where := ' AND okh.org_id  = :org_id' ;
6560                 l_stmt      := l_stmt||l_org_where ;
6561           End If;
6562 
6563            IF p_ctr_rec.old_value IN ('-1111', '-9999') THEN
6564 		IF p_ctr_rec.old_value = '-1111'
6565 		AND p_ctr_rec.attribute IN ('PO_REQUIRED_REN','SUMMARY_PRINT'
6566 		    ,'CON_RENEWAL_TYPE','BP_PRICE_LIST','COV_TYPE','COV_TIMEZONE'
6567 		    ,'PREF_ENGG','RES_GROUP' ) Then
6568 		    OPEN v_CurContract FOR l_stmt using l_old_value, p_ctr_rec.oie_id ,
6569 	                p_ctr_rec.update_level_value;
6570 		Else
6571 		    OPEN v_CurContract FOR l_stmt using p_ctr_rec.oie_id ,
6572 	                p_ctr_rec.update_level_value;
6573 		End If;
6574            ELSE
6575               IF p_ctr_rec.attribute  IN ('COVERAGE_START_TIME' , 'COVERAGE_END_TIME') then
6576                   OPEN v_CurContract FOR l_stmt
6577 		  using l_old_value, p_ctr_rec.oie_id ,p_ctr_rec.old_value,
6578                        p_ctr_rec.old_value , p_ctr_rec.update_level_value;
6579               ELSIF p_ctr_rec.attribute  = 'SALES_REP' then
6580                   OPEN v_CurContract FOR l_stmt
6581 		  using l_old_value, p_ctr_rec.oie_id ,p_ctr_rec.old_value,
6582                        p_ctr_rec.old_value , p_ctr_rec.update_level_value, l_org_id;
6583               ELSIF p_ctr_rec.attribute  = 'REV_ACCT' then
6584                    OPEN v_CurContract FOR l_stmt
6585 		   USING l_old_value, p_ctr_rec.oie_id ,
6586                         p_ctr_rec.old_value, p_ctr_rec.update_level_value,l_org_id;
6587               ELSIF p_ctr_rec.attribute IN ('REACTION_TIME' , 'RESOLUTION_TIME') then
6588                     OPEN v_CurContract FOR l_stmt
6589 		    using l_old_value, p_ctr_rec.oie_id, p_ctr_rec.old_value,
6590                          p_ctr_rec.old_value,p_ctr_rec.old_value,p_ctr_rec.old_value,
6591                          p_ctr_rec.old_value,p_ctr_rec.old_value,p_ctr_rec.old_value,
6592                          p_ctr_rec.update_level_value;
6593 	      ELSIF p_ctr_rec.attribute IN ('AGREEMENT_NAME','PRODUCT_ALIAS'
6594 			,'CONTRACT_LINE_REF','PARTY_SHIPPING_CONTACT'
6595 			,'PARTY_BILLING_CONTACT','LINE_SHIPPING_CONTACT','LINE_BILLING_CONTACT'
6596 			,'PO_REQUIRED_REN','SUMMARY_PRINT','CON_RENEWAL_TYPE','BP_PRICE_LIST'
6597 			,'COV_TYPE','COV_TIMEZONE', 'PREF_ENGG','RES_GROUP' ) Then
6598                    OPEN v_CurContract FOR l_stmt
6599 		   USING l_old_value, p_ctr_rec.oie_id ,
6600                         p_ctr_rec.old_value,p_ctr_rec.update_level_value;
6601               ELSE
6602                    OPEN v_CurContract FOR l_stmt using p_ctr_rec.oie_id ,
6603                         p_ctr_rec.old_value,p_ctr_rec.update_level_value;
6604               END IF ;
6605            END IF;
6606       --End If; -- Org Enabled
6607 		 i := 0;
6608 		 LOOP
6609 		    i := i +1;
6610 		    FETCH v_CurContract INTO
6611 			  x_eligible_contracts(i).CONTRACT_ID,
6612 			  x_eligible_contracts(i).CONTRACT_NUMBER ,
6613 			  x_eligible_contracts(i).CONTRACT_NUMBER_MODIFIER,
6614 			  x_eligible_contracts(i).START_DATE,
6615 			  x_eligible_contracts(i).END_DATE,
6616 			  x_eligible_contracts(i).SHORT_DESCRIPTION,
6617 			  x_eligible_contracts(i).CONTRACT_STATUS,
6618                           x_eligible_contracts(i).qcl_id,
6619                           x_eligible_contracts(i).object_version_number,
6620                           x_eligible_contracts(i).ole_id,
6621                           x_eligible_contracts(i).org_id,
6622                           x_eligible_contracts(i).qa_check_yn,
6623                           x_eligible_contracts(i).operating_unit,
6624 			  x_eligible_contracts(i).billed_at_source,
6625                           x_eligible_contracts(i).old_value;
6626 
6627 		   EXIT WHEN v_CurContract%NOTFOUND;
6628          -- dbms_output.put_line('contract_id:'||to_number(x_eligible_contracts(i).CONTRACT_ID));
6629            END LOOP;
6630         CLOSE v_CurContract;
6631         --------------------------------
6632       END IF;
6633       EXCEPTION
6634 	 WHEN NO_DATA_FOUND THEN
6635 	    NULL;
6636 	 WHEN OTHERS THEN
6637 
6638 	    OKC_API.SET_MESSAGE( p_app_name	=> G_APP_NAME_OKC
6639 	    			         ,p_msg_name	=> G_UNEXPECTED_ERROR
6640 				         ,p_token1		=> G_SQLCODE_TOKEN
6641 				         ,p_token1_value	=> SQLcode
6642 				         ,p_token2		=> G_SQLERRM_TOKEN
6643 				         ,p_token2_value	=> SQLerrm);
6644 
6645 --	  x_return_status := G_UNEXPECTED_ERROR;
6646       x_return_status :=  G_RET_STS_UNEXP_ERROR ;
6647 
6648   END get_eligible_contracts;
6649 
6650 -----------------------------------------------------------------------------------------
6651 --CALL THIS FUNCTION IF U WANT TO SUBMIT CONC REQ FROM THE FORM
6652 -----------------------------------------------------------------------------------------
6653 
6654   FUNCTION SUBMIT_CONC_FORM(p_oie_id              IN NUMBER,
6655                             p_process_type        IN VARCHAR2,
6656                             p_schedule_time       IN VARCHAR2,
6657                             p_check_yn            IN VARCHAR2
6658                             ) RETURN NUMBER IS
6659   req_id NUMBER;
6660   l_mode BOOLEAN;
6661   e_msg Varchar2(2000);
6662 
6663   BEGIN
6664   l_mode := FND_REQUEST.SET_MODE(TRUE);
6665 
6666   -- Modified the follwing code the fix the translation issue.
6667   -- Removed the program description which was passed to FND API
6668   -- Original code is commented below. Bug#3347626
6669 
6670   IF p_schedule_time = 'ASAP' then
6671       req_id := FND_REQUEST.SUbmit_request('OKS'
6672                                            ,'OKSMSCHG'
6673                                            ,Null
6674                                            ,SYSDATE
6675                                            ,FALSE
6676                                            ,p_oie_id
6677                                            ,p_process_type
6678                                            ,p_check_yn);
6679   ELSIF (p_schedule_time IS not NULL) and (p_schedule_time <> 'ASAP' ) then
6680      req_id := FND_REQUEST.submit_request('OKS'
6681                                          ,'OKSMSCHG'
6682                                          ,Null
6683                                          ,p_schedule_time
6684                                          ,FALSE
6685                                          ,p_oie_id
6686                                          ,p_process_type
6687                                          ,p_check_yn);
6688   END IF;
6689 
6690 --  IF p_schedule_time = 'ASAP' then
6691 --      req_id := FND_REQUEST.submit_request('OKS'
6692 --                                           ,'OKSMSCHG'
6693 --                                           ,'Service Contracts Mass Change'
6694 --                                           ,SYSDATE
6695 --                                           ,FALSE
6696 --                                           ,p_oie_id
6697 --                                           ,p_process_type
6698 --                                           ,p_check_yn);
6699 --  ELSIF (p_schedule_time IS not NULL) and (p_schedule_time <> 'ASAP' ) then
6700 --     req_id := FND_REQUEST.submit_request('OKS'
6701 --                                         ,'OKSMSCHG'
6702 --                                         ,'Service Contracts Mass Change'
6703 --                                         ,p_schedule_time
6704 --                                         ,FALSE
6705 --                                         ,p_oie_id
6706 --                                         ,p_process_type
6707 --                                         ,p_check_yn);
6708 --  END IF;
6709 
6710 
6711 --      IF req_id <> 0 THEN
6712 --            IF p_process_type = 'SUBMIT' THEN
6713 --
6714 --               UPDATE OKC_OPERATION_INSTANCES
6715 --               SET request_id = req_id,
6716 --                   status_code = 'UNDER_PROCESS'
6717 --               WHERE id = p_oie_id;
6718 --            ELSIF p_process_type = 'SUBMIT' THEN
6719 --
6720 --               UPDATE OKC_OPERATION_INSTANCES
6721 --               SET request_id = req_id,
6722 --                   status_code = 'UNDER_PREVIEW'
6723 --               WHERE id = p_oie_id;
6724 --            END IF;
6725 --         COMMIT;
6726 --     END IF;
6727 
6728     RETURN(req_id);
6729 
6730     EXCEPTION
6731            WHEN OTHERS THEN
6732            -- Add code for exception;
6733               NULL;
6734 
6735   END SUBMIT_CONC_FORM;
6736 
6737  PROCEDURE Notify_completion(p_process_type    IN Varchar2,
6738                              p_req_id          IN Number,
6739                              p_masschange_name IN Varchar2)IS
6740  BEGIN
6741 
6742        OKC_API.SET_MESSAGE(p_app_name	=> 'OKS',
6743 			p_msg_name	=> 'OKS_MSCHG_NOTIFY_S',
6744 			p_token1	=> 'PROCESS_TYPE',
6745 			p_token1_value	=>  p_process_type,
6746 			p_token2	=> 'REQUEST_ID',
6747 			p_token2_value	=>  p_req_id,
6748 			p_token3	=> 'MASSCHANGE_NAME',
6749 			p_token3_value	=>  p_masschange_name);
6750 
6751     EXCEPTION
6752            WHEN OTHERS THEN
6753            -- Add code for exception;
6754               NULL;
6755  END Notify_completion;
6756 
6757  PROCEDURE SUBMIT_CONC(ERRBUF                         OUT NOCOPY VARCHAR2,
6758                        RETCODE                        OUT NOCOPY NUMBER,
6759                        p_oie_id                       IN NUMBER,
6760                        p_process_type                 IN VARCHAR2,
6761                        p_check_yn                     IN VARCHAR2 ) IS
6762 
6763   CURSOR get_oie_name IS
6764          SELECT name, usr.user_name
6765          FROM okc_operation_instances_v oie,
6766               fnd_user usr
6767          WHERE id = p_oie_id
6768          AND   oie.last_updated_by = usr.user_id;
6769   l_errbuf VARCHAR2(200);
6770   l_retcode NUMBER;
6771   l_api_version		CONSTANT	NUMBER	:= 1.0;
6772   l_init_msg_list	VARCHAR2(2000) ;
6773   l_return_status	VARCHAR2(1);
6774   l_msg_count		NUMBER;
6775   l_msg_data		VARCHAR2(2000);
6776 
6777   l_msg_index_out	NUMBER;
6778   l_msg_index		NUMBER;
6779 
6780   l_cle_id          NUMBER;
6781   l_proc            VARCHAR(1000);
6782   l_oie_name        VARCHAR2(150);
6783   l_req_id          NUMBER;
6784   l_user_name       VARCHAR2(50);
6785 
6786  BEGIN
6787 
6788    l_init_msg_list :=  'T';
6789 
6790    IF p_process_type in ('SUBMIT','PREVIEW') THEN
6791 
6792         OKS_MASSCHANGE_PVT.SUBMIT
6793                            (   errbuf            => l_errbuf,
6794                                retcode           => l_retcode,
6795                                p_api_version	 => l_api_version,
6796     	                       p_init_msg_list	 => l_init_msg_list,
6797     	                       x_return_status 	 => l_return_status,
6798     	                       x_msg_count       => l_msg_count,
6799     	                       x_msg_data	 => l_msg_data,
6800                                p_conc_program    => 'Y',
6801                                p_process_type    => p_process_type,
6802                                p_oie_id          => p_oie_id,
6803                                p_check_yn        => p_check_yn );
6804    ELSE
6805           LOG_MESSAGES('Not a Valid Mass Change Process Type. Valid values are SUBMIT and PREVIEW');
6806    END IF;
6807 
6808        OPEN  get_oie_name;
6809        FETCH get_oie_name INTO l_oie_name, l_user_name;
6810        CLOSE get_oie_name;
6811 
6812         l_req_id := FND_GLOBAL.CONC_REQUEST_ID;
6813 
6814           LOG_MESSAGES('Name:'||l_oie_name||', request id#'||l_req_id);
6815 
6816           l_proc := 'BEGIN OKS_MASSCHANGE_PVT.Notify_completion('||
6817                  'p_process_type     =>'||''''||p_process_type||''''||
6818                  ',p_req_id          =>'||l_req_id||
6819                  ',p_masschange_name  =>'||''''||l_oie_name||''''||'); END ;';
6820 
6821 --           l_proc := 'Begin
6822 --                      OKS_MASSCHANGE_PVT.Notify_completion('''||p_process_type||''','||l_req_id||
6823 --                  ','''||l_oie_name||''');
6824 --                      End;';
6825 
6826           OKC_ASYNC_PUB.loop_call(
6827 			        p_api_version       => l_api_version,
6828                  	        p_init_msg_list	    => l_init_msg_list,
6829     	                        x_return_status	    => l_return_status,
6830     	                        x_msg_count	    => l_msg_count,
6831     	                        x_msg_data          => l_msg_data,
6832         		   	p_proc	            => l_proc,
6833 		        	p_s_recipient       => l_user_name );
6834 
6835         LOG_MESSAGES('OKC_ASYNC_PUB.loop_call status: '||l_return_status);
6836         fnd_msg_pub.get (p_msg_index     => -1,
6837                          p_encoded       => 'F',
6838                          p_data          => l_msg_data,
6839                          p_msg_index_out => l_msg_index_out);
6840           LOG_MESSAGES('Message:'||l_msg_data);
6841 
6842  END  SUBMIT_CONC;
6843 
6844 
6845  PROCEDURE SUBMIT_MASSCHANGE(ERRBUF                         OUT NOCOPY VARCHAR2,
6846                              RETCODE                        OUT NOCOPY NUMBER,
6847                              p_oie_id                       IN NUMBER,
6848                              p_check_yn                     IN  Varchar2 ) IS
6849   l_errbuf VARCHAR2(200);
6850   l_retcode NUMBER;
6851   l_api_version		CONSTANT	NUMBER	:= 1.0;
6852   l_init_msg_list	VARCHAR2(2000) := OKC_API.G_FALSE;
6853   l_return_status	VARCHAR2(1);
6854   l_msg_count		NUMBER;
6855   l_msg_data		VARCHAR2(2000);
6856 
6857   l_msg_index_out	NUMBER;
6858   l_msg_index		NUMBER;
6859 
6860   l_cle_id NUMBER;
6861 
6862  BEGIN
6863 
6864        OKS_MASSCHANGE_PVT.SUBMIT_CONC(errbuf                  => l_errbuf,
6865                                       retcode                 => l_retcode,
6866                                       p_process_type          => 'SUBMIT',
6867                                       p_oie_id                => p_oie_id,
6868                                       p_check_yn              => p_check_yn ) ;
6869 
6870  END  SUBMIT_MASSCHANGE;
6871 
6872  PROCEDURE PREVIEW_MASSCHANGE(ERRBUF                         OUT NOCOPY VARCHAR2,
6873                               RETCODE                        OUT NOCOPY NUMBER,
6874                               p_oie_id                       IN NUMBER,
6875                               p_check_yn                     IN  Varchar2 ) IS
6876   l_errbuf VARCHAR2(200);
6877   l_retcode NUMBER;
6878   l_api_version		CONSTANT	NUMBER	:= 1.0;
6879   l_init_msg_list	VARCHAR2(2000) := OKC_API.G_FALSE;
6880   l_return_status	VARCHAR2(1);
6881   l_msg_count		NUMBER;
6882   l_msg_data		VARCHAR2(2000);
6883 
6884   l_msg_index_out	NUMBER;
6885   l_msg_index		NUMBER;
6886 
6887   l_cle_id NUMBER;
6888 
6889  BEGIN
6890 
6891        OKS_MASSCHANGE_PVT.SUBMIT_CONC(errbuf                  => l_errbuf,
6892                                       retcode                 => l_retcode,
6893                                       p_process_type          => 'PREVIEW',
6894                                       p_oie_id                => p_oie_id,
6895                                       p_check_yn              => p_check_yn ) ;
6896  END  PREVIEW_MASSCHANGE;
6897 
6898 -----------------------------------------------------------------------------------------
6899 --SUBMIT
6900 -----------------------------------------------------------------------------------------
6901  PROCEDURE SUBMIT(ERRBUF                         OUT NOCOPY VARCHAR2,
6902                   RETCODE                        OUT NOCOPY NUMBER,
6903                   p_api_version                  IN  NUMBER,
6904                   p_init_msg_list                IN  VARCHAR2 DEFAULT OKC_API.G_FALSE,
6905                   x_return_status                OUT NOCOPY VARCHAR2,
6906                   x_msg_count                    OUT NOCOPY NUMBER,
6907                   x_msg_data                     OUT NOCOPY VARCHAR2,
6908                   p_conc_program                 IN  VARCHAR2,
6909          	        p_process_type                 IN  Varchar2,
6910                   p_oie_id                       IN  NUMBER,
6911                   p_check_yn                     IN VARCHAR2)
6912      IS
6913 
6914      CURSOR get_criteria_cur IS
6915             SELECT oie.name,
6916                    oie.jtot_object1_code update_level,
6917                    oie.object1_id1 update_level_value,
6918                    omr.ATTRIBUTE_NAME attribute,
6919                    omr.OLD_VALUE old_value,
6920                    omr.NEW_VALUE new_value
6921             FROM   okc_operation_instances_v oie,
6922                    okc_masschange_req_dtls omr
6923             WHERE  oie.id = omr.oie_id
6924             AND    oie.id = p_oie_id;
6925 
6926    CURSOR Get_cgrp_id(p_chr_id IN Number, p_cgp_id IN Number) IS
6927             SELECT id
6928             FROM okc_k_grpings_v
6929             WHERE included_chr_id = p_chr_id
6930             AND   cgp_parent_id = p_cgp_id;
6931 
6932     CURSOR Get_cvr_start(p_chr_id IN Number, p_hour IN Number, p_minute IN Number ) IS
6933            SELECT oct.id,oct.OBJECT_VERSION_NUMBER,
6934                   oct.start_hour,oct.start_minute,oct.end_hour,oct.end_minute
6935            FROM oks_coverage_timezones_v ctz ,
6936                 oks_coverage_times_v oct
6937            WHERE  oct.cov_tze_line_id = ctz.id
6938            AND    oct.dnz_chr_id = p_chr_id
6939            AND    oct.start_hour = p_hour
6940            AND    oct.start_minute = p_minute ;
6941 
6942     CURSOR Get_cvr_end(p_chr_id IN Number, p_hour IN Number, p_minute IN Number) IS
6943            SELECT oct.id ,oct.OBJECT_VERSION_NUMBER,
6944                   oct.start_hour,oct.start_minute,oct.end_hour,oct.end_minute
6945            FROM oks_coverage_timezones_v ctz ,
6946                 oks_coverage_times_v oct
6947            WHERE  oct.cov_tze_line_id = ctz.id
6948            AND    oct.dnz_chr_id = p_chr_id
6949            AND    oct.end_hour = p_hour
6950            AND    oct.end_minute = p_minute ;
6951 
6952     -- The following cusrsor is for checking the coverage time overlap
6953     CURSOR Get_cvr_timezone(p_chr_id IN Number) IS
6954            SELECT oct.id id
6955            FROM   oks_coverage_timezones_V oct
6956            WHERE  oct.dnz_chr_id  = p_chr_id;
6957 
6958     CURSOR Get_timezone(p_chr_id IN Number , p_old_value IN Varchar2) IS
6959            SELECT oct.id id,oct.OBJECT_VERSION_NUMBER,oct.cle_id cle_id
6960            FROM   oks_coverage_timezones_V oct
6961            WHERE  oct.dnz_chr_id  = p_chr_id
6962            AND    oct.timezone_id = p_old_value ;
6963 
6964     CURSOR Get_Acct_Rule(p_chr_id IN Number, p_old_value IN Varchar2) IS
6965            SELECT oksh.id , oksh.object_version_number
6966            FROM   oks_k_headers_b oksh
6967            WHERE  oksh.chr_id = p_chr_id
6968            AND    oksh.acct_rule_id = p_old_value ;
6969 
6970     CURSOR Get_Summary_Print(p_chr_id IN Number, p_old_value IN Varchar2) IS
6971            SELECT oksh.id , oksh.object_version_number
6972            FROM   oks_k_headers_b oksh
6973            WHERE  oksh.chr_id = p_chr_id
6974            AND    nvl(oksh.inv_print_profile,'N') = p_old_value ;
6975 
6976     CURSOR Get_Electronic_Ren_YN(p_chr_id IN Number) IS
6977            SELECT oksh.id , oksh.object_version_number
6978            FROM   oks_k_headers_b oksh
6979            WHERE  oksh.chr_id = p_chr_id;
6980 
6981     CURSOR Get_po_required_ren(p_chr_id IN Number, p_old_value IN Varchar2) IS
6982            SELECT oksh.id , oksh.object_version_number
6983            FROM   oks_k_headers_v oksh
6984            WHERE  oksh.chr_id = p_chr_id
6985            AND    nvl(oksh.renewal_po_required,'N') = p_old_value ;
6986 
6987      CURSOR Get_agreement_name(p_chr_id IN Number, p_old_value IN Varchar2) IS
6988            SELECT ogv.id, ogv.object_version_number
6989            FROM   okc_governances_v ogv
6990            WHERE  ogv.dnz_chr_id = p_chr_id
6991            AND    ogv.isa_agreement_id = p_old_value ;
6992 
6993      CURSOR Get_contact(p_chr_id IN Number,p_cro_code IN Varchar2,
6994                         p_object_code IN Varchar2, p_old_value IN Varchar2) IS
6995            SELECT oc.id, oc.object_version_number, kh.start_date start_date
6996            FROM   okc_contacts oc , okc_k_headers_b kh
6997            WHERE  oc.dnz_chr_id = p_chr_id
6998            AND    oc.cro_code = p_cro_code
6999            AND    oc.object1_id1 = p_old_value
7000            AND    oc.jtot_object1_code = p_object_code
7001            And    Kh.id = oc.dnz_chr_id;
7002 
7003      CURSOR Get_revenue(p_chr_id IN Number, p_old_value IN Number) IS
7004            SELECT rev.id, rev.object_version_number
7005            FROM   oks_rev_distributions_v rev
7006            WHERE  rev.chr_id = p_chr_id
7007            AND    rev.code_combination_id = p_old_value;
7008 
7009      CURSOR Get_Salesrep(p_chr_id IN Number, p_old_value IN Varchar2) IS
7010            SELECT srv.id, srv.object_version_number, kh.start_date
7011            FROM   OKS_K_SALES_CREDITS_V srv
7012                  , Okc_k_headers_b Kh
7013            WHERE  srv.cle_id Is Null
7014            And    kh.id = p_chr_id
7015            And    kh.id = srv.chr_id
7016            AND    srv.ctc_id = to_number(p_old_value);
7017 
7018 
7019      CURSOR Get_LineSalesrep(p_chr_id IN Number, p_old_value IN Varchar2) IS
7020            SELECT srv.id, srv.object_version_number, kl.start_date
7021            FROM   OKS_K_SALES_CREDITS_V srv
7022                 , Okc_k_lines_b Kl
7023            WHERE  srv.chr_id = p_chr_id
7024            And    srv.Cle_id Is nOt null
7025            And    Kl.id = srv.cle_id
7026            AND    srv.ctc_id = to_number(p_old_value);
7027 
7028 
7029      CURSOR Get_Inelligibles(p_oie_id IN Number) IS
7030 	        SELECT okh.id,
7031                    okh.contract_number,
7032                    okh.contract_number_modifier,
7033                    okh.short_description,
7034                    okh.sts_code,
7035                    ole.id ole_id,
7036                    mrd.old_value,
7037 		   okh.billed_at_source
7038 
7039             FROM  okc_k_headers_v okh,
7040                   okc_operation_lines_v ole,
7041                   okc_masschange_req_dtls_v mrd
7042       	    WHERE ole.select_yn = 'Y'
7043 			AND   ole.process_flag is NULL
7044             AND   okh.id = ole.subject_chr_id
7045             AND   ole.id = mrd.ole_id
7046             AND   ole.oie_id = p_oie_id;
7047 
7048     /*
7049     ** Modified the cursor by adding date_cancelled
7050     ** condition as part of Line Level Cancelation project
7051     */
7052     CURSOR Get_lines_csr(p_chr_id IN NUMBER) IS
7053            SELECT okl.id id
7054            FROM   okc_k_lines_b okl
7055                  ,Oks_k_lines_b oks
7056            WHERE  okl.dnz_chr_id = p_chr_id
7057 	     AND    okl.date_cancelled is NULL
7058            And    okl.id = oks.cle_id
7059            AND   ( okl.lse_id in (1,14,19,46)
7060            or   (okl.lse_id = 12 and oks.usage_type in ('FRT','NPR'))) ;
7061 
7062     CURSOR Get_cle_id (p_chr_id IN NUMBER) IS
7063            SELECT okl.id id
7064            FROM   okc_k_lines_b okl
7065            WHERE  okl.dnz_chr_id = p_chr_id
7066 	     AND    okl.date_cancelled is NULL
7067            AND    okl.lse_id in (1,12,14,19,46) ;
7068 
7069     CURSOR Get_cle_id_PM ( p_cle_id IN NUMBER ) IS
7070            SELECT count(*) FROM oks_pm_schedules_v
7071            WHERE cle_id = p_cle_id;
7072 
7073     CURSOR Get_act_time ( p_chr_id IN NUMBER , p_action_type_code VARCHAR2
7074                  , p_old_value IN Varchar2) IS
7075            SELECT oat.id id ,oat.sun_duration ,oat.mon_duration ,oat.tue_duration ,oat.wed_duration,
7076                   oat.thu_duration ,oat.fri_duration, oat.sat_duration, oat.object_version_number
7077            FROM   OKC_K_LINES_V okl, oks_action_times oat , oks_action_time_types att
7078            WHERE  okl.dnz_chr_id     = p_chr_id
7079            AND    att.cle_id         = okl.id
7080            AND    att.action_type_code = p_action_type_code
7081            AND    oat.cov_action_type_id = att.id
7082            AND    (oat.sun_duration = p_old_value
7083                 OR oat.mon_duration = p_old_value
7084                 OR oat.tue_duration = p_old_value
7085                 OR oat.wed_duration = p_old_value
7086                 OR oat.thu_duration = p_old_value
7087                 OR oat.fri_duration = p_old_value
7088                 OR oat.sat_duration = p_old_value ) ;
7089 
7090      CURSOR Get_cov_type ( p_chr_id IN NUMBER , p_old_value IN Varchar2) IS
7091           SELECT osl.id , osl.object_version_number
7092           FROM   okc_k_lines_v okl, oks_k_lines_v osl
7093           WHERE  okl.id = osl.cle_id
7094           AND   okl.dnz_chr_id = p_chr_id
7095           AND   okl.lse_id in( 2,15,20)
7096           AND   osl.coverage_type = p_old_value  ;
7097 
7098      CURSOR get_bp_lines (p_chr_id IN Number,p_old_value in Varchar2) IS
7099            SELECT cln.id , cln.object_version_number
7100            FROM  okc_k_lines_b cln
7101            Where  cln.dnz_chr_id = p_chr_id
7102             AND cln.lse_id in(3,16,21)
7103             AND cln.price_list_id = p_old_value ;
7104 
7105      CURSOR get_bp_lines_all (p_chr_id IN Number) IS
7106            SELECT cln.id , cln.object_version_number
7107            FROM  okc_k_lines_b cln
7108            Where  cln.dnz_chr_id = p_chr_id
7109             AND cln.lse_id in(3,16,21);
7110 
7111      CURSOR get_bp_lines_null (p_chr_id IN Number) IS
7112            SELECT cln.id , cln.object_version_number
7113            FROM  okc_k_lines_b cln
7114            Where  cln.dnz_chr_id = p_chr_id
7115             AND cln.lse_id in(3,16,21)
7116             AND cln.price_list_id is null ;
7117 
7118      CURSOR get_contract_dtls (p_id IN Number) IS
7119 	    Select okch.currency_code
7120 	    From okc_k_headers_b okch
7121 	    Where okch.id = p_id ;
7122 
7123    ---------------------
7124    -- Local variables --
7125    ---------------------
7126    -- Record types and Table types --
7127    ----------------------------------
7128 
7129     l_criteria_rec                criteria_rec_type;
7130     l_eligible_contracts_tbl      eligible_contracts_tbl;
7131 
7132     l_chrv_tbl_in                 okc_contract_pub.chrv_tbl_type;
7133     l_chrv_tbl_out                okc_contract_pub.chrv_tbl_type;
7134 
7135     l_chrv_rec_in                 okc_contract_pub.chrv_rec_type;
7136     l_chrv_rec_out                okc_contract_pub.chrv_rec_type;
7137     l_chrv_rec_null               okc_contract_pub.chrv_rec_type := Null;
7138 
7139     l_clev_tbl_in                 okc_contract_pub.clev_tbl_type;
7140     l_clev_tbl_out                okc_contract_pub.clev_tbl_type;
7141 
7142     l_khrv_rec_type_in            oks_contract_hdr_pub.khrv_rec_type ;
7143     l_khrv_rec_type_out           oks_contract_hdr_pub.khrv_rec_type ;
7144 
7145     l_cgcv_rec_in                 okc_contract_group_pub.cgcv_rec_type;
7146     l_cgcv_rec_out                okc_contract_group_pub.cgcv_rec_type;
7147 
7148     l_gvev_tbl_in                 okc_gve_pvt.gvev_tbl_type;
7149     l_gvev_tbl_out                okc_gve_pvt.gvev_tbl_type;
7150 
7151     l_rilv_tbl_in                 okc_ril_pvt.rilv_tbl_type;
7152     l_rilv_tbl_out                okc_ril_pvt.rilv_tbl_type;
7153 
7154     l_olev_rec_in                 okc_oper_inst_pub.olev_rec_type;
7155     l_olev_rec_out                okc_oper_inst_pub.olev_rec_type;
7156 
7157     l_oiev_rec_in                 okc_oper_inst_pub.oiev_rec_type;
7158     l_oiev_rec_out                okc_oper_inst_pub.oiev_rec_type;
7159 
7160     l_rulv_rec_in                 okc_rule_pub.rulv_rec_type;
7161     l_rulv_rec_out                okc_rule_pub.rulv_rec_type;
7162 
7163     l_rulv_tbl_in                 okc_rule_pub.rulv_tbl_type;
7164     l_rulv_tbl_out                okc_rule_pub.rulv_tbl_type;
7165 
7166     l_ctz_recType_in              oks_ctz_pvt.OksCoverageTimezonesVRecType ;
7167     l_ctz_recType_out             oks_ctz_pvt.OksCoverageTimezonesVRecType ;
7168 
7169     l_ctz_tblType_in              oks_ctz_pvt.OksCoverageTimezonesVTblType ;
7170     l_ctz_tblType_out             oks_ctz_pvt.OksCoverageTimezonesVTblType ;
7171 
7172     l_act_rec_in                  oks_acm_pvt.oks_action_times_v_rec_type ;
7173     l_act_rec_out                 oks_acm_pvt.oks_action_times_v_rec_type ;
7174 
7175     l_act_tbl_in                  oks_acm_pvt.oks_action_times_v_tbl_type ;
7176     l_act_tbl_out                 oks_acm_pvt.oks_action_times_v_tbl_type ;
7177 
7178     l_klnv_tbl_type_in            oks_contract_line_pub.klnv_tbl_type ;
7179     l_klnv_tbl_type_out           oks_contract_line_pub.klnv_tbl_type ;
7180 
7181     l_ctcv_rec_in                 okc_ctc_pvt.ctcv_rec_type;
7182     l_ctcv_rec_out                okc_ctc_pvt.ctcv_rec_type;
7183 
7184     l_ctcv_tbl_in                 okc_ctc_pvt.ctcv_tbl_type;
7185     l_ctcv_tbl_out                okc_ctc_pvt.ctcv_tbl_type;
7186 
7187     l_rdsv_rec_in                 oks_rev_distr_pub.rdsv_rec_type;
7188     l_rdsv_rec_out                oks_rev_distr_pub.rdsv_rec_type;
7189 
7190     -- This table type is not used in the API.
7191     -- l_igsv_ext_tbl_in          okc_time_pub.igsv_ext_tbl_type;
7192     -- l_igsv_ext_tbl_out         okc_time_pub.igsv_ext_tbl_type;
7193 
7194     l_cvt_tbl_in                  oks_cvt_pvt.oks_coverage_times_v_tbl_type ;
7195     l_cvt_tbl_out                 oks_cvt_pvt.oks_coverage_times_v_tbl_type ;
7196 
7197     l_scrv_tbl_in                 oks_sales_credit_pub.scrv_tbl_type;
7198     l_scrv_tbl_out                oks_sales_credit_pub.scrv_tbl_type;
7199 
7200     l_msg_tbl                     OKC_QA_CHECK_PUB.msg_tbl_type;
7201 
7202     l_overlap_type                oks_coverages_pvt.billrate_day_overlap_type;
7203 
7204 
7205     l_count_pm_schedule           NUMBER  ;
7206     l_api_version	          CONSTANT	NUMBER	:= 1.0;
7207     l_init_msg_list	          VARCHAR2(2000) ;
7208     l_return_status	          VARCHAR2(1);
7209     l_msg_count		          NUMBER;
7210     l_msg_data		          VARCHAR2(4000);
7211     l_restricted_update	          VARCHAR2(100)  ;
7212     l_msg_index_out	          NUMBER;
7213     l_can_update_yn               VARCHAR2(1);
7214     l_can_submit_yn               VARCHAR2(1);
7215     l_notelligible_exception      Exception ;
7216 
7217     l_timezone_exists_yn          Varchar2(3);
7218     l_time_zone_id                Number ;
7219 
7220     l_cov_time_wrong              NUMBER ;
7221     l_cov_time_right              NUMBER ;
7222 
7223     cvr_cnt                       Number ;
7224     srv_cnt                       Number ;
7225     rcn_cnt                       Number ;
7226     cnt                           Number ;
7227     l_masschange_name             VARCHAR2(150);
7228     l_update_level_code           VARCHAR2(300);
7229     l_update_level_value_id       VARCHAR2(300);
7230     l_update_level                VARCHAR2(360);
7231     l_update_level_value          VARCHAR2(360);
7232     l_attribute_code              VARCHAR2(50);
7233     l_old_value_id                VARCHAR2(240);
7234     l_new_value_id                VARCHAR2(240);
7235     l_old_value_id_tmp            VARCHAR2(240); -- Created for Sales Person/Revenue Account
7236     l_org_id		          Number;
7237     l_start_date                  Date;
7238 
7239     l_hour                        Number;
7240     l_minute                      Number;
7241 
7242     l_attribute                   VARCHAR2(100);
7243     l_old_value                   VARCHAR2(300);
7244     l_new_value                   VARCHAR2(300);
7245 
7246     l_old_name                    VARCHAR2(300);
7247     l_new_name                    VARCHAR2(300);
7248 
7249     l_old_k_amount                Number;
7250     l_new_k_amount                Number;
7251     l_amt_message                 VARCHAR2(500);
7252 
7253 
7254     l_process_flag                VARCHAR2(30);
7255     l_cgrp_id                     NUMBER;
7256     l_status                      VARCHAR2(30) ;
7257     l_opn_status                  VARCHAR2(10) ;
7258     l_success_cnt                 Number ;
7259     l_error_cnt                   Number ;
7260     l_message                     VARCHAR2(4000) ;
7261     l_test                        varchar2(100);
7262     x_test_chr_id                 NUMBER ;
7263 
7264     l_warranty_flag               Varchar2(3);
7265     l_sts_code                    OKC_STATUSES_B.CODE%Type;
7266 
7267     l_empty_string1               Varchar2(500);
7268     l_dash_string1                Varchar2(500);
7269     l_process_type_msg_seed       Varchar2(100);
7270 
7271     l_currency_code               Varchar2(100);
7272     l_pricelist_valid             Varchar2(100);
7273 
7274     l_billed_at_source_msg	  Varchar2(100);
7275 
7276 
7277     TYPE l_outfile_succ_rec IS RECORD (ID         NUMBER,
7278                                   String1    Varchar2(4000),
7279                                   String2    Varchar2(4000),
7280                                   String3    Varchar2(4000)
7281                                   );
7282     TYPE l_outfile_succ_tbl IS TABLE OF l_outfile_succ_rec INDEX BY BINARY_INTEGER;
7283 
7284     l_outfiles_succ l_outfile_succ_tbl;
7285     l_outfile_success_id          NUMBER  ;
7286     l_succ_count                  NUMBER  ;
7287 
7288     TYPE l_outfile_fail_rec IS RECORD (ID         NUMBER,
7289                                   String1    Varchar2(4000),
7290                                   String2    Varchar2(4000),
7291                                   String3    Varchar2(4000)
7292                                   );
7293     TYPE l_outfile_fail_tbl IS TABLE OF l_outfile_fail_rec INDEX BY BINARY_INTEGER;
7294 
7295     l_outfiles_fail l_outfile_fail_tbl;
7296     l_outfile_fail_id             NUMBER  ;
7297     l_fail_count                  NUMBER  ;
7298 
7299     TYPE l_outfile_inel_rec IS RECORD (ID         NUMBER,
7300                                   String1    Varchar2(4000),
7301                                   String2    Varchar2(4000),
7302                                   String3    Varchar2(4000)
7303                                   );
7304     TYPE l_outfile_inel_tbl IS TABLE OF l_outfile_inel_rec INDEX BY BINARY_INTEGER;
7305 
7306     l_outfiles_inel l_outfile_inel_tbl;
7307     l_outfile_inel_id             NUMBER  ;
7308     l_inel_count                  NUMBER  ;
7309     l_total_rec_count             NUMBER  ;
7310 
7311  -----------------------------------
7312  -- Local Procedure and Functions --
7313  -----------------------------------
7314 
7315    PROCEDURE Get_contract_lines(p_chr_id IN Number,
7316                                 p_attr   IN Varchar2,
7317                                 p_old_value IN Varchar2,
7318                                 p_new_value IN Varchar2,
7319                                 x_return_status OUT NOCOPY Varchar2,
7320                                 x_clev_tbl  OUT NOCOPY okc_contract_pub.clev_tbl_type)
7321    AS
7322 	   TYPE t_cont_lines IS REF CURSOR;
7323 
7324 	   v_CurContLine            t_cont_lines;
7325         l_cle_id                 Number;
7326         l_lse_id                 Number;
7327         l_object_version_number  Number;
7328 	   l_stmt                   Varchar2(10000);
7329         i                        NUMBER  ;
7330    BEGIN
7331 
7332           i := 1;
7333           x_return_status := G_RET_STS_SUCCESS;
7334 
7335 	  /*
7336 	  ** Modified the sql by adding date_cancelled condition
7337 	  ** to take care of Line Level Cancelation project
7338 	  */
7339 
7340           l_stmt:= 'SELECT cle.id,object_version_number,lse_id FROM  okc_k_lines_v cle
7341                     WHERE  cle.date_cancelled is NULL
7342 		      AND  cle.dnz_chr_id = :p_chr_id';
7343 
7344         IF p_attr = 'CONTRACT_START_DATE' then
7345 
7346            IF to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') <
7347                    to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') then
7348              l_stmt:= l_stmt||'  AND trunc(cle.start_date) < trunc(to_date(:p_new_value,''YYYY/MM/DD HH24:MI:SS''))';
7349            ELSIF to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') >
7350                   to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') then
7351              l_stmt:= l_stmt||'  AND trunc(cle.start_date) = trunc(to_date(:p_old_value,''YYYY/MM/DD HH24:MI:SS''))';
7352            END IF;
7353 -- Added Order by clause to fix Bug#3522891.
7354 -- Parent line should be processed before the child line
7355              l_stmt := l_stmt||' Order by cle.lse_id' ;
7356 
7357         ELSIF p_attr = 'CONTRACT_END_DATE' then
7358            IF to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') >
7359                   to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') then
7360              l_stmt:= l_stmt||'  AND trunc(cle.end_date) > trunc(to_date(:p_new_value,''YYYY/MM/DD HH24:MI:SS''))';
7361            ELSIF to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') <
7362                  to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') then
7363              l_stmt:= l_stmt||'  AND trunc(cle.end_date) = trunc(to_date(:p_old_value,''YYYY/MM/DD HH24:MI:SS''))';
7364            END IF;
7365 -- Added Order by clause to fix Bug#3522891.
7366 -- Parent line should be processed before the child line
7367              l_stmt := l_stmt||' Order by cle.lse_id' ;
7368 
7369         ELSIF p_attr = 'CONTRACT_LINE_REF' then
7370            -- IF p_old_value is NULL then
7371             IF p_old_value ='-9999' then
7372             l_stmt := l_stmt||' AND cle.cognomen is NULL
7373                                 AND cle.lse_id in (1,12,14,19)';
7374             ELSIF p_old_value ='-1111' then
7375             l_stmt := l_stmt||' AND cle.lse_id in (1,12,14,19)';
7376             ELSE
7377             l_stmt := l_stmt||' AND cle.cognomen = :p_old_value
7378                                 AND cle.lse_id  in (1,12,14,19)';
7379             END IF;
7380         ELSIF p_attr = 'PRODUCT_ALIAS' then
7381              -- IF p_old_value is NULL then
7382             IF p_old_value ='-9999' then
7383             l_stmt := l_stmt||' AND cle.cognomen is NULL
7384                                 AND cle.lse_id in (9,18,25)';
7385             ELSIF p_old_value = '-1111' then
7386             l_stmt := l_stmt||' AND cle.lse_id in (9,18,25)';
7387             ELSE
7388             l_stmt := l_stmt||' AND cle.cognomen = :p_old_value
7389                                 AND cle.lse_id in (9,18,25)';
7390             END IF;
7391         END IF;
7392         		    i := 0;
7393                  LOG_MESSAGES('l_stmt: '||l_stmt);
7394 
7395               If p_attr in ('CONTRACT_LINE_REF', 'PRODUCT_ALIAS') Then
7396                 /* Fixed byug 5247361 */
7397                  If p_old_value in ('-1111','-9999') Then
7398                       OPEN v_CurContLine FOR l_stmt using p_chr_id;
7399                   Else
7400 
7401                       OPEN v_CurContLine FOR l_stmt using p_chr_id,p_old_value;
7402                   End If;
7403 	        Elsif p_attr = ('CONTRACT_END_DATE') Then
7404                        If to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') >
7405                        to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') Then
7406                            OPEN v_CurContLine FOR l_stmt using p_chr_id,p_new_value;
7407                        ElsIF to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') <
7408                        to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') then
7409                            OPEN v_CurContLine FOR l_stmt using p_chr_id,p_old_value;
7410                        End If;
7411 
7412               ElsIf p_attr = ('CONTRACT_START_DATE') Then
7413                        If to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') >
7414                        to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') Then
7415                            OPEN v_CurContLine FOR l_stmt using p_chr_id,p_old_value;
7416                       ElsIF to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') <
7417                       to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') then
7418                            OPEN v_CurContLine FOR l_stmt using p_chr_id,p_new_value;
7419                       End If;
7420 
7421                 End If;
7422 	           	LOOP
7423         		    i := i +1;
7424                             l_cle_id := NULL;
7425 		            FETCH v_CurContLine INTO l_cle_id, l_object_version_number, l_lse_id;
7426                       IF l_cle_id is NOT NULL THEN
7427 	       		    x_clev_tbl(i).ID                    := l_cle_id;
7428 	       		    x_clev_tbl(i).object_version_number := l_object_version_number;
7429 	       		    x_clev_tbl(i).lse_id                := l_lse_id;
7430 
7431                       END IF;
7432         		  EXIT WHEN v_CurContLine%NOTFOUND;
7433                           LOG_MESSAGES('x_clev_tbl(i).ID:'||x_clev_tbl(i).ID);
7434                 END LOOP;
7435                 CLOSE v_CurContLine;
7436 
7437                 LOG_MESSAGES('Get_contract_lines return_status:'||x_return_status);
7438         EXCEPTION WHEN OTHERS
7439         then
7440            x_return_status := G_RET_STS_UNEXP_ERROR;
7441            LOG_MESSAGES('ERROR In Get_contract_lines for chr_id '||p_chr_id||' : '||SQLERRM);
7442                  LOG_MESSAGES('l_stmt: '||l_stmt);
7443 
7444   END Get_contract_lines;
7445 
7446 
7447 -- Added Vigandhi
7448 -- Fix bug 5075961
7449 -- To get the oks top lines and covered lines to update the invoice text
7450 
7451    PROCEDURE Get_oks_contract_lines(
7452                                 p_chr_id IN Number,
7453                                 p_attr   IN Varchar2,
7454                                 p_old_value IN Varchar2,
7455                                 p_new_value IN Varchar2,
7456                                 x_return_status OUT NOCOPY Varchar2,
7457                                 x_clev_tbl  OUT NOCOPY oks_contract_line_pub.klnv_tbl_type)
7458    AS
7459 	   TYPE t_cont_lines IS REF CURSOR;
7460 
7461 	   v_CurContLine            t_cont_lines;
7462         l_cle_id                 Number;
7463         l_object_version_number  Number;
7464 	   l_stmt                   Varchar2(10000);
7465         i                        NUMBER  ;
7466         l_invoice_text          VARCHAR2(2000);
7467 	l_old_value             varchar2(15);
7468 
7469    BEGIN
7470 
7471           i := 1;
7472           x_return_status := G_RET_STS_SUCCESS;
7473 
7474           l_stmt:= 'SELECT ksl.id,ksl.object_version_number,ksl.invoice_text
7475                     FROM   oks_k_lines_v ksl, okc_k_lines_b kcl
7476                     WHERE  kcl.date_cancelled is NULL
7477                     AND    kcl.dnz_chr_id = :p_chr_id
7478                     AND    kcl.id = ksl.cle_id
7479                     AND    kcl.lse_id IN (7,8,9,10,11,18,25,35,1,12,14,19)';
7480 
7481         IF p_attr = 'CONTRACT_START_DATE' then
7482 
7483            IF to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') <
7484                    to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') then
7485              l_stmt:= l_stmt||'  AND trunc(kcl.start_date) < trunc(to_date(:p_new_value,''YYYY/MM/DD HH24:MI:SS''))';
7486            ELSIF to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') >
7487                   to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') then
7488              l_stmt:= l_stmt||'  AND trunc(kcl.start_date) = trunc(to_date(:p_old_value,''YYYY/MM/DD HH24:MI:SS''))';
7489            END IF;
7490              l_stmt := l_stmt||' Order by kcl.lse_id' ;
7491 
7492         ELSIF p_attr = 'CONTRACT_END_DATE' then
7493            IF to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') >
7494                   to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') then
7495              l_stmt:= l_stmt||'  AND trunc(kcl.end_date) > trunc(to_date(:p_new_value,''YYYY/MM/DD HH24:MI:SS''))';
7496            ELSIF to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') <
7497                  to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') then
7498              l_stmt:= l_stmt||'  AND trunc(kcl.end_date) = trunc(to_date(:p_old_value,''YYYY/MM/DD HH24:MI:SS''))';
7499            END IF;
7500              l_stmt := l_stmt||' Order by kcl.lse_id' ;
7501 
7502         END IF;
7503         		    i := 0;
7504                  LOG_MESSAGES('l_stmt: '||l_stmt);
7505 
7506               If p_attr = ('CONTRACT_END_DATE') Then
7507                        If to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') >
7508                        to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') Then
7509                            OPEN v_CurContLine FOR l_stmt using p_chr_id,p_new_value;
7510                        ElsIF to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') <
7511                        to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') then
7512                            OPEN v_CurContLine FOR l_stmt using p_chr_id,p_old_value;
7513                        End If;
7514 
7515               ElsIf p_attr = ('CONTRACT_START_DATE') Then
7516                       If to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') >
7517                        to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') Then
7518                            OPEN v_CurContLine FOR l_stmt using p_chr_id,p_old_value;
7519                       ElsIF to_date(p_old_value,'YYYY/MM/DD HH24:MI:SS') <
7520                       to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS') then
7521                            OPEN v_CurContLine FOR l_stmt using p_chr_id,p_new_value;
7522                       End If;
7523 
7524                End If;
7525 	           	LOOP
7526                             i := i +1;
7527                             l_cle_id := NULL;
7528 		            FETCH v_CurContLine INTO l_cle_id,
7529                                              l_object_version_number,
7530                                              l_invoice_text;
7531                       IF l_cle_id is NOT NULL THEN
7532         	       		    x_clev_tbl(i).ID                    := l_cle_id;
7533 	            		    x_clev_tbl(i).object_version_number := l_object_version_number;
7534 
7535                         	    IF p_attr = 'CONTRACT_START_DATE'
7536                         	    THEN
7537                         	    l_old_value := SUBSTR (l_invoice_text,-23,11);
7538                         	    ELSE
7539                         	    l_old_value := SUBSTR (l_invoice_text, -11,11);
7540                         	    END IF;
7541 
7542         	        	    x_clev_tbl(i).invoice_text := REPLACE (l_invoice_text,
7543 				    l_old_value,
7544 				    to_char(trunc(to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS')), 'DD-MON-YYYY')	);
7545 
7546 				    LOG_MESSAGES('l_old_value         : '|| l_old_value);
7547 				    LOG_MESSAGES('p_new_value         : '|| to_char(trunc(to_date(p_new_value,'YYYY/MM/DD HH24:MI:SS')), 'DD-MON-YYYY'));
7548 				    LOG_MESSAGES('Invoice Text before : '|| l_invoice_text);
7549 				    LOG_MESSAGES('Invoice Text after  : '||x_clev_tbl(i).invoice_text);
7550 
7551                       END IF;
7552         		  EXIT WHEN v_CurContLine%NOTFOUND;
7553                           LOG_MESSAGES('x_clev_tbl(i).ID:'||x_clev_tbl(i).ID);
7554                 END LOOP;
7555                 CLOSE v_CurContLine;
7556 
7557                 LOG_MESSAGES('Get_contract_lines return_status:'||x_return_status);
7558         EXCEPTION WHEN OTHERS
7559         then
7560            x_return_status := G_RET_STS_UNEXP_ERROR;
7561            LOG_MESSAGES('ERROR In Get_oks_contract_lines for chr_id '||p_chr_id||' : '||SQLERRM);
7562                  LOG_MESSAGES('l_stmt: '||l_stmt);
7563 
7564   END Get_oks_contract_lines;
7565 
7566 -- Fix bug 5075961
7567 
7568 
7569    -- Procedure to seperate the org_id and sales person ID/ Revenue Accoutn ID
7570    -- from the concatenated string with a delimiter '#'
7571 
7572    PROCEDURE parse_org_id ( p_old_value 	IN Varchar2
7573 	       		  ,x_old_value 	OUT NOCOPY Varchar2
7574 	       		  ,x_org_id	OUT NOCOPY Number) IS
7575 	 l_old_value         Varchar2(240);
7576 	 l_org_id	    Number;
7577    BEGIN
7578         	If p_old_value is Not Null then
7579 	 	If instr(p_old_value,'#') > 0 Then
7580               	    l_old_value	 := substr(p_old_value,1,instr(p_old_value,'#')-1) ;
7581               	    l_org_id 	 := substr(p_old_value,instr(p_old_value,'#')+1,length(p_old_value));
7582               	Else
7583               	    l_old_value  := p_old_value;
7584               	    l_org_id     := Null;
7585               	End If;
7586 
7587               	x_old_value      := l_old_value ;
7588               	x_org_id	 := l_org_id;
7589 	       End If;
7590    END parse_org_id;
7591 
7592   FUNCTION Get_lookup_value(p_lookup_code IN Varchar2)
7593   RETURN Varchar2 IS
7594     CURSOR Cur_lookup IS
7595            SELECT meaning FROM fnd_lookups
7596            WHERE lookup_type like 'OKS_MSCHG_LEVEL%'
7597            AND   lookup_code = p_lookup_code
7598            AND   rownum =1;
7599     l_meaning   Varchar2(100);
7600   BEGIN
7601         OPEN  Cur_lookup;
7602         FETCH Cur_lookup INTO l_meaning;
7603         CLOSE Cur_lookup;
7604 
7605         RETURN l_meaning;
7606 
7607   END Get_lookup_value;
7608 
7609 
7610   FUNCTION Get_contract_amount(p_chr_id IN Number)
7611   RETURN Number IS
7612   l_cont_amt  Number;
7613   CURSOR Get_amt IS
7614          SELECT estimated_amount FROM okc_k_headers_v WHERE id = p_chr_id;
7615   BEGIN
7616        OPEN  Get_amt;
7617        FETCH Get_amt INTO l_cont_amt;
7618        CLOSE Get_amt;
7619        RETURN l_cont_amt;
7620   EXCEPTION WHEN OTHERS THEN
7621       LOG_MESSAGES('ERROR in Get_contract_amount:'||SQLERRM);
7622       RAISE G_EXCEPTION_HALT_VALIDATION;
7623   END Get_contract_amount;
7624 
7625   FUNCTION Get_ste_code(p_sts_code IN Varchar2)
7626   RETURN Varchar2 IS
7627   l_ste_code  Varchar2(50):= NULL;
7628   CURSOR Get_ste_code(sts_code IN Varchar2) IS
7629          SELECT ste_code FROM okc_statuses_v WHERE code = sts_code;
7630   BEGIN
7631        OPEN  Get_ste_code(p_sts_code);
7632        FETCH Get_ste_code INTO l_ste_code;
7633        CLOSE Get_ste_code;
7634        RETURN l_ste_code;
7635   EXCEPTION WHEN OTHERS THEN
7636       LOG_MESSAGES('ERROR in Get_ste_code:'||SQLERRM);
7637       RAISE G_EXCEPTION_HALT_VALIDATION;
7638   END Get_ste_code;
7639 
7640 -- This fuctions pads the text with a pading character specified as in parameter
7641 -- Used for generating the mass change report
7642   Function Pad(
7643      p_text    in varchar2
7644     ,p_width   in number
7645     ,p_side    in varchar2 default 'R'
7646     ,p_char    in char default ' ')
7647                          return varchar2 is
7648     l_text varchar2(2000);
7649   BEGIN
7650     l_text := p_text;
7651     IF p_side = 'L' THEN
7652       for i in 1..p_width loop
7653          l_text := ' '||l_text;
7654       End Loop;
7655       return(l_text);
7656     ELSIF p_side = 'R' THEN
7657       return(rpad(l_text, p_width,p_char));
7658     END IF;
7659   END Pad;
7660 
7661   -- Function to check the Contract is a Warranty or not
7662   FUNCTION Check_warranty(p_chr_id IN Number)
7663   RETURN Varchar2 IS
7664     CURSOR Warranty_lookup IS
7665            SELECT id FROM okc_k_headers_b okh
7666            WHERE
7667            Exists (select 'x' from OKC_K_LINES_B cle
7668                  where cle.dnz_chr_id = okh.id
7669                    and cle.lse_id = 14 )
7670            AND okh.id = p_chr_id ;
7671     l_chr_id    Number;
7672     l_warranty_yn  Varchar2(1);
7673   BEGIN
7674         OPEN  Warranty_lookup;
7675         FETCH Warranty_lookup INTO l_chr_id;
7676         If Warranty_lookup%found then
7677            l_warranty_yn := 'Y';
7678         Else
7679            l_warranty_yn := 'N';
7680         End If;
7681         CLOSE Warranty_lookup;
7682 
7683         RETURN l_warranty_yn;
7684 
7685 
7686       EXCEPTION WHEN OTHERS THEN
7687       LOG_MESSAGES('ERROR in Check_warranty:'||SQLERRM);
7688       RAISE G_EXCEPTION_HALT_VALIDATION;
7689   End Check_warranty ;
7690 
7691   -- Function to get the default status code for a status type
7692 
7693   FUNCTION Get_Status_Code(p_ste_code IN Varchar2)
7694   RETURN Varchar2 IS
7695      Cursor get_sts_code (p_ste_code in Varchar2) IS
7696      Select code
7697       From  OKC_STATUSES_B
7698       Where ste_code = p_ste_code
7699         And default_yn = 'Y';
7700 
7701      l_sts_code OKC_STATUSES_B.CODE%type;
7702 
7703   Begin
7704      Open get_sts_code(p_ste_code );
7705      Fetch get_sts_code into l_sts_code;
7706      Close get_sts_code;
7707 
7708      Return l_sts_code;
7709 
7710       EXCEPTION WHEN OTHERS THEN
7711       LOG_MESSAGES('ERROR in getting default status code (PgmUnit:- Get_Status_Code): '||SQLERRM);
7712       RAISE G_EXCEPTION_HALT_VALIDATION;
7713   End Get_Status_Code;
7714 
7715   -- The following function finds the new status for the contract atfer the effectivity date change.
7716   -- Pass the new value to p_start_date when the start_date for the contract is changed.
7717   -- Pass the new value to p_end_date when the end_date for the contract is changed.
7718 
7719   FUNCTION Find_Contract_Status(p_start_date     IN Date  -- pass new start date
7720                                ,p_end_date       IN Date  -- pass new end date
7721                                ,p_sts_code       IN Varchar2)
7722   RETURN Varchar2 IS
7723       l_status_code  Varchar2(40);
7724   BEGIN
7725       If trunc(sysdate) < trunc(p_start_date) Then
7726           l_status_code := get_status_code('SIGNED') ;
7727       Elsif trunc(sysdate) > trunc(p_end_date) Then
7728           l_status_code := get_status_code('EXPIRED') ;
7729       Elsif trunc(sysdate) >= trunc(p_start_date) and trunc(sysdate) <= trunc(p_end_date) Then
7730           l_status_code := get_status_code('ACTIVE') ;
7731       Else
7732           l_status_code := p_sts_code;
7733       End If;
7734 
7735       Return l_status_code;
7736 
7737       Exception When Others Then
7738            LOG_MESSAGES('ERROR in Find_Contract_Status:'||SQLERRM);
7739            Raise G_EXCEPTION_HALT_VALIDATION;
7740   END Find_Contract_Status;
7741 
7742  ------------------------------
7743  -- Submit procedure starts  --
7744  ------------------------------
7745  BEGIN
7746       x_return_status  := G_RET_STS_SUCCESS;
7747       l_conc_program   := 'Y';
7748       l_message        := NULL;
7749 
7750       l_status               := 'SUCCESS';
7751       l_opn_status           := 'PROCESSED';
7752       l_init_msg_list	     := 'T';
7753       l_restricted_update    := 'F' ;
7754       l_message              := 'Successfully completed';
7755 
7756       l_count_pm_schedule    := 0 ;
7757 
7758       l_cov_time_wrong       := 0 ;
7759       l_cov_time_right       := 0 ;
7760       cvr_cnt                := 0 ;
7761       srv_cnt                := 0 ;
7762       rcn_cnt                := 0 ;
7763       cnt                    := 0 ;
7764 
7765       l_success_cnt          := 0 ;
7766       l_error_cnt            := 0 ;
7767       l_outfile_success_id   := 0 ;
7768       l_succ_count           := 0 ;
7769 
7770       l_outfile_fail_id      := 0 ;
7771       l_fail_count           := 0 ;
7772 
7773       l_outfile_inel_id      := 0 ;
7774       l_inel_count           := 0 ;
7775       l_total_rec_count      := 0 ;
7776 
7777       l_billed_at_source_msg := '';
7778 
7779 
7780 
7781 
7782       LOG_MESSAGES('starts processing ....');
7783 
7784       DBMS_TRANSACTION.SAVEPOINT('BEFORE_MASSCHANGE_START');
7785 
7786       LOG_MESSAGES('Before get_criteria_cur');
7787 
7788 	OPEN  get_criteria_cur;
7789 	FETCH get_criteria_cur INTO
7790 	     l_masschange_name
7791 	     ,l_update_level_code
7792 	     ,l_update_level_value_id
7793 	     ,l_attribute_code
7794 	     ,l_old_value_id_tmp
7795 	     ,l_new_value_id;
7796 	CLOSE get_criteria_cur;
7797 
7798 	-- Call the procedure to parse the ORG_ID
7799 	If l_attribute_code in ('SALES_REP','REV_ACCT') then
7800 	   Parse_Org_Id(p_old_value	=> l_old_value_id_tmp
7801 			,x_old_value	=> l_old_value_id
7802 			,x_org_id	=> l_org_id );
7803 
7804 	Else
7805 	    l_old_value_id    := l_old_value_id_tmp;
7806 	End If;
7807 
7808 	LOG_MESSAGES('After get_criteria_cur');
7809 
7810 	l_criteria_rec.oie_id             := p_oie_id;
7811 	l_criteria_rec.update_level       := l_update_level_code;
7812 	l_criteria_rec.update_level_value := l_update_level_value_id;
7813 	l_criteria_rec.attribute          := l_attribute_code;
7814 	l_criteria_rec.old_value          := l_old_value_id;
7815 	l_criteria_rec.ORG_ID             := l_org_id;
7816 	l_criteria_rec.new_value           := l_new_value_id;
7817 
7818         l_update_level := Get_lookup_value(p_lookup_code => l_update_level_code);
7819 
7820         l_update_level_value := OKC_UTIL.GET_NAME_FROM_JTFV(p_object_code =>l_update_level_code,
7821                                                             p_id1 => l_update_level_value_id,
7822                                                             p_id2 => '#');
7823 
7824         get_attribute_value(p_attr_code  => l_attribute_code,
7825                             p_attr_id    => l_old_value_id,
7826                             p_org_id     => l_org_id,
7827                             x_attr_value => l_old_value,
7828                             x_attr_name  => l_attribute);
7829 
7830         -- LOG_MESSAGES('l_old_value:'||l_old_value);
7831 
7832         get_attribute_value(p_attr_code  => l_attribute_code,
7833                             p_attr_id    => l_new_value_id,
7834                             p_org_id     => l_org_id,
7835                             x_attr_value => l_new_value,
7836                             x_attr_name  => l_attribute);
7837 
7838 	LOG_MESSAGES('Oie_id                           :'||l_criteria_rec.oie_id);
7839 	LOG_MESSAGES('Update_level (Stored Code)       :'||l_criteria_rec.update_level);
7840         LOG_MESSAGES('Update_level_value (Stored Code) :'||l_criteria_rec.update_level_value);
7841         LOG_MESSAGES('Attribute (Stored Code)          :'||l_criteria_rec.attribute);
7842         LOG_MESSAGES('Old Vlaue (Stored Code)          :'||l_criteria_rec.old_value);
7843 
7844         LOG_MESSAGES('MASS CHANGE '||p_process_type||' Starts');
7845         LOG_MESSAGES('Mass change Name   :  '||l_masschange_name);
7846         LOG_MESSAGES('Update Level       :  '||l_update_level);
7847         LOG_MESSAGES('Update Level value :  '||l_update_level_value);
7848         LOG_MESSAGES('Attribute          :  '||l_attribute);
7849         LOG_MESSAGES('Old value          :  '||l_old_value);
7850         LOG_MESSAGES('New value          :  '||l_new_value);
7851 
7852         -- The following code for report is moved towards the end of the procedure.
7853         -- Reason: Report printing code was scattered. Mar 2004
7854 
7855         --  fnd_file.put_line(FND_FILE.OUTPUT, '          MASS CHANGE '||p_process_type||' REPORT');
7856         --  fnd_file.put_line(FND_FILE.OUTPUT, '          **************************');
7857         --  fnd_file.new_line(FND_FILE.OUTPUT, 2);
7858         --  fnd_file.put_line(FND_FILE.OUTPUT, 'Mass change Name               :  '||l_masschange_name);
7859         --  fnd_file.new_line(FND_FILE.OUTPUT, 1);
7860         --  fnd_file.put_line(FND_FILE.OUTPUT, 'Mass change Scope              ');
7861         --  fnd_file.put_line(FND_FILE.OUTPUT, '            Update Level       :  '||l_update_level);
7862         --  fnd_file.put_line(FND_FILE.OUTPUT, '            Update Level value :  '||l_update_level_value);
7863         --  fnd_file.new_line(FND_FILE.OUTPUT, 1);
7864         --  fnd_file.put_line(FND_FILE.OUTPUT, 'Mass change Criteria           ');
7865         --  fnd_file.put_line(FND_FILE.OUTPUT, '            Attribute          :  '||l_attribute);
7866         --  fnd_file.put_line(FND_FILE.OUTPUT, '            Old value          :  '||l_old_value);
7867         --  fnd_file.put_line(FND_FILE.OUTPUT, '            New value          :  '||l_new_value);
7868         --  fnd_file.put_line(FND_FILE.OUTPUT, '*********************************************************************************************************************');
7869         --  fnd_file.new_line(FND_FILE.OUTPUT, 1);
7870         -- fnd_file.put_line(FND_FILE.OUTPUT, 'List of Contracts for Mass Change:');
7871         -- fnd_file.put_line(FND_FILE.OUTPUT, '----------------------------------------------------------------------------------------------------------------------');
7872         -- fnd_file.put_line(FND_FILE.OUTPUT, 'Contract Number      Modifier    Description                 Old Value            Process Status      Remark');
7873         -- fnd_file.put_line(FND_FILE.OUTPUT, '----------------------------------------------------------------------------------------------------------------------');
7874 
7875         LOG_MESSAGES('Fetching list of eligible contracts ...');
7876 
7877    OKS_MASSCHANGE_PVT.get_eligible_contracts
7878 		 (p_api_version         => l_api_version
7879 		 ,p_init_msg_list       => l_init_msg_list
7880 		 ,p_ctr_rec             => l_criteria_rec
7881                  ,p_query_type          => 'PROCESS'
7882                  ,p_upg_orig_system_ref => 'N'
7883 		 ,x_return_status       => l_return_status
7884 		 ,x_msg_count           => l_msg_count
7885 		 ,x_msg_data            => l_msg_data
7886 		 ,x_eligible_contracts  => l_eligible_contracts_tbl);
7887 
7888       LOG_MESSAGES('Updating all selected (A,E) operation lines STATUS to NULL   ...'||l_eligible_contracts_tbl.COUNT);
7889 
7890       UPDATE_LINE_STATUS(p_oie_id    => l_criteria_rec.oie_id);
7891 
7892       fnd_file.new_line(FND_FILE.OUTPUT, 1);
7893 
7894   FOR i IN 1 .. l_eligible_contracts_tbl.COUNT
7895   LOOP
7896   BEGIN
7897 
7898     /* added by mkarra as part of Implementing Service Contracts Imports -
7899          This checks if the contract is imported and fully billed at source and if "Yes" it
7900           appends a text in the remarks as " Billing program would not process this fully billed contract"
7901     */
7902     LOG_MESSAGES('Checking billed_at_source for eligible contracts ...'|| l_eligible_contracts_tbl(i).billed_at_source);
7903     if (l_eligible_contracts_tbl(i).billed_at_source is not null and l_eligible_contracts_tbl(i).billed_at_source ='Y') then
7904 	l_billed_at_source_msg := l_billed_at_source_msg || fnd_message.get_string('OKS','OKS_HEADER_CASCADE_DATES_WARN') || ';' ;
7905     else
7906       l_billed_at_source_msg := '';
7907     end if;
7908 
7909   --IF l_eligible_contracts_tbl(i).old_value1=1 then
7910 
7911        FND_MSG_PUB.Initialize;
7912        l_status    := 'SUCCESS';
7913        l_message   := null; --'Successfully completed';
7914        DBMS_TRANSACTION.SAVEPOINT('BEFORE_MASSCHANGE');
7915 
7916         --UPDATE_LINE_STATUS(p_ole_id              => l_eligible_contracts_tbl(i).ole_id);
7917         --Update the attribute
7918         LOG_MESSAGES('Processing Contract contract number :'||l_eligible_contracts_tbl(i).contract_number);
7919         LOG_MESSAGES('Old Value:'||l_eligible_contracts_tbl(i).old_value);
7920 
7921         -- This procedure has been stub out. Hence commenting out the call and validation.
7922         --  OKS_RENEW_UTIL_PUB.Can_Update_Contract(
7923         --                              p_api_version     => l_api_version ,
7924         --                              p_init_msg_list   => l_init_msg_list,
7925         --                              p_chr_id          => l_eligible_contracts_tbl(i).contract_id,
7926         --                              x_can_update_yn   => l_can_update_yn,
7927         --                              x_can_submit_yn   => l_can_submit_yn,
7928         --                              x_msg_count       => l_msg_count,
7929         --                              x_msg_data        => l_msg_data,
7930         --                              x_return_status   => l_return_status ) ;
7931         -- LOG_MESSAGES('Can_Update_Contract :'||l_return_status);
7932         --    IF l_can_update_yn = 'N' then
7933         --       l_status    := 'ERROR';
7934         --       l_message := FND_MESSAGE.get_string('OKS','OKS_MSCHG_UND_REN');
7935         --       l_message := 'Can not update. The contract is under electronic renewal process.';
7936         --       RAISE G_EXCEPTION_HALT_VALIDATION;
7937         --    END IF;
7938 
7939         -- Modified the following since "ALL" cause translation issues.
7940         -- 10-MAR-04
7941         --   IF l_old_value = 'ALL' then
7942         IF l_old_value_id = '-1111' then
7943              get_attribute_value(p_attr_code  => l_attribute_code,
7944                                  p_attr_id    => l_eligible_contracts_tbl(i).old_value,
7945                                  p_org_id     => l_org_id ,
7946                                  x_attr_value => l_old_value,
7947                                  x_attr_name  => l_attribute);
7948         END IF;
7949 
7950       -- Check if the contract is a Warranty .
7951       --  Enable start date and end date to be modified. Also update the Status for these
7952       --  contracts
7953 
7954      l_warranty_flag := Check_warranty(l_eligible_contracts_tbl(i).contract_id);
7955      LOG_MESSAGES('Check warranty flag '||l_warranty_flag);
7956      If l_warranty_flag = 'Y' then
7957         If l_criteria_rec.attribute not in ('CONTRACT_START_DATE','CONTRACT_END_DATE') then
7958 
7959             l_message  := FND_MESSAGE.get_string('OKS','OKS_MSCHG_WARR_CON') ;
7960             -- l_message  := 'Warranty Contract. You can only update Start Date and End Date' ;
7961             RAISE  l_notelligible_exception ;
7962         Else
7963             If l_criteria_rec.attribute = 'CONTRACT_START_DATE' then
7964 
7965                l_chrv_tbl_in.DELETE;
7966 
7967                -- Check Start Date > End Date
7968                If trunc(l_eligible_contracts_tbl(i).end_date) <
7969                            trunc(to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS')) then
7970                   l_message := FND_MESSAGE.get_string('OKS','OKS_MSCHG_WRONG_DT') ;
7971 --                  l_message := 'Contract End Date less than new Start Date' ;
7972                   RAISE  l_notelligible_exception ;
7973                End If;
7974 
7975                -- find the new status for the contract
7976 
7977                l_sts_code := Find_Contract_Status(
7978                                        p_start_date => to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS')
7979                                        ,p_end_date  => l_eligible_contracts_tbl(i).end_date
7980                                        ,p_sts_code  => l_eligible_contracts_tbl(i).CONTRACT_STATUS);
7981 
7982                LOG_MESSAGES('New status for the contract '||l_sts_code);
7983 
7984                l_chrv_tbl_in(1).id		         := l_eligible_contracts_tbl(i).contract_id;
7985                l_chrv_tbl_in(1).object_version_number    := l_eligible_contracts_tbl(i).object_version_number;
7986 
7987                OKC_CONTRACT_PUB.lock_contract_header (
7988                         	p_api_version		=> l_api_version,
7989                           	p_init_msg_list		=> l_init_msg_list,
7990                         	x_return_status		=> l_return_status,
7991                         	x_msg_count             => l_msg_count,
7992                          	x_msg_data              => l_msg_data,
7993                            	p_chrv_tbl              => l_chrv_tbl_in);
7994 
7995                IF l_return_status = G_RET_STS_SUCCESS THEN
7996 
7997                   LOG_MESSAGES('Fetching contract lines for update');
7998                   l_clev_tbl_in.DELETE;
7999                   Get_contract_lines(p_chr_id          => l_eligible_contracts_tbl(i).contract_id,
8000                                       p_attr           => l_criteria_rec.attribute,
8001                                       p_old_value      => l_old_value,
8002                                       p_new_value      => l_new_value,
8003                                       x_return_status  => l_return_status,
8004                                       x_clev_tbl       => l_clev_tbl_in);
8005 
8006                   IF l_return_status = G_RET_STS_SUCCESS THEN
8007 
8008 
8009                        LOG_MESSAGES('Locking contract lines for update, lines count:'||l_clev_tbl_in.COUNT);
8010                        OKC_CONTRACT_PUB.lock_contract_line(
8011                             	                  p_api_version	    => l_api_version,
8012                               	                  p_init_msg_list   => l_init_msg_list,
8013                             	                  x_return_status   => l_return_status,
8014                             	                  x_msg_count       => l_msg_count,
8015                              	                  x_msg_data        => l_msg_data,
8016                                                   p_clev_tbl        => l_clev_tbl_in);
8017 
8018                       LOG_MESSAGES('lock status:'||l_return_status);
8019                       IF l_return_status = G_RET_STS_SUCCESS THEN -- lines locked
8020 
8021                       --- vigandhi added
8022 		      -- Bug Fix 5075961
8023 
8024                       l_klnv_tbl_type_in.DELETE;
8025                       Get_oks_contract_lines(p_chr_id      => l_eligible_contracts_tbl(i).contract_id,
8026                                       p_attr           => l_criteria_rec.attribute,
8027                                       p_old_value      => l_old_value,
8028                                       p_new_value      => l_new_value,
8029                                       x_return_status  => l_return_status,
8030                                       x_clev_tbl       => l_klnv_tbl_type_in);
8031 
8032 		     IF l_return_status = G_RET_STS_SUCCESS THEN
8033 
8034 		       LOG_MESSAGES('Locking oks contract lines for update, lines count:'||l_klnv_tbl_type_in.COUNT);
8035                                     OKS_CONTRACT_LINE_PUB.lock_line(
8036                                         p_api_version         => l_api_version,
8037                                         p_init_msg_list       => l_init_msg_list,
8038                                         x_return_status       => l_return_status,
8039                                         x_msg_count           => l_msg_count,
8040                                         x_msg_data            => l_msg_data,
8041                                         p_klnv_tbl            => l_klnv_tbl_type_in);
8042 
8043 
8044                     IF l_return_status = G_RET_STS_SUCCESS THEN
8045                     -- Bug fix 5075961
8046 
8047                           l_chrv_rec_in.id          := l_eligible_contracts_tbl(i).contract_id;
8048                           l_chrv_rec_in.start_date  := to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS');
8049                           l_chrv_rec_in.sts_code    := l_sts_code;
8050 
8051                           LOG_MESSAGES('updating contract header with new value:'||l_new_value);
8052                           OKC_CONTRACT_PUB.update_contract_header (
8053                         	       p_api_version		=> l_api_version,
8054                           	       p_init_msg_list		=> l_init_msg_list,
8055                         	       x_return_status		=> l_return_status,
8056                         	       x_msg_count     	        => l_msg_count,
8057                          	       x_msg_data               => l_msg_data,
8058                         	       p_chrv_rec               => l_chrv_rec_in,
8059     	                               x_chrv_rec               => l_chrv_rec_out );
8060 
8061                            IF l_return_status = G_RET_STS_SUCCESS THEN -- contract update
8062                                LOG_MESSAGES('CONTRACT_HEADER(Start_Date) update status: '||l_return_status);
8063                                IF l_clev_tbl_in.COUNT > 0 THEN
8064                                     FOR j in 1 .. l_clev_tbl_in.COUNT
8065                                     LOOP
8066                                         l_clev_tbl_in(j).start_date := to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS');
8067                                         l_clev_tbl_in(j).sts_code   := l_sts_code;
8068                                     END LOOP;
8069                                     LOG_MESSAGES('updating contract lines with new value:'||l_new_value);
8070                                     OKC_CONTRACT_PUB.update_contract_line(
8071                             	                  p_api_version	    => l_api_version,
8072                               	                  p_init_msg_list   => l_init_msg_list,
8073                             	                  x_return_status   => l_return_status,
8074                             	                  x_msg_count	    => l_msg_count,
8075                              	                  x_msg_data	    => l_msg_data,
8076                                                   p_clev_tbl        => l_clev_tbl_in,
8077                                                   x_clev_tbl        => l_clev_tbl_out);
8078                                 END IF; -- line_table.COUNT > 0
8079 
8080                                 IF l_return_status = G_RET_STS_SUCCESS THEN
8081                                     LOG_MESSAGES('CONTRACT_HEADER_LINES(Start_Date) update status: '||l_return_status);
8082 
8083                                     -- Vigandhi
8084 				    -- Bug Fix 5075961
8085 
8086                                     IF l_klnv_tbl_type_in.COUNT > 0 THEN
8087 				        LOG_MESSAGES('updating contract lines with new invoice text');
8088                                         oks_contract_line_pub.update_line
8089                                           (p_api_version        => l_api_version,
8090                                            p_init_msg_list      => l_init_msg_list,
8091                                            x_return_status      => l_return_status,
8092                                            x_msg_count          => l_msg_count,
8093                                            x_msg_data           => l_msg_data,
8094                                            p_klnv_tbl           => l_klnv_tbl_type_in,
8095                                            x_klnv_tbl           => l_klnv_tbl_type_out,
8096                                            p_validate_yn        => 'N'
8097                                           );
8098 					  LOG_MESSAGES('CONTRACT_HEADER_OKS_LINES(Start_Date) update status: '||l_return_status);
8099 					  IF l_return_status <> G_RET_STS_SUCCESS THEN
8100 					     IF l_msg_count > 0 Then
8101                                                 FOR i in 1..l_msg_count
8102                                                 LOOP
8103                                                   fnd_msg_pub.get (p_msg_index     => -1,
8104                                                                    p_encoded       => 'F',
8105                                                                    p_data          => l_msg_data,
8106                                                                    p_msg_index_out => l_msg_index_out);
8107                                                   l_message := l_message||' ; '||l_msg_data;
8108                                                 END LOOP;
8109                                               END IF;
8110 					      LOG_MESSAGES('CONTRACT_OKS_LINES(Contract_Start_Date) update status: '||l_return_status);
8111                                               LOG_MESSAGES('Contract oks Lines(Contract_Start_Date) Update failed;'||l_message);
8112                                               l_status := 'ERROR';
8113                                               RAISE G_EXCEPTION_HALT_VALIDATION;
8114  					   END IF;
8115 				    END IF;
8116 				    -- Bug Fix 5075961
8117 
8118                                 ELSE
8119                                    IF l_msg_count > 0 Then
8120                                       FOR i in 1..l_msg_count
8121                                       LOOP
8122                                          fnd_msg_pub.get (p_msg_index     => -1,
8123                                          p_encoded       => 'F',
8124                                          p_data          => l_msg_data,
8125                                          p_msg_index_out => l_msg_index_out);
8126                                          l_message := l_message||' ; '||l_msg_data;
8127                                       END LOOP;
8128                                    END IF;
8129                                    LOG_MESSAGES('CONTRACT_LINES(Contract_Start_Date) update status: '||l_return_status);
8130                                    LOG_MESSAGES('Contract Lines(Contract_Start_Date) Update failed;'||l_message);
8131                                    l_status := 'ERROR';
8132                                    RAISE G_EXCEPTION_HALT_VALIDATION;
8133                                 END IF; -- contract line update status
8134                            ELSE
8135                               IF l_msg_count > 0 Then
8136                               FOR i in 1..l_msg_count
8137                               LOOP
8138                                   fnd_msg_pub.get (p_msg_index     => -1,
8139                                                    p_encoded       => 'F',
8140                                                    p_data          => l_msg_data,
8141                                                    p_msg_index_out => l_msg_index_out);
8142                                        l_message := l_message||' ; '||l_msg_data;
8143                                END LOOP;
8144                                END IF;
8145                                LOG_MESSAGES('CONTRACT_HEADERS(Contract_Start_Date) update status: '||l_return_status);
8146                                LOG_MESSAGES('Contract Header(Contract_Start_Date) Update failed;'||l_message);
8147                                l_status := 'ERROR';
8148                                RAISE G_EXCEPTION_HALT_VALIDATION;
8149                            END IF; -- Contract update
8150 
8151                 	  -- Vigandhi
8152 			  -- Bug Fix 5075961
8153 
8154                 	  ELSE  -- oks line lock
8155 
8156                                LOG_MESSAGES('CONTRACT_START_DATE LOCK_CONTRACT_OKS_LINES status: '||l_return_status||',msg_count:'||l_msg_count);
8157                                IF l_msg_count > 0 then
8158                         	   FOR i in 1..l_msg_count
8159                         	   LOOP
8160                         	   fnd_msg_pub.get (p_msg_index     => -1,
8161                                                     p_encoded       => 'F',
8162                                                     p_data          => l_msg_data,
8163                                                     p_msg_index_out => l_msg_index_out);
8164                                        l_message := l_message||' ; '||l_msg_data;
8165                                     END LOOP;
8166                                END IF;
8167                                LOG_MESSAGES('Contract Oks Lines Lock(CONTRACT_START_DATE) failed;'||l_message);
8168                                l_status := 'ERROR';
8169                                RAISE G_EXCEPTION_HALT_VALIDATION;
8170 
8171                 	  END IF; -- oks line lock
8172 
8173 			ELSE  -- Get oks contract Lines
8174                 	   LOG_MESSAGES('Get_Contract_lines status: '||l_return_status);
8175                 	   LOG_MESSAGES('Get_Contract_lines failed');
8176                 	   l_status := 'ERROR';
8177                 	   RAISE G_EXCEPTION_HALT_VALIDATION;
8178                 	END IF;  -- Get oks Contracts Lines
8179 
8180                        -- Bug Fix 5075961
8181 
8182 
8183                        ELSE -- line lock
8184                            LOG_MESSAGES('CONTRACT_START_DATE LOCK_CONTRACT_LINES status: '||l_return_status||',msg_count:'||l_msg_count);
8185                            IF l_msg_count > 0 then
8186                                FOR i in 1..l_msg_count
8187                                LOOP
8188                                fnd_msg_pub.get (p_msg_index     => -1,
8189                                                 p_encoded       => 'F',
8190                                                 p_data          => l_msg_data,
8191                                                 p_msg_index_out => l_msg_index_out);
8192                                    l_message := l_message||' ; '||l_msg_data;
8193                                 END LOOP;
8194                            END IF;
8195                            LOG_MESSAGES('Contract Lines Lock(CONTRACT_START_DATE) failed;'||l_message);
8196                            l_status := 'ERROR';
8197                            RAISE G_EXCEPTION_HALT_VALIDATION;
8198                        END IF; -- line lock
8199 
8200 
8201                   ELSE -- get contract line
8202                        LOG_MESSAGES('Get_Contract_lines status: '||l_return_status);
8203                        LOG_MESSAGES('Get_Contract_lines failed');
8204                        l_status := 'ERROR';
8205                        RAISE G_EXCEPTION_HALT_VALIDATION;
8206                   END IF; -- get contract lines
8207               ELSE -- lock contract
8208                      IF l_msg_count > 0 Then
8209                         FOR i in 1..l_msg_count
8210                         LOOP
8211                           fnd_msg_pub.get (p_msg_index     => -1,
8212                                            p_encoded       => 'F',
8213                                            p_data          => l_msg_data,
8214                                            p_msg_index_out => l_msg_index_out);
8215                                l_message := l_message||' ; '||l_msg_data;
8216                         END LOOP;
8217                      END IF;
8218                      LOG_MESSAGES('CONTRACT_START_DATE LOCK_CONTRACT status: '||l_return_status);
8219                      LOG_MESSAGES('Contract Lock(CONTRACT_START_DATE) failed;'||l_message);
8220                      l_status := 'ERROR';
8221                      RAISE G_EXCEPTION_HALT_VALIDATION;
8222               END IF; -- lock contract
8223 
8224             Elsif l_criteria_rec.attribute = 'CONTRACT_END_DATE' then
8225 
8226                l_chrv_tbl_in.DELETE;
8227 
8228                -- Check Start Date > End Date
8229                If trunc(l_eligible_contracts_tbl(i).Start_date) >
8230                            trunc(to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS')) then
8231                   l_message := FND_MESSAGE.get_string('OKS','OKS_MSCHG_WRONG_DT') ;
8232 --                  l_message := 'Contract Start Date greater than new End Date' ;
8233                   RAISE  l_notelligible_exception ;
8234                End If;
8235 
8236                -- Find the new status for the contract
8237                l_sts_code := Find_Contract_Status(
8238                                        p_start_date => l_eligible_contracts_tbl(i).start_date
8239                                        ,p_end_date  => to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS')
8240                                        ,p_sts_code  => l_eligible_contracts_tbl(i).CONTRACT_STATUS);
8241 
8242                LOG_MESSAGES('New status for the contract '||l_sts_code);
8243 
8244                l_chrv_tbl_in(1).id		         := l_eligible_contracts_tbl(i).contract_id;
8245                l_chrv_tbl_in(1).object_version_number    := l_eligible_contracts_tbl(i).object_version_number;
8246 
8247                OKC_CONTRACT_PUB.lock_contract_header (
8248                         	p_api_version		=> l_api_version,
8249                           	p_init_msg_list		=> l_init_msg_list,
8250                         	x_return_status		=> l_return_status,
8251                         	x_msg_count             => l_msg_count,
8252                          	x_msg_data              => l_msg_data,
8253                            	p_chrv_tbl              => l_chrv_tbl_in);
8254 
8255                IF l_return_status = G_RET_STS_SUCCESS THEN
8256 
8257                   LOG_MESSAGES('Fetching contract lines for update');
8258                   l_clev_tbl_in.DELETE;
8259                   Get_contract_lines(p_chr_id          => l_eligible_contracts_tbl(i).contract_id,
8260                                       p_attr           => l_criteria_rec.attribute,
8261                                       p_old_value      => l_old_value,
8262                                       p_new_value      => l_new_value,
8263                                       x_return_status  => l_return_status,
8264                                       x_clev_tbl       => l_clev_tbl_in);
8265 
8266                   IF l_return_status = G_RET_STS_SUCCESS THEN
8267                        LOG_MESSAGES('Locking contract lines for update, lines count:'||l_clev_tbl_in.COUNT);
8268                        OKC_CONTRACT_PUB.lock_contract_line(
8269                             	                  p_api_version	    => l_api_version,
8270                               	                  p_init_msg_list   => l_init_msg_list,
8271                             	                  x_return_status   => l_return_status,
8272                             	                  x_msg_count       => l_msg_count,
8273                              	                  x_msg_data        => l_msg_data,
8274                                                   p_clev_tbl        => l_clev_tbl_in);
8275 
8276                       LOG_MESSAGES('lock status:'||l_return_status);
8277                       IF l_return_status = G_RET_STS_SUCCESS THEN -- lines locked
8278 
8279                       --- vigandhi added
8280 		      -- Bug Fix 5075961
8281 
8282                       l_klnv_tbl_type_in.DELETE;
8283                       Get_oks_contract_lines(p_chr_id      => l_eligible_contracts_tbl(i).contract_id,
8284                                       p_attr           => l_criteria_rec.attribute,
8285                                       p_old_value      => l_old_value,
8286                                       p_new_value      => l_new_value,
8287                                       x_return_status  => l_return_status,
8288                                       x_clev_tbl       => l_klnv_tbl_type_in);
8289 
8290 		     IF l_return_status = G_RET_STS_SUCCESS THEN
8291 
8292 		       LOG_MESSAGES('Locking oks contract lines for update, lines count:'||l_klnv_tbl_type_in.COUNT);
8293                                     OKS_CONTRACT_LINE_PUB.lock_line(
8294                                         p_api_version         => l_api_version,
8295                                         p_init_msg_list       => l_init_msg_list,
8296                                         x_return_status       => l_return_status,
8297                                         x_msg_count           => l_msg_count,
8298                                         x_msg_data            => l_msg_data,
8299                                         p_klnv_tbl            => l_klnv_tbl_type_in);
8300 
8301 
8302                     IF l_return_status = G_RET_STS_SUCCESS THEN
8303                     -- Bug fix 5075961
8304 
8305                           l_chrv_rec_in.id          := l_eligible_contracts_tbl(i).contract_id;
8306                           l_chrv_rec_in.end_date  := to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS');
8307                           l_chrv_rec_in.sts_code    := l_sts_code;
8308 
8309                           LOG_MESSAGES('updating contract header with new value:'||l_new_value);
8310                           OKC_CONTRACT_PUB.update_contract_header (
8311                         	       p_api_version		=> l_api_version,
8312                           	       p_init_msg_list		=> l_init_msg_list,
8313                         	       x_return_status		=> l_return_status,
8314                         	       x_msg_count     	        => l_msg_count,
8315                          	       x_msg_data               => l_msg_data,
8316                         	       p_chrv_rec               => l_chrv_rec_in,
8317     	                               x_chrv_rec               => l_chrv_rec_out );
8318 
8319                            IF l_return_status = G_RET_STS_SUCCESS THEN -- contract update
8320                                LOG_MESSAGES('CONTRACT_HEADER(End_Date) update status: '||l_return_status);
8321                                IF l_clev_tbl_in.COUNT > 0 THEN
8322                                     FOR j in 1 .. l_clev_tbl_in.COUNT
8323                                     LOOP
8324                                         l_clev_tbl_in(j).end_date := to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS');
8325                                         l_clev_tbl_in(j).sts_code   := l_sts_code;
8326                                     END LOOP;
8327                                     LOG_MESSAGES('updating contract lines with new value:'||l_new_value);
8328                                     OKC_CONTRACT_PUB.update_contract_line(
8329                             	                  p_api_version	    => l_api_version,
8330                               	                  p_init_msg_list   => l_init_msg_list,
8331                             	                  x_return_status   => l_return_status,
8332                             	                  x_msg_count	    => l_msg_count,
8333                              	                  x_msg_data	    => l_msg_data,
8334                                                   p_clev_tbl        => l_clev_tbl_in,
8335                                                   x_clev_tbl        => l_clev_tbl_out);
8336                                 END IF; -- line_table.COUNT > 0
8337 
8338                                 IF l_return_status = G_RET_STS_SUCCESS THEN
8339                                     LOG_MESSAGES('CONTRACT_HEADER_LINES(End_Date) update status: '||l_return_status);
8340 
8341 
8342                                     -- Vigandhi
8343 				    -- Bug Fix 5075961
8344 
8345                                     IF l_klnv_tbl_type_in.COUNT > 0 THEN
8346 				        LOG_MESSAGES('updating contract lines with new invoice text');
8347                                         oks_contract_line_pub.update_line
8348                                           (p_api_version        => l_api_version,
8349                                            p_init_msg_list      => l_init_msg_list,
8350                                            x_return_status      => l_return_status,
8351                                            x_msg_count          => l_msg_count,
8352                                            x_msg_data           => l_msg_data,
8353                                            p_klnv_tbl           => l_klnv_tbl_type_in,
8354                                            x_klnv_tbl           => l_klnv_tbl_type_out,
8355                                            p_validate_yn        => 'N'
8356                                           );
8357 					  LOG_MESSAGES('CONTRACT_HEADER_OKS_LINES(Start_Date) update status: '||l_return_status);
8358 					  IF l_return_status <> G_RET_STS_SUCCESS THEN
8359 					     IF l_msg_count > 0 Then
8360                                                 FOR i in 1..l_msg_count
8361                                                 LOOP
8362                                                   fnd_msg_pub.get (p_msg_index     => -1,
8363                                                                    p_encoded       => 'F',
8364                                                                    p_data          => l_msg_data,
8365                                                                    p_msg_index_out => l_msg_index_out);
8366                                                   l_message := l_message||' ; '||l_msg_data;
8367                                                 END LOOP;
8368                                               END IF;
8369 					      LOG_MESSAGES('CONTRACT_OKS_LINES(Contract_Start_Date) update status: '||l_return_status);
8370                                               LOG_MESSAGES('Contract oks Lines(Contract_Start_Date) Update failed;'||l_message);
8371                                               l_status := 'ERROR';
8372                                               RAISE G_EXCEPTION_HALT_VALIDATION;
8373  					   END IF;
8374 				    END IF;
8375 				    -- Bug Fix 5075961
8376 
8377                                 ELSE
8378                                    IF l_msg_count > 0 Then
8379                                       FOR i in 1..l_msg_count
8380                                       LOOP
8381                                          fnd_msg_pub.get (p_msg_index     => -1,
8382                                                           p_encoded       => 'F',
8383                                                           p_data          => l_msg_data,
8384                                                           p_msg_index_out => l_msg_index_out);
8385                                               l_message := l_message||' ; '||l_msg_data;
8386                                       END LOOP;
8387                                    END IF;
8388                                    LOG_MESSAGES('CONTRACT_LINES(Contract_End_Date) update status: '||l_return_status);
8389                                    LOG_MESSAGES('Contract Lines(Contract_End_Date) Update failed;'||l_message);
8390                                    l_status := 'ERROR';
8391                                    RAISE G_EXCEPTION_HALT_VALIDATION;
8392                                 END IF; -- contract line update status
8393                            ELSE
8394                               IF l_msg_count > 0 Then
8395                               FOR i in 1..l_msg_count
8396                               LOOP
8397                                   fnd_msg_pub.get (p_msg_index     => -1,
8398                                                    p_encoded       => 'F',
8399                                                    p_data          => l_msg_data,
8400                                                    p_msg_index_out => l_msg_index_out);
8401                                        l_message := l_message||' ; '||l_msg_data;
8402                                END LOOP;
8403                                END IF;
8404                                LOG_MESSAGES('CONTRACT_HEADERS(Contract_End_Date) update status: '||l_return_status);
8405                                LOG_MESSAGES('Contract Header(Contract_End_Date) Update failed;'||l_message);
8406                                l_status := 'ERROR';
8407                                RAISE G_EXCEPTION_HALT_VALIDATION;
8408                            END IF; -- Contract update
8409 
8410                 	  -- Vigandhi
8411 			  -- Bug Fix 5075961
8412 
8413                 	  ELSE  -- oks line lock
8414 
8415                                LOG_MESSAGES('CONTRACT_START_DATE LOCK_CONTRACT_OKS_LINES status: '||l_return_status||',msg_count:'||l_msg_count);
8416                                IF l_msg_count > 0 then
8417                         	   FOR i in 1..l_msg_count
8418                         	   LOOP
8419                         	   fnd_msg_pub.get (p_msg_index     => -1,
8420                                                     p_encoded       => 'F',
8421                                                     p_data          => l_msg_data,
8422                                                     p_msg_index_out => l_msg_index_out);
8423                                        l_message := l_message||' ; '||l_msg_data;
8424                                     END LOOP;
8425                                END IF;
8426                                LOG_MESSAGES('Contract Oks Lines Lock(CONTRACT_START_DATE) failed;'||l_message);
8427                                l_status := 'ERROR';
8428                                RAISE G_EXCEPTION_HALT_VALIDATION;
8429 
8430                 	  END IF; -- oks line lock
8431 
8432 			ELSE  -- Get oks contract Lines
8433                 	   LOG_MESSAGES('Get_Contract_lines status: '||l_return_status);
8434                 	   LOG_MESSAGES('Get_Contract_lines failed');
8435                 	   l_status := 'ERROR';
8436                 	   RAISE G_EXCEPTION_HALT_VALIDATION;
8437                 	END IF;  -- Get oks Contracts Lines
8438 
8439                        -- Bug Fix 5075961
8440 
8441 		       ELSE -- line lock
8442                            LOG_MESSAGES('CONTRACT_START_DATE LOCK_CONTRACT_LINES status: '||l_return_status||',msg_count:'||l_msg_count);
8443                            IF l_msg_count > 0 then
8444                                FOR i in 1..l_msg_count
8445                                LOOP
8446                                fnd_msg_pub.get (p_msg_index     => -1,
8447                                                 p_encoded       => 'F',
8448                                                 p_data          => l_msg_data,
8449                                                 p_msg_index_out => l_msg_index_out);
8450                                    l_message := l_message||' ; '||l_msg_data;
8451                                 END LOOP;
8452                            END IF;
8453                            LOG_MESSAGES('Contract Lines Lock(CONTRACT_END_DATE) failed;'||l_message);
8454                            l_status := 'ERROR';
8455                            RAISE G_EXCEPTION_HALT_VALIDATION;
8456                        END IF; -- line lock
8457 
8458                   ELSE -- get contract line
8459                        LOG_MESSAGES('Get_Contract_lines status: '||l_return_status);
8460                        LOG_MESSAGES('Get_Contract_lines failed');
8461                        l_status := 'ERROR';
8462                        RAISE G_EXCEPTION_HALT_VALIDATION;
8463                   END IF; -- get contract lines
8464               ELSE -- lock contract
8465                      IF l_msg_count > 0 Then
8466                         FOR i in 1..l_msg_count
8467                         LOOP
8468                           fnd_msg_pub.get (p_msg_index     => -1,
8469                                            p_encoded       => 'F',
8470                                            p_data          => l_msg_data,
8471                                            p_msg_index_out => l_msg_index_out);
8472                                l_message := l_message||' ; '||l_msg_data;
8473                         END LOOP;
8474                      END IF;
8475                      LOG_MESSAGES('CONTRACT_START_DATE LOCK_CONTRACT status: '||l_return_status);
8476                      LOG_MESSAGES('Contract Lock(CONTRACT_END_DATE) failed;'||l_message);
8477                      l_status := 'ERROR';
8478                      RAISE G_EXCEPTION_HALT_VALIDATION;
8479               END IF; -- lock contract
8480 
8481             End If; -- start_date/end_date
8482 
8483          End If; -- update attribute type( l_criteria_rec.attribute )
8484 
8485 --    End if; -- dummy for if l_warrranty = 'y'
8486 
8487 
8488   Else  -- Not warranty - Service, Ext. warranty, Subscription
8489 
8490        IF l_criteria_rec.attribute = 'SALES_REP' then
8491            log_messages('l_eligible_contracts_tbl(i).org_id:'||l_eligible_contracts_tbl(i).org_id);
8492            OKC_CONTEXT.SET_OKC_ORG_CONTEXT(l_eligible_contracts_tbl(i).org_id,NULL);
8493            --log_messages('sys_context '||sys_context('OKC_CONTEXT','ORG_ID'));
8494            FOR contact_rec IN  Get_contact(l_eligible_contracts_tbl(i).contract_id,'SALESPERSON','OKX_SALEPERS',l_eligible_contracts_tbl(i).old_value)
8495            LOOP
8496               l_ctcv_rec_in.id		             := nvl(contact_rec.id,NULL);
8497               l_ctcv_rec_in.object_version_number      := contact_rec.object_version_number;
8498               l_start_date                       := contact_rec.start_date;
8499            END LOOP;
8500 
8501          IF l_ctcv_rec_in.id is NOT NULL
8502 	 AND l_ctcv_rec_in.id <> OKC_API.G_MISS_NUM then
8503                    OKC_CTC_PVT.lock_row(
8504                                         p_api_version         => l_api_version,
8505                                         p_init_msg_list       => l_init_msg_list,
8506                                         x_return_status       => l_return_status,
8507                                         x_msg_count           => l_msg_count,
8508                                         x_msg_data            => l_msg_data,
8509                                         p_ctcv_rec            => l_ctcv_rec_in);
8510 
8511          IF l_return_status = G_RET_STS_SUCCESS THEN
8512 
8513          l_ctcv_rec_in.object1_id1  := l_new_value_id;
8514          l_ctcv_rec_in.sales_group_id  := jtf_rs_integration_pub.get_default_sales_group
8515                                       (p_salesrep_id    => l_new_value_id,
8516                                        p_org_id         => Okc_context.get_okc_org_id,
8517                                        p_date           => l_start_date);
8518 
8519                 OKC_CTC_PVT.update_row(
8520                                         p_api_version         => l_api_version,
8521                                         p_init_msg_list       => l_init_msg_list,
8522                                         x_return_status       => l_return_status,
8523                                         x_msg_count           => l_msg_count,
8524                                         x_msg_data            => l_msg_data,
8525                                         p_ctcv_rec            => l_ctcv_rec_in,
8526                                         x_ctcv_rec            => l_ctcv_rec_out);
8527 
8528                  IF l_return_status = G_RET_STS_SUCCESS THEN
8529                         LOG_MESSAGES('SALES_PERSON in OKC_CONTACTS update status: '||l_return_status);
8530                  ELSE
8531                       IF l_msg_count > 0
8532                       THEN
8533                       FOR i in 1..l_msg_count
8534                       LOOP
8535                             fnd_msg_pub.get (p_msg_index     => -1,
8536                                              p_encoded       => 'F',
8537                                              p_data          => l_msg_data,
8538                                              p_msg_index_out => l_msg_index_out);
8539 
8540                             l_message := l_message||' ; '||l_msg_data;
8541 
8542                       END LOOP;
8543                       END IF;
8544 
8545                         LOG_MESSAGES('SALESPERSON in OKC_CONTACTS update status: '||l_return_status);
8546                         LOG_MESSAGES('SALES Person in OKC_CONTACTS  Update failed;'||l_message);
8547                         l_status := 'ERROR';
8548                         RAISE G_EXCEPTION_HALT_VALIDATION;
8549                     END IF;
8550 
8551           ELSE
8552               IF l_msg_count > 0
8553               THEN
8554               FOR i in 1..l_msg_count
8555               LOOP
8556                  fnd_msg_pub.get (p_msg_index     => -1,
8557                                   p_encoded       => 'F',
8558                                   p_data          => l_msg_data,
8559                                   p_msg_index_out => l_msg_index_out);
8560                      l_message := l_message||' ; '||l_msg_data;
8561               END LOOP;
8562               END IF;
8563 
8564                 LOG_MESSAGES('SALESPERSON in OKC_CONTACTS lock status: '||l_return_status);
8565                 LOG_MESSAGES('SALESPERSON in OKC_CONTACTS lock failed;'||l_message);
8566                 l_status := 'ERROR';
8567                 RAISE G_EXCEPTION_HALT_VALIDATION;
8568             END IF;
8569           END IF;
8570 
8571                         srv_cnt := 1;
8572                         l_scrv_tbl_in.DELETE;
8573                         FOR srv_rec IN Get_Salesrep(l_eligible_contracts_tbl(i).contract_id,l_eligible_contracts_tbl(i).old_value)
8574                         LOOP
8575                             l_scrv_tbl_in(srv_cnt).id		               := srv_rec.id;
8576                             l_scrv_tbl_in(srv_cnt).object_version_number   := srv_rec.object_version_number;
8577                             l_scrv_tbl_in(srv_cnt).ctc_id		         := l_new_value_id;
8578                             l_scrv_tbl_in(srv_cnt).sales_group_id          := jtf_rs_integration_pub.get_default_sales_group
8579                                                                                (p_salesrep_id    => l_new_value_id,
8580                                                                                 p_org_id         => Okc_context.get_okc_org_id,
8581                                                                                 p_date           => srv_rec.start_date);
8582 
8583                         srv_cnt :=  srv_cnt+1;
8584                         END LOOP;
8585                         FOR srv_rec IN Get_LineSalesrep(l_eligible_contracts_tbl(i).contract_id,l_eligible_contracts_tbl(i).old_value)
8586                         LOOP
8587                             l_scrv_tbl_in(srv_cnt).id		               := srv_rec.id;
8588                             l_scrv_tbl_in(srv_cnt).object_version_number   := srv_rec.object_version_number;
8589                             l_scrv_tbl_in(srv_cnt).ctc_id		         := l_new_value_id;
8590                             l_scrv_tbl_in(srv_cnt).sales_group_id          := jtf_rs_integration_pub.get_default_sales_group
8591                                                                                (p_salesrep_id    => l_new_value_id,
8592                                                                                 p_org_id         => Okc_context.get_okc_org_id,
8593                                                                                 p_date           => srv_rec.start_date);
8594 
8595                         srv_cnt :=  srv_cnt+1;
8596                         END LOOP;
8597             IF l_scrv_tbl_in.COUNT > 0 then
8598                             OKS_SALES_CREDIT_PUB.Lock_Sales_credit(
8599                                                 p_api_version         => l_api_version,
8600                                                 p_init_msg_list       => l_init_msg_list,
8601                                                 x_return_status       => l_return_status,
8602                                                 x_msg_count           => l_msg_count,
8603                                                 x_msg_data            => l_msg_data,
8604                                                 p_scrv_tbl            => l_scrv_tbl_in);
8605 
8606                                LOG_MESSAGES('OKS_SALES_CREDIT_PUB.Lock_Sales_credit: '||l_return_status);
8607                         IF l_return_status = G_RET_STS_SUCCESS THEN
8608                                 LOG_MESSAGES('SALES_PERSON in OKS_SALES_CREDIT Lock status: '||l_return_status);
8609 
8610                                OKS_SALES_CREDIT_PUB.update_Sales_credit(
8611                                                 p_api_version         => l_api_version,
8612                                                 p_init_msg_list       => l_init_msg_list,
8613                                                 x_return_status       => l_return_status,
8614                                                 x_msg_count           => l_msg_count,
8615                                                 x_msg_data            => l_msg_data,
8616                                                 p_scrv_tbl            => l_scrv_tbl_in,
8617                                                 x_scrv_tbl            => l_scrv_tbl_out);
8618 
8619                         IF l_return_status = G_RET_STS_SUCCESS THEN
8620                                 LOG_MESSAGES('SALES_PERSON in OKS_SALES_CREDIT update status: '||l_return_status);
8621                         ELSE
8622                             IF l_msg_count > 0
8623                             THEN
8624                             FOR i in 1..l_msg_count
8625                             LOOP
8626                                     fnd_msg_pub.get (p_msg_index     => -1,
8627                                                      p_encoded       => 'F',
8628                                                      p_data          => l_msg_data,
8629                                                      p_msg_index_out => l_msg_index_out);
8630 
8631                                     l_message := l_message||' ; '||l_msg_data;
8632 
8633                             END LOOP;
8634                             END IF;
8635                                 LOG_MESSAGES('SALES_PERSON in OKS_SALES_CREDIT update status: '||l_return_status);
8636                                 LOG_MESSAGES('SALES_PERSON in OKS_SALES_CREDIT Update failed;'||l_message);
8637                                 l_status := 'ERROR';
8638                                 RAISE G_EXCEPTION_HALT_VALIDATION;
8639                             END IF;
8640                     ELSE
8641                         IF l_msg_count > 0
8642                         THEN
8643                         FOR i in 1..l_msg_count
8644                         LOOP
8645                                  fnd_msg_pub.get (p_msg_index     => -1,
8646                                                   p_encoded       => 'F',
8647                                                   p_data          => l_msg_data,
8648                                                   p_msg_index_out => l_msg_index_out);
8649 
8650                                     l_message := l_message||' ; '||l_msg_data;
8651 
8652                         END LOOP;
8653                         END IF;
8654                               LOG_MESSAGES('SALES_PERSON in OKS_SALES_CREDIT Lock status: '||l_return_status);
8655                               LOG_MESSAGES('SALES_PERSON in OKS_SALES_CREDIT Lock failed;'||l_message);
8656                               l_status := 'ERROR';
8657                               RAISE G_EXCEPTION_HALT_VALIDATION;
8658                         END IF;
8659                   END IF;
8660        ELSIF l_criteria_rec.attribute = 'REV_ACCT' then
8661 
8662        FOR revenue_rec IN  Get_revenue(l_eligible_contracts_tbl(i).contract_id,l_eligible_contracts_tbl(i).old_value)
8663        LOOP
8664             l_rdsv_rec_in.id		                 := revenue_rec.id;
8665             l_rdsv_rec_in.object_version_number      := revenue_rec.object_version_number;
8666        END LOOP;
8667 	If l_rdsv_rec_in.id Is Not Null Then
8668                    OKS_REV_DISTR_PUB.lock_Revenue_Distr(
8669                                         p_api_version         => l_api_version,
8670                                         p_init_msg_list       => l_init_msg_list,
8671                                         x_return_status       => l_return_status,
8672                                         x_msg_count           => l_msg_count,
8673                                         x_msg_data            => l_msg_data,
8674                                         p_rdsv_rec            => l_rdsv_rec_in);
8675 
8676          IF l_return_status = G_RET_STS_SUCCESS THEN
8677 
8678          l_rdsv_rec_in.code_combination_id  := l_new_value_id;
8679 
8680                 OKS_REV_DISTR_PUB.update_Revenue_Distr(
8681                                         p_api_version         => l_api_version,
8682                                         p_init_msg_list       => l_init_msg_list,
8683                                         x_return_status       => l_return_status,
8684                                         x_msg_count           => l_msg_count,
8685                                         x_msg_data            => l_msg_data,
8686                                         p_rdsv_rec            => l_rdsv_rec_in,
8687                                         x_rdsv_rec            => l_rdsv_rec_out);
8688 
8689                  IF l_return_status = G_RET_STS_SUCCESS THEN
8690                         LOG_MESSAGES('REVENUE_ACCOUNT update status: '||l_return_status);
8691 
8692                  ELSE
8693                       IF l_msg_count > 0
8694                       THEN
8695                       FOR i in 1..l_msg_count
8696                       LOOP
8697                             fnd_msg_pub.get (p_msg_index     => -1,
8698                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
8699                                              p_data          => l_msg_data,
8700                                              p_msg_index_out => l_msg_index_out);
8701 
8702                             l_message := l_message||' ; '||l_msg_data;
8703 
8704                       END LOOP;
8705                       END IF;
8706 
8707                         LOG_MESSAGES('REVENUE_ACCOUNT update status: '||l_return_status);
8708                         LOG_MESSAGES('REVENUE_ACCOUNT Update failed;'||l_message);
8709                         l_status := 'ERROR';
8710                         RAISE G_EXCEPTION_HALT_VALIDATION;
8711                     END IF;
8712 
8713           ELSE
8714               IF l_msg_count > 0
8715               THEN
8716               FOR i in 1..l_msg_count
8717               LOOP
8718                  fnd_msg_pub.get (p_msg_index     => -1,
8719                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
8720                                   p_data          => l_msg_data,
8721                                   p_msg_index_out => l_msg_index_out);
8722                      l_message := l_message||' ; '||l_msg_data;
8723               END LOOP;
8724               END IF;
8725 
8726                 LOG_MESSAGES('REVENUE_ACCOUNT lock status: '||l_return_status);
8727                 LOG_MESSAGES('REVENUE_ACCOUNT lock failed;'||l_message);
8728                 l_status := 'ERROR';
8729                 RAISE G_EXCEPTION_HALT_VALIDATION;
8730             END IF;
8731 
8732 	End If;
8733        ELSIF l_criteria_rec.attribute = 'PARTY_SHIPPING_CONTACT' then
8734 
8735        FOR contact_rec IN  Get_contact(l_eligible_contracts_tbl(i).contract_id,'SHIPPING','OKX_PCONTACT',l_eligible_contracts_tbl(i).old_value)
8736        LOOP
8737             l_ctcv_rec_in.id		                 := contact_rec.id;
8738             l_ctcv_rec_in.object_version_number      := contact_rec.object_version_number;
8739        END LOOP;
8740 	If l_ctcv_rec_in.id Is Not null Then
8741                    OKC_CTC_PVT.lock_row(
8742                                         p_api_version         => l_api_version,
8743                                         p_init_msg_list       => l_init_msg_list,
8744                                         x_return_status       => l_return_status,
8745                                         x_msg_count           => l_msg_count,
8746                                         x_msg_data            => l_msg_data,
8747                                         p_ctcv_rec            => l_ctcv_rec_in);
8748 
8749          IF l_return_status = G_RET_STS_SUCCESS THEN
8750 
8751          l_ctcv_rec_in.object1_id1  := l_new_value_id;
8752 
8753                 OKC_CTC_PVT.update_row(
8754                                         p_api_version         => l_api_version,
8755                                         p_init_msg_list       => l_init_msg_list,
8756                                         x_return_status       => l_return_status,
8757                                         x_msg_count           => l_msg_count,
8758                                         x_msg_data            => l_msg_data,
8759                                         p_ctcv_rec            => l_ctcv_rec_in,
8760                                         x_ctcv_rec            => l_ctcv_rec_out);
8761 
8762                  IF l_return_status = G_RET_STS_SUCCESS THEN
8763                         LOG_MESSAGES('PARTY_SHIPPING_CONTACT update status: '||l_return_status);
8764 
8765                  ELSE
8766                       IF l_msg_count > 0
8767                       THEN
8768                       FOR i in 1..l_msg_count
8769                       LOOP
8770                             fnd_msg_pub.get (p_msg_index     => -1,
8771                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
8772                                              p_data          => l_msg_data,
8773                                              p_msg_index_out => l_msg_index_out);
8774 
8775                             l_message := l_message||' ; '||l_msg_data;
8776 
8777                       END LOOP;
8778                       END IF;
8779 
8780                         LOG_MESSAGES('PARTY_SHIPPING_CONTACT update status: '||l_return_status);
8781                         LOG_MESSAGES('Party Shipping Contact Update failed;'||l_message);
8782                         l_status := 'ERROR';
8783                         RAISE G_EXCEPTION_HALT_VALIDATION;
8784                     END IF;
8785 
8786           ELSE
8787               IF l_msg_count > 0
8788               THEN
8789               FOR i in 1..l_msg_count
8790               LOOP
8791                  fnd_msg_pub.get (p_msg_index     => -1,
8792                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
8793                                   p_data          => l_msg_data,
8794                                   p_msg_index_out => l_msg_index_out);
8795                      l_message := l_message||' ; '||l_msg_data;
8796               END LOOP;
8797               END IF;
8798 
8799                 LOG_MESSAGES('PARTY_SHIPPING_CONTACT rule lock status: '||l_return_status);
8800                 LOG_MESSAGES('PARTY_SHIPPING_CONTACT rule lock failed;'||l_message);
8801                 l_status := 'ERROR';
8802                 RAISE G_EXCEPTION_HALT_VALIDATION;
8803             END IF;
8804 	End If;
8805        ELSIF l_criteria_rec.attribute = 'PARTY_BILLING_CONTACT' then
8806 
8807        FOR contact_rec IN  Get_contact(l_eligible_contracts_tbl(i).contract_id,'BILLING','OKX_PCONTACT',l_eligible_contracts_tbl(i).old_value)
8808        LOOP
8809             l_ctcv_rec_in.id		                 := contact_rec.id;
8810             l_ctcv_rec_in.object_version_number      := contact_rec.object_version_number;
8811         LOG_MESSAGES('Inside PARTY_BILLING_CONTACT:'||l_ctcv_rec_in.id);
8812        END LOOP;
8813 	 If l_ctcv_rec_in.id is not null Then
8814                    OKC_CTC_PVT.lock_row(
8815                                         p_api_version         => l_api_version,
8816                                         p_init_msg_list       => l_init_msg_list,
8817                                         x_return_status       => l_return_status,
8818                                         x_msg_count           => l_msg_count,
8819                                         x_msg_data            => l_msg_data,
8820                                         p_ctcv_rec            => l_ctcv_rec_in);
8821 
8822         LOG_MESSAGES('After OKC_CTC_PVT.lock_row, status:'||l_return_status);
8823          IF l_return_status = G_RET_STS_SUCCESS THEN
8824 
8825          l_ctcv_rec_in.object1_id1  := l_new_value_id;
8826          l_return_status := NULL;
8827                 OKC_CTC_PVT.update_row(
8828                                         p_api_version         => l_api_version,
8829                                         p_init_msg_list       => l_init_msg_list,
8830                                         x_return_status       => l_return_status,
8831                                         x_msg_count           => l_msg_count,
8832                                         x_msg_data            => l_msg_data,
8833                                         p_ctcv_rec            => l_ctcv_rec_in,
8834                                         x_ctcv_rec            => l_ctcv_rec_out);
8835         LOG_MESSAGES('After OKC_CTC_PVT.update_row, status:'||l_return_status);
8836                  IF l_return_status = G_RET_STS_SUCCESS THEN
8837                         LOG_MESSAGES('PARTY_BILLING_CONTACT update status: '||l_return_status);
8838 
8839                  ELSE
8840                       IF l_msg_count > 0
8841                       THEN
8842                       FOR i in 1..l_msg_count
8843                       LOOP
8844                             fnd_msg_pub.get (p_msg_index     => -1,
8845                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
8846                                              p_data          => l_msg_data,
8847                                              p_msg_index_out => l_msg_index_out);
8848 
8849                             l_message := l_message||' ; '||l_msg_data;
8850 
8851                       END LOOP;
8852                       END IF;
8853 
8854                         LOG_MESSAGES('PARTY_BILLING_CONTACT update status: '||l_return_status);
8855                         LOG_MESSAGES('Party Billing Contact Update failed;'||l_message);
8856                         l_status := 'ERROR';
8857         LOG_MESSAGES('1');
8858                         RAISE G_EXCEPTION_HALT_VALIDATION;
8859                  END IF;
8860 
8861           ELSE
8862               IF l_msg_count > 0
8863               THEN
8864               FOR i in 1..l_msg_count
8865               LOOP
8866                  fnd_msg_pub.get (p_msg_index     => -1,
8867                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
8868                                   p_data          => l_msg_data,
8869                                   p_msg_index_out => l_msg_index_out);
8870                      l_message := l_message||' ; '||l_msg_data;
8871               END LOOP;
8872               END IF;
8873 
8874                 LOG_MESSAGES('PARTY_BILLING_CONTACT rule lock status: '||l_return_status);
8875                 LOG_MESSAGES('PARTY_BILLING_CONTACT rule lock failed;'||l_message);
8876                 l_status := 'ERROR';
8877         LOG_MESSAGES('2');
8878                 RAISE G_EXCEPTION_HALT_VALIDATION;
8879             END IF;
8880 	End If;
8881        ELSIF l_criteria_rec.attribute = 'LINE_SHIPPING_CONTACT' then
8882 
8883             l_ctcv_tbl_in.DELETE;
8884             l_ctcv_tbl_out.DELETE;
8885             cnt := 1;
8886 
8887        FOR contact_rec IN  Get_contact(l_eligible_contracts_tbl(i).contract_id,'CUST_SHIPPING','OKX_CONTSHIP',l_eligible_contracts_tbl(i).old_value)
8888        LOOP
8889             l_ctcv_tbl_in(cnt).id		                  := contact_rec.id;
8890             l_ctcv_tbl_in(cnt).object_version_number      := contact_rec.object_version_number;
8891             l_ctcv_tbl_in(cnt).object1_id1                := l_new_value_id ;
8892             cnt := cnt + 1 ;
8893        END LOOP;
8894 	If l_ctcv_tbl_in.count > 0 Then
8895                    OKC_CTC_PVT.lock_row(
8896                                         p_api_version         => l_api_version,
8897                                         p_init_msg_list       => l_init_msg_list,
8898                                         x_return_status       => l_return_status,
8899                                         x_msg_count           => l_msg_count,
8900                                         x_msg_data            => l_msg_data,
8901                                         p_ctcv_tbl            => l_ctcv_tbl_in);
8902 
8903          IF l_return_status = G_RET_STS_SUCCESS THEN
8904 
8905 --         l_ctcv_rec_in.object1_id1  := l_new_value_id;
8906 
8907                 OKC_CTC_PVT.update_row(
8908                                         p_api_version         => l_api_version,
8909                                         p_init_msg_list       => l_init_msg_list,
8910                                         x_return_status       => l_return_status,
8911                                         x_msg_count           => l_msg_count,
8912                                         x_msg_data            => l_msg_data,
8913                                         p_ctcv_tbl            => l_ctcv_tbl_in,
8914                                         x_ctcv_tbl            => l_ctcv_tbl_out);
8915 
8916                  IF l_return_status = G_RET_STS_SUCCESS THEN
8917                         LOG_MESSAGES('LINE_SHIPPING_CONTACT update status: '||l_return_status);
8918 
8919                  ELSE
8920                       IF l_msg_count > 0
8921                       THEN
8922                       FOR i in 1..l_msg_count
8923                       LOOP
8924                             fnd_msg_pub.get (p_msg_index     => -1,
8925                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
8926                                              p_data          => l_msg_data,
8927                                              p_msg_index_out => l_msg_index_out);
8928 
8929                             l_message := l_message||' ; '||l_msg_data;
8930 
8931                       END LOOP;
8932                       END IF;
8933 
8934                         LOG_MESSAGES('LINE_SHIPPING_CONTACT update status: '||l_return_status);
8935                         LOG_MESSAGES('Line Shipping Contact Update failed;'||l_message);
8936                         l_status := 'ERROR';
8937                         RAISE G_EXCEPTION_HALT_VALIDATION;
8938                     END IF;
8939 
8940           ELSE
8941               IF l_msg_count > 0
8942               THEN
8943               FOR i in 1..l_msg_count
8944               LOOP
8945                  fnd_msg_pub.get (p_msg_index     => -1,
8946                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
8947                                   p_data          => l_msg_data,
8948                                   p_msg_index_out => l_msg_index_out);
8949                      l_message := l_message||' ; '||l_msg_data;
8950               END LOOP;
8951               END IF;
8952 
8953                 LOG_MESSAGES('LINE_SHIPPING_CONTACT rule lock status: '||l_return_status);
8954                 LOG_MESSAGES('LINE_SHIPPING_CONTACT rule lock failed;'||l_message);
8955                 l_status := 'ERROR';
8956                 RAISE G_EXCEPTION_HALT_VALIDATION;
8957             END IF;
8958 	End If;
8959        ELSIF l_criteria_rec.attribute = 'LINE_BILLING_CONTACT' then
8960 
8961             l_ctcv_tbl_in.DELETE;
8962             l_ctcv_tbl_out.DELETE;
8963             cnt := 1;
8964 
8965        FOR contact_rec IN  Get_contact(l_eligible_contracts_tbl(i).contract_id,'CUST_BILLING','OKX_CONTBILL',l_eligible_contracts_tbl(i).old_value)
8966        LOOP
8967             l_ctcv_tbl_in(cnt).id		                 := contact_rec.id;
8968             l_ctcv_tbl_in(cnt).object_version_number      := contact_rec.object_version_number;
8969             l_ctcv_tbl_in(cnt).object1_id1                := l_new_value_id;
8970             cnt := cnt + 1 ;
8971        END LOOP;
8972 	If l_ctcv_tbl_in.count > 0 Then
8973                    OKC_CTC_PVT.lock_row(
8974                                         p_api_version         => l_api_version,
8975                                         p_init_msg_list       => l_init_msg_list,
8976                                         x_return_status       => l_return_status,
8977                                         x_msg_count           => l_msg_count,
8978                                         x_msg_data            => l_msg_data,
8979                                         p_ctcv_tbl            => l_ctcv_tbl_in);
8980 
8981             IF l_return_status = G_RET_STS_SUCCESS THEN
8982 
8983 --         l_ctcv_rec_in.object1_id1  := l_new_value_id;
8984 --         l_return_status := NULL;
8985                 OKC_CTC_PVT.update_row(
8986                                         p_api_version         => l_api_version,
8987                                         p_init_msg_list       => l_init_msg_list,
8988                                         x_return_status       => l_return_status,
8989                                         x_msg_count           => l_msg_count,
8990                                         x_msg_data            => l_msg_data,
8991                                         p_ctcv_tbl            => l_ctcv_tbl_in,
8992                                         x_ctcv_tbl            => l_ctcv_tbl_out);
8993 
8994                  IF l_return_status = G_RET_STS_SUCCESS THEN
8995                         LOG_MESSAGES('LINE_BILLING_CONTACT update status: '||l_return_status);
8996 
8997                  ELSE
8998                       IF l_msg_count > 0
8999                       THEN
9000                       FOR i in 1..l_msg_count
9001                       LOOP
9002                             fnd_msg_pub.get (p_msg_index     => -1,
9003                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9004                                              p_data          => l_msg_data,
9005                                              p_msg_index_out => l_msg_index_out);
9006 
9007                             l_message := l_message||' ; '||l_msg_data;
9008 
9009                       END LOOP;
9010                       END IF;
9011 
9012                         LOG_MESSAGES('LINE_BILLING_CONTACT update status: '||l_return_status);
9013                         LOG_MESSAGES('Line Billing Contact Update failed;'||l_message);
9014                         l_status := 'ERROR';
9015 
9016                         RAISE G_EXCEPTION_HALT_VALIDATION;
9017                  END IF;
9018 
9019           ELSE
9020               IF l_msg_count > 0
9021               THEN
9022               FOR i in 1..l_msg_count
9023               LOOP
9024                  fnd_msg_pub.get (p_msg_index     => -1,
9025                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9026                                   p_data          => l_msg_data,
9027                                   p_msg_index_out => l_msg_index_out);
9028                      l_message := l_message||' ; '||l_msg_data;
9029               END LOOP;
9030               END IF;
9031 
9032                 LOG_MESSAGES('LINE_BILLING_CONTACT rule lock status: '||l_return_status);
9033                 LOG_MESSAGES('LINE_BILLING_CONTACT rule lock failed;'||l_message);
9034                 l_status := 'ERROR';
9035 
9036                 RAISE G_EXCEPTION_HALT_VALIDATION;
9037             END IF;
9038 
9039 	End If;
9040       ELSIF l_criteria_rec.attribute = 'HDR_SHIP_TO_ADDRESS' then
9041 
9042             l_chrv_rec_in.id		             := l_eligible_contracts_tbl(i).contract_id ;
9043             l_chrv_rec_in.object_version_number  := l_eligible_contracts_tbl(i).object_version_number;
9044 
9045 
9046             OKC_CONTRACT_PUB.lock_contract_header(
9047                                         p_api_version         => l_api_version,
9048                                         p_init_msg_list       => l_init_msg_list,
9049                                         x_return_status       => l_return_status,
9050                                         x_msg_count           => l_msg_count,
9051                                         x_msg_data            => l_msg_data,
9052                                         p_chrv_rec            => l_chrv_rec_in);
9053 
9054 
9055          IF l_return_status = G_RET_STS_SUCCESS THEN
9056 
9057          l_chrv_rec_in.ship_to_site_use_id  := l_new_value_id;
9058 
9059               OKC_CONTRACT_PUB.update_contract_header(
9060                                         p_api_version         => l_api_version,
9061                                         p_init_msg_list       => l_init_msg_list,
9062                                         x_return_status       => l_return_status,
9063                                         x_msg_count           => l_msg_count,
9064                                         x_msg_data            => l_msg_data,
9065                                         p_restricted_update   => 'F' ,
9066                                         p_chrv_rec            => l_chrv_rec_in,
9067                                         x_chrv_rec            => l_chrv_rec_out);
9068 
9069                  IF l_return_status = G_RET_STS_SUCCESS THEN
9070                         LOG_MESSAGES('SHIP_TO_ADDRESS update status: '||l_return_status);
9071 
9072                  ELSE
9073                       IF l_msg_count > 0
9074                       THEN
9075                       FOR i in 1..l_msg_count
9076                       LOOP
9077                             fnd_msg_pub.get (p_msg_index     => -1,
9078                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9079                                              p_data          => l_msg_data,
9080                                              p_msg_index_out => l_msg_index_out);
9081 
9082                             l_message := l_message||' ; '||l_msg_data;
9083 
9084                       END LOOP;
9085                       END IF;
9086 
9087                         LOG_MESSAGES('SHIP_TO_ADDRESS update status: '||l_return_status);
9088                         LOG_MESSAGES('Ship-To Address Update failed;'||l_message);
9089                         l_status := 'ERROR';
9090                         RAISE G_EXCEPTION_HALT_VALIDATION;
9091                     END IF;
9092 
9093           ELSE
9094               IF l_msg_count > 0
9095               THEN
9096               FOR i in 1..l_msg_count
9097               LOOP
9098                  fnd_msg_pub.get (p_msg_index     => -1,
9099                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9100                                   p_data          => l_msg_data,
9101                                   p_msg_index_out => l_msg_index_out);
9102                      l_message := l_message||' ; '||l_msg_data;
9103               END LOOP;
9104               END IF;
9105 
9106                 LOG_MESSAGES('SHIP_TO_ADDRESS rule lock status: '||l_return_status);
9107                 LOG_MESSAGES('SHIP_TO_ADDRESS rule lock failed;'||l_message);
9108                 l_status := 'ERROR';
9109                 RAISE G_EXCEPTION_HALT_VALIDATION;
9110             END IF;
9111 
9112       ELSIF l_criteria_rec.attribute = 'PAYMENT_TERM' then
9113 
9114             l_chrv_rec_in.id		             := l_eligible_contracts_tbl(i).contract_id ;
9115             l_chrv_rec_in.object_version_number  := l_eligible_contracts_tbl(i).object_version_number;
9116 
9117                 OKC_CONTRACT_PUB.lock_contract_header(
9118                                         p_api_version         => l_api_version,
9119                                         p_init_msg_list       => l_init_msg_list,
9120                                         x_return_status       => l_return_status,
9121                                         x_msg_count           => l_msg_count,
9122                                         x_msg_data            => l_msg_data,
9123                                         p_chrv_rec            => l_chrv_rec_in);
9124 
9125 
9126          IF l_return_status = G_RET_STS_SUCCESS THEN
9127 
9128          l_chrv_rec_in.payment_term_id  := l_new_value_id;
9129 
9130               OKC_CONTRACT_PUB.update_contract_header(
9131                                         p_api_version         => l_api_version,
9132                                         p_init_msg_list       => l_init_msg_list,
9133                                         x_return_status       => l_return_status,
9134                                         x_msg_count           => l_msg_count,
9135                                         x_msg_data            => l_msg_data,
9136                                         p_restricted_update   => 'F' ,
9137                                         p_chrv_rec            => l_chrv_rec_in,
9138                                         x_chrv_rec            => l_chrv_rec_out);
9139 
9140 
9141                  IF l_return_status = G_RET_STS_SUCCESS THEN
9142                         LOG_MESSAGES('PAYMENT_TERM update status: '||l_return_status);
9143 
9144                  ELSE
9145                       IF l_msg_count > 0
9146                       THEN
9147                       FOR i in 1..l_msg_count
9148                       LOOP
9149                             fnd_msg_pub.get (p_msg_index     => -1,
9150                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9151                                              p_data          => l_msg_data,
9152                                              p_msg_index_out => l_msg_index_out);
9153 
9154                             l_message := l_message||' ; '||l_msg_data;
9155 
9156                       END LOOP;
9157                       END IF;
9158 
9159                         LOG_MESSAGES('PAYMENT_TERM update status: '||l_return_status);
9160                         LOG_MESSAGES('PAYMENT_TERM Update failed;'||l_message);
9161                         l_status := 'ERROR';
9162                         RAISE G_EXCEPTION_HALT_VALIDATION;
9163                     END IF;
9164 
9165           ELSE
9166               IF l_msg_count > 0
9167               THEN
9168               FOR i in 1..l_msg_count
9169               LOOP
9170                  fnd_msg_pub.get (p_msg_index     => -1,
9171                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9172                                   p_data          => l_msg_data,
9173                                   p_msg_index_out => l_msg_index_out);
9174                      l_message := l_message||' ; '||l_msg_data;
9175               END LOOP;
9176               END IF;
9177 
9178                 LOG_MESSAGES('PAYMENT_TERM rule lock status: '||l_return_status);
9179                 LOG_MESSAGES('PAYMENT_TERM rule lock failed;'||l_message);
9180                 l_status := 'ERROR';
9181                 RAISE G_EXCEPTION_HALT_VALIDATION;
9182             END IF;
9183 
9184       ELSIF l_criteria_rec.attribute = 'CON_RENEWAL_TYPE' then
9185 
9186        If l_new_value_id = '-9999' then
9187           l_new_value_id := Null;
9188        End If;
9189             l_chrv_rec_in.id		         := l_eligible_contracts_tbl(i).contract_id ;
9190             l_chrv_rec_in.object_version_number  := l_eligible_contracts_tbl(i).object_version_number;
9191 
9192                 OKC_CONTRACT_PUB.lock_contract_header(
9193                                         p_api_version         => l_api_version,
9194                                         p_init_msg_list       => l_init_msg_list,
9195                                         x_return_status       => l_return_status,
9196                                         x_msg_count           => l_msg_count,
9197                                         x_msg_data            => l_msg_data,
9198                                         p_chrv_rec            => l_chrv_rec_in);
9199 
9200 
9201          IF l_return_status = G_RET_STS_SUCCESS THEN
9202          If l_new_value_id = 'ERN' then
9203               l_chrv_rec_in.renewal_type_code  := 'NSR';
9204          Else
9205               l_chrv_rec_in.renewal_type_code  := l_new_value_id;
9206          End If;
9207 
9208               OKC_CONTRACT_PUB.update_contract_header(
9209                                         p_api_version         => l_api_version,
9210                                         p_init_msg_list       => l_init_msg_list,
9211                                         x_return_status       => l_return_status,
9212                                         x_msg_count           => l_msg_count,
9213                                         x_msg_data            => l_msg_data,
9214                                         p_restricted_update   => 'F' ,
9215                                         p_chrv_rec            => l_chrv_rec_in,
9216                                         x_chrv_rec            => l_chrv_rec_out);
9217 
9218 
9219                  IF l_return_status = G_RET_STS_SUCCESS THEN
9220                         LOG_MESSAGES('CON_RENEWAL_TYPE update status: '||l_return_status);
9221 
9222                  ELSE
9223                       IF l_msg_count > 0
9224                       THEN
9225                       FOR i in 1..l_msg_count
9226                       LOOP
9227                             fnd_msg_pub.get (p_msg_index     => -1,
9228                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9229                                              p_data          => l_msg_data,
9230                                              p_msg_index_out => l_msg_index_out);
9231 
9232                             l_message := l_message||' ; '||l_msg_data;
9233 
9234                       END LOOP;
9235                       END IF;
9236 
9237                         LOG_MESSAGES('CON_RENEWAL_TYPE update status: '||l_return_status);
9238                         LOG_MESSAGES('CON_RENEWAL_TYPE Update failed;'||l_message);
9239                         l_status := 'ERROR';
9240                         RAISE G_EXCEPTION_HALT_VALIDATION;
9241                     END IF;
9242 
9243           ELSE
9244               IF l_msg_count > 0
9245               THEN
9246               FOR i in 1..l_msg_count
9247               LOOP
9248                  fnd_msg_pub.get (p_msg_index     => -1,
9249                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9250                                   p_data          => l_msg_data,
9251                                   p_msg_index_out => l_msg_index_out);
9252                      l_message := l_message||' ; '||l_msg_data;
9253               END LOOP;
9254               END IF;
9255 
9256                 LOG_MESSAGES('CON_RENEWAL_TYPE  lock status: '||l_return_status);
9257                 LOG_MESSAGES('CON_RENEWAL_TYPE  lock failed;'||l_message);
9258                 l_status := 'ERROR';
9259                 RAISE G_EXCEPTION_HALT_VALIDATION;
9260             END IF;
9261 
9262      -- Electronic renewal flag update
9263 
9264        FOR rec IN Get_Electronic_Ren_YN(l_eligible_contracts_tbl(i).contract_id )
9265        LOOP
9266             l_khrv_rec_type_in.id	   	     := rec.id;
9267             l_khrv_rec_type_in.object_version_number := rec.object_version_number;
9268 
9269        END LOOP;
9270 
9271                 OKS_CONTRACT_HDR_PUB.lock_header(
9272                                         p_api_version         => l_api_version,
9273                                         p_init_msg_list       => l_init_msg_list,
9274                                         x_return_status       => l_return_status,
9275                                         x_msg_count           => l_msg_count,
9276                                         x_msg_data            => l_msg_data,
9277                                         p_khrv_rec            => l_khrv_rec_type_in );
9278 
9279 
9280            IF l_return_status = G_RET_STS_SUCCESS THEN
9281 
9282            If l_new_value_id = 'ERN' then
9283               l_khrv_rec_type_in.ELECTRONIC_RENEWAL_FLAG  := 'Y';
9284            Else
9285               l_khrv_rec_type_in.ELECTRONIC_RENEWAL_FLAG  := Null;
9286            End If;
9287 
9288                 OKS_CONTRACT_HDR_PUB.update_header(
9289                                         p_api_version         => l_api_version,
9290                                         p_init_msg_list       => l_init_msg_list,
9291                                         x_return_status       => l_return_status,
9292                                         x_msg_count           => l_msg_count,
9293                                         x_msg_data            => l_msg_data,
9294                                         p_khrv_rec            => l_khrv_rec_type_in,
9295                                         x_khrv_rec            => l_khrv_rec_type_out,
9296                                         p_validate_yn         => 'Y');
9297 
9298 
9299                  IF l_return_status = G_RET_STS_SUCCESS THEN
9300                         LOG_MESSAGES('CON_RENEWAL_TYPE  update status: '||l_return_status);
9301 
9302                  ELSE
9303                       IF l_msg_count > 0
9304                       THEN
9305                       FOR i in 1..l_msg_count
9306                       LOOP
9307                             fnd_msg_pub.get (p_msg_index     => -1,
9308                                              p_encoded       => 'F',
9309                                              p_data          => l_msg_data,
9310                                              p_msg_index_out => l_msg_index_out);
9311 
9312                             l_message := l_message||' ; '||l_msg_data;
9313 
9314                       END LOOP;
9315                       END IF;
9316 
9317                         LOG_MESSAGES('CON_RENEWAL_TYPE update status: '||l_return_status);
9318                         LOG_MESSAGES('CON_RENEWAL_TYPE Update failed;'||l_message);
9319                         l_status := 'ERROR';
9320                         RAISE G_EXCEPTION_HALT_VALIDATION;
9321                     END IF;
9322 
9323           ELSE
9324               IF l_msg_count > 0
9325               THEN
9326               FOR i in 1..l_msg_count
9327               LOOP
9328                  fnd_msg_pub.get (p_msg_index     => -1,
9329                                   p_encoded       => 'F',
9330                                   p_data          => l_msg_data,
9331                                   p_msg_index_out => l_msg_index_out);
9332                      l_message := l_message||' ; '||l_msg_data;
9333               END LOOP;
9334               END IF;
9335 
9336                 LOG_MESSAGES('CON_RENEWAL_TYPE  lock status: '||l_return_status);
9337                 LOG_MESSAGES('CON_RENEWAL_TYPE  lock failed;'||l_message);
9338                 l_status := 'ERROR';
9339                 RAISE G_EXCEPTION_HALT_VALIDATION;
9340             END IF;
9341 
9342 
9343        ELSIF l_criteria_rec.attribute = 'ACCT_RULE' then
9344 
9345        FOR rec IN Get_Acct_Rule(l_eligible_contracts_tbl(i).contract_id , l_eligible_contracts_tbl(i).old_value)
9346        LOOP
9347             l_khrv_rec_type_in.id	   	                  := rec.id;
9348             l_khrv_rec_type_in.object_version_number      := rec.object_version_number;
9349 
9350        END LOOP;
9351 	If l_khrv_rec_type_in.id Is Not Null Then
9352                 OKS_CONTRACT_HDR_PUB.lock_header(
9353                                         p_api_version         => l_api_version,
9354                                         p_init_msg_list       => l_init_msg_list,
9355                                         x_return_status       => l_return_status,
9356                                         x_msg_count           => l_msg_count,
9357                                         x_msg_data            => l_msg_data,
9358                                         p_khrv_rec            => l_khrv_rec_type_in );
9359 
9360 
9361            IF l_return_status = G_RET_STS_SUCCESS THEN
9362 
9363            l_khrv_rec_type_in.acct_rule_id  := l_new_value_id;
9364 
9365                 OKS_CONTRACT_HDR_PUB.update_header(
9366                                         p_api_version         => l_api_version,
9367                                         p_init_msg_list       => l_init_msg_list,
9368                                         x_return_status       => l_return_status,
9369                                         x_msg_count           => l_msg_count,
9370                                         x_msg_data            => l_msg_data,
9371                                         p_khrv_rec            => l_khrv_rec_type_in,
9372                                         x_khrv_rec            => l_khrv_rec_type_out,
9373                                         p_validate_yn         => 'Y');
9374 
9375 
9376                  IF l_return_status = G_RET_STS_SUCCESS THEN
9377                         LOG_MESSAGES('ACCT_RULE update status: '||l_return_status);
9378 
9379                  ELSE
9380                       IF l_msg_count > 0
9381                       THEN
9382                       FOR i in 1..l_msg_count
9383                       LOOP
9384                             fnd_msg_pub.get (p_msg_index     => -1,
9385                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9386                                              p_data          => l_msg_data,
9387                                              p_msg_index_out => l_msg_index_out);
9388 
9389                             l_message := l_message||' ; '||l_msg_data;
9390 
9391                       END LOOP;
9392                       END IF;
9393 
9394                         LOG_MESSAGES('ACCT_RULE update status: '||l_return_status);
9395                         LOG_MESSAGES('ACCT_RULE Update failed;'||l_message);
9396                         l_status := 'ERROR';
9397                         RAISE G_EXCEPTION_HALT_VALIDATION;
9398                     END IF;
9399 
9400           ELSE
9401               IF l_msg_count > 0
9402               THEN
9403               FOR i in 1..l_msg_count
9404               LOOP
9405                  fnd_msg_pub.get (p_msg_index     => -1,
9406                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9407                                   p_data          => l_msg_data,
9408                                   p_msg_index_out => l_msg_index_out);
9409                      l_message := l_message||' ; '||l_msg_data;
9410               END LOOP;
9411               END IF;
9412 
9413                 LOG_MESSAGES('ACCT_RULE rule lock status: '||l_return_status);
9414                 LOG_MESSAGES('ACCT_RULE rule lock failed;'||l_message);
9415                 l_status := 'ERROR';
9416                 RAISE G_EXCEPTION_HALT_VALIDATION;
9417             END IF;
9418 
9419 	End If;
9420    ELSIF l_criteria_rec.attribute = 'SUMMARY_PRINT' then
9421 
9422        FOR rec IN Get_Summary_Print(l_eligible_contracts_tbl(i).contract_id , l_eligible_contracts_tbl(i).old_value)
9423        LOOP
9424             l_khrv_rec_type_in.id	   	     := rec.id;
9425             l_khrv_rec_type_in.object_version_number := rec.object_version_number;
9426 
9427        END LOOP;
9428 	If l_khrv_rec_type_in.id Is Not Null Then
9429                 OKS_CONTRACT_HDR_PUB.lock_header(
9430                                         p_api_version         => l_api_version,
9431                                         p_init_msg_list       => l_init_msg_list,
9432                                         x_return_status       => l_return_status,
9433                                         x_msg_count           => l_msg_count,
9434                                         x_msg_data            => l_msg_data,
9435                                         p_khrv_rec            => l_khrv_rec_type_in );
9436 
9437 
9438            IF l_return_status = G_RET_STS_SUCCESS THEN
9439 
9440            l_khrv_rec_type_in.inv_print_profile  := l_new_value_id;
9441 
9442                 OKS_CONTRACT_HDR_PUB.update_header(
9443                                         p_api_version         => l_api_version,
9444                                         p_init_msg_list       => l_init_msg_list,
9445                                         x_return_status       => l_return_status,
9446                                         x_msg_count           => l_msg_count,
9447                                         x_msg_data            => l_msg_data,
9448                                         p_khrv_rec            => l_khrv_rec_type_in,
9449                                         x_khrv_rec            => l_khrv_rec_type_out,
9450                                         p_validate_yn         => 'Y');
9451 
9452 
9453                  IF l_return_status = G_RET_STS_SUCCESS THEN
9454                         LOG_MESSAGES('SUMMARY_PRINT update status: '||l_return_status);
9455 
9456                  ELSE
9457                       IF l_msg_count > 0
9458                       THEN
9459                       FOR i in 1..l_msg_count
9460                       LOOP
9461                             fnd_msg_pub.get (p_msg_index     => -1,
9462                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9463                                              p_data          => l_msg_data,
9464                                              p_msg_index_out => l_msg_index_out);
9465 
9466                             l_message := l_message||' ; '||l_msg_data;
9467 
9468                       END LOOP;
9469                       END IF;
9470 
9471                         LOG_MESSAGES('SUMMARY_PRINT update status: '||l_return_status);
9472                         LOG_MESSAGES('SUMMARY_PRINT Update failed;'||l_message);
9473                         l_status := 'ERROR';
9474                         RAISE G_EXCEPTION_HALT_VALIDATION;
9475                     END IF;
9476 
9477           ELSE
9478               IF l_msg_count > 0
9479               THEN
9480               FOR i in 1..l_msg_count
9481               LOOP
9482                  fnd_msg_pub.get (p_msg_index     => -1,
9483                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9484                                   p_data          => l_msg_data,
9485                                   p_msg_index_out => l_msg_index_out);
9486                      l_message := l_message||' ; '||l_msg_data;
9487               END LOOP;
9488               END IF;
9489 
9490                 LOG_MESSAGES('SUMMARY_PRINT  lock status: '||l_return_status);
9491                 LOG_MESSAGES('SUMMARY_PRINT  lock failed;'||l_message);
9492                 l_status := 'ERROR';
9493                 RAISE G_EXCEPTION_HALT_VALIDATION;
9494             END IF;
9495 	End If;
9496    ELSIF l_criteria_rec.attribute = 'PO_REQUIRED_REN' then
9497 
9498        FOR rec IN Get_po_required_ren(l_eligible_contracts_tbl(i).contract_id ,
9499                                        l_eligible_contracts_tbl(i).old_value)
9500        LOOP
9501             l_khrv_rec_type_in.id  	                  := rec.id;
9502             l_khrv_rec_type_in.object_version_number      := rec.object_version_number;
9503 
9504        END LOOP;
9505 	 If l_khrv_rec_type_in.id Is Not Null Then
9506                 OKS_CONTRACT_HDR_PUB.lock_header(
9507                                         p_api_version         => l_api_version,
9508                                         p_init_msg_list       => l_init_msg_list,
9509                                         x_return_status       => l_return_status,
9510                                         x_msg_count           => l_msg_count,
9511                                         x_msg_data            => l_msg_data,
9512                                         p_khrv_rec            => l_khrv_rec_type_in );
9513 
9514            IF l_return_status = G_RET_STS_SUCCESS THEN
9515 
9516            l_khrv_rec_type_in.renewal_po_required  := l_new_value_id;
9517 
9518                 OKS_CONTRACT_HDR_PUB.update_header(
9519                                         p_api_version         => l_api_version,
9520                                         p_init_msg_list       => l_init_msg_list,
9521                                         x_return_status       => l_return_status,
9522                                         x_msg_count           => l_msg_count,
9523                                         x_msg_data            => l_msg_data,
9524                                         p_khrv_rec            => l_khrv_rec_type_in,
9525                                         x_khrv_rec            => l_khrv_rec_type_out,
9526                                         p_validate_yn         => 'Y');
9527 
9528 
9529                  IF l_return_status = G_RET_STS_SUCCESS THEN
9530                         LOG_MESSAGES('PO Required update status: '||l_return_status);
9531                  ELSE
9532                       IF l_msg_count > 0
9533                       THEN
9534                       FOR i in 1..l_msg_count
9535                       LOOP
9536                             fnd_msg_pub.get (p_msg_index     => -1,
9537                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9538                                              p_data          => l_msg_data,
9539                                              p_msg_index_out => l_msg_index_out);
9540 
9541                             l_message := l_message||' ; '||l_msg_data;
9542 
9543                       END LOOP;
9544                       END IF;
9545 
9546                         LOG_MESSAGES('PO Required update status: '||l_return_status);
9547                         LOG_MESSAGES('PO Required Update failed;'||l_message);
9548                         l_status := 'ERROR';
9549                         RAISE G_EXCEPTION_HALT_VALIDATION;
9550                     END IF;
9551 
9552           ELSE
9553               IF l_msg_count > 0
9554               THEN
9555               FOR i in 1..l_msg_count
9556               LOOP
9557                  fnd_msg_pub.get (p_msg_index     => -1,
9558                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9559                                   p_data          => l_msg_data,
9560                                   p_msg_index_out => l_msg_index_out);
9561                      l_message := l_message||' ; '||l_msg_data;
9562               END LOOP;
9563               END IF;
9564 
9565                 LOG_MESSAGES('PO Required  lock status: '||l_return_status);
9566                 LOG_MESSAGES('PO Required  lock failed;'||l_message);
9567                 l_status := 'ERROR';
9568                 RAISE G_EXCEPTION_HALT_VALIDATION;
9569             END IF;
9570 
9571 	END IF;
9572        ELSIF l_criteria_rec.attribute = 'INV_RULE' then
9573 
9574             l_chrv_rec_in.id		             := l_eligible_contracts_tbl(i).contract_id ;
9575             l_chrv_rec_in.object_version_number  := l_eligible_contracts_tbl(i).object_version_number;
9576 
9577                 OKC_CONTRACT_PUB.lock_contract_header(
9578                                         p_api_version         => l_api_version,
9579                                         p_init_msg_list       => l_init_msg_list,
9580                                         x_return_status       => l_return_status,
9581                                         x_msg_count           => l_msg_count,
9582                                         x_msg_data            => l_msg_data,
9583                                         p_chrv_rec            => l_chrv_rec_in);
9584 
9585 
9586          IF l_return_status = G_RET_STS_SUCCESS THEN
9587             l_chrv_rec_in.inv_rule_id  := l_new_value_id;
9588 
9589             OKC_CONTRACT_PUB.update_contract_header(
9590                                         p_api_version         => l_api_version,
9591                                         p_init_msg_list       => l_init_msg_list,
9592                                         x_return_status       => l_return_status,
9593                                         x_msg_count           => l_msg_count,
9594                                         x_msg_data            => l_msg_data,
9595                                         p_restricted_update   => 'F' ,
9596                                         p_chrv_rec            => l_chrv_rec_in,
9597                                         x_chrv_rec            => l_chrv_rec_out);
9598 
9599               IF l_return_status = G_RET_STS_SUCCESS THEN
9600                  LOG_MESSAGES('INV_RULE update status: '||l_return_status);
9601 
9602                  FOR rec_line_id in Get_lines_csr (l_eligible_contracts_tbl(i).contract_id) LOOP
9603 
9604                        Update Okc_k_lines_b set inv_rule_id = l_new_value_id
9605                        Where id = rec_line_id.id;
9606 
9607                         oks_bill_sch.update_bs_interface_date(
9608                                    p_top_line_id      => rec_line_id.id,
9609                                    p_invoice_rule_id  => l_new_value_id,
9610                                    x_return_status    => l_return_status,
9611                                    x_msg_count        => l_msg_count,
9612                                    x_msg_data         => l_msg_data);
9613 
9614 
9615 
9616 
9617 
9618                  END LOOP ;
9619 
9620                         IF l_return_status = G_RET_STS_SUCCESS THEN
9621                            LOG_MESSAGES('INV_RULE update_bs_interface_date: '||l_return_status);
9622 
9623                         ELSE
9624                            IF l_msg_count > 0 THEN
9625                               FOR i in 1..l_msg_count
9626                               LOOP
9627                               fnd_msg_pub.get (p_msg_index     => -1,
9628                                                p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9629                                                p_data          => l_msg_data,
9630                                                p_msg_index_out => l_msg_index_out);
9631 
9632                               l_message := l_message||' ; '||l_msg_data;
9633 
9634                               END LOOP;
9635                            END IF;
9636 
9637                             LOG_MESSAGES('INV_RULE update_bs_interface_date: '||l_return_status);
9638                             LOG_MESSAGES('INV_RULE update_bs_interface_date Update failed;'||l_message);
9639                             l_status := 'ERROR';
9640                             RAISE G_EXCEPTION_HALT_VALIDATION;
9641                         END IF;
9642                  ELSE
9643                       IF l_msg_count > 0
9644                       THEN
9645                       FOR i in 1..l_msg_count
9646                       LOOP
9647                             fnd_msg_pub.get (p_msg_index     => -1,
9648                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9649                                              p_data          => l_msg_data,
9650                                              p_msg_index_out => l_msg_index_out);
9651 
9652                             l_message := l_message||' ; '||l_msg_data;
9653 
9654                       END LOOP;
9655                       END IF;
9656 
9657                         LOG_MESSAGES('INV_RULE update status: '||l_return_status);
9658                         LOG_MESSAGES('INV_RULE Update failed;'||l_message);
9659                         l_status := 'ERROR';
9660                         RAISE G_EXCEPTION_HALT_VALIDATION;
9661                     END IF;
9662           ELSE
9663               IF l_msg_count > 0
9664               THEN
9665               FOR i in 1..l_msg_count
9666               LOOP
9667                  fnd_msg_pub.get (p_msg_index     => -1,
9668                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9669                                   p_data          => l_msg_data,
9670                                   p_msg_index_out => l_msg_index_out);
9671                      l_message := l_message||' ; '||l_msg_data;
9672               END LOOP;
9673               END IF;
9674 
9675                 LOG_MESSAGES('INV_RULE rule lock status: '||l_return_status);
9676                 LOG_MESSAGES('INV_RULE rule lock failed;'||l_message);
9677                 l_status := 'ERROR';
9678                 RAISE G_EXCEPTION_HALT_VALIDATION;
9679             END IF;
9680 
9681 
9682 
9683    ELSIF l_criteria_rec.attribute = 'COV_TYPE' then
9684     l_klnv_tbl_type_in.DELETE;
9685        cnt := 1;
9686 
9687        FOR rec IN Get_cov_type(l_eligible_contracts_tbl(i).contract_id,l_eligible_contracts_tbl(i).old_value)
9688        LOOP
9689             l_klnv_tbl_type_in(cnt).id	   	                  := rec.id;
9690             l_klnv_tbl_type_in(cnt).object_version_number      := rec.object_version_number;
9691             l_klnv_tbl_type_in(cnt).coverage_type              := l_new_value_id;
9692             cnt := cnt + 1 ;
9693        END LOOP;
9694 	If l_klnv_tbl_type_in.count > 0 Then
9695                 OKS_CONTRACT_LINE_PUB.lock_line(
9696                                         p_api_version         => l_api_version,
9697                                         p_init_msg_list       => l_init_msg_list,
9698                                         x_return_status       => l_return_status,
9699                                         x_msg_count           => l_msg_count,
9700                                         x_msg_data            => l_msg_data,
9701                                         p_klnv_tbl            => l_klnv_tbl_type_in);
9702 
9703 
9704          IF l_return_status = G_RET_STS_SUCCESS THEN
9705 
9706                 OKS_CONTRACT_LINE_PUB.update_line(
9707                                         p_api_version         => l_api_version,
9708                                         p_init_msg_list       => l_init_msg_list,
9709                                         x_return_status       => l_return_status,
9710                                         x_msg_count           => l_msg_count,
9711                                         x_msg_data            => l_msg_data,
9712                                         p_klnv_tbl            => l_klnv_tbl_type_in,
9713                                         x_klnv_tbl            => l_klnv_tbl_type_out,
9714                                         p_validate_yn         => 'Y');
9715 
9716                  IF l_return_status = G_RET_STS_SUCCESS THEN
9717                         LOG_MESSAGES('COV_TYPE update status: '||l_return_status);
9718 
9719                  ELSE
9720                       IF l_msg_count > 0
9721                       THEN
9722                       FOR i in 1..l_msg_count
9723                       LOOP
9724                             fnd_msg_pub.get (p_msg_index     => -1,
9725                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9726                                              p_data          => l_msg_data,
9727                                              p_msg_index_out => l_msg_index_out);
9728 
9729                             l_message := l_message||' ; '||l_msg_data;
9730 
9731                       END LOOP;
9732                       END IF;
9733 
9734                         LOG_MESSAGES('COV_TYPE update status: '||l_return_status);
9735                         LOG_MESSAGES('COV_TYPE Update failed;'||l_message);
9736                         l_status := 'ERROR';
9737                         RAISE G_EXCEPTION_HALT_VALIDATION;
9738                     END IF;
9739 
9740           ELSE
9741               IF l_msg_count > 0
9742               THEN
9743               FOR i in 1..l_msg_count
9744               LOOP
9745                  fnd_msg_pub.get (p_msg_index     => -1,
9746                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9747                                   p_data          => l_msg_data,
9748                                   p_msg_index_out => l_msg_index_out);
9749                      l_message := l_message||' ; '||l_msg_data;
9750               END LOOP;
9751               END IF;
9752 
9753 
9754                 LOG_MESSAGES('COV_TYPE rule lock status: '||l_return_status);
9755                 LOG_MESSAGES('COV_TYPE rule lock failed;'||l_message);
9756                 l_status := 'ERROR';
9757                 RAISE G_EXCEPTION_HALT_VALIDATION;
9758             END IF;
9759 	End If;
9760    ELSIF l_criteria_rec.attribute = 'BP_PRICE_LIST' then
9761        l_clev_tbl_in.DELETE;
9762        l_clev_tbl_out.DELETE;
9763        cnt := 1;
9764 
9765        If l_new_value_id = '-9999' then
9766           l_new_value_id := Null;
9767        End If;
9768 
9769        If l_criteria_rec.old_value  = '-9999' then
9770            FOR rec IN get_bp_lines_null (l_eligible_contracts_tbl(i).contract_id)
9771            LOOP
9772                l_clev_tbl_in(cnt).id	   	          := rec.id;
9773                l_clev_tbl_in(cnt).object_version_number      := rec.object_version_number;
9774                l_clev_tbl_in(cnt).price_list_id              := l_new_value_id;
9775                cnt := cnt + 1 ;
9776            END LOOP;
9777        Elsif l_criteria_rec.old_value = '-1111' then
9778            FOR rec IN get_bp_lines_all (l_eligible_contracts_tbl(i).contract_id)
9779            LOOP
9780                l_clev_tbl_in(cnt).id	   	          := rec.id;
9781                l_clev_tbl_in(cnt).object_version_number      := rec.object_version_number;
9782                l_clev_tbl_in(cnt).price_list_id              := l_new_value_id;
9783                cnt := cnt + 1 ;
9784            END LOOP;
9785        Else
9786            FOR rec IN get_bp_lines (l_eligible_contracts_tbl(i).contract_id
9787                                    ,l_eligible_contracts_tbl(i).old_value)
9788            LOOP
9789                l_clev_tbl_in(cnt).id           	          := rec.id;
9790                l_clev_tbl_in(cnt).object_version_number      := rec.object_version_number;
9791                l_clev_tbl_in(cnt).price_list_id              := l_new_value_id;
9792                cnt := cnt + 1 ;
9793            END LOOP;
9794        End If;
9795 
9796 	If l_clev_tbl_in.count > 0 Then
9797                 OKC_CONTRACT_PUB.lock_contract_line(
9798                                 p_api_version      => l_api_version,
9799                                 p_init_msg_list    => l_init_msg_list,
9800                                 x_return_status    => l_return_status,
9801                                 x_msg_count        => l_msg_count,
9802                                 x_msg_data         => l_msg_data,
9803                                 p_clev_tbl         => l_clev_tbl_in);
9804 
9805          IF l_return_status = G_RET_STS_SUCCESS THEN
9806 
9807                  OKC_CONTRACT_PUB.update_contract_line(
9808                             	p_api_version		=> l_api_version,
9809                               	p_init_msg_list		=> l_init_msg_list,
9810                             	x_return_status		=> l_return_status,
9811                             	x_msg_count		=> l_msg_count,
9812                              	x_msg_data		=> l_msg_data,
9813                                 p_clev_tbl              => l_clev_tbl_in,
9814                                 x_clev_tbl              => l_clev_tbl_out);
9815 
9816                  IF l_return_status = G_RET_STS_SUCCESS THEN
9817                         LOG_MESSAGES('BP Price List update status: '||l_return_status);
9818 
9819                  ELSE
9820                       IF l_msg_count > 0
9821                       THEN
9822                       FOR i in 1..l_msg_count
9823                       LOOP
9824                             fnd_msg_pub.get (p_msg_index     => -1,
9825                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9826                                              p_data          => l_msg_data,
9827                                              p_msg_index_out => l_msg_index_out);
9828 
9829                             l_message := l_message||' ; '||l_msg_data;
9830 
9831                       END LOOP;
9832                       END IF;
9833 
9834                         LOG_MESSAGES('BP Price List update status: '||l_return_status);
9835                         LOG_MESSAGES('BP Price List Update failed;'||l_message);
9836                         l_status := 'ERROR';
9837                         RAISE G_EXCEPTION_HALT_VALIDATION;
9838                     END IF;
9839 
9840           ELSE
9841               IF l_msg_count > 0
9842               THEN
9843               FOR i in 1..l_msg_count
9844               LOOP
9845                  fnd_msg_pub.get (p_msg_index     => -1,
9846                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
9847                                   p_data          => l_msg_data,
9848                                   p_msg_index_out => l_msg_index_out);
9849                      l_message := l_message||' ; '||l_msg_data;
9850               END LOOP;
9851               END IF;
9852 
9853 
9854                 LOG_MESSAGES('BP Price List lock status: '||l_return_status);
9855                 LOG_MESSAGES('BP Price List lock failed;'||l_message);
9856                 l_status := 'ERROR';
9857                 RAISE G_EXCEPTION_HALT_VALIDATION;
9858             END IF;
9859 
9860 	End If;
9861       ELSIF l_criteria_rec.attribute = 'COV_TIMEZONE' then
9862          l_ctz_tblType_in.delete;
9863          l_ctz_tblType_out.delete;
9864          cnt := 1;
9865          FOR rec IN Get_timezone(l_eligible_contracts_tbl(i).contract_id , l_eligible_contracts_tbl(i).old_value)
9866          LOOP
9867             l_ctz_tblType_in(cnt).id		          := rec.id ;
9868             l_ctz_tblType_in(cnt).OBJECT_VERSION_NUMBER   := rec.OBJECT_VERSION_NUMBER;
9869             l_ctz_tblType_in(cnt).cle_id                  := rec.cle_id;
9870             l_ctz_tblType_in(cnt).timezone_id             := l_new_value_id;
9871 
9872             OKS_COVERAGES_PVT.CHECK_TimeZone_Exists
9873                                ( p_api_version            => l_api_version
9874                                  ,p_init_msg_list         => l_init_msg_list
9875                                  ,x_return_status         => l_return_status
9876                                  ,x_msg_count             => l_msg_count
9877                                  ,x_msg_data              => l_msg_data
9878                                  ,P_BP_Line_ID            => l_ctz_tblType_in(cnt).cle_id
9879                                  ,P_TimeZone_Id           => l_new_value_id
9880                                  ,x_TimeZone_Exists       => l_timezone_exists_YN );
9881 
9882             LOG_MESSAGES('Coverage Timezone Duplicate Check status: '||l_return_status);
9883             If l_return_status <> G_RET_STS_SUCCESS then
9884                 IF l_msg_count > 0 then
9885                     FOR i in 1..l_msg_count
9886                     LOOP
9887                         fnd_msg_pub.get (p_msg_index     => -1,
9888                                          p_encoded       => 'F',
9889                                          p_data          => l_msg_data,
9890                                          p_msg_index_out => l_msg_index_out);
9891                         l_message := l_message||' ; '||l_msg_data;
9892                     END LOOP;
9893                 END IF;
9894                 LOG_MESSAGES('Coverage Timezone Duplicate Check : '||l_return_status);
9895                 l_status := 'ERROR';
9896                 RAISE G_EXCEPTION_HALT_VALIDATION;
9897             Else
9898                 If l_timezone_exists_YN = 'N' then
9899                    cnt := cnt + 1;
9900                 Else
9901                    LOG_MESSAGES('Contract Number : '||l_eligible_contracts_tbl(i).contract_number);
9902                    LOG_MESSAGES('Timezone Exists for BP: '||to_char(l_ctz_tblType_in(cnt).cle_id));
9903                    l_message := l_message||' ; '||'Timezone already exists for the Contract Business Process';
9904                    l_status := 'ERROR';
9905                    RAISE G_EXCEPTION_HALT_VALIDATION;
9906                 End If;
9907             End If;
9908 
9909          END LOOP;
9910 
9911          If (l_ctz_tblType_in.count > 0) then
9912              OKS_CTZ_PVT.lock_row(
9913                                p_api_version                   => l_api_version,
9914                                p_init_msg_list                 => l_init_msg_list,
9915                                x_return_status                 => l_return_status,
9916                                x_msg_count                     => l_msg_count,
9917                                x_msg_data                      => l_msg_data,
9918                                p_oks_coverage_timezones_v_tbl  => l_ctz_tblType_in);
9919 
9920              IF l_return_status = G_RET_STS_SUCCESS THEN
9921 
9922               OKS_CTZ_PVT.update_row(
9923                                         p_api_version         => l_api_version,
9924                                         p_init_msg_list       => l_init_msg_list,
9925                                         x_return_status       => l_return_status,
9926                                         x_msg_count           => l_msg_count,
9927                                         x_msg_data            => l_msg_data,
9928                                         p_oks_coverage_timezones_v_tbl            => l_ctz_tblType_in,
9929                                         x_oks_coverage_timezones_v_tbl            => l_ctz_tblType_out);
9930 
9931 
9932                  IF l_return_status = G_RET_STS_SUCCESS THEN
9933                         LOG_MESSAGES('Coverage Timezone update status: '||l_return_status);
9934                  ELSE
9935                       IF l_msg_count > 0
9936                       THEN
9937                       FOR i in 1..l_msg_count
9938                       LOOP
9939                             fnd_msg_pub.get (p_msg_index     => -1,
9940                                              p_encoded       => 'F',
9941                                              p_data          => l_msg_data,
9942                                              p_msg_index_out => l_msg_index_out);
9943 
9944                             l_message := l_message||' ; '||l_msg_data;
9945 
9946                       END LOOP;
9947                       END IF;
9948                         LOG_MESSAGES('Coverage Timezone update status: '||l_return_status);
9949                         LOG_MESSAGES('Coverage Timezone Update failed;'||l_message);
9950                         l_status := 'ERROR';
9951                         RAISE G_EXCEPTION_HALT_VALIDATION;
9952                     END IF;
9953 
9954              ELSE
9955                  IF l_msg_count > 0
9956                  THEN
9957                  FOR i in 1..l_msg_count
9958                  LOOP
9959                     fnd_msg_pub.get (p_msg_index     => -1,
9960                                   p_encoded       => 'F',
9961                                   p_data          => l_msg_data,
9962                                   p_msg_index_out => l_msg_index_out);
9963                      l_message := l_message||' ; '||l_msg_data;
9964                  END LOOP;
9965                  END IF;
9966                   LOG_MESSAGES('Coverage Timezone lock status: '||l_return_status);
9967                   LOG_MESSAGES('Coverage Timezone lock failed;'||l_message);
9968                   l_status := 'ERROR';
9969                 RAISE G_EXCEPTION_HALT_VALIDATION;
9970             END IF;
9971         End If;
9972 
9973       ELSIF l_criteria_rec.attribute = 'PREF_ENGG' then
9974             l_ctcv_tbl_in.DELETE;
9975             l_ctcv_tbl_out.DELETE;
9976             cnt := 1;
9977 
9978             FOR pref_engg_rec IN  Get_contact(l_eligible_contracts_tbl(i).contract_id,'ENGINEER','OKX_RESOURCE',l_eligible_contracts_tbl(i).old_value)
9979        LOOP
9980             l_ctcv_tbl_in(cnt).id		                 := pref_engg_rec.id;
9981             l_ctcv_tbl_in(cnt).object_version_number      := pref_engg_rec.object_version_number;
9982             l_ctcv_tbl_in(cnt).object1_id1                := l_new_value_id;
9983             cnt := cnt + 1 ;
9984        END LOOP;
9985 	If l_ctcv_tbl_in.count > 0 Then
9986                    OKC_CTC_PVT.lock_row(
9987                                         p_api_version         => l_api_version,
9988                                         p_init_msg_list       => l_init_msg_list,
9989                                         x_return_status       => l_return_status,
9990                                         x_msg_count           => l_msg_count,
9991                                         x_msg_data            => l_msg_data,
9992                                         p_ctcv_tbl            => l_ctcv_tbl_in);
9993 
9994          IF l_return_status = G_RET_STS_SUCCESS THEN
9995 
9996 --         l_ctcv_rec_in.object1_id1  := l_new_value_id;
9997   --       l_return_status := NULL;
9998 
9999                  OKC_CTC_PVT.update_row(
10000                                         p_api_version         => l_api_version,
10001                                         p_init_msg_list       => l_init_msg_list,
10002                                         x_return_status       => l_return_status,
10003                                         x_msg_count           => l_msg_count,
10004                                         x_msg_data            => l_msg_data,
10005                                         p_ctcv_tbl            => l_ctcv_tbl_in,
10006                                         x_ctcv_tbl            => l_ctcv_tbl_out);
10007 
10008                  IF l_return_status = G_RET_STS_SUCCESS THEN
10009                         LOG_MESSAGES('PREF_ENGG update status: '||l_return_status);
10010 
10011                  ELSE
10012                       IF l_msg_count > 0
10013                       THEN
10014                       FOR i in 1..l_msg_count
10015                       LOOP
10016                             fnd_msg_pub.get (p_msg_index     => -1,
10017                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10018                                              p_data          => l_msg_data,
10019                                              p_msg_index_out => l_msg_index_out);
10020 
10021                             l_message := l_message||' ; '||l_msg_data;
10022 
10023                       END LOOP;
10024                       END IF;
10025 
10026                         LOG_MESSAGES('PREF_ENGG update status: '||l_return_status);
10027                         LOG_MESSAGES('PREF_ENGG Update failed;'||l_message);
10028                         l_status := 'ERROR';
10029 
10030                         RAISE G_EXCEPTION_HALT_VALIDATION;
10031                  END IF;
10032 
10033           ELSE
10034               IF l_msg_count > 0
10035               THEN
10036               FOR i in 1..l_msg_count
10037               LOOP
10038                  fnd_msg_pub.get (p_msg_index     => -1,
10039                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10040                                   p_data          => l_msg_data,
10041                                   p_msg_index_out => l_msg_index_out);
10042                      l_message := l_message||' ; '||l_msg_data;
10043               END LOOP;
10044               END IF;
10045 
10046                 LOG_MESSAGES('PREF_ENGG rule lock status: '||l_return_status);
10047                 LOG_MESSAGES('PREF_ENGG rule lock failed;'||l_message);
10048                 l_status := 'ERROR';
10049                 RAISE G_EXCEPTION_HALT_VALIDATION;
10050             END IF;
10051 	END IF;
10052       ELSIF l_criteria_rec.attribute = 'RES_GROUP' then
10053             l_ctcv_tbl_in.DELETE;
10054             l_ctcv_tbl_out.DELETE;
10055             cnt := 1;
10056 
10057 
10058             FOR res_group_rec IN  Get_contact(l_eligible_contracts_tbl(i).contract_id,'RSC_GROUP','OKS_RSCGROUP',l_eligible_contracts_tbl(i).old_value)
10059        LOOP
10060             l_ctcv_tbl_in(cnt).id		                 := res_group_rec.id;
10061             l_ctcv_tbl_in(cnt).object_version_number      := res_group_rec.object_version_number;
10062             l_ctcv_tbl_in(cnt).object1_id1                := l_new_value_id;
10063             cnt := cnt + 1 ;
10064        END LOOP;
10065 	If l_ctcv_tbl_in.count > 0 Then
10066                    OKC_CTC_PVT.lock_row(
10067                                         p_api_version         => l_api_version,
10068                                         p_init_msg_list       => l_init_msg_list,
10069                                         x_return_status       => l_return_status,
10070                                         x_msg_count           => l_msg_count,
10071                                         x_msg_data            => l_msg_data,
10072                                         p_ctcv_tbl            => l_ctcv_tbl_in);
10073 
10074          IF l_return_status = G_RET_STS_SUCCESS THEN
10075 
10076                  OKC_CTC_PVT.update_row(
10077                                         p_api_version         => l_api_version,
10078                                         p_init_msg_list       => l_init_msg_list,
10079                                         x_return_status       => l_return_status,
10080                                         x_msg_count           => l_msg_count,
10081                                         x_msg_data            => l_msg_data,
10082                                         p_ctcv_tbl            => l_ctcv_tbl_in,
10083                                         x_ctcv_tbl            => l_ctcv_tbl_out);
10084 
10085                  IF l_return_status = G_RET_STS_SUCCESS THEN
10086                         LOG_MESSAGES('RES_GROUP update status: '||l_return_status);
10087 
10088                  ELSE
10089                       IF l_msg_count > 0
10090                       THEN
10091                       FOR i in 1..l_msg_count
10092                       LOOP
10093                             fnd_msg_pub.get (p_msg_index     => -1,
10094                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10095                                              p_data          => l_msg_data,
10096                                              p_msg_index_out => l_msg_index_out);
10097 
10098                             l_message := l_message||' ; '||l_msg_data;
10099 
10100                       END LOOP;
10101                       END IF;
10102 
10103                         LOG_MESSAGES('RES_GROUP update status: '||l_return_status);
10104                         LOG_MESSAGES('RES_GROUP Update failed;'||l_message);
10105                         l_status := 'ERROR';
10106 
10107                         RAISE G_EXCEPTION_HALT_VALIDATION;
10108                  END IF;
10109 
10110           ELSE
10111               IF l_msg_count > 0
10112               THEN
10113               FOR i in 1..l_msg_count
10114               LOOP
10115                  fnd_msg_pub.get (p_msg_index     => -1,
10116                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10117                                   p_data          => l_msg_data,
10118                                   p_msg_index_out => l_msg_index_out);
10119                      l_message := l_message||' ; '||l_msg_data;
10120               END LOOP;
10121               END IF;
10122 
10123                 LOG_MESSAGES('RES_GROUP rule lock status: '||l_return_status);
10124                 LOG_MESSAGES('RES_GROUP rule lock failed;'||l_message);
10125                 l_status := 'ERROR';
10126                 RAISE G_EXCEPTION_HALT_VALIDATION;
10127             END IF;
10128 
10129 	End If;
10130       ELSIF l_criteria_rec.attribute = 'AGREEMENT_NAME' then
10131        l_gvev_tbl_in.DELETE;
10132        l_gvev_tbl_out.DELETE;
10133        cnt := 1;
10134 
10135        FOR rule_rec IN Get_agreement_name(l_eligible_contracts_tbl(i).contract_id,l_eligible_contracts_tbl(i).old_value)
10136        LOOP
10137             l_gvev_tbl_in(cnt).id	   	                  := rule_rec.id;
10138             l_gvev_tbl_in(cnt).object_version_number      := rule_rec.object_version_number;
10139             l_gvev_tbl_in(cnt).isa_agreement_id           := l_new_value_id;
10140             cnt := cnt + 1 ;
10141        END LOOP;
10142 	If l_gvev_tbl_in.count > 0 Then
10143                 OKC_GVE_PVT.lock_row(
10144                                         p_api_version         => l_api_version,
10145                                         p_init_msg_list       => l_init_msg_list,
10146                                         x_return_status       => l_return_status,
10147                                         x_msg_count           => l_msg_count,
10148                                         x_msg_data            => l_msg_data,
10149                                         p_gvev_tbl            => l_gvev_tbl_in);
10150 
10151          IF l_return_status = G_RET_STS_SUCCESS THEN
10152 
10153                 OKC_GVE_PVT.update_row(
10154                                         p_api_version         => l_api_version,
10155                                         p_init_msg_list       => l_init_msg_list,
10156                                         x_return_status       => l_return_status,
10157                                         x_msg_count           => l_msg_count,
10158                                         x_msg_data            => l_msg_data,
10159                                         p_gvev_tbl            => l_gvev_tbl_in,
10160                                         x_gvev_tbl            => l_gvev_tbl_out);
10161 
10162                  IF l_return_status = G_RET_STS_SUCCESS THEN
10163                         LOG_MESSAGES('AGREEMENT_NAME update status: '||l_return_status);
10164 
10165                  ELSE
10166                       IF l_msg_count > 0
10167                       THEN
10168                       FOR i in 1..l_msg_count
10169                       LOOP
10170                             fnd_msg_pub.get (p_msg_index     => -1,
10171                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10172                                              p_data          => l_msg_data,
10173                                              p_msg_index_out => l_msg_index_out);
10174 
10175                             l_message := l_message||' ; '||l_msg_data;
10176 
10177                       END LOOP;
10178                       END IF;
10179 
10180                         LOG_MESSAGES('AGREEMENT_NAME update status: '||l_return_status);
10181                         LOG_MESSAGES('AGREEMENT_NAME Update failed;'||l_message);
10182                         l_status := 'ERROR';
10183                         RAISE G_EXCEPTION_HALT_VALIDATION;
10184                     END IF;
10185 
10186           ELSE
10187               IF l_msg_count > 0
10188               THEN
10189               FOR i in 1..l_msg_count
10190               LOOP
10191                  fnd_msg_pub.get (p_msg_index     => -1,
10192                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10193                                   p_data          => l_msg_data,
10194                                   p_msg_index_out => l_msg_index_out);
10195                      l_message := l_message||' ; '||l_msg_data;
10196               END LOOP;
10197               END IF;
10198 
10199 
10200                 LOG_MESSAGES('AGREEMENT_NAME rule lock status: '||l_return_status);
10201                 LOG_MESSAGES('AGREEMENT_NAME lock failed;'||l_message);
10202                 l_status := 'ERROR';
10203                 RAISE G_EXCEPTION_HALT_VALIDATION;
10204             END IF;
10205 
10206 	END IF;
10207 
10208 
10209       ELSIF l_criteria_rec.attribute = 'HDR_BILL_TO_ADDRESS' then
10210 
10211             l_chrv_rec_in.id		             := l_eligible_contracts_tbl(i).contract_id ;
10212             l_chrv_rec_in.object_version_number  := l_eligible_contracts_tbl(i).object_version_number;
10213 
10214             OKC_CONTRACT_PUB.lock_contract_header(
10215                                         p_api_version         => l_api_version,
10216                                         p_init_msg_list       => l_init_msg_list,
10217                                         x_return_status       => l_return_status,
10218                                         x_msg_count           => l_msg_count,
10219                                         x_msg_data            => l_msg_data,
10220                                         p_chrv_rec            => l_chrv_rec_in);
10221 
10222 
10223          IF l_return_status = G_RET_STS_SUCCESS THEN
10224 
10225          l_chrv_rec_in.bill_to_site_use_id  := l_new_value_id;
10226 
10227               OKC_CONTRACT_PUB.update_contract_header(
10228                                         p_api_version         => l_api_version,
10229                                         p_init_msg_list       => l_init_msg_list,
10230                                         x_return_status       => l_return_status,
10231                                         x_msg_count           => l_msg_count,
10232                                         x_msg_data            => l_msg_data,
10233                                         p_restricted_update   => 'F' ,
10234                                         p_chrv_rec            => l_chrv_rec_in,
10235                                         x_chrv_rec            => l_chrv_rec_out);
10236 
10237                  IF l_return_status = G_RET_STS_SUCCESS THEN
10238                         LOG_MESSAGES('BILL_TO_ADDRESS update status: '||l_return_status);
10239 
10240                  ELSE
10241                       IF l_msg_count > 0
10242                       THEN
10243                       FOR i in 1..l_msg_count
10244                       LOOP
10245                             fnd_msg_pub.get (p_msg_index     => -1,
10246                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10247                                              p_data          => l_msg_data,
10248                                              p_msg_index_out => l_msg_index_out);
10249 
10250                             l_message := l_message||' ; '||l_msg_data;
10251 
10252                       END LOOP;
10253                       END IF;
10254 
10255                         LOG_MESSAGES('BILL_TO_ADDRESS update status: '||l_return_status);
10256                         LOG_MESSAGES('Bill-To Address Update failed;'||l_message);
10257                         l_status := 'ERROR';
10258                         RAISE G_EXCEPTION_HALT_VALIDATION;
10259                     END IF;
10260 
10261           ELSE
10262               IF l_msg_count > 0
10263               THEN
10264               FOR i in 1..l_msg_count
10265               LOOP
10266                  fnd_msg_pub.get (p_msg_index     => -1,
10267                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10268                                   p_data          => l_msg_data,
10269                                   p_msg_index_out => l_msg_index_out);
10270                      l_message := l_message||' ; '||l_msg_data;
10271               END LOOP;
10272               END IF;
10273 
10274                 LOG_MESSAGES('BILL_TO_ADDRESS rule lock status: '||l_return_status);
10275                 LOG_MESSAGES('BILL_TO_ADDRESS rule lock failed;'||l_message);
10276                 l_status := 'ERROR';
10277                 RAISE G_EXCEPTION_HALT_VALIDATION;
10278             END IF;
10279 
10280 
10281       ELSIF l_criteria_rec.attribute = 'PRICE_LIST' then
10282 
10283 	       l_currency_code      := NULL;
10284 	       l_pricelist_valid    := NULL ;
10285 
10286             l_chrv_rec_in.id                     := l_eligible_contracts_tbl(i).contract_id ;
10287             l_chrv_rec_in.object_version_number  := l_eligible_contracts_tbl(i).object_version_number;
10288 
10289             Open get_contract_dtls (l_eligible_contracts_tbl(i).contract_id);
10290 		      Fetch get_contract_dtls  into l_currency_code ;
10291             Close get_contract_dtls;
10292 
10293             LOG_MESSAGES('Price List ID:  '||l_new_value_id);
10294             LOG_MESSAGES('Currency Code:  '||l_currency_code);
10295             QP_UTIL_PUB.Validate_Price_list_Curr_code
10296                                   ( l_price_list_id           => to_number(l_new_value_id)
10297                                    ,l_currency_code           => l_currency_code
10298 	                              ,l_pricing_effective_date  => sysdate
10299 		                         ,l_validate_result         => l_pricelist_valid );
10300 
10301             LOG_MESSAGES('Is PL Valid?:  '||l_pricelist_valid);
10302 
10303             If nvl(l_pricelist_valid,'N') <> 'Y' then
10304                  LOG_MESSAGES('After pricelist validity check; Price List is invalid ');
10305                  l_status   := 'ERROR';
10306 	         l_message  := FND_MESSAGE.get_string('OKS','OKS_INVALID_PRICE_LIST') ;
10307                  RAISE G_EXCEPTION_HALT_VALIDATION;
10308             End If;
10309 
10310             OKC_CONTRACT_PUB.lock_contract_header(
10311                                         p_api_version         => l_api_version,
10312                                         p_init_msg_list       => l_init_msg_list,
10313                                         x_return_status       => l_return_status,
10314                                         x_msg_count           => l_msg_count,
10315                                         x_msg_data            => l_msg_data,
10316                                         p_chrv_rec            => l_chrv_rec_in);
10317 
10318 
10319          IF l_return_status = G_RET_STS_SUCCESS THEN
10320 
10321 --         l_chrv_rec_in.bill_to_site_use_id  := l_new_value_id;
10322          l_chrv_rec_in.price_list_id  := to_number(l_new_value_id);
10323 
10324               OKC_CONTRACT_PUB.update_contract_header(
10325                                         p_api_version         => l_api_version,
10326                                         p_init_msg_list       => l_init_msg_list,
10327                                         x_return_status       => l_return_status,
10328                                         x_msg_count           => l_msg_count,
10329                                         x_msg_data            => l_msg_data,
10330                                         p_restricted_update   => 'F' ,
10331                                         p_chrv_rec            => l_chrv_rec_in,
10332                                         x_chrv_rec            => l_chrv_rec_out);
10333 
10334                  IF l_return_status = G_RET_STS_SUCCESS THEN
10335                         LOG_MESSAGES('PRICE_LIST update status: '||l_return_status);
10336                         l_old_k_amount := Get_contract_amount(l_eligible_contracts_tbl(i).contract_id);
10337                                           LOG_MESSAGES('After Get_contract_amount');
10338                         OKS_REPRICE_PVT.Call_Pricing_Api(
10339                                         p_api_version         => l_api_version,
10340                                         p_init_msg_list       => l_init_msg_list,
10341                                         P_id        		  => l_eligible_contracts_tbl(i).contract_id,
10342 				                    P_Id_Type		      => 'CHR',
10343                                         x_return_status       => l_return_status,
10344                                         x_msg_count           => l_msg_count,
10345                                         x_msg_data            => l_msg_data);
10346 
10347               IF  l_return_status = G_RET_STS_SUCCESS THEN
10348                 LOG_MESSAGES('PRICE_LIST Repricing status for lines: '||l_return_status);
10349                 FOR rec IN Get_cle_id(l_eligible_contracts_tbl(i).contract_id)
10350                 LOOP
10351                     LOG_MESSAGES('Inside Loop for PRICE_LIST');
10352                     OKS_BILL_SCH.Cascade_Dates_SLL (rec.id,l_return_status,l_msg_count,l_msg_data) ;
10353                     IF l_return_status = G_RET_STS_SUCCESS THEN
10354                        LOG_MESSAGES('CONTRACT_HEADER(Price List) Billing Schedule status for lines: '||l_return_status);
10355                     ELSE
10356                         IF l_msg_count > 0
10357                         THEN
10358                         FOR i in 1..l_msg_count
10359                         LOOP
10360                             fnd_msg_pub.get (p_msg_index     => -1,
10361                                              p_encoded       => 'F',
10362                                              p_data          => l_msg_data,
10363                                              p_msg_index_out => l_msg_index_out);
10364                             l_message := l_message||' ; '||l_msg_data;
10365                         END LOOP;
10366                         END IF;
10367 
10368                     LOG_MESSAGES('Price List Billing Schedule status: '||l_return_status);
10369                     LOG_MESSAGES('Price List Billing Schedule failed;'||l_message);
10370                     l_status := 'ERROR';
10371                     RAISE G_EXCEPTION_HALT_VALIDATION;
10372                     END IF;
10373                 END LOOP ;
10374               END IF ;
10375 
10376                 l_new_k_amount := Get_contract_amount(l_eligible_contracts_tbl(i).contract_id);
10377                 l_amt_message := rpad(' ',30,' ')||'Old Contract Amount: '||rpad(l_old_k_amount,20,' ')||'New Contract Amount: '||rpad(l_new_k_amount,20,' ');
10378                     IF l_return_status = G_RET_STS_SUCCESS THEN
10379                          LOG_MESSAGES('PRICE_LIST Repricing status: '||l_return_status);
10380                     ELSE
10381                         IF l_msg_count > 0
10382                         THEN
10383                         FOR i in 1..l_msg_count
10384                         LOOP
10385                             fnd_msg_pub.get (p_msg_index     => -1,
10386                                              p_encoded       => 'F',
10387                                              p_data          => l_msg_data,
10388                                              p_msg_index_out => l_msg_index_out);
10389                             l_message := l_message||' ; '||l_msg_data;
10390                         END LOOP;
10391                         END IF;
10392 
10393                         LOG_MESSAGES('PRICE_LIST Repricing status: '||l_return_status);
10394                         LOG_MESSAGES('PRICE_LIST Repricing  failed;'||l_message);
10395                         l_status := 'ERROR';
10396                         RAISE G_EXCEPTION_HALT_VALIDATION;
10397                     END IF;
10398                  ELSE
10399                       IF l_msg_count > 0
10400                       THEN
10401                       FOR i in 1..l_msg_count
10402                       LOOP
10403                             fnd_msg_pub.get (p_msg_index     => -1,
10404                                              p_encoded       => 'F',
10405                                              p_data          => l_msg_data,
10406                                              p_msg_index_out => l_msg_index_out);
10407 
10408                             l_message := l_message||' ; '||l_msg_data;
10409 
10410                        END LOOP;
10411                        END IF;
10412 
10413                         LOG_MESSAGES('PRICE_LIST update status: '||l_return_status);
10414                         LOG_MESSAGES('Price List Update failed;'||l_message);
10415                         l_status := 'ERROR';
10416                         RAISE G_EXCEPTION_HALT_VALIDATION;
10417                     END IF;
10418 
10419           ELSE
10420               IF l_msg_count > 0
10421               THEN
10422               FOR i in 1..l_msg_count
10423               LOOP
10424                  fnd_msg_pub.get (p_msg_index     => -1,
10425                                   p_encoded       => 'F',
10426                                   p_data          => l_msg_data,
10427                                   p_msg_index_out => l_msg_index_out);
10428                      l_message := l_message||' ; '||l_msg_data;
10429               END LOOP;
10430               END IF;
10431 
10432                 LOG_MESSAGES('PRICE_LIST rule lock status: '||l_return_status);
10433                 LOG_MESSAGES('PRICE _LIST rule lock failed;'||l_message);
10434                 l_status := 'ERROR';
10435                 RAISE G_EXCEPTION_HALT_VALIDATION;
10436             END IF;
10437 
10438       ELSIF l_criteria_rec.attribute = 'COVERAGE_START_TIME' then
10439 
10440             l_cvt_tbl_in.DELETE;
10441             l_cvt_tbl_out.DELETE;
10442             cvr_cnt := 1;
10443 
10444             l_hour   := trunc(to_number(l_eligible_contracts_tbl(i).old_value)/60);
10445             l_minute := mod(to_number(l_eligible_contracts_tbl(i).old_value),60);
10446        FOR cvr_rec IN Get_cvr_start(l_eligible_contracts_tbl(i).contract_id,l_hour, l_minute)
10447        LOOP
10448 
10449            IF trunc(to_number(l_new_value_id)/60) > cvr_rec.end_hour THEN
10450               l_cov_time_wrong := l_cov_time_wrong + 1;
10451 
10452            ELSIF trunc(to_number(l_new_value_id)/60) = cvr_rec.end_hour AND
10453                  mod(to_number(l_new_value_id),60) >= cvr_rec.end_minute THEN
10454                  l_cov_time_wrong := l_cov_time_wrong + 1;
10455 
10456            ELSE
10457                l_cov_time_right := l_cov_time_right + 1 ;
10458                l_cvt_tbl_in(cnt).id     := cvr_rec.ID;
10459                l_cvt_tbl_in(cnt).OBJECT_VERSION_NUMBER     := cvr_rec.OBJECT_VERSION_NUMBER;
10460                l_cvt_tbl_in(cnt).start_hour   := trunc(to_number(l_new_value_id)/60);
10461                l_cvt_tbl_in(cnt).start_minute := mod(to_number(l_new_value_id),60);
10462                cnt := cnt + 1;
10463            END IF ;
10464        END LOOP;
10465 	 If l_cvt_tbl_in.count > 0 Then
10466               OKS_CVT_PVT.lock_row(     p_api_version         => l_api_version,
10467                                         p_init_msg_list       => l_init_msg_list,
10468                                         x_return_status       => l_return_status,
10469                                         x_msg_count           => l_msg_count,
10470                                         x_msg_data            => l_msg_data,
10471                                         p_oks_coverage_times_v_tbl	      => l_cvt_tbl_in);
10472 
10473 
10474          IF l_return_status = G_RET_STS_SUCCESS THEN
10475 
10476             OKS_CVT_PVT.update_row(     p_api_version                  => l_api_version,
10477                                         p_init_msg_list                => l_init_msg_list,
10478                                         x_return_status                => l_return_status,
10479                                         x_msg_count                    => l_msg_count,
10480                                         x_msg_data                     => l_msg_data,
10481                                         p_oks_coverage_times_v_tbl     => l_cvt_tbl_in,
10482                                         x_oks_coverage_times_v_tbl     => l_cvt_tbl_out);
10483 
10484 
10485                 IF  l_return_status = G_RET_STS_SUCCESS THEN
10486 
10487                     LOG_MESSAGES('COVERAGE_START_TIME update status: '||l_return_status);
10488 
10489                     -- Check for coverage time over lap
10490                     l_overlap_type := Null;
10491                     For tz_rec IN  Get_cvr_timezone(l_eligible_contracts_tbl(i).contract_id)
10492                     Loop
10493                         l_time_zone_id := tz_rec.ID;
10494                         OKS_COVERAGES_PVT.VALIDATE_COVERTIME(
10495                                     p_tze_line_id      => l_time_zone_id,
10496                                     x_days_overlap     => l_overlap_type,
10497                                     x_return_status    => l_return_status);
10498                         If l_return_status = G_RET_STS_SUCCESS Then
10499                              If (l_overlap_type.monday_overlap      = 'Y' OR
10500                                  l_overlap_type.tuesday_overlap     = 'Y' OR
10501                                  l_overlap_type.wednesday_overlap   = 'Y' OR
10502                                  l_overlap_type.thursday_overlap    = 'Y' OR
10503                                  l_overlap_type.friday_overlap      = 'Y' OR
10504                                  l_overlap_type.saturday_overlap    = 'Y' OR
10505                                  l_overlap_type.sunday_overlap      = 'Y'  ) Then
10506 
10507                                      l_status  := 'ERROR';
10508                                      l_message := l_message|| ' Covered time overlaps ';
10509                                      LOG_MESSAGES('COVERAGE_START_TIME Overlaps ');
10510                                      RAISE G_EXCEPTION_HALT_VALIDATION;
10511                              End If;
10512                         Else
10513                             If l_msg_count > 0 Then
10514                                FOR i in 1..l_msg_count
10515                                LOOP
10516                                   fnd_msg_pub.get (p_msg_index     => -1,
10517                                              p_encoded       => 'F',
10518                                              p_data          => l_msg_data,
10519                                              p_msg_index_out => l_msg_index_out);
10520                                              l_message := l_message||' ; '||l_msg_data;
10521                                 END LOOP;
10522                              End If; -- message count
10523 
10524                              LOG_MESSAGES('Coverage Start Time Update failed;'||l_message);
10525                              l_status := 'ERROR';
10526                              RAISE G_EXCEPTION_HALT_VALIDATION;
10527                         End If; -- validate cover time retunr status
10528                     End Loop ;
10529                 ELSE
10530                     IF l_msg_count > 0
10531                     THEN
10532                     FOR i in 1..l_msg_count
10533                     LOOP
10534                         fnd_msg_pub.get (p_msg_index     => -1,
10535                                          p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10536                                          p_data          => l_msg_data,
10537                                          p_msg_index_out => l_msg_index_out);
10538                         l_message := l_message||' ; '||l_msg_data;
10539                     END LOOP;
10540                     END IF;
10541                     LOG_MESSAGES('COVERAGE_START_TIME update status: '||l_return_status);
10542                     LOG_MESSAGES('Coverage Start Time Update failed;'||l_message);
10543                     l_status := 'ERROR';
10544                     RAISE G_EXCEPTION_HALT_VALIDATION;
10545                  END IF;
10546 
10547             ELSE
10548                      IF l_msg_count > 0
10549                      THEN
10550                         FOR i in 1..l_msg_count
10551                         LOOP
10552                             fnd_msg_pub.get (p_msg_index     => -1,
10553                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10554                                              p_data          => l_msg_data,
10555                                              p_msg_index_out => l_msg_index_out);
10556                             l_message := l_message||' ; '||l_msg_data;
10557                         END LOOP;
10558                       END IF;
10559 
10560                         LOG_MESSAGES('COVERAGE_START_TIME status: '||l_return_status);
10561                         LOG_MESSAGES('COVERAGE_START_TIME failed;'||l_message);
10562                         l_status := 'ERROR';
10563                         RAISE G_EXCEPTION_HALT_VALIDATION;
10564             END IF;
10565 
10566 	End If;
10567 
10568    ELSIF l_criteria_rec.attribute = 'COVERAGE_END_TIME' then
10569           cnt := 1;
10570           l_cvt_tbl_in.DELETE;
10571           l_cvt_tbl_out.DELETE;
10572 
10573           l_hour   := trunc(to_number(l_eligible_contracts_tbl(i).old_value)/60);
10574           l_minute := mod(to_number(l_eligible_contracts_tbl(i).old_value),60);
10575        FOR cvr_rec IN Get_cvr_end(l_eligible_contracts_tbl(i).contract_id,l_hour, l_minute)
10576        LOOP
10577            IF    trunc(to_number(l_new_value_id)/60) < cvr_rec.start_hour THEN
10578                  l_cov_time_wrong := l_cov_time_wrong + 1;
10579 
10580            ELSIF trunc(to_number(l_new_value_id)/60) = cvr_rec.start_hour AND
10581                  mod(to_number(l_new_value_id),60) <= cvr_rec.start_minute THEN
10582                  l_cov_time_wrong := l_cov_time_wrong + 1;
10583            ELSE
10584                  l_cov_time_right := l_cov_time_right + 1 ;
10585                  l_cvt_tbl_in(cnt).id     := cvr_rec.ID;
10586                  l_cvt_tbl_in(cnt).OBJECT_VERSION_NUMBER     := cvr_rec.OBJECT_VERSION_NUMBER;
10587                  l_cvt_tbl_in(cnt).end_hour   := trunc(to_number(l_new_value_id)/60);
10588                  l_cvt_tbl_in(cnt).end_minute := mod(to_number(l_new_value_id),60);
10589                  cnt := cnt + 1;
10590            END IF ;
10591        END LOOP;
10592 	If l_cvt_tbl_in.count > 0 Then
10593 
10594               OKS_CVT_PVT.lock_row(     p_api_version         => l_api_version,
10595                                         p_init_msg_list       => l_init_msg_list,
10596                                         x_return_status       => l_return_status,
10597                                         x_msg_count           => l_msg_count,
10598                                         x_msg_data            => l_msg_data,
10599                                         p_oks_coverage_times_v_tbl	      => l_cvt_tbl_in);
10600 
10601 
10602          IF l_return_status = G_RET_STS_SUCCESS THEN
10603 
10604             OKS_CVT_PVT.update_row(     p_api_version         => l_api_version,
10605                                         p_init_msg_list       => l_init_msg_list,
10606                                         x_return_status       => l_return_status,
10607                                         x_msg_count           => l_msg_count,
10608                                         x_msg_data            => l_msg_data,
10609                                         p_oks_coverage_times_v_tbl	      => l_cvt_tbl_in,
10610                                         x_oks_coverage_times_v_tbl        => l_cvt_tbl_out);
10611 
10612 
10613                 IF  l_return_status = G_RET_STS_SUCCESS THEN
10614                     LOG_MESSAGES('COVERAGE_END_TIME update status: '||l_return_status);
10615                     -- Check for coverage time overlap
10616                     l_overlap_type := Null;
10617                     For tz_rec IN  Get_cvr_timezone(l_eligible_contracts_tbl(i).contract_id)
10618                     Loop
10619                         l_time_zone_id := tz_rec.ID;
10620                         OKS_COVERAGES_PVT.VALIDATE_COVERTIME(
10621                                     p_tze_line_id      => l_time_zone_id,
10622                                     x_days_overlap     => l_overlap_type,
10623                                     x_return_status    => l_return_status);
10624                         If l_return_status = G_RET_STS_SUCCESS Then
10625                              If (l_overlap_type.monday_overlap      = 'Y' OR
10626                                  l_overlap_type.tuesday_overlap     = 'Y' OR
10627                                  l_overlap_type.wednesday_overlap   = 'Y' OR
10628                                  l_overlap_type.thursday_overlap    = 'Y' OR
10629                                  l_overlap_type.friday_overlap      = 'Y' OR
10630                                  l_overlap_type.saturday_overlap    = 'Y' OR
10631                                  l_overlap_type.sunday_overlap      = 'Y'  ) Then
10632 
10633                                      l_status  := 'ERROR';
10634                                      l_message := l_message|| ' Covered time overlaps ';
10635                                      LOG_MESSAGES('COVERAGE End Time Overlaps ');
10636                                      RAISE G_EXCEPTION_HALT_VALIDATION;
10637                              End If;
10638                         Else
10639                             If l_msg_count > 0 Then
10640                                FOR i in 1..l_msg_count
10641                                LOOP
10642                                   fnd_msg_pub.get (p_msg_index     => -1,
10643                                              p_encoded       => 'F',
10644                                              p_data          => l_msg_data,
10645                                              p_msg_index_out => l_msg_index_out);
10646                                              l_message := l_message||' ; '||l_msg_data;
10647                                 END LOOP;
10648                              End If; -- message count
10649 
10650                              LOG_MESSAGES('Coverage End Time Update failed;'||l_message);
10651                              l_status := 'ERROR';
10652                              RAISE G_EXCEPTION_HALT_VALIDATION;
10653                         End If; -- validate cover time retunr status
10654                     End Loop ;
10655                 ELSE
10656                     IF l_msg_count > 0
10657                     THEN
10658                     FOR i in 1..l_msg_count
10659                     LOOP
10660                         fnd_msg_pub.get (p_msg_index     => -1,
10661                                          p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10662                                          p_data          => l_msg_data,
10663                                          p_msg_index_out => l_msg_index_out);
10664                         l_message := l_message||' ; '||l_msg_data;
10665                     END LOOP;
10666                     END IF;
10667                     LOG_MESSAGES('COVERAGE_END_TIME update status: '||l_return_status);
10668                     LOG_MESSAGES('Coverage End Time Update failed;'||l_message);
10669                     l_status := 'ERROR';
10670                     RAISE G_EXCEPTION_HALT_VALIDATION;
10671                  END IF;
10672 
10673             ELSE
10674                      IF l_msg_count > 0
10675                      THEN
10676                         FOR i in 1..l_msg_count
10677                         LOOP
10678                             fnd_msg_pub.get (p_msg_index     => -1,
10679                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10680                                              p_data          => l_msg_data,
10681                                              p_msg_index_out => l_msg_index_out);
10682                             l_message := l_message||' ; '||l_msg_data;
10683                         END LOOP;
10684                       END IF;
10685 
10686                         LOG_MESSAGES('COVERAGE_END_TIME status: '||l_return_status);
10687                         LOG_MESSAGES('COVERAGE_END_TIME failed;'||l_message);
10688                         l_status := 'ERROR';
10689                         RAISE G_EXCEPTION_HALT_VALIDATION;
10690             END IF;
10691 	END IF;
10692      ELSIF l_criteria_rec.attribute = 'REACTION_TIME' then
10693 
10694 
10695       LOG_MESSAGES('Inside Reaction time '||l_return_status);
10696 
10697         l_act_tbl_in.delete;
10698         l_act_tbl_out.delete;
10699         cnt := 1;
10700         FOR rec IN Get_act_time(l_eligible_contracts_tbl(i).contract_id,'RCN',l_old_value_id )
10701         LOOP
10702             l_act_tbl_in(cnt).id                        := rec.id;
10703             l_act_tbl_in(cnt).object_version_number     := rec.object_version_number;
10704 
10705             If    rec.sun_duration = l_old_value_id then
10706                   l_act_tbl_in(cnt).sun_duration              := l_new_value_id ;
10707             End If;
10708             If rec.mon_duration = l_old_value_id then
10709                   l_act_tbl_in(cnt).mon_duration              := l_new_value_id;
10710             End If;
10711             If rec.tue_duration = l_old_value_id then
10712                   l_act_tbl_in(cnt).tue_duration              := l_new_value_id;
10713             End If;
10714             If rec.wed_duration = l_old_value_id then
10715                   l_act_tbl_in(cnt).wed_duration              := l_new_value_id;
10716             End If;
10717             If rec.thu_duration = l_old_value_id then
10718                   l_act_tbl_in(cnt).thu_duration              := l_new_value_id;
10719             End If;
10720             If rec.fri_duration = l_old_value_id then
10721                   l_act_tbl_in(cnt).fri_duration              := l_new_value_id;
10722             End If;
10723             If rec.sat_duration = l_old_value_id then
10724                   l_act_tbl_in(cnt).sat_duration              := l_new_value_id;
10725             End If;
10726 
10727             cnt := cnt + 1;
10728 
10729         END LOOP;
10730 	If l_act_tbl_in.count > 0 Then
10731         LOG_MESSAGES('Out side loop  Reaction time '||l_return_status);
10732 
10733          OKS_ACM_PVT.lock_row (
10734                         	p_api_version		=> l_api_version,
10735                           	p_init_msg_list		=> l_init_msg_list,
10736                         	x_return_status		=> l_return_status,
10737                         	x_msg_count			=> l_msg_count,
10738                          	x_msg_data			=> l_msg_data,
10739                            	p_oks_action_times_v_tbl			=> l_act_tbl_in);
10740 
10741 
10742 
10743 
10744          IF l_return_status = G_RET_STS_SUCCESS THEN
10745 
10746             OKS_ACM_PVT.update_row (
10747                         	p_api_version		=> l_api_version,
10748                           	p_init_msg_list		=> l_init_msg_list,
10749                         	x_return_status		=> l_return_status,
10750                         	x_msg_count			=> l_msg_count,
10751                          	x_msg_data			=> l_msg_data,
10752                         	p_oks_action_times_v_tbl		    => l_act_tbl_in,
10753     	                    x_oks_action_times_v_tbl		    => l_act_tbl_out );
10754 
10755 
10756            IF l_return_status = G_RET_STS_SUCCESS THEN
10757                      LOG_MESSAGES('Reaction update status: '||l_return_status);
10758            ELSE
10759                   IF l_msg_count > 0
10760                   THEN
10761                   FOR i in 1..l_msg_count
10762                   LOOP
10763                     fnd_msg_pub.get (p_msg_index     => -1,
10764                                      p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10765                                      p_data          => l_msg_data,
10766                                      p_msg_index_out => l_msg_index_out);
10767                      l_message := l_message||' ; '||l_msg_data;
10768                   END LOOP;
10769                   END IF;
10770 
10771                 LOG_MESSAGES('Reaction Time update status: '||l_return_status);
10772                 LOG_MESSAGES('Reaction Time Update failed;'||l_message);
10773                 l_status := 'ERROR';
10774                 RAISE G_EXCEPTION_HALT_VALIDATION;
10775              END IF;
10776          ELSE
10777               IF l_msg_count > 0
10778               THEN
10779               FOR i in 1..l_msg_count
10780               LOOP
10781                  fnd_msg_pub.get (p_msg_index     => -1,
10782                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10783                                   p_data          => l_msg_data,
10784                                   p_msg_index_out => l_msg_index_out);
10785                      l_message := l_message||' ; '||l_msg_data;
10786               END LOOP;
10787               END IF;
10788 
10789                 LOG_MESSAGES('Reaction Time status: '||l_return_status);
10790                 LOG_MESSAGES('Reaction Time((Cognomen)) failed;'||l_message);
10791                 l_status := 'ERROR';
10792                 RAISE G_EXCEPTION_HALT_VALIDATION;
10793          END IF;
10794 
10795 	END IF;
10796       ELSIF l_criteria_rec.attribute = 'RESOLUTION_TIME' then
10797 
10798         l_act_tbl_in.delete;
10799         l_act_tbl_out.delete;
10800         cnt := 1;
10801         FOR rec IN Get_act_time(l_eligible_contracts_tbl(i).contract_id,'RSN',l_old_value_id )
10802         LOOP
10803               l_act_tbl_in(cnt).id                        := rec.id;
10804               l_act_tbl_in(cnt).object_version_number     := rec.object_version_number;
10805 
10806 
10807               If    rec.sun_duration = l_old_value_id then
10808                     l_act_tbl_in(cnt).sun_duration              := l_new_value_id ;
10809               End If;
10810               If rec.mon_duration = l_old_value_id then
10811                     l_act_tbl_in(cnt).mon_duration              := l_new_value_id;
10812               End If;
10813               If rec.tue_duration = l_old_value_id then
10814                     l_act_tbl_in(cnt).tue_duration              := l_new_value_id;
10815               End If;
10816               If rec.wed_duration = l_old_value_id then
10817                     l_act_tbl_in(cnt).wed_duration              := l_new_value_id;
10818               End If;
10819               If rec.thu_duration = l_old_value_id then
10820                     l_act_tbl_in(cnt).thu_duration              := l_new_value_id;
10821               End If;
10822               If rec.fri_duration = l_old_value_id then
10823                     l_act_tbl_in(cnt).fri_duration              := l_new_value_id;
10824               End If;
10825               If rec.sat_duration = l_old_value_id then
10826                     l_act_tbl_in(cnt).sat_duration              := l_new_value_id;
10827               End If ;
10828 
10829               cnt := cnt + 1;
10830         END LOOP;
10831 	If l_act_tbl_in.count > 0 Then
10832          OKS_ACM_PVT.lock_row (
10833                         	p_api_version		=> l_api_version,
10834                           	p_init_msg_list		=> l_init_msg_list,
10835                         	x_return_status		=> l_return_status,
10836                         	x_msg_count			=> l_msg_count,
10837                          	x_msg_data			=> l_msg_data,
10838                            	p_oks_action_times_v_tbl			=> l_act_tbl_in);
10839 
10840 
10841          IF l_return_status = G_RET_STS_SUCCESS THEN
10842 
10843             OKS_ACM_PVT.update_row (
10844                         	p_api_version		=> l_api_version,
10845                           	p_init_msg_list		=> l_init_msg_list,
10846                         	x_return_status		=> l_return_status,
10847                         	x_msg_count			=> l_msg_count,
10848                          	x_msg_data			=> l_msg_data,
10849                         	p_oks_action_times_v_tbl		    => l_act_tbl_in,
10850     	                    x_oks_action_times_v_tbl		    => l_act_tbl_out );
10851 
10852            IF l_return_status = G_RET_STS_SUCCESS THEN
10853                      LOG_MESSAGES('Resolution update status: '||l_return_status);
10854            ELSE
10855                   IF l_msg_count > 0
10856                   THEN
10857                   FOR i in 1..l_msg_count
10858                   LOOP
10859                     fnd_msg_pub.get (p_msg_index     => -1,
10860                                      p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10861                                      p_data          => l_msg_data,
10862                                      p_msg_index_out => l_msg_index_out);
10863                      l_message := l_message||' ; '||l_msg_data;
10864                   END LOOP;
10865                   END IF;
10866 
10867                 LOG_MESSAGES('Resolution Time update status: '||l_return_status);
10868                 LOG_MESSAGES('Resolution Time Update failed;'||l_message);
10869                 l_status := 'ERROR';
10870                 RAISE G_EXCEPTION_HALT_VALIDATION;
10871              END IF;
10872          ELSE
10873               IF l_msg_count > 0
10874               THEN
10875               FOR i in 1..l_msg_count
10876               LOOP
10877                  fnd_msg_pub.get (p_msg_index     => -1,
10878                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10879                                   p_data          => l_msg_data,
10880                                   p_msg_index_out => l_msg_index_out);
10881                      l_message := l_message||' ; '||l_msg_data;
10882               END LOOP;
10883               END IF;
10884 
10885                 LOG_MESSAGES('Resolution Time status: '||l_return_status);
10886                 LOG_MESSAGES('Resolution Time((Cognomen)) failed;'||l_message);
10887                 l_status := 'ERROR';
10888                 RAISE G_EXCEPTION_HALT_VALIDATION;
10889          END IF;
10890 	End If;
10891       ELSIF l_criteria_rec.attribute = 'CONTRACT_ALIAS' then
10892 
10893             l_chrv_tbl_in(1).id		                  := l_eligible_contracts_tbl(i).contract_id;
10894             l_chrv_tbl_in(1).object_version_number       := l_eligible_contracts_tbl(i).object_version_number;
10895 
10896          OKC_CONTRACT_PUB.lock_contract_header (
10897                         	p_api_version		=> l_api_version,
10898                           	p_init_msg_list		=> l_init_msg_list,
10899                         	x_return_status		=> l_return_status,
10900                         	x_msg_count			=> l_msg_count,
10901                          	x_msg_data			=> l_msg_data,
10902                            	p_chrv_tbl			=> l_chrv_tbl_in);
10903 
10904 
10905          IF l_return_status = G_RET_STS_SUCCESS THEN
10906 
10907          l_chrv_rec_in.id  := l_eligible_contracts_tbl(i).contract_id;
10908          l_chrv_rec_in.cognomen  := l_new_value_id;
10909 
10910           OKC_CONTRACT_PUB.update_contract_header (
10911                         	p_api_version		=> l_api_version,
10912                           	p_init_msg_list		=> l_init_msg_list,
10913                         	x_return_status		=> l_return_status,
10914                         	x_msg_count			=> l_msg_count,
10915                          	x_msg_data			=> l_msg_data,
10916                         	p_chrv_rec		    => l_chrv_rec_in,
10917     	                    x_chrv_rec		    => l_chrv_rec_out );
10918                 IF l_return_status = G_RET_STS_SUCCESS THEN
10919                      LOG_MESSAGES('CONTRACT_HEADER(Cognomen) update status: '||l_return_status);
10920                 ELSE
10921                   IF l_msg_count > 0
10922                   THEN
10923                   FOR i in 1..l_msg_count
10924                   LOOP
10925                     fnd_msg_pub.get (p_msg_index     => -1,
10926                                      p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10927                                      p_data          => l_msg_data,
10928                                      p_msg_index_out => l_msg_index_out);
10929                      l_message := l_message||' ; '||l_msg_data;
10930                   END LOOP;
10931                   END IF;
10932 
10933                 LOG_MESSAGES('CONTRACT_HEADER(Cognomen) update status: '||l_return_status);
10934                 LOG_MESSAGES('Contract Header(Cognomen) Update failed;'||l_message);
10935                 l_status := 'ERROR';
10936                 RAISE G_EXCEPTION_HALT_VALIDATION;
10937                 END IF;
10938          ELSE
10939               IF l_msg_count > 0
10940               THEN
10941               FOR i in 1..l_msg_count
10942               LOOP
10943                  fnd_msg_pub.get (p_msg_index     => -1,
10944                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10945                                   p_data          => l_msg_data,
10946                                   p_msg_index_out => l_msg_index_out);
10947                      l_message := l_message||' ; '||l_msg_data;
10948               END LOOP;
10949               END IF;
10950 
10951                 LOG_MESSAGES('LOCK_CONTRACT(Cognomen) status: '||l_return_status);
10952                 LOG_MESSAGES('Contract Lock((Cognomen)) failed;'||l_message);
10953                 l_status := 'ERROR';
10954                 RAISE G_EXCEPTION_HALT_VALIDATION;
10955          END IF;
10956 
10957       ELSIF l_criteria_rec.attribute = 'PO_NUMBER_BILL' then
10958 
10959 
10960                      l_chrv_tbl_in(1).id		                     := l_eligible_contracts_tbl(i).contract_id;
10961                      l_chrv_tbl_in(1).object_version_number       := l_eligible_contracts_tbl(i).object_version_number;
10962 
10963                      OKC_CONTRACT_PUB.lock_contract_header (
10964                         	p_api_version		=> l_api_version,
10965                           	p_init_msg_list		=> l_init_msg_list,
10966                         	x_return_status		=> l_return_status,
10967                         	x_msg_count			=> l_msg_count,
10968                          	x_msg_data			=> l_msg_data,
10969                            	p_chrv_tbl			=> l_chrv_tbl_in);
10970 
10971 
10972                     IF l_return_status = G_RET_STS_SUCCESS THEN
10973 
10974                        l_chrv_rec_in.id  := l_eligible_contracts_tbl(i).contract_id;
10975                        l_chrv_rec_in.cust_po_number  := l_new_value_id;
10976                        l_chrv_rec_in.payment_instruction_type  := 'PON';
10977 
10978                        OKC_CONTRACT_PUB.update_contract_header (
10979                         	p_api_version		=> l_api_version,
10980                           	p_init_msg_list		=> l_init_msg_list,
10981                         	x_return_status		=> l_return_status,
10982                         	x_msg_count			=> l_msg_count,
10983                          	x_msg_data			=> l_msg_data,
10984                         	p_chrv_rec		    => l_chrv_rec_in,
10985     	                    x_chrv_rec		    => l_chrv_rec_out );
10986                 IF l_return_status = G_RET_STS_SUCCESS THEN
10987                      LOG_MESSAGES('CONTRACT_HEADER(Cust PO Number) update status: '||l_return_status);
10988                 ELSE
10989                   IF l_msg_count > 0
10990                   THEN
10991                   FOR i in 1..l_msg_count
10992                   LOOP
10993                     fnd_msg_pub.get (p_msg_index     => -1,
10994                                      p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
10995                                      p_data          => l_msg_data,
10996                                      p_msg_index_out => l_msg_index_out);
10997                      l_message := l_message||' ; '||l_msg_data;
10998                   END LOOP;
10999                   END IF;
11000 
11001                 LOG_MESSAGES('CONTRACT_HEADER(Cust PO Number) update status: '||l_return_status);
11002                 LOG_MESSAGES('Contract Header(Cust PO Number) Update failed;'||l_message);
11003                 l_status := 'ERROR';
11004                 RAISE G_EXCEPTION_HALT_VALIDATION;
11005                 END IF;
11006          ELSE
11007               IF l_msg_count > 0
11008               THEN
11009               FOR i in 1..l_msg_count
11010               LOOP
11011                  fnd_msg_pub.get (p_msg_index     => -1,
11012                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11013                                   p_data          => l_msg_data,
11014                                   p_msg_index_out => l_msg_index_out);
11015                      l_message := l_message||' ; '||l_msg_data;
11016               END LOOP;
11017               END IF;
11018 
11019                 LOG_MESSAGES('LOCK_CONTRACT(Cust PO Number) status: '||l_return_status);
11020                 LOG_MESSAGES('Contract Lock((Cust PO Number)) failed;'||l_message);
11021                 l_status := 'ERROR';
11022                 RAISE G_EXCEPTION_HALT_VALIDATION;
11023          END IF;
11024 
11025     ELSIF l_criteria_rec.attribute = 'PRODUCT_ALIAS' then
11026                   l_clev_tbl_in.delete;
11027                   LOG_MESSAGES('Fetching contract lines for update');
11028                   Get_contract_lines(p_chr_id    => l_eligible_contracts_tbl(i).contract_id,
11029                                       p_attr      => l_criteria_rec.attribute,
11030                                       p_old_value => l_criteria_rec.old_value, --l_old_value_id,
11031                                       p_new_value => l_new_value_id,
11032                                       x_return_status => l_return_status,
11033                                       x_clev_tbl  => l_clev_tbl_in);
11034 
11035               IF l_return_status = G_RET_STS_SUCCESS AND l_clev_tbl_in.COUNT>0 THEN
11036                   LOG_MESSAGES('Locking contract lines for update');
11037                  OKC_CONTRACT_PUB.lock_contract_header (
11038                         	p_api_version		=> l_api_version,
11039                           	p_init_msg_list		=> l_init_msg_list,
11040                         	x_return_status		=> l_return_status,
11041                         	x_msg_count			=> l_msg_count,
11042                          	x_msg_data			=> l_msg_data,
11043                            	p_chrv_tbl			=> l_chrv_tbl_in);
11044 
11045              END IF;
11046          IF l_return_status = G_RET_STS_SUCCESS THEN
11047 
11048             FOR j in 1 .. l_clev_tbl_in.COUNT LOOP
11049                 l_clev_tbl_in(j).cognomen := l_new_value_id;
11050             END LOOP;
11051 
11052                  OKC_CONTRACT_PUB.update_contract_line(
11053                             	p_api_version		=> l_api_version,
11054                               	p_init_msg_list		=> l_init_msg_list,
11055                             	x_return_status		=> l_return_status,
11056                             	x_msg_count		    => l_msg_count,
11057                              	x_msg_data		    => l_msg_data,
11058                                 p_clev_tbl          => l_clev_tbl_in,
11059                                 x_clev_tbl          => l_clev_tbl_out);
11060 
11061                 IF l_return_status = G_RET_STS_SUCCESS THEN
11062                      LOG_MESSAGES('PRODUCT_ALIAS update status: '||l_return_status);
11063                 ELSE
11064                   IF l_msg_count > 0
11065                   THEN
11066                   FOR i in 1..l_msg_count
11067                   LOOP
11068                     fnd_msg_pub.get (p_msg_index     => -1,
11069                                      p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11070                                      p_data          => l_msg_data,
11071                                      p_msg_index_out => l_msg_index_out);
11072                      l_message := l_message||' ; '||l_msg_data;
11073                   END LOOP;
11074                   END IF;
11075 
11076                 LOG_MESSAGES('PRODUCT_ALIAS update status: '||l_return_status);
11077                 LOG_MESSAGES('PRODUCT_ALIAS Update failed;'||l_message);
11078                 l_status := 'ERROR';
11079                 RAISE G_EXCEPTION_HALT_VALIDATION;
11080                 END IF;
11081          ELSE
11082               IF l_msg_count > 0
11083               THEN
11084               FOR i in 1..l_msg_count
11085               LOOP
11086                  fnd_msg_pub.get (p_msg_index     => -1,
11087                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11088                                   p_data          => l_msg_data,
11089                                   p_msg_index_out => l_msg_index_out);
11090                      l_message := l_message||' ; '||l_msg_data;
11091               END LOOP;
11092               END IF;
11093 
11094                 LOG_MESSAGES('LOCK_CONTRACT_LINE(Product Alias) status: '||l_return_status);
11095                 LOG_MESSAGES('LOCK_CONTRACT_LINE(Product Alias) failed;'||l_message);
11096                 l_status := 'ERROR';
11097                 RAISE G_EXCEPTION_HALT_VALIDATION;
11098          END IF;
11099 
11100       ELSIF l_criteria_rec.attribute = 'CONTRACT_LINE_REF' then
11101                   l_clev_tbl_in.delete;
11102                   LOG_MESSAGES('Fetching contract lines for update');
11103                   Get_contract_lines(p_chr_id    => l_eligible_contracts_tbl(i).contract_id,
11104                                       p_attr      => l_criteria_rec.attribute,
11105                                       p_old_value => l_criteria_rec.old_value, --l_old_value_id,
11106                                       p_new_value => l_new_value_id,
11107                                       x_return_status => l_return_status,
11108                                       x_clev_tbl  => l_clev_tbl_in);
11109 
11110             IF l_return_status = G_RET_STS_SUCCESS AND l_clev_tbl_in.COUNT >0 THEN
11111                   LOG_MESSAGES('Locking contract lines for update');
11112 
11113                   OKC_CONTRACT_PUB.lock_contract_header (
11114                         	p_api_version		=> l_api_version,
11115                           	p_init_msg_list		=> l_init_msg_list,
11116                         	x_return_status		=> l_return_status,
11117                         	x_msg_count			=> l_msg_count,
11118                          	x_msg_data			=> l_msg_data,
11119                            	p_chrv_tbl			=> l_chrv_tbl_in);
11120 
11121 
11122          IF l_return_status = G_RET_STS_SUCCESS THEN
11123 
11124             FOR j in 1 .. l_clev_tbl_in.COUNT LOOP
11125                 l_clev_tbl_in(j).cognomen := l_new_value_id;
11126             END LOOP;
11127 
11128                  OKC_CONTRACT_PUB.update_contract_line(
11129                             	p_api_version		=> l_api_version,
11130                               	p_init_msg_list		=> l_init_msg_list,
11131                             	x_return_status		=> l_return_status,
11132                             	x_msg_count		    => l_msg_count,
11133                              	x_msg_data		    => l_msg_data,
11134                                 p_clev_tbl          => l_clev_tbl_in,
11135                                 x_clev_tbl          => l_clev_tbl_out);
11136 
11137                 IF l_return_status = G_RET_STS_SUCCESS THEN
11138                      LOG_MESSAGES('CONTRACT_LINE_REF update status: '||l_return_status);
11139                 ELSE
11140                   IF l_msg_count > 0
11141                   THEN
11142                   FOR i in 1..l_msg_count
11143                   LOOP
11144                     fnd_msg_pub.get (p_msg_index     => -1,
11145                                      p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11146                                      p_data          => l_msg_data,
11147                                      p_msg_index_out => l_msg_index_out);
11148                      l_message := l_message||' ; '||l_msg_data;
11149                   END LOOP;
11150                   END IF;
11151 
11152                 LOG_MESSAGES('CONTRACT_LINE_REF(Cognomen) update status: '||l_return_status);
11153                 LOG_MESSAGES('CONTRACT_LINE_REF(Cognomen) Update failed;'||l_message);
11154                 l_status := 'ERROR';
11155                 RAISE G_EXCEPTION_HALT_VALIDATION;
11156                 END IF;
11157          ELSE
11158                   IF l_msg_count > 0
11159                   THEN
11160                   FOR i in 1..l_msg_count
11161                   LOOP
11162                     fnd_msg_pub.get (p_msg_index     => -1,
11163                                      p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11164                                      p_data          => l_msg_data,
11165                                      p_msg_index_out => l_msg_index_out);
11166                      l_message := l_message||' ; '||l_msg_data;
11167                   END LOOP;
11168                   END IF;
11169 
11170                 LOG_MESSAGES('CONTRACT_LINE_REF(Cognomen) update status: '||l_return_status);
11171                 LOG_MESSAGES('CONTRACT_LINE_REF(Cognomen) Update failed;'||l_message);
11172                 l_status := 'ERROR';
11173                 RAISE G_EXCEPTION_HALT_VALIDATION;
11174          END IF;
11175        ELSE
11176                 LOG_MESSAGES('Get_contract_lines status: '||l_return_status);
11177                 LOG_MESSAGES('Get_contract_lines failed');
11178                 l_status := 'ERROR';
11179                 RAISE G_EXCEPTION_HALT_VALIDATION;
11180 
11181        END IF;
11182       ELSIF l_criteria_rec.attribute = 'CONTRACT_GROUP' then
11183 
11184          OPEN   Get_cgrp_id(l_eligible_contracts_tbl(i).contract_id,l_eligible_contracts_tbl(i).old_value);
11185          FETCH  Get_cgrp_id INTO l_cgrp_id;
11186          CLOSE  Get_cgrp_id;
11187 
11188         l_cgcv_rec_in.id                := l_cgrp_id;
11189         l_cgcv_rec_in.included_chr_id   := l_eligible_contracts_tbl(i).contract_id;
11190         l_cgcv_rec_in.cgp_parent_id     := l_new_value_id;
11191 
11192         OKC_CONTRACT_GROUP_PUB.update_contract_grpngs(
11193                                         p_api_version         => l_api_version,
11194                                         p_init_msg_list       => l_init_msg_list,
11195                                         x_return_status       => l_return_status,
11196                                         x_msg_count           => l_msg_count,
11197                                         x_msg_data            => l_msg_data,
11198                                         p_cgcv_rec            => l_cgcv_rec_in,
11199                                         x_cgcv_rec            => l_cgcv_rec_out);
11200 
11201                 IF l_return_status = G_RET_STS_SUCCESS THEN
11202                      LOG_MESSAGES('CONTRACT_GROUP update status: '||l_return_status);
11203                 ELSE
11204                   IF l_msg_count > 0
11205                   THEN
11206                   LOG_MESSAGES('l_msg_count: '||l_msg_count);
11207                   FOR i in 1..l_msg_count
11208                   LOOP
11209                     fnd_msg_pub.get (p_msg_index     => -1,
11210                                      p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11211                                      p_data          => l_msg_data,
11212                                      p_msg_index_out => l_msg_index_out);
11213                      l_message := l_message||' ; '||l_msg_data;
11214                   END LOOP;
11215                   END IF;
11216 
11217                 LOG_MESSAGES('CONTRACT_GROUP update status: '||l_return_status);
11218                 LOG_MESSAGES('Contract Group Update failed;'||l_message);
11219                 l_status := 'ERROR';
11220                 RAISE G_EXCEPTION_HALT_VALIDATION;
11221                 END IF;
11222 
11223       ELSIF l_criteria_rec.attribute = 'CONTRACT_START_DATE' then
11224             l_chrv_tbl_in.DELETE;
11225             l_chrv_tbl_in(1).id		              := l_eligible_contracts_tbl(i).contract_id;
11226             l_chrv_tbl_in(1).object_version_number    := l_eligible_contracts_tbl(i).object_version_number;
11227 
11228        IF   OKS_EXTWAR_UTIL_PVT.Check_Already_Billed(l_chrv_tbl_in(1).id,NULL,1,NULL)  then  --to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS')) then
11229 
11230             l_message := FND_MESSAGE.get_string('OKS','OKS_MSCHG_BILL_CON') ;
11231 --            l_message := 'It is already billed. Can not update. ' ;
11232             RAISE  l_notelligible_exception ;
11233 
11234        Else
11235 
11236             OKC_CONTRACT_PUB.lock_contract_header (
11237                         	p_api_version		=> l_api_version,
11238                           	p_init_msg_list		=> l_init_msg_list,
11239                         	x_return_status		=> l_return_status,
11240                         	x_msg_count		=> l_msg_count,
11241                          	x_msg_data		=> l_msg_data,
11242                            	p_chrv_tbl		=> l_chrv_tbl_in);
11243 
11244             IF l_return_status <> G_RET_STS_SUCCESS THEN
11245 
11246 
11247                    IF l_msg_count > 0
11248                    THEN
11249                         FOR i in 1..l_msg_count
11250                         LOOP
11251                                   fnd_msg_pub.get (p_msg_index     => -1,
11252                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11253                                   p_data          => l_msg_data,
11254                                   p_msg_index_out => l_msg_index_out);
11255                                  l_message := l_message||' ; '||l_msg_data;
11256                         END LOOP;
11257                    END IF;
11258 
11259                    LOG_MESSAGES('CONTRACT_START_DATE LOCK_CONTRACT status: '||l_return_status);
11260                    LOG_MESSAGES('Contract Lock(CONTRACT_START_DATE) failed;'||l_message);
11261                    l_status := 'ERROR';
11262                    RAISE G_EXCEPTION_HALT_VALIDATION;
11263              END IF;
11264 
11265              LOG_MESSAGES('Fetching contract lines for update');
11266              l_clev_tbl_in.DELETE;
11267              Get_contract_lines(p_chr_id          => l_eligible_contracts_tbl(i).contract_id,
11268                                       p_attr           => l_criteria_rec.attribute,
11269                                       p_old_value      => l_old_value,
11270                                       p_new_value      => l_new_value,
11271                                       x_return_status  => l_return_status,
11272                                       x_clev_tbl       => l_clev_tbl_in);
11273 
11274              IF l_return_status = G_RET_STS_SUCCESS THEN
11275                 LOG_MESSAGES('Locking contract lines for update, lines count:'||l_clev_tbl_in.COUNT);
11276 
11277                 OKC_CONTRACT_PUB.lock_contract_line(
11278                                           p_api_version     => l_api_version,
11279                                           p_init_msg_list   => l_init_msg_list,
11280                                           x_return_status   => l_return_status,
11281                                           x_msg_count       => l_msg_count,
11282                                           x_msg_data        => l_msg_data,
11283                                           p_clev_tbl        => l_clev_tbl_in);
11284 
11285                 LOG_MESSAGES(' Contract lines lock status:'||l_return_status);
11286 
11287                 IF l_return_status <> G_RET_STS_SUCCESS THEN
11288                    LOG_MESSAGES('Contract lines lock failed');
11289                    l_status := 'ERROR';
11290                    RAISE G_EXCEPTION_HALT_VALIDATION;
11291                 End If;
11292 
11293              ELSE
11294                 LOG_MESSAGES('Get_Contract_lines status: '||l_return_status);
11295                 LOG_MESSAGES('Get_Contract_lines failed');
11296                 l_status := 'ERROR';
11297                 RAISE G_EXCEPTION_HALT_VALIDATION;
11298              END IF;
11299              LOG_MESSAGES('lock status:'||l_return_status);
11300              LOG_MESSAGES('l_new_value:'||l_new_value||' , length:'||length(l_new_value));
11301              --- vigandhi added
11302 		 -- Bug Fix 5075961
11303 
11304              l_klnv_tbl_type_in.DELETE;
11305              Get_oks_contract_lines(p_chr_id      => l_eligible_contracts_tbl(i).contract_id,
11306                                       p_attr           => l_criteria_rec.attribute,
11307                                       p_old_value      => l_old_value,
11308                                       p_new_value      => l_new_value,
11309                                       x_return_status  => l_return_status,
11310                                       x_clev_tbl       => l_klnv_tbl_type_in);
11311 
11312 
11313               LOG_MESSAGES(' Get OKS Contract lines status:'||l_return_status);
11314 
11315 	        IF l_return_status = G_RET_STS_SUCCESS THEN
11316 	                LOG_MESSAGES('Locking oks contract lines for update, lines count:'||l_klnv_tbl_type_in.COUNT);
11317 	        ELSE  -- Get oks contract Lines
11318                       LOG_MESSAGES('Get_Contract_lines status: '||l_return_status);
11319                       LOG_MESSAGES('Get_Contract_lines failed');
11320                 	    l_status := 'ERROR';
11321                 	    RAISE G_EXCEPTION_HALT_VALIDATION;
11322               END IF;  -- Get oks Contracts Lines
11323 
11324 
11325 
11326               OKS_CONTRACT_LINE_PUB.lock_line(
11327                                         p_api_version         => l_api_version,
11328                                         p_init_msg_list       => l_init_msg_list,
11329                                         x_return_status       => l_return_status,
11330                                         x_msg_count           => l_msg_count,
11331                                         x_msg_data            => l_msg_data,
11332                                         p_klnv_tbl            => l_klnv_tbl_type_in);
11333 
11334               IF l_return_status <> G_RET_STS_SUCCESS THEN
11335 
11336 
11337 
11338                        LOG_MESSAGES('CONTRACT_START_DATE LOCK_CONTRACT_OKS_LINES status: '||l_return_status||',msg_count:'||l_msg_count);
11339                        IF l_msg_count > 0 then
11340                        	   FOR i in 1..l_msg_count
11341                        	   LOOP
11342                         	   fnd_msg_pub.get (p_msg_index     => -1,
11343                                                     p_encoded       => 'F',
11344                                                     p_data          => l_msg_data,
11345                                                     p_msg_index_out => l_msg_index_out);
11346                                   l_message := l_message||' ; '||l_msg_data;
11347                             END LOOP;
11348                         END IF;
11349                         LOG_MESSAGES('Contract Oks Lines Lock(CONTRACT_START_DATE) failed;'||l_message);
11350                         l_status := 'ERROR';
11351                         RAISE G_EXCEPTION_HALT_VALIDATION;
11352 
11353                END IF;
11354                -- Bug fix 5075961
11355 
11356                l_chrv_rec_in.id  := l_eligible_contracts_tbl(i).contract_id;
11357                l_chrv_rec_in.start_date  := to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS');
11358                LOG_MESSAGES('updating contract header with new value:'||l_chrv_rec_in.start_date);
11359 
11360                OKC_CONTRACT_PUB.update_contract_header (
11361                         	p_api_version	  => l_api_version,
11362                           	p_init_msg_list	  => l_init_msg_list,
11363                         	x_return_status	  => l_return_status,
11364                         	x_msg_count	  => l_msg_count,
11365                          	x_msg_data	  => l_msg_data,
11366                         	p_chrv_rec        => l_chrv_rec_in,
11367     	                        x_chrv_rec        => l_chrv_rec_out );
11368 
11369                IF l_return_status = G_RET_STS_SUCCESS THEN
11370                           LOG_MESSAGES('CONTRACT_HEADER(Start_Date) update status: '||l_return_status);
11371 
11372                ELSE
11373                           IF l_msg_count > 0
11374                           THEN
11375                                FOR i in 1..l_msg_count
11376                                LOOP
11377                                      fnd_msg_pub.get (p_msg_index     => -1,
11378                                      p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11379                                      p_data          => l_msg_data,
11380                                      p_msg_index_out => l_msg_index_out);
11381                                      l_message := l_message||' ; '||l_msg_data;
11382                                END LOOP;
11383                            END IF;
11384                            LOG_MESSAGES('CONTRACT_HEADERS(Contract_Start_Date) update status: '||l_return_status);
11385                            LOG_MESSAGES('Contract Header(Contract_Start_Date) Update failed;'||l_message);
11386                            l_status := 'ERROR';
11387                            RAISE G_EXCEPTION_HALT_VALIDATION;
11388                 END IF;
11389                 IF l_clev_tbl_in.COUNT > 0 THEN
11390                      FOR j in 1 .. l_clev_tbl_in.COUNT
11391                      LOOP
11392                                l_clev_tbl_in(j).start_date :=
11393                                      to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS');
11394                      END LOOP;
11395                      LOG_MESSAGES('updating contract lines with new value:'||l_new_value);
11396 
11397                      OKC_CONTRACT_PUB.update_contract_line(
11398                         	   p_api_version	=> l_api_version,
11399                              	   p_init_msg_list	=> l_init_msg_list,
11400                             	   x_return_status	=> l_return_status,
11401                             	   x_msg_count	        => l_msg_count,
11402                              	   x_msg_data	        => l_msg_data,
11403                                  p_clev_tbl           => l_clev_tbl_in,
11404                                  x_clev_tbl           => l_clev_tbl_out);
11405                  END IF;
11406 
11407                  IF l_return_status = G_RET_STS_SUCCESS THEN
11408                           LOG_MESSAGES('CONTRACT_HEADER_LINES(Start_Date) update status: '||l_return_status);
11409 
11410                           -- Vigandhi
11411 		              -- Bug Fix 5075961
11412 
11413                           IF l_klnv_tbl_type_in.COUNT > 0 THEN
11414 			              LOG_MESSAGES('updating contract lines with new invoice text');
11415                                 oks_contract_line_pub.update_line
11416                                 (p_api_version        => l_api_version,
11417                                  p_init_msg_list      => l_init_msg_list,
11418                                  x_return_status      => l_return_status,
11419                                  x_msg_count          => l_msg_count,
11420                                  x_msg_data           => l_msg_data,
11421                                  p_klnv_tbl           => l_klnv_tbl_type_in,
11422                                  x_klnv_tbl           => l_klnv_tbl_type_out,
11423                                  p_validate_yn        => 'N'
11424                                  );
11425 				         LOG_MESSAGES('CONTRACT_HEADER_OKS_LINES(Start_Date) update status: '||l_return_status);
11426 				         IF l_return_status <> G_RET_STS_SUCCESS THEN
11427 				                 IF l_msg_count > 0 Then
11428                                                 FOR i in 1..l_msg_count
11429                                                 LOOP
11430                                                   fnd_msg_pub.get (p_msg_index     => -1,
11431                                                                    p_encoded       => 'F',
11432                                                                    p_data          => l_msg_data,
11433                                                                    p_msg_index_out => l_msg_index_out);
11434                                                   l_message := l_message||' ; '||l_msg_data;
11435                                                 END LOOP;
11436                                           END IF;
11437 				                  LOG_MESSAGES('CONTRACT_OKS_LINES(Contract_Start_Date) update status: '||l_return_status);
11438                                           LOG_MESSAGES('Contract oks Lines(Contract_Start_Date) Update failed;'||l_message);
11439                                           l_status := 'ERROR';
11440                                           RAISE G_EXCEPTION_HALT_VALIDATION;
11441  					     END IF;
11442 				     END IF;
11443 				     -- Bug Fix 5075961
11444 
11445 
11446                              l_old_k_amount := Get_contract_amount(l_chrv_rec_in.id);
11447                              LOG_MESSAGES('Old Contract Amount:'||l_old_k_amount);
11448 
11449                              OKS_REPRICE_PVT.Call_Pricing_Api(
11450                                         p_api_version         => l_api_version,
11451                                         p_init_msg_list       => l_init_msg_list,
11452                                         P_id        		  => l_chrv_rec_in.id,
11453 				                        P_Id_Type		      => 'CHR',
11454                                         x_return_status       => l_return_status,
11455                                         x_msg_count           => l_msg_count,
11456                                         x_msg_data            => l_msg_data);
11457 
11458                               IF  l_return_status = G_RET_STS_SUCCESS THEN
11459                                         LOG_MESSAGES('CONTRACT_HEADER(Start_date) Repricing status for lines: '||l_return_status);
11460 
11461 
11462 
11463                                         l_new_k_amount := Get_contract_amount(l_chrv_rec_in.id);
11464                                         LOG_MESSAGES('New Contract Amount:'||l_new_k_amount);
11465                                         l_amt_message := rpad(' ',60,' ')||'Old Contract Amount: '||rpad(to_char(l_old_k_amount),10,' ')||'New Contract Amount: '||rpad(to_char(l_new_k_amount),10,' ');
11466                                         LOG_MESSAGES('CONTRACT_HEADER(Start_date) Repricing status: '||l_return_status);
11467 
11468                               ELSE
11469                                        IF l_msg_count > 0
11470                                        THEN
11471                                             FOR i in 1..l_msg_count
11472                                              LOOP
11473                                              fnd_msg_pub.get (p_msg_index     => -1,
11474                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11475                                              p_data          => l_msg_data,
11476                                              p_msg_index_out => l_msg_index_out);
11477                                               l_message := l_message||' ; '||l_msg_data;
11478                                            END LOOP;
11479                                        END IF;
11480 
11481                                          LOG_MESSAGES('CONTRACT_HEADER(Contract_Start_Date) Repricing status: '||l_return_status);
11482                                         LOG_MESSAGES('Contract Header(Contract_Start_Date) Repricing  failed;'||l_message);
11483                                        l_status := 'ERROR';
11484                                        RAISE G_EXCEPTION_HALT_VALIDATION;
11485                                END IF;
11486 
11487 
11488 
11489 
11490 
11491 
11492                    ELSE
11493                            LOG_MESSAGES('CONTRACT_START_DATE Update_CONTRACT_LINES status: '||l_return_status||',msg_count:'||l_msg_count);
11494                            IF l_msg_count > 0
11495                            THEN
11496                                FOR i in 1..l_msg_count
11497                                LOOP
11498                                fnd_msg_pub.get (p_msg_index     => -1,
11499                                                 p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11500                                                 p_data          => l_msg_data,
11501                                                 p_msg_index_out => l_msg_index_out);
11502 
11503                                 l_message := l_message||' ; '||l_msg_data;
11504                                END LOOP;
11505                              END IF;
11506                              LOG_MESSAGES('Contract Lines Update(CONTRACT_START_DATE) failed;'||l_message);
11507                              l_status := 'ERROR';
11508                              RAISE G_EXCEPTION_HALT_VALIDATION;
11509                     END IF;
11510 
11511                    IF l_clev_tbl_in.COUNT > 0 THEN
11512                         FOR j in 1 .. l_clev_tbl_in.COUNT
11513                         LOOP
11514                         If l_clev_tbl_in(j).lse_id in (1,12,19,46) Then
11515                         OKS_BILL_SCH.Cascade_Dates_SLL (l_clev_tbl_in(j).id,l_return_status,l_msg_count,l_msg_data) ;
11516 
11517                         IF l_return_status = G_RET_STS_SUCCESS THEN
11518                         LOG_MESSAGES('CONTRACT_HEADER(Start_date) Billing Schedule status for lines: '||l_return_status);
11519 
11520                             OPEN  Get_cle_id_PM(l_clev_tbl_in(j).id) ;
11521                             FETCH Get_cle_id_PM INTO l_count_pm_schedule ;
11522                             CLOSE Get_cle_id_PM ;
11523 
11524                             IF l_count_pm_schedule > 0 THEN
11525                                    OKS_PM_PROGRAMS_PVT.ADJUST_PM_PROGRAM_SCHEDULE(
11526                                         p_api_version          => l_api_version,
11527                                         p_init_msg_list        => l_init_msg_list,
11528                                         p_contract_line_id     => l_clev_tbl_in(j).id,
11529                                         p_new_start_date       => to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS'),
11530                                         p_new_end_date         => NULL,
11531                                         x_return_status       => l_return_status,
11532                                         x_msg_count           => l_msg_count,
11533                                         x_msg_data            => l_msg_data);
11534 
11535                                         LOG_MESSAGES('CONTRACT_HEADER(Start_date) PM Schedule status for lines: '||l_return_status);
11536 
11537                                     IF l_return_status  in (G_RET_STS_ERROR,G_RET_STS_UNEXP_ERROR) THEN
11538 
11539                                          IF l_msg_count > 0 THEN
11540                                          FOR i in 1..l_msg_count
11541                                          LOOP
11542                                              fnd_msg_pub.get (p_msg_index     => -1,
11543                                                               p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11544                                                               p_data          => l_msg_data,
11545                                                               p_msg_index_out => l_msg_index_out);
11546                                              l_message := l_message||' ; '||l_msg_data;
11547                                          END LOOP;
11548                                          END IF;
11549 
11550                                          LOG_MESSAGES('Contract_Header(Contract_Start_Date) PM Schedule status: '||l_return_status);
11551                                          LOG_MESSAGES('Contract Header(Contract_Start_Date) PM Schedule failed;'||l_message);
11552                                          l_status := 'ERROR';
11553                                          RAISE G_EXCEPTION_HALT_VALIDATION;
11554                                     END IF;
11555                               END IF ;
11556 
11557                         ELSE
11558                                        IF l_msg_count > 0
11559                                        THEN
11560                                        FOR i in 1..l_msg_count
11561                                        LOOP
11562                                            fnd_msg_pub.get (p_msg_index     => -1,
11563                                                             p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11564                                                             p_data          => l_msg_data,
11565                                                             p_msg_index_out => l_msg_index_out);
11566                                            l_message := l_message||' ; '||l_msg_data;
11567                                        END LOOP;
11568                                        END IF;
11569 
11570                                    LOG_MESSAGES('CONTRACT_HEADER(Contract_Start_Date) Billing Schedule status: '||l_return_status);
11571                                    LOG_MESSAGES('Contract Header(Contract_Start_Date) Billing Schedule failed;'||l_message);
11572                                    l_status := 'ERROR';
11573                                    RAISE G_EXCEPTION_HALT_VALIDATION;
11574                         END IF;
11575                    End If;
11576                 END LOOP ;
11577               END IF ;
11578 
11579      End If;
11580 
11581 ELSIF l_criteria_rec.attribute = 'CONTRACT_END_DATE' then
11582          l_chrv_tbl_in.DELETE;
11583          l_chrv_tbl_in(1).id	                   := l_eligible_contracts_tbl(i).contract_id;
11584          l_chrv_tbl_in(1).object_version_number    := l_eligible_contracts_tbl(i).object_version_number;
11585 
11586 
11587      IF  OKS_EXTWAR_UTIL_PVT.Check_Already_Billed(l_chrv_tbl_in(1).id,NULL,1,to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS')) then
11588 
11589 --          l_message := 'It is already billed. Can not update. ' ;
11590             l_message := FND_MESSAGE.get_string('OKS','OKS_MSCHG_BILL_CON') ;
11591             RAISE  l_notelligible_exception ;
11592 
11593      ELSE
11594 
11595             OKC_CONTRACT_PUB.lock_contract_header (
11596                         	p_api_version		=> l_api_version,
11597                           	p_init_msg_list		=> l_init_msg_list,
11598                         	x_return_status		=> l_return_status,
11599                         	x_msg_count		=> l_msg_count,
11600                          	x_msg_data		=> l_msg_data,
11601                            	p_chrv_tbl		=> l_chrv_tbl_in);
11602 
11603             IF l_return_status <> G_RET_STS_SUCCESS THEN
11604 
11605 
11606                    IF l_msg_count > 0
11607                    THEN
11608                         FOR i in 1..l_msg_count
11609                         LOOP
11610                                   fnd_msg_pub.get (p_msg_index     => -1,
11611                                   p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11612                                   p_data          => l_msg_data,
11613                                   p_msg_index_out => l_msg_index_out);
11614                                  l_message := l_message||' ; '||l_msg_data;
11615                         END LOOP;
11616                    END IF;
11617 
11618                    LOG_MESSAGES('CONTRACT_START_DATE LOCK_CONTRACT status: '||l_return_status);
11619                    LOG_MESSAGES('Contract Lock(CONTRACT_START_DATE) failed;'||l_message);
11620                    l_status := 'ERROR';
11621                    RAISE G_EXCEPTION_HALT_VALIDATION;
11622              END IF;
11623 
11624              LOG_MESSAGES('Fetching contract lines for update');
11625              l_clev_tbl_in.DELETE;
11626              Get_contract_lines(p_chr_id          => l_eligible_contracts_tbl(i).contract_id,
11627                                       p_attr           => l_criteria_rec.attribute,
11628                                       p_old_value      => l_old_value,
11629                                       p_new_value      => l_new_value,
11630                                       x_return_status  => l_return_status,
11631                                       x_clev_tbl       => l_clev_tbl_in);
11632 
11633              IF l_return_status = G_RET_STS_SUCCESS THEN
11634                 LOG_MESSAGES('Locking contract lines for update, lines count:'||l_clev_tbl_in.COUNT);
11635 
11636                 OKC_CONTRACT_PUB.lock_contract_line(
11637                                           p_api_version     => l_api_version,
11638                                           p_init_msg_list   => l_init_msg_list,
11639                                           x_return_status   => l_return_status,
11640                                           x_msg_count       => l_msg_count,
11641                                           x_msg_data        => l_msg_data,
11642                                           p_clev_tbl        => l_clev_tbl_in);
11643 
11644                 LOG_MESSAGES(' Contract lines lock status:'||l_return_status);
11645 
11646                 IF l_return_status <> G_RET_STS_SUCCESS THEN
11647                    LOG_MESSAGES('Contract lines lock failed');
11648                    l_status := 'ERROR';
11649                    RAISE G_EXCEPTION_HALT_VALIDATION;
11650                 End If;
11651 
11652              ELSE
11653                 LOG_MESSAGES('Get_Contract_lines status: '||l_return_status);
11654                 LOG_MESSAGES('Get_Contract_lines failed');
11655                 l_status := 'ERROR';
11656                 RAISE G_EXCEPTION_HALT_VALIDATION;
11657              END IF;
11658              LOG_MESSAGES('lock status:'||l_return_status);
11659              LOG_MESSAGES('l_new_value:'||l_new_value||' , length:'||length(l_new_value));
11660              --- vigandhi added
11661 		 -- Bug Fix 5075961
11662 
11663              l_klnv_tbl_type_in.DELETE;
11664              Get_oks_contract_lines(p_chr_id      => l_eligible_contracts_tbl(i).contract_id,
11665                                       p_attr           => l_criteria_rec.attribute,
11666                                       p_old_value      => l_old_value,
11667                                       p_new_value      => l_new_value,
11668                                       x_return_status  => l_return_status,
11669                                       x_clev_tbl       => l_klnv_tbl_type_in);
11670 
11671 
11672               LOG_MESSAGES(' Get OKS Contract lines status:'||l_return_status);
11673 
11674 	        IF l_return_status = G_RET_STS_SUCCESS THEN
11675 	                LOG_MESSAGES('Locking oks contract lines for update, lines count:'||l_klnv_tbl_type_in.COUNT);
11676 	        ELSE  -- Get oks contract Lines
11677                       LOG_MESSAGES('Get_Contract_lines status: '||l_return_status);
11678                       LOG_MESSAGES('Get_Contract_lines failed');
11679                 	    l_status := 'ERROR';
11680                 	    RAISE G_EXCEPTION_HALT_VALIDATION;
11681               END IF;  -- Get oks Contracts Lines
11682 
11683 
11684 
11685               OKS_CONTRACT_LINE_PUB.lock_line(
11686                                         p_api_version         => l_api_version,
11687                                         p_init_msg_list       => l_init_msg_list,
11688                                         x_return_status       => l_return_status,
11689                                         x_msg_count           => l_msg_count,
11690                                         x_msg_data            => l_msg_data,
11691                                         p_klnv_tbl            => l_klnv_tbl_type_in);
11692 
11693               IF l_return_status <> G_RET_STS_SUCCESS THEN
11694 
11695 
11696 
11697                        LOG_MESSAGES('CONTRACT_End_DATE LOCK_CONTRACT_OKS_LINES status: '||l_return_status||',msg_count:'||l_msg_count);
11698                        IF l_msg_count > 0 then
11699                        	   FOR i in 1..l_msg_count
11700                        	   LOOP
11701                         	   fnd_msg_pub.get (p_msg_index     => -1,
11702                                                     p_encoded       => 'F',
11703                                                     p_data          => l_msg_data,
11704                                                     p_msg_index_out => l_msg_index_out);
11705                                   l_message := l_message||' ; '||l_msg_data;
11706                             END LOOP;
11707                         END IF;
11708                         LOG_MESSAGES('Contract Oks Lines Lock(CONTRACT_End_DATE) failed;'||l_message);
11709                         l_status := 'ERROR';
11710                         RAISE G_EXCEPTION_HALT_VALIDATION;
11711 
11712                END IF;
11713                -- Bug fix 5075961
11714 
11715                l_chrv_rec_in.id  := l_eligible_contracts_tbl(i).contract_id;
11716                l_chrv_rec_in.End_date  := to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS');
11717                LOG_MESSAGES('updating contract header with new value:'||l_chrv_rec_in.End_date);
11718 
11719                OKC_CONTRACT_PUB.update_contract_header (
11720                         	p_api_version	  => l_api_version,
11721                           	p_init_msg_list	  => l_init_msg_list,
11722                         	x_return_status	  => l_return_status,
11723                         	x_msg_count	  => l_msg_count,
11724                          	x_msg_data	  => l_msg_data,
11725                         	p_chrv_rec        => l_chrv_rec_in,
11726     	                        x_chrv_rec        => l_chrv_rec_out );
11727 
11728                IF l_return_status = G_RET_STS_SUCCESS THEN
11729                           LOG_MESSAGES('CONTRACT_HEADER(End_Date) update status: '||l_return_status);
11730 
11731                ELSE
11732                           IF l_msg_count > 0
11733                           THEN
11734                                FOR i in 1..l_msg_count
11735                                LOOP
11736                                      fnd_msg_pub.get (p_msg_index     => -1,
11737                                      p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11738                                      p_data          => l_msg_data,
11739                                      p_msg_index_out => l_msg_index_out);
11740                                      l_message := l_message||' ; '||l_msg_data;
11741                                END LOOP;
11742                            END IF;
11743                            LOG_MESSAGES('CONTRACT_HEADERS(Contract_End_Date) update status: '||l_return_status);
11744                            LOG_MESSAGES('Contract Header(Contract_End_Date) Update failed;'||l_message);
11745                            l_status := 'ERROR';
11746                            RAISE G_EXCEPTION_HALT_VALIDATION;
11747                 END IF;
11748                 IF l_clev_tbl_in.COUNT > 0 THEN
11749                      FOR j in 1 .. l_clev_tbl_in.COUNT
11750                      LOOP
11751                                l_clev_tbl_in(j).End_date :=
11752                                      to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS');
11753                      END LOOP;
11754                      LOG_MESSAGES('updating contract lines with new value:'||l_new_value);
11755 
11756                      OKC_CONTRACT_PUB.update_contract_line(
11757                         	   p_api_version	=> l_api_version,
11758                              	   p_init_msg_list	=> l_init_msg_list,
11759                             	   x_return_status	=> l_return_status,
11760                             	   x_msg_count	        => l_msg_count,
11761                              	   x_msg_data	        => l_msg_data,
11762                                  p_clev_tbl           => l_clev_tbl_in,
11763                                  x_clev_tbl           => l_clev_tbl_out);
11764                  END IF;
11765 
11766                  IF l_return_status = G_RET_STS_SUCCESS THEN
11767                           LOG_MESSAGES('CONTRACT_HEADER_LINES(End_Date) update status: '||l_return_status);
11768 
11769                           -- Vigandhi
11770 		              -- Bug Fix 5075961
11771 
11772                           IF l_klnv_tbl_type_in.COUNT > 0 THEN
11773 			              LOG_MESSAGES('updating contract lines with new invoice text');
11774                                 oks_contract_line_pub.update_line
11775                                 (p_api_version        => l_api_version,
11776                                  p_init_msg_list      => l_init_msg_list,
11777                                  x_return_status      => l_return_status,
11778                                  x_msg_count          => l_msg_count,
11779                                  x_msg_data           => l_msg_data,
11780                                  p_klnv_tbl           => l_klnv_tbl_type_in,
11781                                  x_klnv_tbl           => l_klnv_tbl_type_out,
11782                                  p_validate_yn        => 'N'
11783                                  );
11784 				         LOG_MESSAGES('CONTRACT_HEADER_OKS_LINES(End_Date) update status: '||l_return_status);
11785 				         IF l_return_status <> G_RET_STS_SUCCESS THEN
11786 				                 IF l_msg_count > 0 Then
11787                                                 FOR i in 1..l_msg_count
11788                                                 LOOP
11789                                                   fnd_msg_pub.get (p_msg_index     => -1,
11790                                                                    p_encoded       => 'F',
11791                                                                    p_data          => l_msg_data,
11792                                                                    p_msg_index_out => l_msg_index_out);
11793                                                   l_message := l_message||' ; '||l_msg_data;
11794                                                 END LOOP;
11795                                           END IF;
11796 				                  LOG_MESSAGES('CONTRACT_OKS_LINES(Contract_End_Date) update status: '||l_return_status);
11797                                           LOG_MESSAGES('Contract oks Lines(Contract_End_Date) Update failed;'||l_message);
11798                                           l_status := 'ERROR';
11799                                           RAISE G_EXCEPTION_HALT_VALIDATION;
11800  					     END IF;
11801 				     END IF;
11802 				     -- Bug Fix 5075961
11803 
11804 
11805                              l_old_k_amount := Get_contract_amount(l_chrv_rec_in.id);
11806                              LOG_MESSAGES('Old Contract Amount:'||l_old_k_amount);
11807 
11808                              OKS_REPRICE_PVT.Call_Pricing_Api(
11809                                         p_api_version         => l_api_version,
11810                                         p_init_msg_list       => l_init_msg_list,
11811                                         P_id        		  => l_chrv_rec_in.id,
11812 				                P_Id_Type		      => 'CHR',
11813                                         x_return_status       => l_return_status,
11814                                         x_msg_count           => l_msg_count,
11815                                         x_msg_data            => l_msg_data);
11816 
11817                               IF  l_return_status = G_RET_STS_SUCCESS THEN
11818                                         LOG_MESSAGES('CONTRACT_HEADER(End_date) Repricing status for lines: '||l_return_status);
11819 
11820 
11821 
11822                                         l_new_k_amount := Get_contract_amount(l_chrv_rec_in.id);
11823                                         LOG_MESSAGES('New Contract Amount:'||l_new_k_amount);
11824                                         l_amt_message := rpad(' ',60,' ')||'Old Contract Amount: '||rpad(to_char(l_old_k_amount),10,' ')||'New Contract Amount: '||rpad(to_char(l_new_k_amount),10,' ');
11825                                         LOG_MESSAGES('CONTRACT_HEADER(End_date) Repricing status: '||l_return_status);
11826 
11827                               ELSE
11828                                        IF l_msg_count > 0
11829                                        THEN
11830                                             FOR i in 1..l_msg_count
11831                                              LOOP
11832                                              fnd_msg_pub.get (p_msg_index     => -1,
11833                                              p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11834                                              p_data          => l_msg_data,
11835                                              p_msg_index_out => l_msg_index_out);
11836                                               l_message := l_message||' ; '||l_msg_data;
11837                                            END LOOP;
11838                                        END IF;
11839 
11840                                          LOG_MESSAGES('CONTRACT_HEADER(Contract_End_Date) Repricing status: '||l_return_status);
11841                                         LOG_MESSAGES('Contract Header(Contract_End_Date) Repricing  failed;'||l_message);
11842                                        l_status := 'ERROR';
11843                                        RAISE G_EXCEPTION_HALT_VALIDATION;
11844                                END IF;
11845 
11846 
11847 
11848 
11849 
11850 
11851                    ELSE
11852                            LOG_MESSAGES('CONTRACT_End_DATE Update_CONTRACT_LINES status: '||l_return_status||',msg_count:'||l_msg_count);
11853                            IF l_msg_count > 0
11854                            THEN
11855                                FOR i in 1..l_msg_count
11856                                LOOP
11857                                fnd_msg_pub.get (p_msg_index     => -1,
11858                                                 p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11859                                                 p_data          => l_msg_data,
11860                                                 p_msg_index_out => l_msg_index_out);
11861 
11862                                 l_message := l_message||' ; '||l_msg_data;
11863                                END LOOP;
11864                              END IF;
11865                              LOG_MESSAGES('Contract Lines Update(CONTRACT_End_DATE) failed;'||l_message);
11866                              l_status := 'ERROR';
11867                              RAISE G_EXCEPTION_HALT_VALIDATION;
11868                     END IF;
11869 
11870                    IF l_clev_tbl_in.COUNT > 0 THEN
11871                         FOR j in 1 .. l_clev_tbl_in.COUNT
11872                         LOOP
11873                         If l_clev_tbl_in(j).lse_id in (1,12,19,46) Then
11874 
11875                         OKS_BILL_SCH.Cascade_Dates_SLL (l_clev_tbl_in(j).id,l_return_status,l_msg_count,l_msg_data) ;
11876 
11877                         IF l_return_status = G_RET_STS_SUCCESS THEN
11878                         LOG_MESSAGES('CONTRACT_HEADER(End_date) Billing Schedule status for lines: '||l_return_status);
11879 
11880                             OPEN  Get_cle_id_PM(l_clev_tbl_in(j).id) ;
11881                             FETCH Get_cle_id_PM INTO l_count_pm_schedule ;
11882                             CLOSE Get_cle_id_PM ;
11883 
11884                             IF l_count_pm_schedule > 0 THEN
11885                                    OKS_PM_PROGRAMS_PVT.ADJUST_PM_PROGRAM_SCHEDULE(
11886                                         p_api_version          => l_api_version,
11887                                         p_init_msg_list        => l_init_msg_list,
11888                                         p_contract_line_id     => l_clev_tbl_in(j).id,
11889                                         p_new_start_date       => NULL,
11890                                         p_new_end_date         => to_date(l_new_value,'YYYY/MM/DD HH24:MI:SS'),
11891                                         x_return_status       => l_return_status,
11892                                         x_msg_count           => l_msg_count,
11893                                         x_msg_data            => l_msg_data);
11894                                         LOG_MESSAGES('CONTRACT_HEADER(End_date) PM Schedule status for lines: '||l_return_status);
11895                                     IF l_return_status  in (G_RET_STS_ERROR,G_RET_STS_UNEXP_ERROR) THEN
11896 
11897 
11898                                          IF l_msg_count > 0 THEN
11899                                          FOR i in 1..l_msg_count
11900                                          LOOP
11901                                              fnd_msg_pub.get (p_msg_index     => -1,
11902                                                               p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11903                                                               p_data          => l_msg_data,
11904                                                               p_msg_index_out => l_msg_index_out);
11905                                              l_message := l_message||' ; '||l_msg_data;
11906                                          END LOOP;
11907                                          END IF;
11908 
11909                                          LOG_MESSAGES('Contract_Header(Contract_End_Date) PM Schedule status: '||l_return_status);
11910                                          LOG_MESSAGES('Contract Header(Contract_End_Date) PM Schedule failed;'||l_message);
11911                                          l_status := 'ERROR';
11912                                          RAISE G_EXCEPTION_HALT_VALIDATION;
11913                                     END IF;
11914                               END IF ;
11915 
11916                         ELSE
11917                                        IF l_msg_count > 0
11918                                        THEN
11919                                        FOR i in 1..l_msg_count
11920                                        LOOP
11921                                            fnd_msg_pub.get (p_msg_index     => -1,
11922                                                             p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
11923                                                             p_data          => l_msg_data,
11924                                                             p_msg_index_out => l_msg_index_out);
11925                                            l_message := l_message||' ; '||l_msg_data;
11926                                        END LOOP;
11927                                        END IF;
11928 
11929                                    LOG_MESSAGES('CONTRACT_HEADER(Contract_End_Date) Billing Schedule status: '||l_return_status);
11930                                    LOG_MESSAGES('Contract Header(Contract_End_Date) Billing Schedule failed;'||l_message);
11931                                    l_status := 'ERROR';
11932                                    RAISE G_EXCEPTION_HALT_VALIDATION;
11933                         END IF;
11934                    End if;
11935                 END LOOP ;
11936               END IF ;
11937 
11938      End If;
11939 
11940   END IF;
11941 
11942 
11943    -- Run QA Check
11944     --  IF l_eligible_contracts_tbl(i).contract_status <> 'ENTERED'
11945      -- IF get_ste_code(l_eligible_contracts_tbl(i).contract_status) <> 'ENTERED'
11946      --  AND l_eligible_contracts_tbl(i).qcl_id IS NOT NULL
11947        IF l_eligible_contracts_tbl(i).qa_check_yn = 'Y' then
11948              l_msg_tbl.DELETE;
11949              LOG_MESSAGES('Starting QA Check ....');
11950 
11951              OKC_QA_CHECK_PUB.execute_qa_check_list(
11952                                       p_api_version     => l_api_version,
11953                                       p_init_msg_list   => l_init_msg_list,
11954                                       x_return_status   => l_return_status,
11955                                       x_msg_count       => l_msg_count,
11956                                       x_msg_data        => l_msg_data,
11957                                       p_qcl_id          => l_eligible_contracts_tbl(i).qcl_id,
11958                                       p_chr_id          => l_eligible_contracts_tbl(i).contract_id,
11959                                       x_msg_tbl         => l_msg_tbl);
11960 
11961                     LOG_MESSAGES('QA Check completed with status :'||l_return_status);
11962              IF l_return_status <>'S' then
11963                 IF l_msg_count > 0
11964                 THEN
11965                   l_message := 'Error while running QA check: ';
11966                   FOR i in 1..l_msg_count
11967                   LOOP
11968                     fnd_msg_pub.get (p_msg_index     => -1,
11969                                      p_encoded       => 'F',
11970                                      p_data          => l_msg_data,
11971                                      p_msg_index_out => l_msg_index_out);
11972                     l_message := l_message||' ; '||l_msg_data;
11973                   END LOOP;
11974                     LOG_MESSAGES(l_message);
11975                     RAISE G_EXCEPTION_HALT_VALIDATION;
11976                 END IF;
11977              ELSE
11978                 l_status := 'SUCCESS';
11979                 FOR j in l_msg_tbl.FIRST .. l_msg_tbl.LAST
11980                 LOOP
11981                    IF l_msg_tbl(j).error_status = 'E' then
11982                       l_status := 'ERROR';
11983                       l_message := 'QA Check failed; ';
11984                       LOG_MESSAGES(l_message||l_msg_tbl(j).data);
11985                    END IF;
11986                 END LOOP;
11987                    If l_status = 'ERROR' then -- Rollback if QA fails
11988                       RAISE G_EXCEPTION_HALT_VALIDATION;
11989                    End If;
11990              END IF; --QA Return Status
11991      END IF; -- QA Check Yes
11992 
11993 End IF; -- Warranty contract yes/no -- currently, we are not runnig QA for warranty contracts
11994 
11995     IF l_status <> 'ERROR' then
11996 
11997        IF  l_criteria_rec.attribute = 'COVERAGE_START_TIME' Then
11998            IF l_cov_time_wrong > 0 and l_cov_time_right = 0 Then
11999               l_message := 'The new Coverage Start time is greater than the coverage end time ';
12000               l_status := 'ERROR' ;
12001               l_cov_time_right := 0 ;
12002               l_cov_time_wrong := 0 ;
12003            ELSE
12004               l_message := 'Successfully Completed';
12005               l_cov_time_right := 0 ;
12006               l_cov_time_wrong := 0 ;
12007 
12008            END IF ;
12009        ELSIF l_criteria_rec.attribute = 'COVERAGE_END_TIME' Then
12010            IF l_cov_time_wrong > 0 and l_cov_time_right = 0 Then
12011              -- LOG_MESSAGES('l_cov_time_wrong in If'||l_cov_time_wrong);
12012               l_message := 'The new Coverage End Time is less than the Coverage Start Time ';
12013               l_status := 'ERROR' ;
12014               l_cov_time_right := 0 ;
12015               l_cov_time_wrong := 0 ;
12016            ELSE
12017                LOG_MESSAGES('l_cov_time_wrong in Else:'||l_cov_time_wrong||'l_cov_time_right:'||l_cov_time_right);
12018                l_message := 'Successfully Completed';
12019                l_cov_time_right := 0 ;
12020                l_cov_time_wrong := 0 ;
12021 
12022            END IF ;
12023        END IF ;
12024       IF p_process_type = 'SUBMIT' then
12025 
12026          l_olev_rec_in.id           := l_eligible_contracts_tbl(i).ole_id;
12027          l_olev_rec_in.process_flag := 'P';
12028 
12029          OKC_OPER_INST_PUB.Update_Operation_Line (
12030                                             p_api_version                  => l_api_version,
12031                                             p_init_msg_list                => l_init_msg_list,
12032                                             x_return_status                => l_return_status,
12033                                             x_msg_count                    => l_msg_count,
12034                                             x_msg_data                     => l_msg_data,
12035                                             p_olev_rec                     => l_olev_rec_in,
12036                                             x_olev_rec                     => l_olev_rec_out);
12037 
12038          --commit;
12039       ELSIF p_process_type = 'PREVIEW' then
12040        DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_MASSCHANGE');
12041 
12042        l_olev_rec_in.id           := l_eligible_contracts_tbl(i).ole_id;
12043        l_olev_rec_in.process_flag := 'A';
12044 
12045          OKC_OPER_INST_PUB.Update_Operation_Line (
12046                                             p_api_version                  => l_api_version,
12047                                             p_init_msg_list                => l_init_msg_list,
12048                                             x_return_status                => l_return_status,
12049                                             x_msg_count                    => l_msg_count,
12050                                             x_msg_data                     => l_msg_data,
12051                                             p_olev_rec                     => l_olev_rec_in,
12052                                             x_olev_rec                     => l_olev_rec_out);
12053         --commit;
12054       END IF;
12055     ELSE
12056        DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_MASSCHANGE');
12057          l_olev_rec_in.id           := l_eligible_contracts_tbl(i).ole_id;
12058          l_olev_rec_in.process_flag := 'E';
12059 
12060          OKC_OPER_INST_PUB.Update_Operation_Line (
12061                                             p_api_version                  => l_api_version,
12062                                             p_init_msg_list                => l_init_msg_list,
12063                                             x_return_status                => l_return_status,
12064                                             x_msg_count                    => l_msg_count,
12065                                             x_msg_data                     => l_msg_data,
12066                                             p_olev_rec                     => l_olev_rec_in,
12067                                             x_olev_rec                     => l_olev_rec_out);
12068 
12069     END IF;
12070 
12071   -- Insert into success tbl
12072 
12073   l_outfile_success_id := l_outfile_success_id + 1 ;
12074 
12075   l_outfiles_succ(l_outfile_success_id).ID := l_outfile_success_id  ;
12076   l_outfiles_succ(l_outfile_success_id).String1 :=
12077           rpad(substr(nvl(l_eligible_contracts_tbl(i).contract_number,' '),1,28),28,' ')||'  '||
12078           rpad(substr(nvl(l_eligible_contracts_tbl(i).contract_number_modifier,' '),1,16),18,' ') ;
12079   l_outfiles_succ(l_outfile_success_id).String2 :=
12080           rpad(substr(nvl(l_eligible_contracts_tbl(i).short_description,' '),1,32),32,' ')||'  '||
12081           rpad(substr(nvl(l_old_value,' '),1,25),25,' ') ;
12082   l_outfiles_succ(l_outfile_success_id).String3 := pad( FND_MESSAGE.get_string('OKS','OKS_SUCCESS'),22)
12083                                                    ||'  '||l_message  || l_billed_at_source_msg ;
12084 
12085     l_amt_message := NULL;
12086     l_success_cnt := l_success_cnt + 1;
12087  EXCEPTION
12088      WHEN G_EXCEPTION_HALT_VALIDATION THEN
12089         l_error_cnt := l_error_cnt + 1;
12090         l_status    := FND_MESSAGE.get_string('OKS','OKS_MSCHG_ERROR');
12091 --        l_status    := 'ERROR';
12092         DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_MASSCHANGE');
12093         LOG_MESSAGES('G_EXCEPTION_HALT_VALIDATION in inner LOOP');
12094         --Update operation lines with ERROR  (revisit)
12095         l_olev_rec_in.id           := l_eligible_contracts_tbl(i).ole_id;
12096         l_olev_rec_in.process_flag := 'E';
12097 
12098          OKC_OPER_INST_PUB.Update_Operation_Line (
12099                                             p_api_version                  => l_api_version,
12100                                             p_init_msg_list                => l_init_msg_list,
12101                                             x_return_status                => l_return_status,
12102                                             x_msg_count                    => l_msg_count,
12103                                             x_msg_data                     => l_msg_data,
12104                                             p_olev_rec                     => l_olev_rec_in,
12105                                             x_olev_rec                     => l_olev_rec_out);
12106      -- Insert into failed tbl
12107 
12108         l_outfile_fail_id := l_outfile_fail_id + 1 ;
12109         l_outfiles_fail(l_outfile_fail_id).ID := l_outfile_fail_id  ;
12110         l_outfiles_fail(l_outfile_fail_id).String1 :=
12111                 rpad(substr(nvl(l_eligible_contracts_tbl(i).contract_number,' '),1,28),28,' ')||'  '||
12112                 rpad(substr(nvl(l_eligible_contracts_tbl(i).contract_number_modifier,' '),1,16),18,' ') ;
12113         l_outfiles_fail(l_outfile_fail_id).String2 :=
12114                 rpad(substr(nvl(l_eligible_contracts_tbl(i).short_description,' '),1,32),32,' ')||'  '||
12115                 rpad(substr(nvl(l_old_value,' '),1,25),25,' ') ;
12116         l_outfiles_fail(l_outfile_fail_id).String3 := pad(l_status,22)||'  '||l_message ;
12117 
12118    WHEN l_notelligible_exception THEN
12119        DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_MASSCHANGE');
12120        LOG_MESSAGES('l_notelligible_exception in inner LOOP');
12121 
12122        l_olev_rec_in.id           := l_eligible_contracts_tbl(i).ole_id;
12123        l_olev_rec_in.process_flag := NULL ;
12124 
12125        OKC_OPER_INST_PUB.Update_Operation_Line (
12126                                             p_api_version                  => l_api_version,
12127                                             p_init_msg_list                => l_init_msg_list,
12128                                             x_return_status                => l_return_status,
12129                                             x_msg_count                    => l_msg_count,
12130                                             x_msg_data                     => l_msg_data,
12131                                             p_olev_rec                     => l_olev_rec_in,
12132                                             x_olev_rec                     => l_olev_rec_out);
12133     l_status  := FND_MESSAGE.get_string('OKS','OKS_MSCHG_NOT_ELIG') ;
12134 --    l_status  := 'NOT ELIGIBLE';
12135     l_message := nvl(l_message,
12136                     FND_MESSAGE.get_string('OKS','OKS_MSCHG_MSG_GEN') );
12137 --    l_message := nvl(l_message,'This Contract does not qualify for mass update');
12138     -- insert into inelligible tbl
12139 
12140       l_outfile_inel_id := l_outfile_inel_id + 1 ;
12141       l_outfiles_inel(l_outfile_inel_id).ID := l_outfile_inel_id  ;
12142       l_outfiles_inel(l_outfile_inel_id).String1 :=
12143            rpad(substr(nvl(l_eligible_contracts_tbl(i).contract_number,' '),1,28),28,' ')||'  '||
12144            rpad(substr(nvl(l_eligible_contracts_tbl(i).contract_number_modifier,' '),1,16),18,' ') ;
12145       l_outfiles_inel(l_outfile_inel_id).String2 :=
12146            rpad(substr(nvl(l_eligible_contracts_tbl(i).short_description,' '),1,32),32,' ')||'  '||
12147            rpad(substr(nvl(l_old_value,' '),1,25),25,' ') ;
12148       l_outfiles_inel(l_outfile_inel_id).String3 := pad(l_status,22)||'  '||l_message ;
12149 
12150 
12151      WHEN OTHERS THEN
12152 
12153        DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_MASSCHANGE');
12154        LOG_MESSAGES('For oie_id:'||p_oie_id||', Others EXCEPTION:'||SQLERRM);
12155        l_error_cnt := l_error_cnt + 1;
12156        l_status    := FND_MESSAGE.get_string('OKS','OKS_MSCHG_ERROR');
12157  --      l_status    := 'ERROR';
12158        l_message   := SQLERRM;
12159 
12160        l_olev_rec_in.id           := l_eligible_contracts_tbl(i).ole_id;
12161        l_olev_rec_in.process_flag := 'E';
12162 
12163        OKC_OPER_INST_PUB.Update_Operation_Line (
12164                                             p_api_version                  => l_api_version,
12165                                             p_init_msg_list                => l_init_msg_list,
12166                                             x_return_status                => l_return_status,
12167                                             x_msg_count                    => l_msg_count,
12168                                             x_msg_data                     => l_msg_data,
12169                                             p_olev_rec                     => l_olev_rec_in,
12170                                             x_olev_rec                     => l_olev_rec_out);
12171         -- insert into error tbl
12172           l_outfile_fail_id := l_outfile_fail_id + 1 ;
12173           l_outfiles_fail(l_outfile_fail_id).ID := l_outfile_fail_id  ;
12174           l_outfiles_fail(l_outfile_fail_id).String1 :=
12175               rpad(substr(nvl(l_eligible_contracts_tbl(i).contract_number,' '),1,28),28,' ')||'  '||
12176               rpad(substr(nvl(l_eligible_contracts_tbl(i).contract_number_modifier,' '),1,16),18,' ') ;
12177           l_outfiles_fail(l_outfile_fail_id).String2 :=
12178               rpad(substr(nvl(l_eligible_contracts_tbl(i).short_description,' '),1,32),32,' ')||'  '||
12179               rpad(substr(nvl(l_old_value,' '),1,25),25,' ') ;
12180           l_outfiles_fail(l_outfile_fail_id).String3 := pad(l_status,22)||'  '||l_message ;
12181 
12182      END;
12183    END LOOP;
12184 
12185           l_oiev_rec_in.id  := p_oie_id;
12186 
12187     IF p_process_type = 'SUBMIT' then
12188        IF l_error_cnt > 0 and l_success_cnt>0 then
12189         l_oiev_rec_in.status_code := 'PARTIALLY_PROCESSED';
12190        ELSIF (l_eligible_contracts_tbl.COUNT > 0 and l_error_cnt = 0) then
12191         l_oiev_rec_in.status_code := 'PROCESSED';
12192        ELSIF l_eligible_contracts_tbl.COUNT = 0  then
12193         l_oiev_rec_in.status_code := 'PROCESSED';
12194         LOG_MESSAGES('No Contracts Elligible for Processing ');
12195         --fnd_file.put_line(FND_FILE.OUTPUT,'No Contracts Eligible for Processing ');
12196        ELSIF l_error_cnt > 0 and l_success_cnt=0 then
12197         l_oiev_rec_in.status_code := 'ERROR';
12198        END IF;
12199     ELSIF p_process_type = 'PREVIEW' then
12200        --IF l_err_cnt > 0 then
12201        --       l_oiev_rec_in.status_code := 'PARTIALLY_PREVIEWED';    -- Check with PM
12202        --       ELSE
12203        l_oiev_rec_in.status_code := 'PREVIEWED';
12204        --       END IF;
12205        IF l_eligible_contracts_tbl.COUNT = 0  then
12206        LOG_MESSAGES('No Contracts Elligible for Processing ');
12207        --fnd_file.put_line(FND_FILE.OUTPUT,'No Contracts Eligible for Processing ');
12208        END IF;
12209     END IF;
12210 
12211 -- Printing Inelligible Contracts
12212     FOR inelligible_rec in Get_inelligibles(l_criteria_rec.oie_id)
12213     LOOP
12214     LOG_MESSAGES('inelligible_rec get_attribute_value call ');
12215         get_attribute_value(p_attr_code  => l_attribute_code,
12216                             p_attr_id    => inelligible_rec.old_value,
12217                             p_org_id     => l_org_id,
12218                             x_attr_value => l_old_value,
12219                             x_attr_name  => l_attribute);
12220 
12221 -- The following portion  commented on 12/16/2003.
12222 -- This code has been moved to place where Inelligible exception is handled.
12223 --  Reason: value for the l_message is only available in exception part.
12224 
12225 --     l_status  := 'NOT ELIGIBLE';
12226 --     l_message := 'This Contract does not qualify for mass update';
12227 --     insert into inelligible tbl
12228 --
12229 --      l_outfile_inel_id := l_outfile_inel_id + 1 ;
12230 --      l_outfiles_inel(l_outfile_inel_id).ID := l_outfile_inel_id  ;
12231 --      l_outfiles_inel(l_outfile_inel_id).String1 := rpad(substr(nvl(inelligible_rec.contract_number,' ')
12232 --       ,1,19),19,' ')||'  '||rpad(substr(nvl(inelligible_rec.contract_number_modifier,' '),1,10),10,' ') ;
12233 --      l_outfiles_inel(l_outfile_inel_id).String2 := rpad(substr(nvl(inelligible_rec.short_description,' ')
12234 --       ,1,26),26,' ')||'  '||rpad(substr(nvl(l_old_value,' '),1,19),19,' ') ;
12235 --      l_outfiles_inel(l_outfile_inel_id).String3 := l_status||'  '||l_message ;
12236 
12237 
12238       l_olev_rec_in.id           := inelligible_rec.ole_id;
12239       l_olev_rec_in.process_flag := 'N';
12240 
12241       OKC_OPER_INST_PUB.Update_Operation_Line (
12242                                             p_api_version                  => l_api_version,
12243                                             p_init_msg_list                => l_init_msg_list,
12244                                             x_return_status                => l_return_status,
12245                                             x_msg_count                    => l_msg_count,
12246                                             x_msg_data                     => l_msg_data,
12247                                             p_olev_rec                     => l_olev_rec_in,
12248                                             x_olev_rec                     => l_olev_rec_out);
12249 
12250        LOG_MESSAGES(' OKC_OPER_INST_PUB.Update_Operation_Line:  '||l_return_status);
12251 
12252             IF  l_return_status <> 'S' then
12253                IF l_msg_count > 0
12254               THEN
12255               FOR i in 1..l_msg_count
12256               LOOP
12257                  fnd_msg_pub.get (p_msg_index     => -1,
12258                                   p_encoded       => 'F',
12259                                   p_data          => l_msg_data,
12260                                   p_msg_index_out => l_msg_index_out);
12261                 LOG_MESSAGES('inel Update_Operation_Line: '||l_msg_data);
12262               END LOOP;
12263               END IF;
12264            END IF;
12265 
12266     END LOOP;
12267 
12268     IF l_oiev_rec_in.status_code is NOT NULL then
12269 
12270      OKC_OPER_INST_PUB.Update_Operation_Instance (
12271                                             p_api_version                  => l_api_version,
12272                                             p_init_msg_list                => l_init_msg_list,
12273                                             x_return_status                => l_return_status,
12274                                             x_msg_count                    => l_msg_count,
12275                                             x_msg_data                     => l_msg_data,
12276                                             p_oiev_rec                     => l_oiev_rec_in,
12277                                             x_oiev_rec                     => l_oiev_rec_out);
12278     END IF;
12279 
12280 -- Code for printing Mass Change Report Starts here.
12281 -- This code was modified to make the report headings translatable in Mar 2004.
12282 -- Bug#3337646
12283 
12284         get_attribute_value(p_attr_code  => l_attribute_code,
12285                             p_attr_id    => l_criteria_rec.old_value,
12286                             p_org_id     => l_org_id ,
12287                             x_attr_value => l_old_value,
12288                             x_attr_name  => l_attribute);
12289 
12290         If p_process_type = 'PREVIEW' then
12291            l_process_type_msg_seed := 'OKS_MSCHG_PREVIEW';
12292         Else
12293            l_process_type_msg_seed := 'OKS_MSCHG_SUBMIT';
12294         End If;
12295 
12296   l_empty_string1 :='     ';
12297   l_dash_string1  :='------------------------------';
12298 
12299   fnd_file.new_line(FND_FILE.OUTPUT, 1);
12300   fnd_file.put_line(FND_FILE.OUTPUT, pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_MSCHG')||
12301                                      ' '||FND_MESSAGE.get_string('OKS',l_process_type_msg_seed)||' '||
12302                                      FND_MESSAGE.get_string('OKS','OKS_MSCHG_RPT'),45,'L') );
12303   fnd_file.put_line(FND_FILE.OUTPUT, pad(pad('****',
12304                                      length(FND_MESSAGE.get_string('OKS','OKS_MSCHG_MSCHG')||
12305                                            FND_MESSAGE.get_string('OKS',l_process_type_msg_seed)||
12306                                            FND_MESSAGE.get_string('OKS','OKS_MSCHG_RPT')
12307                                             )+2,'R','*'),45,'L') );
12308   fnd_file.new_line(FND_FILE.OUTPUT, 2);
12309   fnd_file.put_line(FND_FILE.OUTPUT, pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_NAME'),35)
12310                                      ||':  '||l_masschange_name);
12311   fnd_file.new_line(FND_FILE.OUTPUT, 1);
12312   fnd_file.put_line(FND_FILE.OUTPUT, pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_SCOPE'),35) );
12313   fnd_file.put_line(FND_FILE.OUTPUT, pad(l_empty_string1
12314                                      ||FND_MESSAGE.get_string('OKS','OKS_MSCHG_UPD_LVL'),35)
12315                                      ||':  '||l_update_level);
12316   fnd_file.put_line(FND_FILE.OUTPUT, pad(l_empty_string1
12317                                      ||FND_MESSAGE.get_string('OKS','OKS_MSCHG_UPD_LVL_VAL'),35)
12318                                      ||':  '|| l_update_level_value);
12319   fnd_file.new_line(FND_FILE.OUTPUT, 1);
12320   fnd_file.put_line(FND_FILE.OUTPUT, pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_CRIT'),40) );
12321   fnd_file.put_line(FND_FILE.OUTPUT, pad(l_empty_string1
12322                                      ||FND_MESSAGE.get_string('OKS','OKS_MSCHG_ATTR'),35)
12323                                      ||':  '||l_attribute);
12324   fnd_file.put_line(FND_FILE.OUTPUT, pad(l_empty_string1
12325                                      ||FND_MESSAGE.get_string('OKS','OKS_MSCHG_OLD_VAL'),35)
12326                                      ||':  '||l_old_value);
12327   fnd_file.put_line(FND_FILE.OUTPUT, pad(l_empty_string1
12328                                      ||FND_MESSAGE.get_string('OKS','OKS_MSCHG_NEW_VAL'),35)
12329                                      ||':  '||l_new_value);
12330 
12331 --  fnd_file.put_line(FND_FILE.OUTPUT, l_star_string1||l_star_string1||l_star_string1||
12332 --                                     l_star_string1||l_star_string1 );
12333 
12334   fnd_file.new_line(FND_FILE.OUTPUT, 1);
12335   fnd_file.new_line(FND_FILE.OUTPUT, 1);
12336 
12337 
12338         l_succ_count  := l_outfiles_succ.count  ;
12339         l_fail_count  := l_outfiles_fail.count  ;
12340         l_inel_count  := l_outfiles_inel.count  ;
12341         l_total_rec_count := nvl(l_succ_count,0) + nvl(l_fail_count,0) + nvl(l_inel_count,0) ;
12342 
12343     fnd_file.put_line(FND_FILE.OUTPUT,FND_MESSAGE.get_string('OKS','OKS_MSCHG_SUMM') ) ;
12344     fnd_file.put_line(FND_FILE.OUTPUT,'****************') ;
12345     fnd_file.new_line(FND_FILE.OUTPUT,1) ;
12346     fnd_file.put_line(FND_FILE.OUTPUT,pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_SUCC_CON'),50)
12347                                          ||': '||l_outfiles_succ.count) ;
12348     fnd_file.put_line(FND_FILE.OUTPUT,pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_FAIL_CON'),50)
12349                                          ||': '||l_outfiles_fail.count) ;
12350     fnd_file.put_line(FND_FILE.OUTPUT,pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_INELG_CON'),50)
12351                                          ||': '||l_outfiles_inel.count) ;
12352     fnd_file.put_line(FND_FILE.OUTPUT,pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_TOT_PROC'),50)
12353                                          ||': '||l_total_rec_count ) ;
12354     fnd_file.new_line(FND_FILE.OUTPUT,1) ;
12355     fnd_file.put_line(FND_FILE.OUTPUT, FND_MESSAGE.get_string('OKS','OKS_MSCHG_DET')) ;
12356     fnd_file.put_line(FND_FILE.OUTPUT,'****************') ;
12357     fnd_file.new_line(FND_FILE.OUTPUT,1) ;
12358     fnd_file.put_line(FND_FILE.OUTPUT, FND_MESSAGE.get_string('OKS','OKS_MSCHG_LIST_SUCC') ) ;
12359     fnd_file.put_line(FND_FILE.OUTPUT, l_dash_string1||l_dash_string1||
12360                                        l_dash_string1||l_dash_string1||l_dash_string1);
12361     fnd_file.put_line(FND_FILE.OUTPUT,
12362                      pad(FND_MESSAGE.get_string('OKS','OKS_VAL_CONTRACT_NO'),30) ||
12363                      pad(FND_MESSAGE.get_string('OKS','OKS_VAL_MODIFIER'),18)    ||
12364                      pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_CON_DECS'),34)  ||
12365                      pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_OLD_VAL'),25)   ||
12366                      pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_PROC_STAT'),24) ||
12367                      FND_MESSAGE.get_string('OKS','OKS_MSCHG_PROC_REM') );
12368     fnd_file.put_line(FND_FILE.OUTPUT, l_dash_string1||l_dash_string1||
12369                                        l_dash_string1||l_dash_string1||l_dash_string1);
12370 
12371     IF NVL(l_outfiles_succ.count,0) > 0 then
12372         For i in 1..l_outfiles_succ.count LOOP
12373             fnd_file.put_line(FND_FILE.OUTPUT,l_outfiles_succ(i).String1||
12374                                    l_outfiles_succ(i).String2||
12375                                    l_outfiles_succ(i).String3) ;
12376         END LOOP ;
12377     END IF ;
12378 
12379     fnd_file.new_line(FND_FILE.OUTPUT,1) ;
12380     fnd_file.new_line(FND_FILE.OUTPUT,1) ;
12381     fnd_file.put_line(FND_FILE.OUTPUT,FND_MESSAGE.get_string('OKS','OKS_MSCHG_LIST_FAIL') ) ;
12382     fnd_file.put_line(FND_FILE.OUTPUT, l_dash_string1||l_dash_string1||
12383                                        l_dash_string1||l_dash_string1||l_dash_string1);
12384 
12385     fnd_file.put_line(FND_FILE.OUTPUT,
12386                      pad(FND_MESSAGE.get_string('OKS','OKS_VAL_CONTRACT_NO'),30) ||
12387                      pad(FND_MESSAGE.get_string('OKS','OKS_VAL_MODIFIER'),18)    ||
12388                      pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_CON_DECS'),34)  ||
12389                      pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_OLD_VAL'),25)   ||
12390                      pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_PROC_STAT'),24) ||
12391                      FND_MESSAGE.get_string('OKS','OKS_MSCHG_PROC_REM') );
12392 
12393     fnd_file.put_line(FND_FILE.OUTPUT, l_dash_string1||l_dash_string1||
12394                                        l_dash_string1||l_dash_string1||l_dash_string1);
12395     For j in 1..l_outfiles_fail.count LOOP
12396         fnd_file.put_line(FND_FILE.OUTPUT,l_outfiles_fail(j).String1||
12397                                           l_outfiles_fail(j).String2||
12398                                           l_outfiles_fail(j).String3) ;
12399     END LOOP ;
12400 
12401     fnd_file.new_line(FND_FILE.OUTPUT,1) ;
12402     fnd_file.new_line(FND_FILE.OUTPUT,1) ;
12403     fnd_file.put_line(FND_FILE.OUTPUT,FND_MESSAGE.get_string('OKS','OKS_MSCHG_LIST_INELG') ) ;
12404     fnd_file.put_line(FND_FILE.OUTPUT, l_dash_string1||l_dash_string1||
12405                                        l_dash_string1||l_dash_string1||l_dash_string1);
12406 
12407     fnd_file.put_line(FND_FILE.OUTPUT,
12408                      pad(FND_MESSAGE.get_string('OKS','OKS_VAL_CONTRACT_NO'),30) ||
12409                      pad(FND_MESSAGE.get_string('OKS','OKS_VAL_MODIFIER'),18)    ||
12410                      pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_CON_DECS'),34)  ||
12411                      pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_OLD_VAL'),25)   ||
12412                      pad(FND_MESSAGE.get_string('OKS','OKS_MSCHG_PROC_STAT'),24) ||
12413                      FND_MESSAGE.get_string('OKS','OKS_MSCHG_PROC_REM') );
12414 
12415     fnd_file.put_line(FND_FILE.OUTPUT, l_dash_string1||l_dash_string1||
12416                                        l_dash_string1||l_dash_string1||l_dash_string1);
12417     For k in 1..l_outfiles_inel.count LOOP
12418         fnd_file.put_line(FND_FILE.OUTPUT,l_outfiles_inel(k).String1||
12419                                           l_outfiles_inel(k).String2||
12420                                           l_outfiles_inel(k).String3) ;
12421     END LOOP ;
12422     fnd_file.new_line(FND_FILE.OUTPUT,1) ;
12423     fnd_file.new_line(FND_FILE.OUTPUT,1) ;
12424     fnd_file.new_line(FND_FILE.OUTPUT,1) ;
12425     fnd_file.put_line(FND_FILE.OUTPUT, pad('********* '
12426                                      ||FND_MESSAGE.get_string('OKS','OKS_MSCHG_RPT_END')
12427                                      ||' *********',45,'L') );
12428 
12429  EXCEPTION
12430      WHEN OTHERS THEN
12431          DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_MASSCHANGE_START');
12432          LOG_MESSAGES('For oie_id:'||p_oie_id||', Others EXCEPTION in outer:'||SQLERRM);
12433          l_oiev_rec_in.id  := p_oie_id;
12434          l_oiev_rec_in.status_code := 'ERROR';
12435          OKC_OPER_INST_PUB.Update_Operation_Instance (
12436                                             p_api_version                  => l_api_version,
12437                                             p_init_msg_list                => l_init_msg_list,
12438                                             x_return_status                => l_return_status,
12439                                             x_msg_count                    => l_msg_count,
12440                                             x_msg_data                     => l_msg_data,
12441                                             p_oiev_rec                     => l_oiev_rec_in,
12442                                             x_oiev_rec                     => l_oiev_rec_out);
12443          LOG_MESSAGES('Update_Operation_instance status:'||l_return_status);
12444          commit;
12445  END Submit;
12446 
12447  PROCEDURE LOCK_CONTRACT_HEADER(p_header_id IN NUMBER,
12448                                 p_object_version_number IN NUMBER,
12449                                 x_return_status OUT NOCOPY Varchar2) IS
12450 
12451  l_api_version		CONSTANT	NUMBER	:= 1.0;
12452  l_init_msg_list	VARCHAR2(2000) := OKC_API.G_FALSE;
12453  l_return_status	VARCHAR2(1);
12454  l_msg_count		NUMBER;
12455  l_msg_data	       VARCHAR2(2000);
12456  l_msg_index_out	NUMBER;
12457  l_chrv_tbl_in      okc_contract_pub.chrv_tbl_type;
12458  l_chrv_tbl_out     okc_contract_pub.chrv_tbl_type;
12459 
12460  BEGIN
12461  l_chrv_tbl_in(1).id		                  := p_header_id;
12462  l_chrv_tbl_in(1).object_version_number       := p_object_version_number;
12463  okc_contract_pub.lock_contract_header (
12464     	p_api_version			=> l_api_version,
12465     	p_init_msg_list			=> l_init_msg_list,
12466     	x_return_status			=> l_return_status,
12467     	x_msg_count			=> l_msg_count,
12468     	x_msg_data			=> l_msg_data,
12469     	p_chrv_tbl			=> l_chrv_tbl_in
12470     );
12471  LOG_MESSAGES('LOCK_CONTRACT_HEADER l_return_status = ' || l_return_status);
12472  IF (l_return_status <> OKC_API.G_RET_STS_SUCCESS) THEN
12473 	RAISE APP_EXCEPTIONS.RECORD_LOCK_EXCEPTION;
12474  END IF;
12475       x_return_status := l_return_status;
12476  END LOCK_CONTRACT_HEADER;
12477 
12478  PROCEDURE UPDATE_CONTRACT(p_chrv_rec       IN  okc_contract_pub.chrv_rec_type,
12479                            x_return_status  OUT NOCOPY VARCHAR2) IS
12480  l_api_version		CONSTANT	NUMBER	:= 1.0;
12481  l_init_msg_list	VARCHAR2(2000) := OKC_API.G_FALSE;
12482  l_return_status	VARCHAR2(1);
12483  l_msg_count		NUMBER;
12484  l_msg_data		VARCHAR2(2000);
12485  l_msg_index_out	NUMBER;
12486 
12487  l_chrv_rec_out            okc_contract_pub.chrv_rec_type;
12488 
12489  BEGIN
12490 
12491  LOG_MESSAGES(' UPDATEing Contract, header_id = ' ||p_chrv_rec.id);
12492  x_return_status := OKC_API.G_RET_STS_SUCCESS;
12493 
12494  IF p_chrv_rec.id IS NOT NULL THEN
12495  okc_contract_pub.update_contract_header (
12496     	p_api_version		=> l_api_version,
12497     	p_init_msg_list		=> l_init_msg_list,
12498     	x_return_status		=> l_return_status,
12499     	x_msg_count		=> l_msg_count,
12500     	x_msg_data		=> l_msg_data,
12501     	p_chrv_rec		=> p_chrv_rec,
12502     	x_chrv_rec		=> l_chrv_rec_out );
12503 
12504      LOG_MESSAGES('okc_contract_pub.update_contract_header l_return_status = ' || l_return_status);
12505     x_return_status := l_return_status;
12506     IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
12507       LOG_MESSAGES('okc_contract_pub.update_contract_header l_msg_data = ' || l_msg_data);
12508       RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
12509     ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
12510       LOG_MESSAGES('okc_contract_pub.update_contract_header l_msg_data = ' || l_msg_data);
12511       RAISE OKC_API.G_EXCEPTION_ERROR;
12512     END IF;
12513  END IF;
12514  END UPDATE_CONTRACT;
12515 
12516  PROCEDURE LOG_MESSAGES(p_mesg IN VARCHAR2) IS
12517  BEGIN
12518      IF nvl(l_conc_program,'N') = 'N' THEN
12519           --dbms_output.put_line(p_mesg);
12520           NULL;
12521      ELSE
12522          fnd_file.put_line(FND_FILE.LOG, p_mesg);
12523      END IF;
12524  END LOG_MESSAGES;
12525 
12526 PROCEDURE CREATE_OPERATION_INSTANCES (p_oie_rec  IN opr_instance_rec_type,
12527                                       p_mrd_rec  IN masschange_request_rec_type,
12528                                       x_oie_id   OUT NOCOPY NUMBER) is
12529 ------------------------------------------------------------------
12530 ---TAPI variables
12531 ------------------------------------------------------------------
12532   l_api_version		CONSTANT	NUMBER	:= 1.0;
12533   l_init_msg_list	VARCHAR2(2000) := OKC_API.G_FALSE;
12534   l_return_status	VARCHAR2(1);
12535   l_msg_count		NUMBER;
12536   l_msg_data		VARCHAR2(2000);
12537 
12538   l_msg_index_out	NUMBER;
12539 
12540   l_oiev_tbl_in         OKC_OPER_INST_PUB.oiev_tbl_type; --OPERATION INSTANCE
12541   l_oiev_tbl_out        OKC_OPER_INST_PUB.oiev_tbl_type; --OPERATION INSTANCE
12542 
12543   l_omrv_rec_in         OKC_OPER_INST_PUB.mrdv_rec_type;
12544   l_omrv_rec_out        OKC_OPER_INST_PUB.mrdv_rec_type;
12545 
12546   l_omrv_tbl_in         OKC_OPER_INST_PUB.oiev_tbl_type;
12547   l_omrv_tbl_out        OKC_OPER_INST_PUB.oiev_tbl_type;
12548 
12549   l_mod_rec_in          OKS_MOD_PVT.OksMschgOperationsDtlsVRecType;
12550   l_mod_rec_out         OKS_MOD_PVT.OksMschgOperationsDtlsVRecType;
12551 
12552   x_mrd_id              NUMBER ;
12553 --------------------------------------------------------------------
12554 ---Program Variables
12555 --------------------------------------------------------------------
12556   p_class_operation_id NUMBER := 0;
12557 -------------------------------------------------------------------------
12558 ---Find the Class Operation ID to be used
12559 --------------------------------------------------------------------------
12560   CURSOR class_operations is
12561   SELECT ID from OKC_CLASS_OPERATIONS_V
12562   WHERE OPN_CODE = 'MASS_CHANGE' and CLS_CODE = 'SERVICE';
12563 
12564 BEGIN
12565        --dbms_output.put_line('Inside ..');
12566    FOR cur_class_operations in class_operations
12567    LOOP
12568     p_class_operation_id := cur_class_operations.id;
12569     EXIT;
12570    END LOOP;
12571 
12572     l_oiev_tbl_in(1).name                            := p_oie_rec.NAME;
12573     l_oiev_tbl_in(1).cop_id                          := p_class_operation_id;
12574 --    l_oiev_tbl_in(1).status_code :=  G_OI_STATUS_CODE;
12575     if (p_oie_rec.status_code  is NULL) then  --OR ( p_oie_rec.status_code  = OKC_API.G_MISS_CHAR)) then
12576        l_oiev_tbl_in(1).status_code :=  G_OI_STATUS_CODE;
12577     else
12578        l_oiev_tbl_in(1).status_code := p_oie_rec.status_code; --G_OI_STATUS_CODE;
12579     end if;
12580     l_oiev_tbl_in(1).target_chr_id                   := NULL ; --OKC_API.G_MISS_NUM;
12581     l_oiev_tbl_in(1).object1_id1                     := p_oie_rec.update_level_value;
12582     l_oiev_tbl_in(1).object1_id2                     := '#';
12583     l_oiev_tbl_in(1).jtot_object1_code               := p_oie_rec.update_level;
12584     l_oiev_tbl_in(1).object_version_number           := NULL ; --OKC_API.G_MISS_NUM;
12585     l_oiev_tbl_in(1).created_by                      := NULL ; --OKC_API.G_MISS_NUM;
12586     l_oiev_tbl_in(1).creation_date                   := SYSDATE;
12587     l_oiev_tbl_in(1).last_updated_by                 := NULL ; --OKC_API.G_MISS_NUM;
12588     l_oiev_tbl_in(1).last_update_date                := SYSDATE;
12589     l_oiev_tbl_in(1).last_update_login               := NULL ; --OKC_API.G_MISS_NUM;
12590 
12591         OKC_OPER_INST_PUB.Create_Operation_Instance(
12592     	p_api_version					=> l_api_version,
12593     	p_init_msg_list					=> l_init_msg_list,
12594     	x_return_status					=> l_return_status,
12595     	x_msg_count					    => l_msg_count,
12596     	x_msg_data					    => l_msg_data,
12597     	p_oiev_tbl					    => l_oiev_tbl_in,
12598     	x_oiev_tbl					    => l_oiev_tbl_out);
12599 
12600 
12601     x_oie_id := l_oiev_tbl_out(1).id;
12602 
12603 
12604     IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
12605       RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
12606 /*      IF l_msg_count > 0
12607       THEN
12608        FOR i in 1..l_msg_count
12609        LOOP
12610         fnd_msg_pub.get (p_msg_index     => -1,
12611                          p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
12612                          p_data          => l_msg_data,
12613                          p_msg_index_out => l_msg_index_out);
12614        END LOOP;
12615      END IF;
12616         --dbms_output.put_line('Value of l_return_status:'||l_return_status||'l_msg_data='||l_msg_data);
12617         */
12618     ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
12619       RAISE OKC_API.G_EXCEPTION_ERROR;
12620 /*      IF l_msg_count > 0
12621       THEN
12622        FOR i in 1..l_msg_count
12623        LOOP
12624         fnd_msg_pub.get (p_msg_index     => -1,
12625                          p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
12626                          p_data          => l_msg_data,
12627                          p_msg_index_out => l_msg_index_out);
12628        END LOOP;
12629      END IF;
12630         --dbms_output.put_line('Value of l_return_status:'||l_return_status||'l_msg_data='||l_msg_data); */
12631     ELSIF (l_return_status = OKC_API.G_RET_STS_SUCCESS) THEN
12632 
12633   IF p_mrd_rec.attribute_name is not null then
12634     l_omrv_rec_in.id                              := null;
12635     l_omrv_rec_in.oie_id                          := x_oie_id;
12636     l_omrv_rec_in.ole_id                          := null;
12637     l_omrv_rec_in.attribute_name                  := p_mrd_rec.attribute_name;
12638     l_omrv_rec_in.old_value                       := p_mrd_rec.old_value;
12639     l_omrv_rec_in.new_value                       := p_mrd_rec.new_value;
12640     l_omrv_rec_in.object_version_number           := NULL ; --OKC_API.G_MISS_NUM;
12641     l_omrv_rec_in.created_by                      := NULL ; --OKC_API.G_MISS_NUM;
12642     l_omrv_rec_in.creation_date                   := SYSDATE;
12643  --   l_omrv_rec_in.last_updated_by                 := OKC_API.G_MISS_NUM;
12644     l_omrv_rec_in.last_update_date                := SYSDATE;
12645     l_omrv_rec_in.last_update_login               := NULL ; --OKC_API.G_MISS_NUM;
12646 
12647 
12648      OKC_OPER_INST_PUB.Create_Masschange_Dtls(
12649                             	p_api_version					=> l_api_version,
12650     	                        p_init_msg_list					=> l_init_msg_list,
12651     	                        x_return_status					=> l_return_status,
12652     	                        x_msg_count					    => l_msg_count,
12653     	                        x_msg_data					    => l_msg_data,
12654                                 p_mrdv_rec                      => l_omrv_rec_in,
12655                                 x_mrdv_rec                      => l_omrv_rec_out);
12656 
12657         --dbms_output.put_line('Omr status:'||l_return_status);
12658 
12659         IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
12660             RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
12661         ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
12662             RAISE OKC_API.G_EXCEPTION_ERROR;
12663         END IF;
12664 
12665 --    x_mrd_id := l_omrv_rec_out.id;
12666 
12667     l_mod_rec_in.id                              := null;
12668     l_mod_rec_in.mrd_id                          := l_omrv_rec_out.id ;
12669     l_mod_rec_in.oie_id                          := x_oie_id;
12670     l_mod_rec_in.ole_id                          := null;
12671     l_mod_rec_in.mschg_type                      := null;
12672     l_mod_rec_in.attribute_level                 := null;
12673     l_mod_rec_in.qa_check_yn                     := null; --p_mrd_rec.qa_check_yn;
12674     l_mod_rec_in.object_version_number           := NULL ; --OKC_API.G_MISS_NUM;
12675     l_mod_rec_in.created_by                      := NULL ; --OKC_API.G_MISS_NUM;
12676     l_mod_rec_in.creation_date                   := SYSDATE;
12677     l_mod_rec_in.last_updated_by                 := NULL ; --OKC_API.G_MISS_NUM;
12678     l_mod_rec_in.last_update_date                := SYSDATE;
12679    -- l_mod_rec_in.last_update_login               := NULL ; --OKC_API.G_MISS_NUM;
12680    -- l_mod_rec_in.security_group_id               := NULL ;
12681    -- l_mod_rec_in.attribute1                      := NULL ;
12682    -- l_mod_rec_in.attribute2                      := NULL ;
12683    -- l_mod_rec_in.attribute3                      := NULL ;
12684    -- l_mod_rec_in.attribute4                      := NULL ;
12685    -- l_mod_rec_in.attribute5                      := NULL ;
12686    -- l_mod_rec_in.attribute6                      := NULL ;
12687    -- l_mod_rec_in.attribute7                      := NULL ;
12688    -- l_mod_rec_in.attribute8                      := NULL ;
12689    -- l_mod_rec_in.attribute9                      := NULL ;
12690    -- l_mod_rec_in.attribute10                     := NULL ;
12691    -- l_mod_rec_in.attribute11                     := NULL ;
12692    -- l_mod_rec_in.attribute12                     := NULL ;
12693    -- l_mod_rec_in.attribute13                     := NULL ;
12694    -- l_mod_rec_in.attribute14                     := NULL ;
12695    -- l_mod_rec_in.attribute15                     := NULL ;
12696 
12697       OKS_MOD_PVT.insert_row(  	p_api_version					=> l_api_version,
12698     	                        p_init_msg_list					=> l_init_msg_list,
12699     	                        x_return_status					=> l_return_status,
12700     	                        x_msg_count					    => l_msg_count,
12701     	                        x_msg_data					    => l_msg_data,
12702                                 p_OksMschgOperationsDtlsVRec    => l_mod_rec_in,
12703                                 XOksMschgOperationsDtlsVRec     => l_mod_rec_out);
12704 
12705 
12706 
12707 
12708         IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
12709             RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
12710         ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
12711             RAISE OKC_API.G_EXCEPTION_ERROR;
12712         END IF;
12713 
12714     end if;
12715    END IF;
12716 
12717 END CREATE_OPERATION_INSTANCES;
12718 
12719 PROCEDURE UPDATE_OPERATION_INSTANCES (p_oie_rec  IN opr_instance_rec_type,
12720                                       p_mrd_rec  IN masschange_request_rec_type,
12721                                       x_return_status OUT NOCOPY Varchar2) is
12722 ------------------------------------------------------------------
12723 ---TAPI variables
12724 ------------------------------------------------------------------
12725   l_api_version		CONSTANT	NUMBER	:= 1.0;
12726   l_init_msg_list	VARCHAR2(2000) := OKC_API.G_FALSE;
12727   l_return_status	VARCHAR2(1);
12728   l_msg_count		NUMBER;
12729   l_msg_data		VARCHAR2(2000);
12730 
12731   l_msg_index_out	NUMBER;
12732 
12733   l_oiev_tbl_in         OKC_OPER_INST_PUB.oiev_tbl_type; --OPERATION INSTANCE
12734   l_oiev_tbl_out        OKC_OPER_INST_PUB.oiev_tbl_type; --OPERATION INSTANCE
12735 
12736   l_omrv_rec_in         OKC_OPER_INST_PUB.mrdv_rec_type;
12737   l_omrv_rec_out        OKC_OPER_INST_PUB.mrdv_rec_type;
12738 
12739   l_omrv_tbl_in         OKC_OPER_INST_PUB.oiev_tbl_type;
12740   l_omrv_tbl_out        OKC_OPER_INST_PUB.oiev_tbl_type;
12741 
12742   CURSOR Get_line_req(p_oie_id IN Number) IS
12743          SELECT id from okc_masschange_req_dtls_v
12744          WHERE  oie_id = p_oie_id;
12745 BEGIN
12746        --dbms_output.put_line('Inside ..');
12747 
12748     l_oiev_tbl_in(1).id                              := p_oie_rec.oie_id; --OKC_API.G_MISS_CHAR;
12749     l_oiev_tbl_in(1).name                            := p_oie_rec.NAME; --OKC_API.G_MISS_CHAR;
12750     l_oiev_tbl_in(1).object1_id1                     := p_oie_rec.update_level_value;
12751     l_oiev_tbl_in(1).jtot_object1_code               := p_oie_rec.update_level;
12752 
12753 
12754 /*
12755        OKC_OPER_INST_PUB.UPdate_Operation_Instance(
12756     	p_api_version					=> l_api_version,
12757     	p_init_msg_list					=> l_init_msg_list,
12758     	x_return_status					=> l_return_status,
12759     	x_msg_count					    => l_msg_count,
12760     	x_msg_data					    => l_msg_data,
12761     	p_oiev_rec					    => l_oiev_tbl_in(1),
12762     	x_oiev_rec					    => l_oiev_tbl_out(1));
12763 
12764         --dbms_output.put_line('Value of upd_opn_inst l_return_status='||l_return_status);
12765 
12766 
12767        --dbms_output.put_line('oie_id:'||l_oiev_tbl_out(1).id||',status:'||l_return_status);
12768     IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
12769       RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
12770     ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
12771       RAISE OKC_API.G_EXCEPTION_ERROR;
12772         --dbms_output.put_line('Value of l_return_status:'||l_return_status||'l_msg_data='||l_msg_data);
12773     ELSIF (l_return_status = OKC_API.G_RET_STS_SUCCESS) THEN
12774 */
12775         --dbms_output.put_line('Assigning ..');
12776 
12777         OPEN Get_line_req(p_mrd_rec.oie_id);
12778         FETCH Get_line_req INTO l_omrv_rec_in.id;
12779         CLOSE Get_line_req;
12780         --dbms_output.put_line('l_omrv_rec_in.id:'||l_omrv_rec_in.id);
12781 --    l_omrv_rec_in.id                              := p_mrd_rec.id;
12782     --l_omrv_rec_in.ole_id                          := NULL;
12783     l_omrv_rec_in.oie_id                          := p_mrd_rec.oie_id;
12784     l_omrv_rec_in.attribute_name                  := p_mrd_rec.attribute_name;
12785     l_omrv_rec_in.old_value                       := p_mrd_rec.old_value;
12786     l_omrv_rec_in.new_value                       := p_mrd_rec.new_value;
12787 
12788 
12789         --dbms_output.put_line('Calling ..');
12790 
12791      OKC_OPER_INST_PUB.Update_Masschange_Dtls(
12792                             	p_api_version					=> l_api_version,
12793     	                        p_init_msg_list					=> l_init_msg_list,
12794     	                        x_return_status					=> l_return_status,
12795     	                        x_msg_count					    => l_msg_count,
12796     	                        x_msg_data					    => l_msg_data,
12797                                 p_mrdv_rec                      => l_omrv_rec_in,
12798                                 x_mrdv_rec                      => l_omrv_rec_out);
12799 
12800         --dbms_output.put_line('Omr status:'||l_return_status);
12801 
12802         IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
12803             RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
12804         ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
12805             RAISE OKC_API.G_EXCEPTION_ERROR;
12806         END IF;
12807        OKC_OPER_INST_PUB.UPdate_Operation_Instance(
12808     	p_api_version					=> l_api_version,
12809     	p_init_msg_list					=> l_init_msg_list,
12810     	x_return_status					=> l_return_status,
12811     	x_msg_count					    => l_msg_count,
12812     	x_msg_data					    => l_msg_data,
12813     	p_oiev_rec					    => l_oiev_tbl_in(1),
12814     	x_oiev_rec					    => l_oiev_tbl_out(1));
12815 
12816         --dbms_output.put_line('Value of upd_opn_inst l_return_status='||l_return_status);
12817 
12818 --   END IF;
12819    x_return_status := l_return_status;
12820 EXCEPTION WHEN OTHERS THEN
12821         log_messages('EXCEPTION:'||SQLERRM);
12822         --dbms_output.put_line('EXCEPTION:'||SQLERRM);
12823 END UPDATE_OPERATION_INSTANCES;
12824 
12825 PROCEDURE DELETE_OPERATION_INSTANCES (p_oie_rec  IN opr_instance_rec_type,
12826                                       x_return_status OUT NOCOPY Varchar2) is
12827 ------------------------------------------------------------------
12828 ---TAPI variables
12829 ------------------------------------------------------------------
12830   l_api_version		CONSTANT	NUMBER	:= 1.0;
12831   l_init_msg_list	VARCHAR2(2000) := OKC_API.G_FALSE;
12832   l_return_status	VARCHAR2(1);
12833   l_msg_count		NUMBER;
12834   l_msg_data		VARCHAR2(2000);
12835 
12836   l_msg_index_out	NUMBER;
12837 
12838   l_oiev_tbl_in         OKC_OPER_INST_PUB.oiev_tbl_type; --OPERATION INSTANCE
12839   l_oiev_tbl_out        OKC_OPER_INST_PUB.oiev_tbl_type; --OPERATION INSTANCE
12840 
12841 --/*
12842 --  l_omrv_rec_in         OKC_OPER_INST_PUB.mrdv_rec_type;
12843 --  l_omrv_rec_out        OKC_OPER_INST_PUB.mrdv_rec_type;
12844 
12845 --  l_omrv_tbl_in         OKC_OPER_INST_PUB.oiev_tbl_type;
12846 --  l_omrv_tbl_out        OKC_OPER_INST_PUB.oiev_tbl_type;
12847 
12848 -- CURSOR omrv_id is
12849 --  SELECT ID from OKC_MASSCHANGE_REQ_DTLS_V
12850 --  WHERE oie_id = p_oie_rec.oie_id;
12851 -- */
12852 
12853 BEGIN
12854        --dbms_output.put_line('Inside ..');
12855 /*
12856        OPEN omrv_id;
12857        BEGIN
12858         FETCH omrv_id into l_omrv_rec_in.id;
12859        EXCEPTION
12860         WHEN OTHERS THEN
12861               RAISE G_EXCEPTION_HALT_VALIDATION ;
12862        END;
12863        CLOSE omrv_id;
12864 
12865     l_omrv_rec_in.oie_id                          := p_oie_rec.oie_id;
12866 
12867         --dbms_output.put_line('Calling ..');
12868 
12869      OKC_OPER_INST_PUB.Delete_Masschange_Dtls(
12870                             	p_api_version					=> l_api_version,
12871     	                        p_init_msg_list					=> l_init_msg_list,
12872     	                        x_return_status					=> l_return_status,
12873     	                        x_msg_count					    => l_msg_count,
12874     	                        x_msg_data					    => l_msg_data,
12875                                 p_mrdv_rec                      => l_omrv_rec_in);
12876 
12877         --dbms_output.put_line('Omr status:'||l_return_status);
12878 
12879         IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
12880             RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
12881         ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
12882             RAISE OKC_API.G_EXCEPTION_ERROR;
12883         ELSIF (l_return_status = OKC_API.G_RET_STS_SUCCESS) THEN
12884    */
12885 
12886        l_oiev_tbl_in(1).id                              := p_oie_rec.oie_id; --OKC_API.G_MISS_CHAR;
12887 
12888        OKC_OPER_INST_PUB.Delete_Operation_Instance(
12889     	p_api_version					=> l_api_version,
12890     	p_init_msg_list					=> l_init_msg_list,
12891     	x_return_status					=> l_return_status,
12892     	x_msg_count					    => l_msg_count,
12893     	x_msg_data					    => l_msg_data,
12894     	p_oiev_rec					    => l_oiev_tbl_in(1));
12895 
12896 --dbms_output.put_line(' OKC_OPER_INST_PUB.Delete_Operation_Instance Value of l_return_status='||l_return_status);
12897         --dbms_output.put_line('oie_id:'||l_oiev_tbl_out(1).id||',status:'||l_return_status);
12898             IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
12899                 RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
12900             ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
12901                 RAISE OKC_API.G_EXCEPTION_ERROR;
12902             END IF;
12903 
12904        -- END IF;
12905                      x_return_status := l_return_status;
12906 END DELETE_OPERATION_INSTANCES;
12907 
12908 
12909 PROCEDURE CREATE_MASSCHANGE_LINE_DTLS(p_omr_rec  IN masschange_request_rec_type,
12910                                      x_omr_id   OUT NOCOPY NUMBER) is
12911 ------------------------------------------------------------------
12912 ---TAPI variables
12913 ------------------------------------------------------------------
12914   l_api_version		CONSTANT	NUMBER	:= 1.0;
12915   l_init_msg_list	VARCHAR2(2000) := OKC_API.G_FALSE;
12916   l_return_status	VARCHAR2(1);
12917   l_msg_count		NUMBER;
12918   l_msg_data		VARCHAR2(2000);
12919 
12920   l_msg_index_out	NUMBER;
12921 
12922   l_omrv_rec_in         OKC_OPER_INST_PUB.mrdv_rec_type;
12923   l_omrv_rec_out        OKC_OPER_INST_PUB.mrdv_rec_type;
12924 
12925   l_omrv_tbl_in         OKC_OPER_INST_PUB.oiev_tbl_type;
12926   l_oiev_tbl_out        OKC_OPER_INST_PUB.oiev_tbl_type;
12927 
12928   l_mod_rec_in          OKS_MOD_PVT.OksMschgOperationsDtlsVRecType;
12929   l_mod_rec_out         OKS_MOD_PVT.OksMschgOperationsDtlsVRecType;
12930 --------------------------------------------------------------------
12931 ---Program Variables
12932 --------------------------------------------------------------------
12933   l_max_id NUMBER := 0;
12934 -------------------------------------------------------------------------
12935 ---Find the Class Operation ID to be used
12936 -------------------------------------------------------------------------
12937 
12938 BEGIN
12939 
12940     --dbms_output.put_line('Inside masschange_line_dtls');
12941 
12942     l_omrv_rec_in.oie_id                         := NULL;
12943     l_omrv_rec_in.ole_id                         := p_omr_rec.ole_id;
12944     l_omrv_rec_in.attribute_name                 := p_omr_rec.attribute_name;
12945     l_omrv_rec_in.old_value                      := p_omr_rec.old_value;
12946     l_omrv_rec_in.new_value                      := p_omr_rec.new_value;
12947     l_omrv_rec_in.id                              := null;
12948     l_omrv_rec_in.object_version_number           := NULL ; --OKC_API.G_MISS_NUM;
12949     l_omrv_rec_in.created_by                      := NULL ; --OKC_API.G_MISS_NUM;
12950     l_omrv_rec_in.creation_date                   := SYSDATE;
12951  --   l_omrv_rec_in.last_updated_by                 := OKC_API.G_MISS_NUM;
12952     l_omrv_rec_in.last_update_date                := SYSDATE;
12953     l_omrv_rec_in.last_update_login               := NULL ; --OKC_API.G_MISS_NUM;
12954 
12955      OKC_OPER_INST_PUB.Create_Masschange_Dtls (
12956                             	p_api_version					=> l_api_version,
12957     	                        p_init_msg_list					=> l_init_msg_list,
12958     	                        x_return_status					=> l_return_status,
12959     	                        x_msg_count					    => l_msg_count,
12960     	                        x_msg_data					    => l_msg_data,
12961                                 p_mrdv_rec                      => l_omrv_rec_in,
12962                                 x_mrdv_rec                      => l_omrv_rec_out);
12963 
12964      --dbms_output.put_line('After masschange_line_dtls: status:'||l_return_status);
12965     IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
12966        RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
12967     ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
12968        RAISE OKC_API.G_EXCEPTION_ERROR;
12969     ELSIF (l_return_status = OKC_API.G_RET_STS_SUCCESS) THEN
12970         x_omr_id := l_omrv_rec_out.id;
12971     END IF;
12972 
12973 
12974     l_mod_rec_in.id                              := null;
12975     l_mod_rec_in.mrd_id                          := l_omrv_rec_out.id ;
12976     l_mod_rec_in.oie_id                          := null;
12977     l_mod_rec_in.ole_id                          := p_omr_rec.ole_id ; --null;
12978     l_mod_rec_in.mschg_type                      := null;
12979     l_mod_rec_in.attribute_level                 := null;
12980     l_mod_rec_in.qa_check_yn                     := p_omr_rec.qa_check_yn;
12981     l_mod_rec_in.object_version_number           := NULL ; --OKC_API.G_MISS_NUM;
12982     l_mod_rec_in.created_by                      := NULL ; --OKC_API.G_MISS_NUM;
12983     l_mod_rec_in.creation_date                   := SYSDATE;
12984     l_mod_rec_in.last_updated_by                 := NULL ; --OKC_API.G_MISS_NUM;
12985     l_mod_rec_in.last_update_date                := SYSDATE;
12986    -- l_mod_rec_in.last_update_login               := NULL ; --OKC_API.G_MISS_NUM;
12987    -- l_mod_rec_in.security_group_id               := NULL ;
12988    -- l_mod_rec_in.attribute1                      := NULL ;
12989    -- l_mod_rec_in.attribute2                      := NULL ;
12990    -- l_mod_rec_in.attribute3                      := NULL ;
12991    -- l_mod_rec_in.attribute4                      := NULL ;
12992    -- l_mod_rec_in.attribute5                      := NULL ;
12993    -- l_mod_rec_in.attribute6                      := NULL ;
12994    -- l_mod_rec_in.attribute7                      := NULL ;
12995    -- l_mod_rec_in.attribute8                      := NULL ;
12996    -- l_mod_rec_in.attribute9                      := NULL ;
12997    -- l_mod_rec_in.attribute10                     := NULL ;
12998    -- l_mod_rec_in.attribute11                     := NULL ;
12999    -- l_mod_rec_in.attribute12                     := NULL ;
13000    -- l_mod_rec_in.attribute13                     := NULL ;
13001    -- l_mod_rec_in.attribute14                     := NULL ;
13002    -- l_mod_rec_in.attribute15                     := NULL ;
13003 
13004       OKS_MOD_PVT.insert_row(  	p_api_version					=> l_api_version,
13005     	                        p_init_msg_list					=> l_init_msg_list,
13006     	                        x_return_status					=> l_return_status,
13007     	                        x_msg_count					    => l_msg_count,
13008     	                        x_msg_data					    => l_msg_data,
13009                                 p_OksMschgOperationsDtlsVRec    => l_mod_rec_in,
13010                                 XOksMschgOperationsDtlsVRec     => l_mod_rec_out);
13011 
13012 
13013         IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
13014             RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
13015         ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
13016             RAISE OKC_API.G_EXCEPTION_ERROR;
13017         END IF;
13018 
13019        EXCEPTION
13020            WHEN OTHERS THEN
13021            x_omr_id := NULL;
13022            RAISE;
13023 
13024 END CREATE_MASSCHANGE_LINE_DTLS;
13025 
13026 ----------------------------------------------------------------------------
13027 ---Create  OKC_OPERATIONS_LINES
13028 ----------------------------------------------------------------------------
13029 
13030 PROCEDURE CREATE_OPERATION_LINES (p_ole_tbl IN ole_tbl_type, --olev_tbl_type,
13031                                   x_ole_tbl OUT NOCOPY OKC_OPER_INST_PUB.olev_tbl_type) IS
13032 
13033 ----------------------------------------------------------------------------
13034 ---TAPI variables
13035 ----------------------------------------------------------------------------
13036   l_api_version		CONSTANT	NUMBER	:= 1.0;
13037   l_init_msg_list	VARCHAR2(2000) := OKC_API.G_FALSE;
13038   l_return_status	VARCHAR2(1);
13039   l_msg_count		NUMBER;
13040   l_msg_data		VARCHAR2(2000);
13041 
13042   l_msg_index_out						NUMBER;
13043 
13044   l_olev_tbl_in          OKC_OPER_INST_PUB.olev_tbl_type; --OPERATION LINES
13045   l_olev_tbl_out         OKC_OPER_INST_PUB.olev_tbl_type; --OPERATION LINES
13046 
13047 
13048 ------------------------------------------------------------------
13049 ---PROGRAM variables
13050 ------------------------------------------------------------------
13051  i NUMBER := 1;
13052  j NUMBER := 1;
13053 ------------------------------------------------------------------------
13054 ---PROGRAM BEGINS HERE
13055 ------------------------------------------------------------------------
13056  BEGIN
13057   WHILE p_ole_tbl.exists(j) LOOP
13058     l_olev_tbl_in(i).select_yn                       := p_ole_tbl(j).select_yn;
13059     l_olev_tbl_in(i).active_yn                       := NULL ; --OKC_API.G_MISS_CHAR;
13060     l_olev_tbl_in(i).process_flag                    := p_ole_tbl(j).process_flag;
13061     l_olev_tbl_in(i).oie_id                          := p_ole_tbl(j).oie_id;
13062     l_olev_tbl_in(i).subject_chr_id                  := p_ole_tbl(j).chr_id;
13063     l_olev_tbl_in(i).object_chr_id                   := NULL;
13064     l_olev_tbl_in(i).subject_cle_id                  := NULL;
13065     l_olev_tbl_in(i).parent_ole_id                   := NULL;
13066     l_olev_tbl_in(i).object_cle_id                   := NULL;
13067     l_olev_tbl_in(i).object_version_number           := NULL ; --OKC_API.G_MISS_NUM;
13068     l_olev_tbl_in(i).created_by                      := NULL ; --OKC_API.G_MISS_NUM;
13069     l_olev_tbl_in(i).creation_date                   := SYSDATE;
13070     l_olev_tbl_in(i).last_updated_by                 := NULL ; --OKC_API.G_MISS_NUM;
13071     l_olev_tbl_in(i).last_update_date                := SYSDATE;
13072     l_olev_tbl_in(i).last_update_login               := NULL ; --OKC_API.G_MISS_NUM;
13073     l_olev_tbl_in(i).request_id                      := FND_GLOBAL.CONC_REQUEST_ID;
13074     l_olev_tbl_in(i).program_application_id          := FND_GLOBAL.PROG_APPL_ID;
13075     l_olev_tbl_in(i).program_id                      := FND_GLOBAL.CONC_PROGRAM_ID;
13076     l_olev_tbl_in(i).program_update_date             := NULL ; --OKC_API.G_MISS_DATE;
13077     l_olev_tbl_in(i).message_code                    := NULL ; --OKC_API.G_MISS_CHAR;
13078 --dbms_output.put_line('Value of l_olev_tbl_in(i).oie_id='||TO_CHAR(l_olev_tbl_in(i).oie_id));
13079     i:=i+1;
13080     j:=j+1;
13081  END LOOP;
13082 
13083      OKC_OPER_INST_PUB.Create_Operation_Line(
13084     	p_api_version					=> l_api_version,
13085     	p_init_msg_list					=> l_init_msg_list,
13086     	x_return_status					=> l_return_status,
13087     	x_msg_count					=> l_msg_count,
13088     	x_msg_data					=> l_msg_data,
13089     	p_olev_tbl					=> l_olev_tbl_in,
13090     	x_olev_tbl					=> x_ole_tbl);
13091 --dbms_output.put_line('Value of l_return_status='||l_return_status);
13092 --dbms_output.put_line('l_olev_tbl_out(1).id:'||to_char(x_ole_tbl(1).id));
13093 
13094     IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
13095       RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
13096     ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
13097       RAISE OKC_API.G_EXCEPTION_ERROR;
13098     END IF;
13099  --COMMIT;
13100  --dbms_output.put_line('eND OF oPERATION _LINES');
13101 END CREATE_OPERATION_LINES;
13102 
13103 PROCEDURE DELETE_OPERATION_LINES (p_oie_id IN Number,
13104                                   x_return_status OUT NOCOPY Varchar2) IS
13105 
13106 ----------------------------------------------------------------------------
13107 ---TAPI variables
13108 ----------------------------------------------------------------------------
13109   l_api_version		CONSTANT	NUMBER	:= 1.0;
13110   l_init_msg_list	VARCHAR2(2000) := OKC_API.G_FALSE;
13111   l_return_status	VARCHAR2(1);
13112   l_msg_count		NUMBER;
13113   l_msg_data		VARCHAR2(2000);
13114 
13115   l_msg_index_out						NUMBER;
13116 
13117   l_olev_tbl_in          OKC_OPER_INST_PUB.olev_tbl_type; --OPERATION LINES
13118   l_olev_tbl_out         OKC_OPER_INST_PUB.olev_tbl_type; --OPERATION LINES
13119 
13120   l_omrv_tbl_in          OKC_OPER_INST_PUB.mrdv_tbl_type; --OPERATION LINES
13121 
13122   CURSOR Get_opn_lines IS
13123          SELECT ole.id ole_id,omr.id omr_id
13124          from OKC_OPERATION_LINES_V ole, OKC_MASSCHANGE_REQ_DTLS_V omr
13125          where ole.id = omr.ole_id
13126          AND   omr.oie_id IS NULL
13127          AND   ole.oie_id = p_oie_id;
13128 ------------------------------------------------------------------
13129 ---PROGRAM variables
13130 ------------------------------------------------------------------
13131  i NUMBER := 1;
13132  j NUMBER := 1;
13133 ------------------------------------------------------------------------
13134 ---PROGRAM BEGINS HERE
13135 ------------------------------------------------------------------------
13136  BEGIN
13137 --  WHILE p_ole_tbl.exists(j)
13138 FOR ole_rec IN Get_opn_lines
13139 LOOP
13140     l_olev_tbl_in(i).id                          := ole_rec.ole_id;
13141     l_olev_tbl_in(i).oie_id                      := p_oie_id;
13142 
13143     l_omrv_tbl_in(i).id                          := ole_rec.omr_id;
13144     l_omrv_tbl_in(i).ole_id                      := p_oie_id;
13145 
13146 --dbms_output.put_line('Value of l_olev_tbl_in(i).oie_id='||TO_CHAR(l_olev_tbl_in(i).oie_id));
13147     i:=i+1;
13148  END LOOP;
13149 
13150      OKC_OPER_INST_PUB.Delete_Masschange_Dtls (
13151     	p_api_version				=> l_api_version,
13152     	p_init_msg_list				=> l_init_msg_list,
13153     	x_return_status				=> l_return_status,
13154     	x_msg_count					=> l_msg_count,
13155     	x_msg_data					=> l_msg_data,
13156         p_mrdv_tbl                  => l_omrv_tbl_in);
13157 
13158     IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
13159       RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
13160     ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
13161       RAISE OKC_API.G_EXCEPTION_ERROR;
13162     ELSIF (l_return_status = OKC_API.G_RET_STS_SUCCESS) THEN
13163 
13164      OKC_OPER_INST_PUB.Delete_Operation_Line(
13165     	p_api_version				=> l_api_version,
13166     	p_init_msg_list				=> l_init_msg_list,
13167     	x_return_status				=> l_return_status,
13168     	x_msg_count					=> l_msg_count,
13169     	x_msg_data					=> l_msg_data,
13170     	p_olev_tbl					=> l_olev_tbl_in);
13171      END IF;
13172 --dbms_output.put_line('Value of l_return_status='||l_return_status);
13173 
13174 
13175     IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
13176       RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
13177     ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
13178       RAISE OKC_API.G_EXCEPTION_ERROR;
13179     END IF;
13180 
13181    x_return_status := l_return_status;
13182  --dbms_output.put_line('END OF OPERATION _LINES');
13183 END DELETE_OPERATION_LINES;
13184 
13185 PROCEDURE UPDATE_OPERATION_LINES(p_ole_id IN NUMBER,
13186                                  p_select_yn IN VARCHAR2,
13187                                  p_qa_check_yn IN VARCHAR2 ) IS
13188 
13189         l_api_version		CONSTANT	NUMBER	:= 1.0;
13190         l_init_msg_list	    VARCHAR2(2000) := OKC_API.G_FALSE;
13191         l_return_status	    VARCHAR2(1);
13192         l_msg_count		    NUMBER;
13193         l_msg_data		    VARCHAR2(2000);
13194         l_msg_index_out	    NUMBER;
13195         l_olev_tbl_in       OKC_OPER_INST_PUB.olev_tbl_type; --OPERATION LINES
13196         l_olev_tbl_out      OKC_OPER_INST_PUB.olev_tbl_type; --OPERATION LINES
13197 
13198         l_mod_tbl_in      OKS_MOD_PVT.OksMschgOperationsDtlsVRecType ;
13199         l_mod_tbl_out     OKS_MOD_PVT.OksMschgOperationsDtlsVRecType ;
13200         p_mod_id          NUMBER ;
13201         p_mod_mrd_id      NUMBER ;
13202         l_message         Varchar2(3000) ;
13203 
13204  BEGIN
13205 
13206      l_olev_tbl_in(1).id        := p_ole_id ;
13207      l_olev_tbl_in(1).select_yn := p_select_yn ;
13208 
13209      OKC_OPER_INST_PUB.Update_Operation_Line(
13210         	p_api_version			 => l_api_version,
13211     	    p_init_msg_list			 => l_init_msg_list,
13212     	    x_return_status			 => l_return_status,
13213     	    x_msg_count			     => l_msg_count,
13214     	    x_msg_data			     => l_msg_data,
13215     	    p_olev_tbl			     => l_olev_tbl_in,
13216     	    x_olev_tbl		         => l_olev_tbl_out   );
13217 
13218      LOG_MESSAGES('OKC_OPER_INST_PUB.Update_Operation_Line l_return_status = ' || l_return_status);
13219 
13220     IF (l_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
13221         LOG_MESSAGES('OKC_OPER_INST_PUB.Update_Operation_Line l_msg_data = ' || l_msg_data);
13222         Rollback;
13223         RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
13224     ELSIF (l_return_status = OKC_API.G_RET_STS_ERROR) THEN
13225         LOG_MESSAGES('OKC_OPER_INST_PUB.Update_Operation_Line l_msg_data = ' || l_msg_data);
13226         Rollback;
13227         RAISE OKC_API.G_EXCEPTION_ERROR;
13228     END IF;
13229 
13230         Select mcd.id , mcd.mrd_id into  p_mod_id ,p_mod_mrd_id
13231         from oks_mschg_operations_dtls mcd
13232         where mcd.ole_id = p_ole_id ;
13233 
13234         l_mod_tbl_in.id            := p_mod_id;
13235         l_mod_tbl_in.qa_check_yn   := p_qa_check_yn  ; --:OKSOIE_LINES.qa_check_yn;
13236 
13237         OKS_MOD_PVT.Update_row(
13238            p_api_version                   => l_api_version,
13239            p_init_msg_list                 => l_init_msg_list,
13240            x_return_status                 => l_return_status,
13241            x_msg_count                     => l_msg_count,
13242            x_msg_data                      => l_msg_data,
13243            p_OksMschgOperationsDtlsVRec    => l_mod_tbl_in,
13244            XOksMschgOperationsDtlsVRec     => l_mod_tbl_out );
13245 
13246 
13247      		IF l_msg_count > 0
13248                   THEN
13249                   FOR i in 1..l_msg_count
13250                   LOOP
13251                     fnd_msg_pub.get (p_msg_index     => -1,
13252                                      p_encoded       => 'F', -- OKC$APPLICATION.GET_FALSE,
13253                                      p_data          => l_msg_data,
13254                                      p_msg_index_out => l_msg_index_out);
13255                     l_message := l_message||' ; '||l_msg_data;
13256                   END LOOP;
13257                 END IF;
13258  Exception
13259     When others then
13260     LOG_MESSAGES('Error Message' || SQLERRM);
13261  END UPDATE_OPERATION_LINES;
13262 
13263 
13264 
13265 
13266   PROCEDURE get_attribute_value(p_attr_code IN Varchar2,
13267                                  p_attr_id IN Varchar2,
13268                                  p_org_id   IN Number,
13269                                  x_attr_value OUT NOCOPY Varchar2,
13270                                  x_attr_name  OUT NOCOPY Varchar2)
13271    IS
13272        CURSOR get_k_group(p_id IN NUmber) IS
13273              SELECT name
13274              FROM   okc_k_groups_v
13275              WHERE  id = p_id;
13276        CURSOR get_contact(p_id IN NUmber) IS
13277              SELECT name
13278              FROM   okc_k_groups_v
13279              WHERE  id = p_id;
13280 
13281 --       CURSOR get_ccid(p_ccid IN Number) IS
13282 --             SELECT concatenated_segments
13283 --             FROM   gl_code_combinations_kfv
13284 --             WHERE  code_combination_id = p_ccid;
13285 
13286       CURSOR get_ccid (p_ccid IN NUmber, p_organization_id Number) IS
13287 
13288 	      SELECT  gcck.concatenated_segments
13289 	      From gl_code_combinations_kfv  gcck
13290 	        ,  HR_ALL_ORGANIZATION_UNITS HOU
13291 	        ,  HR_ORGANIZATION_INFORMATION HOI2
13292 	        ,  GL_LEDGERS GSOB
13293 	      WHERE HOU.ORGANIZATION_ID = HOI2.ORGANIZATION_ID
13294 	      AND ( HOI2.ORG_INFORMATION_CONTEXT || '') ='Accounting Information'
13295 	      AND HOI2.ORG_INFORMATION1 = TO_CHAR(GSOB.LEDGER_ID)
13296 	      AND gcck.code_combination_id = p_ccid
13297 	      and GSOB.chart_of_accounts_id = gcck.chart_of_accounts_id
13298 	      and HOU.organization_id  = p_organization_id
13299 	      and GSOB.object_type_code = 'L'
13300 	      AND nvl(GSOB.complete_flag, 'Y') = 'Y' ;
13301 
13302 
13303        CURSOR Cur_salesrep(p_id1 IN Number, p_org_id Number) IS
13304               Select rep.name
13305               From okx_salesreps_v rep
13306               Where rep.id1     = p_id1
13307               and rep.org_id    = p_org_id ;
13308 
13309        CURSOR get_cov_type(p_attr_code IN Varchar2) IS
13310               SELECT meaning
13311               FROM   oks_cov_types_v
13312               WHERE  code = p_attr_code ;
13313        CURSOR get_timezone(p_attr_code IN Varchar2) IS
13314               SELECT name
13315               FROM   okx_timezones_v
13316               WHERE  timezone_id = p_attr_code ;
13317 
13318 -- Select statemet for the following cursor was changed to address performance issue. Bug#3231915
13319        CURSOR get_pref_engg(p_attr_code IN Varchar2) IS
13320              SELECT EMP.FULL_NAME NAME
13321              FROM JTF_RS_RESOURCE_EXTNS RSC
13322                  ,FND_USER U
13323                  ,OKX_PER_ALL_PEOPLE_V EMP
13324              WHERE RSC.RESOURCE_ID  = p_attr_code
13325              AND RSC.CATEGORY = 'EMPLOYEE'
13326              AND EMP.PERSON_ID = RSC.SOURCE_ID
13327              AND U.USER_ID = RSC.USER_ID  ;
13328 --            SELECT name
13329 --              FROM   okx_resources_v
13330 --             WHERE  id1 = p_attr_code ;
13331        CURSOR get_res_group(p_attr_code IN Varchar2) IS
13332 
13333               SELECT name
13334               FROM   oks_resource_groups_v
13335               WHERE  id1 = p_attr_code ;
13336 
13337        CURSOR get_billing_profile(p_attr_code IN Varchar2) IS
13338               SELECT description
13339               FROM   oks_billing_profiles_v
13340               WHERE  id = p_attr_code ;
13341        CURSOR get_agreement_name(p_attr_code IN Varchar2) IS
13342               SELECT name
13343               FROM   okx_agreements_v
13344               WHERE  agreement_id = p_attr_code ;
13345 
13346        CURSOR get_line_contact(p_attr_code IN Varchar2) IS
13347                SELECT SUBSTRB(P.PERSON_LAST_NAME,1,50) || ', ' ||
13348                       SUBSTRB(P.PERSON_FIRST_NAME,1,40) NAME
13349                FROM HZ_CUST_ACCOUNT_ROLES CAR,
13350                     HZ_PARTIES P,
13351 		    --NPALEPU
13352                     --29-JUN-2005
13353                     --TCA Project
13354                     --Replaced hz_party_relationships table with hz_relationships table
13355                     /* HZ_PARTY_RELATIONSHIPS PR, */
13356                     HZ_RELATIONSHIPS PR,
13357                     --END NPALEPU
13358                     HZ_ORG_CONTACTS OC
13359                WHERE CAR.ROLE_TYPE = 'CONTACT'
13360                AND PR.PARTY_ID = CAR.PARTY_ID
13361                AND PR.CONTENT_SOURCE_TYPE = 'USER_ENTERED'
13362                --NPALEPU
13363                --29-JUN-2005
13364                --TCA Project
13365                --Replaced pr.party_relationship_id column with pr.relationship_id column and added new conditions
13366                /* AND OC.PARTY_RELATIONSHIP_ID = PR.PARTY_RELATIONSHIP_ID */
13367                AND OC.PARTY_RELATIONSHIP_ID = PR.RELATIONSHIP_ID
13368                AND PR.SUBJECT_TABLE_NAME = 'HZ_PARTIES'
13369                AND PR.OBJECT_TABLE_NAME = 'HZ_PARTIES'
13370                AND PR.DIRECTIONAL_FLAG = 'F'
13371                --END NPALEPU
13372                AND P.PARTY_ID = PR.SUBJECT_ID
13373                --NPALEPU
13374                --29-JUN-2005
13375                --TCA Project
13376                --Replaced dates check with status check as the 'Begin_date' and 'End_date' columns of hz_cust_account_roles table are migrated to 'Status' column
13377                /* AND DECODE(SIGN(TRUNC(sysdate) -
13378                    TRUNC(NVL(car.begin_date,sysdate))),-1,'I', DECODE(SIGN(TRUNC(sysdate) -
13379                    TRUNC(NVL(car.end_date,sysdate))),1,'I','A')) = 'A' */
13380                AND car.status = 'A'
13381                --END NPALEPU
13382                AND EXISTS
13383                    (SELECT 'X'
13384                     FROM hz_cust_acct_sites_all cas
13385                     WHERE cas.cust_account_id = car.cust_account_id)
13386                     AND CAR.CUST_ACCOUNT_ROLE_ID = p_attr_code ;
13387 
13388 --- Cursor for new ATTRIBUTES
13389 
13390        CURSOR get_YN_meaning(p_attr_id IN Varchar2) IS
13391      	      Select meaning
13392               From fnd_lookups
13393               Where lookup_code = p_attr_id
13394               And lookup_type   = 'OKS_SC_YES_NO' ;
13395 
13396        CURSOR get_Renewal_type(p_attr_id IN Varchar2) IS
13397      	      Select meaning
13398               From fnd_lookups
13399               Where lookup_code = p_attr_id
13400               And lookup_type   in( 'OKC_RENEWAL_TYPE','OKS_RENEWAL_TYPE') ;
13401 
13402        CURSOR get_price_list(p_attr_id IN Varchar2) IS
13403      	      Select name
13404               From okx_list_headers_v
13405               Where id1 = p_attr_id
13406               And list_type_code = 'PRL';
13407 
13408 
13409        l_attr_value     Varchar2(100);
13410        l_min            varchar2(5);
13411 
13412        FUNCTION Get_attribute(p_lookup_code IN Varchar2)
13413        RETURN  Varchar2 IS
13414 
13415        CURSOR Cur_lookup IS
13416              SELECT meaning FROM fnd_lookups
13417              WHERE lookup_type = 'OKS_MASS_CHANGE_ATTRIBUTE'
13418              AND   lookup_code = p_lookup_code;
13419        l_meaning  Varchar2(100);
13420 
13421        BEGIN
13422               OPEN Cur_lookup;
13423               FETCH Cur_lookup INTO l_meaning;
13424               CLOSE Cur_lookup;
13425 
13426               RETURN(l_meaning);
13427        EXCEPTION WHEN OTHERS THEN
13428            RETURN(NULL);
13429           RAISE;
13430        END Get_attribute;
13431 
13432      FUNCTION GET_LOOKUP_MEANING(p_type IN VARCHAR2, p_code IN VARCHAR2) RETURN VARCHAR2 IS
13433          l_meaning VARCHAR2(90);
13434 
13435          Cursor l_lookup_csr is
13436          SELECT MEANING
13437          FROM FND_LOOKUPS
13438          WHERE  LOOKUP_TYPE = p_type
13439            AND  LOOKUP_CODE = p_code ;
13440 
13441      BEGIN
13442            OPEN l_lookup_csr;
13443               fetch l_lookup_csr into l_meaning;
13444            CLOSE l_lookup_csr;
13445 
13446           Return l_meaning;
13447 
13448         EXCEPTION
13449           When OTHERS then
13450             Return p_code;
13451      END GET_LOOKUP_MEANING;
13452 
13453      FUNCTION Get_addr(p_attr_code IN Varchar2, p_attr_id IN Varchar2)
13454      RETURN Varchar2 IS
13455        l_site_code  Varchar2(10);
13456        l_addr  Varchar2(500);
13457 
13458        CURSOR Cur_addr(p_site_code IN Varchar2) IS
13459              SELECT name FROM OKX_CUST_SITE_USES_V
13460              WHERE id1 = p_attr_id
13461              AND site_use_code = p_site_code
13462              AND  id2 = '#';
13463      BEGIN
13464             IF p_attr_code = 'HDR_BILL_TO_ADDRESS' THEN
13465                l_site_code := 'BILL_TO';
13466 
13467                OPEN Cur_addr(l_site_code);
13468                FETCH Cur_addr INTO l_addr;
13469                CLOSE Cur_addr;
13470              ELSIF p_attr_code = 'HDR_SHIP_TO_ADDRESS' THEN
13471                l_site_code := 'SHIP_TO';
13472 
13473                OPEN Cur_addr(l_site_code);
13474                FETCH Cur_addr INTO l_addr;
13475                CLOSE Cur_addr;
13476              END IF;
13477           RETURN(nvl(l_addr,NULL));
13478      END Get_addr;
13479 
13480    BEGIN
13481       IF p_attr_code = 'CONTRACT_GROUP'
13482       AND p_attr_id IS not NULL
13483       THEN
13484          IF p_attr_id = '-1111'
13485          THEN
13486 -- Modified the following since "ALL" cause translation issues.
13487 -- 10-MAR-04 GET_STATUS_MEANING
13488 --           l_attr_value := 'ALL';
13489            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13490          ELSIF p_attr_id = '-9999'
13491          THEN
13492            l_attr_value := NULL;
13493          ELSE
13494            OPEN  get_k_group(to_number(p_attr_id));
13495            FETCH get_k_group INTO l_attr_value;
13496            CLOSE get_k_group;
13497          END IF;
13498         --x_attr_name := Get_attribute(p_attr_code);
13499 
13500       ELSIF p_attr_code in ('HDR_BILL_TO_ADDRESS')
13501       AND p_attr_id IS not NULL      THEN
13502          IF p_attr_id = '-1111'
13503          THEN
13504 -- Modified the following since "ALL" cause translation issues.
13505 -- 10-MAR-04 GET_STATUS_MEANING
13506 --           l_attr_value := 'ALL';
13507            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13508          ELSIF p_attr_id = '-9999'
13509          THEN
13510            l_attr_value := NULL;
13511          ELSE
13512 
13513             l_attr_value := Get_addr(p_attr_code,p_attr_id);
13514          END IF;
13515       --x_attr_name := Get_attribute(p_attr_code);
13516       ELSIF p_attr_code in ('HDR_SHIP_TO_ADDRESS')
13517       AND p_attr_id IS not NULL      THEN
13518          IF p_attr_id = '-1111'
13519          THEN
13520 -- Modified the following since "ALL" cause translation issues.
13521 -- 10-MAR-04 GET_STATUS_MEANING
13522 --           l_attr_value := 'ALL';
13523            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13524          ELSIF p_attr_id = '-9999'
13525          THEN
13526            l_attr_value := NULL;
13527          ELSE
13528 
13529             l_attr_value := Get_addr(p_attr_code,p_attr_id);
13530          END IF;
13531       --x_attr_name := Get_attribute(p_attr_code);
13532 
13533       ELSIF p_attr_code in ('PAYMENT_TERM')
13534       AND p_attr_id IS not NULL      THEN
13535          IF p_attr_id = '-1111'
13536          THEN
13537 -- Modified the following since "ALL" cause translation issues.
13538 -- 10-MAR-04
13539 --           l_attr_value := 'ALL';
13540            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13541          ELSIF p_attr_id = '-9999'
13542          THEN
13543            l_attr_value := NULL;
13544          ELSE
13545           l_attr_value := OKC_UTIL.GET_NAME_FROM_JTFV(p_object_code => 'OKX_RPAYTERM',
13546                                                            p_id1 => p_attr_id,
13547                                                            p_id2 => '#');
13548 
13549          END IF;
13550 
13551       ELSIF p_attr_code in ('ACCT_RULE')
13552       AND p_attr_id IS not NULL      THEN
13553          IF p_attr_id = '-1111'
13554          THEN
13555 -- Modified the following since "ALL" cause translation issues.
13556 -- 10-MAR-04
13557 --           l_attr_value := 'ALL';
13558            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13559          ELSIF p_attr_id = '-9999'
13560          THEN
13561            l_attr_value := NULL;
13562          ELSE
13563           l_attr_value := OKC_UTIL.GET_NAME_FROM_JTFV(p_object_code => 'OKX_ACCTRULE',
13564                                                            p_id1 => p_attr_id,
13565                                                            p_id2 => '#');
13566 
13567          END IF;
13568 
13569       ELSIF p_attr_code in ('INV_RULE')
13570       AND p_attr_id IS not NULL      THEN
13571          IF p_attr_id = '-1111'
13572          THEN
13573 -- Modified the following since "ALL" cause translation issues.
13574 -- 10-MAR-04
13575 --           l_attr_value := 'ALL';
13576            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13577          ELSIF p_attr_id = '-9999'
13578          THEN
13579            l_attr_value := NULL;
13580          ELSE
13581           l_attr_value := OKC_UTIL.GET_NAME_FROM_JTFV(p_object_code => 'OKX_INVRULE',
13582                                                            p_id1 => p_attr_id,
13583                                                            p_id2 => '#');
13584 
13585          END IF;
13586       ELSIF p_attr_code = 'COV_TYPE'
13587       AND p_attr_id IS not NULL       THEN
13588          IF p_attr_id = '-1111'
13589          THEN
13590 -- Modified the following since "ALL" cause translation issues.
13591 -- 10-MAR-04
13592 --           l_attr_value := 'ALL';
13593            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13594          ELSIF p_attr_id = '-9999'
13595          THEN
13596            l_attr_value := NULL;
13597          ELSE
13598            OPEN  get_cov_type(p_attr_id);
13599            FETCH get_cov_type INTO l_attr_value;
13600            CLOSE get_cov_type;
13601          END IF;
13602 
13603       ELSIF p_attr_code = 'COV_TIMEZONE'
13604       AND p_attr_id IS not NULL
13605       THEN
13606          IF p_attr_id = '-1111'
13607          THEN
13608 -- Modified the following since "ALL" cause translation issues.
13609 -- 10-MAR-04
13610 --           l_attr_value := 'ALL';
13611            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13612          ELSIF p_attr_id = '-9999'
13613          THEN
13614            l_attr_value := NULL;
13615          ELSE
13616            OPEN  get_timezone(p_attr_id);
13617            FETCH get_timezone INTO l_attr_value;
13618            CLOSE get_timezone;
13619          END IF;
13620 
13621       ELSIF p_attr_code = 'PREF_ENGG'
13622       AND p_attr_id IS not NULL
13623       THEN
13624          IF p_attr_id = '-1111'
13625          THEN
13626 -- Modified the following since "ALL" cause translation issues.
13627 -- 10-MAR-04
13628 --           l_attr_value := 'ALL';
13629            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13630          ELSIF p_attr_id = '-9999'
13631          THEN
13632            l_attr_value := NULL;
13633          ELSE
13634            OPEN  get_pref_engg(p_attr_id);
13635            FETCH get_pref_engg INTO l_attr_value;
13636            CLOSE get_pref_engg;
13637          END IF;
13638 
13639       ELSIF p_attr_code = 'RES_GROUP'
13640       AND p_attr_id IS not NULL
13641       THEN
13642          IF p_attr_id = '-1111'
13643          THEN
13644 -- Modified the following since "ALL" cause translation issues.
13645 -- 10-MAR-04
13646 --           l_attr_value := 'ALL';
13647            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13648          ELSIF p_attr_id = '-9999'
13649          THEN
13650            l_attr_value := NULL;
13651          ELSE
13652            OPEN  get_res_group(p_attr_id);
13653            FETCH get_res_group INTO l_attr_value;
13654            CLOSE get_res_group;
13655          END IF;
13656 
13657       ELSIF p_attr_code = 'BILLING_PROFILE'
13658       AND p_attr_id IS not NULL       THEN
13659          IF p_attr_id = '-1111'
13660          THEN
13661 -- Modified the following since "ALL" cause translation issues.
13662 -- 10-MAR-04
13663 --           l_attr_value := 'ALL';
13664            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13665          ELSIF p_attr_id = '-9999'
13666          THEN
13667            l_attr_value := NULL;
13668          ELSE
13669            OPEN  get_billing_profile(p_attr_id);
13670            FETCH get_billing_profile INTO l_attr_value;
13671            CLOSE get_billing_profile;
13672          END IF;
13673 
13674       ELSIF p_attr_code = 'AGREEMENT_NAME'
13675       AND p_attr_id IS not NULL       THEN
13676          IF p_attr_id = '-1111'
13677          THEN
13678 -- Modified the following since "ALL" cause translation issues.
13679 -- 10-MAR-04
13680 --           l_attr_value := 'ALL';
13681            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13682          ELSIF p_attr_id = '-9999'
13683          THEN
13684            l_attr_value := NULL;
13685          ELSE
13686            OPEN  get_agreement_name(p_attr_id);
13687            FETCH get_agreement_name INTO l_attr_value;
13688            CLOSE get_agreement_name;
13689          END IF;
13690 
13691 
13692       ELSIF p_attr_code in ('PARTY_BILLING_CONTACT','PARTY_SHIPPING_CONTACT')
13693       AND p_attr_id IS not NULL      THEN
13694          IF p_attr_id = '-1111'
13695          THEN
13696 -- Modified the following since "ALL" cause translation issues.
13697 -- 10-MAR-04
13698 --           l_attr_value := 'ALL';
13699            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13700          ELSIF p_attr_id = '-9999'
13701          THEN
13702            l_attr_value := NULL;
13703          ELSE
13704           l_attr_value := OKC_UTIL.GET_NAME_FROM_JTFV(p_object_code => 'OKX_PCONTACT',
13705                                                            p_id1 => p_attr_id,
13706                                                            p_id2 => '#');
13707          END IF ;
13708 
13709       ELSIF p_attr_code in ('LINE_BILLING_CONTACT','LINE_SHIPPING_CONTACT')
13710       AND p_attr_id IS not NULL      THEN
13711          IF p_attr_id = '-1111'
13712          THEN
13713 -- Modified the following since "ALL" cause translation issues.
13714 -- 10-MAR-04
13715 --           l_attr_value := 'ALL';
13716            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13717          ELSIF p_attr_id = '-9999'
13718          THEN
13719            l_attr_value := NULL;
13720          ELSE
13721            OPEN  get_line_contact(p_attr_id);
13722            FETCH get_line_contact INTO l_attr_value;
13723            CLOSE get_line_contact;
13724 
13725          END IF ;
13726 
13727       --x_attr_name := Get_attribute(p_attr_code);
13728       ELSIF p_attr_code in ('SALES_REP')
13729       AND p_attr_id IS not NULL      THEN
13730          IF p_attr_id = '-1111'
13731          THEN
13732 -- Modified the following since "ALL" cause translation issues.
13733 -- 10-MAR-04
13734 --         l_attr_value := 'ALL';
13735            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13736          ELSIF p_attr_id = '-9999'
13737          THEN
13738            l_attr_value := NULL;
13739          ELSE
13740           --l_attr_value := OKC_UTIL.GET_NAME_FROM_JTFV(p_object_code => 'OKX_SALEPERS',
13741           --                                                 p_id1 => p_attr_id,
13742           --                                                 p_id2 => '#');
13743             Open Cur_salesrep(to_number(p_attr_id),p_org_id);
13744             Fetch Cur_salesrep into l_attr_value;
13745             Close Cur_salesrep;
13746          END IF;
13747       --x_attr_name := Get_attribute(p_attr_code);
13748       ELSIF p_attr_code in ('PRICE_LIST')
13749       AND p_attr_id IS not NULL      THEN
13750          IF p_attr_id = '-1111'
13751          THEN
13752 -- Modified the following since "ALL" cause translation issues.
13753 -- 10-MAR-04
13754 --           l_attr_value := 'ALL';
13755            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13756          ELSIF p_attr_id = '-9999'
13757          THEN
13758            l_attr_value := NULL;
13759          ELSE
13760           l_attr_value := OKC_UTIL.GET_NAME_FROM_JTFV(p_object_code => 'OKX_PRICE',
13761                                                            p_id1 => p_attr_id,
13762                                                            p_id2 => '#');
13763          END IF;
13764       --x_attr_name := Get_attribute(p_attr_code);
13765       ELSIF p_attr_code in ('REACTION_TIME','RESOLUTION_TIME','COVERAGE_START_TIME','COVERAGE_END_TIME')
13766          AND p_attr_id IS not NULL THEN
13767          IF p_attr_id = '-9999'
13768          THEN
13769            l_attr_value := NULL;
13770          ELSE
13771            l_min := mod(to_number(p_attr_id),60);
13772            IF length(l_min) <2 then
13773               l_min := l_min||'0';
13774            END IF;
13775            l_attr_value := trunc(to_number(p_attr_id)/60)||':'||l_min;
13776          END IF;
13777      -- x_attr_name := Get_attribute(p_attr_code);
13778 
13779       ELSIF (p_attr_code in ('CONTRACT_START_DATE',
13780                              'CONTRACT_END_DATE',
13781                              'CONTRACT_ALIAS',
13782                              'PRODUCT_ALIAS',
13783                              'CONTRACT_LINE_REF'))
13784            AND p_attr_id IS not NULL then
13785          IF p_attr_id = '-9999'
13786          THEN
13787            l_attr_value := NULL;
13788          ELSIF p_attr_id = '-1111'
13789               THEN
13790 -- Modified the following since "ALL" cause translation issues.
13791 -- 10-MAR-04
13792 --           l_attr_value := 'ALL';
13793            l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13794          ELSE
13795            l_attr_value := p_attr_id;
13796          END IF;
13797 
13798       ELSIF (p_attr_code in ('REV_ACCT'))
13799             AND p_attr_id IS not NULL then
13800 
13801             IF p_attr_id = '-1111'
13802               THEN
13803               -- Modified the following since "ALL" cause translation issues.
13804               -- 10-MAR-04
13805               --  l_attr_value := 'ALL';
13806                l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13807             ELSIF p_attr_id = '-9999'
13808             THEN
13809                l_attr_value := NULL;
13810             ELSE
13811              OPEN  get_ccid(to_number(p_attr_id),p_org_id);
13812              FETCH get_ccid INTO l_attr_value;
13813              CLOSE get_ccid;
13814             END IF;
13815 
13816  -- Coding for new attributes
13817       ELSIF p_attr_code in ('PO_REQUIRED_REN','SUMMARY_PRINT') AND p_attr_id IS not NULL THEN
13818            If p_attr_id = '-9999' Then
13819               l_attr_value := NULL;
13820            Elsif p_attr_id = '-1111' Then
13821 -- Modified the following since "ALL" cause translation issues.
13822 -- 10-MAR-04
13823 --           l_attr_value := 'ALL';
13824                l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13825            Else
13826              If p_attr_id = 'Y' then
13827                 Open get_YN_meaning('YES');
13828                 Fetch get_YN_meaning into l_attr_value;
13829                 Close get_YN_meaning;
13830              Elsif p_attr_id = 'N' then
13831                 Open get_YN_meaning('NO');
13832                 Fetch get_YN_meaning into l_attr_value;
13833                 Close get_YN_meaning;
13834              End If;
13835            End If;
13836 
13837       ELSIF p_attr_code in ('CON_RENEWAL_TYPE') AND p_attr_id IS not NULL THEN
13838            If p_attr_id = '-9999' Then
13839               l_attr_value := NULL;
13840            Elsif p_attr_id = '-1111' Then
13841 -- Modified the following since "ALL" cause translation issues.
13842 -- 10-MAR-04
13843 --           l_attr_value := 'ALL';
13844                l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13845            Else
13846              Open get_renewal_type(p_attr_id);
13847              Fetch get_renewal_type into l_attr_value;
13848              Close get_renewal_type;
13849            End If;
13850       ELSIF p_attr_code in ('BP_PRICE_LIST') AND p_attr_id IS not NULL THEN
13851            If p_attr_id = '-9999' Then
13852               l_attr_value := NULL;
13853            Elsif p_attr_id = '-1111' Then
13854 -- Modified the following since "ALL" cause translation issues.
13855 -- 10-MAR-04
13856 --           l_attr_value := 'ALL';
13857                l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13858            Else
13859              Open get_price_list(p_attr_id);
13860              Fetch get_price_list into l_attr_value;
13861              Close get_price_list;
13862            End If;
13863       Elsif p_attr_code in ('PO_NUMBER_BILL') AND p_attr_id IS not NULL Then
13864            If p_attr_id = '-9999' Then
13865               l_attr_value := NULL;
13866            Elsif p_attr_id = '-1111' Then
13867 -- Modified the following since "ALL" cause translation issues.
13868 -- 10-MAR-04
13869 --           l_attr_value := 'ALL';
13870                l_attr_value := GET_LOOKUP_MEANING('OKS_MSCHG_MISC','-1111');
13871            Else
13872                l_attr_value := p_attr_id;
13873            End If;
13874 
13875       END IF;
13876        x_attr_value := rtrim(l_attr_value);
13877        x_attr_name := Get_attribute(p_attr_code);
13878       EXCEPTION
13879       WHEN OTHERS Then
13880       RAISE ;
13881 
13882    END Get_attribute_value;
13883 
13884 PROCEDURE Create_Mschg_Class_Operation
13885 IS
13886   CURSOR Check_class_opn IS
13887          SELECT count(*) cnt FROM okc_class_operations_v
13888          WHERE opn_code = 'MASS_CHANGE'
13889          AND   cls_code = 'SERVICE';
13890   CURSOR Get_max_id IS
13891          SELECT nvl(max(id),0) + 1 from okc_class_operations_v;
13892 
13893  l_opn_id  Number;
13894  l_count   Number := 0;
13895 BEGIN
13896 
13897    FOR opn_rec IN Check_class_opn
13898    LOOP
13899         l_count := opn_rec.cnt;
13900    END LOOP;
13901 
13902    IF l_count = 0 THEN
13903 
13904       OPEN Get_max_id;
13905       FETCH Get_max_id INTO l_opn_id;
13906       CLOSE Get_max_id;
13907 
13908    INSERT INTO okc_class_operations(
13909      ID
13910     ,OPN_CODE
13911     ,CLS_CODE
13912     ,SEARCH_FUNCTION_ID
13913     ,DETAIL_FUNCTION_ID
13914     ,OBJECT_VERSION_NUMBER
13915     ,CREATED_BY
13916     ,CREATION_DATE
13917     ,LAST_UPDATED_BY
13918     ,LAST_UPDATE_DATE
13919     ,LAST_UPDATE_LOGIN
13920     --,SECURITY_GROUP_ID
13921     ,PDF_ID)
13922     values
13923     (l_opn_id
13924     ,'MASS_CHANGE'
13925     ,'SERVICE'
13926     ,NULL
13927     ,NULL
13928     ,10000
13929     ,1
13930     ,SYSDATE
13931     ,1
13932     ,SYSDATE
13933     ,0
13934     --,NULL
13935     ,NULL);
13936 
13937     commit;
13938     END IF;
13939     EXCEPTION WHEN OTHERS THEN
13940     RAISE;
13941 END Create_Mschg_Class_Operation;
13942 
13943 PROCEDURE UPDATE_LINE_STATUS(p_oie_id IN Number) IS
13944  PRAGMA AUTONOMOUS_TRANSACTION;
13945 BEGIN
13946 
13947  UPDATE okc_operation_lines
13948  SET    process_flag = NULL
13949  WHERE  oie_id = p_oie_id
13950  AND    select_yn = 'Y'
13951  AND    process_flag in ('A','E');
13952 
13953  COMMIT;
13954  EXCEPTION
13955  WHEN OTHERS THEN
13956         LOG_MESSAGES('UPDATE_LINE_STATUS: '||SQLERRM);
13957  END UPDATE_LINE_STATUS;
13958 
13959  PROCEDURE UPDATE_QA_CHECK_YN_COL IS
13960 
13961  Cursor get_rec IS SELECT
13962                    mrd.id
13963                   ,mrd.oie_id
13964                   ,mrd.ole_id
13965                   ,mrd.attribute_name
13966                   ,mrd.old_value
13967                   ,mrd.new_value
13968                   ,mrd.object_version_number
13969                   ,mrd.created_by
13970                   ,mrd.creation_date
13971                   ,mrd.last_updated_by
13972                   ,mrd.last_update_date
13973                   ,mrd.last_update_login
13974                   ,mrd.security_group_id
13975                   ,okh.sts_code status_code
13976              FROM okc_masschange_req_dtls mrd,
13977                   okc_operation_lines opn,
13978                   okc_k_headers_b okh
13979              WHERE mrd.ole_id = opn.id(+)
13980              AND opn.subject_chr_id = okh.id(+) ;
13981 
13982     l_api_version		CONSTANT	NUMBER	:= 1.0;
13983     l_init_msg_list	VARCHAR2(2000) := OKC_API.G_FALSE;
13984     l_return_status	VARCHAR2(1);
13985     l_msg_count		NUMBER;
13986     l_msg_data		VARCHAR2(2000);
13987     l_msg_index_out	NUMBER;
13988     l_mod_rec_in          OKS_MOD_PVT.OksMschgOperationsDtlsVRecType;
13989     l_mod_rec_out         OKS_MOD_PVT.OksMschgOperationsDtlsVRecType;
13990 
13991  BEGIN
13992 
13993   FOR r1 in  get_rec LOOP
13994 
13995     l_mod_rec_in.id                              := null;
13996     l_mod_rec_in.mrd_id                          := r1.id ; --l_omrv_rec_out.id ;
13997     l_mod_rec_in.oie_id                          := r1.oie_id ; --x_oie_id;
13998     l_mod_rec_in.ole_id                          := r1.ole_id ; --null;
13999     l_mod_rec_in.mschg_type                      := null;
14000     l_mod_rec_in.attribute_level                 := null;
14001     --l_mod_rec_in.qa_check_yn                     := r1.qa_check_yn ; --null; --p_mrd_rec.qa_check_yn;
14002     l_mod_rec_in.object_version_number           := r1.object_version_number ; --NULL ; --OKC_API.G_MISS_NUM;
14003     l_mod_rec_in.created_by                      := r1.created_by ; --NULL ; --OKC_API.G_MISS_NUM;
14004     l_mod_rec_in.creation_date                   := r1.creation_date ; --SYSDATE;
14005     l_mod_rec_in.last_updated_by                 := r1.last_updated_by ; --NULL ; --OKC_API.G_MISS_NUM;
14006     l_mod_rec_in.last_update_date                := r1.last_update_date ; --SYSDATE;
14007    -- l_mod_rec_in.last_update_login               := NULL ; --OKC_API.G_MISS_NUM;
14008    -- l_mod_rec_in.security_group_id               := NULL ;
14009 
14010     IF r1.status_code  IS NOT NULL and  r1.status_code = 'ACTIVE' then
14011        l_mod_rec_in.qa_check_yn := 'Y'  ;
14012     ELSIF
14013        r1.status_code  IS NOT NULL and  r1.status_code <> 'ACTIVE' then
14014        l_mod_rec_in.qa_check_yn := 'N'  ;
14015     ELSIF
14016        r1.status_code  IS NULL then
14017        l_mod_rec_in.qa_check_yn := NULL  ;
14018     END IF ;
14019 
14020       OKS_MOD_PVT.insert_row(  	p_api_version					=> l_api_version,
14021     	                        p_init_msg_list					=> l_init_msg_list,
14022     	                        x_return_status					=> l_return_status,
14023     	                        x_msg_count					    => l_msg_count,
14024     	                        x_msg_data					    => l_msg_data,
14025                                 p_OksMschgOperationsDtlsVRec    => l_mod_rec_in,
14026                                 XOksMschgOperationsDtlsVRec     => l_mod_rec_out);
14027 
14028 
14029     END LOOP ;
14030  END UPDATE_QA_CHECK_YN_COL ;
14031 
14032 END OKS_MASSCHANGE_PVT;
14033