DBA Data[Home] [Help]

PACKAGE BODY: APPS.AK_AMPARAM_REGISTRY_PVT

Source


1 package body AK_AMPARAM_REGISTRY_PVT as
2 /* $Header: akdvaprb.pls 120.3 2005/09/15 22:49:22 tshort noship $ */
3 
4 --=======================================================
5 --  Procedure   WRITE_TO_BUFFER (local procedure)
6 --
7 --  Usage       Local procedure for writing the given amparam_registry
8 --              and all its children records to the output file.
9 --              Not designed to be called from outside this package.
10 --
11 --  Desc        This procedure first retrieves and writes the given
12 --              object to the loader file. Then it calls other local
13 --              procedures to write all its object attributes and
14 --              foriegn and unique key definitions to the same output
15 --              file.
16 --
17 --  Results     The API returns the standard p_return_status parameter
18 --              indicating one of the standard return statuses :
19 --                  * Unexpected error
20 --                  * Error
21 --                  * Success
22 --  Parameters
23 --              p_query_code : IN required
24 --                  Key value of the Object to be extracted to the loader
25 --                  file.
26 --              p_nls_language : IN required
27 --                  The NLS langauge that should be used when
28 --                  extracting data from the TL table
29 --=======================================================
30 procedure WRITE_TO_BUFFER (
31 p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
32 p_return_status            OUT NOCOPY     VARCHAR2,
33 p_applicationmodule_defn_name	 IN      VARCHAR2,
34 p_nls_language             IN      VARCHAR2
35 ) is
36 cursor l_get_ap_registry_csr (param_query_code in varchar2) is
37 select *
38 from AK_AM_PARAMETER_REGISTRY
39 where APPLICATIONMODULE_DEFN_NAME = param_query_code
40 order by APPLICATIONMODULE_DEFN_NAME;
41 
42 l_api_name           CONSTANT varchar2(30) := 'Write_to_buffer';
43 l_databuffer_tbl     AK_ON_OBJECTS_PUB.Buffer_Tbl_Type;
44 l_index              NUMBER;
45 l_ap_registry_rec    ak_am_parameter_registry%ROWTYPE;
46 l_return_status      varchar2(1);
47 
48 begin
49 -- Retrieve object information from the database
50 
51 open l_get_ap_registry_csr(p_applicationmodule_defn_name);
52 loop
53 fetch l_get_ap_registry_csr into l_ap_registry_rec;
54 exit when l_get_ap_registry_csr%notfound;
55 
56 -- query Object line must be validated before it is written to the file
57 /* nothing to validate yet
58 if p_validation_level <> FND_API.G_VALID_LEVEL_NONE then
59 if not AK_AMPARAM_REGISTRY_PVT.VALIDATE_AP_REGISTRY (
60 p_validation_level => p_validation_level,
61 p_api_version_number => 1.0,
62 p_return_status => l_return_status,
63 p_APPLICATIONMODULE_DEFN_NAME => l_ap_registry_rec.APPLICATIONMODULE_DEFN_NAME,
64 p_application_id => l_ap_registry_rec.application_id
65 )
66 then
67 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
68 FND_MESSAGE.SET_NAME('AK','AK_AP_REGISTRY_NOT_DOWNLOADED');
69 FND_MESSAGE.SET_TOKEN('KEY', p_APPLICATIONMODULE_DEFN_NAME);
70 FND_MSG_PUB.Add;
71 end if;
72 close l_get_ap_registry_csr;
73 raise FND_API.G_EXC_ERROR;
74 end if;
75 end if;
76 */
77 -- Write object into buffer
78 l_index := 1;
79 
80 l_databuffer_tbl(l_index) := 'BEGIN AMPARAM_REGISTRY "'||
81 AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_ap_registry_rec.APPLICATIONMODULE_DEFN_NAME)||'" "'||AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_ap_registry_rec.param_name)||'" "'||AK_ON_OBJECTS_PVT.REPLACE_SPECIAL_CHAR(l_ap_registry_rec.param_source)||'"';
82 l_index := l_index + 1;
83 l_databuffer_tbl(l_index) := '  APPLICATION_ID = ' ||
84 nvl(to_char(l_ap_registry_rec.application_id),'""');
85 l_index := l_index + 1;
86 l_databuffer_tbl(l_index) := 'END AMPARAM_REGISTRY ';
87 l_index := l_index + 1;
88 l_databuffer_tbl(l_index) := ' ';
89 
90 -- - Write object data out to the specified file
91 AK_ON_OBJECTS_PVT.WRITE_FILE (
92 p_return_status => l_return_status,
93 p_buffer_tbl => l_databuffer_tbl,
94 p_write_mode => AK_ON_OBJECTS_PUB.G_APPEND
95 );
96 -- If API call returns with an error status...
97 if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
98 (l_return_status = FND_API.G_RET_STS_ERROR) then
99 close l_get_ap_registry_csr;
100 RAISE FND_API.G_EXC_ERROR;
101 end if;
102 
103 l_databuffer_tbl.delete;
104 
105 if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
106 (l_return_status = FND_API.G_RET_STS_ERROR) then
107 close l_get_ap_registry_csr;
108 RAISE FND_API.G_EXC_ERROR;
109 end if;
110 
111 -- - Finish up writing object data out to the specified file
112 AK_ON_OBJECTS_PVT.WRITE_FILE (
113 p_return_status => l_return_status,
114 p_buffer_tbl => l_databuffer_tbl,
115 p_write_mode => AK_ON_OBJECTS_PUB.G_APPEND
116 );
117 
118 -- If API call returns with an error status...
119 if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
120 (l_return_status = FND_API.G_RET_STS_ERROR) then
121 close l_get_ap_registry_csr;
122 RAISE FND_API.G_EXC_ERROR;
123 end if;
124 end loop;
125 close l_get_ap_registry_csr;
126 
127 p_return_status := FND_API.G_RET_STS_SUCCESS;
128 
129 EXCEPTION
130 WHEN VALUE_ERROR THEN
131 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
132 FND_MESSAGE.SET_NAME('AK','AK_AP_REGISTRY_VALUE_ERROR');
133 FND_MESSAGE.SET_TOKEN('KEY', p_APPLICATIONMODULE_DEFN_NAME);
134 FND_MSG_PUB.Add;
135 end if;
136 p_return_status := FND_API.G_RET_STS_ERROR;
137 WHEN FND_API.G_EXC_ERROR THEN
138 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
139 FND_MESSAGE.SET_NAME('AK','AK_AP_REGISTRY_NOT_DOWNLOADED');
140 FND_MESSAGE.SET_TOKEN('KEY', p_APPLICATIONMODULE_DEFN_NAME);
141 FND_MSG_PUB.Add;
142 end if;
143 p_return_status := FND_API.G_RET_STS_ERROR;
144 WHEN OTHERS THEN
145 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
146 FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
147 SUBSTR (SQLERRM, 1, 240) );
148 FND_MSG_PUB.Add;
149 end WRITE_TO_BUFFER;
150 
151 --=======================================================
152 --  Procedure   DOWNLOAD_AMPARAM_REGISTRY
153 --
154 --  Usage       Private API for downloading amparam_registry objects. This
155 --              API should only be called by other APIs that are
156 --              owned by the Core Modules Team (AK).
157 --
158 --  Desc        This API will extract the amparam_registry objects selected
159 --              by application ID or by key values from the
160 --              database to the output file.
161 --
162 --  Results     The API returns the standard p_return_status parameter
163 --              indicating one of the standard return statuses :
164 --                  * Unexpected error
165 --                  * Error
166 --                  * Success
167 --  Parameters
168 --              p_nls_language : IN optional
169 --                  NLS language for database. If none if given,
170 --                  the current NLS language will be used.
171 --
172 --              One of the following parameters must be provided:
173 --
174 --              p_application_id : IN optional
175 --                  If given, all attributes for this application ID
176 --                  will be written to the output file.
177 --                  p_application_id will be ignored if a table is
178 --                  given in p_object_pk_tbl.
179 --              p_amparamreg_pk_tbl : IN optional
180 --                  If given, only amparam_registry objects whose key values are
181 --                  included in this table will be written to the
182 --                  output file.
183 --
184 --
185 --  Version     Initial version number  =   1.0
186 --  History     Current version number  =   1.0
187 --=======================================================
188 procedure DOWNLOAD_AMPARAM_REGISTRY (
189 p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
190 p_api_version_number       IN      NUMBER,
191 p_return_status            OUT NOCOPY     VARCHAR2,
192 p_application_id           IN      NUMBER := FND_API.G_MISS_NUM,
193 p_amparamreg_pk_tbl        IN      AK_AMPARAM_REGISTRY_PUB.AmParamReg_Pk_Tbl_Type :=
194 AK_AMPARAM_REGISTRY_PUB.G_MISS_AMPARAMREG_PK_TBL,
195 p_nls_language             IN      VARCHAR2
196 ) is
197 cursor l_get_ap_registry_list_csr (appl_id_parm in number) is
198 select APPLICATIONMODULE_DEFN_NAME
199 from ak_am_parameter_registry
200 where APPLICATION_ID = appl_id_parm;
201 l_api_version_number CONSTANT number := 1.0;
202 l_api_name           CONSTANT varchar2(30) := 'Download_AP_Registry';
203 l_application_id     NUMBER;
204 l_query_code         VARCHAR2(30);
205 l_index              NUMBER;
206 l_last_orig_index    NUMBER;
207 l_msg_count          NUMBER;
208 l_msg_data           VARCHAR2(2000);
209 l_amparamreg_pk_tbl  AK_AMPARAM_REGISTRY_PUB.amparamreg_Pk_Tbl_Type;
210 l_return_status      varchar2(1);
211 begin
212 IF NOT FND_API.Compatible_API_Call (
213 l_api_version_number, p_api_version_number, l_api_name,
214 G_PKG_NAME) then
215 -- dbms_output.put_line('API error in AK_OBJECTS2_PVT');
216 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
217 return;
218 END IF;
219 
220 -- Check that one of the following selection criteria is given:
221 -- - p_application_id alone, or
222 -- - query codes in p_queryobj_PK_tbl
223 
224 if (p_application_id = FND_API.G_MISS_NUM) or (p_application_id is null) then
225 if (p_amparamreg_pk_tbl.count = 0) then
226 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
227 FND_MESSAGE.SET_NAME('AK','AK_NO_SELECTION');
228 FND_MSG_PUB.Add;
229 end if;
230 raise FND_API.G_EXC_ERROR;
231 end if;
232 else
233 if (p_amparamreg_pk_tbl.count > 0) then
234 -- both application ID and a list of objects to be extracted are
235 -- given, issue a warning that we will ignore the application ID
236 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
237 FND_MESSAGE.SET_NAME('AK','AK_APPL_ID_IGNORED');
238 FND_MSG_PUB.Add;
239 end if;
240 end if;
241 end if;
242 
243 -- If selecting by application ID, first load a query object primary key table
244 -- with the query codes of all query objects for the given application ID.
245 -- If selecting by a list of query objects, simply copy the query object unique key
246 -- table with the parameter
247 if (p_amparamreg_pk_tbl.count > 0) then
248 l_amparamreg_pk_tbl := p_amparamreg_pk_tbl;
249 else
250 l_index := 1;
251 open l_get_ap_registry_list_csr(p_application_id);
252 loop
253 fetch l_get_ap_registry_list_csr into l_amparamreg_pk_tbl(l_index);
254 exit when l_get_ap_registry_list_csr%notfound;
255 l_index := l_index + 1;
256 end loop;
257 close l_get_ap_registry_list_csr;
258 end if;
259 
260 -- Put index pointing to the first record of the query objects primary key table
261 l_index := l_amparamreg_pk_tbl.FIRST;
262 
263 -- Write details for each selected query object, including its query
264 -- object lines to a buffer to be passed back to the calling procedure.
265 --
266 
267 while (l_index is not null) loop
268 -- Write object information from the database
269 
270 --dbms_output.put_line('writing object #'||to_char(l_index) || ':' ||
271 --                      l_queryobj_pk_tbl(l_index).query_code);
272 
273 WRITE_TO_BUFFER(
274 p_validation_level => p_validation_level,
275 p_return_status => l_return_status,
276 p_applicationmodule_defn_name => l_amparamreg_pk_tbl(l_index).APPLICATIONMODULE_DEFN_NAME,
277 p_nls_language => p_nls_language
278 );
279 -- Download aborts if any of the validation fails
280 --
281 if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
282 (l_return_status = FND_API.G_RET_STS_ERROR) then
283 --	  dbms_output.put_line('error throwing from WRITE_TO_BUFFER');
284 RAISE FND_API.G_EXC_ERROR;
285 end if;
286 
287 -- Ready to download the next object in the list
288 l_index := l_amparamreg_pk_tbl.NEXT(l_index);
289 
290 end loop;
291 
292 p_return_status := FND_API.G_RET_STS_SUCCESS;
293 
294 -- dbms_output.put_line('returning from ak_object_pvt.download_query_object: ' ||
295 --                        to_char(sysdate, 'MON-DD HH24:MI:SS'));
296 
297 EXCEPTION
298 WHEN VALUE_ERROR THEN
299 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
300 FND_MESSAGE.SET_NAME('AK','AK_APREG_PK_VALUE_ERROR');
301 FND_MSG_PUB.Add;
302 end if;
303 -- dbms_output.put_line('Value error occurred in download- check your object list.');
304 p_return_status := FND_API.G_RET_STS_ERROR;
305 WHEN FND_API.G_EXC_ERROR THEN
306 p_return_status := FND_API.G_RET_STS_ERROR;
307 WHEN OTHERS THEN
308 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
309 FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name,
310 SUBSTR (SQLERRM, 1, 240) );
311 end DOWNLOAD_AMPARAM_REGISTRY;
312 
313 
314 --=======================================================
315 --  Procedure   VALIDATE_AP_REGISTRY (local procedure)
316 --  not being used yet
317 --=======================================================
318 
319 FUNCTION VALIDATE_AP_REGISTRY (
320 p_validation_level			IN	NUMBER := FND_API.G_VALID_LEVEL_FULL,
321 p_api_version_number		IN	NUMBER,
322 p_return_status				OUT NOCOPY	VARCHAR2,
323 p_APPLICATIONMODULE_DEFN_NAME	IN	VARCHAR2,
324 p_application_id			IN	NUMBER,
325 p_pass						IN	NUMBER := 2
326 ) RETURN BOOLEAN IS
327 
328 l_error			boolean;
329 l_return_status varchar2(1);
330 l_api_name		CONSTANT	varchar2(30) := 'VALIDATE_AP_REGISTRY';
331 
332 BEGIN
333 if ( not (AK_ON_OBJECTS_PVT.VALID_APPLICATION_ID(
334 p_api_version_number,
335 l_return_status,
336 p_application_id) ) ) then
337 l_error := TRUE;
338 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) and (p_pass = 2) then
339 FND_MESSAGE.SET_NAME('AK','AK_INVALID_COLUMN_VALUE');
340 FND_MESSAGE.SET_TOKEN('COLUMN','APPLICATION_ID');
341 FND_MSG_PUB.Add;
342 end if;
343 end if;
344 p_return_status := FND_API.G_RET_STS_SUCCESS;
345 return (not l_error);
346 
347 EXCEPTION
348 WHEN OTHERS THEN
349 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
350 FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
351 SUBSTR (SQLERRM, 1, 240) );
352 FND_MSG_PUB.Add;
353 
354 END VALIDATE_AP_REGISTRY;
355 
356 --=======================================================
357 --  Function   AMPARAM_REGISTRY_EXISTS
358 --
359 --  Usage       Private API for checking existence of amparam_registry. This
360 --              API should only be called by other APIs that are
361 --              owned by the Core Modules Team (AK).
362 --=======================================================
363 
364 FUNCTION AMPARAM_REGISTRY_EXISTS (
365 p_api_version_number	in	number,
366 p_return_status			out NOCOPY	varchar2,
367 p_applicationmodule_defn_name	IN      VARCHAR2,
368 p_param_name			IN		VARCHAR2,
369 p_param_value			IN		VARCHAR2,
370 p_application_id		in	number
371 ) RETURN BOOLEAN IS
372 CURSOR l_chk_amparam_exists_csr (appmodule_defn_name_param in varchar2,
373 param_name_param in varchar2, param_value_param in varchar2) is
374 select 1
375 from ak_am_parameter_registry
376 where APPLICATIONMODULE_DEFN_NAME = appmodule_defn_name_param
377 and PARAM_NAME = param_name_param
378 and param_source = param_value_param;
379 l_dummy			number;
380 l_api_name		constant	varchar2(30) := 'AMPARAM_REGISTRY_EXISTS';
381 l_api_version_number      CONSTANT number := 1.0;
382 BEGIN
383 IF NOT FND_API.Compatible_API_Call (
384 l_api_version_number, p_api_version_number, l_api_name,
385 G_PKG_NAME) then
386 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
387 return FALSE;
388 END IF;
389 
390 open l_chk_amparam_exists_csr(p_APPLICATIONMODULE_DEFN_NAME, p_param_name, p_param_value);
391 fetch l_chk_amparam_exists_csr into l_dummy;
392 if (l_chk_amparam_exists_csr%notfound) then
393 close l_chk_amparam_exists_csr;
394 p_return_status := FND_API.G_RET_STS_SUCCESS;
395 return FALSE;
396 else
397 close l_chk_amparam_exists_csr;
398 p_return_status := FND_API.G_RET_STS_SUCCESS;
399 return TRUE;
400 end if;
401 
402 EXCEPTION
403 WHEN FND_API.G_EXC_ERROR THEN
404 p_return_status := FND_API.G_RET_STS_ERROR;
405 return FALSE;
406 WHEN OTHERS THEN
407 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
408 FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
409 SUBSTR (SQLERRM, 1, 240) );
410 FND_MSG_PUB.Add;
411 return FALSE;
412 END AMPARAM_REGISTRY_EXISTS;
413 
414 
415 --=======================================================
416 --  Procedure   CREATE_AMPARAM_REGISTRY
417 --
418 --  Usage       Private API for creating amparam_registry objects. This
419 --              API should only be called by other APIs that are
420 --              owned by the Core Modules Team (AK).
421 --
422 --  Desc        Creates a region using the given info.
423 --              This API should only be called by other APIs that are
424 --              owned by the Core Modules Team (AK).
425 --
426 --  Results     The API returns the standard p_return_status parameter
427 --              indicating one of the standard return statuses :
428 --                  * Unexpected error
429 --                  * Error
430 --                  * Success
431 --  Parameters  Query Object columns
432 --              p_loader_timestamp : IN optional
433 --                  If a timestamp is passed, the API will create the
434 --                  record using this timestamp. Only the upload API
435 --                  should call with this parameter loaded.
436 --=======================================================
437 
438 PROCEDURE CREATE_AMPARAM_REGISTRY(
439 p_validation_level		IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
440 p_api_version_number	IN		NUMBER,
441 p_init_msg_tbl			IN      BOOLEAN := FALSE,
442 p_msg_count				OUT NOCOPY		NUMBER,
443 p_msg_data				OUT NOCOPY		VARCHAR2,
444 p_return_status			OUT NOCOPY		VARCHAR2,
445 p_applicationmodule_defn_name	IN      VARCHAR2,
446 p_param_name			IN		VARCHAR2,
447 p_param_value			IN		VARCHAR2,
448 p_application_id		IN		NUMBER,
449 p_loader_timestamp      IN      DATE := FND_API.G_MISS_DATE,
450 p_pass					IN		NUMBER := 2
451 ) IS
452 l_api_version_number	CONSTANT number := 1.0;
453 l_api_name				constant	varchar2(30) := 'CREATE_AMPARAM_REGISTRY';
454 l_return_status			varchar2(1);
455 l_created_by              number;
456 l_creation_date           date;
457 l_last_update_date        date;
458 l_last_update_login       number;
459 l_last_updated_by         number;
460 BEGIN
461 IF NOT FND_API.Compatible_API_Call (
462 l_api_version_number, p_api_version_number, l_api_name,
463 G_PKG_NAME) then
464 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
465 return;
466 END IF;
467 
468 -- Initialize the message table if requested.
469 
470 if p_init_msg_tbl then
471 FND_MSG_PUB.initialize;
472 end if;
473 
474 savepoint start_create_amparam;
475 
476 --** check to see if row already exists **
477 if AK_AMPARAM_REGISTRY_PVT.AMPARAM_REGISTRY_EXISTS (
478 p_api_version_number => 1.0,
479 p_return_status => l_return_status,
480 p_applicationmodule_defn_name => p_applicationmodule_defn_name,
481 p_param_name => p_param_name,
482 p_param_value => p_param_value,
483 p_application_id => p_application_id) then
484 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
485 FND_MESSAGE.SET_NAME('AK','AK_AMPARAM_REGISTRY_EXISTS');
486 FND_MSG_PUB.Add;
487 end if;
488 -- dbms_output.put_line(G_PKG_NAME || 'Error - Row already exists');
489 raise FND_API.G_EXC_ERROR;
490 end if;
491 
492 -- Create record if no validation error was found
493 /*
494 -- Set WHO columns
495 AK_ON_OBJECTS_PVT.SET_WHO (
496 p_return_status => l_return_status,
497 p_loader_timestamp => p_loader_timestamp,
498 p_created_by => l_created_by,
499 p_creation_date => l_creation_date,
500 p_last_updated_by => l_last_updated_by,
501 p_last_update_date => l_last_update_date,
502 p_last_update_login => l_last_update_login);
503 */
504 
505 insert into AK_AM_PARAMETER_REGISTRY (
506 APPLICATIONMODULE_DEFN_NAME,
507 PARAM_NAME,
508 PARAM_SOURCE,
509 APPLICATION_ID
510 ) values (
511 p_applicationmodule_defn_name,
512 p_param_name,
513 p_param_value,
514 p_application_id);
515 
516 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
517 FND_MESSAGE.SET_NAME('AK','AK_AMPARAM_REGISTRY_CREATED');
518 FND_MESSAGE.SET_TOKEN('KEY', p_applicationmodule_defn_name);
519 FND_MSG_PUB.Add;
520 end if;
521 
522 p_return_status := FND_API.G_RET_STS_SUCCESS;
523 
524 FND_MSG_PUB.Count_And_Get (
525 p_count => p_msg_count,
526 p_data => p_msg_data);
527 
528 EXCEPTION
529 WHEN VALUE_ERROR THEN
530 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
531 FND_MESSAGE.SET_NAME('AK','AK_AMPARAM_VALUE_ERROR');
532 FND_MESSAGE.SET_TOKEN('KEY', p_applicationmodule_defn_name);
533 FND_MSG_PUB.Add;
534 end if;
535 p_return_status := FND_API.G_RET_STS_ERROR;
536 rollback to start_create_amparam;
537 FND_MSG_PUB.Count_And_Get (
538 p_count => p_msg_count,
539 p_data => p_msg_data);
540 WHEN FND_API.G_EXC_ERROR THEN
541 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
542 FND_MESSAGE.SET_NAME('AK','AK_AMPARAM_NOT_CREATED');
543 FND_MESSAGE.SET_TOKEN('KEY', p_applicationmodule_defn_name);
544 FND_MSG_PUB.Add;
545 end if;
546 p_return_status := FND_API.G_RET_STS_ERROR;
547 rollback to start_create_amparam;
548 FND_MSG_PUB.Count_And_Get (
549 p_count => p_msg_count,
550 p_data => p_msg_data);
551 WHEN OTHERS THEN
552 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
553 rollback to start_create_amparam;
554 FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
555 SUBSTR (SQLERRM, 1, 240) );
556 FND_MSG_PUB.Add;
557 FND_MSG_PUB.Count_And_Get (
558 p_count => p_msg_count,
559 p_data => p_msg_data);
560 
561 END CREATE_AMPARAM_REGISTRY;
562 
563 --=======================================================
564 --  Procedure   UPDATE_AMPARAM_REGISTRY
565 --
566 --  Usage       Private API for updating amparam_registry objects. This
567 --              API should only be called by other APIs that are
568 --              owned by the Core Modules Team (AK).
569 --
570 --  Desc        Updates a amparam_registry using the given info.
571 --              This API should only be called by other APIs that are
572 --              owned by the Core Modules Team (AK).
573 --
574 --  Results     The API returns the standard p_return_status parameter
575 --              indicating one of the standard return statuses :
576 --                  * Unexpected error
577 --                  * Error
578 --                  * Success
579 --  Parameters  Query Object columns
580 --              p_loader_timestamp : IN optional
581 --                  If a timestamp is passed, the API will create the
582 --                  record using this timestamp. Only the upload API
583 --                  should call with this parameter loaded.
584 --=======================================================
585 
586 PROCEDURE UPDATE_AMPARAM_REGISTRY(
587 p_validation_level		IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
588 p_api_version_number	IN		NUMBER,
589 p_init_msg_tbl			IN      BOOLEAN := FALSE,
590 p_msg_count				OUT NOCOPY		NUMBER,
591 p_msg_data				OUT NOCOPY		VARCHAR2,
592 p_return_status			OUT NOCOPY		VARCHAR2,
593 p_applicationmodule_defn_name	IN      VARCHAR2,
594 p_param_name			IN		VARCHAR2,
595 p_param_value			IN		VARCHAR2,
596 p_application_id		IN		NUMBER,
597 p_loader_timestamp      IN      DATE := FND_API.G_MISS_DATE,
598 p_pass					IN		NUMBER := 2
599 ) IS
600 cursor l_get_amparam_registry_csr is
601 select *
602 from  AK_AM_PARAMETER_REGISTRY
603 where APPLICATIONMODULE_DEFN_NAME = p_applicationmodule_defn_name
604 for update of APPLICATION_ID;
605 
606 l_api_version_number      CONSTANT number := 1.0;
607 l_api_name                CONSTANT varchar2(30) := 'Update_AmPara_Registry';
608 l_amparam_reg_rec            AK_AM_PARAMETER_REGISTRY%ROWTYPE;
609 l_created_by              number;
610 l_creation_date           date;
611 l_last_update_date        date;
612 l_last_update_login       number;
613 l_last_updated_by         number;
614 l_return_status           varchar2(1);
615 BEGIN
616 IF NOT FND_API.Compatible_API_Call (
617 l_api_version_number, p_api_version_number, l_api_name,
618 G_PKG_NAME) then
619 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
620 return;
621 END IF;
622 
623 -- Initialize the message table if requested.
624 
625 if p_init_msg_tbl then
626 FND_MSG_PUB.initialize;
627 end if;
628 
629 savepoint start_update_amparam;
630 
631 --** retrieve ak_regions row if it exists **
632 open l_get_amparam_registry_csr;
633 fetch l_get_amparam_registry_csr into l_amparam_reg_rec;
634 if (l_get_amparam_registry_csr%notfound) then
635 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) then
636 FND_MESSAGE.SET_NAME('AK','AK_QUERYOBJ_DOES_NOT_EXIST');
637 FND_MSG_PUB.Add;
638 end if;
639 --dbms_output.put_line(l_api_name || 'Error - Row does not exist');
640 close l_get_amparam_registry_csr;
641 raise FND_API.G_EXC_ERROR;
642 end if;
643 close l_get_amparam_registry_csr;
644 
645 if ( NOT AK_ON_OBJECTS_PVT.VALID_APPLICATION_ID (
646 p_api_version_number => 1.0,
647 p_return_status => l_return_status,
648 p_application_id => p_application_id) ) then
649 FND_MESSAGE.SET_NAME('AK','AK_INVALID_COLUMN_VALUE');
650 FND_MESSAGE.SET_TOKEN('COLUMN','APPLICATION_ID');
651 FND_MSG_PUB.Add;
652 raise FND_API.G_EXC_ERROR;
653 end if;
654 
655 l_amparam_reg_rec.application_id := p_application_id;
656 
657 -- Set WHO columns
658 /*
659 AK_ON_OBJECTS_PVT.SET_WHO (
660 p_return_status => l_return_status,
661 p_loader_timestamp => p_loader_timestamp,
662 p_created_by => l_created_by,
663 p_creation_date => l_creation_date,
664 p_last_updated_by => l_last_updated_by,
665 p_last_update_date => l_last_update_date,
666 p_last_update_login => l_last_update_login);
667 */
668 
669 update AK_AM_PARAMETER_REGISTRY set
670 application_id = l_amparam_reg_rec.application_id
671 where applicationmodule_defn_name = p_applicationmodule_defn_name
672 and param_name = p_param_name
673 and param_source = p_param_value;
674 
675 if (sql%notfound) then
676 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
677 FND_MESSAGE.SET_NAME('AK','AK_QUERYOBJ_UPDATE_FAILED');
678 FND_MSG_PUB.Add;
679 end if;
680 raise FND_API.G_EXC_ERROR;
681 end if;
682 
683 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
684 FND_MESSAGE.SET_NAME('AK','AK_AMPARAM_REG_UPDATED');
685 FND_MESSAGE.SET_TOKEN('KEY', p_applicationmodule_defn_name);
686 FND_MSG_PUB.Add;
687 end if;
688 
689 p_return_status := FND_API.G_RET_STS_SUCCESS;
690 
691 FND_MSG_PUB.Count_And_Get (
692 p_count => p_msg_count,
693 p_data => p_msg_data);
694 
695 EXCEPTION
696 WHEN VALUE_ERROR THEN
697 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
698 FND_MESSAGE.SET_NAME('AK','AK_AMPARAM_VALUE_ERROR');
699 FND_MESSAGE.SET_TOKEN('KEY', p_applicationmodule_defn_name);
700 FND_MSG_PUB.Add;
701 end if;
702 rollback to start_update_amparam;
703 p_return_status := FND_API.G_RET_STS_ERROR;
704 FND_MSG_PUB.Count_And_Get (
705 p_count => p_msg_count,
706 p_data => p_msg_data);
707 WHEN FND_API.G_EXC_ERROR THEN
708 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
709 FND_MESSAGE.SET_NAME('AK','AK_AMPARAM_REG_NOT_UPDATED');
710 FND_MESSAGE.SET_TOKEN('KEY', p_applicationmodule_defn_name);
711 FND_MSG_PUB.Add;
712 end if;
713 p_return_status := FND_API.G_RET_STS_ERROR;
714 rollback to start_update_amparam;
715 FND_MSG_PUB.Count_And_Get (
716 p_count => p_msg_count,
717 p_data => p_msg_data);
718 WHEN OTHERS THEN
719 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
720 rollback to start_update_amparam;
721 FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
722 SUBSTR (SQLERRM, 1, 240) );
723 FND_MSG_PUB.Add;
724 FND_MSG_PUB.Count_And_Get (
725 p_count => p_msg_count,
726 p_data => p_msg_data);
727 FND_MSG_PUB.Count_And_Get (
728 p_count => p_msg_count,
729 p_data => p_msg_data);
730 
731 END UPDATE_AMPARAM_REGISTRY;
732 
733 --=======================================================
734 --  Procedure   UPLOAD_AMPARAM_REGISTRY
735 --
736 --  Usage       Private API for loading amparam_registry objects from a
737 --              loader file to the database.
738 --              This API should only be called by other APIs
739 --              that are owned by the Core Modules Team (AK).
740 --
741 --  Desc        This API reads the amparam_registry data
742 --              object lines) stored in the loader file currently being
743 --              processed, parses the data, and loads them to the
744 --              database. The tables are updated with the timestamp
745 --              passed. This API will process the file until the
746 --              EOF is reached, a parse error is encountered, or when
747 --              data for a different business object is read from the file.
748 --
749 --  Results     The API returns the standard p_return_status parameter
750 --              indicating one of the standard return statuses :
751 --                  * Unexpected error
752 --                  * Error
753 --                  * Success
754 --  Parameters  p_index : IN OUT required
755 --                  Index of PL/SQL file to be processed.
756 --              p_loader_timestamp : IN required
757 --                  The timestamp to be used when creating or updating
758 --                  records
759 --              p_line_num : IN optional
760 --                  The first line number in the file to be processed.
761 --                  It is used for keeping track of the line number
762 --                  read so that this info can be included in the
763 --                  error message when a parse error occurred.
764 --              p_buffer : IN required
765 --                  The content of the first line to be processed.
766 --                  The calling API has already read the first line
767 --                  that needs to be parsed by this API, so this
768 --                  line won't be read from the file again.
769 --              p_line_num_out : OUT
770 --                  The number of the last line in the loader file
771 --                  that is read by this API.
772 --              p_buffer_out : OUT
773 --                  The content of the last line read by this API.
774 --                  If an EOF has not reached, this line would
775 --                  contain the beginning of another business object
776 --                  that will need to be processed by another API.
777 --
778 --  Version     Initial version number  =   1.0
779 --  History     Current version number  =   1.0
780 --=======================================================
781 procedure UPLOAD_AMPARAM_REGISTRY (
782 p_validation_level         IN      NUMBER := FND_API.G_VALID_LEVEL_FULL,
783 p_api_version_number       IN      NUMBER,
784 p_return_status            OUT NOCOPY     VARCHAR2,
785 p_index                    IN OUT NOCOPY  NUMBER,
786 p_loader_timestamp         IN      DATE,
787 p_line_num                 IN NUMBER := FND_API.G_MISS_NUM,
788 p_buffer                   IN AK_ON_OBJECTS_PUB.Buffer_Type,
789 p_line_num_out             OUT NOCOPY    NUMBER,
790 p_buffer_out               OUT NOCOPY    AK_ON_OBJECTS_PUB.Buffer_Type,
791 p_upl_loader_cur           IN OUT NOCOPY  AK_ON_OBJECTS_PUB.LoaderCurTyp,
792 p_pass                     IN      NUMBER := 1 -- we don't need 2 passes for query objects, changed from 2 to 1 to match spec for 9i
793 ) is
794 l_api_version_number       CONSTANT number := 1.0;
795 l_api_name                 CONSTANT varchar2(30) := 'Upload_AmParam_Registry';
796 l_buffer                   AK_ON_OBJECTS_PUB.Buffer_Type;
797 l_column                   varchar2(30);
798 l_dummy                    NUMBER;
799 l_eof_flag                 VARCHAR2(1);
800 l_index                    NUMBER;
801 l_line_num                 NUMBER;
802 l_lines_read               NUMBER;
803 l_more_apregistry		 BOOLEAN := TRUE;
804 l_msg_count                NUMBER;
805 l_msg_data                 VARCHAR2(2000);
806 l_amparam_index             NUMBER := 0;
807 l_amparam_rec              ak_am_parameter_registry%ROWTYPE;
808 l_empty_amparam_rec        ak_am_parameter_registry%ROWTYPE;
809 l_amparam_tbl              AK_AMPARAM_REGISTRY_PUB.amparamreg_Tbl_Type;
810 l_return_status            varchar2(1);
811 l_saved_token              AK_ON_OBJECTS_PUB.Buffer_Type;
812 l_state                    NUMBER;
813 l_token                    AK_ON_OBJECTS_PUB.Buffer_Type;
814 l_value_count              NUMBER;
815 l_copy_redo_flag           BOOLEAN := FALSE;
816 l_user_id1				 NUMBER;
817 l_user_id2				 NUMBER;
818 begin
819 
820 IF NOT FND_API.Compatible_API_Call (
821 l_api_version_number, p_api_version_number, l_api_name,
822 G_PKG_NAME) then
823 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
824 return;
825 END IF;
826 
827 SAVEPOINT Start_Upload;
828 
829 -- Retrieve the first non-blank, non-comment line
830 l_state := 0;
831 l_eof_flag := 'N';
832 --
833 -- if calling from ak_on_objects.upload (ie, loader timestamp is given),
834 -- the tokens 'BEGIN AMPARAM_REGISTRY' has already been parsed. Set initial
835 -- buffer to 'BEGIN AMPARAM_REGISTRY' before reading the next line from the
836 -- file. Otherwise, set initial buffer to null.
837 --
838 if (p_loader_timestamp <> FND_API.G_MISS_DATE) then
839 l_buffer := 'BEGIN AMPARAM_REGISTRY ' || p_buffer;
840 else
841 l_buffer := null;
842 end if;
843 
844 if (p_line_num = FND_API.G_MISS_NUM) then
845 l_line_num := 0;
846 else
847 l_line_num := p_line_num;
848 end if;
849 
850 while (l_buffer is null and l_eof_flag = 'N' and p_index <=  AK_ON_OBJECTS_PVT.G_UPL_TABLE_NUM) loop
851 AK_ON_OBJECTS_PVT.READ_LINE (
852 p_return_status => l_return_status,
853 p_index => p_index,
854 p_buffer => l_buffer,
855 p_lines_read => l_lines_read,
856 p_eof_flag => l_eof_flag,
857 p_upl_loader_cur => p_upl_loader_cur
858 );
859 if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
860 (l_return_status = FND_API.G_RET_STS_ERROR) then
861 RAISE FND_API.G_EXC_ERROR;
862 end if;
863 l_line_num := l_line_num + l_lines_read;
864 --
865 -- trim leading spaces and discard comment lines
866 --
867 l_buffer := LTRIM(l_buffer);
868 if (SUBSTR(l_buffer, 1, 1) = '#') then
869 l_buffer := null;
870 end if;
871 end loop;
872 
873 --
874 -- Error if there is nothing to be read from the file
875 --
876 if (l_buffer is null and l_eof_flag = 'Y') then
877 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
878 FND_MESSAGE.SET_NAME('AK','AK_EMPTY_BUFFER');
879 FND_MSG_PUB.Add;
880 end if;
881 raise FND_API.G_EXC_ERROR;
882 end if;
883 
884 -- Read tokens from file, one at a time
885 
886 while (l_eof_flag = 'N') and (l_buffer is not null)
887 and (l_more_apregistry) loop
888 
889 AK_ON_OBJECTS_PVT.GET_TOKEN(
890 p_return_status => l_return_status,
891 p_in_buf => l_buffer,
892 p_token => l_token
893 );
894 
895 --dbms_output.put_line(' State:' || l_state || 'Token:' || l_token);
896 
897 if (l_return_status = FND_API.G_RET_STS_ERROR) or
898 (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) then
899 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
900 FND_MESSAGE.SET_NAME('AK','AK_GET_TOKEN_ERROR');
901 FND_MSG_PUB.Add;
902 end if;
903 --dbms_output.put_line(l_api_name || ' Error parsing buffer');
904 raise FND_API.G_EXC_ERROR;
905 end if;
906 
907 
908 --
909 -- AM_PARAM_REGISTRY (states 0 - 19)
910 --
911 if (l_state = 0) then
912 if (l_token = 'BEGIN') then
913 l_state := 1;
914 else
915 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
916 FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
917 FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
918 FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
919 FND_MESSAGE.SET_TOKEN('EXPECTED','BEGIN');
920 FND_MSG_PUB.Add;
921 end if;
922 raise FND_API.G_EXC_ERROR;
923 end if;
924 elsif (l_state = 1) then
925 if (l_token = 'AMPARAM_REGISTRY') then
926 --== Clear out previous column data  ==--
927 l_amparam_rec := AK_AMPARAM_REGISTRY_PUB.G_MISS_AMPARAMREG_REC;
928 l_state := 2;
929 else
930 -- Found the beginning of a non-region object,
931 -- rebuild last line and pass it back to the caller
932 -- (ak_on_objects_pvt.upload).
933 p_buffer_out := 'BEGIN ' || l_token || ' ' || l_buffer;
934 l_more_apregistry := FALSE;
935 end if;
936 elsif (l_state = 2) then
937 if (l_token is not null) then
938 l_amparam_rec.applicationmodule_defn_name := l_token;
939 l_state := 3;
940 else
941 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
942 FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
943 FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
944 FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
945 FND_MESSAGE.SET_TOKEN('EXPECTED','APPLICATIONMODULE_DEFN_NAME');
946 FND_MSG_PUB.Add;
947 end if;
948 raise FND_API.G_EXC_ERROR;
949 end if;
950 elsif (l_state = 3) then
951 if (l_token is not null) then
952 l_amparam_rec.param_name := l_token;
953 l_state := 4;
954 else
955 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
956 FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
957 FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
958 FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
959 FND_MESSAGE.SET_TOKEN('EXPECTED','PARAM_NAME');
960 FND_MSG_PUB.Add;
961 end if;
962 raise FND_API.G_EXC_ERROR;
963 end if;
964 elsif ( l_state = 4) then
965 if (l_token is not null) then
966 l_amparam_rec.param_source := l_token;
967 l_state := 10;
968 l_value_count := null;
969 else
970 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
971 FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
972 FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
973 FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
974 FND_MESSAGE.SET_TOKEN('EXPECTED','PARAM_VALUE');
975 FND_MSG_PUB.Add;
976 end if;
977 raise FND_API.G_EXC_ERROR;
978 end if;
979 elsif (l_state = 10) then
980 if (l_token = 'END') then
981 l_state := 19;
982 elsif (l_token = 'APPLICATION_ID') then
983 l_column := l_token;
984 l_state := 11;
985 else
986 --
987 -- error if not expecting attribute values added by the translation team
988 -- or if we have read in more than a certain number of values
989 -- for the same DB column
990 --
991 l_value_count := l_value_count + 1;
992 --
993 -- save second value. It will be the token with error if
994 -- it turns out that there is a parse error on this line.
995 --
996 if (l_value_count = 2) then
997 l_saved_token := l_token;
998 end if;
999 if (l_value_count > AK_ON_OBJECTS_PUB.G_MAX_NUM_LOADER_VALUES) or
1000 (l_value_count is null) then
1001 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1002 FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_EFIELD');
1003 FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1004 if (l_value_count is null) then
1005 FND_MESSAGE.SET_TOKEN('TOKEN', l_token||'(debug: l_buffer = '||l_buffer||' l_state = '||to_char(l_state)||')');
1006 else
1007 FND_MESSAGE.SET_TOKEN('TOKEN',l_saved_token);
1008 end if;
1009 FND_MESSAGE.SET_TOKEN('EXPECTED','AMPARAM_REGISTRY');
1010 FND_MSG_PUB.Add;
1011 end if;
1012 --        dbms_output.put_line('Expecting region field, BEGIN, or END');
1013 raise FND_API.G_EXC_ERROR;
1014 end if;
1015 end if;
1016 elsif (l_state = 11) then
1017 if (l_token = '=') then
1018 l_state := 12;
1019 else
1020 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1021 FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1022 FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1023 FND_MESSAGE.SET_TOKEN('TOKEN',l_token);
1024 FND_MESSAGE.SET_TOKEN('EXPECTED','=');
1025 FND_MSG_PUB.Add;
1026 end if;
1027 raise FND_API.G_EXC_ERROR;
1028 end if;
1029 elsif (l_state = 12) then
1030 l_value_count := 1;
1031 if (l_column = 'APPLICATION_ID') then
1032 l_amparam_rec.application_id := to_number(l_token);
1033 l_state := 10;
1034 else
1035 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1036 FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR_VALUE');
1037 FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1038 FND_MESSAGE.SET_TOKEN('TOKEN',l_token||' (debug: l_buffer = '||l_buffer||' l_state = '||to_char(l_state)||')');
1039 FND_MESSAGE.SET_TOKEN('EXPECTED', l_column);
1040 FND_MSG_PUB.Add;
1041 end if;
1042 raise FND_API.G_EXC_ERROR;
1043 end if;
1044 elsif (l_state = 19) then
1045 if (l_token = 'AMPARAM_REGISTRY') then
1046 if AK_AMPARAM_REGISTRY_PVT.AMPARAM_REGISTRY_EXISTS (
1047 p_api_version_number => 1.0,
1048 p_return_status => l_return_status,
1049 p_applicationmodule_defn_name	=> l_amparam_rec.applicationmodule_defn_name,
1050 p_param_name => l_amparam_rec.param_name,
1051 p_param_value	=> l_amparam_rec.param_source,
1052 p_application_id => l_amparam_rec.application_id) then
1053 if ( AK_UPLOAD_GRP.G_UPDATE_MODE ) then
1054 AK_AMPARAM_REGISTRY_PVT.UPDATE_AMPARAM_REGISTRY(
1055 p_validation_level => p_validation_level,
1056 p_api_version_number => 1.0,
1057 p_msg_count => l_msg_count,
1058 p_msg_data => l_msg_data,
1059 p_return_status => l_return_status,
1060 p_applicationmodule_defn_name	=> l_amparam_rec.applicationmodule_defn_name,
1061 p_param_name => l_amparam_rec.param_name,
1062 p_param_value	=> l_amparam_rec.param_source,
1063 p_application_id => l_amparam_rec.application_id,
1064 p_loader_timestamp => p_loader_timestamp,
1065 p_pass => p_pass);
1066 end if;
1067 else
1068 AK_AMPARAM_REGISTRY_PVT.CREATE_AMPARAM_REGISTRY(
1069 p_validation_level => p_validation_level,
1070 p_api_version_number => 1.0,
1071 p_msg_count => l_msg_count,
1072 p_msg_data => l_msg_data,
1073 p_return_status => l_return_status,
1074 p_applicationmodule_defn_name	=> l_amparam_rec.applicationmodule_defn_name,
1075 p_param_name => l_amparam_rec.param_name,
1076 p_param_value	=> l_amparam_rec.param_source,
1077 p_application_id => l_amparam_rec.application_id,
1078 p_loader_timestamp => p_loader_timestamp,
1079 p_pass => p_pass);
1080 
1081 end if;
1082 --
1083 -- If API call returns with an error status, upload aborts
1084 if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
1085 (l_return_status = FND_API.G_RET_STS_ERROR) then
1086 RAISE FND_API.G_EXC_ERROR;
1087 end if; -- /* if l_return_status */
1088 l_state := 0;
1089 else
1090 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1091 FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1092 FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1093 FND_MESSAGE.SET_TOKEN('TOKEN',l_token||' (debug: l_buffer = '||l_buffer||' l_state = '||to_char(l_state)||')');
1094 FND_MESSAGE.SET_TOKEN('EXPECTED', 'AMPARAM_REGISTRY');
1095 FND_MSG_PUB.Add;
1096 end if;
1097 raise FND_API.G_EXC_ERROR;
1098 end if;
1099 
1100 end if; -- if l_state = ...
1101 
1102 -- Get rid of leading white spaces, so that buffer would become
1103 -- null if the only thing in it are white spaces
1104 l_buffer := LTRIM(l_buffer);
1105 
1106 -- Get the next non-blank, non-comment line if current line is
1107 -- fully parsed
1108 while (l_buffer is null and l_eof_flag = 'N' and p_index <=  AK_ON_OBJECTS_PVT.G_UPL_TABLE_NUM) loop
1109 AK_ON_OBJECTS_PVT.READ_LINE (
1110 p_return_status => l_return_status,
1111 p_index => p_index,
1112 p_buffer => l_buffer,
1113 p_lines_read => l_lines_read,
1114 p_eof_flag => l_eof_flag,
1115 p_upl_loader_cur => p_upl_loader_cur
1116 );
1117 if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
1118 (l_return_status = FND_API.G_RET_STS_ERROR) then
1119 RAISE FND_API.G_EXC_ERROR;
1120 end if;
1121 l_line_num := l_line_num + l_lines_read;
1122 --
1123 -- trim leading spaces and discard comment lines
1124 --
1125 l_buffer := LTRIM(l_buffer);
1126 if (SUBSTR(l_buffer, 1, 1) = '#') then
1127 l_buffer := null;
1128 end if;
1129 end loop;
1130 
1131 end LOOP;
1132 
1133 -- If the loops end in a state other then at the end of a region
1134 -- (state 0) or when the beginning of another business object was
1135 -- detected, then the file must have ended prematurely, which is an error
1136 if (l_state <> 0) and (l_more_apregistry) then
1137 if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1138 FND_MESSAGE.SET_NAME('AK','AK_PARSE_ERROR');
1139 FND_MESSAGE.SET_TOKEN('LINENUM', to_char(l_line_num));
1140 FND_MESSAGE.SET_TOKEN('TOKEN', 'END OF FILE');
1141 FND_MESSAGE.SET_TOKEN('EXPECTED', null);
1142 FND_MSG_PUB.Add;
1143 end if;
1144 --dbms_output.put_line('Unexpected END OF FILE: state is ' ||
1145 --            to_char(l_state));
1146 raise FND_API.G_EXC_ERROR;
1147 end if;
1148 
1149 --
1150 -- Load line number of the last file line processed
1151 --
1152 p_line_num_out := l_line_num;
1153 
1154 p_return_status := FND_API.G_RET_STS_SUCCESS;
1155 
1156 
1157 EXCEPTION
1158 WHEN FND_API.G_EXC_ERROR THEN
1159 p_return_status := FND_API.G_RET_STS_ERROR;
1160 rollback to Start_Upload;
1161 WHEN VALUE_ERROR THEN
1162 p_return_status := FND_API.G_RET_STS_ERROR;
1163 FND_MESSAGE.SET_NAME('AK','AK_REGION_VALUE_ERROR');
1164 FND_MESSAGE.SET_TOKEN('KEY',l_amparam_rec.applicationmodule_defn_name);
1165 FND_MSG_PUB.Add;
1166 FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
1167 SUBSTR (SQLERRM, 1, 240)||': '||l_column||'='||l_token );
1168 FND_MSG_PUB.Add;
1169 WHEN OTHERS THEN
1170 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1171 rollback to Start_Upload;
1172 FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
1173 SUBSTR (SQLERRM, 1, 240) );
1174 FND_MSG_PUB.Add;
1175 end UPLOAD_AMPARAM_REGISTRY;
1176 
1177 end AK_AMPARAM_REGISTRY_PVT;