DBA Data[Home] [Help]

APPS.XLA_AE_LINES_PKG SQL Statements

The following lines contain the word 'select', 'insert', 'update' or 'delete':

Line: 31

|     20-MAI-2003 K.Boussema    Added a Token to XLA_AP_CANNOT_INSERT_JE     |
|                               message                                      |
|     27-MAI-2003 K.Boussema    Renamed code_combination_status by           |
|                                  code_combination_status_flag              |
|                               Renamed base_amount by ledger_amount         |
|     30-MAI-2003 K.Boussema    Renamed EXCHANGE_RATE_DATE by EXCHANGE_DATE  |
|                                 bug 2979525                                |
|     17-JUL-2003 K.Boussema    Reviewd the code                             |
|     21-JUL-2003 K.Boussema    Changed reversal options from 'S' and 'R' to |
|                               'SIGN' and 'SIDE'                            |
|     24-JUL-2003 K.Boussema    Updated the error messages                   |
|     10-SEP-2003 K.Boussema    Changed to fix bug3095206:Accounting Reversal|
|     19-SEP-2003 K.Boussema    Code changed to include reversed_ae_header_id|
|                               and reversed_line_num, see bug 3143095       |
|     30-SEP-2003 K.Boussema    Added a validation for Accounting reversal   |
|     03-OCT-2003 K.Boussema    Fixed standard accounting reversal,bug3174532|
|                               Changed description width to 1996            |
|     06-OCT-2003 K.Boussema    Reviewed the StandardAccountingReversal() pg,|
|                               bug 3175581                                  |
|     16-OCT-2003 K.Boussema    Fixed the issue when the entered and         |
|                               accounted amounts are reversed.              |
|     22-OCT-2003 K.Boussema    Changed to capture the Merge Matching Lines  |
|                               preference for Accounting Reversal from JLT  |
|     29-OCT-2003 K.Boussema    Reviewed to fix bug 3222733                  |
|     04-NOV-2003 K.Boussema    Added TransactionReversal_2, LineReversal_2  |
|     13-NOV-2003 K.Boussema    Changed to store Accounting and transaction  |
|                               coa ids defined in Account Derivation rules  |
|     21-NOV-2003 K.Boussema    Added SetEnteredAmount to fix bug 3233610    |
|     25-NOV-2003 Shishir Joshi Made changers for accounting reversal.       |
|                               Merged procedures StandardAccountingReversal |
|                               and LineReversal_2.                          |
|                               Merged procedures TransactionReversal and    |
|                               TransactionReversal_2.                       |
|     05-DEC-2003 K.Boussema    Changed the code to fix bug3289875           |
|     12-DEC-2003 K.Boussema    Renamed target_coa_id in xla_ae_lines_gt     |
|                               by ccid_coa_id                               |
|     18-DEC-2003 K.Boussema    Changed to fix bug 3042840,3307761,3268940   |
|                               3310291 and 3320689                          |
|     07-JAN-2003 K.Boussema    Changed to populate switch_side_flag column  |
|     19-JAN-2004 K.Boussema    Removed the validation of Third party        |
|     20-JAN-2004 K.Boussema    Updated the message error XLA_AP_COA_INVALID |
|                               and Reviewed the validation of PARTY_TYPE    |
|     05-FEB-2004 S.Singhania   Changes based on bug 3419803.                |
|                                 - correct column names are used            |
|                                   TAX_LINE_REF_ID, TAX_SUMMARY_LINE_REF_ID,|
|                                   TAX_REC_NREC_DIST_REF_ID                 |
|                                 - reference to the column is removed.      |
|                                   TAX_REC_NREC_SUMMARY_DIST_REF            |
|                                 - Aaccounting attribute codes are modified |
|                                 - variables storing the column value       |
|                                   TAX_REC_NREC_SUMMARY_DIST_REF are removed|
|     17-FEB-2004 K.Boussema    Revised SetDebitCreditAmounts to fix issue   |
|                                 reported in bug 3438418                    |
|                               Made changes for the FND_LOG.                |
|     11-MAR-2004 K.Boussema    Reviewed StandardAccountingReversal and      |
|                                 TransactionReversal                        |
|                               Removed the validations of accounting class  |
|                                 and the party type                         |
|     22-MAR-2004 K.Boussema    Added a parameter p_module to the TRACE calls|
|                                 and the procedure.                         |
|     04-MAY-2004 K.Boussema    Bug 3531441: updated call to message         |
|                                 XLA_AP_NO_LEDGER_AMOUNT                    |
|     11-MAY-2004 K.Boussema    Removed the call to XLA trace routine from   |
|                                 trace() procedure                          |
|     17-MAY-2004 W.Shen        Changes for attribute enhancement project    |
|                                 Change to InsertLines,                     |
|                                 StandardAccountingReversal                 |
|                              move TransactionReversal toxla_ae_headers_pkg |
|                                 accounting_reversal is no longer used      |
|     26-MAY-2004 W.Shen        remove debug code.                           |
|     17-JUN-2004 K.Boussema    Removed the population with null the         |
|                                 conversion rate and the conversion type    |
|                                 when entered entered currency code = ledger|
|                                 currency code, bug 3592650                 |
|     18-JUN-2004 K.Boussema    Fixed GSCC warning                           |
|     27-JUN-2004 W.Shen        Fix the validation links(ValidateLinks,      |
|                                 ValidateRevLinks bug 3787453               |
|     22-Sep-2004 S.Singhania   Made changes for the bulk peroformance. It   |
|                                 has changed the code at number of places.  |
|     03-Nov-2004 S.Singhania   Bug 3984919. Fixed the technical problem in  |
|                                 AccountingReversal.                        |
|                               Also modified the insert statments in        |
|                                 AccountingRevesal to use amounts from      |
|                                 xla_distribution_links instead of amounts  |
|                                 from xla_ae_lines table.                   |
|     09-MAR-2005 W.Shen       Ledger Currency Project.                      |
|     14-Mar-2005 K.Boussema   Changed for ADR-enhancements.                 |
|     28-Mar-2005 A.Wan        Changed for Business Flow.                    |
|     20-Apr-2005 W. Shen      replace column document_rounding_amount by    |
|                                 doc_rounding_acctd_amt                     |
|     25-Apr-2005 S.singhania  Bug 4257522. Issue fixed with the transaction |
|                                 reversls.                                  |
|     19-MAI-2005 K.Boussema   Reviewed set_segment to fix bug4304098        |
|     25-MAY-2005 W.Chan       fix bug4384869 - BusinessFlowSameEntries      |
|     1-Jul-2005  W. Shen      Bug 4243728, 4444730                      .   |
|                              set entered_cr/dr side based on               |
|                                unrounded_accounted_amount if entered is 0  |
|                                (mainly for gain/loss line)                 |
|                              calculate rounded amount sole based on        |
|                                the calculate_amts_flag.                    |
|                                set calculate_amts_flag correctly.          |
|     11-Jul-2005 A.Wan        4262811 - MPA project                         |
|     12-Jul-2005 W. Chan      Bug 4478604 - Fixed business flow for sec     |
|                              ledg  ALC ledg.  Fixed accounted amount calc  |
|                              for business flow.                            |
|     9-Sep-2005 W. Shen       Bug 4596489, msg XLA_AP_NO_LEDGER_AMOUNT      |
|                                has moved one token                         |
|     22-Sep-2005 S.Singhania  Bug 4544725. Implemented Business Flows and   |
|                                Reversals for Non-Upgraded JEs.             |
|     26-Sep-2005 W. Shen      Bug 4628603. reset g_transaction_accounts     |
|                                after insertion so no duplicated rows will  |
|                                be inserted.                                |
|                                removed the header_num in AccountingReversal|
|                                since it may cause unique index violated    |
|     12-Oct-2005 A.Wan        4656703 - bflow prior entry amt incorrect     |
|     18-Oct-2005 V. Kumar    Removed code for Analytical Criteria           |
|     7-Nov-2005 W.Shen       4655713 - bflow same entry does not work       |
|     17-Nov-2005 W.Shen      4727011 - unique index violated                |
|                                In accountingreversal, when inserting header|
|                                for lines that do not have header yet, the  |
|                                join condition of header_num is not correct |
|                                add nvl for join of header_num since it     |
|                                could be null                               |
|     22-Dec-2005 W.Chan      4903255 - Prior Entry Bflow changes            |
|                             1) Exclude reversal from prior entry           |
|                             2) Allow multiple prior entries                |
|     22-Dec-2005 A.Wan       4669308 - AccountingReversal - for MPA/Accrual |
|                                       reversal.                            |
|     3-Jan-2006  W. Chan     Bug 4924492 - Populate budget version id for   |
|                               accounting reversal                          |
|     4-Jan-2006  A. Govil    Bug 4922099 - Handle Federal Non-upgraded      |
|                             entries.                                       |
|     7-Jan-2006  W. Chan     Bug 4930297 - BflowPriorEntries error cursor   |
|                               not work if bflow app id is null             |
|     20-Jan-2006 W.Chan      4946123 - BC changes for prior entry           |
|     27-Jan-2005 A.Wan       5001981 - Same entry exclude lines with        |
|                             PRIOR_ENTRY business flow method.              |
|     27-Jan-2006 A.Wan       4913967 - performance change for               |
|                                       BusinessFlowSameEntries.             |
|     27-Jan-2006 V.Kumar     4963125 Added hint and join based on appl_id   |
|                               in AccountingReversal.                       |
|     27-Jan-2006 A.Wan       4655713  - to set proper status for SameEntry. |
|     31-Jan-2006 A.Wan       4963422  - set header_num to 0 in acct reversal|
|     01-Feb-2006 A.Wan       4655713b - modify BusinessFlowPriorEntries and |
|                                        BusinessFlowSameEntries to inherit  |
|                                        ae_lines_gt detail for bflow entries|
|                                        for MPA and Accrual Reversal lines. |
|     10-Feb-2006 A.Wan       5019460 - could not reverse prior entries.     |
|     13-Feb-2006 V.Kumar     4955764 Populating Accounting_date in          |
|                                     xla_ae_lines_gt                        |
|     14-Feb-2006 A.Wan       4967526 - copy following for Third Party info  |
|                                       in BusinessFlowPriorEntries:         |
|                                       - merge_code_combination_id          |
|                                       - merge_party_id                     |
|                                       - merge_party_site_id                |
|     20-Feb-2006 A.Wan       4913967 - remove redundant GROUP BY in         |
|                                       BusinessFlowSameEntries.             |
|     28-Feb-2006 A.Wan       5068675 - undo fix on 20-Feb for bug 4913967   |
|     01-Mar-2006 A.Wan       5055878 - Accounting reversal does not handle  |
|                                       reversal method of SIGN.             |
|     07-Mar-2006 A.Wan       4693816 - do not assign PARTY_TYPE is size is  |
|                                       more than 1.                         |
|     08-Mar-2006 V.Kumar     Modified procedure SetNewLines and added new   |
|                             procedure SetNullLine                          |
|     13-Mar-2006 A.Wan       5086984 - modify MPA/Accrual reversal in       |
|                                       AccountingReversal for performance.  |
|     27-Mar-2006 A.Wan       5108415 - modify Accounting reversal for       |
|                                       peformance fix.                      |
|     15-Apr-2006 A.Wan       5132302 - add Applied To Amount for Gain/Loss  |
|     25-Apr-2006 A.Wan       5183946 - line acct reversal error for Accrual |
|                                       Reversal.                            |
|     09-May-2006 V.Kumar     5194849 Modified procedure SetAcctReversalAttrs|
|                                     to populate GL_date for Reversal Acct  |
|     09-May-2006 A.Wan       5204178 - cannot find PE for sec ledger if     |
|                                       valuation method is Yes.             |
|     19-May-2006 V.Kumar     5229264 Modified procedure SetTrxReversalAttrs |
|     11-May-2006 A.Wan       5189664 - reversal line not stamped with       |
|                                       date from reversal event.            |
|     09-May-2006 A.Wan       5162408 - invalid value for acct attribute.    |
|     22-Jun-2006 W.Shen      5294631, 5259776 - put gain/loss amount on dr  |
|                                       side as well so reversal can handle  |
|                                    also, add ccid mapping for g/l lines    |
|     22-Jun-2006 A.Wan       5100860 - make sure to assign a value to       |
|                                       HEADER_NUM in InsertLines.           |
|     28-Jul-2006 A.Wan       5357406 - prior entry performance fix          |
|     01-Aug-2006 A.Wan       5412560 - line reversal for MPA/AccRev.        |
|     17-Aug-2006 A.Wan       5443083 - delete zero amt same entry in ALC    |
|                                       and secondary ledger.                |
|     23-Aug-2006 A.Wan       5486053 - add HINT to same entry               |
|     25-Aug-2006 A.Wan       5479652 - modify condition in line reversal.   |
|     01-SEP-2006 A.Wan       5163338 - raise error when CCID is -1          |
|     20-NOV-2006 A.Wan       5666366 - do not execute MPA-prior entry SQL   |
|                                       if there are no MPA in this run.     |
|     26-jan-2007 A.Wan       5845547 - upgrade fail for not upgraded bflow  |
|                                       and reversal transactions.  Add      |
|                                       upgrade party attributes.            |
|     14-Dec-2007 V.Swapna    6648062 - Populate xla_ae_lines_gt with        |
|                                       the values passed in override acctd  |
|                                       amts accounting attribute and use    |
|                                       it in business flow procedure        |
|     31-Dec-2007 V. Swapna   5339999 - Changes to BusinessFlowPriorEntries  |
|                                       for Historic upgrade of secondary/alc|
|     25-Jan-2007 S.Sawhney   6658161,6727907 --merged branchline fixes onto mainline |
|     05-Nov-2007 KARAMAKR    7485529 - merged branchline fixes onto mainline|
|     06-Nov-2008 VGOPISET    7337288 - AccountingReversal is changed to     |
|                                       consider the SWITCH_SIDE option of   |
|                                       Reversal Event rather than value of  |
|                                       Original Event                       |
+===========================================================================*/
--
--+==========================================================================+
--|                                                                          |
--|                                                                          |
--| CONSTANT                                                                 |
--|                                                                          |
--|                                                                          |
--+==========================================================================+
--
C_MAXROWS             CONSTANT NATURAL     := 1000;
Line: 1577

   l_result := xla_ae_lines_pkg.InsertLines;
Line: 2976

FUNCTION InsertLines
RETURN BOOLEAN
IS
l_result                   BOOLEAN;
Line: 2992

      l_log_module := C_DEFAULT_MODULE||'.InsertLines';
Line: 2996

         (p_msg      => 'BEGIN of InsertLines'
         ,p_level    => C_LEVEL_PROCEDURE
         ,p_module   => l_log_module);
Line: 3005

  (p_msg      => '# temporary journal lines to insert into GT xla_ae_lines_gt = '||g_rec_lines.array_line_num.COUNT
  ,p_level    => C_LEVEL_STATEMENT
  ,p_module   => l_log_module);
Line: 3044

         (p_msg      => 'SQL - Insert into xla_ae_lines_gt'
         ,p_level    => C_LEVEL_STATEMENT
         ,p_module   => l_log_module);
Line: 3052

   INSERT INTO xla_ae_lines_gt
         ( ae_header_id
         , temp_line_num
         , extract_line_num
         , event_id
         , ref_ae_header_id
         --
         , accounting_date        --4955764
         , accounting_class_code
         , rounding_class_code
         , event_class_code
         , event_type_code
         , line_definition_owner_code
         , line_definition_code
         , accounting_line_type_code
         , accounting_line_code
         , document_rounding_level
         , gain_or_loss_ref
         --
         , calculate_acctd_amts_flag
         , calculate_g_l_amts_flag
         , gain_or_loss_flag
         --
         , code_combination_status_code
         , code_combination_id
         , sl_coa_mapping_name
         , sl_coa_mapping_id
         , dynamic_insert_flag
         , source_coa_id
         , ccid_coa_id
         , segment1
         , segment2
         , segment3
         , segment4
         , segment5
         , segment6
         , segment7
         , segment8
         , segment9
         , segment10
         , segment11
         , segment12
         , segment13
         , segment14
         , segment15
         , segment16
         , segment17
         , segment18
         , segment19
         , segment20
         , segment21
         , segment22
         , segment23
         , segment24
         , segment25
         , segment26
         , segment27
         , segment28
         , segment29
         , segment30
         --
         , alt_ccid_status_code
         , alt_code_combination_id
         , alt_segment1
         , alt_segment2
         , alt_segment3
         , alt_segment4
         , alt_segment5
         , alt_segment6
         , alt_segment7
         , alt_segment8
         , alt_segment9
         , alt_segment10
         , alt_segment11
         , alt_segment12
         , alt_segment13
         , alt_segment14
         , alt_segment15
         , alt_segment16
         , alt_segment17
         , alt_segment18
         , alt_segment19
         , alt_segment20
         , alt_segment21
         , alt_segment22
         , alt_segment23
         , alt_segment24
         , alt_segment25
         , alt_segment26
         , alt_segment27
         , alt_segment28
         , alt_segment29
         , alt_segment30
         --
         , description
         , gl_transfer_mode_code
         , merge_duplicate_code
         , switch_side_flag
         --
         , entered_amount
         , ledger_amount
         , unrounded_entered_dr
         , unrounded_entered_cr
         , unrounded_accounted_dr
         , unrounded_accounted_cr
         , entered_currency_mau
         , currency_code
         , currency_conversion_date
         , currency_conversion_rate
         , currency_conversion_type
         , statistical_amount
         --
         , party_id
         , party_site_id
         , party_type_code
         --
         , ussgl_transaction_code
         , jgzz_recon_ref
         , source_distribution_id_char_1
         , source_distribution_id_char_2
         , source_distribution_id_char_3
         , source_distribution_id_char_4
         , source_distribution_id_char_5
         , source_distribution_id_num_1
         , source_distribution_id_num_2
         , source_distribution_id_num_3
         , source_distribution_id_num_4
         , source_distribution_id_num_5
         , source_distribution_type
         --
         , reverse_dist_id_char_1
         , reverse_dist_id_char_2
         , reverse_dist_id_char_3
         , reverse_dist_id_char_4
         , reverse_dist_id_char_5
         , reverse_dist_id_num_1
         , reverse_dist_id_num_2
         , reverse_dist_id_num_3
         , reverse_dist_id_num_4
         , reverse_dist_id_num_5
         , reverse_distribution_type
         --
         , tax_line_ref_id
         , tax_summary_line_ref_id
         , tax_rec_nrec_dist_ref_id
         --
         --
         -- 4262811
         , header_num
         , mpa_accrual_entry_flag
         , multiperiod_option_flag
         , multiperiod_start_date
         , multiperiod_end_date
         --
         , analytical_balance_flag
         , anc_id_1
         , anc_id_2
         , anc_id_3
         , anc_id_4
         , anc_id_5
         , anc_id_6
         , anc_id_7
         , anc_id_8
         , anc_id_9
         , anc_id_10
         , anc_id_11
         , anc_id_12
         , anc_id_13
         , anc_id_14
         , anc_id_15
         , anc_id_16
         , anc_id_17
         , anc_id_18
         , anc_id_19
         , anc_id_20
         , anc_id_21
         , anc_id_22
         , anc_id_23
         , anc_id_24
         , anc_id_25
         , anc_id_26
         , anc_id_27
         , anc_id_28
         , anc_id_29
         , anc_id_30
         , anc_id_31
         , anc_id_32
         , anc_id_33
         , anc_id_34
         , anc_id_35
         , anc_id_36
         , anc_id_37
         , anc_id_38
         , anc_id_39
         , anc_id_40
         , anc_id_41
         , anc_id_42
         , anc_id_43
         , anc_id_44
         , anc_id_45
         , anc_id_46
         , anc_id_47
         , anc_id_48
         , anc_id_49
         , anc_id_50
         , anc_id_51
         , anc_id_52
         , anc_id_53
         , anc_id_54
         , anc_id_55
         , anc_id_56
         , anc_id_57
         , anc_id_58
         , anc_id_59
         , anc_id_60
         , anc_id_61
         , anc_id_62
         , anc_id_63
         , anc_id_64
         , anc_id_65
         , anc_id_66
         , anc_id_67
         , anc_id_68
         , anc_id_69
         , anc_id_70
         , anc_id_71
         , anc_id_72
         , anc_id_73
         , anc_id_74
         , anc_id_75
         , anc_id_76
         , anc_id_77
         , anc_id_78
         , anc_id_79
         , anc_id_80
         , anc_id_81
         , anc_id_82
         , anc_id_83
         , anc_id_84
         , anc_id_85
         , anc_id_86
         , anc_id_87
         , anc_id_88
         , anc_id_89
         , anc_id_90
         , anc_id_91
         , anc_id_92
         , anc_id_93
         , anc_id_94
         , anc_id_95
         , anc_id_96
         , anc_id_97
         , anc_id_98
         , anc_id_99
         , anc_id_100
         --, deferred_indicator
         --, deferred_start_date
         --, deferred_end_date
         --, deferred_no_period
         --, deferred_period_type
        -- bulk performance
         , balance_type_code  -- element at index [x] does not exist.
         , ledger_id          -- element at index [x] does not exist.
         , event_number
         , entity_id
         , reversal_code
         , encumbrance_type_id -- 4458381
         --------------------------------------
         -- 4219869
         -- Business Flow Applied To attributes
         --------------------------------------
         ,inherit_desc_flag
         ,natural_side_code
         ,business_method_code
         ,business_class_code
         ,bflow_application_id
         ,bflow_entity_code
         ,bflow_source_id_num_1
         ,bflow_source_id_num_2
         ,bflow_source_id_num_3
         ,bflow_source_id_num_4
         ,bflow_source_id_char_1
         ,bflow_source_id_char_2
         ,bflow_source_id_char_3
         ,bflow_source_id_char_4
         ,bflow_distribution_type
         ,bflow_dist_id_num_1
         ,bflow_dist_id_num_2
         ,bflow_dist_id_num_3
         ,bflow_dist_id_num_4
         ,bflow_dist_id_num_5
         ,bflow_dist_id_char_1
         ,bflow_dist_id_char_2
         ,bflow_dist_id_char_3
         ,bflow_dist_id_char_4
         ,bflow_dist_id_char_5
         ,bflow_applied_to_amount  -- 5132302
     ,override_acctd_amt_flag
         --
         -- Allocation Attributes
         --
         ,alloc_to_application_id
         ,alloc_to_entity_code
         ,alloc_to_source_id_num_1
         ,alloc_to_source_id_num_2
         ,alloc_to_source_id_num_3
         ,alloc_to_source_id_num_4
         ,alloc_to_source_id_char_1
         ,alloc_to_source_id_char_2
         ,alloc_to_source_id_char_3
         ,alloc_to_source_id_char_4
         ,alloc_to_distribution_type
         ,alloc_to_dist_id_num_1
         ,alloc_to_dist_id_num_2
         ,alloc_to_dist_id_num_3
         ,alloc_to_dist_id_num_4
         ,alloc_to_dist_id_num_5
         ,alloc_to_dist_id_char_1
         ,alloc_to_dist_id_char_2
         ,alloc_to_dist_id_char_3
         ,alloc_to_dist_id_char_4
         ,alloc_to_dist_id_char_5
   )
   VALUES
   (
     g_rec_lines.array_ae_header_id(Idx)
   , g_rec_lines.array_line_num(Idx)
   , g_rec_lines.array_extract_line_num(Idx)
   , g_rec_lines.array_ae_header_id(Idx)
   , g_rec_lines.array_ae_header_id(Idx)
  --
   , g_rec_lines.array_gl_date(Idx)           --4955764
   , g_rec_lines.array_accounting_class(Idx)
   , g_rec_lines.array_rounding_class(Idx)
   , g_rec_lines.array_event_class_code(Idx)
   , g_rec_lines.array_event_type_code(Idx)
   , g_rec_lines.array_line_defn_owner_code(Idx)
   , g_rec_lines.array_line_defn_code(Idx)
   , g_rec_lines.array_accounting_line_type(Idx)
   , g_rec_lines.array_accounting_line_code(Idx)
   , g_rec_lines.array_doc_rounding_level(Idx)
   , nvl(g_rec_lines.array_gain_or_loss_ref(Idx), '#line#'||g_rec_lines.array_extract_line_num(Idx))
   --
   , g_rec_lines.array_calculate_acctd_flag(Idx)
   , g_rec_lines.array_calculate_g_l_flag(Idx)
   , decode(g_rec_lines.array_gain_or_loss_flag(Idx), 'Y', 'Y', decode(g_rec_lines.array_natural_side_code(Idx), 'G', 'Y', 'N'))
   --
   , g_rec_lines.array_ccid_flag(Idx)
   , g_rec_lines.array_ccid(Idx)
   --
   , XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.sl_coa_mapping_name
   , XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.sl_coa_mapping_id
  --
   , XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.dynamic_insert_flag
   , XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.source_coa_id
   , XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.target_coa_id
  --
   , g_rec_lines.array_segment1(Idx)
   , g_rec_lines.array_segment2(Idx)
   , g_rec_lines.array_segment3(Idx)
   , g_rec_lines.array_segment4(Idx)
   , g_rec_lines.array_segment5(Idx)
   , g_rec_lines.array_segment6(Idx)
   , g_rec_lines.array_segment7(Idx)
   , g_rec_lines.array_segment8(Idx)
   , g_rec_lines.array_segment9(Idx)
   , g_rec_lines.array_segment10(Idx)
   , g_rec_lines.array_segment11(Idx)
   , g_rec_lines.array_segment12(Idx)
   , g_rec_lines.array_segment13(Idx)
   , g_rec_lines.array_segment14(Idx)
   , g_rec_lines.array_segment15(Idx)
   , g_rec_lines.array_segment16(Idx)
   , g_rec_lines.array_segment17(Idx)
   , g_rec_lines.array_segment18(Idx)
   , g_rec_lines.array_segment19(Idx)
   , g_rec_lines.array_segment20(Idx)
   , g_rec_lines.array_segment21(Idx)
   , g_rec_lines.array_segment22(Idx)
   , g_rec_lines.array_segment23(Idx)
   , g_rec_lines.array_segment24(Idx)
   , g_rec_lines.array_segment25(Idx)
   , g_rec_lines.array_segment26(Idx)
   , g_rec_lines.array_segment27(Idx)
   , g_rec_lines.array_segment28(Idx)
   , g_rec_lines.array_segment29(Idx)
   , g_rec_lines.array_segment30(Idx)
    --
   , g_rec_lines.alt_array_ccid_flag(Idx)
   , g_rec_lines.alt_array_ccid(Idx)
   , g_rec_lines.alt_array_segment1(Idx)
   , g_rec_lines.alt_array_segment2(Idx)
   , g_rec_lines.alt_array_segment3(Idx)
   , g_rec_lines.alt_array_segment4(Idx)
   , g_rec_lines.alt_array_segment5(Idx)
   , g_rec_lines.alt_array_segment6(Idx)
   , g_rec_lines.alt_array_segment7(Idx)
   , g_rec_lines.alt_array_segment8(Idx)
   , g_rec_lines.alt_array_segment9(Idx)
   , g_rec_lines.alt_array_segment10(Idx)
   , g_rec_lines.alt_array_segment11(Idx)
   , g_rec_lines.alt_array_segment12(Idx)
   , g_rec_lines.alt_array_segment13(Idx)
   , g_rec_lines.alt_array_segment14(Idx)
   , g_rec_lines.alt_array_segment15(Idx)
   , g_rec_lines.alt_array_segment16(Idx)
   , g_rec_lines.alt_array_segment17(Idx)
   , g_rec_lines.alt_array_segment18(Idx)
   , g_rec_lines.alt_array_segment19(Idx)
   , g_rec_lines.alt_array_segment20(Idx)
   , g_rec_lines.alt_array_segment21(Idx)
   , g_rec_lines.alt_array_segment22(Idx)
   , g_rec_lines.alt_array_segment23(Idx)
   , g_rec_lines.alt_array_segment24(Idx)
   , g_rec_lines.alt_array_segment25(Idx)
   , g_rec_lines.alt_array_segment26(Idx)
   , g_rec_lines.alt_array_segment27(Idx)
   , g_rec_lines.alt_array_segment28(Idx)
   , g_rec_lines.alt_array_segment29(Idx)
   , g_rec_lines.alt_array_segment30(Idx)
    --
   , g_rec_lines.array_description(Idx)
   , g_rec_lines.array_gl_transfer_mode(Idx)
   , g_rec_lines.array_merge_duplicate_code(Idx)
   , decode(g_rec_lines.array_natural_side_code(Idx), 'G', 'Y',
           g_rec_lines.array_switch_side_flag(Idx))
      --
   , g_rec_lines.array_entered_amount(Idx)
   , g_rec_lines.array_ledger_amount(Idx)
   , g_rec_lines.array_entered_dr(Idx)
   , g_rec_lines.array_entered_cr(Idx)
   , g_rec_lines.array_accounted_dr(Idx)
   , g_rec_lines.array_accounted_cr(Idx)
   -- currency mau, put some dummy value for gain/loss line
   , decode(g_rec_lines.array_natural_side_code(Idx), 'G', .01
            , g_rec_lines.array_currency_mau(Idx))
   , decode(g_rec_lines.array_natural_side_code(Idx), 'G', l_ledger_currency
            , g_rec_lines.array_currency_code(Idx))--
   , decode(l_ledger_category_code
           ,'PRIMARY',TRUNC(g_rec_lines.array_curr_conversion_date(Idx))
           ,decode(l_ledger_currency
                  ,g_rec_lines.array_currency_code(Idx),NULL
                  ,TRUNC(g_rec_lines.array_curr_conversion_date(Idx))
                  )
           )    -- currency_conversion_date
   , decode(l_ledger_category_code, 'PRIMARY',
        g_rec_lines.array_curr_conversion_rate(Idx)
        ,decode(l_ledger_currency, g_rec_lines.array_currency_code(Idx),
           null, g_rec_lines.array_curr_conversion_rate(Idx)))
   , decode(l_ledger_category_code, 'PRIMARY',
        g_rec_lines.array_curr_conversion_type(Idx)
        ,decode(l_ledger_currency, g_rec_lines.array_currency_code(Idx),
           null, g_rec_lines.array_curr_conversion_type(Idx)))
   , g_rec_lines.array_statistical_amount(Idx)
    --
   , g_rec_lines.array_party_id(Idx)
   , g_rec_lines.array_party_site_id(Idx)
   , g_rec_lines.array_party_type_code(Idx)
    --
   , g_rec_lines.array_ussgl_transaction(Idx)
   , g_rec_lines.array_jgzz_recon_ref(Idx)
    --
   , g_rec_lines.array_distribution_id_char_1(Idx)
   , g_rec_lines.array_distribution_id_char_2(Idx)
   , g_rec_lines.array_distribution_id_char_3(Idx)
   , g_rec_lines.array_distribution_id_char_4(Idx)
   , g_rec_lines.array_distribution_id_char_5(Idx)
   , g_rec_lines.array_distribution_id_num_1(Idx)
   , g_rec_lines.array_distribution_id_num_2(Idx)
   , g_rec_lines.array_distribution_id_num_3(Idx)
   , g_rec_lines.array_distribution_id_num_4(Idx)
   , g_rec_lines.array_distribution_id_num_5(Idx)
   , g_rec_lines.array_sys_distribution_type(Idx)
   --
   , g_rec_lines.array_rev_dist_id_char_1(Idx)
   , g_rec_lines.array_rev_dist_id_char_2(Idx)
   , g_rec_lines.array_rev_dist_id_char_3(Idx)
   , g_rec_lines.array_rev_dist_id_char_4(Idx)
   , g_rec_lines.array_rev_dist_id_char_5(Idx)
   , g_rec_lines.array_rev_dist_id_num_1(Idx)
   , g_rec_lines.array_rev_dist_id_num_2(Idx)
   , g_rec_lines.array_rev_dist_id_num_3(Idx)
   , g_rec_lines.array_rev_dist_id_num_4(Idx)
   , g_rec_lines.array_rev_dist_id_num_5(Idx)
   , g_rec_lines.array_rev_dist_type(Idx)
   --
   , g_rec_lines.array_tax_line_ref(Idx)
   , g_rec_lines.array_tax_summary_line_ref(Idx)
   , g_rec_lines.array_tax_rec_nrec_dist_ref(Idx)
  -- 4262811
   , NVL(g_rec_lines.array_header_num(Idx),0)  -- 5100860  always assign a value
   , g_rec_lines.array_mpa_acc_entry_flag(Idx)
   , g_rec_lines.array_mpa_option(Idx)
   , g_rec_lines.array_mpa_start_date(Idx)
   , g_rec_lines.array_mpa_end_date(Idx)
   -- Analytical Criteria
   , g_rec_lines.array_anc_balance_flag(Idx)
   , g_rec_lines.array_anc_id_1(Idx)
   , g_rec_lines.array_anc_id_2(Idx)
   , g_rec_lines.array_anc_id_3(Idx)
   , g_rec_lines.array_anc_id_4(Idx)
   , g_rec_lines.array_anc_id_5(Idx)
   , g_rec_lines.array_anc_id_6(Idx)
   , g_rec_lines.array_anc_id_7(Idx)
   , g_rec_lines.array_anc_id_8(Idx)
   , g_rec_lines.array_anc_id_9(Idx)
   , g_rec_lines.array_anc_id_10(Idx)
   , g_rec_lines.array_anc_id_11(Idx)
   , g_rec_lines.array_anc_id_12(Idx)
   , g_rec_lines.array_anc_id_13(Idx)
   , g_rec_lines.array_anc_id_14(Idx)
   , g_rec_lines.array_anc_id_15(Idx)
   , g_rec_lines.array_anc_id_16(Idx)
   , g_rec_lines.array_anc_id_17(Idx)
   , g_rec_lines.array_anc_id_18(Idx)
   , g_rec_lines.array_anc_id_19(Idx)
   , g_rec_lines.array_anc_id_20(Idx)
   , g_rec_lines.array_anc_id_21(Idx)
   , g_rec_lines.array_anc_id_22(Idx)
   , g_rec_lines.array_anc_id_23(Idx)
   , g_rec_lines.array_anc_id_24(Idx)
   , g_rec_lines.array_anc_id_25(Idx)
   , g_rec_lines.array_anc_id_26(Idx)
   , g_rec_lines.array_anc_id_27(Idx)
   , g_rec_lines.array_anc_id_28(Idx)
   , g_rec_lines.array_anc_id_29(Idx)
   , g_rec_lines.array_anc_id_30(Idx)
   , g_rec_lines.array_anc_id_31(Idx)
   , g_rec_lines.array_anc_id_32(Idx)
   , g_rec_lines.array_anc_id_33(Idx)
   , g_rec_lines.array_anc_id_34(Idx)
   , g_rec_lines.array_anc_id_35(Idx)
   , g_rec_lines.array_anc_id_36(Idx)
   , g_rec_lines.array_anc_id_37(Idx)
   , g_rec_lines.array_anc_id_38(Idx)
   , g_rec_lines.array_anc_id_39(Idx)
   , g_rec_lines.array_anc_id_40(Idx)
   , g_rec_lines.array_anc_id_41(Idx)
   , g_rec_lines.array_anc_id_42(Idx)
   , g_rec_lines.array_anc_id_43(Idx)
   , g_rec_lines.array_anc_id_44(Idx)
   , g_rec_lines.array_anc_id_45(Idx)
   , g_rec_lines.array_anc_id_46(Idx)
   , g_rec_lines.array_anc_id_47(Idx)
   , g_rec_lines.array_anc_id_48(Idx)
   , g_rec_lines.array_anc_id_49(Idx)
   , g_rec_lines.array_anc_id_50(Idx)
   , g_rec_lines.array_anc_id_51(Idx)
   , g_rec_lines.array_anc_id_52(Idx)
   , g_rec_lines.array_anc_id_53(Idx)
   , g_rec_lines.array_anc_id_54(Idx)
   , g_rec_lines.array_anc_id_55(Idx)
   , g_rec_lines.array_anc_id_56(Idx)
   , g_rec_lines.array_anc_id_57(Idx)
   , g_rec_lines.array_anc_id_58(Idx)
   , g_rec_lines.array_anc_id_59(Idx)
   , g_rec_lines.array_anc_id_60(Idx)
   , g_rec_lines.array_anc_id_61(Idx)
   , g_rec_lines.array_anc_id_62(Idx)
   , g_rec_lines.array_anc_id_63(Idx)
   , g_rec_lines.array_anc_id_64(Idx)
   , g_rec_lines.array_anc_id_65(Idx)
   , g_rec_lines.array_anc_id_66(Idx)
   , g_rec_lines.array_anc_id_67(Idx)
   , g_rec_lines.array_anc_id_68(Idx)
   , g_rec_lines.array_anc_id_69(Idx)
   , g_rec_lines.array_anc_id_70(Idx)
   , g_rec_lines.array_anc_id_71(Idx)
   , g_rec_lines.array_anc_id_72(Idx)
   , g_rec_lines.array_anc_id_73(Idx)
   , g_rec_lines.array_anc_id_74(Idx)
   , g_rec_lines.array_anc_id_75(Idx)
   , g_rec_lines.array_anc_id_76(Idx)
   , g_rec_lines.array_anc_id_77(Idx)
   , g_rec_lines.array_anc_id_78(Idx)
   , g_rec_lines.array_anc_id_79(Idx)
   , g_rec_lines.array_anc_id_80(Idx)
   , g_rec_lines.array_anc_id_81(Idx)
   , g_rec_lines.array_anc_id_82(Idx)
   , g_rec_lines.array_anc_id_83(Idx)
   , g_rec_lines.array_anc_id_84(Idx)
   , g_rec_lines.array_anc_id_85(Idx)
   , g_rec_lines.array_anc_id_86(Idx)
   , g_rec_lines.array_anc_id_87(Idx)
   , g_rec_lines.array_anc_id_88(Idx)
   , g_rec_lines.array_anc_id_89(Idx)
   , g_rec_lines.array_anc_id_90(Idx)
   , g_rec_lines.array_anc_id_91(Idx)
   , g_rec_lines.array_anc_id_92(Idx)
   , g_rec_lines.array_anc_id_93(Idx)
   , g_rec_lines.array_anc_id_94(Idx)
   , g_rec_lines.array_anc_id_95(Idx)
   , g_rec_lines.array_anc_id_96(Idx)
   , g_rec_lines.array_anc_id_97(Idx)
   , g_rec_lines.array_anc_id_98(Idx)
   , g_rec_lines.array_anc_id_99(Idx)
   , g_rec_lines.array_anc_id_100(Idx)
  -- , g_rec_lines.array_deferred_indicator(Idx)
  -- , g_rec_lines.array_deferred_start_date(Idx)
  -- , g_rec_lines.array_deferred_end_date(Idx)
  -- , g_rec_lines.array_deferred_no_period(Idx)
  -- , g_rec_lines.array_deferred_period_type(Idx)
  -- bulk performance
   , g_rec_lines.array_balance_type_code(Idx)  -- element at index [x] does not exist.
   , g_rec_lines.array_ledger_id(Idx)          -- element at index [x] does not exist.
   , g_rec_lines.array_event_number(Idx)
   , g_rec_lines.array_entity_id(Idx)
   , g_rec_lines.array_reversal_code(Idx)
   , g_rec_lines.array_encumbrance_type_id(Idx) -- 4458381
   --------------------------------------
   -- 4219869
   -- Business Flow Applied To attributes
   --------------------------------------
   , g_rec_lines.array_inherit_desc_flag(Idx)
   , g_rec_lines.array_natural_side_code(Idx)
   , g_rec_lines.array_business_method_code(Idx)
   , g_rec_lines.array_business_class_code(Idx)
   , g_rec_lines.array_bflow_application_id(Idx)
   --
   , g_rec_lines.array_bflow_entity_code(Idx)
   , g_rec_lines.array_bflow_source_id_num_1(Idx)
   , g_rec_lines.array_bflow_source_id_num_2(Idx)
   , g_rec_lines.array_bflow_source_id_num_3(Idx)
   , g_rec_lines.array_bflow_source_id_num_4(Idx)
   , g_rec_lines.array_bflow_source_id_char_1(Idx)
   , g_rec_lines.array_bflow_source_id_char_2(Idx)
   , g_rec_lines.array_bflow_source_id_char_3(Idx)
   , g_rec_lines.array_bflow_source_id_char_4(Idx)
   --
   , g_rec_lines.array_bflow_distribution_type(Idx)
   , g_rec_lines.array_bflow_dist_id_num_1(Idx)
   , g_rec_lines.array_bflow_dist_id_num_2(Idx)
   , g_rec_lines.array_bflow_dist_id_num_3(Idx)
   , g_rec_lines.array_bflow_dist_id_num_4(Idx)
   , g_rec_lines.array_bflow_dist_id_num_5(Idx)
   , g_rec_lines.array_bflow_dist_id_char_1(Idx)
   , g_rec_lines.array_bflow_dist_id_char_2(Idx)
   , g_rec_lines.array_bflow_dist_id_char_3(Idx)
   , g_rec_lines.array_bflow_dist_id_char_4(Idx)
   , g_rec_lines.array_bflow_dist_id_char_5(Idx)
   , g_rec_lines.array_bflow_applied_to_amt(Idx)  -- 5132302
   , g_rec_lines.array_override_acctd_amt_flag(Idx)
   --
   -- Allocation Attributes
   --
   , g_rec_lines.array_alloct_application_id(Idx)
   , g_rec_lines.array_alloct_entity_code(Idx)
   , g_rec_lines.array_alloct_source_id_num_1(Idx)
   , g_rec_lines.array_alloct_source_id_num_2(Idx)
   , g_rec_lines.array_alloct_source_id_num_3(Idx)
   , g_rec_lines.array_alloct_source_id_num_4(Idx)
   , g_rec_lines.array_alloct_source_id_char_1(Idx)
   , g_rec_lines.array_alloct_source_id_char_2(Idx)
   , g_rec_lines.array_alloct_source_id_char_3(Idx)
   , g_rec_lines.array_alloct_source_id_char_4(Idx)
   , g_rec_lines.array_alloct_distribution_type(Idx)
   , g_rec_lines.array_alloct_dist_id_num_1(Idx)
   , g_rec_lines.array_alloct_dist_id_num_2(Idx)
   , g_rec_lines.array_alloct_dist_id_num_3(Idx)
   , g_rec_lines.array_alloct_dist_id_num_4(Idx)
   , g_rec_lines.array_alloct_dist_id_num_5(Idx)
   , g_rec_lines.array_alloct_dist_id_char_1(Idx)
   , g_rec_lines.array_alloct_dist_id_char_2(Idx)
   , g_rec_lines.array_alloct_dist_id_char_3(Idx)
   , g_rec_lines.array_alloct_dist_id_char_4(Idx)
   , g_rec_lines.array_alloct_dist_id_char_5(Idx)
   )
  ;
