DBA Data[Home] [Help]

APPS.CST_ACCOUNTINGPERIOD_PUB SQL Statements

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

Line: 83

    SELECT legal_entity
    INTO   l_legal_entity
    FROM   cst_acct_info_v
    WHERE  organization_id = p_org_id;
Line: 98

      SELECT  COUNT(*)
      INTO    l_tcount
      FROM    mtl_material_transactions_temp
      WHERE   organization_id = p_org_id
      AND     transaction_date <= l_sched_close_date
      AND     NVL(transaction_status,0) <> 2; -- 2 indicates a save-only status
Line: 117

      SELECT  /*+ INDEX (MMT MTL_MATERIAL_TRANSACTIONS_N10) */
              COUNT(*)
      INTO    l_tcount
      FROM    mtl_material_transactions MMT
      WHERE   organization_id = p_org_id
      AND     transaction_date <= l_sched_close_date
      AND     costed_flag IN('N','E');-- bug 13054482 Changed the not null condition, as it causes a index full scan
Line: 137

      SELECT  COUNT(*)
      INTO    l_tcount
      FROM    wip_cost_txn_interface
      WHERE   organization_id = p_org_id
      AND     transaction_date <= l_sched_close_date;
Line: 170

      SELECT  COUNT(*)
      INTO    l_tcount
      FROM    wsm_split_merge_txn_interface
      WHERE   organization_id = p_org_id
      AND     process_status <> wip_constants.completed
      AND     transaction_date <= l_sched_close_date;
Line: 182

      SELECT  COUNT(*)
      INTO    l_tcount
      FROM    wsm_lot_move_txn_interface
      WHERE   organization_id = p_org_id
      AND     status <> wip_constants.completed
      AND     transaction_date <= l_sched_close_date;
Line: 194

      SELECT  COUNT(*)
      INTO    l_tcount
      FROM    wsm_lot_split_merges_interface
      WHERE   organization_id = p_org_id
      AND     process_status <> wip_constants.completed
      AND     transaction_date <= l_sched_close_date;
Line: 217

      SELECT  period_start_date
      INTO    l_le_closing_fm_date
      FROM    org_acct_periods
      WHERE   acct_period_id = p_closing_period
      AND     organization_id = p_org_id;
Line: 253

      SELECT  COUNT(*)
      INTO    l_tcount
      FROM    rcv_transactions_interface
      WHERE   to_organization_id = p_org_id
      AND     transaction_date <= l_sched_close_date
      AND     destination_type_code in ('INVENTORY','SHOP FLOOR');
Line: 276

      SELECT  COUNT(*)
      INTO    l_tcount
      FROM    mtl_transactions_interface
      WHERE   organization_id = p_org_id
      AND     transaction_date <= l_sched_close_date
      AND      process_flag <> 9;
Line: 295

      SELECT  COUNT(*)
      INTO    l_tcount
      FROM    wip_move_txn_interface
      WHERE   organization_id = p_org_id
      AND     transaction_date <= l_sched_close_date;
Line: 313

      SELECT NVL(eam_enabled_flag, 'N'), NVL(lcm_enabled_flag, 'N')  /* Support for LCM */
      INTO   l_eam_enabled, l_lcm_enabled
      FROM   mtl_parameters
      WHERE  organization_id = p_org_id;
Line: 319

        SELECT count(*)
        INTO   l_tcount
        FROM   wip_discrete_jobs WDJ, wip_entities WE
        WHERE  WDJ.organization_id            = p_org_id
        AND    WDJ.scheduled_completion_date <= p_sched_close_date
        AND    WDJ.status_type                = 3  -- Released
        AND    WDJ.wip_entity_id              = WE.wip_entity_id
        AND    WDJ.organization_id            = WE.organization_id
        AND    WE.entity_type                 = 6; -- Maintenance Work Order
Line: 341

      SELECT  COUNT(*)
      INTO    l_tcount
      FROM    cst_lc_adj_interface
      WHERE   organization_id = p_org_id
      AND     transaction_date <= l_sched_close_date;
Line: 404

      SELECT  NVL(MAX(schedule_close_date), sysdate),
              count(*)
      FROM    org_acct_periods
      WHERE   organization_id = p_org_id;
Line: 413

      SELECT  start_date
      FROM    gl_periods
      WHERE   end_date < p_period_end_date
      AND     end_date >= x_last_scheduled_close_date
      AND     (period_name, period_year) not in
                (select period_name, period_year
                 from org_acct_periods
                 where organization_id = p_org_id)
      AND     period_type = p_acct_period_type
      AND     period_set_name = p_org_period_set_name
      AND     adjustment_period_flag = 'N';
Line: 427

      SELECT  org_acct_periods_s.nextval
      FROM    sys.dual;
Line: 432

      SELECT  period_start_date
      FROM    org_acct_periods
      WHERE   organization_id = p_org_id
      AND     period_name = p_open_period_name
      AND     period_year = p_open_period_year
      AND     period_num  = p_open_period_num
      AND     acct_period_id <> x_new_acct_period_id;
