DBA Data[Home] [Help]

PACKAGE BODY: APPS.AK_REGION2_PVT

Source


1 package body AK_REGION2_PVT as
2 /* $Header: akdvre2b.pls 120.4 2006/11/30 23:19:34 tshort ship $ */
3 
4 --=======================================================
5 --  Procedure   UPLOAD_REGION
6 --
7 --  Usage       Private API for loading regions from a
8 --              loader file to the database.
9 --              This API should only be called by other APIs
10 --              that are owned by the Core Modules Team (AK).
11 --
12 --  Desc        This API reads the region data (including region
13 --              items) stored in the loader file currently being
14 --              processed, parses the data, and loads them to the
15 --              database. The tables are updated with the timestamp
16 --              passed. This API will process the file until the
17 --              EOF is reached, a parse error is encountered, or when
18 --              data for a different business object is read from the file.
19 --
20 --  Results     The API returns the standard p_return_status parameter
21 --              indicating one of the standard return statuses :
22 --                  * Unexpected error
23 --                  * Error
24 --                  * Success
25 --  Parameters  p_index : IN OUT required
26 --                  Index of PL/SQL file to be processed.
27 --              p_loader_timestamp : IN required
28 --                  The timestamp to be used when creating or updating
29 --                  records
30 --              p_line_num : IN optional
31 --                  The first line number in the file to be processed.
32 --                  It is used for keeping track of the line number
33 --                  read so that this info can be included in the
34 --                  error message when a parse error occurred.
35 --              p_buffer : IN required
36 --                  The content of the first line to be processed.
37 --                  The calling API has already read the first line
38 --                  that needs to be parsed by this API, so this
39 --                  line won't be read from the file again.
40 --              p_line_num_out : OUT
41 --                  The number of the last line in the loader file
42 --                  that is read by this API.
43 --              p_buffer_out : OUT
44 --                  The content of the last line read by this API.
45 --                  If an EOF has not reached, this line would
46 --                  contain the beginning of another business object
47 --                  that will need to be processed by another API.
48 --
49 --  Version     Initial version number  =   1.0
50 --  History     Current version number  =   1.0
51 --=======================================================
52 procedure UPLOAD_REGION (
53   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
54   p_api_version_number       IN      NUMBER,
55   p_return_status            OUT NOCOPY     VARCHAR2,
56   p_index                    IN OUT NOCOPY  NUMBER,
57   p_loader_timestamp         IN      DATE,
58   p_line_num                 IN NUMBER := FND_API.G_MISS_NUM,
59   p_buffer                   IN AK_ON_OBJECTS_PUB.Buffer_Type,
60   p_line_num_out             OUT NOCOPY    NUMBER,
61   p_buffer_out               OUT NOCOPY    AK_ON_OBJECTS_PUB.Buffer_Type,
62   p_upl_loader_cur           IN OUT NOCOPY  AK_ON_OBJECTS_PUB.LoaderCurTyp,
63   p_pass                     IN      NUMBER := 1
64 ) is
65   cursor l_check_fnd_category_name_csr (p_category_id in number) is
66      select name
67      from fnd_document_categories
68      where category_id = p_category_id;
69   cursor l_check_fnd_category_id_csr (p_category_name in varchar2) is
70      select category_id
71      from fnd_document_categories
72      where name =p_category_name;
73   cursor l_get_region_item_csr (region_appl_id_param number,
74   region_code_param varchar2) is
75      select ATTRIBUTE_APPLICATION_ID, ATTRIBUTE_CODE
76      from   AK_REGION_ITEMS
77      where  region_application_id = region_appl_id_param
78      and    region_code = region_code_param;
79   l_api_version_number       CONSTANT number := 1.0;
80   l_api_name                 CONSTANT varchar2(30) := 'Upload_Region';
81   l_item_index               NUMBER := 0;
82   l_item_rec                 AK_REGION_PUB.Item_Rec_Type;
83   l_item_tbl                 AK_REGION_PUB.Item_Tbl_Type;
84 --  l_graph_index		     NUMBER := 0;
85 --  l_graph_rec		     AK_REGION_PUB.Graph_Rec_Type;
86 --  l_empty_graph_rec	     AK_REGION_PUB.Graph_Rec_Type;
87 --  l_graph_tbl		     AK_REGION_PUB.Graph_Tbl_Type;
88 --  l_graph_column_index	     NUMBER := 0;
89 --  l_graph_column_rec	     AK_REGION_GRAPH_COLUMNS%ROWTYPE;
90 --  l_empty_graph_column_rec   AK_REGION_GRAPH_COLUMNS%ROWTYPE;
91 --  l_graph_column_tbl	     AK_REGION_PUB.Graph_Column_Tbl_Type;
92   l_buffer                   AK_ON_OBJECTS_PUB.Buffer_Type;
93   l_column                   varchar2(30);
94   l_dummy                    NUMBER;
95   l_eof_flag                 VARCHAR2(1);
96   l_index                    NUMBER;
97   l_line_num                 NUMBER;
98   l_lines_read               NUMBER;
99   l_more_region              BOOLEAN := TRUE;
100   l_msg_count                NUMBER;
101   l_msg_data                 VARCHAR2(2000);
102   l_region_index             NUMBER := 0;
103   l_lov_relation_index		 NUMBER := 0;
104   l_category_usage_index     NUMBER := 0;
105   l_region_rec               AK_REGION_PUB.Region_Rec_Type;
106   l_region_tbl               AK_REGION_PUB.Region_Tbl_Type;
107   l_lov_relation_rec		 AK_REGION_LOV_RELATIONS%ROWTYPE;
108   l_empty_lov_relation_rec	 AK_REGION_LOV_RELATIONS%ROWTYPE;
109   l_lov_relation_tbl		 AK_REGION_PUB.Lov_Relation_Tbl_Type;
110   l_category_usage_rec		 AK_CATEGORY_USAGES%ROWTYPE;
111   l_empty_category_usage_rec	 AK_CATEGORY_USAGES%ROWTYPE;
112   l_category_usage_tbl		 AK_REGION_PUB.Category_Usages_Tbl_Type;
113   l_return_status            varchar2(1);
114   l_saved_token              AK_ON_OBJECTS_PUB.Buffer_Type;
115   l_state                    NUMBER;
116   l_token                    AK_ON_OBJECTS_PUB.Buffer_Type;
117   l_value_count              NUMBER;
118   l_copy_redo_flag           BOOLEAN := FALSE;
119   l_user_id1				 NUMBER;
120   l_user_id2				 NUMBER;
121   l_update1                  DATE;
122   l_update2                  DATE;
123 begin
124   --dbms_output.put_line('Started region upload: ' ||
125   --                            to_char(sysdate, 'MON-DD HH24:MI:SS'));
126 
127   IF NOT FND_API.Compatible_API_Call (
128     l_api_version_number, p_api_version_number, l_api_name,
129     G_PKG_NAME) then
130       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
131       return;
132   END IF;
133 
134  -- 5665840 - removed savepoint as child  procedures do the savepoint/
135  -- rollback/commit
136   --SAVEPOINT Start_Upload;
137 
138   -- Retrieve the first non-blank, non-comment line
139   l_state := 0;
140   l_eof_flag := 'N';
141   --
142   -- if calling from ak_on_objects.upload (ie, loader timestamp is given),
143   -- the tokens 'BEGIN REGION' has already been parsed. Set initial
144   -- buffer to 'BEGIN REGION' before reading the next line from the
145   -- file. Otherwise, set initial buffer to null.
146   --
147   if (p_loader_timestamp <> FND_API.G_MISS_DATE) then
148     l_buffer := 'BEGIN REGION ' || p_buffer;
149   else
150     l_buffer := null;
151   end if;
152 
153   if (p_line_num = FND_API.G_MISS_NUM) then
154     l_line_num := 0;
155   else
156     l_line_num := p_line_num;
157   end if;
158 
159   while (l_buffer is null and l_eof_flag = 'N' and p_index <=  AK_ON_OBJECTS_PVT.G_UPL_TABLE_NUM) loop
160       AK_ON_OBJECTS_PVT.READ_LINE (
161         p_return_status => l_return_status,
162         p_index => p_index,
163         p_buffer => l_buffer,
164         p_lines_read => l_lines_read,
165         p_eof_flag => l_eof_flag,
166         p_upl_loader_cur => p_upl_loader_cur
167       );
168       if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
169          (l_return_status = FND_API.G_RET_STS_ERROR) then
170           RAISE FND_API.G_EXC_ERROR;
171       end if;
172       l_line_num := l_line_num + l_lines_read;
173       --
174       -- trim leading spaces and discard comment lines
175       --
176       l_buffer := LTRIM(l_buffer);
177       if (SUBSTR(l_buffer, 1, 1) = '#') then
178         l_buffer := null;
179       end if;
180   end loop;
181 
182   --
183   -- Error if there is nothing to be read from the file
184   --
185   if (l_buffer is null and l_eof_flag = 'Y') then
186     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
187       FND_MESSAGE.SET_NAME('AK','AK_EMPTY_BUFFER');
188       FND_MSG_PUB.Add;
189     end if;
190     raise FND_API.G_EXC_ERROR;
191   end if;
192 
193   -- Read tokens from file, one at a time
194 
195   while (l_eof_flag = 'N') and (l_buffer is not null)
196         and (l_more_region) loop
197 
198     AK_ON_OBJECTS_PVT.GET_TOKEN(
199       p_return_status => l_return_status,
200       p_in_buf => l_buffer,
201       p_token => l_token
202     );
203 
204 --dbms_output.put_line(' State:' || l_state || 'Token:' || l_token);
205 
206     if (l_return_status = FND_API.G_RET_STS_ERROR) or
207        (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) then
208       if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
209         FND_MESSAGE.SET_NAME('AK','AK_GET_TOKEN_ERROR');
210         FND_MSG_PUB.Add;
211       end if;
212       --dbms_output.put_line(l_api_name || ' Error parsing buffer');
213       raise FND_API.G_EXC_ERROR;
214     end if;
215 
216 
217     --
218     -- REGION (states 0 - 19)
219     --
220     if (l_state = 0) then
221       if (l_token = 'BEGIN') then
222         l_state := 1;
223       else
224         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
225           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
226           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
227           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
228           FND_MESSAGE.SET_TOKEN('EXPECTED','BEGIN');
229           FND_MSG_PUB.Add;
230         end if;
231         raise FND_API.G_EXC_ERROR;
232       end if;
233     elsif (l_state = 1) then
234       if (l_token = 'REGION') then
235         --== Clear out previous column data  ==--
236     l_region_rec := AK_REGION_PUB.G_MISS_REGION_REC;
237        l_state := 2;
238       else
239         -- Found the beginning of a non-region object,
240         -- rebuild last line and pass it back to the caller
241         -- (ak_on_objects_pvt.upload).
242         p_buffer_out := 'BEGIN ' || l_token || ' ' || l_buffer;
243         l_more_region := FALSE;
244       end if;
245     elsif (l_state = 2) then
246       if (l_token is not null) then
247         l_region_rec.region_application_id := to_number(l_token);
248         l_state := 3;
249       else
250         --dbms_output.put_line('Expecting region application ID');
251         raise FND_API.G_EXC_ERROR;
252       end if;
253     elsif (l_state = 3) then
254       if (l_token is not null) then
255         l_region_rec.region_code := l_token;
256         l_value_count := null;
257         l_state := 10;
258       else
259         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
260           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
261           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
262           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
263           FND_MESSAGE.SET_TOKEN('EXPECTED','REGION_CODE');
264           FND_MSG_PUB.Add;
265         end if;
266         raise FND_API.G_EXC_ERROR;
267       end if;
268     elsif (l_state = 10) then
269       if (l_token = 'BEGIN') then
270         l_state := 13;
271       elsif (l_token = 'END') then
272         l_state := 19;
273       elsif (l_token = 'DATABASE_OBJECT_NAME') or
274         (l_token = 'REGION_STYLE') or
275             (l_token = 'ICX_CUSTOM_CALL') or
276             (l_token = 'NUM_COLUMNS') or
277             (l_token = 'REGION_DEFAULTING_API_PKG') or
278             (l_token = 'REGION_DEFAULTING_API_PROC') or
279             (l_token = 'REGION_VALIDATION_API_PKG') or
280             (l_token = 'REGION_VALIDATION_API_PROC') or
281             (l_token = 'APPLICATIONMODULE_OBJECT_TYPE') or
282             (l_token = 'NUM_ROWS_DISPLAY') or
283             (l_token = 'REGION_OBJECT_TYPE') or
284             (l_token = 'IMAGE_FILE_NAME') or
285             (l_token = 'ISFORM_FLAG') or
286 			(l_token = 'HELP_TARGET') or
287 			(l_token = 'STYLE_SHEET_FILENAME') or
288 			(l_token = 'VERSION') or
289 			(l_token = 'APPLICATIONMODULE_USAGE_NAME') or
290 			(l_token = 'ADD_INDEXED_CHILDREN') or
291 			(l_token = 'STATEFUL_FLAG') or
292 			(l_token = 'FUNCTION_NAME') or
293 			(l_token = 'CHILDREN_VIEW_USAGE_NAME') or
294 			(l_token = 'SEARCH_PANEL') or
295 			(l_token = 'ADVANCED_SEARCH_PANEL') or
296 			(l_token = 'CUSTOMIZE_PANEL') or
297 			(l_token = 'DEFAULT_SEARCH_PANEL') or
298 			(l_token = 'RESULTS_BASED_SEARCH') or
299 			(l_token = 'DISPLAY_GRAPH_TABLE') or
300                         (l_token = 'DISABLE_HEADER') or
301                         (l_token = 'STANDALONE') or
302 			(l_token = 'AUTO_CUSTOMIZATION_CRITERIA') or
303 			(l_token = 'ATTRIBUTE_CATEGORY') or
304 			(l_token = 'ATTRIBUTE1') or
305 			(l_token = 'ATTRIBUTE2') or
306 			(l_token = 'ATTRIBUTE3') or
307 			(l_token = 'ATTRIBUTE4') or
308 			(l_token = 'ATTRIBUTE5') or
309 			(l_token = 'ATTRIBUTE6') or
310 			(l_token = 'ATTRIBUTE7') or
311 			(l_token = 'ATTRIBUTE8') or
312 			(l_token = 'ATTRIBUTE9') or
313 			(l_token = 'ATTRIBUTE10') or
314 			(l_token = 'ATTRIBUTE11') or
315 			(l_token = 'ATTRIBUTE12') or
316 			(l_token = 'ATTRIBUTE13') or
317 			(l_token = 'ATTRIBUTE14') or
318 			(l_token = 'ATTRIBUTE15') or
319             (l_token = 'NAME') or
320             (l_token = 'DESCRIPTION')  or
321                         (l_token = 'CREATED_BY') or
322                         (l_token = 'CREATION_DATE') or
323                         (l_token = 'LAST_UPDATED_BY') or
324                         (l_token = 'OWNER') or
325                         (l_token = 'LAST_UPDATE_DATE') or
326                         (l_token = 'LAST_UPDATE_LOGIN') then
327         l_column := l_token;
328         l_state := 11;
329       else
330       --
331       -- error if not expecting attribute values added by the translation team
332       -- or if we have read in more than a certain number of values
333       -- for the same DB column
334       --
335         l_value_count := l_value_count + 1;
336         --
337         -- save second value. It will be the token with error if
338         -- it turns out that there is a parse error on this line.
339         --
340         if (l_value_count = 2) then
341           l_saved_token := l_token;
342         end if;
343         if (l_value_count > AK_ON_OBJECTS_PUB.G_MAX_NUM_LOADER_VALUES) or
344            (l_value_count is null) then
345           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
346             FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_EFIELD');
347             FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
348             if (l_value_count is null) then
349               FND_MESSAGE.SET_TOKEN('TOKEN', l_token);
350             else
351               FND_MESSAGE.SET_TOKEN('TOKEN',l_saved_token);
352             end if;
353             FND_MESSAGE.SET_TOKEN('EXPECTED','REGION');
354             FND_MSG_PUB.Add;
355           end if;
356 --        dbms_output.put_line('Expecting region field, BEGIN, or END');
357           raise FND_API.G_EXC_ERROR;
358         end if;
359       end if;
360     elsif (l_state = 11) then
361       if (l_token = '=') then
362         l_state := 12;
363       else
364         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
365           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
366           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
367           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
368           FND_MESSAGE.SET_TOKEN('EXPECTED','=');
369           FND_MSG_PUB.Add;
370         end if;
371         raise FND_API.G_EXC_ERROR;
372       end if;
373     elsif (l_state = 12) then
374       l_value_count := 1;
375       if (l_column = 'DATABASE_OBJECT_NAME') then
376          l_region_rec.database_object_name := l_token;
377       elsif (l_column = 'REGION_STYLE') then
378          l_region_rec.region_style := l_token;
379       elsif (l_column = 'ICX_CUSTOM_CALL') then
380          l_region_rec.icx_custom_call := l_token;
381       elsif (l_column = 'NUM_COLUMNS') then
382          l_region_rec.num_columns := to_number(l_token);
383       elsif (l_column = 'REGION_DEFAULTING_API_PKG') then
384          l_region_rec.region_defaulting_api_pkg := l_token;
385       elsif (l_column = 'REGION_DEFAULTING_API_PROC') then
386          l_region_rec.region_defaulting_api_proc := l_token;
387       elsif (l_column = 'REGION_VALIDATION_API_PKG') then
388          l_region_rec.region_validation_api_pkg := l_token;
389       elsif (l_column = 'REGION_VALIDATION_API_PROC') then
390          l_region_rec.region_validation_api_proc := l_token;
391       elsif (l_column = 'APPLICATIONMODULE_OBJECT_TYPE') then
392          l_region_rec.applicationmodule_object_type := l_token;
393       elsif (l_column = 'NUM_ROWS_DISPLAY') then
394          l_region_rec.num_rows_display := l_token;
395       elsif (l_column = 'REGION_OBJECT_TYPE') then
396          l_region_rec.region_object_type := l_token;
397       elsif (l_column = 'IMAGE_FILE_NAME') then
398          l_region_rec.image_file_name := l_token;
399       elsif (l_column = 'ISFORM_FLAG') then
400          l_region_rec.isform_flag := l_token;
401       elsif (l_column = 'HELP_TARGET') then
402          l_region_rec.help_target := l_token;
403       elsif (l_column = 'STYLE_SHEET_FILENAME') then
404          l_region_rec.style_sheet_filename := l_token;
405       elsif (l_column = 'VERSION') then
406          l_region_rec.version := l_token;
407       elsif (l_column = 'APPLICATIONMODULE_USAGE_NAME') then
408          l_region_rec.applicationmodule_usage_name := l_token;
409       elsif (l_column = 'ADD_INDEXED_CHILDREN') then
410          l_region_rec.add_indexed_children := l_token;
411       elsif (l_column = 'STATEFUL_FLAG') then
412          l_region_rec.stateful_flag := l_token;
413       elsif (l_column = 'FUNCTION_NAME') then
414          l_region_rec.function_name := l_token;
415       elsif (l_column = 'CHILDREN_VIEW_USAGE_NAME') then
416          l_region_rec.children_view_usage_name := l_token;
417       elsif (l_column = 'SEARCH_PANEL') then
418          l_region_rec.search_panel := l_token;
419       elsif (l_column = 'ADVANCED_SEARCH_PANEL') then
420          l_region_rec.advanced_search_panel := l_token;
421       elsif (l_column = 'CUSTOMIZE_PANEL') then
422          l_region_rec.customize_panel := l_token;
423       elsif (l_column = 'DEFAULT_SEARCH_PANEL') then
424          l_region_rec.default_search_panel := l_token;
425       elsif (l_column = 'RESULTS_BASED_SEARCH') then
426          l_region_rec.results_based_search := l_token;
427       elsif (l_column = 'DISPLAY_GRAPH_TABLE') then
428          l_region_rec.display_graph_table := l_token;
429       elsif (l_column = 'DISABLE_HEADER') then
430          l_region_rec.disable_header := l_token;
431       elsif (l_column = 'STANDALONE') then
432          l_region_rec.standalone := l_token;
433       elsif (l_column = 'AUTO_CUSTOMIZATION_CRITERIA') then
434          l_region_rec.auto_customization_criteria := l_token;
435       elsif (l_column = 'ATTRIBUTE_CATEGORY') then
436          l_region_rec.attribute_category := l_token;
437       elsif (l_column = 'ATTRIBUTE1') then
438          l_region_rec.attribute1 := l_token;
439       elsif (l_column = 'ATTRIBUTE2') then
440          l_region_rec.attribute2 := l_token;
441       elsif (l_column = 'ATTRIBUTE3') then
442          l_region_rec.attribute3 := l_token;
443       elsif (l_column = 'ATTRIBUTE4') then
444          l_region_rec.attribute4 := l_token;
445       elsif (l_column = 'ATTRIBUTE5') then
446          l_region_rec.attribute5 := l_token;
447       elsif (l_column = 'ATTRIBUTE6') then
448          l_region_rec.attribute6 := l_token;
449       elsif (l_column = 'ATTRIBUTE7') then
450          l_region_rec.attribute7 := l_token;
451       elsif (l_column = 'ATTRIBUTE8') then
452          l_region_rec.attribute8 := l_token;
453       elsif (l_column = 'ATTRIBUTE9') then
454          l_region_rec.attribute9 := l_token;
455       elsif (l_column = 'ATTRIBUTE10') then
456          l_region_rec.attribute10 := l_token;
457       elsif (l_column = 'ATTRIBUTE11') then
458          l_region_rec.attribute11 := l_token;
459       elsif (l_column = 'ATTRIBUTE12') then
460          l_region_rec.attribute12 := l_token;
461       elsif (l_column = 'ATTRIBUTE13') then
462          l_region_rec.attribute13 := l_token;
463       elsif (l_column = 'ATTRIBUTE14') then
464          l_region_rec.attribute14 := l_token;
465       elsif (l_column = 'ATTRIBUTE15') then
466          l_region_rec.attribute15 := l_token;
467       elsif (l_column = 'NAME') then
468          l_region_rec.name := l_token;
469       elsif (l_column = 'DESCRIPTION') then
470          l_region_rec.description := l_token;
471       elsif (l_column = 'CREATED_BY') then
472          l_region_rec.created_by := to_number(l_token);
473       elsif (l_column = 'CREATION_DATE') then
474          l_region_rec.creation_date := to_date(l_token,
475                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
476       elsif (l_column = 'LAST_UPDATED_BY') then
477          l_region_rec.last_updated_by := to_number(l_token);
478       elsif (l_column = 'OWNER') then
479          l_region_rec.last_updated_by := FND_LOAD_UTIL.OWNER_ID(l_token);
480       elsif (l_column = 'LAST_UPDATE_DATE') then
481          l_region_rec.last_update_date := to_date(l_token,
482                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
483       elsif (l_column = 'LAST_UPDATE_LOGIN') then
484          l_region_rec.last_update_login := to_number(l_token);
485       else
486         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
487           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
488           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
489           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
490           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column);
491           FND_MSG_PUB.Add;
492         end if;
493         raise FND_API.G_EXC_ERROR;
494       end if;
495       l_state := 10;
496     elsif (l_state = 13) then
497       if (l_token = 'REGION_ITEM') then
498         --== Clear out previous region item column data  ==--
499         --   and load region key values into record        --
500 		l_item_rec := AK_REGION_PUB.G_MISS_ITEM_REC;
501         l_item_rec.region_application_id := l_region_rec.region_application_id;
502         l_item_rec.region_code := l_region_rec.region_code;
503         l_state := 20;
504 	  elsif ( l_token = 'REGION_LOV_RELATION') then
505 	    -- clear out previous region lov relation column data --
506         --   and load region item key values into record        --
507 		l_lov_relation_rec := l_empty_lov_relation_rec;
508 		l_lov_relation_rec.region_application_id := l_item_rec.region_application_id;
509 		l_lov_relation_rec.region_code := l_item_rec.region_code;
510 		l_lov_relation_rec.attribute_application_id := l_item_rec.attribute_application_id;
511 		l_lov_relation_rec.attribute_code := l_item_rec.attribute_code;
512 		l_state := 100;
513 	  elsif ( l_token = 'CATEGORY_USAGE') then
514 	    -- clear out previous region lov relation column data --
515         --   and load region item key values into record        --
516 		l_category_usage_rec := l_empty_category_usage_rec;
517 		l_category_usage_rec.region_application_id := l_item_rec.region_application_id;
518 		l_category_usage_rec.region_code := l_item_rec.region_code;
519 		l_category_usage_rec.attribute_application_id := l_item_rec.attribute_application_id;
520 		l_category_usage_rec.attribute_code := l_item_rec.attribute_code;
521 		l_state := 200;
522 	elsif (l_token = 'REGION_GRAPH') then
523 	  -- clear out previous region graph data --
524 	  -- and load region graph key values into record --
525 --	  	l_graph_rec := l_empty_graph_rec;
526 --		l_graph_rec.region_application_id := l_region_rec.region_application_id;
527 --		l_graph_rec.region_code := l_region_rec.region_code;
528 		l_state := 300;
529 	elsif (l_token = 'REGION_GRAPH_COLUMN') then
530 	  -- clear out previous region graph column data --
531 	  -- and load region graph column key values into record --
532 --		l_graph_column_rec := l_empty_graph_column_rec;
533 --		l_graph_column_rec.region_application_id := l_graph_rec.region_application_id;
534 --		l_graph_column_rec.region_code := l_graph_rec.region_code;
535 --		l_graph_column_rec.graph_number := l_graph_rec.graph_number;
536 		l_state := 400;
537       else
538         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
539           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
540           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
541           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
542           FND_MESSAGE.SET_TOKEN('EXPECTED', 'REGION_ITEM, REGION_LOV_RELATION, CATEGORY_USAGE');
543           FND_MSG_PUB.Add;
544         end if;
545         raise FND_API.G_EXC_ERROR;
546       end if;
547     elsif (l_state = 19) then
548       if (l_token = 'REGION') then
549         l_state := 0;
550         l_region_index := l_region_index + 1;
551         l_region_tbl(l_region_index) := l_region_rec;
552       else
553         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
554           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
555           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
556           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
557           FND_MESSAGE.SET_TOKEN('EXPECTED', 'REGION');
558           FND_MSG_PUB.Add;
559         end if;
560         raise FND_API.G_EXC_ERROR;
561       end if;
562 
563     --
564     -- REGION_ITEM (states 20 - 39)
565     --
566     elsif (l_state = 20) then
567       if (l_token is not null) then
568         l_item_rec.attribute_application_id := to_number(l_token);
569         l_state := 21;
570       else
571         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
572           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
573           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
574           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
575           FND_MESSAGE.SET_TOKEN('EXPECTED', 'ATTRIBUTE_APPLICATION_ID');
576           FND_MSG_PUB.Add;
577         end if;
578         raise FND_API.G_EXC_ERROR;
579       end if;
580     elsif (l_state = 21) then
581       if (l_token is not null) then
582         l_item_rec.attribute_code := l_token;
583         l_value_count := null;
584         l_state := 30;
585       else
586         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
587           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
588           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
589           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
590           FND_MESSAGE.SET_TOKEN('EXPECTED', 'ATTRIBUTE_CODE');
591           FND_MSG_PUB.Add;
592         end if;
593         raise FND_API.G_EXC_ERROR;
594       end if;
595     elsif (l_state = 30) then
596       if (l_token = 'END') then
597         l_state := 39;
598 	  elsif (l_token = 'BEGIN') then
599 		l_state := 13;
600       elsif (l_token = 'DISPLAY_SEQUENCE') or
601         (l_token = 'NODE_DISPLAY_FLAG') or
602         (l_token = 'NODE_QUERY_FLAG') or
603             (l_token = 'ATTRIBUTE_LABEL_LENGTH') or
604             (l_token = 'DISPLAY_VALUE_LENGTH') or
605             (l_token = 'BOLD') or
606             (l_token = 'ITALIC') or
607             (l_token = 'VERTICAL_ALIGNMENT') or
608             (l_token = 'HORIZONTAL_ALIGNMENT') or
609             (l_token = 'ITEM_STYLE') or
610             (l_token = 'OBJECT_ATTRIBUTE_FLAG') or
611             (l_token = 'ICX_CUSTOM_CALL') or
612             (l_token = 'UPDATE_FLAG') or
613             (l_token = 'REQUIRED_FLAG') or
614             (l_token = 'SECURITY_CODE') or
615             (l_token = 'DEFAULT_VALUE_VARCHAR2') or
616             (l_token = 'DEFAULT_VALUE_NUMBER') or
617             (l_token = 'DEFAULT_VALUE_DATE') or
618             (l_token = 'LOV_REGION') or
619             (l_token = 'LOV_FOREIGN_KEY_NAME') or
620             (l_token = 'LOV_ATTRIBUTE') or
621             (l_token = 'LOV_DEFAULT_FLAG') or
622             (l_token = 'REGION_DEFAULTING_API_PKG') or
623             (l_token = 'REGION_DEFAULTING_API_PROC') or
624             (l_token = 'REGION_VALIDATION_API_PKG') or
625             (l_token = 'REGION_VALIDATION_API_PROC') or
626             (l_token = 'ORDER_SEQUENCE') or
627 	    (l_token = 'INITIAL_SORT_SEQUENCE') or
628 	    (l_token = 'CUSTOMIZATION_APPLICATION_ID') or
629             (l_token = 'CUSTOMIZATION_CODE') or
630             (l_token = 'ORDER_DIRECTION') or
631             (l_token = 'SUBMIT') or
632             (l_token = 'ENCRYPT') or
633             (l_token = 'DISPLAY_HEIGHT') or
634             (l_token = 'CSS_CLASS_NAME') or
635             (l_token = 'VIEW_USAGE_NAME') or
636             (l_token = 'VIEW_ATTRIBUTE_NAME') or
637             (l_token = 'NESTED_REGION_APPLICATION_ID') or
638             (l_token = 'NESTED_REGION_CODE') or
639             (l_token = 'URL') or
640             (l_token = 'POPLIST_VIEWOBJECT') or
641             (l_token = 'POPLIST_DISPLAY_ATTRIBUTE') or
642             (l_token = 'POPLIST_VALUE_ATTRIBUTE') or
643             (l_token = 'IMAGE_FILE_NAME') or
644             (l_token = 'ITEM_NAME') or
645             (l_token = 'CSS_LABEL_CLASS_NAME') or
646 			(l_token = 'MENU_NAME') or
647 			(l_token = 'FLEXFIELD_NAME') or
648 			(l_token = 'FLEXFIELD_APPLICATION_ID') or
649 			(l_token = 'TABULAR_FUNCTION_CODE') or
650 			(l_token = 'TIP_TYPE') or
651 			(l_token = 'TIP_MESSAGE_NAME') or
652 			(l_token = 'TIP_MESSAGE_APPLICATION_ID') or
653 			(l_token = 'FLEX_SEGMENT_LIST') or
654 			(l_token = 'ENTITY_ID') or
655 			(l_token = 'ANCHOR') or
656 			(l_token = 'POPLIST_VIEW_USAGE_NAME') or
657                         (l_token = 'USER_CUSTOMIZABLE') or
658 			(l_token = 'SORTBY_VIEW_ATTRIBUTE_NAME') or
659 			(l_token = 'ADMIN_CUSTOMIZABLE') or
660 			(l_token = 'INVOKE_FUNCTION_NAME') or
661 			(l_token = 'EXPANSION') or
662 			(l_token = 'ALS_MAX_LENGTH') or
663 			(l_token = 'ATTRIBUTE_CATEGORY') or
664 			(l_token = 'ATTRIBUTE1') or
665 			(l_token = 'ATTRIBUTE2') or
666 			(l_token = 'ATTRIBUTE3') or
667 			(l_token = 'ATTRIBUTE4') or
668 			(l_token = 'ATTRIBUTE5') or
669 			(l_token = 'ATTRIBUTE6') or
670 			(l_token = 'ATTRIBUTE7') or
671 			(l_token = 'ATTRIBUTE8') or
672 			(l_token = 'ATTRIBUTE9') or
673 			(l_token = 'ATTRIBUTE10') or
674 			(l_token = 'ATTRIBUTE11') or
675 			(l_token = 'ATTRIBUTE12') or
676 			(l_token = 'ATTRIBUTE13') or
677 			(l_token = 'ATTRIBUTE14') or
678 			(l_token = 'ATTRIBUTE15') or
679                         (l_token = 'CREATED_BY') or
680                         (l_token = 'CREATION_DATE') or
681                         (l_token = 'LAST_UPDATED_BY') or
682                         (l_token = 'OWNER') or
683                         (l_token = 'LAST_UPDATE_DATE') or
684                         (l_token = 'LAST_UPDATE_LOGIN') or
685             (l_token = 'ATTRIBUTE_LABEL_LONG') or
686             (l_token = 'ATTRIBUTE_LABEL_SHORT') or
687             (l_token = 'DESCRIPTION') then
688         l_column := l_token;
689         l_state := 31;
690       else
691       --
692       -- error if not expecting attribute values added by the translation team
693       -- or if we have read in more than a certain number of values
694       -- for the same DB column
695       --
696         l_value_count := l_value_count + 1;
697         --
698         -- save second value. It will be the token with error if
699         -- it turns out that there is a parse error on this line.
700         --
701         if (l_value_count = 2) then
702           l_saved_token := l_token;
703         end if;
704         if (l_value_count > AK_ON_OBJECTS_PUB.G_MAX_NUM_LOADER_VALUES) or
705            (l_value_count is null) then
706           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
707             FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_EFIELD');
708             FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
709             if (l_value_count is null) then
710               FND_MESSAGE.SET_TOKEN('TOKEN', l_token);
711             else
712               FND_MESSAGE.SET_TOKEN('TOKEN',l_saved_token);
713             end if;
714             FND_MESSAGE.SET_TOKEN('EXPECTED','REGION_ITEM');
715             FND_MSG_PUB.Add;
716           end if;
717           raise FND_API.G_EXC_ERROR;
718         end if;
719       end if;
720     elsif (l_state = 31) then
721       if (l_token = '=') then
722         l_state := 32;
723       else
724         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
725           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
726           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
727           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
728           FND_MESSAGE.SET_TOKEN('EXPECTED', '=');
729           FND_MSG_PUB.Add;
730         end if;
731         raise FND_API.G_EXC_ERROR;
732       end if;
733     elsif (l_state = 32) then
734       l_value_count := 1;
735       if (l_column = 'DISPLAY_SEQUENCE') then
736          l_item_rec.DISPLAY_SEQUENCE := to_number(l_token);
737          l_state := 30;
738       elsif (l_column = 'NODE_DISPLAY_FLAG') then
739          l_item_rec.NODE_DISPLAY_FLAG := l_token;
740          l_state := 30;
741       elsif (l_column = 'NODE_QUERY_FLAG') then
742          l_item_rec.NODE_QUERY_FLAG := l_token;
743          l_state := 30;
744       elsif (l_column = 'ATTRIBUTE_LABEL_LENGTH') then
745          l_item_rec.ATTRIBUTE_LABEL_LENGTH := to_number(l_token);
746          l_state := 30;
747       elsif (l_column = 'DISPLAY_VALUE_LENGTH') then
748          l_item_rec.DISPLAY_VALUE_LENGTH := to_number(l_token);
749          l_state := 30;
750       elsif (l_column = 'BOLD') then
751          l_item_rec.BOLD := l_token;
752          l_state := 30;
753       elsif (l_column = 'ITALIC') then
754          l_item_rec.ITALIC := l_token;
755          l_state := 30;
756       elsif (l_column = 'VERTICAL_ALIGNMENT') then
757          l_item_rec.VERTICAL_ALIGNMENT := l_token;
758          l_state := 30;
759       elsif (l_column = 'HORIZONTAL_ALIGNMENT') then
760          l_item_rec.HORIZONTAL_ALIGNMENT := l_token;
761          l_state := 30;
762       elsif (l_column = 'ITEM_STYLE') then
763          l_item_rec.ITEM_STYLE := l_token;
764          l_state := 30;
765       elsif (l_column = 'OBJECT_ATTRIBUTE_FLAG') then
766          l_item_rec.OBJECT_ATTRIBUTE_FLAG := l_token;
767          l_state := 30;
768       elsif (l_column = 'ICX_CUSTOM_CALL') then
769          l_item_rec.ICX_CUSTOM_CALL := l_token;
770          l_state := 30;
771       elsif (l_column = 'UPDATE_FLAG') then
772          l_item_rec.update_flag := l_token;
773          l_state := 30;
774       elsif (l_column = 'REQUIRED_FLAG') then
775          l_item_rec.required_flag := l_token;
776          l_state := 30;
777       elsif (l_column = 'SECURITY_CODE') then
778          l_item_rec.security_code := l_token;
779          l_state := 30;
780       elsif (l_column = 'DEFAULT_VALUE_VARCHAR2') then
781          l_item_rec.default_value_varchar2 := l_token;
782          l_state := 30;
783       elsif (l_column = 'DEFAULT_VALUE_NUMBER') then
784          l_item_rec.default_value_number := to_number(l_token);
785          l_state := 30;
786       elsif (l_column = 'DEFAULT_VALUE_DATE') then
787          l_item_rec.default_value_date := to_date(l_token,
788                                                AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
789          l_state := 30;
790       elsif (l_column = 'LOV_REGION') then
791          l_item_rec.lov_region_application_id := to_number(l_token);
792          l_state := 34;
793       elsif (l_column = 'LOV_FOREIGN_KEY_NAME') then
794          l_item_rec.lov_foreign_key_name := l_token;
795          l_state := 30;
796       elsif (l_column = 'LOV_ATTRIBUTE') then
797          l_item_rec.lov_attribute_application_id := to_number(l_token);
798          l_state := 34;
799       elsif (l_column = 'LOV_DEFAULT_FLAG') then
800          l_item_rec.lov_default_flag := l_token;
801          l_state := 30;
802       elsif (l_column = 'REGION_DEFAULTING_API_PKG') then
803          l_item_rec.REGION_defaulting_api_pkg := l_token;
804          l_state := 30;
805       elsif (l_column = 'REGION_DEFAULTING_API_PROC') then
806          l_item_rec.REGION_defaulting_api_proc := l_token;
807          l_state := 30;
808       elsif (l_column = 'REGION_VALIDATION_API_PKG') then
809          l_item_rec.REGION_validation_api_pkg := l_token;
810          l_state := 30;
811       elsif (l_column = 'REGION_VALIDATION_API_PROC') then
812          l_item_rec.REGION_validation_api_proc := l_token;
813          l_state := 30;
814       elsif (l_column = 'ORDER_SEQUENCE') then
815          l_item_rec.order_sequence := to_number(l_token);
816          l_state := 30;
817       elsif (l_column = 'INITIAL_SORT_SEQUENCE') then
818 	 l_item_rec.initial_sort_sequence := l_token;
819          l_state := 30;
820       elsif (l_column = 'CUSTOMIZATION_APPLICATION_ID') then
821          l_item_rec.customization_application_id := l_token;
822          l_state := 30;
823       elsif (l_column = 'CUSTOMIZATION_CODE') then
824          l_item_rec.customization_code := l_token;
825          l_state := 30;
826       elsif (l_column = 'ORDER_DIRECTION') then
827          l_item_rec.ORDER_DIRECTION := l_token;
828          l_state := 30;
829       elsif (l_column = 'SUBMIT') then
830          l_item_rec.SUBMIT := l_token;
831          l_state := 30;
832       elsif (l_column = 'ENCRYPT') then
833          l_item_rec.ENCRYPT := l_token;
834          l_state := 30;
835       elsif (l_column = 'DISPLAY_HEIGHT') then
836          l_item_rec.DISPLAY_HEIGHT := to_number(l_token);
837          l_state := 30;
838       elsif (l_column = 'CSS_CLASS_NAME') then
839          l_item_rec.CSS_CLASS_NAME := l_token;
840          l_state := 30;
841       elsif (l_column = 'VIEW_USAGE_NAME') then
842          l_item_rec.VIEW_USAGE_NAME := l_token;
843          l_state := 30;
844       elsif (l_column = 'VIEW_ATTRIBUTE_NAME') then
845          l_item_rec.VIEW_ATTRIBUTE_NAME := l_token;
846          l_state := 30;
847       elsif (l_column = 'NESTED_REGION_APPLICATION_ID') then
848          l_item_rec.NESTED_REGION_APPLICATION_ID := to_number(l_token);
849          l_state := 30;
850       elsif (l_column = 'NESTED_REGION_CODE') then
851          l_item_rec.NESTED_REGION_CODE := l_token;
852          l_state := 30;
853       elsif (l_column = 'URL') then
854          l_item_rec.URL := l_token;
855          l_state := 30;
856       elsif (l_column = 'POPLIST_VIEWOBJECT') then
857          l_item_rec.POPLIST_VIEWOBJECT := l_token;
858          l_state := 30;
859       elsif (l_column = 'POPLIST_DISPLAY_ATTRIBUTE') then
860          l_item_rec.POPLIST_DISPLAY_ATTR := l_token;
861          l_state := 30;
862       elsif (l_column = 'POPLIST_VALUE_ATTRIBUTE') then
863          l_item_rec.POPLIST_VALUE_ATTR := l_token;
864          l_state := 30;
865       elsif (l_column = 'IMAGE_FILE_NAME') then
866          l_item_rec.IMAGE_FILE_NAME := l_token;
867          l_state := 30;
868       elsif (l_column = 'ITEM_NAME') then
869          l_item_rec.ITEM_NAME := l_token;
870          l_state := 30;
871       elsif (l_column = 'CSS_LABEL_CLASS_NAME') then
872          l_item_rec.CSS_LABEL_CLASS_NAME := l_token;
873          l_state := 30;
874       elsif (l_column = 'MENU_NAME') then
875          l_item_rec.MENU_NAME := l_token;
876          l_state := 30;
877       elsif (l_column = 'FLEXFIELD_NAME') then
878          l_item_rec.FLEXFIELD_NAME := l_token;
879          l_state := 30;
880       elsif (l_column = 'FLEXFIELD_APPLICATION_ID') then
881          l_item_rec.FLEXFIELD_APPLICATION_ID := l_token;
882          l_state := 30;
883       elsif (l_column = 'TABULAR_FUNCTION_CODE') then
884          l_item_rec.TABULAR_FUNCTION_CODE := l_token;
885          l_state := 30;
886       elsif (l_column = 'TIP_TYPE') then
887          l_item_rec.TIP_TYPE := l_token;
888          l_state := 30;
889       elsif (l_column = 'TIP_MESSAGE_NAME') then
890          l_item_rec.TIP_MESSAGE_NAME := l_token;
891          l_state := 30;
892       elsif (l_column = 'TIP_MESSAGE_APPLICATION_ID') then
893          l_item_rec.TIP_MESSAGE_APPLICATION_ID := l_token;
894          l_state := 30;
895       elsif (l_column = 'FLEX_SEGMENT_LIST') then
896          l_item_rec.FLEX_SEGMENT_LIST := l_token;
897          l_state := 30;
898       elsif (l_column = 'ENTITY_ID') then
899          l_item_rec.ENTITY_ID := l_token;
900          l_state := 30;
901       elsif (l_column = 'ANCHOR') then
902          l_item_rec.ANCHOR := l_token;
903          l_state := 30;
904       elsif (l_column = 'POPLIST_VIEW_USAGE_NAME') then
905          l_item_rec.POPLIST_VIEW_USAGE_NAME := l_token;
906          l_state := 30;
907       elsif (l_column = 'USER_CUSTOMIZABLE') then
908          l_item_rec.USER_CUSTOMIZABLE := l_token;
909          l_state := 30;
910       elsif (l_column = 'SORTBY_VIEW_ATTRIBUTE_NAME') then
911          l_item_rec.SORTBY_VIEW_ATTRIBUTE_NAME := l_token;
912          l_state := 30;
913       elsif (l_column = 'ADMIN_CUSTOMIZABLE') then
914 	 l_item_rec.ADMIN_CUSTOMIZABLE := l_token;
915 	 l_state := 30;
916       elsif (l_column = 'INVOKE_FUNCTION_NAME') then
917 	 l_item_rec.INVOKE_FUNCTION_NAME := l_token;
918 	 l_state := 30;
919       elsif (l_column = 'EXPANSION') then
920          l_item_rec.EXPANSION := l_token;
921          l_state := 30;
922       elsif (l_column = 'ALS_MAX_LENGTH') then
923          l_item_rec.ALS_MAX_LENGTH := l_token;
924          l_state := 30;
925       elsif (l_column = 'ATTRIBUTE_CATEGORY') then
926          l_item_rec.attribute_category := l_token;
927          l_state := 30;
928       elsif (l_column = 'ATTRIBUTE1') then
929          l_item_rec.attribute1 := l_token;
930          l_state := 30;
931       elsif (l_column = 'ATTRIBUTE2') then
932          l_item_rec.attribute2 := l_token;
933          l_state := 30;
934       elsif (l_column = 'ATTRIBUTE3') then
935          l_item_rec.attribute3 := l_token;
936          l_state := 30;
937       elsif (l_column = 'ATTRIBUTE4') then
938          l_item_rec.attribute4 := l_token;
939          l_state := 30;
940       elsif (l_column = 'ATTRIBUTE5') then
941          l_item_rec.attribute5 := l_token;
942          l_state := 30;
943       elsif (l_column = 'ATTRIBUTE6') then
944          l_item_rec.attribute6 := l_token;
945          l_state := 30;
946       elsif (l_column = 'ATTRIBUTE7') then
947          l_item_rec.attribute7 := l_token;
948          l_state := 30;
949       elsif (l_column = 'ATTRIBUTE8') then
950          l_item_rec.attribute8 := l_token;
951          l_state := 30;
952       elsif (l_column = 'ATTRIBUTE9') then
953          l_item_rec.attribute9 := l_token;
954          l_state := 30;
955       elsif (l_column = 'ATTRIBUTE10') then
956          l_item_rec.attribute10 := l_token;
957          l_state := 30;
958       elsif (l_column = 'ATTRIBUTE11') then
959          l_item_rec.attribute11 := l_token;
960          l_state := 30;
961       elsif (l_column = 'ATTRIBUTE12') then
962          l_item_rec.attribute12 := l_token;
963          l_state := 30;
964       elsif (l_column = 'ATTRIBUTE13') then
965          l_item_rec.attribute13 := l_token;
966          l_state := 30;
967       elsif (l_column = 'ATTRIBUTE14') then
968          l_item_rec.attribute14 := l_token;
969          l_state := 30;
970       elsif (l_column = 'ATTRIBUTE15') then
971          l_item_rec.attribute15 := l_token;
972          l_state := 30;
973       elsif (l_column = 'CREATED_BY') then
974          l_item_rec.created_by := to_number(l_token);
975          l_state := 30;
976       elsif (l_column = 'CREATION_DATE') then
977          l_item_rec.creation_date := to_date(l_token,
978                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
979          l_state := 30;
980       elsif (l_column = 'LAST_UPDATED_BY') then
981          l_item_rec.last_updated_by := to_number(l_token);
982          l_state := 30;
983       elsif (l_column = 'OWNER') then
984          l_item_rec.last_updated_by := FND_LOAD_UTIL.OWNER_ID(l_token);
985          l_state := 30;
986       elsif (l_column = 'LAST_UPDATE_DATE') then
987          l_item_rec.last_update_date := to_date(l_token,
988                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
989          l_state := 30;
990       elsif (l_column = 'LAST_UPDATE_LOGIN') then
991          l_item_rec.last_update_login := to_number(l_token);
992          l_state := 30;
993       elsif (l_column = 'ATTRIBUTE_LABEL_LONG') then
994          l_item_rec.ATTRIBUTE_LABEL_LONG := l_token;
995          l_state := 30;
996       elsif (l_column = 'ATTRIBUTE_LABEL_SHORT') then
997          l_item_rec.ATTRIBUTE_LABEL_SHORT := l_token;
998          l_state := 30;
999       elsif (l_column = 'DESCRIPTION') then
1000          l_item_rec.DESCRIPTION := l_token;
1001          l_state := 30;
1002       else
1003         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1004           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1005           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1006           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1007           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column || ' value');
1008           FND_MSG_PUB.Add;
1009         end if;
1010         raise FND_API.G_EXC_ERROR;
1011       end if;
1012     elsif (l_state = 34) then
1013       if (l_column = 'LOV_REGION') then
1014          l_item_rec.lov_region_code := l_token;
1015          l_state := 30;
1016       elsif (l_column = 'LOV_ATTRIBUTE') then
1017          l_item_rec.lov_attribute_code := l_token;
1018          l_state := 30;
1019       else
1020         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1021           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
1022           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1023           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1024           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column);
1025           FND_MSG_PUB.Add;
1026         end if;
1027         raise FND_API.G_EXC_ERROR;
1028       end if;
1029     elsif (l_state = 39) then
1030       if (l_token = 'REGION_ITEM') then
1031         l_value_count := null;
1032         l_state := 10;
1033         l_item_index := l_item_index + 1;
1034         l_item_tbl(l_item_index) := l_item_rec;
1035       else
1036         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1037           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1038           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1039           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1040           FND_MESSAGE.SET_TOKEN('EXPECTED', 'REGION_ITEM');
1041           FND_MSG_PUB.Add;
1042         end if;
1043         raise FND_API.G_EXC_ERROR;
1044       end if;
1045 
1046     --
1047     -- REGION_LOV_RELATION (states 100 - 139)
1048     --
1049     elsif (l_state = 100) then
1050       if (l_token is not null) then
1051         l_lov_relation_rec.lov_region_appl_id := to_number(l_token);
1052         l_state := 101;
1053       else
1054         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1055           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
1056           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1057           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1058           FND_MESSAGE.SET_TOKEN('EXPECTED', 'LOV_REGION_APPL_ID');
1059           FND_MSG_PUB.Add;
1060         end if;
1061         raise FND_API.G_EXC_ERROR;
1062       end if;
1063     elsif (l_state = 101) then
1064       if (l_token is not null) then
1065         l_lov_relation_rec.lov_region_code := l_token;
1066         l_value_count := null;
1067         l_state := 102;
1068       else
1069         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1070           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
1071           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1072           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1073           FND_MESSAGE.SET_TOKEN('EXPECTED', 'LOV_REGION_CODE');
1074           FND_MSG_PUB.Add;
1075         end if;
1076         raise FND_API.G_EXC_ERROR;
1077       end if;
1078     elsif (l_state = 102) then
1079       if (l_token is not null) then
1080         l_lov_relation_rec.lov_attribute_appl_id := to_number(l_token);
1081         l_state := 103;
1082       else
1083         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1084           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
1085           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1086           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1087           FND_MESSAGE.SET_TOKEN('EXPECTED', 'LOV_ATTRIBUTE_APPL_ID');
1088           FND_MSG_PUB.Add;
1089         end if;
1090         raise FND_API.G_EXC_ERROR;
1091       end if;
1092     elsif (l_state = 103) then
1093       if (l_token is not null) then
1094         l_lov_relation_rec.lov_attribute_code := l_token;
1095         l_value_count := null;
1096         l_state := 104;
1097       else
1098         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1099           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
1100           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1101           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1102           FND_MESSAGE.SET_TOKEN('EXPECTED', 'LOV_ATTRIBUTE_CODE');
1103           FND_MSG_PUB.Add;
1104         end if;
1105         raise FND_API.G_EXC_ERROR;
1106       end if;
1107     elsif (l_state = 104) then
1108       if (l_token is not null) then
1109         l_lov_relation_rec.base_attribute_appl_id := to_number(l_token);
1110         l_state := 105;
1111       else
1112         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1113           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
1114           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1115           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1116           FND_MESSAGE.SET_TOKEN('EXPECTED', 'BASE_ATTRIBUTE_APPL_ID');
1117           FND_MSG_PUB.Add;
1118         end if;
1119         raise FND_API.G_EXC_ERROR;
1120       end if;
1121     elsif (l_state = 105) then
1122       if (l_token is not null) then
1123         l_lov_relation_rec.base_attribute_code := l_token;
1124         l_value_count := null;
1125         l_state := 106;
1126       else
1127         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1128           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
1129           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1130           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1131           FND_MESSAGE.SET_TOKEN('EXPECTED', 'BASE_ATTRIBUTE_CODE');
1132           FND_MSG_PUB.Add;
1133         end if;
1134         raise FND_API.G_EXC_ERROR;
1135       end if;
1136     elsif (l_state = 106) then
1137       if (l_token is not null) then
1138         l_lov_relation_rec.direction_flag := l_token;
1139         l_value_count := null;
1140         l_state := 130;
1141       else
1142         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1143           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
1144           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1145           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1146           FND_MESSAGE.SET_TOKEN('EXPECTED', 'DIRECTION_FLAG');
1147           FND_MSG_PUB.Add;
1148         end if;
1149         raise FND_API.G_EXC_ERROR;
1150       end if;
1151     elsif (l_state = 130) then
1152       if (l_token = 'END') then
1153         l_state := 139;
1154 	  elsif ( l_token = 'BASE_REGION_APPL_ID' ) or
1155 		( l_token = 'BASE_REGION_CODE' ) or
1156 		( l_token = 'REQUIRED_FLAG' ) or
1157 		(l_token = 'CREATED_BY') or
1158 		(l_token = 'CREATION_DATE') or
1159 		(l_token = 'LAST_UPDATED_BY') or
1160                 (l_token = 'OWNER') or
1161 		(l_token = 'LAST_UPDATE_DATE') or
1162 		(l_token = 'LAST_UPDATE_LOGIN') then
1163         l_column := l_token;
1164         l_state := 131;
1165       else
1166       --
1167       -- error if not expecting attribute values added by the translation team
1168       -- or if we have read in more than a certain number of values
1169       -- for the same DB column
1170       --
1171         l_value_count := l_value_count + 1;
1172         --
1173         -- save second value. It will be the token with error if
1174         -- it turns out that there is a parse error on this line.
1175         --
1176         if (l_value_count = 2) then
1177           l_saved_token := l_token;
1178         end if;
1179         if (l_value_count > AK_ON_OBJECTS_PUB.G_MAX_NUM_LOADER_VALUES) or
1180            (l_value_count is null) then
1181           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1182             FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_EFIELD');
1183             FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1184             if (l_value_count is null) then
1185               FND_MESSAGE.SET_TOKEN('TOKEN', l_token);
1186             else
1187               FND_MESSAGE.SET_TOKEN('TOKEN',l_saved_token);
1188             end if;
1189             FND_MESSAGE.SET_TOKEN('EXPECTED','REGION_LOV_RELATION');
1190             FND_MSG_PUB.Add;
1191           end if;
1192           raise FND_API.G_EXC_ERROR;
1193         end if;
1194       end if;
1195     elsif (l_state = 131) then
1196       if (l_token = '=') then
1197         l_state := 132;
1198       else
1199         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1200           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1201           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1202           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1203           FND_MESSAGE.SET_TOKEN('EXPECTED', '=');
1204           FND_MSG_PUB.Add;
1205         end if;
1206         raise FND_API.G_EXC_ERROR;
1207       end if;
1208     elsif (l_state = 132) then
1209       l_value_count := 1;
1210       if (l_column = 'BASE_REGION_APPL_ID') then
1211         l_lov_relation_rec.BASE_REGION_APPL_ID := to_number(l_token);
1212         l_state := 130;
1213       elsif (l_column = 'BASE_REGION_CODE') then
1214          l_lov_relation_rec.BASE_REGION_CODE := l_token;
1215          l_state := 130;
1216       elsif (l_column = 'REQUIRED_FLAG') then
1217          l_lov_relation_rec.REQUIRED_FLAG := l_token;
1218          l_state := 130;
1219       elsif (l_column = 'CREATED_BY') then
1220          l_lov_relation_rec.created_by := to_number(l_token);
1221          l_state := 130;
1222       elsif (l_column = 'CREATION_DATE') then
1223          l_lov_relation_rec.creation_date := to_date(l_token,
1224                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
1225          l_state := 130;
1226       elsif (l_column = 'LAST_UPDATED_BY') then
1227          l_lov_relation_rec.last_updated_by := to_number(l_token);
1228          l_state := 130;
1229       elsif (l_column = 'OWNER') then
1230          l_lov_relation_rec.last_updated_by := FND_LOAD_UTIL.OWNER_ID(l_token);
1231          l_state := 130;
1232       elsif (l_column = 'LAST_UPDATE_DATE') then
1233          l_lov_relation_rec.last_update_date := to_date(l_token,
1234                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
1235          l_state := 130;
1236       elsif (l_column = 'LAST_UPDATE_LOGIN') then
1237          l_lov_relation_rec.last_update_login := to_number(l_token);
1238          l_state := 130;
1239       else
1240         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1241           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1242           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1243           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1244           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column || ' value');
1245           FND_MSG_PUB.Add;
1246         end if;
1247         raise FND_API.G_EXC_ERROR;
1248       end if;
1249     elsif (l_state = 139) then
1250       if (l_token = 'REGION_LOV_RELATION') then
1251         l_value_count := null;
1252         l_state := 30;
1253         l_lov_relation_index := l_lov_relation_index + 1;
1254         l_lov_relation_tbl(l_lov_relation_index) := l_lov_relation_rec;
1255       else
1256         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1257           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1258           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1259           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1260           FND_MESSAGE.SET_TOKEN('EXPECTED', 'REGION_LOV_RELATION');
1261           FND_MSG_PUB.Add;
1262         end if;
1263         raise FND_API.G_EXC_ERROR;
1264       end if;
1265 
1266     --
1267     -- CATEGORY_USAGE (states 200 - 239)
1268     --
1269     elsif (l_state = 200) then
1270       if (l_token is not null) then
1271         l_category_usage_rec.category_id := to_number(l_token);
1272 --	select name into l_category_usage_rec.category_name from fnd_document_categories where category_id = l_category_usage_rec.category_id;
1273         l_value_count := null;
1274         l_state := 230;
1275       else
1276         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1277           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
1278           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1279           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1280           FND_MESSAGE.SET_TOKEN('EXPECTED', 'CATEGORY_ID');
1281           FND_MSG_PUB.Add;
1282         end if;
1283         raise FND_API.G_EXC_ERROR;
1284       end if;
1285     elsif (l_state = 230) then
1286       if (l_token = 'END') then
1287         l_state := 239;
1288 	elsif (l_token = 'CATEGORY_NAME') or
1289 		(l_token = 'APPLICATION_ID') or
1290 		(l_token = 'SHOW_ALL') or
1291                         (l_token = 'CREATED_BY') or
1292                         (l_token = 'CREATION_DATE') or
1293                         (l_token = 'LAST_UPDATED_BY') or
1294                         (l_token = 'OWNER') or
1295                         (l_token = 'LAST_UPDATE_DATE') or
1296                         (l_token = 'LAST_UPDATE_LOGIN') then
1297 	l_column := l_token;
1298 	l_state := 231;
1299       else
1300       --
1301       -- error if not expecting attribute values added by the translation team
1302       -- or if we have read in more than a certain number of values
1303       -- for the same DB column
1304       --
1305         l_value_count := l_value_count + 1;
1306         --
1307         -- save second value. It will be the token with error if
1308         -- it turns out that there is a parse error on this line.
1309         --
1310         if (l_value_count = 2) then
1311           l_saved_token := l_token;
1312         end if;
1313         if (l_value_count > AK_ON_OBJECTS_PUB.G_MAX_NUM_LOADER_VALUES) or
1314            (l_value_count is null) then
1315           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1316             FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_EFIELD');
1317             FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1318             if (l_value_count is null) then
1319               FND_MESSAGE.SET_TOKEN('TOKEN', l_token);
1320             else
1321               FND_MESSAGE.SET_TOKEN('TOKEN',l_saved_token);
1322             end if;
1323             FND_MESSAGE.SET_TOKEN('EXPECTED','CATEGORY_USAGE');
1324             FND_MSG_PUB.Add;
1325           end if;
1326           raise FND_API.G_EXC_ERROR;
1327         end if;
1328       end if;
1329     elsif (l_state = 231) then
1330       if (l_token = '=') then
1331         l_state := 232;
1332       else
1333         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1334           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1335           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1336           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1337           FND_MESSAGE.SET_TOKEN('EXPECTED', '=');
1338           FND_MSG_PUB.Add;
1339         end if;
1340         raise FND_API.G_EXC_ERROR;
1341       end if;
1342     elsif (l_state = 232) then
1343       l_value_count := 1;
1344       if (l_column = 'CATEGORY_NAME') then
1345 	 l_category_usage_rec.CATEGORY_NAME := l_token;
1346 	 l_state := 230;
1347       elsif (l_column = 'APPLICATION_ID') then
1348          l_category_usage_rec.APPLICATION_ID := to_number(l_token);
1349          l_state := 230;
1350       elsif (l_column = 'SHOW_ALL') then
1351          l_category_usage_rec.SHOW_ALL := l_token;
1352          l_state := 230;
1353       elsif (l_column = 'CREATED_BY') then
1354          l_category_usage_rec.created_by := to_number(l_token);
1355          l_state := 230;
1356       elsif (l_column = 'CREATION_DATE') then
1357          l_category_usage_rec.creation_date := to_date(l_token,
1358                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
1359          l_state := 230;
1360       elsif (l_column = 'LAST_UPDATED_BY') then
1361          l_category_usage_rec.last_updated_by := to_number(l_token);
1362          l_state := 230;
1363       elsif (l_column = 'OWNER') then
1364          l_category_usage_rec.last_updated_by := FND_LOAD_UTIL.OWNER_ID(l_token);
1365          l_state := 230;
1366       elsif (l_column = 'LAST_UPDATE_DATE') then
1367          l_category_usage_rec.last_update_date := to_date(l_token,
1368                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
1369          l_state := 230;
1370       elsif (l_column = 'LAST_UPDATE_LOGIN') then
1371          l_category_usage_rec.last_update_login := to_number(l_token);
1372          l_state := 230;
1373       else
1374         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1375           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1376           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1377           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1378           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column || ' value');
1379           FND_MSG_PUB.Add;
1380         end if;
1381         raise FND_API.G_EXC_ERROR;
1382       end if;
1383     elsif (l_state = 239) then
1384       if (l_token = 'CATEGORY_USAGE') then
1385         l_value_count := null;
1386         l_state := 30;
1387         l_category_usage_index := l_category_usage_index + 1;
1388         l_category_usage_tbl(l_category_usage_index) := l_category_usage_rec;
1389       else
1390         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1391           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1392           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1393           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1394           FND_MESSAGE.SET_TOKEN('EXPECTED', 'CATEGORY_USAGE');
1395           FND_MSG_PUB.Add;
1396         end if;
1397         raise FND_API.G_EXC_ERROR;
1398       end if;
1399 
1400     --
1401     -- REGION_GRAPH (states 300 - 339)
1402     --
1403     elsif (l_state = 300) then
1404       if (l_token is not null) then
1405 --        l_graph_rec.graph_number := to_number(l_token);
1406  	l_state := 310;
1407       else
1408         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1409           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
1410           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1411           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1412           FND_MESSAGE.SET_TOKEN('EXPECTED', 'GRAPH_NUMBER');
1413           FND_MSG_PUB.Add;
1414         end if;
1415         raise FND_API.G_EXC_ERROR;
1416       end if;
1417     elsif (l_state = 310) then
1418       if (l_token = 'END') then
1419         l_state := 319;
1420           elsif (l_token = 'BEGIN') then
1421                 l_state := 13;
1422       elsif (l_token = 'GRAPH_STYLE') or
1423 		(l_token = 'DISPLAY_FLAG') or
1424 		(l_token = 'DEPTH_RADIUS') or
1425 		(l_token = 'GRAPH_TITLE') or
1426 		(l_token = 'Y_AXIS_LABEL') or
1427                         (l_token = 'CREATED_BY') or
1428                         (l_token = 'CREATION_DATE') or
1429                         (l_token = 'LAST_UPDATED_BY') or
1430                         (l_token = 'LAST_UPDATE_DATE') or
1431                         (l_token = 'LAST_UPDATE_LOGIN') then
1432 	l_column := l_token;
1433 	l_state := 311;
1434       else
1435       --
1436       -- error if not expecting attribute values added by the translation team
1437       -- or if we have read in more than a certain number of values
1438       -- for the same DB column
1439       --
1440         l_value_count := l_value_count + 1;
1441         --
1442         -- save second value. It will be the token with error if
1443         -- it turns out that there is a parse error on this line.
1444         --
1445         if (l_value_count = 2) then
1446           l_saved_token := l_token;
1447         end if;
1448         if (l_value_count > AK_ON_OBJECTS_PUB.G_MAX_NUM_LOADER_VALUES) or
1449            (l_value_count is null) then
1450           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1451             FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_EFIELD');
1452             FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1453             if (l_value_count is null) then
1454               FND_MESSAGE.SET_TOKEN('TOKEN', l_token);
1455             else
1456               FND_MESSAGE.SET_TOKEN('TOKEN',l_saved_token);
1457             end if;
1458             FND_MESSAGE.SET_TOKEN('EXPECTED','REGION_GRAPH');
1459             FND_MSG_PUB.Add;
1460           end if;
1461           raise FND_API.G_EXC_ERROR;
1462         end if;
1463       end if;
1464     elsif (l_state = 311) then
1465       if (l_token = '=') then
1466         l_state := 312;
1467       else
1468         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1469           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1470           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1471           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1472           FND_MESSAGE.SET_TOKEN('EXPECTED', '=');
1473           FND_MSG_PUB.Add;
1474         end if;
1475         raise FND_API.G_EXC_ERROR;
1476       end if;
1477     elsif (l_state = 312) then
1478       l_value_count := 1;
1479       if (l_column = 'GRAPH_STYLE') then
1480 --	l_graph_rec.GRAPH_STYLE := to_number(l_token);
1481 	l_state := 310;
1482       elsif (l_column = 'DISPLAY_FLAG') then
1483 --	l_graph_rec.DISPLAY_FLAG := l_token;
1484 	l_state := 310;
1485       elsif (l_column = 'DEPTH_RADIUS') then
1486 --	l_graph_rec.DEPTH_RADIUS := to_number(l_token);
1487    	l_state := 310;
1488       elsif (l_column = 'GRAPH_TITLE') then
1489 --	l_graph_rec.GRAPH_TITLE := l_token;
1490 	l_state := 310;
1491       elsif (l_column = 'Y_AXIS_LABEL') then
1492 --	l_graph_rec.Y_AXIS_LABEL := l_token;
1493 	l_state := 310;
1494       elsif (l_column = 'CREATED_BY') then
1495 --         l_graph_rec.created_by := to_number(l_token);
1496          l_state := 310;
1497       elsif (l_column = 'CREATION_DATE') then
1498 --         l_graph_rec.creation_date := to_date(l_token,
1499 --                                        AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
1500          l_state := 310;
1501       elsif (l_column = 'LAST_UPDATED_BY') then
1502 --         l_graph_rec.last_updated_by := to_number(l_token);
1503          l_state := 310;
1504       elsif (l_column = 'LAST_UPDATE_DATE') then
1505 --         l_graph_rec.last_update_date := to_date(l_token,
1506 --                                        AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
1507          l_state := 310;
1508       elsif (l_column = 'LAST_UPDATE_LOGIN') then
1509 --         l_graph_rec.last_update_login := to_number(l_token);
1510          l_state := 310;
1511       else
1512         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1513           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1514           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1515           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1516           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column || ' value');
1517           FND_MSG_PUB.Add;
1518         end if;
1519         raise FND_API.G_EXC_ERROR;
1520       end if;
1521     elsif (l_state = 319) then
1522       if (l_token = 'REGION_GRAPH') then
1523         l_value_count := null;
1524         l_state := 10;
1525 --        l_graph_index := l_graph_index + 1;
1526 --	l_graph_tbl(l_graph_index) := l_graph_rec;
1527       else
1528         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1529           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1530           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1531           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1532           FND_MESSAGE.SET_TOKEN('EXPECTED', 'REGION_GRAPH');
1533           FND_MSG_PUB.Add;
1534         end if;
1535         raise FND_API.G_EXC_ERROR;
1536       end if;
1537 
1538     --
1539     -- REGION_GRAPH_COLUMN (400 - 449)
1540     --
1541     elsif (l_state = 400) then
1542       if (l_token is not null) then
1543 --        l_graph_column_rec.attribute_application_id := to_number(l_token);
1544         l_state := 401;
1545       else
1546         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1547           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
1548           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1549           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1550           FND_MESSAGE.SET_TOKEN('EXPECTED', 'ATTRIBUTE_APPLICATION_ID');
1551           FND_MSG_PUB.Add;
1552         end if;
1553         raise FND_API.G_EXC_ERROR;
1554       end if;
1555     elsif (l_state = 401) then
1556       if (l_token is not null) then
1557 --        l_graph_column_rec.attribute_code := l_token;
1558         l_value_count := null;
1559         l_state := 410;
1560       else
1561         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1562           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
1563           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1564           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1565           FND_MESSAGE.SET_TOKEN('EXPECTED', 'ATTRIBUTE_CODE');
1566           FND_MSG_PUB.Add;
1567         end if;
1568         raise FND_API.G_EXC_ERROR;
1569       end if;
1570     elsif (l_state = 410) then
1571       if (l_token = 'END') then
1572         l_state := 419;
1573       else
1574       --
1575       -- error if not expecting attribute values added by the translation team
1576       -- or if we have read in more than a certain number of values
1577       -- for the same DB column
1578       --
1579         l_value_count := l_value_count + 1;
1580         --
1581         -- save second value. It will be the token with error if
1582         -- it turns out that there is a parse error on this line.
1583         --
1584         if (l_value_count = 2) then
1585           l_saved_token := l_token;
1586         end if;
1587         if (l_value_count > AK_ON_OBJECTS_PUB.G_MAX_NUM_LOADER_VALUES) or
1588            (l_value_count is null) then
1589           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1590             FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_EFIELD');
1591             FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1592             if (l_value_count is null) then
1593               FND_MESSAGE.SET_TOKEN('TOKEN', l_token);
1594             else
1595               FND_MESSAGE.SET_TOKEN('TOKEN',l_saved_token);
1596             end if;
1597             FND_MESSAGE.SET_TOKEN('EXPECTED','REGION_GRAPH_COLUMN');
1598             FND_MSG_PUB.Add;
1599           end if;
1600           raise FND_API.G_EXC_ERROR;
1601         end if;
1602       end if;
1603     elsif (l_state = 419) then
1604       if (l_token = 'REGION_GRAPH_COLUMN') then
1605         l_value_count := null;
1606         l_state := 310;
1607 --        l_graph_column_index := l_graph_column_index + 1;
1608 --	l_graph_column_tbl(l_graph_column_index) := l_graph_column_rec;
1609       else
1610         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1611           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1612           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1613           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1614           FND_MESSAGE.SET_TOKEN('EXPECTED', 'REGION_GRAPH_COLUMN');
1615           FND_MSG_PUB.Add;
1616         end if;
1617         raise FND_API.G_EXC_ERROR;
1618       end if;
1619 
1620     end if; -- if l_state = ...
1621 
1622     -- Get rid of leading white spaces, so that buffer would become
1623     -- null if the only thing in it are white spaces
1624     l_buffer := LTRIM(l_buffer);
1625 
1626     -- Get the next non-blank, non-comment line if current line is
1627     -- fully parsed
1628     while (l_buffer is null and l_eof_flag = 'N' and p_index <=  AK_ON_OBJECTS_PVT.G_UPL_TABLE_NUM) loop
1629       AK_ON_OBJECTS_PVT.READ_LINE (
1630         p_return_status => l_return_status,
1631         p_index => p_index,
1632         p_buffer => l_buffer,
1633         p_lines_read => l_lines_read,
1634         p_eof_flag => l_eof_flag,
1635         p_upl_loader_cur => p_upl_loader_cur
1636       );
1637       if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
1638          (l_return_status = FND_API.G_RET_STS_ERROR) then
1639           RAISE FND_API.G_EXC_ERROR;
1640       end if;
1641       l_line_num := l_line_num + l_lines_read;
1642       --
1643       -- trim leading spaces and discard comment lines
1644       --
1645       l_buffer := LTRIM(l_buffer);
1646       if (SUBSTR(l_buffer, 1, 1) = '#') then
1647         l_buffer := null;
1648       end if;
1649     end loop;
1650 
1651   end LOOP;
1652 
1653   -- If the loops end in a state other then at the end of a region
1654   -- (state 0) or when the beginning of another business object was
1655   -- detected, then the file must have ended prematurely, which is an error
1656   if (l_state <> 0) and (l_more_region) then
1657     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1658       FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1659       FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1660       FND_MESSAGE.SET_TOKEN('TOKEN', 'END OF FILE');
1661       FND_MESSAGE.SET_TOKEN('EXPECTED', null);
1662       FND_MSG_PUB.Add;
1663     end if;
1664     --dbms_output.put_line('Unexpected END OF FILE: state is ' ||
1665     --            to_char(l_state));
1666     raise FND_API.G_EXC_ERROR;
1667   end if;
1668 
1669   --
1670   -- create or update all regions to the database
1671   --
1672   if (l_region_tbl.count > 0) then
1673     for l_index in l_region_tbl.FIRST .. l_region_tbl.LAST loop
1674       if (l_region_tbl.exists(l_index)) then
1675         if AK_REGION_PVT.REGION_EXISTS (
1676             p_api_version_number => 1.0,
1677             p_return_status => l_return_status,
1678             p_region_application_id =>
1679                                l_region_tbl(l_index).region_application_id,
1680             p_region_code => l_region_tbl(l_index).region_code) then
1681                /* REMOVE DELETE FUNCTIONALITY DURING UPLOAD
1682 		--Delete all region items under this region only when the
1683 		--jlt file was extracted in the REGION mode
1684 		if (AK_UPLOAD_GRP.G_EXTRACT_OBJ = 'REGION') then
1685 		   for l_item_rec in l_get_region_item_csr(
1686 		      l_region_tbl(l_index).region_application_id,
1687 		      l_region_tbl(l_index).region_code) LOOP
1688 			AK_REGION_PVT.DELETE_ITEM (
1689 			p_validation_level => p_validation_level,
1690 			p_api_version_number => 1.0,
1691 			p_msg_count => l_msg_count,
1692               		p_msg_data => l_msg_data,
1693 			p_return_status => l_return_status,
1694 			p_region_application_id =>
1695 				l_region_tbl(l_index).region_application_id,
1696 			p_region_code => l_region_tbl(l_index).region_code,
1697 			p_attribute_application_id =>
1698 				l_item_rec.attribute_application_id,
1699 			p_attribute_code => l_item_rec.attribute_code,
1700 			p_delete_cascade => 'N');
1701 		   end loop;
1702 		end if;
1703           */
1704           --
1705           -- Update Regions only if G_UPDATE_MODE is TRUE
1706           --
1707           if (AK_UPLOAD_GRP.G_UPDATE_MODE) then
1708             AK_REGION_PVT.UPDATE_REGION (
1709               p_validation_level => p_validation_level,
1710               p_api_version_number => 1.0,
1711               p_msg_count => l_msg_count,
1712               p_msg_data => l_msg_data,
1713               p_return_status => l_return_status,
1714               p_region_application_id =>
1715                                   l_region_tbl(l_index).region_application_id,
1716               p_region_code => l_region_tbl(l_index).region_code,
1717               p_database_object_name =>l_region_tbl(l_index).database_object_name,
1718               p_region_style => l_region_tbl(l_index).region_style,
1719               p_num_columns => l_region_tbl(l_index).num_columns,
1720               p_icx_custom_call => l_region_tbl(l_index).icx_custom_call,
1721               p_region_defaulting_api_pkg =>
1722                  l_region_tbl(l_index).region_defaulting_api_pkg,
1723               p_region_defaulting_api_proc =>
1724                  l_region_tbl(l_index).region_defaulting_api_proc,
1725               p_region_validation_api_pkg =>
1726                  l_region_tbl(l_index).region_validation_api_pkg,
1727               p_region_validation_api_proc =>
1728                  l_region_tbl(l_index).region_validation_api_proc,
1729               p_appmodule_object_type =>
1730                  l_region_tbl(l_index).applicationmodule_object_type,
1731               p_num_rows_display =>
1732                  l_region_tbl(l_index).num_rows_display,
1733               p_region_object_type =>
1734                  l_region_tbl(l_index).region_object_type,
1735               p_image_file_name =>
1736                  l_region_tbl(l_index).image_file_name,
1737               p_isform_flag => l_region_tbl(l_index).isform_flag,
1738 			  p_help_target => l_region_tbl(l_index).help_target,
1739 	  p_style_sheet_filename => l_region_tbl(l_index).style_sheet_filename,
1740 			  p_version => l_region_tbl(l_index).version,
1741 			  p_applicationmodule_usage_name => l_region_tbl(l_index).applicationmodule_usage_name,
1742 	  p_add_indexed_children => l_region_tbl(l_index).add_indexed_children,
1743 	  p_stateful_flag => l_region_tbl(l_index).stateful_flag,
1744 	  p_function_name => l_region_tbl(l_index).function_name,
1745 	  p_children_view_usage_name => l_region_tbl(l_index).children_view_usage_name,
1746 	 p_search_panel => l_region_tbl(l_index).search_panel,
1747 	 p_advanced_search_panel => l_region_tbl(l_index).advanced_search_panel,
1748 	 p_customize_panel => l_region_tbl(l_index).customize_panel,
1749 	 p_default_search_panel => l_region_tbl(l_index).default_search_panel,
1750 	 p_results_based_search => l_region_tbl(l_index).results_based_search,
1751 	 p_display_graph_table => l_region_tbl(l_index).display_graph_table,
1752 	 p_disable_header => l_region_tbl(l_index).disable_header,
1753 	 p_standalone => l_region_tbl(l_index).standalone,
1754 	 p_auto_customization_criteria => l_region_tbl(l_index).auto_customization_criteria,
1755               p_attribute_category => l_region_tbl(l_index).attribute_category,
1756 			  p_attribute1 => l_region_tbl(l_index).attribute1,
1757 			  p_attribute2 => l_region_tbl(l_index).attribute2,
1758 			  p_attribute3 => l_region_tbl(l_index).attribute3,
1759 			  p_attribute4 => l_region_tbl(l_index).attribute4,
1760 			  p_attribute5 => l_region_tbl(l_index).attribute5,
1761 			  p_attribute6 => l_region_tbl(l_index).attribute6,
1762 			  p_attribute7 => l_region_tbl(l_index).attribute7,
1763 			  p_attribute8 => l_region_tbl(l_index).attribute8,
1764 			  p_attribute9 => l_region_tbl(l_index).attribute9,
1765 			  p_attribute10 => l_region_tbl(l_index).attribute10,
1766 			  p_attribute11 => l_region_tbl(l_index).attribute11,
1767 			  p_attribute12 => l_region_tbl(l_index).attribute12,
1768 			  p_attribute13 => l_region_tbl(l_index).attribute13,
1769 			  p_attribute14 => l_region_tbl(l_index).attribute14,
1770 			  p_attribute15 => l_region_tbl(l_index).attribute15,
1771               p_name => l_region_tbl(l_index).name,
1772               p_description => l_region_tbl(l_index).description,
1773 	p_created_by  => l_region_tbl(l_index).created_by,
1774 	p_creation_date  => l_region_tbl(l_index).creation_date,
1775 	p_last_updated_by  => l_region_tbl(l_index).last_updated_by,
1776 	p_last_update_date  => l_region_tbl(l_index).last_update_date,
1777 	p_last_update_login  => l_region_tbl(l_index).last_update_login,
1778               p_loader_timestamp => p_loader_timestamp,
1779 		      p_pass => p_pass,
1780               p_copy_redo_flag => l_copy_redo_flag
1781             );
1782 		  elsif (AK_UPLOAD_GRP.G_NO_CUSTOM_UPDATE) then
1783 			-- do not update customized data
1784 			select ar.last_updated_by, art.last_updated_by,
1785 			       ar.last_update_date, art.last_update_date
1786  			into l_user_id1, l_user_id2, l_update1, l_update2
1787 			from ak_regions ar, ak_regions_tl art
1788 			where ar.region_code = l_region_tbl(l_index).region_code
1789 			and ar.region_application_id = l_region_tbl(l_index).region_application_id
1790 			and ar.region_code = art.region_code
1791 			and ar.region_application_id = art.region_application_id
1792 			and art.language = userenv('LANG');
1793 			/*if (( l_user_id1 = 1 or l_user_id1 = 2 ) and
1794 				( l_user_id2 = 1 or l_user_id2 = 2 )) then*/
1795                 if (AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
1796                   p_loader_timestamp => p_loader_timestamp,
1797                   p_created_by => l_region_tbl(l_index).created_by,
1798                   p_creation_date => l_region_tbl(l_index).creation_date,
1799                   p_last_updated_by => l_region_tbl(l_index).last_updated_by,
1800                   p_db_last_updated_by => l_user_id1,
1801                   p_last_update_date => l_region_tbl(l_index).last_update_date,
1802                   p_db_last_update_date => l_update1,
1803                   p_last_update_login => l_region_tbl(l_index).last_update_login,
1804                   p_create_or_update => 'UPDATE') and
1805 
1806                    AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
1807                   p_loader_timestamp => p_loader_timestamp,
1808                   p_created_by => l_region_tbl(l_index).created_by,
1809                   p_creation_date => l_region_tbl(l_index).creation_date,
1810                   p_last_updated_by => l_region_tbl(l_index).last_updated_by,
1811                   p_db_last_updated_by => l_user_id2,
1812                   p_last_update_date => l_region_tbl(l_index).last_update_date,
1813                   p_db_last_update_date => l_update2,
1814                   p_last_update_login => l_region_tbl(l_index).last_update_login,
1815                   p_create_or_update => 'UPDATE')) then
1816 
1817 	            AK_REGION_PVT.UPDATE_REGION (
1818 	              p_validation_level => p_validation_level,
1819 	              p_api_version_number => 1.0,
1820 	              p_msg_count => l_msg_count,
1821 	              p_msg_data => l_msg_data,
1822 	              p_return_status => l_return_status,
1823 	              p_region_application_id =>
1824 	                                  l_region_tbl(l_index).region_application_id,
1825 	              p_region_code => l_region_tbl(l_index).region_code,
1826 	              p_database_object_name =>l_region_tbl(l_index).database_object_name,
1827 	              p_region_style => l_region_tbl(l_index).region_style,
1828 	              p_num_columns => l_region_tbl(l_index).num_columns,
1829 	              p_icx_custom_call => l_region_tbl(l_index).icx_custom_call,
1830 	              p_region_defaulting_api_pkg =>
1831 	                 l_region_tbl(l_index).region_defaulting_api_pkg,
1832 	              p_region_defaulting_api_proc =>
1833 	                 l_region_tbl(l_index).region_defaulting_api_proc,
1834 	              p_region_validation_api_pkg =>
1835 	                 l_region_tbl(l_index).region_validation_api_pkg,
1836 	              p_region_validation_api_proc =>
1837 	                 l_region_tbl(l_index).region_validation_api_proc,
1838 	              p_appmodule_object_type =>
1839     	             l_region_tbl(l_index).applicationmodule_object_type,
1840         	      p_num_rows_display =>
1841             	     l_region_tbl(l_index).num_rows_display,
1842 	              p_region_object_type =>
1843     	             l_region_tbl(l_index).region_object_type,
1844 	              p_image_file_name =>
1845     	             l_region_tbl(l_index).image_file_name,
1846         	      p_isform_flag => l_region_tbl(l_index).isform_flag,
1847 				  p_help_target => l_region_tbl(l_index).help_target,
1848 				  p_style_sheet_filename => l_region_tbl(l_index).style_sheet_filename,
1849 				  p_version => l_region_tbl(l_index).version,
1850 				  p_applicationmodule_usage_name => l_region_tbl(l_index).applicationmodule_usage_name,
1851 				  p_add_indexed_children => l_region_tbl(l_index).add_indexed_children,
1852 				  p_stateful_flag => l_region_tbl(l_index).stateful_flag,
1853 				  p_function_name => l_region_tbl(l_index).function_name,
1854 				  p_children_view_usage_name => l_region_tbl(l_index).children_view_usage_name,
1855 	p_search_panel => l_region_tbl(l_index).search_panel,
1856 	p_advanced_search_panel => l_region_tbl(l_index).advanced_search_panel,
1857 	p_customize_panel => l_region_tbl(l_index).customize_panel,
1858 	p_default_search_panel => l_region_tbl(l_index).default_search_panel,
1859 	p_results_based_search => l_region_tbl(l_index).results_based_search,
1860 	p_display_graph_table => l_region_tbl(l_index).display_graph_table,
1861 	p_disable_header => l_region_tbl(l_index).disable_header,
1862 	p_standalone => l_region_tbl(l_index).standalone,
1863 	p_auto_customization_criteria => l_region_tbl(l_index).auto_customization_criteria,
1864 	              p_attribute_category => l_region_tbl(l_index).attribute_category,
1865 				  p_attribute1 => l_region_tbl(l_index).attribute1,
1866 				  p_attribute2 => l_region_tbl(l_index).attribute2,
1867 				  p_attribute3 => l_region_tbl(l_index).attribute3,
1868 				  p_attribute4 => l_region_tbl(l_index).attribute4,
1869 				  p_attribute5 => l_region_tbl(l_index).attribute5,
1870 				  p_attribute6 => l_region_tbl(l_index).attribute6,
1871 				  p_attribute7 => l_region_tbl(l_index).attribute7,
1872 				  p_attribute8 => l_region_tbl(l_index).attribute8,
1873 				  p_attribute9 => l_region_tbl(l_index).attribute9,
1874 				  p_attribute10 => l_region_tbl(l_index).attribute10,
1875 				  p_attribute11 => l_region_tbl(l_index).attribute11,
1876 				  p_attribute12 => l_region_tbl(l_index).attribute12,
1877 				  p_attribute13 => l_region_tbl(l_index).attribute13,
1878 				  p_attribute14 => l_region_tbl(l_index).attribute14,
1879 				  p_attribute15 => l_region_tbl(l_index).attribute15,
1880 	              p_name => l_region_tbl(l_index).name,
1881 	              p_description => l_region_tbl(l_index).description,
1882 		p_created_by => l_region_tbl(l_index).created_by,
1883 		p_creation_date => l_region_tbl(l_index).creation_date,
1884 		p_last_updated_by => l_region_tbl(l_index).last_updated_by,
1885 		p_last_update_date => l_region_tbl(l_index).last_update_date,
1886 		p_last_update_login => l_region_tbl(l_index).last_update_login,
1887 	              p_loader_timestamp => p_loader_timestamp,
1888 			      p_pass => p_pass,
1889 	              p_copy_redo_flag => l_copy_redo_flag
1890 	            );
1891 			end if; -- /* if ( l_user_id1 = 1 and l_user_id2 = 1 ) */
1892           end if; -- /* if G_UPDATE_MODE G_NC_UPDATE_MODE*/
1893         else
1894           AK_REGION_PVT.CREATE_REGION (
1895             p_validation_level => p_validation_level,
1896             p_api_version_number => 1.0,
1897             p_msg_count => l_msg_count,
1898             p_msg_data => l_msg_data,
1899             p_return_status => l_return_status,
1900             p_region_application_id =>
1901                                 l_region_tbl(l_index).region_application_id,
1902             p_region_code => l_region_tbl(l_index).region_code,
1903             p_database_object_name =>l_region_tbl(l_index).database_object_name,
1904             p_region_style => l_region_tbl(l_index).region_style,
1905             p_num_columns => l_region_tbl(l_index).num_columns,
1906             p_icx_custom_call => l_region_tbl(l_index).icx_custom_call,
1907             p_region_defaulting_api_pkg =>
1908                l_region_tbl(l_index).region_defaulting_api_pkg,
1909             p_region_defaulting_api_proc =>
1910                l_region_tbl(l_index).region_defaulting_api_proc,
1911             p_region_validation_api_pkg =>
1912                l_region_tbl(l_index).region_validation_api_pkg,
1913             p_region_validation_api_proc =>
1914                l_region_tbl(l_index).region_validation_api_proc,
1915             p_appmodule_object_type =>
1916                l_region_tbl(l_index).applicationmodule_object_type,
1917             p_num_rows_display =>
1918                l_region_tbl(l_index).num_rows_display,
1919             p_region_object_type =>
1920                l_region_tbl(l_index).region_object_type,
1921             p_image_file_name =>
1922                l_region_tbl(l_index).image_file_name,
1923             p_isform_flag => l_region_tbl(l_index).isform_flag,
1924 			p_help_target => l_region_tbl(l_index).help_target,
1925 			p_style_sheet_filename => l_region_tbl(l_index).style_sheet_filename,
1926 			p_version => l_region_tbl(l_index).version,
1927 			p_applicationmodule_usage_name => l_region_tbl(l_index).applicationmodule_usage_name,
1928 			p_add_indexed_children => l_region_tbl(l_index).add_indexed_children,
1929 			p_stateful_flag => l_region_tbl(l_index).stateful_flag,
1930 			p_function_name => l_region_tbl(l_index).function_name,
1931 			p_children_view_usage_name => l_region_tbl(l_index).children_view_usage_name,
1932 	p_search_panel => l_region_tbl(l_index).search_panel,
1933 	p_advanced_search_panel => l_region_tbl(l_index).advanced_search_panel,
1934 	p_customize_panel => l_region_tbl(l_index).customize_panel,
1935 	p_default_search_panel => l_region_tbl(l_index).default_search_panel,
1936 	p_results_based_search => l_region_tbl(l_index).results_based_search,
1937 	p_display_graph_table => l_region_tbl(l_index).display_graph_table,
1938 	p_disable_header => l_region_tbl(l_index).disable_header,
1939 	p_standalone => l_region_tbl(l_index).standalone,
1940 	p_auto_customization_criteria => l_region_tbl(l_index).auto_customization_criteria,
1941             p_attribute_category => l_region_tbl(l_index).attribute_category,
1942 			p_attribute1 => l_region_tbl(l_index).attribute1,
1943 			p_attribute2 => l_region_tbl(l_index).attribute2,
1944 			p_attribute3 => l_region_tbl(l_index).attribute3,
1945 			p_attribute4 => l_region_tbl(l_index).attribute4,
1946 			p_attribute5 => l_region_tbl(l_index).attribute5,
1947 			p_attribute6 => l_region_tbl(l_index).attribute6,
1948 			p_attribute7 => l_region_tbl(l_index).attribute7,
1949 			p_attribute8 => l_region_tbl(l_index).attribute8,
1950 			p_attribute9 => l_region_tbl(l_index).attribute9,
1951 			p_attribute10 => l_region_tbl(l_index).attribute10,
1952 			p_attribute11 => l_region_tbl(l_index).attribute11,
1953 			p_attribute12 => l_region_tbl(l_index).attribute12,
1954 			p_attribute13 => l_region_tbl(l_index).attribute13,
1955 			p_attribute14 => l_region_tbl(l_index).attribute14,
1956 			p_attribute15 => l_region_tbl(l_index).attribute15,
1957             p_name => l_region_tbl(l_index).name,
1958             p_description => l_region_tbl(l_index).description,
1959 	p_created_by => l_region_tbl(l_index).created_by,
1960 	p_creation_date => l_region_tbl(l_index).creation_date,
1961 	p_last_updated_by => l_region_tbl(l_index).last_updated_by,
1962 	p_last_update_date => l_region_tbl(l_index).last_update_date,
1963 	p_last_update_login => l_region_tbl(l_index).last_update_login,
1964             p_loader_timestamp => p_loader_timestamp,
1965 		    p_pass => p_pass,
1966             p_copy_redo_flag => l_copy_redo_flag
1967           );
1968         end if; -- /* if REGION_EXISTS */
1969         --
1970         -- If API call returns with an error status, upload aborts
1971         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
1972         (l_return_status = FND_API.G_RET_STS_ERROR) then
1973           RAISE FND_API.G_EXC_ERROR;
1974         end if; -- /* if l_return_status */
1975 		--
1976 		-- if validation fails, then this record should go to second pass
1977 		if (l_copy_redo_flag) then
1978 		  G_REGION_REDO_INDEX := G_REGION_REDO_INDEX + 1;
1979 		  G_REGION_REDO_TBL(G_REGION_REDO_INDEX) := l_region_tbl(l_index);
1980 		  l_copy_redo_flag := FALSE;
1981 		end if; --/* if l_copy_redo_flag */
1982       end if;
1983     end loop;
1984   end if;
1985 
1986   --
1987   -- create or update all region items to the database
1988   --
1989   if (l_item_tbl.count > 0) then
1990     for l_index in l_item_tbl.FIRST .. l_item_tbl.LAST loop
1991       if (l_item_tbl.exists(l_index)) then
1992         if AK_REGION_PVT.ITEM_EXISTS (
1993             p_api_version_number => 1.0,
1994             p_return_status => l_return_status,
1995             p_region_application_id =>l_item_tbl(l_index).region_application_id,
1996             p_region_code => l_item_tbl(l_index).region_code,
1997             p_attribute_application_id =>
1998                                    l_item_tbl(l_index).attribute_application_id,
1999             p_attribute_code => l_item_tbl(l_index).attribute_code) then
2000           --
2001           -- Update Region Items only if G_UPDATE_MODE is TRUE
2002           --
2003           if (AK_UPLOAD_GRP.G_UPDATE_MODE) then
2004             AK_REGION_PVT.UPDATE_ITEM (
2005               p_validation_level => p_validation_level,
2006               p_api_version_number => 1.0,
2007               p_msg_count => l_msg_count,
2008               p_msg_data => l_msg_data,
2009               p_return_status => l_return_status,
2010               p_region_application_id =>l_item_tbl(l_index).region_application_id,
2011               p_region_code => l_item_tbl(l_index).region_code,
2012               p_attribute_application_id =>
2013                                l_item_tbl(l_index).attribute_application_id,
2014               p_attribute_code => l_item_tbl(l_index).attribute_code,
2015               p_display_sequence => l_item_tbl(l_index).display_sequence,
2016               p_node_display_flag => l_item_tbl(l_index).node_display_flag,
2017               p_node_query_flag => l_item_tbl(l_index).node_query_flag,
2018               p_attribute_label_length =>
2019                                l_item_tbl(l_index).attribute_label_length,
2020               p_display_value_length =>
2021                                l_item_tbl(l_index).display_value_length,
2022               p_bold => l_item_tbl(l_index).bold,
2023               p_italic => l_item_tbl(l_index).italic,
2024               p_vertical_alignment => l_item_tbl(l_index).vertical_alignment,
2025               p_horizontal_alignment => l_item_tbl(l_index).horizontal_alignment,
2026               p_item_style => l_item_tbl(l_index).item_style,
2027               p_object_attribute_flag =>l_item_tbl(l_index).object_attribute_flag,
2028               p_icx_custom_call => l_item_tbl(l_index).icx_custom_call,
2029               p_update_flag => l_item_tbl(l_index).update_flag,
2030               p_required_flag => l_item_tbl(l_index).required_flag,
2031               p_security_code => l_item_tbl(l_index).security_code,
2032               p_default_value_varchar2 =>
2033                  l_item_tbl(l_index).default_value_varchar2,
2034               p_default_value_number =>
2035                  l_item_tbl(l_index).default_value_number,
2036               p_default_value_date =>
2037                  l_item_tbl(l_index).default_value_date,
2038               p_lov_region_application_id =>
2039                  l_item_tbl(l_index).lov_region_application_id,
2040               p_lov_region_code => l_item_tbl(l_index).lov_region_code,
2041               p_lov_foreign_key_name => l_item_tbl(l_index).lov_foreign_key_name,
2042               p_lov_attribute_application_id =>
2043                  l_item_tbl(l_index).lov_attribute_application_id,
2044               p_lov_attribute_code => l_item_tbl(l_index).lov_attribute_code,
2045               p_lov_default_flag => l_item_tbl(l_index).lov_default_flag,
2046               p_region_defaulting_api_pkg =>
2047                  l_item_tbl(l_index).region_defaulting_api_pkg,
2048               p_region_defaulting_api_proc =>
2049                  l_item_tbl(l_index).region_defaulting_api_proc,
2050               p_region_validation_api_pkg =>
2051                  l_item_tbl(l_index).region_validation_api_pkg,
2052               p_region_validation_api_proc =>
2053                  l_item_tbl(l_index).region_validation_api_proc,
2054               p_order_sequence => l_item_tbl(l_index).order_sequence,
2055               p_order_direction => l_item_tbl(l_index).order_direction,
2056 		  p_display_height => l_item_tbl(l_index).display_height,
2057 			  p_submit => l_item_tbl(l_index).submit,
2058 			  p_encrypt => l_item_tbl(l_index).encrypt,
2059 			  p_css_class_name => l_item_tbl(l_index).css_class_name,
2060 			  p_view_usage_name =>l_item_tbl(l_index).view_usage_name,
2061 			  p_view_attribute_name =>l_item_tbl(l_index).view_attribute_name,
2062 			  p_nested_region_appl_id =>l_item_tbl(l_index).nested_region_application_id,
2063 			  p_nested_region_code =>l_item_tbl(l_index).nested_region_code,
2064 			  p_url =>l_item_tbl(l_index).url,
2065 			  p_poplist_viewobject =>l_item_tbl(l_index).poplist_viewobject,
2066 			  p_poplist_display_attr =>l_item_tbl(l_index).poplist_display_attr,
2067 			  p_poplist_value_attr =>l_item_tbl(l_index).poplist_value_attr,
2068 			  p_image_file_name =>l_item_tbl(l_index).image_file_name,
2069 			  p_item_name =>l_item_tbl(l_index).item_name,
2070 			  p_css_label_class_name => l_item_tbl(l_index).css_label_class_name,
2071 			  p_menu_name => l_item_tbl(l_index).menu_name,
2072 			  p_flexfield_name => l_item_tbl(l_index).flexfield_name,
2073 			  p_flexfield_application_id => l_item_tbl(l_index).flexfield_application_id,
2074               p_tabular_function_code    => l_item_tbl(l_index).tabular_function_code,
2075               p_tip_type                 => l_item_tbl(l_index).tip_type,
2076               p_tip_message_name         => l_item_tbl(l_index).tip_message_name,
2077               p_tip_message_application_id  => l_item_tbl(l_index).tip_message_application_id ,
2078               p_flex_segment_list        => l_item_tbl(l_index).flex_segment_list,
2079               p_entity_id  => l_item_tbl(l_index).entity_id,
2080               p_anchor     => l_item_tbl(l_index).anchor,
2081               p_poplist_view_usage_name => l_item_tbl(l_index).poplist_view_usage_name,
2082 	      p_user_customizable => l_item_tbl(l_index).user_customizable,
2083               p_sortby_view_attribute_name => l_item_tbl(l_index).sortby_view_attribute_name,
2084 	      p_admin_customizable => l_item_tbl(l_index).admin_customizable,
2085 	      p_invoke_function_name => l_item_tbl(l_index).invoke_function_name,
2086 	      p_expansion => l_item_tbl(l_index).expansion,
2087 	      p_als_max_length => l_item_tbl(l_index).als_max_length,
2088               p_initial_sort_sequence => l_item_tbl(l_index).initial_sort_sequence,
2089 	      p_customization_application_id => l_item_tbl(l_index).customization_application_id,
2090 	      p_customization_code => l_item_tbl(l_index).customization_code,
2091               p_attribute_category => l_item_tbl(l_index).attribute_category,
2092 			  p_attribute1 => l_item_tbl(l_index).attribute1,
2093 			  p_attribute2 => l_item_tbl(l_index).attribute2,
2094 			  p_attribute3 => l_item_tbl(l_index).attribute3,
2095 			  p_attribute4 => l_item_tbl(l_index).attribute4,
2096 			  p_attribute5 => l_item_tbl(l_index).attribute5,
2097 			  p_attribute6 => l_item_tbl(l_index).attribute6,
2098 			  p_attribute7 => l_item_tbl(l_index).attribute7,
2099 			  p_attribute8 => l_item_tbl(l_index).attribute8,
2100 			  p_attribute9 => l_item_tbl(l_index).attribute9,
2101 			  p_attribute10 => l_item_tbl(l_index).attribute10,
2102 			  p_attribute11 => l_item_tbl(l_index).attribute11,
2103 			  p_attribute12 => l_item_tbl(l_index).attribute12,
2104 			  p_attribute13 => l_item_tbl(l_index).attribute13,
2105 			  p_attribute14 => l_item_tbl(l_index).attribute14,
2106 			  p_attribute15 => l_item_tbl(l_index).attribute15,
2107               p_attribute_label_long => l_item_tbl(l_index).attribute_label_long,
2108               p_attribute_label_short =>l_item_tbl(l_index).attribute_label_short,
2109               p_description =>l_item_tbl(l_index).description,
2110 		p_created_by => l_item_tbl(l_index).created_by,
2111 		p_creation_date => l_item_tbl(l_index).creation_date,
2112 		p_last_updated_by => l_item_tbl(l_index).last_updated_by,
2113 		p_last_update_date => l_item_tbl(l_index).last_update_date,
2114 		p_last_update_login => l_item_tbl(l_index).last_update_login,
2115               p_loader_timestamp => p_loader_timestamp,
2116   		      p_pass => p_pass,
2117               p_copy_redo_flag => l_copy_redo_flag
2118             );
2119 		  -- update non-customized data only
2120 		  elsif ( AK_UPLOAD_GRP.G_NO_CUSTOM_UPDATE ) then
2121 			select ari.last_updated_by, arit.last_updated_by,
2122 			       ari.last_update_date, arit.last_update_date
2123 			into l_user_id1, l_user_id2, l_update1, l_update2
2124 			from ak_region_items ari, ak_region_items_tl arit
2125 			where ari.region_code = l_item_tbl(l_index).region_code
2126 			and ari.region_application_id = l_item_tbl(l_index).region_application_id
2127 			and ari.attribute_code = l_item_tbl(l_index).attribute_code
2128 			and ari.attribute_application_id = l_item_tbl(l_index).attribute_application_id
2129 			and ari.region_code = arit.region_code
2130 			and ari.region_application_id = arit.region_application_id
2131 			and ari.attribute_code = arit.attribute_code
2132 			and ari.attribute_application_id = arit.attribute_application_id
2133 			and arit.language = userenv('LANG');
2134 			/*if (( l_user_id1 = 1 or l_user_id1 = 2 ) and
2135 				( l_user_id2 = 1 or l_user_id2 = 2 )) then*/
2136                 if (AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
2137                       p_loader_timestamp => p_loader_timestamp,
2138                       p_created_by => l_item_tbl(l_index).created_by,
2139                       p_creation_date => l_item_tbl(l_index).creation_date,
2140                       p_last_updated_by => l_item_tbl(l_index).last_updated_by,
2141                       p_db_last_updated_by => l_user_id1,
2142                       p_last_update_date => l_item_tbl(l_index).last_update_date,
2143                       p_db_last_update_date => l_update1,
2144                       p_last_update_login => l_item_tbl(l_index).last_update_login,
2145                       p_create_or_update => 'UPDATE') and
2146 
2147                    AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
2148                       p_loader_timestamp => p_loader_timestamp,
2149                       p_created_by => l_item_tbl(l_index).created_by,
2150                       p_creation_date => l_item_tbl(l_index).creation_date,
2151                       p_last_updated_by => l_item_tbl(l_index).last_updated_by,
2152                       p_db_last_updated_by => l_user_id2,
2153                       p_last_update_date => l_item_tbl(l_index).last_update_date,
2154                       p_db_last_update_date => l_update2,
2155                       p_last_update_login => l_item_tbl(l_index).last_update_login,
2156                       p_create_or_update => 'UPDATE')) then
2157 
2158 	            AK_REGION_PVT.UPDATE_ITEM (
2159 	              p_validation_level => p_validation_level,
2160 	              p_api_version_number => 1.0,
2161 	              p_msg_count => l_msg_count,
2162 	              p_msg_data => l_msg_data,
2163 	              p_return_status => l_return_status,
2164 	              p_region_application_id =>l_item_tbl(l_index).region_application_id,
2165 	              p_region_code => l_item_tbl(l_index).region_code,
2166 	              p_attribute_application_id =>
2167 	                               l_item_tbl(l_index).attribute_application_id,
2168 	              p_attribute_code => l_item_tbl(l_index).attribute_code,
2169 	              p_display_sequence => l_item_tbl(l_index).display_sequence,
2170 	              p_node_display_flag => l_item_tbl(l_index).node_display_flag,
2171 	              p_node_query_flag => l_item_tbl(l_index).node_query_flag,
2172 	              p_attribute_label_length =>
2173 	                               l_item_tbl(l_index).attribute_label_length,
2174 	              p_display_value_length =>
2175 	                               l_item_tbl(l_index).display_value_length,
2176 	              p_bold => l_item_tbl(l_index).bold,
2177 	              p_italic => l_item_tbl(l_index).italic,
2178 	              p_vertical_alignment => l_item_tbl(l_index).vertical_alignment,
2179 	              p_horizontal_alignment => l_item_tbl(l_index).horizontal_alignment,
2180 	              p_item_style => l_item_tbl(l_index).item_style,
2181 	              p_object_attribute_flag =>l_item_tbl(l_index).object_attribute_flag,
2182 	              p_icx_custom_call => l_item_tbl(l_index).icx_custom_call,
2183 	              p_update_flag => l_item_tbl(l_index).update_flag,
2184 	              p_required_flag => l_item_tbl(l_index).required_flag,
2185 	              p_security_code => l_item_tbl(l_index).security_code,
2186 	              p_default_value_varchar2 =>
2187 	                 l_item_tbl(l_index).default_value_varchar2,
2188 	              p_default_value_number =>
2189 	                 l_item_tbl(l_index).default_value_number,
2190 	              p_default_value_date =>
2191 	                 l_item_tbl(l_index).default_value_date,
2192 	              p_lov_region_application_id =>
2193 	                 l_item_tbl(l_index).lov_region_application_id,
2194 	              p_lov_region_code => l_item_tbl(l_index).lov_region_code,
2195 	              p_lov_foreign_key_name => l_item_tbl(l_index).lov_foreign_key_name,
2196 	              p_lov_attribute_application_id =>
2197 	                 l_item_tbl(l_index).lov_attribute_application_id,
2198 	              p_lov_attribute_code => l_item_tbl(l_index).lov_attribute_code,
2199 	              p_lov_default_flag => l_item_tbl(l_index).lov_default_flag,
2200 	              p_region_defaulting_api_pkg =>
2201 	                 l_item_tbl(l_index).region_defaulting_api_pkg,
2202 	              p_region_defaulting_api_proc =>
2203 	                 l_item_tbl(l_index).region_defaulting_api_proc,
2204 	              p_region_validation_api_pkg =>
2205 	                 l_item_tbl(l_index).region_validation_api_pkg,
2206 	              p_region_validation_api_proc =>
2207 	                 l_item_tbl(l_index).region_validation_api_proc,
2208 	              p_order_sequence => l_item_tbl(l_index).order_sequence,
2209 	              p_order_direction => l_item_tbl(l_index).order_direction,
2210 				  p_display_height => l_item_tbl(l_index).display_height,
2211 				  p_submit => l_item_tbl(l_index).submit,
2212 				  p_encrypt => l_item_tbl(l_index).encrypt,
2213 				  p_css_class_name => l_item_tbl(l_index).css_class_name,
2214 				  p_view_usage_name =>l_item_tbl(l_index).view_usage_name,
2215 				  p_view_attribute_name =>l_item_tbl(l_index).view_attribute_name,
2216 				  p_nested_region_appl_id =>l_item_tbl(l_index).nested_region_application_id,
2217 				  p_nested_region_code =>l_item_tbl(l_index).nested_region_code,
2218 				  p_url =>l_item_tbl(l_index).url,
2219 				  p_poplist_viewobject =>l_item_tbl(l_index).poplist_viewobject,
2220 				  p_poplist_display_attr =>l_item_tbl(l_index).poplist_display_attr,
2221 				  p_poplist_value_attr =>l_item_tbl(l_index).poplist_value_attr,
2222 				  p_image_file_name =>l_item_tbl(l_index).image_file_name,
2223 				  p_item_name =>l_item_tbl(l_index).item_name,
2224 				  p_css_label_class_name => l_item_tbl(l_index).css_label_class_name,
2225 				  p_menu_name => l_item_tbl(l_index).menu_name,
2226 				  p_flexfield_name => l_item_tbl(l_index).flexfield_name,
2227 				  p_flexfield_application_id => l_item_tbl(l_index).flexfield_application_id,
2228                   p_tabular_function_code    => l_item_tbl(l_index).tabular_function_code,
2229                   p_tip_type                 => l_item_tbl(l_index).tip_type,
2230                   p_tip_message_name          => l_item_tbl(l_index).tip_message_name,
2231                   p_tip_message_application_id  => l_item_tbl(l_index).tip_message_application_id ,
2232                   p_flex_segment_list        => l_item_tbl(l_index).flex_segment_list,
2233                   p_entity_id  => l_item_tbl(l_index).entity_id,
2234                   p_anchor => l_item_tbl(l_index).anchor,
2235                   p_poplist_view_usage_name => l_item_tbl(l_index).poplist_view_usage_name,
2236 		  p_user_customizable => l_item_tbl(l_index).user_customizable,
2237                   p_sortby_view_attribute_name => l_item_tbl(l_index).sortby_view_attribute_name,
2238 		  p_admin_customizable => l_item_tbl(l_index).admin_customizable,
2239 		  p_invoke_function_name => l_item_tbl(l_index).invoke_function_name,
2240 		  p_expansion => l_item_tbl(l_index).expansion,
2241 		  p_als_max_length => l_item_tbl(l_index).als_max_length,
2242 		  p_initial_sort_sequence => l_item_tbl(l_index).initial_sort_sequence,
2243 		  p_customization_application_id => l_item_tbl(l_index).customization_application_id,
2244 		  p_customization_code => l_item_tbl(l_index).customization_code,
2245 	              p_attribute_category => l_item_tbl(l_index).attribute_category,
2246 				  p_attribute1 => l_item_tbl(l_index).attribute1,
2247 				  p_attribute2 => l_item_tbl(l_index).attribute2,
2248 				  p_attribute3 => l_item_tbl(l_index).attribute3,
2249 				  p_attribute4 => l_item_tbl(l_index).attribute4,
2250 				  p_attribute5 => l_item_tbl(l_index).attribute5,
2251 				  p_attribute6 => l_item_tbl(l_index).attribute6,
2252 				  p_attribute7 => l_item_tbl(l_index).attribute7,
2253 				  p_attribute8 => l_item_tbl(l_index).attribute8,
2254 				  p_attribute9 => l_item_tbl(l_index).attribute9,
2255 				  p_attribute10 => l_item_tbl(l_index).attribute10,
2256 				  p_attribute11 => l_item_tbl(l_index).attribute11,
2257 				  p_attribute12 => l_item_tbl(l_index).attribute12,
2258 				  p_attribute13 => l_item_tbl(l_index).attribute13,
2259 				  p_attribute14 => l_item_tbl(l_index).attribute14,
2260 				  p_attribute15 => l_item_tbl(l_index).attribute15,
2261 	              p_attribute_label_long => l_item_tbl(l_index).attribute_label_long,
2262 	              p_attribute_label_short =>l_item_tbl(l_index).attribute_label_short,
2263 				  p_description => l_item_tbl(l_index).description,
2264 		p_created_by => l_item_tbl(l_index).created_by,
2265 		p_creation_date => l_item_tbl(l_index).creation_date,
2266 		p_last_updated_by => l_item_tbl(l_index).last_updated_by,
2267 		p_last_update_date => l_item_tbl(l_index).last_update_date,
2268 		p_last_update_login => l_item_tbl(l_index).last_update_login,
2269 	              p_loader_timestamp => p_loader_timestamp,
2270 	  		      p_pass => p_pass,
2271 	              p_copy_redo_flag => l_copy_redo_flag
2272 	            );
2273 			end if; /* if l_user_id1 = 1 and l_user_id2 = 1 */
2274           end if; -- /* if G_UPDATE_MODE G_NO_CUSTOM_UPDATE */
2275         else
2276           AK_REGION_PVT.CREATE_ITEM (
2277             p_validation_level => p_validation_level,
2278             p_api_version_number => 1.0,
2279             p_msg_count => l_msg_count,
2280             p_msg_data => l_msg_data,
2281             p_return_status => l_return_status,
2282             p_region_application_id =>l_item_tbl(l_index).region_application_id,
2283             p_region_code => l_item_tbl(l_index).region_code,
2284             p_attribute_application_id =>
2285                              l_item_tbl(l_index).attribute_application_id,
2286             p_attribute_code => l_item_tbl(l_index).attribute_code,
2287             p_display_sequence => l_item_tbl(l_index).display_sequence,
2288             p_node_display_flag => l_item_tbl(l_index).node_display_flag,
2289             p_node_query_flag => l_item_tbl(l_index).node_query_flag,
2290             p_attribute_label_length =>
2291                              l_item_tbl(l_index).attribute_label_length,
2292             p_display_value_length =>
2293                              l_item_tbl(l_index).display_value_length,
2294             p_bold => l_item_tbl(l_index).bold,
2295             p_italic => l_item_tbl(l_index).italic,
2296             p_vertical_alignment => l_item_tbl(l_index).vertical_alignment,
2297             p_horizontal_alignment => l_item_tbl(l_index).horizontal_alignment,
2298             p_item_style => l_item_tbl(l_index).item_style,
2299             p_object_attribute_flag =>l_item_tbl(l_index).object_attribute_flag,
2300             p_icx_custom_call => l_item_tbl(l_index).icx_custom_call,
2301             p_update_flag => l_item_tbl(l_index).update_flag,
2302             p_required_flag => l_item_tbl(l_index).required_flag,
2303             p_security_code => l_item_tbl(l_index).security_code,
2304             p_default_value_varchar2 =>
2305                l_item_tbl(l_index).default_value_varchar2,
2306             p_default_value_number =>
2307                l_item_tbl(l_index).default_value_number,
2308             p_default_value_date =>
2309                l_item_tbl(l_index).default_value_date,
2310             p_lov_region_application_id =>
2311                l_item_tbl(l_index).lov_region_application_id,
2312             p_lov_region_code => l_item_tbl(l_index).lov_region_code,
2313             p_lov_foreign_key_name => l_item_tbl(l_index).lov_foreign_key_name,
2314             p_lov_attribute_application_id =>
2315                l_item_tbl(l_index).lov_attribute_application_id,
2316             p_lov_attribute_code => l_item_tbl(l_index).lov_attribute_code,
2317             p_lov_default_flag => l_item_tbl(l_index).lov_default_flag,
2318             p_region_defaulting_api_pkg =>
2319                l_item_tbl(l_index).region_defaulting_api_pkg,
2320             p_region_defaulting_api_proc =>
2321                l_item_tbl(l_index).region_defaulting_api_proc,
2322             p_region_validation_api_pkg =>
2323                l_item_tbl(l_index).region_validation_api_pkg,
2324             p_region_validation_api_proc =>
2325                l_item_tbl(l_index).region_validation_api_proc,
2326             p_order_sequence => l_item_tbl(l_index).order_sequence,
2327             p_order_direction => l_item_tbl(l_index).order_direction,
2328 			p_display_height => l_item_tbl(l_index).display_height,
2329 			p_submit => l_item_tbl(l_index).submit,
2330 			p_encrypt => l_item_tbl(l_index).encrypt,
2331 			p_css_class_name => l_item_tbl(l_index).css_class_name,
2332 			p_view_usage_name =>l_item_tbl(l_index).view_usage_name,
2333 			p_view_attribute_name =>l_item_tbl(l_index).view_attribute_name,
2334 			p_nested_region_appl_id =>l_item_tbl(l_index).nested_region_application_id,
2335 			p_nested_region_code =>l_item_tbl(l_index).nested_region_code,
2336 			p_url =>l_item_tbl(l_index).url,
2337 			p_poplist_viewobject =>l_item_tbl(l_index).poplist_viewobject,
2338 			p_poplist_display_attr =>l_item_tbl(l_index).poplist_display_attr,
2339 			p_poplist_value_attr =>l_item_tbl(l_index).poplist_value_attr,
2340 			p_image_file_name =>l_item_tbl(l_index).image_file_name,
2341 			p_item_name => l_item_tbl(l_index).item_name,
2342 			p_css_label_class_name => l_item_tbl(l_index).css_label_class_name,
2343 			p_menu_name => l_item_tbl(l_index).menu_name,
2344 			p_flexfield_name => l_item_tbl(l_index).flexfield_name,
2345 			p_flexfield_application_id => l_item_tbl(l_index).flexfield_application_id,
2346             p_tabular_function_code    => l_item_tbl(l_index).tabular_function_code,
2347             p_tip_type                 => l_item_tbl(l_index).tip_type,
2348             p_tip_message_name         => l_item_tbl(l_index).tip_message_name,
2349             p_tip_message_application_id  => l_item_tbl(l_index).tip_message_application_id ,
2350             p_flex_segment_list        => l_item_tbl(l_index).flex_segment_list,
2351             p_entity_id  => l_item_tbl(l_index).entity_id ,
2352             p_anchor => l_item_tbl(l_index).anchor,
2353             p_poplist_view_usage_name => l_item_tbl(l_index).poplist_view_usage_name,
2354 	    p_user_customizable => l_item_tbl(l_index).user_customizable,
2355             p_sortby_view_attribute_name => l_item_tbl(l_index).sortby_view_attribute_name,
2356 	    p_admin_customizable => l_item_tbl(l_index).admin_customizable,
2357 	    p_invoke_function_name => l_item_tbl(l_index).invoke_function_name,
2358 	    p_expansion => l_item_tbl(l_index).expansion,
2359 	    p_als_max_length => l_item_tbl(l_index).als_max_length,
2360             p_initial_sort_sequence => l_item_tbl(l_index).initial_sort_sequence,
2361 	    p_customization_application_id => l_item_tbl(l_index).customization_application_id,
2362 	    p_customization_code => l_item_tbl(l_index).customization_code,
2363             p_attribute_category => l_item_tbl(l_index).attribute_category,
2364 			p_attribute1 => l_item_tbl(l_index).attribute1,
2365 			p_attribute2 => l_item_tbl(l_index).attribute2,
2366 			p_attribute3 => l_item_tbl(l_index).attribute3,
2367 			p_attribute4 => l_item_tbl(l_index).attribute4,
2368 			p_attribute5 => l_item_tbl(l_index).attribute5,
2369 			p_attribute6 => l_item_tbl(l_index).attribute6,
2370 			p_attribute7 => l_item_tbl(l_index).attribute7,
2371 			p_attribute8 => l_item_tbl(l_index).attribute8,
2372 			p_attribute9 => l_item_tbl(l_index).attribute9,
2373 			p_attribute10 => l_item_tbl(l_index).attribute10,
2374 			p_attribute11 => l_item_tbl(l_index).attribute11,
2375 			p_attribute12 => l_item_tbl(l_index).attribute12,
2376 			p_attribute13 => l_item_tbl(l_index).attribute13,
2377 			p_attribute14 => l_item_tbl(l_index).attribute14,
2378 			p_attribute15 => l_item_tbl(l_index).attribute15,
2379             p_attribute_label_long => l_item_tbl(l_index).attribute_label_long,
2380             p_attribute_label_short =>l_item_tbl(l_index).attribute_label_short,
2381 			p_description => l_item_tbl(l_index).description,
2382 		p_created_by => l_item_tbl(l_index).created_by,
2383 		p_creation_date => l_item_tbl(l_index).creation_date,
2384 		p_last_updated_by => l_item_tbl(l_index).last_updated_by,
2385 		p_last_update_date => l_item_tbl(l_index).last_update_date,
2386 		p_last_update_login => l_item_tbl(l_index).last_update_login,
2387             p_loader_timestamp => p_loader_timestamp,
2388 		    p_pass => p_pass,
2389             p_copy_redo_flag => l_copy_redo_flag
2390           );
2391         end if; -- /* if ITEM_EXISTS */
2392         --
2393         -- If API call returns with an error status, upload aborts
2394         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
2395         (l_return_status = FND_API.G_RET_STS_ERROR) then
2396           RAISE FND_API.G_EXC_ERROR;
2397         end if; -- /* if l_return_status */
2398 		--
2399 		-- if validation fails, then this record should go to second pass
2400 		if (l_copy_redo_flag) then
2401 		  G_ITEM_REDO_INDEX := G_ITEM_REDO_INDEX + 1;
2402 		  G_ITEM_REDO_TBL(G_ITEM_REDO_INDEX) := l_item_tbl(l_index);
2403 		  l_copy_redo_flag := FALSE;
2404 		end if; --/* if l_copy_redo_flag */
2405       end if; -- /* if l_item_tbl.exists */
2406     end loop;
2407   end if; -- /* if l_item_tbl.count > 0 */
2408 
2409   --
2410   -- create or update all region lov relations to the database
2411   --
2412   if (l_lov_relation_tbl.count > 0) then
2413     for l_index in l_lov_relation_tbl.FIRST .. l_lov_relation_tbl.LAST loop
2414       if (l_lov_relation_tbl.exists(l_index)) then
2415 	    if ( l_lov_relation_tbl(l_index).base_region_appl_id is null ) then
2416 		  l_lov_relation_tbl(l_index).base_region_appl_id := l_lov_relation_tbl(l_index).region_application_id;
2417 		end if;
2418 		if ( l_lov_relation_tbl(l_index).base_region_code is null ) then
2419   		  l_lov_relation_tbl(l_index).base_region_code := l_lov_relation_tbl(l_index).region_code;
2420 		end if;
2421         if AK_REGION2_PVT.LOV_RELATION_EXISTS (
2422             p_api_version_number => 1.0,
2423             p_return_status => l_return_status,
2424             p_region_application_id =>
2425                                l_lov_relation_tbl(l_index).region_application_id,
2426             p_region_code => l_lov_relation_tbl(l_index).region_code,
2427             p_attribute_application_id =>
2428             					l_lov_relation_tbl(l_index).attribute_application_id,
2429             p_attribute_code => l_lov_relation_tbl(l_index).attribute_code,
2430             p_lov_region_appl_id => l_lov_relation_tbl(l_index).lov_region_appl_id,
2431             p_lov_region_code => l_lov_relation_tbl(l_index).lov_region_code,
2432             p_lov_attribute_appl_id =>
2433             					l_lov_relation_tbl(l_index).lov_attribute_appl_id,
2434             p_lov_attribute_code => l_lov_relation_tbl(l_index).lov_attribute_code,
2435 			p_base_attribute_appl_id => l_lov_relation_tbl(l_index).base_attribute_appl_id,
2436 			p_base_attribute_code => l_lov_relation_tbl(l_index).base_attribute_code,
2437             p_direction_flag => l_lov_relation_tbl(l_index).direction_flag,
2438 	    p_base_region_appl_id => l_lov_relation_tbl(l_index).base_region_appl_id,
2439 	    p_base_region_code => l_lov_relation_tbl(l_index).base_region_code) then
2440           --
2441           -- Update Region lov relations if G_UPDATE_MODE is TRUE
2442           -- Also update Region Lov relations if G_NO_CUSTOM_UPDATE since there's
2443 		  -- no customized data in this table, do not update if G_NO_UPDATE_MODE
2444 		  --
2445           if (AK_UPLOAD_GRP.G_UPDATE_MODE or AK_UPLOAD_GRP.G_NO_CUSTOM_UPDATE) then
2446             AK_REGION2_PVT.UPDATE_LOV_RELATION (
2447               p_validation_level => p_validation_level,
2448               p_api_version_number => 1.0,
2449               p_msg_count => l_msg_count,
2450               p_msg_data => l_msg_data,
2451               p_return_status => l_return_status,
2452               p_region_application_id =>
2453                                   l_lov_relation_tbl(l_index).region_application_id,
2454               p_region_code => l_lov_relation_tbl(l_index).region_code,
2455               p_attribute_application_id =>
2456                                   l_lov_relation_tbl(l_index).attribute_application_id,
2457               p_attribute_code => l_lov_relation_tbl(l_index).attribute_code,
2458 			  p_lov_region_appl_id => l_lov_relation_tbl(l_index).lov_region_appl_id,
2459 			  p_lov_region_code => l_lov_relation_tbl(l_index).lov_region_code,
2460 			  p_lov_attribute_appl_id => l_lov_relation_tbl(l_index).lov_attribute_appl_id,
2461 			  p_lov_attribute_code => l_lov_relation_tbl(l_index).lov_attribute_code,
2462 			  p_base_attribute_appl_id => l_lov_relation_tbl(l_index).base_attribute_appl_id,
2463 			  p_base_attribute_code => l_lov_relation_tbl(l_index).base_attribute_code,
2464               p_direction_flag => l_lov_relation_tbl(l_index).direction_flag,
2465 	      p_base_region_appl_id => l_lov_relation_tbl(l_index).base_region_appl_id,
2466 	      p_base_region_code => l_lov_relation_tbl(l_index).base_region_code,
2467 			  p_required_flag => l_lov_relation_tbl(l_index).required_flag,
2468 		p_created_by => l_lov_relation_tbl(l_index).created_by,
2469 		p_creation_date => l_lov_relation_tbl(l_index).creation_date,
2470 		p_last_updated_by => l_lov_relation_tbl(l_index).last_updated_by,
2471 		p_last_update_date => l_lov_relation_tbl(l_index).last_update_date,
2472 		p_last_update_login => l_lov_relation_tbl(l_index).last_update_login,
2473               p_loader_timestamp => p_loader_timestamp,
2474 		      p_pass => p_pass,
2475               p_copy_redo_flag => l_copy_redo_flag
2476             );
2477 		  end if;
2478         else
2479           AK_REGION2_PVT.CREATE_LOV_RELATION (
2480             p_validation_level => p_validation_level,
2481             p_api_version_number => 1.0,
2482             p_msg_count => l_msg_count,
2483             p_msg_data => l_msg_data,
2484             p_return_status => l_return_status,
2485               p_region_application_id =>
2486                                   l_lov_relation_tbl(l_index).region_application_id,
2487               p_region_code => l_lov_relation_tbl(l_index).region_code,
2488               p_attribute_application_id =>
2489                                   l_lov_relation_tbl(l_index).attribute_application_id,
2490               p_attribute_code => l_lov_relation_tbl(l_index).attribute_code,
2491 			  p_lov_region_appl_id => l_lov_relation_tbl(l_index).lov_region_appl_id,
2492 			  p_lov_region_code => l_lov_relation_tbl(l_index).lov_region_code,
2493 			  p_lov_attribute_appl_id => l_lov_relation_tbl(l_index).lov_attribute_appl_id,
2494 			  p_lov_attribute_code => l_lov_relation_tbl(l_index).lov_attribute_code,
2495 			  p_base_attribute_appl_id => l_lov_relation_tbl(l_index).base_attribute_appl_id,
2496 			  p_base_attribute_code => l_lov_relation_tbl(l_index).base_attribute_code,
2497               p_direction_flag => l_lov_relation_tbl(l_index).direction_flag,
2498 	      p_base_region_appl_id => l_lov_relation_tbl(l_index).base_region_appl_id,
2499 	      p_base_region_code => l_lov_relation_tbl(l_index).base_region_code,
2500 			  p_required_flag => l_lov_relation_tbl(l_index).required_flag,
2501 	p_created_by => l_lov_relation_tbl(l_index).created_by,
2502 	p_creation_date => l_lov_relation_tbl(l_index).creation_date,
2503 	p_last_updated_by => l_lov_relation_tbl(l_index).last_updated_by,
2504 	p_last_update_date => l_lov_relation_tbl(l_index).last_update_date,
2505 	p_last_update_login => l_lov_relation_tbl(l_index).lasT_update_login,
2506             p_loader_timestamp => p_loader_timestamp,
2507 		    p_pass => p_pass,
2508             p_copy_redo_flag => l_copy_redo_flag
2509           );
2510         end if; -- /* if REGION_EXISTS */
2511         --
2512         -- If API call returns with an error status, upload aborts
2513         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
2514         (l_return_status = FND_API.G_RET_STS_ERROR) then
2515           RAISE FND_API.G_EXC_ERROR;
2516         end if; -- /* if l_return_status */
2517 		--
2518 		-- if validation fails, then this record should go to second pass
2519 		-- validation usually fails when referenced record has not been created yet
2520 		if (l_copy_redo_flag) then
2521 		  G_LOV_RELATION_REDO_INDEX := G_LOV_RELATION_REDO_INDEX + 1;
2522 		  G_LOV_RELATION_REDO_TBL(G_LOV_RELATION_REDO_INDEX) := l_lov_relation_tbl(l_index);
2523 		  l_copy_redo_flag := FALSE;
2524 		end if; --/* if l_copy_redo_flag */
2525       end if; -- /* end if l_lov_relation_tbl.exists(l_index) */
2526     end loop; -- /* end for l_index in l_lov_relation_tbl */
2527   end if;
2528 
2529   --
2530   -- create or update all region item category relations to the database
2531   --
2532   if (l_category_usage_tbl.count > 0) then
2533     for l_index in l_category_usage_tbl.FIRST .. l_category_usage_tbl.LAST loop
2534       if (l_category_usage_tbl.exists(l_index)) then
2535        if (l_category_usage_tbl(l_index).category_name is null) then
2536 	 open l_check_fnd_category_name_csr(l_category_usage_tbl(l_index).category_id);
2537 	 fetch l_check_fnd_category_name_csr into l_category_usage_tbl(l_index).category_name;
2538 	 if (l_check_fnd_category_name_csr%notfound) then
2539 	    FND_MESSAGE.SET_NAME('AK','AK_CATEGORY_USAGE_SKIPPED');
2540 	     FND_MESSAGE.SET_TOKEN('KEY', to_char(l_category_usage_tbl(l_index).category_id));
2541       	    FND_MSG_PUB.Add;
2542 	 end if;
2543 	 close l_check_fnd_category_name_csr;
2544        elsif (l_category_usage_tbl(l_index).category_name is not null) then
2545          open l_check_fnd_category_id_csr(l_category_usage_tbl(l_index).category_name);
2546          fetch l_check_fnd_category_id_csr into l_category_usage_tbl(l_index).category_id;
2547          if (l_check_fnd_category_id_csr%notfound) then
2548     	    if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
2549       		FND_MESSAGE.SET_NAME('AK','AK_FND_CATEGORY_DOES_NOT_EXIST');
2550              FND_MESSAGE.SET_TOKEN('KEY', (l_category_usage_tbl(l_index).category_name));
2551       		FND_MSG_PUB.Add;
2552             end if;
2553             close l_check_fnd_category_id_csr;
2554             raise FND_API.G_EXC_ERROR;
2555          end if;
2556 	 close l_check_fnd_category_id_csr;
2557        end if;
2558 
2559 	if (l_category_usage_tbl(l_index).category_name is not null) then
2560         if ( AK_REGION2_PVT.CATEGORY_USAGE_EXISTS(
2561             p_api_version_number => 1.0,
2562             p_return_status => l_return_status,
2563             p_region_application_id =>
2564                                l_category_usage_tbl(l_index).region_application_id,
2565             p_region_code => l_category_usage_tbl(l_index).region_code,
2566             p_attribute_application_id =>
2567             					l_category_usage_tbl(l_index).attribute_application_id,
2568             p_attribute_code => l_category_usage_tbl(l_index).attribute_code,
2569             p_category_name => l_category_usage_tbl(l_index).category_name) = false)  then
2570           AK_REGION2_PVT.CREATE_CATEGORY_USAGE (
2571             p_validation_level => p_validation_level,
2572             p_api_version_number => 1.0,
2573             p_msg_count => l_msg_count,
2574             p_msg_data => l_msg_data,
2575             p_return_status => l_return_status,
2576               p_region_application_id =>
2577                                   l_category_usage_tbl(l_index).region_application_id,
2578               p_region_code => l_category_usage_tbl(l_index).region_code,
2579               p_attribute_application_id =>
2580                                   l_category_usage_tbl(l_index).attribute_application_id,
2581               p_attribute_code => l_category_usage_tbl(l_index).attribute_code,
2582 			  p_category_name => l_category_usage_tbl(l_index).category_name,
2583 		p_category_id => l_category_usage_tbl(l_index).category_id,
2584 		p_application_id => l_category_usage_tbl(l_index).application_id,
2585 		p_show_all => l_category_usage_tbl(l_index).show_all,
2586 		p_created_by => l_category_usage_tbl(l_index).created_by,
2587 		p_creation_date => l_category_usage_tbl(l_index).creation_date,
2588 		p_last_updated_by => l_category_usage_tbl(l_index).last_updated_by,
2589 		p_last_update_date => l_category_usage_tbl(l_index).last_update_date,
2590 		p_last_update_login => l_category_usage_tbl(l_index).last_update_login,
2591             p_loader_timestamp => p_loader_timestamp,
2592 		    p_pass => p_pass,
2593             p_copy_redo_flag => l_copy_redo_flag
2594           );
2595         else
2596           AK_REGION2_PVT.UPDATE_CATEGORY_USAGE (
2597             p_validation_level => p_validation_level,
2598             p_api_version_number => 1.0,
2599             p_msg_count => l_msg_count,
2600             p_msg_data => l_msg_data,
2601             p_return_status => l_return_status,
2602               p_region_application_id =>
2603                                   l_category_usage_tbl(l_index).region_application_id,
2604               p_region_code => l_category_usage_tbl(l_index).region_code,
2605               p_attribute_application_id =>
2606                                   l_category_usage_tbl(l_index).attribute_application_id,
2607               p_attribute_code => l_category_usage_tbl(l_index).attribute_code,
2608                           p_category_name => l_category_usage_tbl(l_index).category_name,
2609                 p_category_id => l_category_usage_tbl(l_index).category_id,
2610                 p_application_id => l_category_usage_tbl(l_index).application_id,
2611                 p_show_all => l_category_usage_tbl(l_index).show_all,
2612 		p_created_by => l_category_usage_tbl(l_index).created_by,
2613 		p_creation_date => l_category_usage_tbl(l_index).creation_date,
2614                 p_last_updated_by => l_category_usage_tbl(l_index).last_updated_by,
2615                 p_last_update_date => l_category_usage_tbl(l_index).last_update_date,
2616                 p_last_update_login => l_category_usage_tbl(l_index).last_update_login,
2617             p_loader_timestamp => p_loader_timestamp,
2618                     p_pass => p_pass,
2619             p_copy_redo_flag => l_copy_redo_flag
2620           );
2621         end if; -- /* if CATEGORY_USAGE_EXISTS */
2622 	end if;
2623         --
2624         -- If API call returns with an error status, upload aborts
2625         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
2626         (l_return_status = FND_API.G_RET_STS_ERROR) then
2627           RAISE FND_API.G_EXC_ERROR;
2628         end if; -- /* if l_return_status */
2629 		--
2630 		-- if validation fails, then this record should go to second pass
2631 		-- validation usually fails when referenced record has not been created yet
2632 --		if (l_copy_redo_flag) then
2633 --		  G_LOV_RELATION_REDO_INDEX := G_LOV_RELATION_REDO_INDEX + 1;
2634 --		  G_LOV_RELATION_REDO_TBL(G_LOV_RELATION_REDO_INDEX) := l_lov_relation_tbl(l_index);
2635 --		  l_copy_redo_flag := FALSE;
2636 --		end if; --/* if l_copy_redo_flag */
2637       end if; -- /* end if l_category_usage_tbl.exists(l_index) */
2638     end loop; -- /* end for l_index in l_category_usage_tbl */
2639   end if;
2640 
2641 /*
2642   --
2643   -- create or update all region graphs to the database
2644   --
2645   if (l_graph_tbl.count > 0) then
2646     for l_index in l_graph_tbl.FIRST .. l_graph_tbl.LAST loop
2647       if (l_graph_tbl.exists(l_index)) then
2648         if AK_REGION_PVT.GRAPH_EXISTS (
2649             p_api_version_number => 1.0,
2650             p_return_status => l_return_status,
2651             p_region_application_id => l_graph_tbl(l_index).region_application_id,
2652             p_region_code => l_graph_tbl(l_index).region_code,
2653 	    p_graph_number => l_graph_tbl(l_index).graph_number) then
2654           --
2655           -- Update Region Graphs only if G_UPDATE_MODE is TRUE
2656           --
2657           if (AK_UPLOAD_GRP.G_UPDATE_MODE) then
2658             AK_REGION_PVT.UPDATE_GRAPH (
2659               p_validation_level => p_validation_level,
2660               p_api_version_number => 1.0,
2661               p_msg_count => l_msg_count,
2662               p_msg_data => l_msg_data,
2663               p_return_status => l_return_status,
2664               p_region_application_id =>l_graph_tbl(l_index).region_application_id,
2665 	      p_region_code => l_graph_tbl(l_index).region_code,
2666 	      p_graph_number => l_graph_tbl(l_index).graph_number,
2667 	      p_graph_style => l_graph_tbl(l_index).graph_style,
2668 	      p_display_flag => l_graph_tbl(l_index).display_flag,
2669 	      p_depth_radius => l_graph_tbl(l_index).depth_radius,
2670 	      p_graph_title => l_graph_tbl(l_index).graph_title,
2671 	      p_y_axis_label => l_graph_tbl(l_index).y_axis_label,
2672 		p_created_by => l_graph_tbl(l_index).created_by,
2673 		p_creation_date => l_graph_tbl(l_index).creation_date,
2674 		p_last_updated_by => l_graph_tbl(l_index).last_updated_by,
2675 		p_last_update_date => l_graph_tbl(l_index).last_update_date,
2676 		p_last_update_login => l_graph_tbl(l_index).last_update_login,
2677               p_loader_timestamp => p_loader_timestamp,
2678                       p_pass => p_pass,
2679               p_copy_redo_flag => l_copy_redo_flag
2680             );
2681                   -- update non-customized data only
2682           elsif ( AK_UPLOAD_GRP.G_NO_CUSTOM_UPDATE ) then
2683                 select arg.last_updated_by, argt.last_updated_by into l_user_id1, l_user_id2
2684                 from ak_region_graphs arg, ak_region_graphs_tl argt
2685                 where arg.region_code = l_graph_tbl(l_index).region_code
2686 		and arg.region_application_id = l_graph_tbl(l_index).region_application_id
2687 		and arg.graph_number = l_graph_tbl(l_index).graph_number
2688 		and arg.region_code = argt.region_code
2689 		and arg.region_application_id = argt.region_application_id
2690 		and arg.graph_number = argt.graph_number
2691 		and argt.language = userenv('LANG');
2692 		if (( l_user_id1 = 1 or l_user_id1 = 2 ) and
2693 			( l_user_id2 = 1 or l_user_id2 = 2 )) then
2694                     AK_REGION_PVT.UPDATE_GRAPH (
2695                       p_validation_level => p_validation_level,
2696                       p_api_version_number => 1.0,
2697                       p_msg_count => l_msg_count,
2698                       p_msg_data => l_msg_data,
2699                       p_return_status => l_return_status,
2700                       p_region_application_id =>l_graph_tbl(l_index).region_application_id,
2701 		      p_region_code => l_graph_tbl(l_index).region_code,
2702 		      p_graph_number => l_graph_tbl(l_index).graph_number,
2703 		      p_graph_style => l_graph_tbl(l_index).graph_style,
2704 		      p_display_flag => l_graph_tbl(l_index).display_flag,
2705 		      p_depth_Radius => l_graph_tbl(l_index).depth_radius,
2706 		      p_graph_title => l_graph_tbl(l_index).graph_title,
2707 		      p_y_axis_label => l_graph_tbl(l_index).y_axis_label,
2708                 p_created_by => l_graph_tbl(l_index).created_by,
2709                 p_creation_date => l_graph_tbl(l_index).creation_date,
2710                 p_last_updated_by => l_graph_tbl(l_index).last_updated_by,
2711                 p_last_update_date => l_graph_tbl(l_index).last_update_date,
2712                 p_last_update_login => l_graph_tbl(l_index).last_update_login,
2713                       p_loader_timestamp => p_loader_timestamp,
2714                               p_pass => p_pass,
2715                       p_copy_redo_flag => l_copy_redo_flag
2716                     );
2717                 end if; -- if l_user_id1 = 1 and l_user_id2 = 1
2718           end if; --  if G_UPDATE_MODE G_NO_CUSTOM_UPDATE
2719         else
2720           AK_REGION_PVT.CREATE_GRAPH (
2721             p_validation_level => p_validation_level,
2722             p_api_version_number => 1.0,
2723             p_msg_count => l_msg_count,
2724             p_msg_data => l_msg_data,
2725             p_return_status => l_return_status,
2726             p_region_application_id =>l_graph_tbl(l_index).region_application_id,
2727 	    p_region_code => l_graph_tbl(l_index).region_code,
2728 	    p_graph_number => l_graph_tbl(l_index).graph_number,
2729 	    p_graph_style => l_graph_tbl(l_index).graph_style,
2730 	    p_display_flag => l_graph_tbl(l_index).display_flag,
2731 	    p_depth_radius => l_graph_tbl(l_index).depth_radius,
2732 	    p_graph_title => l_graph_tbl(l_index).graph_title,
2733 	    p_y_axis_label => l_graph_tbl(l_index).y_axis_label,
2734                 p_created_by => l_graph_tbl(l_index).created_by,
2735                 p_creation_date => l_graph_tbl(l_index).creation_date,
2736                 p_last_updated_by => l_graph_tbl(l_index).last_updated_by,
2737                 p_last_update_date => l_graph_tbl(l_index).last_update_date,
2738                 p_last_update_login => l_graph_tbl(l_index).last_update_login,
2739             p_loader_timestamp => p_loader_timestamp,
2740                     p_pass => p_pass,
2741             p_copy_redo_flag => l_copy_redo_flag
2742           );
2743         end if; --  if ITEM_EXISTS
2744         --
2745         -- If API call returns with an error status, upload aborts
2746         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
2747         (l_return_status = FND_API.G_RET_STS_ERROR) then
2748           RAISE FND_API.G_EXC_ERROR;
2749         end if; --  if l_return_status
2750                 --
2751                -- if validation fails, then this record should go to second pass
2752 		if (l_copy_redo_flag) then
2753                   G_GRAPH_REDO_INDEX := G_GRAPH_REDO_INDEX + 1;
2754 		  G_GRAPH_REDO_TBL(G_GRAPH_REDO_INDEX) := l_graph_tbl(l_index);
2755 		  l_copy_redo_flag := FALSE;
2756                 end if; -- if l_copy_redo_flag
2757       end if; --  if l_item_tbl.exists
2758     end loop;
2759   end if; --  if l_item_tbl.count > 0
2760 
2761   --
2762   -- create or update all region graph columns to the database
2763   -- commented out update due to no updateable columns
2764   --
2765   if (l_graph_column_tbl.count > 0) then
2766     for l_index in l_graph_column_tbl.FIRST .. l_graph_column_tbl.LAST loop
2767       if (l_graph_column_tbl.exists(l_index)) then
2768          if (AK_REGION2_PVT.GRAPH_COLUMN_EXISTS(
2769 	   p_api_version_number => 1.0,
2770 	   p_return_status => l_return_status,
2771 	   p_region_application_id => l_graph_column_tbl(l_index).region_application_id,
2772 	   p_region_code => l_graph_column_tbl(l_index).region_code,
2773 	   p_graph_number => l_graph_column_tbl(l_index).graph_number,
2774 	   p_attribute_application_id => l_graph_column_tbl(l_index).attribute_application_id,
2775 	   p_attribute_code => l_graph_column_tbl(l_index).attribute_code) = false) then */
2776 /*          --
2777           -- Update Region graph columns if G_UPDATE_MODE is TRUE
2778           --
2779           if (AK_UPLOAD_GRP.G_UPDATE_MODE) then
2780             AK_REGION2_PVT.UPDATE_GRAPH_COLUMN (
2781               p_validation_level => p_validation_level,
2782               p_api_version_number => 1.0,
2783               p_msg_count => l_msg_count,
2784               p_msg_data => l_msg_data,
2785               p_return_status => l_return_status,
2786               p_region_application_id =>l_graph_column_tbl(l_index).region_application_id,
2787 	      p_region_code => l_graph_column_tbl(l_index).region_code,
2788 	      p_graph_number => l_graph_column_tbl(l_index).graph_number,
2789 	      p_attribute_application_id => l_graph_column_tbl(l_index).attribute_application_id,
2790 	      p_attribute_code => l_graph_column_tbl(l_index).attribute_code,
2791 		p_created_by => l_graph_column_tbl(l_index).created_by,
2792 		p_creation_date => l_graph_column_tbl(l_index).creation_date,
2793 		p_last_updated_by => l_graph_column_tbl(l_index).last_updated_by,
2794 		p_last_update_date => l_graph_column_tbl(l_index).last_update_date,
2795 		p_last_update_login => l_graph_column_tbl(l_index).last_update_login,
2796               p_loader_timestamp => p_loader_timestamp,
2797                       p_pass => p_pass,
2798               p_copy_redo_flag => l_copy_redo_flag
2799             );
2800                   -- update non-customized data only
2801           elsif ( AK_UPLOAD_GRP.G_NO_CUSTOM_UPDATE ) then
2802 		select last_updated_by into l_user_id1
2803 		from ak_region_graph_columns
2804 	 	where region_code = l_graph_column_tbl(l_index).region_code
2805 		and region_application_id = l_graph_column_tbl(l_index).region_application_id
2806 		and graph_number = l_graph_column_tbl(l_index).graph_number
2807 		and attribute_application_id = l_graph_column_tbl(l_index).attribute_application_id
2808 		and attribute_code = l_graph_column_tbl(l_index).attribute_code;
2809 		if ( l_user_id1 = 1 or l_user_id1 = 2) then
2810 		AK_REGION2_PVT.UPDATE_GRAPH_COLUMN (
2811                       p_validation_level => p_validation_level,
2812                       p_api_version_number => 1.0,
2813                       p_msg_count => l_msg_count,
2814                       p_msg_data => l_msg_data,
2815                       p_return_status => l_return_status,
2816                       p_region_application_id => l_graph_column_tbl(l_index).region_application_id,
2817 		      p_region_code => l_graph_column_tbl(l_index).region_code,
2818 		      p_graph_number => l_graph_column_tbl(l_index).graph_number,
2819 		      p_attribute_application_id => l_graph_column_tbl(l_index).attribute_application_id,
2820 		      p_attribute_code => l_graph_column_tbl(l_index).attribute_code,
2821                 p_created_by => l_graph_column_tbl(l_index).created_by,
2822                 p_creation_date => l_graph_column_tbl(l_index).creation_date,
2823                 p_last_updated_by => l_graph_column_tbl(l_index).last_updated_by,
2824                 p_last_update_date => l_graph_column_tbl(l_index).last_update_date,
2825                 p_last_update_login => l_graph_column_tbl(l_index).last_update_login,
2826                       p_loader_timestamp => p_loader_timestamp,
2827                               p_pass => p_pass,
2828                       p_copy_redo_flag => l_copy_redo_flag
2829                     );
2830                 end if; */ /*if l_user_id1 = 1 */ /*
2831           end if; -- */ /* if G_UPDATE_MODE G_NO_CUSTOM_UPDATE */ /*
2832         else */
2833 /*
2834           AK_REGION2_PVT.CREATE_GRAPH_COLUMN (
2835             p_validation_level => p_validation_level,
2836             p_api_version_number => 1.0,
2837             p_msg_count => l_msg_count,
2838             p_msg_data => l_msg_data,
2839             p_return_status => l_return_status,
2840             p_region_application_id => l_graph_column_tbl(l_index).region_application_id,
2841 	    p_region_code => l_graph_column_tbl(l_index).region_code,
2842 	    p_graph_number => l_graph_column_tbl(l_index).graph_number,
2843 	    p_attribute_application_id => l_graph_column_tbl(l_index).attribute_application_id,
2844 	    p_attribute_code => l_graph_column_tbl(l_index).attribute_code,
2845                 p_created_by => l_graph_column_tbl(l_index).created_by,
2846                 p_creation_date => l_graph_column_tbl(l_index).creation_date,
2847                 p_last_updated_by => l_graph_column_tbl(l_index).last_updated_by,
2848                 p_last_update_date => l_graph_column_tbl(l_index).last_update_date,
2849                 p_last_update_login => l_graph_column_tbl(l_index).last_update_login,
2850             p_loader_timestamp => p_loader_timestamp,
2851                     p_pass => p_pass,
2852             p_copy_redo_flag => l_copy_redo_flag
2853           );
2854         end if; --  if GRAPH_EXISTS
2855         --
2856         -- If API call returns with an error status, upload aborts
2857         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
2858         (l_return_status = FND_API.G_RET_STS_ERROR) then
2859           RAISE FND_API.G_EXC_ERROR;
2860         end if; --  if l_return_status
2861                 --
2862                 -- if validation fails, then this record should go to second pass
2863                 if (l_copy_redo_flag) then
2864                   G_GRAPH_COLUMN_REDO_INDEX := G_GRAPH_COLUMN_REDO_INDEX + 1;
2865 		  G_GRAPH_COLUMN_REDO_TBL(G_GRAPH_COLUMN_REDO_INDEX) := l_graph_column_tbl(l_index);
2866 		  l_copy_redo_flag := FALSE;
2867                 end if; -- if l_copy_redo_flag
2868       end if; --  if l_graph_tbl.exists
2869     end loop;
2870   end if; --  if l_graph_tbl.count > 0
2871 */
2872 
2873   --
2874   -- Load line number of the last file line processed
2875   --
2876   p_line_num_out := l_line_num;
2877 
2878   p_return_status := FND_API.G_RET_STS_SUCCESS;
2879 
2880   --dbms_output.put_line('Leaving region upload: ' ||
2881   --                            to_char(sysdate, 'MON-DD HH24:MI:SS'));
2882 
2883 EXCEPTION
2884   WHEN FND_API.G_EXC_ERROR THEN
2885     p_return_status := FND_API.G_RET_STS_ERROR;
2886     --rollback to Start_Upload;
2887   WHEN VALUE_ERROR THEN
2888     p_return_status := FND_API.G_RET_STS_ERROR;
2889     FND_MESSAGE.SET_NAME('AK','AK_REGION_VALUE_ERROR');
2890     FND_MESSAGE.SET_TOKEN('KEY',to_char(l_region_rec.region_application_id)||' '||
2891     						l_region_rec.region_code);
2892     FND_MSG_PUB.Add;
2893 	FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
2894                            SUBSTR (SQLERRM, 1, 240)||': '||l_column||'='||l_token );
2895 	FND_MSG_PUB.Add;
2896   WHEN OTHERS THEN
2897     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2898     --rollback to Start_Upload;
2899     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
2900                            SUBSTR (SQLERRM, 1, 240) );
2901     FND_MSG_PUB.Add;
2902 end UPLOAD_REGION;
2903 
2904 --=======================================================
2905 --  Procedure   UPLOAD_REGION_SECOND
2906 --
2907 --  Usage       Private API for loading regions that were
2908 --              failed during its first pass
2909 --              This API should only be called by other APIs
2910 --              that are owned by the Core Modules Team (AK).
2911 --
2912 --  Desc        This API reads the region data from PL/SQL table
2913 --              that was prepared during 1st pass, then processes
2914 --              the data, and loads them to the database. The tables
2915 --              are updated with the timestamp passed. This API
2916 --              will process the file until the EOF is reached,
2917 --              a parse error is encountered, or when data for
2918 --              a different business object is read from the file.
2919 --
2920 --  Results     The API returns the standard p_return_status parameter
2921 --              indicating one of the standard return statuses :
2922 --                  * Unexpected error
2923 --                  * Error
2924 --                  * Success
2925 --  Parameters  p_validation_level : IN required
2926 --                  validation level
2927 --
2928 --  Version     Initial version number  =   1.0
2929 --  History     Current version number  =   1.0
2930 --=======================================================
2931 procedure UPLOAD_REGION_SECOND (
2932   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
2933   p_return_status            OUT NOCOPY     VARCHAR2,
2934   p_loader_timestamp         IN      DATE := FND_API.G_MISS_DATE,
2935   p_pass                     IN      NUMBER := 2
2936 ) is
2937   l_api_name                 CONSTANT varchar2(30) := 'Upload_Region_Second';
2938   l_rec_index                NUMBER;
2939   l_return_status            VARCHAR2(1);
2940   l_msg_count                NUMBER;
2941   l_msg_data                 VARCHAR2(240);
2942   l_copy_redo_flag           BOOLEAN;
2943   l_user_id1				 NUMBER;
2944   l_user_id2				 NUMBER;
2945   l_update1				DATE;
2946   l_update2				DATE;
2947 begin
2948   --
2949   -- create or update all regions to the database
2950   --
2951   if (G_REGION_REDO_INDEX > 0) then
2952     for l_index in G_REGION_REDO_TBL.FIRST .. G_REGION_REDO_TBL.LAST loop
2953       if (G_REGION_REDO_TBL.exists(l_index)) then
2954         if AK_REGION_PVT.REGION_EXISTS (
2955             p_api_version_number => 1.0,
2956             p_return_status => l_return_status,
2957             p_region_application_id =>
2958                                G_REGION_REDO_TBL(l_index).region_application_id,
2959             p_region_code => G_REGION_REDO_TBL(l_index).region_code) then
2960           AK_REGION_PVT.UPDATE_REGION (
2961             p_validation_level => p_validation_level,
2962             p_api_version_number => 1.0,
2963             p_msg_count => l_msg_count,
2964             p_msg_data => l_msg_data,
2965             p_return_status => l_return_status,
2966             p_region_application_id =>
2967                                 G_REGION_REDO_TBL(l_index).region_application_id,
2968             p_region_code => G_REGION_REDO_TBL(l_index).region_code,
2969             p_database_object_name =>G_REGION_REDO_TBL(l_index).database_object_name,
2970             p_region_style => G_REGION_REDO_TBL(l_index).region_style,
2971             p_num_columns => G_REGION_REDO_TBL(l_index).num_columns,
2972             p_icx_custom_call => G_REGION_REDO_TBL(l_index).icx_custom_call,
2973             p_region_defaulting_api_pkg =>
2974                G_REGION_REDO_TBL(l_index).region_defaulting_api_pkg,
2975             p_region_defaulting_api_proc =>
2976                G_REGION_REDO_TBL(l_index).region_defaulting_api_proc,
2977             p_region_validation_api_pkg =>
2978                G_REGION_REDO_TBL(l_index).region_validation_api_pkg,
2979             p_region_validation_api_proc =>
2980                G_REGION_REDO_TBL(l_index).region_validation_api_proc,
2981             p_appmodule_object_type =>
2982                G_REGION_REDO_TBL(l_index).applicationmodule_object_type,
2983             p_num_rows_display =>
2984                G_REGION_REDO_TBL(l_index).num_rows_display,
2985             p_region_object_type =>
2986                G_REGION_REDO_TBL(l_index).region_object_type,
2987             p_image_file_name =>
2988                G_REGION_REDO_TBL(l_index).image_file_name,
2989             p_isform_flag => G_REGION_REDO_TBL(l_index).isform_flag,
2990             p_help_target => G_REGION_REDO_TBL(l_index).help_target,
2991             p_style_sheet_filename => G_REGION_REDO_TBL(l_index).style_sheet_filename,
2992 			p_version => G_REGION_REDO_TBL(l_index).version,
2993 			p_applicationmodule_usage_name => G_REGION_REDO_TBL(l_index).applicationmodule_usage_name,
2994 			p_add_indexed_children => G_REGION_REDO_TBL(l_index).add_indexed_children,
2995 			p_stateful_flag => G_REGION_REDO_TBL(l_index).stateful_flag,
2996 			p_function_name => G_REGION_REDO_TBL(l_index).function_name,
2997 			p_children_view_usage_name => G_REGION_REDO_TBL(l_index).children_view_usage_name,
2998 	 p_search_panel => G_REGION_REDO_TBL(l_index).search_panel,
2999          p_advanced_search_panel => G_REGION_REDO_TBL(l_index).advanced_search_panel,
3000          p_customize_panel => G_REGION_REDO_TBL(l_index).customize_panel,
3001          p_default_search_panel => G_REGION_REDO_TBL(l_index).default_search_panel,
3002          p_results_based_search => G_REGION_REDO_TBL(l_index).results_based_search,
3003          p_display_graph_table => G_REGION_REDO_TBL(l_index).display_graph_table,
3004 	 p_disable_header => G_REGION_REDO_TBL(l_index).disable_header,
3005 	 p_standalone => G_REGION_REDO_TBL(l_index).standalone,
3006 	 p_auto_customization_criteria => G_REGION_REDO_TBL(l_index).auto_customization_criteria,
3007             p_attribute_category => G_REGION_REDO_TBL(l_index).attribute_category,
3008 			p_attribute1 => G_REGION_REDO_TBL(l_index).attribute1,
3009 			p_attribute2 => G_REGION_REDO_TBL(l_index).attribute2,
3010 			p_attribute3 => G_REGION_REDO_TBL(l_index).attribute3,
3011 			p_attribute4 => G_REGION_REDO_TBL(l_index).attribute4,
3012 			p_attribute5 => G_REGION_REDO_TBL(l_index).attribute5,
3013 			p_attribute6 => G_REGION_REDO_TBL(l_index).attribute6,
3014 			p_attribute7 => G_REGION_REDO_TBL(l_index).attribute7,
3015 			p_attribute8 => G_REGION_REDO_TBL(l_index).attribute8,
3016 			p_attribute9 => G_REGION_REDO_TBL(l_index).attribute9,
3017 			p_attribute10 => G_REGION_REDO_TBL(l_index).attribute10,
3018 			p_attribute11 => G_REGION_REDO_TBL(l_index).attribute11,
3019 			p_attribute12 => G_REGION_REDO_TBL(l_index).attribute12,
3020 			p_attribute13 => G_REGION_REDO_TBL(l_index).attribute13,
3021 			p_attribute14 => G_REGION_REDO_TBL(l_index).attribute14,
3022 			p_attribute15 => G_REGION_REDO_TBL(l_index).attribute15,
3023             p_name => G_REGION_REDO_TBL(l_index).name,
3024             p_description => G_REGION_REDO_TBL(l_index).description,
3025 		p_created_by => G_REGION_REDO_TBL(l_index).created_by,
3026 		p_creation_date => G_REGION_REDO_TBL(l_index).creation_date,
3027 		p_last_updated_by => G_REGION_REDO_TBL(l_index).last_updated_by,
3028 		p_last_update_date => G_REGION_REDO_TBL(l_index).last_update_date,
3029 		p_last_update_login => G_REGION_REDO_TBL(l_index).last_update_login,
3030             p_loader_timestamp => p_loader_timestamp,
3031 		    p_pass => p_pass,
3032             p_copy_redo_flag => l_copy_redo_flag
3033           );
3034         else
3035           AK_REGION_PVT.CREATE_REGION (
3036             p_validation_level => p_validation_level,
3037             p_api_version_number => 1.0,
3038             p_msg_count => l_msg_count,
3039             p_msg_data => l_msg_data,
3040             p_return_status => l_return_status,
3041             p_region_application_id =>
3042                                 G_REGION_REDO_TBL(l_index).region_application_id,
3043             p_region_code => G_REGION_REDO_TBL(l_index).region_code,
3044             p_database_object_name =>G_REGION_REDO_TBL(l_index).database_object_name,
3045             p_region_style => G_REGION_REDO_TBL(l_index).region_style,
3046             p_num_columns => G_REGION_REDO_TBL(l_index).num_columns,
3047             p_icx_custom_call => G_REGION_REDO_TBL(l_index).icx_custom_call,
3048             p_region_defaulting_api_pkg =>
3049                G_REGION_REDO_TBL(l_index).region_defaulting_api_pkg,
3050             p_region_defaulting_api_proc =>
3051                G_REGION_REDO_TBL(l_index).region_defaulting_api_proc,
3052             p_region_validation_api_pkg =>
3053                G_REGION_REDO_TBL(l_index).region_validation_api_pkg,
3054             p_region_validation_api_proc =>
3055                G_REGION_REDO_TBL(l_index).region_validation_api_proc,
3056             p_appmodule_object_type =>
3057                G_REGION_REDO_TBL(l_index).applicationmodule_object_type,
3058             p_num_rows_display =>
3059                G_REGION_REDO_TBL(l_index).num_rows_display,
3060             p_region_object_type =>
3061                G_REGION_REDO_TBL(l_index).region_object_type,
3062             p_image_file_name =>
3063                G_REGION_REDO_TBL(l_index).image_file_name,
3064             p_isform_flag => G_REGION_REDO_TBL(l_index).isform_flag,
3065             p_help_target => G_REGION_REDO_TBL(l_index).help_target,
3066             p_style_sheet_filename => G_REGION_REDO_TBL(l_index).style_sheet_filename,
3067 			p_version => G_REGION_REDO_TBL(l_index).version,
3068 			p_applicationmodule_usage_name => G_REGION_REDO_TBL(l_index).applicationmodule_usage_name,
3069             p_add_indexed_children => G_REGION_REDO_TBL(l_index).add_indexed_children,
3070 	    p_stateful_flag => G_REGION_REDO_TBL(l_index).stateful_flag,
3071 	    p_function_name => G_REGION_REDO_TBL(l_index).function_name,
3072 	    p_children_view_usage_name => G_REGION_REDO_TBL(l_index).children_view_usage_name,
3073 	p_search_panel => G_REGION_REDO_TBL(l_index).search_panel,
3074         p_advanced_search_panel => G_REGION_REDO_TBL(l_index).advanced_search_panel,
3075         p_customize_panel => G_REGION_REDO_TBL(l_index).customize_panel,
3076         p_default_search_panel => G_REGION_REDO_TBL(l_index).default_search_panel,
3077         p_results_based_search => G_REGION_REDO_TBL(l_index).results_based_search,
3078         p_display_graph_table => G_REGION_REDO_TBL(l_index).display_graph_table,
3079 	p_disable_header => G_REGION_REDO_TBL(l_index).disable_header,
3080 	p_standalone => G_REGION_REDO_TBL(l_index).standalone,
3081 	p_auto_customization_criteria => G_REGION_REDO_TBL(l_index).auto_customization_criteria,
3082         p_attribute_category => G_REGION_REDO_TBL(l_index).attribute_category,
3083 			p_attribute1 => G_REGION_REDO_TBL(l_index).attribute1,
3084 			p_attribute2 => G_REGION_REDO_TBL(l_index).attribute2,
3085 			p_attribute3 => G_REGION_REDO_TBL(l_index).attribute3,
3086 			p_attribute4 => G_REGION_REDO_TBL(l_index).attribute4,
3087 			p_attribute5 => G_REGION_REDO_TBL(l_index).attribute5,
3088 			p_attribute6 => G_REGION_REDO_TBL(l_index).attribute6,
3089 			p_attribute7 => G_REGION_REDO_TBL(l_index).attribute7,
3090 			p_attribute8 => G_REGION_REDO_TBL(l_index).attribute8,
3091 			p_attribute9 => G_REGION_REDO_TBL(l_index).attribute9,
3092 			p_attribute10 => G_REGION_REDO_TBL(l_index).attribute10,
3093 			p_attribute11 => G_REGION_REDO_TBL(l_index).attribute11,
3094 			p_attribute12 => G_REGION_REDO_TBL(l_index).attribute12,
3095 			p_attribute13 => G_REGION_REDO_TBL(l_index).attribute13,
3096 			p_attribute14 => G_REGION_REDO_TBL(l_index).attribute14,
3097 			p_attribute15 => G_REGION_REDO_TBL(l_index).attribute15,
3098             p_name => G_REGION_REDO_TBL(l_index).name,
3099             p_description => G_REGION_REDO_TBL(l_index).description,
3100 	p_created_by => G_REGION_REDO_TBL(l_index).created_by,
3101 	p_creation_date => G_REGION_REDO_TBL(l_index).creation_date,
3102 	p_last_updated_by => G_REGION_REDO_TBL(l_index).last_updated_by,
3103 	p_last_update_date => G_REGION_REDO_TBL(l_index).last_update_date,
3104 	p_last_update_login => G_REGION_REDO_TBL(l_index).last_update_login,
3105             p_loader_timestamp => p_loader_timestamp,
3106 		    p_pass => p_pass,
3107             p_copy_redo_flag => l_copy_redo_flag
3108           );
3109         end if; -- /* if REGION_EXISTS */
3110         --
3111         -- If API call returns with an error status, upload aborts
3112         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
3113         (l_return_status = FND_API.G_RET_STS_ERROR) then
3114           RAISE FND_API.G_EXC_ERROR;
3115         end if; -- /* if l_return_status */
3116       end if; -- /* if G_REGION_REDO_TBL.exists(l_index) */
3117     end loop;
3118   end if; -- /* if G_REGION_REDO_INDEX > 0 */
3119 
3120   --
3121   -- create or update all region items to the database
3122   --
3123   if (G_ITEM_REDO_INDEX > 0) then
3124     for l_index in G_ITEM_REDO_TBL.FIRST .. G_ITEM_REDO_TBL.LAST loop
3125       if (G_ITEM_REDO_TBL.exists(l_index)) then
3126         if AK_REGION_PVT.ITEM_EXISTS (
3127             p_api_version_number => 1.0,
3128             p_return_status => l_return_status,
3129             p_region_application_id =>G_ITEM_REDO_TBL(l_index).region_application_id,
3130             p_region_code => G_ITEM_REDO_TBL(l_index).region_code,
3131             p_attribute_application_id =>
3132                                    G_ITEM_REDO_TBL(l_index).attribute_application_id,
3133             p_attribute_code => G_ITEM_REDO_TBL(l_index).attribute_code) then
3134           --
3135           -- Update Region Items only if G_UPDATE_MODE is TRUE
3136           --
3137           if (AK_UPLOAD_GRP.G_UPDATE_MODE) then
3138             AK_REGION_PVT.UPDATE_ITEM (
3139               p_validation_level => p_validation_level,
3140               p_api_version_number => 1.0,
3141               p_msg_count => l_msg_count,
3142               p_msg_data => l_msg_data,
3143               p_return_status => l_return_status,
3144               p_region_application_id =>G_ITEM_REDO_TBL(l_index).region_application_id,
3145               p_region_code => G_ITEM_REDO_TBL(l_index).region_code,
3146               p_attribute_application_id =>
3147                                G_ITEM_REDO_TBL(l_index).attribute_application_id,
3148               p_attribute_code => G_ITEM_REDO_TBL(l_index).attribute_code,
3149               p_display_sequence => G_ITEM_REDO_TBL(l_index).display_sequence,
3150               p_node_display_flag => G_ITEM_REDO_TBL(l_index).node_display_flag,
3151               p_node_query_flag => G_ITEM_REDO_TBL(l_index).node_query_flag,
3152               p_attribute_label_length =>
3153                                G_ITEM_REDO_TBL(l_index).attribute_label_length,
3154               p_display_value_length =>
3155                                G_ITEM_REDO_TBL(l_index).display_value_length,
3156               p_bold => G_ITEM_REDO_TBL(l_index).bold,
3157               p_italic => G_ITEM_REDO_TBL(l_index).italic,
3158               p_vertical_alignment => G_ITEM_REDO_TBL(l_index).vertical_alignment,
3159               p_horizontal_alignment => G_ITEM_REDO_TBL(l_index).horizontal_alignment,
3160               p_item_style => G_ITEM_REDO_TBL(l_index).item_style,
3161               p_object_attribute_flag =>G_ITEM_REDO_TBL(l_index).object_attribute_flag,
3162               p_icx_custom_call => G_ITEM_REDO_TBL(l_index).icx_custom_call,
3163               p_update_flag => G_ITEM_REDO_TBL(l_index).update_flag,
3164               p_required_flag => G_ITEM_REDO_TBL(l_index).required_flag,
3165               p_security_code => G_ITEM_REDO_TBL(l_index).security_code,
3166               p_default_value_varchar2 =>
3167                  G_ITEM_REDO_TBL(l_index).default_value_varchar2,
3168               p_default_value_number =>
3169                  G_ITEM_REDO_TBL(l_index).default_value_number,
3170               p_default_value_date =>
3171                  G_ITEM_REDO_TBL(l_index).default_value_date,
3172               p_lov_region_application_id =>
3173                  G_ITEM_REDO_TBL(l_index).lov_region_application_id,
3174               p_lov_region_code => G_ITEM_REDO_TBL(l_index).lov_region_code,
3175               p_lov_foreign_key_name => G_ITEM_REDO_TBL(l_index).lov_foreign_key_name,
3176               p_lov_attribute_application_id =>
3177                  G_ITEM_REDO_TBL(l_index).lov_attribute_application_id,
3178               p_lov_attribute_code => G_ITEM_REDO_TBL(l_index).lov_attribute_code,
3179               p_lov_default_flag => G_ITEM_REDO_TBL(l_index).lov_default_flag,
3180               p_region_defaulting_api_pkg =>
3181                  G_ITEM_REDO_TBL(l_index).region_defaulting_api_pkg,
3182               p_region_defaulting_api_proc =>
3183                  G_ITEM_REDO_TBL(l_index).region_defaulting_api_proc,
3184               p_region_validation_api_pkg =>
3185                  G_ITEM_REDO_TBL(l_index).region_validation_api_pkg,
3186               p_region_validation_api_proc =>
3187                  G_ITEM_REDO_TBL(l_index).region_validation_api_proc,
3188               p_order_sequence => G_ITEM_REDO_TBL(l_index).order_sequence,
3189               p_order_direction => G_ITEM_REDO_TBL(l_index).order_direction,
3190 			  p_display_height => G_ITEM_REDO_TBL(l_index).display_height,
3191 			  p_submit => G_ITEM_REDO_TBL(l_index).submit,
3192 			  p_encrypt => G_ITEM_REDO_TBL(l_index).encrypt,
3193 			  p_css_class_name => G_ITEM_REDO_TBL(l_index).css_class_name,
3194 			  p_view_usage_name => G_ITEM_REDO_TBL(l_index).view_usage_name,
3195 			  p_view_attribute_name => G_ITEM_REDO_TBL(l_index).view_attribute_name,
3196 			  p_nested_region_appl_id => G_ITEM_REDO_TBL(l_index).nested_region_application_id,
3197 			  p_nested_region_code => G_ITEM_REDO_TBL(l_index).nested_region_code,
3198 			  p_url => G_ITEM_REDO_TBL(l_index).url,
3199 			  p_poplist_viewobject => G_ITEM_REDO_TBL(l_index).poplist_viewobject,
3200 			  p_poplist_display_attr => G_ITEM_REDO_TBL(l_index).poplist_display_attr,
3201 			  p_poplist_value_attr => G_ITEM_REDO_TBL(l_index).poplist_value_attr,
3202 			  p_image_file_name => G_ITEM_REDO_TBL(l_index).image_file_name,
3203 			  p_item_name => G_ITEM_REDO_TBL(l_index).description,
3204 			  p_css_label_class_name => G_ITEM_REDO_TBL(l_index).css_label_class_name,
3205 			  p_menu_name => G_ITEM_REDO_TBL(l_index).menu_name,
3206 			  p_flexfield_name => G_ITEM_REDO_TBL(l_index).flexfield_name,
3207 			  p_flexfield_application_id => G_ITEM_REDO_TBL(l_index).flexfield_application_id,
3208               p_tabular_function_code    => G_ITEM_REDO_TBL(l_index).tabular_function_code,
3209               p_tip_type                 => G_ITEM_REDO_TBL(l_index).tip_type,
3210               p_tip_message_name         => G_ITEM_REDO_TBL(l_index).tip_message_name,
3211               p_tip_message_application_id  => G_ITEM_REDO_TBL(l_index).tip_message_application_id ,
3212               p_flex_segment_list        => G_ITEM_REDO_TBL(l_index).flex_segment_list,
3213               p_entity_id  => G_ITEM_REDO_TBL(l_index).entity_id ,
3214               p_anchor => G_ITEM_REDO_TBL(l_index).anchor,
3215               p_poplist_view_usage_name => G_ITEM_REDO_TBL(l_index).poplist_view_usage_name,
3216 	      p_user_customizable => G_ITEM_REDO_TBL(l_index).user_customizable,
3217               p_sortby_view_attribute_name => G_ITEM_REDO_TBL(l_index).sortby_view_attribute_name,
3218 	      p_admin_customizable => G_ITEM_REDO_TBL(l_index).admin_customizable,
3219 	      p_invoke_function_name => G_ITEM_REDO_TBL(l_index).invoke_function_name,
3220 	      p_expansion => G_ITEM_REDO_TBL(l_index).expansion,
3221 	      p_als_max_length => G_ITEM_REDO_TBL(l_index).als_max_length,
3222               p_initial_sort_sequence => G_ITEM_REDO_TBL(l_index).initial_sort_sequence,
3223 	      p_customization_application_id => G_ITEM_REDO_TBL(l_index).customization_application_id,
3224 	      p_customization_code => G_ITEM_REDO_TBL(l_index).customization_code,
3225               p_attribute_category => G_ITEM_REDO_TBL(l_index).attribute_category,
3226 			  p_attribute1 => G_ITEM_REDO_TBL(l_index).attribute1,
3227 			  p_attribute2 => G_ITEM_REDO_TBL(l_index).attribute2,
3228 			  p_attribute3 => G_ITEM_REDO_TBL(l_index).attribute3,
3229 			  p_attribute4 => G_ITEM_REDO_TBL(l_index).attribute4,
3230 			  p_attribute5 => G_ITEM_REDO_TBL(l_index).attribute5,
3231 			  p_attribute6 => G_ITEM_REDO_TBL(l_index).attribute6,
3232 			  p_attribute7 => G_ITEM_REDO_TBL(l_index).attribute7,
3233 			  p_attribute8 => G_ITEM_REDO_TBL(l_index).attribute8,
3234 			  p_attribute9 => G_ITEM_REDO_TBL(l_index).attribute9,
3235 			  p_attribute10 => G_ITEM_REDO_TBL(l_index).attribute10,
3236 			  p_attribute11 => G_ITEM_REDO_TBL(l_index).attribute11,
3237 			  p_attribute12 => G_ITEM_REDO_TBL(l_index).attribute12,
3238 			  p_attribute13 => G_ITEM_REDO_TBL(l_index).attribute13,
3239 			  p_attribute14 => G_ITEM_REDO_TBL(l_index).attribute14,
3240 			  p_attribute15 => G_ITEM_REDO_TBL(l_index).attribute15,
3241               p_attribute_label_long => G_ITEM_REDO_TBL(l_index).attribute_label_long,
3242               p_attribute_label_short =>G_ITEM_REDO_TBL(l_index).attribute_label_short,
3243 			  p_description => G_ITEM_REDO_TBL(l_index).description,
3244 	p_created_by => G_ITEM_REDO_TBL(l_index).created_by,
3245 	p_creation_date => G_ITEM_REDO_TBL(l_index).creation_date,
3246 	p_last_updated_by => G_ITEM_REDO_TBL(l_index).last_updated_by,
3247 	p_last_update_date => G_ITEM_REDO_TBL(l_index).last_update_date,
3248 	p_last_update_login => G_ITEM_REDO_TBL(l_index).last_update_login,
3249               p_loader_timestamp => p_loader_timestamp,
3250   		      p_pass => p_pass,
3251               p_copy_redo_flag => l_copy_redo_flag
3252             );
3253 		  elsif ( AK_UPLOAD_GRP.G_NO_CUSTOM_UPDATE ) then
3254 			select ari.last_updated_by, arit.last_updated_by,
3255 			       ari.last_update_date, arit.last_update_date
3256 			into l_user_id1, l_user_id2, l_update1, l_update2
3257 			from ak_region_items ari, ak_region_items_tl arit
3258 			where ari.region_code = G_ITEM_REDO_TBL(l_index).region_code
3259 			and ari.region_application_id = G_ITEM_REDO_TBL(l_index).region_application_id
3260 			and ari.attribute_code = G_ITEM_REDO_TBL(l_index).attribute_code
3261 			and ari.attribute_application_id = G_ITEM_REDO_TBL(l_index).attribute_application_id
3262 			and ari.region_code = arit.region_code
3263 			and ari.region_application_id = arit.region_application_id
3264 			and ari.attribute_code = arit.attribute_code
3265 			and ari.attribute_application_id = arit.attribute_application_id
3266 			and arit.language = userenv('LANG');
3267 			/*if (( l_user_id1 = 1 or l_user_id1 = 2) and
3268 				( l_user_id2 = 1 or l_user_id2 = 2 )) then*/
3269                 if (AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
3270                       p_loader_timestamp => p_loader_timestamp,
3271                       p_created_by => G_ITEM_REDO_TBL(l_index).created_by,
3272                       p_creation_date => G_ITEM_REDO_TBL(l_index).creation_date,
3273                       p_last_updated_by => G_ITEM_REDO_TBL(l_index).last_updated_by,
3274                       p_db_last_updated_by => l_user_id1,
3275                       p_last_update_date => G_ITEM_REDO_TBL(l_index).last_update_date,
3276                       p_db_last_update_date => l_update1,
3277                       p_last_update_login => G_ITEM_REDO_TBL(l_index).last_update_login,
3278                       p_create_or_update => 'UPDATE') and
3279 
3280                    AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
3281                       p_loader_timestamp => p_loader_timestamp,
3282                       p_created_by => G_ITEM_REDO_TBL(l_index).created_by,
3283                       p_creation_date => G_ITEM_REDO_TBL(l_index).creation_date,
3284                       p_last_updated_by => G_ITEM_REDO_TBL(l_index).last_updated_by,
3285                       p_db_last_updated_by => l_user_id2,
3286                       p_last_update_date => G_ITEM_REDO_TBL(l_index).last_update_date,
3287                       p_db_last_update_date => l_update2,
3288                       p_last_update_login => G_ITEM_REDO_TBL(l_index).last_update_login,
3289                       p_create_or_update => 'UPDATE')) then
3290 
3291 	            AK_REGION_PVT.UPDATE_ITEM (
3292 	              p_validation_level => p_validation_level,
3293 	              p_api_version_number => 1.0,
3294 	              p_msg_count => l_msg_count,
3295 	              p_msg_data => l_msg_data,
3296 	              p_return_status => l_return_status,
3297 	              p_region_application_id =>G_ITEM_REDO_TBL(l_index).region_application_id,
3298 	              p_region_code => G_ITEM_REDO_TBL(l_index).region_code,
3299 	              p_attribute_application_id =>
3300 	                               G_ITEM_REDO_TBL(l_index).attribute_application_id,
3301 	              p_attribute_code => G_ITEM_REDO_TBL(l_index).attribute_code,
3302 	              p_display_sequence => G_ITEM_REDO_TBL(l_index).display_sequence,
3303 	              p_node_display_flag => G_ITEM_REDO_TBL(l_index).node_display_flag,
3304 	              p_node_query_flag => G_ITEM_REDO_TBL(l_index).node_query_flag,
3305 	              p_attribute_label_length =>
3306 	                               G_ITEM_REDO_TBL(l_index).attribute_label_length,
3307 	              p_display_value_length =>
3308 	                               G_ITEM_REDO_TBL(l_index).display_value_length,
3309 	              p_bold => G_ITEM_REDO_TBL(l_index).bold,
3310 	              p_italic => G_ITEM_REDO_TBL(l_index).italic,
3311 	              p_vertical_alignment => G_ITEM_REDO_TBL(l_index).vertical_alignment,
3312 	              p_horizontal_alignment => G_ITEM_REDO_TBL(l_index).horizontal_alignment,
3313 	              p_item_style => G_ITEM_REDO_TBL(l_index).item_style,
3314 	              p_object_attribute_flag =>G_ITEM_REDO_TBL(l_index).object_attribute_flag,
3315 	              p_icx_custom_call => G_ITEM_REDO_TBL(l_index).icx_custom_call,
3316 	              p_update_flag => G_ITEM_REDO_TBL(l_index).update_flag,
3317 	              p_required_flag => G_ITEM_REDO_TBL(l_index).required_flag,
3318 	              p_security_code => G_ITEM_REDO_TBL(l_index).security_code,
3319 	              p_default_value_varchar2 =>
3320 	                 G_ITEM_REDO_TBL(l_index).default_value_varchar2,
3321 	              p_default_value_number =>
3322 	                 G_ITEM_REDO_TBL(l_index).default_value_number,
3323 	              p_default_value_date =>
3324 	                 G_ITEM_REDO_TBL(l_index).default_value_date,
3325 	              p_lov_region_application_id =>
3326 	                 G_ITEM_REDO_TBL(l_index).lov_region_application_id,
3327 	              p_lov_region_code => G_ITEM_REDO_TBL(l_index).lov_region_code,
3328 	              p_lov_foreign_key_name => G_ITEM_REDO_TBL(l_index).lov_foreign_key_name,
3329 	              p_lov_attribute_application_id =>
3330 	                 G_ITEM_REDO_TBL(l_index).lov_attribute_application_id,
3331 	              p_lov_attribute_code => G_ITEM_REDO_TBL(l_index).lov_attribute_code,
3332 	              p_lov_default_flag => G_ITEM_REDO_TBL(l_index).lov_default_flag,
3333 	              p_region_defaulting_api_pkg =>
3334 	                 G_ITEM_REDO_TBL(l_index).region_defaulting_api_pkg,
3335 	              p_region_defaulting_api_proc =>
3336 	                 G_ITEM_REDO_TBL(l_index).region_defaulting_api_proc,
3337 	              p_region_validation_api_pkg =>
3338 	                 G_ITEM_REDO_TBL(l_index).region_validation_api_pkg,
3339 	              p_region_validation_api_proc =>
3340 	                 G_ITEM_REDO_TBL(l_index).region_validation_api_proc,
3341 	              p_order_sequence => G_ITEM_REDO_TBL(l_index).order_sequence,
3342 	              p_order_direction => G_ITEM_REDO_TBL(l_index).order_direction,
3343 				  p_display_height => G_ITEM_REDO_TBL(l_index).display_height,
3344 				  p_submit => G_ITEM_REDO_TBL(l_index).submit,
3345 				  p_encrypt => G_ITEM_REDO_TBL(l_index).encrypt,
3346 				  p_css_class_name => G_ITEM_REDO_TBL(l_index).css_class_name,
3347 				  p_view_usage_name => G_ITEM_REDO_TBL(l_index).view_usage_name,
3348 				  p_view_attribute_name => G_ITEM_REDO_TBL(l_index).view_attribute_name,
3349 				  p_nested_region_appl_id => G_ITEM_REDO_TBL(l_index).nested_region_application_id,
3350 				  p_nested_region_code => G_ITEM_REDO_TBL(l_index).nested_region_code,
3351 				  p_url => G_ITEM_REDO_TBL(l_index).url,
3352 				  p_poplist_viewobject => G_ITEM_REDO_TBL(l_index).poplist_viewobject,
3353 				  p_poplist_display_attr => G_ITEM_REDO_TBL(l_index).poplist_display_attr,
3354 				  p_poplist_value_attr => G_ITEM_REDO_TBL(l_index).poplist_value_attr,
3355 				  p_image_file_name => G_ITEM_REDO_TBL(l_index).image_file_name,
3356 				  p_item_name => G_ITEM_REDO_TBL(l_index).item_name,
3357 				  p_css_label_class_name => G_ITEM_REDO_TBL(l_index).css_label_class_name,
3358 				  p_menu_name => G_ITEM_REDO_TBL(l_index).menu_name,
3359 				  p_flexfield_name => G_ITEM_REDO_TBL(l_index).flexfield_name,
3360 				  p_flexfield_application_id => G_ITEM_REDO_TBL(l_index).flexfield_application_id,
3361                   p_tabular_function_code    => G_ITEM_REDO_TBL(l_index).tabular_function_code,
3362                   p_tip_type                 => G_ITEM_REDO_TBL(l_index).tip_type,
3363                   p_tip_message_name         => G_ITEM_REDO_TBL(l_index).tip_message_name,
3364                   p_tip_message_application_id  => G_ITEM_REDO_TBL(l_index).tip_message_application_id ,
3365                   p_flex_segment_list        => G_ITEM_REDO_TBL(l_index).flex_segment_list,
3366                   p_entity_id  => G_ITEM_REDO_TBL(l_index).entity_id ,
3367                   p_anchor => G_ITEM_REDO_TBL(l_index).anchor,
3368                   p_poplist_view_usage_name => G_ITEM_REDO_TBL(l_index).poplist_view_usage_name,
3369 		  p_user_customizable => G_ITEM_REDO_TBL(l_index).user_customizable,
3370                   p_sortby_view_attribute_name => G_ITEM_REDO_TBL(l_index).sortby_view_attribute_name,
3371 		  p_admin_customizable => G_ITEM_REDO_TBL(l_index).admin_customizable,
3372 		  p_invoke_function_name => G_ITEM_REDO_TBL(l_index).invoke_function_name,
3373 		  p_expansion => G_ITEM_REDO_TBL(l_index).expansion,
3374 		  p_als_max_length => G_ITEM_REDO_TBL(l_index).als_max_length,
3375                   p_initial_sort_sequence => G_ITEM_REDO_TBL(l_index).initial_sort_sequence,
3376 		  p_customization_application_id => G_ITEM_REDO_TBL(l_index).customization_application_id,
3377 		  p_customization_code => G_ITEM_REDO_TBL(l_index).customization_code,
3378 	              p_attribute_category => G_ITEM_REDO_TBL(l_index).attribute_category,
3379 				  p_attribute1 => G_ITEM_REDO_TBL(l_index).attribute1,
3380 				  p_attribute2 => G_ITEM_REDO_TBL(l_index).attribute2,
3381 				  p_attribute3 => G_ITEM_REDO_TBL(l_index).attribute3,
3382 				  p_attribute4 => G_ITEM_REDO_TBL(l_index).attribute4,
3383 				  p_attribute5 => G_ITEM_REDO_TBL(l_index).attribute5,
3384 				  p_attribute6 => G_ITEM_REDO_TBL(l_index).attribute6,
3385 				  p_attribute7 => G_ITEM_REDO_TBL(l_index).attribute7,
3386 				  p_attribute8 => G_ITEM_REDO_TBL(l_index).attribute8,
3387 				  p_attribute9 => G_ITEM_REDO_TBL(l_index).attribute9,
3388 				  p_attribute10 => G_ITEM_REDO_TBL(l_index).attribute10,
3389 				  p_attribute11 => G_ITEM_REDO_TBL(l_index).attribute11,
3390 				  p_attribute12 => G_ITEM_REDO_TBL(l_index).attribute12,
3391 				  p_attribute13 => G_ITEM_REDO_TBL(l_index).attribute13,
3392 				  p_attribute14 => G_ITEM_REDO_TBL(l_index).attribute14,
3393 				  p_attribute15 => G_ITEM_REDO_TBL(l_index).attribute15,
3394 	              p_attribute_label_long => G_ITEM_REDO_TBL(l_index).attribute_label_long,
3395 	              p_attribute_label_short =>G_ITEM_REDO_TBL(l_index).attribute_label_short,
3396 				  p_description => G_ITEM_REDO_TBL(l_index).description,
3397 		p_created_by => G_ITEM_REDO_TBL(l_index).created_by,
3398 		p_creation_date => G_ITEM_REDO_TBL(l_index).creation_date,
3399 		p_last_updated_by => G_ITEM_REDO_TBL(l_index).last_updated_by,
3400 		p_last_update_date => G_ITEM_REDO_TBL(l_index).last_update_date,
3401 		p_last_update_login => G_ITEM_REDO_TBL(l_index).last_update_login,
3402 	              p_loader_timestamp => p_loader_timestamp,
3403 	  		      p_pass => p_pass,
3404 	              p_copy_redo_flag => l_copy_redo_flag
3405 	            );
3406 			end if; -- /* if l_user_id1 = 1 and l_user_id2 = 1 */
3407           end if; -- /* if G_UPDATE_MODE G_NO_CUSTOM_UPDATE*/
3408         else
3409           AK_REGION_PVT.CREATE_ITEM (
3410             p_validation_level => p_validation_level,
3411             p_api_version_number => 1.0,
3412             p_msg_count => l_msg_count,
3413             p_msg_data => l_msg_data,
3414             p_return_status => l_return_status,
3415             p_region_application_id =>G_ITEM_REDO_TBL(l_index).region_application_id,
3416             p_region_code => G_ITEM_REDO_TBL(l_index).region_code,
3417             p_attribute_application_id =>
3418                              G_ITEM_REDO_TBL(l_index).attribute_application_id,
3419             p_attribute_code => G_ITEM_REDO_TBL(l_index).attribute_code,
3420             p_display_sequence => G_ITEM_REDO_TBL(l_index).display_sequence,
3421             p_node_display_flag => G_ITEM_REDO_TBL(l_index).node_display_flag,
3422             p_node_query_flag => G_ITEM_REDO_TBL(l_index).node_query_flag,
3423             p_attribute_label_length =>
3424                              G_ITEM_REDO_TBL(l_index).attribute_label_length,
3425             p_display_value_length =>
3426                              G_ITEM_REDO_TBL(l_index).display_value_length,
3427             p_bold => G_ITEM_REDO_TBL(l_index).bold,
3428             p_italic => G_ITEM_REDO_TBL(l_index).italic,
3429             p_vertical_alignment => G_ITEM_REDO_TBL(l_index).vertical_alignment,
3430             p_horizontal_alignment => G_ITEM_REDO_TBL(l_index).horizontal_alignment,
3431             p_item_style => G_ITEM_REDO_TBL(l_index).item_style,
3432             p_object_attribute_flag =>G_ITEM_REDO_TBL(l_index).object_attribute_flag,
3433             p_icx_custom_call => G_ITEM_REDO_TBL(l_index).icx_custom_call,
3434             p_update_flag => G_ITEM_REDO_TBL(l_index).update_flag,
3435             p_required_flag => G_ITEM_REDO_TBL(l_index).required_flag,
3436             p_security_code => G_ITEM_REDO_TBL(l_index).security_code,
3437             p_default_value_varchar2 =>
3438                G_ITEM_REDO_TBL(l_index).default_value_varchar2,
3439             p_default_value_number =>
3440                G_ITEM_REDO_TBL(l_index).default_value_number,
3441             p_default_value_date =>
3442                G_ITEM_REDO_TBL(l_index).default_value_date,
3443             p_lov_region_application_id =>
3444                G_ITEM_REDO_TBL(l_index).lov_region_application_id,
3445             p_lov_region_code => G_ITEM_REDO_TBL(l_index).lov_region_code,
3446             p_lov_foreign_key_name => G_ITEM_REDO_TBL(l_index).lov_foreign_key_name,
3447             p_lov_attribute_application_id =>
3448                G_ITEM_REDO_TBL(l_index).lov_attribute_application_id,
3449             p_lov_attribute_code => G_ITEM_REDO_TBL(l_index).lov_attribute_code,
3450             p_lov_default_flag => G_ITEM_REDO_TBL(l_index).lov_default_flag,
3451             p_region_defaulting_api_pkg =>
3452                G_ITEM_REDO_TBL(l_index).region_defaulting_api_pkg,
3453             p_region_defaulting_api_proc =>
3454                G_ITEM_REDO_TBL(l_index).region_defaulting_api_proc,
3455             p_region_validation_api_pkg =>
3456                G_ITEM_REDO_TBL(l_index).region_validation_api_pkg,
3457             p_region_validation_api_proc =>
3458                G_ITEM_REDO_TBL(l_index).region_validation_api_proc,
3459             p_order_sequence => G_ITEM_REDO_TBL(l_index).order_sequence,
3460             p_order_direction => G_ITEM_REDO_TBL(l_index).order_direction,
3461 			p_display_height => G_ITEM_REDO_TBL(l_index).display_height,
3462 			p_submit => G_ITEM_REDO_TBL(l_index).submit,
3463 			p_encrypt => G_ITEM_REDO_TBL(l_index).encrypt,
3464 			p_css_class_name => G_ITEM_REDO_TBL(l_index).css_class_name,
3465 			p_view_usage_name => G_ITEM_REDO_TBL(l_index).view_usage_name,
3466 			p_view_attribute_name => G_ITEM_REDO_TBL(l_index).view_attribute_name,
3467 			p_nested_region_appl_id => G_ITEM_REDO_TBL(l_index).nested_region_application_id,
3468 			p_nested_region_code => G_ITEM_REDO_TBL(l_index).nested_region_code,
3469 			p_url => G_ITEM_REDO_TBL(l_index).url,
3470 			p_poplist_viewobject => G_ITEM_REDO_TBL(l_index).poplist_viewobject,
3471 			p_poplist_display_attr => G_ITEM_REDO_TBL(l_index).poplist_display_attr,
3472 			p_poplist_value_attr => G_ITEM_REDO_TBL(l_index).poplist_value_attr,
3473 			p_image_file_name => G_ITEM_REDO_TBL(l_index).image_file_name,
3474 			p_css_label_class_name => G_ITEM_REDO_TBL(l_index).css_label_class_name,
3475 			p_menu_name => G_ITEM_REDO_TBL(l_index).menu_name,
3476 			p_flexfield_name => G_ITEM_REDO_TBL(l_index).flexfield_name,
3477 			p_flexfield_application_id => G_ITEM_REDO_TBL(l_index).flexfield_application_id,
3478             p_tabular_function_code    => G_ITEM_REDO_TBL(l_index).tabular_function_code,
3479             p_tip_type                 => G_ITEM_REDO_TBL(l_index).tip_type,
3480             p_tip_message_name         => G_ITEM_REDO_TBL(l_index).tip_message_name,
3481             p_tip_message_application_id  => G_ITEM_REDO_TBL(l_index).tip_message_application_id ,
3482             p_flex_segment_list        => G_ITEM_REDO_TBL(l_index).flex_segment_list,
3483             p_entity_id  => G_ITEM_REDO_TBL(l_index).entity_id ,
3484             p_anchor => G_ITEM_REDO_TBL(l_index).anchor,
3485             p_poplist_view_usage_name => G_ITEM_REDO_TBL(l_index).poplist_view_usage_name,
3486 	    p_user_customizable => G_ITEM_REDO_TBL(l_index).user_customizable,
3487             p_sortby_view_attribute_name => G_ITEM_REDO_TBL(l_index).sortby_view_attribute_name,
3488 	    p_admin_customizable => G_ITEM_REDO_TBL(l_index).admin_customizable,
3489 	    p_invoke_function_name => G_ITEM_REDO_TBL(l_index).invoke_function_name,
3490 	    p_expansion => G_ITEM_REDO_TBL(l_index).expansion,
3491 	    p_als_max_length => G_ITEM_REDO_TBL(l_index).als_max_length,
3492             p_initial_sort_sequence => G_ITEM_REDO_TBL(l_index).initial_sort_sequence,
3493 	    p_customization_application_id => G_ITEM_REDO_TBL(l_index).customization_application_id,
3494 	    p_customization_code => G_ITEM_REDO_TBL(l_index).customization_code,
3495             p_attribute_category => G_ITEM_REDO_TBL(l_index).attribute_category,
3496 			p_attribute1 => G_ITEM_REDO_TBL(l_index).attribute1,
3497 			p_attribute2 => G_ITEM_REDO_TBL(l_index).attribute2,
3498 			p_attribute3 => G_ITEM_REDO_TBL(l_index).attribute3,
3499 			p_attribute4 => G_ITEM_REDO_TBL(l_index).attribute4,
3500 			p_attribute5 => G_ITEM_REDO_TBL(l_index).attribute5,
3501 			p_attribute6 => G_ITEM_REDO_TBL(l_index).attribute6,
3502 			p_attribute7 => G_ITEM_REDO_TBL(l_index).attribute7,
3503 			p_attribute8 => G_ITEM_REDO_TBL(l_index).attribute8,
3504 			p_attribute9 => G_ITEM_REDO_TBL(l_index).attribute9,
3505 			p_attribute10 => G_ITEM_REDO_TBL(l_index).attribute10,
3506 			p_attribute11 => G_ITEM_REDO_TBL(l_index).attribute11,
3507 			p_attribute12 => G_ITEM_REDO_TBL(l_index).attribute12,
3508 			p_attribute13 => G_ITEM_REDO_TBL(l_index).attribute13,
3509 			p_attribute14 => G_ITEM_REDO_TBL(l_index).attribute14,
3510 			p_attribute15 => G_ITEM_REDO_TBL(l_index).attribute15,
3511             p_attribute_label_long => G_ITEM_REDO_TBL(l_index).attribute_label_long,
3512             p_attribute_label_short =>G_ITEM_REDO_TBL(l_index).attribute_label_short,
3513 			p_description => G_ITEM_REDO_TBL(l_index).description,
3514 		p_created_by => G_ITEM_REDO_TBL(l_index).created_by,
3515 		p_creation_date => G_ITEM_REDO_TBL(l_index).creation_date,
3516 		p_last_updated_by => G_ITEM_REDO_TBL(l_index).last_updated_by,
3517 		p_last_update_date => G_ITEM_REDO_TBL(l_index).lasT_update_date,
3518 		p_last_update_login => G_ITEM_REDO_TBL(l_index).last_update_login,
3519             p_loader_timestamp => p_loader_timestamp,
3520 		    p_pass => p_pass,
3521             p_copy_redo_flag => l_copy_redo_flag
3522           );
3523         end if; -- /* if ITEM_EXISTS */
3524         --
3525         -- If API call returns with an error status, upload aborts
3526         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
3527         (l_return_status = FND_API.G_RET_STS_ERROR) then
3528           RAISE FND_API.G_EXC_ERROR;
3529         end if; -- /* if l_return_status */
3530       end if; -- /* if G_ITEM_REDO_TBL.exists */
3531     end loop;
3532   end if;
3533 
3534   --
3535   -- create or update all region lov relations to the database
3536   --
3537   if (G_LOV_RELATION_REDO_INDEX > 0) then
3538     for l_index in G_LOV_RELATION_REDO_TBL.FIRST .. G_LOV_RELATION_REDO_TBL.LAST loop
3539       if (G_LOV_RELATION_REDO_TBL.exists(l_index)) then
3540 	    if ( G_LOV_RELATION_REDO_TBL(l_index).base_region_appl_id is null ) then
3541 		  G_LOV_RELATION_REDO_TBL(l_index).base_region_appl_id := G_LOV_RELATION_REDO_TBL(l_index).region_application_id;
3542 		end if;
3543 		if ( G_LOV_RELATION_REDO_TBL(l_index).base_region_code is null ) then
3544   		  G_LOV_RELATION_REDO_TBL(l_index).base_region_code := G_LOV_RELATION_REDO_TBL(l_index).region_code;
3545 		end if;
3546 
3547         if AK_REGION2_PVT.LOV_RELATION_EXISTS (
3548             p_api_version_number => 1.0,
3549             p_return_status => l_return_status,
3550             p_region_application_id =>
3551                                G_LOV_RELATION_REDO_TBL(l_index).region_application_id,
3552             p_region_code => G_LOV_RELATION_REDO_TBL(l_index).region_code,
3553             p_attribute_application_id =>
3554             					G_LOV_RELATION_REDO_TBL(l_index).attribute_application_id,
3555             p_attribute_code => G_LOV_RELATION_REDO_TBL(l_index).attribute_code,
3556             p_lov_region_appl_id => G_LOV_RELATION_REDO_TBL(l_index).lov_region_appl_id,
3557             p_lov_region_code => G_LOV_RELATION_REDO_TBL(l_index).lov_region_code,
3558             p_lov_attribute_appl_id =>
3559             					G_LOV_RELATION_REDO_TBL(l_index).lov_attribute_appl_id,
3560             p_lov_attribute_code => G_LOV_RELATION_REDO_TBL(l_index).lov_attribute_code,
3561 			p_base_attribute_appl_id => G_LOV_RELATION_REDO_TBL(l_index).base_attribute_appl_id,
3562 			p_base_attribute_code => G_LOV_RELATION_REDO_TBL(l_index).base_attribute_code,
3563             p_direction_flag => G_LOV_RELATION_REDO_TBL(l_index).direction_flag,
3564 	    p_base_region_appl_id => G_LOV_RELATION_REDO_TBL(l_index).base_region_appl_id,
3565 	    p_base_region_code => G_LOV_RELATION_REDO_TBL(l_index).base_region_code) then
3566           AK_REGION2_PVT.UPDATE_LOV_RELATION (
3567             p_validation_level => p_validation_level,
3568             p_api_version_number => 1.0,
3569             p_msg_count => l_msg_count,
3570             p_msg_data => l_msg_data,
3571             p_return_status => l_return_status,
3572             p_region_application_id =>
3573                                 G_LOV_RELATION_REDO_TBL(l_index).region_application_id,
3574             p_region_code => G_LOV_RELATION_REDO_TBL(l_index).region_code,
3575             p_attribute_application_id =>
3576                                 G_LOV_RELATION_REDO_TBL(l_index).attribute_application_id,
3577             p_attribute_code => G_LOV_RELATION_REDO_TBL(l_index).attribute_code,
3578 			p_lov_region_appl_id => G_LOV_RELATION_REDO_TBL(l_index).lov_region_appl_id,
3579 			p_lov_region_code => G_LOV_RELATION_REDO_TBL(l_index).lov_region_code,
3580 			p_lov_attribute_appl_id => G_LOV_RELATION_REDO_TBL(l_index).lov_attribute_appl_id,
3581 			p_lov_attribute_code => G_LOV_RELATION_REDO_TBL(l_index).lov_attribute_code,
3582 			p_base_attribute_appl_id => G_LOV_RELATION_REDO_TBL(l_index).base_attribute_appl_id,
3583 			p_base_attribute_code => G_LOV_RELATION_REDO_TBL(l_index).base_attribute_code,
3584             p_direction_flag => G_LOV_RELATION_REDO_TBL(l_index).direction_flag,
3585 	    p_base_region_appl_id => G_LOV_RELATION_REDO_TBL(l_index).base_region_appl_id,
3586 	    p_base_region_code => G_LOV_RELATION_REDO_TBL(l_index).base_region_code,
3587 			p_required_flag => G_LOV_RELATION_REDO_TBL(l_index).required_flag,
3588             p_loader_timestamp => p_loader_timestamp,
3589 		    p_pass => p_pass,
3590             p_copy_redo_flag => l_copy_redo_flag
3591           );
3592         else
3593           AK_REGION2_PVT.CREATE_LOV_RELATION (
3594             p_validation_level => p_validation_level,
3595             p_api_version_number => 1.0,
3596             p_msg_count => l_msg_count,
3597             p_msg_data => l_msg_data,
3598             p_return_status => l_return_status,
3599             p_region_application_id =>
3600                                 G_LOV_RELATION_REDO_TBL(l_index).region_application_id,
3601             p_region_code => G_LOV_RELATION_REDO_TBL(l_index).region_code,
3602             p_attribute_application_id =>
3603                                 G_LOV_RELATION_REDO_TBL(l_index).attribute_application_id,
3604             p_attribute_code => G_LOV_RELATION_REDO_TBL(l_index).attribute_code,
3605 			p_lov_region_appl_id => G_LOV_RELATION_REDO_TBL(l_index).lov_region_appl_id,
3606 			p_lov_region_code => G_LOV_RELATION_REDO_TBL(l_index).lov_region_code,
3607 			p_lov_attribute_appl_id => G_LOV_RELATION_REDO_TBL(l_index).lov_attribute_appl_id,
3608 			p_lov_attribute_code => G_LOV_RELATION_REDO_TBL(l_index).lov_attribute_code,
3609 			p_base_attribute_appl_id => G_LOV_RELATION_REDO_TBL(l_index).base_attribute_appl_id,
3610 			p_base_attribute_code => G_LOV_RELATION_REDO_TBL(l_index).base_attribute_code,
3611             p_direction_flag => G_LOV_RELATION_REDO_TBL(l_index).direction_flag,
3612 	    p_base_region_appl_id => G_LOV_RELATION_REDO_TBL(l_index).base_region_appl_id,
3613 	    p_base_region_code => G_LOV_RELATION_REDO_TBL(l_index).base_region_code,
3614 			p_required_flag => G_LOV_RELATION_REDO_TBL(l_index).required_flag,
3615 	p_created_by => G_LOV_RELATION_REDO_TBL(l_index).created_by,
3616 	p_creation_date => G_LOV_RELATION_REDO_TBL(l_index).creation_date,
3617 	p_last_updated_by => G_LOV_RELATION_REDO_TBL(l_index).last_updated_by,
3618 	p_last_update_date => G_LOV_RELATION_REDO_TBL(l_index).last_update_date,
3619 	p_last_update_login => G_LOV_RELATION_REDO_TBL(l_index).last_update_login,
3620             p_loader_timestamp => p_loader_timestamp,
3621 		    p_pass => p_pass,
3622             p_copy_redo_flag => l_copy_redo_flag
3623           );
3624         end if; -- /* if LOV_RELATION_EXISTS */
3625         --
3626         -- If API call returns with an error status, upload aborts
3627         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
3628         (l_return_status = FND_API.G_RET_STS_ERROR) then
3629           RAISE FND_API.G_EXC_ERROR;
3630         end if; -- /* if l_return_status */
3631       end if; -- /* if G_LOV_RELATION_REDO_TBL.exists(l_index) */
3632     end loop;
3633   end if; -- /* if G_LOV_RELATION_REDO_INDEX > 0 */
3634 
3635   p_return_status := FND_API.G_RET_STS_SUCCESS;
3636 
3637 EXCEPTION
3638 WHEN FND_API.G_EXC_ERROR THEN
3639   p_return_status := FND_API.G_RET_STS_ERROR;
3640   FND_MSG_PUB.Count_And_Get (
3641    p_count => l_msg_count,
3642    p_data => l_msg_data);
3643 WHEN OTHERS THEN
3644   p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3645   FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
3646                          SUBSTR (SQLERRM, 1, 240) );
3647   FND_MSG_PUB.Count_And_Get (
3648     p_count => l_msg_count,
3649     p_data => l_msg_data);
3650 
3651 end UPLOAD_REGION_SECOND;
3652 
3653 --=======================================================
3654 --  Procedure   CHECK_DISPLAY_SEQUENCE
3655 --
3656 --  Usage       Private API for making sure that the
3657 --              display sequence is unique for a given region
3658 --              code.
3659 --
3660 --  Desc        This API updates a region item, if necessary
3661 --
3662 --  Results     The API returns the standard p_return_status parameter
3663 --              indicating one of the standard return statuses :
3664 --                  * Unexpected error
3665 --                  * Error
3666 --                  * Success
3667 --  Parameters  Region Item columns
3668 --
3669 --  Version     Initial version number  =   1.0
3670 --  History     Current version number  =   1.0
3671 --=======================================================
3672 procedure CHECK_DISPLAY_SEQUENCE (
3673   p_validation_level        IN      NUMBER,
3674   p_region_code             IN      VARCHAR2,
3675   p_region_application_id   IN      NUMBER,
3676   p_attribute_code          IN      VARCHAR2,
3677   p_attribute_application_id IN     NUMBER,
3678   p_display_sequence        IN      NUMBER,
3679   p_return_status           OUT NOCOPY     VARCHAR2,
3680   p_msg_count               OUT NOCOPY     NUMBER,
3681   p_msg_data                OUT NOCOPY     VARCHAR2,
3682   p_pass                    IN      NUMBER,
3683   p_copy_redo_flag          IN OUT NOCOPY  BOOLEAN
3684 ) is
3685   cursor l_ri_csr ( region_code_param IN VARCHAR2,
3686                     region_application_id_param IN NUMBER,
3687                     display_sequence_param IN NUMBER) is
3688     select *
3689     from   ak_region_items
3690     where  region_code = region_code_param
3691     and    region_application_id = region_application_id_param
3692     and    display_sequence = display_sequence_param;
3693 
3694   cursor l_ri_tl_csr (  region_code_param IN VARCHAR2,
3695                         region_application_id_param IN NUMBER,
3696                         attribute_code_param IN VARCHAR2,
3697                         attribute_application_id_param IN NUMBER,
3698                         lang_param IN VARCHAR2) is
3699     select *
3700     from   ak_region_items_tl
3701     where  region_code = region_code_param
3702     and    region_application_id = region_application_id_param
3703     and    attribute_code = attribute_code_param
3704     and    attribute_application_id = attribute_application_id_param
3705     and    language = lang_param;
3706 
3707   l_lang                    varchar2(30);
3708   l_api_name                CONSTANT varchar2(30) := 'Check_Display_Sequence';
3709   l_new_display_sequence    NUMBER;
3710   l_return_status           VARCHAR2(1);
3711   l_ri_rec                  ak_region_items%ROWTYPE;
3712   l_orig_ri_rec             ak_region_items%ROWTYPE;
3713   l_ri_tl_rec               ak_region_items_tl%ROWTYPE;
3714 
3715 begin
3716   l_return_status := FND_API.G_RET_STS_SUCCESS;
3717   open l_ri_csr(    p_region_code,
3718                     p_region_application_id,
3719                     p_display_sequence);
3720   fetch l_ri_csr into l_ri_rec;
3721 
3722   --** Does it exists?
3723   if (l_ri_csr%found) then
3724     if ((l_ri_rec.attribute_code <> p_attribute_code) or
3725         (l_ri_rec.attribute_application_id <> p_attribute_application_id)) then
3726         --** Save it.
3727         l_orig_ri_rec := l_ri_rec;
3728 
3729         --** Get the TL entry
3730         select userenv('LANG') into l_lang from dual;
3731         open l_ri_tl_csr(   p_region_code,
3732                             p_region_application_id,
3733                             l_ri_rec.attribute_code,
3734                             l_ri_rec.attribute_application_id,
3735                             l_lang);
3736         fetch l_ri_tl_csr into l_ri_tl_rec;
3737 
3738         --** Bump up the display sequence value of the region item record
3739         l_new_display_sequence := p_display_sequence + 1000000;
3740         close l_ri_csr;
3741         open l_ri_csr(  p_region_code,
3742                         p_region_application_id,
3743                         l_new_display_sequence);
3744         fetch l_ri_csr into l_ri_rec;
3745 
3746         --** Keep looping until you can't find a record.
3747         while (l_ri_csr%found) loop
3748           close l_ri_csr;
3749           l_new_display_sequence := l_new_display_sequence + 1;
3750           open l_ri_csr(  p_region_code,
3751                           p_region_application_id,
3752                           l_new_display_sequence);
3753           fetch l_ri_csr into l_ri_rec;
3754         end loop;
3755 
3756         --** ASSUMPTION: You have found a unique sequence number for this region.
3757         AK_REGION_PVT.UPDATE_ITEM (
3758             p_validation_level => p_validation_level,
3759             p_api_version_number => 1.0,
3760             p_msg_count => p_msg_count,
3761             p_msg_data => p_msg_data,
3762             p_return_status => l_return_status,
3763             p_region_application_id =>l_orig_ri_rec.region_application_id,
3764             p_region_code => l_orig_ri_rec.region_code,
3765             p_attribute_application_id => l_orig_ri_rec.attribute_application_id,
3766             p_attribute_code => l_orig_ri_rec.attribute_code,
3767             p_display_sequence => l_new_display_sequence,
3768             p_node_display_flag => l_orig_ri_rec.node_display_flag,
3769             p_node_query_flag => l_orig_ri_rec.node_query_flag,
3770             p_attribute_label_length => l_orig_ri_rec.attribute_label_length,
3771             p_display_value_length => l_orig_ri_rec.display_value_length,
3772             p_bold => l_orig_ri_rec.bold,
3773             p_italic => l_orig_ri_rec.italic,
3774             p_vertical_alignment => l_orig_ri_rec.vertical_alignment,
3775             p_horizontal_alignment => l_orig_ri_rec.horizontal_alignment,
3776             p_item_style => l_orig_ri_rec.item_style,
3777             p_object_attribute_flag =>l_orig_ri_rec.object_attribute_flag,
3778             p_icx_custom_call => l_orig_ri_rec.icx_custom_call,
3779             p_update_flag => l_orig_ri_rec.update_flag,
3780             p_required_flag => l_orig_ri_rec.required_flag,
3781             p_security_code => l_orig_ri_rec.security_code,
3782             p_default_value_varchar2 => l_orig_ri_rec.default_value_varchar2,
3783             p_default_value_number => l_orig_ri_rec.default_value_number,
3784             p_default_value_date => l_orig_ri_rec.default_value_date,
3785             p_lov_region_application_id => l_orig_ri_rec.lov_region_application_id,
3786             p_lov_region_code => l_orig_ri_rec.lov_region_code,
3787             p_lov_foreign_key_name => l_orig_ri_rec.lov_foreign_key_name,
3788             p_lov_attribute_application_id => l_orig_ri_rec.lov_attribute_application_id,
3789             p_lov_attribute_code => l_orig_ri_rec.lov_attribute_code,
3790             p_lov_default_flag => l_orig_ri_rec.lov_default_flag,
3791             p_region_defaulting_api_pkg => l_orig_ri_rec.region_defaulting_api_pkg,
3792             p_region_defaulting_api_proc => l_orig_ri_rec.region_defaulting_api_proc,
3793             p_region_validation_api_pkg => l_orig_ri_rec.region_validation_api_pkg,
3794             p_region_validation_api_proc => l_orig_ri_rec.region_validation_api_proc,
3795             p_order_sequence => l_orig_ri_rec.order_sequence,
3796             p_order_direction => l_orig_ri_rec.order_direction,
3797 			p_display_height => l_orig_ri_rec.display_height,
3798 			p_submit => l_orig_ri_rec.submit,
3799 			p_encrypt => l_orig_ri_rec.encrypt,
3800 			p_css_class_name => l_orig_ri_rec.css_class_name,
3801 			p_view_usage_name =>l_orig_ri_rec.view_usage_name,
3802 			p_view_attribute_name =>l_orig_ri_rec.view_attribute_name,
3803 			p_nested_region_appl_id =>l_orig_ri_rec.nested_region_application_id,
3804 			p_nested_region_code =>l_orig_ri_rec.nested_region_code,
3805 			p_url =>l_orig_ri_rec.url,
3806 			p_poplist_viewobject =>l_orig_ri_rec.poplist_viewobject,
3807 			p_poplist_display_attr =>l_orig_ri_rec.poplist_display_attribute,
3808 			p_poplist_value_attr =>l_orig_ri_rec.poplist_value_attribute,
3809 			p_image_file_name =>l_orig_ri_rec.image_file_name,
3810 			p_item_name => l_orig_ri_rec.item_name,
3811 			p_css_label_class_name => l_orig_ri_rec.css_label_class_name,
3812 			p_menu_name => l_orig_ri_rec.menu_name,
3813 			p_flexfield_name => l_orig_ri_rec.flexfield_name,
3814 			p_flexfield_application_id => l_orig_ri_rec.flexfield_application_id,
3815             p_tabular_function_code    => l_orig_ri_rec.tabular_function_code,
3816             p_tip_type                 => l_orig_ri_rec.tip_type,
3817             p_tip_message_name         => l_orig_ri_rec.tip_message_name,
3818             p_tip_message_application_id  => l_orig_ri_rec.tip_message_application_id ,
3819             p_flex_segment_list        => l_orig_ri_rec.flex_segment_list,
3820             p_entity_id  => l_orig_ri_rec.entity_id,
3821             p_anchor => l_orig_ri_rec.anchor,
3822             p_poplist_view_usage_name => l_orig_ri_rec.poplist_view_usage_name,
3823 	    p_user_customizable => l_orig_ri_rec.user_customizable,
3824             p_sortby_view_attribute_name => l_orig_ri_rec.sortby_view_attribute_name,
3825 	    p_admin_customizable => l_orig_ri_rec.admin_customizable,
3826 	    p_invoke_function_name => l_orig_ri_rec.invoke_function_name,
3827 	    p_expansion => l_orig_ri_rec.expansion,
3828 	    p_als_max_length => l_orig_ri_rec.als_max_length,
3829             p_initial_sort_sequence => l_orig_ri_rec.initial_sort_sequence,
3830 	    p_customization_application_id => l_orig_ri_rec.customization_application_id,
3831 	    p_customization_code => l_orig_ri_rec.customization_code,
3832             p_attribute_category => l_orig_ri_rec.attribute_category,
3833 			p_attribute1 => l_orig_ri_rec.attribute1,
3834 			p_attribute2 => l_orig_ri_rec.attribute2,
3835 			p_attribute3 => l_orig_ri_rec.attribute3,
3836 			p_attribute4 => l_orig_ri_rec.attribute4,
3837 			p_attribute5 => l_orig_ri_rec.attribute5,
3838 			p_attribute6 => l_orig_ri_rec.attribute6,
3839 			p_attribute7 => l_orig_ri_rec.attribute7,
3840 			p_attribute8 => l_orig_ri_rec.attribute8,
3841 			p_attribute9 => l_orig_ri_rec.attribute9,
3842 			p_attribute10 => l_orig_ri_rec.attribute10,
3843 			p_attribute11 => l_orig_ri_rec.attribute11,
3844 			p_attribute12 => l_orig_ri_rec.attribute12,
3845 			p_attribute13 => l_orig_ri_rec.attribute13,
3846 			p_attribute14 => l_orig_ri_rec.attribute14,
3847 			p_attribute15 => l_orig_ri_rec.attribute15,
3848             p_attribute_label_long => l_ri_tl_rec.attribute_label_long,
3849             p_attribute_label_short =>l_ri_tl_rec.attribute_label_short,
3850 			p_description => l_ri_tl_rec.description,
3851 		p_created_by => l_ri_tl_rec.created_by,
3852 		p_creation_date => l_ri_tl_rec.creation_date,
3853 		p_last_updated_by => l_ri_tl_rec.last_updated_by,
3854 		p_last_update_date => l_ri_tl_rec.last_update_date,
3855 		p_last_update_login => l_ri_tl_rec.last_update_login,
3856             p_pass => p_pass,
3857             p_copy_redo_flag => p_copy_redo_flag
3858           );
3859     end if;
3860   end if;
3861 
3862   p_return_status := l_return_status;
3863   close l_ri_csr;
3864 
3865 EXCEPTION
3866   WHEN FND_API.G_EXC_ERROR THEN
3867     p_return_status := FND_API.G_RET_STS_ERROR;
3868   WHEN OTHERS THEN
3869     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3870     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
3871                            SUBSTR (SQLERRM, 1, 240) );
3872     FND_MSG_PUB.Add;
3873 
3874 end CHECK_DISPLAY_SEQUENCE;
3875 
3876 /*
3877 --=======================================================
3878 --  Function    GRAPH_COLUMN_EXISTS
3879 --
3880 --  Usage       Private API for checking for the existence of
3881 --              a region graph column with the given key values. This
3882 --              API should only be called by other APIs that are
3883 --              owned by the Core Modules Team (AK).
3884 --
3885 --  Desc        This API check to see if a region graph column record
3886 --              exists with the given key values.
3887 --
3888 --  Results     The API returns the standard p_return_status parameter
3889 --              indicating one of the standard return statuses :
3890 --                  * Unexpected error
3891 --                  * Error
3892 --                  * Success
3893 --              This function will return TRUE if such an object
3894 --              attribute exists, or FALSE otherwise.
3895 --  Parameters  Region Graph Column key columns
3896 --
3897 --  Version     Initial version number  =   1.0
3898 --  History     Current version number  =   1.0
3899 --=======================================================
3900 FUNCTION GRAPH_COLUMN_EXISTS (
3901   p_api_version_number          IN      NUMBER,
3902   p_return_status                       OUT NOCOPY             VARCHAR2,
3903   p_region_application_id       IN              NUMBER,
3904   p_region_code                         IN              VARCHAR2,
3905   p_attribute_application_id IN         NUMBER,
3906   p_attribute_code                      IN              VARCHAR2,
3907   p_graph_number			IN		NUMBER
3908 ) return boolean is
3909   cursor l_check_graph_column_csr is
3910     select 1
3911     from  AK_REGION_GRAPH_COLUMNS
3912     where region_application_id = p_region_application_id
3913     and   region_code = p_region_code
3914     and   attribute_application_id = p_attribute_application_id
3915     and   attribute_code = p_attribute_code
3916     and   graph_number = p_graph_number;
3917 
3918   l_api_version_number CONSTANT number := 1.0;
3919   l_api_name           CONSTANT varchar2(30) := 'Graph_Column_Exists';
3920   l_dummy              number;
3921 begin
3922   IF NOT FND_API.Compatible_API_Call (
3923     l_api_version_number, p_api_version_number, l_api_name,
3924     G_PKG_NAME) then
3925       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3926       return FALSE;
3927   END IF;
3928 
3929   open l_check_graph_column_csr;
3930   fetch l_check_graph_column_csr into l_dummy;
3931   if (l_check_graph_column_csr%notfound) then
3932     close l_check_graph_column_csr;
3933     p_return_status := FND_API.G_RET_STS_SUCCESS;
3934      return FALSE;
3935   else
3936     close l_check_graph_column_csr;
3937     p_return_status := FND_API.G_RET_STS_SUCCESS;
3938     return TRUE;
3939   end if;
3940 
3941 EXCEPTION
3942   WHEN FND_API.G_EXC_ERROR THEN
3943     p_return_status := FND_API.G_RET_STS_ERROR;
3944     return FALSE;
3945   WHEN OTHERS THEN
3946     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3947     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
3948                            SUBSTR (SQLERRM, 1, 240) );
3949     FND_MSG_PUB.Add;
3950     return FALSE;
3951 end GRAPH_COLUMN_EXISTS;
3952 */
3953 
3954 --=======================================================
3955 --  Function    LOV_RELATION_EXISTS
3956 --
3957 --  Usage       Private API for checking for the existence of
3958 --              a region lov relation with the given key values. This
3959 --              API should only be called by other APIs that are
3960 --              owned by the Core Modules Team (AK).
3961 --
3962 --  Desc        This API check to see if a region lov relation record
3963 --              exists with the given key values.
3964 --
3965 --  Results     The API returns the standard p_return_status parameter
3966 --              indicating one of the standard return statuses :
3967 --                  * Unexpected error
3968 --                  * Error
3969 --                  * Success
3970 --              This function will return TRUE if such an object
3971 --              attribute exists, or FALSE otherwise.
3972 --  Parameters  Region Lov Relation key columns
3973 --
3974 --  Version     Initial version number  =   1.0
3975 --  History     Current version number  =   1.0
3976 --=======================================================
3977 FUNCTION LOV_RELATION_EXISTS (
3978   p_api_version_number		IN      NUMBER,
3979   p_return_status			OUT NOCOPY		VARCHAR2,
3980   p_region_application_id	IN		NUMBER,
3981   p_region_code				IN		VARCHAR2,
3982   p_attribute_application_id IN		NUMBER,
3983   p_attribute_code			IN		VARCHAR2,
3984   p_lov_region_appl_id		IN		NUMBER,
3985   p_lov_region_code			IN		VARCHAR2,
3986   p_lov_attribute_appl_id	IN		NUMBER,
3987   p_lov_attribute_code		IN		VARCHAR2,
3988   p_base_attribute_appl_id	IN		NUMBER,
3989   p_base_attribute_code		IN		VARCHAR2,
3990   p_direction_flag			IN		VARCHAR2,
3991   p_base_region_appl_id		IN		NUMBER,
3992   p_base_region_code		IN		VARCHAR2
3993 ) return boolean is
3994   cursor l_check_lov_relation_csr is
3995     select 1
3996     from  AK_REGION_LOV_RELATIONS
3997     where region_application_id = p_region_application_id
3998     and   region_code = p_region_code
3999     and   attribute_application_id = p_attribute_application_id
4000     and   attribute_code = p_attribute_code
4001     and   lov_region_appl_id = p_lov_region_appl_id
4002     and   lov_region_code = p_lov_region_code
4003     and   lov_attribute_appl_id = p_lov_attribute_appl_id
4004     and   lov_attribute_code = p_lov_attribute_code
4005 	and   base_attribute_appl_id = p_base_attribute_appl_id
4006 	and   base_attribute_code = p_base_attribute_code
4007     and   direction_flag = p_direction_flag
4008     and   base_region_appl_id = p_base_region_appl_id
4009     and   base_region_code = p_base_region_code;
4010 
4011   l_api_version_number CONSTANT number := 1.0;
4012   l_api_name           CONSTANT varchar2(30) := 'Lov_Relation_Exists';
4013   l_dummy              number;
4014 begin
4015   IF NOT FND_API.Compatible_API_Call (
4016     l_api_version_number, p_api_version_number, l_api_name,
4017     G_PKG_NAME) then
4018       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4019       return FALSE;
4020   END IF;
4021 
4022   open l_check_lov_relation_csr;
4023   fetch l_check_lov_relation_csr into l_dummy;
4024   if (l_check_lov_relation_csr%notfound) then
4025     close l_check_lov_relation_csr;
4026     p_return_status := FND_API.G_RET_STS_SUCCESS;
4027      return FALSE;
4028   else
4029     close l_check_lov_relation_csr;
4030     p_return_status := FND_API.G_RET_STS_SUCCESS;
4031     return TRUE;
4032   end if;
4033 
4034 EXCEPTION
4035   WHEN FND_API.G_EXC_ERROR THEN
4036     p_return_status := FND_API.G_RET_STS_ERROR;
4037     return FALSE;
4038   WHEN OTHERS THEN
4039     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4040     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
4041                            SUBSTR (SQLERRM, 1, 240) );
4042     FND_MSG_PUB.Add;
4043     return FALSE;
4044 end LOV_RELATION_EXISTS;
4045 
4046 /*
4047 --=======================================================
4048 --  Function    VALIDATE_GRAPH_COLUMN
4049 --
4050 --  Usage       Private API for validating a region graph column. This
4051 --              API should only be called by other APIs that are
4052 --              owned by the Core Modules Team (AK).
4053 --
4054 --  Desc        Perform validation on a region graph column record.
4055 --
4056 --  Results     The API returns the standard p_return_status parameter
4057 --              indicating one of the standard return statuses :
4058 --                  * Unexpected error
4059 --                  * Error
4060 --                  * Success
4061 --              In addition, this function returns TRUE if all
4062 --              validation tests are passed, or FALSE otherwise.
4063 --  Parameters  Region graph column columns
4064 --              p_caller : IN required
4065 --                  Must be one of the following values defined
4066 --                  in package AK_ON_OBJECTS_PVT:
4067 --                  - G_CREATE   (if calling from the Create API)
4068 --                  - G_DOWNLOAD (if calling from the Download API)
4069 --                  - G_UPDATE   (if calling from the Update API)
4070 --
4071 --  Note        This API is intended for performing record-level
4072 --              validation. It is not designed for item-level
4073 --              validation.
4074 --
4075 --  Version     Initial version number  =   1.1
4076 --=======================================================
4077 FUNCTION VALIDATE_GRAPH_COLUMN (
4078   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
4079   p_api_version_number       IN      NUMBER,
4080   p_return_status            OUT NOCOPY     VARCHAR2,
4081   p_region_application_id    IN      NUMBER := FND_API.G_MISS_NUM,
4082   p_region_code              IN      VARCHAR2 := FND_API.G_MISS_CHAR,
4083   p_attribute_application_id IN      NUMBER := FND_API.G_MISS_NUM,
4084   p_attribute_code           IN      VARCHAR2 := FND_API.G_MISS_CHAR,
4085   p_graph_number	     IN      NUMBER := FND_API.G_MISS_NUM,
4086   p_pass		     IN      NUMBER := 2,
4087   p_caller		     IN      VARCHAR2
4088 ) return boolean is
4089   cursor l_check_region_graph_csr (param_region_code in varchar2,
4090   param_region_appl_id in number, param_graph_number in number) is
4091     select  1
4092     from    AK_REGION_GRAPHS
4093     where   region_application_id = param_region_appl_id
4094     and     region_code = param_region_code
4095     and     graph_number = param_graph_number;
4096 
4097   cursor l_check_region_item_csr (param_region_code in varchar2,
4098   param_region_appl_id in number, param_attr_appl_id in number,
4099   param_attr_code in varchar2) is
4100     select 1
4101     from   AK_REGION_ITEMS
4102     where  region_application_id = param_region_appl_id
4103     and    region_code = param_region_code
4104     and    attribute_application_id = param_attr_appl_id
4105     and    attribute_code = param_attr_code;
4106 
4107   l_api_version_number      CONSTANT number := 1.0;
4108   l_api_name                CONSTANT varchar2(30) := 'validate_graph_column';
4109 
4110   l_dummy                   NUMBER;
4111   l_error                   BOOLEAN;
4112   l_return_status           VARCHAR2(1);
4113 begin
4114 
4115   IF NOT FND_API.Compatible_API_Call (
4116     l_api_version_number, p_api_version_number, l_api_name,
4117     G_PKG_NAME) then
4118       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4119       return FALSE;
4120   END IF;
4121 
4122   l_error := FALSE;
4123 
4124   --** if validation level is none, no validation is necessary
4125   if (p_validation_level = FND_API.G_VALID_LEVEL_NONE) then
4126     p_return_status := FND_API.G_RET_STS_SUCCESS;
4127     return TRUE;
4128   end if;
4129 
4130   --** check that key columns are not null and not missing **
4131   if ((p_region_application_id is null) or
4132       (p_region_application_id = FND_API.G_MISS_NUM)) then
4133     l_error := TRUE;
4134     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4135       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4136       FND_MESSAGE.SET_TOKEN('COLUMN', 'REGION_APPLICATION_ID');
4137       FND_MSG_PUB.Add;
4138     end if;
4139   end if;
4140 
4141   if ((p_region_code is null) or
4142       (p_region_code = FND_API.G_MISS_CHAR)) then
4143     l_error := TRUE;
4144     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4145       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4146       FND_MESSAGE.SET_TOKEN('COLUMN', 'REGION_CODE');
4147       FND_MSG_PUB.Add;
4148     end if;
4149   end if;
4150 
4151   if ((p_attribute_application_id is null) or
4152       (p_attribute_application_id = FND_API.G_MISS_NUM)) then
4153     l_error := TRUE;
4154     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4155       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4156       FND_MESSAGE.SET_TOKEN('COLUMN', 'ATTRIBUTE_APPLICATION_ID');
4157       FND_MSG_PUB.Add;
4158     end if;
4159   end if;
4160 
4161   if ((p_attribute_code is null) or
4162       (p_attribute_code = FND_API.G_MISS_CHAR)) then
4163     l_error := TRUE;
4164     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4165       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4166       FND_MESSAGE.SET_TOKEN('COLUMN', 'ATTRIBUTE_CODE');
4167       FND_MSG_PUB.Add;
4168     end if;
4169   end if;
4170 
4171   if ((p_graph_number is null) or
4172       (p_graph_number = FND_API.G_MISS_NUM)) then
4173     l_error := TRUE;
4174     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4175       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4176       FND_MESSAGE.SET_TOKEN('COLUMN', 'GRAPH_NUMBER');
4177       FND_MSG_PUB.Add;
4178     end if;
4179   end if;
4180 
4181   -- - Check that the parent region item exists
4182   open l_check_region_item_csr(p_region_code, p_region_application_id, p_attribute_application_id, p_attribute_code);
4183   fetch l_check_region_item_csr into l_dummy;
4184   if (l_check_region_item_csr%notfound) then
4185     l_error := TRUE;
4186     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4187       FND_MESSAGE.SET_NAME('AK','AK_INVALID_REG_ITEM_REFERENCE');
4188       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||
4189                            ' ' || p_region_code ||' '||
4190 			   to_char(p_attribute_application_id) || ' '||
4191 			   p_attribute_code);
4192       FND_MSG_PUB.Add;
4193     end if;
4194   end if;
4195   close l_check_region_item_csr;
4196 
4197   -- - Check that the parent region graph exists
4198   open l_check_region_graph_csr(p_region_code, p_region_application_id, p_graph_number);
4199   fetch l_check_Region_graph_csr into l_dummy;
4200   if (l_check_region_graph_csr%notfound) then
4201     l_error := TRUE;
4202     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4203       FND_MESSAGE.SET_NAME('AK','AK_INVALID_REG_GRAPH_REFERENCE');
4204       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||
4205                            ' ' || p_region_code ||' '||
4206                            p_graph_number);
4207       FND_MSG_PUB.Add;
4208     end if;
4209   end if;
4210   close l_check_region_graph_csr;
4211 
4212   -- return true if no error, false otherwise
4213   p_return_status := FND_API.G_RET_STS_SUCCESS;
4214   return (not l_error);
4215 
4216 EXCEPTION
4217   WHEN FND_API.G_EXC_ERROR THEN
4218     p_return_status := FND_API.G_RET_STS_ERROR;
4219     return FALSE;
4220   WHEN OTHERS THEN
4221     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4222     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
4223                            SUBSTR (SQLERRM, 1, 240) );
4224     FND_MSG_PUB.Add;
4225     return FALSE;
4226 
4227 end VALIDATE_GRAPH_COLUMN;
4228 */
4229 
4230 --=======================================================
4231 --  Function    VALIDATE_LOV_RELATION
4232 --
4233 --  Usage       Private API for validating a region lov relation. This
4234 --              API should only be called by other APIs that are
4235 --              owned by the Core Modules Team (AK).
4236 --
4237 --  Desc        Perform validation on a region lov relation record.
4238 --
4239 --  Results     The API returns the standard p_return_status parameter
4240 --              indicating one of the standard return statuses :
4241 --                  * Unexpected error
4242 --                  * Error
4243 --                  * Success
4244 --              In addition, this function returns TRUE if all
4245 --              validation tests are passed, or FALSE otherwise.
4246 --  Parameters  Region lov relation columns
4247 --              p_caller : IN required
4248 --                  Must be one of the following values defined
4249 --                  in package AK_ON_OBJECTS_PVT:
4250 --                  - G_CREATE   (if calling from the Create API)
4251 --                  - G_DOWNLOAD (if calling from the Download API)
4252 --                  - G_UPDATE   (if calling from the Update API)
4253 --
4254 --  Note        This API is intended for performing record-level
4255 --              validation. It is not designed for item-level
4256 --              validation.
4257 --
4258 --  Version     Initial version number  =   1.1
4259 --=======================================================
4260 FUNCTION VALIDATE_LOV_RELATION (
4261   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
4262   p_api_version_number       IN      NUMBER,
4263   p_return_status            OUT NOCOPY     VARCHAR2,
4264   p_region_application_id    IN      NUMBER := FND_API.G_MISS_NUM,
4265   p_region_code              IN      VARCHAR2 := FND_API.G_MISS_CHAR,
4266   p_attribute_application_id IN      NUMBER := FND_API.G_MISS_NUM,
4267   p_attribute_code           IN      VARCHAR2 := FND_API.G_MISS_CHAR,
4268   p_lov_region_appl_id    	 IN      NUMBER := FND_API.G_MISS_NUM,
4269   p_lov_region_code          IN      VARCHAR2 := FND_API.G_MISS_CHAR,
4270   p_lov_attribute_appl_id	 IN      NUMBER := FND_API.G_MISS_NUM,
4271   p_lov_attribute_code       IN      VARCHAR2 := FND_API.G_MISS_CHAR,
4272   p_base_attribute_appl_id	 IN      NUMBER := FND_API.G_MISS_NUM,
4273   p_base_attribute_code		 IN      VARCHAR2 := FND_API.G_MISS_CHAR,
4274   p_direction_flag			 IN		 VARCHAR2 := FND_API.G_MISS_CHAR,
4275   p_base_region_appl_id		IN	NUMBER := FND_API.G_MISS_NUM,
4276   p_base_region_code		IN	VARCHAR2 := FND_API.G_MISS_CHAR,
4277   p_caller                   IN      VARCHAR2,
4278   p_pass                     IN      NUMBER := 2
4279 ) return boolean is
4280   cursor l_check_region_csr (param_region_code in varchar2, param_region_appl_id in number) is
4281     select  1
4282     from    AK_REGIONS
4283     where   region_application_id = param_region_appl_id
4284     and     region_code = param_region_code;
4285 
4286   cursor l_check_region_item_csr (param_region_code in varchar2, param_region_appl_id in number,
4287   						param_attr_code in varchar2, param_attr_appl_id number) is
4288     select  1
4289     from    AK_REGION_ITEMS
4290     where   region_application_id = param_region_appl_id
4291     and     region_code = param_region_code
4292     and     attribute_application_id = param_attr_appl_id;
4293 
4294   l_api_version_number      CONSTANT number := 1.0;
4295   l_api_name                CONSTANT varchar2(30) := 'validate_lov_relation';
4296 
4297   l_dummy                   NUMBER;
4298   l_error                   BOOLEAN;
4299   l_return_status           VARCHAR2(1);
4300 begin
4301 
4302   IF NOT FND_API.Compatible_API_Call (
4303     l_api_version_number, p_api_version_number, l_api_name,
4304     G_PKG_NAME) then
4305       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4306       return FALSE;
4307   END IF;
4308 
4309   l_error := FALSE;
4310 
4311   --** if validation level is none, no validation is necessary
4312   if (p_validation_level = FND_API.G_VALID_LEVEL_NONE) then
4313     p_return_status := FND_API.G_RET_STS_SUCCESS;
4314     return TRUE;
4315   end if;
4316 
4317   --** check that key columns are not null and not missing **
4318   if ((p_region_application_id is null) or
4319       (p_region_application_id = FND_API.G_MISS_NUM)) then
4320     l_error := TRUE;
4321     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4322       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4323       FND_MESSAGE.SET_TOKEN('COLUMN', 'REGION_APPLICATION_ID');
4324       FND_MSG_PUB.Add;
4325     end if;
4326   end if;
4327 
4328   if ((p_region_code is null) or
4329       (p_region_code = FND_API.G_MISS_CHAR)) then
4330     l_error := TRUE;
4331     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4332       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4333       FND_MESSAGE.SET_TOKEN('COLUMN', 'REGION_CODE');
4334       FND_MSG_PUB.Add;
4335     end if;
4336   end if;
4337 
4338   if ((p_attribute_application_id is null) or
4339       (p_attribute_application_id = FND_API.G_MISS_NUM)) then
4340     l_error := TRUE;
4341     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4342       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4343       FND_MESSAGE.SET_TOKEN('COLUMN', 'ATTRIBUTE_APPLICATION_ID');
4344       FND_MSG_PUB.Add;
4345     end if;
4346   end if;
4347 
4348   if ((p_attribute_code is null) or
4349       (p_attribute_code = FND_API.G_MISS_CHAR)) then
4350     l_error := TRUE;
4351     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4352       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4353       FND_MESSAGE.SET_TOKEN('COLUMN', 'ATTRIBUTE_CODE');
4354       FND_MSG_PUB.Add;
4355     end if;
4356   end if;
4357 
4358   if ((p_lov_region_appl_id is null) or
4359       (p_lov_region_appl_id = FND_API.G_MISS_NUM)) then
4360     l_error := TRUE;
4361     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4362       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4363       FND_MESSAGE.SET_TOKEN('COLUMN', 'REGION_APPLICATION_ID');
4364       FND_MSG_PUB.Add;
4365     end if;
4366   end if;
4367 
4368   if ((p_lov_region_code is null) or
4369       (p_lov_region_code = FND_API.G_MISS_CHAR)) then
4370     l_error := TRUE;
4371     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4372       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4373       FND_MESSAGE.SET_TOKEN('COLUMN', 'REGION_CODE');
4374       FND_MSG_PUB.Add;
4375     end if;
4376   end if;
4377 
4378   if ((p_lov_attribute_appl_id is null) or
4379       (p_lov_attribute_appl_id = FND_API.G_MISS_NUM)) then
4380     l_error := TRUE;
4381     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4382       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4383       FND_MESSAGE.SET_TOKEN('COLUMN', 'ATTRIBUTE_APPLICATION_ID');
4384       FND_MSG_PUB.Add;
4385     end if;
4386   end if;
4387 
4388   if ((p_lov_attribute_code is null) or
4389       (p_lov_attribute_code = FND_API.G_MISS_CHAR)) then
4390     l_error := TRUE;
4391     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4392       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4393       FND_MESSAGE.SET_TOKEN('COLUMN', 'ATTRIBUTE_CODE');
4394       FND_MSG_PUB.Add;
4395     end if;
4396   end if;
4397 
4398 -- do not raise an error for now, there are ppl who has an old jlt file and upload
4399 --  it manually to a database which contains this patch
4400 /**
4401   if ((p_base_region_appl_id is null) or
4402       (p_base_region_appl_id = FND_API.G_MISS_NUM)) then
4403 
4404     l_error := TRUE;
4405     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4406       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4407       FND_MESSAGE.SET_TOKEN('COLUMN', 'BASE_REGION_APPL_ID');
4408       FND_MSG_PUB.Add;
4409     end if;
4410   end if;
4411 **/
4412 
4413 -- do not raise an error for now, there are ppl who has an old jlt file and upload
4414 --  it manually to a database which contains this patch
4415 /**
4416   if ((p_base_region_code is null) or
4417       (p_base_region_code = FND_API.G_MISS_CHAR)) then
4418     l_error := TRUE;
4419     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4420       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4421       FND_MESSAGE.SET_TOKEN('COLUMN', 'BASE_REGION_CODE');
4422       FND_MSG_PUB.Add;
4423     end if;
4424   end if;
4425 **/
4426 
4427   -- these two columns are not part of primary key but cannot be null
4428   --
4429   if ((p_base_attribute_appl_id is null) or
4430       (p_base_attribute_appl_id = FND_API.G_MISS_NUM)) then
4431     l_error := TRUE;
4432     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4433       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4434       FND_MESSAGE.SET_TOKEN('COLUMN', 'BASE_ATTRIBUTE_APPL_ID');
4435       FND_MSG_PUB.Add;
4436     end if;
4437   end if;
4438 
4439   if ((p_base_attribute_code is null) or
4440       (p_base_attribute_code = FND_API.G_MISS_CHAR)) then
4441     l_error := TRUE;
4442     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4443       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4444       FND_MESSAGE.SET_TOKEN('COLUMN', 'BASE_ATTRIBUTE_CODE');
4445       FND_MSG_PUB.Add;
4446     end if;
4447   end if;
4448 
4449   -- - Check that the parent region item exists
4450   open l_check_region_item_csr(p_region_code, p_region_application_id,
4451   						p_attribute_code, p_attribute_application_id);
4452   fetch l_check_region_item_csr into l_dummy;
4453   if (l_check_region_item_csr%notfound) then
4454     l_error := TRUE;
4455     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4456       FND_MESSAGE.SET_NAME('AK','AK_INVALID_REG_ITEM_REFERENCE');
4457       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||
4458                            ' ' || p_region_code ||' '||
4459                            to_char(p_attribute_application_id)||' '||p_attribute_code);
4460       FND_MSG_PUB.Add;
4461     end if;
4462   end if;
4463   close l_check_region_item_csr;
4464 
4465   -- - Check that the lov region exists
4466   open l_check_region_csr(p_lov_region_code, p_lov_region_appl_id);
4467   fetch l_check_region_csr into l_dummy;
4468   if (l_check_region_csr%notfound) then
4469     l_error := TRUE;
4470     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4471       FND_MESSAGE.SET_NAME('AK','AK_INVALID_LOV_REG_REFERENCE');
4472       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_lov_region_appl_id) ||
4473                            ' ' || p_lov_region_code );
4474       FND_MSG_PUB.Add;
4475     end if;
4476   end if;
4477   close l_check_region_csr;
4478 
4479   -- - Check that the lov region item exists
4480   open l_check_region_item_csr(p_lov_region_code, p_lov_region_appl_id,
4481   						p_lov_attribute_code, p_lov_attribute_appl_id);
4482   fetch l_check_region_item_csr into l_dummy;
4483   if (l_check_region_item_csr%notfound) then
4484     l_error := TRUE;
4485     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4486       FND_MESSAGE.SET_NAME('AK','AK_INVALID_LOV_ITEM_REFERENCE');
4487       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_lov_region_appl_id) ||
4488                            ' ' || p_lov_region_code ||' '||
4489                            to_char(p_lov_attribute_appl_id)||' '||p_lov_attribute_code);
4490       FND_MSG_PUB.Add;
4491     end if;
4492   end if;
4493   close l_check_region_item_csr;
4494 
4495   -- - Check that the base region item exists
4496   open l_check_region_item_csr(p_base_region_code, p_base_region_appl_id,
4497   						p_base_attribute_code, p_base_attribute_appl_id);
4498   fetch l_check_region_item_csr into l_dummy;
4499   if (l_check_region_item_csr%notfound) then
4500     l_error := TRUE;
4501     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4502       FND_MESSAGE.SET_NAME('AK','AK_INVALID_BASE_ITEM_REF');
4503       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_lov_region_appl_id) ||
4504                            ' ' || p_lov_region_code ||' '||
4505                            to_char(p_base_attribute_appl_id)||' '||p_base_attribute_code);
4506       FND_MSG_PUB.Add;
4507     end if;
4508   end if;
4509   close l_check_region_item_csr;
4510 
4511   -- direction_flag
4512   if ( (p_direction_flag <> FND_API.G_MISS_CHAR) and
4513   		(p_direction_flag is not null) )then
4514     if (NOT AK_ON_OBJECTS_PVT.VALID_LOOKUP_CODE (
4515             p_api_version_number => 1.0,
4516             p_return_status => l_return_status,
4517             p_lookup_type  => 'LOV_DIRECTION',
4518             p_lookup_code => p_direction_flag)) then
4519       l_error := TRUE;
4520       if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4521         FND_MESSAGE.SET_NAME('AK','AK_INVALID_COLUMN_VALUE');
4522         FND_MESSAGE.SET_TOKEN('COLUMN','DIRECTION_FLAG');
4523         FND_MSG_PUB.Add;
4524       end if;
4525     end if;
4526   else
4527     l_error := TRUE;
4528     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
4529       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
4530       FND_MESSAGE.SET_TOKEN('COLUMN', 'DIRECTION_FLAG');
4531       FND_MSG_PUB.Add;
4532     end if;
4533   end if;
4534 
4535   -- return true if no error, false otherwise
4536   p_return_status := FND_API.G_RET_STS_SUCCESS;
4537   return (not l_error);
4538 
4539 EXCEPTION
4540   WHEN FND_API.G_EXC_ERROR THEN
4541     p_return_status := FND_API.G_RET_STS_ERROR;
4542     return FALSE;
4543   WHEN OTHERS THEN
4544     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4545     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
4546                            SUBSTR (SQLERRM, 1, 240) );
4547     FND_MSG_PUB.Add;
4548     return FALSE;
4549 
4550 end VALIDATE_LOV_RELATION;
4551 
4552 /*
4553 --=======================================================
4554 --  Procedure   CREATE_GRAPH_COLUMN
4555 --
4556 --  Usage       Private API for creating a region graph column. This
4557 --              API should only be called by other APIs that are
4558 --              owned by the Core Modules Team (AK).
4559 --
4560 --  Desc        Creates a region graph column using the given info.
4561 --              This API should only be called by other APIs that are
4562 --              owned by the Core Modules Team (AK).
4563 --
4564 --  Results     The API returns the standard p_return_status parameter
4565 --              indicating one of the standard return statuses :
4566 --                  * Unexpected error
4567 --                  * Error
4568 --                  * Success
4569 --  Parameters  Region columns
4570 --              p_loader_timestamp : IN optional
4571 --                  If a timestamp is passed, the API will create the
4572 --                  record using this timestamp. Only the upload API
4573 --                  should call with this parameter loaded.
4574 --
4575 --  Version     Initial version number  =   1.1
4576 --=======================================================
4577 PROCEDURE CREATE_GRAPH_COLUMN (
4578   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
4579   p_api_version_number       IN      NUMBER,
4580   p_init_msg_tbl             IN      BOOLEAN := FALSE,
4581   p_msg_count                OUT NOCOPY     NUMBER,
4582   p_msg_data                 OUT NOCOPY     VARCHAR2,
4583   p_return_status            OUT NOCOPY     VARCHAR2,
4584   p_region_application_id    IN      NUMBER := FND_API.G_MISS_NUM,
4585   p_region_code              IN      VARCHAR2 := FND_API.G_MISS_CHAR,
4586   p_attribute_application_id IN      NUMBER := FND_API.G_MISS_NUM,
4587   p_attribute_code           IN      VARCHAR2 := FND_API.G_MISS_CHAR,
4588   p_graph_number	     IN      NUMBER := FND_API.G_MISS_NUM,
4589   p_created_by               IN     NUMBER := FND_API.G_MISS_NUM,
4590   p_creation_date            IN      DATE := FND_API.G_MISS_DATE,
4591   p_last_updated_by          IN     NUMBER := FND_API.G_MISS_NUM,
4592   p_last_update_date         IN      DATE := FND_API.G_MISS_DATE,
4593   p_last_update_login        IN     NUMBER := FND_API.G_MISS_NUM,
4594   p_loader_timestamp         IN      DATE := FND_API.G_MISS_DATE,
4595   p_pass                     IN      NUMBER,
4596   p_copy_redo_flag           IN OUT NOCOPY  BOOLEAN
4597 ) is
4598 
4599   l_api_version_number CONSTANT number := 1.0;
4600   l_api_name           CONSTANT varchar2(30) := 'Create_Graph_Column';
4601   l_created_by         number;
4602   l_creation_date      date;
4603   l_last_update_date   date;
4604   l_last_update_login  number;
4605   l_last_updated_by    number;
4606   l_return_status      varchar2(1);
4607 
4608 begin
4609 
4610   IF NOT FND_API.Compatible_API_Call (
4611     l_api_version_number, p_api_version_number, l_api_name,
4612     G_PKG_NAME) then
4613       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4614       return;
4615   END IF;
4616 
4617   -- Initialize the message table if requested.
4618 
4619   if p_init_msg_tbl then
4620     FND_MSG_PUB.initialize;
4621   end if;
4622 
4623   savepoint start_create_graph_column;
4624 
4625   --** check to see if row already exists **
4626   if AK_REGION2_PVT.GRAPH_COLUMN_EXISTS (
4627             p_api_version_number => 1.0,
4628             p_return_status => l_return_status,
4629             p_region_application_id => p_region_application_id,
4630             p_region_code => p_region_code,
4631             p_attribute_application_id => p_attribute_application_id,
4632             p_attribute_code => p_attribute_code,
4633 	    p_graph_number => p_graph_number) then
4634     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
4635       FND_MESSAGE.SET_NAME('AK','AK_GRAPH_COLUMN_EXISTS');
4636       FND_MSG_PUB.Add;
4637     end if;
4638     raise FND_API.G_EXC_ERROR;
4639   end if;
4640 
4641   --** validate table columns passed in **
4642   if p_validation_level <> FND_API.G_VALID_LEVEL_NONE then
4643     if not AK_REGION2_PVT.VALIDATE_GRAPH_COLUMN (
4644             p_validation_level => p_validation_level,
4645             p_api_version_number => 1.0,
4646             p_return_status => l_return_status,
4647             p_region_application_id => p_region_application_id,
4648             p_region_code => p_region_code,
4649             p_attribute_application_id => p_attribute_application_id,
4650             p_attribute_code => p_attribute_code,
4651 	    p_graph_number => p_graph_number,
4652             p_caller => AK_ON_OBJECTS_PVT.G_CREATE,
4653                         p_pass => p_pass
4654           ) then
4655       -- Do not raise an error if it's the first pass
4656           if (p_pass = 1) then
4657             p_copy_redo_flag := TRUE;
4658       else
4659         raise FND_API.G_EXC_ERROR;
4660       end if;
4661     end if;
4662   end if;
4663 
4664   -- Create record if no validation error was found
4665 
4666   -- Set WHO columns
4667   AK_UPLOAD_GRP.G_UPLOAD_DATE := p_last_update_date;
4668   AK_ON_OBJECTS_PVT.SET_WHO (
4669        p_return_status => l_return_status,
4670        p_loader_timestamp => p_loader_timestamp,
4671        p_created_by => l_created_by,
4672        p_creation_date => l_creation_date,
4673        p_last_updated_by => l_last_updated_by,
4674        p_last_update_date => l_last_update_date,
4675        p_last_update_login => l_last_update_login);
4676 
4677   if (AK_UPLOAD_GRP.G_NON_SEED_DATA) then
4678         l_created_by := p_created_by;
4679         l_last_updated_by := p_last_updated_by;
4680         l_last_update_login := p_last_update_login;
4681   end if;
4682 
4683   insert into AK_REGION_GRAPH_COLUMNS (
4684 	    REGION_APPLICATION_ID,
4685     REGION_CODE,
4686         ATTRIBUTE_APPLICATION_ID,
4687         ATTRIBUTE_CODE,
4688 	GRAPH_NUMBER,
4689     CREATION_DATE,
4690     CREATED_BY,
4691     LAST_UPDATE_DATE,
4692     LAST_UPDATED_BY,
4693     LAST_UPDATE_LOGIN
4694   ) values (
4695     p_region_application_id,
4696     p_region_code,
4697         p_attribute_application_id,
4698         p_attribute_code,
4699 	p_graph_number,
4700     l_creation_date,
4701     l_created_by,
4702     l_last_update_date,
4703     l_last_updated_by,
4704     l_last_update_login
4705   );
4706 
4707 --  ** commit the insert **
4708 --  commit;
4709 
4710   if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
4711     FND_MESSAGE.SET_NAME('AK','AK_GRAPH_COLUMN_CREATED');
4712     FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||' ' ||
4713                                         p_region_code||' '||
4714 					to_char(p_attribute_application_id)||
4715 					' '||p_attribute_code||' '||
4716 					to_char(p_graph_number));
4717     FND_MSG_PUB.Add;
4718   end if;
4719 
4720   p_return_status := FND_API.G_RET_STS_SUCCESS;
4721 
4722   FND_MSG_PUB.Count_And_Get (
4723         p_count => p_msg_count,
4724         p_data => p_msg_data);
4725 
4726 EXCEPTION
4727   WHEN VALUE_ERROR THEN
4728     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
4729       FND_MESSAGE.SET_NAME('AK','AK_GRAPH_COLUMN_VALUE_ERROR');
4730       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||' '||
4731                                         p_region_code||' '||
4732 					to_char(p_attribute_application_id)||
4733 					' '||p_attribute_code||' '||
4734 					to_char(p_graph_number));
4735       FND_MSG_PUB.Add;
4736     end if;
4737     p_return_status := FND_API.G_RET_STS_ERROR;
4738     rollback to start_create_graph_column;
4739     FND_MSG_PUB.Count_And_Get (
4740         p_count => p_msg_count,
4741         p_data => p_msg_data);
4742   WHEN OTHERS THEN
4743     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4744     rollback to start_create_graph_column;
4745     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
4746                            SUBSTR (SQLERRM, 1, 240) );
4747     FND_MSG_PUB.Add;
4748     FND_MSG_PUB.Count_And_Get (
4749         p_count => p_msg_count,
4750         p_data => p_msg_data);
4751 
4752 end CREATE_GRAPH_COLUMN;
4753 */
4754 
4755 --=======================================================
4756 --  Procedure   CREATE_LOV_RELATION
4757 --
4758 --  Usage       Private API for creating a region lov relation. This
4759 --              API should only be called by other APIs that are
4760 --              owned by the Core Modules Team (AK).
4761 --
4762 --  Desc        Creates a region lov relation using the given info.
4763 --              This API should only be called by other APIs that are
4764 --              owned by the Core Modules Team (AK).
4765 --
4766 --  Results     The API returns the standard p_return_status parameter
4767 --              indicating one of the standard return statuses :
4768 --                  * Unexpected error
4769 --                  * Error
4770 --                  * Success
4771 --  Parameters  Region columns
4772 --              p_loader_timestamp : IN optional
4773 --                  If a timestamp is passed, the API will create the
4774 --                  record using this timestamp. Only the upload API
4775 --                  should call with this parameter loaded.
4776 --
4777 --  Version     Initial version number  =   1.1
4778 --=======================================================
4779 PROCEDURE CREATE_LOV_RELATION (
4780   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
4781   p_api_version_number       IN      NUMBER,
4782   p_init_msg_tbl             IN      BOOLEAN := FALSE,
4783   p_msg_count                OUT NOCOPY     NUMBER,
4784   p_msg_data                 OUT NOCOPY     VARCHAR2,
4785   p_return_status            OUT NOCOPY     VARCHAR2,
4786   p_region_application_id    IN      NUMBER := FND_API.G_MISS_NUM,
4787   p_region_code              IN      VARCHAR2 := FND_API.G_MISS_CHAR,
4788   p_attribute_application_id IN      NUMBER := FND_API.G_MISS_NUM,
4789   p_attribute_code           IN      VARCHAR2 := FND_API.G_MISS_CHAR,
4790   p_lov_region_appl_id    	 IN      NUMBER := FND_API.G_MISS_NUM,
4791   p_lov_region_code          IN      VARCHAR2 := FND_API.G_MISS_CHAR,
4792   p_lov_attribute_appl_id	 IN      NUMBER := FND_API.G_MISS_NUM,
4793   p_lov_attribute_code       IN      VARCHAR2 := FND_API.G_MISS_CHAR,
4794   p_base_attribute_appl_id IN      NUMBER := FND_API.G_MISS_NUM,
4795   p_base_attribute_code     IN      VARCHAR2 := FND_API.G_MISS_CHAR,
4796   p_direction_flag			 IN		 VARCHAR2 := FND_API.G_MISS_CHAR,
4797   p_base_region_appl_id		IN 	NUMBER := FND_API.G_MISS_NUM,
4798   p_base_region_code		IN	VARCHAR2 := FND_API.G_MISS_CHAR,
4799   p_required_flag			IN		VARCHAR2 := FND_API.G_MISS_CHAR,
4800   p_created_by               IN     NUMBER := FND_API.G_MISS_NUM,
4801   p_creation_date            IN      DATE := FND_API.G_MISS_DATE,
4802   p_last_updated_by          IN     NUMBER := FND_API.G_MISS_NUM,
4803   p_last_update_date         IN      DATE := FND_API.G_MISS_DATE,
4804   p_last_update_login        IN     NUMBER := FND_API.G_MISS_NUM,
4805   p_loader_timestamp         IN      DATE := FND_API.G_MISS_DATE,
4806   p_pass                     IN      NUMBER,
4807   p_copy_redo_flag           IN OUT NOCOPY  BOOLEAN
4808 ) is
4809 
4810   l_api_version_number CONSTANT number := 1.0;
4811   l_api_name           CONSTANT varchar2(30) := 'Create_Lov_Relation';
4812   l_created_by         number;
4813   l_creation_date      date;
4814   l_direction_flag     VARCHAR2(30) := null;
4815   l_required_flag      VARCHAR2(1) := 'N';
4816   l_last_update_date   date;
4817   l_last_update_login  number;
4818   l_last_updated_by    number;
4819   l_return_status      varchar2(1);
4820 
4821 begin
4822 
4823   IF NOT FND_API.Compatible_API_Call (
4824     l_api_version_number, p_api_version_number, l_api_name,
4825     G_PKG_NAME) then
4826       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4827       return;
4828   END IF;
4829 
4830   -- Initialize the message table if requested.
4831 
4832   if p_init_msg_tbl then
4833     FND_MSG_PUB.initialize;
4834   end if;
4835 
4836   savepoint start_create_lov_relation;
4837 
4838   --** check to see if row already exists **
4839   if AK_REGION2_PVT.LOV_RELATION_EXISTS (
4840             p_api_version_number => 1.0,
4841             p_return_status => l_return_status,
4842             p_region_application_id => p_region_application_id,
4843             p_region_code => p_region_code,
4844             p_attribute_application_id => p_attribute_application_id,
4845             p_attribute_code => p_attribute_code,
4846             p_lov_region_appl_id => p_lov_region_appl_id,
4847             p_lov_region_code => p_lov_region_code,
4848             p_lov_attribute_appl_id => p_lov_attribute_appl_id,
4849             p_lov_attribute_code => p_lov_attribute_code,
4850 	    p_base_attribute_appl_id => p_base_attribute_appl_id,
4851 	    p_base_attribute_code => p_base_attribute_code,
4852             p_direction_flag => p_direction_flag,
4853 	    p_base_region_appl_id => p_base_region_appl_id,
4854 	    p_base_region_code => p_base_region_code) then
4855     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
4856       FND_MESSAGE.SET_NAME('AK','AK_LOV_RELATION_EXISTS');
4857       FND_MSG_PUB.Add;
4858     end if;
4859     raise FND_API.G_EXC_ERROR;
4860   end if;
4861 
4862   --** validate table columns passed in **
4863   if p_validation_level <> FND_API.G_VALID_LEVEL_NONE then
4864     if not AK_REGION2_PVT.VALIDATE_LOV_RELATION (
4865             p_validation_level => p_validation_level,
4866             p_api_version_number => 1.0,
4867             p_return_status => l_return_status,
4868             p_region_application_id => p_region_application_id,
4869             p_region_code => p_region_code,
4870 	    p_attribute_application_id => p_attribute_application_id,
4871             p_attribute_code => p_attribute_code,
4872             p_lov_region_appl_id => p_lov_region_appl_id,
4873             p_lov_region_code => p_lov_region_code,
4874             p_lov_attribute_appl_id => p_lov_attribute_appl_id,
4875             p_lov_attribute_code => p_lov_attribute_code,
4876 	    p_base_attribute_appl_id => p_base_attribute_appl_id,
4877 	    p_base_attribute_code => p_base_attribute_code,
4878             p_direction_flag => p_direction_flag,
4879 	    p_base_region_appl_id => p_base_region_appl_id,
4880 	    p_base_region_code => p_base_region_code,
4881             p_caller => AK_ON_OBJECTS_PVT.G_CREATE,
4882 			p_pass => p_pass
4883           ) then
4884       -- Do not raise an error if it's the first pass
4885 	  if (p_pass = 1) then
4886 	    p_copy_redo_flag := TRUE;
4887       else
4888         raise FND_API.G_EXC_ERROR;
4889       end if;
4890     end if;
4891   end if;
4892 
4893   -- default a value for required_flag column if no value is given
4894   if ( p_required_flag <> FND_API.G_MISS_CHAR and p_required_flag is not null ) then
4895 	l_required_flag := p_required_flag;
4896   end if;
4897 
4898   if (p_created_by <> FND_API.G_MISS_NUM) then
4899     l_created_by := p_created_by;
4900   end if;
4901 
4902   if (p_creation_date <> FND_API.G_MISS_DATE) then
4903     l_creation_date := p_creation_date;
4904   end if;
4905 
4906   if (p_last_updated_by <> FND_API.G_MISS_NUM) then
4907     l_last_updated_by := p_last_updated_by;
4908   end if;
4909 
4910   if (p_last_update_date <> FND_API.G_MISS_DATE) then
4911     l_last_update_date := p_last_update_date;
4912   end if;
4913 
4914   if (p_last_update_login <> FND_API.G_MISS_NUM) then
4915     l_last_update_login := p_last_update_login;
4916   end if;
4917 
4918 
4919   -- Create record if no validation error was found
4920   --  NOTE - Calling IS_UPDATEABLE for backward compatibility
4921   --  old jlt files didn't have who columns and IS_UPDATEABLE
4922   --  calls SET_WHO which populates those columns, for later
4923   --  jlt files IS_UPDATEABLE will always return TRUE for CREATE
4924 
4925 if AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
4926        p_loader_timestamp => p_loader_timestamp,
4927        p_created_by => l_created_by,
4928        p_creation_date => l_creation_date,
4929        p_last_updated_by => l_last_updated_by,
4930        p_db_last_updated_by => null,
4931        p_last_update_date => l_last_update_date,
4932        p_db_last_update_date => null,
4933        p_last_update_login => l_last_update_login,
4934        p_create_or_update => 'CREATE') then
4935      null;
4936   end if;
4937 
4938   insert into AK_REGION_LOV_RELATIONS (
4939     REGION_APPLICATION_ID,
4940     REGION_CODE,
4941 	ATTRIBUTE_APPLICATION_ID,
4942 	ATTRIBUTE_CODE,
4943 	LOV_REGION_APPL_ID,
4944 	LOV_REGION_CODE,
4945 	LOV_ATTRIBUTE_APPL_ID,
4946 	LOV_ATTRIBUTE_CODE,
4947 	BASE_ATTRIBUTE_APPL_ID,
4948 	BASE_ATTRIBUTE_CODE,
4949 	DIRECTION_FLAG,
4950 	BASE_REGION_APPL_ID,
4951 	BASE_REGION_CODE,
4952 	REQUIRED_FLAG,
4953     CREATION_DATE,
4954     CREATED_BY,
4955     LAST_UPDATE_DATE,
4956     LAST_UPDATED_BY,
4957     LAST_UPDATE_LOGIN
4958   ) values (
4959     p_region_application_id,
4960     p_region_code,
4961 	p_attribute_application_id,
4962 	p_attribute_code,
4963 	p_lov_region_appl_id,
4964 	p_lov_region_code,
4965 	p_lov_attribute_appl_id,
4966 	p_lov_attribute_code,
4967 	p_base_attribute_appl_id,
4968 	p_base_attribute_code,
4969 	p_direction_flag,
4970 	p_base_region_appl_id,
4971 	p_base_region_code,
4972 	l_required_flag,
4973     l_creation_date,
4974     l_created_by,
4975     l_last_update_date,
4976     l_last_updated_by,
4977     l_last_update_login
4978   );
4979 
4980 --  /** commit the insert **/
4981 --  commit;
4982 
4983   if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
4984     FND_MESSAGE.SET_NAME('AK','AK_LOV_RELATION_CREATED');
4985     FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||' ' ||
4986    					p_region_code||' '||to_char(p_attribute_application_id)||
4987    					' '||p_attribute_code||' '||
4988    					to_char(p_lov_region_appl_id)||' '||p_lov_region_code||
4989    					' '||to_char(p_lov_attribute_appl_id)||' '||
4990    					p_lov_region_code||' '||to_char(p_base_attribute_appl_id)||
4991    					' '||p_base_attribute_code);
4992     FND_MSG_PUB.Add;
4993   end if;
4994 
4995   p_return_status := FND_API.G_RET_STS_SUCCESS;
4996 
4997   FND_MSG_PUB.Count_And_Get (
4998         p_count => p_msg_count,
4999         p_data => p_msg_data);
5000 
5001 EXCEPTION
5002   WHEN VALUE_ERROR THEN
5003     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5004       FND_MESSAGE.SET_NAME('AK','AK_REGION_VALUE_ERROR');
5005       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||' '||
5006    					p_region_code||' '||to_char(p_attribute_application_id)||
5007    					' '||p_attribute_code||' '||
5008    					to_char(p_lov_region_appl_id)||' '||p_lov_region_code||
5009    					' '||to_char(p_lov_attribute_appl_id)||' '||
5010    					p_lov_region_code||' '||to_char(p_base_attribute_appl_id)||
5011    					' '||p_base_attribute_code);
5012       FND_MSG_PUB.Add;
5013     end if;
5014     p_return_status := FND_API.G_RET_STS_ERROR;
5015     rollback to start_create_lov_relation;
5016     FND_MSG_PUB.Count_And_Get (
5017         p_count => p_msg_count,
5018         p_data => p_msg_data);
5019   WHEN FND_API.G_EXC_ERROR THEN
5020     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5021       FND_MESSAGE.SET_NAME('AK','AK_REGION_NOT_CREATED');
5022       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||' '||
5023    					p_region_code||' '||to_char(p_attribute_application_id)||
5024    					' '||p_attribute_code||' '||
5025    					to_char(p_lov_region_appl_id)||' '||p_lov_region_code||
5026    					' '||to_char(p_lov_attribute_appl_id)||' '||
5027    					p_lov_region_code||' '||to_char(p_base_attribute_appl_id)||
5028    					' '||p_base_attribute_code);
5029       FND_MSG_PUB.Add;
5030     end if;
5031     p_return_status := FND_API.G_RET_STS_ERROR;
5032     rollback to start_create_lov_relation;
5033     FND_MSG_PUB.Count_And_Get (
5034         p_count => p_msg_count,
5035         p_data => p_msg_data);
5036   WHEN OTHERS THEN
5037     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5038     rollback to start_create_region;
5039     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
5040                            SUBSTR (SQLERRM, 1, 240) );
5041     FND_MSG_PUB.Add;
5042     FND_MSG_PUB.Count_And_Get (
5043         p_count => p_msg_count,
5044         p_data => p_msg_data);
5045 
5046 end CREATE_LOV_RELATION;
5047 
5048 /*
5049 --=======================================================
5050 --  Procedure   UPDATE_GRAPH_COLUMN
5051 --
5052 --  Usage       Private API for updating a region graph column.
5053 --              This API should only be called by other APIs
5054 --              that are owned by the Core Modules Team (AK).
5055 --
5056 --  Desc        This API updates a region graph column using the given info
5057 --
5058 --  Results     The API returns the standard p_return_status parameter
5059 --              indicating one of the standard return statuses :
5060 --                  * Unexpected error
5061 --                  * Error
5062 --                  * Success
5063 --  Parameters  Region graph column columns
5064 --              p_loader_timestamp : IN optional
5065 --                  If a timestamp is passed, the API will update the
5066 --                  record using this timestamp. Only the upload API
5067 --                  should call with this parameter loaded.
5068 --
5069 --  Version     Initial version number  =   1.0
5070 --  History     Current version number  =   1.0
5071 --=======================================================
5072 PROCEDURE UPDATE_GRAPH_COLUMN (
5073   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
5074   p_api_version_number       IN      NUMBER,
5075   p_init_msg_tbl             IN      BOOLEAN := FALSE,
5076   p_msg_count                OUT NOCOPY     NUMBER,
5077   p_msg_data                 OUT NOCOPY     VARCHAR2,
5078   p_return_status            OUT NOCOPY     VARCHAR2,
5079   p_region_application_id    IN      NUMBER := FND_API.G_MISS_NUM,
5080   p_region_code              IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5081   p_attribute_application_id IN      NUMBER := FND_API.G_MISS_NUM,
5082   p_attribute_code           IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5083   p_graph_number	     IN      NUMBER := FND_API.G_MISS_NUM,
5084   p_created_by               IN     NUMBER := FND_API.G_MISS_NUM,
5085   p_creation_date            IN      DATE := FND_API.G_MISS_DATE,
5086   p_last_updated_by          IN     NUMBER := FND_API.G_MISS_NUM,
5087   p_last_update_date         IN      DATE := FND_API.G_MISS_DATE,
5088   p_last_update_login        IN     NUMBER := FND_API.G_MISS_NUM,
5089   p_loader_timestamp         IN      DATE := FND_API.G_MISS_DATE,
5090   p_pass                     IN      NUMBER,
5091   p_copy_redo_flag           IN OUT NOCOPY  BOOLEAN
5092 ) is
5093   cursor l_get_row_csr is
5094     select *
5095     from  AK_REGION_GRAPH_COLUMNS
5096     where REGION_APPLICATION_ID = p_region_application_id
5097     and   REGION_CODE = p_region_code
5098         and   ATTRIBUTE_APPLICATION_ID = p_attribute_application_id
5099         and   ATTRIBUTE_CODE = p_attribute_code
5100 	and   GRAPH_NUMBER = p_graph_number
5101 	for update of GRAPH_NUMBER;
5102   l_api_version_number      CONSTANT number := 1.0;
5103   l_api_name                CONSTANT varchar2(30) := 'Update_Graph_Column';
5104   l_created_by              number;
5105   l_creation_date           date;
5106   l_graph_column_rec        AK_REGION_GRAPH_COLUMNS%ROWTYPE;
5107   l_last_update_date        date;
5108   l_last_update_login       number;
5109   l_last_updated_by         number;
5110   l_return_status           varchar2(1);
5111 begin
5112   IF NOT FND_API.Compatible_API_Call (
5113     l_api_version_number, p_api_version_number, l_api_name,
5114     G_PKG_NAME) then
5115       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5116       return;
5117   END IF;
5118 
5119   -- Initialize the message table if requested.
5120 
5121   if p_init_msg_tbl then
5122     FND_MSG_PUB.initialize;
5123   end if;
5124 
5125   savepoint start_update_graph_columns;
5126 
5127   --** retrieve ak_region_graph_columns row if it exists **
5128   open l_get_row_csr;
5129   fetch l_get_row_csr into l_graph_column_rec;
5130   if (l_get_row_csr%notfound) then
5131     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
5132       FND_MESSAGE.SET_NAME('AK','AK_GRAPH_COLUMN_DOES_NOT_EXIST');
5133       FND_MSG_PUB.Add;
5134     end if;
5135     --dbms_output.put_line(l_api_name || 'Error - Row does not exist');
5136     close l_get_row_csr;
5137     raise FND_API.G_EXC_ERROR;
5138   end if;
5139   close l_get_row_csr;
5140 
5141   --** validate table columns passed in **
5142   if p_validation_level <> FND_API.G_VALID_LEVEL_NONE then
5143     if not AK_REGION2_PVT.VALIDATE_GRAPH_COLUMN (
5144             p_validation_level => p_validation_level,
5145             p_api_version_number => 1.0,
5146             p_return_status => l_return_status,
5147             p_region_application_id => p_region_application_id,
5148             p_region_code => p_region_code,
5149             p_attribute_application_id => p_attribute_application_id,
5150             p_attribute_code => p_attribute_code,
5151 	    p_graph_number => p_graph_number,
5152             p_caller => AK_ON_OBJECTS_PVT.G_UPDATE,
5153                         p_pass => p_pass
5154       ) then
5155       --dbms_output.put_line(l_api_name || 'validation failed');
5156       -- Do not raise an error if it's the first pass
5157           if (p_pass = 1) then
5158             p_copy_redo_flag := TRUE;
5159       else
5160         raise FND_API.G_EXC_ERROR;
5161       end if; --  if p_pass
5162     end if;
5163   end if;
5164 
5165   --** Load record to be updated to the database **
5166   --** - first load nullable columns **
5167 
5168 
5169   --** - next, load non-null, non-key columns **
5170 
5171   -- Set WHO columns
5172   AK_UPLOAD_GRP.G_UPLOAD_DATE := p_last_update_date;
5173   AK_ON_OBJECTS_PVT.SET_WHO (
5174        p_return_status => l_return_status,
5175        p_loader_timestamp => p_loader_timestamp,
5176        p_created_by => l_created_by,
5177        p_creation_date => l_creation_date,
5178        p_last_updated_by => l_last_updated_by,
5179        p_last_update_date => l_last_update_date,
5180        p_last_update_login => l_last_update_login);
5181 
5182   if (AK_UPLOAD_GRP.G_NON_SEED_DATA) then
5183         l_created_by := p_created_by;
5184         l_last_updated_by := p_last_updated_by;
5185         l_last_update_login := p_last_update_login;
5186   end if;
5187 
5188   update AK_REGION_GRAPH_COLUMNS set
5189       LAST_UPDATE_DATE = l_last_update_date,
5190       LAST_UPDATED_BY = l_last_updated_by,
5191       LAST_UPDATE_LOGIN = l_last_update_login
5192   where REGION_APPLICATION_ID = p_region_application_id
5193   and   REGION_CODE = p_region_code
5194   and   ATTRIBUTE_APPLICATION_ID = p_attribute_application_id
5195   and   ATTRIBUTE_CODE = p_attribute_code
5196   and   GRAPH_NUMBER = p_graph_number;
5197   if (sql%notfound) then
5198     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5199       FND_MESSAGE.SET_NAME('AK','AK_GRAPH_COLUMN_UPDATE_FAILED');
5200       FND_MSG_PUB.Add;
5201     end if;
5202     raise FND_API.G_EXC_ERROR;
5203   end if;
5204 
5205 --  ** commit the update **
5206 --  commit;
5207 
5208   if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
5209     FND_MESSAGE.SET_NAME('AK','AK_GRAPH_COLUMN_UPDATED');
5210     FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||
5211                                  ' ' || p_region_code);
5212     FND_MSG_PUB.Add;
5213   end if;
5214 
5215    p_return_status := FND_API.G_RET_STS_SUCCESS;
5216 
5217   FND_MSG_PUB.Count_And_Get (
5218         p_count => p_msg_count,
5219         p_data => p_msg_data);
5220 
5221 EXCEPTION
5222   WHEN VALUE_ERROR THEN
5223     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5224       FND_MESSAGE.SET_NAME('AK','AK_GRAPH_COLUMN_VALUE_ERROR');
5225       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||' '||
5226                                         p_region_code||' '||
5227 					to_char(p_attribute_application_id)||
5228 					' '||p_attribute_code||' '||
5229 					to_char(p_graph_number));
5230       FND_MSG_PUB.Add;
5231     end if;
5232     rollback to start_update_graph_column;
5233     p_return_status := FND_API.G_RET_STS_ERROR;
5234     FND_MSG_PUB.Count_And_Get (
5235         p_count => p_msg_count,
5236         p_data => p_msg_data);
5237   WHEN FND_API.G_EXC_ERROR THEN
5238     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5239       FND_MESSAGE.SET_NAME('AK','AK_GRAPH_COLUMN_NOT_UPDATED');
5240       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||' '||
5241                                         p_region_code||' '||
5242 					to_char(p_attribute_application_id)||
5243 					' '||p_attribute_code||' '||
5244 					to_char(p_graph_number));
5245       FND_MSG_PUB.Add;
5246     end if;
5247     p_return_status := FND_API.G_RET_STS_ERROR;
5248     rollback to start_update_graph_column;
5249     FND_MSG_PUB.Count_And_Get (
5250         p_count => p_msg_count,
5251         p_data => p_msg_data);
5252   WHEN OTHERS THEN
5253     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5254     rollback to start_update_graph_column;
5255     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
5256                            SUBSTR (SQLERRM, 1, 240) );
5257     FND_MSG_PUB.Add;
5258     FND_MSG_PUB.Count_And_Get (
5259         p_count => p_msg_count,
5260         p_data => p_msg_data);
5261      FND_MSG_PUB.Count_And_Get (
5262         p_count => p_msg_count,
5263         p_data => p_msg_data);
5264 
5265 end UPDATE_GRAPH_COLUMN;
5266 */
5267 
5268 --=======================================================
5269 --  Procedure   UPDATE_LOV_RELATION
5270 --
5271 --  Usage       Private API for updating a region lov relation.
5272 --              This API should only be called by other APIs
5273 --              that are owned by the Core Modules Team (AK).
5274 --
5275 --  Desc        This API updates a region lov relation using the given info
5276 --
5277 --  Results     The API returns the standard p_return_status parameter
5278 --              indicating one of the standard return statuses :
5279 --                  * Unexpected error
5280 --                  * Error
5281 --                  * Success
5282 --  Parameters  Region lov relation columns
5283 --              p_loader_timestamp : IN optional
5284 --                  If a timestamp is passed, the API will update the
5285 --                  record using this timestamp. Only the upload API
5286 --                  should call with this parameter loaded.
5287 --
5288 --  Version     Initial version number  =   1.0
5289 --  History     Current version number  =   1.0
5290 --=======================================================
5291 PROCEDURE UPDATE_LOV_RELATION (
5292   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
5293   p_api_version_number       IN      NUMBER,
5294   p_init_msg_tbl             IN      BOOLEAN := FALSE,
5295   p_msg_count                OUT NOCOPY     NUMBER,
5296   p_msg_data                 OUT NOCOPY     VARCHAR2,
5297   p_return_status            OUT NOCOPY     VARCHAR2,
5298   p_region_application_id    IN      NUMBER := FND_API.G_MISS_NUM,
5299   p_region_code              IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5300   p_attribute_application_id IN      NUMBER := FND_API.G_MISS_NUM,
5301   p_attribute_code           IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5302   p_lov_region_appl_id    	 IN      NUMBER := FND_API.G_MISS_NUM,
5303   p_lov_region_code          IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5304   p_lov_attribute_appl_id	 IN      NUMBER := FND_API.G_MISS_NUM,
5305   p_lov_attribute_code       IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5306   p_base_attribute_appl_id	 IN      NUMBER := FND_API.G_MISS_NUM,
5307   p_base_attribute_code		 IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5308   p_direction_flag			 IN		 VARCHAR2 := FND_API.G_MISS_CHAR,
5309   p_base_region_appl_id		IN	NUMBER := FND_API.G_MISS_NUM,
5310   p_base_region_code		IN	VARCHAR2 := FND_API.G_MISS_CHAR,
5311   p_required_flag			 IN		 VARCHAR2 := FND_API.G_MISS_CHAR,
5312   p_created_by               IN     NUMBER := FND_API.G_MISS_NUM,
5313   p_creation_date            IN      DATE := FND_API.G_MISS_DATE,
5314   p_last_updated_by          IN     NUMBER := FND_API.G_MISS_NUM,
5315   p_last_update_date         IN      DATE := FND_API.G_MISS_DATE,
5316   p_last_update_login        IN     NUMBER := FND_API.G_MISS_NUM,
5317   p_loader_timestamp         IN      DATE := FND_API.G_MISS_DATE,
5318   p_pass                     IN      NUMBER,
5319   p_copy_redo_flag           IN OUT NOCOPY  BOOLEAN
5320 ) is
5321   cursor l_get_row_csr is
5322     select *
5323     from  AK_REGION_LOV_RELATIONS
5324     where REGION_APPLICATION_ID = p_region_application_id
5325     and   REGION_CODE = p_region_code
5326 	and   ATTRIBUTE_APPLICATION_ID = p_attribute_application_id
5327 	and   ATTRIBUTE_CODE = p_attribute_code
5328     and   LOV_REGION_APPL_ID = p_lov_region_appl_id
5329     and   LOV_REGION_CODE = p_lov_region_code
5330 	and   LOV_ATTRIBUTE_APPL_ID = p_lov_attribute_appl_id
5331 	and   LOV_ATTRIBUTE_CODE = p_lov_attribute_code
5332 	and	  BASE_ATTRIBUTE_APPL_ID = p_base_attribute_appl_id
5333 	and   BASE_ATTRIBUTE_CODE = p_base_attribute_code
5334 	and   DIRECTION_FLAG =p_direction_flag
5335 	and   BASE_REGION_APPL_ID = p_base_region_appl_id
5336 	and   BASE_REGION_CODE = p_base_region_code
5337     for update of REQUIRED_FLAG;
5338   l_api_version_number      CONSTANT number := 1.0;
5339   l_api_name                CONSTANT varchar2(30) := 'Update_Lov_Relation';
5340   l_created_by              number;
5341   l_creation_date           date;
5342   l_lov_relation_rec        AK_REGION_LOV_RELATIONS%ROWTYPE;
5343   l_required_flag			varchar2(1) := 'N';
5344   l_last_update_date        date;
5345   l_last_update_login       number;
5346   l_last_updated_by         number;
5347   l_return_status           varchar2(1);
5348 begin
5349   IF NOT FND_API.Compatible_API_Call (
5350     l_api_version_number, p_api_version_number, l_api_name,
5351     G_PKG_NAME) then
5352       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5353       return;
5354   END IF;
5355 
5356   -- Initialize the message table if requested.
5357 
5358   if p_init_msg_tbl then
5359     FND_MSG_PUB.initialize;
5360   end if;
5361 
5362   savepoint start_update_lov_relation;
5363 
5364   --** retrieve ak_region_lov_relations row if it exists **
5365   open l_get_row_csr;
5366   fetch l_get_row_csr into l_lov_relation_rec;
5367   if (l_get_row_csr%notfound) then
5368     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
5369       FND_MESSAGE.SET_NAME('AK','AK_LOV_REGION_DOES_NOT_EXIST');
5370       FND_MSG_PUB.Add;
5371     end if;
5372     --dbms_output.put_line(l_api_name || 'Error - Row does not exist');
5373     close l_get_row_csr;
5374     raise FND_API.G_EXC_ERROR;
5375   end if;
5376   close l_get_row_csr;
5377 
5378   --** validate table columns passed in **
5379   if p_validation_level <> FND_API.G_VALID_LEVEL_NONE then
5380     if not AK_REGION2_PVT.VALIDATE_LOV_RELATION (
5381             p_validation_level => p_validation_level,
5382             p_api_version_number => 1.0,
5383             p_return_status => l_return_status,
5384             p_region_application_id => p_region_application_id,
5385             p_region_code => p_region_code,
5386 	    p_attribute_application_id => p_attribute_application_id,
5387             p_attribute_code => p_attribute_code,
5388             p_lov_region_appl_id => p_lov_region_appl_id,
5389             p_lov_region_code => p_lov_region_code,
5390             p_lov_attribute_appl_id => p_lov_attribute_appl_id,
5391             p_lov_attribute_code => p_lov_attribute_code,
5392 	    p_base_attribute_appl_id => p_base_attribute_appl_id,
5393 	    p_base_attribute_code => p_base_attribute_code,
5394             p_direction_flag => p_direction_flag,
5395 	    p_base_region_appl_id => p_base_region_appl_id,
5396 	    p_base_region_code => p_base_region_code,
5397             p_caller => AK_ON_OBJECTS_PVT.G_UPDATE,
5398 			p_pass => p_pass
5399       ) then
5400       --dbms_output.put_line(l_api_name || 'validation failed');
5401       -- Do not raise an error if it's the first pass
5402 	  if (p_pass = 1) then
5403 	    p_copy_redo_flag := TRUE;
5404       else
5405         raise FND_API.G_EXC_ERROR;
5406       end if; -- /* if p_pass */
5407     end if;
5408   end if;
5409 
5410   --** Load record to be updated to the database **
5411   --** - first load nullable columns **
5412 
5413 
5414   --** - next, load non-null, non-key columns **
5415 
5416   -- default a value for required_flag column if no value is given
5417   if ( p_required_flag <> FND_API.G_MISS_CHAR and p_required_flag is not null ) then
5418 	l_lov_relation_rec.required_flag := p_required_flag;
5419   else
5420   	l_lov_relation_rec.required_flag := l_required_flag;
5421   end if;
5422 
5423   if (p_created_by <> FND_API.G_MISS_NUM) then
5424     l_created_by := p_created_by;
5425   end if;
5426 
5427   if (p_creation_date <> FND_API.G_MISS_DATE) then
5428     l_creation_date := p_creation_date;
5429   end if;
5430 
5431   if (p_last_updated_by <> FND_API.G_MISS_NUM) then
5432     l_last_updated_by := p_last_updated_by;
5433   end if;
5434 
5435   if (p_last_update_date <> FND_API.G_MISS_DATE) then
5436     l_last_update_date := p_last_update_date;
5437   end if;
5438 
5439   if (p_last_update_login <> FND_API.G_MISS_NUM) then
5440     l_last_update_login := p_last_update_login;
5441   end if;
5442 
5443   -- Set WHO columns
5444   if AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
5445        p_loader_timestamp => p_loader_timestamp,
5446        p_created_by => l_created_by,
5447        p_creation_date => l_creation_date,
5448        p_last_updated_by => l_last_updated_by,
5449        p_db_last_updated_by => l_lov_relation_rec.last_updated_by,
5450        p_last_update_date => l_last_update_date,
5451        p_db_last_update_date => l_lov_relation_rec.last_update_date,
5452        p_last_update_login => l_last_update_login,
5453        p_create_or_update => 'UPDATE') then
5454 
5455   update AK_REGION_LOV_RELATIONS set
5456       REQUIRED_FLAG = l_lov_relation_rec.required_flag,
5457       LAST_UPDATE_DATE = l_last_update_date,
5458       LAST_UPDATED_BY = l_last_updated_by,
5459       LAST_UPDATE_LOGIN = l_last_update_login
5460   where REGION_APPLICATION_ID = p_region_application_id
5461   and   REGION_CODE = p_region_code
5462   and	ATTRIBUTE_APPLICATION_ID = p_attribute_application_id
5463   and   ATTRIBUTE_CODE = p_attribute_code
5464   and   LOV_REGION_APPL_ID = p_lov_region_appl_id
5465   and   LOV_REGION_CODE = p_lov_region_code
5466   and   LOV_ATTRIBUTE_APPL_ID = p_lov_attribute_appl_id
5467   and   LOV_ATTRIBUTE_CODE = p_lov_attribute_code
5468   and	BASE_ATTRIBUTE_APPL_ID = p_base_attribute_appl_id
5469   and	BASE_ATTRIBUTE_CODE = p_base_attribute_code
5470   and	DIRECTION_FLAG = p_direction_flag
5471   and   BASE_REGION_APPL_ID = p_base_region_appl_id
5472   and   BASE_REGION_CODE = p_base_region_code;
5473   if (sql%notfound) then
5474     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5475       FND_MESSAGE.SET_NAME('AK','AK_LOV_RELATION_UPDATE_FAILED');
5476       FND_MSG_PUB.Add;
5477     end if;
5478     raise FND_API.G_EXC_ERROR;
5479   end if;
5480 
5481 --  /** commit the update **/
5482 --  commit;
5483 
5484   if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
5485     FND_MESSAGE.SET_NAME('AK','AK_LOV_RELATION_UPDATED');
5486     FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||
5487                                  ' ' || p_region_code);
5488     FND_MSG_PUB.Add;
5489   end if;
5490 
5491   end if;
5492    p_return_status := FND_API.G_RET_STS_SUCCESS;
5493 
5494   FND_MSG_PUB.Count_And_Get (
5495         p_count => p_msg_count,
5496         p_data => p_msg_data);
5497 
5498 EXCEPTION
5499   WHEN VALUE_ERROR THEN
5500     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5501       FND_MESSAGE.SET_NAME('AK','AK_LOV_RELATION_VALUE_ERROR');
5502       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||' '||
5503    					p_region_code||' '||to_char(p_attribute_application_id)||
5504    					' '||p_attribute_code||' '||
5505    					to_char(p_lov_region_appl_id)||' '||p_lov_region_code||
5506    					' '||to_char(p_lov_attribute_appl_id)||' '||
5507    					p_lov_region_code||' '||to_char(p_base_attribute_appl_id)||
5508    					' '||p_base_attribute_code||' '||p_direction_flag ||
5509 					' '||to_char(p_base_region_appl_id)||' '||p_base_region_code);
5510       FND_MSG_PUB.Add;
5511     end if;
5512     rollback to start_update_lov_relation;
5513     p_return_status := FND_API.G_RET_STS_ERROR;
5514     FND_MSG_PUB.Count_And_Get (
5515         p_count => p_msg_count,
5516         p_data => p_msg_data);
5517   WHEN FND_API.G_EXC_ERROR THEN
5518     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
5519       FND_MESSAGE.SET_NAME('AK','AK_LOV_RELATION_NOT_UPDATED');
5520       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||' '||
5521    					p_region_code||' '||to_char(p_attribute_application_id)||
5522    					' '||p_attribute_code||' '||
5523    					to_char(p_lov_region_appl_id)||' '||p_lov_region_code||
5524    					' '||to_char(p_lov_attribute_appl_id)||' '||
5525    					p_lov_region_code||' '||to_char(p_base_attribute_appl_id)||
5526    					' '||p_base_attribute_code);
5527       FND_MSG_PUB.Add;
5528     end if;
5529     p_return_status := FND_API.G_RET_STS_ERROR;
5530     rollback to start_update_lov_relation;
5531     FND_MSG_PUB.Count_And_Get (
5532         p_count => p_msg_count,
5533         p_data => p_msg_data);
5534   WHEN OTHERS THEN
5535     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5536     rollback to start_update_lov_relation;
5537     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
5538                            SUBSTR (SQLERRM, 1, 240) );
5539     FND_MSG_PUB.Add;
5540     FND_MSG_PUB.Count_And_Get (
5541         p_count => p_msg_count,
5542         p_data => p_msg_data);
5543      FND_MSG_PUB.Count_And_Get (
5544         p_count => p_msg_count,
5545         p_data => p_msg_data);
5546 
5547 end UPDATE_LOV_RELATION;
5548 
5549 --=======================================================
5550 --  Function    CATEGORY_USAGE_EXISTS
5551 --
5552 --  Usage       Private API for checking for the existence of
5553 --              a region item category usage with the given key values. This
5554 --              API should only be called by other APIs that are
5555 --              owned by the Core Modules Team (AK).
5556 --
5557 --  Desc        This API check to see if a region item category usage record
5558 --              exists with the given key values.
5559 --
5560 --  Results     The API returns the standard p_return_status parameter
5561 --              indicating one of the standard return statuses :
5562 --                  * Unexpected error
5563 --                  * Error
5564 --                  * Success
5565 --              This function will return TRUE if such an object
5566 --              attribute exists, or FALSE otherwise.
5567 --  Parameters  Region Lov Relation key columns
5568 --
5569 --  Version     Initial version number  =   1.0
5570 --  History     Current version number  =   1.0
5571 --=======================================================
5572 FUNCTION CATEGORY_USAGE_EXISTS (
5573   p_api_version_number		IN      NUMBER,
5574   p_return_status			OUT NOCOPY		VARCHAR2,
5575   p_region_application_id	IN		NUMBER,
5576   p_region_code				IN		VARCHAR2,
5577   p_attribute_application_id IN		NUMBER,
5578   p_attribute_code			IN		VARCHAR2,
5579   p_category_name	        	IN		VARCHAR2
5580 ) return boolean is
5581   cursor l_check_category_usage_csr is
5582     select 1
5583     from  AK_CATEGORY_USAGES
5584     where region_application_id = p_region_application_id
5585     and   region_code = p_region_code
5586     and   attribute_application_id = p_attribute_application_id
5587     and   attribute_code = p_attribute_code
5588     and   category_name = p_category_name;
5589   l_api_version_number CONSTANT number := 1.0;
5590   l_api_name           CONSTANT varchar2(30) := 'Category_Usage_Exists';
5591   l_dummy              number;
5592 begin
5593   IF NOT FND_API.Compatible_API_Call (
5594     l_api_version_number, p_api_version_number, l_api_name,
5595     G_PKG_NAME) then
5596       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5597       return FALSE;
5598   END IF;
5599 
5600   open l_check_category_usage_csr;
5601   fetch l_check_category_usage_csr into l_dummy;
5602   if (l_check_category_usage_csr%notfound) then
5603     close l_check_category_usage_csr;
5604     p_return_status := FND_API.G_RET_STS_SUCCESS;
5605      return FALSE;
5606   else
5607     close l_check_category_usage_csr;
5608     p_return_status := FND_API.G_RET_STS_SUCCESS;
5609     return TRUE;
5610   end if;
5611 
5612 EXCEPTION
5613   WHEN FND_API.G_EXC_ERROR THEN
5614     p_return_status := FND_API.G_RET_STS_ERROR;
5615     return FALSE;
5616   WHEN OTHERS THEN
5617     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5618     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
5619                            SUBSTR (SQLERRM, 1, 240) );
5620     FND_MSG_PUB.Add;
5621     return FALSE;
5622 end CATEGORY_USAGE_EXISTS;
5623 
5624 --=======================================================
5625 --  Function    VALIDATE_CATEGORY_USAGE
5626 --
5627 --  Usage       Private API for validating a region item category usage. This
5628 --              API should only be called by other APIs that are
5629 --              owned by the Core Modules Team (AK).
5630 --
5631 --  Desc        Perform validation on a region lov relation record.
5632 --
5633 --  Results     The API returns the standard p_return_status parameter
5634 --              indicating one of the standard return statuses :
5635 --                  * Unexpected error
5636 --                  * Error
5637 --                  * Success
5638 --              In addition, this function returns TRUE if all
5639 --              validation tests are passed, or FALSE otherwise.
5640 --  Parameters  Region lov relation columns
5641 --              p_caller : IN required
5642 --                  Must be one of the following values defined
5643 --                  in package AK_ON_OBJECTS_PVT:
5644 --                  - G_CREATE   (if calling from the Create API)
5645 --                  - G_DOWNLOAD (if calling from the Download API)
5646 --                  - G_UPDATE   (if calling from the Update API)
5647 --
5648 --  Note        This API is intended for performing record-level
5649 --              validation. It is not designed for item-level
5650 --              validation.
5651 --
5652 --  Version     Initial version number  =   1.1
5653 --=======================================================
5654 FUNCTION VALIDATE_CATEGORY_USAGE (
5655   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
5656   p_api_version_number       IN      NUMBER,
5657   p_return_status            OUT NOCOPY     VARCHAR2,
5658   p_region_application_id    IN      NUMBER := FND_API.G_MISS_NUM,
5659   p_region_code              IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5660   p_attribute_application_id IN      NUMBER := FND_API.G_MISS_NUM,
5661   p_attribute_code           IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5662   p_category_name    	         IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5663   p_category_id			IN 	NUMBER := FND_API.G_MISS_NUM,
5664   p_application_id		IN	NUMBER := FND_API.G_MISS_NUM,
5665   p_show_all			IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5666   p_caller                   IN      VARCHAR2,
5667   p_pass                     IN      NUMBER := 2
5668 ) return boolean is
5669 
5670   cursor l_check_region_item_csr (param_region_code in varchar2, param_region_appl_id in number,
5671   						param_attr_code in varchar2, param_attr_appl_id number) is
5672     select  item_style
5673     from    AK_REGION_ITEMS
5674     where   region_application_id = param_region_appl_id
5675     and     region_code = param_region_code
5676     and     attribute_application_id = param_attr_appl_id
5677     and     attribute_code = param_attr_code;
5678 
5679   cursor l_check_category_csr (param_category_name in varchar2) is
5680     select 1
5681 	from fnd_document_categories_vl
5682 	where name = param_category_name;
5683 
5684   l_api_version_number      CONSTANT number := 1.0;
5685   l_api_name                CONSTANT varchar2(30) := 'validate_category_usage';
5686 
5687   l_item_style              VARCHAR2(30);
5688   l_dummy		    NUMBER;
5689   l_error                   BOOLEAN;
5690   l_return_status           VARCHAR2(1);
5691 begin
5692 
5693   IF NOT FND_API.Compatible_API_Call (
5694     l_api_version_number, p_api_version_number, l_api_name,
5695     G_PKG_NAME) then
5696       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5697       return FALSE;
5698   END IF;
5699 
5700   l_error := FALSE;
5701 
5702   --** if validation level is none, no validation is necessary
5703   if (p_validation_level = FND_API.G_VALID_LEVEL_NONE) then
5704     p_return_status := FND_API.G_RET_STS_SUCCESS;
5705     return TRUE;
5706   end if;
5707 
5708   --** check that key columns are not null and not missing **
5709   if ((p_region_application_id is null) or
5710       (p_region_application_id = FND_API.G_MISS_NUM)) then
5711     l_error := TRUE;
5712     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
5713       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
5714       FND_MESSAGE.SET_TOKEN('COLUMN', 'REGION_APPLICATION_ID');
5715       FND_MSG_PUB.Add;
5716     end if;
5717   end if;
5718 
5719   if ((p_region_code is null) or
5720       (p_region_code = FND_API.G_MISS_CHAR)) then
5721     l_error := TRUE;
5722     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
5723       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
5724       FND_MESSAGE.SET_TOKEN('COLUMN', 'REGION_CODE');
5725       FND_MSG_PUB.Add;
5726     end if;
5727   end if;
5728 
5729   if ((p_attribute_application_id is null) or
5730       (p_attribute_application_id = FND_API.G_MISS_NUM)) then
5731     l_error := TRUE;
5732     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
5733       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
5734       FND_MESSAGE.SET_TOKEN('COLUMN', 'ATTRIBUTE_APPLICATION_ID');
5735       FND_MSG_PUB.Add;
5736     end if;
5737   end if;
5738 
5739   if ((p_attribute_code is null) or
5740       (p_attribute_code = FND_API.G_MISS_CHAR)) then
5741     l_error := TRUE;
5742     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
5743       FND_MESSAGE.SET_NAME('AK','AK_CANNOT_BE_NULL');
5744       FND_MESSAGE.SET_TOKEN('COLUMN', 'ATTRIBUTE_CODE');
5745       FND_MSG_PUB.Add;
5746     end if;
5747   end if;
5748 
5749   -- - Check that the parent region item exists
5750   open l_check_region_item_csr(p_region_code, p_region_application_id,
5751   						p_attribute_code, p_attribute_application_id);
5752   fetch l_check_region_item_csr into l_item_style;
5753   if (l_check_region_item_csr%notfound) then
5754     l_error := TRUE;
5755     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
5756       FND_MESSAGE.SET_NAME('AK','AK_INVALID_REG_ITEM_REFERENCE');
5757       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||
5758                            ' ' || p_region_code ||' '||
5759                            to_char(p_attribute_application_id)||' '||p_attribute_code);
5760       FND_MSG_PUB.Add;
5761     end if;
5762   else
5763     if ( l_item_style <> 'ATTACHMENT_LINK' AND l_item_style <> 'ATTACHMENT_IMAGE' AND
5764 		l_item_style <> 'ATTACHMENT_TABLE') then
5765 	l_error := TRUE;
5766 	if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
5767 	  FND_MESSAGE.SET_NAME('AK','AK_INVALID_ITEM_STYLE');
5768 	  FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||
5769                                ' ' || p_region_code ||' '||
5770                                 to_char(p_attribute_application_id)||' '||p_attribute_code||'  '||l_item_style);
5771 	  FND_MSG_PUB.Add;
5772 	end if;
5773     end if; -- l_item_style <> 'ATTACHMENT%'
5774   end if;
5775   close l_check_region_item_csr;
5776 
5777   -- - Check that the category exists
5778   open l_check_category_csr(p_category_name);
5779   fetch l_check_category_csr into l_dummy;
5780   if (l_check_category_csr%notfound) then
5781     l_error := TRUE;
5782     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
5783       FND_MESSAGE.SET_NAME('AK','AK_INVALID_CATEGORY_REFERENCE');
5784       FND_MESSAGE.SET_TOKEN('KEY', p_category_name);
5785       FND_MSG_PUB.Add;
5786     end if;
5787   end if;
5788   close l_check_category_csr;
5789 
5790   -- return true if no error, false otherwise
5791   p_return_status := FND_API.G_RET_STS_SUCCESS;
5792   return (not l_error);
5793 
5794 EXCEPTION
5795   WHEN FND_API.G_EXC_ERROR THEN
5796     p_return_status := FND_API.G_RET_STS_ERROR;
5797     return FALSE;
5798   WHEN OTHERS THEN
5799     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5800     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
5801                            SUBSTR (SQLERRM, 1, 240) );
5802     FND_MSG_PUB.Add;
5803     return FALSE;
5804 
5805 end VALIDATE_CATEGORY_USAGE;
5806 
5807 --=======================================================
5808 --  Procedure   CREATE_CATEGORY_USAGE
5809 --
5810 --  Usage       Private API for creating a region item category usage. This
5811 --              API should only be called by other APIs that are
5812 --              owned by the Core Modules Team (AK).
5813 --
5814 --  Desc        Creates a region item category usage using the given info.
5815 --              This API should only be called by other APIs that are
5816 --              owned by the Core Modules Team (AK).
5817 --
5818 --  Results     The API returns the standard p_return_status parameter
5819 --              indicating one of the standard return statuses :
5820 --                  * Unexpected error
5821 --                  * Error
5822 --                  * Success
5823 --  Parameters  Region columns
5824 --              p_loader_timestamp : IN optional
5825 --                  If a timestamp is passed, the API will create the
5826 --                  record using this timestamp. Only the upload API
5827 --                  should call with this parameter loaded.
5828 --
5829 --  Version     Initial version number  =   1.1
5830 --=======================================================
5831 PROCEDURE CREATE_CATEGORY_USAGE (
5832   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
5833   p_api_version_number       IN      NUMBER,
5834   p_init_msg_tbl             IN      BOOLEAN := FALSE,
5835   p_msg_count                OUT NOCOPY     NUMBER,
5836   p_msg_data                 OUT NOCOPY     VARCHAR2,
5837   p_return_status            OUT NOCOPY     VARCHAR2,
5838   p_region_application_id    IN      NUMBER := FND_API.G_MISS_NUM,
5839   p_region_code              IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5840   p_attribute_application_id IN      NUMBER := FND_API.G_MISS_NUM,
5841   p_attribute_code           IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5842   p_category_name	     IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5843   p_category_id         	 IN      NUMBER := FND_API.G_MISS_NUM,
5844   p_application_id	     IN      NUMBER := FND_API.G_MISS_NUM,
5845   p_show_all		     IN      VARCHAR2 := FND_API.G_MISS_CHAR,
5846   p_created_by               IN     NUMBER := FND_API.G_MISS_NUM,
5847   p_creation_date            IN      DATE := FND_API.G_MISS_DATE,
5848   p_last_updated_by          IN     NUMBER := FND_API.G_MISS_NUM,
5849   p_last_update_date         IN      DATE := FND_API.G_MISS_DATE,
5850   p_last_update_login        IN     NUMBER := FND_API.G_MISS_NUM,
5851   p_loader_timestamp         IN      DATE := FND_API.G_MISS_DATE,
5852   p_pass                     IN      NUMBER,
5853   p_copy_redo_flag           IN OUT NOCOPY  BOOLEAN
5854 ) is
5855 
5856   l_api_version_number CONSTANT number := 1.0;
5857   l_api_name           CONSTANT varchar2(30) := 'Create_Category_Usage';
5858   l_created_by         number;
5859   l_creation_date      date;
5860   l_last_update_date   date;
5861   l_last_update_login  number;
5862   l_last_updated_by    number;
5863   l_return_status      varchar2(1);
5864 
5865 begin
5866 
5867   IF NOT FND_API.Compatible_API_Call (
5868     l_api_version_number, p_api_version_number, l_api_name,
5869     G_PKG_NAME) then
5870       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5871       return;
5872   END IF;
5873 
5874   -- Initialize the message table if requested.
5875 
5876   if p_init_msg_tbl then
5877     FND_MSG_PUB.initialize;
5878   end if;
5879 
5880   savepoint start_create_category_usage;
5881 
5882   --** check to see if row already exists **
5883   if AK_REGION2_PVT.CATEGORY_USAGE_EXISTS (
5884             p_api_version_number => 1.0,
5885             p_return_status => l_return_status,
5886             p_region_application_id => p_region_application_id,
5887             p_region_code => p_region_code,
5888             p_attribute_application_id => p_attribute_application_id,
5889             p_attribute_code => p_attribute_code,
5890             p_category_name => p_category_name) then
5891     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
5892       FND_MESSAGE.SET_NAME('AK','AK_CATEGORY_USAGE_EXISTS');
5893       FND_MSG_PUB.Add;
5894     end if;
5895     raise FND_API.G_EXC_ERROR;
5896   end if;
5897 
5898   --** validate table columns passed in **
5899   if p_validation_level <> FND_API.G_VALID_LEVEL_NONE then
5900     if not AK_REGION2_PVT.VALIDATE_CATEGORY_USAGE (
5901             p_validation_level => p_validation_level,
5902             p_api_version_number => 1.0,
5903             p_return_status => l_return_status,
5904             p_region_application_id => p_region_application_id,
5905             p_region_code => p_region_code,
5906             p_attribute_application_id => p_attribute_application_id,
5907             p_attribute_code => p_attribute_code,
5908             p_category_name => p_category_name,
5909 	    p_category_id => p_category_id,
5910 	    p_application_id => p_application_id,
5911 	    p_show_all => p_show_all,
5912             p_caller => AK_ON_OBJECTS_PVT.G_CREATE,
5913 			p_pass => p_pass
5914           ) then
5915       -- Do not raise an error if it's the first pass
5916 	  if (p_pass = 1) then
5917 	    p_copy_redo_flag := TRUE;
5918       else
5919         raise FND_API.G_EXC_ERROR;
5920       end if;
5921     end if;
5922   end if;
5923 
5924   if (p_created_by <> FND_API.G_MISS_NUM) then
5925     l_created_by := p_created_by;
5926   end if;
5927 
5928   if (p_creation_date <> FND_API.G_MISS_DATE) then
5929     l_creation_date := p_creation_date;
5930   end if;
5931 
5932   if (p_last_updated_by <> FND_API.G_MISS_NUM) then
5933     l_last_updated_by := p_last_updated_by;
5934   end if;
5935 
5936   if (p_last_update_date <> FND_API.G_MISS_DATE) then
5937     l_last_update_date := p_last_update_date;
5938   end if;
5939 
5940   if (p_last_update_login <> FND_API.G_MISS_NUM) then
5941     l_last_update_login := p_last_update_login;
5942   end if;
5943 
5944   -- Create record if no validation error was found
5945   --  NOTE - Calling IS_UPDATEABLE for backward compatibility
5946   --  old jlt files didn't have who columns and IS_UPDATEABLE
5947   --  calls SET_WHO which populates those columns, for later
5948   --  jlt files IS_UPDATEABLE will always return TRUE for CREATE
5949 
5950 if AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
5951        p_loader_timestamp => p_loader_timestamp,
5952        p_created_by => l_created_by,
5953        p_creation_date => l_creation_date,
5954        p_last_updated_by => l_last_updated_by,
5955        p_db_last_updated_by => null,
5956        p_last_update_date => l_last_update_date,
5957        p_db_last_update_date => null,
5958        p_last_update_login => l_last_update_login,
5959        p_create_or_update => 'CREATE') then
5960      null;
5961   end if;
5962 
5963   insert into AK_CATEGORY_USAGES (
5964     REGION_APPLICATION_ID,
5965     REGION_CODE,
5966 	ATTRIBUTE_APPLICATION_ID,
5967 	ATTRIBUTE_CODE,
5968 	CATEGORY_NAME,
5969 	CATEGORY_ID,
5970 	APPLICATION_ID,
5971 	SHOW_ALL,
5972     CREATION_DATE,
5973     CREATED_BY,
5974     LAST_UPDATE_DATE,
5975     LAST_UPDATED_BY,
5976     LAST_UPDATE_LOGIN
5977   ) values (
5978     p_region_application_id,
5979     p_region_code,
5980 	p_attribute_application_id,
5981 	p_attribute_code,
5982 	p_category_name,
5983 	p_category_id,
5984 	p_application_id,
5985 	p_show_all,
5986     l_creation_date,
5987     l_created_by,
5988     l_last_update_date,
5989     l_last_updated_by,
5990     l_last_update_login
5991   );
5992 
5993 --  /** commit the insert **/
5994 --  commit;
5995 
5996   if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
5997     FND_MESSAGE.SET_NAME('AK','AK_CATEGORY_USAGE_CREATED');
5998     FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||' ' ||
5999    					p_region_code||' '||to_char(p_attribute_application_id)||
6000    					' '||p_attribute_code||' '||
6001    					p_category_name);
6002     FND_MSG_PUB.Add;
6003   end if;
6004 
6005   p_return_status := FND_API.G_RET_STS_SUCCESS;
6006 
6007   FND_MSG_PUB.Count_And_Get (
6008         p_count => p_msg_count,
6009         p_data => p_msg_data);
6010 
6011 EXCEPTION
6012   WHEN VALUE_ERROR THEN
6013     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
6014       FND_MESSAGE.SET_NAME('AK','AK_CATEGORY_USAGE_VALUE_ERROR');
6015       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||' '||
6016    					p_region_code||' '||to_char(p_attribute_application_id)||
6017    					' '||p_attribute_code||' '||
6018    					p_category_name);
6019       FND_MSG_PUB.Add;
6020     end if;
6021     p_return_status := FND_API.G_RET_STS_ERROR;
6022     rollback to start_create_category_usage;
6023     FND_MSG_PUB.Count_And_Get (
6024         p_count => p_msg_count,
6025         p_data => p_msg_data);
6026   WHEN FND_API.G_EXC_ERROR THEN
6027     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
6028       FND_MESSAGE.SET_NAME('AK','AK_CATEGORY_USAGE_NOT_CREATED');
6029       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||' '||
6030    					p_region_code||' '||to_char(p_attribute_application_id)||
6031    					' '||p_attribute_code||' '||
6032    					p_category_name);
6033       FND_MSG_PUB.Add;
6034     end if;
6035     p_return_status := FND_API.G_RET_STS_ERROR;
6036     rollback to start_create_category_usage;
6037     FND_MSG_PUB.Count_And_Get (
6038         p_count => p_msg_count,
6039         p_data => p_msg_data);
6040   WHEN OTHERS THEN
6041     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6042     rollback to start_create_category_usage;
6043     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
6044                            SUBSTR (SQLERRM, 1, 240) );
6045     FND_MSG_PUB.Add;
6046     FND_MSG_PUB.Count_And_Get (
6047         p_count => p_msg_count,
6048         p_data => p_msg_data);
6049 
6050 end CREATE_CATEGORY_USAGE;
6051 
6052 --=======================================================
6053 --  Procedure   UPDATE_CATEGORY_USAGE
6054 --
6055 --  Usage       Private API for updating category usage.
6056 --              This API should only be called by other APIs
6057 --              that are owned by the Core Modules Team (AK).
6058 --
6059 --  Desc        This API updates a region lov relation using the given info
6060 --
6061 --  Results     The API returns the standard p_return_status parameter
6062 --              indicating one of the standard return statuses :
6063 --                  * Unexpected error
6064 --                  * Error
6065 --                  * Success
6066 --  Parameters  Category usage columns
6067 --              p_loader_timestamp : IN optional
6068 --                  If a timestamp is passed, the API will update the
6069 --                  record using this timestamp. Only the upload API
6070 --                  should call with this parameter loaded.
6071 --
6072 --  Version     Initial version number  =   1.0
6073 --  History     Current version number  =   1.0
6074 --=======================================================
6075 PROCEDURE UPDATE_CATEGORY_USAGE (
6076 p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
6077 p_api_version_number       IN      NUMBER,
6078 p_init_msg_tbl             IN      BOOLEAN := FALSE,
6079 p_msg_count                OUT NOCOPY     NUMBER,
6080 p_msg_data                 OUT NOCOPY     VARCHAR2,
6081 p_return_status            OUT NOCOPY     VARCHAR2,
6082 p_region_application_id    IN      NUMBER := FND_API.G_MISS_NUM,
6083 p_region_code              IN      VARCHAR2 := FND_API.G_MISS_CHAR,
6084 p_attribute_application_id IN      NUMBER := FND_API.G_MISS_NUM,
6085 p_attribute_code           IN      VARCHAR2 := FND_API.G_MISS_CHAR,
6086 p_category_name         IN      VARCHAR2 := FND_API.G_MISS_CHAR,
6087 p_category_id                  IN      NUMBER := FND_API.G_MISS_NUM,
6088 p_application_id                IN      NUMBER := FND_API.G_MISS_NUM,
6089 p_show_all                      IN      VARCHAR2 := FND_API.G_MISS_CHAR,
6090 p_created_by			IN	NUMBER := FND_API.G_MISS_NUM,
6091 p_creation_date		   IN      DATE := FND_API.G_MISS_DATE,
6092 p_last_updated_by          IN     NUMBER := FND_API.G_MISS_NUM,
6093 p_last_update_date         IN      DATE := FND_API.G_MISS_DATE,
6094 p_last_update_login        IN     NUMBER := FND_API.G_MISS_NUM,
6095 p_loader_timestamp         IN      DATE := FND_API.G_MISS_DATE,
6096 p_pass                     IN      NUMBER,
6097 p_copy_redo_flag           IN OUT NOCOPY  BOOLEAN
6098 ) is
6099 cursor l_get_row_csr is
6100 select *
6101 from AK_CATEGORY_USAGES
6102 where REGION_APPLICATION_ID = p_region_application_id
6103 and   REGION_CODE = p_region_code
6104 and   ATTRIBUTE_APPLICATION_ID = p_attribute_application_id
6105 and   ATTRIBUTE_CODE = p_attribute_code
6106 and   CATEGORY_NAME = p_category_name;
6107   l_api_version_number      CONSTANT number := 1.0;
6108   l_api_name                CONSTANT varchar2(30) := 'Update_Category_Usage';
6109   l_created_by              number;
6110   l_creation_date           date;
6111   l_category_usage_rec      AK_CATEGORY_USAGES%ROWTYPE;
6112   l_last_update_date        date;
6113   l_last_update_login       number;
6114   l_last_updated_by         number;
6115   l_return_status           varchar2(1);
6116 begin
6117   IF NOT FND_API.Compatible_API_Call (
6118     l_api_version_number, p_api_version_number, l_api_name,
6119     G_PKG_NAME) then
6120       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6121       return;
6122   END IF;
6123 
6124   -- Initialize the message table if requested.
6125 
6126   if p_init_msg_tbl then
6127     FND_MSG_PUB.initialize;
6128   end if;
6129 
6130   savepoint start_update_category_usage;
6131 
6132   --** retrieve ak_category_usage row if it exists **
6133   open l_get_row_csr;
6134   fetch l_get_row_csr into l_category_usage_rec;
6135   if (l_get_row_csr%notfound) then
6136     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
6137       FND_MESSAGE.SET_NAME('AK','AK_CATEGORY_DOES_NOT_EXIST');
6138       FND_MESSAGE.SET_TOKEN('KEY', (to_char(p_region_application_id) ||' '||
6139 		p_region_code ||' '|| to_char(p_attribute_application_id)||' '||
6140 		p_attribute_code ||' '|| p_category_name ||' '||
6141 		to_char(p_application_id)));
6142       FND_MSG_PUB.Add;
6143       FND_MSG_PUB.Add;
6144     end if;
6145     --dbms_output.put_line(l_api_name || 'Error - Row does not exist');
6146     close l_get_row_csr;
6147     raise FND_API.G_EXC_ERROR;
6148   end if;
6149   close l_get_row_csr;
6150 
6151   --** validate table columns passed in **
6152   if p_validation_level <> FND_API.G_VALID_LEVEL_NONE then
6153     if not AK_REGION2_PVT.VALIDATE_CATEGORY_USAGE (
6154             p_validation_level => p_validation_level,
6155             p_api_version_number => 1.0,
6156             p_return_status => l_return_status,
6157             p_region_application_id => p_region_application_id,
6158             p_region_code => p_region_code,
6159             p_attribute_application_id => p_attribute_application_id,
6160             p_attribute_code => p_attribute_code,
6161   	    p_category_name => p_category_name,
6162   	    p_category_id => p_category_id,
6163   	    p_application_id => p_application_id,
6164   	    p_show_all => p_show_all,
6165             p_caller => AK_ON_OBJECTS_PVT.G_UPDATE,
6166             p_pass => p_pass
6167       ) then
6168       -- Do not raise an error if it's the first pass
6169           if (p_pass = 1) then
6170             p_copy_redo_flag := TRUE;
6171       else
6172         raise FND_API.G_EXC_ERROR;
6173       end if;
6174     end if;
6175   end if;
6176 
6177   if (p_created_by <> FND_API.G_MISS_NUM) then
6178     l_created_by := p_created_by;
6179   end if;
6180   if (p_creation_date <> FND_API.G_MISS_DATE) then
6181     l_creation_date := p_creation_date;
6182   end if;
6183   if (p_last_updated_by <> FND_API.G_MISS_NUM) then
6184     l_last_updated_by := p_last_updated_by;
6185   end if;
6186   if (p_last_update_date <> FND_API.G_MISS_DATE) then
6187     l_last_update_date := p_last_update_date;
6188   end if;
6189   if (p_last_update_login <> FND_API.G_MISS_NUM) then
6190     l_last_update_login := p_last_update_login;
6191   end if;
6192 
6193   --** Load record to be updated to the database **
6194 
6195   if AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
6196        p_loader_timestamp => p_loader_timestamp,
6197        p_created_by => l_created_by,
6198        p_creation_date => l_creation_date,
6199        p_last_updated_by => l_last_updated_by,
6200        p_db_last_updated_by => l_category_usage_rec.last_updated_by,
6201        p_last_update_date => l_last_update_date,
6202        p_db_last_update_date => l_category_usage_rec.last_update_date,
6203        p_last_update_login => l_last_update_login,
6204        p_create_or_update => 'UPDATE') then
6205 
6206   update AK_CATEGORY_USAGES set
6207       SHOW_ALL = p_show_all,
6208       APPLICATION_ID = p_application_id,
6209       LAST_UPDATE_DATE = l_last_update_date,
6210       LAST_UPDATED_BY = l_last_updated_by,
6211       LAST_UPDATE_LOGIN = l_last_update_login
6212   where REGION_APPLICATION_ID = p_region_application_id
6213   and   REGION_CODE = p_region_code
6214   and   ATTRIBUTE_APPLICATION_ID = p_attribute_application_id
6215   and   ATTRIBUTE_CODE = p_attribute_code
6216   and   CATEGORY_NAME = p_category_name;
6217   if (sql%notfound) then
6218     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
6219       FND_MESSAGE.SET_NAME('AK','AK_CATEGORY_UPDATE_FAILED');
6220       FND_MSG_PUB.Add;
6221     end if;
6222     raise FND_API.G_EXC_ERROR;
6223   end if;
6224 
6225 --  /** commit the update **/
6226 --  commit;
6227 
6228   if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
6229     FND_MESSAGE.SET_NAME('AK','AK_CATEGORY_UPDATED');
6230     FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||
6231                                  ' ' || p_region_code);
6232     FND_MSG_PUB.Add;
6233   end if;
6234 
6235   end if;
6236 
6237    p_return_status := FND_API.G_RET_STS_SUCCESS;
6238 
6239   FND_MSG_PUB.Count_And_Get (
6240         p_count => p_msg_count,
6241         p_data => p_msg_data);
6242 
6243 EXCEPTION
6244   WHEN VALUE_ERROR THEN
6245     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
6246       FND_MESSAGE.SET_NAME('AK','AK_CATEGORY_VALUE_ERROR');
6247       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_region_application_id) ||' '||
6248 		p_region_code||' '||to_char(p_attribute_application_id)||' '||
6249 		p_attribute_code||' '|| p_category_name ||' '||
6250                 to_char(p_application_id));
6251       FND_MSG_PUB.Add;
6252     end if;
6253     p_return_status := FND_API.G_RET_STS_ERROR;
6254     rollback to start_update_category_usage;
6255     FND_MSG_PUB.Count_And_Get (
6256         p_count => p_msg_count,
6257         p_data => p_msg_data);
6258   WHEN OTHERS THEN
6259     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6260     rollback to start_update_category_usage;
6261     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
6262                            SUBSTR (SQLERRM, 1, 240) );
6263     FND_MSG_PUB.Add;
6264     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
6265                            'PK = '||to_char(p_region_application_id) ||' '||
6266 			p_region_code||' '||to_char(p_attribute_application_id)||' '||
6267 			p_attribute_code||' '|| p_category_name ||' '||
6268 			to_char(p_application_id) );
6269     FND_MSG_PUB.Add;
6270     FND_MSG_PUB.Count_And_Get (
6271         p_count => p_msg_count,
6272         p_data => p_msg_data);
6273      FND_MSG_PUB.Count_And_Get (
6274         p_count => p_msg_count,
6275         p_data => p_msg_data);
6276 
6277 end UPDATE_CATEGORY_USAGE;
6278 
6279 end AK_REGION2_PVT;