Line: 3726

      (p_msg      => '# temporary journal lines inserted into GT xla_ae_lines_gt = '||TO_CHAR(l_rowcount)
      ,p_level    => C_LEVEL_EVENT
      ,p_module   => l_log_module);
Line: 3736

    INSERT INTO xla_transaction_accts_gt
       (line_number,
        ae_header_id,
        temp_line_num,
        ledger_id,
        code_combination_id,
        segment,
        from_segment_code,
        to_segment_code,
        processing_status_code,
        side_code,
        sl_coa_mapping_id
       )
    VALUES
       (g_transaction_accounts.array_line_num(Jdx),
        g_transaction_accounts.array_ae_header_id(Jdx),
        g_transaction_accounts.array_temp_line_num(Jdx),
        XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id,
        g_transaction_accounts.array_code_combination_id(Jdx),
        g_transaction_accounts.array_segment(Jdx),
        g_transaction_accounts.array_from_segment_code(Jdx),
        g_transaction_accounts.array_to_segment_code(Jdx),
        g_transaction_accounts.array_processing_status_code(Jdx),
        g_transaction_accounts.array_side_code(Jdx),
        XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.sl_coa_mapping_id
  )
  ;
Line: 3768

         (p_msg      => '# lines inserted into xla_transaction_accts_gt = '||TO_CHAR(l_rowcount)
         ,p_level    => C_LEVEL_EVENT
         ,p_module   => l_log_module);
Line: 3778

         (p_msg      => 'No rows to insert into xla_transaction_accts_gt'
         ,p_level    => C_LEVEL_EVENT
         ,p_module   => l_log_module);
Line: 3786

         (p_msg      => 'END of InsertLines'
         ,p_level    => C_LEVEL_PROCEDURE
         ,p_module   => l_log_module);
Line: 3824

      (p_location => 'XLA_AE_LINES_PKG.InsertLines');
Line: 3825

END InsertLines;
Line: 4245

   SELECT event_id
         ,ledger_id
         ,event_number
         ,entity_id
         ,source_distribution_type
         ,source_distribution_id_num_1
         ,source_distribution_id_num_2
         ,source_distribution_id_num_3
         ,source_distribution_id_num_4
         ,source_distribution_id_num_5
         ,source_distribution_id_char_1
         ,source_distribution_id_char_2
         ,source_distribution_id_char_3
         ,source_distribution_id_char_4
         ,source_distribution_id_char_5
         ,reverse_distribution_type
         ,reverse_dist_id_num_1
         ,reverse_dist_id_num_2
         ,reverse_dist_id_num_3
         ,reverse_dist_id_num_4
         ,reverse_dist_id_num_5
         ,reverse_dist_id_char_1
         ,reverse_dist_id_char_2
         ,reverse_dist_id_char_3
         ,reverse_dist_id_char_4
         ,reverse_dist_id_char_5
         ,switch_side_flag        -- 5055878
         ,accounting_date         -- 5189664
         ,tax_line_ref_id            -- 7159711
         ,tax_summary_line_ref_id    -- 7159711
         ,tax_rec_nrec_dist_ref_id   -- 7159711
     BULK COLLECT INTO
          l_array_event_id
         ,l_array_ledger_id
         ,l_array_event_number
         ,l_array_entity_id
         ,l_array_source_dist_type
         ,l_array_source_dist_id_num_1
         ,l_array_source_dist_id_num_2
         ,l_array_source_dist_id_num_3
         ,l_array_source_dist_id_num_4
         ,l_array_source_dist_id_num_5
         ,l_array_source_dist_id_char_1
         ,l_array_source_dist_id_char_2
         ,l_array_source_dist_id_char_3
         ,l_array_source_dist_id_char_4
         ,l_array_source_dist_id_char_5
         ,l_array_rev_dist_type
         ,l_array_rev_dist_id_num_1
         ,l_array_rev_dist_id_num_2
         ,l_array_rev_dist_id_num_3
         ,l_array_rev_dist_id_num_4
         ,l_array_rev_dist_id_num_5
         ,l_array_rev_dist_id_char_1
         ,l_array_rev_dist_id_char_2
         ,l_array_rev_dist_id_char_3
         ,l_array_rev_dist_id_char_4
         ,l_array_rev_dist_id_char_5
         ,l_array_switch_side_flag     -- 5055878
         ,l_array_gl_date              -- 5189664
         ,l_array_tax_line_ref           -- 7159711
         ,l_array_tax_summary_line_ref   -- 7159711
         ,l_array_tax_rec_nrec_dist_ref  -- 7159711
     FROM xla_ae_lines_gt
    WHERE reversal_code = 'DUMMY_LR'
    ORDER by entity_id, event_number;
Line: 4330

         SELECT /*+ Leading(HGT) cardinality(hgt 1) index(lgt XLA_AE_LINES_GT_U1) */
                lgt.ledger_id
               ,lgt.event_id
               ,lgt.ref_ae_header_id
               ,lgt.temp_line_num
               ,lgt.ae_header_id
               ,lgt.header_num
               ,lgt.balance_type_code
         BULK COLLECT INTO
                l_array_mpa_acc_ledger_id
               ,l_array_mpa_acc_event_id
               ,l_array_mpa_acc_ref_ae_header
               ,l_array_mpa_acc_temp_line_num
               ,l_array_mpa_acc_ae_header_id
               ,l_array_mpa_acc_header_num
               ,l_array_mpa_acc_balance_type
         FROM   xla_ae_lines_gt   lgt
               ,xla_ae_headers_gt hgt
         WHERE l_array_ledger_id(i)                   = lgt.ledger_id
           AND l_array_rev_dist_type(i)               = lgt.source_distribution_type
           AND nvl(l_array_rev_dist_id_num_1(i),-99)  = nvl(lgt.source_distribution_id_num_1,-99)
           AND nvl(l_array_rev_dist_id_num_2(i),-99)  = nvl(lgt.source_distribution_id_num_2,-99)
           AND nvl(l_array_rev_dist_id_num_3(i),-99)  = nvl(lgt.source_distribution_id_num_3,-99)
           AND nvl(l_array_rev_dist_id_num_4(i),-99)  = nvl(lgt.source_distribution_id_num_4,-99)
           AND nvl(l_array_rev_dist_id_num_5(i),-99)  = nvl(lgt.source_distribution_id_num_5,-99)
           AND nvl(l_array_rev_dist_id_char_1(i),' ') = nvl(lgt.source_distribution_id_char_1,' ')
           AND nvl(l_array_rev_dist_id_char_2(i),' ') = nvl(lgt.source_distribution_id_char_2,' ')
           AND nvl(l_array_rev_dist_id_char_3(i),' ') = nvl(lgt.source_distribution_id_char_3,' ')
           AND nvl(l_array_rev_dist_id_char_4(i),' ') = nvl(lgt.source_distribution_id_char_4,' ')
           AND nvl(l_array_rev_dist_id_char_5(i),' ') = nvl(lgt.source_distribution_id_char_5,' ')
           AND lgt.reversal_code IS NULL        -- the lines created form revesal are not reversed again
            -- 5412560 replacement
           AND NVL(lgt.header_num,0) > 0
           AND lgt.header_num          = hgt.header_num
           AND hgt.event_id            = lgt.event_id
           AND hgt.ledger_id           = lgt.ledger_id
           AND hgt.balance_type_code   = lgt.balance_type_code
           AND hgt.ae_header_id        = lgt.ae_header_id
           AND hgt.entity_id           = l_array_entity_id(i)
           AND hgt.event_number        < l_array_event_number(i);
Line: 4372

                      SELECT 1
                      FROM xla_ae_lines_gt
                      WHERE ledger_id        = lgt.ledger_id
                        AND ref_ae_header_id = lgt.ref_ae_header_id
                        AND temp_line_num    = lgt.temp_line_num * -1)
           AND NVL(lgt.header_num,0) > 0
           AND lgt.header_num          = hgt.header_num
           AND hgt.event_id            = lgt.event_id
           AND hgt.ledger_id           = lgt.ledger_id
           AND hgt.balance_type_code   = lgt.balance_type_code
           AND hgt.entity_id           = l_array_entity_id(i)
           AND hgt.event_number        < l_array_event_number(i);
Line: 4407

            DELETE xla_ae_lines_gt
            WHERE  ledger_id        = l_array_mpa_acc_ledger_id(j)
            AND    ref_ae_header_id = l_array_mpa_acc_ref_ae_header(j)
            AND    temp_line_num    = l_array_mpa_acc_temp_line_num(j)
            AND    ae_header_id     = l_array_mpa_acc_ae_header_id(j)
            AND    header_num       = l_array_mpa_acc_header_num(j);
Line: 4418

            DELETE xla_ae_headers_gt
            WHERE  ledger_id         = l_array_mpa_acc_ledger_id(j)
            AND    event_id          = l_array_mpa_acc_event_id(j)
            AND    ae_header_id      = l_array_mpa_acc_ae_header_id(j)
            AND    balance_type_code = l_array_mpa_acc_balance_type(j)
            AND    header_num        = l_array_mpa_acc_header_num(j);
Line: 4433

   INSERT INTO xla_ae_lines_gt
      (ae_header_id
      ,temp_line_num
      ,event_id
      ,ref_ae_header_id
      ,ref_ae_line_num
      ,ref_temp_line_num
      ,ref_event_id
      ,ledger_id
      ,balance_type_code
      ,accounting_class_code
      ,event_class_code
      ,event_type_code
      ,line_definition_owner_code
      ,line_definition_code
      ,accounting_line_type_code
      ,accounting_line_code
      ,code_combination_status_code
      ,code_combination_id
      ,sl_coa_mapping_name
      ,dynamic_insert_flag
      ,source_coa_id
      ,ccid_coa_id
      ,calculate_acctd_amts_flag
      ,calculate_g_l_amts_flag
      ,gain_or_loss_flag
      ,rounding_class_code
      ,document_rounding_level
      ,DOC_ROUNDING_ACCTD_AMT
      ,DOC_ROUNDING_ENTERED_AMT
      ,alt_ccid_status_code
      ,alt_code_combination_id
      ,alt_segment1
      ,alt_segment2
      ,alt_segment3
      ,alt_segment4
      ,alt_segment5
      ,alt_segment6
      ,alt_segment7
      ,alt_segment8
      ,alt_segment9
      ,alt_segment10
      ,alt_segment11
      ,alt_segment12
      ,alt_segment13
      ,alt_segment14
      ,alt_segment15
      ,alt_segment16
      ,alt_segment17
      ,alt_segment18
      ,alt_segment19
      ,alt_segment20
      ,alt_segment21
      ,alt_segment22
      ,alt_segment23
      ,alt_segment24
      ,alt_segment25
      ,alt_segment26
      ,alt_segment27
      ,alt_segment28
      ,alt_segment29
      ,alt_segment30
      ,segment1
      ,segment2
      ,segment3
      ,segment4
      ,segment5
      ,segment6
      ,segment7
      ,segment8
      ,segment9
      ,segment10
      ,segment11
      ,segment12
      ,segment13
      ,segment14
      ,segment15
      ,segment16
      ,segment17
      ,segment18
      ,segment19
      ,segment20
      ,segment21
      ,segment22
      ,segment23
      ,segment24
      ,segment25
      ,segment26
      ,segment27
      ,segment28
      ,segment29
      ,segment30
      ,description
      ,gl_transfer_mode_code
      ,merge_duplicate_code
      ,switch_side_flag
      ,unrounded_entered_dr
      ,unrounded_entered_cr
      ,unrounded_accounted_dr
      ,unrounded_accounted_cr
      ,entered_currency_mau
      ,currency_code
      ,currency_conversion_date
      ,currency_conversion_rate
      ,currency_conversion_type
      ,statistical_amount
      ,party_id
      ,party_site_id
      ,party_type_code
      ,ussgl_transaction_code
      ,jgzz_recon_ref
      ,source_distribution_id_char_1
      ,source_distribution_id_char_2
      ,source_distribution_id_char_3
      ,source_distribution_id_char_4
      ,source_distribution_id_char_5
      ,source_distribution_id_num_1
      ,source_distribution_id_num_2
      ,source_distribution_id_num_3
      ,source_distribution_id_num_4
      ,source_distribution_id_num_5
      ,source_distribution_type
      ,reverse_dist_id_char_1
      ,reverse_dist_id_char_2
      ,reverse_dist_id_char_3
      ,reverse_dist_id_char_4
      ,reverse_dist_id_char_5
      ,reverse_dist_id_num_1
      ,reverse_dist_id_num_2
      ,reverse_dist_id_num_3
      ,reverse_dist_id_num_4
      ,reverse_dist_id_num_5
      ,reverse_distribution_type
      ,tax_line_ref_id
      ,tax_summary_line_ref_id
      ,tax_rec_nrec_dist_ref_id
      -- 4262811
      ,header_num
      ,mpa_accrual_entry_flag
      ,multiperiod_option_flag
      ,multiperiod_start_date
      ,multiperiod_end_date
      ,reversal_code
      ,inherit_desc_flag              -- 4219869
      ,encumbrance_type_id            -- 4458381
      ,accounting_entry_status_code
      ,accounting_date
      , BFLOW_APPLICATION_ID
        , BFLOW_ENTITY_CODE
        , APPLIED_TO_ENTITY_ID
        , BFLOW_SOURCE_ID_NUM_1
        , BFLOW_SOURCE_ID_NUM_2
        , BFLOW_SOURCE_ID_NUM_3
        , BFLOW_SOURCE_ID_NUM_4
        , BFLOW_SOURCE_ID_CHAR_1
        , BFLOW_SOURCE_ID_CHAR_2
        , BFLOW_SOURCE_ID_CHAR_3
        , BFLOW_SOURCE_ID_CHAR_4
        , BFLOW_DISTRIBUTION_TYPE
        , BFLOW_DIST_ID_NUM_1
        , BFLOW_DIST_ID_NUM_2
        , BFLOW_DIST_ID_NUM_3
        , BFLOW_DIST_ID_NUM_4
        , BFLOW_DIST_ID_NUM_5
        , BFLOW_DIST_ID_CHAR_1
        , BFLOW_DIST_ID_CHAR_2
        , BFLOW_DIST_ID_CHAR_3
        , BFLOW_DIST_ID_CHAR_4
        , BFLOW_DIST_ID_CHAR_5
 , alloc_to_application_id
 , alloc_to_entity_code
 , alloc_to_source_id_num_1
 , alloc_to_source_id_num_2
 , alloc_to_source_id_num_3
 , alloc_to_source_id_num_4
 , alloc_to_source_id_char_1
 , alloc_to_source_id_char_2
 , alloc_to_source_id_char_3
 , alloc_to_source_id_char_4
 , alloc_to_distribution_type
 , alloc_to_dist_id_char_1
 , alloc_to_dist_id_char_2
 , alloc_to_dist_id_char_3
 , alloc_to_dist_id_char_4
 , alloc_to_dist_id_char_5
 , alloc_to_dist_id_num_1
 , alloc_to_dist_id_num_2
 , alloc_to_dist_id_num_3
 , alloc_to_dist_id_num_4
 , alloc_to_dist_id_num_5    -- 4955764
  , analytical_balance_flag  -- Bug 7382288
 , anc_id_1
 , anc_id_2
 , anc_id_3
 , anc_id_4
 , anc_id_5
 , anc_id_6
 , anc_id_7
 , anc_id_8
 , anc_id_9
 , anc_id_10
 , anc_id_11
 , anc_id_12
 , anc_id_13
 , anc_id_14
 , anc_id_15
 , anc_id_16
 , anc_id_17
 , anc_id_18
 , anc_id_19
 , anc_id_20
 , anc_id_21
 , anc_id_22
 , anc_id_23
 , anc_id_24
 , anc_id_25
 , anc_id_26
 , anc_id_27
 , anc_id_28
 , anc_id_29
 , anc_id_30
 , anc_id_31
 , anc_id_32
 , anc_id_33
 , anc_id_34
 , anc_id_35
 , anc_id_36
 , anc_id_37
 , anc_id_38
 , anc_id_39
 , anc_id_40
 , anc_id_41
 , anc_id_42
 , anc_id_43
 , anc_id_44
 , anc_id_45
 , anc_id_46
 , anc_id_47
 , anc_id_48
 , anc_id_49
 , anc_id_50
 , anc_id_51
 , anc_id_52
 , anc_id_53
 , anc_id_54
 , anc_id_55
 , anc_id_56
 , anc_id_57
 , anc_id_58
 , anc_id_59
 , anc_id_60
 , anc_id_61
 , anc_id_62
 , anc_id_63
 , anc_id_64
 , anc_id_65
 , anc_id_66
 , anc_id_67
 , anc_id_68
 , anc_id_69
 , anc_id_70
 , anc_id_71
 , anc_id_72
 , anc_id_73
 , anc_id_74
 , anc_id_75
 , anc_id_76
 , anc_id_77
 , anc_id_78
 , anc_id_79
 , anc_id_80
 , anc_id_81
 , anc_id_82
 , anc_id_83
 , anc_id_84
 , anc_id_85
 , anc_id_86
 , anc_id_87
 , anc_id_88
 , anc_id_89
 , anc_id_90
 , anc_id_91
 , anc_id_92
 , anc_id_93
 , anc_id_94
 , anc_id_95
 , anc_id_96
 , anc_id_97
 , anc_id_98
 , anc_id_99
 , anc_id_100)
  (SELECT
       ae_header_id
      ,temp_line_num
      ,event_id
      ,ref_ae_header_id
      ,ref_ae_line_num
      ,ref_temp_line_num
      ,ref_event_id
      ,ledger_id
      ,balance_type_code
      ,accounting_class_code
      ,event_class_code
      ,event_type_code
      ,line_definition_owner_code
      ,line_definition_code
      ,accounting_line_type_code
      ,accounting_line_code
      ,code_combination_status_code
      ,code_combination_id
      ,sl_coa_mapping_name
      ,dynamic_insert_flag
      ,source_coa_id
      ,ccid_coa_id
      ,calculate_acctd_amts_flag
      ,calculate_g_l_amts_flag
      ,gain_or_loss_flag
      ,rounding_class_code
      ,document_rounding_level
      ,doc_rounding_acctd_amt
      ,doc_rounding_entered_amt
      ,alt_ccid_status_code
      ,alt_code_combination_id
      ,alt_segment1
      ,alt_segment2
      ,alt_segment3
      ,alt_segment4
      ,alt_segment5
      ,alt_segment6
      ,alt_segment7
      ,alt_segment8
      ,alt_segment9
      ,alt_segment10
      ,alt_segment11
      ,alt_segment12
      ,alt_segment13
      ,alt_segment14
      ,alt_segment15
      ,alt_segment16
      ,alt_segment17
      ,alt_segment18
      ,alt_segment19
      ,alt_segment20
      ,alt_segment21
      ,alt_segment22
      ,alt_segment23
      ,alt_segment24
      ,alt_segment25
      ,alt_segment26
      ,alt_segment27
      ,alt_segment28
      ,alt_segment29
      ,alt_segment30
      ,segment1
      ,segment2
      ,segment3
      ,segment4
      ,segment5
      ,segment6
      ,segment7
      ,segment8
      ,segment9
      ,segment10
      ,segment11
      ,segment12
      ,segment13
      ,segment14
      ,segment15
      ,segment16
      ,segment17
      ,segment18
      ,segment19
      ,segment20
      ,segment21
      ,segment22
      ,segment23
      ,segment24
      ,segment25
      ,segment26
      ,segment27
      ,segment28
      ,segment29
      ,segment30
      ,description
      ,gl_transfer_mode_code
      ,merge_duplicate_code
      ,switch_side_flag
      ,unrounded_entered_dr
      ,unrounded_entered_cr
      ,unrounded_accounted_dr
      ,unrounded_accounted_cr
      ,entered_currency_mau
      ,currency_code
      ,currency_conversion_date
      ,currency_conversion_rate
      ,currency_conversion_type
      ,statistical_amount
      ,party_id
      ,party_site_id
      ,party_type_code
      ,ussgl_transaction_code
      ,jgzz_recon_ref
      ,source_distribution_id_char_1
      ,source_distribution_id_char_2
      ,source_distribution_id_char_3
      ,source_distribution_id_char_4
      ,source_distribution_id_char_5
      ,source_distribution_id_num_1
      ,source_distribution_id_num_2
      ,source_distribution_id_num_3
      ,source_distribution_id_num_4
      ,source_distribution_id_num_5
      ,source_distribution_type
      ,reverse_dist_id_char_1
      ,reverse_dist_id_char_2
      ,reverse_dist_id_char_3
      ,reverse_dist_id_char_4
      ,reverse_dist_id_char_5
      ,reverse_dist_id_num_1
      ,reverse_dist_id_num_2
      ,reverse_dist_id_num_3
      ,reverse_dist_id_num_4
      ,reverse_dist_id_num_5
      ,reverse_distribution_type
      ,tax_line_ref_id
      ,tax_summary_line_ref_id
      ,tax_rec_nrec_dist_ref_id
      ,header_num
      ,mpa_accrual_entry_flag
      ,multiperiod_option_flag
      ,multiperiod_start_date
      ,multiperiod_end_date
      ,reversal_code
      ,inherit_desc_flag
      ,encumbrance_type_id
      ,accounting_entry_status_code
      ,accounting_date
 , BFLOW_APPLICATION_ID
        , BFLOW_ENTITY_CODE
        , APPLIED_TO_ENTITY_ID
        , BFLOW_SOURCE_ID_NUM_1
        , BFLOW_SOURCE_ID_NUM_2
        , BFLOW_SOURCE_ID_NUM_3
        , BFLOW_SOURCE_ID_NUM_4
        , BFLOW_SOURCE_ID_CHAR_1
        , BFLOW_SOURCE_ID_CHAR_2
        , BFLOW_SOURCE_ID_CHAR_3
        , BFLOW_SOURCE_ID_CHAR_4
        , BFLOW_DISTRIBUTION_TYPE
        , BFLOW_DIST_ID_NUM_1
        , BFLOW_DIST_ID_NUM_2
        , BFLOW_DIST_ID_NUM_3
        , BFLOW_DIST_ID_NUM_4
        , BFLOW_DIST_ID_NUM_5
        , BFLOW_DIST_ID_CHAR_1
        , BFLOW_DIST_ID_CHAR_2
        , BFLOW_DIST_ID_CHAR_3
        , BFLOW_DIST_ID_CHAR_4
        , BFLOW_DIST_ID_CHAR_5
 , alloc_to_application_id
 , alloc_to_entity_code
 , alloc_to_source_id_num_1
 , alloc_to_source_id_num_2
 , alloc_to_source_id_num_3
 , alloc_to_source_id_num_4
 , alloc_to_source_id_char_1
 , alloc_to_source_id_char_2
 , alloc_to_source_id_char_3
 , alloc_to_source_id_char_4
 , alloc_to_distribution_type
 , alloc_to_dist_id_char_1
 , alloc_to_dist_id_char_2
 , alloc_to_dist_id_char_3
 , alloc_to_dist_id_char_4
 , alloc_to_dist_id_char_5
 , alloc_to_dist_id_num_1
 , alloc_to_dist_id_num_2
 , alloc_to_dist_id_num_3
 , alloc_to_dist_id_num_4
 , alloc_to_dist_id_num_5
 , analytical_balance_flag  -- Bug 7382288 Included analytical criteria
 , anc_id_1
 , anc_id_2
 , anc_id_3
 , anc_id_4
 , anc_id_5
 , anc_id_6
 , anc_id_7
 , anc_id_8
 , anc_id_9
 , anc_id_10
 , anc_id_11
 , anc_id_12
 , anc_id_13
 , anc_id_14
 , anc_id_15
 , anc_id_16
 , anc_id_17
 , anc_id_18
 , anc_id_19
 , anc_id_20
 , anc_id_21
 , anc_id_22
 , anc_id_23
 , anc_id_24
 , anc_id_25
 , anc_id_26
 , anc_id_27
 , anc_id_28
 , anc_id_29
 , anc_id_30
 , anc_id_31
 , anc_id_32
 , anc_id_33
 , anc_id_34
 , anc_id_35
 , anc_id_36
 , anc_id_37
 , anc_id_38
 , anc_id_39
 , anc_id_40
 , anc_id_41
 , anc_id_42
 , anc_id_43
 , anc_id_44
 , anc_id_45
 , anc_id_46
 , anc_id_47
 , anc_id_48
 , anc_id_49
 , anc_id_50
 , anc_id_51
 , anc_id_52
 , anc_id_53
 , anc_id_54
 , anc_id_55
 , anc_id_56
 , anc_id_57
 , anc_id_58
 , anc_id_59
 , anc_id_60
 , anc_id_61
 , anc_id_62
 , anc_id_63
 , anc_id_64
 , anc_id_65
 , anc_id_66
 , anc_id_67
 , anc_id_68
 , anc_id_69
 , anc_id_70
 , anc_id_71
 , anc_id_72
 , anc_id_73
 , anc_id_74
 , anc_id_75
 , anc_id_76
 , anc_id_77
 , anc_id_78
 , anc_id_79
 , anc_id_80
 , anc_id_81
 , anc_id_82
 , anc_id_83
 , anc_id_84
 , anc_id_85
 , anc_id_86
 , anc_id_87
 , anc_id_88
 , anc_id_89
 , anc_id_90
 , anc_id_91
 , anc_id_92
 , anc_id_93
 , anc_id_94
 , anc_id_95
 , anc_id_96
 , anc_id_97
 , anc_id_98
 , anc_id_99
 , anc_id_100
    FROM
     (SELECT /*+ ORDERED USE_HASH(lgt2) USE_NL(hgt) */
         -- populates ae_header_id which is same as event_id till this point
          lgt1.event_id                                AE_HEADER_ID
         -- populates temp_line_num which is (-ve) of original line
         ,0-lgt2.temp_line_num                         TEMP_LINE_NUM
         -- populates event_id which is the event_id of event under process
         ,lgt1.event_id                                EVENT_ID
         -- populates ref_ae_header_id which is ae_header_id of original line
         ,hgt.ae_header_id                             REF_AE_HEADER_ID
         -- populates ref_ae_line_num which is ae_line_num of original line
         ,lgt2.ae_line_num                             REF_AE_LINE_NUM
         -- populates ref_temp_line_num which is ae_line_num of original line
         ,lgt2.temp_line_num                           REF_TEMP_LINE_NUM
         -- populates ref_event_id which is event_id of original line
         ,lgt2.event_id                                REF_EVENT_ID
         ,lgt2.ledger_id                               LEDGER_ID
         ,lgt2.balance_type_code                       BALANCE_TYPE_CODE
         ,lgt2.accounting_class_code                   ACCOUNTING_CLASS_CODE
         ,lgt2.event_class_code                        EVENT_CLASS_CODE
         ,lgt2.event_type_code                         EVENT_TYPE_CODE
         ,lgt2.line_definition_owner_code              LINE_DEFINITION_OWNER_CODE
         ,lgt2.line_definition_code                    LINE_DEFINITION_CODE
         ,lgt2.accounting_line_type_code               ACCOUNTING_LINE_TYPE_CODE
         ,lgt2.accounting_line_code                    ACCOUNTING_LINE_CODE
                  ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y'
                ,lgt2.alt_ccid_status_code,lgt2.code_combination_status_code)
         ,lgt2.code_combination_status_code)
                                                       CODE_COMBINATION_STATUS_CODE
         ,decode(lgt2.gain_or_loss_flag, 'Y'
            ,decode(lgt2.calculate_g_l_amts_flag,'Y'
                ,lgt2.alt_code_combination_id, lgt2.code_combination_id)
        , lgt2.code_combination_id)
                                                       CODE_COMBINATION_ID
         ,lgt2.sl_coa_mapping_name                    SL_COA_MAPPING_NAME
         ,lgt2.dynamic_insert_flag                     DYNAMIC_INSERT_FLAG
         ,lgt2.source_coa_id                           SOURCE_COA_ID
         ,lgt2.ccid_coa_id                             CCID_COA_ID
         ,lgt2.calculate_acctd_amts_flag               CALCULATE_ACCTD_AMTS_FLAG
         ,lgt2.calculate_g_l_amts_flag                 CALCULATE_G_L_AMTS_FLAG
         ,lgt2.gain_or_loss_flag                       GAIN_OR_LOSS_FLAG
         ,lgt2.rounding_class_code                     ROUNDING_CLASS_CODE
         ,lgt2.document_rounding_level                 DOCUMENT_ROUNDING_LEVEL
         ,lgt2.doc_rounding_acctd_amt                  DOC_ROUNDING_ACCTD_AMT
         ,lgt2.doc_rounding_entered_amt                DOC_ROUNDING_ENTERED_AMT
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.code_combination_status_code ,lgt2.alt_ccid_status_code)
                                                       ALT_CCID_STATUS_CODE
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.code_combination_id ,lgt2.alt_code_combination_id)
                                                       ALT_CODE_COMBINATION_ID
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment1,lgt2.alt_segment1)     ALT_SEGMENT1
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment2,lgt2.alt_segment2)     ALT_SEGMENT2
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment3,lgt2.alt_segment3)     ALT_SEGMENT3
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment4,lgt2.alt_segment4)     ALT_SEGMENT4
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment5,lgt2.alt_segment5)     ALT_SEGMENT5
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment6,lgt2.alt_segment6)     ALT_SEGMENT6
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment7,lgt2.alt_segment7)     ALT_SEGMENT7
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment8,lgt2.alt_segment8)     ALT_SEGMENT8
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment9,lgt2.alt_segment9)     ALT_SEGMENT9
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment10,lgt2.alt_segment10)   ALT_SEGMENT10
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment11,lgt2.alt_segment11)   ALT_SEGMENT11
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment12,lgt2.alt_segment12)   ALT_SEGMENT12
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment13,lgt2.alt_segment13)   ALT_SEGMENT13
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment14,lgt2.alt_segment14)   ALT_SEGMENT14
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment15,lgt2.alt_segment15)   ALT_SEGMENT15
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment16,lgt2.alt_segment16)   ALT_SEGMENT16
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment17,lgt2.alt_segment17)   ALT_SEGMENT17
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment18,lgt2.alt_segment18)   ALT_SEGMENT18
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment19,lgt2.alt_segment19)   ALT_SEGMENT19
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment20,lgt2.alt_segment20)   ALT_SEGMENT20
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment21,lgt2.alt_segment21)   ALT_SEGMENT21
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment22,lgt2.alt_segment22)   ALT_SEGMENT22
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment23,lgt2.alt_segment23)   ALT_SEGMENT23
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment24,lgt2.alt_segment24)   ALT_SEGMENT24
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment25,lgt2.alt_segment25)   ALT_SEGMENT25
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment26,lgt2.alt_segment26)   ALT_SEGMENT26
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment27,lgt2.alt_segment27)   ALT_SEGMENT27
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment28,lgt2.alt_segment28)   ALT_SEGMENT28
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment29,lgt2.alt_segment29)   ALT_SEGMENT29
         ,decode(lgt2.gain_or_loss_flag, 'Y', lgt2.segment30,lgt2.alt_segment30)   ALT_SEGMENT30
         ,decode(lgt2.gain_or_loss_flag, 'Y'
         ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment1,lgt2.segment1)
         ,lgt2.segment1)                                                   SEGMENT1
         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment2,lgt2.segment2)
         ,lgt2.segment2)                                                   SEGMENT2

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment3,lgt2.segment3)
         ,lgt2.segment3)                                                   SEGMENT3

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment4,lgt2.segment4)
         ,lgt2.segment4)                                                     SEGMENT4

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment5,lgt2.segment5)
         ,lgt2.segment5)                                                   SEGMENT5

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment6,lgt2.segment6)
         ,lgt2.segment6)                                                   SEGMENT6

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment7,lgt2.segment7)
         ,lgt2.segment7)                                                  SEGMENT7

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment8,lgt2.segment8)
         ,lgt2.segment8)                                                   SEGMENT8

         ,decode(lgt2.gain_or_loss_flag, 'Y'
                ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment9,lgt2.segment9)
         ,lgt2.segment9)                                                   SEGMENT9

         ,decode(lgt2.gain_or_loss_flag, 'Y'
              ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment10,lgt2.segment10)
         ,lgt2.segment10)                                                   SEGMENT10

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment11,lgt2.segment11)
         ,lgt2.segment11)                                                   SEGMENT11

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment12,lgt2.segment12)
         ,lgt2.segment12)                                                   SEGMENT12

         ,decode(lgt2.gain_or_loss_flag, 'Y'
               ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment13,lgt2.segment13)
         ,lgt2.segment13)                                                   SEGMENT13

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment14,lgt2.segment14)
         ,lgt2.segment14)                                                   SEGMENT14

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment15,lgt2.segment15)
         ,lgt2.segment15)                                                   SEGMENT15

         ,decode(lgt2.gain_or_loss_flag, 'Y'
              ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment16,lgt2.segment16)
         ,lgt2.segment16)                                                   SEGMENT16

         ,decode(lgt2.gain_or_loss_flag, 'Y'
              ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment17,lgt2.segment17)
         ,lgt2.segment17)                                                   SEGMENT17

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment18,lgt2.segment18)
         ,lgt2.segment18)                                                   SEGMENT18

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment19,lgt2.segment19)
         ,lgt2.segment19)                                                   SEGMENT19

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment20,lgt2.segment20)
         ,lgt2.segment20)                                                  SEGMENT20

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment21,lgt2.segment21)
         ,lgt2.segment21)                                                   SEGMENT21

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment22,lgt2.segment22)
         ,lgt2.segment22)                                                   SEGMENT22

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment23,lgt2.segment23)
         ,lgt2.segment23)                                                   SEGMENT23

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment24,lgt2.segment24)
         ,lgt2.segment24)                                                   SEGMENT24

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment25,lgt2.segment25)
         ,lgt2.segment25)                                                   SEGMENT25

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment26,lgt2.segment26)
         ,lgt2.segment26)                                                   SEGMENT26

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment27,lgt2.segment27)
         ,lgt2.segment27)                                                   SEGMENT27

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment28,lgt2.segment28)
         ,lgt2.segment28)                                                  SEGMENT28

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment29,lgt2.segment29)
         ,lgt2.segment29)                                                   SEGMENT29

         ,decode(lgt2.gain_or_loss_flag, 'Y'
             ,decode(lgt2.calculate_g_l_amts_flag,'Y',lgt2.alt_segment30,lgt2.segment30)
         ,lgt2.segment30)                                                   SEGMENT30
         ,lgt2.description                             DESCRIPTION
         ,lgt2.gl_transfer_mode_code                   GL_TRANSFER_MODE_CODE
         ,lgt2.merge_duplicate_code                    MERGE_DUPLICATE_CODE
         ,decode(lgt2.gain_or_loss_flag, 'Y', decode(lgt2.calculate_g_l_amts_flag, 'Y', 'Y', 'N'), lgt1.switch_side_flag)
                                                       SWITCH_SIDE_FLAG -- bug:7337288 changed lgt2 to lgt1 for switch side flag
         -- 5055878 amounts modified for reversal method of SIDE or SIGN
         ,DECODE(lgt1.switch_side_flag,'Y',lgt2.unrounded_entered_cr,  -lgt2.unrounded_entered_dr)       UNROUNDED_ENTERED_DR
         ,DECODE(lgt1.switch_side_flag,'Y',lgt2.unrounded_entered_dr,  -lgt2.unrounded_entered_cr)       UNROUNDED_ENTERED_CR
         ,DECODE(lgt1.switch_side_flag,'Y',lgt2.unrounded_accounted_cr,-lgt2.unrounded_accounted_dr)     UNROUNDED_ACCOUNTED_DR
         ,DECODE(lgt1.switch_side_flag,'Y',lgt2.unrounded_accounted_dr,-lgt2.unrounded_accounted_cr)     UNROUNDED_ACCOUNTED_CR
         --
         ,lgt2.entered_currency_mau                    ENTERED_CURRENCY_MAU
         ,lgt2.currency_code                           CURRENCY_CODE
         ,lgt2.currency_conversion_date                CURRENCY_CONVERSION_DATE
         ,lgt2.currency_conversion_rate                CURRENCY_CONVERSION_RATE
         ,lgt2.currency_conversion_type                CURRENCY_CONVERSION_TYPE
         ,lgt2.statistical_amount                      STATISTICAL_AMOUNT
         ,lgt2.party_id                                PARTY_ID
         ,lgt2.party_site_id                           PARTY_SITE_ID
         ,lgt2.party_type_code                         PARTY_TYPE_CODE
         ,lgt2.ussgl_transaction_code                  USSGL_TRANSACTION_CODE
         ,lgt2.jgzz_recon_ref                          JGZZ_RECON_REF
         ,lgt1.source_distribution_id_char_1           SOURCE_DISTRIBUTION_ID_CHAR_1
         ,lgt1.source_distribution_id_char_2           SOURCE_DISTRIBUTION_ID_CHAR_2
         ,lgt1.source_distribution_id_char_3           SOURCE_DISTRIBUTION_ID_CHAR_3
         ,lgt1.source_distribution_id_char_4           SOURCE_DISTRIBUTION_ID_CHAR_4
         ,lgt1.source_distribution_id_char_5           SOURCE_DISTRIBUTION_ID_CHAR_5
         ,lgt1.source_distribution_id_num_1            SOURCE_DISTRIBUTION_ID_NUM_1
         ,lgt1.source_distribution_id_num_2            SOURCE_DISTRIBUTION_ID_NUM_2
         ,lgt1.source_distribution_id_num_3            SOURCE_DISTRIBUTION_ID_NUM_3
         ,lgt1.source_distribution_id_num_4            SOURCE_DISTRIBUTION_ID_NUM_4
         ,lgt1.source_distribution_id_num_5            SOURCE_DISTRIBUTION_ID_NUM_5
         ,lgt1.source_distribution_type                SOURCE_DISTRIBUTION_TYPE
         ,lgt2.source_distribution_id_char_1           REVERSE_DIST_ID_CHAR_1
         ,lgt2.source_distribution_id_char_2           REVERSE_DIST_ID_CHAR_2
         ,lgt2.source_distribution_id_char_3           REVERSE_DIST_ID_CHAR_3
         ,lgt2.source_distribution_id_char_4           REVERSE_DIST_ID_CHAR_4
         ,lgt2.source_distribution_id_char_5           REVERSE_DIST_ID_CHAR_5
         ,lgt2.source_distribution_id_num_1            REVERSE_DIST_ID_NUM_1
         ,lgt2.source_distribution_id_num_2            REVERSE_DIST_ID_NUM_2
         ,lgt2.source_distribution_id_num_3            REVERSE_DIST_ID_NUM_3
         ,lgt2.source_distribution_id_num_4            REVERSE_DIST_ID_NUM_4
         ,lgt2.source_distribution_id_num_5            REVERSE_DIST_ID_NUM_5
         ,lgt2.source_distribution_type                REVERSE_DISTRIBUTION_TYPE
         ,nvl(lgt1.tax_line_ref_id,lgt2.tax_line_ref_id)                   TAX_LINE_REF_ID          -- bug 7159711
         ,nvl(lgt1.tax_summary_line_ref_id,lgt2.tax_summary_line_ref_id)   TAX_SUMMARY_LINE_REF_ID  -- bug 7159711
         ,nvl(lgt1.tax_rec_nrec_dist_ref_id,lgt2.tax_rec_nrec_dist_ref_id) TAX_REC_NREC_DIST_REF_ID -- bug 7159711
         ,NVL(lgt2.header_num,0)                       HEADER_NUM
         ,lgt2.mpa_accrual_entry_flag                  MPA_ACCRUAL_ENTRY_FLAG
         ,lgt2.multiperiod_option_flag                 MULTIPERIOD_OPTION_FLAG
         ,lgt2.multiperiod_start_date                  MULTIPERIOD_START_DATE
         ,lgt2.multiperiod_end_date                    MULTIPERIOD_END_DATE
         -- populate reversal_code indicating that line is result of reversal
         ,'REVERSAL'                                   REVERSAL_CODE
         ,'N'                                          INHERIT_DESC_FLAG
         ,lgt2.encumbrance_type_id                     ENCUMBRANCE_TYPE_ID
         -- denormalises entry status from headers to line to determine the status of entry being created
         ,hgt.accounting_entry_status_code             ACCOUNTING_ENTRY_STATUS_CODE
         ,lgt1.accounting_date                         ACCOUNTING_DATE
         -- the following assigns duplicate rownum to reversal lines created from same
         -- original line. This is used to filter duplicate rows in the outer query.
         ,row_number() over
              (partition by lgt2.ref_ae_header_Id, lgt2.ledger_id,lgt2.temp_line_num
                   order by lgt1.event_number
              ) rn
 , lgt2.BFLOW_APPLICATION_ID
        , lgt2.BFLOW_ENTITY_CODE
        , lgt2.APPLIED_TO_ENTITY_ID
        , lgt2.BFLOW_SOURCE_ID_NUM_1
        , lgt2.BFLOW_SOURCE_ID_NUM_2
        , lgt2.BFLOW_SOURCE_ID_NUM_3
        , lgt2.BFLOW_SOURCE_ID_NUM_4
        , lgt2.BFLOW_SOURCE_ID_CHAR_1
        , lgt2.BFLOW_SOURCE_ID_CHAR_2
        , lgt2.BFLOW_SOURCE_ID_CHAR_3
        , lgt2.BFLOW_SOURCE_ID_CHAR_4
        , lgt2.BFLOW_DISTRIBUTION_TYPE
        , lgt2.BFLOW_DIST_ID_NUM_1
        , lgt2.BFLOW_DIST_ID_NUM_2
        , lgt2.BFLOW_DIST_ID_NUM_3
        , lgt2.BFLOW_DIST_ID_NUM_4
        , lgt2.BFLOW_DIST_ID_NUM_5
        , lgt2.BFLOW_DIST_ID_CHAR_1
        , lgt2.BFLOW_DIST_ID_CHAR_2
        , lgt2.BFLOW_DIST_ID_CHAR_3
        , lgt2.BFLOW_DIST_ID_CHAR_4
        , lgt2.BFLOW_DIST_ID_CHAR_5
 , lgt2.alloc_to_application_id     alloc_to_application_id
 , lgt2.alloc_to_entity_code        alloc_to_entity_code
 , lgt2.alloc_to_source_id_num_1        alloc_to_source_id_num_1
 , lgt2.alloc_to_source_id_num_2        alloc_to_source_id_num_2
 , lgt2.alloc_to_source_id_num_3        alloc_to_source_id_num_3
 , lgt2.alloc_to_source_id_num_4        alloc_to_source_id_num_4
 , lgt2.alloc_to_source_id_char_1   alloc_to_source_id_char_1
 , lgt2.alloc_to_source_id_char_2   alloc_to_source_id_char_2
 , lgt2.alloc_to_source_id_char_3   alloc_to_source_id_char_3
 , lgt2.alloc_to_source_id_char_4   alloc_to_source_id_char_4
 , lgt2.alloc_to_distribution_type  alloc_to_distribution_type
 , lgt2.alloc_to_dist_id_char_1     alloc_to_dist_id_char_1
 , lgt2.alloc_to_dist_id_char_2     alloc_to_dist_id_char_2
 , lgt2.alloc_to_dist_id_char_3     alloc_to_dist_id_char_3
 , lgt2.alloc_to_dist_id_char_4     alloc_to_dist_id_char_4
 , lgt2.alloc_to_dist_id_char_5     alloc_to_dist_id_char_5
 , lgt2.alloc_to_dist_id_num_1      alloc_to_dist_id_num_1
 , lgt2.alloc_to_dist_id_num_2      alloc_to_dist_id_num_2
 , lgt2.alloc_to_dist_id_num_3      alloc_to_dist_id_num_3
 , lgt2.alloc_to_dist_id_num_4      alloc_to_dist_id_num_4
 , lgt2.alloc_to_dist_id_num_5      alloc_to_dist_id_num_5
 , lgt2.analytical_balance_flag -- Bug 7382288- Included analytical criteria
 , lgt2.anc_id_1
 , lgt2.anc_id_2
 , lgt2.anc_id_3
 , lgt2.anc_id_4
 , lgt2.anc_id_5
 , lgt2.anc_id_6
 , lgt2.anc_id_7
 , lgt2.anc_id_8
 , lgt2.anc_id_9
 , lgt2.anc_id_10
 , lgt2.anc_id_11
 , lgt2.anc_id_12
 , lgt2.anc_id_13
 , lgt2.anc_id_14
 , lgt2.anc_id_15
 , lgt2.anc_id_16
 , lgt2.anc_id_17
 , lgt2.anc_id_18
 , lgt2.anc_id_19
 , lgt2.anc_id_20
 , lgt2.anc_id_21
 , lgt2.anc_id_22
 , lgt2.anc_id_23
 , lgt2.anc_id_24
 , lgt2.anc_id_25
 , lgt2.anc_id_26
 , lgt2.anc_id_27
 , lgt2.anc_id_28
 , lgt2.anc_id_29
 , lgt2.anc_id_30
 , lgt2.anc_id_31
 , lgt2.anc_id_32
 , lgt2.anc_id_33
 , lgt2.anc_id_34
 , lgt2.anc_id_35
 , lgt2.anc_id_36
 , lgt2.anc_id_37
 , lgt2.anc_id_38
 , lgt2.anc_id_39
 , lgt2.anc_id_40
 , lgt2.anc_id_41
 , lgt2.anc_id_42
 , lgt2.anc_id_43
 , lgt2.anc_id_44
 , lgt2.anc_id_45
 , lgt2.anc_id_46
 , lgt2.anc_id_47
 , lgt2.anc_id_48
 , lgt2.anc_id_49
 , lgt2.anc_id_50
 , lgt2.anc_id_51
 , lgt2.anc_id_52
 , lgt2.anc_id_53
 , lgt2.anc_id_54
 , lgt2.anc_id_55
 , lgt2.anc_id_56
 , lgt2.anc_id_57
 , lgt2.anc_id_58
 , lgt2.anc_id_59
 , lgt2.anc_id_60
 , lgt2.anc_id_61
 , lgt2.anc_id_62
 , lgt2.anc_id_63
 , lgt2.anc_id_64
 , lgt2.anc_id_65
 , lgt2.anc_id_66
 , lgt2.anc_id_67
 , lgt2.anc_id_68
 , lgt2.anc_id_69
 , lgt2.anc_id_70
 , lgt2.anc_id_71
 , lgt2.anc_id_72
 , lgt2.anc_id_73
 , lgt2.anc_id_74
 , lgt2.anc_id_75
 , lgt2.anc_id_76
 , lgt2.anc_id_77
 , lgt2.anc_id_78
 , lgt2.anc_id_79
 , lgt2.anc_id_80
 , lgt2.anc_id_81
 , lgt2.anc_id_82
 , lgt2.anc_id_83
 , lgt2.anc_id_84
 , lgt2.anc_id_85
 , lgt2.anc_id_86
 , lgt2.anc_id_87
 , lgt2.anc_id_88
 , lgt2.anc_id_89
 , lgt2.anc_id_90
 , lgt2.anc_id_91
 , lgt2.anc_id_92
 , lgt2.anc_id_93
 , lgt2.anc_id_94
 , lgt2.anc_id_95
 , lgt2.anc_id_96
 , lgt2.anc_id_97
 , lgt2.anc_id_98
 , lgt2.anc_id_99
 , lgt2.anc_id_100
        FROM
          xla_ae_lines_gt     lgt1
         ,xla_ae_lines_gt     lgt2
         ,xla_ae_headers_gt   hgt
      WHERE lgt1.reversal_code                              = 'DUMMY_LR'
        AND lgt2.ledger_id                                  = lgt1.ledger_id
        AND lgt2.source_distribution_type                   = lgt1.reverse_distribution_type
        AND nvl(lgt2.source_distribution_id_num_1,-99)      = nvl(lgt1.reverse_dist_id_num_1,-99)
        AND nvl(lgt2.source_distribution_id_num_2,-99)      = nvl(lgt1.reverse_dist_id_num_2,-99)
        AND nvl(lgt2.source_distribution_id_num_3,-99)      = nvl(lgt1.reverse_dist_id_num_3,-99)
        AND nvl(lgt2.source_distribution_id_num_4,-99)      = nvl(lgt1.reverse_dist_id_num_4,-99)
        AND nvl(lgt2.source_distribution_id_num_5,-99)      = nvl(lgt1.reverse_dist_id_num_5,-99)
        AND nvl(lgt2.source_distribution_id_char_1,' ')     = nvl(lgt1.reverse_dist_id_char_1,' ')
        AND nvl(lgt2.source_distribution_id_char_2,' ')     = nvl(lgt1.reverse_dist_id_char_2,' ')
        AND nvl(lgt2.source_distribution_id_char_3,' ')     = nvl(lgt1.reverse_dist_id_char_3,' ')
        AND nvl(lgt2.source_distribution_id_char_4,' ')     = nvl(lgt1.reverse_dist_id_char_4,' ')
        AND nvl(lgt2.source_distribution_id_char_5,' ')     = nvl(lgt1.reverse_dist_id_char_5,' ')
        AND hgt.event_id            = lgt2.event_id
        AND hgt.ledger_id           = lgt2.ledger_id
        AND hgt.balance_type_code   = lgt2.balance_type_code
        AND hgt.entity_id           = lgt1.entity_id
        -- lines for events with event number > current event number are not reversed.
        AND hgt.event_number        < lgt1.event_number
        AND hgt.header_num          = lgt2.header_num-- 4262811c  Line Reversal (xla_ae_lines_gt_u1 error)
        AND hgt.ae_header_id        = lgt2.ae_header_id
     )
    WHERE rn = 1
  );