Line: 442

      SELECT NULL
      FROM   org_acct_periods
      WHERE  organization_id = p_org_id
      AND    period_year     = p_open_period_year
      AND    period_name     = p_open_period_name
      AND    period_num      = p_open_period_num;
Line: 570

    INSERT INTO org_acct_periods
     (acct_period_id,
      organization_id,
      last_update_date,
      last_updated_by,
      creation_date,
      created_by,
      period_set_name,
      period_year,
      period_num,
      period_name,
      description,
      period_start_date,
      schedule_close_date,
      open_flag,
      last_update_login)
    SELECT
      x_new_acct_period_id, -- acct_period_id
      p_org_id,             -- organization_id
      SYSDATE,              -- last_update_date
      p_user_id,            -- last_updated_by
      SYSDATE,              -- creation_date
      p_user_id,            -- created_by
      GLP.period_set_name,  -- period_set_name
      GLP.period_year,      -- period_year
      GLP.period_num,       -- period_num
      GLP.period_name,      -- period_name
      GLP.description,      -- description

      -- period_start_date
      decode(l_first_period,
             1, GLP.start_date,
             x_last_scheduled_close_date+1),

      GLP.end_date,         -- schedule_close_date
      'Y',                  -- open_flag
      -1                    -- last_update_login
    FROM  gl_periods GLP
    WHERE GLP.period_set_name = p_org_period_set_name
    AND   GLP.period_name     = p_open_period_name
    AND   GLP.period_type     = p_acct_period_type
    AND   GLP.adjustment_period_flag = 'N'
    AND  (GLP.period_name, GLP.period_year)
      NOT IN
       (SELECT period_name, period_year
        FROM   org_acct_periods
        WHERE  organization_id = p_org_id)
    AND NOT EXISTS
     (SELECT period_start_date
      FROM   org_acct_periods
      WHERE  organization_id = p_org_id
      AND    period_year     = p_open_period_year
      AND    period_name     = p_open_period_name
      AND    period_num      = p_open_period_num);
Line: 665

    SELECT NVL(MAX(schedule_close_date), SYSDATE)
    INTO x_last_scheduled_close_date
    FROM org_acct_periods
    WHERE organization_id = p_org_id;
Line: 765

      SELECT acct_period_id
      FROM   org_acct_periods
      WHERE  organization_id = p_org_id
      AND    schedule_close_date = (SELECT MIN(schedule_close_date)
                                    FROM   org_acct_periods
                                    WHERE  organization_id = p_org_id
                                    AND   (open_flag = 'Y' or open_flag = 'P'));
Line: 775

      SELECT MIN(acct_period_id)
      FROM   org_acct_periods
      WHERE  organization_id = p_org_id
      AND    acct_period_id  > p_closing_acct_period_id;
Line: 782

      SELECT acct_period_id
      FROM   org_acct_periods
      WHERE  organization_id = p_org_id
      AND    acct_period_id  = p_closing_acct_period_id
      AND    period_close_date IS NOT NULL
      AND    open_flag = 'P';
Line: 864

    SELECT operating_unit
    INTO   l_operating_unit
    FROM   cst_acct_info_v
    WHERE  organization_id = p_org_id;
Line: 995

    UPDATE org_acct_periods
    SET
      open_flag               = 'P',
      period_close_date       = trunc(sysdate),
      last_update_date        = sysdate, --trunc(sysdate),
      last_updated_by         = p_user_id,
      last_update_login       = p_login_id
    WHERE acct_period_id = p_closing_acct_period_id
    AND   organization_id = p_org_id
    -- program level check to make sure that
    -- the period is only closed once
    AND   open_flag = 'Y';
Line: 1038

    SELECT period_start_date, schedule_close_date
    INTO   l_period_start_date, l_sched_close_date
    FROM   org_acct_periods
    WHERE  acct_period_id = p_closing_acct_period_id
    AND    organization_id = p_org_id;
Line: 1045

    SELECT legal_entity
    INTO   l_legal_entity
    FROM   cst_acct_info_v
    WHERE  organization_id = p_org_id;
Line: 1066

    SELECT  COUNT(*)
    INTO    l_count
    FROM    mtl_material_transactions_temp
    WHERE   organization_id = p_org_id
    AND     transaction_date < l_sched_close_date
    AND     NVL(transaction_status,0) <> 2
    AND     rownum = 1; -- transaction_status = 2 indicates a save-only status
Line: 1080

    SELECT  /*+ INDEX (MMT MTL_MATERIAL_TRANSACTIONS_N10) */
            COUNT(*)
    INTO    l_count
    FROM    mtl_material_transactions MMT
    WHERE   organization_id = p_org_id
    AND     transaction_date < l_sched_close_date
    AND     costed_flag IN('N','E')-- bug 13054482 Changed the not null condition, as it causes a index full scan
    AND     rownum = 1;
Line: 1095

    SELECT  COUNT(*)
    INTO    l_count
    FROM    wip_cost_txn_interface
    WHERE   organization_id = p_org_id
    AND     transaction_date < l_sched_close_date
    AND     rownum = 1;
Line: 1108

    SELECT  COUNT(*)
    INTO    l_count
    FROM    wsm_split_merge_transactions
    WHERE   organization_id = p_org_id
    AND     costed <> wip_constants.completed
    AND     transaction_date < l_sched_close_date
    AND     rownum = 1;
