DBA Data[Home] [Help]

PACKAGE BODY: APPS.HZ_GNR_PVT

Source


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