Line: 5463

      SELECT /*+ Leading(LGT,XDL)  use_nl(lgt xdl aeh ael)*/  -- 5262950
             ael.ae_header_id
            ,ael.ae_line_num
            ,aeh.parent_ae_header_id
      BULK COLLECT INTO
             g_incomplete_mpa_acc_LR.l_array_ae_header_id
            ,g_incomplete_mpa_acc_LR.l_array_ae_line_num
            ,g_incomplete_mpa_acc_LR.l_array_parent_ae_header
      FROM
           xla_ae_lines_gt           lgt
          ,xla_ae_lines              ael
          ,xla_ae_headers            aeh
          ,xla_distribution_links    xdl
      WHERE xdl.application_id                          = l_application_id
        AND xdl.source_distribution_type                = lgt.reverse_distribution_type
        AND lgt.reversal_code                           = 'DUMMY_LR'
        AND     xdl.source_distribution_id_num_1        =     lgt.reverse_dist_id_num_1       -- 5479652
        AND nvl(xdl.source_distribution_id_num_2,-99)   = nvl(lgt.reverse_dist_id_num_2,-99)
        AND nvl(xdl.source_distribution_id_num_3,-99)   = nvl(lgt.reverse_dist_id_num_3,-99)
        AND nvl(xdl.source_distribution_id_num_4,-99)   = nvl(lgt.reverse_dist_id_num_4,-99)
        AND nvl(xdl.source_distribution_id_num_5,-99)   = nvl(lgt.reverse_dist_id_num_5,-99)
        AND nvl(xdl.source_distribution_id_char_1,' ')  = nvl(lgt.reverse_dist_id_char_1,' ')
        AND nvl(xdl.source_distribution_id_char_2,' ')  = nvl(lgt.reverse_dist_id_char_2,' ')
        AND nvl(xdl.source_distribution_id_char_3,' ')  = nvl(lgt.reverse_dist_id_char_3,' ')
        AND nvl(xdl.source_distribution_id_char_4,' ')  = nvl(lgt.reverse_dist_id_char_4,' ')
        AND nvl(xdl.source_distribution_id_char_5,' ')  = nvl(lgt.reverse_dist_id_char_5,' ')
        AND aeh.application_id                          = xdl.application_id
        AND aeh.ae_header_id                            = xdl.ae_header_id
        AND aeh.ledger_id                               = lgt.ledger_id
        AND aeh.entity_id                               = lgt.entity_id
        AND ael.application_id                          = aeh.application_id
        AND ael.ae_header_id                            = aeh.ae_header_id
        AND ael.ae_line_num                             = xdl.ae_line_num
        AND aeh.parent_ae_header_id IS NOT NULL AND aeh.accounting_entry_status_code IN ('D','N','I','R','RELATED_EVENT_ERROR');  -- 5262950 incomplete MPA/AccRev
Line: 5526

   INSERT INTO xla_ae_lines_gt
      (ae_header_id
      ,temp_line_num
      ,event_id
      ,ref_ae_header_id
      ,ref_ae_line_num
      ,ref_temp_line_num
      ,ref_event_id
      ,ledger_id
      ,balance_type_code
      ,accounting_class_code
      ,event_class_code
      ,event_type_code
      ,line_definition_owner_code
      ,line_definition_code
      ,accounting_line_type_code
      ,accounting_line_code
      ,code_combination_status_code
      ,code_combination_id
      ,alt_ccid_status_code
      ,alt_code_combination_id
      ,description
      ,gl_transfer_mode_code
      ,merge_duplicate_code
      ,switch_side_flag  -- 5055878
      ,unrounded_entered_dr
      ,unrounded_entered_cr
      ,unrounded_accounted_dr
      ,unrounded_accounted_cr
      ,calculate_acctd_amts_flag
      ,calculate_g_l_amts_flag
      ,gain_or_loss_flag
      ,rounding_class_code
      ,document_rounding_level
      ,doc_rounding_acctd_amt
      ,doc_rounding_entered_amt
      ,entered_currency_mau
      ,currency_code
      ,currency_conversion_date
      ,currency_conversion_rate
      ,currency_conversion_type
      ,statistical_amount
      ,party_id
      ,party_site_id
      ,party_type_code
      ,ussgl_transaction_code
      ,jgzz_recon_ref
      ,source_distribution_id_char_1
      ,source_distribution_id_char_2
      ,source_distribution_id_char_3
      ,source_distribution_id_char_4
      ,source_distribution_id_char_5
      ,source_distribution_id_num_1
      ,source_distribution_id_num_2
      ,source_distribution_id_num_3
      ,source_distribution_id_num_4
      ,source_distribution_id_num_5
      ,source_distribution_type
      ,reverse_dist_id_char_1
      ,reverse_dist_id_char_2
      ,reverse_dist_id_char_3
      ,reverse_dist_id_char_4
      ,reverse_dist_id_char_5
      ,reverse_dist_id_num_1
      ,reverse_dist_id_num_2
      ,reverse_dist_id_num_3
      ,reverse_dist_id_num_4
      ,reverse_dist_id_num_5
      ,reverse_distribution_type
      ,reversal_code
      ,accounting_entry_status_code
      ,inherit_desc_flag
      ,header_num
      ,encumbrance_type_id
      ,mpa_accrual_entry_flag
      ,accounting_date
       , BFLOW_APPLICATION_ID
        , BFLOW_ENTITY_CODE
        , APPLIED_TO_ENTITY_ID
        , BFLOW_SOURCE_ID_NUM_1
        , BFLOW_SOURCE_ID_NUM_2
        , BFLOW_SOURCE_ID_NUM_3
        , BFLOW_SOURCE_ID_NUM_4
        , BFLOW_SOURCE_ID_CHAR_1
        , BFLOW_SOURCE_ID_CHAR_2
        , BFLOW_SOURCE_ID_CHAR_3
        , BFLOW_SOURCE_ID_CHAR_4
        , BFLOW_DISTRIBUTION_TYPE
        , BFLOW_DIST_ID_NUM_1
        , BFLOW_DIST_ID_NUM_2
        , BFLOW_DIST_ID_NUM_3
        , BFLOW_DIST_ID_NUM_4
        , BFLOW_DIST_ID_NUM_5
        , BFLOW_DIST_ID_CHAR_1
        , BFLOW_DIST_ID_CHAR_2
        , BFLOW_DIST_ID_CHAR_3
        , BFLOW_DIST_ID_CHAR_4
        , BFLOW_DIST_ID_CHAR_5
 , alloc_to_application_id
 , alloc_to_entity_code
 , alloc_to_source_id_num_1
 , alloc_to_source_id_num_2
 , alloc_to_source_id_num_3
 , alloc_to_source_id_num_4
 , alloc_to_source_id_char_1
 , alloc_to_source_id_char_2
 , alloc_to_source_id_char_3
 , alloc_to_source_id_char_4
 , alloc_to_distribution_type
 , alloc_to_dist_id_char_1
 , alloc_to_dist_id_char_2
 , alloc_to_dist_id_char_3
 , alloc_to_dist_id_char_4
 , alloc_to_dist_id_char_5
 , alloc_to_dist_id_num_1
 , alloc_to_dist_id_num_2
 , alloc_to_dist_id_num_3
 , alloc_to_dist_id_num_4
 , alloc_to_dist_id_num_5
 ,TAX_LINE_REF_ID           -- Bug 7159711
 ,TAX_SUMMARY_LINE_REF_ID   -- Bug 7159711
 ,TAX_REC_NREC_DIST_REF_ID  -- Bug 7159711
 ,analytical_balance_flag   -- Bug 7382288
 )
   (SELECT
       ae_header_id
      ,temp_line_num
      ,event_id
      ,ref_ae_header_id
      ,ref_ae_line_num
      ,ref_temp_line_num
      ,ref_event_id
      ,ledger_id
      ,balance_type_code
      ,accounting_class_code
      ,event_class_code
      ,event_type_code
      ,line_definition_owner_code
      ,line_definition_code
      ,accounting_line_type_code
      ,accounting_line_code
      ,code_combination_status_code
      ,code_combination_id
      ,code_combination_status_code
      ,code_combination_id
      ,description
      ,gl_transfer_mode_code
      ,merge_duplicate_code
      ,switch_side_flag  -- 5055878
      ,unrounded_entered_dr
      ,unrounded_entered_cr
      ,unrounded_accounted_dr
      ,unrounded_accounted_cr
      ,calculate_acctd_amts_flag
      ,calculate_g_l_amts_flag
      ,gain_or_loss_flag
      ,rounding_class_code
      ,document_rounding_level
      ,doc_rounding_acctd_amt
      ,doc_rounding_entered_amt
      ,entered_currency_mau
      ,currency_code
      ,currency_conversion_date
      ,currency_conversion_rate
      ,currency_conversion_type
      ,statistical_amount
      ,party_id
      ,party_site_id
      ,party_type_code
      ,ussgl_transaction_code
      ,jgzz_recon_ref
      ,source_distribution_id_char_1
      ,source_distribution_id_char_2
      ,source_distribution_id_char_3
      ,source_distribution_id_char_4
      ,source_distribution_id_char_5
      ,source_distribution_id_num_1
      ,source_distribution_id_num_2
      ,source_distribution_id_num_3
      ,source_distribution_id_num_4
      ,source_distribution_id_num_5
      ,source_distribution_type
      ,reverse_dist_id_char_1
      ,reverse_dist_id_char_2
      ,reverse_dist_id_char_3
      ,reverse_dist_id_char_4
      ,reverse_dist_id_char_5
      ,reverse_dist_id_num_1
      ,reverse_dist_id_num_2
      ,reverse_dist_id_num_3
      ,reverse_dist_id_num_4
      ,reverse_dist_id_num_5
      ,reverse_distribution_type
      ,reversal_code
      ,accounting_entry_status_code
      ,inherit_desc_flag
      ,header_num
      ,encumbrance_type_id
      ,mpa_accrual_entry_flag
      ,accounting_date
       , APPLIED_TO_APPLICATION_ID
 , APPLIED_TO_ENTITY_CODE
 , APPLIED_TO_ENTITY_ID
 , APPLIED_TO_SOURCE_ID_NUM_1
 , APPLIED_TO_SOURCE_ID_NUM_2
 , APPLIED_TO_SOURCE_ID_NUM_3
 , APPLIED_TO_SOURCE_ID_NUM_4
 , APPLIED_TO_SOURCE_ID_CHAR_1
 , APPLIED_TO_SOURCE_ID_CHAR_2
 , APPLIED_TO_SOURCE_ID_CHAR_3
 , APPLIED_TO_SOURCE_ID_CHAR_4
 , APPLIED_TO_DISTRIBUTION_TYPE
 , APPLIED_TO_DIST_ID_NUM_1
 , APPLIED_TO_DIST_ID_NUM_2
 , APPLIED_TO_DIST_ID_NUM_3
 , APPLIED_TO_DIST_ID_NUM_4
 , APPLIED_TO_DIST_ID_NUM_5
 , APPLIED_TO_DIST_ID_CHAR_1
 , APPLIED_TO_DIST_ID_CHAR_2
 , APPLIED_TO_DIST_ID_CHAR_3
 , APPLIED_TO_DIST_ID_CHAR_4
 , APPLIED_TO_DIST_ID_CHAR_5
 , alloc_to_application_id
 , alloc_to_entity_code
 , alloc_to_source_id_num_1
 , alloc_to_source_id_num_2
 , alloc_to_source_id_num_3
 , alloc_to_source_id_num_4
 , alloc_to_source_id_char_1
 , alloc_to_source_id_char_2
 , alloc_to_source_id_char_3
 , alloc_to_source_id_char_4
 , alloc_to_distribution_type
 , alloc_to_dist_id_char_1
 , alloc_to_dist_id_char_2
 , alloc_to_dist_id_char_3
 , alloc_to_dist_id_char_4
 , alloc_to_dist_id_char_5
 , alloc_to_dist_id_num_1
 , alloc_to_dist_id_num_2
 , alloc_to_dist_id_num_3
 , alloc_to_dist_id_num_4
 , alloc_to_dist_id_num_5
 ,TAX_LINE_REF_ID           -- Bug 7159711
 ,TAX_SUMMARY_LINE_REF_ID   -- Bug 7159711
 ,TAX_REC_NREC_DIST_REF_ID  -- Bug 7159711
 ,analytical_balance_flag   -- Bug 7382288
   FROM
      (SELECT /*+ leading(lgt) use_nl(xdl,ael,aeh) */
          -- populates ae_header_id which is same as event_id till this point
          lgt.event_id                                          AE_HEADER_ID
         -- populates temp_line_num which is (-ve) of original line
         ,0 - xdl.temp_line_num                                 TEMP_LINE_NUM
         -- populates event_id which is the event_id of event under process
         ,lgt.event_id                                          EVENT_ID
         -- populates ref_ae_header_id which is ae_header_id of original line
         ,ael.ae_header_id                                      REF_AE_HEADER_ID
         -- populates ref_ae_line_num which is ae_line_num of original line
         ,ael.ae_line_num                                       REF_AE_LINE_NUM
         -- populates ref_temp_line_num which is ae_line_num of original line
         ,xdl.temp_line_num                                     REF_TEMP_LINE_NUM
         -- populates ref_event_id which is event_id of original line
         ,xdl.event_id                                          REF_EVENT_ID
         ,lgt.ledger_id                                         LEDGER_ID
         ,aeh.balance_type_code                                 BALANCE_TYPE_CODE
         ,ael.accounting_class_code                             ACCOUNTING_CLASS_CODE
         ,xdl.event_class_code                                  EVENT_CLASS_CODE
         ,xdl.event_type_code                                   EVENT_TYPE_CODE
         ,xdl.line_definition_owner_code                        LINE_DEFINITION_OWNER_CODE
         ,xdl.line_definition_code                              LINE_DEFINITION_CODE
         ,xdl.accounting_line_type_code                         ACCOUNTING_LINE_TYPE_CODE
         ,xdl.accounting_line_code                              ACCOUNTING_LINE_CODE
         ,C_CREATED                                             CODE_COMBINATION_STATUS_CODE
         ,ael.code_combination_id                               CODE_COMBINATION_ID
         ,ael.description                                       DESCRIPTION
         ,ael.gl_transfer_mode_code                             GL_TRANSFER_MODE_CODE
         ,xdl.merge_duplicate_code                              MERGE_DUPLICATE_CODE
         ,decode(ael.gain_or_loss_flag, 'Y', decode(xdl.calculate_g_l_amts_flag, 'Y', 'Y', 'N'), lgt.switch_side_flag)
                                                                SWITCH_SIDE_FLAG
         -- 5055878 amounts modified for reversal method of SIDE or SIGN
         ,DECODE(lgt.switch_side_flag,'Y',xdl.unrounded_entered_cr,  -xdl.unrounded_entered_dr)     UNROUNDED_ENTERED_DR
         ,DECODE(lgt.switch_side_flag,'Y',xdl.unrounded_entered_dr,  -xdl.unrounded_entered_cr)     UNROUNDED_ENTERED_CR
         ,DECODE(lgt.switch_side_flag,'Y',xdl.unrounded_accounted_cr,-xdl.unrounded_accounted_dr)   UNROUNDED_ACCOUNTED_DR
         ,DECODE(lgt.switch_side_flag,'Y',xdl.unrounded_accounted_dr,-xdl.unrounded_accounted_cr)   UNROUNDED_ACCOUNTED_CR
         --
         ,xdl.calculate_acctd_amts_flag                         CALCULATE_ACCTD_AMTS_FLAG
         ,xdl.calculate_g_l_amts_flag                           CALCULATE_G_L_AMTS_FLAG
         ,ael.gain_or_loss_flag                                 GAIN_OR_LOSS_FLAG
         ,xdl.rounding_class_code                               ROUNDING_CLASS_CODE
         ,xdl.document_rounding_level                           DOCUMENT_ROUNDING_LEVEL
         ,NULL                                                  DOC_ROUNDING_ACCTD_AMT
         ,NULL                                                  DOC_ROUNDING_ENTERED_AMT
         ,nvl(fcu.minimum_accountable_unit, power(10, -1*fcu.precision))         ENTERED_CURRENCY_MAU
         ,ael.currency_code                                     CURRENCY_CODE
         ,ael.currency_conversion_date                          CURRENCY_CONVERSION_DATE
         ,ael.currency_conversion_rate                          CURRENCY_CONVERSION_RATE
         ,ael.currency_conversion_type                          CURRENCY_CONVERSION_TYPE
         ,ael.statistical_amount                                STATISTICAL_AMOUNT
         ,ael.party_id                                          PARTY_ID
         ,ael.party_site_id                                     PARTY_SITE_ID
         ,ael.party_type_code                                   PARTY_TYPE_CODE
         ,ael.ussgl_transaction_code                            USSGL_TRANSACTION_CODE
         ,ael.jgzz_recon_ref                                    JGZZ_RECON_REF
         ,lgt.source_distribution_id_char_1                     SOURCE_DISTRIBUTION_ID_CHAR_1
         ,lgt.source_distribution_id_char_2                     SOURCE_DISTRIBUTION_ID_CHAR_2
         ,lgt.source_distribution_id_char_3                     SOURCE_DISTRIBUTION_ID_CHAR_3
         ,lgt.source_distribution_id_char_4                     SOURCE_DISTRIBUTION_ID_CHAR_4
         ,lgt.source_distribution_id_char_5                     SOURCE_DISTRIBUTION_ID_CHAR_5
         ,lgt.source_distribution_id_num_1                      SOURCE_DISTRIBUTION_ID_NUM_1
         ,lgt.source_distribution_id_num_2                      SOURCE_DISTRIBUTION_ID_NUM_2
         ,lgt.source_distribution_id_num_3                      SOURCE_DISTRIBUTION_ID_NUM_3
         ,lgt.source_distribution_id_num_4                      SOURCE_DISTRIBUTION_ID_NUM_4
         ,lgt.source_distribution_id_num_5                      SOURCE_DISTRIBUTION_ID_NUM_5
         ,lgt.source_distribution_type                          SOURCE_DISTRIBUTION_TYPE
         ,lgt.reverse_dist_id_char_1                            REVERSE_DIST_ID_CHAR_1
         ,lgt.reverse_dist_id_char_2                            REVERSE_DIST_ID_CHAR_2
         ,lgt.reverse_dist_id_char_3                            REVERSE_DIST_ID_CHAR_3
         ,lgt.reverse_dist_id_char_4                            REVERSE_DIST_ID_CHAR_4
         ,lgt.reverse_dist_id_char_5                            REVERSE_DIST_ID_CHAR_5
         ,lgt.reverse_dist_id_num_1                             REVERSE_DIST_ID_NUM_1
         ,lgt.reverse_dist_id_num_2                             REVERSE_DIST_ID_NUM_2
         ,lgt.reverse_dist_id_num_3                             REVERSE_DIST_ID_NUM_3
         ,lgt.reverse_dist_id_num_4                             REVERSE_DIST_ID_NUM_4
         ,lgt.reverse_dist_id_num_5                             REVERSE_DIST_ID_NUM_5
         ,lgt.reverse_distribution_type                         REVERSE_DISTRIBUTION_TYPE
         -- populate reversal_code indicating that line is result of reversal
         ,'REVERSAL'                                            REVERSAL_CODE
         -- denormalises entry status from headers to line to determine the status of entry being created
         -- populates 0 for a valid entry (F or D) else poulates 1
         ,DECODE(aeh.accounting_entry_status_code,'F',0,'D',0,1) ACCOUNTING_ENTRY_STATUS_CODE
         ,'N'                                                    INHERIT_DESC_FLAG
          -- 4669308 combine header with reversal of original entry
         ,0                                                      HEADER_NUM
         ,ael.encumbrance_type_id                                ENCUMBRANCE_TYPE_ID
         ,'N'                                                    MPA_ACCRUAL_ENTRY_FLAG
         ,lgt.accounting_date                                    ACCOUNTING_DATE
            -- original line. This is used to filter duplicate rows in the outer query.
         ,row_number() over
              (partition by xdl.ae_header_Id,xdl.temp_line_num
                   order by lgt.event_number
              ) rn
      , xdl.APPLIED_TO_APPLICATION_ID   APPLIED_TO_APPLICATION_ID
 , xdl.APPLIED_TO_ENTITY_CODE       APPLIED_TO_ENTITY_CODE
 , xdl.APPLIED_TO_ENTITY_ID     APPLIED_TO_ENTITY_ID
 , xdl.APPLIED_TO_SOURCE_ID_NUM_1   APPLIED_TO_SOURCE_ID_NUM_1
 , xdl.APPLIED_TO_SOURCE_ID_NUM_2   APPLIED_TO_SOURCE_ID_NUM_2
 , xdl.APPLIED_TO_SOURCE_ID_NUM_3   APPLIED_TO_SOURCE_ID_NUM_3
 , xdl.APPLIED_TO_SOURCE_ID_NUM_4   APPLIED_TO_SOURCE_ID_NUM_4
 , xdl.APPLIED_TO_SOURCE_ID_CHAR_1  APPLIED_TO_SOURCE_ID_CHAR_1
 , xdl.APPLIED_TO_SOURCE_ID_CHAR_2  APPLIED_TO_SOURCE_ID_CHAR_2
 , xdl.APPLIED_TO_SOURCE_ID_CHAR_3  APPLIED_TO_SOURCE_ID_CHAR_3
 , xdl.APPLIED_TO_SOURCE_ID_CHAR_4  APPLIED_TO_SOURCE_ID_CHAR_4
 , xdl.APPLIED_TO_DISTRIBUTION_TYPE APPLIED_TO_DISTRIBUTION_TYPE
 , xdl.APPLIED_TO_DIST_ID_NUM_1     APPLIED_TO_DIST_ID_NUM_1
 , xdl.APPLIED_TO_DIST_ID_NUM_2     APPLIED_TO_DIST_ID_NUM_2
 , xdl.APPLIED_TO_DIST_ID_NUM_3     APPLIED_TO_DIST_ID_NUM_3
 , xdl.APPLIED_TO_DIST_ID_NUM_4     APPLIED_TO_DIST_ID_NUM_4
 , xdl.APPLIED_TO_DIST_ID_NUM_5     APPLIED_TO_DIST_ID_NUM_5
 , xdl.APPLIED_TO_DIST_ID_CHAR_1    APPLIED_TO_DIST_ID_CHAR_1
 , xdl.APPLIED_TO_DIST_ID_CHAR_2    APPLIED_TO_DIST_ID_CHAR_2
 , xdl.APPLIED_TO_DIST_ID_CHAR_3    APPLIED_TO_DIST_ID_CHAR_3
 , xdl.APPLIED_TO_DIST_ID_CHAR_4    APPLIED_TO_DIST_ID_CHAR_4
 , xdl.APPLIED_TO_DIST_ID_CHAR_5    APPLIED_TO_DIST_ID_CHAR_5
 , xdl.alloc_to_application_id      alloc_to_application_id
 , xdl.alloc_to_entity_code     alloc_to_entity_code
 , xdl.alloc_to_source_id_num_1     alloc_to_source_id_num_1
 , xdl.alloc_to_source_id_num_2     alloc_to_source_id_num_2
 , xdl.alloc_to_source_id_num_3     alloc_to_source_id_num_3
 , xdl.alloc_to_source_id_num_4     alloc_to_source_id_num_4
 , xdl.alloc_to_source_id_char_1    alloc_to_source_id_char_1
 , xdl.alloc_to_source_id_char_2    alloc_to_source_id_char_2
 , xdl.alloc_to_source_id_char_3    alloc_to_source_id_char_3
 , xdl.alloc_to_source_id_char_4    alloc_to_source_id_char_4
 , xdl.alloc_to_distribution_type   alloc_to_distribution_type
 , xdl.alloc_to_dist_id_char_1      alloc_to_dist_id_char_1
 , xdl.alloc_to_dist_id_char_2      alloc_to_dist_id_char_2
 , xdl.alloc_to_dist_id_char_3      alloc_to_dist_id_char_3
 , xdl.alloc_to_dist_id_char_4      alloc_to_dist_id_char_4
 , xdl.alloc_to_dist_id_char_5      alloc_to_dist_id_char_5
 , xdl.alloc_to_dist_id_num_1       alloc_to_dist_id_num_1
 , xdl.alloc_to_dist_id_num_2       alloc_to_dist_id_num_2
 , xdl.alloc_to_dist_id_num_3       alloc_to_dist_id_num_3
 , xdl.alloc_to_dist_id_num_4       alloc_to_dist_id_num_4
 , xdl.alloc_to_dist_id_num_5       alloc_to_dist_id_num_5
 ,nvl(lgt.tax_line_ref_id, xdl.tax_line_ref_id)                   TAX_LINE_REF_ID          -- Bug 7159711
 ,nvl(lgt.tax_summary_line_ref_id, xdl.tax_summary_line_ref_id)   TAX_SUMMARY_LINE_REF_ID  -- Bug 7159711
 ,nvl(lgt.tax_rec_nrec_dist_ref_id, xdl.tax_rec_nrec_dist_ref_id) TAX_REC_NREC_DIST_REF_ID -- Bug 7159711
 ,decode(ael.analytical_balance_flag, 'Y','P',
                                  'P','Y',
                                  null) analytical_balance_flag   -- Bug 7382288
       FROM
           xla_ae_lines_gt           lgt
          ,xla_distribution_links    xdl
          ,xla_ae_lines              ael
          ,xla_ae_headers            aeh
          ,fnd_currencies            fcu
          ,xla_events                evt
       WHERE lgt.reversal_code                              = 'DUMMY_LR'
         AND xdl.application_id                             = l_application_id
         AND xdl.source_distribution_type                   = lgt.reverse_distribution_type
         AND xdl.source_distribution_id_num_1               = nvl(lgt.reverse_dist_id_num_1,-99)
         AND nvl(xdl.source_distribution_id_num_2,-99)      = nvl(lgt.reverse_dist_id_num_2,-99)
         AND nvl(xdl.source_distribution_id_num_3,-99)      = nvl(lgt.reverse_dist_id_num_3,-99)
         AND nvl(xdl.source_distribution_id_num_4,-99)      = nvl(lgt.reverse_dist_id_num_4,-99)
         AND nvl(xdl.source_distribution_id_num_5,-99)      = nvl(lgt.reverse_dist_id_num_5,-99)
         AND nvl(xdl.source_distribution_id_char_1,' ')     = nvl(lgt.reverse_dist_id_char_1,' ')
         AND nvl(xdl.source_distribution_id_char_2,' ')     = nvl(lgt.reverse_dist_id_char_2,' ')
         AND nvl(xdl.source_distribution_id_char_3,' ')     = nvl(lgt.reverse_dist_id_char_3,' ')
         AND nvl(xdl.source_distribution_id_char_4,' ')     = nvl(lgt.reverse_dist_id_char_4,' ')
         AND nvl(xdl.source_distribution_id_char_5,' ')     = nvl(lgt.reverse_dist_id_char_5,' ')
         -- lines that are due to reversals are not reversed again
         AND NVL(xdl.temp_line_num,0)                    >= 0
         AND aeh.application_id                          = xdl.application_id
         AND aeh.ae_header_id                            = xdl.ae_header_id
         AND aeh.ledger_id                               = lgt.ledger_id
         AND aeh.entity_id                               = lgt.entity_id
         AND ael.application_id                          = aeh.application_id
         AND ael.ae_header_id                            = aeh.ae_header_id
         AND ael.ae_line_num                             = xdl.ae_line_num
         AND fcu.currency_code                           = ael.currency_code
         -- lines that have been reversed before in previous run are not reversed again
         AND NOT EXISTS (
                    SELECT /*+ no_unnest */ 1
                    FROM xla_distribution_links
                    WHERE ref_ae_header_id = xdl.ae_header_id
                      AND temp_line_num    = xdl.temp_line_num * -1
                      AND application_id   = xdl.application_id
                   )
         AND evt.application_id                          = aeh.application_id
         AND evt.event_id                                = aeh.event_id
         AND NVL(evt.budgetary_control_flag,'N')         = DECODE(p_accounting_mode
                                                                 ,'FUNDS_CHECK','Y'
                                                                 ,'FUNDS_RESERVE','Y'
                                                                 ,'N'
                                                                 )
         AND  ((aeh.parent_ae_header_id IS NOT NULL AND aeh.accounting_entry_status_code = 'F') OR
               (aeh.parent_ae_header_id IS NULL)
              )
      )
   WHERE rn = 1
   );