Line: 1122

    SELECT  COUNT(*)
    INTO    l_count
    FROM    wsm_split_merge_txn_interface
    WHERE   organization_id = p_org_id
    AND     process_status <> wip_constants.completed
    AND     transaction_date < l_sched_close_date
    AND     rownum = 1;
Line: 1136

    UPDATE org_acct_periods
    SET    summarized_flag = 'N',
           open_flag = 'N'
    WHERE  organization_id = p_org_id
    AND    acct_period_id = p_closing_acct_period_id;
Line: 1148

      SELECT ML.lookup_code
      INTO   l_rep_type
      FROM   mfg_lookups ML,
             mtl_parameters MP
      WHERE  MP.organization_id = p_org_id
      AND    ML.lookup_type = 'CST_PER_CLOSE_REP_TYPE'
      AND    ML.lookup_code =
             DECODE(MP.primary_cost_method,
               1,DECODE(
                   MP.wms_enabled_flag,
                   'Y',1,
                   DECODE(
                     MP.cost_group_accounting,
                     1,DECODE(
                         MP.project_reference_enabled,
                         1,1,
                         2
                       ),
                     2
                   )
                 ),
               1
             );
Line: 1173

      SELECT GL.currency_code
      INTO   l_currency_code
      FROM   hr_organization_information HOI,
             gl_ledgers GL
      WHERE  HOI.organization_id = p_org_id
      AND    HOI.org_information_context = 'Accounting Information'
      AND    TO_NUMBER(HOI.org_information1) = GL.ledger_id;
Line: 1231

      UPDATE org_acct_periods
      SET    open_flag = 'N'
      WHERE  organization_id = p_org_id
      AND    acct_period_id = p_closing_acct_period_id;
Line: 1254

  PROCEDURE Update_EndDate(
    p_api_version            IN         NUMBER,
    p_org_id                 IN         NUMBER,
    p_new_end_date           IN         DATE,
    p_changed_acct_period_id IN         NUMBER,
    p_user_id                IN         NUMBER,
    p_login_id               IN         NUMBER,
    x_period_order           OUT NOCOPY BOOLEAN,
    x_update_failed          OUT NOCOPY BOOLEAN,
    x_return_status          OUT NOCOPY VARCHAR2
  ) IS

    l_next_periods_enddate  DATE;
Line: 1270

      SELECT NVL(MAX(schedule_close_date), p_new_end_date - 1)
      FROM   org_acct_periods
      WHERE  organization_id = p_org_id
      AND    acct_period_id  < p_changed_acct_period_id;
Line: 1276

      SELECT NVL(MIN(schedule_close_date), p_new_end_date + 1)
      FROM   org_acct_periods
      WHERE  organization_id = p_org_id
      AND    acct_period_id  > p_changed_acct_period_id;
Line: 1281

    l_api_name CONSTANT VARCHAR2(30) := 'Update_EndDate';
Line: 1289

    SAVEPOINT Update_EndDate_PUB;
Line: 1358

      UPDATE org_acct_periods
      SET    schedule_close_date     = p_new_end_date,
             last_update_date        = sysdate, --trunc(SYSDATE),
             last_updated_by         = p_user_id,
             last_update_login       = p_login_id
      WHERE  organization_id = p_org_id
      AND    acct_period_id  = p_changed_acct_period_id;
Line: 1367

      UPDATE org_acct_periods
      SET    period_start_date       = p_new_end_date + 1,
             last_update_date        = sysdate, --trunc(SYSDATE),
             last_updated_by         = p_user_id,
             last_update_login       = p_login_id
      WHERE  organization_id = p_org_id
      AND    acct_period_id  =
       (SELECT MIN(acct_period_id)
        FROM   org_acct_periods
        WHERE  acct_period_id  > p_changed_acct_period_id
        AND    organization_id = p_org_id);
Line: 1381

    x_update_failed := FALSE;
Line: 1387

      x_update_failed := TRUE;
Line: 1394

      ROLLBACK TO Update_EndDate_PUB;
Line: 1397

      ROLLBACK TO Update_EndDate_PUB;
Line: 1407

      x_update_failed := TRUE;
Line: 1409

  END Update_EndDate;
Line: 1458

    DELETE FROM org_acct_periods
    WHERE organization_id = p_org_id
    AND   acct_period_id =  x_acct_period_id;
Line: 1568

    SELECT legal_entity
    INTO   l_legal_entity
    FROM   cst_acct_info_v
    WHERE  organization_id = p_org_id;
Line: 1574

    SELECT period_start_date, schedule_close_date
    INTO   l_le_period_start_date, l_le_to_date
    FROM   org_acct_periods
    WHERE  organization_id = p_org_id
    AND    acct_period_id  = p_period_id;
Line: 1650

    SELECT MAX(acct_period_id)
    INTO   l_prior_period_id
    FROM   org_acct_periods
    WHERE  organization_id = p_org_id
    AND    acct_period_id < p_period_id;
