[Home] [Help]
PACKAGE BODY: APPS.XLA_ACCOUNTING_PKG
Source
1 PACKAGE BODY XLA_ACCOUNTING_PKG AS
2 /* $Header: xlaapeng.pkb 120.164.12010000.5 2009/01/15 10:30:44 nmsubram ship $ */
3 /*===========================================================================+
4 | Copyright (c) 2001-2002 Oracle Corporation |
5 | Redwood Shores, CA, USA |
6 | ALL rights reserved. |
7 +============================================================================+
8 | PACKAGE NAME |
9 | xla_accounting_pkg |
10 | |
11 | DESCRIPTION |
12 | Package body for the Accounting Program. |
13 | |
14 | HISTORY |
15 | 11/08/2002 S. Singhania Created |
16 | 02/07/2003 S. Singhania Made changes TO improve performance using|
17 | BULK architecture. |
18 | 05/21/2003 S. Singhania Fix FOR bug # 2970204. |
19 | 06/11/2003 S. Singhania Added calls TO: |
20 | -XLA_TRANSFER_PKG.GL_TRANSFER_MAIN |
21 | -XLA_BALANCE_PKG.MASSIVE_UPDATE FOR |
22 | UPDATE OF balance |
23 | -post_commit_procedure bug #2957496 |
24 | 06/16/2003 S. Singhania Added code TO LOCK entities BEFORE |
25 | updating EVENTS TABLE. PROCEDURE |
26 | modified : BATCH_ACCOUNTING |
27 | Modified THE CURSOR TO REF CURSOR IN |
28 | ENQUEUE_MESSAGES. included filters |
29 | based ON xla_events. |
30 | 06/17/2003 S. Singhania Changed THE NAME OF THE VIEW used |
31 | XLA_EVENT_ENTITIES_V TO |
32 | XLA_ENTITY_EVENTS_V |
33 | 06/26/2003 S. Singhania Bug fix FOR bug # 3022532. (TABLE NAME |
34 | changes.) |
35 | 07/05/2003 S. Singhania Modified code 'spawn child' TO make sure |
36 | children are NOT spawned IF there are |
37 | NO EVENTS TO process. |
38 | 07/17/2003 S. Singhania Fix FOR Bug # 3051978. THE STATEMENT FOR |
39 | UPDATE OF EVENTS IN 'complete_entries' |
40 | IS modified. |
41 | 07/22/2003 S. Singhania Removed THE USE OF CHR FROM THE code |
42 | 07/29/2003 S. Singhania NAME CHANGE FOR objects used IN THE queue|
43 | Removed THE code that does PAD |
44 | incompatibility CHECK. |
45 | Added code TO INSERT program LEVEL errors|
46 | INTO xla_accounting_errors. |
47 | Commented OUT code IN xla_accounting_log |
48 | routine. |
49 | Added THE funtion IS_PARENT_RUNNING |
50 | 07/30/2003 S. Singhania Modified ACCOUNTING_PROGRAM_BATCH, |
51 | UNIT_PROCESSOR_BATCH TO RETURN THE |
52 | p_retcode = 1 IN CASE OF EVENTS IN |
53 | error (bug # 2709397) |
54 | 07/31/2003 S. Singhania Added anonymous BLOCK around EXECUTE |
55 | IMMEDIATE calls. |
56 | 08/05/2003 S. Singhania Added parameter P_ACCOUNTING_FLAG TO |
57 | ACCOUNTING_PROGRAM_DOCUMENT |
58 | Document MODE routines are rewritten. |
59 | Added code IN UNIT_PROCESSOR TO CHECK THE|
60 | error count AND EXIT OUT OF THE LOOP |
61 | AND STOP processing. |
62 | 08/06/2003 S. Singhania Correct PARAMETERS are passed TO THE |
63 | calls TO THE 'pre-processing procedure,|
64 | 'post-processing procedure' AND 'post- |
65 | COMMIT PROCEDURE'. |
66 | 09/09/2003 S. Singhania TO SET error SOURCE, changed THE CALL TO |
67 | XLA_ACCOUNTING_ERR_PKG.SET_ERROR_SOURCE|
68 | 09/17/2003 S. Singhania Performance changes (bug # 3118344) |
69 | - Modified ACCOUNTING_PROGRAM_BATCH TO |
70 | build WHERE condition FOR dynamic SQL|
71 | based ON security PARAMETERS AND |
72 | process CATEGORY code |
73 | - Modified BATCH_ACCOUNTING TO WRITE |
74 | dynamic SQL TO prevent NVL. |
75 | - Modified cursors IN ENQUEUE_MESSAGES |
76 | Added filter FOR MANUAL EVENTS. |
77 | 10/01/2003 S. Singhania NOTE:THIS IS BASED ON xlaapeng.pkb 116.12|
78 | 10/01/2003 S. Singhania Made SOURCE Application Changes. |
79 | (major REWRITE) |
80 | Added semicolon TO THE EXIT STATEMENT. |
81 | (Bug # 3165900) |
82 | Handle THE CASE WHEN Extract PROCEDURE IS|
83 | NOT defined FOR an application. |
84 | (Bug # 3182763) |
85 | 10/15/2003 S. Singhania Fix FOR bug # 2709397 TO SET THE correct |
86 | request status. |
87 | - FOR this defined AND used EXCEPTION |
88 | 'normal_termination' |
89 | 10/31/2003 Shishir Joshi Bug 3220355. Modified INSERT INTO THE |
90 | XLA_EVENTS_GT TABLE. |
91 | 11/18/2003 S. Singhania Bug 3220355. Modified INSERT INTO THE |
92 | XLA_EVENTS_GT TABLE. |
93 | Removed THE NOWAIT FROM THE FOR UPDATE |
94 | statements IN THE batch MODE. |
95 | (Bug # 2697222) |
96 | 11/19/2003 S. Singhania Initilaized 'g_report_request_id' IN THE |
97 | ACCOUNTING_PROGRAM_DOCUMENT so that THE|
98 | EVENTS are stamped correctly WITH THE |
99 | request_id IN THE OFFLINE MODE. |
100 | 11/24/2003 Shishir Joshi Bug 3275659. Modified INSERT INTO THE |
101 | XLA_EVENTS_GT TABLE. |
102 | 11/24/2003 S. Singhania Bug 3275659. |
103 | - Modified INSERT INTO XLA_EVENTS_GT. |
104 | - Added 'p_report_request_id' param TO |
105 | UNIT_PROCESSOR_BATCH |
106 | - Modified SPAWN_CHILD_PROCESSES TO |
107 | included THE NEW parameter WHILE |
108 | submitting XLAACCUP. |
109 | 11/24/2003 S. Singhania Bug 3239212. |
110 | - Added more IF condition TO SET OUT |
111 | variables IN ACCOUNTING_PROGRAM_BATCH|
112 | - Added two OUT PARAMETERS TO routnie |
113 | WAIT_FOR_REQUESTS |
114 | 12/19/2003 S. Singhania Added calls TO sequencing apis FOR THE |
115 | batch MODE. Bug 3000020. |
116 | - modified specs UNIT_PROCESSOR_BATCH |
117 | - added routine SEQUENCING_BATCH_INIT |
118 | - added calls TO sequencing apis IN |
119 | - POST_ACCOUNTING |
120 | - COMPLETE_ENTRIES |
121 | moved COMMIT down AFTER CALL TO THE |
122 | pre-processing PROCEDURE |
123 | 12/19/2003 S. Singhania Modified THE CURSOR's where clause in |
124 | ENQUEUE_MESSAGES. Bug 3327641 |
125 | 01/12/2004 S. Singhania Bug # 3365680. Added hint TO THE UPDATE |
126 | STATEMENT so that INDEX XLA_EVENTS_U1 |
127 | IS always used. |
128 | 01/26/2004 W. Shen Bug # 3339505. replace THE program hook |
129 | WITH workflow business event. |
130 | 02/13/2004 S. Singhania FIXED NOCOPY warnings. |
131 | 02/28/2004 S. Singhania Bug 3416534. Added FND_LOG messages. |
132 | 03/23/2004 S. Singhania Added a parameter p_module TO THE TRACE |
133 | calls AND THE PROCEDURE. |
134 | Made changes FOR handling THE accounting |
135 | OF THE gapless EVENTS. Ffg modified: |
136 | - PRE_ACCOUNTING |
137 | - DOCUMENT_PROCESSOR |
138 | 03/26/2004 S. Singhania Bug 3498491. Added CLEAR messages, WHERE |
139 | ever possible, TO make sure IF there IS|
140 | an EXCEPTION a CLEAR message IS given |
141 | IN THE log FILE. |
142 | 04/28/2004 S. Singhania Cleaned THE FILE, removed commented code|
143 | 05/05/2004 S. Singhania Made changes TO CALL THE NEW api FOR |
144 | balance UPDATE/reversal. |
145 | Verified that ALL THE workflow EVENTS are|
146 | raised IN FINAL AND DRAFT modes. |
147 | Document MODE accounting: |
148 | - Reviewed THE code path |
149 | - Verified CALL TO THE workflows EVENTS|
150 | - Verified CALL TO THE Sequencing apis |
151 | 07/15/2004 W. Shen NEW event status 'R' introduced. |
152 | 08/03/2004 S. Singhania Bug 3808349. |
153 | Modified THE code that build THE string|
154 | g_security_condition TO USE THE COLUMN |
155 | 'valuation_method' |
156 | 09/28/2004 K. Boussema Modified procedures TO cleanup Accounting |
157 | Event Extract Diagnostics data: |
158 | - delete_request_je() AND |
159 | - delete_transaction_je() |
160 | 12/08/2004 K. Boussema Renamed THE diagnostic framework TABLES: |
161 | - xla_extract_events BY xla_diag_events |
162 | - xla_extract_ledgers BY xla_diag_ledgers |
163 | - xla_extract_sources BY xla_diag_sources |
164 | 01/04/2005 S. Singhania Bug 3928357. g_total_error_Count IS SET TO|
165 | have THE right value IN document MODE |
166 | API. |
167 | Bug 3571389. Made changes TO refer TO THE |
168 | XLA_ACCTOUNTING_QTAB queue TABLE IN XLA |
169 | SCHEMA. |
170 | Made changes TO refer TO THE TYPE |
171 | XLA_QUEUE_MSG_TYPE IN APPS SCHEMA |
172 | 01/04/2005 S. Singhania Bug 4364612. WHILE loading xla_events_gt, |
173 | valuation method COLUMN IS populated. |
174 | 05/27/2005 V. Kumar Bug 4339454 Added handle_accounting_hook |
175 | procedure to replace business event by |
176 | APIS in accounting program |
177 | 01/06/2005 W. Shen Modify insert into xla_events_gt to insert|
178 | transaction_date |
179 | 06/06/2005 M. Asada Bug 4259032 Processing Unit Enhancement |
180 | 14/06/2005 V. Swapna Bug 4426342 Enabled business events for |
181 | all products |
182 | 15/06/2005 V. Swapna Bug 3071916 Made changes to call balance |
183 | calculation routine only if there are |
184 | valid entries |
185 | 06/24/2005 S. Singhania Bug 3443872. Added code to set security |
186 | context in unit_processor_batch for |
187 | child threads (XLAACCUP) |
188 | 06/30/2005 V. Kumar Bug 4459117 Added Cash Management in |
189 | handle_accounting_hooks |
190 | 07/11/2005 A. Wan Bug 4262811 MPA Project |
191 | 08/01/2005 W. Chan 4458381 - Public Sector Enhancement |
192 | 09/12/2005 V.Swapna 4599690 - Added Process Manufacturing |
193 | Financials to handle_accounting_hooks |
194 | 09/14/2005 W.Chan 4606566 - Pass budgetary_control_mode to |
195 | AP hook if calling for BC mode |
196 | 10/12/2005 A.Wan 4645092 - MPA report changes |
197 | 18-Oct-2005 V. Kumar Removed code for Analytical Criteria |
198 | 28-Oct-2005 W. Shen Third party merge, add logic to prevent |
199 | third party merge event been processed |
200 | here |
201 | 07-Nov-2005 S. Singhania Modofied event_application_manager to |
202 | print accounting, transfer time in log |
203 | 16-Nov-2005 Shishir Joshi Bug #4677032. Performance Improvement. |
204 | 17-Nov-2005 V. Kumar Bug#4736699 Added hint for performance |
205 | 23-Nov-2005 V. Kumar Bug#4752936 Added join on application_id |
206 | 30-Nov-2005 V.Swapna 4745309 - Added Payroll |
207 | to handle_accounting_hooks |
208 | 30-Nov-2005 V. Kumar Bug#4769388/4769270 Added hints |
209 | 12-Dec-2005 S. Singhania Bug 4883192. Modified the delete statement|
210 | that deletes from xla_distribution_links|
211 | 14-Dec-2005 V. Kumar Bug#4727703 Added condition to avoid unne-|
212 | -cessary execution of DELETE statements |
213 | 29-Dec-2005 V. Kumar Bug#4879954 Added hint for performance |
214 | 12-Jan-2006 V. Kumar Modified the logic to call GL transfer API|
215 | within child thread when transfer mode is |
216 | COMBINED (accounting and transfering to GL|
217 | 01-Feb-2006 V. Swapna Bug 4963736: Modified the call to |
218 | event_application_manager |
219 | 10-Feb-2006 A.Wan Bug 4670097 - budgetary control='N' |
220 | 12-Feb-2006 A.Wan 4860037 - anytime process order issue |
221 | 17-Feb-2006 V.Kumar 5034929 - Modified Cursor csr_event_class |
222 | 23-Feb-2006 V.Kumar 5056659 - Changed date mask to HH24:MI:SS |
223 | 02-Mar-2006 V. Swapna Bug 5018098: Added an exception to handle |
224 | no data found error in batch_accounting |
225 | 19-Apr-2006 A.Wan Bug 5149363 - performance fix |
226 | 20-Apr-2006 A.Wan Bug 5054831 - duplicate entires |
227 | 11-May-2006 A.Wan Bug 5221578 - log message is too long |
228 | 08/31/2006 V. Swapna Bug: 5257343. Add a new parameter to |
229 | unit_processor_batch, also, add this in |
230 | the call to submit the child program. |
231 | 14-Sep-2006 A.Wan Bug 5531502 - AAD_dbase_invalid need to |
232 | check if it is called in BC mode. If so |
233 | then validate for _BC_PKG, else _PKG. |
234 +===========================================================================*/
235
236 --=============================================================================
237 -- **************** declarations ********************
238 --=============================================================================
239 -------------------------------------------------------------------------------
240 -- declaring private constants and structures
241 -------------------------------------------------------------------------------
242 C_QUEUE_TABLE CONSTANT VARCHAR2(30) := 'xla_accounting_qtab';
243 C_CHAR CONSTANT VARCHAR2(30) := '##UNDEFINED##'; -- CHR(12);
244 C_NUM CONSTANT NUMBER := 9.99E125;
245
246 C_BATCH_PROGRAM CONSTANT VARCHAR2(80) := 'Batch Accounting Program';
247 C_UNIT_PROCESSOR CONSTANT VARCHAR2(80) := 'Unit Processor';
248 C_MANUAL CONSTANT VARCHAR2(30) := 'MANUAL';
249
250 ------------------------------------------------------------------------
251 -- 4597150 Process Event
252 ------------------------------------------------------------------------
253 C_DELIMITER CONSTANT VARCHAR2(30) := '#-#-#-#-#-#-#-#';
254 C_COMMA CONSTANT VARCHAR2(30) := ''',''';
255 C_QUOTE CONSTANT VARCHAR2(30) := '''';
256
257 C_LOCK_EVENTS_STR CONSTANT VARCHAR2(32000) :=
258 '
259 SELECT /*+ leading(tab,evt) use_nl(evt) */
260 evt.event_id
261 FROM xla_events evt
262 ,xla_event_types_b xet
263 ,TABLE(CAST(:1 AS xla_array_number_type)) tab
264 WHERE evt.application_id = :2
265 AND evt.event_date <= :3
266 AND evt.entity_id = tab.column_value
267 AND evt.application_id = xet.application_id
268 AND evt.event_type_code = xet.event_type_code
269 AND xet.event_class_code IN ($event_classes$)
270 AND evt.event_type_code NOT IN (''FULL_MERGE'', ''PARTIAL_MERGE'')
271 AND evt.process_status_code IN (''U'',''D'',''E'',''R'',''I'')
272 AND evt.event_status_code IN (''U'', DECODE(:4, ''F'',''N'',''U''))
273 FOR UPDATE OF evt.event_id skip locked
274 ';
275
276 C_CURR_INS_EVENTS CONSTANT VARCHAR2(32000) := '
277 INSERT INTO xla_events_gt
278 (entity_id
279 ,application_id
280 ,ledger_id
281 ,legal_entity_id
282 ,entity_code
283 ,transaction_number
284 ,source_id_int_1
285 ,source_id_int_2
286 ,source_id_int_3
287 ,source_id_int_4
288 ,source_id_char_1
289 ,source_id_char_2
290 ,source_id_char_3
291 ,source_id_char_4
292 ,event_id
293 ,event_class_code
294 ,event_type_code
295 ,event_number
296 ,event_date
297 ,transaction_date
298 ,event_status_code
299 ,process_status_code
300 ,valuation_method
301 ,budgetary_control_flag
302 ,reference_num_1
303 ,reference_num_2
304 ,reference_num_3
305 ,reference_num_4
306 ,reference_char_1
307 ,reference_char_2
308 ,reference_char_3
309 ,reference_char_4
310 ,reference_date_1
311 ,reference_date_2
312 ,reference_date_3
313 ,reference_date_4)
314 SELECT /*+ LEADING(EVT,XET,ENT,ECA) USE_NL(EVT,XET,ENT,ECA) */
315 evt.entity_id
316 ,evt.application_id
317 ,ent.ledger_id
318 ,ent.legal_entity_id
319 ,ent.entity_code
320 ,ent.transaction_number
321 ,ent.source_id_int_1
322 ,ent.source_id_int_2
323 ,ent.source_id_int_3
324 ,ent.source_id_int_4
325 ,ent.source_id_char_1
326 ,ent.source_id_char_2
327 ,ent.source_id_char_3
328 ,ent.source_id_char_4
329 ,evt.event_id
330 ,xet.event_class_code
331 ,evt.event_type_code
332 ,evt.event_number
333 ,evt.event_date
334 ,evt.transaction_date
335 ,evt.event_status_code
336 ,evt.process_status_code
337 ,ent.valuation_method
338 ,NVL(evt.budgetary_control_flag,''N'')
339 ,evt.reference_num_1
340 ,evt.reference_num_2
341 ,evt.reference_num_3
342 ,evt.reference_num_4
343 ,evt.reference_char_1
344 ,evt.reference_char_2
345 ,evt.reference_char_3
346 ,evt.reference_char_4
347 ,evt.reference_date_1
348 ,evt.reference_date_2
349 ,evt.reference_date_3
350 ,evt.reference_date_4
351 FROM xla_events evt
352 ,xla_transaction_entities ent
353 ,xla_event_types_b xet
354 ,xla_event_class_attrs eca
355 WHERE evt.application_id = :1
356 AND evt.event_date <= :2
357 AND evt.event_id = :3
358 AND evt.application_id = ent.application_id
359 AND evt.entity_id = ent.entity_id
360 AND evt.application_id = xet.application_id
361 AND evt.event_type_code = xet.event_type_code
362 AND eca.application_id = xet.application_id
363 AND eca.entity_code = xet.entity_code
364 AND eca.event_class_code = xet.event_class_code
365 AND xet.event_class_code IN ($event_classes$)
366 AND evt.event_type_code NOT IN (''FULL_MERGE'', ''PARTIAL_MERGE'')
367 AND evt.process_status_code IN (''U'',''D'',''E'',''R'',''I'')
368 AND evt.event_status_code IN
369 (''U'', DECODE(:4, ''F'',''N'',''U''))
370 ';
371
372 --
373 -- Unprocessed Event Number of Process Order -1 must be lower than
374 -- those of all Process Order higher than the current Process Order.
375 --
376 C_ANYTIME_INS_EVENTS CONSTANT VARCHAR2(32000) := '
377 INSERT INTO xla_events_gt
378 (entity_id
379 ,application_id
380 ,ledger_id
381 ,legal_entity_id
382 ,entity_code
383 ,transaction_number
384 ,source_id_int_1
385 ,source_id_int_2
386 ,source_id_int_3
387 ,source_id_int_4
388 ,source_id_char_1
389 ,source_id_char_2
390 ,source_id_char_3
391 ,source_id_char_4
392 ,event_id
393 ,event_class_code
394 ,event_type_code
395 ,event_number
396 ,event_date
397 ,transaction_date
398 ,event_status_code
399 ,process_status_code
400 ,valuation_method
401 ,budgetary_control_flag
402 ,reference_num_1
403 ,reference_num_2
404 ,reference_num_3
405 ,reference_num_4
406 ,reference_char_1
407 ,reference_char_2
408 ,reference_char_3
409 ,reference_char_4
410 ,reference_date_1
411 ,reference_date_2
412 ,reference_date_3
413 ,reference_date_4)
414 SELECT /*+ LEADING(EVT,XET,ENT,ECA) USE_NL(EVT,XET,ENT,ECA) */
415 evt.entity_id
416 ,evt.application_id
417 ,ent.ledger_id
418 ,ent.legal_entity_id
419 ,ent.entity_code
420 ,ent.transaction_number
421 ,ent.source_id_int_1
422 ,ent.source_id_int_2
423 ,ent.source_id_int_3
424 ,ent.source_id_int_4
425 ,ent.source_id_char_1
426 ,ent.source_id_char_2
427 ,ent.source_id_char_3
428 ,ent.source_id_char_4
429 ,evt.event_id
430 ,xet.event_class_code
431 ,evt.event_type_code
432 ,evt.event_number
433 ,evt.event_date
434 ,evt.transaction_date
435 ,evt.event_status_code
436 ,evt.process_status_code
437 ,ent.valuation_method
438 ,NVL(evt.budgetary_control_flag,''N'')
439 ,evt.reference_num_1
440 ,evt.reference_num_2
441 ,evt.reference_num_3
442 ,evt.reference_num_4
443 ,evt.reference_char_1
444 ,evt.reference_char_2
445 ,evt.reference_char_3
446 ,evt.reference_char_4
447 ,evt.reference_date_1
448 ,evt.reference_date_2
449 ,evt.reference_date_3
450 ,evt.reference_date_4
451 FROM xla_events evt
452 ,xla_transaction_entities ent
453 ,xla_event_types_b xet
454 ,xla_event_class_attrs eca
455 WHERE evt.application_id = :1
456 AND evt.event_date <= :2
457 AND evt.event_id = :3
458 AND evt.application_id = ent.application_id
459 AND evt.entity_id = ent.entity_id
460 AND evt.application_id = xet.application_id
461 AND evt.event_type_code = xet.event_type_code
462 AND eca.application_id = xet.application_id
463 AND eca.entity_code = xet.entity_code
464 AND eca.event_class_code = xet.event_class_code
465 AND xet.event_class_code IN ($event_classes$)
466 AND evt.event_type_code NOT IN (''FULL_MERGE'', ''PARTIAL_MERGE'')
467 AND evt.process_status_code IN (''U'',''D'',''E'',''R'',''I'')
468 AND evt.event_status_code IN
469 (''U'', DECODE(:4, ''F'',''N'',''U''))
470 AND evt.event_number <
471 (SELECT NVL(MIN(evt2.event_number), evt.event_number + 1)
472 FROM xla_events evt2
473 ,xla_transaction_entities_upg ent2
474 ,xla_event_types_b xet2
475 ,xla_event_class_attrs eca2
476 WHERE evt2.application_id = evt.application_id
477 AND evt2.entity_id = evt.entity_id
478 AND evt2.event_date = :5
479 AND evt2.application_id = ent2.application_id
480 AND evt2.entity_id = ent2.entity_id
481 AND evt2.application_id = xet2.application_id
482 AND evt2.event_type_code = xet2.event_type_code
483 AND eca2.application_id = xet2.application_id
484 AND eca2.entity_code = xet2.entity_code
485 AND eca2.event_class_code = xet2.event_class_code
486 AND xet2.event_class_code NOT IN ($event_class_current_order$)
487 AND xet2.event_class_code NOT IN ($event_class_anytime_order$)
488 AND evt2.event_type_code NOT IN (''FULL_MERGE'', ''PARTIAL_MERGE'')
489 AND evt2.process_status_code IN (''U'',''D'',''E'',''R'',''I'')
490 AND evt2.event_status_code IN
491 (''U'', DECODE(:6, ''F'',''N'',''U''))
492 )
493 ';
494 ------------------------------------------------------------------------
495
496
497 TYPE r_parent_data IS RECORD
498 (total_entity_count NUMBER
499 ,enqueued_msg_count NUMBER);
500
501 TYPE r_child_data IS RECORD
502 (selected_entity_count NUMBER
503 ,dequeued_msg_count NUMBER
504 ,selected_event_count NUMBER);
505
506 TYPE t_array_char_code IS TABLE OF VARCHAR2(1) INDEX BY BINARY_INTEGER;
507 TYPE t_array_char IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
508 TYPE t_array_char_ext IS TABLE OF VARCHAR2(240) INDEX BY BINARY_INTEGER;
509 TYPE t_array_date IS TABLE OF DATE INDEX BY BINARY_INTEGER;
510 TYPE t_array_integer IS TABLE OF INTEGER INDEX BY BINARY_INTEGER;
511
512 -------------------------------------------------------------------------------
513 -- declaring named exceptions
514 -------------------------------------------------------------------------------
515 normal_termination EXCEPTION;
516 resource_busy EXCEPTION;
517 PRAGMA EXCEPTION_INIT(resource_busy, -54);
518
519 -------------------------------------------------------------------------------
520 -- declaring private variables
521 -------------------------------------------------------------------------------
522 g_accounting_batch_id PLS_INTEGER;
523 g_queue_table_name VARCHAR2(80);
524 g_xla_schema_name VARCHAR2(30);
525 g_queue_name VARCHAR2(30);
526 g_comp_queue_name VARCHAR2(30);
527 g_ledger_ids xla_accounting_pkg.t_array_number;
528 g_process_count PLS_INTEGER;
529 g_ep_request_ids xla_accounting_pkg.t_array_number;
530 g_ep_reqid PLS_INTEGER;
531 g_unit_size PLS_INTEGER;
532 g_error_limit PLS_INTEGER;
533 g_seq_enabled_flag VARCHAR2(1);
534 g_global_context VARCHAR2(30);
535 g_conc_hold VARCHAR2(1);
536
537 g_current_entity_id PLS_INTEGER;
538 g_failed_event_id PLS_INTEGER;
539 g_processing_mode VARCHAR2(30);
540 g_execution_mode VARCHAR2(10);
541 g_budgetary_control_mode VARCHAR2(30); -- 4458381
542
543 g_total_error_count NUMBER := 0; -- This is used by parent thread to set request status
544 g_parent_data r_parent_data;
545 g_child_data r_child_data;
546
547 -------------------------------------------------------------------------------
548 -- forward declarion of private procedures and functions
549 -------------------------------------------------------------------------------
550 --PROCEDURE accounting_manager_batch;
551
552 PROCEDURE batch_accounting;
553
554 PROCEDURE enqueue_messages
555 (p_processing_order INTEGER
556 ,p_max_processing_order INTEGER
557 ,p_children_spawned IN OUT NOCOPY BOOLEAN
558 ,p_msg_count IN OUT NOCOPY INTEGER);
559
560 PROCEDURE process_events;
561
562 -- 5054831
563 FUNCTION AAD_dbase_invalid(p_pad_name IN VARCHAR2,p_ledger_category_code IN VARCHAR2,p_enable_bc_flag IN VARCHAR2) return BOOLEAN;
564 PROCEDURE ValidateAAD(p_array_event_dates IN t_array_date);
565
566 PROCEDURE ValidateAAD
567 (p_max_event_date IN DATE);
568
569
570 PROCEDURE unit_processor;
571
572 PROCEDURE complete_entries;
573
574 PROCEDURE wait_for_requests
575 (p_array_request_id IN t_array_number
576 ,p_error_status OUT NOCOPY VARCHAR2
577 ,p_warning_status OUT NOCOPY VARCHAR2);
578
579
580 FUNCTION is_any_child_running
581 RETURN BOOLEAN;
582
583 FUNCTION is_parent_running
584 RETURN BOOLEAN;
585
586 PROCEDURE events_processor(l_processing_order IN NUMBER); -- bug 7193986
587
588 PROCEDURE delete_batch_je;
589
590 PROCEDURE delete_request_je;
591
592 /*
593 PROCEDURE document_processor
594 (p_entity_id IN NUMBER);
595
596 PROCEDURE delete_transaction_je
597 (p_entity_id IN NUMBER);
598 */
599
600 PROCEDURE spawn_child_processes;
601
602 PROCEDURE pre_accounting;
603
604 PROCEDURE post_accounting
605 (p_queue_started_flag IN OUT NOCOPY VARCHAR2
606 ,p_queue_created_flag IN OUT NOCOPY VARCHAR2
607 ,p_seq_api_called_flag IN OUT NOCOPY VARCHAR2);
608
609 PROCEDURE event_application_manager
610 (p_source_application_id IN NUMBER
611 ,p_application_id IN NUMBER
612 ,p_ledger_id IN NUMBER
613 ,p_process_category IN VARCHAR2
614 ,p_end_date IN DATE
615 ,p_accounting_flag IN VARCHAR2
616 ,p_accounting_mode IN VARCHAR2
617 ,p_error_only_flag IN VARCHAR2
618 ,p_transfer_flag IN VARCHAR2
619 ,p_gl_posting_flag IN VARCHAR2
620 ,p_gl_batch_name IN VARCHAR2
621 ,p_valuation_method IN VARCHAR2
622 ,p_security_id_int_1 IN NUMBER
623 ,p_security_id_int_2 IN NUMBER
624 ,p_security_id_int_3 IN NUMBER
625 ,p_security_id_char_1 IN VARCHAR2
626 ,p_security_id_char_2 IN VARCHAR2
627 ,p_security_id_char_3 IN VARCHAR2);
628
629 PROCEDURE sequencing_batch_init
630 (p_seq_enabled_flag IN OUT NOCOPY VARCHAR2);
631
632 PROCEDURE raise_accounting_event
633 (p_application_id IN NUMBER
634 ,p_ledger_id IN NUMBER
635 ,p_process_category IN VARCHAR2
636 ,p_end_date IN DATE
637 ,p_accounting_mode IN VARCHAR2
638 ,p_valuation_method IN VARCHAR2
639 ,p_security_id_int_1 IN NUMBER
640 ,p_security_id_int_2 IN NUMBER
641 ,p_security_id_int_3 IN NUMBER
642 ,p_security_id_char_1 IN VARCHAR2
643 ,p_security_id_char_2 IN VARCHAR2
644 ,p_security_id_char_3 IN VARCHAR2
645 ,p_report_request_id IN NUMBER
646 ,p_event_name IN VARCHAR2
647 ,p_event_key IN VARCHAR2);
648
649 PROCEDURE raise_unit_event
650 (p_application_id IN NUMBER
651 ,p_accounting_mode IN VARCHAR2
652 ,p_event_name IN VARCHAR2
653 ,p_event_key IN VARCHAR2);
654
655 PROCEDURE handle_accounting_hook
656 (p_application_id IN NUMBER
657 ,p_ledger_id IN NUMBER
658 ,p_process_category IN VARCHAR2
659 ,p_end_date IN DATE
660 ,p_accounting_mode IN VARCHAR2
661 ,p_budgetary_control_mode IN VARCHAR2
662 ,p_valuation_method IN VARCHAR2
663 ,p_security_id_int_1 IN NUMBER
664 ,p_security_id_int_2 IN NUMBER
665 ,p_security_id_int_3 IN NUMBER
666 ,p_security_id_char_1 IN VARCHAR2
667 ,p_security_id_char_2 IN VARCHAR2
668 ,p_security_id_char_3 IN VARCHAR2
669 ,p_report_request_id IN NUMBER
670 ,p_event_name IN VARCHAR2
671 ,p_event_key IN VARCHAR2);
672
673 FUNCTION concat_event_classes
674 (p_processing_order IN NUMBER)
675 RETURN VARCHAR2;
676
677 --=============================================================================
678 -- *********** Local Trace Routine **********
679 --=============================================================================
680 C_LEVEL_STATEMENT CONSTANT NUMBER := FND_LOG.LEVEL_STATEMENT;
681 C_LEVEL_PROCEDURE CONSTANT NUMBER := FND_LOG.LEVEL_PROCEDURE;
682 C_LEVEL_EVENT CONSTANT NUMBER := FND_LOG.LEVEL_EVENT;
683 C_LEVEL_EXCEPTION CONSTANT NUMBER := FND_LOG.LEVEL_EXCEPTION;
684 C_LEVEL_ERROR CONSTANT NUMBER := FND_LOG.LEVEL_ERROR;
685 C_LEVEL_UNEXPECTED CONSTANT NUMBER := FND_LOG.LEVEL_UNEXPECTED;
686
687 C_LEVEL_LOG_DISABLED CONSTANT NUMBER := 99;
688 C_DEFAULT_MODULE CONSTANT VARCHAR2(240) := 'xla.plsql.xla_accounting_pkg';
689
690 g_log_level NUMBER;
691 g_log_enabled BOOLEAN;
692
693 C_LOG_SIZE CONSTANT NUMBER := 2000; -- 5221578 actual size is 4000, but maybe too long to be readable
694
695 PROCEDURE trace
696 (p_msg IN VARCHAR2
697 ,p_level IN NUMBER
698 ,p_module IN VARCHAR2 DEFAULT C_DEFAULT_MODULE) IS
699
700 l_max NUMBER;
701 l_pos NUMBER := 1;
702
703 BEGIN
704
705 l_pos := 1;
706
707 IF (p_msg IS NULL AND p_level >= g_log_level) THEN
708 fnd_log.message(p_level, p_module);
709 ELSIF p_level >= g_log_level THEN
710
711 l_max := length(p_msg);
712 IF l_max <= C_LOG_SIZE THEN
713 fnd_log.string(p_level, p_module, p_msg);
714 ELSE
715 -- 5221578 log messages in C_LOG_SIZE
716 WHILE (l_pos-1)*C_LOG_SIZE <= l_max LOOP
717 fnd_log.string(p_level, p_module, substr(p_msg, (l_pos-1)*C_LOG_SIZE+1, C_LOG_SIZE));
718 l_pos := l_pos+1;
719 END LOOP;
720 END IF;
721 END IF;
722
723 EXCEPTION
724 WHEN xla_exceptions_pkg.application_exception THEN
725 RAISE;
726 WHEN OTHERS THEN
727 xla_exceptions_pkg.raise_message
728 (p_location => 'xla_accounting_pkg.trace');
729 END trace;
730
731 --=============================================================================
732 -- ******* Print Log File **********
733 --=============================================================================
734 PROCEDURE print_logfile(p_msg IN VARCHAR2) IS
735 BEGIN
736
737 fnd_file.put_line(fnd_file.log,p_msg);
738
739 EXCEPTION
740 WHEN xla_exceptions_pkg.application_exception THEN
741 RAISE;
742 WHEN OTHERS THEN
743 xla_exceptions_pkg.raise_message
744 (p_location => 'xla_accounting_pkg.print_logfile');
745 END print_logfile;
746
747
748 --=============================================================================
749 -- *********** public procedures and functions **********
750 --=============================================================================
751 --=============================================================================
752 --
753 --
754 --
755 --
756 --
757 --
758 --
759 --
760 --
761 --
762 -- Following routines are used while accounting for a batch of documents
763 --
764 -- 1. accounting_program_batch (procedure)
765 -- 2. event_application_cp (conc executible procedure)
766 -- 3. event_application_manager
767 -- 4. unit_processor_batch (conc executible procedure)
768 --
769 --
770 --
771 --
772 --
773 --
774 --
775 --
776 --
777 --
778 --
779 --=============================================================================
780
781 --=============================================================================
782 --
783 --
784 --
785 --=============================================================================
786 PROCEDURE accounting_program_batch
787 (p_source_application_id IN NUMBER
788 ,p_application_id IN NUMBER
789 ,p_ledger_id IN NUMBER
790 ,p_process_category IN VARCHAR2
791 ,p_end_date IN DATE
792 ,p_accounting_flag IN VARCHAR2
793 ,p_accounting_mode IN VARCHAR2
794 ,p_error_only_flag IN VARCHAR2
795 ,p_transfer_flag IN VARCHAR2
796 ,p_gl_posting_flag IN VARCHAR2
797 ,p_gl_batch_name IN VARCHAR2
798 ,p_valuation_method IN VARCHAR2
799 ,p_security_id_int_1 IN NUMBER
800 ,p_security_id_int_2 IN NUMBER
801 ,p_security_id_int_3 IN NUMBER
802 ,p_security_id_char_1 IN VARCHAR2
803 ,p_security_id_char_2 IN VARCHAR2
804 ,p_security_id_char_3 IN VARCHAR2
805 ,p_accounting_batch_id OUT NOCOPY NUMBER
806 ,p_errbuf OUT NOCOPY VARCHAR2
807 ,p_retcode OUT NOCOPY NUMBER) IS
808 l_array_event_appl_id xla_number_array_type;
809 l_array_request_id t_array_number;
810 l_array_mpa_request_id t_array_number;
811 l_mpa_request_id NUMBER(10);
812 l_xml_output BOOLEAN;
813 l_str_event_application VARCHAR2(2000);
814 l_error_status VARCHAR2(1) := 'N';
815 l_warning_status VARCHAR2(1) := 'N';
816 l_log_module VARCHAR2(240);
817 l_iso_language FND_LANGUAGES.iso_language%TYPE;
818 l_iso_territory FND_LANGUAGES.iso_territory%TYPE;
819 BEGIN
820 --
821 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Starting of the Parent Thread');
822
823 IF g_log_enabled THEN
824 l_log_module := C_DEFAULT_MODULE||'.accounting_program_batch';
825 END IF;
826 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
827 trace
828 (p_msg => 'BEGIN of procedure ACCOUNTING_PROGRAM_BATCH'
829 ,p_level => C_LEVEL_PROCEDURE
830 ,p_module => l_log_module);
831 trace
832 (p_msg => 'p_source_application_id = '||to_char(p_source_application_id)
833 ,p_level => C_LEVEL_PROCEDURE
834 ,p_module => l_log_module);
835 trace
836 (p_msg => 'p_application_id = '||to_char(p_application_id)
837 ,p_level => C_LEVEL_PROCEDURE
838 ,p_module => l_log_module);
839 trace
840 (p_msg => 'p_ledger_id = '||p_ledger_id
841 ,p_level => C_LEVEL_PROCEDURE
842 ,p_module => l_log_module);
843 trace
844 (p_msg => 'p_process_category = '||p_process_category
845 ,p_level => C_LEVEL_PROCEDURE
846 ,p_module => l_log_module);
847 trace
848 (p_msg => 'p_end_date = '||to_char(p_end_date,'DD-MON-YYYY')
849 ,p_level => C_LEVEL_PROCEDURE
850 ,p_module => l_log_module);
851 trace
852 (p_msg => 'p_accounting_flag = '||p_accounting_flag
853 ,p_level => C_LEVEL_PROCEDURE
854 ,p_module => l_log_module);
855 trace
856 (p_msg => 'p_accounting_mode = '||p_accounting_mode
857 ,p_level => C_LEVEL_PROCEDURE
858 ,p_module => l_log_module);
859 trace
860 (p_msg => 'p_error_only_flag = '||p_error_only_flag
861 ,p_level => C_LEVEL_PROCEDURE
862 ,p_module => l_log_module);
863 trace
864 (p_msg => 'p_transfer_flag = '||p_transfer_flag
865 ,p_level => C_LEVEL_PROCEDURE
866 ,p_module => l_log_module);
867 trace
868 (p_msg => 'p_gl_posting_flag = '||p_gl_posting_flag
869 ,p_level => C_LEVEL_PROCEDURE
870 ,p_module => l_log_module);
871 trace
872 (p_msg => 'p_gl_batch_name = '||p_gl_batch_name
873 ,p_level => C_LEVEL_PROCEDURE
874 ,p_module => l_log_module);
875 trace
876 (p_msg => 'p_valuation_method = '||p_valuation_method
877 ,p_level => C_LEVEL_PROCEDURE
878 ,p_module => l_log_module);
879 trace
880 (p_msg => 'p_security_id_int_1 = '||p_security_id_int_1
881 ,p_level => C_LEVEL_PROCEDURE
882 ,p_module => l_log_module);
883 trace
884 (p_msg => 'p_security_id_int_1 = '||p_security_id_int_1
885 ,p_level => C_LEVEL_PROCEDURE
886 ,p_module => l_log_module);
887 trace
888 (p_msg => 'p_security_id_int_3 = '||p_security_id_int_3
889 ,p_level => C_LEVEL_PROCEDURE
890 ,p_module => l_log_module);
891 trace
892 (p_msg => 'p_security_id_char_1 = '||p_security_id_char_1
893 ,p_level => C_LEVEL_PROCEDURE
894 ,p_module => l_log_module);
895 trace
896 (p_msg => 'p_security_id_char_2 = '||p_security_id_char_2
897 ,p_level => C_LEVEL_PROCEDURE
898 ,p_module => l_log_module);
899 trace
900 (p_msg => 'p_security_id_char_3 = '||p_security_id_char_3
901 ,p_level => C_LEVEL_PROCEDURE
902 ,p_module => l_log_module);
903 END IF;
904
905
906 print_logfile('Starting main program for the source application = '||p_source_application_id);
907
908 g_report_request_id := fnd_global.conc_request_id();
909
910 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
911 trace
912 (p_msg => 'g_report_request_id = '||g_report_request_id
913 ,p_level => C_LEVEL_STATEMENT
914 ,p_module => l_log_module);
915 END IF;
916
917 ----------------------------------------------------------------------------
918 -- Making sure at leat source application or event application is passed
919 -- This condition should never arise, as it should be validated in the
920 -- request parameters.
921 ----------------------------------------------------------------------------
922 IF ((p_source_application_id IS NULL) AND (p_application_id IS NULL)) THEN
923 xla_exceptions_pkg.raise_message
924 (p_appli_s_name => 'XLA'
925 ,p_msg_name => 'XLA_COMMON_ERROR'
926 ,p_token_1 => 'LOCATION'
927 ,p_value_1 => 'xla_accounting_pkg.accounting_program_batch'
928 ,p_token_2 => 'ERROR'
929 ,p_value_2 => 'Source application and event application both cannot be NULL');
930 END IF;
931
932 ----------------------------------------------------------------------------
933 -- Fetching Accounting Batch Id
934 ----------------------------------------------------------------------------
935 SELECT xla_accounting_batches_s.NEXTVAL INTO g_accounting_batch_id FROM DUAL;
936
937 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
938 trace
939 (p_msg => 'g_accounting_batch_id = '||g_accounting_batch_id
940 ,p_level => C_LEVEL_STATEMENT
941 ,p_module => l_log_module);
942 END IF;
943
944 ----------------------------------------------------------------------------
945 -- Initializing errors package
946 ----------------------------------------------------------------------------
947 xla_accounting_err_pkg.set_options
948 (p_error_source => xla_accounting_err_pkg.C_ACCT_PROGRAM
949 ,p_request_id => g_report_request_id
950 ,p_application_id => p_application_id);
951
952 ----------------------------------------------------------------------------
953 -- Building filter condition based on security columns and valuation method
954 -- This condition will be added dynamically to select statemtents.
955 ----------------------------------------------------------------------------
956 SELECT
957 DECODE(p_valuation_method,NULL,NULL,'and valuation_method = '''||p_valuation_method||''' ')||
958 DECODE(p_security_id_int_1,NULL,NULL,'and security_id_int_1 = '||p_security_id_int_1||' ')||
959 DECODE(p_security_id_int_2,NULL,NULL,'and security_id_int_2 = '||p_security_id_int_2||' ')||
960 DECODE(p_security_id_int_3,NULL,NULL,'and security_id_int_3 = '||p_security_id_int_3||' ')||
961 DECODE(p_security_id_char_1,NULL,NULL,'and security_id_char_1 = '''||p_security_id_char_1||''' ')||
962 DECODE(p_security_id_char_2,NULL,NULL,'and security_id_char_2 = '''||p_security_id_char_2||''' ')||
963 DECODE(p_security_id_char_3,NULL,NULL,'and security_id_char_3 = '''||p_security_id_char_3||''' ')
964 INTO g_security_condition
965 FROM DUAL;
966
967 ----------------------------------------------------------------------------
968 -- Building filter condition based process_category.
969 -- This condition will be added dynamically to select statemtents.
970 ----------------------------------------------------------------------------
971 SELECT
972 DECODE(p_process_category,NULL,NULL,'and event_class_group_code = '''||p_process_category||'''')
973 INTO g_process_category_condition
974 FROM DUAL;
975
976 ----------------------------------------------------------------------------
977 -- Building filter condition based on source_application_id.
978 ----------------------------------------------------------------------------
979 SELECT
980 DECODE(p_source_application_id,NULL,NULL,'and source_application_id = '||p_source_application_id)
981 INTO g_source_appl_condition
982 FROM DUAL;
983
984 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
985 trace
986 (p_msg => 'g_security_condition = '||g_security_condition
987 ,p_level => C_LEVEL_STATEMENT
988 ,p_module => l_log_module);
989 trace
990 (p_msg => 'g_process_category_condition = '||g_process_category_condition
991 ,p_level => C_LEVEL_STATEMENT
992 ,p_module => l_log_module);
993 trace
994 (p_msg => 'g_source_appl_condition = '||g_source_appl_condition
995 ,p_level => C_LEVEL_STATEMENT
996 ,p_module => l_log_module);
997 END IF;
998
999 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Dynamic conditions built');
1000
1001 ----------------------------------------------------------------------------
1002 -- Finding Event Applications.
1003 ----------------------------------------------------------------------------
1004
1005 IF p_application_id IS NOT NULL THEN
1006 l_array_event_appl_id := xla_number_array_type(p_application_id);
1007 ELSIF p_application_id IS NULL THEN
1008 l_str_event_application :=
1009 'SELECT application_id
1010 FROM xla_entity_events_v
1011 WHERE source_application_id = :2
1012 AND ledger_id = :3
1013 AND event_date <= :4
1014 AND process_status_code IN (''R'',''I'',''E'',DECODE(:5,''N'',''D'',''E'')
1015 ,DECODE(:6,''N'',''U'',''E'')
1016 )
1017 AND event_status_code IN (''U'',DECODE(:7,''F'',''N'',''U''))
1018 AND entity_code <> '''||C_MANUAL||'''
1019 AND NVL(budgetary_control_flag,''N'') = ''N'' '||
1020 g_security_condition||' '||
1021 g_process_category_condition||' '||
1022 'GROUP BY application_id';
1023
1024 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1025 trace
1026 (p_msg => 'l_str_event_application = '||l_str_event_application
1027 ,p_level => C_LEVEL_STATEMENT
1028 ,p_module => l_log_module);
1029 END IF;
1030
1031 EXECUTE IMMEDIATE l_str_event_application
1032 BULK COLLECT INTO l_array_event_appl_id
1033 USING p_source_application_id
1034 ,p_ledger_id
1035 ,p_end_Date
1036 ,p_error_only_flag
1037 ,p_error_only_flag
1038 ,p_accounting_mode;
1039 END IF;
1040
1041 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Event Applications Determined');
1042 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1043 trace
1044 (p_msg => 'Number of Event Applications = '||l_array_event_appl_id.COUNT
1045 ,p_level => C_LEVEL_STATEMENT
1046 ,p_module => l_log_module);
1047 END IF;
1048
1049 IF l_array_event_appl_id.COUNT = 0 THEN
1050 IF (C_LEVEL_EVENT >= g_log_level) THEN
1051 trace
1052 (p_msg => 'No event applications fetched for the source application. '||
1053 'There are no events to process in this run.'
1054 ,p_level => C_LEVEL_EVENT
1055 ,p_module => l_log_module);
1056 END IF;
1057 xla_accounting_err_pkg.build_message
1058 (p_appli_s_name => 'XLA'
1059 ,p_msg_name => 'XLA_AP_NO_EVENT_TO_PROCESS'
1060 ,p_entity_id => NULL
1061 ,p_event_id => NULL);
1062
1063 print_logfile('Technical warning : There are no events to process.');
1064
1065 -------------------------------------------------------------------------
1066 -- Following exception is added to make sure the request ends normal when
1067 -- no event is found to process for the given criteria.
1068 -- bug # 2709397
1069 -------------------------------------------------------------------------
1070 RAISE normal_termination;
1071 ELSIF l_array_event_appl_id.COUNT = 1 THEN
1072 IF (C_LEVEL_EVENT >= g_log_level) THEN
1073 trace
1074 (p_msg => 'Processing event application = '||l_array_event_appl_id(1)
1075 ,p_level => C_LEVEL_EVENT
1076 ,p_module => l_log_module);
1077 END IF;
1078
1079 event_application_manager
1080 (p_source_application_id => p_source_application_id
1081 ,p_application_id => l_array_event_appl_id(1)
1082 ,p_ledger_id => p_ledger_id
1083 ,p_process_category => p_process_category
1084 ,p_end_date => p_end_date
1085 ,p_accounting_flag => p_accounting_flag
1086 ,p_accounting_mode => p_accounting_mode
1087 ,p_error_only_flag => p_error_only_flag
1088 ,p_transfer_flag => p_transfer_flag
1089 ,p_gl_posting_flag => p_gl_posting_flag
1090 ,p_gl_batch_name => p_gl_batch_name
1091 ,p_valuation_method => p_valuation_method
1092 ,p_security_id_int_1 => p_security_id_int_1
1093 ,p_security_id_int_2 => p_security_id_int_2
1094 ,p_security_id_int_3 => p_security_id_int_3
1095 ,p_security_id_char_1 => p_security_id_char_1
1096 ,p_security_id_char_2 => p_security_id_char_2
1097 ,p_security_id_char_3 => p_security_id_char_3);
1098
1099
1100 ELSE
1101
1102 FOR i IN 1..l_array_event_appl_id.COUNT LOOP
1103 l_array_request_id(i) :=
1104 fnd_request.submit_request
1105 (application => 'XLA'
1106 ,program => 'XLAACCEA'
1107 ,description => NULL
1108 ,start_time => NULL
1109 ,sub_request => FALSE
1110 ,argument1 => p_source_application_id
1111 ,argument2 => l_array_event_appl_id(i)
1112 ,argument3 => p_ledger_id
1113 ,argument4 => p_process_category
1114 ,argument5 => p_end_date
1115 ,argument6 => p_accounting_flag
1116 ,argument7 => p_accounting_mode
1117 ,argument8 => p_error_only_flag
1118 ,argument9 => p_transfer_flag
1119 ,argument10 => p_gl_posting_flag
1120 ,argument11 => p_gl_batch_name
1121 ,argument12 => g_accounting_batch_id
1122 ,argument13 => g_report_request_id
1123 ,argument14 => p_valuation_method
1124 ,argument15 => p_security_id_int_1
1125 ,argument16 => p_security_id_int_2
1126 ,argument17 => p_security_id_int_3
1127 ,argument18 => p_security_id_char_1
1128 ,argument19 => p_security_id_char_2
1129 ,argument20 => p_security_id_char_3);
1130 IF l_array_request_id(i) = 0 THEN
1131 xla_accounting_err_pkg.build_message
1132 (p_appli_s_name => 'XLA'
1133 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
1134 ,p_token_1 => 'APPLICATION_NAME'
1135 ,p_value_1 => 'SLA'
1136 ,p_entity_id => NULL
1137 ,p_event_id => NULL);
1138
1139 print_logfile('Technical Error : Unable to submit accounting program request for '||
1140 'application '||l_array_event_appl_id(i));
1141
1142 xla_exceptions_pkg.raise_message
1143 (p_appli_s_name => 'XLA'
1144 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
1145 ,p_token_1 => 'APPLICATION_NAME'
1146 ,p_value_1 => 'SLA');
1147 END IF;
1148 END LOOP;
1149
1150
1151 IF (C_LEVEL_EVENT >= g_log_level) THEN
1152 FOR i IN 1 .. l_array_request_id.count LOOP
1153 trace
1154 (p_msg => 'Submitted request '||l_array_request_id(i)||
1155 'to process event application = '||l_array_event_appl_id(i)
1156 ,p_level => C_LEVEL_EVENT
1157 ,p_module => l_log_module);
1158 END LOOP;
1159 END IF;
1160
1161 -------------------------------------------------------------------------
1162 -- Commit is required after fnd_request.submit_request
1163 -------------------------------------------------------------------------
1164 COMMIT;
1165
1166 -------------------------------------------------------------------------
1167 -- wait for requests to complete
1168 -------------------------------------------------------------------------
1169 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Waiting for Acct Prg - parent requests to complete.');
1170 wait_for_requests
1171 (p_array_request_id => l_array_request_id
1172 ,p_error_status => l_error_status
1173 ,p_warning_status => l_warning_status);
1174 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Monitoring of Acct Prg - parent requests completed.');
1175 END IF;
1176
1177
1178 --------------------------------------------------------
1179 -- 4645092 set request id for get_mpa_accrual_context
1180 --------------------------------------------------------
1181 dbms_session.set_identifier (client_id => g_report_request_id);
1182 IF xla_context_pkg.get_mpa_accrual_context = 'Y' THEN
1183 g_mpa_accrual_exists := 'Y';
1184 ELSE
1185 g_mpa_accrual_exists := 'N';
1186 END IF;
1187 --------------------------------------------------------
1188
1189 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1190 trace('g_mpa_accrual_exists= '|| g_mpa_accrual_exists,
1191 C_LEVEL_STATEMENT,l_log_module);
1192 end if;
1193
1194 IF NVL(g_mpa_accrual_exists,'N') = 'Y' THEN -- 4645092
1195
1196 SELECT lower(iso_language),iso_territory
1197 INTO l_iso_language,l_iso_territory
1198 FROM FND_LANGUAGES
1199 WHERE language_code = USERENV('LANG');
1200
1201 l_xml_output := fnd_request.add_layout(
1202 'XLA', 'XLARPMPB'
1203 ,l_iso_language, l_iso_territory, 'PDF');
1204
1205 FOR i IN 1..l_array_event_appl_id.COUNT LOOP
1206
1207 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1208 trace('p_source_application_id = '|| to_char(p_source_application_id),
1209 C_LEVEL_STATEMENT,l_log_module);
1210 trace('p_application_id = '|| to_char(l_array_event_appl_id(i)),
1211 C_LEVEL_STATEMENT,l_log_module);
1212 trace('p_ledger_id = '|| to_char(p_ledger_id),
1213 C_LEVEL_STATEMENT,l_log_module);
1214 trace('p_process_category_code = '|| p_process_category,
1215 C_LEVEL_STATEMENT,l_log_module);
1216 trace('p_create_accounting = '|| p_accounting_flag,
1217 C_LEVEL_STATEMENT,l_log_module);
1218 trace('p_end_date = '|| to_char(p_end_date,'DD-MON-YYYY'),
1219 C_LEVEL_STATEMENT,l_log_module);
1220 trace('p_accounting_mode = '|| p_accounting_mode,
1221 C_LEVEL_STATEMENT,l_log_module);
1222 trace('p_errors_only_flag = '|| p_error_only_flag,
1223 C_LEVEL_STATEMENT,l_log_module);
1224 trace('p_transfer_to_gl_flag = '|| p_transfer_flag,
1225 C_LEVEL_STATEMENT,l_log_module);
1226 trace('p_post_in_gl_flag = '|| p_gl_posting_flag,
1227 C_LEVEL_STATEMENT,l_log_module);
1228 trace('p_gl_batch_name = '|| p_gl_batch_name,
1229 C_LEVEL_STATEMENT,l_log_module);
1230 trace('g_accounting_batch_id = '|| g_accounting_batch_id,
1231 C_LEVEL_STATEMENT,l_log_module);
1232 END IF;
1233
1234 l_array_mpa_request_id(i) := xla_mpa_accrual_rprtg_pkg.run_report
1235 (p_source_application_id
1236 ,l_array_event_appl_id(i)
1237 ,p_ledger_id
1238 ,p_process_category
1239 ,p_end_date
1240 ,p_accounting_flag
1241 ,p_accounting_mode
1242 ,p_error_only_flag
1243 ,p_transfer_flag
1244 ,p_gl_posting_flag
1245 ,p_gl_batch_name
1246 ,g_accounting_batch_id);
1247
1248
1249 IF l_array_mpa_request_id(i) = 0 THEN
1250 xla_accounting_err_pkg.build_message
1251 (p_appli_s_name => 'XLA'
1252 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
1253 ,p_token_1 => 'APPLICATION_NAME'
1254 ,p_value_1 => 'SLA'
1255 ,p_entity_id => NULL
1256 ,p_event_id => NULL);
1257
1258 print_logfile('Technical Error : '||
1259 'Unable to submit Subledger Multiperiod Accounting'||
1260 ' and Accrual Reversal Report request for '||
1261 'application '||l_array_event_appl_id(i));
1262
1263 xla_exceptions_pkg.raise_message
1264 (p_appli_s_name => 'XLA'
1265 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
1266 ,p_token_1 => 'APPLICATION_NAME'
1267 ,p_value_1 => 'SLA');
1268 END IF;
1269
1270 END LOOP;
1271
1272 IF (C_LEVEL_EVENT >= g_log_level) THEN
1273 FOR i IN 1 .. l_array_mpa_request_id.count LOOP
1274 trace
1275 (p_msg => 'Submitted request '||l_array_mpa_request_id(i)||
1276 'to process mpa report for application = '||
1277 l_array_event_appl_id(i)
1278 ,p_level => C_LEVEL_EVENT
1279 ,p_module => l_log_module);
1280 END LOOP;
1281 END IF;
1282
1283 -------------------------------------------------------------------------
1284 -- Commit is required after fnd_request.submit_request
1285 -------------------------------------------------------------------------
1286 COMMIT;
1287
1288 -------------------------------------------------------------------------
1289 -- wait for requests to complete
1290 -------------------------------------------------------------------------
1291 print_logfile(to_char(sysdate,'DD-MON-YYYY HH:MI:SS')||
1292 '- Waiting for MPA Prg - parent requests to complete.');
1293 wait_for_requests
1294 (p_array_request_id => l_array_mpa_request_id
1295 ,p_error_status => l_error_status
1296 ,p_warning_status => l_warning_status);
1297 print_logfile(to_char(sysdate,'DD-MON-YYYY HH:MI:SS')||
1298 ' - Monitoring of MPA Prg - parent requests completed.');
1299
1300 END IF;
1301
1302 --------------------------------------------------------
1303 -- 4645092 clear out MPA-Accrual flag
1304 --------------------------------------------------------
1305 xla_context_pkg.clear_mpa_accrual_context(p_client_id => g_report_request_id);
1306
1307 ----------------------------------------------------------------------------
1308 -- insert any errors that were build in this session (for them to appear
1309 -- on the report).
1310 ----------------------------------------------------------------------------
1311 xla_accounting_err_pkg.insert_errors;
1312 COMMIT;
1313
1314 ----------------------------------------------------------------------------
1315 -- set out variables
1316 ----------------------------------------------------------------------------
1317 ----------------------------------------------------------------------------
1318 -- Following if conditioin is added to set the retcode to 1 when there are
1319 -- events with errors for that run of accounting program. (bug # 2709397)
1320 -- The if condition is modified to make sure the report request ends in
1321 -- ERROR/WARNING if any of the Parent request end in ERROR/WARNING.
1322 -- (Bug # 3239212).
1323 ----------------------------------------------------------------------------
1324 p_accounting_batch_id := g_accounting_batch_id;
1325
1326 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1327 trace
1328 (p_msg => 'l_error_status = '||l_error_status
1329 ,p_level => C_LEVEL_STATEMENT
1330 ,p_module => l_log_module);
1331 trace
1332 (p_msg => 'l_warning_status = '||l_warning_status
1333 ,p_level => C_LEVEL_STATEMENT
1334 ,p_module => l_log_module);
1335 trace
1336 (p_msg => 'g_total_error_count = '||g_total_error_count
1337 ,p_level => C_LEVEL_STATEMENT
1338 ,p_module => l_log_module);
1339 END IF;
1340
1341 IF l_error_status = 'Y' THEN
1342 -------------------------------------------------------------------------
1343 -- This is effective only if there are multiple event applications
1344 -------------------------------------------------------------------------
1345 p_retcode := 2;
1346 p_errbuf := 'Accouting Report ended in Error because one '||
1347 'of the Parent Accounting Program ended in Error';
1348 ELSIF l_warning_status = 'Y' THEN
1349 -------------------------------------------------------------------------
1350 -- This is effective only if there are multiple event applications
1351 -------------------------------------------------------------------------
1352 p_retcode := 1;
1353 p_errbuf := 'Accouting Report ended in Warning because one '||
1354 'of the Parent Accounting Program ended in Warning';
1355 ELSIF g_total_error_count = 0 THEN
1356 p_retcode := 0;
1357 p_errbuf := 'Accounting Program completed Normal';
1358 ELSIF g_total_error_count <> 0 THEN
1359 -------------------------------------------------------------------------
1360 -- This is effective only if there is one event application
1361 -------------------------------------------------------------------------
1362 p_retcode := 1;
1363 p_errbuf := 'Accounting Program ended in Warning because '||
1364 'there are some events that are in error';
1365 END IF;
1366
1367 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1368 trace
1369 (p_msg => 'p_retcode = '||p_retcode
1370 ,p_level => C_LEVEL_PROCEDURE
1371 ,p_module => l_log_module);
1372 trace
1373 (p_msg => 'p_errbuf = '||p_errbuf
1374 ,p_level => C_LEVEL_PROCEDURE
1375 ,p_module => l_log_module);
1376 trace
1377 (p_msg => 'END of procedure ACCOUNTING_PROGRAM_BATCH'
1378 ,p_level => C_LEVEL_PROCEDURE
1379 ,p_module => l_log_module);
1380 END IF;
1381
1382 EXCEPTION
1383 WHEN normal_termination THEN
1384 ----------------------------------------------------------------------------
1385 -- set out variables
1386 ----------------------------------------------------------------------------
1387 p_accounting_batch_id := g_accounting_batch_id;
1388 p_retcode := 0;
1389 p_errbuf := 'Accounting Program did not find any events.';
1390
1391 print_logfile(p_errbuf);
1392
1393 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1394 trace
1395 (p_msg => 'NORMAL_TERMINATION exception was raised in the code'
1396 ,p_level => C_LEVEL_EXCEPTION
1397 ,p_module => l_log_module);
1398 END IF;
1399 ----------------------------------------------------------------------------
1400 -- insert any errors that were build in this session (for them to appear
1401 -- on the report).
1402 ----------------------------------------------------------------------------
1403 xla_accounting_err_pkg.insert_errors;
1404
1405 COMMIT;
1406
1407 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1408 trace
1409 (p_msg => 'p_retcode = '||p_retcode
1410 ,p_level => C_LEVEL_PROCEDURE
1411 ,p_module => l_log_module);
1412 trace
1413 (p_msg => 'p_errbuf = '||p_errbuf
1414 ,p_level => C_LEVEL_PROCEDURE
1415 ,p_module => l_log_module);
1416 trace
1417 (p_msg => 'END of procedure ACCOUNTING_PROGRAM_BATCH'
1418 ,p_level => C_LEVEL_PROCEDURE
1419 ,p_module => l_log_module);
1420 END IF;
1421 WHEN xla_exceptions_pkg.application_exception THEN
1422 ----------------------------------------------------------------------------
1423 -- set out variables
1424 ----------------------------------------------------------------------------
1425 p_accounting_batch_id := g_accounting_batch_id;
1426 p_retcode := 2;
1427 p_errbuf := xla_messages_pkg.get_message;
1428
1429 print_logfile(p_errbuf);
1430
1431 IF (C_LEVEL_ERROR >= g_log_level) THEN
1432 trace
1433 (p_msg => NULL
1434 ,p_level => C_LEVEL_ERROR
1435 ,p_module => l_log_module);
1436 END IF;
1437
1438 ----------------------------------------------------------------------------
1439 -- insert any errors that were build in this session (for them to appear
1440 -- on the report).
1441 ----------------------------------------------------------------------------
1442 xla_accounting_err_pkg.insert_errors;
1443 COMMIT;
1444
1445
1446 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1447 trace
1448 (p_msg => 'p_retcode = '||p_retcode
1449 ,p_level => C_LEVEL_PROCEDURE
1450 ,p_module => l_log_module);
1451 trace
1452 (p_msg => 'p_errbuf = '||p_errbuf
1453 ,p_level => C_LEVEL_PROCEDURE
1454 ,p_module => l_log_module);
1455 trace
1456 (p_msg => 'END of procedure ACCOUNTING_PROGRAM_BATCH'
1457 ,p_level => C_LEVEL_PROCEDURE
1458 ,p_module => l_log_module);
1459 END IF;
1460 WHEN OTHERS THEN
1461 ----------------------------------------------------------------------------
1462 -- set out variables
1463 ----------------------------------------------------------------------------
1464 p_accounting_batch_id := g_accounting_batch_id;
1465 p_retcode := 2;
1466 p_errbuf := sqlerrm;
1467
1468 print_logfile(p_errbuf);
1469
1470 IF (C_LEVEL_UNEXPECTED >= g_log_level) THEN
1471 trace
1472 (p_msg => NULL
1473 ,p_level => C_LEVEL_UNEXPECTED
1474 ,p_module => l_log_module);
1475 END IF;
1476
1477 ----------------------------------------------------------------------------
1478 -- insert any errors that were build in this session (for them to appear
1479 -- on the report).
1480 ----------------------------------------------------------------------------
1481 xla_accounting_err_pkg.build_message
1482 (p_appli_s_name => 'XLA'
1483 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
1484 ,p_token_1 => 'APPLICATION_NAME'
1485 ,p_value_1 => 'SLA'
1486 ,p_entity_id => NULL
1487 ,p_event_id => NULL);
1488
1489 xla_accounting_err_pkg.insert_errors;
1490 COMMIT;
1491
1492 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1493 trace
1494 (p_msg => 'p_retcode = '||p_retcode
1495 ,p_level => C_LEVEL_PROCEDURE
1496 ,p_module => l_log_module);
1497 trace
1498 (p_msg => 'p_errbuf = '||p_errbuf
1499 ,p_level => C_LEVEL_PROCEDURE
1500 ,p_module => l_log_module);
1501 trace
1502 (p_msg => 'END of procedure ACCOUNTING_PROGRAM_BATCH'
1503 ,p_level => C_LEVEL_PROCEDURE
1504 ,p_module => l_log_module);
1505 END IF;
1506 END accounting_program_batch; -- end of procedure
1507
1508
1509 --=============================================================================
1510 --
1511 --
1512 --
1513 --=============================================================================
1514 PROCEDURE event_application_cp
1515 (p_errbuf OUT NOCOPY VARCHAR2
1516 ,p_retcode OUT NOCOPY NUMBER
1517 ,p_source_application_id IN NUMBER
1518 ,p_application_id IN NUMBER
1519 ,p_ledger_id IN NUMBER
1520 ,p_process_category IN VARCHAR2
1521 ,p_end_date IN DATE
1522 ,p_accounting_flag IN VARCHAR2
1523 ,p_accounting_mode IN VARCHAR2
1524 ,p_error_only_flag IN VARCHAR2
1525 ,p_transfer_flag IN VARCHAR2
1526 ,p_gl_posting_flag IN VARCHAR2
1527 ,p_gl_batch_name IN VARCHAR2
1528 ,p_accounting_batch_id IN NUMBER
1529 ,p_report_request_id IN NUMBER
1530 ,p_valuation_method IN VARCHAR2
1531 ,p_security_id_int_1 IN NUMBER
1532 ,p_security_id_int_2 IN NUMBER
1533 ,p_security_id_int_3 IN NUMBER
1534 ,p_security_id_char_1 IN VARCHAR2
1535 ,p_security_id_char_2 IN VARCHAR2
1536 ,p_security_id_char_3 IN VARCHAR2) IS
1537 l_log_module VARCHAR2(240);
1538 BEGIN
1539 IF g_log_enabled THEN
1540 l_log_module := C_DEFAULT_MODULE||'.event_application_cp';
1541 END IF;
1542 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1543 trace
1544 (p_msg => 'BEGIN of procedure EVENT_APPLICATION_CP'
1545 ,p_level => C_LEVEL_PROCEDURE
1546 ,p_module => l_log_module);
1547 trace
1548 (p_msg => 'p_source_application_id = '||p_source_application_id
1549 ,p_level => C_LEVEL_PROCEDURE
1550 ,p_module => l_log_module);
1551 trace
1552 (p_msg => 'p_application_id = '||p_application_id
1553 ,p_level => C_LEVEL_PROCEDURE
1554 ,p_module => l_log_module);
1555 trace
1556 (p_msg => 'p_ledger_id = '||p_ledger_id
1557 ,p_level => C_LEVEL_PROCEDURE
1558 ,p_module => l_log_module);
1559 trace
1560 (p_msg => 'p_process_category = '||p_process_category
1561 ,p_level => C_LEVEL_PROCEDURE
1562 ,p_module => l_log_module);
1563 trace
1564 (p_msg => 'p_end_date = '||p_end_date
1565 ,p_level => C_LEVEL_PROCEDURE
1566 ,p_module => l_log_module);
1567 trace
1568 (p_msg => 'p_accounting_flag = '||p_accounting_flag
1569 ,p_level => C_LEVEL_PROCEDURE
1570 ,p_module => l_log_module);
1571 trace
1572 (p_msg => 'p_accounting_mode = '||p_accounting_mode
1573 ,p_level => C_LEVEL_PROCEDURE
1574 ,p_module => l_log_module);
1575 trace
1576 (p_msg => 'p_error_only_flag = '||p_error_only_flag
1577 ,p_level => C_LEVEL_PROCEDURE
1578 ,p_module => l_log_module);
1579 trace
1580 (p_msg => 'p_transfer_flag = '||p_transfer_flag
1581 ,p_level => C_LEVEL_PROCEDURE
1582 ,p_module => l_log_module);
1583 trace
1584 (p_msg => 'p_gl_posting_flag = '||p_gl_posting_flag
1585 ,p_level => C_LEVEL_PROCEDURE
1586 ,p_module => l_log_module);
1587 trace
1588 (p_msg => 'p_gl_batch_name = '||p_gl_batch_name
1589 ,p_level => C_LEVEL_PROCEDURE
1590 ,p_module => l_log_module);
1591 trace
1592 (p_msg => 'p_accounting_batch_id = '||p_accounting_batch_id
1593 ,p_level => C_LEVEL_PROCEDURE
1594 ,p_module => l_log_module);
1595 trace
1596 (p_msg => 'p_report_request_id = '||p_report_request_id
1597 ,p_level => C_LEVEL_PROCEDURE
1598 ,p_module => l_log_module);
1599 trace
1600 (p_msg => 'p_valuation_method = '||p_valuation_method
1601 ,p_level => C_LEVEL_PROCEDURE
1602 ,p_module => l_log_module);
1603 trace
1604 (p_msg => 'p_security_id_int_1 = '||p_security_id_int_1
1605 ,p_level => C_LEVEL_PROCEDURE
1606 ,p_module => l_log_module);
1607 trace
1608 (p_msg => 'p_security_id_int_1 = '||p_security_id_int_1
1609 ,p_level => C_LEVEL_PROCEDURE
1610 ,p_module => l_log_module);
1611 trace
1612 (p_msg => 'p_security_id_int_3 = '||p_security_id_int_3
1613 ,p_level => C_LEVEL_PROCEDURE
1614 ,p_module => l_log_module);
1615 trace
1616 (p_msg => 'p_security_id_char_1 = '||p_security_id_char_1
1617 ,p_level => C_LEVEL_PROCEDURE
1618 ,p_module => l_log_module);
1619 trace
1620 (p_msg => 'p_security_id_char_2 = '||p_security_id_char_2
1621 ,p_level => C_LEVEL_PROCEDURE
1622 ,p_module => l_log_module);
1623 trace
1624 (p_msg => 'p_security_id_char_3 = '||p_security_id_char_3
1625 ,p_level => C_LEVEL_PROCEDURE
1626 ,p_module => l_log_module);
1627 END IF;
1628
1629
1630 print_logfile('Starting request for the event application = '||p_application_id);
1631
1632 ----------------------------------------------------------------------------
1633 -- Initializing errors package
1634 ----------------------------------------------------------------------------
1635 xla_accounting_err_pkg.set_options
1636 (p_error_source => xla_accounting_err_pkg.C_ACCT_PROGRAM
1637 ,p_request_id => p_report_request_id
1638 ,p_application_id => p_application_id);
1639
1640 g_accounting_batch_id := p_accounting_batch_id;
1641 g_report_request_id := p_report_request_id;
1642
1643 ----------------------------------------------------------------------------
1644 -- Building filter condition based on security columns and valuation method
1645 -- This condition will be added dynamically to select statemtents.
1646 ----------------------------------------------------------------------------
1647 SELECT
1648 DECODE(p_valuation_method,NULL,NULL,'and valuation_method = '''||p_valuation_method||''' ')||
1649 DECODE(p_security_id_int_1,NULL,NULL,'and security_id_int_1 = '||p_security_id_int_1||' ')||
1650 DECODE(p_security_id_int_2,NULL,NULL,'and security_id_int_2 = '||p_security_id_int_2||' ')||
1651 DECODE(p_security_id_int_3,NULL,NULL,'and security_id_int_3 = '||p_security_id_int_3||' ')||
1652 DECODE(p_security_id_char_1,NULL,NULL,'and security_id_char_1 = '''||p_security_id_char_1||''' ')||
1653 DECODE(p_security_id_char_2,NULL,NULL,'and security_id_char_2 = '''||p_security_id_char_2||''' ')||
1654 DECODE(p_security_id_char_3,NULL,NULL,'and security_id_char_3 = '''||p_security_id_char_3||''' ')
1655 INTO g_security_condition
1656 FROM DUAL;
1657
1658 ----------------------------------------------------------------------------
1659 -- Building filter condition based process_category.
1660 -- This condition will be added dynamically to select statemtents.
1661 ----------------------------------------------------------------------------
1662 SELECT
1663 DECODE(p_process_category,NULL,NULL,'and event_class_group_code = '''||p_process_category||'''')
1664 INTO g_process_category_condition
1665 FROM DUAL;
1666
1667 ----------------------------------------------------------------------------
1668 -- Building filter condition based on source_application_id.
1669 ----------------------------------------------------------------------------
1670 SELECT
1671 DECODE(p_source_application_id,NULL,NULL,'and source_application_id = '||p_source_application_id)
1672 INTO g_source_appl_condition
1673 FROM DUAL;
1674 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Dynamic conditions built');
1675
1676 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1677 trace
1678 (p_msg => 'g_security_condition = '||g_security_condition
1679 ,p_level => C_LEVEL_STATEMENT
1680 ,p_module => l_log_module);
1681 trace
1682 (p_msg => 'g_process_category_condition = '||g_process_category_condition
1683 ,p_level => C_LEVEL_STATEMENT
1684 ,p_module => l_log_module);
1685 trace
1686 (p_msg => 'g_source_appl_condition = '||g_source_appl_condition
1687 ,p_level => C_LEVEL_STATEMENT
1688 ,p_module => l_log_module);
1689 END IF;
1690
1691 ----------------------------------------------------------------------------
1692 -- call event_application_manager
1693 ----------------------------------------------------------------------------
1694 event_application_manager
1695 (p_source_application_id => p_source_application_id
1696 ,p_application_id => p_application_id
1697 ,p_ledger_id => p_ledger_id
1698 ,p_process_category => p_process_category
1699 ,p_end_date => p_end_date
1700 ,p_accounting_flag => p_accounting_flag
1701 ,p_accounting_mode => p_accounting_mode
1702 ,p_error_only_flag => p_error_only_flag
1703 ,p_transfer_flag => p_transfer_flag
1704 ,p_gl_posting_flag => p_gl_posting_flag
1705 ,p_gl_batch_name => p_gl_batch_name
1706 ,p_valuation_method => p_valuation_method
1707 ,p_security_id_int_1 => p_security_id_int_1
1708 ,p_security_id_int_2 => p_security_id_int_2
1709 ,p_security_id_int_3 => p_security_id_int_3
1710 ,p_security_id_char_1 => p_security_id_char_1
1711 ,p_security_id_char_2 => p_security_id_char_2
1712 ,p_security_id_char_3 => p_security_id_char_3);
1713
1714 ----------------------------------------------------------------------------
1715 -- set out variables
1716 ----------------------------------------------------------------------------
1717 ----------------------------------------------------------------------------
1718 -- Following if conditioin is added to set the retcode to 1 when there are
1719 -- events with errors for that run of accounting program. (bug # 2709397)
1720 ----------------------------------------------------------------------------
1721 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1722 trace
1723 (p_msg => 'g_total_error_count = '||g_total_error_count
1724 ,p_level => C_LEVEL_STATEMENT
1725 ,p_module => l_log_module);
1726 END IF;
1727
1728 IF g_total_error_count = 0 THEN
1729 p_retcode := 0;
1730 p_errbuf := 'Accounting Program completed Normal';
1731 ELSE
1732 p_retcode := 1;
1733 p_errbuf := 'Accounting Program completed Normal with some events in error';
1734 END IF;
1735
1736
1737 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1738 trace
1739 (p_msg => 'p_retcode = '||p_retcode
1740 ,p_level => C_LEVEL_PROCEDURE
1741 ,p_module => l_log_module);
1742 trace
1743 (p_msg => 'p_errbuf = '||p_errbuf
1744 ,p_level => C_LEVEL_PROCEDURE
1745 ,p_module => l_log_module);
1746 trace
1747 (p_msg => 'END of procedure EVENT_APPLICATION_CP'
1748 ,p_level => C_LEVEL_PROCEDURE
1749 ,p_module => l_log_module);
1750 END IF;
1751 EXCEPTION
1752 WHEN normal_termination THEN
1753 ----------------------------------------------------------------------------
1754 -- set out variables
1755 ----------------------------------------------------------------------------
1756 p_retcode := 0;
1757 p_errbuf := 'Accounting Program did not find any events.';
1758
1759 print_logfile(p_errbuf);
1760
1761 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1762 trace
1763 (p_msg => 'NORMAL_TERMINATION exception was raised in the code'
1764 ,p_level => C_LEVEL_EXCEPTION
1765 ,p_module => l_log_module);
1766 END IF;
1767 ----------------------------------------------------------------------------
1768 -- insert any errors that were build in this session (for them to appear
1769 -- on the report).
1770 ----------------------------------------------------------------------------
1771 xla_accounting_err_pkg.insert_errors;
1772
1773 COMMIT;
1774
1775
1776 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1777 trace
1778 (p_msg => 'p_retcode = '||p_retcode
1779 ,p_level => C_LEVEL_PROCEDURE
1780 ,p_module => l_log_module);
1781 trace
1782 (p_msg => 'p_errbuf = '||p_errbuf
1783 ,p_level => C_LEVEL_PROCEDURE
1784 ,p_module => l_log_module);
1785 trace
1786 (p_msg => 'END of procedure EVENT_APPLICATION_CP'
1787 ,p_level => C_LEVEL_PROCEDURE
1788 ,p_module => l_log_module);
1789 END IF;
1790 WHEN xla_exceptions_pkg.application_exception THEN
1791 ----------------------------------------------------------------------------
1792 -- set out variables
1793 ----------------------------------------------------------------------------
1794 p_retcode := 2;
1795 p_errbuf := xla_messages_pkg.get_message;
1796
1797 print_logfile(p_errbuf);
1798
1799 IF (C_LEVEL_ERROR >= g_log_level) THEN
1800 trace
1801 (p_msg => NULL
1802 ,p_level => C_LEVEL_ERROR
1803 ,p_module => l_log_module);
1804 END IF;
1805
1806 ----------------------------------------------------------------------------
1807 -- insert any errors that were build in this session (for them to appear
1808 -- on the report).
1809 ----------------------------------------------------------------------------
1810 xla_accounting_err_pkg.insert_errors;
1811
1812 COMMIT;
1813
1814
1815 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1816 trace
1817 (p_msg => 'p_retcode = '||p_retcode
1818 ,p_level => C_LEVEL_PROCEDURE
1819 ,p_module => l_log_module);
1820 trace
1821 (p_msg => 'p_errbuf = '||p_errbuf
1822 ,p_level => C_LEVEL_PROCEDURE
1823 ,p_module => l_log_module);
1824 trace
1825 (p_msg => 'END of procedure EVENT_APPLICATION_CP'
1826 ,p_level => C_LEVEL_PROCEDURE
1827 ,p_module => l_log_module);
1828 END IF;
1829 WHEN OTHERS THEN
1830 ----------------------------------------------------------------------------
1831 -- set out variables
1832 ----------------------------------------------------------------------------
1833 p_retcode := 2;
1834 p_errbuf := sqlerrm;
1835
1836 print_logfile(p_errbuf);
1837
1838 IF (C_LEVEL_UNEXPECTED >= g_log_level) THEN
1839 trace
1840 (p_msg => NULL
1841 ,p_level => C_LEVEL_UNEXPECTED
1842 ,p_module => l_log_module);
1843 END IF;
1844
1845 ----------------------------------------------------------------------------
1846 -- insert any errors that were build in this session (for them to appear
1847 -- on the report).
1848 ----------------------------------------------------------------------------
1849 xla_accounting_err_pkg.build_message
1850 (p_appli_s_name => 'XLA'
1851 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
1852 ,p_token_1 => 'APPLICATION_NAME'
1853 ,p_value_1 => 'SLA'
1854 ,p_entity_id => NULL
1855 ,p_event_id => NULL);
1856
1857 xla_accounting_err_pkg.insert_errors;
1858
1859 COMMIT;
1860
1861
1862 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1863 trace
1864 (p_msg => 'p_retcode = '||p_retcode
1865 ,p_level => C_LEVEL_PROCEDURE
1866 ,p_module => l_log_module);
1867 trace
1868 (p_msg => 'p_errbuf = '||p_errbuf
1869 ,p_level => C_LEVEL_PROCEDURE
1870 ,p_module => l_log_module);
1871 trace
1872 (p_msg => 'END of procedure EVENT_APPLICATION_CP'
1873 ,p_level => C_LEVEL_PROCEDURE
1874 ,p_module => l_log_module);
1875 END IF;
1876 END event_application_cp; -- end of procedure
1877
1878
1879 --=============================================================================
1880 --
1881 --
1882 --
1883 --=============================================================================
1884 PROCEDURE event_application_manager
1885 (p_source_application_id IN NUMBER
1886 ,p_application_id IN NUMBER
1887 ,p_ledger_id IN NUMBER
1888 ,p_process_category IN VARCHAR2
1889 ,p_end_date IN DATE
1890 ,p_accounting_flag IN VARCHAR2
1891 ,p_accounting_mode IN VARCHAR2
1892 ,p_error_only_flag IN VARCHAR2
1893 ,p_transfer_flag IN VARCHAR2
1894 ,p_gl_posting_flag IN VARCHAR2
1895 ,p_gl_batch_name IN VARCHAR2
1896 ,p_valuation_method IN VARCHAR2
1897 ,p_security_id_int_1 IN NUMBER
1898 ,p_security_id_int_2 IN NUMBER
1899 ,p_security_id_int_3 IN NUMBER
1900 ,p_security_id_char_1 IN VARCHAR2
1901 ,p_security_id_char_2 IN VARCHAR2
1902 ,p_security_id_char_3 IN VARCHAR2) IS
1903
1904 l_transfer_mode VARCHAR2(30);
1905 l_sqlerrm VARCHAR2(2000);
1906 l_log_module VARCHAR2(240);
1907
1908 l_temp BOOLEAN;
1909 l_status VARCHAR2(80);
1910 l_industry VARCHAR2(80);
1911 l_xla_schema_name VARCHAR2(30);
1912
1913 l_acct_begin_time NUMBER;
1914 l_acct_end_time NUMBER;
1915 l_transfer_begin_time NUMBER;
1916 l_transfer_end_time NUMBER;
1917
1918 BEGIN
1919 IF g_log_enabled THEN
1920 l_log_module := C_DEFAULT_MODULE||'.event_application_manager';
1921 END IF;
1922 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1923 trace
1924 (p_msg => 'BEGIN of procedure EVENT_APPLICATION_MANAGER'
1925 ,p_level => C_LEVEL_PROCEDURE
1926 ,p_module => l_log_module);
1927 trace
1928 (p_msg => 'p_source_application_id = '||p_source_application_id
1929 ,p_level => C_LEVEL_PROCEDURE
1930 ,p_module => l_log_module);
1931 trace
1932 (p_msg => 'p_application_id = '||p_application_id
1933 ,p_level => C_LEVEL_PROCEDURE
1934 ,p_module => l_log_module);
1935 trace
1936 (p_msg => 'p_ledger_id = '||p_ledger_id
1937 ,p_level => C_LEVEL_PROCEDURE
1938 ,p_module => l_log_module);
1939 trace
1940 (p_msg => 'p_process_category = '||p_process_category
1941 ,p_level => C_LEVEL_PROCEDURE
1942 ,p_module => l_log_module);
1943 trace
1944 (p_msg => 'p_end_date = '||p_end_date
1945 ,p_level => C_LEVEL_PROCEDURE
1946 ,p_module => l_log_module);
1947 trace
1948 (p_msg => 'p_accounting_flag = '||p_accounting_flag
1949 ,p_level => C_LEVEL_PROCEDURE
1950 ,p_module => l_log_module);
1951 trace
1952 (p_msg => 'p_accounting_mode = '||p_accounting_mode
1953 ,p_level => C_LEVEL_PROCEDURE
1954 ,p_module => l_log_module);
1955 trace
1956 (p_msg => 'p_error_only_flag = '||p_error_only_flag
1957 ,p_level => C_LEVEL_PROCEDURE
1958 ,p_module => l_log_module);
1959 trace
1960 (p_msg => 'p_transfer_flag = '||p_transfer_flag
1961 ,p_level => C_LEVEL_PROCEDURE
1962 ,p_module => l_log_module);
1963 trace
1964 (p_msg => 'p_gl_posting_flag = '||p_gl_posting_flag
1965 ,p_level => C_LEVEL_PROCEDURE
1966 ,p_module => l_log_module);
1967 trace
1968 (p_msg => 'p_gl_batch_name = '||p_gl_batch_name
1969 ,p_level => C_LEVEL_PROCEDURE
1970 ,p_module => l_log_module);
1971 trace
1972 (p_msg => 'p_valuation_method = '||p_valuation_method
1973 ,p_level => C_LEVEL_PROCEDURE
1974 ,p_module => l_log_module);
1975 trace
1976 (p_msg => 'p_security_id_int_1 = '||p_security_id_int_1
1977 ,p_level => C_LEVEL_PROCEDURE
1978 ,p_module => l_log_module);
1979 trace
1980 (p_msg => 'p_security_id_int_2 = '||p_security_id_int_2
1981 ,p_level => C_LEVEL_PROCEDURE
1982 ,p_module => l_log_module);
1983 trace
1984 (p_msg => 'p_security_id_int_3 = '||p_security_id_int_3
1985 ,p_level => C_LEVEL_PROCEDURE
1986 ,p_module => l_log_module);
1987 trace
1988 (p_msg => 'p_security_id_char_1 = '||p_security_id_char_1
1989 ,p_level => C_LEVEL_PROCEDURE
1990 ,p_module => l_log_module);
1991 trace
1992 (p_msg => 'p_security_id_char_2 = '||p_security_id_char_2
1993 ,p_level => C_LEVEL_PROCEDURE
1994 ,p_module => l_log_module);
1995 trace
1996 (p_msg => 'p_security_id_char_3 = '||p_security_id_char_3
1997 ,p_level => C_LEVEL_PROCEDURE
1998 ,p_module => l_log_module);
1999 END IF;
2000
2001 ----------------------------------------------------------------------------
2002 -- Initializing global variables
2003 ----------------------------------------------------------------------------
2004 g_application_id := p_application_id;
2005 g_ledger_id := p_ledger_id;
2006 g_process_category := p_process_category;
2007 g_end_date := p_end_date;
2008 g_accounting_flag := p_accounting_flag;
2009 g_accounting_mode := p_accounting_mode;
2010 g_error_only_flag := p_error_only_flag;
2011 g_transfer_flag := p_transfer_flag;
2012 g_gl_posting_flag := p_gl_posting_flag;
2013 g_gl_batch_name := p_gl_batch_name;
2014 -- Bug 4963736
2015 g_valuation_method := p_valuation_method;
2016 g_security_id_int_1 := p_security_id_int_1;
2017 g_security_id_int_2 := p_security_id_int_2;
2018 g_security_id_int_3 := p_security_id_int_3;
2019 g_security_id_char_1 := p_security_id_char_1;
2020 g_security_id_char_2 := p_security_id_char_2;
2021 g_security_id_char_3 := p_security_id_char_3;
2022
2023 g_processing_mode := 'BATCH';
2024 g_execution_mode := 'OFFLINE';
2025 g_total_error_count := 0;
2026 g_parent_request_id := fnd_global.conc_request_id;
2027
2028 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2029 trace
2030 (p_msg => 'g_processing_mode = '||g_processing_mode
2031 ,p_level => C_LEVEL_STATEMENT
2032 ,p_module => l_log_module);
2033 trace
2034 (p_msg => 'g_execution_mode = '||g_execution_mode
2035 ,p_level => C_LEVEL_STATEMENT
2036 ,p_module => l_log_module);
2037 trace
2038 (p_msg => 'g_parent_request_id = '||g_parent_request_id
2039 ,p_level => C_LEVEL_STATEMENT
2040 ,p_module => l_log_module);
2041 END IF;
2042
2043 l_acct_begin_time := 0;
2044 l_acct_end_time := 0;
2045 l_transfer_begin_time := 0;
2046 l_transfer_end_time := 0;
2047
2048
2049 ----------------------------------------------------------------------------
2050 -- Following sets the Security Context for the execution. This enables the
2051 -- the accounting program to respect the transaction security.
2052 ----------------------------------------------------------------------------
2053 xla_security_pkg.set_security_context(p_application_id);
2054
2055 IF (C_LEVEL_EVENT >= g_log_level) THEN
2056 trace
2057 (p_msg => 'Security_context set for application = '||p_application_id
2058 ,p_level => C_LEVEL_EVENT
2059 ,p_module => l_log_module);
2060 END IF;
2061
2062 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Security Context Set ');
2063
2064 ----------------------------------------------------------------------------
2065 -- Following sets the session's client identifier for the purpose of global
2066 -- application context.
2067 ----------------------------------------------------------------------------
2068 dbms_session.set_identifier
2069 (client_id => g_parent_request_id);
2070
2071 IF (C_LEVEL_EVENT >= g_log_level) THEN
2072 trace
2073 (p_msg => 'Session identifier set to = '||g_parent_request_id
2074 ,p_level => C_LEVEL_EVENT
2075 ,p_module => l_log_module);
2076 END IF;
2077
2078 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Session Identifier Set ');
2079
2080 ----------------------------------------------------------------------------
2081 -- Determining xla_schema_name and queue_table_name
2082 ----------------------------------------------------------------------------
2083 l_temp := fnd_installation.get_app_info
2084 (application_short_name => 'XLA'
2085 ,status => l_status
2086 ,industry => l_industry
2087 ,oracle_schema => l_xla_schema_name);
2088
2089 g_queue_table_name := l_xla_schema_name||'.'||C_QUEUE_TABLE;
2090
2091 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2092 trace
2093 (p_msg => 'g_queue_table_name = '||g_queue_table_name
2094 ,p_level => C_LEVEL_STATEMENT
2095 ,p_module => l_log_module);
2096 END IF;
2097
2098 ----------------------------------------------------------------------------
2099 -- Determining queue_name based on request id
2100 ----------------------------------------------------------------------------
2101 g_queue_name := l_xla_schema_name || '.XLA_'||TO_CHAR(g_parent_request_id)||'_DOC_Q';
2102 g_comp_queue_name := l_xla_schema_name || '.XLA_'||TO_CHAR(g_parent_request_id)||'_COMP_Q';
2103
2104 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2105 trace
2106 (p_msg => 'g_queue_name = '||g_queue_name
2107 ,p_level => C_LEVEL_STATEMENT
2108 ,p_module => l_log_module);
2109 END IF;
2110
2111 ----------------------------------------------------------------------------
2112 -- call routines to create accounting entries
2113 ----------------------------------------------------------------------------
2114 IF g_accounting_flag = 'Y' THEN
2115 IF (C_LEVEL_EVENT >= g_log_level) THEN
2116 trace
2117 (p_msg => 'Accounting process being called'
2118 ,p_level => C_LEVEL_EVENT
2119 ,p_module => l_log_module);
2120 END IF;
2121
2122 l_acct_begin_time := dbms_utility.get_time;
2123
2124 batch_accounting;
2125
2126 l_acct_end_time := dbms_utility.get_time;
2127
2128
2129 IF (C_LEVEL_EVENT >= g_log_level) THEN
2130 trace
2131 (p_msg => 'Accounting process completed'
2132 ,p_level => C_LEVEL_EVENT
2133 ,p_module => l_log_module);
2134 END IF;
2135 END IF;
2136
2137 ----------------------------------------------------------------------------
2138 -- call routines to perform 'Transfer to GL'
2139 ----------------------------------------------------------------------------
2140 IF ((g_transfer_flag = 'Y') AND (g_accounting_flag = 'N'))
2141 THEN
2142
2143 IF (C_LEVEL_EVENT >= g_log_level) THEN
2144 trace
2145 (p_msg => 'Transfer to GL process being called'
2146 ,p_level => C_LEVEL_EVENT
2147 ,p_module => l_log_module);
2148 END IF;
2149
2150 l_transfer_begin_time := dbms_utility.get_time;
2151
2152 xla_accounting_err_pkg.set_options
2153 (p_error_source => xla_accounting_err_pkg.C_TRANSFER_TO_GL);
2154
2155 l_transfer_mode := 'STANDALONE';
2156
2157 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2158 trace
2159 (p_msg => 'l_transfer_mode = '||l_transfer_mode
2160 ,p_level => C_LEVEL_STATEMENT
2161 ,p_module => l_log_module);
2162 END IF;
2163
2164 IF (C_LEVEL_EVENT >= g_log_level) THEN
2165 trace
2166 (p_msg => 'Calling transfer routine XLA_TRANSFER_PKG.GL_TRANSFER_MAIN'
2167 ,p_level => C_LEVEL_EVENT
2168 ,p_module => l_log_module);
2169 END IF;
2170
2171 --
2172 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Submitting the transfer to GL');
2173 xla_transfer_pkg.gl_transfer_main
2174 (p_application_id => g_application_id
2175 ,p_transfer_mode => l_transfer_mode
2176 ,p_ledger_id => g_ledger_id
2177 ,p_securiy_id_int_1 => g_security_id_int_1
2178 ,p_securiy_id_int_2 => g_security_id_int_2
2179 ,p_securiy_id_int_3 => g_security_id_int_3
2180 ,p_securiy_id_char_1 => g_security_id_char_1
2181 ,p_securiy_id_char_2 => g_security_id_char_2
2182 ,p_securiy_id_char_3 => g_security_id_char_3
2183 ,p_valuation_method => g_valuation_method
2184 ,p_process_category => g_process_category
2185 ,p_accounting_batch_id => g_accounting_batch_id
2186 ,p_entity_id => NULL
2187 ,p_batch_name => g_gl_batch_name
2188 ,p_end_date => g_end_date
2189 ,p_submit_gl_post => g_gl_posting_flag
2190 ,p_caller => xla_transfer_pkg.C_ACCTPROG_BATCH); -- Bug 5056632
2191
2192 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - End of the transfer to GL');
2193 IF (C_LEVEL_EVENT >= g_log_level) THEN
2194 trace
2195 (p_msg => 'Transfer routine XLA_TRANSFER_PKG.GL_TRANSFER_MAIN executed'
2196 ,p_level => C_LEVEL_EVENT
2197 ,p_module => l_log_module);
2198 END IF;
2199
2200 xla_accounting_err_pkg.set_options
2201 (p_error_source => xla_accounting_err_pkg.C_ACCT_PROGRAM);
2202
2203 l_transfer_end_time := dbms_utility.get_time;
2204
2205 IF (C_LEVEL_EVENT >= g_log_level) THEN
2206 trace
2207 (p_msg => 'Transfer to GL process completed'
2208 ,p_level => C_LEVEL_EVENT
2209 ,p_module => l_log_module);
2210 END IF;
2211 END IF;
2212 ----------------------------------------------------------------------------
2213 -- Handle postaccounting hook
2214 ----------------------------------------------------------------------------
2215 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - executing postaccounting hook');
2216 handle_accounting_hook
2217 (p_application_id => g_application_id
2218 ,p_ledger_id => g_ledger_id
2219 ,p_process_category => g_process_category
2220 ,p_end_date => g_end_date
2221 ,p_accounting_mode => g_accounting_mode
2222 ,p_budgetary_control_mode => g_budgetary_control_mode
2223 ,p_valuation_method => g_valuation_method
2224 ,p_security_id_int_1 => g_security_id_int_1
2225 ,p_security_id_int_2 => g_security_id_int_2
2226 ,p_security_id_int_3 => g_security_id_int_3
2227 ,p_security_id_char_1 => g_security_id_char_1
2228 ,p_security_id_char_2 => g_security_id_char_2
2229 ,p_security_id_char_3 => g_security_id_char_3
2230 ,p_report_request_id => g_report_request_id
2231 ,p_event_name => 'postaccounting'
2232 ,p_event_key => to_char(g_accounting_batch_id)||'-'
2233 ||to_char(g_parent_request_id));
2234 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - postaccounting hook executed successfully');
2235
2236 COMMIT;
2237
2238 print_logfile('- Accounting Time = '||((l_acct_end_time - l_acct_begin_time)/100)||' secs');
2239 print_logfile('- Transfer Time = '||((l_transfer_end_time - l_transfer_begin_time)/100)||' secs');
2240
2241 IF (C_LEVEL_EVENT >= g_log_level) THEN
2242 trace
2243 (p_msg => 'COMMIT issued in the procedure EVENT_APPLICATION_MANAGER'
2244 ,p_level => C_LEVEL_EVENT
2245 ,p_module => l_log_module);
2246 END IF;
2247
2248 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2249 trace
2250 (p_msg => 'END of procedure EVENT_APPLICATION_MANAGER'
2251 ,p_level => C_LEVEL_PROCEDURE
2252 ,p_module => l_log_module);
2253 END IF;
2254 EXCEPTION
2255 WHEN normal_termination THEN
2256 RAISE;
2257 WHEN xla_exceptions_pkg.application_exception THEN
2258 RAISE;
2259 WHEN OTHERS THEN
2260 xla_accounting_err_pkg.build_message
2261 (p_appli_s_name => 'XLA'
2262 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
2263 ,p_token_1 => 'APPLICATION_NAME'
2264 ,p_value_1 => 'SLA'
2265 ,p_entity_id => NULL
2266 ,p_event_id => NULL);
2267 xla_exceptions_pkg.raise_message
2268 (p_location => 'xla_accounting_pkg.event_application_manager');
2269 END event_application_manager; -- end of procedure
2270
2271
2272 --=============================================================================
2273 --
2274 --
2275 --
2276 --=============================================================================
2277 PROCEDURE unit_processor_batch
2278 (p_errbuf OUT NOCOPY VARCHAR2
2279 ,p_retcode OUT NOCOPY NUMBER
2280 ,p_application_id IN NUMBER
2281 ,p_ledger_id IN NUMBER
2282 ,p_end_date IN VARCHAR2 -- Bug 5151844
2283 ,p_accounting_mode IN VARCHAR2
2284 ,p_error_only_flag IN VARCHAR2
2285 ,p_accounting_batch_id IN NUMBER
2286 ,p_parent_request_id IN NUMBER
2287 ,p_report_request_id IN NUMBER
2288 ,p_queue_name IN VARCHAR2
2289 ,p_comp_queue_name IN VARCHAR2
2290 ,p_error_limit IN NUMBER
2291 ,p_seq_enabled_flag IN VARCHAR2
2292 ,p_transfer_flag IN VARCHAR2
2293 ,p_gl_posting_flag IN VARCHAR2
2294 ,p_gl_batch_name IN VARCHAR2) IS -- Bug 5257343
2295
2296 l_log_module VARCHAR2(240);
2297
2298 BEGIN
2299 IF g_log_enabled THEN
2300 l_log_module := C_DEFAULT_MODULE||'.unit_processor_batch';
2301 END IF;
2302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2303 trace
2304 (p_msg => 'BEGIN of procedure UNIT_PROCESSOR_BATCH'
2305 ,p_level => C_LEVEL_PROCEDURE
2306 ,p_module => l_log_module);
2307 trace
2308 (p_msg => 'p_application_id = '||p_application_id
2309 ,p_level => C_LEVEL_PROCEDURE
2310 ,p_module => l_log_module);
2311 trace
2312 (p_msg => 'p_ledger_id = '||p_ledger_id
2313 ,p_level => C_LEVEL_PROCEDURE
2314 ,p_module => l_log_module);
2315 trace
2316 (p_msg => 'p_end_date = '||p_end_date
2317 ,p_level => C_LEVEL_PROCEDURE
2318 ,p_module => l_log_module);
2319 trace
2320 (p_msg => 'p_accounting_mode = '||p_accounting_mode
2321 ,p_level => C_LEVEL_PROCEDURE
2322 ,p_module => l_log_module);
2323 trace
2324 (p_msg => 'p_error_only_flag = '||p_error_only_flag
2325 ,p_level => C_LEVEL_PROCEDURE
2326 ,p_module => l_log_module);
2327 trace
2328 (p_msg => 'p_accounting_batch_id = '||p_accounting_batch_id
2329 ,p_level => C_LEVEL_PROCEDURE
2330 ,p_module => l_log_module);
2331 trace
2332 (p_msg => 'p_parent_request_id = '||p_parent_request_id
2333 ,p_level => C_LEVEL_PROCEDURE
2334 ,p_module => l_log_module);
2335 trace
2336 (p_msg => 'p_report_request_id = '||p_report_request_id
2337 ,p_level => C_LEVEL_PROCEDURE
2338 ,p_module => l_log_module);
2339 trace
2340 (p_msg => 'p_queue_name = '||p_queue_name
2341 ,p_level => C_LEVEL_PROCEDURE
2342 ,p_module => l_log_module);
2343 trace
2344 (p_msg => 'p_comp_queue_name = '||p_comp_queue_name
2345 ,p_level => C_LEVEL_PROCEDURE
2346 ,p_module => l_log_module);
2347 trace
2348 (p_msg => 'p_error_limit = '||p_error_limit
2349 ,p_level => C_LEVEL_PROCEDURE
2350 ,p_module => l_log_module);
2351 trace
2352 (p_msg => 'p_seq_enabled_flag = '||p_seq_enabled_flag
2353 ,p_level => C_LEVEL_PROCEDURE
2354 ,p_module => l_log_module);
2355 trace
2356 (p_msg => 'p_gl_batch_name = '||p_gl_batch_name
2357 ,p_level => C_LEVEL_PROCEDURE
2358 ,p_module => l_log_module);
2359
2360 END IF;
2361
2362
2363 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Executing Unit Processor ...');
2364 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Initializing variables');
2365
2366 ----------------------------------------------------------------------------
2367 -- Initializing global variables
2368 ----------------------------------------------------------------------------
2369 g_application_id := p_application_id;
2370 g_ledger_id := p_ledger_id;
2371 g_end_date := to_date(p_end_date,'YYYY/MM/DD');
2372 g_accounting_mode := p_accounting_mode;
2373 g_accounting_batch_id := p_accounting_batch_id;
2374 g_parent_request_id := p_parent_request_id;
2375 g_report_request_id := p_report_request_id;
2376 g_queue_name := p_queue_name;
2377 g_comp_queue_name := p_comp_queue_name;
2378 g_error_limit := p_error_limit;
2379 g_seq_enabled_flag := p_seq_enabled_flag;
2380
2381 g_ep_reqid := fnd_global.conc_request_id;
2382 g_execution_mode := 'OFFLINE';
2383 g_processing_mode := 'BATCH';
2384 g_current_entity_id := NULL;
2385 g_transfer_flag := p_transfer_flag;
2386 g_gl_posting_flag := p_gl_posting_flag;
2387 g_gl_batch_name := p_gl_batch_name; -- Bug 5257343
2388
2389
2390 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2391 trace
2392 (p_msg => 'g_ep_reqid = '||g_ep_reqid
2393 ,p_level => C_LEVEL_STATEMENT
2394 ,p_module => l_log_module);
2395 trace
2396 (p_msg => 'g_execution_mode = '||g_execution_mode
2397 ,p_level => C_LEVEL_STATEMENT
2398 ,p_module => l_log_module);
2399 trace
2400 (p_msg => 'g_processing_mode = '||g_processing_mode
2401 ,p_level => C_LEVEL_STATEMENT
2402 ,p_module => l_log_module);
2403 END IF;
2404
2405 g_child_data.selected_entity_count := 0;
2406 g_child_data.dequeued_msg_count := 0;
2407 g_child_data.selected_event_count := 0;
2408
2409 ----------------------------------------------------------------------------
2410 -- Following sets the Security Context for the execution. This enables the
2411 -- the accounting program to respect the transaction security.
2412 ----------------------------------------------------------------------------
2413 xla_security_pkg.set_security_context(p_application_id);
2414
2415 IF (C_LEVEL_EVENT >= g_log_level) THEN
2416 trace
2417 (p_msg => 'Security_context set for application = '||p_application_id
2418 ,p_level => C_LEVEL_EVENT
2419 ,p_module => l_log_module);
2420 END IF;
2421
2422 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Security Context Set ');
2423
2424 ----------------------------------------------------------------------------
2425 -- Following sets the session's client identifier for the purpose of global
2426 -- application context.
2427 ----------------------------------------------------------------------------
2428 dbms_session.set_identifier
2429 (client_id => g_parent_request_id);
2430
2431 IF (C_LEVEL_EVENT >= g_log_level) THEN
2432 trace
2433 (p_msg => 'Session identifier set to = '||g_parent_request_id
2434 ,p_level => C_LEVEL_EVENT
2435 ,p_module => l_log_module);
2436 END IF;
2437
2438 ----------------------------------------------------------------------------
2439 -- Initializing error package
2440 ----------------------------------------------------------------------------
2441 xla_accounting_err_pkg.initialize
2442 (p_client_id => g_parent_request_id
2443 ,p_error_limit => g_error_limit
2444 ,p_error_source => xla_accounting_err_pkg.C_ACCT_ENGINE
2445 ,p_application_id => g_application_id);
2446
2447 ----------------------------------------------------------------------------
2448 -- Call the main accounting routine 'unit_processor'
2449 ----------------------------------------------------------------------------
2450 unit_processor;
2451
2452 ----------------------------------------------------------------------------
2453 -- 4645092 Set report request for MPA report
2454 ----------------------------------------------------------------------------
2455 IF g_mpa_accrual_exists = 'Y' THEN
2456 xla_context_pkg.set_mpa_accrual_context
2457 (p_mpa_accrual_exists => 'Y'
2458 ,p_client_id => g_report_request_id);
2459 END IF;
2460
2461 ----------------------------------------------------------------------------
2462 -- Following if conditioin is added to set the retcode to 1 when there are
2463 -- events with errors for that run of child thread in accounting program.
2464 -- (bug # 2709397)
2465 ----------------------------------------------------------------------------
2466
2467 --bug 7253269 condition included
2468 IF xla_accounting_err_pkg.g_error_count = 0 AND NOT XLA_ACCOUNTING_CACHE_PKG.g_hist_bflow_error_exists
2469 AND NOT XLA_AE_LINES_PKG.g_hist_reversal_error_exists AND NOT xla_accounting_cache_pkg.g_reversal_error THEN
2470 p_errbuf := 'Unit Processor completed normally';
2471 p_retcode := 0;
2472 ELSE
2473 p_errbuf := 'Unit Processor completed normally with some events in error';
2474 p_retcode := 1;
2475 END IF;
2476
2477
2478 COMMIT;
2479 IF (C_LEVEL_EVENT >= g_log_level) THEN
2480 trace
2481 (p_msg => 'COMMIT issued in the procedure UNIT_PROCESSOR_BATCH'
2482 ,p_level => C_LEVEL_EVENT
2483 ,p_module => l_log_module);
2484 END IF;
2485
2486 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Unit Processor completed successfully ...');
2487
2488 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2489 trace
2490 (p_msg => 'p_errbuf = '||p_errbuf
2491 ,p_level => C_LEVEL_PROCEDURE
2492 ,p_module => l_log_module);
2493 trace
2494 (p_msg => 'p_retcode = '||p_retcode
2495 ,p_level => C_LEVEL_PROCEDURE
2496 ,p_module => l_log_module);
2497 trace
2498 (p_msg => 'END of procedure UNIT_PROCESSOR_BATCH'
2499 ,p_level => C_LEVEL_PROCEDURE
2500 ,p_module => l_log_module);
2501 END IF;
2502
2503 EXCEPTION
2504 WHEN xla_exceptions_pkg.application_exception THEN
2505 ----------------------------------------------------------------------------
2506 -- Following stores the error message in the accounting log table
2507 ----------------------------------------------------------------------------
2508 p_errbuf := xla_messages_pkg.get_message;
2509 p_retcode := 2;
2510
2511 IF (C_LEVEL_ERROR >= g_log_level) THEN
2512 trace
2513 (p_msg => NULL
2514 ,p_level => C_LEVEL_ERROR
2515 ,p_module => l_log_module);
2516 END IF;
2517
2518 ROLLBACK;
2519
2520 IF (C_LEVEL_EVENT >= g_log_level) THEN
2521 trace
2522 (p_msg => 'ROLLBACK issued in the procedure UNIT_PROCESSOR_BATCH'
2523 ,p_level => C_LEVEL_EVENT
2524 ,p_module => l_log_module);
2525 END IF;
2526
2527
2528 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2529 trace
2530 (p_msg => 'p_errbuf = '||p_errbuf
2531 ,p_level => C_LEVEL_PROCEDURE
2532 ,p_module => l_log_module);
2533 trace
2534 (p_msg => 'p_retcode = '||p_retcode
2535 ,p_level => C_LEVEL_PROCEDURE
2536 ,p_module => l_log_module);
2537 trace
2538 (p_msg => 'END of procedure UNIT_PROCESSOR_BATCH'
2539 ,p_level => C_LEVEL_PROCEDURE
2540 ,p_module => l_log_module);
2541 END IF;
2542 WHEN OTHERS THEN
2543 ----------------------------------------------------------------------------
2544 -- Following stores the error message in the accounting log table
2545 ----------------------------------------------------------------------------
2546 IF SQLCODE = -25228 AND g_conc_hold = 'Y' /* Timeout; queue is likely empty... */
2547 THEN
2548 p_retcode := 1;
2549 ELSE
2550 p_retcode := 2;
2551 END IF;
2552
2553 p_errbuf := sqlerrm;
2554 IF (C_LEVEL_UNEXPECTED >= g_log_level) THEN
2555 trace
2556 (p_msg => NULL
2557 ,p_level => C_LEVEL_UNEXPECTED
2558 ,p_module => l_log_module);
2559 END IF;
2560
2561 ROLLBACK;
2562
2563 IF (C_LEVEL_EVENT >= g_log_level) THEN
2564 trace
2565 (p_msg => 'ROLLBACK issued in the procedure UNIT_PROCESSOR_BATCH'
2566 ,p_level => C_LEVEL_EVENT
2567 ,p_module => l_log_module);
2568 END IF;
2569
2570
2571 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2572 trace
2573 (p_msg => 'p_errbuf = '||p_errbuf
2574 ,p_level => C_LEVEL_PROCEDURE
2575 ,p_module => l_log_module);
2576 trace
2577 (p_msg => 'p_retcode = '||p_retcode
2578 ,p_level => C_LEVEL_PROCEDURE
2579 ,p_module => l_log_module);
2580 trace
2581 (p_msg => 'END of procedure UNIT_PROCESSOR_BATCH'
2582 ,p_level => C_LEVEL_PROCEDURE
2583 ,p_module => l_log_module);
2584 END IF;
2585 END unit_processor_batch; -- end of function
2586
2587 --=============================================================================
2588 --
2589 --
2590 --
2591 --=============================================================================
2592 PROCEDURE accounting_program_events
2593 (p_application_id IN INTEGER
2594 ,p_accounting_mode IN VARCHAR2
2595 ,p_gl_posting_flag IN VARCHAR2
2596 ,p_offline_flag IN VARCHAR2
2597 ,p_accounting_batch_id IN OUT NOCOPY INTEGER
2598 ,p_errbuf IN OUT NOCOPY VARCHAR2
2599 ,p_retcode IN OUT NOCOPY INTEGER)
2600 IS
2601 -- Retrieve any ledgers that does not enable budgetary control
2602 CURSOR c_invalid_bc_ledgers IS
2603 SELECT gl.ledger_id, gl.name ledger_name
2604 FROM xla_acct_prog_events_gt xpa
2605 , gl_ledgers gl
2606 WHERE xpa.ledger_id = gl.ledger_id
2607 AND enable_budgetary_control_flag = 'N'
2608 AND ROWNUM = 1;
2609
2610 -- Retrieve any ledgers that does not contains any JLD that indicates budgetary
2611 -- control validation
2612 CURSOR c_invalid_ledger_id IS
2613 SELECT xgl.ledger_id
2614 , xgl.name ledger_name
2615 , xam.name slam_name
2616 FROM xla_acct_prog_events_gt xap
2617 , xla_gl_ledgers_v xgl
2618 , xla_acctg_methods_tl xam
2619 , xla_acctg_method_rules xar
2620 , xla_aad_line_defn_assgns xal
2621 , xla_line_definitions_b xld
2622 WHERE xld.application_id(+) = xal.application_id
2623 AND xld.amb_context_code(+) = xal.amb_context_code
2624 AND xld.event_class_code(+) = xal.event_class_code
2625 AND xld.event_type_code(+) = xal.event_type_code
2626 AND xld.line_definition_owner_code(+) = xal.line_definition_owner_code
2627 AND xld.line_definition_code(+) = xal.line_definition_code
2628 AND xld.budgetary_control_flag(+) = 'Y'
2629 AND xal.application_id(+) = xar.application_id
2630 AND xal.amb_context_code(+) = xar.amb_context_code
2631 AND xal.product_rule_type_code(+) = xar.product_rule_type_code
2632 AND xal.product_rule_code(+) = xar.product_rule_code
2633 AND xar.accounting_method_type_code(+) = xgl.sla_accounting_method_type
2634 AND xar.accounting_method_code(+) = xgl.sla_accounting_method_code
2635 AND xar.application_id(+) = p_application_id
2636 AND xar.amb_context_code(+) = NVL(fnd_profile.value('XLA_AMB_CONTEXT'),'DEFAULT')
2637 AND xam.accounting_method_type_code(+) = xgl.sla_accounting_method_type
2638 AND xam.accounting_method_code(+) = xgl.sla_accounting_method_code
2639 AND xam.language(+) = USERENV('LANG')
2640 AND xgl.ledger_id = xap.ledger_id
2641 GROUP BY xgl.ledger_id
2642 , xgl.name
2643 , xam.name
2644 HAVING count(*) = 0;
2645
2646 CURSOR c_lock_entity_events IS
2647 SELECT /*+ LEADING (XAP) USE_NL (XAP XE XTE) */
2648 xe.event_id
2649 FROM xla_transaction_entities xte
2650 , xla_events xe
2651 , xla_acct_prog_events_gt xap
2652 WHERE xte.application_id = xe.application_id
2653 AND xte.entity_id = xe.entity_id
2654 AND xe.application_id = p_application_id
2655 AND xe.event_id = xap.event_id
2656 FOR UPDATE NOWAIT;
2657
2658 CURSOR c_entities IS
2659 SELECT distinct entity_id
2660 FROM xla_acct_prog_events_gt xap
2661 , xla_events xe
2662 WHERE xe.application_id = p_application_id
2663 AND xe.event_id = xap.event_id;
2664
2665 -- Retrieve list of ledgers to be processed
2666 CURSOR c_ledgers IS
2667 SELECT DISTINCT ledger_id
2668 FROM xla_acct_prog_events_gt;
2669
2670 i INTEGER;
2671 l_request_id INTEGER;
2672 l_array_event_id t_array_integer;
2673 l_ret_flag_bal_update BOOLEAN;
2674 l_transfer_mode VARCHAR2(30);
2675 l_event_source_info xla_events_pub_pkg.t_event_source_info;
2676
2677 l_log_module VARCHAR2(240);
2678 BEGIN
2679 IF g_log_enabled THEN
2680 l_log_module := C_DEFAULT_MODULE||'.accounting_program_events';
2681 END IF;
2682 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2683 trace
2684 (p_msg => 'BEGIN of procedure accounting_program_events'
2685 ,p_level => C_LEVEL_PROCEDURE
2686 ,p_module => l_log_module);
2687 trace
2688 (p_msg => 'p_application_id = '||p_application_id
2689 ,p_level => C_LEVEL_PROCEDURE
2690 ,p_module => l_log_module);
2691 trace
2692 (p_msg => 'p_accounting_mode = '||p_accounting_mode
2693 ,p_level => C_LEVEL_PROCEDURE
2694 ,p_module => l_log_module);
2695 trace
2696 (p_msg => 'p_gl_posting_flag = '||p_gl_posting_flag
2697 ,p_level => C_LEVEL_PROCEDURE
2698 ,p_module => l_log_module);
2699 trace
2700 (p_msg => 'p_offline_flag = '||p_offline_flag
2701 ,p_level => C_LEVEL_PROCEDURE
2702 ,p_module => l_log_module);
2703 END IF;
2704
2705 SAVEPOINT SP_EVENTS;
2706
2707 IF (C_LEVEL_EVENT >= g_log_level) THEN
2708 trace
2709 (p_msg => 'Established a savepoint SP_EVENTS'
2710 ,p_level => C_LEVEL_EVENT
2711 ,p_module => l_log_module);
2712 END IF;
2713
2714
2715 --
2716 -- Initializing errors package
2717 --
2718 xla_accounting_err_pkg.initialize
2719 (p_client_id => NULL
2720 ,p_error_limit => NULL
2721 ,p_error_source => xla_accounting_err_pkg.C_ACCT_PROGRAM
2722 ,p_application_id => p_application_id);
2723
2724 --
2725 -- If called with budgetary control mode, ensure all ledgers of the entity
2726 -- have budgetary control enabled.
2727 --
2728 IF (p_accounting_mode IN ('FUNDS_RESERVE', 'FUNDS_CHECK')) THEN
2729 IF (C_LEVEL_EVENT >= g_log_level) THEN
2730 trace
2731 (p_msg => 'BEGIN LOOP: XLA_AP_INVALID_BC_LEDGER'
2732 ,p_level => C_LEVEL_EVENT
2733 ,p_module => l_log_module);
2734 END IF;
2735
2736 FOR l_err IN c_invalid_bc_ledgers LOOP
2737 IF (C_LEVEL_ERROR >= g_log_level) THEN
2738 trace
2739 (p_msg => 'LOOP: Error XLA_AP_INVALID_BC_LEDGER - '||
2740 'ledger = '||l_err.ledger_name
2741 ,p_level => C_LEVEL_ERROR
2742 ,p_module => l_log_module);
2743 END IF;
2744
2745 xla_accounting_err_pkg.build_message
2746 (p_appli_s_name => 'XLA'
2747 ,p_msg_name => 'XLA_AP_INVALID_BC_LEDGER'
2748 ,p_token_1 => 'LEDGER_NAME'
2749 ,p_value_1 => l_err.ledger_name
2750 ,p_entity_id => NULL
2751 ,p_event_id => NULL);
2752 END LOOP;
2753
2754 IF (C_LEVEL_EVENT >= g_log_level) THEN
2755 trace
2756 (p_msg => 'END LOOP: XLA_AP_INVALID_BC_LEDGER'
2757 ,p_level => C_LEVEL_EVENT
2758 ,p_module => l_log_module);
2759 END IF;
2760
2761 IF (C_LEVEL_EVENT >= g_log_level) THEN
2762 trace
2763 (p_msg => 'BEGIN LOOP: XLA_AP_INVALID_LEDGER_JLD'
2764 ,p_level => C_LEVEL_EVENT
2765 ,p_module => l_log_module);
2766 END IF;
2767
2768 FOR l_err IN c_invalid_ledger_id LOOP
2769 IF (C_LEVEL_ERROR >= g_log_level) THEN
2770 trace
2771 (p_msg => 'LOOP: Error XLA_AP_INVALID_LEDGER_JLD - '||
2772 'slam = '||l_err.slam_name||
2773 ', ledger = '||l_err.ledger_name
2774 ,p_level => C_LEVEL_ERROR
2775 ,p_module => l_log_module);
2776 END IF;
2777
2778 xla_accounting_err_pkg.build_message
2779 (p_appli_s_name => 'XLA'
2780 ,p_msg_name => 'XLA_AP_INVALID_LEDGER_JLD'
2781 ,p_token_1 => 'SLAM_NAME'
2782 ,p_value_1 => l_err.slam_name
2783 ,p_token_2 => 'LEDGER_NAME'
2784 ,p_value_2 => l_err.ledger_name
2785 ,p_entity_id => NULL
2786 ,p_event_id => NULL);
2787 END LOOP;
2788
2789 IF (C_LEVEL_EVENT >= g_log_level) THEN
2790 trace
2791 (p_msg => 'END LOOP: XLA_AP_INVALID_LEDGER_JLD'
2792 ,p_level => C_LEVEL_EVENT
2793 ,p_module => l_log_module);
2794 END IF;
2795
2796 END IF;
2797
2798 g_application_id := p_application_id;
2799 g_processing_mode := 'DOCUMENT';
2800
2801 IF (p_accounting_mode = 'NONE') THEN
2802 g_accounting_mode := 'N';
2803 g_budgetary_control_mode := 'NONE';
2804 ELSIF (p_accounting_mode = 'FUNDS_RESERVE') THEN
2805 g_accounting_mode := 'F';
2806 g_budgetary_control_mode := p_accounting_mode;
2807 ELSIF (p_accounting_mode = 'FUNDS_CHECK') THEN
2808 g_accounting_mode := 'D';
2809 g_budgetary_control_mode := p_accounting_mode;
2810 ELSIF (p_accounting_mode = 'DRAFT') THEN
2811 g_accounting_mode := 'D';
2812 g_budgetary_control_mode := 'NONE';
2813 ELSE -- FINAL
2814 g_accounting_mode := 'F';
2815 g_budgetary_control_mode := 'NONE';
2816 END IF;
2817
2818 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2819 trace
2820 (p_msg => 'g_accounting_mode = '||g_accounting_mode
2821 ,p_level => C_LEVEL_STATEMENT
2822 ,p_module => l_log_module);
2823 trace
2824 (p_msg => 'g_budgetary_control_mode = '||g_budgetary_control_mode
2825 ,p_level => C_LEVEL_STATEMENT
2826 ,p_module => l_log_module);
2827 END IF;
2828
2829 ----------------------------------------------------------------------------
2830 -- Following sets the Security Context for the execution. This enables the
2831 -- the accounting program to respect the transaction security.
2832 ----------------------------------------------------------------------------
2833 xla_security_pkg.set_security_context(p_application_id);
2834
2835 IF (C_LEVEL_EVENT >= g_log_level) THEN
2836 trace
2837 (p_msg => 'Security_context set for application = '||p_application_id
2838 ,p_level => C_LEVEL_EVENT
2839 ,p_module => l_log_module);
2840 END IF;
2841
2842 --
2843 -- Lock all entity and events in xla_entity_events_v that exists in the
2844 -- xla_acct_prog_events_gt
2845 --
2846 OPEN c_lock_entity_events;
2847 FETCH c_lock_entity_events BULK COLLECT INTO l_array_event_id;
2848 CLOSE c_lock_entity_events;
2849
2850 --
2851 -- Following sets the session's client identifier for the purpose of global
2852 --
2853 -- application context.
2854 --
2855 SELECT xla_accounting_batches_s.nextval INTO p_accounting_batch_id FROM DUAL;
2856 g_accounting_batch_id := p_accounting_batch_id;
2857
2858 dbms_session.set_identifier
2859 (client_id => g_accounting_batch_id);
2860
2861 IF (g_accounting_mode ='F') THEN
2862 l_ret_flag_bal_update := xla_balances_pkg.massive_update_for_events
2863 (p_application_id => g_application_id);
2864
2865 IF (C_LEVEL_EVENT >= g_log_level) THEN
2866 trace
2867 (p_msg => 'Fucntion XLA_BALANCES_PKG.MASSIVE_UPDATE executed'
2868 ,p_level => C_LEVEL_EVENT
2869 ,p_module => l_log_module);
2870 END IF;
2871
2872 IF (C_LEVEL_EVENT >= g_log_level) THEN
2873 trace
2874 (p_msg => 'l_ret_flag_bal_update = '||CASE WHEN l_ret_flag_bal_update
2875 THEN 'TRUE'
2876 ELSE 'FALSE' END
2877 ,p_level => C_LEVEL_EVENT
2878 ,p_module => l_log_module);
2879 END IF;
2880
2881 IF NOT l_ret_flag_bal_update THEN
2882 xla_accounting_err_pkg.build_message
2883 (p_appli_s_name => 'XLA'
2884 ,p_msg_name => 'XLA_AP_BAL_UPDATE_FAILED'
2885 ,p_entity_id => NULL
2886 ,p_event_id => NULL);
2887
2888 print_logfile
2889 ('Technical problem : Problem in submitting request for balance update');
2890
2891 xla_exceptions_pkg.raise_message
2892 (p_appli_s_name => 'XLA'
2893 ,p_msg_name => 'XLA_AP_BAL_UPDATE_FAILED');
2894 ELSE
2895 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - request for balance calulation submitted');
2896 END IF;
2897 END IF;
2898
2899 --
2900 -- Delete the journal entries created for the events and entities to be processed
2901 --
2902
2903 IF (g_accounting_mode IN ('D','F')) THEN
2904 delete_batch_je;
2905
2906 FORALL i IN 1..l_array_event_id.COUNT
2907 UPDATE xla_events xe
2908 SET process_status_code = 'U'
2909 WHERE xe.on_hold_flag = 'N'
2910 AND xe.process_status_code <> 'P'
2911 AND xe.event_type_code not in ('FULL_MERGE', 'PARTIAL_MERGE')
2912 AND xe.event_id = l_array_event_id(i);
2913 END IF;
2914
2915 --
2916 -- Process the events by ledger
2917 --
2918 IF (C_LEVEL_EVENT >= g_log_level) THEN
2919 trace
2920 (p_msg => 'BEGIN LOOP: loop ledger'
2921 ,p_level => C_LEVEL_EVENT
2922 ,p_module => l_log_module);
2923 END IF;
2924
2925 FOR l_ledger IN c_ledgers LOOP
2926 IF (C_LEVEL_EVENT >= g_log_level) THEN
2927 trace
2928 (p_msg => 'LOOP: ledger_id = '||l_ledger.ledger_id
2929 ,p_level => C_LEVEL_EVENT
2930 ,p_module => l_log_module);
2931 trace
2932 (p_msg => 'g_accounting_mode = '||g_accounting_mode
2933 ,p_level => C_LEVEL_EVENT
2934 ,p_module => l_log_module);
2935 END IF;
2936
2937 g_ledger_id := l_ledger.ledger_id;
2938
2939
2940 IF (g_accounting_mode IN ('D','F')) THEN
2941
2942 -- 7193986 start
2943
2944 FOR x IN (
2945 SELECT DISTINCT xla_evt_class_orders_gt.processing_order
2946 FROM xla_acct_prog_events_gt ,
2947 xla_events ,
2948 xla_event_types_b ,
2949 xla_transaction_entities,
2950 xla_evt_class_orders_gt
2951 WHERE xla_events.event_id = xla_acct_prog_events_gt.event_id
2952 AND xla_events.application_id = p_application_id
2953 AND xla_transaction_entities.application_id = p_application_id
2954 AND xla_events.entity_id = xla_transaction_entities.entity_id
2955 AND xla_event_types_b.application_id = p_application_id
2956 AND xla_transaction_entities.entity_code = xla_event_types_b.entity_code
2957 AND xla_events.event_type_code = xla_event_types_b.event_type_code
2958 AND xla_event_types_b.event_class_code = xla_evt_class_orders_gt.event_class_code
2959 ORDER BY xla_evt_class_orders_gt.processing_order ASC)
2960 LOOP
2961
2962 IF (C_LEVEL_EVENT >= g_log_level) THEN
2963 trace
2964 (p_msg => 'BEGIN LOOP: event processor for order = ' || x.processing_order
2965 ,p_level => C_LEVEL_EVENT
2966 ,p_module => l_log_module);
2967 END IF;
2968
2969 events_processor (x.processing_order);
2970
2971 IF (C_LEVEL_EVENT >= g_log_level) THEN
2972 trace
2973 (p_msg => 'END LOOP: event processor for order = ' || x.processing_order
2974 ,p_level => C_LEVEL_EVENT
2975 ,p_module => l_log_module);
2976 END IF;
2977
2978 END LOOP;
2979
2980
2981 -- 7193986 end
2982
2983
2984 IF (g_accounting_mode = 'F') THEN
2985 l_ret_flag_bal_update := xla_balances_pkg.massive_update
2986 (p_application_id => g_application_id
2987 ,p_ledger_id => NULL
2988 ,p_entity_id => NULL
2989 ,p_event_id => NULL
2990 ,p_request_id => NULL
2991 ,p_accounting_batch_id => g_accounting_batch_id
2992 ,p_update_mode => 'A'
2993 ,p_execution_mode => 'O');
2994
2995 IF (C_LEVEL_EVENT >= g_log_level) THEN
2996 trace
2997 (p_msg => 'l_ret_flag_bal_update = '||CASE WHEN l_ret_flag_bal_update
2998 THEN 'TRUE'
2999 ELSE 'FALSE' END
3000 ,p_level => C_LEVEL_EVENT
3001 ,p_module => l_log_module);
3002 END IF;
3003
3004 IF NOT l_ret_flag_bal_update THEN
3005 xla_accounting_err_pkg.build_message
3006 (p_appli_s_name => 'XLA'
3007 ,p_msg_name => 'XLA_AP_BAL_UPDATE_FAILED'
3008 ,p_entity_id => NULL
3009 ,p_event_id => NULL);
3010
3011 print_logfile
3012 ('Technical problem : Problem in submitting request for balance update');
3013
3014 xla_exceptions_pkg.raise_message
3015 (p_appli_s_name => 'XLA'
3016 ,p_msg_name => 'XLA_AP_BAL_UPDATE_FAILED');
3017 ELSE
3018 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - request for balance calulation submitted');
3019 END IF;
3020 END IF;
3021 END IF;
3022
3023 --
3024 -- Call transfer to GL if requested
3025 --
3026 IF (p_gl_posting_flag = 'Y' AND
3027 g_accounting_mode IN ('F', 'N')) THEN
3028
3029 IF (C_LEVEL_EVENT >= g_log_level) THEN
3030 trace
3031 (p_msg => 'Transfer to GL process being called'
3032 ,p_level => C_LEVEL_EVENT
3033 ,p_module => l_log_module);
3034 END IF;
3035
3036 IF p_offline_flag = 'Y' THEN
3037
3038 xla_accounting_err_pkg.set_options
3039 (p_error_source => xla_accounting_err_pkg.C_TRANSFER_TO_GL);
3040
3041 IF p_accounting_mode = 'NONE' THEN
3042 l_transfer_mode := 'STANDALONE';
3043 ELSE
3044 l_transfer_mode := 'COMBINED';
3045 END IF;
3046
3047 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3048 trace
3049 (p_msg => 'l_transfer_mode = '||l_transfer_mode
3050 ,p_level => C_LEVEL_STATEMENT
3051 ,p_module => l_log_module);
3052 END IF;
3053
3054 IF (C_LEVEL_EVENT >= g_log_level) THEN
3055 trace
3056 (p_msg => 'Calling transfer routine XLA_TRANSFER_PKG.GL_TRANSFER_MAIN'
3057 ,p_level => C_LEVEL_EVENT
3058 ,p_module => l_log_module);
3059 END IF;
3060
3061 FOR l in c_entities LOOP
3062 xla_transfer_pkg.gl_transfer_main
3063 (p_application_id => p_application_id
3064 ,p_transfer_mode => l_transfer_mode
3065 ,p_ledger_id => g_ledger_id
3066 ,p_securiy_id_int_1 => NULL
3067 ,p_securiy_id_int_2 => NULL
3068 ,p_securiy_id_int_3 => NULL
3069 ,p_securiy_id_char_1 => NULL
3070 ,p_securiy_id_char_2 => NULL
3071 ,p_securiy_id_char_3 => NULL
3072 ,p_valuation_method => NULL
3073 ,p_process_category => NULL
3074 ,p_accounting_batch_id => g_accounting_batch_id
3075 ,p_entity_id => l.entity_id
3076 ,p_batch_name => NULL
3077 ,p_end_date => NULL
3078 ,p_submit_gl_post => 'Y'
3079 ,p_caller => xla_transfer_pkg.C_ACCTPROG_DOCUMENT); -- Bug 5056632
3080 END LOOP;
3081
3082 IF (C_LEVEL_EVENT >= g_log_level) THEN
3083 trace
3084 (p_msg => 'Transfer routine XLA_TRANSFER_PKG.GL_TRANSFER_MAIN executed'
3085 ,p_level => C_LEVEL_EVENT
3086 ,p_module => l_log_module);
3087 END IF;
3088
3089 xla_accounting_err_pkg.set_options
3090 (p_error_source => xla_accounting_err_pkg.C_ACCT_PROGRAM);
3091 ELSE
3092 IF (C_LEVEL_EVENT >= g_log_level) THEN
3093 trace
3094 (p_msg => 'Calling XLA_ACCOUNTING_PUB_PKG.ACCOUNTING_PROGRAM_DOCUMENT '||
3095 'to submit concurrent request for the transfer'
3096 ,p_level => C_LEVEL_EVENT
3097 ,p_module => l_log_module);
3098 END IF;
3099
3100 l_event_source_info.application_id := p_application_id;
3101 FOR l in c_entities LOOP
3102 xla_accounting_pub_pkg.accounting_program_document
3103 (p_event_source_info => l_event_source_info
3104 ,p_entity_id => l.entity_id
3105 ,p_accounting_flag => 'N'
3106 ,p_accounting_mode => NULL
3107 ,p_transfer_flag => 'Y'
3108 ,p_gl_posting_flag => 'Y'
3109 ,p_offline_flag => 'Y'
3110 ,p_accounting_batch_id => p_accounting_batch_id
3111 ,p_errbuf => p_errbuf
3112 ,p_retcode => p_retcode
3113 ,p_request_id => l_request_id);
3114 END LOOP;
3115
3116 END IF;
3117 END IF;
3118
3119 END LOOP;
3120
3121 IF (C_LEVEL_EVENT >= g_log_level) THEN
3122 trace
3123 (p_msg => 'END LOOP: loop ledger'
3124 ,p_level => C_LEVEL_EVENT
3125 ,p_module => l_log_module);
3126 END IF;
3127
3128
3129 --
3130 -- Insert errors
3131 --
3132 xla_accounting_err_pkg.insert_errors;
3133
3134 IF xla_accounting_err_pkg.g_error_count-xla_accounting_err_pkg.g_warning_count = 0 THEN
3135 p_retcode := 0;
3136 p_errbuf := 'Accounting Program completed Normal';
3137 ELSE
3138 p_retcode := 1;
3139 p_errbuf := 'Accounting Program completed Normal with some events in error';
3140 END IF;
3141
3142 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3143 trace
3144 (p_msg => 'p_errbuf = '||p_errbuf
3145 ,p_level => C_LEVEL_PROCEDURE
3146 ,p_module => l_log_module);
3147 trace
3148 (p_msg => 'p_retcode = '||p_retcode
3149 ,p_level => C_LEVEL_PROCEDURE
3150 ,p_module => l_log_module);
3151 trace
3152 (p_msg => 'END of procedure accounting_program_events'
3153 ,p_level => C_LEVEL_PROCEDURE
3154 ,p_module => l_log_module);
3155 END IF;
3156 EXCEPTION
3157 WHEN xla_exceptions_pkg.application_exception THEN
3158 ----------------------------------------------------------------------------
3159 -- set out variables
3160 ----------------------------------------------------------------------------
3161 p_accounting_batch_id := g_accounting_batch_id;
3162 p_retcode := 2;
3163 p_errbuf := xla_messages_pkg.get_message;
3164
3165 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3166 trace
3167 (p_msg => p_errbuf
3168 ,p_level => C_LEVEL_EVENT
3169 ,p_module => l_log_module);
3170 END IF;
3171
3172 ROLLBACK TO SP_EVENTS;
3173
3174 IF (C_LEVEL_EVENT >= g_log_level) THEN
3175 trace
3176 (p_msg => 'ROLLBACK issued in the procedure accounting_program_events'
3177 ,p_level => C_LEVEL_EVENT
3178 ,p_module => l_log_module);
3179 END IF;
3180
3181 xla_accounting_err_pkg.insert_errors;
3182
3183 WHEN OTHERS THEN
3184 ----------------------------------------------------------------------------
3185 -- set out variables
3186 ----------------------------------------------------------------------------
3187 p_accounting_batch_id := g_accounting_batch_id;
3188 p_retcode := 2;
3189 p_errbuf := sqlerrm;
3190
3191 IF (C_LEVEL_ERROR >= g_log_level) THEN
3192 trace
3193 (p_msg => NULL
3194 ,p_level => C_LEVEL_ERROR
3195 ,p_module => l_log_module);
3196 END IF;
3197
3198 ROLLBACK TO SP_EVENTS;
3199
3200 IF (C_LEVEL_EVENT >= g_log_level) THEN
3201 trace
3202 (p_msg => 'ROLLBACK issued in the procedure accounting_program_events'
3203 ,p_level => C_LEVEL_EVENT
3204 ,p_module => l_log_module);
3205 END IF;
3206
3207 xla_accounting_err_pkg.insert_errors;
3208
3209 END accounting_program_events; -- end of procedure
3210
3211 --=============================================================================
3212 --
3213 --
3214 --
3215 --
3216 --
3217 --
3218 --
3219 --
3220 --
3221 --
3222 -- Following routines are used while accounting for a document
3223 --
3224 -- 1. accounting_program_document (procedure)
3225 --
3226 --
3227 --
3228 --
3229 --
3230 --
3231 --
3232 --
3233 --
3234 --
3235 --
3236 --=============================================================================
3237 --=============================================================================
3238 --
3239 --
3240 --
3241 --=============================================================================
3242 PROCEDURE accounting_program_document
3243 (p_application_id IN INTEGER
3244 ,p_entity_id IN NUMBER
3245 ,p_accounting_flag IN VARCHAR2 DEFAULT 'Y'
3246 ,p_accounting_mode IN VARCHAR2
3247 ,p_gl_posting_flag IN VARCHAR2
3248 ,p_offline_flag IN VARCHAR2
3249 ,p_accounting_batch_id OUT NOCOPY NUMBER
3250 ,p_errbuf OUT NOCOPY VARCHAR2
3251 ,p_retcode OUT NOCOPY NUMBER) IS
3252 l_log_module VARCHAR2(240);
3253 BEGIN
3254 IF g_log_enabled THEN
3255 l_log_module := C_DEFAULT_MODULE||'.accounting_program_document';
3256 END IF;
3257 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3258 trace
3259 (p_msg => 'BEGIN of procedure ACCOUNTING_PROGRAM_DOCUMENT'
3260 ,p_level => C_LEVEL_PROCEDURE
3261 ,p_module => l_log_module);
3262 END IF;
3263
3264 -- Bug 7560116 Journal Import not getting spawned as Security Context is not getting set correctly when
3265 -- this procedure is called directly to perform GL xfer
3266 xla_security_pkg.set_security_context(p_application_id);
3267
3268
3269 INSERT INTO xla_acct_prog_events_gt (event_id, ledger_id)
3270 SELECT xe.event_id, xte.ledger_id
3271 FROM xla_events xe
3272 , xla_transaction_entities xte
3273 WHERE xte.application_id = p_application_id
3274 AND xte.entity_id = p_entity_id
3275 AND xe.application_id = p_application_id
3276 AND xe.entity_id = p_entity_id
3277 AND (p_accounting_flag = 'N' OR
3278 NVL(xe.budgetary_control_flag,'N') = DECODE(p_accounting_mode
3279 ,'D','N'
3280 ,'F','N'
3281 ,'Y'));
3282
3283
3284
3285 -- 7193986 start
3286
3287
3288 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3289 trace
3290 (p_msg => 'Rows inserted into xla_acct_prog_events_gt = '||SQL%ROWCOUNT
3291 ,p_level => C_LEVEL_STATEMENT
3292 ,p_module => l_log_module);
3293 END IF;
3294
3295
3296 INSERT INTO xla_evt_class_orders_gt
3297 (event_class_code
3298 ,processing_order
3299 )
3300 SELECT xec.event_class_code
3301 , NVL(t.max_level, -1)
3302 FROM xla_event_classes_b xec
3303 , (SELECT application_id, event_class_code, max(LEVEL) AS max_level
3304 FROM (SELECT application_id, event_class_code, prior_event_class_code
3305 FROM xla_event_class_predecs
3306 WHERE application_id = p_application_id
3307 UNION
3308 SELECT application_id, prior_event_class_code, NULL
3309 FROM xla_event_class_predecs
3310 WHERE application_id = p_application_id) xep
3311 CONNECT BY application_id = PRIOR application_id
3312 AND prior_event_class_code = PRIOR event_class_code
3313 GROUP BY application_id, event_class_code) t
3314 WHERE xec.event_class_code = t.event_class_code(+)
3315 AND xec.application_id = t.application_id(+)
3316 AND xec.application_id = p_application_id
3317 AND xec.event_class_code <> 'MANUAL';
3318
3319
3320 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3321 trace
3322 (p_msg => 'Number of rows inserted into xla_evt_class_orders_gt = '||SQL%ROWCOUNT
3323 ,p_level => C_LEVEL_STATEMENT
3324 ,p_module => l_log_module);
3325 END IF;
3326
3327 -- 7193986 end
3328
3329
3330
3331
3332 xla_accounting_pkg.accounting_program_events
3333 (p_application_id => p_application_id
3334 ,p_accounting_mode => CASE WHEN p_accounting_flag = 'N'
3335 THEN 'NONE'
3336 WHEN p_accounting_mode = 'D'
3337 THEN 'DRAFT'
3338 when p_accounting_mode = 'F'
3339 THEN 'FINAL'
3340 ELSE p_accounting_mode END
3341 ,p_gl_posting_flag => p_gl_posting_flag
3342 ,p_offline_flag => p_offline_flag
3343 ,p_accounting_batch_id => p_accounting_batch_id
3344 ,p_errbuf => p_errbuf
3345 ,p_retcode => p_retcode);
3346
3347 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3348 trace
3349 (p_msg => 'END of procedure ACCOUNTING_PROGRAM_DOCUMENT'
3350 ,p_level => C_LEVEL_PROCEDURE
3351 ,p_module => l_log_module);
3352 END IF;
3353 EXCEPTION
3354 WHEN xla_exceptions_pkg.application_exception THEN
3355 RAISE;
3356 WHEN OTHERS THEN
3357 xla_exceptions_pkg.raise_message
3358 (p_location => 'xla_accounting_pkg.accounting_program_document');
3359 END accounting_program_document; -- end of procedure
3360
3361
3362 --=============================================================================
3363 -- *********** private procedures and functions **********
3364 --=============================================================================
3365 --=============================================================================
3366 --
3367 --
3368 --
3369 --
3370 --
3371 --
3372 --
3373 --
3374 --
3375 --
3376 -- Following routines are used while accounting for batch of documents
3377 --
3378 -- 1. batch_accounting
3379 -- 2. pre_accounting
3380 -- 3. delete_request_je
3381 -- 4. post_accounting
3382 -- 5. enqueue_messages
3383 -- 6. spawn_child_processes
3384 -- 7. wait_for_requests
3385 -- 8. unit_processor
3386 -- 9. is_parent_running
3387 -- 10. sequencing_batch_init
3388 -- 11. process_events
3389 --
3390 --
3391 --
3392 --
3393 --
3394 --
3395 --
3396 --
3397 --
3398 --
3399 --
3400 --=============================================================================
3401
3402 --=============================================================================
3403 --
3404 --
3405 --
3406 --=============================================================================
3407 PROCEDURE batch_accounting IS
3408 l_pre_processing_str VARCHAR2(2000);
3409
3410
3411 l_queue_created_flag VARCHAR2(1) := 'N';
3412 l_queue_started_flag VARCHAR2(1) := 'N';
3413 l_seq_api_called_flag VARCHAR2(1) := 'N';
3414
3415 l_ret_flag_bal_reversal BOOLEAN := FALSE;
3416 l_ret_flag_bal_update BOOLEAN := FALSE;
3417
3418 l_str_lock_entities VARCHAR2(2000);
3419 l_str_update_events VARCHAR2(2000);
3420
3421 l_error_status VARCHAR2(1) := 'N';
3422 l_warning_status VARCHAR2(1) := 'N';
3423 l_log_module VARCHAR2(240);
3424
3425 l_acct_batch_entries NUMBER;
3426
3427
3428 BEGIN
3429 IF g_log_enabled THEN
3430 l_log_module := C_DEFAULT_MODULE||'.batch_accounting';
3431 END IF;
3432 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3433 trace
3434 (p_msg => 'BEGIN of procedure BATCH_ACCOUNTING'
3435 ,p_level => C_LEVEL_PROCEDURE
3436 ,p_module => l_log_module);
3437 END IF;
3438
3439 -------------------------------------------------------------------------
3440 -- Reading setup options for the event application and the ledger
3441 -------------------------------------------------------------------------
3442 BEGIN
3443
3444 SELECT xso.error_limit
3445 ,NVL(xso.processes,1)
3446 ,NVL(xso.processing_unit_size,1)
3447 INTO g_error_limit
3448 ,g_process_count
3449 ,g_unit_size
3450 FROM xla_subledger_options_v xso
3451 WHERE xso.application_id = g_application_id
3452 AND xso.ledger_id = g_ledger_id;
3453
3454 EXCEPTION
3455 WHEN NO_DATA_FOUND THEN
3456 xla_exceptions_pkg.raise_message
3457 (p_appli_s_name => 'XLA'
3458 ,p_msg_name => 'XLA_COMMON_ERROR'
3459 ,p_token_1 => 'ERROR'
3460 ,p_value_1 => 'ERROR: Subledger Accounting Options are not defined for this ledger and application.'||
3461 'Please run Update Subledger Accounting Options program for your application.'
3462 ,p_token_2 => 'LOCATION'
3463 ,p_value_2 => 'xla_accounting_pkg.batch_accounting');
3464 END;
3465
3466 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3467 trace
3468 (p_msg => 'g_error_limit = '||g_error_limit
3469 ,p_level => C_LEVEL_STATEMENT
3470 ,p_module => l_log_module);
3471 trace
3472 (p_msg => 'g_process_count = '||g_process_count
3473 ,p_level => C_LEVEL_STATEMENT
3474 ,p_module => l_log_module);
3475 trace
3476 (p_msg => 'g_unit_size = '||g_unit_size
3477 ,p_level => C_LEVEL_STATEMENT
3478 ,p_module => l_log_module);
3479 END IF;
3480
3481 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Setup for the ledger and Event applications Read');
3482
3483 ----------------------------------------------------------------------------
3484 -- perform pre-accounting steps
3485 ----------------------------------------------------------------------------
3486 pre_accounting();
3487 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Pre-Accounting steps performed');
3488
3489 ----------------------------------------------------------------------------
3490 -- initialize queue for loading documents and completion message
3491 ----------------------------------------------------------------------------
3492 IF (C_LEVEL_EVENT >= g_log_level) THEN
3493 trace
3494 (p_msg => 'Creating message queue'
3495 ,p_level => C_LEVEL_EVENT
3496 ,p_module => l_log_module);
3497 END IF;
3498
3499 dbms_aqadm.create_queue
3500 (queue_name => g_queue_name
3501 ,queue_table => g_queue_table_name); --C_QUEUE_TABLE);
3502 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Queue Created = '||g_queue_name);
3503
3504 dbms_aqadm.create_queue
3505 (queue_name => g_comp_queue_name
3506 ,queue_table => g_queue_table_name); --C_QUEUE_TABLE);
3507 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Queue Created = '||g_comp_queue_name);
3508
3509 l_queue_created_flag := 'Y';
3510
3511 IF (C_LEVEL_EVENT >= g_log_level) THEN
3512 trace
3513 (p_msg => 'Message queue created'
3514 ,p_level => C_LEVEL_EVENT
3515 ,p_module => l_log_module);
3516 trace
3517 (p_msg => 'Starting Message queue'
3518 ,p_level => C_LEVEL_EVENT
3519 ,p_module => l_log_module);
3520 END IF;
3521
3522 dbms_aqadm.start_queue
3523 (queue_name => g_queue_name);
3524 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Queue Started = '||g_queue_name);
3525
3526 dbms_aqadm.start_queue
3527 (queue_name => g_comp_queue_name);
3528 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Queue Started = '||g_comp_queue_name);
3529
3530 l_queue_started_flag := 'Y';
3531
3532 IF (C_LEVEL_EVENT >= g_log_level) THEN
3533 trace
3534 (p_msg => 'Message queue started'
3535 ,p_level => C_LEVEL_EVENT
3536 ,p_module => l_log_module);
3537 END IF;
3538 ----------------------------------------------------------------------------
3539 -- Initialize the error count in the Global Application Context
3540 -- (for keeping error count accross multiple child processes)
3541 -- The context is set in context of "parent request id" which is same as
3542 -- "sys_context('USERENV','CLIENT_IDENTIFIER').
3543 ----------------------------------------------------------------------------
3544 xla_context_pkg.set_acct_err_context
3545 (p_error_count => 0
3546 ,p_client_id => g_parent_request_id);
3547
3548 xla_context_pkg.set_event_count_context
3549 (p_event_count => 0
3550 ,p_client_id => g_parent_request_id);
3551
3552 xla_context_pkg.set_event_nohdr_context
3553 (p_nohdr_extract_flag => 'N'
3554 ,p_client_id => g_parent_request_id);
3555
3556 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Global Context Initialized');
3557
3558 ----------------------------------------------------------------------------
3559 -- Call sequencing routine batch_init in FINAL accounting
3560 ----------------------------------------------------------------------------
3561 IF g_accounting_mode = 'F' THEN
3562 sequencing_batch_init
3563 (p_seq_enabled_flag => g_seq_enabled_flag);
3564 l_seq_api_called_flag := 'Y';
3565 END IF;
3566 ----------------------------------------------------------------------------
3567 -- enqueue messages in the queue
3568 ----------------------------------------------------------------------------
3569 --enqueue_messages;
3570 process_events;
3571
3572 ----------------------------------------------------------------------------
3573 -- Check and wait for Event Processors to complete
3574 ----------------------------------------------------------------------------
3575 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Waiting for Unit Processor requests to complete');
3576 wait_for_requests
3577 (p_array_request_id => g_ep_request_ids
3578 ,p_error_status => l_error_status
3579 ,p_warning_status => l_warning_status);
3580 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Child Threads completed');
3581
3582 ----------------------------------------------------------------------------
3583 -- calling post-accounting
3584 ----------------------------------------------------------------------------
3585 post_accounting
3586 (p_queue_started_flag => l_queue_started_flag
3587 ,p_queue_created_flag => l_queue_created_flag
3588 ,p_seq_api_called_flag => l_seq_api_called_flag);
3589
3590 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Executed post-accounting routine');
3591
3592 IF ((g_error_limit IS NOT NULL) AND
3593 (g_total_error_count >= g_error_limit)
3594 )
3595 THEN
3596 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Message: The error limit defined in the setups was reached for this application');
3597
3598 -- Bug 2742357. Print the message in the report also
3599 xla_accounting_err_pkg.build_message
3600 (p_appli_s_name => 'XLA'
3601 ,p_msg_name => 'XLA_AP_ERROR_LIMIT'
3602 ,p_entity_id => NULL
3603 ,p_event_id => NULL);
3604
3605
3606 END IF;
3607
3608 COMMIT;
3609
3610 IF (C_LEVEL_EVENT >= g_log_level) THEN
3611 trace
3612 (p_msg => 'COMMIT issued in BATCH_ACCOUNTING'
3613 ,p_level => C_LEVEL_EVENT
3614 ,p_module => l_log_module);
3615 END IF;
3616
3617 ----------------------------------------------------------------------------
3618 -- Call massive update only if there is any valid entry
3619 -- Bug 5065965. Modified the following sql for performance.
3620 ----------------------------------------------------------------------------
3621 SELECT COUNT(1) INTO l_acct_batch_entries FROM DUAL
3622 WHERE EXISTS
3623 (SELECT 'Y'
3624 FROM xla_events
3625 WHERE application_id = g_application_id
3626 AND request_id = g_report_request_id
3627 AND process_status_code IN ('P')
3628 );
3629
3630 IF (l_acct_batch_entries > 0) THEN
3631 IF (C_LEVEL_EVENT >= g_log_level) THEN
3632 trace
3633 (p_msg => 'Calling function XLA_BALANCES_PKG.MASSIVE_UPDATE'
3634 ,p_level => C_LEVEL_EVENT
3635 ,p_module => l_log_module);
3636 END IF;
3637
3638 l_ret_flag_bal_update :=
3639 xla_balances_pkg.massive_update
3640 (p_application_id => g_application_id --NULL
3641 ,p_ledger_id => NULL
3642 ,p_entity_id => NULL
3643 ,p_event_id => NULL
3644 ,p_request_id => NULL
3645 ,p_accounting_batch_id => g_accounting_batch_id
3646 ,p_update_mode => 'A'
3647 ,p_execution_mode => 'C');
3648
3649 IF (C_LEVEL_EVENT >= g_log_level) THEN
3650 trace
3651 (p_msg => 'Fucntion XLA_BALANCES_PKG.MASSIVE_UPDATE executed'
3652 ,p_level => C_LEVEL_EVENT
3653 ,p_module => l_log_module);
3654 END IF;
3655
3656
3657 IF NOT l_ret_flag_bal_update THEN
3658 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3659 trace
3660 (p_msg => 'l_ret_flag_bal_update = FALSE'
3661 ,p_level => C_LEVEL_STATEMENT
3662 ,p_module => l_log_module);
3663 END IF;
3664
3665 xla_accounting_err_pkg.build_message
3666 (p_appli_s_name => 'XLA'
3667 ,p_msg_name => 'XLA_AP_BAL_UPDATE_FAILED'
3668 ,p_entity_id => NULL
3669 ,p_event_id => NULL);
3670
3671 print_logfile('Technical problem : Problem in submitting request for balance update');
3672
3673 xla_exceptions_pkg.raise_message
3674 (p_appli_s_name => 'XLA'
3675 ,p_msg_name => 'XLA_AP_BAL_UPDATE_FAILED');
3676 ELSE
3677 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3678 trace
3679 (p_msg => 'l_ret_flag_bal_update = TRUE'
3680 ,p_level => C_LEVEL_STATEMENT
3681 ,p_module => l_log_module);
3682 END IF;
3683 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - request for balance calulation submitted');
3684 END IF;
3685 END IF;
3686
3687 --
3688 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Accounting Program completed successfully');
3689
3690 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3691 trace
3692 (p_msg => 'END of procedure BATCH_ACCOUNTING'
3693 ,p_level => C_LEVEL_PROCEDURE
3694 ,p_module => l_log_module);
3695 END IF;
3696 EXCEPTION
3697 WHEN normal_termination THEN
3698 RAISE;
3699 WHEN xla_exceptions_pkg.application_exception THEN
3700 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3701 trace
3702 (p_msg => 'xla_exceptions_pkg.application_exception: BATCH_ACCOUNTING'
3703 ,p_level => C_LEVEL_EXCEPTION
3704 ,p_module => l_log_module);
3705 END IF;
3706
3707 ROLLBACK;
3708 ----------------------------------------------------------------------------
3709 -- calling post-accounting
3710 ----------------------------------------------------------------------------
3711 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Post Accounting Started');
3712 post_accounting
3713 (p_queue_started_flag => l_queue_started_flag
3714 ,p_queue_created_flag => l_queue_created_flag
3715 ,p_seq_api_called_flag => l_seq_api_called_flag);
3716
3717 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Post Accounting Ended');
3718 --
3719
3720 RAISE;
3721 WHEN OTHERS THEN
3722 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3723 trace
3724 (p_msg => 'Exception: BATCH_ACCOUNTING'
3725 ,p_level => C_LEVEL_EXCEPTION
3726 ,p_module => l_log_module);
3727 END IF;
3728
3729 ROLLBACK;
3730 ----------------------------------------------------------------------------
3731 -- calling post-accounting
3732 ----------------------------------------------------------------------------
3733 post_accounting
3734 (p_queue_started_flag => l_queue_started_flag
3735 ,p_queue_created_flag => l_queue_created_flag
3736 ,p_seq_api_called_flag => l_seq_api_called_flag);
3737
3738 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Executed post-accounting routine');
3739
3740 xla_accounting_err_pkg.build_message
3741 (p_appli_s_name => 'XLA'
3742 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
3743 ,p_token_1 => 'APPLICATION_NAME'
3744 ,p_value_1 => 'SLA'
3745 ,p_entity_id => NULL
3746 ,p_event_id => NULL);
3747 xla_exceptions_pkg.raise_message
3748 (p_location => 'xla_accounting_pkg.batch_accounting');
3749 END batch_accounting; -- end of procedure
3750
3751
3752 --=============================================================================
3753 --
3754 --
3755 --
3756 --=============================================================================
3757 PROCEDURE pre_accounting IS
3758 l_str_lock_entities VARCHAR2(2000);
3759 l_str_update_events VARCHAR2(2000);
3760 l_pre_processing_str VARCHAR2(2000);
3761 l_ret_flag_bal_reversal BOOLEAN;
3762 l_events_count NUMBER;
3763 l_sqlerrm VARCHAR2(2000);
3764 l_log_module VARCHAR2(240);
3765 l_draft_exists_flag VARCHAR2(1);
3766 BEGIN
3767 IF g_log_enabled THEN
3768 l_log_module := C_DEFAULT_MODULE||'.pre_accounting';
3769 END IF;
3770 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3771 trace
3772 (p_msg => 'BEGIN of procedure PRE_ACCOUNTING'
3773 ,p_level => C_LEVEL_PROCEDURE
3774 ,p_module => l_log_module);
3775 END IF;
3776
3777 ----------------------------------------------------------------------------
3778 -- Handle preaccounting hook
3779 ----------------------------------------------------------------------------
3780 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - executing preaccounting hook');
3781 handle_accounting_hook
3782 (p_application_id => g_application_id
3783 ,p_ledger_id => g_ledger_id
3784 ,p_process_category => g_process_category
3785 ,p_end_date => g_end_date
3786 ,p_accounting_mode => g_accounting_mode
3787 ,p_budgetary_control_mode => g_budgetary_control_mode
3788 ,p_valuation_method => g_valuation_method
3789 ,p_security_id_int_1 => g_security_id_int_1
3790 ,p_security_id_int_2 => g_security_id_int_2
3791 ,p_security_id_int_3 => g_security_id_int_3
3792 ,p_security_id_char_1 => g_security_id_char_1
3793 ,p_security_id_char_2 => g_security_id_char_2
3794 ,p_security_id_char_3 => g_security_id_char_3
3795 ,p_report_request_id => NULL
3796 ,p_event_name => 'preaccounting'
3797 ,p_event_key => to_char(g_accounting_batch_id)||'-'
3798 ||to_char(g_parent_request_id));
3799 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - preaccounting hook executed successfully');
3800
3801
3802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3803 trace
3804 (p_msg => 'END of procedure PRE_ACCOUNTING'
3805 ,p_level => C_LEVEL_PROCEDURE
3806 ,p_module => l_log_module);
3807 END IF;
3808 EXCEPTION
3809 WHEN normal_termination THEN
3810 RAISE;
3811 WHEN xla_exceptions_pkg.application_exception THEN
3812 RAISE;
3813 WHEN OTHERS THEN
3814 xla_accounting_err_pkg.build_message
3815 (p_appli_s_name => 'XLA'
3816 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
3817 ,p_token_1 => 'APPLICATION_NAME'
3818 ,p_value_1 => 'SLA'
3819 ,p_entity_id => NULL
3820 ,p_event_id => NULL);
3821 xla_exceptions_pkg.raise_message
3822 (p_location => 'xla_accounting_pkg.pre_accounting');
3823 END pre_accounting; -- end of procedure
3824
3825
3826 --=============================================================================
3827 --
3828 --
3829 --
3830 --=============================================================================
3831
3832 PROCEDURE delete_request_je IS
3833 l_log_module VARCHAR2(240);
3834 l_delete_count NUMBER;
3835
3836 BEGIN
3837 IF g_log_enabled THEN
3838 l_log_module := C_DEFAULT_MODULE||'.delete_request_je';
3839 END IF;
3840 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3841 trace
3842 (p_msg => 'BEGIN of procedure DELETE_REQUEST_JE'
3843 ,p_level => C_LEVEL_PROCEDURE
3844 ,p_module => l_log_module);
3845 END IF;
3846
3847 --
3848 -- Delete from xla_accounting_errors
3849 --
3850 DELETE FROM xla_accounting_errors
3851 WHERE event_id IN
3852 (SELECT event_id FROM xla_events_gt);
3853
3854 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3855 trace
3856 (p_msg => 'Number of errors deleted = '||SQL%ROWCOUNT
3857 ,p_level => C_LEVEL_STATEMENT
3858 ,p_module => l_log_module);
3859 END IF;
3860
3861 --
3862 -- Delete from xla_distribution_links
3863 --
3864 DELETE FROM xla_distribution_links
3865 WHERE ae_header_id IN
3866 (SELECT /*+ cardinality(XE,10) leading(XE) use_nl(XH) unnest */ xh.ae_header_id
3867 FROM xla_events_gt xe,
3868 xla_ae_headers xh
3869 WHERE xe.process_status_code in ('D','E','R','I')
3870 AND xh.application_id = xe.application_id
3871 AND xh.event_id = xe.event_id
3872 )
3873 AND application_id = g_application_id;
3874
3875 l_delete_count := SQL%ROWCOUNT;
3876
3877 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3878 trace
3879 (p_msg => 'Number of distribution links deleted = '||l_delete_count
3880 ,p_level => C_LEVEL_STATEMENT
3881 ,p_module => l_log_module);
3882 END IF;
3883
3884 IF l_delete_count > 0 THEN
3885 --
3886 -- Delete from xla_ae_segment_values
3887 --
3888 DELETE /*+ index(XLA_AE_SEGMENT_VALUES, XLA_AE_SEGMENT_VALUES_U1) */
3889 FROM xla_ae_segment_values
3890 WHERE ae_header_id IN
3891 (SELECT xh.ae_header_id
3892 FROM xla_events_gt xe,
3893 xla_ae_headers xh
3894 WHERE xe.process_status_code in ('D','E','R', 'I')
3895 AND xh.application_id = xe.application_id
3896 AND xh.event_id = xe.event_id
3897 );
3898
3899 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3900 trace
3901 (p_msg => 'Number of segment values deleted = '||SQL%ROWCOUNT
3902 ,p_level => C_LEVEL_STATEMENT
3903 ,p_module => l_log_module);
3904 END IF;
3905
3906 --
3907 -- Delete from xla_ae_line_acs
3908 --
3909 DELETE FROM xla_ae_line_acs
3910 WHERE ae_header_id IN
3911 (SELECT aeh.ae_header_id
3912 FROM xla_events_gt evt
3913 ,xla_ae_headers aeh
3914 WHERE evt.process_status_code in ('D','E','R','I')
3915 AND aeh.application_id = evt.application_id
3916 AND aeh.event_id = evt.event_id);
3917
3918 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3919 trace
3920 (p_msg => 'Number of line acs deleted = '||SQL%ROWCOUNT
3921 ,p_level => C_LEVEL_STATEMENT
3922 ,p_module => l_log_module);
3923 END IF;
3924
3925 --
3926 -- Delete from xla_ae_header_acs
3927 --
3928 DELETE FROM xla_ae_header_acs
3929 WHERE ae_header_id IN
3930 (SELECT aeh.ae_header_id
3931 FROM xla_events_gt evt
3932 ,xla_ae_headers aeh
3933 WHERE evt.process_status_code in ('D','E','R','I')
3934 AND aeh.application_id = evt.application_id
3935 AND aeh.event_id = evt.event_id);
3936
3937 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3938 trace
3939 (p_msg => 'Number of header acs deleted = '||SQL%ROWCOUNT
3940 ,p_level => C_LEVEL_STATEMENT
3941 ,p_module => l_log_module);
3942 END IF;
3943
3944 --
3945 -- Delete from xla_ae_lines
3946 --
3947 DELETE FROM xla_ae_lines
3948 WHERE application_id = g_application_id
3949 AND ae_header_id IN
3950 (SELECT xh.ae_header_id
3951 FROM xla_events_gt xe,
3952 xla_ae_headers xh
3953 WHERE xe.process_status_code in ('D','E','R','I')
3954 AND xh.application_id = xe.application_id
3955 AND xh.event_id = xe.event_id
3956 );
3957
3958 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3959 trace
3960 (p_msg => 'Number of ae lines deleted = '||SQL%ROWCOUNT
3961 ,p_level => C_LEVEL_STATEMENT
3962 ,p_module => l_log_module);
3963 END IF;
3964
3965 --
3966 -- Delete from xla_ae_headers
3967 --
3968 DELETE /*+ index(aeh, xla_ae_headers_n2) */
3969 FROM xla_ae_headers aeh
3970 WHERE application_id = g_application_id
3971 AND event_id IN (SELECT event_id
3972 FROM xla_events_gt
3973 WHERE process_status_code IN ('D','E','R','I'));
3974
3975 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3976 trace
3977 (p_msg => 'Number of ae headers deleted = '||SQL%ROWCOUNT
3978 ,p_level => C_LEVEL_STATEMENT
3979 ,p_module => l_log_module);
3980 END IF;
3981
3982 END IF;
3983
3984 ----------------------------------------------------------------------------
3985 --
3986 -- Used by the Accounting Event Extract Diagnostics process
3987 --
3988 ----------------------------------------------------------------------------
3989 ----------------------------------------------------------------------------
3990 -- following deletes the Accounting Event Extract Diagnostics data
3991 -- for the events that are being accounted in this run.
3992 ----------------------------------------------------------------------------
3993
3994 IF ( nvl(fnd_profile.value('XLA_DIAGNOSTIC_MODE'),'N') = 'Y') THEN
3995
3996 DELETE FROM xla_diag_sources
3997 WHERE event_id IN
3998 (SELECT event_id FROM xla_events_gt);
3999
4000 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4001 trace
4002 (p_msg => 'Number of Extract sources rows deleted = '||SQL%ROWCOUNT
4003 ,p_level => C_LEVEL_STATEMENT
4004 ,p_module => l_log_module);
4005 END IF;
4006
4007 DELETE FROM xla_diag_events
4008 WHERE event_id IN
4009 (SELECT event_id FROM xla_events_gt);
4010
4011 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4012 trace
4013 (p_msg => 'Number of Extract events deleted = '||SQL%ROWCOUNT
4014 ,p_level => C_LEVEL_STATEMENT
4015 ,p_module => l_log_module);
4016 END IF;
4017 --bug6369888
4018 DELETE FROM xla_diag_ledgers d
4019 WHERE d.application_id = g_application_id
4020 AND NOT EXISTS
4021 (SELECT ledger_id, request_id
4022 FROM xla_diag_events
4023 WHERE application_id = d.application_id
4024 AND request_id = d.accounting_request_id
4025 AND ledger_id = d.primary_ledger_id
4026 );
4027
4028 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4029 trace
4030 (p_msg => 'Number of Extract ledgers deleted = '||SQL%ROWCOUNT
4031 ,p_level => C_LEVEL_STATEMENT
4032 ,p_module => l_log_module);
4033 END IF;
4034
4035 END IF;
4036
4037 ----------------------------------------------------------------------------
4038 --
4039 -- End of code used by the Accounting Event Extract Diagnostics process
4040 --
4041 ----------------------------------------------------------------------------
4042
4043
4044 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4045 trace
4046 (p_msg => 'END of procedure DELETE_REQUEST_JE'
4047 ,p_level => C_LEVEL_PROCEDURE
4048 ,p_module => l_log_module);
4049 END IF;
4050 EXCEPTION
4051 WHEN xla_exceptions_pkg.application_exception THEN
4052 RAISE;
4053 WHEN OTHERS THEN
4054 xla_exceptions_pkg.raise_message
4055 (p_location => 'xla_accounting_pkg.delete_request_je');
4056 END delete_request_je;
4057
4058
4059 --=============================================================================
4060 --
4061 --
4062 --
4063 --=============================================================================
4064 PROCEDURE post_accounting
4065 (p_queue_started_flag IN OUT NOCOPY VARCHAR2
4066 ,p_queue_created_flag IN OUT NOCOPY VARCHAR2
4067 ,p_seq_api_called_flag IN OUT NOCOPY VARCHAR2) IS
4068 l_seq_status VARCHAR2(30);
4069 l_log_module VARCHAR2(240);
4070 BEGIN
4071 IF g_log_enabled THEN
4072 l_log_module := C_DEFAULT_MODULE||'.post_accounting';
4073 END IF;
4074 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4075 trace
4076 (p_msg => 'BEGIN of procedure POST_ACCOUNTING'
4077 ,p_level => C_LEVEL_PROCEDURE
4078 ,p_module => l_log_module);
4079 END IF;
4080
4081 ----------------------------------------------------------------------------
4082 -- Total error error counts are read into a local variable before the
4083 -- global context is cleared. This is later used to set the 'p_retcode'.
4084 -- bug # 2709397.
4085 ----------------------------------------------------------------------------
4086 g_total_error_count := xla_accounting_err_pkg.get_total_error_count;
4087
4088
4089 --
4090 -- 4865292
4091 -- Compare event count with header extract count
4092 -- Display messages when the counts are different
4093 --
4094 IF xla_context_pkg.get_event_nohdr_context = 'Y' THEN
4095
4096 xla_accounting_err_pkg.build_message
4097 (p_appli_s_name => 'XLA'
4098 ,p_msg_name => 'XLA_AP_NO_HDR_EXTRACT'
4099 ,p_entity_id => NULL
4100 ,p_event_id => NULL
4101 ,p_ledger_id => g_ledger_id);
4102
4103 END IF;
4104
4105 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4106 trace
4107 (p_msg => 'g_total_error_count = '||g_total_error_count
4108 ,p_level => C_LEVEL_STATEMENT
4109 ,p_module => l_log_module);
4110 END IF;
4111
4112 ----------------------------------------------------------------------------
4113 -- clean up the global application context
4114 ----------------------------------------------------------------------------
4115 xla_context_pkg.clear_acct_err_context
4116 (p_client_id => g_parent_request_id);
4117
4118 xla_context_pkg.clear_event_context
4119 (p_client_id => g_parent_request_id);
4120
4121 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4122 trace
4123 (p_msg => 'Global Context cleared'
4124 ,p_level => C_LEVEL_STATEMENT
4125 ,p_module => l_log_module);
4126 END IF;
4127
4128 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Global Context cleared');
4129
4130 ----------------------------------------------------------------------------
4131 -- clean up queues for each event application
4132 ----------------------------------------------------------------------------
4133 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4134 trace
4135 (p_msg => 'p_queue_started_flag = '||p_queue_started_flag
4136 ,p_level => C_LEVEL_STATEMENT
4137 ,p_module => l_log_module);
4138 trace
4139 (p_msg => 'p_queue_created_flag = '||p_queue_created_flag
4140 ,p_level => C_LEVEL_STATEMENT
4141 ,p_module => l_log_module);
4142 END IF;
4143
4144 IF p_queue_started_flag = 'Y' THEN
4145 IF (C_LEVEL_EVENT >= g_log_level) THEN
4146 trace
4147 (p_msg => 'Ready to stop the message queue'
4148 ,p_level => C_LEVEL_EVENT
4149 ,p_module => l_log_module);
4150 END IF;
4151
4152 dbms_aqadm.stop_queue(queue_name => g_queue_name
4153 ,wait => TRUE); --5056507
4154 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Queue stopped = '||g_queue_name);
4155 dbms_aqadm.stop_queue(queue_name => g_comp_queue_name
4156 ,wait => TRUE); --5056507
4157 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Queue stopped = '||g_comp_queue_name);
4158 p_queue_started_flag := 'N';
4159
4160 IF (C_LEVEL_EVENT >= g_log_level) THEN
4161 trace
4162 (p_msg => 'Message queue stopped'
4163 ,p_level => C_LEVEL_EVENT
4164 ,p_module => l_log_module);
4165 END IF;
4166 END IF;
4167
4168 IF p_queue_created_flag = 'Y' THEN
4169 IF (C_LEVEL_EVENT >= g_log_level) THEN
4170 trace
4171 (p_msg => 'Ready to drop the message queue'
4172 ,p_level => C_LEVEL_EVENT
4173 ,p_module => l_log_module);
4174 END IF;
4175
4176 dbms_aqadm.drop_queue(queue_name => g_queue_name);
4177 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Queue dropped = '||g_queue_name);
4178 dbms_aqadm.drop_queue(queue_name => g_comp_queue_name);
4179 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Queue dropped = '||g_comp_queue_name);
4180 p_queue_created_flag := 'N';
4181
4182 IF (C_LEVEL_EVENT >= g_log_level) THEN
4183 trace
4184 (p_msg => 'Message queue dropped'
4185 ,p_level => C_LEVEL_EVENT
4186 ,p_module => l_log_module);
4187 END IF;
4188 END IF;
4189
4190 ----------------------------------------------------------------------------
4191 -- Call sequencing batch_exit
4192 ----------------------------------------------------------------------------
4193 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4194 trace
4195 (p_msg => 'p_seq_api_called_flag = '||p_seq_api_called_flag
4196 ,p_level => C_LEVEL_STATEMENT
4197 ,p_module => l_log_module);
4198 END IF;
4199
4200 IF p_seq_api_called_flag = 'Y' THEN
4201 BEGIN
4202 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Calling sequencing batch_exit');
4203
4204 IF (C_LEVEL_EVENT >= g_log_level) THEN
4205 trace
4206 (p_msg => 'Calling the procedure FUN_SEQ_BATCH.BATCH_EXIT'
4207 ,p_level => C_LEVEL_EVENT
4208 ,p_module => l_log_module);
4209 END IF;
4210
4211 fun_seq_batch.batch_exit
4212 (p_request_id => g_parent_request_id
4213 ,x_status => l_seq_status);
4214 p_seq_api_called_flag := 'N';
4215 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Returned from sequencing batch_exit');
4216
4217 IF (C_LEVEL_EVENT >= g_log_level) THEN
4218 trace
4219 (p_msg => 'Procedure FUN_SEQ_BATCH.BATCH_EXIT executed'
4220 ,p_level => C_LEVEL_EVENT
4221 ,p_module => l_log_module);
4222 END IF;
4223
4224 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4225 trace
4226 (p_msg => 'l_seq_status = '||l_seq_status
4227 ,p_level => C_LEVEL_STATEMENT
4228 ,p_module => l_log_module);
4229 END IF;
4230
4231 IF l_seq_status <> 'SUCCESS' THEN
4232 xla_accounting_err_pkg.build_message
4233 (p_appli_s_name => 'XLA'
4234 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
4235 ,p_token_1 => 'APPLICATION_NAME'
4236 ,p_value_1 => 'SLA'
4237 ,p_entity_id => NULL
4238 ,p_event_id => NULL);
4239
4240 print_logfile('Technical problem : Problem encountered in sequencing BATCH_EXIT. '||
4241 'Please submit the concurrent program to compelte this process');
4242 END IF;
4243 EXCEPTION
4244 WHEN OTHERS THEN
4245 xla_accounting_err_pkg.build_message
4246 (p_appli_s_name => 'XLA'
4247 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
4248 ,p_token_1 => 'APPLICATION_NAME'
4249 ,p_value_1 => 'SLA'
4250 ,p_entity_id => NULL
4251 ,p_event_id => NULL);
4252
4253 print_logfile('Technical problem : Problem encountered in sequencing BATCH_EXIT. '||
4254 'Please submit the concurrent program to compelte this process');
4255 END;
4256 END IF;
4257
4258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4259 trace
4260 (p_msg => 'END of procedure POST_ACCOUNTING'
4261 ,p_level => C_LEVEL_PROCEDURE
4262 ,p_module => l_log_module);
4263 END IF;
4264 EXCEPTION
4265 WHEN xla_exceptions_pkg.application_exception THEN
4266 RAISE;
4267 WHEN OTHERS THEN
4268 xla_accounting_err_pkg.build_message
4269 (p_appli_s_name => 'XLA'
4270 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
4271 ,p_token_1 => 'APPLICATION_NAME'
4272 ,p_value_1 => 'SLA'
4273 ,p_entity_id => NULL
4274 ,p_event_id => NULL);
4275 xla_exceptions_pkg.raise_message
4276 (p_location => 'xla_accounting_pkg.post_accounting');
4277 END post_accounting;
4278
4279
4280 --=============================================================================
4281 --
4282 --
4283 --
4284 --=============================================================================
4285
4286 PROCEDURE enqueue_messages
4287 (p_processing_order INTEGER
4288 ,p_max_processing_order INTEGER
4289 ,p_children_spawned IN OUT NOCOPY BOOLEAN
4290 ,p_msg_count IN OUT NOCOPY INTEGER)
4291 IS
4292 TYPE ref_cur_type IS REF CURSOR;
4293 csr_event_class ref_cur_type;
4294 csr_entity ref_cur_type;
4295
4296 l_cur_event_stmt VARCHAR2(8000);
4297 l_cur_entity_stmt VARCHAR2(8000);
4298
4299 l_entity_id xla_array_number_type; -- xla_number_array_type;
4300 l_entity_found BOOLEAN := FALSE;
4301 l_children_spawned BOOLEAN := FALSE;
4302 l_unit_count NUMBER := 0;
4303 l_enq_options dbms_aq.enqueue_options_t;
4304 l_msg_prop dbms_aq.message_properties_t;
4305 l_message xla_queue_msg_type; --SYSTEM.xla_queue_msg_type;
4306 l_msgid RAW(16);
4307
4308 l_event_class_code VARCHAR2(30);
4309 l_unit_size NUMBER := 0;
4310
4311 l_log_module VARCHAR2(240);
4312 l_combine_event_classes VARCHAR2(10000);
4313 l_anytime_class VARCHAR2(5000);
4314 l_current_class VARCHAR2(5000);
4315
4316 BEGIN
4317 IF g_log_enabled THEN
4318 l_log_module := C_DEFAULT_MODULE||'.enqueue_messages';
4319 END IF;
4320 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4321 trace
4322 (p_msg => 'BEGIN of procedure ENQUEUE_MESSAGES'
4323 ,p_level => C_LEVEL_PROCEDURE
4324 ,p_module => l_log_module);
4325
4326 trace
4327 (p_msg => 'p_processing_order = '||p_processing_order
4328 ,p_level => C_LEVEL_PROCEDURE
4329 ,p_module => l_log_module);
4330 END IF;
4331
4332 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Ready to Enqueue documents in the queue');
4333 -------------------------------------------------------------------------------
4334 -- Retrieve Processing Unit Size at Event Class Level
4335 -------------------------------------------------------------------------------
4336 --bug6369888 changed cursor to merge into single query.
4337 l_cur_event_stmt :=
4338 'SELECT /*+ index(evt,XLA_EVENTS_N3) */ MIN(nvl(xjc.processing_unit_size, :1))
4339 FROM xla_events evt,
4340 xla_transaction_entities ent,
4341 xla_event_types_b xet,
4342 xla_event_class_attrs eca,
4343 xla_evt_class_orders_gt xpo,
4344 xla_je_categories xjc
4345 WHERE ent.application_id = :3
4346 AND ent.ledger_id = :4
4347 AND evt.application_id = :5
4348 AND evt.entity_id = ent.entity_id
4349 AND xet.application_id = evt.application_id
4350 AND xet.event_type_code = evt.event_type_code
4351 AND eca.application_id = xet.application_id
4352 AND eca.entity_code = xet.entity_code
4353 AND eca.event_class_code = xet.event_class_code
4354 AND eca.event_class_group_code = nvl(:6, eca.event_class_group_code)
4355 AND evt.event_type_code NOT IN(''FULL_MERGE'', ''PARTIAL_MERGE'')
4356 AND evt.process_status_code IN(''I'', ''E'', ''R'', decode(:7, ''N'', ''D'', ''E''), decode(:8, ''N'', ''U'', ''E''))
4357 AND evt.event_status_code IN(''U'', decode(:9, ''F'', ''N'', ''U''))
4358 AND evt.on_hold_flag = ''N''
4359 AND evt.event_date <= :10
4360 AND ent.entity_code <> :11
4361 AND nvl(evt.budgetary_control_flag, ''N'') = ''N''
4362 AND xet.event_class_code = xpo.event_class_code
4363 AND xpo.processing_order = :2
4364 AND xjc.application_id = :12
4365 AND xjc.ledger_id = :13
4366 AND xjc.event_class_code = xpo.event_class_code '
4367 ||g_security_condition;
4368
4369 l_cur_entity_stmt :=
4370 'SELECT /*+ index(evt,XLA_EVENTS_N3) */ -- Bug 5529420 reverted bug6369888
4371 DISTINCT evt.entity_id
4372 FROM xla_events evt
4373 ,xla_transaction_entities ent
4374 ,xla_event_types_b xet
4375 ,xla_event_class_attrs eca
4376 ,xla_evt_class_orders_gt xpo
4377 WHERE ent.application_id = :1
4378 AND ent.ledger_id = :2
4379 AND evt.application_id = :3
4380 AND evt.entity_id = ent.entity_id
4381 AND xet.application_id = evt.application_id
4382 AND xet.event_type_code = evt.event_type_code
4383 AND eca.application_id = xet.application_id
4384 AND eca.entity_code = xet.entity_code
4385 AND eca.event_class_code = xet.event_class_code
4386 AND eca.event_class_group_code = NVL(:4, eca.event_class_group_code)
4387 AND evt.event_type_code NOT IN (''FULL_MERGE'', ''PARTIAL_MERGE'')
4388 AND evt.process_status_code IN (''I'',''E'', ''R'',DECODE(:5,''N'',''D'',''E'')
4389 ,DECODE(:6,''N'',''U'',''E'')
4390 )
4391 AND evt.event_status_code IN (''U'',DECODE(:7,''F'',''N'',''U''))
4392 AND evt.on_hold_flag = ''N''
4393 AND evt.event_date <= :8
4394 AND ent.entity_code <> :9
4395 AND NVL(evt.budgetary_control_flag,''N'') = ''N''
4396 AND xet.event_class_code = xpo.event_class_code
4397 AND xpo.processing_order = :10 '
4398 ||g_security_condition;
4399
4400 ----------------------------------------------------------------------------
4401 -- initiating queue/message related variables
4402 ----------------------------------------------------------------------------
4403 l_enq_options.visibility := dbms_aq.IMMEDIATE;
4404 l_enq_options.relative_msgid := NULL;
4405 l_enq_options.sequence_deviation := NULL;
4406
4407 IF (p_processing_order = -1) THEN
4408 l_msg_prop.priority := p_max_processing_order+1;
4409 ELSE
4410 l_msg_prop.priority := p_processing_order;
4411 END IF;
4412 l_msg_prop.DELAY := dbms_aq.NO_DELAY;
4413 l_msg_prop.expiration := dbms_aq.NEVER;
4414 l_msg_prop.correlation := NULL;
4415 l_msg_prop.exception_queue := NULL;
4416 l_msg_prop.sender_id := NULL;
4417
4418 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4419 trace
4420 (p_msg => 'l_cur_event_stmt '||l_cur_event_stmt
4421 ,p_level => C_LEVEL_STATEMENT
4422 ,p_module => l_log_module);
4423 END IF;
4424 --bug6369888 removed loop
4425 SELECT MAX(xjc.processing_unit_size)
4426 INTO l_unit_size
4427 FROM xla_je_categories xjc,
4428 (
4429 SELECT
4430 xpo.event_class_code
4431 FROM xla_evt_class_orders_gt xpo
4432 WHERE xpo.processing_order = p_processing_order
4433 ) tab1
4434 WHERE xjc.application_id = g_application_id
4435 AND xjc.ledger_id = g_ledger_id
4436 AND xjc.event_class_code = tab1.event_class_code;
4437
4438 IF l_unit_size <> NULL THEN
4439 OPEN csr_event_class FOR l_cur_event_stmt USING g_unit_size
4440 ,p_processing_order
4441 ,g_application_id
4442 ,g_ledger_id
4443 ,g_application_id
4444 ,g_process_category
4445 ,g_error_only_flag
4446 ,g_error_only_flag
4447 ,g_accounting_mode
4448 ,g_end_date
4449 ,C_MANUAL
4450 ,g_application_id
4451 ,g_ledger_id ;
4452 FETCH csr_event_class INTO l_unit_size;
4453 CLOSE csr_event_class;
4454 END IF;
4455
4456 -------------------------------------------------------------------------------------------------
4457 -- 4597150 Find all event class for process order of -1
4458 -------------------------------------------------------------------------------------------------
4459 l_anytime_class := concat_event_classes(-1);
4460
4461 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4462 trace
4463 (p_msg => 'Event class for processing order of -1 = '||l_anytime_class
4464 ,p_level => C_LEVEL_STATEMENT
4465 ,p_module => l_log_module);
4466 END IF;
4467
4468 ----------------------------------------------------------
4469 -- 4597150 Find all event class for current process order
4470 ----------------------------------------------------------
4471 IF p_processing_order <> -1 THEN
4472 l_current_class := concat_event_classes(p_processing_order);
4473 ELSE
4474 l_current_class := l_anytime_class;
4475 END IF;
4476
4477 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4478 trace
4479 (p_msg => 'Event class for processing order of '
4480 ||p_processing_order||' = '||l_current_class
4481 ,p_level => C_LEVEL_STATEMENT
4482 ,p_module => l_log_module);
4483 END IF;
4484
4485 -------------------------------------------------------------------------
4486 -- 4597150 : combine Current and Anytime event classes
4487 -- e.g. 'EC1','EC2'#-#-#-#-#-#-#-#'EC3','EC4'
4488 -- When Current Process Order is -1, l_current_class = l_anytime_class
4489 -------------------------------------------------------------------------
4490 l_combine_event_classes := l_current_class||C_DELIMITER||l_anytime_class;
4491 l_msg_prop.user_property :=
4492 SYS.AnyData.ConvertVarchar2(l_combine_event_classes);
4493
4494 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4495 trace
4496 (p_msg => 'l_cur_entity_stmt '||l_cur_entity_stmt
4497 ,p_level => C_LEVEL_STATEMENT
4498 ,p_module => l_log_module);
4499 END IF;
4500
4501 OPEN csr_entity FOR l_cur_entity_stmt USING g_application_id
4502 ,g_ledger_id
4503 ,g_application_id
4504 ,g_process_category
4505 ,g_error_only_flag
4506 ,g_error_only_flag
4507 ,g_accounting_mode
4508 ,g_end_date
4509 ,C_MANUAL
4510 ,p_processing_order;
4511
4512 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4513 trace
4514 (p_msg => 'g_unit_size '||g_unit_size
4515 ,p_level => C_LEVEL_STATEMENT
4516 ,p_module => l_log_module);
4517 END IF;
4518
4519 ----------------------------------------------------------------------------
4520 -- loop for each data fetched from the cursor. This will enqueue the data
4521 -- in the queue
4522 ----------------------------------------------------------------------------
4523 LOOP
4524 FETCH csr_entity BULK COLLECT INTO l_entity_id LIMIT NVL(l_unit_size,g_unit_size);
4525
4526 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4527 trace
4528 (p_msg => ' l_entity_id.COUNT ='||l_entity_id.COUNT
4529 ,p_level => C_LEVEL_STATEMENT
4530 ,p_module => l_log_module);
4531 FOR i in 1..l_entity_id.COUNT LOOP
4532 trace
4533 (p_msg => 'entity_id ='||l_entity_id(i)
4534 ,p_level => C_LEVEL_STATEMENT
4535 ,p_module => l_log_module);
4536 END LOOP;
4537 END IF;
4538
4539 -------------------------------------------------------------------------
4540 -- following is the only way to exit the indefinite loop. It exits when
4541 -- no documents are fetched into the array variable 'l_entity_id'
4542 -------------------------------------------------------------------------
4543 EXIT WHEN l_entity_id.COUNT = 0;
4544
4545 IF NOT p_children_spawned THEN
4546 ----------------------------------------------------------------------------
4547 -- spawn parallel processes, "event processors" for processing documents.
4548 -- number of paralle process spawned depends on the ledger setup
4549 ----------------------------------------------------------------------------
4550 --
4551 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Spawning unit processors');
4552
4553 spawn_child_processes;
4554 p_children_spawned := TRUE;
4555 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Unit processors spawned');
4556
4557 END IF;
4558
4559 -------------------------------------------------------------------------
4560 -- l_entity_found is set to TRUE to indicate that there are events that
4561 -- that are eligible to be processed
4562 -------------------------------------------------------------------------
4563 l_entity_found := TRUE;
4564 l_unit_count := l_unit_count + 1;
4565 p_msg_count := p_msg_count + 1;
4566
4567 -------------------------------------------------------------------------
4568 -- create a message from the fetched entity ids.
4569 -------------------------------------------------------------------------
4570 l_message := xla_queue_msg_type(l_entity_id); --SYSTEM.xla_queue_msg_type(l_entity_id);
4571
4572 -------------------------------------------------------------------------
4573 -- enqueue the message in the queue
4574 -------------------------------------------------------------------------
4575 dbms_aq.enqueue
4576 (g_queue_name
4577 ,l_enq_options
4578 ,l_msg_prop
4579 ,l_message
4580 ,l_msgid);
4581
4582 g_parent_data.total_entity_count := g_parent_data.total_entity_count +
4583 csr_entity%ROWCOUNT;
4584 END LOOP;
4585
4586 CLOSE csr_entity;
4587
4588 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4589 trace
4590 (p_msg => 'END of procedure ENQUEUE_MESSAGES'
4591 ,p_level => C_LEVEL_PROCEDURE
4592 ,p_module => l_log_module);
4593 END IF;
4594 EXCEPTION
4595 WHEN NO_DATA_FOUND THEN
4596 IF csr_event_class%NOTFOUND THEN
4597 xla_exceptions_pkg.raise_message
4598 (p_appli_s_name => 'XLA'
4599 ,p_msg_name => 'XLA_COMMON_ERROR'
4600 ,p_token_1 => 'ERROR'
4601 ,p_value_1 => 'Journal categories does not have data for this ledger and application.
4602 Please run Update Subledger Accounting Options program for your
4603 application '||'ledger_id = '||g_ledger_id||
4604 ' application_id = '|| g_application_id
4605 ,p_token_2 => 'LOCATION'
4606 ,p_value_2 => 'xla_accounting_pkg.enqueue_messages');
4607 END IF;
4608 WHEN normal_termination THEN
4609 IF csr_entity%ISOPEN THEN
4610 CLOSE csr_entity;
4611 END IF;
4612 RAISE;
4613 WHEN xla_exceptions_pkg.application_exception THEN
4614 IF csr_entity%ISOPEN THEN
4615 CLOSE csr_entity;
4616 END IF;
4617 RAISE;
4618 WHEN OTHERS THEN
4619 IF csr_entity%ISOPEN THEN
4620 CLOSE csr_entity;
4621 END IF;
4622 xla_exceptions_pkg.raise_message
4623 (p_location => 'xla_accounting_pkg.enqueue_messages');
4624 END enqueue_messages; -- end of procedure
4625
4626 --=============================================================================
4627 --
4628 --
4629 --
4630 --=============================================================================
4631 PROCEDURE dequeue_completion_messages
4632 (p_msg_count INTEGER)
4633 IS
4634 l_msgid RAW(16);
4635 l_conf_msg_prop dbms_aq.message_properties_t;
4636 l_conf_message xla_queue_msg_type; -- SYSTEM.xla_queue_msg_type;
4637 l_deq_options dbms_aq.dequeue_options_t;
4638 l_msg_count INTEGER;
4639
4640 l_log_module VARCHAR2(240);
4641 BEGIN
4642 IF g_log_enabled THEN
4643 l_log_module := C_DEFAULT_MODULE||'.dequeue_completion_messages';
4644 END IF;
4645
4646 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4647 trace
4648 (p_msg => 'BEGIN of procedure dequeue_completion_messages'
4649 ,p_level => C_LEVEL_PROCEDURE
4650 ,p_module => l_log_module);
4651 END IF;
4652
4653 IF (C_LEVEL_EVENT >= g_log_level) THEN
4654 trace
4655 (p_msg => 'BEGIN LOOP : dequeue completion messges - p_msg_count = '||p_msg_count
4656 ,p_level => C_LEVEL_EVENT
4657 ,p_module => l_log_module);
4658 END IF;
4659
4660 l_deq_options.consumer_name := NULL;
4661 l_deq_options.dequeue_mode := dbms_aq.REMOVE;
4662 l_deq_options.navigation := dbms_aq.FIRST_MESSAGE;
4663 l_deq_options.visibility := dbms_aq.IMMEDIATE;
4664 l_deq_options.wait := 60;
4665 l_deq_options.msgid := NULL;
4666 l_deq_options.correlation := NULL;
4667
4668 l_msg_count := p_msg_count;
4669
4670 --
4671 -- Get completion messages for all document messages before proceeding
4672 --
4673 WHILE (l_msg_count > 0) LOOP
4674 IF (C_LEVEL_EVENT >= g_log_level) THEN
4675 trace
4676 (p_msg => 'LOOP : dequeue completion messges : '||p_msg_count
4677 ,p_level => C_LEVEL_EVENT
4678 ,p_module => l_log_module);
4679 END IF;
4680
4681 l_msgid := NULL;
4682 BEGIN
4683
4684 IF (C_LEVEL_EVENT >= g_log_level) THEN
4685 trace
4686 (p_msg => 'Begin LOOP : dequeue completion messges : '||p_msg_count
4687 ,p_level => C_LEVEL_EVENT
4688 ,p_module => l_log_module);
4689 END IF;
4690
4691 dbms_aq.dequeue
4692 (g_comp_queue_name
4693 ,l_deq_options
4694 ,l_conf_msg_prop
4695 ,l_conf_message
4696 ,l_msgid);
4697
4698 IF (C_LEVEL_EVENT >= g_log_level) THEN
4699 trace
4700 (p_msg => 'Dequeue one completion message'
4701 ,p_level => C_LEVEL_EVENT
4702 ,p_module => l_log_module);
4703 END IF;
4704
4705 l_msg_count := l_msg_count - 1;
4706
4707 EXCEPTION
4708 WHEN OTHERS THEN
4709 IF (C_LEVEL_EVENT >= g_log_level) THEN
4710 trace
4711 (p_msg => 'No completion message to dequeue'
4712 ,p_level => C_LEVEL_EVENT
4713 ,p_module => l_log_module);
4714 END IF;
4715
4716 IF (NOT is_any_child_running) THEN
4717 IF (C_LEVEL_EVENT >= g_log_level) THEN
4718 trace
4719 (p_msg => 'No children process running : EXIT dequeue completion message'
4720 ,p_level => C_LEVEL_EVENT
4721 ,p_module => l_log_module);
4722 END IF;
4723
4724 EXIT;
4725 END IF;
4726
4727 END;
4728 END LOOP;
4729
4730 IF (C_LEVEL_EVENT >= g_log_level) THEN
4731 trace
4732 (p_msg => 'END LOOP : dequeue completion messges'
4733 ,p_level => C_LEVEL_EVENT
4734 ,p_module => l_log_module);
4735 END IF;
4736
4737 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4738 trace
4739 (p_msg => 'END of procedure dequeue_completion_messages'
4740 ,p_level => C_LEVEL_PROCEDURE
4741 ,p_module => l_log_module);
4742 END IF;
4743 EXCEPTION
4744 WHEN normal_termination THEN
4745 RAISE;
4746 WHEN xla_exceptions_pkg.application_exception THEN
4747 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4748 trace
4749 (p_msg => 'xla_exceptions_pkg.application_exception: dequeue_completion_messages'
4750 ,p_level => C_LEVEL_EXCEPTION
4751 ,p_module => l_log_module);
4752 END IF;
4753 RAISE;
4754 WHEN OTHERS THEN
4755 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4756 trace
4757 (p_msg => 'EXCEPTION: dequeue_completion_messages'
4758 ,p_level => C_LEVEL_EXCEPTION
4759 ,p_module => l_log_module);
4760 END IF;
4761 xla_exceptions_pkg.raise_message
4762 (p_location => 'xla_accounting_pkg.dequeue_completion_messages');
4763 END dequeue_completion_messages; -- end of procedure
4764
4765
4766
4767
4768 --=============================================================================
4769 --
4770 --
4771 --
4772 --=============================================================================
4773 PROCEDURE process_events IS
4774 l_children_spawned BOOLEAN;
4775 l_msg_count INTEGER;
4776 l_msg_count2 INTEGER;
4777 l_total_msg_count INTEGER;
4778 l_enq_options dbms_aq.enqueue_options_t;
4779 l_msg_prop dbms_aq.message_properties_t;
4780 l_message xla_queue_msg_type; -- SYSTEM.xla_queue_msg_type;
4781 l_msgid RAW(16);
4782 l_max_processing_order INTEGER;
4783 l_num_level INTEGER;
4784
4785 l_log_module VARCHAR2(240);
4786 BEGIN
4787 IF g_log_enabled THEN
4788 l_log_module := C_DEFAULT_MODULE||'.process_events';
4789 END IF;
4790
4791 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4792 trace
4793 (p_msg => 'BEGIN of procedure process_events'
4794 ,p_level => C_LEVEL_PROCEDURE
4795 ,p_module => l_log_module);
4796 END IF;
4797
4798 INSERT INTO xla_evt_class_orders_gt
4799 (event_class_code
4800 ,processing_order
4801 )
4802 SELECT xec.event_class_code
4803 , NVL(t.max_level, -1)
4804 FROM xla_event_classes_b xec
4805 , (SELECT application_id, event_class_code, max(LEVEL) AS max_level
4806 FROM (SELECT application_id, event_class_code, prior_event_class_code
4807 FROM xla_event_class_predecs
4808 WHERE application_id = g_application_id
4809 UNION
4810 SELECT application_id, prior_event_class_code, NULL
4811 FROM xla_event_class_predecs
4812 WHERE application_id = g_application_id) xep
4813 CONNECT BY application_id = PRIOR application_id
4814 AND prior_event_class_code = PRIOR event_class_code
4815 GROUP BY application_id, event_class_code) t
4816 WHERE xec.event_class_code = t.event_class_code(+)
4817 AND xec.application_id = t.application_id(+)
4818 AND xec.application_id = g_application_id
4819 AND xec.event_class_code <> 'MANUAL';
4820
4821 SELECT max(processing_order)
4822 INTO l_max_processing_order
4823 FROM xla_evt_class_orders_gt;
4824
4825 IF (l_max_processing_order = -1) THEN
4826 l_num_level := 1;
4827 ELSE
4828 l_num_level := l_max_processing_order + 1; -- 5113664 to loop one more to handle -1 process order
4829 END IF;
4830
4831 IF (C_LEVEL_EVENT >= g_log_level) THEN
4832 trace
4833 (p_msg => 'Max processing order = '||l_max_processing_order
4834 ,p_level => C_LEVEL_EVENT
4835 ,p_module => l_log_module);
4836 END IF;
4837
4838 g_parent_data.total_entity_count := 0;
4839
4840 l_total_msg_count := 0;
4841 l_msg_count := 0;
4842 l_children_spawned := FALSE;
4843
4844 l_enq_options.visibility := dbms_aq.IMMEDIATE;
4845 l_enq_options.relative_msgid := NULL;
4846 l_enq_options.sequence_deviation := NULL;
4847
4848 l_msg_prop.priority := l_max_processing_order + 2;
4849 l_msg_prop.DELAY := dbms_aq.NO_DELAY;
4850 l_msg_prop.expiration := dbms_aq.NEVER;
4851 l_msg_prop.correlation := NULL;
4852 l_msg_prop.exception_queue := NULL;
4853 l_msg_prop.sender_id := NULL;
4854
4855 l_message := xla_queue_msg_type(NULL); -- SYSTEM.xla_queue_msg_type(NULL);
4856
4857 IF (C_LEVEL_EVENT >= g_log_level) THEN
4858 trace
4859 (p_msg => 'BEGIN LOOP : enqueue document messges'
4860 ,p_level => C_LEVEL_EVENT
4861 ,p_module => l_log_module);
4862 END IF;
4863
4864 --
4865 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Begin enqueue');
4866 --
4867 -- Porcess document starting from the event with lowest processing event
4868 --
4869 FOR i IN 1..l_num_level LOOP
4870 IF (C_LEVEL_EVENT >= g_log_level) THEN
4871 trace
4872 (p_msg => 'LOOP : enqueue document messges : '||i
4873 ,p_level => C_LEVEL_EVENT
4874 ,p_module => l_log_module);
4875 END IF;
4876
4877 IF (l_max_processing_order > 0) THEN
4878
4879 l_msg_count := 0;
4880
4881 --------------------------------------------------------------------------------------------------------------------
4882 -- 5113664
4883 -- To handle case when only processing order -1 events exist, and there are no events for other processing order.
4884 -- When enqueue_message cannot find events of processing order 'i' in csr_entity, it also cannot process -1 order events.
4885 -- Therefore -1 events will not be processed.
4886 -- Increase l_num_level by 1 more than l_max_processing_order to act as a dummy to loop for any remaining -1 events.
4887 -- This is like a 'catch all'.
4888 --------------------------------------------------------------------------------------------------------------------
4889 IF i <= l_max_processing_order THEN
4890 enqueue_messages(p_processing_order => i
4891 ,p_children_spawned => l_children_spawned
4892 ,p_max_processing_order => l_max_processing_order
4893 ,p_msg_count => l_msg_count);
4894 ELSE
4895 enqueue_messages(p_processing_order => -1
4896 ,p_children_spawned => l_children_spawned
4897 ,p_max_processing_order => l_max_processing_order
4898 ,p_msg_count => l_msg_count);
4899 END IF;
4900
4901 l_total_msg_count := l_total_msg_count + l_msg_count;
4902
4903 --------------------------------------------------------------------------------------------------------
4904 -- 4597150 l_max_processing_order < 0 implies only process order -1 exists, and no other process orders.
4905 -- Only call enqueue_messages with -1 if there are no other process orders.
4906 --------------------------------------------------------------------------------------------------------
4907 ELSE
4908 l_msg_count := 0;
4909 enqueue_messages(p_processing_order => -1
4910 ,p_children_spawned => l_children_spawned
4911 ,p_max_processing_order => l_max_processing_order
4912 ,p_msg_count => l_msg_count);
4913 l_total_msg_count := l_total_msg_count + l_msg_count;
4914 END IF;
4915
4916 --
4917 -- After queueing the highest priority events, queue the events that can
4918 -- be processed anytime
4919 --
4920 /* 4597150
4921 IF (i = 1) THEN
4922 l_msg_count2 := 0;
4923 enqueue_messages(p_processing_order => -1
4924 ,p_children_spawned => l_children_spawned
4925 ,p_max_processing_order => l_max_processing_order
4926 ,p_msg_count => l_msg_count2);
4927 l_total_msg_count := l_total_msg_count + l_msg_count2;
4928 END IF;
4929 */
4930
4931 IF (l_children_spawned) THEN
4932 --
4933 -- If after processing the last processing order message and
4934 -- child processes are created, enqueue NULL messages to the
4935 -- document queue to signal the child processes that there is
4936 -- no more documents to be processed
4937 --
4938 -- 5113664 increase l_max_processing_order by 1 since l_num_level is increased also
4939 -- IF (i = l_max_processing_order OR l_max_processing_order = -1) THEN
4940 IF (i = (l_max_processing_order+1) OR l_max_processing_order = -1) THEN
4941
4942 IF (C_LEVEL_EVENT >= g_log_level) THEN
4943 trace
4944 (p_msg => 'BEGIN LOOP : enqueue dummy messges'
4945 ,p_level => C_LEVEL_EVENT
4946 ,p_module => l_log_module);
4947 END IF;
4948
4949 FOR j IN 1..g_process_count LOOP
4950 IF (C_LEVEL_EVENT >= g_log_level) THEN
4951 trace
4952 (p_msg => 'LOOP : enqueue dummy messges : '||j
4953 ,p_level => C_LEVEL_EVENT
4954 ,p_module => l_log_module);
4955 END IF;
4956
4957 dbms_aq.enqueue
4958 (g_queue_name
4959 ,l_enq_options
4960 ,l_msg_prop
4961 ,l_message
4962 ,l_msgid);
4963 END LOOP;
4964
4965 IF (C_LEVEL_EVENT >= g_log_level) THEN
4966 trace
4967 (p_msg => 'END LOOP: enqueue dummy messges'
4968 ,p_level => C_LEVEL_EVENT
4969 ,p_module => l_log_module);
4970 END IF;
4971
4972 END IF;
4973
4974 IF (l_msg_count > 0) THEN
4975 dequeue_completion_messages(p_msg_count => l_msg_count);
4976 END IF;
4977
4978 IF (NOT is_any_child_running) THEN
4979
4980 IF (C_LEVEL_EVENT >= g_log_level) THEN
4981 trace
4982 (p_msg => 'No children process running : EXIT processing events'
4983 ,p_level => C_LEVEL_EVENT
4984 ,p_module => l_log_module);
4985 END IF;
4986
4987 EXIT;
4988 END IF;
4989
4990 END IF; -- if l_children_spawned
4991
4992 END LOOP;
4993
4994 IF (C_LEVEL_EVENT >= g_log_level) THEN
4995 trace
4996 (p_msg => 'END LOOP : enqueue document messges'
4997 ,p_level => C_LEVEL_EVENT
4998 ,p_module => l_log_module);
4999 END IF;
5000
5001 IF (NOT l_children_spawned) THEN
5002 xla_accounting_err_pkg.build_message
5003 (p_appli_s_name => 'XLA'
5004 ,p_msg_name => 'XLA_AP_NO_EVENT_TO_PROCESS'
5005 ,p_entity_id => NULL
5006 ,p_event_id => NULL);
5007
5008 print_logfile('Technical warning : There are no events to process.');
5009
5010 RAISE normal_termination;
5011
5012 ELSE
5013 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Enqueueing completed');
5014
5015 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5016 trace
5017 (p_msg => 'Number of processing units = '||l_total_msg_count
5018 ,p_level => C_LEVEL_STATEMENT
5019 ,p_module => l_log_module);
5020 trace
5021 (p_msg => 'Number of entities = '|| g_parent_data.total_entity_count
5022 ,p_level => C_LEVEL_STATEMENT
5023 ,p_module => l_log_module);
5024 END IF;
5025 END IF;
5026
5027 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5028 trace
5029 (p_msg => 'END of procedure process_events'
5030 ,p_level => C_LEVEL_PROCEDURE
5031 ,p_module => l_log_module);
5032 END IF;
5033 EXCEPTION
5034 WHEN normal_termination THEN
5035 RAISE;
5036 WHEN xla_exceptions_pkg.application_exception THEN
5037 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5038 trace
5039 (p_msg => 'xla_exceptions_pkg.application_exception: process_events'
5040 ,p_level => C_LEVEL_EXCEPTION
5041 ,p_module => l_log_module);
5042 END IF;
5043 RAISE;
5044 WHEN OTHERS THEN
5045 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5046 trace
5047 (p_msg => 'EXCEPTION: process_events'
5048 ,p_level => C_LEVEL_EXCEPTION
5049 ,p_module => l_log_module);
5050 END IF;
5051 xla_exceptions_pkg.raise_message
5052 (p_location => 'xla_accounting_pkg.process_events');
5053 END process_events; -- end of procedure
5054
5055
5056
5057 --=============================================================================
5058 --
5059 --
5060 --
5061 --=============================================================================
5062 PROCEDURE spawn_child_processes IS
5063 PRAGMA AUTONOMOUS_TRANSACTION;
5064 l_ep_request_ids xla_accounting_pkg.t_array_number;
5065 l_log_module VARCHAR2(240);
5066 BEGIN
5067 IF g_log_enabled THEN
5068 l_log_module := C_DEFAULT_MODULE||'.spawn_child_processes';
5069 END IF;
5070 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5071 trace
5072 (p_msg => 'BEGIN of procedure SPAWN_CHILD_PROCESSES'
5073 ,p_level => C_LEVEL_PROCEDURE
5074 ,p_module => l_log_module);
5075 END IF;
5076
5077 FOR i IN 1..(g_process_count) LOOP
5078 l_ep_request_ids(i) :=
5079 fnd_request.submit_request
5080 (application => 'XLA'
5081 ,program => 'XLAACCUP'
5082 ,description => NULL
5083 ,start_time => NULL
5084 ,sub_request => FALSE
5085 ,argument1 => g_application_id
5086 ,argument2 => g_ledger_id
5087 ,argument3 => to_char(g_end_date,'YYYY/MM/DD')
5088 ,argument4 => g_accounting_mode
5089 ,argument5 => g_error_only_flag
5090 ,argument6 => g_accounting_batch_id
5091 ,argument7 => g_parent_request_id
5092 ,argument8 => g_report_request_id
5093 ,argument9 => g_queue_name
5094 ,argument10 => g_comp_queue_name
5095 ,argument11 => g_error_limit
5096 ,argument12 => g_seq_enabled_flag
5097 ,argument13 => g_transfer_flag
5098 ,argument14 => g_gl_posting_flag
5099 ,argument15 => g_gl_batch_name); -- Bug 5257343
5100
5101 IF l_ep_request_ids(i) = 0 THEN
5102 IF (C_LEVEL_EXCEPTION>= g_log_level) THEN
5103 trace
5104 (p_msg => 'Technical Error : Unable to submit child requests.'
5105 ,p_level => C_LEVEL_EXCEPTION
5106 ,p_module => l_log_module);
5107 END IF;
5108
5109 xla_accounting_err_pkg.build_message
5110 (p_appli_s_name => 'XLA'
5111 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
5112 ,p_token_1 => 'APPLICATION_NAME'
5113 ,p_value_1 => 'SLA'
5114 ,p_entity_id => NULL
5115 ,p_event_id => NULL);
5116
5117 print_logfile('Technical Error : Unable to submit child requests');
5118
5119 xla_exceptions_pkg.raise_message
5120 (p_appli_s_name => 'XLA'
5121 ,p_msg_name => 'XLA_COMMON_ERROR'
5122 ,p_token_1 => 'LOCATION'
5123 ,p_value_1 => 'xla_accounting_pkg.spawn_child_processes'
5124 ,p_token_2 => 'ERROR'
5125 ,p_value_2 => 'Technical Error : Unable to submit child requests.');
5126
5127 END IF;
5128 END LOOP;
5129
5130 g_ep_request_ids := l_ep_request_ids;
5131
5132
5133 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5134 FOR i IN 1 .. l_ep_request_ids.count LOOP
5135 trace
5136 (p_msg => 'Submitted unit processor request = '||l_ep_request_ids(i)
5137 ,p_level => C_LEVEL_STATEMENT
5138 ,p_module => l_log_module);
5139 END LOOP;
5140 END IF;
5141
5142 COMMIT;
5143
5144 IF (C_LEVEL_EVENT >= g_log_level) THEN
5145 trace
5146 (p_msg => 'COMMIT issued in AUTONOMOUS_TRANSACTION procedure SPAWN_CHILD_PROCESSES'
5147 ,p_level => C_LEVEL_EVENT
5148 ,p_module => l_log_module);
5149 END IF;
5150
5151 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5152 trace
5153 (p_msg => 'END of procedure SPAWN_CHILD_PROCESSES'
5154 ,p_level => C_LEVEL_PROCEDURE
5155 ,p_module => l_log_module);
5156 END IF;
5157 EXCEPTION
5158 WHEN xla_exceptions_pkg.application_exception THEN
5159 RAISE;
5160 WHEN OTHERS THEN
5161 xla_exceptions_pkg.raise_message
5162 (p_location => 'xla_accounting_pkg.spawn_child_processes');
5163 END spawn_child_processes; -- end of procedure
5164
5165
5166 --=============================================================================
5167 --
5168 --
5169 --
5170 --=============================================================================
5171 PROCEDURE wait_for_requests
5172 (p_array_request_id IN t_array_number
5173 ,p_error_status OUT NOCOPY VARCHAR2
5174 ,p_warning_status OUT NOCOPY VARCHAR2) IS
5175 l_phase VARCHAR2(30);
5176 l_status VARCHAR2(30);
5177 l_dphase VARCHAR2(30);
5178 l_dstatus VARCHAR2(30);
5179 l_message VARCHAR2(240);
5180 l_btemp BOOLEAN;
5181 l_log_module VARCHAR2(240);
5182 BEGIN
5183 IF g_log_enabled THEN
5184 l_log_module := C_DEFAULT_MODULE||'.wait_for_requests';
5185 END IF;
5186 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5187 trace
5188 (p_msg => 'BEGIN of procedure WAIT_FOR_REQUESTS'
5189 ,p_level => C_LEVEL_PROCEDURE
5190 ,p_module => l_log_module);
5191 END IF;
5192
5193 ----------------------------------------------------------------------------
5194 -- Waiting for active/pending requests to complete
5195 ----------------------------------------------------------------------------
5196 IF p_array_request_id.count > 0 THEN
5197 FOR i IN 1..p_array_request_id.count LOOP
5198
5199 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5200 trace
5201 (p_msg => 'waiting for request id = '||p_array_request_id(i)
5202 ,p_level => C_LEVEL_STATEMENT
5203 ,p_module => l_log_module);
5204 END IF;
5205
5206 l_btemp := fnd_concurrent.wait_for_request
5207 (request_id => p_array_request_id(i)
5208 ,interval => 30
5209 ,phase => l_phase
5210 ,status => l_status
5211 ,dev_phase => l_dphase
5212 ,dev_status => l_dstatus
5213 ,message => l_message);
5214 IF NOT l_btemp THEN
5215 xla_accounting_err_pkg.build_message
5216 (p_appli_s_name => 'XLA'
5217 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
5218 ,p_token_1 => 'APPLICATION_NAME'
5219 ,p_value_1 => 'SLA'
5220 ,p_entity_id => NULL
5221 ,p_event_id => NULL);
5222
5223 print_logfile('Technical problem : FND_CONCURRENT.WAIT_FOR_REQUEST returned FALSE '||
5224 'while executing for request id '||p_array_request_id(i));
5225 ELSE
5226 IF (C_LEVEL_EVENT >= g_log_level) THEN
5227 trace
5228 (p_msg => 'request completed with status = '||l_status
5229 ,p_level => C_LEVEL_EVENT
5230 ,p_module => l_log_module);
5231 END IF;
5232
5233 IF l_dstatus = 'WARNING' THEN
5234 p_warning_status := 'Y';
5235 ELSIF l_dstatus = 'ERROR' THEN
5236 p_error_status := 'Y';
5237 END IF;
5238 END IF;
5239 END LOOP;
5240 END IF;
5241
5242 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5243 trace
5244 (p_msg => 'END of procedure WAIT_FOR_REQUESTS'
5245 ,p_level => C_LEVEL_PROCEDURE
5246 ,p_module => l_log_module);
5247 END IF;
5248 EXCEPTION
5249 WHEN xla_exceptions_pkg.application_exception THEN
5250 RAISE;
5251 WHEN OTHERS THEN
5252 xla_exceptions_pkg.raise_message
5253 (p_location => 'xla_accounting_pkg.wait_for_requests');
5254 END wait_for_requests; -- end of procedure
5255
5256
5257
5258 --=============================================================================
5259 -- 5054831 - To validate that the AAD is valid in the database.
5260 --
5261 --
5262 --=============================================================================
5263 FUNCTION AAD_dbase_invalid(p_pad_name IN VARCHAR2,p_ledger_category_code IN VARCHAR2,p_enable_bc_flag IN VARCHAR2 ) return BOOLEAN
5264 IS
5265
5266 CURSOR c_aad_status(c_pad_name VARCHAR2) IS
5267 SELECT status
5268 FROM all_objects
5269 WHERE object_name = c_pad_name
5270 and owner = user
5271 ORDER BY STATUS asc;
5272
5273 /*
5274 select decode(o.status, 0, 'N/A', 1, 'VALID', 'INVALID')
5275 from sys.obj$ o, sys.user$ u
5276 where o.owner# = u.user#
5277 and o.linkname is null
5278 and (o.type# not in (1 ,
5279 10 )
5280 or
5281 (o.type# = 1 and 1 = (select 1
5282 from sys.ind$ i
5283 where i.obj# = o.obj#
5284 and i.type# in (1, 2, 3, 4, 6, 7, 9))))
5285 and o.name <> '_NEXT_OBJECT'
5286 and o.name <> '_default_auditing_options_'
5287 and o.name = p_pad_name
5288 and u.name ='APPS'
5289 order by 1 asc;
5290 */
5291
5292 l_log_module VARCHAR2(240);
5293 l_status VARCHAR2(10);
5294 l_pad_name VARCHAR2(30); -- 5531502
5295
5296 BEGIN
5297 IF g_log_enabled THEN
5298 l_log_module := C_DEFAULT_MODULE||'.AAD_dbase_invalid';
5299 END IF;
5300
5301 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5302 trace
5303 (p_msg => 'BEGIN of procedure AAD_dbase_invalid'
5304 ,p_level => C_LEVEL_PROCEDURE
5305 ,p_module => l_log_module);
5306 trace
5307 (p_msg => 'AAD p_pad_name= '||p_pad_name
5308 ,p_level => C_LEVEL_PROCEDURE
5309 ,p_module => l_log_module);
5310 END IF;
5311
5312 -- 5531502 Need to check for BC package
5313 IF NVL(g_budgetary_control_mode,'NONE') = 'NONE' THEN
5314 l_pad_name := p_pad_name;
5315 ELSE
5316 -- 6509160 Process non bc AAd package for Secondary non bc enabled ledger
5317 IF p_ledger_category_code='SECONDARY' AND p_enable_bc_flag='N' THEN
5318 l_pad_name := p_pad_name;
5319 ELSE
5320 l_pad_name := REPLACE(p_pad_name,'_PKG','_BC_PKG');
5321 END IF;
5322 END IF;
5323 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5324 trace
5325 (p_msg => 'g_budgetary_control_mode = '||g_budgetary_control_mode
5326 ,p_level => C_LEVEL_STATEMENT
5327 ,p_module => l_log_module);
5328 trace
5329 (p_msg => 'l_pad_name = '||l_pad_name
5330 ,p_level => C_LEVEL_STATEMENT
5331 ,p_module => l_log_module);
5332 END IF;
5333
5334 OPEN c_aad_status (l_pad_name);
5335 FETCH c_aad_status INTO l_status;
5336 IF c_aad_status%NOTFOUND or l_status = 'INVALID' THEN
5337 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5338 trace
5339 (p_msg => l_pad_name||' is invalid.'
5340 ,p_level => C_LEVEL_STATEMENT
5341 ,p_module => l_log_module);
5342 END IF;
5343 CLOSE c_aad_status;
5344 return TRUE;
5345 END IF;
5346 CLOSE c_aad_status;
5347
5348 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5349 trace
5350 (p_msg => 'END of procedure AAD_dbase_invalid'
5351 ,p_level => C_LEVEL_PROCEDURE
5352 ,p_module => l_log_module);
5353 trace
5354 (p_msg => l_pad_name||' is valid.'
5355 ,p_level => C_LEVEL_PROCEDURE
5356 ,p_module => l_log_module);
5357 END IF;
5358
5359 return FALSE;
5360
5361 EXCEPTION
5362 WHEN normal_termination THEN
5363 if c_aad_status%ISOPEN THEN
5364 close c_aad_status;
5365 end if;
5366 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5367 trace
5368 (p_msg => 'normal_termination: AAD_dbase_invalid'
5369 ,p_level => C_LEVEL_EXCEPTION
5370 ,p_module => l_log_module);
5371 END IF;
5372 RAISE;
5373 WHEN xla_exceptions_pkg.application_exception THEN
5374 if c_aad_status%ISOPEN THEN
5375 close c_aad_status;
5376 end if;
5377 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5378 trace
5379 (p_msg => 'xla_exceptions_pkg.application_exception: AAD_dbase_invalid'
5380 ,p_level => C_LEVEL_EXCEPTION
5381 ,p_module => l_log_module);
5382 END IF;
5383 RAISE;
5384 WHEN OTHERS THEN
5385 if c_aad_status%ISOPEN THEN
5386 close c_aad_status;
5387 end if;
5388 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5389 trace
5390 (p_msg => 'EXCEPTION: AAD_dbase_invalid'
5391 ,p_level => C_LEVEL_EXCEPTION
5392 ,p_module => l_log_module);
5393 END IF;
5394 xla_exceptions_pkg.raise_message
5395 (p_location => 'xla_accounting_pkg.AAD_dbase_invalid');
5396
5397 END AAD_dbase_invalid;
5398
5399 --=============================================================================
5400 -- 5054831 TO validate that the AAD is valid and there are events in the
5401 -- date range of the AAD
5402 --
5403 --=============================================================================
5404 PROCEDURE ValidateAAD (p_array_event_dates IN t_array_date)
5405 IS
5406
5407 l_log_module VARCHAR2(240);
5408 l_array_ledgers xla_accounting_cache_pkg.t_array_ledger_id;
5409 l_array_ledger_pad xla_accounting_cache_pkg.t_array_pad;
5410 l_max_event_date date;
5411 l_min_event_date date;
5412 l_count NUMBER :=0;
5413 l_encoded_msg VARCHAR2(2000) := null;
5414 l_ledger_category_code VARCHAR2(50);
5415 l_enable_bc_flag VARCHAR2(1):=null;
5416
5417 BEGIN
5418 IF g_log_enabled THEN
5419 l_log_module := C_DEFAULT_MODULE||'.ValidateAAD';
5420 END IF;
5421
5422 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5423 trace
5424 (p_msg => 'BEGIN of procedure ValidateAAD'
5425 ,p_level => C_LEVEL_PROCEDURE
5426 ,p_module => l_log_module);
5427 END IF;
5428
5429 l_array_ledgers := xla_accounting_cache_pkg.GetLedgers;
5430
5431 if p_array_event_dates.COUNT > 0 then
5432 l_min_event_date := p_array_event_dates(1);
5433 l_max_event_date := p_array_event_dates(p_array_event_dates.COUNT);
5434 end if;
5435
5436 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5437 trace
5438 (p_msg => 'count='||p_array_event_dates.COUNT
5439 ,p_level => C_LEVEL_STATEMENT
5440 ,p_module => l_log_module);
5441 trace
5442 (p_msg => 'min event_date='||l_min_event_date
5443 ,p_level => C_LEVEL_STATEMENT
5444 ,p_module => l_log_module);
5445 trace
5446 (p_msg => 'max event_date='||l_max_event_date
5447 ,p_level => C_LEVEL_STATEMENT
5448 ,p_module => l_log_module);
5449 FOR i in 1 .. p_array_event_dates.COUNT LOOP
5450 trace
5451 (p_msg => 'event_date='||p_array_event_dates(i)
5452 ,p_level => C_LEVEL_STATEMENT
5453 ,p_module => l_log_module);
5454 END LOOP;
5455
5456 END IF;
5457
5458 FOR i in 1..l_array_ledgers.COUNT LOOP
5459
5460 -- get category code of ledger
5461 SELECT ledger_category_code,enable_budgetary_control_flag
5462 INTO l_ledger_category_code,l_enable_bc_flag
5463 FROM gl_ledgers
5464 WHERE ledger_id = l_array_ledgers(i);
5465 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5466 trace
5467 (p_msg => 'ledger category code ='||l_ledger_category_code||'bc flag='||l_enable_bc_flag
5468 ,p_level => C_LEVEL_STATEMENT
5469 ,p_module => l_log_module);
5470
5471 END IF;
5472
5473 -- get the AAD for this ledger
5474 l_array_ledger_pad := xla_accounting_cache_pkg.GetArrayPad
5475 (p_ledger_id => l_array_ledgers(i)
5476 ,p_max_event_date => l_max_event_date
5477 ,p_min_event_date => l_min_event_date);
5478
5479 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5480 trace
5481 (p_msg => 'ledger='||l_array_ledgers(i)
5482 ,p_level => C_LEVEL_STATEMENT
5483 ,p_module => l_log_module);
5484 FOR j in 1..l_array_ledger_pad.COUNT LOOP
5485 trace
5486 (p_msg => 'pad ='||l_array_ledger_pad(j).pad_package_name||
5487 ' status='||l_array_ledger_pad(j).compile_status_code||
5488 ' start='||l_array_ledger_pad(j).start_date_active||
5489 ' end='||l_array_ledger_pad(j).end_date_active
5490 ,p_level => C_LEVEL_STATEMENT
5491 ,p_module => l_log_module);
5492 END LOOP;
5493 END IF;
5494
5495 -- Verify if any AAD is invalid and there are event dates within the AAD date range.
5496 FOR k in 1..l_array_ledger_pad.COUNT LOOP
5497 IF l_array_ledger_pad(k).compile_status_code = 'N' or
5498 (l_array_ledger_pad(k).compile_status_code = 'Y' and AAD_dbase_invalid(l_array_ledger_pad(k).pad_package_name,l_ledger_category_code,l_enable_bc_flag)) THEN
5499
5500 FOR l in 1..p_array_event_dates.COUNT LOOP
5501 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5502 trace
5503 (p_msg => 'event date = '||p_array_event_dates(l)||
5504 ' pad='||l_array_ledger_pad(k).pad_package_name||
5505 ' start='||l_array_ledger_pad(k).start_date_active||
5506 ' end='||l_array_ledger_pad(k).end_date_active
5507 ,p_level => C_LEVEL_STATEMENT
5508 ,p_module => l_log_module);
5509 END IF;
5510
5511 IF p_array_event_dates(l) >= l_array_ledger_pad(k).start_date_active AND
5512 p_array_event_dates(l) <= NVL(l_array_ledger_pad(k).end_date_active,p_array_event_dates(l)) THEN
5513
5514 l_count := l_count + 1;
5515 /*--------------------------------------------------------------------------------------------------
5516 -- problem; error is not deleted on rerun during online accounting. for batch, error is not created.
5517 xla_accounting_err_pkg.build_message
5518 (p_appli_s_name => 'XLA'
5519 ,p_msg_name => 'XLA_AP_PAD_INACTIVE'
5520 ,p_token_1 => 'PAD_NAME'
5521 ,p_value_1 => l_array_ledger_pad(k).ledger_product_rule_name
5522 ,p_token_2 => 'OWNER'
5523 ,p_value_2 => xla_lookups_pkg.get_meaning(
5524 'XLA_OWNER_TYPE'
5525 ,l_array_ledger_pad(k).product_rule_owner)
5526 ,p_token_3 => 'SUBLEDGER_ACCTG_METHOD'
5527 ,p_value_3 => xla_accounting_cache_pkg.GetSessionValueChar
5528 (p_source_code => 'XLA_ACCOUNTING_METHOD_NAME'
5529 ,p_target_ledger_id => l_array_ledgers(i))
5530 ,p_entity_id => null
5531 ,p_event_id => null
5532 ,p_ledger_id => l_array_ledgers(i)
5533 ,p_accounting_batch_id => g_accounting_batch_id);
5534 --------------------------------------------------------------------------------------------------*/
5535 xla_messages_pkg.build_message
5536 (p_appli_s_name => 'XLA'
5537 ,p_msg_name => 'XLA_AP_PAD_INACTIVE'
5538 ,p_token_1 => 'PAD_NAME'
5539 ,p_value_1 => l_array_ledger_pad(k).ledger_product_rule_name
5540 ,p_token_2 => 'OWNER'
5541 ,p_value_2 => xla_lookups_pkg.get_meaning(
5542 'XLA_OWNER_TYPE'
5543 ,l_array_ledger_pad(k).product_rule_owner)
5544 ,p_token_3 => 'SUBLEDGER_ACCTG_METHOD'
5545 ,p_value_3 => xla_accounting_cache_pkg.GetSessionValueChar
5546 (p_source_code => 'XLA_ACCOUNTING_METHOD_NAME'
5547 ,p_target_ledger_id => l_array_ledgers(i)));
5548
5549 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5550 trace
5551 (p_msg => 'Invalid AAD = '||l_array_ledger_pad(k).pad_package_name
5552 ,p_level => C_LEVEL_STATEMENT
5553 ,p_module => l_log_module);
5554 END IF;
5555 exit;
5556
5557 END IF;
5558
5559 END LOOP; -- p_array_event_dates
5560
5561 END IF; -- l_array_ledger_pad(k).compile_status_code = 'N'
5562
5563 END LOOP; -- l_array_ledger_pad
5564
5565 END LOOP; -- l_array_ledgers
5566
5567 IF l_count> 0 THEN
5568 l_encoded_msg := fnd_message.get();
5569 raise xla_exceptions_pkg.application_exception;
5570 END IF;
5571
5572 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5573 trace
5574 (p_msg => 'END of procedure ValidateAAD'
5575 ,p_level => C_LEVEL_PROCEDURE
5576 ,p_module => l_log_module);
5577 END IF;
5578
5579 EXCEPTION
5580 WHEN xla_exceptions_pkg.application_exception THEN
5581 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5582 trace
5583 (p_msg => 'xla_exceptions_pkg.application_exception: ValidateAAD'
5584 ,p_level => C_LEVEL_EXCEPTION
5585 ,p_module => l_log_module);
5586 END IF;
5587 IF l_count>0 THEN
5588 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - '||l_encoded_msg);
5589 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN -- log
5590 trace
5591 (p_msg => l_encoded_msg
5592 ,p_level => C_LEVEL_EXCEPTION
5593 ,p_module => l_log_module);
5594 END IF;
5595 END IF;
5596 RAISE;
5597 WHEN OTHERS THEN
5598 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5599 trace
5600 (p_msg => 'EXCEPTION: ValidateAAD'
5601 ,p_level => C_LEVEL_EXCEPTION
5602 ,p_module => l_log_module);
5603 END IF;
5604 xla_exceptions_pkg.raise_message
5605 (p_location => 'xla_accounting_pkg.ValidateAAD');
5606 END ValidateAAD;
5607
5608
5609 --=============================================================================
5610 --
5611 -- The following ValidateAAD is called from unit_processor in batch accounting.
5612 -- It checks validity of AAD in the AMB and in database. If any AAD is invalid
5613 -- in AMB or in database, the procedure terminates 'Accoutning Program'.
5614 --
5615 --=============================================================================
5616
5617 PROCEDURE ValidateAAD
5618 (p_max_event_date IN DATE)
5619 IS
5620
5621 C_MIN_EVENT_DATE CONSTANT DATE := TO_DATE('01/01/1900','DD/MM/YYYY');
5622
5623 l_log_module VARCHAR2(240);
5624 l_array_ledgers xla_accounting_cache_pkg.t_array_ledger_id;
5625 l_array_ledger_pad xla_accounting_cache_pkg.t_array_pad;
5626 l_count NUMBER :=0;
5627 l_message VARCHAR2(2000);
5628
5629 l_pad_name VARCHAR2(240);
5630 l_pad_owner VARCHAR2(240);
5631 l_slam VARCHAR2(240);
5632 l_ledger_category_code VARCHAR2(50);
5633 l_enable_bc_flag VARCHAR2(1):=null;
5634
5635
5636 BEGIN
5637 IF g_log_enabled THEN
5638 l_log_module := C_DEFAULT_MODULE||'.ValidateAAD';
5639 END IF;
5640
5641 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5642 trace
5643 (p_msg => 'BEGIN of procedure ValidateAAD'
5644 ,p_level => C_LEVEL_PROCEDURE
5645 ,p_module => l_log_module);
5646 trace
5647 (p_msg => 'p_max_event_date = '||p_max_event_date
5648 ,p_level => C_LEVEL_PROCEDURE
5649 ,p_module => l_log_module);
5650 END IF;
5651
5652 l_array_ledgers := xla_accounting_cache_pkg.GetLedgers;
5653
5654 FOR i in 1..l_array_ledgers.COUNT LOOP
5655
5656 -- get category code of ledger
5657 SELECT ledger_category_code,enable_budgetary_control_flag
5658 INTO l_ledger_category_code,l_enable_bc_flag
5659 FROM gl_ledgers
5660 WHERE ledger_id = l_array_ledgers(i);
5661
5662 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5663 trace
5664 (p_msg => 'ledger category code ='||l_ledger_category_code||' bc flag='||l_enable_bc_flag
5665 ,p_level => C_LEVEL_STATEMENT
5666 ,p_module => l_log_module);
5667
5668 END IF;
5669
5670 -- get the AAD for this ledger
5671 l_array_ledger_pad :=
5672 xla_accounting_cache_pkg.GetArrayPad
5673 (p_ledger_id => l_array_ledgers(i)
5674 ,p_max_event_date => p_max_event_date
5675 ,p_min_event_date => C_MIN_EVENT_DATE);
5676
5677
5678 -- Verify if any AAD is invalid and there are event dates within the AAD date range.
5679 FOR k in 1..l_array_ledger_pad.COUNT LOOP
5680 IF (l_array_ledger_pad(k).compile_status_code = 'N' OR
5681 (l_array_ledger_pad(k).compile_status_code = 'Y' AND
5682 AAD_dbase_invalid(l_array_ledger_pad(k).pad_package_name,l_ledger_category_code,l_enable_bc_flag)
5683 )
5684 )
5685 THEN
5686 l_pad_name := l_array_ledger_pad(k).ledger_product_rule_name;
5687 l_pad_owner := xla_lookups_pkg.get_meaning
5688 ('XLA_OWNER_TYPE'
5689 ,l_array_ledger_pad(k).product_rule_owner);
5690 l_slam := xla_accounting_cache_pkg.GetSessionValueChar
5691 (p_source_code => 'XLA_ACCOUNTING_METHOD_NAME'
5692 ,p_target_ledger_id => l_array_ledgers(i));
5693
5694 l_count := l_count + 1;
5695
5696 xla_messages_pkg.build_message
5697 (p_appli_s_name => 'XLA'
5698 ,p_msg_name => 'XLA_AP_PAD_INACTIVE'
5699 ,p_token_1 => 'PAD_NAME'
5700 ,p_value_1 => l_pad_name
5701 ,p_token_2 => 'OWNER'
5702 ,p_value_2 => l_pad_owner
5703 ,p_token_3 => 'SUBLEDGER_ACCTG_METHOD'
5704 ,p_value_3 => l_slam);
5705
5706 l_message := fnd_message.get();
5707
5708 print_logfile(l_message);
5709
5710 END IF; -- l_array_ledger_pad(k).compile_status_code = 'N'
5711 END LOOP; -- l_array_ledger_pad
5712 END LOOP; -- l_array_ledgers
5713
5714 IF l_count > 0 THEN
5715 xla_exceptions_pkg.raise_message
5716 (p_location => 'xla_accounting_pkg.ValidateAAD');
5717 END IF;
5718
5719 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5720 trace
5721 (p_msg => 'END of procedure ValidateAAD'
5722 ,p_level => C_LEVEL_PROCEDURE
5723 ,p_module => l_log_module);
5724 END IF;
5725
5726 EXCEPTION
5727 WHEN xla_exceptions_pkg.application_exception THEN
5728 RAISE;
5729 WHEN OTHERS THEN
5730 xla_exceptions_pkg.raise_message
5731 (p_location => 'xla_accounting_pkg.ValidateAAD');
5732 END ValidateAAD;
5733
5734 --=============================================================================
5735 --
5736 --
5737 --
5738 --=============================================================================
5739
5740 PROCEDURE unit_processor IS
5741 TYPE t_lock_events_cur IS REF CURSOR;
5742 lock_events_cur t_lock_events_cur;
5743
5744 l_deq_options dbms_aq.dequeue_options_t;
5745 l_enq_options dbms_aq.enqueue_options_t;
5746 l_msg_prop dbms_aq.message_properties_t;
5747 l_msgid RAW(16);
5748 --l_message xla_queue_msg_type; --SYSTEM.xla_queue_msg_type;
5749 l_entity_count NUMBER := 0;
5750 l_event_count NUMBER := 0;
5751 l_dequeue_flag BOOLEAN;
5752
5753 l_ret_val_acctg_engine NUMBER;
5754 l_sqlerrm VARCHAR2(2000);
5755 l_log_module VARCHAR2(240);
5756 l_transfer_mode VARCHAR2(30);
5757
5758 l_array_events xla_accounting_pkg.t_array_number;
5759
5760 -------------------------------------------------------
5761 -- 4597150
5762 -------------------------------------------------------
5763 l_all_event_classes VARCHAR2(10000);
5764 l_class_current_order VARCHAR2(5000);
5765 l_class_anytime_order VARCHAR2(5000);
5766 l_str1_insert_events VARCHAR2(32000);
5767 l_str2_insert_events VARCHAR2(32000);
5768 l_evt_num_subqry VARCHAR2(32000);
5769 -------------------------------------------------------
5770 l_lock_events_str VARCHAR2(10000);
5771 -------------------------------------------------------
5772 -- Bug 5056632
5773 -------------------------------------------------------
5774 l_array_base_ledgers xla_accounting_cache_pkg.t_array_ledger_id;
5775 l_array_alc_ledgers xla_accounting_cache_pkg.t_array_ledger_id;
5776 l_primary_ledger_group_id NUMBER;
5777 l_temp NUMBER;
5778
5779 l_event_insert_count number;
5780
5781 BEGIN
5782 IF g_log_enabled THEN
5783 l_log_module := C_DEFAULT_MODULE||'.unit_processor';
5784 END IF;
5785 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5786 trace
5787 (p_msg => 'BEGIN of procedure UNIT_PROCESSOR'
5788 ,p_level => C_LEVEL_PROCEDURE
5789 ,p_module => l_log_module);
5790 END IF;
5791
5792 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Ready to cache the Application and Ledger Level Sources ...');
5793
5794 xla_accounting_cache_pkg.load_application_ledgers
5795 (p_application_id => g_application_id
5796 ,p_event_ledger_id => g_ledger_id
5797 ,p_max_event_date => g_end_date);
5798
5799 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Cached the Application and Ledger Level Sources');
5800
5801 -- validate AADs
5802 ValidateAAD(g_end_date);
5803
5804 --
5805 -- Bug 5056632
5806 -- The following fetches group_id and stores them in an array for Transfer
5807 -- to GL. There is a distinct groupid for each base ledger. ALCs share
5808 -- their group_id with Primary ledger..
5809 --
5810 IF g_accounting_mode = 'F' AND g_transfer_flag = 'Y' THEN
5811 l_array_base_ledgers := xla_accounting_cache_pkg.GetLedgers;
5812 l_array_alc_ledgers := xla_accounting_cache_pkg.GetAlcLedgers(g_ledger_id);
5813 --For bug fix 7677948
5814 FOR i IN l_array_base_ledgers.FIRST..l_array_base_ledgers.LAST LOOP
5815 SELECT gl_interface_control_s.NEXTVAL, l_array_base_ledgers(i)
5816 INTO g_array_group_id(i), g_array_ledger_id(i)
5817 FROM DUAL;
5818
5819 IF l_array_alc_ledgers.COUNT > 0 AND
5820 l_array_base_ledgers(i) = g_ledger_id
5821 THEN
5822 l_primary_ledger_group_id := g_array_group_id(i);
5823 END IF;
5824 END LOOP;
5825
5826 IF l_array_alc_ledgers.COUNT > 0 THEN
5827 l_temp := g_array_group_id.COUNT;
5828 FOR i IN (l_array_alc_ledgers.FIRST)..(l_array_alc_ledgers.LAST) LOOP
5829 g_array_group_id(i+l_temp) := l_primary_ledger_group_id;
5830 g_array_ledger_id(i+l_temp) := l_array_alc_ledgers(i);
5831 END LOOP;
5832 END IF;
5833 END IF;
5834
5835 ----------------------------------------------------------------------------
5836 -- Following initiates queue/message related variables
5837 ----------------------------------------------------------------------------
5838 l_deq_options.consumer_name := NULL;
5839 l_deq_options.dequeue_mode := dbms_aq.REMOVE;
5840 l_deq_options.navigation := dbms_aq.FIRST_MESSAGE;
5841 l_deq_options.visibility := dbms_aq.IMMEDIATE;
5842 l_deq_options.wait := 60;
5843 l_deq_options.msgid := NULL;
5844 l_deq_options.correlation := NULL;
5845
5846 l_enq_options.visibility := dbms_aq.IMMEDIATE;
5847 l_enq_options.relative_msgid := NULL;
5848 l_enq_options.sequence_deviation := NULL;
5849
5850 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Entering the loop to read document units from the queue ...');
5851
5852 LOOP -- (reading messages from the queue)
5853 -------------------------------------------------------------------------
5854 -- Initializing variables for a loop
5855 -------------------------------------------------------------------------
5856 l_event_count := 0;
5857
5858 -------------------------------------------------------------------------
5859 -- Following checks to make sure the error count for the accounting
5860 -- program has not reached the error limit.
5861 -------------------------------------------------------------------------
5862 IF ((xla_accounting_err_pkg.g_error_limit IS NOT NULL) AND
5863 (xla_accounting_err_pkg.get_total_error_count >=
5864 xla_accounting_err_pkg.g_error_limit
5865 )
5866 )
5867 THEN
5868 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - This child process is exiting the loop due to the error limit defined in the setups');
5869
5870 IF (C_LEVEL_EVENT >= g_log_level) THEN
5871 trace
5872 (p_msg => 'Message : This child process is exiting the loop due to the error limit defined in the setups'
5873 ,p_level => C_LEVEL_EVENT
5874 ,p_module => l_log_module);
5875 END IF;
5876 EXIT;
5877 END IF;
5878
5879 -------------------------------------------------------------------------
5880 -- Following checks whether the parent accounting program is active
5881 -- or not.
5882 -------------------------------------------------------------------------
5883 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Checking status of the parent Accounting Program');
5884 IF NOT is_parent_running THEN
5885
5886 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5887 trace
5888 (p_msg => 'Technical Error : The parent request for this request is not running'
5889 ,p_level => C_LEVEL_EXCEPTION
5890 ,p_module => l_log_module);
5891 END IF;
5892
5893 xla_exceptions_pkg.raise_message
5894 (p_appli_s_name => 'XLA'
5895 ,p_msg_name => 'XLA_COMMON_ERROR'
5896 ,p_token_1 => 'LOCATION'
5897 ,p_value_1 => 'xla_accounting_pkg.unit_processor'
5898 ,p_token_2 => 'ERROR'
5899 ,p_value_2 => 'Technical Error : The parent request for this request is not running.');
5900 END IF;
5901
5902 -------------------------------------------------------------------------
5903 -- read message from the queue.
5904 -------------------------------------------------------------------------
5905
5906 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Dequeuing the unit from the queue');
5907
5908 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5909 trace
5910 (p_msg => 'Ready to dequeue message from message queue'
5911 ,p_level => C_LEVEL_STATEMENT
5912 ,p_module => l_log_module);
5913 END IF;
5914
5915 l_dequeue_flag := TRUE;
5916 WHILE (l_dequeue_flag) LOOP
5917 BEGIN
5918 dbms_aq.dequeue
5919 (g_queue_name
5920 ,l_deq_options
5921 ,l_msg_prop
5922 ,g_message
5923 ,l_msgid);
5924 l_dequeue_flag := FALSE;
5925 EXCEPTION
5926 WHEN OTHERS THEN
5927
5928 IF g_conc_hold = 'Y' AND SQLCODE = -25228 /* Timeout; queue is likely empty... */
5929 THEN
5930 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')
5931 ||' - Dequeue of ' ||
5932 g_queue_name ||' Timed out');
5933 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')
5934 ||' - Please run Transfer to GL explicitly.');
5935 trace(p_msg => 'Queue is empty.'
5936 ,p_level => C_LEVEL_EXCEPTION
5937 ,p_module => l_log_module);
5938
5939 RAISE;
5940 END IF;
5941
5942 IF NOT is_parent_running THEN
5943
5944 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5945 trace
5946 (p_msg => 'Technical Error : The parent request for this request is not running'
5947 ,p_level => C_LEVEL_EXCEPTION
5948 ,p_module => l_log_module);
5949 END IF;
5950
5951 xla_exceptions_pkg.raise_message
5952 (p_appli_s_name => 'XLA'
5953 ,p_msg_name => 'XLA_COMMON_ERROR'
5954 ,p_token_1 => 'LOCATION'
5955 ,p_value_1 => 'xla_accounting_pkg.unit_processor'
5956 ,p_token_2 => 'ERROR'
5957 ,p_value_2 => 'Technical Error : The parent request for this request is not running.');
5958 END IF;
5959 END;
5960 END LOOP;
5961
5962 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5963 trace
5964 (p_msg => 'Message from message queue is dequeued'
5965 ,p_level => C_LEVEL_STATEMENT
5966 ,p_module => l_log_module);
5967 END IF;
5968
5969 g_child_data.dequeued_msg_count := g_child_data.dequeued_msg_count + 1;
5970
5971 -------------------------------------------------------------------------
5972 -- Following code transfer control out of the loop when the message
5973 -- fetched from the queue has no documents in it (ie NULL).
5974 -- It is a very important step because this is the only exit point of
5975 -- the loop.
5976 -------------------------------------------------------------------------
5977 IF g_message.entity_ids IS NULL THEN
5978 IF (C_LEVEL_EVENT >= g_log_level) THEN
5979 trace
5980 (p_msg => 'Exiting the LOOP because this is end of messages in the message queue'
5981 ,p_level => C_LEVEL_EVENT
5982 ,p_module => l_log_module);
5983 END IF;
5984 EXIT;
5985 END IF;
5986
5987 g_child_data.selected_entity_count :=
5988 g_child_data.selected_entity_count + g_message.entity_ids.COUNT;
5989
5990 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Fetching event information for the documents in the unit');
5991
5992 -------------------------------------------------------------------------
5993 -- Following statement inserts event information into the temporary table
5994 -- for product teams to perform extract.
5995 -------------------------------------------------------------------------
5996 ----------------------------------------------------------------------------------------
5997 -- 4597150 Additional debug
5998 ----------------------------------------------------------------------------------------
5999 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6000 FOR i IN 1..g_message.entity_ids.COUNT LOOP
6001
6002 trace
6003 (p_msg => 'Entity_id = '||i||' = '||g_message.entity_ids(i)
6004 ,p_level => C_LEVEL_STATEMENT
6005 ,p_module => l_log_module);
6006
6007 END LOOP;
6008 END IF;
6009 ----------------------------------------------------------------------------------------
6010
6011 -------------------------------------------------------------------------------------------------
6012 -- 4597150 - divide Current Event Class and Anytime Event Class
6013 -- - list of EVENT_CLASSES is the same for each entity in this Child Process
6014 -------------------------------------------------------------------------------------------------
6015 -- if l_msg_prop.user_property = 'EC1','EC2'#-#-#-#-#-#-#-#'EC3','EC4' then
6016 -- l_class_current_order = 'EC1','EC2'
6017 -- l_class_anytime_order = 'EC3','EC4'
6018 -------------------------------------------------------------------------------------------------
6019 IF g_message.entity_ids IS NOT NULL THEN
6020
6021 ---------------------------------------------------------------------------
6022 -- extract combined event_classes from queue
6023 ---------------------------------------------------------------------------
6024 l_all_event_classes := SYS.AnyData.AccessVarchar2(l_msg_prop.user_property);
6025
6026 l_class_current_order :=
6027 SUBSTRB(l_all_event_classes
6028 ,1
6029 ,INSTRB(l_all_event_classes,C_DELIMITER)-1);
6030
6031 l_class_anytime_order :=
6032 SUBSTRB(l_all_event_classes
6033 ,LENGTH(C_DELIMITER)
6034 + INSTRB(l_all_event_classes,C_DELIMITER));
6035
6036 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6037 trace
6038 (p_msg => 'Event_Class : all = '||l_all_event_classes
6039 ,p_level => C_LEVEL_STATEMENT
6040 ,p_module => l_log_module);
6041 trace
6042 (p_msg => 'Event_Class : current = '||l_class_current_order
6043 ,p_level => C_LEVEL_STATEMENT
6044 ,p_module => l_log_module);
6045 trace
6046 (p_msg => 'Event_Class : anytime = '||l_class_anytime_order
6047 ,p_level => C_LEVEL_STATEMENT
6048 ,p_module => l_log_module);
6049 END IF;
6050
6051 END IF;
6052
6053 -------------------------------------------------------------------------
6054 -- Following is added to lock events. Bug 5534133
6055 -------------------------------------------------------------------------
6056 IF l_class_anytime_order is NULL THEN
6057 l_lock_events_str := REPLACE(C_LOCK_EVENTS_STR
6058 ,'$event_classes$'
6059 ,l_class_current_order);
6060 ELSE
6061 l_lock_events_str := REPLACE(C_LOCK_EVENTS_STR
6062 ,'$event_classes$'
6063 ,l_class_current_order||','||l_class_anytime_order);
6064 END IF;
6065
6066 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6067 trace
6068 (p_msg => 'l_lock_events_str = '|| l_lock_events_str
6069 ,p_level => C_LEVEL_STATEMENT
6070 ,p_module => l_log_module);
6071 END IF;
6072
6073 l_str1_insert_events := C_CURR_INS_EVENTS;
6074
6075 l_str1_insert_events := REPLACE(l_str1_insert_events
6076 ,'$event_classes$'
6077 ,l_class_current_order);
6078
6079 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6080 trace
6081 (p_msg => 'First l_str1_insert_events = '|| l_str1_insert_events
6082 ,p_level => C_LEVEL_STATEMENT
6083 ,p_module => l_log_module);
6084 END IF;
6085
6086 IF l_class_anytime_order IS NOT NULL
6087 AND NVL(l_class_current_order,-1) <> NVL(l_class_anytime_order,-1)
6088 THEN
6089 -- if only Processing Order -1 exist, then they are the same
6090
6091 l_str2_insert_events := C_ANYTIME_INS_EVENTS;
6092
6093 l_str2_insert_events := REPLACE(l_str2_insert_events
6094 ,'$event_classes$'
6095 ,l_class_anytime_order);
6096
6097 l_str2_insert_events := REPLACE(l_str2_insert_events
6098 ,'$event_class_current_order$'
6099 ,l_class_current_order);
6100
6101 l_str2_insert_events := REPLACE(l_str2_insert_events
6102 ,'$event_class_anytime_order$'
6103 ,l_class_anytime_order); -- 4860037
6104
6105 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6106 trace
6107 (p_msg => 'Second l_str2_insert_events = '|| l_str2_insert_events
6108 ,p_level => C_LEVEL_STATEMENT
6109 ,p_module => l_log_module);
6110 END IF;
6111 END IF;
6112
6113 OPEN lock_events_cur for l_lock_events_str
6114 USING xla_accounting_pkg.g_message.entity_ids
6115 ,g_application_id
6116 ,g_end_date
6117 ,g_accounting_mode;
6118 LOOP
6119 fetch lock_events_cur bulk collect into l_array_events limit 5000;
6120 EXIT WHEN l_array_events.COUNT = 0;
6121
6122 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6123 trace
6124 (p_msg => 'l_array_events.COUNT = '|| l_array_events.COUNT
6125 ,p_level => C_LEVEL_STATEMENT
6126 ,p_module => l_log_module);
6127 END IF;
6128
6129
6130 FORALL i IN 1..l_array_events.COUNT
6131 EXECUTE IMMEDIATE l_str1_insert_events
6132 USING g_application_id
6133 ,g_end_date
6134 ,l_array_events(i)
6135 ,g_accounting_mode;
6136
6137 l_event_insert_count := SQL%ROWCOUNT;
6138
6139 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6140 trace
6141 (p_msg => 'l_event_insert_count = '||l_event_insert_count
6142 ,p_level => C_LEVEL_STATEMENT
6143 ,p_module => l_log_module);
6144 END IF;
6145
6146 --
6147 -- 4865292
6148 -- Compare event count with header extract count
6149 --
6150 l_event_count := l_event_count + l_event_insert_count;
6151
6152 --- End of First Insert ----------------------------------------------------------------------------
6153
6154 ----------------------------------------------------------------------------------------------------
6155 -- 4597150
6156 -- Second insert into xla_events_gt is for process order -1
6157 -- When all process orders are -1, events are inserted in
6158 -- the previous insert statement. In this case, l_class_anytime_order
6159 -- becomes null.
6160 ----------------------------------------------------------------------------------------------------
6161
6162 IF l_class_anytime_order IS NOT NULL
6163 AND NVL(l_class_current_order,-1) <> NVL(l_class_anytime_order,-1)
6164 THEN
6165
6166 FORALL i IN 1..l_array_events.COUNT
6167 EXECUTE IMMEDIATE l_str2_insert_events
6168 USING g_application_id
6169 ,g_end_date
6170 ,l_array_events(i)
6171 ,g_accounting_mode
6172 ,g_end_date
6173 ,g_accounting_mode;
6174
6175 l_event_insert_count := SQL%ROWCOUNT;
6176
6177 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6178 trace
6179 (p_msg => 'l_event_insert_count = '||l_event_insert_count
6180 ,p_level => C_LEVEL_STATEMENT
6181 ,p_module => l_log_module);
6182 END IF;
6183
6184 --
6185 -- 4865292
6186 -- Compare event count with header extract count
6187 --
6188 l_event_count := l_event_count + l_event_insert_count;
6189
6190 END IF;
6191 END LOOP;
6192 CLOSE lock_events_cur;
6193
6194 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6195 trace
6196 (p_msg => 'Number of events in XLA_EVENTS_GT = '||l_event_count
6197 ,p_level => C_LEVEL_STATEMENT
6198 ,p_module => l_log_module);
6199 END IF;
6200
6201 IF l_event_count = 0 THEN
6202 GOTO enqueue_completion_msg;
6203 END IF;
6204
6205 delete_request_je;
6206
6207 --
6208 -- 4865292
6209 -- Compare event count with header extract count
6210 --
6211 xla_context_pkg.set_event_count_context
6212 (p_event_count => l_event_count
6213 ,p_client_id => g_parent_request_id);
6214 --------------------------------------------------------------------------
6215 -- Handle extract hook
6216 --------------------------------------------------------------------------
6217 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - executing extract hook');
6218 handle_accounting_hook
6219 (p_application_id => g_application_id
6220 ,p_ledger_id => NULL
6221 ,p_process_category => NULL
6222 ,p_end_date => NULL
6223 ,p_accounting_mode => g_accounting_mode
6224 ,p_budgetary_control_mode => g_budgetary_control_mode
6225 ,p_valuation_method => NULL
6226 ,p_security_id_int_1 => NULL
6227 ,p_security_id_int_2 => NULL
6228 ,p_security_id_int_3 => NULL
6229 ,p_security_id_char_1 => NULL
6230 ,p_security_id_char_2 => NULL
6231 ,p_security_id_char_3 => NULL
6232 ,p_report_request_id => NULL
6233 ,p_event_name => 'extract'
6234 ,p_event_key => to_char(g_accounting_batch_id)||'-'
6235 ||to_char(g_parent_request_id)||'-'
6236 ||rawtohex(l_msgid));
6237 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - extract hook executed successfully');
6238
6239
6240 ----------------------------------------------------------------------
6241 -- Call accounting engine
6242 ----------------------------------------------------------------------
6243 IF (C_LEVEL_EVENT >= g_log_level) THEN
6244 trace
6245 (p_msg => 'Calling the function XLA_ACCOUNTING_ENGINE_PKG.ACCOUNTINGENGINE'
6246 ,p_level => C_LEVEL_EVENT
6247 ,p_module => l_log_module);
6248 END IF;
6249
6250 l_ret_val_acctg_engine :=
6251 xla_accounting_engine_pkg.AccountingEngine
6252 (p_application_id => g_application_id
6253 ,p_ledger_id => g_ledger_id
6254 ,p_end_date => g_end_date -- 4262811
6255 ,p_accounting_mode => g_accounting_mode
6256 ,p_accounting_batch_id => g_accounting_batch_id
6257 ,p_budgetary_control_mode => 'NONE');
6258
6259 IF (C_LEVEL_EVENT >= g_log_level) THEN
6260 trace
6261 (p_msg => 'Function XLA_ACCOUNTING_ENGINE_PKG.ACCOUNTINGENGINE executed'
6262 ,p_level => C_LEVEL_EVENT
6263 ,p_module => l_log_module);
6264 END IF;
6265
6266 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6267 trace
6268 (p_msg => 'l_ret_val_acctg_engine = '||l_ret_val_acctg_engine
6269 ,p_level => C_LEVEL_STATEMENT
6270 ,p_module => l_log_module);
6271 trace
6272 (p_msg => 'g_accounting_mode = '||g_accounting_mode
6273 ,p_level => C_LEVEL_STATEMENT
6274 ,p_module => l_log_module);
6275 END IF;
6276
6277 ----------------------------------------------------------------------------
6278 -- Handle postprocessing hook
6279 ----------------------------------------------------------------------------
6280 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - executing postprocessing hook');
6281 handle_accounting_hook
6282 (p_application_id => g_application_id
6283 ,p_ledger_id => NULL
6284 ,p_process_category => NULL
6285 ,p_end_date => NULL
6286 ,p_accounting_mode => g_accounting_mode
6287 ,p_budgetary_control_mode => g_budgetary_control_mode
6288 ,p_valuation_method => NULL
6289 ,p_security_id_int_1 => NULL
6290 ,p_security_id_int_2 => NULL
6291 ,p_security_id_int_3 => NULL
6292 ,p_security_id_char_1 => NULL
6293 ,p_security_id_char_2 => NULL
6294 ,p_security_id_char_3 => NULL
6295 ,p_report_request_id => NULL
6296 ,p_event_name => 'postprocessing'
6297 ,p_event_key => to_char(g_accounting_batch_id)||'-'
6298 ||to_char(g_parent_request_id)||'-'
6299 ||rawtohex(l_msgid));
6300 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - postprocessing hook executed successfully');
6301
6302
6303 -------------------------------------------------------------------------
6304 -- After processing each unit (fetched from the queue), accounting
6305 -- entries are sequenced (in FINAL mode) and commited in base tables and
6306 -- errors are moved from array to error table,
6307 -------------------------------------------------------------------------
6308 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Completing Journal Entries');
6309
6310 complete_entries;
6311 xla_accounting_err_pkg.insert_errors;
6312
6313 -------------------------------------------------------------------------
6314 -- Following checks whether the parent accounting program is active
6315 -- or not before commiting the transaction
6316 -------------------------------------------------------------------------
6317 IF is_parent_running THEN
6318 COMMIT;
6319
6320 IF (C_LEVEL_EVENT >= g_log_level) THEN
6321 trace
6322 (p_msg => 'COMMIT issued in UNIT_PROCESSOR'
6323 ,p_level => C_LEVEL_EVENT
6324 ,p_module => l_log_module);
6325 END IF;
6326
6327 ELSE
6328 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6329 trace
6330 (p_msg => 'Technical Error : The parent request for this request is not running'
6331 ,p_level => C_LEVEL_EXCEPTION
6332 ,p_module => l_log_module);
6333 END IF;
6334
6335 xla_exceptions_pkg.raise_message
6336 (p_appli_s_name => 'XLA'
6337 ,p_msg_name => 'XLA_COMMON_ERROR'
6338 ,p_token_1 => 'LOCATION'
6339 ,p_value_1 => 'xla_accounting_pkg.pre_accounting'
6340 ,p_token_2 => 'ERROR'
6341 ,p_value_2 => 'Technical Error : The parent request for this request is not running.');
6342 END IF;
6343
6344 <<enqueue_completion_msg>>
6345 --
6346 -- After processing one document message, enqueue a completion message
6347 --
6348 IF (C_LEVEL_EVENT >= g_log_level) THEN
6349 trace
6350 (p_msg => 'Enqueue completion message'
6351 ,p_level => C_LEVEL_EVENT
6352 ,p_module => l_log_module);
6353 END IF;
6354
6355 g_message := xla_queue_msg_type(NULL);
6356 dbms_aq.enqueue
6357 (g_comp_queue_name
6358 ,l_enq_options
6359 ,l_msg_prop
6360 ,g_message
6361 ,l_msgid);
6362
6363 IF (C_LEVEL_EVENT >= g_log_level) THEN
6364 trace
6365 (p_msg => 'Done Enqueue completion message'
6366 ,p_level => C_LEVEL_EVENT
6367 ,p_module => l_log_module);
6368 END IF;
6369
6370 END LOOP; -- (reading messages from the queue)
6371
6372 ----------------------------------------------------------------------------
6373 -- call routines to perform 'Transfer to GL'
6374 ----------------------------------------------------------------------------
6375 IF ((g_transfer_flag = 'Y') AND (g_accounting_mode = 'F' )) THEN
6376
6377 IF (C_LEVEL_EVENT >= g_log_level) THEN
6378 trace
6379 (p_msg => 'Transfer to GL process being called'
6380 ,p_level => C_LEVEL_EVENT
6381 ,p_module => l_log_module);
6382 END IF;
6383
6384 xla_accounting_err_pkg.set_options
6385 (p_error_source => xla_accounting_err_pkg.C_TRANSFER_TO_GL);
6386
6387 l_transfer_mode := 'COMBINED';
6388
6389 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6390 trace
6391 (p_msg => 'l_transfer_mode = '||l_transfer_mode
6392 ,p_level => C_LEVEL_STATEMENT
6393 ,p_module => l_log_module);
6394 END IF;
6395
6396 IF (C_LEVEL_EVENT >= g_log_level) THEN
6397 trace
6398 (p_msg => 'Calling transfer routine XLA_TRANSFER_PKG.GL_TRANSFER_MAIN'
6399 ,p_level => C_LEVEL_EVENT
6400 ,p_module => l_log_module);
6401 END IF;
6402
6403 --
6404 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Submitting the transfer to GL');
6405 xla_transfer_pkg.gl_transfer_main
6406 (p_application_id => g_application_id
6407 ,p_transfer_mode => l_transfer_mode
6408 ,p_ledger_id => g_ledger_id
6409 ,p_securiy_id_int_1 => g_security_id_int_1
6410 ,p_securiy_id_int_2 => g_security_id_int_2
6411 ,p_securiy_id_int_3 => g_security_id_int_3
6412 ,p_securiy_id_char_1 => g_security_id_char_1
6413 ,p_securiy_id_char_2 => g_security_id_char_2
6414 ,p_securiy_id_char_3 => g_security_id_char_3
6415 ,p_valuation_method => g_valuation_method
6416 ,p_process_category => g_process_category
6417 ,p_accounting_batch_id => NULL
6418 ,p_entity_id => NULL
6419 ,p_batch_name => g_gl_batch_name
6420 ,p_end_date => g_end_date
6421 ,p_submit_gl_post => g_gl_posting_flag
6422 ,p_caller => xla_transfer_pkg.C_ACCTPROG_BATCH); -- Bug 5056632
6423
6424 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - End of the transfer to GL');
6425
6426 IF (C_LEVEL_EVENT >= g_log_level) THEN
6427 trace
6428 (p_msg => 'Transfer routine XLA_TRANSFER_PKG.GL_TRANSFER_MAIN executed'
6429 ,p_level => C_LEVEL_EVENT
6430 ,p_module => l_log_module);
6431 END IF;
6432
6433 xla_accounting_err_pkg.set_options
6434 (p_error_source => xla_accounting_err_pkg.C_ACCT_PROGRAM);
6435
6436 END IF;
6437
6438 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6439 trace
6440 (p_msg => 'END of procedure UNIT_PROCESSOR'
6441 ,p_level => C_LEVEL_PROCEDURE
6442 ,p_module => l_log_module);
6443 END IF;
6444 EXCEPTION
6445 WHEN xla_exceptions_pkg.application_exception THEN
6446 g_message := xla_queue_msg_type(NULL);
6447 dbms_aq.enqueue
6448 (g_comp_queue_name
6449 ,l_enq_options
6450 ,l_msg_prop
6451 ,g_message
6452 ,l_msgid);
6453 RAISE;
6454 WHEN OTHERS THEN
6455 IF SQLCODE = -25228 AND g_conc_hold = 'Y' /* Timeout; queue is likely empty... */
6456 THEN
6457 RAISE;
6458 END IF;
6459 g_message := xla_queue_msg_type(NULL);
6460 dbms_aq.enqueue
6461 (g_comp_queue_name
6462 ,l_enq_options
6463 ,l_msg_prop
6464 ,g_message
6465 ,l_msgid);
6466 xla_exceptions_pkg.raise_message
6467 (p_location => 'xla_accounting_pkg.unit_processor');
6468 END unit_processor; -- end of function
6469
6470
6471
6472 --=============================================================================
6473 --
6474 --
6475 --
6476 --=============================================================================
6477 FUNCTION is_parent_running
6478 RETURN BOOLEAN IS
6479 l_phase VARCHAR2(30);
6480 l_status VARCHAR2(30);
6481 l_dphase VARCHAR2(30);
6482 l_dstatus VARCHAR2(30);
6483 l_message VARCHAR2(240);
6484 l_btemp BOOLEAN;
6485 l_result BOOLEAN;
6486 l_log_module VARCHAR2(240);
6487 BEGIN
6488 IF g_log_enabled THEN
6489 l_log_module := C_DEFAULT_MODULE||'.is_parent_running';
6490 END IF;
6491 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6492 trace
6493 (p_msg => 'BEGIN of function IS_PARENT_RUNNING'
6494 ,p_level => C_LEVEL_PROCEDURE
6495 ,p_module => l_log_module);
6496 END IF;
6497
6498 ----------------------------------------------------------------------------
6499 -- Waiting for active/pending requests to complete
6500 ----------------------------------------------------------------------------
6501 l_btemp := fnd_concurrent.get_request_status
6502 (request_id => g_parent_request_id
6503 ,phase => l_phase
6504 ,status => l_status
6505 ,dev_phase => l_dphase
6506 ,dev_status => l_dstatus
6507 ,message => l_message);
6508
6509 IF NOT l_btemp THEN
6510 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6511 trace
6512 (p_msg => 'Technical problem : FND_CONCURRENT.GET_REQUEST_STATUS returned FALSE '||
6513 'while executing for request id '||g_parent_request_id
6514 ,p_level => C_LEVEL_EXCEPTION
6515 ,p_module => l_log_module);
6516 END IF;
6517
6518 xla_exceptions_pkg.raise_message
6519 (p_appli_s_name => 'XLA'
6520 ,p_msg_name => 'XLA_COMMON_ERROR'
6521 ,p_token_1 => 'LOCATION'
6522 ,p_value_1 => 'xla_accounting_pkg.is_parent_running'
6523 ,p_token_2 => 'ERROR'
6524 ,p_value_2 => 'Technical problem : FND_CONCURRENT.GET_REQUEST_STATUS returned FALSE '||
6525 'while executing for request id '||g_parent_request_id);
6526 END IF;
6527
6528 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6529 trace
6530 (p_msg => 'l_dphase = '||l_dphase
6531 ,p_level => C_LEVEL_STATEMENT
6532 ,p_module => l_log_module);
6533 END IF;
6534
6535 IF l_dphase = 'RUNNING' THEN
6536 l_result := TRUE;
6537 ELSE
6538 l_result := FALSE;
6539 END IF;
6540
6541 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6542 trace
6543 (p_msg => 'END of function IS_PARENT_RUNNING'
6544 ,p_level => C_LEVEL_PROCEDURE
6545 ,p_module => l_log_module);
6546 END IF;
6547
6548 RETURN l_result;
6549 EXCEPTION
6550 WHEN xla_exceptions_pkg.application_exception THEN
6551 RAISE;
6552 WHEN OTHERS THEN
6553 xla_exceptions_pkg.raise_message
6554 (p_location => 'xla_accounting_pkg.is_parent_running');
6555 END is_parent_running; -- end of procedure
6556
6557 --=============================================================================
6558 --
6559 --
6560 --
6561 --=============================================================================
6562 FUNCTION is_any_child_running
6563 RETURN BOOLEAN IS
6564 l_phase VARCHAR2(30);
6565 l_status VARCHAR2(30);
6566 l_dphase VARCHAR2(30);
6567 l_dstatus VARCHAR2(30);
6568 l_message VARCHAR2(240);
6569 l_btemp BOOLEAN;
6570 l_result BOOLEAN;
6571 l_log_module VARCHAR2(240);
6572 BEGIN
6573 IF g_log_enabled THEN
6574 l_log_module := C_DEFAULT_MODULE||'.is_any_child_running';
6575 END IF;
6576 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6577 trace
6578 (p_msg => 'BEGIN of function is_any_child_running'
6579 ,p_level => C_LEVEL_PROCEDURE
6580 ,p_module => l_log_module);
6581 END IF;
6582
6583 l_result := FALSE;
6584 IF g_ep_request_ids.count > 0 THEN
6585
6586 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6587 trace
6588 (p_msg => 'BEGIN LOOP: get child process status'
6589 ,p_level => C_LEVEL_PROCEDURE
6590 ,p_module => l_log_module);
6591 END IF;
6592
6593 FOR i IN 1..g_ep_request_ids.count LOOP
6594 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6595 trace
6596 (p_msg => 'LOO: get child process status : '||g_ep_request_ids(i)
6597 ,p_level => C_LEVEL_PROCEDURE
6598 ,p_module => l_log_module);
6599 END IF;
6600
6601 ----------------------------------------------------------------------------
6602 -- Check the child process status
6603 ----------------------------------------------------------------------------
6604 l_btemp := fnd_concurrent.get_request_status
6605 (request_id => g_ep_request_ids(i)
6606 ,phase => l_phase
6607 ,status => l_status
6608 ,dev_phase => l_dphase
6609 ,dev_status => l_dstatus
6610 ,message => l_message);
6611
6612 IF NOT l_btemp THEN
6613 IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6614 trace
6615 (p_msg => 'Technical problem : FND_CONCURRENT.GET_REQUEST_STATUS '||
6616 'returned FALSE '||
6617 'while executing for request id '||g_ep_request_ids(i)
6618 ,p_level => C_LEVEL_EXCEPTION
6619 ,p_module => l_log_module);
6620 END IF;
6621
6622 xla_exceptions_pkg.raise_message
6623 (p_appli_s_name => 'XLA'
6624 ,p_msg_name => 'XLA_COMMON_ERROR'
6625 ,p_token_1 => 'LOCATION'
6626 ,p_value_1 => 'xla_accounting_pkg.is_any_child_running'
6627 ,p_token_2 => 'ERROR'
6628 ,p_value_2 => 'Technical problem : FND_CONCURRENT.GET_REQUEST_STATUS returned FALSE '||
6629 'while executing for request id '||g_ep_request_ids(i));
6630 END IF;
6631
6632 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6633 trace
6634 (p_msg => 'l_dphase = '||l_dphase
6635 ,p_level => C_LEVEL_STATEMENT
6636 ,p_module => l_log_module);
6637 END IF;
6638
6639 IF l_dphase IN ('PENDING', 'RUNNING') THEN
6640
6641 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6642 trace
6643 (p_msg => 'Child '||g_ep_request_ids(i)||' is running'
6644 ,p_level => C_LEVEL_PROCEDURE
6645 ,p_module => l_log_module);
6646 END IF;
6647
6648 l_result := TRUE;
6649 EXIT;
6650 END IF;
6651 END LOOP;
6652
6653 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6654 trace
6655 (p_msg => 'END LOOP: get child process status'
6656 ,p_level => C_LEVEL_PROCEDURE
6657 ,p_module => l_log_module);
6658 END IF;
6659
6660 END IF;
6661
6662 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6663 trace
6664 (p_msg => 'END of function is_any_child_running'
6665 ,p_level => C_LEVEL_PROCEDURE
6666 ,p_module => l_log_module);
6667 END IF;
6668
6669 RETURN l_result;
6670 EXCEPTION
6671 WHEN xla_exceptions_pkg.application_exception THEN
6672 RAISE;
6673 WHEN OTHERS THEN
6674 xla_exceptions_pkg.raise_message
6675 (p_location => 'xla_accounting_pkg.is_any_child_running');
6676 END is_any_child_running; -- end of procedure
6677
6678
6679
6680 --=============================================================================
6681 --
6682 --
6683 --
6684 --=============================================================================
6685 PROCEDURE sequencing_batch_init
6686 (p_seq_enabled_flag IN OUT NOCOPY VARCHAR2) IS
6687 l_xla_application_id NUMBER := 602;
6688 l_xla_seq_entity VARCHAR2(30) := 'XLA_AE_HEADERS';
6689 l_seq_event_code VARCHAR2(30) := 'COMPLETION';
6690 l_seq_context_value fun_seq_batch.context_value_tbl_type;
6691
6692 l_seq_status VARCHAR2(30);
6693 l_seq_context_id NUMBER;
6694 l_sqlerrm VARCHAR2(2000);
6695 l_log_module VARCHAR2(240);
6696 BEGIN
6697 IF g_log_enabled THEN
6698 l_log_module := C_DEFAULT_MODULE||'.sequencing_batch_init';
6699 END IF;
6700 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6701 trace
6702 (p_msg => 'BEGIN of procedure SEQUENCING_BATCH_INIT'
6703 ,p_level => C_LEVEL_PROCEDURE
6704 ,p_module => l_log_module);
6705 trace
6706 (p_msg => 'p_seq_enabled_flag = '||p_seq_enabled_flag
6707 ,p_level => C_LEVEL_PROCEDURE
6708 ,p_module => l_log_module);
6709 END IF;
6710
6711 ----------------------------------------------------------------------------
6712 -- Getting ledger ids that will be used/cached in this run of accounting
6713 -- program (Actually this should come from cache but as cache is not
6714 -- activated in parent, the SQL is repeated here. This may change in
6715 -- future).
6716 ----------------------------------------------------------------------------
6717 SELECT xlr.ledger_id BULK COLLECT
6718 INTO l_seq_context_value
6719 FROM xla_ledger_relationships_v xlr
6720 ,xla_subledger_options_v xso
6721 WHERE xlr.relationship_enabled_flag = 'Y'
6722 AND xlr.ledger_category_code IN ('ALC','PRIMARY','SECONDARY')
6723 AND DECODE(xso.valuation_method_flag
6724 ,'N',xlr.primary_ledger_id
6725 ,DECODE(xlr.ledger_category_code
6726 ,'ALC',xlr.primary_ledger_id
6727 ,xlr.ledger_id)
6728 ) = g_ledger_id
6729 AND xso.application_id = g_application_id
6730 AND xso.ledger_id = DECODE(xlr.ledger_category_code
6731 ,'ALC',xlr.primary_ledger_id
6732 ,xlr.ledger_id)
6733 AND xso.enabled_flag = 'Y';
6734
6735 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6736 trace
6737 (p_msg => 'Number of ledgers being passed to the sequencing api = '||
6738 l_seq_context_value.COUNT
6739 ,p_level => C_LEVEL_STATEMENT
6740 ,p_module => l_log_module);
6741 END IF;
6742
6743 ----------------------------------------------------------------------------
6744 -- Calling sequencing's batch init
6745 ----------------------------------------------------------------------------
6746 BEGIN
6747 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Calling sequencing batch_init');
6748 IF (C_LEVEL_EVENT >= g_log_level) THEN
6749 trace
6750 (p_msg => 'Calling procedure FUN_SEQ_BATCH.BATCH_INIT'
6751 ,p_level => C_LEVEL_EVENT
6752 ,p_module => l_log_module);
6753 END IF;
6754
6755 fun_seq_batch.batch_init
6756 (p_application_id => l_xla_application_id
6757 ,p_table_name => l_xla_seq_entity
6758 ,p_event_code => l_seq_event_code
6759 ,p_context_type => 'LEDGER_AND_CURRENCY'
6760 ,p_context_value_tbl => l_seq_context_value
6761 ,p_request_id => g_parent_request_id
6762 ,x_status => l_seq_status
6763 ,x_seq_context_id => l_seq_context_id);
6764
6765 IF (C_LEVEL_EVENT >= g_log_level) THEN
6766 trace
6767 (p_msg => 'Procedure FUN_SEQ_BATCH.BATCH_INIT executed'
6768 ,p_level => C_LEVEL_EVENT
6769 ,p_module => l_log_module);
6770 END IF;
6771 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Returned from sequencing batch_init');
6772
6773 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6774 trace
6775 (p_msg => 'l_seq_status = '||l_seq_status
6776 ,p_level => C_LEVEL_STATEMENT
6777 ,p_module => l_log_module);
6778 trace
6779 (p_msg => 'l_seq_context_id = '||l_seq_context_id
6780 ,p_level => C_LEVEL_STATEMENT
6781 ,p_module => l_log_module);
6782 END IF;
6783
6784 IF l_seq_status = 'NO_SEQUENCING' THEN
6785 p_seq_enabled_flag := 'N';
6786 ELSE
6787 p_seq_enabled_flag := 'Y';
6788 END IF;
6789
6790 EXCEPTION
6791 WHEN OTHERS THEN
6792 l_sqlerrm := sqlerrm;
6793
6794 IF (C_LEVEL_EXCEPTION>= g_log_level) THEN
6795 trace
6796 (p_msg => 'Technical problem : Problem encountered in sequencing BATCH_INIT.'||
6797 xla_environment_pkg.g_chr_newline||
6798 l_sqlerrm
6799 ,p_level => C_LEVEL_EXCEPTION
6800 ,p_module => l_log_module);
6801 END IF;
6802
6803 xla_accounting_err_pkg.build_message
6804 (p_appli_s_name => 'XLA'
6805 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
6806 ,p_token_1 => 'APPLICATION_NAME'
6807 ,p_value_1 => 'SLA'
6808 ,p_entity_id => NULL
6809 ,p_event_id => NULL);
6810
6811 print_logfile('Technical problem : Problem encountered in sequencing BATCH_INIT.');
6812
6813 xla_exceptions_pkg.raise_message
6814 (p_appli_s_name => 'XLA'
6815 ,p_msg_name => 'XLA_COMMON_ERROR'
6816 ,p_token_1 => 'LOCATION'
6817 ,p_value_1 => 'xla_accounting_pkg.sequencing_batch_init'
6818 ,p_token_2 => 'ERROR'
6819 ,p_value_2 => 'Technical problem : Problem encountered in sequencing BATCH_INIT.'||
6820 xla_environment_pkg.g_chr_newline||
6821 l_sqlerrm);
6822 END;
6823
6824 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6825 trace
6826 (p_msg => 'p_seq_enabled_flag = '||p_seq_enabled_flag
6827 ,p_level => C_LEVEL_PROCEDURE
6828 ,p_module => l_log_module);
6829 trace
6830 (p_msg => 'END of procedure SEQUENCING_BATCH_INIT'
6831 ,p_level => C_LEVEL_PROCEDURE
6832 ,p_module => l_log_module);
6833 END IF;
6834 EXCEPTION
6835 WHEN xla_exceptions_pkg.application_exception THEN
6836 RAISE;
6837 WHEN OTHERS THEN
6838 xla_exceptions_pkg.raise_message
6839 (p_location => 'xla_accounting_pkg.sequencing_batch_init');
6840 END sequencing_batch_init; -- end of procedure
6841
6842
6843 --=============================================================================
6844 --
6845 --
6846 --
6847 --
6848 --
6849 --
6850 --
6851 --
6852 --
6853 --
6854 -- Following routines are used while accounting for batch of events
6855 --
6856 -- 1. events_processor
6857 -- 2. delete_batch_je
6858 --
6859 --
6860 --
6861 --
6862 --
6863 --
6864 --
6865 --
6866 --
6867 --
6868 --=============================================================================
6869
6870 --=============================================================================
6871 --
6872 --
6873 --
6874 --=============================================================================
6875 PROCEDURE events_processor(l_processing_order IN NUMBER) -- bug 7193986
6876 IS
6877 l_ret_val_acctg_engine NUMBER;
6878 l_seq_status VARCHAR2(30);
6879 l_max_event_date DATE;
6880 l_log_module VARCHAR2(240);
6881
6882 -- 5054831 -----------------------------------
6883 l_array_event_dates t_array_date;
6884 CURSOR c_events IS
6885 SELECT distinct event_date
6886 FROM xla_events a
6887 ,xla_acct_prog_events_gt b
6888 WHERE a.application_id = g_application_id
6889 AND a.event_id = b.event_id
6890 AND a.process_status_code = 'U'
6891 AND a.event_status_code IN ('U',DECODE(g_accounting_mode,'F','N','U'))
6892 AND a.on_hold_flag = 'N'
6893 AND a.event_type_code not in ('FULL_MERGE', 'PARTIAL_MERGE')
6894 AND b.ledger_id = g_ledger_id
6895 ORDER BY event_date asc;
6896 ----------------------------------------------
6897
6898 BEGIN
6899 IF g_log_enabled THEN
6900 l_log_module := C_DEFAULT_MODULE||'.events_processor';
6901 END IF;
6902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6903 trace
6904 (p_msg => 'BEGIN of procedure events_processor'
6905 ,p_level => C_LEVEL_PROCEDURE
6906 ,p_module => l_log_module);
6907 END IF;
6908
6909 xla_accounting_cache_pkg.load_application_ledgers
6910 (p_application_id => g_application_id
6911 ,p_event_ledger_id => g_ledger_id);
6912
6913 -- 5054831 -----------------------------
6914 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6915 FOR i in (select a.* from xla_acct_prog_events_gt b, xla_events a WHERE a.application_id = g_application_id
6916 AND a.event_id = b.event_id
6917 AND a.process_status_code = 'U'
6918 AND a.event_status_code IN ('U',DECODE(g_accounting_mode,'F','N','U'))
6919 AND a.on_hold_flag = 'N'
6920 AND a.event_type_code not in ('FULL_MERGE', 'PARTIAL_MERGE')
6921 AND b.ledger_id = g_ledger_id) LOOP
6922 trace
6923 (p_msg => 'event_id='||i.event_id||' event_date='||i.event_date||' status='||i.process_status_code
6924 ,p_level => C_LEVEL_STATEMENT
6925 ,p_module => l_log_module);
6926 END LOOP;
6927 END IF;
6928
6929 OPEN c_events;
6930 FETCH c_events BULK COLLECT INTO l_array_event_dates;
6931 CLOSE c_events;
6932
6933 ValidateAAD(l_array_event_dates);
6934 ----------------------------------------
6935 -- bug 7193986 start
6936 --
6937 -- Delete the events inserted from the previous run
6938 --
6939 DELETE FROM XLA_EVENTS_GT;
6940 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6941 trace
6942 (p_msg => '# rows deleted XLA_EVENTS_GT = '||SQL%ROWCOUNT
6943 ,p_level => C_LEVEL_PROCEDURE
6944 ,p_module => l_log_module);
6945 END IF;
6946 DELETE FROM XLA_AE_LINES_GT;
6947 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6948 trace
6949 (p_msg => '# rows deleted XLA_AE_LINES_GT = '||SQL%ROWCOUNT
6950 ,p_level => C_LEVEL_PROCEDURE
6951 ,p_module => l_log_module);
6952 END IF;
6953 DELETE FROM XLA_AE_HEADERS_GT;
6954 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6955 trace
6956 (p_msg => '# rows deleted XLA_AE_HEADERS_GT = '||SQL%ROWCOUNT
6957 ,p_level => C_LEVEL_PROCEDURE
6958 ,p_module => l_log_module);
6959 END IF;
6960 DELETE FROM XLA_VALIDATION_LINES_GT;
6961 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6962 trace
6963 (p_msg => '# rows deleted XLA_VALIDATION_LINES_GT = '||SQL%ROWCOUNT
6964 ,p_level => C_LEVEL_PROCEDURE
6965 ,p_module => l_log_module);
6966 END IF;
6967
6968
6969 --
6970 -- Insert into xla_events_gt for the entity in xla_acct_prog_events_gt
6971 -- for the p_application_id and p_ledger_id.
6972 --
6973 INSERT INTO xla_events_gt
6974 (entity_id
6975 ,application_id
6976 ,ledger_id
6977 ,legal_entity_id
6978 ,entity_code
6979 ,transaction_number
6980 ,source_id_int_1
6981 ,source_id_int_2
6982 ,source_id_int_3
6983 ,source_id_int_4
6984 ,source_id_char_1
6985 ,source_id_char_2
6986 ,source_id_char_3
6987 ,source_id_char_4
6988 ,event_id
6989 ,event_class_code
6990 ,event_type_code
6991 ,event_number
6992 ,event_date
6993 ,transaction_date
6994 ,event_status_code
6995 ,process_status_code
6996 ,valuation_method
6997 ,budgetary_control_flag
6998 ,reference_num_1
6999 ,reference_num_2
7000 ,reference_num_3
7001 ,reference_num_4
7002 ,reference_char_1
7003 ,reference_char_2
7004 ,reference_char_3
7005 ,reference_char_4
7006 ,reference_date_1
7007 ,reference_date_2
7008 ,reference_date_3
7009 ,reference_date_4)
7010 SELECT xev.entity_id
7011 ,xev.application_id
7012 ,xev.ledger_id
7013 ,xev.legal_entity_id
7014 ,xev.entity_code
7015 ,xev.transaction_number
7016 ,xev.source_id_int_1
7017 ,xev.source_id_int_2
7018 ,xev.source_id_int_3
7019 ,xev.source_id_int_4
7020 ,xev.source_id_char_1
7021 ,xev.source_id_char_2
7022 ,xev.source_id_char_3
7023 ,xev.source_id_char_4
7024 ,xev.event_id
7025 ,xev.event_class_code
7026 ,xev.event_type_code
7027 ,xev.event_number
7028 ,xev.event_date
7029 ,xev.transaction_date
7030 ,xev.event_status_code
7031 ,xev.process_status_code
7032 ,xev.valuation_method
7033 ,NVL(xev.budgetary_control_flag,'N')
7034 ,xev.reference_num_1
7035 ,xev.reference_num_2
7036 ,xev.reference_num_3
7037 ,xev.reference_num_4
7038 ,xev.reference_char_1
7039 ,xev.reference_char_2
7040 ,xev.reference_char_3
7041 ,xev.reference_char_4
7042 ,xev.reference_date_1
7043 ,xev.reference_date_2
7044 ,xev.reference_date_3
7045 ,xev.reference_date_4
7046 FROM xla_entity_events_v xev
7047 , xla_acct_prog_events_gt xap
7048 WHERE xev.application_id = g_application_id
7049 AND xev.event_id = xap.event_id
7050 AND xev.process_status_code = 'U'
7051 AND xev.event_status_code IN ('U',DECODE(g_accounting_mode,'F','N','U'))
7052 AND xev.on_hold_flag = 'N'
7053 AND xev.event_type_code not in ('FULL_MERGE', 'PARTIAL_MERGE')
7054 AND xap.ledger_id = g_ledger_id
7055 AND xap.event_id IN (
7056 SELECT xla_events.event_id
7057 FROM xla_acct_prog_events_gt ,
7058 xla_events ,
7059 xla_event_types_b ,
7060 xla_transaction_entities,
7061 xla_evt_class_orders_gt
7062 WHERE xla_events.event_id = xla_acct_prog_events_gt.event_id
7063 AND xla_events.application_id = g_application_id
7064 AND xla_transaction_entities.application_id = g_application_id
7065 AND xla_events.entity_id = xla_transaction_entities.entity_id
7066 AND xla_event_types_b.application_id = g_application_id
7067 AND xla_transaction_entities.entity_code = xla_event_types_b.entity_code
7068 AND xla_events.event_type_code = xla_event_types_b.event_type_code
7069 AND xla_event_types_b.event_class_code = xla_evt_class_orders_gt.event_class_code
7070 AND xla_evt_class_orders_gt.processing_order = l_processing_order
7071 )
7072 ORDER BY xev.entity_id, xev.event_number;
7073
7074
7075 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7076 trace
7077 (p_msg => '# rows inserted into xla_events_gt = '||SQL%ROWCOUNT
7078 ,p_level => C_LEVEL_PROCEDURE
7079 ,p_module => l_log_module);
7080 END IF;
7081
7082
7083 -- bug 7193986 end
7084
7085
7086 SELECT max(event_date)
7087 INTO l_max_event_date
7088 FROM xla_events_gt;
7089 --
7090 -- Call subledger extract API
7091 --
7092 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - executing extract hook');
7093 handle_accounting_hook
7094 (p_application_id => g_application_id
7095 ,p_ledger_id => NULL
7096 ,p_process_category => NULL
7097 ,p_end_date => NULL
7098 ,p_accounting_mode => g_accounting_mode
7099 ,p_budgetary_control_mode => g_budgetary_control_mode
7100 ,p_valuation_method => NULL
7101 ,p_security_id_int_1 => NULL
7102 ,p_security_id_int_2 => NULL
7103 ,p_security_id_int_3 => NULL
7104 ,p_security_id_char_1 => NULL
7105 ,p_security_id_char_2 => NULL
7106 ,p_security_id_char_3 => NULL
7107 ,p_report_request_id => NULL
7108 ,p_event_name => 'extract'
7109 ,p_event_key => to_char(g_accounting_batch_id));
7110 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - extract hook executed successfully');
7111
7112 xla_accounting_err_pkg.set_options
7113 (p_error_source => xla_accounting_err_pkg.C_ACCT_ENGINE);
7114
7115 l_ret_val_acctg_engine :=
7116 xla_accounting_engine_pkg.AccountingEngine
7117 (p_application_id => g_application_id
7118 ,p_ledger_id => g_ledger_id
7119 ,p_end_date => l_max_event_date
7120 ,p_accounting_mode => g_accounting_mode
7121 ,p_accounting_batch_id => g_accounting_batch_id
7122 ,p_budgetary_control_mode => g_budgetary_control_mode
7123 );
7124
7125 xla_accounting_err_pkg.set_options
7126 (p_error_source => xla_accounting_err_pkg.C_ACCT_PROGRAM);
7127
7128 --
7129 -- Call subledger post-processing API
7130 --
7131 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - executing postprocessing hook');
7132 handle_accounting_hook
7133 (p_application_id => g_application_id
7134 ,p_ledger_id => NULL
7135 ,p_process_category => NULL
7136 ,p_end_date => NULL
7137 ,p_accounting_mode => g_accounting_mode
7138 ,p_budgetary_control_mode => g_budgetary_control_mode
7139 ,p_valuation_method => NULL
7140 ,p_security_id_int_1 => NULL
7141 ,p_security_id_int_2 => NULL
7142 ,p_security_id_int_3 => NULL
7143 ,p_security_id_char_1 => NULL
7144 ,p_security_id_char_2 => NULL
7145 ,p_security_id_char_3 => NULL
7146 ,p_report_request_id => NULL
7147 ,p_event_name => 'postprocessing'
7148 ,p_event_key => to_char(g_accounting_batch_id));
7149 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - postprocessing hook executed successfully');
7150
7151 complete_entries;
7152
7153 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7154 trace
7155 (p_msg => 'END of procedure events_processor'
7156 ,p_level => C_LEVEL_PROCEDURE
7157 ,p_module => l_log_module);
7158 END IF;
7159 EXCEPTION
7160 WHEN xla_exceptions_pkg.application_exception THEN
7161 RAISE;
7162 WHEN OTHERS THEN
7163 xla_exceptions_pkg.raise_message
7164 (p_location => 'xla_accounting_pkg.events_processor');
7165 END events_processor; -- end of procedure
7166
7167 --=============================================================================
7168 --
7169 --
7170 --
7171 --=============================================================================
7172 PROCEDURE delete_batch_je
7173 IS
7174
7175 CURSOR c_headers IS
7176 SELECT /*+ LEADING (XAP) USE_NL (XAP XE XAH) */
7177 xah.ae_header_id
7178 FROM xla_ae_headers xah
7179 , xla_events xe
7180 , xla_acct_prog_events_gt xap
7181 WHERE xah.application_id = xe.application_id
7182 AND xah.event_id = xe.event_id
7183 AND xah.accounting_entry_status_code <> 'F'
7184 AND xe.application_id = g_application_id
7185 AND xe.process_status_code <> 'P'
7186 AND xe.event_id = xap.event_id;
7187
7188 l_array_event_id t_array_integer;
7189 l_array_header_id t_array_integer;
7190 l_array_packet_id t_array_integer;
7191 l_log_module VARCHAR2(240);
7192 BEGIN
7193 IF g_log_enabled THEN
7194 l_log_module := C_DEFAULT_MODULE||'.delete_batch_je';
7195 END IF;
7196 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7197 trace(p_msg => 'BEGIN of procedure delete_batch_je'
7198 ,p_level => C_LEVEL_PROCEDURE
7199 ,p_module => l_log_module);
7200 END IF;
7201
7202 SELECT /*+ leading(xap,xe) use_nl(xe) index(xe,XLA_EVENTS_U1) */
7203 xe.event_id
7204 BULK COLLECT INTO l_array_event_id
7205 FROM xla_events xe
7206 , xla_acct_prog_events_gt xap
7207 WHERE xe.application_id = g_application_id
7208 AND xe.process_status_code <> 'P'
7209 AND xe.event_id = xap.event_id;
7210
7211 IF (l_array_event_id.COUNT > 0) THEN
7212
7213 FORALL i IN 1..l_array_event_id.COUNT
7214 DELETE FROM xla_accounting_errors
7215 WHERE application_id = g_application_id
7216 AND event_id = l_array_event_id(i);
7217
7218 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7219 trace
7220 (p_msg => '# xla_accounting_errors deleted = '||SQL%ROWCOUNT
7221 ,p_level => C_LEVEL_STATEMENT
7222 ,p_module => l_log_module);
7223 END IF;
7224
7225 FORALL i IN 1..l_array_event_id.COUNT
7226 DELETE FROM xla_diag_sources
7227 WHERE event_id = l_array_event_id(i);
7228
7229 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7230 trace(p_msg => '# xla_diag_sources deleted = '||SQL%ROWCOUNT
7231 ,p_level => C_LEVEL_STATEMENT
7232 ,p_module => l_log_module);
7233 END IF;
7234
7235 FORALL i IN 1..l_array_event_id.COUNT
7236 DELETE FROM xla_diag_events
7237 WHERE application_id = g_application_id
7238 AND event_id = l_array_event_id(i);
7239
7240 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7241 trace(p_msg => '# xla_diag_events deleted = '||SQL%ROWCOUNT
7242 ,p_level => C_LEVEL_STATEMENT
7243 ,p_module => l_log_module);
7244 END IF;
7245 --bug6369888
7246 DELETE FROM xla_diag_ledgers d
7247 WHERE d.application_id = g_application_id
7248 AND NOT EXISTS
7249 (SELECT ledger_id, request_id
7250 FROM xla_diag_events
7251 WHERE application_id = d.application_id
7252 AND request_id = d.accounting_request_id
7253 AND ledger_id = d.primary_ledger_id
7254 );
7255
7256 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7257 trace
7258 (p_msg => '# xla_diag_ledgers deleted = '||SQL%ROWCOUNT
7259 ,p_level => C_LEVEL_STATEMENT
7260 ,p_module => l_log_module);
7261 END IF;
7262
7263 FORALL i IN 1..l_array_event_id.COUNT
7264 DELETE FROM gl_bc_packets
7265 WHERE application_id = g_application_id
7266 AND event_id = l_array_event_id(i)
7267 RETURNING packet_id BULK COLLECT INTO l_array_packet_id;
7268
7269 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7270 trace(p_msg => '# gl_bc_packets deleted = '||SQL%ROWCOUNT
7271 ,p_level => C_LEVEL_STATEMENT
7272 ,p_module => l_log_module);
7273 END IF;
7274
7275 IF (l_array_packet_id.COUNT > 0) THEN
7276 FORALL i IN 1..l_array_packet_id.COUNT
7277 DELETE FROM gl_bc_packet_arrival_order
7278 WHERE packet_id = l_array_packet_id(i);
7279
7280 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7281 trace(p_msg => '# gl_bc_packet_arrival_order deleted = '||SQL%ROWCOUNT
7282 ,p_level => C_LEVEL_STATEMENT
7283 ,p_module => l_log_module);
7284 END IF;
7285 END IF;
7286
7287 OPEN c_headers;
7288 FETCH c_headers BULK COLLECT INTO l_array_header_id;
7289 CLOSE c_headers;
7290
7291 IF (l_array_header_id.COUNT > 0) THEN
7292 FORALL i IN 1..l_array_header_id.COUNT
7293 DELETE FROM xla_distribution_links
7294 WHERE application_id = g_application_id
7295 AND ae_header_id = l_array_header_id(i);
7296
7297 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7298 trace(p_msg => '# xla_distribution_links deleted = '||SQL%ROWCOUNT
7299 ,p_level => C_LEVEL_STATEMENT
7300 ,p_module => l_log_module);
7301 END IF;
7302
7303 FORALL i IN 1..l_array_header_id.COUNT
7304 DELETE FROM xla_ae_segment_values
7305 WHERE ae_header_id = l_array_header_id(i);
7306
7307 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7308 trace (p_msg => '# xla_ae_segment_values deleted = '||SQL%ROWCOUNT
7309 ,p_level => C_LEVEL_STATEMENT
7310 ,p_module => l_log_module);
7311 END IF;
7312
7313 FORALL i IN 1..l_array_header_id.COUNT
7314 DELETE FROM xla_ae_line_acs
7315 WHERE ae_header_id = l_array_header_id(i);
7316
7317 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7318 trace (p_msg => '# xla_ae_line_acs deleted = '||SQL%ROWCOUNT
7319 ,p_level => C_LEVEL_STATEMENT
7320 ,p_module => l_log_module);
7321 END IF;
7322
7323 FORALL i IN 1..l_array_header_id.COUNT
7324 DELETE FROM xla_ae_header_acs
7325 WHERE ae_header_id = l_array_header_id(i);
7326
7327 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7328 trace (p_msg => '# xla_ae_header_acs deleted = '||SQL%ROWCOUNT
7329 ,p_level => C_LEVEL_STATEMENT
7330 ,p_module => l_log_module);
7331 END IF;
7332
7333 FORALL i IN 1..l_array_header_id.COUNT
7334 DELETE FROM xla_ae_lines
7335 WHERE application_id = g_application_id
7336 AND ae_header_id = l_array_header_id(i);
7337
7338 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7339 trace(p_msg => '# xla_ae_lines deleted = '||SQL%ROWCOUNT
7340 ,p_level => C_LEVEL_STATEMENT
7341 ,p_module => l_log_module);
7342 END IF;
7343
7344 FORALL i IN 1..l_array_header_id.COUNT
7345 DELETE FROM xla_ae_headers
7346 WHERE application_id = g_application_id
7347 AND ae_header_id = l_array_header_id(i);
7348
7349 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7350 trace(p_msg => '# xla_ae_headers deleted = '||SQL%ROWCOUNT
7351 ,p_level => C_LEVEL_STATEMENT
7352 ,p_module => l_log_module);
7353 END IF;
7354 END IF;
7355 END IF;
7356
7357 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7358 trace(p_msg => 'END of procedure delete_batch_je'
7359 ,p_level => C_LEVEL_PROCEDURE
7360 ,p_module => l_log_module);
7361 END IF;
7362 EXCEPTION
7363 WHEN xla_exceptions_pkg.application_exception THEN
7364 RAISE;
7365 WHEN OTHERS THEN
7366 xla_exceptions_pkg.raise_message
7367 (p_location => 'xla_accounting_pkg.delete_batch_je');
7368 END delete_batch_je;
7369
7370
7371 --=============================================================================
7372 --
7373 --
7374 --
7375 --
7376 --
7377 --
7378 --
7379 --
7380 --
7381 --
7382 -- Following routines are used while accounting for batch of documents as well
7383 -- as for a single document
7384 --
7385 -- 2. complete_entries
7386 --
7387 --
7388 --
7389 --
7390 --
7391 --
7392 --
7393 --
7394 --
7395 --
7396 --
7397 --=============================================================================
7398
7399 --=============================================================================
7400 --
7401 --
7402 --
7403 --=============================================================================
7404
7405 PROCEDURE complete_entries IS
7406 l_index NUMBER := 0;
7407 l_array_ae_header_id t_array_number;
7408 l_array_completion_date t_array_date;
7409 l_array_seq_version_id t_array_number;
7410 l_array_sequence_number t_array_number;
7411 l_array_assignment_id t_array_number;
7412 l_array_error_code t_array_char;
7413
7414 l_xla_application_id NUMBER := 602;
7415 l_xla_seq_entity VARCHAR2(30) := 'XLA_AE_HEADERS';
7416 l_seq_event_code VARCHAR2(30) := 'COMPLETION';
7417 l_control_attribute_rec fun_seq.control_attribute_rec_type;
7418 l_control_date_tbl fun_seq.control_date_tbl_type;
7419
7420 l_sqlerrm VARCHAR2(2000);
7421 l_log_module VARCHAR2(240);
7422 BEGIN
7423 IF g_log_enabled THEN
7424 l_log_module := C_DEFAULT_MODULE||'.complete_entries';
7425 END IF;
7426 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7427 trace
7428 (p_msg => 'BEGIN of procedure COMPLETE_ENTRIES'
7429 ,p_level => C_LEVEL_PROCEDURE
7430 ,p_module => l_log_module);
7431 END IF;
7432
7433 ----------------------------------------------------------------------------
7434 -- If "accounting mode = F", perform sequencing for the subledger journal
7435 -- entries
7436 ----------------------------------------------------------------------------
7437 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7438 trace
7439 (p_msg => 'g_accounting_mode = '||g_accounting_mode
7440 ,p_level => C_LEVEL_STATEMENT
7441 ,p_module => l_log_module);
7442 END IF;
7443
7444 IF g_accounting_mode = 'F' THEN
7445 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7446 trace
7447 (p_msg => 'g_processing_mode = '||g_processing_mode
7448 ,p_level => C_LEVEL_STATEMENT
7449 ,p_module => l_log_module);
7450 trace
7451 (p_msg => 'g_seq_enabled_flag = '||g_seq_enabled_flag
7452 ,p_level => C_LEVEL_STATEMENT
7453 ,p_module => l_log_module);
7454 END IF;
7455
7456 IF g_processing_mode = 'BATCH' AND g_seq_enabled_flag = 'Y' THEN
7457 BEGIN
7458 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Calling sequencing populate_acct_seq_info');
7459
7460 IF (C_LEVEL_EVENT >= g_log_level) THEN
7461 trace
7462 (p_msg => 'Calling procedure FUN_SEQ_BATCH.POPULATE_ACCT_SEQ_INFO'
7463 ,p_level => C_LEVEL_EVENT
7464 ,p_module => l_log_module);
7465 END IF;
7466
7467 fun_seq_batch.populate_acct_seq_info
7468 (p_calling_program => 'ACCOUNTING'
7469 ,p_request_id => g_parent_request_id);
7470
7471 IF (C_LEVEL_EVENT >= g_log_level) THEN
7472 trace
7473 (p_msg => 'Procedure FUN_SEQ_BATCH.POPULATE_ACCT_SEQ_INFO executed'
7474 ,p_level => C_LEVEL_EVENT
7475 ,p_module => l_log_module);
7476 END IF;
7477
7478 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Returned from sequencing populate_acct_seq_info');
7479 EXCEPTION
7480 WHEN OTHERS THEN
7481 l_sqlerrm := sqlerrm;
7482
7483 IF (C_LEVEL_EXCEPTION>= g_log_level) THEN
7484 trace
7485 (p_msg => 'Technical problem : Problem encountered in sequencing POPULATE_ACCT_SEQ_INFO.'||
7486 xla_environment_pkg.g_chr_newline||
7487 l_sqlerrm
7488 ,p_level => C_LEVEL_EXCEPTION
7489 ,p_module => l_log_module);
7490 END IF;
7491
7492 xla_accounting_err_pkg.build_message
7493 (p_appli_s_name => 'XLA'
7494 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
7495 ,p_token_1 => 'APPLICATION_NAME'
7496 ,p_value_1 => 'SLA'
7497 ,p_entity_id => NULL
7498 ,p_event_id => NULL);
7499
7500 print_logfile('Technical problem : Problem encountered in sequencing POPULATE_ACCT_SEQ_INFO.');
7501
7502 xla_exceptions_pkg.raise_message
7503 (p_appli_s_name => 'XLA'
7504 ,p_msg_name => 'XLA_COMMON_ERROR'
7505 ,p_token_1 => 'LOCATION'
7506 ,p_value_1 => 'xla_accounting_pkg.complete_entries'
7507 ,p_token_2 => 'ERROR'
7508 ,p_value_2 => 'Technical problem : Problem encountered in sequencing POPULATE_ACCT_SEQ_INFO.'||
7509 xla_environment_pkg.g_chr_newline||
7510 l_sqlerrm);
7511 END;
7512 ELSIF g_processing_mode = 'DOCUMENT' THEN
7513 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Calling sequencing get_sequence_number');
7514
7515 FOR c1 IN (SELECT /*+ leading(xsl,xeg,aeh) use_nl(aeh) index(xla_ae_headers_n2) */
7516 aeh.ae_header_id ae_header_id
7517 ,aeh.ledger_id ledger_id
7518 ,aeh.balance_type_code balance_type_code
7519 ,xsl.je_source_name je_source_name
7520 ,aeh.je_category_name je_category_name
7521 ,aeh.doc_category_code doc_category_code
7522 ,aeh.event_type_code accounting_event_type_code
7523 ,aeh.accounting_entry_type_code accounting_entry_type_code
7524 ,aeh.accounting_date gl_date
7525 ,aeh.completed_date completion_date
7526 FROM xla_ae_headers aeh
7527 ,xla_events_gt xeg
7528 ,xla_subledgers xsl
7529 WHERE aeh.application_id = xeg.application_id
7530 AND aeh.event_id = xeg.event_id
7531 AND xsl.application_id = xeg.application_id
7532 AND xsl.application_id = g_application_id
7533 AND nvl(aeh.zero_amount_flag, 'N') = 'N')
7534 LOOP
7535 l_index := l_index + 1;
7536
7537 l_control_attribute_rec.balance_type := c1.balance_type_code;
7538 l_control_attribute_rec.journal_source := c1.je_source_name;
7539 l_control_attribute_rec.journal_category := c1.je_category_name;
7540 l_control_attribute_rec.document_category := c1.doc_category_code;
7541 l_control_attribute_rec.accounting_event_type := g_application_id||'.'||c1.accounting_event_type_code;
7542 l_control_attribute_rec.accounting_entry_type := c1.accounting_entry_type_code;
7543
7544 l_control_date_tbl := fun_seq.control_date_tbl_type();
7545 l_control_date_tbl.EXTEND(2);
7546 l_control_date_tbl(1).date_type :='GL_DATE';
7547 l_control_date_tbl(1).date_value := c1.gl_date;
7548 l_control_date_tbl(2).date_type :='COMPLETION_DATE';
7549 l_control_date_tbl(2).date_value := c1.completion_date;
7550
7551 BEGIN
7552 IF (C_LEVEL_EVENT >= g_log_level) THEN
7553 trace
7554 (p_msg => 'Calling procedure FUN_SEQ.GET_SEQUENCE_NUMBER'
7555 ,p_level => C_LEVEL_EVENT
7556 ,p_module => l_log_module);
7557 END IF;
7558
7559 fun_seq.get_sequence_number
7560 (p_context_type => 'LEDGER_AND_CURRENCY'
7561 ,p_context_value => c1.ledger_id
7562 ,p_application_id => l_xla_application_id
7563 ,p_table_name => l_xla_seq_entity
7564 ,p_event_code => l_seq_event_code
7565 ,p_control_attribute_rec => l_control_attribute_rec
7566 ,p_control_date_tbl => l_control_date_tbl
7567 ,p_suppress_error => 'N'
7568 ,x_seq_version_id => l_array_seq_version_id(l_index)
7569 ,x_sequence_number => l_array_sequence_number(l_index)
7570 ,x_assignment_id => l_array_assignment_id(l_index)
7571 ,x_error_code => l_array_error_code(l_index));
7572
7573 IF (C_LEVEL_EVENT >= g_log_level) THEN
7574 trace
7575 (p_msg => 'Procedure FUN_SEQ.GET_SEQUENCE_NUMBER executed'
7576 ,p_level => C_LEVEL_EVENT
7577 ,p_module => l_log_module);
7578 END IF;
7579
7580 l_array_ae_header_id(l_index) := c1.ae_header_id;
7581 l_array_completion_date(l_index) := sysdate;
7582
7583 EXCEPTION
7584 WHEN OTHERS THEN
7585 l_sqlerrm := sqlerrm;
7586
7587 IF (C_LEVEL_EXCEPTION>= g_log_level) THEN
7588 trace
7589 (p_msg => 'Technical problem : Problem encountered in sequencing GET_SEQUENCE_NUMBER.'||
7590 xla_environment_pkg.g_chr_newline||
7591 l_sqlerrm
7592 ,p_level => C_LEVEL_EXCEPTION
7593 ,p_module => l_log_module);
7594 END IF;
7595
7596 xla_accounting_err_pkg.build_message
7597 (p_appli_s_name => 'XLA'
7598 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
7599 ,p_token_1 => 'APPLICATION_NAME'
7600 ,p_value_1 => 'SLA'
7601 ,p_entity_id => NULL
7602 ,p_event_id => NULL);
7603
7604 print_logfile('Technical problem : Problem encountered in sequencing GET_SEQUENCE_NUMBER.');
7605
7606 xla_exceptions_pkg.raise_message
7607 (p_appli_s_name => 'XLA'
7608 ,p_msg_name => 'XLA_COMMON_ERROR'
7609 ,p_token_1 => 'LOCATION'
7610 ,p_value_1 => 'xla_accounting_pkg.complete_entries'
7611 ,p_token_2 => 'ERROR'
7612 ,p_value_2 => 'Technical problem : Problem encountered in sequencing GET_SEQUENCE_NUMBER.'||
7613 xla_environment_pkg.g_chr_newline||
7614 l_sqlerrm);
7615 END;
7616 END LOOP;
7617
7618 FORALL i IN 1..l_array_ae_header_id.COUNT
7619 UPDATE xla_ae_headers aeh
7620 SET aeh.completed_date = l_array_completion_date(i)
7621 ,aeh.completion_acct_seq_assign_id = l_array_assignment_id(i)
7622 ,aeh.completion_acct_seq_version_id = l_array_seq_version_id(i)
7623 ,aeh.completion_acct_seq_value = l_array_sequence_number(i)
7624 WHERE aeh.ae_header_id = l_array_ae_header_id(i);
7625
7626 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7627 trace
7628 (p_msg => 'Number of headers sequenced = '||SQL%ROWCOUNT
7629 ,p_level => C_LEVEL_STATEMENT
7630 ,p_module => l_log_module);
7631 END IF;
7632 print_logfile(to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')||' - Returned from sequencing get_sequence_number');
7633 END IF;
7634 END IF;
7635
7636 ----------------------------------------------------------------------------
7637 -- Following updates event status in xla_events.
7638 -- Statement updated to fix Bug # 3051978
7639 -- Statement updated to fix Bug # 4961401
7640 ----------------------------------------------------------------------------
7641 UPDATE (SELECT /*+ leading(tmp) index(evt, XLA_EVENTS_U1) use_nl(evt)*/ --4769388
7642 evt.event_status_code
7643 ,evt.process_status_code
7644 ,evt.last_update_date
7645 ,evt.last_updated_by
7646 ,evt.last_update_login
7647 ,evt.program_update_date
7648 ,evt.program_application_id
7649 ,evt.program_id
7650 ,evt.request_id
7651 --,DECODE(tmp.process_status_code,'P','P','U') new_event_status_code -- bug 4961401
7652 ,CASE WHEN evt.event_status_code = 'N' THEN 'N'
7653 WHEN tmp.process_status_code = 'P' THEN 'P'
7654 ELSE 'U' END new_event_status_code
7655 --,tmp.process_status_code new_process_status_code -- bug 4961401
7656 ,DECODE(evt.event_status_code,'N','P',tmp.process_status_code) new_process_status_code
7657 FROM xla_events evt
7658 ,xla_events_gt tmp
7659 WHERE evt.event_id = tmp.event_id
7660 AND evt.application_id = g_application_id
7661 )
7662 SET event_status_code = new_event_status_code
7663 ,process_status_code = new_process_status_code
7664 ,last_update_date = sysdate
7665 ,last_updated_by = xla_environment_pkg.g_usr_id
7666 ,last_update_login = xla_environment_pkg.g_login_id
7667 ,request_id = g_report_request_id;
7668
7669
7670 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7671 trace
7672 (p_msg => 'Number of events updated = '||SQL%ROWCOUNT
7673 ,p_level => C_LEVEL_STATEMENT
7674 ,p_module => l_log_module);
7675 END IF;
7676
7677 ----------------------------------------------------------------------------
7678 -- Following call inserts errors into error table
7679 ----------------------------------------------------------------------------
7680 --xla_accounting_err_pkg.insert_errors; -- bug 5206382
7681
7682 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7683 trace
7684 (p_msg => 'END of procedure COMPLETE_ENTRIES'
7685 ,p_level => C_LEVEL_PROCEDURE
7686 ,p_module => l_log_module);
7687 END IF;
7688 EXCEPTION
7689 WHEN xla_exceptions_pkg.application_exception THEN
7690 RAISE;
7691 WHEN OTHERS THEN
7692 xla_exceptions_pkg.raise_message
7693 (p_location => 'xla_accounting_pkg.complete_entries');
7694 END complete_entries; -- end of procedure
7695
7696
7697 --------------------------------------------------------------------------------
7698 -- This procedure is used to raise preaccounting event or postaccounting event
7699 -- p_event_name will be 'preaccounting' or 'postaccounting'
7700 --------------------------------------------------------------------------------
7701 PROCEDURE raise_accounting_event( p_application_id IN NUMBER
7702 ,p_ledger_id IN NUMBER
7703 ,p_process_category IN VARCHAR2
7704 ,p_end_date IN DATE
7705 ,p_accounting_mode IN VARCHAR2
7706 ,p_valuation_method IN VARCHAR2
7707 ,p_security_id_int_1 IN NUMBER
7708 ,p_security_id_int_2 IN NUMBER
7709 ,p_security_id_int_3 IN NUMBER
7710 ,p_security_id_char_1 IN VARCHAR2
7711 ,p_security_id_char_2 IN VARCHAR2
7712 ,p_security_id_char_3 IN VARCHAR2
7713 ,p_report_request_id IN NUMBER
7714 ,p_event_name IN VARCHAR2
7715 ,p_event_key IN VARCHAR2)
7716 IS
7717
7718 x_progress VARCHAR2(100) := '000';
7719 l_parameter_list wf_parameter_list_t := wf_parameter_list_t();
7720 l_event_name VARCHAR2(50):='oracle.apps.xla.accounting.'||p_event_name;
7721 l_log_module VARCHAR2(240);
7722 BEGIN
7723 IF g_log_enabled THEN
7724 l_log_module := C_DEFAULT_MODULE||'.raise_accounting_event';
7725 END IF;
7726 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7727 trace
7728 (p_msg => 'BEGIN of procedure RAISE_ACCOUNTING_EVENT'
7729 ,p_level => C_LEVEL_PROCEDURE
7730 ,p_module => l_log_module);
7731 trace
7732 (p_msg => 'p_application_id = '||p_application_id
7733 ,p_level => C_LEVEL_PROCEDURE
7734 ,p_module => l_log_module);
7735 trace
7736 (p_msg => 'p_ledger_id = '||p_ledger_id
7737 ,p_level => C_LEVEL_PROCEDURE
7738 ,p_module => l_log_module);
7739 trace
7740 (p_msg => 'p_process_category = '||p_process_category
7741 ,p_level => C_LEVEL_PROCEDURE
7742 ,p_module => l_log_module);
7743 trace
7744 (p_msg => 'p_end_date = '||p_end_date
7745 ,p_level => C_LEVEL_PROCEDURE
7746 ,p_module => l_log_module);
7747 trace
7748 (p_msg => 'p_accounting_mode = '||p_accounting_mode
7749 ,p_level => C_LEVEL_PROCEDURE
7750 ,p_module => l_log_module);
7751 trace
7752 (p_msg => 'p_valuation_method = '||p_valuation_method
7753 ,p_level => C_LEVEL_PROCEDURE
7754 ,p_module => l_log_module);
7755 trace
7756 (p_msg => 'p_security_id_int_1 = '||p_security_id_int_1
7757 ,p_level => C_LEVEL_PROCEDURE
7758 ,p_module => l_log_module);
7759 trace
7760 (p_msg => 'p_security_id_int_2 = '||p_security_id_int_2
7761 ,p_level => C_LEVEL_PROCEDURE
7762 ,p_module => l_log_module);
7763 trace
7764 (p_msg => 'p_security_id_int_3 = '||p_security_id_int_3
7765 ,p_level => C_LEVEL_PROCEDURE
7766 ,p_module => l_log_module);
7767 trace
7768 (p_msg => 'p_security_id_char_1 = '||p_security_id_char_1
7769 ,p_level => C_LEVEL_PROCEDURE
7770 ,p_module => l_log_module);
7771 trace
7772 (p_msg => 'p_security_id_char_2 = '||p_security_id_char_2
7773 ,p_level => C_LEVEL_PROCEDURE
7774 ,p_module => l_log_module);
7775 trace
7776 (p_msg => 'p_security_id_char_3 = '||p_security_id_char_3
7777 ,p_level => C_LEVEL_PROCEDURE
7778 ,p_module => l_log_module);
7779 trace
7780 (p_msg => 'p_report_request_id = '||p_report_request_id
7781 ,p_level => C_LEVEL_PROCEDURE
7782 ,p_module => l_log_module);
7783 trace
7784 (p_msg => 'p_event_name = '||p_event_name
7785 ,p_level => C_LEVEL_PROCEDURE
7786 ,p_module => l_log_module);
7787 trace
7788 (p_msg => 'p_event_key = '||p_event_key
7789 ,p_level => C_LEVEL_PROCEDURE
7790 ,p_module => l_log_module);
7791 END IF;
7792
7793 print_logfile('event key = '||p_event_key);
7794
7795 x_progress := '001';
7796
7797 -- Add Parameters
7798 wf_event.AddParameterToList(p_name =>'APPLICATION_ID',
7799 p_value => p_application_id,
7800 p_parameterlist => l_parameter_list);
7801 wf_event.AddParameterToList(p_name =>'LEDGER_ID',
7802 p_value => p_ledger_id,
7803 p_parameterlist => l_parameter_list);
7804 wf_event.AddParameterToList(p_name =>'PROCESS_CATEGORY',
7805 p_value => p_process_category,
7806 p_parameterlist => l_parameter_list);
7807 wf_event.AddParameterToList(p_name =>'END_DATE',
7808 p_value => p_end_date,
7809 p_parameterlist => l_parameter_list);
7810 wf_event.AddParameterToList(p_name =>'ACCOUNTING_MODE',
7811 p_value => p_accounting_mode,
7812 p_parameterlist => l_parameter_list);
7813 wf_event.AddParameterToList(p_name =>'VALUATION_METHOD',
7814 p_value => p_valuation_method,
7815 p_parameterlist => l_parameter_list);
7816 wf_event.AddParameterToList(p_name =>'SECURITY_ID_INT_1',
7817 p_value => p_security_id_int_1,
7818 p_parameterlist => l_parameter_list);
7819 wf_event.AddParameterToList(p_name =>'SECURITY_ID_INT_2',
7820 p_value => p_security_id_int_2,
7821 p_parameterlist => l_parameter_list);
7822 wf_event.AddParameterToList(p_name =>'SECURITY_ID_INT_3',
7823 p_value => p_security_id_int_3,
7824 p_parameterlist => l_parameter_list);
7825 wf_event.AddParameterToList(p_name =>'SECURITY_ID_CHAR_1',
7826 p_value => p_security_id_char_1,
7827 p_parameterlist => l_parameter_list);
7828 wf_event.AddParameterToList(p_name =>'SECURITY_ID_CHAR_2',
7829 p_value => p_security_id_char_2,
7830 p_parameterlist => l_parameter_list);
7831 wf_event.AddParameterToList(p_name =>'SECURITY_ID_CHAR_3',
7832 p_value => p_security_id_char_3,
7833 p_parameterlist => l_parameter_list);
7834 wf_event.AddParameterToList(p_name =>'REQUEST_ID',
7835 p_value => p_report_request_id,
7836 p_parameterlist => l_parameter_list);
7837 x_progress := '002';
7838
7839 wf_event.RAISE( p_event_name => l_event_name,
7840 p_event_key => p_event_key,
7841 p_parameters => l_parameter_list);
7842
7843
7844 l_parameter_list.DELETE;
7845
7846 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7847 trace
7848 (p_msg => 'END of procedure RAISE_ACCOUNTING_EVENT'
7849 ,p_level => C_LEVEL_PROCEDURE
7850 ,p_module => l_log_module);
7851 END IF;
7852
7853 EXCEPTION
7854 WHEN others THEN
7855 wf_core.CONTEXT('xla_accounting_pkg','raise_accounting_event',x_progress);
7856 RAISE;
7857
7858 END raise_accounting_event;
7859
7860
7861 --------------------------------------------------------------------------------
7862 -- This procedure is used to raise postprocessing event or extract event
7863 -- p_event_name will be 'postprocessing' or 'extract'
7864 --------------------------------------------------------------------------------
7865 PROCEDURE raise_unit_event( p_application_id IN NUMBER
7866 ,p_accounting_mode IN VARCHAR2
7867 ,p_event_name IN VARCHAR2
7868 ,p_event_key IN VARCHAR2)
7869 IS
7870
7871 x_progress VARCHAR2(100) := '000';
7872 l_parameter_list wf_parameter_list_t := wf_parameter_list_t();
7873 l_event_name VARCHAR2(50):='oracle.apps.xla.accounting.'||p_event_name;
7874 l_log_module VARCHAR2(240);
7875 BEGIN
7876 IF g_log_enabled THEN
7877 l_log_module := C_DEFAULT_MODULE||'.raise_unit_event';
7878 END IF;
7879 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7880 trace
7881 (p_msg => 'BEGIN of procedure RAISE_UNIT_EVENT'
7882 ,p_level => C_LEVEL_PROCEDURE
7883 ,p_module => l_log_module);
7884 trace
7885 (p_msg => 'p_application_id = '||p_application_id
7886 ,p_level => C_LEVEL_PROCEDURE
7887 ,p_module => l_log_module);
7888 trace
7889 (p_msg => 'p_accounting_mode = '||p_accounting_mode
7890 ,p_level => C_LEVEL_PROCEDURE
7891 ,p_module => l_log_module);
7892 trace
7893 (p_msg => 'p_event_name = '||p_event_name
7894 ,p_level => C_LEVEL_PROCEDURE
7895 ,p_module => l_log_module);
7896 trace
7897 (p_msg => 'p_event_key = '||p_event_key
7898 ,p_level => C_LEVEL_PROCEDURE
7899 ,p_module => l_log_module);
7900 END IF;
7901
7902 print_logfile('event key = '||p_event_key);
7903
7904 x_progress := '001';
7905
7906 -- Add Parameters
7907 wf_event.AddParameterToList(p_name =>'APPLICATION_ID',
7908 p_value => p_application_id,
7909 p_parameterlist => l_parameter_list);
7910 wf_event.AddParameterToList(p_name =>'ACCOUNTING_MODE',
7911 p_value => p_accounting_mode,
7912 p_parameterlist => l_parameter_list);
7913 x_progress := '002';
7914
7915 wf_event.RAISE( p_event_name => l_event_name,
7916 p_event_key => p_event_key,
7917 p_parameters => l_parameter_list);
7918
7919 l_parameter_list.DELETE;
7920
7921 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7922 trace
7923 (p_msg => 'END of procedure RAISE_UNIT_EVENT'
7924 ,p_level => C_LEVEL_PROCEDURE
7925 ,p_module => l_log_module);
7926 END IF;
7927
7928 EXCEPTION
7929 WHEN others THEN
7930 wf_core.CONTEXT('xla_accounting_pkg','raise_unit_event',x_progress);
7931 RAISE;
7932
7933 END raise_unit_event;
7934
7935 --------------------------------------------------------------------------------
7936 -- This procedure is used to handle accounting hooks for preaccounting, extract,
7937 -- postprocessing and postaccounting.
7938 -- p_event_name will be 'postprocessing' or 'extract' or 'preaccounting' or
7939 -- 'postaccounting'
7940 --------------------------------------------------------------------------------
7941 PROCEDURE handle_accounting_hook
7942 (p_application_id IN NUMBER
7943 ,p_ledger_id IN NUMBER
7944 ,p_process_category IN VARCHAR2
7945 ,p_end_date IN DATE
7946 ,p_accounting_mode IN VARCHAR2
7947 ,p_budgetary_control_mode IN VARCHAR2
7948 ,p_valuation_method IN VARCHAR2
7949 ,p_security_id_int_1 IN NUMBER
7950 ,p_security_id_int_2 IN NUMBER
7951 ,p_security_id_int_3 IN NUMBER
7952 ,p_security_id_char_1 IN VARCHAR2
7953 ,p_security_id_char_2 IN VARCHAR2
7954 ,p_security_id_char_3 IN VARCHAR2
7955 ,p_report_request_id IN NUMBER
7956 ,p_event_name IN VARCHAR2
7957 ,p_event_key IN VARCHAR2)
7958 IS
7959 l_log_module VARCHAR2(240);
7960 l_sqlerrm VARCHAR2(2000);
7961 BEGIN
7962 IF g_log_enabled THEN
7963 l_log_module := C_DEFAULT_MODULE||'.handle_accounting_hook';
7964 END IF;
7965
7966 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7967 trace
7968 (p_msg => 'BEGIN of procedure handle_accounting_hook'
7969 ,p_level => C_LEVEL_PROCEDURE
7970 ,p_module => l_log_module);
7971 END IF;
7972
7973 --------------------------------------------------------------------------
7974 -- Calling different API's depending on Application ID
7975 --------------------------------------------------------------------------
7976 CASE
7977 --
7978 -- For Account Payables
7979 --
7980 WHEN p_application_id = 200 THEN
7981 xla_ap_acct_hooks_pkg.main
7982 ( p_application_id => p_application_id
7983 ,p_ledger_id => p_ledger_id
7984 ,p_process_category => p_process_category
7985 ,p_end_date => p_end_date
7986 ,p_accounting_mode => CASE WHEN NVL(p_budgetary_control_mode,'NONE') = 'NONE'
7987 THEN p_accounting_mode
7988 ELSE p_budgetary_control_mode
7989 END -- 4606566
7990 ,p_valuation_method => p_valuation_method
7991 ,p_security_id_int_1 => p_security_id_int_1
7992 ,p_security_id_int_2 => p_security_id_int_2
7993 ,p_security_id_int_3 => p_security_id_int_3
7994 ,p_security_id_char_1 => p_security_id_char_1
7995 ,p_security_id_char_2 => p_security_id_char_2
7996 ,p_security_id_char_3 => p_security_id_char_3
7997 ,p_report_request_id => p_report_request_id
7998 ,p_event_name => p_event_name);
7999
8000 --
8001 -- For Account Recievables
8002 --
8003 WHEN p_application_id = 222 THEN
8004 xla_ar_acct_hooks_pkg.main
8005 ( p_application_id => p_application_id
8006 ,p_ledger_id => p_ledger_id
8007 ,p_process_category => p_process_category
8008 ,p_end_date => p_end_date
8009 ,p_accounting_mode => p_accounting_mode
8010 ,p_valuation_method => p_valuation_method
8011 ,p_security_id_int_1 => p_security_id_int_1
8012 ,p_security_id_int_2 => p_security_id_int_2
8013 ,p_security_id_int_3 => p_security_id_int_3
8014 ,p_security_id_char_1 => p_security_id_char_1
8015 ,p_security_id_char_2 => p_security_id_char_2
8016 ,p_security_id_char_3 => p_security_id_char_3
8017 ,p_report_request_id => p_report_request_id
8018 ,p_event_name => p_event_name);
8019
8020 --
8021 -- For Fixed Assets
8022 --
8023 WHEN p_application_id = 140 THEN
8024 xla_fa_acct_hooks_pkg.main
8025 ( p_application_id => p_application_id
8026 ,p_ledger_id => p_ledger_id
8027 ,p_process_category => p_process_category
8028 ,p_end_date => p_end_date
8029 ,p_accounting_mode => p_accounting_mode
8030 ,p_valuation_method => p_valuation_method
8031 ,p_security_id_int_1 => p_security_id_int_1
8032 ,p_security_id_int_2 => p_security_id_int_2
8033 ,p_security_id_int_3 => p_security_id_int_3
8034 ,p_security_id_char_1 => p_security_id_char_1
8035 ,p_security_id_char_2 => p_security_id_char_2
8036 ,p_security_id_char_3 => p_security_id_char_3
8037 ,p_report_request_id => p_report_request_id
8038 ,p_event_name => p_event_name);
8039
8040 --
8041 -- For Cash Managment
8042 --
8043 WHEN p_application_id = 260 THEN
8044 xla_ce_acct_hooks_pkg.main
8045 ( p_application_id => p_application_id
8046 ,p_ledger_id => p_ledger_id
8047 ,p_process_category => p_process_category
8048 ,p_end_date => p_end_date
8049 ,p_accounting_mode => p_accounting_mode
8050 ,p_valuation_method => p_valuation_method
8051 ,p_security_id_int_1 => p_security_id_int_1
8052 ,p_security_id_int_2 => p_security_id_int_2
8053 ,p_security_id_int_3 => p_security_id_int_3
8054 ,p_security_id_char_1 => p_security_id_char_1
8055 ,p_security_id_char_2 => p_security_id_char_2
8056 ,p_security_id_char_3 => p_security_id_char_3
8057 ,p_report_request_id => p_report_request_id
8058 ,p_event_name => p_event_name);
8059
8060
8061
8062 --
8063 -- For Process Manufacturing Financials
8064 --
8065
8066 WHEN p_application_id = 555 THEN
8067 xla_gmf_acct_hooks_pkg.main
8068 ( p_application_id => p_application_id
8069 ,p_ledger_id => p_ledger_id
8070 ,p_process_category => p_process_category
8071 ,p_end_date => p_end_date
8072 ,p_accounting_mode => p_accounting_mode
8073 ,p_valuation_method => p_valuation_method
8074 ,p_security_id_int_1 => p_security_id_int_1
8075 ,p_security_id_int_2 => p_security_id_int_2
8076 ,p_security_id_int_3 => p_security_id_int_3
8077 ,p_security_id_char_1 => p_security_id_char_1
8078 ,p_security_id_char_2 => p_security_id_char_2
8079 ,p_security_id_char_3 => p_security_id_char_3
8080 ,p_report_request_id => p_report_request_id
8081 ,p_event_name => p_event_name);
8082
8083 --
8084 -- For Payroll
8085 --
8086
8087 WHEN p_application_id = 801 THEN
8088 xla_pay_acct_hooks_pkg.main
8089 ( p_application_id => p_application_id
8090 ,p_ledger_id => p_ledger_id
8091 ,p_process_category => p_process_category
8092 ,p_end_date => p_end_date
8093 ,p_accounting_mode => p_accounting_mode
8094 ,p_valuation_method => p_valuation_method
8095 ,p_security_id_int_1 => p_security_id_int_1
8096 ,p_security_id_int_2 => p_security_id_int_2
8097 ,p_security_id_int_3 => p_security_id_int_3
8098 ,p_security_id_char_1 => p_security_id_char_1
8099 ,p_security_id_char_2 => p_security_id_char_2
8100 ,p_security_id_char_3 => p_security_id_char_3
8101 ,p_report_request_id => p_report_request_id
8102 ,p_event_name => p_event_name);
8103
8104
8105
8106
8107 --
8108 -- For all other products
8109 --
8110 ELSE
8111 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8112 trace
8113 (p_msg => 'Warning: Product is not integrated using APIs'
8114 ,p_level => C_LEVEL_PROCEDURE
8115 ,p_module => l_log_module);
8116 END IF;
8117 END CASE;
8118
8119 --
8120 -- raising business event for all the subledgers
8121 --
8122
8123 IF p_event_name IN ('extract','postprocessing') THEN
8124 raise_unit_event
8125 (p_application_id => p_application_id
8126 ,p_accounting_mode => p_accounting_mode
8127 ,p_event_name => p_event_name
8128 ,p_event_key => p_event_key);
8129 ELSE
8130 raise_accounting_event
8131 (p_application_id => p_application_id
8132 ,p_ledger_id => p_ledger_id
8133 ,p_process_category => p_process_category
8134 ,p_end_date => p_end_date
8135 ,p_accounting_mode => p_accounting_mode
8136 ,p_valuation_method => p_valuation_method
8137 ,p_security_id_int_1 => p_security_id_int_1
8138 ,p_security_id_int_2 => p_security_id_int_2
8139 ,p_security_id_int_3 => p_security_id_int_3
8140 ,p_security_id_char_1 => p_security_id_char_1
8141 ,p_security_id_char_2 => p_security_id_char_2
8142 ,p_security_id_char_3 => p_security_id_char_3
8143 ,p_report_request_id => p_report_request_id
8144 ,p_event_name => p_event_name
8145 ,p_event_key => p_event_key);
8146 END IF;
8147
8148 -- Call to PSA accounting hook
8149 xla_psa_acct_hooks_pkg.main
8150 ( p_application_id => p_application_id
8151 ,p_ledger_id => p_ledger_id
8152 ,p_process_category => p_process_category
8153 ,p_end_date => p_end_date
8154 ,p_accounting_mode => p_accounting_mode
8155 ,p_valuation_method => p_valuation_method
8156 ,p_security_id_int_1 => p_security_id_int_1
8157 ,p_security_id_int_2 => p_security_id_int_2
8158 ,p_security_id_int_3 => p_security_id_int_3
8159 ,p_security_id_char_1 => p_security_id_char_1
8160 ,p_security_id_char_2 => p_security_id_char_2
8161 ,p_security_id_char_3 => p_security_id_char_3
8162 ,p_report_request_id => p_report_request_id
8163 ,p_event_name => p_event_name);
8164
8165 -- Call to Federal accounting hook
8166 xla_fv_acct_hooks_pkg.main
8167 ( p_application_id => p_application_id
8168 ,p_ledger_id => p_ledger_id
8169 ,p_process_category => p_process_category
8170 ,p_end_date => p_end_date
8171 ,p_accounting_mode => p_accounting_mode
8172 ,p_valuation_method => p_valuation_method
8173 ,p_security_id_int_1 => p_security_id_int_1
8174 ,p_security_id_int_2 => p_security_id_int_2
8175 ,p_security_id_int_3 => p_security_id_int_3
8176 ,p_security_id_char_1 => p_security_id_char_1
8177 ,p_security_id_char_2 => p_security_id_char_2
8178 ,p_security_id_char_3 => p_security_id_char_3
8179 ,p_report_request_id => p_report_request_id
8180 ,p_event_name => p_event_name);
8181
8182
8183 -- Call to IGI accounting hook bug6359422
8184
8185 xla_igi_acct_hooks_pkg.main
8186 ( p_application_id => p_application_id
8187 ,p_ledger_id => p_ledger_id
8188 ,p_process_category => p_process_category
8189 ,p_end_date => p_end_date
8190 ,p_accounting_mode => p_accounting_mode
8191 ,p_valuation_method => p_valuation_method
8192 ,p_security_id_int_1 => p_security_id_int_1
8193 ,p_security_id_int_2 => p_security_id_int_2
8194 ,p_security_id_int_3 => p_security_id_int_3
8195 ,p_security_id_char_1 => p_security_id_char_1
8196 ,p_security_id_char_2 => p_security_id_char_2
8197 ,p_security_id_char_3 => p_security_id_char_3
8198 ,p_report_request_id => p_report_request_id
8199 ,p_event_name => p_event_name);
8200
8201 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8202 trace
8203 (p_msg => 'END of procedure handle_accounting_hooks'
8204 ,p_level => C_LEVEL_PROCEDURE
8205 ,p_module => l_log_module);
8206 END IF;
8207
8208 EXCEPTION
8209 WHEN xla_exceptions_pkg.application_exception THEN
8210 RAISE;
8211 WHEN others THEN
8212 l_sqlerrm := sqlerrm;
8213
8214 IF (C_LEVEL_EXCEPTION>= g_log_level) THEN
8215 trace
8216 (p_msg => 'Technical problem : Exception encounterd while raising '||
8217 'business event for '||p_event_name||
8218 xla_environment_pkg.g_chr_newline||l_sqlerrm
8219 ,p_level => C_LEVEL_EXCEPTION
8220 ,p_module => l_log_module);
8221 END IF;
8222
8223 xla_accounting_err_pkg.build_message
8224 (p_appli_s_name => 'XLA'
8225 ,p_msg_name => 'XLA_AP_TECHNICAL_ERROR'
8226 ,p_token_1 => 'APPLICATION_NAME'
8227 ,p_value_1 => 'SLA'
8228 ,p_entity_id => NULL
8229 ,p_event_id => NULL);
8230
8231 print_logfile('Technical problem : Exception encounterd while raising busniess event for '||p_event_name);
8232
8233 xla_exceptions_pkg.raise_message
8234 (p_appli_s_name => 'XLA'
8235 ,p_msg_name => 'XLA_COMMON_ERROR'
8236 ,p_token_1 => 'LOCATION'
8237 ,p_value_1 => 'xla_accounting_pkg.handle_accounting_hook'
8238 ,p_token_2 => 'ERROR'
8239 ,p_value_2 => 'Technical problem : Exception encounterd while raising '||
8240 'busniess event for '||p_event_name||
8241 xla_environment_pkg.g_chr_newline||l_sqlerrm);
8242 END handle_accounting_hook;
8243
8244 FUNCTION concat_event_classes
8245 (p_processing_order IN NUMBER)
8246 RETURN VARCHAR2
8247 IS
8248 l_concat_classes VARCHAR2(5000);
8249 BEGIN
8250 l_concat_classes := NULL;
8251 --
8252 -- changes done for bug 5673550 to put filter based on process category
8253 --
8254 IF g_process_category IS NULL THEN
8255 FOR c IN (SELECT event_class_code FROM xla_evt_class_orders_gt WHERE processing_order = p_processing_order) LOOP
8256 IF l_concat_classes IS NULL THEN
8257 l_concat_classes := C_QUOTE;
8258 ELSE
8259 l_concat_classes := l_concat_classes || C_COMMA;
8260 END IF;
8261 l_concat_classes := l_concat_classes || c.event_class_code;
8262 END LOOP;
8263 ELSE
8264 FOR c IN (SELECT xec.event_class_code
8265 FROM xla_evt_class_orders_gt xec
8266 ,xla_event_class_attrs xea
8267 WHERE xea.application_id = g_application_id
8268 AND xea.event_class_code = xec.event_class_code
8269 AND xea.event_class_group_code = g_process_category
8270 AND xec.processing_order = p_processing_order) LOOP
8271 IF l_concat_classes IS NULL THEN
8272 l_concat_classes := C_QUOTE;
8273 ELSE
8274 l_concat_classes := l_concat_classes || C_COMMA;
8275 END IF;
8276 l_concat_classes := l_concat_classes || c.event_class_code;
8277 END LOOP;
8278 END IF;
8279
8280 IF l_concat_classes IS NOT NULL THEN
8281 l_concat_classes := l_concat_classes || C_QUOTE;
8282 END IF;
8283
8284 RETURN l_concat_classes;
8285
8286 END concat_event_classes;
8287
8288 --=============================================================================
8289 -- *********** Initialization routine **********
8290 --=============================================================================
8291
8292 --=============================================================================
8293 --
8294 --
8295 --
8296 --
8297 --
8298 --
8299 --
8300 --
8301 --
8302 --
8303 -- Following code is executed when the package body is referenced for the first
8304 -- time
8305 --
8306 --
8307 --
8308 --
8309 --
8310 --
8311 --
8312 --
8313 --
8314 --
8315 --
8316 --
8317 --=============================================================================
8318
8319 BEGIN
8320 g_log_level := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
8321 g_log_enabled := fnd_log.test
8322 (log_level => g_log_level
8323 ,MODULE => C_DEFAULT_MODULE);
8324
8325 IF NOT g_log_enabled THEN
8326 g_log_level := C_LEVEL_LOG_DISABLED;
8327 END IF;
8328
8329 g_conc_hold := fnd_profile.value('CONC_HOLD');
8330
8331 END xla_accounting_pkg;