Line: 6000

    SELECT 1
    INTO l_upgrade_check
    FROM DUAL
    WHERE EXISTS
        (SELECT 1
        FROM gl_ledger_relationships
        WHERE hist_conv_status_code = 'SUCCESSFUL'
        AND primary_ledger_id = l_primary_ledger_id
        AND relationship_enabled_flag = 'Y');
Line: 6026

    SELECT max(glp.start_date)
      INTO l_max_first_open_period
      FROM  gl_period_statuses glp,
            gl_ledgers gl,
            gl_ledger_relationships glr
      WHERE glp.period_name = gl.first_ledger_period_name
      AND  glp.ledger_id = gl.ledger_id
      AND  glp.application_id = 101
      AND  gl.ledger_id = glr.target_ledger_id
      AND  glr.primary_ledger_id = l_primary_ledger_id
      AND  glr.relationship_enabled_flag = 'Y'
      AND  gl.ledger_category_code <> 'PRIMARY';
Line: 6043

  SELECT min(xla_ae_headers.accounting_date)
    INTO l_min_ref_event_date
    FROM xla_ae_lines_gt gt1, xla_ae_headers
   WHERE gt1.reversal_code = 'REVERSAL'
     AND gt1.ref_event_id = xla_ae_headers.event_id;
Line: 6078

 (SELECT DISTINCT gt1.event_id, gt1.ledger_id
 FROM xla_ae_lines_gt gt1, gl_ledgers gll
 WHERE gt1.reversal_code = 'DUMMY_LR'
 AND gll.ledger_id = gt1.ledger_id
 AND gll.ledger_category_code <> 'PRIMARY'
 AND NOT EXISTS (SELECT 1
                 FROM xla_ae_lines_gt gt2
         WHERE gt2.reversal_code = 'REVERSAL'
         AND gt1.event_id = gt2.event_id
         AND gt1.ledger_id = gt2.ledger_id)
 AND EXISTS (SELECT 1
            FROM xla_ae_lines_gt gt3
            WHERE gt3.reversal_code = 'REVERSAL'
        AND gt1.event_id = gt3.event_id))

 LOOP
  --IF (C_LEVEL_STATEMENT >= g_log_level) THEN
  --    trace
  --       (p_msg      => 'WARNING - Reversal (LR) lines could not be created for event  ' || c_not_reversed_entries.event_id || ' of ledger ' || c_not_reversed_entries.ledger_id || '. Please create Manual Adjustment Entries.'
  --       ,p_level    => C_LEVEL_STATEMENT
  --       ,p_module   => l_log_module);
Line: 6140

   SELECT event_id
         ,ledger_id
         ,event_number
         ,entity_id
         ,source_distribution_type
         ,source_distribution_id_num_1
         ,source_distribution_id_num_2
         ,source_distribution_id_num_3
         ,source_distribution_id_num_4
         ,source_distribution_id_num_5
         ,source_distribution_id_char_1
         ,source_distribution_id_char_2
         ,source_distribution_id_char_3
         ,source_distribution_id_char_4
         ,source_distribution_id_char_5
         ,switch_side_flag        -- 5055878
         ,accounting_date         -- 5189664
         ,tax_line_ref_id            -- 7226263
         ,tax_summary_line_ref_id    -- 7226263
         ,tax_rec_nrec_dist_ref_id   -- 7226263
     BULK COLLECT INTO
          l_array_event_id
         ,l_array_ledger_id
         ,l_array_event_number
         ,l_array_entity_id
         ,l_array_source_dist_type
         ,l_array_source_dist_id_num_1
         ,l_array_source_dist_id_num_2
         ,l_array_source_dist_id_num_3
         ,l_array_source_dist_id_num_4
         ,l_array_source_dist_id_num_5
         ,l_array_source_dist_id_char_1
         ,l_array_source_dist_id_char_2
         ,l_array_source_dist_id_char_3
         ,l_array_source_dist_id_char_4
         ,l_array_source_dist_id_char_5
         ,l_array_switch_side_flag     -- 5055878
         ,l_array_gl_date              -- 5189664
         ,l_array_tax_line_ref           -- 7226263
         ,l_array_tax_summary_line_ref   -- 7226263
         ,l_array_tax_rec_nrec_dist_ref  -- 7226263
     FROM xla_ae_lines_gt
    WHERE reversal_code = 'DUMMY_TR'
    ORDER by entity_id, event_number;
Line: 6202

      DELETE xla_ae_lines_gt lgt
      WHERE l_array_ledger_id(i)          = lgt.ledger_id
        AND lgt.reversal_code IS NULL        -- the lines created from reversal are not reversed again
        AND NOT EXISTS (                     -- the lines already reversed are not reversed again
                   SELECT 1
                   FROM xla_ae_lines_gt
                   WHERE ledger_id        = lgt.ledger_id
                     AND ref_ae_header_id = lgt.ae_header_id  -- 5499367 lgt.ref_ae_header_id
                     AND temp_line_num    = lgt.temp_line_num * -1
                  )
        AND  NVL(lgt.header_num,0) > 0
        AND lgt.header_num IN
            (SELECT hgt.header_num
             FROM   xla_ae_headers_gt hgt
             WHERE  hgt.entity_id           = l_array_entity_id(i)
             AND    hgt.ledger_id           = l_array_ledger_id(i)
             AND    hgt.event_number        < l_array_event_number(i)
             AND    lgt.event_id            = hgt.event_id
             AND    lgt.ledger_id           = hgt.ledger_id
             AND    lgt.balance_type_code   = hgt.balance_type_code
             AND    lgt.header_num          = hgt.header_num)
      ;
Line: 6230

      DELETE xla_ae_headers_gt hgt
      WHERE  hgt.ledger_id         = l_array_ledger_id(i)
      AND    hgt.entity_id         = l_array_entity_id(i)
      AND    hgt.event_number      < l_array_event_number(i)
      AND    NVL(hgt.header_num,0) > 0
      ;
Line: 6244

   INSERT INTO xla_ae_lines_gt
      (ae_header_id
      ,temp_line_num
      ,event_id
      ,ref_ae_header_id
      ,ref_ae_line_num
      ,ref_temp_line_num
      ,ref_event_id
      ,ledger_id
      ,balance_type_code
      ,accounting_class_code
      ,event_class_code
      ,event_type_code
      ,line_definition_owner_code
      ,line_definition_code
      ,accounting_line_type_code
      ,accounting_line_code
      ,code_combination_status_code
      ,code_combination_id
      ,sl_coa_mapping_name
      ,dynamic_insert_flag
      ,source_coa_id
      ,ccid_coa_id
      ,segment1
      ,segment2
      ,segment3
      ,segment4
      ,segment5
      ,segment6
      ,segment7
      ,segment8
      ,segment9
      ,segment10
      ,segment11
      ,segment12
      ,segment13
      ,segment14
      ,segment15
      ,segment16
      ,segment17
      ,segment18
      ,segment19
      ,segment20
      ,segment21
      ,segment22
      ,segment23
      ,segment24
      ,segment25
      ,segment26
      ,segment27
      ,segment28
      ,segment29
      ,segment30
      , calculate_acctd_amts_flag
      , calculate_g_l_amts_flag
      , gain_or_loss_flag
      , rounding_class_code
      , document_rounding_level
      , doc_rounding_acctd_amt
      , doc_rounding_entered_amt
      ,alt_ccid_status_code
      ,alt_code_combination_id
      ,alt_segment1
      ,alt_segment2
      ,alt_segment3
      ,alt_segment4
      ,alt_segment5
      ,alt_segment6
      ,alt_segment7
      ,alt_segment8
      ,alt_segment9
      ,alt_segment10
      ,alt_segment11
      ,alt_segment12
      ,alt_segment13
      ,alt_segment14
      ,alt_segment15
      ,alt_segment16
      ,alt_segment17
      ,alt_segment18
      ,alt_segment19
      ,alt_segment20
      ,alt_segment21
      ,alt_segment22
      ,alt_segment23
      ,alt_segment24
      ,alt_segment25
      ,alt_segment26
      ,alt_segment27
      ,alt_segment28
      ,alt_segment29
      ,alt_segment30
      ,description
      ,gl_transfer_mode_code
      ,merge_duplicate_code
      ,switch_side_flag
--      ,entered_amount
--      ,ledger_amount
      ,unrounded_entered_dr
      ,unrounded_entered_cr
      ,unrounded_accounted_dr
      ,unrounded_accounted_cr
      ,entered_currency_mau
      ,currency_code
      ,currency_conversion_date
      ,currency_conversion_rate
      ,currency_conversion_type
      ,statistical_amount
      ,party_id
      ,party_site_id
      ,party_type_code
      ,ussgl_transaction_code
      ,jgzz_recon_ref
      ,source_distribution_id_char_1
      ,source_distribution_id_char_2
      ,source_distribution_id_char_3
      ,source_distribution_id_char_4
      ,source_distribution_id_char_5
      ,source_distribution_id_num_1
      ,source_distribution_id_num_2
      ,source_distribution_id_num_3
      ,source_distribution_id_num_4
      ,source_distribution_id_num_5
      ,source_distribution_type
      ,reverse_dist_id_char_1
      ,reverse_dist_id_char_2
      ,reverse_dist_id_char_3
      ,reverse_dist_id_char_4
      ,reverse_dist_id_char_5
      ,reverse_dist_id_num_1
      ,reverse_dist_id_num_2
      ,reverse_dist_id_num_3
      ,reverse_dist_id_num_4
      ,reverse_dist_id_num_5
      ,reverse_distribution_type
      ,tax_line_ref_id
      ,tax_summary_line_ref_id
      ,tax_rec_nrec_dist_ref_id
    -- 4262811
      ,header_num
      ,mpa_accrual_entry_flag
      ,multiperiod_option_flag
      ,multiperiod_start_date
      ,multiperiod_end_date
    --,deferred_indicator
    --,deferred_start_date
    --,deferred_end_date
    --,deferred_no_period
    --,deferred_period_type
      ,reversal_code
      ,accounting_entry_status_code
      ,encumbrance_type_id -- 4458381
      ,inherit_desc_flag   -- 4219869
      ,accounting_date
      , BFLOW_APPLICATION_ID
        , BFLOW_ENTITY_CODE
        , APPLIED_TO_ENTITY_ID
        , BFLOW_SOURCE_ID_NUM_1
        , BFLOW_SOURCE_ID_NUM_2
        , BFLOW_SOURCE_ID_NUM_3
        , BFLOW_SOURCE_ID_NUM_4
        , BFLOW_SOURCE_ID_CHAR_1
        , BFLOW_SOURCE_ID_CHAR_2
        , BFLOW_SOURCE_ID_CHAR_3
        , BFLOW_SOURCE_ID_CHAR_4
        , BFLOW_DISTRIBUTION_TYPE
        , BFLOW_DIST_ID_NUM_1
        , BFLOW_DIST_ID_NUM_2
        , BFLOW_DIST_ID_NUM_3
        , BFLOW_DIST_ID_NUM_4
        , BFLOW_DIST_ID_NUM_5
        , BFLOW_DIST_ID_CHAR_1
        , BFLOW_DIST_ID_CHAR_2
        , BFLOW_DIST_ID_CHAR_3
        , BFLOW_DIST_ID_CHAR_4
        , BFLOW_DIST_ID_CHAR_5
 , alloc_to_application_id
 , alloc_to_entity_code
 , alloc_to_source_id_num_1
 , alloc_to_source_id_num_2
 , alloc_to_source_id_num_3
 , alloc_to_source_id_num_4
 , alloc_to_source_id_char_1
 , alloc_to_source_id_char_2
 , alloc_to_source_id_char_3
 , alloc_to_source_id_char_4
 , alloc_to_distribution_type
 , alloc_to_dist_id_char_1
 , alloc_to_dist_id_char_2
 , alloc_to_dist_id_char_3
 , alloc_to_dist_id_char_4
 , alloc_to_dist_id_char_5
 , alloc_to_dist_id_num_1
 , alloc_to_dist_id_num_2
 , alloc_to_dist_id_num_3
 , alloc_to_dist_id_num_4
 , alloc_to_dist_id_num_5)    -- 4955764
   SELECT
       -- populates ae_header_id which is same as event_id till this point
       l_array_event_id(i)
      -- populates temp_line_num which is (-ve) of original line
      ,0-lgt.temp_line_num
      -- populates event_id which is the event_id of event under process
      ,l_array_event_id(i)
      -- populates ref_ae_header_id which is ae_header_id of original line
      ,hgt.ae_header_id
      -- populates ref_ae_line_num which is ae_line_num of original line
      ,lgt.ae_line_num
      -- populates ref_temp_line_num which is ae_line_num of original line
      ,lgt.temp_line_num
      -- populates ref_event_id which is event_id of original line
      ,lgt.event_id
      ,lgt.ledger_id
      ,lgt.balance_type_code
      ,lgt.accounting_class_code
      ,lgt.event_class_code
      ,lgt.event_type_code
      ,lgt.line_definition_owner_code
      ,lgt.line_definition_code
      ,lgt.accounting_line_type_code
      ,lgt.accounting_line_code
      ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y'
                ,lgt.alt_ccid_status_code,lgt.code_combination_status_code)
         ,lgt.code_combination_status_code)
                                                       CODE_COMBINATION_STATUS_CODE
      ,decode(lgt.gain_or_loss_flag, 'Y'
            ,decode(lgt.calculate_g_l_amts_flag,'Y'
                 ,lgt.alt_code_combination_id, lgt.code_combination_id)
       , lgt.code_combination_id)
                                                       CODE_COMBINATION_ID
      ,lgt.sl_coa_mapping_name
      ,lgt.dynamic_insert_flag
      ,lgt.source_coa_id
      ,lgt.ccid_coa_id
         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment1,lgt.segment1)
         ,lgt.segment1)                                                   SEGMENT1
         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment2,lgt.segment2)
         ,lgt.segment2)                                                   SEGMENT2

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment3,lgt.segment3)
         ,lgt.segment3)                                                   SEGMENT3

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment4,lgt.segment4)
         ,lgt.segment4)                                                     SEGMENT4

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment5,lgt.segment5)
         ,lgt.segment5)                                                   SEGMENT5

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment6,lgt.segment6)
         ,lgt.segment6)                                                   SEGMENT6

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment7,lgt.segment7)
         ,lgt.segment7)                                                  SEGMENT7

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment8,lgt.segment8)
         ,lgt.segment8)                                                   SEGMENT8

         ,decode(lgt.gain_or_loss_flag, 'Y'
                ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment9,lgt.segment9)
         ,lgt.segment9)                                                   SEGMENT9

         ,decode(lgt.gain_or_loss_flag, 'Y'
              ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment10,lgt.segment10)
         ,lgt.segment10)                                                   SEGMENT10

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment11,lgt.segment11)
         ,lgt.segment11)                                                   SEGMENT11

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment12,lgt.segment12)
         ,lgt.segment12)                                                   SEGMENT12

         ,decode(lgt.gain_or_loss_flag, 'Y'
               ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment13,lgt.segment13)
         ,lgt.segment13)                                                   SEGMENT13

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment14,lgt.segment14)
         ,lgt.segment14)                                                   SEGMENT14

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment15,lgt.segment15)
         ,lgt.segment15)                                                   SEGMENT15

         ,decode(lgt.gain_or_loss_flag, 'Y'
              ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment16,lgt.segment16)
         ,lgt.segment16)                                                   SEGMENT16

         ,decode(lgt.gain_or_loss_flag, 'Y'
              ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment17,lgt.segment17)
         ,lgt.segment17)                                                   SEGMENT17

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment18,lgt.segment18)
         ,lgt.segment18)                                                   SEGMENT18

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment19,lgt.segment19)
         ,lgt.segment19)                                                   SEGMENT19

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment20,lgt.segment20)
         ,lgt.segment20)                                                  SEGMENT20

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment21,lgt.segment21)
         ,lgt.segment21)                                                   SEGMENT21

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment22,lgt.segment22)
         ,lgt.segment22)                                                   SEGMENT22

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment23,lgt.segment23)
         ,lgt.segment23)                                                   SEGMENT23

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment24,lgt.segment24)
         ,lgt.segment24)                                                   SEGMENT24

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment25,lgt.segment25)
         ,lgt.segment25)                                                   SEGMENT25

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment26,lgt.segment26)
         ,lgt.segment26)                                                   SEGMENT26

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment27,lgt.segment27)
         ,lgt.segment27)                                                   SEGMENT27

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment28,lgt.segment28)
         ,lgt.segment28)                                                  SEGMENT28

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment29,lgt.segment29)
         ,lgt.segment29)                                                   SEGMENT29

         ,decode(lgt.gain_or_loss_flag, 'Y'
             ,decode(lgt.calculate_g_l_amts_flag,'Y',lgt.alt_segment30,lgt.segment30)
         ,lgt.segment30)                                                   SEGMENT30
      ,lgt.calculate_acctd_amts_flag
      ,lgt.calculate_g_l_amts_flag
      ,lgt.gain_or_loss_flag
      ,lgt.rounding_class_code
      ,lgt.document_rounding_level
      ,lgt.doc_rounding_acctd_amt
      ,lgt.doc_rounding_entered_amt
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.code_combination_status_code ,lgt.alt_ccid_status_code)
                                                       ALT_CCID_STATUS_CODE
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.code_combination_id ,lgt.alt_code_combination_id)
                                                       ALT_CODE_COMBINATION_ID
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment1,lgt.alt_segment1)     ALT_SEGMENT1
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment2,lgt.alt_segment2)     ALT_SEGMENT2
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment3,lgt.alt_segment3)     ALT_SEGMENT3
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment4,lgt.alt_segment4)     ALT_SEGMENT4
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment5,lgt.alt_segment5)     ALT_SEGMENT5
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment6,lgt.alt_segment6)     ALT_SEGMENT6
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment7,lgt.alt_segment7)     ALT_SEGMENT7
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment8,lgt.alt_segment8)     ALT_SEGMENT8
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment9,lgt.alt_segment9)     ALT_SEGMENT9
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment10,lgt.alt_segment10)   ALT_SEGMENT10
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment11,lgt.alt_segment11)   ALT_SEGMENT11
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment12,lgt.alt_segment12)   ALT_SEGMENT12
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment13,lgt.alt_segment13)   ALT_SEGMENT13
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment14,lgt.alt_segment14)   ALT_SEGMENT14
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment15,lgt.alt_segment15)   ALT_SEGMENT15
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment16,lgt.alt_segment16)   ALT_SEGMENT16
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment17,lgt.alt_segment17)   ALT_SEGMENT17
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment18,lgt.alt_segment18)   ALT_SEGMENT18
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment19,lgt.alt_segment19)   ALT_SEGMENT19
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment20,lgt.alt_segment20)   ALT_SEGMENT20
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment21,lgt.alt_segment21)   ALT_SEGMENT21
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment22,lgt.alt_segment22)   ALT_SEGMENT22
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment23,lgt.alt_segment23)   ALT_SEGMENT23
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment24,lgt.alt_segment24)   ALT_SEGMENT24
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment25,lgt.alt_segment25)   ALT_SEGMENT25
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment26,lgt.alt_segment26)   ALT_SEGMENT26
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment27,lgt.alt_segment27)   ALT_SEGMENT27
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment28,lgt.alt_segment28)   ALT_SEGMENT28
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment29,lgt.alt_segment29)   ALT_SEGMENT29
      ,decode(lgt.gain_or_loss_flag, 'Y', lgt.segment30,lgt.alt_segment30)   ALT_SEGMENT30
      ,lgt.description
      ,lgt.gl_transfer_mode_code
      ,lgt.merge_duplicate_code
      ,decode(lgt.gain_or_loss_flag, 'Y', decode(lgt.calculate_g_l_amts_flag, 'Y', 'Y', 'N'), lgt.switch_side_flag)      -- 5055878  lgt.switch_side_flag
--      ,lgt.entered_amount
--      ,lgt.ledger_amount
      -- 5055878 amounts modified for reversal method of SIDE or SIGN
      ,DECODE(l_array_switch_side_flag(i),'Y',lgt.unrounded_entered_cr,  -lgt.unrounded_entered_dr)
      ,DECODE(l_array_switch_side_flag(i),'Y',lgt.unrounded_entered_dr,  -lgt.unrounded_entered_cr)
      ,DECODE(l_array_switch_side_flag(i),'Y',lgt.unrounded_accounted_cr,-lgt.unrounded_accounted_dr)
      ,DECODE(l_array_switch_side_flag(i),'Y',lgt.unrounded_accounted_dr,-lgt.unrounded_accounted_cr)
      --
/*
      ,DECODE(lgt.switch_side_flag
             ,C_NO_SWITCH, - lgt.entered_dr
             ,C_SWITCH, lgt.entered_cr
             )
      ,DECODE(lgt.switch_side_flag
             ,C_NO_SWITCH, - lgt.entered_cr
             ,C_SWITCH,   lgt.entered_dr
             )
      ,DECODE(lgt.switch_side_flag
             ,C_NO_SWITCH, - lgt.unrounded_accounted_dr
             ,C_SWITCH,lgt.unrounded_accounted_cr
             )
      ,DECODE(lgt.switch_side_flag
             ,C_NO_SWITCH, - lgt.unrounded_accounted_cr
             ,C_SWITCH, lgt.unrounded_accounted_dr
             )
*/
      ,lgt.entered_currency_mau
      ,lgt.currency_code
      ,lgt.currency_conversion_date
      ,lgt.currency_conversion_rate
      ,lgt.currency_conversion_type
      ,lgt.statistical_amount
      ,lgt.party_id
      ,lgt.party_site_id
      ,lgt.party_type_code
      ,lgt.ussgl_transaction_code
      ,lgt.jgzz_recon_ref
      -- if there are no distributions for this event
      -- populate with the distribution if lines that is being reversed
      ,NVL(l_array_source_dist_id_char_1(i),lgt.source_distribution_id_char_1)
      ,NVL(l_array_source_dist_id_char_2(i),lgt.source_distribution_id_char_2)
      ,NVL(l_array_source_dist_id_char_3(i),lgt.source_distribution_id_char_3)
      ,NVL(l_array_source_dist_id_char_4(i),lgt.source_distribution_id_char_4)
      ,NVL(l_array_source_dist_id_char_5(i),lgt.source_distribution_id_char_5)
      ,NVL(l_array_source_dist_id_num_1(i),lgt.source_distribution_id_num_1)
      ,NVL(l_array_source_dist_id_num_2(i),lgt.source_distribution_id_num_2)
      ,NVL(l_array_source_dist_id_num_3(i),lgt.source_distribution_id_num_3)
      ,NVL(l_array_source_dist_id_num_4(i),lgt.source_distribution_id_num_4)
      ,NVL(l_array_source_dist_id_num_5(i),lgt.source_distribution_id_num_5)
      ,NVL(l_array_source_dist_type(i),lgt.source_distribution_type)
      -- populate reverse distibutions from original line
      ,lgt.source_distribution_id_char_1
      ,lgt.source_distribution_id_char_2
      ,lgt.source_distribution_id_char_3
      ,lgt.source_distribution_id_char_4
      ,lgt.source_distribution_id_char_5
      ,lgt.source_distribution_id_num_1
      ,lgt.source_distribution_id_num_2
      ,lgt.source_distribution_id_num_3
      ,lgt.source_distribution_id_num_4
      ,lgt.source_distribution_id_num_5
      ,lgt.source_distribution_type
      ,lgt.tax_line_ref_id
      ,lgt.tax_summary_line_ref_id
      ,lgt.tax_rec_nrec_dist_ref_id
    -- 4262811
      ,NVL(lgt.header_num,0)  -- 4963422
      ,lgt.mpa_accrual_entry_flag
      ,lgt.multiperiod_option_flag
      ,lgt.multiperiod_start_date
      ,lgt.multiperiod_end_date
    --,lgt.deferred_indicator
    --,lgt.deferred_start_date
    --,lgt.deferred_end_date
    --,lgt.deferred_no_period
    --,lgt.deferred_period_type
      -- populate reversal_code to indicate that line is due to a reversal
      ,'REVERSAL'
      -- denormalize entry status to lines from header to decide on status of new entry
      ,hgt.accounting_entry_status_code
      ,lgt.encumbrance_type_id -- 4458381
      ,'N'    -- lgt.inherit_desc_flag            -- 4219869  Should it be from l_array
      ,l_array_gl_date(i)      -- 5189664     hgt.accounting_date     -- 4955764
      , lgt.BFLOW_APPLICATION_ID
        , lgt.BFLOW_ENTITY_CODE
        , lgt.APPLIED_TO_ENTITY_ID
        , lgt.BFLOW_SOURCE_ID_NUM_1
        , lgt.BFLOW_SOURCE_ID_NUM_2
        , lgt.BFLOW_SOURCE_ID_NUM_3
        , lgt.BFLOW_SOURCE_ID_NUM_4
        , lgt.BFLOW_SOURCE_ID_CHAR_1
        , lgt.BFLOW_SOURCE_ID_CHAR_2
        , lgt.BFLOW_SOURCE_ID_CHAR_3
        , lgt.BFLOW_SOURCE_ID_CHAR_4
        , lgt.BFLOW_DISTRIBUTION_TYPE
        , lgt.BFLOW_DIST_ID_NUM_1
        , lgt.BFLOW_DIST_ID_NUM_2
        , lgt.BFLOW_DIST_ID_NUM_3
        , lgt.BFLOW_DIST_ID_NUM_4
        , lgt.BFLOW_DIST_ID_NUM_5
        , lgt.BFLOW_DIST_ID_CHAR_1
        , lgt.BFLOW_DIST_ID_CHAR_2
        , lgt.BFLOW_DIST_ID_CHAR_3
        , lgt.BFLOW_DIST_ID_CHAR_4
        , lgt.BFLOW_DIST_ID_CHAR_5
 , lgt.alloc_to_application_id      alloc_to_application_id
 , lgt.alloc_to_entity_code     alloc_to_entity_code
 , lgt.alloc_to_source_id_num_1     alloc_to_source_id_num_1
 , lgt.alloc_to_source_id_num_2     alloc_to_source_id_num_2
 , lgt.alloc_to_source_id_num_3     alloc_to_source_id_num_3
 , lgt.alloc_to_source_id_num_4     alloc_to_source_id_num_4
 , lgt.alloc_to_source_id_char_1    alloc_to_source_id_char_1
 , lgt.alloc_to_source_id_char_2    alloc_to_source_id_char_2
 , lgt.alloc_to_source_id_char_3    alloc_to_source_id_char_3
 , lgt.alloc_to_source_id_char_4    alloc_to_source_id_char_4
 , lgt.alloc_to_distribution_type   alloc_to_distribution_type
 , lgt.alloc_to_dist_id_char_1      alloc_to_dist_id_char_1
 , lgt.alloc_to_dist_id_char_2      alloc_to_dist_id_char_2
 , lgt.alloc_to_dist_id_char_3      alloc_to_dist_id_char_3
 , lgt.alloc_to_dist_id_char_4      alloc_to_dist_id_char_4
 , lgt.alloc_to_dist_id_char_5      alloc_to_dist_id_char_5
 , lgt.alloc_to_dist_id_num_1       alloc_to_dist_id_num_1
 , lgt.alloc_to_dist_id_num_2       alloc_to_dist_id_num_2
 , lgt.alloc_to_dist_id_num_3       alloc_to_dist_id_num_3
 , lgt.alloc_to_dist_id_num_4       alloc_to_dist_id_num_4
 , lgt.alloc_to_dist_id_num_5       alloc_to_dist_id_num_5
    FROM xla_ae_lines_gt     lgt
        ,xla_ae_headers_gt   hgt
   WHERE hgt.entity_id                  = l_array_entity_id(i)
     AND hgt.ledger_id                  = l_array_ledger_id(i)
     AND hgt.event_number               < l_array_event_number(i)
     AND lgt.event_id                   = hgt.event_id
     AND lgt.ledger_id                  = hgt.ledger_id
     AND lgt.balance_type_code          = hgt.balance_type_code
     -- lines that are reversal lines are not revrsed again
     AND lgt.reversal_code              IS NULL
     -- lines that are reversed earlier are not reversed again
     AND NOT EXISTS (
                SELECT 1
                FROM xla_ae_lines_gt
                WHERE ledger_id        = lgt.ledger_id
                  AND ref_ae_header_id = lgt.ae_header_id  -- 5499367 lgt.ref_ae_header_id
                  AND temp_line_num    = lgt.temp_line_num * -1
               )
     AND lgt.header_num = hgt.header_num     -- 4262811c  Transaction Reversal (not yet finalised)
   ;
Line: 6802

      SELECT /*+ Leading(LGT,XET) use_nl(lgt xet aeh ael)*/  -- 5262950
             ael.ae_header_id
            ,ael.ae_line_num
            ,aeh.parent_ae_header_id
      BULK COLLECT INTO
             g_incomplete_mpa_acc_TR.l_array_ae_header_id
            ,g_incomplete_mpa_acc_TR.l_array_ae_line_num
            ,g_incomplete_mpa_acc_TR.l_array_parent_ae_header
      FROM
           xla_ae_lines_gt           lgt
          ,xla_ae_lines              ael
          ,xla_ae_headers            aeh
          ,xla_events                xet -- 5262950
      WHERE aeh.application_id                        = l_application_id
      AND lgt.reversal_code                           = 'DUMMY_TR'
      AND xet.application_id                          = l_application_id -- 5262950
      AND xet.entity_id                               = lgt.entity_id    -- 5262950
      AND aeh.event_id                                = xet.event_id     -- 5262950
      AND aeh.ledger_id                               = lgt.ledger_id
      AND aeh.entity_id                               = xet.entity_id    -- 5262950 lgt.entity_id
   -- AND aeh.entity_id                               = lgt.entity_id
      AND ael.application_id                          = aeh.application_id   -- 5262950
      AND ael.ae_header_id                            = aeh.ae_header_id     -- 5262950
      AND aeh.parent_ae_header_id IS NOT NULL AND aeh.accounting_entry_status_code IN ('D','N','I','R','RELATED_EVENT_ERROR');  -- 5262950
Line: 6870

   INSERT INTO xla_ae_lines_gt
      (ae_header_id
      ,temp_line_num
      ,event_id
      ,ref_ae_header_id
      ,ref_ae_line_num
      ,ref_temp_line_num
      ,ref_event_id
      ,balance_type_code
      ,ledger_id
      ,accounting_class_code
      ,event_class_code
      ,event_type_code
      ,line_definition_owner_code
      ,line_definition_code
      ,accounting_line_type_code
      ,accounting_line_code
      ,code_combination_status_code
      ,code_combination_id
      ,alt_ccid_status_code
      ,alt_code_combination_id
      ,description
      ,gl_transfer_mode_code
      ,merge_duplicate_code
      ,switch_side_flag   -- 5055878
--      ,entered_amount
--      ,ledger_amount
      ,unrounded_entered_dr
      ,unrounded_entered_cr
      ,unrounded_accounted_dr
      ,unrounded_accounted_cr
      ,calculate_acctd_amts_flag
      ,calculate_g_l_amts_flag
      ,gain_or_loss_flag
      ,rounding_class_code
      ,document_rounding_level
      ,doc_rounding_acctd_amt
      ,doc_rounding_entered_amt
      ,entered_currency_mau
      ,currency_code
      ,currency_conversion_date
      ,currency_conversion_rate
      ,currency_conversion_type
      ,statistical_amount
      ,party_id
      ,party_site_id
      ,party_type_code
      ,ussgl_transaction_code
      ,jgzz_recon_ref
      ,tax_line_ref_id                  -- bug 7159711
      ,tax_summary_line_ref_id          -- bug 7159711
      ,tax_rec_nrec_dist_ref_id         -- bug 7159711
      ,source_distribution_id_char_1
      ,source_distribution_id_char_2
      ,source_distribution_id_char_3
      ,source_distribution_id_char_4
      ,source_distribution_id_char_5
      ,source_distribution_id_num_1
      ,source_distribution_id_num_2
      ,source_distribution_id_num_3
      ,source_distribution_id_num_4
      ,source_distribution_id_num_5
      ,source_distribution_type
      ,reverse_dist_id_char_1
      ,reverse_dist_id_char_2
      ,reverse_dist_id_char_3
      ,reverse_dist_id_char_4
      ,reverse_dist_id_char_5
      ,reverse_dist_id_num_1
      ,reverse_dist_id_num_2
      ,reverse_dist_id_num_3
      ,reverse_dist_id_num_4
      ,reverse_dist_id_num_5
      ,reverse_distribution_type
      ,reversal_code
      ,accounting_entry_status_code
      ,encumbrance_type_id -- 4458381
      ,inherit_desc_flag   -- 4219869
      ,header_num               -- 4669308
      ,mpa_accrual_entry_flag   -- 4262811
      ,accounting_date
      , BFLOW_APPLICATION_ID
        , BFLOW_ENTITY_CODE
        , APPLIED_TO_ENTITY_ID
        , BFLOW_SOURCE_ID_NUM_1
        , BFLOW_SOURCE_ID_NUM_2
        , BFLOW_SOURCE_ID_NUM_3
        , BFLOW_SOURCE_ID_NUM_4
        , BFLOW_SOURCE_ID_CHAR_1
        , BFLOW_SOURCE_ID_CHAR_2
        , BFLOW_SOURCE_ID_CHAR_3
        , BFLOW_SOURCE_ID_CHAR_4
        , BFLOW_DISTRIBUTION_TYPE
        , BFLOW_DIST_ID_NUM_1
        , BFLOW_DIST_ID_NUM_2
        , BFLOW_DIST_ID_NUM_3
        , BFLOW_DIST_ID_NUM_4
        , BFLOW_DIST_ID_NUM_5
        , BFLOW_DIST_ID_CHAR_1
        , BFLOW_DIST_ID_CHAR_2
        , BFLOW_DIST_ID_CHAR_3
        , BFLOW_DIST_ID_CHAR_4
        , BFLOW_DIST_ID_CHAR_5
 , alloc_to_application_id
 , alloc_to_entity_code
 , alloc_to_source_id_num_1
 , alloc_to_source_id_num_2
 , alloc_to_source_id_num_3
 , alloc_to_source_id_num_4
 , alloc_to_source_id_char_1
 , alloc_to_source_id_char_2
 , alloc_to_source_id_char_3
 , alloc_to_source_id_char_4
 , alloc_to_distribution_type
 , alloc_to_dist_id_char_1
 , alloc_to_dist_id_char_2
 , alloc_to_dist_id_char_3
 , alloc_to_dist_id_char_4
 , alloc_to_dist_id_char_5
 , alloc_to_dist_id_num_1
 , alloc_to_dist_id_num_2
 , alloc_to_dist_id_num_3
 , alloc_to_dist_id_num_4
 , alloc_to_dist_id_num_5)         -- 4955764
   SELECT
       -- populates ae_header_id which is same as event_id till this point
       l_array_event_id(i)
      -- populates temp_line_num which is (-ve) of original line
      ,0 - xdl.temp_line_num
      -- populates event_id which is the event_id of event under process
      ,l_array_event_id(i)
      -- populates ref_ae_header_id which is ae_header_id of original line
      ,ael.ae_header_id
      -- populates ref_ae_line_num which is ae_line_num of original line
      ,ael.ae_line_num
      -- populates ref_temp_line_num which is ae_line_num of original line
      ,xdl.temp_line_num
      -- populates ref_event_id which is event_id of original line
      ,xdl.event_id
      ,aeh.balance_type_code
      ,l_array_ledger_id(i)
      ,ael.accounting_class_code
      ,xdl.event_class_code
      ,xdl.event_type_code
      ,xdl.line_definition_owner_code
      ,xdl.line_definition_code
      ,xdl.accounting_line_type_code
      ,xdl.accounting_line_code
      ,C_CREATED
      ,ael.code_combination_id
      ,C_CREATED
      ,ael.code_combination_id
      ,ael.description
      ,ael.gl_transfer_mode_code
      ,xdl.merge_duplicate_code
      --,decode(ael.gain_or_loss_flag, 'Y', decode(xdl.calculate_g_l_amts_flag, 'Y', 'Y', 'N'), 'N')
                            -- 5055878  switch_side_flag
      -- 5055878 amounts modified for reversal method of SIDE or SIGN
      , decode(ael.gain_or_loss_flag, 'Y', decode(xdl.calculate_g_l_amts_flag, 'Y', 'Y', 'N'), l_default_switch_side_flag)
      --bug#6933157 24-Apr-2008
      ,DECODE(l_array_switch_side_flag(i),'Y',xdl.unrounded_entered_cr,  -xdl.unrounded_entered_dr)
      ,DECODE(l_array_switch_side_flag(i),'Y',xdl.unrounded_entered_dr,  -xdl.unrounded_entered_cr)
      ,DECODE(l_array_switch_side_flag(i),'Y',xdl.unrounded_accounted_cr,-xdl.unrounded_accounted_dr)
      ,DECODE(l_array_switch_side_flag(i),'Y',xdl.unrounded_accounted_dr,-xdl.unrounded_accounted_cr)
      --
      ,xdl.calculate_acctd_amts_flag
      ,xdl.calculate_g_l_amts_flag
      ,ael.gain_or_loss_flag
      ,xdl.rounding_class_code
      ,xdl.document_rounding_level
      ,NULL     -- xdl.doc_rounding_acctd_amt    4669308 creates wrong ROUNDING line for MPA reversal
      ,NULL     -- xdl.doc_rounding_entered_amt  4669308 creates wrong ROUNDING line for MPA reversal