Line: 1660

    SELECT count(*)
    INTO   l_resummarize
    FROM   org_acct_periods
    WHERE  organization_id = p_org_id
    AND    acct_period_id = p_period_id
    AND    summarized_flag = 'N'
    AND EXISTS
          (SELECT 'Data exists in CPCS'
           FROM   cst_period_close_summary
           WHERE  organization_id = p_org_id
           AND    acct_period_id = p_period_id);
Line: 1686

      DELETE cst_period_close_summary
      WHERE  organization_id = p_org_id
      AND    acct_period_id >= p_period_id;
Line: 1690

      /* Updating org_acct_periods in case the customer has not updated summarized_flag
         for all succeeding periods */
      l_stmt_num := 37;
Line: 1693

      UPDATE org_acct_periods
      SET    summarized_flag = 'N'
      WHERE  organization_id = p_org_id
      AND    acct_period_id >= p_period_id
      AND    summarized_flag = 'Y';
Line: 1702

    SELECT count(*)
    INTO   l_prev_summary
    FROM   org_acct_periods
    WHERE  organization_id = p_org_id
    AND    acct_period_id = l_prior_period_id
    AND    summarized_flag = 'Y';
Line: 1710

    SELECT count(*)
    INTO   l_cpcs_count
    FROM   cst_period_close_summary
    WHERE  organization_id = p_org_id
    AND    rownum = 1;
Line: 1718

    SELECT category_set_id
    INTO   l_category_set_id
    FROM   mtl_default_category_sets
    WHERE  functional_area_id = 5; -- Costing functional area
Line: 1728

      SELECT NVL(OAP1.schedule_close_date+1-(1/(24*3600)),
                 OAP2.period_start_date-(1/(24*3600)))
      INTO   l_le_prior_end_date
      FROM   org_acct_periods OAP1,
             org_acct_periods OAP2
      WHERE  OAP1.organization_id(+) = OAP2.organization_id
      AND    OAP1.acct_period_id(+) = l_prior_period_id
      AND    OAP2.organization_id = p_org_id
      AND    OAP2.acct_period_id = p_period_id;
Line: 1786

      INSERT
      INTO   cst_per_close_summary_temp(
             cost_group_id,
             subinventory_code,
             inventory_item_id,
             accounted_value,
             rollback_value,
             rollback_qty,
             rollback_onhand_value,
             rollback_intransit_value)
      SELECT CIQT.cost_group_id,
             CIQT.subinventory_code,
             CIQT.inventory_item_id,
             0 accounted_value,
             SUM(NVL(CIQT.rollback_qty,0))*NVL(CICT.item_cost,0) rollback_value,
             SUM(NVL(CIQT.rollback_qty,0)),
             SUM(DECODE(CIQT.qty_source,
                          3,NVL(CIQT.rollback_qty,0),
                          4,NVL(CIQT.rollback_qty,0),
                          5,NVL(CIQT.rollback_qty,0),
                          0))*NVL(CICT.item_cost,0) rollback_onhand_value,
             SUM(DECODE(CIQT.qty_source,
                          6,NVL(CIQT.rollback_qty,0),
                          7,NVL(CIQT.rollback_qty,0),
                          8,NVL(CIQT.rollback_qty,0),
                          0))*NVL(CICT.item_cost,0) rollback_intransit_value
      FROM   cst_inv_qty_temp CIQT,
             cst_inv_cost_temp CICT
      WHERE  CIQT.organization_id = p_org_id
      AND    CIQT.organization_id = CICT.organization_id
      AND    NVL(CIQT.cost_group_id,-1) =
             NVL(CICT.cost_group_id,NVL(CIQT.cost_group_id,-1))
      AND    CIQT.inventory_item_id = CICT.inventory_item_id
      AND    CICT.cost_source = 2 -- PAST
      GROUP BY
             CIQT.organization_id,
             CIQT.cost_group_id,
             CIQT.subinventory_code,
             CIQT.inventory_item_id,
             CICT.item_cost
     /* Bug 14036099*/
      HAVING SUM(NVL(CIQT.rollback_qty,0))*NVL(CICT.item_cost,0) <> 0 OR
             SUM(NVL(CIQT.rollback_qty,0)) <> 0 OR
             l_zero_val_hook = 0;
Line: 1837

          p_error_text => l_stmt_num||': Inserted  '||SQL%ROWCOUNT||
                          ' rows to CPCST for initialization'
        );
Line: 1843

      DELETE CST_ITEM_LIST_TEMP;
Line: 1844

      DELETE CST_CG_LIST_TEMP;
Line: 1845

      DELETE CST_SUB_LIST_TEMP;
Line: 1846

      DELETE CST_INV_QTY_TEMP;
Line: 1847

      DELETE CST_INV_COST_TEMP;
