DBA Data[Home] [Help]

APPS.XLA_BALANCES_CALC_PKG SQL Statements

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

Line: 22

|     update the effective_period_num in balances table in addition to  |
|     updating the effective_period_num in xla_ledger_options.          |
|                                                                       |
|                                                                       |
+======================================================================*/

   -- Private exceptions
   --
   le_resource_busy                EXCEPTION;
Line: 61

   g_preupdate_flag                VARCHAR2 (1);
Line: 62

   g_postupdate_flag               VARCHAR2 (1);
Line: 125

l_insert_sql   VARCHAR2(2000);
Line: 220

        SELECT   xah.ledger_id
               , xah.application_id
               , xah.accounting_batch_id
        BULK COLLECT INTO
                  g_ledger_array
               ,  g_application_array
               ,  g_accounting_batch_array
            FROM xla_ae_headers xah
	       , xla_ae_lines xal
	       , gl_period_statuses gps
	       , xla_ledger_relationships_v xlr
           WHERE xah.application_id = p_application_id
             AND xah.ledger_id = p_ledger_id
             AND xah.ae_header_id = xal.ae_header_id
             AND xah.application_id = xal.application_id
             AND xah.accounting_batch_id IS NOT NULL
             -- to handle undo case. accounting_batch_id will be null if the entries were created by undo
             AND (   xal.analytical_balance_flag = 'P'
                  OR xal.control_balance_flag = 'P'
                 )
	     AND xah.accounting_entry_status_code ='F'
	     AND xah.ledger_id = xlr.ledger_id
	     AND gps.period_name = xah.period_name
	     AND gps.ledger_id = DECODE(xlr.ledger_category_code, 'ALC' , xlr.primary_ledger_id, xlr.ledger_id)
       AND gps.application_id=101
	     AND gps.closing_status in ('O','C','P')
	     AND gps.adjustment_period_flag = 'N'
        GROUP BY xah.application_id
               , xah.ledger_id
               , xah.accounting_batch_id;
Line: 253

        INSERT INTO xla_bal_concurrency_control
                 (ledger_id
                , application_id
                , concurrency_class
                , accounting_batch_id
                , execution_mode
                , request_id
                 ) VALUES
             (   g_ledger_array(i)
               , g_application_array(i)
               , p_concurrency_class
               , g_accounting_batch_array(i)
               , p_execution_mode
               , p_request_id ) ;
Line: 272

       select  distinct
             ledger_id
            ,application_id
            ,accounting_batch_id
       BULK COLLECT INTO
              g_ledger_array
            , g_application_array
            , g_accounting_batch_array
       from xla_ae_headers
       where application_id = p_application_id
         and entity_id      = p_entity_id;
Line: 286

        INSERT INTO xla_bal_concurrency_control
                 (ledger_id
                , application_id
                , concurrency_class
                , accounting_batch_id
                , execution_mode
                , request_id
                 ) VALUES
             (   g_ledger_array(i)
               , g_application_array(i)
               , p_concurrency_class
               , g_accounting_batch_array(i)
               , p_execution_mode
               , -1*p_entity_id ) ;
Line: 302

       select  distinct
             ledger_id
            ,application_id
            ,accounting_batch_id
       BULK COLLECT INTO
              g_ledger_array
            , g_application_array
            , g_accounting_batch_array
       from xla_ae_headers
       where application_id = p_application_id
         and ae_header_id   = p_ae_header_id;
Line: 315

        INSERT INTO xla_bal_concurrency_control
                 (ledger_id
                , application_id
                , concurrency_class
                , accounting_batch_id
                , execution_mode
                , request_id
                 ) VALUES
             (   g_ledger_array(i)
               , g_application_array(i)
               , p_concurrency_class
               , g_accounting_batch_array(i)
               , p_execution_mode
               , -1*p_ae_header_id ) ;
Line: 332

       select  distinct
             ledger_id
            ,application_id
            ,p_accounting_batch_id
       BULK COLLECT INTO
              g_ledger_array
            ,  g_application_array
            ,  g_accounting_batch_array
       from xla_ae_headers
       where accounting_batch_id = p_accounting_batch_id
         and application_id      = p_application_id;
Line: 345

        INSERT INTO xla_bal_concurrency_control
                 (ledger_id
                , application_id
                , concurrency_class
                , accounting_batch_id
                , execution_mode
                , request_id
                 ) VALUES
             (   g_ledger_array(i)
               , g_application_array(i)
               , p_concurrency_class
               , g_accounting_batch_array(i)
               , p_execution_mode
               , p_request_id ) ;
Line: 363

       select
           p_ledger_id
          ,p_application_id
          ,p_accounting_batch_id
       BULK COLLECT INTO
              g_ledger_array
            ,  g_application_array
            ,  g_accounting_batch_array
       FROM dual;
Line: 374

        INSERT INTO xla_bal_concurrency_control
                 (ledger_id
                , application_id
                , concurrency_class
                , accounting_batch_id
                , execution_mode
                , request_id
                 ) VALUES
             (   g_ledger_array(i)
               , g_application_array(i)
               , p_concurrency_class
               , g_accounting_batch_array(i)
               , p_execution_mode
               , p_request_id ) ;
Line: 393

       select
           p_ledger_id
       BULK COLLECT INTO
              g_ledger_array
       FROM dual;
Line: 400

        INSERT INTO xla_bal_concurrency_control
                 (ledger_id
                , concurrency_class
                , request_id
                 ) VALUES
             (   g_ledger_array(i)
               , p_concurrency_class
               , p_request_id ) ;
Line: 414

          , p_msg         => '# rows inserted into xla_bal_concurrency_control ' || SQL%ROWCOUNT
          , p_level       => c_level_procedure
           );
Line: 482

  l_insert1_count           NUMBER;
Line: 484

  l_update1_count           NUMBER;
Line: 485

  l_insert2_count           NUMBER;
Line: 486

  l_update2_count           NUMBER;
Line: 487

  l_update_bal              VARCHAR2(6000);
Line: 488

  l_insert_bal              VARCHAR2(6000);
Line: 489

  l_update_processed        VARCHAR2(5000);