/*
      ,xdl.entered_amount
      ,xdl.ledger_amount
      -- populates entered_dr. amount should be equal to the entered amount in distribution links
      ,DECODE(ael.entered_cr,NULL,NULL,xdl.entered_amount)
      -- populates entered_cr. amount should be equal to the entered amount in distribution links
      ,DECODE(ael.entered_dr,NULL,NULL,xdl.entered_amount)
      -- populates accounted_dr. amount should be equal to the ledger amount in distribution links
      ,DECODE(ael.accounted_cr,NULL,NULL,xdl.ledger_amount)
      -- populates accounted_cr. amount should be equal to the ledger amount in distribution links
      ,DECODE(ael.accounted_dr,NULL,NULL,xdl.ledger_amount)
*/
--      ,ael.entered_cr
--      ,ael.entered_dr
--      ,ael.accounted_cr
--      ,ael.accounted_dr
      ,nvl(fcu.minimum_accountable_unit, power(10, -1* fcu.precision))
      ,ael.currency_code
      ,ael.currency_conversion_date
      ,ael.currency_conversion_rate
      ,ael.currency_conversion_type
      ,ael.statistical_amount
      ,ael.party_id
      ,ael.party_site_id
      ,ael.party_type_code
      ,ael.ussgl_transaction_code
      ,ael.jgzz_recon_ref
      -- if there are no distributions for this event
      -- populate with the distribution if lines that is being reversed
      ,NVL(l_array_tax_line_ref(i),xdl.tax_line_ref_id)                   -- bug7159711
      ,NVL(l_array_tax_summary_line_ref(i),xdl.tax_summary_line_ref_id)   -- bug7159711
      ,NVL(l_array_tax_rec_nrec_dist_ref(i),xdl.tax_rec_nrec_dist_ref_id) -- bug7159711
      ,NVL(l_array_source_dist_id_char_1(i),xdl.source_distribution_id_char_1)
      ,NVL(l_array_source_dist_id_char_2(i),xdl.source_distribution_id_char_2)
      ,NVL(l_array_source_dist_id_char_3(i),xdl.source_distribution_id_char_3)
      ,NVL(l_array_source_dist_id_char_4(i),xdl.source_distribution_id_char_4)
      ,NVL(l_array_source_dist_id_char_5(i),xdl.source_distribution_id_char_5)
      ,NVL(l_array_source_dist_id_num_1(i),xdl.source_distribution_id_num_1)
      ,NVL(l_array_source_dist_id_num_2(i),xdl.source_distribution_id_num_2)
      ,NVL(l_array_source_dist_id_num_3(i),xdl.source_distribution_id_num_3)
      ,NVL(l_array_source_dist_id_num_4(i),xdl.source_distribution_id_num_4)
      ,NVL(l_array_source_dist_id_num_5(i),xdl.source_distribution_id_num_5)
      ,NVL(l_array_source_dist_type(i),xdl.source_distribution_type)
      ,xdl.source_distribution_id_char_1
      ,xdl.source_distribution_id_char_2
      ,xdl.source_distribution_id_char_3
      ,xdl.source_distribution_id_char_4
      ,xdl.source_distribution_id_char_5
      ,xdl.source_distribution_id_NUM_1
      ,xdl.source_distribution_id_NUM_2
      ,xdl.source_distribution_id_NUM_3
      ,xdl.source_distribution_id_NUM_4
      ,xdl.source_distribution_id_NUM_5
      ,xdl.source_distribution_type
      -- populate reversal_code indicating that line is result of reversal
      ,'REVERSAL'
      -- denormalises entry status from headers to line to determine the status of entry being created
      -- populates 0 for a valid entry (F or D) else poulates 1
      ,DECODE(aeh.accounting_entry_status_code,'F',0,'D',0,1)
      ,ael.encumbrance_type_id  -- 4458381
      ,'N'            -- 4219869 inherit_desc_flag  Should it be from l_array?
      ,0              -- 4669308 combine header with reversal of original entry
      ,'N'            -- 4262811 mpa_accrual_entry_flag
      ,l_array_gl_date(i)    -- 5189664    aeh.accounting_date  -- 4955764
      , xdl.APPLIED_TO_APPLICATION_ID   APPLIED_TO_APPLICATION_ID
 , xdl.APPLIED_TO_ENTITY_CODE       APPLIED_TO_ENTITY_CODE
 , xdl.APPLIED_TO_ENTITY_ID     APPLIED_TO_ENTITY_ID
 , xdl.APPLIED_TO_SOURCE_ID_NUM_1   APPLIED_TO_SOURCE_ID_NUM_1
 , xdl.APPLIED_TO_SOURCE_ID_NUM_2   APPLIED_TO_SOURCE_ID_NUM_2
 , xdl.APPLIED_TO_SOURCE_ID_NUM_3   APPLIED_TO_SOURCE_ID_NUM_3
 , xdl.APPLIED_TO_SOURCE_ID_NUM_4   APPLIED_TO_SOURCE_ID_NUM_4
 , xdl.APPLIED_TO_SOURCE_ID_CHAR_1  APPLIED_TO_SOURCE_ID_CHAR_1
 , xdl.APPLIED_TO_SOURCE_ID_CHAR_2  APPLIED_TO_SOURCE_ID_CHAR_2
 , xdl.APPLIED_TO_SOURCE_ID_CHAR_3  APPLIED_TO_SOURCE_ID_CHAR_3
 , xdl.APPLIED_TO_SOURCE_ID_CHAR_4  APPLIED_TO_SOURCE_ID_CHAR_4
 , xdl.APPLIED_TO_DISTRIBUTION_TYPE APPLIED_TO_DISTRIBUTION_TYPE
 , xdl.APPLIED_TO_DIST_ID_NUM_1     APPLIED_TO_DIST_ID_NUM_1
 , xdl.APPLIED_TO_DIST_ID_NUM_2     APPLIED_TO_DIST_ID_NUM_2
 , xdl.APPLIED_TO_DIST_ID_NUM_3     APPLIED_TO_DIST_ID_NUM_3
 , xdl.APPLIED_TO_DIST_ID_NUM_4     APPLIED_TO_DIST_ID_NUM_4
 , xdl.APPLIED_TO_DIST_ID_NUM_5     APPLIED_TO_DIST_ID_NUM_5
 , xdl.APPLIED_TO_DIST_ID_CHAR_1    APPLIED_TO_DIST_ID_CHAR_1
 , xdl.APPLIED_TO_DIST_ID_CHAR_2    APPLIED_TO_DIST_ID_CHAR_2
 , xdl.APPLIED_TO_DIST_ID_CHAR_3    APPLIED_TO_DIST_ID_CHAR_3
 , xdl.APPLIED_TO_DIST_ID_CHAR_4    APPLIED_TO_DIST_ID_CHAR_4
 , xdl.APPLIED_TO_DIST_ID_CHAR_5    APPLIED_TO_DIST_ID_CHAR_5
 , xdl.alloc_to_application_id      alloc_to_application_id
 , xdl.alloc_to_entity_code     alloc_to_entity_code
 , xdl.alloc_to_source_id_num_1     alloc_to_source_id_num_1
 , xdl.alloc_to_source_id_num_2     alloc_to_source_id_num_2
 , xdl.alloc_to_source_id_num_3     alloc_to_source_id_num_3
 , xdl.alloc_to_source_id_num_4     alloc_to_source_id_num_4
 , xdl.alloc_to_source_id_char_1    alloc_to_source_id_char_1
 , xdl.alloc_to_source_id_char_2    alloc_to_source_id_char_2
 , xdl.alloc_to_source_id_char_3    alloc_to_source_id_char_3
 , xdl.alloc_to_source_id_char_4    alloc_to_source_id_char_4
 , xdl.alloc_to_distribution_type   alloc_to_distribution_type
 , xdl.alloc_to_dist_id_char_1      alloc_to_dist_id_char_1
 , xdl.alloc_to_dist_id_char_2      alloc_to_dist_id_char_2
 , xdl.alloc_to_dist_id_char_3      alloc_to_dist_id_char_3
 , xdl.alloc_to_dist_id_char_4      alloc_to_dist_id_char_4
 , xdl.alloc_to_dist_id_char_5      alloc_to_dist_id_char_5
 , xdl.alloc_to_dist_id_num_1       alloc_to_dist_id_num_1
 , xdl.alloc_to_dist_id_num_2       alloc_to_dist_id_num_2
 , xdl.alloc_to_dist_id_num_3       alloc_to_dist_id_num_3
 , xdl.alloc_to_dist_id_num_4       alloc_to_dist_id_num_4
 , xdl.alloc_to_dist_id_num_5       alloc_to_dist_id_num_5
   FROM
        xla_ae_lines              ael
       ,xla_ae_headers            aeh
       ,xla_distribution_links    xdl
       ,fnd_currencies            fcu
       ,xla_events                xe
   WHERE aeh.application_id                          = l_application_id
     AND aeh.ledger_id                               = l_array_ledger_id(i)
     AND aeh.entity_id                               = l_array_entity_id(i)
   --  AND aeh.event_number                            < l_array_event_number(i)
     AND xdl.application_id                          = aeh.application_id
     AND xdl.ae_header_id                        = aeh.ae_header_id         -- 5499367
     -- AND xdl.ref_temp_line_num                       IS NULL  -- 5019460 old
     AND NVL(xdl.temp_line_num,0)                    >= 0        -- 5019460 new
     AND ael.application_id                          = xdl.application_id
     AND ael.ae_header_id                            = xdl.ae_header_id     -- 5499367
     AND ael.ae_line_num                             = xdl.ae_line_num
     AND ael.currency_code                           = fcu.currency_code
     AND NOT EXISTS (
                SELECT /*+ no_unnest */ 1
                FROM xla_distribution_links
                WHERE ref_ae_header_id = xdl.ae_header_id
                  AND temp_line_num    = xdl.temp_line_num * -1
                  AND application_id   = xdl.application_id
               )
     AND NOT EXISTS (
                SELECT /*+ no_unnest */ 1
                FROM xla_ae_lines_gt
                WHERE ref_ae_header_id = xdl.ae_header_id
                  AND temp_line_num    = xdl.temp_line_num * -1
                  AND ledger_id        = l_array_ledger_id(i)
               )
     AND xe.application_id                  = aeh.application_id
     AND xe.event_id                        = aeh.event_id
     AND NVL(xe.budgetary_control_flag,'N') = DECODE(p_accounting_mode
                                                    ,'FUNDS_CHECK','Y'
                                                    ,'FUNDS_RESERVE','Y'
                                                    ,'N')
     AND  ((aeh.parent_ae_header_id IS NOT NULL AND aeh.accounting_entry_status_code = 'F') OR  -- 4669308
           (aeh.parent_ae_header_id IS NULL))                                                   -- 4669308
   GROUP BY
       (0 - xdl.temp_line_num)
      ,ael.ae_header_id
      ,ael.ae_line_num
      ,xdl.temp_line_num
      ,xdl.event_id
      ,aeh.balance_type_code
      ,ael.accounting_class_code
      ,xdl.event_class_code
      ,xdl.event_type_code
      ,xdl.line_definition_owner_code
      ,xdl.line_definition_code
      ,xdl.accounting_line_type_code
      ,xdl.accounting_line_code
      ,xdl.unrounded_entered_cr
      ,xdl.unrounded_entered_dr
      ,xdl.unrounded_accounted_cr
      ,xdl.unrounded_accounted_dr
      ,xdl.calculate_acctd_amts_flag
      ,xdl.calculate_g_l_amts_flag
      ,ael.gain_or_loss_flag
      ,xdl.rounding_class_code
      ,xdl.document_rounding_level
      ,xdl.doc_rounding_acctd_amt
      ,xdl.doc_rounding_entered_amt
      ,ael.code_combination_id
      ,ael.description
      ,ael.gl_transfer_mode_code
      ,xdl.merge_duplicate_code
--      ,ael.entered_cr
--      ,ael.entered_dr
--      ,ael.accounted_cr
--      ,ael.accounted_dr
      ,nvl(fcu.minimum_accountable_unit, power(10, -1* fcu.precision))
      ,ael.currency_code
      ,ael.currency_conversion_date
      ,ael.currency_conversion_rate
      ,ael.currency_conversion_type
      ,ael.statistical_amount
      ,ael.party_id
      ,ael.party_site_id
      ,ael.party_type_code
      ,ael.ussgl_transaction_code
      ,ael.jgzz_recon_ref
      ,aeh.accounting_entry_status_code
      ,ael.encumbrance_type_id
      ,xdl.tax_line_ref_id              -- bug7226263
      ,xdl.tax_summary_line_ref_id      -- bug7226263
      ,xdl.tax_rec_nrec_dist_ref_id     -- bug7226263
      ,xdl.source_distribution_id_char_1
      ,xdl.source_distribution_id_char_2
      ,xdl.source_distribution_id_char_3
      ,xdl.source_distribution_id_char_4
      ,xdl.source_distribution_id_char_5
      ,xdl.source_distribution_id_NUM_1
      ,xdl.source_distribution_id_NUM_2
      ,xdl.source_distribution_id_NUM_3
      ,xdl.source_distribution_id_NUM_4
      ,xdl.source_distribution_id_NUM_5
      ,xdl.source_distribution_type
      ,aeh.accounting_date
      , xdl.APPLIED_TO_APPLICATION_ID
 , xdl.APPLIED_TO_ENTITY_CODE
 , xdl.APPLIED_TO_ENTITY_ID
 , xdl.APPLIED_TO_SOURCE_ID_NUM_1
 , xdl.APPLIED_TO_SOURCE_ID_NUM_2
 , xdl.APPLIED_TO_SOURCE_ID_NUM_3
 , xdl.APPLIED_TO_SOURCE_ID_NUM_4
 , xdl.APPLIED_TO_SOURCE_ID_CHAR_1
 , xdl.APPLIED_TO_SOURCE_ID_CHAR_2
 , xdl.APPLIED_TO_SOURCE_ID_CHAR_3
 , xdl.APPLIED_TO_SOURCE_ID_CHAR_4
 , xdl.APPLIED_TO_DISTRIBUTION_TYPE
 , xdl.APPLIED_TO_DIST_ID_NUM_1
 , xdl.APPLIED_TO_DIST_ID_NUM_2
 , xdl.APPLIED_TO_DIST_ID_NUM_3
 , xdl.APPLIED_TO_DIST_ID_NUM_4
 , xdl.APPLIED_TO_DIST_ID_NUM_5
 , xdl.APPLIED_TO_DIST_ID_CHAR_1
 , xdl.APPLIED_TO_DIST_ID_CHAR_2
 , xdl.APPLIED_TO_DIST_ID_CHAR_3
 , xdl.APPLIED_TO_DIST_ID_CHAR_4
 , xdl.APPLIED_TO_DIST_ID_CHAR_5
 , xdl.alloc_to_application_id
 , xdl.alloc_to_entity_code
 , xdl.alloc_to_source_id_num_1
 , xdl.alloc_to_source_id_num_2
 , xdl.alloc_to_source_id_num_3
 , xdl.alloc_to_source_id_num_4
 , xdl.alloc_to_source_id_char_1
 , xdl.alloc_to_source_id_char_2
 , xdl.alloc_to_source_id_char_3
 , xdl.alloc_to_source_id_char_4
 , xdl.alloc_to_distribution_type
 , xdl.alloc_to_dist_id_char_1
 , xdl.alloc_to_dist_id_char_2
 , xdl.alloc_to_dist_id_char_3
 , xdl.alloc_to_dist_id_char_4
 , xdl.alloc_to_dist_id_char_5
 , xdl.alloc_to_dist_id_num_1
 , xdl.alloc_to_dist_id_num_2
 , xdl.alloc_to_dist_id_num_3
 , xdl.alloc_to_dist_id_num_4
 , xdl.alloc_to_dist_id_num_5
   ;
Line: 7308

SELECT min(xla_ae_headers.accounting_date)
INTO l_min_ref_event_date
FROM xla_ae_lines_gt gt1, xla_ae_headers
WHERE gt1.reversal_code = 'REVERSAL'
AND gt1.ref_event_id = xla_ae_headers.event_id;
Line: 7326

 (SELECT DISTINCT gt1.event_id, gt1.ledger_id
 FROM xla_ae_lines_gt gt1, gl_ledgers gll
 WHERE gt1.reversal_code = 'DUMMY_TR'
 AND gll.ledger_id = gt1.ledger_id
 AND gll.ledger_category_code <> 'PRIMARY'
 AND NOT EXISTS (SELECT 1
                 FROM xla_ae_lines_gt gt2
         WHERE gt2.reversal_code = 'REVERSAL'
         AND gt1.event_id = gt2.event_id
         AND gt1.ledger_id = gt2.ledger_id)
 AND EXISTS (SELECT 1
            FROM xla_ae_lines_gt gt3
            WHERE gt3.reversal_code = 'REVERSAL'
        AND gt1.event_id = gt3.event_id))

 LOOP
  --IF (C_LEVEL_STATEMENT >= g_log_level) THEN
  --    trace
  --       (p_msg      => 'WARNING - Reversal (TR) lines could not be created for event  ' || c_not_reversed_entries.event_id || ' of ledger ' || c_not_reversed_entries.ledger_id || '. Please create Manual Adjustment Entries.'
  --       ,p_level    => C_LEVEL_STATEMENT
  --       ,p_module   => l_log_module);
Line: 7371

   SELECT event_id
         ,ledger_id
         ,balance_type_code
         ,max(accounting_entry_status_code)
         ,NVL(header_num,0)                   -- 4262811c missing mpa reversal lines, 4963422 set header_num to 0
     BULK COLLECT INTO
          l_array_event_id
         ,l_array_ledger_id
         ,l_array_balance_type_code
         ,l_array_entry_status_code
         ,l_array_header_num                  -- 4262811c missing mpa reversal lines
     FROM xla_ae_lines_gt  lgt
    WHERE reversal_code = 'REVERSAL'
      AND NOT EXISTS
         (SELECT 1
            FROM xla_ae_headers_gt
           WHERE event_id = lgt.event_id
             AND ledger_id = lgt.ledger_id
          -- AND nvl(header_num, -1) = nvl(lgt.header_num, -1)  -- 4262811c missing mpa reversal lines
                                                                -- 4669308  NVL(-1) give separate headers for MPA
                                                                --          also causing XLA_AE_LINES_U1 error
             AND nvl(header_num,  0) = nvl(lgt.header_num,  0)  -- 4669308  NVL(0) combine replacement and MPA to 1 header
             AND balance_type_code = lgt.balance_type_code)
    GROUP BY event_id
            ,ledger_id
            ,header_num                       -- 4262811c missing mpa reversal lines
            ,balance_type_code;
Line: 7410

      INSERT INTO xla_ae_headers_gt
          ( ae_header_id
          , accounting_entry_status_code
          , accounting_entry_type_code
          , ledger_id
          , entity_id
          , event_id
          , event_type_code
          , accounting_date
          , product_rule_type_code
          , product_rule_code
          , product_rule_version
          , je_category_name
          , period_name
          , doc_sequence_id
          , doc_sequence_value
          , description
          , budget_version_id
          --, encumbrance_type_id
          , balance_type_code
          , amb_context_code
          , doc_category_code
          , gl_transfer_status_code
          , event_status_code
          , header_num              -- 4262811c  MPA header for line reversal
          ,accrual_reversal_flag)   -- 4262811
       (SELECT
            ae_header_id
          , l_array_entry_status_code(i)
          , accounting_entry_type_code
          , ledger_id
          , entity_id
          , event_id
          , event_type_code
          , accounting_date
          , product_rule_type_code
          , product_rule_code
          , product_rule_version
          , je_category_name
          , period_name
          , doc_sequence_id
          , doc_sequence_value
          , description
          , DECODE(l_array_balance_type_code(i),'B',budget_version_id,NULL) -- 4924492
          --, encumbrance_type_id
          , l_array_balance_type_code(i)
          , amb_context_code
          , doc_category_code
          , gl_transfer_status_code
          , decode(l_array_entry_status_code(i),XLA_AE_JOURNAL_ENTRY_PKG.C_VALID,'X','I')
          , l_array_header_num(i)    -- 4262811c  MPA header for line reversal
          , accrual_reversal_flag    -- 4262811a
       FROM xla_ae_headers_gt
      WHERE event_id = l_array_event_id(i)
        AND ledger_id = l_array_ledger_id(i)
        AND balance_type_code = 'X'
        AND NVL(header_num,0) = 0);   -- 5183946  xla_ae_headers_gt_u1 error
Line: 7471

         (p_msg      => 'Headers inserted in xla_ae_headers_gt = '||TO_CHAR(SQL%ROWCOUNT)
         ,p_level    => C_LEVEL_EVENT
         ,p_module   => l_log_module);
Line: 7488

 (SELECT DISTINCT gt1.event_id, gt1.ledger_id
 FROM xla_ae_lines_gt gt1
 WHERE gt1.reversal_code IN ('DUMMY_LR', 'DUMMY_TR')
 AND NOT EXISTS (SELECT 1
                 FROM xla_ae_lines_gt gt2
         WHERE gt2.reversal_code = 'REVERSAL'
         AND gt1.event_id = gt2.event_id
         AND gt1.ledger_id = gt2.ledger_id))


 LOOP
  IF (C_LEVEL_STATEMENT >= g_log_level) THEN
      trace
         (p_msg      => 'EVENT not reversed ' || c_not_reversed_entries.event_id || ' of ledger ' || c_not_reversed_entries.ledger_id
         ,p_level    => C_LEVEL_STATEMENT
         ,p_module   => l_log_module);
Line: 8194

        g_rec_lines.array_currency_code(g_LineNumber)  := ' ';  -- otherwise insert NULL error in currency_code
Line: 9655

  SELECT xal.calculate_acctd_amts_flag
        ,xal.currency_conversion_type
        ,TRUNC(nvl(xal.currency_conversion_date, xeg.transaction_date))
        ,decode(xal.currency_conversion_type, 'User', xal.currency_conversion_rate, -1)
        ,xal.currency_code
        ,xal.ledger_id
        ,decode( fc.derive_type, 'EURO', 'EURO', 'EMU',
                  decode( sign( trunc(nvl(xal.currency_conversion_date, xeg.transaction_date)) -
                      trunc(fc.derive_effective)), -1, 'OTHER', 'EMU'), 'OTHER' ) from_type
        ,decode( fc1.derive_type, 'EURO', 'EURO', 'EMU',
                  decode( sign( trunc(nvl(xal.currency_conversion_date, xeg.transaction_date)) -
                      trunc(fc1.derive_effective)), -1, 'OTHER', 'EMU'), 'OTHER' ) to_type
        ,decode( fc2.derive_type, 'EURO', 'EURO', 'EMU',
                  decode( sign( trunc(nvl(xal.currency_conversion_date, xeg.transaction_date)) -
                      trunc(fc2.derive_effective)), -1, 'OTHER', 'EMU'), 'OTHER' ) primary_type
    FROM xla_ae_lines_gt xal
        ,gl_ledgers gl
        ,fnd_currencies fc
        ,fnd_currencies fc1
        ,fnd_currencies fc2
        ,xla_events_gt xeg
   WHERE xal.ledger_id = gl.ledger_id
     AND gl.object_type_code      = 'L' /* only ledgers (not ledger sets) */
     AND gl.le_ledger_type_code   = 'L' /* only legal ledgers */
     AND xal.currency_code <> gl.currency_code
     AND xal.gain_or_loss_flag = 'N'
     AND xal.balance_type_code <> 'X'
     AND xal.calculate_acctd_amts_flag = 'Y'
     AND fc.currency_code = xal.currency_code
     AND fc1.currency_code = gl.currency_code
     AND fc2.currency_code = l_primary_ledger_currency
     AND xal.event_id = xeg.event_id
     AND nvl(xal.reversal_code,C_CHAR) <> C_DUMMY_PRIOR
  GROUP BY
         xal.calculate_acctd_amts_flag
        ,xal.currency_conversion_type
        ,TRUNC(nvl(xal.currency_conversion_date, xeg.transaction_date))
        ,xal.currency_conversion_rate
        ,xal.currency_code
        ,xal.ledger_id
        ,fc.derive_type
        ,fc.derive_effective
        ,fc1.derive_type
        ,fc1.derive_effective
        ,fc2.derive_type
        ,fc2.derive_effective
        ,decode(xal.currency_conversion_type, 'User', xal.currency_conversion_rate, -1)
        ;
Line: 10010

        UPDATE xla_ae_lines_gt xal
           SET currency_conversion_rate = l_array_new_rate(i)
              ,currency_conversion_type = l_array_new_type(i)
              ,currency_conversion_date = l_array_conversion_date(i)
              ,unrounded_accounted_cr   = unrounded_entered_cr * l_array_new_rate(i)
              ,unrounded_accounted_dr   = unrounded_entered_dr * l_array_new_rate(i)
         WHERE xal.ledger_id = l_array_ledger_id(i)
           AND xal.currency_code = l_array_entered_curr(i)
           AND xal.gain_or_loss_flag = 'N'
           AND xal.balance_type_code <> 'X'
           AND xal.calculate_acctd_amts_flag = 'Y'
           AND (xal.currency_conversion_type = l_array_conversion_type(i)
                 or (xal.currency_conversion_type is null and l_array_conversion_type(i) is null))
           AND l_array_conversion_date(i) =
                  (select TRUNC(nvl(xal.currency_conversion_date, xeg.transaction_date))
                     from xla_events_gt xeg
                    where xal.event_id = xeg.event_id)
           AND decode(currency_conversion_type, 'User', currency_conversion_rate, -1) = l_array_conversion_rate(i)
           AND nvl(xal.reversal_code,'dd') <> C_DUMMY_PRIOR
           ;
Line: 10033

         (p_msg      => 'ending update'
         ,p_level    => C_LEVEL_STATEMENT
         ,p_module   => l_log_module);