Line: 1850

      INSERT
      INTO   cst_inv_qty_temp(
             qty_source,
             organization_id,
             cost_group_id,
             subinventory_code,
             inventory_item_id,
             accounted_value)

      SELECT 1, -- PRIOR ONHAND
             p_org_id organization_id,
             CPCST.cost_group_id,
             CPCST.subinventory_code,
             CPCST.inventory_item_id,
             CPCST.rollback_onhand_value
      FROM   cst_per_close_summary_temp CPCST
      WHERE  CPCST.rollback_onhand_value <> 0

      UNION ALL

      SELECT 2, -- PRIOR INTRANSIT
             p_org_id organization_id,
             CPCST.cost_group_id,
             CPCST.subinventory_code,
             CPCST.inventory_item_id,
             CPCST.rollback_intransit_value
      FROM   cst_per_close_summary_temp CPCST
      WHERE  CPCST.rollback_intransit_value <> 0

      UNION ALL

      SELECT 21, -- CUMULATIVE ONHAND
             p_org_id organization_id,
             CPCST.cost_group_id,
             CPCST.subinventory_code,
             CPCST.inventory_item_id,
             CPCST.rollback_onhand_value
      FROM   cst_per_close_summary_temp CPCST
      WHERE  CPCST.rollback_onhand_value <> 0

      UNION ALL

      SELECT 22, -- CUMULATIVE INTRANSIT
             p_org_id organization_id,
             CPCST.cost_group_id,
             CPCST.subinventory_code,
             CPCST.inventory_item_id,
             CPCST.rollback_intransit_value
      FROM   cst_per_close_summary_temp CPCST
      WHERE  CPCST.rollback_intransit_value <> 0;
Line: 1903

        DELETE cst_per_close_summary_temp;
Line: 1911

          p_error_text => l_stmt_num||': Inserted  '||SQL%ROWCOUNT||
                          ' rows to CIQT as baseline from CPCST'
        );
Line: 1927

      INSERT
      INTO   cst_inv_qty_temp(
             qty_source,
             organization_id,
             cost_group_id,
             subinventory_code,
             inventory_item_id,
             accounted_value)
      SELECT
             1, -- PRIOR ONHAND
             p_org_id organization_id,
             CPCS.cost_group_id,
             CPCS.subinventory_code,
             CPCS.inventory_item_id,
             CPCS.rollback_onhand_value
      FROM
             cst_period_close_summary CPCS
      WHERE  CPCS.organization_id = p_org_id
      AND    CPCS.acct_period_id = NVL(l_prior_period_id,-1)

      UNION ALL

      SELECT
             2, -- PRIOR INTRANSIT
             p_org_id organization_id,
             CPCS.cost_group_id,
             CPCS.subinventory_code,
             CPCS.inventory_item_id,
             CPCS.rollback_intransit_value
      FROM
             cst_period_close_summary CPCS
      WHERE  CPCS.organization_id = p_org_id
      AND    CPCS.acct_period_id = NVL(l_prior_period_id,-1)

      UNION ALL

      SELECT
             21, -- CUMULATIVE ONHAND
             p_org_id organization_id,
             CPCS.cost_group_id,
             CPCS.subinventory_code,
             CPCS.inventory_item_id,
             CPCS.cumulative_onhand_mta
      FROM
             cst_period_close_summary CPCS
      WHERE  CPCS.organization_id = p_org_id
      AND    CPCS.acct_period_id = NVL(l_prior_period_id,-1)

      UNION ALL

      SELECT
             22, -- CUMULATIVE INTRANSIT
             p_org_id organization_id,
             CPCS.cost_group_id,
             CPCS.subinventory_code,
             CPCS.inventory_item_id,
             CPCS.cumulative_intransit_mta
      FROM
             cst_period_close_summary CPCS
      WHERE  CPCS.organization_id = p_org_id
      AND    CPCS.acct_period_id = NVL(l_prior_period_id,-1); */
Line: 1990

      INSERT ALL
      INTO cst_inv_qty_temp (
             qty_source,
             organization_id,
             cost_group_id,
             subinventory_code,
             inventory_item_id,
             accounted_value)
      VALUES (1, -- PRIOR ONHAND
             organization_id,
             cost_group_id,
             subinventory_code,
             inventory_item_id,
             rollback_onhand_value)
      INTO cst_inv_qty_temp (
             qty_source,
             organization_id,
             cost_group_id,
             subinventory_code,
             inventory_item_id,
             accounted_value)
      VALUES (2, -- PRIOR INTRANSIT
             organization_id,
             cost_group_id,
             subinventory_code,
             inventory_item_id,
             rollback_intransit_value)
      INTO cst_inv_qty_temp (
             qty_source,
             organization_id,
             cost_group_id,
             subinventory_code,
             inventory_item_id,
             accounted_value)
      VALUES (21, -- CUMULATIVE ONHAND
             organization_id,
             cost_group_id,
             subinventory_code,
             inventory_item_id,
             cumulative_onhand_mta)
      INTO cst_inv_qty_temp (
             qty_source,
             organization_id,
             cost_group_id,
             subinventory_code,
             inventory_item_id,
             accounted_value)
      VALUES (22, -- CUMULATIVE INTRANSIT
             organization_id,
             cost_group_id,
             subinventory_code,
             inventory_item_id,
             cumulative_intransit_mta)
      SELECT p_org_id organization_id,
             CPCS.cost_group_id,
             CPCS.subinventory_code,
             CPCS.inventory_item_id,
             CPCS.rollback_onhand_value,
             CPCS.rollback_intransit_value,
             CPCS.cumulative_onhand_mta,
             CPCS.cumulative_intransit_mta
      FROM
             cst_period_close_summary CPCS
      WHERE  CPCS.organization_id = p_org_id
      AND    CPCS.acct_period_id = NVL(l_prior_period_id,-1)
      AND    (rollback_quantity <> 0 OR
              rollback_onhand_value <> 0 OR
              rollback_intransit_value <> 0 OR
              accounted_onhand_value <> 0 OR
              accounted_intransit_value <> 0 OR
              l_zero_val_hook = 0);
