1 PACKAGE BODY HZ_GNR_PVT AS
2 /* $Header: ARHGNRVB.pls 120.16 2006/07/22 00:33:28 nsinghai noship $ */
3
4 -----------------------------------------------------------------------------+
5 -- Package variables
6 -----------------------------------------------------------------------------+
7 l_module_prefix CONSTANT VARCHAR2(30) := 'HZ:ARHGNRVB:HZ_GNR_PVT';
8 l_module CONSTANT VARCHAR2(30) := 'SEARCH_GEOGRAPHIES';
9 l_debug_prefix VARCHAR2(30) ;
10
11 -----------------------------------------------------------------------------+
12 -- Private function to get geo type list based on postion of geo type.
13 -- If for US structure, 2 is passed, it will give STATE, COUNTY, CITY, POSTAL_CODE
14 -- Created By Nishant Singhai (for Bug 4600030 on 27-Sep-2005)
15 -----------------------------------------------------------------------------+
16 FUNCTION get_geo_type_list (l_geo_struct_tbl IN hz_gnr_pvt.geo_struct_tbl_type,
17 l_index IN NUMBER, l_for_map_or_usg IN VARCHAR2 DEFAULT 'USAGE' ) RETURN VARCHAR2 IS
18 v_not_validated_geo_type VARCHAR(200);
19 BEGIN
20 FOR i IN l_geo_struct_tbl.FIRST..l_geo_struct_tbl.LAST LOOP
21 -- if call is to return for full mapping, return
22 IF (l_for_map_or_usg = 'MAPPING') THEN
23 IF (i >= l_index) THEN
24 IF (v_not_validated_geo_type) IS NULL THEN
25 v_not_validated_geo_type := l_geo_struct_tbl(i).v_geo_type;
26 ELSE
27 v_not_validated_geo_type := v_not_validated_geo_type||', '||l_geo_struct_tbl(i).v_geo_type;
28 END IF;
29 END IF;
30 ELSE -- return only components set for geo validation usage (which is most of the cases)
31 IF (i >= l_index) THEN
32 IF (l_geo_struct_tbl(i).v_valid_for_usage = 'Y') THEN
33 IF (v_not_validated_geo_type) IS NULL THEN
34 v_not_validated_geo_type := l_geo_struct_tbl(i).v_geo_type;
35 ELSE
36 v_not_validated_geo_type := v_not_validated_geo_type||', '||l_geo_struct_tbl(i).v_geo_type;
37 END IF;
38 END IF;
39 END IF;
40 END IF;
41
42 END LOOP;
43
44 RETURN v_not_validated_geo_type;
45 END get_geo_type_list;
46
47 ----------------------------------------------------------------------------+
48 -- Private Function to get list of geography types which are mandatory but
49 -- user has not entered value
50 -- Created By Nishant Singhai (for Bug 4600030 on 27-Sep-2005)
51 ----------------------------------------------------------------------------+
52 FUNCTION get_missing_input_fields (l_geo_struct_tbl IN hz_gnr_pvt.geo_struct_tbl_type
53 ) RETURN VARCHAR2 IS
54 v_missing_fields VARCHAR(200);
55 BEGIN
56 FOR i IN l_geo_struct_tbl.FIRST..l_geo_struct_tbl.LAST LOOP
57 IF ((l_geo_struct_tbl(i).v_valid_for_usage = 'Y') AND
58 (l_geo_struct_tbl(i).v_param_value IS NULL)) THEN
59 IF (v_missing_fields IS NULL) THEN
60 v_missing_fields := l_geo_struct_tbl(i).v_geo_type;
61 ELSE
62 v_missing_fields := v_missing_fields||', '||l_geo_struct_tbl(i).v_geo_type;
63 END IF;
64 END IF;
65 END LOOP;
66
67 RETURN v_missing_fields;
68 END get_missing_input_fields;
69
70 --------------------------------------------------------------------------+
71 -- FUNCTION TO CHECK IF user passed values for all components for which
72 -- geo usage is checked for validation
73 --------------------------------------------------------------------------+
74 FUNCTION is_all_geo_usage_param_passed (ll_geo_struct_tbl IN hz_gnr_pvt.geo_struct_tbl_type)
75 RETURN BOOLEAN IS
76 BEGIN
77 IF (ll_geo_struct_tbl.COUNT > 0) THEN
78 FOR i IN ll_geo_struct_tbl.FIRST..ll_geo_struct_tbl.LAST LOOP
79 IF (ll_geo_struct_tbl(i).v_valid_for_usage = 'Y') THEN
80 IF (ll_geo_struct_tbl(i).v_param_value IS NULL) THEN
81 RETURN FALSE;
82 EXIT;
83 END IF;
84 END IF;
85 END LOOP;
86 RETURN TRUE;
87 ELSE
88 RETURN TRUE; -- if no structure, no issue. it is success
89 END IF;
90 END is_all_geo_usage_param_passed;
91
92 -----------------------------------------------------------------------------+
93 -- Procedure to return geography types in a string that could not be validated
94 -- Created By Nishant Singhai (for Bug 4600030 on 27-Sep-2005)
95 -----------------------------------------------------------------------------+
96 PROCEDURE validate_input_values_proc (l_geo_struct_tbl IN hz_gnr_pvt.geo_struct_tbl_type,
97 x_not_validated_geo_type OUT NOCOPY VARCHAR2,
98 x_rec_count_flag OUT NOCOPY VARCHAR2,
99 x_success_geo_level OUT NOCOPY NUMBER) IS
100
101 l_map_tbl hz_gnr_util_pkg.maploc_rec_tbl_type;
102 l_query_temp VARCHAR2(10000);
103 l_query VARCHAR2(10000);
104 l_status VARCHAR2(10);
105 l_success_geo_level NUMBER;
106 l_success_rec_count NUMBER;
107
108 l_not_validated_geo_type VARCHAR2(200);
109 lx_max_usage_element_col_value NUMBER;
110
111 TYPE param_details_rec_type IS RECORD
112 ( geo_type VARCHAR2(100),
113 geo_value VARCHAR2(360),
114 query_text VARCHAR2(10000)
115 );
116
117 TYPE param_details_tbl_type IS TABLE OF param_details_rec_type INDEX BY BINARY_INTEGER;
118
119 l_param_details_tbl param_details_tbl_type;
120
121 l_country_code VARCHAR2(10);
122 l_country_geo_id NUMBER;
123 l_count NUMBER;
124
125 l_rec_count_flag VARCHAR2(10);
126 l_level NUMBER;
127 l_temp_level NUMBER;
128 l_temp_usage VARCHAR2(30);
129
130 CURSOR c_geo_id (l_country_code IN VARCHAR2) IS
131 SELECT geography_id
132 FROM hz_geography_identifiers
133 WHERE UPPER(identifier_value) = l_country_code
134 AND identifier_type = 'CODE'
135 AND identifier_subtype = 'ISO_COUNTRY_CODE'
136 AND geography_use = 'MASTER_REF'
137 AND geography_type = 'COUNTRY'
138 ;
139
140 TYPE cur_sql_type IS REF CURSOR;
141 cv_sql cur_sql_type;
142
143 BEGIN
144 -- FND Logging for debug purpose
145 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
146 hz_utility_v2pub.debug
147 (p_message => 'Begin procedure validate_input_values_proc(+)',
148 p_prefix => l_debug_prefix,
149 p_msg_level => fnd_log.level_procedure,
150 p_module_prefix => l_module_prefix,
151 p_module => l_module
152 );
153 END IF;
154
155 -- main code logic begins here
156 lx_max_usage_element_col_value := 0;
157 l_country_code := UPPER(REPLACE(l_geo_struct_tbl(1).v_param_value,'%',''));
158
159
160 -- get geography_id for country_code
161 OPEN c_geo_id (l_country_code);
162 FETCH c_geo_id INTO l_country_geo_id;
163 CLOSE c_geo_id;
164
165 IF (l_country_geo_id IS NOT NULL) THEN
166
167 -- FND Logging for debug purpose
168 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
169 hz_utility_v2pub.debug
170 (p_message => 'Fetched country geography id. It is:'||l_country_geo_id,
171 p_prefix => l_debug_prefix,
172 p_msg_level => fnd_log.level_statement,
173 p_module_prefix => l_module_prefix,
174 p_module => l_module
175 );
176 END IF;
177
178 IF (l_geo_struct_tbl.COUNT > 0) THEN
179
180 -- again get the max element column for which geo usage is required to be valid
181 FOR i IN l_geo_struct_tbl.FIRST..l_geo_struct_tbl.LAST LOOP
182 IF (l_geo_struct_tbl(i).v_valid_for_usage = 'Y') THEN
183 lx_max_usage_element_col_value :=
184 GREATEST(NVL(lx_max_usage_element_col_value,0),TO_NUMBER(SUBSTR(l_geo_struct_tbl(i).v_element_col,18)));
185 END IF;
186 END LOOP;
187
188 FOR i IN l_geo_struct_tbl.FIRST..l_geo_struct_tbl.LAST LOOP
189
190 l_query_temp := NULL;
191 l_query := NULL;
192 l_count := NULL;
193
194 IF (i = 1) THEN
195 l_map_tbl(i).LOC_SEQ_NUM := l_geo_struct_tbl(i).v_level;
196 l_map_tbl(i).LOC_COMPONENT := l_geo_struct_tbl(i).v_tab_col;
197 l_map_tbl(i).GEOGRAPHY_TYPE := l_geo_struct_tbl(i).v_geo_type;
198 l_map_tbl(i).GEO_ELEMENT_COL := l_geo_struct_tbl(i).v_element_col;
199 l_map_tbl(i).LOC_COMPVAL := l_country_code;
200 l_map_tbl(i).GEOGRAPHY_ID := l_country_geo_id;
201
202 l_param_details_tbl(i).geo_type := l_geo_struct_tbl(i).v_geo_type;
203 l_param_details_tbl(i).geo_value := l_country_code;
204
205 l_rec_count_flag := 1;
206 l_level := 1;
207 l_success_geo_level := l_level;
208 l_success_rec_count := 1;
209
210 ELSE
211 l_map_tbl(i).LOC_SEQ_NUM := l_geo_struct_tbl(i).v_level;
212 l_map_tbl(i).LOC_COMPONENT := l_geo_struct_tbl(i).v_tab_col;
213 l_map_tbl(i).GEOGRAPHY_TYPE := l_geo_struct_tbl(i).v_geo_type;
214 l_map_tbl(i).GEO_ELEMENT_COL := l_geo_struct_tbl(i).v_element_col;
215 l_map_tbl(i).LOC_COMPVAL := UPPER(REPLACE(l_geo_struct_tbl(i).v_param_value,'%',''));
216
217
218 IF (l_geo_struct_tbl(i).v_param_value IS NOT NULL) THEN
219 l_param_details_tbl(i).geo_type := l_geo_struct_tbl(i).v_geo_type;
220 l_param_details_tbl(i).geo_value := UPPER(REPLACE(l_geo_struct_tbl(i).v_param_value,'%',''));
221 l_query_temp := HZ_GNR_UTIL_PKG.getQuery(l_map_tbl, l_map_tbl, l_status);
222 l_query := 'SELECT COUNT(*) FROM ('||l_query_temp||')';
223 l_param_details_tbl(i).query_text := l_query;
224
225 -- ns_debug.put_line('----------------------------------------');
226 -- ns_debug.put_line('Status: '||l_status);
227 -- ns_debug.put_line(l_query);
228 ELSE
229 l_param_details_tbl(i).geo_type := 'X';
230 l_param_details_tbl(i).geo_value := 'X';
231 l_param_details_tbl(i).query_text := NULL;
232 --ns_debug.put_line('----------------------------------------');
233 --ns_debug.put_line('for level '||i||' no parameter is passed');
234 END IF;
235
236 IF (l_param_details_tbl(i).query_text IS NOT NULL) THEN
237 CASE i
238 WHEN 2 THEN
239 OPEN cv_sql FOR l_param_details_tbl(i).query_text USING l_country_code, l_country_geo_id,
240 l_param_details_tbl(2).geo_type, l_param_details_tbl(2).geo_value, l_param_details_tbl(2).geo_type;
241 /*
242 ns_debug.put_line('----------------------------------------');
243 ns_debug.put_line('Bind For 2:'||l_country_code||':'||l_country_geo_id||':'||
244 l_param_details_tbl(2).geo_type||':'||l_param_details_tbl(2).geo_value||':'||
245 l_param_details_tbl(2).geo_type
246 );
247 */
248 WHEN 3 THEN
249 OPEN cv_sql FOR l_param_details_tbl(i).query_text USING l_country_code, l_country_geo_id,
250 l_param_details_tbl(2).geo_type, l_param_details_tbl(2).geo_value,
251 l_param_details_tbl(3).geo_type, l_param_details_tbl(3).geo_value, l_param_details_tbl(3).geo_type;
252 /*
253 ns_debug.put_line('----------------------------------------');
254 ns_debug.put_line('Bind For 3:'||l_country_code||':'||l_country_geo_id||':'||
255 l_param_details_tbl(2).geo_type||':'||l_param_details_tbl(2).geo_value||':'||
256 l_param_details_tbl(3).geo_type||':'||l_param_details_tbl(3).geo_value||':'||
257 l_param_details_tbl(3).geo_type
258 );
259 */
260 WHEN 4 THEN
261 OPEN cv_sql FOR l_param_details_tbl(i).query_text USING l_country_code, l_country_geo_id,
262 l_param_details_tbl(2).geo_type, l_param_details_tbl(2).geo_value,
263 l_param_details_tbl(3).geo_type, l_param_details_tbl(3).geo_value,
264 l_param_details_tbl(4).geo_type, l_param_details_tbl(4).geo_value, l_param_details_tbl(4).geo_type;
265 /*
266 ns_debug.put_line('----------------------------------------');
267 ns_debug.put_line('Bind For 4:'||l_country_code||':'||l_country_geo_id||':'||
268 l_param_details_tbl(2).geo_type||':'||l_param_details_tbl(2).geo_value||':'||
269 l_param_details_tbl(3).geo_type||':'||l_param_details_tbl(3).geo_value||':'||
270 l_param_details_tbl(4).geo_type||':'||l_param_details_tbl(4).geo_value||':'||
271 l_param_details_tbl(4).geo_type
272 );
273 */
274 WHEN 5 THEN
275 OPEN cv_sql FOR l_param_details_tbl(i).query_text USING l_country_code, l_country_geo_id,
276 l_param_details_tbl(2).geo_type, l_param_details_tbl(2).geo_value,
277 l_param_details_tbl(3).geo_type, l_param_details_tbl(3).geo_value,
278 l_param_details_tbl(4).geo_type, l_param_details_tbl(4).geo_value,
279 l_param_details_tbl(5).geo_type, l_param_details_tbl(5).geo_value, l_param_details_tbl(5).geo_type;
280 /*
281 ns_debug.put_line('----------------------------------------');
282 ns_debug.put_line('Bind For 5:'||l_country_code||':'||l_country_geo_id||':'||
283 l_param_details_tbl(2).geo_type||':'||l_param_details_tbl(2).geo_value||':'||
284 l_param_details_tbl(3).geo_type||':'||l_param_details_tbl(3).geo_value||':'||
285 l_param_details_tbl(4).geo_type||':'||l_param_details_tbl(4).geo_value||':'||
286 l_param_details_tbl(5).geo_type||':'||l_param_details_tbl(5).geo_value||':'||
287 l_param_details_tbl(5).geo_type
288 );
289 */
290 WHEN 6 THEN
291 OPEN cv_sql FOR l_param_details_tbl(i).query_text USING l_country_code, l_country_geo_id,
292 l_param_details_tbl(2).geo_type, l_param_details_tbl(2).geo_value,
293 l_param_details_tbl(3).geo_type, l_param_details_tbl(3).geo_value,
294 l_param_details_tbl(4).geo_type, l_param_details_tbl(4).geo_value,
295 l_param_details_tbl(5).geo_type, l_param_details_tbl(5).geo_value,
296 l_param_details_tbl(6).geo_type, l_param_details_tbl(6).geo_value, l_param_details_tbl(6).geo_type;
297 /*
298 ns_debug.put_line('----------------------------------------');
299 ns_debug.put_line('Bind For 6:'||l_country_code||':'||l_country_geo_id||':'||
300 l_param_details_tbl(2).geo_type||':'||l_param_details_tbl(2).geo_value||':'||
301 l_param_details_tbl(3).geo_type||':'||l_param_details_tbl(3).geo_value||':'||
302 l_param_details_tbl(4).geo_type||':'||l_param_details_tbl(4).geo_value||':'||
303 l_param_details_tbl(5).geo_type||':'||l_param_details_tbl(5).geo_value||':'||
304 l_param_details_tbl(6).geo_type||':'||l_param_details_tbl(6).geo_value||':'||
305 l_param_details_tbl(6).geo_type
306 );
307 */
308 WHEN 7 THEN
309 OPEN cv_sql FOR l_param_details_tbl(i).query_text USING l_country_code, l_country_geo_id,
310 l_param_details_tbl(2).geo_type, l_param_details_tbl(2).geo_value,
311 l_param_details_tbl(3).geo_type, l_param_details_tbl(3).geo_value,
312 l_param_details_tbl(4).geo_type, l_param_details_tbl(4).geo_value,
313 l_param_details_tbl(5).geo_type, l_param_details_tbl(5).geo_value,
314 l_param_details_tbl(6).geo_type, l_param_details_tbl(6).geo_value,
315 l_param_details_tbl(7).geo_type, l_param_details_tbl(7).geo_value, l_param_details_tbl(7).geo_type;
316 /*
317 ns_debug.put_line('----------------------------------------');
318 ns_debug.put_line('Bind For 7:'||l_country_code||':'||l_country_geo_id||':'||
319 l_param_details_tbl(2).geo_type||':'||l_param_details_tbl(2).geo_value||':'||
320 l_param_details_tbl(3).geo_type||':'||l_param_details_tbl(3).geo_value||':'||
321 l_param_details_tbl(4).geo_type||':'||l_param_details_tbl(4).geo_value||':'||
322 l_param_details_tbl(5).geo_type||':'||l_param_details_tbl(5).geo_value||':'||
323 l_param_details_tbl(6).geo_type||':'||l_param_details_tbl(6).geo_value||':'||
324 l_param_details_tbl(7).geo_type||':'||l_param_details_tbl(7).geo_value||':'||
325 l_param_details_tbl(7).geo_type
326 );
327 */
328 WHEN 8 THEN
329 OPEN cv_sql FOR l_param_details_tbl(i).query_text USING l_country_code, l_country_geo_id,
330 l_param_details_tbl(2).geo_type, l_param_details_tbl(2).geo_value,
331 l_param_details_tbl(3).geo_type, l_param_details_tbl(3).geo_value,
332 l_param_details_tbl(4).geo_type, l_param_details_tbl(4).geo_value,
333 l_param_details_tbl(5).geo_type, l_param_details_tbl(5).geo_value,
334 l_param_details_tbl(6).geo_type, l_param_details_tbl(6).geo_value,
335 l_param_details_tbl(7).geo_type, l_param_details_tbl(7).geo_value,
336 l_param_details_tbl(8).geo_type, l_param_details_tbl(8).geo_value, l_param_details_tbl(8).geo_type;
337 /*
338 ns_debug.put_line('----------------------------------------');
339 ns_debug.put_line('Bind For 8:'||l_country_code||':'||l_country_geo_id||':'||
340 l_param_details_tbl(2).geo_type||':'||l_param_details_tbl(2).geo_value||':'||
341 l_param_details_tbl(3).geo_type||':'||l_param_details_tbl(3).geo_value||':'||
342 l_param_details_tbl(4).geo_type||':'||l_param_details_tbl(4).geo_value||':'||
343 l_param_details_tbl(5).geo_type||':'||l_param_details_tbl(5).geo_value||':'||
344 l_param_details_tbl(6).geo_type||':'||l_param_details_tbl(6).geo_value||':'||
345 l_param_details_tbl(7).geo_type||':'||l_param_details_tbl(7).geo_value||':'||
346 l_param_details_tbl(8).geo_type||':'||l_param_details_tbl(8).geo_value||':'||
347 l_param_details_tbl(8).geo_type
348 );
349 */
350 WHEN 9 THEN
351 OPEN cv_sql FOR l_param_details_tbl(i).query_text USING l_country_code, l_country_geo_id,
352 l_param_details_tbl(2).geo_type, l_param_details_tbl(2).geo_value,
353 l_param_details_tbl(3).geo_type, l_param_details_tbl(3).geo_value,
354 l_param_details_tbl(4).geo_type, l_param_details_tbl(4).geo_value,
355 l_param_details_tbl(5).geo_type, l_param_details_tbl(5).geo_value,
356 l_param_details_tbl(6).geo_type, l_param_details_tbl(6).geo_value,
357 l_param_details_tbl(7).geo_type, l_param_details_tbl(7).geo_value,
358 l_param_details_tbl(8).geo_type, l_param_details_tbl(8).geo_value,
359 l_param_details_tbl(9).geo_type, l_param_details_tbl(9).geo_value, l_param_details_tbl(9).geo_type;
360 /*
361 ns_debug.put_line('----------------------------------------');
362 ns_debug.put_line('Bind For 9:'||l_country_code||':'||l_country_geo_id||':'||
363 l_param_details_tbl(2).geo_type||':'||l_param_details_tbl(2).geo_value||':'||
364 l_param_details_tbl(3).geo_type||':'||l_param_details_tbl(3).geo_value||':'||
365 l_param_details_tbl(4).geo_type||':'||l_param_details_tbl(4).geo_value||':'||
366 l_param_details_tbl(5).geo_type||':'||l_param_details_tbl(5).geo_value||':'||
367 l_param_details_tbl(6).geo_type||':'||l_param_details_tbl(6).geo_value||':'||
368 l_param_details_tbl(7).geo_type||':'||l_param_details_tbl(7).geo_value||':'||
369 l_param_details_tbl(8).geo_type||':'||l_param_details_tbl(8).geo_value||':'||
370 l_param_details_tbl(9).geo_type||':'||l_param_details_tbl(9).geo_value||':'||
371 l_param_details_tbl(9).geo_type
372 );
373 */
374 WHEN 10 THEN
375 OPEN cv_sql FOR l_param_details_tbl(i).query_text USING l_country_code, l_country_geo_id,
376 l_param_details_tbl(2).geo_type, l_param_details_tbl(2).geo_value,
377 l_param_details_tbl(3).geo_type, l_param_details_tbl(3).geo_value,
378 l_param_details_tbl(4).geo_type, l_param_details_tbl(4).geo_value,
379 l_param_details_tbl(5).geo_type, l_param_details_tbl(5).geo_value,
380 l_param_details_tbl(6).geo_type, l_param_details_tbl(6).geo_value,
381 l_param_details_tbl(7).geo_type, l_param_details_tbl(7).geo_value,
382 l_param_details_tbl(8).geo_type, l_param_details_tbl(8).geo_value,
383 l_param_details_tbl(9).geo_type, l_param_details_tbl(9).geo_value,
384 l_param_details_tbl(10).geo_type, l_param_details_tbl(10).geo_value, l_param_details_tbl(10).geo_type;
385 /*
386 ns_debug.put_line('----------------------------------------');
387 ns_debug.put_line('Bind For 10:'||l_country_code||':'||l_country_geo_id||':'||
388 l_param_details_tbl(2).geo_type||':'||l_param_details_tbl(2).geo_value||':'||
389 l_param_details_tbl(3).geo_type||':'||l_param_details_tbl(3).geo_value||':'||
390 l_param_details_tbl(4).geo_type||':'||l_param_details_tbl(4).geo_value||':'||
391 l_param_details_tbl(5).geo_type||':'||l_param_details_tbl(5).geo_value||':'||
392 l_param_details_tbl(6).geo_type||':'||l_param_details_tbl(6).geo_value||':'||
393 l_param_details_tbl(7).geo_type||':'||l_param_details_tbl(7).geo_value||':'||
394 l_param_details_tbl(8).geo_type||':'||l_param_details_tbl(8).geo_value||':'||
395 l_param_details_tbl(9).geo_type||':'||l_param_details_tbl(9).geo_value||':'||
396 l_param_details_tbl(10).geo_type||':'||l_param_details_tbl(10).geo_value||':'||
397 l_param_details_tbl(10).geo_type
398 );
399 */
400
401 END CASE;
402
403 FETCH cv_sql INTO l_count;
404 CLOSE cv_sql;
405
406 -- do count logic here
407 l_level := i;
408 IF (l_count > 0) THEN
409 IF (l_count =1) THEN
410 l_rec_count_flag := '1';
411 l_success_rec_count := '1';
412 ELSE
413 l_rec_count_flag := '2';
414 l_success_rec_count := '2';
415 END IF;
416 l_success_geo_level := l_level; -- used to retain value of
417 -- level for which query can derive records
418 ELSE
419 l_rec_count_flag := '0';
420 --ns_debug.put_line('----------------------------------------');
421 --ns_debug.put_line('Data could not be validated for :'||l_param_details_tbl(i).geo_value||'('||l_param_details_tbl(i).geo_type||')');
422 --l_not_validated_geo_type := l_param_details_tbl(i).geo_type;
423 EXIT;
424 END IF;
425
426 END IF; -- query_text not null
427
428 END IF; -- i=1
429
430 END LOOP;
431
432 ---------------------------------------------------------------------+
433 -- Output processing
434 ---------------------------------------------------------------------+
435 --ns_debug.put_line('----------------------------------------');
436 --ns_debug.put_line('Record Count Flag ='||l_rec_count_flag);
437 --ns_debug.put_line('Level ='||l_level);
438 --ns_debug.put_line('Success Level='||l_success_geo_level);
439
440 -- FND Logging for debug purpose
441 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
442 hz_utility_v2pub.debug
443 (p_message => 'Record Count Flag is:'||l_rec_count_flag||
444 '. Level is:'||l_level||'. Success Geo Level is:'||l_success_geo_level,
445 p_prefix => l_debug_prefix,
446 p_msg_level => fnd_log.level_statement,
447 p_module_prefix => l_module_prefix,
448 p_module => l_module
449 );
450 END IF;
451
452 -- Atleast 1 user input param is wrong.
453 IF (l_rec_count_flag = '0') THEN
454
455 -- If we have unique record till user entered value, tell user values from next level
456 IF (l_success_rec_count = '1') THEN
457 l_not_validated_geo_type := get_geo_type_list(l_geo_struct_tbl, l_success_geo_level+1, 'USAGE');
458
459 -- FND Logging for debug purpose
460 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
461 hz_utility_v2pub.debug
462 (p_message => 'For passed in values we have 1 record at level:'||l_success_geo_level,
463 p_prefix => l_debug_prefix,
464 p_msg_level => fnd_log.level_statement,
465 p_module_prefix => l_module_prefix,
466 p_module => l_module
467 );
468 END IF;
469
470 ELSIF
471 -- If we have multiple records for user entered value, tell user values from that level
472 (l_success_rec_count = '2') THEN
473
474 -- Since last entered value did not fetch any record (i.e is wrong)
475 -- and just before that we have multiple values, get the required fields
476 -- for usage that may be missing and causing multiple values.
477 -- (Fix for Bug 5356895 by Nishant 27-Jun-2006)
478 l_not_validated_geo_type := get_missing_input_fields(l_geo_struct_tbl);
479
480 -- if all fields were entered, then tell user from the last valid value for
481 -- which we got mulptiple records
482 IF (l_not_validated_geo_type IS NULL) THEN
483 l_not_validated_geo_type := get_geo_type_list(l_geo_struct_tbl, l_success_geo_level, 'USAGE');
484 END IF;
485
486 -- FND Logging for debug purpose
487 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
488 hz_utility_v2pub.debug
489 (p_message => 'For passed in values we have multiple records at level:'||l_success_geo_level||
490 '. Geo Type not validated for msg:'||l_not_validated_geo_type,
491 p_prefix => l_debug_prefix,
492 p_msg_level => fnd_log.level_statement,
493 p_module_prefix => l_module_prefix,
494 p_module => l_module
495 );
496 END IF;
497
498 END IF;
499
500 -- FND Logging for debug purpose
501 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
502 hz_utility_v2pub.debug
503 (p_message => 'For Record Count Flag = 0, l_success_rec_count='||l_success_rec_count
504 ||', geo type not validated is :'||l_not_validated_geo_type,
505 p_prefix => l_debug_prefix,
506 p_msg_level => fnd_log.level_statement,
507 p_module_prefix => l_module_prefix,
508 p_module => l_module
509 );
510 END IF;
511
512 --ns_debug.put_line('----------------------------------------');
513 --ns_debug.put_line('Following Geography Components Could Not Be Validated: '||INITCAP(REPLACE(l_not_validated_geo_type,'_',' ')));
514 END IF;
515
516 -- If everthing passed is valid, but not complete.
517 -- i.e. 1. or more rec found but it is not complete for geo usage
518 -- l_rec_count_flag > 0
519 IF (l_not_validated_geo_type IS NULL AND l_level > 0) THEN
520
521 -- FND Logging for debug purpose
522 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
523 hz_utility_v2pub.debug
524 (p_message => 'Everthing passed is valid, but may not be complete, i.e. 1. rec found but it is not complete for geo usage',
525 p_prefix => l_debug_prefix,
526 p_msg_level => fnd_log.level_statement,
527 p_module_prefix => l_module_prefix,
528 p_module => l_module
529 );
530 END IF;
531
532 -- If level is greater than element column value set for geo usage,
533 -- pass max element col value, so that we will get at least 1 element
534 -- in message otherwise, missing element will be NULL.
535 -- Corner case. Should not happen.
536 IF (l_success_geo_level >= lx_max_usage_element_col_value) THEN
537 l_not_validated_geo_type := get_missing_input_fields(l_geo_struct_tbl);
538 --ns_debug.put_line('All geo elements passed are valid, use missing elements for geo');
539 -- FND Logging for debug purpose
540 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
541 hz_utility_v2pub.debug
542 (p_message => 'All geo elements passed are valid, try reporting missing elements for geo',
543 p_prefix => l_debug_prefix,
544 p_msg_level => fnd_log.level_statement,
545 p_module_prefix => l_module_prefix,
546 p_module => l_module
547 );
548 END IF;
549
550 -- Still it is null i.e. all values passed, very tough to figure out
551 -- what exactly is wrong with address then show the component name for full mapping
552 IF (l_not_validated_geo_type IS NULL) THEN
553 IF (l_success_rec_count = '2') THEN -- More than 1 rec found till last usage
554 l_temp_level := l_success_geo_level;
555 IF (l_success_geo_level = lx_max_usage_element_col_value) THEN
556 -- Multiple values found till usage requirement
557 l_temp_usage := 'USAGE';
558 ELSE -- multiple rec found for values beyond usage requirement
559 l_temp_usage := 'MAPPING';
560 END IF;
561
562 ELSE
563 l_temp_level := l_success_geo_level + 1; -- Only 1 record till last usage
564 l_temp_usage := 'MAPPING';
565 END IF;
566
567 l_not_validated_geo_type := get_geo_type_list(l_geo_struct_tbl,l_temp_level,l_temp_usage);
568
569 -- FND Logging for debug purpose
570 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
571 hz_utility_v2pub.debug
572 (p_message => 'All required input fields were populated, '||
573 'very tough to figure out wrong components. '||
574 'Report invalid comp for which multiple rec found for : '||
575 l_temp_usage||' : '||l_not_validated_geo_type,
576 p_prefix => l_debug_prefix,
577 p_msg_level => fnd_log.level_statement,
578 p_module_prefix => l_module_prefix,
579 p_module => l_module
580 );
581 END IF;
582
583 END IF;
584 ELSE
585 -- rec not valid till mapped usage
586 IF (l_success_rec_count = '2') THEN -- More than 1 rec found till last usage
587 l_temp_level := l_success_geo_level;
588 ELSE
589 l_temp_level := l_success_geo_level + 1; -- Only 1 record till last usage
590 END IF;
591
592 l_not_validated_geo_type := get_geo_type_list(l_geo_struct_tbl,l_temp_level,'USAGE');
593
594 -- FND Logging for debug purpose
595 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
596 hz_utility_v2pub.debug
597 (p_message => 'All required geo elements are not passed. Start the list from '||
598 'next level :'||l_not_validated_geo_type,
599 p_prefix => l_debug_prefix,
600 p_msg_level => fnd_log.level_statement,
601 p_module_prefix => l_module_prefix,
602 p_module => l_module
603 );
604 END IF;
605
606 END IF;
607
608 -- FND Logging for debug purpose
609 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
610 hz_utility_v2pub.debug
611 (p_message => 'Everthing passed is valid, but not complete. '||
612 'Following geo type not validated :'||l_not_validated_geo_type,
613 p_prefix => l_debug_prefix,
614 p_msg_level => fnd_log.level_statement,
615 p_module_prefix => l_module_prefix,
616 p_module => l_module
617 );
618 END IF;
619 --ns_debug.put_line('----------------------------------------');
620 --ns_debug.put_line('Passed values are valid but need values for '||INITCAP(REPLACE(l_not_validated_geo_type,'_',' ')));
621 END IF; -- Only country passed check
622
623 x_not_validated_geo_type := l_not_validated_geo_type;
624 x_rec_count_flag := l_rec_count_flag;
625 x_success_geo_level := l_success_geo_level;
626
627 END IF; -- end of geo structure tbl > 0 count
628
629 END IF; -- country found check
630
631 -- FND Logging for debug purpose
632 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
633 hz_utility_v2pub.debug
634 (p_message => 'End procedure validate_input_values_proc(-)',
635 p_prefix => l_debug_prefix,
636 p_msg_level => fnd_log.level_procedure,
637 p_module_prefix => l_module_prefix,
638 p_module => l_module
639 );
640 END IF;
641
642 EXCEPTION WHEN OTHERS THEN
643 --ns_debug.put_line('Exception occured in validate_input_values_proc:'||SQLERRM);
644 -- FND Logging for debug purpose
645 IF (fnd_log.level_exception >= fnd_log.g_current_runtime_level) THEN
646 hz_utility_v2pub.debug
647 (p_message => 'Error in validate_input_values_proc:'||
648 SUBSTR(SQLERRM,1,200),
649 p_prefix => l_debug_prefix,
650 p_msg_level => fnd_log.level_exception,
651 p_module_prefix => l_module_prefix,
652 p_module => l_module
653 );
654 END IF;
655
656 END validate_input_values_proc;
657
658 -----------------------------------------------------------------------------+
659 -- Procedure to do sorting based on suggetion list column in geo_suggest_tbl
660 -- plsql table
661 -- Created By Nishant Singhai (for Bug 4600030 on 28-Sep-2005)
662 -----------------------------------------------------------------------------+
663 PROCEDURE quick_sort_suggestion_list
664 (
665 p_left INTEGER,
666 p_right INTEGER,
667 p_list IN OUT NOCOPY hz_gnr_pvt.geo_suggest_tbl_type
668 )
669 IS
670
671 i INTEGER;
672 j INTEGER;
673 l_left INTEGER := p_left;
674 l_right INTEGER := p_right;
675 l_current_node hz_gnr_pvt.geo_suggest_rec;
676 l_dummy_node hz_gnr_pvt.geo_suggest_rec;
677
678 BEGIN
679
680 IF (l_right > l_left) THEN
681 l_current_node := p_list(l_right);
682 i := l_left -1;
683 j := l_right;
684 LOOP
685 LOOP
686 i := i +1;
687 IF (p_list(i).suggestion_list < l_current_node.suggestion_list) THEN
688 null;
689 ELSE
690 exit;
691 END IF;
692
693 IF (i >= p_list.count) THEN
694 exit;
695 END IF;
696 END LOOP;
697
698 LOOP
699 j := j -1;
700 IF (j <= 0) THEN
701 exit;
702 END IF;
703
704 IF (p_list(j).suggestion_list > l_current_node.suggestion_list) THEN
705 null;
706 ELSE
707 exit;
708 END IF;
709
710 END LOOP;
711
712 IF (i >= j) THEN
713 exit;
714 END IF;
715
716 l_dummy_node := p_list(i);
717 p_list(i) := p_list(j);
718 p_list(j) := l_dummy_node;
719 END LOOP;
720
721 l_dummy_node := p_list(i);
722 p_list(i) := p_list(l_right);
723 p_list(l_right) := l_dummy_node;
724
725 quick_sort_suggestion_list(l_left, i-1, p_list);
726 quick_sort_suggestion_list(i+1, l_right, p_list);
727
728 END IF;
729
730 END quick_sort_suggestion_list;
731
732 ----------------------------------------------------------------------------+
733 -- Procedure to get geography details for any passed in geography name or geo code
734 ----------------------------------------------------------------------------+
735 PROCEDURE get_geo_details_proc (p_geo_code IN VARCHAR2 DEFAULT NULL,
736 p_geo_name IN VARCHAR2 DEFAULT NULL,
737 p_geo_type IN VARCHAR2,
738 p_country_code IN VARCHAR2,
739 x_geo_name OUT nocopy VARCHAR2,
740 x_geo_id OUT nocopy NUMBER,
741 x_geo_code OUT nocopy VARCHAR2
742 ) IS
743 lv_geo_name VARCHAR2(360);
744 lv_geo_code VARCHAR2(100);
745 lv_geo_id NUMBER;
746
747 CURSOR c_geo_name (v_geo_name VARCHAR2, v_geo_type VARCHAR2, v_country_code VARCHAR2) IS
748 SELECT hg.geography_name, hg.geography_id, hg.geography_code
749 FROM hz_geography_identifiers hi
750 ,hz_geographies hg
751 WHERE hi.identifier_type = 'NAME'
752 AND UPPER(hi.identifier_value) = v_geo_name
753 AND hi.geography_type = v_geo_type
754 AND hi.geography_use = 'MASTER_REF'
755 AND hi.geography_id = hg.geography_id
756 AND hg.geography_use = 'MASTER_REF'
757 AND UPPER(hg.country_code) = v_country_code
758 AND SYSDATE BETWEEN hg.START_DATE AND hg.END_DATE
759 ;
760
761 CURSOR c_geo_code (v_geo_code VARCHAR2, v_geo_type VARCHAR2, v_country_code VARCHAR2) IS
762 SELECT hg.geography_name, hg.geography_id, hg.geography_code
763 FROM hz_geography_identifiers hi
764 ,hz_geographies hg
765 WHERE hi.identifier_type = 'CODE'
766 AND UPPER(hi.identifier_value) = v_geo_code
767 AND hi.geography_type = v_geo_type
768 AND hi.geography_use = 'MASTER_REF'
769 AND hi.geography_id = hg.geography_id
770 AND hg.geography_use = 'MASTER_REF'
771 AND UPPER(hg.country_code) = v_country_code
772 AND SYSDATE BETWEEN hg.START_DATE AND hg.END_DATE
773 ;
774
775 BEGIN
776 IF (p_geo_code IS NOT NULL) THEN
777 OPEN c_geo_code(upper(p_geo_code), p_geo_type, upper(p_country_code));
778 FETCH c_geo_code INTO lv_geo_name, lv_geo_id, lv_geo_code;
779 CLOSE c_geo_code;
780 END IF;
781
782 IF ((lv_geo_id IS NULL) AND (p_geo_name IS NOT NULL)) THEN
783 OPEN c_geo_name(upper(p_geo_name), p_geo_type, upper(p_country_code));
784 FETCH c_geo_name INTO lv_geo_name, lv_geo_id, lv_geo_code;
785 CLOSE c_geo_name;
786 END IF;
787
788 x_geo_name := lv_geo_name;
789 x_geo_id := lv_geo_id;
790 x_geo_code := lv_geo_code;
791
792 EXCEPTION WHEN OTHERS
793 THEN NULL;
794 END get_geo_details_proc;
795
796 ----------------------------------------------------------------------------+
797 -- Main procedure to do address search and provide with suggestions
798 -- This procedure takes location components as input and provides suggested
799 -- values in plsql table format
800 ----------------------------------------------------------------------------+
801 PROCEDURE search_geographies
802 (
803 p_table_name IN VARCHAR2,
804 p_address_style IN VARCHAR2,
805 p_address_usage IN VARCHAR2,
806 p_country_code IN HZ_LOCATIONS.COUNTRY%TYPE,
807 p_state IN HZ_LOCATIONS.STATE%TYPE,
808 p_province IN HZ_LOCATIONS.PROVINCE%TYPE,
809 p_county IN HZ_LOCATIONS.COUNTY%TYPE,
810 p_city IN HZ_LOCATIONS.CITY%TYPE,
811 p_postal_code IN HZ_LOCATIONS.POSTAL_CODE%TYPE,
812 p_postal_plus4_code IN HZ_LOCATIONS.POSTAL_PLUS4_CODE%TYPE,
813 p_attribute1 IN HZ_LOCATIONS.ATTRIBUTE1%TYPE,
814 p_attribute2 IN HZ_LOCATIONS.ATTRIBUTE2%TYPE,
815 p_attribute3 IN HZ_LOCATIONS.ATTRIBUTE3%TYPE,
816 p_attribute4 IN HZ_LOCATIONS.ATTRIBUTE4%TYPE,
817 p_attribute5 IN HZ_LOCATIONS.ATTRIBUTE5%TYPE,
818 p_attribute6 IN HZ_LOCATIONS.ATTRIBUTE6%TYPE,
819 p_attribute7 IN HZ_LOCATIONS.ATTRIBUTE7%TYPE,
820 p_attribute8 IN HZ_LOCATIONS.ATTRIBUTE8%TYPE,
821 p_attribute9 IN HZ_LOCATIONS.ATTRIBUTE9%TYPE,
822 p_attribute10 IN HZ_LOCATIONS.ATTRIBUTE10%TYPE,
823 x_mapped_struct_count OUT NOCOPY NUMBER,
824 x_records_count OUT NOCOPY NUMBER,
825 x_return_code OUT NOCOPY NUMBER,
826 x_validation_level OUT NOCOPY VARCHAR2,
827 x_geo_suggest_tbl OUT NOCOPY HZ_GNR_PVT.geo_suggest_tbl_type,
828 x_geo_struct_tbl OUT NOCOPY HZ_GNR_PVT.geo_struct_tbl_type,
829 x_geo_suggest_misc_rec OUT NOCOPY HZ_GNR_PVT.geo_suggest_misc_rec,
830 x_return_status OUT NOCOPY VARCHAR2,
831 x_msg_count OUT NOCOPY NUMBER,
832 x_msg_data OUT NOCOPY VARCHAR2
833 ) IS
834
835 l_select VARCHAR2(2000);
836 l_select_6 VARCHAR2(1000);
837 l_from VARCHAR2(1000);
838 l_from_5 VARCHAR2(500);
839 l_from_6 VARCHAR2(500);
840 l_from_7 VARCHAR2(500);
841 l_where VARCHAR2(2800);
842 l_where_1 VARCHAR2(2600);
843 l_where_3 VARCHAR2(600);
844 l_where_4 VARCHAR2(600);
845 l_where_5 VARCHAR2(2600);
846 l_where_6 VARCHAR2(2600);
847 l_where_7 VARCHAR2(2600);
848 l_order_by VARCHAR2(200);
849 l_sql_stmt VARCHAR2(10000);
850 l_sql_stmt_2 VARCHAR2(10000);
851 l_sql_stmt_3 VARCHAR2(10000);
852
853 l_priv_valid_index NUMBER;
854 l_priv_valid_index_6 NUMBER;
855 l_priv_valid_index_7 NUMBER;
856 l_count_for_where_clause_2 NUMBER;
857 l_count_for_where_clause_3 NUMBER;
858
859 l_max_fetch_count NUMBER;
860 l_address_usage VARCHAR2(100);
861
862 l_error_location VARCHAR2(100);
863
864 l_country_only_passed VARCHAR2(1);
865 l_country_only_mapped VARCHAR2(1);
866 l_country_only_name HZ_GEOGRAPHIES.GEOGRAPHY_NAME%TYPE;
867 l_country_only_id HZ_GEOGRAPHIES.GEOGRAPHY_ID%TYPE;
868 l_country_only_code HZ_GEOGRAPHIES.GEOGRAPHY_CODE%TYPE;
869 l_search_type VARCHAR2(100);
870 l_addr_val_level VARCHAR2(100);
871
872 l_max_passed_element_col_value NUMBER;
873 l_max_mapped_element_col_value NUMBER;
874 l_max_usage_element_col_value NUMBER;
875 l_lowest_usage_geo_type hz_geographies.GEOGRAPHY_TYPE%TYPE;
876 l_last_geo_type_usg_val_psd hz_geographies.GEOGRAPHY_TYPE%TYPE;
877 l_lowest_passed_geo_type hz_geographies.GEOGRAPHY_TYPE%TYPE;
878 l_lowest_mapped_geo_type hz_geographies.GEOGRAPHY_TYPE%TYPE;
879 l_lowest_passed_geo_value hz_geographies.GEOGRAPHY_NAME%TYPE;
880 l_geo_data_count INTEGER;
881
882 l_success VARCHAR2(10);
883 l_geo_validation_passed VARCHAR2(10);
884 l_check_geo_type_not_passed VARCHAR2(255);
885 LX_ADDR_VAL_LEVEL VARCHAR2(30);
886 LX_ADDR_WARN_MSG VARCHAR2(1000);
887 LX_ADDR_VAL_STATUS VARCHAR2(10);
888 LX_STATUS VARCHAR2(10);
889
890 lx_not_validated_geo_type VARCHAR2(255);
891 lx_rec_count_flag VARCHAR2(10);
892 lx_success_geo_level NUMBER;
893
894 TYPE GeoCurTyp IS REF CURSOR;
895 geo_cv GeoCurTyp;
896
897 ------ multi parent variables
898 l_select_mp VARCHAR2(1000);
899 l_from_mp VARCHAR2(1000);
900 l_where_mp VARCHAR2(6000);
901 l_sql_stmt_mp VARCHAR2(10000);
902 l_struct_level_count_mp NUMBER;
903 l_last_index_mp NUMBER;
904 l_total_null_cols_mp NUMBER;
905
906 ------ multi parent record
907 TYPE rec_type_mp IS RECORD
908 (
909 geo_id_1 HZ_GEOGRAPHIES.GEOGRAPHY_ID%TYPE,
910 geo_name_1 HZ_GEOGRAPHIES.GEOGRAPHY_NAME%TYPE,
911 geo_code_1 HZ_GEOGRAPHIES.GEOGRAPHY_CODE%TYPE,
912 geo_type_1 HZ_GEOGRAPHIES.GEOGRAPHY_TYPE%TYPE,
913 geo_id_2 HZ_GEOGRAPHIES.GEOGRAPHY_ID%TYPE,
914 geo_name_2 HZ_GEOGRAPHIES.GEOGRAPHY_NAME%TYPE,
915 geo_code_2 HZ_GEOGRAPHIES.GEOGRAPHY_CODE%TYPE,
916 geo_type_2 HZ_GEOGRAPHIES.GEOGRAPHY_TYPE%TYPE,
917 geo_id_3 HZ_GEOGRAPHIES.GEOGRAPHY_ID%TYPE,
918 geo_name_3 HZ_GEOGRAPHIES.GEOGRAPHY_NAME%TYPE,
919 geo_code_3 HZ_GEOGRAPHIES.GEOGRAPHY_CODE%TYPE,
920 geo_type_3 HZ_GEOGRAPHIES.GEOGRAPHY_TYPE%TYPE,
921 geo_id_4 HZ_GEOGRAPHIES.GEOGRAPHY_ID%TYPE,
922 geo_name_4 HZ_GEOGRAPHIES.GEOGRAPHY_NAME%TYPE,
923 geo_code_4 HZ_GEOGRAPHIES.GEOGRAPHY_CODE%TYPE,
924 geo_type_4 HZ_GEOGRAPHIES.GEOGRAPHY_TYPE%TYPE,
925 geo_id_5 HZ_GEOGRAPHIES.GEOGRAPHY_ID%TYPE,
926 geo_name_5 HZ_GEOGRAPHIES.GEOGRAPHY_NAME%TYPE,
927 geo_code_5 HZ_GEOGRAPHIES.GEOGRAPHY_CODE%TYPE,
928 geo_type_5 HZ_GEOGRAPHIES.GEOGRAPHY_TYPE%TYPE,
929 geo_id_6 HZ_GEOGRAPHIES.GEOGRAPHY_ID%TYPE,
930 geo_name_6 HZ_GEOGRAPHIES.GEOGRAPHY_NAME%TYPE,
931 geo_code_6 HZ_GEOGRAPHIES.GEOGRAPHY_CODE%TYPE,
932 geo_type_6 HZ_GEOGRAPHIES.GEOGRAPHY_TYPE%TYPE,
933 geo_id_7 HZ_GEOGRAPHIES.GEOGRAPHY_ID%TYPE,
934 geo_name_7 HZ_GEOGRAPHIES.GEOGRAPHY_NAME%TYPE,
935 geo_code_7 HZ_GEOGRAPHIES.GEOGRAPHY_CODE%TYPE,
936 geo_type_7 HZ_GEOGRAPHIES.GEOGRAPHY_TYPE%TYPE,
937 geo_id_8 HZ_GEOGRAPHIES.GEOGRAPHY_ID%TYPE,
938 geo_name_8 HZ_GEOGRAPHIES.GEOGRAPHY_NAME%TYPE,
939 geo_code_8 HZ_GEOGRAPHIES.GEOGRAPHY_CODE%TYPE,
940 geo_type_8 HZ_GEOGRAPHIES.GEOGRAPHY_TYPE%TYPE,
941 geo_id_9 HZ_GEOGRAPHIES.GEOGRAPHY_ID%TYPE,
942 geo_name_9 HZ_GEOGRAPHIES.GEOGRAPHY_NAME%TYPE,
943 geo_code_9 HZ_GEOGRAPHIES.GEOGRAPHY_CODE%TYPE,
944 geo_type_9 HZ_GEOGRAPHIES.GEOGRAPHY_TYPE%TYPE,
945 geo_id_10 HZ_GEOGRAPHIES.GEOGRAPHY_ID%TYPE,
946 geo_name_10 HZ_GEOGRAPHIES.GEOGRAPHY_NAME%TYPE,
947 geo_code_10 HZ_GEOGRAPHIES.GEOGRAPHY_CODE%TYPE,
948 geo_type_10 HZ_GEOGRAPHIES.GEOGRAPHY_TYPE%TYPE
949 );
950
951 rec_mp rec_type_mp;
952
953 TYPE cur_type_mp IS REF CURSOR;
954 cv_mp cur_type_mp;
955
956 -----intermediate table record
957 TYPE geo_rec_type IS RECORD
958 (
959 GEOGRAPHY_ID hz_geographies.GEOGRAPHY_ID%TYPE,
960 GEOGRAPHY_TYPE hz_geographies.GEOGRAPHY_TYPE%TYPE,
961 GEOGRAPHY_NAME hz_geographies.GEOGRAPHY_NAME%TYPE,
962 GEOGRAPHY_CODE hz_geographies.GEOGRAPHY_CODE%TYPE,
963 MULTIPLE_PARENT_FLAG hz_geographies.MULTIPLE_PARENT_FLAG%TYPE,
964 COUNTRY_CODE hz_geographies.COUNTRY_CODE%TYPE,
965 GEOGRAPHY_ELEMENT1 hz_geographies.GEOGRAPHY_ELEMENT1%TYPE,
966 GEOGRAPHY_ELEMENT1_ID hz_geographies.GEOGRAPHY_ELEMENT1_ID%TYPE,
967 GEOGRAPHY_ELEMENT1_CODE hz_geographies.GEOGRAPHY_ELEMENT1_CODE%TYPE,
968 GEOGRAPHY_ELEMENT2 hz_geographies.GEOGRAPHY_ELEMENT2%TYPE,
969 GEOGRAPHY_ELEMENT2_ID hz_geographies.GEOGRAPHY_ELEMENT2_ID%TYPE,
970 GEOGRAPHY_ELEMENT2_CODE hz_geographies.GEOGRAPHY_ELEMENT2_CODE%TYPE,
971 GEOGRAPHY_ELEMENT3 hz_geographies.GEOGRAPHY_ELEMENT3%TYPE,
972 GEOGRAPHY_ELEMENT3_ID hz_geographies.GEOGRAPHY_ELEMENT3_ID%TYPE,
973 GEOGRAPHY_ELEMENT3_CODE hz_geographies.GEOGRAPHY_ELEMENT3_CODE%TYPE,
974 GEOGRAPHY_ELEMENT4 hz_geographies.GEOGRAPHY_ELEMENT4%TYPE,
975 GEOGRAPHY_ELEMENT4_ID hz_geographies.GEOGRAPHY_ELEMENT4_ID%TYPE,
976 GEOGRAPHY_ELEMENT4_CODE hz_geographies.GEOGRAPHY_ELEMENT4_CODE%TYPE,
977 GEOGRAPHY_ELEMENT5 hz_geographies.GEOGRAPHY_ELEMENT5%TYPE,
978 GEOGRAPHY_ELEMENT5_ID hz_geographies.GEOGRAPHY_ELEMENT5_ID%TYPE,
979 GEOGRAPHY_ELEMENT5_CODE hz_geographies.GEOGRAPHY_ELEMENT5_CODE%TYPE,
980 GEOGRAPHY_ELEMENT6 hz_geographies.GEOGRAPHY_ELEMENT6%TYPE,
981 GEOGRAPHY_ELEMENT6_ID hz_geographies.GEOGRAPHY_ELEMENT6_ID%TYPE,
982 GEOGRAPHY_ELEMENT7 hz_geographies.GEOGRAPHY_ELEMENT7%TYPE,
983 GEOGRAPHY_ELEMENT7_ID hz_geographies.GEOGRAPHY_ELEMENT7_ID%TYPE,
984 GEOGRAPHY_ELEMENT8 hz_geographies.GEOGRAPHY_ELEMENT8%TYPE,
985 GEOGRAPHY_ELEMENT8_ID hz_geographies.GEOGRAPHY_ELEMENT8_ID%TYPE,
986 GEOGRAPHY_ELEMENT9 hz_geographies.GEOGRAPHY_ELEMENT9%TYPE,
987 GEOGRAPHY_ELEMENT9_ID hz_geographies.GEOGRAPHY_ELEMENT9_ID%TYPE,
988 GEOGRAPHY_ELEMENT10 hz_geographies.GEOGRAPHY_ELEMENT10%TYPE,
989 GEOGRAPHY_ELEMENT10_ID hz_geographies.GEOGRAPHY_ELEMENT10_ID%TYPE
990 );
991
992 TYPE geo_rec_tbl_type IS TABLE OF geo_rec_type INDEX BY BINARY_INTEGER;
993
994 geo_rec geo_rec_type;
995 geo_rec_tbl geo_rec_tbl_type;
996
997 geo_struct_tbl HZ_GNR_PVT.geo_struct_tbl_type;
998 geo_suggest_tbl HZ_GNR_PVT.geo_suggest_tbl_type;
999
1000 l_geo_rec_tab_col hz_geo_struct_map_dtl.loc_component%TYPE;
1001 l_geo_rec_geo_type hz_geo_struct_map_dtl.geography_type%TYPE;
1002 l_geo_rec_geo_name hz_geographies.geography_name%TYPE;
1003 l_geo_rec_geo_id hz_geographies.geography_id%TYPE;
1004 l_geo_rec_geo_code hz_geographies.geography_code%TYPE;
1005 l_geo_rec_country_code hz_geographies.country_code%TYPE;
1006
1007 l_not_validated_geo_type VARCHAR2(200);
1008 l_rec_count_flag VARCHAR2(10);
1009
1010 -- variables for dynamic bind to query
1011 TYPE bind_rec_type IS RECORD (bind_value VARCHAR2(2000));
1012 TYPE bind_tbl_type IS TABLE OF bind_rec_type INDEX BY binary_integer;
1013 bind_table_1 bind_tbl_type;
1014 bind_table_2 bind_tbl_type;
1015 bind_table_3 bind_tbl_type;
1016 l_bind_counter NUMBER := 0;
1017
1018 ---------------------------------------------------------------------+
1019 -- function to get table column name of hz_locations
1020 -- input is element column name from hz_geographies stored in mapping table
1021 ---------------------------------------------------------------------+
1022 FUNCTION get_mapped_tab_col (pf_element_column_name IN VARCHAR2) RETURN VARCHAR2
1023 IS
1024 x_loc_col VARCHAR2(100);
1025 BEGIN
1026 IF (geo_struct_tbl IS NOT NULL) THEN
1027 IF (geo_struct_tbl.COUNT > 0) THEN
1028 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
1029 IF (upper(geo_struct_tbl(i).v_element_col) = UPPER(pf_element_column_name)) THEN
1030 x_loc_col := geo_struct_tbl(i).v_tab_col;
1031 END IF;
1032 END LOOP;
1033 END IF;
1034 END IF;
1035 RETURN x_loc_col;
1036 END get_mapped_tab_col;
1037
1038 ---------------------------------------------------------------------+
1039 -- function to get table column name of hz_locations
1040 -- input is geography type stored in mapping table
1041 ---------------------------------------------------------------------+
1042 FUNCTION get_tab_col_from_geo_type (pf_geo_type IN VARCHAR2) RETURN VARCHAR2
1043 IS
1044 x_loc_col VARCHAR2(100);
1045 BEGIN
1046 IF (geo_struct_tbl IS NOT NULL) THEN
1047 IF (geo_struct_tbl.COUNT > 0) THEN
1048 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
1049 IF (upper(geo_struct_tbl(i).v_geo_type) = UPPER(pf_geo_type)) THEN
1050 x_loc_col := geo_struct_tbl(i).v_tab_col;
1051 END IF;
1052 END LOOP;
1053 END IF;
1054 END IF;
1055 RETURN x_loc_col;
1056 END get_tab_col_from_geo_type;
1057
1058 ---------------------------------------------------------------------+
1059 -- function to get element column name of hz_geographies
1060 -- input is geography type from hz_geographies stored in mapping table
1061 ---------------------------------------------------------------------+
1062 FUNCTION get_element_col_for_geo_type (pf_geo_type IN VARCHAR2) RETURN VARCHAR2
1063 IS
1064 x_element_col VARCHAR2(100);
1065 BEGIN
1066 IF (geo_struct_tbl IS NOT NULL) THEN
1067 IF (geo_struct_tbl.COUNT > 0) THEN
1068 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
1069 IF (upper(geo_struct_tbl(i).v_geo_type) = UPPER(pf_geo_type)) THEN
1070 x_element_col := geo_struct_tbl(i).v_element_col;
1071 END IF;
1072 END LOOP;
1073 END IF;
1074 END IF;
1075 RETURN x_element_col;
1076 END get_element_col_for_geo_type;
1077
1078 ---------------------------------------------------------------------+
1079 -- function to get geo type
1080 -- input is table column name from hz_locations stored in mapping table
1081 ---------------------------------------------------------------------+
1082 FUNCTION get_mapped_geo_type (pf_loc_column_name IN VARCHAR2) RETURN VARCHAR2
1083 IS
1084 x_geo_type VARCHAR2(100);
1085 BEGIN
1086 IF (geo_struct_tbl IS NOT NULL) THEN
1087 IF (geo_struct_tbl.COUNT > 0) THEN
1088 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
1089 IF (upper(geo_struct_tbl(i).v_tab_col) = UPPER(pf_loc_column_name)) THEN
1090 x_geo_type := geo_struct_tbl(i).v_geo_type;
1091 END IF;
1092 END LOOP;
1093 END IF;
1094 END IF;
1095 RETURN x_geo_type;
1096 END get_mapped_geo_type;
1097
1098 ---------------------------------------------------------------------+
1099 -- function to get geography type for mapped column
1100 -- input is element column from hz_geographies stored in mapping table
1101 ---------------------------------------------------------------------+
1102 FUNCTION get_geo_type_from_element_col (pf_element_column IN VARCHAR2) RETURN VARCHAR2
1103 IS
1104 x_geo_type VARCHAR2(100);
1105 BEGIN
1106 IF (geo_struct_tbl IS NOT NULL) THEN
1107 IF (geo_struct_tbl.COUNT > 0) THEN
1108 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
1109 IF (UPPER(geo_struct_tbl(i).v_element_col) = UPPER(pf_element_column)) THEN
1110 x_geo_type := geo_struct_tbl(i).v_geo_type;
1111 END IF;
1112 END LOOP;
1113 END IF;
1114 END IF;
1115 RETURN x_geo_type;
1116 END get_geo_type_from_element_col;
1117
1118 ---------------------------------------------------------------------+
1119 -- function to get parameter value
1120 -- input is column name from hz_locations stored in mapping table
1121 ---------------------------------------------------------------------+
1122 FUNCTION get_mapped_param_value (pf_loc_column_name IN VARCHAR2) RETURN VARCHAR2
1123 IS
1124 x_param_value VARCHAR2(100);
1125 BEGIN
1126 IF (geo_struct_tbl IS NOT NULL) THEN
1127 IF (geo_struct_tbl.COUNT > 0) THEN
1128 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
1129 IF (upper(geo_struct_tbl(i).v_tab_col) = UPPER(pf_loc_column_name)) THEN
1130 x_param_value := geo_struct_tbl(i).v_param_value;
1131 END IF;
1132 END LOOP;
1133 END IF;
1134 END IF;
1135 RETURN x_param_value;
1136 END get_mapped_param_value;
1137
1138 ---------------------------------------------------------------------+
1139 -- function to get parameter value from element column
1140 -- input is element column name stored in mapping table
1141 ---------------------------------------------------------------------+
1142 FUNCTION get_map_param_val_for_element (pf_element_col IN VARCHAR2) RETURN VARCHAR2
1143 IS
1144 x_param_value VARCHAR2(100);
1145 BEGIN
1146 IF (geo_struct_tbl IS NOT NULL) THEN
1147 IF (geo_struct_tbl.COUNT > 0) THEN
1148 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
1149 IF (upper(geo_struct_tbl(i).v_element_col) = UPPER(pf_element_col)) THEN
1150 x_param_value := geo_struct_tbl(i).v_param_value;
1151 END IF;
1152 END LOOP;
1153 END IF;
1154 END IF;
1155 RETURN x_param_value;
1156 END get_map_param_val_for_element;
1157
1158
1159 ---------------------------------------------------------------------+
1160 -- Procedure to build l_where_5 (detailed search where clause) based on column
1161 -- names of HZ_LOCATIONS stored in mapping table
1162 -- and update geo_struct_tbl with passed in parameter value
1163 -- it also checks if lowest level parameter is passed
1164 -- Retaining the procedure as this logic is performing faster. Drawback in
1165 -- this procedure is that it does not fetch multiple parents records.
1166 ---------------------------------------------------------------------+
1167 PROCEDURE create_where_1_clause_pvt (ll_index NUMBER, ll_passed_param VARCHAR2, ll_search_type VARCHAR2)
1168 IS
1169 BEGIN
1170 IF (ll_passed_param IS NOT NULL) THEN
1171
1172 -- get the max element coumn for which a parameter value is passed
1173 -- e.g. if max value of element col is geography_element4, get "4" out of it
1174 l_max_passed_element_col_value :=
1175 GREATEST(NVL(l_max_passed_element_col_value,0),TO_NUMBER(SUBSTR(geo_struct_tbl(ll_index).v_element_col,18)));
1176
1177 l_lowest_passed_geo_type := geo_struct_tbl(ll_index).v_geo_type;
1178 l_lowest_passed_geo_value := geo_struct_tbl(ll_index).v_param_value;
1179
1180 -- Build dynamic where clause for detailed search (search2)
1181 /* -- sample query
1182 AND hg0.geography_element1_id = hgi1.geography_id
1183 AND hgi1.geography_use = hg0.geography_use
1184 AND hgi1.geography_type = 'COUNTRY'
1185 AND UPPER(hgi1.identifier_value) LIKE UPPER('us%')
1186 --AND hgi1.identifier_type = 'CODE' -- 'NAME'
1187 */
1188
1189 l_from_5 := l_from_5 ||', hz_geography_identifiers hg'||ll_index;
1190
1191 l_where_5 := l_where_5 ||' AND hg0.'||geo_struct_tbl(ll_index).v_element_col||'_id = hg'||ll_index||'.geography_id'
1192 ||' AND hg'||ll_index||'.geography_use = hg'||to_char(l_priv_valid_index)||'.geography_use'
1193 ||' AND hg'||ll_index||'.geography_type = :x_'||ll_index||'_1 '
1194 ||' AND UPPER(hg'||ll_index||'.identifier_value) LIKE :x_'||ll_index||'_2 ';
1195
1196 bind_table_1(bind_table_1.COUNT+1).bind_value := geo_struct_tbl(ll_index).v_geo_type;
1197 bind_table_1(bind_table_1.COUNT+1).bind_value := geo_struct_tbl(ll_index).v_param_value;
1198
1199 -- default is search type = 'BOTH' so that identifier type is ignored.
1200 -- only for country it is 'CODE'
1201 IF (ll_search_type IN ('NAME','CODE')) THEN
1202 l_where_5 := l_where_5||' AND hg'||ll_index||'.identifier_type = :x_'||ll_index||'_3 ';
1203 bind_table_1(bind_table_1.COUNT+1).bind_value := ll_search_type;
1204 END IF;
1205
1206 -- update previus valid index to use in building where clause
1207 l_priv_valid_index := ll_index;
1208
1209 END IF;
1210
1211 END create_where_1_clause_pvt;
1212
1213 ----------------------------------------------------------------------------+
1214 -- Procedure to create where clause for Search 3 (Union of 1+2+last passed
1215 -- element and 1+2+(last-1)passed element
1216 ----------------------------------------------------------------------------+
1217 PROCEDURE create_where_2_clause_pvt (ll_index NUMBER, ll_sql_id NUMBER) IS
1218 BEGIN
1219 -- 1st select stmt
1220 IF (ll_sql_id = 1) THEN
1221 l_from_6 := l_from_6 ||', hz_geography_identifiers hg'||ll_index;
1222
1223 -- we are adding country_code in where clause. This has to be done only once
1224 -- so putting the check of index = 1
1225 IF (ll_index = 1) THEN
1226 l_where_6 := ' WHERE hg0.geography_use = ''MASTER_REF'' '||
1227 ' AND SYSDATE between hg0.start_date and hg0.end_date '||
1228 ' AND upper(hg0.country_code) = :x_country_code_1 '||
1229 ' AND hg0.multiple_parent_flag = ''N'' ';
1230 bind_table_2(bind_table_2.COUNT+1).bind_value := UPPER(p_country_code);
1231 END IF;
1232
1233 l_where_6 := l_where_6 ||' AND hg0.'||geo_struct_tbl(ll_index).v_element_col||'_id = hg'||ll_index||'.geography_id'
1234 ||' AND hg'||ll_index||'.geography_use = hg'||to_char(l_priv_valid_index_6)||'.geography_use'
1235 ||' AND hg'||ll_index||'.geography_type = :x_'||ll_index||'_1 '
1236 ||' AND UPPER(hg'||ll_index||'.identifier_value) LIKE :x_'||ll_index||'_2 ';
1237
1238 bind_table_2(bind_table_2.COUNT+1).bind_value := geo_struct_tbl(ll_index).v_geo_type;
1239 bind_table_2(bind_table_2.COUNT+1).bind_value := geo_struct_tbl(ll_index).v_param_value;
1240
1241 -- update previus valid index to use in building where clause
1242 l_priv_valid_index_6 := ll_index;
1243 END IF;
1244
1245 -- 2nd select stmt
1246 IF (ll_sql_id = 2) THEN
1247
1248 l_from_7 := l_from_7 ||', hz_geography_identifiers hg'||ll_index;
1249
1250 -- we are adding country_code in where clause. This has to be done only once
1251 -- so putting the check of index = 1
1252 IF (ll_index = 1) THEN
1253 l_where_7 := ' WHERE hg0.geography_use = ''MASTER_REF'' '||
1254 ' AND SYSDATE between hg0.start_date and hg0.end_date '||
1255 ' AND upper(hg0.country_code) = :x_country_code_2 ' ||
1256 ' AND hg0.multiple_parent_flag = ''N'' ' ;
1257 bind_table_2(bind_table_2.COUNT+1).bind_value := UPPER(p_country_code);
1258 END IF;
1259
1260 l_where_7 := l_where_7 ||' AND hg0.'||geo_struct_tbl(ll_index).v_element_col||'_id = hg'||ll_index||'.geography_id'
1261 ||' AND hg'||ll_index||'.geography_use = hg'||to_char(l_priv_valid_index_7)||'.geography_use'
1262 ||' AND hg'||ll_index||'.geography_type = :x_'||ll_index||'_11 '
1263 ||' AND UPPER(hg'||ll_index||'.identifier_value) LIKE :x_'||ll_index||'_12 ';
1264
1265 bind_table_2(bind_table_2.COUNT+1).bind_value := geo_struct_tbl(ll_index).v_geo_type;
1266 bind_table_2(bind_table_2.COUNT+1).bind_value := geo_struct_tbl(ll_index).v_param_value;
1267 -- update previus valid index to use in building where clause
1268 l_priv_valid_index_7 := ll_index;
1269 END IF;
1270
1271 END create_where_2_clause_pvt;
1272
1273 ---------------------------------------------------------------------+
1274 -- Main insert procedure which populates Final plsql table geo_suggest_tbl
1275 ---------------------------------------------------------------------+
1276 PROCEDURE insert_in_geo_suggest_tbl (pv_geo_data_count NUMBER,
1277 pv_geo_rec_tab_col VARCHAR2,
1278 pv_geo_rec_geo_name VARCHAR2,
1279 pv_geo_rec_geo_id NUMBER,
1280 pv_geo_rec_geo_code VARCHAR2)
1281 IS
1282 pv_geo_rec_geo_type VARCHAR2(100);
1283 lv_geo_rec_geo_name VARCHAR2(360);
1284 BEGIN
1285 IF (pv_geo_rec_tab_col IS NOT NULL
1286 ) THEN
1287
1288 pv_geo_rec_geo_type := get_mapped_geo_type(pv_geo_rec_tab_col);
1289 IF (pv_geo_rec_geo_code IN ('MISSING','UNKNOWN')) THEN -- if code is missing or unknown
1290 lv_geo_rec_geo_name := NULL;
1291 ELSE
1292 lv_geo_rec_geo_name := pv_geo_rec_geo_name;
1293 END IF;
1294
1295 CASE pv_geo_rec_tab_col
1296 WHEN 'COUNTRY' THEN
1297 geo_suggest_tbl(pv_geo_data_count).country := lv_geo_rec_geo_name;
1298 geo_suggest_tbl(pv_geo_data_count).country_geo_id := pv_geo_rec_geo_id;
1299 geo_suggest_tbl(pv_geo_data_count).country_code := pv_geo_rec_geo_code;
1300 geo_suggest_tbl(pv_geo_data_count).country_geo_type := pv_geo_rec_geo_type;
1301 WHEN 'STATE' THEN
1302 geo_suggest_tbl(pv_geo_data_count).state := lv_geo_rec_geo_name;
1303 geo_suggest_tbl(pv_geo_data_count).state_geo_id := pv_geo_rec_geo_id;
1304 geo_suggest_tbl(pv_geo_data_count).state_code := pv_geo_rec_geo_code;
1305 geo_suggest_tbl(pv_geo_data_count).state_geo_type := pv_geo_rec_geo_type;
1306 WHEN 'PROVINCE' THEN
1307 geo_suggest_tbl(pv_geo_data_count).province := lv_geo_rec_geo_name;
1308 geo_suggest_tbl(pv_geo_data_count).province_geo_id := pv_geo_rec_geo_id;
1309 geo_suggest_tbl(pv_geo_data_count).province_code := pv_geo_rec_geo_code;
1310 geo_suggest_tbl(pv_geo_data_count).province_geo_type := pv_geo_rec_geo_type;
1311 WHEN 'COUNTY' THEN
1312 geo_suggest_tbl(pv_geo_data_count).county := INITCAP(lv_geo_rec_geo_name);
1313 geo_suggest_tbl(pv_geo_data_count).county_geo_id := pv_geo_rec_geo_id;
1314 geo_suggest_tbl(pv_geo_data_count).county_geo_type := pv_geo_rec_geo_type;
1315 WHEN 'CITY' THEN
1316 geo_suggest_tbl(pv_geo_data_count).city := INITCAP(lv_geo_rec_geo_name);
1317 geo_suggest_tbl(pv_geo_data_count).city_geo_id := pv_geo_rec_geo_id;
1318 geo_suggest_tbl(pv_geo_data_count).city_geo_type := pv_geo_rec_geo_type;
1319 WHEN 'POSTAL_CODE' THEN
1320 geo_suggest_tbl(pv_geo_data_count).postal_code := lv_geo_rec_geo_name;
1321 geo_suggest_tbl(pv_geo_data_count).postal_code_geo_id := pv_geo_rec_geo_id;
1322 geo_suggest_tbl(pv_geo_data_count).postal_code_geo_type := pv_geo_rec_geo_type;
1323 WHEN 'POSTAL_PLUS4_CODE' THEN
1324 geo_suggest_tbl(pv_geo_data_count).postal_plus4_code := lv_geo_rec_geo_name;
1325 geo_suggest_tbl(pv_geo_data_count).postal_plus4_code_geo_id := pv_geo_rec_geo_id;
1326 geo_suggest_tbl(pv_geo_data_count).postal_plus4_code_geo_type := pv_geo_rec_geo_type;
1327 WHEN 'ATTRIBUTE1' THEN
1328 geo_suggest_tbl(pv_geo_data_count).attribute1 := lv_geo_rec_geo_name;
1329 geo_suggest_tbl(pv_geo_data_count).attribute1_geo_id := pv_geo_rec_geo_id;
1330 geo_suggest_tbl(pv_geo_data_count).attribute1_geo_type := pv_geo_rec_geo_type;
1331 WHEN 'ATTRIBUTE2' THEN
1332 geo_suggest_tbl(pv_geo_data_count).attribute2 := lv_geo_rec_geo_name;
1333 geo_suggest_tbl(pv_geo_data_count).attribute2_geo_id := pv_geo_rec_geo_id;
1334 geo_suggest_tbl(pv_geo_data_count).attribute2_geo_type := pv_geo_rec_geo_type;
1335 WHEN 'ATTRIBUTE3' THEN
1336 geo_suggest_tbl(pv_geo_data_count).attribute3 := lv_geo_rec_geo_name;
1337 geo_suggest_tbl(pv_geo_data_count).attribute3_geo_id := pv_geo_rec_geo_id;
1338 geo_suggest_tbl(pv_geo_data_count).attribute3_geo_type := pv_geo_rec_geo_type;
1339 WHEN 'ATTRIBUTE4' THEN
1340 geo_suggest_tbl(pv_geo_data_count).attribute4 := lv_geo_rec_geo_name;
1341 geo_suggest_tbl(pv_geo_data_count).attribute4_geo_id := pv_geo_rec_geo_id;
1342 geo_suggest_tbl(pv_geo_data_count).attribute4_geo_type := pv_geo_rec_geo_type;
1343 WHEN 'ATTRIBUTE5' THEN
1344 geo_suggest_tbl(pv_geo_data_count).attribute5 := lv_geo_rec_geo_name;
1345 geo_suggest_tbl(pv_geo_data_count).attribute5_geo_id := pv_geo_rec_geo_id;
1346 geo_suggest_tbl(pv_geo_data_count).attribute5_geo_type := pv_geo_rec_geo_type;
1347 WHEN 'ATTRIBUTE6' THEN
1348 geo_suggest_tbl(pv_geo_data_count).attribute6 := lv_geo_rec_geo_name;
1349 geo_suggest_tbl(pv_geo_data_count).attribute6_geo_id := pv_geo_rec_geo_id;
1350 geo_suggest_tbl(pv_geo_data_count).attribute6_geo_type := pv_geo_rec_geo_type;
1351 WHEN 'ATTRIBUTE7' THEN
1352 geo_suggest_tbl(pv_geo_data_count).attribute7 := lv_geo_rec_geo_name;
1353 geo_suggest_tbl(pv_geo_data_count).attribute7_geo_id := pv_geo_rec_geo_id;
1354 geo_suggest_tbl(pv_geo_data_count).attribute7_geo_type := pv_geo_rec_geo_type;
1355 WHEN 'ATTRIBUTE8' THEN
1356 geo_suggest_tbl(pv_geo_data_count).attribute8 := lv_geo_rec_geo_name;
1357 geo_suggest_tbl(pv_geo_data_count).attribute8_geo_id := pv_geo_rec_geo_id;
1358 geo_suggest_tbl(pv_geo_data_count).attribute8_geo_type := pv_geo_rec_geo_type;
1359 WHEN 'ATTRIBUTE9' THEN
1360 geo_suggest_tbl(pv_geo_data_count).attribute9 := lv_geo_rec_geo_name;
1361 geo_suggest_tbl(pv_geo_data_count).attribute9_geo_id := pv_geo_rec_geo_id;
1362 geo_suggest_tbl(pv_geo_data_count).attribute9_geo_type := pv_geo_rec_geo_type;
1363 WHEN 'ATTRIBUTE10' THEN
1364 geo_suggest_tbl(pv_geo_data_count).attribute10 := lv_geo_rec_geo_name;
1365 geo_suggest_tbl(pv_geo_data_count).attribute10_geo_id := pv_geo_rec_geo_id;
1366 geo_suggest_tbl(pv_geo_data_count).attribute10_geo_type := pv_geo_rec_geo_type;
1367 ELSE
1368 NULL;
1369 END CASE;
1370 END IF;
1371 END insert_in_geo_suggest_tbl;
1372
1373 ---------------------------------------------------------------------+
1374 -- Insert procedure which populates intermediate plsql table geo_rec_tbl
1375 ---------------------------------------------------------------------+
1376 PROCEDURE insert_in_geo_rec_tbl (pv_geo_data_count NUMBER,
1377 pv_geo_rec_element_col VARCHAR2,
1378 pv_geo_rec_geo_name VARCHAR2,
1379 pv_geo_rec_geo_id NUMBER,
1380 pv_geo_rec_geo_code VARCHAR2)
1381 IS
1382 pv_geo_rec_geo_type VARCHAR2(100);
1383 BEGIN
1384 IF (pv_geo_rec_element_col IS NOT NULL) THEN
1385
1386 CASE pv_geo_rec_element_col
1387 WHEN 'GEOGRAPHY_ELEMENT1' THEN
1388 geo_rec_tbl(pv_geo_data_count).geography_element1 := pv_geo_rec_geo_name;
1389 geo_rec_tbl(pv_geo_data_count).geography_element1_id := pv_geo_rec_geo_id;
1390 geo_rec_tbl(pv_geo_data_count).geography_element1_code := pv_geo_rec_geo_code;
1391 WHEN 'GEOGRAPHY_ELEMENT2' THEN
1392 geo_rec_tbl(pv_geo_data_count).geography_element2 := pv_geo_rec_geo_name;
1393 geo_rec_tbl(pv_geo_data_count).geography_element2_id := pv_geo_rec_geo_id;
1394 geo_rec_tbl(pv_geo_data_count).geography_element2_code := pv_geo_rec_geo_code;
1395 WHEN 'GEOGRAPHY_ELEMENT3' THEN
1396 geo_rec_tbl(pv_geo_data_count).geography_element3 := pv_geo_rec_geo_name;
1397 geo_rec_tbl(pv_geo_data_count).geography_element3_id := pv_geo_rec_geo_id;
1398 geo_rec_tbl(pv_geo_data_count).geography_element3_code := pv_geo_rec_geo_code;
1399 WHEN 'GEOGRAPHY_ELEMENT4' THEN
1400 geo_rec_tbl(pv_geo_data_count).geography_element4 := pv_geo_rec_geo_name;
1401 geo_rec_tbl(pv_geo_data_count).geography_element4_id := pv_geo_rec_geo_id;
1402 geo_rec_tbl(pv_geo_data_count).geography_element4_code := pv_geo_rec_geo_code;
1403 WHEN 'GEOGRAPHY_ELEMENT5' THEN
1404 geo_rec_tbl(pv_geo_data_count).geography_element5 := pv_geo_rec_geo_name;
1405 geo_rec_tbl(pv_geo_data_count).geography_element5_id := pv_geo_rec_geo_id;
1406 geo_rec_tbl(pv_geo_data_count).geography_element5_code := pv_geo_rec_geo_code;
1407 WHEN 'GEOGRAPHY_ELEMENT6' THEN
1408 geo_rec_tbl(pv_geo_data_count).geography_element6 := pv_geo_rec_geo_name;
1409 geo_rec_tbl(pv_geo_data_count).geography_element6_id := pv_geo_rec_geo_id;
1410 WHEN 'GEOGRAPHY_ELEMENT7' THEN
1411 geo_rec_tbl(pv_geo_data_count).geography_element7 := pv_geo_rec_geo_name;
1412 geo_rec_tbl(pv_geo_data_count).geography_element7_id := pv_geo_rec_geo_id;
1413 WHEN 'GEOGRAPHY_ELEMENT8' THEN
1414 geo_rec_tbl(pv_geo_data_count).geography_element8 := pv_geo_rec_geo_name;
1415 geo_rec_tbl(pv_geo_data_count).geography_element8_id := pv_geo_rec_geo_id;
1416 WHEN 'GEOGRAPHY_ELEMENT9' THEN
1417 geo_rec_tbl(pv_geo_data_count).geography_element9 := pv_geo_rec_geo_name;
1418 geo_rec_tbl(pv_geo_data_count).geography_element9_id := pv_geo_rec_geo_id;
1419 WHEN 'GEOGRAPHY_ELEMENT10' THEN
1420 geo_rec_tbl(pv_geo_data_count).geography_element10 := pv_geo_rec_geo_name;
1421 geo_rec_tbl(pv_geo_data_count).geography_element10_id := pv_geo_rec_geo_id;
1422 ELSE NULL;
1423 END CASE;
1424 END IF;
1425 END insert_in_geo_rec_tbl;
1426
1427 ----------------------------------------------------------------------+
1428 -- Procedure to move data from intermediate table geo_rec_tbl to Final table
1429 -- geo_suggest_tbl
1430 ----------------------------------------------------------------------+
1431 PROCEDURE move_from_geo_rec_to_suggest (ll_geo_rec_index IN INTEGER,
1432 ll_geo_suggest_index IN INTEGER) IS
1433 ll_geo_rec geo_rec_type;
1434 BEGIN
1435 ll_geo_rec := geo_rec_tbl(ll_geo_rec_index);
1436
1437 -- fetch values and do processing
1438 -----------------------------------------------------------------+
1439 -- GEOGRAPHY_ELEMENT1
1440 -----------------------------------------------------------------+
1441 -- assignments to suggest table
1442 IF (ll_geo_rec.geography_element1 IS NOT NULL) THEN
1443 -- look for mapping for this column
1444 l_geo_rec_tab_col := get_mapped_tab_col('GEOGRAPHY_ELEMENT1');
1445 l_geo_rec_geo_name := ll_geo_rec.geography_element1;
1446 l_geo_rec_geo_id := ll_geo_rec.geography_element1_id;
1447 l_geo_rec_geo_code := ll_geo_rec.geography_element1_code;
1448 insert_in_geo_suggest_tbl(ll_geo_suggest_index,
1449 l_geo_rec_tab_col,
1450 l_geo_rec_geo_name,
1451 l_geo_rec_geo_id,
1452 l_geo_rec_geo_code
1453 );
1454 END IF;
1455
1456 -----------------------------------------------------------------+
1457 -- GEOGRAPHY_ELEMENT2
1458 -----------------------------------------------------------------+
1459 -- look for mapping for this column
1460 l_geo_rec_tab_col := get_mapped_tab_col('GEOGRAPHY_ELEMENT2');
1461
1462 IF (l_geo_rec_tab_col IS NOT NULL) THEN
1463 l_geo_rec_geo_name := ll_geo_rec.geography_element2;
1464 l_geo_rec_geo_id := ll_geo_rec.geography_element2_id;
1465 l_geo_rec_geo_code := ll_geo_rec.geography_element2_code;
1466
1467 IF (l_geo_rec_geo_name IS NOT NULL) THEN
1468 insert_in_geo_suggest_tbl(ll_geo_suggest_index,
1469 l_geo_rec_tab_col,
1470 l_geo_rec_geo_name,
1471 l_geo_rec_geo_id,
1472 l_geo_rec_geo_code
1473 );
1474 END IF;
1475
1476 END IF;
1477
1478 -----------------------------------------------------------------+
1479 -- GEOGRAPHY_ELEMENT3
1480 -----------------------------------------------------------------+
1481 -- look for mapping for this column
1482 l_geo_rec_tab_col := get_mapped_tab_col('GEOGRAPHY_ELEMENT3');
1483
1484 IF (l_geo_rec_tab_col IS NOT NULL) THEN
1485 l_geo_rec_geo_name := ll_geo_rec.geography_element3;
1486 l_geo_rec_geo_id := ll_geo_rec.geography_element3_id;
1487 l_geo_rec_geo_code := ll_geo_rec.geography_element3_code;
1488
1489 IF (l_geo_rec_geo_name IS NOT NULL) THEN
1490 insert_in_geo_suggest_tbl(ll_geo_suggest_index,
1491 l_geo_rec_tab_col,
1492 l_geo_rec_geo_name,
1493 l_geo_rec_geo_id,
1494 l_geo_rec_geo_code
1495 );
1496 END IF;
1497
1498 END IF;
1499
1500 -----------------------------------------------------------------+
1501 -- GEOGRAPHY_ELEMENT4
1502 -----------------------------------------------------------------+
1503 -- look for mapping for this column
1504 l_geo_rec_tab_col := get_mapped_tab_col('GEOGRAPHY_ELEMENT4');
1505
1506 IF (l_geo_rec_tab_col IS NOT NULL) THEN
1507 l_geo_rec_geo_name := ll_geo_rec.geography_element4;
1508 l_geo_rec_geo_id := ll_geo_rec.geography_element4_id;
1509 l_geo_rec_geo_code := ll_geo_rec.geography_element4_code;
1510
1511 IF (l_geo_rec_geo_name IS NOT NULL) THEN
1512 insert_in_geo_suggest_tbl(ll_geo_suggest_index,
1513 l_geo_rec_tab_col,
1514 l_geo_rec_geo_name,
1515 l_geo_rec_geo_id,
1516 l_geo_rec_geo_code
1517 );
1518 END IF;
1519
1520 END IF;
1521
1522 -----------------------------------------------------------------+
1523 -- GEOGRAPHY_ELEMENT5
1524 -----------------------------------------------------------------+
1525 -- look for mapping for this column
1526 l_geo_rec_tab_col := get_mapped_tab_col('GEOGRAPHY_ELEMENT5');
1527
1528 IF (l_geo_rec_tab_col IS NOT NULL) THEN
1529 l_geo_rec_geo_name := ll_geo_rec.geography_element5;
1530 l_geo_rec_geo_id := ll_geo_rec.geography_element5_id;
1531 l_geo_rec_geo_code := ll_geo_rec.geography_element5_code;
1532
1533 IF (l_geo_rec_geo_name IS NOT NULL) THEN
1534 insert_in_geo_suggest_tbl(ll_geo_suggest_index,
1535 l_geo_rec_tab_col,
1536 l_geo_rec_geo_name,
1537 l_geo_rec_geo_id,
1538 l_geo_rec_geo_code
1539 );
1540 END IF;
1541
1542 END IF;
1543 -----------------------------------------------------------------+
1544 -- GEOGRAPHY_ELEMENT6
1545 -----------------------------------------------------------------+
1546 -- look for mapping for this column
1547 l_geo_rec_tab_col := get_mapped_tab_col('GEOGRAPHY_ELEMENT6');
1548
1549 IF (l_geo_rec_tab_col IS NOT NULL) THEN
1550 l_geo_rec_geo_name := ll_geo_rec.geography_element6;
1551 l_geo_rec_geo_id := ll_geo_rec.geography_element6_id;
1552 l_geo_rec_geo_code := NULL;
1553
1554 IF (l_geo_rec_geo_name IS NOT NULL) THEN
1555 insert_in_geo_suggest_tbl(ll_geo_suggest_index,
1556 l_geo_rec_tab_col,
1557 l_geo_rec_geo_name,
1558 l_geo_rec_geo_id,
1559 l_geo_rec_geo_code
1560 );
1561 END IF;
1562
1563 END IF;
1564
1565 -----------------------------------------------------------------+
1566 -- GEOGRAPHY_ELEMENT7
1567 -----------------------------------------------------------------+
1568 -- look for mapping for this column
1569 l_geo_rec_tab_col := get_mapped_tab_col('GEOGRAPHY_ELEMENT7');
1570
1571 IF (l_geo_rec_tab_col IS NOT NULL) THEN
1572 l_geo_rec_geo_name := ll_geo_rec.geography_element7;
1573 l_geo_rec_geo_id := ll_geo_rec.geography_element7_id;
1574 l_geo_rec_geo_code := NULL;
1575
1576 IF (l_geo_rec_geo_name IS NOT NULL) THEN
1577 insert_in_geo_suggest_tbl(ll_geo_suggest_index,
1578 l_geo_rec_tab_col,
1579 l_geo_rec_geo_name,
1580 l_geo_rec_geo_id,
1581 l_geo_rec_geo_code
1582 );
1583 END IF;
1584
1585 END IF;
1586
1587 -----------------------------------------------------------------+
1588 -- GEOGRAPHY_ELEMENT8
1589 -----------------------------------------------------------------+
1590 -- look for mapping for this column
1591 l_geo_rec_tab_col := get_mapped_tab_col('GEOGRAPHY_ELEMENT8');
1592
1593 IF (l_geo_rec_tab_col IS NOT NULL) THEN
1594 l_geo_rec_geo_name := ll_geo_rec.geography_element8;
1595 l_geo_rec_geo_id := ll_geo_rec.geography_element8_id;
1596 l_geo_rec_geo_code := NULL;
1597
1598 IF (l_geo_rec_geo_name IS NOT NULL) THEN
1599 insert_in_geo_suggest_tbl(ll_geo_suggest_index,
1600 l_geo_rec_tab_col,
1601 l_geo_rec_geo_name,
1602 l_geo_rec_geo_id,
1603 l_geo_rec_geo_code
1604 );
1605 END IF;
1606
1607 END IF;
1608
1609 -----------------------------------------------------------------+
1610 -- GEOGRAPHY_ELEMENT9
1611 -----------------------------------------------------------------+
1612 -- look for mapping for this column
1613 l_geo_rec_tab_col := get_mapped_tab_col('GEOGRAPHY_ELEMENT9');
1614
1615 IF (l_geo_rec_tab_col IS NOT NULL) THEN
1616 l_geo_rec_geo_name := ll_geo_rec.geography_element9;
1617 l_geo_rec_geo_id := ll_geo_rec.geography_element9_id;
1618 l_geo_rec_geo_code := NULL;
1619
1620 IF (l_geo_rec_geo_name IS NOT NULL) THEN
1621 insert_in_geo_suggest_tbl(ll_geo_suggest_index,
1622 l_geo_rec_tab_col,
1623 l_geo_rec_geo_name,
1624 l_geo_rec_geo_id,
1625 l_geo_rec_geo_code
1626 );
1627 END IF;
1628
1629 END IF;
1630
1631 -----------------------------------------------------------------+
1632 -- GEOGRAPHY_ELEMENT10
1633 -----------------------------------------------------------------+
1634 -- look for mapping for this column
1635 l_geo_rec_tab_col := get_mapped_tab_col('GEOGRAPHY_ELEMENT10');
1636
1637 IF (l_geo_rec_tab_col IS NOT NULL) THEN
1638 l_geo_rec_geo_name := ll_geo_rec.geography_element10;
1639 l_geo_rec_geo_id := ll_geo_rec.geography_element10_id;
1640 l_geo_rec_geo_code := NULL;
1641
1642 IF (l_geo_rec_geo_name IS NOT NULL) THEN
1643 insert_in_geo_suggest_tbl(ll_geo_suggest_index,
1644 l_geo_rec_tab_col,
1645 l_geo_rec_geo_name,
1646 l_geo_rec_geo_id,
1647 l_geo_rec_geo_code
1648 );
1649 END IF;
1650
1651 END IF;
1652 END move_from_geo_rec_to_suggest;
1653
1654 -----------------------------------------------------------------------------+
1655 -- Procedure to insert multiple parent records in geo_rec_tbl intermediate
1656 -- plsql table
1657 -----------------------------------------------------------------------------+
1658 PROCEDURE insert_mp_in_geo_rec_proc (ll_geo_data_count IN NUMBER,
1659 ll_geo_type IN VARCHAR2,
1660 ll_geo_name IN VARCHAR2,
1661 ll_geo_code IN VARCHAR2,
1662 ll_geo_id IN NUMBER,
1663 x_insert_geo_suggest_rec OUT nocopy VARCHAR2) IS
1664 ll_mapped_param_value VARCHAR2(100);
1665 ll_mapped_element_col VARCHAR2(100);
1666 BEGIN
1667 -- look for mapping for this column
1668 ll_mapped_element_col := get_element_col_for_geo_type(ll_geo_type);
1669 -- for mapped table column, check if there is a parameter passed
1670 -- if it is passed, Insert only if the value matches that passed parameter.
1671 -- if not passed, insert it anyway.
1672 IF (ll_mapped_element_col IS NOT NULL) THEN
1673 ll_mapped_param_value := get_map_param_val_for_element(ll_mapped_element_col);
1674 l_geo_rec_geo_name := ll_geo_name;
1675 l_geo_rec_geo_id := ll_geo_id;
1676 l_geo_rec_geo_code := ll_geo_code;
1677 IF ((ll_mapped_param_value IS NOT NULL) AND (l_search_type <> 'LEVEL4_UNION_LEVEL5_SEARCH')) THEN
1678 IF (
1679 (ll_mapped_param_value = UPPER(SUBSTR(l_geo_rec_geo_name,1,LENGTH(ll_mapped_param_value)-1)||'%'))
1680 OR (ll_mapped_param_value = UPPER(SUBSTR(l_geo_rec_geo_code,1,LENGTH(ll_mapped_param_value)-1)||'%'))
1681 ) THEN
1682 insert_in_geo_rec_tbl(ll_geo_data_count,
1683 ll_mapped_element_col,
1684 l_geo_rec_geo_name,
1685 l_geo_rec_geo_id,
1686 l_geo_rec_geo_code
1687 );
1688 ELSE
1689 x_insert_geo_suggest_rec := 'N';
1690 END IF;
1691 ELSE -- if mapped parameter not passed, insert it
1692 insert_in_geo_rec_tbl(ll_geo_data_count,
1693 ll_mapped_element_col,
1694 l_geo_rec_geo_name,
1695 l_geo_rec_geo_id,
1696 l_geo_rec_geo_code
1697 );
1698 END IF;
1699 END IF;
1700
1701 END insert_mp_in_geo_rec_proc;
1702
1703 -----------------------------------------------------------------------------+
1704 -- Procedure to handle multiple parents case.
1705 -- Input is geography_id for which there are multiple parents
1706 -- It will call insert_mp_in_geo_rec_proc to insert data in
1707 -- geo_rec table (intermediate plsql table)
1708 -----------------------------------------------------------------------------+
1709 PROCEDURE multiple_parent_proc (ll_geo_id hz_geographies.geography_id%TYPE
1710 ,ll_geo_type hz_geographies.geography_type%TYPE) IS
1711 l_structure_level_count NUMBER;
1712 l_insert_geo_valid_rec_final VARCHAR2(1);
1713 l_insert_geo_suggest_rec VARCHAR2(1);
1714
1715 -- this execption will occur if hierarchy node information does not
1716 -- match geography structure levels i.e. some level is missing in hierarchy node
1717 -- or for some reason we are not able to fetch data from hierarchy nodes
1718 -- for multi parents case.
1719 INCONSISTENT_DATATYPE EXCEPTION;
1720 PRAGMA EXCEPTION_INIT(INCONSISTENT_DATATYPE, -932);
1721
1722 BEGIN
1723
1724 -- FND Logging for debug purpose
1725 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
1726 hz_utility_v2pub.debug
1727 (p_message => 'Trying to fetch Parents for Multi Parent record for Geo id:'||
1728 ll_geo_id||' and geo type '||ll_geo_type ,
1729 p_prefix => l_debug_prefix,
1730 p_msg_level => fnd_log.level_statement,
1731 p_module_prefix => l_module_prefix,
1732 p_module => l_module
1733 );
1734 END IF;
1735
1736
1737 -- get the structure levels for which we have to build the query
1738 -- result here will be 1 less since for country no structure level is defined.
1739 SELECT COUNT(*)
1740 INTO l_structure_level_count
1741 FROM hz_geo_structure_levels
1742 WHERE country_code = upper(p_country_code)
1743 CONNECT BY geography_type = PRIOR parent_geography_type
1744 AND country_code = upper(p_country_code)
1745 START WITH geography_type = ll_geo_type
1746 AND country_code = upper(p_country_code);
1747
1748 IF (l_structure_level_count > 0) THEN
1749 -- build the select statement
1750 l_select_mp := 'SELECT distinct p0.geography_id , p0.geography_name ,'
1751 ||'p0.geography_code , p0.geography_type '
1752 ||',p1.geography_id , p1.geography_name ,'
1753 ||'p1.geography_code , p1.geography_type ';
1754 l_from_mp := ' FROM hz_geographies p0 '
1755 ||', hz_hierarchy_nodes hn1'
1756 ||', hz_geographies p1 ';
1757 l_where_mp := ' WHERE hn1.child_id = p0.geography_id '
1758 ||' AND p0.geography_use = ''MASTER_REF'' '
1759 ||' AND SYSDATE BETWEEN p0.start_date AND p0.end_date '
1760 ||' AND hn1.child_id = :x_missing_geo_id '
1761 ||' AND hn1.hierarchy_type = ''MASTER_REF'' '
1762 ||' AND hn1.level_number = 1 '
1763 ||' AND hn1.child_table_name = ''HZ_GEOGRAPHIES'' '
1764 ||' AND SYSDATE BETWEEN hn1.effective_start_date AND hn1.effective_end_date '
1765 ||' AND NVL(hn1.status,''A'') = ''A'' '
1766 ||' AND hn1.parent_table_name = ''HZ_GEOGRAPHIES'' '
1767 ||' AND hn1.parent_id = p1.geography_id '
1768 ||' AND p1.geography_use = ''MASTER_REF'' '
1769 ||' AND SYSDATE BETWEEN p1.start_date AND p1.end_date ';
1770
1771 l_last_index_mp := 1;
1772
1773 --build select from where cluase for other levels as well
1774 IF (l_structure_level_count > 1) THEN
1775 FOR i IN 2..l_structure_level_count LOOP
1776 l_select_mp := l_select_mp ||',p'||i||'.geography_id , p'||i||'.geography_name '
1777 ||',p'||i||'.geography_code, p'||i||'.geography_type ';
1778
1779 l_from_mp := l_from_mp ||', hz_hierarchy_nodes hn'||i
1780 ||', hz_geographies p'||i ;
1781
1782 l_where_mp := l_where_mp ||' AND hn'||i||'.child_id = hn'||l_last_index_mp||'.parent_id '
1783 ||' AND hn'||i||'.hierarchy_type = ''MASTER_REF'' '
1784 ||' AND hn'||i||'.level_number = 1 '
1785 ||' AND hn'||i||'.child_table_name = ''HZ_GEOGRAPHIES'' '
1786 ||' AND SYSDATE BETWEEN hn'||i||'.effective_start_date AND hn'||i||'.effective_end_date '
1787 ||' AND NVL(hn'||i||'.status,''A'') = ''A'' '
1788 ||' AND hn'||i||'.parent_table_name = ''HZ_GEOGRAPHIES'' '
1789 ||' AND hn'||i||'.parent_id = p'||i||'.geography_id '
1790 ||' AND p'||i||'.geography_use = ''MASTER_REF'' '
1791 ||' AND SYSDATE BETWEEN p'||i||'.start_date AND p'||i||'.end_date ';
1792
1793 l_last_index_mp := i;
1794
1795 END LOOP;
1796
1797 -- pad rest of the columns in select stmt (to be fetched in rec_mp record) to null
1798 -- l_total_null_cols_mp := (10-(l_structure_level_count))*4;
1799 l_total_null_cols_mp := (40 - (4 * (l_structure_level_count+1)));
1800
1801 IF (l_total_null_cols_mp > 0) THEN
1802 FOR i IN 1..l_total_null_cols_mp LOOP
1803 l_select_mp := l_select_mp ||', NULL ';
1804 END LOOP;
1805 END IF;
1806
1807 l_sql_stmt_mp := l_select_mp||l_from_mp||l_where_mp;
1808 -- ns_debug.put_line(' Multiple Parent Query ');
1809 -- ns_debug.put_line(' ======================');
1810 -- ns_debug.put_line(l_sql_stmt_mp);
1811 -- ns_debug.put_line(' ======================');
1812
1813 -----------------debug statements---------------+
1814 -- FND Logging for debug purpose
1815 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
1816 hz_utility_v2pub.debug
1817 (p_message => 'Total NULL cols appended:'||l_total_null_cols_mp,
1818 p_prefix => l_debug_prefix,
1819 p_msg_level => fnd_log.level_statement,
1820 p_module_prefix => l_module_prefix,
1821 p_module => l_module
1822 );
1823 END IF;
1824
1825 -- FND Logging for debug purpose
1826 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
1827 hz_utility_v2pub.debug
1828 (p_message => 'Multiparent Query :'||l_sql_stmt_mp ,
1829 p_prefix => l_debug_prefix,
1830 p_msg_level => fnd_log.level_statement,
1831 p_module_prefix => l_module_prefix,
1832 p_module => l_module
1833 );
1834 END IF;
1835 ----------------end debug statements------------+
1836
1837 -- execute the query
1838 OPEN cv_mp FOR l_sql_stmt_mp USING ll_geo_id;
1839 LOOP
1840 FETCH cv_mp INTO rec_mp;
1841 EXIT WHEN cv_mp%NOTFOUND;
1842 -- l_geo_data_count is counter for row. It is same the one used
1843 -- in main query
1844 l_geo_data_count := geo_rec_tbl.COUNT+1;
1845 EXIT WHEN l_geo_data_count > l_max_fetch_count; -- no. of records retrieved
1846 -- ns_debug.put_line('Multiple parent data');
1847 -- ns_debug.put_line('====================');
1848 -- ns_debug.put_line(l_geo_data_count||':1:'||rec_mp.geo_name_1||':'||rec_mp.geo_code_1
1849 /* ||':2:'||rec_mp.geo_name_2||':'||rec_mp.geo_code_2
1850 ||':3:'||rec_mp.geo_name_3||':'||rec_mp.geo_code_3
1851 ||':4:'||rec_mp.geo_name_4||':'||rec_mp.geo_code_4
1852 ||':5:'||rec_mp.geo_name_5||':'||rec_mp.geo_code_5
1853 ||':6:'||rec_mp.geo_name_6||':'||rec_mp.geo_code_6
1854 ||':7:'||rec_mp.geo_name_7||':'||rec_mp.geo_code_7
1855 ||':8:'||rec_mp.geo_name_8||':'||rec_mp.geo_code_8
1856 ||':9:'||rec_mp.geo_name_9||':'||rec_mp.geo_code_9
1857 ||':10:'||rec_mp.geo_name_10||':'||rec_mp.geo_code_10);
1858 */
1859 -- fetch values and do processing
1860 -----------------------------------------------------------------+
1861 -- GEO_ID_1
1862 -----------------------------------------------------------------+
1863 -- assignments to suggest table
1864 IF (rec_mp.geo_id_1 IS NOT NULL) THEN
1865 -- insert this value in geo_rec_tbl for geo_id column
1866 geo_rec_tbl(l_geo_data_count).geography_id := rec_mp.geo_id_1;
1867 geo_rec_tbl(l_geo_data_count).geography_name := rec_mp.geo_name_1;
1868 geo_rec_tbl(l_geo_data_count).geography_code := rec_mp.geo_code_1;
1869 geo_rec_tbl(l_geo_data_count).geography_type := rec_mp.geo_type_1;
1870 geo_rec_tbl(l_geo_data_count).multiple_parent_flag := 'Y';
1871
1872 -- do regular insert
1873 insert_mp_in_geo_rec_proc (ll_geo_data_count => l_geo_data_count,
1874 ll_geo_type => rec_mp.geo_type_1,
1875 ll_geo_name => rec_mp.geo_name_1,
1876 ll_geo_code => rec_mp.geo_code_1,
1877 ll_geo_id => rec_mp.geo_id_1,
1878 x_insert_geo_suggest_rec => l_insert_geo_suggest_rec);
1879 IF (l_insert_geo_suggest_rec = 'N') THEN
1880 l_insert_geo_valid_rec_final := 'N';
1881 END IF;
1882 END IF;
1883 -----------------------------------------------------------------+
1884 -- GEO_ID_2
1885 -----------------------------------------------------------------+
1886 -- assignments to suggest table
1887 IF ((rec_mp.geo_id_2 IS NOT NULL) AND (NVL(l_insert_geo_valid_rec_final,'Y') <> 'N'))
1888 THEN
1889 insert_mp_in_geo_rec_proc (ll_geo_data_count => l_geo_data_count,
1890 ll_geo_type => rec_mp.geo_type_2,
1891 ll_geo_name => rec_mp.geo_name_2,
1892 ll_geo_code => rec_mp.geo_code_2,
1893 ll_geo_id => rec_mp.geo_id_2,
1894 x_insert_geo_suggest_rec => l_insert_geo_suggest_rec);
1895 IF (l_insert_geo_suggest_rec = 'N') THEN
1896 l_insert_geo_valid_rec_final := 'N';
1897 END IF;
1898 END IF;
1899
1900 -----------------------------------------------------------------+
1901 -- GEO_ID_3
1902 -----------------------------------------------------------------+
1903 -- assignments to suggest table
1904 IF ((rec_mp.geo_id_3 IS NOT NULL) AND (NVL(l_insert_geo_valid_rec_final,'Y') <> 'N'))
1905 THEN
1906 insert_mp_in_geo_rec_proc (ll_geo_data_count => l_geo_data_count,
1907 ll_geo_type => rec_mp.geo_type_3,
1908 ll_geo_name => rec_mp.geo_name_3,
1909 ll_geo_code => rec_mp.geo_code_3,
1910 ll_geo_id => rec_mp.geo_id_3,
1911 x_insert_geo_suggest_rec => l_insert_geo_suggest_rec);
1912 IF (l_insert_geo_suggest_rec = 'N') THEN
1913 l_insert_geo_valid_rec_final := 'N';
1914 END IF;
1915 END IF;
1916
1917 -----------------------------------------------------------------+
1918 -- GEO_ID_4
1919 -----------------------------------------------------------------+
1920 -- assignments to suggest table
1921 IF ((rec_mp.geo_id_4 IS NOT NULL) AND (NVL(l_insert_geo_valid_rec_final,'Y') <> 'N'))
1922 THEN
1923 insert_mp_in_geo_rec_proc (ll_geo_data_count => l_geo_data_count,
1924 ll_geo_type => rec_mp.geo_type_4,
1925 ll_geo_name => rec_mp.geo_name_4,
1926 ll_geo_code => rec_mp.geo_code_4,
1927 ll_geo_id => rec_mp.geo_id_4,
1928 x_insert_geo_suggest_rec => l_insert_geo_suggest_rec);
1929 IF (l_insert_geo_suggest_rec = 'N') THEN
1930 l_insert_geo_valid_rec_final := 'N';
1931 END IF;
1932 END IF;
1933
1934 -----------------------------------------------------------------+
1935 -- GEO_ID_5
1936 -----------------------------------------------------------------+
1937 -- assignments to suggest table
1938 IF ((rec_mp.geo_id_5 IS NOT NULL) AND (NVL(l_insert_geo_valid_rec_final,'Y') <> 'N'))
1939 THEN
1940 insert_mp_in_geo_rec_proc (ll_geo_data_count => l_geo_data_count,
1941 ll_geo_type => rec_mp.geo_type_5,
1942 ll_geo_name => rec_mp.geo_name_5,
1943 ll_geo_code => rec_mp.geo_code_5,
1944 ll_geo_id => rec_mp.geo_id_5,
1945 x_insert_geo_suggest_rec => l_insert_geo_suggest_rec);
1946 IF (l_insert_geo_suggest_rec = 'N') THEN
1947 l_insert_geo_valid_rec_final := 'N';
1948 END IF;
1949 END IF;
1950
1951 -----------------------------------------------------------------+
1952 -- GEO_ID_6
1953 -----------------------------------------------------------------+
1954 -- assignments to suggest table
1955 IF ((rec_mp.geo_id_6 IS NOT NULL) AND (NVL(l_insert_geo_valid_rec_final,'Y') <> 'N'))
1956 THEN
1957 insert_mp_in_geo_rec_proc (ll_geo_data_count => l_geo_data_count,
1958 ll_geo_type => rec_mp.geo_type_6,
1959 ll_geo_name => rec_mp.geo_name_6,
1960 ll_geo_code => rec_mp.geo_code_6,
1961 ll_geo_id => rec_mp.geo_id_6,
1962 x_insert_geo_suggest_rec => l_insert_geo_suggest_rec);
1963 IF (l_insert_geo_suggest_rec = 'N') THEN
1964 l_insert_geo_valid_rec_final := 'N';
1965 END IF;
1966 END IF;
1967
1968 -----------------------------------------------------------------+
1969 -- GEO_ID_7
1970 -----------------------------------------------------------------+
1971 -- assignments to suggest table
1972 IF ((rec_mp.geo_id_7 IS NOT NULL) AND (NVL(l_insert_geo_valid_rec_final,'Y') <> 'N'))
1973 THEN
1974 insert_mp_in_geo_rec_proc (ll_geo_data_count => l_geo_data_count,
1975 ll_geo_type => rec_mp.geo_type_7,
1976 ll_geo_name => rec_mp.geo_name_7,
1977 ll_geo_code => rec_mp.geo_code_7,
1978 ll_geo_id => rec_mp.geo_id_7,
1979 x_insert_geo_suggest_rec => l_insert_geo_suggest_rec);
1980 IF (l_insert_geo_suggest_rec = 'N') THEN
1981 l_insert_geo_valid_rec_final := 'N';
1982 END IF;
1983 END IF;
1984
1985 -----------------------------------------------------------------+
1986 -- GEO_ID_8
1987 -----------------------------------------------------------------+
1988 -- assignments to suggest table
1989 IF ((rec_mp.geo_id_8 IS NOT NULL) AND (NVL(l_insert_geo_valid_rec_final,'Y') <> 'N'))
1990 THEN
1991 insert_mp_in_geo_rec_proc (ll_geo_data_count => l_geo_data_count,
1992 ll_geo_type => rec_mp.geo_type_8,
1993 ll_geo_name => rec_mp.geo_name_8,
1994 ll_geo_code => rec_mp.geo_code_8,
1995 ll_geo_id => rec_mp.geo_id_8,
1996 x_insert_geo_suggest_rec => l_insert_geo_suggest_rec);
1997 IF (l_insert_geo_suggest_rec = 'N') THEN
1998 l_insert_geo_valid_rec_final := 'N';
1999 END IF;
2000 END IF;
2001
2002 -----------------------------------------------------------------+
2003 -- GEO_ID_9
2004 -----------------------------------------------------------------+
2005 -- assignments to suggest table
2006 IF ((rec_mp.geo_id_9 IS NOT NULL) AND (NVL(l_insert_geo_valid_rec_final,'Y') <> 'N'))
2007 THEN
2008 insert_mp_in_geo_rec_proc (ll_geo_data_count => l_geo_data_count,
2009 ll_geo_type => rec_mp.geo_type_9,
2010 ll_geo_name => rec_mp.geo_name_9,
2011 ll_geo_code => rec_mp.geo_code_9,
2012 ll_geo_id => rec_mp.geo_id_9,
2013 x_insert_geo_suggest_rec => l_insert_geo_suggest_rec);
2014 IF (l_insert_geo_suggest_rec = 'N') THEN
2015 l_insert_geo_valid_rec_final := 'N';
2016 END IF;
2017 END IF;
2018
2019 -----------------------------------------------------------------+
2020 -- GEO_ID_10
2021 -----------------------------------------------------------------+
2022 -- assignments to suggest table
2023 IF ((rec_mp.geo_id_10 IS NOT NULL) AND (NVL(l_insert_geo_valid_rec_final,'Y') <> 'N'))
2024 THEN
2025 insert_mp_in_geo_rec_proc (ll_geo_data_count => l_geo_data_count,
2026 ll_geo_type => rec_mp.geo_type_10,
2027 ll_geo_name => rec_mp.geo_name_10,
2028 ll_geo_code => rec_mp.geo_code_10,
2029 ll_geo_id => rec_mp.geo_id_10,
2030 x_insert_geo_suggest_rec => l_insert_geo_suggest_rec);
2031 IF (l_insert_geo_suggest_rec = 'N') THEN
2032 l_insert_geo_valid_rec_final := 'N';
2033 END IF;
2034 END IF;
2035
2036 -- delete whole row if l_insert_geo_suggest_rec is set to N
2037 IF (l_insert_geo_valid_rec_final = 'N') THEN
2038 geo_rec_tbl.DELETE(l_geo_data_count);
2039 l_insert_geo_valid_rec_final := 'Y';
2040 l_insert_geo_suggest_rec := 'Y';
2041 END IF;
2042
2043 END LOOP;
2044 CLOSE cv_mp;
2045
2046 END IF;
2047 END IF;
2048
2049 -- FND Logging for debug purpose
2050 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
2051 hz_utility_v2pub.debug
2052 (p_message => 'Done with Multi Parent Case...' ,
2053 p_prefix => l_debug_prefix,
2054 p_msg_level => fnd_log.level_statement,
2055 p_module_prefix => l_module_prefix,
2056 p_module => l_module
2057 );
2058 END IF;
2059
2060 EXCEPTION
2061 WHEN INCONSISTENT_DATATYPE THEN
2062 NULL;
2063 -- FND Logging for debug purpose
2064 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
2065 hz_utility_v2pub.debug
2066 (p_message => 'INCONSISTENT_DATATYPE Exception in multiple_parent_proc.'||
2067 'This has occured because HZ_HIERARCHY_NODES data is not '||
2068 'correctly setup for geography id:'||ll_geo_id ,
2069 p_prefix => l_debug_prefix,
2070 p_msg_level => fnd_log.level_statement,
2071 p_module_prefix => l_module_prefix,
2072 p_module => l_module
2073 );
2074 END IF;
2075 -- ns_debug.put_line('hz_hierarchy_nodes data is not correctly setup for geography id:'||ll_geo_id);
2076 WHEN OTHERS THEN
2077 NULL;
2078 -- FND Logging for debug purpose
2079 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
2080 hz_utility_v2pub.debug
2081 (p_message => SUBSTR('Exception OTHERS in multiple_parent_proc.'||
2082 'HZ_HIERARCHY_NODES data is not '||
2083 'correctly setup for geography id:'||ll_geo_id||':'||SQLERRM,1,255),
2084 p_prefix => l_debug_prefix,
2085 p_msg_level => fnd_log.level_statement,
2086 p_module_prefix => l_module_prefix,
2087 p_module => l_module
2088 );
2089 END IF;
2090 -- ns_debug.put_line('Error in fetching hz_hierarchy_nodes data for geography id:'||ll_geo_id);
2091 END multiple_parent_proc;
2092
2093 ---------------------------------------------------------------------+
2094 -- Main Search procedure which builds sql stmt for Search 1 and Search 2
2095 -- and executes query
2096 ---------------------------------------------------------------------+
2097 PROCEDURE search_routine_pvt (pt_search_type IN VARCHAR2,
2098 pt_bind_table IN bind_tbl_type,
2099 pt_success_geo_level IN NUMBER DEFAULT NULL)
2100 IS
2101 pp_search_type VARCHAR2 (100);
2102 pp_bind_table bind_tbl_type;
2103 BEGIN
2104 pp_search_type := pt_search_type;
2105 pp_bind_table := pt_bind_table;
2106
2107 -- Select clause
2108 -- NOTE : IF ANY element is added or deleted in select clause, modify geo_rec_type
2109 -- record type accordingly.
2110 l_select := 'SELECT DISTINCT hg0.GEOGRAPHY_ID, hg0.GEOGRAPHY_TYPE, hg0.GEOGRAPHY_NAME,'||
2111 'hg0.GEOGRAPHY_CODE, hg0.MULTIPLE_PARENT_FLAG, hg0.COUNTRY_CODE,'||
2112 'hg0.GEOGRAPHY_ELEMENT1, hg0.GEOGRAPHY_ELEMENT1_ID, hg0.GEOGRAPHY_ELEMENT1_CODE,'||
2113 'hg0.GEOGRAPHY_ELEMENT2, hg0.GEOGRAPHY_ELEMENT2_ID, hg0.GEOGRAPHY_ELEMENT2_CODE,'||
2114 'hg0.GEOGRAPHY_ELEMENT3, hg0.GEOGRAPHY_ELEMENT3_ID, hg0.GEOGRAPHY_ELEMENT3_CODE,'||
2115 'hg0.GEOGRAPHY_ELEMENT4, hg0.GEOGRAPHY_ELEMENT4_ID, hg0.GEOGRAPHY_ELEMENT4_CODE,'||
2116 'hg0.GEOGRAPHY_ELEMENT5, hg0.GEOGRAPHY_ELEMENT5_ID, hg0.GEOGRAPHY_ELEMENT5_CODE,'||
2117 'hg0.GEOGRAPHY_ELEMENT6, hg0.GEOGRAPHY_ELEMENT6_ID,'||
2118 'hg0.GEOGRAPHY_ELEMENT7, hg0.GEOGRAPHY_ELEMENT7_ID,'||
2119 'hg0.GEOGRAPHY_ELEMENT8, hg0.GEOGRAPHY_ELEMENT8_ID,'||
2120 'hg0.GEOGRAPHY_ELEMENT9, hg0.GEOGRAPHY_ELEMENT9_ID,'||
2121 'hg0.GEOGRAPHY_ELEMENT10, hg0.GEOGRAPHY_ELEMENT10_ID ';
2122
2123 -- from clause
2124 l_from := ' FROM hz_geographies hg0 ';
2125
2126 -- Mandatory where clause
2127 l_where := ' WHERE hg0.geography_use = ''MASTER_REF'' '||
2128 ' AND SYSDATE between hg0.start_date and hg0.end_date '||
2129 ' AND hg0.country_code = :x_country_code ' ||
2130 ' AND hg0.multiple_parent_flag = ''N'' ' ;
2131
2132 l_order_by := NULL;
2133
2134 -- we are making sure that we are fetching the leaf nodes for the passed parameters
2135 -- i.e. if only county is passed in above example, we want to fetch rows
2136 -- only for Country -> State -> County
2137 FOR k IN l_max_passed_element_col_value+1..l_max_passed_element_col_value+3 LOOP
2138 IF k < 11 THEN -- we have only 10 elements
2139 l_where_3 := l_where_3||' AND hg0.geography_element'||k||' is NULL ';
2140 END IF;
2141 END LOOP;
2142
2143 -- make sure when doing detailed child search we are fetching only
2144 -- those records which have value till the last mapped column
2145 -- this search we are doing after only making sure we have only 1
2146 -- unique record identified for passed parameters
2147 l_where_4 := 'AND hg0.geography_element'||l_max_mapped_element_col_value||' is NOT NULL ';
2148
2149 ------------------
2150 -- select stmt to fetch the multiple parent records for passed value
2151 -- once record is fetched, seperate multiple parent procedure will get all
2152 -- corresponding data for that
2153 l_sql_stmt_2 := ' UNION ALL '||l_select ||l_from||' , hz_geography_identifiers hg1 '
2154 ||' WHERE hg0.geography_use = ''MASTER_REF'' '
2155 ||' AND SYSDATE between hg0.start_date and hg0.end_date '
2156 ||' AND upper(hg0.country_code) = :x_country_code_101 '
2157 ||' AND hg0.multiple_parent_flag = ''Y'' '
2158 ||' AND hg0.geography_id = hg1.geography_id '
2159 ||' AND hg1.geography_use = ''MASTER_REF'' '
2160 ||' AND hg1.geography_type = :x_geo_type_101 '
2161 ||' AND UPPER(hg1.identifier_value) LIKE :x_geo_name_101 ' ;
2162
2163 ------------------
2164 -- select stmt to fetch the multiple parent records for passed value
2165 -- once record is fetched, seperate multiple parent procedure will get all
2166 -- corresponding data for that union case where we are doing max mapped element -1
2167 -- i.e. if Foster City + 94065 is passed then, check for Foster City for Multiple
2168 -- Parent case.
2169 l_sql_stmt_3 := ' UNION ALL '||l_select ||l_from||' , hz_geography_identifiers hg1 '
2170 ||' WHERE hg0.geography_use = ''MASTER_REF'' '
2171 ||' AND SYSDATE between hg0.start_date and hg0.end_date '
2172 ||' AND upper(hg0.country_code) = :x_country_code_102 '
2173 ||' AND hg0.multiple_parent_flag = ''Y'' '
2174 ||' AND hg0.geography_id = hg1.geography_id '
2175 ||' AND hg1.geography_use = ''MASTER_REF'' '
2176 ||' AND hg1.geography_type = :x_geo_type_102 '
2177 ||' AND UPPER(hg1.identifier_value) LIKE :x_geo_name_102 ' ;
2178
2179 ------------------
2180
2181 -- 1. do search for all passed and mapped params if search type = ALL_PASSED_PARAM_SEARCH
2182 -- 2. if 0 record is found, then if more than 3 elements are mapped and last mapped element is passed
2183 -- as parameter, then do search for combinations of element1 + element2 + Last Mapped(and passed) element
2184 -- UNION element1 + element2 + (Last-1) Mapped (and passed) element
2185 -- search type = LEVEL4_UNION_LEVEL5_SEARCH
2186 IF (pp_search_type = 'ALL_PASSED_PARAM_SEARCH') THEN
2187 -- dynamic where clause built before for all passed parameters
2188 IF (l_lowest_passed_geo_type IS NOT NULL) THEN
2189 l_where_3 := ' AND hg0.geography_type = :x_last_geo_type ';
2190 pp_bind_table(pp_bind_table.COUNT+1).bind_value := l_lowest_passed_geo_type;
2191 -- bind for sql stmt 2 also (for multiple parent flag check)
2192 pp_bind_table(pp_bind_table.COUNT+1).bind_value := upper(p_country_code);
2193 pp_bind_table(pp_bind_table.COUNT+1).bind_value := l_lowest_passed_geo_type;
2194 pp_bind_table(pp_bind_table.COUNT+1).bind_value := l_lowest_passed_geo_value;
2195 l_where := l_where||l_where_5||l_where_3;
2196 l_from := l_from ||l_from_5;
2197 l_sql_stmt := l_select||l_from||l_where||l_sql_stmt_2||l_order_by;
2198 ELSE
2199 -- here we use old l_where_3 clause because new where3 could not be built
2200 -- ns_debug.put_line('Using Old where clause ');
2201 l_where := l_where||l_where_5||l_where_3;
2202 l_from := l_from ||l_from_5;
2203 l_sql_stmt := l_select||l_from||l_where||l_order_by;
2204 END IF;
2205 ELSIF (pp_search_type = 'SEARCH_FROM_TOP') THEN
2206 l_where_3 := ' AND hg0.geography_type = :x_last_geo_type ';
2207 pp_bind_table(pp_bind_table.COUNT+1).bind_value := get_geo_type_from_element_col('GEOGRAPHY_ELEMENT'||pt_success_geo_level); --l_lowest_passed_geo_type;
2208 -- bind for sql stmt 2 also (for multiple parent flag check)
2209 pp_bind_table(pp_bind_table.COUNT+1).bind_value := upper(p_country_code);
2210 pp_bind_table(pp_bind_table.COUNT+1).bind_value := get_geo_type_from_element_col('GEOGRAPHY_ELEMENT'||pt_success_geo_level); --l_lowest_passed_geo_type;
2211 pp_bind_table(pp_bind_table.COUNT+1).bind_value := get_map_param_val_for_element('GEOGRAPHY_ELEMENT'||pt_success_geo_level); --l_lowest_passed_geo_value;
2212 l_where := l_where||l_where_5||l_where_3;
2213 l_from := l_from ||l_from_5;
2214 l_sql_stmt := l_select||l_from||l_where||l_sql_stmt_2||l_order_by;
2215 ELSIF (pp_search_type = 'LEVEL4_UNION_LEVEL5_SEARCH') THEN
2216 IF (l_lowest_mapped_geo_type IS NOT NULL) THEN
2217 -- bind for sql stmt 2 also (for multiple parent flag check)
2218 pp_bind_table(pp_bind_table.COUNT+1).bind_value := upper(p_country_code);
2219 pp_bind_table(pp_bind_table.COUNT+1).bind_value := l_lowest_passed_geo_type;
2220 pp_bind_table(pp_bind_table.COUNT+1).bind_value := l_lowest_passed_geo_value;
2221 ELSE
2222 l_sql_stmt_2 := NULL;
2223 END IF;
2224
2225 IF (l_count_for_where_clause_3 = 2) THEN
2226 -- bind for sql stmt 3 also (for multiple parent flag check)
2227 -- at that time need to provide addditional where clause in l_where_7
2228 -- to not pick multi parent flag = Y record
2229 pp_bind_table(pp_bind_table.COUNT+1).bind_value := upper(p_country_code);
2230 pp_bind_table(pp_bind_table.COUNT+1).bind_value := get_geo_type_from_element_col('GEOGRAPHY_ELEMENT'||to_char(l_max_mapped_element_col_value-1));
2231 pp_bind_table(pp_bind_table.COUNT+1).bind_value := get_map_param_val_for_element('GEOGRAPHY_ELEMENT'||to_char(l_max_mapped_element_col_value-1));
2232 ELSE
2233 l_sql_stmt_3 := NULL;
2234 END IF;
2235
2236 -- order of SQL stmt is very imp as valriables are bound in the same order
2237 IF ((l_count_for_where_clause_2 = 2) AND (l_count_for_where_clause_3 <> 2)) THEN
2238 l_sql_stmt := l_select||l_from||l_from_6||l_where_6||l_sql_stmt_2||l_order_by;
2239 ELSIF
2240 ((l_count_for_where_clause_2 <> 2) AND (l_count_for_where_clause_3 = 2)) THEN
2241 l_sql_stmt := l_select||l_from||l_from_7||l_where_7||l_sql_stmt_2||l_sql_stmt_3||l_order_by;
2242 ELSIF
2243 ((l_count_for_where_clause_2 = 2) AND (l_count_for_where_clause_3 = 2)) THEN
2244 l_sql_stmt := l_select||l_from||l_from_6||l_where_6
2245 ||' UNION '||
2246 l_select||l_from||l_from_7||l_where_7||l_sql_stmt_2||l_sql_stmt_3||l_order_by;
2247 END IF;
2248 END IF;
2249
2250 l_bind_counter := TO_NUMBER(pp_bind_table.COUNT);
2251
2252 -- FND Logging for debug purpose
2253 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
2254 hz_utility_v2pub.debug
2255 (p_message => 'Search Type:'||pp_search_type||
2256 ', No. of Bind Values:'||TO_CHAR(l_bind_counter),
2257 p_prefix => l_debug_prefix,
2258 p_msg_level => fnd_log.level_statement,
2259 p_module_prefix => l_module_prefix,
2260 p_module => l_module
2261 );
2262 END IF;
2263
2264 /*
2265 ns_debug.put_line('Search Type :'||pp_search_type);
2266 ns_debug.put_line('Bind_counter:'||l_bind_counter);
2267 IF (l_bind_counter > 0) THEN
2268 ns_debug.put_line('BIND VALUES ');
2269 ns_debug.put_line('============');
2270 FOR i IN pp_bind_table.FIRST..pp_bind_table.LAST LOOP
2271 ns_debug.put_line(i||'='||pp_bind_table(i).bind_value);
2272 NULL;
2273 END LOOP;
2274 END IF;
2275 ns_debug.put_line('Max Passed Column Value : '||l_max_passed_element_col_value);
2276 ns_debug.put_line('Max Mapped Column Value : '||l_max_mapped_element_col_value);
2277 ns_debug.put_line('Length of SELECT Clause : '||LENGTH(l_select));
2278 ns_debug.put_line('Length of FROM Clause : '||LENGTH(l_from));
2279 ns_debug.put_line('Length of WHERE Clause : '||LENGTH(l_where));
2280 ns_debug.put_line('Total Length of SQL Stmt: '||LENGTH(l_sql_stmt));
2281 ns_debug.put_line('SQL Statement ');
2282 ns_debug.put_line('============= ');
2283 ns_debug.put_line(l_sql_stmt);
2284 */
2285
2286 --execute query for the resource based on bind variables to use
2287 IF (l_sql_stmt IS NOT NULL) THEN
2288 IF(l_bind_counter = 1) THEN
2289 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value;
2290 ELSIF(l_bind_counter = 2) THEN
2291 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2292 pp_bind_table(2).bind_value;
2293 ELSIF(l_bind_counter = 3) THEN
2294 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2295 pp_bind_table(2).bind_value,
2296 pp_bind_table(3).bind_value;
2297 ELSIF(l_bind_counter = 4) THEN
2298 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2299 pp_bind_table(2).bind_value,
2300 pp_bind_table(3).bind_value,
2301 pp_bind_table(4).bind_value;
2302 ELSIF(l_bind_counter = 5) THEN
2303 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2304 pp_bind_table(2).bind_value,
2305 pp_bind_table(3).bind_value,
2306 pp_bind_table(4).bind_value,
2307 pp_bind_table(5).bind_value;
2308 ELSIF(l_bind_counter = 6) THEN
2309 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2310 pp_bind_table(2).bind_value,
2311 pp_bind_table(3).bind_value,
2312 pp_bind_table(4).bind_value,
2313 pp_bind_table(5).bind_value,
2314 pp_bind_table(6).bind_value;
2315 ELSIF(l_bind_counter = 7) THEN
2316 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2317 pp_bind_table(2).bind_value,
2318 pp_bind_table(3).bind_value,
2319 pp_bind_table(4).bind_value,
2320 pp_bind_table(5).bind_value,
2321 pp_bind_table(6).bind_value,
2322 pp_bind_table(7).bind_value;
2323 ELSIF(l_bind_counter = 8) THEN
2324 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2325 pp_bind_table(2).bind_value,
2326 pp_bind_table(3).bind_value,
2327 pp_bind_table(4).bind_value,
2328 pp_bind_table(5).bind_value,
2329 pp_bind_table(6).bind_value,
2330 pp_bind_table(7).bind_value,
2331 pp_bind_table(8).bind_value;
2332 ELSIF(l_bind_counter = 9) THEN
2333 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2334 pp_bind_table(2).bind_value,
2335 pp_bind_table(3).bind_value,
2336 pp_bind_table(4).bind_value,
2337 pp_bind_table(5).bind_value,
2338 pp_bind_table(6).bind_value,
2339 pp_bind_table(7).bind_value,
2340 pp_bind_table(8).bind_value,
2341 pp_bind_table(9).bind_value;
2342
2343 ELSIF(l_bind_counter = 10) THEN
2344 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2345 pp_bind_table(2).bind_value,
2346 pp_bind_table(3).bind_value,
2347 pp_bind_table(4).bind_value,
2348 pp_bind_table(5).bind_value,
2349 pp_bind_table(6).bind_value,
2350 pp_bind_table(7).bind_value,
2351 pp_bind_table(8).bind_value,
2352 pp_bind_table(9).bind_value,
2353 pp_bind_table(10).bind_value;
2354 ELSIF(l_bind_counter = 11) THEN
2355 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2356 pp_bind_table(2).bind_value,
2357 pp_bind_table(3).bind_value,
2358 pp_bind_table(4).bind_value,
2359 pp_bind_table(5).bind_value,
2360 pp_bind_table(6).bind_value,
2361 pp_bind_table(7).bind_value,
2362 pp_bind_table(8).bind_value,
2363 pp_bind_table(9).bind_value,
2364 pp_bind_table(10).bind_value,
2365 pp_bind_table(11).bind_value;
2366 ELSIF(l_bind_counter = 12) THEN
2367 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2368 pp_bind_table(2).bind_value,
2369 pp_bind_table(3).bind_value,
2370 pp_bind_table(4).bind_value,
2371 pp_bind_table(5).bind_value,
2372 pp_bind_table(6).bind_value,
2373 pp_bind_table(7).bind_value,
2374 pp_bind_table(8).bind_value,
2375 pp_bind_table(9).bind_value,
2376 pp_bind_table(10).bind_value,
2377 pp_bind_table(11).bind_value,
2378 pp_bind_table(12).bind_value;
2379 ELSIF(l_bind_counter = 13) THEN
2380 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2381 pp_bind_table(2).bind_value,
2382 pp_bind_table(3).bind_value,
2383 pp_bind_table(4).bind_value,
2384 pp_bind_table(5).bind_value,
2385 pp_bind_table(6).bind_value,
2386 pp_bind_table(7).bind_value,
2387 pp_bind_table(8).bind_value,
2388 pp_bind_table(9).bind_value,
2389 pp_bind_table(10).bind_value,
2390 pp_bind_table(11).bind_value,
2391 pp_bind_table(12).bind_value,
2392 pp_bind_table(13).bind_value;
2393 ELSIF(l_bind_counter = 14) THEN
2394 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2395 pp_bind_table(2).bind_value,
2396 pp_bind_table(3).bind_value,
2397 pp_bind_table(4).bind_value,
2398 pp_bind_table(5).bind_value,
2399 pp_bind_table(6).bind_value,
2400 pp_bind_table(7).bind_value,
2401 pp_bind_table(8).bind_value,
2402 pp_bind_table(9).bind_value,
2403 pp_bind_table(10).bind_value,
2404 pp_bind_table(11).bind_value,
2405 pp_bind_table(12).bind_value,
2406 pp_bind_table(13).bind_value,
2407 pp_bind_table(14).bind_value;
2408 ELSIF(l_bind_counter = 15) THEN
2409 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2410 pp_bind_table(2).bind_value,
2411 pp_bind_table(3).bind_value,
2412 pp_bind_table(4).bind_value,
2413 pp_bind_table(5).bind_value,
2414 pp_bind_table(6).bind_value,
2415 pp_bind_table(7).bind_value,
2416 pp_bind_table(8).bind_value,
2417 pp_bind_table(9).bind_value,
2418 pp_bind_table(10).bind_value,
2419 pp_bind_table(11).bind_value,
2420 pp_bind_table(12).bind_value,
2421 pp_bind_table(13).bind_value,
2422 pp_bind_table(14).bind_value,
2423 pp_bind_table(15).bind_value;
2424 ELSIF(l_bind_counter = 16) THEN
2425 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2426 pp_bind_table(2).bind_value,
2427 pp_bind_table(3).bind_value,
2428 pp_bind_table(4).bind_value,
2429 pp_bind_table(5).bind_value,
2430 pp_bind_table(6).bind_value,
2431 pp_bind_table(7).bind_value,
2432 pp_bind_table(8).bind_value,
2433 pp_bind_table(9).bind_value,
2434 pp_bind_table(10).bind_value,
2435 pp_bind_table(11).bind_value,
2436 pp_bind_table(12).bind_value,
2437 pp_bind_table(13).bind_value,
2438 pp_bind_table(14).bind_value,
2439 pp_bind_table(15).bind_value,
2440 pp_bind_table(16).bind_value;
2441
2442 ELSIF(l_bind_counter = 17) THEN
2443 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2444 pp_bind_table(2).bind_value,
2445 pp_bind_table(3).bind_value,
2446 pp_bind_table(4).bind_value,
2447 pp_bind_table(5).bind_value,
2448 pp_bind_table(6).bind_value,
2449 pp_bind_table(7).bind_value,
2450 pp_bind_table(8).bind_value,
2451 pp_bind_table(9).bind_value,
2452 pp_bind_table(10).bind_value,
2453 pp_bind_table(11).bind_value,
2454 pp_bind_table(12).bind_value,
2455 pp_bind_table(13).bind_value,
2456 pp_bind_table(14).bind_value,
2457 pp_bind_table(15).bind_value,
2458 pp_bind_table(16).bind_value,
2459 pp_bind_table(17).bind_value;
2460 ELSIF(l_bind_counter = 18) THEN
2461 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2462 pp_bind_table(2).bind_value,
2463 pp_bind_table(3).bind_value,
2464 pp_bind_table(4).bind_value,
2465 pp_bind_table(5).bind_value,
2466 pp_bind_table(6).bind_value,
2467 pp_bind_table(7).bind_value,
2468 pp_bind_table(8).bind_value,
2469 pp_bind_table(9).bind_value,
2470 pp_bind_table(10).bind_value,
2471 pp_bind_table(11).bind_value,
2472 pp_bind_table(12).bind_value,
2473 pp_bind_table(13).bind_value,
2474 pp_bind_table(14).bind_value,
2475 pp_bind_table(15).bind_value,
2476 pp_bind_table(16).bind_value,
2477 pp_bind_table(17).bind_value,
2478 pp_bind_table(18).bind_value;
2479 ELSIF(l_bind_counter = 19) THEN
2480 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2481 pp_bind_table(2).bind_value,
2482 pp_bind_table(3).bind_value,
2483 pp_bind_table(4).bind_value,
2484 pp_bind_table(5).bind_value,
2485 pp_bind_table(6).bind_value,
2486 pp_bind_table(7).bind_value,
2487 pp_bind_table(8).bind_value,
2488 pp_bind_table(9).bind_value,
2489 pp_bind_table(10).bind_value,
2490 pp_bind_table(11).bind_value,
2491 pp_bind_table(12).bind_value,
2492 pp_bind_table(13).bind_value,
2493 pp_bind_table(14).bind_value,
2494 pp_bind_table(15).bind_value,
2495 pp_bind_table(16).bind_value,
2496 pp_bind_table(17).bind_value,
2497 pp_bind_table(18).bind_value,
2498 pp_bind_table(19).bind_value;
2499
2500 ELSIF(l_bind_counter = 20) THEN
2501 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2502 pp_bind_table(2).bind_value,
2503 pp_bind_table(3).bind_value,
2504 pp_bind_table(4).bind_value,
2505 pp_bind_table(5).bind_value,
2506 pp_bind_table(6).bind_value,
2507 pp_bind_table(7).bind_value,
2508 pp_bind_table(8).bind_value,
2509 pp_bind_table(9).bind_value,
2510 pp_bind_table(10).bind_value,
2511 pp_bind_table(11).bind_value,
2512 pp_bind_table(12).bind_value,
2513 pp_bind_table(13).bind_value,
2514 pp_bind_table(14).bind_value,
2515 pp_bind_table(15).bind_value,
2516 pp_bind_table(16).bind_value,
2517 pp_bind_table(17).bind_value,
2518 pp_bind_table(18).bind_value,
2519 pp_bind_table(19).bind_value,
2520 pp_bind_table(20).bind_value;
2521 ELSIF(l_bind_counter = 21) THEN
2522 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2523 pp_bind_table(2).bind_value,
2524 pp_bind_table(3).bind_value,
2525 pp_bind_table(4).bind_value,
2526 pp_bind_table(5).bind_value,
2527 pp_bind_table(6).bind_value,
2528 pp_bind_table(7).bind_value,
2529 pp_bind_table(8).bind_value,
2530 pp_bind_table(9).bind_value,
2531 pp_bind_table(10).bind_value,
2532 pp_bind_table(11).bind_value,
2533 pp_bind_table(12).bind_value,
2534 pp_bind_table(13).bind_value,
2535 pp_bind_table(14).bind_value,
2536 pp_bind_table(15).bind_value,
2537 pp_bind_table(16).bind_value,
2538 pp_bind_table(17).bind_value,
2539 pp_bind_table(18).bind_value,
2540 pp_bind_table(19).bind_value,
2541 pp_bind_table(20).bind_value,
2542 pp_bind_table(21).bind_value;
2543 ELSIF(l_bind_counter = 22) THEN
2544 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2545 pp_bind_table(2).bind_value,
2546 pp_bind_table(3).bind_value,
2547 pp_bind_table(4).bind_value,
2548 pp_bind_table(5).bind_value,
2549 pp_bind_table(6).bind_value,
2550 pp_bind_table(7).bind_value,
2551 pp_bind_table(8).bind_value,
2552 pp_bind_table(9).bind_value,
2553 pp_bind_table(10).bind_value,
2554 pp_bind_table(11).bind_value,
2555 pp_bind_table(12).bind_value,
2556 pp_bind_table(13).bind_value,
2557 pp_bind_table(14).bind_value,
2558 pp_bind_table(15).bind_value,
2559 pp_bind_table(16).bind_value,
2560 pp_bind_table(17).bind_value,
2561 pp_bind_table(18).bind_value,
2562 pp_bind_table(19).bind_value,
2563 pp_bind_table(20).bind_value,
2564 pp_bind_table(21).bind_value,
2565 pp_bind_table(22).bind_value;
2566
2567 ELSIF(l_bind_counter = 23) THEN
2568 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2569 pp_bind_table(2).bind_value,
2570 pp_bind_table(3).bind_value,
2571 pp_bind_table(4).bind_value,
2572 pp_bind_table(5).bind_value,
2573 pp_bind_table(6).bind_value,
2574 pp_bind_table(7).bind_value,
2575 pp_bind_table(8).bind_value,
2576 pp_bind_table(9).bind_value,
2577 pp_bind_table(10).bind_value,
2578 pp_bind_table(11).bind_value,
2579 pp_bind_table(12).bind_value,
2580 pp_bind_table(13).bind_value,
2581 pp_bind_table(14).bind_value,
2582 pp_bind_table(15).bind_value,
2583 pp_bind_table(16).bind_value,
2584 pp_bind_table(17).bind_value,
2585 pp_bind_table(18).bind_value,
2586 pp_bind_table(19).bind_value,
2587 pp_bind_table(20).bind_value,
2588 pp_bind_table(21).bind_value,
2589 pp_bind_table(22).bind_value,
2590 pp_bind_table(23).bind_value;
2591 ELSIF(l_bind_counter = 24) THEN
2592 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2593 pp_bind_table(2).bind_value,
2594 pp_bind_table(3).bind_value,
2595 pp_bind_table(4).bind_value,
2596 pp_bind_table(5).bind_value,
2597 pp_bind_table(6).bind_value,
2598 pp_bind_table(7).bind_value,
2599 pp_bind_table(8).bind_value,
2600 pp_bind_table(9).bind_value,
2601 pp_bind_table(10).bind_value,
2602 pp_bind_table(11).bind_value,
2603 pp_bind_table(12).bind_value,
2604 pp_bind_table(13).bind_value,
2605 pp_bind_table(14).bind_value,
2606 pp_bind_table(15).bind_value,
2607 pp_bind_table(16).bind_value,
2608 pp_bind_table(17).bind_value,
2609 pp_bind_table(18).bind_value,
2610 pp_bind_table(19).bind_value,
2611 pp_bind_table(20).bind_value,
2612 pp_bind_table(21).bind_value,
2613 pp_bind_table(22).bind_value,
2614 pp_bind_table(23).bind_value,
2615 pp_bind_table(24).bind_value;
2616 ELSIF(l_bind_counter = 25) THEN
2617 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2618 pp_bind_table(2).bind_value,
2619 pp_bind_table(3).bind_value,
2620 pp_bind_table(4).bind_value,
2621 pp_bind_table(5).bind_value,
2622 pp_bind_table(6).bind_value,
2623 pp_bind_table(7).bind_value,
2624 pp_bind_table(8).bind_value,
2625 pp_bind_table(9).bind_value,
2626 pp_bind_table(10).bind_value,
2627 pp_bind_table(11).bind_value,
2628 pp_bind_table(12).bind_value,
2629 pp_bind_table(13).bind_value,
2630 pp_bind_table(14).bind_value,
2631 pp_bind_table(15).bind_value,
2632 pp_bind_table(16).bind_value,
2633 pp_bind_table(17).bind_value,
2634 pp_bind_table(18).bind_value,
2635 pp_bind_table(19).bind_value,
2636 pp_bind_table(20).bind_value,
2637 pp_bind_table(21).bind_value,
2638 pp_bind_table(22).bind_value,
2639 pp_bind_table(23).bind_value,
2640 pp_bind_table(24).bind_value,
2641 pp_bind_table(25).bind_value;
2642 ELSIF(l_bind_counter = 26) THEN
2643 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2644 pp_bind_table(2).bind_value,
2645 pp_bind_table(3).bind_value,
2646 pp_bind_table(4).bind_value,
2647 pp_bind_table(5).bind_value,
2648 pp_bind_table(6).bind_value,
2649 pp_bind_table(7).bind_value,
2650 pp_bind_table(8).bind_value,
2651 pp_bind_table(9).bind_value,
2652 pp_bind_table(10).bind_value,
2653 pp_bind_table(11).bind_value,
2654 pp_bind_table(12).bind_value,
2655 pp_bind_table(13).bind_value,
2656 pp_bind_table(14).bind_value,
2657 pp_bind_table(15).bind_value,
2658 pp_bind_table(16).bind_value,
2659 pp_bind_table(17).bind_value,
2660 pp_bind_table(18).bind_value,
2661 pp_bind_table(19).bind_value,
2662 pp_bind_table(20).bind_value,
2663 pp_bind_table(21).bind_value,
2664 pp_bind_table(22).bind_value,
2665 pp_bind_table(23).bind_value,
2666 pp_bind_table(24).bind_value,
2667 pp_bind_table(25).bind_value,
2668 pp_bind_table(26).bind_value;
2669 ELSIF(l_bind_counter = 27) THEN
2670 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2671 pp_bind_table(2).bind_value,
2672 pp_bind_table(3).bind_value,
2673 pp_bind_table(4).bind_value,
2674 pp_bind_table(5).bind_value,
2675 pp_bind_table(6).bind_value,
2676 pp_bind_table(7).bind_value,
2677 pp_bind_table(8).bind_value,
2678 pp_bind_table(9).bind_value,
2679 pp_bind_table(10).bind_value,
2680 pp_bind_table(11).bind_value,
2681 pp_bind_table(12).bind_value,
2682 pp_bind_table(13).bind_value,
2683 pp_bind_table(14).bind_value,
2684 pp_bind_table(15).bind_value,
2685 pp_bind_table(16).bind_value,
2686 pp_bind_table(17).bind_value,
2687 pp_bind_table(18).bind_value,
2688 pp_bind_table(19).bind_value,
2689 pp_bind_table(20).bind_value,
2690 pp_bind_table(21).bind_value,
2691 pp_bind_table(22).bind_value,
2692 pp_bind_table(23).bind_value,
2693 pp_bind_table(24).bind_value,
2694 pp_bind_table(25).bind_value,
2695 pp_bind_table(26).bind_value,
2696 pp_bind_table(27).bind_value;
2697 ELSIF(l_bind_counter = 28) THEN
2698 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2699 pp_bind_table(2).bind_value,
2700 pp_bind_table(3).bind_value,
2701 pp_bind_table(4).bind_value,
2702 pp_bind_table(5).bind_value,
2703 pp_bind_table(6).bind_value,
2704 pp_bind_table(7).bind_value,
2705 pp_bind_table(8).bind_value,
2706 pp_bind_table(9).bind_value,
2707 pp_bind_table(10).bind_value,
2708 pp_bind_table(11).bind_value,
2709 pp_bind_table(12).bind_value,
2710 pp_bind_table(13).bind_value,
2711 pp_bind_table(14).bind_value,
2712 pp_bind_table(15).bind_value,
2713 pp_bind_table(16).bind_value,
2714 pp_bind_table(17).bind_value,
2715 pp_bind_table(18).bind_value,
2716 pp_bind_table(19).bind_value,
2717 pp_bind_table(20).bind_value,
2718 pp_bind_table(21).bind_value,
2719 pp_bind_table(22).bind_value,
2720 pp_bind_table(23).bind_value,
2721 pp_bind_table(24).bind_value,
2722 pp_bind_table(25).bind_value,
2723 pp_bind_table(26).bind_value,
2724 pp_bind_table(27).bind_value,
2725 pp_bind_table(28).bind_value;
2726 ELSIF(l_bind_counter = 29) THEN
2727 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2728 pp_bind_table(2).bind_value,
2729 pp_bind_table(3).bind_value,
2730 pp_bind_table(4).bind_value,
2731 pp_bind_table(5).bind_value,
2732 pp_bind_table(6).bind_value,
2733 pp_bind_table(7).bind_value,
2734 pp_bind_table(8).bind_value,
2735 pp_bind_table(9).bind_value,
2736 pp_bind_table(10).bind_value,
2737 pp_bind_table(11).bind_value,
2738 pp_bind_table(12).bind_value,
2739 pp_bind_table(13).bind_value,
2740 pp_bind_table(14).bind_value,
2741 pp_bind_table(15).bind_value,
2742 pp_bind_table(16).bind_value,
2743 pp_bind_table(17).bind_value,
2744 pp_bind_table(18).bind_value,
2745 pp_bind_table(19).bind_value,
2746 pp_bind_table(20).bind_value,
2747 pp_bind_table(21).bind_value,
2748 pp_bind_table(22).bind_value,
2749 pp_bind_table(23).bind_value,
2750 pp_bind_table(24).bind_value,
2751 pp_bind_table(25).bind_value,
2752 pp_bind_table(26).bind_value,
2753 pp_bind_table(27).bind_value,
2754 pp_bind_table(28).bind_value,
2755 pp_bind_table(29).bind_value;
2756 ELSIF(l_bind_counter = 30) THEN
2757 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2758 pp_bind_table(2).bind_value,
2759 pp_bind_table(3).bind_value,
2760 pp_bind_table(4).bind_value,
2761 pp_bind_table(5).bind_value,
2762 pp_bind_table(6).bind_value,
2763 pp_bind_table(7).bind_value,
2764 pp_bind_table(8).bind_value,
2765 pp_bind_table(9).bind_value,
2766 pp_bind_table(10).bind_value,
2767 pp_bind_table(11).bind_value,
2768 pp_bind_table(12).bind_value,
2769 pp_bind_table(13).bind_value,
2770 pp_bind_table(14).bind_value,
2771 pp_bind_table(15).bind_value,
2772 pp_bind_table(16).bind_value,
2773 pp_bind_table(17).bind_value,
2774 pp_bind_table(18).bind_value,
2775 pp_bind_table(19).bind_value,
2776 pp_bind_table(20).bind_value,
2777 pp_bind_table(21).bind_value,
2778 pp_bind_table(22).bind_value,
2779 pp_bind_table(23).bind_value,
2780 pp_bind_table(24).bind_value,
2781 pp_bind_table(25).bind_value,
2782 pp_bind_table(26).bind_value,
2783 pp_bind_table(27).bind_value,
2784 pp_bind_table(28).bind_value,
2785 pp_bind_table(29).bind_value,
2786 pp_bind_table(30).bind_value;
2787 ELSIF(l_bind_counter = 31) THEN
2788 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2789 pp_bind_table(2).bind_value,
2790 pp_bind_table(3).bind_value,
2791 pp_bind_table(4).bind_value,
2792 pp_bind_table(5).bind_value,
2793 pp_bind_table(6).bind_value,
2794 pp_bind_table(7).bind_value,
2795 pp_bind_table(8).bind_value,
2796 pp_bind_table(9).bind_value,
2797 pp_bind_table(10).bind_value,
2798 pp_bind_table(11).bind_value,
2799 pp_bind_table(12).bind_value,
2800 pp_bind_table(13).bind_value,
2801 pp_bind_table(14).bind_value,
2802 pp_bind_table(15).bind_value,
2803 pp_bind_table(16).bind_value,
2804 pp_bind_table(17).bind_value,
2805 pp_bind_table(18).bind_value,
2806 pp_bind_table(19).bind_value,
2807 pp_bind_table(20).bind_value,
2808 pp_bind_table(21).bind_value,
2809 pp_bind_table(22).bind_value,
2810 pp_bind_table(23).bind_value,
2811 pp_bind_table(24).bind_value,
2812 pp_bind_table(25).bind_value,
2813 pp_bind_table(26).bind_value,
2814 pp_bind_table(27).bind_value,
2815 pp_bind_table(28).bind_value,
2816 pp_bind_table(29).bind_value,
2817 pp_bind_table(30).bind_value,
2818 pp_bind_table(31).bind_value;
2819 ELSIF(l_bind_counter = 32) THEN
2820 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2821 pp_bind_table(2).bind_value,
2822 pp_bind_table(3).bind_value,
2823 pp_bind_table(4).bind_value,
2824 pp_bind_table(5).bind_value,
2825 pp_bind_table(6).bind_value,
2826 pp_bind_table(7).bind_value,
2827 pp_bind_table(8).bind_value,
2828 pp_bind_table(9).bind_value,
2829 pp_bind_table(10).bind_value,
2830 pp_bind_table(11).bind_value,
2831 pp_bind_table(12).bind_value,
2832 pp_bind_table(13).bind_value,
2833 pp_bind_table(14).bind_value,
2834 pp_bind_table(15).bind_value,
2835 pp_bind_table(16).bind_value,
2836 pp_bind_table(17).bind_value,
2837 pp_bind_table(18).bind_value,
2838 pp_bind_table(19).bind_value,
2839 pp_bind_table(20).bind_value,
2840 pp_bind_table(21).bind_value,
2841 pp_bind_table(22).bind_value,
2842 pp_bind_table(23).bind_value,
2843 pp_bind_table(24).bind_value,
2844 pp_bind_table(25).bind_value,
2845 pp_bind_table(26).bind_value,
2846 pp_bind_table(27).bind_value,
2847 pp_bind_table(28).bind_value,
2848 pp_bind_table(29).bind_value,
2849 pp_bind_table(30).bind_value,
2850 pp_bind_table(31).bind_value,
2851 pp_bind_table(32).bind_value;
2852 ELSIF(l_bind_counter = 33) THEN
2853 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2854 pp_bind_table(2).bind_value,
2855 pp_bind_table(3).bind_value,
2856 pp_bind_table(4).bind_value,
2857 pp_bind_table(5).bind_value,
2858 pp_bind_table(6).bind_value,
2859 pp_bind_table(7).bind_value,
2860 pp_bind_table(8).bind_value,
2861 pp_bind_table(9).bind_value,
2862 pp_bind_table(10).bind_value,
2863 pp_bind_table(11).bind_value,
2864 pp_bind_table(12).bind_value,
2865 pp_bind_table(13).bind_value,
2866 pp_bind_table(14).bind_value,
2867 pp_bind_table(15).bind_value,
2868 pp_bind_table(16).bind_value,
2869 pp_bind_table(17).bind_value,
2870 pp_bind_table(18).bind_value,
2871 pp_bind_table(19).bind_value,
2872 pp_bind_table(20).bind_value,
2873 pp_bind_table(21).bind_value,
2874 pp_bind_table(22).bind_value,
2875 pp_bind_table(23).bind_value,
2876 pp_bind_table(24).bind_value,
2877 pp_bind_table(25).bind_value,
2878 pp_bind_table(26).bind_value,
2879 pp_bind_table(27).bind_value,
2880 pp_bind_table(28).bind_value,
2881 pp_bind_table(29).bind_value,
2882 pp_bind_table(30).bind_value,
2883 pp_bind_table(31).bind_value,
2884 pp_bind_table(32).bind_value,
2885 pp_bind_table(33).bind_value;
2886 ELSIF(l_bind_counter = 34) THEN
2887 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2888 pp_bind_table(2).bind_value,
2889 pp_bind_table(3).bind_value,
2890 pp_bind_table(4).bind_value,
2891 pp_bind_table(5).bind_value,
2892 pp_bind_table(6).bind_value,
2893 pp_bind_table(7).bind_value,
2894 pp_bind_table(8).bind_value,
2895 pp_bind_table(9).bind_value,
2896 pp_bind_table(10).bind_value,
2897 pp_bind_table(11).bind_value,
2898 pp_bind_table(12).bind_value,
2899 pp_bind_table(13).bind_value,
2900 pp_bind_table(14).bind_value,
2901 pp_bind_table(15).bind_value,
2902 pp_bind_table(16).bind_value,
2903 pp_bind_table(17).bind_value,
2904 pp_bind_table(18).bind_value,
2905 pp_bind_table(19).bind_value,
2906 pp_bind_table(20).bind_value,
2907 pp_bind_table(21).bind_value,
2908 pp_bind_table(22).bind_value,
2909 pp_bind_table(23).bind_value,
2910 pp_bind_table(24).bind_value,
2911 pp_bind_table(25).bind_value,
2912 pp_bind_table(26).bind_value,
2913 pp_bind_table(27).bind_value,
2914 pp_bind_table(28).bind_value,
2915 pp_bind_table(29).bind_value,
2916 pp_bind_table(30).bind_value,
2917 pp_bind_table(31).bind_value,
2918 pp_bind_table(32).bind_value,
2919 pp_bind_table(33).bind_value,
2920 pp_bind_table(34).bind_value;
2921 ELSIF(l_bind_counter = 35) THEN
2922 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2923 pp_bind_table(2).bind_value,
2924 pp_bind_table(3).bind_value,
2925 pp_bind_table(4).bind_value,
2926 pp_bind_table(5).bind_value,
2927 pp_bind_table(6).bind_value,
2928 pp_bind_table(7).bind_value,
2929 pp_bind_table(8).bind_value,
2930 pp_bind_table(9).bind_value,
2931 pp_bind_table(10).bind_value,
2932 pp_bind_table(11).bind_value,
2933 pp_bind_table(12).bind_value,
2934 pp_bind_table(13).bind_value,
2935 pp_bind_table(14).bind_value,
2936 pp_bind_table(15).bind_value,
2937 pp_bind_table(16).bind_value,
2938 pp_bind_table(17).bind_value,
2939 pp_bind_table(18).bind_value,
2940 pp_bind_table(19).bind_value,
2941 pp_bind_table(20).bind_value,
2942 pp_bind_table(21).bind_value,
2943 pp_bind_table(22).bind_value,
2944 pp_bind_table(23).bind_value,
2945 pp_bind_table(24).bind_value,
2946 pp_bind_table(25).bind_value,
2947 pp_bind_table(26).bind_value,
2948 pp_bind_table(27).bind_value,
2949 pp_bind_table(28).bind_value,
2950 pp_bind_table(29).bind_value,
2951 pp_bind_table(30).bind_value,
2952 pp_bind_table(31).bind_value,
2953 pp_bind_table(32).bind_value,
2954 pp_bind_table(33).bind_value,
2955 pp_bind_table(34).bind_value,
2956 pp_bind_table(35).bind_value;
2957 ELSIF(l_bind_counter = 36) THEN
2958 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2959 pp_bind_table(2).bind_value,
2960 pp_bind_table(3).bind_value,
2961 pp_bind_table(4).bind_value,
2962 pp_bind_table(5).bind_value,
2963 pp_bind_table(6).bind_value,
2964 pp_bind_table(7).bind_value,
2965 pp_bind_table(8).bind_value,
2966 pp_bind_table(9).bind_value,
2967 pp_bind_table(10).bind_value,
2968 pp_bind_table(11).bind_value,
2969 pp_bind_table(12).bind_value,
2970 pp_bind_table(13).bind_value,
2971 pp_bind_table(14).bind_value,
2972 pp_bind_table(15).bind_value,
2973 pp_bind_table(16).bind_value,
2974 pp_bind_table(17).bind_value,
2975 pp_bind_table(18).bind_value,
2976 pp_bind_table(19).bind_value,
2977 pp_bind_table(20).bind_value,
2978 pp_bind_table(21).bind_value,
2979 pp_bind_table(22).bind_value,
2980 pp_bind_table(23).bind_value,
2981 pp_bind_table(24).bind_value,
2982 pp_bind_table(25).bind_value,
2983 pp_bind_table(26).bind_value,
2984 pp_bind_table(27).bind_value,
2985 pp_bind_table(28).bind_value,
2986 pp_bind_table(29).bind_value,
2987 pp_bind_table(30).bind_value,
2988 pp_bind_table(31).bind_value,
2989 pp_bind_table(32).bind_value,
2990 pp_bind_table(33).bind_value,
2991 pp_bind_table(34).bind_value,
2992 pp_bind_table(35).bind_value,
2993 pp_bind_table(36).bind_value;
2994 ELSIF(l_bind_counter = 37) THEN
2995 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
2996 pp_bind_table(2).bind_value,
2997 pp_bind_table(3).bind_value,
2998 pp_bind_table(4).bind_value,
2999 pp_bind_table(5).bind_value,
3000 pp_bind_table(6).bind_value,
3001 pp_bind_table(7).bind_value,
3002 pp_bind_table(8).bind_value,
3003 pp_bind_table(9).bind_value,
3004 pp_bind_table(10).bind_value,
3005 pp_bind_table(11).bind_value,
3006 pp_bind_table(12).bind_value,
3007 pp_bind_table(13).bind_value,
3008 pp_bind_table(14).bind_value,
3009 pp_bind_table(15).bind_value,
3010 pp_bind_table(16).bind_value,
3011 pp_bind_table(17).bind_value,
3012 pp_bind_table(18).bind_value,
3013 pp_bind_table(19).bind_value,
3014 pp_bind_table(20).bind_value,
3015 pp_bind_table(21).bind_value,
3016 pp_bind_table(22).bind_value,
3017 pp_bind_table(23).bind_value,
3018 pp_bind_table(24).bind_value,
3019 pp_bind_table(25).bind_value,
3020 pp_bind_table(26).bind_value,
3021 pp_bind_table(27).bind_value,
3022 pp_bind_table(28).bind_value,
3023 pp_bind_table(29).bind_value,
3024 pp_bind_table(30).bind_value,
3025 pp_bind_table(31).bind_value,
3026 pp_bind_table(32).bind_value,
3027 pp_bind_table(33).bind_value,
3028 pp_bind_table(34).bind_value,
3029 pp_bind_table(35).bind_value,
3030 pp_bind_table(36).bind_value,
3031 pp_bind_table(37).bind_value;
3032 ELSIF(l_bind_counter = 38) THEN
3033 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
3034 pp_bind_table(2).bind_value,
3035 pp_bind_table(3).bind_value,
3036 pp_bind_table(4).bind_value,
3037 pp_bind_table(5).bind_value,
3038 pp_bind_table(6).bind_value,
3039 pp_bind_table(7).bind_value,
3040 pp_bind_table(8).bind_value,
3041 pp_bind_table(9).bind_value,
3042 pp_bind_table(10).bind_value,
3043 pp_bind_table(11).bind_value,
3044 pp_bind_table(12).bind_value,
3045 pp_bind_table(13).bind_value,
3046 pp_bind_table(14).bind_value,
3047 pp_bind_table(15).bind_value,
3048 pp_bind_table(16).bind_value,
3049 pp_bind_table(17).bind_value,
3050 pp_bind_table(18).bind_value,
3051 pp_bind_table(19).bind_value,
3052 pp_bind_table(20).bind_value,
3053 pp_bind_table(21).bind_value,
3054 pp_bind_table(22).bind_value,
3055 pp_bind_table(23).bind_value,
3056 pp_bind_table(24).bind_value,
3057 pp_bind_table(25).bind_value,
3058 pp_bind_table(26).bind_value,
3059 pp_bind_table(27).bind_value,
3060 pp_bind_table(28).bind_value,
3061 pp_bind_table(29).bind_value,
3062 pp_bind_table(30).bind_value,
3063 pp_bind_table(31).bind_value,
3064 pp_bind_table(32).bind_value,
3065 pp_bind_table(33).bind_value,
3066 pp_bind_table(34).bind_value,
3067 pp_bind_table(35).bind_value,
3068 pp_bind_table(36).bind_value,
3069 pp_bind_table(37).bind_value,
3070 pp_bind_table(38).bind_value;
3071 ELSIF(l_bind_counter = 39) THEN
3072 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
3073 pp_bind_table(2).bind_value,
3074 pp_bind_table(3).bind_value,
3075 pp_bind_table(4).bind_value,
3076 pp_bind_table(5).bind_value,
3077 pp_bind_table(6).bind_value,
3078 pp_bind_table(7).bind_value,
3079 pp_bind_table(8).bind_value,
3080 pp_bind_table(9).bind_value,
3081 pp_bind_table(10).bind_value,
3082 pp_bind_table(11).bind_value,
3083 pp_bind_table(12).bind_value,
3084 pp_bind_table(13).bind_value,
3085 pp_bind_table(14).bind_value,
3086 pp_bind_table(15).bind_value,
3087 pp_bind_table(16).bind_value,
3088 pp_bind_table(17).bind_value,
3089 pp_bind_table(18).bind_value,
3090 pp_bind_table(19).bind_value,
3091 pp_bind_table(20).bind_value,
3092 pp_bind_table(21).bind_value,
3093 pp_bind_table(22).bind_value,
3094 pp_bind_table(23).bind_value,
3095 pp_bind_table(24).bind_value,
3096 pp_bind_table(25).bind_value,
3097 pp_bind_table(26).bind_value,
3098 pp_bind_table(27).bind_value,
3099 pp_bind_table(28).bind_value,
3100 pp_bind_table(29).bind_value,
3101 pp_bind_table(30).bind_value,
3102 pp_bind_table(31).bind_value,
3103 pp_bind_table(32).bind_value,
3104 pp_bind_table(33).bind_value,
3105 pp_bind_table(34).bind_value,
3106 pp_bind_table(35).bind_value,
3107 pp_bind_table(36).bind_value,
3108 pp_bind_table(37).bind_value,
3109 pp_bind_table(38).bind_value,
3110 pp_bind_table(39).bind_value;
3111 ELSIF(l_bind_counter = 40) THEN
3112 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
3113 pp_bind_table(2).bind_value,
3114 pp_bind_table(3).bind_value,
3115 pp_bind_table(4).bind_value,
3116 pp_bind_table(5).bind_value,
3117 pp_bind_table(6).bind_value,
3118 pp_bind_table(7).bind_value,
3119 pp_bind_table(8).bind_value,
3120 pp_bind_table(9).bind_value,
3121 pp_bind_table(10).bind_value,
3122 pp_bind_table(11).bind_value,
3123 pp_bind_table(12).bind_value,
3124 pp_bind_table(13).bind_value,
3125 pp_bind_table(14).bind_value,
3126 pp_bind_table(15).bind_value,
3127 pp_bind_table(16).bind_value,
3128 pp_bind_table(17).bind_value,
3129 pp_bind_table(18).bind_value,
3130 pp_bind_table(19).bind_value,
3131 pp_bind_table(20).bind_value,
3132 pp_bind_table(21).bind_value,
3133 pp_bind_table(22).bind_value,
3134 pp_bind_table(23).bind_value,
3135 pp_bind_table(24).bind_value,
3136 pp_bind_table(25).bind_value,
3137 pp_bind_table(26).bind_value,
3138 pp_bind_table(27).bind_value,
3139 pp_bind_table(28).bind_value,
3140 pp_bind_table(29).bind_value,
3141 pp_bind_table(30).bind_value,
3142 pp_bind_table(31).bind_value,
3143 pp_bind_table(32).bind_value,
3144 pp_bind_table(33).bind_value,
3145 pp_bind_table(34).bind_value,
3146 pp_bind_table(35).bind_value,
3147 pp_bind_table(36).bind_value,
3148 pp_bind_table(37).bind_value,
3149 pp_bind_table(38).bind_value,
3150 pp_bind_table(39).bind_value,
3151 pp_bind_table(40).bind_value;
3152 ELSIF(l_bind_counter = 41) THEN
3153 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
3154 pp_bind_table(2).bind_value,
3155 pp_bind_table(3).bind_value,
3156 pp_bind_table(4).bind_value,
3157 pp_bind_table(5).bind_value,
3158 pp_bind_table(6).bind_value,
3159 pp_bind_table(7).bind_value,
3160 pp_bind_table(8).bind_value,
3161 pp_bind_table(9).bind_value,
3162 pp_bind_table(10).bind_value,
3163 pp_bind_table(11).bind_value,
3164 pp_bind_table(12).bind_value,
3165 pp_bind_table(13).bind_value,
3166 pp_bind_table(14).bind_value,
3167 pp_bind_table(15).bind_value,
3168 pp_bind_table(16).bind_value,
3169 pp_bind_table(17).bind_value,
3170 pp_bind_table(18).bind_value,
3171 pp_bind_table(19).bind_value,
3172 pp_bind_table(20).bind_value,
3173 pp_bind_table(21).bind_value,
3174 pp_bind_table(22).bind_value,
3175 pp_bind_table(23).bind_value,
3176 pp_bind_table(24).bind_value,
3177 pp_bind_table(25).bind_value,
3178 pp_bind_table(26).bind_value,
3179 pp_bind_table(27).bind_value,
3180 pp_bind_table(28).bind_value,
3181 pp_bind_table(29).bind_value,
3182 pp_bind_table(30).bind_value,
3183 pp_bind_table(31).bind_value,
3184 pp_bind_table(32).bind_value,
3185 pp_bind_table(33).bind_value,
3186 pp_bind_table(34).bind_value,
3187 pp_bind_table(35).bind_value,
3188 pp_bind_table(36).bind_value,
3189 pp_bind_table(37).bind_value,
3190 pp_bind_table(38).bind_value,
3191 pp_bind_table(39).bind_value,
3192 pp_bind_table(40).bind_value,
3193 pp_bind_table(41).bind_value;
3194 ELSIF(l_bind_counter = 42) THEN
3195 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
3196 pp_bind_table(2).bind_value,
3197 pp_bind_table(3).bind_value,
3198 pp_bind_table(4).bind_value,
3199 pp_bind_table(5).bind_value,
3200 pp_bind_table(6).bind_value,
3201 pp_bind_table(7).bind_value,
3202 pp_bind_table(8).bind_value,
3203 pp_bind_table(9).bind_value,
3204 pp_bind_table(10).bind_value,
3205 pp_bind_table(11).bind_value,
3206 pp_bind_table(12).bind_value,
3207 pp_bind_table(13).bind_value,
3208 pp_bind_table(14).bind_value,
3209 pp_bind_table(15).bind_value,
3210 pp_bind_table(16).bind_value,
3211 pp_bind_table(17).bind_value,
3212 pp_bind_table(18).bind_value,
3213 pp_bind_table(19).bind_value,
3214 pp_bind_table(20).bind_value,
3215 pp_bind_table(21).bind_value,
3216 pp_bind_table(22).bind_value,
3217 pp_bind_table(23).bind_value,
3218 pp_bind_table(24).bind_value,
3219 pp_bind_table(25).bind_value,
3220 pp_bind_table(26).bind_value,
3221 pp_bind_table(27).bind_value,
3222 pp_bind_table(28).bind_value,
3223 pp_bind_table(29).bind_value,
3224 pp_bind_table(30).bind_value,
3225 pp_bind_table(31).bind_value,
3226 pp_bind_table(32).bind_value,
3227 pp_bind_table(33).bind_value,
3228 pp_bind_table(34).bind_value,
3229 pp_bind_table(35).bind_value,
3230 pp_bind_table(36).bind_value,
3231 pp_bind_table(37).bind_value,
3232 pp_bind_table(38).bind_value,
3233 pp_bind_table(39).bind_value,
3234 pp_bind_table(40).bind_value,
3235 pp_bind_table(41).bind_value,
3236 pp_bind_table(42).bind_value;
3237 ELSIF(l_bind_counter = 43) THEN
3238 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
3239 pp_bind_table(2).bind_value,
3240 pp_bind_table(3).bind_value,
3241 pp_bind_table(4).bind_value,
3242 pp_bind_table(5).bind_value,
3243 pp_bind_table(6).bind_value,
3244 pp_bind_table(7).bind_value,
3245 pp_bind_table(8).bind_value,
3246 pp_bind_table(9).bind_value,
3247 pp_bind_table(10).bind_value,
3248 pp_bind_table(11).bind_value,
3249 pp_bind_table(12).bind_value,
3250 pp_bind_table(13).bind_value,
3251 pp_bind_table(14).bind_value,
3252 pp_bind_table(15).bind_value,
3253 pp_bind_table(16).bind_value,
3254 pp_bind_table(17).bind_value,
3255 pp_bind_table(18).bind_value,
3256 pp_bind_table(19).bind_value,
3257 pp_bind_table(20).bind_value,
3258 pp_bind_table(21).bind_value,
3259 pp_bind_table(22).bind_value,
3260 pp_bind_table(23).bind_value,
3261 pp_bind_table(24).bind_value,
3262 pp_bind_table(25).bind_value,
3263 pp_bind_table(26).bind_value,
3264 pp_bind_table(27).bind_value,
3265 pp_bind_table(28).bind_value,
3266 pp_bind_table(29).bind_value,
3267 pp_bind_table(30).bind_value,
3268 pp_bind_table(31).bind_value,
3269 pp_bind_table(32).bind_value,
3270 pp_bind_table(33).bind_value,
3271 pp_bind_table(34).bind_value,
3272 pp_bind_table(35).bind_value,
3273 pp_bind_table(36).bind_value,
3274 pp_bind_table(37).bind_value,
3275 pp_bind_table(38).bind_value,
3276 pp_bind_table(39).bind_value,
3277 pp_bind_table(40).bind_value,
3278 pp_bind_table(41).bind_value,
3279 pp_bind_table(42).bind_value,
3280 pp_bind_table(43).bind_value;
3281 ELSIF(l_bind_counter = 44) THEN
3282 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
3283 pp_bind_table(2).bind_value,
3284 pp_bind_table(3).bind_value,
3285 pp_bind_table(4).bind_value,
3286 pp_bind_table(5).bind_value,
3287 pp_bind_table(6).bind_value,
3288 pp_bind_table(7).bind_value,
3289 pp_bind_table(8).bind_value,
3290 pp_bind_table(9).bind_value,
3291 pp_bind_table(10).bind_value,
3292 pp_bind_table(11).bind_value,
3293 pp_bind_table(12).bind_value,
3294 pp_bind_table(13).bind_value,
3295 pp_bind_table(14).bind_value,
3296 pp_bind_table(15).bind_value,
3297 pp_bind_table(16).bind_value,
3298 pp_bind_table(17).bind_value,
3299 pp_bind_table(18).bind_value,
3300 pp_bind_table(19).bind_value,
3301 pp_bind_table(20).bind_value,
3302 pp_bind_table(21).bind_value,
3303 pp_bind_table(22).bind_value,
3304 pp_bind_table(23).bind_value,
3305 pp_bind_table(24).bind_value,
3306 pp_bind_table(25).bind_value,
3307 pp_bind_table(26).bind_value,
3308 pp_bind_table(27).bind_value,
3309 pp_bind_table(28).bind_value,
3310 pp_bind_table(29).bind_value,
3311 pp_bind_table(30).bind_value,
3312 pp_bind_table(31).bind_value,
3313 pp_bind_table(32).bind_value,
3314 pp_bind_table(33).bind_value,
3315 pp_bind_table(34).bind_value,
3316 pp_bind_table(35).bind_value,
3317 pp_bind_table(36).bind_value,
3318 pp_bind_table(37).bind_value,
3319 pp_bind_table(38).bind_value,
3320 pp_bind_table(39).bind_value,
3321 pp_bind_table(40).bind_value,
3322 pp_bind_table(41).bind_value,
3323 pp_bind_table(42).bind_value,
3324 pp_bind_table(43).bind_value,
3325 pp_bind_table(44).bind_value;
3326 ELSIF(l_bind_counter = 45) THEN
3327 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
3328 pp_bind_table(2).bind_value,
3329 pp_bind_table(3).bind_value,
3330 pp_bind_table(4).bind_value,
3331 pp_bind_table(5).bind_value,
3332 pp_bind_table(6).bind_value,
3333 pp_bind_table(7).bind_value,
3334 pp_bind_table(8).bind_value,
3335 pp_bind_table(9).bind_value,
3336 pp_bind_table(10).bind_value,
3337 pp_bind_table(11).bind_value,
3338 pp_bind_table(12).bind_value,
3339 pp_bind_table(13).bind_value,
3340 pp_bind_table(14).bind_value,
3341 pp_bind_table(15).bind_value,
3342 pp_bind_table(16).bind_value,
3343 pp_bind_table(17).bind_value,
3344 pp_bind_table(18).bind_value,
3345 pp_bind_table(19).bind_value,
3346 pp_bind_table(20).bind_value,
3347 pp_bind_table(21).bind_value,
3348 pp_bind_table(22).bind_value,
3349 pp_bind_table(23).bind_value,
3350 pp_bind_table(24).bind_value,
3351 pp_bind_table(25).bind_value,
3352 pp_bind_table(26).bind_value,
3353 pp_bind_table(27).bind_value,
3354 pp_bind_table(28).bind_value,
3355 pp_bind_table(29).bind_value,
3356 pp_bind_table(30).bind_value,
3357 pp_bind_table(31).bind_value,
3358 pp_bind_table(32).bind_value,
3359 pp_bind_table(33).bind_value,
3360 pp_bind_table(34).bind_value,
3361 pp_bind_table(35).bind_value,
3362 pp_bind_table(36).bind_value,
3363 pp_bind_table(37).bind_value,
3364 pp_bind_table(38).bind_value,
3365 pp_bind_table(39).bind_value,
3366 pp_bind_table(40).bind_value,
3367 pp_bind_table(41).bind_value,
3368 pp_bind_table(42).bind_value,
3369 pp_bind_table(43).bind_value,
3370 pp_bind_table(44).bind_value,
3371 pp_bind_table(45).bind_value;
3372 ELSIF(l_bind_counter = 46) THEN
3373 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
3374 pp_bind_table(2).bind_value,
3375 pp_bind_table(3).bind_value,
3376 pp_bind_table(4).bind_value,
3377 pp_bind_table(5).bind_value,
3378 pp_bind_table(6).bind_value,
3379 pp_bind_table(7).bind_value,
3380 pp_bind_table(8).bind_value,
3381 pp_bind_table(9).bind_value,
3382 pp_bind_table(10).bind_value,
3383 pp_bind_table(11).bind_value,
3384 pp_bind_table(12).bind_value,
3385 pp_bind_table(13).bind_value,
3386 pp_bind_table(14).bind_value,
3387 pp_bind_table(15).bind_value,
3388 pp_bind_table(16).bind_value,
3389 pp_bind_table(17).bind_value,
3390 pp_bind_table(18).bind_value,
3391 pp_bind_table(19).bind_value,
3392 pp_bind_table(20).bind_value,
3393 pp_bind_table(21).bind_value,
3394 pp_bind_table(22).bind_value,
3395 pp_bind_table(23).bind_value,
3396 pp_bind_table(24).bind_value,
3397 pp_bind_table(25).bind_value,
3398 pp_bind_table(26).bind_value,
3399 pp_bind_table(27).bind_value,
3400 pp_bind_table(28).bind_value,
3401 pp_bind_table(29).bind_value,
3402 pp_bind_table(30).bind_value,
3403 pp_bind_table(31).bind_value,
3404 pp_bind_table(32).bind_value,
3405 pp_bind_table(33).bind_value,
3406 pp_bind_table(34).bind_value,
3407 pp_bind_table(35).bind_value,
3408 pp_bind_table(36).bind_value,
3409 pp_bind_table(37).bind_value,
3410 pp_bind_table(38).bind_value,
3411 pp_bind_table(39).bind_value,
3412 pp_bind_table(40).bind_value,
3413 pp_bind_table(41).bind_value,
3414 pp_bind_table(42).bind_value,
3415 pp_bind_table(43).bind_value,
3416 pp_bind_table(44).bind_value,
3417 pp_bind_table(45).bind_value,
3418 pp_bind_table(46).bind_value;
3419 ELSIF(l_bind_counter = 47) THEN
3420 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
3421 pp_bind_table(2).bind_value,
3422 pp_bind_table(3).bind_value,
3423 pp_bind_table(4).bind_value,
3424 pp_bind_table(5).bind_value,
3425 pp_bind_table(6).bind_value,
3426 pp_bind_table(7).bind_value,
3427 pp_bind_table(8).bind_value,
3428 pp_bind_table(9).bind_value,
3429 pp_bind_table(10).bind_value,
3430 pp_bind_table(11).bind_value,
3431 pp_bind_table(12).bind_value,
3432 pp_bind_table(13).bind_value,
3433 pp_bind_table(14).bind_value,
3434 pp_bind_table(15).bind_value,
3435 pp_bind_table(16).bind_value,
3436 pp_bind_table(17).bind_value,
3437 pp_bind_table(18).bind_value,
3438 pp_bind_table(19).bind_value,
3439 pp_bind_table(20).bind_value,
3440 pp_bind_table(21).bind_value,
3441 pp_bind_table(22).bind_value,
3442 pp_bind_table(23).bind_value,
3443 pp_bind_table(24).bind_value,
3444 pp_bind_table(25).bind_value,
3445 pp_bind_table(26).bind_value,
3446 pp_bind_table(27).bind_value,
3447 pp_bind_table(28).bind_value,
3448 pp_bind_table(29).bind_value,
3449 pp_bind_table(30).bind_value,
3450 pp_bind_table(31).bind_value,
3451 pp_bind_table(32).bind_value,
3452 pp_bind_table(33).bind_value,
3453 pp_bind_table(34).bind_value,
3454 pp_bind_table(35).bind_value,
3455 pp_bind_table(36).bind_value,
3456 pp_bind_table(37).bind_value,
3457 pp_bind_table(38).bind_value,
3458 pp_bind_table(39).bind_value,
3459 pp_bind_table(40).bind_value,
3460 pp_bind_table(41).bind_value,
3461 pp_bind_table(42).bind_value,
3462 pp_bind_table(43).bind_value,
3463 pp_bind_table(44).bind_value,
3464 pp_bind_table(45).bind_value,
3465 pp_bind_table(46).bind_value,
3466 pp_bind_table(47).bind_value;
3467 ELSIF(l_bind_counter = 48) THEN
3468 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
3469 pp_bind_table(2).bind_value,
3470 pp_bind_table(3).bind_value,
3471 pp_bind_table(4).bind_value,
3472 pp_bind_table(5).bind_value,
3473 pp_bind_table(6).bind_value,
3474 pp_bind_table(7).bind_value,
3475 pp_bind_table(8).bind_value,
3476 pp_bind_table(9).bind_value,
3477 pp_bind_table(10).bind_value,
3478 pp_bind_table(11).bind_value,
3479 pp_bind_table(12).bind_value,
3480 pp_bind_table(13).bind_value,
3481 pp_bind_table(14).bind_value,
3482 pp_bind_table(15).bind_value,
3483 pp_bind_table(16).bind_value,
3484 pp_bind_table(17).bind_value,
3485 pp_bind_table(18).bind_value,
3486 pp_bind_table(19).bind_value,
3487 pp_bind_table(20).bind_value,
3488 pp_bind_table(21).bind_value,
3489 pp_bind_table(22).bind_value,
3490 pp_bind_table(23).bind_value,
3491 pp_bind_table(24).bind_value,
3492 pp_bind_table(25).bind_value,
3493 pp_bind_table(26).bind_value,
3494 pp_bind_table(27).bind_value,
3495 pp_bind_table(28).bind_value,
3496 pp_bind_table(29).bind_value,
3497 pp_bind_table(30).bind_value,
3498 pp_bind_table(31).bind_value,
3499 pp_bind_table(32).bind_value,
3500 pp_bind_table(33).bind_value,
3501 pp_bind_table(34).bind_value,
3502 pp_bind_table(35).bind_value,
3503 pp_bind_table(36).bind_value,
3504 pp_bind_table(37).bind_value,
3505 pp_bind_table(38).bind_value,
3506 pp_bind_table(39).bind_value,
3507 pp_bind_table(40).bind_value,
3508 pp_bind_table(41).bind_value,
3509 pp_bind_table(42).bind_value,
3510 pp_bind_table(43).bind_value,
3511 pp_bind_table(44).bind_value,
3512 pp_bind_table(45).bind_value,
3513 pp_bind_table(46).bind_value,
3514 pp_bind_table(47).bind_value,
3515 pp_bind_table(48).bind_value;
3516 ELSIF(l_bind_counter = 49) THEN
3517 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
3518 pp_bind_table(2).bind_value,
3519 pp_bind_table(3).bind_value,
3520 pp_bind_table(4).bind_value,
3521 pp_bind_table(5).bind_value,
3522 pp_bind_table(6).bind_value,
3523 pp_bind_table(7).bind_value,
3524 pp_bind_table(8).bind_value,
3525 pp_bind_table(9).bind_value,
3526 pp_bind_table(10).bind_value,
3527 pp_bind_table(11).bind_value,
3528 pp_bind_table(12).bind_value,
3529 pp_bind_table(13).bind_value,
3530 pp_bind_table(14).bind_value,
3531 pp_bind_table(15).bind_value,
3532 pp_bind_table(16).bind_value,
3533 pp_bind_table(17).bind_value,
3534 pp_bind_table(18).bind_value,
3535 pp_bind_table(19).bind_value,
3536 pp_bind_table(20).bind_value,
3537 pp_bind_table(21).bind_value,
3538 pp_bind_table(22).bind_value,
3539 pp_bind_table(23).bind_value,
3540 pp_bind_table(24).bind_value,
3541 pp_bind_table(25).bind_value,
3542 pp_bind_table(26).bind_value,
3543 pp_bind_table(27).bind_value,
3544 pp_bind_table(28).bind_value,
3545 pp_bind_table(29).bind_value,
3546 pp_bind_table(30).bind_value,
3547 pp_bind_table(31).bind_value,
3548 pp_bind_table(32).bind_value,
3549 pp_bind_table(33).bind_value,
3550 pp_bind_table(34).bind_value,
3551 pp_bind_table(35).bind_value,
3552 pp_bind_table(36).bind_value,
3553 pp_bind_table(37).bind_value,
3554 pp_bind_table(38).bind_value,
3555 pp_bind_table(39).bind_value,
3556 pp_bind_table(40).bind_value,
3557 pp_bind_table(41).bind_value,
3558 pp_bind_table(42).bind_value,
3559 pp_bind_table(43).bind_value,
3560 pp_bind_table(44).bind_value,
3561 pp_bind_table(45).bind_value,
3562 pp_bind_table(46).bind_value,
3563 pp_bind_table(47).bind_value,
3564 pp_bind_table(48).bind_value,
3565 pp_bind_table(49).bind_value;
3566 ELSIF(l_bind_counter = 50) THEN
3567 OPEN geo_cv FOR l_sql_stmt USING pp_bind_table(1).bind_value,
3568 pp_bind_table(2).bind_value,
3569 pp_bind_table(3).bind_value,
3570 pp_bind_table(4).bind_value,
3571 pp_bind_table(5).bind_value,
3572 pp_bind_table(6).bind_value,
3573 pp_bind_table(7).bind_value,
3574 pp_bind_table(8).bind_value,
3575 pp_bind_table(9).bind_value,
3576 pp_bind_table(10).bind_value,
3577 pp_bind_table(11).bind_value,
3578 pp_bind_table(12).bind_value,
3579 pp_bind_table(13).bind_value,
3580 pp_bind_table(14).bind_value,
3581 pp_bind_table(15).bind_value,
3582 pp_bind_table(16).bind_value,
3583 pp_bind_table(17).bind_value,
3584 pp_bind_table(18).bind_value,
3585 pp_bind_table(19).bind_value,
3586 pp_bind_table(20).bind_value,
3587 pp_bind_table(21).bind_value,
3588 pp_bind_table(22).bind_value,
3589 pp_bind_table(23).bind_value,
3590 pp_bind_table(24).bind_value,
3591 pp_bind_table(25).bind_value,
3592 pp_bind_table(26).bind_value,
3593 pp_bind_table(27).bind_value,
3594 pp_bind_table(28).bind_value,
3595 pp_bind_table(29).bind_value,
3596 pp_bind_table(30).bind_value,
3597 pp_bind_table(31).bind_value,
3598 pp_bind_table(32).bind_value,
3599 pp_bind_table(33).bind_value,
3600 pp_bind_table(34).bind_value,
3601 pp_bind_table(35).bind_value,
3602 pp_bind_table(36).bind_value,
3603 pp_bind_table(37).bind_value,
3604 pp_bind_table(38).bind_value,
3605 pp_bind_table(39).bind_value,
3606 pp_bind_table(40).bind_value,
3607 pp_bind_table(41).bind_value,
3608 pp_bind_table(42).bind_value,
3609 pp_bind_table(43).bind_value,
3610 pp_bind_table(44).bind_value,
3611 pp_bind_table(45).bind_value,
3612 pp_bind_table(46).bind_value,
3613 pp_bind_table(47).bind_value,
3614 pp_bind_table(48).bind_value,
3615 pp_bind_table(49).bind_value,
3616 pp_bind_table(50).bind_value;
3617 END IF;
3618
3619 LOOP
3620 FETCH geo_cv INTO geo_rec;
3621 EXIT WHEN geo_cv%NOTFOUND;
3622 l_geo_data_count := geo_rec_tbl.COUNT + 1;
3623 EXIT WHEN l_geo_data_count > l_max_fetch_count; -- only suggest these many values
3624 -- Check if it is a multiple parent record.
3625 IF (geo_rec.multiple_parent_flag = 'Y') THEN
3626 -- If so do a seperate processing
3627 multiple_parent_proc(geo_rec.geography_id, geo_rec.geography_type);
3628 ELSE
3629 -- If not multiple parents, fetch values and do processing
3630 geo_rec_tbl(l_geo_data_count) := geo_rec;
3631 END IF; -- multiple parent check
3632 END LOOP;
3633 CLOSE geo_cv;
3634 END IF; -- end of sql stmt not null check
3635
3636 END search_routine_pvt;
3637
3638 -----------------------------------------------------------------------------+
3639 -- Procedure to check if input and output values match in case of multiple
3640 -- records. If there is exact match (for complete mapping), then retain that
3641 -- record and delete other records as we have found what user wanted to enter.
3642 -- This check will be done before starting output processing.
3643 -- There is no use suggesting alternates.
3644 -- Created By Nishant Singhai (29-Sep-2005) for Bug 4633962
3645 -----------------------------------------------------------------------------+
3646 PROCEDURE check_exact_match_del_rest IS
3647
3648 l_element_matched VARCHAR2(10);
3649 l_check_next_row VARCHAR2(10);
3650 l_exact_row_match_found VARCHAR2(10);
3651
3652 l_geo_suggest_tbl_temp hz_gnr_pvt.geo_suggest_tbl_type;
3653
3654 PROCEDURE priv_match_proc(ll_index number, ll_tbl_value IN VARCHAR2) IS
3655 BEGIN
3656 IF ((REPLACE(geo_struct_tbl(ll_index).v_param_value,'%','') =
3657 UPPER(ll_tbl_value)))
3658 THEN
3659 l_element_matched := 'Y'; -- match
3660 ELSE
3661 l_element_matched := 'N'; -- no match
3662 END IF;
3663 END priv_match_proc;
3664
3665 PROCEDURE do_match (p_tab_col IN VARCHAR2, p_suggest_tbl_index IN NUMBER, p_struct_tbl_index IN NUMBER) IS
3666 i NUMBER;
3667 j NUMBER;
3668 BEGIN
3669 i := p_suggest_tbl_index;
3670 j := p_struct_tbl_index;
3671 CASE p_tab_col
3672 WHEN 'COUNTRY' THEN
3673 priv_match_proc(j, geo_suggest_tbl(i).country_code);
3674 WHEN 'STATE' THEN
3675 priv_match_proc(j, geo_suggest_tbl(i).state);
3676 WHEN 'PROVINCE' THEN
3677 priv_match_proc(j, geo_suggest_tbl(i).province);
3678 WHEN 'COUNTY' THEN
3679 priv_match_proc(j, geo_suggest_tbl(i).county);
3680 WHEN 'CITY' THEN
3681 priv_match_proc(j, geo_suggest_tbl(i).city);
3682 WHEN 'POSTAL_CODE' THEN
3683 priv_match_proc(j, geo_suggest_tbl(i).postal_code);
3684 WHEN 'POSTAL_PLUS4_CODE' THEN
3685 priv_match_proc(j, geo_suggest_tbl(i).postal_plus4_code);
3686 WHEN 'ATTRIBUTE1' THEN
3687 priv_match_proc(j, geo_suggest_tbl(i).attribute1);
3688 WHEN 'ATTRIBUTE2' THEN
3689 priv_match_proc(j, geo_suggest_tbl(i).attribute2);
3690 WHEN 'ATTRIBUTE3' THEN
3691 priv_match_proc(j, geo_suggest_tbl(i).attribute3);
3692 WHEN 'ATTRIBUTE4' THEN
3693 priv_match_proc(j, geo_suggest_tbl(i).attribute4);
3694 WHEN 'ATTRIBUTE5' THEN
3695 priv_match_proc(j, geo_suggest_tbl(i).attribute5);
3696 WHEN 'ATTRIBUTE6' THEN
3697 priv_match_proc(j, geo_suggest_tbl(i).attribute6);
3698 WHEN 'ATTRIBUTE7' THEN
3699 priv_match_proc(j, geo_suggest_tbl(i).attribute7);
3700 WHEN 'ATTRIBUTE8' THEN
3701 priv_match_proc(j, geo_suggest_tbl(i).attribute8);
3702 WHEN 'ATTRIBUTE9' THEN
3703 priv_match_proc(j, geo_suggest_tbl(i).attribute9);
3704 WHEN 'ATTRIBUTE10' THEN
3705 priv_match_proc(j, geo_suggest_tbl(i).attribute10);
3706 ELSE
3707 NULL;
3708 END CASE;
3709
3710 END do_match;
3711
3712 BEGIN
3713 -- FND Logging for debug purpose
3714 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
3715 hz_utility_v2pub.debug
3716 (p_message => 'Begin procedure check_exact_match_del_rest(+)',
3717 p_prefix => l_debug_prefix,
3718 p_msg_level => fnd_log.level_procedure,
3719 p_module_prefix => l_module_prefix,
3720 p_module => l_module
3721 );
3722 END IF;
3723
3724 l_element_matched := 'Y';
3725 l_check_next_row := 'Y';
3726 l_exact_row_match_found := 'N';
3727
3728 -- check if user has entered all mapped columns.
3729 IF (geo_struct_tbl.COUNT > 0 AND geo_suggest_tbl.COUNT > 0) THEN
3730
3731 -- FND Logging for debug purpose
3732 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
3733 hz_utility_v2pub.debug
3734 (p_message => 'Geo_struct_tbl and geo_suggest_tbl count greater than 0',
3735 p_prefix => l_debug_prefix,
3736 p_msg_level => fnd_log.level_statement,
3737 p_module_prefix => l_module_prefix,
3738 p_module => l_module
3739 );
3740 END IF;
3741
3742 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
3743 IF (geo_struct_tbl(i).v_param_value IS NULL) THEN
3744
3745 -- FND Logging for debug purpose
3746 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
3747 hz_utility_v2pub.debug
3748 (p_message => 'Input value for '||geo_struct_tbl(i).v_tab_col||' is null '||
3749 'No use proceeding with input out put match. Exiting procedure.',
3750 p_prefix => l_debug_prefix,
3751 p_msg_level => fnd_log.level_statement,
3752 p_module_prefix => l_module_prefix,
3753 p_module => l_module
3754 );
3755 END IF;
3756
3757 l_check_next_row := 'N'; -- no use doing match
3758 EXIT;
3759 END IF;
3760 END LOOP;
3761 ELSE
3762 -- FND Logging for debug purpose
3763 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
3764 hz_utility_v2pub.debug
3765 (p_message => 'Geo_struct_tbl and geo_suggest_tbl count is less than 0.'||
3766 'No use proceeding with input out put match. Exiting procedure.',
3767 p_prefix => l_debug_prefix,
3768 p_msg_level => fnd_log.level_statement,
3769 p_module_prefix => l_module_prefix,
3770 p_module => l_module
3771 );
3772 END IF;
3773
3774 l_check_next_row := 'N';
3775 END IF;
3776
3777 -- all parameters are passed
3778 IF (l_check_next_row = 'Y') THEN
3779
3780 -- FND Logging for debug purpose
3781 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
3782 hz_utility_v2pub.debug
3783 (p_message => 'All params passed. Start matching input values with fetched data',
3784 p_prefix => l_debug_prefix,
3785 p_msg_level => fnd_log.level_statement,
3786 p_module_prefix => l_module_prefix,
3787 p_module => l_module
3788 );
3789 END IF;
3790
3791 FOR i IN geo_suggest_tbl.FIRST..geo_suggest_tbl.LAST LOOP
3792 IF (l_check_next_row = 'Y') THEN
3793
3794 FOR j IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
3795 do_match(geo_struct_tbl(j).v_tab_col, i, j);
3796 -- if not matched, go to next row of suggest table
3797 IF (l_element_matched = 'Y') THEN
3798 l_check_next_row := 'N';
3799 l_exact_row_match_found := 'Y';
3800 ELSE
3801 l_check_next_row := 'Y';
3802 l_exact_row_match_found := 'N';
3803 EXIT;
3804 END IF;
3805 END LOOP; -- geo_struct_tbl loop
3806
3807 IF (l_exact_row_match_found = 'Y') THEN
3808
3809 -- FND Logging for debug purpose
3810 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
3811 hz_utility_v2pub.debug
3812 (p_message => 'Exact match found. Copying that row into '||
3813 'final suggest tbl and deleting rest of suggestions',
3814 p_prefix => l_debug_prefix,
3815 p_msg_level => fnd_log.level_statement,
3816 p_module_prefix => l_module_prefix,
3817 p_module => l_module
3818 );
3819 END IF;
3820
3821 -- DELETE all other rows and keep only this row in address suggestion
3822 l_geo_suggest_tbl_temp(1) := geo_suggest_tbl(i);
3823 geo_suggest_tbl.DELETE;
3824 geo_suggest_tbl := l_geo_suggest_tbl_temp;
3825 -- set the counter in case of number of records is null (i.e. more than 55)
3826 IF (l_geo_data_count > l_max_fetch_count) THEN
3827 l_geo_data_count := geo_suggest_tbl.COUNT;
3828 END IF;
3829 EXIT;
3830 END IF;
3831
3832 END IF;
3833 END LOOP; -- geo_suggest_tbl loop
3834
3835 END IF;
3836
3837 -- FND Logging for debug purpose
3838 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
3839 hz_utility_v2pub.debug
3840 (p_message => 'Completed procedure check_exact_match_del_rest(-)',
3841 p_prefix => l_debug_prefix,
3842 p_msg_level => fnd_log.level_procedure,
3843 p_module_prefix => l_module_prefix,
3844 p_module => l_module
3845 );
3846 END IF;
3847
3848 END check_exact_match_del_rest;
3849
3850 -----------------------------------------------------------------------------+
3851 -- Function to check if all input and output values match
3852 -- This is used in case of 1 record fetched
3853 -- For multiple records fetched, first check_exact_match_del_rest will be called
3854 -----------------------------------------------------------------------------+
3855 FUNCTION do_input_output_match_check RETURN BOOLEAN
3856 IS
3857 l_last_tab_col VARCHAR2(100);
3858 l_match NUMBER;
3859
3860 PROCEDURE priv_match_proc(ll_index number, ll_tbl_value IN VARCHAR2,
3861 ll_tbl_value_code IN VARCHAR2, ll_tbl_value_id IN NUMBER) IS
3862 BEGIN
3863 -- ns_debug.put_line('In Match Procedure..');
3864 -- ns_debug.put_line('Left Side : '||REPLACE(geo_struct_tbl(ll_index).v_param_value,'%',''));
3865 -- ns_debug.put_line('Right Side: '||UPPER(ll_tbl_value));
3866 -- ns_debug.put_line('Right Side: '||UPPER(ll_tbl_value_code));
3867 -- Handle NVL with some randon value. NULL = NULL is not success case
3868 -- Bug 5167520 (Nishant 17-APR-2006) When only country is passed but more geo usage fields
3869 -- are to be validated, then if only country is fetched in search result, then it should not be
3870 -- treated as exact match
3871 IF ( (ll_tbl_value_id IS NOT NULL) AND -- Bug 5167520 (Nishant 17-APR-2006)
3872 (
3873 (NVL(REPLACE(geo_struct_tbl(ll_index).v_param_value,'%',''),'XdFj734') =
3874 NVL(UPPER(ll_tbl_value),'PaXT36h'))
3875 OR
3876 (NVL(REPLACE(geo_struct_tbl(ll_index).v_param_value,'%',''),'XdFj734') =
3877 NVL(UPPER(ll_tbl_value_code),'PaXT36h'))
3878 )
3879 )
3880 THEN
3881 l_match := 1; -- match
3882 ELSE
3883 l_match := 2; -- no match
3884 END IF;
3885 END;
3886
3887 BEGIN
3888
3889 l_match := 0;
3890
3891 -- get last mapped table column
3892 IF (geo_struct_tbl.COUNT > 0 AND geo_suggest_tbl.COUNT > 0) THEN
3893 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
3894
3895 -- match the input and output values for Geo usage columns
3896 -- IF geo_struct_tbl(i).v_param_value IS NOT NULL THEN
3897 IF geo_struct_tbl(i).v_valid_for_usage = 'Y' THEN
3898 CASE geo_struct_tbl(i).v_tab_col
3899 -- checking for geo_id not null because to handle 'MISSING' and 'UNKNOWN'
3900 -- geo codes, we are making geo name NULL but retaing geo_id and geo_code
3901 -- for them. So, even if geo name is NULL, it is possible to have
3902 -- geo_id and geo_code populated.
3903 WHEN 'COUNTRY' THEN
3904 priv_match_proc(i, geo_suggest_tbl(1).country,
3905 geo_suggest_tbl(1).country_code, geo_suggest_tbl(1).country_geo_id);
3906 WHEN 'STATE' THEN
3907 priv_match_proc(i, geo_suggest_tbl(1).state,
3908 geo_suggest_tbl(1).state_code, geo_suggest_tbl(1).state_geo_id);
3909 WHEN 'PROVINCE' THEN
3910 priv_match_proc(i, geo_suggest_tbl(1).province,
3911 geo_suggest_tbl(1).province_code, geo_suggest_tbl(1).province_geo_id);
3912 WHEN 'COUNTY' THEN
3913 priv_match_proc(i, geo_suggest_tbl(1).county,
3914 geo_suggest_tbl(1).county, geo_suggest_tbl(1).county_geo_id) ;
3915 WHEN 'CITY' THEN
3916 priv_match_proc(i, geo_suggest_tbl(1).city,
3917 geo_suggest_tbl(1).city, geo_suggest_tbl(1).city_geo_id);
3918 WHEN 'POSTAL_CODE' THEN
3919 priv_match_proc(i, geo_suggest_tbl(1).postal_code,
3920 geo_suggest_tbl(1).postal_code, geo_suggest_tbl(1).postal_code_geo_id);
3921 WHEN 'POSTAL_PLUS4_CODE' THEN
3922 priv_match_proc(i, geo_suggest_tbl(1).postal_plus4_code,
3923 geo_suggest_tbl(1).postal_plus4_code, geo_suggest_tbl(1).postal_plus4_code_geo_id);
3924 WHEN 'ATTRIBUTE1' THEN
3925 priv_match_proc(i, geo_suggest_tbl(1).attribute1, geo_suggest_tbl(1).attribute1,
3926 geo_suggest_tbl(1).attribute1_geo_id);
3927 WHEN 'ATTRIBUTE2' THEN
3928 priv_match_proc(i, geo_suggest_tbl(1).attribute2, geo_suggest_tbl(1).attribute2,
3929 geo_suggest_tbl(1).attribute2_geo_id);
3930 WHEN 'ATTRIBUTE3' THEN
3931 priv_match_proc(i, geo_suggest_tbl(1).attribute3, geo_suggest_tbl(1).attribute3,
3932 geo_suggest_tbl(1).attribute3_geo_id);
3933 WHEN 'ATTRIBUTE4' THEN
3934 priv_match_proc(i, geo_suggest_tbl(1).attribute4, geo_suggest_tbl(1).attribute4,
3935 geo_suggest_tbl(1).attribute4_geo_id);
3936 WHEN 'ATTRIBUTE5' THEN
3937 priv_match_proc(i, geo_suggest_tbl(1).attribute5, geo_suggest_tbl(1).attribute5,
3938 geo_suggest_tbl(1).attribute5_geo_id);
3939 WHEN 'ATTRIBUTE6' THEN
3940 priv_match_proc(i, geo_suggest_tbl(1).attribute6, geo_suggest_tbl(1).attribute6,
3941 geo_suggest_tbl(1).attribute6_geo_id);
3942 WHEN 'ATTRIBUTE7' THEN
3943 priv_match_proc(i, geo_suggest_tbl(1).attribute7, geo_suggest_tbl(1).attribute7,
3944 geo_suggest_tbl(1).attribute7_geo_id);
3945 WHEN 'ATTRIBUTE8' THEN
3946 priv_match_proc(i, geo_suggest_tbl(1).attribute8, geo_suggest_tbl(1).attribute8,
3947 geo_suggest_tbl(1).attribute8_geo_id);
3948 WHEN 'ATTRIBUTE9' THEN
3949 priv_match_proc(i, geo_suggest_tbl(1).attribute9, geo_suggest_tbl(1).attribute9,
3950 geo_suggest_tbl(1).attribute9_geo_id);
3951 WHEN 'ATTRIBUTE10' THEN
3952 priv_match_proc(i, geo_suggest_tbl(1).attribute10, geo_suggest_tbl(1).attribute10,
3953 geo_suggest_tbl(1).attribute10_geo_id);
3954 ELSE
3955 NULL;
3956 END CASE;
3957
3958 -- if does not match then exit loop
3959 IF (l_match = 2) THEN
3960 EXIT;
3961 END IF;
3962
3963 END IF; -- end of v_valid_for_usage = 'Y' check
3964
3965 END LOOP; -- end of geo struct loop
3966 END IF; -- end of geo struct tbl count check
3967
3968 IF (l_match = 2) THEN
3969
3970 -- FND Logging for debug purpose
3971 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
3972 hz_utility_v2pub.debug
3973 (p_message => 'Input values not exactly same as fetched values for usage',
3974 p_prefix => l_debug_prefix,
3975 p_msg_level => fnd_log.level_statement,
3976 p_module_prefix => l_module_prefix,
3977 p_module => l_module
3978 );
3979 END IF;
3980
3981 RETURN FALSE;
3982 ELSE
3983
3984 -- FND Logging for debug purpose
3985 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
3986 hz_utility_v2pub.debug
3987 (p_message => 'Input values matches fetched values',
3988 p_prefix => l_debug_prefix,
3989 p_msg_level => fnd_log.level_statement,
3990 p_module_prefix => l_module_prefix,
3991 p_module => l_module
3992 );
3993 END IF;
3994
3995 RETURN TRUE;
3996 END IF;
3997
3998 END do_input_output_match_check;
3999
4000 -----------------------------------------------------------------------------+
4001 -- Private procedure to build mapping table which can be used throughout the
4002 -- code.
4003 -----------------------------------------------------------------------------+
4004 PROCEDURE build_geo_struct_tbl_pvt (pv_country_code IN VARCHAR2, pv_address_style IN VARCHAR2,
4005 pv_table_name IN VARCHAR2, pv_address_usage IN VARCHAR2) IS
4006
4007 i INTEGER;
4008 l_temp NUMBER;
4009 l_address_style VARCHAR2(255);
4010 l_mapped_column_list VARCHAR2(255);
4011 l_mapped_geo_type_list VARCHAR2(255);
4012 l_passed_param_values VARCHAR2(255);
4013
4014 CURSOR c_full_struct_not_null (ll_country_code VARCHAR2, ll_address_style VARCHAR2,
4015 ll_table_name VARCHAR2)
4016 IS
4017 SELECT dmap.loc_component, dmap.geography_type, dmap.geo_element_col, dmap.loc_seq_num
4018 FROM hz_geo_struct_map smap
4019 ,hz_geo_struct_map_dtl dmap
4020 WHERE smap.address_style = ll_address_style
4021 AND SMAP.country_code = ll_country_code
4022 AND SMAP.loc_tbl_name = ll_table_name
4023 AND smap.map_id = dmap.map_id
4024 ORDER BY dmap.loc_seq_num;
4025
4026 CURSOR c_full_struct_for_null (ll_country_code VARCHAR2, ll_table_name VARCHAR2)
4027 IS
4028 SELECT dmap.loc_component, dmap.geography_type, dmap.geo_element_col, dmap.loc_seq_num
4029 FROM hz_geo_struct_map smap
4030 ,hz_geo_struct_map_dtl dmap
4031 WHERE smap.address_style IS NULL
4032 AND SMAP.country_code = ll_country_code
4033 AND SMAP.loc_tbl_name = ll_table_name
4034 AND smap.map_id = dmap.map_id
4035 ORDER BY dmap.loc_seq_num;
4036
4037 CURSOR c_usage_not_null (ll_country_code VARCHAR2, ll_address_style VARCHAR2,
4038 ll_table_name VARCHAR2, ll_usage VARCHAR2)
4039 IS
4040 SELECT haud.geography_type
4041 FROM hz_geo_struct_map smap
4042 ,hz_geo_struct_map_dtl dmap
4043 ,hz_address_usages hau
4044 ,hz_address_usage_dtls haud
4045 WHERE smap.address_style = ll_address_style
4046 AND SMAP.country_code = ll_country_code
4047 AND SMAP.loc_tbl_name = ll_table_name
4048 AND smap.map_id = dmap.map_id
4049 AND smap.map_id = hau.map_id
4050 AND hau.usage_code = ll_usage
4051 AND hau.status_flag = 'A'
4052 AND hau.usage_id = haud.usage_id
4053 AND haud.geography_type = dmap.geography_type
4054 ORDER BY dmap.loc_seq_num;
4055
4056 CURSOR c_usage_for_null (ll_country_code VARCHAR2,
4057 ll_table_name VARCHAR2, ll_usage VARCHAR2)
4058 IS
4059 SELECT haud.geography_type
4060 FROM hz_geo_struct_map smap
4061 ,hz_geo_struct_map_dtl dmap
4062 ,hz_address_usages hau
4063 ,hz_address_usage_dtls haud
4064 WHERE smap.address_style IS NULL
4065 AND SMAP.country_code = ll_country_code
4066 AND SMAP.loc_tbl_name = ll_table_name
4067 AND smap.map_id = dmap.map_id
4068 AND smap.map_id = hau.map_id
4069 AND hau.usage_code = ll_usage
4070 AND hau.status_flag = 'A'
4071 AND hau.usage_id = haud.usage_id
4072 AND haud.geography_type = dmap.geography_type
4073 ORDER BY dmap.loc_seq_num;
4074
4075 BEGIN
4076 i := 0;
4077 geo_struct_tbl.DELETE;
4078 l_max_usage_element_col_value := 0;
4079
4080 IF ((LENGTH(pv_address_style) = 0) OR (pv_address_style IS NULL)) THEN
4081 l_address_style := NULL;
4082 ELSE
4083 l_address_style := pv_address_style;
4084 END IF;
4085
4086 -- FND Logging for debug purpose
4087 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4088 hz_utility_v2pub.debug
4089 (p_message => 'Address Style passed is :'||l_address_style,
4090 p_prefix => l_debug_prefix,
4091 p_msg_level => fnd_log.level_statement,
4092 p_module_prefix => l_module_prefix,
4093 p_module => l_module
4094 );
4095 END IF;
4096
4097 IF (l_address_style IS NOT NULL) THEN
4098 FOR c_full_struct_rec IN c_full_struct_not_null (UPPER(pv_country_code), l_address_style,
4099 UPPER(pv_table_name))
4100 LOOP
4101 i := i+1;
4102 geo_struct_tbl(i).v_tab_col := c_full_struct_rec.loc_component;
4103 geo_struct_tbl(i).v_geo_type := c_full_struct_rec.geography_type;
4104 geo_struct_tbl(i).v_element_col := c_full_struct_rec.geo_element_col;
4105 geo_struct_tbl(i).v_level := c_full_struct_rec.loc_seq_num;
4106 l_temp := 1;
4107 END LOOP;
4108 END IF;
4109
4110 -- if no data found then, try with NULL address style (which is default address style)
4111 IF (geo_struct_tbl.COUNT = 0) THEN
4112
4113 -- FND Logging for debug purpose
4114 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4115 hz_utility_v2pub.debug
4116 (p_message => 'Either address style is NULL or mapping for passed address style not found.'||
4117 ' Trying with NULL address style.',
4118 p_prefix => l_debug_prefix,
4119 p_msg_level => fnd_log.level_statement,
4120 p_module_prefix => l_module_prefix,
4121 p_module => l_module
4122 );
4123 END IF;
4124
4125 -- try with NULL address style
4126 FOR c_full_struct_rec IN c_full_struct_for_null (UPPER(pv_country_code), UPPER(pv_table_name))
4127 LOOP
4128 i := i+1;
4129 geo_struct_tbl(i).v_tab_col := c_full_struct_rec.loc_component;
4130 geo_struct_tbl(i).v_geo_type := c_full_struct_rec.geography_type;
4131 geo_struct_tbl(i).v_element_col := c_full_struct_rec.geo_element_col;
4132 geo_struct_tbl(i).v_level := c_full_struct_rec.loc_seq_num;
4133 l_temp := 2;
4134 END LOOP;
4135 END IF;
4136
4137 -- fill in usage column in case of not null address style
4138 IF ((l_temp = 1) AND (geo_struct_tbl.COUNT > 0)) THEN
4139 FOR c_full_struct_rec IN c_usage_not_null (UPPER(pv_country_code), l_address_style,
4140 UPPER(pv_table_name), UPPER(pv_address_usage))
4141 LOOP
4142 FOR j IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
4143 IF (geo_struct_tbl(j).v_geo_type = c_full_struct_rec.geography_type) THEN
4144 geo_struct_tbl(j).v_valid_for_usage := 'Y';
4145 END IF;
4146 END LOOP;
4147 END LOOP;
4148 END IF;
4149
4150 -- fill in usage column if null address style is used
4151 IF ((l_temp = 2) AND (geo_struct_tbl.COUNT > 0)) THEN
4152 FOR c_full_struct_rec IN c_usage_for_null (UPPER(pv_country_code),
4153 UPPER(pv_table_name), UPPER(pv_address_usage))
4154 LOOP
4155 FOR j IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
4156 IF (geo_struct_tbl(j).v_geo_type = c_full_struct_rec.geography_type) THEN
4157 geo_struct_tbl(j).v_valid_for_usage := 'Y';
4158 END IF;
4159 END LOOP;
4160 END LOOP;
4161 END IF;
4162
4163 -- FND Logging for debug purpose
4164 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4165 hz_utility_v2pub.debug
4166 (p_message => 'Mapped structure count :'||TO_CHAR(geo_struct_tbl.COUNT),
4167 p_prefix => l_debug_prefix,
4168 p_msg_level => fnd_log.level_statement,
4169 p_module_prefix => l_module_prefix,
4170 p_module => l_module
4171 );
4172 END IF;
4173
4174 -- Read the mapped structure and based on mapping of each table column
4175 -- read the values of input parameters passed. If mapped table column
4176 -- is STATE then read value of parameter p_state and so on.
4177 IF (geo_struct_tbl.COUNT > 0) THEN
4178 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
4179
4180 l_mapped_column_list := SUBSTR(l_mapped_column_list||' '||geo_struct_tbl(i).v_tab_col,1,255);
4181 l_mapped_geo_type_list := SUBSTR(l_mapped_geo_type_list||' '||geo_struct_tbl(i).v_geo_type,1,255);
4182
4183 CASE geo_struct_tbl(i).v_tab_col
4184 WHEN 'COUNTRY' THEN
4185 IF (p_country_code IS NOT NULL) THEN
4186 geo_struct_tbl(i).v_param_value := UPPER(p_country_code)||'%';
4187 END IF;
4188 WHEN 'STATE' THEN
4189 IF (p_state IS NOT NULL) THEN
4190 geo_struct_tbl(i).v_param_value := UPPER(p_state)||'%';
4191 END IF;
4192 WHEN 'PROVINCE' THEN
4193 IF (p_province IS NOT NULL) THEN
4194 geo_struct_tbl(i).v_param_value := UPPER(p_province)||'%';
4195 END IF;
4196 WHEN 'COUNTY' THEN
4197 IF (p_county IS NOT NULL) THEN
4198 geo_struct_tbl(i).v_param_value := UPPER(p_county)||'%';
4199 END IF;
4200 WHEN 'CITY' THEN
4201 IF (p_city IS NOT NULL) THEN
4202 geo_struct_tbl(i).v_param_value := UPPER(p_city)||'%';
4203 END IF;
4204 WHEN 'POSTAL_CODE' THEN
4205 IF (p_postal_code IS NOT NULL) THEN
4206 geo_struct_tbl(i).v_param_value := UPPER(p_postal_code)||'%';
4207 END IF;
4208 WHEN 'POSTAL_PLUS4_CODE' THEN
4209 IF (p_postal_plus4_code IS NOT NULL) THEN
4210 geo_struct_tbl(i).v_param_value := UPPER(p_postal_plus4_code)||'%';
4211 END IF;
4212 WHEN 'ATTRIBUTE1' THEN
4213 IF (p_attribute1 IS NOT NULL) THEN
4214 geo_struct_tbl(i).v_param_value := UPPER(p_attribute1)||'%';
4215 END IF;
4216 WHEN 'ATTRIBUTE2' THEN
4217 IF (p_attribute2 IS NOT NULL) THEN
4218 geo_struct_tbl(i).v_param_value := UPPER(p_attribute2)||'%';
4219 END IF;
4220 WHEN 'ATTRIBUTE3' THEN
4221 IF (p_attribute3 IS NOT NULL) THEN
4222 geo_struct_tbl(i).v_param_value := UPPER(p_attribute3)||'%';
4223 END IF;
4224 WHEN 'ATTRIBUTE4' THEN
4225 IF (p_attribute4 IS NOT NULL) THEN
4226 geo_struct_tbl(i).v_param_value := UPPER(p_attribute4)||'%';
4227 END IF;
4228 WHEN 'ATTRIBUTE5' THEN
4229 IF (p_attribute5 IS NOT NULL) THEN
4230 geo_struct_tbl(i).v_param_value := UPPER(p_attribute5)||'%';
4231 END IF;
4232 WHEN 'ATTRIBUTE6' THEN
4233 IF (p_attribute6 IS NOT NULL) THEN
4234 geo_struct_tbl(i).v_param_value := UPPER(p_attribute6)||'%';
4235 END IF;
4236 WHEN 'ATTRIBUTE7' THEN
4237 IF (p_attribute7 IS NOT NULL) THEN
4238 geo_struct_tbl(i).v_param_value := UPPER(p_attribute7)||'%';
4239 END IF;
4240 WHEN 'ATTRIBUTE8' THEN
4241 IF (p_attribute8 IS NOT NULL) THEN
4242 geo_struct_tbl(i).v_param_value := UPPER(p_attribute8)||'%';
4243 END IF;
4244 WHEN 'ATTRIBUTE9' THEN
4245 IF (p_attribute9 IS NOT NULL) THEN
4246 geo_struct_tbl(i).v_param_value := UPPER(p_attribute9)||'%';
4247 END IF;
4248 WHEN 'ATTRIBUTE10' THEN
4249 IF (p_attribute10 IS NOT NULL) THEN
4250 geo_struct_tbl(i).v_param_value := UPPER(p_attribute10)||'%';
4251 END IF;
4252 ELSE
4253 NULL;
4254 END CASE;
4255
4256 -- Get the max element column which is mapped
4257 -- e.g. if max value of element col is geography_element4, get "4" out of it
4258 l_max_mapped_element_col_value :=
4259 GREATEST(NVL(l_max_mapped_element_col_value,0),TO_NUMBER(SUBSTR(geo_struct_tbl(i).v_element_col,18)));
4260
4261 l_lowest_mapped_geo_type := geo_struct_tbl(i).v_geo_type;
4262
4263 l_passed_param_values := SUBSTR(l_passed_param_values||':'||geo_struct_tbl(i).v_param_value,1,255);
4264
4265 -- Get the max element for which for geo usage is to be valid
4266 IF (geo_struct_tbl(i).v_valid_for_usage = 'Y') THEN
4267 l_max_usage_element_col_value :=
4268 GREATEST(NVL(l_max_usage_element_col_value,0),TO_NUMBER(SUBSTR(geo_struct_tbl(i).v_element_col,18)));
4269
4270 l_lowest_usage_geo_type := geo_struct_tbl(i).v_geo_type;
4271
4272 -- also get the lowest geo type for which value is passed
4273 IF (geo_struct_tbl(i).v_param_value IS NOT NULL) THEN
4274 l_last_geo_type_usg_val_psd := geo_struct_tbl(i).v_geo_type;
4275 END IF;
4276 END IF;
4277
4278 END LOOP;
4279
4280 -- FND Logging for debug purpose
4281 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4282 hz_utility_v2pub.debug
4283 (p_message => SUBSTR('Mapped Columns:'||l_mapped_column_list,1,255),
4284 p_prefix => l_debug_prefix,
4285 p_msg_level => fnd_log.level_statement,
4286 p_module_prefix => l_module_prefix,
4287 p_module => l_module
4288 );
4289 END IF;
4290
4291 -- FND Logging for debug purpose
4292 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4293 hz_utility_v2pub.debug
4294 (p_message => SUBSTR('Mapped Geo Types:'||l_mapped_geo_type_list,1,255),
4295 p_prefix => l_debug_prefix,
4296 p_msg_level => fnd_log.level_statement,
4297 p_module_prefix => l_module_prefix,
4298 p_module => l_module
4299 );
4300 END IF;
4301
4302 -- FND Logging for debug purpose
4303 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4304 hz_utility_v2pub.debug
4305 (p_message => SUBSTR('Passed Param Values'||l_passed_param_values,1,255),
4306 p_prefix => l_debug_prefix,
4307 p_msg_level => fnd_log.level_statement,
4308 p_module_prefix => l_module_prefix,
4309 p_module => l_module
4310 );
4311 END IF;
4312
4313 -- FND Logging for debug purpose
4314 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4315 hz_utility_v2pub.debug
4316 (p_message => 'Max Mapped Element Column Value:'||TO_CHAR(l_max_mapped_element_col_value),
4317 p_prefix => l_debug_prefix,
4318 p_msg_level => fnd_log.level_statement,
4319 p_module_prefix => l_module_prefix,
4320 p_module => l_module
4321 );
4322 END IF;
4323
4324 -- FND Logging for debug purpose
4325 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4326 hz_utility_v2pub.debug
4327 (p_message => 'Max Geo Usage Element Col Value:'||TO_CHAR(l_max_usage_element_col_value),
4328 p_prefix => l_debug_prefix,
4329 p_msg_level => fnd_log.level_statement,
4330 p_module_prefix => l_module_prefix,
4331 p_module => l_module
4332 );
4333 END IF;
4334
4335 -- FND Logging for debug purpose
4336 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4337 hz_utility_v2pub.debug
4338 (p_message => 'Max Geo Type for which Geo usage is marked: '||l_lowest_usage_geo_type,
4339 p_prefix => l_debug_prefix,
4340 p_msg_level => fnd_log.level_statement,
4341 p_module_prefix => l_module_prefix,
4342 p_module => l_module
4343 );
4344 END IF;
4345
4346 -- FND Logging for debug purpose
4347 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4348 hz_utility_v2pub.debug
4349 (p_message => 'Lowest Geo Type for which Geo usage is marked and value is passed: '||l_last_geo_type_usg_val_psd,
4350 p_prefix => l_debug_prefix,
4351 p_msg_level => fnd_log.level_statement,
4352 p_module_prefix => l_module_prefix,
4353 p_module => l_module
4354 );
4355 END IF;
4356
4357 -- copy it to output table also
4358 IF (geo_struct_tbl IS NOT NULL) THEN
4359 x_geo_struct_tbl := geo_struct_tbl;
4360 END IF;
4361
4362 END IF;
4363
4364 x_mapped_struct_count := geo_struct_tbl.COUNT;
4365
4366 END build_geo_struct_tbl_pvt;
4367
4368 ---------------------------------------------------------------------+
4369 -- Build Suggestion List for consumer teams. This is done by concatnating
4370 -- all fetched and mapped values of FInal Table (geo_suggest_tbl).
4371 -- This will be based on the order of mapping fo components.
4372 -- ER # 4600030
4373 ---------------------------------------------------------------------+
4374 PROCEDURE build_suggestion_list IS
4375 l_suggest_list VARCHAR2(4000);
4376
4377 FUNCTION build_list (l_rec_number IN NUMBER, l_position IN NUMBER, l_tab_col IN VARCHAR2) RETURN VARCHAR2
4378 IS
4379 l_list VARCHAR2(4000);
4380 i NUMBER := l_rec_number;
4381 BEGIN
4382 CASE l_tab_col
4383 WHEN 'COUNTRY' THEN
4384 IF (geo_suggest_tbl(i).country_geo_id IS NOT NULL) THEN
4385 IF (l_position = 2 ) THEN
4386 l_list := geo_suggest_tbl(i).country;
4387 ELSIF
4388 (l_position > 2) THEN
4389 l_list := ', '||geo_suggest_tbl(i).country;
4390 END IF;
4391 END IF;
4392 WHEN 'STATE' THEN
4393 IF (geo_suggest_tbl(i).STATE_GEO_ID IS NOT NULL) THEN
4394 IF (l_position = 2) THEN
4395 l_list := geo_suggest_tbl(i).STATE;
4396 ELSIF
4397 (l_position > 2) THEN
4398 l_list := ', '||geo_suggest_tbl(i).STATE;
4399 END IF;
4400 END IF;
4401 WHEN 'PROVINCE' THEN
4402 IF (geo_suggest_tbl(i).PROVINCE_GEO_ID IS NOT NULL) THEN
4403 IF (l_position = 2) THEN
4404 l_list := geo_suggest_tbl(i).PROVINCE;
4405 ELSIF
4406 (l_position > 2) THEN
4407 l_list := ', '||geo_suggest_tbl(i).PROVINCE;
4408 END IF;
4409 END IF;
4410 WHEN 'COUNTY' THEN
4411 IF (geo_suggest_tbl(i).COUNTY_GEO_ID IS NOT NULL) THEN
4412 IF (l_position = 2) THEN
4413 l_list := INITCAP(geo_suggest_tbl(i).COUNTY);
4414 ELSIF
4415 (l_position > 2) THEN
4416 l_list := ', '||INITCAP(geo_suggest_tbl(i).COUNTY);
4417 END IF;
4418 END IF;
4419 WHEN 'CITY' THEN
4420 IF (geo_suggest_tbl(i).CITY_GEO_ID IS NOT NULL) THEN
4421 IF (l_position = 2) THEN
4422 l_list := INITCAP(geo_suggest_tbl(i).CITY);
4423 ELSIF
4424 (l_position > 2) THEN
4425 l_list := ', '||INITCAP(geo_suggest_tbl(i).CITY);
4426 END IF;
4427 END IF;
4428 WHEN 'POSTAL_CODE' THEN
4429 IF (geo_suggest_tbl(i).POSTAL_CODE_GEO_ID IS NOT NULL) THEN
4430 IF (l_position = 2) THEN
4431 l_list := geo_suggest_tbl(i).POSTAL_CODE;
4432 ELSIF
4433 (l_position > 2) THEN
4434 l_list := ', '||geo_suggest_tbl(i).POSTAL_CODE;
4435 END IF;
4436 END IF;
4437 WHEN 'POSTAL_PLUS4_CODE' THEN
4438 IF (geo_suggest_tbl(i).POSTAL_PLUS4_CODE_GEO_ID IS NOT NULL) THEN
4439 IF (l_position = 2) THEN
4440 l_list := geo_suggest_tbl(i).POSTAL_PLUS4_CODE;
4441 ELSIF
4442 (l_position > 2) THEN
4443 l_list := ', '||geo_suggest_tbl(i).POSTAL_PLUS4_CODE;
4444 END IF;
4445 END IF;
4446 WHEN 'ATTRIBUTE1' THEN
4447 IF (geo_suggest_tbl(i).ATTRIBUTE1_GEO_ID IS NOT NULL) THEN
4448 IF (l_position = 2) THEN
4449 l_list := geo_suggest_tbl(i).ATTRIBUTE1;
4450 ELSIF
4451 (l_position > 2) THEN
4452 l_list := ', '||geo_suggest_tbl(i).ATTRIBUTE1;
4453 END IF;
4454 END IF;
4455 WHEN 'ATTRIBUTE2' THEN
4456 IF (geo_suggest_tbl(i).ATTRIBUTE2_GEO_ID IS NOT NULL) THEN
4457 IF (l_position = 2) THEN
4458 l_list := geo_suggest_tbl(i).ATTRIBUTE2;
4459 ELSIF
4460 (l_position > 2) THEN
4461 l_list := ', '||geo_suggest_tbl(i).ATTRIBUTE2;
4462 END IF;
4463 END IF;
4464 WHEN 'ATTRIBUTE3' THEN
4465 IF (geo_suggest_tbl(i).ATTRIBUTE3_GEO_ID IS NOT NULL) THEN
4466 IF (l_position = 2) THEN
4467 l_list := geo_suggest_tbl(i).ATTRIBUTE3;
4468 ELSIF
4469 (l_position > 2) THEN
4470 l_list := ', '||geo_suggest_tbl(i).ATTRIBUTE3;
4471 END IF;
4472 END IF;
4473 WHEN 'ATTRIBUTE4' THEN
4474 IF (geo_suggest_tbl(i).ATTRIBUTE4_GEO_ID IS NOT NULL) THEN
4475 IF (l_position = 2) THEN
4476 l_list := geo_suggest_tbl(i).ATTRIBUTE4;
4477 ELSIF
4478 (l_position > 2) THEN
4479 l_list := ', '||geo_suggest_tbl(i).ATTRIBUTE4;
4480 END IF;
4481 END IF;
4482 WHEN 'ATTRIBUTE5' THEN
4483 IF (geo_suggest_tbl(i).ATTRIBUTE5_GEO_ID IS NOT NULL) THEN
4484 IF (l_position = 2) THEN
4485 l_list := geo_suggest_tbl(i).ATTRIBUTE5;
4486 ELSIF
4487 (l_position > 2) THEN
4488 l_list := ', '||geo_suggest_tbl(i).ATTRIBUTE5;
4489 END IF;
4490 END IF;
4491 WHEN 'ATTRIBUTE6' THEN
4492 IF (geo_suggest_tbl(i).ATTRIBUTE6_GEO_ID IS NOT NULL) THEN
4493 IF (l_position = 2) THEN
4494 l_list := geo_suggest_tbl(i).ATTRIBUTE6;
4495 ELSIF
4496 (l_position > 2) THEN
4497 l_list := ', '||geo_suggest_tbl(i).ATTRIBUTE6;
4498 END IF;
4499 END IF;
4500 WHEN 'ATTRIBUTE7' THEN
4501 IF (geo_suggest_tbl(i).ATTRIBUTE7_GEO_ID IS NOT NULL) THEN
4502 IF (l_position = 2) THEN
4503 l_list := geo_suggest_tbl(i).ATTRIBUTE7;
4504 ELSIF
4505 (l_position > 2) THEN
4506 l_list := ', '||geo_suggest_tbl(i).ATTRIBUTE7;
4507 END IF;
4508 END IF;
4509 WHEN 'ATTRIBUTE8' THEN
4510 IF (geo_suggest_tbl(i).ATTRIBUTE8_GEO_ID IS NOT NULL) THEN
4511 IF (l_position = 2) THEN
4512 l_list := geo_suggest_tbl(i).ATTRIBUTE8;
4513 ELSIF
4514 (l_position > 2) THEN
4515 l_list := ', '||geo_suggest_tbl(i).ATTRIBUTE8;
4516 END IF;
4517 END IF;
4518 WHEN 'ATTRIBUTE9' THEN
4519 IF (geo_suggest_tbl(i).ATTRIBUTE9_GEO_ID IS NOT NULL) THEN
4520 IF (l_position = 2) THEN
4521 l_list := geo_suggest_tbl(i).ATTRIBUTE9;
4522 ELSIF
4523 (l_position > 2) THEN
4524 l_list := ', '||geo_suggest_tbl(i).ATTRIBUTE9;
4525 END IF;
4526 END IF;
4527 WHEN 'ATTRIBUTE10' THEN
4528 IF (geo_suggest_tbl(i).ATTRIBUTE10_GEO_ID IS NOT NULL) THEN
4529 IF (l_position = 2) THEN
4530 l_list := geo_suggest_tbl(i).ATTRIBUTE10;
4531 ELSIF
4532 (l_position > 2) THEN
4533 l_list := ', '||geo_suggest_tbl(i).ATTRIBUTE10;
4534 END IF;
4535 END IF;
4536 ELSE
4537 NULL;
4538 END CASE;
4539
4540 RETURN l_list;
4541 END build_list;
4542
4543 BEGIN
4544 ---------------------------------------------------------------------+
4545 -- Build Suggestion List for consumer teams. This is done by concatnating
4546 -- all fetched and mapped values of Final Table (geo_suggest_tbl).
4547 -- This will be based on the order of mapping fo components.
4548 ---------------------------------------------------------------------+
4549 -- FND Logging for debug purpose
4550 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
4551 hz_utility_v2pub.debug
4552 (p_message => 'Building Suggestion list for Java APIs: build_suggestion_list(+)',
4553 p_prefix => l_debug_prefix,
4554 p_msg_level => fnd_log.level_procedure,
4555 p_module_prefix => l_module_prefix,
4556 p_module => l_module
4557 );
4558 END IF;
4559
4560 IF (geo_suggest_tbl.COUNT > 0) THEN
4561 FOR i IN geo_suggest_tbl.FIRST..geo_suggest_tbl.LAST LOOP
4562 l_suggest_list := NULL;
4563 IF (geo_struct_tbl.COUNT > 0) THEN
4564 FOR j IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
4565 l_suggest_list := l_suggest_list || build_list(i, j, geo_struct_tbl(j).v_tab_col);
4566 END LOOP;
4567 END IF;
4568 geo_suggest_tbl(i).suggestion_list := l_suggest_list;
4569 END LOOP;
4570
4571 -- FND LOGGING FOR DEBUG PURPOSE
4572 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
4573 HZ_UTILITY_V2PUB.DEBUG
4574 (P_MESSAGE => 'Begin procedure quick_sort_suggestion_list(+)',
4575 P_PREFIX => L_DEBUG_PREFIX,
4576 P_MSG_LEVEL => FND_LOG.LEVEL_PROCEDURE,
4577 P_MODULE_PREFIX => L_MODULE_PREFIX,
4578 P_MODULE => L_MODULE
4579 );
4580 END IF;
4581
4582 -- do sorting on geo_suggest_tbl based on suggestion_list column
4583 quick_sort_suggestion_list(geo_suggest_tbl.FIRST, geo_suggest_tbl.LAST, geo_suggest_tbl);
4584
4585 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
4586 hz_utility_v2pub.debug
4587 (p_message => 'End procedure quick_sort_suggestion_list(-)',
4588 p_prefix => l_debug_prefix,
4589 p_msg_level => fnd_log.level_procedure,
4590 p_module_prefix => l_module_prefix,
4591 p_module => l_module
4592 );
4593 END IF;
4594
4595 END IF;
4596
4597 -- Implement check that if only country is fetched, and more has to be validated
4598 -- then suggestion list will be null. In that case delete that country row also.
4599 -- Bug 5391120 (Nishant 21-Jul-2006)
4600 IF (geo_suggest_tbl.COUNT = 1) THEN
4601
4602 -- FND Logging for debug purpose
4603 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
4604 hz_utility_v2pub.debug
4605 (p_message => 'Only 1 row in Suggestion list. Its value is:'||geo_suggest_tbl(1).suggestion_list,
4606 p_prefix => l_debug_prefix,
4607 p_msg_level => fnd_log.level_procedure,
4608 p_module_prefix => l_module_prefix,
4609 p_module => l_module
4610 );
4611 END IF;
4612
4613 IF (geo_suggest_tbl(1).suggestion_list IS NULL OR
4614 LENGTH(LTRIM(RTRIM(geo_suggest_tbl(1).suggestion_list))) = 0) THEN
4615 geo_suggest_tbl.DELETE(1);
4616
4617 -- FND Logging for debug purpose
4618 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
4619 hz_utility_v2pub.debug
4620 (p_message => 'Since value in suggestion list is NULL or of 0 length,'||
4621 'deleting the row from geo_suggest_tbl',
4622 p_prefix => l_debug_prefix,
4623 p_msg_level => fnd_log.level_procedure,
4624 p_module_prefix => l_module_prefix,
4625 p_module => l_module
4626 );
4627 END IF;
4628
4629 END IF;
4630 END IF;
4631
4632 -- FND Logging for debug purpose
4633 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
4634 hz_utility_v2pub.debug
4635 (p_message => 'Completed building Suggestion list for Java APIs: build_suggestion_list(-)',
4636 p_prefix => l_debug_prefix,
4637 p_msg_level => fnd_log.level_procedure,
4638 p_module_prefix => l_module_prefix,
4639 p_module => l_module
4640 );
4641 END IF;
4642
4643 END build_suggestion_list;
4644
4645 -----------------------------------------------------------------------------+
4646 -- Private procedure to setup return code, records count, suggestions
4647 -- and message strings to output variables
4648 -- Created by Nishant Singhai (27-Sep-2005) (Bug # 4600030)
4649 -----------------------------------------------------------------------------+
4650 PROCEDURE setup_msg_and_ret_code_proc (p_return_code IN NUMBER,
4651 p_msg_name IN VARCHAR2 DEFAULT NULL,
4652 p_msg_token_name IN VARCHAR2 DEFAULT NULL,
4653 p_msg_token_value IN VARCHAR2 DEFAULT NULL) IS
4654
4655 l_not_validated_geo_type VARCHAR2(200);
4656 l_rec_count_flag VARCHAR2(10);
4657 ll_success_geo_level NUMBER;
4658 BEGIN
4659 -- Set output values
4660 x_records_count := geo_suggest_tbl.COUNT;
4661 x_return_code := p_return_code;
4662 x_geo_suggest_tbl := geo_suggest_tbl;
4663
4664 IF (p_msg_name IS NOT NULL) THEN
4665 -- get message string
4666 FND_MESSAGE.SET_NAME('AR', p_msg_name );
4667
4668 IF (p_msg_token_name IS NOT NULL) THEN
4669 IF (p_msg_token_value IS NULL) THEN
4670 -- validate input values and get invalid geo types back
4671 validate_input_values_proc (l_geo_struct_tbl => geo_struct_tbl,
4672 x_not_validated_geo_type => l_not_validated_geo_type,
4673 x_rec_count_flag => l_rec_count_flag,
4674 x_success_geo_level => ll_success_geo_level);
4675 ELSE -- use passed in token value in case of missing fields
4676 l_not_validated_geo_type := p_msg_token_value;
4677 END IF;
4678
4679 FND_MESSAGE.SET_TOKEN(p_msg_token_name, l_not_validated_geo_type );
4680 END IF;
4681 x_geo_suggest_misc_rec.v_suggestion_msg_text := SUBSTR(FND_MESSAGE.GET,1,1000);
4682 END IF;
4683
4684 END setup_msg_and_ret_code_proc;
4685
4686 ----------------------------------------------------------------------------+
4687 -- Private procedure to process fetched data and populate output variables
4688 -- It will do processing for 'ERROR', 'WARNING', 'MINIMUM' and 'NONE' validation
4689 -- levels. It will set return codes, record count, suggestion table, return
4690 -- messages based on validation level
4691 -- Created By : Nishant Singhai (27-Sep-2005) for Bug # 4600030
4692 ----------------------------------------------------------------------------+
4693 PROCEDURE process_output_data_proc IS
4694 l_miss_min_geo_type VARCHAR2(200);
4695 l_msg_name VARCHAR2(100);
4696 l_msg_token_name VARCHAR2(100);
4697 BEGIN
4698 -- FND Logging for debug purpose
4699 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
4700 hz_utility_v2pub.debug
4701 (p_message => 'BEGIN: process_output_data_proc(+)',
4702 p_prefix => l_debug_prefix,
4703 p_msg_level => fnd_log.level_procedure,
4704 p_module_prefix => l_module_prefix,
4705 p_module => l_module
4706 );
4707 END IF;
4708
4709 -- Build sorted suggestion List for fetching proper return codes.
4710 -- (Nishant 20-Jul-2006 for Bug 5391120)
4711 build_suggestion_list;
4712
4713 IF (l_addr_val_level = 'ERROR') THEN
4714
4715 -- FND Logging for debug purpose
4716 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4717 hz_utility_v2pub.debug
4718 (p_message => 'Validation Level : ERROR',
4719 p_prefix => l_debug_prefix,
4720 p_msg_level => fnd_log.level_statement,
4721 p_module_prefix => l_module_prefix,
4722 p_module => l_module
4723 );
4724 END IF;
4725
4726 -- If it is 2nd pass and geo validation success, then return ADDRESS_COMPLETE
4727 IF ((HZ_GNR_PVT.G_USER_ATTEMPT_COUNT IS NOT NULL) AND -- this is 2nd attempt
4728 (l_success = 'Y')) THEN
4729 -- FND Logging for debug purpose
4730 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4731 hz_utility_v2pub.debug
4732 (p_message => 'Geo Validated Address is complete, return code=0(ADDRESS_COMPLETE)',
4733 p_prefix => l_debug_prefix,
4734 p_msg_level => fnd_log.level_statement,
4735 p_module_prefix => l_module_prefix,
4736 p_module => l_module
4737 );
4738 END IF;
4739
4740 -- set return code and return message
4741 setup_msg_and_ret_code_proc(p_return_code => 0); /* ADDRESS_COMPLETE */
4742 -- reset the global variable (session) to null so that next time
4743 -- address suggestion kickes in initially
4744 HZ_GNR_PVT.G_USER_ATTEMPT_COUNT := NULL;
4745
4746 ELSE -- do further processing to verify if record is success
4747
4748 IF (geo_suggest_tbl.COUNT = 0) THEN
4749
4750 -- FND Logging for debug purpose
4751 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4752
4753 hz_utility_v2pub.debug
4754 (p_message => 'Records count is 0, return code= -1(ADDRESS_INVALID)',
4755 p_prefix => l_debug_prefix,
4756 p_msg_level => fnd_log.level_statement,
4757 p_module_prefix => l_module_prefix,
4758 p_module => l_module
4759 );
4760
4761 END IF;
4762
4763 -- set return code and return message
4764 /* -- checking if Geo validation was success, then given message that
4765 -- user can click Apply and continue (equivalent to what we given in warning scenario)
4766 -- Bug 5172103 (Nishant 11-May-2006)
4767 */
4768 IF (l_geo_validation_passed = 'Y') THEN
4769 l_msg_name := 'HZ_GEO_WARN_MIN_PASS';
4770 l_msg_token_name := 'P_ALL_ELEMENTS';
4771 ELSE
4772 l_msg_name := 'HZ_GEO_INVALID_ADDRESS';
4773 l_msg_token_name := 'P_MISSING_ELEMENTS';
4774 END IF;
4775
4776 setup_msg_and_ret_code_proc(p_return_code => -1, /* ADDRESS_INVALID */
4777 p_msg_name => l_msg_name,
4778 p_msg_token_name => l_msg_token_name);
4779
4780 -- set the global variable (session) to '1' (some value) to identify that
4781 -- next time we can directly go to geo validation i.e.
4782 HZ_GNR_PVT.G_USER_ATTEMPT_COUNT := '1';
4783
4784 ELSE -- geo_suggest_tbl count is not 0
4785
4786 -- set the global variable (session) to '1' (some value) to identify that
4787 -- next time we can directly go to geo validation i.e.
4788 HZ_GNR_PVT.G_USER_ATTEMPT_COUNT := '1';
4789
4790 IF (geo_suggest_tbl.COUNT =1) THEN
4791 -- check if all input values match all fetched values
4792 IF (do_input_output_match_check) THEN
4793
4794 -- FND Logging for debug purpose
4795 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4796 hz_utility_v2pub.debug
4797 (p_message => 'Address is complete, return code=0(ADDRESS_COMPLETE)',
4798 p_prefix => l_debug_prefix,
4799 p_msg_level => fnd_log.level_statement,
4800 p_module_prefix => l_module_prefix,
4801 p_module => l_module
4802 );
4803 END IF;
4804
4805 -- set return code and return message
4806 setup_msg_and_ret_code_proc(p_return_code => 0); /* ADDRESS_COMPLETE */
4807 -- reset the global variable (session) to null so that next time
4808 -- address suggestion kickes in initially
4809 HZ_GNR_PVT.G_USER_ATTEMPT_COUNT := NULL;
4810
4811 ELSE
4812 -- FND Logging for debug purpose
4813 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4814 hz_utility_v2pub.debug
4815 (p_message => 'input output match check failed, return code=1(ADDRESS_VALID)',
4816 p_prefix => l_debug_prefix,
4817 p_msg_level => fnd_log.level_statement,
4818 p_module_prefix => l_module_prefix,
4819 p_module => l_module
4820 );
4821 END IF;
4822
4823 -- set return code and return message
4824 /* -- checking if Geo validation was success, then given message that
4825 -- user can click Apply and continue (equivalent to what we given in warning scenario)
4826 -- Bug 5172103 (Nishant 11-May-2006)
4827 */
4828 IF (l_geo_validation_passed = 'Y') THEN
4829 l_msg_name := 'HZ_GEO_WARN_MIN_PASS';
4830 l_msg_token_name := 'P_ALL_ELEMENTS';
4831 ELSE
4832 l_msg_name := 'HZ_GEO_INVALID_ADDRESS';
4833 l_msg_token_name := 'P_MISSING_ELEMENTS';
4834 END IF;
4835
4836 setup_msg_and_ret_code_proc(p_return_code => 1, /* ADDRESS_VALID */ --2, /* ADDRESS_UNIQUE */
4837 p_msg_name => l_msg_name,
4838 p_msg_token_name => l_msg_token_name);
4839
4840 END IF; -- input output match check
4841
4842 ELSIF -- more than 55
4843 ((geo_suggest_tbl.COUNT > 1) AND (l_geo_data_count > l_max_fetch_count)) THEN
4844
4845 -- FND Logging for debug purpose
4846 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4847 hz_utility_v2pub.debug
4848 (p_message => 'more than 55 records, return code=1000(TOO_MANY_ROWS)',
4849 p_prefix => l_debug_prefix,
4850 p_msg_level => fnd_log.level_statement,
4851 p_module_prefix => l_module_prefix,
4852 p_module => l_module
4853 );
4854 END IF;
4855
4856 -- set return code and return message
4857 /* -- checking if Geo validation was success, then given message that
4858 -- user can click Apply and continue (equivalent to what we given in warning scenario)
4859 -- Bug 5172103 (Nishant 11-May-2006)
4860 */
4861 IF (l_geo_validation_passed = 'Y') THEN
4862 l_msg_name := 'HZ_GEO_WARN_MORE_TO_FETCH';
4863 l_msg_token_name := 'P_ALL_ELEMENTS';
4864 ELSE
4865 l_msg_name := 'HZ_GEO_MORE_TO_FETCH';
4866 l_msg_token_name := 'P_MISSING_ELEMENTS';
4867 END IF;
4868
4869 setup_msg_and_ret_code_proc(p_return_code => 1000, /* TOO_MANY_ROWS */
4870 p_msg_name => l_msg_name,
4871 p_msg_token_name => l_msg_token_name);
4872
4873 -- SET x_records_count TO NULL so that calling UI does not get wrong picture
4874 -- about number of records.
4875 x_records_count := NULL;
4876
4877 ELSE -- between 2 and 55
4878
4879 -- FND Logging for debug purpose
4880 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4881 hz_utility_v2pub.debug
4882 (p_message => 'No. of records between 2 and 55, return code=1(ADDRESS_VALID)',
4883 p_prefix => l_debug_prefix,
4884 p_msg_level => fnd_log.level_statement,
4885 p_module_prefix => l_module_prefix,
4886 p_module => l_module
4887 );
4888 END IF;
4889
4890 -- set return code and return message
4891 /* -- checking if Geo validation was success, then given message that
4892 -- user can click Apply and continue (equivalent to what we given in warning scenario)
4893 -- Bug 5172103 (Nishant 11-May-2006)
4894 */
4895 IF (l_geo_validation_passed = 'Y') THEN
4896 l_msg_name := 'HZ_GEO_WARN_MIN_PASS';
4897 l_msg_token_name := 'P_ALL_ELEMENTS';
4898 ELSE
4899 l_msg_name := 'HZ_GEO_INVALID_ADDRESS';
4900 l_msg_token_name := 'P_MISSING_ELEMENTS';
4901 END IF;
4902
4903 setup_msg_and_ret_code_proc(p_return_code => 1, /* ADDRESS_VALID */
4904 p_msg_name => l_msg_name,
4905 p_msg_token_name => l_msg_token_name);
4906
4907 END IF; -- geo suggest tbl count > 0
4908 END IF; -- geo suggest tbl count = 0
4909 END IF; -- 2nd attempt success check
4910 END IF; -- validation level = ERROR
4911
4912 IF (l_addr_val_level = 'WARNING') THEN
4913
4914 -- FND Logging for debug purpose
4915 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4916 hz_utility_v2pub.debug
4917 (p_message => 'Validation Level : WARNING',
4918 p_prefix => l_debug_prefix,
4919 p_msg_level => fnd_log.level_statement,
4920 p_module_prefix => l_module_prefix,
4921 p_module => l_module
4922 );
4923 END IF;
4924
4925 IF (geo_suggest_tbl.COUNT = 0) THEN
4926
4927 -- FND Logging for debug purpose
4928 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4929 hz_utility_v2pub.debug
4930 (p_message => 'No. of records 0, return code=1(ADDRESS_VALID)',
4931 p_prefix => l_debug_prefix,
4932 p_msg_level => fnd_log.level_statement,
4933 p_module_prefix => l_module_prefix,
4934 p_module => l_module
4935 );
4936 END IF;
4937
4938 -- set return code and return message
4939 setup_msg_and_ret_code_proc(p_return_code => 1, /* ADDRESS_VALID */
4940 p_msg_name => 'HZ_GEO_WARN_MIN_PASS',
4941 p_msg_token_name => 'P_ALL_ELEMENTS');
4942
4943 ELSE -- geo_suggest_tbl count is not 0
4944
4945 IF (geo_suggest_tbl.COUNT =1) THEN
4946
4947 -- check if all input values match all fetched values
4948 IF (do_input_output_match_check) THEN
4949
4950 -- FND Logging for debug purpose
4951 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4952 hz_utility_v2pub.debug
4953 (p_message => 'No. of records 1, exact match, return code=0(ADDRESS_COMPLETE)',
4954 p_prefix => l_debug_prefix,
4955 p_msg_level => fnd_log.level_statement,
4956 p_module_prefix => l_module_prefix,
4957 p_module => l_module
4958 );
4959 END IF;
4960
4961 -- set return code and return message
4962 setup_msg_and_ret_code_proc(p_return_code => 0);/* ADDRESS_COMPLETE */
4963
4964 ELSE -- input output match check failed
4965
4966 -- FND Logging for debug purpose
4967 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4968 hz_utility_v2pub.debug
4969 (p_message => 'No. of records 1, input output match check failed, '||
4970 'return code=1(ADDRESS_VALID)',
4971 p_prefix => l_debug_prefix,
4972 p_msg_level => fnd_log.level_statement,
4973 p_module_prefix => l_module_prefix,
4974 p_module => l_module
4975 );
4976 END IF;
4977
4978 -- set return code and return message
4979 setup_msg_and_ret_code_proc(p_return_code => 1, /* ADDRESS_VALID */
4980 p_msg_name => 'HZ_GEO_WARN_MIN_PASS',
4981 p_msg_token_name => 'P_ALL_ELEMENTS');
4982
4983 END IF; -- input output match check
4984
4985 ELSIF -- more than 55
4986 ((geo_suggest_tbl.COUNT > 1) AND (l_geo_data_count > l_max_fetch_count)) THEN
4987
4988 -- FND Logging for debug purpose
4989 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
4990 hz_utility_v2pub.debug
4991 (p_message => 'No. of records more than 55, '||
4992 'return code=1000(TOO_MANY_ROWS)',
4993 p_prefix => l_debug_prefix,
4994 p_msg_level => fnd_log.level_statement,
4995 p_module_prefix => l_module_prefix,
4996 p_module => l_module
4997 );
4998 END IF;
4999
5000 -- set return code and return message
5001 setup_msg_and_ret_code_proc(p_return_code => 1000, /* TOO_MANY_ROWS */
5002 p_msg_name => 'HZ_GEO_WARN_MORE_TO_FETCH',
5003 p_msg_token_name => 'P_ALL_ELEMENTS');
5004
5005 -- SET x_records_count TO NULL so that calling UI does not get wrong picture
5006 -- about number of records.
5007 x_records_count := NULL;
5008
5009 ELSE -- between 2 and 55
5010
5011 -- FND Logging for debug purpose
5012 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5013 hz_utility_v2pub.debug
5014 (p_message => 'No. of records between 2 and 55, '||
5015 'return code=1(ADDRESS_VALID)',
5016 p_prefix => l_debug_prefix,
5017 p_msg_level => fnd_log.level_statement,
5018 p_module_prefix => l_module_prefix,
5019 p_module => l_module
5020 );
5021 END IF;
5022
5023 -- set return code and return message
5024 setup_msg_and_ret_code_proc(p_return_code => 1, /* ADDRESS_VALID */
5025 p_msg_name => 'HZ_GEO_WARN_MIN_PASS',
5026 p_msg_token_name => 'P_ALL_ELEMENTS');
5027
5028 END IF; -- geo suggest tbl count > 0
5029 END IF; -- geo suggest tbl count = 0
5030 END IF; -- validation level = WARNING
5031
5032 IF (l_addr_val_level = 'MINIMUM') THEN
5033
5034 -- FND Logging for debug purpose
5035 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5036 hz_utility_v2pub.debug
5037 (p_message => 'Validation Level : MINIMUM',
5038 p_prefix => l_debug_prefix,
5039 p_msg_level => fnd_log.level_statement,
5040 p_module_prefix => l_module_prefix,
5041 p_module => l_module
5042 );
5043 END IF;
5044
5045 l_miss_min_geo_type := NULL;
5046 l_miss_min_geo_type := get_missing_input_fields (l_geo_struct_tbl => geo_struct_tbl);
5047
5048 IF (l_miss_min_geo_type IS NOT NULL) THEN -- minimum check failed
5049
5050 -- FND Logging for debug purpose
5051 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5052 hz_utility_v2pub.debug
5053 (p_message => 'Minimum check failed, '||
5054 'return code=-1(ADDRESS_INVALID)',
5055 p_prefix => l_debug_prefix,
5056 p_msg_level => fnd_log.level_statement,
5057 p_module_prefix => l_module_prefix,
5058 p_module => l_module
5059 );
5060 END IF;
5061
5062 -- set return code and return message
5063 setup_msg_and_ret_code_proc(p_return_code => -1, /* ADDRESS_INVALID */
5064 p_msg_name => 'HZ_GEO_NULL_ADDRESS',
5065 p_msg_token_name => 'P_MISSING_ELEMENTS',
5066 p_msg_token_value => l_miss_min_geo_type);
5067 ELSE -- minimum check passed
5068
5069 -- FND Logging for debug purpose
5070 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5071 hz_utility_v2pub.debug
5072 (p_message => 'Minimum check passed, '||
5073 'return code=0(ADDRESS_COMPLETE)',
5074 p_prefix => l_debug_prefix,
5075 p_msg_level => fnd_log.level_statement,
5076 p_module_prefix => l_module_prefix,
5077 p_module => l_module
5078 );
5079 END IF;
5080
5081 -- set return code and return message
5082 setup_msg_and_ret_code_proc(p_return_code => 0); /* ADDRESS_COMPLETE */
5083
5084 END IF; -- minimum check
5085 END IF; -- validation level = MINIMUM
5086
5087 IF (l_addr_val_level = 'NONE') THEN
5088 -- FND Logging for debug purpose
5089 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5090 hz_utility_v2pub.debug
5091 (p_message => 'Validation Level : NONE, return code=0(ADDRESS_COMPLETE)',
5092 p_prefix => l_debug_prefix,
5093 p_msg_level => fnd_log.level_statement,
5094 p_module_prefix => l_module_prefix,
5095 p_module => l_module
5096 );
5097 END IF;
5098
5099 -- set return code and return message
5100 setup_msg_and_ret_code_proc(p_return_code => 0); /* ADDRESS_COMPLETE */
5101 END IF; -- validation level = MINIMUM
5102
5103 -- FND Logging for debug purpose
5104 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
5105 hz_utility_v2pub.debug
5106 (p_message => 'End: process_output_data_proc(-)',
5107 p_prefix => l_debug_prefix,
5108 p_msg_level => fnd_log.level_procedure,
5109 p_module_prefix => l_module_prefix,
5110 p_module => l_module
5111 );
5112 END IF;
5113
5114 END process_output_data_proc;
5115
5116 /*---------------------------------------------------------------------------+
5117 Function is_geo_valid_in_geo_rec_tbl_f will validate if results in geo_rec_tbl
5118 (Intermediate table) meet the geo usage criteria
5119 ----------------------------------------------------------------------------*/
5120
5121 FUNCTION is_geo_valid_in_geo_rec_tbl_f (l_max_usage_element_col_value IN NUMBER)
5122 RETURN BOOLEAN IS
5123 BEGIN
5124 IF (geo_rec_tbl.COUNT > 0) THEN
5125 CASE l_max_usage_element_col_value
5126 WHEN 1 THEN
5127 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT1 IS NOT NULL) THEN RETURN TRUE ;
5128 ELSE RETURN FALSE ;
5129 END IF;
5130 WHEN 2 THEN
5131 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT2 IS NOT NULL) THEN RETURN TRUE ;
5132 ELSE RETURN FALSE ;
5133 END IF;
5134 WHEN 3 THEN
5135 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT3 IS NOT NULL) THEN RETURN TRUE ;
5136 ELSE RETURN FALSE ;
5137 END IF;
5138 WHEN 4 THEN
5139 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT4 IS NOT NULL) THEN RETURN TRUE ;
5140 ELSE RETURN FALSE ;
5141 END IF;
5142 WHEN 5 THEN
5143 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT5 IS NOT NULL) THEN RETURN TRUE ;
5144 ELSE RETURN FALSE ;
5145 END IF;
5146 WHEN 6 THEN
5147 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT6 IS NOT NULL) THEN RETURN TRUE ;
5148 ELSE RETURN FALSE ;
5149 END IF;
5150 WHEN 7 THEN
5151 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT7 IS NOT NULL) THEN RETURN TRUE ;
5152 ELSE RETURN FALSE ;
5153 END IF;
5154 WHEN 8 THEN
5155 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT8 IS NOT NULL) THEN RETURN TRUE ;
5156 ELSE RETURN FALSE ;
5157 END IF;
5158 WHEN 9 THEN
5159 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT9 IS NOT NULL) THEN RETURN TRUE ;
5160 ELSE RETURN FALSE ;
5161 END IF;
5162 WHEN 10 THEN
5163 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT10 IS NOT NULL) THEN RETURN TRUE ;
5164 ELSE RETURN FALSE ;
5165 END IF;
5166 ELSE
5167 RETURN FALSE;
5168 END CASE;
5169 ELSE
5170 RETURN FALSE;
5171 END IF;
5172 END is_geo_valid_in_geo_rec_tbl_f;
5173
5174 /*---------------------------------------------------------------------------+
5175 Function to get max column for which value is fetched
5176 ----------------------------------------------------------------------------*/
5177
5178 FUNCTION get_max_fetched_value
5179 RETURN NUMBER IS
5180 ll_max_fetched_value NUMBER;
5181 BEGIN
5182 ll_max_fetched_value := 0;
5183
5184 IF (geo_rec_tbl.COUNT > 0) THEN
5185
5186 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT1 IS NOT NULL) THEN
5187 ll_max_fetched_value := 1;
5188 END IF;
5189 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT2 IS NOT NULL) THEN
5190 ll_max_fetched_value := 2;
5191 END IF;
5192 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT3 IS NOT NULL) THEN
5193 ll_max_fetched_value := 3;
5194 END IF;
5195 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT4 IS NOT NULL) THEN
5196 ll_max_fetched_value := 4;
5197 END IF;
5198 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT5 IS NOT NULL) THEN
5199 ll_max_fetched_value := 5;
5200 END IF;
5201 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT6 IS NOT NULL) THEN
5202 ll_max_fetched_value := 6;
5203 END IF;
5204 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT7 IS NOT NULL) THEN
5205 ll_max_fetched_value := 7;
5206 END IF;
5207 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT8 IS NOT NULL) THEN
5208 ll_max_fetched_value := 8;
5209 END IF;
5210 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT9 IS NOT NULL) THEN
5211 ll_max_fetched_value := 9;
5212 END IF;
5213 IF (geo_rec_tbl(1).GEOGRAPHY_ELEMENT10 IS NOT NULL) THEN
5214 ll_max_fetched_value := 10;
5215 END IF;
5216 END IF;
5217 RETURN ll_max_fetched_value;
5218 END get_max_fetched_value;
5219
5220 -----------------------------------------------------------------------------+
5221 -- Procedure get_next_level_children_proc is to get next level children
5222 -- record for data already avaliable in intermediate
5223 -- table geo_rec_tbl. Once child records are fetched, move fetched data and
5224 -- geo_rec_tbl data to final table geo_suggest_tbl.
5225 -----------------------------------------------------------------------------+
5226 PROCEDURE get_next_level_children_proc IS
5227 l_structure_level_count NUMBER;
5228 l_insert_geo_valid_rec_final VARCHAR2(1);
5229 l_insert_geo_suggest_rec VARCHAR2(1);
5230 l_max_fetched_value NUMBER;
5231
5232 l_child_map_count NUMBER;
5233 l_select_child VARCHAR2(2000);
5234 l_from_child VARCHAR2(2000);
5235 l_where_child VARCHAR2(4000);
5236 l_sql_stmt_child VARCHAR2(10000);
5237 l_last_index_child NUMBER;
5238 l_total_null_cols_child NUMBER;
5239
5240 TYPE child_cur_type IS REF CURSOR;
5241 child_cursor child_cur_type;
5242 child_rec rec_type_mp;
5243
5244 BEGIN
5245
5246 l_child_map_count := 0;
5247 IF (geo_struct_tbl.COUNT > 1) THEN
5248
5249 -- FND Logging for debug purpose
5250 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5251 hz_utility_v2pub.debug
5252 (p_message => 'Trying to fetch children for complete next level...',
5253 p_prefix => l_debug_prefix,
5254 p_msg_level => fnd_log.level_statement,
5255 p_module_prefix => l_module_prefix,
5256 p_module => l_module
5257 );
5258 END IF;
5259
5260 -- get max column for which value is fetched
5261 l_max_fetched_value := get_max_fetched_value;
5262 -- ns_debug.put_line('MAX FETCH VALUE :'||l_max_fetched_value);
5263
5264 -- FND Logging for debug purpose
5265 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5266 hz_utility_v2pub.debug
5267 (p_message => 'l_max_fetched_value:'||l_max_fetched_value
5268 ||' l_max_mapped_element_col_value:'||l_max_mapped_element_col_value,
5269 p_prefix => l_debug_prefix,
5270 p_msg_level => fnd_log.level_statement,
5271 p_module_prefix => l_module_prefix,
5272 p_module => l_module
5273 );
5274 END IF;
5275
5276 -- does not have to execute child query if l_max_fetched_value = max mapped value
5277 -- i.e. there is no more child level
5278 IF (l_max_fetched_value < l_max_mapped_element_col_value) THEN
5279
5280 -- FND Logging for debug purpose
5281 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5282 hz_utility_v2pub.debug
5283 (p_message => 'Trying to get child data...',
5284 p_prefix => l_debug_prefix,
5285 p_msg_level => fnd_log.level_statement,
5286 p_module_prefix => l_module_prefix,
5287 p_module => l_module
5288 );
5289 END IF;
5290
5291 -- build the sql stmt for child records
5292 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
5293 IF TO_NUMBER(SUBSTR(geo_struct_tbl(i).v_element_col,18)) = (l_max_fetched_value+1) THEN
5294 l_child_map_count := l_child_map_count+1;
5295
5296 IF (l_child_map_count = 1) THEN
5297 l_select_child := 'SELECT distinct p1.geography_id , p1.geography_name ,'
5298 ||'p1.geography_code , p1.geography_type ';
5299 l_from_child := ' FROM hz_hierarchy_nodes hn1'
5300 ||', hz_geographies p1 ';
5301 l_where_child := ' WHERE hn1.parent_id = :x_parent_geo_id '
5302 ||' AND hn1.HIERARCHY_TYPE = ''MASTER_REF'' '
5303 ||' AND hn1.level_number = 1 '
5304 ||' AND hn1.CHILD_TABLE_NAME = ''HZ_GEOGRAPHIES'' '
5305 ||' AND SYSDATE BETWEEN hn1.effective_start_date AND hn1.effective_end_date '
5306 ||' AND NVL(hn1.status,''A'') = ''A'' '
5307 ||' AND hn1.PARENT_TABLE_NAME = ''HZ_GEOGRAPHIES'' '
5308 ||' AND hn1.child_id = p1.geography_id '
5309 ||' AND p1.GEOGRAPHY_USE = ''MASTER_REF'' '
5310 ||' AND SYSDATE BETWEEN p1.start_date AND p1.end_date ';
5311 l_last_index_child := 1;
5312 ELSE
5313 l_select_child := l_select_child ||',p'||l_child_map_count||'.geography_id , p'||l_child_map_count||'.geography_name '
5314 ||',p'||l_child_map_count||'.geography_code, p'||l_child_map_count||'.geography_type ';
5315
5316 l_from_child := l_from_child ||', hz_hierarchy_nodes hn'||l_child_map_count
5317 ||', hz_geographies p'||l_child_map_count ;
5318
5319 l_where_child := l_where_child ||' AND hn'||l_child_map_count||'.parent_id = hn'||l_last_index_child||'.child_id '
5320 ||' AND hn'||l_child_map_count||'.HIERARCHY_TYPE = ''MASTER_REF'' '
5321 ||' AND hn'||l_child_map_count||'.level_number = 1 '
5322 ||' AND hn'||l_child_map_count||'.CHILD_TABLE_NAME = ''HZ_GEOGRAPHIES'' '
5323 ||' AND SYSDATE BETWEEN hn'||l_child_map_count||'.effective_start_date AND hn'||l_child_map_count||'.effective_end_date '
5324 ||' AND NVL(hn'||l_child_map_count||'.status,''A'') = ''A'' '
5325 ||' AND hn'||l_child_map_count||'.PARENT_TABLE_NAME = ''HZ_GEOGRAPHIES'' '
5326 ||' AND hn'||l_child_map_count||'.child_id = p'||l_child_map_count||'.geography_id '
5327 ||' AND p'||l_child_map_count||'.GEOGRAPHY_USE = ''MASTER_REF'' '
5328 ||' AND SYSDATE BETWEEN p'||l_child_map_count||'.start_date AND p'||l_child_map_count||'.end_date ';
5329 l_last_index_child := l_child_map_count;
5330 END IF;
5331 END IF;
5332 END LOOP;
5333
5334 -- pad rest of the columns in select stmt (to be fetched in child_rec record) to null
5335 -- for example, if geo_struct_tbl contains 3 mapping rows, then other 7 elements (since total is 10),
5336 -- have to be made NULL in select statement
5337 l_total_null_cols_child := (10-(l_child_map_count))*4;
5338
5339 IF (l_total_null_cols_child > 0) THEN
5340 FOR i IN 1..l_total_null_cols_child LOOP
5341 l_select_child := l_select_child ||', NULL ';
5342 END LOOP;
5343 END IF;
5344
5345 l_sql_stmt_child := l_select_child||l_from_child||l_where_child;
5346
5347 -- FND Logging for debug purpose
5348 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5349 hz_utility_v2pub.debug
5350 (p_message => 'Total NULL columns appended in fetch child query :'||l_total_null_cols_child,
5351 p_prefix => l_debug_prefix,
5352 p_msg_level => fnd_log.level_statement,
5353 p_module_prefix => l_module_prefix,
5354 p_module => l_module
5355 );
5356 END IF;
5357
5358 -- FND Logging for debug purpose
5359 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5360 hz_utility_v2pub.debug
5361 (p_message => 'Child Query :'||l_sql_stmt_child,
5362 p_prefix => l_debug_prefix,
5363 p_msg_level => fnd_log.level_statement,
5364 p_module_prefix => l_module_prefix,
5365 p_module => l_module
5366 );
5367 END IF;
5368
5369 --ns_debug.put_line(' Child Query ');
5370 --ns_debug.put_line(' ======================');
5371 --ns_debug.put_line(l_sql_stmt_child);
5372 --ns_debug.put_line(' ======================');
5373
5374 -- for each record in geo_rec_tbl execute this query
5375 -- (Only if sql stmt has been built properly) (Bug 5157824 : Nishant 17-APR-2006)
5376 IF ((geo_rec_tbl.COUNT > 0) AND
5377 (l_total_null_cols_child < 40)) THEN -- (Bug 5157824 (if less than 40, it means sql has been built))
5378 FOR j IN geo_rec_tbl.FIRST..geo_rec_tbl.LAST LOOP
5379 -- execute the query
5380 -- ns_debug.put_line('Parent Geo id:'||geo_rec_tbl(j).geography_id);
5381
5382 OPEN child_cursor FOR l_sql_stmt_child USING geo_rec_tbl(j).geography_id;
5383 LOOP
5384 FETCH child_cursor INTO child_rec;
5385 EXIT WHEN child_cursor%NOTFOUND;
5386 -- l_geo_data_count is counter for row. It is same the one used
5387 -- in main query
5388 l_geo_data_count := geo_suggest_tbl.COUNT+1;
5389 EXIT WHEN l_geo_data_count > l_max_fetch_count; -- no. of records retrieved
5390
5391 -- move existing data from geo_rec_tbl to geo_suggest_tbl
5392 move_from_geo_rec_to_suggest(j,l_geo_data_count);
5393
5394 -- retrieve data for child records
5395 -----------------------------------------------------------------+
5396 -- GEO_ID_1
5397 -----------------------------------------------------------------+
5398 -- assignments to suggest table
5399 IF (child_rec.geo_id_1 IS NOT NULL) THEN
5400 l_geo_rec_tab_col := get_tab_col_from_geo_type(child_rec.geo_type_1);
5401
5402 IF (l_geo_rec_tab_col IS NOT NULL) THEN
5403 l_geo_rec_geo_name := child_rec.geo_name_1;
5404 l_geo_rec_geo_id := child_rec.geo_id_1;
5405 l_geo_rec_geo_code := child_rec.geo_code_1;
5406
5407 IF (l_geo_rec_geo_name IS NOT NULL) THEN
5408 insert_in_geo_suggest_tbl(l_geo_data_count,
5409 l_geo_rec_tab_col,
5410 l_geo_rec_geo_name,
5411 l_geo_rec_geo_id,
5412 l_geo_rec_geo_code
5413 );
5414 END IF;
5415 END IF;
5416 END IF;
5417 -----------------------------------------------------------------+
5418 -- GEO_ID_2
5419 -----------------------------------------------------------------+
5420 -- assignments to suggest table
5421 IF (child_rec.geo_id_2 IS NOT NULL) THEN
5422 l_geo_rec_tab_col := get_tab_col_from_geo_type(child_rec.geo_type_2);
5423
5424 IF (l_geo_rec_tab_col IS NOT NULL) THEN
5425 l_geo_rec_geo_name := child_rec.geo_name_2;
5426 l_geo_rec_geo_id := child_rec.geo_id_2;
5427 l_geo_rec_geo_code := child_rec.geo_code_2;
5428
5429 IF (l_geo_rec_geo_name IS NOT NULL) THEN
5430 insert_in_geo_suggest_tbl(l_geo_data_count,
5431 l_geo_rec_tab_col,
5432 l_geo_rec_geo_name,
5433 l_geo_rec_geo_id,
5434 l_geo_rec_geo_code
5435 );
5436 END IF;
5437 END IF;
5438 END IF;
5439
5440 -----------------------------------------------------------------+
5441 -- GEO_ID_3
5442 -----------------------------------------------------------------+
5443 -- assignments to suggest table
5444 IF (child_rec.geo_id_3 IS NOT NULL) THEN
5445 l_geo_rec_tab_col := get_tab_col_from_geo_type(child_rec.geo_type_3);
5446
5447 IF (l_geo_rec_tab_col IS NOT NULL) THEN
5448 l_geo_rec_geo_name := child_rec.geo_name_3;
5449 l_geo_rec_geo_id := child_rec.geo_id_3;
5450 l_geo_rec_geo_code := child_rec.geo_code_3;
5451
5452 IF (l_geo_rec_geo_name IS NOT NULL) THEN
5453 insert_in_geo_suggest_tbl(l_geo_data_count,
5454 l_geo_rec_tab_col,
5455 l_geo_rec_geo_name,
5456 l_geo_rec_geo_id,
5457 l_geo_rec_geo_code
5458 );
5459 END IF;
5460 END IF;
5461 END IF;
5462
5463 -----------------------------------------------------------------+
5464 -- GEO_ID_4
5465 -----------------------------------------------------------------+
5466 -- assignments to suggest table
5467 IF (child_rec.geo_id_4 IS NOT NULL) THEN
5468 l_geo_rec_tab_col := get_tab_col_from_geo_type(child_rec.geo_type_4);
5469
5470 IF (l_geo_rec_tab_col IS NOT NULL) THEN
5471 l_geo_rec_geo_name := child_rec.geo_name_4;
5472 l_geo_rec_geo_id := child_rec.geo_id_4;
5473 l_geo_rec_geo_code := child_rec.geo_code_4;
5474
5475 IF (l_geo_rec_geo_name IS NOT NULL) THEN
5476 insert_in_geo_suggest_tbl(l_geo_data_count,
5477 l_geo_rec_tab_col,
5478 l_geo_rec_geo_name,
5479 l_geo_rec_geo_id,
5480 l_geo_rec_geo_code
5481 );
5482 END IF;
5483 END IF;
5484 END IF;
5485
5486 -----------------------------------------------------------------+
5487 -- GEO_ID_5
5488 -----------------------------------------------------------------+
5489 -- assignments to suggest table
5490 IF (child_rec.geo_id_5 IS NOT NULL) THEN
5491 l_geo_rec_tab_col := get_tab_col_from_geo_type(child_rec.geo_type_5);
5492
5493 IF (l_geo_rec_tab_col IS NOT NULL) THEN
5494 l_geo_rec_geo_name := child_rec.geo_name_5;
5495 l_geo_rec_geo_id := child_rec.geo_id_5;
5496 l_geo_rec_geo_code := child_rec.geo_code_5;
5497
5498 IF (l_geo_rec_geo_name IS NOT NULL) THEN
5499 insert_in_geo_suggest_tbl(l_geo_data_count,
5500 l_geo_rec_tab_col,
5501 l_geo_rec_geo_name,
5502 l_geo_rec_geo_id,
5503 l_geo_rec_geo_code
5504 );
5505 END IF;
5506 END IF;
5507 END IF;
5508
5509 -----------------------------------------------------------------+
5510 -- GEO_ID_6
5511 -----------------------------------------------------------------+
5512 -- assignments to suggest table
5513 IF (child_rec.geo_id_6 IS NOT NULL) THEN
5514 l_geo_rec_tab_col := get_tab_col_from_geo_type(child_rec.geo_type_6);
5515
5516 IF (l_geo_rec_tab_col IS NOT NULL) THEN
5517 l_geo_rec_geo_name := child_rec.geo_name_6;
5518 l_geo_rec_geo_id := child_rec.geo_id_6;
5519 l_geo_rec_geo_code := child_rec.geo_code_6;
5520
5521 IF (l_geo_rec_geo_name IS NOT NULL) THEN
5522 insert_in_geo_suggest_tbl(l_geo_data_count,
5523 l_geo_rec_tab_col,
5524 l_geo_rec_geo_name,
5525 l_geo_rec_geo_id,
5526 l_geo_rec_geo_code
5527 );
5528 END IF;
5529 END IF;
5530 END IF;
5531
5532 -----------------------------------------------------------------+
5533 -- GEO_ID_7
5534 -----------------------------------------------------------------+
5535 -- assignments to suggest table
5536 IF (child_rec.geo_id_7 IS NOT NULL) THEN
5537 l_geo_rec_tab_col := get_tab_col_from_geo_type(child_rec.geo_type_7);
5538
5539 IF (l_geo_rec_tab_col IS NOT NULL) THEN
5540 l_geo_rec_geo_name := child_rec.geo_name_7;
5541 l_geo_rec_geo_id := child_rec.geo_id_7;
5542 l_geo_rec_geo_code := child_rec.geo_code_7;
5543
5544 IF (l_geo_rec_geo_name IS NOT NULL) THEN
5545 insert_in_geo_suggest_tbl(l_geo_data_count,
5546 l_geo_rec_tab_col,
5547 l_geo_rec_geo_name,
5548 l_geo_rec_geo_id,
5549 l_geo_rec_geo_code
5550 );
5551 END IF;
5552 END IF;
5553 END IF;
5554
5555 -----------------------------------------------------------------+
5556 -- GEO_ID_8
5557 -----------------------------------------------------------------+
5558 -- assignments to suggest table
5559 IF (child_rec.geo_id_8 IS NOT NULL) THEN
5560 l_geo_rec_tab_col := get_tab_col_from_geo_type(child_rec.geo_type_8);
5561
5562 IF (l_geo_rec_tab_col IS NOT NULL) THEN
5563 l_geo_rec_geo_name := child_rec.geo_name_8;
5564 l_geo_rec_geo_id := child_rec.geo_id_8;
5565 l_geo_rec_geo_code := child_rec.geo_code_8;
5566
5567 IF (l_geo_rec_geo_name IS NOT NULL) THEN
5568 insert_in_geo_suggest_tbl(l_geo_data_count,
5569 l_geo_rec_tab_col,
5570 l_geo_rec_geo_name,
5571 l_geo_rec_geo_id,
5572 l_geo_rec_geo_code
5573 );
5574 END IF;
5575 END IF;
5576 END IF;
5577
5578 -----------------------------------------------------------------+
5579 -- GEO_ID_9
5580 -----------------------------------------------------------------+
5581 -- assignments to suggest table
5582 IF (child_rec.geo_id_9 IS NOT NULL) THEN
5583 l_geo_rec_tab_col := get_tab_col_from_geo_type(child_rec.geo_type_9);
5584
5585 IF (l_geo_rec_tab_col IS NOT NULL) THEN
5586 l_geo_rec_geo_name := child_rec.geo_name_9;
5587 l_geo_rec_geo_id := child_rec.geo_id_9;
5588 l_geo_rec_geo_code := child_rec.geo_code_9;
5589
5590 IF (l_geo_rec_geo_name IS NOT NULL) THEN
5591 insert_in_geo_suggest_tbl(l_geo_data_count,
5592 l_geo_rec_tab_col,
5593 l_geo_rec_geo_name,
5594 l_geo_rec_geo_id,
5595 l_geo_rec_geo_code
5596 );
5597 END IF;
5598 END IF;
5599 END IF;
5600
5601 -----------------------------------------------------------------+
5602 -- GEO_ID_10
5603 -----------------------------------------------------------------+
5604 -- assignments to suggest table
5605 IF (child_rec.geo_id_10 IS NOT NULL) THEN
5606 l_geo_rec_tab_col := get_tab_col_from_geo_type(child_rec.geo_type_10);
5607
5608 IF (l_geo_rec_tab_col IS NOT NULL) THEN
5609 l_geo_rec_geo_name := child_rec.geo_name_10;
5610 l_geo_rec_geo_id := child_rec.geo_id_10;
5611 l_geo_rec_geo_code := child_rec.geo_code_10;
5612
5613 IF (l_geo_rec_geo_name IS NOT NULL) THEN
5614 insert_in_geo_suggest_tbl(l_geo_data_count,
5615 l_geo_rec_tab_col,
5616 l_geo_rec_geo_name,
5617 l_geo_rec_geo_id,
5618 l_geo_rec_geo_code
5619 );
5620 END IF;
5621 END IF;
5622 END IF;
5623
5624 -----------------------------------
5625 -- ns_debug.put_line('Child data');
5626 -- ns_debug.put_line('====================');
5627 -- ns_debug.put_line(l_geo_data_count||':1:'||child_rec.geo_name_1||':'||child_rec.geo_code_1
5628 /* ||':2:'||child_rec.geo_name_2||':'||child_rec.geo_code_2
5629 ||':3:'||child_rec.geo_name_3||':'||child_rec.geo_code_3
5630 ||':4:'||child_rec.geo_name_4||':'||child_rec.geo_code_4
5631 ||':5:'||child_rec.geo_name_5||':'||child_rec.geo_code_5
5632 ||':6:'||child_rec.geo_name_6||':'||child_rec.geo_code_6
5633 ||':7:'||child_rec.geo_name_7||':'||child_rec.geo_code_7
5634 ||':8:'||child_rec.geo_name_8||':'||child_rec.geo_code_8
5635 ||':9:'||child_rec.geo_name_9||':'||child_rec.geo_code_9
5636 ||':10:'||child_rec.geo_name_10||':'||child_rec.geo_code_10);
5637 */
5638 -----------------------------------
5639
5640 END LOOP; -- end of loop for child cursor
5641 CLOSE child_cursor;
5642 END LOOP; -- end of loop for geo_rec_tbl
5643 END IF; -- geo rec tbl count > 0 check
5644 END IF; -- max fetched value < max mapped value check
5645 END IF; -- geo struct tbl count > 0 check
5646
5647 END get_next_level_children_proc;
5648
5649 ---------------------------------------------------------------------+
5650 -- Main code for Search_geographies procedure
5651 ---------------------------------------------------------------------+
5652 BEGIN
5653
5654 -- FND Logging for debug purpose
5655 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5656 hz_utility_v2pub.debug
5657 (p_message => 'BEGIN: Address Suggestion API',
5658 p_prefix => l_debug_prefix,
5659 p_msg_level => fnd_log.level_statement,
5660 p_module_prefix => l_module_prefix,
5661 p_module => l_module
5662 );
5663 END IF;
5664
5665 -- initialize the parameters
5666 x_records_count := 0;
5667 x_return_status := FND_API.G_RET_STS_SUCCESS ;
5668 l_success := 'N';
5669 l_geo_validation_passed := 'N';
5670
5671 -- Maximum number of rows fetched from suggestion API. If more than this
5672 -- number, return code will be set to 1000 and x_records_count will be set to
5673 -- NULL value.
5674 -- Setting it to 55 because no. of US states is 51 and we do not want to get
5675 -- too many rows everytime user queries for Country 'US'. As per PM suggestion,
5676 -- putting it to 55.
5677 l_max_fetch_count := 55;
5678
5679 -- Hard coding this usage because it is used for MINIMUM address validation level
5680 -- check. Address validation level is only for GEOGRAPHY usage. This means p_address_usage
5681 -- parameter is not being used anywhere in the code. For future enhancements,
5682 -- we are exposing this parameter. (This is based on TDD review on 27 July 2005).
5683 -- l_address_usage := p_address_usage;
5684 l_address_usage := 'GEOGRAPHY';
5685
5686 -- FND Logging for debug purpose
5687 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
5688 hz_utility_v2pub.debug
5689 (p_message => 'Get mapping details. Call build_geo_struct_tbl_pvt(+)',
5690 p_prefix => l_debug_prefix,
5691 p_msg_level => fnd_log.level_procedure,
5692 p_module_prefix => l_module_prefix,
5693 p_module => l_module
5694 );
5695 END IF;
5696
5697 -- get full mapped structure for specific address_style and
5698 -- store it in plsql table
5699 build_geo_struct_tbl_pvt(p_country_code, p_address_style, p_table_name, l_address_usage);
5700
5701 -- FND Logging for debug purpose
5702 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
5703 hz_utility_v2pub.debug
5704 (p_message => 'Finished calling build_geo_struct_tbl_pvt(-)',
5705 p_prefix => l_debug_prefix,
5706 p_msg_level => fnd_log.level_procedure,
5707 p_module_prefix => l_module_prefix,
5708 p_module => l_module
5709 );
5710 END IF;
5711
5712 -- get address validation level, if it is null i.e. not set at any level
5713 -- (which ideally should not happen), then we will assume it to be no validation,
5714 -- since we can not error out records for that country.
5715 l_addr_val_level := NVL(hz_gnr_pub.get_addr_val_level(UPPER(p_country_code)),'NONE');
5716 --l_addr_val_level := 'ERROR';
5717 x_validation_level := l_addr_val_level;
5718
5719 -- FND Logging for debug purpose
5720 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5721 hz_utility_v2pub.debug
5722 (p_message => 'Validation Level:'||l_addr_val_level,
5723 p_prefix => l_debug_prefix,
5724 p_msg_level => fnd_log.level_statement,
5725 p_module_prefix => l_module_prefix,
5726 p_module => l_module
5727 );
5728 END IF;
5729
5730 -- ns_debug.put_line('Address Validation Level:'||l_addr_val_level);
5731 -- ns_debug.put_line('Address Validation Level API value:'||hz_gnr_pub.get_addr_val_level(p_country_code));
5732
5733 /*-----------BEGIN GEO Validation and 2nd PASS TEST-----------------------------------------+
5734 Put logic of 1st pass or 2nd pass so, that if it is 2nd pass and
5735 validation level is ERROR and all fields required for geo validation are
5736 passed, call geo validation api to check if geo usage is success. If
5737 success, return success else go in suggestion logic of deriving helpful
5738 suggestions for user
5739
5740 NOTE: In case of WARNING, we are not setting global varibale
5741 HZ_GNR_PVT.G_USER_ATTEMPT_COUNT because CPUI bypasses suggestion API if
5742 user decides to save the record without changing any value in any field.
5743 In that case, there will not be any 2nd attempt. When user changes anything
5744 in any field, the cpui treats it as field modification and will again
5745 call address suggestion. For address suggestion, it is similar to 1st attempt
5746 So, do the suggestion check to suggest values if any.
5747 ------------------------------------------------------------------------+*/
5748
5749 IF (l_addr_val_level = 'ERROR') THEN
5750
5751 -- FND Logging for debug purpose
5752 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5753 hz_utility_v2pub.debug
5754 (p_message => 'Performing Geo Validation to see if it will pass or fail later with current data (+)',
5755 p_prefix => l_debug_prefix,
5756 p_msg_level => fnd_log.level_statement,
5757 p_module_prefix => l_module_prefix,
5758 p_module => l_module
5759 );
5760 END IF;
5761
5762 -- do the geo validation (from backend api)
5763 BEGIN
5764 HZ_GNR_PKG.validateLoc(
5765 P_LOCATION_ID => NULL,
5766 P_USAGE_CODE => 'GEOGRAPHY',
5767 P_ADDRESS_STYLE => P_ADDRESS_STYLE,
5768 P_COUNTRY => P_COUNTRY_CODE,
5769 P_STATE => P_STATE,
5770 P_PROVINCE => P_PROVINCE,
5771 P_COUNTY => P_COUNTY,
5772 P_CITY => P_CITY,
5773 P_POSTAL_CODE => P_POSTAL_CODE,
5774 P_POSTAL_PLUS4_CODE => P_POSTAL_PLUS4_CODE,
5775 P_ATTRIBUTE1 => P_ATTRIBUTE1,
5776 P_ATTRIBUTE2 => P_ATTRIBUTE2,
5777 P_ATTRIBUTE3 => P_ATTRIBUTE3,
5778 P_ATTRIBUTE4 => P_ATTRIBUTE4,
5779 P_ATTRIBUTE5 => P_ATTRIBUTE5,
5780 P_ATTRIBUTE6 => P_ATTRIBUTE6,
5781 P_ATTRIBUTE7 => P_ATTRIBUTE7,
5782 P_ATTRIBUTE8 => P_ATTRIBUTE8,
5783 P_ATTRIBUTE9 => P_ATTRIBUTE9,
5784 P_ATTRIBUTE10 => P_ATTRIBUTE10,
5785 P_CALLED_FROM => 'VALIDATE',
5786 P_LOCK_FLAG => FND_API.G_TRUE,
5787 X_ADDR_VAL_LEVEL => LX_ADDR_VAL_LEVEL,
5788 X_ADDR_WARN_MSG => LX_ADDR_WARN_MSG,
5789 X_ADDR_VAL_STATUS => LX_ADDR_VAL_STATUS,
5790 X_STATUS => LX_STATUS)
5791 ;
5792
5793 IF (LX_STATUS <> FND_API.G_RET_STS_SUCCESS) THEN
5794 l_success := 'N';
5795
5796 -- FND Logging for debug purpose
5797 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5798 hz_utility_v2pub.debug
5799 (p_message => 'Geo Validation Failed. Perform suggestion logic.',
5800 p_prefix => l_debug_prefix,
5801 p_msg_level => fnd_log.level_statement,
5802 p_module_prefix => l_module_prefix,
5803 p_module => l_module
5804 );
5805 END IF;
5806
5807 ELSE
5808 -- check if it is 1st attempt for ERROR condition.
5809 IF (HZ_GNR_PVT.G_USER_ATTEMPT_COUNT IS NULL) THEN
5810 l_success := 'N'; -- so that we can suggest more if there is anything during 1st attempt
5811 l_geo_validation_passed := 'Y'; -- This will be used while setting message for validation level ERROR
5812
5813 -- FND Logging for debug purpose
5814 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5815 hz_utility_v2pub.debug
5816 (p_message => 'Even though Geo Validation Passed, it was users 1st attempt, so continue with suggestion..',
5817 p_prefix => l_debug_prefix,
5818 p_msg_level => fnd_log.level_statement,
5819 p_module_prefix => l_module_prefix,
5820 p_module => l_module
5821 );
5822 END IF;
5823
5824 ELSE
5825 l_success := 'Y';
5826
5827 -- FND Logging for debug purpose
5828 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5829 hz_utility_v2pub.debug
5830 (p_message => 'Geo Validation Successful. No need for suggestion.',
5831 p_prefix => l_debug_prefix,
5832 p_msg_level => fnd_log.level_statement,
5833 p_module_prefix => l_module_prefix,
5834 p_module => l_module
5835 );
5836 END IF;
5837
5838 END IF; -- end of 1st attempt check for geo validation
5839
5840 END IF; -- end of success check for geo validation
5841
5842 -- if any exception happens in Geo Validation API, continue with suggestion logic.
5843 EXCEPTION WHEN OTHERS THEN
5844 l_success := 'N';
5845
5846 -- FND Logging for debug purpose
5847 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5848 hz_utility_v2pub.debug
5849 (p_message => 'Exception happend in Geo Validation API. Perform suggestion logic. '||SQLERRM,
5850 p_prefix => l_debug_prefix,
5851 p_msg_level => fnd_log.level_statement,
5852 p_module_prefix => l_module_prefix,
5853 p_module => l_module
5854 );
5855 END IF;
5856
5857 END;
5858
5859 --ns_debug.put_line('Geo Validation X_STATUS :'||LX_STATUS);
5860 --ns_debug.put_line('Geo Validation X_ADDR_VAL_STATUS :'||LX_ADDR_VAL_STATUS);
5861 ELSE
5862 --ns_debug.put_line('Second Pass Test Failed...');
5863
5864 -- FND Logging for debug purpose
5865 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5866 hz_utility_v2pub.debug
5867 (p_message => 'Validation level is not ERROR...Did not go into Geo Validation check..',
5868 p_prefix => l_debug_prefix,
5869 p_msg_level => fnd_log.level_statement,
5870 p_module_prefix => l_module_prefix,
5871 p_module => l_module
5872 );
5873 END IF;
5874
5875 END IF;
5876 ------------END OF GEO Validation and 2nd PASS TEST------------------------------------------+
5877
5878 -- get into address suggestion mode only if geo validation (2nd pass) did not
5879 -- succeed.
5880 IF (l_addr_val_level IN ('ERROR','WARNING') AND (l_success = 'N')) THEN
5881
5882 -- FND Logging for debug purpose
5883 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
5884 hz_utility_v2pub.debug
5885 (p_message => 'Mapped Elements Table Count:'||NVL(geo_struct_tbl.COUNT,0),
5886 p_prefix => l_debug_prefix,
5887 p_msg_level => fnd_log.level_statement,
5888 p_module_prefix => l_module_prefix,
5889 p_module => l_module
5890 );
5891 END IF;
5892
5893 -- Do main processing only if mapping is found
5894 IF (NVL(geo_struct_tbl.COUNT,0) > 0) THEN
5895
5896 -- Delete bind tables that are used for search1,2,and3
5897 bind_table_1.DELETE;
5898 bind_table_2.DELETE;
5899
5900 IF (p_country_code IS NOT NULL) THEN
5901 bind_table_1(bind_table_1.COUNT+1).bind_value := UPPER(p_country_code);
5902 -- for bind_table_2 bind country code at the time of building where clause
5903 END IF;
5904
5905 -- initialize previous valid index to 0
5906 l_priv_valid_index := 0;
5907 l_priv_valid_index_6 := 0;
5908 l_priv_valid_index_7 := 0;
5909
5910 -- build the dynamic SQL (Search 1) for fetching data
5911 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
5912 CASE geo_struct_tbl(i).v_tab_col
5913 WHEN 'COUNTRY' THEN
5914 create_where_1_clause_pvt(i, geo_struct_tbl(i).v_param_value, 'CODE');
5915 ELSE create_where_1_clause_pvt(i, geo_struct_tbl(i).v_param_value, 'BOTH');
5916 END CASE;
5917 END LOOP;
5918
5919 --------------BEGIN Search ---------------------------------------+
5920
5921 -- we delete the results table before starting any new search routine
5922 geo_suggest_tbl.DELETE;
5923 geo_rec_tbl.DELETE;
5924
5925 -------------------------------------------------------------------+
5926 -- SEARCH 1: Here we query for all passed parameters for which mapping
5927 -- exist in mapping table.
5928 -------------------------------------------------------------------+
5929 -- FND Logging for debug purpose
5930 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
5931 hz_utility_v2pub.debug
5932 (p_message => 'Begin search 1 for ALL_PASSED_PARAM_SEARCH (+)',
5933 p_prefix => l_debug_prefix,
5934 p_msg_level => fnd_log.level_procedure,
5935 p_module_prefix => l_module_prefix,
5936 p_module => l_module
5937 );
5938 END IF;
5939
5940 l_search_type := 'ALL_PASSED_PARAM_SEARCH';
5941 search_routine_pvt (pt_search_type => l_search_type,
5942 pt_bind_table => bind_table_1);
5943
5944 -- FND Logging for debug purpose
5945 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
5946 hz_utility_v2pub.debug
5947 (p_message => 'End of search 1 for ALL_PASSED_PARAM_SEARCH (-)',
5948 p_prefix => l_debug_prefix,
5949 p_msg_level => fnd_log.level_procedure,
5950 p_module_prefix => l_module_prefix,
5951 p_module => l_module
5952 );
5953 END IF;
5954
5955 -----------------END of SEARCH 1-----------------------------------+
5956
5957 /*--------------------------------------------------------------+
5958 LOGIC TO DO FURTHER SEARCH
5959 1. If 1 row is identified,
5960 1.1 Suggest 1 level down children.
5961 2. If >1 row identified, show suggestions
5962 3. If 0 row
5963 3.1 Break the input in following parameters
5964 (Level 1 + Level n) (Country + Zip) (Suggest till Level n)
5965 UNION
5966 (Level 1 + Level (n-1) (Country + City) (Suggest till Level n-1)
5967 4. If still 0 rows
5968 4.1 Start querying combinations from top node (starting with US), to get
5969 validity of input parameters
5970 4.2 This query continue till the point we cannot identify any further record.
5971 4.3 Then for uniquely identified record, get child records.
5972 ----------------------------------------------------------------*/
5973
5974 ------------------------------------------------
5975 -- 1. If 1 row is identified,
5976 IF (geo_rec_tbl.COUNT = 1) THEN
5977 -- 1.1 Check if fetched row satisfies geo validation criteria.
5978 -- 1.1.1. If Yes, No further processing required. Success.
5979 -- comment out this logic of checking if this unique row satisfies geo validation req.
5980 -- uncomment it if later required.
5981 -- If 1 row found, always show child rec, if available.
5982 -- IF (is_geo_valid_in_geo_rec_tbl_f(l_max_usage_element_col_value)) THEN --
5983 -- NULL;
5984 -- ELSE
5985 -- 1.1.2. If No, Suggest 1 level down children.
5986 -- This will put data in geo_suggest_tbl also
5987
5988 -- FND Logging for debug purpose
5989 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
5990 hz_utility_v2pub.debug
5991 (p_message => '1 Rec found in ALL_PASSED_PARAM_SEARCH. Performing child search (+)',
5992 p_prefix => l_debug_prefix,
5993 p_msg_level => fnd_log.level_procedure,
5994 p_module_prefix => l_module_prefix,
5995 p_module => l_module
5996 );
5997 END IF;
5998
5999 get_next_level_children_proc;
6000
6001 -- FND Logging for debug purpose
6002 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
6003 hz_utility_v2pub.debug
6004 (p_message => 'Child search for ALL_PASSED_PARAM_SEARCH completed (-)',
6005 p_prefix => l_debug_prefix,
6006 p_msg_level => fnd_log.level_procedure,
6007 p_module_prefix => l_module_prefix,
6008 p_module => l_module
6009 );
6010 END IF;
6011
6012
6013 -- END IF;
6014 END IF;
6015 ------------------------------------------------+
6016
6017 -------------------------------------------------------------------+
6018 -- SEARCH 2
6019 -- if still no record is found, then if min 4 level value is passed
6020 -- then do combination for 1+4 union 1+5 levels (for example)
6021 -- this is to handle backward compatibility (US+94065 union US+San Francisco)
6022 -- case. Also it will help in fetching multiple parents records as we are skipping
6023 -- parent levels which can be null
6024 -- This search is performed if :
6025 -- 1. Previous serach did not fetch any result
6026 -- 2. User has passed value for Country and
6027 -- a. either for last mapped parameter (like Postal_code)
6028 -- b. OR for second last parameter (like city)
6029 -- 3. Parameter passed above is for level 4 and higher in geo structure
6030 -- i.e. for US, value has been passed either for city or postal code
6031 -------------------------------------------------------------------+
6032 IF ((geo_rec_tbl.COUNT = 0) AND
6033 ((l_max_mapped_element_col_value = l_max_passed_element_col_value) OR
6034 (l_max_mapped_element_col_value-1 = l_max_passed_element_col_value)) AND
6035 (l_max_passed_element_col_value > 3)
6036 )THEN
6037
6038 -- FND Logging for debug purpose
6039 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
6040 hz_utility_v2pub.debug
6041 (p_message => 'Begin search 2..l_max_passed_element_col_value='||
6042 l_max_passed_element_col_value||' l_max_mapped_element_col_value='||
6043 l_max_mapped_element_col_value,
6044 p_prefix => l_debug_prefix,
6045 p_msg_level => fnd_log.level_statement,
6046 p_module_prefix => l_module_prefix,
6047 p_module => l_module
6048 );
6049 END IF;
6050
6051 l_count_for_where_clause_2 := 0;
6052 -- check if we have to build the where clause
6053 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
6054 IF (TO_NUMBER(SUBSTR(geo_struct_tbl(i).v_element_col,18)) IN (1,l_max_mapped_element_col_value)) THEN --1,2,5
6055 IF (geo_struct_tbl(i).v_param_value IS NOT NULL) THEN
6056 l_count_for_where_clause_2 := l_count_for_where_clause_2 +1;
6057 END IF;
6058 END IF;
6059 END LOOP;
6060 -- if l_count_for_where_clause_2 = 2 i.e. all required params passed,
6061 -- build where clause
6062 IF (l_count_for_where_clause_2 = 2) THEN
6063
6064 -- FND Logging for debug purpose
6065 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
6066 hz_utility_v2pub.debug
6067 (p_message => 'For Where Clause 2...required params are passed',
6068 p_prefix => l_debug_prefix,
6069 p_msg_level => fnd_log.level_statement,
6070 p_module_prefix => l_module_prefix,
6071 p_module => l_module
6072 );
6073 END IF;
6074
6075 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
6076 IF (TO_NUMBER(SUBSTR(geo_struct_tbl(i).v_element_col,18)) IN (1,l_max_mapped_element_col_value)) THEN --1,2,5
6077 IF (geo_struct_tbl(i).v_param_value IS NOT NULL) THEN
6078 create_where_2_clause_pvt(i, 1);
6079 END IF;
6080 END IF;
6081 END LOOP;
6082 IF (l_lowest_mapped_geo_type IS NOT NULL) THEN
6083 l_where_6 := l_where_6 ||' AND hg0.geography_type = :x_where_6_geo_type ';
6084 bind_table_2(bind_table_2.COUNT+1).bind_value := l_lowest_mapped_geo_type;
6085 END IF;
6086 END IF;
6087
6088 l_count_for_where_clause_3 := 0;
6089 -- check if we have to build the where clause
6090 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
6091 IF (TO_NUMBER(SUBSTR(geo_struct_tbl(i).v_element_col,18)) IN (1,l_max_mapped_element_col_value-1)) THEN --1,2,4
6092 -- build the where clause
6093 IF (geo_struct_tbl(i).v_param_value IS NOT NULL) THEN
6094 l_count_for_where_clause_3 := l_count_for_where_clause_3 +1;
6095 END IF;
6096 END IF;
6097 END LOOP;
6098 -- if l_count_for_where_clause_3 = 2 i.e. all required params passed,
6099 -- build where clause
6100 IF (l_count_for_where_clause_3 = 2) THEN
6101 -- FND Logging for debug purpose
6102 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
6103 hz_utility_v2pub.debug
6104 (p_message => 'For Where Clause 3...required params are passed',
6105 p_prefix => l_debug_prefix,
6106 p_msg_level => fnd_log.level_statement,
6107 p_module_prefix => l_module_prefix,
6108 p_module => l_module
6109 );
6110 END IF;
6111
6112 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
6113 IF (TO_NUMBER(SUBSTR(geo_struct_tbl(i).v_element_col,18)) IN (1,l_max_mapped_element_col_value-1)) THEN --1,2,4
6114 IF (geo_struct_tbl(i).v_param_value IS NOT NULL) THEN
6115 create_where_2_clause_pvt(i, 2);
6116 END IF;
6117 END IF;
6118 END LOOP;
6119 -- use geography type that of l_lowest_mapped_geo_type (since we want data till last level)
6120 IF (l_lowest_mapped_geo_type IS NOT NULL) THEN
6121 l_where_7 := l_where_7 ||' AND hg0.geography_type = :x_where_7_geo_type ';
6122 bind_table_2(bind_table_2.COUNT+1).bind_value
6123 := get_geo_type_from_element_col('GEOGRAPHY_ELEMENT'||to_char(l_max_mapped_element_col_value-1)); --l_lowest_mapped_geo_type;
6124 END IF;
6125 END IF;
6126
6127 -- execute query only if any of these 2 sql queries are constructed completely
6128 IF ((l_count_for_where_clause_2 = 2) OR (l_count_for_where_clause_3 = 2)) THEN
6129
6130 -- FND Logging for debug purpose
6131 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
6132 hz_utility_v2pub.debug
6133 (p_message => 'Begin search 2 for LEVEL4_UNION_LEVEL5_SEARCH (+)',
6134 p_prefix => l_debug_prefix,
6135 p_msg_level => fnd_log.level_procedure,
6136 p_module_prefix => l_module_prefix,
6137 p_module => l_module
6138 );
6139 END IF;
6140
6141 l_search_type := 'LEVEL4_UNION_LEVEL5_SEARCH';
6142 search_routine_pvt (pt_search_type => l_search_type,
6143 pt_bind_table => bind_table_2);
6144
6145 -- FND Logging for debug purpose
6146 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
6147 hz_utility_v2pub.debug
6148 (p_message => 'End search 3 for LEVEL4_UNION_LEVEL5_SEARCH (-)',
6149 p_prefix => l_debug_prefix,
6150 p_msg_level => fnd_log.level_procedure,
6151 p_module_prefix => l_module_prefix,
6152 p_module => l_module
6153 );
6154 END IF;
6155
6156 ELSE -- ignored LEVEL4_UNION_LEVEL5_SEARCH search
6157
6158 -- FND Logging for debug purpose
6159 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
6160 hz_utility_v2pub.debug
6161 (p_message => 'Ignored LEVEL4_UNION_LEVEL5_SEARCH because values for '||
6162 'neither Level1+Level(n) '||
6163 'nor Level1 + Level(n-1) are passed',
6164 p_prefix => l_debug_prefix,
6165 p_msg_level => fnd_log.level_procedure,
6166 p_module_prefix => l_module_prefix,
6167 p_module => l_module
6168 );
6169 END IF;
6170
6171 END IF;
6172
6173 -- Again check, if 1 row fetched, try to get child records
6174 IF (geo_rec_tbl.COUNT = 1) THEN
6175
6176 -- FND Logging for debug purpose
6177 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
6178 hz_utility_v2pub.debug
6179 (p_message => '1 Rec found in LEVEL4_UNION_LEVEL5_SEARCH. Performing child search (+)',
6180 p_prefix => l_debug_prefix,
6181 p_msg_level => fnd_log.level_procedure,
6182 p_module_prefix => l_module_prefix,
6183 p_module => l_module
6184 );
6185 END IF;
6186
6187 get_next_level_children_proc;
6188
6189 -- FND Logging for debug purpose
6190 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
6191 hz_utility_v2pub.debug
6192 (p_message => 'Completed child search for LEVEL4_UNION_LEVEL5_SEARCH (-)',
6193 p_prefix => l_debug_prefix,
6194 p_msg_level => fnd_log.level_procedure,
6195 p_module_prefix => l_module_prefix,
6196 p_module => l_module
6197 );
6198 END IF;
6199
6200 END IF;
6201
6202 END IF; -- End of LEVEL4_UNION_LEVEL5_SEARCH search (search 3)
6203 ----------------END OF SEARCH 2 -----------------------------------+
6204
6205 /*---------------- Search 3 -----------------------------------------+
6206 If still no suggestion could be derived, then check till what level
6207 from top we have unique valid values from top. Then suggest 1 level
6208 down from there. To handle case where full passed combination or partial
6209 combination is wrong. In that case, at least suggest whatever is valid
6210 down the country. It could mean suggesting all states if only country
6211 is valid or suggesting County if Country and State are valid.
6212 --------------------------------------------------------------------*/
6213
6214 IF (geo_rec_tbl.COUNT = 0) AND (geo_struct_tbl.COUNT > 0) THEN
6215 validate_input_values_proc (l_geo_struct_tbl => geo_struct_tbl,
6216 x_not_validated_geo_type => lx_not_validated_geo_type,
6217 x_rec_count_flag => lx_rec_count_flag,
6218 x_success_geo_level => lx_success_geo_level);
6219
6220 bind_table_1.DELETE;
6221
6222 IF (p_country_code IS NOT NULL) THEN
6223 bind_table_1(bind_table_1.COUNT+1).bind_value := UPPER(p_country_code);
6224 -- for bind_table_2 bind country code at the time of building where clause
6225 END IF;
6226
6227 -- initialize previous valid index to 0
6228 l_priv_valid_index := 0;
6229 l_from_5 := NULL;
6230 l_where_5 := NULL;
6231 l_max_passed_element_col_value := 0; -- reset it as we want to query data only
6232 -- till valid values
6233
6234 -- build the dynamic SQL (Search 1) for fetching data
6235 FOR i IN geo_struct_tbl.FIRST..geo_struct_tbl.LAST LOOP
6236 IF (geo_struct_tbl(i).v_level <= lx_success_geo_level) THEN
6237 CASE geo_struct_tbl(i).v_tab_col
6238 WHEN 'COUNTRY' THEN
6239 create_where_1_clause_pvt(i, geo_struct_tbl(i).v_param_value, 'CODE');
6240 ELSE create_where_1_clause_pvt(i, geo_struct_tbl(i).v_param_value, 'BOTH');
6241 END CASE;
6242 END IF;
6243 END LOOP;
6244
6245 l_search_type := 'SEARCH_FROM_TOP';
6246 search_routine_pvt (pt_search_type => l_search_type,
6247 pt_bind_table => bind_table_1,
6248 pt_success_geo_level => lx_success_geo_level);
6249
6250 -- 1. If 1 row is identified,
6251 -- If more than 1 rows, then just suggest them.
6252 IF (geo_rec_tbl.COUNT = 1) THEN
6253
6254 -- FND Logging for debug purpose
6255 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
6256 hz_utility_v2pub.debug
6257 (p_message => '1 record found for SEARCH_FROM_TOP search. Performing child search (+)',
6258 p_prefix => l_debug_prefix,
6259 p_msg_level => fnd_log.level_procedure,
6260 p_module_prefix => l_module_prefix,
6261 p_module => l_module
6262 );
6263 END IF;
6264
6265 get_next_level_children_proc;
6266
6267 -- FND Logging for debug purpose
6268 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
6269 hz_utility_v2pub.debug
6270 (p_message => 'Completed child search for SEARCH_FROM_TOP search.(-)',
6271 p_prefix => l_debug_prefix,
6272 p_msg_level => fnd_log.level_procedure,
6273 p_module_prefix => l_module_prefix,
6274 p_module => l_module
6275 );
6276 END IF;
6277
6278 END IF;
6279
6280 END IF;
6281 -------------------END OF SEARCH 3------------------------------------+
6282
6283 -- Nishant : commented out country only check (redundant check on 18-Apr-2006)
6284 -- END IF; -- end of check that only COUNTRY is mapped.
6285 --2------------------------------------------------------------------+
6286
6287 -- if anything exists in intermediate table geo_rec_tbl but
6288 -- nothing is there in final table geo_suggest_tbl, then copy it to final
6289 -- table, as that is the best that could be derived for suggestion.
6290 -- One example is: If country is passed and there are no states setup
6291 -- for that country.
6292 IF ((geo_suggest_tbl.COUNT = 0) AND (geo_rec_tbl.COUNT > 0)) THEN
6293
6294 -- FND Logging for debug purpose
6295 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
6296 hz_utility_v2pub.debug
6297 (p_message => 'Geo_suggest_tbl count is 0.. while geo_rec_tbl count is '
6298 ||TO_CHAR(geo_rec_tbl.COUNT),
6299 p_prefix => l_debug_prefix,
6300 p_msg_level => fnd_log.level_statement,
6301 p_module_prefix => l_module_prefix,
6302 p_module => l_module
6303 );
6304 END IF;
6305
6306 FOR i IN geo_rec_tbl.FIRST..geo_rec_tbl.LAST LOOP
6307 move_from_geo_rec_to_suggest(i,i);
6308 END LOOP;
6309
6310 -- FND Logging for debug purpose
6311 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
6312 hz_utility_v2pub.debug
6313 (p_message => 'Moved records from geo_rec_tbl to geo_suggest_tbl',
6314 p_prefix => l_debug_prefix,
6315 p_msg_level => fnd_log.level_statement,
6316 p_module_prefix => l_module_prefix,
6317 p_module => l_module
6318 );
6319 END IF;
6320
6321 END IF;
6322
6323 -------------------------------------------------------------------------+
6324 -- Check if exact match for the complete mapping is found i.e. whatever user
6325 -- has enetered for complete mapping is fetched, then we do not need to
6326 -- return suggestion. Delete other suggested values and just return the
6327 -- fetched values. Bug 4633962 (Fixed by Nishant Singhai on 29-Sep-2005)
6328 -------------------------------------------------------------------------+
6329 check_exact_match_del_rest;
6330
6331 -------------------------------------------------------------------------+
6332 -- Output data
6333 -- Changed logic to process output data based on discussion with dev team,
6334 -- and PMs. Bug 4600030 (28-Sep-2005)
6335 -------------------------------------------------------------------------+
6336 process_output_data_proc;
6337
6338 --------------------no geo mapping exist --------------------------+
6339 ELSIF (geo_struct_tbl.COUNT = 0) THEN
6340
6341 -- FND Logging for debug purpose
6342 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
6343 hz_utility_v2pub.debug
6344 (p_message => 'No Mapping Exists for passed country code and '||
6345 'address style combination (return code = NO_MAPPING_EXISTS)',
6346 p_prefix => l_debug_prefix,
6347 p_msg_level => fnd_log.level_statement,
6348 p_module_prefix => l_module_prefix,
6349 p_module => l_module
6350 );
6351 END IF;
6352
6353 -- set return code and return message
6354 setup_msg_and_ret_code_proc(p_return_code => 50, /* NO_MAPPING_EXISTS */
6355 p_msg_name => 'HZ_GEO_NO_MAP_FOR_COUNTRY');
6356
6357 -- ns_debug.put_line('NO MAPPING EXISTS ');
6358
6359 END IF; -- end of geo_struct_tbl count check
6360
6361 ----------------Validation level is miniumum or none -----------------+
6362 ELSE -- Validation level is MINIMUM or NONE
6363
6364 -- FND Logging for debug purpose
6365 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
6366 hz_utility_v2pub.debug
6367 (p_message => 'Validation Level is :'||l_addr_val_level||
6368 '. Calling procedure process_output_data_proc(+)',
6369 p_prefix => l_debug_prefix,
6370 p_msg_level => fnd_log.level_procedure,
6371 p_module_prefix => l_module_prefix,
6372 p_module => l_module
6373 );
6374 END IF;
6375
6376 process_output_data_proc;
6377
6378 -- FND Logging for debug purpose
6379 IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level) THEN
6380 hz_utility_v2pub.debug
6381 (p_message => 'Completed procedure process_output_data_proc(-)',
6382 p_prefix => l_debug_prefix,
6383 p_msg_level => fnd_log.level_procedure,
6384 p_module_prefix => l_module_prefix,
6385 p_module => l_module
6386 );
6387 END IF;
6388
6389 END IF;
6390
6391 -- FND Logging for debug purpose
6392 IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
6393 hz_utility_v2pub.debug
6394 (p_message => 'END: Address Suggestion API.'||
6395 ' Value of x_return_code='||x_return_code||
6396 ', x_records_count='||x_records_count ,
6397 p_prefix => l_debug_prefix,
6398 p_msg_level => fnd_log.level_statement,
6399 p_module_prefix => l_module_prefix,
6400 p_module => l_module
6401 );
6402 END IF;
6403
6404 EXCEPTION
6405 WHEN OTHERS THEN
6406
6407 -- FND Logging for debug purpose
6408 IF (fnd_log.level_exception >= fnd_log.g_current_runtime_level) THEN
6409 hz_utility_v2pub.debug
6410 (p_message => SUBSTR('SYSTEM ERROR occured in Address Suggestion API. '||
6411 SQLERRM, 1,255),
6412 p_prefix => l_debug_prefix,
6413 p_msg_level => fnd_log.level_exception,
6414 p_module_prefix => l_module_prefix,
6415 p_module => l_module
6416 );
6417 END IF;
6418
6419 HZ_GNR_PVT.G_USER_ATTEMPT_COUNT := NULL; -- reset the global variable
6420 x_return_status := FND_API.G_RET_STS_ERROR ;
6421
6422 -- set return code and return message
6423 setup_msg_and_ret_code_proc(p_return_code => 200); /* SYSTEM_ERROR (System Error) */
6424
6425 FND_MESSAGE.SET_NAME( 'AR', 'HZ_API_OTHERS_EXCEP' );
6426 FND_MESSAGE.SET_TOKEN( 'ERROR' ,SQLERRM );
6427 FND_MSG_PUB.ADD;
6428
6429 FND_MSG_PUB.Count_And_Get(
6430 p_encoded => FND_API.G_FALSE,
6431 p_count => x_msg_count,
6432 p_data => x_msg_data );
6433
6434 -- ns_debug.put_line(SUBSTR('ERROR :'||SQLERRM,1,255));
6435 -- ns_debug.put_line('location= '||l_error_location);
6436 -- ns_debug.put_line(l_sql_stmt);
6437
6438 END search_geographies;
6439
6440 END HZ_GNR_PVT;