Line: 10061

    UPDATE xla_ae_lines_gt xal
       SET (xal.unrounded_accounted_dr
           ,xal.unrounded_accounted_cr
           ,xal.currency_conversion_rate
           )
        =
     (SELECT
        CASE xal.currency_code
        WHEN l_ledger_attrs.array_ledger_currency_code(i) THEN
          xal.entered_dr
        ELSE
          CASE l_ledger_attrs.array_ledger_type(i)
          WHEN 'PRIMARY' THEN
            CASE calculate_acctd_amts_flag
            WHEN 'Y' THEN
              CASE xal.currency_conversion_type
              WHEN 'User' THEN
                xal.entered_dr * xal.currency_conversion_rate
              ELSE
                xal.entered_dr *
                CASE decode( fc.derive_type,'EURO', 'EURO',
                     'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                     trunc(xah.accounting_date)) -trunc(fc.derive_effective)),
                   -1, 'OTHER','EMU'),'OTHER' )
                WHEN 'EMU' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )/
                     decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  WHEN 'EURO' THEN
                     1/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  END
                WHEN 'EURO' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                ELSE
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) - trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                      ra.conversion_rate*decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                END
              END
            ELSE
              xal.unrounded_accounted_dr
            END
          ELSE
            CASE xal.currency_conversion_type
            WHEN 'User' THEN
              xal.entered_dr * xal.currency_conversion_rate *
                CASE decode( fc.derive_type,'EURO', 'EURO',
                     'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                     trunc(xah.accounting_date)) -trunc(fc.derive_effective)),
                   -1, 'OTHER','EMU'),'OTHER' )
                WHEN 'EMU' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )/
                     decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  WHEN 'EURO' THEN
                     1/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  END
                WHEN 'EURO' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                ELSE
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) - trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                      ra.conversion_rate*decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                END
            ELSE
              xal.entered_dr *
                CASE decode( fc.derive_type,'EURO', 'EURO',
                     'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                     trunc(xah.accounting_date)) -trunc(fc.derive_effective)),
                   -1, 'OTHER','EMU'),'OTHER' )
                WHEN 'EMU' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )/
                     decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  WHEN 'EURO' THEN
                     1/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  END
                WHEN 'EURO' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                ELSE
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) - trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                      ra.conversion_rate*decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                END
            END
          END
        END,
        CASE xal.currency_code
        WHEN l_ledger_attrs.array_ledger_currency_code(i) THEN
          xal.entered_cr
        ELSE
          CASE l_ledger_attrs.array_ledger_type(i)
          WHEN 'PRIMARY' THEN
            CASE calculate_acctd_amts_flag
            WHEN 'Y' THEN
              CASE xal.currency_conversion_type
              WHEN 'User' THEN
                xal.entered_cr * xal.currency_conversion_rate
              ELSE
                xal.entered_cr *
                CASE decode( fc.derive_type,'EURO', 'EURO',
                     'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                     trunc(xah.accounting_date)) -trunc(fc.derive_effective)),
                   -1, 'OTHER','EMU'),'OTHER' )
                WHEN 'EMU' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )/
                     decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  WHEN 'EURO' THEN
                     1/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  END
                WHEN 'EURO' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                ELSE
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) - trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                      ra.conversion_rate*decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                END
              END
            ELSE
              xal.unrounded_accounted_cr
            END
          ELSE
            CASE xal.currency_conversion_type
            WHEN 'User' THEN
              xal.entered_cr * xal.currency_conversion_rate *
                CASE decode( fc.derive_type,'EURO', 'EURO',
                     'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                     trunc(xah.accounting_date)) -trunc(fc.derive_effective)),
                   -1, 'OTHER','EMU'),'OTHER' )
                WHEN 'EMU' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )/
                     decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  WHEN 'EURO' THEN
                     1/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  END
                WHEN 'EURO' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                ELSE
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) - trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                      ra.conversion_rate*decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                END
            ELSE
              xal.entered_cr *
                CASE decode( fc.derive_type,'EURO', 'EURO',
                     'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                     trunc(xah.accounting_date)) -trunc(fc.derive_effective)),
                   -1, 'OTHER','EMU'),'OTHER' )
                WHEN 'EMU' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )/
                     decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  WHEN 'EURO' THEN
                     1/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  END
                WHEN 'EURO' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                ELSE
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) - trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                      ra.conversion_rate*decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                END
            END
          END
        END,
        CASE xal.currency_code
        WHEN l_ledger_attrs.array_ledger_currency_code(i) THEN
          null
        ELSE
          CASE l_ledger_attrs.array_ledger_type(i)
          WHEN 'PRIMARY' THEN
            CASE calculate_acctd_amts_flag
            WHEN 'Y' THEN
              CASE xal.currency_conversion_type
              WHEN 'User' THEN
                xal.currency_conversion_rate
              ELSE
                CASE decode( fc.derive_type,'EURO', 'EURO',
                     'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                     trunc(xah.accounting_date)) -trunc(fc.derive_effective)),
                   -1, 'OTHER','EMU'),'OTHER' )
                WHEN 'EMU' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )/
                     decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  WHEN 'EURO' THEN
                     1/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  END
                WHEN 'EURO' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                ELSE
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) - trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                      ra.conversion_rate*decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                END
              END
            ELSE
              xal.currency_conversion_rate
            END
          ELSE
            CASE xal.currency_conversion_type
            WHEN 'User' THEN
              xal.currency_conversion_rate *
                CASE decode( fc.derive_type,'EURO', 'EURO',
                     'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                     trunc(xah.accounting_date)) -trunc(fc.derive_effective)),
                   -1, 'OTHER','EMU'),'OTHER' )
                WHEN 'EMU' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )/
                     decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  WHEN 'EURO' THEN
                     1/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  END
                WHEN 'EURO' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                ELSE
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) - trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                      ra.conversion_rate*decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                END
            ELSE

                CASE decode( fc.derive_type,'EURO', 'EURO',
                     'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                     trunc(xah.accounting_date)) -trunc(fc.derive_effective)),
                   -1, 'OTHER','EMU'),'OTHER' )
                WHEN 'EMU' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )/
                     decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  WHEN 'EURO' THEN
                     1/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate/decode( fc.derive_type, 'EURO', 1,
                  'EMU', fc.derive_factor,'OTHER', -1 )
                  END
                WHEN 'EURO' THEN
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) -trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                     decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                ELSE
                  CASE decode( fc1.derive_type,'EURO', 'EURO',
                       'EMU', decode( sign(nvl(trunc(xal.currency_conversion_date),
                       trunc(xah.accounting_date)) - trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                  WHEN 'EMU' THEN
                      ra.conversion_rate*decode( fc1.derive_type, 'EURO', 1,
                  'EMU', fc1.derive_factor,'OTHER', -1 )
                  ELSE ra.conversion_rate
                  END
                END

            END
          END
        END
      FROM   gl_daily_rates ra
            ,xla_ae_headers_gt xah
            ,FND_CURRENCIES fc
            ,FND_CURRENCIES fc1
      WHERE  ra.conversion_date(+)=
                 nvl(trunc(xal.currency_conversion_date), trunc(xah.accounting_date))
        AND  ra.conversion_type        (+)=
               CASE l_ledger_attrs.array_ledger_type(i)
               WHEN 'PRIMARY' THEN xal.currency_conversion_type
               ELSE
                 CASE xal.currency_conversion_type
                 WHEN 'User' THEN l_ledger_attrs.array_default_rate_type(i)
                 ELSE
                   CASE l_ledger_attrs.array_inhert_type_flag(i)
                   WHEN 'Y' THEN
                     CASE xal.currency_code
                     WHEN l_primary_ledger_currency THEN
                       l_ledger_attrs.array_default_rate_type(i)
                     ELSE xal.currency_conversion_type
                     END
                   ELSE l_ledger_attrs.array_default_rate_type(i)
                   END
                 END
               END
       AND  ra.from_currency (+)=
               CASE decode( fc.derive_type,'EURO', 'EURO','EMU',
                    decode( sign(nvl(trunc(xal.currency_conversion_date),
                    trunc(xah.accounting_date)) - trunc(fc.derive_effective)),
                    -1, 'OTHER','EMU'),'OTHER' )
               WHEN 'EMU' THEN
                 CASE decode( fc1.derive_type,'EURO', 'EURO','EMU',
                      decode( sign(nvl(trunc(xal.currency_conversion_date),
                      trunc(xah.accounting_date)) - trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                 WHEN 'OTHER' THEN l_euro
                 ELSE decode(xal.currency_conversion_type, 'User',
                          l_primary_ledger_currency, xal.currency_code)
                 END
               ELSE decode(xal.currency_conversion_type, 'User',
                          l_primary_ledger_currency, xal.currency_code)
               END
       AND    ra.to_currency (+)=
               CASE decode( fc.derive_type,'EURO', 'EURO','EMU',
                    decode( sign(nvl(trunc(xal.currency_conversion_date),
                    trunc(xah.accounting_date)) - trunc(fc.derive_effective)),
                    -1, 'OTHER','EMU'),'OTHER' )
               WHEN 'OTHER' THEN
                 CASE decode( fc1.derive_type,'EURO', 'EURO','EMU',
                      decode( sign(nvl(trunc(xal.currency_conversion_date),
                      trunc(xah.accounting_date)) - trunc(fc1.derive_effective)),
                      -1, 'OTHER','EMU'),'OTHER' )
                 WHEN 'EMU' THEN l_euro
                 ELSE l_ledger_attrs.array_ledger_currency_code(i)
                 END
               ELSE l_ledger_attrs.array_ledger_currency_code(i)
               END
       AND xal.ae_header_id = xah.ae_header_id
       AND xal.ledger_id = xah.ledger_id
       AND xal.balance_type_code = xah.balance_type_code
       AND xah.balance_type_code <> 'X'
          )
   WHERE xal.gain_or_loss_flag = 'N'
     AND xal.ledger_id = l_ledger_attrs.array_ledger_id(i)
--     AND xal.ledger_amount is null
     AND xal.balance_type_code <> 'X'
     AND xal.reversal_code is null;
Line: 10585

    UPDATE xla_ae_lines_gt xal
       SET (xal.unrounded_accounted_dr
           ,xal.unrounded_accounted_cr
           ,xal.currency_conversion_rate
           )
        =
     (SELECT
        CASE xal.currency_code
        WHEN l_ledger_attrs.array_ledger_currency_code(i) THEN
          xal.entered_dr
        ELSE
          CASE l_ledger_attrs.array_ledger_type(i)
          WHEN 'PRIMARY' THEN
            CASE calculate_acctd_amts_flag
            WHEN 'Y' THEN
              CASE xal.currency_conversion_type
              WHEN 'User' THEN
                xal.entered_dr * xal.currency_conversion_rate
              ELSE
                xal.entered_dr * ra.conversion_rate
              END
            ELSE
              xal.unrounded_accounted_dr
            END
          ELSE
            CASE xal.currency_conversion_type
            WHEN 'User' THEN
              xal.entered_dr * xal.currency_conversion_rate * ra.conversion_rate
            ELSE
              xal.entered_dr * ra.conversion_rate
            END
          END
        END,
        CASE xal.currency_code
        WHEN l_ledger_attrs.array_ledger_currency_code(i) THEN
          xal.entered_cr
        ELSE
          CASE l_ledger_attrs.array_ledger_type(i)
          WHEN 'PRIMARY' THEN
            CASE calculate_acctd_amts_flag
            WHEN 'Y' THEN
              CASE xal.currency_conversion_type
              WHEN 'User' THEN
                xal.entered_cr * xal.currency_conversion_rate
              ELSE
                xal.entered_cr * ra.conversion_rate
              END
            ELSE
              xal.unrounded_accounted_cr
            END
          ELSE
            CASE xal.currency_conversion_type
            WHEN 'User' THEN
              xal.entered_cr * xal.currency_conversion_rate * ra.conversion_rate
            ELSE
              xal.entered_cr * ra.conversion_rate
            END
          END
        END,
        CASE xal.currency_code
        WHEN l_ledger_attrs.array_ledger_currency_code(i) THEN
          null
        ELSE
          CASE l_ledger_attrs.array_ledger_type(i)
          WHEN 'PRIMARY' THEN
            CASE calculate_acctd_amts_flag
            WHEN 'Y' THEN
              CASE xal.currency_conversion_type
              WHEN 'User' THEN
                xal.currency_conversion_rate
              ELSE
                ra.conversion_rate
              END
            ELSE
              xal.currency_conversion_rate
            END
          ELSE
            CASE xal.currency_conversion_type
            WHEN 'User' THEN
              xal.currency_conversion_rate * ra.conversion_rate
            ELSE
              ra.conversion_rate
            END
          END
        END
      FROM   gl_daily_rates ra
            ,xla_ae_headers_gt xah
      WHERE  ra.conversion_date(+)=
                 nvl(trunc(xal.currency_conversion_date), trunc(xah.accounting_date))
        AND  ra.conversion_type        (+)=
               CASE l_ledger_attrs.array_ledger_type(i)
               WHEN 'PRIMARY' THEN xal.currency_conversion_type
               ELSE
                 CASE xal.currency_conversion_type
                 WHEN 'User' THEN l_ledger_attrs.array_default_rate_type(i)
                 ELSE
                   CASE l_ledger_attrs.array_inhert_type_flag(i)
                   WHEN 'Y' THEN
                     CASE xal.currency_code
                     WHEN l_primary_ledger_currency THEN
                       l_ledger_attrs.array_default_rate_type(i)
                     ELSE xal.currency_conversion_type
                     END
                   ELSE l_ledger_attrs.array_default_rate_type(i)
                   END
                 END
               END
       AND  ra.from_currency (+)= decode(xal.currency_conversion_type, 'User',
                          l_primary_ledger_currency, xal.currency_code)
       AND    ra.to_currency (+)= l_ledger_attrs.array_ledger_currency_code(i)
       AND xal.ae_header_id = xah.ae_header_id
       AND xal.ledger_id = xah.ledger_id
       AND xal.balance_type_code = xah.balance_type_code
       AND xah.balance_type_code <> 'X'
          )
   WHERE xal.gain_or_loss_flag = 'N'
     AND xal.ledger_id = l_ledger_attrs.array_ledger_id(i)
     AND xal.balance_type_code <> 'X'
     AND xal.reversal_code is null;
Line: 10759

   SELECT ledger_id
         ,ae_header_id
      FROM XLA_AE_LINES_GT xal2
     WHERE nvl(xal2.gain_or_loss_flag, 'N') = 'Y'
       AND xal2.balance_type_code          <> 'X'
       AND xal2.calculate_g_l_amts_flag    = 'Y'
       AND xal2.reversal_code              IS NULL
    GROUP BY ledger_id, ae_header_id;
Line: 10768

 SELECT nvl(sum(xal2.unrounded_accounted_dr), 0)
                    - nvl(sum(xal2.unrounded_accounted_cr), 0)
          ,min(xal2.currency_code)
          ,max(xal2.currency_code)
          ,min(xal2.extract_line_num)
          ,ledger_id
          ,ae_header_id
          ,balance_type_code
          ,gain_or_loss_ref
          ,event_id
    FROM XLA_AE_LINES_GT xal2
    WHERE nvl(xal2.gain_or_loss_flag, 'N') = 'N'
      AND xal2.balance_type_code               <> 'X'
      AND xal2.reversal_code               is NULL
   HAVING nvl(sum(xal2.unrounded_accounted_dr), 0) <> nvl(sum(xal2.unrounded_accounted_cr), 0)  -- 5745199
 GROUP BY ledger_id, ae_header_id, balance_type_code, gain_or_loss_ref, event_id;
Line: 10823

      UPDATE /*+ index(xal XLA_AE_LINES_GT_N3)*/ xla_ae_lines_gt xal  -- 6658161
     SET (xal.unrounded_accounted_cr
         , xal.unrounded_entered_cr
         , xal.unrounded_accounted_dr
         , xal.unrounded_entered_dr
            ,xal.currency_code
            ,xal.balance_type_code
         ) =
            (SELECT /*+ index(xal2 XLA_AE_LINES_GT_N4)*/  -- 6658161,6727907
                  case sign(nvl(sum(xal2.unrounded_accounted_dr), 0)
                    - nvl(sum(xal2.unrounded_accounted_cr), 0))
                  when -1 then null
                  else nvl(sum(xal2.unrounded_accounted_dr), 0)
                               - nvl(sum(xal2.unrounded_accounted_cr), 0)
                  end
                  , case sign(nvl(sum(xal2.unrounded_accounted_dr), 0)
                    - nvl(sum(xal2.unrounded_accounted_cr), 0))
                  when -1 then null
                  else 0
                  end
                  , case sign(nvl(sum(xal2.unrounded_accounted_dr), 0)
                    - nvl(sum(xal2.unrounded_accounted_cr), 0))
                  when -1 then
                     nvl(sum(xal2.unrounded_accounted_cr), 0)
                     - nvl(sum(xal2.unrounded_accounted_dr), 0)
                  else null
                  end
                  , case sign(nvl(sum(xal2.unrounded_accounted_dr), 0)
                    - nvl(sum(xal2.unrounded_accounted_cr), 0))
                  when -1 then 0
                  else null
                  end
                 ,case
          when xal.currency_code = min(xal2.currency_code)
          then max(xal2.currency_code)
          else min(xal2.currency_code)
          end
                 ,case
                  when nvl(sum(xal2.unrounded_accounted_dr), 0)
                          - nvl(sum(xal2.unrounded_accounted_cr), 0) = 0
                  THEN 'X'
                  ELSE
                    CASE
                    WHEN xal.extract_line_num = min(xal2.extract_line_num)
                    then xal.balance_type_code
                    else 'X'
                    END
                  END
               FROM xla_ae_lines_gt xal2
              WHERE xal2.ae_header_id = xal.ae_header_id
                AND xal2.balance_type_code = xal.balance_type_code
                AND xal2.gain_or_loss_ref = xal.gain_or_loss_ref
                AND xal2.ledger_id = xal.ledger_id
                AND xal2.event_id = xal.event_id
                AND nvl(xal2.gain_or_loss_flag, 'N') = 'N'
                AND xal2.balance_type_code <> 'X'
                AND xal2.reversal_code IS NULL)
   WHERE nvl(xal.gain_or_loss_flag, 'N') = 'Y'
     AND balance_type_code <> 'X'
     AND xal.calculate_g_l_amts_flag = 'Y'
     AND xal.reversal_code  is NULL
     AND xal.ae_header_id = l_array_ae_header_id(Idx)
     AND xal.ledger_id = l_array_ledger_id(Idx);
Line: 10888

         UPDATE xla_ae_lines_gt xal
         SET xal.unrounded_accounted_cr =
                     CASE sign(l_res_array_accounted_amount(Idx))
                     WHEN -1 THEN NULL
                     ELSE l_res_array_accounted_amount(Idx)
                     END
            ,xal.unrounded_entered_cr =
                     CASE sign(l_res_array_accounted_amount(Idx))
                     WHEN -1 THEN NULL
                     ELSE 0
                     END
            ,xal.unrounded_accounted_dr =
                     CASE sign(l_res_array_accounted_amount(Idx))
                     WHEN -1 THEN 0-l_res_array_accounted_amount(Idx)
                     ELSE NULL
                     END
            ,xal.unrounded_entered_dr =
                     CASE sign(l_res_array_accounted_amount(Idx))
                     WHEN -1 THEN 0
                     ELSE NULL
                     END
            ,xal.currency_code =
                     DECODE (l_res_array_min_currency_code(Idx),
                               xal.currency_code,
                               l_res_array_max_currency_code(Idx),
                               l_res_array_min_currency_code(Idx))
            ,xal.balance_type_code = decode(l_res_array_accounted_amount(Idx), 0, 'X',
                                        decode(xal.extract_line_num,
                                               l_res_array_extract_line_num(Idx),
                                               xal.balance_type_code,
                                               'X'))
     WHERE nvl(xal.gain_or_loss_flag, 'N') = 'Y'
       AND balance_type_code               <> 'X'
       AND xal.calculate_g_l_amts_flag     = 'Y'
       AND xal.reversal_code               is NULL
       AND xal.ae_header_id                = l_array_ae_header_id(Idx)
       AND xal.balance_type_code           = l_array_balance_type_code(Idx)
       AND xal.gain_or_loss_ref            = l_array_gain_or_loss_ref(Idx)
       AND xal.ledger_id                   = l_array_ledger_id(Idx)
       AND (xal.currency_code               <> l_res_array_min_currency_code(Idx)
            OR xal.currency_code           <> l_res_array_max_currency_code(Idx))
       AND xal.event_id                    = l_array_event_id(Idx);
Line: 10935

    UPDATE /*+ index(xal2 XLA_AE_LINES_GT_N3)*/ xla_ae_lines_gt xal
       SET xal.currency_code =
            (SELECT /*+ index(xal2 XLA_AE_LINES_GT_N4)*/  max(currency_code)
               FROM xla_ae_lines_gt xal2
              WHERE xal2.ae_header_id = xal.ae_header_id
                AND xal2.balance_type_code <> 'X'
                AND xal2.gain_or_loss_ref = xal.gain_or_loss_ref
                AND xal2.ledger_id = xal.ledger_id
                AND xal2.event_id = xal.event_id
                AND nvl(xal2.gain_or_loss_flag, 'N') = 'N'
                AND xal2.reversal_code = C_DUMMY_PRIOR)
     WHERE xal.gain_or_loss_flag = 'Y'
       AND balance_type_code <> 'X'
       AND xal.calculate_g_l_amts_flag = 'Y'
       AND xal.reversal_code  is NULL
       and (xal.ae_header_id, balance_type_code, gain_or_loss_ref, ledger_id, event_id)
           in
           (select /*+ index(xal2 XLA_AE_LINES_GT_N4)*/ ae_header_id, balance_type_code, gain_or_loss_ref, ledger_id, event_id
              from xla_ae_lines_gt xal3
              where xal3.ae_header_id = xal.ae_header_id
                AND xal3.balance_type_code <> 'X'
                AND xal3.gain_or_loss_ref = xal.gain_or_loss_ref
                AND xal3.ledger_id = xal.ledger_id
                AND xal3.event_id = xal.event_id
                AND nvl(xal3.gain_or_loss_flag, 'N') = 'N'
                and xal3.reversal_code = C_DUMMY_PRIOR);
Line: 10969

         (p_msg      => 'Before update...'
         ,p_level    => C_LEVEL_PROCEDURE
         ,p_module   => l_log_module);
Line: 10974

  UPDATE xla_ae_lines_gt xal
     --SET xal.temp_line_num = 0 -- It casues XLA_AE_LINES_GT_U1 violation when
                                 -- there are 2 extract lines and g/l is on
     SET balance_type_code = 'X'
   WHERE xal.gain_or_loss_flag = 'Y'
     AND nvl(xal.unrounded_accounted_cr, 0) = 0
     AND xal.reversal_code  is NULL;
Line: 11135

   SELECT gt.ROW_ID
               ,gt.code_combination_id
               ,gt.description
               ,gt.currency_code
               ,gt.currency_conversion_rate
               ,gt.currency_conversion_type
               ,gt.currency_conversion_date
               ,gt.entered_currency_mau
               ,gt.unrounded_entered_cr
               ,gt.unrounded_entered_dr
               ,gt.party_type_code
               ,gt.party_id
               ,gt.party_site_id
               ,gt.encumbrance_type_id
               ,gt.code_combination_status_code
               ,gt.ref_event_id
               ,gt.temp_ref_ae_header_id
               ,gt.ref_ae_line_num
               ,gt.ref_temp_line_num
               ,gt.bflow_prior_entry_status_code
               ,gt.applied_to_entity_id
   FROM (SELECT /*+Leading(xalg xte xah xdl) use_nl(xalg xte xah xdl) */
               xalg.ROWID                                                                       ROW_ID
               , RANK() OVER ( PARTITION BY xalg.ROWID
                               ORDER BY xdl.ae_header_id desc, xdl.ae_line_num ASC  )             line_rank
               ,(NVL(xal.merge_code_combination_id,xal.code_combination_id))                    code_combination_id
               ,(DECODE(xalg.inherit_desc_flag, 'Y', xal.description, xalg.description))         description
               ,(xal.currency_code)                                                              currency_code
               ,(DECODE(xal.currency_code
                      ,xla_accounting_cache_pkg.GetValueChar('XLA_CURRENCY_CODE',xalg.ledger_id)
                      ,NULL
                      ,xal.currency_conversion_rate))                                            currency_conversion_rate
               ,(DECODE(xal.currency_code
                      ,xla_accounting_cache_pkg.GetValueChar('XLA_CURRENCY_CODE',xalg.ledger_id)
                      ,NULL
                      ,xal.currency_conversion_type))                                            currency_conversion_type
               ,(DECODE(xal.currency_code
                      ,xla_accounting_cache_pkg.GetValueChar('XLA_CURRENCY_CODE',xalg.ledger_id)
                      ,NULL
                      ,xal.currency_conversion_date))                                            currency_conversion_date
               ,(xla_accounting_cache_pkg.GetCurrencyMau(xal.currency_code))                     entered_currency_mau
               ,(DECODE(xdl.calculate_acctd_amts_flag
                      ,'N', DECODE(xalg.currency_code
                                 ,xla_accounting_cache_pkg.GetValueChar('XLA_CURRENCY_CODE',xalg.ledger_id)
                                 ,NVL(xalg.unrounded_accounted_cr,xalg.unrounded_entered_cr)
                                 ,xalg.unrounded_entered_cr)
                     ,xalg.unrounded_entered_cr)  )                                               unrounded_entered_cr
               ,(DECODE(xdl.calculate_acctd_amts_flag
                     ,'N', DECODE(xalg.currency_code
                                 ,xla_accounting_cache_pkg.GetValueChar('XLA_CURRENCY_CODE',xalg.ledger_id)
                                 ,NVL(xalg.unrounded_accounted_dr,xalg.unrounded_entered_dr)
                                 ,xalg.unrounded_entered_dr)
                     ,xalg.unrounded_entered_dr))                                               unrounded_entered_dr
               ,(xal.party_type_code)                                                          party_type_code
               ,(NVL(xal.merge_party_id,xal.party_id))                                        party_id
               ,(NVL(xal.merge_party_site_id,xal.party_site_id))                              party_site_id
               ,(xal.encumbrance_type_id)                                                      encumbrance_type_id
               ,C_CREATED                                                                       code_combination_status_code
               ,(xdl.event_id)                                                                 ref_event_id
               ,(xdl.ae_header_id)                                                             temp_ref_ae_header_id
               ,(xal.ae_line_num)                                                              ref_ae_line_num
               ,(xdl.temp_line_num)                                                            ref_temp_line_num
               ,(DECODE(xalg.currency_code,xal.currency_code,xah.accounting_entry_status_code,
                        DECODE(xalg.bflow_applied_to_amount, NULL, 'X', xah.accounting_entry_status_code))) bflow_prior_entry_status_code
               ,(xah.entity_id)                                                                applied_to_entity_id
           FROM   xla_ae_lines_gt          xalg
                 ,xla_transaction_entities xte
                 ,xla_ae_headers    xah
                 ,xla_distribution_links   xdl
                 ,xla_ae_lines      xal
--               ,xla_ledger_relationships_v  xlr
--               ,xla_gl_ledgers_v            xgl
--               ,xla_ledger_options          xlo
           WHERE  xah.application_id               = xdl.application_id
           AND    xah.ae_header_id                 = xdl.ae_header_id
           AND    xal.application_id               = xdl.application_id
           AND    xal.ae_header_id                 = xdl.ae_header_id
           AND    xal.ae_line_num                  = xdl.ae_line_num
           AND    xal.business_class_code          = xalg.business_class_code
           AND    xdl.source_distribution_type     = xalg.bflow_distribution_type
           AND    xdl.source_distribution_id_num_1   = NVL(xalg.bflow_dist_id_num_1,-99)
           AND    NVL(xdl.source_distribution_id_num_2,-99)   = NVL(xalg.bflow_dist_id_num_2,-99)
           AND    NVL(xdl.source_distribution_id_num_3,-99)   = NVL(xalg.bflow_dist_id_num_3,-99)
           AND    NVL(xdl.source_distribution_id_num_4,-99)   = NVL(xalg.bflow_dist_id_num_4,-99)
           AND    NVL(xdl.source_distribution_id_num_5,-99)   = NVL(xalg.bflow_dist_id_num_5,-99)
           AND    NVL(xdl.source_distribution_id_char_1,' ') = NVL(xalg.bflow_dist_id_char_1,' ')
           AND    NVL(xdl.source_distribution_id_char_2,' ') = NVL(xalg.bflow_dist_id_char_2,' ')
           AND    NVL(xdl.source_distribution_id_char_3,' ') = NVL(xalg.bflow_dist_id_char_3,' ')
           AND    NVL(xdl.source_distribution_id_char_4,' ') = NVL(xalg.bflow_dist_id_char_4,' ')
           AND    NVL(xdl.source_distribution_id_char_5,' ') = NVL(xalg.bflow_dist_id_char_5,' ')
           AND    xah.parent_ae_header_id IS NULL
           --
           -- exclude reversed entries
           -- When running in BC mode, draft reversal entries are not considered
       -- ignore exclude reversal for AP.6647974/6614418
           AND NOT EXISTS (SELECT /*+ no_unnest */  1
                             FROM xla_distribution_links xdl4
                                , xla_ae_headers xah4
                            WHERE xdl4.ref_ae_header_id = xdl.ae_header_id
                              AND xdl4.application_id   = xdl.application_id
                              AND xdl4.temp_line_num    = xdl.temp_line_num * -1
                              AND xah4.application_id   = xdl4.application_id
                              AND xah4.ae_header_id     = xdl4.ae_header_id
                  AND xah4.application_id <> 200
                  AND xdl4.application_id <> 200
                              AND (xah4.accounting_entry_status_code = 'F' OR
                                   (xah4.accounting_entry_status_code = 'D' AND
                                    p_accounting_mode = 'D' AND
                                    p_bc_mode = 'NONE')))
           AND    xdl.application_id       = xalg.bflow_application_id
           --
--         AND    xgl.ledger_id          = xalg.ledger_id
--         AND    xlr.ledger_id          = xgl.ledger_id
           AND    xte.application_id     = xalg.bflow_application_id
           AND    xte.entity_code        = xalg.bflow_entity_code
           AND    xte.ledger_id          = p_ledger_id
--         AND    xte.ledger_id          = DECODE(xla_accounting_cache_pkg.GetValueChar('VALUATION_METHOD_FLAG'),
--                                                        'N', xlr.primary_ledger_id,
--                                                        DECODE(xlr.ledger_category_code
--                                                              ,'ALC', xlr.primary_ledger_id
--                                                              ,DECODE(NVL(xlo.capture_event_flag,'N'),'N',xlr.primary_ledger_id
--                                                              ,xlr.ledger_id)))  -- 5204178 requires secondary ledger event
--         AND    xlo.ledger_id (+)      = xgl.ledger_id
--         AND    xlo.application_id (+) = g_application_id
           --
           AND    NVL(xte.source_id_int_1,-99)   = NVL(xalg.bflow_source_id_num_1,-99)
           AND    NVL(xte.source_id_int_2,-99)   = NVL(xalg.bflow_source_id_num_2,-99)
           AND    NVL(xte.source_id_int_3,-99)   = NVL(xalg.bflow_source_id_num_3,-99)
           AND    NVL(xte.source_id_int_4,-99)   = NVL(xalg.bflow_source_id_num_4,-99)
           AND    NVL(xte.source_id_char_1,' ') = NVL(xalg.bflow_source_id_char_1,' ')
           AND    NVL(xte.source_id_char_2,' ') = NVL(xalg.bflow_source_id_char_2,' ')
           AND    NVL(xte.source_id_char_3,' ') = NVL(xalg.bflow_source_id_char_3,' ')
           AND    NVL(xte.source_id_char_4,' ') = NVL(xalg.bflow_source_id_char_4,' ')
           --
           AND    xah.application_id              = xte.application_id
           AND    xah.ledger_id                   = xalg.ledger_id
           AND    xah.entity_id                   = xte.entity_id
           AND    xah.balance_type_code           = xalg.balance_type_code
           --
           AND    xdl.event_id                    = xah.event_id
           --
           AND    xah.accounting_entry_status_code  IN ('F', DECODE(p_bc_mode,'NONE',p_accounting_mode,'F'))
           AND    xalg.reversal_code = C_DUMMY_PRIOR
          ) gt
   WHERE   gt.line_rank = 1;
Line: 11283

   SELECT ae_header_id,
          event_id,
          ledger_id,
          balance_type_code,
          temp_line_num
     FROM xla_ae_lines_gt
    WHERE reversal_code = C_DUMMY_PRIOR
      AND bflow_prior_entry_status_code IS NOT NULL AND bflow_prior_entry_status_code <> 'X';  -- 5132302  if applied to amt is null
Line: 11297

     SELECT ae_header_id
         ,xal.temp_line_num
         ,xal.event_id
         ,xal.ledger_id
         ,xal.bflow_prior_entry_status_code
         ,xal.balance_type_code
         ,xal.entity_id
         ,fav.application_name
     ,'N'
     ,gl.ledger_category_code
     ,glp.start_date

     FROM xla_ae_lines_gt xal,
          fnd_application_vl fav,
      gl_ledgers gl,
      gl_period_statuses glp
    WHERE ((reversal_code = C_DUMMY_PRIOR
      AND  (bflow_prior_entry_status_code IS NULL OR NVL(bflow_prior_entry_status_code,'N') = 'X'))  -- 5132302
      OR  reversal_code = C_MPA_PRIOR_ENTRY)      -- 4655713b
      AND fav.application_id(+)  = xal.bflow_application_id
      AND xal.ledger_id = gl.ledger_id
      AND glp.period_name = gl.first_ledger_period_name
      AND glp.ledger_id = gl.ledger_id
      AND glp.application_id = 101;
Line: 11445

       FOR l IN (SELECT * FROM xla_ae_lines_gt WHERE reversal_code = C_DUMMY_PRIOR) LOOP
         trace(p_msg      => 'event_id='||l.event_id||
                             ' ae_header_id='||l.ae_header_id
              ,p_level    => C_LEVEL_STATEMENT
              ,p_module   => l_log_module);
Line: 11529

          UPDATE xla_ae_lines_gt
          SET  code_combination_id = l_array_ccid (i)
              ,description         = l_array_description (i)
              ,temp_currency_code  = l_array_currency_code (i)     -- upstream currency code
              ,currency_conversion_rate = l_array_curr_conversion_rate (i)
              ,currency_conversion_type = l_array_curr_conversion_type (i)
              ,currency_conversion_date = TRUNC(l_array_curr_conversion_date (i))
              ,entered_currency_mau     = l_array_currency_mau (i)
              ,unrounded_entered_cr     = l_array_unrounded_entered_cr (i)
              ,unrounded_entered_dr     = l_array_unrounded_entered_dr (i)
              ,party_type_code          = l_array_party_type_code (i)
              ,party_id                 = l_array_party_id (i)
              ,party_site_id            = l_array_party_site_id (i)
              ,encumbrance_type_id      = l_array_encumbrance_type_id (i)
              ,code_combination_status_code = l_array_ccid_status_code (i)
              ,ref_event_id             = l_array_ref_event_id (i)
              ,temp_ref_ae_header_id    = l_array_temp_ref_ae_header_id (i)
              ,ref_ae_line_num          = l_array_ref_ae_line_num (i)
              ,ref_temp_line_num        = l_array_ref_temp_line_num (i)
              ,bflow_prior_entry_status_code = l_array_bflow_pe_status_code (i)
              ,applied_to_entity_id     = l_array_pe_entity_id (i)
          WHERE rowid = l_array_row_id (i);
Line: 11557

     UPDATE xla_ae_lines_gt xalg
      SET (code_combination_id
          ,description
          ,temp_currency_code       -- upstream currency code
          ,currency_conversion_rate
          ,currency_conversion_type
          ,currency_conversion_date
          ,entered_currency_mau      -- 4482069
          ,unrounded_entered_cr      -- 4482069
          ,unrounded_entered_dr      -- 4482069
          ,party_type_code
          ,party_id
          ,party_site_id
          ,encumbrance_type_id
          ,code_combination_status_code
          ,ref_event_id
          ,temp_ref_ae_header_id
          ,ref_ae_line_num
          ,ref_temp_line_num
          ,bflow_prior_entry_status_code
          ,applied_to_entity_id
         ) =
        (SELECT MIN(NVL(xal3.merge_code_combination_id,xal3.code_combination_id))     -- 4967526
               ,MIN(DECODE(xalg.inherit_desc_flag, 'Y', xal3.description, xalg.description))
               ,MIN(xal3.currency_code)
               ,MIN(DECODE(xal3.currency_code
                      ,xla_accounting_cache_pkg.GetValueChar('XLA_CURRENCY_CODE',xalg.ledger_id)
                      ,NULL
                      ,xal3.currency_conversion_rate))
               ,MIN(DECODE(xal3.currency_code
                      ,xla_accounting_cache_pkg.GetValueChar('XLA_CURRENCY_CODE',xalg.ledger_id)
                      ,NULL
                      ,xal3.currency_conversion_type))
               ,MIN(DECODE(xal3.currency_code
                      ,xla_accounting_cache_pkg.GetValueChar('XLA_CURRENCY_CODE',xalg.ledger_id)
                      ,NULL
                      ,xal3.currency_conversion_date))
               ---------------------------------------------------------------------------
               -- 4482069 error XLA_AP_INVALID_AMT_BASE
               -- Occurs when upstream is invalid so c_bflow_valid_lines
               -- is not found hence entered amounts will not calc.
               -- Upstream invalid need not prevent this value to be assigned.
               ---------------------------------------------------------------------------
               ,MIN(xla_accounting_cache_pkg.GetCurrencyMau(xal3.currency_code))
               ---------------------------------------------------------------------------
               -- 4482069 based on calculate_acctd_amts_flag and transaction currency
               -- Note: In theory, when calculate_acctd_amts_flag is 'No', entered and
               --       accounted amt should be the same (therefore we need not recalc
               --       accounted amt.) But just in case, perform the following copy to
               --       make sure they will be the same.
               ---------------------------------------------------------------------------
               ,MIN(DECODE(calculate_acctd_amts_flag
                      ,'N', DECODE(xalg.currency_code
                                 ,xla_accounting_cache_pkg.GetValueChar('XLA_CURRENCY_CODE',xalg.ledger_id)
                                 ,NVL(xalg.unrounded_accounted_cr,xalg.unrounded_entered_cr)
                                 ,xalg.unrounded_entered_cr)
                     ,xalg.unrounded_entered_cr)  )
               ---------------------------------------------------------------------------
               -- 4482069 based on calculate_acctd_amts_flag and transaction currency
               ---------------------------------------------------------------------------
               ,MIN(DECODE(calculate_acctd_amts_flag
                     ,'N', DECODE(xalg.currency_code
                                 ,xla_accounting_cache_pkg.GetValueChar('XLA_CURRENCY_CODE',xalg.ledger_id)
                                 ,NVL(xalg.unrounded_accounted_dr,xalg.unrounded_entered_dr)
                                 ,xalg.unrounded_entered_dr)
                     ,xalg.unrounded_entered_dr))
              ,MIN(xal3.party_type_code)
              ,MIN(NVL(xal3.merge_party_id,xal3.party_id))             -- 4967526
              ,MIN(NVL(xal3.merge_party_site_id,xal3.party_site_id))   -- 4967526
              ,MIN(xal3.encumbrance_type_id)
              ,C_CREATED
              ,MIN(xdl3.event_id)
              ,MIN(xdl3.ae_header_id)
              ,MIN(xal3.ae_line_num)
              ,MIN(xdl3.temp_line_num)
            --,MIN(xah3.accounting_entry_status_code)
              ,MIN(DECODE(xalg.currency_code,xal3.currency_code,xah3.accounting_entry_status_code,                            -- 5132302
                                             DECODE(xalg.bflow_applied_to_amount, NULL, 'X', xah3.accounting_entry_status_code))) -- 5132302
              ,MIN(xah3.entity_id)
          FROM xla_ae_lines xal3
             , xla_ae_headers xah3
             , xla_distribution_links xdl3
         WHERE xah3.application_id               = xdl3.application_id
           AND xah3.ae_header_id                 = xdl3.ae_header_id
           AND xal3.application_id               = xdl3.application_id
           AND xal3.ae_header_id                 = xdl3.ae_header_id
           AND xal3.ae_line_num                  = xdl3.ae_line_num
           AND xal3.business_class_code          = xalg.business_class_code -- 4336173
           AND xdl3.source_distribution_type     = xalg.bflow_distribution_type
           AND NVL(xdl3.source_distribution_id_num_1,C_NUM)   = NVL(xalg.bflow_dist_id_num_1,C_NUM)
           AND NVL(xdl3.source_distribution_id_num_2,C_NUM)   = NVL(xalg.bflow_dist_id_num_2,C_NUM)
           AND NVL(xdl3.source_distribution_id_num_3,C_NUM)   = NVL(xalg.bflow_dist_id_num_3,C_NUM)
           AND NVL(xdl3.source_distribution_id_num_4,C_NUM)   = NVL(xalg.bflow_dist_id_num_4,C_NUM)
           AND NVL(xdl3.source_distribution_id_num_5,C_NUM)   = NVL(xalg.bflow_dist_id_num_5,C_NUM)
           AND NVL(xdl3.source_distribution_id_char_1,C_CHAR) = NVL(xalg.bflow_dist_id_char_1,C_CHAR)
           AND NVL(xdl3.source_distribution_id_char_2,C_CHAR) = NVL(xalg.bflow_dist_id_char_2,C_CHAR)
           AND NVL(xdl3.source_distribution_id_char_3,C_CHAR) = NVL(xalg.bflow_dist_id_char_3,C_CHAR)
           AND NVL(xdl3.source_distribution_id_char_4,C_CHAR) = NVL(xalg.bflow_dist_id_char_4,C_CHAR)
           AND NVL(xdl3.source_distribution_id_char_5,C_CHAR) = NVL(xalg.bflow_dist_id_char_5,C_CHAR)
           AND xah3.parent_ae_header_id IS NULL -- 4655713b  MPA/Accrual Reversal lines cannot be used as prior entries
           -- exclude reversed entries
           AND NOT EXISTS (SELECT 1
                             FROM xla_distribution_links xdl4
                                , xla_ae_headers xah4
                            WHERE xdl4.ref_ae_header_id = xdl3.ae_header_id
                              AND xdl4.temp_line_num    = xdl3.temp_line_num * -1
                              AND xah4.application_id   = xdl4.application_id
                              AND xah4.ae_header_id     = xdl4.ae_header_id
                              AND (xah4.accounting_entry_status_code = 'F' OR
                                   (xah4.accounting_entry_status_code = 'D' AND
                                    p_accounting_mode = 'D' AND
                                    p_bc_mode = 'NONE')))
           AND xdl3.application_id       = xalg.bflow_application_id
           AND xdl3.ae_header_id =
        (SELECT MAX(xdl.ae_header_id)
          FROM xla_transaction_entities xte
             , xla_ae_headers           xah
             , xla_distribution_links   xdl
             , xla_ae_lines             xal
             , xla_ledger_relationships_v  xlr   -- 4478604
             , xla_gl_ledgers_v            xgl   -- 4478604
             , xla_ledger_options   xlo  -- 5204178
         WHERE xgl.ledger_id            = xalg.ledger_id -- 4478604
           AND xlr.ledger_id            = xgl.ledger_id -- 4478604
           AND xte.application_id       = xalg.bflow_application_id
           AND xte.entity_code          = xalg.bflow_entity_code
           AND xte.ledger_id            = DECODE(xla_accounting_cache_pkg.GetValueChar('VALUATION_METHOD_FLAG'),
                                                  'N', xlr.primary_ledger_id,
                                                  DECODE(xlr.ledger_category_code
                                                        ,'ALC', xlr.primary_ledger_id
                                                        ,DECODE(NVL(xlo.capture_event_flag,'N'),'N',xlr.primary_ledger_id
                                                        ,xlr.ledger_id)))  -- 5204178 requires secondary ledger event
            AND  xlo.ledger_id (+)      = xgl.ledger_id
            AND  xlo.application_id (+) = g_application_id
            --
            AND NVL(xte.source_id_int_1,C_NUM)   = NVL(xalg.bflow_source_id_num_1,C_NUM)
            AND NVL(xte.source_id_int_2,C_NUM)   = NVL(xalg.bflow_source_id_num_2,C_NUM)
            AND NVL(xte.source_id_int_3,C_NUM)   = NVL(xalg.bflow_source_id_num_3,C_NUM)
            AND NVL(xte.source_id_int_4,C_NUM)   = NVL(xalg.bflow_source_id_num_4,C_NUM)
            AND NVL(xte.source_id_char_1,C_CHAR) = NVL(xalg.bflow_source_id_char_1,C_CHAR)
            AND NVL(xte.source_id_char_2,C_CHAR) = NVL(xalg.bflow_source_id_char_2,C_CHAR)
            AND NVL(xte.source_id_char_3,C_CHAR) = NVL(xalg.bflow_source_id_char_3,C_CHAR)
            AND NVL(xte.source_id_char_4,C_CHAR) = NVL(xalg.bflow_source_id_char_4,C_CHAR)
            --
            AND xah.application_id               = xte.application_id
            AND xah.ledger_id                    = xalg.ledger_id
            AND xah.entity_id                    = xte.entity_id
            AND xah.balance_type_code            = xalg.balance_type_code
            --
            AND xdl.application_id               = xah.application_id
            AND xdl.event_id                     = xah.event_id
            AND xdl.ae_header_id                 = xah.ae_header_id
            AND xdl.source_distribution_type     = xalg.bflow_distribution_type
            AND NVL(xdl.source_distribution_id_num_1,C_NUM)   = NVL(xalg.bflow_dist_id_num_1,C_NUM)
            AND NVL(xdl.source_distribution_id_num_2,C_NUM)   = NVL(xalg.bflow_dist_id_num_2,C_NUM)
            AND NVL(xdl.source_distribution_id_num_3,C_NUM)   = NVL(xalg.bflow_dist_id_num_3,C_NUM)
            AND NVL(xdl.source_distribution_id_num_4,C_NUM)   = NVL(xalg.bflow_dist_id_num_4,C_NUM)
            AND NVL(xdl.source_distribution_id_num_5,C_NUM)   = NVL(xalg.bflow_dist_id_num_5,C_NUM)
            AND NVL(xdl.source_distribution_id_char_1,C_CHAR) = NVL(xalg.bflow_dist_id_char_1,C_CHAR)
            AND NVL(xdl.source_distribution_id_char_2,C_CHAR) = NVL(xalg.bflow_dist_id_char_2,C_CHAR)
            AND NVL(xdl.source_distribution_id_char_3,C_CHAR) = NVL(xalg.bflow_dist_id_char_3,C_CHAR)
            AND NVL(xdl.source_distribution_id_char_4,C_CHAR) = NVL(xalg.bflow_dist_id_char_4,C_CHAR)
            AND NVL(xdl.source_distribution_id_char_5,C_CHAR) = NVL(xalg.bflow_dist_id_char_5,C_CHAR)
            --
            AND xal.business_class_code           = xalg.business_class_code -- 4336173
            AND xal.application_id                = xdl.application_id
            AND xal.ae_header_id                  = xdl.ae_header_id
            AND xal.ae_line_num                   = xdl.ae_line_num
            -- bug 4946123 - limit the status of the prior entry
            -- Final entries are always considered
            -- If running in BC mode, draft is not considered
            -- Otherwise, draft is considered only if running in draft mode
            AND xah.accounting_entry_status_code  IN ('F', DECODE(p_bc_mode,'NONE',p_accounting_mode,'F'))
            -- exclude reversed entries
            -- When running in BC mode, draft reversal entries are not considered
            AND NOT EXISTS (SELECT 1
                              FROM xla_distribution_links xdl2
                                 , xla_ae_headers xah2
                             WHERE xdl2.ref_ae_header_id = xdl.ae_header_id
                               AND xdl2.temp_line_num    = xdl.temp_line_num * -1
                               AND xah2.application_id   = xdl2.application_id
                               AND xah2.ae_header_id     = xdl2.ae_header_id
                               AND (xah2.accounting_entry_status_code = 'F' OR
                                    (xah2.accounting_entry_status_code = 'D' AND
                                     p_accounting_mode = 'D' AND
                                     p_bc_mode = 'NONE')))
            ))
      WHERE xalg.reversal_code = C_DUMMY_PRIOR;
Line: 11767

           UPDATE /*+ index(xalg xla_ae_lines_gt_n4) */  xla_ae_lines_gt xalg   -- 6990256
              SET ref_ae_header_id  = temp_ref_ae_header_id,
                  currency_code     = temp_currency_code,
                  reversal_code     = null,                -- 5499367
                 (unrounded_entered_cr         -- 5132302
                 ,unrounded_entered_dr         -- 5132302
                 ,unrounded_accounted_cr
                 ,unrounded_accounted_dr) =
                 ----------------------------------------------------------------------------------------------------------
                 -- Modified for bug 4482069
                 -- Normally, business flow should be setup between different sides.  So just in case, we first try
                 -- to use the amount from the opposite side.  And if it is null, take amount from same side.
                 --
                 -- Modify for bug 4656703
                 -- Modify for bug 4873615 - Handle the 'divided by zero' error
                 --
                 -- Modify for bug 5132302 - calculate accounted amt from applied_to_amt if currencies are different
                 ----------------------------------------------------------------------------------------------------------
                 (SELECT  DECODE(xalg.currency_code,xalg.temp_currency_code, xalg.unrounded_entered_cr,
                                      DECODE(xalg.unrounded_entered_cr,NULL,NULL,NVL(xalg.bflow_applied_to_amount,xalg.unrounded_entered_cr)))
                         ,DECODE(xalg.currency_code,xalg.temp_currency_code, xalg.unrounded_entered_dr,
                                      DECODE(xalg.unrounded_entered_dr,NULL,NULL,NVL(xalg.bflow_applied_to_amount,xalg.unrounded_entered_dr)))
                         ,DECODE(xalg.override_acctd_amt_flag,'Y'
                     ,xalg.unrounded_accounted_cr,
                                (DECODE (xal.unrounded_accounted_dr,NULL
                                ,CASE WHEN xal.unrounded_entered_cr <> 0
                                      THEN DECODE(xalg.currency_code,xalg.temp_currency_code,
                                           (xal.unrounded_accounted_cr/xal.unrounded_entered_cr)*xalg.unrounded_entered_cr,
                                           (xal.unrounded_accounted_cr/xal.unrounded_entered_cr)* DECODE(xalg.unrounded_entered_cr,NULL,NULL,
                                                                                 NVL(xalg.bflow_applied_to_amount,xalg.unrounded_entered_cr)))
                                      ELSE xalg.unrounded_entered_cr END
                                ,CASE WHEN xal.unrounded_entered_dr <> 0
                                      THEN DECODE(xalg.currency_code,xalg.temp_currency_code,
                                           (xal.unrounded_accounted_dr/xal.unrounded_entered_dr)*xalg.unrounded_entered_cr,
                                           (xal.unrounded_accounted_dr/xal.unrounded_entered_dr)* DECODE(xalg.unrounded_entered_cr,NULL,NULL,
                                                                                 NVL(xalg.bflow_applied_to_amount,xalg.unrounded_entered_cr)))
                                      ELSE xalg.unrounded_entered_cr END))
                                 )

                         ,DECODE(xalg.override_acctd_amt_flag,'Y'
                     ,xalg.unrounded_accounted_dr,
                                (DECODE (xal.unrounded_accounted_cr,NULL
                                ,CASE WHEN xal.unrounded_entered_dr <> 0
                                      THEN DECODE(xalg.currency_code,xalg.temp_currency_code,
                                           (xal.unrounded_accounted_dr/xal.unrounded_entered_dr)*xalg.unrounded_entered_dr,
                                           (xal.unrounded_accounted_dr/xal.unrounded_entered_dr)* DECODE(xalg.unrounded_entered_dr,NULL,NULL,
                                                                                 NVL(xalg.bflow_applied_to_amount,xalg.unrounded_entered_dr)))
                                      ELSE xalg.unrounded_entered_dr END
                                ,CASE WHEN xal.unrounded_entered_cr <> 0
                                      THEN DECODE(xalg.currency_code,xalg.temp_currency_code,
                                           (xal.unrounded_accounted_cr/xal.unrounded_entered_cr)*xalg.unrounded_entered_dr,
                                           (xal.unrounded_accounted_cr/xal.unrounded_entered_cr)* DECODE(xalg.unrounded_entered_dr,NULL,NULL,
                                                                                 NVL(xalg.bflow_applied_to_amount,xalg.unrounded_entered_dr)))
                                      ELSE xalg.unrounded_entered_dr END))
                                 )

                     FROM xla_ae_lines xal
                    WHERE xal.application_id              = xalg.bflow_application_id
                      AND xal.ae_header_id                = xalg.temp_ref_ae_header_id
                      AND xal.ae_line_num                 = xalg.ref_ae_line_num),
                  entered_currency_mau = xla_accounting_cache_pkg.GetCurrencyMau(temp_currency_code),
                  (segment1,  segment2,  segment3,  segment4,  segment5,  segment6,  segment7,  segment8,  segment9,  segment10
                  ,segment11, segment12, segment13, segment14, segment15, segment16, segment17, segment18, segment19, segment20
                  ,segment21, segment22, segment23, segment24, segment25, segment26, segment27, segment28, segment29, segment30) =
                  (SELECT gcc.segment1,  gcc.segment2,  gcc.segment3,  gcc.segment4,  gcc.segment5
                         ,gcc.segment6,  gcc.segment7,  gcc.segment8,  gcc.segment9,  gcc.segment10
                         ,gcc.segment11, gcc.segment12, gcc.segment13, gcc.segment14, gcc.segment15
                         ,gcc.segment16, gcc.segment17, gcc.segment18, gcc.segment19, gcc.segment20
                         ,gcc.segment21, gcc.segment22, gcc.segment23, gcc.segment24, gcc.segment25
                         ,gcc.segment26, gcc.segment27, gcc.segment28, gcc.segment29, gcc.segment30
                     FROM gl_code_combinations gcc
                    WHERE gcc.code_combination_id = xalg.code_combination_id),
                         (anc_id_1,  anc_id_2,  anc_id_3,  anc_id_4,  anc_id_5
                         ,anc_id_6,  anc_id_7,  anc_id_8,  anc_id_9,  anc_id_10
                         ,anc_id_11, anc_id_12, anc_id_13, anc_id_14, anc_id_15
                         ,anc_id_16, anc_id_17, anc_id_18, anc_id_19, anc_id_20
                         ,anc_id_21, anc_id_22, anc_id_23, anc_id_24, anc_id_25
                         ,anc_id_26, anc_id_27, anc_id_28, anc_id_29, anc_id_30
                         ,anc_id_31, anc_id_32, anc_id_33, anc_id_34, anc_id_35
                         ,anc_id_36, anc_id_37, anc_id_38, anc_id_39, anc_id_40
                         ,anc_id_41, anc_id_42, anc_id_43, anc_id_44, anc_id_45
                         ,anc_id_46, anc_id_47, anc_id_48, anc_id_49, anc_id_50
                         ,anc_id_51, anc_id_52, anc_id_53, anc_id_54, anc_id_55
                         ,anc_id_56, anc_id_57, anc_id_58, anc_id_59, anc_id_60
                         ,anc_id_61, anc_id_62, anc_id_63, anc_id_64, anc_id_65
                         ,anc_id_66, anc_id_67, anc_id_68, anc_id_69, anc_id_70
                         ,anc_id_71, anc_id_72, anc_id_73, anc_id_74, anc_id_75
                         ,anc_id_76, anc_id_77, anc_id_78, anc_id_79, anc_id_80
                         ,anc_id_81, anc_id_82, anc_id_83, anc_id_84, anc_id_85
                         ,anc_id_86, anc_id_87, anc_id_88, anc_id_89, anc_id_90
                         ,anc_id_91, anc_id_92, anc_id_93, anc_id_94, anc_id_95
                         ,anc_id_96, anc_id_97, anc_id_98, anc_id_99, anc_id_100) =
                 (SELECT
                          MAX(DECODE(rank,1,anc_id))   ,MAX(DECODE(rank,2,anc_id))
                         ,MAX(DECODE(rank,3,anc_id))   ,MAX(DECODE(rank,4,anc_id))
                         ,MAX(DECODE(rank,5,anc_id))   ,MAX(DECODE(rank,6,anc_id))
                         ,MAX(DECODE(rank,7,anc_id))   ,MAX(DECODE(rank,8,anc_id))
                         ,MAX(DECODE(rank,9,anc_id))   ,MAX(DECODE(rank,10,anc_id))
                         ,MAX(DECODE(rank,11,anc_id))  ,MAX(DECODE(rank,12,anc_id))
                         ,MAX(DECODE(rank,13,anc_id))  ,MAX(DECODE(rank,14,anc_id))
                         ,MAX(DECODE(rank,15,anc_id))  ,MAX(DECODE(rank,16,anc_id))
                         ,MAX(DECODE(rank,17,anc_id))  ,MAX(DECODE(rank,18,anc_id))
                         ,MAX(DECODE(rank,19,anc_id))  ,MAX(DECODE(rank,20,anc_id))
                         ,MAX(DECODE(rank,21,anc_id))  ,MAX(DECODE(rank,22,anc_id))
                         ,MAX(DECODE(rank,23,anc_id))  ,MAX(DECODE(rank,24,anc_id))
                         ,MAX(DECODE(rank,25,anc_id))  ,MAX(DECODE(rank,26,anc_id))
                         ,MAX(DECODE(rank,27,anc_id))  ,MAX(DECODE(rank,28,anc_id))
                         ,MAX(DECODE(rank,29,anc_id))  ,MAX(DECODE(rank,30,anc_id))
                         ,MAX(DECODE(rank,31,anc_id))  ,MAX(DECODE(rank,32,anc_id))
                         ,MAX(DECODE(rank,33,anc_id))  ,MAX(DECODE(rank,34,anc_id))
                         ,MAX(DECODE(rank,35,anc_id))  ,MAX(DECODE(rank,36,anc_id))
                         ,MAX(DECODE(rank,37,anc_id))  ,MAX(DECODE(rank,38,anc_id))
                         ,MAX(DECODE(rank,39,anc_id))  ,MAX(DECODE(rank,40,anc_id))
                         ,MAX(DECODE(rank,41,anc_id))  ,MAX(DECODE(rank,42,anc_id))
                         ,MAX(DECODE(rank,43,anc_id))  ,MAX(DECODE(rank,44,anc_id))
                         ,MAX(DECODE(rank,45,anc_id))  ,MAX(DECODE(rank,46,anc_id))
                         ,MAX(DECODE(rank,47,anc_id))  ,MAX(DECODE(rank,48,anc_id))
                         ,MAX(DECODE(rank,49,anc_id))  ,MAX(DECODE(rank,50,anc_id))
                         ,MAX(DECODE(rank,51,anc_id))  ,MAX(DECODE(rank,52,anc_id))
                         ,MAX(DECODE(rank,53,anc_id))  ,MAX(DECODE(rank,54,anc_id))
                         ,MAX(DECODE(rank,55,anc_id))  ,MAX(DECODE(rank,56,anc_id))
                         ,MAX(DECODE(rank,57,anc_id))  ,MAX(DECODE(rank,58,anc_id))
                         ,MAX(DECODE(rank,59,anc_id))  ,MAX(DECODE(rank,60,anc_id))
                         ,MAX(DECODE(rank,61,anc_id))  ,MAX(DECODE(rank,62,anc_id))
                         ,MAX(DECODE(rank,63,anc_id))  ,MAX(DECODE(rank,64,anc_id))
                         ,MAX(DECODE(rank,65,anc_id))  ,MAX(DECODE(rank,66,anc_id))
                         ,MAX(DECODE(rank,67,anc_id))  ,MAX(DECODE(rank,68,anc_id))
                         ,MAX(DECODE(rank,69,anc_id))  ,MAX(DECODE(rank,70,anc_id))
                         ,MAX(DECODE(rank,71,anc_id))  ,MAX(DECODE(rank,72,anc_id))
                         ,MAX(DECODE(rank,73,anc_id))  ,MAX(DECODE(rank,74,anc_id))
                         ,MAX(DECODE(rank,75,anc_id))  ,MAX(DECODE(rank,76,anc_id))
                         ,MAX(DECODE(rank,77,anc_id))  ,MAX(DECODE(rank,78,anc_id))
                         ,MAX(DECODE(rank,79,anc_id))  ,MAX(DECODE(rank,80,anc_id))
                         ,MAX(DECODE(rank,81,anc_id))  ,MAX(DECODE(rank,82,anc_id))
                         ,MAX(DECODE(rank,83,anc_id))  ,MAX(DECODE(rank,84,anc_id))
                         ,MAX(DECODE(rank,85,anc_id))  ,MAX(DECODE(rank,86,anc_id))
                         ,MAX(DECODE(rank,87,anc_id))  ,MAX(DECODE(rank,88,anc_id))
                         ,MAX(DECODE(rank,89,anc_id))  ,MAX(DECODE(rank,90,anc_id))
                         ,MAX(DECODE(rank,91,anc_id))  ,MAX(DECODE(rank,92,anc_id))
                         ,MAX(DECODE(rank,93,anc_id))  ,MAX(DECODE(rank,94,anc_id))
                         ,MAX(DECODE(rank,95,anc_id))  ,MAX(DECODE(rank,96,anc_id))
                         ,MAX(DECODE(rank,97,anc_id))  ,MAX(DECODE(rank,98,anc_id))
                         ,MAX(DECODE(rank,99,anc_id))  ,MAX(DECODE(rank,100,anc_id))
                    FROM (SELECT ae_header_id
                                ,ae_line_num
                                ,analytical_criterion_code      || '(]' ||
                                 analytical_criterion_type_code || '(]' ||
                                 amb_context_code               || '(]' ||
                                 ac1                            || '(]' ||
                                 ac2                            || '(]' ||
                                 ac3                            || '(]' ||
                                 ac4                            || '(]' ||
                                 ac5           anc_id
                                ,RANK() OVER (
                                  PARTITION BY ae_header_id, ae_line_num
                                      ORDER BY analytical_criterion_code
                                              ,analytical_criterion_type_code
                                              ,amb_context_code
                                              ,ac1
                                              ,ac2
                                              ,ac3
                                              ,ac4
                                              ,ac5) rank
             FROM xla_ae_line_acs) aed
            WHERE aed.ae_header_id        = xalg.temp_ref_ae_header_id
              AND aed.ae_line_num         = xalg.ref_ae_line_num)
            WHERE balance_type_code = l_array_balance_type_code(i)
              AND ae_header_id      = l_array_ae_header_id(i)
              AND event_id          = l_array_event_id(i)
              AND ledger_id         = l_array_ledger_id(i)
              AND temp_line_num     = l_array_line_num(i);
Line: 11945

      SELECT /*+ Leading (xal1,xah1,xal2) index(xah1 XLA_AE_HEADERS_GT_U1) index(xal2 XLA_AE_LINES_GT_N2) no_expand */  -- 5666366
             xal2.segment1,  xal2.segment2,  xal2.segment3,  xal2.segment4,  xal2.segment5
            ,xal2.segment6,  xal2.segment7,  xal2.segment8,  xal2.segment9,  xal2.segment10
            ,xal2.segment11, xal2.segment12, xal2.segment13, xal2.segment14, xal2.segment15
            ,xal2.segment16, xal2.segment17, xal2.segment18, xal2.segment19, xal2.segment20
            ,xal2.segment21, xal2.segment22, xal2.segment23, xal2.segment24, xal2.segment25
            ,xal2.segment26, xal2.segment27, xal2.segment28, xal2.segment29, xal2.segment30
            ,xal2.code_combination_id
            ,xal2.code_combination_status_code
            ,DECODE(NVL(xal1.inherit_desc_flag,'N'), 'Y', xal2.description, xal1.description)
            ,xal2.currency_code   -- upstream
            ,xal1.currency_code   -- downstream  5132302
            ,xal2.currency_conversion_rate
            ,xal2.currency_conversion_type
            ,xal2.currency_conversion_date
            ,xal2.entered_currency_mau
            ,xal2.party_type_code
            ,xal2.party_id
            ,xal2.party_site_id
            ,xal2.encumbrance_type_id
            -- CALCULATE_ACCTD_AMTS_FLAG is ignored for Prior Entry (see bug 4482069 for details). Same applies to MPA lines.
            ,DECODE (xal3.unrounded_accounted_dr,NULL
                    ,CASE WHEN xal3.unrounded_entered_cr <> 0
                          THEN xal3.unrounded_accounted_cr/xal3.unrounded_entered_cr
                          ELSE 1 END
                    ,CASE WHEN xal3.unrounded_entered_dr <> 0
                          THEN xal3.unrounded_accounted_dr/xal3.unrounded_entered_dr
                          ELSE 1 END)
            ,DECODE (xal3.unrounded_accounted_cr,NULL
                    ,CASE WHEN xal3.unrounded_entered_dr <> 0
                          THEN xal3.unrounded_accounted_dr/xal3.unrounded_entered_dr
                          ELSE 1 END
                    ,CASE WHEN xal3.unrounded_entered_cr <> 0
                          THEN xal3.unrounded_accounted_cr/xal3.unrounded_entered_cr
                          ELSE 1 END)
            -- join conditions
            ,xal1.ledger_id
            ,xal1.ref_ae_header_id
            ,xal1.temp_line_num
            ,xal1.ae_header_id
            ,xal1.header_num
            ,DECODE(xah1.parent_ae_line_num,NULL,'Y','N')  -- accrual_reversal_flag
      BULK COLLECT INTO
             l_array_mpa_segment1 ,l_array_mpa_segment2 ,l_array_mpa_segment3 ,l_array_mpa_segment4 ,l_array_mpa_segment5
            ,l_array_mpa_segment6 ,l_array_mpa_segment7 ,l_array_mpa_segment8 ,l_array_mpa_segment9 ,l_array_mpa_segment10
            ,l_array_mpa_segment11 ,l_array_mpa_segment12 ,l_array_mpa_segment13 ,l_array_mpa_segment14 ,l_array_mpa_segment15
            ,l_array_mpa_segment16 ,l_array_mpa_segment17 ,l_array_mpa_segment18 ,l_array_mpa_segment19 ,l_array_mpa_segment20
            ,l_array_mpa_segment21 ,l_array_mpa_segment22 ,l_array_mpa_segment23 ,l_array_mpa_segment24 ,l_array_mpa_segment25
            ,l_array_mpa_segment26 ,l_array_mpa_segment27 ,l_array_mpa_segment28 ,l_array_mpa_segment29 ,l_array_mpa_segment30
            ,l_array_mpa_ccid
            ,l_array_mpa_ccid_status_code
            ,l_array_mpa_description
            ,l_array_mpa_currency_code
            ,l_array_mpa_currency_code_pe  -- 5132302
            ,l_array_mpa_curr_conv_rate
            ,l_array_mpa_curr_conv_type
            ,l_array_mpa_curr_conv_date
            ,l_array_mpa_currency_mau
            ,l_array_mpa_party_type_code
            ,l_array_mpa_party_id
            ,l_array_mpa_party_site_id
            ,l_array_mpa_encum_type_id
            ,l_array_mpa_acct_cr_ratio
            ,l_array_mpa_acct_dr_ratio
            -- join conditions
            ,l_array_mpa_ledger_id
            ,l_array_mpa_ref_ae_header_id
            ,l_array_mpa_temp_line_num
            ,l_array_mpa_ae_header_id
            ,l_array_mpa_header_num
            ,l_array_acc_rev_flag
      FROM  xla_ae_lines_gt   xal2   -- original downstream line
           ,xla_ae_headers_gt xah1   -- original downstream header
           ,xla_ae_lines_gt   xal1   -- recognition lines
           ,xla_ae_lines      xal3   -- upstream line
      WHERE xal2.source_distribution_type                  = xal1.source_distribution_type
      AND   NVL(xal2.source_distribution_id_num_1,C_NUM)   = NVL(xal1.source_distribution_id_num_1,C_NUM)
      AND   NVL(xal2.source_distribution_id_num_2,C_NUM)   = NVL(xal1.source_distribution_id_num_2,C_NUM)
      AND   NVL(xal2.source_distribution_id_num_3,C_NUM)   = NVL(xal1.source_distribution_id_num_3,C_NUM)
      AND   NVL(xal2.source_distribution_id_num_4,C_NUM)   = NVL(xal1.source_distribution_id_num_4,C_NUM)
      AND   NVL(xal2.source_distribution_id_num_5,C_NUM)   = NVL(xal1.source_distribution_id_num_5,C_NUM)
      AND   NVL(xal2.source_distribution_id_char_1,C_CHAR) = NVL(xal1.source_distribution_id_char_1,C_CHAR)
      AND   NVL(xal2.source_distribution_id_char_2,C_CHAR) = NVL(xal1.source_distribution_id_char_2,C_CHAR)
      AND   NVL(xal2.source_distribution_id_char_3,C_CHAR) = NVL(xal1.source_distribution_id_char_3,C_CHAR)
      AND   NVL(xal2.source_distribution_id_char_4,C_CHAR) = NVL(xal1.source_distribution_id_char_4,C_CHAR)
      AND   NVL(xal2.source_distribution_id_char_5,C_CHAR) = NVL(xal1.source_distribution_id_char_5,C_CHAR)
      AND   xal2.event_id                      = xal1.event_id
      AND   xal2.ledger_id                     = xal1.ledger_id
      AND   xal2.balance_type_code             = xal1.balance_type_code
      AND   xal2.event_class_code              = xal1.event_class_code
      AND   xal2.event_type_code               = xal1.event_type_code
      AND   xal2.line_definition_owner_code    = xal1.line_definition_owner_code
      AND   xal2.line_definition_code          = xal1.line_definition_code
      AND   xal2.ACCOUNTING_LINE_TYPE_CODE     = xal1.ACCOUNTING_LINE_TYPE_CODE
      AND   xal2.ACCOUNTING_LINE_CODE          = xal1.ACCOUNTING_LINE_CODE
      --
      AND   xah1.ledger_id        = xal1.ledger_id
      AND   xah1.ae_header_id     = xal1.ae_header_id
      AND   xah1.header_num       = xal1.header_num
      AND ((xah1.parent_ae_line_num IS NOT NULL AND xal2.temp_line_num = xah1.parent_ae_line_num)  -- MPA
      OR    xah1.parent_ae_line_num IS NULL)                                                       -- Accrual Reversal
      --  5666366  -------------------------------------
      AND XAL1.BALANCE_TYPE_CODE  = XAH1.BALANCE_TYPE_CODE
      AND XAL2.AE_HEADER_ID       = XAL1.AE_HEADER_ID
      --------------------------------------------------
      AND   xal2.header_num       = 0
      AND   xal1.reversal_code    = C_MPA_PRIOR_ENTRY
      --
      AND   xal2.bflow_prior_entry_status_code IS NOT NULL AND xal2.bflow_prior_entry_status_code <> 'X'  -- 5132302
      --
      AND   xal3.application_id   = xal2.bflow_application_id
      AND   xal3.ae_header_id     = xal2.temp_ref_ae_header_id
      AND   xal3.ae_line_num      = xal2.ref_ae_line_num;
Line: 12078

         FOR i IN (select * from xla_ae_Lines_gt where reversal_code=C_MPA_PRIOR_ENTRY) LOOP
            trace
            (p_msg      => 'ae_lines_gt  PE dist ledger='||i.ledger_id||' ref_ae_header='||i.ref_ae_header_id||
                           ' temp_line='||i.temp_line_num||' ae_header='||i.ae_header_id||' header_num='||i.header_num||
                           ' bflow='||i.business_method_code||
                           ' curr='||i.currency_code||' applied_amt='||i.bflow_applied_to_amount||  -- 5132302
                           ' conv_type='||i.currency_conversion_type||' conv_rate='||i.currency_conversion_rate||
                           ' udr='||i.unrounded_ACCOUNTED_DR||' ucr='||i.unrounded_ACCOUNTED_CR||' switch='||i.switch_side_flag||
                           ' line='||i.line_definition_code|| ' dist='||i.source_distribution_type||' rev='||i.reversal_code||
                           ' n1='||i.source_distribution_id_num_1|| ' n2='||i.source_distribution_id_num_2||
                           ' n3='||i.source_distribution_id_num_3|| ' n4='||i.source_distribution_id_num_4||
                           ' n5='||i.source_distribution_id_num_5|| ' c1='||i.source_distribution_id_char_1||
                           ' c2='||i.source_distribution_id_char_2|| ' c3='||i.source_distribution_id_char_3||
                           ' c4='||i.source_distribution_id_char_4|| ' c5='||i.source_distribution_id_char_5||
                           ' bal='||i.balance_type_code|| ' side='||i.natural_side_code||
                           ' rev='||i.reversal_code
            ,p_level    => C_LEVEL_STATEMENT
            ,p_module   => l_log_module);
Line: 12098

         FOR i IN (select * from xla_ae_Lines_gt where reversal_code=C_MPA_PRIOR_ENTRY) LOOP
             trace
            (p_msg      => '                seg s1='||i.segment1||' s2='||i.segment2|| ' s3='||i.segment3||' s4='||i.segment4||
                                       ' s5='||i.segment5||' s6='||i.segment6|| ' s7='||i.segment7||' s8='||i.segment8||
                                       ' s9='||i.segment9||' s10='||i.segment10|| ' s11='||i.segment11||' s12='||i.segment12||
                                       ' s13='||i.segment13||' s14='||i.segment14|| ' s15='||i.segment15||' s16='||i.segment16||
                                       ' s17='||i.segment17||' s18='||i.segment18|| ' s19='||i.segment19||' s20='||i.segment20||
                                       ' s21='||i.segment21||' s22='||i.segment22|| ' s23='||i.segment23||' s24='||i.segment24||
                                       ' s25='||i.segment25||' s26='||i.segment26|| ' s27='||i.segment27||' s28='||i.segment28||
                                       ' s29='||i.segment29||' s30='||i.segment30||' ccid='||i.code_combination_id
            ,p_level    => C_LEVEL_STATEMENT
            ,p_module   => l_log_module);
Line: 12119

         UPDATE xla_ae_lines_gt xal
         SET      segment1  = l_array_mpa_segment1(i)
                , segment2  = l_array_mpa_segment2(i)
                , segment3  = l_array_mpa_segment3(i)
                , segment4  = l_array_mpa_segment4(i)
                , segment5  = l_array_mpa_segment5(i)
                , segment6  = l_array_mpa_segment6(i)
                , segment7  = l_array_mpa_segment7(i)
                , segment8  = l_array_mpa_segment8(i)
                , segment9  = l_array_mpa_segment9(i)
                , segment10 = l_array_mpa_segment10(i)
                , segment11 = l_array_mpa_segment11(i)
                , segment12 = l_array_mpa_segment12(i)
                , segment13 = l_array_mpa_segment13(i)
                , segment14 = l_array_mpa_segment14(i)
                , segment15 = l_array_mpa_segment15(i)
                , segment16 = l_array_mpa_segment16(i)
                , segment17 = l_array_mpa_segment17(i)
                , segment18 = l_array_mpa_segment18(i)
                , segment19 = l_array_mpa_segment19(i)
                , segment20 = l_array_mpa_segment20(i)
                , segment21 = l_array_mpa_segment21(i)
                , segment22 = l_array_mpa_segment22(i)
                , segment23 = l_array_mpa_segment23(i)
                , segment24 = l_array_mpa_segment24(i)
                , segment25 = l_array_mpa_segment25(i)
                , segment26 = l_array_mpa_segment26(i)
                , segment27 = l_array_mpa_segment27(i)
                , segment28 = l_array_mpa_segment28(i)
                , segment29 = l_array_mpa_segment29(i)
                , segment30 = l_array_mpa_segment30(i)
                , description              = l_array_mpa_description(i)
                , code_combination_id      = l_array_mpa_ccid(i)
                , code_combination_status_code = DECODE(l_array_mpa_ccid(i),NULL,C_PROCESSING     -- 4655713b used in Create_CCID
                                                                                ,l_array_mpa_ccid_status_code(i))
                , reversal_code            = null
                --
                , currency_code            = l_array_mpa_currency_code(i)
                , currency_conversion_rate = l_array_mpa_curr_conv_rate(i)
                , currency_conversion_type = l_array_mpa_curr_conv_type(i)
                , currency_conversion_date = TRUNC(l_array_mpa_curr_conv_date(i))
                , party_type_code          = l_array_mpa_party_type_code(i)
                , party_id                 = l_array_mpa_party_id(i)
                , party_site_id            = l_array_mpa_party_site_id(i)
                , encumbrance_type_id      = l_array_mpa_encum_type_id(i)
                , unrounded_entered_cr     = DECODE(l_array_mpa_currency_code(i),l_array_mpa_currency_code_pe(i),  -- 5132302
                                                    unrounded_entered_cr,
                                                    DECODE(unrounded_entered_cr,NULL,NULL,NVL(bflow_applied_to_amount,unrounded_entered_cr)))
                , unrounded_entered_dr     = DECODE(l_array_mpa_currency_code(i),l_array_mpa_currency_code_pe(i),  -- 5132302
                                                    unrounded_entered_dr,
                                                    DECODE(unrounded_entered_dr,NULL,NULL,NVL(bflow_applied_to_amount,unrounded_entered_dr)))
                , unrounded_accounted_cr   = DECODE(l_array_mpa_currency_code(i),l_array_mpa_currency_code_pe(i),  -- 5132302
                                                    unrounded_entered_cr*l_array_mpa_acct_cr_ratio(i),
                                                    DECODE(unrounded_entered_cr,NULL,NULL,
                                                           NVL(bflow_applied_to_amount,unrounded_entered_cr))*l_array_mpa_acct_cr_ratio(i))
                , unrounded_accounted_dr   = DECODE(l_array_mpa_currency_code(i),l_array_mpa_currency_code_pe(i),  -- 5132302
                                                    unrounded_entered_dr*l_array_mpa_acct_dr_ratio(i),
                                                    DECODE(unrounded_entered_dr,NULL,NULL,
                                                           NVL(bflow_applied_to_amount,unrounded_entered_dr))*l_array_mpa_acct_dr_ratio(i))
           WHERE xal.ledger_id             = l_array_mpa_ledger_id(i)
           AND   xal.ref_ae_header_id      = l_array_mpa_ref_ae_header_id(i)
           AND   xal.temp_line_num         = l_array_mpa_temp_line_num(i)  -- Acc-Rev or MPA-Accrual line which is a PRIOR_ENTR
           AND   xal.ae_header_id          = l_array_mpa_ae_header_id(i)
           AND   NVL(xal.header_num,0)     = l_array_mpa_header_num(i);
Line: 12194

         UPDATE xla_ae_lines_gt xal
         SET      currency_code            = DECODE(l_array_acc_rev_flag(i),'N',l_array_mpa_currency_code(i)
                                                                               ,currency_code)
                , currency_conversion_rate = DECODE(l_array_acc_rev_flag(i),'N',l_array_mpa_curr_conv_rate(i)
                                                                               ,currency_conversion_rate)
                , currency_conversion_type = DECODE(l_array_acc_rev_flag(i),'N',l_array_mpa_curr_conv_type(i)
                                                                               ,currency_conversion_type)
                , currency_conversion_date = DECODE(l_array_acc_rev_flag(i),'N',TRUNC(l_array_mpa_curr_conv_date(i))
                                                                               ,TRUNC(currency_conversion_date))
                , party_type_code          = DECODE(l_array_acc_rev_flag(i),'N',l_array_mpa_party_type_code(i)
                                                                               ,party_type_code)
                , party_id                 = DECODE(l_array_acc_rev_flag(i),'N',l_array_mpa_party_id(i)
                                                                               ,party_id)
                , party_site_id            = DECODE(l_array_acc_rev_flag(i),'N',l_array_mpa_party_site_id(i)
                                                                               ,party_site_id)
         --       , encumbrance_type_id      = DECODE(l_array_acc_rev_flag(i),'N',encumbrance_type_id,l_array_mpa_encum_type_id(i)
         --                                                                      ,encumbrance_type_id)
                , entered_currency_mau     = DECODE(l_array_acc_rev_flag(i),'N',l_array_mpa_currency_mau(i)
                                                                               ,entered_currency_mau)
                , unrounded_entered_cr     = DECODE(l_array_acc_rev_flag(i),'N',DECODE(l_array_mpa_currency_code(i),l_array_mpa_currency_code_pe(i),  -- 5132302
                                                    unrounded_entered_cr,
                                                    DECODE(unrounded_entered_cr,NULL,NULL,NVL(bflow_applied_to_amount,unrounded_entered_cr)))
                                                   ,unrounded_entered_cr)
                , unrounded_entered_dr     = DECODE(l_array_acc_rev_flag(i),'N',DECODE(l_array_mpa_currency_code(i),l_array_mpa_currency_code_pe(i),  -- 5132302
                                                    unrounded_entered_dr,
                                                    DECODE(unrounded_entered_dr,NULL,NULL,NVL(bflow_applied_to_amount,unrounded_entered_dr)))
                                                   ,unrounded_entered_dr)
                , unrounded_accounted_cr   = DECODE(l_array_acc_rev_flag(i),'N',DECODE(l_array_mpa_currency_code(i),l_array_mpa_currency_code_pe(i),  -- 5132302
                                                                                       unrounded_entered_cr*l_array_mpa_acct_cr_ratio(i),
                                                                                       DECODE(unrounded_entered_cr,NULL,NULL,
                                                                                       NVL(bflow_applied_to_amount,unrounded_entered_cr)*l_array_mpa_acct_cr_ratio(i)))
                                                                               ,unrounded_accounted_cr)
                , unrounded_accounted_dr   = DECODE(l_array_acc_rev_flag(i),'N',DECODE(l_array_mpa_currency_code(i),l_array_mpa_currency_code_pe(i),  -- 5132302
                                                                                       unrounded_entered_dr*l_array_mpa_acct_dr_ratio(i),
                                                                                       DECODE(unrounded_entered_dr,NULL,NULL,
                                                                                       NVL(bflow_applied_to_amount,unrounded_entered_dr)*l_array_mpa_acct_dr_ratio(i)))
                                                                               ,unrounded_accounted_dr)
           WHERE xal.ledger_id         = l_array_mpa_ledger_id(i)
           AND   xal.ref_ae_header_id  = l_array_mpa_ref_ae_header_id(i)
           AND   xal.ae_header_id      = l_array_mpa_ae_header_id(i)
           AND   NVL(xal.header_num,0) = l_array_mpa_header_num(i);
Line: 12269

      SELECT glp.start_date
       INTO l_primary_start_date
      FROM  gl_period_statuses glp
           ,gl_ledgers gl
      WHERE glp.period_name = gl.first_ledger_period_name
      AND  glp.ledger_id = gl.ledger_id
      AND  glp.application_id = 101
      AND  gl.ledger_id = p_ledger_id;
Line: 12360

       DELETE FROM XLA_AE_LINES_GT
       WHERE ae_header_id      = l_array_ae_header_id(i)
       AND event_id            = l_array_event_id(i)
       AND ledger_id           = l_array_ledger_id(i)
       AND 'Y'                 = l_array_bflow_historic (i);
Line: 12371

       DELETE FROM XLA_AE_HEADERS_GT
       WHERE ae_header_id    = l_array_ae_header_id(i)
       AND event_id          = l_array_event_id(i)
       AND ledger_id         = l_array_ledger_id(i)
       AND 'Y'               = l_array_bflow_historic (i);
Line: 12387

           UPDATE xla_ae_headers_gt
              SET accounting_entry_status_code = XLA_AE_JOURNAL_ENTRY_PKG.C_INVALID  -- C_INVALID_STATUS
            WHERE balance_type_code = l_array_balance_type_code(i)
            AND ae_header_id        = l_array_ae_header_id(i)
            AND event_id            = l_array_event_id(i)
            AND ledger_id           = l_array_ledger_id(i);
Line: 12400

           UPDATE /*+ index(xalg xla_ae_lines_gt_n2) */ xla_ae_lines_gt xalg
              SET xalg.code_combination_status_code = C_INVALID
                , xalg.code_combination_id = -1
            WHERE xalg.balance_type_code = l_array_balance_type_code(i)
            AND xalg.ae_header_id        = l_array_ae_header_id(i)
            AND xalg.temp_line_num       = l_array_line_num(i)
            AND xalg.event_id            = l_array_event_id(i)
            AND xalg.ledger_id           = l_array_ledger_id(i);
Line: 12456

     SELECT l.ae_header_id
          , l.temp_line_num           -- 5443083 l.ae_line_num
          , l.event_id
          , l.ledger_id
          , l.balance_type_code
          , h.entity_id
          , l.ref_ae_header_id        -- 5443083
          , l.header_num              -- 5443083
          , xlr.ledger_category_code  -- 5443083
          , DECODE(NVL(l.unrounded_entered_dr,0)
                      ,0, DECODE(NVL(l.unrounded_entered_cr,0)
                                ,0, DECODE(NVL(l.unrounded_accounted_dr,0)
                                          ,0, DECODE(NVL(l.unrounded_accounted_cr,0)
                                                    ,0,'Y'
                                                    ,'N')
                                          ,'N')
                                ,'N')
                      ,'N')           -- 5443083
       FROM xla_ae_lines_gt l
           ,xla_ae_headers_gt h
           ,xla_gl_ledgers_v  xlr
      WHERE (reversal_code = C_DUMMY_SAME
      OR     reversal_code = C_MPA_SAME_ENTRY)  -- 4655713b
      AND   l.ae_header_id      = h.ae_header_id
      AND   l.ledger_id         = h.ledger_id            -- 5443083
      AND   l.balance_type_code = h.balance_type_code    -- 5443083
      AND   l.header_num        = h.header_num           -- 5443083
      AND   l.ledger_id         = xlr.ledger_id          -- 5443083
     ORDER BY l.ae_header_id;
Line: 12599

      SELECT      CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment1, C_CHAR, NVL(xal2.segment1,gcc.segment1), xal.segment1))
                       ELSE MIN(DECODE(xal.segment1, C_CHAR, NULL, xal.segment1)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment2, C_CHAR, NVL(xal2.segment2,gcc.segment2), xal.segment2))
                       ELSE MIN(DECODE(xal.segment2, C_CHAR, NULL, xal.segment2)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment3, C_CHAR, NVL(xal2.segment3,gcc.segment3), xal.segment3))
                       ELSE MIN(DECODE(xal.segment3, C_CHAR, NULL, xal.segment3)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment4, C_CHAR, NVL(xal2.segment4,gcc.segment4), xal.segment4))
                       ELSE MIN(DECODE(xal.segment4, C_CHAR, NULL, xal.segment4)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment5, C_CHAR, NVL(xal2.segment5,gcc.segment5), xal.segment5))
                       ELSE MIN(DECODE(xal.segment5, C_CHAR, NULL, xal.segment5)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment6, C_CHAR, NVL(xal2.segment6,gcc.segment6), xal.segment6))
                       ELSE MIN(DECODE(xal.segment6, C_CHAR, NULL, xal.segment6)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment7, C_CHAR, NVL(xal2.segment7,gcc.segment7), xal.segment7))
                       ELSE MIN(DECODE(xal.segment7, C_CHAR, NULL, xal.segment7)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment8, C_CHAR, NVL(xal2.segment8,gcc.segment8), xal.segment8))
                       ELSE MIN(DECODE(xal.segment8, C_CHAR, NULL, xal.segment8)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment9, C_CHAR, NVL(xal2.segment9,gcc.segment9), xal.segment9))
                       ELSE MIN(DECODE(xal.segment9, C_CHAR, NULL, xal.segment9)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment10, C_CHAR, NVL(xal2.segment10,gcc.segment10), xal.segment10))
                       ELSE MIN(DECODE(xal.segment10, C_CHAR, NULL, xal.segment10)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment11, C_CHAR, NVL(xal2.segment11,gcc.segment11), xal.segment11))
                       ELSE MIN(DECODE(xal.segment11, C_CHAR, NULL, xal.segment11)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment12, C_CHAR, NVL(xal2.segment12,gcc.segment12), xal.segment12))
                       ELSE MIN(DECODE(xal.segment12, C_CHAR, NULL, xal.segment12)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment13, C_CHAR, NVL(xal2.segment13,gcc.segment13), xal.segment13))
                       ELSE MIN(DECODE(xal.segment13, C_CHAR, NULL, xal.segment13)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment14, C_CHAR, NVL(xal2.segment14,gcc.segment14), xal.segment14))
                       ELSE MIN(DECODE(xal.segment14, C_CHAR, NULL, xal.segment14)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment15, C_CHAR, NVL(xal2.segment15,gcc.segment15), xal.segment15))
                       ELSE MIN(DECODE(xal.segment15, C_CHAR, NULL, xal.segment15)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment16, C_CHAR, NVL(xal2.segment16,gcc.segment16), xal.segment16))
                       ELSE MIN(DECODE(xal.segment16, C_CHAR, NULL, xal.segment16)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment17, C_CHAR, NVL(xal2.segment17,gcc.segment17), xal.segment17))
                       ELSE MIN(DECODE(xal.segment17, C_CHAR, NULL, xal.segment17)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment18, C_CHAR, NVL(xal2.segment18,gcc.segment18), xal.segment18))
                       ELSE MIN(DECODE(xal.segment18, C_CHAR, NULL, xal.segment18)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment19, C_CHAR, NVL(xal2.segment19,gcc.segment19), xal.segment19))
                       ELSE MIN(DECODE(xal.segment19, C_CHAR, NULL, xal.segment19)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment20, C_CHAR, NVL(xal2.segment20,gcc.segment20), xal.segment20))
                       ELSE MIN(DECODE(xal.segment20, C_CHAR, NULL, xal.segment20)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment21, C_CHAR, NVL(xal2.segment21,gcc.segment21), xal.segment21))
                       ELSE MIN(DECODE(xal.segment21, C_CHAR, NULL, xal.segment21)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment22, C_CHAR, NVL(xal2.segment22,gcc.segment22), xal.segment22))
                       ELSE MIN(DECODE(xal.segment22, C_CHAR, NULL, xal.segment22)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment23, C_CHAR, NVL(xal2.segment23,gcc.segment23), xal.segment23))
                       ELSE MIN(DECODE(xal.segment23, C_CHAR, NULL, xal.segment23)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment24, C_CHAR, NVL(xal2.segment24,gcc.segment24), xal.segment24))
                       ELSE MIN(DECODE(xal.segment24, C_CHAR, NULL, xal.segment24)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment25, C_CHAR, NVL(xal2.segment25,gcc.segment25), xal.segment25))
                       ELSE MIN(DECODE(xal.segment25, C_CHAR, NULL, xal.segment25)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment26, C_CHAR, NVL(xal2.segment26,gcc.segment26), xal.segment26))
                       ELSE MIN(DECODE(xal.segment26, C_CHAR, NULL, xal.segment26)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment27, C_CHAR, NVL(xal2.segment27,gcc.segment27), xal.segment27))
                       ELSE MIN(DECODE(xal.segment27, C_CHAR, NULL, xal.segment27)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment28, C_CHAR, NVL(xal2.segment28,gcc.segment28), xal.segment28))
                       ELSE MIN(DECODE(xal.segment28, C_CHAR, NULL, xal.segment28)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment29, C_CHAR, NVL(xal2.segment29,gcc.segment29), xal.segment29))
                       ELSE MIN(DECODE(xal.segment29, C_CHAR, NULL, xal.segment29)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment30, C_CHAR, NVL(xal2.segment30,gcc.segment30), xal.segment30))
                       ELSE MIN(DECODE(xal.segment30, C_CHAR, NULL, xal.segment30)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.code_combination_id, C_NUM, xal2.code_combination_id, xal.code_combination_id))
                       ELSE -1 END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.inherit_desc_flag, 'Y', xal2.description, xal.description)) ELSE NULL END
                , CASE WHEN count(*) = 1
                       THEN NULL ELSE MIN(xal.reversal_code) END
                -- join conditions
                , CASE WHEN count(*) = 1
                       THEN xal.ledger_id ELSE NULL END
                , CASE WHEN count(*) = 1
                       THEN xal.ref_ae_header_id ELSE NULL END
                , CASE WHEN count(*) = 1
                       THEN xal.temp_line_num ELSE NULL END
                , CASE WHEN count(*) = 1
                       THEN xal.ae_header_id ELSE NULL END
                , CASE WHEN count(*) = 1
                       THEN NVL(xal.header_num,0) ELSE NULL END
      BULK COLLECT INTO
                  l_array_same_segment1
                , l_array_same_segment2
                , l_array_same_segment3
                , l_array_same_segment4
                , l_array_same_segment5
                , l_array_same_segment6
                , l_array_same_segment7
                , l_array_same_segment8
                , l_array_same_segment9
                , l_array_same_segment10
                , l_array_same_segment11
                , l_array_same_segment12
                , l_array_same_segment13
                , l_array_same_segment14
                , l_array_same_segment15
                , l_array_same_segment16
                , l_array_same_segment17
                , l_array_same_segment18
                , l_array_same_segment19
                , l_array_same_segment20
                , l_array_same_segment21
                , l_array_same_segment22
                , l_array_same_segment23
                , l_array_same_segment24
                , l_array_same_segment25
                , l_array_same_segment26
                , l_array_same_segment27
                , l_array_same_segment28
                , l_array_same_segment29
                , l_array_same_segment30
                , l_array_same_ccid
                , l_array_same_description
                , l_array_same_reversal_code
                -- join conditions
                , l_array_join_ledger_id
                , l_array_join_ref_ae_header_id
                , l_array_join_temp_line_num
                , l_array_join_ae_header_id
                , l_array_join_header_num
      FROM  xla_ae_lines_gt          xal2
         ,  xla_ae_lines_gt          xal
         ,  gl_code_combinations     gcc
      WHERE xal2.source_distribution_type                  = xal.source_distribution_type
      AND   NVL(xal2.source_distribution_id_num_1,C_NUM)   = NVL(xal.source_distribution_id_num_1,C_NUM)
      AND   NVL(xal2.source_distribution_id_num_2,C_NUM)   = NVL(xal.source_distribution_id_num_2,C_NUM)
      AND   NVL(xal2.source_distribution_id_num_3,C_NUM)   = NVL(xal.source_distribution_id_num_3,C_NUM)
      AND   NVL(xal2.source_distribution_id_num_4,C_NUM)   = NVL(xal.source_distribution_id_num_4,C_NUM)
      AND   NVL(xal2.source_distribution_id_num_5,C_NUM)   = NVL(xal.source_distribution_id_num_5,C_NUM)
      AND   NVL(xal2.source_distribution_id_char_1,C_CHAR) = NVL(xal.source_distribution_id_char_1,C_CHAR)
      AND   NVL(xal2.source_distribution_id_char_2,C_CHAR) = NVL(xal.source_distribution_id_char_2,C_CHAR)
      AND   NVL(xal2.source_distribution_id_char_3,C_CHAR) = NVL(xal.source_distribution_id_char_3,C_CHAR)
      AND   NVL(xal2.source_distribution_id_char_4,C_CHAR) = NVL(xal.source_distribution_id_char_4,C_CHAR)
      AND   NVL(xal2.source_distribution_id_char_5,C_CHAR) = NVL(xal.source_distribution_id_char_5,C_CHAR)
      AND   xal2.event_id                      = xal.event_id
      AND   xal2.ledger_id                     = xal.ledger_id
      AND   xal2.balance_type_code             = xal.balance_type_code
      AND   xal2.event_class_code              = xal.event_class_code
      AND   xal2.event_type_code               = xal.event_type_code
      AND   xal2.line_definition_owner_code    = xal.line_definition_owner_code
      AND   xal2.line_definition_code          = xal.line_definition_code
      AND   xal2.natural_side_code             = DECODE(xal.natural_side_code, 'C', 'D', 'C')
      AND   gcc.code_combination_id(+)         = xal2.code_combination_id -- bug4384869
   -- AND   nvl(xal2.reversal_code, 'A') not in (C_DUMMY_SAME, C_DUMMY_PRIOR)  -- 5001981
      AND   xal.reversal_code = C_DUMMY_SAME
      AND   NVL(xal2.header_num,0) = 0  -- 4655713b  excludes MPA/Accrual Reversal lines,cannot be used for bflow
      GROUP BY xal.ledger_id    -- 5068675
              ,xal.ref_ae_header_id
              ,xal.temp_line_num
              ,xal.ae_header_id
              ,xal.header_num;