Line: 2067

          p_error_text => l_stmt_num||': Inserted  '||SQL%ROWCOUNT||
                          ' rows to CIQT as baseline from CPCS'
        );
Line: 2075

    SELECT primary_cost_method
    INTO   l_cost_method
    FROM   mtl_parameters
    WHERE  organization_id = p_org_id;
Line: 2083

    INSERT
    INTO   cst_inv_qty_temp(
           qty_source,
           organization_id,
           cost_group_id,
           subinventory_code,
           inventory_item_id,
           accounted_value)
    SELECT 11, -- CURRENT ONHAND
           p_org_id organization_id,
           DECODE(MTA.transaction_source_type_id,
                  5,
                  DECODE(
                    l_cost_method,
                    2,
                    NVL(MMT.transfer_cost_group_id,
                        MMT.cost_group_id),
                    MMT.cost_group_id),
                  MMT.cost_group_id),
           DECODE(MTA.transaction_source_type_id,
                  5,
                  DECODE(
                    l_cost_method,
                    2,
                    DECODE(MMT.transfer_cost_group_id,
                           NULL, MMT.subinventory_code,
					/* Bug 3500534
					It is possible to have normal issue to WIP transactions in
					average costing organizations with transfer_cost_group_id
					= cost_group_id.  The following condition ensures such cases
					are handled as normal issue to WIP rather than common. */
				   MMT.cost_group_id, MMT.subinventory_code,
                           NULL),
                    MMT.subinventory_code),
                  MMT.subinventory_code),
           MMT.inventory_item_id,
           SUM(MTA.base_transaction_value)
    FROM   mtl_material_transactions MMT,
           mtl_transaction_accounts MTA /*,
           mtl_secondary_inventories SUB */
    WHERE  MTA.accounting_line_type = 1 -- inventory
    AND    MTA.transaction_date >= l_period_start_date
    AND    MTA.transaction_date <= l_to_date+1-(1/(24*3600))
    AND    MTA.organization_id = p_org_id
/*  AND    SUB.organization_id (+) = MMT.organization_id
    AND    SUB.secondary_inventory_name (+) = MMT.subinventory_code
    AND    NVL(SUB.asset_inventory,1) = 1 */
    AND     (sign(MMT.primary_quantity) = sign(MTA.primary_quantity)/*BUG7326014*/
                         OR
              MMT.transaction_action_id = 24)
    AND    MMT.transaction_id = MTA.transaction_id
    AND    MMT.transaction_type_id <> 25
    GROUP BY
           DECODE(MTA.transaction_source_type_id,
                  5,
                  DECODE(
                    l_cost_method,
                    2,
                    NVL(MMT.transfer_cost_group_id,
                        MMT.cost_group_id),
                    MMT.cost_group_id),
                  MMT.cost_group_id),
           DECODE(MTA.transaction_source_type_id,
                  5,
                  DECODE(
                    l_cost_method,
                    2,
                    DECODE(MMT.transfer_cost_group_id,
                           NULL, MMT.subinventory_code,
					/* Bug 3500534
					It is possible to have normal issue to WIP transactions in
					average costing organizations with transfer_cost_group_id
					= cost_group_id.  The following condition ensures such cases
					are handled as normal issue to WIP rather than common. */
				   MMT.cost_group_id, MMT.subinventory_code,
                           NULL),
                    MMT.subinventory_code),
                  MMT.subinventory_code),
           MMT.inventory_item_id
          /* Bug 14036099 */
          HAVING (SUM(base_transaction_value) <> 0
	       OR l_zero_val_hook = 0);
Line: 2171

        p_error_text => l_stmt_num||': Inserted  '||SQL%ROWCOUNT||
                        ' rows to CIQT for same MMT MTA primary quantity'
      );
Line: 2179

    INSERT
    INTO   cst_inv_qty_temp(
           qty_source,
           organization_id,
           cost_group_id,
           subinventory_code,
           inventory_item_id,
           accounted_value)
    SELECT 11, -- CURRENT ONHAND
           p_org_id organization_id,
           MMT.transfer_cost_group_id,
           MMT.transfer_subinventory,
           MMT.inventory_item_id,
           SUM(MTA.base_transaction_value)
    FROM   mtl_material_transactions MMT,
           mtl_transaction_accounts MTA /*,
           mtl_secondary_inventories SUB */
    WHERE  MTA.accounting_line_type = 1 -- inventory
    AND    MTA.transaction_date >= l_period_start_date
    AND    MTA.transaction_date <= l_to_date+1-(1/(24*3600))
    AND    MTA.organization_id = p_org_id
 /* AND    SUB.organization_id (+) = MMT.transfer_organization_id
    AND    SUB.secondary_inventory_name (+) = MMT.transfer_subinventory
    AND    NVL(SUB.asset_inventory,1) = 1 */
    AND    sign(MMT.primary_quantity )<>sign( MTA.primary_quantity)/*BUG7326014*/
    AND    MMT.transaction_id = MTA.transaction_id
    AND    MMT.transaction_action_id in (1,2,3,5,28,55)
    GROUP BY
           MMT.transfer_cost_group_id,
           MMT.transfer_subinventory,
           MMT.inventory_item_id
