DBA Data[Home] [Help]

PACKAGE BODY: APPS.XLA_00206_AAD_S_000003_PKG

Source


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