Line: 12810

         FOR i IN (select * from xla_ae_Lines_gt where reversal_code=C_DUMMY_SAME) LOOP
            trace
            (p_msg      => 'ae_lines_gt  SE dist ledger='||i.ledger_id||' ref_ae_header='||i.ref_ae_header_id||
                           ' temp_line='||i.temp_line_num||' ae_header='||i.ae_header_id||' header_num='||i.header_num||
                           ' bflow='||i.business_method_code||
                           ' line='||i.line_definition_code|| ' dist='||i.source_distribution_type||' rev='||i.reversal_code||
                           ' n1='||i.source_distribution_id_num_1|| ' n2='||i.source_distribution_id_num_2||
                           ' n3='||i.source_distribution_id_num_3|| ' n4='||i.source_distribution_id_num_4||
                           ' n5='||i.source_distribution_id_num_5|| ' c1='||i.source_distribution_id_char_1||
                           ' c2='||i.source_distribution_id_char_2|| ' c3='||i.source_distribution_id_char_3||
                           ' c4='||i.source_distribution_id_char_4|| ' c5='||i.source_distribution_id_char_5||
                           ' bal='||i.balance_type_code|| ' side='||i.natural_side_code||
                           ' rev='||i.reversal_code
            ,p_level    => C_LEVEL_STATEMENT
            ,p_module   => l_log_module);