/* Bug 14036099 */
    HAVING (SUM(base_transaction_value) <> 0
        OR l_zero_val_hook = 0);
Line: 2219

        p_error_text => l_stmt_num||': Inserted  '||SQL%ROWCOUNT||
                        ' rows to CIQT for different MMT MTA primary quantity'
      );
Line: 2226

    INSERT
    INTO   cst_inv_qty_temp(
             qty_source,
             organization_id,
             cost_group_id,
             subinventory_code,
             inventory_item_id,
             accounted_value)
    SELECT 12, -- CURRENT INTRANSIT
           p_org_id organization_id,
           DECODE(MMT.transaction_action_id,
                  24,MMT.cost_group_id,
		  /* Bug 9764385 */
                  15,MMT.cost_group_id,
                  22,MMT.cost_group_id,
                  MMT.transfer_cost_group_id),
           NULL,
           MMT.inventory_item_id,
           SUM(MTA.base_transaction_value)
    FROM   mtl_material_transactions MMT,
	   mtl_transaction_accounts MTA
    WHERE  MTA.accounting_line_type = 14 -- intransit account
    AND    MTA.transaction_date >= l_period_start_date
    AND    MTA.transaction_date <= l_to_date+1-(1/(24*3600))
    AND    MTA.organization_id = p_org_id
    AND    MMT.transaction_id = MTA.transaction_id
    GROUP
    BY     MMT.inventory_item_id,
           DECODE(MMT.transaction_action_id,
                  24,MMT.cost_group_id,
		  /* Bug 9764385 */
                  15,MMT.cost_group_id,
                  22,MMT.cost_group_id,
                  MMT.transfer_cost_group_id)
/* Bug 14036099 */
    HAVING (SUM(MTA.base_transaction_value) <> 0
        OR l_zero_val_hook = 0);
Line: 2269

        p_error_text => l_stmt_num||': Inserted  '||SQL%ROWCOUNT||
                        ' rows to CIQT for intransit quantity'
      );
Line: 2314

      INSERT
      INTO   cst_per_close_summary_temp(
             cost_group_id,
             subinventory_code,
             inventory_item_id,
             accounted_value,
             rollback_value,
             rollback_qty)
      SELECT CIQT.cost_group_id,
             CIQT.subinventory_code,
             CIQT.inventory_item_id,
             SUM(DECODE(CIQT.qty_source,
                  21,0,
                  22,0,
                  NVL(CIQT.accounted_value,0))) accounted_value,
             SUM(NVL(CIQT.rollback_qty,0))*NVL(CICT.item_cost,0) rollback_value,
             SUM(NVL(CIQT.rollback_qty,0))
      FROM   cst_inv_qty_temp CIQT,
             cst_inv_cost_temp CICT
      WHERE  CIQT.organization_id = p_org_id
      AND    CIQT.organization_id = CICT.organization_id(+)
      AND    NVL(CIQT.cost_group_id,-1) =
             NVL(CICT.cost_group_id,NVL(CIQT.cost_group_id,-1))
      AND    CIQT.inventory_item_id = CICT.inventory_item_id(+)
      AND    CICT.cost_source(+) = 2 -- PAST
      GROUP BY
             CIQT.cost_group_id,
             CIQT.subinventory_code,
             CIQT.inventory_item_id,
             CICT.item_cost
      /* Bug 14036099 */
      HAVING SUM(DECODE(CIQT.qty_source,
                  21,0,
                  22,0,
                  NVL(CIQT.accounted_value,0))) <> 0
             OR SUM(NVL(CIQT.rollback_qty,0))*NVL(CICT.item_cost,0) <> 0
             OR SUM(NVL(CIQT.rollback_qty,0)) <> 0
             OR l_zero_val_hook = 0;
Line: 2358

        p_error_text => l_stmt_num||': Inserted  '||SQL%ROWCOUNT||
                        ' rows to CPCST for simulation purposes'
      );
