DBA Data[Home] [Help]

PACKAGE BODY: APPS.XLA_CMP_EVENT_TYPE_PKG

Source


1 PACKAGE BODY xla_cmp_event_type_pkg AS
2 /* $Header: xlacpevt.pkb 120.75.12010000.3 2008/12/17 14:09:00 kapkumar ship $   */
3 /*===========================================================================+
4 |             Copyright (c) 2001-2002 Oracle Corporation                     |
5 |                       Redwood Shores, CA, USA                              |
6 |                         All rights reserved.                               |
7 +============================================================================+
8 | PACKAGE NAME                                                               |
9 |     xla_cmp_event_type_pkg                                                 |
10 |                                                                            |
11 | DESCRIPTION                                                                |
12 |     This is a XLA private package, which contains all the logic required   |
13 |     to generate Event Class or Event Type Function                         |
14 |     from AMB specifcations                                                 |
15 |                                                                            |
16 |                                                                            |
17 | HISTORY                                                                    |
18 |     25-JUN-2002 K.Boussema    Created                                      |
19 |     25-FEB-2003 K.Boussema    Added 'dbdrv' command                        |
20 |     19-MAR-2003 K.Boussema    Added amb_context_code                       |
21 |     02-APR-2003 K.boussema    Added generation of analytical criteria      |
22 |     14-APR-2003 K.Bouusema    Added the error messages                     |
23 |     22-APR-2003 K.Boussema    Included error messages                      |
24 |     22-APR-2003 K.Boussema    Added SEQ_DOC_CATEGORY_CODE source           |
25 |     13-MAI-2003 K.Boussema    Modified the Extract according to bug 2857548|
26 |     02-JUN-2003 K.Boussema    Modified to fix bug 2975670 and bug 2729143  |
27 |     27-JUN-2003 K.Boussema    Renamed XLA_DESCRIPTION_PRIO table           |
28 |     17-JUL-2003 K.Boussema    Reviewd the code                             |
29 |     24-JUL-2003 K.Boussema    Updated the error messages                   |
30 |     26-AUG-2003 K.Boussema    Reviewd the generation of the extract to     |
31 |                               handle the use of line_number as source      |
32 |     10-SEP-2003 K.Boussema    Changed to fix bug3095206:Accounting Reversal|
33 |     17-SEP-2003 K.Boussema    Updated to Get je_category from cache:3109690|
34 |     09-OCT-2003 K.Boussema    Changed to accept AADs differents Extract    |
35 |                               specifcations                                |
36 |     27-OCT-2003 K.Boussema    Changed to raise Error when no data retrieved|
37 |                               by the extract, bug 3203657                  |
38 |     04-NOV-2003 K.Boussema    Added new accounting reversal indicator value|
39 |     01-DEC-2003 K.Boussema    Added the cache of Extract errors in code    |
40 |                               generated by the compiler                    |
41 |     12-DEC-2003 K.Boussema    Reviewed for bug 3042840                     |
42 |     18-DEC-2003 K.Boussema    Changed to fix bug 3042840,3307761,3268940   |
43 |                               3310291 and 3320689                          |
44 |     22-DEC-2003 K.Boussema    Replaced Extract Validations by a call to    |
45 |                               Extract Integrity Checker routine            |
46 |     02-FRB-2004 K.Boussema    Changed code generated, refer to bug 3274707 |
47 |     12-FEB-2004 K.Boussema    Changed to only display the extraxt error msg|
48 |                               of the alway_populated objects               |
49 |     19-FEB-2004 K.Boussema    Made changes for the FND_LOG.                |
50 |     12-MAR-2004 K.Boussema    Changed to incorporate the select of lookups |
51 |                               from the extract objects                     |
52 |     22-MAR-2004 K.Boussema    Added a parameter p_module to the TRACE calls|
53 |                               and the procedure.                           |
54 |     11-MAY-2004 K.Boussema  Removed the call to XLA trace routine from     |
55 |                             trace() procedure                              |
56 |     17-MAY-2004 W.Shen        Accounting Attribute Enhancement project     |
57 |                               check the dld for changed made to the package|
58 |     26-MAY-2004 W.Shen        change code for the error message            |
59 |     26-Jul-2004 W.Shen        bug 3786968. transaction reversal do not have|
60 |                               extract line. When call function             |
61 |                               xla_accounting_engine_pkg.CacheExtractErrors |
62 |                               The transaction reversal flag is passed.     |
63 |     23-Sep-2004 S.Singhania Made changes for the bulk peroformance. It has |
64 |                               changed the code at number of places.        |
65 |     05-Oct-2004 S.Singhania Bug 3931752: Modified constants C_EVENT_BODY   |
66 |                               C_BODY_LINES to set correct target_ledger_id.|
67 |     08-Oct-2004 S.Singhania Bug 3939231: Added code to C_EVENT_BODY to     |
68 |                               initialize xla_ae_lines_pkg.g_temp_line_num. |
69 |     12-Oct-2004 K.Boussema    Made changes for the Accounting Event Extract|
70 |                               Diagnostics feature.                         |
71 |     08-Dec-2004 K.Boussema  Updated to add diagnostic framework datamodel  |
72 |                             changes                                        |
73 |     27-DEC-2004 K.Boussema Changed the VARCHAR2 type by CLOB to handle the |
74 |                            large main procedure                            |
75 |     15-Feb-2005 W.Shen        change code ledger currency project          |
76 |                            remove alc object.                              |
77 |                            add the two calculate accounted amts, gain/loss |
78 |                               flags                                        |
79 |     07-Mar-2005 K.Boussema    Changed for ADR-enhancements.                |
80 |     29-Mar-2005 M.Asada       Changed for Reference Objects.               |
81 |     18-Jul-2005 W.Chan        4495733 - In GetEntityName, update length    |
82 |                               of l_name from 30 to 90                      |
83 |     21-JUL-2005 K.Boussema   Reviewed to handle the two cases:             |
84 |                                - no header Transaction objects and         |
85 |                                - no line Transaction objects               |
86 |     22-Sep-2005 S.Singhania  Bug 4544725. Implemented Business Flows and   |
87 |                                Reversals for Non-Upgraded JEs.             |
88 |     18-Oct-2005 V. Kumar    Removed code for Analytical Criteria           |
89 |     20-Jan-2006 A. Wan      4884853 -                                      |
90 |                             Modified GenerateAccRevBody to adjust Accrual  |
91 |                             Reversal Date before PostAccountingEngine.     |
92 |     10-Feb-2006 A. Wan      5019460 - redundant logic in C_EVENT_BODY      |
93 |     08-Mar-2006 V. Kumar    Modified C_MAIN_PROCEDURE                      |
94 |     09-May-2006 V. Kumar    5217187 Populating GL_DATE for Reversal        |
95 |     09-May-2006 A.WAn       5202219 - prevent trx rev error out.           |
96 |     19-May-2006 V. Kumar    5229264 Populating gl_date for Trx rev. case   |
97 |     09-Nov-2006 A.Wan       5648433 - init l_event_id for line_cursor.     |
98 +===========================================================================*/
99 
100 --
101 --+==========================================================================+
102 --|                                                                          |
103 --|                                                                          |
104 --|                                                                          |
105 --|                                                                          |
106 --|                                                                          |
107 --|                                                                          |
108 --|                                                                          |
109 --|                                                                          |
110 --|                                                                          |
111 --|                                                                          |
112 --|                    AAD templates/Global constants                        |
113 --|                                                                          |
114 --|                                                                          |
115 --|                                                                          |
116 --|                                                                          |
117 --|                                                                          |
118 --|                                                                          |
119 --|                                                                          |
120 --|                                                                          |
121 --|                                                                          |
122 --+==========================================================================+
123 --
124 --
125 --+========================================================
126 --| Template of the main function CreateHeadersAndLines
127 --+========================================================
128 --
129 C_MAIN_PROCEDURE   CONSTANT VARCHAR2(10000) := '
130 --
131 --+============================================+
132 --|                                            |
133 --|  PRIVATE FUNCTION                          |
134 --|                                            |
135 --+============================================+
136 --
137 FUNCTION CreateHeadersAndLines
138        (p_application_id         IN NUMBER
139        ,p_base_ledger_id         IN NUMBER
140        ,p_target_ledger_id       IN NUMBER
141        ,p_pad_start_date         IN DATE
142        ,p_pad_end_date           IN DATE
143        ,p_primary_ledger_id      IN NUMBER)
144 RETURN BOOLEAN IS
145 l_created                   BOOLEAN:=FALSE;
146 l_event_id                  NUMBER;
147 l_event_date                DATE;
148 l_language                  VARCHAR2(30);
149 l_currency_code             VARCHAR2(30);
150 l_sla_ledger_id             NUMBER;
151 l_log_module                VARCHAR2(240);
152 
153 BEGIN
154 --
155 IF g_log_enabled THEN
156    l_log_module := C_DEFAULT_MODULE||''.CreateHeadersAndLines'';
157 END IF;
158 --
159 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
160    trace
161       (p_msg      => ''BEGIN of CreateHeadersAndLines''
162       ,p_level    => C_LEVEL_PROCEDURE
163       ,p_module   => l_log_module);
164 END IF;
165 
166 l_language         := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
167 l_currency_code    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.currency_code;
168 l_sla_ledger_id    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.sla_ledger_id;
169 
170 --
171 -- initialize array of lines with NULL
172 --
173 xla_ae_lines_pkg.SetNullLine;
174 
175 --
176 -- initialize header extract count -- Bug 4865292
177 --
178 g_hdr_extract_count:= 0;
179 
180 $BODY_MAIN_PROCEDURE$
181 
182  --
183  -- Bug 4865292
184  -- When the number of events and that of header extract do not match,
185  -- set the no header extract flag to indicate there are some issues
186  -- in header extract.
187  --
188  -- Event count context is set in xla_accounting_pkg.unit_processor.
189  -- Build_Message for this error is called in xla_accounting_pkg.post_accounting
190  -- to report it as a general error.
191  --
192  IF  xla_context_pkg.get_event_count_context <> g_hdr_extract_count
193  AND xla_context_pkg.get_event_nohdr_context <> ''Y'' THEN
194 
195      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
196         trace
197           (p_msg      => ''# of extracted headers and events does not match''
198           ,p_level    => C_LEVEL_STATEMENT
199           ,p_module   => l_log_module);
200 
201         trace
202           (p_msg      => ''# of extracted headers: ''
203                          ||g_hdr_extract_count
204           ,p_level    => C_LEVEL_STATEMENT
205           ,p_module   => l_log_module);
206 
207         trace
208           (p_msg      => ''# of events in xla_events_gt: ''
209                          ||xla_context_pkg.get_event_count_context
210           ,p_level    => C_LEVEL_STATEMENT
211           ,p_module   => l_log_module);
212 
213         trace
214           (p_msg      => ''Event No Header Extract Context: ''
215                          ||xla_context_pkg.get_event_nohdr_context
216           ,p_level    => C_LEVEL_STATEMENT
217           ,p_module   => l_log_module);
218 
219      END IF;
220 
221 
222      xla_context_pkg.set_event_nohdr_context
223        (p_nohdr_extract_flag => ''Y''
224        ,p_client_id => sys_context(''USERENV'',''CLIENT_IDENTIFIER''));
225 
226      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
227         trace
228           (p_msg      => ''No Header Extract Flag is set to Y''
229           ,p_level    => C_LEVEL_STATEMENT
230           ,p_module   => l_log_module);
231      END IF;
232 
233  END IF;
234 
235 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
236    trace
237       (p_msg      => ''END of CreateHeadersAndLines''
238       ,p_level    => C_LEVEL_PROCEDURE
239       ,p_module   => l_log_module);
240 END IF;
241 
242 RETURN l_created;
243 EXCEPTION
244 WHEN xla_exceptions_pkg.application_exception THEN
245    RAISE;
246 WHEN OTHERS THEN
247    xla_exceptions_pkg.raise_message
248       (p_location => ''$PACKAGE_NAME$.CreateHeadersAndLines'');
249 END CreateHeadersAndLines;
250 --
251 --
252 ';
253 --
254 --+=============================================================
255 --| Template of ELSE ... END IF; in CreateHeadersAndLines
259 ELSE
256 --+=============================================================
257 --
258 C_END_IF          CONSTANT VARCHAR2(10000) := '
260    --
261    -- Product error No PAD defined for this event type
262    --
263    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
264 
265    xla_accounting_err_pkg.build_message
266             (p_appli_s_name             => ''XLA''
267              ,p_msg_name                => ''XLA_AP_INV_SYST_EVENT_TYPE''
268              ,p_token_1                 => ''EVENT_TYPE_NAME''
269              ,p_value_1                 => xla_ae_journal_entry_pkg.g_cache_event_tl.session_event_type
270              ,p_token_2                 => ''PAD_NAME''
271              ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
272              ,p_token_3                 => ''PAD_OWNER''
273              ,p_value_3                 => xla_lookups_pkg.get_meaning(
274                                             ''XLA_OWNER_TYPE''
275                                             ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
276                                              )
277              ,p_token_4                 => ''PRODUCT_NAME''
278              ,p_value_4                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
279              ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
280              ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
281              ,p_ledger_id               => p_base_ledger_id
282          );
283     --
284    l_created := FALSE;
285    --
286 END IF;
287 --'
288 ;
289 --
290 --+=======================================
291 --| Template of Event Type Function
292 --+=======================================
293 --
294 C_EVENT_TYPE_PROC                 CONSTANT      VARCHAR2(10000):= '
295 ---------------------------------------
296 --
297 -- PRIVATE FUNCTION
298 --         Event$EVENT_ID$
299 --
300 ----------------------------------------
301 --
302 FUNCTION Event$EVENT_ID$
303        (p_application_id         IN NUMBER
304        ,p_base_ledger_id         IN NUMBER
305        ,p_target_ledger_id       IN NUMBER
306        ,p_language               IN VARCHAR2
307        ,p_currency_code          IN VARCHAR2
308        ,p_sla_ledger_id          IN NUMBER
309        ,p_pad_start_date         IN DATE
310        ,p_pad_end_date           IN DATE
311        ,p_primary_ledger_id      IN NUMBER)
312 RETURN BOOLEAN IS
313 --
314 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := ''$event_type_code$'';
315 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := ''$event_class_code$'';
316 
317 l_calculate_acctd_flag   VARCHAR2(1) :=''$calculate_acctd_flag$'';
318 l_calculate_g_l_flag     VARCHAR2(1) :=''$calculate_g_l_flag$'';
319 --
320 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
321 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
322 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
323 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
324 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
325 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
326 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
327 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
328 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
329 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
330 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
331 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
332 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
333 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
334 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
335 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
336 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
337 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
338 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
339 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
340 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
341 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
342 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
343 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
344 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
345 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
346 
347 l_event_id                             NUMBER;
348 l_previous_event_id                    NUMBER;
349 l_first_event_id                       NUMBER;
350 l_last_event_id                        NUMBER;
351 
352 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
353 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
354 --
355 --
356 l_result                    BOOLEAN := TRUE;
357 l_rows                      NUMBER  := 1000;
358 l_event_type_name           VARCHAR2(80) := ''$event_type_name$'';
359 l_event_class_name          VARCHAR2(80) := ''$event_class_name$'';
360 l_description               VARCHAR2(4000);
364 l_log_module                VARCHAR2(240);
361 l_transaction_reversal      NUMBER;
362 l_ae_header_id              NUMBER;
363 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
365 --
366 l_acct_reversal_source      VARCHAR2(30);
367 l_trx_reversal_source       VARCHAR2(30);
368 
369 l_continue_with_lines       BOOLEAN := TRUE;
370 --
371 l_acc_rev_gl_date_source    DATE;                      -- 4262811
372 --
373 type t_array_event_id is table of number index by binary_integer;
374 
375 l_rec_array_event                    t_rec_array_event;
376 l_null_rec_array_event               t_rec_array_event;
377 l_array_ae_header_id                 xla_number_array_type;
378 l_actual_flag                        VARCHAR2(1) := NULL;
379 l_actual_gain_loss_ref               VARCHAR2(30) := ''#####'';
380 l_balance_type_code                  VARCHAR2(1) :=NULL;
381 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
382 
383 --
384 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
385 --
386 $header_types$
387 $line_types$
388 $header_variables$
389 $line_variables$
390 $header_cursor$
391 $line_cursor$
392 --
393 BEGIN
394 IF g_log_enabled THEN
395    l_log_module := C_DEFAULT_MODULE||''.Event$EVENT_ID$'';
396 END IF;
397 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
398    trace
399       (p_msg      => ''BEGIN of Event$EVENT_ID$''
400       ,p_level    => C_LEVEL_PROCEDURE
401       ,p_module   => l_log_module);
402 END IF;
403 
404 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
405    trace
406       (p_msg      => ''p_application_id = ''||p_application_id||
407                      '' - p_base_ledger_id = ''||p_base_ledger_id||
408                      '' - p_target_ledger_id  = ''||p_target_ledger_id||
409                      '' - p_language = ''||p_language||
410                      '' - p_currency_code = ''||p_currency_code||
411                      '' - p_sla_ledger_id = ''||p_sla_ledger_id
412       ,p_level    => C_LEVEL_STATEMENT
413       ,p_module   => l_log_module);
414 END IF;
415 --
416 -- initialze arrays
417 --
418 g_array_event.DELETE;
419 l_rec_array_event := l_null_rec_array_event;
420 --
421 --------------------------------------
422 -- 4262811 Initialze MPA Line Number
423 --------------------------------------
424 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
425 
426 --
427 $event_body$
428 --
429 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
430    trace
431       (p_msg      => ''END of Event$EVENT_ID$''
432       ,p_level    => C_LEVEL_PROCEDURE
433       ,p_module   => l_log_module);
434 END IF;
435 --
436 RETURN l_result;
437 EXCEPTION
438 WHEN xla_exceptions_pkg.application_exception THEN
439    $close_header_cursor$
440    $close_line_cursor$
441    RAISE;
442 
443 WHEN NO_DATA_FOUND THEN
444 
445 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
446 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
447 
448 FOR header_record IN header_cur
449 LOOP
450     l_array_header_events(header_record.event_id) := header_record.event_id;
451 END LOOP;
452 
453 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
454 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
455 
456 fnd_file.put_line(fnd_file.LOG, ''                    '');
457 fnd_file.put_line(fnd_file.LOG, ''***************************************************************************'');
458 fnd_file.put_line(fnd_file.LOG, ''EVENT CLASS CODE = '' || C_EVENT_CLASS_CODE );
459 fnd_file.put_line(fnd_file.LOG, ''The following events are present in the line extract but MISSING in the header extract: '');
460 
461 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
462 LOOP
463 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
464 	fnd_file.put_line(fnd_file.log, ''Event_id = '' || line_record.event_id);
465         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
466 	END IF;
467 END LOOP;
468 
469 fnd_file.put_line(fnd_file.LOG, ''***************************************************************************'');
470 fnd_file.put_line(fnd_file.LOG, ''                    '');
471 
472 
473 xla_exceptions_pkg.raise_message
474       (p_location => ''$package_name$.Event$EVENT_ID$'');
475 
476 
477 WHEN OTHERS THEN
478    xla_exceptions_pkg.raise_message
479       (p_location => ''$package_name$.Event$EVENT_ID$'');
480 END Event$EVENT_ID$;
481 --
482 ';
483 --
484 --+==========================================================================+
485 --|                                                                          |
486 --| Template to close header and line Cursors, if program fails              |
487 --|                                                                          |
488 --+==========================================================================+
489 --
490 -- Close header cursour
491 --
492 C_CLOSE_HEADER_CURSOR                    CONSTANT      VARCHAR2(1000):= '
493 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
494 ';
495 --
496 -- Close line cursor
497 --
498 C_CLOSE_LINE_CURSOR                    CONSTANT      VARCHAR2(1000):= '
502 --+==========================================================================+
499 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
500 ';
501 --
503 --|                                                                          |
504 --| HEADER BODY TEMPLATE, WHEN THIRD PARTY CHANGE OPTION IS NOT USED         |
505 --|                                                                          |
506 --+==========================================================================+
507 --
508 -- when header extract objects exist
509 --
510 C_EVENT_BODY                    CONSTANT      VARCHAR2(10000):= '
511 --
512 OPEN header_cur;
513 --
514 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
515    trace
516    (p_msg      => ''SQL - FETCH header_cur''
517    ,p_level    => C_LEVEL_STATEMENT
518    ,p_module   => l_log_module);
519 END IF;
520 --
521 LOOP
522 FETCH header_cur BULK COLLECT INTO
523         l_array_entity_id
524       , l_array_legal_entity_id
525       , l_array_entity_code
526       , l_array_transaction_num
527       , l_array_event_id
528       , l_array_class_code
529       , l_array_event_type
530       , l_array_event_number
531       , l_array_event_date
532       , l_array_transaction_date
533       , l_array_reference_num_1
534       , l_array_reference_num_2
535       , l_array_reference_num_3
536       , l_array_reference_num_4
537       , l_array_reference_char_1
538       , l_array_reference_char_2
539       , l_array_reference_char_3
540       , l_array_reference_char_4
541       , l_array_reference_date_1
542       , l_array_reference_date_2
543       , l_array_reference_date_3
544       , l_array_reference_date_4
545       , l_array_event_created_by
546       , l_array_budgetary_control_flag $header_var$
547       LIMIT l_rows;
548 --
549 IF (C_LEVEL_EVENT >= g_log_level) THEN
550    trace
551    (p_msg      => ''# rows extracted from header extract objects = ''||TO_CHAR(header_cur%ROWCOUNT)
552    ,p_level    => C_LEVEL_EVENT
553    ,p_module   => l_log_module);
554 END IF;
555 --
556 EXIT WHEN l_array_entity_id.COUNT = 0;
557 
558 -- initialize arrays
559 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
560 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
561 
562 --
563 -- Bug 4458708
564 --
565 XLA_AE_LINES_PKG.g_LineNumber := 0;
566 
567 
568 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
569 g_last_hdr_idx := l_array_event_id.LAST;
570 --
571 -- loop for the headers. Each iteration is for each header extract row
572 -- fetched in header cursor
573 --
574 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
575 
576 --
577 -- set event info as cache for other routines to refer event attributes
578 --
579 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
580    (p_application_id           => p_application_id
581    ,p_primary_ledger_id        => p_primary_ledger_id
582    ,p_base_ledger_id           => p_base_ledger_id
583    ,p_target_ledger_id         => p_target_ledger_id
584    ,p_entity_id                => l_array_entity_id(hdr_idx)
585    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
586    ,p_entity_code              => l_array_entity_code(hdr_idx)
587    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
588    ,p_event_id                 => l_array_event_id(hdr_idx)
589    ,p_event_class_code         => l_array_class_code(hdr_idx)
590    ,p_event_type_code          => l_array_event_type(hdr_idx)
591    ,p_event_number             => l_array_event_number(hdr_idx)
592    ,p_event_date               => l_array_event_date(hdr_idx)
593    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
594    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
595    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
596    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
597    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
598    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
599    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
600    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
601    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
602    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
603    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
604    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
605    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
606    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
607    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
608 
609 --
610 -- set the status of entry to C_VALID (0)
611 --
612 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
613 
614 --
615 -- initialize a row for ae header
616 --
617 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
618 
619 l_event_id := l_array_event_id(hdr_idx);
620 
621 --
622 -- storing the hdr_idx for event. May be used by line cursor.
623 --
624 g_array_event(l_event_id).array_value_num(''header_index'') := hdr_idx;
625 
626 --
627 -- store sources from header extract. This can be improved to
628 -- store only those sources from header extract that may be used in lines
632 --
629 --
630 $cache_header_sources$
631 
633 -- initilaize the status of ae headers for diffrent balance types
634 -- the status is initialised to C_NOT_CREATED (2)
635 --
636 --g_array_event(l_event_id).array_value_num(''actual_je_status'') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
637 --g_array_event(l_event_id).array_value_num(''budget_je_status'') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
638 --g_array_event(l_event_id).array_value_num(''encumbrance_je_status'') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
639 
640 --
641 -- call api to validate and store accounting attributes for header
642 --
643 $hdr_accounting_attributes$
644 
645 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
646 
647 XLA_AE_HEADER_PKG.SetJeCategoryName;
648 
649 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
650 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
651 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
652 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
653 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
654 
655 $call_header_description$
656 $call_hdr_analytic_criteria$
657 
658 --
659 --accounting attribute enhancement, bug 3612931
660 --
661 l_trx_reversal_source := SUBSTR($trx_reversal_source$, 1,30);
662 
663 IF NVL(l_trx_reversal_source, ''N'') NOT IN (''N'',''Y'') THEN
664    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
665 
666    xla_accounting_err_pkg.build_message
667       (p_appli_s_name            => ''XLA''
668       ,p_msg_name                => ''XLA_AP_INVALID_HDR_ATTR''
669       ,p_token_1                 => ''ACCT_ATTR_NAME''
670       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName(''TRX_ACCT_REVERSAL_OPTION'')
671       ,p_token_2                 => ''PRODUCT_NAME''
672       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
673       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
674       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
675       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
676 
677 ELSIF NVL(l_trx_reversal_source, ''N'') = ''Y'' THEN
678    --
679    -- following sets the accounting attributes needed to reverse
680    -- accounting for a distributeion
681    --
682    xla_ae_lines_pkg.SetTrxReversalAttrs
683       (p_event_id              => l_event_id
684       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
685       ,p_trx_reversal_source   => l_trx_reversal_source);
686 
687 END IF;
688 
689 
690 ----------------------------------------------------------------
691 -- 4262811 -  update the header statuses to invalid in need be
692 ----------------------------------------------------------------
693 --
694 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
695 
696 $accrual_reversal_body$
697 ----------------------------------------------------------------
698 
699 --
700 -- this ends the header loop iteration for one bulk fetch
701 --
702 END LOOP;
703 
704 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
705 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
706 
707 --
708 -- insert dummy rows into lines gt table that were created due to
709 -- transaction reversals
710 --
711 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
712    l_result := XLA_AE_LINES_PKG.InsertLines;
713 END IF;
714 
715 --
716 -- reset the temp_line_num for each set of events fetched from header
717 -- cursor rather than doing it for each new event in line cursor
718 -- Bug 3939231
719 --
720 xla_ae_lines_pkg.g_temp_line_num := 0;
721 
722 
723 $lines_body$
724 
725 --
726 -- insert headers into xla_ae_headers_gt table
727 --
728 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
729 
730 -- insert into errors table here.
731 
732 END LOOP;
733 
734 --
735 -- 4865292
736 --
737 -- Compare g_hdr_extract_count with event count in
738 -- CreateHeadersAndLines.
739 --
740 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
741 
742 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
743    trace (p_msg     => ''# rows extracted from header extract objects ''
744                     || '' (running total): ''
745                     || g_hdr_extract_count
746          ,p_level   => C_LEVEL_STATEMENT
747          ,p_module  => l_log_module);
748 END IF;
749 
750 CLOSE header_cur;
751 --
752 ';  -- C_EVENT_BODY
753 
754 --
755 --
756 
757 --
758 --+==========================================================================+
759 --|                                                                          |
760 --| HEADER BODY TEMPLATE, WHEN THIRD PARTY CHANGE OPTION IS USED             |
761 --|                                                                          |
762 --+==========================================================================+
763 --
764 --
768   IF $third_party_change$ = ''Y'' THEN
765 C_THIRD_PARTY_CHANGE_BODY                    CONSTANT      VARCHAR2(10000):= '
766 --
767   --
769   --
770      xla_ae_header_pkg.change_third_party;
771   --
772   ELSIF NVL($third_party_change$,''N'') <> ''N'' THEN
773   --
774     xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
775              --
776     xla_accounting_err_pkg.build_message
777                            (p_appli_s_name            => ''XLA''
778                            ,p_msg_name                => ''XLA_AP_THIRD_PARTY_OPTION''
779                            ,p_token_1                 => ''PRODUCT_NAME''
780                            ,p_value_1                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
781                            ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
782                            ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
783                            ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
784            );
785   END IF;
786   --
787 ';
788 --
789 --+==========================================================================+
790 --|                                                                          |
791 --| LINES BODY TEMPLATE, WHEN ACCOUNTING REVERSAL OPTION IS NOT USED         |
792 --|                                                                          |
793 --+==========================================================================+
794 --
795 -- Extract line Objects defined
796 --
797 C_BODY_LINES           CONSTANT      VARCHAR2(10000):= '
798 --
799 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
800 --
801 --
802 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
803 
804       trace
805          (p_msg      => ''SQL - FETCH line_cur''
806          ,p_level    => C_LEVEL_STATEMENT
807          ,p_module   => l_log_module);
808 
809 END IF;
810 --
811 --
812 LOOP
813   --
814   FETCH line_cur BULK COLLECT INTO
815         l_array_entity_id
816       , l_array_legal_entity_id
817       , l_array_entity_code
818       , l_array_transaction_num
819       , l_array_event_id
820       , l_array_class_code
821       , l_array_event_type
822       , l_array_event_number
823       , l_array_event_date
824       , l_array_transaction_date
825       , l_array_reference_num_1
826       , l_array_reference_num_2
827       , l_array_reference_num_3
828       , l_array_reference_num_4
829       , l_array_reference_char_1
830       , l_array_reference_char_2
831       , l_array_reference_char_3
832       , l_array_reference_char_4
833       , l_array_reference_date_1
834       , l_array_reference_date_2
835       , l_array_reference_date_3
836       , l_array_reference_date_4
837       , l_array_event_created_by
838       , l_array_budgetary_control_flag
839 $line_var$
840       LIMIT l_rows;
841 
842   --
843   IF (C_LEVEL_EVENT >= g_log_level) THEN
844             trace
845                (p_msg      => ''# rows extracted from line extract objects = ''||TO_CHAR(line_cur%ROWCOUNT)
846                ,p_level    => C_LEVEL_EVENT
847                ,p_module   => l_log_module);
848   END IF;
849   --
850   EXIT WHEN l_array_entity_id.count = 0;
851 
852   XLA_AE_LINES_PKG.g_rec_lines := null;
853 
854 --
855 -- Bug 4458708
856 --
857 XLA_AE_LINES_PKG.g_LineNumber := 0;
858 --
859 --
860 
861 FOR Idx IN 1..l_array_event_id.count LOOP
862    --
863    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
864    --
865    l_event_id := l_array_event_id(idx);  -- 5648433
866 
867    --
868    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
869    --
870 
871    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
872              (g_array_event(l_event_id).array_value_num(''header_index''))
873          ,''N''
874          ) <> ''Y''
875    THEN
876       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
877          trace
878             (p_msg      => ''Trancaction revesal option is not Y ''
879             ,p_level    => C_LEVEL_STATEMENT
880             ,p_module   => l_log_module);
881       END IF;
882 
883 --
884 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
885 --
886 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
887 --
888 -- set event info as cache for other routines to refer event attributes
889 --
890 
891 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
892    l_previous_event_id := l_event_id;
893 
894    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
895       (p_application_id           => p_application_id
896       ,p_primary_ledger_id        => p_primary_ledger_id
897       ,p_base_ledger_id           => p_base_ledger_id
898       ,p_target_ledger_id         => p_target_ledger_id
899       ,p_entity_id                => l_array_entity_id(Idx)
900       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
901       ,p_entity_code              => l_array_entity_code(Idx)
902       ,p_transaction_num          => l_array_transaction_num(Idx)
906       ,p_event_number             => l_array_event_number(Idx)
903       ,p_event_id                 => l_array_event_id(Idx)
904       ,p_event_class_code         => l_array_class_code(Idx)
905       ,p_event_type_code          => l_array_event_type(Idx)
907       ,p_event_date               => l_array_event_date(Idx)
908       ,p_transaction_date         => l_array_transaction_date(Idx)
909       ,p_reference_num_1          => l_array_reference_num_1(Idx)
910       ,p_reference_num_2          => l_array_reference_num_2(Idx)
911       ,p_reference_num_3          => l_array_reference_num_3(Idx)
912       ,p_reference_num_4          => l_array_reference_num_4(Idx)
913       ,p_reference_char_1         => l_array_reference_char_1(Idx)
914       ,p_reference_char_2         => l_array_reference_char_2(Idx)
915       ,p_reference_char_3         => l_array_reference_char_3(Idx)
916       ,p_reference_char_4         => l_array_reference_char_4(Idx)
917       ,p_reference_date_1         => l_array_reference_date_1(Idx)
918       ,p_reference_date_2         => l_array_reference_date_2(Idx)
919       ,p_reference_date_3         => l_array_reference_date_3(Idx)
920       ,p_reference_date_4         => l_array_reference_date_4(Idx)
921       ,p_event_created_by         => l_array_event_created_by(Idx)
922       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
923        --
924 END IF;
925 
926 
927 
928 --
929 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
930 
931 l_acct_reversal_source := SUBSTR($acct_reversal_source$, 1,30);
932 
933 IF l_continue_with_lines THEN
934    IF NVL(l_acct_reversal_source, ''N'') NOT IN (''N'',''Y'',''B'') THEN
935       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
936 
937       xla_accounting_err_pkg.build_message
938          (p_appli_s_name            => ''XLA''
939          ,p_msg_name                => ''XLA_AP_INVALID_REVERSAL_OPTION''
940          ,p_token_1                 => ''LINE_NUMBER''
941          ,p_value_1                 => l_array_extract_line_num(Idx)
942          ,p_token_2                 => ''PRODUCT_NAME''
943          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
944          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
945          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
946          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
947 
948    ELSIF NVL(l_acct_reversal_source, ''N'') IN (''Y'',''B'') THEN
949       --
950       -- following sets the accounting attributes needed to reverse
951       -- accounting for a distributeion
952       --
953 
954       --
955       -- 5217187
956       --
957       l_rec_rev_acct_attrs.array_acct_attr_code(1):= ''GL_DATE'';
958       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
959                                        g_array_event(l_event_id).array_value_num(''header_index''));
960       --
961       --
962 
963 $acct_reversal_code$
964 
965       xla_ae_lines_pkg.SetAcctReversalAttrs
966          (p_event_id             => l_event_id
967          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
968          ,p_calculate_acctd_flag => l_calculate_acctd_flag
969          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
970    END IF;
971 
972    IF NVL(l_acct_reversal_source, ''N'') IN (''N'',''B'') THEN
973       $call_alts$
974       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
975       -- or secondary ledger that has different currency with primary
976       -- or alc that is calculated by sla
977       IF (((l_calculate_g_l_flag = ''Y'' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> ''ALC'') or
978             (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code in (''ALC'', ''SECONDARY'') AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.calculate_amts_flag=''Y''))
979 
980 --      IF((l_calculate_g_l_flag=''Y'' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
981 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
982           AND (l_actual_flag = ''A'')) THEN
983         XLA_AE_LINES_PKG.CreateGainOrLossLines(
984           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
985          ,p_application_id   => p_application_id
986          ,p_amb_context_code => ''$amb_context_code$''
987          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
988          ,p_event_class_code => C_EVENT_CLASS_CODE
989          ,p_event_type_code  => C_EVENT_TYPE_CODE
990          $gain_loss_account_params$
991          ,p_actual_flag      => l_actual_flag
992          ,p_enc_flag         => null
993          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
994          ,p_enc_g_l_ref      => null
995          );
996       END IF;
997    END IF;
998 END IF;
999 
1000    ELSE
1001       --
1002       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
1003       --
1004       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1005          trace
1006             (p_msg      => ''Trancaction revesal option is Y''
1007             ,p_level    => C_LEVEL_STATEMENT
1008             ,p_module   => l_log_module);
1009       END IF;
1010    END IF;
1011 
1012 END LOOP;
1013 l_result := XLA_AE_LINES_PKG.InsertLines ;
1014 end loop;
1015 close line_cur;
1016 ';
1017 
1018 
1019 --+=============================================================================+
1023 --|                                                                             |
1020 --|                                                                             |
1021 --| 4262811                                                                     |
1022 --| Template for the accrual reversal code in the EventType/EventClass_xxx API. |
1024 --+=============================================================================+
1025 --
1026 C_ACC_REV_BODY         CONSTANT      VARCHAR2(10000) := '
1027 --
1028 -- Generate the accrual reversal headers
1029 --
1030 IF NVL(l_trx_reversal_source, ''N'') = ''N'' THEN
1031 
1032 $if_cond$
1033 
1034 -- indicate that the accrual entry has a reversal entry
1035 XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag(hdr_idx) := ''Y'';
1036 
1037 --
1038 -- initialize a row for ae header
1039 --
1040 g_last_hdr_idx := g_last_hdr_idx + 1;
1041 XLA_AE_HEADER_PKG.CopyHeaderInfo (p_parent_hdr_idx => hdr_idx,
1042                                   p_hdr_idx        => g_last_hdr_idx) ;
1043 XLA_AE_HEADER_PKG.g_rec_header_new.array_header_num      (g_last_hdr_idx) := 1;
1044 XLA_AE_HEADER_PKG.g_rec_header_new.array_parent_header_id(g_last_hdr_idx) :=
1045                XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx);
1046 
1047 --
1048 -- record the index for the reversal entry, it will be used by the journal
1049 -- line creation
1050 --
1051 g_array_event(l_event_id).array_value_num(''acc_rev_header_index'') := g_last_hdr_idx;
1052 
1053 --
1054 -- Populate the GL Date and override the GL date defined in the
1055 -- SetHdrAcctAttrs if necessary
1056 --
1057 $accrual_reversal_body2$
1058 
1059 --
1060 -- Update the header status
1061 --
1062 XLA_AE_JOURNAL_ENTRY_PKG.updateJournalEntryStatus (p_hdr_idx => g_last_hdr_idx);
1063 
1064 $end_if$
1065 
1066 END IF;
1067 
1068 ';
1069 
1070 
1071 
1072 
1073 --+=============================================================================+
1074 --|                                                                             |
1075 --| 4262811                                                                     |
1076 --| Template to populate accrual reversal GL date accounting attribut in the    |
1077 --| EventType/EventClass_xxx API.                                               |
1078 --|                                                                             |
1079 --+=============================================================================+
1080 --
1081 C_HDR_ACCT_BODY     CONSTANT      VARCHAR2(10000) := '
1082 ------------------------------------------------------------
1083 -- Accrual Reversal : to get date for Standard Source (NONE)
1084 ------------------------------------------------------------
1085 l_acc_rev_gl_date_source := $acc_rev_gl_date_source$;
1086 
1087 ';
1088 
1089 --
1090 ------------------------------------------------------------------------------
1091 --
1092 --
1093 --
1094 --
1095 --
1096 --       Transaction Objects Diagnostics Constants/Templates
1097 --
1098 --
1099 --
1100 --
1101 --
1102 ------------------------------------------------------------------------------
1103 --
1104 --
1105 --
1106 C_INSERT_SOURCES_PROC                 CONSTANT      CLOB:= '
1107 ---------------------------------------
1108 --
1109 -- PRIVATE PROCEDURE
1110 --         insert_sources_$EVENT_INDEX$
1111 --
1112 ----------------------------------------
1113 --
1114 PROCEDURE insert_sources_$EVENT_INDEX$(
1115                                 p_target_ledger_id       IN NUMBER
1116                               , p_language               IN VARCHAR2
1117                               , p_sla_ledger_id          IN NUMBER
1118                               , p_pad_start_date         IN DATE
1119                               , p_pad_end_date           IN DATE
1120                          )
1121 IS
1122 
1123 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := ''$event_type_code$'';
1124 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := ''$event_class_code$'';
1125 p_apps_owner                   VARCHAR2(30);
1126 l_log_module                   VARCHAR2(240);
1127 BEGIN
1128 IF g_log_enabled THEN
1129       l_log_module := C_DEFAULT_MODULE||''.insert_sources_$EVENT_INDEX$'';
1130 END IF;
1131 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1132 
1133       trace
1134          (p_msg      => ''BEGIN of insert_sources_$EVENT_INDEX$''
1135          ,p_level    => C_LEVEL_PROCEDURE
1136          ,p_module   => l_log_module);
1137 
1138 END IF;
1139 
1140 -- select APPS owner
1141 SELECT oracle_username
1142   INTO p_apps_owner
1143   FROM fnd_oracle_userid
1144  WHERE read_only_flag = ''U''
1145 ;
1146 
1147 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1148       trace
1149          (p_msg      => ''p_target_ledger_id = ''||p_target_ledger_id||
1150                         '' - p_language = ''||p_language||
1151                         '' - p_sla_ledger_id  = ''||p_sla_ledger_id ||
1152                         '' - p_pad_start_date = ''||TO_CHAR(p_pad_start_date)||
1153                         '' - p_pad_end_date = ''||TO_CHAR(p_pad_end_date)||
1154                         '' - p_apps_owner = ''||TO_CHAR(p_apps_owner)
1155          ,p_level    => C_LEVEL_STATEMENT
1156          ,p_module   => l_log_module);
1157 END IF;
1158 
1159 $insert_header_sources$
1160 
1161 $insert_line_sources$
1162 
1166          ,p_level    => C_LEVEL_PROCEDURE
1163 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1164       trace
1165          (p_msg      => ''END of insert_sources_$EVENT_INDEX$''
1167          ,p_module   => l_log_module);
1168 END IF;
1169 EXCEPTION
1170   WHEN xla_exceptions_pkg.application_exception THEN
1171       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1172             trace
1173                (p_msg      => ''ERROR: XLA_CMP_COMPILER_ERROR = ''||sqlerrm
1174                ,p_level    => C_LEVEL_EXCEPTION
1175                ,p_module   => l_log_module);
1176       END IF;
1177       RAISE;
1178   WHEN OTHERS THEN
1179       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1180             trace
1181                (p_msg      => ''ERROR: XLA_CMP_COMPILER_ERROR = ''||sqlerrm
1182                ,p_level    => C_LEVEL_EXCEPTION
1183                ,p_module   => l_log_module);
1184        END IF;
1185        xla_exceptions_pkg.raise_message
1186            (p_location => ''$package_name$.insert_sources_$EVENT_INDEX$'');
1187 END insert_sources_$EVENT_INDEX$;
1188 --
1189 ';
1190 --
1191 --
1192 --+==========================================================================+
1193 --|                                                                          |
1194 --| Private global constant or variable declarations                         |
1195 --|                                                                          |
1196 --+==========================================================================+
1197 --
1198 g_package_name            VARCHAR2(30);
1199 g_product_rule_code       VARCHAR2(30);
1200 g_product_rule_type_code  VARCHAR2(1);
1201 g_product_rule_version    VARCHAR2(30);
1202 g_product_rule_name       VARCHAR2(80);
1203 
1204 g_chr_newline      CONSTANT VARCHAR2(10):= xla_environment_pkg.g_chr_newline;
1205 --=============================================================================
1206 --
1207 --
1208 --
1209 --
1210 --
1211 --
1212 --
1213 --
1214 --
1215 --                               FND_LOG trace
1216 --
1217 --
1218 --
1219 --
1220 --
1221 --
1222 --
1223 --
1224 --
1225 --
1226 --
1227 --=============================================================================
1228 
1229 --
1230 --=============================================================================
1231 --               *********** Local Trace Routine **********
1232 --=============================================================================
1233 
1234 C_LEVEL_STATEMENT     CONSTANT NUMBER := FND_LOG.LEVEL_STATEMENT;
1235 C_LEVEL_PROCEDURE     CONSTANT NUMBER := FND_LOG.LEVEL_PROCEDURE;
1236 C_LEVEL_EVENT         CONSTANT NUMBER := FND_LOG.LEVEL_EVENT;
1237 C_LEVEL_EXCEPTION     CONSTANT NUMBER := FND_LOG.LEVEL_EXCEPTION;
1238 C_LEVEL_ERROR         CONSTANT NUMBER := FND_LOG.LEVEL_ERROR;
1239 C_LEVEL_UNEXPECTED    CONSTANT NUMBER := FND_LOG.LEVEL_UNEXPECTED;
1240 
1241 C_LEVEL_LOG_DISABLED  CONSTANT NUMBER := 99;
1242 C_DEFAULT_MODULE      CONSTANT VARCHAR2(240) := 'xla.plsql.XLA_CMP_EVENT_TYPE_PKG';
1243 
1244 g_log_level           NUMBER;
1245 g_log_enabled         BOOLEAN;
1246 
1247 PROCEDURE trace
1248            (p_msg                        IN VARCHAR2
1249            ,p_level                      IN NUMBER
1250            ,p_module                     IN VARCHAR2)
1251 IS
1252 BEGIN
1253 IF (p_msg IS NULL AND p_level >= g_log_level) THEN
1254           fnd_log.message(p_level, p_module);
1255 ELSIF p_level >= g_log_level THEN
1256           fnd_log.string(p_level, p_module, p_msg);
1257 END IF;
1258 
1259 EXCEPTION
1260        WHEN xla_exceptions_pkg.application_exception THEN
1261           RAISE;
1262        WHEN OTHERS THEN
1263           xla_exceptions_pkg.raise_message
1264              (p_location   => 'XLA_CMP_EVENT_TYPE_PKG.trace');
1265 END trace;
1266 
1267 --+==========================================================================+
1268 --|                                                                          |
1269 --|                                                                          |
1270 --|                                                                          |
1271 --|                                                                          |
1272 --|                                                                          |
1273 --|                                                                          |
1274 --|                                                                          |
1275 --|                                                                          |
1276 --|                                                                          |
1277 --|                                                                          |
1278 --|                                                                          |
1279 --|                                                                          |
1280 --|                                                                          |
1281 --|                                                                          |
1282 --|                                                                          |
1283 --|                                                                          |
1284 --|                                                                          |
1285 --|                                                                          |
1286 --|                                                                          |
1290 
1287 --|                                                                          |
1288 --+==========================================================================+
1289 
1291 /*------------------------------------------------------------+
1292 |                                                             |
1293 |  Private procedure                                          |
1294 |                                                             |
1295 |    GetEventClassEventType                                   |
1296 |                                                             |
1297 |  Retrieves the event classes and event types defined in AAD |
1298 |                                                             |
1299 +------------------------------------------------------------*/
1300 
1301 PROCEDURE GetEventClassEventType(
1302                     p_application_id                  IN NUMBER
1303                   , p_amb_context_code                IN VARCHAR2
1304                   , p_product_rule_code               IN VARCHAR2
1305                   , p_product_rule_type_code          IN VARCHAR2
1306                   , p_array_entity                   OUT NOCOPY xla_cmp_source_pkg.t_array_VL30
1307                   , p_array_event_class              OUT NOCOPY xla_cmp_source_pkg.t_array_VL30
1308                   , p_array_event_type               OUT NOCOPY xla_cmp_source_pkg.t_array_VL30
1309                   , p_array_event_class_acctd_flag   OUT NOCOPY xla_cmp_source_pkg.t_array_VL1
1310                   , p_array_event_class_g_l_flag     OUT NOCOPY xla_cmp_source_pkg.t_array_VL1
1311 )
1312 IS
1313 --
1314 -- get event_type belong entered product rule
1315 --
1316 CURSOR event_type_cur
1317 IS
1318 SELECT  DISTINCT
1319           xpah.event_type_code
1320         , xpah.event_class_code
1321         , xpah.entity_code
1322         , xeca.calculate_acctd_amts_flag
1323         , xeca.calculate_g_l_amts_flag
1324   FROM  xla_prod_acct_headers     xpah
1325       , xla_event_types_b         xetb
1326       , xla_event_class_attrs     xeca
1327  WHERE  xpah.product_rule_code        = p_product_rule_code
1328    AND  xpah.product_rule_type_code   = p_product_rule_type_code
1329    AND  xpah.application_id           = p_application_id
1330    AND  xpah.amb_context_code         = p_amb_context_code
1331    AND  xpah.application_id           = xetb.application_id
1332    AND  xpah.entity_code              = xetb.entity_code
1333    AND  xpah.event_class_code         = xetb.event_class_code
1334    AND  (xetb.event_type_code         = xpah.event_type_code
1335         OR
1336          xetb.event_type_code         = xpah.event_class_code||'_ALL'
1337         )
1338    AND  xetb.accounting_flag          = xpah.accounting_required_flag
1339    AND  xpah.accounting_required_flag = 'Y'
1340    AND  xpah.validation_status_code   = 'R'   -- Running
1341    AND  xetb.enabled_flag             = 'Y'
1342    AND  xeca.application_id           = xetb.application_id
1343    AND  xeca.event_class_code         = xetb.event_class_code
1344    AND  xeca.entity_code              = xetb.entity_code
1345 ORDER BY xpah.event_type_code
1346 ;
1347 --
1348 CURSOR event_type_bc_cur
1349 IS
1350 SELECT  DISTINCT
1351           xpah.event_type_code
1352         , xpah.event_class_code
1353         , xpah.entity_code
1354         , xeca.calculate_acctd_amts_flag
1355         , xeca.calculate_g_l_amts_flag
1356   FROM  xla_prod_acct_headers     xpah
1357       , xla_event_types_b         xetb
1358       , xla_event_class_attrs     xeca
1359       , xla_aad_line_defn_assgns  xald
1360       , xla_line_definitions_b     xld
1361  WHERE  xpah.product_rule_code        = p_product_rule_code
1362    AND  xpah.product_rule_type_code   = p_product_rule_type_code
1363    AND  xpah.application_id           = p_application_id
1364    AND  xpah.amb_context_code         = p_amb_context_code
1365    AND  xpah.application_id           = xetb.application_id
1366    AND  xpah.entity_code              = xetb.entity_code
1367    AND  xpah.event_class_code         = xetb.event_class_code
1368    AND  (xetb.event_type_code         = xpah.event_type_code
1369         OR
1370          xetb.event_type_code         = xpah.event_class_code||'_ALL'
1371         )
1372    AND  xetb.accounting_flag          = xpah.accounting_required_flag
1373    AND  xpah.accounting_required_flag = 'Y'
1374    AND  xpah.validation_status_code   = 'R'   -- Running
1375    AND  xetb.enabled_flag             = 'Y'
1376    AND  xeca.application_id           = xetb.application_id
1377    AND  xeca.event_class_code         = xetb.event_class_code
1378    AND  xeca.entity_code              = xetb.entity_code
1379    AND  xald.application_id          = xpah.application_id
1380    AND  xald.amb_context_code        = xpah.amb_context_code
1381    AND  xald.event_class_code        = xpah.event_class_code
1382    AND  xald.event_type_code         = xpah.event_type_code
1383    AND  xald.product_rule_type_code = xpah.product_rule_type_code
1384    AND  xald.product_rule_code       = xpah.product_rule_code
1385    AND xald.application_id         = xld.application_id
1386    AND xald.amb_context_code       = xld.amb_context_code
1387    AND xald.event_class_code       = xld.event_class_code
1388    AND xald.event_type_code        = xld.event_type_code
1389    AND xald.line_definition_owner_code = xld.line_definition_owner_code
1390    AND xald.line_definition_code  = xld.line_definition_code
1391    AND xld.budgetary_control_flag = 'Y'
1392  ORDER BY xpah.event_type_code;
1393 --
1394 l_array_event_type                xla_cmp_source_pkg.t_array_VL30;
1398 l_array_event_class_g_l_flag      xla_cmp_source_pkg.t_array_VL1;
1395 l_array_event_class               xla_cmp_source_pkg.t_array_VL30;
1396 l_array_entity                    xla_cmp_source_pkg.t_array_VL30;
1397 l_array_event_class_acctd_flag    xla_cmp_source_pkg.t_array_VL1;
1399 l_log_module                      VARCHAR2(240);
1400 --
1401 BEGIN
1402 
1403 IF g_log_enabled THEN
1404       l_log_module := C_DEFAULT_MODULE||'.GetEventClassEventType';
1405 END IF;
1406 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1407       trace
1408          (p_msg      => 'BEGIN of GetEventClassEventType'
1409          ,p_level    => C_LEVEL_PROCEDURE
1410          ,p_module   => l_log_module);
1411 END IF;
1412 
1413 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1414 
1415       trace
1416          (p_msg      => 'SQL - Select from xla_prod_acct_headers '
1417          ,p_level    => C_LEVEL_STATEMENT
1418          ,p_module   => l_log_module);
1419 
1420 END IF;
1421 --
1422 IF (XLA_CMP_PAD_PKG.g_bc_pkg_flag = 'N') THEN
1423    OPEN  event_type_cur;
1424    FETCH event_type_cur BULK COLLECT INTO   l_array_event_type
1425                                           , l_array_event_class
1426                                           , l_array_entity
1427                                           , l_array_event_class_acctd_flag
1428                                           , l_array_event_class_g_l_flag
1429                                           ;
1430    CLOSE event_type_cur;
1431 ELSE
1432    OPEN  event_type_bc_cur;
1433    FETCH event_type_bc_cur BULK COLLECT INTO l_array_event_type
1434                                            , l_array_event_class
1435                                            , l_array_entity
1436                                            , l_array_event_class_acctd_flag
1437                                            , l_array_event_class_g_l_flag
1438                                            ;
1439    CLOSE event_type_bc_cur;
1440 END IF;
1441 --
1442 p_array_event_type       := l_array_event_type;
1443 p_array_event_class      := l_array_event_class;
1444 p_array_entity           := l_array_entity;
1445 p_array_event_class_acctd_flag := l_array_event_class_acctd_flag;
1446 p_array_event_class_g_l_flag   := l_array_event_class_g_l_flag;
1447 --
1448 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1449 
1450       trace
1451          (p_msg      => 'END of GetEventClassEventType'
1452          ,p_level    => C_LEVEL_PROCEDURE
1453          ,p_module   => l_log_module);
1454 
1455 END IF;
1456 --
1457 EXCEPTION
1458   WHEN xla_exceptions_pkg.application_exception   THEN
1459        IF event_type_cur%ISOPEN THEN CLOSE event_type_cur; END IF;
1460        IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1461             trace
1462                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
1463                ,p_level    => C_LEVEL_EXCEPTION
1464                ,p_module   => l_log_module);
1465        END IF;
1466        RAISE;
1467   WHEN OTHERS    THEN
1468        IF event_type_cur%ISOPEN THEN CLOSE event_type_cur; END IF;
1469        xla_exceptions_pkg.raise_message
1470             (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GetEventClassEventType');
1471 END GetEventClassEventType;
1472 
1473 /*------------------------------------------------------------+
1474 |                                                             |
1475 |  Private procedure                                          |
1476 |                                                             |
1477 |    GetNoAccountEventTypes                                   |
1478 |                                                             |
1479 |  Retrieves the non accounting event types defined in AAD    |
1480 |                                                             |
1481 +------------------------------------------------------------*/
1482 
1483 PROCEDURE GetNoAccountEventTypes(
1484                     p_application_id          IN NUMBER
1485                   , p_amb_context_code        IN VARCHAR2
1486                   , p_product_rule_code       IN VARCHAR2
1487                   , p_product_rule_type_code  IN VARCHAR2
1488                   , p_array_event_type        OUT NOCOPY xla_cmp_source_pkg.t_array_VL30
1489 )
1490 IS
1491 --
1492 -- get event_type belong entered product rule
1493 --
1494 CURSOR event_type_cur
1495 IS
1496 SELECT  DISTINCT
1497           xetb.event_type_code
1498   FROM  xla_prod_acct_headers xpah
1499       , xla_event_types_b     xetb
1500  WHERE  xpah.product_rule_code         = p_product_rule_code
1501    AND  xpah.product_rule_type_code    = p_product_rule_type_code
1502    AND  xpah.application_id            = p_application_id
1503    AND  xpah.amb_context_code          = p_amb_context_code
1504    AND  xpah.application_id            = xetb.application_id
1505    AND  xpah.entity_code               = xetb.entity_code
1506    AND  xpah.event_class_code          = xetb.event_class_code
1507    AND  xetb.event_type_code           = DECODE( xpah.event_type_code
1508                                                , xpah.event_class_code ||'_ALL',xetb.event_type_code
1509                                                , xpah.event_type_code
1510                                                )
1511    AND  xetb.event_type_code           <> xetb.event_class_code || '_ALL'
1512    AND  xetb.accounting_flag           = 'Y'
1513    AND  xetb.enabled_flag              = 'Y'
1514    AND  (xpah.accounting_required_flag = 'N'
1515          OR
1519 l_array_event_type                xla_cmp_source_pkg.t_array_VL30;
1516          xpah.validation_status_code   <> 'R')  -- not Running
1517   ;
1518 --
1520 l_log_module                      VARCHAR2(240);
1521 --
1522 BEGIN
1523 IF g_log_enabled THEN
1524       l_log_module := C_DEFAULT_MODULE||'.GetNoAccountEventTypes';
1525 END IF;
1526 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1527       trace
1528          (p_msg      => 'BEGIN of GetNoAccountEventTypes'
1529          ,p_level    => C_LEVEL_PROCEDURE
1530          ,p_module   => l_log_module);
1531 END IF;
1532 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1533       trace
1534          (p_msg      => 'SQL - SELECT from xla_prod_acct_headers'
1535          ,p_level    => C_LEVEL_STATEMENT
1536          ,p_module   => l_log_module);
1537 END IF;
1538 
1539 OPEN  event_type_cur;
1540 
1541 FETCH event_type_cur BULK COLLECT INTO   l_array_event_type
1542                                        ;
1543 CLOSE event_type_cur;
1544 
1545 p_array_event_type       := l_array_event_type;
1546 
1547 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1548       trace
1549          (p_msg      => 'END of GetNoAccountEventTypes ='||p_array_event_type.COUNT
1550          ,p_level    => C_LEVEL_PROCEDURE
1551          ,p_module   => l_log_module);
1552 END IF;
1553 EXCEPTION
1554   WHEN xla_exceptions_pkg.application_exception   THEN
1555        IF event_type_cur%ISOPEN THEN CLOSE event_type_cur; END IF;
1556        IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1557             trace
1558                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
1559                ,p_level    => C_LEVEL_EXCEPTION
1560                ,p_module   => l_log_module);
1561         END IF;
1562        RAISE;
1563   WHEN OTHERS    THEN
1564        IF event_type_cur%ISOPEN THEN CLOSE event_type_cur; END IF;
1565        xla_exceptions_pkg.raise_message
1566             (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GetNoAccountEventTypes');
1567 END GetNoAccountEventTypes;
1568 
1569 /*------------------------------------------------------------+
1570 |                                                             |
1571 |  Private procedure                                          |
1572 |                                                             |
1573 |    GetEventType                                             |
1574 |                                                             |
1575 |  Retrieves the event types belong entered event class       |
1576 |                                                             |
1577 +------------------------------------------------------------*/
1578 
1579 PROCEDURE GetEventType(
1580                     p_application_id          IN NUMBER
1581                   , p_entity_code             IN VARCHAR2
1582                   , p_event_class_code        IN VARCHAR2
1583                   , p_array_event_type        OUT NOCOPY xla_cmp_source_pkg.t_array_VL30
1584 )
1585 IS
1586 l_array_event_type                xla_cmp_source_pkg.t_array_VL30;
1587 
1588 CURSOR event_type_cur
1589 IS
1590 SELECT  DISTINCT
1591         xetb.event_type_code
1592   FROM  xla_event_types_b xetb
1593  WHERE  xetb.entity_code              = p_entity_code
1594    AND  xetb.event_class_code         = p_event_class_code
1595    AND  xetb.application_id           = p_application_id
1596    AND  xetb.accounting_flag          = 'Y'
1597    AND  xetb.enabled_flag             = 'Y'
1598    AND  xetb.event_type_code         <>  xetb.event_class_code || '_ALL'
1599  ORDER BY xetb.event_type_code
1600    ;
1601 l_log_module                      VARCHAR2(240);
1602 BEGIN
1603 IF g_log_enabled THEN
1604       l_log_module := C_DEFAULT_MODULE||'.GetEventType';
1605 END IF;
1606 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1607       trace
1608          (p_msg      => 'BEGIN of GetEventType'
1609          ,p_level    => C_LEVEL_PROCEDURE
1610          ,p_module   => l_log_module);
1611 END IF;
1612 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1613       trace
1614          (p_msg      => 'SQL - SELECT from xla_event_types_b'
1615          ,p_level    => C_LEVEL_STATEMENT
1616          ,p_module   => l_log_module);
1617 END IF;
1618 
1619 OPEN  event_type_cur;
1620 
1621 FETCH event_type_cur BULK COLLECT INTO l_array_event_type;
1622 
1623 CLOSE event_type_cur;
1624 
1625 p_array_event_type := l_array_event_type;
1626 
1627 
1628 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1629       trace
1630          (p_msg      => 'END of GetEventType = '||p_array_event_type.COUNT
1631          ,p_level    => C_LEVEL_PROCEDURE
1632          ,p_module   => l_log_module);
1633 
1634 END IF;
1635 EXCEPTION
1636   WHEN xla_exceptions_pkg.application_exception   THEN
1637        IF event_type_cur%ISOPEN THEN CLOSE event_type_cur; END IF;
1638        IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1639             trace
1640                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
1641                ,p_level    => C_LEVEL_EXCEPTION
1642                ,p_module   => l_log_module);
1643        END IF;
1644        RAISE;
1645   WHEN OTHERS    THEN
1646        IF event_type_cur%ISOPEN THEN CLOSE event_type_cur; END IF;
1647        xla_exceptions_pkg.raise_message
1648             (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GetEventType');
1649 END GetEventType;
1650 
1651 /*------------------------------------------------------------+
1655 |    GetEventTypeName                                         |
1652 |                                                             |
1653 |  Private function                                           |
1654 |                                                             |
1656 |                                                             |
1657 |  Retrieves the event type name                              |
1658 |                                                             |
1659 +------------------------------------------------------------*/
1660 
1661 FUNCTION GetEventTypeName(
1662   p_application_id            IN NUMBER
1663 , p_entity_code               IN VARCHAR2
1664 , p_event_class_code          IN VARCHAR2
1665 , p_event_type_code           IN VARCHAR2
1666 )
1667 RETURN VARCHAR2
1668 IS
1669 l_name                   VARCHAR2(80);
1670 l_log_module                      VARCHAR2(240);
1671 BEGIN
1672 IF g_log_enabled THEN
1673       l_log_module := C_DEFAULT_MODULE||'.GetEventTypeName';
1674 END IF;
1675 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1676       trace
1677          (p_msg      => 'BEGIN of GetEventTypeName'
1678          ,p_level    => C_LEVEL_PROCEDURE
1679          ,p_module   => l_log_module);
1680 
1681 END IF;
1682 
1683 BEGIN
1684    SELECT  REPLACE(xect.name , '''','''''')
1685      INTO  l_name
1686      FROM  xla_event_types_tl  xect
1687     WHERE  xect.application_id     = p_application_id
1688       AND  xect.entity_code        = p_entity_code
1689       AND  xect.event_class_code   = p_event_class_code
1690       AND  xect.event_type_code    = p_event_type_code
1691       AND  xect.language           = USERENV('LANG')
1692    ;
1693 EXCEPTION
1694 WHEN NO_DATA_FOUND OR TOO_MANY_ROWS THEN
1695    l_name := NULL;
1696 END;
1697 
1698 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1699       trace
1700          (p_msg      => 'END of GetEventTypeName'
1701          ,p_level    => C_LEVEL_PROCEDURE
1702          ,p_module   => l_log_module);
1703 END IF;
1704 RETURN l_name;
1705 EXCEPTION
1706  WHEN xla_exceptions_pkg.application_exception   THEN
1707         RETURN NULL;
1708  WHEN OTHERS    THEN
1709       xla_exceptions_pkg.raise_message
1710          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GetEventTypeName ');
1711 END GetEventTypeName;
1712 
1713 /*------------------------------------------------------------+
1714 |                                                             |
1715 |  Private function                                           |
1716 |                                                             |
1717 |    GetEntityName                                            |
1718 |                                                             |
1719 |  Retrieves the entity name                                  |
1720 |                                                             |
1721 +------------------------------------------------------------*/
1722 
1723 FUNCTION GetEntityName( p_entity         IN VARCHAR2
1724                       , p_application_id IN NUMBER
1725                     )
1726 RETURN VARCHAR2
1727 IS
1728 l_name                            VARCHAR2(90);
1729 l_log_module                      VARCHAR2(240);
1730 BEGIN
1731 IF g_log_enabled THEN
1732       l_log_module := C_DEFAULT_MODULE||'.GetEntityName';
1733 END IF;
1734 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1735       trace
1736          (p_msg      => 'BEGIN of GetEntityName'
1737          ,p_level    => C_LEVEL_PROCEDURE
1738          ,p_module   => l_log_module);
1739 END IF;
1740 
1741 BEGIN
1742   SELECT REPLACE(xett.name , '''','''''')
1743     INTO l_name
1744     FROM xla_entity_types_tl             xett
1745    WHERE  xett.application_id           = p_application_id
1746      AND  xett.entity_code              = p_entity
1747      AND  xett.LANGUAGE                 = USERENV('LANG')
1748  ;
1749 EXCEPTION
1750 WHEN NO_DATA_FOUND OR TOO_MANY_ROWS THEN
1751    l_name := NULL;
1752 END;
1753 
1754 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1755       trace
1756          (p_msg      => 'END of GetEntityName'
1757          ,p_level    => C_LEVEL_PROCEDURE
1758          ,p_module   => l_log_module);
1759 END IF;
1760 RETURN l_name;
1761 EXCEPTION
1762  WHEN xla_exceptions_pkg.application_exception   THEN
1763         RETURN NULL;
1764  WHEN OTHERS    THEN
1765       xla_exceptions_pkg.raise_message
1766          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GetEntityName ');
1767 END GetEntityName;
1768 
1769 /*------------------------------------------------------------+
1770 |                                                             |
1771 |  Private function                                           |
1772 |                                                             |
1773 |    GetEventClassName                                        |
1774 |                                                             |
1775 |  Retrieves the event class name                             |
1776 |                                                             |
1777 +------------------------------------------------------------*/
1778 
1779 FUNCTION GetEventClassName(
1780   p_application_id            IN NUMBER
1781 , p_entity_code               IN VARCHAR2
1782 , p_event_class_code          IN VARCHAR2
1783 )
1784 RETURN VARCHAR2
1785 IS
1786 l_name                            VARCHAR2(80);
1787 l_log_module                      VARCHAR2(240);
1788 BEGIN
1789 IF g_log_enabled THEN
1793       trace
1790       l_log_module := C_DEFAULT_MODULE||'.GetEventClassName';
1791 END IF;
1792 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1794          (p_msg      => 'BEGIN of GetEventClassName'
1795          ,p_level    => C_LEVEL_PROCEDURE
1796          ,p_module   => l_log_module);
1797 END IF;
1798 
1799 BEGIN
1800   SELECT  REPLACE(xect.name , '''','''''')
1801     INTO  l_name
1802     FROM  xla_event_classes_tl  xect
1803    WHERE  xect.application_id     = p_application_id
1804      AND  xect.entity_code        = p_entity_code
1805      AND  xect.event_class_code   = p_event_class_code
1806      AND  xect.language           = USERENV('LANG')
1807    ;
1808 EXCEPTION
1809 WHEN NO_DATA_FOUND OR TOO_MANY_ROWS THEN
1810    l_name := NULL;
1811 END;
1812 
1813 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1814       trace
1815          (p_msg      => 'END of GetEventClassName'
1816          ,p_level    => C_LEVEL_PROCEDURE
1817          ,p_module   => l_log_module);
1818 
1819 END IF;
1820 RETURN l_name;
1821 EXCEPTION
1822  WHEN xla_exceptions_pkg.application_exception   THEN
1823         RETURN NULL;
1824  WHEN OTHERS    THEN
1825       xla_exceptions_pkg.raise_message
1826          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GetEventClassName ');
1827 END GetEventClassName;
1828 --
1829 --+==========================================================================+
1830 --|                                                                          |
1831 --| COLLECT THE NEEDED SOURCES                                               |
1832 --|                                                                          |
1833 --|                                                                          |
1834 --|                                                                          |
1835 --|                                                                          |
1836 --|                                                                          |
1837 --|                                                                          |
1838 --|                                                                          |
1839 --|                                                                          |
1840 --+==========================================================================+
1841 --
1842 --
1843 --+==========================================================================+
1844 --|                                                                          |
1845 --| PRIVATE procedure                                                        |
1846 --|                                                                          |
1847 --|  Add third_party_chage_option and accounting_reversal_option to the list |
1848 --|  of sources to extract from the Product tables/views                     |
1849 --|                                                                          |
1850 --+==========================================================================+
1851 --
1852 --
1853 --+==========================================================================+
1854 --|                                                                          |
1855 --| PRIVATE function                                                         |
1856 --|                                                                          |
1857 --|      Check if Option Flag party_change_option                            |
1858 --|      or accounting_reversal_option is defined in                         |
1859 --|      Transaction Objects                                                 |
1860 --|                                                                          |
1861 --+==========================================================================+
1862 --
1863 FUNCTION IsOptionFlagInEventExtract (
1864     p_source_option                IN VARCHAR2
1865   , p_array_source_code            IN xla_cmp_source_pkg.t_array_VL30
1866 )
1867 RETURN NUMBER
1868 IS
1869 
1870 l_IsSourceExists             NUMBER;
1871 l_array_source_code          xla_cmp_source_pkg.t_array_VL30;
1872 l_log_module                 VARCHAR2(240);
1873 
1874 BEGIN
1875 IF g_log_enabled THEN
1876       l_log_module := C_DEFAULT_MODULE||'.IsOptionFlagInEventExtract';
1877 END IF;
1878 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1879    trace
1880       (p_msg      => 'BEGIN of IsOptionFlagInEventExtract'
1881       ,p_level    => C_LEVEL_PROCEDURE
1882       ,p_module   => l_log_module);
1883 END IF;
1884 
1885 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1886       trace
1887          (p_msg      => 'p_source_option = '||p_source_option
1888          ,p_level    => C_LEVEL_STATEMENT
1889          ,p_module   => l_log_module);
1890       trace
1891          (p_msg      => '# of sources = '||p_array_source_code.COUNT
1892          ,p_level    => C_LEVEL_STATEMENT
1893          ,p_module   => l_log_module);
1894 END IF;
1895 
1896 l_array_source_code := p_array_source_code;
1897 l_IsSourceExists    := NULL;
1898 
1899 IF l_array_source_code.COUNT > 0 THEN
1900 
1901 FOR Idx IN l_array_source_code.FIRST .. l_array_source_code.LAST LOOP
1902 
1903   IF l_array_source_code.EXISTS(Idx) AND l_array_source_code(Idx) = p_source_option
1904   THEN
1905      l_IsSourceExists := Idx;
1906   END IF;
1907 
1908 END LOOP;
1909 
1910 END IF;
1911 
1912 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1913    trace
1914       (p_msg      => 'return value, Source Index  = '||l_IsSourceExists
1915       ,p_level    => C_LEVEL_STATEMENT
1916       ,p_module   => l_log_module);
1917 END IF;
1921          ,p_level    => C_LEVEL_PROCEDURE
1918 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1919       trace
1920          (p_msg      => 'END of IsOptionFlagInEventExtract'
1922          ,p_module   => l_log_module);
1923 END IF;
1924 RETURN l_IsSourceExists;
1925 EXCEPTION
1926    WHEN xla_exceptions_pkg.application_exception   THEN
1927         RETURN NULL;
1928    WHEN OTHERS    THEN
1929       xla_exceptions_pkg.raise_message
1930          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.IsOptionFlagInEventExtract');
1931 END IsOptionFlagInEventExtract;
1932 --
1933 --+==========================================================================+
1934 --|                                                                          |
1935 --| PRIVATE Procedure                                                        |
1936 --|                                                                          |
1937 --|      Get Index and level (Header or line) of Option Flags                |
1938 --|      party_change_option and accounting_reversal_option                  |
1939 --|                                                                          |
1940 --+==========================================================================+
1941 --
1942 PROCEDURE GetIndexOfOptionFlags (
1943   p_array_hdr_acctg_source           IN xla_cmp_source_pkg.t_array_VL30
1944 , p_array_hdr_acct_attr_source       IN xla_cmp_source_pkg.t_array_int
1945 , p_array_line_acctg_source          IN xla_cmp_source_pkg.t_array_VL30
1946 , p_array_line_acct_attr_source      IN xla_cmp_source_pkg.t_array_int
1947 , p_ThirdPartyIdx                    OUT NOCOPY NUMBER
1948 , p_AcctReversalIdx                  OUT NOCOPY NUMBER
1949 , p_TrxReversalIdx                   OUT NOCOPY NUMBER
1950 )
1951 IS
1952 --
1953 l_log_module                 VARCHAR2(240);
1954 BEGIN
1955 --
1956 IF g_log_enabled THEN
1957       l_log_module := C_DEFAULT_MODULE||'.GetIndexOfOptionFlags';
1958 END IF;
1959 --
1960 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1961       trace
1962          (p_msg      => 'BEGIN of GetIndexOfOptionFlags'
1963          ,p_level    => C_LEVEL_PROCEDURE
1964          ,p_module   => l_log_module);
1965 END IF;
1966 --
1967 p_ThirdPartyIdx            := NULL;
1968 p_AcctReversalIdx          := NULL;
1969 p_TrxReversalIdx           := NULL;
1970 --
1971 p_ThirdPartyIdx      := IsOptionFlagInEventExtract(
1972                               p_source_option          =>'PARTY_CHANGE_OPTION'
1973                             , p_array_source_code      => p_array_hdr_acctg_source
1974                             );
1975 --
1976 --
1977 p_AcctReversalIdx := IsOptionFlagInEventExtract(
1978                               p_source_option          =>'ACCOUNTING_REVERSAL_OPTION'
1979                             , p_array_source_code      => p_array_line_acctg_source
1980                             );
1981 --
1982 --
1983 p_TrxReversalIdx := IsOptionFlagInEventExtract(
1984                               p_source_option          =>'TRX_ACCT_REVERSAL_OPTION'
1985                             , p_array_source_code      => p_array_hdr_acctg_source
1986                             );
1987 --
1988 --
1989 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1990       trace
1991          (p_msg      => 'END of GetIndexOfOptionFlags'
1992          ,p_level    => C_LEVEL_PROCEDURE
1993          ,p_module   => l_log_module);
1994 END IF;
1995 --
1996 EXCEPTION
1997    WHEN xla_exceptions_pkg.application_exception   THEN
1998       p_ThirdPartyIdx            := NULL;
1999       p_AcctReversalIdx          := NULL;
2000       p_TrxReversalIdx           := NULL;
2001    WHEN OTHERS    THEN
2002       xla_exceptions_pkg.raise_message
2003          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GetIndexOfOptionFlags');
2004 END GetIndexOfOptionFlags;
2005 
2006 /*--------------------------------------------------------------------+
2007 |                                                                     |
2008 |  Private procedure                                                  |
2009 |                                                                     |
2010 |    GetHeaderAcctgSources                                            |
2011 |                                                                     |
2012 |  Get sources assigned to header accounting attributes.              |
2013 |                                                                     |
2014 +--------------------------------------------------------------------*/
2015 
2016 PROCEDURE GetHeaderAcctgSources (
2017     p_entity                       IN VARCHAR2
2018   , p_event_class                  IN VARCHAR2
2019   , p_event_type                   IN VARCHAR2
2020   , p_application_id               IN NUMBER
2021   , p_amb_context_code             IN VARCHAR2
2022   , p_product_rule_type_code       IN VARCHAR2
2023   , p_product_rule_code            IN VARCHAR2
2024   --
2025   , p_array_evt_source_index       IN OUT NOCOPY xla_cmp_source_pkg.t_array_ByInt
2026   , p_array_hdr_acctg_source       OUT NOCOPY xla_cmp_source_pkg.t_array_VL30
2027   , p_array_hdr_acctg_source_type  OUT NOCOPY xla_cmp_source_pkg.t_array_VL1
2028   , p_array_hdr_acct_attr_source   OUT NOCOPY xla_cmp_source_pkg.t_array_int
2029   --
2030   , p_rec_sources                  IN OUT NOCOPY xla_cmp_source_pkg.t_rec_sources
2031 )
2032 IS
2033 --
2034 --
2035 CURSOR source_cur
2036 IS
2037 SELECT      eca.accounting_attribute_code
2038           , eca.source_application_id
2039           , eca.source_type_code
2040           , eca.source_code
2044      , xla_acct_attributes_b      xasb
2041           , DECODE(nvl(xes.level_code, 'H'),'H','H','L')
2042   FROM xla_evt_class_acct_attrs   eca
2043      , xla_event_sources          xes
2045      , xla_sources_b              xsb
2046 WHERE  eca.application_id             = p_application_id
2047    AND eca.event_class_code           = p_event_class
2048    AND xasb.accounting_attribute_code = eca.accounting_attribute_code
2049    AND xasb.assignment_level_code     = 'EVT_CLASS_ONLY'
2050    AND xes.application_id(+)          = p_application_id
2051    AND xes.entity_code(+)             = p_entity
2052    AND xes.event_class_code(+)        = p_event_class
2053    AND xes.source_application_id(+)   = eca.source_application_id
2054    AND xes.source_type_code(+)        = eca.source_type_code
2055    AND xes.source_code(+)             = eca.source_code
2056    AND xasb.journal_entry_level_code  = 'H'
2057    AND xes.active_flag(+)             = 'Y'
2058    AND xsb.application_id             = eca.source_application_id
2059    AND xsb.source_type_code           = eca.source_type_code
2060    AND xsb.source_code                = eca.source_code
2061 UNION
2062 SELECT      aha.accounting_attribute_code
2063           , aha.source_application_id
2064           , aha.source_type_code
2065           , aha.source_code
2066           , DECODE(xes.level_code,'H','H','L')
2067   FROM xla_aad_hdr_acct_attrs   aha
2068      , xla_event_sources        xes
2069      , xla_acct_attributes_b    xasb
2070      , xla_sources_b   xsb
2071 WHERE  aha.application_id             = p_application_id
2072    AND aha.amb_context_code           = p_amb_context_code
2073    AND aha.product_rule_type_code     = p_product_rule_type_code
2074    AND aha.product_rule_code          = p_product_rule_code
2075    AND aha.event_class_code           = p_event_class
2076    AND aha.event_type_code            = p_event_type
2077    AND xasb.accounting_attribute_code = aha.accounting_attribute_code
2078    AND xasb.assignment_level_code     IN ('AAD_ONLY','EVT_CLASS_AAD')
2079    AND xes.application_id(+)          = p_application_id
2080    AND xes.entity_code(+)             = p_entity
2081    AND xes.event_class_code(+)        = p_event_class
2082    AND xes.source_application_id(+)   = aha.source_application_id
2083    AND xes.source_type_code(+)        = aha.source_type_code
2084    AND xes.source_code(+)             = aha.source_code
2085    AND xes.active_flag (+)            = 'Y'
2086    AND xsb.application_id             = aha.source_application_id
2087    AND xsb.source_type_code           = aha.source_type_code
2088    AND xsb.source_code                = aha.source_code
2089 ;
2090 --
2091 --
2092 l_SourceIdx                     BINARY_INTEGER;
2093 l_accounting_source             xla_cmp_source_pkg.t_array_VL30;
2094 l_accounting_source_type        xla_cmp_source_pkg.t_array_VL1;
2095 l_source_application_id         xla_cmp_source_pkg.t_array_Num;
2096 l_source_type_code              xla_cmp_source_pkg.t_array_VL1;
2097 l_source_code                   xla_cmp_source_pkg.t_array_VL30;
2098 l_log_module                    VARCHAR2(240);
2099 --
2100 BEGIN
2101 --
2102 IF g_log_enabled THEN
2103       l_log_module := C_DEFAULT_MODULE||'.GetHeaderAcctgSources';
2104 END IF;
2105 --
2106 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2107 
2108       trace
2109          (p_msg      => 'BEGIN of GetHeaderAcctgSources'
2110          ,p_level    => C_LEVEL_PROCEDURE
2111          ,p_module   => l_log_module);
2112 
2113 END IF;
2114 
2115 IF (C_LEVEL_STATEMENT>= g_log_level) THEN
2116       trace
2117          (p_msg      => 'entity:'||p_entity||
2118                         ' - class:'||p_event_class||
2119                         ' - type:'||p_event_type||
2120                         ' - amb_context_code:'||p_amb_context_code||
2121                         ' - rule_type_code:'||p_product_rule_type_code||
2122                         ' - rule_code:'||p_product_rule_code
2123          ,p_level    => C_LEVEL_STATEMENT
2124          ,p_module   => l_log_module);
2125 END IF;
2126 
2127 OPEN source_cur;
2128 
2129 FETCH source_cur BULK COLLECT INTO l_accounting_source
2130                                  , l_source_application_id
2131                                  , l_source_type_code
2132                                  , l_source_code
2133                                  , l_accounting_source_type
2134                                  ;
2135 
2136 CLOSE source_cur;
2137 --
2138 --
2139 IF l_accounting_source.EXISTS(NVL(l_accounting_source.FIRST,1)) THEN
2140 
2141 FOR Idx IN l_accounting_source.FIRST .. l_accounting_source.LAST LOOP
2142 
2143  IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2144       trace
2145          (p_msg      => 'Accouting sources  = '||l_accounting_source(Idx)||
2146                         ' - Source Code  = '||l_source_code(Idx)
2147          ,p_level    => C_LEVEL_STATEMENT
2148          ,p_module   => l_log_module);
2149  END IF;
2150  IF l_source_code.EXISTS(Idx) AND l_source_code(Idx) IS NOT NULL THEN
2151 
2152   l_SourceIdx := xla_cmp_source_pkg.StackSource(
2153                 p_source_code                => l_source_code(Idx)
2154               , p_source_type_code           => l_source_type_code(Idx)
2155               , p_source_application_id      => l_source_application_id(Idx)
2156               , p_array_source_index         => p_array_evt_source_index
2157               , p_rec_sources                => p_rec_sources
2158               );
2159 
2163 
2160   p_array_hdr_acctg_source(Idx)      := l_accounting_source(Idx);
2161   p_array_hdr_acctg_source_type(Idx) := l_accounting_source_type(Idx);
2162   p_array_hdr_acct_attr_source(Idx)  := l_SourceIdx;
2164  END IF;
2165 END LOOP;
2166 END IF;
2167 
2168 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2169       trace
2170          (p_msg      => 'END of GetHeaderAcctgSources ='||l_accounting_source.COUNT
2171          ,p_level    => C_LEVEL_PROCEDURE
2172          ,p_module   => l_log_module);
2173 END IF;
2174 EXCEPTION
2175    WHEN xla_exceptions_pkg.application_exception   THEN
2176         IF source_cur%ISOPEN THEN CLOSE source_cur; END IF;
2177         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2178             trace
2179                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
2180                ,p_level    => C_LEVEL_EXCEPTION
2181                ,p_module   => l_log_module);
2182         END IF;
2183         RAISE;
2184    WHEN OTHERS    THEN
2185       IF source_cur%ISOPEN THEN CLOSE source_cur; END IF;
2186       xla_exceptions_pkg.raise_message
2187          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GetHeaderAcctgSources ');
2188 END GetHeaderAcctgSources;
2189 
2190 /*--------------------------------------------------------------------+
2191 |                                                                     |
2192 |  Private procedure                                                  |
2193 |                                                                     |
2194 |    GetLineAcctgSources                                              |
2195 |                                                                     |
2196 |  Get sources assigned to Reversal line accounting attributes.       |
2197 |                                                                     |
2198 +--------------------------------------------------------------------*/
2199 
2200 PROCEDURE GetLineAcctgSources (
2201     p_entity                       IN VARCHAR2
2202   , p_event_class                  IN VARCHAR2
2203   , p_application_id               IN NUMBER
2204   --
2205   , p_array_evt_source_index       IN OUT NOCOPY xla_cmp_source_pkg.t_array_ByInt
2206   , p_array_line_acctg_source      OUT NOCOPY xla_cmp_source_pkg.t_array_VL30
2207   , p_array_line_acctg_source_type OUT NOCOPY xla_cmp_source_pkg.t_array_VL1
2208   , p_array_line_acct_attr_source  OUT NOCOPY xla_cmp_source_pkg.t_array_int
2209   --
2210   , p_rec_sources                  IN OUT NOCOPY xla_cmp_source_pkg.t_rec_sources
2211 )
2212 IS
2213 --
2214 CURSOR source_cur
2215 IS
2216 SELECT      eca.accounting_attribute_code
2217           , eca.source_application_id
2218           , eca.source_type_code
2219           , eca.source_code
2220           , DECODE(nvl(xes.level_code, 'H'),'H','H','L')
2221   FROM xla_evt_class_acct_attrs   eca
2222      , xla_event_sources      xes
2223      , xla_acct_attributes_b  xasb
2224      , xla_sources_b   xsb
2225 WHERE  eca.application_id             = p_application_id
2226    AND eca.event_class_code           = p_event_class
2227    AND xasb.accounting_attribute_code = eca.accounting_attribute_code
2228    AND xasb.assignment_level_code     = 'EVT_CLASS_ONLY'
2229    AND xes.application_id (+)         = p_application_id
2230    AND xes.entity_code (+)            = p_entity
2231    AND xes.event_class_code(+)        = p_event_class
2232    AND xes.source_application_id(+)   = eca.source_application_id
2233    AND xes.source_type_code(+)        = eca.source_type_code
2234    AND xes.source_code(+)             = eca.source_code
2235    AND xasb.journal_entry_level_code  in ('L', 'C')
2236    AND xes.active_flag(+)             = 'Y'
2237    AND xsb.application_id             = eca.source_application_id
2238    AND xsb.source_type_code           = eca.source_type_code
2239    AND xsb.source_code                = eca.source_code
2240 ;
2241 --
2242 l_SourceIdx                      BINARY_INTEGER;
2243 l_accounting_source              xla_cmp_source_pkg.t_array_VL30;
2244 l_accounting_source_type         xla_cmp_source_pkg.t_array_VL1;
2245 l_source_application_id          xla_cmp_source_pkg.t_array_Num;
2246 l_source_type_code               xla_cmp_source_pkg.t_array_VL1;
2247 l_source_code                    xla_cmp_source_pkg.t_array_VL30;
2248 l_number                         NUMBER;
2249 l_log_module                     VARCHAR2(240);
2250 --
2251 BEGIN
2252 IF g_log_enabled THEN
2253       l_log_module := C_DEFAULT_MODULE||'.GetLineAcctgSources';
2254 END IF;
2255 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2256       trace
2257          (p_msg      => 'BEGIN of GetLineAcctgSources'
2258          ,p_level    => C_LEVEL_PROCEDURE
2259          ,p_module   => l_log_module);
2260 END IF;
2261 
2262 l_number  := 0;
2263 --
2264 -- check if the accounting reversal option exists
2265 --
2266 SELECT  count(xes.accounting_attribute_code)
2267   INTO  l_number
2268   FROM  xla_evt_class_acct_attrs xes
2269  WHERE  xes.application_id        =  p_application_id
2270 --   AND  xes.entity_code           =  p_entity
2271    AND xes.event_class_code       =  p_event_class
2272 --   AND xes.active_flag            = 'Y'
2273    AND xes.accounting_attribute_code = 'ACCOUNTING_REVERSAL_OPTION'
2274    ;
2275 
2276 IF l_number > 0 THEN
2277 --
2278 OPEN source_cur;
2279 --
2280 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2281       trace
2282          (p_msg      => 'SQL - SELECT from xla_event_sources and xla_acctg_sources_b'
2283          ,p_level    => C_LEVEL_STATEMENT
2287 FETCH source_cur BULK COLLECT INTO l_accounting_source
2284          ,p_module   => l_log_module);
2285 END IF;
2286 
2288                                  , l_source_application_id
2289                                  , l_source_type_code
2290                                  , l_source_code
2291                                  , l_accounting_source_type
2292                                  ;
2293 
2294 CLOSE source_cur;
2295 
2296 IF l_accounting_source.COUNT > 0 THEN
2297 
2298 FOR Idx IN l_accounting_source.FIRST .. l_accounting_source.LAST LOOP
2299 
2300    IF l_source_code.EXISTS(Idx) AND l_source_code(Idx) IS NOT NULL THEN
2301 
2302         l_SourceIdx := xla_cmp_source_pkg.StackSource (
2303                 p_source_code            => l_source_code(Idx)
2304               , p_source_type_code       => l_source_type_code(Idx)
2305               , p_source_application_id  => l_source_application_id(Idx)
2306               , p_array_source_index     => p_array_evt_source_index
2307               , p_rec_sources            => p_rec_sources
2308               );
2309 
2310         p_array_line_acctg_source(Idx)      := l_accounting_source(Idx);
2311         p_array_line_acctg_source_type(Idx) := l_accounting_source_type(Idx);
2312         p_array_line_acct_attr_source(Idx)  := l_SourceIdx;
2313 
2314     END IF;
2315 
2316 END LOOP;
2317 END IF;
2318 
2319 END IF;
2320 
2321 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2322       trace
2323          (p_msg      => 'END of GetLineAcctgSources = '||l_accounting_source.COUNT
2324          ,p_level    => C_LEVEL_PROCEDURE
2325          ,p_module   => l_log_module);
2326 END IF;
2327 EXCEPTION
2328    WHEN xla_exceptions_pkg.application_exception   THEN
2329         IF source_cur%ISOPEN THEN CLOSE source_cur; END IF;
2330         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2331             trace
2332                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
2333                ,p_level    => C_LEVEL_EXCEPTION
2334                ,p_module   => l_log_module);
2335         END IF;
2336         RAISE;
2337    WHEN OTHERS    THEN
2338       IF source_cur%ISOPEN THEN CLOSE source_cur; END IF;
2339       xla_exceptions_pkg.raise_message
2340          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GetLineAcctgSources ');
2341 END GetLineAcctgSources;
2342 
2343 
2344 /*--------------------------------------------------------------------+
2345 |                                                                     |
2346 |  Private procedure                                                  |
2347 |                                                                     |
2348 |    GetSourcesDefinedInHeader                                        |
2349 |                                                                     |
2350 |  Get header sources defined in header description.                  |
2351 |                                                                     |
2352 +--------------------------------------------------------------------*/
2353 
2354 PROCEDURE GetSourcesDefinedInHeader(
2355     p_entity                       IN VARCHAR2
2356   , p_event_class                  IN VARCHAR2
2357   , p_event_type                   IN VARCHAR2
2358   , p_application_id               IN NUMBER
2359   , p_product_rule_code            IN VARCHAR2
2360   , p_product_rule_type_code       IN VARCHAR2
2361   , p_amb_context_code             IN VARCHAR2
2362   , p_array_evt_source_index       IN OUT NOCOPY xla_cmp_source_pkg.t_array_ByInt
2363   , p_hdr_description_index        IN OUT NOCOPY BINARY_INTEGER
2364   , p_rec_aad_objects              IN OUT NOCOPY xla_cmp_source_pkg.t_rec_aad_objects
2365 )
2366 IS
2367 --
2368 l_description_type_code      VARCHAR2(1);
2369 l_description_code           VARCHAR2(30);
2370 l_ObjectIndex                BINARY_INTEGER;
2371 l_log_module                 VARCHAR2(240);
2372 
2373 BEGIN
2374 
2375 IF g_log_enabled THEN
2376       l_log_module := C_DEFAULT_MODULE||'.GetSourcesDefinedInHeader';
2377 END IF;
2378 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2379       trace
2380          (p_msg      => 'BEGIN of GetSourcesDefinedInHeader'
2381          ,p_level    => C_LEVEL_PROCEDURE
2382          ,p_module   => l_log_module);
2383 END IF;
2384 
2385 SELECT   xpah.description_code
2386        , xpah.description_type_code
2387     INTO l_description_code
2388        , l_description_type_code
2389     FROM xla_prod_acct_headers xpah
2390    WHERE xpah.product_rule_type_code    = p_product_rule_type_code
2391      AND xpah.product_rule_code         = p_product_rule_code
2392      AND xpah.entity_code               = p_entity
2393      AND xpah.event_class_code          = p_event_class
2394      AND xpah.event_type_code           = p_event_type
2395      AND xpah.application_id            = p_application_id
2396      AND xpah.amb_context_code          = p_amb_context_code
2397      AND xpah.accounting_required_flag  = 'Y'
2398 ;
2399 
2400 l_ObjectIndex :=xla_cmp_source_pkg.GetAADObjectPosition(
2401                p_object                   => xla_cmp_source_pkg.C_DESC
2402              , p_object_code              => l_description_code
2403              , p_object_type_code         => l_description_type_code
2404              , p_application_id           => p_application_id
2405              , p_event_class_code         => NULL
2406              , p_event_type_code          => NULL
2407              , p_rec_aad_objects          => p_rec_aad_objects
2411 
2408               );
2409 
2410 IF l_ObjectIndex IS NOT NULL THEN
2412         xla_cmp_source_pkg.GetSourcesInAADObject(
2413                              p_object              => xla_cmp_source_pkg.C_DESC
2414                            , p_object_code         => l_description_code
2415                            , p_object_type_code    => l_description_type_code
2416                            , p_application_id      => p_application_id
2417                            , p_event_class_code    => NULL
2418                            , p_event_type_code     => NULL
2419                            , p_array_source_Index  => p_array_evt_source_index
2420                            , p_rec_aad_objects     => p_rec_aad_objects
2421                           );
2422 
2423 END IF;
2424 
2425 p_hdr_description_index := l_ObjectIndex;
2426 
2427 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2428       trace
2429          (p_msg      => 'END of GetSourcesDefinedInHeader = '||p_hdr_description_index
2430          ,p_level    => C_LEVEL_PROCEDURE
2431          ,p_module   => l_log_module);
2432 END IF;
2433 EXCEPTION
2434    WHEN NO_DATA_FOUND THEN
2435     IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2436       trace
2437          (p_msg      => 'END of GetSourcesDefinedInHeader (no header description)'
2438          ,p_level    => C_LEVEL_PROCEDURE
2439          ,p_module   => l_log_module);
2440      END IF;
2441      p_hdr_description_index := NULL;
2442    WHEN TOO_MANY_ROWS THEN
2443     IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2444             trace
2445                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = two_many_rows '||sqlerrm
2446                ,p_level    => C_LEVEL_EXCEPTION
2447                ,p_module   => l_log_module);
2448         END IF;
2449      RAISE;
2450    WHEN xla_exceptions_pkg.application_exception   THEN
2451        IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2452             trace
2453                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
2454                ,p_level    => C_LEVEL_EXCEPTION
2455                ,p_module   => l_log_module);
2456         END IF;
2457         RAISE;
2458    WHEN OTHERS    THEN
2459       xla_exceptions_pkg.raise_message
2460          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GetSourcesDefinedInHeader');
2461 END GetSourcesDefinedInHeader;
2462 
2463 /*--------------------------------------------------------------------+
2464 |                                                                     |
2465 |  Private procedure                                                  |
2466 |                                                                     |
2467 |    GetSourcesDefinedInAcctgLine                                     |
2468 |                                                                     |
2469 |  Get header sources defined in Jorunal Line Definitions.            |
2470 |                                                                     |
2471 +--------------------------------------------------------------------*/
2472 
2473 PROCEDURE GetSourcesDefinedInAcctgLine (
2474     p_entity                       IN VARCHAR2
2475   , p_event_class                  IN VARCHAR2
2476   , p_event_type                   IN VARCHAR2
2477   , p_application_id               IN NUMBER
2478   , p_product_rule_code            IN VARCHAR2
2479   , p_product_rule_type_code       IN VARCHAR2
2480   , p_amb_context_code             IN VARCHAR2
2481   , p_array_evt_source_index       IN OUT NOCOPY xla_cmp_source_pkg.t_array_ByInt
2482   , p_array_alt_index              IN OUT NOCOPY xla_cmp_source_pkg.t_array_ByInt
2483   , p_rec_aad_objects              IN OUT NOCOPY xla_cmp_source_pkg.t_rec_aad_objects
2484 )
2485 IS
2486 --
2487 CURSOR alt_cur
2488 IS
2489  SELECT  DISTINCT
2490          xldj.accounting_line_code
2491        , xldj.accounting_line_type_code
2492        , xldj.line_definition_code
2493        , xldj.line_definition_owner_code
2494     FROM xla_aad_line_defn_assgns xald
2495        , xla_line_defn_jlt_assgns xldj
2496        , xla_prod_acct_headers    xpah
2497        , xla_line_definitions_b   xld
2498    WHERE xldj.line_definition_owner_code = xald.line_definition_owner_code
2499      AND xldj.line_definition_code       = xald.line_definition_code
2500      AND xldj.event_class_code           = xald.event_class_code
2501      AND xldj.event_type_code            = xald.event_type_code
2502      AND xldj.application_id             = xald.application_id
2503      AND xldj.amb_context_code           = xald.amb_context_code
2504      AND xldj.active_flag                = 'Y'
2505      --
2506      AND xld.line_definition_owner_code = xald.line_definition_owner_code
2507      AND xld.line_definition_code       = xald.line_definition_code
2508      AND xld.event_class_code           = xald.event_class_code
2509      AND xld.event_type_code            = xald.event_type_code
2510      AND xld.application_id             = xald.application_id
2511      AND xld.amb_context_code           = xald.amb_context_code
2512      AND xld.budgetary_control_flag     = XLA_CMP_PAD_PKG.g_bc_pkg_flag
2513      --
2514      AND xald.product_rule_type_code     = xpah.product_rule_type_code
2515      AND xald.product_rule_code          = xpah.product_rule_code
2516      AND xald.event_class_code           = xpah.event_class_code
2517      AND xald.event_type_code            = xpah.event_type_code
2518      AND xald.application_id             = xpah.application_id
2519      AND xald.amb_context_code           = xpah.amb_context_code
2520      --
2521      AND xpah.product_rule_type_code     = p_product_rule_type_code
2525      AND xpah.event_type_code            = p_event_type
2522      AND xpah.product_rule_code          = p_product_rule_code
2523      AND xpah.entity_code                = p_entity
2524      AND xpah.event_class_code           = p_event_class
2526      AND xpah.application_id             = p_application_id
2527      AND xpah.amb_context_code           = p_amb_context_code
2528      AND xpah.accounting_required_flag   = 'Y'
2529 ORDER BY xldj.accounting_line_type_code, xldj.accounting_line_code
2530        , xldj.line_definition_owner_code, xldj.line_definition_code
2531 ;
2532 --
2533 l_array_alt_code         xla_cmp_source_pkg.t_array_VL30;
2534 l_array_alt_type_code    xla_cmp_source_pkg.t_array_VL1;
2535 l_array_jld_code         xla_cmp_source_pkg.t_array_VL30;
2536 l_array_jld_owner_code   xla_cmp_source_pkg.t_array_VL1;
2537 l_ObjectIndex            BINARY_INTEGER;
2538 l_log_module             VARCHAR2(240);
2539 invalid_jlt              EXCEPTION;
2540 --
2541 BEGIN
2542 --
2543 IF g_log_enabled THEN
2544       l_log_module := C_DEFAULT_MODULE||'.GetSourcesDefinedInAcctgLine';
2545 END IF;
2546 --
2547 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2548 
2549       trace
2550          (p_msg      => 'BEGIN of GetSourcesDefinedInAcctgLine'
2551          ,p_level    => C_LEVEL_PROCEDURE
2552          ,p_module   => l_log_module);
2553 
2554 END IF;
2555 --
2556 OPEN alt_cur;
2557 --
2558 FETCH alt_cur BULK COLLECT INTO l_array_alt_code
2559                               , l_array_alt_type_code
2560                               , l_array_jld_code
2561                               , l_array_jld_owner_code
2562                               ;
2563 
2564 CLOSE alt_cur;
2565 
2566 IF l_array_alt_code.COUNT > 0 THEN
2567 
2568 FOR Idx IN l_array_alt_code.FIRST .. l_array_alt_code.LAST LOOP
2569 
2570    IF l_array_alt_code.EXISTS(Idx) THEN
2571 
2572        l_ObjectIndex :=xla_cmp_source_pkg.GetAADObjectPosition(
2573                         p_object                       => xla_cmp_source_pkg.C_ALT
2574                       , p_object_code                  => l_array_alt_code(Idx)
2575                       , p_object_type_code             => l_array_alt_type_code(Idx)
2576                       , p_application_id               => p_application_id
2577                       , p_line_definition_code         => l_array_jld_code(Idx)
2578                       , p_line_definition_owner_code   => l_array_jld_owner_code(Idx)
2579                       , p_event_class_code             => p_event_class
2580                       , p_event_type_code              => p_event_type
2581                       , p_rec_aad_objects              => p_rec_aad_objects
2582                      );
2583 
2584        IF l_ObjectIndex IS NOT NULL THEN
2585 
2586              xla_cmp_source_pkg.GetSourcesInAADObject(
2587                              p_object                       => xla_cmp_source_pkg.C_ALT
2588                            , p_object_code                  => l_array_alt_code(Idx)
2589                            , p_object_type_code             => l_array_alt_type_code(Idx)
2590                            , p_application_id               => p_application_id
2591                            , p_line_definition_code         => l_array_jld_code(Idx)
2592                            , p_line_definition_owner_code   => l_array_jld_owner_code(Idx)
2593                            , p_event_class_code             => p_event_class
2594                            , p_event_type_code              => p_event_type
2595                            , p_array_source_Index           => p_array_evt_source_index
2596                            , p_rec_aad_objects              => p_rec_aad_objects
2597                           );
2598 
2599        ELSE
2600 
2601         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2602             trace
2603                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = Journal Line Type not cached = '||
2604                               'JLT ='||l_array_alt_code(Idx)||' - '||l_array_alt_type_code(Idx)||
2605                               ' - JLD ='||l_array_jld_code(Idx)||' - '||l_array_jld_owner_code(Idx)
2606                ,p_level    => C_LEVEL_EXCEPTION
2607                ,p_module   => l_log_module);
2608         END IF;
2609         RAISE invalid_jlt;
2610 
2611        END IF;
2612 
2613        p_array_alt_index(Idx) := l_ObjectIndex;
2614 
2615    END IF;
2616 
2617 END LOOP;
2618 
2619 END IF;
2620 
2621 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2622       trace
2623          (p_msg      => 'END of GetSourcesDefinedInAcctgLine = '|| p_array_alt_index.COUNT
2624          ,p_level    => C_LEVEL_PROCEDURE
2625          ,p_module   => l_log_module);
2626 END IF;
2627 EXCEPTION
2628    WHEN invalid_jlt THEN
2629        IF alt_cur%ISOPEN THEN CLOSE alt_cur; END IF;
2630        RAISE;
2631    WHEN xla_exceptions_pkg.application_exception   THEN
2632         IF alt_cur%ISOPEN THEN CLOSE alt_cur; END IF;
2633         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2634             trace
2635                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
2636                ,p_level    => C_LEVEL_EXCEPTION
2637                ,p_module   => l_log_module);
2638         END IF;
2639         RAISE;
2640    WHEN OTHERS    THEN
2641       IF alt_cur%ISOPEN THEN CLOSE alt_cur; END IF;
2642       xla_exceptions_pkg.raise_message
2643          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GetSourcesDefinedInAcctgLine');
2644 END GetSourcesDefinedInAcctgLine;
2645 
2646 /*--------------------------------------------------------------------+
2650 |    CollectHeaderAndLineSources                                      |
2647 |                                                                     |
2648 |  Private procedure                                                  |
2649 |                                                                     |
2651 |                                                                     |
2652 | Collect header and line sources to extract from the Transaction     |
2653 | Objects                                                             |
2654 |                                                                     |
2655 +--------------------------------------------------------------------*/
2656 
2657 PROCEDURE CollectHeaderAndLineSources (
2658     p_entity                       IN VARCHAR2
2659   , p_event_class                  IN VARCHAR2
2660   , p_event_type                   IN VARCHAR2
2661   , p_application_id               IN NUMBER
2662   , p_product_rule_code            IN VARCHAR2
2663   , p_product_rule_type_code       IN VARCHAR2
2664   , p_amb_context_code             IN VARCHAR2
2665   , p_array_evt_source_index       IN OUT NOCOPY xla_cmp_source_pkg.t_array_ByInt
2666   , p_array_hdr_acctg_source       OUT NOCOPY xla_cmp_source_pkg.t_array_VL30
2667   , p_array_hdr_acctg_source_type  OUT NOCOPY xla_cmp_source_pkg.t_array_VL1
2668   , p_array_hdr_acct_attr_source   OUT NOCOPY xla_cmp_source_pkg.t_array_int
2669   , p_array_line_acctg_source      OUT NOCOPY xla_cmp_source_pkg.t_array_VL30
2670   , p_array_line_acctg_source_type OUT NOCOPY xla_cmp_source_pkg.t_array_VL1
2671   , p_array_line_acct_attr_source  OUT NOCOPY xla_cmp_source_pkg.t_array_int
2672   , p_hdr_description_index        IN OUT NOCOPY BINARY_INTEGER
2673   , p_array_alt_index              IN OUT NOCOPY xla_cmp_source_pkg.t_array_ByInt
2674   , p_rec_aad_objects              IN OUT NOCOPY xla_cmp_source_pkg.t_rec_aad_objects
2675   , p_rec_sources                  IN OUT NOCOPY xla_cmp_source_pkg.t_rec_sources
2676 )
2677 IS
2678 
2679 l_Idx            BINARY_INTEGER;
2680 l_log_module     VARCHAR2(240);
2681 
2682 BEGIN
2683 IF g_log_enabled THEN
2684       l_log_module := C_DEFAULT_MODULE||'.CollectHeaderAndLineSources';
2685 END IF;
2686 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2687       trace
2688          (p_msg      => 'BEGIN of CollectHeaderAndLineSources'
2689          ,p_level    => C_LEVEL_PROCEDURE
2690          ,p_module   => l_log_module);
2691 END IF;
2692 
2693 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2694       trace
2695          (p_msg      => '# number of sources = '||p_array_evt_source_index.COUNT
2696          ,p_level    => C_LEVEL_STATEMENT
2697          ,p_module   => l_log_module);
2698       trace
2699          (p_msg      => 'Get header description sources'
2700          ,p_level    => C_LEVEL_STATEMENT
2701          ,p_module   => l_log_module);
2702 END IF;
2703 
2704 GetSourcesDefinedInHeader(
2705   p_entity                     => p_entity
2706 , p_event_class                => p_event_class
2707 , p_event_type                 => p_event_type
2708 , p_application_id             => p_application_id
2709 , p_product_rule_code          => p_product_rule_code
2710 , p_product_rule_type_code     => p_product_rule_type_code
2711 , p_amb_context_code           => p_amb_context_code
2712 , p_array_evt_source_index     => p_array_evt_source_index
2713 , p_hdr_description_index      => p_hdr_description_index
2714 , p_rec_aad_objects            => p_rec_aad_objects
2715 );
2716 
2717 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2718       trace
2719          (p_msg      => 'Get header accounting attribute sources'
2720          ,p_level    => C_LEVEL_STATEMENT
2721          ,p_module   => l_log_module);
2722 
2723       trace
2724          (p_msg      => '# number of sources  = '||p_array_evt_source_index.COUNT
2725          ,p_level    => C_LEVEL_STATEMENT
2726          ,p_module   => l_log_module);
2727 END IF;
2728 
2729 GetHeaderAcctgSources (
2730   p_entity                       => p_entity
2731 , p_event_class                  => p_event_class
2732 , p_event_type                   => p_event_type
2733 , p_application_id               => p_application_id
2734 , p_amb_context_code             => p_amb_context_code
2735 , p_product_rule_code            => p_product_rule_code
2736 , p_product_rule_type_code       => p_product_rule_type_code
2737 , p_array_evt_source_index       => p_array_evt_source_index
2738 , p_array_hdr_acctg_source       => p_array_hdr_acctg_source
2739 , p_array_hdr_acctg_source_type  => p_array_hdr_acctg_source_type
2740 , p_array_hdr_acct_attr_source   => p_array_hdr_acct_attr_source
2741 , p_rec_sources                  => p_rec_sources
2742 )
2743 ;
2744 
2745 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2746       trace
2747          (p_msg      => 'Get Journal Line Definition sources'
2748          ,p_level    => C_LEVEL_STATEMENT
2749          ,p_module   => l_log_module);
2750       trace
2751          (p_msg      => '# number of sources  = '||p_array_evt_source_index.COUNT
2752          ,p_level    => C_LEVEL_STATEMENT
2753          ,p_module   => l_log_module);
2754 END IF;
2755 
2756 
2757 xla_cmp_analytic_criteria_pkg.GetAnalyticalCriteriaSources (
2758   p_entity                     => p_entity
2759 , p_event_class                => p_event_class
2760 , p_event_type                 => p_event_type
2761 , p_application_id             => p_application_id
2762 , p_product_rule_code          => p_product_rule_code
2766 , p_rec_sources                => p_rec_sources           );
2763 , p_product_rule_type_code     => p_product_rule_type_code
2764 , p_amb_context_code           => p_amb_context_code
2765 , p_array_evt_source_index     => p_array_evt_source_index
2767 
2768 
2769 GetSourcesDefinedInAcctgLine(
2770   p_entity                      => p_entity
2771 , p_event_class                 => p_event_class
2772 , p_event_type                  => p_event_type
2773 , p_application_id              => p_application_id
2774 , p_product_rule_code           => p_product_rule_code
2775 , p_product_rule_type_code      => p_product_rule_type_code
2776 , p_amb_context_code            => p_amb_context_code
2777 , p_array_evt_source_index      => p_array_evt_source_index
2778 , p_array_alt_index             => p_array_alt_index
2779 , p_rec_aad_objects             => p_rec_aad_objects
2780 );
2781 
2782 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2783      trace
2784          (p_msg      => 'Get Reversal Line Accounting Attribute sources'
2785          ,p_level    => C_LEVEL_STATEMENT
2786          ,p_module   => l_log_module);
2787       trace
2788          (p_msg      => '# number of sources  = '||p_array_evt_source_index.COUNT
2789          ,p_level    => C_LEVEL_STATEMENT
2790          ,p_module   => l_log_module);
2791 END IF;
2792 
2793 GetLineAcctgSources (
2794   p_entity                       => p_entity
2795 , p_event_class                  => p_event_class
2796 , p_application_id               => p_application_id
2797 , p_array_evt_source_index       => p_array_evt_source_index
2798 , p_array_line_acctg_source      => p_array_line_acctg_source
2799 , p_array_line_acctg_source_type => p_array_line_acctg_source_type
2800 , p_array_line_acct_attr_source  => p_array_line_acct_attr_source
2801 , p_rec_sources                  => p_rec_sources
2802 )
2803 ;
2804 
2805 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2806       trace
2807          (p_msg      => '# of header and line sources = '||p_array_evt_source_index.COUNT
2808          ,p_level    => C_LEVEL_STATEMENT
2809          ,p_module   => l_log_module);
2810 END IF;
2811 
2812 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2813       trace
2814          (p_msg      => 'END of CollectHeaderAndLineSources'
2815          ,p_level    => C_LEVEL_PROCEDURE
2816          ,p_module   => l_log_module);
2817 END IF;
2818 EXCEPTION
2819    WHEN xla_exceptions_pkg.application_exception   THEN
2820         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2821             trace
2822                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
2823                ,p_level    => C_LEVEL_EXCEPTION
2824                ,p_module   => l_log_module);
2825         END IF;
2826         RAISE;
2827    WHEN OTHERS    THEN
2828       xla_exceptions_pkg.raise_message
2829          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.CollectHeaderAndLineSources');
2830 END CollectHeaderAndLineSources;
2831 
2832 /*-----------------------------------------------------------------------+
2833 |                                                                        |
2834 |  Private function                                                      |
2835 |                                                                        |
2836 |   GenerateHdrDescription                                               |
2837 |                                                                        |
2838 | Generates in EventClass_x()/EventType_x() a call to header description |
2839 |                                                                        |
2840 +-----------------------------------------------------------------------*/
2841 
2842 FUNCTION GenerateHdrDescription  (
2843    p_hdr_description_index    IN BINARY_INTEGER
2844  , p_rec_aad_objects          IN xla_cmp_source_pkg.t_rec_aad_objects
2845  , p_rec_sources              IN xla_cmp_source_pkg.t_rec_sources
2846 )
2847 RETURN CLOB
2848 IS
2849 
2850 C_CALL_HDR_DESC                    CONSTANT      VARCHAR2(10000):= '
2851 --
2852 xla_ae_header_pkg.SetHdrDescription(
2853    p_description => Description_$desc_code$ (
2854    p_application_id => p_application_id $parameters$
2855    )
2856 );
2857 --
2858 ';
2859 
2860 l_hdr_desc                         CLOB;
2861 l_log_module                       VARCHAR2(240);
2862 BEGIN
2863 IF g_log_enabled THEN
2864       l_log_module := C_DEFAULT_MODULE||'.GenerateHdrDescription';
2865 END IF;
2866 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2867       trace
2868          (p_msg      => 'BEGIN of GenerateHdrDescription'
2869          ,p_level    => C_LEVEL_PROCEDURE
2870          ,p_module   => l_log_module);
2871 END IF;
2872 
2873 l_hdr_desc := NULL;
2874 
2875 IF nvl(p_hdr_description_index,0) <> 0  THEN
2876 
2877    l_hdr_desc := C_CALL_HDR_DESC;
2878    l_hdr_desc := xla_cmp_string_pkg.replace_token(l_hdr_desc,'$desc_code$', TO_CHAR(p_hdr_description_index));  -- 4417664
2879    l_hdr_desc := xla_cmp_string_pkg.replace_token(l_hdr_desc,'$parameters$',
2880                  xla_cmp_call_fct_pkg.GetHeaderParameters(
2881                      p_array_source_index => p_rec_aad_objects.array_array_object(p_hdr_description_index)
2882                    , p_rec_sources        => p_rec_sources
2883                   )
2884                 );
2885 
2886 END IF;
2887 
2888 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2889       trace
2890          (p_msg      => 'END of GenerateHdrDescription'
2894 RETURN l_hdr_desc;
2891          ,p_level    => C_LEVEL_PROCEDURE
2892          ,p_module   => l_log_module);
2893 END IF;
2895 EXCEPTION
2896    WHEN VALUE_ERROR THEN
2897         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2898             trace
2899                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
2900                ,p_level    => C_LEVEL_EXCEPTION
2901                ,p_module   => l_log_module);
2902         END IF;
2903         RAISE;
2904    WHEN xla_exceptions_pkg.application_exception   THEN
2905         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
2906             trace
2907                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
2908                ,p_level    => C_LEVEL_EXCEPTION
2909                ,p_module   => l_log_module);
2910         END IF;
2911         RAISE;
2912  WHEN OTHERS    THEN
2913       xla_exceptions_pkg.raise_message
2914          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GenerateHdrDescription');
2915 END  GenerateHdrDescription;
2916 
2917 /*-----------------------------------------------------------------------+
2918 |                                                                        |
2919 |  Private function                                                      |
2920 |                                                                        |
2921 |   GenerateHdrAcctgSources                                              |
2922 |                                                                        |
2923 | Generates in EventClass_x()/EventType_x() the set of Header Accounting |
2924 | Attributes.                                                            |
2925 |                                                                        |
2926 +-----------------------------------------------------------------------*/
2927 
2928 FUNCTION GenerateHdrAcctgSources (
2929     p_array_hdr_acctg_source       IN xla_cmp_source_pkg.t_array_VL30
2930   , p_array_hdr_acctg_source_type  IN xla_cmp_source_pkg.t_array_VL1
2931   , p_array_hdr_acct_attr_source   IN xla_cmp_source_pkg.t_array_int
2932   , p_rec_sources                  IN OUT NOCOPY xla_cmp_source_pkg.t_rec_sources
2933 )
2934 RETURN CLOB
2935 IS
2936 --
2937 C_SET_HDR_ACCT_SOURCES                CONSTANT       VARCHAR2(10000):=
2938 '     l_rec_acct_attrs.array_acct_attr_code($index$)   := ''$accounting_attribute$'';
2939       l_rec_acct_attrs.array_$datatype$_value($index$) := $source$;
2940 ';
2941 --
2942 l_hdr_acctg_sources     CLOB;
2943 l_hdr_acctg_source      VARCHAR2(32000) ;
2944 l_source                VARCHAR2(2000);
2945 l_log_module            VARCHAR2(240);
2946 --
2947 l_index                 NUMBER;
2948 BEGIN
2949    IF g_log_enabled THEN
2950       l_log_module := C_DEFAULT_MODULE||'.GenerateHdrAcctgSources';
2951    END IF;
2952    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2953       trace
2954          (p_msg      => 'BEGIN of GenerateHdrAcctgSources'
2955          ,p_level    => C_LEVEL_PROCEDURE
2956          ,p_module   => l_log_module);
2957    END IF;
2958 
2959    l_index              := 0;
2960    l_hdr_acctg_sources  := C_HDR_ACCT_BODY;   -- 4262811
2961 
2962    IF (C_LEVEL_STATEMENT>= g_log_level) THEN
2963       trace
2964          (p_msg      => 'p_array_hdr_acctg_source.count is:'||to_char(p_array_hdr_acctg_source.COUNT)
2965          ,p_level    => C_LEVEL_STATEMENT
2966          ,p_module   => l_log_module);
2967    END IF;
2968 
2969    IF p_array_hdr_acctg_source.COUNT > 0 THEN
2970 
2971       FOR Idx IN p_array_hdr_acctg_source.FIRST .. p_array_hdr_acctg_source.LAST LOOP
2972 
2973          IF p_array_hdr_acctg_source.EXISTS(Idx)      AND
2974             p_array_hdr_acctg_source_type.EXISTS(Idx) THEN
2975 
2976           --l_index := l_index + 1;  -- 4262811 Move to below to avoid index starting at 2,3,,,
2977 
2978             IF p_array_hdr_acctg_source(Idx) not in ('EXCHANGE_GAIN_CCID', 'EXCHANGE_LOSS_CCID') THEN
2979               IF p_array_hdr_acctg_source(Idx) <> 'ACCRUAL_REVERSAL_GL_DATE' THEN  -- 4262811
2980                  l_index := l_index + 1;  -- 4262811
2981 
2982                  l_source := xla_cmp_source_pkg.GenerateSource(
2983                                                 p_Index            => p_array_hdr_acct_attr_source(Idx)
2984                                               , p_rec_sources      => p_rec_sources
2985                                               , p_variable         => p_array_hdr_acctg_source_type(Idx)
2986                                               , p_translated_flag  => 'N') ;
2987 
2988                  l_hdr_acctg_source  := REPLACE(C_SET_HDR_ACCT_SOURCES,'$index$',to_char(l_index));
2989 
2990                  l_hdr_acctg_source  := REPLACE(l_hdr_acctg_source,'$accounting_attribute$', p_array_hdr_acctg_source(Idx));
2991 
2992                  l_hdr_acctg_source  := REPLACE(l_hdr_acctg_source,'$source$', l_source);
2993 
2994                  CASE p_rec_sources.array_datatype_code(p_array_hdr_acct_attr_source(Idx))
2995                      when 'F' then
2996                         l_hdr_acctg_source  := REPLACE(l_hdr_acctg_source,'$datatype$','num') ;
2997                      when 'I' then
2998                         l_hdr_acctg_source  := REPLACE(l_hdr_acctg_source,'$datatype$','num') ;
2999                      when 'N' then
3000                         l_hdr_acctg_source  := REPLACE(l_hdr_acctg_source,'$datatype$','num') ;
3001                      when 'C' then
3002                         l_hdr_acctg_source  := REPLACE(l_hdr_acctg_source,'$datatype$','char') ;
3006                         l_hdr_acctg_source  := REPLACE(l_hdr_acctg_source,'$datatype$',
3003                      when 'D' then
3004                         l_hdr_acctg_source  := REPLACE(l_hdr_acctg_source,'$datatype$','date') ;
3005                      else
3007                            p_rec_sources.array_datatype_code(p_array_hdr_acct_attr_source(Idx))) ;
3008                  END CASE;
3009 
3010                  l_hdr_acctg_sources := l_hdr_acctg_sources || l_hdr_acctg_source;
3011 
3012               ELSE  -- 4262811
3013 
3014               -- IF p_rec_sources.array_source_code (Idx) NOT IN ('XLA_NEXT_DAY',
3015               --                                                  'XLA_FIRST_DAY_NEXT_GL_PERIOD',
3016               --                                                  'XLA_LAST_DAY_NEXT_GL_PERIOD') OR
3017                  IF p_rec_sources.array_source_code (p_array_hdr_acct_attr_source(Idx)) NOT IN
3018                                                                  ('XLA_NEXT_DAY',
3019                                                                   'XLA_FIRST_DAY_NEXT_GL_PERIOD',
3020                                                                   'XLA_LAST_DAY_NEXT_GL_PERIOD') AND
3021                    (p_rec_sources.array_source_type_code (Idx) <> 'Y' OR
3022                     p_rec_sources.array_application_id (Idx) <> 602) THEN
3023 
3024                     l_source := xla_cmp_source_pkg.GenerateSource(
3025                                                   p_Index            => p_array_hdr_acct_attr_source(Idx)
3026                                                 , p_rec_sources      => p_rec_sources
3027                                                 , p_variable         => p_array_hdr_acctg_source_type(Idx)
3028                                                 , p_translated_flag  => 'N') ;
3029 
3030                     l_hdr_acctg_sources := xla_cmp_string_pkg.replace_token(l_hdr_acctg_sources,
3031                                                           '$acc_rev_gl_date_source$', l_source);
3032                  END IF;
3033 
3034               END IF; -- p_array_hdr_acctg_source(Idx) <> 'ACCRUAL_REVERSAL_GL_DATE'
3035             END IF;
3036 
3037          END IF;  --  p_array_hdr_acctg_source.EXISTS(Idx)
3038 
3039       END LOOP;
3040 
3041       -------------------------------------------------------------------------------------
3042       -- 4262811
3043       -------------------------------------------------------------------------------------
3044       -- If the acc_rev_gl_date_source token is not replaced, the ACCRUAL_REVERSAL_GL_DATE
3045       -- attribute is not found.  Then replace the accounting attribute by NULL
3046       -------------------------------------------------------------------------------------
3047       l_hdr_acctg_sources := xla_cmp_string_pkg.replace_token(l_hdr_acctg_sources,'$acc_rev_gl_date_source$','NULL');
3048 
3049    END IF;  -- p_array_hdr_acctg_source.COUNT > 0
3050 
3051    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3052       trace
3053          (p_msg      => 'END of GenerateHdrAcctgSources'
3054          ,p_level    => C_LEVEL_PROCEDURE
3055          ,p_module   => l_log_module);
3056    END IF;
3057 
3058    RETURN l_hdr_acctg_sources;
3059 
3060 EXCEPTION
3061 WHEN VALUE_ERROR THEN
3062         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3063             trace
3064                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
3065                ,p_level    => C_LEVEL_EXCEPTION
3066                ,p_module   => l_log_module);
3067         END IF;
3068         RAISE;
3069 WHEN xla_exceptions_pkg.application_exception   THEN
3070         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3071             trace
3072                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
3073                ,p_level    => C_LEVEL_EXCEPTION
3074                ,p_module   => l_log_module);
3075         END IF;
3076         RAISE;
3077  WHEN OTHERS    THEN
3078       xla_exceptions_pkg.raise_message
3079          (p_location => 'XLA_CMP_EVENT_TYPE_PKG. GenerateHdrAcctgSources');
3080 END GenerateHdrAcctgSources;
3081 
3082 /*-----------------------------------------------------------------------+
3083 |                                                                        |
3084 |  Private function                                                      |
3085 |                                                                        |
3086 |   GenerateGainLossAcctSources                                  |
3087 |                                                                        |
3088 | Generates in EventClass_x()/EventType_x() the default gain/loss ccid   |
3089 | calling parameters                                                     |
3090 |                                                                        |
3091 +-----------------------------------------------------------------------*/
3092 
3093 FUNCTION GenerateGainLossAcctSources(
3094     p_array_hdr_acctg_source       IN xla_cmp_source_pkg.t_array_VL30
3095   , p_array_hdr_acctg_source_type  IN xla_cmp_source_pkg.t_array_VL1
3096   , p_array_hdr_acct_attr_source   IN xla_cmp_source_pkg.t_array_int
3097   , p_rec_sources                  IN OUT NOCOPY xla_cmp_source_pkg.t_rec_sources
3098 )
3099 RETURN CLOB
3100 IS
3101 --
3102 C_CALLING_PARAMS                      CONSTANT       VARCHAR2(10000):='
3103          ,p_gain_ccid        => $gain_ccid_source$
3104          ,p_loss_ccid        => $loss_ccid_source$
3105 ';
3106 --
3107 l_gain_or_loss_source   VARCHAR2(30000);
3108 l_hdr_acctg_source      VARCHAR2(32000) ;
3109 l_source                VARCHAR2(2000);
3110 l_log_module            VARCHAR2(240);
3111 --
3115       l_log_module := C_DEFAULT_MODULE||'.GenerateGainLossAcctSources';
3112 l_index                 NUMBER;
3113 BEGIN
3114    IF g_log_enabled THEN
3116    END IF;
3117    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3118       trace
3119          (p_msg      => 'BEGIN of GenerateGainLossAcctSources'
3120          ,p_level    => C_LEVEL_PROCEDURE
3121          ,p_module   => l_log_module);
3122    END IF;
3123 
3124    l_index               := 0;
3125    l_gain_or_loss_source := C_CALLING_PARAMS;
3126 
3127    IF (C_LEVEL_STATEMENT>= g_log_level) THEN
3128       trace
3129          (p_msg      => 'p_array_hdr_acctg_source.count is:'||to_char(p_array_hdr_acctg_source.COUNT)
3130          ,p_level    => C_LEVEL_STATEMENT
3131          ,p_module   => l_log_module);
3132    END IF;
3133 
3134    IF p_array_hdr_acctg_source.COUNT > 0 THEN
3135       l_index := 0;
3136 
3137       FOR Idx IN p_array_hdr_acctg_source.FIRST .. p_array_hdr_acctg_source.LAST LOOP
3138          IF(l_index = 3) THEN
3139            EXIT;
3140          END IF;
3141 
3142          IF p_array_hdr_acctg_source.EXISTS(Idx)      AND
3143             p_array_hdr_acctg_source_type.EXISTS(Idx) THEN
3144 
3145             IF p_array_hdr_acctg_source(Idx) in ('EXCHANGE_GAIN_CCID', 'EXCHANGE_LOSS_CCID') THEN
3146 
3147                l_source := xla_cmp_source_pkg.GenerateSource(
3148                                                 p_Index            => p_array_hdr_acct_attr_source(Idx)
3149                                               , p_rec_sources      => p_rec_sources
3150                                               , p_variable         => p_array_hdr_acctg_source_type(Idx)
3151                                               , p_translated_flag  => 'N') ;
3152 
3153                IF p_array_hdr_acctg_source(Idx) = 'EXCHANGE_GAIN_CCID' THEN
3154                  l_index := l_index + 1;
3155                  l_gain_or_loss_source:= REPLACE(l_gain_or_loss_source,'$gain_ccid_source$', l_source);
3156                ELSE
3157                  l_index := l_index + 2;
3158                  l_gain_or_loss_source:= REPLACE(l_gain_or_loss_source,'$loss_ccid_source$', l_source);
3159                END IF;
3160 
3161             END IF;
3162          END IF;  --  p_array_hdr_acctg_source.EXISTS(Idx)
3163 
3164       END LOOP;
3165 
3166    END IF;  -- p_array_hdr_acctg_source.COUNT > 0
3167 
3168    IF(l_index <3) THEN
3169      IF(l_index = 0 ) THEN
3170        l_gain_or_loss_source:= REPLACE(l_gain_or_loss_source,'$gain_ccid_source$', '-1');
3171        l_gain_or_loss_source:= REPLACE(l_gain_or_loss_source,'$loss_ccid_source$', '-1');
3172      ELSIF(l_index = 1 ) THEN
3173        l_gain_or_loss_source:= REPLACE(l_gain_or_loss_source,'$loss_ccid_source$', '-1');
3174      ELSE
3175        l_gain_or_loss_source:= REPLACE(l_gain_or_loss_source,'$gain_ccid_source$', '-1');
3176      END IF;
3177    END IF;
3178 
3179 
3180    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3181       trace
3182          (p_msg      => 'END of GenerateHdrAcctgSources'
3183          ,p_level    => C_LEVEL_PROCEDURE
3184          ,p_module   => l_log_module);
3185    END IF;
3186 
3187    RETURN l_gain_or_loss_source;
3188 
3189 EXCEPTION
3190 WHEN VALUE_ERROR THEN
3191         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3192             trace
3193                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
3194                ,p_level    => C_LEVEL_EXCEPTION
3195                ,p_module   => l_log_module);
3196         END IF;
3197         RAISE;
3198 WHEN xla_exceptions_pkg.application_exception   THEN
3199         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3200             trace
3201                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
3202                ,p_level    => C_LEVEL_EXCEPTION
3203                ,p_module   => l_log_module);
3204         END IF;
3205         RAISE;
3206  WHEN OTHERS    THEN
3207       xla_exceptions_pkg.raise_message
3208          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GenerateGainLossAcctSources');
3209 END GenerateGainLossAcctSources;
3210 
3211 /*---------------------------------------------------------------+
3212 |                                                                |
3213 |  Private function                                              |
3214 |                                                                |
3215 |   GenerateReversalAcctgSources                                 |
3216 |                                                                |
3217 | Generates in EventClass_x()/EventType_x() the set of Reversal  |
3218 | Accounting Attributes.                                         |
3219 |                                                                |
3220 +---------------------------------------------------------------*/
3221 
3222 FUNCTION GenerateReversalAcctgSources (
3223     p_array_line_acctg_source      IN xla_cmp_source_pkg.t_array_VL30
3224   , p_array_line_acctg_source_type IN xla_cmp_source_pkg.t_array_VL1
3225   , p_array_line_acct_attr_source  IN xla_cmp_source_pkg.t_array_int
3226   , p_rec_sources                  IN OUT NOCOPY xla_cmp_source_pkg.t_rec_sources
3227 )
3228 RETURN CLOB
3229 IS
3230 
3231 C_SET_REV_ACCT_SOURCES                CONSTANT       VARCHAR2(10000):=
3232 '      l_rec_rev_acct_attrs.array_acct_attr_code($index$) := ''$accounting_attribute$'';
3233       l_rec_rev_acct_attrs.array_$datatype$_value($index$)  := $source$;
3234 ';
3235 
3236 l_line_acctg_sources     CLOB;
3240 l_index                  NUMBER;
3237 l_line_acctg_source      VARCHAR2(32000) ;
3238 l_log_module             VARCHAR2(240);
3239 --
3241 BEGIN
3242 
3243 IF g_log_enabled THEN
3244    l_log_module := C_DEFAULT_MODULE||'.GenerateReversalAcctgSources';
3245 END IF;
3246 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3247    trace
3248       (p_msg      => 'BEGIN of GenerateReversalAcctgSources'
3249       ,p_level    => C_LEVEL_PROCEDURE
3250       ,p_module   => l_log_module);
3251 END IF;
3252 
3253 l_index               := 1;   --5217187
3254 l_line_acctg_sources  := NULL;
3255 
3256 FOR Idx IN 1..(p_array_line_acctg_source.COUNT) LOOP
3257 
3258   IF p_array_line_acct_attr_source.EXISTS(Idx) AND
3259      p_array_line_acct_attr_source(Idx) IS NOT NULL
3260   THEN
3261      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3262         trace
3263         (p_msg      => 'accounting attribute = '||p_array_line_acctg_source(Idx)
3264         ,p_level    => C_LEVEL_STATEMENT
3265         ,p_module   => l_log_module);
3266      END IF;
3267 
3268      l_index := l_index + 1;
3269 
3270      l_line_acctg_source  := REPLACE(C_SET_REV_ACCT_SOURCES ,'$accounting_attribute$',
3271                                        p_array_line_acctg_source(Idx));
3272 
3273      l_line_acctg_source  := REPLACE(l_line_acctg_source , '$source$',
3274                                 xla_cmp_source_pkg.GenerateSource(
3275                                          p_Index                     => p_array_line_acct_attr_source(Idx)
3276                                        , p_rec_sources               => p_rec_sources
3277                                        , p_variable                  => p_array_line_acctg_source_type(Idx)
3278                                        , p_translated_flag           => 'N')
3279                                        );
3280     --
3281     l_line_acctg_source  := REPLACE(l_line_acctg_source,'$index$',to_char(l_index));
3282 
3283     CASE p_rec_sources.array_datatype_code(p_array_line_acct_attr_source(Idx))
3284        when 'F' then
3285           l_line_acctg_source  := REPLACE(l_line_acctg_source,'$datatype$','num') ;
3286        when 'I' then
3287           l_line_acctg_source  := REPLACE(l_line_acctg_source,'$datatype$','num') ;
3288        when 'N' then
3289           l_line_acctg_source  := REPLACE(l_line_acctg_source,'$datatype$','num') ;
3290        when 'C' then
3291           l_line_acctg_source  := REPLACE(l_line_acctg_source,'$datatype$','char') ;
3292        when 'D' then
3293           l_line_acctg_source  := REPLACE(l_line_acctg_source,'$datatype$','date') ;
3294        else
3295           l_line_acctg_source  := REPLACE(l_line_acctg_source,'$datatype$',
3296                 p_rec_sources.array_datatype_code(p_array_line_acct_attr_source(Idx))) ;
3297     END CASE;
3298 
3299     l_line_acctg_sources := l_line_acctg_sources || l_line_acctg_source;
3300 
3301   END IF;
3302 END LOOP;
3303 
3304 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3305    trace
3306       (p_msg      => 'END of GenerateReversalAcctgSources'
3307       ,p_level    => C_LEVEL_PROCEDURE
3308       ,p_module   => l_log_module);
3309 END IF;
3310 RETURN l_line_acctg_sources;
3311 EXCEPTION
3312 WHEN VALUE_ERROR THEN
3313         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3314             trace
3315                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
3316                ,p_level    => C_LEVEL_EXCEPTION
3317                ,p_module   => l_log_module);
3318         END IF;
3319         RAISE;
3320 WHEN xla_exceptions_pkg.application_exception   THEN
3321         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3322             trace
3323                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
3324                ,p_level    => C_LEVEL_EXCEPTION
3325                ,p_module   => l_log_module);
3326         END IF;
3327         RAISE;
3328  WHEN OTHERS    THEN
3329       xla_exceptions_pkg.raise_message
3330          (p_location => 'XLA_CMP_EVENT_TYPE_PKG. GenerateReversalAcctgSources');
3331 END GenerateReversalAcctgSources;
3332 
3333 /*---------------------------------------------------------------+
3334 |                                                                |
3335 |  Private function                                              |
3336 |                                                                |
3337 |   GenerateAcctLinetypes                                        |
3338 |                                                                |
3339 | Generates in EventClass_x()/EventType_x() the calls to Journal |
3340 | Line Types procedures/ AcctLineType_xxx()                      |
3341 |                                                                |
3342 +---------------------------------------------------------------*/
3343 
3344 FUNCTION GenerateAcctLinetypes  (
3345    p_array_alt_index          IN xla_cmp_source_pkg.t_array_ByInt
3346  , p_array_evt_source_Level   IN xla_cmp_source_pkg.t_array_VL1
3347  , p_rec_aad_objects          IN xla_cmp_source_pkg.t_rec_aad_objects
3348  , p_rec_sources              IN xla_cmp_source_pkg.t_rec_sources
3349 )
3350 RETURN CLOB
3351 IS
3352 
3353 C_ALT_PROC                    CONSTANT      VARCHAR2(10000):= '
3354 --
3355 AcctLineType_$alt_code$ (
3356  p_application_id  => p_application_id
3357  ,p_event_id     => l_event_id
3358  ,p_calculate_acctd_flag => l_calculate_acctd_flag
3359  ,p_calculate_g_l_flag => l_calculate_g_l_flag
3363  $parameters$
3360  ,p_actual_flag => l_actual_flag
3361  ,p_balance_type_code => l_balance_type_code
3362  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
3364  );
3365 If(l_balance_type_code = ''A'') THEN
3366   l_actual_gain_loss_ref := l_gain_or_loss_ref;
3367 END IF;
3368 
3369 --
3370 ';
3371 
3372 l_alts                         CLOB;
3373 l_alt                          CLOB;
3374 l_log_module                   VARCHAR2(240);
3375 BEGIN
3376 IF g_log_enabled THEN
3377       l_log_module := C_DEFAULT_MODULE||'.GenerateAcctLinetypes';
3378 END IF;
3379 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3380       trace
3381          (p_msg      => 'BEGIN of GenerateAcctLinetypes'
3382          ,p_level    => C_LEVEL_PROCEDURE
3383          ,p_module   => l_log_module);
3384 
3385 END IF;
3386 
3387 l_alts := ' l_actual_flag := NULL;  l_actual_gain_loss_ref := ''#####'';';
3388 l_alt  := NULL;
3389 
3390 IF p_array_alt_index.COUNT > 0 THEN
3391 
3392 FOR Idx IN p_array_alt_index.FIRST .. p_array_alt_index.LAST LOOP
3393 
3394   IF p_array_alt_index.EXISTS(Idx) THEN
3395 
3396      l_alt  := C_ALT_PROC ;
3397      l_alt  := xla_cmp_string_pkg.replace_token(l_alt ,'$alt_code$', TO_CHAR( p_array_alt_index(Idx) ));  -- 4417664
3398 
3399      l_alt  := xla_cmp_string_pkg.replace_token (l_alt ,'$parameters$'
3400                 ,xla_cmp_call_fct_pkg.GetLineParameters(
3401                     p_array_source_index   => p_rec_aad_objects.array_array_object(p_array_alt_index(Idx))
3402                   , p_array_source_level   => p_array_evt_source_Level
3403                   , p_rec_sources          => p_rec_sources)
3404                 );
3405      l_alts := l_alts || g_chr_newline|| l_alt;
3406 
3407   END IF;
3408 
3409 END LOOP;
3410 
3411 END IF;
3412 
3413 IF l_alts IS NULL THEN l_alts:=' null;';END IF;
3414 
3415 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3416       trace
3417          (p_msg      => 'END of GenerateAcctLinetypes'
3418          ,p_level    => C_LEVEL_PROCEDURE
3419          ,p_module   => l_log_module);
3420 END IF;
3421 RETURN l_alts;
3422 EXCEPTION
3423 WHEN VALUE_ERROR THEN
3424         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3425             trace
3426                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
3427                ,p_level    => C_LEVEL_EXCEPTION
3428                ,p_module   => l_log_module);
3429         END IF;
3430         RAISE;
3431 WHEN xla_exceptions_pkg.application_exception   THEN
3432         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3433             trace
3434                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
3435                ,p_level    => C_LEVEL_EXCEPTION
3436                ,p_module   => l_log_module);
3437         END IF;
3438         RAISE;
3439  WHEN OTHERS    THEN
3440       xla_exceptions_pkg.raise_message
3441          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GenerateAcctLinetypes ');
3442 END GenerateAcctLinetypes;
3443 
3444 
3445 
3446 /*---------------------------------------------------------------+
3447 |                                                                |
3448 |  Private function                                              |
3449 |                                                                |
3450 |   GenerateAccRevBody                                           |
3451 |                                                                |
3452 |   4262811 -                                                    |
3453 |   Retrieve the source of the accrual reversal GL date          |
3454 |   accounting attribute.                                        |
3455 |                                                                |
3456 |   4884853 - add logic to get array_gl_date for accrual reversal|
3457 |                                                                |
3458 +---------------------------------------------------------------*/
3459 FUNCTION GenerateAccRevBody (
3460     p_array_hdr_acctg_source       IN xla_cmp_source_pkg.t_array_VL30
3461   , p_array_hdr_acct_attr_source   IN xla_cmp_source_pkg.t_array_int  -- (to generate ACCRUAL_REVERSAL_GL_DATE)
3462   , p_rec_sources                  IN xla_cmp_source_pkg.t_rec_sources
3463 )
3464 RETURN CLOB
3465 IS
3466 
3467 l_body               CLOB;
3468 l_log_module         VARCHAR2(240);
3469 
3470 l_AccRevGlDateIdx    NUMBER;
3471 l_source_code         VARCHAR2(30);
3472 l_source_type_code    VARCHAR2(1);
3473 
3474 BEGIN
3475 
3476 IF g_log_enabled THEN
3477       l_log_module := C_DEFAULT_MODULE||'.GenerateAccRevBody';
3478 END IF;
3479 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3480       trace
3481          (p_msg      => 'BEGIN of GenerateAccRevBody'
3482          ,p_level    => C_LEVEL_PROCEDURE
3483          ,p_module   => l_log_module);
3484 END IF;
3485 
3486 l_body := NULL;
3487 l_AccRevGlDateIdx  := IsOptionFlagInEventExtract(
3488                       p_source_option         => 'ACCRUAL_REVERSAL_GL_DATE' -- value in this attr indicates to reverse
3489                     , p_array_source_code     => p_array_hdr_acctg_source);
3490 
3491 
3492 IF (l_AccRevGlDateIdx IS NULL) THEN
3493   l_body := '
3494   -----------------------------------------------
3495   -- No accrual reversal for the event class/type
3496   -----------------------------------------------';
3497 ELSE
3498 
3499    l_body := C_ACC_REV_BODY;
3503    l_source_code      := p_rec_sources.array_source_code     (p_array_hdr_acct_attr_source(l_AccRevGlDateIdx));
3500 -- l_source_type_code := p_rec_sources.array_source_type_code(l_AccRevGlDateIdx);
3501 -- l_source_code      := p_rec_sources.array_source_code(l_AccRevGlDateIdx);
3502    l_source_type_code := p_rec_sources.array_source_type_code(p_array_hdr_acct_attr_source(l_AccRevGlDateIdx));
3504 
3505    IF (l_source_type_code = 'Y' and l_source_code = 'XLA_NEXT_DAY') THEN
3506        l_body := xla_cmp_string_pkg.replace_token (l_body,'$if_cond$','');
3507        l_body := xla_cmp_string_pkg.replace_token (l_body,'$end_if$', '');
3508        l_body := xla_cmp_string_pkg.replace_token (l_body,'$accrual_reversal_body2$'
3509               ,'
3510               ---------------------- XLA_NEXT_DAY ----------------------
3511               XLA_AE_HEADER_PKG.g_rec_header_new.array_acc_rev_gl_date_option(g_last_hdr_idx) := ''XLA_NEXT_DAY'';
3512               XLA_AE_HEADER_PKG.GetAccrualRevDate(g_last_hdr_idx
3513                                        ,XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(g_last_hdr_idx)
3514                                        ,XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
3515                                        ,XLA_AE_HEADER_PKG.g_rec_header_new.array_acc_rev_gl_date_option(g_last_hdr_idx));
3516               ');
3517    ELSIF (l_source_type_code = 'Y' and l_source_code = 'XLA_FIRST_DAY_NEXT_GL_PERIOD') THEN
3518        l_body := xla_cmp_string_pkg.replace_token (l_body,'$if_cond$','');
3519        l_body := xla_cmp_string_pkg.replace_token (l_body,'$accrual_reversal_body2$'
3520               ,'
3521               ---------------------- XLA_FIRST_DAY_NEXT_GL_PERIOD ----------------------
3522               XLA_AE_HEADER_PKG.g_rec_header_new.array_acc_rev_gl_date_option(g_last_hdr_idx) := ''XLA_FIRST_DAY_NEXT_GL_PERIOD'';
3523               XLA_AE_HEADER_PKG.GetAccrualRevDate(g_last_hdr_idx
3524                                        ,XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(g_last_hdr_idx)
3525                                        ,XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
3526                                        ,XLA_AE_HEADER_PKG.g_rec_header_new.array_acc_rev_gl_date_option(g_last_hdr_idx));
3527               ');
3528        l_body := xla_cmp_string_pkg.replace_token (l_body,'$end_if$', '');
3529 
3530    ELSIF (l_source_type_code = 'Y' and l_source_code = 'XLA_LAST_DAY_NEXT_GL_PERIOD') THEN
3531        l_body := xla_cmp_string_pkg.replace_token (l_body,'$if_cond$','');
3532        l_body := xla_cmp_string_pkg.replace_token (l_body,'$accrual_reversal_body2$'
3533               ,'
3534               ---------------------- XLA_LAST_DAY_NEXT_GL_PERIOD ----------------------
3535               XLA_AE_HEADER_PKG.g_rec_header_new.array_acc_rev_gl_date_option(g_last_hdr_idx) := ''XLA_LAST_DAY_NEXT_GL_PERIOD'';
3536               XLA_AE_HEADER_PKG.GetAccrualRevDate(g_last_hdr_idx
3537                                        ,XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(g_last_hdr_idx)
3538                                        ,XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
3539                                        ,XLA_AE_HEADER_PKG.g_rec_header_new.array_acc_rev_gl_date_option(g_last_hdr_idx));
3540               ');
3541        l_body := xla_cmp_string_pkg.replace_token (l_body,'$end_if$', '');
3542 
3543    ELSE
3544        l_body := xla_cmp_string_pkg.replace_token (l_body ,'$if_cond$' ,'IF l_acc_rev_gl_date_source IS NOT NULL THEN ');
3545        l_body := xla_cmp_string_pkg.replace_token (l_body,'$accrual_reversal_body2$'
3546               ,'
3547               ---------------------- NONE - Standard Source  ----------------------
3548               IF l_acc_rev_gl_date_source < XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx) THEN
3549                  xla_accounting_err_pkg.build_message
3550                            (p_appli_s_name            => ''XLA''
3551                            ,p_msg_name                => ''XLA_MA_INVALID_GL_DATE''
3552                            ,p_token_1                 => ''ACCRUAL_REVERSAL_DATE''
3553                            ,p_value_1                 => l_acc_rev_gl_date_source
3554                            ,p_token_2                 => ''ACCRUAL_GL_DATE''    -- 4262811
3555                            ,p_value_2                 => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
3556                            ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
3557                            ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
3558                            ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
3559                           );
3560               END IF;
3561               XLA_AE_HEADER_PKG.g_rec_header_new.array_acc_rev_gl_date_option(g_last_hdr_idx) := ''NONE'';
3562               XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_last_hdr_idx) := trunc(l_acc_rev_gl_date_source);
3563               ');
3564        l_body := xla_cmp_string_pkg.replace_token (l_body ,'$end_if$' , 'END IF;');
3565 
3566    END IF;
3567 END IF;
3568 RETURN l_body;
3569 
3570 EXCEPTION
3571 WHEN VALUE_ERROR THEN
3572         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3573             trace
3574                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
3575                ,p_level    => C_LEVEL_EXCEPTION
3576                ,p_module   => l_log_module);
3577         END IF;
3578         RAISE;
3579 WHEN xla_exceptions_pkg.application_exception   THEN
3580         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3581             trace
3582                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
3586         RAISE;
3583                ,p_level    => C_LEVEL_EXCEPTION
3584                ,p_module   => l_log_module);
3585         END IF;
3587  WHEN OTHERS    THEN
3588       xla_exceptions_pkg.raise_message
3589          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GenerateAccRevBody ');
3590 END GenerateAccRevBody;
3591 
3592 
3593 /*---------------------------------------------------------------+
3594 |                                                                |
3595 |  Private function                                              |
3596 |                                                                |
3597 |   GenerateProcedureBody                                        |
3598 |                                                                |
3599 | Generates EventClass_x()/EventType_x() body function           |
3600 |                                                                |
3601 +---------------------------------------------------------------*/
3602 
3603 FUNCTION GenerateProcedureBody  (
3604   p_application_id               IN NUMBER
3605 , p_product_rule_code            IN VARCHAR2
3606 , p_product_rule_type_code       IN VARCHAR2
3607 , p_amb_context_code             IN VARCHAR2
3608 , p_entity                       IN VARCHAR2
3609 , p_event_class                  IN VARCHAR2
3610 , p_event_type                   IN VARCHAR2
3611 
3612 , p_hdr_description_index        IN BINARY_INTEGER
3613 , p_array_alt_index              IN xla_cmp_source_pkg.t_array_ByInt
3614 , p_array_evt_source_Level       IN xla_cmp_source_pkg.t_array_VL1
3615 
3616 , p_array_hdr_acctg_source       IN xla_cmp_source_pkg.t_array_VL30
3617 , p_array_hdr_acctg_source_type  IN xla_cmp_source_pkg.t_array_VL1
3618 , p_array_hdr_acct_attr_source   IN xla_cmp_source_pkg.t_array_int
3619 , p_array_line_acctg_source      IN xla_cmp_source_pkg.t_array_VL30
3620 , p_array_line_acctg_source_type IN xla_cmp_source_pkg.t_array_VL1
3621 , p_array_line_acct_attr_source  IN xla_cmp_source_pkg.t_array_int
3622 
3623 , p_array_table_name             IN xla_cmp_source_pkg.t_array_VL30
3624 , p_array_table_type             IN xla_cmp_source_pkg.t_array_VL30
3625 , p_array_table_hash             IN xla_cmp_source_pkg.t_array_VL30
3626 , p_array_populated_flag         IN xla_cmp_source_pkg.t_array_VL1
3627 
3628 , p_array_h_source_index         IN xla_cmp_source_pkg.t_array_ByInt
3629 , p_array_h_table_index          IN xla_cmp_source_pkg.t_array_ByInt
3630 
3631 , p_array_h_mls_source_index     IN xla_cmp_source_pkg.t_array_ByInt
3632 , p_array_h_mls_table_index      IN xla_cmp_source_pkg.t_array_ByInt
3633 
3634 , p_array_l_source_index         IN xla_cmp_source_pkg.t_array_ByInt
3635 , p_array_l_table_index          IN xla_cmp_source_pkg.t_array_ByInt
3636 
3637 , p_array_l_mls_source_index     IN xla_cmp_source_pkg.t_array_ByInt
3638 , p_array_l_mls_table_index      IN xla_cmp_source_pkg.t_array_ByInt
3639 
3640 , p_rec_sources                  IN OUT NOCOPY xla_cmp_source_pkg.t_rec_sources
3641 , p_rec_aad_objects              IN xla_cmp_source_pkg.t_rec_aad_objects
3642 )
3643 RETURN CLOB
3644 IS
3645 
3646 l_body                         CLOB;
3647 l_ThirdPartyIdx                NUMBER;
3648 l_AcctReversalIdx              NUMBER;
3649 l_TrxReversalIdx               NUMBER;
3650 l_count                        INTEGER;
3651 l_log_module                   VARCHAR2(240);
3652 
3653 BEGIN
3654 IF g_log_enabled THEN
3655       l_log_module := C_DEFAULT_MODULE||'.GenerateProcedureBody';
3656 END IF;
3657 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3658       trace
3659          (p_msg      => 'BEGIN of GenerateProcedureBody'
3660          ,p_level    => C_LEVEL_PROCEDURE
3661          ,p_module   => l_log_module);
3662       trace
3663          (p_msg      => 'event class:'||p_event_class
3664                       ||', event type:'||p_event_type
3665          ,p_level    => C_LEVEL_PROCEDURE
3666          ,p_module   => l_log_module);
3667 
3668 END IF;
3669 
3670 GetIndexOfOptionFlags(
3671   p_array_hdr_acctg_source            => p_array_hdr_acctg_source
3672 , p_array_hdr_acct_attr_source        => p_array_hdr_acct_attr_source
3673 , p_array_line_acctg_source           => p_array_line_acctg_source
3674 , p_array_line_acct_attr_source       => p_array_line_acct_attr_source
3675 , p_ThirdPartyIdx                     => l_ThirdPartyIdx
3676 , p_AcctReversalIdx                   => l_AcctReversalIdx
3677 , p_TrxReversalIdx                    => l_TrxReversalIdx);
3678 
3679 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3680    trace
3681       (p_msg      => 'l_ThirdPartyIdx = '||l_ThirdPartyIdx
3682                    ||', l_AcctReversalIdx = '||l_AcctReversalIdx
3683                    ||', l_TrxReversalIdx = '||l_TrxReversalIdx
3684       ,p_level    => C_LEVEL_STATEMENT
3685       ,p_module   => l_log_module);
3686 END IF;
3687 
3688 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3689    l_count := p_array_h_source_index.COUNT + p_array_h_mls_source_index.COUNT;
3690    trace
3691       (p_msg      => 'generate = '||l_count
3692       ,p_level    => C_LEVEL_STATEMENT
3693       ,p_module   => l_log_module);
3694 END IF;
3695 
3696 l_body := C_EVENT_BODY;
3697 
3698 --bug 4492149
3699 --IF (p_array_h_source_index.COUNT + p_array_h_mls_source_index.COUNT > 0) THEN
3700 
3701    IF l_ThirdPartyIdx IS NOT NULL AND
3702       p_array_hdr_acct_attr_source.EXISTS(l_ThirdPartyIdx) AND
3703       p_array_hdr_acct_attr_source(l_ThirdPartyIdx) IS NOT NULL THEN
3704       --
3705       -- Change third party process
3709 
3706       --
3707       l_body := xla_cmp_string_pkg.replace_token
3708                    (l_body,'$third_party_code$', C_THIRD_PARTY_CHANGE_BODY);
3710       l_body := xla_cmp_string_pkg.replace_token(l_body
3711                  ,'$third_party_change$'
3712                  , xla_cmp_source_pkg.GenerateSource(
3713                            p_Index            => p_array_hdr_acct_attr_source(l_ThirdPartyIdx)
3714                          , p_rec_sources      => p_rec_sources
3715                          , p_variable         => p_array_hdr_acctg_source_type(l_ThirdPartyIdx)
3716                          , p_translated_flag  => 'N'
3717                          ));
3718    ELSE
3719       l_body := xla_cmp_string_pkg.replace_token(l_body   -- 4417664
3720                        ,'$third_party_code$'
3721                        ,'-- No Third Party Code generated');
3722    END IF;
3723 
3724 
3725    IF l_TrxReversalIdx IS NOT NULL AND
3726       p_array_hdr_acct_attr_source.EXISTS(l_TrxReversalIdx) AND
3727       p_array_hdr_acct_attr_source(l_TrxReversalIdx) IS NOT NULL
3728    THEN
3729       l_body := xla_cmp_string_pkg.replace_token
3730                    (l_body,'$trx_reversal_source$'
3731                    ,xla_cmp_source_pkg.GenerateSource(
3732                         p_Index             => p_array_hdr_acct_attr_source(l_TrxReversalIdx)
3733                        ,p_rec_sources       => p_rec_sources
3734                        ,p_variable          => p_array_hdr_acctg_source_type(l_TrxReversalIdx)
3735                        ,p_translated_flag   => 'N')
3736                    );
3737 
3738    ELSE
3739       l_body := xla_cmp_string_pkg.replace_token(l_body,'$trx_reversal_source$','NULL');  -- 4417664
3740    END IF;
3741 
3742    IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3743         trace
3744            (p_msg      => '-> CALL xla_cmp_extract_pkg.GenerateFetchHeaderCursor API'
3745            ,p_level    => C_LEVEL_STATEMENT
3746            ,p_module   => l_log_module);
3747    END IF;
3748    --
3749    -- generate 'Open header cursor'
3750    --
3751     l_body := xla_cmp_string_pkg.replace_token
3752                (l_body
3753                ,'$header_var$'
3754                ,xla_cmp_extract_pkg.GenerateFetchHeaderCursor
3755                    (p_array_h_source_index       =>  p_array_h_source_index
3756                    ,p_array_h_mls_source_index   =>  p_array_h_mls_source_index
3757                    ,p_array_lookup_type          =>  p_rec_sources.array_lookup_type
3758                    ,p_array_view_application_id  =>  p_rec_sources.array_view_application_id)
3759                );
3760 
3761   --
3762   -- generate the code to cache header sources
3763   l_body := xla_cmp_string_pkg.replace_token
3764                (l_body
3765                ,'$cache_header_sources$'
3766                ,xla_cmp_extract_pkg.GenerateCacheHdrSources
3767                    (p_array_h_source_index       =>  p_array_h_source_index
3768                    ,p_array_h_mls_source_index   =>  p_array_h_mls_source_index
3769                    ,p_array_lookup_type          =>  p_rec_sources.array_lookup_type
3770                    ,p_array_view_application_id  =>  p_rec_sources.array_view_application_id
3771                    ,p_array_datatype_code        =>  p_rec_sources.array_datatype_code)
3772                );
3773 
3774    -- generate 'header accounting sources'
3775    --
3776    l_body := xla_cmp_string_pkg.replace_token
3777                 (l_body
3778                 ,'$hdr_accounting_attributes$'
3779                 ,GenerateHdrAcctgSources
3780                     (p_array_hdr_acctg_source       => p_array_hdr_acctg_source
3781                     ,p_array_hdr_acctg_source_type  => p_array_hdr_acctg_source_type
3782                     ,p_array_hdr_acct_attr_source   => p_array_hdr_acct_attr_source
3783                     ,p_rec_sources                  => p_rec_sources)
3784                 );
3785 
3786    -------------------------------------------------------------------
3787    -- 4262811 Generate Accrual Reversal
3788    -------------------------------------------------------------------
3789    l_body := xla_cmp_string_pkg.replace_token
3790                 (l_body
3791                 ,'$accrual_reversal_body$'
3792                 ,GenerateAccRevBody(
3793                      p_array_hdr_acctg_source      => p_array_hdr_acctg_source
3794                     ,p_array_hdr_acct_attr_source  => p_array_hdr_acct_attr_source
3795                     ,p_rec_sources                 => p_rec_sources
3796                         ));
3797    --
3798    -- generate 'header Description'
3799    --
3800    l_body := xla_cmp_string_pkg.replace_token
3801                 (l_body
3802                 ,'$call_header_description$'
3803                 , GenerateHdrDescription  (
3804                      p_hdr_description_index    => p_hdr_description_index
3805                    , p_rec_aad_objects          => p_rec_aad_objects
3806                    , p_rec_sources              => p_rec_sources
3807                     )
3808                 );
3809 
3810    --
3811    -- generate  'header Analytical criteria'
3812    --
3813    IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3814       trace
3815          (p_msg      => '-> CALL xla_cmp_analytic_criteria_pkg.GenerateHdrAnalyticCriteria API'
3816          ,p_level    => C_LEVEL_STATEMENT
3817          ,p_module   => l_log_module);
3818    END IF;
3819 
3820    l_body := xla_cmp_string_pkg.replace_token
3821                 (l_body
3825                    ,p_product_rule_code            => p_product_rule_code
3822                 ,'$call_hdr_analytic_criteria$'
3823                 ,xla_cmp_analytic_criteria_pkg.GenerateHdrAnalyticCriteria
3824                    (p_application_id               => p_application_id
3826                    ,p_product_rule_type_code       => p_product_rule_type_code
3827                    ,p_amb_context_code             => p_amb_context_code
3828                    ,p_entity                       => p_entity
3829                    ,p_event_class                  => p_event_class
3830                    ,p_event_type                   => p_event_type
3831                    ,p_rec_sources                  => p_rec_sources)
3832                  );
3833 
3834 --END IF;
3835 
3836 --bug 4492149
3837 --IF (p_array_l_source_index.COUNT +  p_array_l_mls_source_index.COUNT > 0 ) THEN
3838     l_body  := xla_cmp_string_pkg.replace_token
3839                   (l_body
3840                   ,'$lines_body$'
3841                   ,C_BODY_LINES);
3842 
3843     l_body := xla_cmp_string_pkg.replace_token
3844                  (l_body
3845                  ,'$gain_loss_account_params$'
3846                  ,GenerateGainLossAcctSources
3847                     (p_array_hdr_acctg_source       => p_array_hdr_acctg_source
3848                     ,p_array_hdr_acctg_source_type  => p_array_hdr_acctg_source_type
3849                     ,p_array_hdr_acct_attr_source   => p_array_hdr_acct_attr_source
3850                     ,p_rec_sources                  => p_rec_sources)
3851                  );
3852 
3853     IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3854        trace
3855           (p_msg      => '-> CALL xla_cmp_extract_pkg.GenerateFetchLineCursor API'
3856           ,p_level    => C_LEVEL_STATEMENT
3857           ,p_module   => l_log_module);
3858     END IF;
3859     --
3860     -- Generate 'Open Line cursor'
3861     --
3862     l_body := xla_cmp_string_pkg.replace_token
3863                  (l_body
3864                  ,'$line_var$'
3865                  ,xla_cmp_extract_pkg.GenerateFetchLineCursor
3866                      (p_array_l_source_index        => p_array_l_source_index
3867                      ,p_array_l_mls_source_index    => p_array_l_mls_source_index
3868                      ,p_array_source_code           => p_rec_sources.array_source_code
3869                      ,p_array_lookup_type           => p_rec_sources.array_lookup_type
3870                      ,p_array_view_application_id   => p_rec_sources.array_view_application_id)
3871                   );
3872     --
3873     -- generate 'Accounting line type procedures'
3874     --
3875     l_body := xla_cmp_string_pkg.replace_token
3876                  (l_body
3877                  ,'$call_alts$'
3878                  ,  GenerateAcctLinetypes  (
3879                      p_array_alt_index          => p_array_alt_index
3880                    , p_array_evt_source_Level   => p_array_evt_source_Level
3881                    , p_rec_aad_objects          => p_rec_aad_objects
3882                    , p_rec_sources              => p_rec_sources
3883                    )
3884                  );
3885     --
3886     -- replace amb_context_code
3887     --
3888     l_body := xla_cmp_string_pkg.replace_token
3889                  (l_body
3890                  ,'$amb_context_code$'
3891                  ,  p_amb_context_code
3892                  );
3893     --
3894     -- generate line level reversal code
3895     --
3896 
3897     IF l_AcctReversalIdx IS NOT NULL OR
3898        p_array_line_acct_attr_source.EXISTS(l_AcctReversalIdx) AND
3899        p_array_line_acct_attr_source(l_AcctReversalIdx) IS NOT NULL
3900     THEN
3901        l_body := xla_cmp_string_pkg.replace_token      -- 4417664
3902                    (l_body,'$acct_reversal_source$'
3903                    , xla_cmp_source_pkg.GenerateSource
3904                        (p_Index            => p_array_line_acct_attr_source(l_AcctReversalIdx)
3905                        ,p_rec_sources      => p_rec_sources
3906                        ,p_variable         => p_array_line_acctG_source_type(l_AcctReversalIdx)
3907                        ,p_translated_flag  => 'N')
3908                    );
3909 
3910 
3911        l_body := xla_cmp_string_pkg.replace_token
3912                     (l_body,'$acct_reversal_code$'
3913                        ,GenerateReversalAcctgSources
3914                         (p_array_line_acctg_source      => p_array_line_acctg_source
3915                         ,p_array_line_acctg_source_type => p_array_line_acctg_source_type
3916                         ,p_array_line_acct_attr_source  => p_array_line_acct_attr_source
3917                         ,p_rec_sources                  => p_rec_sources)
3918                     );
3919     ELSE
3920        l_body := xla_cmp_string_pkg.replace_token(l_body,'$acct_reversal_source$','NULL');  -- 4417664
3921        l_body := xla_cmp_string_pkg.replace_token(l_body,'$acct_reversal_code$','      -- No reversal code generated');  -- 4417664
3922     END IF;
3923 
3924 
3925 --END IF;
3926 
3927 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3928       trace
3929          (p_msg      => 'END of GenerateProcedureBody'
3930          ,p_level    => C_LEVEL_PROCEDURE
3931          ,p_module   => l_log_module);
3932       trace
3933          (p_msg      => 'l_body:'||to_char(length(l_body))
3934          ,p_level    => C_LEVEL_PROCEDURE
3935          ,p_module   => l_log_module);
3936 END IF;
3937 RETURN l_body;
3938 EXCEPTION
3942                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
3939 WHEN VALUE_ERROR THEN
3940         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3941             trace
3943                ,p_level    => C_LEVEL_EXCEPTION
3944                ,p_module   => l_log_module);
3945         END IF;
3946         RAISE;
3947 WHEN xla_exceptions_pkg.application_exception   THEN
3948         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
3949             trace
3950                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
3951                ,p_level    => C_LEVEL_EXCEPTION
3952                ,p_module   => l_log_module);
3953         END IF;
3954         RAISE;
3955  WHEN OTHERS    THEN
3956       xla_exceptions_pkg.raise_message
3957          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GenerateProcedureBody ');
3958 END GenerateProcedureBody;
3959 
3960 /*---------------------------------------------------------------+
3961 |                                                                |
3962 |  Private function                                              |
3963 |                                                                |
3964 |   PopulateBCObjectNames                                         |
3965 |                                                                |
3966 | Generates Event_$Index$() function                             |
3967 |                                                                |
3968 +---------------------------------------------------------------*/
3969 
3970 PROCEDURE PopulateBCObjectNames(
3971 p_array_table_name     IN OUT NOCOPY xla_cmp_source_pkg.t_array_VL30,
3972 p_array_join_condition IN OUT NOCOPY xla_cmp_source_pkg.t_array_VL2000
3973 )
3974 IS
3975 l_log_module                    VARCHAR2(240);
3976 BEGIN
3977 
3978 IF g_log_enabled THEN
3979       l_log_module := C_DEFAULT_MODULE||'.PopulateBCObjectNames';
3980 END IF;
3981 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3982       trace
3983          (p_msg      => 'BEGIN of PopulateBCObjectNames'
3984          ,p_level    => C_LEVEL_PROCEDURE
3985          ,p_module   => l_log_module);
3986 END IF;
3987 
3988 For idx in 1..p_array_table_name.COUNT loop
3989   IF p_array_table_name(idx) = 'AP_INVOICE_EXTRACT_DETAILS_V' THEN
3990     P_array_table_name(idx) := 'AP_EXTRACT_INVOICE_DTLS_BC_V';
3991   ELSIF p_array_table_name(idx) = 'AP_PREPAYAPP_EXTRACT_DETAILS_V' THEN
3992     P_array_table_name(idx) := 'AP_PREPAYAPP_EXTRACT_DTLS_BC_V';
3993   END IF;
3994 End loop;
3995 
3996 For idx in 1..p_array_join_condition.COUNT loop
3997   p_array_join_condition(idx) := replace(p_array_join_condition(idx)
3998                                         ,'AP_INVOICE_EXTRACT_DETAILS_V'
3999                                         ,'AP_EXTRACT_INVOICE_DTLS_BC_V');
4000   p_array_join_condition(idx) := replace(p_array_join_condition(idx)
4001                                         ,'AP_PREPAYAPP_EXTRACT_DETAILS_V'
4002                                         ,'AP_PREPAYAPP_EXTRACT_DTLS_BC_V');
4003 End loop;
4004 
4005 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4006       trace
4007          (p_msg      => 'END of PopulateBCObjectNames'
4008          ,p_level    => C_LEVEL_PROCEDURE
4009          ,p_module   => l_log_module);
4010 END IF;
4011 EXCEPTION
4012  WHEN OTHERS    THEN
4013       xla_exceptions_pkg.raise_message
4014          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.PopulateBCObjectNames ');
4015 END PopulateBCObjectNames;
4016 
4017 
4018 
4019 /*---------------------------------------------------------------+
4020 |                                                                |
4021 |  Private function                                              |
4022 |                                                                |
4023 |   GenerateOneProcedure                                         |
4024 |                                                                |
4025 | Generates Event_$Index$() function                             |
4026 |                                                                |
4027 +---------------------------------------------------------------*/
4028 
4029 FUNCTION GenerateOneProcedure  (
4030   p_application_id               IN NUMBER
4031 , p_product_rule_code            IN VARCHAR2
4032 , p_product_rule_type_code       IN VARCHAR2
4033 , p_amb_context_code             IN VARCHAR2
4034 , p_entity                       IN VARCHAR2
4035 , p_event_class                  IN VARCHAR2
4036 , p_event_type                   IN VARCHAR2
4037 --
4038 , p_hdr_description_index        IN BINARY_INTEGER
4039 , p_array_alt_index              IN xla_cmp_source_pkg.t_array_ByInt
4040 , p_array_evt_source_Level       IN xla_cmp_source_pkg.t_array_VL1
4041 --
4042 , p_array_hdr_acctg_source       IN xla_cmp_source_pkg.t_array_VL30
4043 , p_array_hdr_acctg_source_type  IN xla_cmp_source_pkg.t_array_VL1
4044 , p_array_hdr_acct_attr_source   IN xla_cmp_source_pkg.t_array_int
4045 , p_array_line_acctg_source      IN xla_cmp_source_pkg.t_array_VL30
4046 , p_array_line_acctg_source_type IN xla_cmp_source_pkg.t_array_VL1
4047 , p_array_line_acct_attr_source  IN xla_cmp_source_pkg.t_array_int
4048 --
4049 , p_array_table_name             IN xla_cmp_source_pkg.t_array_VL30
4050 , p_array_parent_table_index           IN xla_cmp_source_pkg.t_array_ByInt
4051 , p_array_table_type             IN xla_cmp_source_pkg.t_array_VL30
4052 , p_array_table_hash             IN xla_cmp_source_pkg.t_array_VL30
4053 , p_array_populated_flag         IN xla_cmp_source_pkg.t_array_VL1
4054 --
4055 , p_array_ref_obj_flag           IN xla_cmp_source_pkg.t_array_VL1
4059 , p_array_h_table_index          IN xla_cmp_source_pkg.t_array_ByInt
4056 , p_array_join_condition         IN xla_cmp_source_pkg.t_array_VL2000
4057 --
4058 , p_array_h_source_index         IN xla_cmp_source_pkg.t_array_ByInt
4060 --
4061 , p_array_h_mls_source_index     IN xla_cmp_source_pkg.t_array_ByInt
4062 , p_array_h_mls_table_index      IN xla_cmp_source_pkg.t_array_ByInt
4063 --
4064 , p_array_l_source_index         IN xla_cmp_source_pkg.t_array_ByInt
4065 , p_array_l_table_index          IN xla_cmp_source_pkg.t_array_ByInt
4066 --
4067 , p_array_l_mls_source_index     IN xla_cmp_source_pkg.t_array_ByInt
4068 , p_array_l_mls_table_index      IN xla_cmp_source_pkg.t_array_ByInt
4069 --
4070 , p_rec_sources                  IN OUT NOCOPY xla_cmp_source_pkg.t_rec_sources
4071 , p_rec_aad_objects              IN xla_cmp_source_pkg.t_rec_aad_objects
4072 --
4073 , p_extract_status               IN BOOLEAN
4074 , p_procedure                    IN VARCHAR2
4075 )
4076 RETURN CLOB
4077 IS
4078 l_event                         CLOB;
4079 l_log_module                    VARCHAR2(240);
4080 BEGIN
4081 
4082 IF g_log_enabled THEN
4083       l_log_module := C_DEFAULT_MODULE||'.GenerateOneProcedure';
4084 END IF;
4085 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4086       trace
4087          (p_msg      => 'BEGIN of GenerateOneProcedure'
4088          ,p_level    => C_LEVEL_PROCEDURE
4089          ,p_module   => l_log_module);
4090 END IF;
4091 
4092 l_event     := C_EVENT_TYPE_PROC;
4093 
4094 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4095       trace
4096          (p_msg      => 'p_extract_status = '||
4097            CASE WHEN p_extract_status THEN 'TRUE' ELSE 'FALSE' END
4098          ,p_level    => C_LEVEL_STATEMENT
4099          ,p_module   => l_log_module);
4100 END IF;
4101 
4102 IF NOT p_extract_status THEN
4103 
4104    l_event     := xla_cmp_string_pkg.replace_token (l_event, '$header_types$',  ' ');  -- 4417664
4105    l_event     := xla_cmp_string_pkg.replace_token (l_event, '$line_types$',  ' ');  -- 4417664
4106    l_event     := xla_cmp_string_pkg.replace_token (l_event, '$header_variables$'  ,  ' ');  -- 4417664
4107    l_event     := xla_cmp_string_pkg.replace_token (l_event, '$line_variables$'   ,  ' ');  -- 4417664
4108    l_event     := xla_cmp_string_pkg.replace_token (l_event, '$header_cursor$',  ' ');  -- 4417664
4109    l_event     := xla_cmp_string_pkg.replace_token (l_event, '$line_cursor$'  ,  ' ');  -- 4417664
4110    l_event     := xla_cmp_string_pkg.replace_token (l_event, '$close_header_cursor$', ' ' );  -- 4417664
4111    l_event     := xla_cmp_string_pkg.replace_token (l_event, '$close_line_cursor$',  ' ' );  -- 4417664
4112    l_event     := xla_cmp_string_pkg.replace_token (l_event, '$event_body$'   ,  'NULL;');  -- 4417664
4113 
4114 ELSE
4115 
4116    l_event     := xla_cmp_string_pkg.replace_token
4117                      (l_event
4118                      ,'$event_body$'
4119                      ,GenerateProcedureBody
4120                          (p_application_id               => p_application_id
4121                          ,p_product_rule_code            => p_product_rule_code
4122                          ,p_product_rule_type_code       => p_product_rule_type_code
4123                          ,p_amb_context_code             => p_amb_context_code
4124                          ,p_entity                       => p_entity
4125                          ,p_event_class                  => p_event_class
4126                          ,p_event_type                   => p_event_type
4127                          --
4128                          ,p_hdr_description_index        => p_hdr_description_index
4129                          ,p_array_alt_index              => p_array_alt_index
4130                         , p_array_evt_source_Level       => p_array_evt_source_Level
4131                          --
4132                          ,p_array_hdr_acctg_source       => p_array_hdr_acctg_source
4133                          ,p_array_hdr_acctg_source_type  => p_array_hdr_acctg_source_type
4134                          ,p_array_hdr_acct_attr_source   => p_array_hdr_acct_attr_source
4135                          ,p_array_line_acctg_source      => p_array_line_acctg_source
4136                          ,p_array_line_acctg_source_type => p_array_line_acctg_source_type
4137                          ,p_array_line_acct_attr_source  => p_array_line_acct_attr_source
4138                          --
4139                          ,p_array_table_name             => p_array_table_name
4140                          ,p_array_table_type             => p_array_table_type
4141                          ,p_array_table_hash             => p_array_table_hash
4142                          ,p_array_populated_flag         => p_array_populated_flag
4143                          --
4144                          ,p_array_h_source_index         => p_array_h_source_index
4145                          ,p_array_h_table_index          => p_array_h_table_index
4146                          --
4147                          ,p_array_h_mls_source_index     => p_array_h_mls_source_index
4148                          ,p_array_h_mls_table_index      => p_array_h_mls_table_index
4149                          --
4150                          ,p_array_l_source_index         => p_array_l_source_index
4151                          ,p_array_l_table_index          => p_array_l_table_index
4152                          --
4153                          ,p_array_l_mls_source_index     => p_array_l_mls_source_index
4154                          ,p_array_l_mls_table_index      => p_array_l_mls_table_index
4155                          --
4159 
4156                          ,p_rec_sources                  => p_rec_sources
4157                          ,p_rec_aad_objects              => p_rec_aad_objects)
4158                      );
4160   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4161 
4162       trace
4163          (p_msg      => 'after generateprocedurebody length of l_event:'||to_char(length(l_event))
4164          ,p_level    => C_LEVEL_PROCEDURE
4165          ,p_module   => l_log_module);
4166 
4167   END IF;
4168 
4169   IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4170       trace
4171          (p_msg      => 'COUNT: p_array_h_source_index = '||p_array_h_source_index.COUNT
4172                       ||', p_array_h_mls_source_index = '||p_array_h_mls_source_index.COUNT
4173          ,p_level    => C_LEVEL_STATEMENT
4174          ,p_module   => l_log_module);
4175   END IF;
4176 
4177   -- generate the declaration of header variables and header cursor
4178   --
4179    /*  --4492149
4180     IF (p_array_h_source_index.COUNT +  p_array_h_mls_source_index.COUNT > 0
4181      ) THEN
4182     */
4183      --
4184      -- generate array strucnture definitions for header sources
4185      --
4186      l_event     :=
4187         xla_cmp_string_pkg.replace_token
4188            (l_event, '$header_types$'
4189            ,xla_cmp_extract_pkg.GenerateHdrStructure
4190               (p_array_table_name             => p_array_table_name
4191               ,p_array_source_code            => p_rec_sources.array_source_code
4192               ,p_array_h_source_index         => p_array_h_source_index
4193               ,p_array_h_table_index          => p_array_h_table_index
4194               ,p_array_h_mls_source_index     => p_array_h_mls_source_index
4195               ,p_array_h_mls_table_index      => p_array_h_mls_table_index)
4196            );
4197 
4198       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4199           trace
4200              (p_msg      => 'after GenerateHdrStructure length of l_event = '||to_char(length(l_event))
4201              ,p_level    => C_LEVEL_PROCEDURE
4202              ,p_module   => l_log_module);
4203       END IF;
4204      --
4205      -- generate the declaration of header variables
4206      --
4207      l_event     :=
4208         xla_cmp_string_pkg.replace_token
4209            (l_event, '$header_variables$'
4210            ,xla_cmp_extract_pkg.GenerateHdrVariables
4211                (p_array_h_source_index         => p_array_h_source_index
4212                ,p_array_h_mls_source_index     => p_array_h_mls_source_index
4213                ,p_array_source_code            => p_rec_sources.array_source_code
4214                ,p_array_lookup_type            => p_rec_sources.array_lookup_type
4215                ,p_array_view_application_id    => p_rec_sources.array_view_application_id)
4216             );
4217 
4218       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4219           trace
4220              (p_msg      => 'after GenerateHdrVariables length of l_event = '||to_char(length(l_event))
4221              ,p_level    => C_LEVEL_PROCEDURE
4222              ,p_module   => l_log_module);
4223       END IF;
4224 
4225      --
4226      -- generate the header cursor
4227      --
4228      l_event     := xla_cmp_string_pkg.replace_token
4229                        (l_event
4230                        ,'$header_cursor$'
4231                        ,XLA_cmp_extract_pkg.GenerateHeaderCursor
4232                            (p_array_table_name           => p_array_table_name
4233                            ,p_array_parent_table_index         => p_array_parent_table_index
4234                            ,p_array_table_hash           => p_array_table_hash
4235                            ,p_array_populated_flag       => p_array_populated_flag
4236                            ,p_array_ref_obj_flag         => p_array_ref_obj_flag
4237                            ,p_array_join_condition       => p_array_join_condition
4238                            ,p_array_h_source_index       => p_array_h_source_index
4239                            ,p_array_h_table_index        => p_array_h_table_index
4240                            ,p_array_h_mls_source_index   => p_array_h_mls_source_index
4241                            ,p_array_h_mls_table_index    => p_array_h_mls_table_index
4242                            ,p_array_source_code          => p_rec_sources.array_source_code
4243                            ,p_array_lookup_type          => p_rec_sources.array_lookup_type
4244                            ,p_array_view_application_id  => p_rec_sources.array_view_application_id
4245                            ,p_procedure                  => p_procedure)
4246                        );
4247 
4248      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4249 
4250              trace
4251                 (p_msg      => 'after generateheadercursor length of l_event:'||to_char(length(l_event))
4252                 ,p_level    => C_LEVEL_PROCEDURE
4253                 ,p_module   => l_log_module);
4254 
4255      END IF;
4256      l_event     := xla_cmp_string_pkg.replace_token (l_event, '$close_header_cursor$', C_CLOSE_HEADER_CURSOR );-- 4417664
4257   /* --4492149
4258   ELSE
4259      l_event     := xla_cmp_string_pkg.replace_token (l_event, '$header_types$',' ');-- 4417664
4260      l_event     := xla_cmp_string_pkg.replace_token (l_event, '$header_variables$',' ');-- 4417664
4261      l_event     := xla_cmp_string_pkg.replace_token (l_event, '$header_cursor$',' ');-- 4417664
4262      l_event     := xla_cmp_string_pkg.replace_token (l_event, '$close_header_cursor$',  ' ' );-- 4417664
4263    END IF;
4264    */
4265    --
4269      IF (p_array_l_source_index.COUNT +
4266    -- generate line structures, line variables and line cursor
4267    --
4268    /* --4492149
4270        p_array_l_mls_source_index.COUNT > 0 )
4271     THEN
4272    */
4273      --
4274      -- generate the structure of line variables
4275      --
4276      --
4277      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4278 
4279               trace
4280                  (p_msg      => '-> CALL xla_cmp_extract_pkg.GenerateLineStructure API'
4281                  ,p_level    => C_LEVEL_STATEMENT
4282                  ,p_module   => l_log_module);
4283 
4284      END IF;
4285      --
4286      l_event     := xla_cmp_string_pkg.replace_token
4287                        (l_event
4288                        ,'$line_types$'
4289                        ,xla_cmp_extract_pkg.GenerateLineStructure
4290                            (p_array_table_name             => p_array_table_name
4291                            ,p_array_source_code            => p_rec_sources.array_source_code
4292                            ,p_array_l_source_index         => p_array_l_source_index
4293                            ,p_array_l_table_index          => p_array_l_table_index
4294                            ,p_array_l_mls_source_index     => p_array_l_mls_source_index
4295                            ,p_array_l_mls_table_index      => p_array_l_mls_table_index)
4296                        );
4297 
4298      --
4299      -- generate the declaration of line variables
4300      --
4301      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4302 
4303              trace
4304                 (p_msg      => 'after generatelineStructure length of l_event:'||to_char(length(l_event))
4305                 ,p_level    => C_LEVEL_PROCEDURE
4306                 ,p_module   => l_log_module);
4307               trace
4308                  (p_msg      => '-> CALL xla_cmp_extract_pkg.GenerateLineVariables API'
4309                  ,p_level    => C_LEVEL_STATEMENT
4310                  ,p_module   => l_log_module);
4311 
4312      END IF;
4313      --
4314      l_event     := xla_cmp_string_pkg.replace_token
4315                        (l_event
4316                        ,'$line_variables$'
4317                        ,xla_cmp_extract_pkg.GenerateLineVariables
4318                            (p_array_l_source_index         => p_array_l_source_index
4319                            ,p_array_l_mls_source_index     => p_array_l_mls_source_index
4320                            ,p_array_source_code            => p_rec_sources.array_source_code
4321                            ,p_array_lookup_type            => p_rec_sources.array_lookup_type
4322                            ,p_array_view_application_id    => p_rec_sources.array_view_application_id)
4323                        );
4324      --
4325      -- generate the declaration of line cursor
4326      --
4327      --
4328      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4329 
4330              trace
4331                 (p_msg      => 'after generatelinevariables length of l_event:'||to_char(length(l_event))
4332                 ,p_level    => C_LEVEL_PROCEDURE
4333                 ,p_module   => l_log_module);
4334               trace
4335                  (p_msg      => '-> CALL xla_cmp_extract_pkg.GenerateLineCursor API'
4336                  ,p_level    => C_LEVEL_STATEMENT
4337                  ,p_module   => l_log_module);
4338 
4339      END IF;
4340      --
4341      l_event     := xla_cmp_string_pkg.replace_token
4342                        (l_event
4343                        ,'$line_cursor$'
4344                        ,xla_cmp_extract_pkg.GenerateLineCursor
4345                            (p_application_id             => p_application_id
4346                            ,p_array_table_name           => p_array_table_name
4347                            ,p_array_parent_table_index         => p_array_parent_table_index
4348                            ,p_array_table_hash           => p_array_table_hash
4349                            ,p_array_populated_flag       => p_array_populated_flag
4350                            ,p_array_ref_obj_flag         => p_array_ref_obj_flag
4351                            ,p_array_join_condition       => p_array_join_condition
4352                            ,p_array_l_source_index       => p_array_l_source_index
4353                            ,p_array_l_table_index        => p_array_l_table_index
4354                            ,p_array_l_mls_source_index   => p_array_l_mls_source_index
4355                            ,p_array_l_mls_table_index    => p_array_l_mls_table_index
4356                            ,p_array_source_code          => p_rec_sources.array_source_code
4357                            ,p_array_lookup_type          => p_rec_sources.array_lookup_type
4358                            ,p_array_view_application_id  => p_rec_sources.array_view_application_id
4359                            ,p_procedure                  => p_procedure)
4360                        );
4361 
4362      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4363 
4364              trace
4365                 (p_msg      => 'after generatelinecursor length of l_event:'||to_char(length(l_event))
4366                 ,p_level    => C_LEVEL_PROCEDURE
4367                 ,p_module   => l_log_module);
4368               trace
4369                  (p_msg      => '-> CALL xla_cmp_extract_pkg.GenerateLineCursor API'
4370                  ,p_level    => C_LEVEL_STATEMENT
4371                  ,p_module   => l_log_module);
4372 
4373      END IF;
4377    ELSE
4374      l_event   := xla_cmp_string_pkg.replace_token (l_event, '$close_line_cursor$', C_CLOSE_LINE_CURSOR ); --4262811 awan
4375   --
4376 /*  --4492149
4378    l_event     := xla_cmp_string_pkg.replace_token (l_event, '$line_types$',' ');          -- 4417664
4379    l_event     := xla_cmp_string_pkg.replace_token (l_event, '$line_variables$', ' ');     -- 4417664
4380    l_event     := xla_cmp_string_pkg.replace_token (l_event, '$line_cursor$',' ');         -- 4417664
4381    l_event     := xla_cmp_string_pkg.replace_token (l_event, '$close_line_cursor$',  ' ' );-- 4417664
4382   END IF;
4383 */
4384 --
4385 END IF;
4386 
4387 --
4388 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4389       trace
4390          (p_msg      => 'END of GenerateOneProcedure'
4391          ,p_level    => C_LEVEL_PROCEDURE
4392          ,p_module   => l_log_module);
4393       trace
4394          (p_msg      => 'length of l_event:'||to_char(length(l_event))
4395          ,p_level    => C_LEVEL_PROCEDURE
4396          ,p_module   => l_log_module);
4397 END IF;
4398 RETURN l_event;
4399 EXCEPTION
4400 WHEN VALUE_ERROR THEN
4401         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4402             trace
4403                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
4404                ,p_level    => C_LEVEL_EXCEPTION
4405                ,p_module   => l_log_module);
4406         END IF;
4407         RAISE;
4408 WHEN xla_exceptions_pkg.application_exception   THEN
4409         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4410             trace
4411                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
4412                ,p_level    => C_LEVEL_EXCEPTION
4413                ,p_module   => l_log_module);
4414         END IF;
4415         RAISE;
4416 WHEN OTHERS    THEN
4417       xla_exceptions_pkg.raise_message
4418          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GenerateOneProcedure');
4419 END GenerateOneProcedure;
4420 
4421 /*---------------------------------------------------------------+
4422 |                                                                |
4423 |  Private function                                              |
4424 |                                                                |
4425 |   GenerateProcedure                                            |
4426 |                                                                |
4427 | Generates EventType_xxx() or EventClass_xxx() function         |
4428 |                                                                |
4429 +---------------------------------------------------------------*/
4430 
4431 FUNCTION GenerateProcedure  (
4432   p_entity                       IN VARCHAR2
4433 , p_event_class                  IN VARCHAR2
4434 , p_event_type                   IN VARCHAR2
4435 , p_application_id               IN NUMBER
4436 , p_product_rule_code            IN VARCHAR2
4437 , p_product_rule_type_code       IN VARCHAR2
4438 , p_amb_context_code             IN VARCHAR2
4439 , p_acctd_flag                   IN VARCHAR2
4440 , p_g_l_flag                     IN VARCHAR2
4441 --
4442 , p_hdr_description_index        IN BINARY_INTEGER
4443 , p_array_alt_index              IN xla_cmp_source_pkg.t_array_ByInt
4444 , p_array_evt_source_Level       IN xla_cmp_source_pkg.t_array_VL1
4445 --
4446 , p_array_hdr_acctg_source       IN xla_cmp_source_pkg.t_array_VL30
4447 , p_array_hdr_acctg_source_type  IN xla_cmp_source_pkg.t_array_VL1
4448 , p_array_hdr_acct_attr_source   IN xla_cmp_source_pkg.t_array_int
4449 , p_array_line_acctg_source      IN xla_cmp_source_pkg.t_array_VL30
4450 , p_array_line_acctg_source_type IN xla_cmp_source_pkg.t_array_VL1
4451 , p_array_line_acct_attr_source  IN xla_cmp_source_pkg.t_array_int
4452 --
4453 , p_array_table_name             IN xla_cmp_source_pkg.t_array_VL30
4454 , p_array_parent_table_index           IN xla_cmp_source_pkg.t_array_ByInt
4455 , p_array_table_type             IN xla_cmp_source_pkg.t_array_VL30
4456 , p_array_table_hash             IN xla_cmp_source_pkg.t_array_VL30
4457 , p_array_populated_flag         IN xla_cmp_source_pkg.t_array_VL1
4458 --
4459 , p_array_ref_obj_flag           IN xla_cmp_source_pkg.t_array_VL1
4460 , p_array_join_condition         IN xla_cmp_source_pkg.t_array_VL2000
4461 --
4462 , p_array_h_source_index         IN xla_cmp_source_pkg.t_array_ByInt
4463 , p_array_h_table_index          IN xla_cmp_source_pkg.t_array_ByInt
4464 --
4465 , p_array_h_mls_source_index     IN xla_cmp_source_pkg.t_array_ByInt
4466 , p_array_h_mls_table_index      IN xla_cmp_source_pkg.t_array_ByInt
4467 --
4468 , p_array_l_source_index         IN xla_cmp_source_pkg.t_array_ByInt
4469 , p_array_l_table_index          IN xla_cmp_source_pkg.t_array_ByInt
4470 --
4471 , p_array_l_mls_source_index     IN xla_cmp_source_pkg.t_array_ByInt
4472 , p_array_l_mls_table_index      IN xla_cmp_source_pkg.t_array_ByInt
4473 
4474 , p_rec_sources                  IN OUT NOCOPY xla_cmp_source_pkg.t_rec_sources
4475 , p_rec_aad_objects              IN xla_cmp_source_pkg.t_rec_aad_objects
4476 --
4477 , p_extract_status               IN BOOLEAN
4478 , p_procedure                    IN VARCHAR2
4479 )
4480 RETURN CLOB
4481 IS
4482 l_event                         CLOB;
4483 l_log_module                    VARCHAR2(240);
4484 BEGIN
4485 --
4486 IF g_log_enabled THEN
4487       l_log_module := C_DEFAULT_MODULE||'.GenerateProcedure';
4488 END IF;
4489 --
4490 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4491 
4492       trace
4493          (p_msg      => 'BEGIN of GenerateProcedure '
4497 END IF;
4494          ,p_level    => C_LEVEL_PROCEDURE
4495          ,p_module   => l_log_module);
4496 
4498 --
4499 l_event     := GenerateOneProcedure(
4500   p_application_id               => p_application_id
4501 , p_product_rule_code            => p_product_rule_code
4502 , p_product_rule_type_code       => p_product_rule_type_code
4503 , p_amb_context_code             => p_amb_context_code
4504 , p_entity                       => p_entity
4505 , p_event_class                  => p_event_class
4506 , p_event_type                   => p_event_type
4507 --
4508 , p_hdr_description_index        => p_hdr_description_index
4509 , p_array_alt_index              => p_array_alt_index
4510 , p_array_evt_source_Level       => p_array_evt_source_Level
4511 --
4512 , p_array_hdr_acctg_source       => p_array_hdr_acctg_source
4513 , p_array_hdr_acctg_source_type  => p_array_hdr_acctg_source_type
4514 , p_array_hdr_acct_attr_source   => p_array_hdr_acct_attr_source
4515 , p_array_line_acctg_source      => p_array_line_acctg_source
4516 , p_array_line_acctg_source_type => p_array_line_acctg_source_type
4517 , p_array_line_acct_attr_source  => p_array_line_acct_attr_source
4518 --
4519 , p_array_table_name             => p_array_table_name
4520 , p_array_parent_table_index           => p_array_parent_table_index
4521 , p_array_table_type             => p_array_table_type
4522 , p_array_table_hash             => p_array_table_hash
4523 , p_array_populated_flag         => p_array_populated_flag
4524 --
4525 , p_array_ref_obj_flag           => p_array_ref_obj_flag
4526 , p_array_join_condition         => p_array_join_condition
4527 --
4528 , p_array_h_source_index         => p_array_h_source_index
4529 , p_array_h_table_index          => p_array_h_table_index
4530 --
4531 , p_array_h_mls_source_index     => p_array_h_mls_source_index
4532 , p_array_h_mls_table_index      => p_array_h_mls_table_index
4533 --
4534 , p_array_l_source_index         => p_array_l_source_index
4535 , p_array_l_table_index          => p_array_l_table_index
4536 --
4537 , p_array_l_mls_source_index     => p_array_l_mls_source_index
4538 , p_array_l_mls_table_index      => p_array_l_mls_table_index
4539 --
4540 , p_rec_sources                  => p_rec_sources
4541 , p_rec_aad_objects              => p_rec_aad_objects
4542 --
4543 , p_extract_status               => p_extract_status
4544 , p_procedure                    => p_procedure
4545 );
4546 --
4547 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4548    trace
4549       (p_msg      => 'length of l_event:'||to_char(length(l_event))
4550       ,p_level    => C_LEVEL_PROCEDURE
4551       ,p_module   => l_log_module);
4552 END IF;
4553 --
4554 l_event     := xla_cmp_string_pkg.replace_token(l_event,'$event_class_code$', p_event_class);  -- 4417664
4555 l_event     := xla_cmp_string_pkg.replace_token(l_event,'$event_type_code$',p_event_type);  -- 4417664
4556 l_event     := xla_cmp_string_pkg.replace_token(l_event,'$calculate_acctd_flag$',p_acctd_flag);  -- 4417664
4557 l_event     := xla_cmp_string_pkg.replace_token(l_event,'$calculate_g_l_flag$',p_g_l_flag);  -- 4417664
4558 
4559 l_event     :=
4560    xla_cmp_string_pkg.replace_token   -- 4417664
4561       (l_event,'$event_class_name$'
4562       ,GetEventClassName
4563           (p_application_id   => p_application_id
4564           ,p_entity_code      => p_entity
4565           ,p_event_class_code => p_event_class)
4566       );
4567 
4568 l_event     :=
4569    xla_cmp_string_pkg.replace_token   -- 4417664
4570       (l_event,'$event_type_name$'
4571       ,GetEventTypeName
4572           (p_application_id   => p_application_id
4573           ,p_entity_code      => p_entity
4574           ,p_event_class_code => p_event_class
4575           ,p_event_type_code  => p_event_type)
4576       );
4577 
4578 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4579    trace
4580       (p_msg      => 'END of GenerateProcedure'
4581       ,p_level    => C_LEVEL_PROCEDURE
4582       ,p_module   => l_log_module);
4583 END IF;
4584 --
4585 RETURN l_event;
4586 EXCEPTION
4587 WHEN VALUE_ERROR THEN
4588         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4589             trace
4590                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
4591                ,p_level    => C_LEVEL_EXCEPTION
4592                ,p_module   => l_log_module);
4593         END IF;
4594         RAISE;
4595 WHEN xla_exceptions_pkg.application_exception   THEN
4596         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4597             trace
4598                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
4599                ,p_level    => C_LEVEL_EXCEPTION
4600                ,p_module   => l_log_module);
4601         END IF;
4602         RAISE;
4603 WHEN OTHERS    THEN
4604    xla_exceptions_pkg.raise_message
4605       (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GenerateProcedure');
4606 END GenerateProcedure;
4607 
4608 /*---------------------------------------------------------------+
4609 |                                                                |
4610 |  Private function                                              |
4611 |                                                                |
4612 |   GetEventTypeClassProc                                        |
4613 |                                                                |
4614 | Generates EventType_xxx() and EventClass_xxx() functions       |
4615 |                                                                |
4619   p_entity                       IN VARCHAR2
4616 +---------------------------------------------------------------*/
4617 --
4618 FUNCTION GetEventTypeClassProc  (
4620 , p_event_class                  IN VARCHAR2
4621 , p_event_type                   IN VARCHAR2
4622 , p_acctd_flag                   IN VARCHAR2
4623 , p_g_l_flag                     IN VARCHAR2
4624 , p_application_id               IN NUMBER
4625 , p_product_rule_code            IN VARCHAR2
4626 , p_product_rule_type_code       IN VARCHAR2
4627 , p_amb_context_code             IN VARCHAR2
4628 , p_rec_sources                  IN OUT NOCOPY xla_cmp_source_pkg.t_rec_sources
4629 , p_rec_aad_objects              IN OUT NOCOPY xla_cmp_source_pkg.t_rec_aad_objects
4630 , p_procedure                    IN VARCHAR2
4631 , p_IsCompiled                   OUT NOCOPY BOOLEAN
4632 )
4633 RETURN DBMS_SQL.VARCHAR2S
4634 IS
4635 --
4636 l_event                         CLOB;
4637 l_array_event                   DBMS_SQL.VARCHAR2S;
4638 --
4639 l_IsExtractValid                BOOLEAN;
4640 l_IsCompiled                    BOOLEAN;
4641 --
4642 l_array_evt_source_index        xla_cmp_source_pkg.t_array_ByInt;
4643 l_array_evt_source_level        xla_cmp_source_pkg.t_array_VL1;
4644 --
4645 l_array_null_source_index       xla_cmp_source_pkg.t_array_ByInt;
4646 --
4647 l_array_hdr_acctg_source        xla_cmp_source_pkg.t_array_VL30;
4648 l_array_hdr_acctg_source_type   xla_cmp_source_pkg.t_array_VL1;
4649 l_array_hdr_acct_attr_source    xla_cmp_source_pkg.t_array_int;
4650 l_array_line_acctg_source       xla_cmp_source_pkg.t_array_VL30;
4651 l_array_line_acctg_source_type  xla_cmp_source_pkg.t_array_VL1;
4652 l_array_line_acct_attr_source   xla_cmp_source_pkg.t_array_int;
4653 --
4654 l_array_table_name              xla_cmp_source_pkg.t_array_VL30;
4655 l_array_parent_table_index            xla_cmp_source_pkg.t_array_ByInt;
4656 l_array_table_type              xla_cmp_source_pkg.t_array_VL30;
4657 l_array_table_hash              xla_cmp_source_pkg.t_array_VL30;
4658 l_array_populated_flag          xla_cmp_source_pkg.t_array_VL1;
4659 --
4660 l_array_ref_obj_flag            xla_cmp_source_pkg.t_array_VL1;
4661 l_array_join_condition          xla_cmp_source_pkg.t_array_VL2000;
4662 --
4663 l_array_h_source_index          xla_cmp_source_pkg.t_array_ByInt;
4664 l_array_h_table_index           xla_cmp_source_pkg.t_array_ByInt;
4665 --
4666 l_array_h_mls_source_index      xla_cmp_source_pkg.t_array_ByInt;
4667 l_array_h_mls_table_index       xla_cmp_source_pkg.t_array_ByInt;
4668 --
4669 l_array_l_source_index          xla_cmp_source_pkg.t_array_ByInt;
4670 l_array_l_table_index           xla_cmp_source_pkg.t_array_ByInt;
4671 --
4672 l_array_l_mls_source_index      xla_cmp_source_pkg.t_array_ByInt;
4673 l_array_l_mls_table_index       xla_cmp_source_pkg.t_array_ByInt;
4674 --
4675 l_hdr_description_index         BINARY_INTEGER;
4676 l_array_alt_index               xla_cmp_source_pkg.t_array_ByInt;
4677 --
4678 l_ObjectIndex                   BINARY_INTEGER;
4679 l_log_module                    VARCHAR2(240);
4680 --
4681 -- Transaction Objects Diagnostics variables
4682 --
4683 l_insert_sources                CLOB;
4684 l_array_insert_sources          DBMS_SQL.VARCHAR2S;
4685 --
4686 BEGIN
4687 IF g_log_enabled THEN
4688    l_log_module := C_DEFAULT_MODULE||'.GetEventTypeClassProc';
4689 END IF;
4690 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4691    trace
4692       (p_msg      => 'p_procedure = '||p_procedure
4693       ,p_level    => C_LEVEL_PROCEDURE
4694       ,p_module   => l_log_module);
4695    trace
4696       (p_msg      => 'BEGIN of GetEventTypeClassProc'
4697       ,p_level    => C_LEVEL_PROCEDURE
4698       ,p_module   => l_log_module);
4699 END IF;
4700 
4701 g_entity_name            := GetEntityName(
4702                                     p_entity         => p_entity
4703                                   , p_application_id => p_application_id
4704                                    );
4705 
4706 g_event_class_name       := GetEventClassName(
4707                                     p_application_id     => p_application_id
4708                                   , p_entity_code        => p_entity
4709                                   , p_event_class_code   => p_event_class
4710                                             );
4711 
4712 g_event_type_name        := GetEventTypeName(
4713                                     p_application_id     => p_application_id
4714                                   , p_entity_code        => p_entity
4715                                   , p_event_class_code   => p_event_class
4716                                   , p_event_type_code    => p_event_type
4717                                    );
4718 
4719 
4720 --
4721 l_IsExtractValid                := TRUE;
4722 l_IsCompiled                    := TRUE;
4723 --
4724 CollectHeaderAndLineSources (
4725     p_entity                       => p_entity
4726   , p_event_class                  => p_event_class
4727   , p_event_type                   => p_event_type
4728   , p_application_id               => p_application_id
4729   , p_product_rule_code            => p_product_rule_code
4730   , p_product_rule_type_code       => p_product_rule_type_code
4731   , p_amb_context_code             => p_amb_context_code
4732   , p_array_evt_source_index       => l_array_evt_source_index
4733   , p_array_hdr_acctg_source       => l_array_hdr_acctg_source
4734   , p_array_hdr_acctg_source_type  => l_array_hdr_acctg_source_type
4735   , p_array_hdr_acct_attr_source   => l_array_hdr_acct_attr_source
4739   , p_hdr_description_index        => l_hdr_description_index
4736   , p_array_line_acctg_source      => l_array_line_acctg_source
4737   , p_array_line_acctg_source_type => l_array_line_acctg_source_type
4738   , p_array_line_acct_attr_source  => l_array_line_acct_attr_source
4740   , p_array_alt_index              => l_array_alt_index
4741   , p_rec_aad_objects              => p_rec_aad_objects
4742   , p_rec_sources                  => p_rec_sources
4743 );
4744 
4745 
4746 -- Call the Extract Integrity Checker to validate sources with
4747 -- event class Extract Objects
4748 
4749 l_IsExtractValid := xla_cmp_extract_pkg.CallExtractIntegrityChecker (
4750   p_application_id               => p_application_id
4751 , p_entity_code                  => p_entity
4752 , p_event_class_code             => p_event_class
4753 , p_amb_context_code             => p_amb_context_code
4754 , p_product_rule_type_code       => p_product_rule_type_code
4755 , p_product_rule_code            => p_product_rule_code
4756 , p_array_evt_source_index       => l_array_evt_source_index
4757 , p_array_application_id         => p_rec_sources.array_application_id
4758 , p_array_source_code            => p_rec_sources.array_source_code
4759 , p_array_source_type_code       => p_rec_sources.array_source_type_code
4760 , p_array_datatype_code          => p_rec_sources.array_datatype_code
4761 , p_array_translated_flag        => p_rec_sources.array_translated_flag
4762 , p_array_evt_source_Level       => l_array_evt_source_level
4763 , p_array_object_name            => l_array_table_name
4764 , p_array_parent_object_index    => l_array_parent_table_index
4765 , p_array_object_type            => l_array_table_type
4766 , p_array_object_hash_id         => l_array_table_hash
4767 , p_array_populated_flag         => l_array_populated_flag
4768 , p_array_ref_obj_flag           => l_array_ref_obj_flag
4769 , p_array_join_condition         => l_array_join_condition
4770 , p_array_h_source_index         => l_array_h_source_index
4771 , p_array_h_table_index          => l_array_h_table_index
4772 , p_array_h_mls_source_index     => l_array_h_mls_source_index
4773 , p_array_h_mls_table_index      => l_array_h_mls_table_index
4774 , p_array_l_source_index         => l_array_l_source_index
4775 , p_array_l_table_index          => l_array_l_table_index
4776 , p_array_l_mls_source_index     => l_array_l_mls_source_index
4777 , p_array_l_mls_table_index      => l_array_l_mls_table_index
4778 )
4779 ;
4780 
4781 IF (p_application_id = 200 AND XLA_CMP_PAD_PKG.g_bc_pkg_flag = 'Y') THEN
4782   PopulateBCObjectNames(l_array_table_name, l_array_join_condition);
4783 END IF;
4784 
4785 -- generate the event type/event class functions
4786 
4787 l_event := GenerateProcedure(
4788   p_entity                       => p_entity
4789 , p_event_class                  => p_event_class
4790 , p_event_type                   => p_event_type
4791 , p_application_id               => p_application_id
4792 , p_product_rule_code            => p_product_rule_code
4793 , p_product_rule_type_code       => p_product_rule_type_code
4794 , p_amb_context_code             => p_amb_context_code
4795 , p_acctd_flag                   => p_acctd_flag
4796 , p_g_l_flag                     => p_g_l_flag
4797 --
4798 , p_hdr_description_index        => l_hdr_description_index
4799 , p_array_alt_index              => l_array_alt_index
4800 , p_array_evt_source_Level      => l_array_evt_source_level
4801 --
4802 , p_array_hdr_acctg_source       => l_array_hdr_acctg_source
4803 , p_array_hdr_acctg_source_type  => l_array_hdr_acctg_source_type
4804 , p_array_hdr_acct_attr_source   => l_array_hdr_acct_attr_source
4805 , p_array_line_acctg_source      => l_array_line_acctg_source
4806 , p_array_line_acctg_source_type => l_array_line_acctg_source_type
4807 , p_array_line_acct_attr_source  => l_array_line_acct_attr_source
4808 --
4809 , p_array_table_name             => l_array_table_name
4810 , p_array_parent_table_index           => l_array_parent_table_index
4811 , p_array_table_type             => l_array_table_type
4812 , p_array_table_hash             => l_array_table_hash
4813 , p_array_populated_flag         => l_array_populated_flag
4814 --
4815 , p_array_ref_obj_flag           => l_array_ref_obj_flag
4816 , p_array_join_condition         => l_array_join_condition
4817 --
4818 , p_array_h_source_index         => l_array_h_source_index
4819 , p_array_h_table_index          => l_array_h_table_index
4820 , p_array_h_mls_source_index     => l_array_h_mls_source_index
4821 , p_array_h_mls_table_index      => l_array_h_mls_table_index
4822 , p_array_l_source_index         => l_array_l_source_index
4823 , p_array_l_table_index          => l_array_l_table_index
4824 , p_array_l_mls_source_index     => l_array_l_mls_source_index
4825 , p_array_l_mls_table_index      => l_array_l_mls_table_index
4826 --
4827 , p_rec_sources                  => p_rec_sources
4828 , p_rec_aad_objects              => p_rec_aad_objects
4829 , p_extract_status               => l_IsExtractValid
4830 , p_procedure                    => p_procedure
4831 );
4832 
4833   IF (C_LEVEL_STATEMENT>= g_log_level) THEN
4834 
4835           trace
4836              (p_msg      => 'length of l_event:'|| to_char(length(l_event))
4837              ,p_level    => C_LEVEL_STATEMENT
4838              ,p_module   => l_log_module);
4839   END IF;
4840 
4841   IF p_procedure = 'EVENT_TYPE' THEN
4842 
4843       l_ObjectIndex := xla_cmp_source_pkg.CacheAADObject (
4844                p_object                    => xla_cmp_source_pkg.C_EVT
4848              , p_array_source_Index        => l_array_evt_source_index
4845              , p_object_code               => p_event_type
4846              , p_object_type_code          => 'S'
4847              , p_application_id            => p_application_id
4849              , p_rec_aad_objects           => p_rec_aad_objects
4850              );
4851 
4852      l_event := xla_cmp_string_pkg.replace_token(l_event,'$EVENT_ID$'   ,'Type_'||TO_CHAR(l_ObjectIndex));  -- 4417664
4853      l_event := xla_cmp_string_pkg.replace_token(l_event,'$package_name$'          , g_package_name);  -- 4417664
4854 
4855   ELSIF  p_procedure = 'EVENT_CLASS' THEN
4856 
4857      l_ObjectIndex := xla_cmp_source_pkg.CacheAADObject (
4858                  p_object                    => xla_cmp_source_pkg.C_CLASS
4859                , p_object_code               => p_event_class
4860                , p_object_type_code          => 'S'
4861                , p_application_id            => p_application_id
4862                , p_array_source_Index        => l_array_evt_source_index
4863                , p_rec_aad_objects           => p_rec_aad_objects
4864                );
4865 
4866      l_event := xla_cmp_string_pkg.replace_token(l_event,'$EVENT_ID$'   ,'Class_'||TO_CHAR(l_ObjectIndex));  -- 4417664
4867      l_event := xla_cmp_string_pkg.replace_token(l_event,'$package_name$'          , g_package_name);  -- 4417664
4868 
4869   END IF;
4870 --
4871 l_IsCompiled:= l_IsCompiled AND (l_event IS NOT NULL) AND l_IsExtractValid;
4872 
4873 IF (C_LEVEL_STATEMENT>= g_log_level) THEN
4874           trace
4875              (p_msg      => 'length of l_event:'|| to_char(length(l_event))
4876              ,p_level    => C_LEVEL_STATEMENT
4877              ,p_module   => l_log_module);
4878           trace
4879              (p_msg      => 'l_isCompiled = '||
4880               CASE l_IsCompiled WHEN TRUE THEN 'TRUE' ELSE 'FALSE' END
4881              ,p_level    => C_LEVEL_STATEMENT
4882              ,p_module   => l_log_module);
4883           trace
4884              (p_msg      => 'l_IsExtractValid= '||
4885               CASE l_IsExtractValid WHEN TRUE THEN 'TRUE' ELSE 'FALSE' END
4886              ,p_level    => C_LEVEL_STATEMENT
4887              ,p_module   => l_log_module);
4888 END IF;
4889 
4890 xla_cmp_string_pkg.CreateString(
4891                       p_package_text  => l_event
4892                      ,p_array_string  => l_array_event
4893                      );
4894 
4895 --
4896 --+==========================================================================+
4897 --|                                                                          |
4898 --|                                                                          |
4899 --|                                                                          |
4900 --|                                                                          |
4901 --|                                                                          |
4902 --|                                                                          |
4903 --|                                                                          |
4904 --|                                                                          |
4905 --|                                                                          |
4906 --|                      Transaction Objects Diagnostics                     |
4907 --|                                                                          |
4908 --|                                                                          |
4909 --|                                                                          |
4910 --|                                                                          |
4911 --|                                                                          |
4912 --|                                                                          |
4913 --|                                                                          |
4914 --|                                                                          |
4915 --|                                                                          |
4916 --|                                                                          |
4917 --+==========================================================================+
4918 
4919 IF (C_LEVEL_STATEMENT>= g_log_level) THEN
4920    trace
4921     (p_msg      => ' -> CALL Transaction Objects Diagnostics '
4922     ,p_level    => C_LEVEL_STATEMENT
4923     ,p_module   => l_log_module);
4924 END IF;
4925 
4926 l_insert_sources := C_INSERT_SOURCES_PROC;
4927 l_insert_sources := xla_cmp_string_pkg.replace_token(l_insert_sources,'$event_class_code$', nvl(p_event_class,' '));  -- 4417664
4928 l_insert_sources := xla_cmp_string_pkg.replace_token(l_insert_sources,'$event_type_code$',nvl(p_event_type,' '));  -- 4417664
4929 
4930 
4931 l_insert_sources := xla_cmp_string_pkg.replace_token(l_insert_sources,'$insert_header_sources$',
4932                            nvl(xla_cmp_extract_pkg.GenerateInsertHdrSources  (
4933                            --
4934                              p_array_table_name             => l_array_table_name
4935                            , p_array_parent_table_index           => l_array_parent_table_index
4936                            , p_array_table_hash             => l_array_table_hash
4937                            , p_array_table_type             => l_array_table_type
4938                            , p_array_populated_flag         => l_array_populated_flag
4939                            --
4940                            , p_array_ref_obj_flag           => l_array_ref_obj_flag
4944                            , p_array_h_table_index          => l_array_h_table_index
4941                            , p_array_join_condition         => l_array_join_condition
4942                            --
4943                            , p_array_h_source_index         => l_array_h_source_index
4945                            --
4946                            , p_array_h_mls_source_index     => l_array_h_mls_source_index
4947                            , p_array_h_mls_table_index      => l_array_h_mls_table_index
4948                            --
4949                            , p_array_application_id         => p_rec_sources.array_application_id
4950                            , p_array_source_code            => p_rec_sources.array_source_code
4951                            , p_array_source_type_code       => p_rec_sources.array_source_type_code
4952                            , p_array_flex_value_set_id      => p_rec_sources.array_flex_value_set_id
4953                            , p_array_lookup_type            => p_rec_sources.array_lookup_type
4954                            , p_array_view_application_id    => p_rec_sources.array_view_application_id
4955                            --
4956                            , p_procedure                    => p_procedure
4957                            ),' ')
4958                          );
4959 
4960 l_insert_sources := xla_cmp_string_pkg.replace_token(l_insert_sources, '$insert_line_sources$',
4961                            nvl(xla_cmp_extract_pkg.GenerateInsertLineSources (
4962                            --
4963                              p_array_table_name             => l_array_table_name
4964                            , p_array_parent_table_index           => l_array_parent_table_index
4965                            , p_array_table_hash             => l_array_table_hash
4966                            , p_array_table_type             => l_array_table_type
4967                            , p_array_populated_flag         => l_array_populated_flag
4968                            --
4969                            , p_array_ref_obj_flag           => l_array_ref_obj_flag
4970                            , p_array_join_condition         => l_array_join_condition
4971                            --
4972                            , p_array_l_source_index         => l_array_l_source_index
4973                            , p_array_l_table_index          => l_array_l_table_index
4974                            --
4975                            , p_array_l_mls_source_index     => l_array_l_mls_source_index
4976                            , p_array_l_mls_table_index      => l_array_l_mls_table_index
4977                            --
4978                            , p_array_application_id         => p_rec_sources.array_application_id
4979                            , p_array_source_code            => p_rec_sources.array_source_code
4980                            , p_array_source_type_code       => p_rec_sources.array_source_type_code
4981                            , p_array_flex_value_set_id      => p_rec_sources.array_flex_value_set_id
4982                            , p_array_lookup_type            => p_rec_sources.array_lookup_type
4983                            , p_array_view_application_id    => p_rec_sources.array_view_application_id
4984                            --
4985                            , p_procedure                    => p_procedure
4986                            )  ,' ')
4987                           );
4988 
4989 --
4990 l_insert_sources:= xla_cmp_string_pkg.replace_token(l_insert_sources,'$EVENT_INDEX$'   ,TO_CHAR(l_ObjectIndex));  -- 4417664
4991 
4992 l_insert_sources:= xla_cmp_string_pkg.replace_token(l_insert_sources,'$package_name$'   ,g_package_name);   -- 4417664
4993 
4994 xla_cmp_string_pkg.CreateString(
4995                       p_package_text  => l_insert_sources
4996                      ,p_array_string  => l_array_insert_sources
4997                      );
4998 
4999 
5000 IF (C_LEVEL_STATEMENT>= g_log_level) THEN
5001 
5002           trace
5003              (p_msg      => 'End call to Transaction Objects Diagnostics  '
5004              ,p_level    => C_LEVEL_STATEMENT
5005              ,p_module   => l_log_module);
5006 
5007 
5008           trace
5009              (p_msg      => 'Concat to event type or event class function the code ='
5010                             ||l_array_insert_sources.COUNT
5011              ,p_level    => C_LEVEL_STATEMENT
5012              ,p_module   => l_log_module);
5013 
5014 END IF;
5015 
5016 l_array_event   := xla_cmp_string_pkg.ConcatTwoStrings (
5017                                  p_array_string_1    => l_array_insert_sources
5018                                 ,p_array_string_2    => l_array_event
5019                           );
5020 
5021 IF (C_LEVEL_STATEMENT>= g_log_level) THEN
5022         trace
5023              (p_msg      => 'Event class or Event Type function length ='
5024                             ||l_array_event.COUNT
5025              ,p_level    => C_LEVEL_STATEMENT
5026              ,p_module   => l_log_module);
5027 
5028 END IF;
5029 --
5030 ------------------------------------------------------------------------------
5031 --
5032 --   END the generation of Transaction Objects Diagnostics
5033 --
5034 ------------------------------------------------------------------------------
5035 --
5036 l_array_evt_source_index   := l_array_null_source_index;
5037 --
5038 p_IsCompiled := l_IsCompiled;
5039 --
5040 --
5041 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5042    trace
5043        (p_msg      => 'p_IsCompiled = '||
5047    trace
5044               CASE p_IsCompiled WHEN TRUE THEN 'TRUE' ELSE 'FALSE' END
5045        ,p_level    => C_LEVEL_STATEMENT
5046        ,p_module   => l_log_module);
5048       (p_msg      => 'END of GetEventTypeClassProc'
5049       ,p_level    => C_LEVEL_PROCEDURE
5050       ,p_module   => l_log_module);
5051 END IF;
5052 
5053 RETURN l_array_event;
5054 EXCEPTION
5055 WHEN VALUE_ERROR THEN
5056         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5057             trace
5058                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
5059                ,p_level    => C_LEVEL_EXCEPTION
5060                ,p_module   => l_log_module);
5061         END IF;
5062         RAISE;
5063 WHEN xla_exceptions_pkg.application_exception   THEN
5064         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5065             trace
5066                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
5067                ,p_level    => C_LEVEL_EXCEPTION
5068                ,p_module   => l_log_module);
5069         END IF;
5070         RAISE;
5071 WHEN OTHERS    THEN
5072    xla_exceptions_pkg.raise_message
5073       (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GetEventTypeClassProc ');
5074 END GetEventTypeClassProc;
5075 
5076 
5077 /*---------------------------------------------------------------+
5078 |                                                                |
5079 |  Private function                                              |
5080 |                                                                |
5081 |   GetEventTypeOrClassProc                                      |
5082 |                                                                |
5083 | Drives the generation of EventType_xxx() or EventClass_xxx()   |
5084 | functions                                                      |
5085 |                                                                |
5086 +---------------------------------------------------------------*/
5087 
5088 FUNCTION GetEventTypeOrClassProc  (
5089   p_application_id               IN NUMBER
5090 , p_amb_context_code             IN VARCHAR2
5091 , p_product_rule_code            IN VARCHAR2
5092 , p_product_rule_type_code       IN VARCHAR2
5093 , p_entity                       IN VARCHAR2
5094 , p_event_class                  IN VARCHAR2
5095 , p_event_type                   IN VARCHAR2
5096 , p_acctd_flag                   IN VARCHAR2
5097 , p_g_l_flag                     IN VARCHAR2
5098 --
5099 , p_rec_sources                  IN OUT NOCOPY xla_cmp_source_pkg.t_rec_sources
5100 , p_rec_aad_objects              IN OUT NOCOPY xla_cmp_source_pkg.t_rec_aad_objects
5101 --
5102 , p_IsCompiled                   OUT NOCOPY BOOLEAN
5103 )
5104 RETURN DBMS_SQL.VARCHAR2S
5105 IS
5106 
5107 l_event                 DBMS_SQL.VARCHAR2S;
5108 l_IsCompiled            BOOLEAN;
5109 l_log_module            VARCHAR2(240);
5110 
5111 BEGIN
5112 IF g_log_enabled THEN
5113       l_log_module := C_DEFAULT_MODULE||'.GetEventTypeOrClassProc';
5114 END IF;
5115 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5116 
5117       trace
5118          (p_msg      => 'BEGIN of GetEventTypeOrClassProc'
5119          ,p_level    => C_LEVEL_PROCEDURE
5120          ,p_module   => l_log_module);
5121       trace
5122          (p_msg      => 'p_entity = '||p_entity||
5123                         ' - p_event_class = '||p_event_class ||
5124                         ' - p_event_type = '||p_event_type
5125          ,p_level    => C_LEVEL_PROCEDURE
5126          ,p_module   => l_log_module);
5127 END IF;
5128 --
5129 l_IsCompiled := TRUE;
5130 p_IsCompiled := TRUE;
5131 --
5132 l_event  := xla_cmp_string_pkg.g_null_varchar2s;
5133 --
5134 IF (p_event_type <> p_event_class ||'_ALL') THEN
5135 --
5136 -- generate event type procedure
5137 --
5138   l_event:= GetEventTypeClassProc  (
5139   p_entity                      => p_entity
5140 , p_event_class                 => p_event_class
5141 , p_event_type                  => p_event_type
5142 , p_acctd_flag                  => p_acctd_flag
5143 , p_g_l_flag                    => p_g_l_flag
5144 , p_application_id              => p_application_id
5145 , p_product_rule_code           => p_product_rule_code
5146 , p_product_rule_type_code      => p_product_rule_type_code
5147 , p_amb_context_code            => p_amb_context_code
5148 --
5149 , p_rec_sources                 => p_rec_sources
5150 , p_rec_aad_objects             => p_rec_aad_objects
5151 --
5152 , p_procedure                   => 'EVENT_TYPE'
5153 , p_IsCompiled                  => l_IsCompiled
5154 );
5155 --
5156 ELSE
5157 --
5158 -- generate event class procedure
5159 --
5160   l_event:= GetEventTypeClassProc  (
5161   p_entity                      => p_entity
5162 , p_event_class                 => p_event_class
5163 , p_event_type                  => p_event_type
5164 , p_acctd_flag                  => p_acctd_flag
5165 , p_g_l_flag                    => p_g_l_flag
5166 , p_application_id              => p_application_id
5167 , p_product_rule_code           => p_product_rule_code
5168 , p_product_rule_type_code      => p_product_rule_type_code
5169 , p_amb_context_code            => p_amb_context_code
5170 --
5171 , p_rec_sources                 => p_rec_sources
5172 , p_rec_aad_objects             => p_rec_aad_objects
5173 --
5177 --
5174 , p_procedure                   => 'EVENT_CLASS'
5175 , p_IsCompiled                  => l_IsCompiled
5176 );
5178 END IF;
5179 
5180 --
5181 p_IsCompiled :=  p_IsCompiled AND l_IsCompiled ;
5182 --
5183 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5184    trace
5185        (p_msg      => 'p_IsCompiled = '||
5186               CASE p_IsCompiled WHEN TRUE THEN 'TRUE' ELSE 'FALSE' END
5187        ,p_level    => C_LEVEL_STATEMENT
5188        ,p_module   => l_log_module);
5189    trace
5190       (p_msg      => 'END of GetEventTypeOrClassProc'
5191       ,p_level    => C_LEVEL_PROCEDURE
5192       ,p_module   => l_log_module);
5193 END IF;
5194 RETURN l_event;
5195 EXCEPTION
5196 WHEN VALUE_ERROR THEN
5197         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5198             trace
5199                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
5200                ,p_level    => C_LEVEL_EXCEPTION
5201                ,p_module   => l_log_module);
5202         END IF;
5203         RAISE;
5204 WHEN xla_exceptions_pkg.application_exception   THEN
5205         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5206             trace
5207                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
5208                ,p_level    => C_LEVEL_EXCEPTION
5209                ,p_module   => l_log_module);
5210         END IF;
5211         RAISE;
5212  WHEN OTHERS    THEN
5213       xla_exceptions_pkg.raise_message
5214          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GetEventTypeOrClassProc ');
5215 END GetEventTypeOrClassProc;
5216 
5217 /*---------------------------------------------------------------+
5218 |                                                                |
5219 |  Private function                                              |
5220 |                                                                |
5221 |   GetEventTypeOrClassProc                                      |
5222 |                                                                |
5223 | Generates all EventType_xxx() or EventClass_xxx() from event   |
5224 | types and event classes assigned to AAD                        |
5225 |                                                                |
5226 +---------------------------------------------------------------*/
5227 
5228 FUNCTION GetEventClassAndTypeProcs  (
5229   p_product_rule_code            IN VARCHAR2
5230 , p_product_rule_type_code       IN VARCHAR2
5231 , p_application_id               IN NUMBER
5232 , p_amb_context_code             IN VARCHAR2
5233 --
5234 , p_rec_sources                  IN OUT NOCOPY xla_cmp_source_pkg.t_rec_sources
5235 , p_rec_aad_objects              IN OUT NOCOPY xla_cmp_source_pkg.t_rec_aad_objects
5236 --
5237 , p_IsCompiled                   OUT NOCOPY BOOLEAN
5238 )
5239 RETURN DBMS_SQL.VARCHAR2S
5240 IS
5241 --
5242 l_events                      DBMS_SQL.VARCHAR2S;
5243 l_array_events                DBMS_SQL.VARCHAR2S;
5244 --
5245 l_array_entity                xla_cmp_source_pkg.t_array_VL30;
5246 l_array_event_class           xla_cmp_source_pkg.t_array_VL30;
5247 l_array_event_type            xla_cmp_source_pkg.t_array_VL30;
5248 l_array_event_class_acctd_flag   xla_cmp_source_pkg.t_array_VL1;
5249 l_array_event_class_g_l_flag     xla_cmp_source_pkg.t_array_VL1;
5250 --
5251 l_array_null_entity           xla_cmp_source_pkg.t_array_VL30;
5252 l_array_null_event_class      xla_cmp_source_pkg.t_array_VL30;
5253 l_array_null_event_type       xla_cmp_source_pkg.t_array_VL30;
5254 --
5255 l_IsCompiled                  BOOLEAN;
5256 l_log_module                  VARCHAR2(240);
5257 --
5258 BEGIN
5259 IF g_log_enabled THEN
5260       l_log_module := C_DEFAULT_MODULE||'.GetEventClassAndTypeProcs';
5261 END IF;
5262 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5263       trace
5264          (p_msg      => 'BEGIN of GetEventClassAndTypeProcs'
5265          ,p_level    => C_LEVEL_PROCEDURE
5266          ,p_module   => l_log_module);
5267 END IF;
5268 
5269 l_IsCompiled    := TRUE;
5270 p_IsCompiled    := TRUE;
5271 
5272 GetEventClassEventType(
5273                     p_application_id
5274                   , p_amb_context_code
5275                   , p_product_rule_code
5276                   , p_product_rule_type_code
5277                   , l_array_entity
5278                   , l_array_event_class
5279                   , l_array_event_type
5280                   , l_array_event_class_acctd_flag
5281                   , l_array_event_class_g_l_flag
5282                   );
5283 
5284 l_events := xla_cmp_string_pkg.g_null_varchar2s;
5285 
5286 IF l_array_event_type.COUNT > 0 THEN
5287   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5288 
5289       trace
5290          (p_msg      => 'count is:'||to_char(l_array_event_type.COUNT)
5291          ,p_level    => C_LEVEL_PROCEDURE
5292          ,p_module   => l_log_module);
5293 
5294   END IF;
5295 
5296  FOR Idx IN l_array_event_type.FIRST .. l_array_event_type.LAST LOOP
5297    IF l_array_event_type.EXISTS(Idx) THEN
5298 
5299    l_array_events :=  GetEventTypeOrClassProc  (
5300                p_application_id              => p_application_id
5301              , p_amb_context_code            => p_amb_context_code
5302              , p_product_rule_code           => p_product_rule_code
5303              , p_product_rule_type_code      => p_product_rule_type_code
5304              --
5305              , p_entity                      => l_array_entity(Idx)
5309              , p_g_l_flag                    => l_array_event_class_g_l_flag(Idx)
5306              , p_event_class                 => l_array_event_class(Idx)
5307              , p_event_type                  => l_array_event_type(Idx)
5308              , p_acctd_flag                  => l_array_event_class_acctd_flag(Idx)
5310              --
5311              , p_rec_sources                 => p_rec_sources
5312              , p_rec_aad_objects             => p_rec_aad_objects
5313              --
5314              , p_IsCompiled                  => l_IsCompiled
5315              );
5316 
5317      IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5318          trace
5319             (p_msg      => 'l_event length is:'||to_char(l_events.COUNT)
5320             ,p_level    => C_LEVEL_PROCEDURE
5321             ,p_module   => l_log_module);
5322          trace
5323             (p_msg      => 'l__array_event length is:'||to_char(l_array_events.COUNT)
5324             ,p_level    => C_LEVEL_PROCEDURE
5325             ,p_module   => l_log_module);
5326      END IF;
5327 
5328      l_events :=  xla_cmp_string_pkg.ConcatTwoStrings (
5329                                  p_array_string_1    => l_events
5330                                 ,p_array_string_2    => l_array_events
5331                           );
5332      IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5333          trace
5334             (p_msg      => 'l_event length is:'||to_char(l_events.COUNT)
5335             ,p_level    => C_LEVEL_PROCEDURE
5336             ,p_module   => l_log_module);
5337      END IF;
5338 
5339      p_IsCompiled := p_IsCompiled AND l_IsCompiled;
5340 
5341      END IF;
5342  END LOOP;
5343 END IF;
5344 
5345 l_array_entity           := l_array_null_entity;
5346 l_array_event_class      := l_array_null_event_class;
5347 l_array_event_type       := l_array_null_event_type;
5348 --
5349 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5350    trace
5351        (p_msg      => 'p_IsCompiled = '||
5352               CASE p_IsCompiled WHEN TRUE THEN 'TRUE' ELSE 'FALSE' END
5353        ,p_level    => C_LEVEL_STATEMENT
5354        ,p_module   => l_log_module);
5355    trace
5356       (p_msg      => 'END of GetEventClassAndTypeProcs'
5357       ,p_level    => C_LEVEL_PROCEDURE
5358       ,p_module   => l_log_module);
5359 END IF;
5360 --
5361 RETURN l_events;
5362 EXCEPTION
5363  WHEN VALUE_ERROR THEN
5364         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5365             trace
5366                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
5367                ,p_level    => C_LEVEL_EXCEPTION
5368                ,p_module   => l_log_module);
5369         END IF;
5370         RAISE;
5371 WHEN xla_exceptions_pkg.application_exception   THEN
5372         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5373             trace
5374                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
5375                ,p_level    => C_LEVEL_EXCEPTION
5376                ,p_module   => l_log_module);
5377         END IF;
5378         RAISE;
5379  WHEN OTHERS    THEN
5380       xla_exceptions_pkg.raise_message
5381          (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GetEventClassAndTypeProcs ');
5382 END GetEventClassAndTypeProcs;
5383 
5384 /*-----------------------------------------------------------------------+
5385 |                                                                        |
5386 |  Public function                                                       |
5387 |                                                                        |
5388 |    GenerateEventClassAndType                                           |
5389 |                                                                        |
5390 |  Generates the EventType_xxx() and EventCass_xxx() functions from the  |
5391 |  Event Type Code and Event Class Code assigned to the AAD.             |
5392 |                                                                        |
5393 +-----------------------------------------------------------------------*/
5394 
5395 FUNCTION GenerateEventClassAndType   (
5396   p_application_id               IN NUMBER
5397 , p_product_rule_code            IN VARCHAR2
5398 , p_product_rule_type_code       IN VARCHAR2
5399 , p_product_rule_version         IN VARCHAR2
5400 , p_amb_context_code             IN VARCHAR2
5401 , p_product_rule_name            IN VARCHAR2
5402 , p_package_name                 IN VARCHAR2
5403 , p_rec_aad_objects              IN OUT NOCOPY xla_cmp_source_pkg.t_rec_aad_objects
5404 , p_rec_sources                  IN OUT NOCOPY xla_cmp_source_pkg.t_rec_sources
5405 , p_package_body                 OUT NOCOPY DBMS_SQL.VARCHAR2S
5406 )
5407 RETURN BOOLEAN
5408 IS
5409 --
5410 l_IsCompiled                BOOLEAN:= TRUE;
5411 l_events                    DBMS_SQL.VARCHAR2S;
5412 l_log_module                VARCHAR2(240);
5413 --
5414 BEGIN
5415 
5416 IF g_log_enabled THEN
5417       l_log_module := C_DEFAULT_MODULE||'.GenerateEventClassAndType';
5418 END IF;
5419 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5420       trace
5421          (p_msg      => 'BEGIN of GenerateEventClassAndType'
5422          ,p_level    => C_LEVEL_PROCEDURE
5423          ,p_module   => l_log_module);
5424 
5425 END IF;
5426 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5427       trace
5428          (p_msg      => 'p_package_name = '||p_package_name||
5432                         ' - p_product_rule_name='||p_product_rule_name
5429                         ' - p_product_rule_code='||p_product_rule_code||
5430                         ' - p_product_rule_type_code='||p_product_rule_type_code||
5431                         ' - p_product_rule_version='||p_product_rule_version||
5433          ,p_level    => C_LEVEL_STATEMENT
5434          ,p_module   => l_log_module);
5435 
5436 END IF;
5437 
5438 g_package_name            := p_package_name ;
5439 g_product_rule_code       := p_product_rule_code;
5440 g_product_rule_type_code  := p_product_rule_type_code;
5441 g_product_rule_version    := p_product_rule_version;
5442 g_product_rule_name       := p_product_rule_name;
5443 g_application_name        := XLA_CMP_PAD_PKG.GetApplicationName(p_application_id);
5444 
5445 --
5446 l_events :=  GetEventClassAndTypeProcs   (
5447   p_product_rule_code           => p_product_rule_code
5448 , p_product_rule_type_code      => p_product_rule_type_code
5449 , p_application_id              => p_application_id
5450 , p_amb_context_code            => p_amb_context_code
5451 , p_rec_sources                 => p_rec_sources
5452 , p_rec_aad_objects             => p_rec_aad_objects
5453 , p_IsCompiled                  => l_IsCompiled
5454  );
5455 
5456 
5457 p_package_body            := l_events;
5458 
5459 g_package_name            := NULL;
5460 g_product_rule_code       := NULL;
5461 g_product_rule_type_code  := NULL;
5462 g_product_rule_version    := NULL;
5463 g_product_rule_name       := NULL;
5464 
5465 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5466    trace
5467        (p_msg      => 'l_IsCompiled = '||
5468               CASE l_IsCompiled WHEN TRUE THEN 'TRUE' ELSE 'FALSE' END
5469        ,p_level    => C_LEVEL_STATEMENT
5470        ,p_module   => l_log_module);
5471    trace
5472       (p_msg      => 'END of GenerateEventClassAndType'
5473       ,p_level    => C_LEVEL_PROCEDURE
5474       ,p_module   => l_log_module);
5475 END IF;
5476 
5477 RETURN l_IsCompiled;
5478 EXCEPTION
5479 WHEN VALUE_ERROR THEN
5480         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5481             trace
5482                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
5483                ,p_level    => C_LEVEL_EXCEPTION
5484                ,p_module   => l_log_module);
5485         END IF;
5486         RAISE;
5487 WHEN xla_exceptions_pkg.application_exception   THEN
5488         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5489             trace
5490                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
5491                ,p_level    => C_LEVEL_EXCEPTION
5492                ,p_module   => l_log_module);
5493         END IF;
5494         RAISE;
5495 WHEN OTHERS    THEN
5496    xla_exceptions_pkg.raise_message
5497       (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GenerateEventClassAndType ');
5498 END GenerateEventClassAndType;
5499 
5500 --+==========================================================================+
5501 --|                                                                          |
5502 --|                                                                          |
5503 --|                                                                          |
5504 --|                                                                          |
5505 --|                                                                          |
5506 --|                                                                          |
5507 --|                                                                          |
5508 --|                                                                          |
5509 --|                                                                          |
5510 --|                                                                          |
5511 --|                  Generate main procedure                                 |
5512 --|                                                                          |
5513 --|                                                                          |
5514 --|                                                                          |
5515 --|                                                                          |
5516 --|                                                                          |
5517 --|                                                                          |
5518 --|                                                                          |
5519 --|                                                                          |
5520 --|                                                                          |
5521 --+==========================================================================+
5522 
5523 
5524 /*---------------------------------------------------------------+
5525 |                                                                |
5526 |  Private function                                              |
5527 |                                                                |
5528 |   GenerateMainProcedure                                        |
5529 |                                                                |
5530 | Generates call to EventType_xxx() or EventClass_xxx() in AAD   |
5531 | package.                                                       |
5532 |                                                                |
5533 +---------------------------------------------------------------*/
5534 
5535 FUNCTION GenerateMainProcedure(
5536   p_application_id               IN NUMBER
5537 , p_amb_context_code             IN VARCHAR2
5538 , p_product_rule_code            IN VARCHAR2
5539 , p_product_rule_type_code       IN VARCHAR2
5540 , p_product_rule_name            IN VARCHAR2
5541 , p_rec_aad_objects              IN xla_cmp_source_pkg.t_rec_aad_objects
5542  )
5543 RETURN CLOB
5544 IS
5545 ------------------------------------------------------------
5546 --
5547 -- Call to EventClass_X() and EventType_X()
5548 --
5549 ------------------------------------------------------------
5550 
5551 C_CALL_EVENT_CLASS       CONSTANT VARCHAR2(10000) :='
5552 l_created := EventClass_$Index$(
5553    p_application_id         => p_application_id
5554  , p_base_ledger_id         => p_base_ledger_id
5555  , p_target_ledger_id       => p_target_ledger_id
5556  , p_language               => l_language
5557  , p_currency_code          => l_currency_code
5558  , p_sla_ledger_id          => l_sla_ledger_id
5559  , p_pad_start_date         => p_pad_start_date
5560  , p_pad_end_date           => p_pad_end_date
5561  , p_primary_ledger_id      => p_primary_ledger_id
5562 );
5563 
5564 ';
5565 
5566 C_CALL_EVENT_TYPE       CONSTANT VARCHAR2(10000) := '
5567  l_created :=  EventType_$Index$(
5568    p_application_id         => p_application_id
5569  , p_base_ledger_id         => p_base_ledger_id
5570  , p_target_ledger_id       => p_target_ledger_id
5571  , p_language               => l_language
5572  , p_currency_code          => l_currency_code
5573  , p_sla_ledger_id          => l_sla_ledger_id
5574  , p_pad_start_date         => p_pad_start_date
5575  , p_pad_end_date           => p_pad_end_date
5576  , p_primary_ledger_id      => p_primary_ledger_id
5577 );
5578 
5579 ';
5580 
5581 ------------------------------------------------------------
5582 --
5583 -- Call Transaction Objects Diagnostics
5584 --
5585 ------------------------------------------------------------
5586 --
5587 C_CALL_INSERT_EXT_SOURCES   CONSTANT VARCHAR2(3000) := '
5588 
5589      IF ( g_diagnostics_mode =''Y'' ) THEN
5590 
5591          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5592           trace
5593               (p_msg      => ''CALL Transaction Objects Diagnostics''
5594               ,p_level    => C_LEVEL_STATEMENT
5595               ,p_module   => l_log_module);
5596 
5597          END IF;
5598 
5599          insert_sources_$Index$(
5600                           p_target_ledger_id => p_target_ledger_id
5601                         , p_language         => l_language
5602                         , p_sla_ledger_id    => l_sla_ledger_id
5603                         , p_pad_start_date   => p_pad_start_date
5604                         , p_pad_end_date     => p_pad_end_date
5605                           );
5606 
5607      END IF;
5608 ';
5609 
5610 l_MainBodyProc                   CLOB;
5611 l_name                           VARCHAR2(80);
5612 l_ObjectIndex                    BINARY_INTEGER;
5613 l_call_event                     VARCHAR2(32000);
5614 l_array_entity                   xla_cmp_source_pkg.t_array_VL30;
5615 l_array_event_type               xla_cmp_source_pkg.t_array_VL30;
5616 l_array_NoAcctg_event_type       xla_cmp_source_pkg.t_array_VL30;
5617 l_array_event_class              xla_cmp_source_pkg.t_array_VL30;
5618 l_array_EventTypeInClass         xla_cmp_source_pkg.t_array_VL30;
5619 l_array_event_class_acctd_flag   xla_cmp_source_pkg.t_array_VL1;
5620 l_array_event_class_g_l_flag     xla_cmp_source_pkg.t_array_VL1;
5621 l_log_module                     VARCHAR2(240);
5622 
5623 BEGIN
5624 
5625 IF g_log_enabled THEN
5626       l_log_module := C_DEFAULT_MODULE||'.GenerateMainProcedure';
5627 END IF;
5628 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5629       trace
5630          (p_msg      => 'BEGIN of GenerateMainProcedure'
5631          ,p_level    => C_LEVEL_PROCEDURE
5632          ,p_module   => l_log_module);
5633 END IF;
5634 
5635 l_MainBodyProc    := NULL;
5636 
5637 GetEventClassEventType(
5638                     p_application_id               => p_application_id
5639                   , p_amb_context_code             => p_amb_context_code
5640                   , p_product_rule_code            => p_product_rule_code
5641                   , p_product_rule_type_code       => p_product_rule_type_code
5642                   , p_array_entity                 => l_array_entity
5643                   , p_array_event_class            => l_array_event_class
5644                   , p_array_event_type             => l_array_event_type
5645                   , p_array_event_class_acctd_flag => l_array_event_class_acctd_flag
5646                   , p_array_event_class_g_l_flag   => l_array_event_class_g_l_flag
5647                   );
5648 
5652          ,p_level    => C_LEVEL_STATEMENT
5649 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5650       trace
5651          (p_msg      => 'l_array_event_type.COUNT = '||l_array_event_type.COUNT
5653          ,p_module   => l_log_module);
5654 END IF;
5655 
5656 GetNoAccountEventTypes(
5657                     p_application_id            => p_application_id
5658                   , p_amb_context_code          => p_amb_context_code
5659                   , p_product_rule_code         => p_product_rule_code
5660                   , p_product_rule_type_code    => p_product_rule_type_code
5661                   , p_array_event_type          => l_array_NoAcctg_event_type
5662 )
5663 ;
5664 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5665       trace
5666          (p_msg      => 'l_array_NoAcctg_event_type.COUNT = '||l_array_NoAcctg_event_type.COUNT
5667          ,p_level    => C_LEVEL_STATEMENT
5668          ,p_module   => l_log_module);
5669 END IF;
5670 
5671 IF l_array_event_type.COUNT > 0 THEN
5672    FOR Idx IN l_array_event_type.FIRST .. l_array_event_type.LAST LOOP
5673       IF (l_array_event_type(Idx) <> l_array_event_class(Idx)||'_ALL') THEN
5674 
5675          l_ObjectIndex := xla_cmp_source_pkg.GetAADObjectPosition(
5676                       p_object                   => xla_cmp_source_pkg.C_EVT
5677                     , p_object_code              => l_array_event_type(Idx)
5678                     , p_object_type_code         => 'S'
5679                     , p_application_id           => p_application_id
5680                     , p_event_class_code         => NULL
5681                     , p_event_type_code          => NULL
5682                     , p_rec_aad_objects          => p_rec_aad_objects);
5683 
5684 
5685 
5686          IF l_ObjectIndex IS NOT NULL THEN
5687              --
5688              l_call_event   := C_CALL_EVENT_TYPE ;
5689              l_call_event   := l_call_event || C_CALL_INSERT_EXT_SOURCES;
5690              l_call_event   := REPLACE(l_call_event,'$Index$', TO_CHAR(l_ObjectIndex));
5691              l_MainBodyProc := l_MainBodyProc ||l_call_event ;
5692           END IF;
5693       ELSE
5694 
5695          GetEventType(
5696                p_application_id      => p_application_id
5697              , p_entity_code         => l_array_entity(Idx)
5698              , p_event_class_code    => l_array_event_class(Idx)
5699              , p_array_event_type    => l_array_EventTypeInClass);
5700          --
5701          IF l_array_EventTypeInClass.COUNT > 0 THEN
5702 
5703             l_ObjectIndex := xla_cmp_source_pkg.GetAADObjectPosition(
5704                               p_object                   => xla_cmp_source_pkg.C_CLASS
5705                             , p_object_code              => l_array_event_class(Idx)
5706                             , p_object_type_code         => 'S'
5707                             , p_application_id           => p_application_id
5708                             , p_event_class_code         => NULL
5709                             , p_event_type_code          => NULL
5710                             , p_rec_aad_objects          => p_rec_aad_objects);
5711 
5712             IF l_ObjectIndex IS NOT NULL THEN
5713                --
5714                l_call_event   := C_CALL_EVENT_CLASS;
5715                l_call_event   := l_call_event ||C_CALL_INSERT_EXT_SOURCES;
5716                l_call_event   := REPLACE(l_call_event,'$Index$', TO_CHAR(l_ObjectIndex));
5717                l_MainBodyProc := l_MainBodyProc ||l_call_event ;
5718             END IF;
5719          ELSE
5720             --
5721             BEGIN
5722                --
5723                l_name := GetEventClassName(
5724                  p_application_id            => p_application_id
5725                , p_entity_code               => l_array_entity(Idx)
5726                , p_event_class_code          => l_array_event_class(Idx)) ;
5727                --
5728 
5729                IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5730                   trace
5731                      (p_msg      => 'ERROR: XLA_CMP_NO_EVENT_TYPE '
5732                      ,p_level    => C_LEVEL_EXCEPTION
5733                      ,p_module   => l_log_module);
5734                END IF;
5735 
5736                xla_exceptions_pkg.raise_message
5737                                       ('XLA'
5738                                       ,'XLA_CMP_NO_EVENT_TYPE'
5739                                       ,'PAD_NAME'
5740                                       , XLA_CMP_PAD_PKG.g_component_name
5741                                       ,'PAD_OWNER'
5742                                       , XLA_CMP_PAD_PKG.g_owner
5743                                       ,'EVENT_CLASS_NAME'
5744                                       , l_name);
5745 
5746             END;
5747          END IF;
5748       END IF;
5749    END LOOP;
5750 ELSE
5751 
5752    l_MainBodyProc := NULL;
5753 
5754    IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5755          trace
5756             (p_msg      => 'ERROR: XLA_CMP_NO_EVENT_CLASS  '
5757             ,p_level    => C_LEVEL_EXCEPTION
5758             ,p_module   => l_log_module);
5759    END IF;
5760    xla_exceptions_pkg.raise_message
5761                                    ('XLA'
5762                                    ,'XLA_CMP_NO_EVENT_CLASS'
5763                                    ,'PAD_NAME'
5764                                    , XLA_CMP_PAD_PKG.g_component_name
5765                                    ,'PAD_OWNER'
5766                                    , XLA_CMP_PAD_PKG.g_owner);
5767 END IF;
5768 --
5769 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5773          ,p_module   => l_log_module);
5770       trace
5771          (p_msg      => 'END of GenerateMainProcedure'
5772          ,p_level    => C_LEVEL_PROCEDURE
5774 
5775 END IF;
5776 RETURN l_MainBodyProc;
5777 EXCEPTION
5778 WHEN VALUE_ERROR THEN
5779         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5780             trace
5781                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
5782                ,p_level    => C_LEVEL_EXCEPTION
5783                ,p_module   => l_log_module);
5784         END IF;
5785          RAISE;
5786 WHEN xla_exceptions_pkg.application_exception   THEN
5787         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5788             trace
5789                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
5790                ,p_level    => C_LEVEL_EXCEPTION
5791                ,p_module   => l_log_module);
5792         END IF;
5793         RAISE;
5794 WHEN OTHERS    THEN
5795        xla_exceptions_pkg.raise_message
5796             (p_location => 'XLA_CMP_EVENT_TYPE_PKG.GenerateMainProcedure');
5797 END GenerateMainProcedure;
5798 
5799 /*-----------------------------------------------------------------+
5800 |                                                                  |
5801 |  Public function                                                 |
5802 |                                                                  |
5803 |    BuildMainProc                                                 |
5804 |                                                                  |
5805 |  Generates the main procedure CreateHeadersAndLines() in the AAD |
5806 |  packages                                                        |
5807 |                                                                  |
5808 +-----------------------------------------------------------------*/
5809 
5810 FUNCTION BuildMainProc(
5811   p_application_id               IN NUMBER
5812 , p_product_rule_code            IN VARCHAR2
5813 , p_product_rule_type_code       IN VARCHAR2
5814 , p_product_rule_name            IN VARCHAR2
5815 , p_product_rule_version         IN VARCHAR2
5816 , p_amb_context_code             IN VARCHAR2
5817 , p_package_name                 IN VARCHAR2
5818 --
5819 , p_rec_aad_objects              IN xla_cmp_source_pkg.t_rec_aad_objects
5820 --
5821 , p_package_body                 OUT NOCOPY DBMS_SQL.VARCHAR2S
5822 )
5823 RETURN BOOLEAN
5824 IS
5825 --
5826 l_MainProcedure           CLOB;
5827 l_MainBody                CLOB;
5828 l_array_main              DBMS_SQL.VARCHAR2S;
5829 l_IsCompiled              BOOLEAN;
5830 l_log_module              VARCHAR2(240);
5831 --
5832 BEGIN
5833 --
5834 IF g_log_enabled THEN
5835    l_log_module := C_DEFAULT_MODULE||'.BuildMainProc';
5836 END IF;
5837 --
5838 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5839    trace
5840       (p_msg      => 'BEGIN of BuildMainProc'
5841       ,p_level    => C_LEVEL_PROCEDURE
5842       ,p_module   => l_log_module);
5843 END IF;
5844 
5845 l_IsCompiled := TRUE;
5846 l_array_main :=  xla_cmp_string_pkg.g_null_varchar2s;
5847 l_MainBody   := NULL;
5848 
5849 l_MainBody     :=  GenerateMainProcedure(
5850                p_application_id           => p_application_id
5851              , p_amb_context_code         => p_amb_context_code
5852              , p_product_rule_code        => p_product_rule_code
5853              , p_product_rule_type_code   => p_product_rule_type_code
5854              , p_product_rule_name        => p_product_rule_name
5855              , p_rec_aad_objects          => p_rec_aad_objects
5856              );
5857 
5858 l_IsCompiled        := l_MainBody IS NOT NULL;
5859 
5860 l_MainProcedure     := C_MAIN_PROCEDURE ;
5861 
5862 l_MainProcedure     := xla_cmp_string_pkg.replace_token(l_MainProcedure ,  -- 4417664
5863                                    '$PACKAGE_NAME$',p_package_name);
5864 
5865 l_MainProcedure     := xla_cmp_string_pkg.replace_token
5866                           (l_MainProcedure
5867                           ,'$BODY_MAIN_PROCEDURE$'
5868                           ,l_MainBody);
5869 
5870 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5871    trace
5872       (p_msg      => '-> CALL xla_cmp_string_pkg.CreateString API'
5873       ,p_level    => C_LEVEL_STATEMENT
5874       ,p_module   => l_log_module);
5875 END IF;
5876 
5877 xla_cmp_string_pkg.CreateString
5878    (p_package_text  => l_MainProcedure
5879    ,p_array_string  => l_array_main);
5880 
5881 p_package_body   := l_array_main ;
5882 
5883 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5884    trace
5885        (p_msg      => 'l_IsCompiled = '||
5886               CASE l_IsCompiled WHEN TRUE THEN 'TRUE' ELSE 'FALSE' END
5887        ,p_level    => C_LEVEL_STATEMENT
5888        ,p_module   => l_log_module);
5889    trace
5890       (p_msg      => 'END of BuildMainProc'
5891       ,p_level    => C_LEVEL_PROCEDURE
5892       ,p_module   => l_log_module);
5893 END IF;
5894 --
5895 RETURN l_IsCompiled;
5896 EXCEPTION
5897 WHEN VALUE_ERROR THEN
5898         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5899             trace
5900                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
5901                ,p_level    => C_LEVEL_EXCEPTION
5902                ,p_module   => l_log_module);
5903         END IF;
5904         RAISE;
5905 WHEN xla_exceptions_pkg.application_exception   THEN
5906         IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
5907             trace
5908                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
5909                ,p_level    => C_LEVEL_EXCEPTION
5910                ,p_module   => l_log_module);
5911         END IF;
5912         RAISE;
5913 WHEN OTHERS    THEN
5914    xla_exceptions_pkg.raise_message
5915       (p_location => 'XLA_CMP_EVENT_TYPE_PKG.BuildMainProc');
5916 END BuildMainProc;
5917 --
5918 --=============================================================================
5919 --
5920 --
5921 --
5922 --
5923 --
5924 --
5925 --
5926 --
5927 --
5928 --
5929 --
5930 --
5931 --
5932 --
5933 --
5934 --
5935 --
5936 --
5937 --
5938 --
5939 --
5940 --
5941 --=============================================================================
5942 --=============================================================================
5943 --          *********** Initialization routine **********
5944 --=============================================================================
5945 
5946 BEGIN
5947 
5948    g_log_level      := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
5949    g_log_enabled    := fnd_log.test
5950                           (log_level  => g_log_level
5951                           ,module     => C_DEFAULT_MODULE);
5952 
5953    IF NOT g_log_enabled  THEN
5954       g_log_level := C_LEVEL_LOG_DISABLED;
5955    END IF;
5956 --
5957 END xla_cmp_event_type_pkg; --