DBA Data[Home] [Help]

PACKAGE BODY: APPS.AK_FLOW2_PVT

Source


1 package body AK_FLOW2_PVT as
2 /* $Header: akdvfl2b.pls 120.3 2005/09/15 22:18:27 tshort ship $ */
3 
4 
5 --=======================================================
6 --  Procedure   WRITE_ITEMS_TO_BUFFER (local procedure)
7 --
8 --  Usage       Local procedure for writing all flow page region
9 --              item records for the given flow page region to
10 --              the output file. Not designed to be called
11 --              from outside this package.
12 --
13 --  Desc        This procedure retrieves all Flow Page Region Item
14 --              records for the given Flow Page Region from the
15 --              database, and writes them to the output file
16 --              in loader file format.
17 --
18 --  Results     The API returns the standard p_return_status parameter
19 --              indicating one of the standard return statuses :
20 --                  * Unexpected error
21 --                  * Error
22 --                  * Success
23 --  Parameters
24 --              p_flow_application_id : IN required
25 --              p_flow_code : IN required
26 --              p_page_application_id : IN required
27 --              p_page_code : IN required
28 --              p_region_application_id : IN required
29 --              p_region_code : IN required
30 --                  Key value of the Flow Page Region record
31 --                  whose Flow Page Region Item records are to be
32 --                  extracted to the loader file.
33 --=======================================================
34 procedure WRITE_ITEMS_TO_BUFFER (
35   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
36   p_return_status            OUT NOCOPY     VARCHAR2,
37   p_flow_application_id      IN      NUMBER,
38   p_flow_code                IN      VARCHAR2,
39   p_page_application_id      IN      NUMBER,
40   p_page_code                IN      VARCHAR2,
41   p_region_application_id    IN      NUMBER,
42   p_region_code              IN      VARCHAR2
43 ) is
44   cursor l_get_items_csr is
45     select *
46     from   AK_FLOW_PAGE_REGION_ITEMS
47     where  FLOW_APPLICATION_ID = p_flow_application_id
48     and    FLOW_CODE = p_flow_code
49     and    PAGE_APPLICATION_ID = p_page_application_id
50     and    PAGE_CODE = p_page_code
51     and    REGION_APPLICATION_ID = p_region_application_id
52     and    REGION_CODE = p_region_code;
53   l_api_name           CONSTANT varchar2(30) := 'Write_Items_to_buffer';
54   l_databuffer_tbl     AK_ON_OBJECTS_PUB.Buffer_Tbl_Type;
55   l_index              NUMBER;
56   l_items_rec          AK_FLOW_PAGE_REGION_ITEMS%ROWTYPE;
57   l_return_status      varchar2(1);
58 begin
59   -- Find out where the next buffer entry to be written to
60   l_index := 1;
61 
62   -- Retrieve flow page region items information from the database
63 
64   open l_get_items_csr;
65   loop
66     fetch l_get_items_csr into l_items_rec;
67     exit when l_get_items_csr%notfound;
68     -- write this flow page region item if it is validated
69     if (p_validation_level <> FND_API.G_VALID_LEVEL_NONE) and
70           not AK_FLOW3_PVT.VALIDATE_PAGE_REGION_ITEM (
71             p_validation_level => p_validation_level,
72             p_api_version_number => 1.0,
73             p_return_status => l_return_status,
74             p_flow_application_id => p_flow_application_id,
75             p_flow_code => p_flow_code,
76             p_page_application_id => p_page_application_id,
77             p_page_code => p_page_code,
78             p_region_application_id => p_region_application_id,
79             p_region_code => p_region_code,
80             p_attribute_application_id => l_items_rec.attribute_application_id,
81             p_attribute_code => l_items_rec.attribute_code,
82             p_to_page_appl_id => l_items_rec.to_page_appl_id,
83             p_to_page_code => l_items_rec.to_page_code,
84             p_to_url_attribute_appl_id => l_items_rec.to_url_attribute_appl_id,
85             p_to_url_attribute_code => l_items_rec.to_url_attribute_code,
86             p_caller => AK_ON_OBJECTS_PVT.G_DOWNLOAD)
87     then
88         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
89           FND_MESSAGE.SET_NAME('AK','AK_PG_REG_ITEM_NOT_DOWNLOADED');
90           FND_MESSAGE.SET_TOKEN('KEY', to_char(p_flow_application_id) ||
91                    ' ' || p_flow_code ||
92                    ' ' || to_char(p_page_application_id) ||
93                    ' ' || p_page_code ||
94                    ' ' || to_char(p_region_application_id) ||
95                    ' ' || p_region_code ||
96                    ' ' || to_char(l_items_rec.attribute_application_id) ||
97                    ' ' || l_items_rec.attribute_code );
98           FND_MSG_PUB.Add;
99 	  close l_get_items_csr;
100 		  raise FND_API.G_EXC_ERROR;
101         end if;
102     else
103       l_databuffer_tbl(l_index) := ' ';
104       l_index := l_index + 1;
105       l_databuffer_tbl(l_index) := '      BEGIN FLOW_PAGE_REGION_ITEM "' ||
106         nvl(to_char(l_items_rec.attribute_application_id),'') || '" "' ||
107           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_items_rec.attribute_code)
108             || '"';
109       if ((l_items_rec.to_page_appl_id IS NOT NULL) and
110          (l_items_rec.to_page_appl_id <> FND_API.G_MISS_NUM) and
111          (l_items_rec.to_page_code IS NOT NULL) and
112          (l_items_rec.to_page_code <> FND_API.G_MISS_CHAR)) then
113         l_index := l_index + 1;
114         l_databuffer_tbl(l_index) := '        TO_PAGE = "' ||
115           nvl(to_char(l_items_rec.to_page_appl_id),'')||'" "'||
116             AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_items_rec.to_page_code)
117               || '"';
118       end if;
119       if (l_items_rec.to_url_attribute_appl_id IS NOT NULL) and
120          (l_items_rec.to_url_attribute_appl_id <> FND_API.G_MISS_NUM) and
121          (l_items_rec.to_url_attribute_code IS NOT NULL) and
122          (l_items_rec.to_url_attribute_code <> FND_API.G_MISS_CHAR) then
123         l_index := l_index + 1;
124         l_databuffer_tbl(l_index) := '        TO_URL_ATTRIBUTE = "' ||
125            nvl(to_char(l_items_rec.to_url_attribute_appl_id),'')||'" "'||
126              AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
127                l_items_rec.to_url_attribute_code)|| '"';
128       end if;
129       -- Flex Fields
130       --
131       if ((l_items_rec.attribute_category IS NOT NULL) and
132          (l_items_rec.attribute_category <> FND_API.G_MISS_CHAR)) then
133         l_index := l_index + 1;
134         l_databuffer_tbl(l_index) := '        ATTRIBUTE_CATEGORY = "' ||
135           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
136                      l_items_rec.attribute_category) || '"';
137       end if;
138       if ((l_items_rec.attribute1 IS NOT NULL) and
139          (l_items_rec.attribute1 <> FND_API.G_MISS_CHAR)) then
140         l_index := l_index + 1;
141         l_databuffer_tbl(l_index) := '        ATTRIBUTE1 = "' ||
142           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
143                      l_items_rec.attribute1) || '"';
144       end if;
145       if ((l_items_rec.attribute2 IS NOT NULL) and
146          (l_items_rec.attribute2 <> FND_API.G_MISS_CHAR)) then
147         l_index := l_index + 1;
148         l_databuffer_tbl(l_index) := '        ATTRIBUTE2 = "' ||
149           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
150                      l_items_rec.attribute2) || '"';
151       end if;
152       if ((l_items_rec.attribute3 IS NOT NULL) and
153          (l_items_rec.attribute3 <> FND_API.G_MISS_CHAR)) then
154         l_index := l_index + 1;
155         l_databuffer_tbl(l_index) := '        ATTRIBUTE3 = "' ||
156           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
157                      l_items_rec.attribute3) || '"';
158       end if;
159       if ((l_items_rec.attribute4 IS NOT NULL) and
160          (l_items_rec.attribute4 <> FND_API.G_MISS_CHAR)) then
161         l_index := l_index + 1;
162         l_databuffer_tbl(l_index) := '        ATTRIBUTE4 = "' ||
163           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
164                      l_items_rec.attribute4) || '"';
165       end if;
166       if ((l_items_rec.attribute5 IS NOT NULL) and
167          (l_items_rec.attribute5 <> FND_API.G_MISS_CHAR)) then
168         l_index := l_index + 1;
169         l_databuffer_tbl(l_index) := '        ATTRIBUTE5 = "' ||
170           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
171                      l_items_rec.attribute5) || '"';
172       end if;
173       if ((l_items_rec.attribute6 IS NOT NULL) and
174          (l_items_rec.attribute6 <> FND_API.G_MISS_CHAR)) then
175         l_index := l_index + 1;
176         l_databuffer_tbl(l_index) := '        ATTRIBUTE6 = "' ||
177           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
178                      l_items_rec.attribute6) || '"';
179       end if;
180       if ((l_items_rec.attribute7 IS NOT NULL) and
181          (l_items_rec.attribute7 <> FND_API.G_MISS_CHAR)) then
182         l_index := l_index + 1;
183         l_databuffer_tbl(l_index) := '        ATTRIBUTE7 = "' ||
184           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
185                      l_items_rec.attribute7) || '"';
186       end if;
187       if ((l_items_rec.attribute8 IS NOT NULL) and
188          (l_items_rec.attribute8 <> FND_API.G_MISS_CHAR)) then
189         l_index := l_index + 1;
190         l_databuffer_tbl(l_index) := '        ATTRIBUTE8 = "' ||
191           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
192                      l_items_rec.attribute8) || '"';
193       end if;
194       if ((l_items_rec.attribute9 IS NOT NULL) and
195          (l_items_rec.attribute9 <> FND_API.G_MISS_CHAR)) then
196         l_index := l_index + 1;
197         l_databuffer_tbl(l_index) := '        ATTRIBUTE9 = "' ||
198           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
199                      l_items_rec.attribute9) || '"';
200       end if;
201       if ((l_items_rec.attribute10 IS NOT NULL) and
202          (l_items_rec.attribute10 <> FND_API.G_MISS_CHAR)) then
203         l_index := l_index + 1;
204         l_databuffer_tbl(l_index) := '        ATTRIBUTE10 = "' ||
205           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
206                      l_items_rec.attribute10) || '"';
207       end if;
208       if ((l_items_rec.attribute11 IS NOT NULL) and
209          (l_items_rec.attribute11 <> FND_API.G_MISS_CHAR)) then
210         l_index := l_index + 1;
211         l_databuffer_tbl(l_index) := '        ATTRIBUTE11 = "' ||
212           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
213                      l_items_rec.attribute11) || '"';
214       end if;
215       if ((l_items_rec.attribute12 IS NOT NULL) and
216          (l_items_rec.attribute12 <> FND_API.G_MISS_CHAR)) then
217         l_index := l_index + 1;
218         l_databuffer_tbl(l_index) := '        ATTRIBUTE12 = "' ||
219           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
220                      l_items_rec.attribute12) || '"';
221       end if;
222       if ((l_items_rec.attribute13 IS NOT NULL) and
223          (l_items_rec.attribute13 <> FND_API.G_MISS_CHAR)) then
224         l_index := l_index + 1;
225         l_databuffer_tbl(l_index) := '        ATTRIBUTE13 = "' ||
226           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
227                      l_items_rec.attribute13) || '"';
228       end if;
229       if ((l_items_rec.attribute14 IS NOT NULL) and
230          (l_items_rec.attribute14 <> FND_API.G_MISS_CHAR)) then
231         l_index := l_index + 1;
232         l_databuffer_tbl(l_index) := '        ATTRIBUTE14 = "' ||
233           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
234                      l_items_rec.attribute14) || '"';
235       end if;
236       if ((l_items_rec.attribute15 IS NOT NULL) and
237          (l_items_rec.attribute15 <> FND_API.G_MISS_CHAR)) then
238         l_index := l_index + 1;
239         l_databuffer_tbl(l_index) := '        ATTRIBUTE15 = "' ||
240           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
241                      l_items_rec.attribute15) || '"';
242       end if;
243   -- - Write out who columns
244     l_index := l_index + 1;
245     l_databuffer_tbl(l_index) := '        CREATED_BY = "' ||
246                 nvl(to_char(l_items_rec.created_by),'') || '"';
247     l_index := l_index + 1;
248     l_databuffer_tbl(l_index) := '        CREATION_DATE = "' ||
249                 to_char(l_items_rec.creation_date,
250                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT) || '"';
251     l_index := l_index + 1;
252 --  CHANGED TO OWNER FOR R12
253 --    l_databuffer_tbl(l_index) := '        LAST_UPDATED_BY = "' ||
254 --                nvl(to_char(l_items_rec.last_updated_by),'') || '"';
255     l_databuffer_tbl(l_index) := '        OWNER = "' ||
256                 FND_LOAD_UTIL.OWNER_NAME(l_items_rec.last_updated_by) || '"';
257     l_index := l_index + 1;
258     l_databuffer_tbl(l_index) := '        LAST_UPDATE_DATE = "' ||
259                 to_char(l_items_rec.last_update_date,
260                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT) || '"';
261     l_index := l_index + 1;
262     l_databuffer_tbl(l_index) := '        LAST_UPDATE_LOGIN = "' ||
263                 nvl(to_char(l_items_rec.last_update_login),'') || '"';
264 
265 
266       -- finish up flow page region item
267       l_index := l_index + 1;
268       l_databuffer_tbl(l_index) := '      END FLOW_PAGE_REGION_ITEM';
269       l_index := l_index + 1;
270       l_databuffer_tbl(l_index) := ' ';
271     end if; -- validation OK
272 
273   end loop;
274 
275   close l_get_items_csr;
276 
277   -- - Write page region item data out to the specified file
278   --   don't call write_file if there is no data to be written
279   if (l_databuffer_tbl.count > 0) then
280     AK_ON_OBJECTS_PVT.WRITE_FILE (
281       p_return_status => l_return_status,
282       p_buffer_tbl => l_databuffer_tbl,
283       p_write_mode => AK_ON_OBJECTS_PUB.G_APPEND
284     );
285     -- If API call returns with an error status...
286     if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
287        (l_return_status = FND_API.G_RET_STS_ERROR) then
288       RAISE FND_API.G_EXC_ERROR;
289     end if;
290   end if;
291 
292   p_return_status := FND_API.G_RET_STS_SUCCESS;
293 
294 EXCEPTION
295   WHEN VALUE_ERROR THEN
296     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
297       FND_MESSAGE.SET_NAME('AK','AK_PG_REG_ITEM_VALUE_ERROR');
298       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_flow_application_id) ||
299                    ' ' || p_flow_code ||
300                    ' ' || to_char(p_page_application_id) ||
301                    ' ' || p_page_code ||
302                    ' ' || to_char(p_region_application_id) ||
303                    ' ' || p_region_code ||
304                    ' ' || to_char(l_items_rec.attribute_application_id) ||
305                    ' ' || l_items_rec.attribute_code );
306       FND_MSG_PUB.Add;
307     end if;
308     p_return_status := FND_API.G_RET_STS_ERROR;
309   WHEN FND_API.G_EXC_ERROR THEN
310     p_return_status := FND_API.G_RET_STS_ERROR;
311   WHEN OTHERS THEN
312     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
313     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
314                            SUBSTR (SQLERRM, 1, 240) );
315     FND_MSG_PUB.Add;
316 end WRITE_ITEMS_TO_BUFFER;
317 
318 --=======================================================
319 --  Procedure   WRITE_REGIONS_TO_BUFFER (local procedure)
320 --
321 --  Usage       Local procedure for writing all flow page
322 --              region records for the given flow page to
323 --              the output file. Not designed to be called
324 --              from outside this package.
325 --
326 --  Desc        This procedure retrieves all Flow Page Region
327 --              records for the given Flow Page, as well as
328 --              all Flow Page Region Item records for these
329 --              Flow Page Regions and the intrapage Flow Region
330 --              Relation connecting the flow page region and its
331 --              parent region, from the database and writes them
332 --              to the output file in loader file format.
333 --
334 --  Results     The API returns the standard p_return_status parameter
335 --              indicating one of the standard return statuses :
336 --                  * Unexpected error
337 --                  * Error
338 --                  * Success
339 --  Parameters
340 --              p_flow_application_id : IN required
341 --              p_flow_code : IN required
342 --              p_page_application_id : IN required
343 --              p_page_code : IN required
344 --                  Key value of the Flow Page record
345 --                  whose Flow Page Region records are to be
349   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
346 --                  extracted to the loader file.
347 --=======================================================
348 procedure WRITE_REGIONS_TO_BUFFER (
350   p_return_status            OUT NOCOPY     VARCHAR2,
351   p_flow_application_id      IN      NUMBER,
352   p_flow_code                IN      VARCHAR2,
353   p_page_application_id      IN      NUMBER,
354   p_page_code                IN      VARCHAR2
355 ) is
356   cursor l_get_regions_csr is
357     select *
358     from   AK_FLOW_PAGE_REGIONS
359     where  FLOW_APPLICATION_ID = p_flow_application_id
360     and    FLOW_CODE = p_flow_code
361     and    PAGE_APPLICATION_ID = p_page_application_id
362     and    PAGE_CODE = p_page_code;
363   cursor l_get_relation_csr (parent_region_appl_id_param number,
364                              parent_region_code_param varchar2,
365                              region_appl_id_param number,
366                              region_code_param varchar2) is
367     select foreign_key_name
368     from   AK_FLOW_REGION_RELATIONS
369     where  FLOW_APPLICATION_ID = p_flow_application_id
370     and    FLOW_CODE = p_flow_code
371     and    FROM_PAGE_APPL_ID = p_page_application_id
372     and    FROM_PAGE_CODE = p_page_code
373     and    FROM_REGION_APPL_ID = parent_region_appl_id_param
374     and    FROM_REGION_CODE = parent_region_code_param
375     and    TO_PAGE_APPL_ID = p_page_application_id
376     and    TO_PAGE_CODE = p_page_code
377     and    TO_REGION_APPL_ID = region_appl_id_param
378     and    TO_REGION_CODE = region_code_param;
379   l_api_name           CONSTANT varchar2(30) := 'Write_Region_to_buffer';
380   l_databuffer_tbl     AK_ON_OBJECTS_PUB.Buffer_Tbl_Type;
381   l_foreign_key_name   VARCHAR2(30);
382   l_index              NUMBER;
383   l_regions_rec        AK_FLOW_PAGE_REGIONS%ROWTYPE;
384   l_return_status      varchar2(1);
385 begin
386   -- Find out where the next buffer entry to be written to
387   l_index := 1;
388 
389   -- Retrieve flow page regions information from the database
390 
391   open l_get_regions_csr;
392   loop
393     fetch l_get_regions_csr into l_regions_rec;
394     exit when l_get_regions_csr%notfound;
395     --
396     -- get foreign key name from the intrapage relation if there is
397     -- a parent region
398     --
399     if (l_regions_rec.parent_region_application_id is not null) or
400        (l_regions_rec.parent_region_code is not null) then
401       open l_get_relation_csr (l_regions_rec.parent_region_application_id,
402                                l_regions_rec.parent_region_code,
403                                l_regions_rec.region_application_id,
404                                l_regions_rec.region_code);
405       fetch l_get_relation_csr into l_foreign_key_name;
406       close l_get_relation_csr;
407     else
408       l_foreign_key_name := null;
409     end if;
410 
411     -- write this flow page region if it is validated
412     if (p_validation_level <> FND_API.G_VALID_LEVEL_NONE) and
413           not AK_FLOW3_PVT.VALIDATE_PAGE_REGION (
414             p_validation_level => p_validation_level,
415             p_api_version_number => 1.0,
416             p_return_status => l_return_status,
417             p_flow_application_id => p_flow_application_id,
418             p_flow_code => p_flow_code,
419             p_page_application_id => p_page_application_id,
420             p_page_code => p_page_code,
421             p_region_application_id => l_regions_rec.region_application_id,
422             p_region_code => l_regions_rec.region_code,
423             p_display_sequence => l_regions_rec.display_sequence,
424             p_region_style => l_regions_rec.region_style,
425             p_num_columns => l_regions_rec.num_columns,
426             p_icx_custom_call => l_regions_rec.icx_custom_call,
427             p_parent_region_application_id =>
428                          l_regions_rec.parent_region_application_id,
429             p_parent_region_code => l_regions_rec.parent_region_code,
430             p_foreign_key_name => l_foreign_key_name,
431             p_caller => AK_ON_OBJECTS_PVT.G_DOWNLOAD)
432     then
433         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
434           FND_MESSAGE.SET_NAME('AK','AK_PG_REGION_NOT_DOWNLOADED');
435           FND_MESSAGE.SET_TOKEN('KEY', to_char(p_flow_application_id) ||
436                    ' ' || p_flow_code ||
437                    ' ' || to_char(p_page_application_id) ||
438                    ' ' || p_page_code ||
439                    ' ' || to_char(l_regions_rec.region_application_id) ||
440                    ' ' || l_regions_rec.region_code );
441           FND_MSG_PUB.Add;
442 	  close l_get_regions_csr;
443 		  raise FND_API.G_EXC_ERROR;
444         end if;
445     else
446       l_databuffer_tbl(l_index) := ' ';
447       l_index := l_index + 1;
448       l_databuffer_tbl(l_index) := '    BEGIN FLOW_PAGE_REGION "' ||
449         nvl(to_char(l_regions_rec.region_application_id),'') || '" "' ||
450         AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_regions_rec.region_code)
451         || '"';
452       l_index := l_index + 1;
453       l_databuffer_tbl(l_index) := '      DISPLAY_SEQUENCE = "' ||
454                nvl(to_char(l_regions_rec.display_sequence),'') || '"';
455       l_index := l_index + 1;
456       l_databuffer_tbl(l_index) := '      REGION_STYLE = "' ||
457         AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_regions_rec.region_style)
458          || '"';
462         l_databuffer_tbl(l_index) := '      NUM_COLUMNS = "' ||
459       if (l_regions_rec.num_columns IS NOT NULL) and
460          (l_regions_rec.num_columns <> FND_API.G_MISS_NUM) then
461         l_index := l_index + 1;
463                  nvl(to_char(l_regions_rec.num_columns),'') || '"';
464       end if;
465       if (l_regions_rec.icx_custom_call IS NOT NULL) and
466          (l_regions_rec.icx_custom_call <> FND_API.G_MISS_CHAR) then
467         l_index := l_index + 1;
468         l_databuffer_tbl(l_index) := '      ICX_CUSTOM_CALL = "' ||
469           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_regions_rec.icx_custom_call)          ||'"';
470       end if;
471       if (l_regions_rec.parent_region_application_id IS NOT NULL) and
472          (l_regions_rec.parent_region_application_id <> FND_API.G_MISS_NUM) and
473          (l_regions_rec.parent_region_code IS NOT NULL) and
474          (l_regions_rec.parent_region_code <> FND_API.G_MISS_CHAR) then
475         l_index := l_index + 1;
476         l_databuffer_tbl(l_index) := '      PARENT_REGION = "' ||
477           nvl(to_char(l_regions_rec.parent_region_application_id),'')||'" "'||
478           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_regions_rec.parent_region_code)
479           ||'"';
480       end if;
481       if (l_foreign_key_name IS NOT NULL) and
482          (l_foreign_key_name <> FND_API.G_MISS_CHAR) then
483         l_index := l_index + 1;
484         l_databuffer_tbl(l_index) := '      FOREIGN_KEY_NAME = "' ||
485          AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_foreign_key_name)
486          ||'"';
487       end if;
488       -- Flex Fields
489       --
490       if ((l_regions_rec.attribute_category IS NOT NULL) and
491          (l_regions_rec.attribute_category <> FND_API.G_MISS_CHAR)) then
492         l_index := l_index + 1;
493         l_databuffer_tbl(l_index) := '      ATTRIBUTE_CATEGORY = "' ||
494           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
495                      l_regions_rec.attribute_category) || '"';
496       end if;
497       if ((l_regions_rec.attribute1 IS NOT NULL) and
498          (l_regions_rec.attribute1 <> FND_API.G_MISS_CHAR)) then
499         l_index := l_index + 1;
500         l_databuffer_tbl(l_index) := '      ATTRIBUTE1 = "' ||
501           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
502                      l_regions_rec.attribute1) || '"';
503       end if;
504       if ((l_regions_rec.attribute2 IS NOT NULL) and
505          (l_regions_rec.attribute2 <> FND_API.G_MISS_CHAR)) then
506         l_index := l_index + 1;
507         l_databuffer_tbl(l_index) := '      ATTRIBUTE2 = "' ||
508           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
509                      l_regions_rec.attribute2) || '"';
510       end if;
511       if ((l_regions_rec.attribute3 IS NOT NULL) and
512          (l_regions_rec.attribute3 <> FND_API.G_MISS_CHAR)) then
513         l_index := l_index + 1;
514         l_databuffer_tbl(l_index) := '      ATTRIBUTE3 = "' ||
515           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
516                      l_regions_rec.attribute3) || '"';
517       end if;
518       if ((l_regions_rec.attribute4 IS NOT NULL) and
519          (l_regions_rec.attribute4 <> FND_API.G_MISS_CHAR)) then
520         l_index := l_index + 1;
521         l_databuffer_tbl(l_index) := '      ATTRIBUTE4 = "' ||
522           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
523                      l_regions_rec.attribute4) || '"';
524       end if;
525       if ((l_regions_rec.attribute5 IS NOT NULL) and
526          (l_regions_rec.attribute5 <> FND_API.G_MISS_CHAR)) then
527         l_index := l_index + 1;
528         l_databuffer_tbl(l_index) := '      ATTRIBUTE5 = "' ||
529           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
530                      l_regions_rec.attribute5) || '"';
531       end if;
532       if ((l_regions_rec.attribute6 IS NOT NULL) and
533          (l_regions_rec.attribute6 <> FND_API.G_MISS_CHAR)) then
534         l_index := l_index + 1;
535         l_databuffer_tbl(l_index) := '      ATTRIBUTE6 = "' ||
536           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
537                      l_regions_rec.attribute6) || '"';
538       end if;
539       if ((l_regions_rec.attribute7 IS NOT NULL) and
540          (l_regions_rec.attribute7 <> FND_API.G_MISS_CHAR)) then
541         l_index := l_index + 1;
542         l_databuffer_tbl(l_index) := '      ATTRIBUTE7 = "' ||
543           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
544                      l_regions_rec.attribute7) || '"';
545       end if;
546       if ((l_regions_rec.attribute8 IS NOT NULL) and
547          (l_regions_rec.attribute8 <> FND_API.G_MISS_CHAR)) then
548         l_index := l_index + 1;
549         l_databuffer_tbl(l_index) := '      ATTRIBUTE8 = "' ||
550           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
551                      l_regions_rec.attribute8) || '"';
552       end if;
553       if ((l_regions_rec.attribute9 IS NOT NULL) and
554          (l_regions_rec.attribute9 <> FND_API.G_MISS_CHAR)) then
555         l_index := l_index + 1;
556         l_databuffer_tbl(l_index) := '      ATTRIBUTE9 = "' ||
557           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
558                      l_regions_rec.attribute9) || '"';
559       end if;
560       if ((l_regions_rec.attribute10 IS NOT NULL) and
561          (l_regions_rec.attribute10 <> FND_API.G_MISS_CHAR)) then
562         l_index := l_index + 1;
563         l_databuffer_tbl(l_index) := '      ATTRIBUTE10 = "' ||
564           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
565                      l_regions_rec.attribute10) || '"';
566       end if;
570         l_databuffer_tbl(l_index) := '      ATTRIBUTE11 = "' ||
567       if ((l_regions_rec.attribute11 IS NOT NULL) and
568          (l_regions_rec.attribute11 <> FND_API.G_MISS_CHAR)) then
569         l_index := l_index + 1;
571           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
572                      l_regions_rec.attribute11) || '"';
573       end if;
574       if ((l_regions_rec.attribute12 IS NOT NULL) and
575          (l_regions_rec.attribute12 <> FND_API.G_MISS_CHAR)) then
576         l_index := l_index + 1;
577         l_databuffer_tbl(l_index) := '      ATTRIBUTE12 = "' ||
578           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
579                      l_regions_rec.attribute12) || '"';
580       end if;
581       if ((l_regions_rec.attribute13 IS NOT NULL) and
582          (l_regions_rec.attribute13 <> FND_API.G_MISS_CHAR)) then
583         l_index := l_index + 1;
584         l_databuffer_tbl(l_index) := '      ATTRIBUTE13 = "' ||
585           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
586                      l_regions_rec.attribute13) || '"';
587       end if;
588       if ((l_regions_rec.attribute14 IS NOT NULL) and
589          (l_regions_rec.attribute14 <> FND_API.G_MISS_CHAR)) then
590         l_index := l_index + 1;
591         l_databuffer_tbl(l_index) := '      ATTRIBUTE14 = "' ||
592           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
593                      l_regions_rec.attribute14) || '"';
594       end if;
595       if ((l_regions_rec.attribute15 IS NOT NULL) and
596          (l_regions_rec.attribute15 <> FND_API.G_MISS_CHAR)) then
597         l_index := l_index + 1;
598         l_databuffer_tbl(l_index) := '      ATTRIBUTE15 = "' ||
599           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
600                      l_regions_rec.attribute15) || '"';
601       end if;
602   -- - Write out who columns
603     l_index := l_index + 1;
604     l_databuffer_tbl(l_index) := '      CREATED_BY = "' ||
605                 nvl(to_char(l_regions_rec.created_by),'') || '"';
606     l_index := l_index + 1;
607     l_databuffer_tbl(l_index) := '      CREATION_DATE = "' ||
608                 to_char(l_regions_rec.creation_date,
609                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT) || '"';
610     l_index := l_index + 1;
611 -- CHANGED TO OWNER FOR R12
612 --    l_databuffer_tbl(l_index) := '      LAST_UPDATED_BY = "' ||
613 --                nvl(to_char(l_regions_rec.last_updated_by),'') || '"';
614     l_databuffer_tbl(l_index) := '      OWNER = "' ||
615                 FND_LOAD_UTIL.OWNER_NAME(l_regions_rec.last_updated_by) ||'"';
616     l_index := l_index + 1;
617     l_databuffer_tbl(l_index) := '      LAST_UPDATE_DATE = "' ||
618                 to_char(l_regions_rec.last_update_date,
619                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT) || '"';
620     l_index := l_index + 1;
621     l_databuffer_tbl(l_index) := '      LAST_UPDATE_LOGIN = "' ||
622                 nvl(to_char(l_regions_rec.last_update_login),'') || '"';
623 
624 
625       -- - Write flow page region data out to the specified file
626       AK_ON_OBJECTS_PVT.WRITE_FILE (
627         p_return_status => l_return_status,
628         p_buffer_tbl => l_databuffer_tbl,
629         p_write_mode => AK_ON_OBJECTS_PUB.G_APPEND
630       );
631       -- If API call returns with an error status...
632       if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
633          (l_return_status = FND_API.G_RET_STS_ERROR) then
634 	close l_get_regions_csr;
635         RAISE FND_API.G_EXC_ERROR;
636       end if;
637 
638       l_databuffer_tbl.delete;
639 
640       -- Load region items (AK_FLOW_PAGE_REGION_ITEMS)
641       WRITE_ITEMS_TO_BUFFER (
642         p_validation_level => p_validation_level,
643         p_return_status => l_return_status,
644         p_flow_application_id => p_flow_application_id,
645         p_flow_code => p_flow_code,
646         p_page_application_id => p_page_application_id,
647         p_page_code => p_page_code,
648         p_region_application_id => l_regions_rec.region_application_id,
649         p_region_code => l_regions_rec.region_code
650       );
651 
652       -- Download should abort if validation fails
653 	  --
654       if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
655         (l_return_status = FND_API.G_RET_STS_ERROR) then
656        close l_get_regions_csr;
657        RAISE FND_API.G_EXC_ERROR;
658       end if;
659 
660       -- finish up flow page region
661       l_index := 1;
662       l_databuffer_tbl(l_index) := '    END FLOW_PAGE_REGION';
663       l_index := l_index + 1;
664       l_databuffer_tbl(l_index) := ' ';
665     end if; -- validation OK
666 
667     -- - Finish up writing object data out to the specified file
668     AK_ON_OBJECTS_PVT.WRITE_FILE (
669       p_return_status => l_return_status,
670       p_buffer_tbl => l_databuffer_tbl,
671       p_write_mode => AK_ON_OBJECTS_PUB.G_APPEND
672     );
673     -- If API call returns with an error status...
674     if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
675        (l_return_status = FND_API.G_RET_STS_ERROR) then
676       close l_get_regions_csr;
677       RAISE FND_API.G_EXC_ERROR;
678     end if;
679 
680     l_databuffer_tbl.delete;
681 
682   end loop;
683   close l_get_regions_csr;
684 
685   p_return_status := FND_API.G_RET_STS_SUCCESS;
686 
687 EXCEPTION
688   WHEN VALUE_ERROR THEN
689     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
693                    ' ' || to_char(p_page_application_id) ||
690       FND_MESSAGE.SET_NAME('AK','AK_PG_REGION_VALUE_ERROR');
691       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_flow_application_id) ||
692                    ' ' || p_flow_code ||
694                    ' ' || p_page_code ||
695                    ' ' || to_char(l_regions_rec.region_application_id) ||
696                    ' ' || l_regions_rec.region_code );
697       FND_MSG_PUB.Add;
698     end if;
699     p_return_status := FND_API.G_RET_STS_ERROR;
700   WHEN FND_API.G_EXC_ERROR THEN
701     p_return_status := FND_API.G_RET_STS_ERROR;
702   WHEN OTHERS THEN
703     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
704     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
705                            SUBSTR (SQLERRM, 1, 240) );
706     FND_MSG_PUB.Add;
707 end WRITE_REGIONS_TO_BUFFER;
708 
709 --=======================================================
710 --  Procedure   WRITE_PAGES_TO_BUFFER (local procedure)
711 --
712 --  Usage       Local procedure for writing all flow page
713 --              records for the given flow to the output file.
714 --              Not designed to be called from outside this package.
715 --
716 --  Desc        This procedure retrieves all Flow Page
717 --              records for the given Flow, as well as all the
718 --              all Flow Page Region and Flow Page Region Item
719 --              records for these Flow Pages, from the database and
720 --              writes them to the output file in loader file format.
721 --
722 --  Results     The API returns the standard p_return_status parameter
723 --              indicating one of the standard return statuses :
724 --                  * Unexpected error
725 --                  * Error
726 --                  * Success
727 --  Parameters
728 --              p_flow_application_id : IN required
729 --              p_flow_code : IN required
730 --                  Key value of the Flow record whose Flow Page
731 --                  Region records are to be extracted to the loader file.
732 --              p_nls_language : IN required
733 --                  The NLS langauge that should be used when
734 --                  extracting data from the TL table
735 --=======================================================
736 procedure WRITE_PAGES_TO_BUFFER (
737   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
738   p_return_status            OUT NOCOPY     VARCHAR2,
739   p_flow_application_id      IN      NUMBER,
740   p_flow_code                IN      VARCHAR2,
741   p_nls_language             IN      VARCHAR2
742 ) is
743   cursor l_get_pages_csr is
744     select *
745     from   AK_FLOW_PAGES
746     where  FLOW_APPLICATION_ID = p_flow_application_id
747     and    FLOW_CODE = p_flow_code;
748   cursor l_get_page_tl_csr (page_appl_id_param number,
749                             page_code_param varchar2) is
750     select *
751     from   AK_FLOW_PAGES_TL
752     where  FLOW_APPLICATION_ID = p_flow_application_id
753     and    FLOW_CODE = p_flow_code
754     and    PAGE_APPLICATION_ID = page_appl_id_param
755     and    PAGE_CODE = page_code_param
756     and    LANGUAGE = p_nls_language;
757   l_api_name           CONSTANT varchar2(30) := 'Write_Pages_to_buffer';
758   l_databuffer_tbl     AK_ON_OBJECTS_PUB.Buffer_Tbl_Type;
759   l_index              NUMBER;
760   l_pages_rec          AK_FLOW_PAGES%ROWTYPE;
761   l_pages_tl_rec       AK_FLOW_PAGES_TL%ROWTYPE;
762   l_return_status      varchar2(1);
763 begin
764   -- Find out where the next buffer entry to be written to
765   l_index := 1;
766 
767   -- Retrieve flow pages and its TL information from the database
768 
769   open l_get_pages_csr;
770   loop
771     fetch l_get_pages_csr into l_pages_rec;
772     exit when l_get_pages_csr%notfound;
773 --dbms_output.put_line('flow page is ' || to_char(p_flow_application_id) || ' '
774 --                         || p_flow_code || ' ' ||
775 --                         to_char(l_pages_rec.page_application_id)
776 --                                || ' ' || l_pages_rec.page_code);
777 
778     open l_get_page_tl_csr(l_pages_rec.page_application_id,
779                            l_pages_rec.page_code);
780     fetch l_get_page_tl_csr into l_pages_tl_rec;
781     if l_get_page_tl_csr%found then
782 
783     -- write this flow page if it is validated
784       if (p_validation_level <> FND_API.G_VALID_LEVEL_NONE) and
785           not AK_FLOW3_PVT.VALIDATE_PAGE (
786             p_validation_level => p_validation_level,
787             p_api_version_number => 1.0,
788             p_return_status => l_return_status,
789             p_flow_application_id => p_flow_application_id,
790             p_flow_code => p_flow_code,
791             p_page_application_id => l_pages_rec.page_application_id,
792             p_page_code => l_pages_rec.page_code,
793             p_primary_region_appl_id => l_pages_rec.primary_region_appl_id,
794             p_primary_region_code => l_pages_rec.primary_region_code,
795             p_name => l_pages_tl_rec.name,
796             p_description => l_pages_tl_rec.description,
797             p_caller => AK_ON_OBJECTS_PVT.G_DOWNLOAD)
798       then
799         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
800           FND_MESSAGE.SET_NAME('AK','AK_FLOW_PAGE_NOT_DOWNLOADED');
801           FND_MESSAGE.SET_TOKEN('KEY', to_char(p_flow_application_id) ||
802                    ' ' || p_flow_code ||
806         end if;
803                    ' ' || to_char(l_pages_rec.page_application_id) ||
804                    ' ' || l_pages_rec.page_code );
805           FND_MSG_PUB.Add;
807 	close l_get_page_tl_csr;
808 	close l_get_pages_csr;
809         RAISE FND_API.G_EXC_ERROR;
810       else
811         l_databuffer_tbl(l_index) := ' ';
812         l_index := l_index + 1;
813         l_databuffer_tbl(l_index) := '  BEGIN FLOW_PAGE "' ||
814           nvl(to_char(l_pages_rec.page_application_id),'') || '" "' ||
815           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_pages_rec.page_code)
816           || '"';
817         l_index := l_index + 1;
818         l_databuffer_tbl(l_index) := '    PRIMARY_REGION = "' ||
819           nvl(to_char(l_pages_rec.primary_region_appl_id),'')||'" "'||
820           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
821                                 l_pages_rec.primary_region_code) ||'"';
822       -- Flex Fields
823       --
824       if ((l_pages_rec.attribute_category IS NOT NULL) and
825          (l_pages_rec.attribute_category <> FND_API.G_MISS_CHAR)) then
826         l_index := l_index + 1;
827         l_databuffer_tbl(l_index) := '    ATTRIBUTE_CATEGORY = "' ||
828           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
829                      l_pages_rec.attribute_category) || '"';
830       end if;
831       if ((l_pages_rec.attribute1 IS NOT NULL) and
832          (l_pages_rec.attribute1 <> FND_API.G_MISS_CHAR)) then
833         l_index := l_index + 1;
834         l_databuffer_tbl(l_index) := '    ATTRIBUTE1 = "' ||
835           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
836                      l_pages_rec.attribute1) || '"';
837       end if;
838       if ((l_pages_rec.attribute2 IS NOT NULL) and
839          (l_pages_rec.attribute2 <> FND_API.G_MISS_CHAR)) then
840         l_index := l_index + 1;
841         l_databuffer_tbl(l_index) := '    ATTRIBUTE2 = "' ||
842           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
843                      l_pages_rec.attribute2) || '"';
844       end if;
845       if ((l_pages_rec.attribute3 IS NOT NULL) and
846          (l_pages_rec.attribute3 <> FND_API.G_MISS_CHAR)) then
847         l_index := l_index + 1;
848         l_databuffer_tbl(l_index) := '    ATTRIBUTE3 = "' ||
849           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
850                      l_pages_rec.attribute3) || '"';
851       end if;
852       if ((l_pages_rec.attribute4 IS NOT NULL) and
853          (l_pages_rec.attribute4 <> FND_API.G_MISS_CHAR)) then
854         l_index := l_index + 1;
855         l_databuffer_tbl(l_index) := '    ATTRIBUTE4 = "' ||
856           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
857                      l_pages_rec.attribute4) || '"';
858       end if;
859       if ((l_pages_rec.attribute5 IS NOT NULL) and
860          (l_pages_rec.attribute5 <> FND_API.G_MISS_CHAR)) then
861         l_index := l_index + 1;
862         l_databuffer_tbl(l_index) := '    ATTRIBUTE5 = "' ||
863           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
864                      l_pages_rec.attribute5) || '"';
865       end if;
866       if ((l_pages_rec.attribute6 IS NOT NULL) and
867          (l_pages_rec.attribute6 <> FND_API.G_MISS_CHAR)) then
868         l_index := l_index + 1;
869         l_databuffer_tbl(l_index) := '    ATTRIBUTE6 = "' ||
870           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
871                      l_pages_rec.attribute6) || '"';
872       end if;
873       if ((l_pages_rec.attribute7 IS NOT NULL) and
874          (l_pages_rec.attribute7 <> FND_API.G_MISS_CHAR)) then
875         l_index := l_index + 1;
876         l_databuffer_tbl(l_index) := '    ATTRIBUTE7 = "' ||
877           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
878                      l_pages_rec.attribute7) || '"';
879       end if;
880       if ((l_pages_rec.attribute8 IS NOT NULL) and
881          (l_pages_rec.attribute8 <> FND_API.G_MISS_CHAR)) then
882         l_index := l_index + 1;
883         l_databuffer_tbl(l_index) := '    ATTRIBUTE8 = "' ||
884           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
885                      l_pages_rec.attribute8) || '"';
886       end if;
887       if ((l_pages_rec.attribute9 IS NOT NULL) and
888          (l_pages_rec.attribute9 <> FND_API.G_MISS_CHAR)) then
889         l_index := l_index + 1;
890         l_databuffer_tbl(l_index) := '    ATTRIBUTE9 = "' ||
891           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
892                      l_pages_rec.attribute9) || '"';
893       end if;
894       if ((l_pages_rec.attribute10 IS NOT NULL) and
895          (l_pages_rec.attribute10 <> FND_API.G_MISS_CHAR)) then
896         l_index := l_index + 1;
897         l_databuffer_tbl(l_index) := '    ATTRIBUTE10 = "' ||
898           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
899                      l_pages_rec.attribute10) || '"';
900       end if;
901       if ((l_pages_rec.attribute11 IS NOT NULL) and
902          (l_pages_rec.attribute11 <> FND_API.G_MISS_CHAR)) then
903         l_index := l_index + 1;
904         l_databuffer_tbl(l_index) := '    ATTRIBUTE11 = "' ||
905           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
906                      l_pages_rec.attribute11) || '"';
907       end if;
908       if ((l_pages_rec.attribute12 IS NOT NULL) and
909          (l_pages_rec.attribute12 <> FND_API.G_MISS_CHAR)) then
910         l_index := l_index + 1;
911         l_databuffer_tbl(l_index) := '    ATTRIBUTE12 = "' ||
912           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
913                      l_pages_rec.attribute12) || '"';
917         l_index := l_index + 1;
914       end if;
915       if ((l_pages_rec.attribute13 IS NOT NULL) and
916          (l_pages_rec.attribute13 <> FND_API.G_MISS_CHAR)) then
918         l_databuffer_tbl(l_index) := '    ATTRIBUTE13 = "' ||
919           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
920                      l_pages_rec.attribute13) || '"';
921       end if;
922       if ((l_pages_rec.attribute14 IS NOT NULL) and
923          (l_pages_rec.attribute14 <> FND_API.G_MISS_CHAR)) then
924         l_index := l_index + 1;
925         l_databuffer_tbl(l_index) := '    ATTRIBUTE14 = "' ||
926           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
927                      l_pages_rec.attribute14) || '"';
928       end if;
929       if ((l_pages_rec.attribute15 IS NOT NULL) and
930          (l_pages_rec.attribute15 <> FND_API.G_MISS_CHAR)) then
931         l_index := l_index + 1;
932         l_databuffer_tbl(l_index) := '    ATTRIBUTE15 = "' ||
933           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
934                      l_pages_rec.attribute15) || '"';
935       end if;
936   -- - Write out who columns
937     l_index := l_index + 1;
938     l_databuffer_tbl(l_index) := '    CREATED_BY = "' ||
939                 nvl(to_char(l_pages_rec.created_by),'') || '"';
940     l_index := l_index + 1;
941     l_databuffer_tbl(l_index) := '    CREATION_DATE = "' ||
942                 to_char(l_pages_rec.creation_date,
943                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT) || '"';
944     l_index := l_index + 1;
945 -- CHANGED TO OWNER FOR R12
946 --    l_databuffer_tbl(l_index) := '    LAST_UPDATED_BY = "' ||
947 --                nvl(to_char(l_pages_rec.last_updated_by),'') || '"';
948     l_databuffer_tbl(l_index) := '    OWNER = "' ||
949                 FND_LOAD_UTIL.OWNER_NAME(l_pages_rec.last_updated_by) || '"';
950     l_index := l_index + 1;
951     l_databuffer_tbl(l_index) := '    LAST_UPDATE_DATE = "' ||
952                 to_char(l_pages_rec.last_update_date,
953                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT) || '"';
954     l_index := l_index + 1;
955     l_databuffer_tbl(l_index) := '    LAST_UPDATE_LOGIN = "' ||
956                 nvl(to_char(l_pages_rec.last_update_login),'') || '"';
957 
958         if ((l_pages_tl_rec.name IS NOT NULL) and
959            (l_pages_tl_rec.name <> FND_API.G_MISS_CHAR)) then
960           l_index := l_index + 1;
961           l_databuffer_tbl(l_index) := '    NAME = "' ||
962             AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_pages_tl_rec.name) || '"';
963         end if;
964         if ((l_pages_tl_rec.description IS NOT NULL) and
965            (l_pages_tl_rec.description <> FND_API.G_MISS_CHAR)) then
966           l_index := l_index + 1;
967           l_databuffer_tbl(l_index) := '    DESCRIPTION = "' ||
968             AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_pages_tl_rec.description)
969             || '"';
970         end if;
971 
972         -- - Write flow page data out to the specified file
973         AK_ON_OBJECTS_PVT.WRITE_FILE (
974           p_return_status => l_return_status,
975           p_buffer_tbl => l_databuffer_tbl,
976           p_write_mode => AK_ON_OBJECTS_PUB.G_APPEND
977         );
978         -- If API call returns with an error status...
979         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
980            (l_return_status = FND_API.G_RET_STS_ERROR) then
981 	  close l_get_page_tl_csr;
982 	  close l_get_pages_csr;
983           RAISE FND_API.G_EXC_ERROR;
984         end if;
985 
986         l_databuffer_tbl.delete;
987 
988         -- Load Page regions (AK_FLOW_PAGE_REGIONS) and their page region
989         -- item (AK_FLOW_PAGE_REGION_ITEMS)
990         WRITE_REGIONS_TO_BUFFER (
991           p_validation_level => p_validation_level,
992           p_return_status => l_return_status,
993           p_flow_application_id => p_flow_application_id,
994           p_flow_code => p_flow_code,
995           p_page_application_id => l_pages_rec.page_application_id,
996           p_page_code => l_pages_rec.page_code
997         );
998         --
999         -- Download aborts if validation fails in WRITE_REGIONS_TO_BUFFER
1000 	    --
1001         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
1002           (l_return_status = FND_API.G_RET_STS_ERROR) then
1003 	  close l_get_page_tl_csr;
1004 	  close l_get_pages_csr;
1005           RAISE FND_API.G_EXC_ERROR;
1006         end if;
1007 
1008         -- finish up flow page
1009         l_index := 1;
1010         l_databuffer_tbl(l_index) := '  END FLOW_PAGE';
1011         l_index := l_index + 1;
1012         l_databuffer_tbl(l_index) := ' ';
1013       end if; -- validation OK --
1014 
1015       -- - Finish up writing flow page data out to the specified file
1016       AK_ON_OBJECTS_PVT.WRITE_FILE (
1017         p_return_status => l_return_status,
1018         p_buffer_tbl => l_databuffer_tbl,
1019         p_write_mode => AK_ON_OBJECTS_PUB.G_APPEND
1020       );
1021       -- If API call returns with an error status...
1022       if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
1023          (l_return_status = FND_API.G_RET_STS_ERROR) then
1024 	close l_get_page_tl_csr;
1025 	close l_get_pages_csr;
1026         RAISE FND_API.G_EXC_ERROR;
1027       end if;
1028 
1029       l_databuffer_tbl.delete;
1030 
1031     end if;  -- if TL record found --
1032     close l_get_page_tl_csr;
1033   end loop;
1034   close l_get_pages_csr;
1035 
1036   p_return_status := FND_API.G_RET_STS_SUCCESS;
1037 
1041       FND_MESSAGE.SET_NAME('AK','AK_FLOW_PAGE_VALUE_ERROR');
1038 EXCEPTION
1039   WHEN VALUE_ERROR THEN
1040     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1042       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_flow_application_id) ||
1043                    ' ' || p_flow_code ||
1044                    ' ' || to_char(l_pages_rec.page_application_id) ||
1045                    ' ' || l_pages_rec.page_code );
1046       FND_MSG_PUB.Add;
1047     end if;
1048     p_return_status := FND_API.G_RET_STS_ERROR;
1049   WHEN FND_API.G_EXC_ERROR THEN
1050     p_return_status := FND_API.G_RET_STS_ERROR;
1051   WHEN OTHERS THEN
1052     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1053     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
1054                            SUBSTR (SQLERRM, 1, 240) );
1055     FND_MSG_PUB.Add;
1056 end WRITE_PAGES_TO_BUFFER;
1057 
1058 --=======================================================
1059 --  Procedure   WRITE_RELATIONS_TO_BUFFER (local procedure)
1060 --
1061 --  Usage       Local procedure for writing all interpage flow region
1062 --              relation records for the given flow to the output file.
1063 --              Not designed to be called from outside this package.
1064 --
1065 --  Desc        This procedure retrieves all interpage Flow Region Relation
1066 --              records for the given Flow from the database and
1067 --              writes them to the output file in loader file format.
1068 --              Note: All intrapage region relations will be written along
1069 --              with flow page regions information.
1070 --
1071 --
1072 --  Results     The API returns the standard p_return_status parameter
1073 --              indicating one of the standard return statuses :
1074 --                  * Unexpected error
1075 --                  * Error
1076 --                  * Success
1077 --  Parameters
1078 --              p_flow_application_id : IN required
1079 --              p_flow_code : IN required
1080 --                  Key value of the Flow record whose Flow Region
1081 --                  Relation records are to be extracted to the loader file.
1082 --=======================================================
1083 procedure WRITE_RELATIONS_TO_BUFFER (
1084   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
1085   p_return_status            OUT NOCOPY     VARCHAR2,
1086   p_flow_application_id      IN      NUMBER,
1087   p_flow_code                IN      VARCHAR2
1088 ) is
1089   cursor l_get_relations_csr is
1090     select *
1091     from   AK_FLOW_REGION_RELATIONS
1092     where  FLOW_APPLICATION_ID = p_flow_application_id
1093     and    FLOW_CODE = p_flow_code
1094     and    ( (FROM_PAGE_APPL_ID <> TO_PAGE_APPL_ID) or
1095              (FROM_PAGE_CODE <> TO_PAGE_CODE) );
1096   l_api_name           CONSTANT varchar2(30) := 'Write_Relations_to_buffer';
1097   l_databuffer_tbl     AK_ON_OBJECTS_PUB.Buffer_Tbl_Type;
1098   l_index              NUMBER;
1099   l_relations_rec      AK_FLOW_REGION_RELATIONS%ROWTYPE;
1100   l_return_status      varchar2(1);
1101 begin
1102   -- Find out where the next buffer entry to be written to
1103   l_index := 1;
1104 
1105   -- Retrieve region relations information from the database
1106 
1107   open l_get_relations_csr;
1108   loop
1109     fetch l_get_relations_csr into l_relations_rec;
1110     exit when l_get_relations_csr%notfound;
1111     -- write this flow region relation if it is validated
1112     if (p_validation_level <> FND_API.G_VALID_LEVEL_NONE) and
1113           not AK_FLOW3_PVT.VALIDATE_REGION_RELATION (
1114             p_validation_level => p_validation_level,
1115             p_api_version_number => 1.0,
1116             p_return_status => l_return_status,
1117             p_flow_application_id => p_flow_application_id,
1118             p_flow_code => p_flow_code,
1119             p_foreign_key_name => l_relations_rec.foreign_key_name,
1120             p_from_page_appl_id => l_relations_rec.from_page_appl_id,
1121             p_from_page_code => l_relations_rec.from_page_code,
1122             p_from_region_appl_id => l_relations_rec.from_region_appl_id,
1123             p_from_region_code => l_relations_rec.from_region_code,
1124             p_to_page_appl_id => l_relations_rec.to_page_appl_id,
1125             p_to_page_code => l_relations_rec.to_page_code,
1126             p_to_region_appl_id => l_relations_rec.to_region_appl_id,
1127             p_to_region_code => l_relations_rec.to_region_code,
1128             p_application_id => l_relations_rec.application_id,
1129             p_caller => AK_ON_OBJECTS_PVT.G_DOWNLOAD)
1130     then
1131         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
1132           FND_MESSAGE.SET_NAME('AK','AK_RELATION_NOT_DOWNLOADED');
1133           FND_MESSAGE.SET_TOKEN('KEY', to_char(p_flow_application_id) ||
1134                           ' ' || p_flow_code ||
1135                           ' ' || l_relations_rec.foreign_key_name ||
1136                           ' ' || to_char(l_relations_rec.from_page_appl_id) ||
1137                           ' ' || l_relations_rec.from_page_code ||
1138                           ' ' || to_char(l_relations_rec.from_region_appl_id)||
1139                           ' ' || l_relations_rec.from_region_code ||
1140                           ' ' || to_char(l_relations_rec.to_page_appl_id) ||
1141                           ' ' || l_relations_rec.to_page_code ||
1142                           ' ' || to_char(l_relations_rec.to_region_appl_id) ||
1143                           ' ' || l_relations_rec.to_region_code);
1144          FND_MSG_PUB.Add;
1145         end if;
1146 	close l_get_relations_csr;
1150       l_index := l_index + 1;
1147         RAISE FND_API.G_EXC_ERROR;
1148     else
1149       l_databuffer_tbl(l_index) := ' ';
1151       l_databuffer_tbl(l_index) := '  BEGIN FLOW_REGION_RELATION "' ||
1152        AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_relations_rec.foreign_key_name)
1153        || '" "' ||
1154        nvl(to_char(l_relations_rec.from_page_appl_id),'') || '" "' ||
1155        AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_relations_rec.from_page_code)
1156         || '" "' ||
1157        nvl(to_char(l_relations_rec.from_region_appl_id),'') || '" "' ||
1158        AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_relations_rec.from_region_code)
1159         || '" "' ||
1160        nvl(to_char(l_relations_rec.to_page_appl_id),'') || '" "' ||
1161        AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_relations_rec.to_page_code)
1162         || '" "' ||
1163        nvl(to_char(l_relations_rec.to_region_appl_id),'') || '" "' ||
1164        AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_relations_rec.to_region_code)
1165         || '"';
1166       l_index := l_index + 1;
1167       l_databuffer_tbl(l_index) := '    APPLICATION_ID = "' ||
1168         nvl(to_char(l_relations_rec.application_id),'') || '"';
1169       -- Flex Fields
1170       --
1171       if ((l_relations_rec.attribute_category IS NOT NULL) and
1172          (l_relations_rec.attribute_category <> FND_API.G_MISS_CHAR)) then
1173         l_index := l_index + 1;
1174         l_databuffer_tbl(l_index) := '    ATTRIBUTE_CATEGORY = "' ||
1175           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1176                      l_relations_rec.attribute_category) || '"';
1177       end if;
1178       if ((l_relations_rec.attribute1 IS NOT NULL) and
1179          (l_relations_rec.attribute1 <> FND_API.G_MISS_CHAR)) then
1180         l_index := l_index + 1;
1181         l_databuffer_tbl(l_index) := '    ATTRIBUTE1 = "' ||
1182           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1183                      l_relations_rec.attribute1) || '"';
1184       end if;
1185       if ((l_relations_rec.attribute2 IS NOT NULL) and
1186          (l_relations_rec.attribute2 <> FND_API.G_MISS_CHAR)) then
1187         l_index := l_index + 1;
1188         l_databuffer_tbl(l_index) := '    ATTRIBUTE2 = "' ||
1189           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1190                      l_relations_rec.attribute2) || '"';
1191       end if;
1192       if ((l_relations_rec.attribute3 IS NOT NULL) and
1193          (l_relations_rec.attribute3 <> FND_API.G_MISS_CHAR)) then
1194         l_index := l_index + 1;
1195         l_databuffer_tbl(l_index) := '    ATTRIBUTE3 = "' ||
1196           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1197                      l_relations_rec.attribute3) || '"';
1198       end if;
1199       if ((l_relations_rec.attribute4 IS NOT NULL) and
1200          (l_relations_rec.attribute4 <> FND_API.G_MISS_CHAR)) then
1201         l_index := l_index + 1;
1202         l_databuffer_tbl(l_index) := '    ATTRIBUTE4 = "' ||
1203           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1204                      l_relations_rec.attribute4) || '"';
1205       end if;
1206       if ((l_relations_rec.attribute5 IS NOT NULL) and
1207          (l_relations_rec.attribute5 <> FND_API.G_MISS_CHAR)) then
1208         l_index := l_index + 1;
1209         l_databuffer_tbl(l_index) := '    ATTRIBUTE5 = "' ||
1210           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1211                      l_relations_rec.attribute5) || '"';
1212       end if;
1213       if ((l_relations_rec.attribute6 IS NOT NULL) and
1214          (l_relations_rec.attribute6 <> FND_API.G_MISS_CHAR)) then
1215         l_index := l_index + 1;
1216         l_databuffer_tbl(l_index) := '    ATTRIBUTE6 = "' ||
1217           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1218                      l_relations_rec.attribute6) || '"';
1219       end if;
1220       if ((l_relations_rec.attribute7 IS NOT NULL) and
1221          (l_relations_rec.attribute7 <> FND_API.G_MISS_CHAR)) then
1222         l_index := l_index + 1;
1223         l_databuffer_tbl(l_index) := '    ATTRIBUTE7 = "' ||
1224           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1225                      l_relations_rec.attribute7) || '"';
1226       end if;
1227       if ((l_relations_rec.attribute8 IS NOT NULL) and
1228          (l_relations_rec.attribute8 <> FND_API.G_MISS_CHAR)) then
1229         l_index := l_index + 1;
1230         l_databuffer_tbl(l_index) := '    ATTRIBUTE8 = "' ||
1231           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1232                      l_relations_rec.attribute8) || '"';
1233       end if;
1234       if ((l_relations_rec.attribute9 IS NOT NULL) and
1235          (l_relations_rec.attribute9 <> FND_API.G_MISS_CHAR)) then
1236         l_index := l_index + 1;
1237         l_databuffer_tbl(l_index) := '    ATTRIBUTE9 = "' ||
1238           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1239                      l_relations_rec.attribute9) || '"';
1240       end if;
1241       if ((l_relations_rec.attribute10 IS NOT NULL) and
1242          (l_relations_rec.attribute10 <> FND_API.G_MISS_CHAR)) then
1243         l_index := l_index + 1;
1244         l_databuffer_tbl(l_index) := '    ATTRIBUTE10 = "' ||
1245           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1246                      l_relations_rec.attribute10) || '"';
1247       end if;
1248       if ((l_relations_rec.attribute11 IS NOT NULL) and
1249          (l_relations_rec.attribute11 <> FND_API.G_MISS_CHAR)) then
1250         l_index := l_index + 1;
1251         l_databuffer_tbl(l_index) := '    ATTRIBUTE11 = "' ||
1252           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1253                      l_relations_rec.attribute11) || '"';
1254       end if;
1258         l_databuffer_tbl(l_index) := '    ATTRIBUTE12 = "' ||
1255       if ((l_relations_rec.attribute12 IS NOT NULL) and
1256          (l_relations_rec.attribute12 <> FND_API.G_MISS_CHAR)) then
1257         l_index := l_index + 1;
1259           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1260                      l_relations_rec.attribute12) || '"';
1261       end if;
1262       if ((l_relations_rec.attribute13 IS NOT NULL) and
1263          (l_relations_rec.attribute13 <> FND_API.G_MISS_CHAR)) then
1264         l_index := l_index + 1;
1265         l_databuffer_tbl(l_index) := '    ATTRIBUTE13 = "' ||
1266           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1267                      l_relations_rec.attribute13) || '"';
1268       end if;
1269       if ((l_relations_rec.attribute14 IS NOT NULL) and
1270          (l_relations_rec.attribute14 <> FND_API.G_MISS_CHAR)) then
1271         l_index := l_index + 1;
1272         l_databuffer_tbl(l_index) := '    ATTRIBUTE14 = "' ||
1273           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1274                      l_relations_rec.attribute14) || '"';
1275       end if;
1276       if ((l_relations_rec.attribute15 IS NOT NULL) and
1277          (l_relations_rec.attribute15 <> FND_API.G_MISS_CHAR)) then
1278         l_index := l_index + 1;
1279         l_databuffer_tbl(l_index) := '    ATTRIBUTE15 = "' ||
1280           AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1281                      l_relations_rec.attribute15) || '"';
1282       end if;
1283   -- - Write out who columns
1284     l_index := l_index + 1;
1285     l_databuffer_tbl(l_index) := '    CREATED_BY = "' ||
1286                 nvl(to_char(l_relations_rec.created_by),'') || '"';
1287     l_index := l_index + 1;
1288     l_databuffer_tbl(l_index) := '    CREATION_DATE = "' ||
1289                 to_char(l_relations_rec.creation_date,
1290                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT) || '"';
1291     l_index := l_index + 1;
1292 -- CHANGED TO OWNER FOR R12
1293 --    l_databuffer_tbl(l_index) := '    LAST_UPDATED_BY = "' ||
1294 --                nvl(to_char(l_relations_rec.last_updated_by),'') || '"';
1295     l_databuffer_tbl(l_index) := '    OWNER = "' ||
1296                 FND_LOAD_UTIL.OWNER_NAME(l_relations_rec.last_updated_by) || '"';
1297     l_index := l_index + 1;
1298     l_databuffer_tbl(l_index) := '    LAST_UPDATE_DATE = "' ||
1299                 to_char(l_relations_rec.last_update_date,
1300                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT) || '"';
1301     l_index := l_index + 1;
1302     l_databuffer_tbl(l_index) := '    LAST_UPDATE_LOGIN = "' ||
1303                 nvl(to_char(l_relations_rec.last_update_login),'') || '"';
1304 
1305 
1306       -- finish up flow region relations
1307       l_index := l_index + 1;
1308       l_databuffer_tbl(l_index) := '  END FLOW_REGION_RELATION';
1309       l_index := l_index + 1;
1310       l_databuffer_tbl(l_index) := ' ';
1311     end if; -- validation OK --
1312 
1313   end loop;
1314 
1315   -- - Write relation data out to the specified file
1316   --   don't call write_file if there is no data to be written
1317   if (l_databuffer_tbl.count > 0) then
1318     AK_ON_OBJECTS_PVT.WRITE_FILE (
1319       p_return_status => l_return_status,
1320       p_buffer_tbl => l_databuffer_tbl,
1321       p_write_mode => AK_ON_OBJECTS_PUB.G_APPEND
1322     );
1323     -- If API call returns with an error status...
1324     if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
1325        (l_return_status = FND_API.G_RET_STS_ERROR) then
1326       close l_get_relations_csr;
1327       RAISE FND_API.G_EXC_ERROR;
1328     end if;
1329   end if;
1330 
1331   close l_get_relations_csr;
1332 
1333   p_return_status := FND_API.G_RET_STS_SUCCESS;
1334 
1335 EXCEPTION
1336   WHEN VALUE_ERROR THEN
1337     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1338       FND_MESSAGE.SET_NAME('AK','AK_RELATION_VALUE_ERROR');
1339       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_flow_application_id) ||
1340                           ' ' || p_flow_code ||
1341                           ' ' || l_relations_rec.foreign_key_name ||
1342                           ' ' || to_char(l_relations_rec.from_page_appl_id) ||
1343                           ' ' || l_relations_rec.from_page_code ||
1344                           ' ' || to_char(l_relations_rec.from_region_appl_id)||
1345                           ' ' || l_relations_rec.from_region_code ||
1346                           ' ' || to_char(l_relations_rec.to_page_appl_id) ||
1347                           ' ' || l_relations_rec.to_page_code ||
1348                           ' ' || to_char(l_relations_rec.to_region_appl_id) ||
1349                           ' ' || l_relations_rec.to_region_code);
1350       FND_MSG_PUB.Add;
1351     end if;
1352     p_return_status := FND_API.G_RET_STS_ERROR;
1353   WHEN FND_API.G_EXC_ERROR THEN
1354     p_return_status := FND_API.G_RET_STS_ERROR;
1355   WHEN OTHERS THEN
1356     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1357     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
1358                            SUBSTR (SQLERRM, 1, 240) );
1359     FND_MSG_PUB.Add;
1360 end WRITE_RELATIONS_TO_BUFFER;
1361 
1362 --=======================================================
1363 --  Procedure   WRITE_TO_BUFFER (local procedure)
1364 --
1365 --  Usage       Local procedure for writing the given flow
1366 --              and all its children records to the output file.
1367 --              Not designed to be called from outside this package.
1368 --
1369 --  Desc        This procedure first retrieves and writes the given
1370 --              flow to the loader file. Then it calls other local
1374 --
1371 --              procedures to write all its flow pages, flow page
1372 --              regions, flow page region items, and flow region
1373 --              relations to the same output file.
1375 --  Results     The API returns the standard p_return_status parameter
1376 --              indicating one of the standard return statuses :
1377 --                  * Unexpected error
1378 --                  * Error
1379 --                  * Success
1380 --  Parameters
1381 --              p_database_object_name : IN required
1382 --                  Key value of the Object to be extracted to the loader
1383 --                  file.
1384 --              p_nls_language : IN required
1385 --                  The NLS langauge that should be used when
1386 --                  extracting data from the TL table
1387 --=======================================================
1388 procedure WRITE_TO_BUFFER (
1389   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
1390   p_return_status            OUT NOCOPY     VARCHAR2,
1391   p_flow_application_id      IN      NUMBER,
1392   p_flow_code                IN      VARCHAR2,
1393   p_nls_language             IN      VARCHAR2
1394 ) is
1395   cursor l_get_flow_csr is
1396     select *
1397     from  AK_FLOWS
1398     where flow_application_id = p_flow_application_id
1399     and   flow_code = p_flow_code;
1400   cursor l_get_flow_tl_csr is
1401     select *
1402     from  AK_FLOWS_TL
1403     where flow_application_id = p_flow_application_id
1404     and   flow_code = p_flow_code
1405     and   LANGUAGE = p_nls_language;
1406   l_api_name           CONSTANT varchar2(30) := 'Write_to_buffer';
1407   l_databuffer_tbl     AK_ON_OBJECTS_PUB.Buffer_Tbl_Type;
1408   l_index              NUMBER;
1409   l_flows_rec          AK_FLOWS%ROWTYPE;
1410   l_flows_tl_rec       AK_FLOWS_TL%ROWTYPE;
1411   l_return_status      varchar2(1);
1412 begin
1413   -- Retrieve flow information from the database
1414 
1415   open l_get_flow_csr;
1416   fetch l_get_flow_csr into l_flows_rec;
1417   if (l_get_flow_csr%notfound) then
1418     close l_get_flow_csr;
1419     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
1420       FND_MESSAGE.SET_NAME('AK','AK_FLOW_DOES_NOT_EXIST');
1421       FND_MSG_PUB.Add;
1422     end if;
1423     RAISE FND_API.G_EXC_ERROR;
1424   end if;
1425   close l_get_flow_csr;
1426 
1427   open l_get_flow_tl_csr;
1428   fetch l_get_flow_tl_csr into l_flows_tl_rec;
1429   if (l_get_flow_tl_csr%notfound) then
1430     close l_get_flow_tl_csr;
1431     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
1432       FND_MESSAGE.SET_NAME('AK','AK_FLOW_DOES_NOT_EXIST');
1433       FND_MSG_PUB.Add;
1434     end if;
1435     RAISE FND_API.G_EXC_ERROR;
1436   end if;
1437   close l_get_flow_tl_csr;
1438 
1439   -- Flow must be validated before it is written to the file
1440   if p_validation_level <> FND_API.G_VALID_LEVEL_NONE then
1441     if not AK_FLOW3_PVT.VALIDATE_FLOW (
1442 	p_validation_level => p_validation_level,
1443 	p_api_version_number => 1.0,
1444 	p_return_status => l_return_status,
1445         p_flow_application_id => l_flows_rec.flow_application_id,
1446         p_flow_code => l_flows_rec.flow_code,
1447         p_primary_page_appl_id => l_flows_rec.primary_page_appl_id,
1448         p_primary_page_code => l_flows_rec.primary_page_code,
1449         p_name => l_flows_tl_rec.name,
1450         p_description => l_flows_tl_rec.description,
1451  	p_caller => AK_ON_OBJECTS_PVT.G_DOWNLOAD)
1452     then
1453       raise FND_API.G_EXC_ERROR;
1454     end if;
1455   end if;
1456 
1457   -- Write flow into buffer
1458   l_index := 1;
1459 
1460   l_databuffer_tbl(l_index) := 'BEGIN FLOW "' ||
1461      nvl(to_char(l_flows_rec.flow_application_id),'') || '" "' ||
1462      AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_flows_rec.flow_code) || '"';
1463   l_index := l_index + 1;
1464   l_databuffer_tbl(l_index) := '  PRIMARY_PAGE = "' ||
1465     nvl(to_char(l_flows_rec.primary_page_appl_id),'')||'" "'||
1466     AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_flows_rec.primary_page_code)||'"';
1467   -- Flex Fields
1468   --
1469   if ((l_flows_rec.attribute_category IS NOT NULL) and
1470      (l_flows_rec.attribute_category <> FND_API.G_MISS_CHAR)) then
1471     l_index := l_index + 1;
1472     l_databuffer_tbl(l_index) := '  ATTRIBUTE_CATEGORY = "' ||
1473       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1474                  l_flows_rec.attribute_category) || '"';
1475   end if;
1476   if ((l_flows_rec.attribute1 IS NOT NULL) and
1477      (l_flows_rec.attribute1 <> FND_API.G_MISS_CHAR)) then
1478     l_index := l_index + 1;
1479     l_databuffer_tbl(l_index) := '  ATTRIBUTE1 = "' ||
1480       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1481                  l_flows_rec.attribute1) || '"';
1482   end if;
1483   if ((l_flows_rec.attribute2 IS NOT NULL) and
1484      (l_flows_rec.attribute2 <> FND_API.G_MISS_CHAR)) then
1485     l_index := l_index + 1;
1486     l_databuffer_tbl(l_index) := '  ATTRIBUTE2 = "' ||
1487       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1488                  l_flows_rec.attribute2) || '"';
1489   end if;
1490   if ((l_flows_rec.attribute3 IS NOT NULL) and
1491      (l_flows_rec.attribute3 <> FND_API.G_MISS_CHAR)) then
1492     l_index := l_index + 1;
1493     l_databuffer_tbl(l_index) := '  ATTRIBUTE3 = "' ||
1494       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1495                  l_flows_rec.attribute3) || '"';
1496   end if;
1497   if ((l_flows_rec.attribute4 IS NOT NULL) and
1501       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1498      (l_flows_rec.attribute4 <> FND_API.G_MISS_CHAR)) then
1499     l_index := l_index + 1;
1500     l_databuffer_tbl(l_index) := '  ATTRIBUTE4 = "' ||
1502                  l_flows_rec.attribute4) || '"';
1503   end if;
1504   if ((l_flows_rec.attribute5 IS NOT NULL) and
1505      (l_flows_rec.attribute5 <> FND_API.G_MISS_CHAR)) then
1506     l_index := l_index + 1;
1507     l_databuffer_tbl(l_index) := '  ATTRIBUTE5 = "' ||
1508       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1509                  l_flows_rec.attribute5) || '"';
1510   end if;
1511   if ((l_flows_rec.attribute6 IS NOT NULL) and
1512      (l_flows_rec.attribute6 <> FND_API.G_MISS_CHAR)) then
1513     l_index := l_index + 1;
1514     l_databuffer_tbl(l_index) := '  ATTRIBUTE6 = "' ||
1515       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1516                  l_flows_rec.attribute6) || '"';
1517   end if;
1518   if ((l_flows_rec.attribute7 IS NOT NULL) and
1519      (l_flows_rec.attribute7 <> FND_API.G_MISS_CHAR)) then
1520     l_index := l_index + 1;
1521     l_databuffer_tbl(l_index) := '  ATTRIBUTE7 = "' ||
1522       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1523                  l_flows_rec.attribute7) || '"';
1524   end if;
1525   if ((l_flows_rec.attribute8 IS NOT NULL) and
1526      (l_flows_rec.attribute8 <> FND_API.G_MISS_CHAR)) then
1527     l_index := l_index + 1;
1528     l_databuffer_tbl(l_index) := '  ATTRIBUTE8 = "' ||
1529       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1530                  l_flows_rec.attribute8) || '"';
1531   end if;
1532   if ((l_flows_rec.attribute9 IS NOT NULL) and
1533      (l_flows_rec.attribute9 <> FND_API.G_MISS_CHAR)) then
1534     l_index := l_index + 1;
1535     l_databuffer_tbl(l_index) := '  ATTRIBUTE9 = "' ||
1536       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1537                  l_flows_rec.attribute9) || '"';
1538   end if;
1539   if ((l_flows_rec.attribute10 IS NOT NULL) and
1540      (l_flows_rec.attribute10 <> FND_API.G_MISS_CHAR)) then
1541     l_index := l_index + 1;
1542     l_databuffer_tbl(l_index) := '  ATTRIBUTE10 = "' ||
1543       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1544                  l_flows_rec.attribute10) || '"';
1545   end if;
1546   if ((l_flows_rec.attribute11 IS NOT NULL) and
1547      (l_flows_rec.attribute11 <> FND_API.G_MISS_CHAR)) then
1548     l_index := l_index + 1;
1549     l_databuffer_tbl(l_index) := '  ATTRIBUTE11 = "' ||
1550       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1551                  l_flows_rec.attribute11) || '"';
1552   end if;
1553   if ((l_flows_rec.attribute12 IS NOT NULL) and
1554      (l_flows_rec.attribute12 <> FND_API.G_MISS_CHAR)) then
1555     l_index := l_index + 1;
1556     l_databuffer_tbl(l_index) := '  ATTRIBUTE12 = "' ||
1557       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1558                  l_flows_rec.attribute12) || '"';
1559   end if;
1560   if ((l_flows_rec.attribute13 IS NOT NULL) and
1561      (l_flows_rec.attribute13 <> FND_API.G_MISS_CHAR)) then
1562     l_index := l_index + 1;
1563     l_databuffer_tbl(l_index) := '  ATTRIBUTE13 = "' ||
1564       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1565                  l_flows_rec.attribute13) || '"';
1566   end if;
1567   if ((l_flows_rec.attribute14 IS NOT NULL) and
1568      (l_flows_rec.attribute14 <> FND_API.G_MISS_CHAR)) then
1569     l_index := l_index + 1;
1570     l_databuffer_tbl(l_index) := '  ATTRIBUTE14 = "' ||
1571       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1572                  l_flows_rec.attribute14) || '"';
1573   end if;
1574   if ((l_flows_rec.attribute15 IS NOT NULL) and
1575      (l_flows_rec.attribute15 <> FND_API.G_MISS_CHAR)) then
1576     l_index := l_index + 1;
1577     l_databuffer_tbl(l_index) := '  ATTRIBUTE15 = "' ||
1578       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(
1579                  l_flows_rec.attribute15) || '"';
1580   end if;
1581   -- - Write out who columns
1582     l_index := l_index + 1;
1583     l_databuffer_tbl(l_index) := '  CREATED_BY = "' ||
1584                 nvl(to_char(l_flows_rec.created_by),'') || '"';
1585     l_index := l_index + 1;
1586     l_databuffer_tbl(l_index) := '  CREATION_DATE = "' ||
1587                 to_char(l_flows_rec.creation_date,
1588                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT) || '"';
1589     l_index := l_index + 1;
1590 -- CHANGED TO OWNER FOR R12
1591 --    l_databuffer_tbl(l_index) := '  LAST_UPDATED_BY = "' ||
1592 --                nvl(to_char(l_flows_rec.last_updated_by),'') || '"';
1593     l_databuffer_tbl(l_index) := '  OWNER = "' ||
1594                 FND_LOAD_UTIL.OWNER_NAME(l_flows_rec.last_updated_by) || '"';
1595     l_index := l_index + 1;
1596     l_databuffer_tbl(l_index) := '  LAST_UPDATE_DATE = "' ||
1597                 to_char(l_flows_rec.last_update_date,
1598                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT) || '"';
1599     l_index := l_index + 1;
1600     l_databuffer_tbl(l_index) := '  LAST_UPDATE_LOGIN = "' ||
1601                 nvl(to_char(l_flows_rec.last_update_login),'') || '"';
1602 
1603   -- translation columns
1604   --
1605   if (l_flows_tl_rec.name IS NOT NULL) and
1606      (l_flows_tl_rec.name <> FND_API.G_MISS_CHAR) then
1607     l_index := l_index + 1;
1608     l_databuffer_tbl(l_index) := '  NAME = "' ||
1609       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_flows_tl_rec.name) || '"';
1610   end if;
1611   if ((l_flows_tl_rec.description IS NOT NULL) and
1612      (l_flows_tl_rec.description <> FND_API.G_MISS_CHAR)) then
1613     l_index := l_index + 1;
1614     l_databuffer_tbl(l_index) := '  DESCRIPTION = "' ||
1618   -- - Write flow data out to the specified file
1615       AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_flows_tl_rec.description) || '"';
1616   end if;
1617 
1619   AK_ON_OBJECTS_PVT.WRITE_FILE (
1620     p_return_status => l_return_status,
1621     p_buffer_tbl => l_databuffer_tbl,
1622     p_write_mode => AK_ON_OBJECTS_PUB.G_APPEND
1623   );
1624 --  dbms_output.put_line('after write file');
1625   -- If API call returns with an error status...
1626   if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
1627      (l_return_status = FND_API.G_RET_STS_ERROR) then
1628     RAISE FND_API.G_EXC_ERROR;
1629   end if;
1630 
1631   l_databuffer_tbl.delete;
1632 
1633   WRITE_PAGES_TO_BUFFER (
1634     p_validation_level => p_validation_level,
1635     p_return_status => l_return_status,
1636     p_flow_application_id => p_flow_application_id,
1637     p_flow_code => p_flow_code,
1638     p_nls_language => p_nls_language
1639   );
1640   if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
1641      (l_return_status = FND_API.G_RET_STS_ERROR) then
1642     RAISE FND_API.G_EXC_ERROR;
1643   end if;
1644 
1645   WRITE_RELATIONS_TO_BUFFER (
1646     p_validation_level => p_validation_level,
1647     p_return_status => l_return_status,
1648     p_flow_application_id => p_flow_application_id,
1649     p_flow_code => p_flow_code
1650   );
1651   if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
1652      (l_return_status = FND_API.G_RET_STS_ERROR) then
1653     RAISE FND_API.G_EXC_ERROR;
1654   end if;
1655 
1656   l_index := 1;
1657   l_databuffer_tbl(l_index) := 'END FLOW';
1658   l_index := l_index + 1;
1659   l_databuffer_tbl(l_index) := ' ';
1660 
1661   -- - Finish up writing flow data out to the specified file
1662   AK_ON_OBJECTS_PVT.WRITE_FILE (
1663     p_return_status => l_return_status,
1664     p_buffer_tbl => l_databuffer_tbl,
1665     p_write_mode => AK_ON_OBJECTS_PUB.G_APPEND
1666   );
1667   -- If API call returns with an error status...
1668   if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
1669      (l_return_status = FND_API.G_RET_STS_ERROR) then
1670     RAISE FND_API.G_EXC_ERROR;
1671   end if;
1672 
1673   p_return_status := FND_API.G_RET_STS_SUCCESS;
1674 
1675 EXCEPTION
1676   WHEN VALUE_ERROR THEN
1677     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1678       FND_MESSAGE.SET_NAME('AK','AK_FLOW_VALUE_ERROR');
1679       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_flow_application_id) ||
1680                           ' ' || p_flow_code);
1681       FND_MSG_PUB.Add;
1682     end if;
1683     p_return_status := FND_API.G_RET_STS_ERROR;
1684   WHEN FND_API.G_EXC_ERROR THEN
1685     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1686       FND_MESSAGE.SET_NAME('AK','AK_FLOW_NOT_DOWNLOADED');
1687       FND_MESSAGE.SET_TOKEN('KEY', to_char(p_flow_application_id) ||
1688                           ' ' || p_flow_code);
1689       FND_MSG_PUB.Add;
1690     end if;
1691     p_return_status := FND_API.G_RET_STS_ERROR;
1692   WHEN OTHERS THEN
1693     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1694     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
1695                            SUBSTR (SQLERRM, 1, 240) );
1696     FND_MSG_PUB.Add;
1697 end WRITE_TO_BUFFER;
1698 
1699 --=======================================================
1700 --  Procedure   DOWNLOAD_FLOW
1701 --
1702 --  Usage       Private API for downloading flows. This
1703 --              API should only be called by other APIs that are
1704 --              owned by the Core Modules Team (AK).
1705 --
1706 --  Desc        This API will extract the flows selected
1707 --              by application ID or by key values from the
1708 --              database to the output file.
1709 --              If a flow is selected for writing to the loader
1710 --              file, all its children records (including flow pages,
1711 --              flow page regions, flow page region items, and flow
1712 --              region relations) will also be written.
1713 --
1714 --  Results     The API returns the standard p_return_status parameter
1715 --              indicating one of the standard return statuses :
1716 --                  * Unexpected error
1717 --                  * Error
1718 --                  * Success
1719 --  Parameters
1720 --              p_nls_language : IN optional
1721 --                  NLS language for database. If none if given,
1722 --                  the current NLS language will be used.
1723 --
1724 --              One of the following parameters must be provided:
1725 --
1726 --              p_application_id : IN optional
1727 --                  If given, all attributes for this application ID
1728 --                  will be written to the output file.
1729 --                  p_application_id will be ignored if a table is
1730 --                  given in p_flow_pk_tbl.
1731 --              p_flow_pk_tbl : IN optional
1732 --                  If given, only flows whose key values are
1733 --                  included in this table will be written to the
1734 --                  output file.
1735 --
1736 --  Version     Initial version number  =   1.0
1737 --  History     Current version number  =   1.0
1738 --=======================================================
1739 procedure DOWNLOAD_FLOW (
1740   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
1741   p_api_version_number       IN      NUMBER,
1742   p_return_status            OUT NOCOPY     VARCHAR2,
1746   p_nls_language             IN      VARCHAR2
1743   p_application_id           IN      NUMBER := FND_API.G_MISS_NUM,
1744   p_flow_pk_tbl              IN      AK_FLOW_PUB.Flow_PK_Tbl_Type
1745                                      := AK_FLOW_PUB.G_MISS_FLOW_PK_TBL,
1747 ) is
1748   cursor l_get_flow_list_csr (appl_id_parm number) is
1749     select flow_application_id, flow_code
1750     from   AK_FLOWS
1751     where  FLOW_APPLICATION_ID = appl_id_parm;
1752   cursor l_get_regions_csr (flow_appl_id_param number,
1753                             flow_code_param varchar2) is
1754     select distinct REGION_APPLICATION_ID, REGION_CODE
1755     from   AK_FLOW_PAGE_REGIONS
1756     where  flow_application_id = flow_appl_id_param
1757     and    flow_code = flow_code_param;
1758   l_api_version_number CONSTANT number := 1.0;
1759   l_api_name           CONSTANT varchar2(30) := 'Download_Flow';
1760   l_index              NUMBER;
1761   l_msg_count          NUMBER;
1762   l_msg_data           VARCHAR2(2000);
1763   l_flow_pk_tbl        AK_FLOW_PUB.Flow_PK_Tbl_Type;
1764   l_region_appl_id     NUMBER(15);
1765   l_region_code        VARCHAR2(30);
1766   l_region_pk_tbl      AK_REGION_PUB.Region_PK_Tbl_Type;
1767   l_return_status      varchar2(1);
1768 begin
1769   IF NOT FND_API.Compatible_API_Call (
1770     l_api_version_number, p_api_version_number, l_api_name,
1771     G_PKG_NAME) then
1772       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1773       return;
1774   END IF;
1775 
1776 
1777   -- Check that one of the following selection criteria is given:
1778   -- - p_application_id alone, or
1779   -- - flow codes in p_flow_PK_tbl
1780   if (p_application_id = FND_API.G_MISS_NUM) or (p_application_id is null) then
1781     if (p_flow_PK_tbl.count = 0) then
1782       if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1783         FND_MESSAGE.SET_NAME('AK','AK_NO_SELECTION');
1784         FND_MSG_PUB.Add;
1785       end if;
1786       raise FND_API.G_EXC_ERROR;
1787     end if;
1788   else
1789     if (p_flow_PK_tbl.count > 0) then
1790       -- both application ID and a list of flows to be extracted are
1791       -- given, issue a warning that we will ignore the application ID
1792       if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1793         FND_MESSAGE.SET_NAME('AK','AK_APPL_ID_IGNORED');
1794         FND_MSG_PUB.Add;
1795       end if;
1796     end if;
1797   end if;
1798 
1799   -- If selecting by application ID, first load a flow primary key table
1800   -- with the primary key of all flows for the given application ID.
1801   -- If selecting by a list of flows, simply copy the flow primary key
1802   -- table with the parameter
1803   if (p_flow_PK_tbl.count > 0) then
1804     l_flow_pk_tbl := p_flow_pk_tbl;
1805   else
1806     l_index := 1;
1807     open l_get_flow_list_csr(p_application_id);
1808     loop
1809       fetch l_get_flow_list_csr into l_flow_pk_tbl(l_index).flow_appl_id,
1810                                      l_flow_pk_tbl(l_index).flow_code;
1811       exit when l_get_flow_list_csr%notfound;
1812       l_index := l_index + 1;
1813     end loop;
1814     close l_get_flow_list_csr;
1815   end if;
1816 
1817   -- Build list of regions that are need by the flows to be extracted
1818   -- from the database.
1819   --
1820   l_index := l_flow_pk_tbl.FIRST;
1821 
1822   while (l_index is not null) loop
1823     --
1824     -- Build list of regions that are referenced by this flow, and
1825     -- add them to the region list.
1826     --
1827     open l_get_regions_csr (
1828                  l_flow_pk_tbl(l_index).flow_appl_id,
1829                  l_flow_pk_tbl(l_index).flow_code);
1830     loop
1831       fetch l_get_regions_csr into l_region_appl_id, l_region_code;
1832       exit when (l_get_regions_csr%notfound);
1833         AK_REGION_PVT.INSERT_REGION_PK_TABLE (
1834               p_return_status => l_return_status,
1835               p_region_application_id => l_region_appl_id,
1836               p_region_code => l_region_code,
1837               p_region_pk_tbl => l_region_pk_tbl);
1838     end loop;
1839     close l_get_regions_csr;
1840 
1841     -- Ready to download the next flow in the list
1842     l_index := l_flow_pk_tbl.NEXT(l_index);
1843   end loop;
1844 
1845   -- Download region information for regions that were based on any
1846   -- of the extracted flows.
1847 
1848   if (l_region_pk_tbl.count > 0) then
1849     AK_REGION_PVT.DOWNLOAD_REGION (
1850       p_validation_level => p_validation_level,
1851       p_api_version_number => 1.0,
1852       p_return_status => l_return_status,
1853       p_region_pk_tbl => l_region_pk_tbl,
1854       p_nls_language => p_nls_language,
1855       p_get_object_flag => 'Y'    -- Need to get objects for regions
1856     );
1857   end if;
1858 
1859   if (l_return_status = FND_API.G_RET_STS_ERROR) or
1860     (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) then
1861 	raise FND_API.G_EXC_ERROR;
1862   end if;
1863 
1864 
1865   -- Write details for each selected flow, including its flow pages,
1866   -- page regions, page region links, and region relations to a
1867   -- buffer to be passed back to the calling procedure.
1868   --
1869   l_index := l_flow_pk_tbl.FIRST;
1870   while (l_index is not null) loop
1871     -- Write flow information from the database
1872     if ( (l_flow_pk_tbl(l_index).flow_appl_id is not null) and
1873 	(l_flow_pk_tbl(l_index).flow_code is not null) ) then
1874       WRITE_TO_BUFFER(
1878 	p_flow_code => l_flow_pk_tbl(l_index).flow_code,
1875         p_validation_level => p_validation_level,
1876         p_return_status => l_return_status,
1877         p_flow_application_id => l_flow_pk_tbl(l_index).flow_appl_id,
1879         p_nls_language => p_nls_language
1880       );
1881     end if;
1882     -- Ready to download the next flow in the list
1883     l_index := l_flow_pk_tbl.NEXT(l_index);
1884   end loop;
1885 
1886 --dbms_output.put_line('returning from ak_flow_pvt.download_flow: ' ||
1887 --                        to_char(sysdate, 'MON-DD HH24:MI:SS'));
1888 
1889 --  p_buffer_tbl := l_region_buf_tbl;
1890     if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
1891        (l_return_status = FND_API.G_RET_STS_ERROR) then
1892       RAISE FND_API.G_EXC_ERROR;
1893     end if;
1894 
1895   p_return_status := FND_API.G_RET_STS_SUCCESS;
1896 
1897 EXCEPTION
1898   WHEN VALUE_ERROR THEN
1899     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1900       FND_MESSAGE.SET_NAME('AK','AK_FLOW_PK_VALUE_ERROR');
1901       FND_MESSAGE.SET_TOKEN('KEY', null);
1902       FND_MSG_PUB.Add;
1903     end if;
1904     p_return_status := FND_API.G_RET_STS_ERROR;
1905   WHEN FND_API.G_EXC_ERROR THEN
1906     p_return_status := FND_API.G_RET_STS_ERROR;
1907   WHEN OTHERS THEN
1908     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1909     FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name,
1910                            SUBSTR (SQLERRM, 1, 240) );
1911 end DOWNLOAD_FLOW;
1912 
1913 --=======================================================
1914 --  Procedure   UPLOAD_FLOW
1915 --
1916 --  Usage       Private API for loading flows from a
1917 --              loader file to the database.
1918 --              This API should only be called by other APIs
1919 --              that are owned by the Core Modules Team (AK).
1920 --
1921 --  Desc        This API reads the flow data (including flow pages,
1922 --              flow page regions, flow page region items, and
1923 --              flow region relations) stored in the loader file
1924 --              currently being processed, parses the data, and
1925 --              loads them to the database. The tables
1926 --              are updated with the timestamp passed. This API
1927 --              will process the file until the EOF is reached,
1928 --              a parse error is encountered, or when data for
1929 --              a different business object is read from the file.
1930 --
1931 --  Results     The API returns the standard p_return_status parameter
1932 --              indicating one of the standard return statuses :
1933 --                  * Unexpected error
1934 --                  * Error
1935 --                  * Success
1936 --  Parameters  p_index : IN OUT required
1937 --                  Index of PL/SQL file to be processed.
1938 --              p_loader_timestamp : IN required
1939 --                  The timestamp to be used when creating or updating
1940 --                  records
1941 --              p_line_num : IN optional
1942 --                  The first line number in the file to be processed.
1943 --                  It is used for keeping track of the line number
1944 --                  read so that this info can be included in the
1945 --                  error message when a parse error occurred.
1946 --              p_buffer : IN required
1947 --                  The content of the first line to be processed.
1948 --                  The calling API has already read the first line
1949 --                  that needs to be parsed by this API, so this
1950 --                  line won't be read from the file again.
1951 --              p_line_num_out : OUT
1952 --                  The number of the last line in the loader file
1953 --                  that is read by this API.
1954 --              p_buffer_out : OUT
1955 --                  The content of the last line read by this API.
1956 --                  If an EOF has not reached, this line would
1957 --                  contain the beginning of another business object
1958 --                  that will need to be processed by another API.
1959 --
1960 --  Version     Initial version number  =   1.0
1961 --  History     Current version number  =   1.0
1962 --=======================================================
1963 procedure UPLOAD_FLOW (
1964   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
1965   p_api_version_number       IN      NUMBER,
1966   p_return_status            OUT NOCOPY     VARCHAR2,
1967   p_index                    IN OUT NOCOPY  NUMBER,
1968   p_loader_timestamp         IN      DATE,
1969   p_line_num                 IN NUMBER := FND_API.G_MISS_NUM,
1970   p_buffer                   IN AK_ON_OBJECTS_PUB.Buffer_Type,
1971   p_line_num_out             OUT NOCOPY    NUMBER,
1972   p_buffer_out               OUT NOCOPY    AK_ON_OBJECTS_PUB.Buffer_Type,
1973   p_upl_loader_cur           IN OUT NOCOPY  AK_ON_OBJECTS_PUB.LoaderCurTyp,
1974   p_pass                     IN      NUMBER := 1
1975 ) is
1976   l_api_version_number       CONSTANT number := 1.0;
1977   l_api_name                 CONSTANT varchar2(30) := 'Upload_Object';
1978   l_buffer                   AK_ON_OBJECTS_PUB.Buffer_Type;
1979   l_column  	             varchar2(30);
1980   l_dummy                    NUMBER;
1981   l_eof_flag                 VARCHAR2(1);
1982   l_flow_index               NUMBER := 0;
1983   l_flow_rec                 AK_FLOW_PUB.Flow_Rec_Type;
1984   l_flow_tbl                 AK_FLOW_PUB.Flow_Tbl_Type;
1985   l_index                    NUMBER;
1986   l_item_index               NUMBER := 0;
1990   l_lines_read               NUMBER;
1987   l_item_rec                 AK_FLOW_PUB.Page_Region_Item_Rec_Type;
1988   l_item_tbl                 AK_FLOW_PUB.Page_Region_Item_Tbl_Type;
1989   l_line_num                 NUMBER;
1991   l_more_flow                BOOLEAN := TRUE;
1992   l_msg_count                NUMBER;
1993   l_msg_data                 VARCHAR2(2000);
1994   l_page_index               NUMBER := 0;
1995   l_page_rec                 AK_FLOW_PUB.Page_Rec_Type;
1996   l_page_tbl                 AK_FLOW_PUB.Page_Tbl_Type;
1997   l_region_index             NUMBER := 0;
1998   l_region_rec               AK_FLOW_PUB.Page_Region_Rec_Type;
1999   l_region_tbl               AK_FLOW_PUB.Page_Region_Tbl_Type;
2000   l_relation_index           NUMBER := 0;
2001   l_relation_rec             AK_FLOW_PUB.Region_Relation_Rec_Type;
2002   l_relation_tbl             AK_FLOW_PUB.Region_Relation_Tbl_Type;
2003   l_saved_token              AK_ON_OBJECTS_PUB.Buffer_Type;
2004   l_state                    NUMBER;
2005   l_return_status            varchar2(1);
2006   l_token                    AK_ON_OBJECTS_PUB.Buffer_Type;
2007   l_value_count              NUMBER;  -- # of values read for current column
2008   l_copy_redo_flag           BOOLEAN := FALSE;
2009   l_user_id1				 NUMBER;
2010   l_user_id2				 NUMBER;
2011   l_update1				 DATE;
2012   l_update2				 DATE;
2013   l_temp_key_code			 VARCHAR2(30);
2014   l_temp_key_appl_id		 NUMBER;
2015 begin
2016   -- dbms_output.put_line('Started flow upload:'  ||
2017   --                            to_char(sysdate, 'MON-DD HH24:MI:SS'));
2018 
2019   IF NOT FND_API.Compatible_API_Call (
2020     l_api_version_number, p_api_version_number, l_api_name,
2021     G_PKG_NAME) then
2022       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2023       return;
2024   END IF;
2025 
2026   SAVEPOINT Start_Upload;
2027 
2028   -- Retrieve the first non-blank, non-comment line
2029   l_state := 0;
2030   l_eof_flag := 'N';
2031   --
2032   -- if calling from ak_on_objects.upload (ie, loader timestamp is given),
2033   -- the tokens 'BEGIN FLOW' has already been parsed. Set initial
2034   -- buffer to 'BEGIN FLOW' before reading the next line from the
2035   -- file. Otherwise, set initial buffer to null.
2036   --
2037   if (p_loader_timestamp <> FND_API.G_MISS_DATE) then
2038     l_buffer := 'BEGIN FLOW ' || p_buffer;
2039   else
2040     l_buffer := null;
2041   end if;
2042 
2043   if (p_line_num = FND_API.G_MISS_NUM) then
2044     l_line_num := 0;
2045   else
2046     l_line_num := p_line_num;
2047   end if;
2048 
2049   while (l_buffer is null and l_eof_flag = 'N' and p_index <= AK_ON_OBJECTS_PVT.G_UPL_TABLE_NUM) loop
2050       AK_ON_OBJECTS_PVT.READ_LINE (
2051         p_return_status => l_return_status,
2052         p_index => p_index,
2053         p_buffer => l_buffer,
2054         p_lines_read => l_lines_read,
2055         p_eof_flag => l_eof_flag,
2056 		p_upl_loader_cur => p_upl_loader_cur
2057       );
2058       if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
2059          (l_return_status = FND_API.G_RET_STS_ERROR) then
2060           RAISE FND_API.G_EXC_ERROR;
2061       end if;
2062       l_line_num := l_line_num + l_lines_read;
2063       --
2064       -- trim leading spaces and discard comment lines
2065       --
2066       l_buffer := LTRIM(l_buffer);
2067       if (SUBSTR(l_buffer, 1, 1) = '#') then
2068         l_buffer := null;
2069       end if;
2070   end loop;
2071 
2072   --
2073   -- Error if there is nothing to be read from the file
2074   --
2075   if (l_buffer is null and l_eof_flag = 'Y') then
2076     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2077       FND_MESSAGE.SET_NAME('AK','AK_EMPTY_BUFFER');
2078       FND_MSG_PUB.Add;
2079     end if;
2080     raise FND_API.G_EXC_ERROR;
2081   end if;
2082 
2083   -- Read tokens from file, one at a time
2084 
2085   while (l_eof_flag = 'N') and (l_buffer is not null)
2086         and (l_more_flow) loop
2087 
2088     AK_ON_OBJECTS_PVT.GET_TOKEN(
2089       p_return_status => l_return_status,
2090       p_in_buf => l_buffer,
2091       p_token => l_token
2092     );
2093 --
2094 --  dbms_output.put_line(' State:' || l_state || ' Token:' || l_token ||
2095 --                     ' value_count:' || nvl(to_char(l_value_count),'null') );
2096 
2097     if (l_return_status = FND_API.G_RET_STS_ERROR) or
2098        (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) then
2099       if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2100         FND_MESSAGE.SET_NAME('AK','AK_GET_TOKEN_ERROR');
2101         FND_MSG_PUB.Add;
2102       end if;
2103       -- dbms_output.put_line(l_api_name || 'Error parsing buffer');
2104       raise FND_API.G_EXC_ERROR;
2105     end if;
2106 
2107     --****     Flow processing (states 0 - 19)     ****
2108     if (l_state = 0) then
2109       if (l_token = 'BEGIN') then
2110         --== Clear out previous column data  ==--
2111 	l_flow_rec := AK_FLOW_PUB.G_MISS_FLOW_REC;
2112         l_state := 1;
2113       else
2114         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2115           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2116           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2117           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2118           FND_MESSAGE.SET_TOKEN('EXPECTED','BEGIN');
2119           FND_MSG_PUB.Add;
2120         end if;
2124     elsif (l_state = 1) then
2121         -- dbms_output.put_line('Expecting BEGIN');
2122         raise FND_API.G_EXC_ERROR;
2123       end if;
2125       if (l_token = 'FLOW') then
2126         l_state := 2;
2127       else
2128         -- Found the beginning of a non-flow object,
2129         -- rebuild last line and pass it back to the caller
2130         -- (ak_on_objects_pvt.upload).
2131         p_buffer_out := 'BEGIN ' || l_token || ' ' || l_buffer;
2132         l_more_flow := FALSE;
2133       end if;
2134     elsif (l_state = 2) then
2135       if (l_token is not null) then
2136         l_flow_rec.flow_application_id := to_number(l_token);
2137         l_state := 3;
2138       else
2139         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2140           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2141           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2142           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2143           FND_MESSAGE.SET_TOKEN('EXPECTED','FLOW_APPLICATION_ID');
2144           FND_MSG_PUB.Add;
2145         end if;
2146         raise FND_API.G_EXC_ERROR;
2147       end if;
2148     elsif (l_state = 3) then
2149       if (l_token is not null) then
2150         l_flow_rec.flow_code := l_token;
2151         l_value_count := null;
2152         l_state := 10;
2153       else
2154         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2155           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2156           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2157           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2158           FND_MESSAGE.SET_TOKEN('EXPECTED','FLOW_CODE');
2159           FND_MSG_PUB.Add;
2160         end if;
2161         raise FND_API.G_EXC_ERROR;
2162       end if;
2163     elsif (l_state = 10) then
2164       if (l_token = 'BEGIN') then
2165         l_state := 13;
2166       elsif (l_token = 'END') then
2167         l_state := 19;
2168       elsif (l_token = 'NAME') or
2169 	    (l_token = 'DESCRIPTION') or
2170             (l_token = 'PRIMARY_PAGE') or
2171 			(l_token = 'ATTRIBUTE_CATEGORY') or
2172 			(l_token = 'ATTRIBUTE1') or
2173 			(l_token = 'ATTRIBUTE2') or
2174 			(l_token = 'ATTRIBUTE3') or
2175 			(l_token = 'ATTRIBUTE4') or
2176 			(l_token = 'ATTRIBUTE5') or
2177 			(l_token = 'ATTRIBUTE6') or
2178 			(l_token = 'ATTRIBUTE7') or
2179 			(l_token = 'ATTRIBUTE8') or
2180 			(l_token = 'ATTRIBUTE9') or
2181 			(l_token = 'ATTRIBUTE10') or
2182 			(l_token = 'ATTRIBUTE11') or
2183 			(l_token = 'ATTRIBUTE12') or
2184 			(l_token = 'ATTRIBUTE13') or
2185 			(l_token = 'ATTRIBUTE14') or
2186 			(l_token = 'ATTRIBUTE15') or
2187                         (l_token = 'CREATED_BY') or
2188                         (l_token = 'CREATION_DATE') or
2189                         (l_token = 'LAST_UPDATED_BY') or
2190                         (l_token = 'OWNER') or
2191                         (l_token = 'LAST_UPDATE_DATE') or
2192                         (l_token = 'LAST_UPDATE_LOGIN') then
2193         l_column := l_token;
2194         l_state := 11;
2195       else
2196       --
2197       -- error if not expecting attribute values added by the translation team
2198       -- or if we have read in more than a certain number of values
2199       -- for the same DB column
2200       --
2201         l_value_count := l_value_count + 1;
2202         --
2203         -- save second value. It will be the token with error if
2204         -- it turns out that there is a parse error on this line.
2205         --
2206         if (l_value_count = 2) then
2207           l_saved_token := l_token;
2208         end if;
2209         if (l_value_count > AK_ON_OBJECTS_PUB.G_MAX_NUM_LOADER_VALUES) or
2210            (l_value_count is null) then
2211           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2212             FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2213             FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2214             if (l_value_count is null) then
2215               FND_MESSAGE.SET_TOKEN('TOKEN', l_token);
2216             else
2217               FND_MESSAGE.SET_TOKEN('TOKEN',l_saved_token);
2218             end if;
2219             FND_MESSAGE.SET_TOKEN('EXPECTED','flow field name, BEGIN, END');
2220             FND_MSG_PUB.Add;
2221           end if;
2222           raise FND_API.G_EXC_ERROR;
2223         end if;
2224       end if;
2225     elsif (l_state = 11) then
2226       if (l_token = '=') then
2227         l_state := 12;
2228       else
2229         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2230           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2231           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2232           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2233           FND_MESSAGE.SET_TOKEN('EXPECTED','=');
2234           FND_MSG_PUB.Add;
2235         end if;
2236         raise FND_API.G_EXC_ERROR;
2237       end if;
2238     elsif (l_state = 12) then
2239       l_value_count := 1;
2240       if (l_column = 'NAME') then
2241          l_flow_rec.name := l_token;
2242          l_state := 10;
2243       elsif (l_column = 'DESCRIPTION') then
2244          l_flow_rec.description := l_token;
2245          l_state := 10;
2246       elsif (l_column = 'PRIMARY_PAGE') then
2247          l_flow_rec.primary_page_appl_id := to_number(l_token);
2248          l_state := 14;
2249       elsif (l_column = 'ATTRIBUTE_CATEGORY') then
2253          l_flow_rec.attribute1 := l_token;
2250          l_flow_rec.attribute_category := l_token;
2251          l_state := 10;
2252       elsif (l_column = 'ATTRIBUTE1') then
2254          l_state := 10;
2255       elsif (l_column = 'ATTRIBUTE2') then
2256          l_flow_rec.attribute2 := l_token;
2257          l_state := 10;
2258       elsif (l_column = 'ATTRIBUTE3') then
2259          l_flow_rec.attribute3 := l_token;
2260          l_state := 10;
2261       elsif (l_column = 'ATTRIBUTE4') then
2262          l_flow_rec.attribute4 := l_token;
2263          l_state := 10;
2264       elsif (l_column = 'ATTRIBUTE5') then
2265          l_flow_rec.attribute5 := l_token;
2266          l_state := 10;
2267       elsif (l_column = 'ATTRIBUTE6') then
2268          l_flow_rec.attribute6 := l_token;
2269          l_state := 10;
2270       elsif (l_column = 'ATTRIBUTE7') then
2271          l_flow_rec.attribute7 := l_token;
2272          l_state := 10;
2273       elsif (l_column = 'ATTRIBUTE8') then
2274          l_flow_rec.attribute8 := l_token;
2275          l_state := 10;
2276       elsif (l_column = 'ATTRIBUTE9') then
2277          l_flow_rec.attribute9 := l_token;
2278          l_state := 10;
2279       elsif (l_column = 'ATTRIBUTE10') then
2280          l_flow_rec.attribute10 := l_token;
2281          l_state := 10;
2282       elsif (l_column = 'ATTRIBUTE11') then
2283          l_flow_rec.attribute11 := l_token;
2284          l_state := 10;
2285       elsif (l_column = 'ATTRIBUTE12') then
2286          l_flow_rec.attribute12 := l_token;
2287          l_state := 10;
2288       elsif (l_column = 'ATTRIBUTE13') then
2289          l_flow_rec.attribute13 := l_token;
2290          l_state := 10;
2291       elsif (l_column = 'ATTRIBUTE14') then
2292          l_flow_rec.attribute14 := l_token;
2293          l_state := 10;
2294       elsif (l_column = 'ATTRIBUTE15') then
2295          l_flow_rec.attribute15 := l_token;
2296          l_state := 10;
2297       elsif (l_column = 'CREATED_BY') then
2298          l_flow_rec.created_by := to_number(l_token);
2299          l_state := 10;
2300       elsif (l_column = 'CREATION_DATE') then
2301          l_flow_rec.creation_date := to_date(l_token,
2302                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
2303          l_state := 10;
2304       elsif (l_column = 'LAST_UPDATED_BY') then
2305          l_flow_rec.last_updated_by := to_number(l_token);
2306          l_state := 10;
2307       elsif (l_column = 'OWNER') then
2308  	 l_flow_rec.last_updated_by := FND_LOAD_UTIL.OWNER_ID(l_token);
2309          l_state := 10;
2310       elsif (l_column = 'LAST_UPDATE_DATE') then
2311          l_flow_rec.last_update_date := to_date(l_token,
2312                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
2313          l_state := 10;
2314       elsif (l_column = 'LAST_UPDATE_LOGIN') then
2315          l_flow_rec.last_update_login := to_number(l_token);
2316          l_state := 10;
2317       else
2318         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2319           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
2320           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2321           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2322           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column);
2323           FND_MSG_PUB.Add;
2324         end if;
2325         --dbms_output.put_line('Expecting ' || l_column || ' value');
2326         raise FND_API.G_EXC_ERROR;
2327       end if;
2328     elsif (l_state = 13) then
2329       if (l_token = 'FLOW_PAGE') then
2330         l_state := 20;
2331       elsif (l_token = 'FLOW_REGION_RELATION') then
2332         l_state := 40;
2333       else
2334         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2335           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2336           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2337           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2338           FND_MESSAGE.SET_TOKEN('EXPECTED','FLOW_PAGE / FLOW_REGION_RELATION');
2339           FND_MSG_PUB.Add;
2340         end if;
2341         raise FND_API.G_EXC_ERROR;
2342       end if;
2343 	elsif (l_state = 14) then
2344 	  if (l_column = 'PRIMARY_PAGE') then
2345          l_flow_rec.primary_page_code := l_token;
2346          l_state := 10;
2347       else
2348         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2349           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
2350           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2351           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2352           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column);
2353           FND_MSG_PUB.Add;
2354         end if;
2355         --dbms_output.put_line('Expecting ' || l_column || ' value');
2356         raise FND_API.G_EXC_ERROR;
2357       end if;
2358     elsif (l_state = 19) then
2359       if (l_token = 'FLOW') then
2360         l_state := 0;
2361         l_flow_index := l_flow_index + 1;
2362         l_flow_tbl(l_flow_index) := l_flow_rec;
2363       else
2364         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2365           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2366           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2367           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2368           FND_MESSAGE.SET_TOKEN('EXPECTED', 'FLOW');
2369           FND_MSG_PUB.Add;
2370         end if;
2371         raise FND_API.G_EXC_ERROR;
2372       end if;
2373 
2377         --== Clear out previous data  ==--
2374     --****     FLOW_PAGE processing (states 20 - 39)     ****
2375     elsif (l_state = 20) then
2376       if (l_token is not null) then
2378 	l_page_rec := AK_FLOW_PUB.G_MISS_PAGE_REC;
2379         l_page_rec.page_application_id := to_number(l_token);
2380         l_state := 21;
2381       else
2382         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2383           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
2384           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2385           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2386           FND_MESSAGE.SET_TOKEN('EXPECTED', 'PAGE_APPLICATION_ID');
2387           FND_MSG_PUB.Add;
2388         end if;
2389         raise FND_API.G_EXC_ERROR;
2390       end if;
2391     elsif (l_state = 21) then
2392       if (l_token is not null) then
2393         l_page_rec.page_code := l_token;
2394         l_value_count := null;
2395         l_state := 30;
2396       else
2397         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2398           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
2399           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2400           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2401           FND_MESSAGE.SET_TOKEN('EXPECTED', 'PAGE_CODE');
2402           FND_MSG_PUB.Add;
2403         end if;
2404         raise FND_API.G_EXC_ERROR;
2405       end if;
2406     elsif (l_state = 30) then
2407       if (l_token = 'BEGIN') then
2408         l_state := 33;
2409       elsif (l_token = 'END') then
2410         l_state := 39;
2411       elsif (l_token = 'NAME') or
2412             (l_token = 'DESCRIPTION') or
2413             (l_token = 'PRIMARY_REGION') or
2414 			(l_token = 'ATTRIBUTE_CATEGORY') or
2415 			(l_token = 'ATTRIBUTE1') or
2416 			(l_token = 'ATTRIBUTE2') or
2417 			(l_token = 'ATTRIBUTE3') or
2418 			(l_token = 'ATTRIBUTE4') or
2419 			(l_token = 'ATTRIBUTE5') or
2420 			(l_token = 'ATTRIBUTE6') or
2421 			(l_token = 'ATTRIBUTE7') or
2422 			(l_token = 'ATTRIBUTE8') or
2423 			(l_token = 'ATTRIBUTE9') or
2424 			(l_token = 'ATTRIBUTE10') or
2425 			(l_token = 'ATTRIBUTE11') or
2426 			(l_token = 'ATTRIBUTE12') or
2427 			(l_token = 'ATTRIBUTE13') or
2428 			(l_token = 'ATTRIBUTE14') or
2429 			(l_token = 'ATTRIBUTE15') or
2430                         (l_token = 'CREATED_BY') or
2431                         (l_token = 'CREATION_DATE') or
2432                         (l_token = 'LAST_UPDATED_BY') or
2433                         (l_token = 'OWNER') or
2434                         (l_token = 'LAST_UPDATE_DATE') or
2435                         (l_token = 'LAST_UPDATE_LOGIN') then
2436         l_column := l_token;
2437         l_state := 31;
2438       else
2439         --
2440         -- error if not expecting attribute values added by the translation
2441         -- team or if we have read in more than a certain number of values
2442         -- for the same DB column
2443         --
2444         l_value_count := l_value_count + 1;
2445         --
2446         -- save second value. It will be the token with error if
2447         -- it turns out that there is a parse error on this line.
2448         --
2449         if (l_value_count = 2) then
2450           l_saved_token := l_token;
2451         end if;
2452         if (l_value_count > AK_ON_OBJECTS_PUB.G_MAX_NUM_LOADER_VALUES) or
2453            (l_value_count is null) then
2454           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2455             FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_BEFIELD');
2456             FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2457             if (l_value_count is null) then
2458               FND_MESSAGE.SET_TOKEN('TOKEN', l_token);
2459             else
2460               FND_MESSAGE.SET_TOKEN('TOKEN',l_saved_token);
2461             end if;
2462             FND_MESSAGE.SET_TOKEN('EXPECTED','FLOW_PAGE ');
2463             FND_MSG_PUB.Add;
2464           end if;
2465           raise FND_API.G_EXC_ERROR;
2466         end if;
2467       end if;
2468     elsif (l_state = 31) then
2469       if (l_token = '=') then
2470         l_state := 32;
2471       else
2472         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2473           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2474           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2475           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2476           FND_MESSAGE.SET_TOKEN('EXPECTED', '=');
2477           FND_MSG_PUB.Add;
2478         end if;
2479         raise FND_API.G_EXC_ERROR;
2480       end if;
2481     elsif (l_state = 32) then
2482       l_value_count := 1;
2483       if (l_column = 'NAME') then
2484          l_page_rec.name := l_token;
2485          l_state := 30;
2486       elsif (l_column = 'DESCRIPTION') then
2487          l_page_rec.description := l_token;
2488          l_state := 30;
2489       elsif (l_column = 'PRIMARY_REGION') then
2490          l_page_rec.primary_region_appl_id := to_number(l_token);
2491 		 l_state := 34;
2492       elsif (l_column = 'ATTRIBUTE_CATEGORY') then
2493          l_page_rec.attribute_category := l_token;
2494          l_state := 30;
2495       elsif (l_column = 'ATTRIBUTE1') then
2496          l_page_rec.attribute1 := l_token;
2497          l_state := 30;
2498       elsif (l_column = 'ATTRIBUTE2') then
2499          l_page_rec.attribute2 := l_token;
2500          l_state := 30;
2504       elsif (l_column = 'ATTRIBUTE4') then
2501       elsif (l_column = 'ATTRIBUTE3') then
2502          l_page_rec.attribute3 := l_token;
2503          l_state := 30;
2505          l_page_rec.attribute4 := l_token;
2506          l_state := 30;
2507       elsif (l_column = 'ATTRIBUTE5') then
2508          l_page_rec.attribute5 := l_token;
2509          l_state := 30;
2510       elsif (l_column = 'ATTRIBUTE6') then
2511          l_page_rec.attribute6 := l_token;
2512          l_state := 30;
2513       elsif (l_column = 'ATTRIBUTE7') then
2514          l_page_rec.attribute7 := l_token;
2515          l_state := 30;
2516       elsif (l_column = 'ATTRIBUTE8') then
2517          l_page_rec.attribute8 := l_token;
2518          l_state := 30;
2519       elsif (l_column = 'ATTRIBUTE9') then
2520          l_page_rec.attribute9 := l_token;
2521          l_state := 30;
2522       elsif (l_column = 'ATTRIBUTE10') then
2523          l_page_rec.attribute10 := l_token;
2524          l_state := 30;
2525       elsif (l_column = 'ATTRIBUTE11') then
2526          l_page_rec.attribute11 := l_token;
2527          l_state := 30;
2528       elsif (l_column = 'ATTRIBUTE12') then
2529          l_page_rec.attribute12 := l_token;
2530          l_state := 30;
2531       elsif (l_column = 'ATTRIBUTE13') then
2532          l_page_rec.attribute13 := l_token;
2533          l_state := 30;
2534       elsif (l_column = 'ATTRIBUTE14') then
2535          l_page_rec.attribute14 := l_token;
2536          l_state := 30;
2537       elsif (l_column = 'ATTRIBUTE15') then
2538          l_page_rec.attribute15 := l_token;
2539          l_state := 30;
2540       elsif (l_column = 'CREATED_BY') then
2541          l_page_rec.created_by := to_number(l_token);
2542          l_state := 30;
2543       elsif (l_column = 'CREATION_DATE') then
2544          l_page_rec.creation_date := to_date(l_token,
2545                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
2546          l_state := 30;
2547       elsif (l_column = 'LAST_UPDATED_BY') then
2548          l_page_rec.last_updated_by := to_number(l_token);
2549          l_state := 30;
2550       elsif (l_column = 'OWNER') then
2551          l_page_rec.last_updated_by := FND_LOAD_UTIL.OWNER_ID(l_token);
2552          l_state := 30;
2553       elsif (l_column = 'LAST_UPDATE_DATE') then
2554          l_page_rec.last_update_date := to_date(l_token,
2555                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
2556          l_state := 30;
2557       elsif (l_column = 'LAST_UPDATE_LOGIN') then
2558          l_page_rec.last_update_login := to_number(l_token);
2559          l_state := 30;
2560       else
2561         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2562           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
2563           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2564           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2565           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column);
2566           FND_MSG_PUB.Add;
2567         end if;
2568         raise FND_API.G_EXC_ERROR;
2569       end if;
2570     elsif (l_state = 33) then
2571       if (l_token = 'FLOW_PAGE_REGION') then
2572         l_state := 100;
2573       else
2574         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2575           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2576           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2577           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2578           FND_MESSAGE.SET_TOKEN('EXPECTED','FLOW_PAGE_REGION');
2579           FND_MSG_PUB.Add;
2580         end if;
2581         raise FND_API.G_EXC_ERROR;
2582       end if;
2583 	elsif (l_state = 34) then
2584       if (l_column = 'PRIMARY_REGION') then
2585         l_page_rec.primary_region_code := l_token;
2586         l_state := 30;
2587       else
2588         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2589           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
2590           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2591           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2592           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column);
2593           FND_MSG_PUB.Add;
2594         end if;
2595         raise FND_API.G_EXC_ERROR;
2596       end if;
2597 
2598     elsif (l_state = 39) then
2599       if (l_token = 'FLOW_PAGE') then
2600         l_value_count := null;
2601         l_state := 10;
2602         l_page_rec.flow_application_id := l_flow_rec.flow_application_id;
2603         l_page_rec.flow_code := l_flow_rec.flow_code;
2604         l_page_index := l_page_index + 1;
2605         l_page_tbl(l_page_index) := l_page_rec;
2606       else
2607         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2608           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2609           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2610           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2611           FND_MESSAGE.SET_TOKEN('EXPECTED', 'FLOW_PAGE');
2612           FND_MSG_PUB.Add;
2613         end if;
2614         raise FND_API.G_EXC_ERROR;
2615       end if;
2616 
2617     --****     FLOW_REGION_RELATION processing (states 40 - 59)     ****
2618     elsif (l_state = 40) then
2619       if (l_token is not null) then
2620         --== Clear out previous data  ==--
2621 	l_relation_rec := AK_FLOW_PUB.G_MISS_REGION_RELATION_REC;
2622         l_relation_rec.foreign_key_name := l_token;
2623         l_state := 41;
2624       else
2628           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2625         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2626           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2627           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2629           FND_MESSAGE.SET_TOKEN('EXPECTED', 'FOREIGN_KEY_NAME');
2630           FND_MSG_PUB.Add;
2631         end if;
2632         raise FND_API.G_EXC_ERROR;
2633       end if;
2634     elsif (l_state = 41) then
2635       if (l_token is not null) then
2636         l_relation_rec.from_page_appl_id := to_number(l_token);
2637         l_state := 42;
2638       else
2639         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2640           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2641           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2642           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2643           FND_MESSAGE.SET_TOKEN('EXPECTED', 'FROM_PAGE_APPL_ID');
2644           FND_MSG_PUB.Add;
2645         end if;
2646         raise FND_API.G_EXC_ERROR;
2647       end if;
2648     elsif (l_state = 42) then
2649       if (l_token is not null) then
2650         l_relation_rec.from_page_code := l_token;
2651         l_state := 43;
2652       else
2653         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2654           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2655           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2656           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2657           FND_MESSAGE.SET_TOKEN('EXPECTED', 'FROM_PAGE_CODE');
2658           FND_MSG_PUB.Add;
2659         end if;
2660         raise FND_API.G_EXC_ERROR;
2661       end if;
2662     elsif (l_state = 43) then
2663       if (l_token is not null) then
2664         l_relation_rec.from_region_appl_id := to_number(l_token);
2665         l_state := 44;
2666       else
2667         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2668           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2669           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2670           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2671           FND_MESSAGE.SET_TOKEN('EXPECTED', 'FROM_REGION_APPL_ID');
2672           FND_MSG_PUB.Add;
2673         end if;
2674         raise FND_API.G_EXC_ERROR;
2675       end if;
2676     elsif (l_state = 44) then
2677       if (l_token is not null) then
2678         l_relation_rec.from_region_code := l_token;
2679         l_state := 45;
2680       else
2681         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2682           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2683           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2684           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2685           FND_MESSAGE.SET_TOKEN('EXPECTED', 'FROM_REGION_CODE');
2686           FND_MSG_PUB.Add;
2687         end if;
2688         raise FND_API.G_EXC_ERROR;
2689       end if;
2690     elsif (l_state = 45) then
2691       if (l_token is not null) then
2692         l_relation_rec.to_page_appl_id := to_number(l_token);
2693         l_state := 46;
2694       else
2695         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2696           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2697           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2698           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2699           FND_MESSAGE.SET_TOKEN('EXPECTED', 'TO_PAGE_APPL_ID');
2700           FND_MSG_PUB.Add;
2701         end if;
2702         raise FND_API.G_EXC_ERROR;
2703       end if;
2704     elsif (l_state = 46) then
2705       if (l_token is not null) then
2706         l_relation_rec.to_page_code := l_token;
2707         l_state := 47;
2708       else
2709         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2710           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2711           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2712           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2713           FND_MESSAGE.SET_TOKEN('EXPECTED', 'TO_PAGE_CODE');
2714           FND_MSG_PUB.Add;
2715         end if;
2716         raise FND_API.G_EXC_ERROR;
2717       end if;
2718     elsif (l_state = 47) then
2719       if (l_token is not null) then
2720         l_relation_rec.to_region_appl_id := to_number(l_token);
2721         l_state := 48;
2722       else
2723         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2724           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2725           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2726           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2727           FND_MESSAGE.SET_TOKEN('EXPECTED', 'TO_REGION_APPL_ID');
2728           FND_MSG_PUB.Add;
2729         end if;
2730         raise FND_API.G_EXC_ERROR;
2731       end if;
2732     elsif (l_state = 48) then
2733       if (l_token is not null) then
2734         l_relation_rec.to_region_code := l_token;
2735         l_state := 50;
2736       else
2737         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2738           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2739           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2740           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2741           FND_MESSAGE.SET_TOKEN('EXPECTED', 'TO_REGION_CODE');
2742           FND_MSG_PUB.Add;
2743         end if;
2744         raise FND_API.G_EXC_ERROR;
2745       end if;
2746     elsif (l_state = 50) then
2747       if (l_token = 'END') then
2751 			(l_token = 'ATTRIBUTE1') or
2748         l_state := 59;
2749       elsif (l_token = 'APPLICATION_ID') or
2750 			(l_token = 'ATTRIBUTE_CATEGORY') or
2752 			(l_token = 'ATTRIBUTE2') or
2753 			(l_token = 'ATTRIBUTE3') or
2754 			(l_token = 'ATTRIBUTE4') or
2755 			(l_token = 'ATTRIBUTE5') or
2756 			(l_token = 'ATTRIBUTE6') or
2757 			(l_token = 'ATTRIBUTE7') or
2758 			(l_token = 'ATTRIBUTE8') or
2759 			(l_token = 'ATTRIBUTE9') or
2760 			(l_token = 'ATTRIBUTE10') or
2761 			(l_token = 'ATTRIBUTE11') or
2762 			(l_token = 'ATTRIBUTE12') or
2763 			(l_token = 'ATTRIBUTE13') or
2764 			(l_token = 'ATTRIBUTE14') or
2765 			(l_token = 'ATTRIBUTE15') or
2766             (l_token = 'CREATED_BY') or
2767             (l_token = 'CREATION_DATE') or
2768             (l_token = 'LAST_UPDATED_BY') or
2769             (l_token = 'OWNER') or
2770             (l_token = 'LAST_UPDATE_DATE') or
2771             (l_token = 'LAST_UPDATE_LOGIN') then
2772         l_column := l_token;
2773         l_state := 51;
2774       else
2775         --
2776         -- error if not expecting attribute values added by the translation
2777         -- team or if we have read in more than a certain number of values
2778         -- for the same DB column
2779         --
2780         l_value_count := l_value_count + 1;
2781         --
2782         -- save second value. It will be the token with error if
2783         -- it turns out that there is a parse error on this line.
2784         --
2785         if (l_value_count = 2) then
2786           l_saved_token := l_token;
2787         end if;
2788         if (l_value_count > AK_ON_OBJECTS_PUB.G_MAX_NUM_LOADER_VALUES) or
2789            (l_value_count is null) then
2790           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2791             FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_EFIELD');
2792             FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2793             if (l_value_count is null) then
2794               FND_MESSAGE.SET_TOKEN('TOKEN', l_token);
2795             else
2796               FND_MESSAGE.SET_TOKEN('TOKEN',l_saved_token);
2797             end if;
2798             FND_MESSAGE.SET_TOKEN('EXPECTED','FLOW_REGION_RELATION');
2799             FND_MSG_PUB.Add;
2800           end if;
2801         raise FND_API.G_EXC_ERROR;
2802         end if;
2803       end if;
2804     elsif (l_state = 51) then
2805       if (l_token = '=') then
2806         l_state := 52;
2807       else
2808         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2809           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2810           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2811           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2812           FND_MESSAGE.SET_TOKEN('EXPECTED', '=');
2813           FND_MSG_PUB.Add;
2814         end if;
2815         raise FND_API.G_EXC_ERROR;
2816       end if;
2817     elsif (l_state = 52) then
2818       l_value_count := 1;
2819       if (l_column = 'APPLICATION_ID') then
2820          l_relation_rec.application_id := to_number(l_token);
2821       elsif (l_column = 'ATTRIBUTE_CATEGORY') then
2822          l_relation_rec.attribute_category := l_token;
2823       elsif (l_column = 'ATTRIBUTE1') then
2824          l_relation_rec.attribute1 := l_token;
2825       elsif (l_column = 'ATTRIBUTE2') then
2826          l_relation_rec.attribute2 := l_token;
2827       elsif (l_column = 'ATTRIBUTE3') then
2828          l_relation_rec.attribute3 := l_token;
2829       elsif (l_column = 'ATTRIBUTE4') then
2830          l_relation_rec.attribute4 := l_token;
2831       elsif (l_column = 'ATTRIBUTE5') then
2832          l_relation_rec.attribute5 := l_token;
2833       elsif (l_column = 'ATTRIBUTE6') then
2834          l_relation_rec.attribute6 := l_token;
2835       elsif (l_column = 'ATTRIBUTE7') then
2836          l_relation_rec.attribute7 := l_token;
2837       elsif (l_column = 'ATTRIBUTE8') then
2838          l_relation_rec.attribute8 := l_token;
2839       elsif (l_column = 'ATTRIBUTE9') then
2840          l_relation_rec.attribute9 := l_token;
2841       elsif (l_column = 'ATTRIBUTE10') then
2842          l_relation_rec.attribute10 := l_token;
2843       elsif (l_column = 'ATTRIBUTE11') then
2844          l_relation_rec.attribute11 := l_token;
2845       elsif (l_column = 'ATTRIBUTE12') then
2846          l_relation_rec.attribute12 := l_token;
2847       elsif (l_column = 'ATTRIBUTE13') then
2848          l_relation_rec.attribute13 := l_token;
2849       elsif (l_column = 'ATTRIBUTE14') then
2850          l_relation_rec.attribute14 := l_token;
2851       elsif (l_column = 'ATTRIBUTE15') then
2852          l_relation_rec.attribute15 := l_token;
2853       elsif (l_column = 'CREATED_BY') then
2854          l_relation_rec.created_by := to_number(l_token);
2855       elsif (l_column = 'CREATION_DATE') then
2856          l_relation_rec.creation_date := to_date(l_token,
2857                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
2858       elsif (l_column = 'LAST_UPDATED_BY') then
2859          l_relation_rec.last_updated_by := to_number(l_token);
2860       elsif (l_column = 'OWNER') then
2861          l_relation_rec.last_updated_by := FND_LOAD_UTIL.OWNER_ID(l_token);
2862       elsif (l_column = 'LAST_UPDATE_DATE') then
2863          l_relation_rec.last_update_date := to_date(l_token,
2864                                        AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
2865       elsif (l_column = 'LAST_UPDATE_LOGIN') then
2866          l_relation_rec.last_update_login := to_number(l_token);
2870           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2867       else
2868         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2869           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
2871           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2872           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column);
2873           FND_MSG_PUB.Add;
2874         end if;
2875         raise FND_API.G_EXC_ERROR;
2876       end if;
2877       l_state := 50;
2878     elsif (l_state = 59) then
2879       if (l_token = 'FLOW_REGION_RELATION') then
2880         l_value_count := null;
2881         l_state := 10;
2882         l_relation_rec.flow_application_id := l_flow_rec.flow_application_id;
2883         l_relation_rec.flow_code := l_flow_rec.flow_code;
2884         l_relation_index := l_relation_index + 1;
2885         l_relation_tbl(l_relation_index) := l_relation_rec;
2886       else
2887         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2888           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2889           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2890           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2891           FND_MESSAGE.SET_TOKEN('EXPECTED', 'FLOW_REGION_RELATION');
2892           FND_MSG_PUB.Add;
2893         end if;
2894         raise FND_API.G_EXC_ERROR;
2895       end if;
2896 
2897     --****     FLOW_PAGE_REGION processing (states 100 - 119)     ****
2898     elsif (l_state = 100) then
2899       if (l_token is not null) then
2900         --== Clear out previous data  ==--
2901         l_region_rec := AK_FLOW_PUB.G_MISS_PAGE_REGION_REC;
2902         l_region_rec.region_application_id := to_number(l_token);
2903         l_state := 101;
2904       else
2905         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2906           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2907           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2908           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2909           FND_MESSAGE.SET_TOKEN('EXPECTED', 'REGION_APPLICATION_ID');
2910           FND_MSG_PUB.Add;
2911         end if;
2912         raise FND_API.G_EXC_ERROR;
2913       end if;
2914     elsif (l_state = 101) then
2915       if (l_token is not null) then
2916         l_region_rec.region_code := l_token;
2917         l_state := 110;
2918       else
2919         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2920           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2921           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2922           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
2923           FND_MESSAGE.SET_TOKEN('EXPECTED', 'REGION_CODE');
2924           FND_MSG_PUB.Add;
2925         end if;
2926         raise FND_API.G_EXC_ERROR;
2927       end if;
2928     elsif (l_state = 110) then
2929       if (l_token = 'END') then
2930         l_state := 119;
2931       elsif (l_token = 'BEGIN')then
2932         l_state := 113;
2933       elsif (l_token = 'DISPLAY_SEQUENCE') or
2934             (l_token = 'REGION_STYLE') or
2935             (l_token = 'NUM_COLUMNS') or
2936             (l_token = 'ICX_CUSTOM_CALL') or
2937             (l_token = 'PARENT_REGION') or
2938             (l_token = 'FOREIGN_KEY_NAME') or
2939 			(l_token = 'ATTRIBUTE_CATEGORY') or
2940 			(l_token = 'ATTRIBUTE1') or
2941 			(l_token = 'ATTRIBUTE2') or
2942 			(l_token = 'ATTRIBUTE3') or
2943 			(l_token = 'ATTRIBUTE4') or
2944 			(l_token = 'ATTRIBUTE5') or
2945 			(l_token = 'ATTRIBUTE6') or
2946 			(l_token = 'ATTRIBUTE7') or
2947 			(l_token = 'ATTRIBUTE8') or
2948 			(l_token = 'ATTRIBUTE9') or
2949 			(l_token = 'ATTRIBUTE10') or
2950 			(l_token = 'ATTRIBUTE11') or
2951 			(l_token = 'ATTRIBUTE12') or
2952 			(l_token = 'ATTRIBUTE13') or
2953 			(l_token = 'ATTRIBUTE14') or
2954 			(l_token = 'ATTRIBUTE15') or
2955                         (l_token = 'CREATED_BY') or
2956                         (l_token = 'CREATION_DATE') or
2957                         (l_token = 'LAST_UPDATED_BY') or
2958                         (l_token = 'OWNER') or
2959                         (l_token = 'LAST_UPDATE_DATE') or
2960                         (l_token = 'LAST_UPDATE_LOGIN') then
2961         l_column := l_token;
2962         l_state := 111;
2963       else
2964         --
2965         -- error if not expecting attribute values added by the translation
2966         -- team or if we have read in more than a certain number of values
2967         -- for the same DB column
2968         --
2969         l_value_count := l_value_count + 1;
2970         --
2971         -- save second value. It will be the token with error if
2972         -- it turns out that there is a parse error on this line.
2973         --
2974         if (l_value_count = 2) then
2975           l_saved_token := l_token;
2976         end if;
2977         if (l_value_count > AK_ON_OBJECTS_PUB.G_MAX_NUM_LOADER_VALUES) or
2978            (l_value_count is null) then
2979           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2980             FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_BEFIELD');
2981             FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
2982             if (l_value_count is null) then
2983               FND_MESSAGE.SET_TOKEN('TOKEN', l_token);
2984             else
2985               FND_MESSAGE.SET_TOKEN('TOKEN',l_saved_token);
2986             end if;
2987             FND_MESSAGE.SET_TOKEN('EXPECTED','FLOW_PAGE_REGION');
2988             FND_MSG_PUB.Add;
2992       end if;
2989           end if;
2990         raise FND_API.G_EXC_ERROR;
2991         end if;
2993     elsif (l_state = 111) then
2994       if (l_token = '=') then
2995         l_state := 112;
2996       else
2997         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2998           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
2999           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
3000           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
3001           FND_MESSAGE.SET_TOKEN('EXPECTED', '=');
3002           FND_MSG_PUB.Add;
3003         end if;
3004         raise FND_API.G_EXC_ERROR;
3005       end if;
3006     elsif (l_state = 112) then
3007       l_value_count := 1;
3008       if (l_column = 'DISPLAY_SEQUENCE') then
3009          l_region_rec.display_sequence := to_number(l_token);
3010          l_state := 110;
3011       elsif (l_column = 'REGION_STYLE') then
3012          l_region_rec.region_style := l_token;
3013          l_state := 110;
3014       elsif (l_column = 'NUM_COLUMNS') then
3015          l_region_rec.num_columns := to_number(l_token);
3016          l_state := 110;
3017       elsif (l_column = 'ICX_CUSTOM_CALL') then
3018          l_region_rec.icx_custom_call := l_token;
3019          l_state := 110;
3020       elsif (l_column = 'PARENT_REGION') then
3021          l_region_rec.parent_region_appl_id := to_number(l_token);
3022 		 l_state := 114;
3023       elsif (l_column = 'FOREIGN_KEY_NAME') then
3024          l_region_rec.foreign_key_name := l_token;
3025          l_state := 110;
3026       elsif (l_column = 'ATTRIBUTE_CATEGORY') then
3027          l_region_rec.attribute_category := l_token;
3028          l_state := 110;
3029       elsif (l_column = 'ATTRIBUTE1') then
3030          l_region_rec.attribute1 := l_token;
3031          l_state := 110;
3032       elsif (l_column = 'ATTRIBUTE2') then
3033          l_region_rec.attribute2 := l_token;
3034          l_state := 110;
3035       elsif (l_column = 'ATTRIBUTE3') then
3036          l_region_rec.attribute3 := l_token;
3037          l_state := 110;
3038       elsif (l_column = 'ATTRIBUTE4') then
3039          l_region_rec.attribute4 := l_token;
3040          l_state := 110;
3041       elsif (l_column = 'ATTRIBUTE5') then
3042          l_region_rec.attribute5 := l_token;
3043          l_state := 110;
3044       elsif (l_column = 'ATTRIBUTE6') then
3045          l_region_rec.attribute6 := l_token;
3046          l_state := 110;
3047       elsif (l_column = 'ATTRIBUTE7') then
3048          l_region_rec.attribute7 := l_token;
3049          l_state := 110;
3050       elsif (l_column = 'ATTRIBUTE8') then
3051          l_region_rec.attribute8 := l_token;
3052          l_state := 110;
3053       elsif (l_column = 'ATTRIBUTE9') then
3054          l_region_rec.attribute9 := l_token;
3055          l_state := 110;
3056       elsif (l_column = 'ATTRIBUTE10') then
3057          l_region_rec.attribute10 := l_token;
3058          l_state := 110;
3059       elsif (l_column = 'ATTRIBUTE11') then
3060          l_region_rec.attribute11 := l_token;
3061          l_state := 110;
3062       elsif (l_column = 'ATTRIBUTE12') then
3063          l_region_rec.attribute12 := l_token;
3064          l_state := 110;
3065       elsif (l_column = 'ATTRIBUTE13') then
3066          l_region_rec.attribute13 := l_token;
3067          l_state := 110;
3068       elsif (l_column = 'ATTRIBUTE14') then
3069          l_region_rec.attribute14 := l_token;
3070          l_state := 110;
3071       elsif (l_column = 'ATTRIBUTE15') then
3072          l_region_rec.attribute15 := l_token;
3073          l_state := 110;
3074       elsif (l_column = 'CREATED_BY') then
3075          l_region_rec.created_by := to_number(l_token);
3076          l_state := 110;
3077       elsif (l_column = 'CREATION_DATE') then
3078          l_region_rec.creation_date := to_date(l_token,
3079                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
3080          l_state := 110;
3081       elsif (l_column = 'LAST_UPDATED_BY') then
3082          l_region_rec.last_updated_by := to_number(l_token);
3083          l_state := 110;
3084       elsif (l_column = 'OWNER') then
3085          l_region_rec.last_updated_by := FND_LOAD_UTIL.OWNER_ID(l_token);
3086          l_state := 110;
3087       elsif (l_column = 'LAST_UPDATE_DATE') then
3088          l_region_rec.last_update_date := to_date(l_token,
3089                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
3090          l_state := 110;
3091       elsif (l_column = 'LAST_UPDATE_LOGIN') then
3092          l_region_rec.last_update_login := to_number(l_token);
3093          l_state := 110;
3094       else
3095         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3096           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
3097           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
3098           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
3099           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column);
3100           FND_MSG_PUB.Add;
3101         end if;
3102         raise FND_API.G_EXC_ERROR;
3103       end if;
3104     elsif (l_state = 113) then
3105       if (l_token = 'FLOW_PAGE_REGION_ITEM') then
3106         l_state := 200;
3107       else
3108         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3109           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
3110           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
3111           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
3115         raise FND_API.G_EXC_ERROR;
3112           FND_MESSAGE.SET_TOKEN('EXPECTED','FLOW_PAGE_REGION_ITEM');
3113           FND_MSG_PUB.Add;
3114         end if;
3116       end if;
3117     elsif (l_state = 114) then
3118       if (l_column = 'PARENT_REGION') then
3119          l_region_rec.parent_region_code := l_token;
3120          l_state := 110;
3121       else
3122         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3123           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
3124           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
3125           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
3126           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column);
3127           FND_MSG_PUB.Add;
3128         end if;
3129         raise FND_API.G_EXC_ERROR;
3130       end if;
3131     elsif (l_state = 119) then
3132       if (l_token = 'FLOW_PAGE_REGION') then
3133         l_value_count := null;
3134         l_state := 30;
3135         l_region_rec.flow_application_id := l_flow_rec.flow_application_id;
3136         l_region_rec.flow_code := l_flow_rec.flow_code;
3137         l_region_rec.page_application_id := l_page_rec.page_application_id;
3138         l_region_rec.page_code := l_page_rec.page_code;
3139         l_region_index := l_region_index + 1;
3140         l_region_tbl(l_region_index) := l_region_rec;
3141       else
3142         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3143           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
3144           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
3145           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
3146           FND_MESSAGE.SET_TOKEN('EXPECTED', 'FLOW_PAGE_REGION');
3147           FND_MSG_PUB.Add;
3148         end if;
3149         raise FND_API.G_EXC_ERROR;
3150       end if;
3151 
3152     --****     FLOW_PAGE_REGION_ITEM processing (states 200 - 219)     ****
3153     elsif (l_state = 200) then
3154       if (l_token is not null) then
3155         --== Clear out previous data  ==--
3156         l_item_rec := AK_FLOW_PUB.G_MISS_PAGE_REGION_ITEM_REC;
3157         l_item_rec.attribute_application_id := to_number(l_token);
3158         l_state := 201;
3159       else
3160         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3161           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
3162           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
3163           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
3164           FND_MESSAGE.SET_TOKEN('EXPECTED', 'ATTRIBUTE_APPLICATION_ID');
3165           FND_MSG_PUB.Add;
3166         end if;
3167         raise FND_API.G_EXC_ERROR;
3168       end if;
3169     elsif (l_state = 201) then
3170       if (l_token is not null) then
3171         l_item_rec.attribute_code := l_token;
3172         l_value_count := null;
3173         l_state := 210;
3174       else
3175         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3176           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
3177           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
3178           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
3179           FND_MESSAGE.SET_TOKEN('EXPECTED', 'ATTRIBUTE_CODE');
3180           FND_MSG_PUB.Add;
3181         end if;
3182         raise FND_API.G_EXC_ERROR;
3183       end if;
3184     elsif (l_state = 210) then
3185       if (l_token = 'END') then
3186         l_state := 219;
3187       elsif (l_token = 'TO_PAGE') or
3188             (l_token = 'TO_URL_ATTRIBUTE') or
3189 			(l_token = 'ATTRIBUTE_CATEGORY') or
3190 			(l_token = 'ATTRIBUTE1') or
3191 			(l_token = 'ATTRIBUTE2') or
3192 			(l_token = 'ATTRIBUTE3') or
3193 			(l_token = 'ATTRIBUTE4') or
3194 			(l_token = 'ATTRIBUTE5') or
3195 			(l_token = 'ATTRIBUTE6') or
3196 			(l_token = 'ATTRIBUTE7') or
3197 			(l_token = 'ATTRIBUTE8') or
3198 			(l_token = 'ATTRIBUTE9') or
3199 			(l_token = 'ATTRIBUTE10') or
3200 			(l_token = 'ATTRIBUTE11') or
3201 			(l_token = 'ATTRIBUTE12') or
3202 			(l_token = 'ATTRIBUTE13') or
3203 			(l_token = 'ATTRIBUTE14') or
3204 			(l_token = 'ATTRIBUTE15') or
3205             (l_token = 'CREATED_BY') or
3206             (l_token = 'CREATION_DATE') or
3207             (l_token = 'LAST_UPDATED_BY') or
3208             (l_token = 'OWNER') or
3209             (l_token = 'LAST_UPDATE_DATE') or
3210             (l_token = 'LAST_UPDATE_LOGIN') then
3211         l_column := l_token;
3212         l_state := 211;
3213       else
3214         --
3215         -- error if not expecting attribute values added by the translation
3216         -- team or if we have read in more than a certain number of values
3217         -- for the same DB column
3218         --
3219         l_value_count := l_value_count + 1;
3220         --
3221         -- save second value. It will be the token with error if
3222         -- it turns out that there is a parse error on this line.
3223         --
3224         if (l_value_count = 2) then
3225           l_saved_token := l_token;
3226         end if;
3227         if (l_value_count > AK_ON_OBJECTS_PUB.G_MAX_NUM_LOADER_VALUES) or
3228            (l_value_count is null) then
3229           if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3230             FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_EFIELD');
3231             FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
3232             if (l_value_count is null) then
3233               FND_MESSAGE.SET_TOKEN('TOKEN', l_token);
3234             else
3238             FND_MSG_PUB.Add;
3235               FND_MESSAGE.SET_TOKEN('TOKEN',l_saved_token);
3236             end if;
3237             FND_MESSAGE.SET_TOKEN('EXPECTED','FLOW_PAGE_REGION_ITEM');
3239           end if;
3240         raise FND_API.G_EXC_ERROR;
3241         end if;
3242       end if;
3243     elsif (l_state = 211) then
3244       if (l_token = '=') then
3245         l_state := 212;
3246       else
3247         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3248           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
3249           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
3250           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
3251           FND_MESSAGE.SET_TOKEN('EXPECTED', '=');
3252           FND_MSG_PUB.Add;
3253         end if;
3254         --dbms_output.put_line('Expecting =');
3255         raise FND_API.G_EXC_ERROR;
3256       end if;
3257     elsif (l_state = 212) then
3258       l_value_count := 1;
3259       if (l_column = 'TO_PAGE') then
3260          l_item_rec.to_page_appl_id := to_number(l_token);
3261          l_state := 214;
3262       elsif (l_column = 'TO_URL_ATTRIBUTE') then
3263          l_item_rec.to_url_attribute_appl_id := to_number(l_token);
3264          l_state := 214;
3265       elsif (l_column = 'ATTRIBUTE_CATEGORY') then
3266          l_item_rec.attribute_category := l_token;
3267          l_state := 210;
3268       elsif (l_column = 'ATTRIBUTE1') then
3269          l_item_rec.attribute1 := l_token;
3270          l_state := 210;
3271       elsif (l_column = 'ATTRIBUTE2') then
3272          l_item_rec.attribute2 := l_token;
3273          l_state := 210;
3274       elsif (l_column = 'ATTRIBUTE3') then
3275          l_item_rec.attribute3 := l_token;
3276          l_state := 210;
3277       elsif (l_column = 'ATTRIBUTE4') then
3278          l_item_rec.attribute4 := l_token;
3279          l_state := 210;
3280       elsif (l_column = 'ATTRIBUTE5') then
3281          l_item_rec.attribute5 := l_token;
3282          l_state := 210;
3283       elsif (l_column = 'ATTRIBUTE6') then
3284          l_item_rec.attribute6 := l_token;
3285          l_state := 210;
3286       elsif (l_column = 'ATTRIBUTE7') then
3287          l_item_rec.attribute7 := l_token;
3288          l_state := 210;
3289       elsif (l_column = 'ATTRIBUTE8') then
3290          l_item_rec.attribute8 := l_token;
3291          l_state := 210;
3292       elsif (l_column = 'ATTRIBUTE9') then
3293          l_item_rec.attribute9 := l_token;
3294          l_state := 210;
3295       elsif (l_column = 'ATTRIBUTE10') then
3296          l_item_rec.attribute10 := l_token;
3297          l_state := 210;
3298       elsif (l_column = 'ATTRIBUTE11') then
3299          l_item_rec.attribute11 := l_token;
3300          l_state := 210;
3301       elsif (l_column = 'ATTRIBUTE12') then
3302          l_item_rec.attribute12 := l_token;
3303          l_state := 210;
3304       elsif (l_column = 'ATTRIBUTE13') then
3305          l_item_rec.attribute13 := l_token;
3306          l_state := 210;
3307       elsif (l_column = 'ATTRIBUTE14') then
3308          l_item_rec.attribute14 := l_token;
3309          l_state := 210;
3310       elsif (l_column = 'ATTRIBUTE15') then
3311          l_item_rec.attribute15 := l_token;
3312          l_state := 210;
3313       elsif (l_column = 'CREATED_BY') then
3314          l_item_rec.created_by := to_number(l_token);
3315          l_state := 210;
3316       elsif (l_column = 'CREATION_DATE') then
3317          l_item_rec.creation_date := to_date(l_token,
3318                                         AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
3319          l_state := 210;
3320       elsif (l_column = 'LAST_UPDATED_BY') then
3321          l_item_rec.last_updated_by := to_number(l_token);
3322          l_state := 210;
3323       elsif (l_column = 'OWNER') then
3324          l_item_rec.last_updated_by := FND_LOAD_UTIL.OWNER_ID(l_token);
3325          l_state := 210;
3326       elsif (l_column = 'LAST_UPDATE_DATE') then
3327          l_item_rec.last_update_date := to_date(l_token,
3328                                        AK_ON_OBJECTS_PUB.G_DATE_FORMAT);
3329          l_state := 210;
3330       elsif (l_column = 'LAST_UPDATE_LOGIN') then
3331          l_item_rec.last_update_login := to_number(l_token);
3332          l_state := 210;
3333       else
3334         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3335           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
3336           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
3337           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
3338           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column);
3339           FND_MSG_PUB.Add;
3340         end if;
3341         raise FND_API.G_EXC_ERROR;
3342       end if;
3343     elsif (l_state = 214) then
3344       if (l_column = 'TO_PAGE') then
3345          l_item_rec.to_page_code := l_token;
3346       elsif (l_column = 'TO_URL_ATTRIBUTE') then
3347          l_item_rec.to_url_attribute_code := l_token;
3348       else
3349         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3350           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
3351           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
3352           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
3353           FND_MESSAGE.SET_TOKEN('EXPECTED', l_column);
3354           FND_MSG_PUB.Add;
3355         end if;
3356         raise FND_API.G_EXC_ERROR;
3357       end if;
3358       l_state := 210;
3362         l_state := 110;
3359     elsif (l_state = 219) then
3360       if (l_token = 'FLOW_PAGE_REGION_ITEM') then
3361         l_value_count := null;
3363         l_item_rec.flow_application_id := l_flow_rec.flow_application_id;
3364         l_item_rec.flow_code := l_flow_rec.flow_code;
3365         l_item_rec.page_application_id := l_page_rec.page_application_id;
3366         l_item_rec.page_code := l_page_rec.page_code;
3367         l_item_rec.region_application_id := l_region_rec.region_application_id;
3368         l_item_rec.region_code := l_region_rec.region_code;
3369         l_item_index := l_item_index + 1;
3370         l_item_tbl(l_item_index) := l_item_rec;
3371       else
3372         if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3373           FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
3374           FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
3375           FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
3376           FND_MESSAGE.SET_TOKEN('EXPECTED', 'FLOW_PAGE_REGION_ITEM');
3377           FND_MSG_PUB.Add;
3378         end if;
3379         raise FND_API.G_EXC_ERROR;
3380       end if;
3381 
3382     end if; -- if l_state = ...
3383 
3384     -- Get rid of leading white spaces, so that buffer would become
3385     -- null if the only thing in it are white spaces
3386     l_buffer := LTRIM(l_buffer);
3387 
3388     --
3389     -- Get the next non-blank, non-comment line if current line is
3390     -- fully parsed
3391     --
3392     while (l_buffer is null and l_eof_flag = 'N' and p_index <= AK_ON_OBJECTS_PVT.G_UPL_TABLE_NUM) loop
3393       AK_ON_OBJECTS_PVT.READ_LINE (
3394         p_return_status => l_return_status,
3395         p_index => p_index,
3396         p_buffer => l_buffer,
3397         p_lines_read => l_lines_read,
3398         p_eof_flag => l_eof_flag,
3399 		p_upl_loader_cur => p_upl_loader_cur
3400       );
3401       if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
3402          (l_return_status = FND_API.G_RET_STS_ERROR) then
3403           RAISE FND_API.G_EXC_ERROR;
3404       end if;
3405       l_line_num := l_line_num + l_lines_read;
3406       --
3407       -- trim leading spaces and discard comment lines
3408       --
3409       l_buffer := LTRIM(l_buffer);
3410       if (SUBSTR(l_buffer, 1, 1) = '#') then
3411         l_buffer := null;
3412       end if;
3413     end loop;
3414 
3415   end LOOP; --** finish parsing the input file **
3416 
3417 -- dbms_output.put_line('finished parsing flows: ' ||
3418 --                        to_char(sysdate, 'MON-DD HH24:MI:SS'));
3419 
3420   -- If the loops end in a state other then at the end of an object
3421   -- (state 0) or when the beginning of another business object was
3422   -- detected, then the file must have ended prematurely, which is an error
3423   if (l_state <> 0) and (l_more_flow) then
3424     if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3425       FND_MESSAGE.SET_NAME('AK','AK_UNEXPECTED_EOF_ERROR');
3426       FND_MSG_PUB.Add;
3427     end if;
3428     raise FND_API.G_EXC_ERROR;
3429   end if;
3430 
3431   -- Create new flows to the database
3432   --
3433   -- - Create flows that are not already in the database. Since it is
3434   --   very likely that there are no pages for these new flows,
3435   --   these flows will be created without specifying their primary pages.
3436   --   Later in this procedure, they will be updated with the appropriate
3437   --   primary pages once all the flow pages are loaded.
3438   --
3439   --   Existing flows will also be updated with new data at that time.
3440   --
3441   if (l_flow_tbl.count > 0) then
3442     for l_index in l_flow_tbl.FIRST .. l_flow_tbl.LAST loop
3443       if (l_flow_tbl.exists(l_index)) then
3444         if NOT AK_FLOW_PVT.FLOW_EXISTS (
3445             p_api_version_number => 1.0,
3446             p_return_status => l_return_status,
3447             p_flow_application_id =>
3448                         l_flow_tbl(l_index).flow_application_id,
3449             p_flow_code => l_flow_tbl(l_index).flow_code) then
3450           AK_FLOW_PVT.CREATE_FLOW (
3451             p_validation_level => p_validation_level,
3452             p_api_version_number => 1.0,
3453             p_msg_count => l_msg_count,
3454             p_msg_data => l_msg_data,
3455             p_return_status => l_return_status,
3456             p_flow_application_id =>
3457                         l_flow_tbl(l_index).flow_application_id,
3458             p_flow_code => l_flow_tbl(l_index).flow_code,
3459             p_attribute_category => l_flow_tbl(l_index).attribute_category,
3460 			p_attribute1 => l_flow_tbl(l_index).attribute1,
3461 			p_attribute2 => l_flow_tbl(l_index).attribute2,
3462 			p_attribute3 => l_flow_tbl(l_index).attribute3,
3463 			p_attribute4 => l_flow_tbl(l_index).attribute4,
3464 			p_attribute5 => l_flow_tbl(l_index).attribute5,
3465 			p_attribute6 => l_flow_tbl(l_index).attribute6,
3466 			p_attribute7 => l_flow_tbl(l_index).attribute7,
3467 			p_attribute8 => l_flow_tbl(l_index).attribute8,
3468 			p_attribute9 => l_flow_tbl(l_index).attribute9,
3469 			p_attribute10 => l_flow_tbl(l_index).attribute10,
3470 			p_attribute11 => l_flow_tbl(l_index).attribute11,
3471 			p_attribute12 => l_flow_tbl(l_index).attribute12,
3472 			p_attribute13 => l_flow_tbl(l_index).attribute13,
3473 			p_attribute14 => l_flow_tbl(l_index).attribute14,
3474 			p_attribute15 => l_flow_tbl(l_index).attribute15,
3475             p_name => l_flow_tbl(l_index).name,
3479         p_last_updated_by => l_flow_tbl(l_index).last_updated_by,
3476             p_description => l_flow_tbl(l_index).description,
3477 	p_created_by => l_flow_tbl(l_index).created_by,
3478         p_creation_date => l_flow_tbl(l_index).creation_date,
3480         p_last_update_date => l_flow_tbl(l_index).last_update_date,
3481         p_last_update_login => l_flow_tbl(l_index).last_update_login,
3482             p_loader_timestamp => p_loader_timestamp,
3483   		    p_pass => p_pass,
3484             p_copy_redo_flag => l_copy_redo_flag
3485           );
3486 
3487             -- If API call returns with an error status...
3488             if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
3489             (l_return_status = FND_API.G_RET_STS_ERROR) then
3490               RAISE FND_API.G_EXC_ERROR;
3491             end if;
3492         end if; -- /* if AK_FLOW_PVT.FLOW_EXISTS */
3493       end if;
3494     end loop;
3495   end if;
3496 
3497   -- Create new flow pages to the database
3498   --
3499   -- - Create flow pages that are not already in the database. Since it is
3500   --   very likely that there are no page regions for these new flows,
3501   --   these flow pages will be created without specifying any  primary
3502   --   page regions.
3503   --   Later in this procedure, they will be updated with the appropriate
3504   --   primary regions once all the flow page regions are loaded.
3505   --
3506   --   Existing flow pages will also be updated with new data at that time.
3507   --
3508   if (l_page_tbl.count > 0) then
3509     for l_index in l_page_tbl.FIRST .. l_page_tbl.LAST loop
3510       if (l_page_tbl.exists(l_index)) then
3511         if NOT AK_FLOW_PVT.PAGE_EXISTS (
3512             p_api_version_number => 1.0,
3513             p_return_status => l_return_status,
3514             p_flow_application_id =>
3515                         l_page_tbl(l_index).flow_application_id,
3516             p_flow_code => l_page_tbl(l_index).flow_code,
3517             p_page_application_id =>
3518                         l_page_tbl(l_index).page_application_id,
3519             p_page_code => l_page_tbl(l_index).page_code) then
3520           AK_FLOW_PVT.CREATE_PAGE (
3521             p_validation_level => p_validation_level,
3522             p_api_version_number => 1.0,
3523             p_msg_count => l_msg_count,
3524             p_msg_data => l_msg_data,
3525             p_return_status => l_return_status,
3526             p_flow_application_id =>
3527                         l_page_tbl(l_index).flow_application_id,
3528             p_flow_code => l_page_tbl(l_index).flow_code,
3529             p_page_application_id =>
3530                         l_page_tbl(l_index).page_application_id,
3531             p_page_code => l_page_tbl(l_index).page_code,
3532             p_attribute_category => l_page_tbl(l_index).attribute_category,
3533 			p_attribute1 => l_page_tbl(l_index).attribute1,
3534 			p_attribute2 => l_page_tbl(l_index).attribute2,
3535 			p_attribute3 => l_page_tbl(l_index).attribute3,
3536 			p_attribute4 => l_page_tbl(l_index).attribute4,
3537 			p_attribute5 => l_page_tbl(l_index).attribute5,
3538 			p_attribute6 => l_page_tbl(l_index).attribute6,
3539 			p_attribute7 => l_page_tbl(l_index).attribute7,
3540 			p_attribute8 => l_page_tbl(l_index).attribute8,
3541 			p_attribute9 => l_page_tbl(l_index).attribute9,
3542 			p_attribute10 => l_page_tbl(l_index).attribute10,
3543 			p_attribute11 => l_page_tbl(l_index).attribute11,
3544 			p_attribute12 => l_page_tbl(l_index).attribute12,
3545 			p_attribute13 => l_page_tbl(l_index).attribute13,
3546 			p_attribute14 => l_page_tbl(l_index).attribute14,
3547 			p_attribute15 => l_page_tbl(l_index).attribute15,
3548             p_name => l_page_tbl(l_index).name,
3549             p_description => l_page_tbl(l_index).description,
3550         p_created_by => l_page_tbl(l_index).created_by,
3551         p_creation_date => l_page_tbl(l_index).creation_date,
3552         p_last_updated_by => l_page_tbl(l_index).last_updated_by,
3553         p_last_update_date => l_page_tbl(l_index).last_update_date,
3554         p_last_update_login => l_page_tbl(l_index).last_update_login,
3555             p_loader_timestamp => p_loader_timestamp,
3556   		    p_pass => p_pass,
3557             p_copy_redo_flag => l_copy_redo_flag
3558           );
3559 
3560             -- If API call returns with an error status..., abort upload
3561             if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
3562             (l_return_status = FND_API.G_RET_STS_ERROR) then
3563               RAISE FND_API.G_EXC_ERROR;
3564             end if;
3565         end if; -- /* if PAGE_EXISTS */
3566       end if;
3567     end loop;
3568   end if;
3569 
3570   -- Update primary page columns for new flows, and update all columns
3571   -- for existing flows.
3572   --
3573   --   Now that all flow pages have been loaded into the database,
3574   --   we can load the primary page columns for all new flows that
3575   --   has a primary page. Existing flows are also updated with new
3576   --   data in the loader file at this time.
3577   --
3578   if (l_flow_tbl.count > 0) then
3579     for l_index in l_flow_tbl.FIRST .. l_flow_tbl.LAST loop
3580       if (l_flow_tbl.exists(l_index)) then
3581 		-- update all records
3582 		if ( AK_UPLOAD_GRP.G_UPDATE_MODE ) then
3583          AK_FLOW_PVT.UPDATE_FLOW (
3584             p_validation_level => p_validation_level,
3585             p_api_version_number => 1.0,
3586             p_msg_count => l_msg_count,
3590                         l_flow_tbl(l_index).flow_application_id,
3587             p_msg_data => l_msg_data,
3588             p_return_status => l_return_status,
3589             p_flow_application_id =>
3591             p_flow_code => l_flow_tbl(l_index).flow_code,
3592             p_name => l_flow_tbl(l_index).name,
3593             p_description => l_flow_tbl(l_index).description,
3594             p_primary_page_appl_id => l_flow_tbl(l_index).primary_page_appl_id,
3595             p_primary_page_code => l_flow_tbl(l_index).primary_page_code,
3596             p_attribute_category => l_flow_tbl(l_index).attribute_category,
3597 			p_attribute1 => l_flow_tbl(l_index).attribute1,
3598 			p_attribute2 => l_flow_tbl(l_index).attribute2,
3599 			p_attribute3 => l_flow_tbl(l_index).attribute3,
3600 			p_attribute4 => l_flow_tbl(l_index).attribute4,
3601 			p_attribute5 => l_flow_tbl(l_index).attribute5,
3602 			p_attribute6 => l_flow_tbl(l_index).attribute6,
3603 			p_attribute7 => l_flow_tbl(l_index).attribute7,
3604 			p_attribute8 => l_flow_tbl(l_index).attribute8,
3605 			p_attribute9 => l_flow_tbl(l_index).attribute9,
3606 			p_attribute10 => l_flow_tbl(l_index).attribute10,
3607 			p_attribute11 => l_flow_tbl(l_index).attribute11,
3608 			p_attribute12 => l_flow_tbl(l_index).attribute12,
3609 			p_attribute13 => l_flow_tbl(l_index).attribute13,
3610 			p_attribute14 => l_flow_tbl(l_index).attribute14,
3611 			p_attribute15 => l_flow_tbl(l_index).attribute15,
3612         p_created_by  => l_flow_tbl(l_index).created_by,
3613         p_creation_date  => l_flow_tbl(l_index).creation_date,
3614         p_last_updated_by  => l_flow_tbl(l_index).last_updated_by,
3615         p_last_update_date  => l_flow_tbl(l_index).last_update_date,
3616         p_last_update_login  => l_flow_tbl(l_index).last_update_login,
3617             p_loader_timestamp => p_loader_timestamp,
3618   		    p_pass => p_pass,
3619             p_copy_redo_flag => l_copy_redo_flag
3620           );
3621 		-- update flow records if primary page has been changed or
3622 		-- update non-customized data
3623 		elsif ( AK_UPLOAD_GRP.G_NO_CUSTOM_UPDATE AND (NOT AK_UPLOAD_GRP.G_UPDATE_MODE) ) then
3624 		  select af.primary_page_code, af.primary_page_appl_id, af.last_updated_by,
3625 		  aft.last_updated_by,
3626 		  af.last_update_date, aft.last_update_date
3627 		  into l_temp_key_code, l_temp_key_appl_id, l_user_id1, l_user_id2, l_update1, l_update2
3628 		  from ak_flows af, ak_flows_tl aft
3629 		  where af.flow_code = l_flow_tbl(l_index).flow_code
3630 		  and af.flow_application_id = l_flow_tbl(l_index).flow_application_id
3631 		  and af.flow_code = aft.flow_code
3632 		  and af.flow_application_id = aft.flow_application_id
3633 		  and aft.language = userenv('LANG');
3634 		  /*if ( ( ( l_user_id1 = 1 or l_user_id1 = 2 ) and
3635 			( l_user_id2 = 1 or l_user_id2 = 2 )) */
3636                 if ((AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
3637                       p_loader_timestamp => p_loader_timestamp,
3638                       p_created_by => l_flow_tbl(l_index).created_by,
3639                       p_creation_date => l_flow_tbl(l_index).creation_date,
3640                       p_last_updated_by => l_flow_tbl(l_index).last_updated_by,
3641                       p_db_last_updated_by => l_user_id1,
3642                       p_last_update_date => l_flow_tbl(l_index).last_update_date,
3643                       p_db_last_update_date => l_update1,
3644                       p_last_update_login => l_flow_tbl(l_index).last_update_login,
3645                       p_create_or_update => 'UPDATE') and
3646 
3647                    AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
3648                       p_loader_timestamp => p_loader_timestamp,
3649                       p_created_by => l_flow_tbl(l_index).created_by,
3650                       p_creation_date => l_flow_tbl(l_index).creation_date,
3651                       p_last_updated_by => l_flow_tbl(l_index).last_updated_by,
3652                       p_db_last_updated_by => l_user_id2,
3653                       p_last_update_date => l_flow_tbl(l_index).last_update_date,
3654                       p_db_last_update_date => l_update2,
3655                       p_last_update_login => l_flow_tbl(l_index).last_update_login,
3656                       p_create_or_update => 'UPDATE'))
3657 or
3658 			( l_temp_key_code <> l_flow_tbl(l_index).primary_page_code and
3659 			  l_temp_key_appl_id <> l_flow_tbl(l_index).primary_page_appl_id ) ) then
3660 	         AK_FLOW_PVT.UPDATE_FLOW (
3661 	            p_validation_level => p_validation_level,
3662 	            p_api_version_number => 1.0,
3663 	            p_msg_count => l_msg_count,
3664 	            p_msg_data => l_msg_data,
3665 	            p_return_status => l_return_status,
3666 	            p_flow_application_id =>
3667 	                        l_flow_tbl(l_index).flow_application_id,
3668 	            p_flow_code => l_flow_tbl(l_index).flow_code,
3669 	            p_name => l_flow_tbl(l_index).name,
3670 	            p_description => l_flow_tbl(l_index).description,
3671 	            p_primary_page_appl_id => l_flow_tbl(l_index).primary_page_appl_id,
3672 	            p_primary_page_code => l_flow_tbl(l_index).primary_page_code,
3673 	            p_attribute_category => l_flow_tbl(l_index).attribute_category,
3674 				p_attribute1 => l_flow_tbl(l_index).attribute1,
3675 				p_attribute2 => l_flow_tbl(l_index).attribute2,
3676 				p_attribute3 => l_flow_tbl(l_index).attribute3,
3677 				p_attribute4 => l_flow_tbl(l_index).attribute4,
3678 				p_attribute5 => l_flow_tbl(l_index).attribute5,
3679 				p_attribute6 => l_flow_tbl(l_index).attribute6,
3680 				p_attribute7 => l_flow_tbl(l_index).attribute7,
3681 				p_attribute8 => l_flow_tbl(l_index).attribute8,
3685 				p_attribute12 => l_flow_tbl(l_index).attribute12,
3682 				p_attribute9 => l_flow_tbl(l_index).attribute9,
3683 				p_attribute10 => l_flow_tbl(l_index).attribute10,
3684 				p_attribute11 => l_flow_tbl(l_index).attribute11,
3686 				p_attribute13 => l_flow_tbl(l_index).attribute13,
3687 				p_attribute14 => l_flow_tbl(l_index).attribute14,
3688 				p_attribute15 => l_flow_tbl(l_index).attribute15,
3689         p_created_by  => l_flow_tbl(l_index).created_by,
3690         p_creation_date  => l_flow_tbl(l_index).creation_date,
3691         p_last_updated_by  => l_flow_tbl(l_index).last_updated_by,
3692         p_last_update_date  => l_flow_tbl(l_index).last_update_date,
3693         p_last_update_login  => l_flow_tbl(l_index).last_update_login,
3694 	            p_loader_timestamp => p_loader_timestamp,
3695 	  		    p_pass => p_pass,
3696 	            p_copy_redo_flag => l_copy_redo_flag
3697 	          );
3698 		  end if; -- /* if l_user_id1 */
3699 		end if; -- /* if G_UPDATE_MODE */
3700           if (l_copy_redo_flag) then
3701             G_FLOW_REDO_INDEX := G_FLOW_REDO_INDEX + 1;
3702             G_FLOW_REDO_TBL(G_FLOW_REDO_INDEX) := l_flow_tbl(l_index);
3703             l_copy_redo_flag := FALSE;
3704           end if; /* if l_copy_redo_flag */
3705       end if; /* if l_flow_tbl.exists(l_index) exists */
3706     end loop;
3707   end if;
3708 
3709   -- Insert or update all page regions to the database
3710   --
3711   --   Since not all page regions exists in the database, we are
3712   --   creating new page regions with parent regions set to null.
3713   --   Update to certain page regions with a parent region will
3714   --   fail due to the same reason.
3715   --   Later in this procedure, they will be updated with the appropriate
3716   --   parent regions once all the page regions are loaded.
3717   --
3718   if (l_region_tbl.count > 0) then
3719     for l_index in l_region_tbl.FIRST .. l_region_tbl.LAST loop
3720       if (l_region_tbl.exists(l_index)) then
3721         if AK_FLOW_PVT.PAGE_REGION_EXISTS (
3722             p_api_version_number => 1.0,
3723             p_return_status => l_return_status,
3724             p_flow_application_id =>
3725                         l_region_tbl(l_index).flow_application_id,
3726             p_flow_code => l_region_tbl(l_index).flow_code,
3727             p_page_application_id =>
3728                         l_region_tbl(l_index).page_application_id,
3729             p_page_code => l_region_tbl(l_index).page_code,
3730             p_region_application_id =>
3731                         l_region_tbl(l_index).region_application_id,
3732             p_region_code => l_region_tbl(l_index).region_code) then
3733           --
3734           -- Update Page Region only if Update Mode is TRUE
3735 		  --
3736           if (AK_UPLOAD_GRP.G_UPDATE_MODE) then
3737             AK_FLOW_PVT.UPDATE_PAGE_REGION (
3738               p_validation_level => p_validation_level,
3739               p_api_version_number => 1.0,
3740               p_msg_count => l_msg_count,
3741               p_msg_data => l_msg_data,
3742               p_return_status => l_return_status,
3743               p_flow_application_id =>
3744                           l_region_tbl(l_index).flow_application_id,
3745               p_flow_code => l_region_tbl(l_index).flow_code,
3746               p_page_application_id =>
3747                           l_region_tbl(l_index).page_application_id,
3748               p_page_code => l_region_tbl(l_index).page_code,
3749               p_region_application_id =>
3750                           l_region_tbl(l_index).region_application_id,
3751               p_region_code => l_region_tbl(l_index).region_code,
3752               p_display_sequence => l_region_tbl(l_index).display_sequence,
3753               p_region_style => l_region_tbl(l_index).region_style,
3754               p_num_columns => l_region_tbl(l_index).num_columns,
3755               p_icx_custom_call => l_region_tbl(l_index).icx_custom_call,
3756               p_parent_region_application_id =>
3757                           l_region_tbl(l_index).parent_region_appl_id,
3758               p_parent_region_code => l_region_tbl(l_index).parent_region_code,
3759               p_foreign_key_name => l_region_tbl(l_index).foreign_key_name,
3760               p_attribute_category => l_region_tbl(l_index).attribute_category,
3761 			  p_attribute1 => l_region_tbl(l_index).attribute1,
3762 			  p_attribute2 => l_region_tbl(l_index).attribute2,
3763 			  p_attribute3 => l_region_tbl(l_index).attribute3,
3764 			  p_attribute4 => l_region_tbl(l_index).attribute4,
3765 			  p_attribute5 => l_region_tbl(l_index).attribute5,
3766 			  p_attribute6 => l_region_tbl(l_index).attribute6,
3767 			  p_attribute7 => l_region_tbl(l_index).attribute7,
3768 			  p_attribute8 => l_region_tbl(l_index).attribute8,
3769 			  p_attribute9 => l_region_tbl(l_index).attribute9,
3770 			  p_attribute10 => l_region_tbl(l_index).attribute10,
3771 			  p_attribute11 => l_region_tbl(l_index).attribute11,
3772 			  p_attribute12 => l_region_tbl(l_index).attribute12,
3773 			  p_attribute13 => l_region_tbl(l_index).attribute13,
3774 			  p_attribute14 => l_region_tbl(l_index).attribute14,
3775 			  p_attribute15 => l_region_tbl(l_index).attribute15,
3776         p_created_by  => l_region_tbl(l_index).created_by,
3777         p_creation_date  => l_region_tbl(l_index).creation_date,
3778         p_last_updated_by  => l_region_tbl(l_index).last_updated_by,
3779         p_last_update_date  => l_region_tbl(l_index).last_update_date,
3780         p_last_update_login  => l_region_tbl(l_index).last_update_login,
3784             );
3781               p_loader_timestamp => p_loader_timestamp,
3782   		      p_pass => p_pass,
3783               p_copy_redo_flag => l_copy_redo_flag
3785 		  elsif ( AK_UPLOAD_GRP.G_NO_CUSTOM_UPDATE ) then
3786 			select last_updated_by, last_update_date
3787 			into l_user_id1, l_update1
3788 			from ak_flow_page_regions
3789 			where flow_code = l_region_tbl(l_index).flow_code
3790 			and flow_application_id = l_region_tbl(l_index).flow_application_id
3791 			and page_code = l_region_tbl(l_index).page_code
3792 			and page_application_id = l_region_tbl(l_index).page_application_id
3793 			and region_code = l_region_tbl(l_index).region_code
3794 			and region_application_id = l_region_tbl(l_index).region_application_id;
3795 			/*if ( l_user_id1 = 1 or l_user_id1 = 2 ) then*/
3796 
3797                 if AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
3798                       p_loader_timestamp => p_loader_timestamp,
3799                       p_created_by => l_region_tbl(l_index).created_by,
3800                       p_creation_date => l_region_tbl(l_index).creation_date,
3801                       p_last_updated_by => l_region_tbl(l_index).last_updated_by,
3802                       p_db_last_updated_by => l_user_id1,
3803                       p_last_update_date => l_region_tbl(l_index).last_update_date,
3804                       p_db_last_update_date => l_update1,
3805                       p_last_update_login => l_region_tbl(l_index).last_update_login,
3806                       p_create_or_update => 'UPDATE') then
3807 
3808 	            AK_FLOW_PVT.UPDATE_PAGE_REGION (
3809 	              p_validation_level => p_validation_level,
3810 	              p_api_version_number => 1.0,
3811 	              p_msg_count => l_msg_count,
3812 	              p_msg_data => l_msg_data,
3813 	              p_return_status => l_return_status,
3814 	              p_flow_application_id =>
3815 	                          l_region_tbl(l_index).flow_application_id,
3816 	              p_flow_code => l_region_tbl(l_index).flow_code,
3817 	              p_page_application_id =>
3818 	                          l_region_tbl(l_index).page_application_id,
3819 	              p_page_code => l_region_tbl(l_index).page_code,
3820 	              p_region_application_id =>
3821 	                          l_region_tbl(l_index).region_application_id,
3822 	              p_region_code => l_region_tbl(l_index).region_code,
3823 	              p_display_sequence => l_region_tbl(l_index).display_sequence,
3824 	              p_region_style => l_region_tbl(l_index).region_style,
3825 	              p_num_columns => l_region_tbl(l_index).num_columns,
3826 	              p_icx_custom_call => l_region_tbl(l_index).icx_custom_call,
3827 	              p_parent_region_application_id =>
3828 	                          l_region_tbl(l_index).parent_region_appl_id,
3829 	              p_parent_region_code => l_region_tbl(l_index).parent_region_code,
3830 	              p_foreign_key_name => l_region_tbl(l_index).foreign_key_name,
3831 	              p_attribute_category => l_region_tbl(l_index).attribute_category,
3832 				  p_attribute1 => l_region_tbl(l_index).attribute1,
3833 				  p_attribute2 => l_region_tbl(l_index).attribute2,
3834 				  p_attribute3 => l_region_tbl(l_index).attribute3,
3835 				  p_attribute4 => l_region_tbl(l_index).attribute4,
3836 				  p_attribute5 => l_region_tbl(l_index).attribute5,
3837 				  p_attribute6 => l_region_tbl(l_index).attribute6,
3838 				  p_attribute7 => l_region_tbl(l_index).attribute7,
3839 				  p_attribute8 => l_region_tbl(l_index).attribute8,
3840 				  p_attribute9 => l_region_tbl(l_index).attribute9,
3841 				  p_attribute10 => l_region_tbl(l_index).attribute10,
3842 				  p_attribute11 => l_region_tbl(l_index).attribute11,
3843 				  p_attribute12 => l_region_tbl(l_index).attribute12,
3844 				  p_attribute13 => l_region_tbl(l_index).attribute13,
3845 				  p_attribute14 => l_region_tbl(l_index).attribute14,
3846 				  p_attribute15 => l_region_tbl(l_index).attribute15,
3847         p_created_by  => l_region_tbl(l_index).created_by,
3848         p_creation_date  => l_region_tbl(l_index).creation_date,
3849         p_last_updated_by  => l_region_tbl(l_index).last_updated_by,
3850         p_last_update_date  => l_region_tbl(l_index).last_update_date,
3851         p_last_update_login  => l_region_tbl(l_index).last_update_login,
3852 	              p_loader_timestamp => p_loader_timestamp,
3853 	  		      p_pass => p_pass,
3854 	              p_copy_redo_flag => l_copy_redo_flag
3855 	            );
3856 			end if; -- /* if l_user_id1 = 1 */
3857           end if; -- /* if G_UPDATE_MODE G_NO_CUSTOM_UPDATE */
3858         else
3859           AK_FLOW_PVT.CREATE_PAGE_REGION (
3860             p_validation_level => p_validation_level,
3861             p_api_version_number => 1.0,
3862             p_msg_count => l_msg_count,
3863             p_msg_data => l_msg_data,
3864             p_return_status => l_return_status,
3865             p_flow_application_id =>
3866                         l_region_tbl(l_index).flow_application_id,
3867             p_flow_code => l_region_tbl(l_index).flow_code,
3868             p_page_application_id =>
3869                         l_region_tbl(l_index).page_application_id,
3870             p_page_code => l_region_tbl(l_index).page_code,
3871             p_region_application_id =>
3872                         l_region_tbl(l_index).region_application_id,
3873             p_region_code => l_region_tbl(l_index).region_code,
3874             p_display_sequence => l_region_tbl(l_index).display_sequence,
3875             p_region_style => l_region_tbl(l_index).region_style,
3876             p_num_columns => l_region_tbl(l_index).num_columns,
3880             p_foreign_key_name => null,
3877             p_icx_custom_call => l_region_tbl(l_index).icx_custom_call,
3878             p_parent_region_application_id => null,
3879             p_parent_region_code => null,
3881             p_attribute_category => l_region_tbl(l_index).attribute_category,
3882 			p_attribute1 => l_region_tbl(l_index).attribute1,
3883 			p_attribute2 => l_region_tbl(l_index).attribute2,
3884 			p_attribute3 => l_region_tbl(l_index).attribute3,
3885 			p_attribute4 => l_region_tbl(l_index).attribute4,
3886 			p_attribute5 => l_region_tbl(l_index).attribute5,
3887 			p_attribute6 => l_region_tbl(l_index).attribute6,
3888 			p_attribute7 => l_region_tbl(l_index).attribute7,
3889 			p_attribute8 => l_region_tbl(l_index).attribute8,
3890 			p_attribute9 => l_region_tbl(l_index).attribute9,
3891 			p_attribute10 => l_region_tbl(l_index).attribute10,
3892 			p_attribute11 => l_region_tbl(l_index).attribute11,
3893 			p_attribute12 => l_region_tbl(l_index).attribute12,
3894 			p_attribute13 => l_region_tbl(l_index).attribute13,
3895 			p_attribute14 => l_region_tbl(l_index).attribute14,
3896 			p_attribute15 => l_region_tbl(l_index).attribute15,
3897         p_created_by => l_region_tbl(l_index).created_by,
3898         p_creation_date => l_region_tbl(l_index).creation_date,
3899         p_last_updated_by => l_region_tbl(l_index).last_updated_by,
3900         p_last_update_date => l_region_tbl(l_index).last_update_date,
3901         p_last_update_login => l_region_tbl(l_index).last_update_login,
3902             p_loader_timestamp => p_loader_timestamp,
3903   		    p_pass => p_pass,
3904             p_copy_redo_flag => l_copy_redo_flag
3905           );
3906         end if;	-- /* if PAGE_REGION_EXISTS */
3907 		--
3908         -- If API call returns with an error status, upload aborts
3909         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
3910         (l_return_status = FND_API.G_RET_STS_ERROR) then
3911           RAISE FND_API.G_EXC_ERROR;
3912         end if; -- /* if l_return_status */
3913         if (l_copy_redo_flag) then
3914           G_PAGE_REGION_REDO_INDEX := G_PAGE_REGION_REDO_INDEX + 1;
3915           G_PAGE_REGION_REDO_TBL(G_PAGE_REGION_REDO_INDEX) := l_region_tbl(l_index);
3916           l_copy_redo_flag := FALSE;
3917         end if; /* if l_copy_redo_flag */
3918 
3919       end if; -- /* if l_region_tbl.exists */
3920     end loop;
3921   end if;
3922 
3923   -- Update parent region columns for page regions
3924   --
3925   --   Now that all page regions have been loaded into the database,
3926   --   we can load the parent region columns for all page regions that
3927   --   has a parent region.
3928   --
3929   --   Intrapage region relations are created in UPDATE_PAGE_REGION when
3930   --   a parent region is specified.
3931   --
3932   if (l_region_tbl.count > 0) then
3933     for l_index in l_region_tbl.FIRST .. l_region_tbl.LAST loop
3934       if (l_region_tbl.exists(l_index)) then
3935         if ( (l_region_tbl(l_index).parent_region_appl_id is not null) or
3936              (l_region_tbl(l_index).parent_region_code is not null) ) then
3937          AK_FLOW_PVT.UPDATE_PAGE_REGION (
3938             p_validation_level => p_validation_level,
3939             p_api_version_number => 1.0,
3940             p_msg_count => l_msg_count,
3941             p_msg_data => l_msg_data,
3942             p_return_status => l_return_status,
3943             p_flow_application_id =>
3944                         l_region_tbl(l_index).flow_application_id,
3945             p_flow_code => l_region_tbl(l_index).flow_code,
3946             p_page_application_id =>
3947                         l_region_tbl(l_index).page_application_id,
3948             p_page_code => l_region_tbl(l_index).page_code,
3949             p_region_application_id =>
3950                         l_region_tbl(l_index).region_application_id,
3951             p_region_code => l_region_tbl(l_index).region_code,
3952             p_parent_region_application_id =>
3953                         l_region_tbl(l_index).parent_region_appl_id,
3954             p_parent_region_code => l_region_tbl(l_index).parent_region_code,
3955             p_foreign_key_name => l_region_tbl(l_index).foreign_key_name,
3956             p_attribute_category => l_region_tbl(l_index).attribute_category,
3957 			p_attribute1 => l_region_tbl(l_index).attribute1,
3958 			p_attribute2 => l_region_tbl(l_index).attribute2,
3959 			p_attribute3 => l_region_tbl(l_index).attribute3,
3960 			p_attribute4 => l_region_tbl(l_index).attribute4,
3961 			p_attribute5 => l_region_tbl(l_index).attribute5,
3962 			p_attribute6 => l_region_tbl(l_index).attribute6,
3963 			p_attribute7 => l_region_tbl(l_index).attribute7,
3964 			p_attribute8 => l_region_tbl(l_index).attribute8,
3965 			p_attribute9 => l_region_tbl(l_index).attribute9,
3966 			p_attribute10 => l_region_tbl(l_index).attribute10,
3967 			p_attribute11 => l_region_tbl(l_index).attribute11,
3968 			p_attribute12 => l_region_tbl(l_index).attribute12,
3969 			p_attribute13 => l_region_tbl(l_index).attribute13,
3970 			p_attribute14 => l_region_tbl(l_index).attribute14,
3971 			p_attribute15 => l_region_tbl(l_index).attribute15,
3972         p_created_by  => l_region_tbl(l_index).created_by,
3973         p_creation_date  => l_region_tbl(l_index).creation_date,
3974         p_last_updated_by  => l_region_tbl(l_index).last_updated_by,
3975         p_last_update_date  => l_region_tbl(l_index).last_update_date,
3976         p_last_update_login  => l_region_tbl(l_index).last_update_login,
3977             p_loader_timestamp => p_loader_timestamp,
3978   		    p_pass => p_pass,
3979             p_copy_redo_flag => l_copy_redo_flag
3983         (l_return_status = FND_API.G_RET_STS_ERROR) then
3980           );
3981         -- If API call returns with an error status, upload aborts
3982         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
3984           RAISE FND_API.G_EXC_ERROR;
3985         end if; -- /* if l_return_status */
3986           if (l_copy_redo_flag) then
3987             G_PAGE_REGION_REDO_INDEX := G_PAGE_REGION_REDO_INDEX + 1;
3988             G_PAGE_REGION_REDO_TBL(G_PAGE_REGION_REDO_INDEX) := l_region_tbl(l_index);
3989             l_copy_redo_flag := FALSE;
3990           end if; /* if l_copy_redo_flag */
3991         end if; /* if parent_region is not null */
3992       end if; /* if l_region_tbl(l_index) exists */
3993     end loop;
3994   end if;
3995 
3996   -- Update primary region columns for new flow pages, and update all columns
3997   -- for existing flow pages.
3998   --
3999   --   Now that all flow page regions have been loaded into the database,
4000   --   we can load the primary region columns for all new flow pages that
4001   --   has a primary region. Existing flow pages are also updated with new
4002   --   data in the loader file at this time.
4003   --
4004   if (l_page_tbl.count > 0) then
4005     for l_index in l_page_tbl.FIRST .. l_page_tbl.LAST loop
4006       if (l_page_tbl.exists(l_index)) then
4007 		-- update all records
4008 		if ( AK_UPLOAD_GRP.G_UPDATE_MODE ) then
4009          AK_FLOW_PVT.UPDATE_PAGE (
4010             p_validation_level => p_validation_level,
4011             p_api_version_number => 1.0,
4012             p_msg_count => l_msg_count,
4013             p_msg_data => l_msg_data,
4014             p_return_status => l_return_status,
4015             p_flow_application_id =>
4016                         l_page_tbl(l_index).flow_application_id,
4017             p_flow_code => l_page_tbl(l_index).flow_code,
4018             p_page_application_id =>
4019                         l_page_tbl(l_index).page_application_id,
4020             p_page_code => l_page_tbl(l_index).page_code,
4021             p_primary_region_appl_id =>
4022                         l_page_tbl(l_index).primary_region_appl_id,
4023             p_primary_region_code => l_page_tbl(l_index).primary_region_code,
4024             p_attribute_category => l_page_tbl(l_index).attribute_category,
4025 			p_attribute1 => l_page_tbl(l_index).attribute1,
4026 			p_attribute2 => l_page_tbl(l_index).attribute2,
4027 			p_attribute3 => l_page_tbl(l_index).attribute3,
4028 			p_attribute4 => l_page_tbl(l_index).attribute4,
4029 			p_attribute5 => l_page_tbl(l_index).attribute5,
4030 			p_attribute6 => l_page_tbl(l_index).attribute6,
4031 			p_attribute7 => l_page_tbl(l_index).attribute7,
4032 			p_attribute8 => l_page_tbl(l_index).attribute8,
4033 			p_attribute9 => l_page_tbl(l_index).attribute9,
4034 			p_attribute10 => l_page_tbl(l_index).attribute10,
4035 			p_attribute11 => l_page_tbl(l_index).attribute11,
4036 			p_attribute12 => l_page_tbl(l_index).attribute12,
4037 			p_attribute13 => l_page_tbl(l_index).attribute13,
4038 			p_attribute14 => l_page_tbl(l_index).attribute14,
4039 			p_attribute15 => l_page_tbl(l_index).attribute15,
4040         p_created_by  => l_page_tbl(l_index).created_by,
4041         p_creation_date  => l_page_tbl(l_index).creation_date,
4042         p_last_updated_by  => l_page_tbl(l_index).last_updated_by,
4043         p_last_update_date  => l_page_tbl(l_index).last_update_date,
4044         p_last_update_login  => l_page_tbl(l_index).last_update_login,
4045             p_name => l_page_tbl(l_index).name,
4046             p_description => l_page_tbl(l_index).description,
4047             p_loader_timestamp => p_loader_timestamp,
4048   		    p_pass => p_pass,
4049             p_copy_redo_flag => l_copy_redo_flag
4050           );
4051 		elsif ( AK_UPLOAD_GRP.G_NO_CUSTOM_UPDATE or (NOT AK_UPLOAD_GRP.G_UPDATE_MODE) ) then
4052 		  select afp.primary_region_code, afp.primary_region_appl_id, afp.last_updated_by,
4053 		  afpt.last_updated_by,
4054 		  afp.last_update_date, afpt.last_update_date
4055 		  into l_temp_key_code, l_temp_key_appl_id,
4056 		  l_user_id1 , l_user_id2, l_update1, l_update2
4057 		  from ak_flow_pages afp, ak_flow_pages_tl afpt
4058 		  where afp.flow_code = l_page_tbl(l_index).flow_code
4059 		  and afp.flow_application_id = l_page_tbl(l_index).flow_application_id
4060 		  and afp.page_code = l_page_tbl(l_index).page_code
4061 		  and afp.page_application_id = l_page_tbl(l_index).page_application_id
4062 		  and afp.flow_code = afpt.flow_code
4063 		  and afp.flow_application_id = afpt.flow_application_id
4064 		  and afp.page_code = afpt.page_code
4065 		  and afp.page_application_id = afpt.page_application_id
4066 		  and afpt.language = userenv('LANG');
4067 		  /*if ( ( ( l_user_id1 = 1 or l_user_id1 = 2) and
4068 			(l_user_id2 = 1 or l_user_id2 = 2)) */
4069                 if ((AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
4070                       p_loader_timestamp => p_loader_timestamp,
4071                       p_created_by => l_page_tbl(l_index).created_by,
4072                       p_creation_date => l_page_tbl(l_index).creation_date,
4073                       p_last_updated_by => l_page_tbl(l_index).last_updated_by,
4074                       p_db_last_updated_by => l_user_id1,
4075                       p_last_update_date => l_page_tbl(l_index).last_update_date,
4076                       p_db_last_update_date => l_update1,
4077                       p_last_update_login => l_page_tbl(l_index).last_update_login,
4078                       p_create_or_update => 'UPDATE') and
4079 
4080 		    AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
4084                       p_last_updated_by => l_page_tbl(l_index).last_updated_by,
4081                       p_loader_timestamp => p_loader_timestamp,
4082                       p_created_by => l_page_tbl(l_index).created_by,
4083                       p_creation_date => l_page_tbl(l_index).creation_date,
4085                       p_db_last_updated_by => l_user_id2,
4086                       p_last_update_date => l_page_tbl(l_index).last_update_date,
4087                       p_db_last_update_date => l_update2,
4088                       p_last_update_login => l_page_tbl(l_index).last_update_login,
4089                       p_create_or_update => 'UPDATE'))
4090 or
4091 		  	( l_temp_key_appl_id <> l_page_tbl(l_index).primary_region_appl_id and
4092 			  l_temp_key_code <> l_page_tbl(l_index).primary_region_code ) ) then
4093 	         AK_FLOW_PVT.UPDATE_PAGE (
4094 	            p_validation_level => p_validation_level,
4095 	            p_api_version_number => 1.0,
4096 	            p_msg_count => l_msg_count,
4097 	            p_msg_data => l_msg_data,
4098 	            p_return_status => l_return_status,
4099 	            p_flow_application_id =>
4100 	                        l_page_tbl(l_index).flow_application_id,
4101 	            p_flow_code => l_page_tbl(l_index).flow_code,
4102 	            p_page_application_id =>
4103 	                        l_page_tbl(l_index).page_application_id,
4104 	            p_page_code => l_page_tbl(l_index).page_code,
4105 	            p_primary_region_appl_id =>
4106 	                        l_page_tbl(l_index).primary_region_appl_id,
4107 	            p_primary_region_code => l_page_tbl(l_index).primary_region_code,
4108 	            p_attribute_category => l_page_tbl(l_index).attribute_category,
4109 				p_attribute1 => l_page_tbl(l_index).attribute1,
4110 				p_attribute2 => l_page_tbl(l_index).attribute2,
4111 				p_attribute3 => l_page_tbl(l_index).attribute3,
4112 				p_attribute4 => l_page_tbl(l_index).attribute4,
4113 				p_attribute5 => l_page_tbl(l_index).attribute5,
4114 				p_attribute6 => l_page_tbl(l_index).attribute6,
4115 				p_attribute7 => l_page_tbl(l_index).attribute7,
4116 				p_attribute8 => l_page_tbl(l_index).attribute8,
4117 				p_attribute9 => l_page_tbl(l_index).attribute9,
4118 				p_attribute10 => l_page_tbl(l_index).attribute10,
4119 				p_attribute11 => l_page_tbl(l_index).attribute11,
4120 				p_attribute12 => l_page_tbl(l_index).attribute12,
4121 				p_attribute13 => l_page_tbl(l_index).attribute13,
4122 				p_attribute14 => l_page_tbl(l_index).attribute14,
4123 				p_attribute15 => l_page_tbl(l_index).attribute15,
4124 	            p_name => l_page_tbl(l_index).name,
4125 	            p_description => l_page_tbl(l_index).description,
4126         p_created_by  => l_page_tbl(l_index).created_by,
4127         p_creation_date  => l_page_tbl(l_index).creation_date,
4128         p_last_updated_by  => l_page_tbl(l_index).last_updated_by,
4129         p_last_update_date  => l_page_tbl(l_index).last_update_date,
4130         p_last_update_login  => l_page_tbl(l_index).last_update_login,
4131 	            p_loader_timestamp => p_loader_timestamp,
4132 	  		    p_pass => p_pass,
4133 	            p_copy_redo_flag => l_copy_redo_flag
4134 	          );
4135 		  end if; -- /* if l_user_id1 */
4136 		end if; -- /* if G_UPDATE_MODE */
4137         -- If API call returns with an error status, upload aborts
4138         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
4139         (l_return_status = FND_API.G_RET_STS_ERROR) then
4140           RAISE FND_API.G_EXC_ERROR;
4141         end if; -- /* if l_return_status */
4142         if (l_copy_redo_flag) then
4143           G_PAGE_REDO_INDEX := G_PAGE_REDO_INDEX + 1;
4144           G_PAGE_REDO_TBL(G_PAGE_REDO_INDEX) := l_page_tbl(l_index);
4145           l_copy_redo_flag := FALSE;
4146         end if; /* if l_copy_redo_flag */
4147       end if; /* if l_page_tbl(l_index) exists */
4148     end loop;
4149   end if;
4150 
4151   -- Insert or update all interpage region relations to the database
4152   --
4153   --   Create or update interpage region relations to the database.
4154   --   All intrapage region relations were created while loading
4155   --   flow page regions.
4156   --
4157   if (l_relation_tbl.count > 0) then
4158     for l_index in l_relation_tbl.FIRST .. l_relation_tbl.LAST loop
4159       if (l_relation_tbl.exists(l_index)) then
4160         if AK_FLOW_PVT.REGION_RELATION_EXISTS (
4161             p_api_version_number => 1.0,
4162             p_return_status => l_return_status,
4163             p_flow_application_id =>
4164                         l_relation_tbl(l_index).flow_application_id,
4165             p_flow_code => l_relation_tbl(l_index).flow_code,
4166             p_foreign_key_name => l_relation_tbl(l_index).foreign_key_name,
4167             p_from_page_appl_id => l_relation_tbl(l_index).from_page_appl_id,
4168             p_from_page_code => l_relation_tbl(l_index).from_page_code,
4169             p_from_region_appl_id =>
4170                         l_relation_tbl(l_index).from_region_appl_id,
4171             p_from_region_code => l_relation_tbl(l_index).from_region_code,
4172             p_to_page_appl_id => l_relation_tbl(l_index).to_page_appl_id,
4173             p_to_page_code => l_relation_tbl(l_index).to_page_code,
4174             p_to_region_appl_id =>
4175                         l_relation_tbl(l_index).to_region_appl_id,
4176             p_to_region_code => l_relation_tbl(l_index).to_region_code) then
4177           --
4178 		  -- Update Flow Page Region Relation only if G_UPDATE_MODE is TRUE
4179 		  --
4180 		  if (AK_UPLOAD_GRP.G_UPDATE_MODE) then
4181             AK_FLOW_PVT.UPDATE_REGION_RELATION (
4185               p_msg_data => l_msg_data,
4182               p_validation_level => p_validation_level,
4183               p_api_version_number => 1.0,
4184               p_msg_count => l_msg_count,
4186               p_return_status => l_return_status,
4187               p_flow_application_id =>
4188                           l_relation_tbl(l_index).flow_application_id,
4189               p_flow_code => l_relation_tbl(l_index).flow_code,
4190               p_foreign_key_name => l_relation_tbl(l_index).foreign_key_name,
4191               p_from_page_appl_id => l_relation_tbl(l_index).from_page_appl_id,
4192               p_from_page_code => l_relation_tbl(l_index).from_page_code,
4193               p_from_region_appl_id =>
4194                           l_relation_tbl(l_index).from_region_appl_id,
4195               p_from_region_code => l_relation_tbl(l_index).from_region_code,
4196               p_to_page_appl_id => l_relation_tbl(l_index).to_page_appl_id,
4197               p_to_page_code => l_relation_tbl(l_index).to_page_code,
4198               p_to_region_appl_id =>
4199                           l_relation_tbl(l_index).to_region_appl_id,
4200               p_to_region_code => l_relation_tbl(l_index).to_region_code,
4201               p_application_id => l_relation_tbl(l_index).application_id,
4202               p_attribute_category => l_relation_tbl(l_index).attribute_category,
4203 			  p_attribute1 => l_relation_tbl(l_index).attribute1,
4204 			  p_attribute2 => l_relation_tbl(l_index).attribute2,
4205 			  p_attribute3 => l_relation_tbl(l_index).attribute3,
4206 			  p_attribute4 => l_relation_tbl(l_index).attribute4,
4207 			  p_attribute5 => l_relation_tbl(l_index).attribute5,
4208 			  p_attribute6 => l_relation_tbl(l_index).attribute6,
4209 			  p_attribute7 => l_relation_tbl(l_index).attribute7,
4210 			  p_attribute8 => l_relation_tbl(l_index).attribute8,
4211 			  p_attribute9 => l_relation_tbl(l_index).attribute9,
4212 			  p_attribute10 => l_relation_tbl(l_index).attribute10,
4213 			  p_attribute11 => l_relation_tbl(l_index).attribute11,
4214 			  p_attribute12 => l_relation_tbl(l_index).attribute12,
4215 			  p_attribute13 => l_relation_tbl(l_index).attribute13,
4216 			  p_attribute14 => l_relation_tbl(l_index).attribute14,
4217 			  p_attribute15 => l_relation_tbl(l_index).attribute15,
4218         p_created_by  => l_relation_tbl(l_index).created_by,
4219         p_creation_date  => l_relation_tbl(l_index).creation_date,
4220         p_last_updated_by  => l_relation_tbl(l_index).last_updated_by,
4221         p_last_update_date  => l_relation_tbl(l_index).last_update_date,
4222         p_last_update_login  => l_relation_tbl(l_index).last_update_login,
4223               p_loader_timestamp => p_loader_timestamp,
4224   		      p_pass => p_pass,
4225               p_copy_redo_flag => l_copy_redo_flag
4226             );
4227 		  elsif ( AK_UPLOAD_GRP.G_NO_CUSTOM_UPDATE ) then
4228 		    select last_updated_by, last_update_date
4229 			into l_user_id1, l_update1
4230 			from ak_flow_region_relations
4231 			where flow_code = l_relation_tbl(l_index).flow_code
4232 			and flow_application_id = l_relation_tbl(l_index).flow_application_id
4233 			and foreign_key_name = l_relation_tbl(l_index).foreign_key_name
4234 			and from_page_code = l_relation_tbl(l_index).from_page_code
4235 			and from_page_appl_id = l_relation_tbl(l_index).from_page_appl_id
4236 			and from_region_code = l_relation_tbl(l_index).from_region_code
4237 			and from_region_appl_id = l_relation_tbl(l_index).from_region_appl_id
4238 			and to_page_code = l_relation_tbl(l_index).to_page_code
4239 			and to_page_appl_id = l_relation_tbl(l_index).to_page_appl_id
4240 			and to_region_code = l_relation_tbl(l_index).to_region_code
4241 			and to_region_appl_id = l_relation_tbl(l_index).to_region_appl_id;
4242 
4243 			/*if ( l_user_id1 = 1 or l_user_id1 = 2) then*/
4244                 if AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
4245                       p_loader_timestamp => p_loader_timestamp,
4246                       p_created_by => l_relation_tbl(l_index).created_by,
4247                       p_creation_date => l_relation_tbl(l_index).creation_date,
4248                       p_last_updated_by => l_relation_tbl(l_index).last_updated_by,
4249                       p_db_last_updated_by => l_user_id1,
4250                       p_last_update_date => l_relation_tbl(l_index).last_update_date,
4251                       p_db_last_update_date => l_update1,
4252                       p_last_update_login => l_relation_tbl(l_index).last_update_login,
4253                       p_create_or_update => 'UPDATE') then
4254 
4255 	            AK_FLOW_PVT.UPDATE_REGION_RELATION (
4256 	              p_validation_level => p_validation_level,
4257 	              p_api_version_number => 1.0,
4258 	              p_msg_count => l_msg_count,
4259 	              p_msg_data => l_msg_data,
4260 	              p_return_status => l_return_status,
4261 	              p_flow_application_id =>
4262 	                          l_relation_tbl(l_index).flow_application_id,
4263 	              p_flow_code => l_relation_tbl(l_index).flow_code,
4264 	              p_foreign_key_name => l_relation_tbl(l_index).foreign_key_name,
4265 	              p_from_page_appl_id => l_relation_tbl(l_index).from_page_appl_id,
4266 	              p_from_page_code => l_relation_tbl(l_index).from_page_code,
4267 	              p_from_region_appl_id =>
4268 	                          l_relation_tbl(l_index).from_region_appl_id,
4269 	              p_from_region_code => l_relation_tbl(l_index).from_region_code,
4270 	              p_to_page_appl_id => l_relation_tbl(l_index).to_page_appl_id,
4271 	              p_to_page_code => l_relation_tbl(l_index).to_page_code,
4272 	              p_to_region_appl_id =>
4276 	              p_attribute_category => l_relation_tbl(l_index).attribute_category,
4273 	                          l_relation_tbl(l_index).to_region_appl_id,
4274 	              p_to_region_code => l_relation_tbl(l_index).to_region_code,
4275 	              p_application_id => l_relation_tbl(l_index).application_id,
4277 				  p_attribute1 => l_relation_tbl(l_index).attribute1,
4278 				  p_attribute2 => l_relation_tbl(l_index).attribute2,
4279 				  p_attribute3 => l_relation_tbl(l_index).attribute3,
4280 				  p_attribute4 => l_relation_tbl(l_index).attribute4,
4281 				  p_attribute5 => l_relation_tbl(l_index).attribute5,
4282 				  p_attribute6 => l_relation_tbl(l_index).attribute6,
4283 				  p_attribute7 => l_relation_tbl(l_index).attribute7,
4284 				  p_attribute8 => l_relation_tbl(l_index).attribute8,
4285 				  p_attribute9 => l_relation_tbl(l_index).attribute9,
4286 				  p_attribute10 => l_relation_tbl(l_index).attribute10,
4287 				  p_attribute11 => l_relation_tbl(l_index).attribute11,
4288 				  p_attribute12 => l_relation_tbl(l_index).attribute12,
4289 				  p_attribute13 => l_relation_tbl(l_index).attribute13,
4290 				  p_attribute14 => l_relation_tbl(l_index).attribute14,
4291 				  p_attribute15 => l_relation_tbl(l_index).attribute15,
4292         p_created_by  => l_relation_tbl(l_index).created_by,
4293         p_creation_date  => l_relation_tbl(l_index).creation_date,
4294         p_last_updated_by  => l_relation_tbl(l_index).last_updated_by,
4295         p_last_update_date  => l_relation_tbl(l_index).last_update_date,
4296         p_last_update_login  => l_relation_tbl(l_index).last_update_login,
4297 	              p_loader_timestamp => p_loader_timestamp,
4298 	  		      p_pass => p_pass,
4299 	              p_copy_redo_flag => l_copy_redo_flag
4300 	            );
4301 			end if; -- /* if l_user_id1 = 1 */
4302           end if; -- /* if G_UPDATE_MODE G_NO_CUSTOM_UPDATE */
4303         else
4304           AK_FLOW_PVT.CREATE_REGION_RELATION (
4305             p_validation_level => p_validation_level,
4306             p_api_version_number => 1.0,
4307             p_msg_count => l_msg_count,
4308             p_msg_data => l_msg_data,
4309             p_return_status => l_return_status,
4310             p_flow_application_id =>
4311                         l_relation_tbl(l_index).flow_application_id,
4312             p_flow_code => l_relation_tbl(l_index).flow_code,
4313             p_foreign_key_name => l_relation_tbl(l_index).foreign_key_name,
4314             p_from_page_appl_id => l_relation_tbl(l_index).from_page_appl_id,
4315             p_from_page_code => l_relation_tbl(l_index).from_page_code,
4316             p_from_region_appl_id =>
4317                         l_relation_tbl(l_index).from_region_appl_id,
4318             p_from_region_code => l_relation_tbl(l_index).from_region_code,
4319             p_to_page_appl_id => l_relation_tbl(l_index).to_page_appl_id,
4320             p_to_page_code => l_relation_tbl(l_index).to_page_code,
4321             p_to_region_appl_id =>
4322                         l_relation_tbl(l_index).to_region_appl_id,
4323             p_to_region_code => l_relation_tbl(l_index).to_region_code,
4324             p_application_id => l_relation_tbl(l_index).application_id,
4325             p_attribute_category => l_relation_tbl(l_index).attribute_category,
4326 			p_attribute1 => l_relation_tbl(l_index).attribute1,
4327 			p_attribute2 => l_relation_tbl(l_index).attribute2,
4328 			p_attribute3 => l_relation_tbl(l_index).attribute3,
4329 			p_attribute4 => l_relation_tbl(l_index).attribute4,
4330 			p_attribute5 => l_relation_tbl(l_index).attribute5,
4331 			p_attribute6 => l_relation_tbl(l_index).attribute6,
4332 			p_attribute7 => l_relation_tbl(l_index).attribute7,
4333 			p_attribute8 => l_relation_tbl(l_index).attribute8,
4334 			p_attribute9 => l_relation_tbl(l_index).attribute9,
4335 			p_attribute10 => l_relation_tbl(l_index).attribute10,
4336 			p_attribute11 => l_relation_tbl(l_index).attribute11,
4337 			p_attribute12 => l_relation_tbl(l_index).attribute12,
4338 			p_attribute13 => l_relation_tbl(l_index).attribute13,
4339 			p_attribute14 => l_relation_tbl(l_index).attribute14,
4340 			p_attribute15 => l_relation_tbl(l_index).attribute15,
4341         p_created_by => l_relation_tbl(l_index).created_by,
4342         p_creation_date => l_relation_tbl(l_index).creation_date,
4343         p_last_updated_by => l_relation_tbl(l_index).last_updated_by,
4344         p_last_update_date => l_relation_tbl(l_index).last_update_date,
4345         p_last_update_login => l_relation_tbl(l_index).last_update_login,
4346             p_loader_timestamp => p_loader_timestamp,
4347   		    p_pass => p_pass,
4348             p_copy_redo_flag => l_copy_redo_flag
4349           );
4350         end if; -- /* if REGION_RELATION_EXISTS */
4351 		--
4352         -- If API call returns with an error status, upload aborts
4353         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
4354         (l_return_status = FND_API.G_RET_STS_ERROR) then
4355           RAISE FND_API.G_EXC_ERROR;
4356         end if; -- /* if l_return_status */
4357         if (l_copy_redo_flag) then
4358           G_REGION_RELATION_REDO_INDEX := G_REGION_RELATION_REDO_INDEX + 1;
4359           G_REGION_RELATION_REDO_TBL(G_REGION_RELATION_REDO_INDEX) := l_relation_tbl(l_index);
4360           l_copy_redo_flag := FALSE;
4361         end if; /* if l_copy_redo_flag */
4362       end if;
4363     end loop;
4364   end if;
4365 
4366   -- Insert or update all page region items to the database
4367   --
4368   --   Create or update page region items to the database. This step
4369   --   must be done after all region relations have been loaded, since
4373     for l_index in l_item_tbl.FIRST .. l_item_tbl.LAST loop
4370   --   page region items (or links) depends on region relations.
4371   --
4372   if (l_item_tbl.count > 0) then
4374       if (l_item_tbl.exists(l_index)) then
4375         if AK_FLOW_PVT.PAGE_REGION_ITEM_EXISTS (
4376             p_api_version_number => 1.0,
4377             p_return_status => l_return_status,
4378             p_flow_application_id =>
4379                         l_item_tbl(l_index).flow_application_id,
4380             p_flow_code => l_item_tbl(l_index).flow_code,
4381             p_page_application_id =>
4382                         l_item_tbl(l_index).page_application_id,
4383             p_page_code => l_item_tbl(l_index).page_code,
4384             p_region_application_id =>
4385                         l_item_tbl(l_index).region_application_id,
4386             p_region_code => l_item_tbl(l_index).region_code,
4387             p_attribute_application_id =>
4388                         l_item_tbl(l_index).attribute_application_id,
4389             p_attribute_code => l_item_tbl(l_index).attribute_code) then
4390           --
4391 		  -- Update Flow Page Region Item only if G_UPDATE_MODE is TRUE
4392 		  --
4393 		  if (AK_UPLOAD_GRP.G_UPDATE_MODE) then
4394             AK_FLOW_PVT.UPDATE_PAGE_REGION_ITEM (
4395                p_validation_level => p_validation_level,
4396                p_api_version_number => 1.0,
4397                p_msg_count => l_msg_count,
4398                p_msg_data => l_msg_data,
4399                p_return_status => l_return_status,
4400                p_flow_application_id =>
4401                            l_item_tbl(l_index).flow_application_id,
4402                p_flow_code => l_item_tbl(l_index).flow_code,
4403                p_page_application_id =>
4404                            l_item_tbl(l_index).page_application_id,
4405                p_page_code => l_item_tbl(l_index).page_code,
4406                p_region_application_id =>
4407                            l_item_tbl(l_index).region_application_id,
4408                p_region_code => l_item_tbl(l_index).region_code,
4409                p_attribute_application_id =>
4410                            l_item_tbl(l_index).attribute_application_id,
4411                p_attribute_code => l_item_tbl(l_index).attribute_code,
4412                p_to_page_appl_id => l_item_tbl(l_index).to_page_appl_id,
4413                p_to_page_code => l_item_tbl(l_index).to_page_code,
4414                p_to_url_attribute_appl_id =>
4415                            l_item_tbl(l_index).to_url_attribute_appl_id,
4416                p_to_url_attribute_code =>
4417                            l_item_tbl(l_index).to_url_attribute_code,
4418                p_attribute_category => l_item_tbl(l_index).attribute_category,
4419 			   p_attribute1 => l_item_tbl(l_index).attribute1,
4420 			   p_attribute2 => l_item_tbl(l_index).attribute2,
4421 			   p_attribute3 => l_item_tbl(l_index).attribute3,
4422 			   p_attribute4 => l_item_tbl(l_index).attribute4,
4423 			   p_attribute5 => l_item_tbl(l_index).attribute5,
4424 			   p_attribute6 => l_item_tbl(l_index).attribute6,
4425 			   p_attribute7 => l_item_tbl(l_index).attribute7,
4426 			   p_attribute8 => l_item_tbl(l_index).attribute8,
4427 			   p_attribute9 => l_item_tbl(l_index).attribute9,
4428 			   p_attribute10 => l_item_tbl(l_index).attribute10,
4429 			   p_attribute11 => l_item_tbl(l_index).attribute11,
4430 			   p_attribute12 => l_item_tbl(l_index).attribute12,
4431 			   p_attribute13 => l_item_tbl(l_index).attribute13,
4432 			   p_attribute14 => l_item_tbl(l_index).attribute14,
4433 			   p_attribute15 => l_item_tbl(l_index).attribute15,
4434         p_created_by  => l_item_tbl(l_index).created_by,
4435         p_creation_date  => l_item_tbl(l_index).creation_date,
4436         p_last_updated_by  => l_item_tbl(l_index).last_updated_by,
4437         p_last_update_date  => l_item_tbl(l_index).last_update_date,
4438         p_last_update_login  => l_item_tbl(l_index).last_update_login,
4439                p_loader_timestamp => p_loader_timestamp,
4440                p_pass => p_pass,
4441                p_copy_redo_flag => l_copy_redo_flag
4442              );
4443 		  elsif ( AK_UPLOAD_GRP.G_NO_CUSTOM_UPDATE ) then
4444 		    select last_updated_by, last_update_date
4445 			into l_user_id1, l_update1
4446 			from ak_flow_page_region_items
4447 			where flow_code = l_item_tbl(l_index).flow_code
4448 			and flow_application_id = l_item_tbl(l_index).flow_application_id
4449 			and page_code = l_item_tbl(l_index).page_code
4450 			and page_application_id = l_item_tbl(l_index).page_application_id
4451 			and region_code = l_item_tbl(l_index).region_code
4452 			and region_application_id = l_item_tbl(l_index).region_application_id
4453 			and attribute_code = l_item_tbl(l_index).attribute_code
4454 			and attribute_application_id = l_item_tbl(l_index).attribute_application_id;
4455 			/*if ( l_user_id1 = 1 or l_user_id1 = 2) then*/
4456                 if AK_ON_OBJECTS_PVT.IS_UPDATEABLE(
4457                       p_loader_timestamp => p_loader_timestamp,
4458                       p_created_by => l_item_tbl(l_index).created_by,
4459                       p_creation_date => l_item_tbl(l_index).creation_date,
4460                       p_last_updated_by => l_item_tbl(l_index).last_updated_by,
4461                       p_db_last_updated_by => l_user_id1,
4462                       p_last_update_date => l_item_tbl(l_index).last_update_date,
4463                       p_db_last_update_date => l_update1,
4464                       p_last_update_login => l_item_tbl(l_index).last_update_login,
4465                       p_create_or_update => 'UPDATE') then
4466 
4470 	               p_msg_count => l_msg_count,
4467 	            AK_FLOW_PVT.UPDATE_PAGE_REGION_ITEM (
4468 	               p_validation_level => p_validation_level,
4469 	               p_api_version_number => 1.0,
4471 	               p_msg_data => l_msg_data,
4472 	               p_return_status => l_return_status,
4473 	               p_flow_application_id =>
4474 	                           l_item_tbl(l_index).flow_application_id,
4475 	               p_flow_code => l_item_tbl(l_index).flow_code,
4476 	               p_page_application_id =>
4477 	                           l_item_tbl(l_index).page_application_id,
4478 	               p_page_code => l_item_tbl(l_index).page_code,
4479 	               p_region_application_id =>
4480 	                           l_item_tbl(l_index).region_application_id,
4481 	               p_region_code => l_item_tbl(l_index).region_code,
4482 	               p_attribute_application_id =>
4483 	                           l_item_tbl(l_index).attribute_application_id,
4484 	               p_attribute_code => l_item_tbl(l_index).attribute_code,
4485 	               p_to_page_appl_id => l_item_tbl(l_index).to_page_appl_id,
4486 	               p_to_page_code => l_item_tbl(l_index).to_page_code,
4487 	               p_to_url_attribute_appl_id =>
4488 	                           l_item_tbl(l_index).to_url_attribute_appl_id,
4489 	               p_to_url_attribute_code =>
4490 	                           l_item_tbl(l_index).to_url_attribute_code,
4491 	               p_attribute_category => l_item_tbl(l_index).attribute_category,
4492 				   p_attribute1 => l_item_tbl(l_index).attribute1,
4493 				   p_attribute2 => l_item_tbl(l_index).attribute2,
4494 				   p_attribute3 => l_item_tbl(l_index).attribute3,
4495 				   p_attribute4 => l_item_tbl(l_index).attribute4,
4496 				   p_attribute5 => l_item_tbl(l_index).attribute5,
4497 				   p_attribute6 => l_item_tbl(l_index).attribute6,
4498 				   p_attribute7 => l_item_tbl(l_index).attribute7,
4499 				   p_attribute8 => l_item_tbl(l_index).attribute8,
4500 				   p_attribute9 => l_item_tbl(l_index).attribute9,
4501 				   p_attribute10 => l_item_tbl(l_index).attribute10,
4502 				   p_attribute11 => l_item_tbl(l_index).attribute11,
4503 				   p_attribute12 => l_item_tbl(l_index).attribute12,
4504 				   p_attribute13 => l_item_tbl(l_index).attribute13,
4505 				   p_attribute14 => l_item_tbl(l_index).attribute14,
4506 				   p_attribute15 => l_item_tbl(l_index).attribute15,
4507         p_created_by  => l_item_tbl(l_index).created_by,
4508         p_creation_date  => l_item_tbl(l_index).creation_date,
4509         p_last_updated_by  => l_item_tbl(l_index).last_updated_by,
4510         p_last_update_date  => l_item_tbl(l_index).last_update_date,
4511         p_last_update_login  => l_item_tbl(l_index).last_update_login,
4512 	               p_loader_timestamp => p_loader_timestamp,
4513 	               p_pass => p_pass,
4514 	               p_copy_redo_flag => l_copy_redo_flag
4515 	             );
4516 			end if; -- /* if l_user_id1 = 1 */
4517 		  end if; -- /* if G_UPDATE_MODE G_NO_CUSTOM_UPDATE */
4518         else
4519           AK_FLOW_PVT.CREATE_PAGE_REGION_ITEM (
4520             p_validation_level => p_validation_level,
4521             p_api_version_number => 1.0,
4522             p_msg_count => l_msg_count,
4523             p_msg_data => l_msg_data,
4524             p_return_status => l_return_status,
4525             p_flow_application_id =>
4526                         l_item_tbl(l_index).flow_application_id,
4527             p_flow_code => l_item_tbl(l_index).flow_code,
4528             p_page_application_id =>
4529                         l_item_tbl(l_index).page_application_id,
4530             p_page_code => l_item_tbl(l_index).page_code,
4531             p_region_application_id =>
4532                         l_item_tbl(l_index).region_application_id,
4533             p_region_code => l_item_tbl(l_index).region_code,
4534             p_attribute_application_id =>
4535                         l_item_tbl(l_index).attribute_application_id,
4536             p_attribute_code => l_item_tbl(l_index).attribute_code,
4537             p_to_page_appl_id => l_item_tbl(l_index).to_page_appl_id,
4538             p_to_page_code => l_item_tbl(l_index).to_page_code,
4539             p_to_url_attribute_appl_id =>
4540                         l_item_tbl(l_index).to_url_attribute_appl_id,
4541             p_to_url_attribute_code =>
4542                         l_item_tbl(l_index).to_url_attribute_code,
4543             p_attribute_category => l_item_tbl(l_index).attribute_category,
4544 			p_attribute1 => l_item_tbl(l_index).attribute1,
4545 			p_attribute2 => l_item_tbl(l_index).attribute2,
4546 			p_attribute3 => l_item_tbl(l_index).attribute3,
4547 			p_attribute4 => l_item_tbl(l_index).attribute4,
4548 			p_attribute5 => l_item_tbl(l_index).attribute5,
4549 			p_attribute6 => l_item_tbl(l_index).attribute6,
4550 			p_attribute7 => l_item_tbl(l_index).attribute7,
4551 			p_attribute8 => l_item_tbl(l_index).attribute8,
4552 			p_attribute9 => l_item_tbl(l_index).attribute9,
4553 			p_attribute10 => l_item_tbl(l_index).attribute10,
4554 			p_attribute11 => l_item_tbl(l_index).attribute11,
4555 			p_attribute12 => l_item_tbl(l_index).attribute12,
4556 			p_attribute13 => l_item_tbl(l_index).attribute13,
4557 			p_attribute14 => l_item_tbl(l_index).attribute14,
4558 			p_attribute15 => l_item_tbl(l_index).attribute15,
4559         p_created_by => l_item_tbl(l_index).created_by,
4560         p_creation_date => l_item_tbl(l_index).creation_date,
4561         p_last_updated_by => l_item_tbl(l_index).last_updated_by,
4562         p_last_update_date => l_item_tbl(l_index).last_update_date,
4563         p_last_update_login => l_item_tbl(l_index).last_update_login,
4567           );
4564             p_loader_timestamp => p_loader_timestamp,
4565   		    p_pass => p_pass,
4566             p_copy_redo_flag => l_copy_redo_flag
4568         end if; -- /* if PAGE_REGION_ITEM_EXISTS */
4569 		--
4570         -- If API call returns with an error status, upload aborts
4571         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
4572         (l_return_status = FND_API.G_RET_STS_ERROR) then
4573           RAISE FND_API.G_EXC_ERROR;
4574         end if; -- /* if l_return_status */
4575       end if;
4576     end loop;
4577   end if;
4578 
4579   --
4580   -- Load line number of the last file line processed
4581   --
4582   p_line_num_out := l_line_num;
4583 
4584   p_return_status := FND_API.G_RET_STS_SUCCESS;
4585 
4586   -- dbms_output.put_line('Leaving flow upload:'  ||
4587   --                            to_char(sysdate, 'MON-DD HH24:MI:SS'));
4588 
4589 EXCEPTION
4590   WHEN FND_API.G_EXC_ERROR THEN
4591     p_return_status := FND_API.G_RET_STS_ERROR;
4592   WHEN VALUE_ERROR THEN
4593     p_return_status := FND_API.G_RET_STS_ERROR;
4594     FND_MESSAGE.SET_NAME('AK','AK_FLOW_VALUE_ERROR');
4595     FND_MESSAGE.SET_TOKEN('KEY',to_char(l_flow_rec.flow_application_id)||' '||
4596     						l_flow_rec.flow_code);
4597     FND_MSG_PUB.Add;
4598 	FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
4599                            SUBSTR (SQLERRM, 1, 240)||': '||l_column||'='||l_token );
4600 	FND_MSG_PUB.Add;
4601   WHEN OTHERS THEN
4602     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4603     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
4604                            SUBSTR (SQLERRM, 1, 240) );
4605     FND_MSG_PUB.Add;
4606 end UPLOAD_FLOW;
4607 
4608 --=======================================================
4609 --  Procedure   UPLOAD_FLOW_SECOND
4610 --
4611 --  Usage       Private API for loading flows that were
4612 --              failed during its first pass
4613 --              This API should only be called by other APIs
4614 --              that are owned by the Core Modules Team (AK).
4615 --
4616 --  Desc        This API reads the flow data from PL/SQL table
4617 --              that was prepared during 1st pass, then processes
4618 --              the data, and loads them to the database. The tables
4619 --              are updated with the timestamp passed. This API
4620 --              will process the file until the EOF is reached,
4621 --              a parse error is encountered, or when data for
4622 --              a different business object is read from the file.
4623 --
4624 --  Results     The API returns the standard p_return_status parameter
4625 --              indicating one of the standard return statuses :
4626 --                  * Unexpected error
4627 --                  * Error
4628 --                  * Success
4629 --  Parameters  p_validation_level : IN required
4630 --                  validation level
4631 --
4632 --  Version     Initial version number  =   1.0
4633 --  History     Current version number  =   1.0
4634 --=======================================================
4635 procedure UPLOAD_FLOW_SECOND (
4636   p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
4637   p_return_status            OUT NOCOPY     VARCHAR2,
4638   p_loader_timestamp         IN      DATE := FND_API.G_MISS_DATE,
4639   p_pass                     IN      NUMBER := 2
4640 ) is
4641   l_api_name                 CONSTANT varchar2(30) := 'Upload_Object_Second';
4642   l_rec_index                NUMBER;
4643   l_return_status            VARCHAR2(1);
4644   l_msg_count                NUMBER;
4645   l_msg_data                 VARCHAR2(240);
4646   l_copy_redo_flag           BOOLEAN := FALSE;
4647 begin
4648   -- Create new flows to the database
4649   --
4650   -- - Create flows that are not already in the database. Since it is
4651   --   very likely that there are no pages for these new flows,
4652   --   these flows will be created without specifying their primary pages.
4653   --   Later in this procedure, they will be updated with the appropriate
4654   --   primary pages once all the flow pages are loaded.
4655   --
4656   --   Existing flows will also be updated with new data at that time.
4657   --
4658   if (G_FLOW_REDO_INDEX > 0) then
4659 
4660   -- dbms_output.put_line('number of redo flows: '||to_char(G_FLOW_REDO_INDEX));
4661 
4662     for l_index in G_FLOW_REDO_TBL.FIRST .. G_FLOW_REDO_TBL.LAST loop
4663       if (G_FLOW_REDO_TBL.exists(l_index)) then
4664         if NOT AK_FLOW_PVT.FLOW_EXISTS (
4665             p_api_version_number => 1.0,
4666             p_return_status => l_return_status,
4667             p_flow_application_id =>
4668                         G_FLOW_REDO_TBL(l_index).flow_application_id,
4669             p_flow_code => G_FLOW_REDO_TBL(l_index).flow_code) then
4670           AK_FLOW_PVT.CREATE_FLOW (
4671             p_validation_level => p_validation_level,
4672             p_api_version_number => 1.0,
4673             p_msg_count => l_msg_count,
4674             p_msg_data => l_msg_data,
4675             p_return_status => l_return_status,
4676             p_flow_application_id =>
4677                         G_FLOW_REDO_TBL(l_index).flow_application_id,
4678             p_flow_code => G_FLOW_REDO_TBL(l_index).flow_code,
4679             p_name => G_FLOW_REDO_TBL(l_index).name,
4680             p_description => G_FLOW_REDO_TBL(l_index).description,
4681         p_created_by => G_FLOW_REDO_TBL(l_index).created_by,
4685         p_last_update_login => G_FLOW_REDO_TBL(l_index).last_update_login,
4682         p_creation_date => G_FLOW_REDO_TBL(l_index).creation_date,
4683         p_last_updated_by => G_FLOW_REDO_TBL(l_index).last_updated_by,
4684         p_last_update_date => G_FLOW_REDO_TBL(l_index).last_update_date,
4686             p_loader_timestamp => p_loader_timestamp,
4687   		    p_pass => p_pass,
4688             p_copy_redo_flag => l_copy_redo_flag
4689           );
4690 
4691             -- If API call returns with an error status...
4692             if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
4693             (l_return_status = FND_API.G_RET_STS_ERROR) then
4694               RAISE FND_API.G_EXC_ERROR;
4695             end if;
4696         end if; -- /* if AK_FLOW_PVT.FLOW_EXISTS */
4697       end if;
4698     end loop;
4699   end if;
4700 
4701   -- Create new flow pages to the database
4702   --
4703   -- - Create flow pages that are not already in the database. Since it is
4704   --   very likely that there are no page regions for these new flows,
4705   --   these flow pages will be created without specifying any  primary
4706   --   page regions.
4707   --   Later in this procedure, they will be updated with the appropriate
4708   --   primary regions once all the flow page regions are loaded.
4709   --
4710   --   Existing flow pages will also be updated with new data at that time.
4711   --
4712   if (G_PAGE_REDO_INDEX > 0) then
4713   -- dbms_output.put_line('number of redo pages: '||to_char(G_PAGE_REDO_INDEX));
4714     for l_index in G_PAGE_REDO_TBL.FIRST .. G_PAGE_REDO_TBL.LAST loop
4715       if (G_PAGE_REDO_TBL.exists(l_index)) then
4716         if NOT AK_FLOW_PVT.PAGE_EXISTS (
4717             p_api_version_number => 1.0,
4718             p_return_status => l_return_status,
4719             p_flow_application_id =>
4720                         G_PAGE_REDO_TBL(l_index).flow_application_id,
4721             p_flow_code => G_PAGE_REDO_TBL(l_index).flow_code,
4722             p_page_application_id =>
4723                         G_PAGE_REDO_TBL(l_index).page_application_id,
4724             p_page_code => G_PAGE_REDO_TBL(l_index).page_code) then
4725           AK_FLOW_PVT.CREATE_PAGE (
4726             p_validation_level => p_validation_level,
4727             p_api_version_number => 1.0,
4728             p_msg_count => l_msg_count,
4729             p_msg_data => l_msg_data,
4730             p_return_status => l_return_status,
4731             p_flow_application_id =>
4732                         G_PAGE_REDO_TBL(l_index).flow_application_id,
4733             p_flow_code => G_PAGE_REDO_TBL(l_index).flow_code,
4734             p_page_application_id =>
4735                         G_PAGE_REDO_TBL(l_index).page_application_id,
4736             p_page_code => G_PAGE_REDO_TBL(l_index).page_code,
4737             p_attribute_category => G_PAGE_REDO_TBL(l_index).attribute_category,
4738 			p_attribute1 => G_PAGE_REDO_TBL(l_index).attribute1,
4739 			p_attribute2 => G_PAGE_REDO_TBL(l_index).attribute2,
4740 			p_attribute3 => G_PAGE_REDO_TBL(l_index).attribute3,
4741 			p_attribute4 => G_PAGE_REDO_TBL(l_index).attribute4,
4742 			p_attribute5 => G_PAGE_REDO_TBL(l_index).attribute5,
4743 			p_attribute6 => G_PAGE_REDO_TBL(l_index).attribute6,
4744 			p_attribute7 => G_PAGE_REDO_TBL(l_index).attribute7,
4745 			p_attribute8 => G_PAGE_REDO_TBL(l_index).attribute8,
4746 			p_attribute9 => G_PAGE_REDO_TBL(l_index).attribute9,
4747 			p_attribute10 => G_PAGE_REDO_TBL(l_index).attribute10,
4748 			p_attribute11 => G_PAGE_REDO_TBL(l_index).attribute11,
4749 			p_attribute12 => G_PAGE_REDO_TBL(l_index).attribute12,
4750 			p_attribute13 => G_PAGE_REDO_TBL(l_index).attribute13,
4751 			p_attribute14 => G_PAGE_REDO_TBL(l_index).attribute14,
4752 			p_attribute15 => G_PAGE_REDO_TBL(l_index).attribute15,
4753             p_name => G_PAGE_REDO_TBL(l_index).name,
4754             p_description => G_PAGE_REDO_TBL(l_index).description,
4755         p_created_by => G_PAGE_REDO_TBL(l_index).created_by,
4756         p_creation_date => G_PAGE_REDO_TBL(l_index).creation_date,
4757         p_last_updated_by => G_PAGE_REDO_TBL(l_index).last_updated_by,
4758         p_last_update_date => G_PAGE_REDO_TBL(l_index).last_update_date,
4759         p_last_update_login => G_PAGE_REDO_TBL(l_index).last_update_login,
4760             p_loader_timestamp => p_loader_timestamp,
4761   		    p_pass => p_pass,
4762             p_copy_redo_flag => l_copy_redo_flag
4763           );
4764 
4765             -- If API call returns with an error status..., abort upload
4766             if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
4767             (l_return_status = FND_API.G_RET_STS_ERROR) then
4768               RAISE FND_API.G_EXC_ERROR;
4769             end if;
4770         end if; -- /* if PAGE_EXISTS */
4771       end if;
4772     end loop;
4773   end if;
4774 
4775   -- Update primary page columns for new flows, and update all columns
4776   -- for existing flows.
4777   --
4778   --   Now that all flow pages have been loaded into the database,
4779   --   we can load the primary page columns for all new flows that
4780   --   has a primary page. Existing flows are also updated with new
4781   --   data in the loader file at this time.
4782   --
4783   if (G_FLOW_REDO_TBL.count > 0) then
4784     for l_index in G_FLOW_REDO_TBL.FIRST .. G_FLOW_REDO_TBL.LAST loop
4785       if (G_FLOW_REDO_TBL.exists(l_index)) then
4786          AK_FLOW_PVT.UPDATE_FLOW (
4787             p_validation_level => p_validation_level,
4788             p_api_version_number => 1.0,
4789             p_msg_count => l_msg_count,
4793                         G_FLOW_REDO_TBL(l_index).flow_application_id,
4790             p_msg_data => l_msg_data,
4791             p_return_status => l_return_status,
4792             p_flow_application_id =>
4794             p_flow_code => G_FLOW_REDO_TBL(l_index).flow_code,
4795             p_name => G_FLOW_REDO_TBL(l_index).name,
4796             p_description => G_FLOW_REDO_TBL(l_index).description,
4797             p_primary_page_appl_id => G_FLOW_REDO_TBL(l_index).primary_page_appl_id,
4798             p_primary_page_code => G_FLOW_REDO_TBL(l_index).primary_page_code,
4799             p_attribute_category => G_FLOW_REDO_TBL(l_index).attribute_category,
4800 			p_attribute1 => G_FLOW_REDO_TBL(l_index).attribute1,
4801 			p_attribute2 => G_FLOW_REDO_TBL(l_index).attribute2,
4802 			p_attribute3 => G_FLOW_REDO_TBL(l_index).attribute3,
4803 			p_attribute4 => G_FLOW_REDO_TBL(l_index).attribute4,
4804 			p_attribute5 => G_FLOW_REDO_TBL(l_index).attribute5,
4805 			p_attribute6 => G_FLOW_REDO_TBL(l_index).attribute6,
4806 			p_attribute7 => G_FLOW_REDO_TBL(l_index).attribute7,
4807 			p_attribute8 => G_FLOW_REDO_TBL(l_index).attribute8,
4808 			p_attribute9 => G_FLOW_REDO_TBL(l_index).attribute9,
4809 			p_attribute10 => G_FLOW_REDO_TBL(l_index).attribute10,
4810 			p_attribute11 => G_FLOW_REDO_TBL(l_index).attribute11,
4811 			p_attribute12 => G_FLOW_REDO_TBL(l_index).attribute12,
4812 			p_attribute13 => G_FLOW_REDO_TBL(l_index).attribute13,
4813 			p_attribute14 => G_FLOW_REDO_TBL(l_index).attribute14,
4814 			p_attribute15 => G_FLOW_REDO_TBL(l_index).attribute15,
4815         p_created_by  => G_FLOW_REDO_TBL(l_index).created_by,
4816         p_creation_date  => G_FLOW_REDO_TBL(l_index).creation_date,
4817         p_last_updated_by  => G_FLOW_REDO_TBL(l_index).last_updated_by,
4818         p_last_update_date  => G_FLOW_REDO_TBL(l_index).last_update_date,
4819         p_last_update_login  => G_FLOW_REDO_TBL(l_index).last_update_login,
4820             p_loader_timestamp => p_loader_timestamp,
4821   		    p_pass => p_pass,
4822             p_copy_redo_flag => l_copy_redo_flag
4823           );
4824       end if;
4825     end loop;
4826   end if;
4827 
4828   -- Insert or update all page regions to the database
4829   --
4830   --   Since not all page regions exists in the database, we are
4831   --   creating new page regions with parent regions set to null.
4832   --   Update to certain page regions with a parent region will
4833   --   fail due to the same reason.
4834   --   Later in this procedure, they will be updated with the appropriate
4835   --   parent regions once all the page regions are loaded.
4836   --
4837   if (G_PAGE_REGION_REDO_INDEX > 0) then
4838   -- dbms_output.put_line('number of redo page regions: '||to_char(G_PAGE_REGION_REDO_INDEX));
4839     for l_index in G_PAGE_REGION_REDO_TBL.FIRST .. G_PAGE_REGION_REDO_TBL.LAST loop
4840       if (G_PAGE_REGION_REDO_TBL.exists(l_index)) then
4841         if AK_FLOW_PVT.PAGE_REGION_EXISTS (
4842             p_api_version_number => 1.0,
4843             p_return_status => l_return_status,
4844             p_flow_application_id =>
4845                         G_PAGE_REGION_REDO_TBL(l_index).flow_application_id,
4846             p_flow_code => G_PAGE_REGION_REDO_TBL(l_index).flow_code,
4847             p_page_application_id =>
4848                         G_PAGE_REGION_REDO_TBL(l_index).page_application_id,
4849             p_page_code => G_PAGE_REGION_REDO_TBL(l_index).page_code,
4850             p_region_application_id =>
4851                         G_PAGE_REGION_REDO_TBL(l_index).region_application_id,
4852             p_region_code => G_PAGE_REGION_REDO_TBL(l_index).region_code) then
4853           AK_FLOW_PVT.UPDATE_PAGE_REGION (
4854             p_validation_level => p_validation_level,
4855             p_api_version_number => 1.0,
4856             p_msg_count => l_msg_count,
4857             p_msg_data => l_msg_data,
4858             p_return_status => l_return_status,
4859             p_flow_application_id =>
4860                         G_PAGE_REGION_REDO_TBL(l_index).flow_application_id,
4861             p_flow_code => G_PAGE_REGION_REDO_TBL(l_index).flow_code,
4862             p_page_application_id =>
4863                         G_PAGE_REGION_REDO_TBL(l_index).page_application_id,
4864             p_page_code => G_PAGE_REGION_REDO_TBL(l_index).page_code,
4865             p_region_application_id =>
4866                         G_PAGE_REGION_REDO_TBL(l_index).region_application_id,
4867             p_region_code => G_PAGE_REGION_REDO_TBL(l_index).region_code,
4868             p_display_sequence => G_PAGE_REGION_REDO_TBL(l_index).display_sequence,
4869             p_region_style => G_PAGE_REGION_REDO_TBL(l_index).region_style,
4870             p_num_columns => G_PAGE_REGION_REDO_TBL(l_index).num_columns,
4871             p_icx_custom_call => G_PAGE_REGION_REDO_TBL(l_index).icx_custom_call,
4872             p_parent_region_application_id =>
4873                         G_PAGE_REGION_REDO_TBL(l_index).parent_region_appl_id,
4874             p_parent_region_code => G_PAGE_REGION_REDO_TBL(l_index).parent_region_code,
4875             p_foreign_key_name => G_PAGE_REGION_REDO_TBL(l_index).foreign_key_name,
4876             p_attribute_category => G_PAGE_REGION_REDO_TBL(l_index).attribute_category,
4877 			p_attribute1 => G_PAGE_REGION_REDO_TBL(l_index).attribute1,
4878 			p_attribute2 => G_PAGE_REGION_REDO_TBL(l_index).attribute2,
4879 			p_attribute3 => G_PAGE_REGION_REDO_TBL(l_index).attribute3,
4880 			p_attribute4 => G_PAGE_REGION_REDO_TBL(l_index).attribute4,
4881 			p_attribute5 => G_PAGE_REGION_REDO_TBL(l_index).attribute5,
4882 			p_attribute6 => G_PAGE_REGION_REDO_TBL(l_index).attribute6,
4883 			p_attribute7 => G_PAGE_REGION_REDO_TBL(l_index).attribute7,
4887 			p_attribute11 => G_PAGE_REGION_REDO_TBL(l_index).attribute11,
4884 			p_attribute8 => G_PAGE_REGION_REDO_TBL(l_index).attribute8,
4885 			p_attribute9 => G_PAGE_REGION_REDO_TBL(l_index).attribute9,
4886 			p_attribute10 => G_PAGE_REGION_REDO_TBL(l_index).attribute10,
4888 			p_attribute12 => G_PAGE_REGION_REDO_TBL(l_index).attribute12,
4889 			p_attribute13 => G_PAGE_REGION_REDO_TBL(l_index).attribute13,
4890 			p_attribute14 => G_PAGE_REGION_REDO_TBL(l_index).attribute14,
4891 			p_attribute15 => G_PAGE_REGION_REDO_TBL(l_index).attribute15,
4892                 p_created_by => G_PAGE_REGION_REDO_TBL(l_index).created_by,
4893                 p_creation_date => G_PAGE_REGION_REDO_TBL(l_index).creation_date,
4894                 p_last_updated_by => G_PAGE_REGION_REDO_TBL(l_index).last_updated_by,
4895                 p_last_update_date => G_PAGE_REGION_REDO_TBL(l_index).last_update_date,
4896                 p_last_update_login => G_PAGE_REGION_REDO_TBL(l_index).last_update_login,
4897             p_loader_timestamp => p_loader_timestamp,
4898   		    p_pass => p_pass,
4899             p_copy_redo_flag => l_copy_redo_flag
4900           );
4901         else
4902           AK_FLOW_PVT.CREATE_PAGE_REGION (
4903             p_validation_level => p_validation_level,
4904             p_api_version_number => 1.0,
4905             p_msg_count => l_msg_count,
4906             p_msg_data => l_msg_data,
4907             p_return_status => l_return_status,
4908             p_flow_application_id =>
4909                         G_PAGE_REGION_REDO_TBL(l_index).flow_application_id,
4910             p_flow_code => G_PAGE_REGION_REDO_TBL(l_index).flow_code,
4911             p_page_application_id =>
4912                         G_PAGE_REGION_REDO_TBL(l_index).page_application_id,
4913             p_page_code => G_PAGE_REGION_REDO_TBL(l_index).page_code,
4914             p_region_application_id =>
4915                         G_PAGE_REGION_REDO_TBL(l_index).region_application_id,
4916             p_region_code => G_PAGE_REGION_REDO_TBL(l_index).region_code,
4917             p_display_sequence => G_PAGE_REGION_REDO_TBL(l_index).display_sequence,
4918             p_region_style => G_PAGE_REGION_REDO_TBL(l_index).region_style,
4919             p_num_columns => G_PAGE_REGION_REDO_TBL(l_index).num_columns,
4920             p_icx_custom_call => G_PAGE_REGION_REDO_TBL(l_index).icx_custom_call,
4921             p_parent_region_application_id => null,
4922             p_parent_region_code => null,
4923             p_foreign_key_name => null,
4924             p_attribute_category => G_PAGE_REGION_REDO_TBL(l_index).attribute_category,
4925 			p_attribute1 => G_PAGE_REGION_REDO_TBL(l_index).attribute1,
4926 			p_attribute2 => G_PAGE_REGION_REDO_TBL(l_index).attribute2,
4927 			p_attribute3 => G_PAGE_REGION_REDO_TBL(l_index).attribute3,
4928 			p_attribute4 => G_PAGE_REGION_REDO_TBL(l_index).attribute4,
4929 			p_attribute5 => G_PAGE_REGION_REDO_TBL(l_index).attribute5,
4930 			p_attribute6 => G_PAGE_REGION_REDO_TBL(l_index).attribute6,
4931 			p_attribute7 => G_PAGE_REGION_REDO_TBL(l_index).attribute7,
4932 			p_attribute8 => G_PAGE_REGION_REDO_TBL(l_index).attribute8,
4933 			p_attribute9 => G_PAGE_REGION_REDO_TBL(l_index).attribute9,
4934 			p_attribute10 => G_PAGE_REGION_REDO_TBL(l_index).attribute10,
4935 			p_attribute11 => G_PAGE_REGION_REDO_TBL(l_index).attribute11,
4936 			p_attribute12 => G_PAGE_REGION_REDO_TBL(l_index).attribute12,
4937 			p_attribute13 => G_PAGE_REGION_REDO_TBL(l_index).attribute13,
4938 			p_attribute14 => G_PAGE_REGION_REDO_TBL(l_index).attribute14,
4939 			p_attribute15 => G_PAGE_REGION_REDO_TBL(l_index).attribute15,
4940         p_created_by => G_PAGE_REGION_REDO_TBL(l_index).created_by,
4941         p_creation_date => G_PAGE_REGION_REDO_TBL(l_index).creation_date,
4942         p_last_updated_by => G_PAGE_REGION_REDO_TBL(l_index).last_updated_by,
4943         p_last_update_date => G_PAGE_REGION_REDO_TBL(l_index).last_update_date,
4944         p_last_update_login => G_PAGE_REGION_REDO_TBL(l_index).last_update_login,
4945             p_loader_timestamp => p_loader_timestamp,
4946   		    p_pass => p_pass,
4947             p_copy_redo_flag => l_copy_redo_flag
4948           );
4949         end if;	-- /* if PAGE_REGION_EXISTS */
4950 		--
4951         -- If API call returns with an error status, upload aborts
4952         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
4953         (l_return_status = FND_API.G_RET_STS_ERROR) then
4954           RAISE FND_API.G_EXC_ERROR;
4955         end if; -- /* if l_return_status */
4956       end if; -- /* if G_PAGE_REGION_REDO_TBL.exists */
4957     end loop;
4958   end if;
4959 
4960   -- Update parent region columns for page regions
4961   --
4962   --   Now that all page regions have been loaded into the database,
4963   --   we can load the parent region columns for all page regions that
4964   --   has a parent region.
4965   --
4966   --   Intrapage region relations are created in UPDATE_PAGE_REGION when
4967   --   a parent region is specified.
4968   --
4969   if (G_PAGE_REGION_REDO_INDEX > 0) then
4970     for l_index in G_PAGE_REGION_REDO_TBL.FIRST .. G_PAGE_REGION_REDO_TBL.LAST loop
4971       if (G_PAGE_REGION_REDO_TBL.exists(l_index)) then
4972         if ( (G_PAGE_REGION_REDO_TBL(l_index).parent_region_appl_id is not null) or
4973              (G_PAGE_REGION_REDO_TBL(l_index).parent_region_code is not null) ) then
4974          AK_FLOW_PVT.UPDATE_PAGE_REGION (
4975             p_validation_level => p_validation_level,
4976             p_api_version_number => 1.0,
4977             p_msg_count => l_msg_count,
4978             p_msg_data => l_msg_data,
4979             p_return_status => l_return_status,
4980             p_flow_application_id =>
4984                         G_PAGE_REGION_REDO_TBL(l_index).page_application_id,
4981                         G_PAGE_REGION_REDO_TBL(l_index).flow_application_id,
4982             p_flow_code => G_PAGE_REGION_REDO_TBL(l_index).flow_code,
4983             p_page_application_id =>
4985             p_page_code => G_PAGE_REGION_REDO_TBL(l_index).page_code,
4986             p_region_application_id =>
4987                         G_PAGE_REGION_REDO_TBL(l_index).region_application_id,
4988             p_region_code => G_PAGE_REGION_REDO_TBL(l_index).region_code,
4989             p_parent_region_application_id =>
4990                         G_PAGE_REGION_REDO_TBL(l_index).parent_region_appl_id,
4991             p_parent_region_code => G_PAGE_REGION_REDO_TBL(l_index).parent_region_code,
4992             p_attribute_category => G_PAGE_REGION_REDO_TBL(l_index).attribute_category,
4993 			p_attribute1 => G_PAGE_REGION_REDO_TBL(l_index).attribute1,
4994 			p_attribute2 => G_PAGE_REGION_REDO_TBL(l_index).attribute2,
4995 			p_attribute3 => G_PAGE_REGION_REDO_TBL(l_index).attribute3,
4996 			p_attribute4 => G_PAGE_REGION_REDO_TBL(l_index).attribute4,
4997 			p_attribute5 => G_PAGE_REGION_REDO_TBL(l_index).attribute5,
4998 			p_attribute6 => G_PAGE_REGION_REDO_TBL(l_index).attribute6,
4999 			p_attribute7 => G_PAGE_REGION_REDO_TBL(l_index).attribute7,
5000 			p_attribute8 => G_PAGE_REGION_REDO_TBL(l_index).attribute8,
5001 			p_attribute9 => G_PAGE_REGION_REDO_TBL(l_index).attribute9,
5002 			p_attribute10 => G_PAGE_REGION_REDO_TBL(l_index).attribute10,
5003 			p_attribute11 => G_PAGE_REGION_REDO_TBL(l_index).attribute11,
5004 			p_attribute12 => G_PAGE_REGION_REDO_TBL(l_index).attribute12,
5005 			p_attribute13 => G_PAGE_REGION_REDO_TBL(l_index).attribute13,
5006 			p_attribute14 => G_PAGE_REGION_REDO_TBL(l_index).attribute14,
5007 			p_attribute15 => G_PAGE_REGION_REDO_TBL(l_index).attribute15,
5008             p_foreign_key_name => G_PAGE_REGION_REDO_TBL(l_index).foreign_key_name,
5009                 p_created_by => G_PAGE_REGION_REDO_TBL(l_index).created_by,
5010                 p_creation_date => G_PAGE_REGION_REDO_TBL(l_index).creation_date,
5011                 p_last_updated_by => G_PAGE_REGION_REDO_TBL(l_index).last_updated_by,
5012                 p_last_update_date => G_PAGE_REGION_REDO_TBL(l_index).last_update_date,
5013                 p_last_update_login => G_PAGE_REGION_REDO_TBL(l_index).last_update_login,
5014             p_loader_timestamp => p_loader_timestamp,
5015   		    p_pass => p_pass,
5016             p_copy_redo_flag => l_copy_redo_flag
5017           );
5018         end if;
5019       end if;
5020     end loop;
5021   end if;
5022 
5023   -- Update primary region columns for new flow pages, and update all columns
5024   -- for existing flow pages.
5025   --
5026   --   Now that all flow page regions have been loaded into the database,
5027   --   we can load the primary region columns for all new flow pages that
5028   --   has a primary region. Existing flow pages are also updated with new
5029   --   data in the loader file at this time.
5030   --
5031   if (G_PAGE_REDO_TBL.count > 0) then
5032     for l_index in G_PAGE_REDO_TBL.FIRST .. G_PAGE_REDO_TBL.LAST loop
5033       if (G_PAGE_REDO_TBL.exists(l_index)) then
5034          AK_FLOW_PVT.UPDATE_PAGE (
5035             p_validation_level => p_validation_level,
5036             p_api_version_number => 1.0,
5037             p_msg_count => l_msg_count,
5038             p_msg_data => l_msg_data,
5039             p_return_status => l_return_status,
5040             p_flow_application_id =>
5041                         G_PAGE_REDO_TBL(l_index).flow_application_id,
5042             p_flow_code => G_PAGE_REDO_TBL(l_index).flow_code,
5043             p_page_application_id =>
5044                         G_PAGE_REDO_TBL(l_index).page_application_id,
5045             p_page_code => G_PAGE_REDO_TBL(l_index).page_code,
5046             p_name => G_PAGE_REDO_TBL(l_index).name,
5047             p_description => G_PAGE_REDO_TBL(l_index).description,
5048             p_primary_region_appl_id =>
5049                         G_PAGE_REDO_TBL(l_index).primary_region_appl_id,
5050             p_primary_region_code => G_PAGE_REDO_TBL(l_index).primary_region_code,
5051             p_attribute_category => G_PAGE_REDO_TBL(l_index).attribute_category,
5052 			p_attribute1 => G_PAGE_REDO_TBL(l_index).attribute1,
5053 			p_attribute2 => G_PAGE_REDO_TBL(l_index).attribute2,
5054 			p_attribute3 => G_PAGE_REDO_TBL(l_index).attribute3,
5055 			p_attribute4 => G_PAGE_REDO_TBL(l_index).attribute4,
5056 			p_attribute5 => G_PAGE_REDO_TBL(l_index).attribute5,
5057 			p_attribute6 => G_PAGE_REDO_TBL(l_index).attribute6,
5058 			p_attribute7 => G_PAGE_REDO_TBL(l_index).attribute7,
5059 			p_attribute8 => G_PAGE_REDO_TBL(l_index).attribute8,
5060 			p_attribute9 => G_PAGE_REDO_TBL(l_index).attribute9,
5061 			p_attribute10 => G_PAGE_REDO_TBL(l_index).attribute10,
5062 			p_attribute11 => G_PAGE_REDO_TBL(l_index).attribute11,
5063 			p_attribute12 => G_PAGE_REDO_TBL(l_index).attribute12,
5064 			p_attribute13 => G_PAGE_REDO_TBL(l_index).attribute13,
5065 			p_attribute14 => G_PAGE_REDO_TBL(l_index).attribute14,
5066 			p_attribute15 => G_PAGE_REDO_TBL(l_index).attribute15,
5067                 p_created_by => G_PAGE_REDO_TBL(l_index).created_by,
5068                 p_creation_date => G_PAGE_REDO_TBL(l_index).creation_date,
5069                 p_last_updated_by => G_PAGE_REDO_TBL(l_index).last_updated_by,
5070                 p_last_update_date => G_PAGE_REDO_TBL(l_index).last_update_date,
5071                 p_last_update_login => G_PAGE_REDO_TBL(l_index).last_update_login,
5072             p_loader_timestamp => p_loader_timestamp,
5073   		    p_pass => p_pass,
5077     end loop;
5074             p_copy_redo_flag => l_copy_redo_flag
5075           );
5076       end if;
5078   end if;
5079 
5080   -- Insert or update all interpage region relations to the database
5081   --
5082   --   Create or update interpage region relations to the database.
5083   --   All intrapage region relations were created while loading
5084   --   flow page regions.
5085   --
5086   if (G_REGION_RELATION_REDO_INDEX > 0) then
5087     for l_index in G_REGION_RELATION_REDO_TBL.FIRST .. G_REGION_RELATION_REDO_TBL.LAST loop
5088       if (G_REGION_RELATION_REDO_TBL.exists(l_index)) then
5089         if AK_FLOW_PVT.REGION_RELATION_EXISTS (
5090             p_api_version_number => 1.0,
5091             p_return_status => l_return_status,
5092             p_flow_application_id =>
5093                         G_REGION_RELATION_REDO_TBL(l_index).flow_application_id,
5094             p_flow_code => G_REGION_RELATION_REDO_TBL(l_index).flow_code,
5095             p_foreign_key_name => G_REGION_RELATION_REDO_TBL(l_index).foreign_key_name,
5096             p_from_page_appl_id => G_REGION_RELATION_REDO_TBL(l_index).from_page_appl_id,
5097             p_from_page_code => G_REGION_RELATION_REDO_TBL(l_index).from_page_code,
5098             p_from_region_appl_id =>
5099                         G_REGION_RELATION_REDO_TBL(l_index).from_region_appl_id,
5100             p_from_region_code => G_REGION_RELATION_REDO_TBL(l_index).from_region_code,
5101             p_to_page_appl_id => G_REGION_RELATION_REDO_TBL(l_index).to_page_appl_id,
5102             p_to_page_code => G_REGION_RELATION_REDO_TBL(l_index).to_page_code,
5103             p_to_region_appl_id =>
5104                         G_REGION_RELATION_REDO_TBL(l_index).to_region_appl_id,
5105             p_to_region_code => G_REGION_RELATION_REDO_TBL(l_index).to_region_code) then
5106           AK_FLOW_PVT.UPDATE_REGION_RELATION (
5107             p_validation_level => p_validation_level,
5108             p_api_version_number => 1.0,
5109             p_msg_count => l_msg_count,
5110             p_msg_data => l_msg_data,
5111             p_return_status => l_return_status,
5112             p_flow_application_id =>
5113                         G_REGION_RELATION_REDO_TBL(l_index).flow_application_id,
5114             p_flow_code => G_REGION_RELATION_REDO_TBL(l_index).flow_code,
5115             p_foreign_key_name => G_REGION_RELATION_REDO_TBL(l_index).foreign_key_name,
5116             p_from_page_appl_id => G_REGION_RELATION_REDO_TBL(l_index).from_page_appl_id,
5117             p_from_page_code => G_REGION_RELATION_REDO_TBL(l_index).from_page_code,
5118             p_from_region_appl_id =>
5119                         G_REGION_RELATION_REDO_TBL(l_index).from_region_appl_id,
5120             p_from_region_code => G_REGION_RELATION_REDO_TBL(l_index).from_region_code,
5121             p_to_page_appl_id => G_REGION_RELATION_REDO_TBL(l_index).to_page_appl_id,
5122             p_to_page_code => G_REGION_RELATION_REDO_TBL(l_index).to_page_code,
5123             p_to_region_appl_id =>
5124                         G_REGION_RELATION_REDO_TBL(l_index).to_region_appl_id,
5125             p_to_region_code => G_REGION_RELATION_REDO_TBL(l_index).to_region_code,
5126             p_application_id => G_REGION_RELATION_REDO_TBL(l_index).application_id,
5127             p_attribute_category => G_REGION_RELATION_REDO_TBL(l_index).attribute_category,
5128 			p_attribute1 => G_REGION_RELATION_REDO_TBL(l_index).attribute1,
5129 			p_attribute2 => G_REGION_RELATION_REDO_TBL(l_index).attribute2,
5130 			p_attribute3 => G_REGION_RELATION_REDO_TBL(l_index).attribute3,
5131 			p_attribute4 => G_REGION_RELATION_REDO_TBL(l_index).attribute4,
5132 			p_attribute5 => G_REGION_RELATION_REDO_TBL(l_index).attribute5,
5133 			p_attribute6 => G_REGION_RELATION_REDO_TBL(l_index).attribute6,
5134 			p_attribute7 => G_REGION_RELATION_REDO_TBL(l_index).attribute7,
5135 			p_attribute8 => G_REGION_RELATION_REDO_TBL(l_index).attribute8,
5136 			p_attribute9 => G_REGION_RELATION_REDO_TBL(l_index).attribute9,
5137 			p_attribute10 => G_REGION_RELATION_REDO_TBL(l_index).attribute10,
5138 			p_attribute11 => G_REGION_RELATION_REDO_TBL(l_index).attribute11,
5139 			p_attribute12 => G_REGION_RELATION_REDO_TBL(l_index).attribute12,
5140 			p_attribute13 => G_REGION_RELATION_REDO_TBL(l_index).attribute13,
5141 			p_attribute14 => G_REGION_RELATION_REDO_TBL(l_index).attribute14,
5142 			p_attribute15 => G_REGION_RELATION_REDO_TBL(l_index).attribute15,
5143                 p_created_by => G_REGION_RELATION_REDO_TBL(l_index).created_by,
5144                 p_creation_date => G_REGION_RELATION_REDO_TBL(l_index).creation_date,
5145                 p_last_updated_by => G_REGION_RELATION_REDO_TBL(l_index).last_updated_by,
5146                 p_last_update_date => G_REGION_RELATION_REDO_TBL(l_index).last_update_date,
5147                 p_last_update_login => G_REGION_RELATION_REDO_TBL(l_index).last_update_login,
5148             p_loader_timestamp => p_loader_timestamp,
5149   		    p_pass => p_pass,
5150             p_copy_redo_flag => l_copy_redo_flag
5154             p_validation_level => p_validation_level,
5151           );
5152         else
5153           AK_FLOW_PVT.CREATE_REGION_RELATION (
5155             p_api_version_number => 1.0,
5156             p_msg_count => l_msg_count,
5157             p_msg_data => l_msg_data,
5158             p_return_status => l_return_status,
5159             p_flow_application_id =>
5160                         G_REGION_RELATION_REDO_TBL(l_index).flow_application_id,
5161             p_flow_code => G_REGION_RELATION_REDO_TBL(l_index).flow_code,
5162             p_foreign_key_name => G_REGION_RELATION_REDO_TBL(l_index).foreign_key_name,
5163             p_from_page_appl_id => G_REGION_RELATION_REDO_TBL(l_index).from_page_appl_id,
5164             p_from_page_code => G_REGION_RELATION_REDO_TBL(l_index).from_page_code,
5165             p_from_region_appl_id =>
5166                         G_REGION_RELATION_REDO_TBL(l_index).from_region_appl_id,
5167             p_from_region_code => G_REGION_RELATION_REDO_TBL(l_index).from_region_code,
5168             p_to_page_appl_id => G_REGION_RELATION_REDO_TBL(l_index).to_page_appl_id,
5169             p_to_page_code => G_REGION_RELATION_REDO_TBL(l_index).to_page_code,
5170             p_to_region_appl_id =>
5171                         G_REGION_RELATION_REDO_TBL(l_index).to_region_appl_id,
5172             p_to_region_code => G_REGION_RELATION_REDO_TBL(l_index).to_region_code,
5173             p_application_id => G_REGION_RELATION_REDO_TBL(l_index).application_id,
5174             p_attribute_category => G_REGION_RELATION_REDO_TBL(l_index).attribute_category,
5175 			p_attribute1 => G_REGION_RELATION_REDO_TBL(l_index).attribute1,
5176 			p_attribute2 => G_REGION_RELATION_REDO_TBL(l_index).attribute2,
5177 			p_attribute3 => G_REGION_RELATION_REDO_TBL(l_index).attribute3,
5178 			p_attribute4 => G_REGION_RELATION_REDO_TBL(l_index).attribute4,
5179 			p_attribute5 => G_REGION_RELATION_REDO_TBL(l_index).attribute5,
5180 			p_attribute6 => G_REGION_RELATION_REDO_TBL(l_index).attribute6,
5181 			p_attribute7 => G_REGION_RELATION_REDO_TBL(l_index).attribute7,
5182 			p_attribute8 => G_REGION_RELATION_REDO_TBL(l_index).attribute8,
5183 			p_attribute9 => G_REGION_RELATION_REDO_TBL(l_index).attribute9,
5184 			p_attribute10 => G_REGION_RELATION_REDO_TBL(l_index).attribute10,
5185 			p_attribute11 => G_REGION_RELATION_REDO_TBL(l_index).attribute11,
5186 			p_attribute12 => G_REGION_RELATION_REDO_TBL(l_index).attribute12,
5187 			p_attribute13 => G_REGION_RELATION_REDO_TBL(l_index).attribute13,
5188 			p_attribute14 => G_REGION_RELATION_REDO_TBL(l_index).attribute14,
5189 			p_attribute15 => G_REGION_RELATION_REDO_TBL(l_index).attribute15,
5190         p_created_by => G_REGION_RELATION_REDO_TBL(l_index).created_by,
5191         p_creation_date => G_REGION_RELATION_REDO_TBL(l_index).creation_date,
5192         p_last_updated_by => G_REGION_RELATION_REDO_TBL(l_index).last_updated_by,
5193         p_last_update_date => G_REGION_RELATION_REDO_TBL(l_index).last_update_date,
5194         p_last_update_login => G_REGION_RELATION_REDO_TBL(l_index).last_update_login,
5195             p_loader_timestamp => p_loader_timestamp,
5196   		    p_pass => p_pass,
5197             p_copy_redo_flag => l_copy_redo_flag
5198           );
5199         end if; -- /* if REGION_RELATION_EXISTS */
5200 		--
5201         -- If API call returns with an error status, upload aborts
5202         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
5203         (l_return_status = FND_API.G_RET_STS_ERROR) then
5204           RAISE FND_API.G_EXC_ERROR;
5205         end if; -- /* if l_return_status */
5206       end if;
5207     end loop;
5208   end if;
5209 
5210   -- Insert or update all page region items to the database
5211   --
5212   --   Create or update page region items to the database. This step
5213   --   must be done after all region relations have been loaded, since
5214   --   page region items (or links) depends on region relations.
5215   --
5216   if (G_PAGE_REGION_ITEM_REDO_INDEX > 0) then
5217     for l_index in G_PAGE_REGION_ITEM_REDO_TBL.FIRST .. G_PAGE_REGION_ITEM_REDO_TBL.LAST loop
5218       if (G_PAGE_REGION_ITEM_REDO_TBL.exists(l_index)) then
5219         if AK_FLOW_PVT.PAGE_REGION_ITEM_EXISTS (
5220             p_api_version_number => 1.0,
5221             p_return_status => l_return_status,
5222             p_flow_application_id =>
5223                         G_PAGE_REGION_ITEM_REDO_TBL(l_index).flow_application_id,
5224             p_flow_code => G_PAGE_REGION_ITEM_REDO_TBL(l_index).flow_code,
5225             p_page_application_id =>
5226                         G_PAGE_REGION_ITEM_REDO_TBL(l_index).page_application_id,
5227             p_page_code => G_PAGE_REGION_ITEM_REDO_TBL(l_index).page_code,
5228             p_region_application_id =>
5229                         G_PAGE_REGION_ITEM_REDO_TBL(l_index).region_application_id,
5230             p_region_code => G_PAGE_REGION_ITEM_REDO_TBL(l_index).region_code,
5231             p_attribute_application_id =>
5232                         G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute_application_id,
5233             p_attribute_code => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute_code) then
5234           AK_FLOW_PVT.UPDATE_PAGE_REGION_ITEM (
5235              p_validation_level => p_validation_level,
5236              p_api_version_number => 1.0,
5237              p_msg_count => l_msg_count,
5238              p_msg_data => l_msg_data,
5239              p_return_status => l_return_status,
5240              p_flow_application_id =>
5241                          G_PAGE_REGION_ITEM_REDO_TBL(l_index).flow_application_id,
5242              p_flow_code => G_PAGE_REGION_ITEM_REDO_TBL(l_index).flow_code,
5243              p_page_application_id =>
5244                          G_PAGE_REGION_ITEM_REDO_TBL(l_index).page_application_id,
5245              p_page_code => G_PAGE_REGION_ITEM_REDO_TBL(l_index).page_code,
5246              p_region_application_id =>
5247                          G_PAGE_REGION_ITEM_REDO_TBL(l_index).region_application_id,
5248              p_region_code => G_PAGE_REGION_ITEM_REDO_TBL(l_index).region_code,
5249              p_attribute_application_id =>
5250                          G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute_application_id,
5251              p_attribute_code => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute_code,
5252              p_to_page_appl_id => G_PAGE_REGION_ITEM_REDO_TBL(l_index).to_page_appl_id,
5253              p_to_page_code => G_PAGE_REGION_ITEM_REDO_TBL(l_index).to_page_code,
5254              p_to_url_attribute_appl_id =>
5255                          G_PAGE_REGION_ITEM_REDO_TBL(l_index).to_url_attribute_appl_id,
5256              p_to_url_attribute_code =>
5257                          G_PAGE_REGION_ITEM_REDO_TBL(l_index).to_url_attribute_code,
5258              p_attribute_category => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute_category,
5259 			 p_attribute1 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute1,
5260 			 p_attribute2 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute2,
5261 			 p_attribute3 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute3,
5262 			 p_attribute4 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute4,
5263 			 p_attribute5 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute5,
5264 			 p_attribute6 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute6,
5265 			 p_attribute7 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute7,
5266 			 p_attribute8 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute8,
5267 			 p_attribute9 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute9,
5268 			 p_attribute10 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute10,
5269 			 p_attribute11 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute11,
5270 			 p_attribute12 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute12,
5271 			 p_attribute13 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute13,
5272 			 p_attribute14 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute14,
5273 			 p_attribute15 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute15,
5274                 p_created_by => G_PAGE_REGION_ITEM_REDO_TBL(l_index).created_by,
5275                 p_creation_date => G_PAGE_REGION_ITEM_REDO_TBL(l_index).creation_date,
5276                 p_last_updated_by => G_PAGE_REGION_ITEM_REDO_TBL(l_index).last_updated_by,
5277                 p_last_update_date => G_PAGE_REGION_ITEM_REDO_TBL(l_index).last_update_date,
5278                 p_last_update_login => G_PAGE_REGION_ITEM_REDO_TBL(l_index).last_update_login,
5279              p_loader_timestamp => p_loader_timestamp,
5280              p_pass => p_pass,
5281              p_copy_redo_flag => l_copy_redo_flag
5282            );
5283         else
5284           AK_FLOW_PVT.CREATE_PAGE_REGION_ITEM (
5285             p_validation_level => p_validation_level,
5286             p_api_version_number => 1.0,
5287             p_msg_count => l_msg_count,
5288             p_msg_data => l_msg_data,
5289             p_return_status => l_return_status,
5290             p_flow_application_id =>
5291                         G_PAGE_REGION_ITEM_REDO_TBL(l_index).flow_application_id,
5292             p_flow_code => G_PAGE_REGION_ITEM_REDO_TBL(l_index).flow_code,
5293             p_page_application_id =>
5294                         G_PAGE_REGION_ITEM_REDO_TBL(l_index).page_application_id,
5295             p_page_code => G_PAGE_REGION_ITEM_REDO_TBL(l_index).page_code,
5296             p_region_application_id =>
5297                         G_PAGE_REGION_ITEM_REDO_TBL(l_index).region_application_id,
5298             p_region_code => G_PAGE_REGION_ITEM_REDO_TBL(l_index).region_code,
5299             p_attribute_application_id =>
5300                         G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute_application_id,
5301             p_attribute_code => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute_code,
5302             p_to_page_appl_id => G_PAGE_REGION_ITEM_REDO_TBL(l_index).to_page_appl_id,
5303             p_to_page_code => G_PAGE_REGION_ITEM_REDO_TBL(l_index).to_page_code,
5304             p_to_url_attribute_appl_id =>
5305                         G_PAGE_REGION_ITEM_REDO_TBL(l_index).to_url_attribute_appl_id,
5306             p_to_url_attribute_code =>
5307                         G_PAGE_REGION_ITEM_REDO_TBL(l_index).to_url_attribute_code,
5308             p_attribute_category => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute_category,
5309 			p_attribute1 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute1,
5310 			p_attribute2 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute2,
5311 			p_attribute3 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute3,
5312 			p_attribute4 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute4,
5313 			p_attribute5 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute5,
5314 			p_attribute6 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute6,
5315 			p_attribute7 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute7,
5316 			p_attribute8 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute8,
5317 			p_attribute9 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute9,
5318 			p_attribute10 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute10,
5319 			p_attribute11 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute11,
5320 			p_attribute12 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute12,
5321 			p_attribute13 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute13,
5322 			p_attribute14 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute14,
5323 			p_attribute15 => G_PAGE_REGION_ITEM_REDO_TBL(l_index).attribute15,
5324         p_created_by => G_PAGE_REGION_ITEM_REDO_TBL(l_index).created_by,
5325         p_creation_date => G_PAGE_REGION_ITEM_REDO_TBL(l_index).creation_date,
5326         p_last_updated_by => G_PAGE_REGION_ITEM_REDO_TBL(l_index).last_updated_by,
5327         p_last_update_date => G_PAGE_REGION_ITEM_REDO_TBL(l_index).last_update_date,
5328         p_last_update_login => G_PAGE_REGION_ITEM_REDO_TBL(l_index).last_update_login,
5329             p_loader_timestamp => p_loader_timestamp,
5330   		    p_pass => p_pass,
5331             p_copy_redo_flag => l_copy_redo_flag
5332           );
5333         end if; -- /* if PAGE_REGION_ITEM_EXISTS */
5334 		--
5335         -- If API call returns with an error status, upload aborts
5336         if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
5337         (l_return_status = FND_API.G_RET_STS_ERROR) then
5338           RAISE FND_API.G_EXC_ERROR;
5339         end if; -- /* if l_return_status */
5340       end if;
5341     end loop;
5342   end if;
5343 
5344   p_return_status := FND_API.G_RET_STS_SUCCESS;
5345 
5346 EXCEPTION
5347 WHEN FND_API.G_EXC_ERROR THEN
5348   p_return_status := FND_API.G_RET_STS_ERROR;
5349   FND_MSG_PUB.Count_And_Get (
5350    p_count => l_msg_count,
5351    p_data => l_msg_data);
5352 WHEN OTHERS THEN
5353   p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5354   FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
5355                          SUBSTR (SQLERRM, 1, 240) );
5356   FND_MSG_PUB.Count_And_Get (
5357     p_count => l_msg_count,
5358     p_data => l_msg_data);
5359 
5360 end UPLOAD_FLOW_SECOND;
5361 
5362 end AK_FLOW2_PVT;