Line: 12827

         FOR i IN (select * from xla_ae_Lines_gt where reversal_code=C_DUMMY_SAME) LOOP
             trace
            (p_msg      => '                seg s1='||i.segment1||' s2='||i.segment2|| ' s3='||i.segment3||' s4='||i.segment4||
                                       ' s5='||i.segment5||' s6='||i.segment6|| ' s7='||i.segment7||' s8='||i.segment8||
                                       ' s9='||i.segment9||' s10='||i.segment10|| ' s11='||i.segment11||' s12='||i.segment12||
                                       ' s13='||i.segment13||' s14='||i.segment14|| ' s15='||i.segment15||' s16='||i.segment16||
                                       ' s17='||i.segment17||' s18='||i.segment18|| ' s19='||i.segment19||' s20='||i.segment20||
                                       ' s21='||i.segment21||' s22='||i.segment22|| ' s23='||i.segment23||' s24='||i.segment24||
                                       ' s25='||i.segment25||' s26='||i.segment26|| ' s27='||i.segment27||' s28='||i.segment28||
                                       ' s29='||i.segment29||' s30='||i.segment30||' ccid='||i.code_combination_id
            ,p_level    => C_LEVEL_STATEMENT
            ,p_module   => l_log_module);
Line: 12844

         UPDATE xla_ae_lines_gt xal
         SET      segment1  = l_array_same_segment1(i)
                , segment2  = l_array_same_segment2(i)
                , segment3  = l_array_same_segment3(i)
                , segment4  = l_array_same_segment4(i)
                , segment5  = l_array_same_segment5(i)
                , segment6  = l_array_same_segment6(i)
                , segment7  = l_array_same_segment7(i)
                , segment8  = l_array_same_segment8(i)
                , segment9  = l_array_same_segment9(i)
                , segment10 = l_array_same_segment10(i)
                , segment11 = l_array_same_segment11(i)
                , segment12 = l_array_same_segment12(i)
                , segment13 = l_array_same_segment13(i)
                , segment14 = l_array_same_segment14(i)
                , segment15 = l_array_same_segment15(i)
                , segment16 = l_array_same_segment16(i)
                , segment17 = l_array_same_segment17(i)
                , segment18 = l_array_same_segment18(i)
                , segment19 = l_array_same_segment19(i)
                , segment20 = l_array_same_segment20(i)
                , segment21 = l_array_same_segment21(i)
                , segment22 = l_array_same_segment22(i)
                , segment23 = l_array_same_segment23(i)
                , segment24 = l_array_same_segment24(i)
                , segment25 = l_array_same_segment25(i)
                , segment26 = l_array_same_segment26(i)
                , segment27 = l_array_same_segment27(i)
                , segment28 = l_array_same_segment28(i)
                , segment29 = l_array_same_segment29(i)
                , segment30 = l_array_same_segment30(i)
                , code_combination_id  = l_array_same_ccid(i)
                , code_combination_status_code = DECODE(l_array_same_ccid(i),NULL,C_PROCESSING     -- 4655713b used in Create_CCID
                                                                                 ,C_NOT_PROCESSED) -- 4655713  used in Override_CCID
                , description          = l_array_same_description(i)
                , reversal_code        = l_array_same_reversal_code(i)
           WHERE xal.ledger_id         = l_array_join_ledger_id(i)
           AND   xal.ref_ae_header_id  = l_array_join_ref_ae_header_id(i)
           AND   xal.temp_line_num     = l_array_join_temp_line_num(i)
           AND   xal.ae_header_id      = l_array_join_ae_header_id(i)
           AND   NVL(xal.header_num,0) = l_array_join_header_num(i);
Line: 12888

            (p_msg      => 'BusinessFlowSameEntries - no of rows updated = '||SQL%ROWCOUNT
            ,p_level    => C_LEVEL_STATEMENT
            ,p_module   => l_log_module);
Line: 12897

            SELECT /*+ Leading (xal1,xah1,xal2) index(xah1 XLA_AE_HEADERS_GT_U1) index(xal2 XLA_AE_LINES_GT_N2) no_expand */  -- 7128871
                   xal2.segment1,  xal2.segment2,  xal2.segment3,  xal2.segment4,  xal2.segment5
            ,xal2.segment6,  xal2.segment7,  xal2.segment8,  xal2.segment9,  xal2.segment10
            ,xal2.segment11, xal2.segment12, xal2.segment13, xal2.segment14, xal2.segment15
            ,xal2.segment16, xal2.segment17, xal2.segment18, xal2.segment19, xal2.segment20
            ,xal2.segment21, xal2.segment22, xal2.segment23, xal2.segment24, xal2.segment25
            ,xal2.segment26, xal2.segment27, xal2.segment28, xal2.segment29, xal2.segment30
            ,xal2.code_combination_id
            ,xal2.code_combination_status_code
            ,DECODE(NVL(xal1.inherit_desc_flag,'N'), 'Y', xal2.description, xal1.description)
            -- join conditions
            ,xal1.ledger_id
            ,xal1.ref_ae_header_id
            ,xal1.temp_line_num
            ,xal1.ae_header_id
            ,xal1.header_num
      BULK COLLECT INTO
             l_array_mpa_segment1 ,l_array_mpa_segment2 ,l_array_mpa_segment3 ,l_array_mpa_segment4 ,l_array_mpa_segment5
            ,l_array_mpa_segment6 ,l_array_mpa_segment7 ,l_array_mpa_segment8 ,l_array_mpa_segment9 ,l_array_mpa_segment10
            ,l_array_mpa_segment11 ,l_array_mpa_segment12 ,l_array_mpa_segment13 ,l_array_mpa_segment14 ,l_array_mpa_segment15
            ,l_array_mpa_segment16 ,l_array_mpa_segment17 ,l_array_mpa_segment18 ,l_array_mpa_segment19 ,l_array_mpa_segment20
            ,l_array_mpa_segment21 ,l_array_mpa_segment22 ,l_array_mpa_segment23 ,l_array_mpa_segment24 ,l_array_mpa_segment25
            ,l_array_mpa_segment26 ,l_array_mpa_segment27 ,l_array_mpa_segment28 ,l_array_mpa_segment29 ,l_array_mpa_segment30
            ,l_array_mpa_ccid
            ,l_array_mpa_ccid_status_code
            ,l_array_mpa_description
            -- join conditions
            ,l_array_mpa_ledger_id
            ,l_array_mpa_ref_ae_header_id
            ,l_array_mpa_temp_line_num
            ,l_array_mpa_ae_header_id
            ,l_array_mpa_header_num
      FROM  xla_ae_lines_gt   xal2   -- Original line
           ,xla_ae_headers_gt xah1
           ,xla_ae_lines_gt   xal1   -- MPA line
      WHERE xal2.source_distribution_type                  = xal1.source_distribution_type
      AND   NVL(xal2.source_distribution_id_num_1,C_NUM)   = NVL(xal1.source_distribution_id_num_1,C_NUM)
      AND   NVL(xal2.source_distribution_id_num_2,C_NUM)   = NVL(xal1.source_distribution_id_num_2,C_NUM)
      AND   NVL(xal2.source_distribution_id_num_3,C_NUM)   = NVL(xal1.source_distribution_id_num_3,C_NUM)
      AND   NVL(xal2.source_distribution_id_num_4,C_NUM)   = NVL(xal1.source_distribution_id_num_4,C_NUM)
      AND   NVL(xal2.source_distribution_id_num_5,C_NUM)   = NVL(xal1.source_distribution_id_num_5,C_NUM)
      AND   NVL(xal2.source_distribution_id_char_1,C_CHAR) = NVL(xal1.source_distribution_id_char_1,C_CHAR)
      AND   NVL(xal2.source_distribution_id_char_2,C_CHAR) = NVL(xal1.source_distribution_id_char_2,C_CHAR)
      AND   NVL(xal2.source_distribution_id_char_3,C_CHAR) = NVL(xal1.source_distribution_id_char_3,C_CHAR)
      AND   NVL(xal2.source_distribution_id_char_4,C_CHAR) = NVL(xal1.source_distribution_id_char_4,C_CHAR)
      AND   NVL(xal2.source_distribution_id_char_5,C_CHAR) = NVL(xal1.source_distribution_id_char_5,C_CHAR)
      AND   xal2.event_id                      = xal1.event_id
      AND   xal2.ledger_id                     = xal1.ledger_id
      AND   xal2.balance_type_code             = xal1.balance_type_code
      AND   xal2.event_class_code              = xal1.event_class_code
      AND   xal2.event_type_code               = xal1.event_type_code
      AND   xal2.line_definition_owner_code    = xal1.line_definition_owner_code
      AND   xal2.line_definition_code          = xal1.line_definition_code
      AND   xal2.ACCOUNTING_LINE_TYPE_CODE     = xal1.ACCOUNTING_LINE_TYPE_CODE
      AND   xal2.ACCOUNTING_LINE_CODE          = xal1.ACCOUNTING_LINE_CODE
      --
      AND   xah1.ledger_id        = xal1.ledger_id
      AND   xah1.ae_header_id     = xal1.ae_header_id
      AND   xah1.header_num       = xal1.header_num
      AND ((xah1.parent_ae_line_num IS NOT NULL AND xal2.temp_line_num = xah1.parent_ae_line_num)  -- MPA
      OR    xah1.parent_ae_line_num IS NULL)                                                       -- Accrual Reversal
      --  7128871  -------------------------------------
      AND XAL1.BALANCE_TYPE_CODE  = XAH1.BALANCE_TYPE_CODE
      AND XAL2.AE_HEADER_ID       = XAL1.AE_HEADER_ID
      --------------------------------------------------
      AND   xal2.header_num       = 0
      AND   xal2.reversal_code IS NULL     -- 5443083 found the same entry
      AND   xal1.reversal_code    = C_MPA_SAME_ENTRY;
Line: 12984

         UPDATE xla_ae_lines_gt xal
         SET      segment1  = l_array_mpa_segment1(i)
                , segment2  = l_array_mpa_segment2(i)
                , segment3  = l_array_mpa_segment3(i)
                , segment4  = l_array_mpa_segment4(i)
                , segment5  = l_array_mpa_segment5(i)
                , segment6  = l_array_mpa_segment6(i)
                , segment7  = l_array_mpa_segment7(i)
                , segment8  = l_array_mpa_segment8(i)
                , segment9  = l_array_mpa_segment9(i)
                , segment10 = l_array_mpa_segment10(i)
                , segment11 = l_array_mpa_segment11(i)
                , segment12 = l_array_mpa_segment12(i)
                , segment13 = l_array_mpa_segment13(i)
                , segment14 = l_array_mpa_segment14(i)
                , segment15 = l_array_mpa_segment15(i)
                , segment16 = l_array_mpa_segment16(i)
                , segment17 = l_array_mpa_segment17(i)
                , segment18 = l_array_mpa_segment18(i)
                , segment19 = l_array_mpa_segment19(i)
                , segment20 = l_array_mpa_segment20(i)
                , segment21 = l_array_mpa_segment21(i)
                , segment22 = l_array_mpa_segment22(i)
                , segment23 = l_array_mpa_segment23(i)
                , segment24 = l_array_mpa_segment24(i)
                , segment25 = l_array_mpa_segment25(i)
                , segment26 = l_array_mpa_segment26(i)
                , segment27 = l_array_mpa_segment27(i)
                , segment28 = l_array_mpa_segment28(i)
                , segment29 = l_array_mpa_segment29(i)
                , segment30 = l_array_mpa_segment30(i)
                , code_combination_id          = l_array_mpa_ccid(i)
                , code_combination_status_code = l_array_mpa_ccid_status_code(i)  -- 4655713 used in Override_CCID
                , description          = l_array_mpa_description(i)
                , reversal_code        = null
           WHERE xal.ledger_id         = l_array_mpa_ledger_id(i)
           AND   xal.ref_ae_header_id  = l_array_mpa_ref_ae_header_id(i)
           AND   xal.temp_line_num     = l_array_mpa_temp_line_num(i)
           AND   xal.ae_header_id      = l_array_mpa_ae_header_id(i)
           AND   NVL(xal.header_num,0) = l_array_mpa_header_num(i);
Line: 13031

      UPDATE xla_ae_lines_gt xal
      SET (segment1,  segment2,  segment3,  segment4,  segment5,  segment6,  segment7,  segment8,  segment9,  segment10
          ,segment11, segment12, segment13, segment14, segment15, segment16, segment17, segment18, segment19, segment20
          ,segment21, segment22, segment23, segment24, segment25, segment26, segment27, segment28, segment29, segment30
          ,code_combination_id
          ,description
          ,reversal_code) =
          (SELECT CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment1, C_CHAR, NVL(xal2.segment1,gcc.segment1), xal.segment1))
                       ELSE MIN(DECODE(xal.segment1, C_CHAR, NULL, xal.segment1)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment2, C_CHAR, NVL(xal2.segment2,gcc.segment2), xal.segment2))
                       ELSE MIN(DECODE(xal.segment2, C_CHAR, NULL, xal.segment2)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment3, C_CHAR, NVL(xal2.segment3,gcc.segment3), xal.segment3))
                       ELSE MIN(DECODE(xal.segment3, C_CHAR, NULL, xal.segment3)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment4, C_CHAR, NVL(xal2.segment4,gcc.segment4), xal.segment4))
                       ELSE MIN(DECODE(xal.segment4, C_CHAR, NULL, xal.segment4)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment5, C_CHAR, NVL(xal2.segment5,gcc.segment5), xal.segment5))
                       ELSE MIN(DECODE(xal.segment5, C_CHAR, NULL, xal.segment5)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment6, C_CHAR, NVL(xal2.segment6,gcc.segment6), xal.segment6))
                       ELSE MIN(DECODE(xal.segment6, C_CHAR, NULL, xal.segment6)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment7, C_CHAR, NVL(xal2.segment7,gcc.segment7), xal.segment7))
                       ELSE MIN(DECODE(xal.segment7, C_CHAR, NULL, xal.segment7)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment8, C_CHAR, NVL(xal2.segment8,gcc.segment8), xal.segment8))
                       ELSE MIN(DECODE(xal.segment8, C_CHAR, NULL, xal.segment8)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment9, C_CHAR, NVL(xal2.segment9,gcc.segment9), xal.segment9))
                       ELSE MIN(DECODE(xal.segment9, C_CHAR, NULL, xal.segment9)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment10, C_CHAR, NVL(xal2.segment10,gcc.segment10), xal.segment10))
                       ELSE MIN(DECODE(xal.segment10, C_CHAR, NULL, xal.segment10)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment11, C_CHAR, NVL(xal2.segment11,gcc.segment11), xal.segment11))
                       ELSE MIN(DECODE(xal.segment11, C_CHAR, NULL, xal.segment11)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment12, C_CHAR, NVL(xal2.segment12,gcc.segment12), xal.segment12))
                       ELSE MIN(DECODE(xal.segment12, C_CHAR, NULL, xal.segment12)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment13, C_CHAR, NVL(xal2.segment13,gcc.segment13), xal.segment13))
                       ELSE MIN(DECODE(xal.segment13, C_CHAR, NULL, xal.segment13)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment14, C_CHAR, NVL(xal2.segment14,gcc.segment14), xal.segment14))
                       ELSE MIN(DECODE(xal.segment14, C_CHAR, NULL, xal.segment14)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment15, C_CHAR, NVL(xal2.segment15,gcc.segment15), xal.segment15))
                       ELSE MIN(DECODE(xal.segment15, C_CHAR, NULL, xal.segment15)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment16, C_CHAR, NVL(xal2.segment16,gcc.segment16), xal.segment16))
                       ELSE MIN(DECODE(xal.segment16, C_CHAR, NULL, xal.segment16)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment17, C_CHAR, NVL(xal2.segment17,gcc.segment17), xal.segment17))
                       ELSE MIN(DECODE(xal.segment17, C_CHAR, NULL, xal.segment17)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment18, C_CHAR, NVL(xal2.segment18,gcc.segment18), xal.segment18))
                       ELSE MIN(DECODE(xal.segment18, C_CHAR, NULL, xal.segment18)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment19, C_CHAR, NVL(xal2.segment19,gcc.segment19), xal.segment19))
                       ELSE MIN(DECODE(xal.segment19, C_CHAR, NULL, xal.segment19)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment20, C_CHAR, NVL(xal2.segment20,gcc.segment20), xal.segment20))
                       ELSE MIN(DECODE(xal.segment20, C_CHAR, NULL, xal.segment20)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment21, C_CHAR, NVL(xal2.segment21,gcc.segment21), xal.segment21))
                       ELSE MIN(DECODE(xal.segment21, C_CHAR, NULL, xal.segment21)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment22, C_CHAR, NVL(xal2.segment22,gcc.segment22), xal.segment22))
                       ELSE MIN(DECODE(xal.segment22, C_CHAR, NULL, xal.segment22)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment23, C_CHAR, NVL(xal2.segment23,gcc.segment23), xal.segment23))
                       ELSE MIN(DECODE(xal.segment23, C_CHAR, NULL, xal.segment23)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment24, C_CHAR, NVL(xal2.segment24,gcc.segment24), xal.segment24))
                       ELSE MIN(DECODE(xal.segment24, C_CHAR, NULL, xal.segment24)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment25, C_CHAR, NVL(xal2.segment25,gcc.segment25), xal.segment25))
                       ELSE MIN(DECODE(xal.segment25, C_CHAR, NULL, xal.segment25)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment26, C_CHAR, NVL(xal2.segment26,gcc.segment26), xal.segment26))
                       ELSE MIN(DECODE(xal.segment26, C_CHAR, NULL, xal.segment26)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment27, C_CHAR, NVL(xal2.segment27,gcc.segment27), xal.segment27))
                       ELSE MIN(DECODE(xal.segment27, C_CHAR, NULL, xal.segment27)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment28, C_CHAR, NVL(xal2.segment28,gcc.segment28), xal.segment28))
                       ELSE MIN(DECODE(xal.segment28, C_CHAR, NULL, xal.segment28)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment29, C_CHAR, NVL(xal2.segment29,gcc.segment29), xal.segment29))
                       ELSE MIN(DECODE(xal.segment29, C_CHAR, NULL, xal.segment29)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.segment30, C_CHAR, NVL(xal2.segment30,gcc.segment30), xal.segment30))
                       ELSE MIN(DECODE(xal.segment30, C_CHAR, NULL, xal.segment30)) END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.code_combination_id, C_NUM, xal2.code_combination_id, xal.code_combination_id))
                       ELSE -1 END
                , CASE WHEN count(*) = 1
                       THEN MIN(DECODE(xal.inherit_desc_flag, 'Y', xal2.description, xal.description)) ELSE NULL END
                , CASE WHEN count(*) = 1
                       THEN NULL ELSE xal.reversal_code END
           FROM  xla_ae_lines_gt          xal2
              ,  gl_code_combinations     gcc   -- bug4384869
           WHERE xal2.source_distribution_type      = xal.source_distribution_type
           AND   NVL(xal2.source_distribution_id_num_1,C_NUM)   = NVL(xal.source_distribution_id_num_1,C_NUM)
           AND   NVL(xal2.source_distribution_id_num_2,C_NUM)   = NVL(xal.source_distribution_id_num_2,C_NUM)
           AND   NVL(xal2.source_distribution_id_num_3,C_NUM)   = NVL(xal.source_distribution_id_num_3,C_NUM)
           AND   NVL(xal2.source_distribution_id_num_4,C_NUM)   = NVL(xal.source_distribution_id_num_4,C_NUM)
           AND   NVL(xal2.source_distribution_id_num_5,C_NUM)   = NVL(xal.source_distribution_id_num_5,C_NUM)
           AND   NVL(xal2.source_distribution_id_char_1,C_CHAR) = NVL(xal.source_distribution_id_char_1,C_CHAR)
           AND   NVL(xal2.source_distribution_id_char_2,C_CHAR) = NVL(xal.source_distribution_id_char_2,C_CHAR)
           AND   NVL(xal2.source_distribution_id_char_3,C_CHAR) = NVL(xal.source_distribution_id_char_3,C_CHAR)
           AND   NVL(xal2.source_distribution_id_char_4,C_CHAR) = NVL(xal.source_distribution_id_char_4,C_CHAR)
           AND   NVL(xal2.source_distribution_id_char_5,C_CHAR) = NVL(xal.source_distribution_id_char_5,C_CHAR)
           AND   xal2.event_id                      = xal.event_id
           AND   xal2.ledger_id                     = xal.ledger_id
           AND   xal2.balance_type_code             = xal.balance_type_code
           AND   xal2.event_class_code              = xal.event_class_code
           AND   xal2.event_type_code               = xal.event_type_code
           AND   xal2.line_definition_owner_code    = xal.line_definition_owner_code
           AND   xal2.line_definition_code          = xal.line_definition_code
           AND   xal2.natural_side_code             = DECODE(xal.natural_side_code, 'C', 'D', 'C')
           AND   gcc.code_combination_id(+)         = xal2.code_combination_id -- bug4384869
           AND   nvl(xal2.reversal_code, 'A') not in (C_DUMMY_SAME, C_DUMMY_PRIOR)
           )
      WHERE xal.reversal_code = C_DUMMY_SAME;
Line: 13224

                DELETE xla_ae_lines_gt
                WHERE  ledger_id        = l_array_ledger_id(i)
                AND    ref_ae_header_id = l_array_ref_ae_header_id(i)
                AND    temp_line_num    = l_array_temp_line_num(i)
                AND    ae_header_id     = l_array_ae_header_id(i)
                AND    header_num       = l_array_header_num(i);
Line: 13234

                      ,p_msg => '     zero amt line deleted='||SQL%ROWCOUNT
                      ,p_level => C_LEVEL_STATEMENT
                   );
Line: 13239

                DELETE xla_ae_headers_gt hgt
                WHERE  ledger_id         = l_array_ledger_id(i)
                AND    ae_header_id      = l_array_ae_header_id(i)
                AND    balance_type_code = l_array_balance_type_code(i)
                AND    header_num        = l_array_header_num(i)
                AND NOT EXISTS  (SELECT /*+ index(lgt XLA_AE_LINES_GT_N2) */ 1
                                 FROM   xla_ae_lines_gt lgt
                                 WHERE  lgt.ledger_id    = hgt.ledger_id
                                 AND    lgt.ae_header_id = hgt.ae_header_id
                                 AND    lgt.header_num   = hgt.header_num
                                 AND    lgt.balance_type_code = hgt.balance_type_code);
Line: 13254

                      ,p_msg => '     zero amt header deleted='||SQL%ROWCOUNT
                      ,p_level => C_LEVEL_STATEMENT
                   );
Line: 13274

                 UPDATE xla_ae_lines_gt
                 SET    description = DECODE(description, C_CHAR, NULL, description)
                      , code_combination_id = DECODE(code_combination_id, C_NUM, -1, code_combination_id)
                      , code_combination_status_code = C_INVALID     -- 4655713
                      , segment1  = DECODE(segment1,   C_CHAR, NULL, segment1)
                      , segment2  = DECODE(segment2,   C_CHAR, NULL, segment2)
                      , segment3  = DECODE(segment3,   C_CHAR, NULL, segment3)
                      , segment4  = DECODE(segment4,   C_CHAR, NULL, segment4)
                      , segment5  = DECODE(segment5,   C_CHAR, NULL, segment5)
                      , segment6  = DECODE(segment6,   C_CHAR, NULL, segment6)
                      , segment7  = DECODE(segment7,   C_CHAR, NULL, segment7)
                      , segment8  = DECODE(segment8,   C_CHAR, NULL, segment8)
                      , segment9  = DECODE(segment9,   C_CHAR, NULL, segment9)
                      , segment10 = DECODE(segment10,  C_CHAR, NULL, segment10)
                      , segment11 = DECODE(segment11,  C_CHAR, NULL, segment11)
                      , segment12 = DECODE(segment12,  C_CHAR, NULL, segment12)
                      , segment13 = DECODE(segment13,  C_CHAR, NULL, segment13)
                      , segment14 = DECODE(segment14,  C_CHAR, NULL, segment14)
                      , segment15 = DECODE(segment15,  C_CHAR, NULL, segment15)
                      , segment16 = DECODE(segment16,  C_CHAR, NULL, segment16)
                      , segment17 = DECODE(segment17,  C_CHAR, NULL, segment17)
                      , segment18 = DECODE(segment18,  C_CHAR, NULL, segment18)
                      , segment19 = DECODE(segment19,  C_CHAR, NULL, segment19)
                      , segment20 = DECODE(segment20,  C_CHAR, NULL, segment20)
                      , segment21 = DECODE(segment21,  C_CHAR, NULL, segment21)
                      , segment22 = DECODE(segment22,  C_CHAR, NULL, segment22)
                      , segment23 = DECODE(segment23,  C_CHAR, NULL, segment23)
                      , segment24 = DECODE(segment24,  C_CHAR, NULL, segment24)
                      , segment25 = DECODE(segment25,  C_CHAR, NULL, segment25)
                      , segment26 = DECODE(segment26,  C_CHAR, NULL, segment26)
                      , segment27 = DECODE(segment27,  C_CHAR, NULL, segment27)
                      , segment28 = DECODE(segment28,  C_CHAR, NULL, segment28)
                      , segment29 = DECODE(segment29,  C_CHAR, NULL, segment29)
                      , segment30 = DECODE(segment30,  C_CHAR, NULL, segment30)
                 WHERE ae_header_id      = l_array_ae_header_id(i)
             --  AND   ae_line_num       = l_array_ae_line_num(i)        -- 5443083
                 AND   temp_line_num     = l_array_temp_line_num(i)      -- 5443083
                 AND   ref_ae_header_id  = l_array_ref_ae_header_id(i)   -- 5443083
                 AND   header_num        = l_array_header_num(i)         -- 5443083
                 AND   event_id          = l_array_event_id(i)
                 AND   ledger_id         = l_array_ledger_id(i)
                 AND   balance_type_code = l_array_balance_type_code(i);
Line: 13321

                 UPDATE xla_ae_headers_gt hgt
                 SET   accounting_entry_status_code = XLA_AE_JOURNAL_ENTRY_PKG.C_INVALID  -- C_INVALID_STATUS
                 WHERE ae_header_id      = l_array_ae_header_id(i)
                 AND   event_id          = l_array_event_id(i)
                 AND   ledger_id         = l_array_ledger_id(i)
                 AND   header_num        = l_array_header_num(i)         -- 5443083
                 AND   balance_type_code = l_array_balance_type_code(i)
                 AND EXISTS  (SELECT /*+ index(lgt XLA_AE_LINES_GT_N2) */ 1  - 5443083
                              FROM   xla_ae_lines_gt lgt
                              WHERE  lgt.ledger_id    = hgt.ledger_id
                              AND    lgt.ae_header_id = hgt.ae_header_id
                              AND    lgt.header_num   = hgt.header_num
                              AND    lgt.balance_type_code = hgt.balance_type_code
                              AND   (lgt.reversal_code = C_DUMMY_SAME
                              OR     lgt.reversal_code = C_MPA_SAME_ENTRY));