[Home] [Help]
PACKAGE BODY: APPS.FA_CUA_MASS_EXT_RET_PKG
Source
1 PACKAGE BODY FA_CUA_MASS_EXT_RET_PKG AS
2 /* $Header: FACXTREMB.pls 120.31 2011/02/10 09:57:51 spooyath ship $
3
4 /* Global Variables holding Mass External Retirements Information */
5 G_Mass_External_Retire_Id fa_mass_Ext_retirements.Mass_External_Retire_Id%TYPE;
6 G_Book_Type_Code fa_mass_Ext_retirements.Book_Type_Code%TYPE;
7 G_Batch_Name fa_mass_Ext_retirements.Batch_Name%TYPE;
8 G_Asset_Id fa_mass_Ext_retirements.Asset_Id%TYPE;
9 G_Transaction_Name fa_mass_Ext_retirements.Transaction_Name%TYPE;
10 G_Date_Retired fa_mass_Ext_retirements.Date_Retired%TYPE;
11 G_Cost_Retired fa_mass_Ext_retirements.Cost_Retired%TYPE;
12 G_Retirement_Prorate_Conv fa_mass_Ext_retirements.Retirement_Prorate_Convention%TYPE;
13 G_Units fa_mass_Ext_retirements.Units%TYPE;
14 G_Cost_Of_Removal fa_mass_Ext_retirements.Cost_Of_Removal%TYPE;
15 G_Proceeds_Of_Sale fa_mass_Ext_retirements.Proceeds_Of_Sale%TYPE;
16 G_Retirement_Type_Code fa_mass_Ext_retirements.Retirement_Type_Code%TYPE;
17 G_Reference_Num fa_mass_Ext_retirements.Reference_Num%TYPE;
18 G_Sold_To fa_mass_Ext_retirements.Sold_To%TYPE;
19 G_Trade_In_Asset_Id fa_mass_Ext_retirements.Trade_In_Asset_Id%TYPE;
20 G_Stl_Method_Code fa_mass_Ext_retirements.Stl_Method_Code%TYPE;
21 G_Stl_Life_In_Months fa_mass_Ext_retirements.Stl_Life_In_Months%TYPE;
22 G_Stl_Deprn_Amount fa_mass_Ext_retirements.Stl_Deprn_Amount%TYPE;
23 G_Itc_Recaptured fa_retirements.Itc_Recaptured%TYPE;
24 G_Itc_Recapture_Id fa_retirements.Itc_Recapture_Id%TYPE;
25 G_Current_Units fa_asset_history.Units%TYPE;
26 G_Asset_Number fa_additions_b.asset_number%TYPE;
27 G_period_counter_fully_retired Number;
28 /* Bug 8483118(R12) and 8206076(11i) - Start */
29 G_Recognize_Gain_Loss fa_retirements.recognize_gain_loss%Type;
30 G_Recapture_Reserve_Flag fa_retirements.recapture_reserve_flag%Type;
31 G_Limit_Proceeds_Flag fa_retirements.limit_proceeds_flag%Type;
32 G_Terminal_Gain_Loss fa_retirements.terminal_gain_loss%Type;
33 /* Bug 8483118(R12) and 8206076(11i) - End */
34 G_Last_Update_Login NUMBER(15) := FND_GLOBAL.LOGIN_ID;
35 G_Precision NUMBER;
36 G_Ext_Precision NUMBER;
37 G_Min_Acct_Unit NUMBER;
38 G_Today_Datetime DATE := SYSDATE;
39 G_Currency_Code gl_sets_of_books.currency_code%TYPE;
40 G_Set_of_Books_ID fa_book_controls.set_of_books_id%TYPE;
41 G_calc_gain_loss_flag varchar2(50) := FND_API.G_FALSE;
42 G_Distribution_id fa_distribution_history.distribution_id%TYPE;
43 -- bug 1857395
44 G_Code_Combination_Id fa_mass_Ext_retirements.Code_Combination_Id%TYPE;
45 G_Location_Id fa_mass_Ext_retirements.Location_Id%TYPE;
46 G_Assigned_To fa_mass_Ext_retirements.Assigned_To%TYPE;
47 G_Recursion_Level VARCHAR2(1);
48 G_Created_By NUMBER(15) := FND_GLOBAL.USER_ID;
49 G_Creation_Date DATE := SYSDATE;
50 G_Varchar2_Dummy VARCHAR2(80);
51 G_Number_Dummy NUMBER(15);
52 G_Date_Dummy Date;
53 G_Date_Effective Date;
54 G_Transaction_Header_Id_In Number;
55 G_Transaction_Header_Id_Out Number;
56 G_ah_transaction_header_id Number;
57 G_category_id Number;
58 G_Book_Header_Id Number;
59 G_Transaction_Units Number;
60 G_Calling_Interface VARCHAR2(30) := 'FAMPRET';
61 --
62
63 G_Subroutine_Fail EXCEPTION;
64 /* Start Bug 1300585 */
65 G_TH_Attribute_Category fa_mass_Ext_retirements.TH_Attribute_Category%TYPE;
66 G_TH_Attribute1 fa_mass_Ext_retirements.TH_Attribute1%TYPE;
67 G_TH_Attribute2 fa_mass_Ext_retirements.TH_Attribute2%TYPE;
68 G_TH_Attribute3 fa_mass_Ext_retirements.TH_Attribute3%TYPE;
69 G_TH_Attribute4 fa_mass_Ext_retirements.TH_Attribute4%TYPE;
70 G_TH_Attribute5 fa_mass_Ext_retirements.TH_Attribute5%TYPE;
71 G_TH_Attribute6 fa_mass_Ext_retirements.TH_Attribute6%TYPE;
72 G_TH_Attribute7 fa_mass_Ext_retirements.TH_Attribute7%TYPE;
73 G_TH_Attribute8 fa_mass_Ext_retirements.TH_Attribute8%TYPE;
74 G_TH_Attribute9 fa_mass_Ext_retirements.TH_Attribute9%TYPE;
75 G_TH_Attribute10 fa_mass_Ext_retirements.TH_Attribute10%TYPE;
76 G_TH_Attribute11 fa_mass_Ext_retirements.TH_Attribute11%TYPE;
77 G_TH_Attribute12 fa_mass_Ext_retirements.TH_Attribute12%TYPE;
78 G_TH_Attribute13 fa_mass_Ext_retirements.TH_Attribute13%TYPE;
79 G_TH_Attribute14 fa_mass_Ext_retirements.TH_Attribute14%TYPE;
80 G_TH_Attribute15 fa_mass_Ext_retirements.TH_Attribute15%TYPE;
81 G_Attribute_Category fa_mass_Ext_retirements.Attribute_Category%TYPE;
82 G_Attribute1 fa_mass_Ext_retirements.Attribute1%TYPE;
83 G_Attribute2 fa_mass_Ext_retirements.Attribute2%TYPE;
84 G_Attribute3 fa_mass_Ext_retirements.Attribute3%TYPE;
85 G_Attribute4 fa_mass_Ext_retirements.Attribute4%TYPE;
86 G_Attribute5 fa_mass_Ext_retirements.Attribute5%TYPE;
87 G_Attribute6 fa_mass_Ext_retirements.Attribute6%TYPE;
88 G_Attribute7 fa_mass_Ext_retirements.Attribute7%TYPE;
89 G_Attribute8 fa_mass_Ext_retirements.Attribute8%TYPE;
90 G_Attribute9 fa_mass_Ext_retirements.Attribute9%TYPE;
91 G_Attribute10 fa_mass_Ext_retirements.Attribute10%TYPE;
92 G_Attribute11 fa_mass_Ext_retirements.Attribute11%TYPE;
93 G_Attribute12 fa_mass_Ext_retirements.Attribute12%TYPE;
94 G_Attribute13 fa_mass_Ext_retirements.Attribute13%TYPE;
95 G_Attribute14 fa_mass_Ext_retirements.Attribute14%TYPE;
96 G_Attribute15 fa_mass_Ext_retirements.Attribute15%TYPE;
97
98 /* End of bug 1300585*/
99
100 G_fatal_error boolean := FALSE;
101 G_failure_count number := 0;
102 G_success_count NUMBER := 0;
103
104 g_prev_asset_id number := 0;
105 g_prev_batch_name varchar2(30) := 'ZZZZZZZZZZZZZZZZ';
106 g_num_of_distributions number;
107 g_i number;
108
109 G_test_num_of_distributions NUMBER;
110 G_test_ident_distributions NUMBER;
111 G_single_dist_array VARCHAR2(10);
112
113 g_log_level_rec fa_api_types.log_level_rec_type;
114
115 PROCEDURE Mass_Ext_Retire (P_BOOK_TYPE_CODE IN VARCHAR2,
116 PX_BATCH_NAME IN OUT NOCOPY VARCHAR2,
117 P_PARENT_REQUEST_ID IN NUMBER,
118 P_TOTAL_REQUESTS IN NUMBER,
119 P_REQUEST_NUMBER IN NUMBER,
120 PX_MAX_MASS_EXT_RETIRE_ID IN OUT NOCOPY NUMBER,
121 X_SUCCESS_COUNT OUT NOCOPY NUMBER,
122 X_FAILURE_COUNT OUT NOCOPY NUMBER,
123 X_RETURN_STATUS OUT NOCOPY NUMBER) IS
124
125 CURSOR mass_external_retirement IS
126 SELECT mer.Mass_External_Retire_Id,
127 mer.Book_Type_Code,
128 mer.Batch_Name,
129 mer.Asset_Id,
130 Mer.Transaction_Name,
131 mer.Date_Retired,
132 mer.Cost_Retired,
133 mer.Retirement_Prorate_Convention,
134 mer.Units,
135 nvl(mer.Cost_Of_Removal,0),
136 nvl(mer.Proceeds_Of_Sale,0),
137 mer.Retirement_Type_Code,
138 mer.Reference_Num,
139 mer.Sold_To,
140 mer.Trade_In_Asset_Id,
141 mer.calc_gain_loss_flag,
142 mer.Stl_Method_Code,
143 mer.Stl_Life_In_Months,
144 mer.Stl_Deprn_Amount,
145 mer.Last_Update_Login,
146 sysdate,
147 sob.currency_code,
148 fbc.set_of_books_id,
149 ad.current_units,
150 ad.asset_number,
151 bks.period_counter_fully_retired,
152 mer.distribution_id,
153 mer.code_combination_id,
154 mer.location_id,
155 mer.assigned_to,
156 mer.th_attribute_category,
157 mer.th_attribute1,
158 mer.th_attribute2,
159 mer.th_attribute3,
160 mer.th_attribute4,
161 mer.th_attribute5,
162 mer.th_attribute6,
163 mer.th_attribute7,
164 mer.th_attribute8,
165 mer.th_attribute9,
166 mer.th_attribute10,
167 mer.th_attribute11,
168 mer.th_attribute12,
169 mer.th_attribute13,
170 mer.th_attribute14,
171 mer.th_attribute15,
172 mer.attribute_category,
173 mer.attribute1,
174 mer.attribute2,
175 mer.attribute3,
176 mer.attribute4,
177 mer.attribute5,
178 mer.attribute6,
179 mer.attribute7,
180 mer.attribute8,
181 mer.attribute9,
182 mer.attribute10,
183 mer.attribute11,
184 mer.attribute12,
185 mer.attribute13,
186 mer.attribute14,
187 mer.attribute15,
188 mer.recognize_gain_loss,/*Bug 8647381 *//* Bug 8483118(R12) and 8206076(11i) - Start */
189 bks.recapture_reserve_flag,
190 bks.limit_proceeds_flag,
191 bks.terminal_gain_loss /* Bug 8483118(R12) and 8206076(11i) - End */
192 FROM fa_mass_Ext_retirements mer,
193 fa_books bks,
194 fa_additions_b ad,
195 fa_book_controls fbc,
196 gl_sets_of_books sob
197 WHERE mer.review_status = 'POST'
198 AND mer.book_type_code = fbc.book_type_code
199 AND fbc.set_of_books_id = sob.set_of_books_id
200 AND mer.batch_name = nvl(px_batch_name,mer.batch_name)
201 AND mer.book_type_code = P_Book_Type_Code
202 AND bks.book_type_code = mer.book_type_code
203 AND bks.asset_id = mer.asset_id
204 AND bks.date_ineffective is null
205 AND ad.asset_id = mer.asset_id
206 and mer.mass_external_retire_id > px_max_mass_ext_retire_id
207 and MOD(nvl(bks.group_asset_id,mer.asset_id), p_total_requests) = (p_request_number - 1)
208 order by mer.batch_name, mer.mass_external_retire_id;
209
210 -- used for bulk fetching
211 l_batch_size number;
212
213 -- index for For..loops
214 i number := 0;
215 j number := 0;
216 k number := 0;
217 -- main cursor
218 -- type for table variable
219 type num_tbl_type is table of number index by binary_integer;
220 type char_tbl_type is table of varchar2(150) index by binary_integer;
221 type date_tbl_type is table of date index by binary_integer;
222
223 -- api declaration
224 -- variables and structs used for api call
225 -- l_debug_flag VARCHAR2(3) := 'YES';
226 l_debug_flag VARCHAR2(3) := 'NO';
227 l_api_version NUMBER := 1; -- 1.0
228 l_init_msg_list VARCHAR2(50) := FND_API.G_FALSE; -- 1
229 l_commit VARCHAR2(1) := FND_API.G_FALSE;
230 l_validation_level NUMBER := FND_API.G_VALID_LEVEL_FULL;
231 l_return_status VARCHAR2(10);
232 l_msg_count NUMBER;
233 -- l_msg_data VARCHAR2(4000);
234 l_calling_fn VARCHAR2(100) := 'fa_cua_mass_ext_ret_pkg';
235 l_trans_rec fa_api_types.trans_rec_type;
236 l_dist_trans_rec fa_api_types.trans_rec_type;
237 l_asset_hdr_rec fa_api_types.asset_hdr_rec_type;
238 l_asset_retire_rec fa_api_types.asset_retire_rec_type;
239 l_asset_dist_rec fa_api_types.asset_dist_rec_type;
240 l_asset_dist_tbl fa_api_types.asset_dist_tbl_type;
241 l_subcomp_rec fa_api_types.subcomp_rec_type;
242 l_subcomp_tbl fa_api_types.subcomp_tbl_type;
243 l_inv_rec fa_api_types.inv_rec_type;
244 l_inv_tbl fa_api_types.inv_tbl_type;
245 -- end api declaration
246
247 l_Mass_External_Retire_Id num_tbl_type;
248 L_Book_Type_Code char_tbl_type;
249 L_Batch_Name char_tbl_type;
250 L_Asset_Id num_tbl_type;
251 L_Transaction_Name char_tbl_type;
252 L_Date_Retired date_tbl_type;
253 L_Cost_Retired num_tbl_type;
254 L_Retirement_Prorate_Conv char_tbl_type;
255 L_Units num_tbl_type;
256 L_Cost_Of_Removal num_tbl_type;
257 L_Proceeds_Of_Sale num_tbl_type;
258 L_Retirement_Type_Code char_tbl_type;
259 L_Reference_Num char_tbl_type;
260 L_Sold_To char_tbl_type;
261 L_Trade_In_Asset_Id num_tbl_type;
262 L_Calc_Gain_Loss_Flag char_tbl_type;
263 L_Stl_Method_Code char_tbl_type;
264 L_Stl_Life_In_Months num_tbl_type;
265 L_Stl_Deprn_Amount num_tbl_type;
266 L_Last_Update_Login num_tbl_type;
267 L_Today_Datetime date_tbl_type;
268 L_Currency_Code char_tbl_type;
269 L_Set_of_Books_Id num_tbl_type;
270 L_Current_Units num_tbl_type;
271 L_Asset_Number char_tbl_type;
272 L_Period_Counter_Fully_Retired num_tbl_type;
273 /* Bug 8483118(R12) and 8206076(11i) - Start */
274 L_Recognize_Gain_Loss char_tbl_type;
275 L_Recapture_Reserve_Flag char_tbl_type;
276 L_Limit_Proceeds_Flag char_tbl_type;
277 L_Terminal_Gain_Loss char_tbl_type;
278 /* Bug 8483118(R12) and 8206076(11i) - Start */
279 L_Distribution_Id num_tbl_type;
280 L_Code_combination_id num_tbl_type;
281 L_location_id num_tbl_type;
282 L_assigned_to num_tbl_type;
283 L_TH_Attribute_Category char_tbl_type;
284 L_TH_Attribute1 char_tbl_type;
285 L_TH_Attribute2 char_tbl_type;
286 L_TH_Attribute3 char_tbl_type;
287 L_TH_Attribute4 char_tbl_type;
288 L_TH_Attribute5 char_tbl_type;
289 L_TH_Attribute6 char_tbl_type;
290 L_TH_Attribute7 char_tbl_type;
291 L_TH_Attribute8 char_tbl_type;
292 L_TH_Attribute9 char_tbl_type;
293 L_TH_Attribute10 char_tbl_type;
294 L_TH_Attribute11 char_tbl_type;
295 L_TH_Attribute12 char_tbl_type;
296 L_TH_Attribute13 char_tbl_type;
297 L_TH_Attribute14 char_tbl_type;
298 L_TH_Attribute15 char_tbl_type;
299 L_Attribute_Category char_tbl_type;
300 L_Attribute1 char_tbl_type;
301 L_Attribute2 char_tbl_type;
302 L_Attribute3 char_tbl_type;
303 L_Attribute4 char_tbl_type;
304 L_Attribute5 char_tbl_type;
305 L_Attribute6 char_tbl_type;
306 L_Attribute7 char_tbl_type;
307 L_Attribute8 char_tbl_type;
308 L_Attribute9 char_tbl_type;
309 L_Attribute10 char_tbl_type;
310 L_Attribute11 char_tbl_type;
311 L_Attribute12 char_tbl_type;
312 L_Attribute13 char_tbl_type;
313 L_Attribute14 char_tbl_type;
314 L_Attribute15 char_tbl_type;
315
316 /** commented out for bugfix 2036777
317 Cursor Source_Lines_C Is
318 Select ext.*
319 from fa_ext_inv_retirements ext ,
320 fa_asset_invoices ai
321 where ext.mass_external_retire_id = L_Mass_External_Retire_ID
322 and ext.source_line_id = ai.source_line_id
323 and ai.date_ineffective is null
324 and ai.asset_id = G_Asset_Id;
325 Source_Lines Source_Lines_C%ROWTYPE;
326 **/
327
328 -- added for bugfix 2036777
329 -- modified after 2036777, added fa_ai, so only invoices belonging
330 -- to current asset are treated.
331 Cursor Source_Lines_C Is
332 select ext.*, ext.ROWID row_id
333 from fa_ext_inv_retirements ext,
334 fa_asset_invoices ai
335 where ext.mass_external_retire_id = G_Mass_External_Retire_ID
336 and ext.source_line_id = ai.source_line_id
337 and ai.asset_id = g_asset_id
338 and ext.source_line_id_retired is null;
339
340 Source_Lines Source_Lines_C%ROWTYPE;
341
342 -- added for bugfix 2036777
343 Cursor C3(p_src_line_id number) IS
344 select b.source_line_id
345 from fa_asset_invoices b
346 where b.source_line_id in (
347 select a.source_line_id
348 from fa_asset_invoices a
349 start with a.source_Line_id = p_src_line_id
350 connect by prior a.invoice_transaction_id_out = a.invoice_transaction_id_in )
351 and b.date_ineffective is null;
352
353 C3_lines C3%ROWTYPE;
354
355
356 Cursor c_ret_type IS
357 select 'Y'
358 from fa_lookups
359 where lookup_type = 'RETIREMENT'
360 and enabled_flag = 'Y'
361 and nvl(end_date_active,sysdate+1) > sysdate
362 and lookup_code = G_retirement_type_code;
363
364 Cursor c_dh IS
365 select rowid,
366 distribution_id,
367 book_type_code,
368 asset_id,
369 units_assigned,
370 date_effective,
371 code_combination_id,
372 location_id,
373 transaction_header_id_in,
374 last_update_date,
375 last_updated_by,
376 date_ineffective,
377 assigned_to,
378 transaction_header_id_out,
379 transaction_units,
380 retirement_id,
381 last_update_login
382 from fa_distribution_history
383 where asset_id = G_asset_id
384 and code_combination_id = G_Code_Combination_id
385 and location_id = G_Location_id
386 and nvl(assigned_to,0) = nvl(G_Assigned_To,0)
387 and date_ineffective is null;
388 dhrec c_dh%ROWTYPE;
389
390 Cursor c_currency_info IS
391 select
392 fc.precision
393 from gl_sets_of_books sob,
394 fa_book_controls fbc,
395 fnd_currencies fc
396 where fc.currency_code = sob.currency_code
397 and fc.enabled_flag = 'Y'
398 and fbc.book_type_code = p_book_type_code
399 and fbc.set_of_books_id = sob.set_of_books_id;
400
401 Cursor c_dhident is
402 select nvl(count(*),0)
403 into g_test_ident_distributions
404 from fa_mass_ext_retirements
405 where batch_name = G_batch_name
406 and review_status = 'POST'
407 and asset_id = g_asset_id
408 group by code_combination_id, location_id, assigned_to
409 having count(*) > 1;
410
411 -- loop_count number:= 0;
412 lv_sl_cost_retired number;
413 lv_src_line_id number;
414 lv_src_line_cost number;
415 lv_sl_count number := 0;
416 lv_sl_count2 number := 0;
417 lv_new_inv_txn_id number;
418 l_src_line_inv_txn_id number;
419 lv_it_rowid rowid;
420 lv_ret_id number;
421
422 -- variables for validation
423 lv_cost number;
424 lv_current_units number;
425 lv_date_retired date;
426 lv_current_fiscal_year number;
427 lv_book_class varchar2(15);
428 lv_fy_start_date date;
429 lv_fy_end_date date;
430 lv_current_period_counter number;
431 lv_asset_added_pc number;
432 lv_cal_per_close_date date;
433 lv_max_txn_date_entered date;
434 lv_asset_type varchar2(11);
435 lv_ret_prorate_convention varchar2(10);
436 lv_use_stl_ret_flag varchar2(3);
437 lv_stl_method_code varchar2(4);
438 lv_stl_life_in_months number;
439 lv_val_count number;
440 lv_message varchar2(50);
441 l_pcfr number;
442 Validation_Error exception;
443 Fully_Reserved_Error exception;
444 Duplicate_Req exception;
445 lv_app varchar2(3);
446 lv_dummy_var VARCHAR2(1);
447
448 -- added by msiddiqu feb-24-2001
449 l_count number := 0;
450 l_error_status varchar2(30):= null;
451 pending_batch exception;
452 v_dummy_bool boolean:= FALSE;
453
454 -- partial unit retirement extension
455 p_event varchar2(30) := 'INSERT';
456 h_return_status BOOLEAN;
457 h_status BOOLEAN;
458 p_ah_rowid rowid;
459 temp_ret_cost number;
460 -- mrcapi variables.
461 x_msg_data varchar2(4000);
462 MRCAPI_ERROR exception;
463 CIPTAX_ERROR exception;
464 DONE_EXC exception;
465 INIT_PROBLEM exception;
466 l_mrc_thid number;
467 l_source_line_id_new number(15);
468
469 --
470 l_token varchar2(40);
471 l_value varchar2(40);
472 l_string varchar2(512);
473
474 g_num_of_identical number := 0;
475 -- variables for multidist occurences.
476 num_dist number := 0;
477
478 l_tot_units number;
479 dist_i number;
480
481 BEGIN -- Mass_Ext_Retire
482
483 -- New api house keeping
484
485 px_max_mass_ext_retire_id := nvl(px_max_mass_ext_retire_id, 0);
486 G_success_count := 0;
487 G_failure_count := 0;
488 x_success_count := 0;
489 x_failure_count := 0;
490 x_return_status := 0;
491
492
493 if (not g_log_level_rec.initialized) then
494 if (NOT fa_util_pub.get_log_level_rec (
495 x_log_level_rec => g_log_level_rec
496 )) then
497 raise init_problem;
498 end if;
499 end if;
500
501 -- get book information
502 if not fa_cache_pkg.fazcbc(X_book => p_book_type_code, p_log_level_rec => g_log_level_rec) then
503 raise init_problem;
504 end if;
505
506 l_batch_size := nvl(fa_cache_pkg.fa_batch_size, 200);
507
508 -- clear the debug stack initially and later for each asset
509 FA_DEBUG_PKG.Initialize;
510 -- reset the message level to prevent bogus errors
511 FA_SRVR_MSG.Set_Message_Level(message_level => 10, p_log_level_rec => g_log_level_rec);
512
513 g_i := 0;
514 if (g_log_level_rec.statement_level) then
515 fa_debug_pkg.add(l_calling_fn, 'px_max_mass_ext_retire_id', px_max_mass_ext_retire_id, p_log_level_rec => g_log_level_rec);
516 fa_debug_pkg.add(l_calling_fn, 'p_book', p_book_type_code, p_log_level_rec => g_log_level_rec);
517 fa_debug_pkg.add(l_calling_fn, 'p_parent_request_id', p_parent_request_id, p_log_level_rec => g_log_level_rec);
518 fa_debug_pkg.add(l_calling_fn, 'p_total_requests', p_total_requests, p_log_level_rec => g_log_level_rec);
519 fa_debug_pkg.add(l_calling_fn, 'p_request_number', p_request_number, p_log_level_rec => g_log_level_rec);
520
521 end if;
522
523 -- if (g_log_level_rec.statement_level) then
524 -- fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
525 -- end if;
526
527
528 -- Initial outfile heading
529
530 -- if (p_mode = 1 and px_max_asset_id = 0) or
531 -- (p_loop_count = 0 and px_max_asset_id = 0) then
532
533 if (px_max_mass_ext_retire_id = 0) then
534
535 if (g_log_level_rec.statement_level) then
536 fa_debug_pkg.add('FACXTREMB.pls',
537 'FND_FILE init: BOOK ',
538 P_BOOK_TYPE_CODE, p_log_level_rec => g_log_level_rec);
539 End if;
540
541 FND_FILE.put(FND_FILE.output,'');
542 FND_FILE.new_line(FND_FILE.output,1);
543
544 -- dump out the headings
545 fnd_message.set_name('OFA', 'FA_POST_MASSRET_REPORT_COLUMN');
546 l_string := fnd_message.get;
547
548 FND_FILE.put(FND_FILE.output,l_string);
549 FND_FILE.new_line(FND_FILE.output,1);
550
551 fnd_message.set_name('OFA', 'FA_POST_MASSRET_REPORT_LINE');
552 l_string := fnd_message.get;
553 FND_FILE.put(FND_FILE.output,l_string);
554 FND_FILE.new_line(FND_FILE.output,1);
555
556 end if;
557 if (g_log_level_rec.statement_level) then
558 fa_debug_pkg.add('FACXTREMB.pls',
559 'Before CRL test ',
560 '', p_log_level_rec => g_log_level_rec);
561 End if;
562
563 -- Call Hierarchy batch if CRL enabled
564
565 if (nvl(fnd_profile.value('CRL-FA ENABLED'), 'N') = 'Y') then
566 -- returns true if batch is pending
567
568 if fa_cua_hr_retirements_pkg.check_pending_batch
569 ( x_calling_function => 'CUA_EXT_RETIREMENTS'
570 , x_book_type_code => P_Book_Type_Code
571 , x_event_code => null
572 , x_asset_id => null
573 , x_node_id => null
574 , x_category_id => null
575 , x_attribute => null
576 , x_conc_request_id => null
577 , x_status => l_error_status , p_log_level_rec => g_log_level_rec) then
578
579 -- there exists a pending batch
580 if ( substr(l_error_status, 1, 3) = 'CUA') then
581 lv_app := 'CUA';
582 end if;
583 x_return_status := 2;
584 lv_message := l_error_status;
585 raise PENDING_BATCH;
586 end if;
587 end if;
588
589
590 if (g_log_level_rec.statement_level) then
591 fa_debug_pkg.add('FACXTREMB.pls',
592 'Before mass ext mainselect ',
593 '', p_log_level_rec => g_log_level_rec);
594 End if;
595
596 OPEN mass_external_retirement;
597
598 FETCH mass_external_retirement BULK COLLECT INTO
599 L_Mass_External_Retire_Id ,
600 L_Book_Type_Code ,
601 L_Batch_Name ,
602 L_Asset_Id ,
603 L_Transaction_Name ,
604 L_Date_Retired ,
605 L_Cost_Retired ,
606 L_Retirement_Prorate_Conv ,
607 L_Units ,
608 L_Cost_Of_Removal ,
609 L_Proceeds_Of_Sale ,
610 L_Retirement_Type_Code ,
611 L_Reference_Num ,
612 L_Sold_To ,
613 L_Trade_In_Asset_Id ,
614 L_Calc_Gain_Loss_Flag ,
615 L_Stl_Method_Code ,
616 L_Stl_Life_In_Months ,
617 L_Stl_Deprn_Amount ,
618 L_Last_Update_Login ,
619 L_Today_Datetime ,
620 L_Currency_Code ,
621 L_Set_of_Books_Id ,
622 L_Current_Units ,
623 L_Asset_Number ,
624 L_Period_Counter_Fully_Retired ,
625 L_Distribution_Id ,
626 L_Code_combination_id ,
627 L_location_id ,
628 L_assigned_to ,
629 L_TH_Attribute_Category ,
630 L_TH_Attribute1 ,
631 L_TH_Attribute2 ,
632 L_TH_Attribute3 ,
633 L_TH_Attribute4 ,
634 L_TH_Attribute5 ,
635 L_TH_Attribute6 ,
636 L_TH_Attribute7 ,
637 L_TH_Attribute8 ,
638 L_TH_Attribute9 ,
639 L_TH_Attribute10 ,
640 L_TH_Attribute11 ,
641 L_TH_Attribute12 ,
642 L_TH_Attribute13 ,
643 L_TH_Attribute14 ,
644 L_TH_Attribute15 ,
645 L_Attribute_Category ,
646 L_Attribute1 ,
647 L_Attribute2 ,
648 L_Attribute3 ,
649 L_Attribute4 ,
650 L_Attribute5 ,
651 L_Attribute6 ,
652 L_Attribute7 ,
653 L_Attribute8 ,
654 L_Attribute9 ,
655 L_Attribute10 ,
656 L_Attribute11 ,
657 L_Attribute12 ,
658 L_Attribute13 ,
659 L_Attribute14 ,
660 L_Attribute15 , /* Bug 8483118(R12) and 8206076(11i) - Start */
661 L_Recognize_Gain_Loss ,
662 L_Recapture_Reserve_Flag ,
663 L_Limit_Proceeds_Flag ,
664 L_Terminal_Gain_Loss /* Bug 8483118(R12) and 8206076(11i) - End */
665 LIMIT l_batch_size;
666 Close Mass_external_retirement;
667
668 IF (g_log_level_rec.statement_level) then
669 fa_debug_pkg.add('FACXTREMB.pls',
670 'Before for loop, number of loops ',
671 l_asset_id.count, p_log_level_rec => g_log_level_rec);
672 END IF;
673
674
675 if l_asset_id.count = 0 then
676 raise done_exc;
677 end if;
678
679 -- clear the debug stack for each asset
680 FA_DEBUG_PKG.Initialize;
681 -- reset the message level to prevent bogus errors
682 FA_SRVR_MSG.Set_Message_Level(message_level => 10, p_log_level_rec => g_log_level_rec);
683
684 For i in 1..l_asset_id.count loop -- mass_external_retirement
685 -- assign bulk to variables.
686
687 -- Print asset_number to logfile
688 fa_srvr_msg.add_message(
689 calling_fn => NULL,
690 name => 'FA_SHARED_ASSET_NUMBER',
691 token1 => 'NUMBER',
692 value1 => l_asset_number(i) , p_log_level_rec => g_log_level_rec);
693 fa_srvr_msg.add_message(
694 calling_fn => NULL,
695 name => 'FA_SHARED_ASSET_NUMBER',
696 token1 => 'NUMBER',
697 value1 => l_mass_external_retire_id(i), p_log_level_rec =>
698 g_log_level_rec );
699
700 g_mass_external_retire_id := l_Mass_External_Retire_Id(i);
701 g_book_type_code := L_Book_Type_Code(i);
702 g_batch_name := L_Batch_Name(i);
703 g_asset_id := L_Asset_Id(i);
704 g_transaction_name := L_Transaction_Name(i);
705 g_date_retired := L_Date_Retired(i);
706 g_cost_retired := L_Cost_Retired(i);
707 g_retirement_prorate_conv := L_Retirement_Prorate_Conv(i);
708 g_units := L_Units(i);
709 g_cost_of_removal := L_Cost_Of_Removal(i);
710 g_proceeds_of_sale := L_Proceeds_Of_Sale(i);
711 g_retirement_type_code := L_Retirement_Type_Code(i);
712 g_reference_num := L_Reference_Num(i);
713 g_sold_to := L_Sold_To(i);
714 g_trade_in_asset_id := L_Trade_In_Asset_Id(i);
715 g_calc_gain_loss_flag := L_Calc_Gain_Loss_Flag(i);
716 g_stl_method_code := L_Stl_Method_Code(i);
717 g_stl_life_in_months := L_Stl_Life_In_Months(i);
718 g_stl_deprn_amount := L_Stl_Deprn_Amount(i);
719 g_last_update_login := L_Last_Update_Login(i);
720 g_today_datetime := L_Today_Datetime(i);
721 g_currency_code := L_Currency_Code(i);
722 g_set_of_books_id := L_Set_of_Books_Id(i);
723 g_current_units := L_Current_Units(i);
724 g_asset_number := L_Asset_Number(i);
725 g_period_counter_fully_retired := L_Period_Counter_Fully_Retired(i);
726 /* 8483118(R12) and 8206076(11i) - Start */
727 g_recognize_gain_loss := L_Recognize_Gain_Loss(i);
728 g_recapture_reserve_flag := L_Recapture_Reserve_Flag(i);
729 g_limit_proceeds_flag := L_Limit_Proceeds_Flag(i);
730 g_terminal_gain_loss := L_Terminal_Gain_Loss(i);
731 /* 8483118(R12) and 8206076(11i) - End */
732 g_distribution_id := L_Distribution_Id(i);
733 g_code_combination_id := L_Code_combination_id(i);
734 g_location_id := L_location_id(i);
735 g_assigned_to := L_assigned_to(i);
736 g_th_attribute_category := L_TH_Attribute_Category(i);
737 g_th_attribute1 := L_TH_Attribute1(i);
738 g_th_attribute2 := L_TH_Attribute2(i);
739 g_th_attribute3 := L_TH_Attribute3(i);
740 g_th_attribute4 := L_TH_Attribute4(i);
741 g_th_attribute5 := L_TH_Attribute5(i);
742 g_th_attribute6 := L_TH_Attribute6(i);
743 g_th_attribute7 := L_TH_Attribute7(i);
744 g_th_attribute8 := L_TH_Attribute8(i);
745 g_th_attribute9 := L_TH_Attribute9(i);
746 g_th_attribute10 := L_TH_Attribute10(i);
747 g_th_attribute11 := L_TH_Attribute11(i);
748 g_th_attribute12 := L_TH_Attribute12(i);
749 g_th_attribute13 := L_TH_Attribute13(i);
750 g_th_attribute14 := L_TH_Attribute14(i);
751 g_th_attribute15 := L_TH_Attribute15(i);
752 g_attribute_category := L_Attribute_Category(i);
753 g_attribute1 := L_Attribute1(i);
754 g_attribute2 := L_Attribute2(i);
755 g_attribute3 := L_Attribute3(i);
756 g_attribute4 := L_Attribute4(i);
757 g_attribute5 := L_Attribute5(i);
758 g_attribute6 := L_Attribute6(i);
759 g_attribute7 := L_Attribute7(i);
760 g_attribute8 := L_Attribute8(i);
761 g_attribute9 := L_Attribute9(i);
762 g_attribute10 := L_Attribute10(i);
763 g_attribute11 := L_Attribute11(i);
764 g_attribute12 := L_Attribute12(i);
765 g_attribute13 := L_Attribute13(i);
766 g_attribute14 := L_Attribute14(i);
767 g_attribute15 := L_Attribute15(i);
768
769 IF (g_log_level_rec.statement_level) then
770 fa_debug_pkg.add('FACXTREMB.pls',
771 'Before Validation subblock: asset_id',
772 g_asset_id, p_log_level_rec => g_log_level_rec);
773 END IF;
774
775 -- test if muliple partial unit retirements with same batch and asset.
776 -- declare:
777
778
779
780 Begin
781 -- validation subblock to stay in loop if failure
782
783 if (g_asset_id <> g_prev_asset_id or
784 g_batch_name <> g_prev_batch_name) then
785
786
787
788
789
790 select count(*)
791 into g_num_of_distributions
792 from fa_mass_ext_retirements
793 where batch_name = G_batch_name
794 and review_status = 'POST'
795 and asset_id = g_asset_id
796 and code_combination_id is not null
797 and mass_external_retire_id <> g_mass_external_retire_id;
798
799
800 IF (g_log_level_rec.statement_level) then
801 fa_debug_pkg.add('FACXTREMB.pls',
802 'g_num_of_distributiosn:',
803 g_num_of_distributions , p_log_level_rec => g_log_level_rec);
804
805 end if;
806
807 g_single_dist_array := 'NO';
808
809 select count(*)
810 into g_num_of_identical
811 from fa_mass_ext_retirements
812 where batch_name = G_batch_name
813 and review_status = 'POST'
814 and asset_id = g_asset_id
815 and code_combination_id is not null;
816
817 if g_num_of_identical > 0 then
818 -- note, make this select fault tolerant, i.e. explicit cursor.
819
820 open c_dhident;
821 fetch c_dhident into g_test_ident_distributions;
822 close c_dhident;
823
824 if g_test_ident_distributions > 0 then
825 g_single_dist_array := 'YES';
826 end if;
827
828 IF (g_log_level_rec.statement_level) then
829 fa_debug_pkg.add('FACXTREMB.pls',
830 'g_single_dist_array:',
831 g_single_dist_array , p_log_level_rec => g_log_level_rec);
832 end if;
833
834
835 end if;
836 -- end test
837
838 -- Deleting table only when changing asset, also when changing batch...?
839 l_asset_dist_tbl.delete;
840
841 IF (g_log_level_rec.statement_level) then
842 fa_debug_pkg.add('FACXTREMB.pls',
843 'Number of distributions:',
844 g_num_of_distributions, p_log_level_rec => g_log_level_rec);
845 fa_debug_pkg.add('FACXTREMB.pls',
846 'test ident distributions:',
847 g_test_ident_distributions, p_log_level_rec => g_log_level_rec);
848
849 END IF;
850
851 end if;
852
853 if(nvl(g_period_counter_fully_retired,0) > 0) then
854 lv_app:= 'OFA';
855 lv_message := 'FA_REC_RETIRED';
856 raise Fully_Reserved_Error;
857 end if;
858
859
860 -- bug 1857395
861 -- While ccid and location_id are mandatory in fa_distribution_history;
862 -- if any of these two are entered; both must be.
863
864 If nvl(G_Distribution_Id,0) = 0 then
865 If (nvl(G_Code_Combination_Id,0) <> 0
866 and nvl(G_Location_Id,0) <> 0 ) then
867
868 -- Derive distribution_id,
869
870 open c_dh;
871 fetch c_dh into dhrec;
872
873 If c_dh%NOTFOUND then
874 close c_dh;
875
876 lv_app:= 'CUA';
877 lv_message := 'CUA_MAP_DISTRIBUTION';
878 raise validation_error;
879 end if;
880 close c_dh;
881 -- Perform distribution validation here.
882
883 if dhrec.units_assigned < g_units then
884 lv_app:= 'OFA';
885 lv_message := 'FA_RET_UNITS_TOO_BIG';
886 raise validation_error;
887 end if;
888 if dhrec.date_ineffective is not null then
889 lv_app:= 'OFA';
890 lv_message := 'FA_RBL_DIST';
891 raise validation_error;
892 end if;
893 -- bug 9555594. Changed g_units < 1 to g_units <0
894 -- for partial unit ret, if ret unit < 1
895 if g_units < 0 then
896 lv_app:= 'OFA';
897 lv_message := 'FA_TFR_NONZERO';
898 raise validation_error;
899 end if;
900
901 g_distribution_id := dhrec.distribution_id;
902
903 -- bug 1857395 - validation.
904 elsif (nvl(G_Code_Combination_Id,0) <> 0
905 and nvl(G_Location_Id,0) = 0 ) then
906 lv_app:= 'CUA';
907 lv_message := 'CUA_INVALID_LOCATION';
908 raise validation_error;
909
910 elsif (nvl(G_Code_Combination_Id,0) = 0
911 and nvl(G_Location_Id,0) <> 0 ) then
912 lv_app:= 'CUA';
913 lv_message := 'CUA_INVALID_EXPENSE_ACCOUNT';
914 raise validation_error;
915 else
916 null;
917 end if;
918
919 end if; -- if distribution_id null
920
921 IF (g_log_level_rec.statement_level) then
922 fa_debug_pkg.add('FACXTREMB.pls',
923 'Before validate call mass_ext_ret_id ',
924 g_mass_external_retire_id, p_log_level_rec => g_log_level_rec);
925 END IF;
926
927 -- modified and added additional logic for bugfix 2036777
928
929 IF (g_log_level_rec.statement_level) then
930 fa_debug_pkg.add('FACXTREMB.pls',
931 'Before source line retirement loop: lv_new_inv_txn_id',
932 lv_new_inv_txn_id, p_log_level_rec => g_log_level_rec);
933 END IF;
934
935
936 k := 0;
937 l_inv_tbl.delete;
938 For Source_lines_rec in Source_lines_C Loop
939
940 IF (g_log_level_rec.statement_level) then
941 fa_debug_pkg.add('FACXTREMB.pls',
942 'In source line retirement loop:',
943 source_lines_rec.source_line_id, p_log_level_rec => g_log_level_rec);
944 END IF;
945
946 k := k +1;
947
948 OPEN C3( Source_lines_rec.source_line_id);
949 FETCH C3 into C3_lines;
950 if C3%NOTFOUND then
951 lv_app:= 'CUA';
952 lv_message := 'CUA_INVALID_SOURCE_LINE_ID';
953 CLOSE C3;
954 raise validation_error;
955 end if;
956 CLOSE C3;
957
958 -- Populate inv_rec here...
959
960 -- ***** Invoice Info ***** --
961
962 IF (g_log_level_rec.statement_level) then
963 fa_debug_pkg.add('FACXTREMB.pls',
964 'In source line loop 2: c3_lines.slid',
965 c3_lines.source_line_id, p_log_level_rec => g_log_level_rec);
966 END IF;
967 -- Use C3_lines.Source_Line_ID, due to bug 2036777
968 -- l_inv_rec.source_line_id := source_lines_rec.source_line_id;
969
970 l_inv_rec.source_line_id := C3_lines.source_line_id;
971 If source_lines_rec.cost_retired > 0 then
972 l_inv_rec.fixed_assets_cost := source_lines_rec.cost_retired * -1;
973 else
974 l_inv_rec.fixed_assets_cost := source_lines_rec.cost_retired;
975 end if;
976 l_inv_rec.inv_indicator := k;
977
978 update fa_ext_inv_retirements
979 set source_line_id_retired = l_inv_rec.source_line_id
980 where source_line_id = l_inv_rec.source_line_id;
981
982 l_inv_tbl(k) := l_inv_rec;
983
984 end loop;
985
986 IF (g_log_level_rec.statement_level) then
987 fa_debug_pkg.add('FACXTREMB.pls',
988 'Before loading arrays: Transaction_name ',
989 g_transaction_name, p_log_level_rec => g_log_level_rec);
990 END IF;
991
992 -- Load array structures before calling do_retirement
993 -- ***** Asset Transaction Info ***** --
994 -- activate when mass_transaction_id exists in trans_rec.
995 -- mass_transaction_id only populated where we have a prim-foreign key relation
996 IF (g_log_level_rec.statement_level) then
997 fa_debug_pkg.add('FACXTREMB.pls',
998 'Loading arrays: g_Batch_name ',
999 g_batch_name, p_log_level_rec => g_log_level_rec);
1000 END IF;
1001
1002
1003
1004 if substr(g_batch_name,1,8) = 'MASSRET-' then
1005 l_trans_rec.mass_transaction_id := to_number(substr(g_batch_name,9,30));
1006 end if;
1007
1008 IF (g_log_level_rec.statement_level) then
1009 fa_debug_pkg.add('FACXTREMB.pls',
1010 'Loading arrays: Mass trx id ',
1011 l_trans_rec.mass_transaction_id, p_log_level_rec => g_log_level_rec);
1012 END IF;
1013
1014 l_trans_rec.transaction_header_id := ''; -- will get assigned in do_retirement
1015 l_trans_rec.transaction_type_code := ''; -- " --
1016 l_trans_rec.transaction_date_entered := g_date_retired;
1017 l_trans_rec.transaction_name := g_transaction_name;
1018 l_trans_rec.source_transaction_header_id := ''; -- " --
1019 l_trans_rec.mass_reference_id := P_PARENT_REQUEST_ID;
1020 l_trans_rec.transaction_subtype := ''; -- will get assigned in do_retirem
1021 l_trans_rec.transaction_key := ''; -- " --
1022 l_trans_rec.amortization_start_date := ''; -- " --
1023 l_trans_rec.calling_interface := g_calling_interface;
1024 l_trans_rec.desc_flex.attribute1 := g_th_attribute1;
1025 l_trans_rec.desc_flex.attribute2 := g_th_attribute2;
1026 l_trans_rec.desc_flex.attribute3 := g_th_attribute3;
1027 l_trans_rec.desc_flex.attribute4 := g_th_attribute4;
1028 l_trans_rec.desc_flex.attribute5 := g_th_attribute5;
1029 l_trans_rec.desc_flex.attribute6 := g_th_attribute6;
1030 l_trans_rec.desc_flex.attribute7 := g_th_attribute7;
1031 l_trans_rec.desc_flex.attribute8 := g_th_attribute8;
1032 l_trans_rec.desc_flex.attribute9 := g_th_attribute9;
1033 l_trans_rec.desc_flex.attribute10 := g_th_attribute10;
1034 l_trans_rec.desc_flex.attribute11 := g_th_attribute11;
1035 l_trans_rec.desc_flex.attribute12 := g_th_attribute12;
1036 l_trans_rec.desc_flex.attribute13 := g_th_attribute13;
1037 l_trans_rec.desc_flex.attribute14 := g_th_attribute14;
1038 l_trans_rec.desc_flex.attribute15 := g_th_attribute15;
1039 l_trans_rec.desc_flex.attribute_category_code :=
1040 g_th_attribute_category;
1041 l_trans_rec.who_info.last_update_date := G_Today_Datetime;
1042 l_trans_rec.who_info.last_updated_by := G_Created_By;
1043 l_trans_rec.who_info.created_by := G_created_by;
1044 l_trans_rec.who_info.creation_date := G_Today_Datetime;
1045 l_trans_rec.who_info.last_update_login := G_last_update_login;
1046 l_trans_rec.event_id := '' ; -- Bug 11728924
1047
1048 -- ***** Distribution Transaction Info ***** --
1049
1050 l_dist_trans_rec.transaction_header_id := ''; -- get assigned in do_retirem.
1051 l_dist_trans_rec.transaction_date_entered := g_date_retired;
1052 l_dist_trans_rec.transaction_name := g_transaction_name;
1053 l_dist_trans_rec.calling_interface := g_calling_interface;
1054 -- No dist desc flex
1055 l_dist_trans_rec.desc_flex.attribute1 := g_th_attribute1;
1056 l_dist_trans_rec.desc_flex.attribute2 := g_th_attribute2;
1057 l_dist_trans_rec.desc_flex.attribute3 := g_th_attribute3;
1058 l_dist_trans_rec.desc_flex.attribute4 := g_th_attribute4;
1059 l_dist_trans_rec.desc_flex.attribute5 := g_th_attribute5;
1060 l_dist_trans_rec.desc_flex.attribute6 := g_th_attribute6;
1061 l_dist_trans_rec.desc_flex.attribute7 := g_th_attribute7;
1062 l_dist_trans_rec.desc_flex.attribute8 := g_th_attribute8;
1063 l_dist_trans_rec.desc_flex.attribute9 := g_th_attribute9;
1064 l_dist_trans_rec.desc_flex.attribute10 := g_th_attribute10;
1065 l_dist_trans_rec.desc_flex.attribute11 := g_th_attribute11;
1066 l_dist_trans_rec.desc_flex.attribute12 := g_th_attribute12;
1067 l_dist_trans_rec.desc_flex.attribute13 := g_th_attribute13;
1068 l_dist_trans_rec.desc_flex.attribute14 := g_th_attribute14;
1069 l_dist_trans_rec.desc_flex.attribute15 := g_th_attribute15;
1070 l_dist_trans_rec.desc_flex.attribute_category_code := g_th_attribute_category;
1071 --
1072 l_dist_trans_rec.who_info.last_update_date := G_Today_Datetime;
1073 l_dist_trans_rec.who_info.last_updated_by := G_Created_By;
1074 l_dist_trans_rec.who_info.created_by := G_created_by;
1075 l_dist_trans_rec.who_info.creation_date := G_Today_Datetime;
1076 l_dist_trans_rec.who_info.last_update_login := G_last_update_login;
1077
1078 -- ***** Asset Header Info ***** --
1079 l_asset_hdr_rec.asset_id := G_asset_id;
1080 l_asset_hdr_rec.book_type_code := G_book_type_code;
1081
1082 -- Derive set of books id for primary book
1083 l_asset_hdr_rec.set_of_books_id := G_set_of_books_id;
1084
1085 IF (g_log_level_rec.statement_level) then
1086 fa_debug_pkg.add('FACXTREMB.pls',
1087 'Before loading Retirement1 arrays: cost_retired ',
1088 g_cost_retired, p_log_level_rec => g_log_level_rec);
1089 fa_debug_pkg.add('FACXTREMB.pls',
1090 'Before loading Retirement1 arrays: units_retired ',
1091 g_units, p_log_level_rec => g_log_level_rec);
1092 END IF;
1093
1094 -- ***** Asset Retirement Info ***** --
1095 l_asset_retire_rec.retirement_id := '';
1096 l_asset_retire_rec.date_retired := g_date_retired;
1097 l_asset_retire_rec.units_retired := g_units;
1098 l_asset_retire_rec.cost_retired := g_cost_retired;
1099 l_asset_retire_rec.proceeds_of_sale := g_proceeds_of_sale;
1100 l_asset_retire_rec.cost_of_removal := g_cost_of_removal;
1101 l_asset_retire_rec.retirement_type_code := g_retirement_type_code;
1102 l_asset_retire_rec.retirement_prorate_convention := g_retirement_prorate_conv;
1103 l_asset_retire_rec.detail_info.stl_method_code := g_stl_method_code;
1104 l_asset_retire_rec.detail_info.stl_life_in_months := g_stl_life_in_months;
1105 l_asset_retire_rec.sold_to := g_sold_to;
1106 l_asset_retire_rec.trade_in_asset_id := g_trade_in_asset_id;
1107 l_asset_retire_rec.status := 'PENDING';
1108 l_asset_retire_rec.reference_num := g_reference_num;
1109 -- this parameter gives an option to run gain/loss right after the transaction.
1110 -- retirement api is using fnd_api.g_true/g_false
1111 -- converting potential Y and N to fnd_api.g_true/g_false.
1112 --
1113 if g_calc_gain_loss_flag in ('Y','YES') then
1114 g_calc_gain_loss_flag := fnd_api.g_true;
1115 elsif g_calc_gain_loss_flag in ('N','NO') then
1116 g_calc_gain_loss_flag := fnd_api.g_false;
1117 end if;
1118 l_asset_retire_rec.calculate_gain_loss := g_calc_gain_loss_flag;
1119 l_asset_retire_rec.desc_flex.attribute1 := g_attribute1;
1120 l_asset_retire_rec.desc_flex.attribute2 := g_attribute2;
1121 l_asset_retire_rec.desc_flex.attribute3 := g_attribute3;
1122 l_asset_retire_rec.desc_flex.attribute4 := g_attribute4;
1123 l_asset_retire_rec.desc_flex.attribute5 := g_attribute5;
1124 l_asset_retire_rec.desc_flex.attribute6 := g_attribute6;
1125 l_asset_retire_rec.desc_flex.attribute7 := g_attribute7;
1126 L_asset_retire_rec.desc_flex.attribute8 := g_attribute8;
1127 l_asset_retire_rec.desc_flex.attribute9 := g_attribute9;
1128 l_asset_retire_rec.desc_flex.attribute10 := g_attribute10;
1129 l_asset_retire_rec.desc_flex.attribute11 := g_attribute11;
1130 l_asset_retire_rec.desc_flex.attribute12 := g_attribute12;
1131 l_asset_retire_rec.desc_flex.attribute13 := g_attribute13;
1132 l_asset_retire_rec.desc_flex.attribute14 := g_attribute14;
1133 l_asset_retire_rec.desc_flex.attribute15 := g_attribute15;
1134 l_asset_retire_rec.desc_flex.attribute_category_code :=
1135 g_attribute_category;
1136 /* Bug 8483118(R12) and 8206076(11i) - Start */
1137 l_asset_retire_rec.recognize_gain_loss := g_recognize_gain_loss;
1138 l_asset_retire_rec.recapture_reserve_flag := g_recapture_reserve_flag;
1139 l_asset_retire_rec.limit_proceeds_flag := g_limit_proceeds_flag;
1140 l_asset_retire_rec.terminal_gain_loss := g_terminal_gain_loss;
1141 /* Bug 8483118(R12) and 8206076(11i) - End */
1142
1143 IF (g_log_level_rec.statement_level) then
1144 fa_debug_pkg.add('FACXTREMB.pls',
1145 'Before loading dist arrays g_units',
1146 g_units, p_log_level_rec => g_log_level_rec);
1147 fa_debug_pkg.add('FACXTREMB.pls',
1148 'Before loading dist arrays g_current_units',
1149 g_current_units, p_log_level_rec => g_log_level_rec);
1150 END IF;
1151
1152
1153 -- The dist info should only be loaded when partial unit retirement.
1154
1155 if ( nvl(G_Units,0) <> 0 and G_Units < G_current_units) then
1156 -- ***** Asset Distribution Info ***** --
1157 IF (g_log_level_rec.statement_level) then
1158 fa_debug_pkg.add('FACXTREMB.pls',
1159 'Before loading dist arrays inside if',
1160 g_current_units, p_log_level_rec => g_log_level_rec);
1161 END IF;
1162
1163
1164
1165 if (g_asset_id <> g_prev_asset_id or g_batch_name <> g_prev_batch_name) OR
1166 ( g_single_dist_array = 'YES' ) then
1167 num_dist := 1;
1168 else
1169 num_dist := num_dist + 1;
1170 end if;
1171
1172
1173 l_asset_dist_rec.units_assigned := NULL;
1174
1175 if g_units >= 0 then
1176 l_asset_dist_rec.transaction_units := g_units * -1;
1177 else
1178 l_asset_dist_rec.transaction_units := g_units;
1179 end if;
1180 l_asset_dist_rec.assigned_to := g_assigned_to;
1181 l_asset_dist_rec.expense_ccid := g_code_combination_id;
1182 l_asset_dist_rec.location_ccid := g_location_id;
1183 -- fails if distribution_id is null.
1184 l_asset_dist_rec.distribution_id := g_distribution_id;
1185 l_asset_dist_tbl(num_dist) := l_asset_dist_rec;
1186
1187 IF (g_log_level_rec.statement_level) then
1188 fa_debug_pkg.add('FACXTREMB.pls',
1189 'Before loading dist arrays inside if',
1190 num_dist, p_log_level_rec => g_log_level_rec);
1191 fa_debug_pkg.add('FACXTREMB.pls',
1192 'Before loading dist arrays inside if',
1193 g_distribution_id, p_log_level_rec => g_log_level_rec);
1194 fa_debug_pkg.add('FACXTREMB.pls',
1195 'Before loading dist arrays inside if',
1196 g_location_id, p_log_level_rec => g_log_level_rec);
1197 fa_debug_pkg.add('FACXTREMB.pls',
1198 'Before loading dist arrays inside if',
1199 g_code_combination_id, p_log_level_rec => g_log_level_rec);
1200 fa_debug_pkg.add('FACXTREMB.pls',
1201 'Before loading dist arrays inside if',
1202 l_asset_dist_rec.transaction_units, p_log_level_rec => g_log_level_rec);
1203 END IF;
1204
1205 end if;
1206
1207 l_tot_units := 0;
1208 for dist_i in 1 .. l_asset_dist_tbl.COUNT loop
1209
1210 l_tot_units := l_tot_units + abs(l_asset_dist_tbl(dist_i).transaction_units);
1211 l_asset_retire_rec.units_retired := l_tot_units;
1212
1213 end loop;
1214
1215 if l_tot_units = g_current_units then
1216 l_asset_retire_rec.units_retired := l_tot_units;
1217 l_asset_dist_tbl.delete;
1218 end if;
1219
1220
1221 l_subcomp_tbl.delete;
1222
1223 -- l_init_msg_list should be set to false
1224 -- Call Public Retirement API
1225
1226 if (g_num_of_distributions = 0) OR (g_single_dist_array = 'YES') then
1227
1228 IF (g_log_level_rec.statement_level) then
1229 fa_debug_pkg.add('FACXTREMB.pls',
1230 'Before do_retirement call ',
1231 G_Asset_Number, p_log_level_rec => g_log_level_rec);
1232 END IF;
1233
1234
1235 fa_retirement_pub.do_retirement
1236 (p_api_version => l_api_version,
1237 p_init_msg_list => l_init_msg_list,
1238 p_commit => l_commit,
1239 p_validation_level => l_validation_level,
1240 p_calling_fn => l_calling_fn,
1241 x_return_status => l_return_status,
1242 x_msg_count => l_msg_count,
1243 x_msg_data => x_msg_data,
1244 px_trans_rec => l_trans_rec,
1245 px_dist_trans_rec => l_dist_trans_rec,
1246 px_asset_hdr_rec => l_asset_hdr_rec,
1247 px_asset_retire_rec => l_asset_retire_rec,
1248 p_asset_dist_tbl => l_asset_dist_tbl,
1249 p_subcomp_tbl => l_subcomp_tbl,
1250 p_inv_tbl => l_inv_tbl);
1251
1252 IF (g_log_level_rec.statement_level) then
1253 fa_debug_pkg.add('FACXTREMB.pls',
1254 'After do_retirement call, status',
1255 l_return_status, p_log_level_rec => g_log_level_rec);
1256 fa_debug_pkg.add('FACXTREMB.pls',
1257 'After do_retirement call, msg_count',
1258 l_msg_count, p_log_level_rec => g_log_level_rec);
1259 fa_debug_pkg.add('FACXTREMB.pls',
1260 'After do_retirement call, x_msg_data',
1261 x_msg_data, p_log_level_rec => g_log_level_rec);
1262
1263 END IF;
1264
1265
1266 if (l_return_status <> FND_API.G_RET_STS_SUCCESS) then
1267 raise G_Subroutine_Fail;
1268 else
1269 G_success_count := G_success_count + 1;
1270 x_success_count := x_success_count + 1;
1271 end if;
1272 if (g_single_dist_array = 'YES') then
1273 l_asset_dist_tbl.delete;
1274 end if;
1275
1276 -- test
1277 -- probably not necessary to reduce if g_test_ident_distributions
1278 elsif g_num_of_distributions > 0 then
1279 g_num_of_distributions := g_num_of_distributions - 1;
1280 G_success_count := G_success_count + 1;
1281 x_success_count := x_success_count + 1;
1282
1283 IF (g_log_level_rec.statement_level) then
1284 fa_debug_pkg.add('FACXTREMB.pls',
1285 'Skipped do_retirement call ',
1286 g_num_of_distributions, p_log_level_rec => g_log_level_rec);
1287 END IF;
1288
1289 end if; -- num_of_distribution
1290
1291 UPDATE fa_mass_Ext_retirements
1292 SET review_status = 'POSTED',
1293 -- bugfix 2442439 retirement_id = lv_ret_id
1294 retirement_id = l_asset_retire_rec.retirement_id,
1295 last_update_date = sysdate,
1296 last_updated_by = fnd_global.user_id,
1297 last_update_login = fnd_global.login_id
1298 WHERE mass_external_retire_id = G_Mass_External_Retire_Id;
1299
1300 Commit;
1301
1302 write_message
1303 (p_asset_number => g_asset_number,
1304 p_book_type_code => g_book_type_code,
1305 p_mass_external_retire_id => g_mass_external_retire_id,
1306 p_message => 'FA_MCP_RETIRE_SUCCESS',
1307 p_token => '',
1308 p_value => '',
1309 p_app_short_name => 'OFA',
1310 p_db_error => '',
1311 p_mode => 'S');
1312
1313 Exception
1314 WHEN G_Subroutine_Fail THEN
1315
1316 if (g_log_level_rec.statement_level) then
1317 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
1318 end if;
1319
1320 UPDATE fa_mass_Ext_retirements
1321 SET review_status = 'ERROR',
1322 last_update_date = sysdate,
1323 last_updated_by = fnd_global.user_id,
1324 last_update_login = fnd_global.login_id
1325 WHERE mass_external_retire_id = G_Mass_External_Retire_Id;
1326
1327 -- non-fatal
1328 write_message(
1329 p_asset_number => g_asset_number,
1330 p_book_type_code => g_book_type_code,
1331 p_mass_external_retire_id => g_mass_external_retire_id,
1332 p_message => 'FA_POST_MASSRET_FAILURE',
1333 p_token => '',
1334 p_value => '',
1335 p_app_short_name => 'OFA',
1336 p_db_error => '',
1337 p_mode => 'W');
1338
1339 fa_srvr_msg.add_message(calling_fn => l_calling_fn, p_log_level_rec => g_log_level_rec);
1340 -- x_return_status := FND_API.G_RET_STS_ERROR;
1341
1342 FND_CONCURRENT.AF_COMMIT;
1343 x_return_status := 1;
1344
1345 WHEN Validation_Error THEN
1346
1347 FND_CONCURRENT.AF_ROLLBACK;
1348 if(g_log_level_rec.statement_level) then
1349 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
1350 end if;
1351
1352 UPDATE fa_mass_Ext_retirements
1353 SET review_status = 'ERROR',
1354 last_update_date = sysdate,
1355 last_updated_by = fnd_global.user_id,
1356 last_update_login = fnd_global.login_id
1357 WHERE mass_external_retire_id = G_Mass_External_Retire_Id;
1358
1359
1360 if lv_message = '' then
1361 write_message(
1362 p_asset_number => g_asset_number,
1363 p_book_type_code => g_book_type_code,
1364 p_mass_external_retire_id => g_mass_external_retire_id,
1365 p_message => 'FA_POST_MASSRET_FAILURE',
1366 p_token => '',
1367 p_value => '',
1368 p_app_short_name => 'OFA',
1369 p_db_error => '',
1370 p_mode => 'W');
1371
1372 else
1373 write_message(
1374 p_asset_number => g_asset_number,
1375 p_book_type_code => g_book_type_code,
1376 p_mass_external_retire_id => g_mass_external_retire_id,
1377 p_message => lv_message,
1378 p_token => '',
1379 p_value => '',
1380 p_app_short_name => lv_app,
1381 p_db_error => '',
1382 p_mode => 'W');
1383
1384 end if;
1385 FND_CONCURRENT.AF_COMMIT;
1386 x_return_status := 1;
1387
1388 WHEN Fully_Reserved_Error THEN
1389
1390 FND_CONCURRENT.AF_ROLLBACK;
1391 if(g_log_level_rec.statement_level) then
1392 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
1393 end if;
1394
1395 UPDATE fa_mass_Ext_retirements
1396 SET review_status = 'ERROR',
1397 last_update_date = sysdate,
1398 last_updated_by = fnd_global.user_id,
1399 last_update_login = fnd_global.login_id
1400 WHERE mass_external_retire_id = G_Mass_External_Retire_Id;
1401
1402 write_message(
1403 p_asset_number => g_asset_number,
1404 p_book_type_code => g_book_type_code,
1405 p_mass_external_retire_id => g_mass_external_retire_id,
1406 p_message => 'FA_REC_RETIRED',
1407 p_token => '',
1408 p_value => '',
1409 p_app_short_name => 'OFA',
1410 p_db_error => '',
1411 p_mode => 'W');
1412
1413 FND_CONCURRENT.AF_COMMIT;
1414 x_return_status := 1;
1415
1416
1417 WHEN OTHERS THEN
1418
1419 FND_CONCURRENT.AF_COMMIT;
1420
1421 if(g_log_level_rec.statement_level) then
1422 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
1423 end if;
1424
1425 UPDATE fa_mass_Ext_retirements
1426 SET review_status = 'ERROR',
1427 last_update_date = sysdate,
1428 last_updated_by = fnd_global.user_id,
1429 last_update_login = fnd_global.login_id
1430 WHERE mass_external_retire_id = G_Mass_External_Retire_Id;
1431
1432 write_message(
1433 p_asset_number => g_asset_number,
1434 p_book_type_code => g_book_type_code,
1435 p_mass_external_retire_id => g_mass_external_retire_id,
1436 p_message => '',
1437 p_token => '',
1438 p_value => '',
1439 p_app_short_name => lv_message,
1440 p_db_error => SQLCODE,
1441 p_mode => 'W');
1442
1443 FND_CONCURRENT.AF_COMMIT;
1444 x_return_status := 1;
1445
1446 End; /* validation subblock ends */
1447
1448 g_prev_asset_id := g_asset_id;
1449 g_prev_batch_name := g_batch_name;
1450 END LOOP; -- mass_external_retirement
1451
1452 -- set the max id
1453
1454 px_max_mass_ext_retire_id := l_mass_external_retire_id
1455 (l_mass_external_retire_id.count);
1456 px_batch_name := l_batch_name(l_batch_name.count);
1457
1458 x_failure_count := G_failure_count;
1459 x_success_count := G_success_count;
1460 x_return_status := 0;
1461
1462
1463
1464 if (g_log_level_rec.statement_level) then
1465 fa_debug_pkg.add(l_calling_fn, 'px_max_mass_ext_retire_id', px_max_mass_ext_retire_id, p_log_level_rec => g_log_level_rec);
1466 fa_debug_pkg.add(l_calling_fn, 'End of Mass External Retirement session', x_return_status, p_log_level_rec => g_log_level_rec);
1467 end if;
1468
1469 if (g_log_level_rec.statement_level) then
1470 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
1471 end if;
1472
1473
1474 EXCEPTION -- Mass_Ext_Retire
1475
1476 WHEN done_exc then
1477 x_success_count := G_success_count;
1478 x_failure_count := G_failure_count;
1479 x_return_status := 0;
1480 FND_CONCURRENT.AF_COMMIT;
1481
1482 if (g_log_level_rec.statement_level) then
1483 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
1484 end if;
1485
1486 -- msiddiqu Feb-24-2001
1487 WHEN pending_batch THEN
1488
1489 FND_CONCURRENT.AF_COMMIT;
1490
1491 UPDATE fa_mass_Ext_retirements
1492 SET review_status = 'ERROR',
1493 last_update_date = sysdate,
1494 last_updated_by = fnd_global.user_id,
1495 last_update_login = fnd_global.login_id
1496 WHERE batch_name = nvl(px_batch_name,batch_name)
1497 AND book_type_code = p_book_type_code;
1498
1499 write_message(
1500 p_asset_number => g_asset_number,
1501 p_book_type_code => g_book_type_code,
1502 p_mass_external_retire_id => g_mass_external_retire_id,
1503 p_message => lv_message,
1504 p_token => '',
1505 p_value => '',
1506 p_app_short_name => lv_app,
1507 p_db_error => '',
1508 p_mode => 'W');
1509
1510 x_success_count := G_success_count;
1511 x_failure_count := G_failure_count;
1512
1513 -- end of modification msiddiqu Feb-24-2001
1514 FND_CONCURRENT.AF_COMMIT;
1515 x_return_status := 2;
1516
1517 if (g_log_level_rec.statement_level) then
1518 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
1519 end if;
1520
1521
1522 WHEN Init_problem THEN
1523
1524 FND_CONCURRENT.AF_COMMIT;
1525
1526 write_message(
1527 p_asset_number => g_asset_number,
1528 p_book_type_code => g_book_type_code,
1529 p_mass_external_retire_id => g_mass_external_retire_id,
1530 p_message => '',
1531 p_token => '',
1532 p_value => '',
1533 p_app_short_name => 'When Init_problem Exception in Mass_Ext_Retire',
1534 p_db_error => '',
1535 p_mode => 'F');
1536
1537 x_success_count := G_success_count;
1538 x_failure_count := G_failure_count;
1539
1540 x_return_status := 2;
1541
1542 if (g_log_level_rec.statement_level) then
1543 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
1544 end if;
1545
1546
1547 WHEN Others THEN
1548
1549 FND_CONCURRENT.AF_COMMIT;
1550
1551 write_message(
1552 p_asset_number => g_asset_number,
1553 p_book_type_code => g_book_type_code,
1554 p_mass_external_retire_id => g_mass_external_retire_id,
1555 p_message => '',
1556 p_token => '',
1557 p_value => '',
1558 p_app_short_name => 'When Others Exception in Mass_Ext_Retire',
1559 p_db_error => '',
1560 p_mode => 'F');
1561
1562 x_success_count := G_success_count;
1563 x_failure_count := G_failure_count;
1564
1565 x_return_status := 2;
1566
1567 if (g_log_level_rec.statement_level) then
1568 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
1569 end if;
1570
1571
1572 END Mass_Ext_Retire;
1573
1574 ------------------------------------------------------------------------------
1575 PROCEDURE Purge(ERRBUF OUT NOCOPY VARCHAR2,
1576 RETCODE OUT NOCOPY VARCHAR2, p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) IS
1577
1578 Cursor Assets_C is
1579 select Mass_External_Retire_ID
1580 from fa_mass_ext_retirements
1581 where review_status in ('DELETE','POSTED')
1582 for update nowait;
1583
1584 LV_Mass_External_Retire_ID NUMBER;
1585 LV_Inv_Count NUMBER;
1586
1587 BEGIN
1588 Open Assets_C;
1589
1590 Loop
1591 Fetch Assets_C into LV_Mass_External_Retire_ID;
1592 Exit when Assets_C%NOTFOUND;
1593
1594 Select count(*) into LV_Inv_Count
1595 from fa_ext_inv_retirements
1596 where mass_external_retire_id = LV_Mass_External_Retire_ID;
1597
1598 if LV_Inv_Count > 0 then
1599 Delete from fa_ext_inv_retirements
1600 where mass_external_retire_id = LV_Mass_External_Retire_ID;
1601 end if;
1602
1603 Delete from fa_mass_ext_retirements
1604 where mass_external_retire_id = LV_Mass_External_Retire_ID;
1605
1606 End Loop;
1607
1608 Close Assets_C;
1609
1610 EXCEPTION
1611 When NO_DATA_FOUND Then
1612 Return;
1613 WHEN OTHERS THEN
1614 errbuf := substr(SQLERRM(SQLCODE), 1,200);
1615 retcode := SQLCODE;
1616 return;
1617 END Purge;
1618
1619
1620 ----------------------------------
1621 -- this is used to maintaint the old execution report seperately
1622 -- from the log. Only the main message will be dumped to out file.
1623 -- all messaging and debug will be demped to the log file
1624
1625 PROCEDURE write_message(
1626 p_asset_number in varchar2,
1627 p_book_type_code in varchar2,
1628 p_mass_external_retire_id in number,
1629 p_message in varchar2,
1630 p_token in varchar2,
1631 p_value in varchar2,
1632 p_app_short_name in varchar2,
1633 p_db_error in number,
1634 p_mode in varchar2 ) IS
1635
1636 l_book_type_code varchar2(30);
1637 l_asset_number varchar2(15);
1638 l_mass_external_retire_id varchar2(20);
1639 l_mesg varchar2(512);
1640 l_string varchar2(512);
1641 l_calling_fn varchar2(40);
1642
1643 BEGIN
1644
1645 if p_mode = 'S' then
1646 -- first dump the message to the output file
1647 -- set/translate/retrieve the mesg from fnd
1648
1649
1650 FND_MESSAGE.SET_NAME(p_app_short_name, p_message);
1651 l_mesg := substrb(FND_MESSAGE.GET,1,100);
1652 l_asset_number := rpad(p_asset_number, 15);
1653 l_mass_external_retire_id := rpad(to_char(p_mass_external_retire_id), 18);
1654
1655 l_string := l_mass_external_retire_id || ' ' || l_asset_number || ' ' ||
1656 l_mesg;
1657
1658
1659
1660 FND_FILE.put(FND_FILE.output,l_string);
1661 FND_FILE.new_line(FND_FILE.output,1);
1662
1663 else
1664 G_failure_count := G_failure_count + 1;
1665
1666 -- only pass calling_fn for failures
1667 if p_mode = 'F' then
1668 -- l_calling_fn := 'fa_cua_mass_ret_pkg';
1669 G_fatal_error := TRUE;
1670 end if;
1671
1672 -- ex. x_app_name = CUA
1673 -- x_app_error = The message name.
1674 IF ( p_app_short_name is not null and
1675 p_message is not null) then
1676 FND_MESSAGE.SET_NAME(p_app_short_name, p_message);
1677 if p_token is not null then
1678 fnd_message.set_token(p_token, p_value);
1679 end if;
1680 l_mesg := substrb(FND_MESSAGE.GET,1,100);
1681 ELSIF p_db_error is not null then
1682 l_mesg := substrb(SQLERRM(p_db_error),1,100);
1683 ELSE
1684 l_mesg := substrb(p_app_short_name,1,100);
1685 END IF;
1686
1687 -- first dump the message to the output file
1688 -- set/translate/retrieve the mesg from fnd
1689
1690 l_asset_number := rpad(p_asset_number, 15);
1691 l_book_type_code := rpad(p_book_type_code,15);
1692 l_mass_external_retire_id := rpad(to_char(p_mass_external_retire_id), 18);
1693
1694 l_string := l_mass_external_retire_id||' '||l_asset_number||' '||l_mesg;
1695
1696 FND_FILE.put(FND_FILE.output,l_string);
1697 FND_FILE.new_line(FND_FILE.output,1);
1698
1699 -- Asset number now printed in beginning of main loop
1700 -- 1/ Print asset_number to logfile
1701 -- if l_asset_number is not null then
1702 -- fa_srvr_msg.add_message(
1703 -- calling_fn => l_calling_fn,
1704 -- name => 'FA_SHARED_ASSET_NUMBER',
1705 -- token1 => 'NUMBER',
1706 -- value1 => l_asset_number, p_log_level_rec => p_log_level_rec);
1707 -- end if;
1708
1709 -- 2/ Print message
1710 if p_message is not null then
1711 fa_srvr_msg.add_message
1712 (calling_fn => l_calling_fn,
1713 name => p_message,
1714 token1 => p_token,
1715 value1 => p_value, p_log_level_rec => g_log_level_rec);
1716 end if;
1717 end if;
1718
1719 EXCEPTION
1720 when others then
1721 raise;
1722 END ;
1723
1724 END FA_CUA_MASS_EXT_RET_PKG;