DBA Data[Home] [Help]

PACKAGE BODY: APPS.AK_ON_OBJECTS_PVT

Source


1 package body AK_ON_OBJECTS_PVT as
2 /* $Header: akdvonb.pls 120.6 2006/08/10 21:23:15 tshort ship $ */
3 
4 --
5 -- Type definitions (only used within this package body)
6 --
7 -- Table containing the index numbers within the PL/SQL table in which
8 -- the first line of a certain business object type begins.
9 --
10 TYPE Index_Tbl_Type IS TABLE OF NUMBER
11 	INDEX BY BINARY_INTEGER;
12 
13 --
14 -- global variables within this package body
15 --
16 G_buffer_tbl       AK_ON_OBJECTS_PUB.Buffer_Tbl_Type;
17 
18 --==============================================
19 --  Procedure   REPLACE_ESCAPED_CHARS (local procedure)
20 --
21 --  Usage       Local procedure for replacing all escaped characters.
22 --              Not designed to be called from outside this package.
23 --
24 --  Desc        Replaces all escaped characters in the input string
25 --              such as \\ with their original characters.
26 --
27 --  Results     The procedure returns a string which is the result of
28 --              replacing all escaped characters with their original
29 --              characters.
30 --  Parameters  p_buffer : IN required
31 --                  The input string with escaped characters.
32 --==============================================
33 function REPLACE_ESCAPED_CHARS (
34   p_buffer IN varchar2
35 ) return varchar2 is
36   l_buffer    AK_ON_OBJECTS_PUB.Buffer_Type;
37 begin
38   l_buffer := REPLACE(p_buffer, '\"', '"');
39   l_buffer := REPLACE(l_buffer, '\t', '	');   /* tab */
40   l_buffer := REPLACE(l_buffer, '\n', '
41 ');  /* newline - this is on the next line because the new line character
42                   is included in the quotes*/
43   l_buffer := REPLACE(l_buffer, '\\', '\');
44   return l_buffer;
45 end REPLACE_ESCAPED_CHARS;
46 
47 --==============================================
48 --  Function   REPLACE_SPECIAL_CHARS
49 --
50 --  Usage       Private function for replacing all special characters
51 --              with escaped characters.
52 --              This function is intended to be called only by other APIs
53 --              that are owned by the Core Modules Team (AK)
54 --
55 --  Desc        Replaces all special characters in the input string
56 --              with the corresponding escaped characters, for instance,
57 --              the 'tab' character will be replaced by '\t'.
58 --
59 --  Results     The procedure returns a string which is the result of
60 --              replacing all special characters with their corresponding
61 --              escaped characters.
62 --  Parameters  p_buffer : IN required
63 --                  The input string with special characters.
64 --==============================================
65 function REPLACE_SPECIAL_CHAR (
66   p_buffer                  IN      VARCHAR2
67 ) return VARCHAR2 is
68   l_api_version_number      CONSTANT number := 1.0;
69   l_api_name                CONSTANT varchar2(30) := 'Replace_Special_Char';
70   l_buffer                  AK_ON_OBJECTS_PUB.Buffer_Type;
71 begin
72 
73   if (p_buffer is null) then
74     return null;
75   end if;
76 
77   --
78   -- Add preceding backslash to special characters
79   --
80   l_buffer := REPLACE(p_buffer, '\', '\\');      /* backslash */
81   l_buffer := REPLACE(l_buffer, '	', '\t');   /* tabs */
82   l_buffer := REPLACE(l_buffer, '
83 ', '\n');  /* newline  - this is on the next line because the new line character
84                   is included in the quotes */
85   return REPLACE(l_buffer, '"', '\"');           /* quote */
86 
87 END REPLACE_SPECIAL_CHAR;
88 
89 --==============================================
90 --  Procedure   APPEND_BUFFER_TABLES
91 --
92 --  Usage       Private procedure for appending one buffer table to the
93 --              end of another buffer table.
94 --              This procedure is intended to be called only by other APIs
95 --              that are owned by the Core Modules Team (AK)
96 --
97 --  Desc        Appends all elements in the from_table to the end of the
98 --              to_table. Both tables must be of type Buffer_Tbl_Type.
99 --
100 --  Results     The procedure returns the standard p_return_status parameter
101 --              indicating one of the standard return statuses :
102 --                  * Unexpected error
103 --                  * Error
104 --                  * Success
105 --  Parameters  p_from_table : IN required
106 --                  The from buffer table containing elements to be
107 --                  appended to the end of the to buffer table.
108 --              p_to_table : IN OUT
109 --                  The target buffer table which will have the elements
110 --                  in the from table appended to it.
111 --==============================================
112 procedure APPEND_BUFFER_TABLES (
113   p_return_status            OUT NOCOPY     VARCHAR2,
114   p_from_table               IN      AK_ON_OBJECTS_PUB.Buffer_Tbl_Type,
115   p_to_table                 IN OUT NOCOPY  AK_ON_OBJECTS_PUB.Buffer_Tbl_Type
116 ) is
117   l_api_name                CONSTANT varchar2(30) := 'Append_Buffer_Tables';
118   l_from_index   NUMBER;
119   l_to_index     NUMBER;
120 begin
121   --
122   -- Return if from table is empty
123   --
124   if (p_from_table.count = 0) then
125     p_return_status := FND_API.G_RET_STS_SUCCESS;
126     return;
127   end if;
128 
129   l_to_index := nvl(p_to_table.LAST, 0) + 1;
130 
131   for l_from_index in p_from_table.FIRST .. p_from_table.LAST LOOP
132     if (p_from_table.EXISTS(l_from_index)) then
133       p_to_table(l_to_index) := p_from_table(l_from_index);
134       l_to_index := l_to_index + 1;
135     end if;
136   end loop;
137 
138   p_return_status := FND_API.G_RET_STS_SUCCESS;
139 
140 EXCEPTION
141   WHEN FND_API.G_EXC_ERROR THEN
142     p_return_status := FND_API.G_RET_STS_ERROR;
143   WHEN OTHERS THEN
144     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
145     FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name,
146                            SUBSTR (SQLERRM, 1, 240) );
147 end APPEND_BUFFER_TABLES;
148 
149 --==============================================
150 --  Procedure   DOWNLOAD_HEADER
151 --
152 --  Usage       Private procedure for writing standard header information
153 --              to a loader file.
154 --              This procedure is intended to be called only by other APIs
155 --              that are owned by the Core Modules Team (AK)
156 --
157 --  Desc        This procedure writes all the standard header information
158 --              including the DEFINE section to the loader file.
159 --
160 --  Results     The API returns the standard p_return_status parameter
161 --              indicating one of the standard return statuses :
162 --                  * Unexpected error
163 --                  * Error
164 --                  * Success
165 --  Parameters  p_nls_language : IN optional
166 --                  The NLS language of the database. If this is omitted,
167 --                  the default NLS language defined in the database
168 --                  will be used.
169 --              p_application_id : IN optional
170 --                  The application ID to be used to extract data from
171 --                  the database. If p_application_id is omitted, then
172 --                  either p_application_short_name must be given, or
173 --                  p_table_size must be greater than 0.
174 --              p_application_short_name : IN optional
175 --                  The application short name to be used to extract data
176 --                  from the database. If p_application_short_name is
177 --                  not provided, then either p_application_id must be
178 --                  given, or p_table_size must be greater than 0.
179 --                  p_application_short_name will be ignored if
180 --                  p_application_id is given.
181 --              p_table_size : IN required
182 --                  The size of the PL/SQL table containing the list of
183 --                  flows, objects, regions, or attributes to be extracted
184 --                  from the database. If p_table_size is 0, then either
185 --                  p_application_id or p_application_short_name must
186 --                  be provided.
187 --              p_download_by_object : IN required
188 --                  Must be one of the following literal defined in
189 --                  AK_ON_OBJECTS_PVT package:
190 --                    G_ATTRIBUTE - Caller is DOWNLOAD_ATTRIBUTE API
191 --                    G_OBJECT    - Caller is DOWNLOAD_OBJECT API
192 --                    G_REGION    - Caller is DOWNLOAD_REGION API
193 --                    G_FLOW      - Caller is DOWNLOAD_FLOW API
194 --                  This parameter is used to determine which portions
195 --                  of the DEFINE section should be written to the file.
196 --              p_nls_language_out : OUT
197 --                  This parameter will be loaded with p_nls_language if
198 --                  one is given, or with the default NLS language in the
199 --                  database if p_nls_language is not provided.
200 --              p_application_id_out : OUT
201 --                  This parameter will be loaded with p_application_id if
202 --                  one is given, or with the application ID of the
203 --                  p_application_short_name parameter if no application ID
204 --                  is provided. If both p_application_short_name and
205 --                  p_application_id are not given, the p_application_id_out
206 --                  will be null.
207 --==============================================
208 procedure DOWNLOAD_HEADER (
209   p_validation_level        IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
210   p_api_version_number      IN      NUMBER,
211   p_return_status           OUT NOCOPY     VARCHAR2,
212   p_nls_language            IN      VARCHAR2 := FND_API.G_MISS_CHAR,
213   p_application_id          IN      NUMBER := FND_API.G_MISS_NUM,
214   p_application_short_name  IN      VARCHAR2 := FND_API.G_MISS_CHAR,
215   p_table_size              IN      NUMBER,
216   p_download_by_object      IN      VARCHAR2,
217   p_nls_language_out        OUT NOCOPY     VARCHAR2,
218   p_application_id_out      OUT NOCOPY     NUMBER
219 ) is
220   cursor l_get_appl_id_csr (short_name_param varchar2) is
221   select application_id
222   from   fnd_application_vl
223   where  application_short_name = short_name_param;
224   l_api_version_number CONSTANT number := 1.0;
225   l_api_name           CONSTANT varchar2(30) := 'Download_Header';
226   l_application_id number;
227   l_header_tbl     AK_ON_OBJECTS_PUB.Buffer_Tbl_Type;
228   l_index          NUMBER;
229   l_nls_language   VARCHAR2(30);
230   l_return_status  varchar2(1);
231   l_sub_phase      varchar2(2);
232   l_dbname	   varchar2(8);
233 begin
234   --
235   -- Check verion number
236   --
237   IF NOT FND_API.Compatible_API_Call (
238     l_api_version_number, p_api_version_number, l_api_name,
239     G_PKG_NAME) then
240       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
241       return;
242   END IF;
243 
244   --
245   -- Either p_aplication_short_name, p_application_id, or a table with
246   -- a list of attributes/regions/objects/flows to be extracted from
247   -- the database must be provided
248   --
249 
250   if ((p_application_short_name = FND_API.G_MISS_CHAR) or
251       (p_application_short_name is null)) and
252      ((p_application_id = FND_API.G_MISS_NUM) or
253       (p_application_id is null)) and
254      (p_table_size = 0)  then
255       if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
256         FND_MESSAGE.SET_NAME('AK','AK_NO_SELECTION');
257         FND_MSG_PUB.Add;
258       end if;
259       raise FND_API.G_EXC_ERROR;
260   end if;
261 
262   --
263   -- - Load l_application_id
264   -- if an application short name is passed and no application ID is
265   -- given, find the application ID from the application short name
266   --
267   l_application_id := p_application_id;
268 
269   if (p_application_short_name <> FND_API.G_MISS_CHAR) then
270 
271     -- /** Since we pass appl short name only from Java wrapper, this
272 	-- meesage is not necessary **/
273     --if (p_application_id <> FND_API.G_MISS_NUM) then
274       --if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
275       --  FND_MESSAGE.SET_NAME('AK','AK_APPL_SHORT_NAME_IGNORED');
276       --  FND_MSG_PUB.Add;
277       --end if;
278     --else
279 	-- /***********************************************/
280 	if (p_application_id = FND_API.G_MISS_NUM) then
281       open l_get_appl_id_csr(p_application_short_name);
282       fetch l_get_appl_id_csr into l_application_id;
283       if (l_get_appl_id_csr%notfound) then
284         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
285           FND_MESSAGE.SET_NAME('AK','AK_APPL_SHORT_NAME_INVALID');
286           FND_MESSAGE.SET_TOKEN('APPL_SHORT_NAME', p_application_short_name);
287           FND_MSG_PUB.Add;
288         end if;
289         close l_get_appl_id_csr;
290         raise FND_API.G_EXC_ERROR;
291       end if;
292       close l_get_appl_id_csr;
293     end if;
294   end if;
295 
296   --
297   -- If no LANGUAGE CODE is given, use the default language code
298   --
299   if ((p_nls_language = FND_API.G_MISS_CHAR) or
300       (p_nls_language is null)) then
301 
302       select userenv('LANG') into l_nls_language
303       from dual;
304 
305   else
306       l_nls_language := p_nls_language;
307   end if;
308 
309   select value into l_dbname from v$parameter
310   where name = 'db_name';
311 
312   -- determine sub-phase
313   --
314   if ( p_download_by_object = AK_ON_OBJECTS_PVT.G_REGION ) then
315     l_sub_phase := '24';
316   elsif ( p_download_by_object = AK_ON_OBJECTS_PVT.G_FLOW or p_download_by_object = AK_ON_OBJECTS_PVT.G_SECURITY) then
317     l_sub_phase := '20';
318   elsif ( p_download_by_object = AK_ON_OBJECTS_PVT.G_ATTRIBUTE ) then
319     l_sub_phase := '16';
320   elsif ( p_download_by_object = AK_ON_OBJECTS_PVT.G_CUSTOM_REGION ) then
321     l_sub_phase := '25';
322   end if;
323 
324   --
325   -- - Load file header information such as nls_language and
326   --   codeset
327   --
328   l_index := 1;
329   l_header_tbl(l_index) := '# Object Navigator Definition File';
330 
331   l_index := l_index + 1;
332   l_header_tbl(l_index) := '#';
333 
334   l_index := l_index + 1;
335   l_header_tbl(l_index) := '# $Hea' || 'der: $';
336   l_index := l_index + 1;
337   l_header_tbl(l_index) := '# dbdrv: exec java oracle/apps/ak akload.class java '||'&'||'phase=dat+'||l_sub_phase||' \ ';
338   l_index := l_index + 1;
339   l_header_tbl(l_index) := '# dbdrv: checkfile:~PROD:~PATH:~FILE '||'&'||'un_apps \';
340   l_index := l_index + 1;
341   l_header_tbl(l_index) := '# dbdrv: '||'&'||'pw_apps '||'&'||'jdbc_protocol '||'&'||'jdbc_db_addr UPLOAD \';
342   l_index := l_index + 1;
343   l_header_tbl(l_index) := '# dbdrv: '||'&'||'fullpath_~PROD_~PATH_~FILE NCUPDATE '||'&'||'env=NLS_LANG';
344 
345   l_index := l_index + 1;
346   l_header_tbl(l_index) := '# Generated on ' ||
347                            to_char(sysdate, 'YY/MM/DD HH24:MI:SS');
348 
349   l_index := l_index + 1;
350   l_header_tbl(l_index) := '# Source Database ' || l_dbname;
351 
352   l_index := l_index + 1;
353   l_header_tbl(l_index) := '#';
354 
355   l_index := l_index + 1;
356   l_header_tbl(l_index) := 'LANGUAGE = "' || l_nls_language || '"';
357 
358 -- commented out because it's now supporting multiple appl_id
359 --
360 --  l_index := l_index + 1;
361 --  l_header_tbl(l_index) := 'EXTRACT_BY_APPLICATION = ';
362 --  if (p_table_size = 0) then
363 --    l_header_tbl(l_index) := l_header_tbl(l_index) ||
364 --                             to_char(l_application_id);
365 --  else
366 --    l_header_tbl(l_index) := l_header_tbl(l_index) || '""';
367 --  end if;
368 
369   l_index := l_index + 1;
370   l_header_tbl(l_index) := 'EXTRACT_BY_OBJECT = "' ||
371                             p_download_by_object || '"';
372 
373   l_index := l_index + 1;
374   l_header_tbl(l_index) := 'FILE_FORMAT_VERSION = '||to_char(AK_ON_OBJECTS_PUB.G_FILE_FORMAT_VER);
375 
376   --
377   -- DEFINE section
378   --
379   -- Check if the Object type is valid values
380   l_index := l_index + 1;
381   l_header_tbl(l_index) := ' ';
382 
383   if (p_download_by_object in (AK_ON_OBJECTS_PVT.G_OBJECT,
384            AK_ON_OBJECTS_PVT.G_REGION, AK_ON_OBJECTS_PVT.G_CUSTOM_REGION,
385            AK_ON_OBJECTS_PVT.G_FLOW, AK_ON_OBJECTS_PVT.G_ATTRIBUTE)) then
386 
387   l_index := l_index + 1;
388   l_header_tbl(l_index) := 'DEFINE ATTRIBUTE ';
389   l_index := l_index + 1;
390   l_header_tbl(l_index) := '  KEY ATTRIBUTE_APPLICATION_ID NUMBER(15)';
391   l_index := l_index + 1;
392   l_header_tbl(l_index) := '  KEY ATTRIBUTE_CODE VARCHAR2(30)';
393   l_index := l_index + 1;
394   l_header_tbl(l_index) := '  CTX ATTRIBUTE_LABEL_LENGTH NUMBER(15)';
395   l_index := l_index + 1;
396   l_header_tbl(l_index) := '  BASE ATTRIBUTE_VALUE_LENGTH NUMBER(15)';
397   l_index := l_index + 1;
398   l_header_tbl(l_index) := '  BASE BOLD VARCHAR2(1)';
399   l_index := l_index + 1;
400   l_header_tbl(l_index) := '  BASE ITALIC VARCHAR2(1)';
401   l_index := l_index + 1;
402   l_header_tbl(l_index) := '  BASE VERTICAL_ALIGNMENT VARCHAR2(30)';
403   l_index := l_index + 1;
404   l_header_tbl(l_index) := '  BASE HORIZONTAL_ALIGNMENT VARCHAR2(30)';
405   l_index := l_index + 1;
406   l_header_tbl(l_index) := '  BASE DATA_TYPE VARCHAR2(30)';
407   l_index := l_index + 1;
408   l_header_tbl(l_index) := '  BASE UPPER_CASE_FLAG VARCHAR2(1)';
409   l_index := l_index + 1;
410   l_header_tbl(l_index) := '  BASE DEFAULT_VALUE_VARCHAR2 VARCHAR2(240)';
411   l_index := l_index + 1;
412   l_header_tbl(l_index) := '  BASE DEFAULT_VALUE_NUMBER NUMBER(15)';
413   l_index := l_index + 1;
414   l_header_tbl(l_index) := '  BASE DEFAULT_VALUE_DATE DATE';
415   l_index := l_index + 1;
416   l_header_tbl(l_index) := '  BASE LOV_REGION REFERENCES REGION';
417   l_index := l_index + 1;
418   l_header_tbl(l_index) := '  BASE ITEM_STYLE VARCHAR2(30)';
419   l_index := l_index + 1;
420   l_header_tbl(l_index) := '  BASE DISPLAY_HEIGHT NUMBER(15)';
421   l_index := l_index + 1;
422   l_header_tbl(l_index) := '  BASE CSS_CLASS_NAME VARCHAR2(80)';
423   l_index := l_index + 1;
424   l_header_tbl(l_index) := '  BASE POPLIST_VIEWOBJECT VARCHAR2(240)';
425   l_index := l_index + 1;
426   l_header_tbl(l_index) := '  BASE POPLIST_DISPLAY_ATTRIBUTE VARCHAR2(80)';
427   l_index := l_index + 1;
428   l_header_tbl(l_index) := '  BASE POPLIST_VALUE_ATTRIBUTE VARCHAR2(80)';
429   l_index := l_index + 1;
430   l_header_tbl(l_index) := '  BASE CSS_LABEL_CLASS_NAME VARCHAR2(80)';
431   l_index := l_index + 1;
432   l_header_tbl(l_index) := '  BASE PRECISION NUMBER(15)';
433   l_index := l_index + 1;
434   l_header_tbl(l_index) := '  CTX EXPANSION NUMBER(15)';
435   l_index := l_index + 1;
436   l_header_tbl(l_index) := '  CTX ALS_MAX_LENGTH NUMBER(15)';
437   l_index := l_index + 1;
438   l_header_tbl(l_index) := '  BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
439   l_index := l_index + 1;
440   l_header_tbl(l_index) := '  BASE ATTRIBUTE1 VARCHAR2(150)';
441   l_index := l_index + 1;
442   l_header_tbl(l_index) := '  BASE ATTRIBUTE2 VARCHAR2(150)';
443   l_index := l_index + 1;
444   l_header_tbl(l_index) := '  BASE ATTRIBUTE3 VARCHAR2(150)';
445   l_index := l_index + 1;
446   l_header_tbl(l_index) := '  BASE ATTRIBUTE4 VARCHAR2(150)';
447   l_index := l_index + 1;
448   l_header_tbl(l_index) := '  BASE ATTRIBUTE5 VARCHAR2(150)';
449   l_index := l_index + 1;
450   l_header_tbl(l_index) := '  BASE ATTRIBUTE6 VARCHAR2(150)';
451   l_index := l_index + 1;
452   l_header_tbl(l_index) := '  BASE ATTRIBUTE7 VARCHAR2(150)';
453   l_index := l_index + 1;
454   l_header_tbl(l_index) := '  BASE ATTRIBUTE8 VARCHAR2(150)';
455   l_index := l_index + 1;
456   l_header_tbl(l_index) := '  BASE ATTRIBUTE9 VARCHAR2(150)';
457   l_index := l_index + 1;
458   l_header_tbl(l_index) := '  BASE ATTRIBUTE10 VARCHAR2(150)';
459   l_index := l_index + 1;
460   l_header_tbl(l_index) := '  BASE ATTRIBUTE11 VARCHAR2(150)';
461   l_index := l_index + 1;
462   l_header_tbl(l_index) := '  BASE ATTRIBUTE12 VARCHAR2(150)';
463   l_index := l_index + 1;
464   l_header_tbl(l_index) := '  BASE ATTRIBUTE13 VARCHAR2(150)';
465   l_index := l_index + 1;
466   l_header_tbl(l_index) := '  BASE ATTRIBUTE14 VARCHAR2(150)';
467   l_index := l_index + 1;
468   l_header_tbl(l_index) := '  BASE ATTRIBUTE15 VARCHAR2(150)';
469   l_index := l_index + 1;
470   l_header_tbl(l_index) := '  BASE CREATED_BY NUMBER(15)';
471   l_index := l_index + 1;
472   l_header_tbl(l_index) := '  BASE CREATION_DATE DATE';
473   l_index := l_index + 1;
474   l_header_tbl(l_index) := '  BASE LAST_UPDATED_BY NUMBER(15)';
475   l_index := l_index + 1;
476   l_header_tbl(l_index) := '  CTX OWNER VARCHAR2(4000)';
477   l_index := l_index + 1;
478   l_header_tbl(l_index) := '  BASE LAST_UPDATE_DATE DATE';
479   l_index := l_index + 1;
480   l_header_tbl(l_index) := '  BASE LAST_UPDATE_LOGIN NUMBER(15)';
481   l_index := l_index + 1;
482   l_header_tbl(l_index) := '  BASE NAME VARCHAR2(80)';
483   l_index := l_index + 1;
484   l_header_tbl(l_index) := '  TRANS ATTRIBUTE_LABEL_LONG VARCHAR2(80)';
485   l_index := l_index + 1;
486   l_header_tbl(l_index) := '  TRANS ATTRIBUTE_LABEL_SHORT VARCHAR2(40)';
487   l_index := l_index + 1;
488   l_header_tbl(l_index) := '  TRANS DESCRIPTION VARCHAR2(2000)';
489   l_index := l_index + 1;
490   l_header_tbl(l_index) := 'END ATTRIBUTE';
491   l_index := l_index + 1;
492   l_header_tbl(l_index) := ' ';
493 
494   -- Check if the Object type is valid values
495   if (p_download_by_object in (AK_ON_OBJECTS_PVT.G_OBJECT,
496            AK_ON_OBJECTS_PVT.G_REGION, AK_ON_OBJECTS_PVT.G_CUSTOM_REGION,
497 	   AK_ON_OBJECTS_PVT.G_FLOW)) then
498   l_index := l_index + 1;
499   l_header_tbl(l_index) := 'DEFINE OBJECT';
500   l_index := l_index + 1;
501   l_header_tbl(l_index) := '  KEY DATABASE_OBJECT_NAME VARCHAR2(30)';
502   l_index := l_index + 1;
503   l_header_tbl(l_index) := '  BASE APPLICATION_ID NUMBER(15)';
504   l_index := l_index + 1;
505   l_header_tbl(l_index) := '  BASE PRIMARY_KEY_NAME REFERENCES UNIQUE_KEY';
506   l_index := l_index + 1;
507   l_header_tbl(l_index) := '  BASE DEFAULTING_API_PKG VARCHAR2(30)';
508   l_index := l_index + 1;
509   l_header_tbl(l_index) := '  BASE DEFAULTING_API_PROC VARCHAR2(30)';
510   l_index := l_index + 1;
511   l_header_tbl(l_index) := '  BASE VALIDATION_API_PKG VARCHAR2(30)';
512   l_index := l_index + 1;
513   l_header_tbl(l_index) := '  BASE VALIDATION_API_PROC VARCHAR2(30)';
514   l_index := l_index + 1;
515   l_header_tbl(l_index) := '  BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
516   l_index := l_index + 1;
517   l_header_tbl(l_index) := '  BASE ATTRIBUTE1 VARCHAR2(150)';
518   l_index := l_index + 1;
519   l_header_tbl(l_index) := '  BASE ATTRIBUTE2 VARCHAR2(150)';
520   l_index := l_index + 1;
521   l_header_tbl(l_index) := '  BASE ATTRIBUTE3 VARCHAR2(150)';
522   l_index := l_index + 1;
523   l_header_tbl(l_index) := '  BASE ATTRIBUTE4 VARCHAR2(150)';
524   l_index := l_index + 1;
525   l_header_tbl(l_index) := '  BASE ATTRIBUTE5 VARCHAR2(150)';
526   l_index := l_index + 1;
527   l_header_tbl(l_index) := '  BASE ATTRIBUTE6 VARCHAR2(150)';
528   l_index := l_index + 1;
529   l_header_tbl(l_index) := '  BASE ATTRIBUTE7 VARCHAR2(150)';
530   l_index := l_index + 1;
531   l_header_tbl(l_index) := '  BASE ATTRIBUTE8 VARCHAR2(150)';
532   l_index := l_index + 1;
533   l_header_tbl(l_index) := '  BASE ATTRIBUTE9 VARCHAR2(150)';
534   l_index := l_index + 1;
535   l_header_tbl(l_index) := '  BASE ATTRIBUTE10 VARCHAR2(150)';
536   l_index := l_index + 1;
537   l_header_tbl(l_index) := '  BASE ATTRIBUTE11 VARCHAR2(150)';
538   l_index := l_index + 1;
539   l_header_tbl(l_index) := '  BASE ATTRIBUTE12 VARCHAR2(150)';
540   l_index := l_index + 1;
541   l_header_tbl(l_index) := '  BASE ATTRIBUTE13 VARCHAR2(150)';
542   l_index := l_index + 1;
543   l_header_tbl(l_index) := '  BASE ATTRIBUTE14 VARCHAR2(150)';
544   l_index := l_index + 1;
545   l_header_tbl(l_index) := '  BASE ATTRIBUTE15 VARCHAR2(150)';
546   l_index := l_index + 1;
547   l_header_tbl(l_index) := '  BASE CREATED_BY NUMBER(15)';
548   l_index := l_index + 1;
549   l_header_tbl(l_index) := '  BASE CREATION_DATE DATE';
550   l_index := l_index + 1;
551   l_header_tbl(l_index) := '  BASE LAST_UPDATED_BY NUMBER(15)';
552   l_index := l_index + 1;
553   l_header_tbl(l_index) := '  CTX OWNER VARCHAR2(4000)';
554   l_index := l_index + 1;
555   l_header_tbl(l_index) := '  BASE LAST_UPDATE_DATE DATE';
556   l_index := l_index + 1;
557   l_header_tbl(l_index) := '  BASE LAST_UPDATE_LOGIN NUMBER(15)';
558   l_index := l_index + 1;
559   l_header_tbl(l_index) := '  TRANS NAME VARCHAR2(30)';
560   l_index := l_index + 1;
561   l_header_tbl(l_index) := '  TRANS DESCRIPTION VARCHAR2(2000)';
562   l_index := l_index + 1;
563   l_header_tbl(l_index) := ' ';
564   l_index := l_index + 1;
565   l_header_tbl(l_index) := '  DEFINE OBJECT_ATTRIBUTE';
566   l_index := l_index + 1;
567   l_header_tbl(l_index) := '    KEY OBJECT_ATTRIBUTE_PK REFERENCES ATTRIBUTE';
568   l_index := l_index + 1;
569   l_header_tbl(l_index) := '    BASE COLUMN_NAME VARCHAR2(30)';
570   l_index := l_index + 1;
571   l_header_tbl(l_index) := '    BASE ATTRIBUTE_LABEL_LENGTH NUMBER(15)';
572   l_index := l_index + 1;
573   l_header_tbl(l_index) := '    BASE DISPLAY_VALUE_LENGTH NUMBER(15)';
574   l_index := l_index + 1;
575   l_header_tbl(l_index) := '    BASE BOLD VARCHAR2(1)';
576   l_index := l_index + 1;
577   l_header_tbl(l_index) := '    BASE ITALIC VARCHAR2(1)';
578   l_index := l_index + 1;
579   l_header_tbl(l_index) := '    BASE VERTICAL_ALIGNMENT VARCHAR2(30)';
580   l_index := l_index + 1;
581   l_header_tbl(l_index) := '    BASE HORIZONTAL_ALIGNMENT VARCHAR2(30)';
582   l_index := l_index + 1;
583   l_header_tbl(l_index) := '    BASE DATA_SOURCE_TYPE VARCHAR2(30)';
584   l_index := l_index + 1;
585   l_header_tbl(l_index) := '    BASE DATA_STORAGE_TYPE VARCHAR2(30)';
586   l_index := l_index + 1;
587   l_header_tbl(l_index) := '    BASE TABLE_NAME VARCHAR2(30)';
588   l_index := l_index + 1;
589   l_header_tbl(l_index) := '    BASE BASE_TABLE_COLUMN_NAME VARCHAR2(30)';
590   l_index := l_index + 1;
591   l_header_tbl(l_index) := '    BASE REQUIRED_FLAG VARCHAR2(1)';
592   l_index := l_index + 1;
593   l_header_tbl(l_index) := '    BASE DEFAULT_VALUE_VARCHAR2 VARCHAR2(240)';
594   l_index := l_index + 1;
595   l_header_tbl(l_index) := '    BASE DEFAULT_VALUE_NUMBER NUMBER(15)';
596   l_index := l_index + 1;
597   l_header_tbl(l_index) := '    BASE DEFAULT_VALUE_DATE DATE';
598   l_index := l_index + 1;
599   l_header_tbl(l_index) := '    BASE LOV_REGION REFERENCES REGION';
600   l_index := l_index + 1;
601   l_header_tbl(l_index) := '    BASE LOV_FOREIGN_KEY_NAME REFERENCES FOREIGN_KEY';
602   l_index := l_index + 1;
603   l_header_tbl(l_index) := '    BASE LOV_ATTRIBUTE REFERENCES ATTRIBUTE';
604   l_index := l_index + 1;
605   l_header_tbl(l_index) := '    BASE DEFAULTING_API_PKG VARCHAR2(30)';
606   l_index := l_index + 1;
607   l_header_tbl(l_index) := '    BASE DEFAULTING_API_PROC VARCHAR2(30)';
608   l_index := l_index + 1;
609   l_header_tbl(l_index) := '    BASE VALIDATION_API_PKG VARCHAR2(30)';
610   l_index := l_index + 1;
611   l_header_tbl(l_index) := '    BASE VALIDATION_API_PROC VARCHAR2(30)';
612   l_index := l_index + 1;
613   l_header_tbl(l_index) := '    BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
614   l_index := l_index + 1;
615   l_header_tbl(l_index) := '    BASE ATTRIBUTE1 VARCHAR2(150)';
616   l_index := l_index + 1;
617   l_header_tbl(l_index) := '    BASE ATTRIBUTE2 VARCHAR2(150)';
618   l_index := l_index + 1;
619   l_header_tbl(l_index) := '    BASE ATTRIBUTE3 VARCHAR2(150)';
620   l_index := l_index + 1;
621   l_header_tbl(l_index) := '    BASE ATTRIBUTE4 VARCHAR2(150)';
622   l_index := l_index + 1;
623   l_header_tbl(l_index) := '    BASE ATTRIBUTE5 VARCHAR2(150)';
624   l_index := l_index + 1;
625   l_header_tbl(l_index) := '    BASE ATTRIBUTE6 VARCHAR2(150)';
626   l_index := l_index + 1;
627   l_header_tbl(l_index) := '    BASE ATTRIBUTE7 VARCHAR2(150)';
628   l_index := l_index + 1;
629   l_header_tbl(l_index) := '    BASE ATTRIBUTE8 VARCHAR2(150)';
630   l_index := l_index + 1;
631   l_header_tbl(l_index) := '    BASE ATTRIBUTE9 VARCHAR2(150)';
632   l_index := l_index + 1;
633   l_header_tbl(l_index) := '    BASE ATTRIBUTE10 VARCHAR2(150)';
634   l_index := l_index + 1;
635   l_header_tbl(l_index) := '    BASE ATTRIBUTE11 VARCHAR2(150)';
636   l_index := l_index + 1;
637   l_header_tbl(l_index) := '    BASE ATTRIBUTE12 VARCHAR2(150)';
638   l_index := l_index + 1;
639   l_header_tbl(l_index) := '    BASE ATTRIBUTE13 VARCHAR2(150)';
640   l_index := l_index + 1;
641   l_header_tbl(l_index) := '    BASE ATTRIBUTE14 VARCHAR2(150)';
642   l_index := l_index + 1;
643   l_header_tbl(l_index) := '    BASE ATTRIBUTE15 VARCHAR2(150)';
644   l_index := l_index + 1;
645   l_header_tbl(l_index) := '    BASE CREATED_BY NUMBER(15)';
646   l_index := l_index + 1;
647   l_header_tbl(l_index) := '    BASE CREATION_DATE DATE';
648   l_index := l_index + 1;
649   l_header_tbl(l_index) := '    BASE LAST_UPDATED_BY NUMBER(15)';
650   l_index := l_index + 1;
651   l_header_tbl(l_index) := '    CTX OWNER VARCHAR2(4000)';
652   l_index := l_index + 1;
653   l_header_tbl(l_index) := '    BASE LAST_UPDATE_DATE DATE';
654   l_index := l_index + 1;
655   l_header_tbl(l_index) := '    BASE LAST_UPDATE_LOGIN NUMBER(15)';
656   l_index := l_index + 1;
657   l_header_tbl(l_index) := '    TRANS ATTRIBUTE_LABEL_LONG VARCHAR2(80)';
658   l_index := l_index + 1;
659   l_header_tbl(l_index) := '    TRANS ATTRIBUTE_LABEL_SHORT VARCHAR2(30)';
660   l_index := l_index + 1;
661   l_header_tbl(l_index) := ' ';
662   l_index := l_index + 1;
663   l_header_tbl(l_index) := '    DEFINE ATTRIBUTE_NAVIGATION';
664   l_index := l_index + 1;
665   l_header_tbl(l_index) := '      KEY VALUE_VARCHAR2 VARCHAR2(240)';
666   l_index := l_index + 1;
667   l_header_tbl(l_index) := '      KEY VALUE_DATE DATE';
668   l_index := l_index + 1;
669   l_header_tbl(l_index) := '      KEY VALUE_NUMBER NUMBER(15)';
670   l_index := l_index + 1;
671   l_header_tbl(l_index) := '      BASE TO_REGION REFERENCES REGION';
672   l_index := l_index + 1;
673   l_header_tbl(l_index) := '      BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
674   l_index := l_index + 1;
675   l_header_tbl(l_index) := '      BASE ATTRIBUTE1 VARCHAR2(150)';
676   l_index := l_index + 1;
677   l_header_tbl(l_index) := '      BASE ATTRIBUTE2 VARCHAR2(150)';
678   l_index := l_index + 1;
679   l_header_tbl(l_index) := '      BASE ATTRIBUTE3 VARCHAR2(150)';
680   l_index := l_index + 1;
681   l_header_tbl(l_index) := '      BASE ATTRIBUTE4 VARCHAR2(150)';
682   l_index := l_index + 1;
683   l_header_tbl(l_index) := '      BASE ATTRIBUTE5 VARCHAR2(150)';
684   l_index := l_index + 1;
685   l_header_tbl(l_index) := '      BASE ATTRIBUTE6 VARCHAR2(150)';
686   l_index := l_index + 1;
687   l_header_tbl(l_index) := '      BASE ATTRIBUTE7 VARCHAR2(150)';
688   l_index := l_index + 1;
689   l_header_tbl(l_index) := '      BASE ATTRIBUTE8 VARCHAR2(150)';
690   l_index := l_index + 1;
691   l_header_tbl(l_index) := '      BASE ATTRIBUTE9 VARCHAR2(150)';
692   l_index := l_index + 1;
693   l_header_tbl(l_index) := '      BASE ATTRIBUTE10 VARCHAR2(150)';
694   l_index := l_index + 1;
695   l_header_tbl(l_index) := '      BASE ATTRIBUTE11 VARCHAR2(150)';
696   l_index := l_index + 1;
697   l_header_tbl(l_index) := '      BASE ATTRIBUTE12 VARCHAR2(150)';
698   l_index := l_index + 1;
699   l_header_tbl(l_index) := '      BASE ATTRIBUTE13 VARCHAR2(150)';
700   l_index := l_index + 1;
701   l_header_tbl(l_index) := '      BASE ATTRIBUTE14 VARCHAR2(150)';
702   l_index := l_index + 1;
703   l_header_tbl(l_index) := '      BASE ATTRIBUTE15 VARCHAR2(150)';
704   l_index := l_index + 1;
705   l_header_tbl(l_index) := '      BASE CREATED_BY NUMBER(15)';
706   l_index := l_index + 1;
707   l_header_tbl(l_index) := '      BASE CREATION_DATE DATE';
708   l_index := l_index + 1;
709   l_header_tbl(l_index) := '      BASE LAST_UPDATED_BY NUMBER(15)';
710   l_index := l_index + 1;
711   l_header_tbl(l_index) := '      CTX OWNER VARCHAR2(4000)';
712   l_index := l_index + 1;
713   l_header_tbl(l_index) := '      BASE LAST_UPDATE_DATE DATE';
714   l_index := l_index + 1;
715   l_header_tbl(l_index) := '      BASE LAST_UPDATE_LOGIN NUMBER(15)';
716   l_index := l_index + 1;
717   l_header_tbl(l_index) := '    END ATTRIBUTE_NAVIGATION';
718   l_index := l_index + 1;
719   l_header_tbl(l_index) := '  END OBJECT_ATTRIBUTE';
720   l_index := l_index + 1;
721   l_header_tbl(l_index) := ' ';
722   --
723   -- Do not download Attribute_value
724   --
725   /*
726   l_index := l_index + 1;
727   l_header_tbl(l_index) := '    DEFINE ATTRIBUTE_VALUE';
728   l_index := l_index + 1;
729   l_header_tbl(l_index) := '      KEY KEY_VALUE_1 VARCHAR2(100)';
730   l_index := l_index + 1;
731   l_header_tbl(l_index) := '      KEY KEY_VALUE_2 VARCHAR2(100)';
732   l_index := l_index + 1;
733   l_header_tbl(l_index) := '      KEY KEY_VALUE_3 VARCHAR2(100)';
734   l_index := l_index + 1;
735   l_header_tbl(l_index) := '      KEY KEY_VALUE_4 VARCHAR2(100)';
736   l_index := l_index + 1;
737   l_header_tbl(l_index) := '      KEY KEY_VALUE_5 VARCHAR2(100)';
738   l_index := l_index + 1;
739   l_header_tbl(l_index) := '      KEY KEY_VALUE_6 VARCHAR2(100)';
740   l_index := l_index + 1;
741   l_header_tbl(l_index) := '      KEY KEY_VALUE_7 VARCHAR2(100)';
742   l_index := l_index + 1;
743   l_header_tbl(l_index) := '      KEY KEY_VALUE_8 VARCHAR2(100)';
744   l_index := l_index + 1;
745   l_header_tbl(l_index) := '      KEY KEY_VALUE_9 VARCHAR2(100)';
746   l_index := l_index + 1;
747   l_header_tbl(l_index) := '      KEY KEY_VALUE_10 VARCHAR2(100)';
748   l_index := l_index + 1;
749   l_header_tbl(l_index) := '      BASE VALUE REFERENCES ATTRIBUTE_NAVIGATION';
750   l_index := l_index + 1;
751   l_header_tbl(l_index) := '      BASE CREATED_BY NUMBER(15)';
752   l_index := l_index + 1;
753   l_header_tbl(l_index) := '      BASE CREATION_DATE DATE';
754   l_index := l_index + 1;
755   l_header_tbl(l_index) := '      BASE LAST_UPDATED_BY NUMBER(15)';
756   l_index := l_index + 1;
757   l_header_tbl(l_index) := '      CTX OWNER VARCHAR2(4000)';
758   l_index := l_index + 1;
759   l_header_tbl(l_index) := '      BASE LAST_UPDATE_DATE DATE';
760   l_index := l_index + 1;
761   l_header_tbl(l_index) := '      BASE LAST_UPDATE_LOGIN NUMBER(15)';
762   l_index := l_index + 1;
763   l_header_tbl(l_index) := '    END ATTRIBUTE_VALUE';
764   l_index := l_index + 1;
765   l_header_tbl(l_index) := '  END OBJECT_ATTRIBUTE';
766   l_index := l_index + 1;
767   l_header_tbl(l_index) := ' ';
768   */
769   l_index := l_index + 1;
770   l_header_tbl(l_index) := '  DEFINE UNIQUE_KEY';
771   l_index := l_index + 1;
772   l_header_tbl(l_index) := '    KEY UNIQUE_KEY_NAME VARCHAR2(30)';
773   l_index := l_index + 1;
774   l_header_tbl(l_index) := '    BASE APPLICATION_ID NUMBER(15)';
775   l_index := l_index + 1;
776   l_header_tbl(l_index) := '    BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
777   l_index := l_index + 1;
778   l_header_tbl(l_index) := '    BASE ATTRIBUTE1 VARCHAR2(150)';
779   l_index := l_index + 1;
780   l_header_tbl(l_index) := '    BASE ATTRIBUTE2 VARCHAR2(150)';
781   l_index := l_index + 1;
782   l_header_tbl(l_index) := '    BASE ATTRIBUTE3 VARCHAR2(150)';
783   l_index := l_index + 1;
784   l_header_tbl(l_index) := '    BASE ATTRIBUTE4 VARCHAR2(150)';
785   l_index := l_index + 1;
786   l_header_tbl(l_index) := '    BASE ATTRIBUTE5 VARCHAR2(150)';
787   l_index := l_index + 1;
788   l_header_tbl(l_index) := '    BASE ATTRIBUTE6 VARCHAR2(150)';
789   l_index := l_index + 1;
790   l_header_tbl(l_index) := '    BASE ATTRIBUTE7 VARCHAR2(150)';
791   l_index := l_index + 1;
792   l_header_tbl(l_index) := '    BASE ATTRIBUTE8 VARCHAR2(150)';
793   l_index := l_index + 1;
794   l_header_tbl(l_index) := '    BASE ATTRIBUTE9 VARCHAR2(150)';
795   l_index := l_index + 1;
796   l_header_tbl(l_index) := '    BASE ATTRIBUTE10 VARCHAR2(150)';
797   l_index := l_index + 1;
798   l_header_tbl(l_index) := '    BASE ATTRIBUTE11 VARCHAR2(150)';
799   l_index := l_index + 1;
800   l_header_tbl(l_index) := '    BASE ATTRIBUTE12 VARCHAR2(150)';
801   l_index := l_index + 1;
802   l_header_tbl(l_index) := '    BASE ATTRIBUTE13 VARCHAR2(150)';
803   l_index := l_index + 1;
804   l_header_tbl(l_index) := '    BASE ATTRIBUTE14 VARCHAR2(150)';
805   l_index := l_index + 1;
806   l_header_tbl(l_index) := '    BASE ATTRIBUTE15 VARCHAR2(150)';
807   l_index := l_index + 1;
808   l_header_tbl(l_index) := '    BASE CREATED_BY NUMBER(15)';
809   l_index := l_index + 1;
810   l_header_tbl(l_index) := '    BASE CREATION_DATE DATE';
811   l_index := l_index + 1;
812   l_header_tbl(l_index) := '    BASE LAST_UPDATED_BY NUMBER(15)';
813   l_index := l_index + 1;
814   l_header_tbl(l_index) := '    CTX OWNER VARCHAR2(4000)';
815   l_index := l_index + 1;
816   l_header_tbl(l_index) := '    BASE LAST_UPDATE_DATE DATE';
817   l_index := l_index + 1;
818   l_header_tbl(l_index) := '    BASE LAST_UPDATE_LOGIN NUMBER(15)';
819   l_index := l_index + 1;
820   l_header_tbl(l_index) := ' ';
821   l_index := l_index + 1;
822   l_header_tbl(l_index) := '    DEFINE UNIQUE_KEY_COLUMN';
823   l_index := l_index + 1;
824   l_header_tbl(l_index) := '      KEY UNIQUE_KEY_COLUMNS_PK REFERENCES ATTRIBUTE';
825   l_index := l_index + 1;
826   l_header_tbl(l_index) := '      BASE UNIQUE_KEY_SEQUENCE NUMBER(15)';
827   l_index := l_index + 1;
828   l_header_tbl(l_index) := '      BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
829   l_index := l_index + 1;
830   l_header_tbl(l_index) := '      BASE ATTRIBUTE1 VARCHAR2(150)';
831   l_index := l_index + 1;
832   l_header_tbl(l_index) := '      BASE ATTRIBUTE2 VARCHAR2(150)';
833   l_index := l_index + 1;
834   l_header_tbl(l_index) := '      BASE ATTRIBUTE3 VARCHAR2(150)';
835   l_index := l_index + 1;
836   l_header_tbl(l_index) := '      BASE ATTRIBUTE4 VARCHAR2(150)';
837   l_index := l_index + 1;
838   l_header_tbl(l_index) := '      BASE ATTRIBUTE5 VARCHAR2(150)';
839   l_index := l_index + 1;
840   l_header_tbl(l_index) := '      BASE ATTRIBUTE6 VARCHAR2(150)';
841   l_index := l_index + 1;
842   l_header_tbl(l_index) := '      BASE ATTRIBUTE7 VARCHAR2(150)';
843   l_index := l_index + 1;
844   l_header_tbl(l_index) := '      BASE ATTRIBUTE8 VARCHAR2(150)';
845   l_index := l_index + 1;
846   l_header_tbl(l_index) := '      BASE ATTRIBUTE9 VARCHAR2(150)';
847   l_index := l_index + 1;
848   l_header_tbl(l_index) := '      BASE ATTRIBUTE10 VARCHAR2(150)';
849   l_index := l_index + 1;
850   l_header_tbl(l_index) := '      BASE ATTRIBUTE11 VARCHAR2(150)';
851   l_index := l_index + 1;
852   l_header_tbl(l_index) := '      BASE ATTRIBUTE12 VARCHAR2(150)';
853   l_index := l_index + 1;
854   l_header_tbl(l_index) := '      BASE ATTRIBUTE13 VARCHAR2(150)';
855   l_index := l_index + 1;
856   l_header_tbl(l_index) := '      BASE ATTRIBUTE14 VARCHAR2(150)';
857   l_index := l_index + 1;
858   l_header_tbl(l_index) := '      BASE ATTRIBUTE15 VARCHAR2(150)';
859   l_index := l_index + 1;
860   l_header_tbl(l_index) := '      BASE CREATED_BY NUMBER(15)';
861   l_index := l_index + 1;
862   l_header_tbl(l_index) := '      BASE CREATION_DATE DATE';
863   l_index := l_index + 1;
864   l_header_tbl(l_index) := '      BASE LAST_UPDATED_BY NUMBER(15)';
865   l_index := l_index + 1;
866   l_header_tbl(l_index) := '      CTX OWNER VARCHAR2(4000)';
867   l_index := l_index + 1;
868   l_header_tbl(l_index) := '      BASE LAST_UPDATE_DATE DATE';
869   l_index := l_index + 1;
870   l_header_tbl(l_index) := '      BASE LAST_UPDATE_LOGIN NUMBER(15)';
871   l_index := l_index + 1;
872   l_header_tbl(l_index) := '    END UNIQUE_KEY_COLUMN';
873   l_index := l_index + 1;
874   l_header_tbl(l_index) := '  END UNIQUE_KEY';
875   l_index := l_index + 1;
876   l_header_tbl(l_index) := ' ';
877   l_index := l_index + 1;
878   l_header_tbl(l_index) := '  DEFINE FOREIGN_KEY';
879   l_index := l_index + 1;
880   l_header_tbl(l_index) := '    KEY FOREIGN_KEY_NAME VARCHAR2(30)';
881   l_index := l_index + 1;
882   l_header_tbl(l_index) := '    BASE UNIQUE_KEY_NAME REFERENCES UNIQUE_KEY';
883   l_index := l_index + 1;
884   l_header_tbl(l_index) := '    BASE APPLICATION_ID NUMBER(15)';
885   l_index := l_index + 1;
886   l_header_tbl(l_index) := '    BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
887   l_index := l_index + 1;
888   l_header_tbl(l_index) := '    BASE ATTRIBUTE1 VARCHAR2(150)';
889   l_index := l_index + 1;
890   l_header_tbl(l_index) := '    BASE ATTRIBUTE2 VARCHAR2(150)';
891   l_index := l_index + 1;
892   l_header_tbl(l_index) := '    BASE ATTRIBUTE3 VARCHAR2(150)';
893   l_index := l_index + 1;
894   l_header_tbl(l_index) := '    BASE ATTRIBUTE4 VARCHAR2(150)';
895   l_index := l_index + 1;
896   l_header_tbl(l_index) := '    BASE ATTRIBUTE5 VARCHAR2(150)';
897   l_index := l_index + 1;
898   l_header_tbl(l_index) := '    BASE ATTRIBUTE6 VARCHAR2(150)';
899   l_index := l_index + 1;
900   l_header_tbl(l_index) := '    BASE ATTRIBUTE7 VARCHAR2(150)';
901   l_index := l_index + 1;
902   l_header_tbl(l_index) := '    BASE ATTRIBUTE8 VARCHAR2(150)';
903   l_index := l_index + 1;
904   l_header_tbl(l_index) := '    BASE ATTRIBUTE9 VARCHAR2(150)';
905   l_index := l_index + 1;
906   l_header_tbl(l_index) := '    BASE ATTRIBUTE10 VARCHAR2(150)';
907   l_index := l_index + 1;
908   l_header_tbl(l_index) := '    BASE ATTRIBUTE11 VARCHAR2(150)';
909   l_index := l_index + 1;
910   l_header_tbl(l_index) := '    BASE ATTRIBUTE12 VARCHAR2(150)';
911   l_index := l_index + 1;
912   l_header_tbl(l_index) := '    BASE ATTRIBUTE13 VARCHAR2(150)';
913   l_index := l_index + 1;
914   l_header_tbl(l_index) := '    BASE ATTRIBUTE14 VARCHAR2(150)';
915   l_index := l_index + 1;
916   l_header_tbl(l_index) := '    BASE ATTRIBUTE15 VARCHAR2(150)';
917   l_index := l_index + 1;
918   l_header_tbl(l_index) := '    BASE CREATED_BY NUMBER(15)';
919   l_index := l_index + 1;
920   l_header_tbl(l_index) := '    BASE CREATION_DATE DATE';
921   l_index := l_index + 1;
922   l_header_tbl(l_index) := '    BASE LAST_UPDATED_BY NUMBER(15)';
923   l_index := l_index + 1;
924   l_header_tbl(l_index) := '    CTX OWNER VARCHAR2(4000)';
925   l_index := l_index + 1;
926   l_header_tbl(l_index) := '    BASE LAST_UPDATE_DATE DATE';
927   l_index := l_index + 1;
928   l_header_tbl(l_index) := '    BASE LAST_UPDATE_LOGIN NUMBER(15)';
929   l_index := l_index + 1;
930   l_header_tbl(l_index) := '    BASE FROM_TO_NAME VARCHAR2(45)';
931   l_index := l_index + 1;
932   l_header_tbl(l_index) := '    BASE FROM_TO_DESCRIPTION VARCHAR2(1500)';
933   l_index := l_index + 1;
934   l_header_tbl(l_index) := '    BASE TO_FROM_NAME VARCHAR2(45)';
935   l_index := l_index + 1;
936   l_header_tbl(l_index) := '    BASE TO_FROM_DESCRIPTION VARCHAR2(1500)';
937   l_index := l_index + 1;
938   l_header_tbl(l_index) := ' ';
939   l_index := l_index + 1;
940   l_header_tbl(l_index) := '    DEFINE FOREIGN_KEY_COLUMN';
941   l_index := l_index + 1;
942   l_header_tbl(l_index) := '      KEY FOREIGN_KEY_COLUMNS_PK REFERENCES ATTRIBUTE';
943   l_index := l_index + 1;
944   l_header_tbl(l_index) := '      BASE FOREIGN_KEY_SEQUENCE NUMBER(15)';
945   l_index := l_index + 1;
946   l_header_tbl(l_index) := '      BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
947   l_index := l_index + 1;
948   l_header_tbl(l_index) := '      BASE ATTRIBUTE1 VARCHAR2(150)';
949   l_index := l_index + 1;
950   l_header_tbl(l_index) := '      BASE ATTRIBUTE2 VARCHAR2(150)';
951   l_index := l_index + 1;
952   l_header_tbl(l_index) := '      BASE ATTRIBUTE3 VARCHAR2(150)';
953   l_index := l_index + 1;
954   l_header_tbl(l_index) := '      BASE ATTRIBUTE4 VARCHAR2(150)';
955   l_index := l_index + 1;
956   l_header_tbl(l_index) := '      BASE ATTRIBUTE5 VARCHAR2(150)';
957   l_index := l_index + 1;
958   l_header_tbl(l_index) := '      BASE ATTRIBUTE6 VARCHAR2(150)';
959   l_index := l_index + 1;
960   l_header_tbl(l_index) := '      BASE ATTRIBUTE7 VARCHAR2(150)';
961   l_index := l_index + 1;
962   l_header_tbl(l_index) := '      BASE ATTRIBUTE8 VARCHAR2(150)';
963   l_index := l_index + 1;
964   l_header_tbl(l_index) := '      BASE ATTRIBUTE9 VARCHAR2(150)';
965   l_index := l_index + 1;
966   l_header_tbl(l_index) := '      BASE ATTRIBUTE10 VARCHAR2(150)';
967   l_index := l_index + 1;
968   l_header_tbl(l_index) := '      BASE ATTRIBUTE11 VARCHAR2(150)';
969   l_index := l_index + 1;
970   l_header_tbl(l_index) := '      BASE ATTRIBUTE12 VARCHAR2(150)';
971   l_index := l_index + 1;
972   l_header_tbl(l_index) := '      BASE ATTRIBUTE13 VARCHAR2(150)';
973   l_index := l_index + 1;
974   l_header_tbl(l_index) := '      BASE ATTRIBUTE14 VARCHAR2(150)';
975   l_index := l_index + 1;
976   l_header_tbl(l_index) := '      BASE ATTRIBUTE15 VARCHAR2(150)';
977   l_index := l_index + 1;
978   l_header_tbl(l_index) := '      BASE CREATED_BY NUMBER(15)';
979   l_index := l_index + 1;
980   l_header_tbl(l_index) := '      BASE CREATION_DATE DATE';
981   l_index := l_index + 1;
982   l_header_tbl(l_index) := '      BASE LAST_UPDATED_BY NUMBER(15)';
983   l_index := l_index + 1;
984   l_header_tbl(l_index) := '      CTX OWNER VARCHAR2(4000)';
985   l_index := l_index + 1;
986   l_header_tbl(l_index) := '      BASE LAST_UPDATE_DATE DATE';
987   l_index := l_index + 1;
988   l_header_tbl(l_index) := '      BASE LAST_UPDATE_LOGIN NUMBER(15)';
989   l_index := l_index + 1;
990   l_header_tbl(l_index) := '    END FOREIGN_KEY_COLUMN';
991   l_index := l_index + 1;
992   l_header_tbl(l_index) := '  END FOREIGN_KEY';
993   l_index := l_index + 1;
994   l_header_tbl(l_index) := 'END OBJECT';
995   l_index := l_index + 1;
996   l_header_tbl(l_index) := ' ';
997   l_index := l_index + 1;
998   l_header_tbl(l_index) := 'DEFINE REGION';
999   l_index := l_index + 1;
1000   l_header_tbl(l_index) := '  KEY REGION_APPLICATION_ID NUMBER(15)';
1001   l_index := l_index + 1;
1002   l_header_tbl(l_index) := '  KEY REGION_CODE VARCHAR2(30)';
1003   l_index := l_index + 1;
1004   l_header_tbl(l_index) := '  BASE DATABASE_OBJECT_NAME REFERENCES OBJECT';
1005   l_index := l_index + 1;
1006   l_header_tbl(l_index) := '  BASE REGION_STYLE VARCHAR2(30)';
1007   l_index := l_index + 1;
1008   l_header_tbl(l_index) := '  BASE NUM_COLUMNS NUMBER(15)';
1009   l_index := l_index + 1;
1010   l_header_tbl(l_index) := '  BASE ICX_CUSTOM_CALL VARCHAR2(80)';
1011   l_index := l_index + 1;
1012   l_header_tbl(l_index) := '  BASE REGION_DEFAULTING_API_PKG VARCHAR2(30)';
1013   l_index := l_index + 1;
1014   l_header_tbl(l_index) := '  BASE REGION_DEFAULTING_API_PROC VARCHAR2(30)';
1015   l_index := l_index + 1;
1016   l_header_tbl(l_index) := '  BASE REGION_VALIDATION_API_PKG VARCHAR2(30)';
1017   l_index := l_index + 1;
1018   l_header_tbl(l_index) := '  BASE REGION_VALIDATION_API_PROC VARCHAR2(30)';
1019   l_index := l_index + 1;
1020   l_header_tbl(l_index) := '  BASE APPLICATIONMODULE_OBJECT_TYPE VARCHAR2(240)';
1021   l_index := l_index + 1;
1022   l_header_tbl(l_index) := '  BASE NUM_ROWS_DISPLAY NUMBER(15)';
1023   l_index := l_index + 1;
1024   l_header_tbl(l_index) := '  BASE REGION_OBJECT_TYPE VARCHAR2(240)';
1025   l_index := l_index + 1;
1026   l_header_tbl(l_index) := '  BASE IMAGE_FILE_NAME VARCHAR2(80)';
1027   l_index := l_index + 1;
1028   l_header_tbl(l_index) := '  BASE ISFORM_FLAG VARCHAR2(1)';
1029   l_index := l_index + 1;
1030   l_header_tbl(l_index) := '  BASE HELP_TARGET VARCHAR2(240)';
1031   l_index := l_index + 1;
1032   l_header_tbl(l_index) := '  BASE STYLE_SHEET_FILENAME VARCHAR2(240)';
1033   l_index := l_index + 1;
1034   l_header_tbl(l_index) := '  BASE VERSION VARCHAR2(30)';
1035   l_index := l_index + 1;
1036   l_header_tbl(l_index) := '  BASE APPLICATIONMODULE_USAGE_NAME VARCHAR2(80)';
1037   l_index := l_index + 1;
1038   l_header_tbl(l_index) := '  BASE ADD_INDEXED_CHILDREN VARCHAR2(1)';
1039   l_index := l_index + 1;
1040   l_header_tbl(l_index) := '  BASE STATEFUL_FLAG VARCHAR2(1)';
1041   l_index := l_index + 1;
1042   l_header_tbl(l_index) := '  BASE FUNCTION_NAME VARCHAR2(30)';
1043   l_index := l_index + 1;
1044   l_header_tbl(l_index) := '  BASE CHILDREN_VIEW_USAGE_NAME VARCHAR2(80)';
1045   l_index := l_index + 1;
1046   l_header_tbl(l_index) := '  BASE SEARCH_PANEL VARCHAR2(1)';
1047   l_index := l_index + 1;
1048   l_header_tbl(l_index) := '  BASE ADVANCED_SEARCH_PANEL VARCHAR2(1)';
1049   l_index := l_index + 1;
1050   l_header_tbl(l_index) := '  BASE CUSTOMIZE_PANEL VARCHAR2(1)';
1051   l_index := l_index + 1;
1052   l_header_tbl(l_index) := '  BASE DEFAULT_SEARCH_PANEL VARCHAR2(30)';
1053   l_index := l_index + 1;
1054   l_header_tbl(l_index) := '  BASE RESULTS_BASED_SEARCH VARCHAR2(1)';
1055   l_index := l_index + 1;
1056   l_header_tbl(l_index) := '  BASE DISPLAY_GRAPH_TABLE VARCHAR2(1)';
1057   l_index := l_index + 1;
1058   l_header_tbl(l_index) := '  BASE DISABLE_HEADER VARCHAR2(1)';
1059   l_index := l_index + 1;
1060   l_header_tbl(l_index) := '  BASE STANDALONE VARCHAR2(1)';
1061   l_index := l_index + 1;
1062   l_header_tbl(l_index) := '  BASE AUTO_CUSTOMIZATION_CRITERIA VARCHAR2(1)';
1063   l_index := l_index + 1;
1064   l_header_tbl(l_index) := '  BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
1065   l_index := l_index + 1;
1066   l_header_tbl(l_index) := '  BASE ATTRIBUTE1 VARCHAR2(150)';
1067   l_index := l_index + 1;
1068   l_header_tbl(l_index) := '  BASE ATTRIBUTE2 VARCHAR2(150)';
1069   l_index := l_index + 1;
1070   l_header_tbl(l_index) := '  BASE ATTRIBUTE3 VARCHAR2(150)';
1071   l_index := l_index + 1;
1072   l_header_tbl(l_index) := '  BASE ATTRIBUTE4 VARCHAR2(150)';
1073   l_index := l_index + 1;
1074   l_header_tbl(l_index) := '  BASE ATTRIBUTE5 VARCHAR2(150)';
1075   l_index := l_index + 1;
1076   l_header_tbl(l_index) := '  BASE ATTRIBUTE6 VARCHAR2(150)';
1077   l_index := l_index + 1;
1078   l_header_tbl(l_index) := '  BASE ATTRIBUTE7 VARCHAR2(150)';
1079   l_index := l_index + 1;
1080   l_header_tbl(l_index) := '  BASE ATTRIBUTE8 VARCHAR2(150)';
1081   l_index := l_index + 1;
1082   l_header_tbl(l_index) := '  BASE ATTRIBUTE9 VARCHAR2(150)';
1083   l_index := l_index + 1;
1084   l_header_tbl(l_index) := '  BASE ATTRIBUTE10 VARCHAR2(150)';
1085   l_index := l_index + 1;
1086   l_header_tbl(l_index) := '  BASE ATTRIBUTE11 VARCHAR2(150)';
1087   l_index := l_index + 1;
1088   l_header_tbl(l_index) := '  BASE ATTRIBUTE12 VARCHAR2(150)';
1089   l_index := l_index + 1;
1090   l_header_tbl(l_index) := '  BASE ATTRIBUTE13 VARCHAR2(150)';
1091   l_index := l_index + 1;
1092   l_header_tbl(l_index) := '  BASE ATTRIBUTE14 VARCHAR2(150)';
1093   l_index := l_index + 1;
1094   l_header_tbl(l_index) := '  BASE ATTRIBUTE15 VARCHAR2(150)';
1095   l_index := l_index + 1;
1096   l_header_tbl(l_index) := '  BASE CREATED_BY NUMBER(15)';
1097   l_index := l_index + 1;
1098   l_header_tbl(l_index) := '  BASE CREATION_DATE DATE';
1099   l_index := l_index + 1;
1100   l_header_tbl(l_index) := '  BASE LAST_UPDATED_BY NUMBER(15)';
1101   l_index := l_index + 1;
1102   l_header_tbl(l_index) := '  CTX OWNER VARCHAR2(4000)';
1103   l_index := l_index + 1;
1104   l_header_tbl(l_index) := '  BASE LAST_UPDATE_DATE DATE';
1105   l_index := l_index + 1;
1106   l_header_tbl(l_index) := '  BASE LAST_UPDATE_LOGIN NUMBER(15)';
1107   l_index := l_index + 1;
1108   l_header_tbl(l_index) := '  TRANS NAME VARCHAR2(80)';
1109   l_index := l_index + 1;
1110   l_header_tbl(l_index) := '  TRANS DESCRIPTION VARCHAR2(2000)';
1111   l_index := l_index + 1;
1112   l_header_tbl(l_index) := ' ';
1113   l_index := l_index + 1;
1114   l_header_tbl(l_index) := '  DEFINE REGION_ITEM';
1115   l_index := l_index + 1;
1116   l_header_tbl(l_index) := '    KEY REGION_ITEM_PK REFERENCES ATTRIBUTE';
1117   l_index := l_index + 1;
1118   l_header_tbl(l_index) := '    BASE DISPLAY_SEQUENCE NUMBER(15)';
1119   l_index := l_index + 1;
1120   l_header_tbl(l_index) := '    BASE NODE_DISPLAY_FLAG VARCHAR2(1)';
1121   l_index := l_index + 1;
1122   l_header_tbl(l_index) := '    BASE NODE_QUERY_FLAG VARCHAR2(1)';
1123   l_index := l_index + 1;
1124   l_header_tbl(l_index) := '    CTX ATTRIBUTE_LABEL_LENGTH NUMBER(15)';
1125   l_index := l_index + 1;
1126   l_header_tbl(l_index) := '    BASE DISPLAY_VALUE_LENGTH NUMBER(15)';
1127   l_index := l_index + 1;
1128   l_header_tbl(l_index) := '    BASE BOLD VARCHAR2(1)';
1129   l_index := l_index + 1;
1130   l_header_tbl(l_index) := '    BASE ITALIC VARCHAR2(1)';
1131   l_index := l_index + 1;
1132   l_header_tbl(l_index) := '    BASE VERTICAL_ALIGNMENT VARCHAR2(30)';
1133   l_index := l_index + 1;
1134   l_header_tbl(l_index) := '    BASE HORIZONTAL_ALIGNMENT VARCHAR2(30)';
1135   l_index := l_index + 1;
1136   l_header_tbl(l_index) := '    BASE ITEM_STYLE VARCHAR2(30)';
1137   l_index := l_index + 1;
1138   l_header_tbl(l_index) := '    BASE OBJECT_ATTRIBUTE_FLAG VARCHAR2(1)';
1139   l_index := l_index + 1;
1140   l_header_tbl(l_index) := '    BASE ICX_CUSTOM_CALL VARCHAR2(80)';
1141   l_index := l_index + 1;
1142   l_header_tbl(l_index) := '    BASE UPDATE_FLAG VARCHAR2(1)';
1143   l_index := l_index + 1;
1144   l_header_tbl(l_index) := '    BASE REQUIRED_FLAG VARCHAR2(1)';
1145   l_index := l_index + 1;
1146   l_header_tbl(l_index) := '    BASE SECURITY_CODE VARCHAR2(30)';
1147   l_index := l_index + 1;
1148   l_header_tbl(l_index) := '    BASE DEFAULT_VALUE_VARCHAR2 VARCHAR2(240)';
1149   l_index := l_index + 1;
1150   l_header_tbl(l_index) := '    BASE DEFAULT_VALUE_NUMBER NUMBER(15)';
1151   l_index := l_index + 1;
1152   l_header_tbl(l_index) := '    BASE DEFAULT_VALUE_DATE DATE';
1153   l_index := l_index + 1;
1154   l_header_tbl(l_index) := '    BASE LOV_REGION REFERENCES REGION';
1155   l_index := l_index + 1;
1156   l_header_tbl(l_index) := '    BASE LOV_FOREIGN_KEY_NAME REFERENCES FOREIGN_KEY';
1157   l_index := l_index + 1;
1158   l_header_tbl(l_index) := '    BASE LOV_ATTRIBUTE REFERENCES ATTRIBUTE';
1159   l_index := l_index + 1;
1160   l_header_tbl(l_index) := '    BASE LOV_DEFAULT_FLAG VARCHAR2(1)';
1161   l_index := l_index + 1;
1162   l_header_tbl(l_index) := '    BASE REGION_DEFAULTING_API_PKG VARCHAR2(30)';
1163   l_index := l_index + 1;
1164   l_header_tbl(l_index) := '    BASE REGION_DEFAULTING_API_PROC VARCHAR2(30)';
1165   l_index := l_index + 1;
1166   l_header_tbl(l_index) := '    BASE REGION_VALIDATION_API_PKG VARCHAR2(30)';
1167   l_index := l_index + 1;
1168   l_header_tbl(l_index) := '    BASE REGION_VALIDATION_API_PROC VARCHAR2(30)';
1169   l_index := l_index + 1;
1170   l_header_tbl(l_index) := '    BASE ORDER_SEQUENCE NUMBER(15)';
1171   l_index := l_index + 1;
1172   l_header_tbl(l_index) := '    BASE ORDER_DIRECTION VARCHAR2(30)';
1173   l_index := l_index + 1;
1174   l_header_tbl(l_index) := '    BASE DISPLAY_HEIGHT NUMBER(15)';
1175   l_index := l_index + 1;
1176   l_header_tbl(l_index) := '    BASE SUBMIT VARCHAR2(1)';
1177   l_index := l_index + 1;
1178   l_header_tbl(l_index) := '    BASE ENCRYPT VARCHAR2(1)';
1179   l_index := l_index + 1;
1180   l_header_tbl(l_index) := '    BASE CSS_CLASS_NAME VARCHAR2(80)';
1181   l_index := l_index + 1;
1182   l_header_tbl(l_index) := '    BASE VIEW_USAGE_NAME VARCHAR2(80)';
1183   l_index := l_index + 1;
1184   l_header_tbl(l_index) := '    BASE VIEW_ATTRIBUTE_NAME VARCHAR2(80)';
1185   l_index := l_index + 1;
1186   l_header_tbl(l_index) := '    BASE NESTED_REGION_APPLICATION_ID NUMBER(15)';
1187   l_index := l_index + 1;
1188   l_header_tbl(l_index) := '    BASE NESTED_REGION_CODE VARCHAR2(30)';
1189   l_index := l_index + 1;
1190   l_header_tbl(l_index) := '    BASE URL VARCHAR2(2000)';
1191   l_index := l_index + 1;
1192   l_header_tbl(l_index) := '    BASE POPLIST_VIEWOBJECT VARCHAR2(240)';
1193   l_index := l_index + 1;
1194   l_header_tbl(l_index) := '    BASE POPLIST_DISPLAY_ATTRIBUTE VARCHAR2(80)';
1195   l_index := l_index + 1;
1196   l_header_tbl(l_index) := '    BASE POPLIST_VALUE_ATTRIBUTE VARCHAR2(80)';
1197   l_index := l_index + 1;
1198   l_header_tbl(l_index) := '    BASE IMAGE_FILE_NAME VARCHAR2(80)';
1199   l_index := l_index + 1;
1200   l_header_tbl(l_index) := '    BASE ITEM_NAME VARCHAR2(30)';
1201   l_index := l_index + 1;
1202   l_header_tbl(l_index) := '    BASE CSS_LABEL_CLASS_NAME VARCHAR2(80)';
1203   l_index := l_index + 1;
1204   l_header_tbl(l_index) := '    BASE MENU_NAME VARCHAR2(30)';
1205   l_index := l_index + 1;
1206   l_header_tbl(l_index) := '    BASE FLEXFIELD_NAME VARCHAR2(40)';
1207   l_index := l_index + 1;
1208   l_header_tbl(l_index) := '    BASE FLEXFIELD_APPLICATION_ID NUMBER(15)';
1209   l_index := l_index + 1;
1210   l_header_tbl(l_index) := '    BASE TABULAR_FUNCTION_CODE VARCHAR2(10)';
1211   l_index := l_index + 1;
1212   l_header_tbl(l_index) := '    BASE TIP_TYPE VARCHAR2(10)';
1213   l_index := l_index + 1;
1214   l_header_tbl(l_index) := '    BASE TIP_MESSAGE_NAME VARCHAR2(30)';
1215   l_index := l_index + 1;
1216   l_header_tbl(l_index) := '    BASE TIP_MESSAGE_APPLICATION_ID NUMBER(15)';
1217   l_index := l_index + 1;
1218   l_header_tbl(l_index) := '    BASE FLEX_SEGMENT_LIST VARCHAR2(4000)';
1219   l_index := l_index + 1;
1220   l_header_tbl(l_index) := '    BASE ENTITY_ID VARCHAR2(30)';
1221   l_index := l_index + 1;
1222   l_header_tbl(l_index) := '    BASE ANCHOR VARCHAR2(1)';
1223   l_index := l_index + 1;
1224   l_header_tbl(l_index) := '    BASE POPLIST_VIEW_USAGE_NAME VARCHAR2(80)';
1225   l_index := l_index + 1;
1226   l_header_tbl(l_index) := '    BASE USER_CUSTOMIZABLE VARCHAR2(1)';
1227   l_index := l_index + 1;
1228   l_header_tbl(l_index) := '    BASE SORTBY_VIEW_ATTRIBUTE_NAME VARCHAR2(80)';
1229   l_index := l_index + 1;
1230   l_header_tbl(l_index) := '    BASE ADMIN_CUSTOMIZABLE VARCHAR2(1)';
1231   l_index := l_index + 1;
1232   l_header_tbl(l_index) := '    BASE INVOKE_FUNCTION_NAME VARCHAR2(30)';
1233   l_index := l_index + 1;
1234   l_header_tbl(l_index) := '    CTX EXPANSION NUMBER(15)';
1235   l_index := l_index + 1;
1236   l_header_tbl(l_index) := '    CTX ALS_MAX_LENGTH NUMBER(15)';
1237   l_index := l_index + 1;
1238   l_header_tbl(l_index) := '    BASE INITIAL_SORT_SEQUENCE VARCHAR2(30)';
1239   l_index := l_index + 1;
1240   l_header_tbl(l_index) := '    BASE CUSTOMIZATION_APPLICATION_ID NUMBER(15)';
1241   l_index := l_index + 1;
1242   l_header_tbl(l_index) := '    BASE CUSTOMIZATION_CODE VARCHAR2(30)';
1243   l_index := l_index + 1;
1244   l_header_tbl(l_index) := '    BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
1245   l_index := l_index + 1;
1246   l_header_tbl(l_index) := '    BASE ATTRIBUTE1 VARCHAR2(150)';
1247   l_index := l_index + 1;
1248   l_header_tbl(l_index) := '    BASE ATTRIBUTE2 VARCHAR2(150)';
1249   l_index := l_index + 1;
1250   l_header_tbl(l_index) := '    BASE ATTRIBUTE3 VARCHAR2(150)';
1251   l_index := l_index + 1;
1252   l_header_tbl(l_index) := '    BASE ATTRIBUTE4 VARCHAR2(150)';
1253   l_index := l_index + 1;
1254   l_header_tbl(l_index) := '    BASE ATTRIBUTE5 VARCHAR2(150)';
1255   l_index := l_index + 1;
1256   l_header_tbl(l_index) := '    BASE ATTRIBUTE6 VARCHAR2(150)';
1257   l_index := l_index + 1;
1258   l_header_tbl(l_index) := '    BASE ATTRIBUTE7 VARCHAR2(150)';
1259   l_index := l_index + 1;
1260   l_header_tbl(l_index) := '    BASE ATTRIBUTE8 VARCHAR2(150)';
1261   l_index := l_index + 1;
1262   l_header_tbl(l_index) := '    BASE ATTRIBUTE9 VARCHAR2(150)';
1263   l_index := l_index + 1;
1264   l_header_tbl(l_index) := '    BASE ATTRIBUTE10 VARCHAR2(150)';
1265   l_index := l_index + 1;
1266   l_header_tbl(l_index) := '    BASE ATTRIBUTE11 VARCHAR2(150)';
1267   l_index := l_index + 1;
1268   l_header_tbl(l_index) := '    BASE ATTRIBUTE12 VARCHAR2(150)';
1269   l_index := l_index + 1;
1270   l_header_tbl(l_index) := '    BASE ATTRIBUTE13 VARCHAR2(150)';
1271   l_index := l_index + 1;
1272   l_header_tbl(l_index) := '    BASE ATTRIBUTE14 VARCHAR2(150)';
1273   l_index := l_index + 1;
1274   l_header_tbl(l_index) := '    BASE ATTRIBUTE15 VARCHAR2(150)';
1275   l_index := l_index + 1;
1276   l_header_tbl(l_index) := '    BASE CREATED_BY NUMBER(15)';
1277   l_index := l_index + 1;
1278   l_header_tbl(l_index) := '    BASE CREATION_DATE DATE';
1279   l_index := l_index + 1;
1280   l_header_tbl(l_index) := '    BASE LAST_UPDATED_BY NUMBER(15)';
1281   l_index := l_index + 1;
1282   l_header_tbl(l_index) := '    CTX OWNER VARCHAR2(4000)';
1283   l_index := l_index + 1;
1284   l_header_tbl(l_index) := '    BASE LAST_UPDATE_DATE DATE';
1285   l_index := l_index + 1;
1286   l_header_tbl(l_index) := '    BASE LAST_UPDATE_LOGIN NUMBER(15)';
1287   l_index := l_index + 1;
1288   l_header_tbl(l_index) := '    TRANS ATTRIBUTE_LABEL_LONG VARCHAR2(80)';
1289   l_index := l_index + 1;
1290   l_header_tbl(l_index) := '    TRANS ATTRIBUTE_LABEL_SHORT VARCHAR2(30)';
1291   l_index := l_index + 1;
1292   l_header_tbl(l_index) := '    TRANS DESCRIPTION VARCHAR2(2000)';
1293   l_index := l_index + 1;
1294   l_header_tbl(l_index) := '      DEFINE REGION_LOV_RELATION';
1295   l_index := l_index + 1;
1296   l_header_tbl(l_index) := '        KEY LOV_REGION REFERENCES REGION';
1297   l_index := l_index + 1;
1298   l_header_tbl(l_index) := '        KEY LOV_ATTRIBUTE REFERENCES ATTRIBUTE';
1299   l_index := l_index + 1;
1300   l_header_tbl(l_index) := '        KEY BASE_ATTRIBUTE REFERENCES ATTRIBUTE';
1301   l_index := l_index + 1;
1302   l_header_tbl(l_index) := '        KEY DIRECTION_FLAG VARCHAR2(30)';
1303   l_index := l_index + 1;
1304   l_header_tbl(l_index) := '        BASE BASE_REGION_APPL_ID NUMBER(15)';
1305   l_index := l_index + 1;
1306   l_header_tbl(l_index) := '        BASE BASE_REGION_CODE VARCHAR2(30)';
1307   l_index := l_index + 1;
1308   l_header_tbl(l_index) := '        BASE REQUIRED_FLAG VARCHAR2(1)';
1309   l_index := l_index + 1;
1310   l_header_tbl(l_index) := '        BASE CREATED_BY NUMBER(15)';
1311   l_index := l_index + 1;
1312   l_header_tbl(l_index) := '        BASE CREATION_DATE DATE';
1313   l_index := l_index + 1;
1314   l_header_tbl(l_index) := '        BASE LAST_UPDATED_BY NUMBER(15)';
1315   l_index := l_index + 1;
1316   l_header_tbl(l_index) := '        CTX OWNER VARCHAR2(4000)';
1317   l_index := l_index + 1;
1318   l_header_tbl(l_index) := '        BASE LAST_UPDATE_DATE DATE';
1319   l_index := l_index + 1;
1320   l_header_tbl(l_index) := '        BASE LAST_UPDATE_LOGIN NUMBER(15)';
1321   l_index := l_index + 1;
1322   l_header_tbl(l_index) := '      END REGION_LOV_RELATION';
1323   l_index := l_index + 1;
1324   l_header_tbl(l_index) := '      DEFINE CATEGORY_USAGE';
1325   l_index := l_index + 1;
1326   l_header_tbl(l_index) := '        KEY CATEGORY_ID NUMBER(15)';
1327   l_index := l_index + 1;
1328   l_header_tbl(l_index) := '        BASE CATEGORY_NAME VARCHAR2(30)';
1329   l_index := l_index + 1;
1330   l_header_tbl(l_index) := '        BASE APPLICATION_ID NUMBER(15)';
1331   l_index := l_index + 1;
1332   l_header_tbl(l_index) := '        BASE SHOW_ALL VARCHAR2(1)';
1333   l_index := l_index + 1;
1334   l_header_tbl(l_index) := '        BASE CREATED_BY NUMBER(15)';
1335   l_index := l_index + 1;
1336   l_header_tbl(l_index) := '        BASE CREATION_DATE DATE';
1337   l_index := l_index + 1;
1338   l_header_tbl(l_index) := '        BASE LAST_UPDATED_BY NUMBER(15)';
1339   l_index := l_index + 1;
1340   l_header_tbl(l_index) := '        CTX OWNER VARCHAR2(4000)';
1341   l_index := l_index + 1;
1342   l_header_tbl(l_index) := '        BASE LAST_UPDATE_DATE DATE';
1343   l_index := l_index + 1;
1344   l_header_tbl(l_index) := '        BASE LAST_UPDATE_LOGIN NUMBER(15)';
1345   l_index := l_index + 1;
1346   l_header_tbl(l_index) := '      END CATEGORY_USAGE';
1347   l_index := l_index + 1;
1348   l_header_tbl(l_index) := '  END REGION_ITEM';
1349   l_index := l_index + 1;
1350   l_header_tbl(l_index) := '  DEFINE REGION_GRAPH';
1351   l_index := l_index + 1;
1352   l_header_tbl(l_index) := '    KEY GRAPH_NUMBER NUMBER(15)';
1353   l_index := l_index + 1;
1354   l_header_tbl(l_index) := '    BASE GRAPH_STYLE NUMBER(15)';
1355   l_index := l_index + 1;
1356   l_header_tbl(l_index) := '    BASE DISPLAY_FLAG VARCHAR2(1)';
1357   l_index := l_index + 1;
1358   l_header_tbl(l_index) := '    BASE DEPTH_RADIUS NUMBER(15)';
1359   l_index := l_index + 1;
1360   l_header_tbl(l_index) := '    BASE CREATED_BY NUMBER(15)';
1361   l_index := l_index + 1;
1362   l_header_tbl(l_index) := '    BASE CREATION_DATE DATE';
1363   l_index := l_index + 1;
1364   l_header_tbl(l_index) := '    BASE LAST_UPDATED_BY NUMBER(15)';
1365   l_index := l_index + 1;
1366   l_header_tbl(l_index) := '    CTX OWNER VARCHAR2(4000)';
1367   l_index := l_index + 1;
1368   l_header_tbl(l_index) := '    BASE LAST_UPDATE_DATE DATE';
1369   l_index := l_index + 1;
1370   l_header_tbl(l_index) := '    BASE LAST_UPDATE_LOGIN NUMBER(15)';
1371   l_index := l_index + 1;
1372   l_header_tbl(l_index) := '    TRANS GRAPH_TITLE VARCHAR2(240)';
1373   l_index := l_index + 1;
1374   l_header_tbl(l_index) := '    TRANS Y_AXIS_LABEL VARCHAR2(80)';
1375   l_index := l_index + 1;
1376   l_header_tbl(l_index) := '    TRANS LANGUAGE VARCHAR2(4)';
1377   l_index := l_index + 1;
1378   l_header_tbl(l_index) := '    DEFINE REGION_COLUMN';
1379   l_index := l_index + 1;
1380   l_header_tbl(l_index) := '      KEY ATTRIBUTE_APPLICATION_ID NUMBER(15)';
1381   l_index := l_index + 1;
1382   l_header_tbl(l_index) := '      KEY ATTRIBUTE_CODE VARCHAR2(30)';
1383   l_index := l_index + 1;
1384   l_header_tbl(l_index) := '      BASE CREATED_BY NUMBER(15)';
1385   l_index := l_index + 1;
1386   l_header_tbl(l_index) := '      BASE CREATION_DATE DATE';
1387   l_index := l_index + 1;
1388   l_header_tbl(l_index) := '      BASE LAST_UPDATED_BY NUMBER(15)';
1389   l_index := l_index + 1;
1390   l_header_tbl(l_index) := '      CTX OWNER VARCHAR2(4000)';
1391   l_index := l_index + 1;
1392   l_header_tbl(l_index) := '      BASE LAST_UPDATE_DATE DATE';
1393   l_index := l_index + 1;
1394   l_header_tbl(l_index) := '      BASE LAST_UPDATE_LOGIN NUMBER(15)';
1395   l_index := l_index + 1;
1396   l_header_tbl(l_index) := '    END REGION_COLUMN';
1397   l_index := l_index + 1;
1398   l_header_tbl(l_index) := '  END REGION_GRAPH';
1399   l_index := l_index + 1;
1400   l_header_tbl(l_index) := 'END REGION';
1401   l_index := l_index + 1;
1402   l_header_tbl(l_index) := ' ';
1403   end if;
1404 
1405   if (p_download_by_object = AK_ON_OBJECTS_PVT.G_CUSTOM_REGION) then
1406   l_index := l_index + 1;
1407   l_header_tbl(l_index) := 'DEFINE CUSTOMIZATION';
1408   l_index := l_index + 1;
1409   l_header_tbl(l_index) := '  KEY CUSTOMIZATION_APPLICATION_ID NUMBER(15)';
1410   l_index := l_index + 1;
1411   l_header_tbl(l_index) := '  KEY CUSTOMIZATION_CODE VARCHAR2(30)';
1412   l_index := l_index + 1;
1413   l_header_tbl(l_index) := '  KEY REGION_APPLICATION_ID NUMBER(15)';
1414   l_index := l_index + 1;
1415   l_header_tbl(l_index) := '  KEY REGION_CODE VARCHAR2(30)';
1416   l_index := l_index + 1;
1417   l_header_tbl(l_index) := '  BASE VERTICALIZATION_ID VARCHAR2(150)';
1418   l_index := l_index + 1;
1419   l_header_tbl(l_index) := '  BASE LOCALIZATION_CODE VARCHAR2(150)';
1420   l_index := l_index + 1;
1421   l_header_tbl(l_index) := '  BASE ORG_ID NUMBER(15)';
1422   l_index := l_index + 1;
1423   l_header_tbl(l_index) := '  BASE SITE_ID NUMBER(15)';
1424   l_index := l_index + 1;
1425   l_header_tbl(l_index) := '  BASE RESPONSIBILITY_ID NUMBER(15)';
1426   l_index := l_index + 1;
1427   l_header_tbl(l_index) := '  BASE WEB_USER_ID NUMBER(15)';
1428   l_index := l_index + 1;
1429   l_header_tbl(l_index) := '  BASE CUSTOMIZATION_FLAG VARCHAR2(1)';
1430   l_index := l_index + 1;
1431   l_header_tbl(l_index) := '  BASE CUSTOMIZATION_LEVEL_ID NUMBER(15)';
1432   l_index := l_index + 1;
1433   l_header_tbl(l_index) := '  BASE DEVELOPER_MODE VARCHAR2(1)';
1434   l_index := l_index + 1;
1435   l_header_tbl(l_index) := '  BASE REFERENCE_PATH VARCHAR2(100)';
1436   l_index := l_index + 1;
1437   l_header_tbl(l_index) := '  BASE FUNCTION_NAME VARCHAR2(30)';
1438   l_index := l_index + 1;
1439   l_header_tbl(l_index) := '  BASE START_DATE_ACTIVE DATE';
1440   l_index := l_index + 1;
1441   l_header_tbl(l_index) := '  BASE END_DATE_ACTIVE DATE';
1442   l_index := l_index + 1;
1443   l_header_tbl(l_index) := '  BASE CREATED_BY NUMBER(15)';
1444   l_index := l_index + 1;
1445   l_header_tbl(l_index) := '  BASE CREATION_DATE DATE';
1446   l_index := l_index + 1;
1447   l_header_tbl(l_index) := '  BASE LAST_UPDATED_BY NUMBER(15)';
1448   l_index := l_index + 1;
1449   l_header_tbl(l_index) := '  CTX OWNER VARCHAR2(4000)';
1450   l_index := l_index + 1;
1451   l_header_tbl(l_index) := '  BASE LAST_UPDATE_DATE DATE';
1452   l_index := l_index + 1;
1453   l_header_tbl(l_index) := '  BASE LAST_UPDATE_LOGIN NUMBER(15)';
1454   l_index := l_index + 1;
1455   l_header_tbl(l_index) := '  TRANS NAME VARCHAR2(80)';
1456   l_index := l_index + 1;
1457   l_header_tbl(l_index) := '  TRANS DESCRIPTION VARCHAR2(2000)';
1458   l_index := l_index + 1;
1459   l_header_tbl(l_index) := ' ';
1460   l_index := l_index + 1;
1461   l_header_tbl(l_index) := '  DEFINE CUSTOM_REGION';
1462   l_index := l_index + 1;
1463   l_header_tbl(l_index) := '    KEY PROPERTY_NAME VARCHAR2(30)';
1464   l_index := l_index + 1;
1465   l_header_tbl(l_index) := '    BASE PROPERTY_VARCHAR2_VALUE VARCHAR2(2000)';
1466   l_index := l_index + 1;
1467   l_header_tbl(l_index) := '    BASE PROPERTY_NUMBER_VALUE NUMBER(15)';
1468   l_index := l_index + 1;
1469   l_header_tbl(l_index) := '    BASE CRITERIA_JOIN_CONDITION VARCHAR2(3)';
1470   l_index := l_index + 1;
1471   l_header_tbl(l_index) := '    BASE CREATED_BY NUMBER(15)';
1472   l_index := l_index + 1;
1473   l_header_tbl(l_index) := '    BASE CREATION_DATE DATE';
1474   l_index := l_index + 1;
1475   l_header_tbl(l_index) := '    BASE LAST_UPDATED_BY NUMBER(15)';
1476   l_index := l_index + 1;
1477   l_header_tbl(l_index) := '    CTX OWNER VARCHAR2(4000)';
1478   l_index := l_index + 1;
1479   l_header_tbl(l_index) := '    BASE LAST_UPDATE_DATE DATE';
1480   l_index := l_index + 1;
1481   l_header_tbl(l_index) := '    BASE LAST_UPDATE_LOGIN NUMBER(15)';
1482   l_index := l_index + 1;
1483   l_header_tbl(l_index) := '    TRANS PROPERTY_VARCHAR2_VALUE_TL VARCHAR2(2000)';
1484   l_index := l_index + 1;
1485   l_header_tbl(l_index) := '  END CUSTOM_REGION';
1486   l_index := l_index + 1;
1487   l_header_tbl(l_index) := ' ';
1488   l_index := l_index + 1;
1489   l_header_tbl(l_index) := '  DEFINE CUSTOM_REGION_ITEM';
1490   l_index := l_index + 1;
1491   l_header_tbl(l_index) := '    KEY ATTRIBUTE_APPLICATION_ID NUMBER(15)';
1492   l_index := l_index + 1;
1493   l_header_tbl(l_index) := '    KEY ATTRIBUTE_CODE VARCHAR2(30)';
1494   l_index := l_index + 1;
1495   l_header_tbl(l_index) := '    KEY PROPERTY_NAME VARCHAR2(30)';
1496   l_index := l_index + 1;
1497   l_header_tbl(l_index) := '    BASE PROPERTY_VARCHAR2_VALUE VARCHAR2(4000)';
1498   l_index := l_index + 1;
1499   l_header_tbl(l_index) := '    BASE PROPERTY_NUMBER_VALUE NUMBER(15)';
1500   l_index := l_index + 1;
1501   l_header_tbl(l_index) := '    BASE PROPERTY_DATE_VALUE DATE';
1502   l_index := l_index + 1;
1503   l_header_tbl(l_index) := '    BASE CREATED_BY NUMBER(15)';
1504   l_index := l_index + 1;
1505   l_header_tbl(l_index) := '    BASE CREATION_DATE DATE';
1506   l_index := l_index + 1;
1507   l_header_tbl(l_index) := '    BASE LAST_UPDATED_BY NUMBER(15)';
1508   l_index := l_index + 1;
1509   l_header_tbl(l_index) := '    CTX OWNER VARCHAR2(4000)';
1510   l_index := l_index + 1;
1511   l_header_tbl(l_index) := '    BASE LAST_UPDATE_DATE DATE';
1512   l_index := l_index + 1;
1513   l_header_tbl(l_index) := '    BASE LAST_UPDATE_LOGIN NUMBER(15)';
1514   l_index := l_index + 1;
1515   l_header_tbl(l_index) := '    TRANS PROPERTY_VARCHAR2_VALUE_TL VARCHAR2(4000)';
1516   l_index := l_index + 1;
1517   l_header_tbl(l_index) := '  END CUSTOM_REGION_ITEM';
1518   l_index := l_index + 1;
1519   l_header_tbl(l_index) := ' ';
1520   l_index := l_index + 1;
1521   l_header_tbl(l_index) := '  DEFINE CRITERIA';
1522   l_index := l_index + 1;
1523   l_header_tbl(l_index) := '    KEY ATTRIBUTE_APPLICATION_ID NUMBER(15)';
1524   l_index := l_index + 1;
1525   l_header_tbl(l_index) := '    KEY ATTRIBUTE_CODE VARCHAR2(30)';
1526   l_index := l_index + 1;
1527   l_header_tbl(l_index) := '    KEY SEQUENCE_NUMBER NUMBER(15)';
1528   l_index := l_index + 1;
1529   l_header_tbl(l_index) := '    BASE OPERATION VARCHAR2(30)';
1530   l_index := l_index + 1;
1531   l_header_tbl(l_index) := '    BASE VALUE_VARCHAR2 VARCHAR2(240)';
1532   l_index := l_index + 1;
1533   l_header_tbl(l_index) := '    BASE VALUE_NUMBER NUMBER(15)';
1534   l_index := l_index + 1;
1535   l_header_tbl(l_index) := '    BASE VALUE_DATE DATE';
1536   l_index := l_index + 1;
1537   l_header_tbl(l_index) := '    BASE START_DATE_ACTIVE DATE';
1538   l_index := l_index + 1;
1539   l_header_tbl(l_index) := '    BASE END_DATE_ACTIVE DATE';
1540   l_index := l_index + 1;
1541   l_header_tbl(l_index) := '    BASE CREATED_BY NUMBER(15)';
1542   l_index := l_index + 1;
1543   l_header_tbl(l_index) := '    BASE CREATION_DATE DATE';
1544   l_index := l_index + 1;
1545   l_header_tbl(l_index) := '    BASE LAST_UPDATED_BY NUMBER(15)';
1546   l_index := l_index + 1;
1547   l_header_tbl(l_index) := '    CTX OWNER VARCHAR2(4000)';
1548   l_index := l_index + 1;
1549   l_header_tbl(l_index) := '    BASE LAST_UPDATE_DATE DATE';
1550   l_index := l_index + 1;
1551   l_header_tbl(l_index) := '    BASE LAST_UPDATE_LOGIN NUMBER(15)';
1552   l_index := l_index + 1;
1553   l_header_tbl(l_index) := '  END CRITERIA';
1554   l_index := l_index + 1;
1555   l_header_tbl(l_index) := 'END CUSTOMIZATION';
1556   l_index := l_index + 1;
1557   l_header_tbl(l_index) := ' ';
1558   end if;
1559 
1560   if (p_download_by_object = AK_ON_OBJECTS_PVT.G_FLOW) then
1561   l_index := l_index + 1;
1562   l_header_tbl(l_index) := 'DEFINE FLOW';
1563   l_index := l_index + 1;
1564   l_header_tbl(l_index) := '  KEY FLOW_APPLICATION_ID NUMBER(15)';
1565   l_index := l_index + 1;
1566   l_header_tbl(l_index) := '  KEY FLOW_CODE VARCHAR2(30)';
1567   l_index := l_index + 1;
1568   l_header_tbl(l_index) := '  BASE PRIMARY_PAGE REFERENCES FLOW_PAGE';
1569   l_index := l_index + 1;
1570   l_header_tbl(l_index) := '  BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
1571   l_index := l_index + 1;
1572   l_header_tbl(l_index) := '  BASE ATTRIBUTE1 VARCHAR2(150)';
1573   l_index := l_index + 1;
1574   l_header_tbl(l_index) := '  BASE ATTRIBUTE2 VARCHAR2(150)';
1575   l_index := l_index + 1;
1576   l_header_tbl(l_index) := '  BASE ATTRIBUTE3 VARCHAR2(150)';
1577   l_index := l_index + 1;
1578   l_header_tbl(l_index) := '  BASE ATTRIBUTE4 VARCHAR2(150)';
1579   l_index := l_index + 1;
1580   l_header_tbl(l_index) := '  BASE ATTRIBUTE5 VARCHAR2(150)';
1581   l_index := l_index + 1;
1582   l_header_tbl(l_index) := '  BASE ATTRIBUTE6 VARCHAR2(150)';
1583   l_index := l_index + 1;
1584   l_header_tbl(l_index) := '  BASE ATTRIBUTE7 VARCHAR2(150)';
1585   l_index := l_index + 1;
1586   l_header_tbl(l_index) := '  BASE ATTRIBUTE8 VARCHAR2(150)';
1587   l_index := l_index + 1;
1588   l_header_tbl(l_index) := '  BASE ATTRIBUTE9 VARCHAR2(150)';
1589   l_index := l_index + 1;
1590   l_header_tbl(l_index) := '  BASE ATTRIBUTE10 VARCHAR2(150)';
1591   l_index := l_index + 1;
1592   l_header_tbl(l_index) := '  BASE ATTRIBUTE11 VARCHAR2(150)';
1593   l_index := l_index + 1;
1594   l_header_tbl(l_index) := '  BASE ATTRIBUTE12 VARCHAR2(150)';
1595   l_index := l_index + 1;
1596   l_header_tbl(l_index) := '  BASE ATTRIBUTE13 VARCHAR2(150)';
1597   l_index := l_index + 1;
1598   l_header_tbl(l_index) := '  BASE ATTRIBUTE14 VARCHAR2(150)';
1599   l_index := l_index + 1;
1600   l_header_tbl(l_index) := '  BASE ATTRIBUTE15 VARCHAR2(150)';
1601   l_index := l_index + 1;
1602   l_header_tbl(l_index) := '  BASE CREATED_BY NUMBER(15)';
1603   l_index := l_index + 1;
1604   l_header_tbl(l_index) := '  BASE CREATION_DATE DATE';
1605   l_index := l_index + 1;
1606   l_header_tbl(l_index) := '  BASE LAST_UPDATED_BY NUMBER(15)';
1607   l_index := l_index + 1;
1608   l_header_tbl(l_index) := '  CTX OWNER VARCHAR2(4000)';
1609   l_index := l_index + 1;
1610   l_header_tbl(l_index) := '  BASE LAST_UPDATE_DATE DATE';
1611   l_index := l_index + 1;
1612   l_header_tbl(l_index) := '  BASE LAST_UPDATE_LOGIN NUMBER(15)';
1613   l_index := l_index + 1;
1614   l_header_tbl(l_index) := '  TRANS NAME VARCHAR2(30)';
1615   l_index := l_index + 1;
1616   l_header_tbl(l_index) := '  TRANS DESCRIPTION VARCHAR2(2000)';
1617   l_index := l_index + 1;
1618   l_header_tbl(l_index) := ' ';
1619   l_index := l_index + 1;
1620   l_header_tbl(l_index) := '  DEFINE FLOW_PAGE';
1621   l_index := l_index + 1;
1622   l_header_tbl(l_index) := '    KEY PAGE_APPLICATION_ID NUMBER(15)';
1623   l_index := l_index + 1;
1624   l_header_tbl(l_index) := '    KEY PAGE_CODE VARCHAR2(30)';
1625   l_index := l_index + 1;
1626   l_header_tbl(l_index) := '    BASE PRIMARY_REGION REFERENCES REGION';
1627   l_index := l_index + 1;
1628   l_header_tbl(l_index) := '    BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
1629   l_index := l_index + 1;
1630   l_header_tbl(l_index) := '    BASE ATTRIBUTE1 VARCHAR2(150)';
1631   l_index := l_index + 1;
1632   l_header_tbl(l_index) := '    BASE ATTRIBUTE2 VARCHAR2(150)';
1633   l_index := l_index + 1;
1634   l_header_tbl(l_index) := '    BASE ATTRIBUTE3 VARCHAR2(150)';
1635   l_index := l_index + 1;
1636   l_header_tbl(l_index) := '    BASE ATTRIBUTE4 VARCHAR2(150)';
1637   l_index := l_index + 1;
1638   l_header_tbl(l_index) := '    BASE ATTRIBUTE5 VARCHAR2(150)';
1639   l_index := l_index + 1;
1640   l_header_tbl(l_index) := '    BASE ATTRIBUTE6 VARCHAR2(150)';
1641   l_index := l_index + 1;
1642   l_header_tbl(l_index) := '    BASE ATTRIBUTE7 VARCHAR2(150)';
1643   l_index := l_index + 1;
1644   l_header_tbl(l_index) := '    BASE ATTRIBUTE8 VARCHAR2(150)';
1645   l_index := l_index + 1;
1646   l_header_tbl(l_index) := '    BASE ATTRIBUTE9 VARCHAR2(150)';
1647   l_index := l_index + 1;
1648   l_header_tbl(l_index) := '    BASE ATTRIBUTE10 VARCHAR2(150)';
1649   l_index := l_index + 1;
1650   l_header_tbl(l_index) := '    BASE ATTRIBUTE11 VARCHAR2(150)';
1651   l_index := l_index + 1;
1652   l_header_tbl(l_index) := '    BASE ATTRIBUTE12 VARCHAR2(150)';
1653   l_index := l_index + 1;
1654   l_header_tbl(l_index) := '    BASE ATTRIBUTE13 VARCHAR2(150)';
1655   l_index := l_index + 1;
1656   l_header_tbl(l_index) := '    BASE ATTRIBUTE14 VARCHAR2(150)';
1657   l_index := l_index + 1;
1658   l_header_tbl(l_index) := '    BASE ATTRIBUTE15 VARCHAR2(150)';
1659   l_index := l_index + 1;
1660   l_header_tbl(l_index) := '    BASE CREATED_BY NUMBER(15)';
1661   l_index := l_index + 1;
1662   l_header_tbl(l_index) := '    BASE CREATION_DATE DATE';
1663   l_index := l_index + 1;
1664   l_header_tbl(l_index) := '    BASE LAST_UPDATED_BY NUMBER(15)';
1665   l_index := l_index + 1;
1666   l_header_tbl(l_index) := '    CTX OWNER VARCHAR2(4000)';
1667   l_index := l_index + 1;
1668   l_header_tbl(l_index) := '    BASE LAST_UPDATE_DATE DATE';
1669   l_index := l_index + 1;
1670   l_header_tbl(l_index) := '    BASE LAST_UPDATE_LOGIN NUMBER(15)';
1671   l_index := l_index + 1;
1672   l_header_tbl(l_index) := '    TRANS NAME VARCHAR2(80)';
1673   l_index := l_index + 1;
1674   l_header_tbl(l_index) := '    TRANS DESCRIPTION VARCHAR2(2000)';
1675   l_index := l_index + 1;
1676   l_header_tbl(l_index) := ' ';
1677   l_index := l_index + 1;
1678   l_header_tbl(l_index) := '    DEFINE FLOW_PAGE_REGION';
1679   l_index := l_index + 1;
1680   l_header_tbl(l_index) := '      KEY FLOW_PAGE_REGION_PK REFERENCES REGION';
1681   l_index := l_index + 1;
1682   l_header_tbl(l_index) := '      BASE DISPLAY_SEQUENCE NUMBER(15)';
1683   l_index := l_index + 1;
1684   l_header_tbl(l_index) := '      BASE REGION_STYLE VARCHAR2(30)';
1685   l_index := l_index + 1;
1686   l_header_tbl(l_index) := '      BASE NUM_COLUMNS NUMBER(15)';
1687   l_index := l_index + 1;
1688   l_header_tbl(l_index) := '      BASE ICX_CUSTOM_CALL VARCHAR2(80)';
1689   l_index := l_index + 1;
1690   l_header_tbl(l_index) := '      BASE PARENT_REGION REFERENCES REGION';
1691   l_index := l_index + 1;
1692   l_header_tbl(l_index) := '      BASE FOREIGN_KEY_NAME REFERENCES FOREIGN_KEY';
1693   l_index := l_index + 1;
1694   l_header_tbl(l_index) := '      BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
1695   l_index := l_index + 1;
1696   l_header_tbl(l_index) := '      BASE ATTRIBUTE1 VARCHAR2(150)';
1697   l_index := l_index + 1;
1698   l_header_tbl(l_index) := '      BASE ATTRIBUTE2 VARCHAR2(150)';
1699   l_index := l_index + 1;
1700   l_header_tbl(l_index) := '      BASE ATTRIBUTE3 VARCHAR2(150)';
1701   l_index := l_index + 1;
1702   l_header_tbl(l_index) := '      BASE ATTRIBUTE4 VARCHAR2(150)';
1703   l_index := l_index + 1;
1704   l_header_tbl(l_index) := '      BASE ATTRIBUTE5 VARCHAR2(150)';
1705   l_index := l_index + 1;
1706   l_header_tbl(l_index) := '      BASE ATTRIBUTE6 VARCHAR2(150)';
1707   l_index := l_index + 1;
1708   l_header_tbl(l_index) := '      BASE ATTRIBUTE7 VARCHAR2(150)';
1709   l_index := l_index + 1;
1710   l_header_tbl(l_index) := '      BASE ATTRIBUTE8 VARCHAR2(150)';
1711   l_index := l_index + 1;
1712   l_header_tbl(l_index) := '      BASE ATTRIBUTE9 VARCHAR2(150)';
1713   l_index := l_index + 1;
1714   l_header_tbl(l_index) := '      BASE ATTRIBUTE10 VARCHAR2(150)';
1715   l_index := l_index + 1;
1716   l_header_tbl(l_index) := '      BASE ATTRIBUTE11 VARCHAR2(150)';
1717   l_index := l_index + 1;
1718   l_header_tbl(l_index) := '      BASE ATTRIBUTE12 VARCHAR2(150)';
1719   l_index := l_index + 1;
1720   l_header_tbl(l_index) := '      BASE ATTRIBUTE13 VARCHAR2(150)';
1721   l_index := l_index + 1;
1722   l_header_tbl(l_index) := '      BASE ATTRIBUTE14 VARCHAR2(150)';
1723   l_index := l_index + 1;
1724   l_header_tbl(l_index) := '      BASE ATTRIBUTE15 VARCHAR2(150)';
1725   l_index := l_index + 1;
1726   l_header_tbl(l_index) := '      BASE CREATED_BY NUMBER(15)';
1727   l_index := l_index + 1;
1728   l_header_tbl(l_index) := '      BASE CREATION_DATE DATE';
1729   l_index := l_index + 1;
1730   l_header_tbl(l_index) := '      BASE LAST_UPDATED_BY NUMBER(15)';
1731   l_index := l_index + 1;
1732   l_header_tbl(l_index) := '      CTX OWNER VARCHAR2(4000)';
1733   l_index := l_index + 1;
1734   l_header_tbl(l_index) := '      BASE LAST_UPDATE_DATE DATE';
1735   l_index := l_index + 1;
1736   l_header_tbl(l_index) := '      BASE LAST_UPDATE_LOGIN NUMBER(15)';
1737   l_index := l_index + 1;
1738   l_header_tbl(l_index) := ' ';
1739   l_index := l_index + 1;
1740   l_header_tbl(l_index) := '      DEFINE FLOW_PAGE_REGION_ITEM';
1741   l_index := l_index + 1;
1742   l_header_tbl(l_index) := '        KEY FLOW_PAGE_REGION_ITEM_PK REFERENCES ATTRIBUTE';
1743   l_index := l_index + 1;
1744   l_header_tbl(l_index) := '        BASE TO_PAGE REFERENCES FLOW_PAGE';
1745   l_index := l_index + 1;
1746   l_header_tbl(l_index) := '        BASE TO_URL_ATTRIBUTE REFERENCES ATTRIBUTE';
1747   l_index := l_index + 1;
1748   l_header_tbl(l_index) := '        BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
1749   l_index := l_index + 1;
1750   l_header_tbl(l_index) := '        BASE ATTRIBUTE1 VARCHAR2(150)';
1751   l_index := l_index + 1;
1752   l_header_tbl(l_index) := '        BASE ATTRIBUTE2 VARCHAR2(150)';
1753   l_index := l_index + 1;
1754   l_header_tbl(l_index) := '        BASE ATTRIBUTE3 VARCHAR2(150)';
1755   l_index := l_index + 1;
1756   l_header_tbl(l_index) := '        BASE ATTRIBUTE4 VARCHAR2(150)';
1757   l_index := l_index + 1;
1758   l_header_tbl(l_index) := '        BASE ATTRIBUTE5 VARCHAR2(150)';
1759   l_index := l_index + 1;
1760   l_header_tbl(l_index) := '        BASE ATTRIBUTE6 VARCHAR2(150)';
1761   l_index := l_index + 1;
1762   l_header_tbl(l_index) := '        BASE ATTRIBUTE7 VARCHAR2(150)';
1763   l_index := l_index + 1;
1764   l_header_tbl(l_index) := '        BASE ATTRIBUTE8 VARCHAR2(150)';
1765   l_index := l_index + 1;
1766   l_header_tbl(l_index) := '        BASE ATTRIBUTE9 VARCHAR2(150)';
1767   l_index := l_index + 1;
1768   l_header_tbl(l_index) := '        BASE ATTRIBUTE10 VARCHAR2(150)';
1769   l_index := l_index + 1;
1770   l_header_tbl(l_index) := '        BASE ATTRIBUTE11 VARCHAR2(150)';
1771   l_index := l_index + 1;
1772   l_header_tbl(l_index) := '        BASE ATTRIBUTE12 VARCHAR2(150)';
1773   l_index := l_index + 1;
1774   l_header_tbl(l_index) := '        BASE ATTRIBUTE13 VARCHAR2(150)';
1775   l_index := l_index + 1;
1776   l_header_tbl(l_index) := '        BASE ATTRIBUTE14 VARCHAR2(150)';
1777   l_index := l_index + 1;
1778   l_header_tbl(l_index) := '        BASE ATTRIBUTE15 VARCHAR2(150)';
1779   l_index := l_index + 1;
1780   l_header_tbl(l_index) := '        BASE CREATED_BY NUMBER(15)';
1781   l_index := l_index + 1;
1782   l_header_tbl(l_index) := '        BASE CREATION_DATE DATE';
1783   l_index := l_index + 1;
1784   l_header_tbl(l_index) := '        BASE LAST_UPDATED_BY NUMBER(15)';
1785   l_index := l_index + 1;
1786   l_header_tbl(l_index) := '        CTX OWNER VARCHAR2(4000)';
1787   l_index := l_index + 1;
1788   l_header_tbl(l_index) := '        BASE LAST_UPDATE_DATE DATE';
1789   l_index := l_index + 1;
1790   l_header_tbl(l_index) := '        BASE LAST_UPDATE_LOGIN NUMBER(15)';
1791   l_index := l_index + 1;
1792   l_header_tbl(l_index) := '      END FLOW_PAGE_REGION_ITEM';
1793   l_index := l_index + 1;
1794   l_header_tbl(l_index) := '    END FLOW_PAGE_REGION';
1795   l_index := l_index + 1;
1796   l_header_tbl(l_index) := '  END FLOW_PAGE';
1797   l_index := l_index + 1;
1798   l_header_tbl(l_index) := ' ';
1799   l_index := l_index + 1;
1800   l_header_tbl(l_index) := '  DEFINE FLOW_REGION_RELATION';
1801   l_index := l_index + 1;
1802   l_header_tbl(l_index) := '    KEY FOREIGN_KEY_NAME REFERENCES FOREIGN_KEY';
1803   l_index := l_index + 1;
1804   l_header_tbl(l_index) := '    KEY FROM_PAGE REFERENCES FLOW_PAGE';
1805   l_index := l_index + 1;
1806   l_header_tbl(l_index) := '    KEY FROM_REGION REFERENCES REGION';
1807   l_index := l_index + 1;
1808   l_header_tbl(l_index) := '    KEY TO_PAGE REFERENCES FLOW_PAGE';
1809   l_index := l_index + 1;
1810   l_header_tbl(l_index) := '    KEY TO_REGION REFERENCES REGION';
1811   l_index := l_index + 1;
1812   l_header_tbl(l_index) := '    BASE APPLICATION_ID NUMBER(15)';
1813   l_index := l_index + 1;
1814   l_header_tbl(l_index) := '    BASE ATTRIBUTE_CATEGORY VARCHAR2(30)';
1815   l_index := l_index + 1;
1816   l_header_tbl(l_index) := '    BASE ATTRIBUTE1 VARCHAR2(150)';
1817   l_index := l_index + 1;
1818   l_header_tbl(l_index) := '    BASE ATTRIBUTE2 VARCHAR2(150)';
1819   l_index := l_index + 1;
1820   l_header_tbl(l_index) := '    BASE ATTRIBUTE3 VARCHAR2(150)';
1821   l_index := l_index + 1;
1822   l_header_tbl(l_index) := '    BASE ATTRIBUTE4 VARCHAR2(150)';
1823   l_index := l_index + 1;
1824   l_header_tbl(l_index) := '    BASE ATTRIBUTE5 VARCHAR2(150)';
1825   l_index := l_index + 1;
1826   l_header_tbl(l_index) := '    BASE ATTRIBUTE6 VARCHAR2(150)';
1827   l_index := l_index + 1;
1828   l_header_tbl(l_index) := '    BASE ATTRIBUTE7 VARCHAR2(150)';
1829   l_index := l_index + 1;
1830   l_header_tbl(l_index) := '    BASE ATTRIBUTE8 VARCHAR2(150)';
1831   l_index := l_index + 1;
1832   l_header_tbl(l_index) := '    BASE ATTRIBUTE9 VARCHAR2(150)';
1833   l_index := l_index + 1;
1834   l_header_tbl(l_index) := '    BASE ATTRIBUTE10 VARCHAR2(150)';
1835   l_index := l_index + 1;
1836   l_header_tbl(l_index) := '    BASE ATTRIBUTE11 VARCHAR2(150)';
1837   l_index := l_index + 1;
1838   l_header_tbl(l_index) := '    BASE ATTRIBUTE12 VARCHAR2(150)';
1839   l_index := l_index + 1;
1840   l_header_tbl(l_index) := '    BASE ATTRIBUTE13 VARCHAR2(150)';
1841   l_index := l_index + 1;
1842   l_header_tbl(l_index) := '    BASE ATTRIBUTE14 VARCHAR2(150)';
1843   l_index := l_index + 1;
1844   l_header_tbl(l_index) := '    BASE ATTRIBUTE15 VARCHAR2(150)';
1845   l_index := l_index + 1;
1846   l_header_tbl(l_index) := '    BASE CREATED_BY NUMBER(15)';
1847   l_index := l_index + 1;
1848   l_header_tbl(l_index) := '    BASE CREATION_DATE DATE';
1849   l_index := l_index + 1;
1850   l_header_tbl(l_index) := '    BASE LAST_UPDATED_BY NUMBER(15)';
1851   l_index := l_index + 1;
1852   l_header_tbl(l_index) := '    CTX OWNER VARCHAR2(4000)';
1853   l_index := l_index + 1;
1854   l_header_tbl(l_index) := '    BASE LAST_UPDATE_DATE DATE';
1855   l_index := l_index + 1;
1856   l_header_tbl(l_index) := '    BASE LAST_UPDATE_LOGIN NUMBER(15)';
1857   l_index := l_index + 1;
1858   l_header_tbl(l_index) := '  END FLOW_REGION_RELATION';
1859   l_index := l_index + 1;
1860   l_header_tbl(l_index) := 'END FLOW';
1861   l_index := l_index + 1;
1862   l_header_tbl(l_index) := ' ';
1863 
1864   end if;
1865   end if; -- the first if for checking Attribute, Flow, Region and Object
1866 
1867   if (p_download_by_object = AK_ON_OBJECTS_PVT.G_SECURITY) then
1868   l_index := l_index + 1;
1869   l_header_tbl(l_index) := 'DEFINE EXCLUDED_ITEMS';
1870   l_index := l_index + 1;
1871   l_header_tbl(l_index) := '  KEY RESPONSIBILITY_ID NUMBER(15)';
1872   l_index := l_index + 1;
1873   l_header_tbl(l_index) := '  KEY RESP_APPLICATION_ID NUMBER(15)';
1874   l_index := l_index + 1;
1875   l_header_tbl(l_index) := '  KEY ATTRIBUTE REFERENCES ATTRIBUTE';
1876   l_index := l_index + 1;
1877   l_header_tbl(l_index) := '  BASE CREATED_BY NUMBER(15)';
1878   l_index := l_index + 1;
1879   l_header_tbl(l_index) := '  BASE CREATION_DATE DATE';
1880   l_index := l_index + 1;
1881   l_header_tbl(l_index) := '  BASE LAST_UPDATED_BY NUMBER(15)';
1882   l_index := l_index + 1;
1883   l_header_tbl(l_index) := '  CTX OWNER VARCHAR2(4000)';
1884   l_index := l_index + 1;
1885   l_header_tbl(l_index) := '  BASE LAST_UPDATE_DATE DATE';
1886   l_index := l_index + 1;
1887   l_header_tbl(l_index) := '  BASE LAST_UPDATE_LOGIN NUMBER(15)';
1888   l_index := l_index + 1;
1889   l_header_tbl(l_index) := 'END EXCLUDED_ITEMS';
1890   l_index := l_index + 1;
1891   l_header_tbl(l_index) := ' ';
1892 
1893   l_index := l_index + 1;
1894   l_header_tbl(l_index) := 'DEFINE RESP_SECURITY_ATTRIBUTES';
1895   l_index := l_index + 1;
1896   l_header_tbl(l_index) := '  KEY RESPONSIBILITY_ID NUMBER(15)';
1897   l_index := l_index + 1;
1898   l_header_tbl(l_index) := '  KEY RESP_APPLICATION_ID NUMBER(15)';
1899   l_index := l_index + 1;
1900   l_header_tbl(l_index) := '  KEY ATTRIBUTE REFERENCES ATTRIBUTE';
1901   l_index := l_index + 1;
1902   l_header_tbl(l_index) := '  BASE CREATED_BY NUMBER(15)';
1903   l_index := l_index + 1;
1904   l_header_tbl(l_index) := '  BASE CREATION_DATE DATE';
1905   l_index := l_index + 1;
1906   l_header_tbl(l_index) := '  BASE LAST_UPDATED_BY NUMBER(15)';
1907   l_index := l_index + 1;
1908   l_header_tbl(l_index) := '  CTX OWNER VARCHAR2(4000)';
1909   l_index := l_index + 1;
1910   l_header_tbl(l_index) := '  BASE LAST_UPDATE_DATE DATE';
1911   l_index := l_index + 1;
1912   l_header_tbl(l_index) := '  BASE LAST_UPDATE_LOGIN NUMBER(15)';
1913   l_index := l_index + 1;
1914   l_header_tbl(l_index) := 'END RESP_SECURITY_ATTRIBUTES';
1915   l_index := l_index + 1;
1916   l_header_tbl(l_index) := ' ';
1917   end if;
1918 
1919   -- Check if the Object type is valid values
1920   if (p_download_by_object = AK_ON_OBJECTS_PVT.G_QUERYOBJ) then
1921 
1922   l_index := l_index + 1;
1923   l_header_tbl(l_index) := 'DEFINE QUERY_OBJECT';
1924   l_index := l_index + 1;
1925   l_header_tbl(l_index) := '  KEY QUERY_CODE VARCHAR2(30)';
1926   l_index := l_index + 1;
1927   l_header_tbl(l_index) := '  BASE APPLICATION_ID NUMBER(15)';
1928   l_index := l_index + 1;
1929   l_header_tbl(l_index) := '  BASE CREATED_BY NUMBER(15)';
1930   l_index := l_index + 1;
1931   l_header_tbl(l_index) := '  BASE CREATION_DATE DATE';
1932   l_index := l_index + 1;
1933   l_header_tbl(l_index) := '  BASE LAST_UPDATED_BY NUMBER(15)';
1934   l_index := l_index + 1;
1935   l_header_tbl(l_index) := '  CTX OWNER VARCHAR2(4000)';
1936   l_index := l_index + 1;
1937   l_header_tbl(l_index) := '  BASE LAST_UPDATE_DATE DATE';
1938   l_index := l_index + 1;
1939   l_header_tbl(l_index) := '  BASE LAST_UPDATE_LOGIN NUMBER(15)';
1940   l_index := l_index + 1;
1941   l_header_tbl(l_index) := ' ';
1942   l_index := l_index + 1;
1943   l_header_tbl(l_index) := '  DEFINE QUERY_OBJECT_LINE';
1944   l_index := l_index + 1;
1945   l_header_tbl(l_index) := '    KEY SEQ_NUM NUMBER(15)';
1946   l_index := l_index + 1;
1947   l_header_tbl(l_index) := '    BASE QUERY_LINE_TYPE VARCHAR2(30)';
1948   l_index := l_index + 1;
1949   l_header_tbl(l_index) := '    BASE QUERY_LINE VARCHAR2(4000)';
1950   l_index := l_index + 1;
1951   l_header_tbl(l_index) := '    BASE LINKED_PARAMETER VARCHAR2(30)';
1952   l_index := l_index + 1;
1953   l_header_tbl(l_index) := '    BASE CREATED_BY NUMBER(15)';
1954   l_index := l_index + 1;
1955   l_header_tbl(l_index) := '    BASE CREATION_DATE DATE';
1956   l_index := l_index + 1;
1957   l_header_tbl(l_index) := '    BASE LAST_UPDATED_BY NUMBER(15)';
1958   l_index := l_index + 1;
1959   l_header_tbl(l_index) := '    CTX OWNER VARCHAR2(4000)';
1960   l_index := l_index + 1;
1961   l_header_tbl(l_index) := '    BASE LAST_UPDATE_DATE DATE';
1962   l_index := l_index + 1;
1963   l_header_tbl(l_index) := '    BASE LAST_UPDATE_LOGIN NUMBER(15)';
1964   l_index := l_index + 1;
1965   l_header_tbl(l_index) := '  END QUERY_OBJECT_LINE';
1966   l_index := l_index + 1;
1967   l_header_tbl(l_index) := 'END QUERY_OBJECT';
1968   l_index := l_index + 1;
1969   l_header_tbl(l_index) := ' ';
1970 
1971   end if; -- if G_QUERYOBJ
1972 
1973   -- Check if the Object type is valid values
1974   if (p_download_by_object = AK_ON_OBJECTS_PVT.G_AMPARAM_REGISTRY) then
1975 
1976   l_index := l_index + 1;
1977   l_header_tbl(l_index) := 'DEFINE AMPARAM_REGISTRY';
1978   l_index := l_index + 1;
1979   l_header_tbl(l_index) := '  KEY  APPLICATIONMODULE_DEFN_NAME VARCHAR2(240)';
1980   l_index := l_index + 1;
1981   l_header_tbl(l_index) := '  KEY  PARAM_NAME VARCHAR2(80)';
1982   l_index := l_index + 1;
1983   l_header_tbl(l_index) := '  KEY  PARAM_SOURCE VARCHAR2(30)';
1984   l_index := l_index + 1;
1985   l_header_tbl(l_index) := '  BASE APPLICATION_ID NUMBER(15)';
1986   l_index := l_index + 1;
1987   l_header_tbl(l_index) := 'END AMPARAM_REGISTRY';
1988   l_index := l_index + 1;
1989   l_header_tbl(l_index) := ' ';
1990 
1991   end if; -- if G_AMPARAM_REGISTRY
1992 
1993   l_index := l_index + 1;
1994   l_header_tbl(l_index) := ' ';
1995 
1996   --
1997   -- Write the header information out to the flat file
1998   --
1999   AK_ON_OBJECTS_PVT.WRITE_FILE (
2000     p_return_status => l_return_status,
2001     p_buffer_tbl => l_header_tbl,
2002     p_write_mode => AK_ON_OBJECTS_PUB.G_OVERWRITE
2003   );
2004   if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
2005      (l_return_status = FND_API.G_RET_STS_ERROR) then
2006     --dbms_output.put_line(G_PKG_NAME || ': first write_File failed');
2007     RAISE FND_API.G_EXC_ERROR;
2008   end if;
2009 
2010   --
2011   -- Load output parameters and set return status to success
2012   --
2013   p_nls_language_out := l_nls_language;
2014   p_application_id_out := l_application_id;
2015   p_return_status := FND_API.G_RET_STS_SUCCESS;
2016 
2017 EXCEPTION
2018   WHEN FND_API.G_EXC_ERROR THEN
2019     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2020       FND_MESSAGE.SET_NAME('AK','AK_HEADER_DOWNLOAD_ERROR');
2021       FND_MSG_PUB.Add;
2022     end if;
2023     p_return_status := FND_API.G_RET_STS_ERROR;
2024   WHEN OTHERS THEN
2025     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2026     FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name,
2027                            SUBSTR (SQLERRM, 1, 240) );
2028 end DOWNLOAD_HEADER;
2029 
2030 --==============================================
2031 --  Procedure   UPLOAD
2032 --
2033 --  Usage       Private API for loading flows, objects, regions,
2034 --              and attributes from a loader file to the database.
2035 --              This procedure is intended to be called only by other APIs
2036 --              that are owned by the Core Modules Team (AK)
2037 --
2038 --  Desc        This API parses the header information and the DEFINE
2039 --              section, and calls the appropriate private API to read
2040 --              in all flow, object, region, attribute, security
2041 --				and query object data
2042 --              (including all the tables in these business objects)
2043 --              from the loader file, and update them to the database.
2044 --
2045 --  Results     The API returns the standard p_return_status parameter
2046 --              indicating one of the standard return statuses :
2047 --                  * Unexpected error
2048 --                  * Error
2049 --                  * Success
2050 --  Parameters
2051 --==============================================
2052 procedure UPLOAD (
2053   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
2054   p_api_version_number       IN      NUMBER,
2055   p_init_msg_tbl             IN      BOOLEAN := FALSE,
2056   p_msg_count                OUT NOCOPY     NUMBER,
2057   p_msg_data                 OUT NOCOPY     VARCHAR2,
2058   p_return_status            OUT NOCOPY     VARCHAR2
2059 ) is
2060   l_upl_loader_cur       AK_ON_OBJECTS_PUB.LoaderCurTyp;	-- Cursor for upload
2061   l_api_version_number   CONSTANT number := 1.0;
2062   l_api_name             CONSTANT varchar2(30) := 'Upload';
2063   l_attribute_index      NUMBER := 0;
2064   l_attribute_index_tbl  Index_Tbl_Type;
2065   l_buffer_tbl           AK_ON_OBJECTS_PUB.Buffer_Tbl_Type;
2066   l_buffer               AK_ON_OBJECTS_PUB.Buffer_Type;
2067   l_buffer2              AK_ON_OBJECTS_PUB.Buffer_Type;
2068   l_column               varchar2(30);
2069   l_dummy                NUMBER;
2070   l_eof_flag             varchar2(1);
2071   l_extract_by_obj       varchar2(20);
2072   l_index                NUMBER;
2073   l_language             varchar2(30);
2074   l_line_num             NUMBER;
2075   l_line_num2            NUMBER;
2076   l_lines_read           NUMBER;
2077   l_object_index         NUMBER := 0;
2078   l_object_index_tbl     Index_Tbl_Type;
2079   l_object_name          varchar2(30);
2080   l_return_status        varchar2(1);
2081   l_state                NUMBER;
2082   l_timestamp            DATE := sysdate;
2083   l_token                AK_ON_OBJECTS_PUB.Buffer_Type;
2084   l_tbl_index            NUMBER;
2085   l_file_version         NUMBER;
2086   l_validation_level     NUMBER := FND_API.G_VALID_LEVEL_FULL;
2087   l_not_compatible_version	 BOOLEAN := TRUE;
2088   i						 NUMBER;
2089 begin
2090   IF NOT FND_API.Compatible_API_Call (
2091     l_api_version_number, p_api_version_number, l_api_name,
2092     G_PKG_NAME) then
2093       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2094       return;
2095   END IF;
2096 
2097   -- Initialize the message table if requested.
2098 
2099   if p_init_msg_tbl then
2100     FND_MSG_PUB.initialize;
2101   end if;
2102 
2103 --dbms_output.put_line(to_char(l_timestamp));
2104 
2105   -- Get total number of records in AK_LOADER_TEMP
2106   --
2107     select count(*) into G_UPL_TABLE_NUM
2108 	from AK_LOADER_TEMP;
2109 
2110 	l_lines_read := 0;
2111 
2112   --
2113   -- Retrieve the first non-blank, non-comment line
2114   --
2115   l_state := 0;
2116   l_eof_flag := 'N';
2117   l_buffer := null;
2118   l_line_num := 0;
2119   l_tbl_index := 0;
2120 
2121   --
2122   -- Process 2 times to make sure all forward dependencies could be
2123   -- resolved
2124   --
2125   -- First pass:
2126   l_index := 1;
2127 
2128   --dbms_output.put_line('**** Processing pass # ' || to_char(l_index) || ' ****');
2129 
2130   -- Open Upload Loader Cursor
2131   OPEN l_upl_loader_cur	FOR SELECT TBL_INDEX,LINE_CONTENT FROM ak_loader_temp
2132   where session_id = AK_ON_OBJECTS_PVT.G_SESSION_ID
2133   order by tbl_index;
2134 
2135   while (l_buffer is null and l_eof_flag = 'N' and l_tbl_index <=  G_UPL_TABLE_NUM) loop
2136     AK_ON_OBJECTS_PVT.READ_LINE (
2137         p_return_status => l_return_status,
2138         p_index => l_tbl_index,
2139         p_buffer => l_buffer,
2140         p_lines_read => l_lines_read,
2141         p_eof_flag => l_eof_flag,
2142 		p_upl_loader_cur => l_upl_loader_cur
2143     );
2144 
2145     if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
2146        (l_return_status = FND_API.G_RET_STS_ERROR) then
2147         RAISE FND_API.G_EXC_ERROR;
2148     end if;
2149     l_line_num := l_line_num + l_lines_read;
2150 
2151     --
2152     -- discard comment lines
2153     --
2154       --
2155       -- trim leading spaces and discard comment lines
2156       --
2157     l_buffer := LTRIM(l_buffer);
2158     if (SUBSTR(l_buffer, 1, 1) = '#') then
2159         if (SUBSTR(l_buffer, 3,12) = 'Generated on') then
2160           AK_UPLOAD_GRP.G_GEN_DATE:= to_date(substr(l_buffer,16),'RR/MM/DD HH24:MI:SS');
2161         end if;
2162       l_buffer := null;
2163     end if;
2164   end loop;
2165 
2166   if (AK_UPLOAD_GRP.G_GEN_DATE is null) then
2167     AK_UPLOAD_GRP.G_GEN_DATE := l_timestamp;
2168   end if;
2169 
2170   --
2171   -- if we cannot even get one non-blank, non-comment line from
2172   -- the file, there is nothing to be processed in this file
2173   --
2174   if (l_buffer is null and l_eof_flag = 'Y' and l_tbl_index = G_UPL_TABLE_NUM) then
2175     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2176       FND_MESSAGE.SET_NAME('AK','AK_EMPTY_FILE');
2177       FND_MSG_PUB.Add;
2178     end if;
2179     RAISE FND_API.G_EXC_ERROR;
2180   end if;
2181 
2182   --
2183   -- Parse the buffer read to obtain header information such as
2184   -- language and codeset
2185   --
2186   while (l_eof_flag = 'N') and (l_buffer is not null) loop
2187     --
2188     -- - get next token from buffer
2189     --
2190 
2191     AK_ON_OBJECTS_PVT.GET_TOKEN(
2192       p_return_status => l_return_status,
2193       p_in_buf => l_buffer,
2194       p_token => l_token
2195     );
2196 
2197     if (l_return_status = FND_API.G_RET_STS_ERROR) or
2198        (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) then
2199       if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2200         FND_MESSAGE.SET_NAME('AK','AK_GET_TOKEN_ERROR');
2201         FND_MSG_PUB.Add;
2202       end if;
2203       raise FND_API.G_EXC_ERROR;
2204     end if;
2205     --dbms_output.put_line(' State:' || l_state || 'Token:' || l_token);
2206 
2207     --
2208     -- - process token
2209     --
2210     if (l_state = 0) then
2211       if (l_token = 'BEGIN') then
2212         --
2213         -- Check for missing header info
2214         -- Language and codeset, and extract_by_object are required.
2215         --
2216         if (l_language is null) or (l_extract_by_obj is null) then
2217           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2218             FND_MESSAGE.SET_NAME('AK','AK_HEADER_INFO_MISSING');
2219             FND_MSG_PUB.Add;
2220           end if;
2221           raise FND_API.G_EXC_ERROR;
2222         else
2223 --  dbms_output.put_line('l_language is ' || l_language);
2224 --  dbms_output.put_line('l_extract_by_obj is ' || l_extract_by_obj);
2225           l_state := 3;
2226         end if;
2227       elsif (l_token = 'LANGUAGE') or
2228             (l_token = 'EXTRACT_BY_OBJECT') or
2229             (l_token = 'FILE_FORMAT_VERSION') then
2230         l_column := l_token;
2231         l_state := 1;
2232       elsif (l_token = 'DEFINE') then
2233         l_state := 10;
2234       else
2235         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2236           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2237           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2238           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2239           FND_MESSAGE.SET_TOKEN('EXPECTED','BEGIN, LANGUAGE, CODESET, ' ||
2240                                 'EXTRACT_BY_OBJECT, EXTRACT_BY_APPLICATION');
2241           FND_MSG_PUB.Add;
2242         end if;
2243         raise FND_API.G_EXC_ERROR;
2244       end if; -- endif of (l_token = 'BEGIN')
2245     elsif (l_state = 1) then
2246       if (l_token = '=') then
2247         l_state := 2;
2248       else
2249         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2250           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2251           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2252           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2253           FND_MESSAGE.SET_TOKEN('EXPECTED','=');
2254           FND_MSG_PUB.Add;
2255         end if;
2256         --dbms_output.put_line('Expecting =');
2257         raise FND_API.G_EXC_ERROR;
2258       end if;
2259     elsif (l_state = 2) then
2260       if (l_column = 'LANGUAGE') then
2261         l_language := UPPER(l_token);
2262       elsif (l_column = 'EXTRACT_BY_OBJECT') then
2263         if (UPPER(l_token) NOT IN (AK_ON_OBJECTS_PVT.G_ATTRIBUTE,
2264                                    AK_ON_OBJECTS_PVT.G_FLOW,
2265                                    AK_ON_OBJECTS_PVT.G_OBJECT,
2266                                    AK_ON_OBJECTS_PVT.G_REGION,
2267 				   AK_ON_OBJECTS_PVT.G_CUSTOM_REGION,
2268                                    AK_ON_OBJECTS_PVT.G_SECURITY,
2269                                    AK_ON_OBJECTS_PVT.G_QUERYOBJ,
2270 				   AK_ON_OBJECTS_PVT.G_AMPARAM_REGISTRY) ) then
2271           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2272             FND_MESSAGE.SET_NAME('AK','AK_INVALID_COLUMN_VALUE');
2273             FND_MESSAGE.SET_TOKEN('COLUMN','EXTRACT_BY_OBJECT');
2274             FND_MSG_PUB.Add;
2275           end if;
2276           raise FND_API.G_EXC_ERROR;
2277         else
2278           l_extract_by_obj := UPPER(l_token);
2279 	  AK_UPLOAD_GRP.G_EXTRACT_OBJ := l_extract_by_obj;
2280         end if;
2281       elsif (l_column = 'FILE_FORMAT_VERSION') then
2282 	l_file_version := to_number(l_token);
2283 	 AK_ON_OBJECTS_PUB.G_UPLOAD_FILE_VERSION := l_file_version;
2284 	if ( l_file_version <> AK_ON_OBJECTS_PUB.G_FILE_FORMAT_VER and
2285 		l_file_version <> AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER1 and
2286 		l_file_version <> AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER2 and
2287 		l_file_version <> AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER3 and
2288 		l_file_version <> AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER4 and
2289 		l_file_version <> AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER5 and
2290 		l_file_version <> AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER6 and
2291 		l_file_version <> AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER7 and
2292 		l_file_version <> AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER8 and
2293 		l_file_version <> AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER9 and
2294 		l_file_version <> AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER10 and
2295 		l_file_version <> AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER11 and
2296 		l_file_version <> AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER12 and
2297 		l_file_version <> AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER14 and
2298                 l_file_version <> AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER15) then
2299           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2300             FND_MESSAGE.SET_NAME('AK','AK_WRONG_FILE_VERSION');
2301             FND_MSG_PUB.Add;
2302           end if;
2303           raise FND_API.G_EXC_ERROR;
2304 	end if; -- end if l_file_version
2305       else
2306         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2307           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
2308           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2309           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2310           FND_MESSAGE.SET_TOKEN('EXPECTED',l_column);
2311           FND_MSG_PUB.Add;
2312         end if;
2313         -- dbms_output.put_line('Expecting ' || l_column || ' value');
2314         raise FND_API.G_EXC_ERROR;
2315       end if;
2316       l_state := 0;
2317     elsif (l_state = 4) then
2318       if (l_token = 'BEGIN') then
2319         l_state := 5;
2320       else
2321         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2322           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2323           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2324           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2325           FND_MESSAGE.SET_TOKEN('EXPECTED','BEGIN');
2326           FND_MSG_PUB.Add;
2327         end if;
2328         -- dbms_output.put_line('Expecting BEGIN');
2329         raise FND_API.G_EXC_ERROR;
2330       end if;
2331     elsif (l_state = 3) or (l_state = 5) then
2332       if (l_token = 'ATTRIBUTE') then
2333         -- call ak_attribute_pvt.upload --
2334         -- dbms_output.put_line('Calling attribute upload: ' ||
2335         --                      to_char(sysdate, 'MON-DD HH24:MI:SS'));
2336         --
2337         -- Update index table for attribute. Since some attributes refer
2338         -- to LOV objects which do not exists yet, we will need to remember
2339         -- where the ATTRIBUTE object begins so that we can upload it to
2340         -- the database again once all objects have been uploaded.
2341         --
2342         l_attribute_index := l_attribute_index + 1;
2343         l_attribute_index_tbl(l_attribute_index) :=G_buffer_tbl.prior(l_index);
2344         --
2345         -- Upload attribute information to the database
2346         --
2347         AK_ATTRIBUTE_PVT.UPLOAD_ATTRIBUTE (
2348           p_validation_level => l_validation_level,
2349           p_api_version_number => 1.0,
2350           p_return_status => l_return_status,
2351           p_index => l_tbl_index,
2352           p_loader_timestamp => l_timestamp,
2353           p_line_num => l_line_num,
2354           p_buffer => l_buffer,
2355  	  p_line_num_out => l_line_num2,
2356 	  p_buffer_out => l_buffer2,
2357 		  p_upl_loader_cur => l_upl_loader_cur,
2358 		  p_pass => l_index
2359         );
2360 	l_buffer := l_buffer2;
2361 	l_line_num := l_line_num2;
2362 
2363         if (l_return_status = FND_API.G_RET_STS_ERROR) or
2364          (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) then
2365          raise FND_API.G_EXC_ERROR;
2366 		else
2367 		  -- commit the changes from uploading attribute
2368 		  commit;
2369         end if;
2370 -- dbms_output.put_line('l_buffer returned: ' || l_buffer);
2371       elsif (l_token = 'OBJECT') then
2372         -- call ak_object_pvt.upload --
2373         -- dbms_output.put_line('Calling object upload: ' ||
2374         --                      to_char(sysdate, 'MON-DD HH24:MI:SS'));
2375         --
2376         -- Update index table for object. Since some attribute navigation
2377         -- records refer to target regions which do not exists yet,
2378         -- we will need to remembewhere the OBJECT object begins so that we
2379         -- can upload them to the database again once all regions have been
2380         -- uploaded.
2381         --
2382         l_object_index := l_object_index + 1;
2383         l_object_index_tbl(l_object_index) :=G_buffer_tbl.prior(l_index);
2384         --
2385         -- Upload attribute information to the database
2386         --
2387         AK_OBJECT3_PVT.UPLOAD_OBJECT (
2388           p_validation_level => l_validation_level,
2389           p_api_version_number => 1.0,
2390           p_return_status => l_return_status,
2391           p_index => l_tbl_index,
2392           p_loader_timestamp => l_timestamp,
2393           p_line_num => l_line_num,
2394           p_buffer => l_buffer,
2395 	  p_line_num_out => l_line_num2,
2396 	  p_buffer_out => l_buffer2,
2397 		  p_upl_loader_cur => l_upl_loader_cur,
2398 		  p_pass => l_index
2399         );
2400         l_buffer := l_buffer2;
2401         l_line_num := l_line_num2;
2402         --dbms_output.put_line('Return from Upload Object to UPLOAD, return status = '||l_return_status);
2403         if (l_return_status = FND_API.G_RET_STS_ERROR) or
2404          (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) then
2405          raise FND_API.G_EXC_ERROR;
2406 		else
2407 		  -- commit the changes from uploading object
2408 		  commit;
2409         end if;
2410 
2411       elsif (l_token = 'REGION') then
2412         -- call ak_region_pvt.upload --
2413         -- dbms_output.put_line('Calling region upload:'  ||
2414         --                      to_char(sysdate, 'MON-DD HH24:MI:SS'));
2415         AK_REGION2_PVT.UPLOAD_REGION (
2416           p_validation_level => l_validation_level,
2417           p_api_version_number => 1.0,
2418           p_return_status => l_return_status,
2419           p_index => l_tbl_index,
2420           p_loader_timestamp => l_timestamp,
2421           p_line_num => l_line_num,
2422           p_buffer => l_buffer,
2423 	  p_line_num_out => l_line_num2,
2424 	  p_buffer_out => l_buffer2,
2425 		  p_upl_loader_cur => l_upl_loader_cur,
2426 		  p_pass => l_index
2427         );
2428         l_buffer := l_buffer2;
2429         l_line_num := l_line_num2;
2430  -- dbms_output.put_line('l_buffer returned: ' || l_buffer);
2431         if (l_return_status = FND_API.G_RET_STS_ERROR) or
2432          (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) then
2433          raise FND_API.G_EXC_ERROR;
2434 		else
2435 		  -- commit the changes from uploading region
2436 		  commit;
2437         end if;
2438 
2439       elsif (l_token = 'CUSTOMIZATION') then
2440         AK_CUSTOM2_PVT.UPLOAD_CUSTOM (
2441           p_validation_level => l_validation_level,
2442           p_api_version_number => 1.0,
2443           p_return_status => l_return_status,
2444           p_index => l_tbl_index,
2445           p_loader_timestamp => l_timestamp,
2446           p_line_num => l_line_num,
2447           p_buffer => l_buffer,
2448 	  p_line_num_out => l_line_num2,
2449 	  p_buffer_out => l_buffer2,
2450                   p_upl_loader_cur => l_upl_loader_cur,
2451                   p_pass => l_index
2452         );
2453         l_buffer := l_buffer2;
2454         l_line_num := l_line_num2;
2455         if (l_return_status = FND_API.G_RET_STS_ERROR) or
2456          (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) then
2457          raise FND_API.G_EXC_ERROR;
2458 		else
2459 		  -- commit the changes from uploading customization
2460 		  commit;
2461         end if;
2462 
2463       elsif (l_token = 'FLOW') then
2464         -- call ak_flow_pvt.upload --
2465         -- dbms_output.put_line('Calling flow upload:' ||
2466         --                      to_char(sysdate, 'MON-DD HH24:MI:SS'));
2467         AK_FLOW2_PVT.UPLOAD_FLOW (
2468           p_validation_level => l_validation_level,
2469           p_api_version_number => 1.0,
2470           p_return_status => l_return_status,
2471           p_index => l_tbl_index,
2472           p_loader_timestamp => l_timestamp,
2473           p_line_num => l_line_num,
2474           p_buffer => l_buffer,
2475           p_line_num_out => l_line_num2,
2476 	  p_buffer_out => l_buffer2,
2477 		  p_upl_loader_cur => l_upl_loader_cur,
2478 		  p_pass => l_index
2479         );
2480         l_buffer := l_buffer2;
2481         l_line_num := l_line_num2;
2482 		-- dbms_output.put_line('Returning from flow upload: '||
2483         --                      to_char(sysdate, 'MON-DD HH24:MI:SS')||' status: '||l_return_status);
2484         if (l_return_status = FND_API.G_RET_STS_ERROR) or
2485          (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) then
2486          raise FND_API.G_EXC_ERROR;
2487 		else
2488 		  -- commit the changes from uploading flow
2489 		  commit;
2490         end if;
2491 
2492       elsif (l_token = 'EXCLUDED_ITEMS' or l_token = 'RESP_SECURITY_ATTRIBUTES') then
2493         -- call ak_flow_pvt.upload --
2494         -- dbms_output.put_line('Calling security upload:' ||
2495         --                      to_char(sysdate, 'MON-DD HH24:MI:SS'));
2496         -- There's no need to pass SECURITY two times since there's
2497 		-- no forward references problem in it
2498 		--
2499         AK_SECURITY_PVT.UPLOAD_SECURITY (
2500           p_validation_level => l_validation_level,
2501           p_api_version_number => 1.0,
2502           p_return_status => l_return_status,
2503           p_index => l_tbl_index,
2504           p_loader_timestamp => l_timestamp,
2505           p_line_num => l_line_num,
2506           p_buffer => l_token ||' '||l_buffer,
2507 	  p_line_num_out => l_line_num2,
2508 	  p_buffer_out => l_buffer2,
2509 		  p_upl_loader_cur => l_upl_loader_cur
2510         );
2511         l_buffer := l_buffer2;
2512         l_line_num := l_line_num2;
2513         if (l_return_status = FND_API.G_RET_STS_ERROR) or
2514          (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) then
2515          raise FND_API.G_EXC_ERROR;
2516 		else
2517 		  -- commit the changes from uploading security
2518 		  commit;
2519         end if;
2520 
2521       elsif (l_token = 'QUERY_OBJECT') then
2522         -- call ak_region_pvt.upload --
2523         -- dbms_output.put_line('Calling query object upload:'  ||
2524         --                      to_char(sysdate, 'MON-DD HH24:MI:SS'));
2525         AK_QUERYOBJ_PVT.UPLOAD_QUERY_OBJECT (
2526           p_validation_level => l_validation_level,
2527           p_api_version_number => 1.0,
2528           p_return_status => l_return_status,
2529           p_index => l_tbl_index,
2530           p_loader_timestamp => l_timestamp,
2531           p_line_num => l_line_num,
2532           p_buffer => l_buffer,
2533 	  p_line_num_out => l_line_num2,
2534 	  p_buffer_out => l_buffer2,
2535 		  p_upl_loader_cur => l_upl_loader_cur,
2536 		  p_pass => l_index
2537         );
2538         l_buffer := l_buffer2;
2539         l_line_num := l_line_num2;
2540  -- dbms_output.put_line('l_buffer returned: ' || l_buffer);
2541         if (l_return_status = FND_API.G_RET_STS_ERROR) or
2542          (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) then
2543          raise FND_API.G_EXC_ERROR;
2544 		else
2545 		  -- commit the changes from uploading query object
2546 		  commit;
2547         end if;
2548 
2549       elsif (l_token = 'AMPARAM_REGISTRY') then
2550         --
2551         -- Upload amparm_registry information to the database
2552         --
2553         AK_AMPARAM_REGISTRY_PVT.UPLOAD_AMPARAM_REGISTRY (
2554           p_validation_level => l_validation_level,
2555           p_api_version_number => 1.0,
2556           p_return_status => l_return_status,
2557           p_index => l_tbl_index,
2558           p_loader_timestamp => l_timestamp,
2559           p_line_num => l_line_num,
2560           p_buffer => l_buffer,
2561 	  p_line_num_out => l_line_num2,
2562 	  p_buffer_out => l_buffer2,
2563 		  p_upl_loader_cur => l_upl_loader_cur,
2564 		  p_pass => l_index
2565         );
2566         l_buffer := l_buffer2;
2567         l_line_num := l_line_num2;
2568         --dbms_output.put_line('Return from Upload Object to UPLOAD, return status = '||l_return_status);
2569         if (l_return_status = FND_API.G_RET_STS_ERROR) or
2570          (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) then
2571          raise FND_API.G_EXC_ERROR;
2572 		else
2573 		  -- commit the changes from uploading amparam_registry
2574 		  commit;
2575         end if;
2576 
2577       else
2578 --        dbms_output.put_line('Expecting ATTRIBUTE, OBJECT, REGION, FLOW,
2579 --          EXCLUDED_ITEMS or RESP_SECURITY_ATTRIBUTES');
2580         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2581           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2582           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2583           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2584           FND_MESSAGE.SET_TOKEN('EXPECTED','ATTRIBUTE, OBJECT, REGION,
2585             FLOW, EXCLUDED_ITEMS, RESP_SECURITY_ATTRIBUTES OR QUERY_OBJECT');
2586           FND_MSG_PUB.Add;
2587         end if;
2588         raise FND_API.G_EXC_ERROR;
2589       end if;
2590       l_state := 4;
2591 --      l_buffer := '';  /* clears buffer so a different line will be read */
2592     elsif (l_state = 10) then
2593       l_object_name := l_token;
2594       l_state := 11;
2595     elsif (l_state = 11) then
2596       --
2597       -- ignores all tokens except END and BEGIN
2598       --
2599       if (l_token = 'END') then
2600         l_state := 12;
2601       elsif (l_token = 'BEGIN') then
2602         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2603           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2604           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2605           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2606           FND_MESSAGE.SET_TOKEN('EXPECTED', 'END ' || l_object_name);
2607           FND_MSG_PUB.Add;
2608         end if;
2609         raise FND_API.G_EXC_ERROR;
2610       end if;
2611     elsif (l_state = 12) then
2612       if (l_token = l_object_name) then
2613         l_state := 0;
2614       else
2615         l_state := 11;
2616       end if;
2617     end if;
2618 
2619     --
2620     -- Get rid of leading white spaces, so that buffer would become
2621     -- null if the only thing in it are white spaces
2622     --
2623     l_buffer := LTRIM(l_buffer);
2624 
2625     --
2626     -- Get the next non-blank, non-comment line if current line is
2627     -- fully parsed
2628     --
2629     while (l_buffer is null and l_eof_flag = 'N' and l_tbl_index <=  G_UPL_TABLE_NUM) loop
2630       AK_ON_OBJECTS_PVT.READ_LINE (
2631         p_return_status => l_return_status,
2632         p_index => l_tbl_index,
2633         p_buffer => l_buffer,
2634         p_lines_read => l_lines_read,
2635         p_eof_flag => l_eof_flag,
2636 		p_upl_loader_cur => l_upl_loader_cur
2637       );
2638       if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
2639          (l_return_status = FND_API.G_RET_STS_ERROR) then
2640           RAISE FND_API.G_EXC_ERROR;
2641       end if;
2642       l_line_num := l_line_num + l_lines_read;
2643       --
2644       -- trim leading spaces and discard comment lines
2645       --
2646       l_buffer := LTRIM(l_buffer);
2647       if (SUBSTR(l_buffer, 1, 1) = '#') then
2648         l_buffer := null;
2649       end if;
2650     end loop;
2651 
2652   end loop; -- End of while loop
2653 
2654   close l_upl_loader_cur; -- Close Upload cursor
2655 
2656   --
2657   -- Write a '# lines processed message' to the message stack
2658   --
2659 --  dbms_output.put_line(to_char(l_line_num) || ' lines processed.');
2660 --  FND_MESSAGE.SET_NAME('AK','AK_LINES_PROCESSED');
2661 --  FND_MESSAGE.SET_TOKEN('NUMLINES', to_char(l_line_num));
2662 --  FND_MSG_PUB.Add;
2663 
2664   -- ************* Starts second pass *****************
2665 
2666   l_index := 2;
2667   --
2668   -- Write message informing user whether this is the first pass or the
2669   -- second pass at reading the input file
2670   --
2671   FND_MESSAGE.SET_NAME('AK','AK_UPLOAD_PASS2' || to_char(l_index));
2672   FND_MSG_PUB.Add;
2673 
2674   AK_ATTRIBUTE_PVT.UPLOAD_ATTRIBUTE_SECOND (
2675     p_validation_level => p_validation_level,
2676     p_return_status => l_return_status,
2677     p_loader_timestamp => l_timestamp,
2678 	p_pass => l_index
2679   );
2680   -- If API call returns with an error status, upload aborts
2681   if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
2682      (l_return_status = FND_API.G_RET_STS_ERROR) then
2683     RAISE FND_API.G_EXC_ERROR;
2684   end if; -- /* if l_return_status */
2685 
2686   AK_OBJECT2_PVT.UPLOAD_OBJECT_SECOND (
2687     p_validation_level => p_validation_level,
2688     p_return_status => l_return_status,
2689     p_loader_timestamp => l_timestamp,
2690 	p_pass => l_index
2691   );
2692   -- If API call returns with an error status, upload aborts
2693   if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
2694      (l_return_status = FND_API.G_RET_STS_ERROR) then
2695     RAISE FND_API.G_EXC_ERROR;
2696   end if; -- /* if l_return_status */
2697 
2698   AK_REGION2_PVT.UPLOAD_REGION_SECOND (
2699     p_validation_level => p_validation_level,
2700     p_return_status => l_return_status,
2701     p_loader_timestamp => l_timestamp,
2702 	p_pass => l_index
2703   );
2704   -- If API call returns with an error status, upload aborts
2705   if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
2706      (l_return_status = FND_API.G_RET_STS_ERROR) then
2707     RAISE FND_API.G_EXC_ERROR;
2708   end if; -- /* if l_return_status */
2709 
2710   AK_CUSTOM2_PVT.UPLOAD_CUSTOM_SECOND (
2711     p_validation_level => p_validation_level,
2712     p_return_status => l_return_status,
2713     p_loader_timestamp => l_timestamp,
2714         p_pass => l_index
2715   );
2716   -- If API call returns with an error status, upload aborts
2717   if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
2718      (l_return_status = FND_API.G_RET_STS_ERROR) then
2719     RAISE FND_API.G_EXC_ERROR;
2720   end if; -- /* if l_return_status */
2721 
2722   AK_FLOW2_PVT.UPLOAD_FLOW_SECOND (
2723     p_validation_level => p_validation_level,
2724     p_return_status => l_return_status,
2725     p_loader_timestamp => l_timestamp,
2726 	p_pass => l_index
2727   );
2728   -- If API call returns with an error status, upload aborts
2729   if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
2730      (l_return_status = FND_API.G_RET_STS_ERROR) then
2731     RAISE FND_API.G_EXC_ERROR;
2732   end if; -- /* if l_return_status */
2733 
2734   -- ******* FUTURE ENHANCEMENT ********
2735 
2736   -- if extracting object by application ID, logic should be like this:
2737   --   for each flow with this application ID, with timestamp not
2738   --   equals to the loader timestamp, and created by and last updated
2739   --   by are both 1, call ak_object_pvt.delete with cascade = 'Y'.
2740   --   Then for each attribute referenced by any object attributes to be
2741   --   deleted, call ak_attribute_pvt.delete with cascade = 'N'.
2742 
2743   p_return_status := FND_API.G_RET_STS_SUCCESS;
2744 
2745   FND_MSG_PUB.Count_And_Get (
2746         p_count => p_msg_count,
2747         p_data => p_msg_data);
2748 
2749 EXCEPTION
2750   WHEN FND_API.G_EXC_ERROR THEN
2751     p_return_status := FND_API.G_RET_STS_ERROR;
2752     FND_MSG_PUB.Count_And_Get (
2753         p_count => p_msg_count,
2754         p_data => p_msg_data);
2755   WHEN OTHERS THEN
2756     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2757     FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name,
2758                            SUBSTR (SQLERRM, 1, 240) );
2759     FND_MSG_PUB.Count_And_Get (
2760         p_count => p_msg_count,
2761         p_data => p_msg_data);
2762 end UPLOAD;
2763 
2764 --=======================================================
2765 --  Procedure   GET_TOKEN
2766 --
2767 --  Usage       Private procedure for returning the first token from
2768 --              the given input string.
2769 --              This function is intended to be called only by other APIs
2770 --              that are owned by the Core Modules Team (AK)
2771 --
2772 --  Desc        This procedure parses the input string and returns the first
2773 --              token in the string. It then removes that token from the
2774 --              input string.
2775 --
2776 --  Results     The API returns the standard p_return_status parameter
2777 --              indicating one of the standard return statuses :
2778 --                  * Unexpected error
2779 --                  * Error (including parse error, such as empty input string)
2780 --                  * Success
2781 --              The procedure returns the first token in the input string
2782 --              in the p_token parameter. It also removes the token from
2783 --              the input string.
2784 --  Parameters  p_in_buf : IN OUT
2785 --                  The input string to be parsed. The procedure would
2786 --                  remove the first token from this string before
2787 --                  passing it back to the calling API.
2788 --              p_token : OUT
2789 --                  The first token parsed in the input string, with
2790 --                  all the escaped characters in the token already
2791 --                  replaced with their original characters.
2792 --=======================================================
2793 procedure GET_TOKEN (
2794   p_return_status           OUT NOCOPY     VARCHAR2,
2795   p_in_buf                  IN OUT NOCOPY  VARCHAR2,
2796   p_token                   OUT NOCOPY     VARCHAR2
2797 ) is
2798   l_api_name           CONSTANT varchar2(30) := 'Get_Token';
2799   l_num_slash number;
2800   l_start_pos number;
2801   l_end_pos   number;
2802   l_curr_pos  number;
2803   l_done      boolean;
2804 begin
2805   p_in_buf := LTRIM(p_in_buf);
2806 
2807   if (p_in_buf is null) then
2808     p_token := null;
2809     --dbms_output.put_line('No more token');
2810     raise FND_API.G_EXC_ERROR;
2811   end if;
2812 
2813   l_start_pos := 1;
2814   l_curr_pos := 1;
2815 
2816   --
2817   -- If a quote is found, get string in quotes as token
2818   --
2819   IF (SUBSTR(p_in_buf, 1, 1) = '"') THEN
2820     l_done := FALSE;
2821     --
2822     -- find end quote. If a quote is preceeded with an odd number of
2823     -- backslashes, then it is not an end quote
2824     --
2825     WHILE not l_done LOOP
2826       l_end_pos := INSTR(p_in_buf, '"', l_curr_pos + 1);
2827       if (l_end_pos = 0) or (SUBSTR(p_in_buf, l_end_pos - 1, 1) <> '\') then
2828         l_done := TRUE;
2829       else
2830         l_num_slash := 1;
2831         l_curr_pos := l_end_pos - 2;
2832         while (SUBSTR(p_in_buf, l_curr_pos, 1) = '\') loop
2833           l_num_slash := l_num_slash + 1;
2834           l_curr_pos := l_curr_pos - 1;
2835         end LOOP;
2836         if (MOD(l_num_slash, 2) = 0) then
2837           l_done := TRUE;
2838         end if;
2839         --
2840         -- start next search from position of this quotation mark
2841         --
2842         l_curr_pos := l_end_pos;
2843       END IF;
2844     END LOOP;
2845     l_start_pos := l_start_pos + 1; /* don't include quote */
2846 
2847   --
2848   -- No quote found, get string up to next white space or end of line
2849   -- as token
2850   --
2851   ELSE
2852     l_end_pos := INSTR(p_in_buf, ' ');
2853     --
2854     -- if cannot find a terminating space, return whole string as token
2855     --
2856     if (l_end_pos = 0) then
2857       l_end_pos := length(p_in_buf) + 1;
2858     end if;
2859   END IF;
2860 
2861   if (l_end_pos > 0) then
2862     p_token := REPLACE_ESCAPED_CHARS(
2863                   SUBSTR(p_in_buf, l_start_pos, l_end_pos - l_start_pos) );
2864     p_in_buf := SUBSTR(p_in_buf, l_end_pos + 1, length(p_in_buf)- l_end_pos+1);
2865     p_return_status := FND_API.G_RET_STS_SUCCESS;
2866   else
2867     --
2868     -- error: missing end quote
2869     --
2870     p_token := null;
2871     -- dbms_output.put_line('Error - Missing end quote');
2872     raise FND_API.G_EXC_ERROR;
2873   end if;
2874 
2875 EXCEPTION
2876   WHEN FND_API.G_EXC_ERROR THEN
2877     p_return_status := FND_API.G_RET_STS_ERROR;
2878   WHEN OTHERS THEN
2879     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2880     FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name,
2881                            SUBSTR (SQLERRM, 1, 240) );
2882 end GET_TOKEN;
2883 
2884 --=======================================================
2885 --  Procedure   READ_LINE
2886 --
2887 --  Usage       Private procedure for reading the next line from a file.
2888 --              This function is intended to be called only by other APIs
2889 --              that are owned by the Core Modules Team (AK)
2890 --
2891 --  Desc        This procedure reads the next logical line from a flat file
2892 --              whose file has been read into a Global PL/SQL table.
2893 --              A logical line may contain many physical lines in the
2894 --              file, each except the last physical line has  a trailing
2895 --              character indicating that the line is to be continued.
2896 --
2897 --  Results     The API returns the standard p_return_status parameter
2898 --              indicating one of the standard return statuses :
2899 --                  * Unexpected error
2900 --                  * Error
2901 --                  * Success
2902 --              The procedure returns the data read from the file into
2903 --              the p_buffer parameter. It also return the number of physical
2904 --              lines read when reading the next logical line through the
2905 --              p_lines_read parameter. If the end-of-file is reached, the
2906 --              p_eof_flag will be loaded with 'Y'.
2907 --  Parameters
2908 --				p_index: IN OUT required
2909 --
2910 --              p_buffer : OUT
2911 --                  The buffer where the logical line read from the file
2912 --                  will be loaded.
2913 --              p_lines_read : OUT
2914 --                  The number of lines read from the file when reading
2915 --                  the current logical line
2916 --              p_eof_flag : OUT
2917 --                  This flag will be loaded with 'Y' if the procedure
2918 --                  has encountered the end-of-file while trying to read
2919 --                  the next line from the file.
2920 --  Notes       This procedure will NOT close the file after the last
2921 --              line is read - the caller must close the file by calling
2922 --              the CLOSE_FILE API.
2923 --=======================================================
2924 procedure READ_LINE (
2925   p_return_status           OUT NOCOPY     VARCHAR2,
2926   p_index                   IN OUT NOCOPY  Number,
2927   p_buffer                  OUT NOCOPY     AK_ON_OBJECTS_PUB.Buffer_Type,
2928   p_lines_read              OUT NOCOPY     number,
2929   p_eof_flag                OUT NOCOPY     VARCHAR2,
2930   p_upl_loader_cur          IN OUT NOCOPY  AK_ON_OBJECTS_PUB.LoaderCurTyp
2931   )
2932   is
2933   l_api_name           CONSTANT varchar2(30) := 'Read_Line';
2934   l_buffer             AK_ON_OBJECTS_PUB.Buffer_Type;
2935   l_cont_buffer        AK_ON_OBJECTS_PUB.Buffer_Type;
2936   l_done               BOOLEAN := TRUE;
2937   l_lines_read         NUMBER := 0;
2938   l_index              NUMBER;
2939   l_return_status      VARCHAR2(1);
2940   l_dummy              NUMBER;
2941 begin
2942   --
2943   -- Read next line from file.
2944   --
2945 
2946   l_index := p_index;
2947 
2948   l_index := l_index + 1;
2949   FETCH p_upl_loader_cur into l_dummy, l_buffer;
2950 
2951   l_lines_read := 1;
2952   --
2953   -- If line is a comment, (i.e. the first non-white space char is '#')
2954   -- then we do not need to check for continuation line. Simply
2955   -- return this line.
2956   --
2957   if (SUBSTR(LTRIM(l_buffer), 1, 1) = '#') then
2958     p_buffer := l_buffer;
2959   else
2960     --
2961     -- not a comment line, check for continuation lines
2962     --
2963     l_cont_buffer := null;
2964     l_done := FALSE;
2965     while (not l_done) loop
2966       if (SUBSTR(RTRIM(l_buffer), -1, 1) = '\') then
2967         --
2968         -- This line to be continued, add to buffer
2969         --
2970         l_cont_buffer := l_cont_buffer ||
2971                                  SUBSTR(l_buffer,1,length(l_buffer)-1);
2972 
2973 		FETCH p_upl_loader_cur into l_dummy, l_buffer;
2974 
2975         l_lines_read := l_lines_read + 1;
2976 		l_index := l_index + 1;
2977       else
2978         --
2979         -- line ends, load buffer
2980         --
2981         p_buffer := l_cont_buffer || l_buffer;
2982         l_done := TRUE;
2983       end if;
2984     end LOOP; /* while not l_done */
2985   end if; /* if comment line */
2986 
2987   --
2988   -- Return the number of physical lines read
2989   --
2990   p_lines_read := l_lines_read;
2991   p_eof_flag := 'N';
2992   p_index := l_index;
2993   p_return_status := FND_API.G_RET_STS_SUCCESS;
2994 
2995 EXCEPTION
2996   WHEN NO_DATA_FOUND THEN
2997     if not l_done then
2998       if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
2999         FND_MESSAGE.SET_NAME('AK','AK_UNEXPECTED_EOF_ERROR');
3000         FND_MSG_PUB.Add;
3001         p_return_status := FND_API.G_RET_STS_ERROR;
3002       end if;
3003     end if;
3004     p_return_status := FND_API.G_RET_STS_SUCCESS;
3005     p_lines_read := l_lines_read;
3006     p_eof_flag := 'Y';
3007 	p_index := l_index;
3008   WHEN INVALID_CURSOR THEN
3009     --dbms_output.put_line('Invalid cursor');
3010     if not l_done then
3011       if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
3012         FND_MESSAGE.SET_NAME('AK','AK_UNEXPECTED_EOF_ERROR');
3013         FND_MSG_PUB.Add;
3014       end if;
3015     end if;
3016 	p_return_status := FND_API.G_RET_STS_ERROR;
3017     p_lines_read := l_lines_read;
3018     p_eof_flag := 'Y';
3019 	p_index := l_index;
3020   WHEN OTHERS THEN
3021     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3022     FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name,
3023                            SUBSTR (SQLERRM, 1, 240) );
3024     p_eof_flag := 'Y';
3025     p_lines_read := l_lines_read;
3026 end READ_LINE;
3027 
3028 --=======================================================
3029 --  Procedure   SET_WHO
3030 --
3031 --  Usage       Private procedure for setting the who columns values.
3032 --              This function is intended to be called only by other APIs
3033 --              that are owned by the Core Modules Team (AK)
3034 --
3035 --  Desc        This procedure returns to the caller the values of the
3036 --              who columns for updating or creating a record. It returns
3037 --              a different set of values depending on whether the update
3038 --              is initiated by a user or by the loader.
3039 --
3040 --  Results     The API returns the standard p_return_status parameter
3041 --              indicating one of the standard return statuses :
3042 --                  * Unexpected error
3043 --                  * Error
3044 --                  * Success
3045 --  Parameters  p_loader_timestamp : IN optional
3046 --                  The timestamp to be used when the record are to be
3047 --                  updated or created by the loader. It should not
3048 --                  contain any value (ie, G_MISS_DATE) if the record
3049 --                  is not being updated or created by the loader.
3050 --              p_created_by : OUT
3051 --                  It contains the value to be used for the CREATED_BY
3052 --                  who column. This value should be ignored by the
3053 --                  caller if the caller is only updating a record.
3054 --              p_creation_date : OUT
3055 --                  It contains the value to be used for the CREATION_DATE
3056 --                  who column. This value should be ignored by the
3057 --                  caller if the caller is only updating a record.
3058 --              p_last_updated_by : OUT
3059 --                  It contains the value to be used for the LAST_UPDATED_BY
3060 --                  who column.
3061 --              p_last_update_date : OUT
3062 --                  It contains the value to be used for the LAST_UPDATE_DATE
3063 --                  who column.
3064 --              p_last_update_login : OUT
3065 --                  It contains the value to be used for the
3066 --                  LAST_UPDATE_LOGIN who column.
3067 --=======================================================
3068 procedure SET_WHO (
3069   p_return_status            OUT NOCOPY     VARCHAR2,
3070   p_loader_timestamp         IN      DATE := FND_API.G_MISS_DATE,
3071   p_created_by               OUT NOCOPY     NUMBER,
3072   p_creation_date            OUT NOCOPY     DATE,
3073   p_last_updated_by          OUT NOCOPY     NUMBER,
3074   p_last_update_date         OUT NOCOPY     DATE,
3075   p_last_update_login        OUT NOCOPY     NUMBER
3076 ) is
3077   l_api_name           CONSTANT varchar2(30) := 'Set_Who';
3078   l_file_version 	number;
3079 begin
3080 
3081 if AK_UPLOAD_GRP.G_UPLOAD_DATE is null then
3082    AK_UPLOAD_GRP.G_UPLOAD_DATE := AK_UPLOAD_GRP.G_GEN_DATE;
3083 end if;
3084 if (p_loader_timestamp <> FND_API.G_MISS_DATE) then
3085   l_file_version := AK_ON_OBJECTS_PUB.G_UPLOAD_FILE_VERSION;
3086     if ( l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER1 or
3087                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER2 or
3088                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER3 or
3089                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER4 or
3090                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER5 or
3091                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER6 or
3092                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER7 or
3093                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER8 or
3094                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER9 or
3095                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER10 or
3096                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER11 or
3097                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER12) then
3098        if (AK_UPLOAD_GRP.G_UPLOAD_DATE is null and AK_UPLOAD_GRP.G_COMPARE_UPDATE = FALSE) then
3099 	     AK_UPLOAD_GRP.G_UPLOAD_DATE := p_loader_timestamp;
3100        elsif (AK_UPLOAD_GRP.G_UPLOAD_DATE is null and AK_UPLOAD_GRP.G_COMPARE_UPDATE = TRUE) then
3101           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
3102              FND_MESSAGE.SET_NAME('AK','AK_MISSING_GEN_DATE');
3103              FND_MSG_PUB.Add;
3104           end if;
3105           raise FND_API.G_EXC_ERROR;
3106        end if;
3107        p_created_by := 1;
3108        p_creation_date := AK_UPLOAD_GRP.G_UPLOAD_DATE;
3109        p_last_updated_by := 1;
3110        p_last_update_date := AK_UPLOAD_GRP.G_UPLOAD_DATE;
3111        p_last_update_login := 1;
3112   elsif ( l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER15 or
3113 		l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER14) then
3114     -- called from loader
3115     	p_created_by := 2;
3116     	p_creation_date := AK_UPLOAD_GRP.G_UPLOAD_DATE;
3117     	p_last_updated_by := 2;
3118     	p_last_update_date := AK_UPLOAD_GRP.G_UPLOAD_DATE;
3119     	p_last_update_login := 1;
3120   end if;
3121 else
3122     -- called from user procedure
3123     p_created_by := to_number(nvl(fnd_profile.value('USER_ID'),0));
3124     p_creation_date := sysdate;
3125     p_last_updated_by := to_number(nvl(fnd_profile.value('USER_ID'),0));
3126     p_last_update_date := sysdate;
3127     p_last_update_login := to_number(
3128 	nvl(fnd_profile.value('LOGIN_ID'),0));
3129 end if;
3130 
3131   p_return_status := FND_API.G_RET_STS_SUCCESS;
3132 
3133 EXCEPTION
3134   WHEN FND_API.G_EXC_ERROR THEN
3135     p_return_status := FND_API.G_RET_STS_ERROR;
3136   WHEN OTHERS THEN
3137     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3138     FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name,
3139                            SUBSTR (SQLERRM, 1, 240) );
3140 END SET_WHO;
3141 
3142 
3143 --=======================================================
3144 --  Function    IS_UPDATEABLE
3145 --
3146 --  Usage       Private function for determining if record will be
3147 --              updated.
3148 --              This function is intended to be called only by other APIs
3149 --              that are owned by the Core Modules Team (AK)
3150 --
3151 --  Desc        This function returns to the caller true or false
3152 --              depending on the results of old manual AK logic for
3153 --              determining updateablity, or for jlt files with
3154 --              G_FORMAT_FILE_VER of 120.1 or greater uses
3155 --              FND_LOAD_UTIL.UPLOAD_TEST.
3156 --
3157 --  Results     The API returns the standard p_return_status parameter
3158 --              indicating one of the standard return statuses :
3159 --                  * Unexpected error
3160 --                  * Error
3161 --                  * Success
3162 --  Parameters  p_loader_timestamp : IN optional
3163 --                  The timestamp to be used when the record are to be
3164 --                  updated or created by the loader. It should not
3165 --                  contain any value (ie, G_MISS_DATE) if the record
3166 --                  is not being updated or created by the loader.
3167 --              p_created_by : OUT
3168 --                  It contains the value to be used for the CREATED_BY
3169 --                  who column. This value should be ignored by the
3170 --                  caller if the caller is only updating a record.
3171 --              p_creation_date : OUT
3172 --                  It contains the value to be used for the CREATION_DATE
3173 --                  who column. This value should be ignored by the
3174 --                  caller if the caller is only updating a record.
3175 --              p_last_updated_by : OUT
3176 --                  It contains the value to be used for the LAST_UPDATED_BY
3177 --                  who column.
3178 --              p_last_update_date : OUT
3179 --                  It contains the value to be used for the LAST_UPDATE_DATE
3180 --                  who column.
3181 --              p_last_update_login : OUT
3182 --                  It contains the value to be used for the
3183 --                  LAST_UPDATE_LOGIN who column.
3184 --=======================================================
3185 --   p_file_id - FND_LOAD_UTIL.OWNER_ID(<OWNER attribute from data file>)
3186 --   p_file_lud - LAST_UPDATE_DATE attribute from data file
3187 --   p_db_id - LAST_UPDATED_BY of db row
3188 --   p_db_lud - LAST_UPDATE_DATE of db row
3189 --   p_custom_mode - CUSTOM_MODE FNDLOAD parameter value
3190 function IS_UPDATEABLE (
3191   p_loader_timestamp         IN      DATE := FND_API.G_MISS_DATE,
3192   p_created_by               IN OUT NOCOPY	NUMBER,
3193   p_creation_date            IN OUT NOCOPY	DATE,
3194   p_last_updated_by          IN OUT NOCOPY	NUMBER,
3195   p_db_last_updated_by	     IN 	NUMBER,
3196   p_last_update_date         IN OUT NOCOPY 	DATE,
3197   p_db_last_update_date      IN         DATE,
3198   p_last_update_login        IN	OUT NOCOPY	NUMBER,
3199   p_create_or_update	     IN         VARCHAR2)
3200 return boolean is
3201   l_return_status varchar2(1);
3202   l_file_version number;
3203   l_created_by             number;
3204   l_creation_date          date;
3205   l_last_update_date       date;
3206   l_last_update_login      number;
3207   l_last_updated_by        number;
3208   l_custom_mode		   varchar2(8);
3209 begin
3210 
3211   l_file_version := AK_ON_OBJECTS_PUB.G_UPLOAD_FILE_VERSION;
3212   if (AK_UPLOAD_GRP.G_UPDATE_MODE or p_create_or_update = 'FORCE') then
3213 	l_custom_mode := 'FORCE';
3214   elsif (AK_UPLOAD_GRP.G_NO_CUSTOM_UPDATE) then
3215         l_custom_mode := 'NCUPDATE';
3216   else
3217 	l_custom_mode := 'INVALID';
3218   end if;
3219   -- IF VERSION 120.1 OR GREATER USE FND_LOAD_UTIL COMPARISON LOGIC
3220   if (l_file_version = AK_ON_OBJECTS_PUB.G_FILE_FORMAT_VER and
3221      (p_create_or_update = 'UPDATE' or p_create_or_update = 'FORCE')) then
3222   	if FND_LOAD_UTIL.UPLOAD_TEST (
3223 		p_file_id => p_last_updated_by,
3224 		p_file_lud => p_last_update_date,
3225 		p_db_id => p_db_last_updated_by,
3226 	        p_db_lud => p_db_last_update_date,
3227                 p_custom_mode => l_custom_mode)
3228         then
3229 		return TRUE;
3230         else
3231 		return FALSE;
3232         end if;
3233 
3234   /* ELSIF JLT PRIOR TO R12 DO OLD COMPARISON CHECKING */
3235   elsif (l_file_version <> AK_ON_OBJECTS_PUB.G_FILE_FORMAT_VER) then
3236      if (AK_UPLOAD_GRP.G_NO_CUSTOM_UPDATE) then
3237         if (p_db_last_updated_by <> 1 and p_db_last_updated_by <> 2) then
3238            return FALSE;
3239         end if;
3240      end if;
3241      AK_UPLOAD_GRP.G_UPLOAD_DATE := p_last_update_date;
3242      AK_ON_OBJECTS_PVT.SET_WHO (
3243        	p_return_status => l_return_status,
3244        	p_loader_timestamp => p_loader_timestamp,
3245        	p_created_by => l_created_by,
3246        	p_creation_date => l_creation_date,
3247        	p_last_updated_by => l_last_updated_by,
3248        	p_last_update_date => l_last_update_date,
3249        	p_last_update_login => l_last_update_login);
3250 
3251      if (AK_UPLOAD_GRP.G_NON_SEED_DATA) then
3252         l_created_by := p_created_by;
3253         l_last_updated_by := p_last_updated_by;
3254         l_last_update_login := p_last_update_login;
3255      end if;
3256 
3257      p_created_by := l_created_by;
3258      p_creation_date := l_creation_date;
3259      p_last_updated_by := l_last_updated_by;
3260      p_last_update_date := l_last_update_date;
3261      p_last_update_login := l_last_update_login;
3262 
3263      if p_create_or_update = 'CREATE' then
3264   	return TRUE;
3265      elsif
3266        ((AK_UPLOAD_GRP.G_COMPARE_UPDATE = TRUE and
3267         (l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER15 or
3268         l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER14) and
3269         (p_db_last_updated_by = 1 or p_last_update_date > p_db_last_update_date))  or
3270         (AK_UPLOAD_GRP.G_COMPARE_UPDATE = TRUE and
3271               ( l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER1 or
3272                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER2 or
3273                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER3 or
3274                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER4 or
3275                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER5 or
3276                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER6 or
3277                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER7 or
3278                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER8 or
3279                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER9 or
3280                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER10 or
3281                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER11 or
3282                 l_file_version = AK_ON_OBJECTS_PUB.G_OLD_FILE_FORMAT_VER12) and
3283             p_db_last_updated_by = 1)  or
3284             AK_UPLOAD_GRP.G_COMPARE_UPDATE = FALSE)
3285         THEN
3286            return TRUE;
3287      else return FALSE;
3288      end if;
3289  else return FALSE;
3290  end if;
3291  return TRUE;
3292 end IS_UPDATEABLE;
3293 
3294 --=======================================================
3295 --  Procedure   WRITE_FILE
3296 --
3297 --  Usage       Private procedure for writing the contents in a PL/SQL
3298 --              table to global PL/SQL table.
3299 --              This function is intended to be called only by other APIs
3300 --              that are owned by the Core Modules Team (AK)
3301 --
3302 --  Desc        This procedure writes the contents in the PL/SQL table passed
3303 --              into the specified file. The file could be overwritten
3304 --              or appended depending on the value of the parameter
3305 --              p_write_mode.
3306 --
3307 --  Results     The API returns the standard p_return_status parameter
3308 --              indicating one of the standard return statuses :
3309 --                  * Unexpected error
3310 --                  * Error
3311 --                  * Success
3312 --  Parameters
3313 --              p_buffer_tbl : IN required
3314 --                  The PL/SQL table of type Buffer_Tbl_Type whose
3315 --                  content is to be written to a file.
3316 --              p_write_mode : IN optional
3317 --                  It must be G_APPEND or G_OVERWRITE if a value
3318 --                  is given. It tells this procedure whether to
3319 --                  write the PL/SQL table contents to the end of the
3320 --                  file (default), or to overwrite the file with the
3321 --                  contents in the PL/SQL table.
3322 --=======================================================
3323 procedure WRITE_FILE (
3324   p_return_status           OUT NOCOPY     VARCHAR2,
3325   p_buffer_tbl              IN      AK_ON_OBJECTS_PUB.Buffer_Tbl_Type,
3326   p_write_mode              IN      VARCHAR2 := AK_ON_OBJECTS_PUB.G_APPEND
3327 ) is
3328   l_api_name           CONSTANT varchar2(30) := 'Write_File';
3329   l_buf_len            NUMBER;
3330   l_buf_written        NUMBER := 0;
3331   l_char_to_write      NUMBER;
3332   l_index              NUMBER;
3333   l_tbl_index          NUMBER;
3334   l_string_pos         NUMBER;
3335   l_buffer             VARCHAR2(2000);
3336 begin
3337 
3338   --
3339   -- return without doing anything if buffer is empty
3340   --
3341   if (p_buffer_tbl.count = 0) then
3342    p_return_status := FND_API.G_RET_STS_SUCCESS;
3343    return;
3344   end if;
3345 
3346   --
3347   -- indicate error if write mode is not G_APPEND or G_OVERWRITE
3348   --
3349   if (p_write_mode <> AK_ON_OBJECTS_PUB.G_APPEND) and
3350      (p_write_mode <> AK_ON_OBJECTS_PUB.G_OVERWRITE) then
3351     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
3352       FND_MESSAGE.SET_NAME('AK','AK_INVALID_WRITE_MODE');
3353       FND_MSG_PUB.Add;
3354     end if;
3355     raise FND_API.G_EXC_ERROR;
3356   end if;
3357 
3358   -- If it's append mode, start appending to the end of the global table
3359   --
3360   if (p_write_mode = AK_ON_OBJECTS_PUB.G_OVERWRITE AND AK_DOWNLOAD_GRP.G_WRITE_HEADER) then
3361       G_TBL_INDEX := 0;
3362   end if;
3363 
3364   --
3365   -- Write all lines from buffer to ak_loader_temp table.
3366   -- And break long lines into mulitple lines in the file.
3367   --
3368   G_WRITE_MODE := p_write_mode;
3369 
3370   for l_index in p_buffer_tbl.first .. p_buffer_tbl.last LOOP
3371     if (p_buffer_tbl.exists(l_index)) then
3372       l_buf_len := length(p_buffer_tbl(l_index));
3373       l_buf_written := 0;
3374       WHILE (l_buf_len > l_buf_written) LOOP
3375         l_char_to_write := LEAST(G_MAX_FILE_LINE_LEN - 1,
3376                                   l_buf_len - l_buf_written);
3377         if (l_buf_len > l_buf_written + l_char_to_write) then
3378           --
3379           -- write line with trailing backslash indicating line to be continued
3380           --
3381 		  G_TBL_INDEX := G_TBL_INDEX + 1;
3382           l_buffer := SUBSTR(p_buffer_tbl(l_index),
3383                                          l_buf_written + 1, l_char_to_write) ||
3384                                          '\';
3385           --
3386 	      -- write line to a physical temporary table (AK_LOADER_TEMP) in database
3387 		  --
3388 		  WRITE_TO_TABLE (
3389 			p_buffer => l_buffer);
3390         else
3391           --
3392           -- write line without trailing backslash
3393           --
3394 		  G_TBL_INDEX := G_TBL_INDEX + 1;
3395           l_buffer := SUBSTR(p_buffer_tbl(l_index),
3396                                          l_buf_written + 1, l_char_to_write);
3397 
3398           --
3399 	      -- write line to a physical temporary table (AK_LOADER_TEMP) in database
3400 		  --
3401 		  WRITE_TO_TABLE (
3402 			p_buffer => l_buffer);
3403         end if;
3404         l_buf_written := l_buf_written + l_char_to_write;
3405       END LOOP;
3406     end if;
3407 
3408   END LOOP;
3409 
3410   p_return_status := FND_API.G_RET_STS_SUCCESS;
3411 
3412 EXCEPTION
3413   WHEN FND_API.G_EXC_ERROR THEN
3414     p_return_status := FND_API.G_RET_STS_ERROR;
3415   WHEN OTHERS THEN
3416     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3417     FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name,
3418                            SUBSTR (SQLERRM, 1, 240) );
3419 end WRITE_FILE;
3420 
3421 --=======================================================
3422 --  Procedure   WRITE_LOG_FILE
3423 --
3424 --  Usage       Private procedure for writing the contents in a PL/SQL
3425 --              table to a file.
3426 --              This function is intended to be called only by other APIs
3427 --              that are owned by the Core Modules Team (AK)
3428 --
3429 --  Desc        This procedure writes the contents in the PL/SQL table passed
3430 --              into the specified file. The file could be overwritten
3431 --              or appended depending on the value of the parameter
3432 --              p_write_mode.
3433 --
3434 --  Results     The API returns the standard p_return_status parameter
3435 --              indicating one of the standard return statuses :
3436 --                  * Unexpected error
3437 --                  * Error
3438 --                  * Success
3439 --  Parameters
3440 --              p_buffer_tbl : IN required
3441 --                  The PL/SQL table of type Buffer_Tbl_Type whose
3442 --                  content is to be written to a file.
3443 --              p_write_mode : IN optional
3444 --                  It must be G_APPEND or G_OVERWRITE if a value
3445 --                  is given. It tells this procedure whether to
3446 --                  write the PL/SQL table contents to the end of the
3447 --                  file (default), or to overwrite the file with the
3448 --                  contents in the PL/SQL table.
3449 --=======================================================
3450 procedure WRITE_LOG_FILE (
3451   p_return_status           OUT NOCOPY     VARCHAR2,
3452   p_buffer_tbl              IN      AK_ON_OBJECTS_PUB.Buffer_Tbl_Type,
3453   p_write_mode              IN      VARCHAR2 := AK_ON_OBJECTS_PUB.G_APPEND
3454 ) is
3455   l_api_name           CONSTANT varchar2(30) := 'Write_File';
3456   l_buf_len            NUMBER;
3457   l_buf_written        NUMBER := 0;
3458   l_char_to_write      NUMBER;
3459   l_index              NUMBER;
3460   l_tbl_index          NUMBER;
3461   l_string_pos         NUMBER;
3462 begin
3463   --
3464   -- return without doing anything if buffer is empty
3465   --
3466   if (p_buffer_tbl.count = 0) then
3467    p_return_status := FND_API.G_RET_STS_SUCCESS;
3468    --G_LOG_BUFFER_TBL.DELETE;
3469    return;
3470   end if;
3471 
3472   --
3473   -- indicate error if write mode is not G_APPEND or G_OVERWRITE
3474   --
3475   if (p_write_mode <> AK_ON_OBJECTS_PUB.G_APPEND) and
3476      (p_write_mode <> AK_ON_OBJECTS_PUB.G_OVERWRITE) then
3477     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
3478       FND_MESSAGE.SET_NAME('AK','AK_INVALID_WRITE_MODE');
3479       FND_MSG_PUB.Add;
3480     end if;
3481     raise FND_API.G_EXC_ERROR;
3482   end if;
3483 
3484   -- If it's append mode, start appending to the end of the global table
3485   --
3486   if (p_write_mode = AK_ON_OBJECTS_PUB.G_APPEND) then
3487       l_tbl_index := G_LOG_BUFFER_TBL.count;
3488   else
3489       l_tbl_index := 0;
3490   end if;
3491 
3492   --
3493   -- Write all lines from buffer to file.
3494   -- And break long lines into mulitple lines in the file.
3495   --
3496   l_tbl_index := 0;
3497   G_WRITE_MODE := p_write_mode;
3498   for l_index in p_buffer_tbl.first .. p_buffer_tbl.last LOOP
3499     if (p_buffer_tbl.exists(l_index)) then
3500       l_buf_len := length(p_buffer_tbl(l_index));
3501       l_buf_written := 0;
3502       WHILE (l_buf_len > l_buf_written) LOOP
3503         l_char_to_write := LEAST(G_MAX_FILE_LINE_LEN - 1,
3504                                   l_buf_len - l_buf_written);
3505         if (l_buf_len > l_buf_written + l_char_to_write) then
3506           --
3507           -- write line with trailing backslash indicating line to be continued
3508           --
3509 		  l_tbl_index := l_tbl_index + 1;
3510           G_LOG_BUFFER_TBL(l_tbl_index) := SUBSTR(p_buffer_tbl(l_index),
3511                                          l_buf_written + 1, l_char_to_write) ||
3512                                          '\';
3513         else
3514           --
3515           -- write line without trailing backslash
3516           --
3517 		  l_tbl_index := l_tbl_index + 1;
3518           G_LOG_BUFFER_TBL(l_tbl_index) := SUBSTR(p_buffer_tbl(l_index),
3519                                          l_buf_written + 1, l_char_to_write);
3520         end if;
3521         l_buf_written := l_buf_written + l_char_to_write;
3522       END LOOP;
3523     end if;
3524   END LOOP;
3525   p_return_status := FND_API.G_RET_STS_SUCCESS;
3526 
3527 EXCEPTION
3528   WHEN STORAGE_ERROR THEN
3529     p_return_status := FND_API.G_RET_STS_ERROR;
3530     FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name,
3531                            SUBSTR (SQLERRM, 1, 240) );
3532   WHEN OTHERS THEN
3533     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3534     FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name,
3535                            SUBSTR (SQLERRM, 1, 240) );
3536 end WRITE_LOG_FILE;
3537 
3538 
3539 -- Insert into AK_LOADER_TEMP
3540 --
3541 procedure WRITE_TO_TABLE (
3542 	p_buffer	IN	VARCHAR2
3543 	) is
3544 	insert_err  EXCEPTION;
3545 	err_num     NUMBER;
3546 	err_msg     VARCHAR2(100);
3547 	l_api_name  CONSTANT varchar2(30) := 'Write_To_Table';
3548 begin
3549 	INSERT INTO ak_loader_temp (
3550 		tbl_index,
3551 		line_content,
3552 		session_id
3553 		) values (
3554 		G_TBL_INDEX,
3555 		p_buffer,
3556 		AK_ON_OBJECTS_PVT.G_SESSION_ID
3557 		);
3558 
3559 if SQL%ROWCOUNT = 0 then
3560 --	dbms_output.put_line('no rows has been inserted into ak_loader_temp');
3561 	raise insert_err;
3562 elsif SQL%NOTFOUND then
3563 --	dbms_output.put_line('Error SQL%NOTFOUND');
3564 	raise insert_err;
3565 end if;
3566 
3567 -- commit;
3568 
3569 EXCEPTION
3570 	WHEN insert_err THEN
3571 	--	dbms_output.put_line('Exception insert_err ak_loader_temp');
3572           FND_MESSAGE.SET_NAME('AK','AK_LOADER_TEMP_EXCEPTION');
3573           FND_MSG_PUB.Add;
3574 	WHEN OTHERS THEN
3575           FND_MESSAGE.SET_NAME('AK','AK_LOADER_TEMP_ERROR');
3576 	  FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
3577                            SUBSTR (SQLERRM, 1, 240) );
3578     	  FND_MSG_PUB.Add;
3579 	--	err_num := SQLCODE;
3580 	--	err_msg := SUBSTR(SQLERRM, 1, 100);
3581 	--	dbms_output.put_line('Other errors in inserting into ak_loader_temp');
3582 	--	dbms_output.put_line(to_char(err_num)||' '||err_msg);
3583 
3584 end WRITE_TO_TABLE;
3585 
3586 
3587 --=======================================================
3588 --  Function    VALID_APPLICATION_ID
3589 --
3590 --  Usage       Private function for validating an application ID. This
3591 --              API should only be called by other APIs that are
3592 --              owned by the Core Modules Team (AK).
3593 --
3594 --  Desc        This function checks to see if the given application ID is
3595 --              a valid application ID in the FND_APPLICATION table.
3596 --
3597 --  Results     This  function returns the standard p_return_status parameter
3598 --              indicating one of the standard return statuses :
3599 --                  * Unexpected error
3600 --                  * Error
3601 --                  * Success
3602 --  Parameters  p_application_id : IN required
3603 --                  The application ID that needs to be checked against
3604 --                  the FND_APPLICATION table.
3605 --              This function will return TRUE if the application ID
3606 --              exists in the FND_APPLICATION table, or FALSE otherwise.
3607 --
3608 --  Version     Initial version number  =   1.0
3609 --  History     Current version number  =   1.0
3610 --=======================================================
3611 function VALID_APPLICATION_ID (
3612   p_api_version_number      IN      NUMBER,
3613   p_return_status           OUT NOCOPY     VARCHAR2,
3614   p_application_id          IN      NUMBER
3615 ) return BOOLEAN is
3616   cursor l_check_appl_id_csr is
3617     select 1
3618     from  FND_APPLICATION
3619     where application_id = p_application_id;
3620   l_api_version_number CONSTANT number := 1.0;
3621   l_api_name           CONSTANT varchar2(30) := 'Valid_Application_ID';
3622   l_dummy number;
3623 begin
3624   IF NOT FND_API.Compatible_API_Call (
3625     l_api_version_number, p_api_version_number, l_api_name,
3626     G_PKG_NAME) then
3627       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3628       return FALSE;
3629   END IF;
3630 
3631   open l_check_appl_id_csr;
3632   fetch l_check_appl_id_csr into l_dummy;
3633   if (l_check_appl_id_csr%notfound) then
3634     close l_check_appl_id_csr;
3635     p_return_status := FND_API.G_RET_STS_SUCCESS;
3636     return FALSE;
3637   else
3638     close l_check_appl_id_csr;
3639     p_return_status := FND_API.G_RET_STS_SUCCESS;
3640     return TRUE;
3641   end if;
3642 
3643 EXCEPTION
3644   WHEN FND_API.G_EXC_ERROR THEN
3645     p_return_status := FND_API.G_RET_STS_ERROR;
3646     return FALSE;
3647   WHEN OTHERS THEN
3648     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3649     FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name,
3650                            SUBSTR (SQLERRM, 1, 240) );
3651     return FALSE;
3652 end VALID_APPLICATION_ID;
3653 
3654 --=======================================================
3655 --  Function    VALID_LOOKUP_CODE
3656 --
3657 --  Usage       Private function for validating a lookup code. This
3658 --              API should only be called by other APIs that are
3659 --              owned by the Core Modules Team (AK).
3660 --
3661 --  Desc        This function checks to see if the given lookup type and
3662 --              lookup code exists in the AK_LOOKUP_CODES table.
3663 --
3664 --  Results     This  function returns the standard p_return_status parameter
3665 --              indicating one of the standard return statuses :
3666 --                  * Unexpected error
3667 --                  * Error
3668 --                  * Success
3669 --  Parameters  p_lookup_type : IN required
3670 --                  The type of the lookup code to be verified
3671 --              p_lookup_code : IN required
3672 --                  The lookup code to be verified against AK_LOOKUP_CODES
3673 --              This function will return TRUE if the lookup type and
3674 --              lookup code exists in the AK_LOOKUP_CODES table, or
3675 --              FALSE otherwise.
3676 --
3677 --  Version     Initial version number  =   1.0
3678 --  History     Current version number  =   1.0
3679 --=======================================================
3680 function VALID_LOOKUP_CODE (
3681   p_api_version_number      IN      NUMBER,
3682   p_return_status           OUT NOCOPY     VARCHAR2,
3683   p_lookup_type             IN      VARCHAR2,
3684   p_lookup_code             IN      VARCHAR2
3685 ) return BOOLEAN is
3686   cursor l_checklookup_csr (lookup_type_parm varchar2,
3687 			    lookup_code_parm varchar2)is
3688     select 1
3689     from  AK_LOOKUP_CODES
3690     where lookup_type = lookup_type_parm
3691     and   lookup_code = lookup_code_parm;
3692   l_api_version_number CONSTANT number := 1.0;
3693   l_api_name           CONSTANT varchar2(30) := 'Valid_Application_ID';
3694   l_dummy number;
3695 begin
3696   IF NOT FND_API.Compatible_API_Call (
3697     l_api_version_number, p_api_version_number, l_api_name,
3698     G_PKG_NAME) then
3699       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3700       return FALSE;
3701   END IF;
3702 
3703   open l_checklookup_csr (p_lookup_type, p_lookup_code);
3704   fetch l_checklookup_csr into l_dummy;
3705   if (l_checklookup_csr%notfound) then
3706     close l_checklookup_csr;
3707     p_return_status := FND_API.G_RET_STS_SUCCESS;
3708     return FALSE;
3709   else
3710     close l_checklookup_csr;
3711     p_return_status := FND_API.G_RET_STS_SUCCESS;
3712     return TRUE;
3713   end if;
3714 
3715 EXCEPTION
3716   WHEN FND_API.G_EXC_ERROR THEN
3717     p_return_status := FND_API.G_RET_STS_ERROR;
3718     return FALSE;
3719   WHEN OTHERS THEN
3720     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3721     FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name,
3722                            SUBSTR (SQLERRM, 1, 240) );
3723     return FALSE;
3724 end VALID_LOOKUP_CODE;
3725 
3726 --=======================================================
3727 --  Function    VALID_YES_NO
3728 --
3729 --  Usage       Private function for validating a Y/N column. This
3730 --              API should only be called by other APIs that are
3731 --              owned by the Core Modules Team (AK).
3732 --
3733 --  Desc        This function checks to see if the given value is
3734 --              either 'Y' or 'N'. It is used for checking for valid
3735 --              data in columns that accepts only 'Y' or 'N' as valid
3736 --              values.
3737 --
3738 --  Results     This  function returns the standard p_return_status parameter
3739 --              indicating one of the standard return statuses :
3740 --                  * Unexpected error
3741 --                  * Error
3742 --                  * Success
3743 --  Parameters  p_value : IN required
3744 --                  The value to be checked
3745 --              This function will return TRUE if the value is either
3746 --              'Y' or 'N', or FALSE otherwise.
3747 --
3748 --  Version     Initial version number  =   1.0
3749 --  History     Current version number  =   1.0
3750 --=======================================================
3751 function VALID_YES_NO (
3752   p_value                  IN VARCHAR2
3753 ) return BOOLEAN is
3754 begin
3755   return ((p_value = 'Y') or (p_value = 'N'));
3756 end VALID_YES_NO;
3757 
3758 end AK_ON_OBJECTS_PVT;