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