DBA Data[Home] [Help]

PACKAGE BODY: APPS.QP_BULK_VALIDATE

Source


1 PACKAGE BODY QP_BULK_VALIDATE AS
2 /* $Header: QPXBLVAB.pls 120.62.12010000.4 2008/11/05 12:07:08 kdurgasi ship $ */
3 
4 function get_count(p_request_id number,
5 		   p_orig_sys_header_ref VARCHAR2,
6 		   p_orig_sys_line_ref VARCHAR2)
7 return number
8 is
9 l_count number;
10 l_count1 number;
11 l_interface_action_code varchar2(30);
12 begin
13     --Bug#5488061 RAVI START
14     --Initialize variables
15     l_count  := 0;
16     l_count1 := 0;
17     l_interface_action_code := null;
18     --Bug#5488061 RAVI END
19 
20     begin
21 	select interface_action_code
22 	into l_interface_action_code
23 	from qp_interface_list_lines
24 	where orig_sys_line_ref = p_orig_sys_line_ref;
25     exception
26 	when others then
27 		null;
28     end;
29 
30     --Bug#5488061 RAVI START
31     --Return the number of pricing attributes that the line has in
32     --both the Interface_pricing_attribs and Qp_pricing_attribs table.
33     IF l_interface_action_code is not null THEN
34         if l_interface_action_code = 'INSERT' then
35 	      begin
36             	select count(*)
37         	   into l_count1
38             	from qp_interface_pricing_attribs
39             	where orig_sys_line_ref = p_orig_sys_line_ref
40                 and process_status_flag = 'P'
41 	           and request_id = p_request_id;
42            exception
43 	          when others then
44 	       	      l_count1:=0;
45            end;
46     	   return l_count1;
47         end if;
48         if l_interface_action_code = 'UPDATE' then
49         	begin
50 	          select count(*)
51               into l_count
52               from qp_interface_pricing_attribs
53               where orig_sys_line_ref = p_orig_sys_line_ref
54                 and request_id = p_request_id
55                 and process_status_flag = 'P'
56             	and interface_action_code = 'INSERT';
57         	exception
58             	when others then
59             		l_count:=0;
60         	end;
61             begin
62             	select count(*)
63             	into l_count1
64         	   from qp_pricing_attributes
65             	where orig_sys_line_ref = p_orig_sys_line_ref
66             	and orig_sys_header_ref = p_orig_sys_header_ref;
67     	   exception
68     	       when others then
69             		l_count1:=0;
70     	   end;
71            return(l_count + l_count1);
72         end if;
73     ELSE
74         begin
75            	select count(*)
76            	into l_count
77             from qp_pricing_attributes
78            	where orig_sys_line_ref = p_orig_sys_line_ref
79            	and orig_sys_header_ref = p_orig_sys_header_ref;
80     	exception
81     	    when others then
82             		l_count:=0;
83     	end;
84         return(l_count);
85     END IF;
86     --Bug#5488061 RAVI END
87 
88 end;
89 
90 function check_dates_for_dupl
91 		      (p_request_id NUMBER,
92 			p_start_date_active date,
93 			p_end_date_active date,
94 			p_orig_sys_header_ref varchar,
95 			p_orig_sys_line_ref1 varchar,
96 			p_orig_sys_line_ref2 varchar)
97 return boolean
98 IS
99 
100 l_min_date DATE;
101 l_max_date DATE;
102 l_sdate DATE;
103 l_edate DATE;
104 l_msg VARCHAR2(200);
105 l_error_id NUMBER;
106 
107 BEGIN
108     l_min_date := to_date('01/01/1900', 'MM/DD/YYYY');
109     l_max_date := to_date('12/31/9999', 'MM/DD/YYYY');
110     qp_bulk_loader_pub.write_log('Inside check dates');
111     Begin
112 	SELECT start_date_active, end_date_active
113 	Into l_sdate, l_edate
114 	From qp_interface_list_lines
115 	Where orig_sys_line_ref=p_orig_sys_line_ref2;
116 	Exception
117 	When no_data_found then
118 
119 	Begin
120 	    SELECT start_date_active, end_date_active
121 	    into l_sdate, l_edate
122 	    from qp_list_lines
123 	    where orig_sys_line_ref=p_orig_sys_line_ref2
124 	    and orig_sys_header_ref = p_orig_sys_header_ref;
125 	Exception
126 	When no_data_found then
127 	    Null;
128 	End;
129     End;
130 
131 
132     IF ( nvl(p_Start_Date_Active, l_min_date) <= nvl(l_sdate, l_min_date))
133     THEN
134 	l_min_date := nvl(p_Start_Date_Active, l_min_date);
135     ELSE
136 	l_min_date := nvl(l_sdate, l_min_date);
137     END IF;
138 
139     IF ( nvl(p_End_Date_Active, l_max_date) >= nvl(l_edate, l_max_date))
140     THEN
141 	l_max_date := nvl(p_End_Date_Active, l_max_date);
142     ELSE
143 	l_max_date := nvl(l_edate, l_max_date);
144     END IF;
145 
146     If ( trunc(nvl(l_sdate, l_min_date)) between
147 	trunc(nvl(p_Start_Date_Active, l_min_date))
148 	and trunc(nvl(p_End_Date_Active, l_max_date)) )
149 	OR
150 	( trunc(nvl(l_edate, l_max_date)) between
151 	trunc(nvl(p_Start_Date_Active, l_min_date))
152 	and trunc(nvl(p_End_Date_Active, l_max_date)) )
153 
154 	OR
155 	( trunc(nvl(l_sdate, l_min_date)) <=
156 	nvl(p_Start_Date_Active,l_min_date)
157 	AND
158 	trunc(nvl(l_edate, l_max_date)) >=
159 	nvl(p_End_Date_Active,l_max_date) )
160 
161     THEN
162 	qp_bulk_loader_pub.write_log('DUP line exists');
163 	Update qp_interface_list_lines set process_status_flag=NULL --'E'
164 	Where orig_sys_line_ref = p_orig_sys_line_ref1
165 	And request_id = p_request_id;
166 
167 	fnd_message.set_name('QP','QP_DUPLICATE_LIST_LINES');
168 	l_msg:=fnd_message.Get;
169 
170 	--Insert the message into Interface error table.
171 	Select qp_interface_errors_s.nextval
172 	into l_error_id
173 	from dual;
174 
175 	INSERT INTO
176 	QP_INTERFACE_ERRORS
177 	(error_id,last_update_date, last_updated_by, creation_date,
178 	created_by, last_update_login, request_id, program_application_id,
179 	program_id, program_update_date, entity_type, table_name, column_name,
180 	orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
181 	orig_sys_pricing_attr_ref, error_message)
182 	VALUES
183 	(l_error_id, sysdate ,FND_GLOBAL.USER_ID, sysdate,
184 	FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, p_request_id, 661,
185 	NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES', NULL,
186 	p_orig_sys_header_ref,p_orig_sys_line_ref1,null,null,l_msg);
187 	return FALSE;
188     END IF;
189     return TRUE;
190 END;
191 
192 PROCEDURE DUP_LINE_CHECK
193           (p_request_id NUMBER)
194 IS
195 
196 CURSOR  c_dup_line_rec is
197 select /*+ ordered use_nl(a b) index(b QP_INTERFACE_PRCNG_ATTRIBS_N1) */
198 	a.orig_sys_line_ref,
199 	b.orig_sys_line_ref,
200 	a.orig_sys_header_ref,
201 	a.product_uom_code, b.product_uom_code,
202 	a.pricing_attribute_context, b.pricing_attribute_context,
203 	a.pricing_attribute, b.pricing_attribute,
204 	a.pricing_attr_value_from, b.pricing_attr_value_from,
205 	a.pricing_attr_value_to, b.pricing_attr_value_to,
206 	a.comparison_operator_code, b.comparison_operator_code
207 	-- Bug 5092813 RAVI
208 	,b.list_line_id
209     -- Bug 5234939 RAVI START
210     ,a.orig_sys_pricing_attr_ref
211     ,b.orig_sys_pricing_attr_ref
212     -- Bug 5234939 RAVI END
213 from qp_interface_pricing_attribs a, qp_interface_pricing_attribs b
214 where   a.request_id = p_request_id
215 and     b.request_id = p_request_id
216 and     a.process_status_flag ='P'
217 and     b.interface_action_code IN ('INSERT', 'UPDATE')
218 and     b.process_status_flag ='P'
219 and     b.orig_sys_line_ref <> a.orig_sys_line_ref
220 and b.product_attribute_context = a.product_attribute_context
221 and b.product_attribute = a.product_attribute
222 and b.product_attr_value = a.product_attr_value
223 and b.orig_Sys_Header_Ref = a.orig_sys_header_ref;
224 
225 CURSOR  c_dup_line_rec1 is
226 select a.orig_sys_line_ref , b.orig_sys_line_ref,
227 	a.orig_sys_header_ref,
228 	a.product_uom_code, b.product_uom_code,
229 	a.pricing_attribute_context, b.pricing_attribute_context,
230 	a.pricing_attribute, b.pricing_attribute,
231 	a.pricing_attr_value_from, b.pricing_attr_value_from,
232 	a.pricing_attr_value_to, b.pricing_attr_value_to,
233 	a.comparison_operator_code, b.comparison_operator_code
234 	-- Bug 5092813 RAVI
235 	,b.list_line_id
236     -- Bug 5234939 RAVI START
237     ,a.orig_sys_pricing_attr_ref
238     ,b.orig_sys_pricing_attr_ref
239     -- Bug 5234939 RAVI END
240 from qp_interface_pricing_attribs a, qp_pricing_attributes b
241 -- Bug 5234939 RAVI
242 where   a.request_id = p_request_id
243 and     a.process_status_flag ='P'
244 and     b.orig_sys_line_ref <>  a.orig_sys_line_ref
245 and b.product_attribute_context = a.product_attribute_context
246 and b.product_attribute = a.product_attribute
247 and b.product_attr_value = a.product_attr_value
248 and b.orig_sys_header_ref = a.orig_Sys_Header_Ref
249 -- Bug 5234939 RAVI
250 AND  NOT EXISTS (SELECT /*+ no_unnest index(C QP_INTERFACE_PRCNG_ATTRIBS_N5) */ 'X' --bug 7433219
251 
252          from qp_interface_pricing_attribs c
253          where c.request_id = p_request_id
254          and c.orig_sys_pricing_attr_ref = b.orig_sys_pricing_attr_ref  --bug 7433219
255          and c.interface_action_code IN ('UPDATE','DELETE')
256          );
257 
258 -- Bug 5234939 RAVI START
259 Cursor c_pa_line_ref(l_orig_sys_line_ref Varchar2,
260                      l_orig_sys_pricing_attr_ref Varchar2,
261                      -- Bug 5246745 Use Composite Index for Ref columns
262                      l_orig_sys_header_ref Varchar2) is
263 select orig_sys_pricing_attr_ref,
264        orig_sys_line_ref,
265        pricing_attribute_context,
266        pricing_attribute,
267        pricing_attr_value_from,
268        pricing_attr_value_to,
269        comparison_operator_code
270 from   qp_interface_pricing_attribs ipa
271 where  request_id = p_request_id
272   and  orig_sys_line_ref = l_orig_sys_line_ref
273   and  orig_sys_pricing_attr_ref <> l_orig_sys_pricing_attr_ref
274   and  pricing_attribute_context is not null
275   and  pricing_attribute is not null
276 UNION
277 select orig_sys_pricing_attr_ref,
278        orig_sys_line_ref,
279        pricing_attribute_context,
280        pricing_attribute,
281        pricing_attr_value_from,
282        pricing_attr_value_to,
283        comparison_operator_code
284 from   qp_pricing_attributes qpa
285 where  qpa.orig_sys_line_ref = l_orig_sys_line_ref
286   -- Bug 5246745 Use Composite Index for Ref columns
287   and  qpa.orig_sys_header_ref = l_orig_sys_header_ref
288   and  qpa.pricing_attribute_context is not null
289   and  qpa.pricing_attribute is not null
290   and  qpa.orig_sys_pricing_attr_ref <> l_orig_sys_pricing_attr_ref
291   and  qpa.orig_sys_pricing_attr_ref NOT IN
292         (Select c.orig_sys_pricing_attr_ref
293          from   qp_interface_pricing_attribs c
294          where  c.orig_sys_line_ref = l_orig_sys_line_ref
295            and  c.interface_action_code IN ('UPDATE','DELETE')
296          );
297 -- Bug 5234939 RAVI END
298 
299 l_min_date DATE;
300 l_max_date DATE;
301 l_sdate DATE;
302 l_edate DATE;
303 l_msg VARCHAR2(200);
304 l_error_id NUMBER;
305 l_count1 number;
306 l_count2 number;
307 l_orig_sys_header_ref varchar2(50);
308 l_orig_sys_line_ref varchar2(50);
309 l_dummy                       VARCHAR2(10);
310 l_dup_lin_rec qp_bulk_validate.dupl_line_type;
311 l_check_ipa c_pa_line_ref%ROWTYPE;
312 l_check_qpa c_pa_line_ref%ROWTYPE;
313 l_start_date_active date;
314 l_end_date_active date;
315 l1_orig_sys_header_ref varchar2(50);
316 l1_orig_sys_line_ref varchar2(50);
317 
318 -- Bug 5234939 RAVI START
319 l_pa_line_type1 qp_bulk_validate.pa_line_type;
320 l_pa_line_type2 qp_bulk_validate.pa_line_type;
321 l_pa_count1 Number;
322 l_pa_count2 Number;
323 l_pa_count Number;
324 -- Bug 5234939 RAVI END
325 
326 -- Bug 5092813 START RAVI
327 /**
328 Count of number of pricing attributes for a given line.
329 **/
330 l_int_pr_attrbs_count NUMBER := 0;
331 l_pr_attrbs_count NUMBER := 0;
332 nvl_check1 VARCHAR2(10);
333 nvl_check2 VARCHAR2(10);
334 -- Bug 5092813 END RAVI
335 
336 BEGIN
337 	dbms_session.set_sql_trace(TRUE);
338     qp_bulk_loader_pub.write_log('Entering Duplicate Line Check');
339     BEGIN
340     FOR i_mode IN 1..2
341     LOOP
342     qp_bulk_loader_pub.write_log('Mode:'||to_char(i_mode));
343     IF i_mode = 1 THEN
344 	OPEN c_dup_line_rec;
345 	l_dup_lin_rec.a_orig_sys_line_ref.delete;
346 	l_dup_lin_rec.b_orig_sys_line_ref.delete;
347 	l_dup_lin_rec.orig_sys_header_ref.delete;
348 	l_dup_lin_rec.a_product_uom_code.delete;
349 	l_dup_lin_rec.b_product_uom_code.delete;
350 	l_dup_lin_rec.a_pricing_attribute_context.delete;
351 	l_dup_lin_rec.b_pricing_attribute_context.delete;
352 	l_dup_lin_rec.a_pricing_attribute.delete;
353 	l_dup_lin_rec.b_pricing_attribute.delete;
354 	l_dup_lin_rec.a_pricing_attr_value_from.delete;
355 	l_dup_lin_rec.b_pricing_attr_value_from.delete;
356 	l_dup_lin_rec.a_pricing_attr_value_to.delete;
357 	l_dup_lin_rec.b_pricing_attr_value_to.delete;
358 	l_dup_lin_rec.a_comparison_operator_code.delete;
359 	l_dup_lin_rec.b_comparison_operator_code.delete;
360 	l_dup_lin_rec.b_list_line_id.delete;
361     -- Bug 5234939 RAVI START
362 	l_dup_lin_rec.a_orig_sys_pricing_attr_ref.delete;
363 	l_dup_lin_rec.b_orig_sys_pricing_attr_ref.delete;
364     -- Bug 5234939 RAVI END
365 
366 	FETCH c_dup_line_rec  BULK COLLECT
367 	INTO l_dup_lin_rec.a_orig_sys_line_ref,
368 	l_dup_lin_rec.b_orig_sys_line_ref,
369 	l_dup_lin_rec.orig_sys_header_ref,
370 	l_dup_lin_rec.a_product_uom_code,
371 	l_dup_lin_rec.b_product_uom_code,
372 	l_dup_lin_rec.a_pricing_attribute_context,
373 	l_dup_lin_rec.b_pricing_attribute_context,
374 	l_dup_lin_rec.a_pricing_attribute,
375 	l_dup_lin_rec.b_pricing_attribute,
376 	l_dup_lin_rec.a_pricing_attr_value_from,
377 	l_dup_lin_rec.b_pricing_attr_value_from,
378 	l_dup_lin_rec.a_pricing_attr_value_to,
379 	l_dup_lin_rec.b_pricing_attr_value_to,
380 	l_dup_lin_rec.a_comparison_operator_code,
381 	l_dup_lin_rec.b_comparison_operator_code,
382 	l_dup_lin_rec.b_list_line_id,
383     -- Bug 5234939 RAVI START
384 	l_dup_lin_rec.a_orig_sys_pricing_attr_ref,
385 	l_dup_lin_rec.b_orig_sys_pricing_attr_ref;
386     -- Bug 5234939 RAVI END
387 
388 	CLOSE c_dup_line_rec;
389     END IF;
390     IF i_mode = 2 THEN
391 	OPEN c_dup_line_rec1;
392 	l_dup_lin_rec.a_orig_sys_line_ref.delete;
393 	l_dup_lin_rec.b_orig_sys_line_ref.delete;
394 	l_dup_lin_rec.orig_sys_header_ref.delete;
395 	l_dup_lin_rec.a_product_uom_code.delete;
396 	l_dup_lin_rec.b_product_uom_code.delete;
397 	l_dup_lin_rec.a_pricing_attribute_context.delete;
398 	l_dup_lin_rec.b_pricing_attribute_context.delete;
399 	l_dup_lin_rec.a_pricing_attribute.delete;
400 	l_dup_lin_rec.b_pricing_attribute.delete;
401 	l_dup_lin_rec.a_pricing_attr_value_from.delete;
402 	l_dup_lin_rec.b_pricing_attr_value_from.delete;
403 	l_dup_lin_rec.a_pricing_attr_value_to.delete;
404 	l_dup_lin_rec.b_pricing_attr_value_to.delete;
405 	l_dup_lin_rec.a_comparison_operator_code.delete;
406 	l_dup_lin_rec.b_comparison_operator_code.delete;
407 	-- Bug 5149548 RAVI
408 	l_dup_lin_rec.b_list_line_id.delete;
409     -- Bug 5234939 RAVI START
410 	l_dup_lin_rec.a_orig_sys_pricing_attr_ref.delete;
411 	l_dup_lin_rec.b_orig_sys_pricing_attr_ref.delete;
412     -- Bug 5234939 RAVI END
413 
414 	FETCH c_dup_line_rec1  BULK COLLECT
415 	INTO l_dup_lin_rec.a_orig_sys_line_ref,
416 	l_dup_lin_rec.b_orig_sys_line_ref,
417 	l_dup_lin_rec.orig_sys_header_ref,
418 	l_dup_lin_rec.a_product_uom_code,
419 	l_dup_lin_rec.b_product_uom_code,
420 	l_dup_lin_rec.a_pricing_attribute_context,
421 	l_dup_lin_rec.b_pricing_attribute_context,
422 	l_dup_lin_rec.a_pricing_attribute,
423 	l_dup_lin_rec.b_pricing_attribute,
424 	l_dup_lin_rec.a_pricing_attr_value_from,
425 	l_dup_lin_rec.b_pricing_attr_value_from,
426 	l_dup_lin_rec.a_pricing_attr_value_to,
427 	l_dup_lin_rec.b_pricing_attr_value_to,
428 	l_dup_lin_rec.a_comparison_operator_code,
429 	l_dup_lin_rec.b_comparison_operator_code,
430 	-- Bug 5149548 RAVI
431 	l_dup_lin_rec.b_list_line_id,
432     -- Bug 5234939 RAVI START
433 	l_dup_lin_rec.a_orig_sys_pricing_attr_ref,
434 	l_dup_lin_rec.b_orig_sys_pricing_attr_ref;
435     -- Bug 5234939 RAVI END
436 
437 	CLOSE c_dup_line_rec1;
438     END IF;
439     qp_bulk_loader_pub.write_log('Count of duplicate = '|| to_char(l_dup_lin_rec.a_orig_sys_line_ref.count));
440 
441     FOR I IN 1..l_dup_lin_rec.a_orig_sys_line_ref.COUNT
442     LOOP
443     -- Bug 5092813 START RAVI
444     /**
445     If the line has pricing attributes (old or new) then the null pricing attribute
446     record (the default for the line) should not be considered.
447     **/
448     select count(*) into l_int_pr_attrbs_count
449     from qp_interface_pricing_attribs a
450     where a.orig_sys_line_ref=l_dup_lin_rec.a_orig_sys_line_ref(I)
451     and   a.request_id = p_request_id;
452 
453     select count(*) into l_pr_attrbs_count
454     from qp_pricing_attributes b
455     where b.orig_sys_line_ref=l_dup_lin_rec.a_orig_sys_line_ref(I)
456     -- Bug 5246745 Use Composite Index for Ref columns
457     and b.orig_sys_header_ref=l_dup_lin_rec.orig_sys_header_ref(I)
458     and b.list_line_id=l_dup_lin_rec.b_list_line_id(I);
459 
460     IF l_int_pr_attrbs_count+l_pr_attrbs_count > 1 THEN
461       nvl_check1 :='*';
462       nvl_check2 :='#';
463     ELSE
464       nvl_check1 :='*';
465       nvl_check2 :='*';
466     END IF;
467 
468     --Check if any pricing attributes records match (EIF1)
469     IF (nvl(l_dup_lin_rec.a_product_uom_code(I), '*')= nvl(l_dup_lin_rec.b_product_uom_code(I), '*') and
470 	nvl(l_dup_lin_rec.a_pricing_attribute_context(I), nvl_check1)= nvl(l_dup_lin_rec.b_pricing_attribute_context(I), nvl_check2) and
471 	nvl(l_dup_lin_rec.a_pricing_attribute(I), nvl_check1)= nvl(l_dup_lin_rec.b_pricing_attribute(I), nvl_check1) and
472 	nvl(l_dup_lin_rec.a_pricing_attr_value_from(I), 0)= nvl(l_dup_lin_rec.b_pricing_attr_value_from(I), 0) and
473 	nvl(l_dup_lin_rec.a_pricing_attr_value_to(I), 0)= nvl(l_dup_lin_rec.b_pricing_attr_value_to(I), 0) and
474         --Bug#5488061 RAVI
475 	nvl(l_dup_lin_rec.a_comparison_operator_code(I), 'BETWEEN')= nvl(l_dup_lin_rec.b_comparison_operator_code(I), 'BETWEEN')) THEN
476     -- Bug 5092813 END RAVI
477 
478 
479     -- Bug 5234939 RAVI START
480     l_pa_count1 := 0;
481     l_pa_count2 := 0;
482     l_pa_count := 0;
483 
484 	OPEN c_pa_line_ref(l_dup_lin_rec.a_orig_sys_line_ref(I),
485                        l_dup_lin_rec.a_orig_sys_pricing_attr_ref(I),
486                        -- Bug 5246745 Use Composite Index for Ref columns
487                        l_dup_lin_rec.orig_sys_header_ref(I));
488 	l_pa_line_type1.orig_sys_pricing_attr_ref.delete;
489 	l_pa_line_type1.orig_sys_line_ref.delete;
490 	l_pa_line_type1.pricing_attribute_context.delete;
491 	l_pa_line_type1.pricing_attribute.delete;
492 	l_pa_line_type1.pricing_attr_value_from.delete;
493 	l_pa_line_type1.pricing_attr_value_to.delete;
494 	l_pa_line_type1.comparison_operator_code.delete;
495 
496     --Get all the pricing attributed for the line (a)
497 	FETCH c_pa_line_ref BULK COLLECT
498 	INTO
499 	l_pa_line_type1.orig_sys_pricing_attr_ref,
500 	l_pa_line_type1.orig_sys_line_ref,
501 	l_pa_line_type1.pricing_attribute_context,
502 	l_pa_line_type1.pricing_attribute,
503 	l_pa_line_type1.pricing_attr_value_from,
504 	l_pa_line_type1.pricing_attr_value_to,
505 	l_pa_line_type1.comparison_operator_code;
506 	CLOSE c_pa_line_ref;
507 
508 
509 	OPEN c_pa_line_ref(l_dup_lin_rec.b_orig_sys_line_ref(I),
510                        l_dup_lin_rec.b_orig_sys_pricing_attr_ref(I),
511                        -- Bug 5246745 Use Composite Index for Ref columns
512                        l_dup_lin_rec.orig_sys_header_ref(I));
513 	l_pa_line_type2.orig_sys_pricing_attr_ref.delete;
514 	l_pa_line_type2.orig_sys_line_ref.delete;
515 	l_pa_line_type2.pricing_attribute_context.delete;
516 	l_pa_line_type2.pricing_attribute.delete;
517 	l_pa_line_type2.pricing_attr_value_from.delete;
518 	l_pa_line_type2.pricing_attr_value_to.delete;
519 	l_pa_line_type2.comparison_operator_code.delete;
520 
521     --Get all the pricing attributed for the line (b)
522 	FETCH c_pa_line_ref BULK COLLECT
523 	INTO
524 	l_pa_line_type2.orig_sys_pricing_attr_ref,
525 	l_pa_line_type2.orig_sys_line_ref,
526 	l_pa_line_type2.pricing_attribute_context,
527 	l_pa_line_type2.pricing_attribute,
528 	l_pa_line_type2.pricing_attr_value_from,
529 	l_pa_line_type2.pricing_attr_value_to,
530 	l_pa_line_type2.comparison_operator_code;
531 	CLOSE c_pa_line_ref;
532 
533     l_pa_count1 := l_pa_line_type1.orig_sys_pricing_attr_ref.count;
534     l_pa_count2 := l_pa_line_type2.orig_sys_pricing_attr_ref.count;
535 
536     --Check if the pricing attributes in both the lines (a and b) match
537     IF l_pa_count1=l_pa_count2
538     THEN
539        l_pa_count:=l_pa_count1;
540        FOR J IN 1..l_pa_line_type1.orig_sys_pricing_attr_ref.count
541        LOOP
542           FOR K IN 1..l_pa_line_type2.orig_sys_pricing_attr_ref.count
543           LOOP
544              IF l_pa_line_type1.pricing_attribute_context(J) = l_pa_line_type2.pricing_attribute_context(K) and
545                 l_pa_line_type1.pricing_attribute(J) = l_pa_line_type2.pricing_attribute(K) and
546                 l_pa_line_type1.pricing_attr_value_from(J) = l_pa_line_type2.pricing_attr_value_from(K) and
547                 nvl(l_pa_line_type1.pricing_attr_value_to(J),'*') = nvl(l_pa_line_type2.pricing_attr_value_to(K),'*') and
548                 l_pa_line_type1.comparison_operator_code(J) = l_pa_line_type2.comparison_operator_code(K)
549              THEN
550                 l_pa_count := l_pa_count-1;
551              END IF;
552           END LOOP;
553        END LOOP;
554     END IF;
555 
556     --If pa_count=0 then there is a conflict in between
557     --all the pricing attributes of the 2 lines (a and b) (EIF2)
558     IF l_pa_count=0
559     THEN
560     -- Bug 5234939 RAVI END
561 
562      qp_bulk_loader_pub.write_log('Dupl. after price attr  '|| l_dup_lin_rec.a_orig_sys_line_ref(I)||' - '||l_dup_lin_rec.b_orig_sys_line_ref(I));
563 	l_dummy := null;
564 	if i_mode = 1 then
565 	    begin
566 		Select 'x'
567 		into l_dummy
568 		From  qp_interface_list_lines
569 		where orig_sys_line_ref = l_dup_lin_rec.b_orig_sys_line_ref(I)
570 		and   price_break_header_ref is not NULL
571 		and   rltd_modifier_grp_type='PRICE BREAK';
572 	    Exception
573 		when others then
574 		null;
575 	    End;
576 	end if;
577 	if i_mode = 2 then
578 	    begin
579 		select 'x'
580 		into l_dummy
581 		from qp_rltd_modifiers qrm, qp_list_lines b
582 		where b.orig_sys_header_ref = l_dup_lin_rec.orig_sys_header_ref(I)
583 		and   b.orig_sys_line_ref = l_dup_lin_rec.b_orig_sys_line_ref(I)
584 		and   qrm.rltd_modifier_grp_type = 'PRICE BREAK'
585 		and   qrm.to_rltd_modifier_id = b.list_line_id;
586 	    Exception
587 		when others then
588 		null;
589 	    End;
590 	end if;
591 	qp_bulk_loader_pub.write_log('Dummy '||nvl(l_dummy, '*'));
592 	if l_dummy is NULL then
593 	    if i_mode = 1 then
594 		begin
595 		    select count(*)
596 		    into l_count1
597 		    from qp_interface_pricing_attribs
598 		    where orig_sys_line_ref = l_dup_lin_rec.a_orig_sys_line_ref(I)
599 		    and process_status_flag = 'P'
600 		    and request_id = p_request_id;
601 
602 		    select count(*)
603 		    into l_count2
604 		    from qp_interface_pricing_attribs
605 		    where orig_sys_line_ref = l_dup_lin_rec.b_orig_sys_line_ref(I)
606 		    and process_status_flag = 'P'
607 		    and request_id = p_request_id;
608 		exception
609 		    when others then
610 			    null;
611 		end;
612 	    end if;
613 	    if i_mode =2 then
614 		l_count1 := get_count(p_request_id,
615 				    l_dup_lin_rec.orig_sys_header_ref(I),
616 				l_dup_lin_rec.a_orig_sys_line_ref(I));
617 		l_count2 := get_count(p_request_id,
618 				    l_dup_lin_rec.orig_sys_header_ref(I),
619 				l_dup_lin_rec.b_orig_sys_line_ref(I));
620 	    end if;
621 	    qp_bulk_loader_pub.write_log('Counts '||to_char(l_count1)||' - '||to_char(l_count2));
622 	    if l_count1 = l_count2 then
623 		Select 	a.start_date_active,
624 			a.end_date_active,
625 			a.Orig_sys_header_ref,
626 			a.Orig_sys_line_ref
627 		into    l_start_date_active,
628 			l_end_date_active,
629 			l1_orig_sys_header_ref,
630 			l1_orig_sys_line_ref
631 		From	qp_interface_list_lines a
632 		Where a.orig_sys_line_ref=l_dup_lin_rec.a_orig_sys_line_ref(I);
633 
634 		if not check_dates_for_dupl(p_request_id,
635 			l_start_date_active,
636 			l_end_date_active,
637 			l1_orig_sys_header_ref,
638 			l1_orig_sys_line_ref,
639 			l_dup_lin_rec.b_orig_sys_line_ref(I)) then
640 			null;
641 		end if;
642 	    end if;
643 	end if;
644     -- Bug 5234939 RAVI
645     END IF;       -- End IF for EIF2
646     END IF;       -- End IF for EIF1
647     END LOOP;     -- End for one line
648     END LOOP;     -- End of one mode
649     EXCEPTION
650 	WHEN NO_DATA_FOUND THEN--no duplicate line for this line
651 		Null;
652     END;
653  dbms_session.set_sql_trace(FALSE);
654  qp_bulk_loader_pub.write_log('Leaving Duplicate line check');
655 
656 EXCEPTION
657     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
658        qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE DUP_LINE_CHECK:'||sqlerrm);
659        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
660     WHEN OTHERS THEN
661        qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE DUP_LINE_CHECK:'||sqlerrm);
662        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
663 END DUP_LINE_CHECK;
664 
665 FUNCTION GET_FLEX_ENABLED_FLAG(p_flex_name VARCHAR2)
666 RETURN VARCHAR2
667 IS
668 l_count NUMBER;
669 BEGIN
670     SELECT count(*)
671     INTO l_count
672     FROM fnd_descr_flex_column_usages
673     WHERE APPLICATION_ID = 661
674     AND DESCRIPTIVE_FLEXFIELD_NAME = p_flex_name
675     AND ENABLED_FLAG = 'Y'
676     AND ROWNUM = 1;
677 
678     IF l_count = 1 THEN
679         RETURN 'Y';
680     ELSE
681         RETURN 'N';
682     END IF;
683 EXCEPTION
684     WHEN OTHERS THEN
685         RETURN 'N';
686 END GET_FLEX_ENABLED_FLAG;
687 
688 FUNCTION Desc_Flex ( p_flex_name IN VARCHAR2 )
689 RETURN BOOLEAN
690 IS
691    l_count NUMBER := 0;
692 BEGIN
693 
694 
695     qp_bulk_loader_pub.write_log( 'In Desc Flex '||p_flex_name);
696 
697     g_context     := NULL;
698     g_attribute1  := NULL;
699     g_attribute2  := NULL;
700     g_attribute3  := NULL;
701     g_attribute4  := NULL;
702     g_attribute5  := NULL;
703     g_attribute6  := NULL;
704     g_attribute7  := NULL;
705     g_attribute8  := NULL;
706     g_attribute9  := NULL;
707     g_attribute10 := NULL;
708     g_attribute11 := NULL;
709     g_attribute12 := NULL;
710     g_attribute13 := NULL;
711     g_attribute14 := NULL;
712     g_attribute15 := NULL;
713 
714     IF FND_FLEX_DESCVAL.Validate_Desccols( 'QP', p_flex_name, 'D') THEN
715 
716 
717        -- Copying values into global variables
718        l_count := fnd_flex_descval.segment_count;
719        qp_bulk_loader_pub.write_log( 'segment count='||to_char(l_count));
720 
721        FOR i IN 1..l_count LOOP
722 
723 qp_bulk_loader_pub.write_log( 'segment col nam='||FND_FLEX_DESCVAL.segment_column_name(i));
724 qp_bulk_loader_pub.write_log( 'segment ID='|| FND_FLEX_DESCVAL.segment_id(i));
725 
726           IF FND_FLEX_DESCVAL.segment_column_name(i) = g_context_name THEN
727              g_context :=  FND_FLEX_DESCVAL.segment_id(i);
728            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute1_name THEN
729              g_attribute1 := FND_FLEX_DESCVAL.segment_id(i);
730            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute2_name THEN
731              g_attribute2 := FND_FLEX_DESCVAL.segment_id(i);
732            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute3_name THEN
733              g_attribute3 := FND_FLEX_DESCVAL.segment_id(i);
734            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute4_name THEN
735              g_attribute4 := FND_FLEX_DESCVAL.segment_id(i);
736            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute5_name THEN
737              g_attribute5 := FND_FLEX_DESCVAL.segment_id(i);
738            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute6_name THEN
739              g_attribute6 := FND_FLEX_DESCVAL.segment_id(i);
740            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute7_name THEN
741              g_attribute7 := FND_FLEX_DESCVAL.segment_id(i);
742            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute8_name THEN
743              g_attribute8 := FND_FLEX_DESCVAL.segment_id(i);
744            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute9_name THEN
745              g_attribute9 := FND_FLEX_DESCVAL.segment_id(i);
746            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute10_name THEN
747              g_attribute10 := FND_FLEX_DESCVAL.segment_id(i);
748            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute11_name THEN
749              g_attribute11 := FND_FLEX_DESCVAL.segment_id(i);
750            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute12_name THEN
751              g_attribute12 := FND_FLEX_DESCVAL.segment_id(i);
752            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute13_name THEN
753              g_attribute13 := FND_FLEX_DESCVAL.segment_id(i);
754            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute14_name THEN
755              g_attribute14 := FND_FLEX_DESCVAL.segment_id(i);
756            ELSIF FND_FLEX_DESCVAL.segment_column_name(i) = g_attribute15_name THEN
757              g_attribute15 := FND_FLEX_DESCVAL.segment_id(i);
758           END IF;
759        END LOOP;
760 
761        RETURN TRUE;
762 
763      ELSE
764         --  Prepare the encoded message by setting it on the message
765         --  dictionary stack. Then, add it to the API message list.
766 
767         FND_MESSAGE.Set_Encoded(FND_FLEX_DESCVAL.Encoded_Error_Message);
768 
769         --  Derive return status.
770 
771         IF FND_FLEX_DESCVAL.value_error OR
772             FND_FLEX_DESCVAL.unsupported_error
773         THEN
774             --  In case of an expected error return FALSE
775 	    qp_bulk_loader_pub.write_log( p_flex_name||'Desc Flex value/unsupport error');
776             RETURN FALSE;
777         ELSE
778             --  In case of an unexpected error raise an exception.
779 	    qp_bulk_loader_pub.write_log( p_flex_name||'Desc Flex unexpected error');
780             RETURN FALSE;
781         END IF;
782     END IF;
783 
784 
785     RETURN TRUE;
786 END Desc_Flex;
787 
788 FUNCTION Init_Desc_Flex (p_flex_name IN VARCHAR2,
789 			   p_context IN VARCHAR2,
790                            p_attribute1 IN VARCHAR2,
791                            p_attribute2 IN VARCHAR2,
792                            p_attribute3 IN VARCHAR2,
793                            p_attribute4 IN VARCHAR2,
794                            p_attribute5 IN VARCHAR2,
795                            p_attribute6 IN VARCHAR2,
796                            p_attribute7 IN VARCHAR2,
797                            p_attribute8 IN VARCHAR2,
798                            p_attribute9 IN VARCHAR2,
799                            p_attribute10 IN VARCHAR2,
800                            p_attribute11 IN VARCHAR2,
801                            p_attribute12 IN VARCHAR2,
802                            p_attribute13 IN VARCHAR2,
803                            p_attribute14 IN VARCHAR2,
804                            p_attribute15 IN VARCHAR2)
805 RETURN BOOLEAN
806 IS
807 l_column_value VARCHAR2(240) := null;
808 BEGIN
809       qp_bulk_loader_pub.write_log( 'In Init Desc Flex '||p_flex_name);
810 
811 	g_context_name := 'CONTEXT';
812 	g_attribute1_name := 'ATTRIBUTE1';
813 	g_attribute2_name := 'ATTRIBUTE2';
814 	g_attribute3_name := 'ATTRIBUTE3';
815 	g_attribute4_name := 'ATTRIBUTE4';
816 	g_attribute5_name := 'ATTRIBUTE5';
817 	g_attribute6_name := 'ATTRIBUTE6';
818 	g_attribute7_name := 'ATTRIBUTE7';
819 	g_attribute8_name := 'ATTRIBUTE8';
820 	g_attribute9_name := 'ATTRIBUTE9';
821 	g_attribute10_name := 'ATTRIBUTE10';
822 	g_attribute11_name := 'ATTRIBUTE11';
823 	g_attribute12_name := 'ATTRIBUTE12';
824 	g_attribute13_name := 'ATTRIBUTE13';
825 	g_attribute14_name := 'ATTRIBUTE14';
826 	g_attribute15_name := 'ATTRIBUTE15';
827 
828 	  IF p_attribute1 = FND_API.G_MISS_CHAR THEN
829 
830 	     l_column_value := null;
831 
832 	  ELSE
833 
834 	     l_column_value := p_attribute1;
835 	    qp_bulk_loader_pub.write_log( 'Attribute1='||l_column_value);
836 
837 	  END IF;
838 
839 	  FND_FLEX_DESCVAL.Set_Column_Value
840 	  (   column_name   => 'ATTRIBUTE1'
841 	   ,  column_value  => l_column_value);
842 
843 	  IF p_attribute2 = FND_API.G_MISS_CHAR THEN
844 
845 	     l_column_value := null;
846 
847 	  ELSE
848 
849 	     l_column_value := p_attribute2;
850 	    qp_bulk_loader_pub.write_log( 'Attribute2='||l_column_value);
851 
852 	  END IF;
853 
854 	  FND_FLEX_DESCVAL.Set_Column_Value
855 	  (   column_name   => 'ATTRIBUTE2'
856 	   ,  column_value  => l_column_value);
857 
858 	  IF p_attribute3 = FND_API.G_MISS_CHAR THEN
859 
860 	     l_column_value := null;
861 
862 	  ELSE
863 
864 	     l_column_value := p_attribute3;
865 	    qp_bulk_loader_pub.write_log( 'Attribute3='||l_column_value);
866 
867 	  END IF;
868 
869 	  FND_FLEX_DESCVAL.Set_Column_Value
870 	  (   column_name   => 'ATTRIBUTE3'
871 	   ,  column_value  => l_column_value);
872 
873 	  IF p_attribute4 = FND_API.G_MISS_CHAR THEN
874 
875 	     l_column_value := null;
876 
877 	  ELSE
878 
879 	     l_column_value := p_attribute4;
880 	    qp_bulk_loader_pub.write_log( 'Attribute4='||l_column_value);
881 
882 	  END IF;
883 
884 	  FND_FLEX_DESCVAL.Set_Column_Value
885 	  (   column_name   => 'ATTRIBUTE4'
886 	   ,  column_value  => l_column_value);
887 
888 	  IF p_attribute5 = FND_API.G_MISS_CHAR THEN
889 
890 	     l_column_value := null;
891 
892 	  ELSE
893 
894 	     l_column_value := p_attribute5;
895 	    qp_bulk_loader_pub.write_log( 'Attribute5='||l_column_value);
896 
897 	  END IF;
898 
899 	  FND_FLEX_DESCVAL.Set_Column_Value
900 	  (   column_name   => 'ATTRIBUTE5'
901 	   ,  column_value  => l_column_value);
902 
903 	  IF p_attribute6 = FND_API.G_MISS_CHAR THEN
904 
905 	     l_column_value := null;
906 
907 	  ELSE
908 
909 	     l_column_value := p_attribute6;
910 	    qp_bulk_loader_pub.write_log( 'Attribute6='||l_column_value);
911 
912 	  END IF;
913 
914 	  FND_FLEX_DESCVAL.Set_Column_Value
915 	  (   column_name   => 'ATTRIBUTE6'
916 	   ,  column_value  => l_column_value);
917 
918 	  IF p_attribute7 = FND_API.G_MISS_CHAR THEN
919 
920 	     l_column_value := null;
921 
922 	  ELSE
923 
924 	     l_column_value := p_attribute7;
925 	    qp_bulk_loader_pub.write_log( 'Attribute7='||l_column_value);
926 
927 	  END IF;
928 
929 	  FND_FLEX_DESCVAL.Set_Column_Value
930 	  (   column_name   => 'ATTRIBUTE7'
931 	   ,  column_value  => l_column_value);
932 
933 	  IF p_attribute8 = FND_API.G_MISS_CHAR THEN
934 
935 	     l_column_value := null;
936 
937 	  ELSE
938 
939 	     l_column_value := p_attribute8;
940 	    qp_bulk_loader_pub.write_log( 'Attribute8='||l_column_value);
941 
942 	  END IF;
943 
944 	  FND_FLEX_DESCVAL.Set_Column_Value
945 	  (   column_name   => 'ATTRIBUTE8'
946 	   ,  column_value  => l_column_value);
947 
948 	  IF p_attribute9 = FND_API.G_MISS_CHAR THEN
949 
950 	     l_column_value := null;
951 
952 	  ELSE
953 
954 	     l_column_value := p_attribute9;
955 	    qp_bulk_loader_pub.write_log( 'Attribute9='||l_column_value);
956 
957 	  END IF;
958 
959 	  FND_FLEX_DESCVAL.Set_Column_Value
960 	  (   column_name   => 'ATTRIBUTE9'
961 	   ,  column_value  => l_column_value);
962 
963 	  IF p_attribute10 = FND_API.G_MISS_CHAR THEN
964 
965 	     l_column_value := null;
966 
967 	  ELSE
968 
969 	     l_column_value := p_attribute10;
970 	    qp_bulk_loader_pub.write_log( 'Attribute10='||l_column_value);
971 
972 	  END IF;
973 
974 	  FND_FLEX_DESCVAL.Set_Column_Value
975 	  (   column_name   => 'ATTRIBUTE10'
976 	   ,  column_value  => l_column_value);
977 
978 	  IF p_attribute11 = FND_API.G_MISS_CHAR THEN
979 
980 	     l_column_value := null;
981 
982 	  ELSE
983 
984 	     l_column_value := p_attribute11;
985 	    qp_bulk_loader_pub.write_log( 'Attribute11='||l_column_value);
986 
987 	  END IF;
988 
989 	  FND_FLEX_DESCVAL.Set_Column_Value
990 	  (   column_name   => 'ATTRIBUTE11'
991 	   ,  column_value  => l_column_value);
992 
993 	  IF p_attribute12 = FND_API.G_MISS_CHAR THEN
994 
995 	     l_column_value := null;
996 
997 	  ELSE
998 
999 	     l_column_value := p_attribute12;
1000 	    qp_bulk_loader_pub.write_log( 'Attribute12='||l_column_value);
1001 
1002 	  END IF;
1003 
1004 	  FND_FLEX_DESCVAL.Set_Column_Value
1005 	  (   column_name   => 'ATTRIBUTE12'
1006 	   ,  column_value  => l_column_value);
1007 
1008 	  IF p_attribute13 = FND_API.G_MISS_CHAR THEN
1009 
1010 	     l_column_value := null;
1011 
1012 	  ELSE
1013 
1014 	     l_column_value := p_attribute13;
1015 	    qp_bulk_loader_pub.write_log( 'Attribute13='||l_column_value);
1016 
1017 	  END IF;
1018 
1019 	  FND_FLEX_DESCVAL.Set_Column_Value
1020 	  (   column_name   => 'ATTRIBUTE13'
1021 	   ,  column_value  => l_column_value);
1022 
1023 	  IF p_attribute14 = FND_API.G_MISS_CHAR THEN
1024 
1025 	     l_column_value := null;
1026 
1027 	  ELSE
1028 
1029 	     l_column_value := p_attribute14;
1030 	    qp_bulk_loader_pub.write_log( 'Attribute14='||l_column_value);
1031 
1032 	  END IF;
1033 
1034 	  FND_FLEX_DESCVAL.Set_Column_Value
1035 	  (   column_name   => 'ATTRIBUTE14'
1036 	   ,  column_value  => l_column_value);
1037 
1038 	  IF p_attribute15 = FND_API.G_MISS_CHAR THEN
1039 
1040 	     l_column_value := null;
1041 
1042 	  ELSE
1043 
1044 	     l_column_value := p_attribute15;
1045 	    qp_bulk_loader_pub.write_log( 'Attribute15='||l_column_value);
1046 
1047 	  END IF;
1048 
1049 	  FND_FLEX_DESCVAL.Set_Column_Value
1050 	  (   column_name   => 'ATTRIBUTE15'
1051 	   ,  column_value  => l_column_value);
1052 
1053 	  IF p_context = FND_API.G_MISS_CHAR THEN
1054 
1055 	     l_column_value := null;
1056 
1057 	  ELSE
1058 
1059 	     l_column_value := p_context;
1060 	    qp_bulk_loader_pub.write_log( 'Context='||l_column_value);
1061 
1062 	  END IF;
1063 	  FND_FLEX_DESCVAL.Set_Context_Value
1064 	   ( context_value   => l_column_value);
1065 
1066 	 IF NOT Desc_Flex(p_flex_name) THEN
1067 		RETURN FALSE;
1068 	 END IF;
1069 	RETURN TRUE;
1070 END;
1071 
1072 PROCEDURE ENTITY_HEADER
1073           (p_header_rec IN OUT NOCOPY QP_BULK_LOADER_PUB.HEADER_REC_TYPE)
1074 
1075 IS
1076 l_msg_rec QP_BULK_MSG.Msg_Rec_Type;
1077 l_old_PRICE_LIST_rec  QP_Price_List_PUB.Price_List_Rec_Type;
1078 l_dummy                       VARCHAR2(10);
1079 l_unit_precision_type varchar2(255) ;
1080 l_precision number := NULL;
1081 l_extended_precision number := NULL;
1082 l_price_rounding   VARCHAR2(50);
1083 l_list_header_id NUMBER;
1084 l_exist NUMBER;
1085 l_start_date_active VARCHAR2(30);
1086 l_qp_pte VARCHAR2(50);
1087 l_qp_source_system_code VARCHAR2(50);
1088 
1089 l_header_flex_enabled VARCHAR2(1);
1090 l_security_profile VARCHAR2(1);
1091 l_header_id_null VARCHAR2(1);   --bug 6961376
1092 
1093 -- Bug 4904393 START RAVI
1094 /**
1095 Local variables to store the hdr interface dates in date format.
1096 **/
1097 l_start_date DATE;
1098 l_end_date DATE;
1099 -- Bug 4904393 END RAVI
1100 
1101 -- Bug 5414062 START RAVI
1102 l_first_date_hash VARCHAR2(1);
1103 l_second_date_hash VARCHAR2(1);
1104 l_date_length NUMBER;
1105 -- Bug 5414062 END RAVI
1106 
1107 BEGIN
1108    qp_bulk_loader_pub.write_log('Entering Entity_header validation');
1109 
1110    select fnd_date.date_to_canonical(TRUNC(SYSDATE))
1111    into	  l_start_date_active
1112    from DUAL;
1113 
1114     l_qp_pte := FND_PROFILE.VALUE('QP_PRICING_TRANSACTION_ENTITY');
1115     l_qp_source_system_code := FND_PROFILE.VALUE('QP_SOURCE_SYSTEM_CODE');
1116 
1117    l_header_flex_enabled := get_flex_enabled_flag('QP_LIST_HEADERS');
1118    qp_bulk_loader_pub.write_log('Flex enabled '||l_header_flex_enabled);
1119 
1120 FOR I IN 1..p_header_rec.orig_sys_header_ref.COUNT
1121 LOOP
1122 
1123 --Initially setting the message context.
1124 
1125 l_msg_rec.REQUEST_ID := P_HEADER_REC.REQUEST_ID(I);
1126 l_msg_rec.ENTITY_TYPE :='PRL';
1127 l_msg_rec.TABLE_NAME :='QP_INTERFACE_LIST_HEADERS';
1128 l_msg_rec.ORIG_SYS_HEADER_REF := nvl(p_header_rec.orig_sys_header_ref(I),p_header_rec.list_header_id(I));
1129 l_msg_rec.LIST_HEADER_ID := p_header_rec.list_header_id(I);
1130 l_msg_rec.ORIG_SYS_LINE_REF := NULL;
1131 l_msg_rec.ORIG_SYS_QUALIFIER_REF := NULL;
1132 l_msg_rec.ORIG_SYS_PRICING_ATTR_REF := NULL;
1133 
1134   -- Populating internal fields --
1135 
1136   IF p_header_rec.interface_action_code(I) = 'INSERT' THEN
1137       Select qp_list_headers_b_s.nextval
1138 	into p_header_rec.list_header_id(I)
1139 	from dual;
1140   END IF;
1141 
1142   p_header_rec.version_no(I) := '1';
1143   p_header_rec.automatic_flag(I) := 'Y';
1144   p_header_rec.discount_lines_flag(I) := 'N';
1145   if p_header_rec.active_flag(I) is NULL then
1146 	p_header_rec.active_flag(I) := 'Y';
1147   end if;
1148   if p_header_rec.mobile_download(I) is NULL then
1149 	p_header_rec.mobile_download(I) := 'N';
1150   end if;
1151   if p_header_rec.global_flag(I) is NULL then
1152 	p_header_rec.global_flag(I) := 'Y';
1153   end if;
1154 --source_system_code
1155     IF p_header_rec.source_system_code(I) IS NULL
1156     THEN
1157        p_header_rec.source_system_code(I) := l_qp_source_system_code;
1158         if p_header_rec.source_system_code(I) is NULL then
1159            p_header_rec.source_system_code(I) := 'QP';
1160         end if;
1161     END IF;
1162 --pte_code
1163     IF p_header_rec.pte_code(I) IS NULL
1164     THEN
1165        p_header_rec.pte_code(I) := l_qp_pte;
1166         if p_header_rec.pte_code(I) is NULL then
1167            p_header_rec.pte_code(I) := 'ORDFUL';
1168         end if;
1169     END IF;
1170 
1171 /*------------ Performing required field validation for ----------------------*/
1172 
1173     --orig_sys_header_ref,
1174   IF p_header_rec.interface_action_code(I) = 'INSERT' THEN
1175     IF p_header_rec.orig_sys_header_ref(I) IS NULL
1176     THEN
1177 
1178        p_header_rec.process_status_flag(I):=NULL; --'E';
1179 
1180        FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
1181        FND_MESSAGE.SET_TOKEN('ATTRIBUTE','ORIG_SYS_HEADER_ID');
1182        QP_BULK_MSG.ADD(l_msg_rec);
1183 
1184     END IF;
1185   END IF;
1186 
1187     --List_type_code
1188 
1189     IF p_header_rec.list_type_code(I) IS NULL
1190     THEN
1191        p_header_rec.list_type_code(I):= '1';
1192        P_header_rec.process_status_flag(I):=NULL; --'E';
1193 
1194        FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
1195        FND_MESSAGE.SET_TOKEN('ATTRIBUTE','LIST_TYPE_CODE');
1196        QP_BULK_MSG.ADD(l_msg_rec);
1197 
1198     END IF;
1199 
1200     --currency_code
1201     IF p_header_rec.currency_code(I) IS NULL
1202     THEN
1203        p_header_rec.currency_code(I) := '1';
1204        P_header_rec.process_status_flag(I):=NULL; --'E';
1205 
1206        FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
1207        FND_MESSAGE.SET_TOKEN('ATTRIBUTE','CURRENCY_CODE');
1208        QP_BULK_MSG.ADD(l_msg_rec);
1209        qp_bulk_loader_pub.write_log('Currency Validation failed');
1210 
1211     END IF;
1212 
1213     --Name
1214     IF p_header_rec.name(I) IS NULL
1215     THEN
1216        p_header_rec.name(I) := '1';
1217        p_header_rec.process_status_flag(I):=NULL; --'E';
1218 
1219        FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
1220        FND_MESSAGE.SET_TOKEN('ATTRIBUTE','NAME');
1221        QP_BULK_MSG.ADD(l_msg_rec);
1222 
1223     END IF;
1224 
1225     --Rounding_factor
1226     IF p_header_rec.rounding_factor(I) IS NULL
1227     THEN
1228        p_header_rec.rounding_factor(I):= -1;
1229        P_header_rec.process_status_flag(I):=NULL;
1230 
1231        FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
1232        FND_MESSAGE.SET_TOKEN('ATTRIBUTE','ROUNDING_FACTOR');
1233        QP_BULK_MSG.ADD(l_msg_rec);
1234 
1235     END IF;
1236 
1237   IF p_header_rec.interface_action_code(I) = 'INSERT' THEN
1238     -- Language
1239     IF p_header_rec.language(I) IS NULL
1240     THEN
1241        p_header_rec.language(I):= '1';
1242        P_header_rec.process_status_flag(I):=NULL;
1243 
1244        FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
1245        FND_MESSAGE.SET_TOKEN('ATTRIBUTE','LANGUAGE');
1246        QP_BULK_MSG.ADD(l_msg_rec);
1247 
1248     END IF;
1249 
1250     -- Source Language
1251     IF p_header_rec.source_lang(I) IS NULL
1252     THEN
1253        p_header_rec.source_lang(I):= '1';
1254        p_header_rec.process_status_flag(I):=NULL;
1255 
1256        FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
1257        FND_MESSAGE.SET_TOKEN('ATTRIBUTE','SOURCE_LANG');
1258        QP_BULK_MSG.ADD(l_msg_rec);
1259 
1260     END IF;
1261   END IF;
1262 
1263     --curency_header_id (conditionally required)
1264     If NVL(fnd_profile.value('QP_MULTI_CURRENCY_INSTALLED'), 'N') = 'Y'
1265     AND p_header_rec.currency_header_id(I) IS NULL
1266     THEN
1267 
1268        p_header_rec.process_status_flag(I):=NULL;
1269        FND_MESSAGE.SET_NAME('QP','QP_MUL_CURR_REQD');
1270        QP_BULK_MSG.ADD(l_msg_rec);
1271 
1272     END IF;
1273 
1274 
1275     -- Effective Date Check
1276 
1277     -- Bug 4904393 START RAVI (5138015,5207598,5207612,5414062)
1278     /**
1279     The date entered in the interface headers should be in the canonical format
1280     YYYY/MM/DD format or an error should be thrown
1281     **/
1282     IF p_header_rec.start_date_active(I) is not null THEN
1283 
1284        l_first_date_hash := null;
1285        l_second_date_hash := null;
1286        l_date_length := null;
1287 
1288        begin
1289           select substr(p_header_rec.start_date_active(I),5,1)
1290           into l_first_date_hash from dual;
1291           select substr(p_header_rec.start_date_active(I),8,1)
1292           into l_second_date_hash from dual;
1293           select length(p_header_rec.start_date_active(I))
1294           into l_date_length from dual;
1295 
1296           IF l_date_length<>10 or l_first_date_hash<>'/' or l_second_date_hash<>'/'
1297           THEN
1298              p_header_rec.process_status_flag(I):=NULL;
1299              FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_DATE');
1300              QP_BULK_MSG.Add(l_msg_rec);
1301           END IF;
1302 
1303           l_start_date := to_date(p_header_rec.start_date_active(I),'YYYY/MM/DD');
1304        exception
1305        when others then
1306              p_header_rec.process_status_flag(I):=NULL;
1307              FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_DATE');
1308              QP_BULK_MSG.Add(l_msg_rec);
1309        end;
1310     END IF;
1311 
1312     IF p_header_rec.end_date_active(I) is not null THEN
1313 
1314        l_first_date_hash := null;
1315        l_second_date_hash := null;
1316        l_date_length := null;
1317 
1318        begin
1319           select substr(p_header_rec.end_date_active(I),5,1)
1320           into l_first_date_hash from dual;
1321           select substr(p_header_rec.end_date_active(I),8,1)
1322           into l_second_date_hash from dual;
1323           select length(p_header_rec.end_date_active(I))
1324           into l_date_length from dual;
1325 
1326           IF l_date_length<>10 or l_first_date_hash<>'/' or l_second_date_hash<>'/'
1327           THEN
1328              p_header_rec.process_status_flag(I):=NULL;
1329              FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_DATE');
1330              QP_BULK_MSG.Add(l_msg_rec);
1331           END IF;
1332 
1333           l_end_date := to_date(p_header_rec.end_date_active(I),'YYYY/MM/DD');
1334        exception
1335        when others then
1336              p_header_rec.process_status_flag(I):=NULL;
1337              FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_DATE');
1338              QP_BULK_MSG.Add(l_msg_rec);
1339        end;
1340     END IF;
1341     -- Bug 4904393 END RAVI (5138015,5207598,5207612,5414062)
1342 
1343     -- Bug 4929691 START RAVI (5207598,5207612)
1344     /**
1345     If start date is null set it to sysdate and then check if it's greater
1346     than end date. If it is throw an error and set the process status to null
1347     **/
1348     IF l_end_date IS NOT NULL
1349     AND l_start_date IS NOT NULL
1350     THEN
1351        IF l_start_date > l_end_date THEN
1352           p_header_rec.process_status_flag(I):=NULL;
1353           FND_MESSAGE.SET_NAME('QP', 'QP_STRT_DATE_BFR_END_DATE');
1354 	      QP_BULK_MSG.Add(l_msg_rec);
1355        END IF;
1356     END IF;
1357     -- Bug 4929691 END RAVI (5207598,5207612)
1358 
1359     -- Rounding factor value check
1360       l_unit_precision_type :=  FND_PROFILE.VALUE('QP_UNIT_PRICE_PRECISION_TYPE');
1361       l_price_rounding := fnd_profile.value('QP_PRICE_ROUNDING');
1362 
1363 	IF p_header_rec.currency_code(I) is not null THEN
1364                       BEGIN
1365                       	SELECT -1*PRECISION, -1*EXTENDED_PRECISION
1366              		INTO   l_precision, l_extended_precision
1367 			FROM   FND_CURRENCIES
1368 			WHERE  CURRENCY_CODE = P_header_rec.CURRENCY_CODE(I);
1369                      EXCEPTION
1370                                WHEN NO_DATA_FOUND THEN
1371        				 p_header_rec.process_status_flag(I):=NULL;
1372                                  FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
1373                                  FND_MESSAGE.SET_TOKEN('ATTRIBUTE','rounding_factor');
1374                                  qp_bulk_msg.add(l_msg_rec);
1375                      END;
1376                      END IF;
1377 
1378         IF p_header_rec.rounding_factor(I) IS  NOT NULL
1379         THEN
1380 
1381         IF l_unit_precision_type = 'STANDARD' THEN
1382 
1383 	   IF l_price_rounding = 'PRECISION' THEN
1384 	       IF p_header_rec.rounding_factor(I) <> l_precision THEN
1385        		      p_header_rec.process_status_flag(I):=NULL;
1386                       FND_MESSAGE.SET_NAME('QP', 'QP_ROUNDING_FACTOR_NO_UPDATE');
1387                      qp_bulk_msg.add(l_msg_rec);
1388                END IF;
1389            END IF;
1390 
1391            IF (p_header_rec.rounding_factor(I))
1392 		 < nvl((l_precision), (p_header_rec.rounding_factor(I))) THEN
1393        		          p_header_rec.process_status_flag(I):=NULL;
1394 			  FND_MESSAGE.SET_NAME('QP', 'OE_PRL_INVALID_ROUNDING_FACTOR');
1395                           FND_MESSAGE.SET_TOKEN('PRECISION', l_precision);
1396                           qp_bulk_msg.add(l_msg_rec);
1397            END IF;
1398 
1399        ELSE
1400            IF l_price_rounding = 'PRECISION' THEN
1401                    IF p_header_rec.rounding_factor(I) <> l_extended_precision THEN
1402        		      p_header_rec.process_status_flag(I):=NULL;
1403                       FND_MESSAGE.SET_NAME('QP', 'QP_ROUNDING_FACTOR_NO_UPDATE');
1404  		      qp_bulk_msg.add(l_msg_rec);
1405                    END IF;
1406            END IF;
1407 
1408            IF (p_header_rec.rounding_factor(I))
1409 		      < nvl((l_extended_precision),(p_header_rec.rounding_factor(I))) THEN
1410        		p_header_rec.process_status_flag(I):=NULL;
1411  	        FND_MESSAGE.SET_NAME('QP', 'OE_PRL_INVALID_ROUNDING_FACTOR');
1412                 FND_MESSAGE.SET_TOKEN('PRECISION', l_extended_precision);
1413                 qp_bulk_msg.add(l_msg_rec);
1414             END IF;
1415        END IF;
1416 
1417      END IF;
1418 -- end rounding_factor
1419 
1420 /*-------checking for the value of the flags ----------------------------
1421 --active_flag
1422 --automatic_flag
1423 --mobile_download
1424 --global_flag
1425 -------------------------------------------------------------------------*/
1426 
1427     IF ( p_header_rec.active_flag(I) IS NOT NULL)
1428     THEN
1429 		IF p_header_rec.active_flag(I) NOT IN ('Y', 'N', 'y', 'n')
1430 		THEN
1431                   p_header_rec.process_status_flag(I):=NULL;
1432 		  FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
1433 		  FND_MESSAGE.SET_TOKEN('ATTRIBUTE','active_flag');
1434                   qp_bulk_msg.add(l_msg_rec);
1435         	END IF;
1436     END IF;
1437 
1438     IF ( p_header_rec.automatic_flag(I) IS NOT NULL)
1439     THEN
1440 		IF p_header_rec.automatic_flag(I) NOT IN ('Y', 'N', 'y', 'n')
1441 		THEN
1442                   p_header_rec.process_status_flag(I):=NULL;
1443 		  FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
1444 		  FND_MESSAGE.SET_TOKEN('ATTRIBUTE','automatic_flag');
1445 		  qp_bulk_msg.add(l_msg_rec);
1446         	END IF;
1447     END IF;
1448 
1449 		IF p_header_rec.global_flag(I) NOT IN ('Y', 'N', 'n')
1450 		THEN
1451                   p_header_rec.process_status_flag(I):=NULL;
1452 		  FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
1453 		  FND_MESSAGE.SET_TOKEN('ATTRIBUTE','global_flag');
1454  		  qp_bulk_msg.add(l_msg_rec);
1455         	END IF;
1456 
1457     --added for MOAC
1458     l_security_profile := QP_SECURITY.security_on;
1459 
1460     IF ( p_header_rec.global_flag(I) IS NOT NULL)
1461     THEN
1462 
1463                 --if security is OFF, global_flag cannot be 'N'
1464                 IF (l_security_profile = 'N'
1465                 and p_header_rec.global_flag(I) in ('N', 'n')) THEN
1466                   p_header_rec.process_status_flag(I):=NULL;
1467 		  FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
1468 		  FND_MESSAGE.SET_TOKEN('ATTRIBUTE','global_flag');
1469 		  qp_bulk_msg.add(l_msg_rec);
1470         	END IF;
1471 
1472                 IF l_security_profile = 'Y' THEN
1473                   --if security is ON and global_flag is 'N', orig_org_id cannot be null
1474                   IF (p_header_rec.global_flag(I) in ('N', 'n')
1475                   -- Bug 4947191 RAVI
1476                   /**
1477                   if security is ON and global_flag is 'N', orig_org_id cannot be null
1478                   **/
1479                   and p_header_rec.orig_org_id(I) is null) THEN
1480                     p_header_rec.process_status_flag(I):=NULL;
1481 		    FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
1482                     FND_MESSAGE.SET_TOKEN('ATTRIBUTE','ORIG_ORG_ID');
1483 		    qp_bulk_msg.add(l_msg_rec);
1484 
1485                   END IF;
1486 
1487 /* for bug 4731613 moved this validation to attribute_header procedure
1488                   --if orig_org_id is not null and it is not a valid org
1489                   IF (p_header_rec.orig_org_id(I) is not null
1490                   and QP_UTIL.validate_org_id(p_header_rec.orig_org_id(I)) = 'N') THEN
1491                     p_header_rec.process_status_flag(I):=NULL;
1492                     FND_MESSAGE.SET_NAME('FND','FND_MO_ORG_INVALID');
1493 --		    FND_MESSAGE.SET_TOKEN('ATTRIBUTE','orig_org_id');
1494 		    qp_bulk_msg.add(l_msg_rec);
1495                   END IF;
1496 */
1497                 END IF;--IF l_security_profile = 'Y'
1498 
1499                 --global_flag 'Y', org_id not null combination is invalid
1500                 IF ((p_header_rec.global_flag(I) = 'Y'
1501                 and p_header_rec.orig_org_id(I) is not null) OR (p_header_rec.global_flag(I) = 'N' and p_header_rec.orig_org_id(I) is null)) THEN
1502                   p_header_rec.process_status_flag(I):=NULL;
1503                   FND_MESSAGE.SET_NAME('QP', 'QP_GLOBAL_OU_VALIDATION');
1504                   qp_bulk_msg.add(l_msg_rec);
1505                 END IF;--p_header_rec.global_flag
1506     END IF;
1507     --end validations for moac
1508 
1509         IF ( p_header_rec.mobile_download(I) IS NOT NULL)
1510     THEN
1511 		IF p_header_rec.mobile_download(I) NOT IN ('Y', 'N', 'y', 'n')
1512 		THEN
1513                   p_header_rec.process_status_flag(I):=NULL;
1514 		  FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
1515 		  FND_MESSAGE.SET_TOKEN('ATTRIBUTE','mobile_download');
1516 		  qp_bulk_msg.add(l_msg_rec);
1517         	END IF;
1518     END IF;
1519 
1520 --Checking for uniqueness of the Name in qp_list_headers.
1521     l_exist:=null;
1522     Begin
1523       Select 1 into l_exist
1524       from qp_list_headers_tl
1525       where name= p_header_rec.name(I)
1526       and list_header_id <>
1527           (select list_header_id From qp_list_headers_b
1528            -- ENH unod alcoa changes RAVI
1529            /**
1530            The key between interface and qp tables is only orig_sys_hdr_ref
1531            (not list_header_id)
1532            **/
1533            where orig_system_header_ref =p_header_rec.orig_sys_header_ref(I)
1534            and nvl(list_source_code,'*') =nvl(p_header_rec.list_source_code(I),'*')
1535            )
1536        and language = userenv('LANG');
1537 
1538     Exception
1539        When no_data_found then
1540 	  l_exist := 0;
1541     End;
1542 
1543     If l_exist = 1  THEN
1544        p_header_rec.process_status_flag(I):=NULL;
1545        fnd_message.set_name('QP', 'SO_OTHER_NAME_ALREADY_IN_USE');
1546        qp_bulk_msg.add(l_msg_rec);
1547     END IF;
1548 
1549      l_exist := NULL;
1550 
1551    IF p_header_rec.interface_action_code(I) = 'INSERT' THEN
1552      Select count(*) into l_exist
1553        from qp_interface_list_headers
1554       where request_id = p_header_rec.request_id(I)
1555 	and name = p_header_rec.name(I)
1556 	and orig_sys_header_ref <> p_header_rec.orig_sys_header_ref(I)
1557         and process_status_flag = 'P'; --is null;
1558 
1559      IF  l_exist >0 THEN
1560 	 p_header_rec.process_status_flag(I):=NULL;
1561 	 fnd_message.set_name('QP', 'SO_OTHER_NAME_ALREADY_IN_USE');
1562          qp_bulk_msg.add(l_msg_rec);
1563     END IF;
1564   END IF;
1565 
1566 --Checking for uniqueness of orig_sys_header_ref in qp_list_headers
1567 --and qp_interface_list_headers
1568 
1569     l_exist := NULL;
1570 
1571    BEGIN
1572      select 1, list_header_id into l_exist, l_list_header_id
1573      from qp_list_headers_b
1574      -- ENH unod alcoa changes START RAVI
1575      /**
1576      The key between interface and qp tables is only orig_sys_hdr_ref
1577      (not list_header_id)
1578      **/
1579      where orig_system_header_ref = p_header_rec.orig_sys_header_ref(I)
1580     and nvl(list_source_code,'*') =nvl(p_header_rec.list_source_code(I),'*');
1581    EXCEPTION
1582       	When no_data_found then
1583 	   l_exist := 0;
1584      END;
1585 
1586      IF p_header_rec.interface_action_code(I) = 'INSERT' AND l_exist =1 THEN
1587 	p_header_rec.process_status_flag(I):=NULL;
1588 	fnd_message.set_name('QP', 'ORIG_SYS_HEADER_REF_NOT_UNIQUE');
1589         FND_MESSAGE.SET_TOKEN('REF_NO', p_header_rec.orig_sys_header_ref(I));
1590         FND_MESSAGE.SET_TOKEN('LS_CODE', p_header_rec.list_source_code(I));
1591         qp_bulk_msg.add(l_msg_rec);
1592      ELSIF p_header_rec.interface_action_code(I) = 'UPDATE' AND l_exist =0 THEN
1593 	p_header_rec.process_status_flag(I):=NULL;
1594 	fnd_message.set_name('QP', 'HEADER_RECORD_DOES_NOT_EXIST');
1595         FND_MESSAGE.SET_TOKEN('REF_NO', p_header_rec.orig_sys_header_ref(I));
1596         FND_MESSAGE.SET_TOKEN('LS_CODE', p_header_rec.list_source_code(I));
1597         qp_bulk_msg.add(l_msg_rec);
1598     END IF;
1599 
1600     --bug 6961376 start
1601 
1602     IF  p_header_rec.list_header_id(I) IS NULL THEN
1603         l_header_id_null := 'Y';
1604     ELSE
1605         l_header_id_null := 'N';
1606     END IF;
1607     qp_bulk_loader_pub.write_log('Is Header Id null: ' || l_header_id_null);
1608 
1609 
1610     IF p_header_rec.interface_action_code(I) = 'UPDATE'
1611 	AND p_header_rec.list_header_id(I) IS NULL
1612 	AND l_exist =1 THEN
1613 	p_header_rec.list_header_id(I):=l_list_header_id;
1614     END IF;
1615 
1616     l_exist:= NULL;
1617 
1618      IF p_header_rec.interface_action_code(I) = 'INSERT' THEN
1619       select count(*) into l_exist
1620         from qp_interface_list_headers
1621        where request_id =p_header_rec.request_id(I)
1622          and (list_header_id = p_header_rec.list_header_id(I) or
1623               orig_sys_header_ref = p_header_rec.orig_sys_header_ref(I))
1624         and nvl(list_source_code,'*') =nvl(p_header_rec.list_source_code(I),'*');
1625 
1626        IF l_exist >1 THEN
1627           qp_bulk_loader_pub.write_log('Entity Header l_exist of orig is: '||l_exist);
1628 	  p_header_rec.process_status_flag(I):=NULL;
1629 	  fnd_message.set_name('QP','ORIG_SYS_HEADER_REF_NOT_UNIQUE');
1630           FND_MESSAGE.SET_TOKEN('REF_NO', p_header_rec.orig_sys_header_ref(I));
1631           FND_MESSAGE.SET_TOKEN('LS_CODE', p_header_rec.list_source_code(I));
1632           qp_bulk_msg.add(l_msg_rec);
1633        END IF;
1634      ELSIF p_header_rec.interface_action_code(I) = 'UPDATE' AND l_header_id_null = 'N' THEN
1635         qp_bulk_loader_pub.write_log('checking for unique orig_sys_header_ref: ' || p_header_rec.orig_sys_header_ref(I));
1636           select count(distinct list_header_id) into l_exist
1637              from qp_interface_list_headers
1638           where  request_id =p_header_rec.request_id(I)
1639 	      and orig_sys_header_ref = p_header_rec.orig_sys_header_ref(I)
1640               and nvl(list_source_code,'*') =nvl(p_header_rec.list_source_code(I),'*');
1641 /* 1749 to 1764 commented to for the bug number 6961376 as the bug 3604226 and bug 6961376  are raised for the same problem and the fix for the
1642 bug 6961376 is giving better result than the bug 3604226 we commented these lines and incorporated the new code */
1643 
1644    /*   select count(*) into l_exist
1645         from qp_interface_list_headers
1646        where request_id =p_header_rec.request_id(I)
1647          -- Bug 3604226 RAVI
1648          /**
1649          Multiple headers for insert or delete action with same orig_sys_hdr_ref
1650          are not allowed
1651          **/
1652      --    and p_header_rec.interface_action_code(I) <> 'UPDATE'
1653          -- ENH undo alcoa changes RAVI
1654          /**
1655          The key between interface and qp tables is only orig_sys_hdr_ref
1656          (not list_header_id)
1657          **/
1658       --   and orig_sys_header_ref = p_header_rec.orig_sys_header_ref(I)
1659       --  and nvl(list_source_code,'*') =nvl(p_header_rec.list_source_code(I),'*'); */
1660 
1661 
1662     IF l_exist >1 THEN
1663        qp_bulk_loader_pub.write_log('Entity Header l_exist of orig is: '||l_exist);
1664 	p_header_rec.process_status_flag(I):=NULL;
1665 	fnd_message.set_name('QP','ORIG_SYS_HEADER_REF_NOT_UNIQUE');
1666         FND_MESSAGE.SET_TOKEN('REF_NO', p_header_rec.orig_sys_header_ref(I));
1667         FND_MESSAGE.SET_TOKEN('LS_CODE', p_header_rec.list_source_code(I));
1668         qp_bulk_msg.add(l_msg_rec);
1669     END IF;
1670    END IF;
1671    --bug 6961376 end
1672 
1673 --QP_Security_check
1674   IF p_header_rec.interface_action_code(I) = 'UPDATE' THEN
1675  qp_bulk_loader_pub.write_log('Secu. Check list_header_id: '||to_char(p_header_rec.list_header_id(I)));
1676      IF QP_security.check_function( p_function_name => QP_Security.G_FUNCTION_UPDATE,
1677                                  p_instance_type => QP_Security.G_PRICELIST_OBJECT,
1678                                  p_instance_pk1  => p_header_rec.list_header_id(I)) <> 'T' THEN
1679 	p_header_rec.process_status_flag(I):=NULL;
1680         fnd_message.set_name('QP', 'QP_NO_PRIVILEGE');
1681         fnd_message.set_token('PRICING_OBJECT', 'Price List');
1682         qp_bulk_msg.add(l_msg_rec);
1683      END IF;
1684   END IF;
1685 
1686 --Defaulting
1687 -- Basic_Pricing_Condition
1688     IF (QP_BULK_LOADER_PUB.GET_QP_STATUS <> 'I' OR
1689 	   FND_PROFILE.VALUE('QP_MULTI_CURRENCY_INSTALLED') = 'N')
1690 	AND p_header_rec.currency_header_id(I) IS NOT NULL THEN
1691     -- No multi currency in Basic Pricing
1692        p_header_rec.currency_header_id(I) := NULL;
1693     END IF;
1694 
1695 --Flex field check
1696 
1697     IF l_header_flex_enabled = 'Y' THEN
1698       qp_bulk_loader_pub.write_log( 'Header Flex enabled ');
1699 
1700          IF NOT Init_Desc_Flex
1701                (p_flex_name	     =>'QP_LIST_HEADERS'
1702 	       ,p_context            => p_header_rec.context(i)
1703                ,p_attribute1         => p_header_rec.attribute1(i)
1704                ,p_attribute2         => p_header_rec.attribute2(i)
1705                ,p_attribute3         => p_header_rec.attribute3(i)
1706                ,p_attribute4         => p_header_rec.attribute4(i)
1707                ,p_attribute5         => p_header_rec.attribute5(i)
1708                ,p_attribute6         => p_header_rec.attribute6(i)
1709                ,p_attribute7         => p_header_rec.attribute7(i)
1710                ,p_attribute8         => p_header_rec.attribute8(i)
1711                ,p_attribute9         => p_header_rec.attribute9(i)
1712                ,p_attribute10        => p_header_rec.attribute10(i)
1713                ,p_attribute11        => p_header_rec.attribute11(i)
1714                ,p_attribute12        => p_header_rec.attribute12(i)
1715                ,p_attribute13        => p_header_rec.attribute13(i)
1716                ,p_attribute14        => p_header_rec.attribute14(i)
1717                ,p_attribute15        => p_header_rec.attribute15(i)) THEN
1718 
1719 	         QP_BULK_MSG.ADD(l_msg_rec);
1720 
1721                  -- Log Error Message
1722                  FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
1723                  FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
1724                                        'Entity:Flexfield:Header_Desc_Flex');
1725 	         P_header_rec.process_status_flag(I):=NULL;
1726 
1727 	         QP_BULK_MSG.ADD(l_msg_rec);
1728 
1729           ELSE -- if the flex validation is successfull
1730 
1731             IF p_header_rec.context(i) IS NULL
1732               OR p_header_rec.context(i) = FND_API.G_MISS_CHAR THEN
1733                p_header_rec.context(i)    := g_context;
1734             END IF;
1735 
1736             IF p_header_rec.attribute1(i) IS NULL
1737               OR p_header_rec.attribute1(i) = FND_API.G_MISS_CHAR THEN
1738                p_header_rec.attribute1(i) := g_attribute1;
1739             END IF;
1740 
1741             IF p_header_rec.attribute2(i) IS NULL
1742               OR p_header_rec.attribute2(i) = FND_API.G_MISS_CHAR THEN
1743                p_header_rec.attribute2(i) := g_attribute2;
1744             END IF;
1745 
1746             IF p_header_rec.attribute3(i) IS NULL
1747               OR p_header_rec.attribute3(i) = FND_API.G_MISS_CHAR THEN
1748                p_header_rec.attribute3(i) := g_attribute3;
1749             END IF;
1750 
1751             IF p_header_rec.attribute4(i) IS NULL
1752               OR p_header_rec.attribute4(i) = FND_API.G_MISS_CHAR THEN
1753                p_header_rec.attribute4(i) := g_attribute4;
1754             END IF;
1755 
1756             IF p_header_rec.attribute5(i) IS NULL
1757               OR p_header_rec.attribute5(i) = FND_API.G_MISS_CHAR THEN
1758                p_header_rec.attribute5(i) := g_attribute5;
1759             END IF;
1760 
1761             IF p_header_rec.attribute6(i) IS NULL
1762               OR p_header_rec.attribute6(i) = FND_API.G_MISS_CHAR THEN
1763                p_header_rec.attribute6(i) := g_attribute6;
1764             END IF;
1765             IF p_header_rec.attribute7(i) IS NULL
1766               OR p_header_rec.attribute7(i) = FND_API.G_MISS_CHAR THEN
1767                p_header_rec.attribute7(i) := g_attribute7;
1768             END IF;
1769 
1770             IF p_header_rec.attribute8(i) IS NULL
1771               OR p_header_rec.attribute8(i) = FND_API.G_MISS_CHAR THEN
1772                p_header_rec.attribute8(i) := g_attribute8;
1773             END IF;
1774 
1775             IF p_header_rec.attribute9(i) IS NULL
1776               OR p_header_rec.attribute9(i) = FND_API.G_MISS_CHAR THEN
1777                p_header_rec.attribute9(i) := g_attribute9;
1778             END IF;
1779 
1780             IF p_header_rec.attribute10(i) IS NULL
1781               OR p_header_rec.attribute10(i) = FND_API.G_MISS_CHAR THEN
1782                p_header_rec.attribute10(i) := G_attribute10;
1783             End IF;
1784 
1785             IF p_header_rec.attribute11(i) IS NULL
1786               OR p_header_rec.attribute11(i) = FND_API.G_MISS_CHAR THEN
1787                p_header_rec.attribute11(i) := g_attribute11;
1788             END IF;
1789 
1790             IF p_header_rec.attribute12(i) IS NULL
1791               OR p_header_rec.attribute12(i) = FND_API.G_MISS_CHAR THEN
1792                p_header_rec.attribute12(i) := g_attribute12;
1793             END IF;
1794 
1795             IF p_header_rec.attribute13(i) IS NULL
1796               OR p_header_rec.attribute13(i) = FND_API.G_MISS_CHAR THEN
1797                p_header_rec.attribute13(i) := g_attribute13;
1798             END IF;
1799 
1800             IF p_header_rec.attribute14(i) IS NULL
1801               OR p_header_rec.attribute14(i) = FND_API.G_MISS_CHAR THEN
1802                p_header_rec.attribute14(i) := g_attribute14;
1803             END IF;
1804 
1805             IF p_header_rec.attribute15(i) IS NULL
1806               OR p_header_rec.attribute15(i) = FND_API.G_MISS_CHAR THEN
1807                p_header_rec.attribute15(i) := g_attribute15;
1808             END IF;
1809 	END IF;
1810     END IF; 	--l_header_flex_enabled = 'Y'
1811 
1812 --start_date_active
1813 -- bug 4510489
1814 /*
1815     IF p_header_rec.start_date_active(I) IS NULL
1816        AND (p_header_rec.end_date_active(I) IS NULL or
1817 	to_date(p_header_rec.end_date_active(I), 'MM/DD/YYYY') <= to_date(l_start_date_active, 'MM/DD/YYYY'))
1818     THEN
1819 	p_header_rec.start_date_active(I) := l_start_date_active;
1820     END IF;
1821 */
1822 
1823 
1824   -- Updation check
1825   --cannot update Source system code, pte code
1826   IF p_header_rec.interface_action_code(I) = 'UPDATE'
1827      AND p_header_rec.process_status_flag(I) = 'P'  THEN
1828 
1829       qp_bulk_loader_pub.write_log( 'Update header no: '||to_char(l_list_header_id));
1830       l_old_PRICE_LIST_rec := QP_Price_List_Util.Query_Row
1831 	(   p_list_header_id        => l_list_header_id
1832 	);
1833 
1834       qp_bulk_loader_pub.write_log( 'Update source_system_code : '||l_old_price_list_rec.source_system_code);
1835       qp_bulk_loader_pub.write_log( 'Update pte_code : '||l_old_price_list_rec.pte_code);
1836       IF l_old_price_list_rec.source_system_code <> p_header_rec.source_system_code(I) or
1837          l_old_price_list_rec.pte_code <> p_header_rec.pte_code(I) THEN
1838 	    p_header_rec.process_status_flag(I):=NULL;
1839 	    fnd_message.set_name('QP', 'QP_NO_UPDATE_ATTRIBUTE');
1840             fnd_message.set_token('ATTRIBUTE', 'Source System Code / PTE Code');
1841 	    qp_bulk_msg.add(l_msg_rec);
1842       END IF;
1843   END IF;
1844 
1845 END LOOP;
1846 
1847   qp_bulk_loader_pub.write_log('Leaving Entity_header validation');
1848 
1849 EXCEPTION
1850     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1851        qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE ENTITY_HEADER:'||sqlerrm);
1852        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1853     WHEN OTHERS THEN
1854        qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE ENTITY_HEADER:'||sqlerrm);
1855        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1856 END ENTITY_HEADER;
1857 
1858 
1859 PROCEDURE ENTITY_LINE
1860           (P_LINE_REC IN OUT NOCOPY QP_BULK_LOADER_PUB.LINE_REC_TYPE)
1861 
1862 IS
1863    l_msg_rec QP_BULK_MSG.Msg_Rec_Type;
1864    l_dummy NUMBER;
1865    l_dummy_1 NUMBER;
1866    l_exist  NUMBER;
1867    l_pb_type_code  QP_LIST_LINES.price_break_type_code%type;
1868    l_art_opr  QP_LIST_LINES.arithmetic_operator%type;
1869    l_list_header_id	NUMBER:=null;
1870    l_orig_sys_header_ref VARCHAR2(50) := NULL;
1871    l_start_date date;
1872    l_line_flex_enabled VARCHAR2(1);
1873 
1874    --Bug 5246745 RAVI
1875    l_header_start_date DATE;
1876    l_header_end_date DATE;
1877 
1878    --Bug 5246745 RAVI
1879    l_servicable_item Varchar2(1) := 'N';
1880 
1881    --Bug 5246745 RAVI
1882    l_PBH_start_date DATE;
1883    l_PBH_end_date DATE;
1884 
1885 BEGIN
1886 
1887    qp_bulk_loader_pub.write_log('Entering Entity Line');
1888 
1889     l_line_flex_enabled := get_flex_enabled_flag('QP_LIST_LINES');
1890     qp_bulk_loader_pub.write_log('Flex enabled '||l_line_flex_enabled);
1891 
1892    FOR I IN 1..p_line_rec.orig_sys_line_ref.count
1893    LOOP
1894 
1895       --Initially setting the message context.
1896       --qp_bulk_loader_pub.write_log(' In the loop');
1897       l_msg_rec.REQUEST_ID := P_LINE_REC.REQUEST_ID(i);
1898       l_msg_rec.ENTITY_TYPE :='PRL';
1899       l_msg_rec.TABLE_NAME :='QP_INTERFACE_LIST_LINES';
1900       l_msg_rec.ORIG_SYS_HEADER_REF := p_line_rec.orig_sys_header_ref(I);
1901       l_msg_rec.ORIG_SYS_LINE_REF := p_line_rec.orig_sys_line_ref(I);
1902       l_msg_rec.ORIG_SYS_QUALIFIER_REF := NULL;
1903       l_msg_rec.ORIG_SYS_PRICING_ATTR_REF := NULL;
1904 
1905    /*-- populating some internal fields --*/
1906       If p_line_rec.interface_action_code(I)='INSERT' THEN
1907 	  select  qp_list_lines_s.nextval
1908 	    into  p_line_rec.list_line_id(I)
1909 	    from dual;
1910       end if;
1911       p_line_rec.list_line_no(I):= p_line_rec.list_line_id(I);
1912       p_line_rec.pricing_phase_id(I) := 1;
1913       p_line_rec.automatic_flag(I) := 'Y';
1914       p_line_rec.modifier_level_code(I) := 'LINE';
1915       p_line_rec.incompatibility_grp_code(I) := 'EXCL';
1916 
1917       IF l_orig_sys_header_ref IS NULL or
1918 	 l_orig_sys_header_ref <> p_line_rec.orig_sys_header_ref(I) THEN
1919 	  Begin
1920 	  select list_header_id, start_date_active
1921 	    into p_line_rec.list_header_id(I), l_start_date
1922 	    from qp_list_headers_b
1923 	   where orig_system_header_ref = p_line_rec.orig_sys_header_ref(I);
1924 	 Exception
1925 	    When no_data_found then
1926 	    p_line_rec.list_header_id(I) := -1;
1927 	    p_line_rec.process_status_flag(I):=NULL;
1928 	    fnd_message.set_name('QP', 'QP_INVALID_HEADER_REF');
1929 	    FND_MESSAGE.SET_TOKEN('REF_NO', p_line_rec.orig_sys_header_ref(I));
1930 	    FND_MESSAGE.SET_TOKEN('LS_CODE', NULL);
1931 	    qp_bulk_msg.add(l_msg_rec);
1932 	 End;
1933 	 IF p_line_rec.list_header_id(I) IS NOT NULL or
1934 	    p_line_rec.list_header_id(I) <> 0 THEN
1935 		l_list_header_id := p_line_rec.list_header_id(I);
1936 		l_orig_sys_header_ref := p_line_rec.orig_sys_header_ref(I);
1937 	 ELSE
1938 		l_list_header_id := NULL;
1939 		l_orig_sys_header_ref := NULL;
1940 	 END IF;
1941       ELSE
1942 	 p_line_rec.list_header_id(I) := l_list_header_id;
1943       END IF;
1944       qp_bulk_loader_pub.write_log('Line Start date active'||to_char(l_start_date));
1945 
1946    /*------- Performing required field validation for ---------*/
1947 
1948    --1.orig_sys_line_ref,
1949    IF p_line_rec.orig_sys_line_ref(I) IS NULL
1950    THEN
1951         p_line_rec.process_status_flag(I):=NULL;
1952 	fnd_message.set_name('QP', 'QP_ATTRIBUTE_REQUIRED');
1953 	fnd_message.set_token('ATTRIBUTE', 'ORIG_SYS_LINE_REF');
1954         qp_bulk_msg.add(l_msg_rec);
1955    END IF;
1956 
1957    --Bug#5359974 RAVI START
1958    --The continuous PB flag set to 'Y' if the line is PBH
1959    --1.1 continuous_price_break_flag
1960    IF p_line_rec.list_line_type_code(I)='PBH'
1961    THEN
1962       p_line_rec.continuous_price_break_flag(I):= 'Y';
1963    END IF;
1964    --Bug#5359974 RAVI END
1965 
1966    --2.List Line Type Code
1967     IF p_line_rec.list_line_type_code(I) IS NULL
1968    THEN
1969         p_line_rec.list_line_type_code(I):= '1';
1970         p_line_rec.process_status_flag(I):=NULL;
1971 	fnd_message.set_name('QP', 'QP_ATTRIBUTE_REQUIRED');
1972 	fnd_message.set_token('ATTRIBUTE', 'LIST_LINE_TYPE_CODE');
1973         qp_bulk_msg.add(l_msg_rec);
1974    END IF;
1975 
1976    IF p_line_rec.list_line_type_code(I) <>'PLL' AND p_line_rec.list_line_type_code(I)<>'PBH' THEN
1977        p_line_rec.process_status_flag(I):=NULL;
1978 	fnd_message.set_name('QP', 'QP_INVALID_ATTRIBUTE');
1979 	fnd_message.set_token('ATTRIBUTE', 'LIST_LINE_TYPE_CODE');
1980         qp_bulk_msg.add(l_msg_rec);
1981    END IF;
1982 
1983    --3. Arithmetic Operator
1984    IF p_line_rec.arithmetic_operator(I) IS NULL
1985    THEN
1986         p_line_rec.arithmetic_operator(I):= '1';
1987         p_line_rec.process_status_flag(I):=NULL;
1988 	fnd_message.set_name('QP', 'QP_ATTRIBUTE_REQUIRED');
1989 	fnd_message.set_token('ATTRIBUTE', 'ARITHMETIC_OPERATOR1');
1990         qp_bulk_msg.add(l_msg_rec);
1991    ELSE
1992 	IF p_line_rec.arithmetic_operator(I) = 'BLOCK_PRICE' AND
1993            p_line_rec.list_line_type_code(I) <> 'PBH' AND
1994 	   p_line_rec.price_break_header_ref(I) IS NULL THEN
1995 	    p_line_rec.arithmetic_operator(I):= '1';
1996 	    p_line_rec.process_status_flag(I):=NULL;
1997 	    FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
1998 	    fnd_message.set_token('ATTRIBUTE', 'ARITHMETIC_OPERATOR 2');
1999 	    qp_bulk_msg.add(l_msg_rec);
2000 	END IF;
2001 	IF  p_line_rec.arithmetic_operator(I) = 'BREAKUNIT_PRICE' THEN
2002 		IF p_line_rec.list_line_type_code(I) = 'PLL' AND
2003        		   p_line_rec.price_break_header_ref(I) IS NOT NULL THEN
2004 		    NULL;
2005 		ELSE
2006 		    p_line_rec.arithmetic_operator(I):= '1';
2007 		    p_line_rec.process_status_flag(I):=NULL;
2008 		    FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2009 		    fnd_message.set_token('ATTRIBUTE', 'ARITHMETIC_OPERATOR 3');
2010 		    qp_bulk_msg.add(l_msg_rec);
2011 		END IF;
2012 	 END IF;
2013     --End arithemetic operator check
2014 
2015     -- Bug# 5246745 RAVI START
2016     --Check if item is servicable
2017 	IF p_line_rec.arithmetic_operator(I) = 'PERCENT_PRICE' THEN
2018    		qp_bulk_loader_pub.write_log('Percent Price - arithmetic operator check');
2019 		l_exist :=0;
2020 
2021 		begin
2022 		   select count(*) into l_exist
2023     	   from qp_interface_pricing_attribs qipa, mtl_system_items_vl msiv
2024 		   where qipa.orig_sys_line_ref = p_line_rec.orig_sys_line_ref(I)
2025 		   and qipa.request_id = p_line_rec.request_id(I)
2026 		   and qipa.product_attribute_context = 'ITEM'
2027 		   and qipa.product_attribute = 'PRICING_ATTRIBUTE1'
2028 		   and msiv.inventory_item_id = to_number(qipa.PRODUCT_ATTR_VALUE)
2029 		   and msiv.organization_id = fnd_profile.value('QP_ORGANIZATION_ID')
2030 		   and msiv.service_item_flag = 'Y'
2031            and qipa.interface_action_code in ('INSERT','UPDATE');
2032 		exception
2033            when NO_DATA_FOUND then
2034 		   l_exist := 0;
2035 		end;
2036 
2037 		if l_exist=0 then
2038            begin
2039 	      select count(*) into l_exist
2040     	      from qp_pricing_attributes qpa, mtl_system_items_vl msiv
2041 	      where qpa.orig_sys_line_ref = p_line_rec.orig_sys_line_ref(I)
2042               -- Bug 5246745 Use Composite Index for Ref columns
2043               and qpa.orig_sys_header_ref = p_line_rec.orig_sys_header_ref(I)
2044               and qpa.product_attribute_context = 'ITEM'
2045 	      and qpa.product_attribute = 'PRICING_ATTRIBUTE1'
2046 	      and msiv.inventory_item_id = to_number(qpa.PRODUCT_ATTR_VALUE)
2047 	      and msiv.organization_id = fnd_profile.value('QP_ORGANIZATION_ID')
2048 	      and msiv.service_item_flag = 'Y'
2049               and qpa.orig_sys_pricing_attr_ref not in (
2050                        select qpa.orig_sys_pricing_attr_ref
2051                        from   qp_interface_pricing_attribs qipa
2052                        where  qipa.orig_sys_pricing_attr_ref = qpa.orig_sys_pricing_attr_ref
2053                        and    qipa.interface_action_code = 'DELETE'
2054                        and    qipa.request_id = p_line_rec.request_id(I));
2055 		   exception
2056               when NO_DATA_FOUND then
2057 		      l_exist := 0;
2058 		   end;
2059         end if;
2060 
2061 		if l_exist = 0 then
2062 		    p_line_rec.arithmetic_operator(I):= '1';
2063 		    p_line_rec.process_status_flag(I):=NULL;
2064 		    FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2065 		    fnd_message.set_token('ATTRIBUTE', 'ARITHMETIC_OPERATOR 4');
2066 		    qp_bulk_msg.add(l_msg_rec);
2067         else
2068            l_servicable_item := 'Y';
2069 		end if;
2070 	END IF;
2071    END IF; --End arithemetic operator check
2072 
2073    qp_bulk_loader_pub.write_log('After required field check');
2074 
2075     -- Uniqueness of orig_sys_line_ref
2076     l_exist := 0;
2077 
2078    qp_bulk_loader_pub.write_log('Header ref'|| p_line_rec.orig_sys_header_ref(I));
2079    qp_bulk_loader_pub.write_log('Line ref'|| p_line_rec.orig_sys_line_ref(I));
2080 
2081    BEGIN
2082      select count(*) into l_exist
2083      from   qp_list_lines
2084      where  orig_sys_line_ref = p_line_rec.orig_sys_line_ref(I)
2085      and    orig_sys_header_ref = p_line_rec.orig_sys_header_ref(I) ;
2086 
2087    EXCEPTION
2088       	When no_data_found then
2089 	   l_exist := 0;
2090    END;
2091 
2092      If p_line_rec.interface_action_code(I)='INSERT' AND l_exist >= 1 THEN
2093 	p_line_rec.process_status_flag(I):=NULL;
2094 	fnd_message.set_name('QP', 'ORIG_SYS_LINE_REF_NOT_UNIQUE');
2095         FND_MESSAGE.SET_TOKEN('REF_NO', p_line_rec.orig_sys_line_ref(I));
2096         qp_bulk_msg.add(l_msg_rec);
2097      ELSIF p_line_rec.interface_action_code(I)='UPDATE' AND l_exist = 0 THEN
2098 	p_line_rec.process_status_flag(I):=NULL;
2099 	fnd_message.set_name('QP', 'LINE_RECORD_DOES_NOT_EXIST');
2100         FND_MESSAGE.SET_TOKEN('REF_NO', p_line_rec.orig_sys_line_ref(I));
2101         qp_bulk_msg.add(l_msg_rec);
2102      END IF;
2103 
2104    If p_line_rec.interface_action_code(I)='INSERT' THEN
2105       l_exist:= NULL;
2106       select count(*) into l_exist
2107       from   qp_interface_list_lines
2108       where  request_id = p_line_rec.request_id(I)
2109       and    orig_sys_line_ref = p_line_rec.orig_sys_line_ref(I)
2110       and    orig_sys_header_ref = p_line_rec.orig_sys_header_ref(I);
2111 
2112     IF l_exist >1 THEN
2113 	p_line_rec.process_status_flag(I):=NULL;
2114 	fnd_message.set_name('QP', 'ORIG_SYS_LINE_REF_NOT_UNIQUE');
2115         FND_MESSAGE.SET_TOKEN('REF_NO', p_line_rec.orig_sys_line_ref(I));
2116         qp_bulk_msg.add(l_msg_rec);
2117     END IF;
2118    end if;
2119 
2120        --- check for conditionally required fields --------
2121      IF p_line_rec.list_line_type_code(I) = 'PBH' then
2122        IF p_line_rec.price_break_type_code(I) IS NULL then
2123 	p_line_rec.process_status_flag(I):=NULL;
2124 	fnd_message.set_name('QP', 'QP_ATTRIBUTE_REQUIRED');
2125 	fnd_message.set_token('ATTRIBUTE', 'PRICE_BREAK_TYPE_CODE');
2126         qp_bulk_msg.add(l_msg_rec);
2127        END IF;
2128     ELSE
2129        IF p_line_rec.price_break_header_ref(I) IS NULL and
2130 	  p_line_rec.price_break_type_code(I) IS NOT NULL then
2131 	    p_line_rec.process_status_flag(I):=NULL;
2132 	    FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2133 	    fnd_message.set_token('ATTRIBUTE', 'PRICE_BREAK_TYPE_CODE');
2134 	    qp_bulk_msg.add(l_msg_rec);
2135        END IF;
2136     END IF;
2137 
2138      IF p_line_rec.price_break_header_ref(I) IS NOT NULL then
2139        IF p_line_rec.rltd_modifier_grp_type(I) IS NULL then
2140 	p_line_rec.process_status_flag(I):=NULL;
2141 	fnd_message.set_name('QP', 'QP_ATTRIBUTE_REQUIRED');
2142 	fnd_message.set_token('ATTRIBUTE', 'RLTD_MODIFIER_GRP_TYPE');
2143         qp_bulk_msg.add(l_msg_rec);
2144        END IF;
2145     END IF;
2146 
2147        qp_bulk_loader_pub.write_log('check price break ARITHMETIC OPERATOR');
2148        -- check UNIT price break has no BLOCK price break child lines
2149 
2150        l_dummy:= null;
2151      IF p_line_rec.list_line_type_code(I) = 'PBH' then
2152 	 IF (p_LINE_rec.arithmetic_operator(I) = 'UNIT_PRICE')
2153          THEN
2154 	  SELECT count(*)
2155 	      INTO l_dummy
2156 	      FROM qp_interface_list_lines
2157 	     WHERE price_break_header_ref = p_LINE_rec.orig_sys_line_ref(I)
2158 	       AND arithmetic_operator = 'BLOCK_PRICE';
2159 
2160           -- if any price breaks are BLOCK
2161 	  IF (l_dummy > 0) THEN
2162 	     p_line_rec.process_status_flag(I):=NULL;
2163 	     FND_MESSAGE.SET_NAME('QP','QP_INVALID_CHILD_APPL_METHOD');
2164 	     qp_bulk_msg.add(l_msg_rec);
2165 	  END IF;
2166 
2167          -- Bug# 5228560 RAVI START
2168          l_dummy:= null;
2169 
2170          select count(*) into l_dummy
2171          from qp_list_lines l1, qp_list_lines l2, qp_rltd_modifiers l3
2172          where l1.orig_sys_line_ref=p_LINE_rec.orig_sys_line_ref(I)
2173          -- Bug 5246745 Use Composite Index for Ref columns
2174          and l1.orig_sys_header_ref=p_LINE_rec.orig_sys_header_ref(I)
2175          and l1.list_line_id=l3.FROM_RLTD_MODIFIER_ID
2176          and l3.TO_RLTD_MODIFIER_ID=l2.list_line_id
2177          and l3.RLTD_MODIFIER_GRP_TYPE='PRICE BREAK'
2178 	 AND l2.arithmetic_operator <> 'UNIT_PRICE';
2179 
2180          -- if any price breaks are BLOCK in old lines
2181          IF (l_dummy > 0) THEN
2182 	    p_line_rec.process_status_flag(I):=NULL;
2183 	    FND_MESSAGE.SET_NAME('QP','QP_INVALID_CHILD_APPL_METHOD');
2184 	    qp_bulk_msg.add(l_msg_rec);
2185 	 END IF;
2186          -- Bug# 5228560 RAVI END
2187       END IF;
2188 
2189        -- block pricing
2190        l_dummy := null;
2191        l_dummy_1 := null;
2192        IF (p_LINE_rec.arithmetic_operator(I) = 'BLOCK_PRICE' AND
2193 	   p_LINE_rec.price_break_type_code(I) = 'POINT')
2194        THEN
2195 --	  SELECT count(*)
2196 --	      INTO l_dummy
2197 --	      FROM qp_list_lines pl, qp_list_lines cl,qp_rltd_modifiers rtd
2198 --	     WHERE pl.orig_sys_line_ref = p_line_rec.orig_sys_line_ref(I)
2199 --	       AND rtd.from_rltd_modifier_id = pl.list_line_id
2200 --	       AND cl.list_line_id = rtd.to_rltd_modifier_id
2201 --	       AND (cl.arithmetic_operator = 'UNIT_PRICE' OR cl.recurring_value IS NOT NULL);
2202 --
2203 	  SELECT count(*)
2204 	      INTO l_dummy
2205 	      FROM qp_interface_list_lines
2206 	     WHERE price_break_header_ref = p_LINE_rec.orig_sys_line_ref(I)
2207 	       AND (arithmetic_operator = 'UNIT_PRICE' OR recurring_value IS NOT NULL);
2208 
2209 	IF (l_dummy > 0) THEN
2210 	    p_line_rec.process_status_flag(I):=NULL;
2211 	     FND_MESSAGE.SET_NAME('QP','QP_INVALID_PRICE_BREAK');
2212 	     qp_bulk_msg.add(l_msg_rec);
2213 	END IF;
2214 
2215       END IF;
2216 
2217       -- Bug# 5228560 RAVI START
2218       IF p_LINE_rec.arithmetic_operator(I) = 'BLOCK_PRICE' THEN
2219          l_dummy := null;
2220          IF p_LINE_rec.price_break_type_code(I) = 'RANGE' THEN
2221             select count(*) into l_dummy
2222             from qp_list_lines l1, qp_list_lines l2, qp_rltd_modifiers l3
2223             where l1.orig_sys_line_ref=p_LINE_rec.orig_sys_line_ref(I)
2224             -- Bug 5246745 Use Composite Index for Ref columns
2225             and l1.orig_sys_header_ref=p_LINE_rec.orig_sys_header_ref(I)
2226             and l1.list_line_id=l3.FROM_RLTD_MODIFIER_ID
2227             and l3.TO_RLTD_MODIFIER_ID=l2.list_line_id
2228             and l3.RLTD_MODIFIER_GRP_TYPE='PRICE BREAK'
2229             AND l2.arithmetic_operator = 'UNIT_PRICE';
2230          END IF;
2231 
2232          IF (l_dummy > 0) THEN
2233 	        p_line_rec.process_status_flag(I):=NULL;
2234             FND_MESSAGE.SET_NAME('QP','QP_INVALID_PRICE_BREAK');
2235             qp_bulk_msg.add(l_msg_rec);
2236          END IF;
2237 
2238          l_dummy := null;
2239          IF p_LINE_rec.price_break_type_code(I) = 'POINT' THEN
2240             select count(*) into l_dummy
2241             from qp_list_lines l1, qp_list_lines l2, qp_rltd_modifiers l3
2242             where l1.orig_sys_line_ref=p_LINE_rec.orig_sys_line_ref(I)
2243             -- Bug 5246745 Use Composite Index for Ref columns
2244             and l1.orig_sys_header_ref=p_LINE_rec.orig_sys_header_ref(I)
2245             and l1.list_line_id=l3.FROM_RLTD_MODIFIER_ID
2246             and l3.TO_RLTD_MODIFIER_ID=l2.list_line_id
2247             and l3.RLTD_MODIFIER_GRP_TYPE='PRICE BREAK'
2248             AND l2.arithmetic_operator <> 'UNIT_PRICE';
2249          END IF;
2250 
2251          IF (l_dummy > 0) THEN
2252             p_line_rec.process_status_flag(I):=NULL;
2253             FND_MESSAGE.SET_NAME('QP','QP_INVALID_PRICE_BREAK');
2254             qp_bulk_msg.add(l_msg_rec);
2255          END IF;
2256       END IF;
2257       -- Bug# 5228560 RAVI END
2258 
2259    END IF;
2260 
2261       -- check for pbh child line arithmetic operator
2262      IF p_line_rec.list_line_type_code(I) = 'PLL' AND
2263         p_line_rec.price_break_header_ref(I) IS NOT NULL THEN
2264 
2265         IF p_line_rec.arithmetic_operator(I) = 'BREAKUNIT_PRICE' and
2266            p_line_rec.recurring_value(I) is not NULL THEN
2267 	       P_LINE_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
2268 	       FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2269 	       FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Recurring Value');
2270 	       QP_BULK_MSG.ADD(l_msg_rec);
2271         END IF;
2272 
2273         BEGIN
2274            SELECT price_break_type_code, arithmetic_operator
2275 	       INTO l_pb_type_code, l_art_opr
2276 	       FROM QP_INTERFACE_LIST_LINES
2277 	       WHERE orig_sys_line_ref = p_line_rec.price_break_header_ref(I)
2278 	       AND orig_sys_header_ref = p_line_rec.orig_sys_header_ref(I)
2279 	       AND request_id = p_line_rec.request_id(I);
2280            --Bug 4405737 START RAVI
2281            /**
2282            Price break type of Price break hdr line and child line should not be null.
2283            The price break type code of Price break hdr line and child line should be
2284            equal.
2285            **/
2286            IF p_line_rec.price_break_type_code(I) IS NULL OR
2287               l_pb_type_code IS NULL THEN
2288               P_LINE_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
2289               FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2290 	          FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Recurring Value');
2291 	          QP_BULK_MSG.ADD(l_msg_rec);
2292               qp_bulk_loader_pub.write_log('PRICE BREAK TYPE CODE NULL');
2293            ELSE
2294               IF p_line_rec.price_break_type_code(I) = l_pb_type_code
2295               THEN
2296                  NULL;
2297               ELSE
2298                  P_LINE_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
2299                  FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2300                  FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Recurring Value');
2301                  QP_BULK_MSG.ADD(l_msg_rec);
2302                  qp_bulk_loader_pub.write_log('PRICE BREAK TYPE CODE OF PARENT AND CHILD UNEQUAL');
2303               END IF;
2304            END IF;
2305     --Bug 4405737 END RAVI
2306       IF l_servicable_item='N' THEN
2307          IF p_line_rec.arithmetic_operator(I) = 'UNIT_PRICE' THEN
2308             IF l_art_opr <> 'UNIT_PRICE'
2309 		       and l_art_opr <> 'PERCENT_PRICE'
2310             THEN
2311 	           P_LINE_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
2312 	           FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2313 	           FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Arithmetic Operator');
2314 	           QP_BULK_MSG.ADD(l_msg_rec);
2315             END IF;
2316          ELSIF p_line_rec.arithmetic_operator(I) = 'BLOCK_PRICE' THEN
2317             IF l_art_opr <> 'BLOCK_PRICE' THEN
2318 	           P_LINE_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
2319                FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2320 	           FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Arithmetic Operator');
2321 	           QP_BULK_MSG.ADD(l_msg_rec);
2322             END IF;
2323          ELSIF p_line_rec.arithmetic_operator(I) = 'BREAKUNIT_PRICE' THEN
2324             IF l_art_opr <> 'BLOCK_PRICE' OR l_pb_type_code <> 'RANGE'  THEN
2325 	           P_LINE_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
2326                FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2327 	           FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Arithmetic Operator');
2328 	           QP_BULK_MSG.ADD(l_msg_rec);
2329             END IF;
2330 	     END IF;
2331       END IF;
2332 
2333          -- Bug# 5228560 (5246745) RAVI START
2334          -- Check for application method compatibility between PBH line and PBC line
2335 	     l_pb_type_code := NULL;
2336 	     l_art_opr := NULL;
2337 
2338          --Get the PBH details
2339          SELECT L2.price_break_type_code, L2.arithmetic_operator
2340     	 INTO l_pb_type_code, l_art_opr
2341          from qp_list_lines l1, qp_list_lines l2, qp_rltd_modifiers l3
2342          where l1.orig_sys_line_ref=p_LINE_rec.orig_sys_line_ref(I)
2343          -- Bug 5246745 Use Composite Index for Ref columns
2344          and l1.orig_sys_header_ref=p_LINE_rec.orig_sys_header_ref(I)
2345          and l1.list_line_id=l3.TO_RLTD_MODIFIER_ID
2346          and l3.FROM_RLTD_MODIFIER_ID=l2.list_line_id
2347          and l3.RLTD_MODIFIER_GRP_TYPE='PRICE BREAK';
2348 
2349          IF l_servicable_item='N' THEN
2350             IF p_line_rec.arithmetic_operator(I) = 'UNIT_PRICE' THEN
2351                IF l_art_opr <> 'UNIT_PRICE' THEN
2352                   P_LINE_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
2353                   FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2354                   FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Arithmetic Operator - Orderable item - PBC UNIT_PRICE -- PBH Wrong');
2355                   QP_BULK_MSG.ADD(l_msg_rec);
2356                END IF;
2357 	        ELSIF p_line_rec.arithmetic_operator(I) = 'BLOCK_PRICE' THEN
2358                IF l_art_opr <> 'BLOCK_PRICE' THEN
2359 	              P_LINE_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
2360                   FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2361 	              FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Arithmetic Operator - Orderable item - PBC BLOCK_PRICE -- PBH Wrong');
2362 	              QP_BULK_MSG.ADD(l_msg_rec);
2363                END IF;
2364             ELSIF p_line_rec.arithmetic_operator(I) = 'BREAKUNIT_PRICE' THEN
2365                IF l_art_opr <> 'BLOCK_PRICE' OR l_pb_type_code <> 'RANGE' THEN
2366                   P_LINE_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
2367 	              FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2368                   FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Arithmetic Operator - Orderable item - PBC BREAKUNIT_PRICE -- PBH Wrong');
2369 	              QP_BULK_MSG.ADD(l_msg_rec);
2370                END IF;
2371 	        END IF;
2372          ELSIF l_servicable_item='Y' THEN
2373             IF p_line_rec.arithmetic_operator(I) = 'UNIT_PRICE' THEN
2374                IF l_art_opr <> 'UNIT_PRICE' and l_art_opr <> 'PERCENT_PRICE' THEN
2375                   P_LINE_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
2376                   FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2377                   FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Arithmetic Operator - Servicable item - PBC UNIT_PRICE -- PBH Wrong');
2378                   QP_BULK_MSG.ADD(l_msg_rec);
2379                END IF;
2380 	        ELSIF p_line_rec.arithmetic_operator(I) = 'BLOCK_PRICE' THEN
2381                IF l_art_opr <> 'BLOCK_PRICE' THEN
2382 	              P_LINE_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
2383                   FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2384 	              FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Arithmetic Operator - Servicable item - PBC BLOCK_PRICE -- PBH Wrong');
2385 	              QP_BULK_MSG.ADD(l_msg_rec);
2386                END IF;
2387             ELSIF p_line_rec.arithmetic_operator(I) = 'BREAKUNIT_PRICE' THEN
2388                IF l_art_opr <> 'BLOCK_PRICE' THEN
2389                   P_LINE_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
2390 	              FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2391                   FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Arithmetic Operator - Servicable item - PBC BREAKUNIT_PRICE -- PBH Wrong');
2392 	              QP_BULK_MSG.ADD(l_msg_rec);
2393                END IF;
2394             ELSIF p_line_rec.arithmetic_operator(I) = 'PERCENT_PRICE' THEN
2395                IF l_art_opr <> 'BLOCK_PRICE' OR
2396                   l_art_opr <> 'PERCENT_PRICE' OR
2397                   l_art_opr <> 'UNIT_PRICE'
2398                THEN
2399                   P_LINE_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
2400 	              FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
2401                   FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Arithmetic Operator - Servicable item - PBC PERCENT_PRICE -- PBH Wrong');
2402 	              QP_BULK_MSG.ADD(l_msg_rec);
2403                END IF;
2404             END IF;
2405          END IF;
2406          -- Bug# 5228560 (5246745) RAVI END
2407 
2408         EXCEPTION
2409 	   WHEN NO_DATA_FOUND THEN
2410 	      null;
2411 	END;
2412      END IF;
2413 
2414       qp_bulk_loader_pub.write_log('After pbh check');
2415 
2416    -- check for operand value for the line.
2417    IF  p_LINE_rec.list_line_type_code(I) = 'PLL'
2418    and p_LINE_rec.operand(I) IS NULL
2419    and p_LINE_rec.price_by_formula_id(I) IS NULL
2420    and p_LINE_rec.generate_using_formula_id(I) IS NULL
2421    THEN
2422 
2423     p_line_rec.process_status_flag(I):=NULL;
2424     FND_MESSAGE.SET_NAME('QP','QP_OPERAND_FORMULA');
2425     QP_BULK_MSG.ADD(l_msg_rec);
2426 
2427    END IF;
2428 
2429    -- Recurring value check
2430    -- Bug 4995724 START RAVI
2431    /**
2432    Recurring value should always be more than 1.
2433    Recurring value allowed only for RANGE and BLOCK PRICE
2434    **/
2435    IF p_line_rec.recurring_value(I) is not null THEN
2436       IF p_line_rec.recurring_value(I) < 1 Then
2437          FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
2438          FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Recurring Value');
2439          QP_BULK_MSG.ADD(l_msg_rec);
2440       ELSIF p_line_rec.arithmetic_operator(I) <> 'BLOCK_PRICE'
2441       OR l_art_opr <> 'BLOCK_PRICE'
2442       OR l_pb_type_code <> 'RANGE'
2443       THEN
2444          FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
2445          FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Recurring Value');
2446          QP_BULK_MSG.ADD(l_msg_rec);
2447        END IF;
2448    END IF;
2449    /**
2450    IF p_line_rec.recurring_value(I) is not null
2451       And p_line_rec.recurring_value(I) < 1 Then
2452       FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
2453       FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Recurring Value');
2454       QP_BULK_MSG.ADD(l_msg_rec);
2455    END IF;
2456    **/
2457    -- Bug 4995724 END RAVI
2458 
2459 
2460    -- Date Check
2461    IF p_line_rec.end_date_active(I) IS NULL
2462    OR p_line_rec.start_date_active(I) IS NULL
2463    THEN
2464        Null;
2465    ELSIF (p_line_rec.start_date_active(I) > p_line_rec.end_date_active(I) ) THEN
2466        FND_MESSAGE.SET_NAME('QP', 'QP_STRT_DATE_BFR_END_DATE');
2467        QP_BULK_MSG.Add(l_msg_rec);
2468        --Bug# 5228368 RAVI
2469        p_line_rec.process_status_flag(I):=NULL;
2470    END IF;
2471 
2472 
2473    -- Date check with respect to header dates
2474    /**
2475     * Bug 5246745 RAVI START
2476     * Price List Line Start date should be on or after Price List Header Start Date
2477     * Price List Line End date should be on or before Price List Header End Date
2478     **/
2479     l_header_start_date := null;
2480     l_header_end_date := null;
2481 
2482     BEGIN
2483        select fnd_date.canonical_to_date(start_date_active),
2484               fnd_date.canonical_to_date(end_date_active)
2485        into l_header_start_date, l_header_end_date
2486        from qp_interface_list_headers
2487        where orig_sys_header_ref=p_line_rec.orig_sys_header_ref(I)
2488          and request_id=p_line_rec.request_id(I)
2489          and interface_action_code in ('INSERT','UPDATE');
2490     EXCEPTION
2491        WHEN OTHERS
2492        THEN
2493           qp_bulk_loader_pub.write_log( 'ERROR in comparing the Header and Line start Dates (INTERFACE)');
2494     END;
2495 
2496     IF l_header_start_date IS NULL THEN
2497        BEGIN
2498           select start_date_active, end_date_active
2499           into l_header_start_date, l_header_end_date
2500           from qp_list_headers_b
2501           where orig_system_header_ref=p_line_rec.orig_sys_header_ref(I);
2502        EXCEPTION
2503           WHEN OTHERS
2504           THEN
2505              qp_bulk_loader_pub.write_log( 'ERROR in comparing the Header and Line start Dates (QP)');
2506        END;
2507     END IF;
2508 
2509     IF p_line_rec.start_date_active(I) < l_header_start_date OR
2510        p_line_rec.end_date_active(I) > l_header_end_date
2511     THEN
2512        FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_DATE');
2513        QP_BULK_MSG.Add(l_msg_rec);
2514        p_line_rec.process_status_flag(I):=NULL;
2515     END IF;
2516     -- Bug 5246745 RAVI END
2517 
2518 
2519    -- Price break child date check with respect to price break header dates
2520    /**
2521     * Bug 5246745 RAVI START
2522     * Price break child line Start date should be equal to Price break Header Start Date
2523     * Price break child line End date should be equal to Price break Header End Date
2524     **/
2525     l_PBH_start_date := null;
2526     l_PBH_end_date := null;
2527 
2528     IF p_line_rec.list_line_type_code(I)='PLL' AND
2529        p_line_rec.PRICE_BREAK_HEADER_REF(I) is not null AND
2530        p_line_rec.RLTD_MODIFIER_GRP_TYPE(I)='PRICE BREAK'
2531     THEN
2532        BEGIN
2533           select start_date_active, end_date_active
2534           into l_PBH_start_date, l_PBH_end_date
2535           from qp_interface_list_lines
2536           where orig_sys_line_ref=p_line_rec.PRICE_BREAK_HEADER_REF(I)
2537             -- Bug 5246745 Use Composite Index for Ref columns
2538             and orig_sys_header_ref=p_LINE_rec.orig_sys_header_ref(I)
2539             and request_id=p_line_rec.request_id(I)
2540             and interface_action_code in ('INSERT','UPDATE');
2541        EXCEPTION
2542           WHEN OTHERS
2543           THEN
2544              qp_bulk_loader_pub.write_log( 'ERROR in comparing the PBH and PBC start Dates (INTERFACE)');
2545        END;
2546 
2547        IF l_PBH_start_date is null THEN
2548           BEGIN
2549              select start_date_active, end_date_active
2550              into l_PBH_start_date, l_PBH_end_date
2551              from qp_list_lines
2552              where orig_sys_line_ref=p_line_rec.PRICE_BREAK_HEADER_REF(I)
2553              -- Bug 5246745 Use Composite Index for Ref columns
2554              and orig_sys_header_ref=p_LINE_rec.orig_sys_header_ref(I);
2555           EXCEPTION
2556              WHEN OTHERS
2557              THEN
2558                 qp_bulk_loader_pub.write_log( 'ERROR in comparing the PBH and PBC start Dates (INTERFACE)');
2559           END;
2560        END IF;
2561 
2562        IF l_PBH_start_date <> p_line_rec.start_date_active(I) OR
2563           l_PBH_end_date <> p_line_rec.end_date_active(I)
2564        THEN
2565           FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_DATE');
2566           QP_BULK_MSG.Add(l_msg_rec);
2567           p_line_rec.process_status_flag(I):=NULL;
2568        END IF;
2569     END IF;
2570     -- Bug 5246745 RAVI END
2571 
2572 --Flex field check
2573 
2574     IF l_line_flex_enabled = 'Y' THEN
2575       qp_bulk_loader_pub.write_log( 'Line Flex enabled ');
2576 
2577          IF NOT Init_Desc_Flex
2578                (p_flex_name	     =>'QP_LIST_LINES'
2579 	       ,p_context            => p_line_rec.context(i)
2580                ,p_attribute1         => p_line_rec.attribute1(i)
2581                ,p_attribute2         => p_line_rec.attribute2(i)
2582                ,p_attribute3         => p_line_rec.attribute3(i)
2583                ,p_attribute4         => p_line_rec.attribute4(i)
2584                ,p_attribute5         => p_line_rec.attribute5(i)
2585                ,p_attribute6         => p_line_rec.attribute6(i)
2586                ,p_attribute7         => p_line_rec.attribute7(i)
2587                ,p_attribute8         => p_line_rec.attribute8(i)
2588                ,p_attribute9         => p_line_rec.attribute9(i)
2589                ,p_attribute10        => p_line_rec.attribute10(i)
2590                ,p_attribute11        => p_line_rec.attribute11(i)
2591                ,p_attribute12        => p_line_rec.attribute12(i)
2592                ,p_attribute13        => p_line_rec.attribute13(i)
2593                ,p_attribute14        => p_line_rec.attribute14(i)
2594                ,p_attribute15        => p_line_rec.attribute15(i)) THEN
2595 
2596 	         QP_BULK_MSG.ADD(l_msg_rec);
2597 
2598                  -- Log Error Message
2599                  FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
2600                  FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
2601                                        'Entity:Flexfield:Line_Desc_Flex');
2602 	         p_line_rec.process_status_flag(I):=NULL;
2603 
2604 	         QP_BULK_MSG.ADD(l_msg_rec);
2605 
2606           ELSE -- if the flex validation is successfull
2607 
2608             IF p_line_rec.context(i) IS NULL
2609               OR p_line_rec.context(i) = FND_API.G_MISS_CHAR THEN
2610                p_line_rec.context(i)    := g_context;
2611             END IF;
2612 
2613             IF p_line_rec.attribute1(i) IS NULL
2614               OR p_line_rec.attribute1(i) = FND_API.G_MISS_CHAR THEN
2615                p_line_rec.attribute1(i) := g_attribute1;
2616             END IF;
2617 
2618             IF p_line_rec.attribute2(i) IS NULL
2619               OR p_line_rec.attribute2(i) = FND_API.G_MISS_CHAR THEN
2620                p_line_rec.attribute2(i) := g_attribute2;
2621             END IF;
2622 
2623             IF p_line_rec.attribute3(i) IS NULL
2624               OR p_line_rec.attribute3(i) = FND_API.G_MISS_CHAR THEN
2625                p_line_rec.attribute3(i) := g_attribute3;
2626             END IF;
2627 
2628             IF p_line_rec.attribute4(i) IS NULL
2629               OR p_line_rec.attribute4(i) = FND_API.G_MISS_CHAR THEN
2630                p_line_rec.attribute4(i) := g_attribute4;
2631             END IF;
2632 
2633             IF p_line_rec.attribute5(i) IS NULL
2634               OR p_line_rec.attribute5(i) = FND_API.G_MISS_CHAR THEN
2635                p_line_rec.attribute5(i) := g_attribute5;
2636             END IF;
2637 
2638             IF p_line_rec.attribute6(i) IS NULL
2639               OR p_line_rec.attribute6(i) = FND_API.G_MISS_CHAR THEN
2640                p_line_rec.attribute6(i) := g_attribute6;
2641             END IF;
2642             IF p_line_rec.attribute7(i) IS NULL
2643               OR p_line_rec.attribute7(i) = FND_API.G_MISS_CHAR THEN
2644                p_line_rec.attribute7(i) := g_attribute7;
2645             END IF;
2646 
2647             IF p_line_rec.attribute8(i) IS NULL
2648               OR p_line_rec.attribute8(i) = FND_API.G_MISS_CHAR THEN
2649                p_line_rec.attribute8(i) := g_attribute8;
2650             END IF;
2651 
2652             IF p_line_rec.attribute9(i) IS NULL
2653               OR p_line_rec.attribute9(i) = FND_API.G_MISS_CHAR THEN
2654                p_line_rec.attribute9(i) := g_attribute9;
2655             END IF;
2656 
2657             IF p_line_rec.attribute10(i) IS NULL
2658               OR p_line_rec.attribute10(i) = FND_API.G_MISS_CHAR THEN
2659                p_line_rec.attribute10(i) := G_attribute10;
2660             End IF;
2661 
2662             IF p_line_rec.attribute11(i) IS NULL
2663               OR p_line_rec.attribute11(i) = FND_API.G_MISS_CHAR THEN
2664                p_line_rec.attribute11(i) := g_attribute11;
2665             END IF;
2666 
2667             IF p_line_rec.attribute12(i) IS NULL
2668               OR p_line_rec.attribute12(i) = FND_API.G_MISS_CHAR THEN
2669                p_line_rec.attribute12(i) := g_attribute12;
2670             END IF;
2671 
2672             IF p_line_rec.attribute13(i) IS NULL
2673               OR p_line_rec.attribute13(i) = FND_API.G_MISS_CHAR THEN
2674                p_line_rec.attribute13(i) := g_attribute13;
2675             END IF;
2676 
2677             IF p_line_rec.attribute14(i) IS NULL
2678               OR p_line_rec.attribute14(i) = FND_API.G_MISS_CHAR THEN
2679                p_line_rec.attribute14(i) := g_attribute14;
2680             END IF;
2681 
2682             IF p_line_rec.attribute15(i) IS NULL
2683               OR p_line_rec.attribute15(i) = FND_API.G_MISS_CHAR THEN
2684                p_line_rec.attribute15(i) := g_attribute15;
2685             END IF;
2686 	END IF;
2687     END IF;
2688 
2689 -- Basic_Pricing_Condition
2690    IF QP_BULK_LOADER_PUB.GET_QP_STATUS <> 'I' THEN
2691 	IF p_line_rec.price_break_type_code(I) IS NOT NULL THEN
2692 	   p_line_rec.price_break_type_code(I) := NULL;
2693 	END IF;
2694 	IF p_line_rec.primary_uom_flag(I) = 'Y' THEN
2695 	   p_line_rec.primary_uom_flag(I) := 'N';
2696 	END IF;
2697    END IF;
2698 --start_date_active
2699       qp_bulk_loader_pub.write_log('Line Start date value'||nvl(to_char(p_line_rec.start_date_active(I)), 'NULL'));
2700       qp_bulk_loader_pub.write_log('Line end date value'||nvl(to_char(p_line_rec.end_date_active(I)), 'NULL'));
2701 
2702     --Bug#5353889 RAVI START
2703     --Start date null should be allowed
2704     /**
2705     IF p_line_rec.start_date_active(I) IS NULL
2706        AND (p_line_rec.end_date_active(I) IS NULL or
2707 	p_line_rec.end_date_active(I) <= l_start_date)
2708     THEN
2709       qp_bulk_loader_pub.write_log('Line Start date updated');
2710 	p_line_rec.start_date_active(I) := l_start_date;
2711     END IF;
2712     **/
2713     --Bug#5353889 RAVI END
2714 
2715   END LOOP;
2716 
2717   qp_bulk_loader_pub.write_log('Leaving entity line validation');
2718 
2719  EXCEPTION
2720     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2721        qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE ENTITY_LINE:'||sqlerrm);
2722        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2723     WHEN OTHERS THEN
2724        qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE ENTITY_LINE:'||sqlerrm);
2725        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2726 END ENTITY_LINE;
2727 
2728 
2729 PROCEDURE ENTITY_QUALIFIER
2730           (p_qualifier_rec IN OUT NOCOPY QP_BULK_LOADER_PUB.qualifier_rec_type)
2731 IS
2732  l_msg_rec                  QP_BULK_MSG.Msg_Rec_Type;
2733  l_segment_name             VARCHAR2(240);
2734  x_value                    VARCHAR2(240);
2735  x_id                       VARCHAR2(150);
2736  x_format_type              VARCHAR2(1);
2737  l_exist                    NUMBER;
2738  l_dummy                    VARCHAR2(240);
2739  l_seg_level                VARCHAR2(10);
2740 
2741 l_context_error VARCHAR2(1);
2742 l_attribute_error VARCHAR2(1);
2743 l_value_error VARCHAR2(1);
2744 l_datatype VARCHAR2(1);
2745 l_precedence NUMBER;
2746 l_error_code NUMBER;
2747 
2748 l_context_type                VARCHAR2(30);
2749 l_sourcing_enabled            VARCHAR2(1);
2750 l_sourcing_status             VARCHAR2(1);
2751 l_hierarchy_enabled           VARCHAR2(1);
2752 l_sourcing_method             VARCHAR2(30);
2753 
2754 -- Bug 4926775 RAVI
2755 /**
2756 local variable for header id.
2757 **/
2758 l_list_header_id NUMBER;
2759 
2760 BEGIN
2761   qp_bulk_loader_pub.write_log('Entering Entity Qualifier');
2762 
2763   FOR I IN p_qualifier_rec.orig_sys_qualifier_ref.first
2764            ..p_qualifier_rec.orig_sys_qualifier_ref.last
2765   LOOP
2766 
2767      --qp_bulk_loader_pub.write_log('request_id: '||p_qualifier_rec.request_id(I));
2768       --Initially setting the message context.
2769 
2770      l_msg_rec.REQUEST_ID := P_QUALIFIER_REC.REQUEST_ID(I);
2771      l_msg_rec.ENTITY_TYPE :='PRL';
2772      l_msg_rec.TABLE_NAME :='QP_INTERFACE_QUALIFIERS';
2773      l_msg_rec.ORIG_SYS_HEADER_REF := p_qualifier_rec.orig_sys_header_ref(I);
2774      l_msg_rec.ORIG_SYS_QUALIFIER_REF := p_qualifier_rec.orig_sys_qualifier_ref(I);
2775      l_msg_rec.ORIG_SYS_QUALIFIER_REF := NULL;
2776      l_msg_rec.ORIG_SYS_PRICING_ATTR_REF := NULL;
2777 
2778      /*--- Internal Field populate ----*/
2779      p_qualifier_rec.excluder_flag(I) := 'N';
2780      p_qualifier_rec.orig_sys_line_ref(I) := '-1';
2781 
2782       If p_qualifier_rec.interface_action_code(I)='INSERT' THEN
2783        Select qp_qualifiers_s.nextval
2784        into p_qualifier_rec.qualifier_id(I) from dual;
2785       end if;
2786 
2787 
2788 
2789      /*---- Conversion of qualifier_context, qualifier_attribute,-------------
2790      --------qualifier_attr_value, qualifier_attr_value_to  -----------------*/
2791 
2792      IF p_qualifier_rec.qualifier_grouping_no(I) IS NULL THEN
2793 	p_qualifier_rec.process_status_flag(I):=NULL;
2794 	FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
2795         FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER GROUPING NO');
2796         QP_BULK_MSG.ADD(l_msg_rec);
2797      END IF;
2798 
2799      IF p_qualifier_rec.list_line_id(I) IS NOT NULL THEN
2800 	IF p_qualifier_rec.list_line_id(I) <> -1 THEN
2801 	       p_qualifier_rec.process_status_flag(I):=NULL;
2802 	       FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
2803 	       FND_MESSAGE.SET_TOKEN('ATTRIBUTE','LIST_LINE_ID');
2804 	       QP_BULK_MSG.ADD(l_msg_rec);
2805      	END IF;
2806      ELSE
2807 	p_qualifier_rec.list_line_id(I):=-1;
2808      END IF;
2809      -- Qualifier Context
2810 /*     IF p_qualifier_rec.qualifier_context(I) IS NULL THEN
2811 	p_qualifier_rec.qualifier_context(I) := '1';
2812 	p_qualifier_rec.process_status_flag(I):=NULL;
2813 	FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
2814         FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER CONTEXT');
2815         QP_BULK_MSG.ADD(l_msg_rec);
2816     END IF; */
2817 
2818 
2819      -- Qualifier Attribute
2820 
2821 	IF p_qualifier_rec.qualifier_attribute(I) IS NULL THEN
2822 
2823 --	IF p_qualifier_rec.qualifier_attribute_code(I) IS NULL THEN
2824 	p_qualifier_rec.qualifier_attribute_code(I):= '1';
2825 	p_qualifier_rec.process_status_flag(I):=NULL;
2826 	FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
2827         FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER ATTRIBUTE CODE');
2828         QP_BULK_MSG.ADD(l_msg_rec);
2829 /*	ELSE
2830 
2831 	   BEGIN
2832 	      p_qualifier_rec.qualifier_attribute(I):= QP_UTIL.Get_Attribute_Name(
2833 				p_application_short_name => 'QP',
2834 				p_flexfield_name=> 'QP_ATTR_DEFNS_QUALIFIER',
2835 				p_context_name =>p_qualifier_rec.qualifier_context(I),
2836 				p_attribute_name=>p_qualifier_rec.qualifier_attribute_code(I));
2837 
2838               IF p_qualifier_rec.qualifier_attribute(I) IS NULL THEN
2839                 p_qualifier_rec.qualifier_attribute(I):='1';
2840 		p_qualifier_rec.process_status_flag(I):=NULL;
2841 		FND_MESSAGE.SET_NAME('QP','QP_VALUE_TO_ID_ERROR');
2842 		FND_MESSAGE.SET_TOKEN('ATTRIBUTE','qualifier_attribute');
2843 		QP_BULK_MSG.ADD(l_msg_rec);
2844               END IF;
2845 	   EXCEPTION
2846 	     WHEN NO_DATA_FOUND THEN
2847 		 p_qualifier_rec.qualifier_attribute(I):='1';
2848 		p_qualifier_rec.process_status_flag(I):=NULL;
2849 		FND_MESSAGE.SET_NAME('QP','QP_VALUE_TO_ID_ERROR');
2850 		FND_MESSAGE.SET_TOKEN('ATTRIBUTE','qualifier_attribute');
2851 		QP_BULK_MSG.ADD(l_msg_rec);
2852 	  END;
2853 	END IF; */
2854 
2855 	END IF;
2856 
2857     	IF ( p_qualifier_rec.qualify_hier_descendents_flag(I) IS NOT NULL)
2858           THEN
2859                 IF p_qualifier_rec.qualify_hier_descendents_flag(I) NOT IN ('Y', 'N', 'y', 'n')
2860                 THEN
2861                 p_qualifier_rec.process_status_flag(I):=NULL;
2862                 FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
2863                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFY HIER DESCENDENTS FLAG ');
2864                 qp_bulk_msg.add(l_msg_rec);
2865                 ELSIF p_qualifier_rec.qualify_hier_descendents_flag(I) in ('Y','y') THEN
2866                  BEGIN
2867                  select 'Y' into l_hierarchy_enabled
2868                  from dual
2869                  where exists(select 'X'
2870                  from qp_segments_b qs,qp_prc_contexts_b qpc
2871                  where
2872                  qs.prc_context_id = qpc.prc_context_id and
2873                  qpc.prc_context_code = p_qualifier_rec.qualifier_context(I) and
2874                  qs.segment_mapping_column = p_qualifier_rec.qualifier_attribute(I) and
2875                  qpc.PRC_CONTEXT_TYPE = 'QUALIFIER'
2876                  and qs.party_hierarchy_enabled_flag ='Y');
2877                   p_qualifier_rec.qualify_hier_descendents_flag(I) := 'Y';
2878                  EXCEPTION WHEN NO_DATA_FOUND THEN
2879                   p_qualifier_rec.process_status_flag(I):=NULL;
2880                   FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
2881                   FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFY HIER DESCENDENTS FLAG ');
2882                   qp_bulk_msg.add(l_msg_rec);
2883                  END;
2884                  ELSE
2885                     null;
2886                 END IF;
2887     END IF;
2888 
2889 -- Bug# 5214576 RAVI START
2890 -- Qualifier Start and End Date validation
2891 IF p_qualifier_rec.end_date_active(I) is not null THEN
2892    IF p_qualifier_rec.start_date_active(I) is not null THEN
2893       IF p_qualifier_rec.start_date_active(I) > p_qualifier_rec.end_date_active(I) THEN
2894          qp_bulk_loader_pub.write_log('End Date is before Start Date');
2895          p_qualifier_rec.process_status_flag(I):=NULL;
2896          FND_MESSAGE.SET_NAME('QP', 'QP_STRT_DATE_BFR_END_DATE');
2897 	 QP_BULK_MSG.Add(l_msg_rec);
2898       END IF;
2899    ELSE
2900       qp_bulk_loader_pub.write_log('Qualifier Start Date is null');
2901       p_qualifier_rec.process_status_flag(I):=NULL;
2902       FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_DATE');
2903       QP_BULK_MSG.Add(l_msg_rec);
2904    END IF;
2905 END IF;
2906 -- Bug# 5214576 RAVI END
2907 
2908 -- Qualifier Attr Value
2909 
2910 --Bug 4929426 START RAVI
2911 /**
2912 Qualifier attribute value validation (Messages)
2913 **/
2914 
2915 IF p_qualifier_rec.qualifier_context(I) = 'MODLIST'
2916 AND p_qualifier_rec.qualifier_attribute(I) = 'QUALIFIER_ATTRIBUTE4'
2917 THEN
2918    begin
2919       select 1 into l_exist from qp_list_headers_b
2920       where list_header_id = to_number(p_qualifier_rec.qualifier_attr_value(I));
2921    exception when others then
2922       p_qualifier_rec.process_status_flag(I):=NULL;
2923       FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
2924       FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER_ATTR_VALUE');
2925       QP_BULK_MSG.ADD(l_msg_rec);
2926    end;
2927 ELSE
2928 
2929    -- Bug 5152088 Checking if Qualifier Attribute Value Code is valid
2930    IF p_QUALIFIER_rec.qualifier_attr_value_code(I) IS NOT NULL THEN
2931       p_QUALIFIER_rec.qualifier_attr_value(I) := QP_Value_To_Id.qualifier_attr_value(
2932                                     p_QUALIFIER_rec.qualifier_attr_value_code(I),
2933                                     p_QUALIFIER_rec.qualifier_context(I),
2934                                     p_QUALIFIER_rec.qualifier_attribute(I)
2935                                    );
2936    END IF;
2937 
2938    QP_UTIL.validate_qp_flexfield(
2939       flexfield_name         =>'QP_ATTR_DEFNS_QUALIFIER'
2940       ,context               =>p_QUALIFIER_rec.qualifier_context(I)
2941    	  ,attribute             =>p_QUALIFIER_rec.qualifier_attribute(I)
2942    	  -- Bug 5152088 Checking if Qualifier Attribute Value Code is valid
2943 	  ,value                 =>p_QUALIFIER_rec.qualifier_attr_value(I)
2944       ,application_short_name=>'QP'
2945 	  ,context_flag          =>l_context_error
2946 	  ,attribute_flag        =>l_attribute_error
2947 	  ,value_flag            =>l_value_error
2948 	  ,datatype              =>l_datatype
2949 	  ,precedence            =>l_precedence
2950 	  ,error_code            =>l_error_code
2951    );
2952 
2953    IF l_error_code IS NULL THEN
2954       p_qualifier_rec.process_status_flag(I):=NULL;
2955       FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
2956       FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER ATTRIBUTE CODE');
2957       QP_BULK_MSG.ADD(l_msg_rec);
2958    ELSE
2959       IF l_error_code=1 THEN
2960          qp_bulk_loader_pub.write_log('Qualifier Flexfield_name is not passed.');
2961          p_qualifier_rec.process_status_flag(I):=NULL;
2962          FND_MESSAGE.SET_NAME('QP','QP_QLF_FLXFLD_NULL');
2963          --FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER ATTRIBUTE CODE');
2964          QP_BULK_MSG.ADD(l_msg_rec);
2965       ELSIF l_error_code=2 THEN
2966          qp_bulk_loader_pub.write_log('Qualifier Context is not passed');
2967          p_qualifier_rec.process_status_flag(I):=NULL;
2968          FND_MESSAGE.SET_NAME('QP','QP_QLF_CNTXT_NULL');
2969          --FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER ATTRIBUTE CODE');
2970          QP_BULK_MSG.ADD(l_msg_rec);
2971       ELSIF l_error_code=3 THEN
2972          qp_bulk_loader_pub.write_log('Qualifier Attribute is not passed.');
2973          p_qualifier_rec.process_status_flag(I):=NULL;
2974          FND_MESSAGE.SET_NAME('QP','QP_QLF_ATTR_NULL');
2975          --FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER ATTRIBUTE CODE');
2976          QP_BULK_MSG.ADD(l_msg_rec);
2977       ELSIF l_error_code=4 THEN
2978          qp_bulk_loader_pub.write_log('Qualifier Value is not passed');
2979          p_qualifier_rec.process_status_flag(I):=NULL;
2980          FND_MESSAGE.SET_NAME('QP','QP_QLF_ATTR_VAL_NULL');
2981          --FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER ATTRIBUTE CODE');
2982          QP_BULK_MSG.ADD(l_msg_rec);
2983       ELSIF l_error_code=5 THEN
2984          qp_bulk_loader_pub.write_log('Qualifier Application short name is not passed');
2985          p_qualifier_rec.process_status_flag(I):=NULL;
2986          FND_MESSAGE.SET_NAME('QP','QP_QLF_APP_NAME_NULL');
2987          --FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER ATTRIBUTE CODE');
2988          QP_BULK_MSG.ADD(l_msg_rec);
2989       ELSIF l_error_code=6 THEN
2990          qp_bulk_loader_pub.write_log('Qualifier Invalid application short name.');
2991          p_qualifier_rec.process_status_flag(I):=NULL;
2992          FND_MESSAGE.SET_NAME('QP','QP_QLF_INVALID_APP_NAME');
2993          --FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER ATTRIBUTE CODE');
2994          QP_BULK_MSG.ADD(l_msg_rec);
2995       ELSIF l_error_code=7 THEN
2996          qp_bulk_loader_pub.write_log('Qualifier Invalid context passed');
2997          p_qualifier_rec.process_status_flag(I):=NULL;
2998          FND_MESSAGE.SET_NAME('QP','QP_QLF_INVALID_CNTXT');
2999          --FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER ATTRIBUTE CODE');
3000          QP_BULK_MSG.ADD(l_msg_rec);
3001       ELSIF l_error_code=8 THEN
3002          qp_bulk_loader_pub.write_log('Qualifier Invalid Attribute passed');
3003          p_qualifier_rec.process_status_flag(I):=NULL;
3004          FND_MESSAGE.SET_NAME('QP','QP_QLF_INVALID_ATTRIB');
3005          --FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER ATTRIBUTE CODE');
3006          QP_BULK_MSG.ADD(l_msg_rec);
3007       ELSIF l_error_code=9 THEN
3008          qp_bulk_loader_pub.write_log('Qualifier Value does not exist');
3009          p_qualifier_rec.process_status_flag(I):=NULL;
3010          FND_MESSAGE.SET_NAME('QP','QP_QLF_INVALID_ATTR_VAL');
3011          --FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER ATTRIBUTE CODE');
3012          QP_BULK_MSG.ADD(l_msg_rec);
3013       ELSIF l_error_code=10 THEN
3014          qp_bulk_loader_pub.write_log('Qualifier Invalid Flexfield Name');
3015          p_qualifier_rec.process_status_flag(I):=NULL;
3016          FND_MESSAGE.SET_NAME('QP','QP_QLF_INVALID_FLXFLD_NAME');
3017          --FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER ATTRIBUTE CODE');
3018          QP_BULK_MSG.ADD(l_msg_rec);
3019       END IF;
3020    END IF;
3021 END IF;
3022 
3023 --Bug 4929426 END RAVI
3024 
3025 	qp_bulk_loader_pub.write_log( 'Qualifier_attr_val:'||p_qualifier_rec.qualifier_attr_value(I));
3026       -- Qualifier Attr Value To
3027        IF p_qualifier_rec.comparison_operator_code(I)= 'BETWEEN' AND
3028 	  p_qualifier_rec.qualifier_attr_value_to(I) IS NULL 	THEN
3029 
3030 	IF p_qualifier_rec.qualifier_attr_value_to_code(I) IS NULL THEN
3031 	p_qualifier_rec.process_status_flag(I):=NULL;
3032 	FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
3033         FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER ATTRIBUTE VALUE TO');
3034         QP_BULK_MSG.ADD(l_msg_rec);
3035 	ELSE
3036 
3037 	   BEGIN
3038 	      l_segment_name :=QP_PRICE_LIST_LINE_UTIL.Get_Segment_Name
3039 			('QP_ATTR_DEFNS_QUALIFIER',
3040 			 p_qualifier_rec.qualifier_context(I),
3041   			 p_qualifier_rec.qualifier_attribute(I));
3042 
3043 	      QP_Value_To_ID.Flex_Meaning_To_Value_Id(
3044  		    p_flexfield_name => 'QP_ATTR_DEFNS_QUALIFIER',
3045  		    p_context => p_qualifier_rec.qualifier_context(I),
3046                     p_segment => l_segment_name,
3047 	            p_meaning => p_qualifier_rec.qualifier_attr_value_to_code(I),
3048                     x_value => x_value,
3049              	    x_id => x_id,
3050  		    x_format_type => x_format_type);
3051 
3052 	      IF x_id IS NOT NULL THEN
3053 		 p_qualifier_rec.qualifier_attr_value_to(I) := x_id;
3054 	      ELSE
3055 		 p_qualifier_rec.qualifier_attr_value_to(I) := x_value;
3056 	      END IF;
3057 
3058 	      IF p_qualifier_rec.qualifier_attr_value_to(I) IS NULL THEN
3059 	       p_qualifier_rec.process_status_flag(I):=NULL;
3060                FND_MESSAGE.SET_NAME('QP','QP_VALUE_TO_ID_ERROR');
3061                FND_MESSAGE.SET_TOKEN('ATTRIBUTE','qualifier_attr_value_to');
3062 	       QP_BULK_MSG.add(l_msg_rec);
3063 	      END IF;
3064 
3065 	   EXCEPTION
3066 	      WHEN NO_DATA_FOUND THEN
3067                 p_qualifier_rec.process_status_flag(I):=NULL;
3068                FND_MESSAGE.SET_NAME('QP','QP_VALUE_TO_ID_ERROR');
3069                FND_MESSAGE.SET_TOKEN('ATTRIBUTE','qualifier_attr_value_to');
3070 	       QP_BULK_MSG.ADD(l_msg_rec);
3071 
3072 	   END;
3073 	END IF;
3074      END IF;
3075 
3076 
3077 
3078     /*------ Performing required field validation for ----------------
3079          orig_sys_qualifier_ref.
3080      -------------------------------------------------------------*/
3081      IF p_qualifier_rec.orig_sys_qualifier_ref(I) IS NULL THEN
3082         p_qualifier_rec.process_status_flag(I):=NULL;
3083       	FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
3084         FND_MESSAGE.SET_TOKEN('ATTRIBUTE','ORIG_SYS_QUALIFIER_REF');
3085         QP_BULK_MSG.ADD(l_msg_rec);
3086      END IF;
3087      l_exist:=null;
3088      -- Check for uniqueness of orig_sys_qualifier_ref
3089      BEGIN
3090 	Select  1 INTO l_exist
3091 	  from qp_qualifiers
3092 	 where orig_sys_qualifier_ref=p_qualifier_rec.orig_sys_qualifier_ref(I)
3093 	   and orig_sys_header_ref = p_qualifier_rec.orig_sys_header_ref(I);
3094      EXCEPTION
3095 	 WHEN NO_DATA_FOUND THEN
3096 	    l_exist := 0;
3097      END;
3098 
3099      IF p_qualifier_rec.interface_action_code(I) = 'INSERT' AND l_exist =  1 THEN
3100 	p_qualifier_rec.process_status_flag(I):=NULL;
3101 	FND_MESSAGE.SET_NAME('QP', 'ORIG_SYS_QUAL_REF_NOT_UNIQUE');
3102         FND_MESSAGE.SET_TOKEN('REF_NO', p_qualifier_rec.orig_sys_qualifier_ref(I));
3103 	QP_BULK_MSG.add(l_msg_rec);
3104      ELSIF p_qualifier_rec.interface_action_code(I) = 'UPDATE' AND l_exist = 0 THEN
3105 	p_qualifier_rec.process_status_flag(I):=NULL;
3106 	FND_MESSAGE.SET_NAME('QP', 'QUALIFIER_REC_DOES_NOT_EXIST');
3107         FND_MESSAGE.SET_TOKEN('REF_NO', p_qualifier_rec.orig_sys_qualifier_ref(I));
3108 	QP_BULK_MSG.add(l_msg_rec);
3109      END IF;
3110      If p_qualifier_rec.interface_action_code(I)='INSERT' THEN
3111      l_exist:=null;
3112     	Select count(*) INTO l_exist
3113 	  from qp_interface_qualifiers
3114 	 where request_id = p_qualifier_rec.request_id(I)
3115 	   and orig_sys_qualifier_ref=p_qualifier_rec.orig_sys_qualifier_ref(I)
3116 	   and p_qualifier_rec.process_status_flag(I) ='P' --is null
3117            and orig_sys_header_ref = p_qualifier_rec.orig_sys_header_ref(I);
3118 
3119       IF l_exist >1 THEN
3120 	p_qualifier_rec.process_status_flag(I):=NULL;
3121 	FND_MESSAGE.SET_NAME('QP', 'ORIG_SYS_QUAL_REF_NOT_UNIQUE');
3122         FND_MESSAGE.SET_TOKEN('REF_NO', p_qualifier_rec.orig_sys_qualifier_ref(I));
3123 	QP_BULK_MSG.add(l_msg_rec);
3124      END IF;
3125     end if;
3126 
3127      Begin
3128        select  list_header_id, active_flag
3129 	into    p_qualifier_rec.list_header_id(I), p_qualifier_rec.active_flag(i)
3130 	from    qp_list_headers_b
3131 	where   orig_system_header_ref = p_qualifier_rec.orig_sys_header_ref(I);
3132      Exception
3133 	When NO_DATA_FOUND then
3134 	   p_qualifier_rec.process_status_flag(I):=NULL;
3135 	   p_qualifier_rec.list_header_id(I) := -1;
3136 	   fnd_message.set_name('QP', 'QP_INVALID_HEADER_REF');
3137            FND_MESSAGE.SET_TOKEN('REF_NO',NULL);
3138 	   qp_bulk_msg.add(l_msg_rec);
3139      End;
3140 
3141  --SECONDARY PRICELIST CHECK
3142     qp_bulk_loader_pub.write_log( 'SECONDARY PRICELIST CHECK');
3143     IF p_qualifier_rec.qualifier_context(I) = 'MODLIST'
3144 	AND p_qualifier_rec.qualifier_attribute(I) = 'QUALIFIER_ATTRIBUTE4' THEN
3145 
3146 -- Bug 4926775 START RAVI
3147 /**
3148 The currency code for the primary and secondary price lists should be same. (Messages)
3149 **/
3150 	    BEGIN
3151 	    SELECT qplh.list_header_id
3152 	      INTO l_list_header_id
3153 	      FROM QP_interface_list_headers qpilh, qp_list_headers qplh
3154           WHERE qplh.list_header_id = to_number(p_qualifier_rec.qualifier_attr_value(I))
3155 	       AND qpilh.ORIG_SYS_HEADER_REF = p_qualifier_rec.ORIG_SYS_HEADER_REF(I)
3156            AND qplh.currency_code = qpilh.currency_code;
3157 	    EXCEPTION
3158 	       WHEN NO_DATA_FOUND THEN
3159 	          qp_bulk_loader_pub.write_log( 'Secondary Price List Currency not compatible with primary price list currency code');
3160 		  P_QUALIFIER_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
3161 		  FND_MESSAGE.SET_NAME('QP', 'QP_SEC_PRL_CCD_INVALID');
3162 		  --FND_MESSAGE.SET_TOKEN('PRICELIST_NAME', p_qualifier_rec.qualifier_attr_value(I));
3163 		  QP_BULK_MSG.ADD(l_msg_rec);
3164 	    END;
3165 -- Bug 4926775 END RAVI
3166 
3167 	IF p_qualifier_rec.qualifier_attr_value(I) IS NULL THEN
3168 	    qp_bulk_loader_pub.write_log( 'Secondary Price List read from qp_list_header');
3169 	    BEGIN
3170 	    SELECT to_char(list_header_id)
3171 	      INTO p_qualifier_rec.qualifier_attr_value(I)
3172 	      FROM QP_LIST_HEADERS_TL
3173 	     WHERE NAME = p_qualifier_rec.qualifier_attr_value_code(I)
3174 	       AND LANGUAGE = userenv('LANG');
3175 	    EXCEPTION
3176 	       WHEN NO_DATA_FOUND THEN
3177 		  P_QUALIFIER_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
3178 		  FND_MESSAGE.SET_NAME('QP', 'SEC_PRL_ERROR');
3179 		  FND_MESSAGE.SET_TOKEN('PRICELIST_NAME', p_qualifier_rec.qualifier_attr_value_code(I));
3180 		  QP_BULK_MSG.ADD(l_msg_rec);
3181 	    END;
3182 	END IF;
3183 	IF p_qualifier_rec.qualifier_attr_value(I) IS NOT NULL THEN
3184 	    qp_bulk_loader_pub.write_log( 'Secondary Price List duplicate check');
3185 	    l_exist:=0;
3186 	    begin
3187 	    select 1 into l_exist
3188 	    from qp_qualifiers
3189 	    where qualifier_context = 'MODLIST'
3190 	    and qualifier_attribute = 'QUALIFIER_ATTRIBUTE4'
3191 	    and qualifier_attr_value = to_number(p_qualifier_rec.qualifier_attr_value(I))
3192 	    -- Bug# 5276935 RAVI
3193 	    -- Chcek for duplication in the remaining qualifiers
3194             and orig_sys_qualifier_ref <> p_qualifier_rec.orig_sys_qualifier_ref(I)
3195 	    and list_header_id = p_qualifier_rec.list_header_id(I);
3196 	    exception
3197 		when others then
3198 			null;
3199 	    end;
3200 	    if l_exist = 0 then
3201 	    qp_bulk_loader_pub.write_log( 'Secondary Price List dupl. checkin int. table');
3202 		begin
3203 		select 1 into l_exist
3204 		from qp_interface_qualifiers
3205 		where request_id = p_qualifier_rec.request_id(I)
3206 		and orig_sys_header_ref = p_qualifier_rec.orig_sys_header_ref(I)
3207 		and orig_sys_qualifier_ref <> p_qualifier_rec.orig_sys_qualifier_ref(I)
3208 		and qualifier_context = 'MODLIST'
3209 		and qualifier_attribute = 'QUALIFIER_ATTRIBUTE4'
3210 	    	and qualifier_attr_value = p_qualifier_rec.qualifier_attr_value(I);
3211 		exception
3212 		    when others then
3213 			    null;
3214 		end;
3215 	    end if;
3216 	    if l_exist <> 0 then
3217 		  P_QUALIFIER_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
3218 		  FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
3219 		  FND_MESSAGE.SET_TOKEN('ATTRIBUTE',' Price List');
3220 		  QP_BULK_MSG.ADD(l_msg_rec);
3221 	    end if;
3222 	    qp_bulk_loader_pub.write_log( 'Secondary Price List security check');
3223 	      IF QP_security.check_function(p_function_name => QP_Security.G_FUNCTION_UPDATE,
3224 					 p_instance_type => QP_Security.G_PRICELIST_OBJECT,
3225 					 p_instance_pk1  => to_number(p_qualifier_rec.qualifier_attr_value(I))) <> 'T' THEN
3226 		p_qualifier_rec.process_status_flag(I):=NULL;
3227 		fnd_message.set_name('QP', 'QP_NO_PRIVILEGE');
3228 		fnd_message.set_token('PRICING_OBJECT', 'Price List');
3229 		qp_bulk_msg.add(l_msg_rec);
3230 	       END IF;
3231         END IF;
3232     END IF;
3233 
3234 -- Basic_Pricing_Condition
3235 -- Secondary PricelIst check while basic pricing
3236    IF QP_BULK_LOADER_PUB.GET_QP_STATUS<>'I' THEN
3237     IF p_qualifier_rec.qualifier_context(I) = 'MODLIST'
3238 	AND p_qualifier_rec.qualifier_attribute(I) = 'QUALIFIER_ATTRIBUTE4' THEN
3239      	   l_exist:=0;
3240 
3241 	   SELECT count(*)
3242 	   INTO	  l_exist
3243 	   FROM   QP_SECONDARY_PRICE_LISTS_V
3244 	   WHERE  parent_price_list_id = p_qualifier_rec.qualifier_attr_value(I);
3245 
3246     qp_bulk_loader_pub.write_log( 'l_exist='||l_exist);
3247 
3248 	   IF l_exist > 0 THEN
3249 	      P_QUALIFIER_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
3250 	      FND_MESSAGE.SET_NAME('QP','QP_1_SEC_PLST_FOR_BASIC');
3251 	      --Only one secondary pricelist allowed in Basic Pricing
3252 	      QP_BULK_MSG.ADD(l_msg_rec);
3253 	   END IF;
3254 	   l_exist:=0;
3255 	   SELECT count(*)
3256 	   INTO	l_exist
3257 	   FROM	QP_INTERFACE_QUALIFIERS
3258 	   WHERE QUALIFIER_CONTEXT = 'MODLIST'
3259 	   AND	QUALIFIER_ATTRIBUTE = 'QUALIFIER_ATTRIBUTE4'
3260 	   AND  request_id = p_qualifier_rec.request_id(I)
3261 	   AND	(QUALIFIER_ATTR_VALUE = p_qualifier_rec.qualifier_attr_value(I)
3262 	    OR	QUALIFIER_ATTR_VALUE_CODE = p_qualifier_rec.qualifier_attr_value_code(I));
3263 	   IF l_exist > 1 THEN
3264 	      P_QUALIFIER_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
3265 	      FND_MESSAGE.SET_NAME('QP','QP_1_SEC_PLST_FOR_BASIC');
3266 	      --Only one secondary pricelist allowed in Basic Pricing
3267 	      QP_BULK_MSG.ADD(l_msg_rec);
3268 	   END IF;
3269     END IF;
3270    END IF;
3271  --check for the qualifier level
3272   IF p_qualifier_rec.process_status_flag(I) ='P' THEN --IS NOT NULL THEN
3273     BEGIN
3274        SELECT  f.segment_level
3275 	 INTO  l_seg_level
3276 	 FROM  qp_prc_contexts_b d,
3277 	       qp_segments_b e,  qp_pte_segments f
3278 	WHERE  d.prc_context_code =p_qualifier_rec.qualifier_context(I)
3279 	  AND  e.segment_mapping_column = p_qualifier_rec.qualifier_attribute(I)
3280 	  AND  d.prc_context_id = e.prc_context_id
3281 	  AND  e.segment_id = f.segment_id
3282 	  AND  f.pte_code = 'ORDFUL';
3283 
3284      IF l_seg_level = 'ORDER' THEN
3285 	  P_QUALIFIER_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
3286           FND_MESSAGE.SET_NAME('QP', 'QP_ORDER_LEVEL_QUAL_NOT_ALLOWED');
3287 	  QP_BULK_MSG.ADD(l_msg_rec);
3288      END IF;
3289 
3290      EXCEPTION
3291 	 WHEN NO_DATA_FOUND THEN
3292 	    NULL;
3293      END;
3294 
3295   END IF;
3296 
3297   IF p_qualifier_rec.qualifier_precedence(I) IS NULL or
3298      p_qualifier_rec.qualifier_precedence(I) = 0 THEN
3299     QP_UTIL.validate_qp_flexfield(flexfield_name =>'QP_ATTR_DEFNS_QUALIFIER'
3300                ,context        =>p_qualifier_rec.qualifier_context(I)
3301                ,attribute      =>p_qualifier_rec.qualifier_attribute(I)
3302 	       ,value          =>p_qualifier_rec.qualifier_attr_value(I)
3303                 ,application_short_name         => 'QP'
3304                          ,context_flag           =>l_context_error
3305                          ,attribute_flag         =>l_attribute_error
3306                          ,value_flag             =>l_value_error
3307                          ,datatype               =>l_datatype
3308                          ,precedence              =>l_precedence
3309                          ,error_code             =>l_error_code
3310                          );
3311 
3312     If l_error_code = 0 Then
3313           p_qualifier_rec.qualifier_precedence(I) := l_precedence;
3314     end if;
3315   END IF;
3316 
3317 --warning messages
3318   IF P_QUALIFIER_REC.PROCESS_STATUS_FLAG(I)='P' THEN --,'*')<> 'E' THEN
3319    qp_bulk_loader_pub.write_log('Entering Qualifier warnings');
3320 
3321     IF p_Qualifier_rec.qualifier_context(I) IS NOT NULL AND
3322        p_Qualifier_rec.qualifier_attribute(I) IS NOT NULL
3323     THEN
3324       qp_bulk_loader_pub.write_log('Context and Attribute OK ');
3325       QP_UTIL.Get_Context_Type('QP_ATTR_DEFNS_QUALIFIER',
3326                                p_Qualifier_rec.qualifier_context(I),
3327                                l_context_type,
3328                                l_error_code);
3329 
3330       IF l_error_code = 0 THEN --successfully returned context_type
3331 
3332         QP_UTIL.Get_Sourcing_Info(l_context_type,
3333                                   p_Qualifier_rec.qualifier_context(I),
3334                                   p_Qualifier_rec.qualifier_attribute(I),
3335                                   l_sourcing_enabled,
3336                                   l_sourcing_status,
3337                                   l_sourcing_method);
3338 
3339    	qp_bulk_loader_pub.write_log('Sourcing method / status / enabled'||l_sourcing_method||l_sourcing_status||l_sourcing_enabled);
3340 
3341         IF l_sourcing_method = 'ATTRIBUTE MAPPING' THEN
3342 
3343           IF l_sourcing_enabled <> 'Y' THEN
3344 
3345             FND_MESSAGE.SET_NAME('QP','QP_ENABLE_SOURCING');
3346             FND_MESSAGE.SET_TOKEN('CONTEXT',
3347                                   p_Qualifier_rec.qualifier_context(I));
3348             FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
3349                                   p_Qualifier_rec.qualifier_attribute(I));
3350 	    QP_BULK_MSG.ADD(l_msg_rec);
3351 
3352           END IF;
3353 
3354           IF l_sourcing_status <> 'Y' THEN
3355 
3356             IF NOT (
3357                p_qualifier_rec.qualifier_context(I)= 'MODLIST' AND
3358                p_qualifier_rec.qualifier_attribute(I) = 'QUALIFIER_ATTRIBUTE10')
3359             THEN
3360               FND_MESSAGE.SET_NAME('QP','QP_BUILD_SOURCING_RULES');
3361               FND_MESSAGE.SET_TOKEN('CONTEXT',
3362                                     p_Qualifier_rec.qualifier_context(I));
3363               FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
3364                                     p_Qualifier_rec.qualifier_attribute(I));
3365 	      QP_BULK_MSG.ADD(l_msg_rec);
3366             END IF;
3367 
3368           END IF;
3369 
3370         END IF; --If sourcing_method = 'ATTRIBUTE MAPPING'
3371 
3372       END IF; --l_error_code = 0
3373 
3374     END IF;--If qualifier_context and qualifier_attribute are NOT NULL
3375 
3376   END IF;
3377 END LOOP;
3378 
3379  qp_bulk_loader_pub.write_log('Leaving Entity qualifier validation');
3380 
3381  EXCEPTION
3382     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3383        qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE ENTITY_QUALIFIER:'||sqlerrm);
3384        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3385     WHEN OTHERS THEN
3386        qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE ENTITY_QUALIFIER:'||sqlerrm);
3387        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3388 
3389 
3390 END ENTITY_QUALIFIER;
3391 
3392 PROCEDURE ENTITY_PRICING_ATTR
3393           (p_pricing_attr_rec IN OUT  NOCOPY QP_BULK_LOADER_PUB.pricing_attr_rec_type)
3394 IS
3395    l_msg_rec QP_BULK_MSG.Msg_Rec_Type;
3396    l_exist NUMBER;
3397    l_exist1 NUMBER;
3398    l_comparison_operator_code VARCHAR2(30);
3399    l_error_code NUMBER;
3400    l_precedence NUMBER;
3401    l_datatype FND_FLEX_VALUE_SETS.Format_type%TYPE;
3402    l_value_error                 VARCHAR2(1);
3403    l_context_error               VARCHAR2(1);
3404    l_attribute_error             VARCHAR2(1);
3405    l_primary_uom_flag            VARCHAR2(1);
3406    l_count                       NUMBER;
3407    l_count1                      NUMBER;
3408    l_msg_txt                     VARCHAR2(2000);
3409    l_status                      VARCHAR2(20);
3410    l_status1                     VARCHAR2(20);
3411    l_pricing_attribute_id        NUMBER;
3412    l_old_pricing_attr_rec        QP_Price_List_PUB.Pricing_Attr_Rec_Type;
3413    l_availability_in_basic	VARCHAR2(1);
3414    l_pricing_attr_flex_enabled VARCHAR2(1);
3415    l_pte_code VARCHAR2(30);
3416 
3417 l_context_type                VARCHAR2(30);
3418 l_sourcing_enabled            VARCHAR2(1);
3419 l_sourcing_status             VARCHAR2(1);
3420 l_sourcing_method             VARCHAR2(30);
3421 
3422 l_ss_code                     VARCHAR2(30);
3423 l_fna_name                    VARCHAR2(4000);
3424 l_fna_desc                    VARCHAR2(489);
3425 l_fna_valid                   BOOLEAN;
3426 
3427 --ENH Continuous Price Break START RAVI
3428 l_old_break_pa_count NUMBER := -1;
3429 l_new_break_pa_count NUMBER := -1;
3430 l_new_break_low_value NUMBER := -1;
3431 l_new_break_high_value NUMBER := -1;
3432 l_old_break_low_value NUMBER := -1;
3433 l_old_break_high_value NUMBER := -1;
3434 l_break_high_value NUMBER := -1;
3435 l_to_value_old NUMBER := -1;
3436 l_to_value_new NUMBER := -1;
3437 l_from_value_old NUMBER := -1;
3438 l_from_value_new NUMBER := -1;
3439 --ENH Continuous Price Break END RAVI
3440 
3441 -- Bug# 5246745 RAVI
3442 l_pa_count NUMBER := 0;
3443 
3444 
3445 -- Bug# 5440851 RAVI
3446 l_pa_from_val_tmp NUMBER := 0;
3447 l_pa_to_val_tmp   NUMBER := 0;
3448 
3449 -- Bug# 5528754
3450 -- Local variable to store price break or price list line
3451 l_pa_price_break VARCHAR2(30):='PRICE LIST LINE';
3452 
3453 Cursor C_break_lines(p_orig_sys_line_ref VARCHAR2,
3454                      -- Bug 5246745 Use Composite Index for Ref columns
3455                      p_orig_sys_header_ref VARCHAR2) IS
3456 --ENH Continuous Price Break RAVI
3457 /**
3458 Check for overlap of price breaks
3459 **/
3460        SELECT  'OVERLAP'
3461           FROM   qp_list_lines la,
3462 		 qp_rltd_modifiers ra,
3463                  qp_rltd_modifiers rb,
3464                  qp_interface_pricing_attribs pa,
3465                  qp_pricing_attributes pb
3466        WHERE  la.orig_sys_line_ref = p_orig_sys_line_ref
3467        -- Bug 5246745 Use Composite Index for Ref columns
3468        AND    la.orig_sys_header_ref = p_orig_sys_header_ref
3469        AND    ra.to_rltd_modifier_id = la.list_line_id
3470        AND    ra.rltd_modifier_grp_type = 'PRICE BREAK'
3471        -- Got Price Break Line
3472        AND    ra.from_rltd_modifier_id = rb.from_rltd_modifier_id
3473        AND    ra.to_rltd_modifier_id <> rb.to_rltd_modifier_id
3474        -- Got Remaining Price Break Lines
3475        AND    pa.orig_sys_line_ref = la.orig_sys_line_ref
3476        -- Got Price Break Line New Values
3477        AND    rb.to_rltd_modifier_id = pb.list_line_id
3478        -- Got Remaining Price Break Lines Values
3479        -- Bug# 5236432 RAVI
3480        AND pb.orig_sys_pricing_attr_ref NOT IN (
3481                 select pia.orig_sys_pricing_attr_ref
3482                 from qp_interface_pricing_attribs pia
3483                 where pia.orig_sys_header_ref=pb.orig_sys_header_ref
3484                 and pia.orig_sys_line_ref=pb.orig_sys_line_ref
3485            )
3486        -- Got the remaining Price Break Lines that are not being updated in this request
3487        AND (
3488              ( qp_number.canonical_to_number(pa.pricing_attr_value_from) >=
3489                  qp_number.canonical_to_number(pa.pricing_attr_value_to)
3490              ) -- New Price Break To is greater than (or equal to) New Price Break From
3491              OR
3492              ( qp_number.canonical_to_number(pa.pricing_attr_value_from) <
3493                  qp_number.canonical_to_number(pb.pricing_attr_value_to)
3494                AND qp_number.canonical_to_number(pa.pricing_attr_value_from) >=
3495                    qp_number.canonical_to_number(pb.pricing_attr_value_from)
3496              ) -- New Price Break From in between Old Price Break
3497              OR
3498              ( qp_number.canonical_to_number(pa.pricing_attr_value_to) <=
3499                  qp_number.canonical_to_number(pb.pricing_attr_value_to)
3500                AND qp_number.canonical_to_number(pa.pricing_attr_value_to) >
3501                   qp_number.canonical_to_number(pb.pricing_attr_value_from)
3502              ) -- New Price Break To in between Old Price Break
3503              OR
3504              ( qp_number.canonical_to_number(pa.pricing_attr_value_from) <
3505                  qp_number.canonical_to_number(pb.pricing_attr_value_from)
3506                AND qp_number.canonical_to_number(pa.pricing_attr_value_to) >
3507                   qp_number.canonical_to_number(pb.pricing_attr_value_to)
3508              ) -- Old Price Break in between New Price Break
3509            );
3510 
3511 Cursor C_old_cont_grp_break_line(p_orig_sys_line_ref VARCHAR2,
3512                      -- Bug 5246745 Use Composite Index for Ref columns
3513                      p_orig_sys_header_ref VARCHAR2) IS
3514 --ENH Continuous Price Break RAVI
3515 /**
3516 Count of old price breaks
3517 **/
3518        SELECT  count(*) old_break_pa_count,
3519                min(to_number(pb.pricing_attr_value_from)) new_break_low_value,
3520                max(to_number(pb.pricing_attr_value_to)) new_break_high_value
3521           FROM   qp_list_lines la,
3522 		 qp_rltd_modifiers ra,
3523                  qp_rltd_modifiers rb,
3524                  qp_interface_pricing_attribs pa,
3525                  qp_pricing_attributes pb
3526        WHERE  la.orig_sys_line_ref = p_orig_sys_line_ref
3527        -- Bug 5246745 Use Composite Index for Ref columns
3528        AND    la.orig_sys_header_ref = p_orig_sys_header_ref
3529        AND    ra.to_rltd_modifier_id = la.list_line_id
3530        AND    ra.rltd_modifier_grp_type = 'PRICE BREAK'
3531        -- Got Price Break Line
3532        AND    ra.from_rltd_modifier_id = rb.from_rltd_modifier_id
3533        AND    ra.to_rltd_modifier_id <> rb.to_rltd_modifier_id
3534        -- Got Remaining Price Break Lines
3535        AND    pa.orig_sys_line_ref = la.orig_sys_line_ref
3536        -- Got Price Break Line New Values
3537        AND    rb.to_rltd_modifier_id = pb.list_line_id;
3538        -- Got Remaining Price Break Lines Values
3539 
3540 --ENH Continuous Price Break RAVI
3541 /**
3542 Count of new price breaks
3543 **/
3544 Cursor C_new_cont_grp_break_lines(p_orig_sys_line_ref VARCHAR2,
3545                      -- Bug 5246745 Use Composite Index for Ref columns
3546                      p_orig_sys_header_ref VARCHAR2) IS
3547        SELECT  count(*) new_break_pa_count,
3548                min(to_number(pb.pricing_attr_value_from)) new_break_low_value,
3549                max(to_number(pb.pricing_attr_value_to)) new_break_high_value
3550           FROM   qp_list_lines la,
3551 	         qp_list_lines lb,
3552 		 qp_rltd_modifiers ra,
3553                  qp_rltd_modifiers rb,
3554                  qp_interface_pricing_attribs pa,
3555                  qp_interface_pricing_attribs pb
3556        WHERE  la.orig_sys_line_ref = p_orig_sys_line_ref
3557        -- Bug 5246745 Use Composite Index for Ref columns
3558        AND    la.orig_sys_header_ref = p_orig_sys_header_ref
3559        AND    ra.to_rltd_modifier_id = la.list_line_id
3560        AND    ra.from_rltd_modifier_id = rb.from_rltd_modifier_id
3561        AND    pa.orig_sys_line_ref = la.orig_sys_line_ref
3562        AND    rb.to_rltd_modifier_id = lb.list_line_id
3563        AND    pb.orig_sys_line_ref = lb.orig_sys_line_ref
3564        AND    ra.rltd_modifier_grp_type = 'PRICE BREAK'
3565        AND    ra.to_rltd_modifier_id <> rb.to_rltd_modifier_id;
3566 
3567 --ENH Continuous Price Break RAVI
3568 /**
3569 Count of Old Price Breaks with Same From value
3570 **/
3571 Cursor C_from_value_old(p_orig_sys_line_ref VARCHAR2,
3572                      -- Bug 5246745 Use Composite Index for Ref columns
3573                      p_orig_sys_header_ref VARCHAR2) IS
3574        SELECT  count(*) l_from_value_old
3575           FROM   qp_list_lines la,
3576 		 qp_rltd_modifiers ra,
3577                  qp_rltd_modifiers rb,
3578                  qp_interface_pricing_attribs pa,
3579                  qp_pricing_attributes pb
3580        WHERE  la.orig_sys_line_ref = p_orig_sys_line_ref
3581        -- Bug 5246745 Use Composite Index for Ref columns
3582        AND    la.orig_sys_header_ref = p_orig_sys_header_ref
3583        AND    ra.to_rltd_modifier_id = la.list_line_id
3584        AND    ra.rltd_modifier_grp_type = 'PRICE BREAK'
3585        -- Got Price Break Line
3586        AND    ra.from_rltd_modifier_id = rb.from_rltd_modifier_id
3587        AND    ra.to_rltd_modifier_id <> rb.to_rltd_modifier_id
3588        -- Got Remaining Price Break Lines
3589        AND    pa.orig_sys_line_ref = la.orig_sys_line_ref
3590        -- Got Price Break Line New Values
3591        AND    rb.to_rltd_modifier_id = pb.list_line_id
3592        -- Got Remaining Price Break Lines Values
3593        AND    pa.pricing_attr_value_from=pb.pricing_attr_value_to;
3594 
3595 --ENH Continuous Price Break RAVI
3596 /**
3597 Count of new Price Breaks with Same From value
3598 **/
3599 Cursor C_from_value_new(p_orig_sys_line_ref VARCHAR2,
3600                      -- Bug 5246745 Use Composite Index for Ref columns
3601                      p_orig_sys_header_ref VARCHAR2) IS
3602        SELECT  count(*) l_from_value_new
3603           FROM   qp_list_lines la,
3604 	         qp_list_lines lb,
3605 		 qp_rltd_modifiers ra,
3606                  qp_rltd_modifiers rb,
3607                  qp_interface_pricing_attribs pa,
3608                  qp_interface_pricing_attribs pb
3609        WHERE  la.orig_sys_line_ref = p_orig_sys_line_ref
3610        -- Bug 5246745 Use Composite Index for Ref columns
3611        AND    la.orig_sys_header_ref = p_orig_sys_header_ref
3612        AND    ra.to_rltd_modifier_id = la.list_line_id
3613        AND    ra.from_rltd_modifier_id = rb.from_rltd_modifier_id
3614        AND    pa.orig_sys_line_ref = la.orig_sys_line_ref
3615        AND    rb.to_rltd_modifier_id = lb.list_line_id
3616        AND    pb.orig_sys_line_ref = lb.orig_sys_line_ref
3617        AND    ra.rltd_modifier_grp_type = 'PRICE BREAK'
3618        AND    ra.to_rltd_modifier_id <> rb.to_rltd_modifier_id
3619        AND    pa.pricing_attr_value_from=pb.pricing_attr_value_to;
3620 
3621 --ENH Continuous Price Break RAVI
3622 /**
3623 Count of Old Price Breaks with Same to value
3624 **/
3625 Cursor C_to_value_old(p_orig_sys_line_ref VARCHAR2,
3626                      -- Bug 5246745 Use Composite Index for Ref columns
3627                      p_orig_sys_header_ref VARCHAR2) IS
3628        SELECT  count(*) l_to_value_old
3629           FROM   qp_list_lines la,
3630 		 qp_rltd_modifiers ra,
3631                  qp_rltd_modifiers rb,
3632                  qp_interface_pricing_attribs pa,
3633                  qp_pricing_attributes pb
3634        WHERE  la.orig_sys_line_ref = p_orig_sys_line_ref
3635        -- Bug 5246745 Use Composite Index for Ref columns
3636        AND    la.orig_sys_header_ref = p_orig_sys_header_ref
3637        AND    ra.to_rltd_modifier_id = la.list_line_id
3638        AND    ra.rltd_modifier_grp_type = 'PRICE BREAK'
3639        -- Got Price Break Line
3640        AND    ra.from_rltd_modifier_id = rb.from_rltd_modifier_id
3641        AND    ra.to_rltd_modifier_id <> rb.to_rltd_modifier_id
3642        -- Got Remaining Price Break Lines
3643        AND    pa.orig_sys_line_ref = la.orig_sys_line_ref
3644        -- Got Price Break Line New Values
3645        AND    rb.to_rltd_modifier_id = pb.list_line_id
3646        -- Got Remaining Price Break Lines Values
3647        AND    pa.pricing_attr_value_to=pb.pricing_attr_value_from;
3648 
3649 --ENH Continuous Price Break RAVI
3650 /**
3651 Count of new Price Breaks with Same to value
3652 **/
3653 Cursor C_to_value_new(p_orig_sys_line_ref VARCHAR2,
3654                      -- Bug 5246745 Use Composite Index for Ref columns
3655                      p_orig_sys_header_ref VARCHAR2) IS
3656        SELECT  count(*) l_to_value_new
3657           FROM   qp_list_lines la,
3658 	         qp_list_lines lb,
3659 		 qp_rltd_modifiers ra,
3660                  qp_rltd_modifiers rb,
3661                  qp_interface_pricing_attribs pa,
3662                  qp_interface_pricing_attribs pb
3663        WHERE  la.orig_sys_line_ref = p_orig_sys_line_ref
3664        -- Bug 5246745 Use Composite Index for Ref columns
3665        AND    la.orig_sys_header_ref = p_orig_sys_header_ref
3666        AND    ra.to_rltd_modifier_id = la.list_line_id
3667        AND    ra.from_rltd_modifier_id = rb.from_rltd_modifier_id
3668        AND    pa.orig_sys_line_ref = la.orig_sys_line_ref
3669        AND    rb.to_rltd_modifier_id = lb.list_line_id
3670        AND    pb.orig_sys_line_ref = lb.orig_sys_line_ref
3671        AND    ra.rltd_modifier_grp_type = 'PRICE BREAK'
3672        AND    ra.to_rltd_modifier_id <> rb.to_rltd_modifier_id
3673        AND    pa.pricing_attr_value_to=pb.pricing_attr_value_from;
3674 
3675 Cursor C_Int_break_lines(p_orig_sys_line_ref VARCHAR2,
3676                      -- Bug 5246745 Use Composite Index for Ref columns
3677                      p_orig_sys_header_ref VARCHAR2,
3678                      p_request_id number) IS   -- changes done by rassharm for bug no 6028305
3679        SELECT  /*+ leading(la) index(pa QP_INTERFACE_PRCNG_ATTRIBS_N4) index(pb QP_INTERFACE_PRCNG_ATTRIBS_N4) */ --7433219
3680        'OVERLAP'
3681           FROM   qp_list_lines la,
3682 	         qp_list_lines lb,
3683 		 qp_rltd_modifiers ra,
3684                  qp_rltd_modifiers rb,
3685                  qp_interface_pricing_attribs pa,
3686                  qp_interface_pricing_attribs pb
3687        WHERE  la.orig_sys_line_ref = p_orig_sys_line_ref
3688        -- Bug 5246745 Use Composite Index for Ref columns
3689        AND    la.orig_sys_header_ref = p_orig_sys_header_ref
3690        AND    ra.to_rltd_modifier_id = la.list_line_id
3691        AND    ra.from_rltd_modifier_id = rb.from_rltd_modifier_id
3692        AND    pa.orig_sys_line_ref = la.orig_sys_line_ref
3693        AND    rb.to_rltd_modifier_id = lb.list_line_id
3694        AND    pb.orig_sys_line_ref = lb.orig_sys_line_ref
3695        AND    ra.rltd_modifier_grp_type = 'PRICE BREAK'
3696        AND    ra.to_rltd_modifier_id <> rb.to_rltd_modifier_id
3697 	AND    nvl(pa.pricing_attribute_datatype,'N') = 'N'
3698        -- changes done by rassharm for bug no 6028305
3699        AND pa.request_id=p_request_id
3700        AND pb.request_id=p_request_id
3701        -- end changes
3702 
3703        AND    (qp_number.canonical_to_number(pa.pricing_attr_value_from) < -- 4713369
3704                   qp_number.canonical_to_number(pb.pricing_attr_value_to)      AND
3705                      qp_number.canonical_to_number(pa.pricing_attr_value_from) >=
3706                      qp_number.canonical_to_number(pb.pricing_attr_value_from)
3707                      OR
3708                         qp_number.canonical_to_number(pa.pricing_attr_value_to) <=
3709                   qp_number.canonical_to_number(pb.pricing_attr_value_to)      AND
3710                      qp_number.canonical_to_number(pa.pricing_attr_value_to) >
3711                      qp_number.canonical_to_number(pb.pricing_attr_value_from)
3712                      OR
3713                         qp_number.canonical_to_number(pa.pricing_attr_value_from) <=
3714                   qp_number.canonical_to_number(pb.pricing_attr_value_from)    AND
3715                      qp_number.canonical_to_number(pa.pricing_attr_value_to) >=
3716                      qp_number.canonical_to_number(pb.pricing_attr_value_to));
3717 
3718 BEGIN
3719 qp_bulk_loader_pub.write_log('Entering Entity pricing attribute validation');
3720 FND_PROFILE.GET('QP_PRICING_TRANSACTION_ENTITY',l_pte_code);
3721 
3722 FOR I IN 1..p_pricing_attr_rec.orig_sys_pricing_attr_ref.COUNT
3723 LOOP
3724 
3725 --Initially setting the message context.
3726 
3727 l_msg_rec.REQUEST_ID := P_PRICING_ATTR_REC.REQUEST_ID(I);
3728 l_msg_rec.ENTITY_TYPE := 'PRL';
3729 l_msg_rec.TABLE_NAME := 'QP_INTERFACE_PRICING_ATTRIBS';
3730 l_msg_rec.ORIG_SYS_HEADER_REF := p_pricing_attr_rec.orig_sys_header_ref(I);
3731 l_msg_rec.ORIG_SYS_LINE_REF := p_pricing_attr_rec.orig_sys_line_ref(I);
3732 l_msg_rec.ORIG_SYS_QUALIFIER_REF := NULL;
3733 l_msg_rec.ORIG_SYS_PRICING_ATTR_REF := p_pricing_attr_rec.orig_sys_pricing_attr_ref(I);
3734 
3735  qp_bulk_loader_pub.write_log('Inside entity pricing attr');
3736 -- Internal field population
3737 --List Line ID
3738  BEGIN
3739  select list_line_id
3740    into p_pricing_attr_rec.list_line_id(I)
3741    from qp_list_lines
3742   where orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
3743     and orig_sys_header_ref  = p_pricing_attr_rec.orig_sys_header_ref(I);
3744 
3745  EXCEPTION
3746      WHEN NO_DATA_FOUND THEN
3747 	p_pricing_attr_rec.list_line_id(I) := -1;
3748         p_pricing_attr_rec.process_status_flag(I):=NULL;
3749 	fnd_message.set_name('QP', 'QP_INVALID_LINE_REF');
3750         FND_MESSAGE.SET_TOKEN('REF_NO', p_pricing_attr_rec.orig_sys_line_ref(I));
3751         qp_bulk_msg.add(l_msg_rec);
3752  END;
3753  qp_bulk_loader_pub.write_log('After entity list_line_id pricing attribute');
3754 
3755 
3756  -- Bug# 5246745 RAVI START
3757  --2 If org is Purchasing or PO then the item must be Purchasable or Orderable.
3758  IF p_pricing_attr_rec.product_attribute_context(I)='ITEM' AND
3759     p_pricing_attr_rec.product_attribute(I)= 'PRICING_ATTRIBUTE1'
3760  THEN
3761     l_pa_count :=0;
3762     IF fnd_global.resp_appl_id=178 OR fnd_global.resp_appl_id=201
3763     THEN --Check if item is purchasing enabled
3764        Begin
3765           select count(*) into l_pa_count
3766           from qp_interface_pricing_attribs qipa, mtl_system_items msi
3767           where qipa.orig_sys_pricing_attr_ref = p_pricing_attr_rec.orig_sys_pricing_attr_ref(I)
3768           and qipa.request_id = P_PRICING_ATTR_REC.REQUEST_ID(I)
3769           and qipa.product_attribute_context = 'ITEM'
3770           and qipa.product_attribute = 'PRICING_ATTRIBUTE1'
3771           and msi.inventory_item_id = to_number(qipa.PRODUCT_ATTR_VALUE)
3772           and msi.organization_id = fnd_profile.value('QP_ORGANIZATION_ID')
3773           and msi.purchasing_enabled_flag = 'Y'
3774           and qipa.interface_action_code in ('INSERT','UPDATE');
3775        Exception
3776           when NO_DATA_FOUND then
3777              l_pa_count := 0;
3778        End;
3779     ELSE --Check if item is orderable
3780        Begin
3781           select count(*) into l_pa_count
3782           from qp_interface_pricing_attribs qipa, mtl_system_items msi
3783           where qipa.orig_sys_pricing_attr_ref = p_pricing_attr_rec.orig_sys_pricing_attr_ref(I)
3784           and qipa.request_id = P_PRICING_ATTR_REC.REQUEST_ID(I)
3785           and qipa.product_attribute_context = 'ITEM'
3786           and qipa.product_attribute = 'PRICING_ATTRIBUTE1'
3787           and msi.inventory_item_id = to_number(qipa.PRODUCT_ATTR_VALUE)
3788           and msi.organization_id = fnd_profile.value('QP_ORGANIZATION_ID')
3789           and msi.CUSTOMER_ORDER_flag = 'Y'
3790           and qipa.interface_action_code in ('INSERT','UPDATE');
3791        Exception
3792           when NO_DATA_FOUND then
3793              l_pa_count := 0;
3794        End;
3795     END IF;
3796     if l_pa_count=0 then
3797        p_pricing_attr_rec.process_status_flag(I):=NULL;
3798        FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_ATTRIBUTE');
3799        fnd_message.set_token('ATTRIBUTE', 'PRODUCT_ATTRIBUTE_VALUE');
3800        qp_bulk_msg.add(l_msg_rec);
3801     end if;
3802  END IF;
3803  -- Bug# 5246745 RAVI END
3804 
3805   --list_header_id
3806 
3807  BEGIN
3808  select list_header_id
3809    into p_pricing_attr_rec.list_header_id(I)
3810    from qp_list_headers_b
3811   where orig_system_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I);
3812  EXCEPTION
3813      WHEN NO_DATA_FOUND THEN
3814 	p_pricing_attr_rec.list_header_id(I) := -1;
3815         p_pricing_attr_rec.process_status_flag(I):=NULL;
3816 	fnd_message.set_name('QP', 'QP_INVALID_HEADER_REF');
3817         FND_MESSAGE.SET_TOKEN('REF_NO', p_pricing_attr_rec.orig_sys_header_ref(I));
3818         FND_MESSAGE.SET_TOKEN('LS_CODE', NULL);
3819         qp_bulk_msg.add(l_msg_rec);
3820  END;
3821 
3822   -- Excluder Flag
3823  p_pricing_attr_rec.excluder_flag(I):='N';
3824  p_pricing_attr_rec.accumulate_flag(I):='N';
3825 
3826  -- Attribute Grouping No
3827 
3828  IF p_pricing_attr_rec.interface_action_code(I) = 'INSERT' THEN
3829      Select qp_pricing_attr_group_no_s.nextval
3830        into p_pricing_attr_rec.attribute_grouping_no(I)
3831        from dual;
3832  END IF;
3833 
3834  p_pricing_attr_rec.pricing_phase_id(I):=1;
3835 
3836  -- Check for the uniqueness of orig_sys_pricing_attr_ref
3837  l_exist:=null;
3838  BEGIN
3839       SELECT 1,pricing_attribute_id INTO l_exist,l_pricing_attribute_id
3840 	FROM qp_pricing_attributes
3841        WHERE orig_sys_pricing_attr_ref = p_pricing_attr_rec.orig_sys_pricing_attr_ref(I)
3842          AND orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
3843          AND orig_sys_header_ref =  p_pricing_attr_rec.orig_sys_header_ref(I);
3844  EXCEPTION
3845  WHEN NO_DATA_FOUND THEN
3846     l_exist:=0;
3847  END;
3848 
3849  IF p_pricing_attr_rec.interface_action_code(I) = 'INSERT' AND l_exist = 1 THEN
3850         p_pricing_attr_rec.process_status_flag(I):=NULL;
3851 	fnd_message.set_name('QP', 'ORIG_SYS_PRC_ATTR_REF_NOT_UNIQ');
3852         FND_MESSAGE.SET_TOKEN('REF_NO', p_pricing_attr_rec.orig_sys_pricing_attr_ref(I));
3853         qp_bulk_msg.add(l_msg_rec);
3854  ELSIF p_pricing_attr_rec.interface_action_code(I) = 'UPDATE' AND l_exist = 0 THEN
3855         p_pricing_attr_rec.process_status_flag(I):=NULL;
3856 	fnd_message.set_name('QP', 'PRC_ATTR_REC_DOES_NOT_EXIST');
3857         FND_MESSAGE.SET_TOKEN('REF_NO', p_pricing_attr_rec.orig_sys_pricing_attr_ref(I));
3858         qp_bulk_msg.add(l_msg_rec);
3859  END IF;
3860 
3861  IF p_pricing_attr_rec.interface_action_code(I) = 'INSERT' THEN
3862   l_exist:=null;
3863   BEGIN
3864       SELECT count(*) INTO l_exist
3865 	FROM qp_interface_pricing_attribs
3866        WHERE request_id = p_pricing_attr_rec.request_id(I)
3867 	 AND orig_sys_pricing_attr_ref = p_pricing_attr_rec.orig_sys_pricing_attr_ref(I)
3868 	 AND orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
3869          AND orig_sys_header_ref =  p_pricing_attr_rec.orig_sys_header_ref(I);
3870 
3871  EXCEPTION
3872  WHEN NO_DATA_FOUND THEN
3873     l_exist:=0;
3874  END;
3875 
3876  IF l_exist > 1 THEN
3877         p_pricing_attr_rec.process_status_flag(I):=NULL;
3878 	fnd_message.set_name('QP', 'ORIG_SYS_PRC_ATTR_REF_NOT_UNIQ');
3879         FND_MESSAGE.SET_TOKEN('REF_NO', p_pricing_attr_rec.orig_sys_pricing_attr_ref(I));
3880         qp_bulk_msg.add(l_msg_rec);
3881  END IF;
3882  END IF;
3883 
3884      -- Functional Area Validation for Hierarchical Categories (sfiresto)
3885     IF p_PRICING_ATTR_rec.product_attribute_context(I) = 'ITEM' AND
3886        p_PRICING_ATTR_rec.product_attribute(I) = 'PRICING_ATTRIBUTE2' THEN
3887         BEGIN
3888 
3889           SELECT nvl(pte_code, fnd_profile.value('QP_PRICING_TRANSACTION_ENTITY')),
3890                  nvl(source_system_code, fnd_profile.value('QP_SOURCE_SYSTEM_CODE'))
3891           INTO l_pte_code, l_ss_code
3892           FROM qp_interface_list_headers
3893           WHERE orig_sys_header_ref = p_PRICING_ATTR_rec.orig_sys_header_ref(I);
3894 
3895           QP_UTIL.Get_Item_Cat_Info(
3896              p_PRICING_ATTR_rec.product_attr_value(I),
3897              l_pte_code,
3898              l_ss_code,
3899              l_fna_name,
3900              l_fna_desc,
3901              l_fna_valid);
3902 
3903           IF NOT l_fna_valid THEN
3904 
3905             P_PRICING_ATTR_REC.process_status_flag(I):=NULL;
3906 
3907             FND_MESSAGE.set_name('QP', 'QP_INVALID_CAT_FUNC_PTE');
3908             FND_MESSAGE.set_token('CATID', p_PRICING_ATTR_REC.product_attr_value(I));
3909             FND_MESSAGE.set_token('PTE', l_pte_code);
3910             FND_MESSAGE.set_token('SS', l_ss_code);
3911             QP_BULK_MSG.Add(L_MSG_REC);
3912 
3913           END IF;
3914 
3915         END;
3916     END IF;
3917 
3918  ----- Getting product_attribute_datatype -----
3919  QP_UTIL.GET_PROD_FLEX_PROPERTIES(p_pricing_attr_rec.product_attribute_context(I),
3920 				  p_pricing_attr_rec.product_attribute(I),
3921 				  p_pricing_attr_rec.product_attr_value(I),
3922 				  l_datatype,
3923 				  l_precedence,
3924 				  l_error_code);
3925  IF l_datatype IS NOT NULL THEN
3926     p_pricing_attr_rec.product_attribute_datatype(I):=l_datatype;
3927  ELSE
3928     p_pricing_attr_rec.process_status_flag(I):=NULL;
3929     fnd_message.set_name('QP', 'QP_ATTRIBUTE_REQUIRED');
3930     FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Product Attribute Datatype');
3931     qp_bulk_msg.add(l_msg_rec);
3932  END IF;
3933 
3934   qp_bulk_loader_pub.write_log('After entity pricing attribute');
3935 
3936 -- product uom code
3937 
3938  IF P_PRICING_ATTR_REC.PRODUCT_UOM_CODE(I) IS NULL THEN
3939     P_PRICING_ATTR_REC.process_status_flag(I):=NULL;
3940     FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
3941     FND_MESSAGE.SET_TOKEN('ATTRIBUTE',QP_PRC_UTIL.Get_Attribute_Name('PRODUCT_UOM_CODE'));
3942     QP_BULK_MSG.ADD(L_MSG_REC);
3943  END IF;
3944 
3945 
3946  --- check for single pricing_attribute record with pricing context/attr/value null
3947   qp_bulk_loader_pub.write_log('Pricing attr ref' || p_pricing_attr_rec.orig_sys_pricing_attr_ref(I));
3948   IF p_pricing_attr_rec.pricing_attribute_context(I) IS NULL
3949     OR p_pricing_attr_rec.pricing_attribute(I) IS NULL THEN
3950      l_exist := 0;
3951      BEGIN
3952 	SELECT count(*) INTO l_exist
3953 	  FROM qp_pricing_attributes
3954 	 WHERE orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
3955 	   AND orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I)
3956 	   AND pricing_attribute_context IS NULL
3957            AND pricing_attribute IS NULL
3958            AND orig_sys_pricing_attr_ref <> p_pricing_attr_rec.orig_sys_pricing_attr_ref(I)
3959            AND (pricing_attr_value_from IS NULL OR pricing_Attr_value_to IS NULL);
3960       EXCEPTION
3961 	 WHEN NO_DATA_FOUND THEN
3962 	    l_exist := 0;
3963       END;
3964 
3965       qp_bulk_loader_pub.write_log('Count of records in Pricing Attr table with pricing contect/attr/value null' || to_char(l_exist));
3966       l_exist1:=null;
3967       BEGIN
3968 	SELECT count(*) INTO l_exist1
3969 	  FROM qp_interface_pricing_attribs
3970 	 WHERE request_id = p_pricing_attr_rec.request_id(I)
3971 	   AND orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
3972 	   AND orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I)
3973 	    AND orig_sys_pricing_attr_ref <> p_pricing_attr_rec.orig_sys_pricing_attr_ref(I)
3974 	   AND pricing_attribute_context IS NULL
3975            AND pricing_attribute IS NULL
3976            AND (pricing_attr_value_from IS NULL OR pricing_attr_value_to IS NULL);
3977       EXCEPTION
3978 	 WHEN NO_DATA_FOUND THEN
3979 	    l_exist1 := 0;
3980       END;
3981 
3982       qp_bulk_loader_pub.write_log('Count of records in Int table with pricing contect/attr/value null' || to_char(l_exist1));
3983       IF l_exist > 0 THEN
3984 	 p_pricing_attr_rec.process_status_flag(I):=NULL;
3985 	 FND_MESSAGE.SET_NAME('QP','QP_BULK_PRC_ATTR_ERROR');
3986 	 QP_BULK_MSG.ADD(l_msg_rec);
3987       END IF;
3988       IF l_exist1 > 0 THEN
3989 	 p_pricing_attr_rec.process_status_flag(I):=NULL;
3990 	 FND_MESSAGE.SET_NAME('QP','QP_BULK_INT_PRC_ATTR_ERROR');
3991 	 QP_BULK_MSG.ADD(l_msg_rec);
3992       END IF;
3993 
3994     END IF;
3995 
3996 -- Basic_Pricing_Condition
3997     IF QP_BULK_LOADER_PUB.GET_QP_STATUS <> 'I' THEN
3998       IF p_pricing_attr_rec.pricing_attribute_context(I) IS NOT NULL
3999 	AND p_pricing_attr_rec.pricing_attribute(I) IS NOT NULL THEN
4000 	 l_exist := 0;
4001 	 BEGIN
4002 	    SELECT count(*) INTO l_exist
4003 	      FROM qp_pricing_attributes
4004 	     WHERE orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
4005 	       AND orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I)
4006 	       AND pricing_attribute_context <> p_pricing_attr_rec.pricing_attribute_context(I)
4007 	       AND orig_sys_pricing_attr_ref <> p_pricing_attr_rec.orig_sys_pricing_attr_ref(I);
4008 	  EXCEPTION
4009 	     WHEN NO_DATA_FOUND THEN
4010 		l_exist := 0;
4011 	  END;
4012 
4013 	  l_exist1:=null;
4014 	  BEGIN
4015 	    SELECT count(*) INTO l_exist1
4016 	      FROM qp_interface_pricing_attribs
4017 	     WHERE request_id = p_pricing_attr_rec.request_id(I)
4018 	       AND orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
4019 	       AND orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I)
4020 		AND orig_sys_pricing_attr_ref <> p_pricing_attr_rec.orig_sys_pricing_attr_ref(I)
4021 	       AND pricing_attribute_context <> p_pricing_attr_rec.pricing_attribute_context(I);
4022 	  EXCEPTION
4023 	     WHEN NO_DATA_FOUND THEN
4024 		l_exist1 := 0;
4025 	  END;
4026 	  IF l_exist > 0 OR l_exist1 > 0 THEN
4027 	     p_pricing_attr_rec.process_status_flag(I):=NULL;
4028 	     FND_MESSAGE.SET_NAME('QP','QP_1_PRIC_CONT_FOR_BASIC');
4029 	     --Only one pricing context allwed in Basic Pricing
4030 	     QP_BULK_MSG.ADD(l_msg_rec);
4031 	  END IF;
4032 
4033       END IF;
4034     END IF;
4035 
4036 -- Basic_Pricing_Condition
4037     IF QP_BULK_LOADER_PUB.GET_QP_STATUS <> 'I' THEN
4038        IF p_pricing_attr_rec.pricing_attribute_context(I) IS NOT NULL AND
4039 	  p_pricing_attr_rec.pricing_attribute(I) IS NOT NULL	THEN
4040 	BEGIN
4041 		select s.availability_in_basic
4042 		into   l_availability_in_basic
4043 		from   qp_segments_b s, qp_prc_contexts_b c
4044 		where  s.prc_context_id = c.prc_context_id
4045 		and    c.prc_context_code = p_pricing_attr_rec.pricing_attribute_context(I)
4046 		and    s.segment_mapping_column = p_pricing_attr_rec.pricing_attribute(I)
4047 		and    s.availability_in_basic = 'Y';
4048 	EXCEPTION
4049 		WHEN NO_DATA_FOUND THEN
4050 		 p_pricing_attr_rec.process_status_flag(I):=NULL;
4051 		 FND_MESSAGE.SET_NAME('QP','QP_PRIC_CONTXT_NA_BASIC');
4052 		 --Pricing Attribute Context not allowed in Basic Pricing
4053 		 QP_BULK_MSG.ADD(l_msg_rec);
4054 	END;
4055 
4056        END IF;
4057 
4058        IF p_pricing_attr_rec.product_attribute_context(I) IS NOT NULL AND
4059 	  p_pricing_attr_rec.product_attribute(I) IS NOT NULL	THEN
4060 	BEGIN
4061 		select s.availability_in_basic
4062 		into   l_availability_in_basic
4063 		from   qp_segments_b s, qp_prc_contexts_b c
4064 		where  s.prc_context_id = c.prc_context_id
4065 		and    c.prc_context_code = p_pricing_attr_rec.product_attribute_context(I)
4066 		and    s.segment_mapping_column = p_pricing_attr_rec.product_attribute(I)
4067 		and    s.availability_in_basic = 'Y';
4068 	EXCEPTION
4069 		WHEN NO_DATA_FOUND THEN
4070 		 p_pricing_attr_rec.process_status_flag(I):=NULL;
4071 		 FND_MESSAGE.SET_NAME('QP','QP_PROD_CONTXT_NA_BASIC');
4072 		 --Product Attribute Context not allowed in Basic Pricing
4073 		 QP_BULK_MSG.ADD(l_msg_rec);
4074 	END;
4075       END IF;
4076     END IF;
4077  --- check for consistency of product context/att/val among the attributes
4078 
4079     BEGIN
4080        l_exist := NULL;
4081        SELECT count(*) INTO l_exist
4082 	 FROM qp_pricing_attributes
4083         WHERE orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
4084 	  AND orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I)
4085 	  AND product_attribute_context <> p_pricing_attr_rec.product_attribute_context(I)
4086 	  AND product_attribute <> p_pricing_attr_rec.product_attribute(I)
4087 	  AND product_attr_value <> p_pricing_attr_rec.product_attr_value(I);
4088      EXCEPTION
4089 	WHEN NO_DATA_FOUND THEN
4090 	   l_exist:=0;
4091      END;
4092 
4093     BEGIN
4094        l_exist1 := NULL;
4095        SELECT /*+ index(qipa QP_INTERFACE_PRCNG_ATTRIBS_N2) */ --7433219
4096        count(*) INTO l_exist1
4097 	 FROM qp_interface_pricing_attribs
4098         WHERE request_id = p_pricing_attr_rec.request_id(I)
4099 	  AND process_status_flag = 'P' --is null
4100 	  AND orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
4101 	  AND orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I)
4102 	  AND product_attribute_context <> p_pricing_attr_rec.product_attribute_context(I)
4103 	  AND product_attribute <> p_pricing_attr_rec.product_attribute(I)
4104 	  AND product_attr_value <> p_pricing_attr_rec.product_attr_value(I);
4105      EXCEPTION
4106 	WHEN NO_DATA_FOUND THEN
4107 	   l_exist1:=0;
4108      END;
4109 
4110      IF l_exist >0 OR l_exist1>0 THEN
4111 	 p_pricing_attr_rec.process_status_flag(I):=NULL;
4112 	 FND_MESSAGE.SET_NAME('QP', 'INVALID_PROD_CONTEXT_ATTR_PAIR');
4113 	 QP_BULK_MSG.ADD(l_msg_rec);
4114      END IF;
4115 
4116  -- check for pricing atributes
4117      IF (p_Pricing_Attr_rec.pricing_attribute_context(I) IS NOT NULL
4118 	 OR p_Pricing_Attr_rec.pricing_attribute(I) IS NOT NULL
4119 	 OR p_Pricing_Attr_rec.pricing_attr_value_from(I) IS NOT NULL
4120 	 OR p_Pricing_Attr_rec.pricing_attr_value_to(I) IS NOT NULL)
4121      THEN
4122 	IF (p_Pricing_Attr_rec.pricing_attribute_context(I) IS NULL
4123 	    OR p_Pricing_Attr_rec.pricing_attribute(I) IS NULL
4124 	    OR p_Pricing_Attr_rec.comparison_operator_code(I) IS NULL)
4125         THEN
4126 	 p_pricing_attr_rec.process_status_flag(I):=NULL;
4127 	 IF p_Pricing_Attr_rec.pricing_attribute_context(I) IS NULL THEN
4128 	     FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED'  );
4129 	     FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'PRICING_ATTRIBUTE_CONTEXT');
4130 	     QP_BULK_MSG.ADD(l_msg_rec);
4131 	 END IF;
4132 	 IF p_Pricing_Attr_rec.pricing_attribute(I) IS NULL THEN
4133 	     IF p_Pricing_Attr_rec.pricing_attr_code(I) IS NULL THEN
4134 		 FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED'  );
4135 		 FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'PRICING_ATTRIBUTE');
4136 		 QP_BULK_MSG.ADD(l_msg_rec);
4137 	     ELSE
4138 		 FND_MESSAGE.SET_NAME('QP','QP_VALUE_TO_ID_ERROR'  );
4139 		 FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'PRICING_ATTRIBUTE');
4140 		 QP_BULK_MSG.ADD(l_msg_rec);
4141 	     END IF;
4142 	 END IF;
4143 	 IF p_Pricing_Attr_rec.comparison_operator_code(I) IS NULL THEN
4144 	     FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED'  );
4145 	     FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'COMPARISON_OPERATOR_CODE');
4146 	     QP_BULK_MSG.ADD(l_msg_rec);
4147 	 END IF;
4148         ELSE
4149 	   QP_UTIL.validate_qp_flexfield(flexfield_name  =>'QP_ATTR_DEFNS_PRICING'
4150 					 ,context =>p_Pricing_Attr_rec.pricing_attribute_context(I)
4151 					 ,attribute =>p_Pricing_Attr_rec.pricing_attribute(I)
4152 					 ,value =>p_Pricing_Attr_rec.pricing_attr_value_from(I)
4153 					 ,application_short_name         => 'QP'
4154 					 ,context_flag                   =>l_context_error
4155 					 ,attribute_flag                 =>l_attribute_error
4156 					 ,value_flag                     =>l_value_error
4157 					 ,datatype                       =>l_datatype
4158 					 ,precedence                      =>l_precedence
4159 					 ,error_code                     =>l_error_code
4160 					 );
4161 
4162 	   If (l_context_error = 'N'  AND l_error_code = 7)       --  invalid context
4163 	   Then
4164 	      p_pricing_attr_rec.process_status_flag(I):=NULL;
4165 	      FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED'  );
4166 	      FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
4167 				    QP_PRC_UTIL.Get_Attribute_Name('PRICING_ATTRIBUTE_CONTEXT'));
4168 
4169 	      QP_BULK_MSG.Add(l_msg_rec);
4170 	   END IF;
4171 
4172 	   If l_attribute_error = 'N'   AND l_error_code = 8    --  invalid Attribute
4173 					    Then
4174 	      p_pricing_attr_rec.process_status_flag(I):=NULL;
4175 	      FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
4176 	      FND_MESSAGE.SET_TOKEN('ATTRIBUTE',' Attribute');
4177 	      QP_BULK_MSG.Add(l_msg_rec);
4178 	   END IF;
4179 
4180 	   IF p_pricing_Attr_rec.comparison_operator_code(I) = '=' Then
4181 
4182 	      If l_value_error = 'N'  AND l_error_code = 9      --  invalid value
4183 					  Then
4184 		 p_pricing_attr_rec.process_status_flag(I):=NULL;
4185 		 FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
4186 		 FND_MESSAGE.SET_TOKEN('ATTRIBUTE',' Value From ');
4187 		 QP_BULK_MSG.Add(l_msg_rec);
4188 	      End If;
4189 	   END IF;
4190 
4191 	   p_pricing_attr_rec.pricing_attribute_datatype(I):=l_datatype;
4192 
4193 	   IF p_Pricing_Attr_rec.pricing_attribute_context(I) = 'VOLUME' AND
4194              p_Pricing_Attr_rec.pricing_attribute(I) = 'PRICING_ATTRIBUTE12'
4195                    --When Pricing Context is 'Volume' and Attribute is 'Item Amount'
4196            THEN
4197               p_pricing_attr_rec.process_status_flag(I):=NULL;
4198               FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
4199               FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Pricing Attribute');
4200               QP_BULK_MSG.Add(l_msg_rec);
4201 	   END IF;
4202 
4203 --validation for canonical form
4204 l_error_code:=QP_UTIL.validate_num_date(p_Pricing_Attr_rec.pricing_attribute_datatype(I),
4205 					p_Pricing_Attr_rec.pricing_attr_value_from(I));
4206         IF l_error_code  <> 0  THEN
4207               p_pricing_attr_rec.process_status_flag(I):=NULL;
4208                FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
4209                FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Value From ');
4210               QP_BULK_MSG.Add(l_msg_rec);
4211      END IF;
4212 
4213  -- Validation for Value_To
4214 
4215          IF p_Pricing_Attr_rec.pricing_attribute_context(I) IS NOT NULL AND
4216             p_Pricing_Attr_rec.pricing_attribute(I) IS NOT NULL AND
4217                   UPPER(p_Pricing_Attr_rec.comparison_operator_code(I)) = 'BETWEEN' AND
4218                     (p_Pricing_Attr_rec.pricing_attr_value_to(I) IS NULL OR
4219                         p_Pricing_Attr_rec.pricing_attr_value_from(I) IS NULL)
4220       THEN
4221                    p_pricing_attr_rec.process_status_flag(I):=NULL;
4222                    FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED'  );
4223                    FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
4224 			QP_PRC_UTIL.Get_Attribute_Name('PRICING_ATTR_VALUE_TO')||'/'||
4225                       	QP_PRC_UTIL.Get_Attribute_Name('PRICING_ATTR_VALUE_FROM'));
4226               QP_BULK_MSG.Add(l_msg_rec);
4227       END IF;
4228 
4229  -- validate value from
4230 
4231          IF p_Pricing_Attr_rec.pricing_attribute_context(I) IS NOT NULL AND
4232             p_Pricing_Attr_rec.pricing_attribute(I) IS NOT NULL AND
4233                   UPPER(p_Pricing_Attr_rec.comparison_operator_code(I)) <> 'BETWEEN' AND
4234                         p_Pricing_Attr_rec.pricing_attr_value_from(I) IS NULL
4235        THEN
4236                    p_pricing_attr_rec.process_status_flag(I):=NULL;
4237                    FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED'  );
4238                    FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
4239 			QP_PRC_UTIL.Get_Attribute_Name('PRICING_ATTR_VALUE_FROM'));
4240                     QP_BULK_MSG.Add(l_msg_rec);
4241         END IF;
4242 
4243    l_error_code:=QP_UTIL.validate_num_date(p_Pricing_Attr_rec.pricing_attribute_datatype(I),
4244   		             		     p_Pricing_Attr_rec.pricing_attr_value_to(I));
4245 
4246          IF l_error_code  <> 0  THEN
4247                 p_pricing_attr_rec.process_status_flag(I):=NULL;
4248                 FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
4249                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Value To ');
4250                 QP_BULK_MSG.Add(l_msg_rec);
4251         END IF;
4252 
4253       END IF;  -- Else
4254 
4255  END IF;  -- pricing attr pair not null
4256 
4257    IF ( p_Pricing_Attr_rec.pricing_attribute_context(I) is not null
4258 	 or   p_Pricing_Attr_rec.pricing_attribute(I) is not null ) then
4259 
4260     IF p_Pricing_Attr_rec.comparison_operator_code(I) is null then
4261        p_pricing_attr_rec.process_status_flag(I) :=NULL; --'E';
4262        FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED'  );
4263        FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
4264 			     QP_PRC_UTIL.Get_Attribute_Name('COMPARISON_OPERATOR_CODE'));
4265        QP_BULK_MSG.Add(l_msg_rec);
4266     ElSE
4267 	 SELECT  lookup_code
4268            INTO  l_comparison_operator_code
4269            FROM  QP_LOOKUPS
4270           WHERE  LOOKUP_TYPE = 'COMPARISON_OPERATOR'
4271             AND  LOOKUP_CODE = UPPER(p_Pricing_Attr_rec.comparison_operator_code(I));
4272 
4273        If SQL%NOTFOUND
4274        Then
4275 	  p_pricing_attr_rec.process_status_flag(I) :=NULL; --'E';
4276 	  FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED'  );
4277 	  FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
4278 				QP_PRC_UTIL.Get_Attribute_Name('COMPARISON_OPERATOR_CODE'));
4279 	  QP_BULK_MSG.Add(l_msg_rec);
4280        END IF;
4281 
4282     END IF; /* comparison_operator_code is null */
4283 
4284     l_exist := 0;
4285     begin
4286        SELECT  1
4287        into l_exist
4288        FROM qp_interface_pricing_attribs b, qp_prc_contexts_b d,
4289 	    qp_segments_b e, qp_pte_segments f
4290        WHERE orig_sys_pricing_attr_ref = p_pricing_attr_rec.orig_sys_pricing_attr_ref(I)
4291         AND  b.product_attribute_context = d.prc_context_code
4292 	AND b.product_attribute = e.segment_mapping_column
4293 	AND d.prc_context_id = e.prc_context_id
4294 	AND d.prc_context_type = 'PRICING_ATTRIBUTE'
4295 	AND e.segment_id = f.segment_id
4296 	AND f.pte_code = l_pte_code
4297 	AND f.segment_level <> 'LINE';
4298    exception
4299 	when others then
4300 		null;
4301    end;
4302    if l_exist > 0 then
4303       p_pricing_attr_rec.process_status_flag(I) :=NULL; --'E';
4304       FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
4305       FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'PRICING ATTRIBUTE');
4306       QP_BULK_MSG.Add(l_msg_rec);
4307    end if;
4308 
4309  END IF; /* context or atttribute is not null */
4310 
4311  -- price break child line can have only VOLUME pricing context
4312 
4313  IF  p_pricing_attr_rec.process_status_flag(I)='P' --<> 'E'
4314  THEN
4315    BEGIN
4316     --Bug# 5528754 RAVI
4317     --Check if the pricing attribute is for a PRICE BREAK
4318     SELECT r.rltd_modifier_grp_type
4319       INTO l_pa_price_break
4320      FROM  qp_list_lines l, qp_rltd_modifiers r
4321     WHERE  l.orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
4322       -- Bug 5246745 Use Composite Index for Ref columns
4323       AND  l.orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I)
4324       AND  r.to_rltd_modifier_id = l.list_line_id
4325       AND  r.rltd_modifier_grp_type = 'PRICE BREAK';
4326 
4327     IF    p_pricing_attr_rec.pricing_attribute_context(I) IS NULL THEN
4328 	  p_pricing_attr_rec.process_status_flag(I) :=NULL; --'E';
4329 	  FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
4330           FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Pricing Attribute Context');
4331 	  QP_BULK_MSG.Add(l_msg_rec);
4332     ELSIF p_pricing_attr_rec.pricing_attribute_context(I)<>'VOLUME' THEN
4333 	  p_pricing_attr_rec.process_status_flag(I) :=NULL; --'E';
4334 	  FND_MESSAGE.SET_NAME('QP','PBH_CHILD_LINE_INVALID_CONTEXT');
4335 	  QP_BULK_MSG.Add(l_msg_rec);
4336     END IF;
4337 
4338     EXCEPTION
4339       WHEN NO_DATA_FOUND THEN
4340         --Bug 5649050 (If this pricing attribute is not for a price break then set it back to default)
4341         l_pa_price_break :='PRICE LIST LINE';
4342     END;
4343  END IF;
4344 
4345    --  qp_bulk_loader_pub.write_log('check 5');
4346 
4347   --check for duplicate primary uom flag set
4348  IF p_pricing_attr_rec.process_status_flag(I)='P' THEN -- IS NULL THEN
4349 
4350       SELECT  primary_uom_flag
4351 	INTO  l_primary_uom_flag
4352 	FROM  qp_list_lines
4353        WHERE  list_line_id = p_PRICING_ATTR_rec.list_line_id(I);
4354 
4355     IF l_primary_uom_flag = 'Y'
4356 	 AND p_PRICING_ATTR_rec.product_attribute(I) <> 'PRICING_ATTRIBUTE3' THEN
4357        l_count:= null;
4358        BEGIN
4359        -- Bug# 5228284 RAVI
4360        -- Do not consider the line if it's already the primary flag
4361 	    SELECT count(*)
4362               INTO   l_count
4363 	      FROM   qp_list_lines l, qp_pricing_attributes a
4364 	     WHERE    l.list_line_id = a.list_line_id
4365 	       AND    a.list_header_id = p_PRICING_ATTR_rec.list_header_id(I)
4366 	       AND    a.product_attribute_context=p_PRICING_ATTR_rec.product_attribute_context(I)
4367 	       AND    a.product_attribute = p_PRICING_ATTR_rec.product_attribute(I)
4368 	       AND    a.product_attr_value = p_PRICING_ATTR_rec.product_attr_value(I)
4369 	       AND    a.product_uom_code <> p_PRICING_ATTR_rec.product_uom_code(I)
4370 	       AND    l.primary_uom_flag = 'Y'
4371 	       AND    l.list_line_id <> p_PRICING_ATTR_rec.list_line_id(I);
4372 
4373        EXCEPTION
4374 	  WHEN NO_DATA_FOUND THEN
4375 	     l_count := 0;
4376        END;
4377 
4378        IF l_count > 0 THEN
4379 	  p_pricing_attr_rec.process_status_flag(I):=NULL;
4380 	  FND_MESSAGE.SET_NAME('QP','QP_UNIQUE_PRIMARY_UOM');
4381 	  QP_BULK_MSG.Add(l_msg_rec);
4382 
4383 	  -- set the corresponding line as errored
4384 	    UPDATE qp_interface_list_lines
4385 	       SET  process_status_flag = NULL --'E'
4386 	     WHERE  request_id = p_pricing_attr_rec.request_id(I)
4387 	       AND  orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
4388 	       AND  orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I);
4389 
4390 	  FND_MESSAGE.SET_NAME('QP','QP_UNIQUE_PRIMARY_UOM');
4391 	  l_msg_txt:= FND_MESSAGE.GET;
4392 
4393 	    INSERT INTO QP_INTERFACE_ERRORS
4394 			(error_id,last_update_date, last_updated_by, creation_date,
4395 			 created_by, last_update_login, request_id, program_application_id,
4396 			 program_id, program_update_date, entity_type, table_name, column_name,
4397 			 orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
4398 			orig_sys_pricing_attr_ref, error_message)
4399 	    VALUES
4400 	     (qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
4401 	      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, p_pricing_attr_rec.request_id(I),661,
4402 	      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES', NULL,
4403 	      p_pricing_attr_rec.orig_sys_header_ref(I),p_pricing_attr_rec.orig_sys_line_ref(I),null,
4404 	      null,l_msg_txt);
4405 
4406 	  FOR J IN p_pricing_attr_rec.orig_sys_line_ref.first
4407 		   ..p_pricing_attr_rec.orig_sys_line_ref.last
4408 		   LOOP
4409 	     IF p_pricing_attr_rec.orig_sys_line_ref(J) = p_pricing_attr_rec.orig_sys_line_ref(I)
4410              AND p_pricing_attr_rec.orig_sys_pricing_attr_ref(J) <>
4411 		 p_pricing_attr_rec.orig_sys_pricing_attr_ref(I)
4412 	     THEN
4413 		p_pricing_attr_rec.process_status_flag(J):=NULL; --'E';
4414 		l_msg_rec.orig_sys_pricing_attr_ref := p_pricing_attr_rec.orig_sys_pricing_attr_ref(J);
4415 		FND_MESSAGE.SET_NAME('QP', 'QP_PARENT_FAILED');
4416 		QP_BULK_MSG.ADD(l_msg_rec);
4417 	     END IF;
4418 	  END LOOP;
4419 
4420        END IF;  --End duplicate exists
4421 
4422        BEGIN
4423 	  l_count := null;
4424 	    SELECT count(*)
4425 	      INTO   l_count
4426 	      FROM   qp_list_lines l, qp_interface_pricing_attribs a
4427 	     WHERE   l.orig_sys_line_ref  = a.orig_sys_line_ref
4428 	       AND   l.orig_sys_header_ref  = a.orig_sys_header_ref
4429 	       AND    a.orig_sys_header_ref = p_PRICING_ATTR_rec.orig_sys_header_ref(I)
4430 	       AND    a.product_attribute_context = p_PRICING_ATTR_rec.product_attribute_context(I)
4431 	       AND    a.product_attribute = p_PRICING_ATTR_rec.product_attribute(I)
4432 	       AND    a.product_attr_value = p_PRICING_ATTR_rec.product_attr_value(I)
4433 	       AND    a.product_uom_code <> p_PRICING_ATTR_rec.product_uom_code(I)
4434                AND    a.orig_sys_pricing_attr_ref <> p_pricing_attr_rec.orig_sys_pricing_attr_ref(I)
4435 	       AND    l.primary_uom_flag = 'Y';
4436 
4437        EXCEPTION
4438 	  WHEN NO_DATA_FOUND THEN
4439 	     l_count := 0;
4440        END;
4441 
4442        IF l_count > 0 THEN
4443 	  p_pricing_attr_rec.process_status_flag(I):=NULL;
4444 	  FND_MESSAGE.SET_NAME('QP','QP_UNIQUE_PRIMARY_UOM');
4445 	  QP_BULK_MSG.Add(l_msg_rec);
4446 
4447 	  -- set the corresponding line as errored
4448 	    UPDATE qp_interface_list_lines
4449 	       SET  process_status_flag = NULL --'E'
4450 	     WHERE  request_id = p_pricing_attr_rec.request_id(I)
4451 	       AND  orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
4452 	       AND  orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I);
4453 
4454 	  FND_MESSAGE.SET_NAME('QP','QP_UNIQUE_PRIMARY_UOM');
4455 	  l_msg_txt:= FND_MESSAGE.GET;
4456 
4457 	    INSERT INTO QP_INTERFACE_ERRORS
4458 			(error_id,last_update_date, last_updated_by, creation_date,
4459 			 created_by, last_update_login, request_id, program_application_id,
4460 			 program_id, program_update_date, entity_type, table_name, column_name,
4461 			 orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
4462 			 orig_sys_pricing_attr_ref, error_message)
4463 	    VALUES
4464 	     (qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
4465 	      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, p_pricing_attr_rec.request_id(I),661,
4466 	      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES', NULL,
4467 	      p_pricing_attr_rec.orig_sys_header_ref(I),p_pricing_attr_rec.orig_sys_line_ref(I),null,
4468 	      null,l_msg_txt);
4469 
4470 	  FOR J IN p_pricing_attr_rec.orig_sys_line_ref.first
4471 		   ..p_pricing_attr_rec.orig_sys_line_ref.last
4472 		   LOOP
4473 	     IF p_pricing_attr_rec.orig_sys_line_ref(J) = p_pricing_attr_rec.orig_sys_line_ref(I)
4474 		AND p_pricing_attr_rec.orig_sys_pricing_attr_ref(J) <>
4475 		    p_pricing_attr_rec.orig_sys_pricing_attr_ref(I)
4476 	     THEN
4477 		p_pricing_attr_rec.process_status_flag(J):=NULL; --'E';
4478 		l_msg_rec.orig_sys_pricing_attr_ref := p_pricing_attr_rec.orig_sys_pricing_attr_ref(J);
4479 		FND_MESSAGE.SET_NAME('QP', 'QP_PARENT_FAILED');
4480 		QP_BULK_MSG.ADD(l_msg_rec);
4481 	     END IF;
4482 	  END LOOP;
4483        END IF;   -- If duplicate
4484 
4485 
4486     END IF;   -- IF  primary_uom_flag set
4487 
4488  END IF;   --  IF process_status_flag
4489 
4490  l_msg_rec.orig_sys_pricing_attr_ref := p_pricing_attr_rec.orig_sys_pricing_attr_ref(I);
4491 
4492  -- qp_bulk_loader_pub.write_log('check 6');
4493 --Delayed request validation
4494 -- Checking multiple price break attributes
4495 
4496      BEGIN
4497 
4498           l_count:=null;
4499 	 /* SELECT COUNT(1) INTO l_count
4500 	   FROM
4501 	  (SELECT /*+ ordered leading(la) index(pb QP_INTERFACE_PRCNG_ATTRIBS_N4) */ /*DISTINCT pb.pricing_attribute
4502 	    FROM qp_list_lines la,
4503 		 qp_pricing_attributes pb,
4504 		 qp_rltd_modifiers ra
4505 	   WHERE ra.to_rltd_modifier_id = la.list_line_id
4506 	     AND pb.list_line_id = ra.to_rltd_modifier_id
4507 	     AND ra.from_rltd_modifier_id = (select from_rltd_modifier_id
4508                            from qp_rltd_modifiers, qp_list_lines
4509                            where orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
4510                            -- Bug 5246745 Use Composite Index for Ref columns
4511                            and orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I)
4512                            and to_rltd_modifier_id = list_line_id)
4513 	     AND ra.rltd_modifier_grp_type = 'PRICE BREAK'
4514 	    UNION
4515 	  SELECT  /*+ leading(la) */ /*DISTINCT pb.pricing_attribute
4516 	    FROM   qp_list_lines la,
4517 	           qp_interface_pricing_attribs pb,
4518         	   qp_rltd_modifiers ra
4519 	   WHERE   ra.to_rltd_modifier_id = la.list_line_id
4520 	     AND   pb.orig_sys_line_ref  = la.orig_sys_line_ref
4521 	     AND   pb.request_id =  p_pricing_attr_rec.request_id(I)
4522 	     AND   pb.process_status_flag = 'P' --IS NULL
4523 	     AND   ra.from_rltd_modifier_id = (select from_rltd_modifier_id
4524                            from qp_rltd_modifiers, qp_list_lines
4525                            where orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
4526                            -- Bug 5246745 Use Composite Index for Ref columns
4527                            and orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I)
4528                            and to_rltd_modifier_id = list_line_id)
4529 	     AND   ra.rltd_modifier_grp_type = 'PRICE BREAK');*/
4530 
4531 
4532 	  SELECT COUNT(1) INTO l_count
4533 	   FROM
4534           (SELECT /*+ ordered leading(la) index(pb QP_INTERFACE_PRCNG_ATTRIBS_N4) */ DISTINCT pb.pricing_attribute
4535 	    FROM qp_list_lines la,
4536 		 qp_rltd_modifiers ra,
4537                  qp_rltd_modifiers rb,
4538                  qp_list_lines lb,
4539 		 qp_interface_pricing_attribs pb
4540             WHERE la.orig_sys_line_ref =  p_pricing_attr_rec.orig_sys_line_ref(I) AND
4541                   la.list_line_type_code = 'PLL' AND
4542                   la.pricing_phase_id = 1 AND
4543                   ra.to_rltd_modifier_id = la.list_line_id AND
4544                   rb.from_rltd_modifier_id = ra.FROM_RLTD_MODIFIER_ID AND
4545                   lb.list_line_id = rb.to_rltd_modifier_id AND
4546                   pb.orig_sys_line_ref = lb.orig_sys_line_ref AND
4547                   pb.request_id =  p_pricing_attr_rec.request_id(I) AND
4548                   pb.process_status_flag = 'P' AND --IS NULL  AND
4549                   rb.rltd_modifier_grp_type = 'PRICE BREAK'
4550          UNION
4551             SELECT /*+ leading(la) */ DISTINCT pb.pricing_attribute
4552 	    FROM qp_list_lines la,
4553 		 qp_pricing_attributes pb,
4554 		 qp_rltd_modifiers ra,
4555                  qp_rltd_modifiers rb
4556             WHERE la.orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I) AND
4557                   la.list_line_type_code = 'PLL' AND
4558                   la.pricing_phase_id = 1 AND
4559                   ra.to_rltd_modifier_id = la.list_line_id AND
4560                   rb.from_rltd_modifier_id = ra.FROM_RLTD_MODIFIER_ID AND
4561                   pb.list_line_id = rb.to_rltd_modifier_id AND
4562                   rb.rltd_modifier_grp_type = 'PRICE BREAK');
4563 
4564 	 --qp_bulk_loader_pub.write_log('multi_attr:'||l_count);
4565 
4566          IF l_count>1 THEN
4567             P_PRICING_ATTR_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
4568 	    FND_MESSAGE.SET_NAME('QP', 'QP_MULT_PRICE_BREAK_ATTRS');
4569 	    QP_BULK_MSG.ADD(l_msg_rec);
4570 
4571 	    UPDATE qp_interface_list_lines
4572 	       SET process_status_flag = NULL --'E'
4573 	     WHERE orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
4574 	       AND orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I);
4575 
4576 	  l_msg_txt:= FND_MESSAGE.GET;
4577 
4578 	  INSERT INTO QP_INTERFACE_ERRORS
4579 		       (error_id,last_update_date, last_updated_by, creation_date,
4580 			created_by, last_update_login, request_id, program_application_id,
4581 			program_id, program_update_date, entity_type, table_name, column_name,
4582 			orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
4583 			orig_sys_pricing_attr_ref, error_message)
4584 	   VALUES
4585 	    (qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
4586 	     FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, p_pricing_attr_rec.request_id(I), 661,
4587 	     NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES', NULL,
4588 	     p_pricing_attr_rec.orig_sys_header_ref(I),p_pricing_attr_rec.orig_sys_line_ref(I),null,
4589 	     null,l_msg_txt);
4590 
4591 	 END IF;
4592 
4593       EXCEPTION
4594 	 WHEN NO_DATA_FOUND THEN
4595 	    NULL;
4596       END;
4597 
4598 -- qp_bulk_loader_pub.write_log('check 7: Ref:'|| p_pricing_attr_rec.orig_sys_pricing_attr_ref(I));
4599 
4600 -- Check Overlapping Price break child lines
4601    BEGIN
4602 
4603     l_status := null;
4604     l_status1:= null;
4605 
4606    IF  p_pricing_attr_rec.pricing_attribute_datatype(I)='N' THEN
4607        OPEN C_break_lines(p_pricing_attr_rec.orig_sys_line_ref(I),
4608                           -- Bug 5246745 Use Composite Index for Ref columns
4609                           p_pricing_attr_rec.orig_sys_header_ref(I));
4610 
4611        FETCH C_break_lines into l_status;       CLOSE C_break_lines;
4612    END IF;
4613 
4614 --ENH Continuous Price Breaks START RAVI
4615 /**
4616 Validation check for multiple continuous price breaks (Messages)
4617 **/
4618    IF  p_pricing_attr_rec.pricing_attribute_datatype(I)='N' THEN
4619 
4620        -- Bug# 5440851 RAVI START
4621        -- If the PA values are tried to be changed to Char from Num type throw an error.
4622        BEGIN
4623   	  l_pa_to_val_tmp:=to_number(p_pricing_attr_rec.pricing_attr_value_to(I));
4624        EXCEPTION
4625           WHEN OTHERS THEN
4626              P_PRICING_ATTR_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
4627 	     FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_DATA_TYPE');
4628 	     QP_BULK_MSG.ADD(l_msg_rec);
4629              p_pricing_attr_rec.pricing_attr_value_to(I):=0;
4630        END;
4631 
4632        BEGIN
4633           l_pa_from_val_tmp:=to_number(p_pricing_attr_rec.pricing_attr_value_from(I));
4634        EXCEPTION
4635           WHEN OTHERS THEN
4636              P_PRICING_ATTR_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
4637 	     FND_MESSAGE.SET_NAME('QP', 'QP_INVALID_DATA_TYPE');
4638 	     QP_BULK_MSG.ADD(l_msg_rec);
4639              p_pricing_attr_rec.pricing_attr_value_from(I):=0;
4640        END;
4641        -- Bug# 5440851 RAVI END
4642 
4643        OPEN C_old_cont_grp_break_line(p_pricing_attr_rec.orig_sys_line_ref(I),
4644                           -- Bug 5246745 Use Composite Index for Ref columns
4645                           p_pricing_attr_rec.orig_sys_header_ref(I));
4646        FETCH C_old_cont_grp_break_line
4647              into l_old_break_pa_count, l_old_break_low_value, l_old_break_high_value;
4648        CLOSE C_old_cont_grp_break_line;
4649        OPEN C_new_cont_grp_break_lines(p_pricing_attr_rec.orig_sys_line_ref(I),
4650                           -- Bug 5246745 Use Composite Index for Ref columns
4651                           p_pricing_attr_rec.orig_sys_header_ref(I));
4652        FETCH C_new_cont_grp_break_lines
4653              into l_new_break_pa_count, l_new_break_low_value, l_new_break_high_value;
4654        CLOSE C_new_cont_grp_break_lines;
4655 
4656        --Max from value
4657        l_break_high_value:=to_number(p_pricing_attr_rec.pricing_attr_value_to(I));
4658        IF l_break_high_value < l_old_break_high_value THEN
4659           l_break_high_value:=l_old_break_high_value;
4660        END IF;
4661 
4662        IF l_break_high_value < l_new_break_high_value THEN
4663           l_break_high_value:=l_new_break_high_value;
4664        END IF;
4665 
4666        --Continuous Price Break To and From Values Check
4667        OPEN C_to_value_old(p_pricing_attr_rec.orig_sys_line_ref(I),
4668                           -- Bug 5246745 Use Composite Index for Ref columns
4669                           p_pricing_attr_rec.orig_sys_header_ref(I));
4670        FETCH C_to_value_old into l_to_value_old;
4671        CLOSE C_to_value_old;
4672        OPEN C_to_value_new(p_pricing_attr_rec.orig_sys_line_ref(I),
4673                           -- Bug 5246745 Use Composite Index for Ref columns
4674                           p_pricing_attr_rec.orig_sys_header_ref(I));
4675        FETCH C_to_value_new into l_to_value_new;
4676        CLOSE C_to_value_new;
4677 
4678        OPEN C_from_value_old(p_pricing_attr_rec.orig_sys_line_ref(I),
4679                           -- Bug 5246745 Use Composite Index for Ref columns
4680                           p_pricing_attr_rec.orig_sys_header_ref(I));
4681        FETCH C_from_value_old into l_from_value_old;
4682        CLOSE C_from_value_old;
4683        OPEN C_from_value_new(p_pricing_attr_rec.orig_sys_line_ref(I),
4684                           -- Bug 5246745 Use Composite Index for Ref columns
4685                           p_pricing_attr_rec.orig_sys_header_ref(I));
4686        FETCH C_from_value_new into l_from_value_new;
4687        CLOSE C_from_value_new;
4688 
4689        IF l_old_break_pa_count > 0 OR l_new_break_pa_count > 0 THEN
4690           --Multiple price breaks
4691           qp_bulk_loader_pub.write_log('The price breaks header has multiple price breaks');
4692           IF l_to_value_old = 1 OR l_to_value_new = 1 OR
4693              to_number(p_pricing_attr_rec.pricing_attr_value_to(I)) = l_break_high_value THEN
4694              qp_bulk_loader_pub.write_log('TO value has a corresponding FROM value or is the max.');
4695              IF l_from_value_old = 1 OR l_from_value_new = 1 OR
4696                 to_number(p_pricing_attr_rec.pricing_attr_value_from(I))=0 THEN
4697                 null;
4698                 qp_bulk_loader_pub.write_log('FROM value has a corresponding TO value or is zero.');
4699              ELSE
4700 		qp_bulk_loader_pub.write_log('ERROR: No Same To_From Value for Price Break');
4701                 P_PRICING_ATTR_REC.PROCESS_STATUS_FLAG(I):= NULL ; --'E';
4702                 FND_MESSAGE.SET_NAME('QP', 'QP_PBK_CRSPNDNG_TO_FROM');
4703                 QP_BULK_MSG.ADD(l_msg_rec);
4704 
4705       	        UPDATE qp_interface_list_lines
4706                 SET process_status_flag = NULL --'E'
4707 	            WHERE orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
4708 	            AND orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I);
4709 
4710                 FND_MESSAGE.SET_NAME('QP', 'QP_PBK_CRSPNDNG_TO_FROM');
4711 	            l_msg_txt:= FND_MESSAGE.GET;
4712 
4713       	        INSERT INTO QP_INTERFACE_ERRORS
4714 	      	       (error_id,last_update_date, last_updated_by, creation_date,
4715 		         	created_by, last_update_login, request_id, program_application_id,
4716       	      		program_id, program_update_date, entity_type, table_name, column_name,
4717 	      	      	orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
4718       		      	orig_sys_pricing_attr_ref, error_message)
4719                 VALUES
4720 	                (qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
4721 	                 FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, p_pricing_attr_rec.request_id(I), 661,
4722                      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES', NULL,
4723 	                 p_pricing_attr_rec.orig_sys_header_ref(I),p_pricing_attr_rec.orig_sys_line_ref(I),null,
4724                      null,l_msg_txt);
4725              END IF;
4726           ELSE
4727 	     qp_bulk_loader_pub.write_log('ERROR: No Same From_To Value for Price Break');
4728              P_PRICING_ATTR_REC.PROCESS_STATUS_FLAG(I):= NULL ; --'E';
4729              FND_MESSAGE.SET_NAME('QP', 'QP_PBK_CRSPNDNG_FROM_TO');
4730              QP_BULK_MSG.ADD(l_msg_rec);
4731 
4732 	         UPDATE qp_interface_list_lines
4733 	         SET process_status_flag = NULL --'E'
4734 	         WHERE orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
4735 	         AND orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I);
4736 
4737 	         FND_MESSAGE.SET_NAME('QP', 'QP_PBK_CRSPNDNG_FROM_TO');
4738 	         l_msg_txt:= FND_MESSAGE.GET;
4739 
4740 	         INSERT INTO QP_INTERFACE_ERRORS
4741 		       (error_id,last_update_date, last_updated_by, creation_date,
4742 			    created_by, last_update_login, request_id, program_application_id,
4743 			    program_id, program_update_date, entity_type, table_name, column_name,
4744 			    orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
4745 			    orig_sys_pricing_attr_ref, error_message)
4746 	         VALUES
4747 	           (qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
4748 	            FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, p_pricing_attr_rec.request_id(I), 661,
4749 	            NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES', NULL,
4750 	            p_pricing_attr_rec.orig_sys_header_ref(I),p_pricing_attr_rec.orig_sys_line_ref(I),null,
4751             	null,l_msg_txt);
4752           END IF;
4753        END IF;
4754 
4755        --Check if lowest PB value is zero
4756        IF to_number(p_pricing_attr_rec.pricing_attr_value_from(I)) <> 0 AND l_pa_price_break='PRICE BREAK'
4757        THEN
4758 
4759        --Bug# 5528754 RAVI END
4760           IF l_old_break_low_value = 0 OR l_new_break_low_value = 0 THEN
4761              NULL;
4762           ELSE
4763 	     qp_bulk_loader_pub.write_log('ERROR: No 0 From Value');
4764              P_PRICING_ATTR_REC.PROCESS_STATUS_FLAG(I):= NULL ; --'E';
4765              FND_MESSAGE.SET_NAME('QP', 'QP_PBK_ZERO_FROM');
4766              QP_BULK_MSG.ADD(l_msg_rec);
4767 
4768   	         UPDATE qp_interface_list_lines
4769 	         SET process_status_flag = NULL --'E'
4770 	         WHERE orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
4771 	         AND orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I);
4772 
4773 	         FND_MESSAGE.SET_NAME('QP', 'QP_PBK_ZERO_FROM');
4774 	         l_msg_txt:= FND_MESSAGE.GET;
4775 
4776 	         INSERT INTO QP_INTERFACE_ERRORS
4777 		       (error_id,last_update_date, last_updated_by, creation_date,
4778 			    created_by, last_update_login, request_id, program_application_id,
4779 			    program_id, program_update_date, entity_type, table_name, column_name,
4780 			    orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
4781 			    orig_sys_pricing_attr_ref, error_message)
4782 	           VALUES
4783 	             (qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
4784 	              FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, p_pricing_attr_rec.request_id(I), 661,
4785 	              NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES', NULL,
4786 	              p_pricing_attr_rec.orig_sys_header_ref(I),p_pricing_attr_rec.orig_sys_line_ref(I),null,
4787             	  null,l_msg_txt);
4788           END IF;
4789        END IF;
4790    END IF;
4791 --ENH Continuous Price Breaks END RAVI
4792 
4793    IF p_pricing_attr_rec.pricing_attribute_datatype(I)='N' THEN
4794        OPEN C_Int_break_lines(p_pricing_attr_rec.orig_sys_line_ref(I),
4795                           -- Bug 5246745 Use Composite Index for Ref columns
4796                           p_pricing_attr_rec.orig_sys_header_ref(I),
4797                           p_pricing_attr_rec.request_id(I));  -- changes done by rassharm for bug no 6028305
4798        FETCH C_Int_break_lines into l_status1;
4799 
4800        CLOSE C_Int_break_lines;
4801    END IF;
4802 
4803    IF l_status = 'OVERLAP' OR l_status1 = 'OVERLAP' THEN
4804       qp_bulk_loader_pub.write_log('Overlapping Price Breaks');
4805       P_PRICING_ATTR_REC.PROCESS_STATUS_FLAG(I):= NULL ; --'E';
4806       FND_MESSAGE.SET_NAME('QP', 'QP_OVERLAP_PRICE_BREAK_RANGE');
4807       QP_BULK_MSG.ADD(l_msg_rec);
4808 
4809 	    UPDATE qp_interface_list_lines
4810 	       SET process_status_flag = NULL --'E'
4811 	     WHERE orig_sys_line_ref = p_pricing_attr_rec.orig_sys_line_ref(I)
4812 	       AND orig_sys_header_ref = p_pricing_attr_rec.orig_sys_header_ref(I);
4813 
4814 	  FND_MESSAGE.SET_NAME('QP', 'QP_OVERLAP_PRICE_BREAK_RANGE');
4815 	  l_msg_txt:= FND_MESSAGE.GET;
4816 
4817 	 INSERT INTO QP_INTERFACE_ERRORS
4818 		       (error_id,last_update_date, last_updated_by, creation_date,
4819 			created_by, last_update_login, request_id, program_application_id,
4820 			program_id, program_update_date, entity_type, table_name, column_name,
4821 			orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
4822 			orig_sys_pricing_attr_ref, error_message)
4823 	   VALUES
4824 	    (qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
4825 	     FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, p_pricing_attr_rec.request_id(I), 661,
4826 	     NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES', NULL,
4827 	     p_pricing_attr_rec.orig_sys_header_ref(I),p_pricing_attr_rec.orig_sys_line_ref(I),null,
4828 	     null,l_msg_txt);
4829 
4830    END IF;
4831 EXCEPTION
4832    WHEN NO_DATA_FOUND THEN
4833       NULL;
4834 END;
4835 
4836 --Flex field check
4837 
4838    IF ( p_Pricing_Attr_rec.pricing_attribute_context(I) is not null
4839 	 or   p_Pricing_Attr_rec.pricing_attribute(I) is not null ) then
4840 
4841     IF l_pricing_attr_flex_enabled = 'Y' THEN
4842       qp_bulk_loader_pub.write_log( 'Pricing Attr Flex enabled ');
4843 
4844          IF NOT Init_Desc_Flex
4845                (p_flex_name	     =>'QP_PRICING_ATTRIBUTES'
4846 	       ,p_context            => p_pricing_attr_rec.context(i)
4847                ,p_attribute1         => p_pricing_attr_rec.attribute1(i)
4848                ,p_attribute2         => p_pricing_attr_rec.attribute2(i)
4849                ,p_attribute3         => p_pricing_attr_rec.attribute3(i)
4850                ,p_attribute4         => p_pricing_attr_rec.attribute4(i)
4851                ,p_attribute5         => p_pricing_attr_rec.attribute5(i)
4852                ,p_attribute6         => p_pricing_attr_rec.attribute6(i)
4853                ,p_attribute7         => p_pricing_attr_rec.attribute7(i)
4854                ,p_attribute8         => p_pricing_attr_rec.attribute8(i)
4855                ,p_attribute9         => p_pricing_attr_rec.attribute9(i)
4856                ,p_attribute10        => p_pricing_attr_rec.attribute10(i)
4857                ,p_attribute11        => p_pricing_attr_rec.attribute11(i)
4858                ,p_attribute12        => p_pricing_attr_rec.attribute12(i)
4859                ,p_attribute13        => p_pricing_attr_rec.attribute13(i)
4860                ,p_attribute14        => p_pricing_attr_rec.attribute14(i)
4861                ,p_attribute15        => p_pricing_attr_rec.attribute15(i)) THEN
4862 
4863 	         QP_BULK_MSG.ADD(l_msg_rec);
4864 
4865                  -- Log Error Message
4866                  FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
4867                  FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
4868                                        'Entity:Flexfield:Pricing_Attr_Desc_Flex');
4869 	         p_pricing_attr_rec.process_status_flag(I):=NULL;
4870 
4871 	         QP_BULK_MSG.ADD(l_msg_rec);
4872 
4873           ELSE -- if the flex validation is successfull
4874 
4875             IF p_pricing_attr_rec.context(i) IS NULL
4876               OR p_pricing_attr_rec.context(i) = FND_API.G_MISS_CHAR THEN
4877                p_pricing_attr_rec.context(i)    := g_context;
4878             END IF;
4879 
4880             IF p_pricing_attr_rec.attribute1(i) IS NULL
4881               OR p_pricing_attr_rec.attribute1(i) = FND_API.G_MISS_CHAR THEN
4882                p_pricing_attr_rec.attribute1(i) := g_attribute1;
4883             END IF;
4884 
4885             IF p_pricing_attr_rec.attribute2(i) IS NULL
4886               OR p_pricing_attr_rec.attribute2(i) = FND_API.G_MISS_CHAR THEN
4887                p_pricing_attr_rec.attribute2(i) := g_attribute2;
4888             END IF;
4889 
4890             IF p_pricing_attr_rec.attribute3(i) IS NULL
4891               OR p_pricing_attr_rec.attribute3(i) = FND_API.G_MISS_CHAR THEN
4892                p_pricing_attr_rec.attribute3(i) := g_attribute3;
4893             END IF;
4894 
4895             IF p_pricing_attr_rec.attribute4(i) IS NULL
4896               OR p_pricing_attr_rec.attribute4(i) = FND_API.G_MISS_CHAR THEN
4897                p_pricing_attr_rec.attribute4(i) := g_attribute4;
4898             END IF;
4899 
4900             IF p_pricing_attr_rec.attribute5(i) IS NULL
4901               OR p_pricing_attr_rec.attribute5(i) = FND_API.G_MISS_CHAR THEN
4902                p_pricing_attr_rec.attribute5(i) := g_attribute5;
4903             END IF;
4904 
4905             IF p_pricing_attr_rec.attribute6(i) IS NULL
4906               OR p_pricing_attr_rec.attribute6(i) = FND_API.G_MISS_CHAR THEN
4907                p_pricing_attr_rec.attribute6(i) := g_attribute6;
4908             END IF;
4909             IF p_pricing_attr_rec.attribute7(i) IS NULL
4910               OR p_pricing_attr_rec.attribute7(i) = FND_API.G_MISS_CHAR THEN
4911                p_pricing_attr_rec.attribute7(i) := g_attribute7;
4912             END IF;
4913 
4914             IF p_pricing_attr_rec.attribute8(i) IS NULL
4915               OR p_pricing_attr_rec.attribute8(i) = FND_API.G_MISS_CHAR THEN
4916                p_pricing_attr_rec.attribute8(i) := g_attribute8;
4917             END IF;
4918 
4919             IF p_pricing_attr_rec.attribute9(i) IS NULL
4920               OR p_pricing_attr_rec.attribute9(i) = FND_API.G_MISS_CHAR THEN
4921                p_pricing_attr_rec.attribute9(i) := g_attribute9;
4922             END IF;
4923 
4924             IF p_pricing_attr_rec.attribute10(i) IS NULL
4925               OR p_pricing_attr_rec.attribute10(i) = FND_API.G_MISS_CHAR THEN
4926                p_pricing_attr_rec.attribute10(i) := G_attribute10;
4927             End IF;
4928 
4929             IF p_pricing_attr_rec.attribute11(i) IS NULL
4930               OR p_pricing_attr_rec.attribute11(i) = FND_API.G_MISS_CHAR THEN
4931                p_pricing_attr_rec.attribute11(i) := g_attribute11;
4932             END IF;
4933 
4934             IF p_pricing_attr_rec.attribute12(i) IS NULL
4935               OR p_pricing_attr_rec.attribute12(i) = FND_API.G_MISS_CHAR THEN
4936                p_pricing_attr_rec.attribute12(i) := g_attribute12;
4937             END IF;
4938 
4939             IF p_pricing_attr_rec.attribute13(i) IS NULL
4940               OR p_pricing_attr_rec.attribute13(i) = FND_API.G_MISS_CHAR THEN
4941                p_pricing_attr_rec.attribute13(i) := g_attribute13;
4942             END IF;
4943 
4944             IF p_pricing_attr_rec.attribute14(i) IS NULL
4945               OR p_pricing_attr_rec.attribute14(i) = FND_API.G_MISS_CHAR THEN
4946                p_pricing_attr_rec.attribute14(i) := g_attribute14;
4947             END IF;
4948 
4949             IF p_pricing_attr_rec.attribute15(i) IS NULL
4950               OR p_pricing_attr_rec.attribute15(i) = FND_API.G_MISS_CHAR THEN
4951                p_pricing_attr_rec.attribute15(i) := g_attribute15;
4952             END IF;
4953 	END IF;
4954     END IF;
4955  END IF;  -- pricing attr pair not null
4956 
4957   -- Updation check
4958   --cannot update product attribute
4959   IF p_pricing_attr_rec.interface_action_code(I) = 'UPDATE'
4960      AND p_pricing_attr_rec.process_status_flag(I)='P' THEN --,'*') <> 'E' THEN
4961 
4962       l_old_pricing_attr_rec := Qp_pll_pricing_attr_Util.Query_Row
4963 	(   p_pricing_attribute_id        => l_pricing_attribute_id
4964 	);
4965 
4966       IF l_old_pricing_attr_rec.product_attribute_context <>
4967 	 p_pricing_attr_rec.product_attribute_context(I)
4968 	 OR l_old_pricing_attr_rec.product_attribute <>
4969 	    p_pricing_attr_rec.product_attribute(I)
4970 	    OR l_old_pricing_attr_rec.product_attr_value <>
4971 	       p_pricing_attr_rec.product_attr_value(I) THEN
4972 
4973 	 P_PRICING_ATTR_REC.PROCESS_STATUS_FLAG(I):= NULL; --'E';
4974 	 FND_MESSAGE.SET_NAME('QP', 'NO_PRODUCT_ATTR_UPD');
4975 	 QP_BULK_MSG.ADD(l_msg_rec);
4976       END IF;
4977   END IF;
4978 
4979 
4980 --Warning messages
4981 -- Product attribute
4982      IF p_pricing_attr_rec.process_status_flag(I)='P' --,'*') <> 'E'
4983 	and p_pricing_attr_rec.pricing_attribute_context(I) IS NULL
4984 	and p_pricing_attr_rec.pricing_attribute(I) IS NULL THEN
4985 
4986         QP_UTIL.Get_Context_Type('QP_ATTR_DEFNS_PRICING',
4987                                p_Pricing_Attr_rec.product_attribute_context(I),
4988                                l_context_type,
4989                                l_error_code);
4990 
4991         QP_UTIL.Get_Sourcing_Info(l_context_type,
4992                                   p_Pricing_Attr_rec.product_attribute_context(I),
4993                                   p_Pricing_Attr_rec.product_attribute(I),
4994                                   l_sourcing_enabled,
4995                                   l_sourcing_status,
4996                                   l_sourcing_method);
4997    	qp_bulk_loader_pub.write_log('Sourcing method / status / enabled'||l_sourcing_method||l_sourcing_status||l_sourcing_enabled);
4998 
4999         IF l_sourcing_method = 'ATTRIBUTE MAPPING' THEN
5000 
5001           IF l_sourcing_enabled <> 'Y' THEN
5002 
5003             FND_MESSAGE.SET_NAME('QP','QP_ENABLE_SOURCING');
5004             FND_MESSAGE.SET_TOKEN('CONTEXT',
5005                                 p_Pricing_Attr_rec.product_attribute_context(I));
5006 	    FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
5007                                   p_Pricing_Attr_rec.product_attribute(I));
5008 	    QP_BULK_MSG.ADD(l_msg_rec);
5009            END IF;
5010 
5011           IF l_sourcing_status <> 'Y' THEN
5012 
5013             FND_MESSAGE.SET_NAME('QP','QP_BUILD_SOURCING_RULES');
5014             FND_MESSAGE.SET_TOKEN('CONTEXT',
5015                                   p_Pricing_Attr_rec.product_attribute_context(I));
5016 	    FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
5017                                   p_Pricing_Attr_rec.product_attribute(I));
5018 	    QP_BULK_MSG.ADD(l_msg_rec);
5019 
5020           END IF;
5021 
5022         END IF; --If sourcing_method = 'ATTRIBUTE MAPPING'
5023      END IF; -- process_status_flag(I) <> 'E'
5024 
5025 -- Pricing attribute
5026      IF p_pricing_attr_rec.process_status_flag(I)='P' --,'*') <> 'E'
5027 	and p_pricing_attr_rec.pricing_attribute_context(I) IS NOT NULL
5028 	and p_pricing_attr_rec.pricing_attribute(I) IS NOT NULL THEN
5029 
5030         QP_UTIL.Get_Context_Type('QP_ATTR_DEFNS_PRICING',
5031                                p_Pricing_Attr_rec.pricing_attribute_context(I),
5032                                l_context_type,
5033                                l_error_code);
5034 
5035         QP_UTIL.Get_Sourcing_Info(l_context_type,
5036                                   p_Pricing_Attr_rec.pricing_attribute_context(I),
5037                                   p_Pricing_Attr_rec.pricing_attribute(I),
5038                                   l_sourcing_enabled,
5039                                   l_sourcing_status,
5040                                   l_sourcing_method);
5041 
5042    	qp_bulk_loader_pub.write_log('Sourcing method / status / enabled'||l_sourcing_method||l_sourcing_status||l_sourcing_enabled);
5043 
5044         IF l_sourcing_method = 'ATTRIBUTE MAPPING' THEN
5045 
5046           IF l_sourcing_enabled <> 'Y' THEN
5047 
5048             FND_MESSAGE.SET_NAME('QP','QP_ENABLE_SOURCING');
5049             FND_MESSAGE.SET_TOKEN('CONTEXT',
5050                                 p_Pricing_Attr_rec.pricing_attribute_context(I));
5051 	    FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
5052                                   p_Pricing_Attr_rec.pricing_attribute(I));
5053 	    QP_BULK_MSG.ADD(l_msg_rec);
5054            END IF;
5055 
5056           IF l_sourcing_status <> 'Y' THEN
5057 
5058             FND_MESSAGE.SET_NAME('QP','QP_BUILD_SOURCING_RULES');
5059             FND_MESSAGE.SET_TOKEN('CONTEXT',
5060                                   p_Pricing_Attr_rec.pricing_attribute_context(I));
5061 	    FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
5062                                   p_Pricing_Attr_rec.pricing_attribute(I));
5063 	    QP_BULK_MSG.ADD(l_msg_rec);
5064 
5065           END IF;
5066 
5067         END IF; --If sourcing_method = 'ATTRIBUTE MAPPING'
5068      END IF; -- process_status_flag(I) <> 'E'
5069  END LOOP;
5070 
5071  qp_bulk_loader_pub.write_log( 'Leaving Entity Pricing Attr validation');
5072 
5073  EXCEPTION
5074     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5075        qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE ENTITY_PRICING_ATTR:'||sqlerrm);
5076        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5077     WHEN OTHERS THEN
5078        qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE ENTITY_PRICING_ATTR:'||sqlerrm);
5079        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5080 
5081 
5082 END ENTITY_PRICING_ATTR;
5083 
5084 
5085 
5086 
5087 PROCEDURE ATTRIBUTE_HEADER
5088           (p_request_id NUMBER)
5089 IS
5090    l_msg_txt VARCHAR2(240);
5091 
5092 BEGIN
5093 
5094         --Currency Code
5095 	--List Type Code
5096 	--Freight Terms
5097 	--Payment Terms
5098 	--Ship Method (Freight Carrier)
5099 	--Currency Header Id
5100 	--Name
5101 	--PTE
5102 	--Source System
5103 
5104 qp_bulk_loader_pub.write_log('Entering Attribute Header validation');
5105 -- 1.Currency  Code
5106 
5107 FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
5108 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','CURRENCY CODE');
5109 l_msg_txt := FND_MESSAGE.GET;
5110 
5111 
5112 INSERT INTO QP_INTERFACE_ERRORS
5113    (error_id,last_update_date, last_updated_by, creation_date,
5114     created_by, last_update_login, request_id, program_application_id,
5115     program_id, program_update_date, entity_type, table_name, column_name,
5116     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5117     orig_sys_pricing_attr_ref, error_message)
5118     	SELECT
5119      	qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5120      	FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5121      	NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS', 'CURRENCY_CODE',
5122      	qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5123     	FROM QP_INTERFACE_LIST_HEADERS qpih
5124     	WHERE qpih.request_id = p_request_id
5125       	AND qpih.process_status_flag ='P' --is null
5126         AND qpih.currency_code is not null
5127 	AND qpih.interface_action_code IN ('INSERT', 'UPDATE')
5128       	AND NOT EXISTS (SELECT currency_code -- Validation
5129      		      FROM fnd_currencies_vl
5130      		      WHERE enabled_flag = 'Y'
5131      		      AND currency_flag='Y'
5132      		      AND currency_code = qpih.currency_code
5133                       );
5134 
5135  -- 2.Freight Terms
5136 
5137 FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
5138 FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'FREIGHT TERMS');
5139 l_msg_txt := FND_MESSAGE.GET;
5140 
5141 --Bug# 5412029 START RAVI
5142 --Check if the frieght terms are valid
5143     INSERT INTO QP_INTERFACE_ERRORS
5144    (error_id,last_update_date, last_updated_by, creation_date,
5145     created_by, last_update_login, request_id, program_application_id,
5146     program_id, program_update_date, entity_type, table_name, column_name,
5147     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5148     orig_sys_pricing_attr_ref, error_message)
5149     SELECT
5150      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5151      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5152      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS', 'FREIGHT TERMS',
5153      qpih.orig_sys_header_ref,null,null,null, l_msg_txt
5154     FROM QP_INTERFACE_LIST_HEADERS qpih
5155     WHERE qpih.request_id = p_request_id
5156       AND  qpih.process_status_flag ='P' --is null
5157       AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5158       AND qpih.freight_terms_code IS NOT NULL
5159       AND qpih.freight_terms_code <> QP_BULK_LOADER_PUB.G_NULL_CHAR
5160       AND qpih.freight_terms IS NOT NULL
5161       AND NOT EXISTS (SELECT   freight_terms_code
5162                       	   FROM     OE_FRGHT_TERMS_ACTIVE_V
5163                       	   WHERE    freight_terms_code = qpih.freight_terms_code
5164                            AND      freight_terms = qpih.freight_terms
5165                       	   AND    sysdate BETWEEN nvl(start_date_active, sysdate)
5166                                               AND    nvl(end_date_active, sysdate));
5167 
5168     INSERT INTO QP_INTERFACE_ERRORS
5169    (error_id,last_update_date, last_updated_by, creation_date,
5170     created_by, last_update_login, request_id, program_application_id,
5171     program_id, program_update_date, entity_type, table_name, column_name,
5172     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5173     orig_sys_pricing_attr_ref, error_message)
5174     SELECT
5175      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5176      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5177      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS', 'FREIGHT TERMS',
5178      qpih.orig_sys_header_ref,null,null,null, l_msg_txt
5179     FROM QP_INTERFACE_LIST_HEADERS qpih
5180     WHERE qpih.request_id = p_request_id
5181       AND  qpih.process_status_flag ='P' --is null
5182       AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5183       AND qpih.freight_terms IS NOT NULL
5184       AND qpih.freight_terms_code IS NULL
5185       AND NOT EXISTS (SELECT   freight_terms_code
5186                       	   FROM     OE_FRGHT_TERMS_ACTIVE_V
5187                       	   WHERE    freight_terms = qpih.freight_terms
5188                       	   AND    sysdate BETWEEN nvl(start_date_active, sysdate)
5189                                               AND    nvl(end_date_active, sysdate));
5190 
5191     INSERT INTO QP_INTERFACE_ERRORS
5192    (error_id,last_update_date, last_updated_by, creation_date,
5193     created_by, last_update_login, request_id, program_application_id,
5194     program_id, program_update_date, entity_type, table_name, column_name,
5195     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5196     orig_sys_pricing_attr_ref, error_message)
5197     SELECT
5198      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5199      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5200      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS', 'FREIGHT TERMS',
5201      qpih.orig_sys_header_ref,null,null,null, l_msg_txt
5202     FROM QP_INTERFACE_LIST_HEADERS qpih
5203     WHERE qpih.request_id = p_request_id
5204       AND  qpih.process_status_flag ='P' --is null
5205       AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5206       AND qpih.freight_terms IS NULL
5207       AND qpih.freight_terms_code IS NOT NULL
5208       AND qpih.freight_terms_code <> QP_BULK_LOADER_PUB.G_NULL_CHAR
5209       AND NOT EXISTS (SELECT   freight_terms_code
5210                       	   FROM     OE_FRGHT_TERMS_ACTIVE_V
5211                       	   WHERE    freight_terms_code = qpih.freight_terms_code
5212                       	   AND    sysdate BETWEEN nvl(start_date_active, sysdate)
5213                                               AND    nvl(end_date_active, sysdate));
5214 --Bug# 5412029 END RAVI
5215 
5216 -- 3.  LIST TYPE CODE
5217 
5218 FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
5219 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','LIST TYPE CODE');
5220 l_msg_txt := FND_MESSAGE.GET;
5221 
5222     INSERT INTO QP_INTERFACE_ERRORS
5223    (error_id,last_update_date, last_updated_by, creation_date,
5224     created_by, last_update_login, request_id, program_application_id,
5225     program_id, program_update_date, entity_type, table_name, column_name,
5226     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5227     orig_sys_pricing_attr_ref, error_message)
5228     SELECT
5229      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5230      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5231      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS', 'LIST_TYPE_CODE',
5232      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5233     FROM QP_INTERFACE_LIST_HEADERS qpih
5234     WHERE qpih.request_id = p_request_id
5235          AND   qpih.process_status_flag ='P' --is null
5236          AND   qpih.interface_action_code IN ('INSERT', 'UPDATE')
5237          AND   qpih.list_type_code IS NOT NULL
5238          AND   NOT EXISTS (SELECT lookup_code
5239      		      FROM qp_lookups
5240      	      	      WHERE lookup_type = 'LIST_TYPE_CODE'
5241      		      AND lookup_code   = qpih.list_type_code);
5242 
5243 -- 4.Ship Method(Freight Carrier)
5244 
5245 FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
5246 FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'FREIGHT CARRIER');
5247 l_msg_txt := FND_MESSAGE.GET;
5248 
5249 --Bug# 5412029 START RAVI
5250 --Check if the ship method are valid
5251     INSERT INTO QP_INTERFACE_ERRORS
5252    (error_id,last_update_date, last_updated_by, creation_date,
5253     created_by, last_update_login, request_id, program_application_id,
5254     program_id, program_update_date, entity_type, table_name, column_name,
5255     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5256     orig_sys_pricing_attr_ref,  error_message)
5257     SELECT
5258      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5259      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5260      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'FRIEGHT CARRIER',
5261      qpih.orig_sys_header_ref, null,null,null,l_msg_txt
5262     FROM QP_INTERFACE_LIST_HEADERS qpih
5263     WHERE qpih.request_id = p_request_id
5264       AND  qpih.process_status_flag ='P' --is null
5265       AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5266       AND qpih.ship_method IS NOT NULL
5267       AND qpih.ship_method_code IS NOT NULL
5268       AND qpih.ship_method_code <> QP_BULK_LOADER_PUB.G_NULL_CHAR
5269       AND NOT EXISTS (SELECT LOOKUP_CODE
5270     		        FROM OE_SHIP_METHODS_V
5271     		       WHERE LOOKUP_TYPE = 'SHIP_METHOD'
5272     		       AND  LOOKUP_CODE = qpih.ship_method_code
5273     		       AND  MEANING = qpih.ship_method
5274     		       AND  sysdate BETWEEN nvl(start_date_active, sysdate)
5275                                      AND    nvl(end_date_active, sysdate) );
5276 
5277     INSERT INTO QP_INTERFACE_ERRORS
5278    (error_id,last_update_date, last_updated_by, creation_date,
5279     created_by, last_update_login, request_id, program_application_id,
5280     program_id, program_update_date, entity_type, table_name, column_name,
5281     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5282     orig_sys_pricing_attr_ref,  error_message)
5283     SELECT
5284      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5285      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5286      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'FRIEGHT CARRIER',
5287      qpih.orig_sys_header_ref, null,null,null,l_msg_txt
5288     FROM QP_INTERFACE_LIST_HEADERS qpih
5289     WHERE qpih.request_id = p_request_id
5290       AND  qpih.process_status_flag ='P' --is null
5291       AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5292       AND qpih.ship_method IS NULL
5293       AND qpih.ship_method_code IS NOT NULL
5294       AND qpih.ship_method_code <> QP_BULK_LOADER_PUB.G_NULL_CHAR
5295       AND NOT EXISTS (SELECT LOOKUP_CODE
5296     		        FROM OE_SHIP_METHODS_V
5297     		       WHERE LOOKUP_TYPE = 'SHIP_METHOD'
5298     		       AND  LOOKUP_CODE = qpih.ship_method_code
5299     		       AND  sysdate BETWEEN nvl(start_date_active, sysdate)
5300                                      AND    nvl(end_date_active, sysdate) );
5301 
5302     INSERT INTO QP_INTERFACE_ERRORS
5303    (error_id,last_update_date, last_updated_by, creation_date,
5304     created_by, last_update_login, request_id, program_application_id,
5305     program_id, program_update_date, entity_type, table_name, column_name,
5306     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5307     orig_sys_pricing_attr_ref,  error_message)
5308     SELECT
5309      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5310      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5311      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'FRIEGHT CARRIER',
5312      qpih.orig_sys_header_ref, null,null,null,l_msg_txt
5313     FROM QP_INTERFACE_LIST_HEADERS qpih
5314     WHERE qpih.request_id = p_request_id
5315       AND  qpih.process_status_flag ='P' --is null
5316       AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5317       AND qpih.ship_method IS NOT NULL
5318       AND qpih.ship_method_code IS NULL
5319       AND NOT EXISTS (SELECT LOOKUP_CODE
5320     		        FROM OE_SHIP_METHODS_V
5321     		       WHERE LOOKUP_TYPE = 'SHIP_METHOD'
5322     		       AND  MEANING = qpih.ship_method
5323     		       AND  sysdate BETWEEN nvl(start_date_active, sysdate)
5324                                      AND    nvl(end_date_active, sysdate) );
5325 --Bug# 5412029 END RAVI
5326 
5327 -- 5. Payment Terms
5328 FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
5329 FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'PAYMENT TERMS');
5330 l_msg_txt := FND_MESSAGE.GET;
5331 
5332 --Bug# 5412029 START RAVI
5333 --Check if the payment terms are valid
5334     INSERT INTO QP_INTERFACE_ERRORS
5335    (error_id,last_update_date, last_updated_by, creation_date,
5336     created_by, last_update_login, request_id, program_application_id,
5337     program_id, program_update_date, entity_type, table_name, column_name,
5338     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5339     orig_sys_pricing_attr_ref, error_message)
5340     SELECT
5341      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5342      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5343      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS', 'PAYMENT TERMS',
5344      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5345     FROM QP_INTERFACE_LIST_HEADERS qpih
5346     WHERE qpih.request_id = p_request_id
5347       AND  qpih.process_status_flag ='P' --is null
5348       AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5349       AND qpih.terms_id IS NOT NULL
5350       AND qpih.terms IS NOT NULL
5351       AND qpih.terms <> QP_BULK_LOADER_PUB.G_NULL_CHAR
5352       --Bug#5248659 RAVI
5353       --Use Term_id not terms_id
5354       AND NOT EXISTS (SELECT   TERM_ID
5355                       FROM     RA_TERMS
5356                       WHERE    TERM_ID = qpih.terms_id
5357                         AND    name = qpih.terms
5358                         AND    sysdate BETWEEN nvl(start_date_active, sysdate)
5359                                      AND    nvl(end_date_active, sysdate) );
5360 
5361     INSERT INTO QP_INTERFACE_ERRORS
5362    (error_id,last_update_date, last_updated_by, creation_date,
5363     created_by, last_update_login, request_id, program_application_id,
5364     program_id, program_update_date, entity_type, table_name, column_name,
5365     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5366     orig_sys_pricing_attr_ref, error_message)
5367     SELECT
5368      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5369      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5370      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS', 'PAYMENT TERMS',
5371      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5372     FROM QP_INTERFACE_LIST_HEADERS qpih
5373     WHERE qpih.request_id = p_request_id
5374       AND  qpih.process_status_flag ='P' --is null
5375       AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5376       AND qpih.terms_id IS NOT NULL
5377       AND qpih.terms IS NULL
5378       --Bug#5248659 RAVI
5379       --Use Term_id not terms_id
5380       AND NOT EXISTS (SELECT   TERM_ID
5381                       FROM     RA_TERMS
5382                       WHERE    TERM_ID = qpih.terms_id
5383                         AND    sysdate BETWEEN nvl(start_date_active, sysdate)
5384                                      AND    nvl(end_date_active, sysdate) );
5385 
5386     INSERT INTO QP_INTERFACE_ERRORS
5387    (error_id,last_update_date, last_updated_by, creation_date,
5388     created_by, last_update_login, request_id, program_application_id,
5389     program_id, program_update_date, entity_type, table_name, column_name,
5390     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5391     orig_sys_pricing_attr_ref, error_message)
5392     SELECT
5393      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5394      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5395      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS', 'PAYMENT TERMS',
5396      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5397     FROM QP_INTERFACE_LIST_HEADERS qpih
5398     WHERE qpih.request_id = p_request_id
5399       AND  qpih.process_status_flag ='P' --is null
5400       AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5401       AND qpih.terms_id IS NULL
5402       AND qpih.terms IS NOT NULL
5403       AND qpih.terms <> QP_BULK_LOADER_PUB.G_NULL_CHAR
5404       --Bug#5248659 RAVI
5405       --Use Term_id not terms_id
5406       AND NOT EXISTS (SELECT   TERM_ID
5407                       FROM     RA_TERMS
5408                       WHERE    name = qpih.terms
5409                         AND    sysdate BETWEEN nvl(start_date_active, sysdate)
5410                                      AND    nvl(end_date_active, sysdate) );
5411 
5412 --Bug# 5412029 END RAVI
5413   -- 6. Currency Header
5414 
5415 FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
5416 FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'CURRENCY HEADER');
5417 l_msg_txt := FND_MESSAGE.GET;
5418 
5419 -- Bug 4938046,5412029 START RAVI
5420 /**
5421 Currency Header and Header ID validation
5422 **/
5423 
5424 INSERT INTO QP_INTERFACE_ERRORS
5425    (error_id,last_update_date, last_updated_by, creation_date,
5426     created_by, last_update_login, request_id, program_application_id,
5427     program_id, program_update_date, entity_type, table_name, column_name,
5428     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5429     orig_sys_pricing_attr_ref,  error_message)
5430     SELECT
5431      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5432      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5433      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'CURRENCY_HEADER',
5434      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5435     FROM QP_INTERFACE_LIST_HEADERS qpih
5436     WHERE qpih.request_id = p_request_id
5437       AND qpih.process_status_flag ='P' --is null
5438       AND qpih.interface_action_code IN ('INSERT', 'UPDATE')
5439       AND qpih.currency_header_id is NOT NULL
5440       AND qpih.currency_header is NOT NULL
5441       AND qpih.currency_header <> QP_BULK_LOADER_PUB.G_NULL_CHAR
5442       AND NOT EXISTS ( SELECT qpclb.currency_header_id
5443 		       FROM   qp_currency_lists_b qpclb, qp_currency_lists_tl qpclt
5444 		       WHERE  qpclb.currency_header_id = qpih.currency_header_id
5445                AND    qpclb.base_currency_code = qpih.currency_code
5446                AND    qpclt.currency_header_id = qpclb.currency_header_id
5447                AND    qpclt.language = nvl(qpih.language,'US')
5448                AND    qpclt.name = qpih.currency_header);
5449 
5450 INSERT INTO QP_INTERFACE_ERRORS
5451    (error_id,last_update_date, last_updated_by, creation_date,
5452     created_by, last_update_login, request_id, program_application_id,
5453     program_id, program_update_date, entity_type, table_name, column_name,
5454     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5455     orig_sys_pricing_attr_ref,  error_message)
5456     SELECT
5457      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5458      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5459      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'CURRENCY_HEADER',
5460      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5461     FROM QP_INTERFACE_LIST_HEADERS qpih
5462     WHERE qpih.request_id = p_request_id
5463       AND  qpih.process_status_flag ='P' --is null
5464       AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5465       AND  qpih.currency_header is NOT NULL
5466       AND  qpih.currency_header <> QP_BULK_LOADER_PUB.G_NULL_CHAR
5467       AND  qpih.currency_header_id is NULL
5468       AND NOT EXISTS ( SELECT qpclb.currency_header_id
5469 		       FROM   qp_currency_lists_b qpclb, qp_currency_lists_tl qpclt
5470 		       WHERE  qpclb.base_currency_code = qpih.currency_code
5471                AND    qpclt.currency_header_id = qpclb.currency_header_id
5472                AND    qpclt.language = nvl(qpih.language,'US')
5473                AND    qpclt.name = qpih.currency_header);
5474 
5475 INSERT INTO QP_INTERFACE_ERRORS
5476    (error_id,last_update_date, last_updated_by, creation_date,
5477     created_by, last_update_login, request_id, program_application_id,
5478     program_id, program_update_date, entity_type, table_name, column_name,
5479     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5480     orig_sys_pricing_attr_ref,  error_message)
5481     SELECT
5482      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5483      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5484      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'CURRENCY_HEADER',
5485      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5486     FROM QP_INTERFACE_LIST_HEADERS qpih
5487     WHERE qpih.request_id = p_request_id
5488       AND  qpih.process_status_flag ='P' --is null
5489       AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5490       AND  qpih.currency_header_id is NOT NULL
5491       AND  qpih.currency_header is NULL
5492       AND NOT EXISTS ( SELECT qpclb.currency_header_id
5493 		       FROM   qp_currency_lists_b qpclb
5494 		       WHERE  qpclb.currency_header_id = qpih.currency_header_id
5495                        AND    qpclb.base_currency_code = qpih.currency_code);
5496 -- Bug 4938046,5412029 END RAVI
5497 
5498   -- 7. Name
5499 
5500 fnd_message.set_name('QP', 'QP_ATTRIBUTE_REQUIRED');
5501 FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'NAME');
5502 l_msg_txt := FND_MESSAGE.GET;
5503 
5504 INSERT INTO QP_INTERFACE_ERRORS
5505    (error_id,last_update_date, last_updated_by, creation_date,
5506     created_by, last_update_login, request_id, program_application_id,
5507     program_id, program_update_date, entity_type, table_name, column_name,
5508     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5509     orig_sys_pricing_attr_ref,  error_message)
5510     SELECT
5511      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5512      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5513      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'Name',
5514      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5515     FROM QP_INTERFACE_LIST_HEADERS qpih
5516     WHERE qpih.request_id = p_request_id
5517       AND  qpih.process_status_flag ='P' --is null
5518 --      AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5519       AND  qpih.interface_action_code IN ('INSERT')
5520       AND  (name is null or name = '');
5521 
5522   -- 8. Name in other pricelists
5523 
5524 fnd_message.set_name('QP', 'SO_OTHER_NAME_ALREADY_IN_USE');
5525 l_msg_txt := FND_MESSAGE.GET;
5526 
5527  qp_bulk_loader_pub.write_log('Name check in TL table '||userenv('LANG')||' '||to_char(p_request_id));
5528 
5529 INSERT INTO QP_INTERFACE_ERRORS
5530    (error_id,last_update_date, last_updated_by, creation_date,
5531     created_by, last_update_login, request_id, program_application_id,
5532     program_id, program_update_date, entity_type, table_name, column_name,
5533     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5534     orig_sys_pricing_attr_ref,  error_message)
5535     SELECT
5536      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5537      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5538      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'Name',
5539      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5540     FROM QP_INTERFACE_LIST_HEADERS qpih
5541     WHERE qpih.request_id = p_request_id
5542       AND  qpih.process_status_flag ='P' --is null
5543       AND  qpih.interface_action_code IN ('INSERT')
5544       AND EXISTS ( Select qlht.name from qp_list_headers_tl qlht
5545 	     	   where qlht.name= qpih.name
5546 	           and qlht.language = qpih.language);
5547 
5548  qp_bulk_loader_pub.write_log('Count '||SQL%ROWCOUNT);
5549 
5550   -- 9. Name in other Interface header records
5551 
5552 fnd_message.set_name('QP', 'SO_OTHER_NAME_ALREADY_IN_USE');
5553 l_msg_txt := FND_MESSAGE.GET;
5554 
5555 INSERT INTO QP_INTERFACE_ERRORS
5556    (error_id,last_update_date, last_updated_by, creation_date,
5557     created_by, last_update_login, request_id, program_application_id,
5558     program_id, program_update_date, entity_type, table_name, column_name,
5559     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5560     orig_sys_pricing_attr_ref,  error_message)
5561     SELECT
5562      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5563      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5564      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'Name',
5565      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5566     FROM QP_INTERFACE_LIST_HEADERS qpih
5567     WHERE qpih.request_id = p_request_id
5568       AND  qpih.process_status_flag ='P' --is null
5569       AND  qpih.interface_action_code IN ('INSERT')
5570       AND EXISTS ( Select 'x' from qp_interface_list_headers qpih1
5571 		  where qpih1.request_id = p_request_id
5572 		    and qpih1.name = qpih.name
5573 		    and qpih1.process_status_flag is null
5574 		    and qpih1.rowid <> qpih.rowid
5575 		    and qpih1.interface_action_code = 'INSERT');
5576  qp_bulk_loader_pub.write_log('Count 9 '||SQL%ROWCOUNT);
5577 
5578   -- 10. Pricing Transaction Entity
5579 
5580 FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
5581 FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Pricing Transaction Entity');
5582 l_msg_txt := FND_MESSAGE.GET;
5583 
5584 INSERT INTO QP_INTERFACE_ERRORS
5585    (error_id,last_update_date, last_updated_by, creation_date,
5586     created_by, last_update_login, request_id, program_application_id,
5587     program_id, program_update_date, entity_type, table_name, column_name,
5588     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5589     orig_sys_pricing_attr_ref,  error_message)
5590     SELECT
5591      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5592      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5593      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'pte_code',
5594      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5595     FROM QP_INTERFACE_LIST_HEADERS qpih
5596     WHERE qpih.request_id = p_request_id
5597       AND  qpih.process_status_flag ='P' --is null
5598       AND   qpih.interface_action_code IN ('INSERT', 'UPDATE')
5599       AND   qpih.pte_code IS NOT NULL
5600       AND   NOT EXISTS (SELECT lookup_code
5601      		      FROM qp_lookups
5602      	      	      WHERE lookup_type = 'QP_PTE_TYPE'
5603      		      AND  lookup_code   = qpih.pte_code);
5604 
5605   -- 11. Source System Code
5606 
5607 FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
5608 FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Source System Code');
5609 l_msg_txt := FND_MESSAGE.GET;
5610 
5611 INSERT INTO QP_INTERFACE_ERRORS
5612    (error_id,last_update_date, last_updated_by, creation_date,
5613     created_by, last_update_login, request_id, program_application_id,
5614     program_id, program_update_date, entity_type, table_name, column_name,
5615     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5616     orig_sys_pricing_attr_ref,  error_message)
5617     SELECT
5618      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5619      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5620      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'Name',
5621      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5622     FROM QP_INTERFACE_LIST_HEADERS qpih
5623     WHERE qpih.request_id = p_request_id
5624       AND  qpih.process_status_flag ='P' --is null
5625       AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5626       AND   qpih.source_system_code IS NOT NULL
5627       AND   NOT EXISTS (SELECT lookup_code
5628      		      FROM qp_lookups
5629      	      	      WHERE lookup_type = 'SOURCE_SYSTEM'
5630      		      AND  lookup_code   = qpih.source_system_code);
5631 
5632 -- Bug 5208365 RAVI
5633 INSERT INTO QP_INTERFACE_ERRORS
5634    (error_id,last_update_date, last_updated_by, creation_date,
5635     created_by, last_update_login, request_id, program_application_id,
5636     program_id, program_update_date, entity_type, table_name, column_name,
5637     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5638     orig_sys_pricing_attr_ref,  error_message)
5639     SELECT
5640      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5641      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5642      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'Name',
5643      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5644     FROM QP_INTERFACE_LIST_HEADERS qpih
5645     WHERE qpih.request_id = p_request_id
5646       AND  qpih.process_status_flag ='P' --is null
5647       AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5648       -- Bug 5416556 RAVI
5649       --Only Price Lists with source system code equal to FND_PROFILE.VALUE('QP_SOURCE_SYSTEM_CODE') should be updated.
5650       AND   qpih.source_system_code <> FND_PROFILE.VALUE('QP_SOURCE_SYSTEM_CODE');
5651 
5652 --for bug 4731613 moved this validation to attribute_header procedure
5653   -- 12. Validate Orig_Org_Id
5654 
5655 FND_MESSAGE.SET_NAME('FND','FND_MO_ORG_INVALID');
5656 --FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'Source System Code');
5657 l_msg_txt := FND_MESSAGE.GET;
5658 
5659 INSERT INTO QP_INTERFACE_ERRORS
5660    (error_id,last_update_date, last_updated_by, creation_date,
5661     created_by, last_update_login, request_id, program_application_id,
5662     program_id, program_update_date, entity_type, table_name, column_name,
5663     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5664     orig_sys_pricing_attr_ref,  error_message)
5665     SELECT
5666      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5667      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5668      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'Name',
5669      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5670     FROM QP_INTERFACE_LIST_HEADERS qpih
5671     WHERE qpih.request_id = p_request_id
5672       AND  qpih.process_status_flag ='P' --is null
5673       AND  qpih.interface_action_code IN ('INSERT', 'UPDATE')
5674       AND   qpih.global_flag = 'N' and qpih.orig_org_id IS NOT NULL
5675       AND   QP_UTIL.validate_org_id(qpih.orig_org_id) = 'N';
5676 
5677   --Bug#5208112 RAVI START
5678   -- 13. Validate Rounding Factor
5679 
5680   FND_MESSAGE.SET_NAME('QP','QP_ROUNDING_FACTOR_NO_UPDATE');
5681   l_msg_txt := FND_MESSAGE.GET;
5682 
5683   INSERT INTO QP_INTERFACE_ERRORS
5684    (error_id,last_update_date, last_updated_by, creation_date,
5685     created_by, last_update_login, request_id, program_application_id,
5686     program_id, program_update_date, entity_type, table_name, column_name,
5687     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5688     orig_sys_pricing_attr_ref,  error_message)
5689     SELECT
5690      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5691      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5692      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'ROUNDING_FACTOR',
5693      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5694     FROM QP_INTERFACE_LIST_HEADERS qpih
5695     WHERE qpih.request_id = p_request_id
5696       AND qpih.process_status_flag ='P' --is null
5697       AND qpih.interface_action_code ='UPDATE'
5698       AND EXISTS(
5699             select 1 from qp_list_headers qplh
5700             where qplh.orig_system_header_ref=qpih.orig_sys_header_ref
5701             and qplh.rounding_factor <> qpih.rounding_factor
5702             );
5703   --Bug#5208112 RAVI END
5704 
5705   -- Bug#3604226 RAVI START
5706 
5707   -- 14. Only one record with a unique Orig_Sys_Hdr_ref must be updated in one request
5708   -- Commenting code for bug 6961376
5709 
5710   /*fnd_message.set_name('QP', 'QP_HDR_REF_MULTIPLE_UPDATE');
5711   l_msg_txt := FND_MESSAGE.GET;
5712 
5713   INSERT INTO QP_INTERFACE_ERRORS
5714    (error_id,last_update_date, last_updated_by, creation_date,
5715     created_by, last_update_login, request_id, program_application_id,
5716     program_id, program_update_date, entity_type, table_name, column_name,
5717     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5718     orig_sys_pricing_attr_ref,  error_message)
5719     SELECT
5720      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5721      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpih.request_id, 661,
5722      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_HEADERS',  'ORIG_SYS_HEADER_REF',
5723      qpih.orig_sys_header_ref,null,null,null,l_msg_txt
5724     FROM QP_INTERFACE_LIST_HEADERS qpih
5725     WHERE qpih.request_id = p_request_id
5726       AND qpih.process_status_flag ='P' --is null
5727       AND qpih.interface_action_code IN ('UPDATE', 'DELETE')
5728       AND ( select count(*) from qp_interface_list_headers qplh
5729             where qplh.orig_sys_header_ref=qpih.orig_sys_header_ref
5730             ) > 1;*/
5731   --Bug#3604226 RAVI END
5732 
5733 
5734  qp_bulk_loader_pub.write_log('Leaving Attribute Header validation');
5735 
5736  EXCEPTION
5737     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5738        qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE ATTRIBUTE_HEADER:'||sqlerrm);
5739        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5740     WHEN OTHERS THEN
5741        qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE ATTRIBUTE_HEADER:'||sqlerrm);
5742        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5743 
5744 END ATTRIBUTE_HEADER;
5745 
5746 
5747 
5748 PROCEDURE ATTRIBUTE_QUALIFIER
5749                (p_request_id NUMBER)
5750 IS
5751 
5752    l_msg_txt VARCHAR2(240);
5753    l_pte_code VARCHAR2(30);
5754 
5755 BEGIN
5756 
5757     qp_bulk_loader_pub.write_log('Entering Attribute qualifier validation');
5758     FND_PROFILE.GET('QP_PRICING_TRANSACTION_ENTITY',l_pte_code);
5759     --1. Comparison Operator
5760 
5761    FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
5762    FND_MESSAGE.SET_TOKEN('ATTRIBUTE','COMPARISON OPERATOR');
5763    l_msg_txt := FND_MESSAGE.GET;
5764 
5765     INSERT INTO QP_INTERFACE_ERRORS
5766    (error_id,last_update_date, last_updated_by, creation_date,
5767     created_by, last_update_login, request_id, program_application_id,
5768     program_id, program_update_date, entity_type, table_name, column_name,
5769     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5770     orig_sys_pricing_attr_ref,  error_message)
5771     SELECT
5772      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5773      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpiq.request_id, 661,
5774      NULL,NULL, 'PRL', 'QP_INTERFACE_QUALIFIERS',  'COMPARISON_OPERATOR',
5775      qpiq.orig_sys_header_ref,null,qpiq.orig_sys_qualifier_ref,null, l_msg_txt
5776     FROM QP_INTERFACE_QUALIFIERS qpiq
5777     WHERE qpiq.request_id = p_request_id
5778       AND  qpiq.process_status_flag ='P' --is null
5779       AND  qpiq.interface_action_code IN ('INSERT', 'UPDATE')
5780       AND  qpiq.comparison_operator_code is NOT NULL
5781       AND NOT EXISTS ( SELECT  lookup_code
5782 		       FROM     qp_lookups
5783 		       WHERE lookup_type = 'COMPARISON_OPERATOR'
5784 	               AND    lookup_code   = qpiq.comparison_operator_code);
5785 
5786    --2. Orig sys header ref
5787 
5788    FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
5789    FND_MESSAGE.SET_TOKEN('ATTRIBUTE','ORIG SYS HEADER REF');
5790    l_msg_txt := FND_MESSAGE.GET;
5791 
5792     INSERT INTO QP_INTERFACE_ERRORS
5793    (error_id,last_update_date, last_updated_by, creation_date,
5794     created_by, last_update_login, request_id, program_application_id,
5795     program_id, program_update_date, entity_type, table_name, column_name,
5796     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5797     orig_sys_pricing_attr_ref,error_message)
5798     SELECT
5799      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5800      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpiq.request_id, 661,
5801      NULL,NULL, 'PRL', 'QP_INTERFACE_QUALIFIERS',  'ORIG_SYS_HEADER_REF',
5802      qpiq.orig_sys_header_ref,null,qpiq.orig_sys_qualifier_ref,null,l_msg_txt
5803     FROM QP_INTERFACE_QUALIFIERS qpiq
5804     WHERE qpiq.request_id = p_request_id
5805       AND  qpiq.process_status_flag ='P' --is null
5806       AND  qpiq.interface_action_code IN ('INSERT', 'UPDATE')
5807       AND  qpiq.orig_sys_header_ref is NOT NULL
5808       AND NOT EXISTS ( SELECT  orig_system_header_ref
5809 		       FROM     qp_list_headers_b
5810 		       WHERE  orig_system_header_ref = qpiq.orig_sys_header_ref);
5811 
5812     --3. Secondary Pricelist
5813 
5814 -- Basic_Pricing_Condition
5815    -- In the case of Basic pricing only the qualifier of type secondary
5816    -- Pricelists are allowed.
5817 
5818    IF QP_BULK_LOADER_PUB.GET_QP_STATUS <> 'I' THEN
5819 
5820        FND_MESSAGE.SET_NAME('QP','QP_QUAL_NA_BASIC');
5821        --Qualifiers not allowed in Basic Pricing
5822        l_msg_txt := FND_MESSAGE.GET;
5823 
5824 	INSERT INTO QP_INTERFACE_ERRORS
5825        (error_id,last_update_date, last_updated_by, creation_date,
5826 	created_by, last_update_login, request_id, program_application_id,
5827 	program_id, program_update_date, entity_type, table_name,
5828 	orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5829 	orig_sys_pricing_attr_ref,  error_message)
5830 	SELECT
5831 	 qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5832 	 FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpiq.request_id, 661,
5833 	 NULL,NULL, 'PRL', 'QP_INTERFACE_QUALIFIERS',
5834 	 qpiq.orig_sys_header_ref,null,qpiq.orig_sys_qualifier_ref,null, l_msg_txt
5835 	FROM QP_INTERFACE_QUALIFIERS qpiq
5836 	WHERE qpiq.request_id = p_request_id
5837 	  AND  qpiq.process_status_flag ='P' --is null
5838 	  AND  qpiq.interface_action_code IN ('INSERT', 'UPDATE')
5839 	  AND  (qpiq.qualifier_context <> 'MODLIST'
5840 	    OR qpiq.qualifier_attribute <> 'QUALIFIER_ATTRIBUTE4');
5841 
5842   END IF;
5843 
5844    --4. Qualifier Context
5845        FND_MESSAGE.SET_NAME('QP','QP_ATTRIBUTE_REQUIRED');
5846        FND_MESSAGE.SET_TOKEN('ATTRIBUTE', 'QUALIFIER CONTEXT');
5847 
5848        l_msg_txt := FND_MESSAGE.GET;
5849 
5850 	INSERT INTO QP_INTERFACE_ERRORS
5851        (error_id,last_update_date, last_updated_by, creation_date,
5852 	created_by, last_update_login, request_id, program_application_id,
5853 	program_id, program_update_date, entity_type, table_name,
5854 	orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5855 	orig_sys_pricing_attr_ref,  error_message)
5856 	SELECT
5857 	 qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5858 	 FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpiq.request_id, 661,
5859 	 NULL,NULL, 'PRL', 'QP_INTERFACE_QUALIFIERS',
5860 	 qpiq.orig_sys_header_ref,null,qpiq.orig_sys_qualifier_ref,null, l_msg_txt
5861 	FROM QP_INTERFACE_QUALIFIERS qpiq
5862 	WHERE qpiq.request_id = p_request_id
5863 	  AND  qpiq.process_status_flag ='P' --is null
5864 	  AND  qpiq.interface_action_code IN ('INSERT', 'UPDATE')
5865 	  AND  qpiq.qualifier_context IS NULL;
5866 
5867    --5. Qualifier Attribute
5868 
5869    FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
5870    FND_MESSAGE.SET_TOKEN('ATTRIBUTE','QUALIFIER ATTRIBUTE');
5871    l_msg_txt := FND_MESSAGE.GET;
5872 
5873 --Bug# 5456164 START RAVI
5874 --Validate qualifier attribute
5875     INSERT INTO QP_INTERFACE_ERRORS
5876    (error_id,last_update_date, last_updated_by, creation_date,
5877     created_by, last_update_login, request_id, program_application_id,
5878     program_id, program_update_date, entity_type, table_name, column_name,
5879     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5880     orig_sys_pricing_attr_ref,error_message)
5881     SELECT
5882      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5883      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpiq.request_id, 661,
5884      NULL,NULL, 'PRL', 'QP_INTERFACE_QUALIFIERS',  'QUALIFIER_ATTRIBUTE',
5885      qpiq.orig_sys_header_ref,null,qpiq.orig_sys_qualifier_ref,null,l_msg_txt
5886     FROM QP_INTERFACE_QUALIFIERS qpiq
5887     WHERE qpiq.request_id = p_request_id
5888       AND  qpiq.process_status_flag ='P' --is null
5889       AND  qpiq.interface_action_code IN ('INSERT', 'UPDATE')
5890       AND  qpiq.qualifier_attribute is not null
5891       AND  qpiq.qualifier_attribute_code is not null
5892       AND  qpiq.qualifier_attribute_code <> QP_BULK_LOADER_PUB.G_NULL_CHAR
5893       AND NOT EXISTS (
5894         SELECT  'x'
5895         FROM    qp_interface_qualifiers b,
5896                 qp_prc_contexts_b d,
5897                 qp_segments_b e,
5898                 qp_pte_segments f
5899         WHERE b.qualifier_context = d.prc_context_code
5900 	  AND b.qualifier_attribute = e.segment_mapping_column
5901           and e.segment_code = b.qualifier_attribute_code
5902 	  AND d.prc_context_id = e.prc_context_id
5903           AND d.prc_context_type = 'QUALIFIER'
5904 	  AND e.segment_id = f.segment_id
5905 	  AND f.pte_code = l_pte_code
5906 	  AND f.segment_level NOT IN ('LINE')
5907 	  AND qpiq.rowid = b.rowid);
5908 
5909     INSERT INTO QP_INTERFACE_ERRORS
5910    (error_id,last_update_date, last_updated_by, creation_date,
5911     created_by, last_update_login, request_id, program_application_id,
5912     program_id, program_update_date, entity_type, table_name, column_name,
5913     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5914     orig_sys_pricing_attr_ref,error_message)
5915     SELECT
5916      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5917      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpiq.request_id, 661,
5918      NULL,NULL, 'PRL', 'QP_INTERFACE_QUALIFIERS',  'QUALIFIER_ATTRIBUTE',
5919      qpiq.orig_sys_header_ref,null,qpiq.orig_sys_qualifier_ref,null,l_msg_txt
5920     FROM QP_INTERFACE_QUALIFIERS qpiq
5921     WHERE qpiq.request_id = p_request_id
5922       AND  qpiq.process_status_flag ='P' --is null
5923       AND  qpiq.interface_action_code IN ('INSERT', 'UPDATE')
5924       AND  qpiq.qualifier_attribute is null
5925       AND  qpiq.qualifier_attribute_code is not null
5926       AND  qpiq.qualifier_attribute_code <> QP_BULK_LOADER_PUB.G_NULL_CHAR
5927       AND NOT EXISTS (
5928         SELECT  'x'
5929         FROM    qp_interface_qualifiers b,
5930                 qp_prc_contexts_b d,
5931                 qp_segments_b e,
5932                 qp_pte_segments f
5933         WHERE  b.qualifier_context = d.prc_context_code
5934            and e.segment_code = b.qualifier_attribute_code
5935 	   AND d.prc_context_id = e.prc_context_id
5936            AND d.prc_context_type = 'QUALIFIER'
5937 	   AND e.segment_id = f.segment_id
5938 	   AND f.pte_code = l_pte_code
5939 	   AND f.segment_level NOT IN ('LINE')
5940 	   AND qpiq.rowid = b.rowid);
5941 
5942     INSERT INTO QP_INTERFACE_ERRORS
5943    (error_id,last_update_date, last_updated_by, creation_date,
5944     created_by, last_update_login, request_id, program_application_id,
5945     program_id, program_update_date, entity_type, table_name, column_name,
5946     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
5947     orig_sys_pricing_attr_ref,error_message)
5948     SELECT
5949      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
5950      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpiq.request_id, 661,
5951      NULL,NULL, 'PRL', 'QP_INTERFACE_QUALIFIERS',  'QUALIFIER_ATTRIBUTE',
5952      qpiq.orig_sys_header_ref,null,qpiq.orig_sys_qualifier_ref,null,l_msg_txt
5953     FROM QP_INTERFACE_QUALIFIERS qpiq
5954     WHERE qpiq.request_id = p_request_id
5955       AND  qpiq.process_status_flag ='P' --is null
5956       AND  qpiq.interface_action_code IN ('INSERT', 'UPDATE')
5957       AND  qpiq.qualifier_attribute is not null
5958       AND  qpiq.qualifier_attribute_code is null
5959       AND NOT EXISTS (
5960         SELECT  'x'
5961         FROM    qp_interface_qualifiers b,
5962                 qp_prc_contexts_b d,
5963                 qp_segments_b e,
5964                 qp_pte_segments f
5965         WHERE b.qualifier_context = d.prc_context_code
5966 	  AND b.qualifier_attribute = e.segment_mapping_column
5967 	  AND d.prc_context_id = e.prc_context_id
5968           AND d.prc_context_type = 'QUALIFIER'
5969 	  AND e.segment_id = f.segment_id
5970 	  AND f.pte_code = l_pte_code
5971 	  AND f.segment_level NOT IN ('LINE')
5972 	  AND qpiq.rowid = b.rowid);
5973 --Bug# 5456164 END RAVI
5974 
5975    qp_bulk_loader_pub.write_log('Leaving Attribute qualifier validation');
5976 
5977 EXCEPTION
5978     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5979        qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE ATTRIBUTE_QUALIFIER:'||sqlerrm);
5980        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5981     WHEN OTHERS THEN
5982        qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE ATTRIBUTE_QUALIFIER:'||sqlerrm);
5983        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5984 
5985 END ATTRIBUTE_QUALIFIER;
5986 
5987 
5988 -- Bug# 5412045
5989 -- Shell for qp_validate.product_uom to return Varchar2 ('TRUE', 'FALSE')
5990 -- qp_validate.product_uom returns a boolean.
5991 Function product_uom ( p_product_uom_code IN VARCHAR2,
5992                        p_category_id IN NUMBER,
5993                        p_list_header_id IN NUMBER )
5994 RETURN VARCHAR2 IS
5995 BEGIN
5996    IF QP_Validate.product_uom(p_product_uom_code,p_category_id,p_list_header_id)=TRUE
5997    THEN
5998       RETURN 'TRUE';
5999    ELSE
6000       RETURN 'FALSE';
6001    END IF;
6002 EXCEPTION
6003   When OTHERS THEN
6004      RETURN 'FALSE';
6005 END product_uom;
6006 
6007 
6008 PROCEDURE ATTRIBUTE_LINE
6009                (p_request_id NUMBER)
6010 IS
6011 
6012    l_msg_txt  VARCHAR2(240);
6013    l_pte_code VARCHAR2(30);
6014 
6015    BEGIN
6016 
6017     qp_bulk_loader_pub.write_log('Entering Attribute line validation');
6018     FND_PROFILE.GET('QP_PRICING_TRANSACTION_ENTITY',l_pte_code);
6019 
6020     -- 1. LIST LINE TYPE CODE
6021    FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
6022    FND_MESSAGE.SET_TOKEN('ATTRIBUTE','LIST_LINE_TYPE_CODE');
6023    l_msg_txt := FND_MESSAGE.GET;
6024 
6025     INSERT INTO QP_INTERFACE_ERRORS
6026    (error_id,last_update_date, last_updated_by, creation_date,
6027     created_by, last_update_login, request_id, program_application_id,
6028     program_id, program_update_date, entity_type, table_name, column_name,
6029     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6030     orig_sys_pricing_attr_ref,error_message)
6031     SELECT
6032      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6033      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6034      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'LIST_LINE_TYPE_CODE',
6035      qpil.orig_sys_header_ref,qpil.orig_sys_line_ref,null,null, l_msg_txt
6036     FROM QP_INTERFACE_LIST_LINES qpil
6037     WHERE qpil.request_id = p_request_id
6038       AND  qpil.process_status_flag ='P' --is null
6039       AND  qpil.interface_action_code IN ('INSERT', 'UPDATE')
6040       AND  qpil.list_line_type_code is NOT NULL
6041       AND NOT EXISTS ( SELECT  lookup_code
6042 		       FROM     qp_lookups
6043 		       WHERE  lookup_type= 'LIST_LINE_TYPE_CODE'
6044                        AND        lookup_code= qpil.list_line_type_code
6045                        AND        qpil.list_line_type_code IN ('PLL', 'PBH') );
6046 
6047   -- 2. ARITHMETIC OPERATOR
6048    FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
6049    FND_MESSAGE.SET_TOKEN('ATTRIBUTE','ARITHMETIC_OPERATOR 5');
6050    l_msg_txt := FND_MESSAGE.GET;
6051 
6052     INSERT INTO QP_INTERFACE_ERRORS
6053    (error_id,last_update_date, last_updated_by, creation_date,
6054     created_by, last_update_login, request_id, program_application_id,
6055     program_id, program_update_date, entity_type, table_name, column_name,
6056     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6057     orig_sys_pricing_attr_ref,error_message)
6058     SELECT
6059      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6060      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6061      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'ARITHMETIC_OPERATOR',
6062      qpil.orig_sys_header_ref,qpil.orig_sys_line_ref,null,null,l_msg_txt
6063     FROM QP_INTERFACE_LIST_LINES qpil
6064     WHERE qpil.request_id = p_request_id
6065       AND  qpil.process_status_flag ='P' --is null
6066       AND  qpil.interface_action_code IN ('INSERT', 'UPDATE')
6067       AND  qpil.arithmetic_operator is NOT NULL
6068       AND NOT EXISTS ( SELECT  meaning
6069 		       FROM     qp_lookups
6070 		       WHERE  lookup_type= 'ARITHMETIC_OPERATOR'
6071                        AND        lookup_code= qpil.arithmetic_operator );
6072 
6073    --3. PRICE BREAK TYPE CODE
6074    FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
6075    FND_MESSAGE.SET_TOKEN('ATTRIBUTE','PRICE_BREAK_TYPE_CODE');
6076    l_msg_txt := FND_MESSAGE.GET;
6077 
6078     INSERT INTO QP_INTERFACE_ERRORS
6079    (error_id,last_update_date, last_updated_by, creation_date,
6080     created_by, last_update_login, request_id, program_application_id,
6081     program_id, program_update_date, entity_type, table_name, column_name,
6082     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6083     orig_sys_pricing_attr_ref,error_message)
6084     SELECT
6085      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6086      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6087      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'PRICE_BREAK_TYPE_CODE',
6088      qpil.orig_sys_header_ref,qpil.orig_sys_line_ref,null,null,l_msg_txt
6089     FROM QP_INTERFACE_LIST_LINES qpil
6090     WHERE qpil.request_id = p_request_id
6091       AND  qpil.process_status_flag ='P' --is null
6092       AND  qpil.interface_action_code IN ('INSERT', 'UPDATE')
6093       AND  qpil.price_break_type_code is NOT NULL
6094       AND NOT EXISTS ( SELECT     meaning
6095 		       FROM     qp_lookups
6096 		       WHERE  lookup_type= 'PRICE_BREAK_TYPE_CODE'
6097                        AND        lookup_code= qpil.price_break_type_code);
6098 
6099   --4. UOM
6100    FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
6101    FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Product Uom Code');
6102    l_msg_txt := FND_MESSAGE.GET;
6103 
6104 	-- Bug# 5412045
6105 	-- Validate UOM for a category line
6106     INSERT INTO QP_INTERFACE_ERRORS
6107    (error_id,last_update_date, last_updated_by, creation_date,
6108     created_by, last_update_login, request_id, program_application_id,
6109     program_id, program_update_date, entity_type, table_name, column_name,
6110     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6111     orig_sys_pricing_attr_ref,error_message)
6112     SELECT /*+ index(qpip QP_INTERFACE_PRCNG_ATTRIBS_N4) */
6113      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6114      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6115      NULL,NULL, 'PRL', 'QP_INTERFACE_PRICING_ATTRIBS',  'PRODUCT_UOM_CODE',
6116      qpip.orig_sys_header_ref,qpip.orig_sys_line_ref,null,
6117      qpip.orig_sys_pricing_attr_ref,  l_msg_txt
6118     FROM QP_INTERFACE_LIST_LINES qpil, QP_INTERFACE_PRICING_ATTRIBS qpip, QP_LIST_HEADERS_B qplh
6119     WHERE qpil.request_id = p_request_id
6120       AND  qpip.request_id = p_request_id -- bug no 5881528
6121       AND  qpil.process_status_flag ='P' --is null
6122       AND  qpil.orig_sys_line_ref = qpip.orig_sys_line_ref
6123       -- ENH unod alcoa changes RAVI
6124       /**
6125       The key between interface and qp tables is only orig_sys_hdr_ref
6126       (not list_header_id)
6127       **/
6128       AND  qpil.orig_sys_header_ref = qplh.orig_system_header_ref
6129       AND  qpip.pricing_attribute_context IS NULL
6130       AND  qpil.interface_action_code IN ('INSERT', 'UPDATE')
6131       AND  qpip.interface_action_code IN ('INSERT', 'UPDATE')
6132       AND  qpip.product_uom_code is NOT NULL
6133       and qpip.product_attribute_context = 'ITEM'
6134       and qpip.product_attribute = 'PRICING_ATTRIBUTE1'
6135       AND NOT EXISTS (
6136 	select uom_code
6137 	from mtl_item_uoms_view
6138 	where organization_id = nvl(qpil.organization_id, organization_id)
6139 	and inventory_item_id = to_number(qpip.product_attr_value)
6140 	and uom_code = qpip.product_uom_code
6141         -- commented out for bug 4713401
6142         /*
6143 	union
6144 	select uom_code
6145 	from mtl_item_uoms_view
6146 	where (organization_id = qpil.organization_id or qpil.organization_id is null)
6147 	and inventory_item_id in ( select inventory_item_id
6148 	from mtl_item_categories
6149 	where category_id =      to_number(qpip.product_attr_value)
6150 	and (organization_id = qpil.organization_id or qpil.organization_id is null ))
6151 	and qpip.product_attribute_context = 'ITEM'
6152 	and qpip.product_attribute = 'PRICING_ATTRIBUTE2'
6153 	and uom_code = qpip.product_uom_code
6154         */
6155 	-- added for bug 4713401
6156         /* commented out as this code is not performant
6157 	union
6158 	select uom_code
6159 	from mtl_item_uoms_view
6160 	where (organization_id = qpil.organization_id or qpil.organization_id is null) and
6161         qpip.product_attribute_context = 'ITEM' and
6162         qpip.product_attribute = 'PRICING_ATTRIBUTE2' and
6163 	uom_code = qpip.product_uom_code and
6164         inventory_item_id in ( select inventory_item_id
6165         	                     from mtl_item_categories cat
6166 	                             where (category_id = to_number(qpip.product_attr_value) or
6167 				            exists (SELECT 'Y'
6168 					      FROM   eni_denorm_hierarchies
6169 					      WHERE  parent_id = to_number(qpip.product_attr_value) and
6170 					             child_id = cat.category_id
6171 					             and exists (select 'Y' from QP_SOURCESYSTEM_FNAREA_MAP A,
6172 										 qp_pte_source_systems B ,
6173 										 mtl_default_category_sets c,
6174 										 mtl_category_sets d
6175 					                         where A.PTE_SOURCE_SYSTEM_ID = B.PTE_SOURCE_SYSTEM_ID and
6176 					                               B.PTE_CODE = qplh.pte_code and
6177 					                               B.APPLICATION_SHORT_NAME = qplh.source_system_code and
6178 					                               A.FUNCTIONAL_AREA_ID = c.FUNCTIONAL_AREA_ID and
6179 					                               c.CATEGORY_SET_ID = d.CATEGORY_SET_ID and
6180 					                               d.HIERARCHY_ENABLED = 'Y' and
6181 					                               A.ENABLED_FLAG = 'Y' and B.ENABLED_FLAG = 'Y'))))
6182         */
6183 	union
6184 	select  uom_code
6185 	from mtl_units_of_measure_vl
6186 	where uom_code = qpip.product_uom_code
6187 	);
6188 
6189 
6190 	-- Bug# 5412045
6191 	-- Validate UOM for a category line
6192     INSERT INTO QP_INTERFACE_ERRORS
6193    (error_id,last_update_date, last_updated_by, creation_date,
6194     created_by, last_update_login, request_id, program_application_id,
6195     program_id, program_update_date, entity_type, table_name, column_name,
6196     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6197     orig_sys_pricing_attr_ref,error_message)
6198     SELECT
6199      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6200      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6201      NULL,NULL, 'PRL', 'QP_INTERFACE_PRICING_ATTRIBS',  'PRODUCT_UOM_CODE',
6202      qpip.orig_sys_header_ref,qpip.orig_sys_line_ref,null,
6203      qpip.orig_sys_pricing_attr_ref,  l_msg_txt
6204     FROM QP_INTERFACE_LIST_LINES qpil, QP_INTERFACE_PRICING_ATTRIBS qpip, QP_LIST_HEADERS_B qplh
6205     WHERE qpil.request_id = p_request_id
6206       AND  qpip.request_id = p_request_id -- bug no 5881528
6207       AND  qpil.process_status_flag ='P' --is null
6208       AND  qpil.orig_sys_line_ref = qpip.orig_sys_line_ref
6209       AND  qpil.orig_sys_header_ref = qplh.orig_system_header_ref
6210       AND  qpip.pricing_attribute_context IS NULL
6211       AND  qpil.interface_action_code IN ('INSERT', 'UPDATE')
6212       AND  qpip.interface_action_code IN ('INSERT', 'UPDATE')
6213       AND  qpip.product_uom_code is NOT NULL
6214       and qpip.product_attribute_context = 'ITEM'
6215       and qpip.product_attribute = 'PRICING_ATTRIBUTE2'
6216       AND NOT EXISTS (
6217         select 'EXISTS'
6218         from dual
6219         where QP_BULK_VALIDATE.product_uom(
6220                 qpip.product_uom_code,
6221                 to_number(qpip.product_attr_value),
6222                 qplh.list_header_id) = 'TRUE'
6223       );
6224 
6225 
6226  /**
6227   Bug# 5465109 RAVI START
6228   4.1) UNIQUE FORMULA CHECK
6229   Only one formula should be inserted or updated in a line. Either PriceBy or Generate Formula is to be used.
6230   If one is used the other should be set to null. If both are used then an error should be thrown.
6231  **/
6232    FND_MESSAGE.SET_NAME('QP','QP_STATIC_OR_DYNAMIC_FORMULA');
6233    l_msg_txt := FND_MESSAGE.GET;
6234 
6235     INSERT INTO QP_INTERFACE_ERRORS
6236    (error_id,last_update_date, last_updated_by, creation_date,
6237     created_by, last_update_login, request_id, program_application_id,
6238     program_id, program_update_date, entity_type, table_name, column_name,
6239     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6240     orig_sys_pricing_attr_ref,error_message)
6241     SELECT
6242      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6243      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6244      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'PRICE_BY_AND_GENERATE_FORMULA_ID',
6245      qpil.orig_sys_header_ref,qpil.orig_sys_line_ref,null,null,l_msg_txt
6246     FROM QP_INTERFACE_LIST_LINES qpil
6247     WHERE qpil.request_id = p_request_id
6248       AND  qpil.process_status_flag ='P' --is null
6249       AND  qpil.interface_action_code IN ('INSERT', 'UPDATE')
6250       AND  qpil.price_by_formula_id is NOT NULL
6251       AND  qpil.price_by_formula_id <> QP_BULK_LOADER_PUB.G_NULL_NUMBER
6252       AND  qpil.generate_using_formula_id is NOT NULL
6253       AND  qpil.generate_using_formula_id <> QP_BULK_LOADER_PUB.G_NULL_NUMBER;
6254   --Bug# 5465109 RAVI END
6255 
6256 --5. PRICE BY FORMULA ID
6257 
6258    -- Bug# 5236656 RAVI
6259    -- Change the message that needs to be thrown.
6260 
6261    FND_MESSAGE.SET_NAME('QP','QP_PRC_FOR_NAME_ID_INCMPTBLE');
6262    l_msg_txt := FND_MESSAGE.GET;
6263 
6264     INSERT INTO QP_INTERFACE_ERRORS
6265    (error_id,last_update_date, last_updated_by, creation_date,
6266     created_by, last_update_login, request_id, program_application_id,
6267     program_id, program_update_date, entity_type, table_name, column_name,
6268     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6269     orig_sys_pricing_attr_ref,error_message)
6270     SELECT
6271      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6272      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6273      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'PRICE_BY_FORMULA_ID',
6274      qpil.orig_sys_header_ref,qpil.orig_sys_line_ref,null,null,l_msg_txt
6275     FROM QP_INTERFACE_LIST_LINES qpil
6276     WHERE qpil.request_id = p_request_id
6277       AND  qpil.process_status_flag ='P' --is null
6278       AND  qpil.interface_action_code IN ('INSERT', 'UPDATE')
6279       AND  qpil.price_by_formula_id is NOT NULL
6280       AND  qpil.price_by_formula is NOT NULL
6281       AND  qpil.price_by_formula <> QP_BULK_LOADER_PUB.G_NULL_CHAR
6282       AND NOT EXISTS ( SELECT  name
6283 		       FROM    qp_price_formulas_vl
6284 		       WHERE   price_formula_id = qpil.price_by_formula_id
6285 		       AND     name = qpil.price_by_formula);
6286 
6287     INSERT INTO QP_INTERFACE_ERRORS
6288    (error_id,last_update_date, last_updated_by, creation_date,
6289     created_by, last_update_login, request_id, program_application_id,
6290     program_id, program_update_date, entity_type, table_name, column_name,
6291     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6292     orig_sys_pricing_attr_ref,error_message)
6293     SELECT
6294      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6295      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6296      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'PRICE_BY_FORMULA_ID',
6297      qpil.orig_sys_header_ref,qpil.orig_sys_line_ref,null,null,l_msg_txt
6298     FROM QP_INTERFACE_LIST_LINES qpil
6299     WHERE qpil.request_id = p_request_id
6300       AND  qpil.process_status_flag ='P' --is null
6301       AND  qpil.interface_action_code IN ('INSERT', 'UPDATE')
6302       AND  qpil.price_by_formula_id is NOT NULL
6303       AND  qpil.price_by_formula is NULL
6304       AND NOT EXISTS ( SELECT  name
6305 		       FROM    qp_price_formulas_vl
6306 		       WHERE   price_formula_id = qpil.price_by_formula_id);
6307 
6308     INSERT INTO QP_INTERFACE_ERRORS
6309    (error_id,last_update_date, last_updated_by, creation_date,
6310     created_by, last_update_login, request_id, program_application_id,
6311     program_id, program_update_date, entity_type, table_name, column_name,
6312     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6313     orig_sys_pricing_attr_ref,error_message)
6314     SELECT
6315      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6316      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6317      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'PRICE_BY_FORMULA_ID',
6318      qpil.orig_sys_header_ref,qpil.orig_sys_line_ref,null,null,l_msg_txt
6319     FROM QP_INTERFACE_LIST_LINES qpil
6320     WHERE qpil.request_id = p_request_id
6321       AND  qpil.process_status_flag ='P' --is null
6322       AND  qpil.interface_action_code IN ('INSERT', 'UPDATE')
6323       AND  qpil.price_by_formula_id is NULL
6324       AND  qpil.price_by_formula is NOT NULL
6325       AND  qpil.price_by_formula <> QP_BULK_LOADER_PUB.G_NULL_CHAR
6326       AND NOT EXISTS ( SELECT  name
6327 		       FROM    qp_price_formulas_vl
6328 		       WHERE   name = qpil.price_by_formula);
6329 
6330 --5. GENERATE USING FORMULA ID
6331 
6332     -- Bug# 5236656 RAVI START
6333     -- Change the message that needs to be thrown.
6334 
6335    FND_MESSAGE.SET_NAME('QP','QP_GEN_FOR_NAME_ID_INCMPTBLE');
6336    l_msg_txt := FND_MESSAGE.GET;
6337 
6338     INSERT INTO QP_INTERFACE_ERRORS
6339    (error_id,last_update_date, last_updated_by, creation_date,
6340     created_by, last_update_login, request_id, program_application_id,
6341     program_id, program_update_date, entity_type, table_name, column_name,
6342     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6343     orig_sys_pricing_attr_ref,error_message)
6344     SELECT
6345      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6346      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6347      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'GENERATE_USING_FORMULA_ID',
6348      qpil.orig_sys_header_ref,qpil.orig_sys_line_ref,null,null,l_msg_txt
6349     FROM QP_INTERFACE_LIST_LINES qpil
6350     WHERE qpil.request_id = p_request_id
6351       AND  qpil.process_status_flag ='P' --is null
6352       AND  qpil.interface_action_code IN ('INSERT', 'UPDATE')
6353       AND  qpil.generate_using_formula_id is NOT NULL
6354       AND  qpil.generate_using_formula is NOT NULL
6355       AND  qpil.generate_using_formula <> QP_BULK_LOADER_PUB.G_NULL_CHAR
6356       AND NOT EXISTS ( SELECT  name
6357 		       FROM    qp_price_formulas_vl
6358 		       WHERE   price_formula_id = qpil.generate_using_formula_id
6359 		       AND     name = qpil.generate_using_formula);
6360 
6361 
6362      IF SQL%ROWCOUNT >0 THEN
6363         qp_bulk_loader_pub.write_log('Generate formula ID and Name are incompatible');
6364      END IF;
6365 
6366     --FND_MESSAGE.SET_NAME('QP','QP_INVALID_FORMULA_FOR_PL');
6367     --l_msg_txt := FND_MESSAGE.GET;
6368     -- Bug# 5236656 RAVI END
6369 
6370     INSERT INTO QP_INTERFACE_ERRORS
6371    (error_id,last_update_date, last_updated_by, creation_date,
6372     created_by, last_update_login, request_id, program_application_id,
6373     program_id, program_update_date, entity_type, table_name, column_name,
6374     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6375     orig_sys_pricing_attr_ref,error_message)
6376     SELECT
6377      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6378      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6379      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'GENERATE_USING_FORMULA_ID',
6380      qpil.orig_sys_header_ref,qpil.orig_sys_line_ref,null,null,l_msg_txt
6381     FROM QP_INTERFACE_LIST_LINES qpil
6382     WHERE qpil.request_id = p_request_id
6383       AND  qpil.process_status_flag ='P' --is null
6384       AND  qpil.interface_action_code IN ('INSERT', 'UPDATE')
6385       AND  qpil.generate_using_formula_id is NOT NULL
6386       AND  qpil.generate_using_formula is NULL
6387       AND NOT EXISTS ( SELECT  name
6388 		       FROM    qp_price_formulas_vl
6389 		       WHERE   price_formula_id = qpil.generate_using_formula_id);
6390 
6391     INSERT INTO QP_INTERFACE_ERRORS
6392    (error_id,last_update_date, last_updated_by, creation_date,
6393     created_by, last_update_login, request_id, program_application_id,
6394     program_id, program_update_date, entity_type, table_name, column_name,
6395     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6396     orig_sys_pricing_attr_ref,error_message)
6397     SELECT
6398      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6399      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6400      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'GENERATE_USING_FORMULA_ID',
6401      qpil.orig_sys_header_ref,qpil.orig_sys_line_ref,null,null,l_msg_txt
6402     FROM QP_INTERFACE_LIST_LINES qpil
6403     WHERE qpil.request_id = p_request_id
6404       AND  qpil.process_status_flag ='P' --is null
6405       AND  qpil.interface_action_code IN ('INSERT', 'UPDATE')
6406       AND  qpil.generate_using_formula_id is NULL
6407       AND  qpil.generate_using_formula is NOT NULL
6408       AND  qpil.generate_using_formula <> QP_BULK_LOADER_PUB.G_NULL_CHAR
6409       AND NOT EXISTS ( SELECT  name
6410 		       FROM    qp_price_formulas_vl
6411 		       WHERE   name = qpil.generate_using_formula);
6412 
6413     -- Bug# 5236656 RAVI
6414     IF SQL%ROWCOUNT >0 THEN
6415        qp_bulk_loader_pub.write_log('Generate formula ID is inaccurate');
6416     END IF;
6417 
6418 --6. PBH not allowed in Basic pricing
6419 -- Basic_Pricing_Condition
6420 
6421    IF QP_BULK_LOADER_PUB.GET_QP_STATUS <> 'I' THEN
6422        FND_MESSAGE.SET_NAME('QP','QP_PBH_NA_BASIC');
6423        --Price Break Header not allowed in Basic Pricing
6424        l_msg_txt := FND_MESSAGE.GET;
6425 
6426 	INSERT INTO QP_INTERFACE_ERRORS
6427        (error_id,last_update_date, last_updated_by, creation_date,
6428 	created_by, last_update_login, request_id, program_application_id,
6429 	program_id, program_update_date, entity_type, table_name,
6430 	orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6431 	orig_sys_pricing_attr_ref,error_message)
6432 	SELECT
6433 	 qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6434 	 FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6435 	 NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',
6436 	 qpil.orig_sys_header_ref,qpil.orig_sys_line_ref,null,null,l_msg_txt
6437 	FROM QP_INTERFACE_LIST_LINES qpil
6438 	WHERE qpil.request_id = p_request_id
6439 	  AND  qpil.process_status_flag ='P' --is null
6440 	  AND  qpil.interface_action_code IN ('INSERT', 'UPDATE')
6441 	  AND  (qpil.list_line_type_code = 'PBH'
6442 		OR qpil.price_break_header_ref is not NULL);
6443 
6444   END IF;
6445 
6446   --7. Product Attribute
6447    FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
6448    FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Product Attribute ');
6449    l_msg_txt := FND_MESSAGE.GET;
6450 
6451     INSERT INTO QP_INTERFACE_ERRORS
6452    (error_id,last_update_date, last_updated_by, creation_date,
6453     created_by, last_update_login, request_id, program_application_id,
6454     program_id, program_update_date, entity_type, table_name, column_name,
6455     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6456     orig_sys_pricing_attr_ref,error_message)
6457     SELECT
6458      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6459      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6460      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'PRODUCT_ATTRIBUTE',
6461      qpip.orig_sys_header_ref,qpip.orig_sys_line_ref,null,
6462      qpip.orig_sys_pricing_attr_ref,  l_msg_txt
6463     FROM QP_INTERFACE_LIST_LINES qpil, QP_INTERFACE_PRICING_ATTRIBS qpip
6464     WHERE qpil.request_id = p_request_id
6465       AND  qpip.request_id = p_request_id -- bug no 5881528
6466       AND  qpil.process_status_flag ='P' --is null
6467       AND  qpil.orig_sys_line_ref = qpip.orig_sys_line_ref
6468       AND  qpip.pricing_attribute_context IS NULL
6469       AND  qpil.interface_action_code IN ('INSERT', 'UPDATE')
6470       AND EXISTS ( SELECT  'x'
6471         FROM qp_interface_pricing_attribs b, qp_prc_contexts_b d, qp_segments_b e, qp_pte_segments f
6472         WHERE  b.product_attribute_context = d.prc_context_code
6473 	AND b.product_attribute = e.segment_mapping_column
6474 	and e.segment_code = b.product_attr_code
6475         AND d.prc_context_id = e.prc_context_id
6476 	AND d.prc_context_type = 'PRODUCT'
6477 	AND e.segment_id = f.segment_id
6478 	AND f.pte_code = l_pte_code
6479 	AND f.segment_level <> 'LINE'
6480 	AND qpip.rowid = b.rowid
6481         union
6482         SELECT  'x'
6483         FROM qp_interface_pricing_attribs b, qp_prc_contexts_b d, qp_segments_b e, qp_pte_segments f
6484         WHERE  b.product_attribute_context = d.prc_context_code
6485 	AND b.product_attribute is NULL and e.segment_code = b.product_attr_code
6486 	AND d.prc_context_id = e.prc_context_id
6487 	AND d.prc_context_type = 'PRODUCT'
6488 	AND e.segment_id = f.segment_id
6489 	AND f.pte_code = l_pte_code
6490 	AND f.segment_level <> 'LINE'
6491 	AND qpip.rowid = b.rowid);
6492 
6493 --Bug# 5456164 START RAVI
6494   --Validate product attribute
6495   --8. Product Attribute
6496    FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
6497    FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Product Attribute ');
6498    l_msg_txt := FND_MESSAGE.GET;
6499 
6500     INSERT INTO QP_INTERFACE_ERRORS
6501    (error_id,last_update_date, last_updated_by, creation_date,
6502     created_by, last_update_login, request_id, program_application_id,
6503     program_id, program_update_date, entity_type, table_name, column_name,
6504     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6505     orig_sys_pricing_attr_ref,error_message)
6506     SELECT
6507      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6508      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6509      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'PRODUCT_ATTRIBUTE',
6510      qpip.orig_sys_header_ref,qpip.orig_sys_line_ref,null,
6511      qpip.orig_sys_pricing_attr_ref,  l_msg_txt
6512     FROM QP_INTERFACE_LIST_LINES qpil, QP_INTERFACE_PRICING_ATTRIBS qpip
6513     WHERE qpil.request_id = p_request_id
6514       AND  qpip.request_id = p_request_id -- bug no 5881528
6515       AND qpil.process_status_flag ='P' --is null
6516       AND qpil.orig_sys_line_ref = qpip.orig_sys_line_ref
6517       AND qpip.product_attribute_context IS NOT NULL
6518       AND qpip.product_attribute IS NOT NULL
6519       AND qpip.product_attr_code IS NOT NULL
6520       AND qpip.product_attr_code <> QP_BULK_LOADER_PUB.G_NULL_CHAR
6521       AND qpil.interface_action_code IN ('INSERT', 'UPDATE')
6522       AND NOT EXISTS ( SELECT  'x'
6523         FROM qp_interface_pricing_attribs b, qp_prc_contexts_b d, qp_segments_b e, qp_pte_segments f
6524         WHERE  b.product_attribute_context = d.prc_context_code
6525 	AND b.product_attribute = e.segment_mapping_column
6526 	and e.segment_code = b.product_attr_code
6527         AND d.prc_context_id = e.prc_context_id
6528 	AND d.prc_context_type = 'PRODUCT'
6529 	AND e.segment_id = f.segment_id
6530 	AND f.pte_code = l_pte_code
6531 	AND qpip.rowid = b.rowid);
6532 
6533     INSERT INTO QP_INTERFACE_ERRORS
6534    (error_id,last_update_date, last_updated_by, creation_date,
6535     created_by, last_update_login, request_id, program_application_id,
6536     program_id, program_update_date, entity_type, table_name, column_name,
6537     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6538     orig_sys_pricing_attr_ref,error_message)
6539     SELECT
6540      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6541      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6542      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'PRODUCT_ATTRIBUTE',
6543      qpip.orig_sys_header_ref,qpip.orig_sys_line_ref,null,
6544      qpip.orig_sys_pricing_attr_ref,  l_msg_txt
6545     FROM QP_INTERFACE_LIST_LINES qpil, QP_INTERFACE_PRICING_ATTRIBS qpip
6546     WHERE qpil.request_id = p_request_id
6547       AND  qpip.request_id = p_request_id -- bug no 5881528
6548       AND qpil.process_status_flag ='P' --is null
6549       AND qpil.orig_sys_line_ref = qpip.orig_sys_line_ref
6550       AND qpip.product_attribute_context IS NOT NULL
6551       AND qpip.product_attribute IS NULL
6552       AND qpip.product_attr_code IS NOT NULL
6553       AND qpip.product_attr_code <> QP_BULK_LOADER_PUB.G_NULL_CHAR
6554       AND qpil.interface_action_code IN ('INSERT', 'UPDATE')
6555       AND NOT EXISTS ( SELECT  'x'
6556         FROM qp_interface_pricing_attribs b, qp_prc_contexts_b d, qp_segments_b e, qp_pte_segments f
6557         WHERE  b.product_attribute_context = d.prc_context_code
6558 	and e.segment_code = b.product_attr_code
6559         AND d.prc_context_id = e.prc_context_id
6560 	AND d.prc_context_type = 'PRODUCT'
6561 	AND e.segment_id = f.segment_id
6562 	AND f.pte_code = l_pte_code
6563 	AND qpip.rowid = b.rowid);
6564 
6565     INSERT INTO QP_INTERFACE_ERRORS
6566    (error_id,last_update_date, last_updated_by, creation_date,
6567     created_by, last_update_login, request_id, program_application_id,
6568     program_id, program_update_date, entity_type, table_name, column_name,
6569     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6570     orig_sys_pricing_attr_ref,error_message)
6571     SELECT
6572      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6573      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6574      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'PRODUCT_ATTRIBUTE',
6575      qpip.orig_sys_header_ref,qpip.orig_sys_line_ref,null,
6576      qpip.orig_sys_pricing_attr_ref,  l_msg_txt
6577     FROM QP_INTERFACE_LIST_LINES qpil, QP_INTERFACE_PRICING_ATTRIBS qpip
6578     WHERE qpil.request_id = p_request_id
6579       AND  qpip.request_id = p_request_id -- bug no 5881528
6580       AND qpil.process_status_flag ='P' --is null
6581       AND qpil.orig_sys_line_ref = qpip.orig_sys_line_ref
6582       AND qpip.product_attribute_context IS NOT NULL
6583       AND qpip.product_attribute IS NOT NULL
6584       AND qpip.product_attr_code IS NULL
6585       AND qpil.interface_action_code IN ('INSERT', 'UPDATE')
6586       AND NOT EXISTS ( SELECT  'x'
6587         FROM qp_interface_pricing_attribs b, qp_prc_contexts_b d, qp_segments_b e, qp_pte_segments f
6588         WHERE  b.product_attribute_context = d.prc_context_code
6589 	AND b.product_attribute = e.segment_mapping_column
6590         AND d.prc_context_id = e.prc_context_id
6591 	AND d.prc_context_type = 'PRODUCT'
6592 	AND e.segment_id = f.segment_id
6593 	AND f.pte_code = l_pte_code
6594 	AND qpip.rowid = b.rowid);
6595 
6596   --Validate pricing attribute
6597   --9. Pricing Attribute
6598    FND_MESSAGE.SET_NAME('QP','QP_INVALID_ATTRIBUTE');
6599    FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Pricing Attribute ');
6600    l_msg_txt := FND_MESSAGE.GET;
6601 
6602     INSERT INTO QP_INTERFACE_ERRORS
6603    (error_id,last_update_date, last_updated_by, creation_date,
6604     created_by, last_update_login, request_id, program_application_id,
6605     program_id, program_update_date, entity_type, table_name, column_name,
6606     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6607     orig_sys_pricing_attr_ref,error_message)
6608     SELECT
6609      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6610      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6611      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'PRODUCT_ATTRIBUTE',
6612      qpip.orig_sys_header_ref,qpip.orig_sys_line_ref,null,
6613      qpip.orig_sys_pricing_attr_ref,  l_msg_txt
6614     FROM QP_INTERFACE_LIST_LINES qpil, QP_INTERFACE_PRICING_ATTRIBS qpip
6615     WHERE qpil.request_id = p_request_id
6616       AND  qpip.request_id = p_request_id -- bug no 5881528
6617       AND qpil.process_status_flag ='P' --is null
6618       AND qpil.orig_sys_line_ref = qpip.orig_sys_line_ref
6619       AND qpip.pricing_attribute_context IS NOT NULL
6620       AND qpip.pricing_attribute IS NOT NULL
6621       AND qpip.pricing_attr_code IS NOT NULL
6622       AND qpip.pricing_attr_code <> QP_BULK_LOADER_PUB.G_NULL_CHAR
6623       AND qpil.interface_action_code IN ('INSERT', 'UPDATE')
6624       AND NOT EXISTS ( SELECT  'x'
6625         FROM qp_interface_pricing_attribs b, qp_prc_contexts_b d, qp_segments_b e, qp_pte_segments f
6626         WHERE  b.pricing_attribute_context = d.prc_context_code
6627 	AND b.pricing_attribute = e.segment_mapping_column
6628 	and e.segment_code = b.pricing_attr_code
6629         AND d.prc_context_id = e.prc_context_id
6630 	AND d.prc_context_type = 'PRICING_ATTRIBUTE'
6631 	AND e.segment_id = f.segment_id
6632 	AND f.pte_code = l_pte_code
6633 	AND qpip.rowid = b.rowid);
6634 
6635     INSERT INTO QP_INTERFACE_ERRORS
6636    (error_id,last_update_date, last_updated_by, creation_date,
6637     created_by, last_update_login, request_id, program_application_id,
6638     program_id, program_update_date, entity_type, table_name, column_name,
6639     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6640     orig_sys_pricing_attr_ref,error_message)
6641     SELECT
6642      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6643      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6644      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'PRODUCT_ATTRIBUTE',
6645      qpip.orig_sys_header_ref,qpip.orig_sys_line_ref,null,
6646      qpip.orig_sys_pricing_attr_ref,  l_msg_txt
6647     FROM QP_INTERFACE_LIST_LINES qpil, QP_INTERFACE_PRICING_ATTRIBS qpip
6648     WHERE qpil.request_id = p_request_id
6649       AND  qpip.request_id = p_request_id -- bug no 5881528
6650       AND qpil.process_status_flag ='P' --is null
6651       AND qpil.orig_sys_line_ref = qpip.orig_sys_line_ref
6652       AND qpip.pricing_attribute_context IS NOT NULL
6653       AND qpip.pricing_attribute IS NULL
6654       AND qpip.pricing_attr_code IS NOT NULL
6655       AND qpip.pricing_attr_code <> QP_BULK_LOADER_PUB.G_NULL_CHAR
6656       AND qpil.interface_action_code IN ('INSERT', 'UPDATE')
6657       AND NOT EXISTS ( SELECT  'x'
6658         FROM qp_interface_pricing_attribs b, qp_prc_contexts_b d, qp_segments_b e, qp_pte_segments f
6659         WHERE  b.pricing_attribute_context = d.prc_context_code
6660 	and e.segment_code = b.pricing_attr_code
6661         AND d.prc_context_id = e.prc_context_id
6662 	AND d.prc_context_type = 'PRICING_ATTRIBUTE'
6663 	AND e.segment_id = f.segment_id
6664 	AND f.pte_code = l_pte_code
6665 	AND qpip.rowid = b.rowid);
6666 
6667     INSERT INTO QP_INTERFACE_ERRORS
6668    (error_id,last_update_date, last_updated_by, creation_date,
6669     created_by, last_update_login, request_id, program_application_id,
6670     program_id, program_update_date, entity_type, table_name, column_name,
6671     orig_sys_header_ref,orig_sys_line_ref,orig_sys_qualifier_ref,
6672     orig_sys_pricing_attr_ref,error_message)
6673     SELECT
6674      qp_interface_errors_s.nextval, sysdate ,FND_GLOBAL.USER_ID, sysdate,
6675      FND_GLOBAL.USER_ID, FND_GLOBAL.CONC_LOGIN_ID, qpil.request_id, 661,
6676      NULL,NULL, 'PRL', 'QP_INTERFACE_LIST_LINES',  'PRODUCT_ATTRIBUTE',
6677      qpip.orig_sys_header_ref,qpip.orig_sys_line_ref,null,
6678      qpip.orig_sys_pricing_attr_ref,  l_msg_txt
6679     FROM QP_INTERFACE_LIST_LINES qpil, QP_INTERFACE_PRICING_ATTRIBS qpip
6680     WHERE qpil.request_id = p_request_id
6681       AND  qpip.request_id = p_request_id -- bug no 5881528
6682       AND qpil.process_status_flag ='P' --is null
6683       AND qpil.orig_sys_line_ref = qpip.orig_sys_line_ref
6684       AND qpip.pricing_attribute_context IS NOT NULL
6685       AND qpip.pricing_attribute IS NOT NULL
6686       AND qpip.pricing_attr_code IS NULL
6687       AND qpil.interface_action_code IN ('INSERT', 'UPDATE')
6688       AND NOT EXISTS ( SELECT  'x'
6689         FROM qp_interface_pricing_attribs b, qp_prc_contexts_b d, qp_segments_b e, qp_pte_segments f
6690         WHERE  b.pricing_attribute_context = d.prc_context_code
6691 	AND b.pricing_attribute = e.segment_mapping_column
6692         AND d.prc_context_id = e.prc_context_id
6693 	AND d.prc_context_type = 'PRICING_ATTRIBUTE'
6694 	AND e.segment_id = f.segment_id
6695 	AND f.pte_code = l_pte_code
6696 	AND qpip.rowid = b.rowid);
6697 --Bug# 5456164 END RAVI
6698 
6699        qp_bulk_loader_pub.write_log('Leaving Attribute Line validation');
6700 	EXCEPTION
6701 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6702 	   qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE ATTRIBUTE_LINE:'||sqlerrm);
6703 	   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6704 	WHEN OTHERS THEN
6705 	   qp_bulk_loader_pub.write_log( 'UNEXCPECTED ERROR IN PROCEDURE ATTRIBUTE_LINE:'||sqlerrm);
6706        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6707 END ATTRIBUTE_LINE;
6708 
6709 
6710 PROCEDURE MARK_ERRORED_INTERFACE_RECORD
6711    (p_table_type  VARCHAR2,
6712     p_request_id  NUMBER)
6713 IS
6714 BEGIN
6715 
6716    qp_bulk_loader_pub.write_log('Entering Mark errored inreface record');
6717 
6718    IF p_table_type = 'HEADER'  THEN
6719 
6720 	UPDATE qp_interface_list_headers h
6721 	   SET h.process_status_flag = NULL --'E'
6722 	 WHERE h.request_id = p_request_id
6723 	   AND EXISTS
6724 	 (SELECT  orig_sys_header_ref
6725 	    FROM  qp_interface_errors e
6726 	   WHERE  e.orig_sys_header_ref = h.orig_sys_header_ref
6727 	     AND  e.table_name ='QP_INTERFACE_LIST_HEADERS'
6728 	     AND  e.request_id = p_request_id	  );
6729 
6730    ELSIF p_table_type = 'QUALIFIER' THEN
6731 
6732 	UPDATE qp_interface_qualifiers  q
6733 	   SET process_status_flag = NULL --'E'
6734 	 WHERE q.request_id =p_request_id
6735 	   AND EXISTS
6736 	 (SELECT  orig_sys_qualifier_ref
6737 	    FROM    qp_interface_errors e
6738 	   WHERE    e.orig_sys_qualifier_ref = q.orig_sys_qualifier_ref
6739 	     AND    e.orig_sys_header_ref = q.orig_sys_header_ref
6740 	     AND    e.table_name ='QP_INTERFACE_QUALIFIERS'
6741 	     AND    e.request_id = p_request_id);
6742 
6743    ELSIF p_table_type = 'LINE' THEN
6744 
6745 	UPDATE qp_interface_list_lines  l
6746 	   SET    process_status_flag = NULL --'E'
6747 	 WHERE    l.request_id =p_request_id
6748 	   AND EXISTS
6749 	 (SELECT  orig_sys_line_ref
6750 	    FROM    qp_interface_errors e
6751 	   WHERE    e.orig_sys_line_ref = l.orig_sys_line_ref
6752 	     AND    e.orig_sys_header_ref = l.orig_sys_header_ref
6753 	     AND  table_name ='QP_INTERFACE_LIST_LINES'
6754 	     AND  e.request_id = p_request_id	 );
6755 
6756    ELSIF p_table_type = 'PRICING_ATTRIBS' THEN
6757 
6758 	UPDATE qp_interface_pricing_attribs  a
6759 	   SET     process_status_flag = NULL --'E'
6760 	 WHERE  a.request_id =p_request_id
6761 		AND EXISTS
6762 	 (SELECT    orig_sys_pricing_attr_ref
6763 	    FROM    qp_interface_errors e
6764 	   WHERE    e.orig_sys_line_ref = a.orig_sys_line_ref
6765 	     AND    e.orig_sys_header_ref = a.orig_sys_header_ref
6766 	     AND    e.orig_sys_pricing_attr_ref = a.orig_sys_pricing_attr_ref
6767 	     AND    table_name ='QP_INTERFACE_PRICING_ATTRIBS'
6768 	     AND    e.request_id = p_request_id	 );
6769 
6770    END IF;
6771 
6772    qp_bulk_loader_pub.write_log('Entering Mark errored inreface record');
6773 
6774    EXCEPTION
6775     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6776        qp_bulk_loader_pub.write_log(
6777 			 'UNEXCPECTED ERROR IN PROCEDURE MARK_ERRORED_INTERFACE_RECORD:'||sqlerrm);
6778        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6779     WHEN OTHERS THEN
6780        qp_bulk_loader_pub.write_log(
6781 			 'UNEXCPECTED ERROR IN PROCEDURE MARK_ERRORED_INTERFACE_RECORD:'||sqlerrm);
6782        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6783 
6784 END MARK_ERRORED_INTERFACE_RECORD;
6785 
6786 END QP_BULK_VALIDATE;