[Home] [Help]
PACKAGE BODY: APPS.GMF_ALLOCATIONDEFINITION_PUB
Source
1 PACKAGE BODY GMF_AllocationDefinition_PUB AS
2 /* $Header: GMFPALCB.pls 120.3 2005/12/06 04:30:23 jboppana noship $ */
3
4 -- Start of comments
5 --+==========================================================================+
6 --| Copyright (c) 1998 Oracle Corporation |
7 --| Redwood Shores, CA, USA |
8 --| All rights reserved. |
9 --+==========================================================================+
10 --| File Name : GMFPALCS.pls |
11 --| Package Name : GMF_AllocationDefinition_PUB |
12 --| API name : GMF_AllocationDefinition_PUB |
13 --| Type : Public |
14 --| Pre-reqs : N/A |
15 --| Function : Allocation Definition creation, updatation and |
16 --| deletetion. |
17 --| Parameters : N/A |
18 --| |
19 --| Current Vers : 3.0 |
20 --| Previous Vers : 2.0 |
21 --| Initial Vers : 1.0 |
22 --| |
23 --| Contents |
24 --| Create_Allocation_Definition |
25 --| Update_Allocation_Definition |
26 --| Delete_Allocation_Definition |
27 --| |
28 --| Notes |
29 --| This package contains public procedures relating to Allocation |
30 --| Definition creation, updatation and deletetion. |
31 --| |
32 --| Pre-defined API message levels |
33 --| |
34 --| Valid values for message levels are from 1-50. |
35 --| 1 being least severe and 50 highest. |
36 --| |
37 --| The pre-defined levels correspond to standard API |
38 --| return status. Debug levels are used to control the amount of |
39 --| debug information a program writes to the PL/SQL message table. |
40 --| |
41 --| G_MSG_LVL_UNEXP_ERROR CONSTANT NUMBER := 60; |
42 --| G_MSG_LVL_ERROR CONSTANT NUMBER := 50; |
43 --| G_MSG_LVL_SUCCESS CONSTANT NUMBER := 40; |
44 --| G_MSG_LVL_DEBUG_HIGH CONSTANT NUMBER := 30; |
45 --| G_MSG_LVL_DEBUG_MEDIUM CONSTANT NUMBER := 20; |
46 --| G_MSG_LVL_DEBUG_LOW CONSTANT NUMBER := 10; |
47 --| |
48 --| HISTORY |
49 --| 27/Feb/2001 Uday Moogala Created Bug# 1418689 |
50 --| |
51 --| 05/NOV/2002 Uday Moogala Bug# 2659435 |
52 --| Performance related fixes. |
53 --| 1. remove G_MISS_xxx assignments. |
54 --| 2. Conditionally calling debug routine. |
55 --| Also, fixed issues found during unit testing. Search for the bug |
56 --| number to find the fixes. |
57 --| 30/Oct/2002 R.Sharath Kumar Bug# 2641405 Added NOCOPY hint |
58 --| 21/NOV/2002 Uday Moogala Bug# 2681243 |
59 --| 1. Return value of GMA_GLOBAL_GRP.set_who has changed to -1 from 0 |
60 --| in case of invalid users. |
61 --| 2. Allocation method is always required. |
62 --| 3. Made g_miss_char to g_miss_num for fixed_percentage validation |
63 --| 4. Removed "when others" section in validate_input_params |
64 --+==========================================================================+
65 -- End of comments
66
67
68 -- Pre-defined API message levels
69 --
70 -- Valid values for message levels are from 1-50.
71 -- 1 being least severe and 50 highest.
72 --
73 -- The pre-defined levels correspond to standard API
74 -- return status. Debug levels are used to control the amount of
75 -- debug information a program writes to the PL/SQL message table.
76
77 -- G_MSG_LVL_UNEXP_ERROR CONSTANT NUMBER := 60;
78 -- G_MSG_LVL_ERROR CONSTANT NUMBER := 50;
79 -- G_MSG_LVL_SUCCESS CONSTANT NUMBER := 40;
80 -- G_MSG_LVL_DEBUG_HIGH CONSTANT NUMBER := 30;
81 -- G_MSG_LVL_DEBUG_MEDIUM CONSTANT NUMBER := 20;
82 -- G_MSG_LVL_DEBUG_LOW CONSTANT NUMBER := 10;
83
84
85 PROCEDURE Validate_Input_Params
86 (
87 p_alloc_def_rec IN Allocation_Definition_Rec_Type
88 ,x_alloc_def_rec OUT NOCOPY Allocation_Definition_Rec_Type
89 ,x_user_id OUT NOCOPY fnd_user.user_id%TYPE
90 ,x_return_status OUT NOCOPY VARCHAR2
91 ) ;
92 --
93 -- Function to check existence of allocation definition
94 FUNCTION check_alloc_def
95 (
96 p_alloc_id IN gl_aloc_bas.alloc_id%TYPE
97 ,p_alloc_method IN gl_aloc_bas.alloc_method%TYPE
98 )
99 RETURN BOOLEAN ;
100 --
101 FUNCTION is_fxdpct_hundred
102 (
103 p_alloc_id IN gl_aloc_bas.alloc_id%TYPE
104 )
105 RETURN BOOLEAN ;
106 --
107 FUNCTION check_record_exist
108 (
109 p_alloc_id IN gl_aloc_bas.alloc_id%TYPE,
110 p_line_no IN gl_aloc_bas.line_no%TYPE
111 )
112 RETURN BOOLEAN ;
113 --
114 PROCEDURE log_msg -- Bug 2659435: Removed first param for debug level
115 (
116 p_msg_text IN VARCHAR2
117 );
118 --
119 -- Bug 2659435: Added new procedure to log header message
120 PROCEDURE add_header_to_error_stack
121 (
122 p_header Allocation_Definition_Rec_Type
123 );
124 --
125
126 -- Global variables
127 G_PKG_NAME CONSTANT VARCHAR2(30) := 'GMF_AllocationDefinition_PUB';
128
129 -- Bug 2659435
130 G_operation VARCHAR2(30); -- values will be Insert, Update or Delete
131 G_tmp BOOLEAN := FND_MSG_PUB.Check_Msg_Level(0) ; -- temp call to initialize the
132 -- msg level threshhold gobal
133 -- variable.
134 G_debug_level NUMBER(2) := FND_MSG_PUB.G_Msg_Level_Threshold; -- Use this variable everywhere
135 -- to decide to log a debug msg.
136 G_header_logged VARCHAR2(1); -- to indicate whether header is already in
137 -- error stack or not - avoid logging duplicate headers
138
139 --Start of comments
140 --+========================================================================+
141 --| API Name : Create_Allocation_Definition |
142 --| TYPE : Public |
143 --| Function : Creates a new Allocation Definition based on the input |
144 --| into table GL_ALOC_BAS |
145 --| Pre-reqa : None. |
146 --| Parameters : |
147 --| IN : |
148 --| p_api_version IN NUMBER - Required |
149 --| p_init_msg_list IN VARCHAR2 - Optional |
150 --| p_commit IN VARCHAR2 - Optional |
151 --| p_allocation_definition_rec |
152 --| IN Allocation_Definition_Rec_Type |
153 --| OUT : |
154 --| x_return_status OUT VARCHAR2 |
155 --| x_msg_count OUT NUMBER |
156 --| x_msg_data OUT VARCHAR2 |
157 --| |
158 --| Version : |
159 --| Current Version : 3.0 |
160 --| Previous Version : 2.0 |
161 --| Initial Version : 1.0 |
162 --| |
163 --| Notes : |
164 --| |
165 --| HISTORY |
166 --| 01-Mar-01 Uday Moogala - Created |
167 --| |
168 --+========================================================================+
169 -- End of comments
170
171 PROCEDURE Create_Allocation_Definition
172 (
173 p_api_version IN NUMBER ,
174 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE ,
175 p_commit IN VARCHAR2 := FND_API.G_FALSE ,
176
177 x_return_status OUT NOCOPY VARCHAR2 ,
178 x_msg_count OUT NOCOPY NUMBER ,
179 x_msg_data OUT NOCOPY VARCHAR2 ,
180
181 p_allocation_definition_rec IN Allocation_Definition_Rec_Type
182 )
183 IS
184 l_api_name CONSTANT VARCHAR2(30) := 'Create_Allocation_Definition' ;
185 l_api_version CONSTANT NUMBER := 3.0 ;
186 l_alloc_def_rec Allocation_Definition_Rec_Type ;
187 l_user_id fnd_user.user_id%TYPE ;
188 l_return_status VARCHAR2(2) ;
189 l_count NUMBER(10) ;
190 l_data VARCHAR2(2000) ;
191 l_no_rows_ins NUMBER(10) ;
192
193 BEGIN
194
195
196 -- Standard Start of API savepoint
197 SAVEPOINT Create_Alloc_Definition_PUB;
198
199 -- Initialize message list if p_init_msg_list is set to TRUE.
200 IF FND_API.to_Boolean( p_init_msg_list ) THEN
201 FND_MSG_PUB.initialize;
202 END IF;
203
204 -- Standard call to check for call compatibility.
205 IF NOT FND_API.Compatible_API_Call ( l_api_version ,
206 p_api_version ,
207 l_api_name ,
208 G_PKG_NAME )
209 THEN
210 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
211 END IF;
212
213 -- Initialize API return status to success
214 x_return_status := FND_API.G_RET_STS_SUCCESS;
215
216 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
217 log_msg('Beginning Create Allocation Definition process.');
218 END IF;
219
220 G_operation := 'INSERT'; -- Bug 2659435
221 G_header_logged := 'N'; -- to indicate header is logged or not for errors
222
223 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
224 log_msg('Validating input parameters');
225 END IF;
226
227 -- Validate all the input parameters.
228 VALIDATE_INPUT_PARAMS
229 (p_alloc_def_rec => p_allocation_definition_rec,
230 x_alloc_def_rec => l_alloc_def_rec,
231 x_user_id => l_user_id,
232 x_return_status => l_return_status) ;
233
234 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
235 log_msg('Return Status after validating : ' || l_return_status);
236 END IF;
237
238 -- Return if validation failures detected
239 IF l_return_status = FND_API.G_RET_STS_ERROR
240 THEN
241 RAISE FND_API.G_EXC_ERROR;
242 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
243 THEN
244 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
245 END IF;
246
247 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
248 log_msg('Calling private API to insert record.');
249 END IF;
250
251 GMF_AllocationDefinition_PVT.Create_Allocation_Definition
252 ( p_api_version => 3.0
253 , p_init_msg_list => FND_API.G_FALSE
254 , p_commit => FND_API.G_FALSE
255
256 , x_return_status => l_return_status
257 , x_msg_count => l_count
258 , x_msg_data => l_data
259
260 , p_allocation_definition_rec => l_alloc_def_rec
261 , p_user_id => l_user_id
262 );
263
264 -- Return if insert fails for any reason
265 IF l_return_status = FND_API.G_RET_STS_ERROR
266 THEN
267 RAISE FND_API.G_EXC_ERROR;
268 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
269 THEN
270 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
271 END IF;
272
273 l_no_rows_ins := SQL%ROWCOUNT ;
274
275 IF l_alloc_def_rec.alloc_method = 1 THEN
276 IF NOT is_fxdpct_hundred(l_alloc_def_rec.alloc_id) THEN
277 add_header_to_error_stack(l_alloc_def_rec); -- Bug 2659435
278 FND_MESSAGE.SET_NAME('GMF','GMF_API_TOTAL_PCT_NOTHUNDRED');
279 FND_MESSAGE.SET_TOKEN('ALLOC_ID',l_alloc_def_rec.alloc_id);
280 FND_MSG_PUB.Add;
281 END IF;
282 END IF;
283
284 add_header_to_error_stack(l_alloc_def_rec); -- Bug 2659435
285 FND_MESSAGE.SET_NAME('GMF','GMF_API_ROWS_INS');
286 FND_MESSAGE.SET_TOKEN('NUM_ROWS',l_no_rows_ins);
287 FND_MSG_PUB.Add;
288
289 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
290 log_msg('1 row inserted');
291 END IF;
292
293 -- Standard check of p_commit.
294 IF FND_API.To_Boolean( p_commit ) THEN
295 COMMIT WORK;
296 END IF;
297
298 -- Standard call to get message count and if count is 1, get message info.
299 FND_MSG_PUB.Count_And_Get
300 ( p_count => x_msg_count ,
301 p_data => x_msg_data
302 );
303
304 EXCEPTION
305 WHEN FND_API.G_EXC_ERROR THEN
306 ROLLBACK TO Create_Alloc_Definition_PUB;
307 x_return_status := FND_API.G_RET_STS_ERROR ;
308 FND_MSG_PUB.Count_And_Get
309 ( p_count => x_msg_count ,
310 p_data => x_msg_data
311 );
312 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
313 ROLLBACK TO Create_Alloc_Definition_PUB;
314 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
315 FND_MSG_PUB.Count_And_Get
316 ( p_count => x_msg_count ,
317 p_data => x_msg_data
318 );
319 WHEN OTHERS THEN
320 ROLLBACK TO Create_Alloc_Definition_PUB;
321 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
322 IF FND_MSG_PUB.Check_Msg_Level
323 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
324 THEN
325 FND_MSG_PUB.Add_Exc_Msg
326 ( G_PKG_NAME ,
327 l_api_name
328 );
329 END IF;
330 FND_MSG_PUB.Count_And_Get
331 ( p_count => x_msg_count ,
332 p_data => x_msg_data
333 );
334
335 END Create_Allocation_Definition;
336
337
338 --Start of comments
339 --+========================================================================+
340 --| API Name : Update_Allocation_Definition |
341 --| TYPE : Public |
342 --| Function : Updates Allocation Definition based on the input |
343 --| into GL_ALOC_BAS |
344 --| Pre-reqa : None. |
345 --| Parameters : |
346 --| IN : |
347 --| p_api_version IN NUMBER - Required |
348 --| p_init_msg_list IN VARCHAR2 - Optional |
349 --| p_commit IN VARCHAR2 - Optional |
350 --| p_allocation_definition_rec |
351 --| IN Allocation_Definition_Rec_Type |
352 --| OUT : |
353 --| x_return_status OUT VARCHAR2 |
354 --| x_msg_count OUT NUMBER |
355 --| x_msg_data OUT VARCHAR2 |
356 --| |
357 --| Version : |
358 --| Current Version : 3.0 |
359 --| Previous Version : 2.0 |
360 --| Initial Version : 1.0 |
361 --| |
362 --| Notes : |
363 --| |
364 --| HISTORY |
365 --| 01-Mar-01 Uday Moogala - Created |
366 --| |
367 --+========================================================================+
368 -- End of comments
369
370 PROCEDURE Update_Allocation_Definition
371 (
372 p_api_version IN NUMBER ,
373 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE ,
374 p_commit IN VARCHAR2 := FND_API.G_FALSE ,
375
376 x_return_status OUT NOCOPY VARCHAR2 ,
377 x_msg_count OUT NOCOPY NUMBER ,
378 x_msg_data OUT NOCOPY VARCHAR2 ,
379
380 p_allocation_definition_rec IN Allocation_Definition_Rec_Type
381 )
382 IS
383 l_api_name CONSTANT VARCHAR2(30) := 'Update_Allocation_Definition' ;
384 l_api_version CONSTANT NUMBER := 3.0 ;
385 l_alloc_def_rec Allocation_Definition_Rec_Type ;
386 l_user_id fnd_user.user_id%TYPE ;
387 l_no_rows_upd NUMBER(10) ;
388 l_return_status VARCHAR2(2) ;
389 l_count NUMBER(10) ;
390 l_cnt NUMBER(10) ; -- used for validate basis account
391 l_data VARCHAR2(2000) ;
392
393 BEGIN
394 -- Standard Start of API savepoint
395 SAVEPOINT Update_Alloc_Definition_PUB;
396
397 -- Initialize message list if p_init_msg_list is set to TRUE.
398 IF FND_API.to_Boolean( p_init_msg_list ) THEN
399 FND_MSG_PUB.initialize;
400 END IF;
401
402 -- Standard call to check for call compatibility.
403 IF NOT FND_API.Compatible_API_Call ( l_api_version ,
404 p_api_version ,
405 l_api_name ,
406 G_PKG_NAME )
407 THEN
408 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
409 END IF;
410
411 -- Initialize API return status to success
412 x_return_status := FND_API.G_RET_STS_SUCCESS;
413
414 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
415 log_msg('Beginning Update Allocation Definition process.');
416 END IF;
417
418 G_operation := 'UPDATE'; -- Bug 2659435
419 G_header_logged := 'N'; -- to indicate header is logged or not for errors
420
421 --
422 -- Line Number.
423 -- Should be not null
424 --
425 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
426 log_msg('validating line_no : '||p_allocation_definition_rec.line_no);
427 END IF;
428
429 IF (p_allocation_definition_rec.line_no IS NULL) OR
430 (p_allocation_definition_rec.line_no = FND_API.G_MISS_NUM) THEN -- Bug 2659435
431 add_header_to_error_stack(p_allocation_definition_rec); -- Bug 2659435
432 FND_MESSAGE.SET_NAME('GMF','GMF_API_LINE_NO_REQ');
433 FND_MSG_PUB.Add;
434 RAISE FND_API.G_EXC_ERROR;
435 END IF;
436 -- End Line number
437
438 -- Validate all the input parameters.
439 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
440 log_msg('Validating input parameters');
441 END IF;
442
443 VALIDATE_INPUT_PARAMS
444 (p_alloc_def_rec => p_allocation_definition_rec,
445 x_alloc_def_rec => l_alloc_def_rec,
446 x_user_id => l_user_id,
447 x_return_status => l_return_status) ;
448
449 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
450 log_msg('Return Status after validating : ' || l_return_status);
451 END IF;
452
453 -- Return if validation failures detected
454 IF l_return_status = FND_API.G_RET_STS_ERROR
455 THEN
456 RAISE FND_API.G_EXC_ERROR;
457 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
458 THEN
459 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
460 END IF;
461
462 /*
463 -- Check whether any records exists for update
464 SELECT count(1)
465 INTO l_cnt
466 FROM gl_aloc_bas
467 WHERE alloc_id = l_alloc_def_rec.alloc_id
468 AND line_no = l_alloc_def_rec.line_no ;
469
470 IF l_cnt = 0 THEN
471 FND_MESSAGE.SET_NAME('GMF','GMF_API_NO_ROWS_FOUND');
472 FND_MESSAGE.SET_TOKEN('ALLOC_ID',l_alloc_def_rec.alloc_id);
473 FND_MESSAGE.SET_TOKEN('LINE_NO', l_alloc_def_rec.line_no);
474 FND_MSG_PUB.Add;
475 RAISE FND_API.G_EXC_ERROR;
476 END IF ;
477 */
478
479 -- Check whether any records exists for update
480 IF NOT check_record_exist(l_alloc_def_rec.alloc_id, l_alloc_def_rec.line_no) THEN
481 add_header_to_error_stack(l_alloc_def_rec); -- Bug 2659435
482 FND_MESSAGE.SET_NAME('GMF','GMF_API_NO_ROWS_FOUND');
483 FND_MESSAGE.SET_TOKEN('ALLOC_ID',l_alloc_def_rec.alloc_id);
484 FND_MESSAGE.SET_TOKEN('LINE_NO', l_alloc_def_rec.line_no);
485 FND_MSG_PUB.Add;
486 RAISE FND_API.G_EXC_ERROR;
487 END IF ;
488
489 IF l_alloc_def_rec.delete_mark = 1 THEN
490 add_header_to_error_stack(l_alloc_def_rec); -- Bug 2659435
491 FND_MESSAGE.SET_NAME('GMF','GMF_API_CANT_MARK_FOR_PURGE');
492 FND_MSG_PUB.Add;
493 RAISE FND_API.G_EXC_ERROR;
494 END IF ;
495
496 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
497 log_msg('Updating record for alloc_id : ' ||
498 l_alloc_def_rec.alloc_id || ' line_no : ' || l_alloc_def_rec.line_no);
499 END IF;
500
501 GMF_AllocationDefinition_PVT.Update_Allocation_Definition
502 ( p_api_version => 3.0
503 , p_init_msg_list => FND_API.G_FALSE
504 , p_commit => FND_API.G_FALSE
505
506 , x_return_status => l_return_status
507 , x_msg_count => l_count
508 , x_msg_data => l_data
509
510 , p_allocation_definition_rec => l_alloc_def_rec
511 , p_user_id => l_user_id
512 );
513
514 -- Return if insert fails for any reason
515 IF l_return_status = FND_API.G_RET_STS_ERROR
516 THEN
517 RAISE FND_API.G_EXC_ERROR;
518 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
519 THEN
520 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
521 END IF;
522
523 l_no_rows_upd := SQL%ROWCOUNT ;
524
525 IF l_alloc_def_rec.alloc_method = 1 THEN
526 IF NOT is_fxdpct_hundred(l_alloc_def_rec.alloc_id) THEN
527 add_header_to_error_stack(l_alloc_def_rec); -- Bug 2659435
528 FND_MESSAGE.SET_NAME('GMF','GMF_API_TOTAL_PCT_NOTHUNDRED');
529 FND_MESSAGE.SET_TOKEN('ALLOC_ID',l_alloc_def_rec.alloc_id);
530 FND_MSG_PUB.Add;
531 END IF;
532 END IF;
533
534 add_header_to_error_stack(l_alloc_def_rec); -- Bug 2659435
535 FND_MESSAGE.SET_NAME('GMF','GMF_API_ROWS_UPD');
536 FND_MESSAGE.SET_TOKEN('NUM_ROWS',l_no_rows_upd);
537 FND_MSG_PUB.Add;
538
539 --log_msg( l_no_rows_upd || ' rows updated.');
540
541 -- Standard check of p_commit.
542 IF FND_API.To_Boolean( p_commit ) THEN
543 COMMIT WORK;
544 END IF;
545
546 -- Standard call to get message count and if count is 1, get message info.
547 FND_MSG_PUB.Count_And_Get
548 ( p_count => x_msg_count ,
549 p_data => x_msg_data
550 );
551
552 EXCEPTION
553 WHEN FND_API.G_EXC_ERROR THEN
554 ROLLBACK TO Update_Alloc_Definition_PUB;
555 x_return_status := FND_API.G_RET_STS_ERROR ;
556 FND_MSG_PUB.Count_And_Get
557 ( p_count => x_msg_count ,
558 p_data => x_msg_data
559 );
560 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
561 ROLLBACK TO Update_Alloc_Definition_PUB;
562 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
563 FND_MSG_PUB.Count_And_Get
564 ( p_count => x_msg_count ,
565 p_data => x_msg_data
566 );
567 WHEN OTHERS THEN
568 ROLLBACK TO Update_Alloc_Definition_PUB;
569 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
570 IF FND_MSG_PUB.Check_Msg_Level
571 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
572 THEN
573 FND_MSG_PUB.Add_Exc_Msg
574 ( G_PKG_NAME ,
575 l_api_name
576 );
577 END IF;
578 FND_MSG_PUB.Count_And_Get
579 ( p_count => x_msg_count ,
580 p_data => x_msg_data
581 );
582
583 END Update_Allocation_Definition ;
584
585
586 --Start of comments
587 --+========================================================================+
588 --| API Name : Delete_Allocation_Definition |
589 --| TYPE : Public |
590 --| Function : Deletes Allocation Definition based on the input |
591 --| from GL_ALOC_BAS |
592 --| Pre-reqa : None. |
593 --| Parameters : |
594 --| IN : |
595 --| p_api_version IN NUMBER - Required |
596 --| p_init_msg_list IN VARCHAR2 - Optional |
597 --| p_commit IN VARCHAR2 - Optional |
598 --| p_allocation_definition_rec |
599 --| IN Allocation_Definition_Rec_Type |
600 --| OUT : |
601 --| x_return_status OUT VARCHAR2 |
602 --| x_msg_count OUT NUMBER |
603 --| x_msg_data OUT VARCHAR2 |
604 --| |
605 --| Version : |
606 --| Current Version : 3.0 |
607 --| Previous Version : 2.0 |
608 --| Initial Version : 1.0 |
609 --| |
610 --| Notes : |
611 --| |
612 --| HISTORY |
613 --| 01-Mar-01 Uday Moogala - Created |
614 --| |
615 --+========================================================================+
616 -- End of comments
617
618 PROCEDURE Delete_Allocation_Definition
619 (
620 p_api_version IN NUMBER ,
621 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE ,
622 p_commit IN VARCHAR2 := FND_API.G_FALSE ,
623
624 x_return_status OUT NOCOPY VARCHAR2 ,
625 x_msg_count OUT NOCOPY NUMBER ,
626 x_msg_data OUT NOCOPY VARCHAR2 ,
627
628 p_allocation_definition_rec IN Allocation_Definition_Rec_Type
629 )
630 IS
631 l_api_name CONSTANT VARCHAR2(30) := 'Delete_Allocation_Definition' ;
632 l_api_version CONSTANT NUMBER := 3.0 ;
633
634 l_alloc_def_rec Allocation_Definition_Rec_Type ;
635 l_user_id fnd_user.user_id%TYPE ;
636 l_no_rows_del NUMBER(10) ;
637 l_count NUMBER(10) ;
638 l_cnt NUMBER(10) ;
639 l_user_name fnd_user.user_name%TYPE ; --:= FND_API.G_MISS_CHAR ; Bug 2659435
640 l_return_status VARCHAR2(2) ;
641 l_data VARCHAR2(2000) ;
642
643 BEGIN
644
645 -- Standard Start of API savepoint
646 SAVEPOINT Delete_Alloc_Definition_PUB;
647
648 -- Initialize message list if p_init_msg_list is set to TRUE.
649 IF FND_API.to_Boolean( p_init_msg_list ) THEN
650 FND_MSG_PUB.initialize;
651 END IF;
652
653 -- Standard call to check for call compatibility.
654 IF NOT FND_API.Compatible_API_Call ( l_api_version ,
655 p_api_version ,
656 l_api_name ,
657 G_PKG_NAME )
658 THEN
659 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
660 END IF;
661
662 -- Initialize API return status to success
663 x_return_status := FND_API.G_RET_STS_SUCCESS;
664
665 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
666 log_msg('Beginning Delete Allocation Definition process.');
667 END IF;
668
669 G_header_logged := 'N'; -- Bug 2659435 to indicate header is logged or not for errors
670
671 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
672 log_msg('alloc_id : '|| p_allocation_definition_rec.alloc_id);
673 log_msg('alloc_code : '|| p_allocation_definition_rec.alloc_code);
674 log_msg('legal entity id : '|| p_allocation_definition_rec.legal_entity_id);
675 log_msg('line_no : '|| p_allocation_definition_rec.line_no);
676 log_msg('user name : ' || p_allocation_definition_rec.user_name);
677 log_msg('Validating input parameters');
678 END IF;
679
680 --
681 -- Line Number.
682 -- Should be not null
683 --
684 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
685 log_msg('validating line_no : '||p_allocation_definition_rec.line_no);
686 END IF;
687
688 IF (p_allocation_definition_rec.line_no IS NULL) OR
689 (p_allocation_definition_rec.line_no = FND_API.G_MISS_NUM) THEN -- Bug 2659435
690 add_header_to_error_stack(p_allocation_definition_rec); -- Bug 2659435
691 FND_MESSAGE.SET_NAME('GMF','GMF_API_LINE_NO_REQ');
692 FND_MSG_PUB.Add;
693 RAISE FND_API.G_EXC_ERROR;
694 ELSE
695 l_alloc_def_rec.line_no := p_allocation_definition_rec.line_no ;
696 END IF;
697 -- End Line number
698
699 --
700 -- Allocation Id
701 --
702 -- Use alloc_id if sent otherwise use Alloc_code and legal_entity_id
703 -- If both are sent then use only alloc_id and ignore other params and log a message
704 -- If both are not sent then raise error.
705 --
706 IF (p_allocation_definition_rec.alloc_id <> FND_API.G_MISS_NUM) AND
707 (p_allocation_definition_rec.alloc_id IS NOT NULL) THEN
708 -- validate alloc_id
709 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
710 log_msg('validating alloc_id : '||
711 p_allocation_definition_rec.alloc_id);
712 END IF;
713
714 IF NOT GMF_VALIDATIONS_PVT.Validate_Alloc_Id(p_allocation_definition_rec.alloc_id) THEN
715 add_header_to_error_stack(p_allocation_definition_rec); -- Bug 2659435
716 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_ALLOC_ID');
717 FND_MESSAGE.SET_TOKEN('ALLOC_ID',p_allocation_definition_rec.alloc_id);
718 FND_MSG_PUB.Add;
719 RAISE FND_API.G_EXC_ERROR;
720 END IF;
721
722 l_alloc_def_rec.alloc_id := p_allocation_definition_rec.alloc_id ;
723
724 -- Log message if alloc_code and company is also passed
725 IF ((p_allocation_definition_rec.alloc_code <> FND_API.G_MISS_CHAR) AND
726 (p_allocation_definition_rec.alloc_code IS NOT NULL)) OR
727 ((p_allocation_definition_rec.legal_entity_id <> FND_API.G_MISS_NUM) AND
728 (p_allocation_definition_rec.legal_entity_id IS NOT NULL))
729 THEN
730 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
731 add_header_to_error_stack(p_allocation_definition_rec); -- Bug 2659435
732 FND_MESSAGE.SET_NAME('GMF','GMF_API_IGNORE_ALLOC_CODE');
733 FND_MESSAGE.SET_TOKEN('ALLOC_CODE',p_allocation_definition_rec.alloc_code);
734 FND_MESSAGE.SET_TOKEN('LEGAL_ENTITY',p_allocation_definition_rec.LEGAL_ENTITY_ID);
735 FND_MSG_PUB.Add;
736 END IF;
737 END IF;
738 ELSIF ((p_allocation_definition_rec.alloc_code <> FND_API.G_MISS_CHAR) AND
739 (p_allocation_definition_rec.alloc_code IS NOT NULL)) AND
740 ((p_allocation_definition_rec.LEGAL_ENTITY_ID <> FND_API.G_MISS_NUM) AND
741 (p_allocation_definition_rec.alloc_code IS NOT NULL)) THEN
742
743 -- Convert value into ID.
744
745 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
746 log_msg(
747 'Fetching alloc_id using alloc_code : '|| p_allocation_definition_rec.alloc_code ||
748 ' legal entity : '|| p_allocation_definition_rec.legal_entity_id);
749 END IF;
750
751 l_alloc_def_rec.alloc_id := GMF_VALIDATIONS_PVT.Fetch_Alloc_Id(
752 p_allocation_definition_rec.alloc_code,
753 p_allocation_definition_rec.legal_entity_id);
754
755 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
756 log_msg('alloc_id : '|| l_alloc_def_rec.alloc_id);
757 END IF;
758
759 IF l_alloc_def_rec.alloc_id IS NULL THEN -- Alloc_Id fetch was not successful
760 -- Conversion failed.
761 add_header_to_error_stack(l_alloc_def_rec); -- Bug 2659435
762 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_ALLOC_CODE');
763 FND_MESSAGE.SET_TOKEN('ALLOC_CODE',p_allocation_definition_rec.alloc_code);
764 FND_MESSAGE.SET_TOKEN('LEGAL_ENTITY',p_allocation_definition_rec.legal_entity_id);
765 FND_MSG_PUB.Add;
766 RAISE FND_API.G_EXC_ERROR;
767 END IF;
768 ELSE
769 add_header_to_error_stack(p_allocation_definition_rec); -- Bug 2659435
770 FND_MESSAGE.SET_NAME('GMF','GMF_API_ALLOC_DTL_REQ');
771 FND_MSG_PUB.Add;
772 RAISE FND_API.G_EXC_ERROR;
773 END IF;
774 -- End Allocation Id
775
776 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
777 log_msg('validating user_name : '|| p_allocation_definition_rec.user_name);
778 END IF;
779
780 IF (p_allocation_definition_rec.user_name <> FND_API.G_MISS_CHAR) AND
781 (p_allocation_definition_rec.user_name IS NOT NULL) THEN
782 GMA_GLOBAL_GRP.Get_who( p_user_name => p_allocation_definition_rec.user_name
783 , x_user_id => l_user_id
784 );
785 IF l_user_id = -1 THEN -- Bug 2681243: GMA changed return status value to -1.
786 add_header_to_error_stack(p_allocation_definition_rec); -- Bug 2659435
787 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_USER_NAME');
788 FND_MESSAGE.SET_TOKEN('USER_NAME',p_allocation_definition_rec.user_name);
789 FND_MSG_PUB.Add;
790 RAISE FND_API.G_EXC_ERROR;
791 ELSE
792 l_alloc_def_rec.user_name := p_allocation_definition_rec.user_name;
793 END IF;
794 ELSE
795 add_header_to_error_stack(p_allocation_definition_rec); -- Bug 2659435
796 FND_MESSAGE.SET_NAME('GMF','GMF_API_USER_NAME_REQ');
797 FND_MSG_PUB.Add;
798 RAISE FND_API.G_EXC_ERROR;
799 END IF;
800 -- End User Name
801
802
803 /*
804 -- Check whether any records exists to delete
805 SELECT count(1)
806 INTO l_cnt
807 FROM gl_aloc_bas
808 WHERE alloc_id = l_alloc_def_rec.alloc_id
809 AND line_no = l_alloc_def_rec.line_no ;
810
811 IF l_cnt = 0 THEN
812 add_header_to_error_stack(l_alloc_def_rec); -- Bug 2659435
813 FND_MESSAGE.SET_NAME('GMF','GMF_API_NO_ROWS_FOUND');
814 FND_MESSAGE.SET_TOKEN('ALLOC_ID',l_alloc_def_rec.alloc_id);
815 FND_MESSAGE.SET_TOKEN('LINE_NO', l_alloc_def_rec.line_no);
816 FND_MSG_PUB.Add;
817 RAISE FND_API.G_EXC_ERROR;
818 END IF ;
819 */
820
821 -- Check whether any records exists for update
822 IF NOT check_record_exist(l_alloc_def_rec.alloc_id, l_alloc_def_rec.line_no) THEN
823 add_header_to_error_stack(l_alloc_def_rec); -- Bug 2659435
824 FND_MESSAGE.SET_NAME('GMF','GMF_API_NO_ROWS_FOUND');
825 FND_MESSAGE.SET_TOKEN('ALLOC_ID',l_alloc_def_rec.alloc_id);
826 FND_MESSAGE.SET_TOKEN('LINE_NO', l_alloc_def_rec.line_no);
827 FND_MSG_PUB.Add;
828 RAISE FND_API.G_EXC_ERROR;
829 END IF ;
830
831 l_alloc_def_rec.delete_mark := 1;
832
833 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
834 log_msg('deleteing record for alloc_id : ' ||
835 l_alloc_def_rec.alloc_id ||' line_no : ' || l_alloc_def_rec.line_no);
836 END IF;
837
838 GMF_AllocationDefinition_PVT.Update_Allocation_Definition
839 ( p_api_version => 3.0
840 , p_init_msg_list => FND_API.G_FALSE
841 , p_commit => FND_API.G_FALSE
842
843 , x_return_status => l_return_status
844 , x_msg_count => l_count
845 , x_msg_data => l_data
846
847 , p_allocation_definition_rec => l_alloc_def_rec
848 , p_user_id => l_user_id
849 );
850
851 -- Return if insert fails for any reason
852 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
853 RAISE FND_API.G_EXC_ERROR;
854 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
855 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
856 END IF;
857
858 l_no_rows_del := SQL%ROWCOUNT ;
859
860 IF p_allocation_definition_rec.alloc_method = 1 THEN
861 IF NOT is_fxdpct_hundred(l_alloc_def_rec.alloc_id) THEN
862 add_header_to_error_stack(l_alloc_def_rec); -- Bug 2659435
863 FND_MESSAGE.SET_NAME('GMF','GMF_API_TOTAL_PCT_NOTHUNDRED');
864 FND_MESSAGE.SET_TOKEN('ALLOC_ID',l_alloc_def_rec.alloc_id);
865 FND_MSG_PUB.Add;
866 END IF;
867 END IF;
868
869 add_header_to_error_stack(l_alloc_def_rec); -- Bug 2659435
870 FND_MESSAGE.SET_NAME('GMF','GMF_API_ROWS_DEL');
871 FND_MESSAGE.SET_TOKEN('NUM_ROWS',l_no_rows_del);
872 FND_MSG_PUB.Add;
873
874 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
875 log_msg(l_no_rows_del || ' rows deleted.');
876 END IF;
877
878 -- Standard check of p_commit.
879 IF FND_API.To_Boolean( p_commit ) THEN
880 COMMIT WORK;
881 END IF;
882
883 -- Standard call to get message count and if count is 1, get message info.
884 FND_MSG_PUB.Count_And_Get
885 ( p_count => x_msg_count ,
886 p_data => x_msg_data
887 );
888
889 EXCEPTION
890 WHEN FND_API.G_EXC_ERROR THEN
891 ROLLBACK TO Delete_Alloc_Definition_PUB;
892 x_return_status := FND_API.G_RET_STS_ERROR ;
893 FND_MSG_PUB.Count_And_Get
894 ( p_count => x_msg_count ,
895 p_data => x_msg_data
896 );
897 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
898 ROLLBACK TO Delete_Alloc_Definition_PUB;
899 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
900 FND_MSG_PUB.Count_And_Get
901 ( p_count => x_msg_count ,
902 p_data => x_msg_data
903 );
904 WHEN OTHERS THEN
905 ROLLBACK TO Delete_Alloc_Definition_PUB;
906 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
907 IF FND_MSG_PUB.Check_Msg_Level
908 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
909 THEN
910 FND_MSG_PUB.Add_Exc_Msg
911 ( G_PKG_NAME ,
912 l_api_name
913 );
914 END IF;
915 FND_MSG_PUB.Count_And_Get
916 ( p_count => x_msg_count ,
917 p_data => x_msg_data
918 );
919
920 END Delete_Allocation_Definition ;
921
922 -- Proc start of comments
923 --+==========================================================================+
924 --| PROCEDURE NAME |
925 --| Validate_Input_Params |
926 --| |
927 --| DESCRIPTION |
928 --| Validates all the input parameters. |
929 --| |
930 --| PARAMETERS |
931 --| p_allocation_definition_rec IN Allocation_Definition_Rec_Type |
932 --| x_return_status OUT VARCHAR2 |
933 --| |
934 --| RETURNS |
935 --| TRUE - If succesfully initialized all variables |
936 --| FALSE - If any error |
937 --| |
938 --| HISTORY |
939 --| 27/02/2001 Uday Moogla - Created |
940 --| |
941 --+==========================================================================+
942 -- Proc end of comments
943
944 PROCEDURE Validate_Input_Params
945 (
946 p_alloc_def_rec IN Allocation_Definition_Rec_Type
947 ,x_alloc_def_rec OUT NOCOPY Allocation_Definition_Rec_Type
948 ,x_user_id OUT NOCOPY fnd_user.user_id%TYPE
949 ,x_return_status OUT NOCOPY VARCHAR2
950 )
951 IS
952 -- Bug 2659435. Commented all default assignments to increase performance.
953 l_Alloc_id NUMBER ; -- := FND_API.G_MISS_NUM ;
954 l_alloc_code gl_aloc_mst.alloc_code%TYPE ; -- := FND_API.G_MISS_CHAR ;
955 l_legal_entity_id gmf_legal_entities.legal_entity_id%TYPE ; -- := FND_API.G_MISS_CHAR ;
956 l_alloc_method NUMBER ; -- := FND_API.G_MISS_NUM ;
957 l_line_no NUMBER ; -- := FND_API.G_MISS_NUM ;
958 l_Item_Id NUMBER ; -- := FND_API.G_MISS_NUM ;
959 l_item_number mtl_item_flexfields.item_number%TYPE ; -- := FND_API.G_MISS_CHAR ;
960 l_basis_account_id gl_aloc_bas.basis_account_id%TYPE ;
961 l_basis_account_key gl_aloc_bas.basis_account_key%TYPE ; -- := FND_API.G_MISS_CHAR ;
962 l_balance_type NUMBER ; -- := FND_API.G_MISS_NUM ;
963 l_bas_ytd_ptd NUMBER ; -- := FND_API.G_MISS_NUM ;
964 l_basis_type NUMBER;
965 l_fixed_percent NUMBER ; -- := FND_API.G_MISS_NUM ;
966 l_cmpntcls_id NUMBER ; -- := FND_API.G_MISS_NUM ;
967 l_cost_cmpntcls_code cm_cmpt_mst.cost_cmpntcls_code%TYPE ; -- := FND_API.G_MISS_CHAR ;
968 l_analysis_code cm_alys_mst.cost_analysis_code%TYPE ; -- := FND_API.G_MISS_CHAR ;
969 l_organization_id NUMBER ; -- := FND_API.G_MISS_CHAR ;
970 l_delete_mark NUMBER ; -- := FND_API.G_MISS_NUM ;
971 l_user_name fnd_user.user_name%TYPE ; -- := FND_API.G_MISS_CHAR ;
972 l_user_id NUMBER ; -- := FND_API.G_MISS_NUM ;
973 l_usage_ind cm_cmpt_mst.usage_ind%TYPE ;
974 l_status NUMBER(2) ; -- used for validate basis account
975 l_organization_code mtl_parameters.organization_code%TYPE;
976
977
978 BEGIN
979
980 -- Initialize API return status to success
981 x_return_status := FND_API.G_RET_STS_SUCCESS;
982
983 l_Alloc_id := p_alloc_def_rec.Alloc_id ;
984 l_alloc_code := p_alloc_def_rec.alloc_code ;
985 l_legal_entity_id := p_alloc_def_rec.legal_entity_id ;
986 l_alloc_method := p_alloc_def_rec.alloc_method ;
987 l_line_no := p_alloc_def_rec.line_no ;
988 l_Item_Id := p_alloc_def_rec.Item_Id ;
989 l_item_number := p_alloc_def_rec.item_number ;
990 l_basis_account_id := p_alloc_def_rec.basis_account_id ;
991 l_basis_account_key := p_alloc_def_rec.basis_account_key ;
992 l_balance_type := p_alloc_def_rec.balance_type ;
993 l_bas_ytd_ptd := p_alloc_def_rec.bas_ytd_ptd ;
994 l_basis_type := p_alloc_def_rec.basis_type ;
995 l_fixed_percent := p_alloc_def_rec.fixed_percent ;
996 l_cmpntcls_id := p_alloc_def_rec.cmpntcls_id ;
997 l_cost_cmpntcls_code := p_alloc_def_rec.cost_cmpntcls_code ;
998 l_analysis_code := p_alloc_def_rec.analysis_code ;
999 l_organization_id := p_alloc_def_rec.organization_id ;
1000 l_organization_code := p_alloc_def_rec.organization_code;
1001 l_delete_mark := p_alloc_def_rec.delete_mark ;
1002 l_user_name := p_alloc_def_rec.user_name ;
1003
1004 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1005 log_msg('alloc_id : '|| l_alloc_id);
1006 log_msg('alloc_code : '|| l_alloc_code);
1007 log_msg('legal_entity_id: '|| l_legal_entity_id);
1008 log_msg('alloc_mthd : '||l_alloc_method);
1009 log_msg('line_no : '||l_line_no);
1010 log_msg('item_id : ' || l_item_id);
1011 log_msg('item_number : ' || l_item_number);
1012 log_msg('Basis Acct : '|| l_Basis_account_key);
1013 log_msg('Balance Type : '|| l_balance_type);
1014 log_msg('Basis YTP/PTD : '|| l_bas_ytd_ptd);
1015 log_msg('basis type : '||l_basis_type);
1016 log_msg('fixed % : '||l_fixed_percent);
1017 log_msg('Cmpt Cls ID : '|| l_cmpntcls_id);
1018 log_msg('Cmpt Cls Code : '|| l_cost_cmpntcls_code);
1019 log_msg('analysis_code : ' || l_analysis_code);
1020 log_msg('organization_id : ' || l_organization_id);
1021 log_msg('delete_mark : ' || l_delete_mark);
1022 log_msg('user name : ' || l_user_name);
1023 END IF;
1024
1025 --
1026 -- Allocation Id
1027 --
1028 -- Use alloc_id if sent otherwise use Alloc_code and legal_entity_id
1029 -- If both are sent then use only alloc_id and ignore other params and log a message
1030 -- If both are not sent then raise error.
1031 --
1032
1033 IF (l_alloc_id <> FND_API.G_MISS_NUM) AND
1034 (l_alloc_id IS NOT NULL) THEN
1035 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1036 log_msg('validating alloc_id : '|| l_alloc_id);
1037 END IF;
1038
1039 -- validate alloc_id
1040 IF NOT GMF_VALIDATIONS_PVT.Validate_Alloc_Id(l_alloc_id) THEN
1041 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1042 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_ALLOC_ID');
1043 FND_MESSAGE.SET_TOKEN('ALLOC_ID',l_alloc_id);
1044 FND_MSG_PUB.Add;
1045 RAISE FND_API.G_EXC_ERROR;
1046 END IF;
1047
1048 SELECT legal_entity_id
1049 INTO l_legal_entity_id
1050 FROM gl_aloc_mst
1051 WHERE alloc_id = l_alloc_id ;
1052
1053 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1054 log_msg('legal_entity_id : '|| l_legal_entity_id);
1055 END IF;
1056
1057 -- Log message if alloc_code and company is also passed
1058 IF ((l_alloc_code <> FND_API.G_MISS_CHAR) AND
1059 (l_alloc_code IS NOT NULL)) OR
1060 ((p_alloc_def_rec.legal_entity_id <> FND_API.G_MISS_NUM) AND
1061 (p_alloc_def_rec.legal_entity_id IS NOT NULL)) THEN
1062 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
1063 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1064 FND_MESSAGE.SET_NAME('GMF','GMF_API_IGNORE_ALLOC_CODE');
1065 FND_MESSAGE.SET_TOKEN('ALLOC_CODE',l_alloc_code);
1066 FND_MESSAGE.SET_TOKEN('LEGAL_ENTITY',p_alloc_def_rec.legal_entity_id);
1067 FND_MSG_PUB.Add;
1068 --RAISE FND_API.G_EXC_ERROR;
1069 END IF;
1070 END IF;
1071 ELSIF ((l_alloc_code <> FND_API.G_MISS_CHAR) AND
1072 (l_alloc_code IS NOT NULL)) AND
1073 ((l_legal_entity_id <> FND_API.G_MISS_NUM) AND
1074 (l_legal_entity_id IS NOT NULL)) THEN
1075
1076
1077 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1078 log_msg('Fetching alloc_id using alloc_code : '||
1079 l_alloc_code || ' legal_entity_id : '|| l_legal_entity_id);
1080 END IF;
1081
1082 -- Convert value into ID.
1083 l_alloc_id := GMF_VALIDATIONS_PVT.Fetch_Alloc_Id(l_alloc_code,
1084 l_legal_entity_id);
1085
1086 IF l_alloc_id IS NULL THEN -- Alloc_Id fetch was not successful
1087 -- Conversion failed.
1088 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1089 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_ALLOC_CODE');
1090 FND_MESSAGE.SET_TOKEN('ALLOC_CODE',l_alloc_code);
1091 FND_MESSAGE.SET_TOKEN('LEGAL_ENTITY',l_legal_entity_id);
1092 FND_MSG_PUB.Add;
1093 RAISE FND_API.G_EXC_ERROR;
1094 END IF;
1095 ELSE
1096 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1097 FND_MESSAGE.SET_NAME('GMF','GMF_API_ALLOC_DTL_REQ');
1098 FND_MSG_PUB.Add;
1099 RAISE FND_API.G_EXC_ERROR;
1100 END IF;
1101 -- End Allocation Id
1102
1103 --
1104 -- Allocation Method
1105 -- Should be 0 or 1
1106 --
1107 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1108 log_msg('validating alloc_mthd : '||l_alloc_method);
1109 END IF;
1110
1111 IF (l_alloc_method <> FND_API.G_MISS_NUM) AND
1112 (l_alloc_method IS NOT NULL) THEN
1113 IF (l_alloc_method NOT IN (0,1)) THEN
1114 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1115 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_ALLOC_MTHD');
1116 FND_MESSAGE.SET_TOKEN('ALLOC_METHOD',l_alloc_method);
1117 FND_MSG_PUB.Add;
1118 RAISE FND_API.G_EXC_ERROR;
1119 END IF;
1120 ELSE
1121 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1122 FND_MESSAGE.SET_NAME('GMF','GMF_API_ALLOC_MTHD_REQ');
1123 FND_MSG_PUB.Add;
1124 RAISE FND_API.G_EXC_ERROR;
1125 END IF;
1126 -- End Allocation Method
1127
1128 --
1129 -- Checks whether alloc def already exists or not. If exist, compare alloc_method.
1130 -- If alloc_method differs raise error.
1131 -- Bug 2659435: was above alloc method check
1132 --
1133 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1134 log_msg('checking for consistency of alloc method...');
1135 END IF;
1136
1137 IF NOT check_alloc_def(l_alloc_id, l_alloc_method) THEN
1138 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1139 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_ALLOC_DEF');
1140 FND_MESSAGE.SET_TOKEN('ALLOC_METHOD',l_alloc_method);
1141 FND_MSG_PUB.Add;
1142 RAISE FND_API.G_EXC_ERROR;
1143 END IF ;
1144
1145 --Organization Validation
1146 IF (l_organization_id <> FND_API.G_MISS_NUM)
1147 AND (l_organization_id IS NOT NULL)
1148 THEN
1149 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level
1150 THEN
1151 log_msg('Validating organization id: ' || l_organization_id);
1152 END IF;
1153
1154 IF NOT GMF_VALIDATIONS_PVT.Validate_organization_Id(l_organization_id)
1155 THEN
1156 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_ORGN_ID');
1157 FND_MESSAGE.SET_TOKEN('ORGANIZATION_ID',l_organization_id);
1158 FND_MSG_PUB.Add;
1159 RAISE FND_API.G_EXC_ERROR;
1160 END IF;
1161
1162 -- Log message if organization_code is also passed
1163 IF (l_organization_code <> FND_API.G_MISS_CHAR) AND (l_organization_code IS NOT NULL)
1164 THEN
1165
1166 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS)
1167 THEN
1168
1169 FND_MESSAGE.SET_NAME('GMF','GMF_API_IGNORE_ORGN_CODE');
1170 FND_MESSAGE.SET_TOKEN('ORG_CODE',l_organization_code);
1171 FND_MSG_PUB.Add;
1172
1173 END IF;
1174 END IF;
1175 ELSIF ((l_organization_code <> FND_API.G_MISS_CHAR)AND (l_organization_code IS NOT NULL))
1176 THEN
1177
1178 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level
1179 THEN
1180 log_msg('Validating Organization Code : ' || l_organization_code);
1181 END IF;
1182
1183 l_organization_id := gmf_validations_pvt.validate_organization_code(l_organization_code);
1184
1185 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level
1186 THEN
1187 log_msg('organization_id : ' || l_organization_id);
1188 END IF;
1189
1190 IF l_organization_id IS NULL
1191 THEN
1192 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_ORGN_CODE');
1193 FND_MESSAGE.SET_TOKEN('ORGANIZATION_CODE',l_organization_code);
1194 FND_MSG_PUB.Add;
1195 RAISE FND_API.G_EXC_ERROR;
1196 END IF;
1197 ELSE
1198
1199 FND_MESSAGE.SET_NAME('GMF','GMF_API_ORGN_ID_REQ');
1200 FND_MSG_PUB.Add;
1201 RAISE FND_API.G_EXC_ERROR;
1202 END IF;
1203
1204
1205
1206 --
1207 -- Item Id
1208 --
1209 -- Use item_id if sent otherwise use item_number
1210 -- If both are sent then use only item_id and ignore other params and log a message
1211 -- If both are not sent then raise error.
1212 --
1213 IF (l_item_id <> FND_API.G_MISS_NUM) AND
1214 (l_item_id IS NOT NULL) THEN
1215 -- validate item_id
1216 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1217 log_msg('validating item_id : ' || l_item_id);
1218 END IF;
1219
1220 IF NOT GMF_VALIDATIONS_PVT.Validate_inventory_item_Id(l_item_id,l_organization_id) THEN
1221 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1222 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_ITEM_ID');
1223 FND_MESSAGE.SET_TOKEN('ITEM_ID',l_item_id);
1224 FND_MESSAGE.SET_TOKEN('ORGANIZATION_ID',l_organization_id);
1225 FND_MSG_PUB.Add;
1226 RAISE FND_API.G_EXC_ERROR;
1227 END IF;
1228
1229 -- Log message if item_number is also passed
1230 IF (l_item_number <> FND_API.G_MISS_CHAR) AND
1231 (l_item_number IS NOT NULL) THEN
1232 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
1233 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1234 FND_MESSAGE.SET_NAME('GMF','GMF_API_IGNORE_ITEM_NO');
1235 FND_MESSAGE.SET_TOKEN('ITEM_NO',l_item_number);
1236 FND_MSG_PUB.Add;
1237 END IF;
1238 END IF;
1239 ELSIF (l_item_number <> FND_API.G_MISS_CHAR) AND
1240 (l_item_number IS NOT NULL) THEN
1241 -- Convert value into ID.
1242 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1243 log_msg('validating item_number : ' || l_item_number);
1244 END IF;
1245
1246 l_item_id := GMF_VALIDATIONS_PVT.Validate_Item_Number(l_item_number,l_organization_id);
1247 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1248 log_msg('item_id : ' || l_item_id);
1249 END IF;
1250
1251 IF l_item_id IS NULL THEN -- item_Id fetch was not successful
1252 -- Conversion failed.
1253 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1254 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_ITEM_NO');
1255 FND_MESSAGE.SET_TOKEN('ITEM_NO',l_item_number);
1256 FND_MESSAGE.SET_TOKEN('ORGANIZATION_ID',l_organization_id);
1257 FND_MSG_PUB.Add;
1258 RAISE FND_API.G_EXC_ERROR;
1259 END IF;
1260 ELSIF (l_item_number = FND_API.G_MISS_CHAR AND -- Bug 2659435
1261 G_operation = 'UPDATE') OR
1262 (G_operation = 'INSERT') THEN
1263 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1264 FND_MESSAGE.SET_NAME('GMF','GMF_API_ITEM_ID_REQ');
1265 FND_MSG_PUB.Add;
1266 RAISE FND_API.G_EXC_ERROR;
1267 END IF;
1268 -- End Item Id
1269
1270 --
1271 -- Basis Account Key and Balance Type
1272 -- Validate only when alloc_method = 0 else null.
1273 --
1274 IF l_alloc_method = 0 THEN
1275 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1276 log_msg('validating Basis Acct : '|| l_Basis_account_key);
1277 END IF;
1278
1279 -- Validate Basis Account Key
1280 IF (l_basis_account_id <> FND_API.G_MISS_NUM)
1281 AND (l_basis_account_id IS NOT NULL)
1282 THEN
1283 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level
1284 THEN
1285 log_msg('Validating basis_account_id: ' || l_basis_account_id);
1286 END IF;
1287
1288 IF NOT GMF_VALIDATIONS_PVT.Validate_account_Id(l_basis_account_id,l_legal_entity_id)
1289 THEN
1290 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_ACCT_ID');
1291 FND_MESSAGE.SET_TOKEN('ACCOUNT_ID',l_basis_account_id);
1292 FND_MSG_PUB.Add;
1293 RAISE FND_API.G_EXC_ERROR;
1294 END IF;
1295
1296
1297 IF (l_basis_account_key <> FND_API.G_MISS_CHAR) AND (l_basis_account_key IS NOT NULL)
1298 THEN
1299
1300 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS)
1301 THEN
1302
1303 FND_MESSAGE.SET_NAME('GMF','GMF_API_IGNORE_ACCT_KEY');
1304 FND_MESSAGE.SET_TOKEN('ACCT_KEY',l_basis_account_key);
1305 FND_MSG_PUB.Add;
1306
1307 END IF;
1308 END IF;
1309 ELSIF (l_Basis_account_key <> FND_API.G_MISS_CHAR) AND
1310 (l_Basis_account_key IS NOT NULL) THEN
1311
1312 l_basis_account_id := GMF_VALIDATIONS_PVT.Validate_Basis_account_key(l_Basis_account_key, l_legal_entity_id) ;
1313
1314 IF l_basis_account_id IS NULL THEN -- error in acctg_unit_no
1315 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1316 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_ACCT_NO');
1317 FND_MESSAGE.SET_TOKEN('BAS_ACC_KEY',l_Basis_account_key);
1318 FND_MSG_PUB.Add;
1319 RAISE FND_API.G_EXC_ERROR;
1320 END IF;
1321 ELSIF (l_basis_account_key = FND_API.G_MISS_CHAR AND G_operation = 'UPDATE') OR
1322 (G_operation = 'INSERT') THEN
1323 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1324 FND_MESSAGE.SET_NAME('GMF','GMF_API_ACCOUNT_ID_REQ');
1325 FND_MSG_PUB.Add;
1326 RAISE FND_API.G_EXC_ERROR;
1327 END IF;
1328 -- End Basis Account Key
1329
1330 --
1331 -- Balance Type must be 0 = Statistical; 1 = Budget; or 2 = Actual
1332 --
1333 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1334 log_msg('validating Balance Type :'|| l_balance_type);
1335 END IF;
1336
1337 IF (l_balance_type <> FND_API.G_MISS_NUM) AND
1338 (l_balance_type IS NOT NULL) THEN
1339 -- validate Basis Acct Key
1340 IF (l_balance_type NOT IN (0,1,2) ) THEN
1341 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1342 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_BALANCE_TYPE');
1343 FND_MESSAGE.SET_TOKEN('BALANCE_TYPE',l_balance_type);
1344 FND_MSG_PUB.Add;
1345 RAISE FND_API.G_EXC_ERROR;
1346 END IF;
1347 ELSIF (l_balance_type = FND_API.G_MISS_NUM AND -- Bug 2659435
1348 G_operation = 'UPDATE') OR
1349 (G_operation = 'INSERT') THEN
1350 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1351 FND_MESSAGE.SET_NAME('GMF','GMF_API_BALANCE_TYPE_REQ');
1352 FND_MSG_PUB.Add;
1353 RAISE FND_API.G_EXC_ERROR;
1354 END IF;
1355 -- End Balance Type
1356
1357 --
1358 -- Basis YTP/PTD must be either 0 = Period To Date Basis Amount or
1359 -- 1 = Year To Date Basis Amount
1360 --
1361 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1362 log_msg('validating Basis YTP/PTD :'|| l_bas_ytd_ptd);
1363 END IF;
1364
1365 IF (l_bas_ytd_ptd <> FND_API.G_MISS_NUM) AND
1366 (l_bas_ytd_ptd IS NOT NULL) THEN
1367 -- validate Basis YTP/PTD
1368 IF (l_bas_ytd_ptd NOT IN (0,1) ) THEN
1369 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1370 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_BAS_YTD_PTD');
1371 FND_MESSAGE.SET_TOKEN('BAS_YTD_PTD',l_bas_ytd_ptd);
1372 FND_MSG_PUB.Add;
1373 RAISE FND_API.G_EXC_ERROR;
1374 END IF;
1375 ELSIF (l_bas_ytd_ptd = FND_API.G_MISS_NUM AND -- Bug 2659435
1376 G_operation = 'UPDATE') OR
1377 (G_operation = 'INSERT') THEN
1378 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1379 FND_MESSAGE.SET_NAME('GMF','GMF_API_BAS_YTD_PTD_REQ');
1380 FND_MSG_PUB.Add;
1381 RAISE FND_API.G_EXC_ERROR;
1382 END IF;
1383 -- End Basis YTP/PTD
1384
1385 IF (l_basis_type <> FND_API.G_MISS_NUM) AND
1386 (l_basis_type IS NOT NULL) THEN
1387 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
1388 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1389 FND_MESSAGE.SET_NAME('GMF','GMF_API_IGNORE_BASIS_TYPE');
1390 FND_MESSAGE.SET_TOKEN('BASIS_TYPE',l_basis_type);
1391 FND_MSG_PUB.Add;
1392 END IF;
1393 END IF;
1394 IF (l_fixed_percent <> FND_API.G_MISS_NUM) AND
1395 (l_fixed_percent IS NOT NULL) THEN
1396 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
1397 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1398 FND_MESSAGE.SET_NAME('GMF','GMF_API_IGNORE_FIXED_PERCENT');
1399 FND_MESSAGE.SET_TOKEN('FIXED_PERCENT',l_fixed_percent);
1400 FND_MSG_PUB.Add;
1401 END IF;
1402 END IF;
1403
1404 ELSE -- method = 1
1405 l_basis_account_key := '' ;
1406 l_balance_type := '' ;
1407 l_bas_ytd_ptd := '' ;
1408 END IF;
1409
1410 --
1411 -- Fixed percentage - Used only when Allocation Method = 1
1412 --
1413 IF l_alloc_method = 1 THEN
1414 --
1415
1416 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1417 log_msg('validating basis type :'||l_basis_type);
1418 END IF;
1419
1420 IF (l_basis_type <> FND_API.G_MISS_NUM) AND(l_basis_type IS NOT NULL) THEN
1421 IF (l_basis_type <> 1) THEN
1422 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1423 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_BASIS_TYPE');
1424 FND_MESSAGE.SET_TOKEN('BASIS_TYPE',l_basis_type);
1425 FND_MSG_PUB.Add;
1426 RAISE FND_API.G_EXC_ERROR;
1427 END IF;
1428 ELSE
1429 l_basis_type := 1;
1430 END IF;
1431 -- Fixed percentage must be a valid number between 1 and 100
1432 -- (Used only when Allocation Method = 1).
1433 --
1434 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1435 log_msg('validating fixed percentage :'||l_fixed_percent);
1436 END IF;
1437
1438 IF (l_fixed_percent <> FND_API.G_MISS_NUM) AND(l_fixed_percent IS NOT NULL) THEN
1439 IF (l_fixed_percent < 0 OR l_fixed_percent > 100) THEN
1440 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1441 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_FIXED_PERCENT');
1442 FND_MESSAGE.SET_TOKEN('FIXED_PERCENT',l_fixed_percent);
1443 FND_MSG_PUB.Add;
1444 RAISE FND_API.G_EXC_ERROR;
1445 END IF;
1446 ELSIF (l_fixed_percent = FND_API.G_MISS_NUM AND G_operation = 'UPDATE') OR
1447 (G_operation = 'INSERT') THEN
1448 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1449 FND_MESSAGE.SET_NAME('GMF','GMF_API_FIXED_PERCENT_REQ');
1450 FND_MSG_PUB.Add;
1451 RAISE FND_API.G_EXC_ERROR;
1452 END IF;
1453 IF( ((p_alloc_def_rec.basis_account_id <> FND_API.G_MISS_NUM) AND
1454 (p_alloc_def_rec.basis_account_id IS NOT NULL)) OR
1455 ((p_alloc_def_rec.basis_account_key <> FND_API.G_MISS_CHAR) AND
1456 (p_alloc_def_rec.basis_account_key IS NOT NULL)) OR
1457 ((p_alloc_def_rec.balance_type <> FND_API.G_MISS_NUM) AND
1458 (p_alloc_def_rec.balance_type IS NOT NULL)) OR
1459 ((p_alloc_def_rec.bas_ytd_ptd <> FND_API.G_MISS_NUM) AND
1460 (p_alloc_def_rec.bas_ytd_ptd IS NOT NULL))
1461 ) THEN
1462 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
1463 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1464 FND_MESSAGE.SET_NAME('GMF','GMF_API_IGNORE_BASIS');
1465 FND_MSG_PUB.Add;
1466 END IF;
1467 END IF;
1468 ELSE
1469 l_fixed_percent := '' ;
1470 l_basis_type := '';
1471 END IF;
1472 -- End Fixed percentage
1473
1474 --
1475 -- CmpntCls Id
1476 --
1477 -- Use cmpntcls_id if sent otherwise use cmpntcls_code
1478 -- If both are sent then use only cmpntcls_id and ignore other params and log a message
1479 -- If both are not sent then raise error.
1480 --
1481 IF (l_cmpntcls_id <> FND_API.G_MISS_NUM) AND
1482 (l_cmpntcls_id IS NOT NULL) THEN
1483 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1484 log_msg('validating Cmpt Cls ID :'|| l_cmpntcls_id);
1485 END IF;
1486
1487 -- validate CmpntCls Id
1488 GMF_VALIDATIONS_PVT.Validate_Cost_Cmpntcls_Id (
1489 l_cmpntcls_id,l_cost_cmpntcls_code,l_usage_ind);
1490
1491 IF l_usage_ind IS NULL THEN
1492 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1493 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_CMPNTCLS_ID');
1494 FND_MESSAGE.SET_TOKEN('CMPNTCLS_ID',l_cmpntcls_id);
1495 FND_MSG_PUB.Add;
1496 RAISE FND_API.G_EXC_ERROR;
1497 ELSIF l_usage_ind <> 4 THEN
1498 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1499 FND_MESSAGE.SET_NAME('GMF','GMF_API_CMPNTCLS_USG_NOT_ALC');
1500 FND_MESSAGE.SET_TOKEN('CMPNTCLS',l_cmpntcls_id);
1501 FND_MSG_PUB.Add;
1502 RAISE FND_API.G_EXC_ERROR;
1503 END IF;
1504
1505 -- Log message if cost_cmpntcls_code is also passed
1506 IF (p_alloc_def_rec.cost_cmpntcls_code <> FND_API.G_MISS_CHAR) AND
1507 (p_alloc_def_rec.cost_cmpntcls_code IS NOT NULL) THEN
1508 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_SUCCESS) THEN
1509 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1510 FND_MESSAGE.SET_NAME('GMF','GMF_API_IGNORE_CMPNTCLS_CODE');
1511 FND_MESSAGE.SET_TOKEN('CMPNTCLS_CODE',p_alloc_def_rec.cost_cmpntcls_code);
1512 FND_MSG_PUB.Add;
1513 END IF;
1514 END IF;
1515 ELSIF (l_cost_cmpntcls_code <> FND_API.G_MISS_CHAR) AND
1516 (l_cost_cmpntcls_code IS NOT NULL) THEN
1517 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1518 log_msg('validating Cmpt Cls Code :'|| l_cost_cmpntcls_code);
1519 END IF;
1520
1521 -- Convert value into ID.
1522 GMF_VALIDATIONS_PVT.Validate_Cost_Cmpntcls_Code (
1523 l_cost_cmpntcls_code,
1524 l_cmpntcls_id,
1525 l_usage_ind
1526 ) ;
1527 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1528 log_msg('Cmpt Cls Id := ' || l_cmpntcls_id);
1529 END IF;
1530
1531 IF (l_cmpntcls_id IS NULL) OR (l_usage_ind IS NULL) THEN -- Cmpntcls_Id fetch was not successful
1532 -- Conversion failed.
1533 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1534 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_CMPNTCLS_CODE');
1535 FND_MESSAGE.SET_TOKEN('CMPNTCLS_CODE',l_cost_cmpntcls_code);
1536 FND_MSG_PUB.Add;
1537 RAISE FND_API.G_EXC_ERROR;
1538 ELSIF l_usage_ind <> 4 THEN
1539 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1540 FND_MESSAGE.SET_NAME('GMF','GMF_API_CMPNTCLS_USG_NOT_ALC');
1541 FND_MESSAGE.SET_TOKEN('CMPNTCLS',l_cost_cmpntcls_code);
1542 FND_MSG_PUB.Add;
1543 RAISE FND_API.G_EXC_ERROR;
1544 END IF;
1545 ELSIF (l_cmpntcls_id = FND_API.G_MISS_NUM AND -- Bug 2659435
1546 G_operation = 'UPDATE') OR
1547 (G_operation = 'INSERT') THEN
1548 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1549 FND_MESSAGE.SET_NAME('GMF','GMF_API_CMPNTCLS_ID_REQ');
1550 FND_MSG_PUB.Add;
1551 RAISE FND_API.G_EXC_ERROR;
1552 END IF;
1553 -- End CmpntCls Id
1554
1555 --
1556 -- Analysis Code
1557 --
1558 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1559 log_msg('validating analysis_code :' || l_analysis_code);
1560 END IF;
1561
1562 IF (l_analysis_code <> FND_API.G_MISS_CHAR) AND
1563 (l_analysis_code IS NOT NULL) THEN
1564 IF NOT GMF_VALIDATIONS_PVT.Validate_Analysis_Code(l_analysis_code)
1565 THEN
1566 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1567 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_ANALYSIS_CODE');
1568 FND_MESSAGE.SET_TOKEN('ANALYSIS_CODE',l_analysis_code);
1569 FND_MSG_PUB.Add;
1570 RAISE FND_API.G_EXC_ERROR;
1571 END IF;
1572 ELSIF (l_analysis_code = FND_API.G_MISS_CHAR AND -- Bug 2659435
1573 G_operation = 'UPDATE') OR
1574 (G_operation = 'INSERT') THEN
1575 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1576 FND_MESSAGE.SET_NAME('GMF','GMF_API_ANALYSIS_CODE_REQ');
1577 FND_MSG_PUB.Add;
1578 RAISE FND_API.G_EXC_ERROR;
1579 END IF;
1580 -- End Analysis Code
1581 --
1582 -- Delete Mark
1583 --
1584 IF (l_delete_mark <> FND_API.G_MISS_NUM) AND
1585 (l_delete_mark IS NOT NULL) THEN
1586 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1587 log_msg('validating delete_mark :' || l_delete_mark);
1588 END IF;
1589
1590 IF l_delete_mark NOT IN (0,1) THEN
1591 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1592 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_DELETE_MARK');
1593 FND_MESSAGE.SET_TOKEN('DELETE_MARK',l_delete_mark);
1594 FND_MSG_PUB.Add;
1595 RAISE FND_API.G_EXC_ERROR;
1596 END IF;
1597 ELSIF (l_delete_mark = FND_API.G_MISS_NUM AND G_operation = 'UPDATE') OR
1598 (G_operation = 'INSERT') THEN
1599 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1600 FND_MESSAGE.SET_NAME('GMF','GMF_API_DELETE_MARK_REQ');
1601 FND_MSG_PUB.Add;
1602 RAISE FND_API.G_EXC_ERROR;
1603 END IF;
1604 -- End Delete Mark
1605
1606 -- Populate WHO columns
1607 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1608 log_msg('Validating user name : ' || l_user_name);
1609 END IF;
1610
1611 IF (l_user_name <> FND_API.G_MISS_CHAR) AND
1612 (l_user_name IS NOT NULL) THEN
1613 GMA_GLOBAL_GRP.Get_who( p_user_name => l_user_name
1614 , x_user_id => l_user_id
1615 );
1616
1617 IF l_user_id = -1 THEN -- Bug 2681243: GMA changed return status value to -1.
1618 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1619 FND_MESSAGE.SET_NAME('GMF','GMF_API_INVALID_USER_NAME');
1620 FND_MESSAGE.SET_TOKEN('USER_NAME',l_user_name);
1621 FND_MSG_PUB.Add;
1622 RAISE FND_API.G_EXC_ERROR;
1623 END IF;
1624 ELSE
1625 add_header_to_error_stack(p_alloc_def_rec); -- Bug 2659435
1626 FND_MESSAGE.SET_NAME('GMF','GMF_API_USER_NAME_REQ');
1627 FND_MSG_PUB.Add;
1628 RAISE FND_API.G_EXC_ERROR;
1629 END IF;
1630 -- End User Name
1631
1632
1633 x_alloc_def_rec.Alloc_id := l_Alloc_id ;
1634 x_alloc_def_rec.alloc_code := l_alloc_code ;
1635 x_alloc_def_rec.legal_entity_id := l_legal_entity_id ;
1636 x_alloc_def_rec.alloc_method := l_alloc_method ;
1637 x_alloc_def_rec.line_no := l_line_no ;
1638 x_alloc_def_rec.Item_Id := l_Item_Id ;
1639 x_alloc_def_rec.item_number := l_item_number ;
1640 x_alloc_def_rec.basis_account_id := l_basis_account_id ;
1641 x_alloc_def_rec.basis_account_key := l_basis_account_key ;
1642 x_alloc_def_rec.balance_type := l_balance_type ;
1643 x_alloc_def_rec.bas_ytd_ptd := l_bas_ytd_ptd ;
1644 x_alloc_def_rec.basis_type := l_basis_type ;
1645 x_alloc_def_rec.fixed_percent := l_fixed_percent ;
1646 x_alloc_def_rec.cmpntcls_id := l_cmpntcls_id ;
1647 x_alloc_def_rec.cost_cmpntcls_code := l_cost_cmpntcls_code ;
1648 x_alloc_def_rec.analysis_code := l_analysis_code ;
1649 x_alloc_def_rec.organization_id := l_organization_id ;
1650 x_alloc_def_rec.delete_mark := l_delete_mark ;
1651 x_alloc_def_rec.user_name := l_user_name ;
1652 x_user_id := l_user_id ;
1653
1654 EXCEPTION -- Bug 2681243: removed when others to capture ORA errors.
1655 WHEN FND_API.G_EXC_ERROR THEN
1656 x_return_status := FND_API.G_RET_STS_ERROR ;
1657 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1658 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1659 END Validate_Input_Params;
1660
1661 -- Func start of comments
1662 --+==========================================================================+
1663 --| FUNCTION NAME |
1664 --| check_alloc_def |
1665 --| |
1666 --| DESCRIPTION |
1667 --| This function checks whether allocation definition is already |
1668 --| defined or not. If defined, then check whether allocation methods |
1669 --| are same. To add a Alloc Def line allocation methods should be |
1670 --| same. |
1671 --| |
1672 --| PARAMETERS |
1673 --| p_alloc_id IN NUMBER(10) - Allocation Id |
1674 --| p_alloc_method IN NUMBER(10) - Allocation Method |
1675 --| |
1676 --| RETURNS |
1677 --| TRUE - If Alloc Def is already defined and alloc methods are |
1678 --| same. And also if Alloc Def is not already defined. |
1679 --| FALSE - If Alloc Def is already defined and alloc methods are |
1680 --| not same. |
1681 --| |
1682 --| HISTORY |
1683 --| 27/02/2001 Uday Moogla - Created |
1684 --| |
1685 --+==========================================================================+
1686 -- Func end of comments
1687
1688 FUNCTION check_alloc_def
1689 (
1690 p_alloc_id IN gl_aloc_bas.alloc_id%TYPE,
1691 p_alloc_method IN gl_aloc_bas.alloc_method%TYPE
1692 )
1693 RETURN BOOLEAN
1694 IS
1695 CURSOR Cur_gl_aloc_bas(p_alloc_id gl_aloc_bas.alloc_id%TYPE,
1696 p_alloc_method gl_aloc_bas.alloc_method%TYPE)
1697 IS
1698 SELECT distinct alloc_method
1699 FROM gl_aloc_bas
1700 WHERE alloc_id = p_alloc_id
1701 AND delete_mark = 0;
1702
1703 l_alloc_method gl_aloc_bas.alloc_method%TYPE ;
1704
1705 BEGIN
1706 OPEN Cur_gl_aloc_bas(p_alloc_id, p_alloc_method);
1707 FETCH Cur_gl_aloc_bas INTO l_alloc_method;
1708 CLOSE Cur_gl_aloc_bas;
1709
1710 IF l_alloc_method IS NOT NULL THEN
1711 IF l_alloc_method = p_alloc_method THEN
1712 RETURN TRUE;
1713 ELSE
1714 RETURN FALSE;
1715 END IF;
1716 ELSE
1717 RETURN TRUE;
1718 END IF;
1719 END check_alloc_def;
1720
1721 -- Func start of comments
1722 --+==========================================================================+
1723 --| FUNCTION NAME |
1724 --| is_fxdpct_hundred |
1725 --| |
1726 --| DESCRIPTION |
1727 --| This function checks whether fixed % is greater than hundred. |
1728 --| |
1729 --| PARAMETERS |
1730 --| p_alloc_id IN NUMBER(10) - Allocation Id |
1731 --| p_fixed_percent IN NUMBER(10) - Fixed % |
1732 --| |
1733 --| RETURNS |
1734 --| TRUE - If % is = 100 |
1735 --| FALSE - If % is <> 100 |
1736 --| |
1737 --| HISTORY |
1738 --| 27/02/2001 Uday Moogla - Created |
1739 --| |
1740 --+==========================================================================+
1741 -- Func end of comments
1742
1743 FUNCTION is_fxdpct_hundred
1744 (
1745 p_alloc_id IN gl_aloc_bas.alloc_id%TYPE
1746 )
1747 RETURN BOOLEAN
1748 IS
1749 CURSOR Cur_gl_aloc_bas(p_alloc_id gl_aloc_bas.alloc_id%TYPE)
1750 IS
1751 SELECT nvl(sum(fixed_percent),0)
1752 FROM gl_aloc_bas
1753 WHERE alloc_id = p_alloc_id
1754 AND delete_mark = 0
1755 AND alloc_method = 1 ;
1756
1757 l_fixed_percent gl_aloc_bas.fixed_percent%TYPE ;
1758
1759 BEGIN
1760 OPEN Cur_gl_aloc_bas(p_alloc_id);
1761 FETCH Cur_gl_aloc_bas INTO l_fixed_percent;
1762 CLOSE Cur_gl_aloc_bas;
1763
1764 IF FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW >= G_Debug_Level THEN -- Bug 2659435
1765 log_msg('Total fixed percent : '||to_char(l_fixed_percent));
1766 END IF;
1767
1768 IF (l_fixed_percent) = 100 THEN
1769 RETURN TRUE;
1770 ELSE
1771 RETURN FALSE;
1772 END IF;
1773 END is_fxdpct_hundred;
1774
1775 -- Func start of comments
1776 --+==========================================================================+
1777 --| FUNCTION NAME |
1778 --| check_record_exist |
1779 --| |
1780 --| DESCRIPTION |
1781 --| This function checks whether allocation definition exist or not |
1782 --| |
1783 --| PARAMETERS |
1784 --| p_alloc_id IN NUMBER(10) - Allocation Id |
1785 --| p_line_no IN NUMBER(10) - Allocation Method |
1786 --| |
1787 --| RETURNS |
1788 --| TRUE - If record exist. |
1789 --| FALSE - If record does not exist. |
1790 --| |
1791 --| HISTORY |
1792 --| 27/02/2001 Uday Moogla - Created |
1793 --| |
1794 --+==========================================================================+
1795 -- Func end of comments
1796
1797 FUNCTION check_record_exist
1798 (
1799 p_alloc_id IN gl_aloc_bas.alloc_id%TYPE,
1800 p_line_no IN gl_aloc_bas.line_no%TYPE
1801 )
1802 RETURN BOOLEAN
1803 IS
1804 CURSOR Cur_gl_aloc_bas(p_alloc_id gl_aloc_bas.alloc_id%TYPE,
1805 p_line_no gl_aloc_bas.line_no%TYPE)
1806 IS
1807 SELECT count(1)
1808 FROM gl_aloc_bas
1809 WHERE alloc_id = p_alloc_id
1810 AND line_no = p_line_no ;
1811
1812 l_count NUMBER(10) ;
1813
1814 BEGIN
1815 OPEN Cur_gl_aloc_bas(p_alloc_id, p_line_no);
1816 FETCH Cur_gl_aloc_bas INTO l_count;
1817 CLOSE Cur_gl_aloc_bas;
1818
1819 IF l_count = 0 THEN
1820 RETURN FALSE;
1821 ELSE
1822 RETURN TRUE;
1823 END IF;
1824 END check_record_exist;
1825
1826 -- Func start of comments
1827 --+==========================================================================+
1828 --| Procedure Name |
1829 --| log_msg |
1830 --| |
1831 --| DESCRIPTION |
1832 --| This procedure logs messages to message stack. |
1833 --| |
1834 --| PARAMETERS |
1835 --| p_msg_lvl IN NUMBER(10) - Message Level |
1836 --| p_msg_text IN NUMBER(10) - Actual Message Text |
1837 --| |
1838 --| RETURNS |
1839 --| |
1840 --| HISTORY |
1841 --| 27/02/2001 Uday Moogla - Created |
1842 --| 05/nov/2002 Uday Moogala Bug 2659435 |
1843 --| Removed first param for debug level |
1844 --| |
1845 --+==========================================================================+
1846 -- Func end of comments
1847
1848
1849 PROCEDURE log_msg
1850 (
1851 p_msg_text IN VARCHAR2
1852 )
1853 IS
1854 BEGIN
1855
1856 -- IF FND_MSG_PUB.Check_Msg_Level (p_msg_lvl) THEN Bug 2659435
1857 FND_MESSAGE.SET_NAME('GMF','GMF_API_DEBUG');
1858 FND_MESSAGE.SET_TOKEN('MSG',p_msg_text);
1859 FND_MSG_PUB.Add;
1860 -- END IF; Bug 2659435
1861
1862 END log_msg ;
1863
1864 -- Func start of comments
1865 --+==========================================================================+
1866 --| Procedure Name |
1867 --| add_header_to_error_stack |
1868 --| |
1869 --| DESCRIPTION |
1870 --| This procedure logs header to message stack. |
1871 --| |
1872 --| PARAMETERS |
1873 --| p_header Header Record to be logged |
1874 --| |
1875 --| RETURNS |
1876 --| |
1877 --| HISTORY |
1878 --| 05/11/2001 Uday Moogla - Created Bug 2659435 |
1879 --| |
1880 --+==========================================================================+
1881 -- Func end of comments
1882
1883 PROCEDURE add_header_to_error_stack
1884 (
1885 p_header Allocation_Definition_Rec_Type
1886 )
1887 IS
1888 BEGIN
1889
1890 IF G_header_logged = 'N' THEN
1891 G_header_logged := 'Y';
1892 FND_MESSAGE.SET_NAME('GMF','GMF_API_ALLOCATION_HEADER');
1893 FND_MESSAGE.SET_TOKEN('ALLOCATION_ID',p_header.alloc_id);
1894 FND_MESSAGE.SET_TOKEN('ALLOCATION_CODE',p_header.alloc_code);
1895 FND_MESSAGE.SET_TOKEN('LEGAL ENTITY',p_header.legal_entity_id);
1896 FND_MESSAGE.SET_TOKEN('ITEM_ID',p_header.item_id);
1897 FND_MESSAGE.SET_TOKEN('ITEM_NO',p_header.item_number);
1898 FND_MESSAGE.SET_TOKEN('CMPNT_CLASS_ID',p_header.cmpntcls_id);
1899 FND_MESSAGE.SET_TOKEN('CMPNT_CLASS_CODE',p_header.cmpntcls_id);
1900 FND_MSG_PUB.Add;
1901 END IF;
1902
1903 END add_header_to_error_stack;
1904
1905
1906 END GMF_AllocationDefinition_PUB;