DBA Data[Home] [Help]

PACKAGE BODY: APPS.XLA_AE_HEADER_PKG

Source


1 PACKAGE BODY xla_ae_header_pkg AS
2 /* $Header: xlajehdr.pkb 120.59.12010000.2 2008/11/02 13:46:49 pshukla ship $   */
3 /*===========================================================================+
4 |             Copyright (c) 2001-2002 Oracle Corporation                     |
5 |                       Redwood Shores, CA, USA                              |
6 |                         All rights reserved.                               |
7 +============================================================================+
8 | PACKAGE NAME                                                               |
9 |     XLA_AE_HEADER_PKG                                                      |
10 |                                                                            |
11 | DESCRIPTION                                                                |
12 |                                                                            |
13 |                                                                            |
14 | HISTORY                                                                    |
15 |     20-NOV-2002 K.Boussema  Created                                        |
16 |     08-JAN-2003 K.Boussema  Changed xla_temp_journal_entries by            |
17 |                              xla_journal_entries_temp                      |
18 |     10-JAN-2003 K.Boussema  Removed gl_sl_link_id column from temp table   |
19 |                             Added 'dbdrv' command                          |
20 |     10-MAR-2003 K.Boussema    Made changes for the new bulk approach of the|
21 |                               accounting engine                            |
22 |                             Changed xla_journal_entries_temp by            |
23 |                               xla_je_lines_temp                            |
24 |     01-APR-2003 K.Boussema    Included amb_context_code                    |
25 |     03-APR-2003 K.Boussema    Included Analytical criteria feature         |
26 |     19-APR-2003 K.Boussema    Included Error messages                      |
27 |     22-APR-2003 K.Boussema    Added DOC_CATEGORY_NAME source               |
28 |     28-APR-2003 K.Boussema    Added validation of Accounting Event Extract |
29 |                               bug 2925651                                  |
30 |     06-MAI-2003 K.Boussema    Modifcation included for bug2936071          |
31 |     13-MAI-2003 K.Boussema    Renamed temporary tables xla_je_lines_gt by  |
32 |                               xla_ae_lines_gt, xla_je_headers_gt by        |
33 |                               xla_ae_headers_gt                            |
34 |                               Renamed in xla_distribution_links the column |
35 |                               base_amount by ledger_amount                 |
36 |     20-MAI-2003 K.Boussema    Added a Token to XLA_AP_CANNOT_INSERT_JE     |
37 |                               message                                      |
38 |     27-MAI-2003 K.Boussema    Renamed the Document seq. Accounting sources |
39 |     27-MAI-2003 K.Boussema    Renamed code_combination_status by           |
40 |                                  code_combination_status_flag              |
41 |                               Renamed base_amount by ledger_amount         |
42 |     30-MAI-2003 K.Boussema   Renamed BUSGET_VERSION_ID by BUDGET_VERSION_ID|
43 |                               bug 2981358                                  |
44 |     11-JUN-2003 K.Boussema    Renamed Sequence columns, bug 3000007        |
45 |     23-JUN-2003 K.Boussema   Updated the call to get_period_name bug3005754|
46 |     17-JUL-2003 K.Boussema    Reviewd the code                             |
47 |     17-SEP-2003 K.Boussema    Updated to Get je_category from cache:3109690|
48 |     19-SEP-2003 K.Boussema    Code changed to include reversed_ae_header_id|
49 |                               and reversed_line_num, see bug 3143095       |
50 |     03-OCT-2003 K.Boussema    Changed description width to 1996            |
51 |     16-OCT-2003 K.Boussema    Fixed the issue when the entered and         |
52 |                               accounted amounts are reversed.              |
53 |     22-OCT-2003 K.Boussema    Changed to capture the Merge Matching Lines  |
54 |                               preference for Accounting Reversal from JLT  |
55 |     26-NOV-2003 K.Boussema    Removed the insert of the sl_coa_mapping name|
56 |                               for change third party lines, bug 3278955    |
57 |     12-DEC-2003 K. Boussema   Renamed target_coa_id in xla_ae_lines_gt     |
58 |                               by ccid_coa_id                               |
59 |                               Reviewed the InsertHeaders, bug 3042840      |
60 |     18-DEC-2003 K.Boussema    Changed to fix bug 3042840,3307761,3268940   |
61 |                               3310291 and 3320689                          |
62 |     07-JAN-2004 K.Boussema    Changed to populate switch_side_flag column  |
63 |     19-JAN-2004 K.Boussema    Removed the validation of doc sequence       |
64 |     05-FEB-2004 S.Singhania   Changes based on bug 3419803.                |
65 |                                 - correct column names are used            |
66 |                                   TAX_LINE_REF_ID, TAX_SUMMARY_LINE_REF_ID,|
67 |                                   TAX_REC_NREC_DIST_REF_ID                 |
68 |                                 - reference to the column is removed.      |
69 |                                   TAX_REC_NREC_SUMMARY_DIST_REF            |
70 |     17-FEB-2004 K.Boussema    Made changes for the FND_LOG.                |
71 |                               passed ae_header_id to error messages        |
72 |     12-MAR-2004 K.Boussema    Removed the validation of the party type     |
73 |     22-MAR-2004 K.Boussema    Added a parameter p_module to the TRACE calls|
74 |                               and the procedure.                           |
75 |     29-MAR-2204 K.Boussema    Changed based on bug 3528667                 |
76 |                                - added get_period_name function to retrieve|
77 |                                the period_name from gl_period_statuses     |
78 |                                - added the cache of period_name            |
79 |                                - changed the insert into xla_ae_headers_gt |
80 |     11-MAY-2004 K.Boussema  Removed the call to XLA trace routine from     |
81 |                             trace() procedure                              |
82 |     17-MAY-2004 W.Shen      change for attribute enhancement project       |
83 |                             1. add TransactionReversal procedure from      |
84 |                                lines package                               |
85 |                             2. SetHdrAccountingSource, add gl_transfer_flag|
86 |                                and trx_acct_reversal_option                |
87 |                             3. SetHdrAccountingSource, add gl_date         |
88 |                             4. change to InsertHeaders procedure           |
89 |                             5. rename reversed_ae_header_id to             |
90 |                                ref_ae_header_id, reversed_ae_line_num to   |
91 |                                ref_ae_line_num                             |
92 |     26-MAY-2004 W.Shen      change error message                           |
93 |     02-JUL-2004 W.Shen      if gl_transfer_flag is not mapped at all, set  |
94 |                                the default value to 'N' instead of 'NT'    |
95 |                                bug 3741223                                 |
96 |     27-JUL-2004 W.Shen      In SetHeaderId, if all the 3 flag is 'N',      |
97 |                               (which is the case when transaction reversal)|
98 |                               3 header ids are generated and assigned      |
99 |                               bug 3786980                                  |
100 |     23-Sep-2004 S.Singhania Made changes for the bulk peroformance. It has |
101 |                               changed the code at number of places.        |
102 |     25-May-2005 W. Shen     Remove column ledger_amount,entered amount     |
103 |                               from xla_distribution_links, change the      |
104 |                               function change_third_party to remove the    |
105 |                               reference to the columns.                    |
106 |     11-Jul-2005 A. Wan      Changed for MPA.  4262811                      |
107 |     01-Aug-2005 W. Chan     4458381 - Public Sector Enhancement            |
108 |     18-Oct-2005 V. Kumar    Removed code for Analytical Criteria           |
109 |     23-Nov-2005 V. Kumar    Bug 4752774 - Added Hints for performance      |
110 |     3-Jan-2006  W. Chan     Bug 4924492 - Populate budget version id for   |
111 |                               accounting reversal                          |
112 |     20-JAN-2006 A.Wan       4884853 add GetAccrualRevDate                  |
113 |     07-FEB-2006 A.Wan       4897417 error if MPA's GL periods not defined. |
114 |     13-Feb-2006 A.Wan       4955764 - set MPA's g_rec_lines.array_gl_date  |
115 |     16-Apr-2006 A.Wan       5132302 - applied to amt for Gain/Loss         |
116 |     09-May-2006 A.Wan       5161760 - chk header attributes is valid.      |
117 |     21-Jun-2006 A.Wan       5100860 Performance fix, see bug for detail    |
118 +===========================================================================*/
119 --
120 --+==========================================================================+
121 --|                                                                          |
122 --|                                                                          |
123 --| CONSTANTS                                                                |
124 --|                                                                          |
125 --|                                                                          |
126 --+==========================================================================+
127 --
128 --
129 C_VALID             CONSTANT NUMBER        := 0;
130 C_INVALID           CONSTANT NUMBER        := 1;
131 --
132 --
133 C_STANDARD          CONSTANT VARCHAR2(30)  := 'STANDARD';
134 C_INVALID_STATUS    CONSTANT VARCHAR2(1)   := 'I';
135 C_DRAFT_STATUS      CONSTANT VARCHAR2(1)   := 'D';
136 C_FINAL_STATUS      CONSTANT VARCHAR2(1)   := 'F';
137 --
138 -- bulk performance
139 C_INCOMPLETE        CONSTANT VARCHAR2(1)   := 'X';
140 --
141 C_ACTUAL            CONSTANT VARCHAR2(1)   := 'A';
142 C_BUDGET            CONSTANT VARCHAR2(1)   := 'B';
143 C_ENCUMBRANCE       CONSTANT VARCHAR2(1)   := 'E';
144 --
145 --
146 C_ALL                 CONSTANT  VARCHAR2(1)    := 'A';
147 C_SAME_SIDE           CONSTANT  VARCHAR2(1)    := 'W';
148 C_NO_MERGE            CONSTANT  VARCHAR2(1)    := 'N';
149 --
150 C_CCID                   CONSTANT VARCHAR2(30)  := 'CREATED';
151 
152 -- Application id for GL
153 C_GL_APPLICATION_ID             CONSTANT INTEGER := 101;
154 --
155 C_SWITCH               CONSTANT VARCHAR2(1)    := 'Y';
156 C_NO_SWITCH            CONSTANT VARCHAR2(1)    := 'N';
157 --
158 --====================================================================
159 --
160 --
161 --
162 --
163 --
164 --                                   FND_LOG trace
165 --
166 --
167 --
168 --
169 --
170 --
171 --
172 --
173 --
174 --
175 --
176 --
177 --
178 --
179 --
180 --
181 --======================================================================
182 --=============================================================================
183 --               *********** Local Trace Routine **********
184 --=============================================================================
185 
186 C_LEVEL_STATEMENT     CONSTANT NUMBER := FND_LOG.LEVEL_STATEMENT;
187 C_LEVEL_PROCEDURE     CONSTANT NUMBER := FND_LOG.LEVEL_PROCEDURE;
188 C_LEVEL_EVENT         CONSTANT NUMBER := FND_LOG.LEVEL_EVENT;
189 C_LEVEL_EXCEPTION     CONSTANT NUMBER := FND_LOG.LEVEL_EXCEPTION;
190 C_LEVEL_ERROR         CONSTANT NUMBER := FND_LOG.LEVEL_ERROR;
191 C_LEVEL_UNEXPECTED    CONSTANT NUMBER := FND_LOG.LEVEL_UNEXPECTED;
192 
193 C_LEVEL_LOG_DISABLED  CONSTANT NUMBER := 99;
194 C_DEFAULT_MODULE      CONSTANT VARCHAR2(240) := 'xla.plsql.XLA_AE_HEADER_PKG';
195 
196 --
197 --+==========================================================================+
198 --|                                                                          |
199 --|                                                                          |
200 --| PL/SQL structures                                                        |
201 --|                                                                          |
202 --|                                                                          |
203 --+==========================================================================+
204 --
205 -- period_name cache structure
206 --
207 TYPE t_rec_period_name IS RECORD
208    (period_name                        VARCHAR2(25)
209    ,ledger_id                          NUMBER
210    ,start_date                         DATE
211    ,end_date                           DATE
212    )
213 ;
214 --
215 --
216 --+==========================================================================+
217 --|                                                                          |
218 --|                                                                          |
219 --| Global Variables                                                         |
220 --|                                                                          |
221 --|                                                                          |
222 --+==========================================================================+
223 --
224 -- period_name cache
225 --
226 g_cache_period_name    t_rec_period_name;
227 g_application_id               INTEGER :=  xla_accounting_cache_pkg.GetValueNum('XLA_EVENT_APPL_ID');
228 
229 --
230 --
231 -- FND log global variables
232 --
233 
234 g_log_level            NUMBER;
235 g_log_enabled          BOOLEAN;
236 
237 --====================================================================
238 --
239 --
240 --
241 --
242 --
243 --        list of PRIVATE  procedures and functions
244 --
245 --
246 --
247 --
248 --
249 --
250 --
251 --
252 --
253 --
254 --
255 --
256 --
257 --
258 --
259 --
260 --======================================================================
261 PROCEDURE trace (
262    p_msg                 IN VARCHAR2
263   ,p_level               IN NUMBER
264   ,p_module              IN VARCHAR2 DEFAULT C_DEFAULT_MODULE
265 )
266 ;
267 
268 --====================================================================
269 --
270 --
271 --
272 --
273 --
274 --        PRIVATE  procedures and functions
275 --
276 --
277 --
278 --
279 --
280 --
281 --
282 --
283 --
284 --
285 --
286 --
287 --
288 --
289 --
290 --
291 --======================================================================
292 --
293 /*======================================================================+
294 |                                                                       |
295 | Private Procedure                                                     |
296 |                                                                       |
297 |      trace                                                            |
298 +======================================================================*/
299 PROCEDURE trace
300            (p_msg                        IN VARCHAR2
301            ,p_level                      IN NUMBER
302            ,p_module                     IN VARCHAR2 DEFAULT C_DEFAULT_MODULE) IS
303 BEGIN
304 
305 ----------------------------------------------------------------------------
306 -- Following is for FND log.
307 ----------------------------------------------------------------------------
308 IF (p_msg IS NULL AND p_level >= g_log_level) THEN
309           fnd_log.message(p_level, p_module);
310 ELSIF p_level >= g_log_level THEN
311           fnd_log.string(p_level, p_module, p_msg);
312 END IF;
313 
314 EXCEPTION
315        WHEN xla_exceptions_pkg.application_exception THEN
316           RAISE;
317        WHEN OTHERS THEN
318           xla_exceptions_pkg.raise_message
319              (p_location   => 'XLA_AE_HEADER_PKG.trace');
320 END trace;
321 --
322 --
323 --====================================================================
324 --
325 --
326 --
327 --
328 --
329 --        PUBLIC  procedures and functions
330 --
331 --
332 --
333 --
334 --
335 --
336 --
337 --
338 --
339 --
340 --
341 --
342 --
343 --
344 --
345 --
346 --======================================================================
347 --
348 /*======================================================================+
349 |                                                                       |
350 | Public Procedure                                                      |
351 |                                                                       |
352 |                                                                       |
353 +======================================================================*/
354 --bulk performance
355 -- modified to initilize a record in array
356 PROCEDURE InitHeader
357        (p_header_idx       in number)
358 IS
359 --l_rec_header_new_line            t_rec_header_new;
360 l_log_module                 VARCHAR2(240);
361 BEGIN
362 --
363 IF g_log_enabled THEN
364       l_log_module := C_DEFAULT_MODULE||'.InitHeader';
365 END IF;
366 --
367 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
368       trace
369          (p_msg      => 'BEGIN of InitHeader'
370          ,p_level    => C_LEVEL_PROCEDURE
371          ,p_module   => l_log_module);
372       trace
373          (p_msg      => 'p_header_idx = '||p_header_idx
374          ,p_level    => C_LEVEL_PROCEDURE
375          ,p_module   => l_log_module);
376 
377 END IF;
378 -- g_header_idx is used as index for array values in g_rec_header_new
379 -- This is a counter coming from header loop in aad package. For each
380 -- header fetched (one header per event) incremented counter value is passed
381 -- as p_header_idx
382   g_header_idx                                := p_header_idx;
383 
384 -- This initializes a new row in the array values in g_rec_header_new to NULL;
385 g_rec_header_new.array_event_type_code(g_header_idx)           := NULL;
386 g_rec_header_new.array_event_id(g_header_idx)                  := NULL;
387 g_rec_header_new.array_entity_id(g_header_idx)                 := NULL;
388 --
389 g_rec_header_new.array_header_num(g_header_idx)                := 0;       -- 4262811
390 g_rec_header_new.array_parent_header_id(g_header_idx)          := NULL;    -- 4262811
391 g_rec_header_new.array_parent_line_num(g_header_idx)           := NULL;    -- 4262811
392 g_rec_header_new.array_accrual_reversal_flag(g_header_idx)     := 'N';     -- 4262811
393 g_rec_header_new.array_acc_rev_gl_date_option(g_header_idx)    := 'NONE';  -- 4262811
394 --
395 g_rec_header_new.array_target_ledger_id(g_header_idx)          := NULL;
396 g_rec_header_new.array_actual_header_id(g_header_idx)          := NULL;
397 g_rec_header_new.array_budget_header_id(g_header_idx)          := NULL;
398 g_rec_header_new.array_encumb_header_id(g_header_idx)          := NULL;
399 g_rec_header_new.array_je_category_name(g_header_idx)          := NULL;
400 g_rec_header_new.array_period_name(g_header_idx)               := NULL;
401 g_rec_header_new.array_description(g_header_idx)               := NULL;
402 g_rec_header_new.array_doc_sequence_id(g_header_idx)           := NULL;
403 g_rec_header_new.array_doc_sequence_value(g_header_idx)        := NULL;
404 g_rec_header_new.array_doc_category_code(g_header_idx)         := NULL;
405 g_rec_header_new.array_budget_version_id(g_header_idx)         := NULL;
406 --g_rec_header_new.array_encumbrance_type_id(g_header_idx)       := NULL; -- 4458381
407 g_rec_header_new.array_party_change_option(g_header_idx)       := NULL;
408 g_rec_header_new.array_party_change_type(g_header_idx)         := NULL;
409 g_rec_header_new.array_new_party_id(g_header_idx)              := NULL;
410 g_rec_header_new.array_new_party_site_id(g_header_idx)         := NULL;
411 g_rec_header_new.array_previous_party_id(g_header_idx)         := NULL;
412 g_rec_header_new.array_previous_party_site_id(g_header_idx)    := NULL;
413 g_rec_header_new.array_gl_transfer_flag(g_header_idx)          := NULL;
414 g_rec_header_new.array_trx_acct_reversal_option(g_header_idx)  := NULL;
415 g_rec_header_new.array_gl_date(g_header_idx)                   := NULL;
416 --
417 g_rec_header_new.array_anc_id_1(g_header_idx)                  := NULL;
418 g_rec_header_new.array_anc_id_2(g_header_idx)                  := NULL;
419 g_rec_header_new.array_anc_id_3(g_header_idx)                  := NULL;
420 g_rec_header_new.array_anc_id_4(g_header_idx)                  := NULL;
421 g_rec_header_new.array_anc_id_5(g_header_idx)                  := NULL;
422 g_rec_header_new.array_anc_id_6(g_header_idx)                  := NULL;
423 g_rec_header_new.array_anc_id_7(g_header_idx)                  := NULL;
424 g_rec_header_new.array_anc_id_8(g_header_idx)                  := NULL;
425 g_rec_header_new.array_anc_id_9(g_header_idx)                  := NULL;
426 g_rec_header_new.array_anc_id_10(g_header_idx)    := NULL;
427 g_rec_header_new.array_anc_id_11(g_header_idx)    := NULL;
428 g_rec_header_new.array_anc_id_12(g_header_idx)    := NULL;
429 g_rec_header_new.array_anc_id_13(g_header_idx)    := NULL;
430 g_rec_header_new.array_anc_id_14(g_header_idx)    := NULL;
431 g_rec_header_new.array_anc_id_15(g_header_idx)    := NULL;
432 g_rec_header_new.array_anc_id_16(g_header_idx)    := NULL;
433 g_rec_header_new.array_anc_id_17(g_header_idx)    := NULL;
434 g_rec_header_new.array_anc_id_18(g_header_idx)    := NULL;
435 g_rec_header_new.array_anc_id_19(g_header_idx)    := NULL;
436 g_rec_header_new.array_anc_id_20(g_header_idx)    := NULL;
437 g_rec_header_new.array_anc_id_21(g_header_idx)    := NULL;
438 g_rec_header_new.array_anc_id_22(g_header_idx)    := NULL;
439 g_rec_header_new.array_anc_id_23(g_header_idx)    := NULL;
440 g_rec_header_new.array_anc_id_24(g_header_idx)    := NULL;
441 g_rec_header_new.array_anc_id_25(g_header_idx)    := NULL;
442 g_rec_header_new.array_anc_id_26(g_header_idx)    := NULL;
443 g_rec_header_new.array_anc_id_27(g_header_idx)    := NULL;
444 g_rec_header_new.array_anc_id_28(g_header_idx)    := NULL;
445 g_rec_header_new.array_anc_id_29(g_header_idx)    := NULL;
446 g_rec_header_new.array_anc_id_30(g_header_idx)    := NULL;
447 g_rec_header_new.array_anc_id_31(g_header_idx)    := NULL;
448 g_rec_header_new.array_anc_id_32(g_header_idx)    := NULL;
449 g_rec_header_new.array_anc_id_33(g_header_idx)    := NULL;
450 g_rec_header_new.array_anc_id_34(g_header_idx)    := NULL;
451 g_rec_header_new.array_anc_id_35(g_header_idx)    := NULL;
452 g_rec_header_new.array_anc_id_36(g_header_idx)    := NULL;
453 g_rec_header_new.array_anc_id_37(g_header_idx)    := NULL;
454 g_rec_header_new.array_anc_id_38(g_header_idx)    := NULL;
455 g_rec_header_new.array_anc_id_39(g_header_idx)    := NULL;
456 g_rec_header_new.array_anc_id_40(g_header_idx)    := NULL;
457 g_rec_header_new.array_anc_id_41(g_header_idx)    := NULL;
458 g_rec_header_new.array_anc_id_42(g_header_idx)    := NULL;
459 g_rec_header_new.array_anc_id_43(g_header_idx)    := NULL;
460 g_rec_header_new.array_anc_id_44(g_header_idx)    := NULL;
461 g_rec_header_new.array_anc_id_45(g_header_idx)    := NULL;
462 g_rec_header_new.array_anc_id_46(g_header_idx)    := NULL;
463 g_rec_header_new.array_anc_id_47(g_header_idx)    := NULL;
464 g_rec_header_new.array_anc_id_48(g_header_idx)    := NULL;
465 g_rec_header_new.array_anc_id_49(g_header_idx)    := NULL;
466 g_rec_header_new.array_anc_id_50(g_header_idx)    := NULL;
467 g_rec_header_new.array_anc_id_51(g_header_idx)    := NULL;
468 g_rec_header_new.array_anc_id_52(g_header_idx)    := NULL;
469 g_rec_header_new.array_anc_id_53(g_header_idx)    := NULL;
470 g_rec_header_new.array_anc_id_54(g_header_idx)    := NULL;
471 g_rec_header_new.array_anc_id_55(g_header_idx)    := NULL;
472 g_rec_header_new.array_anc_id_56(g_header_idx)    := NULL;
473 g_rec_header_new.array_anc_id_57(g_header_idx)    := NULL;
474 g_rec_header_new.array_anc_id_58(g_header_idx)    := NULL;
475 g_rec_header_new.array_anc_id_59(g_header_idx)    := NULL;
476 g_rec_header_new.array_anc_id_60(g_header_idx)    := NULL;
477 g_rec_header_new.array_anc_id_61(g_header_idx)    := NULL;
478 g_rec_header_new.array_anc_id_62(g_header_idx)    := NULL;
479 g_rec_header_new.array_anc_id_63(g_header_idx)    := NULL;
480 g_rec_header_new.array_anc_id_64(g_header_idx)    := NULL;
481 g_rec_header_new.array_anc_id_65(g_header_idx)    := NULL;
482 g_rec_header_new.array_anc_id_66(g_header_idx)    := NULL;
483 g_rec_header_new.array_anc_id_67(g_header_idx)    := NULL;
484 g_rec_header_new.array_anc_id_68(g_header_idx)    := NULL;
485 g_rec_header_new.array_anc_id_69(g_header_idx)    := NULL;
486 g_rec_header_new.array_anc_id_70(g_header_idx)    := NULL;
487 g_rec_header_new.array_anc_id_71(g_header_idx)    := NULL;
488 g_rec_header_new.array_anc_id_72(g_header_idx)    := NULL;
489 g_rec_header_new.array_anc_id_73(g_header_idx)    := NULL;
490 g_rec_header_new.array_anc_id_74(g_header_idx)    := NULL;
491 g_rec_header_new.array_anc_id_75(g_header_idx)    := NULL;
492 g_rec_header_new.array_anc_id_76(g_header_idx)    := NULL;
493 g_rec_header_new.array_anc_id_77(g_header_idx)    := NULL;
494 g_rec_header_new.array_anc_id_78(g_header_idx)    := NULL;
495 g_rec_header_new.array_anc_id_79(g_header_idx)    := NULL;
496 g_rec_header_new.array_anc_id_80(g_header_idx)    := NULL;
497 g_rec_header_new.array_anc_id_81(g_header_idx)    := NULL;
498 g_rec_header_new.array_anc_id_82(g_header_idx)    := NULL;
499 g_rec_header_new.array_anc_id_83(g_header_idx)    := NULL;
500 g_rec_header_new.array_anc_id_84(g_header_idx)    := NULL;
501 g_rec_header_new.array_anc_id_85(g_header_idx)    := NULL;
502 g_rec_header_new.array_anc_id_86(g_header_idx)    := NULL;
503 g_rec_header_new.array_anc_id_87(g_header_idx)    := NULL;
504 g_rec_header_new.array_anc_id_88(g_header_idx)    := NULL;
505 g_rec_header_new.array_anc_id_89(g_header_idx)    := NULL;
506 g_rec_header_new.array_anc_id_90(g_header_idx)    := NULL;
507 g_rec_header_new.array_anc_id_91(g_header_idx)    := NULL;
508 g_rec_header_new.array_anc_id_92(g_header_idx)    := NULL;
509 g_rec_header_new.array_anc_id_93(g_header_idx)    := NULL;
510 g_rec_header_new.array_anc_id_94(g_header_idx)    := NULL;
511 g_rec_header_new.array_anc_id_95(g_header_idx)    := NULL;
512 g_rec_header_new.array_anc_id_96(g_header_idx)    := NULL;
513 g_rec_header_new.array_anc_id_97(g_header_idx)    := NULL;
514 g_rec_header_new.array_anc_id_98(g_header_idx)    := NULL;
515 g_rec_header_new.array_anc_id_99(g_header_idx)    := NULL;
516 g_rec_header_new.array_anc_id_100(g_header_idx)   := NULL;
517 
518 --
519 g_rec_header_new.array_event_number(g_header_idx)              := NULL;
520 
521 --
522 -- bulk performance
523 -- Following may not be needed in the bulk approach as
524 -- je status is handled in a different way.
525 --  XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
526 --
527 -- bulk performance
528 -- following initial1ses the status of je headers for each balance type
529 -- initial status is kept as 'valid'
530 g_rec_header_new.array_actual_status(g_header_idx)   := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
531 g_rec_header_new.array_budget_status(g_header_idx)   := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
532 g_rec_header_new.array_encumbrance_status(g_header_idx)   := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
533 g_rec_header_new.array_event_status(g_header_idx)   := 'X'; -- X indicates processed sucessfully.
534 
535 --
536 --
537 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
538       trace
539          (p_msg      => 'END of InitHeader'
540          ,p_level    => C_LEVEL_PROCEDURE
541          ,p_module   => l_log_module);
542 
543 END IF;
544 EXCEPTION
545   WHEN xla_exceptions_pkg.application_exception THEN
546       XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    :=  XLA_AE_JOURNAL_ENTRY_PKG.C_INVALID;
547       RAISE;
548   WHEN OTHERS  THEN
549        xla_exceptions_pkg.raise_message
550                (p_location => 'XLA_AE_HEADER_PKG.InitHeader');
551        --
552 END InitHeader;
553 --
554 
555 
556 /*======================================================================+
557 |                                                                       |
558 | Public Procedure - 4884853                                            |
559 |                                                                       |
560 |                                                                       |
561 +======================================================================*/
562 PROCEDURE GetAccrualRevDate(
563   p_hdr_idx           IN NUMBER
564 , p_ledger_id         IN NUMBER
565 , p_gl_date           IN DATE
566 , p_gl_date_option    IN VARCHAR2
567 )
568 IS
569 --
570 CURSOR c_one_period IS
571 SELECT period_name
572       ,CASE p_gl_date_option
573             WHEN 'XLA_FIRST_DAY_NEXT_GL_PERIOD' THEN start_date
574             WHEN 'XLA_LAST_DAY_NEXT_GL_PERIOD'  THEN end_date
575             ELSE  p_gl_date + 1
576             END                                   GL_DATE
577   FROM gl_period_statuses gps
578  WHERE gps.application_id         = 101
579    AND gps.ledger_id              = p_ledger_id
580    AND gps.adjustment_period_flag = 'N'
581    AND p_gl_date < gps.start_date
582 ORDER BY gps.start_date ASC;
583 
584 
585 l_period_name     gl_period_statuses.period_name%TYPE;
586 l_accrev_date     DATE;
587 l_log_module      VARCHAR2(240);
588 
589 
590 BEGIN
591 
592    IF g_log_enabled THEN
593       l_log_module := C_DEFAULT_MODULE||'.GetAccrualRevDate';
594    END IF;
595    --
596    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
597           trace
598              (p_msg      => 'BEGIN of GetAccrualRevDate'
599              ,p_level    => C_LEVEL_PROCEDURE
600              ,p_module   => l_log_module);
601 
602    END IF;
603 
604    l_period_name := NULL;
605    OPEN  c_one_period;
606    FETCH c_one_period INTO l_period_name, l_accrev_date;
607       IF c_one_period%NOTFOUND or l_accrev_date < p_gl_date THEN
608          l_accrev_date := p_gl_date;
609       END IF;
610    CLOSE c_one_period;
611 
612    g_rec_header_new.array_gl_date(p_hdr_idx) := l_accrev_date;
613    IF l_period_name IS NOT NULL THEN
614       g_rec_header_new.array_period_name(p_hdr_idx) := l_period_name;
615    END IF;
616 
617    IF (C_LEVEL_STATEMENT >= g_log_level) THEN
618        trace
619           (p_msg      => 'g_rec_header_new.array_gl_date = '||g_rec_header_new.array_gl_date(p_hdr_idx)||
620                          ' g_rec_header_new.array_period_name = '||g_rec_header_new.array_period_name(p_hdr_idx)
621           ,p_level    => C_LEVEL_STATEMENT
622           ,p_module   => l_log_module);
623    END IF;
624 
625 
626 EXCEPTION
627 WHEN xla_exceptions_pkg.application_exception   THEN
628    IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
629             trace
630                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
631                ,p_level    => C_LEVEL_EXCEPTION
632                ,p_module   => l_log_module);
633    END IF;
634    RAISE;
635 WHEN OTHERS THEN
636    xla_exceptions_pkg.raise_message
637       (p_location => 'xla_ae_header_pkg.GetAccrualRevDate');
638 END GetAccrualRevDate;
639 
640 
641 /*======================================================================+
642 |                                                                       |
643 | Public Procedure - 4262811                                            |
644 |                                                                       |
645 |                                                                       |
646 +======================================================================*/
647 PROCEDURE GetRecognitionEntriesInfo(
648   p_ledger_id            IN NUMBER
649 , p_start_date           IN DATE
650 , p_end_date             IN DATE
651 , p_gl_date_option       IN VARCHAR2
652 , p_num_entries_option   IN VARCHAR2
653 , p_proration_code       IN VARCHAR2
654 , p_calculate_acctd_flag IN VARCHAR2  -- 4262811b for accounted amount
655 , p_same_currency        IN BOOLEAN   -- 4262811b for accounted amount
656 , p_accted_amt           IN NUMBER    -- this should be the unrounded_accounted_amount
657 , p_entered_amt          IN NUMBER    -- this should be the unrounded_entered_amount
658 , p_bflow_applied_to_amt  IN NUMBER                                           -- 5132302
659 , x_num_entries          IN OUT NOCOPY NUMBER
660 , x_gl_dates             IN OUT NOCOPY xla_ae_journal_entry_pkg.t_array_date
661 , x_accted_amts          IN OUT NOCOPY xla_ae_journal_entry_pkg.t_array_num
662 , x_entered_amts         IN OUT NOCOPY xla_ae_journal_entry_pkg.t_array_num
663 , x_period_names         IN OUT NOCOPY xla_ae_journal_entry_pkg.t_array_V15L
664 , x_bflow_applied_to_amts IN OUT NOCOPY xla_ae_journal_entry_pkg.t_array_num  -- 5132302
665 )
666 IS
667 --
668 cursor c_one_period is
669 SELECT period_name
670       ,CASE p_gl_date_option
671               WHEN 'FIRST_DAY_GL_PERIOD' THEN start_date
672               WHEN 'LAST_DAY_GL_PERIOD' THEN  end_date
673               ELSE  ADD_MONTHS(p_start_date, ROUND(MONTHS_BETWEEN(start_date, p_start_date)))  -- originating_day
674               END                                   GL_DATE
675   FROM gl_period_statuses gps
676  WHERE gps.application_id         = 101
677    AND gps.ledger_id              = p_ledger_id
678    AND gps.adjustment_period_flag = 'N'
679    AND p_end_date BETWEEN gps.start_date AND gps.end_date
680  ORDER BY gps.start_date DESC;
681 
682 --
683 -- Cursor to populate the recognition journal entry
684 --
685 CURSOR c_periods IS
686   SELECT period_name,
687          CASE p_gl_date_option
688               WHEN 'FIRST_DAY_GL_PERIOD' THEN start_date
689               WHEN 'LAST_DAY_GL_PERIOD' THEN  end_date
690               ELSE  ADD_MONTHS(p_start_date, ROUND(MONTHS_BETWEEN(start_date, p_start_date)))  -- originating_day
691               END                                   GL_DATE,
692       -- closing_status,    -- Not needed.  Updated in PostAccountingEngine (?)
693          CASE p_proration_code
694               WHEN '360_DAYS' THEN 30
695               ELSE  end_date-start_date+1
696               END                                   DAYS_IN_PERIOD,
697          CASE p_proration_code
698               WHEN '360_DAYS' THEN least(end_date-p_start_date+1,30)
699               ELSE  end_date-p_start_date+1
700               END                                   DAYS_IN_FIRST_PERIOD,  -- only valid for first period
701          CASE p_proration_code
702               WHEN '360_DAYS' THEN least(p_end_date-start_date+1,30)
703               ELSE  p_end_date-start_date+1
704               END                                   DAYS_IN_LAST_PERIOD    -- only valid for last period
705     FROM gl_period_statuses
706    WHERE application_id         = 101
707      AND ledger_id              = p_ledger_id
708      AND adjustment_period_flag = 'N'
709      AND end_date               > p_start_date
710      AND start_date             < p_end_date
711    ORDER BY start_date;
712 
713 --l_closing_statuses         xla_ae_journal_entry_pkg.t_array_V30L;
714 l_days_in_periods          xla_ae_journal_entry_pkg.t_array_num;
715 l_days_in_first_periods    xla_ae_journal_entry_pkg.t_array_num;
716 l_days_in_last_periods     xla_ae_journal_entry_pkg.t_array_num;
717 
718 l_total_months             NUMBER;
719 l_whole_months             NUMBER;
720 l_other_accted_amt         NUMBER;
721 l_other_entered_amt        NUMBER;
722 l_total_days               NUMBER;
723 l_total_accted_amt         NUMBER;
724 l_total_entered_amt        NUMBER;
725 l_log_module               VARCHAR2(240);
726 
727 l_other_bflow_applied_to_amt   NUMBER;  -- 5132302
728 l_total_bflow_applied_to_amt   NUMBER;  -- 5132302
729 
730 -- l_rounding_fac          NUMBER;  -- 4262811b
731 
732 BEGIN
733 
734    IF g_log_enabled THEN
735       l_log_module := C_DEFAULT_MODULE||'.GetRecognitionEntriesInfo';
736    END IF;
737    --
738    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
739           trace
740              (p_msg      => 'BEGIN of GetRecognitionEntriesInfo'
741              ,p_level    => C_LEVEL_PROCEDURE
742              ,p_module   => l_log_module);
743 
744    END IF;
745 
746 
747    IF (p_num_entries_option = 'ONE') THEN   -- see XLA_MPA_NUM_OF_ENTRIES
748 
749       --x_gl_dates(1)      := p_end_date;   -- depends on Gl period option
750       open c_one_period;
751       fetch c_one_period into x_period_names(1), x_gl_dates(1);
752       close c_one_period;
753 
754       IF x_period_names.count=0  THEN  -- 4897417
755          x_num_entries := 0;
756 
757       ELSE
758          x_num_entries      := 1;
759 
760          x_entered_amts (1) := p_entered_amt;
761          IF p_calculate_acctd_flag = 'N' THEN  -- 4262811b
762             IF p_same_currency THEN            -- 4262811b
763                x_accted_amts  (1) := p_entered_amt;
764             ELSE
765                x_accted_amts  (1) := p_accted_amt;
766             END IF;
767          ELSE
768             x_accted_amts (1) := NULL;
769          END IF;
770 
771          x_bflow_applied_to_amts (1) := p_bflow_applied_to_amt; -- 5132302
772 
773       END IF;
774 
775 
776    ELSE  -- ONE_PER_PERIOD
777       OPEN  c_periods;
778       FETCH c_periods BULK COLLECT INTO x_period_names
779                                       , x_gl_dates
780                                     --, l_closing_statuses
781                                       , l_days_in_periods
782                                       , l_days_in_first_periods
783                                       , l_days_in_last_periods;
784       CLOSE c_periods;
785 
786       x_num_entries := x_period_names.count;
787 
788       IF x_num_entries > 0 THEN  -- 4897417
789          ----------------------------------------------------------------------------------
790          -- If the GL date of the first period is before the start date, use the start date
791          ----------------------------------------------------------------------------------
792          IF (x_gl_dates(1) < p_start_date) THEN
793              x_gl_dates(1) := p_start_date;
794          END IF;
795 
796          /*  awan Let cursor determine the last period date
797          --------------------------------------------------------------------------------
798          -- If the GL date of the last period is after the end date, use the end date
799          --------------------------------------------------------------------------------
800          IF (x_gl_dates(x_num_entries) > p_end_date) THEN
801              x_gl_dates(x_num_entries) := p_end_date;
802          END IF;
803          */
804 
805          IF x_num_entries = 1 THEN
806 
807             x_entered_amts (1) := p_entered_amt;
808             IF p_calculate_acctd_flag = 'N' THEN  -- 4262811b
809                IF p_same_currency THEN            -- 4262811b
810                   x_accted_amts  (1) := p_entered_amt;
811                ELSE
812                   x_accted_amts  (1) := p_accted_amt;
813                END IF;
814             ELSE
815                x_accted_amts (1) := NULL;
816             END IF;
817 
818             x_bflow_applied_to_amts (1) := p_bflow_applied_to_amt; -- 5132302
819 
820          ELSE
821 
822             -----------------------------------------
823             -- Calculate whole months
824             -----------------------------------------
825             IF x_num_entries > 2 THEN
826                l_whole_months := x_num_entries - 2;
827             ELSE
828                l_whole_months := 0;
829             END IF;
830 
831             --===================================================================================================
832             -- Calculate the accounted amount and entered amount of the first, last,
833             -- and 'the other' period for the different proration types.
834             -- See XLA_MPA_PRORATION lookup type
835             --===================================================================================================
836 
837             ---------------------------------------------------------------------------
838             IF (p_proration_code = 'DAYS_IN_PERIOD') THEN  -- actual days in each month
839             ---------------------------------------------------------------------------
840                l_total_months := (l_days_in_first_periods(1) / l_days_in_periods(1)) +
841                                  (l_days_in_last_periods(x_num_entries) / l_days_in_periods(x_num_entries)) +  l_whole_months;
842 
843                l_other_entered_amt   := p_entered_amt / l_total_months;
844                x_entered_amts (1)    := l_other_entered_amt * l_days_in_first_periods(1) / l_days_in_periods(1);
845 
846                IF p_calculate_acctd_flag = 'N' THEN  -- 4262811b
847                   IF p_same_currency THEN            -- 4262811b
848                      l_other_accted_amt    := l_other_entered_amt;
849                      x_accted_amts (1)     := x_entered_amts (1);
850                   ELSE
851                      l_other_accted_amt    := p_accted_amt / l_total_months;
852                      x_accted_amts (1)     := l_other_accted_amt * l_days_in_first_periods(1) / l_days_in_periods(1);
853                   END IF;
854                ELSE
855                   l_other_accted_amt := NULL;
856                   x_accted_amts (1)  := NULL;
857                END IF;
858 
859                -- 5132302
860                l_other_bflow_applied_to_amt  := p_bflow_applied_to_amt / l_total_months;
861                x_bflow_applied_to_amts (1)   := l_other_bflow_applied_to_amt * l_days_in_first_periods(1) / l_days_in_periods(1);
862 
863             ---------------------------------------------------------------------------------
864             ELSIF (p_proration_code = '360_DAYS') THEN  -- 30 days per month, 360 days a year
865             ---------------------------------------------------------------------------------
866                l_total_months := (l_days_in_first_periods(1) / 360 * 12) +
867                                  (l_days_in_last_periods(x_num_entries) / 360 * 12) + l_whole_months;
868 
869                l_other_entered_amt    := p_entered_amt / l_total_months;
870                x_entered_amts (1)     := l_other_entered_amt * l_days_in_first_periods(1) / 360 * 12;
871 
872                IF p_calculate_acctd_flag = 'N' THEN  -- 4262811b
873                   IF p_same_currency THEN            -- 4262811b
874                      l_other_accted_amt     := l_other_entered_amt;
875                      x_accted_amts (1)      := x_entered_amts (1);
876                   ELSE
877                      l_other_accted_amt     := p_accted_amt / l_total_months;
878                      x_accted_amts (1)      := l_other_accted_amt * l_days_in_first_periods(1) / 360 * 12;
879                   END IF;
880                ELSE
881                   l_other_accted_amt := NULL;
882                   x_accted_amts (1)  := NULL;
883                END IF;
884 
885                -- 5132302
886                l_other_bflow_applied_to_amt    := p_bflow_applied_to_amt / l_total_months;
887                x_bflow_applied_to_amts (1)     := l_other_bflow_applied_to_amt * l_days_in_first_periods(1) / 360 * 12;
888 
889             -------------------------------------------------------------------------------------
890             ELSIF (p_proration_code = 'TOTAL_DAYS_IN_PERIOD') THEN  -- total days in all periods
891             -------------------------------------------------------------------------------------
892             -- NOTE: the result is one penny different after rounding for the following example:
893             --       1) US$23000 * 17 / 366
894             --       2) 17 / 366 * US$23000
895             -------------------------------------------------------------------------------------
896 
897                l_total_days := l_days_in_first_periods(1) + l_days_in_last_periods(x_num_entries);
898 
899                FOR i IN 2..x_num_entries-1 LOOP
900                    l_total_days := l_total_days + l_days_in_periods(i);
901                END LOOP;
902 
903                x_entered_amts (1) := p_entered_amt * l_days_in_first_periods(1) / l_total_days;
904                IF p_calculate_acctd_flag = 'N' THEN  -- 4262811b
905                   IF p_same_currency THEN            -- 4262811b
906                      x_accted_amts (1)  := x_entered_amts (1);
907                   ELSE
908                      x_accted_amts (1)  := p_accted_amt * l_days_in_first_periods(1) / l_total_days;
909                   END IF;
910                ELSE
911                   x_accted_amts (1) := NULL;
912                END IF;
913 
914                -- 5132302
915                x_bflow_applied_to_amts (1)   := p_bflow_applied_to_amt * l_days_in_first_periods(1) / l_total_days;
916                l_total_bflow_applied_to_amt  := x_bflow_applied_to_amts (1);
917 
918                l_total_accted_amt  := x_accted_amts (1);
919                l_total_entered_amt := x_entered_amts (1);
920 
921                FOR i IN 2..x_num_entries-1 LOOP
922                    x_entered_amts (i)  := p_entered_amt * l_days_in_periods(i) / l_total_days;
923                    l_total_entered_amt := l_total_entered_amt + x_entered_amts (i);
924 
925                    IF p_calculate_acctd_flag = 'N' THEN  -- 4262811b
926                       IF p_same_currency THEN            -- 4262811b
927                          x_accted_amts (i)   := x_entered_amts (i);
928                          l_total_accted_amt  := l_total_entered_amt;
929                       ELSE
930                          x_accted_amts (i)   := p_accted_amt * l_days_in_periods(i) / l_total_days;
931                          l_total_accted_amt  := l_total_accted_amt + x_accted_amts (i);
932                       END IF;
933                    ELSE
934                       x_accted_amts (i)  := NULL;
935                       l_total_accted_amt := NULL;
936                    END IF;
937 
938                    -- 5132302
939                    x_bflow_applied_to_amts (i)    := p_bflow_applied_to_amt * l_days_in_periods(i) / l_total_days;
940                    l_total_bflow_applied_to_amt   := l_total_bflow_applied_to_amt + x_bflow_applied_to_amts (i);
941 
942                END LOOP;
943 
944                -------------------------------------------
945                -- To adjust rounding for last MPA period
946                -------------------------------------------
947                x_entered_amts (x_num_entries) := p_entered_amt - l_total_entered_amt;
948                IF p_calculate_acctd_flag = 'N' THEN  -- 4262811b
949                   IF p_same_currency THEN            -- 4262811b
950                      x_accted_amts (x_num_entries)  := x_entered_amts (x_num_entries);
951                   ELSE
952                      x_accted_amts (x_num_entries)  := p_accted_amt - l_total_accted_amt;
953                   END IF;
954                ELSE
955                   x_accted_amts (x_num_entries)  := NULL;
956                END IF;
957 
958                x_bflow_applied_to_amts (x_num_entries)  := p_bflow_applied_to_amt - l_total_bflow_applied_to_amt;  -- 5132302
959 
960             ----------------------------------------------------------------------
961             ELSE  -- FIRST_PERIOD (zero amount on the last period)
962             ----------------------------------------------------------------------
963 
964                ------------------------------------------------------------------------------------
965                -- Removing final period
966                ------------------------------------------------------------------------------------
967                IF x_num_entries > 1 THEN
968                   x_period_names.DELETE(x_num_entries);
969                   x_num_entries := x_period_names.count;
970                END IF;
971 
972                x_entered_amts (1)        := p_entered_amt / x_num_entries;
973                l_other_entered_amt       := x_entered_amts (1);
974 
975                IF p_calculate_acctd_flag = 'N' THEN  -- 4262811b
976                   IF p_same_currency THEN            -- 4262811b
977                      x_accted_amts (1)   := x_entered_amts (1);
978                      l_other_accted_amt  := l_other_entered_amt;
979                   ELSE
980                      x_accted_amts (1)   := p_accted_amt / x_num_entries;
981                      l_other_accted_amt  := x_accted_amts (1);
982                   END IF;
983                ELSE
984                   x_accted_amts (1)  := NULL;
985                   l_total_accted_amt := NULL;
986                END IF;
987 
988                -- 5132302
989                x_bflow_applied_to_amts (1)   := p_bflow_applied_to_amt / x_num_entries;
990                l_other_bflow_applied_to_amt  := x_bflow_applied_to_amts (1);
991 
992 
993             END IF; -- p_proration_code = 'DAYS_IN_PERIOD'
994 
995             --==============================================================================
996             -- Populate 'the other' periods and adjust rounding for last MPA period
997             --==============================================================================
998             IF (p_proration_code <> 'TOTAL_DAYS_IN_PERIOD') THEN
999                --
1000                -- Copy the accounted amount and the entered amount of 'the other' period
1001                -- from the 'second' to the 'second-to-last' entries.
1002                --
1003                l_total_accted_amt  := x_accted_amts (1);
1004                l_total_entered_amt := x_entered_amts (1);
1005 
1006                l_total_bflow_applied_to_amt := x_bflow_applied_to_amts (1);  -- 5132302
1007 
1008                -- To handle final period
1009                FOR i IN 2.. x_num_entries-1 LOOP
1010                    x_accted_amts (i)   := l_other_accted_amt;
1011                    x_entered_amts (i)  := l_other_entered_amt;
1012                    l_total_accted_amt  := l_total_accted_amt + x_accted_amts (i);
1013                    l_total_entered_amt := l_total_entered_amt + x_entered_amts (i);
1014                    --
1015                    x_bflow_applied_to_amts (i)  := l_other_bflow_applied_to_amt;  -- 5132302
1016                    l_total_bflow_applied_to_amt := l_total_bflow_applied_to_amt + x_bflow_applied_to_amts (i);  -- 5132302
1017                END LOOP;
1018 
1019                ------------------------------------------------------------------------
1020                -- awan To adjust rounding for last MPA period
1021                ------------------------------------------------------------------------
1022                IF x_num_entries <> 1 THEN  -- in case FIRST_PERIOD results in only one period
1023                   x_accted_amts (x_num_entries)  := p_accted_amt - l_total_accted_amt;
1024                   x_entered_amts (x_num_entries) := p_entered_amt - l_total_entered_amt;
1025                   x_bflow_applied_to_amts (x_num_entries) := p_bflow_applied_to_amt - l_total_bflow_applied_to_amt;
1026                END IF;
1027 
1028             END IF;
1029 
1030          END IF; -- x_num_entries = 1
1031 
1032       END IF; -- x_num_entries > 0
1033 
1034    END IF; -- p_num_entries_option = 'ONE'
1035 
1036 EXCEPTION
1037 WHEN xla_exceptions_pkg.application_exception   THEN
1038    IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1039             trace
1040                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
1041                ,p_level    => C_LEVEL_EXCEPTION
1042                ,p_module   => l_log_module);
1043    END IF;
1044    RAISE;
1045 WHEN OTHERS THEN
1046    xla_exceptions_pkg.raise_message
1047       (p_location => 'xla_ae_header_pkg.GetRecognitionEntriesInfo');
1048 END GetRecognitionEntriesInfo;
1049 
1050 
1051 /*======================================================================+
1052 |                                                                       |
1053 | Public Procedure - 4262811                                            |
1054 |                                                                       |
1055 |                                                                       |
1056 +======================================================================*/
1057 PROCEDURE CopyHeaderInfo(
1058    p_parent_hdr_idx   IN NUMBER
1059  , p_hdr_idx          IN NUMBER
1060 )
1061 IS
1062 l_log_module               VARCHAR2(240);
1063 
1064 BEGIN
1065 
1066    IF g_log_enabled THEN
1067       l_log_module := C_DEFAULT_MODULE||'.CopyHeaderInfo';
1068    END IF;
1069    --
1070    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1071           trace
1072              (p_msg      => 'BEGIN of CopyHeaderInfo'
1073              ,p_level    => C_LEVEL_PROCEDURE
1074              ,p_module   => l_log_module);
1075 
1076    END IF;
1077 
1078    -------------------------------------------
1079    -- Create a new header
1080    -------------------------------------------
1081    InitHeader(p_hdr_idx);
1082 
1083    -------------------------------------------------------------------------------
1084    -- Copy all information in g_rec_header_new from p_parent_hdr_idx to p_hdr_idx:
1085    -- with the following exceptions:
1086    --
1087    -- Not copied:
1088    --     array_accrual_reversal_flag
1089    --     array_acc_rev_gl_date_option
1090    --------------------------------------------------------------------------------------------------
1091    --------------------------------------------------------------------------------------------------
1092    g_rec_header_new.array_event_type_code(p_hdr_idx)           := g_rec_header_new.array_event_type_code(p_parent_hdr_idx);
1093    g_rec_header_new.array_event_id(p_hdr_idx)                  := g_rec_header_new.array_event_id(p_parent_hdr_idx);
1094 
1095    g_rec_header_new.array_header_num(p_hdr_idx)                := g_rec_header_new.array_header_num(p_parent_hdr_idx);
1096    g_rec_header_new.array_entity_id(p_hdr_idx)                 := g_rec_header_new.array_entity_id(p_parent_hdr_idx);
1097 
1098    g_rec_header_new.array_parent_header_id(p_hdr_idx)          := g_rec_header_new.array_parent_header_id(p_parent_hdr_idx);
1099    g_rec_header_new.array_parent_line_num(p_hdr_idx)           := g_rec_header_new.array_parent_line_num(p_parent_hdr_idx);
1100 
1101    --
1102    g_rec_header_new.array_target_ledger_id(p_hdr_idx)          := g_rec_header_new.array_target_ledger_id(p_parent_hdr_idx);
1103    g_rec_header_new.array_actual_header_id(p_hdr_idx)          := g_rec_header_new.array_actual_header_id(p_parent_hdr_idx);
1104    g_rec_header_new.array_budget_header_id(p_hdr_idx)          := g_rec_header_new.array_budget_header_id(p_parent_hdr_idx);
1105    g_rec_header_new.array_encumb_header_id(p_hdr_idx)          := g_rec_header_new.array_encumb_header_id(p_parent_hdr_idx);
1106    g_rec_header_new.array_je_category_name(p_hdr_idx)          := g_rec_header_new.array_je_category_name(p_parent_hdr_idx);
1107    g_rec_header_new.array_period_name(p_hdr_idx)               := g_rec_header_new.array_period_name(p_parent_hdr_idx);
1108    g_rec_header_new.array_description(p_hdr_idx)               := g_rec_header_new.array_description(p_parent_hdr_idx);
1109    g_rec_header_new.array_doc_sequence_id(p_hdr_idx)           := g_rec_header_new.array_doc_sequence_id(p_parent_hdr_idx);
1110    g_rec_header_new.array_doc_sequence_value(p_hdr_idx)        := g_rec_header_new.array_doc_sequence_value(p_parent_hdr_idx);
1111    g_rec_header_new.array_doc_category_code(p_hdr_idx)         := g_rec_header_new.array_doc_category_code(p_parent_hdr_idx);
1112    g_rec_header_new.array_budget_version_id(p_hdr_idx)         := g_rec_header_new.array_budget_version_id(p_parent_hdr_idx);
1113    -- g_rec_header_new.array_encumbrance_type_id(p_hdr_idx)       := g_rec_header_new.array_encumbrance_type_id(p_parent_hdr_idx);
1114    g_rec_header_new.array_party_change_option(p_hdr_idx)       := g_rec_header_new.array_party_change_option(p_parent_hdr_idx);
1115    g_rec_header_new.array_party_change_type(p_hdr_idx)         := g_rec_header_new.array_party_change_type(p_parent_hdr_idx);
1116    g_rec_header_new.array_new_party_id(p_hdr_idx)              := g_rec_header_new.array_new_party_id(p_parent_hdr_idx);
1117    g_rec_header_new.array_new_party_site_id(p_hdr_idx)         := g_rec_header_new.array_new_party_site_id(p_parent_hdr_idx);
1118    g_rec_header_new.array_previous_party_id(p_hdr_idx)         := g_rec_header_new.array_previous_party_id(p_parent_hdr_idx);
1119    g_rec_header_new.array_previous_party_site_id(p_hdr_idx)    := g_rec_header_new.array_previous_party_site_id(p_parent_hdr_idx);
1120    g_rec_header_new.array_gl_transfer_flag(p_hdr_idx)          := g_rec_header_new.array_gl_transfer_flag(p_parent_hdr_idx);
1121    g_rec_header_new.array_trx_acct_reversal_option(p_hdr_idx)  := g_rec_header_new.array_trx_acct_reversal_option(p_parent_hdr_idx);
1122    g_rec_header_new.array_gl_date(p_hdr_idx)                   := g_rec_header_new.array_gl_date(p_parent_hdr_idx);
1123    --
1124    IF NVL(g_rec_header_new.array_accrual_reversal_flag(p_parent_hdr_idx),'N') = 'Y' OR
1125           g_rec_header_new.array_parent_header_id(p_parent_hdr_idx) IS NOT NULL THEN
1126    g_rec_header_new.array_anc_id_1(p_hdr_idx)     := g_rec_header_new.array_anc_id_1(p_parent_hdr_idx);
1127    g_rec_header_new.array_anc_id_2(p_hdr_idx)     := g_rec_header_new.array_anc_id_2(p_parent_hdr_idx);
1128    g_rec_header_new.array_anc_id_3(p_hdr_idx)     := g_rec_header_new.array_anc_id_3(p_parent_hdr_idx);
1129    g_rec_header_new.array_anc_id_4(p_hdr_idx)     := g_rec_header_new.array_anc_id_4(p_parent_hdr_idx);
1130    g_rec_header_new.array_anc_id_5(p_hdr_idx)     := g_rec_header_new.array_anc_id_5(p_parent_hdr_idx);
1131    g_rec_header_new.array_anc_id_6(p_hdr_idx)     := g_rec_header_new.array_anc_id_6(p_parent_hdr_idx);
1132    g_rec_header_new.array_anc_id_7(p_hdr_idx)     := g_rec_header_new.array_anc_id_7(p_parent_hdr_idx);
1133    g_rec_header_new.array_anc_id_8(p_hdr_idx)     := g_rec_header_new.array_anc_id_8(p_parent_hdr_idx);
1134    g_rec_header_new.array_anc_id_9(p_hdr_idx)     := g_rec_header_new.array_anc_id_9(p_parent_hdr_idx);
1135    g_rec_header_new.array_anc_id_10(p_hdr_idx)    := g_rec_header_new.array_anc_id_10(p_parent_hdr_idx);
1136    g_rec_header_new.array_anc_id_11(p_hdr_idx)    := g_rec_header_new.array_anc_id_11(p_parent_hdr_idx);
1137    g_rec_header_new.array_anc_id_12(p_hdr_idx)    := g_rec_header_new.array_anc_id_12(p_parent_hdr_idx);
1138    g_rec_header_new.array_anc_id_13(p_hdr_idx)    := g_rec_header_new.array_anc_id_13(p_parent_hdr_idx);
1139    g_rec_header_new.array_anc_id_14(p_hdr_idx)    := g_rec_header_new.array_anc_id_14(p_parent_hdr_idx);
1140    g_rec_header_new.array_anc_id_15(p_hdr_idx)    := g_rec_header_new.array_anc_id_15(p_parent_hdr_idx);
1141    g_rec_header_new.array_anc_id_16(p_hdr_idx)    := g_rec_header_new.array_anc_id_16(p_parent_hdr_idx);
1142    g_rec_header_new.array_anc_id_17(p_hdr_idx)    := g_rec_header_new.array_anc_id_17(p_parent_hdr_idx);
1143    g_rec_header_new.array_anc_id_18(p_hdr_idx)    := g_rec_header_new.array_anc_id_18(p_parent_hdr_idx);
1144    g_rec_header_new.array_anc_id_19(p_hdr_idx)    := g_rec_header_new.array_anc_id_19(p_parent_hdr_idx);
1145    g_rec_header_new.array_anc_id_20(p_hdr_idx)    := g_rec_header_new.array_anc_id_20(p_parent_hdr_idx);
1146    g_rec_header_new.array_anc_id_21(p_hdr_idx)    := g_rec_header_new.array_anc_id_21(p_parent_hdr_idx);
1147    g_rec_header_new.array_anc_id_22(p_hdr_idx)    := g_rec_header_new.array_anc_id_22(p_parent_hdr_idx);
1148    g_rec_header_new.array_anc_id_23(p_hdr_idx)    := g_rec_header_new.array_anc_id_23(p_parent_hdr_idx);
1149    g_rec_header_new.array_anc_id_24(p_hdr_idx)    := g_rec_header_new.array_anc_id_24(p_parent_hdr_idx);
1150    g_rec_header_new.array_anc_id_25(p_hdr_idx)    := g_rec_header_new.array_anc_id_25(p_parent_hdr_idx);
1151    g_rec_header_new.array_anc_id_26(p_hdr_idx)    := g_rec_header_new.array_anc_id_26(p_parent_hdr_idx);
1152    g_rec_header_new.array_anc_id_27(p_hdr_idx)    := g_rec_header_new.array_anc_id_27(p_parent_hdr_idx);
1153    g_rec_header_new.array_anc_id_28(p_hdr_idx)    := g_rec_header_new.array_anc_id_28(p_parent_hdr_idx);
1154    g_rec_header_new.array_anc_id_29(p_hdr_idx)    := g_rec_header_new.array_anc_id_29(p_parent_hdr_idx);
1155    g_rec_header_new.array_anc_id_30(p_hdr_idx)    := g_rec_header_new.array_anc_id_30(p_parent_hdr_idx);
1156    g_rec_header_new.array_anc_id_31(p_hdr_idx)    := g_rec_header_new.array_anc_id_31(p_parent_hdr_idx);
1157    g_rec_header_new.array_anc_id_32(p_hdr_idx)    := g_rec_header_new.array_anc_id_32(p_parent_hdr_idx);
1158    g_rec_header_new.array_anc_id_33(p_hdr_idx)    := g_rec_header_new.array_anc_id_33(p_parent_hdr_idx);
1159    g_rec_header_new.array_anc_id_34(p_hdr_idx)    := g_rec_header_new.array_anc_id_34(p_parent_hdr_idx);
1160    g_rec_header_new.array_anc_id_35(p_hdr_idx)    := g_rec_header_new.array_anc_id_35(p_parent_hdr_idx);
1161    g_rec_header_new.array_anc_id_36(p_hdr_idx)    := g_rec_header_new.array_anc_id_36(p_parent_hdr_idx);
1162    g_rec_header_new.array_anc_id_37(p_hdr_idx)    := g_rec_header_new.array_anc_id_37(p_parent_hdr_idx);
1163    g_rec_header_new.array_anc_id_38(p_hdr_idx)    := g_rec_header_new.array_anc_id_38(p_parent_hdr_idx);
1164    g_rec_header_new.array_anc_id_39(p_hdr_idx)    := g_rec_header_new.array_anc_id_39(p_parent_hdr_idx);
1165    g_rec_header_new.array_anc_id_40(p_hdr_idx)    := g_rec_header_new.array_anc_id_40(p_parent_hdr_idx);
1166    g_rec_header_new.array_anc_id_41(p_hdr_idx)    := g_rec_header_new.array_anc_id_41(p_parent_hdr_idx);
1167    g_rec_header_new.array_anc_id_42(p_hdr_idx)    := g_rec_header_new.array_anc_id_42(p_parent_hdr_idx);
1168    g_rec_header_new.array_anc_id_43(p_hdr_idx)    := g_rec_header_new.array_anc_id_43(p_parent_hdr_idx);
1169    g_rec_header_new.array_anc_id_44(p_hdr_idx)    := g_rec_header_new.array_anc_id_44(p_parent_hdr_idx);
1170    g_rec_header_new.array_anc_id_45(p_hdr_idx)    := g_rec_header_new.array_anc_id_45(p_parent_hdr_idx);
1171    g_rec_header_new.array_anc_id_46(p_hdr_idx)    := g_rec_header_new.array_anc_id_46(p_parent_hdr_idx);
1172    g_rec_header_new.array_anc_id_47(p_hdr_idx)    := g_rec_header_new.array_anc_id_47(p_parent_hdr_idx);
1173    g_rec_header_new.array_anc_id_48(p_hdr_idx)    := g_rec_header_new.array_anc_id_48(p_parent_hdr_idx);
1174    g_rec_header_new.array_anc_id_49(p_hdr_idx)    := g_rec_header_new.array_anc_id_49(p_parent_hdr_idx);
1175    g_rec_header_new.array_anc_id_50(p_hdr_idx)    := g_rec_header_new.array_anc_id_50(p_parent_hdr_idx);
1176    g_rec_header_new.array_anc_id_51(p_hdr_idx)    := g_rec_header_new.array_anc_id_51(p_parent_hdr_idx);
1177    g_rec_header_new.array_anc_id_52(p_hdr_idx)    := g_rec_header_new.array_anc_id_52(p_parent_hdr_idx);
1178    g_rec_header_new.array_anc_id_53(p_hdr_idx)    := g_rec_header_new.array_anc_id_53(p_parent_hdr_idx);
1179    g_rec_header_new.array_anc_id_54(p_hdr_idx)    := g_rec_header_new.array_anc_id_54(p_parent_hdr_idx);
1180    g_rec_header_new.array_anc_id_55(p_hdr_idx)    := g_rec_header_new.array_anc_id_55(p_parent_hdr_idx);
1181    g_rec_header_new.array_anc_id_56(p_hdr_idx)    := g_rec_header_new.array_anc_id_56(p_parent_hdr_idx);
1182    g_rec_header_new.array_anc_id_57(p_hdr_idx)    := g_rec_header_new.array_anc_id_57(p_parent_hdr_idx);
1183    g_rec_header_new.array_anc_id_58(p_hdr_idx)    := g_rec_header_new.array_anc_id_58(p_parent_hdr_idx);
1184    g_rec_header_new.array_anc_id_59(p_hdr_idx)    := g_rec_header_new.array_anc_id_59(p_parent_hdr_idx);
1185    g_rec_header_new.array_anc_id_60(p_hdr_idx)    := g_rec_header_new.array_anc_id_60(p_parent_hdr_idx);
1186    g_rec_header_new.array_anc_id_61(p_hdr_idx)    := g_rec_header_new.array_anc_id_61(p_parent_hdr_idx);
1187    g_rec_header_new.array_anc_id_62(p_hdr_idx)    := g_rec_header_new.array_anc_id_62(p_parent_hdr_idx);
1188    g_rec_header_new.array_anc_id_63(p_hdr_idx)    := g_rec_header_new.array_anc_id_63(p_parent_hdr_idx);
1189    g_rec_header_new.array_anc_id_64(p_hdr_idx)    := g_rec_header_new.array_anc_id_64(p_parent_hdr_idx);
1190    g_rec_header_new.array_anc_id_65(p_hdr_idx)    := g_rec_header_new.array_anc_id_65(p_parent_hdr_idx);
1191    g_rec_header_new.array_anc_id_66(p_hdr_idx)    := g_rec_header_new.array_anc_id_66(p_parent_hdr_idx);
1192    g_rec_header_new.array_anc_id_67(p_hdr_idx)    := g_rec_header_new.array_anc_id_67(p_parent_hdr_idx);
1193    g_rec_header_new.array_anc_id_68(p_hdr_idx)    := g_rec_header_new.array_anc_id_68(p_parent_hdr_idx);
1194    g_rec_header_new.array_anc_id_69(p_hdr_idx)    := g_rec_header_new.array_anc_id_69(p_parent_hdr_idx);
1195    g_rec_header_new.array_anc_id_70(p_hdr_idx)    := g_rec_header_new.array_anc_id_70(p_parent_hdr_idx);
1196    g_rec_header_new.array_anc_id_71(p_hdr_idx)    := g_rec_header_new.array_anc_id_71(p_parent_hdr_idx);
1197    g_rec_header_new.array_anc_id_72(p_hdr_idx)    := g_rec_header_new.array_anc_id_72(p_parent_hdr_idx);
1198    g_rec_header_new.array_anc_id_73(p_hdr_idx)    := g_rec_header_new.array_anc_id_73(p_parent_hdr_idx);
1199    g_rec_header_new.array_anc_id_74(p_hdr_idx)    := g_rec_header_new.array_anc_id_74(p_parent_hdr_idx);
1200    g_rec_header_new.array_anc_id_75(p_hdr_idx)    := g_rec_header_new.array_anc_id_75(p_parent_hdr_idx);
1201    g_rec_header_new.array_anc_id_76(p_hdr_idx)    := g_rec_header_new.array_anc_id_76(p_parent_hdr_idx);
1202    g_rec_header_new.array_anc_id_77(p_hdr_idx)    := g_rec_header_new.array_anc_id_77(p_parent_hdr_idx);
1203    g_rec_header_new.array_anc_id_78(p_hdr_idx)    := g_rec_header_new.array_anc_id_78(p_parent_hdr_idx);
1204    g_rec_header_new.array_anc_id_79(p_hdr_idx)    := g_rec_header_new.array_anc_id_79(p_parent_hdr_idx);
1205    g_rec_header_new.array_anc_id_80(p_hdr_idx)    := g_rec_header_new.array_anc_id_80(p_parent_hdr_idx);
1206    g_rec_header_new.array_anc_id_81(p_hdr_idx)    := g_rec_header_new.array_anc_id_81(p_parent_hdr_idx);
1207    g_rec_header_new.array_anc_id_82(p_hdr_idx)    := g_rec_header_new.array_anc_id_82(p_parent_hdr_idx);
1208    g_rec_header_new.array_anc_id_83(p_hdr_idx)    := g_rec_header_new.array_anc_id_83(p_parent_hdr_idx);
1209    g_rec_header_new.array_anc_id_84(p_hdr_idx)    := g_rec_header_new.array_anc_id_84(p_parent_hdr_idx);
1210    g_rec_header_new.array_anc_id_85(p_hdr_idx)    := g_rec_header_new.array_anc_id_85(p_parent_hdr_idx);
1211    g_rec_header_new.array_anc_id_86(p_hdr_idx)    := g_rec_header_new.array_anc_id_86(p_parent_hdr_idx);
1212    g_rec_header_new.array_anc_id_87(p_hdr_idx)    := g_rec_header_new.array_anc_id_87(p_parent_hdr_idx);
1213    g_rec_header_new.array_anc_id_88(p_hdr_idx)    := g_rec_header_new.array_anc_id_88(p_parent_hdr_idx);
1214    g_rec_header_new.array_anc_id_89(p_hdr_idx)    := g_rec_header_new.array_anc_id_89(p_parent_hdr_idx);
1215    g_rec_header_new.array_anc_id_90(p_hdr_idx)    := g_rec_header_new.array_anc_id_90(p_parent_hdr_idx);
1216    g_rec_header_new.array_anc_id_91(p_hdr_idx)    := g_rec_header_new.array_anc_id_91(p_parent_hdr_idx);
1217    g_rec_header_new.array_anc_id_92(p_hdr_idx)    := g_rec_header_new.array_anc_id_92(p_parent_hdr_idx);
1218    g_rec_header_new.array_anc_id_93(p_hdr_idx)    := g_rec_header_new.array_anc_id_93(p_parent_hdr_idx);
1219    g_rec_header_new.array_anc_id_94(p_hdr_idx)    := g_rec_header_new.array_anc_id_94(p_parent_hdr_idx);
1220    g_rec_header_new.array_anc_id_95(p_hdr_idx)    := g_rec_header_new.array_anc_id_95(p_parent_hdr_idx);
1221    g_rec_header_new.array_anc_id_96(p_hdr_idx)    := g_rec_header_new.array_anc_id_96(p_parent_hdr_idx);
1222    g_rec_header_new.array_anc_id_97(p_hdr_idx)    := g_rec_header_new.array_anc_id_97(p_parent_hdr_idx);
1223    g_rec_header_new.array_anc_id_98(p_hdr_idx)    := g_rec_header_new.array_anc_id_98(p_parent_hdr_idx);
1224    g_rec_header_new.array_anc_id_99(p_hdr_idx)    := g_rec_header_new.array_anc_id_99(p_parent_hdr_idx);
1225    g_rec_header_new.array_anc_id_100(p_hdr_idx)   := g_rec_header_new.array_anc_id_100(p_parent_hdr_idx);
1226    END IF;
1227 
1228    --
1229    g_rec_header_new.array_event_number(p_hdr_idx)       := g_rec_header_new.array_event_number(p_parent_hdr_idx);
1230    g_rec_header_new.array_actual_status(p_hdr_idx)      := g_rec_header_new.array_actual_status(p_parent_hdr_idx);
1231    g_rec_header_new.array_budget_status(p_hdr_idx)      := g_rec_header_new.array_budget_status(p_parent_hdr_idx);
1232    g_rec_header_new.array_encumbrance_status(p_hdr_idx) := g_rec_header_new.array_encumbrance_status(p_parent_hdr_idx);
1233    g_rec_header_new.array_event_status(p_hdr_idx)       := g_rec_header_new.array_event_status(p_parent_hdr_idx);
1234 
1235    --------------------------------------------------------------------------------------------------
1236    --------------------------------------------------------------------------------------------------
1237 
1238    -------------------------------------------
1239    -- Validate header accounting attributes
1240    -------------------------------------------
1241    IF NVL(g_rec_header_new.array_party_change_option(p_hdr_idx),'N') NOT IN ('Y','N') THEN
1242       XLA_AE_JOURNAL_ENTRY_PKG.g_global_status :=  XLA_AE_JOURNAL_ENTRY_PKG.C_INVALID;
1243       xla_accounting_err_pkg.build_message
1244             (p_appli_s_name            => 'XLA'
1245             ,p_msg_name                => 'XLA_AP_THIRD_PARTY_OPTION'
1246             ,p_token_1                 => 'PRODUCT_NAME'
1247             ,p_value_1                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
1248             ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
1249             ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
1250             ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id);
1251    END IF;
1252 
1253    IF g_rec_header_new.array_gl_transfer_flag(p_hdr_idx) NOT IN ('Y', 'N') THEN
1254       XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_INVALID;
1255       xla_accounting_err_pkg.build_message
1256             (p_appli_s_name            => 'XLA'
1257             ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
1258             ,p_token_1                 => 'ACCT_ATTR_NAME'
1259             ,p_value_1                 => XLA_AE_SOURCES_PKG.GetAccountingSourceName('GL_TRANSFER_FLAG')
1260             ,p_token_2                 => 'PRODUCT_NAME'
1261             ,p_value_2                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
1262             ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
1263             ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
1264             ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id);
1265    END IF;
1266 
1267    IF g_rec_header_new.array_trx_acct_reversal_option(p_hdr_idx) NOT IN ('Y', 'N') THEN
1268       XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_INVALID;
1269       xla_accounting_err_pkg.build_message
1270             (p_appli_s_name            => 'XLA'
1271             ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
1272             ,p_token_1                 => 'ACCT_ATTR_NAME'
1273             ,p_value_1                 => XLA_AE_SOURCES_PKG.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
1274             ,p_token_2                 => 'PRODUCT_NAME'
1275             ,p_value_2                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
1276             ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
1277             ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
1278             ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id);
1279    END IF;
1280 
1281    IF g_rec_header_new.array_gl_date(p_hdr_idx) is NULL THEN
1282       XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_INVALID;
1283       xla_accounting_err_pkg.build_message
1284             (p_appli_s_name            => 'XLA'
1285             ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
1286             ,p_token_1                 => 'ACCT_ATTR_NAME'
1287             ,p_value_1                 => XLA_AE_SOURCES_PKG.GetAccountingSourceName('GL_DATE')
1288             ,p_token_2                 => 'PRODUCT_NAME'
1289             ,p_value_2                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
1290             ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
1291             ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
1292             ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id);
1293    END IF;
1294 
1295    --
1296    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1297           trace
1298              (p_msg      => 'END of CopyHeaderInfo'
1299              ,p_level    => C_LEVEL_PROCEDURE
1300              ,p_module   => l_log_module);
1301    END IF;
1302 
1303 EXCEPTION
1304 
1305 WHEN xla_exceptions_pkg.application_exception   THEN
1306    IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1307             trace
1308                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
1309                ,p_level    => C_LEVEL_EXCEPTION
1310                ,p_module   => l_log_module);
1311    END IF;
1312    RAISE;
1313 WHEN OTHERS THEN
1314    xla_exceptions_pkg.raise_message
1315       (p_location => 'xla_ae_header_pkg.CopyHeaderInfo');
1316 END CopyHeaderInfo;
1317 
1318 
1319 /*======================================================================+
1320 |                                                                       |
1321 | Public  Procedure - 4262811                                           |
1322 |                                                                       |
1323 |                                                                       |
1324 +======================================================================*/
1325 FUNCTION CreateRecognitionEntries(
1326   p_event_id           IN INTEGER
1327 , p_num_entries        IN INTEGER
1328 , p_last_hdr_idx       IN INTEGER
1329 , p_recog_line_num_1   IN INTEGER
1330 , p_recog_line_num_2   IN INTEGER
1331 , p_gl_dates           IN xla_ae_journal_entry_pkg.t_array_date
1332 , p_accted_amts        IN xla_ae_journal_entry_pkg.t_array_num
1333 , p_entered_amts       IN xla_ae_journal_entry_pkg.t_array_num
1334 , p_bflow_applied_to_amts   IN xla_ae_journal_entry_pkg.t_array_num  -- 5132302
1335 ) RETURN NUMBER
1336 IS
1337 
1338 l_hdr_idx             NUMBER;
1339 l_log_module          VARCHAR2(240);
1340 
1341 i                     NUMBER;
1342 
1343 BEGIN
1344 
1345    IF g_log_enabled THEN
1346       l_log_module := C_DEFAULT_MODULE||'.CreateRecognitionEntries';
1347    END IF;
1348    --
1349    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1350        trace
1351              (p_msg      => 'BEGIN of CreateRecognitionEntries'
1352              ,p_level    => C_LEVEL_PROCEDURE
1353              ,p_module   => l_log_module);
1354    END IF;
1355 
1356    l_hdr_idx := p_last_hdr_idx;  -- initialise
1357 
1358    -------------------------------------------------------------------------------------
1359    -- Copy the following information from the first recognition line to the current line
1360    -------------------------------------------------------------------------------------
1361    FOR i IN 2..p_num_entries LOOP
1362 
1363       --**************************************************************************************************************
1364       -- awan Problem with multiple Accrual JLT, they are all created under the first Accrual JLT
1365       -- Need to differentiate the different JLT journal lines
1366       --**************************************************************************************************************
1367       g_mpa_line_num := NVL(g_mpa_line_num,0) + 1;
1368       --**************************************************************************************************************
1369 
1370       -----------------------------------
1371       -- create header
1372       -----------------------------------
1373       l_hdr_idx := l_hdr_idx + 1;
1374 
1375       CopyHeaderInfo( p_parent_hdr_idx => p_last_hdr_idx
1376                     , p_hdr_idx        => l_hdr_idx);
1377 
1378       --**************************************************************************************************************
1379       -- 4262811a  Copy the MPA Gl date Option to be used in PostAccountingEngine
1380       g_rec_header_new.array_acc_rev_gl_date_option (l_hdr_idx) :=
1381                                                        g_rec_header_new.array_acc_rev_gl_date_option (p_last_hdr_idx);
1382       --**************************************************************************************************************
1383 
1384       --**************************************************************************************************************
1385       g_rec_header_new.array_header_num(l_hdr_idx) := g_mpa_line_num ;  --  multiple JLT
1386       --g_rec_header_new.array_header_num(l_hdr_idx) := i;              --  multiple JLT  original
1387       --**************************************************************************************************************
1388       g_rec_header_new.array_gl_date(l_hdr_idx)    := trunc(p_gl_dates(i));
1389 
1390 
1391       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx           => l_hdr_idx
1392                                                         ,p_balance_type_code => 'A');
1393 
1394       -----------------------------------------------------------
1395       -- create recognition line - for Recognition JLT1
1396       -----------------------------------------------------------
1397       XLA_AE_LINES_PKG.CopyLineInfo(p_recog_line_num_1);
1398       --**************************************************************************************************************
1399       XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id
1400                                        ,p_header_num   => g_mpa_line_num );  -- multiple JLT
1401                                      --,p_header_num   => i);                -- original multiple JLT
1402       --**************************************************************************************************************
1403       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount (XLA_AE_LINES_PKG.g_LineNumber)  := p_accted_amts(i);
1404       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount (XLA_AE_LINES_PKG.g_LineNumber) := p_entered_amts(i);
1405       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt (XLA_AE_LINES_PKG.g_LineNumber) := p_bflow_applied_to_amts(i); -- 5132302
1406 
1407       -- 4955764
1408       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1409                                                                    g_rec_header_new.array_gl_date(l_hdr_idx);
1410 
1411       XLA_AE_LINES_PKG.ValidateCurrentLine;
1412       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1413 
1414       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx           => l_hdr_idx
1415                                                         ,p_balance_type_code => 'A');
1416 
1417       -----------------------------------------------------------
1418       -- create recognition line - for Recognition JLT2
1419       -----------------------------------------------------------
1420       XLA_AE_LINES_PKG.CopyLineInfo(p_recog_line_num_2);
1421       --**************************************************************************************************************
1422       XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id
1423                                        ,p_header_num   => g_mpa_line_num );   -- multiple JLT
1424                                      --,p_header_num   => i);                 -- original  multiple JLT
1425       --**************************************************************************************************************
1426       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount (XLA_AE_LINES_PKG.g_LineNumber) := p_accted_amts(i);
1427       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount (XLA_AE_LINES_PKG.g_LineNumber) := p_entered_amts(i);
1428       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt (XLA_AE_LINES_PKG.g_LineNumber) := p_bflow_applied_to_amts(i); -- 5132302
1429 
1430       -- 4955764
1431       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1432                                                                    g_rec_header_new.array_gl_date(l_hdr_idx);
1433       XLA_AE_LINES_PKG.ValidateCurrentLine;
1434       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1435 
1436       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx           => l_hdr_idx
1437                                                         ,p_balance_type_code => 'A');
1438 
1439    END LOOP;
1440 
1441    --
1442    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1443           trace
1444              (p_msg      => 'END of CreateRecognitionEntries'
1445              ,p_level    => C_LEVEL_PROCEDURE
1446              ,p_module   => l_log_module);
1447    END IF;
1448 
1449    RETURN l_hdr_idx;  -- return to g_last_hdr_idx
1450 
1451 EXCEPTION
1452 WHEN xla_exceptions_pkg.application_exception   THEN
1453    IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1454             trace
1455                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
1456                ,p_level    => C_LEVEL_EXCEPTION
1457                ,p_module   => l_log_module);
1458    END IF;
1459    RETURN NULL;
1460 WHEN OTHERS THEN
1461    xla_exceptions_pkg.raise_message
1462       (p_location => 'xla_ae_header_pkg.CreateRecognitionEntries');
1463 
1464 END CreateRecognitionEntries;
1465 
1466 /*======================================================================+
1467 |                                                                       |
1468 | Public Procedure                                                      |
1469 |                                                                       |
1470 |                                                                       |
1471 +======================================================================*/
1472 PROCEDURE SetJeCategoryName
1473 IS
1474 l_log_module         VARCHAR2(240);
1475 BEGIN
1476 --
1477 IF g_log_enabled THEN
1478       l_log_module := C_DEFAULT_MODULE||'.SetJeCategoryName';
1479 END IF;
1480 --
1481 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1482 
1483       trace
1484          (p_msg      => 'BEGIN of SetJeCategoryName'
1485          ,p_level    => C_LEVEL_PROCEDURE
1486          ,p_module   => l_log_module);
1487 END IF;
1488 --
1489 g_rec_header_new.array_je_category_name(g_header_idx)  := xla_accounting_cache_pkg.get_je_category(
1490                p_ledger_id        => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.base_ledger_id
1491               ,p_event_class_code => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_class);
1492 --
1493 
1494 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1495 
1496       trace
1497          (p_msg      => 'return value. = '||g_rec_header_new.array_je_category_name(g_header_idx)
1498          ,p_level    => C_LEVEL_PROCEDURE
1499          ,p_module   => l_log_module);
1500 
1501       trace
1502          (p_msg      => 'END of SetJeCategoryName'
1503          ,p_level    => C_LEVEL_PROCEDURE
1504          ,p_module   => l_log_module);
1505 END IF;
1506 --
1507 EXCEPTION
1508   WHEN xla_exceptions_pkg.application_exception THEN
1509       XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    :=  XLA_AE_JOURNAL_ENTRY_PKG.C_INVALID;
1510       RAISE;
1511   WHEN OTHERS  THEN
1512        xla_exceptions_pkg.raise_message
1513                (p_location => 'XLA_AE_HEADER_PKG.InitHeader');
1514        --
1515 END SetJeCategoryName;
1516 --
1517 --
1518 /*======================================================================+
1519 |                                                                       |
1520 | Public Function                                                       |
1521 |                                                                       |
1522 |   SetAnalyticalCriteria                                               |
1523 |                                                                       |
1524 +======================================================================*/
1525 --
1526 FUNCTION SetAnalyticalCriteria(
1527    p_analytical_criterion_name    IN VARCHAR2
1528  , p_analytical_criterion_owner   IN VARCHAR2
1529  , p_analytical_criterion_code    IN VARCHAR2
1530  , p_amb_context_code             IN VARCHAR2
1531  , p_balancing_flag               IN VARCHAR2
1532 --
1533  , p_analytical_detail_char_1     IN VARCHAR2
1534  , p_analytical_detail_num_1      IN NUMBER
1535  , p_analytical_detail_date_1     IN DATE
1536  , p_analytical_detail_char_2     IN VARCHAR2
1537  , p_analytical_detail_num_2      IN NUMBER
1538  , p_analytical_detail_date_2     IN DATE
1539  , p_analytical_detail_char_3     IN VARCHAR2
1540  , p_analytical_detail_num_3      IN NUMBER
1541  , p_analytical_detail_date_3     IN DATE
1542  , p_analytical_detail_char_4     IN VARCHAR2
1543  , p_analytical_detail_num_4      IN NUMBER
1544  , p_analytical_detail_date_4     IN DATE
1545  , p_analytical_detail_char_5     IN VARCHAR2
1546  , p_analytical_detail_num_5      IN NUMBER
1547  , p_analytical_detail_date_5     IN DATE
1548 --
1549 )
1550 RETURN VARCHAR2
1551 IS
1552 l_analytical_criteria  VARCHAR2(240);
1553 l_log_module           VARCHAR2(240);
1554 BEGIN
1555 --
1556 IF g_log_enabled THEN
1557       l_log_module := C_DEFAULT_MODULE||'.SetAnalyticalCriteria';
1558 END IF;
1559 --
1560 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1561 
1562       trace
1563          (p_msg      => 'BEGIN of SetAnalyticalCriteria'
1564          ,p_level    => C_LEVEL_PROCEDURE
1565          ,p_module   => l_log_module);
1566 
1567 END IF;
1568 --
1569 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1570 
1571      trace
1572          (p_msg      => 'p_analytical_criterion_name  = '||p_analytical_criterion_name
1573          ,p_level    => C_LEVEL_STATEMENT
1574          ,p_module   => l_log_module);
1575 
1576      trace
1577          (p_msg      => 'p_analytical_criterion_owner = '||p_analytical_criterion_owner
1578          ,p_level    => C_LEVEL_STATEMENT
1579          ,p_module   => l_log_module);
1580 
1581      trace
1582          (p_msg      => 'p_analytical_criterion_code = '||p_analytical_criterion_code
1583          ,p_level    => C_LEVEL_STATEMENT
1584          ,p_module   => l_log_module);
1585 
1586      trace
1587          (p_msg      => 'p_amb_context_code = '||p_amb_context_code
1588          ,p_level    => C_LEVEL_STATEMENT
1589          ,p_module   => l_log_module);
1590 
1591      trace
1592          (p_msg      => 'p_balancing_flag = '||p_balancing_flag
1593          ,p_level    => C_LEVEL_STATEMENT
1594          ,p_module   => l_log_module);
1595      trace
1596          (p_msg      => 'p_analytical_detail_char_1 = '||p_analytical_detail_char_1
1597          ,p_level    => C_LEVEL_STATEMENT
1598          ,p_module   => l_log_module);
1599 
1600      trace
1601          (p_msg      => 'p_analytical_detail_char_2 = '||p_analytical_detail_char_2
1602          ,p_level    => C_LEVEL_STATEMENT
1603          ,p_module   => l_log_module);
1604 
1605      trace
1606          (p_msg      => 'p_analytical_detail_char_3 = '||p_analytical_detail_char_3
1607          ,p_level    => C_LEVEL_STATEMENT
1608          ,p_module   => l_log_module);
1609 
1610      trace
1611          (p_msg      => 'p_analytical_detail_char_4 = '||p_analytical_detail_char_4
1612          ,p_level    => C_LEVEL_STATEMENT
1613          ,p_module   => l_log_module);
1614 
1615      trace
1616          (p_msg      => 'p_analytical_detail_char_5 = '||p_analytical_detail_char_5
1617          ,p_level    => C_LEVEL_STATEMENT
1618          ,p_module   => l_log_module);
1619 
1620      trace
1621          (p_msg      => 'p_analytical_detail_num_1 = '||p_analytical_detail_num_1
1622          ,p_level    => C_LEVEL_STATEMENT
1623          ,p_module   => l_log_module);
1624 
1625      trace
1626          (p_msg      => 'p_analytical_detail_num_2 = '||p_analytical_detail_num_2
1627          ,p_level    => C_LEVEL_STATEMENT
1628          ,p_module   => l_log_module);
1629 
1630      trace
1631          (p_msg      => 'p_analytical_detail_num_3 = '||p_analytical_detail_num_3
1632          ,p_level    => C_LEVEL_STATEMENT
1633          ,p_module   => l_log_module);
1634      trace
1635          (p_msg      => 'p_analytical_detail_num_4 = '||p_analytical_detail_num_4
1636          ,p_level    => C_LEVEL_STATEMENT
1637          ,p_module   => l_log_module);
1638 
1639      trace
1640          (p_msg      => 'p_analytical_detail_num_5 = '||p_analytical_detail_num_5
1641          ,p_level    => C_LEVEL_STATEMENT
1642          ,p_module   => l_log_module);
1643 
1644      trace
1645          (p_msg      => 'p_analytical_detail_date_1 = '||p_analytical_detail_date_1
1646          ,p_level    => C_LEVEL_STATEMENT
1647          ,p_module   => l_log_module);
1648 
1649      trace
1650          (p_msg      => 'p_analytical_detail_date_2 = '||p_analytical_detail_date_2
1651          ,p_level    => C_LEVEL_STATEMENT
1652          ,p_module   => l_log_module);
1653 
1654      trace
1655          (p_msg      => 'p_analytical_detail_date_3 = '||p_analytical_detail_date_3
1656          ,p_level    => C_LEVEL_STATEMENT
1657          ,p_module   => l_log_module);
1658 
1659      trace
1660          (p_msg      => 'p_analytical_detail_date_4 = '||p_analytical_detail_date_4
1661          ,p_level    => C_LEVEL_STATEMENT
1662          ,p_module   => l_log_module);
1663 
1664      trace
1665          (p_msg      => 'p_analytical_detail_date_5 = '||p_analytical_detail_date_5
1666          ,p_level    => C_LEVEL_STATEMENT
1667          ,p_module   => l_log_module);
1668 
1669 END IF;
1670 --
1671 l_analytical_criteria :=  XLA_ANALYTICAL_CRITERIA_PKG.concat_detail_values
1672                 ( p_anacri_code              => p_analytical_criterion_code
1673                  ,p_anacri_type_code         => p_analytical_criterion_owner
1674                  ,p_amb_context_code         => p_amb_context_code
1675                  ,p_detail_char_1            => p_analytical_detail_char_1
1676                  ,p_detail_date_1            => p_analytical_detail_date_1
1677                  ,p_detail_number_1          => p_analytical_detail_num_1
1678                  ,p_detail_char_2            => p_analytical_detail_char_2
1679                  ,p_detail_date_2            => p_analytical_detail_date_2
1680                  ,p_detail_number_2          => p_analytical_detail_num_2
1681                  ,p_detail_char_3            => p_analytical_detail_char_3
1682                  ,p_detail_date_3            => p_analytical_detail_date_3
1683                  ,p_detail_number_3          => p_analytical_detail_num_3
1684                  ,p_detail_char_4            => p_analytical_detail_char_4
1685                  ,p_detail_date_4            => p_analytical_detail_date_4
1686                  ,p_detail_number_4          => p_analytical_detail_num_4
1687                  ,p_detail_char_5            => p_analytical_detail_char_5
1688                  ,p_detail_date_5            => p_analytical_detail_date_5
1689                  ,p_detail_number_5          => p_analytical_detail_num_5
1690                 );
1691 --
1692 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1693       trace
1694          (p_msg      => 'return value. = '||TO_CHAR(l_analytical_criteria)
1695          ,p_level    => C_LEVEL_PROCEDURE
1696          ,p_module   => l_log_module);
1697 
1698       trace
1699          (p_msg      => 'END of SetAnalyticalCriteria'
1700          ,p_level    => C_LEVEL_PROCEDURE
1701          ,p_module   => l_log_module);
1702 
1703 END IF;
1704 RETURN l_analytical_criteria;
1705 EXCEPTION
1706 WHEN xla_exceptions_pkg.application_exception THEN
1707  XLA_AE_JOURNAL_ENTRY_PKG.g_global_status     :=  XLA_AE_JOURNAL_ENTRY_PKG.C_INVALID;
1708  RETURN NULL;
1709 WHEN OTHERS  THEN
1710    xla_exceptions_pkg.raise_message
1711            (p_location => 'XLA_AE_HEADER_PKG.SetAnalyticalCriteria');
1712   --
1713 END SetAnalyticalCriteria;
1714 
1715 
1716 /*======================================================================+
1717 |                                                                       |
1718 | Public Procedure                                                      |
1719 |                                                                       |
1720 |   SetHdrDescription                                                   |
1721 |                                                                       |
1722 +======================================================================*/
1723 PROCEDURE SetHdrDescription(
1724   p_description         IN VARCHAR2
1725 )
1726 IS
1727 l_log_module         VARCHAR2(240);
1728 BEGIN
1729 --
1730 IF g_log_enabled THEN
1731       l_log_module := C_DEFAULT_MODULE||'.SetHdrDescription';
1732 END IF;
1733 --
1734 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1735 
1736       trace
1737          (p_msg      => 'BEGIN of SetHdrDescription'
1738          ,p_level    => C_LEVEL_PROCEDURE
1739          ,p_module   => l_log_module);
1740 END IF;
1741 --
1742    g_rec_header_new.array_description(g_header_idx)  := SUBSTR(p_description,1,1996);
1743 --
1744 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1745 
1746       trace
1747          (p_msg      => 'END of SetHdrDescription'
1748          ,p_level    => C_LEVEL_PROCEDURE
1749          ,p_module   => l_log_module);
1750 END IF;
1751 EXCEPTION
1752 --
1753 WHEN xla_exceptions_pkg.application_exception THEN
1754   XLA_AE_JOURNAL_ENTRY_PKG.g_global_status     :=  XLA_AE_JOURNAL_ENTRY_PKG.C_INVALID;
1755   RAISE;
1756 WHEN OTHERS  THEN
1757    xla_exceptions_pkg.raise_message
1758            (p_location => 'XLA_AE_HEADER_PKG.SetHdrDescription');
1759 END SetHdrDescription;
1760 --
1761 /*======================================================================+
1762 |                                                                       |
1763 | PRIVATE Procedure                                                     |
1764 |     InsertHeaders                                                     |
1765 |                                                                       |
1766 +======================================================================*/
1767 FUNCTION  InsertHeaders
1768 RETURN BOOLEAN
1769 IS
1770 --
1771 l_period_name            VARCHAR2(25);
1772 l_array_header_id        XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
1773 l_array_balance_type     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V1L;
1774 l_result                 BOOLEAN;
1775 l_Idx                    BINARY_INTEGER := 0;
1776 l_log_module             VARCHAR2(240);
1777 -- added 7526530
1778 errors                     NUMBER;
1779 ERR_IND                    NUMBER;
1780 ERR_CODE                   VARCHAR2(100);
1781 dml_errors                 EXCEPTION;
1782 PRAGMA exception_init(dml_errors, -24381);
1783 -- end 7526530
1784 BEGIN
1785 --
1786 IF g_log_enabled THEN
1787       l_log_module := C_DEFAULT_MODULE||'.InsertHeaders';
1788 END IF;
1789 --
1790 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1791 
1792       trace
1793          (p_msg      => 'BEGIN of InsertHeaders'
1794          ,p_level    => C_LEVEL_PROCEDURE
1795          ,p_module   => l_log_module);
1796 
1797 END IF;
1798 --
1799 l_result            := TRUE;
1800 
1801 --
1802 -- create headers
1803 --
1804 -- how is the following used??
1805 /*
1806 IF g_rec_header_new.array_actual_header_id(g_header_idx) > 0 THEN
1807    --
1808     l_Idx                            :=  l_Idx + 1;
1809     l_array_header_id(l_Idx)         :=  g_rec_header_new.array_actual_header_id(g_header_idx);
1810     l_array_balance_type(l_Idx)      :=  C_ACTUAL;
1811    --
1812     l_period_name                    := get_period_name(
1813                                             p_ledger_id        => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
1814                                           , p_accounting_date  => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_date
1815                                           , p_ae_header_id     => g_rec_header_new.array_actual_header_id(g_header_idx)
1816                                           );
1817 END IF;
1818   --
1819 IF g_rec_header_new.array_budget_header_id(g_header_idx) > 0 THEN
1820     --
1821     l_Idx                            :=  l_Idx + 1;
1822     l_array_header_id(l_Idx)         :=  g_rec_header_new.array_budget_header_id(g_header_idx);
1823     l_array_balance_type(l_Idx)      :=  C_BUDGET;
1824     --
1825     l_period_name                    := get_period_name(
1826                                             p_ledger_id        => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
1827                                           , p_accounting_date  => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_date
1828                                           , p_ae_header_id     => g_rec_header_new.array_budget_header_id(g_header_idx)
1829                                           );
1830 END IF;
1831   --
1832 IF g_rec_header_new.array_encumb_header_id(g_header_idx) > 0 THEN
1833    --
1834    l_Idx                            :=  l_Idx + 1;
1835    l_array_header_id(l_Idx)         :=  g_rec_header_new.array_encumb_header_id(g_header_idx);
1836    l_array_balance_type(l_Idx)      :=  C_ENCUMBRANCE;
1837    --
1838    l_period_name                    := get_period_name(
1839                                             p_ledger_id        => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
1840                                           , p_accounting_date  => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_date
1841                                           , p_ae_header_id     => g_rec_header_new.array_encumb_header_id(g_header_idx)
1842                                           );
1843 END IF;
1844 */
1845 --
1846 -- insert the headers created
1847 --
1848 --
1849 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1850     trace
1851        (p_msg      => 'g_rec_header_new.array_je_category_name.count = '||
1852                       g_rec_header_new.array_je_category_name.count
1853        ,p_level    => C_LEVEL_STATEMENT
1854        ,p_module   => l_log_module);
1855 END IF;
1856 --
1857 --
1858 --IF l_array_header_id.COUNT > 0  AND l_period_name IS NOT NULL THEN
1859 
1860      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1861 
1862          trace
1863             (p_msg      => 'SQL - Insert into  xla_ae_headers_gt'
1864             ,p_level    => C_LEVEL_STATEMENT
1865             ,p_module   => l_log_module);
1866      END IF;
1867 
1868 
1869 FORALL Idx IN 1..g_rec_header_new.array_je_category_name.count  SAVE EXCEPTIONS --added Save exception 7526530
1870     INSERT INTO xla_ae_headers_gt
1871        ( ae_header_id
1872        , accounting_entry_status_code
1873        , accounting_entry_type_code
1874        , ledger_id
1875        , entity_id
1876        , event_id
1877        , event_type_code
1878        , accounting_date
1879        , product_rule_type_code
1880        , product_rule_code
1881        , product_rule_version
1882        , je_category_name
1883        --, period_name
1884        , doc_sequence_id
1885        , doc_sequence_value
1886        , description
1887        , budget_version_id
1888        --, encumbrance_type_id
1889        , balance_type_code
1890        , amb_context_code
1891        , doc_category_code
1892        , gl_transfer_status_code
1893        , event_status_code
1894        , anc_id_1
1895        , anc_id_2
1896        , anc_id_3
1897        , anc_id_4
1898        , anc_id_5
1899        , anc_id_6
1900        , anc_id_7
1901        , anc_id_8
1902        , anc_id_9
1903        , anc_id_10
1904        , anc_id_11
1905        , anc_id_12
1906        , anc_id_13
1907        , anc_id_14
1908        , anc_id_15
1909        , anc_id_16
1910        , anc_id_17
1911        , anc_id_18
1912        , anc_id_19
1913        , anc_id_20
1914        , anc_id_21
1915        , anc_id_22
1916        , anc_id_23
1917        , anc_id_24
1918        , anc_id_25
1919        , anc_id_26
1920        , anc_id_27
1921        , anc_id_28
1922        , anc_id_29
1923        , anc_id_30
1924        , anc_id_31
1925        , anc_id_32
1926        , anc_id_33
1927        , anc_id_34
1928        , anc_id_35
1929        , anc_id_36
1930        , anc_id_37
1931        , anc_id_38
1932        , anc_id_39
1933        , anc_id_40
1934        , anc_id_41
1935        , anc_id_42
1936        , anc_id_43
1937        , anc_id_44
1938        , anc_id_45
1939        , anc_id_46
1940        , anc_id_47
1941        , anc_id_48
1942        , anc_id_49
1943        , anc_id_50
1944        , anc_id_51
1945        , anc_id_52
1946        , anc_id_53
1947        , anc_id_54
1948        , anc_id_55
1949        , anc_id_56
1950        , anc_id_57
1951        , anc_id_58
1952        , anc_id_59
1953        , anc_id_60
1954        , anc_id_61
1955        , anc_id_62
1956        , anc_id_63
1957        , anc_id_64
1958        , anc_id_65
1959        , anc_id_66
1960        , anc_id_67
1961        , anc_id_68
1962        , anc_id_69
1963        , anc_id_70
1964        , anc_id_71
1965        , anc_id_72
1966        , anc_id_73
1967        , anc_id_74
1968        , anc_id_75
1969        , anc_id_76
1970        , anc_id_77
1971        , anc_id_78
1972        , anc_id_79
1973        , anc_id_80
1974        , anc_id_81
1975        , anc_id_82
1976        , anc_id_83
1977        , anc_id_84
1978        , anc_id_85
1979        , anc_id_86
1980        , anc_id_87
1981        , anc_id_88
1982        , anc_id_89
1983        , anc_id_90
1984        , anc_id_91
1985        , anc_id_92
1986        , anc_id_93
1987        , anc_id_94
1988        , anc_id_95
1989        , anc_id_96
1990        , anc_id_97
1991        , anc_id_98
1992        , anc_id_99
1993        , anc_id_100
1994        --
1995        , event_number
1996        , header_num               -- 4262811
1997        , accrual_reversal_flag    -- 4262811
1998        , acc_rev_gl_date_option   -- 4262811
1999        , parent_header_id         -- 4262811
2000        , parent_ae_line_num)      -- 4262811
2001        (SELECT  /*+ INDEX (AEL, XLA_AE_LINES_GT_N2) */      -- 4752774
2002                  g_rec_header_new.array_event_id(Idx)
2003                , CASE ael.balance_type_code
2004                    when C_BUDGET THEN
2005                       g_rec_header_new.array_budget_status(Idx)
2006                    when C_ENCUMBRANCE THEN
2007                       g_rec_header_new.array_encumbrance_status(Idx)
2008                    when C_ACTUAL THEN
2009                       g_rec_header_new.array_actual_status(Idx)
2010                    ELSE
2011                       XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED
2012                  END CASE
2013                , C_STANDARD
2014                , g_rec_header_new.array_target_ledger_id(Idx)
2015                , g_rec_header_new.array_entity_id(Idx)
2016                , g_rec_header_new.array_event_id(Idx)
2017                , g_rec_header_new.array_event_type_code(Idx)
2018                , g_rec_header_new.array_gl_date(Idx)
2019                , XLA_AE_JOURNAL_ENTRY_PKG.g_cache_pad.product_rule_type_code
2020                , XLA_AE_JOURNAL_ENTRY_PKG.g_cache_pad.product_rule_code
2021                , XLA_AE_JOURNAL_ENTRY_PKG.g_cache_pad.product_rule_version
2022                , g_rec_header_new.array_je_category_name(Idx)
2023                --, 'XYZ' --l_period_name
2024                , g_rec_header_new.array_doc_sequence_id(Idx)
2025                , g_rec_header_new.array_doc_sequence_value(Idx)
2026                , g_rec_header_new.array_description(Idx)
2027                , DECODE(ael.balance_type_code  -- 4924492
2028                        ,C_BUDGET, g_rec_header_new.array_budget_version_id(Idx)
2029                        ,'X', g_rec_header_new.array_budget_version_id(Idx)
2030                        ,NULL)
2031                --, DECODE(ael.balance_type_code, C_ENCUMBRANCE, g_rec_header_new.array_encumbrance_type_id(Idx)
2032                --         , NULL)  -- 4458381  Public Sector Enh
2033                , ael.balance_type_code
2034                , XLA_AE_JOURNAL_ENTRY_PKG.g_cache_pad.amb_context_code
2035                , g_rec_header_new.array_doc_category_code(Idx)
2036                , DECODE(g_rec_header_new.array_gl_transfer_flag(Idx), 'N', 'NT', 'Y', 'N', 'N')
2037                , g_rec_header_new.array_event_status(Idx)
2038                , g_rec_header_new.array_anc_id_1(Idx)
2039                , g_rec_header_new.array_anc_id_2(Idx)
2040                , g_rec_header_new.array_anc_id_3(Idx)
2041                , g_rec_header_new.array_anc_id_4(Idx)
2042                , g_rec_header_new.array_anc_id_5(Idx)
2043                , g_rec_header_new.array_anc_id_6(Idx)
2044                , g_rec_header_new.array_anc_id_7(Idx)
2045                , g_rec_header_new.array_anc_id_8(Idx)
2046                , g_rec_header_new.array_anc_id_9(Idx)
2047                , g_rec_header_new.array_anc_id_10(Idx)
2048                , g_rec_header_new.array_anc_id_11(Idx)
2049                , g_rec_header_new.array_anc_id_12(Idx)
2050                , g_rec_header_new.array_anc_id_13(Idx)
2051                , g_rec_header_new.array_anc_id_14(Idx)
2052                , g_rec_header_new.array_anc_id_15(Idx)
2053                , g_rec_header_new.array_anc_id_16(Idx)
2054                , g_rec_header_new.array_anc_id_17(Idx)
2055                , g_rec_header_new.array_anc_id_18(Idx)
2056                , g_rec_header_new.array_anc_id_19(Idx)
2057                , g_rec_header_new.array_anc_id_20(Idx)
2058                , g_rec_header_new.array_anc_id_21(Idx)
2059                , g_rec_header_new.array_anc_id_22(Idx)
2060                , g_rec_header_new.array_anc_id_23(Idx)
2061                , g_rec_header_new.array_anc_id_24(Idx)
2062                , g_rec_header_new.array_anc_id_25(Idx)
2063                , g_rec_header_new.array_anc_id_26(Idx)
2064                , g_rec_header_new.array_anc_id_27(Idx)
2065                , g_rec_header_new.array_anc_id_28(Idx)
2066                , g_rec_header_new.array_anc_id_29(Idx)
2067                , g_rec_header_new.array_anc_id_30(Idx)
2068                , g_rec_header_new.array_anc_id_31(Idx)
2069                , g_rec_header_new.array_anc_id_32(Idx)
2070                , g_rec_header_new.array_anc_id_33(Idx)
2071                , g_rec_header_new.array_anc_id_34(Idx)
2072                , g_rec_header_new.array_anc_id_35(Idx)
2073                , g_rec_header_new.array_anc_id_36(Idx)
2074                , g_rec_header_new.array_anc_id_37(Idx)
2075                , g_rec_header_new.array_anc_id_38(Idx)
2076                , g_rec_header_new.array_anc_id_39(Idx)
2077                , g_rec_header_new.array_anc_id_40(Idx)
2078                , g_rec_header_new.array_anc_id_41(Idx)
2079                , g_rec_header_new.array_anc_id_42(Idx)
2080                , g_rec_header_new.array_anc_id_43(Idx)
2081                , g_rec_header_new.array_anc_id_44(Idx)
2082                , g_rec_header_new.array_anc_id_45(Idx)
2083                , g_rec_header_new.array_anc_id_46(Idx)
2084                , g_rec_header_new.array_anc_id_47(Idx)
2085                , g_rec_header_new.array_anc_id_48(Idx)
2086                , g_rec_header_new.array_anc_id_49(Idx)
2087                , g_rec_header_new.array_anc_id_50(Idx)
2088                , g_rec_header_new.array_anc_id_51(Idx)
2089                , g_rec_header_new.array_anc_id_52(Idx)
2090                , g_rec_header_new.array_anc_id_53(Idx)
2091                , g_rec_header_new.array_anc_id_54(Idx)
2092                , g_rec_header_new.array_anc_id_55(Idx)
2093                , g_rec_header_new.array_anc_id_56(Idx)
2094                , g_rec_header_new.array_anc_id_57(Idx)
2095                , g_rec_header_new.array_anc_id_58(Idx)
2096                , g_rec_header_new.array_anc_id_59(Idx)
2097                , g_rec_header_new.array_anc_id_60(Idx)
2098                , g_rec_header_new.array_anc_id_61(Idx)
2099                , g_rec_header_new.array_anc_id_62(Idx)
2100                , g_rec_header_new.array_anc_id_63(Idx)
2101                , g_rec_header_new.array_anc_id_64(Idx)
2102                , g_rec_header_new.array_anc_id_65(Idx)
2103                , g_rec_header_new.array_anc_id_66(Idx)
2104                , g_rec_header_new.array_anc_id_67(Idx)
2105                , g_rec_header_new.array_anc_id_68(Idx)
2106                , g_rec_header_new.array_anc_id_69(Idx)
2107                , g_rec_header_new.array_anc_id_70(Idx)
2108                , g_rec_header_new.array_anc_id_71(Idx)
2109                , g_rec_header_new.array_anc_id_72(Idx)
2110                , g_rec_header_new.array_anc_id_73(Idx)
2111                , g_rec_header_new.array_anc_id_74(Idx)
2112                , g_rec_header_new.array_anc_id_75(Idx)
2113                , g_rec_header_new.array_anc_id_76(Idx)
2114                , g_rec_header_new.array_anc_id_77(Idx)
2115                , g_rec_header_new.array_anc_id_78(Idx)
2116                , g_rec_header_new.array_anc_id_79(Idx)
2117                , g_rec_header_new.array_anc_id_80(Idx)
2118                , g_rec_header_new.array_anc_id_81(Idx)
2119                , g_rec_header_new.array_anc_id_82(Idx)
2120                , g_rec_header_new.array_anc_id_83(Idx)
2121                , g_rec_header_new.array_anc_id_84(Idx)
2122                , g_rec_header_new.array_anc_id_85(Idx)
2123                , g_rec_header_new.array_anc_id_86(Idx)
2124                , g_rec_header_new.array_anc_id_87(Idx)
2125                , g_rec_header_new.array_anc_id_88(Idx)
2126                , g_rec_header_new.array_anc_id_89(Idx)
2127                , g_rec_header_new.array_anc_id_90(Idx)
2128                , g_rec_header_new.array_anc_id_91(Idx)
2129                , g_rec_header_new.array_anc_id_92(Idx)
2130                , g_rec_header_new.array_anc_id_93(Idx)
2131                , g_rec_header_new.array_anc_id_94(Idx)
2132                , g_rec_header_new.array_anc_id_95(Idx)
2133                , g_rec_header_new.array_anc_id_96(Idx)
2134                , g_rec_header_new.array_anc_id_97(Idx)
2135                , g_rec_header_new.array_anc_id_98(Idx)
2136                , g_rec_header_new.array_anc_id_99(Idx)
2137                , g_rec_header_new.array_anc_id_100(Idx)
2138                --
2139                , g_rec_header_new.array_event_number(Idx)
2140                , g_rec_header_new.array_header_num(Idx)              -- 4262811
2141                , g_rec_header_new.array_accrual_reversal_flag(Idx)   -- 4262811
2142                , g_rec_header_new.array_acc_rev_gl_date_option(Idx)  -- 4262811
2143                , g_rec_header_new.array_parent_header_id(Idx)        -- 4262811
2144                , g_rec_header_new.array_parent_line_num(Idx)         -- 4262811
2145           FROM   xla_ae_lines_gt ael
2146          WHERE   ael.ae_header_id = g_rec_header_new.array_event_id(Idx)
2147            AND   ael.ledger_id    = g_rec_header_new.array_target_ledger_id(Idx)
2148            AND   (nvl(ael.gain_or_loss_flag, 'N') <> 'Y' or nvl(ael.calculate_g_l_amts_flag, 'N') <> 'Y')
2149 --           AND   nvl(ael.entered_amount,0) > 0
2150 --           AND   ael.temp_line_num <> 0
2151            group by ael.balance_type_code
2152            );
2153 --
2154 
2155 
2156      IF (C_LEVEL_EVENT >= g_log_level) THEN
2157 
2158          trace
2159              (p_msg      => '# temporary headers inserted into GT xla_ae_headers_gt = '||SQL%ROWCOUNT
2160              ,p_level    => C_LEVEL_EVENT
2161              ,p_module   => l_log_module);
2162      END IF;
2163 --
2164   l_result:= ( (SQL%ROWCOUNT > 0) OR
2165                (XLA_AE_JOURNAL_ENTRY_PKG.g_global_status =  XLA_AE_JOURNAL_ENTRY_PKG.C_VALID)) ;
2166 
2167 --
2168 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2169 
2170       trace
2171          (p_msg      => 'END of InsertHeaders'
2172          ,p_level    => C_LEVEL_PROCEDURE
2173          ,p_module   => l_log_module);
2174 
2175 END IF;
2176 --
2177 RETURN l_result;
2178 --
2179 EXCEPTION
2180 
2181 WHEN xla_exceptions_pkg.application_exception THEN
2182    RAISE;
2183 -- added 7526530
2184 
2185 ----Added  to handle Exceptions and send to Out file ------------
2186 WHEN dml_errors THEN
2187    errors := SQL%BULK_EXCEPTIONS.COUNT;
2188    FOR i IN 1..errors LOOP
2189       ERR_IND:= SQL%BULK_EXCEPTIONS(i).ERROR_INDEX;
2190       ERR_CODE:= SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE);
2191       fnd_file.put_line(fnd_file.log, 'ERROR : '|| UPPER(ERR_CODE));
2192       fnd_file.put_line(fnd_file.log, 'event_id: '||g_rec_header_new.array_event_id(ERR_IND));
2193       fnd_file.put_line(fnd_file.log, 'header_num: '||g_rec_header_new.array_header_num(ERR_IND));
2194       fnd_file.put_line(fnd_file.log, 'ledger_id: '||g_rec_header_new.array_target_ledger_id(ERR_IND));
2195 
2196   END LOOP;
2197   xla_exceptions_pkg.raise_message
2198       (p_location => 'XLA_AE_HEADER_PKG.InsertHeaders');
2199   WHEN OTHERS  THEN
2200    xla_exceptions_pkg.raise_message
2201       (p_location => 'XLA_AE_HEADER_PKG.InsertHeaders');
2202 END InsertHeaders;
2203 --
2204 /*======================================================================+
2205 |                                                                       |
2206 | Public Procedure                                                      |
2207 |                                                                       |
2208 |                                                                       |
2209 +======================================================================*/
2210 PROCEDURE change_third_party
2211 
2212 IS
2213 l_log_module         VARCHAR2(240);
2214 BEGIN
2215 --
2216 IF g_log_enabled THEN
2217       l_log_module := C_DEFAULT_MODULE||'.change_third_party';
2218 END IF;
2219 --
2220 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2221 
2222       trace
2223          (p_msg      => 'BEGIN of change_third_party'
2224          ,p_level    => C_LEVEL_PROCEDURE
2225          ,p_module   => l_log_module);
2226 
2227 END IF;
2228 --
2229 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2230 
2231      trace
2232          (p_msg      => 'SQL - Insert into xla_ae_lines_gt  '
2233          ,p_level    => C_LEVEL_STATEMENT
2234          ,p_module   => l_log_module);
2235 END IF;
2236 --
2237  INSERT INTO xla_ae_lines_gt
2238  (
2239   ae_header_id
2240 , temp_line_num
2241 , event_id
2242 --
2243 , ref_ae_header_id
2244 , ref_ae_line_num
2245 , ref_temp_line_num
2246 --
2247 , accounting_class_code
2248 , event_class_code
2249 , event_type_code
2250 , line_definition_owner_code
2251 , line_definition_code
2252 , accounting_line_type_code
2253 , accounting_line_code
2254 --
2255 , code_combination_status_code
2256 , code_combination_id
2257 , sl_coa_mapping_name
2258 , dynamic_insert_flag
2259 , source_coa_id
2260 , ccid_coa_id
2261 --
2262 , description
2263 , gl_transfer_mode_code
2264 , merge_duplicate_code
2265 , switch_side_flag
2266 --
2267 --, entered_amount
2268 --, ledger_amount
2269 , unrounded_entered_cr
2270 , unrounded_entered_dr
2271 , unrounded_accounted_cr
2272 , unrounded_accounted_dr
2273 , entered_cr
2274 , entered_dr
2275 , accounted_cr
2276 , accounted_dr
2277 , currency_code
2278 , currency_conversion_date
2279 , currency_conversion_rate
2280 , currency_conversion_type
2281 , statistical_amount
2282 --
2283 , party_id
2284 , party_site_id
2285 , party_type_code
2286 --
2287 , ussgl_transaction_code
2288 , jgzz_recon_ref
2289 --
2290 , source_distribution_id_char_1
2291 , source_distribution_id_char_2
2292 , source_distribution_id_char_3
2293 , source_distribution_id_char_4
2294 , source_distribution_id_char_5
2295 , source_distribution_id_num_1
2296 , source_distribution_id_num_2
2297 , source_distribution_id_num_3
2298 , source_distribution_id_num_4
2299 , source_distribution_id_num_5
2300 , source_distribution_type
2301 --
2302 , tax_line_ref_id
2303 , tax_summary_line_ref_id
2304 , tax_rec_nrec_dist_ref_id
2305 , anc_id_1
2306 , anc_id_2
2307 , anc_id_3
2308 , anc_id_4
2309 , anc_id_5
2310 , anc_id_6
2311 , anc_id_7
2312 , anc_id_8
2313 , anc_id_9
2314 , anc_id_10
2315 , anc_id_11
2316 , anc_id_12
2317 , anc_id_13
2318 , anc_id_14
2319 , anc_id_15
2320 , anc_id_16
2321 , anc_id_17
2322 , anc_id_18
2323 , anc_id_19
2324 , anc_id_20
2325 , anc_id_21
2326 , anc_id_22
2327 , anc_id_23
2328 , anc_id_24
2329 , anc_id_25
2330 , anc_id_26
2331 , anc_id_27
2332 , anc_id_28
2333 , anc_id_29
2334 , anc_id_30
2335 , anc_id_31
2336 , anc_id_32
2337 , anc_id_33
2338 , anc_id_34
2339 , anc_id_35
2340 , anc_id_36
2341 , anc_id_37
2342 , anc_id_38
2343 , anc_id_39
2344 , anc_id_40
2345 , anc_id_41
2346 , anc_id_42
2347 , anc_id_43
2348 , anc_id_44
2349 , anc_id_45
2350 , anc_id_46
2351 , anc_id_47
2352 , anc_id_48
2353 , anc_id_49
2354 , anc_id_50
2355 , anc_id_51
2356 , anc_id_52
2357 , anc_id_53
2358 , anc_id_54
2359 , anc_id_55
2360 , anc_id_56
2361 , anc_id_57
2362 , anc_id_58
2363 , anc_id_59
2364 , anc_id_60
2365 , anc_id_61
2366 , anc_id_62
2367 , anc_id_63
2368 , anc_id_64
2369 , anc_id_65
2370 , anc_id_66
2371 , anc_id_67
2372 , anc_id_68
2373 , anc_id_69
2374 , anc_id_70
2375 , anc_id_71
2376 , anc_id_72
2377 , anc_id_73
2378 , anc_id_74
2379 , anc_id_75
2380 , anc_id_76
2381 , anc_id_77
2382 , anc_id_78
2383 , anc_id_79
2384 , anc_id_80
2385 , anc_id_81
2386 , anc_id_82
2387 , anc_id_83
2388 , anc_id_84
2389 , anc_id_85
2390 , anc_id_86
2391 , anc_id_87
2392 , anc_id_88
2393 , anc_id_89
2394 , anc_id_90
2395 , anc_id_91
2396 , anc_id_92
2397 , anc_id_93
2398 , anc_id_94
2399 , anc_id_95
2400 , anc_id_96
2401 , anc_id_97
2402 , anc_id_98
2403 , anc_id_99
2404 , anc_id_100
2405 , inherit_desc_flag        -- 4219869
2406 , mpa_accrual_entry_flag   -- 4262811
2407 , encumbrance_type_id      -- 4458381  Public Sector Enh
2408 , header_num               -- 5100860  assign value to avoid using function index
2409 )
2410 
2411 SELECT
2412         CASE xah.balance_type_code
2413           WHEN C_ACTUAL      THEN g_rec_header_new.array_actual_header_id(g_header_idx)
2414           WHEN C_BUDGET      THEN g_rec_header_new.array_budget_header_id(g_header_idx)
2415           WHEN C_ENCUMBRANCE THEN g_rec_header_new.array_encumb_header_id(g_header_idx)
2416         END
2417      ,  XLA_AE_LINES_PKG.SetLineNum(xah.balance_type_code)
2418      ,  XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
2419     --
2420      ,  xal.ae_header_id
2421      ,  xal.ae_line_num
2422      ,  xdl.temp_line_num
2423     --
2424      ,  xal.accounting_class_code
2425      ,  xdl.event_class_code
2426      ,  xdl.event_type_code
2427      ,  xdl.line_definition_owner_code
2428      ,  xdl.line_definition_code
2429      ,  xdl.accounting_line_type_code
2430      ,  xdl.accounting_line_code
2431     --
2432      , C_CCID
2433      , xal.code_combination_id
2434      , NULL
2435      , NULL
2436      , NULL
2437      , NULL
2438      , xal.description
2439      , xal.gl_transfer_mode_code
2440      , xdl.merge_duplicate_code
2441      , DECODE(XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option,
2442                   'SIDE', C_SWITCH,
2443                    C_NO_SWITCH
2444               )
2445 /*     , xdl.entered_amount
2446      , xdl.ledger_amount */
2447      --
2448      , xal.unrounded_entered_dr
2449      , xal.unrounded_entered_cr
2450      , xal.unrounded_accounted_dr
2451      , xal.unrounded_accounted_cr
2452      , xal.entered_dr
2453      , xal.entered_cr
2454      , xal.accounted_dr
2455      , xal.accounted_cr
2456      --
2457      , xal.currency_code
2458      , xal.currency_conversion_date
2459      , xal.currency_conversion_rate
2460      , xal.currency_conversion_type
2461      , xal.statistical_amount
2462      --
2463      , xal.party_id
2464      , xal.party_site_id
2465      , xal.party_type_code
2466      --
2467      , xal.ussgl_transaction_code
2468      , xal.jgzz_recon_ref
2469       --
2470      , xdl.source_distribution_id_char_1
2471      , xdl.source_distribution_id_char_2
2472      , xdl.source_distribution_id_char_3
2473      , xdl.source_distribution_id_char_4
2474      , xdl.source_distribution_id_char_5
2475      , xdl.source_distribution_id_num_1
2476      , xdl.source_distribution_id_num_2
2477      , xdl.source_distribution_id_num_3
2478      , xdl.source_distribution_id_num_4
2479      , xdl.source_distribution_id_num_5
2480      , xdl.source_distribution_type
2481      --
2482      , xdl.tax_line_ref_id
2483      , xdl.tax_summary_line_ref_id
2484      , xdl.tax_rec_nrec_dist_ref_id
2485      , anc_id_1
2486      , anc_id_2
2487      , anc_id_3
2488      , anc_id_4
2489      , anc_id_5
2490      , anc_id_6
2491      , anc_id_7
2492      , anc_id_8
2493      , anc_id_9
2494      , anc_id_10
2495      , anc_id_11
2496      , anc_id_12
2497      , anc_id_13
2498      , anc_id_14
2499      , anc_id_15
2500      , anc_id_16
2501      , anc_id_17
2502      , anc_id_18
2503      , anc_id_19
2504      , anc_id_20
2505      , anc_id_21
2506      , anc_id_22
2507      , anc_id_23
2508      , anc_id_24
2509      , anc_id_25
2510      , anc_id_26
2511      , anc_id_27
2512      , anc_id_28
2513      , anc_id_29
2514      , anc_id_30
2515      , anc_id_31
2516      , anc_id_32
2517      , anc_id_33
2518      , anc_id_34
2519      , anc_id_35
2520      , anc_id_36
2521      , anc_id_37
2522      , anc_id_38
2523      , anc_id_39
2524      , anc_id_40
2525      , anc_id_41
2526      , anc_id_42
2527      , anc_id_43
2528      , anc_id_44
2529      , anc_id_45
2530      , anc_id_46
2531      , anc_id_47
2532      , anc_id_48
2533      , anc_id_49
2534      , anc_id_50
2535      , anc_id_51
2536      , anc_id_52
2537      , anc_id_53
2538      , anc_id_54
2539      , anc_id_55
2540      , anc_id_56
2541      , anc_id_57
2542      , anc_id_58
2543      , anc_id_59
2544      , anc_id_60
2545      , anc_id_61
2546      , anc_id_62
2547      , anc_id_63
2548      , anc_id_64
2549      , anc_id_65
2550      , anc_id_66
2551      , anc_id_67
2552      , anc_id_68
2553      , anc_id_69
2554      , anc_id_70
2555      , anc_id_71
2556      , anc_id_72
2557      , anc_id_73
2558      , anc_id_74
2559      , anc_id_75
2560      , anc_id_76
2561      , anc_id_77
2562      , anc_id_78
2563      , anc_id_79
2564      , anc_id_80
2565      , anc_id_81
2566      , anc_id_82
2567      , anc_id_83
2568      , anc_id_84
2569      , anc_id_85
2570      , anc_id_86
2571      , anc_id_87
2572      , anc_id_88
2573      , anc_id_89
2574      , anc_id_90
2575      , anc_id_91
2576      , anc_id_92
2577      , anc_id_93
2578      , anc_id_94
2579      , anc_id_95
2580      , anc_id_96
2581      , anc_id_97
2582      , anc_id_98
2583      , anc_id_99
2584      , anc_id_100
2585      , 'N'   -- 4219869  inherit_desc_flag
2586      , 'N'   -- 4262811  mpa_accrual_entry_flag
2587      , xal.encumbrance_type_id -- 4458381  Public Sector Enh
2588      , 0                       -- 5100860  assign value to avoid using function index
2589      --
2590 FROM  xla_ae_lines            xal,
2591       xla_ae_headers          xah,
2592       xla_distribution_links  xdl,
2593       xla_events              xe,
2594      (SELECT ae_header_id
2595             ,ae_line_num
2596             ,MAX(DECODE(rank,1,anc_id)) anc_id_1
2597             ,MAX(DECODE(rank,2,anc_id)) anc_id_2
2598             ,MAX(DECODE(rank,3,anc_id)) anc_id_3
2599             ,MAX(DECODE(rank,4,anc_id)) anc_id_4
2600             ,MAX(DECODE(rank,5,anc_id)) anc_id_5
2601             ,MAX(DECODE(rank,6,anc_id)) anc_id_6
2602             ,MAX(DECODE(rank,7,anc_id)) anc_id_7
2603             ,MAX(DECODE(rank,8,anc_id)) anc_id_8
2604             ,MAX(DECODE(rank,9,anc_id)) anc_id_9
2605             ,MAX(DECODE(rank,10,anc_id)) anc_id_10
2606             ,MAX(DECODE(rank,11,anc_id)) anc_id_11
2607             ,MAX(DECODE(rank,12,anc_id)) anc_id_12
2608             ,MAX(DECODE(rank,13,anc_id)) anc_id_13
2609             ,MAX(DECODE(rank,14,anc_id)) anc_id_14
2610             ,MAX(DECODE(rank,15,anc_id)) anc_id_15
2611             ,MAX(DECODE(rank,16,anc_id)) anc_id_16
2612             ,MAX(DECODE(rank,17,anc_id)) anc_id_17
2613             ,MAX(DECODE(rank,18,anc_id)) anc_id_18
2614             ,MAX(DECODE(rank,19,anc_id)) anc_id_19
2615             ,MAX(DECODE(rank,20,anc_id)) anc_id_20
2616             ,MAX(DECODE(rank,21,anc_id)) anc_id_21
2617             ,MAX(DECODE(rank,22,anc_id)) anc_id_22
2618             ,MAX(DECODE(rank,23,anc_id)) anc_id_23
2619             ,MAX(DECODE(rank,24,anc_id)) anc_id_24
2620             ,MAX(DECODE(rank,25,anc_id)) anc_id_25
2621             ,MAX(DECODE(rank,26,anc_id)) anc_id_26
2622             ,MAX(DECODE(rank,27,anc_id)) anc_id_27
2623             ,MAX(DECODE(rank,28,anc_id)) anc_id_28
2624             ,MAX(DECODE(rank,29,anc_id)) anc_id_29
2625             ,MAX(DECODE(rank,30,anc_id)) anc_id_30
2626             ,MAX(DECODE(rank,31,anc_id)) anc_id_31
2627             ,MAX(DECODE(rank,32,anc_id)) anc_id_32
2628             ,MAX(DECODE(rank,33,anc_id)) anc_id_33
2629             ,MAX(DECODE(rank,34,anc_id)) anc_id_34
2630             ,MAX(DECODE(rank,35,anc_id)) anc_id_35
2631             ,MAX(DECODE(rank,36,anc_id)) anc_id_36
2632             ,MAX(DECODE(rank,37,anc_id)) anc_id_37
2633             ,MAX(DECODE(rank,38,anc_id)) anc_id_38
2634             ,MAX(DECODE(rank,39,anc_id)) anc_id_39
2635             ,MAX(DECODE(rank,40,anc_id)) anc_id_40
2636             ,MAX(DECODE(rank,41,anc_id)) anc_id_41
2637             ,MAX(DECODE(rank,42,anc_id)) anc_id_42
2638             ,MAX(DECODE(rank,43,anc_id)) anc_id_43
2639             ,MAX(DECODE(rank,44,anc_id)) anc_id_44
2640             ,MAX(DECODE(rank,45,anc_id)) anc_id_45
2641             ,MAX(DECODE(rank,46,anc_id)) anc_id_46
2642             ,MAX(DECODE(rank,47,anc_id)) anc_id_47
2643             ,MAX(DECODE(rank,48,anc_id)) anc_id_48
2644             ,MAX(DECODE(rank,49,anc_id)) anc_id_49
2645             ,MAX(DECODE(rank,50,anc_id)) anc_id_50
2646             ,MAX(DECODE(rank,51,anc_id)) anc_id_51
2647             ,MAX(DECODE(rank,52,anc_id)) anc_id_52
2648             ,MAX(DECODE(rank,53,anc_id)) anc_id_53
2649             ,MAX(DECODE(rank,54,anc_id)) anc_id_54
2650             ,MAX(DECODE(rank,55,anc_id)) anc_id_55
2651             ,MAX(DECODE(rank,56,anc_id)) anc_id_56
2652             ,MAX(DECODE(rank,57,anc_id)) anc_id_57
2653             ,MAX(DECODE(rank,58,anc_id)) anc_id_58
2654             ,MAX(DECODE(rank,59,anc_id)) anc_id_59
2655             ,MAX(DECODE(rank,60,anc_id)) anc_id_60
2656             ,MAX(DECODE(rank,61,anc_id)) anc_id_61
2657             ,MAX(DECODE(rank,62,anc_id)) anc_id_62
2658             ,MAX(DECODE(rank,63,anc_id)) anc_id_63
2659             ,MAX(DECODE(rank,64,anc_id)) anc_id_64
2660             ,MAX(DECODE(rank,65,anc_id)) anc_id_65
2661             ,MAX(DECODE(rank,66,anc_id)) anc_id_66
2662             ,MAX(DECODE(rank,67,anc_id)) anc_id_67
2663             ,MAX(DECODE(rank,68,anc_id)) anc_id_68
2664             ,MAX(DECODE(rank,69,anc_id)) anc_id_69
2665             ,MAX(DECODE(rank,70,anc_id)) anc_id_70
2666             ,MAX(DECODE(rank,71,anc_id)) anc_id_71
2667             ,MAX(DECODE(rank,72,anc_id)) anc_id_72
2668             ,MAX(DECODE(rank,73,anc_id)) anc_id_73
2669             ,MAX(DECODE(rank,74,anc_id)) anc_id_74
2670             ,MAX(DECODE(rank,75,anc_id)) anc_id_75
2671             ,MAX(DECODE(rank,76,anc_id)) anc_id_76
2672             ,MAX(DECODE(rank,77,anc_id)) anc_id_77
2673             ,MAX(DECODE(rank,78,anc_id)) anc_id_78
2674             ,MAX(DECODE(rank,79,anc_id)) anc_id_79
2675             ,MAX(DECODE(rank,80,anc_id)) anc_id_80
2676             ,MAX(DECODE(rank,81,anc_id)) anc_id_81
2677             ,MAX(DECODE(rank,82,anc_id)) anc_id_82
2678             ,MAX(DECODE(rank,83,anc_id)) anc_id_83
2679             ,MAX(DECODE(rank,84,anc_id)) anc_id_84
2680             ,MAX(DECODE(rank,85,anc_id)) anc_id_85
2681             ,MAX(DECODE(rank,86,anc_id)) anc_id_86
2682             ,MAX(DECODE(rank,87,anc_id)) anc_id_87
2683             ,MAX(DECODE(rank,88,anc_id)) anc_id_88
2684             ,MAX(DECODE(rank,89,anc_id)) anc_id_89
2685             ,MAX(DECODE(rank,90,anc_id)) anc_id_90
2686             ,MAX(DECODE(rank,91,anc_id)) anc_id_91
2687             ,MAX(DECODE(rank,92,anc_id)) anc_id_92
2688             ,MAX(DECODE(rank,93,anc_id)) anc_id_93
2689             ,MAX(DECODE(rank,94,anc_id)) anc_id_94
2690             ,MAX(DECODE(rank,95,anc_id)) anc_id_95
2691             ,MAX(DECODE(rank,96,anc_id)) anc_id_96
2692             ,MAX(DECODE(rank,97,anc_id)) anc_id_97
2693             ,MAX(DECODE(rank,98,anc_id)) anc_id_98
2694             ,MAX(DECODE(rank,99,anc_id)) anc_id_99
2695             ,MAX(DECODE(rank,100,anc_id)) anc_id_100
2696      FROM
2697      (SELECT  xald.ae_header_id
2698             , xald.ae_line_num
2699             , xald.analytical_criterion_code      || '(]' ||
2700               xald.analytical_criterion_type_code || '(]' ||
2701               xald.amb_context_code               || '(]' ||
2702               xald.ac1                            || '(]' ||
2703               xald.ac2                            || '(]' ||
2704               xald.ac3                            || '(]' ||
2705               xald.ac4                            || '(]' ||
2706               xald.ac5                            anc_id
2707             , RANK() OVER (
2708               PARTITION BY ae_header_id, ae_line_num
2709                   ORDER BY analytical_criterion_code
2710                           ,analytical_criterion_type_code
2711                           ,amb_context_code
2712                           ,ac1
2713                           ,ac2
2714                           ,ac3
2715                           ,ac4
2716                           ,ac5) rank
2717        FROM  xla_ae_line_acs xald)
2718       GROUP  BY ae_header_id, ae_line_num) anc
2719 
2720 WHERE xe.event_id                         = xdl.event_id
2721   AND xe.event_id                         = xah.event_id
2722   AND xal.ae_header_id                    = xdl.ae_header_id
2723   AND xal.ae_header_id                    = xah.ae_header_id
2724   AND xal.ae_line_num                     = xdl.ae_line_num
2725   AND xe.entity_id                        = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
2726   AND anc.ae_header_id                    = xdl.ae_header_id
2727   AND anc.ae_line_num                     = xdl.ae_line_num
2728   AND xah.ledger_id                       = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
2729   AND (g_rec_header_new.array_previous_party_id(g_header_idx) IS NULL
2730       OR
2731       xal.party_id                        = g_rec_header_new.array_previous_party_id(g_header_idx))
2732   AND (g_rec_header_new.array_previous_party_site_id(g_header_idx) IS NULL
2733       OR
2734       xal.party_site_id                   = g_rec_header_new.array_previous_party_site_id(g_header_idx))
2735   AND (g_rec_header_new.array_party_change_type(g_header_idx) IS NULL
2736       OR
2737       xal.party_type_code                 = g_rec_header_new.array_party_change_type(g_header_idx))
2738 ;
2739 
2740 IF (C_LEVEL_EVENT >= g_log_level) THEN
2741 
2742      trace
2743          (p_msg      => '# temporary journal lines inserted into GT xla_ae_lines_gt = '||SQL%ROWCOUNT
2744          ,p_level    => C_LEVEL_EVENT
2745          ,p_module   => l_log_module);
2746 
2747 END IF;
2748 
2749 
2750 IF SQL%ROWCOUNT > 0 THEN
2751 --
2752 --
2753 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2754 
2755      trace
2756          (p_msg      => 'SQL - Insert into xla_ae_lines_gt  '
2757          ,p_level    => C_LEVEL_STATEMENT
2758          ,p_module   => l_log_module);
2759 END IF;
2760 --
2761 --
2762  INSERT INTO xla_ae_lines_gt
2763  (
2764   ae_header_id
2765 , temp_line_num
2766 , event_id
2767 --
2768 , ref_ae_header_id
2769 , ref_ae_line_num
2770 , ref_temp_line_num
2771 --
2772 , accounting_class_code
2773 , event_class_code
2774 , event_type_code
2775 , line_definition_owner_code
2776 , line_definition_code
2777 , accounting_line_type_code
2778 , accounting_line_code
2779 --
2780 , code_combination_status_code
2781 , code_combination_id
2782 , sl_coa_mapping_name
2783 , dynamic_insert_flag
2784 , source_coa_id
2785 , ccid_coa_id
2786 --
2787 , description
2788 , gl_transfer_mode_code
2789 , merge_duplicate_code
2790 , switch_side_flag
2791 --
2792 --, entered_amount
2793 --, ledger_amount
2794 , unrounded_entered_dr
2795 , unrounded_entered_cr
2796 , unrounded_accounted_dr
2797 , unrounded_accounted_cr
2798 , entered_dr
2799 , entered_cr
2800 , accounted_dr
2801 , accounted_cr
2802 , currency_code
2803 , currency_conversion_date
2804 , currency_conversion_rate
2805 , currency_conversion_type
2806 , statistical_amount
2807 --
2808 , party_id
2809 , party_site_id
2810 , party_type_code
2811 --
2812 , ussgl_transaction_code
2813 , jgzz_recon_ref
2814 --
2815 , source_distribution_id_char_1
2816 , source_distribution_id_char_2
2817 , source_distribution_id_char_3
2818 , source_distribution_id_char_4
2819 , source_distribution_id_char_5
2820 , source_distribution_id_num_1
2821 , source_distribution_id_num_2
2822 , source_distribution_id_num_3
2823 , source_distribution_id_num_4
2824 , source_distribution_id_num_5
2825 , source_distribution_type
2826 --
2827 , tax_line_ref_id
2828 , tax_summary_line_ref_id
2829 , tax_rec_nrec_dist_ref_id
2830 , inherit_desc_flag        -- 4219869
2831 , mpa_accrual_entry_flag   -- 4262811
2832 , encumbrance_type_id      -- 4458381  Public Sector Enh
2833 , header_num               -- 5100860  assign value to avoid using function index
2834 )
2835 
2836 SELECT
2837         CASE xah.balance_type_code
2838           WHEN C_ACTUAL      THEN g_rec_header_new.array_actual_header_id(g_header_idx)
2839           WHEN C_BUDGET      THEN g_rec_header_new.array_budget_header_id(g_header_idx)
2840           WHEN C_ENCUMBRANCE THEN g_rec_header_new.array_encumb_header_id(g_header_idx)
2841         END
2842      ,  XLA_AE_LINES_PKG.SetLineNum(xah.balance_type_code)
2843      ,  XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
2844     --
2845      ,  xal.ae_header_id
2846      ,  xal.ae_line_num
2847      ,  xdl.temp_line_num
2848     --
2849      ,  xal.accounting_class_code
2850      ,  xdl.event_class_code
2851      ,  xdl.event_type_code
2852      ,  xdl.line_definition_owner_code
2853      ,  xdl.line_definition_code
2854      ,  xdl.accounting_line_type_code
2855      ,  xdl.accounting_line_code
2856     --
2857      , C_CCID
2858      , xal.code_combination_id
2859      , NULL
2860      , NULL
2861      , NULL
2862      , NULL
2863      , xal.description
2864      , xal.gl_transfer_mode_code
2865      , xdl.merge_duplicate_code
2866      , DECODE(XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option,
2867                   'SIDE', C_SWITCH,
2868                    C_NO_SWITCH
2869               )
2870 --     , xdl.entered_amount
2871 --     , xdl.ledger_amount
2872      --
2873      , xal.unrounded_entered_dr
2874      , xal.unrounded_entered_cr
2875      , xal.unrounded_accounted_dr
2876      , xal.unrounded_accounted_cr
2877      , xal.entered_dr
2878      , xal.entered_cr
2879      , xal.accounted_dr
2880      , xal.accounted_cr
2881      --
2882      , xal.currency_code
2883      , xal.currency_conversion_date
2884      , xal.currency_conversion_rate
2885      , xal.currency_conversion_type
2886      , xal.statistical_amount
2887      --
2888      , g_rec_header_new.array_new_party_id(g_header_idx)
2889      , g_rec_header_new.array_new_party_site_id(g_header_idx)
2890      , g_rec_header_new.array_party_change_type(g_header_idx)
2891      --
2892      , xal.ussgl_transaction_code
2893      , xal.jgzz_recon_ref
2894       --
2895      , xdl.source_distribution_id_char_1
2896      , xdl.source_distribution_id_char_2
2897      , xdl.source_distribution_id_char_3
2898      , xdl.source_distribution_id_char_4
2899      , xdl.source_distribution_id_char_5
2900      , xdl.source_distribution_id_num_1
2901      , xdl.source_distribution_id_num_2
2902      , xdl.source_distribution_id_num_3
2903      , xdl.source_distribution_id_num_4
2904      , xdl.source_distribution_id_num_5
2905      , xdl.source_distribution_type
2906      --
2907      , xdl.tax_line_ref_id
2908      , xdl.tax_summary_line_ref_id
2909      , xdl.tax_rec_nrec_dist_ref_id
2910      , 'N'   -- 4219869 inherit_desc_flag
2911      , 'N'   -- 4262811 mpa_accrual_entry_flag
2912      , xal.encumbrance_type_id -- 4458381  Public Sector Enh
2913      , 0                       -- 5100860  assign value to avoid using function index
2914      --
2915 FROM  xla_ae_lines            xal,
2916       xla_ae_headers          xah,
2917       xla_distribution_links  xdl,
2918       xla_events              xe
2919 WHERE xe.event_id                         = xdl.event_id
2920   AND xe.event_id                         = xah.event_id
2921   AND xal.ae_header_id                    = xdl.ae_header_id
2922   AND xal.ae_header_id                    = xah.ae_header_id
2923   AND xal.ae_line_num                     = xdl.ae_line_num
2924   AND xe.entity_id                        = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
2925   AND xah.ledger_id                       = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
2926   AND ( g_rec_header_new.array_previous_party_id(g_header_idx) IS NULL
2927       OR
2928       xal.party_id                        = g_rec_header_new.array_previous_party_id(g_header_idx))
2929   AND ( g_rec_header_new.array_previous_party_site_id(g_header_idx) IS NULL
2930       OR
2931       xal.party_site_id                   = g_rec_header_new.array_previous_party_site_id(g_header_idx))
2932   AND ( g_rec_header_new.array_party_change_type(g_header_idx) IS NULL
2933       OR
2934       xal.party_type_code                 = g_rec_header_new.array_party_change_type(g_header_idx))
2935 ;
2936 --
2937 --
2938    IF (C_LEVEL_EVENT >= g_log_level) THEN
2939 
2940      trace
2941          (p_msg      => '# temporary journal lines inserted into GT xla_ae_lines_gt = '||SQL%ROWCOUNT
2942          ,p_level    => C_LEVEL_EVENT
2943          ,p_module   => l_log_module);
2944    END IF;
2945 
2946 END IF;
2947 --
2948 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2949 
2950       trace
2951          (p_msg      => 'END of change_third_party'
2952          ,p_level    => C_LEVEL_PROCEDURE
2953          ,p_module   => l_log_module);
2954 
2955 END IF;
2956 EXCEPTION
2957 WHEN xla_exceptions_pkg.application_exception THEN
2958    RAISE;
2959 WHEN OTHERS  THEN
2960    xla_exceptions_pkg.raise_message
2961            (p_location => 'XLA_AE_HEADER_PKG.change_third_party');
2962   --
2963 END change_third_party;
2964 --
2965 --
2966 /*======================================================================+
2967 |                                                                       |
2968 | Public Procedure                                                      |
2969 |                                                                       |
2970 |                                                                       |
2971 +======================================================================*/
2972 PROCEDURE RefreshHeader
2973 IS
2974 l_null_rec_header_new        t_rec_header_new;
2975 l_null_rec_period_name       t_rec_period_name;
2976 l_log_module                 VARCHAR2(240);
2977 BEGIN
2978 --
2979 IF g_log_enabled THEN
2980       l_log_module := C_DEFAULT_MODULE||'.RefreshHeader';
2981 END IF;
2982 --
2983 
2984 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2985 
2986       trace
2987          (p_msg      => 'BEGIN of RefreshHeader'
2988          ,p_level    => C_LEVEL_PROCEDURE
2989          ,p_module   => l_log_module);
2990 
2991 END IF;
2992 --
2993   g_rec_header_new                               := l_null_rec_header_new  ;
2994   g_cache_period_name                         := l_null_rec_period_name;
2995   XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := NULL;
2996 --
2997 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2998 
2999       trace
3000          (p_msg      => 'END of RefreshHeader'
3001          ,p_level    => C_LEVEL_PROCEDURE
3002          ,p_module   => l_log_module);
3003 
3004 END IF;
3005 --
3006 EXCEPTION
3007   WHEN xla_exceptions_pkg.application_exception THEN
3008       RAISE;
3009   WHEN OTHERS  THEN
3010        xla_exceptions_pkg.raise_message
3011                (p_location => 'XLA_AE_HEADER_PKG.RefreshHeader');
3012        --
3013 END RefreshHeader;
3014 --
3015 /*======================================================================+
3016 |                                                                       |
3017 |                                                                       |
3018 |                                                                       |
3019 +======================================================================*/
3020 procedure SetHdrAcctAttrs
3021        (p_rec_acct_attrs    in t_rec_acct_attrs) is
3022 l_log_module                 VARCHAR2(240);
3023 BEGIN
3024 --
3025 IF g_log_enabled THEN
3026       l_log_module := C_DEFAULT_MODULE||'.SetHdrAcctAttrs';
3027 END IF;
3028 
3029    FOR i in 1..p_rec_acct_attrs.array_acct_attr_code.count loop
3030 
3031       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3032          IF p_rec_acct_attrs.array_char_value.EXISTS(i) THEN
3033             trace(p_msg      => 'Loop count = '||i||
3034                                 ' (char) : '||p_rec_acct_attrs.array_acct_attr_code(i)||
3035                                 ' = '||p_rec_acct_attrs.array_char_value(i)
3036                  ,p_level    => C_LEVEL_STATEMENT
3037                  ,p_module   => l_log_module);
3038          ELSIF p_rec_acct_attrs.array_date_value.EXISTS(i) THEN
3039             trace(p_msg      => 'Loop count = '||i||
3040                                 ' (date) : '||p_rec_acct_attrs.array_acct_attr_code(i)||
3041                                 ' = '||p_rec_acct_attrs.array_date_value(i)
3042                  ,p_level    => C_LEVEL_STATEMENT
3043                  ,p_module   => l_log_module);
3044          ELSE
3045             trace(p_msg      => 'Loop count = '||i||
3046                                 ' (num) : '||p_rec_acct_attrs.array_acct_attr_code(i)||
3047                                 ' = '||p_rec_acct_attrs.array_num_value(i)
3048                  ,p_level    => C_LEVEL_STATEMENT
3049                  ,p_module   => l_log_module);
3050          END IF;
3051 
3052       END IF;
3053 
3054       CASE p_rec_acct_attrs.array_acct_attr_code(i)
3055          WHEN 'DOC_CATEGORY_CODE'     THEN
3056             IF p_rec_acct_attrs.array_char_value.EXISTS(i) THEN
3057               g_rec_header_new.array_doc_category_code(g_header_idx)     := p_rec_acct_attrs.array_char_value(i);
3058             ELSE
3059               g_rec_header_new.array_doc_category_code(g_header_idx)     := p_rec_acct_attrs.array_num_value(i);
3060             END IF;
3061 
3062          WHEN 'PARTY_CHANGE_OPTION' THEN
3063             -- 5161760
3064             IF p_rec_acct_attrs.array_char_value.EXISTS(i) THEN
3065                IF length(p_rec_acct_attrs.array_char_value(i)) > 1 THEN
3066                   g_rec_header_new.array_party_change_option(g_header_idx)     := 'X';
3067                ELSE
3068                   g_rec_header_new.array_party_change_option(g_header_idx)     := p_rec_acct_attrs.array_char_value(i);
3069                END IF;
3070             ELSE
3071               g_rec_header_new.array_party_change_option(g_header_idx)     := p_rec_acct_attrs.array_num_value(i);
3072             END IF;
3073 
3074             IF NVL(g_rec_header_new.array_party_change_option(g_header_idx),'N') NOT IN ('Y','N') THEN
3075                XLA_AE_JOURNAL_ENTRY_PKG.g_global_status      :=  XLA_AE_JOURNAL_ENTRY_PKG.C_INVALID;
3076                xla_accounting_err_pkg.build_message
3077                   (p_appli_s_name            => 'XLA'
3078                   ,p_msg_name                => 'XLA_AP_THIRD_PARTY_OPTION'
3079                   ,p_token_1                 => 'PRODUCT_NAME'
3080                   ,p_value_1                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
3081                   ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
3082                   ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
3083                   ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id);
3084              END IF;
3085 
3086          WHEN 'GL_TRANSFER_FLAG'          THEN
3087             -- 5161760
3088             IF p_rec_acct_attrs.array_char_value.EXISTS(i) THEN
3089                IF length(p_rec_acct_attrs.array_char_value(i)) > 1 THEN
3090                   g_rec_header_new.array_gl_transfer_flag(g_header_idx) := 'X';
3091                ELSE
3092                   g_rec_header_new.array_gl_transfer_flag(g_header_idx) := nvl(p_rec_acct_attrs.array_char_value(i), 'Y');
3093                END IF;
3094             ELSE
3095               g_rec_header_new.array_gl_transfer_flag(g_header_idx) := nvl(p_rec_acct_attrs.array_num_value(i), 'Y');
3096             END IF;
3097 
3098             IF NVL(g_rec_header_new.array_gl_transfer_flag(g_header_idx),'Y') NOT IN ('Y', 'N') THEN
3099                XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_INVALID;
3100                xla_accounting_err_pkg.build_message
3101                   (p_appli_s_name            => 'XLA'
3102                   ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
3103                   ,p_token_1                 => 'ACCT_ATTR_NAME'
3104                   ,p_value_1                 => XLA_AE_SOURCES_PKG.GetAccountingSourceName('GL_TRANSFER_FLAG')
3105                   ,p_token_2                 => 'PRODUCT_NAME'
3106                   ,p_value_2                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
3107                   ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
3108                   ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
3109                   ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id);
3110             END IF;
3111 
3112          WHEN 'TRX_ACCT_REVERSAL_OPTION'          THEN
3113             -- 5161760
3114             IF p_rec_acct_attrs.array_char_value.EXISTS(i) THEN
3115                IF length(p_rec_acct_attrs.array_char_value(i)) > 1 THEN
3116                   g_rec_header_new.array_trx_acct_reversal_option(g_header_idx) := 'X';
3117                ELSE
3118                   g_rec_header_new.array_trx_acct_reversal_option(g_header_idx) := nvl(p_rec_acct_attrs.array_char_value(i), 'N');
3119                END IF;
3120             ELSE
3121                g_rec_header_new.array_trx_acct_reversal_option(g_header_idx) := nvl(p_rec_acct_attrs.array_num_value(i), 'N');
3122             END IF;
3123 
3124             IF NVL(g_rec_header_new.array_trx_acct_reversal_option(g_header_idx),'N') NOT IN ('Y', 'N') THEN
3125                XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_INVALID;
3126                xla_accounting_err_pkg.build_message
3127                   (p_appli_s_name            => 'XLA'
3128                   ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
3129                   ,p_token_1                 => 'ACCT_ATTR_NAME'
3130                   ,p_value_1                 => XLA_AE_SOURCES_PKG.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
3131                   ,p_token_2                 => 'PRODUCT_NAME'
3132                   ,p_value_2                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
3133                   ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
3134                   ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
3135                   ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id);
3136             END IF;
3137 
3138          WHEN 'PARTY_CHANGE_TYPE'         THEN
3139             IF p_rec_acct_attrs.array_char_value.EXISTS(i) THEN
3140               g_rec_header_new.array_party_change_type(g_header_idx)          := p_rec_acct_attrs.array_char_value(i);
3141             ELSE
3142               g_rec_header_new.array_party_change_type(g_header_idx)          := p_rec_acct_attrs.array_num_value(i);
3143             END IF;
3144 
3145          WHEN 'DOC_SEQUENCE_ID'           THEN
3146             g_rec_header_new.array_doc_sequence_id(g_header_idx)         := p_rec_acct_attrs.array_num_value(i);
3147 
3148          WHEN 'DOC_SEQUENCE_VALUE'        THEN
3149             g_rec_header_new.array_doc_sequence_value(g_header_idx)      := p_rec_acct_attrs.array_num_value(i);
3150 
3151 /*  -- 4458381 Public Sector Enh
3152          WHEN 'ENCUMBRANCE_TYPE_ID'       THEN
3153             g_rec_header_new.array_encumbrance_type_id(g_header_idx)     := p_rec_acct_attrs.array_num_value(i);
3154 */
3155 
3156          WHEN 'BUDGET_VERSION_ID'         THEN
3157             g_rec_header_new.array_budget_version_id(g_header_idx)       := p_rec_acct_attrs.array_num_value(i);
3158 
3159          WHEN 'NEW_PARTY_ID'              THEN
3160             g_rec_header_new.array_new_party_id(g_header_idx)            := p_rec_acct_attrs.array_num_value(i);
3161 
3162          WHEN 'NEW_PARTY_SITE_ID'         THEN
3163             g_rec_header_new.array_new_party_site_id(g_header_idx)       := p_rec_acct_attrs.array_num_value(i);
3164 
3165          WHEN 'PREVIOUS_PARTY_ID'         THEN
3166             g_rec_header_new.array_previous_party_id(g_header_idx)       := p_rec_acct_attrs.array_num_value(i);
3167 
3168          WHEN 'PREVIOUS_PARTY_SITE_ID'    THEN
3169             g_rec_header_new.array_previous_party_site_id(g_header_idx)  := p_rec_acct_attrs.array_num_value(i);
3170 
3171          WHEN 'GL_DATE'                   THEN
3172             g_rec_header_new.array_gl_date(g_header_idx) := trunc(p_rec_acct_attrs.array_date_value(i));
3173             IF p_rec_acct_attrs.array_date_value(i) is NULL THEN
3174                XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_INVALID;
3175                xla_accounting_err_pkg.build_message
3176                   (p_appli_s_name            => 'XLA'
3177                   ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
3178                   ,p_token_1                 => 'ACCT_ATTR_NAME'
3179                   ,p_value_1                 => XLA_AE_SOURCES_PKG.GetAccountingSourceName('GL_DATE')
3180                   ,p_token_2                 => 'PRODUCT_NAME'
3181                   ,p_value_2                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
3182                   ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
3183                   ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
3184                   ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id);
3185             END IF;
3186          ELSE null;
3187       END CASE;
3188    end loop;
3189 EXCEPTION
3190 WHEN xla_exceptions_pkg.application_exception THEN
3191   RAISE;
3192 WHEN OTHERS  THEN
3193    xla_exceptions_pkg.raise_message
3194            (p_location => 'XLA_AE_HEADER_PKG.SetHdrAcctAttrs');
3195   --
3196 end SetHdrAcctAttrs;
3197 --
3198 /*======================================================================+
3199 |                                                                       |
3200 |                                                                       |
3201 |                                                                       |
3202 |                                                                       |
3203  +======================================================================*/
3204 PROCEDURE ValidateBusinessDate
3205 (p_ledger_id                      IN NUMBER
3206 )
3207 IS
3208 l_transaction_calendar_id          INTEGER;
3209 l_effective_date_rule_code         VARCHAR2(1);
3210 
3211 l_log_module                       VARCHAR2(240);
3212 BEGIN
3213 
3214 IF g_log_enabled THEN
3215       l_log_module := C_DEFAULT_MODULE||'.ValidateBusinessDate';
3216 END IF;
3217 
3218 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3219       trace
3220          (p_msg      => 'BEGIN of ValidateBusinessDate'
3221          ,p_level    => C_LEVEL_PROCEDURE
3222          ,p_module   => l_log_module);
3223 END IF;
3224 
3225 l_transaction_calendar_id := xla_accounting_cache_pkg.GetValueNum('TRANSACTION_CALENDAR_ID', p_ledger_id);
3226 
3227 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3228       trace
3229          (p_msg      => 'l_transaction_calendar_id ='||l_transaction_calendar_id
3230          ,p_level    => C_LEVEL_STATEMENT
3231          ,p_module   => l_log_module);
3232 END IF;
3233 
3234 IF (xla_accounting_cache_pkg.getValueChar('ENABLE_AVERAGE_BALANCES_FLAG',p_ledger_id) = 'Y' AND
3235     xla_accounting_cache_pkg.getValueChar('EFFECTIVE_DATE_RULE_CODE',p_ledger_id) = 'R' AND
3236     l_transaction_calendar_id IS NOT NULL) THEN
3237 
3238   IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3239     trace
3240        (p_msg      => 'SQL - update xla_ae_headers_gt'
3241        ,p_level    => C_LEVEL_STATEMENT
3242        ,p_module   => l_log_module);
3243   END IF;
3244 
3245   UPDATE xla_ae_headers_gt xah
3246      SET accounting_date =
3247          DECODE(xah.acc_rev_gl_date_option,
3248                 'XLA_NEXT_DAY',
3249                 (SELECT min(transaction_date)
3250                    FROM gl_transaction_dates d
3251                   WHERE d.business_day_flag = 'Y'
3252                     AND d.transaction_date >= xah.accounting_date
3253                     AND d.transaction_calendar_id = l_transaction_calendar_id),
3254                 -- XLA_FIRST_DAY_NEXT_GL_PERIOD, XLA_LAST_DAY_NEXT_GL_PERIOD, NONE
3255                 (SELECT transaction_date
3256                    FROM (SELECT xah2.ae_header_id
3257                               , d.transaction_date
3258                            FROM xla_ae_headers_gt xah2
3259                               , gl_transaction_dates d
3260                           WHERE d.transaction_calendar_id = l_transaction_calendar_id
3261                             AND d.business_day_flag       = 'Y'
3262                             AND d.transaction_date        >= xah2.period_start_date
3263                           ORDER by CASE WHEN d.transaction_date = xah2.accounting_date
3264                                         THEN 0
3265                                         WHEN d.transaction_date < xah2.accounting_date
3266                                         THEN xah2.accounting_date - d.transaction_date
3267                                         WHEN d.transaction_date > xah2.accounting_date
3268                                         THEN 1000 + d.transaction_date - xah2.accounting_date
3269                                         END ) tmp
3270                   WHERE ROWNUM = 1
3271                     AND xah.ae_header_id = tmp.ae_header_id));
3272 
3273   IF (C_LEVEL_STATEMENT >= g_log_level) THEN
3274     trace
3275        (p_msg      => '# rows updated in xla_ae_headers_gt(1.2) ='||SQL%ROWCOUNT
3276        ,p_level    => C_LEVEL_STATEMENT
3277        ,p_module   => l_log_module);
3278   END IF;
3279 
3280 END IF;
3281 
3282 
3283 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3284       trace
3285          (p_msg      => 'END of ValidateBusinessDate'
3286          ,p_level    => C_LEVEL_PROCEDURE
3287          ,p_module   => l_log_module);
3288 END IF;
3289 
3290 EXCEPTION
3291 WHEN xla_exceptions_pkg.application_exception THEN
3292    RAISE;
3293 WHEN OTHERS  THEN
3294    xla_exceptions_pkg.raise_message
3295                 (p_location => 'xla_ae_header_pkg.ValidateBusinessDate');
3296 END ValidateBusinessDate;
3297 
3298 --=============================================================================
3299 --
3300 --
3301 --
3302 --
3303 --
3304 --
3305 --
3306 --
3307 --
3308 --
3309 --
3310 --
3311 --
3312 --
3313 --
3314 --
3315 --
3316 --
3317 --
3318 --
3319 --
3320 --
3321 --=============================================================================
3322 --=============================================================================
3323 --          *********** Initialization routine **********
3324 --=============================================================================
3325 
3326 BEGIN
3327 
3328    g_log_level      := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
3329    g_log_enabled    := fnd_log.test
3330                           (log_level  => g_log_level
3331                           ,module     => C_DEFAULT_MODULE);
3332 
3333    IF NOT g_log_enabled  THEN
3334       g_log_level := C_LEVEL_LOG_DISABLED;
3335    END IF;
3336 
3337 END xla_ae_header_pkg; --