Line: 2368

      INSERT
      INTO   cst_period_close_summary(
             acct_period_id,
             organization_id,
             cost_group_id,
             subinventory_code,
             inventory_item_id,
             accounted_value,
             rollback_value,
             rollback_quantity,
             rollback_onhand_value,
             rollback_intransit_value,
             accounted_onhand_value,
             accounted_intransit_value,
             onhand_value_discrepancy,
             intransit_value_discrepancy,
             cumulative_onhand_mta,
             cumulative_intransit_mta,
             last_update_date,
             last_updated_by,
             creation_date,
             creation_by)
      SELECT p_period_id,
             CIQT.organization_id,
             CIQT.cost_group_id,
             CIQT.subinventory_code,
             CIQT.inventory_item_id,
             SUM(DECODE(CIQT.qty_source,
                         21,0,
                         22,0,
                         NVL(CIQT.accounted_value,0))) accounted_value,
             SUM(NVL(CIQT.rollback_qty,0))*NVL(CICT.item_cost,0) rollback_value,
             SUM(NVL(CIQT.rollback_qty,0)),
             SUM(DECODE(CIQT.qty_source,
                         3,NVL(CIQT.rollback_qty,0),
                         4,NVL(CIQT.rollback_qty,0),
                         5,NVL(CIQT.rollback_qty,0),
                         0))*NVL(CICT.item_cost,0) rollback_onhand_value,
             SUM(DECODE(CIQT.qty_source,
                         6,NVL(CIQT.rollback_qty,0),
                         7,NVL(CIQT.rollback_qty,0),
                         8,NVL(CIQT.rollback_qty,0),
                         0))*NVL(CICT.item_cost,0) rollback_intransit_value,
             SUM(DECODE(CIQT.qty_source,
                         1,NVL(CIQT.accounted_value,0),
                         11,NVL(CIQT.accounted_value,0),
                         0)) accounted_onhand_value,
             SUM(DECODE(CIQT.qty_source,
                         2,NVL(CIQT.accounted_value,0),
                         12,NVL(CIQT.accounted_value,0),
                         0)) accounted_intransit_value,
             SUM(DECODE(CIQT.qty_source,
                         3,NVL(CIQT.rollback_qty,0),
                         4,NVL(CIQT.rollback_qty,0),
                         5,NVL(CIQT.rollback_qty,0),
                         0))*NVL(CICT.item_cost,0) -
             SUM(DECODE(CIQT.qty_source,
                         1,NVL(CIQT.accounted_value,0),
                         11,NVL(CIQT.accounted_value,0),
                         0)) onhand_value_discrepancy,
             SUM(DECODE(CIQT.qty_source,
                         6,NVL(CIQT.rollback_qty,0),
                         7,NVL(CIQT.rollback_qty,0),
                         8,NVL(CIQT.rollback_qty,0),
                         0))*NVL(CICT.item_cost,0) -
             SUM(DECODE(CIQT.qty_source,
                         2,NVL(CIQT.accounted_value,0),
                         12,NVL(CIQT.accounted_value,0),
                         0)) intransit_value_discrepancy,
             SUM(DECODE(CIQT.qty_source,
                         11,NVL(CIQT.accounted_value,0),
                         21,NVL(CIQT.accounted_value,0),
                         0)) cumulative_onhand_mta,
             SUM(DECODE(CIQT.qty_source,
                         12,NVL(CIQT.accounted_value,0),
                         22,NVL(CIQT.accounted_value,0),
                         0)) cumulative_intransit_mta,
             SYSDATE,
             1,
             SYSDATE,
             1
      FROM   cst_inv_qty_temp CIQT,
             cst_inv_cost_temp CICT
      WHERE  CIQT.organization_id = p_org_id
      AND    CIQT.organization_id = CICT.organization_id(+)
      AND    NVL(CIQT.cost_group_id,-1) =
             NVL(CICT.cost_group_id,NVL(CIQT.cost_group_id,-1))
      AND    CIQT.inventory_item_id = CICT.inventory_item_id(+)
      AND    CICT.cost_source(+) = 2 -- PAST
      GROUP BY
             CIQT.organization_id,
             CIQT.cost_group_id,
             CIQT.subinventory_code,
             CIQT.inventory_item_id,
             CICT.item_cost
      /* Bug 14036099 */
      HAVING SUM(NVL(CIQT.rollback_qty,0)) <> 0
          OR SUM(DECODE(CIQT.qty_source,
                         3,NVL(CIQT.rollback_qty,0),
                         4,NVL(CIQT.rollback_qty,0),
                         5,NVL(CIQT.rollback_qty,0),
                         0))*NVL(CICT.item_cost,0) <> 0
          OR SUM(DECODE(CIQT.qty_source,
                         6,NVL(CIQT.rollback_qty,0),
                         7,NVL(CIQT.rollback_qty,0),
                         8,NVL(CIQT.rollback_qty,0),
                         0))*NVL(CICT.item_cost,0) <> 0
          OR SUM(DECODE(CIQT.qty_source,
                         1,NVL(CIQT.accounted_value,0),
                         11,NVL(CIQT.accounted_value,0),
                         0)) <> 0
          OR SUM(DECODE(CIQT.qty_source,
                         2,NVL(CIQT.accounted_value,0),
                         12,NVL(CIQT.accounted_value,0),
                         0)) <> 0
          OR l_zero_val_hook = 0;
Line: 2490

          p_error_text => l_stmt_num||': Inserted  '||SQL%ROWCOUNT||
                          ' rows to CPCS for org/period ' || p_org_id || '/' || p_period_id
        );
Line: 2496

      UPDATE org_acct_periods
      SET    summarized_flag = 'Y'

      WHERE  organization_id = p_org_id
      AND    acct_period_id = p_period_id;