Line: 495

  l_summary_stmt VARCHAR2(7000):= 'INSERT INTO xla_ac_bal_interim_gt
                                              ( application_id
                                              , ledger_id
                                              , code_combination_id
                                              , analytical_criterion_code
                                              , analytical_criterion_type_code
                                              , amb_context_code
                                              , ac1
                                              , ac2
                                              , ac3
                                              , ac4
                                              , ac5
                                              , period_name
                                              , effective_period_num
                                              , period_balance_dr
                                              , period_balance_cr
                                              , period_year
                                              )
                                     SELECT   /*+ $parallel$ use_nl(aeh) use_nl(acs) use_nl(ael) */
                                              ael.application_id
                                            , ael.ledger_id
                                            , ael.code_combination_id
                                            , acs.analytical_criterion_code
                                            , acs.analytical_criterion_type_code
                                            , acs.amb_context_code
                                            , acs.ac1
                                            , acs.ac2
                                            , acs.ac3
                                            , acs.ac4
                                            , acs.ac5
                                            , aeh.period_name
                                            , gps.effective_period_num
                                            , $period_balance_dr$
                                            , $period_balance_cr$
                                            , SUBSTR (gps.effective_period_num, 1, 4) period_year
                                       FROM xla_ae_headers aeh
                                          , xla_ae_lines ael
                                          , xla_ae_line_acs acs
                                          , xla_analytical_hdrs_b xbh
                                          , gl_period_statuses gps
                                          , xla_ledger_options xlo
                                          , xla_ledger_relationships_v xlr
                                          $bal_concurrency$
                                    WHERE aeh.application_id               = :'||l_summary_bind_count||'
                                      AND aeh.accounting_entry_status_code = ''F''
				      AND aeh.balance_type_code            = ''A''
                                      AND ael.application_id               = aeh.application_id
                                      AND ael.ae_header_id                 = aeh.ae_header_id
                                      AND ael.analytical_balance_flag      = '''||g_preupdate_flag||'''
                                      AND ael.ledger_id                    = aeh.ledger_id
                                      AND acs.ae_header_id                 = ael.ae_header_id
                                      AND acs.ae_line_num                  = ael.ae_line_num
                                      AND xlr.ledger_id                    = aeh.ledger_id
                                      AND xlo.application_id               = aeh.application_id
                                      AND xlo.ledger_id                    =  DECODE (xlr.ledger_category_code  , ''ALC''
                                                                                    , xlr.primary_ledger_id , xlr.ledger_id )
                                      AND gps.ledger_id                    = xlo.ledger_id
                                      AND gps.application_id               = 101
                                      AND gps.closing_status               IN (''O'', ''C'', ''P'')
                                      AND gps.effective_period_num         <= xlo.effective_period_num
                                      AND gps.adjustment_period_flag       = ''N''
                                      AND gps.period_name                  = aeh.period_name
                                      AND xbh.analytical_criterion_code      = acs.analytical_criterion_code
                                      AND xbh.analytical_criterion_type_code = acs.analytical_criterion_type_code
                                      AND xbh.amb_context_code               = acs.amb_context_code
                                      AND xbh.balancing_flag <> ''N''';
Line: 800

   l_insert1_count := SQL%ROWCOUNT;
Line: 805

         , p_msg         =>    '# rows inserted in XLA_AC_BAL_INTERIM_GT : '
                            || l_insert1_count
         , p_level       => c_level_procedure
          );
Line: 811

   IF l_insert1_count = 0
   THEN
    IF (c_level_procedure >= g_log_level)
    THEN
       TRACE (p_module      => l_log_module
            , p_msg         => 'No Records to process ' || l_insert1_count
            , p_level       => c_level_procedure
             );
Line: 828

    USING (SELECT period_balance_dr
                , period_balance_cr
                -- Begin Bug 13498442
                , decode (year_end_carry_forward_code,'Y',
                  SUM (lag_dr) OVER (PARTITION BY application_id, ledger_id, code_combination_id
                , analytical_criterion_code, analytical_criterion_type_code, amb_context_code
                , ac1, ac2, ac3, ac4, ac5 ORDER BY application_id, ledger_id
                , code_combination_id
                , analytical_criterion_code
                , analytical_criterion_type_code
                , amb_context_code
                , ac1
                , ac2
                , ac3
                , ac4
                , ac5
                , effective_period_num)
                ,  SUM (lag_dr) OVER (PARTITION BY application_id, ledger_id, code_combination_id
                , analytical_criterion_code, analytical_criterion_type_code, amb_context_code
                , ac1, ac2, ac3, ac4, ac5, period_year ORDER BY application_id, ledger_id
                , code_combination_id
                , analytical_criterion_code
                , analytical_criterion_type_code
                , amb_context_code
                , ac1
                , ac2
                , ac3
                , ac4
                , ac5
                , effective_period_num) )   xal_beginning_balance_dr
                , decode (year_end_carry_forward_code,'Y',
                  SUM (lag_cr) OVER (PARTITION BY application_id, ledger_id, code_combination_id
                , analytical_criterion_code, analytical_criterion_type_code, amb_context_code
                , ac1, ac2, ac3, ac4, ac5 ORDER BY application_id, ledger_id
                , code_combination_id
                , analytical_criterion_code
                , analytical_criterion_type_code
                , amb_context_code
                , ac1
                , ac2
                , ac3
                , ac4
                , ac5
                , effective_period_num)
                ,  SUM (lag_cr) OVER (PARTITION BY application_id, ledger_id, code_combination_id
                , analytical_criterion_code, analytical_criterion_type_code, amb_context_code
                , ac1, ac2, ac3, ac4, ac5, period_year ORDER BY application_id, ledger_id
                , code_combination_id
                , analytical_criterion_code
                , analytical_criterion_type_code
                , amb_context_code
                , ac1
                , ac2
                , ac3
                , ac4
                , ac5
                , effective_period_num) )   xal_beginning_balance_cr
            -- End Bug 13498442
                , application_id
                , ledger_id
                , code_combination_id
                , analytical_criterion_code
                , analytical_criterion_type_code
                , amb_context_code
                , ac1
                , ac2
                , ac3
                , ac4
                , ac5
                , period_name
                , effective_period_num
                , period_year
             FROM (SELECT   /*+  leading(xag,xal_bal)  */
                            xal_bal.application_id
                          , xal_bal.ledger_id
                          , xal_bal.code_combination_id
                                                     code_combination_id
                          , xal_bal.analytical_criterion_code
                          , xal_bal.analytical_criterion_type_code
                          , xal_bal.amb_context_code
                          , xal_bal.ac1
                          , xal_bal.ac2
                          , xal_bal.ac3
                          , xal_bal.ac4
                          , xal_bal.ac5
                          , xal_bal.year_end_carry_forward_code  --Bug13498442
                          , xal_bal.period_name period_name
                          , xal_bal.effective_period_num
                          , xal_bal.period_balance_dr
                          , xal_bal.period_balance_cr
                          , xal_bal.period_year
                          , LAG (NVL (xal_bal.period_balance_dr, 0)
                               , 1
                               , NVL (xal_bal.beginning_balance_dr, 0)
                                ) OVER (PARTITION BY xal_bal.application_id, xal_bal.ledger_id
                           , xal_bal.code_combination_id, xal_bal.analytical_criterion_type_code
                           , xal_bal.amb_context_code, xal_bal.ac1, xal_bal.ac2, xal_bal.ac3, xal_bal.ac4
                           , xal_bal.ac5 ORDER BY xal_bal.application_id
                           , xal_bal.ledger_id
                           , xal_bal.code_combination_id
                           , xal_bal.analytical_criterion_code
                           , xal_bal.analytical_criterion_type_code
                           , xal_bal.amb_context_code
                           , xal_bal.ac1
                           , xal_bal.ac2
                           , xal_bal.ac3
                           , xal_bal.ac4
                           , xal_bal.ac5
                           , xal_bal.effective_period_num) lag_dr
                          , LAG (NVL (xal_bal.period_balance_cr, 0)
                               , 1
                               , NVL (xal_bal.beginning_balance_cr, 0)
                                ) OVER (PARTITION BY xal_bal.application_id, xal_bal.ledger_id
                           , xal_bal.code_combination_id, xal_bal.analytical_criterion_type_code
                           , xal_bal.amb_context_code, xal_bal.ac1, xal_bal.ac2, xal_bal.ac3
                           , xal_bal.ac4, xal_bal.ac5 ORDER BY xal_bal.application_id
                           , xal_bal.ledger_id
                           , xal_bal.code_combination_id
                           , xal_bal.analytical_criterion_code
                           , xal_bal.analytical_criterion_type_code
                           , xal_bal.amb_context_code
                           , xal_bal.ac1
                           , xal_bal.ac2
                           , xal_bal.ac3
                           , xal_bal.ac4
                           , xal_bal.ac5
                           , xal_bal.effective_period_num) lag_cr
                       FROM (SELECT   tmp.application_id
                                    , tmp.ledger_id
                                    , tmp.code_combination_id
                                    , tmp.analytical_criterion_code
                                    , tmp.analytical_criterion_type_code
                                    , tmp.amb_context_code
                                    , decode (xbh.year_end_carry_forward_code,'Y','Y','A','Y','B',decode(gcc.account_type,'A','Y','L','Y','O','Y','N'),'N') year_end_carry_forward_code   --Bug13498442
                                    , MAX
                                         (DECODE
                                               (gps.effective_period_num
                                              , tmp.effective_period_num, tmp.period_balance_dr
                                              , NULL
                                               )
                                         ) period_balance_dr
                                    , MAX
                                         (DECODE
                                               (gps.effective_period_num
                                              , tmp.effective_period_num, tmp.period_balance_cr
                                              , NULL
                                               )
                                         ) period_balance_cr
                                    , tmp.beginning_balance_dr
                                    , tmp.beginning_balance_cr
                                    , tmp.ac1
                                    , tmp.ac2
                                    , tmp.ac3
                                    , tmp.ac4
                                    , tmp.ac5
                                    , gps.period_name
                                    , gps.effective_period_num
                                    , gps.period_year
                                 FROM gl_period_statuses gps
                                    ,xla_analytical_hdrs_b xbh   --Bug13498442
                                    , gl_code_combinations gcc  --Bug13498442
                                    , xla_ac_bal_interim_gt tmp
                                                                            , xla_ledger_options xlo
                                                                            , xla_ledger_relationships_v xlr
                                WHERE gps.effective_period_num  <= xlo.effective_period_num
                                  AND gps.effective_period_num  >= tmp.effective_period_num
                                  AND gps.closing_status        IN ('O', 'C', 'P')
                                  AND gps.adjustment_period_flag = 'N'
                                  AND gps.application_id         = 101
                                  AND gps.ledger_id              = xlo.ledger_id
                                  AND gcc.code_combination_id    = tmp.code_combination_id
                                  AND xlo.application_id         = tmp.application_id
                                  AND tmp.ledger_id              = xlr.ledger_id
                                  AND xlo.ledger_id              = DECODE(xlr.ledger_category_code, 'ALC'
                                                                    , xlr.primary_ledger_id, tmp.ledger_id)
                                  --Begin Bug13498442
                                  AND xbh.analytical_criterion_code      = tmp.analytical_criterion_code
                                  AND xbh.analytical_criterion_type_code = tmp.analytical_criterion_type_code
                                  AND xbh.amb_context_code               = tmp.amb_context_code
                                  --End Bug13498442
                             GROUP BY tmp.application_id
                                    , tmp.ledger_id
                                    , tmp.code_combination_id
                                    , tmp.analytical_criterion_code
                                    , tmp.analytical_criterion_type_code
                                    , tmp.amb_context_code
                                    , decode (xbh.year_end_carry_forward_code,'Y','Y','A','Y','B',decode(gcc.account_type,'A','Y','L','Y','O','Y','N'),'N')  --Bug13498442
                                    , tmp.beginning_balance_dr
                                    , tmp.beginning_balance_cr
                                    , tmp.ac1
                                    , tmp.ac2
                                    , tmp.ac3
                                    , tmp.ac4
                                    , tmp.ac5
                                    , gps.period_name
                                    , gps.effective_period_num
                                    , gps.period_year) xal_bal
                   ORDER BY xal_bal.application_id
                          , xal_bal.ledger_id
                          , xal_bal.code_combination_id
                          , xal_bal.analytical_criterion_code
                          , xal_bal.analytical_criterion_type_code
                          , xal_bal.amb_context_code
                          , xal_bal.ac1
                          , xal_bal.ac2
                          , xal_bal.ac3
                          , xal_bal.ac4
                          , xal_bal.ac5
                          , xal_bal.effective_period_num
                          , xal_bal.period_year)) tmp
    ON (    stmp.application_id                     = tmp.application_id
        AND stmp.ledger_id                          = tmp.ledger_id
        AND stmp.code_combination_id                = tmp.code_combination_id
        AND stmp.analytical_criterion_code          = tmp.analytical_criterion_code
        AND stmp.analytical_criterion_type_code = tmp.analytical_criterion_type_code
        AND stmp.amb_context_code                           = tmp.amb_context_code
        AND NVL (stmp.ac1, ' ')                             = NVL (tmp.ac1, ' ')
        AND NVL (stmp.ac2, ' ')                 = NVL (tmp.ac2, ' ')
        AND NVL (stmp.ac3, ' ')                 = NVL (tmp.ac3, ' ')
        AND NVL (stmp.ac4, ' ')                 = NVL (tmp.ac4, ' ')
        AND NVL (stmp.ac5, ' ')                 = NVL (tmp.ac5, ' ')
        AND stmp.effective_period_num           = tmp.effective_period_num)
    WHEN MATCHED THEN
       UPDATE
          SET stmp.beginning_balance_dr = tmp.xal_beginning_balance_dr
            , stmp.beginning_balance_cr = tmp.xal_beginning_balance_cr
    WHEN NOT MATCHED THEN
       INSERT (stmp.application_id, stmp.ledger_id
             , stmp.code_combination_id, stmp.analytical_criterion_code
             , stmp.analytical_criterion_type_code
             , stmp.amb_context_code, stmp.ac1, stmp.ac2, stmp.ac3
             , stmp.ac4, stmp.ac5, stmp.period_balance_dr
             , stmp.period_balance_cr, stmp.beginning_balance_dr
             , stmp.beginning_balance_cr, stmp.period_name
             , stmp.effective_period_num, stmp.period_year)
       VALUES (tmp.application_id, tmp.ledger_id
             , tmp.code_combination_id, tmp.analytical_criterion_code
             , tmp.analytical_criterion_type_code, tmp.amb_context_code
             , tmp.ac1, tmp.ac2, tmp.ac3, tmp.ac4, tmp.ac5
             , tmp.period_balance_dr, tmp.period_balance_cr
             , tmp.xal_beginning_balance_dr
             , tmp.xal_beginning_balance_cr, tmp.period_name
             , tmp.effective_period_num, tmp.period_year);
Line: 1086

   l_update_bal := 'UPDATE /*+ index(b,xla_ac_balances_N99) */xla_ac_balances b
                   SET last_update_date           = '''||g_date||'''
		     , last_updated_by            = '||g_user_id||'
                     , last_update_login          = '||g_login_id||'
                     , program_update_date        = '''||g_date||'''
                     , program_application_id     = '||g_prog_appl_id||'
                     , program_id                 = '||g_prog_id||'
                     , request_id                 = '||g_req_id||'
		     ,(period_balance_dr, period_balance_cr
                      , beginning_balance_dr, beginning_balance_cr) = (SELECT /*+ $parallel$  index(tmp,xla_ac_bgnbal_gt_U1) */
                                                                                NVL (b.period_balance_dr, 0)
                                                                              + NVL (tmp.period_balance_dr, 0) period_balance_dr
                                                                            ,   NVL (b.period_balance_cr, 0)
                                                                              + NVL (tmp.period_balance_cr, 0) period_balance_cr
                                                                            ,   NVL (b.beginning_balance_dr, 0)
                                                                              + NVL (tmp.beginning_balance_dr, 0) beginning_balance_dr
                                                                            ,   NVL (b.beginning_balance_cr, 0)
                                                                              + NVL (tmp.beginning_balance_cr, 0) beginning_balance_cr
                                                                       FROM xla_ac_bal_interim_gt tmp
                                                                       WHERE tmp.application_id                   = b.application_id
                                                                           AND tmp.ledger_id                      = b.ledger_id
                                                                           AND tmp.code_combination_id            = b.code_combination_id
                                                                           AND tmp.analytical_criterion_code      = b.analytical_criterion_code
                                                                           AND tmp.analytical_criterion_type_code = b.analytical_criterion_type_code
                                                                           AND tmp.amb_context_code               = b.amb_context_code
                                                                           AND NVL (tmp.ac1, '' '')               = NVL (b.ac1, '' '')
                                                                           AND NVL (tmp.ac2, '' '')               = NVL (b.ac2, '' '')
                                                                           AND NVL (tmp.ac3, '' '')               = NVL (b.ac3, '' '')
                                                                           AND NVL (tmp.ac4, '' '')               = NVL (b.ac4, '' '')
                                                                           AND NVL (tmp.ac5, '' '')               = NVL (b.ac5, '' '')
                                                                           AND tmp.effective_period_num           = b.effective_period_num)
                    WHERE ( b.application_id
                          , b.ledger_id
                          , b.code_combination_id
                          , b.analytical_criterion_code
                          , b.analytical_criterion_type_code
                          , b.amb_context_code
                          , NVL (b.ac1, '' '')
                          , NVL (b.ac2, '' '')
                          , NVL (b.ac3, '' '')
                          , NVL (b.ac4, '' '')
                          , NVL (b.ac5, '' '')
                          , b.effective_period_num
                          ) IN (SELECT /*+ $parallel_1$ full(xal_bal1) */
                                         xal_bal1.application_id
                                       , xal_bal1.ledger_id
                                       , xal_bal1.code_combination_id
                                       , xal_bal1.analytical_criterion_code
                                       , xal_bal1.analytical_criterion_type_code
                                       , xal_bal1.amb_context_code
                                       , NVL (xal_bal1.ac1, '' '')
                                       , NVL (xal_bal1.ac2, '' '')
                                       , NVL (xal_bal1.ac3, '' '')
                                       , NVL (xal_bal1.ac4, '' '')
                                       , NVL (xal_bal1.ac5, '' '')
                                       , xal_bal1.effective_period_num
                                FROM xla_ac_bal_interim_gt xal_bal1)';
Line: 1146

     l_update_bal := REPLACE(l_update_bal,'$parallel$','parallel(tmp)');
Line: 1147

     l_update_bal := REPLACE(l_update_bal,'$parallel_1$','parallel(xal_bal1)');
Line: 1149

     l_update_bal := REPLACE(l_update_bal,'$parallel$','');
Line: 1150

     l_update_bal := REPLACE(l_update_bal,'$parallel_1$','');
Line: 1156

	     (p_msg      => 'AC l_update_bal_1:'||substr(l_update_bal, 1, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1160

	     (p_msg      => 'AC l_update_bal_2:'||substr(l_update_bal, 1001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1164

	     (p_msg      => 'AC l_update_bal_3:'||substr(l_update_bal, 2001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1168

	     (p_msg      => 'AC l_update_bal_4:'||substr(l_update_bal, 3001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1172

	     (p_msg      => 'AC l_update_bal_5:'||substr(l_update_bal, 4001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1176

	     (p_msg      => 'AC l_update_bal_6:'||substr(l_update_bal, 5001, 999)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1184

   EXECUTE IMMEDIATE l_update_bal;
Line: 1187

   l_update1_count := SQL%ROWCOUNT;
Line: 1192

         , p_msg         =>    '# rows updated in xla_ac_balances : '
                            || l_update1_count
         , p_level       => c_level_procedure
          );
Line: 1201

   IF  l_update1_count  <> l_merge_count
   THEN
    -- insert rows only if the rows updated is not equal to the total no of rows in gt table
    l_insert_bal := 'INSERT INTO xla_ac_balances xba
                              (  application_id
                               , ledger_id
                               , code_combination_id
                               , analytical_criterion_code
                               , analytical_criterion_type_code
                               , amb_context_code
                               , ac1
                               , ac2
                               , ac3
                               , ac4
                               , ac5
                               , period_name
                               , period_year
                               , first_period_flag
                               , period_balance_dr
                               , period_balance_cr
                               , beginning_balance_dr
                               , beginning_balance_cr
                               , initial_balance_flag
                               , effective_period_num
                               , creation_date
                               , created_by
                               , last_update_date
                               , last_updated_by
			       , last_update_login
			       , program_update_date
			       , program_application_id
			       , program_id
			       , request_id
                              )
                   SELECT /*+ $parallel$ */
                              temp.application_id
                            , temp.ledger_id
                            , temp.code_combination_id
                            , temp.analytical_criterion_code
                            , temp.analytical_criterion_type_code
                            , temp.amb_context_code
                            , temp.ac1
                            , temp.ac2
                            , temp.ac3
                            , temp.ac4
                            , temp.ac5
                            , gps.period_name
                            , gps.period_year
                            , DECODE (gps.period_num, 1, ''Y'', ''N'') first_period_flag
                            , temp.period_balance_dr
                            , temp.period_balance_cr
                            , temp.beginning_balance_dr
                            , temp.beginning_balance_cr
                            , ''N'' initial_balance_flag
                            , temp.effective_period_num
                            , '''||g_date||'''
                            , '||g_user_id||'
                            , '''||g_date||'''
                            , '||g_user_id||'
			    , '||g_login_id||'
			    , '''||g_date||'''
			    , '||g_prog_appl_id||'
			    , '||g_prog_id||'
			    , '||g_req_id||'
                    FROM xla_ac_bal_interim_gt temp
                       , xla_analytical_hdrs_b xbh
                       , gl_code_combinations gcc
                       , gl_period_statuses gps
                       , xla_ledger_relationships_v xlr
                   WHERE xlr.ledger_id  = temp.ledger_id
                      AND gps.ledger_id = DECODE(xlr.ledger_category_code,''ALC''
                                                ,xlr.primary_ledger_id , temp.ledger_id)
                      AND gps.effective_period_num = temp.effective_period_num
                      AND gps.application_id = 101
                      AND gps.adjustment_period_flag = ''N''
                      AND gps.closing_status IN (''O'', ''C'', ''P'')
                      AND gcc.code_combination_id = temp.code_combination_id
                      AND xbh.analytical_criterion_code = temp.analytical_criterion_code
                      AND xbh.analytical_criterion_type_code =  temp.analytical_criterion_type_code
                      AND xbh.amb_context_code = temp.amb_context_code
                      AND xbh.balancing_flag <> ''N''
                      AND (   gps.period_year =  SUBSTR (temp.effective_period_num, 1, 4)
                              OR xbh.year_end_carry_forward_code = ''A''
                              OR (    xbh.year_end_carry_forward_code = ''B''
                                      AND gcc.account_type IN (''A'', ''L'', ''O'')
                                  )
                           )
                      AND NOT EXISTS ( SELECT /*+ no_unnest $parallel_1$ */ 1
                                       FROM xla_ac_balances xba
                                       WHERE xba.application_id = temp.application_id
                                         AND xba.ledger_id = temp.ledger_id
                                         AND xba.code_combination_id =  temp.code_combination_id
                                         AND xba.analytical_criterion_code = temp.analytical_criterion_code
                                         AND xba.analytical_criterion_type_code = temp.analytical_criterion_type_code
                                         AND xba.amb_context_code = temp.amb_context_code
                                         AND NVL (xba.ac1, '' '') = NVL (temp.ac1, '' '')
                                         AND NVL (xba.ac2, '' '') = NVL (temp.ac2, '' '')
                                         AND NVL (xba.ac3, '' '') = NVL (temp.ac3, '' '')
                                         AND NVL (xba.ac4, '' '') = NVL (temp.ac4, '' '')
                                         AND NVL (xba.ac5, '' '') = NVL (temp.ac5, '' '')
                                         AND xba.period_name = gps.period_name)';
Line: 1305

        l_insert_bal := REPLACE(l_insert_bal,'$parallel$','parallel(temp)');
Line: 1306

        l_insert_bal := REPLACE(l_insert_bal,'$parallel_1$','parallel(xba)');
Line: 1308

        l_insert_bal := REPLACE(l_insert_bal,'$parallel$','');
Line: 1309

        l_insert_bal := REPLACE(l_insert_bal,'$parallel_1$','');
Line: 1315

	     (p_msg      => 'AC l_insert_bal_1:'||substr(l_insert_bal, 1, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1319

	     (p_msg      => 'AC l_insert_bal_2:'||substr(l_insert_bal, 1001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1323

	     (p_msg      => 'AC l_insert_bal_3:'||substr(l_insert_bal, 2001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1327

	     (p_msg      => 'AC l_insert_bal_4:'||substr(l_insert_bal, 3001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1331

	     (p_msg      => 'AC l_insert_bal_5:'||substr(l_insert_bal, 4001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1335

	     (p_msg      => 'AC l_insert_bal_6:'||substr(l_insert_bal, 5001, 999)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1341

    EXECUTE IMMEDIATE l_insert_bal;
Line: 1343

    l_insert2_count := SQL%ROWCOUNT;
Line: 1352

         , p_msg         =>    ' # rows inserted into xla_ac_balances : '
                            || l_insert2_count
         , p_level       => c_level_procedure
          );
Line: 1362

   l_update_processed := 'UPDATE /*+ use_nl(ael) */xla_ae_lines ael
                                                     SET analytical_balance_flag   = '''||g_postupdate_flag||'''
                                                    WHERE application_id           = :'||l_processed_bind_count||'
                                                    AND analytical_balance_flag    = '''||g_preupdate_flag||'''
                                                    AND (ae_header_id,ae_line_num) IN
						                      ( SELECT /*+ $parallel$ leading(aeh)  */
                                                                              ael.ae_header_id
                                                                             ,ael.ae_line_num
                                                                         FROM xla_ae_headers aeh
                                                                                , xla_ae_lines ael
                                                                                , gl_period_statuses gps
                                                                                , xla_ledger_options xlo
                                                                                , xla_ledger_relationships_v xlr
                                                                                $bal_concurrency$
                                                                        WHERE aeh.accounting_entry_status_code = ''F''
                                                                          AND aeh.application_id               = :'||l_processed_bind_count||'
                                                                          AND aeh.ledger_id                    = xlr.ledger_id
                                                                          AND ael.ae_header_id                 = aeh.ae_header_id
									  AND aeh.balance_type_code            = ''A''
                                                                          AND ael.analytical_balance_flag      = '''||g_preupdate_flag||'''
                                                                          AND ael.application_id               = aeh.application_id
                                                                          AND xlo.ledger_id                    = DECODE(xlr.ledger_category_code, ''ALC''
                                                                                                                       ,xlr.primary_ledger_id, xlr.ledger_id)
                                                                          AND gps.ledger_id                    = xlo.ledger_id
                                                                          AND gps.application_id               = 101
                                                                          AND gps.closing_status               IN (''O'', ''C'', ''P'')
                                                                          AND gps.effective_period_num         <= xlo.effective_period_num
                                                                          AND gps.adjustment_period_flag       = ''N''
                                                                          AND gps.period_name                  = aeh.period_name
                                                                         ' ;
Line: 1398

     l_update_processed := REPLACE(l_update_processed,'$bal_concurrency$',',xla_bal_concurrency_control bcc');
Line: 1399

     l_update_processed := l_update_processed||
     ' AND bcc.request_id = :'||l_processed_bind_count||'
       AND bcc.accounting_batch_id          = aeh.accounting_batch_id
       AND bcc.application_id               = aeh.application_id' ;
Line: 1408

     l_update_processed := REPLACE(l_update_processed,'$bal_concurrency$','');
Line: 1413

     l_update_processed := l_update_processed||
   ' AND aeh.accounting_batch_id = :'||l_processed_bind_count;
Line: 1422

     l_update_processed := l_update_processed||
   ' AND aeh.event_id  = :'||l_processed_bind_count;
Line: 1431

   l_update_processed := l_update_processed||
   ' AND aeh.entity_id  = :'||l_processed_bind_count;
Line: 1439

   l_update_processed := l_update_processed||
   ' AND aeh.ae_header_id  = :'||l_processed_bind_count;
Line: 1448

   l_update_processed := l_update_processed||
   ' AND ael.ae_line_num  = :'||l_processed_bind_count;
Line: 1462

    l_update_processed := l_update_processed || '
    AND aeh.ledger_id = :'||l_processed_bind_count;
Line: 1471

   l_update_processed := l_update_processed||')';
Line: 1475

   l_update_processed := REPLACE(l_update_processed,'$parallel$','parallel(aeh)');
Line: 1477

   l_update_processed := REPLACE(l_update_processed,'$parallel$','');
Line: 1483

	     (p_msg      => 'AC l_update_processed_1:'||substr(l_update_processed, 1, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1487

	     (p_msg      => 'AC l_update_processed_2:'||substr(l_update_processed, 1001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1491

	     (p_msg      => 'AC l_update_processed_3:'||substr(l_update_processed, 2001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1495

	     (p_msg      => 'AC l_update_processed_4:'||substr(l_update_processed, 3001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1499

	     (p_msg      => 'AC l_update_processed_5:'||substr(l_update_processed, 4001, 999)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 1507

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1),l_processed_bind_array(1);
Line: 1510

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1), l_processed_bind_array(1),l_processed_bind_array(2);
Line: 1513

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1),l_processed_bind_array(1),l_processed_bind_array(2),l_processed_bind_array(3);
Line: 1516

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1), l_processed_bind_array(1),l_processed_bind_array(2),l_processed_bind_array(3)
                       ,l_processed_bind_array(4);
Line: 1520

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1),l_processed_bind_array(1),l_processed_bind_array(2),l_processed_bind_array(3)
                       ,l_processed_bind_array(4),l_processed_bind_array(5);
Line: 1524

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1),l_processed_bind_array(1),l_processed_bind_array(2),l_processed_bind_array(3)
                       ,l_processed_bind_array(4),l_processed_bind_array(5),l_processed_bind_array(6);
Line: 1528

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1),l_processed_bind_array(1),l_processed_bind_array(2),l_processed_bind_array(3)
                       ,l_processed_bind_array(4),l_processed_bind_array(5),l_processed_bind_array(6),l_processed_bind_array(7);
Line: 1532

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1),l_processed_bind_array(1),l_processed_bind_array(2),l_processed_bind_array(3)
                       ,l_processed_bind_array(4),l_processed_bind_array(5),l_processed_bind_array(6),l_processed_bind_array(7)
		       ,l_processed_bind_array(8);
Line: 1538

   l_update2_count := SQL%ROWCOUNT;
Line: 1543

         , p_msg         => '# Rows update in xla_ae_lines' || l_update2_count
         , p_level       => c_level_procedure
          );
Line: 1594

   l_insert1_count  NUMBER;
Line: 1596

   l_update1_count  NUMBER;
Line: 1597

   l_insert2_count  NUMBER;
Line: 1598

   l_update2_count  NUMBER;
Line: 1599

   l_update_bal        VARCHAR2(6000);
Line: 1600

   l_insert_bal        VARCHAR2(6000);
Line: 1601

   l_update_processed  VARCHAR2(5000);
Line: 1607

   l_summary_stmt VARCHAR2(6000):= 'INSERT INTO xla_ctrl_bal_interim_gt (
                                               application_id
                                             , ledger_id
                                             , code_combination_id
                                             , party_type_code
                                             , party_id
                                             , party_site_id
                                             , period_name
                                             , effective_period_num
                                             , period_balance_dr
                                             , period_balance_cr
                                             , period_year
                                            )
                                   SELECT   /*+ $parallel$ use_nl(aeh) use_nl(ael) */
                                               ael.application_id
                                             , ael.ledger_id
                                             , ael.code_combination_id
                                             , ael.party_type_code
                                             , ael.party_id
                                             , nvl(ael.party_site_id,-999)   -- bug11887321
                                             , gps.period_name
                                             , gps.effective_period_num
                                             , $period_balance_dr$
                                             , $period_balance_cr$
                                              , SUBSTR (gps.effective_period_num, 1, 4) period_year
                                      FROM xla_ae_headers aeh
                                         , xla_ae_lines ael
                                         , gl_period_statuses gps
                                         , xla_ledger_options xlo
                                         , xla_ledger_relationships_v xlr
                                           $bal_concurrency$
                                     WHERE aeh.application_id = :'||l_summary_bind_count||'
                                       AND aeh.accounting_entry_status_code = ''F''
				       AND aeh.balance_type_code            = ''A''
                                       AND ael.application_id = aeh.application_id
                                       AND ael.ae_header_id = aeh.ae_header_id
                                       AND ael.control_balance_flag = '''||g_preupdate_flag||'''
                                       AND ael.ledger_id = aeh.ledger_id
                                       AND xlr.ledger_id = aeh.ledger_id
                                       AND xlo.application_id = aeh.application_id
                                       AND xlo.ledger_id = DECODE (xlr.ledger_category_code , ''ALC''
                                                                 , xlr.primary_ledger_id , xlr.ledger_id )
                                       AND gps.ledger_id = xlo.ledger_id
                                       AND gps.application_id = 101
                                       AND gps.closing_status IN (''O'', ''C'', ''P'')
                                       AND gps.effective_period_num <= xlo.effective_period_num
                                       AND gps.adjustment_period_flag = ''N''
                                       AND gps.period_name = aeh.period_name';
Line: 1913

   l_insert1_count := SQL%ROWCOUNT;
Line: 1918

         , p_msg         =>    '# rows inserted in xla_ctrl_bal_interim_gt : '
                            || l_insert1_count
         , p_level       => c_level_procedure
          );
Line: 1924

   IF l_insert1_count = 0
   THEN
   IF (c_level_procedure >= g_log_level)
   THEN
       TRACE (p_module      => l_log_module
            , p_msg         => 'No Records to process ' || l_insert1_count
            , p_level       => c_level_procedure
             );
Line: 1941

    USING (SELECT period_balance_dr
                , period_balance_cr
                , SUM (lag_dr) OVER (PARTITION BY application_id, ledger_id, code_combination_id
                , party_type_code, party_id, party_site_id
                  ORDER BY application_id
                 , ledger_id
                 , code_combination_id
                 , party_type_code
                 , party_id
                 , party_site_id
                 , effective_period_num) xal_beginning_balance_dr
                 , SUM (lag_cr) OVER (PARTITION BY application_id, ledger_id, code_combination_id
                 , party_type_code, party_id, party_site_id
                  ORDER BY application_id
                 , ledger_id
                 , code_combination_id
                 , party_type_code
                 , party_id
                 , party_site_id
                 , effective_period_num) xal_beginning_balance_cr
                , application_id
                , ledger_id
                , code_combination_id
                , party_type_code
                , party_id
                , party_site_id
                , period_name
                , effective_period_num
                , period_year
             FROM (SELECT   /*+  leading(xag,xal_bal)  */
                            xal_bal.application_id
                          , xal_bal.ledger_id
                          , xal_bal.code_combination_id
                          , xal_bal.party_type_code
                          , xal_bal.party_id
                          , xal_bal.party_site_id
                          , xal_bal.period_name
                          , xal_bal.effective_period_num
                          , xal_bal.period_balance_dr
                          , xal_bal.period_balance_cr
                          , xal_bal.period_year
                          , LAG (NVL (xal_bal.period_balance_dr, 0)
                               , 1
                               , NVL (xal_bal.beginning_balance_dr, 0)
                                ) OVER (PARTITION BY xal_bal.application_id, xal_bal.ledger_id
                                , xal_bal.code_combination_id, xal_bal.party_type_code
                                , xal_bal.party_id, xal_bal.party_site_id
                                ORDER BY xal_bal.application_id
                           , xal_bal.ledger_id
                           , xal_bal.code_combination_id
                           , xal_bal.party_type_code
                           , xal_bal.party_id
                           , xal_bal.party_site_id
                           , xal_bal.effective_period_num) lag_dr
                          , LAG (NVL (xal_bal.period_balance_cr, 0)
                               , 1
                               , NVL (xal_bal.beginning_balance_cr, 0)
                                ) OVER (PARTITION BY xal_bal.application_id, xal_bal.ledger_id
                                , xal_bal.code_combination_id, xal_bal.party_type_code
                                , xal_bal.party_id, xal_bal.party_site_id
                                ORDER BY xal_bal.application_id
                           , xal_bal.ledger_id
                           , xal_bal.code_combination_id
                           , xal_bal.party_type_code
                           , xal_bal.party_id
                           , xal_bal.party_site_id
                           , xal_bal.effective_period_num) lag_cr
                       FROM (SELECT   tmp.application_id
                                    , tmp.ledger_id
                                    , tmp.code_combination_id
                                    , tmp.party_type_code
                                    , tmp.party_id
                                    , tmp.party_site_id
                                    , MAX
                                         (DECODE
                                               (gps.effective_period_num
                                              , tmp.effective_period_num, tmp.period_balance_dr
                                              , NULL
                                               )
                                         ) period_balance_dr
                                    , MAX
                                         (DECODE
                                               (gps.effective_period_num
                                              , tmp.effective_period_num, tmp.period_balance_cr
                                              , NULL
                                               )
                                         ) period_balance_cr
                                    , tmp.beginning_balance_dr
                                    , tmp.beginning_balance_cr
                                    , gps.period_name
                                    , gps.effective_period_num
                                    , gps.period_year
                                 FROM gl_period_statuses gps
                                    , xla_ctrl_bal_interim_gt tmp
                                    , xla_ledger_options xlo
                                    , xla_ledger_relationships_v xlr
                                WHERE gps.effective_period_num <= xlo.effective_period_num
                                AND gps.effective_period_num >=   tmp.effective_period_num
                                  AND gps.closing_status IN ('O', 'C', 'P')
                                  AND gps.adjustment_period_flag = 'N'
                                  AND gps.application_id = 101
                                  AND gps.ledger_id = xlo.ledger_id
                                  AND tmp.application_id = xlo.application_id
                                  AND tmp.ledger_id = xlr.ledger_id
                                  AND xlo.ledger_id = DECODE(xlr.ledger_category_code, 'ALC'
				                            ,xlr.primary_ledger_id, xlr.ledger_id)
                             GROUP BY tmp.application_id
                                    , tmp.ledger_id
                                    , tmp.code_combination_id
                                    , tmp.party_type_code
                                    , tmp.party_id
                                    , tmp.party_site_id
                                    , tmp.beginning_balance_dr
                                    , tmp.beginning_balance_cr
                                    , gps.period_name
                                    , gps.effective_period_num
                                    , gps.period_year) xal_bal
                   ORDER BY xal_bal.application_id
                          , xal_bal.ledger_id
                          , xal_bal.code_combination_id
                          , xal_bal.party_type_code
                          , xal_bal.party_id
                          , xal_bal.party_site_id
                          , xal_bal.effective_period_num
                          , xal_bal.period_year)) tmp
    ON (    stmp.application_id = tmp.application_id
        AND stmp.ledger_id = tmp.ledger_id
        AND stmp.code_combination_id = tmp.code_combination_id
        AND stmp.party_type_code = tmp.party_type_code
        AND stmp.party_id = tmp.party_id
        AND stmp.party_site_id = tmp.party_site_id
        AND stmp.effective_period_num = tmp.effective_period_num)
    WHEN MATCHED THEN
       UPDATE
          SET stmp.beginning_balance_dr = tmp.xal_beginning_balance_dr
            , stmp.beginning_balance_cr = tmp.xal_beginning_balance_cr
    WHEN NOT MATCHED THEN
       INSERT (stmp.application_id, stmp.ledger_id
             , stmp.code_combination_id, stmp.party_type_code
             , stmp.party_id, stmp.party_site_id, stmp.period_balance_dr
             , stmp.period_balance_cr, stmp.beginning_balance_dr
             , stmp.beginning_balance_cr, stmp.period_name
             , stmp.effective_period_num, stmp.period_year)
       VALUES (tmp.application_id, tmp.ledger_id
             , tmp.code_combination_id, tmp.party_type_code
             , tmp.party_id, tmp.party_site_id, tmp.period_balance_dr
             , tmp.period_balance_cr, tmp.xal_beginning_balance_dr
             , tmp.xal_beginning_balance_cr, tmp.period_name
             , tmp.effective_period_num, tmp.period_year);
Line: 2106

   l_update_bal := 'UPDATE /*+ ordered index(b,xla_control_balances_N99) */xla_control_balances b
    SET last_update_date           = '''||g_date||'''
      , last_updated_by            = '||g_user_id||'
      , last_update_login          = '||g_login_id||'
      , program_update_date        = '''||g_date||'''
      , program_application_id     = '||g_prog_appl_id||'
      , program_id                 = '||g_prog_id||'
      , request_id                 = '||g_req_id||'
      ,(period_balance_dr, period_balance_cr, beginning_balance_dr
       , beginning_balance_cr) =
           (SELECT /*+ $parallel$ index(tmp,xla_ctrl_bal_interim_gt_U1) */
                     NVL (b.period_balance_dr, 0)
                   + NVL (tmp.period_balance_dr, 0) period_balance_dr
                 ,   NVL (b.period_balance_cr, 0)
                   + NVL (tmp.period_balance_cr, 0) period_balance_cr
                 ,   NVL (b.beginning_balance_dr, 0)
                   + NVL (tmp.beginning_balance_dr, 0) beginning_balance_dr
                 ,   NVL (b.beginning_balance_cr, 0)
                   + NVL (tmp.beginning_balance_cr, 0) beginning_balance_cr
              FROM xla_ctrl_bal_interim_gt tmp
             WHERE tmp.application_id = b.application_id
               AND tmp.ledger_id = b.ledger_id
               AND tmp.code_combination_id = b.code_combination_id
               AND tmp.party_type_code = b.party_type_code
               AND tmp.party_id = b.party_id
               AND tmp.party_site_id = b.party_site_id
               AND tmp.effective_period_num = b.effective_period_num)
   WHERE (b.application_id
       , b.ledger_id
       , b.code_combination_id
       , b.party_type_code
       , b.party_id
       , b.party_site_id
       , b.effective_period_num
        ) IN (
           SELECT /*+ $parallel_1$ full(xal_bal1) */
                  xal_bal1.application_id
                , xal_bal1.ledger_id
                , xal_bal1.code_combination_id
                , xal_bal1.party_type_code
                , xal_bal1.party_id
                , xal_bal1.party_site_id
                , xal_bal1.effective_period_num
             FROM xla_ctrl_bal_interim_gt xal_bal1)';
Line: 2153

   l_update_bal := REPLACE(l_update_bal,'$parallel$','parallel(tmp)');
Line: 2154

   l_update_bal := REPLACE(l_update_bal,'$parallel_1$','parallel(xal_bal1)');
Line: 2156

   l_update_bal := REPLACE(l_update_bal,'$parallel$','');
Line: 2157

   l_update_bal := REPLACE(l_update_bal,'$parallel_1$','');
Line: 2163

	     (p_msg      => 'CTRL: l_update_bal_1:'||substr(l_update_bal, 1, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2167

	     (p_msg      => 'CTRL: l_update_bal_2:'||substr(l_update_bal, 1001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2171

	     (p_msg      => 'CTRL: l_update_bal_3:'||substr(l_update_bal, 2001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2175

	     (p_msg      => 'CTRL: l_update_bal_4:'||substr(l_update_bal, 3001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2179

	     (p_msg      => 'CTRL: l_update_bal_5:'||substr(l_update_bal, 4001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2183

	     (p_msg      => 'CTRL: l_update_bal_6:'||substr(l_update_bal, 5001, 999)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2189

   EXECUTE IMMEDIATE l_update_bal;
Line: 2191

  l_update1_count:=SQL%ROWCOUNT;
Line: 2196

         , p_msg         =>    '# rows updated in xla_control_balances : '
                            || l_update1_count
         , p_level       => c_level_procedure
          );
Line: 2205

   IF l_update1_count <> l_merge_count
   THEN
   -- insert rows only if the rows updated is not equal to the total no of rows in gt table
   l_insert_bal := 'INSERT INTO xla_control_balances xba (
                               application_id
                             , ledger_id
                             , code_combination_id
                             , party_type_code
                             , party_id
                             , party_site_id
                             , period_name
                             , period_year
                             , first_period_flag
                             , period_balance_dr
                             , period_balance_cr
                             , beginning_balance_dr
                             , beginning_balance_cr
                             , initial_balance_flag
                             , effective_period_num
                             , creation_date
                             , created_by
                             , last_update_date
                             , last_updated_by
			     , last_update_login
			     , program_update_date
			     , program_application_id
			     , program_id
			     , request_id
                            )
                   SELECT /*+ $parallel$ */
                              temp.application_id
                            , temp.ledger_id
                            , temp.code_combination_id
                            , temp.party_type_code
                            , temp.party_id
                            , temp.party_site_id
                            , gps.period_name
                            , gps.period_year
                            , DECODE (gps.period_num, 1, ''Y'', ''N'') first_period_flag
                            , temp.period_balance_dr
                            , temp.period_balance_cr
                            , temp.beginning_balance_dr
                            , temp.beginning_balance_cr
                            , ''N'' initial_balance_flag
                            , temp.effective_period_num
                            , '''||g_date||'''
                            , '||g_user_id||'
                            , '''||g_date||'''
                            , '||g_user_id||'
			    , '||g_login_id||'
			    , '''||g_date||'''
			    , '||g_prog_appl_id||'
			    , '||g_prog_id||'
			    , '||g_req_id||'
                     FROM xla_ctrl_bal_interim_gt temp
                        , gl_period_statuses gps
                        , xla_ledger_relationships_v xlr
                    WHERE xlr.ledger_id = temp.ledger_id
                      AND gps.ledger_id = DECODE(xlr.ledger_category_code, ''ALC''
                                                ,xlr.primary_ledger_id , xlr.ledger_id)
                      AND gps.effective_period_num = temp.effective_period_num
                      AND gps.application_id = 101
                      AND gps.adjustment_period_flag = ''N''
                      AND gps.closing_status IN (''O'', ''C'', ''P'')
                      AND NOT EXISTS ( SELECT /*+ no_unnest $parallel_1$ */ 1
                                         FROM xla_control_balances xba
                                        WHERE xba.application_id = temp.application_id
                                          AND xba.ledger_id = temp.ledger_id
                                          AND xba.code_combination_id = temp.code_combination_id
                                          AND xba.party_type_code = temp.party_type_code
                                          AND xba.party_id = temp.party_id
                                          AND xba.party_site_id = temp.party_site_id
                                          AND xba.period_name = temp.period_name)';
Line: 2281

    l_insert_bal := REPLACE(l_insert_bal,'$parallel$','parallel(temp)');
Line: 2282

    l_insert_bal := REPLACE(l_insert_bal,'$parallel_1$','parallel(xba)');
Line: 2284

    l_insert_bal := REPLACE(l_insert_bal,'$parallel$','');
Line: 2285

    l_insert_bal := REPLACE(l_insert_bal,'$parallel_1$','');
Line: 2291

	     (p_msg      => 'CTRL: l_insert_bal_1:'||substr(l_insert_bal, 1, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2295

	     (p_msg      => 'CTRL: l_insert_bal_2:'||substr(l_insert_bal, 1001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2299

	     (p_msg      => 'CTRL: l_insert_bal_3:'||substr(l_insert_bal, 2001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2303

	     (p_msg      => 'CTRL: l_insert_bal_4:'||substr(l_insert_bal, 3001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2307

	     (p_msg      => 'CTRL: l_insert_bal_5:'||substr(l_insert_bal, 4001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2311

	     (p_msg      => 'CTRL: l_insert_bal_6:'||substr(l_insert_bal, 5001, 999)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2317

   EXECUTE IMMEDIATE l_insert_bal;
Line: 2319

   l_insert2_count := SQL%ROWCOUNT;
Line: 2325

         , p_msg         =>    ' # rows inserted into xla_control_balances : '
                            || l_insert2_count
         , p_level       => c_level_procedure
          );
Line: 2334

   l_update_processed := 'UPDATE /*+ use_nl(ael) */xla_ae_lines ael
                     SET control_balance_flag   = '''||g_postupdate_flag||'''
                    WHERE application_id        = :'||l_processed_bind_count||'
                    AND control_balance_flag    = '''||g_preupdate_flag||'''
                    AND (ae_header_id,ae_line_num) IN ( SELECT /*+ $parallel$ leading(aeh)  */
                                                              ael.ae_header_id
                                                             ,ael.ae_line_num
                                                         FROM xla_ae_headers aeh
                                                            , xla_ae_lines ael
                                                            , gl_period_statuses gps
                                                            , xla_ledger_options xlo
                                                            , xla_ledger_relationships_v xlr
                                                              $bal_concurrency$
                                                        WHERE aeh.accounting_entry_status_code = ''F''
                                                          AND aeh.application_id               = :'||l_processed_bind_count||'
							  AND aeh.balance_type_code            = ''A''
                                                          AND aeh.ledger_id                    = xlr.ledger_id
                                                          AND ael.ae_header_id                 = aeh.ae_header_id
                                                          AND ael.control_balance_flag      = '''||g_preupdate_flag||'''
                                                          AND ael.application_id               = aeh.application_id
                                                          AND xlo.ledger_id                    = DECODE(xlr.ledger_category_code, ''ALC''
                                                                                                       ,xlr.primary_ledger_id, xlr.ledger_id)
                                                          AND gps.ledger_id                    = xlo.ledger_id
                                                          AND gps.application_id               = 101
                                                          AND gps.closing_status               IN (''O'', ''C'', ''P'')
                                                          AND gps.effective_period_num         <= xlo.effective_period_num
                                                          AND gps.adjustment_period_flag       = ''N''
                                                          AND gps.period_name                  = aeh.period_name' ;
Line: 2369

    l_update_processed := REPLACE(l_update_processed,'$bal_concurrency$',',xla_bal_concurrency_control bcc');
Line: 2370

    l_update_processed := l_update_processed||
    ' AND bcc.request_id = :'||l_processed_bind_count||'
    AND bcc.accounting_batch_id          = aeh.accounting_batch_id
    AND bcc.application_id               = aeh.application_id' ;
Line: 2378

     l_update_processed := REPLACE(l_update_processed,'$bal_concurrency$','');
Line: 2383

    l_update_processed := l_update_processed||
    ' AND aeh.accounting_batch_id = :'||l_processed_bind_count;
Line: 2392

     l_update_processed := l_update_processed||
   ' AND aeh.event_id  = :'||l_processed_bind_count;
Line: 2401

     l_update_processed := l_update_processed||
   ' AND aeh.entity_id  = :'||l_processed_bind_count;
Line: 2409

     l_update_processed := l_update_processed||
   ' AND aeh.ae_header_id  = :'||l_processed_bind_count;
Line: 2417

     l_update_processed := l_update_processed||
   ' AND ael.ae_line_num  = :'||l_processed_bind_count;
Line: 2431

     l_update_processed := l_update_processed || '
     AND aeh.ledger_id = :'||l_processed_bind_count;
Line: 2440

   l_update_processed := l_update_processed||')';
Line: 2444

   l_update_processed := REPLACE(l_update_processed,'$parallel$','parallel(aeh)');
Line: 2446

   l_update_processed := REPLACE(l_update_processed,'$parallel$','');
Line: 2452

	     (p_msg      => 'CTRL: l_update_processed_1:'||substr(l_update_processed, 1, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2456

	     (p_msg      => 'CTRL: l_update_processed_2:'||substr(l_update_processed, 1001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2460

	     (p_msg      => 'CTRL: l_update_processed_3:'||substr(l_update_processed, 2001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2464

	     (p_msg      => 'CTRL: l_update_processed_4:'||substr(l_update_processed, 3001, 1000)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2468

	     (p_msg      => 'CTRL: l_update_processed_5:'||substr(l_update_processed, 4001, 999)
	     ,p_level    => C_LEVEL_STATEMENT
	     ,p_module   => l_log_module);
Line: 2480

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1),l_processed_bind_array(1);
Line: 2483

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1), l_processed_bind_array(1),l_processed_bind_array(2);
Line: 2486

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1),l_processed_bind_array(1),l_processed_bind_array(2),l_processed_bind_array(3);
Line: 2489

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1), l_processed_bind_array(1),l_processed_bind_array(2),l_processed_bind_array(3)
                       ,l_processed_bind_array(4);
Line: 2493

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1),l_processed_bind_array(1),l_processed_bind_array(2),l_processed_bind_array(3)
                       ,l_processed_bind_array(4),l_processed_bind_array(5);
Line: 2497

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1),l_processed_bind_array(1),l_processed_bind_array(2),l_processed_bind_array(3)
                       ,l_processed_bind_array(4),l_processed_bind_array(5),l_processed_bind_array(6);
Line: 2501

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1),l_processed_bind_array(1),l_processed_bind_array(2),l_processed_bind_array(3)
                       ,l_processed_bind_array(4),l_processed_bind_array(5),l_processed_bind_array(6),l_processed_bind_array(7);
Line: 2505

     EXECUTE IMMEDIATE l_update_processed USING l_processed_bind_array(1),l_processed_bind_array(1),l_processed_bind_array(2),l_processed_bind_array(3)
                       ,l_processed_bind_array(4),l_processed_bind_array(5),l_processed_bind_array(6),l_processed_bind_array(7)
		       ,l_processed_bind_array(8);
Line: 2511

   l_update2_count := SQL%ROWCOUNT;
Line: 2517

         , p_msg         =>    ' # rows updated in xla_ae_lines : ' || l_update2_count
         , p_level       => c_level_procedure
          );
Line: 2561

			       , p_update_mode           IN   VARCHAR2
			       , p_execution_mode        IN   VARCHAR2
			      )
RETURN BOOLEAN
IS
l_log_module        VARCHAR2 (240);
Line: 2623

         , p_msg         => 'p_update_mode : ' || p_execution_mode
         , p_level       => c_level_exception
          );
Line: 2642

      l_open_period_sql    := 'SELECT SUM(
                                          DECODE(xlo_effective_period_num, gps_effective_period_num,0,1)
                                          )
				FROM (
                                      SELECT DISTINCT xlo.effective_period_num xlo_effective_period_num
                                             ,(SELECT MAX(gps.effective_period_num)
                                                 FROM gl_period_statuses gps
                                               WHERE gps.application_id = 101
                                                 AND gps.ledger_id = xlo.ledger_id
                                                 AND gps.closing_status IN (''O'',''C'',''P'')
                                                 AND gps.adjustment_period_flag = ''N''
                                               )gps_effective_period_num
                                              , xlo.ledger_id
                                        FROM xla_ledger_options xlo
                                            ,xla_ledger_relationships_v xlr
                                       WHERE xlr.ledger_id = '||p_ledger_id || '
                                         AND xlo.ledger_id = DECODE(xlr.ledger_category_code , ''ALC''
                                                                   ,xlr.primary_ledger_id, xlr.ledger_id)
                                         AND xlo.application_id = '||p_application_id||'
                                      )';
Line: 2663

      l_open_period_sql     := 'SELECT SUM(
                                           DECODE(xlo_effective_period_num, gps_effective_period_num,0,1)
                                           )
				 FROM (
                                       SELECT DISTINCT xlo.effective_period_num xlo_effective_period_num
                                             ,(SELECT MAX(gps.effective_period_num)
                                                 FROM gl_period_statuses gps
                                               WHERE gps.application_id = 101
                                                 AND gps.ledger_id = xlo.ledger_id
                                                 AND gps.closing_status IN (''O'',''C'',''P'')
                                                 AND gps.adjustment_period_flag = ''N''
                                               )gps_effective_period_num
                                              , xlo.ledger_id
                                        FROM xla_ledger_options xlo
                                            ,xla_ledger_relationships_v xlr
                                            ,xla_ae_headers xah
                                       WHERE xlo.ledger_id = DECODE(xlr.ledger_category_code , ''ALC''
                                                                   ,xlr.primary_ledger_id, xlr.ledger_id)
                                         AND xlo.application_id = '||p_application_id||'
                                         AND xah.application_id = ' ||p_application_id ||'
                                         AND xlr.ledger_id      = xah.ledger_id';
Line: 2774

   IF p_update_mode IN ('A','F','M')
   THEN
     l_operation_code := 'A';
Line: 2777

   ELSIF  p_update_mode = 'D'
   THEN
     l_operation_code := 'R'; --remove
Line: 2786

                            || 'Invalid value for Update Mode '|| p_update_mode
         , p_level       => c_level_exception
          );
Line: 2798

                               || 'Invalid value for update mode '||p_update_mode
       );
Line: 2803

      g_preupdate_flag  := 'P';
Line: 2804

      g_postupdate_flag := 'Y';
Line: 2807

      g_preupdate_flag  := 'Y';
Line: 2808

      g_postupdate_flag := 'P';
Line: 2896

     SELECT distinct effective_period_num
       FROM xla_ledger_options
      WHERE ledger_id = p_ledger_id
        AND effective_period_num is not null;
Line: 2919

   SELECT count(1)
    INTO l_count
   FROM gl_period_statuses
   WHERE application_id=101
   AND ledger_id = p_ledger_id
   AND effective_period_num = p_effective_period_num
   AND closing_status in ('O','C','P')
   AND adjustment_period_flag = 'N';
Line: 2986

     INSERT INTO xla_ac_balances
                 (application_id
                , ledger_id
                , code_combination_id
                , analytical_criterion_code
                , analytical_criterion_type_code
                , amb_context_code
                , ac1
                , ac2
                , ac3
                , ac4
                , ac5
                , period_name
                , first_period_flag
                , effective_period_num
                , initial_balance_flag
                , creation_date
                , created_by
                , last_update_date
                , last_updated_by
                , beginning_balance_dr
                , beginning_balance_cr
                , period_year
		, last_update_login
		, program_update_date
		, program_application_id
		, program_id
		, request_id
                 )
        SELECT /*+ parallel(bal,24) */
               bal.application_id
             , bal.ledger_id
             , bal.code_combination_id
             , bal.analytical_criterion_code
             , bal.analytical_criterion_type_code
             , bal.amb_context_code
             , bal.ac1
             , bal.ac2
             , bal.ac3
             , bal.ac4
             , bal.ac5
             , gps.period_name
             , DECODE (period_num, 1, 'Y', 'N') first_period_flag
             , gps.effective_period_num
             , 'N' initial_balance_flag
             , g_date
             , g_user_id
             , g_date
             , g_user_id
             , DECODE (gps.period_year
                     , SUBSTR (bal.effective_period_num, 1, 4), (  NVL
                                                                      (bal.beginning_balance_dr
                                                                     , 0
                                                                      )
                                                                 + NVL
                                                                      (bal.period_balance_dr
                                                                     , 0
                                                                      )
                        )
                     , DECODE (SIGN (  (  NVL (bal.beginning_balance_dr, 0)
                                        + NVL (bal.period_balance_dr, 0)
                                       )
                                     - (  NVL (bal.beginning_balance_cr, 0)
                                        + NVL (bal.period_balance_cr, 0)
                                       )
                                    )
                             , 1, (  (  NVL (bal.beginning_balance_dr, 0)
                                      + NVL (bal.period_balance_dr, 0)
                                     )
                                   - (  NVL (bal.beginning_balance_cr, 0)
                                      + NVL (bal.period_balance_cr, 0)
                                     )
                                )
                             , 0
                              )
                      ) beginning_balance_dr
             , DECODE (gps.period_year
                     , SUBSTR (bal.effective_period_num, 1, 4), (  NVL
                                                                      (bal.beginning_balance_cr
                                                                     , 0
                                                                      )
                                                                 + NVL
                                                                      (bal.period_balance_cr
                                                                     , 0
                                                                      )
                        )
                     , DECODE (SIGN (  (  NVL (bal.beginning_balance_dr, 0)
                                        + NVL (bal.period_balance_dr, 0)
                                       )
                                     - (  NVL (bal.beginning_balance_cr, 0)
                                        + NVL (bal.period_balance_cr, 0)
                                       )
                                    )
                             , -1, (  NVL (bal.beginning_balance_cr, 0)
                                    + NVL (bal.period_balance_cr, 0)
                                   )
                                - (  NVL (bal.beginning_balance_dr, 0)
                                   + NVL (bal.period_balance_dr, 0)
                                  )
                             , 0
                              )
                      ) beginning_balance_cr
             ,gps.period_year
	     ,g_login_id
             ,g_date
             ,g_prog_appl_id
             ,g_prog_id
             ,g_req_id
          FROM gl_period_statuses gps
             , xla_ac_balances bal
             , gl_code_combinations gcc
             , xla_analytical_hdrs_b xbh
             , (select ledger_id
                   from xla_ledger_relationships_v
                   where (ledger_category_code IN ('PRIMARY','ALC')
                            and primary_ledger_id = p_ledger_id)
                            or (ledger_category_code = 'SECONDARY'
                            and ledger_id = p_ledger_id)
                    ) xlr
         WHERE gps.application_id = 101
           AND gps.ledger_id = p_ledger_id
           AND gps.closing_status IN ('O', 'C', 'P')
           AND gps.adjustment_period_flag = 'N'
           AND gps.effective_period_num <= p_effective_period_num
           AND gps.effective_period_num > l_from_effective_period_num
           AND bal.effective_period_num = l_from_effective_period_num
           AND bal.ledger_id = xlr.ledger_id
           AND gcc.code_combination_id = bal.code_combination_id
           AND xbh.analytical_criterion_code = bal.analytical_criterion_code
           AND xbh.analytical_criterion_type_code =
                                           bal.analytical_criterion_type_code
           AND xbh.amb_context_code = bal.amb_context_code
           AND xbh.balancing_flag <> 'N'
           AND (   gps.period_year = SUBSTR (bal.effective_period_num, 1, 4)
                OR xbh.year_end_carry_forward_code = 'A'
                OR (    xbh.year_end_carry_forward_code = 'B'
                    AND gcc.account_type IN ('A', 'L', 'O')
                   )
               );
Line: 3142

     INSERT INTO xla_control_balances
                 (application_id
                , ledger_id
                , code_combination_id
                , party_type_code
                , party_id
                , party_site_id
                , period_name
                , first_period_flag
                , effective_period_num
                , initial_balance_flag
                , creation_date
                , created_by
                , last_update_date
                , last_updated_by
                , beginning_balance_dr
                , beginning_balance_cr
                , period_year
		, last_update_login
                , program_update_date
                , program_application_id
                , program_id
                , request_id
                 )
        SELECT /*+ parallel(bal,24) */
               bal.application_id
             , bal.ledger_id
             , bal.code_combination_id
             , bal.party_type_code
             , bal.party_id
             , bal.party_site_id
             , gps.period_name
             , DECODE (period_num, 1, 'Y', 'N') first_period_flag
             , gps.effective_period_num
             , 'N' initial_balance_flag
             , g_date
             , g_user_id
             , g_date
             , g_user_id
             , DECODE (gps.period_year
                     , SUBSTR (bal.effective_period_num, 1, 4), (  NVL
                                                                      (bal.beginning_balance_dr
                                                                     , 0
                                                                      )
                                                                 + NVL
                                                                      (bal.period_balance_dr
                                                                     , 0
                                                                      )
                        )
                     , DECODE (SIGN (  (  NVL (bal.beginning_balance_dr, 0)
                                        + NVL (bal.period_balance_dr, 0)
                                       )
                                     - (  NVL (bal.beginning_balance_cr, 0)
                                        + NVL (bal.period_balance_cr, 0)
                                       )
                                    )
                             , 1, (  (  NVL (bal.beginning_balance_dr, 0)
                                      + NVL (bal.period_balance_dr, 0)
                                     )
                                   - (  NVL (bal.beginning_balance_cr, 0)
                                      + NVL (bal.period_balance_cr, 0)
                                     )
                                )
                             , 0
                              )
                      ) beginning_balance_dr
             , DECODE (gps.period_year
                     , SUBSTR (bal.effective_period_num, 1, 4), (  NVL
                                                                      (bal.beginning_balance_cr
                                                                     , 0
                                                                      )
                                                                 + NVL
                                                                      (bal.period_balance_cr
                                                                     , 0
                                                                      )
                        )
                     , DECODE (SIGN (  (  NVL (bal.beginning_balance_dr, 0)
                                        + NVL (bal.period_balance_dr, 0)
                                       )
                                     - (  NVL (bal.beginning_balance_cr, 0)
                                        + NVL (bal.period_balance_cr, 0)
                                       )
                                    )
                             , -1, (  NVL (bal.beginning_balance_cr, 0)
                                    + NVL (bal.period_balance_cr, 0)
                                   )
                                - (  NVL (bal.beginning_balance_dr, 0)
                                   + NVL (bal.period_balance_dr, 0)
                                  )
                             , 0
                              )
                      ) beginning_balance_cr
                    ,gps.period_year
		    ,g_login_id
		    ,g_date
		    ,g_prog_appl_id
		    ,g_prog_id
	            ,g_req_id
          FROM gl_period_statuses gps
             , xla_control_balances bal
             ,(select ledger_id
                   from xla_ledger_relationships_v
                   where (ledger_category_code IN ('PRIMARY','ALC')
                            and primary_ledger_id = p_ledger_id)
                            or (ledger_category_code = 'SECONDARY'
                            and ledger_id = p_ledger_id)
                    ) xlr
         WHERE gps.application_id = 101
           AND gps.ledger_id = p_ledger_id
           AND gps.closing_status IN ('O', 'C', 'P')
           AND gps.adjustment_period_flag = 'N'
           AND gps.effective_period_num <= p_effective_period_num
           AND gps.effective_period_num > l_from_effective_period_num
           AND bal.effective_period_num = l_from_effective_period_num
           AND bal.ledger_id = xlr.ledger_id;
Line: 3268

     UPDATE xla_ledger_options
     SET effective_period_num = p_effective_period_num
     WHERE ledger_id = p_ledger_id
     AND nvl(effective_period_num,-1) < p_effective_period_num;
Line: 3275

        TRACE (p_msg         => '# rows updated in xla_ledger_options : ' || SQL%ROWCOUNT
             , p_level       => c_level_procedure
             , p_module      => l_log_module
              );
Line: 3283

        TRACE (p_msg         => 'xla_ledger_options updated with effective_period_num '||p_effective_period_num
                 , p_level       => c_level_procedure
                 , p_module      => l_log_module
                  );
Line: 3356

SELECT application_id
       ,ledger_id
   FROM xla_bal_concurrency_control
  WHERE ledger_id = p_ledger_id
  AND   application_id IN ( SELECT * FROM TABLE(g_application_array))
 FOR UPDATE NOWAIT; --Lock All the applications belonging to this ledger
Line: 3365

  SELECT l.ledger_category_code
       , gps.effective_period_num
       , adjustment_period_flag      -- Bug 12613841
    FROM gl_period_statuses gps
	   , gl_ledgers l
   WHERE l.ledger_id = p_ledger_id
     AND gps.ledger_id = l.ledger_id
     AND gps.application_id = 101
     AND gps.period_name = p_period_name;
Line: 3377

  SELECT COUNT(1) xlo_effperiod_count
    FROM xla_ledger_options
   WHERE ledger_id =  p_ledger_id
     AND effective_period_num is not null;
Line: 3384

  SELECT COUNT(1) bal_count
    FROM dual
  WHERE EXISTS (SELECT 1 FROM xla_control_balances where effective_period_num is  null)
    OR  EXISTS (SELECT 1 FROM xla_ac_balances where effective_period_num is  null);
Line: 3391

  SELECT COUNT(1) bal_sob_count
    FROM dual
   WHERE EXISTS (SELECT 1 FROM xla_control_balances WHERE ledger_id = p_ledger_id)
     OR  EXISTS (SELECT 1 FROM xla_ac_balances WHERE ledger_id = p_ledger_id);
Line: 3399

SELECT count(1)
INTO l_not_nul_count
FROM xla_ledger_options
WHERE effective_period_num IS NOT NULL;
Line: 3456

       UPDATE xla_ledger_options xlo
       SET effective_period_num = (SELECT gps.effective_period_num
                            FROM gl_period_statuses gps,gl_ledgers gll
                              WHERE gps.application_id= 101
                                AND gps.ledger_id     = xlo.ledger_id
                                AND gll.ledger_id     = xlo.ledger_id
                                AND gps.period_name   = gll.FIRST_LEDGER_PERIOD_NAME
               )
       WHERE ledger_id   in
       (
        SELECT ledger_id
        FROM xla_ledger_relationships_v xlr
        WHERE (xlr.primary_ledger_id = p_ledger_id OR ledger_id = p_ledger_id)
          AND xlr.relationship_enabled_flag = 'Y'
          AND xlr.ledger_category_code      IN('ALC',   'PRIMARY',   'SECONDARY')
       )
       and  effective_period_num  is null;
Line: 3476

       UPDATE xla_ac_balances xab
       SET EFFECTIVE_PERIOD_NUM =   (  SELECT gps.effective_period_num
                                         FROM gl_period_statuses gps
                                       WHERE  gps.ledger_id           = xab.ledger_id
                                       AND gps.application_id         = 101
                                       AND gps.adjustment_period_flag = 'N'
                                       AND gps.period_name            = xab.period_name
                                    )
       WHERE effective_period_num is null
       AND  ledger_id   in
       (
        SELECT ledger_id
        FROM xla_ledger_relationships_v xlr
        WHERE (xlr.primary_ledger_id = p_ledger_id OR ledger_id = p_ledger_id)
        AND xlr.relationship_enabled_flag = 'Y'
        AND xlr.ledger_category_code      IN('ALC',   'PRIMARY',   'SECONDARY')
       );
Line: 3498

                , p_msg         => '# Rows update in xla_ac_balances ' || SQL%ROWCOUNT
                , p_level       => c_level_procedure
                );
Line: 3504

       UPDATE xla_control_balances xab
       SET EFFECTIVE_PERIOD_NUM =   (  SELECT gps.effective_period_num
                                         FROM gl_period_statuses gps
                                        WHERE gps.ledger_id              = xab.ledger_id
                                          AND gps.application_id         =  101
                                          AND gps.adjustment_period_flag =  'N'
                                          AND gps.period_name=xab.period_name
                                    )
      WHERE effective_period_num is null
        AND  ledger_id   in
       (
        SELECT ledger_id
        FROM xla_ledger_relationships_v xlr
        WHERE (xlr.primary_ledger_id = p_ledger_id OR ledger_id = p_ledger_id)
        AND xlr.relationship_enabled_flag = 'Y'
        AND xlr.ledger_category_code      IN('ALC',   'PRIMARY',   'SECONDARY')
       );
Line: 3526

                , p_msg         => '# Rows update in xla_control_balances ' || SQL%ROWCOUNT
                , p_level       => c_level_procedure
                );
Line: 3539

			  Run xlabalupg.sql to use Update Subledger Accounting Balances program'
		       );
Line: 3545

   THEN -- No record in balances table. So, update xla_ledger_options and exit

     --Bug 12673914
     --Added condition effective_period_num < l_effective_period_num
      UPDATE xla_ledger_options
         SET effective_period_num = l_effective_period_num
       WHERE ledger_id   in
       (
        SELECT ledger_id
        FROM xla_ledger_relationships_v xlr
        WHERE (xlr.primary_ledger_id = p_ledger_id OR ledger_id = p_ledger_id)
          AND xlr.relationship_enabled_flag = 'Y'
          AND xlr.ledger_category_code      IN('ALC',   'PRIMARY',   'SECONDARY')
       )
       AND nvl(effective_period_num,-1) < l_effective_period_num;
Line: 3566

                , p_msg         => '# Rows update in xla_ledger_options ' || SQL%ROWCOUNT
                , p_level       => c_level_procedure
                );
Line: 3574

       UPDATE xla_ac_balances xab
       SET EFFECTIVE_PERIOD_NUM =   (  SELECT gps.effective_period_num
                                         FROM gl_period_statuses gps
                                       WHERE  gps.ledger_id           = xab.ledger_id
                                       AND gps.application_id         = 101
                                       AND gps.adjustment_period_flag = 'N'
                                       AND gps.period_name            = xab.period_name
                                    )
       WHERE effective_period_num is null
       AND ledger_id   in
       (
        SELECT ledger_id
        FROM xla_ledger_relationships_v xlr
        WHERE (xlr.primary_ledger_id = p_ledger_id OR ledger_id = p_ledger_id)
          AND xlr.relationship_enabled_flag = 'Y'
          AND xlr.ledger_category_code      IN('ALC',   'PRIMARY',   'SECONDARY')
       );
Line: 3596

                , p_msg         => '# Rows update in xla_ac_balances ' || SQL%ROWCOUNT
                , p_level       => c_level_procedure
                );
Line: 3602

       UPDATE xla_control_balances xab
       SET EFFECTIVE_PERIOD_NUM =   (  SELECT gps.effective_period_num
                                         FROM gl_period_statuses gps
                                        WHERE gps.ledger_id              = xab.ledger_id
                                          AND gps.application_id         =  101
                                          AND gps.adjustment_period_flag =  'N'
                                          AND gps.period_name=xab.period_name
                                    )
      WHERE effective_period_num is null
        AND ledger_id   in
       (
        SELECT ledger_id
        FROM xla_ledger_relationships_v xlr
        WHERE (xlr.primary_ledger_id = p_ledger_id OR ledger_id = p_ledger_id)
          AND xlr.relationship_enabled_flag = 'Y'
          AND xlr.ledger_category_code      IN('ALC',   'PRIMARY',   'SECONDARY')
       );
Line: 3624

                , p_msg         => '# Rows update in xla_control_balances ' || SQL%ROWCOUNT
                , p_level       => c_level_procedure
                );
Line: 3662

                         , p_value_2           => 'EXCEPTION:'|| 'Record cannot be inserted into XLA_BAL_CONCURRENCY_CONTROL '
                         );
Line: 3678

               delete xla_bal_concurrency_control where  request_id = g_req_id;  --Bug  13614923
Line: 3682

               delete xla_bal_concurrency_control where  request_id = g_req_id;  --Bug  13614923
Line: 3727

   delete xla_bal_concurrency_control where  request_id = g_req_id;   -- Bug13614923
Line: 3735

   delete xla_bal_concurrency_control where  request_id = g_req_id;   -- Bug13614923
Line: 3741

   delete xla_bal_concurrency_control where  request_id = g_req_id;   -- Bug13614923
Line: 3752

PROCEDURE massive_update_srs (
  p_errbuf                OUT NOCOPY      VARCHAR2
, p_retcode               OUT NOCOPY      NUMBER
, p_application_id        IN              NUMBER
, p_ledger_id             IN              NUMBER
, p_accounting_batch_id   IN              NUMBER
, p_update_mode           IN              VARCHAR2
)
IS
/*======================================================================+
|                                                                       |
| Public Function                                                       |
|                                                                       |
| Description                                                           |
| -----------                                                           |
|  Just the SRS wrapper for massive_update in batch mode                |
|                                                                       |
| Pseudo-code                                                           |
| -----------                                                           |
|  Call massive_update             and assign its return code to        |
|  p_retcode                                                            |
|  RETURN p_retcode (0=success, 1=warning, 2=error)                     |
|                                                                       |
| Open issues                                                           |
| -----------                                                           |
|                                                                       |
| 1) Need to review the value assigned to p_errbuf                      |
|                                                                       |
|                                                                       |
|                                                                       |
+======================================================================*/
l_commit_flag      VARCHAR2 (1);
Line: 3792

SELECT application_id
       ,ledger_id
   FROM xla_bal_concurrency_control
  WHERE application_id = p_application_id
  AND   ledger_id IN ( SELECT * FROM TABLE(g_ledger_array))
  FOR UPDATE NOWAIT;
Line: 3806

    l_log_module := c_default_module || '.massive_update_srs';
Line: 3841

         , p_msg         => 'p_update_mode ' || p_update_mode
         , p_level       => c_level_procedure
          );
Line: 3860

   SELECT count(1)
     INTO l_ledger_count
   FROM xla_ledger_options
   WHERE effective_period_num IS NOT NULL;
Line: 3868

			,'Balances upgrade script xlabalupg.sql has not been run. Run xlabalupg.sql to use Update Subledger Accounting Balances program'
		       );
Line: 3890

                        , p_value_1           => 'xla_balances_calc_pkg.massive_update_srs'
                        , p_token_2           => 'ERROR'
                        , p_value_2           =>    'EXCEPTION:'
                                                 || 'p_application_id cannot be NULL'
                         );
Line: 3913

         , p_value_1           => 'xla_balances_calc_pkg.massive_update_srs'
         , p_token_2           => 'ERROR'
         , p_value_2           =>    'EXCEPTION:'
                                  || 'p_ledger_id and p_accounting_batch_id cannot be NULL'
          );
Line: 3938

         , p_value_1           => 'xla_balances_calc_pkg.massive_update_srs'
         , p_token_2           => 'ERROR'
         , p_value_2           =>    'EXCEPTION:'
                                  || 'XLA_BAL_CONCURRENCY_CONTROL COULD NOT BE LOCKED. RESOURCE BUSY'
          );
Line: 3963

                              , p_update_mode                         => p_update_mode
                              , p_execution_mode          => l_execution_mode
                             )
        THEN
              p_retcode := 0;  --bug14255667
Line: 3970

              DELETE  xla_bal_concurrency_control WHERE request_id     = g_req_id;   --Bug 13614923
Line: 3973

               DELETE  xla_bal_concurrency_control WHERE request_id     = g_req_id;   --Bug 13614923
Line: 3998

  for i in ( SELECT distinct application_id
       ,ledger_id
   FROM xla_bal_concurrency_control
  WHERE application_id = p_application_id
  AND   ledger_id IN ( SELECT * FROM TABLE(g_ledger_array)))
  loop
     fnd_file.put_line
    (fnd_file.LOG
    , 'There is another request(s) running for the ledger_id : '
     || i.ledger_id
     || ' application_id : '
     || i.application_id);
Line: 4014

   'Pls. submit Subledger Accounting Balances Update Concurrent Program once the running request is completed');
Line: 4019

 DELETE  xla_bal_concurrency_control WHERE request_id     = g_req_id;
Line: 4027

  DELETE  xla_bal_concurrency_control WHERE request_id     = g_req_id;  --Bug 13614923
Line: 4035

  DELETE  xla_bal_concurrency_control WHERE request_id     = g_req_id;
Line: 4037

        (p_location      => 'xla_balances_calc_pkg.massive_update_srs');
Line: 4038

END massive_update_srs;
Line: 4047

FUNCTION massive_update (
p_application_id        IN   INTEGER
, p_ledger_id             IN   INTEGER
, p_entity_id             IN   INTEGER
, p_event_id              IN   INTEGER
, p_request_id            IN   INTEGER
, p_accounting_batch_id   IN   INTEGER
, p_update_mode           IN   VARCHAR2
, p_execution_mode        IN   VARCHAR2
)
RETURN BOOLEAN
IS
/*======================================================================+
|                                                                       |
| Public Function                                                       |
|                                                                       |
| Description                                                           |
| -----------                                                           |
|  Called in online accounting flow            |
|                                                                       |
| Pseudo-code                                                           |
| -----------                                                           |
|  Call massive_update             and assign its return code to        |
|  p_retcode                                                            |
|  RETURN p_retcode (0=success, 1=warning, 2=error)                     |
|                                                                       |
| Open issues                                                           |
| -----------                                                           |
|                                                                       |
| 1) Need to review the value assigned to p_errbuf                      |
|                                                                       |
|                                                                       |
|                                                                       |
+======================================================================*/
l_commit_flag      VARCHAR2 (1);
Line: 4093

SELECT application_id
       ,ledger_id
   FROM xla_bal_concurrency_control
  WHERE application_id = p_application_id
  AND   ledger_id IN ( SELECT * FROM TABLE(g_ledger_array))
 FOR UPDATE NOWAIT;
Line: 4104

    l_log_module := c_default_module || '.massive_update';
Line: 4160

         , p_msg         => 'p_update_mode ' || p_update_mode
         , p_level       => c_level_procedure
          );
Line: 4186

   SELECT count(1)
     INTO l_ledger_count
   FROM xla_ledger_options
   WHERE effective_period_num IS NOT NULL;
Line: 4194

			,'Balances upgrade script xlabalupg.sql has not been run. Run xlabalupg.sql to use Update Subledger Accounting Balances program'
		       );
Line: 4216

                           , p_value_1           => 'xla_balances_calc_pkg.massive_update'
                           , p_token_2           => 'ERROR'
                           , p_value_2           =>    'EXCEPTION:'
                                                    || 'p_application_id cannot be NULL'
                            );
Line: 4234

                                   , argument4        => p_update_mode
                                    );
Line: 4277

           , p_value_1           => 'xla_balances_calc_pkg.MASSIVE_UPDATE'
           , p_token_2           => 'ERROR'
           , p_value_2           =>    'EXCEPTION:'
                                    || 'XLA_BAL_CONCURRENCY_CONTROL COULD NOT BE LOCKED. RESOURCE BUSY'
            );
Line: 4299

                             , p_update_mode         => p_update_mode
                             , p_execution_mode      => p_execution_mode
                            )
      THEN
         if p_entity_id is null then
            DELETE FROM xla_bal_concurrency_control where request_id=g_req_id;
Line: 4306

            DELETE FROM xla_bal_concurrency_control where request_id=-1*p_entity_id;
Line: 4318

          DELETE FROM xla_bal_concurrency_control where request_id=g_req_id;
Line: 4320

          DELETE FROM xla_bal_concurrency_control where request_id=-1*p_entity_id;
Line: 4338

  for i in ( SELECT distinct application_id
       ,ledger_id
   FROM xla_bal_concurrency_control
  WHERE application_id = p_application_id
  AND   ledger_id IN ( SELECT * FROM TABLE(g_ledger_array)))
  loop
     fnd_file.put_line
    (fnd_file.LOG
    , 'There is another request(s) running for the ledger_id : '
     || i.ledger_id
     || ' application_id : '
     || i.application_id);
Line: 4354

   'Pls. submit Subledger Accounting Balances Update Concurrent Program once the running request is completed');
Line: 4366

    DELETE FROM xla_bal_concurrency_control where request_id=g_req_id;
Line: 4368

    DELETE FROM xla_bal_concurrency_control where request_id=-1*p_entity_id;
Line: 4376

    DELETE FROM xla_bal_concurrency_control where request_id=g_req_id;
Line: 4378

    DELETE FROM xla_bal_concurrency_control where request_id=-1*p_entity_id;
Line: 4386

    DELETE FROM xla_bal_concurrency_control where request_id=g_req_id;
Line: 4388

    DELETE FROM xla_bal_concurrency_control where request_id=-1*p_entity_id;
Line: 4392

                      (p_location      => 'xla_balances_calc_pkg.massive_update');
Line: 4394

END massive_update;
Line: 4404

FUNCTION single_update
(
p_application_id          IN INTEGER
,p_ae_header_id            IN INTEGER
,p_ae_line_num             IN INTEGER
,p_update_mode             IN VARCHAR2
) RETURN BOOLEAN
IS
l_return_value                 BOOLEAN      ;
Line: 4420

  SELECT application_id
        ,ledger_id
   FROM xla_bal_concurrency_control
  WHERE application_id   IN ( SELECT * FROM TABLE(g_application_array))
  AND   ledger_id        IN ( SELECT * FROM TABLE(g_ledger_array))
 FOR UPDATE NOWAIT;
Line: 4428

     l_log_module := C_DEFAULT_MODULE||'.single_update';
Line: 4447

            ,p_msg      => 'p_update_mode ' || p_update_mode
            ,p_level    => C_LEVEL_PROCEDURE);
Line: 4467

   SELECT count(1)
     INTO l_ledger_count
   FROM xla_ledger_options
   WHERE effective_period_num is not null;
Line: 4476

			,'Balances upgrade script xlabalupg.sql has not been run. Run xlabalupg.sql to use Update Subledger Accounting Balances program'
		       );
Line: 4517

     IF p_update_mode IS NULL
     THEN
               IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
                      trace
                             (p_module => l_log_module
                             ,p_msg   => 'EXCEPTION:' ||'p_update_mode cannot be NULL'
                              ,p_level => C_LEVEL_EXCEPTION
                             );
Line: 4532

                      ,p_value_2        => 'EXCEPTION:' ||'p_update_mode cannot be NULL');
Line: 4533

     ELSIF p_update_mode NOT IN ('A', 'D', 'F')
     THEN
               IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
                      trace
                             (p_module => l_log_module
                             ,p_msg   => 'EXCEPTION:' || 'Unsupported value for p_update_mode: ' || p_update_mode
                             ,p_level => C_LEVEL_EXCEPTION
                             );
Line: 4548

                      ,p_value_2        => 'EXCEPTION:' ||'Unsupported value for p_update_mode: ' || p_update_mode);
Line: 4568

           , p_value_1           => 'xla_balances_calc_pkg.MASSIVE_UPDATE'
           , p_token_2           => 'ERROR'
           , p_value_2           =>    'EXCEPTION:'
                                    || 'XLA_BAL_CONCURRENCY_CONTROL COULD NOT BE LOCKED. RESOURCE BUSY'
            );
Line: 4588

                                        , p_update_mode             => p_update_mode
                                        , p_execution_mode          => l_execution_mode
                                        );
Line: 4592

     DELETE FROM xla_bal_concurrency_control where request_id=-1*p_ae_header_id;
Line: 4605

       DELETE FROM xla_bal_concurrency_control where request_id=-1*p_ae_header_id;
Line: 4630

 for i in ( SELECT distinct application_id
       ,ledger_id
   FROM xla_bal_concurrency_control
  WHERE application_id = p_application_id
  AND   ledger_id IN ( SELECT * FROM TABLE(g_ledger_array)))
  loop
     fnd_file.put_line
    (fnd_file.LOG
    , 'There is another request(s) running for the ledger_id : '
     || i.ledger_id
     || ' application_id : '
     || i.application_id);
Line: 4646

   'Pls. submit Subledger Accounting Balances Update Concurrent Program once the running request is completed');
Line: 4649

 DELETE FROM xla_bal_concurrency_control where request_id=-1*p_ae_header_id;
Line: 4654

    DELETE FROM xla_bal_concurrency_control where request_id=-1*p_ae_header_id;
Line: 4659

    DELETE FROM xla_bal_concurrency_control where request_id=-1*p_ae_header_id;
Line: 4661

          (p_location => 'xla_balances_calc_pkg.single_update');
Line: 4663

END single_update;
Line: 4720

         SELECT gcc.reference3
           INTO l_qualifier_value
           FROM gl_code_combinations gcc
          WHERE gcc.code_combination_id = p_code_combination_id;
Line: 4763

            SELECT xsl.control_account_type_code
              INTO l_je_source_name
              FROM xla_subledgers xsl
             WHERE xsl.application_id = p_application_id;
Line: 4908

l_query := 'SELECT count(1)
            FROM dual
            where exists(select 1
             from xla_ae_lines xal
                 ,xla_ae_line_acs xac
                 ,gl_period_statuses gps1
                 ,gl_period_statuses gps2
                 ,xla_ae_headers xah
            where xah.application_id = :'||to_number(l_bind_count)||'
              and xah.ledger_id = :'||to_number(l_bind_count+1)||'
              and xah.accounting_date between gps1.start_date and gps2.end_date
              and xal.application_id = xah.application_id
              and xal.ae_header_id = xah.ae_header_id
              and xal.analytical_balance_flag ='|| '''P'''||'
              and xac.ae_header_id = xal.ae_header_id
              and xac.ae_line_num = xal.ae_line_num
              and xac.analytical_criterion_code like :'||to_number(l_bind_count+2)||'
              and xac.analytical_criterion_type_code like :'||to_number(l_bind_count+3)||'
              and xac.amb_context_code = :'||to_number(l_bind_count+4)||'
              and gps1.application_id = 101
              and gps1.ledger_id= :'||to_number(l_bind_count+5)||'
              and gps1.effective_period_num = :'||to_number(l_bind_count+6)||'
              and gps2.application_id = gps1.application_id
              and gps2.ledger_id = gps1.ledger_id
              and gps2.effective_period_num = :'||to_number(l_bind_count+7);